sphinx/tests/test_builders/test_build_latex.py

2277 lines
77 KiB
Python
Raw Normal View History

2022-02-19 21:05:56 -06:00
"""Test the build process with LaTeX builder with the test root."""
2010-01-17 05:29:00 -06:00
import http.server
2010-01-17 05:29:00 -06:00
import os
2010-06-03 10:25:16 -05:00
import re
import subprocess
from pathlib import Path
from shutil import copyfile
2022-10-17 09:54:59 -05:00
from subprocess import CalledProcessError
2010-01-17 05:29:00 -06:00
2017-01-03 07:24:00 -06:00
import pytest
from sphinx.builders.latex import default_latex_documents
from sphinx.config import Config
from sphinx.errors import SphinxError
from sphinx.ext.intersphinx import load_mappings, validate_intersphinx_mapping
from sphinx.ext.intersphinx import setup as intersphinx_setup
from sphinx.util.osutil import ensuredir
2010-01-17 05:29:00 -06:00
from sphinx.writers.latex import LaTeXTranslator
from tests.utils import http_server
try:
from contextlib import chdir
except ImportError:
from sphinx.util.osutil import _chdir as chdir
2024-08-11 08:58:56 -05:00
STYLEFILES = [
'article.cls',
'fancyhdr.sty',
'titlesec.sty',
'amsmath.sty',
'framed.sty',
'color.sty',
'fancyvrb.sty',
'fncychap.sty',
'geometry.sty',
'kvoptions.sty',
'hyperref.sty',
'booktabs.sty',
]
2024-01-18 21:21:42 -06:00
# only run latex if all needed packages are there
def kpsetest(*filenames):
try:
subprocess.run(['kpsewhich', *list(filenames)], capture_output=True, check=True)
return True
except (OSError, CalledProcessError):
return False # command not found or exit with non-zero
# compile latex document with app.config.latex_engine
def compile_latex_document(app, filename='projectnamenotset.tex', docclass='manual'):
# now, try to run latex over it
try:
with chdir(app.outdir):
# name latex output-directory according to both engine and docclass
# to avoid reuse of auxiliary files by one docclass from another
latex_outputdir = app.config.latex_engine + docclass
ensuredir(latex_outputdir)
2019-02-03 08:54:22 -06:00
# keep a copy of latex file for this engine in case test fails
copyfile(filename, latex_outputdir + '/' + filename)
2024-08-11 08:58:56 -05:00
args = [
app.config.latex_engine,
'--halt-on-error',
'--interaction=nonstopmode',
f'-output-directory={latex_outputdir}',
filename,
]
2022-10-17 09:54:59 -05:00
subprocess.run(args, capture_output=True, check=True)
except OSError as exc: # most likely the latex executable was not found
raise pytest.skip.Exception from exc
except CalledProcessError as exc:
print(exc.stdout.decode('utf8'))
print(exc.stderr.decode('utf8'))
msg = f'{app.config.latex_engine} exited with return code {exc.returncode}'
raise AssertionError(msg) from exc
2017-04-22 04:14:06 -05:00
def skip_if_requested(testfunc):
if 'SKIP_LATEX_BUILD' in os.environ:
msg = 'Skip LaTeX builds because SKIP_LATEX_BUILD is set'
2017-04-27 09:38:42 -05:00
return pytest.mark.skipif(True, reason=msg)(testfunc)
2017-04-22 04:14:06 -05:00
else:
return testfunc
def skip_if_stylefiles_notfound(testfunc):
if kpsetest(*STYLEFILES) is False:
msg = 'not running latex, the required styles do not seem to be installed'
2017-04-27 09:38:42 -05:00
return pytest.mark.skipif(True, reason=msg)(testfunc)
else:
return testfunc
class RemoteImageHandler(http.server.BaseHTTPRequestHandler):
2024-08-11 08:58:56 -05:00
protocol_version = 'HTTP/1.1'
def do_GET(self):
content, content_type = None, None
2024-08-11 08:58:56 -05:00
if self.path == '/sphinx.png':
with open('tests/roots/test-local-logo/images/img.png', 'rb') as f:
content = f.read()
2024-08-11 08:58:56 -05:00
content_type = 'image/png'
if content:
2024-08-11 08:58:56 -05:00
self.send_response(200, 'OK')
self.send_header('Content-Length', str(len(content)))
self.send_header('Content-Type', content_type)
self.end_headers()
self.wfile.write(content)
else:
2024-08-11 08:58:56 -05:00
self.send_response(404, 'Not Found')
self.send_header('Content-Length', '0')
self.end_headers()
2017-04-22 04:14:06 -05:00
@skip_if_requested
@skip_if_stylefiles_notfound
2017-01-03 07:24:00 -06:00
@pytest.mark.parametrize(
('engine', 'docclass', 'python_maximum_signature_line_length'),
# Only running test with `python_maximum_signature_line_length` not None with last
# LaTeX engine to reduce testing time, as if this configuration does not fail with
# one engine, it's almost impossible it would fail with another.
[
('pdflatex', 'manual', None),
('pdflatex', 'howto', None),
('lualatex', 'manual', None),
('lualatex', 'howto', None),
('xelatex', 'manual', 1),
('xelatex', 'howto', 1),
],
2017-01-03 07:24:00 -06:00
)
2024-08-11 08:58:56 -05:00
@pytest.mark.sphinx(
'latex',
testroot='root',
2024-08-11 08:58:56 -05:00
freshenv=True,
)
def test_build_latex_doc(app, engine, docclass, python_maximum_signature_line_length):
2024-08-11 08:58:56 -05:00
app.config.python_maximum_signature_line_length = (
python_maximum_signature_line_length
)
app.config.intersphinx_mapping = {
'sphinx': ('https://www.sphinx-doc.org/en/master/', None),
}
intersphinx_setup(app)
app.config.latex_engine = engine
app.config.latex_documents = [app.config.latex_documents[0][:4] + (docclass,)]
LaTeX: support for booktabs-style and zebra-striped tables (#10759) This is a combination of 2 + 28 + 7 + and some more commits... * Cherry-pick: Add support for booktabs-style tables to LaTeX builder * Cherry-pick: Add support for zebra-striped tables to LaTeX builder Co-authored-by: Stefan Wiehler <stefan.wiehler@missinglinkelectronics.com> Above work originally initiated by @sephalon (thanks!) Development refactored and continued by @jfbu * latex_table_style configuration, support booktabs, colorrows, borderless Some details: - Simplify a bit a conditional in the longtable template This also puts the target for a longtable with a label but no caption above the toprule for better hyperlinking (testing shows hyperlink target can not end up alone at bottom of previous page). - Extend allowed syntax for colour assignments via 'sphinxsetup' - latex_table_style new configuration value and coloured rows For the user interface I tried to look for inspiration in https://docutils.sourceforge.io/docs/user/config.html#table-style which mentions booktabs and borderless. They also mention captionbelow which we can implement later, now that architecture is here. They don't mention coloured rows. - Test on our own document... looks fine! - Work-around an incompatibility of \cline with row colours - Reverse priority of classes to allow overruling booktabs by standard after parsing source but before letting LaTeX writer act - Closes #8220 Commit https://github.com/sphinx-doc/sphinx/commit/bb859c669679baebd8cc8d10c99382478c0d1647 already improved a bit, this finishes it (as :rst:dir:`rst-class` was actually not linking to anywhere). - Let booktabs style defaults to *not* using \cmidrule. They actually don't make much sense there, as all \hline's are removed. - Add \sphinxnorowcolor which allows construct such as this one in a tabularcolumns directive: >{\columncolor{blue}\sphinxnorowcolor} else LaTeX always overrides column colour by row colour - Add TableMergeColorHeader, TableMergeColorOdd, TableMergeColorEven so single-row merged cells can be styled especially - Extend row colours to all header rows not only the first one (all header rows will share same colour settings) - Auto-adjust to a no '|'-colspec for optimal handling of merged cell - Add \sphinxcolorblend - Workaround LaTeX's \cline features and other grid tables matters - Add \sphinxbuildwarning for important warnings - Fix some white gaps in merged cells of tables with vlines and colorrows - Work around LaTeX's \cline serious deficiencies for complex grid tables This commit corrects \cline badly impacting vertical spacing and making tables look even more cramped as they usually are in LaTeX (although one sees it clearly only with \arrarrulewidth a bit more than the LaTeX default of 0.4pt). Most importantly this commit solves the problem that \cline's got masked by colour panels from the row below. - Update CHANGES for PR #10759 - Improve documentation of new latex_table_style regarding colours
2022-10-12 10:15:40 -05:00
if engine == 'xelatex':
app.config.latex_table_style = ['booktabs']
elif engine == 'lualatex':
app.config.latex_table_style = ['colorrows']
validate_intersphinx_mapping(app, app.config)
load_mappings(app)
app.builder.init()
2010-01-17 05:29:00 -06:00
LaTeXTranslator.ignore_missing_images = True
with http_server(RemoteImageHandler):
app.build(force_all=True)
2010-01-17 05:29:00 -06:00
# file from latex_additional_files
assert (app.outdir / 'svgimg.svg').is_file()
2010-01-17 05:29:00 -06:00
compile_latex_document(app, 'sphinxtests.tex', docclass)
@pytest.mark.sphinx('latex', testroot='root')
def test_writer(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'sphinxtests.tex').read_text(encoding='utf8')
2024-08-11 08:58:56 -05:00
assert (
'\\begin{sphinxfigure-in-table}\n\\centering\n\\capstart\n'
'\\noindent\\sphinxincludegraphics{{img}.png}\n'
'\\sphinxfigcaption{figure in table}\\label{\\detokenize{markup:id8}}'
'\\end{sphinxfigure-in-table}\\relax'
) in result
assert (
'\\begin{wrapfigure}{r}{0pt}\n\\centering\n'
'\\noindent\\sphinxincludegraphics{{rimg}.png}\n'
'\\caption{figure with align option}\\label{\\detokenize{markup:id10}}'
'\\end{wrapfigure}\n\n'
'\\mbox{}\\par\\vskip-\\dimexpr\\baselineskip+\\parskip\\relax'
) in result
assert (
'\\begin{wrapfigure}{r}{0.500\\linewidth}\n\\centering\n'
'\\noindent\\sphinxincludegraphics{{rimg}.png}\n'
'\\caption{figure with align \\& figwidth option}'
'\\label{\\detokenize{markup:id11}}'
'\\end{wrapfigure}\n\n'
'\\mbox{}\\par\\vskip-\\dimexpr\\baselineskip+\\parskip\\relax'
) in result
assert (
'\\begin{wrapfigure}{r}{3cm}\n\\centering\n'
'\\noindent\\sphinxincludegraphics[width=3cm]{{rimg}.png}\n'
'\\caption{figure with align \\& width option}'
'\\label{\\detokenize{markup:id12}}'
'\\end{wrapfigure}\n\n'
'\\mbox{}\\par\\vskip-\\dimexpr\\baselineskip+\\parskip\\relax'
) in result
2018-12-08 09:35:46 -06:00
assert 'Footnotes' not in result
2024-08-11 08:58:56 -05:00
assert (
'\\begin{sphinxseealso}{See also:}\n\n'
'\\sphinxAtStartPar\n'
'something, something else, something more\n'
'\\begin{description}\n'
'\\sphinxlineitem{\\sphinxhref{https://www.google.com}{Google}}\n'
'\\sphinxAtStartPar\n'
'For everything.\n'
'\n'
'\\end{description}\n'
'\n\n\\end{sphinxseealso}\n\n'
) in result
@pytest.mark.sphinx('latex', testroot='basic')
def test_latex_basic(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'test.tex').read_text(encoding='utf8')
print(result)
print(app.status.getvalue())
print(app.warning.getvalue())
assert r'\title{The basic Sphinx documentation for testing}' in result
assert r'\release{}' in result
assert r'\renewcommand{\releasename}{}' in result
2024-08-11 08:58:56 -05:00
@pytest.mark.sphinx(
'latex',
testroot='basic',
confoverrides={
'latex_documents': [('index', 'test.tex', 'title', 'author', 'manual')],
},
)
def test_latex_basic_manual(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'test.tex').read_text(encoding='utf8')
print(result)
assert r'\def\sphinxdocclass{report}' in result
assert r'\documentclass[letterpaper,10pt,english]{sphinxmanual}' in result
2024-08-11 08:58:56 -05:00
@pytest.mark.sphinx(
'latex',
testroot='basic',
confoverrides={
'latex_documents': [('index', 'test.tex', 'title', 'author', 'howto')],
},
)
def test_latex_basic_howto(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'test.tex').read_text(encoding='utf8')
print(result)
assert r'\def\sphinxdocclass{article}' in result
assert r'\documentclass[letterpaper,10pt,english]{sphinxhowto}' in result
2024-08-11 08:58:56 -05:00
@pytest.mark.sphinx(
'latex',
testroot='basic',
confoverrides={
'language': 'ja',
'latex_documents': [('index', 'test.tex', 'title', 'author', 'manual')],
},
)
def test_latex_basic_manual_ja(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'test.tex').read_text(encoding='utf8')
print(result)
assert r'\def\sphinxdocclass{ujbook}' in result
assert r'\documentclass[letterpaper,10pt,dvipdfmx]{sphinxmanual}' in result
2024-08-11 08:58:56 -05:00
@pytest.mark.sphinx(
'latex',
testroot='basic',
confoverrides={
'language': 'ja',
'latex_documents': [('index', 'test.tex', 'title', 'author', 'howto')],
},
)
def test_latex_basic_howto_ja(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'test.tex').read_text(encoding='utf8')
print(result)
assert r'\def\sphinxdocclass{ujreport}' in result
assert r'\documentclass[letterpaper,10pt,dvipdfmx]{sphinxhowto}' in result
2019-12-28 04:36:55 -06:00
@pytest.mark.sphinx('latex', testroot='latex-theme')
def test_latex_theme(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
2019-12-28 04:36:55 -06:00
print(result)
assert r'\def\sphinxdocclass{book}' in result
assert r'\documentclass[a4paper,12pt,english]{sphinxbook}' in result
2024-08-11 08:58:56 -05:00
@pytest.mark.sphinx(
'latex',
testroot='latex-theme',
confoverrides={'latex_elements': {'papersize': 'b5paper', 'pointsize': '9pt'}},
)
def test_latex_theme_papersize(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
print(result)
assert r'\def\sphinxdocclass{book}' in result
assert r'\documentclass[b5paper,9pt,english]{sphinxbook}' in result
2024-08-11 08:58:56 -05:00
@pytest.mark.sphinx(
'latex',
testroot='latex-theme',
confoverrides={'latex_theme_options': {'papersize': 'b5paper', 'pointsize': '9pt'}},
)
def test_latex_theme_options(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
print(result)
assert r'\def\sphinxdocclass{book}' in result
assert r'\documentclass[b5paper,9pt,english]{sphinxbook}' in result
2019-12-28 04:36:55 -06:00
2024-08-11 08:58:56 -05:00
@pytest.mark.sphinx(
'latex',
testroot='basic',
confoverrides={'language': 'zh'},
)
def test_latex_additional_settings_for_language_code(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'test.tex').read_text(encoding='utf8')
print(result)
print(app.status.getvalue())
print(app.warning.getvalue())
assert r'\usepackage{xeCJK}' in result
2024-08-11 08:58:56 -05:00
@pytest.mark.sphinx(
'latex',
testroot='basic',
confoverrides={'language': 'el'},
)
def test_latex_additional_settings_for_greek(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'test.tex').read_text(encoding='utf8')
print(result)
print(app.status.getvalue())
print(app.warning.getvalue())
assert '\\usepackage{polyglossia}\n\\setmainlanguage{greek}' in result
assert '\\newfontfamily\\greekfonttt{FreeMono}' in result
@pytest.mark.sphinx('latex', testroot='latex-title')
def test_latex_title_after_admonitions(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'test.tex').read_text(encoding='utf8')
print(result)
print(app.status.getvalue())
print(app.warning.getvalue())
assert '\\title{test\\sphinxhyphen{}latex\\sphinxhyphen{}title}' in result
2024-08-11 08:58:56 -05:00
@pytest.mark.sphinx(
'latex',
testroot='basic',
confoverrides={'release': '1.0_0'},
)
def test_latex_release(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'test.tex').read_text(encoding='utf8')
print(result)
print(app.status.getvalue())
print(app.warning.getvalue())
assert r'\release{1.0\_0}' in result
assert r'\renewcommand{\releasename}{Release}' in result
2024-08-11 08:58:56 -05:00
@pytest.mark.sphinx(
'latex',
testroot='numfig',
confoverrides={'numfig': True},
)
def test_numref(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
2014-10-01 21:17:34 -05:00
print(result)
print(app.status.getvalue())
print(app.warning.getvalue())
2024-08-11 08:58:56 -05:00
assert (
'\\hyperref[\\detokenize{index:fig1}]'
'{Fig.\\@ \\ref{\\detokenize{index:fig1}}}'
) in result
assert (
'\\hyperref[\\detokenize{baz:fig22}]{Figure\\ref{\\detokenize{baz:fig22}}}'
) in result
assert (
'\\hyperref[\\detokenize{index:table-1}]'
'{Table \\ref{\\detokenize{index:table-1}}}'
) in result
assert (
'\\hyperref[\\detokenize{baz:table22}]'
'{Table:\\ref{\\detokenize{baz:table22}}}'
) in result
assert (
'\\hyperref[\\detokenize{index:code-1}]'
'{Listing \\ref{\\detokenize{index:code-1}}}'
) in result
assert (
'\\hyperref[\\detokenize{baz:code22}]'
'{Code\\sphinxhyphen{}\\ref{\\detokenize{baz:code22}}}'
) in result
assert (
'\\hyperref[\\detokenize{foo:foo}]{Section \\ref{\\detokenize{foo:foo}}}'
) in result
assert (
'\\hyperref[\\detokenize{bar:bar-a}]{Section \\ref{\\detokenize{bar:bar-a}}}'
) in result
assert (
'\\hyperref[\\detokenize{index:fig1}]{Fig.\\ref{\\detokenize{index:fig1}} '
'\\nameref{\\detokenize{index:fig1}}}'
) in result
assert (
'\\hyperref[\\detokenize{foo:foo}]{Sect.\\ref{\\detokenize{foo:foo}} '
'\\nameref{\\detokenize{foo:foo}}}'
) in result
# sphinxmessages.sty
result = (app.outdir / 'sphinxmessages.sty').read_text(encoding='utf8')
print(result)
assert r'\addto\captionsenglish{\renewcommand{\figurename}{Fig.\@{} }}' in result
assert r'\addto\captionsenglish{\renewcommand{\tablename}{Table }}' in result
2024-08-11 08:58:56 -05:00
assert (
r'\addto\captionsenglish{\renewcommand{\literalblockname}{Listing}}'
) in result
@pytest.mark.sphinx(
2024-08-11 08:58:56 -05:00
'latex',
testroot='numfig',
confoverrides={
'numfig': True,
'numfig_format': {
'figure': 'Figure:%s',
'table': 'Tab_%s',
'code-block': 'Code-%s',
'section': 'SECTION-%s',
},
},
)
def test_numref_with_prefix1(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
print(result)
print(app.status.getvalue())
print(app.warning.getvalue())
2016-12-08 14:43:04 -06:00
assert '\\ref{\\detokenize{index:fig1}}' in result
assert '\\ref{\\detokenize{baz:fig22}}' in result
assert '\\ref{\\detokenize{index:table-1}}' in result
assert '\\ref{\\detokenize{baz:table22}}' in result
assert '\\ref{\\detokenize{index:code-1}}' in result
assert '\\ref{\\detokenize{baz:code22}}' in result
2024-08-11 08:58:56 -05:00
assert (
'\\hyperref[\\detokenize{index:fig1}]'
'{Figure:\\ref{\\detokenize{index:fig1}}}'
) in result
assert (
'\\hyperref[\\detokenize{baz:fig22}]{Figure\\ref{\\detokenize{baz:fig22}}}'
) in result
assert (
'\\hyperref[\\detokenize{index:table-1}]'
'{Tab\\_\\ref{\\detokenize{index:table-1}}}'
) in result
assert (
'\\hyperref[\\detokenize{baz:table22}]'
'{Table:\\ref{\\detokenize{baz:table22}}}'
) in result
assert (
'\\hyperref[\\detokenize{index:code-1}]'
'{Code\\sphinxhyphen{}\\ref{\\detokenize{index:code-1}}}'
) in result
assert (
'\\hyperref[\\detokenize{baz:code22}]'
'{Code\\sphinxhyphen{}\\ref{\\detokenize{baz:code22}}}'
) in result
assert (
'\\hyperref[\\detokenize{foo:foo}]'
'{SECTION\\sphinxhyphen{}\\ref{\\detokenize{foo:foo}}}'
) in result
assert (
'\\hyperref[\\detokenize{bar:bar-a}]'
'{SECTION\\sphinxhyphen{}\\ref{\\detokenize{bar:bar-a}}}'
) in result
assert (
'\\hyperref[\\detokenize{index:fig1}]{Fig.\\ref{\\detokenize{index:fig1}} '
'\\nameref{\\detokenize{index:fig1}}}'
) in result
assert (
'\\hyperref[\\detokenize{foo:foo}]{Sect.\\ref{\\detokenize{foo:foo}} '
'\\nameref{\\detokenize{foo:foo}}}'
) in result
# sphinxmessages.sty
result = (app.outdir / 'sphinxmessages.sty').read_text(encoding='utf8')
print(result)
assert r'\addto\captionsenglish{\renewcommand{\figurename}{Figure:}}' in result
assert r'\addto\captionsenglish{\renewcommand{\tablename}{Tab\_}}' in result
assert r'\addto\captionsenglish{\renewcommand{\literalblockname}{Code-}}' in result
@pytest.mark.sphinx(
2024-08-11 08:58:56 -05:00
'latex',
testroot='numfig',
confoverrides={
'numfig': True,
'numfig_format': {
'figure': 'Figure:%s.',
'table': 'Tab_%s:',
'code-block': 'Code-%s | ',
'section': 'SECTION_%s_',
},
},
)
def test_numref_with_prefix2(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
print(result)
print(app.status.getvalue())
print(app.warning.getvalue())
2024-08-11 08:58:56 -05:00
assert (
'\\hyperref[\\detokenize{index:fig1}]'
'{Figure:\\ref{\\detokenize{index:fig1}}.\\@}'
) in result
assert (
'\\hyperref[\\detokenize{baz:fig22}]{Figure\\ref{\\detokenize{baz:fig22}}}'
) in result
assert (
'\\hyperref[\\detokenize{index:table-1}]'
'{Tab\\_\\ref{\\detokenize{index:table-1}}:}'
) in result
assert (
'\\hyperref[\\detokenize{baz:table22}]'
'{Table:\\ref{\\detokenize{baz:table22}}}'
) in result
assert (
'\\hyperref[\\detokenize{index:code-1}]{Code\\sphinxhyphen{}\\ref{\\detokenize{index:code-1}} '
'| }'
) in result
assert (
'\\hyperref[\\detokenize{baz:code22}]'
'{Code\\sphinxhyphen{}\\ref{\\detokenize{baz:code22}}}'
) in result
assert (
'\\hyperref[\\detokenize{foo:foo}]'
'{SECTION\\_\\ref{\\detokenize{foo:foo}}\\_}'
) in result
assert (
'\\hyperref[\\detokenize{bar:bar-a}]'
'{SECTION\\_\\ref{\\detokenize{bar:bar-a}}\\_}'
) in result
assert (
'\\hyperref[\\detokenize{index:fig1}]{Fig.\\ref{\\detokenize{index:fig1}} '
'\\nameref{\\detokenize{index:fig1}}}'
) in result
assert (
'\\hyperref[\\detokenize{foo:foo}]{Sect.\\ref{\\detokenize{foo:foo}} '
'\\nameref{\\detokenize{foo:foo}}}'
) in result
2014-10-01 21:17:34 -05:00
# sphinxmessages.sty
result = (app.outdir / 'sphinxmessages.sty').read_text(encoding='utf8')
print(result)
assert r'\addto\captionsenglish{\renewcommand{\figurename}{Figure:}}' in result
assert r'\def\fnum@figure{\figurename\thefigure{}.}' in result
assert r'\addto\captionsenglish{\renewcommand{\tablename}{Tab\_}}' in result
assert r'\def\fnum@table{\tablename\thetable{}:}' in result
assert r'\addto\captionsenglish{\renewcommand{\literalblockname}{Code-}}' in result
2014-10-01 21:17:34 -05:00
@pytest.mark.sphinx(
2024-08-11 08:58:56 -05:00
'latex',
testroot='numfig',
confoverrides={'numfig': True, 'language': 'ja'},
)
def test_numref_with_language_ja(app):
2023-01-03 22:22:20 -06:00
app.build()
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
print(result)
print(app.status.getvalue())
print(app.warning.getvalue())
2024-08-11 08:58:56 -05:00
assert (
'\\hyperref[\\detokenize{index:fig1}]'
'{\u56f3 \\ref{\\detokenize{index:fig1}}}'
) in result
assert (
'\\hyperref[\\detokenize{baz:fig22}]{Figure\\ref{\\detokenize{baz:fig22}}}'
) in result
assert (
'\\hyperref[\\detokenize{index:table-1}]'
'{\u8868 \\ref{\\detokenize{index:table-1}}}'
) in result
assert (
'\\hyperref[\\detokenize{baz:table22}]'
'{Table:\\ref{\\detokenize{baz:table22}}}'
) in result
assert (
'\\hyperref[\\detokenize{index:code-1}]'
'{\u30ea\u30b9\u30c8 \\ref{\\detokenize{index:code-1}}}'
) in result
assert (
'\\hyperref[\\detokenize{baz:code22}]'
'{Code\\sphinxhyphen{}\\ref{\\detokenize{baz:code22}}}'
) in result
assert (
'\\hyperref[\\detokenize{foo:foo}]{\\ref{\\detokenize{foo:foo}} \u7ae0}'
) in result
assert (
'\\hyperref[\\detokenize{bar:bar-a}]{\\ref{\\detokenize{bar:bar-a}} \u7ae0}'
) in result
assert (
'\\hyperref[\\detokenize{index:fig1}]{Fig.\\ref{\\detokenize{index:fig1}} '
'\\nameref{\\detokenize{index:fig1}}}'
) in result
assert (
'\\hyperref[\\detokenize{foo:foo}]{Sect.\\ref{\\detokenize{foo:foo}} '
'\\nameref{\\detokenize{foo:foo}}}'
) in result
# sphinxmessages.sty
result = (app.outdir / 'sphinxmessages.sty').read_text(encoding='utf8')
print(result)
assert '\\@iden{\\renewcommand{\\figurename}{図 }}' in result
assert '\\@iden{\\renewcommand{\\tablename}{表 }}' in result
assert '\\@iden{\\renewcommand{\\literalblockname}{リスト}}' in result
@pytest.mark.sphinx('latex', testroot='latex-numfig')
def test_latex_obey_numfig_is_false(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'SphinxManual.tex').read_text(encoding='utf8')
assert '\\usepackage{sphinx}' in result
result = (app.outdir / 'SphinxHowTo.tex').read_text(encoding='utf8')
assert '\\usepackage{sphinx}' in result
@pytest.mark.sphinx(
2024-08-11 08:58:56 -05:00
'latex',
testroot='latex-numfig',
confoverrides={'numfig': True, 'numfig_secnum_depth': 0},
)
def test_latex_obey_numfig_secnum_depth_is_zero(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'SphinxManual.tex').read_text(encoding='utf8')
assert '\\usepackage[,nonumfigreset,mathnumfig]{sphinx}' in result
result = (app.outdir / 'SphinxHowTo.tex').read_text(encoding='utf8')
assert '\\usepackage[,nonumfigreset,mathnumfig]{sphinx}' in result
@pytest.mark.sphinx(
2024-08-11 08:58:56 -05:00
'latex',
testroot='latex-numfig',
confoverrides={'numfig': True, 'numfig_secnum_depth': 2},
)
def test_latex_obey_numfig_secnum_depth_is_two(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'SphinxManual.tex').read_text(encoding='utf8')
assert '\\usepackage[,numfigreset=2,mathnumfig]{sphinx}' in result
result = (app.outdir / 'SphinxHowTo.tex').read_text(encoding='utf8')
assert '\\usepackage[,numfigreset=3,mathnumfig]{sphinx}' in result
@pytest.mark.sphinx(
2024-08-11 08:58:56 -05:00
'latex',
testroot='latex-numfig',
confoverrides={'numfig': True, 'math_numfig': False},
)
def test_latex_obey_numfig_but_math_numfig_false(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'SphinxManual.tex').read_text(encoding='utf8')
assert '\\usepackage[,numfigreset=1]{sphinx}' in result
result = (app.outdir / 'SphinxHowTo.tex').read_text(encoding='utf8')
assert '\\usepackage[,numfigreset=2]{sphinx}' in result
@pytest.mark.sphinx('latex', testroot='basic')
def test_latex_add_latex_package(app):
app.add_latex_package('foo')
app.add_latex_package('bar', 'baz')
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'test.tex').read_text(encoding='utf8')
2014-09-28 07:00:51 -05:00
assert '\\usepackage{foo}' in result
2014-09-28 07:56:20 -05:00
assert '\\usepackage[baz]{bar}' in result
@pytest.mark.sphinx('latex', testroot='latex-babel')
def test_babel_with_no_language_settings(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
print(result)
print(app.status.getvalue())
print(app.warning.getvalue())
assert '\\documentclass[letterpaper,10pt,english]{sphinxmanual}' in result
assert '\\usepackage{babel}' in result
assert '\\usepackage{tgtermes}' in result
assert '\\usepackage[Bjarne]{fncychap}' in result
2024-08-11 08:58:56 -05:00
assert (
'\\addto\\captionsenglish{\\renewcommand{\\contentsname}{Table of content}}\n'
) in result
assert '\\shorthandoff{"}' in result
# sphinxmessages.sty
result = (app.outdir / 'sphinxmessages.sty').read_text(encoding='utf8')
print(result)
assert r'\def\pageautorefname{page}' in result
assert r'\addto\captionsenglish{\renewcommand{\figurename}{Fig.\@{} }}' in result
assert r'\addto\captionsenglish{\renewcommand{\tablename}{Table.\@{} }}' in result
@pytest.mark.sphinx(
2024-08-11 08:58:56 -05:00
'latex',
testroot='latex-babel',
confoverrides={'language': 'de'},
)
def test_babel_with_language_de(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
print(result)
print(app.status.getvalue())
print(app.warning.getvalue())
assert '\\documentclass[letterpaper,10pt,ngerman]{sphinxmanual}' in result
assert '\\usepackage{babel}' in result
assert '\\usepackage{tgtermes}' in result
assert '\\usepackage[Sonny]{fncychap}' in result
2024-08-11 08:58:56 -05:00
assert (
'\\addto\\captionsngerman{\\renewcommand{\\contentsname}{Table of content}}\n'
) in result
assert '\\shorthandoff{"}' in result
# sphinxmessages.sty
result = (app.outdir / 'sphinxmessages.sty').read_text(encoding='utf8')
print(result)
assert r'\def\pageautorefname{Seite}' in result
assert r'\addto\captionsngerman{\renewcommand{\figurename}{Fig.\@{} }}' in result
assert r'\addto\captionsngerman{\renewcommand{\tablename}{Table.\@{} }}' in result
@pytest.mark.sphinx(
2024-08-11 08:58:56 -05:00
'latex',
testroot='latex-babel',
confoverrides={'language': 'ru'},
)
def test_babel_with_language_ru(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
print(result)
print(app.status.getvalue())
print(app.warning.getvalue())
assert '\\documentclass[letterpaper,10pt,russian]{sphinxmanual}' in result
assert '\\usepackage{babel}' in result
assert '\\usepackage{tgtermes}' not in result
assert '\\usepackage[Sonny]{fncychap}' in result
2024-08-11 08:58:56 -05:00
assert (
'\\addto\\captionsrussian{\\renewcommand{\\contentsname}{Table of content}}\n'
) in result
assert '\\shorthandoff{"}' in result
# sphinxmessages.sty
result = (app.outdir / 'sphinxmessages.sty').read_text(encoding='utf8')
print(result)
assert r'\def\pageautorefname{страница}' in result
assert r'\addto\captionsrussian{\renewcommand{\figurename}{Fig.\@{} }}' in result
assert r'\addto\captionsrussian{\renewcommand{\tablename}{Table.\@{} }}' in result
@pytest.mark.sphinx(
2024-08-11 08:58:56 -05:00
'latex',
testroot='latex-babel',
confoverrides={'language': 'tr'},
)
def test_babel_with_language_tr(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
print(result)
print(app.status.getvalue())
print(app.warning.getvalue())
assert '\\documentclass[letterpaper,10pt,turkish]{sphinxmanual}' in result
assert '\\usepackage{babel}' in result
assert '\\usepackage{tgtermes}' in result
assert '\\usepackage[Sonny]{fncychap}' in result
2024-08-11 08:58:56 -05:00
assert (
'\\addto\\captionsturkish{\\renewcommand{\\contentsname}{Table of content}}\n'
) in result
assert '\\shorthandoff{=}' in result
# sphinxmessages.sty
result = (app.outdir / 'sphinxmessages.sty').read_text(encoding='utf8')
print(result)
assert r'\def\pageautorefname{sayfa}' in result
assert r'\addto\captionsturkish{\renewcommand{\figurename}{Fig.\@{} }}' in result
assert r'\addto\captionsturkish{\renewcommand{\tablename}{Table.\@{} }}' in result
@pytest.mark.sphinx(
2024-08-11 08:58:56 -05:00
'latex',
testroot='latex-babel',
confoverrides={'language': 'ja'},
)
def test_babel_with_language_ja(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
print(result)
print(app.status.getvalue())
print(app.warning.getvalue())
assert '\\documentclass[letterpaper,10pt,dvipdfmx]{sphinxmanual}' in result
assert '\\usepackage{babel}' not in result
assert '\\usepackage{tgtermes}' in result
assert '\\usepackage[Sonny]{fncychap}' not in result
assert '\\renewcommand{\\contentsname}{Table of content}\n' in result
assert '\\shorthandoff' not in result
# sphinxmessages.sty
result = (app.outdir / 'sphinxmessages.sty').read_text(encoding='utf8')
print(result)
assert r'\def\pageautorefname{ページ}' in result
assert '\\@iden{\\renewcommand{\\figurename}{Fig.\\@{} }}' in result
assert '\\@iden{\\renewcommand{\\tablename}{Table.\\@{} }}' in result
@pytest.mark.sphinx(
2024-08-11 08:58:56 -05:00
'latex',
testroot='latex-babel',
confoverrides={'language': 'unknown'},
)
def test_babel_with_unknown_language(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
print(result)
print(app.status.getvalue())
print(app.warning.getvalue())
assert '\\documentclass[letterpaper,10pt,english]{sphinxmanual}' in result
assert '\\usepackage{babel}' in result
assert '\\usepackage{tgtermes}' in result
assert '\\usepackage[Sonny]{fncychap}' in result
2024-08-11 08:58:56 -05:00
assert (
'\\addto\\captionsenglish{\\renewcommand{\\contentsname}{Table of content}}\n'
) in result
assert '\\shorthandoff' in result
2024-08-11 08:58:56 -05:00
assert (
"WARNING: no Babel option known for language 'unknown'"
) in app.warning.getvalue()
# sphinxmessages.sty
result = (app.outdir / 'sphinxmessages.sty').read_text(encoding='utf8')
print(result)
assert r'\def\pageautorefname{page}' in result
assert r'\addto\captionsenglish{\renewcommand{\figurename}{Fig.\@{} }}' in result
assert r'\addto\captionsenglish{\renewcommand{\tablename}{Table.\@{} }}' in result
@pytest.mark.sphinx(
2024-08-11 08:58:56 -05:00
'latex',
testroot='latex-babel',
confoverrides={'language': 'de', 'latex_engine': 'lualatex'},
)
def test_polyglossia_with_language_de(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
print(result)
print(app.status.getvalue())
print(app.warning.getvalue())
assert '\\documentclass[letterpaper,10pt,german]{sphinxmanual}' in result
assert '\\usepackage{polyglossia}' in result
assert '\\setmainlanguage[spelling=new]{german}' in result
assert '\\usepackage{tgtermes}' not in result
assert '\\usepackage[Sonny]{fncychap}' in result
2024-08-11 08:58:56 -05:00
assert (
'\\addto\\captionsgerman{\\renewcommand{\\contentsname}{Table of content}}\n'
) in result
assert '\\shorthandoff' not in result
# sphinxmessages.sty
result = (app.outdir / 'sphinxmessages.sty').read_text(encoding='utf8')
print(result)
assert r'\def\pageautorefname{Seite}' in result
assert r'\addto\captionsgerman{\renewcommand{\figurename}{Fig.\@{} }}' in result
assert r'\addto\captionsgerman{\renewcommand{\tablename}{Table.\@{} }}' in result
@pytest.mark.sphinx(
2024-08-11 08:58:56 -05:00
'latex',
testroot='latex-babel',
confoverrides={'language': 'de-1901', 'latex_engine': 'lualatex'},
)
def test_polyglossia_with_language_de_1901(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
print(result)
print(app.status.getvalue())
print(app.warning.getvalue())
assert '\\documentclass[letterpaper,10pt,german]{sphinxmanual}' in result
assert '\\usepackage{polyglossia}' in result
assert '\\setmainlanguage[spelling=old]{german}' in result
assert '\\usepackage{tgtermes}' not in result
assert '\\usepackage[Sonny]{fncychap}' in result
2024-08-11 08:58:56 -05:00
assert (
'\\addto\\captionsgerman{\\renewcommand{\\contentsname}{Table of content}}\n'
) in result
assert '\\shorthandoff' not in result
# sphinxmessages.sty
result = (app.outdir / 'sphinxmessages.sty').read_text(encoding='utf8')
print(result)
assert r'\def\pageautorefname{page}' in result
assert r'\addto\captionsgerman{\renewcommand{\figurename}{Fig.\@{} }}' in result
assert r'\addto\captionsgerman{\renewcommand{\tablename}{Table.\@{} }}' in result
@pytest.mark.sphinx('latex', testroot='root')
def test_footnote(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'sphinxtests.tex').read_text(encoding='utf8')
print(result)
print(app.status.getvalue())
print(app.warning.getvalue())
2024-08-11 08:58:56 -05:00
assert (
'\\sphinxAtStartPar\n%\n\\begin{footnote}[1]\\sphinxAtStartFootnote\n'
'numbered\n%\n\\end{footnote}'
) in result
assert (
'\\begin{footnote}[2]\\sphinxAtStartFootnote\nauto numbered\n%\n'
'\\end{footnote}'
) in result
assert (
'\\begin{footnote}[3]\\sphinxAtStartFootnote\nnamed\n%\n\\end{footnote}'
) in result
2018-04-28 04:09:33 -05:00
assert '\\sphinxcite{footnote:bar}' in result
2024-08-11 08:58:56 -05:00
assert '\\bibitem[bar]{footnote:bar}\n\\sphinxAtStartPar\ncite\n' in result
assert '\\sphinxcaption{Table caption \\sphinxfootnotemark[4]' in result
2024-08-11 08:58:56 -05:00
assert (
'\\sphinxmidrule\n\\sphinxtableatstartofbodyhook%\n'
'\\begin{footnotetext}[4]\\sphinxAtStartFootnote\n'
'footnote in table caption\n%\n\\end{footnotetext}\\ignorespaces %\n'
'\\begin{footnotetext}[5]\\sphinxAtStartFootnote\n'
'footnote in table header\n%\n\\end{footnotetext}\\ignorespaces '
'\n\\sphinxAtStartPar\n'
'VIDIOC\\_CROPCAP\n&\n\\sphinxAtStartPar\n'
) in result
assert (
'Information about VIDIOC\\_CROPCAP %\n'
'\\begin{footnote}[6]\\sphinxAtStartFootnote\n'
'footnote in table not in header\n%\n\\end{footnote}\n\\\\\n'
'\\sphinxbottomrule\n\\end{tabulary}\n'
'\\sphinxtableafterendhook\\par\n\\sphinxattableend\\end{savenotes}\n'
) in result
@pytest.mark.sphinx('latex', testroot='footnotes')
def test_reference_in_caption_and_codeblock_in_footnote(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
print(result)
print(app.status.getvalue())
print(app.warning.getvalue())
2024-08-11 08:58:56 -05:00
assert (
'\\caption{This is the figure caption with a reference to '
'\\sphinxcite{index:authoryear}.}'
) in result
assert '\\chapter{The section with a reference to {[}AuthorYear{]}}' in result
2024-08-11 08:58:56 -05:00
assert (
'\\sphinxcaption{The table title with a reference to {[}AuthorYear{]}}'
) in result
assert (
'\\subsubsection*{The rubric title with a reference to {[}AuthorYear{]}}'
) in result
assert (
'\\chapter{The section with a reference to \\sphinxfootnotemark[6]}\n'
'\\label{\\detokenize{index:the-section-with-a-reference-to}}'
'%\n\\begin{footnotetext}[6]\\sphinxAtStartFootnote\n'
'Footnote in section\n%\n\\end{footnotetext}'
) in result
assert (
'\\caption{This is the figure caption with a footnote to '
'\\sphinxfootnotemark[8].}\\label{\\detokenize{index:id35}}\\end{figure}\n'
'%\n\\begin{footnotetext}[8]\\sphinxAtStartFootnote\n'
'Footnote in caption\n%\n\\end{footnotetext}'
) in result
assert (
'\\sphinxcaption{footnote \\sphinxfootnotemark[9] in '
'caption of normal table}\\label{\\detokenize{index:id36}}'
) in result
assert (
'\\caption{footnote \\sphinxfootnotemark[10] '
'in caption \\sphinxfootnotemark[11] of longtable\\strut}'
) in result
assert (
'\\endlastfoot\n\\sphinxtableatstartofbodyhook\n%\n'
'\\begin{footnotetext}[10]\\sphinxAtStartFootnote\n'
'Foot note in longtable\n%\n\\end{footnotetext}\\ignorespaces %\n'
'\\begin{footnotetext}[11]\\sphinxAtStartFootnote\n'
'Second footnote in caption of longtable\n'
) in result
assert (
'This is a reference to the code\\sphinxhyphen{}block in the footnote:\n'
'{\\hyperref[\\detokenize{index:codeblockinfootnote}]'
'{\\sphinxcrossref{\\DUrole{std,std-ref}{I am in a footnote}}}}'
) in result
assert (
'&\n\\sphinxAtStartPar\nThis is one more footnote with some code in it %\n'
'\\begin{footnote}[12]\\sphinxAtStartFootnote\n'
'Third footnote in longtable\n'
) in result
assert '\\end{sphinxVerbatim}\n%\n\\end{footnote}.\n' in result
assert '\\begin{sphinxVerbatim}[commandchars=\\\\\\{\\}]' in result
2015-12-06 20:02:45 -06:00
@pytest.mark.sphinx('latex', testroot='footnotes')
def test_footnote_referred_multiple_times(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
print(result)
print(app.status.getvalue())
print(app.warning.getvalue())
2024-08-11 08:58:56 -05:00
assert (
'Explicitly numbered footnote: %\n'
'\\begin{footnote}[100]'
'\\sphinxAtStartFootnote\nNumbered footnote\n%\n'
'\\end{footnote} \\sphinxfootnotemark[100]\n'
) in result
assert (
'Named footnote: %\n'
'\\begin{footnote}[13]'
'\\sphinxAtStartFootnote\nNamed footnote\n%\n'
'\\end{footnote} \\sphinxfootnotemark[13]\n'
) in result
@pytest.mark.sphinx(
2024-08-11 08:58:56 -05:00
'latex',
testroot='footnotes',
confoverrides={'latex_show_urls': 'inline'},
)
def test_latex_show_urls_is_inline(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
2015-12-06 20:02:45 -06:00
print(result)
print(app.status.getvalue())
print(app.warning.getvalue())
2024-08-11 08:58:56 -05:00
assert (
'Same footnote number %\n'
'\\begin{footnote}[1]\\sphinxAtStartFootnote\n'
'footnote in bar\n%\n\\end{footnote} in bar.rst'
) in result
assert (
'Auto footnote number %\n\\begin{footnote}[1]\\sphinxAtStartFootnote\n'
'footnote in baz\n%\n\\end{footnote} in baz.rst'
) in result
assert (
'\\phantomsection\\label{\\detokenize{index:id38}}'
'{\\hyperref[\\detokenize{index:the-section'
'-with-a-reference-to-authoryear}]'
'{\\sphinxcrossref{The section with a reference to '
'\\sphinxcite{index:authoryear}}}}'
) in result
assert (
'\\phantomsection\\label{\\detokenize{index:id39}}'
'{\\hyperref[\\detokenize{index:the-section-with-a-reference-to}]'
'{\\sphinxcrossref{The section with a reference to }}}'
) in result
assert (
'First footnote: %\n\\begin{footnote}[2]\\sphinxAtStartFootnote\n'
'First\n%\n\\end{footnote}'
) in result
assert (
'Second footnote: %\n'
'\\begin{footnote}[1]\\sphinxAtStartFootnote\n'
'Second\n%\n\\end{footnote}\n'
) in result
assert (
'\\sphinxhref{https://sphinx-doc.org/}{Sphinx} (https://sphinx\\sphinxhyphen{}doc.org/)'
) in result
assert (
'Third footnote: %\n\\begin{footnote}[3]\\sphinxAtStartFootnote\n'
'Third \\sphinxfootnotemark[4]\n%\n\\end{footnote}%\n'
'\\begin{footnotetext}[4]\\sphinxAtStartFootnote\n'
'Footnote inside footnote\n%\n\\end{footnotetext}\\ignorespaces'
) in result
assert (
'Fourth footnote: %\n\\begin{footnote}[5]\\sphinxAtStartFootnote\n'
'Fourth\n%\n\\end{footnote}\n'
) in result
assert (
'\\sphinxhref{https://sphinx-doc.org/~test/}{URL including tilde} '
'(https://sphinx\\sphinxhyphen{}doc.org/\\textasciitilde{}test/)'
) in result
assert (
'\\sphinxlineitem{\\sphinxhref{https://sphinx-doc.org/}{URL in term} '
'(https://sphinx\\sphinxhyphen{}doc.org/)}\n'
'\\sphinxAtStartPar\nDescription'
) in result
assert (
'\\sphinxlineitem{Footnote in term \\sphinxfootnotemark[7]}%\n'
'\\begin{footnotetext}[7]\\sphinxAtStartFootnote\n'
) in result
assert (
'\\sphinxlineitem{\\sphinxhref{https://sphinx-doc.org/}{URL in term} '
'(https://sphinx\\sphinxhyphen{}doc.org/)}\n'
'\\sphinxAtStartPar\nDescription'
) in result
assert (
'\\sphinxlineitem{Footnote in term \\sphinxfootnotemark[7]}%\n'
'\\begin{footnotetext}[7]\\sphinxAtStartFootnote\n'
'Footnote in term\n%\n\\end{footnotetext}\\ignorespaces '
'\n\\sphinxAtStartPar\nDescription'
) in result
assert (
'\\sphinxlineitem{\\sphinxhref{https://sphinx-doc.org/}{Term in deflist} '
'(https://sphinx\\sphinxhyphen{}doc.org/)}'
'\n\\sphinxAtStartPar\nDescription'
) in result
assert '\\sphinxurl{https://github.com/sphinx-doc/sphinx}\n' in result
2024-08-11 08:58:56 -05:00
assert (
'\\sphinxhref{mailto:sphinx-dev@googlegroups.com}'
'{sphinx\\sphinxhyphen{}dev@googlegroups.com}'
) in result
2021-02-01 17:00:00 -06:00
assert '\\begin{savenotes}\\begin{fulllineitems}' not in result
2015-12-06 20:02:45 -06:00
@pytest.mark.sphinx(
2024-08-11 08:58:56 -05:00
'latex',
testroot='footnotes',
confoverrides={'latex_show_urls': 'footnote'},
)
def test_latex_show_urls_is_footnote(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
2015-12-06 20:02:45 -06:00
print(result)
print(app.status.getvalue())
print(app.warning.getvalue())
2024-08-11 08:58:56 -05:00
assert (
'Same footnote number %\n'
'\\begin{footnote}[1]\\sphinxAtStartFootnote\n'
'footnote in bar\n%\n\\end{footnote} in bar.rst'
) in result
assert (
'Auto footnote number %\n\\begin{footnote}[2]\\sphinxAtStartFootnote\n'
'footnote in baz\n%\n\\end{footnote} in baz.rst'
) in result
assert (
'\\phantomsection\\label{\\detokenize{index:id38}}'
'{\\hyperref[\\detokenize{index:the-section-with-a-reference-to-authoryear}]'
'{\\sphinxcrossref{The section with a reference '
'to \\sphinxcite{index:authoryear}}}}'
) in result
assert (
'\\phantomsection\\label{\\detokenize{index:id39}}'
'{\\hyperref[\\detokenize{index:the-section-with-a-reference-to}]'
'{\\sphinxcrossref{The section with a reference to }}}'
) in result
assert (
'First footnote: %\n\\begin{footnote}[3]\\sphinxAtStartFootnote\n'
'First\n%\n\\end{footnote}'
) in result
assert (
'Second footnote: %\n'
'\\begin{footnote}[1]\\sphinxAtStartFootnote\n'
'Second\n%\n\\end{footnote}'
) in result
assert (
'\\sphinxhref{https://sphinx-doc.org/}{Sphinx}'
'%\n\\begin{footnote}[4]\\sphinxAtStartFootnote\n'
'\\sphinxnolinkurl{https://sphinx-doc.org/}\n%\n\\end{footnote}'
) in result
assert (
'Third footnote: %\n\\begin{footnote}[6]\\sphinxAtStartFootnote\n'
'Third \\sphinxfootnotemark[7]\n%\n\\end{footnote}%\n'
'\\begin{footnotetext}[7]\\sphinxAtStartFootnote\n'
'Footnote inside footnote\n%\n'
'\\end{footnotetext}\\ignorespaces'
) in result
assert (
'Fourth footnote: %\n\\begin{footnote}[8]\\sphinxAtStartFootnote\n'
'Fourth\n%\n\\end{footnote}\n'
) in result
assert (
'\\sphinxhref{https://sphinx-doc.org/~test/}{URL including tilde}'
'%\n\\begin{footnote}[5]\\sphinxAtStartFootnote\n'
'\\sphinxnolinkurl{https://sphinx-doc.org/~test/}\n%\n\\end{footnote}'
) in result
assert (
'\\sphinxlineitem{\\sphinxhref{https://sphinx-doc.org/}'
'{URL in term}\\sphinxfootnotemark[10]}%\n'
'\\begin{footnotetext}[10]'
'\\sphinxAtStartFootnote\n'
'\\sphinxnolinkurl{https://sphinx-doc.org/}\n%\n'
'\\end{footnotetext}\\ignorespaces \n\\sphinxAtStartPar\nDescription'
) in result
assert (
'\\sphinxlineitem{Footnote in term \\sphinxfootnotemark[12]}%\n'
'\\begin{footnotetext}[12]'
'\\sphinxAtStartFootnote\n'
'Footnote in term\n%\n\\end{footnotetext}\\ignorespaces '
'\n\\sphinxAtStartPar\nDescription'
) in result
assert (
'\\sphinxlineitem{\\sphinxhref{https://sphinx-doc.org/}{Term in deflist}'
'\\sphinxfootnotemark[11]}%\n'
'\\begin{footnotetext}[11]'
'\\sphinxAtStartFootnote\n'
'\\sphinxnolinkurl{https://sphinx-doc.org/}\n%\n'
'\\end{footnotetext}\\ignorespaces \n\\sphinxAtStartPar\nDescription'
) in result
assert '\\sphinxurl{https://github.com/sphinx-doc/sphinx}\n' in result
assert (
'\\sphinxhref{mailto:sphinx-dev@googlegroups.com}'
'{sphinx\\sphinxhyphen{}dev@googlegroups.com}\n'
) in result
2021-02-01 17:00:00 -06:00
assert '\\begin{savenotes}\\begin{fulllineitems}' in result
2015-12-06 20:02:45 -06:00
@pytest.mark.sphinx(
2024-08-11 08:58:56 -05:00
'latex',
testroot='footnotes',
confoverrides={'latex_show_urls': 'no'},
)
def test_latex_show_urls_is_no(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
2015-12-06 20:02:45 -06:00
print(result)
print(app.status.getvalue())
print(app.warning.getvalue())
2024-08-11 08:58:56 -05:00
assert (
'Same footnote number %\n'
'\\begin{footnote}[1]\\sphinxAtStartFootnote\n'
'footnote in bar\n%\n\\end{footnote} in bar.rst'
) in result
assert (
'Auto footnote number %\n\\begin{footnote}[1]\\sphinxAtStartFootnote\n'
'footnote in baz\n%\n\\end{footnote} in baz.rst'
) in result
assert (
'\\phantomsection\\label{\\detokenize{index:id38}}'
'{\\hyperref[\\detokenize{index:the-section-with-a-reference-to-authoryear}]'
'{\\sphinxcrossref{The section with a reference '
'to \\sphinxcite{index:authoryear}}}}'
) in result
assert (
'\\phantomsection\\label{\\detokenize{index:id39}}'
'{\\hyperref[\\detokenize{index:the-section-with-a-reference-to}]'
'{\\sphinxcrossref{The section with a reference to }}}'
) in result
assert (
'First footnote: %\n\\begin{footnote}[2]\\sphinxAtStartFootnote\n'
'First\n%\n\\end{footnote}'
) in result
assert (
'Second footnote: %\n'
'\\begin{footnote}[1]\\sphinxAtStartFootnote\n'
'Second\n%\n\\end{footnote}'
) in result
2024-01-13 22:18:57 -06:00
assert '\\sphinxhref{https://sphinx-doc.org/}{Sphinx}' in result
2024-08-11 08:58:56 -05:00
assert (
'Third footnote: %\n\\begin{footnote}[3]\\sphinxAtStartFootnote\n'
'Third \\sphinxfootnotemark[4]\n%\n\\end{footnote}%\n'
'\\begin{footnotetext}[4]\\sphinxAtStartFootnote\n'
'Footnote inside footnote\n%\n\\end{footnotetext}\\ignorespaces'
) in result
assert (
'Fourth footnote: %\n\\begin{footnote}[5]\\sphinxAtStartFootnote\n'
'Fourth\n%\n\\end{footnote}\n'
) in result
2024-01-13 22:18:57 -06:00
assert '\\sphinxhref{https://sphinx-doc.org/~test/}{URL including tilde}' in result
2024-08-11 08:58:56 -05:00
assert (
'\\sphinxlineitem{\\sphinxhref{https://sphinx-doc.org/}{URL in term}}\n'
'\\sphinxAtStartPar\nDescription'
) in result
assert (
'\\sphinxlineitem{Footnote in term \\sphinxfootnotemark[7]}%\n'
'\\begin{footnotetext}[7]\\sphinxAtStartFootnote\n'
'Footnote in term\n%\n\\end{footnotetext}\\ignorespaces '
'\n\\sphinxAtStartPar\nDescription'
) in result
assert (
'\\sphinxlineitem{\\sphinxhref{https://sphinx-doc.org/}{Term in deflist}}'
'\n\\sphinxAtStartPar\nDescription'
) in result
assert '\\sphinxurl{https://github.com/sphinx-doc/sphinx}\n' in result
assert (
'\\sphinxhref{mailto:sphinx-dev@googlegroups.com}'
'{sphinx\\sphinxhyphen{}dev@googlegroups.com}\n'
) in result
2021-02-01 17:00:00 -06:00
assert '\\begin{savenotes}\\begin{fulllineitems}' not in result
@pytest.mark.sphinx(
2024-08-11 08:58:56 -05:00
'latex',
testroot='footnotes',
confoverrides={
'latex_show_urls': 'footnote',
'rst_prolog': '.. |URL| replace:: `text <https://www.example.com/>`__',
},
)
def test_latex_show_urls_footnote_and_substitutions(app):
# hyperlinks in substitutions should not effect to make footnotes (refs: #4784)
test_latex_show_urls_is_footnote(app)
@pytest.mark.sphinx('latex', testroot='image-in-section')
def test_image_in_section(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
print(result)
print(app.status.getvalue())
print(app.warning.getvalue())
2024-08-11 08:58:56 -05:00
assert (
'\\chapter[Test section]{\\lowercase{\\sphinxincludegraphics'
'[width=15bp,height=15bp]}{{pic}.png} Test section}'
) in result
assert (
'\\chapter[Other {[}blah{]} section]{Other {[}blah{]} '
'\\lowercase{\\sphinxincludegraphics[width=15bp,height=15bp]}'
'{{pic}.png} section}'
) in result
assert '\\chapter{Another section}' in result
2024-08-11 08:58:56 -05:00
@pytest.mark.sphinx(
'latex',
testroot='basic',
confoverrides={'latex_logo': 'notfound.jpg'},
)
def test_latex_logo_if_not_found(app):
2023-02-17 17:46:31 -06:00
with pytest.raises(SphinxError):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
2017-12-20 14:30:05 -06:00
@pytest.mark.sphinx('latex', testroot='toctree-maxdepth')
def test_toctree_maxdepth_manual(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
print(result)
print(app.status.getvalue())
print(app.warning.getvalue())
assert '\\setcounter{tocdepth}{1}' in result
assert '\\setcounter{secnumdepth}' not in result
2017-12-20 14:30:05 -06:00
assert '\\chapter{Foo}' in result
2017-12-23 06:20:32 -06:00
@pytest.mark.sphinx(
2024-08-11 08:58:56 -05:00
'latex',
testroot='toctree-maxdepth',
confoverrides={
'latex_documents': [
(
'index',
'projectnamenotset.tex',
'Sphinx Tests Documentation',
'Georg Brandl',
'howto',
),
]
},
)
def test_toctree_maxdepth_howto(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
print(result)
print(app.status.getvalue())
print(app.warning.getvalue())
assert '\\setcounter{tocdepth}{2}' in result
assert '\\setcounter{secnumdepth}' not in result
2017-12-20 14:30:05 -06:00
assert '\\section{Foo}' in result
2017-12-23 06:20:32 -06:00
@pytest.mark.sphinx(
2024-08-11 08:58:56 -05:00
'latex',
testroot='toctree-maxdepth',
confoverrides={'root_doc': 'foo'},
)
def test_toctree_not_found(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
print(result)
print(app.status.getvalue())
print(app.warning.getvalue())
assert '\\setcounter{tocdepth}' not in result
assert '\\setcounter{secnumdepth}' not in result
2017-12-20 14:30:05 -06:00
assert '\\chapter{Foo A}' in result
2017-12-23 06:20:32 -06:00
@pytest.mark.sphinx(
2024-08-11 08:58:56 -05:00
'latex',
testroot='toctree-maxdepth',
confoverrides={'root_doc': 'bar'},
)
def test_toctree_without_maxdepth(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
print(result)
print(app.status.getvalue())
print(app.warning.getvalue())
assert '\\setcounter{tocdepth}' not in result
assert '\\setcounter{secnumdepth}' not in result
@pytest.mark.sphinx(
2024-08-11 08:58:56 -05:00
'latex',
testroot='toctree-maxdepth',
confoverrides={'root_doc': 'qux'},
)
def test_toctree_with_deeper_maxdepth(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
print(result)
print(app.status.getvalue())
print(app.warning.getvalue())
assert '\\setcounter{tocdepth}{3}' in result
assert '\\setcounter{secnumdepth}{3}' in result
@pytest.mark.sphinx(
2024-08-11 08:58:56 -05:00
'latex',
testroot='toctree-maxdepth',
confoverrides={'latex_toplevel_sectioning': None},
)
def test_latex_toplevel_sectioning_is_None(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
print(result)
print(app.status.getvalue())
print(app.warning.getvalue())
assert '\\chapter{Foo}' in result
@pytest.mark.sphinx(
2024-08-11 08:58:56 -05:00
'latex',
testroot='toctree-maxdepth',
confoverrides={'latex_toplevel_sectioning': 'part'},
)
def test_latex_toplevel_sectioning_is_part(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
print(result)
print(app.status.getvalue())
print(app.warning.getvalue())
assert '\\part{Foo}' in result
2017-12-20 14:30:05 -06:00
assert '\\chapter{Foo A}' in result
assert '\\chapter{Foo B}' in result
@pytest.mark.sphinx(
2024-08-11 08:58:56 -05:00
'latex',
testroot='toctree-maxdepth',
confoverrides={
'latex_toplevel_sectioning': 'part',
'latex_documents': [
(
'index',
'projectnamenotset.tex',
'Sphinx Tests Documentation',
'Georg Brandl',
'howto',
),
],
},
)
def test_latex_toplevel_sectioning_is_part_with_howto(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
2017-12-20 14:30:05 -06:00
print(result)
print(app.status.getvalue())
print(app.warning.getvalue())
2017-12-20 14:30:05 -06:00
assert '\\part{Foo}' in result
assert '\\section{Foo A}' in result
assert '\\section{Foo B}' in result
@pytest.mark.sphinx(
2024-08-11 08:58:56 -05:00
'latex',
testroot='toctree-maxdepth',
confoverrides={'latex_toplevel_sectioning': 'chapter'},
)
def test_latex_toplevel_sectioning_is_chapter(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
print(result)
print(app.status.getvalue())
print(app.warning.getvalue())
assert '\\chapter{Foo}' in result
2017-12-20 14:30:05 -06:00
@pytest.mark.sphinx(
2024-08-11 08:58:56 -05:00
'latex',
testroot='toctree-maxdepth',
confoverrides={
'latex_toplevel_sectioning': 'chapter',
'latex_documents': [
(
'index',
'projectnamenotset.tex',
'Sphinx Tests Documentation',
'Georg Brandl',
'howto',
),
],
},
)
def test_latex_toplevel_sectioning_is_chapter_with_howto(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
2017-12-20 14:30:05 -06:00
print(result)
print(app.status.getvalue())
print(app.warning.getvalue())
2017-12-20 14:30:05 -06:00
assert '\\section{Foo}' in result
@pytest.mark.sphinx(
2024-08-11 08:58:56 -05:00
'latex',
testroot='toctree-maxdepth',
confoverrides={'latex_toplevel_sectioning': 'section'},
)
def test_latex_toplevel_sectioning_is_section(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
print(result)
print(app.status.getvalue())
print(app.warning.getvalue())
assert '\\section{Foo}' in result
2016-11-04 17:57:00 -05:00
2017-01-25 10:13:17 -06:00
@skip_if_stylefiles_notfound
@pytest.mark.sphinx('latex', testroot='maxlistdepth')
def test_maxlistdepth_at_ten(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
2016-11-04 17:57:00 -05:00
print(result)
print(app.status.getvalue())
print(app.warning.getvalue())
compile_latex_document(app, 'projectnamenotset.tex')
2024-08-11 08:58:56 -05:00
@pytest.mark.sphinx(
'latex',
testroot='latex-table',
confoverrides={'latex_table_style': []},
)
@pytest.mark.test_params(shared_result='latex-table')
def test_latex_table_tabulars(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
tables = {}
2017-05-11 04:23:38 -05:00
for chap in re.split(r'\\(?:section|chapter){', result)[1:]:
sectname, content = chap.split('}', 1)
content = re.sub(r'\\sphinxstepscope', '', content) # filter a separator
tables[sectname] = content.strip()
2017-05-11 04:23:38 -05:00
def get_expected(name):
2024-08-11 08:58:56 -05:00
return (
(app.srcdir / 'expects' / (name + '.tex'))
.read_text(encoding='utf8')
.strip()
)
2017-05-11 04:23:38 -05:00
# simple_table
2017-05-11 04:23:38 -05:00
actual = tables['simple table']
expected = get_expected('simple_table')
assert actual == expected
2017-02-04 09:23:35 -06:00
# table having :widths: option
2017-05-11 04:23:38 -05:00
actual = tables['table having :widths: option']
expected = get_expected('table_having_widths')
assert actual == expected
# table having :align: option (tabulary)
2017-05-11 04:23:38 -05:00
actual = tables['table having :align: option (tabulary)']
expected = get_expected('tabulary_having_widths')
assert actual == expected
# table having :align: option (tabular)
2017-05-11 04:23:38 -05:00
actual = tables['table having :align: option (tabular)']
expected = get_expected('tabular_having_widths')
assert actual == expected
# table with tabularcolumn
2017-05-11 04:23:38 -05:00
actual = tables['table with tabularcolumn']
expected = get_expected('tabularcolumn')
assert actual == expected
# table with cell in first column having three paragraphs
actual = tables['table with cell in first column having three paragraphs']
expected = get_expected('table_having_threeparagraphs_cell_in_first_col')
assert actual == expected
# table having caption
2017-05-11 04:23:38 -05:00
actual = tables['table having caption']
expected = get_expected('table_having_caption')
assert actual == expected
2017-02-03 23:40:40 -06:00
# table having verbatim
2017-05-11 04:23:38 -05:00
actual = tables['table having verbatim']
expected = get_expected('table_having_verbatim')
assert actual == expected
2017-02-03 23:40:40 -06:00
# table having problematic cell
2017-05-11 04:23:38 -05:00
actual = tables['table having problematic cell']
expected = get_expected('table_having_problematic_cell')
assert actual == expected
2017-02-03 23:40:40 -06:00
# table having both :widths: and problematic cell
2017-05-11 04:23:38 -05:00
actual = tables['table having both :widths: and problematic cell']
expected = get_expected('table_having_widths_and_problematic_cell')
assert actual == expected
# table having both stub columns and problematic cell
2017-05-11 04:23:38 -05:00
actual = tables['table having both stub columns and problematic cell']
expected = get_expected('table_having_stub_columns_and_problematic_cell')
assert actual == expected
2017-02-07 19:48:12 -06:00
2024-08-11 08:58:56 -05:00
@pytest.mark.sphinx(
'latex',
testroot='latex-table',
confoverrides={'latex_table_style': []},
)
@pytest.mark.test_params(shared_result='latex-table')
def test_latex_table_longtable(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
2017-02-07 19:48:12 -06:00
tables = {}
2017-05-11 04:23:38 -05:00
for chap in re.split(r'\\(?:section|chapter){', result)[1:]:
2017-02-07 19:48:12 -06:00
sectname, content = chap.split('}', 1)
content = re.sub(r'\\sphinxstepscope', '', content) # filter a separator
2017-02-07 19:48:12 -06:00
tables[sectname] = content.strip()
2017-05-11 04:23:38 -05:00
def get_expected(name):
2024-08-11 08:58:56 -05:00
return (
(app.srcdir / 'expects' / (name + '.tex'))
.read_text(encoding='utf8')
.strip()
)
2017-05-11 04:23:38 -05:00
# longtable
2017-05-11 04:23:38 -05:00
actual = tables['longtable']
expected = get_expected('longtable')
assert actual == expected
2017-02-03 23:40:40 -06:00
# longtable having :widths: option
2017-05-11 04:23:38 -05:00
actual = tables['longtable having :widths: option']
expected = get_expected('longtable_having_widths')
assert actual == expected
2017-02-03 23:40:40 -06:00
# longtable having :align: option
2017-05-11 04:23:38 -05:00
actual = tables['longtable having :align: option']
expected = get_expected('longtable_having_align')
assert actual == expected
# longtable with tabularcolumn
2017-05-11 04:23:38 -05:00
actual = tables['longtable with tabularcolumn']
expected = get_expected('longtable_with_tabularcolumn')
assert actual == expected
2017-02-03 23:40:40 -06:00
# longtable having caption
2017-05-11 04:23:38 -05:00
actual = tables['longtable having caption']
expected = get_expected('longtable_having_caption')
assert actual == expected
2017-02-03 23:40:40 -06:00
# longtable having verbatim
2017-05-11 04:23:38 -05:00
actual = tables['longtable having verbatim']
expected = get_expected('longtable_having_verbatim')
assert actual == expected
2017-02-03 23:40:40 -06:00
# longtable having problematic cell
2017-05-11 04:23:38 -05:00
actual = tables['longtable having problematic cell']
expected = get_expected('longtable_having_problematic_cell')
assert actual == expected
2017-02-03 23:40:40 -06:00
# longtable having both :widths: and problematic cell
2017-05-11 04:23:38 -05:00
actual = tables['longtable having both :widths: and problematic cell']
expected = get_expected('longtable_having_widths_and_problematic_cell')
assert actual == expected
# longtable having both stub columns and problematic cell
2017-05-11 04:23:38 -05:00
actual = tables['longtable having both stub columns and problematic cell']
expected = get_expected('longtable_having_stub_columns_and_problematic_cell')
assert actual == expected
2024-08-11 08:58:56 -05:00
@pytest.mark.sphinx(
'latex',
testroot='latex-table',
confoverrides={'latex_table_style': []},
)
@pytest.mark.test_params(shared_result='latex-table')
def test_latex_table_complex_tables(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
tables = {}
2017-05-11 04:23:38 -05:00
for chap in re.split(r'\\(?:section|renewcommand){', result)[1:]:
sectname, content = chap.split('}', 1)
tables[sectname] = content.strip()
2017-05-11 04:23:38 -05:00
def get_expected(name):
2024-08-11 08:58:56 -05:00
return (
(app.srcdir / 'expects' / (name + '.tex'))
.read_text(encoding='utf8')
.strip()
)
2017-05-11 04:23:38 -05:00
# grid table
2017-05-11 04:23:38 -05:00
actual = tables['grid table']
expected = get_expected('gridtable')
assert actual == expected
LaTeX: support for booktabs-style and zebra-striped tables (#10759) This is a combination of 2 + 28 + 7 + and some more commits... * Cherry-pick: Add support for booktabs-style tables to LaTeX builder * Cherry-pick: Add support for zebra-striped tables to LaTeX builder Co-authored-by: Stefan Wiehler <stefan.wiehler@missinglinkelectronics.com> Above work originally initiated by @sephalon (thanks!) Development refactored and continued by @jfbu * latex_table_style configuration, support booktabs, colorrows, borderless Some details: - Simplify a bit a conditional in the longtable template This also puts the target for a longtable with a label but no caption above the toprule for better hyperlinking (testing shows hyperlink target can not end up alone at bottom of previous page). - Extend allowed syntax for colour assignments via 'sphinxsetup' - latex_table_style new configuration value and coloured rows For the user interface I tried to look for inspiration in https://docutils.sourceforge.io/docs/user/config.html#table-style which mentions booktabs and borderless. They also mention captionbelow which we can implement later, now that architecture is here. They don't mention coloured rows. - Test on our own document... looks fine! - Work-around an incompatibility of \cline with row colours - Reverse priority of classes to allow overruling booktabs by standard after parsing source but before letting LaTeX writer act - Closes #8220 Commit https://github.com/sphinx-doc/sphinx/commit/bb859c669679baebd8cc8d10c99382478c0d1647 already improved a bit, this finishes it (as :rst:dir:`rst-class` was actually not linking to anywhere). - Let booktabs style defaults to *not* using \cmidrule. They actually don't make much sense there, as all \hline's are removed. - Add \sphinxnorowcolor which allows construct such as this one in a tabularcolumns directive: >{\columncolor{blue}\sphinxnorowcolor} else LaTeX always overrides column colour by row colour - Add TableMergeColorHeader, TableMergeColorOdd, TableMergeColorEven so single-row merged cells can be styled especially - Extend row colours to all header rows not only the first one (all header rows will share same colour settings) - Auto-adjust to a no '|'-colspec for optimal handling of merged cell - Add \sphinxcolorblend - Workaround LaTeX's \cline features and other grid tables matters - Add \sphinxbuildwarning for important warnings - Fix some white gaps in merged cells of tables with vlines and colorrows - Work around LaTeX's \cline serious deficiencies for complex grid tables This commit corrects \cline badly impacting vertical spacing and making tables look even more cramped as they usually are in LaTeX (although one sees it clearly only with \arrarrulewidth a bit more than the LaTeX default of 0.4pt). Most importantly this commit solves the problem that \cline's got masked by colour panels from the row below. - Update CHANGES for PR #10759 - Improve documentation of new latex_table_style regarding colours
2022-10-12 10:15:40 -05:00
# grid table with tabularcolumns
# MEMO: filename should end with tabularcolumns but tabularcolumn has been
# used in existing other cases
actual = tables['grid table with tabularcolumns having no vline']
expected = get_expected('gridtable_with_tabularcolumn')
assert actual == expected
# complex spanning cell
2017-05-11 04:23:38 -05:00
actual = tables['complex spanning cell']
expected = get_expected('complex_spanning_cell')
assert actual == expected
@pytest.mark.sphinx('latex', testroot='latex-table')
def test_latex_table_with_booktabs_and_colorrows(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
LaTeX: support for booktabs-style and zebra-striped tables (#10759) This is a combination of 2 + 28 + 7 + and some more commits... * Cherry-pick: Add support for booktabs-style tables to LaTeX builder * Cherry-pick: Add support for zebra-striped tables to LaTeX builder Co-authored-by: Stefan Wiehler <stefan.wiehler@missinglinkelectronics.com> Above work originally initiated by @sephalon (thanks!) Development refactored and continued by @jfbu * latex_table_style configuration, support booktabs, colorrows, borderless Some details: - Simplify a bit a conditional in the longtable template This also puts the target for a longtable with a label but no caption above the toprule for better hyperlinking (testing shows hyperlink target can not end up alone at bottom of previous page). - Extend allowed syntax for colour assignments via 'sphinxsetup' - latex_table_style new configuration value and coloured rows For the user interface I tried to look for inspiration in https://docutils.sourceforge.io/docs/user/config.html#table-style which mentions booktabs and borderless. They also mention captionbelow which we can implement later, now that architecture is here. They don't mention coloured rows. - Test on our own document... looks fine! - Work-around an incompatibility of \cline with row colours - Reverse priority of classes to allow overruling booktabs by standard after parsing source but before letting LaTeX writer act - Closes #8220 Commit https://github.com/sphinx-doc/sphinx/commit/bb859c669679baebd8cc8d10c99382478c0d1647 already improved a bit, this finishes it (as :rst:dir:`rst-class` was actually not linking to anywhere). - Let booktabs style defaults to *not* using \cmidrule. They actually don't make much sense there, as all \hline's are removed. - Add \sphinxnorowcolor which allows construct such as this one in a tabularcolumns directive: >{\columncolor{blue}\sphinxnorowcolor} else LaTeX always overrides column colour by row colour - Add TableMergeColorHeader, TableMergeColorOdd, TableMergeColorEven so single-row merged cells can be styled especially - Extend row colours to all header rows not only the first one (all header rows will share same colour settings) - Auto-adjust to a no '|'-colspec for optimal handling of merged cell - Add \sphinxcolorblend - Workaround LaTeX's \cline features and other grid tables matters - Add \sphinxbuildwarning for important warnings - Fix some white gaps in merged cells of tables with vlines and colorrows - Work around LaTeX's \cline serious deficiencies for complex grid tables This commit corrects \cline badly impacting vertical spacing and making tables look even more cramped as they usually are in LaTeX (although one sees it clearly only with \arrarrulewidth a bit more than the LaTeX default of 0.4pt). Most importantly this commit solves the problem that \cline's got masked by colour panels from the row below. - Update CHANGES for PR #10759 - Improve documentation of new latex_table_style regarding colours
2022-10-12 10:15:40 -05:00
assert r'\PassOptionsToPackage{booktabs}{sphinx}' in result
assert r'\PassOptionsToPackage{colorrows}{sphinx}' in result
# tabularcolumns
assert r'\begin{longtable}{|c|c|}' in result
LaTeX: support for booktabs-style and zebra-striped tables (#10759) This is a combination of 2 + 28 + 7 + and some more commits... * Cherry-pick: Add support for booktabs-style tables to LaTeX builder * Cherry-pick: Add support for zebra-striped tables to LaTeX builder Co-authored-by: Stefan Wiehler <stefan.wiehler@missinglinkelectronics.com> Above work originally initiated by @sephalon (thanks!) Development refactored and continued by @jfbu * latex_table_style configuration, support booktabs, colorrows, borderless Some details: - Simplify a bit a conditional in the longtable template This also puts the target for a longtable with a label but no caption above the toprule for better hyperlinking (testing shows hyperlink target can not end up alone at bottom of previous page). - Extend allowed syntax for colour assignments via 'sphinxsetup' - latex_table_style new configuration value and coloured rows For the user interface I tried to look for inspiration in https://docutils.sourceforge.io/docs/user/config.html#table-style which mentions booktabs and borderless. They also mention captionbelow which we can implement later, now that architecture is here. They don't mention coloured rows. - Test on our own document... looks fine! - Work-around an incompatibility of \cline with row colours - Reverse priority of classes to allow overruling booktabs by standard after parsing source but before letting LaTeX writer act - Closes #8220 Commit https://github.com/sphinx-doc/sphinx/commit/bb859c669679baebd8cc8d10c99382478c0d1647 already improved a bit, this finishes it (as :rst:dir:`rst-class` was actually not linking to anywhere). - Let booktabs style defaults to *not* using \cmidrule. They actually don't make much sense there, as all \hline's are removed. - Add \sphinxnorowcolor which allows construct such as this one in a tabularcolumns directive: >{\columncolor{blue}\sphinxnorowcolor} else LaTeX always overrides column colour by row colour - Add TableMergeColorHeader, TableMergeColorOdd, TableMergeColorEven so single-row merged cells can be styled especially - Extend row colours to all header rows not only the first one (all header rows will share same colour settings) - Auto-adjust to a no '|'-colspec for optimal handling of merged cell - Add \sphinxcolorblend - Workaround LaTeX's \cline features and other grid tables matters - Add \sphinxbuildwarning for important warnings - Fix some white gaps in merged cells of tables with vlines and colorrows - Work around LaTeX's \cline serious deficiencies for complex grid tables This commit corrects \cline badly impacting vertical spacing and making tables look even more cramped as they usually are in LaTeX (although one sees it clearly only with \arrarrulewidth a bit more than the LaTeX default of 0.4pt). Most importantly this commit solves the problem that \cline's got masked by colour panels from the row below. - Update CHANGES for PR #10759 - Improve documentation of new latex_table_style regarding colours
2022-10-12 10:15:40 -05:00
# class: standard
assert r'\begin{tabulary}{\linewidth}[t]{|T|T|T|T|T|}' in result
assert r'\begin{longtable}{ll}' in result
LaTeX: support for booktabs-style and zebra-striped tables (#10759) This is a combination of 2 + 28 + 7 + and some more commits... * Cherry-pick: Add support for booktabs-style tables to LaTeX builder * Cherry-pick: Add support for zebra-striped tables to LaTeX builder Co-authored-by: Stefan Wiehler <stefan.wiehler@missinglinkelectronics.com> Above work originally initiated by @sephalon (thanks!) Development refactored and continued by @jfbu * latex_table_style configuration, support booktabs, colorrows, borderless Some details: - Simplify a bit a conditional in the longtable template This also puts the target for a longtable with a label but no caption above the toprule for better hyperlinking (testing shows hyperlink target can not end up alone at bottom of previous page). - Extend allowed syntax for colour assignments via 'sphinxsetup' - latex_table_style new configuration value and coloured rows For the user interface I tried to look for inspiration in https://docutils.sourceforge.io/docs/user/config.html#table-style which mentions booktabs and borderless. They also mention captionbelow which we can implement later, now that architecture is here. They don't mention coloured rows. - Test on our own document... looks fine! - Work-around an incompatibility of \cline with row colours - Reverse priority of classes to allow overruling booktabs by standard after parsing source but before letting LaTeX writer act - Closes #8220 Commit https://github.com/sphinx-doc/sphinx/commit/bb859c669679baebd8cc8d10c99382478c0d1647 already improved a bit, this finishes it (as :rst:dir:`rst-class` was actually not linking to anywhere). - Let booktabs style defaults to *not* using \cmidrule. They actually don't make much sense there, as all \hline's are removed. - Add \sphinxnorowcolor which allows construct such as this one in a tabularcolumns directive: >{\columncolor{blue}\sphinxnorowcolor} else LaTeX always overrides column colour by row colour - Add TableMergeColorHeader, TableMergeColorOdd, TableMergeColorEven so single-row merged cells can be styled especially - Extend row colours to all header rows not only the first one (all header rows will share same colour settings) - Auto-adjust to a no '|'-colspec for optimal handling of merged cell - Add \sphinxcolorblend - Workaround LaTeX's \cline features and other grid tables matters - Add \sphinxbuildwarning for important warnings - Fix some white gaps in merged cells of tables with vlines and colorrows - Work around LaTeX's \cline serious deficiencies for complex grid tables This commit corrects \cline badly impacting vertical spacing and making tables look even more cramped as they usually are in LaTeX (although one sees it clearly only with \arrarrulewidth a bit more than the LaTeX default of 0.4pt). Most importantly this commit solves the problem that \cline's got masked by colour panels from the row below. - Update CHANGES for PR #10759 - Improve documentation of new latex_table_style regarding colours
2022-10-12 10:15:40 -05:00
assert r'\begin{tabular}[t]{*{2}{\X{1}{2}}}' in result
assert r'\begin{tabular}[t]{\X{30}{100}\X{70}{100}}' in result
2024-08-11 08:58:56 -05:00
@pytest.mark.sphinx(
'latex',
testroot='latex-table',
confoverrides={'templates_path': ['_mytemplates/latex']},
)
def test_latex_table_custom_template_caseA(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
assert 'SALUT LES COPAINS' in result
assert 'AU REVOIR, KANIGGETS' in result
2024-08-11 08:58:56 -05:00
@pytest.mark.sphinx(
'latex',
testroot='latex-table',
confoverrides={'templates_path': ['_mytemplates']},
)
def test_latex_table_custom_template_caseB(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'projectnamenotset.tex').read_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):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
assert 'SALUT LES COPAINS' not in result
@pytest.mark.sphinx('latex', testroot='directives-raw')
def test_latex_raw_directive(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
# standard case
assert 'standalone raw directive (HTML)' not in result
2024-08-11 08:58:56 -05:00
assert (
'\\label{\\detokenize{index:id1}}\nstandalone raw directive (LaTeX)'
) in result
# with substitution
assert 'HTML: abc ghi' in result
assert 'LaTeX: abc def ghi' in result
@pytest.mark.sphinx('latex', testroot='images')
def test_latex_images(app):
with http_server(RemoteImageHandler, port=7777):
app.build(force_all=True)
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
# images are copied
assert '\\sphinxincludegraphics{{sphinx}.png}' in result
assert (app.outdir / 'sphinx.png').exists()
# not found images
assert '\\sphinxincludegraphics{{NOT_EXIST}.PNG}' not in result
2024-08-11 08:58:56 -05:00
assert (
'WARNING: Could not fetch remote image: '
'http://localhost:7777/NOT_EXIST.PNG [404]'
) in app.warning.getvalue()
# an image having target
2024-08-11 08:58:56 -05:00
assert (
'\\sphinxhref{https://www.sphinx-doc.org/}'
'{\\sphinxincludegraphics{{rimg}.png}}\n\n'
) in result
2024-08-11 08:58:56 -05:00
# a centered image having target
assert (
'\\sphinxhref{https://www.python.org/}{{\\hspace*{\\fill}'
'\\sphinxincludegraphics{{rimg}.png}\\hspace*{\\fill}}}\n\n'
) in result
@pytest.mark.sphinx('latex', testroot='latex-index')
def test_latex_index(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
2024-08-11 08:58:56 -05:00
assert (
'A \\index{famous@\\spxentry{famous}}famous '
'\\index{equation@\\spxentry{equation}}equation:\n'
) in result
assert (
'\n\\index{Einstein@\\spxentry{Einstein}}'
'\\index{relativity@\\spxentry{relativity}}'
'\\ignorespaces \n\\sphinxAtStartPar\nand'
) in result
assert (
'\n\\index{main \\sphinxleftcurlybrace{}@\\spxentry{'
'main \\sphinxleftcurlybrace{}}}\\ignorespaces '
) in result
@pytest.mark.sphinx('latex', testroot='latex-equations')
def test_latex_equations(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
2024-08-11 08:58:56 -05:00
expected = (
(app.srcdir / 'expects' / 'latex-equations.tex')
.read_text(encoding='utf8')
.strip()
)
assert expected in result
@pytest.mark.sphinx('latex', testroot='image-in-parsed-literal')
def test_latex_image_in_parsed_literal(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
2024-08-11 08:58:56 -05:00
assert (
'{\\sphinxunactivateextrasandspace \\raisebox{-0.5\\height}'
'{\\sphinxincludegraphics[height=2.00000cm]{{pic}.png}}'
'}AFTER'
) in result
@pytest.mark.sphinx('latex', testroot='nested-enumerated-list')
def test_latex_nested_enumerated_list(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
2024-08-11 08:58:56 -05:00
assert (
'\\sphinxsetlistlabels{\\arabic}{enumi}{enumii}{}{.}%\n'
'\\setcounter{enumi}{4}\n'
) in result
assert (
'\\sphinxsetlistlabels{\\alph}{enumii}{enumiii}{}{.}%\n'
'\\setcounter{enumii}{3}\n'
) in result
assert (
'\\sphinxsetlistlabels{\\arabic}{enumiii}{enumiv}{}{)}%\n'
'\\setcounter{enumiii}{9}\n'
) in result
assert (
'\\sphinxsetlistlabels{\\arabic}{enumiv}{enumv}{(}{)}%\n'
'\\setcounter{enumiv}{23}\n'
) in result
assert (
'\\sphinxsetlistlabels{\\roman}{enumii}{enumiii}{}{.}%\n'
'\\setcounter{enumii}{2}\n'
) in result
2018-04-25 11:13:54 -05:00
@pytest.mark.sphinx('latex', testroot='footnotes')
def test_latex_thebibliography(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
2018-04-25 11:13:54 -05:00
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
2018-04-25 11:13:54 -05:00
print(result)
2024-08-11 08:58:56 -05:00
assert (
'\\begin{sphinxthebibliography}{AuthorYe}\n'
'\\bibitem[AuthorYear]{index:authoryear}\n\\sphinxAtStartPar\n'
'Author, Title, Year\n'
'\\end{sphinxthebibliography}\n'
) in result
2018-04-28 04:09:33 -05:00
assert '\\sphinxcite{index:authoryear}' in result
2018-05-23 07:41:45 -05:00
@pytest.mark.sphinx('latex', testroot='glossary')
def test_latex_glossary(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
2024-08-11 08:58:56 -05:00
assert (
r'\sphinxlineitem{ähnlich\index{ähnlich@\spxentry{ähnlich}|spxpagem}'
r'\phantomsection'
r'\label{\detokenize{index:term-ahnlich}}}'
) in result
assert (
r'\sphinxlineitem{boson\index{boson@\spxentry{boson}|spxpagem}\phantomsection'
r'\label{\detokenize{index:term-boson}}}'
) in result
assert (
r'\sphinxlineitem{\sphinxstyleemphasis{fermion}'
r'\index{fermion@\spxentry{fermion}|spxpagem}'
r'\phantomsection'
r'\label{\detokenize{index:term-fermion}}}'
) in result
assert (
r'\sphinxlineitem{tauon\index{tauon@\spxentry{tauon}|spxpagem}\phantomsection'
r'\label{\detokenize{index:term-tauon}}}'
r'\sphinxlineitem{myon\index{myon@\spxentry{myon}|spxpagem}\phantomsection'
r'\label{\detokenize{index:term-myon}}}'
r'\sphinxlineitem{electron\index{electron@\spxentry{electron}|spxpagem}\phantomsection'
r'\label{\detokenize{index:term-electron}}}'
) in result
assert (
r'\sphinxlineitem{über\index{über@\spxentry{über}|spxpagem}\phantomsection'
r'\label{\detokenize{index:term-uber}}}'
) in result
@pytest.mark.sphinx('latex', testroot='latex-labels')
def test_latex_labels(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
# figures
2024-08-11 08:58:56 -05:00
assert (
r'\caption{labeled figure}'
r'\label{\detokenize{index:id1}}'
r'\label{\detokenize{index:figure2}}'
r'\label{\detokenize{index:figure1}}'
r'\end{figure}'
) in result
assert (
r'\caption{labeled figure}'
'\\label{\\detokenize{index:figure3}}\n'
'\\begin{sphinxlegend}\n\\sphinxAtStartPar\n'
'with a legend\n\\end{sphinxlegend}\n'
r'\end{figure}'
) in result
# code-blocks
2024-08-11 08:58:56 -05:00
assert (
r'\def\sphinxLiteralBlockLabel{'
r'\label{\detokenize{index:codeblock2}}'
r'\label{\detokenize{index:codeblock1}}}'
) in result
assert (
r'\def\sphinxLiteralBlockLabel{\label{\detokenize{index:codeblock3}}}'
) in result
# tables
2024-08-11 08:58:56 -05:00
assert (
r'\sphinxcaption{table caption}'
r'\label{\detokenize{index:id2}}'
r'\label{\detokenize{index:table2}}'
r'\label{\detokenize{index:table1}}'
) in result
assert r'\sphinxcaption{table caption}\label{\detokenize{index:table3}}' in result
# sections
2024-08-11 08:58:56 -05:00
assert (
'\\chapter{subsection}\n'
r'\label{\detokenize{index:subsection}}'
r'\label{\detokenize{index:section2}}'
r'\label{\detokenize{index:section1}}'
) in result
assert (
'\\section{subsubsection}\n'
r'\label{\detokenize{index:subsubsection}}'
r'\label{\detokenize{index:section3}}'
) in result
assert (
'\\subsection{otherdoc}\n'
r'\label{\detokenize{otherdoc:otherdoc}}'
r'\label{\detokenize{otherdoc::doc}}'
) in result
2020-07-18 19:43:11 -05:00
# Embedded standalone hyperlink reference (refs: #5948)
assert result.count(r'\label{\detokenize{index:section1}}') == 1
2019-02-03 08:20:26 -06:00
@pytest.mark.sphinx('latex', testroot='latex-figure-in-admonition')
def test_latex_figure_in_admonition(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
assert 'tabulary' not in result
for type in ('caution', 'note', 'seealso', 'todo'):
assert f'{type} directive.\n\n\\begin{{figure}}[H]' in result
2019-06-30 00:55:22 -05:00
def test_default_latex_documents():
from sphinx.util import texescape
2024-08-11 08:58:56 -05:00
texescape.init()
2024-08-11 08:58:56 -05:00
config = Config({
'root_doc': 'index',
'project': 'STASI™ Documentation',
'author': "Wolfgang Schäuble & G'Beckstein.",
})
config.add('latex_engine', None, True, None)
2019-12-28 04:36:55 -06:00
config.add('latex_theme', 'manual', True, None)
2024-08-11 08:58:56 -05:00
expected = [
(
'index',
'stasi.tex',
'STASI™ Documentation',
r'Wolfgang Schäuble \& G\textquotesingle{}Beckstein.\@{}',
'manual',
)
]
assert default_latex_documents(config) == expected
@skip_if_requested
@skip_if_stylefiles_notfound
@pytest.mark.sphinx('latex', testroot='latex-includegraphics')
def test_includegraphics_oversized(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
print(app.status.getvalue())
print(app.warning.getvalue())
compile_latex_document(app)
2019-03-10 01:52:51 -06:00
@pytest.mark.sphinx('latex', testroot='index_on_title')
def test_index_on_title(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
2024-08-11 08:58:56 -05:00
assert (
'\\chapter{Test for index in top level title}\n'
'\\label{\\detokenize{contents:test-for-index-in-top-level-title}}'
'\\index{index@\\spxentry{index}}\n'
) in result
2024-08-11 08:58:56 -05:00
@pytest.mark.sphinx(
'latex',
testroot='latex-unicode',
confoverrides={'latex_engine': 'pdflatex'},
)
def test_texescape_for_non_unicode_supported_engine(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
print(result)
assert 'script small e: e' in result
assert 'double struck italic small i: i' in result
assert r'superscript: \(\sp{\text{0}}\), \(\sp{\text{1}}\)' in result
assert r'subscript: \(\sb{\text{0}}\), \(\sb{\text{1}}\)' in result
2024-08-11 08:58:56 -05:00
@pytest.mark.sphinx(
'latex',
testroot='latex-unicode',
confoverrides={'latex_engine': 'xelatex'},
)
def test_texescape_for_unicode_supported_engine(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
print(result)
assert 'script small e: e' in result
assert 'double struck italic small i: i' in result
assert 'superscript: ⁰, ¹' in result
assert 'subscript: ₀, ₁' in result
2024-08-11 08:58:56 -05:00
@pytest.mark.sphinx(
'latex',
testroot='basic',
confoverrides={'latex_elements': {'extrapackages': r'\usepackage{foo}'}},
)
def test_latex_elements_extrapackages(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'test.tex').read_text(encoding='utf8')
assert r'\usepackage{foo}' in result
@pytest.mark.sphinx('latex', testroot='nested-tables')
def test_latex_nested_tables(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
assert app.warning.getvalue() == ''
2021-05-15 15:53:36 -05:00
@pytest.mark.sphinx('latex', testroot='latex-container')
def test_latex_container(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
2021-07-04 14:15:56 -05:00
assert r'\begin{sphinxuseclass}{classname}' in result
assert r'\end{sphinxuseclass}' in result
@pytest.mark.sphinx('latex', testroot='reST-code-role')
def test_latex_code_role(app):
app.build()
content = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
common_content = (
r'\PYG{k}{def} '
r'\PYG{n+nf}{foo}'
r'\PYG{p}{(}'
r'\PYG{l+m+mi}{1} '
r'\PYG{o}{+} '
r'\PYG{l+m+mi}{2} '
r'\PYG{o}{+} '
r'\PYG{k+kc}{None} '
r'\PYG{o}{+} '
r'\PYG{l+s+s2}{\PYGZdq{}}'
r'\PYG{l+s+s2}{abc}'
r'\PYG{l+s+s2}{\PYGZdq{}}'
r'\PYG{p}{)}'
r'\PYG{p}{:} '
2024-08-11 08:58:56 -05:00
r'\PYG{k}{pass}'
)
assert (
r'Inline \sphinxcode{\sphinxupquote{%' # NoQA: ISC003
+ '\n'
+ common_content
+ '%\n}} code block'
) in content
assert (
r'\begin{sphinxVerbatim}[commandchars=\\\{\}]'
'\n' + common_content + '\n' + r'\end{sphinxVerbatim}'
) in content
@pytest.mark.usefixtures('_http_teapot')
@pytest.mark.sphinx('latex', testroot='images')
def test_copy_images(app):
app.build()
test_dir = Path(app.outdir)
images = {
2024-08-11 08:58:56 -05:00
image.name
for image in test_dir.rglob('*')
if image.suffix in {'.gif', '.pdf', '.png', '.svg'}
}
images.discard('sphinx.png')
assert images == {
'ba30773957c3fe046897111afd65a80b81cad089.png', # latex: image from data:image/png URI in source
'img.pdf',
'rimg.png',
'testimäge.png',
2024-08-11 08:58:56 -05:00
} # fmt: skip
@pytest.mark.sphinx('latex', testroot='latex-labels-before-module')
def test_duplicated_labels_before_module(app):
app.build()
content: str = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
def count_label(name):
text = r'\phantomsection\label{\detokenize{%s}}' % name
return content.count(text)
2024-08-11 08:58:56 -05:00
pattern = (
r'\\phantomsection\\label\{\\detokenize\{index:label-(?:auto-)?\d+[a-z]*}}'
)
2023-04-17 05:13:29 -05:00
# labels found in the TeX output
output_labels = frozenset(match.group() for match in re.finditer(pattern, content))
# labels that have been tested and occurring exactly once in the output
tested_labels = set()
# iterate over the (explicit) labels in the corresponding index.rst
2023-04-17 05:13:29 -05:00
for rst_label_name in [
2024-08-11 08:58:56 -05:00
'label_1a',
'label_1b',
'label_2',
'label_3',
'label_auto_1a',
'label_auto_1b',
'label_auto_2',
'label_auto_3',
2023-04-17 05:13:29 -05:00
]:
tex_label_name = 'index:' + rst_label_name.replace('_', '-')
tex_label_code = r'\phantomsection\label{\detokenize{%s}}' % tex_label_name
2024-08-11 08:58:56 -05:00
assert (
content.count(tex_label_code) == 1
), f'duplicated label: {tex_label_name!r}'
2023-04-17 05:13:29 -05:00
tested_labels.add(tex_label_code)
2023-04-17 05:13:29 -05:00
# ensure that we did not forget any label to check
# and if so, report them nicely in case of failure
assert sorted(tested_labels) == sorted(output_labels)
2024-08-11 08:58:56 -05:00
@pytest.mark.sphinx(
'latex',
testroot='domain-py-python_maximum_signature_line_length',
confoverrides={'python_maximum_signature_line_length': 23},
)
def test_one_parameter_per_line(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
# TODO: should these asserts check presence or absence of a final \sphinxparamcomma?
# signature of 23 characters is too short to trigger one-param-per-line mark-up
2024-08-11 08:58:56 -05:00
assert '\\pysiglinewithargsret{\\sphinxbfcode{\\sphinxupquote{hello}}}' in result
2024-08-11 08:58:56 -05:00
assert '\\pysigwithonelineperarg{\\sphinxbfcode{\\sphinxupquote{foo}}}' in result
# generic_arg[T]
2024-08-11 08:58:56 -05:00
assert (
'\\pysiglinewithargsretwithtypelist{\\sphinxbfcode{\\sphinxupquote{generic\\_arg}}}'
'{\\sphinxtypeparam{\\DUrole{n}{T}}}{}{}'
) in result
# generic_foo[T]()
2024-08-11 08:58:56 -05:00
assert (
'\\pysiglinewithargsretwithtypelist{\\sphinxbfcode{\\sphinxupquote{generic\\_foo}}}'
) in result
# generic_bar[T](x: list[T])
2024-08-11 08:58:56 -05:00
assert (
'\\pysigwithonelineperargwithtypelist{\\sphinxbfcode{\\sphinxupquote{generic\\_bar}}}'
) in result
# generic_ret[R]() -> R
2024-08-11 08:58:56 -05:00
assert (
'\\pysiglinewithargsretwithtypelist{\\sphinxbfcode{\\sphinxupquote{generic\\_ret}}}'
'{\\sphinxtypeparam{\\DUrole{n}{R}}}{}{{ $\\rightarrow$ R}}'
) in result
# MyGenericClass[X]
2024-08-11 08:58:56 -05:00
assert (
'\\pysiglinewithargsretwithtypelist{\\sphinxbfcode{\\sphinxupquote{class\\DUrole{w}{ '
'}}}\\sphinxbfcode{\\sphinxupquote{MyGenericClass}}}'
) in result
# MyList[T](list[T])
2024-08-11 08:58:56 -05:00
assert (
'\\pysiglinewithargsretwithtypelist{\\sphinxbfcode{\\sphinxupquote{class\\DUrole{w}{ '
'}}}\\sphinxbfcode{\\sphinxupquote{MyList}}}'
) in result
@pytest.mark.sphinx('latex', testroot='markup-rubric')
def test_latex_rubric(app):
app.build()
content = (app.outdir / 'test.tex').read_text(encoding='utf8')
assert r'\subsubsection*{This is a rubric}' in content
assert r'\subsection*{A rubric with a heading level 2}' in content