diff --git a/CHANGES b/CHANGES index 24ebd9362..1a91991a4 100644 --- a/CHANGES +++ b/CHANGES @@ -41,6 +41,7 @@ Incompatible changes ``xcolor`` packages should be used by extensions of Sphinx latex writer. (refs #3550) * ``Builder.env`` is not filled at instantiation +* #3594: LaTeX: single raw directive has been considereed as block level element Features removed ---------------- diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index 6466194b0..7e666ecff 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -1991,8 +1991,12 @@ class LaTeXTranslator(nodes.NodeVisitor): def visit_raw(self, node): # type: (nodes.Node) -> None + if not self.is_inline(node): + self.body.append('\n') if 'latex' in node.get('format', '').split(): self.body.append(node.astext()) + if not self.is_inline(node): + self.body.append('\n') raise nodes.SkipNode def visit_reference(self, node): diff --git a/tests/roots/test-directives-raw/conf.py b/tests/roots/test-directives-raw/conf.py new file mode 100644 index 000000000..f81c30bc4 --- /dev/null +++ b/tests/roots/test-directives-raw/conf.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +master_doc = 'index' diff --git a/tests/roots/test-directives-raw/index.rst b/tests/roots/test-directives-raw/index.rst new file mode 100644 index 000000000..401ab73b5 --- /dev/null +++ b/tests/roots/test-directives-raw/index.rst @@ -0,0 +1,40 @@ +test-directives-raw +=================== + +HTML +---- + +standard +^^^^^^^^ + +.. raw:: html + + standalone raw directive (HTML) + +with substitution +^^^^^^^^^^^^^^^^^ + +HTML: abc |HTML_RAW| ghi + +.. |HTML_RAW| raw:: html + + def + +LaTeX +----- + +standard +^^^^^^^^ + +.. raw:: latex + + standalone raw directive (LaTeX) + +with substitution +^^^^^^^^^^^^^^^^^ + +LaTeX: abc |LATEX_RAW| ghi + +.. |LATEX_RAW| raw:: latex + + def diff --git a/tests/test_build_html.py b/tests/test_build_html.py index def6722c3..d4f37c787 100644 --- a/tests/test_build_html.py +++ b/tests/test_build_html.py @@ -1180,3 +1180,17 @@ def test_html_inventory(app): '', 'http://example.com/index.html', 'The basic Sphinx documentation for testing') + + +@pytest.mark.sphinx('html', testroot='directives-raw') +def test_html_raw_directive(app, status, warning): + app.builder.build_all() + result = (app.outdir / 'index.html').text(encoding='utf8') + + # standard case + assert 'standalone raw directive (HTML)' in result + assert 'standalone raw directive (LaTeX)' not in result + + # with substitution + assert '

HTML: abc def ghi

' in result + assert '

LaTeX: abc ghi

' in result diff --git a/tests/test_build_latex.py b/tests/test_build_latex.py index b2cfd6cbb..24ce0050a 100644 --- a/tests/test_build_latex.py +++ b/tests/test_build_latex.py @@ -1027,3 +1027,18 @@ def test_latex_table_complex_tables(app, status, warning): '\\sphinxtablestrut{6}&\\sphinxtablestrut{4}&\ncell3-5\n' '\\\\\n\\hline\n\\end{tabulary}\n' in table) + + +@pytest.mark.sphinx('latex', testroot='directives-raw') +def test_latex_raw_directive(app, status, warning): + app.builder.build_all() + result = (app.outdir / 'Python.tex').text(encoding='utf8') + + # standard case + assert 'standalone raw directive (HTML)' not in result + assert ('\\label{\\detokenize{index:id1}}\n' + 'standalone raw directive (LaTeX)' in result) + + # with substitution + assert 'HTML: abc ghi' in result + assert 'LaTeX: abc def ghi' in result