diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index ab15ec8b5..56f0061d9 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -927,8 +927,9 @@ class LaTeXTranslator(nodes.NodeVisitor): def render(self, template_name, variables): # type: (unicode, Dict) -> unicode - for template_path in self.builder.config.templates_path: - template = path.join(template_path, template_name) + for template_dir in self.builder.config.templates_path: + template = path.join(self.builder.srcdir, template_dir, + template_name) if path.exists(template): return LaTeXRenderer().render(template, variables) diff --git a/tests/roots/test-latex-table/_mytemplates/latex/longtable.tex_t b/tests/roots/test-latex-table/_mytemplates/latex/longtable.tex_t new file mode 100644 index 000000000..e2cb1db0a --- /dev/null +++ b/tests/roots/test-latex-table/_mytemplates/latex/longtable.tex_t @@ -0,0 +1 @@ +SALUT LES COPAINS diff --git a/tests/test_build_latex.py b/tests/test_build_latex.py index 5613672bb..e7731f063 100644 --- a/tests/test_build_latex.py +++ b/tests/test_build_latex.py @@ -1098,6 +1098,30 @@ def test_latex_table_complex_tables(app, status, warning): assert actual == expected +@pytest.mark.sphinx('latex', testroot='latex-table', + confoverrides={'templates_path': ['_mytemplates/latex']}) +def test_latex_table_custom_template_caseA(app, status, warning): + app.builder.build_all() + result = (app.outdir / 'test.tex').text(encoding='utf8') + assert 'SALUT LES COPAINS' in result + + +@pytest.mark.sphinx('latex', testroot='latex-table', + confoverrides={'templates_path': ['_mytemplates']}) +def test_latex_table_custom_template_caseB(app, status, warning): + app.builder.build_all() + result = (app.outdir / 'test.tex').text(encoding='utf8') + assert 'SALUT LES COPAINS' not in result + + +@pytest.mark.sphinx('latex', testroot='latex-table') +@pytest.mark.test_params(shared_result='latex-table') +def test_latex_table_custom_template_caseC(app, status, warning): + app.builder.build_all() + result = (app.outdir / 'test.tex').text(encoding='utf8') + assert 'SALUT LES COPAINS' not in result + + @pytest.mark.sphinx('latex', testroot='directives-raw') def test_latex_raw_directive(app, status, warning): app.builder.build_all()