summaryrefslogtreecommitdiff
path: root/tests/test_build_latex.py
blob: 28ae183ca517bcc434f53ffb2c9d5757a384bd18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
# -*- coding: utf-8 -*-
"""
    test_build_latex
    ~~~~~~~~~~~~~~~~

    Test the build process with LaTeX builder with the test root.

    :copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS.
    :license: BSD, see LICENSE for details.
"""
from __future__ import print_function

import os
import re
from subprocess import Popen, PIPE

from six import PY3

from sphinx.errors import SphinxError
from sphinx.writers.latex import LaTeXTranslator

from util import SkipTest, remove_unicode_literals, with_app
from test_build_html import ENV_WARNINGS


LATEX_WARNINGS = ENV_WARNINGS + """\
%(root)s/footnote.txt:60: WARNING: citation not found: missing
%(root)s/images.txt:20: WARNING: no matching candidate for image URI u'foo.\\*'
"""

if PY3:
    LATEX_WARNINGS = remove_unicode_literals(LATEX_WARNINGS)


@with_app(buildername='latex', freshenv=True)  # use freshenv to check warnings
def test_latex(app, status, warning):
    LaTeXTranslator.ignore_missing_images = True
    app.builder.build_all()
    latex_warnings = warning.getvalue().replace(os.sep, '/')
    latex_warnings_exp = LATEX_WARNINGS % {
        'root': re.escape(app.srcdir.replace(os.sep, '/'))}
    assert re.match(latex_warnings_exp + '$', latex_warnings), \
        'Warnings don\'t match:\n' + \
        '--- Expected (regex):\n' + latex_warnings_exp + \
        '--- Got:\n' + latex_warnings

    # file from latex_additional_files
    assert (app.outdir / 'svgimg.svg').isfile()

    # only run latex if all needed packages are there
    def kpsetest(filename):
        try:
            p = Popen(['kpsewhich', filename], stdout=PIPE)
        except OSError:
            # no kpsewhich... either no tex distribution is installed or it is
            # a "strange" one -- don't bother running latex
            return None
        else:
            p.communicate()
            if p.returncode != 0:
                # not found
                return False
            # found
            return True

    if kpsetest('article.sty') is None:
        raise SkipTest('not running latex, it doesn\'t seem to be installed')
    for filename in ['fancyhdr.sty', 'fancybox.sty', 'titlesec.sty',
                     'amsmath.sty', 'framed.sty', 'color.sty', 'fancyvrb.sty',
                     'threeparttable.sty']:
        if not kpsetest(filename):
            raise SkipTest('not running latex, the %s package doesn\'t '
                           'seem to be installed' % filename)

    # now, try to run latex over it
    cwd = os.getcwd()
    os.chdir(app.outdir)
    try:
        try:
            p = Popen(['pdflatex', '--interaction=nonstopmode',
                       'SphinxTests.tex'], stdout=PIPE, stderr=PIPE)
        except OSError:
            raise SkipTest  # most likely pdflatex was not found
        else:
            stdout, stderr = p.communicate()
            if p.returncode != 0:
                print(stdout)
                print(stderr)
                assert False, 'latex exited with return code %s' % p.returncode
    finally:
        os.chdir(cwd)


@with_app(buildername='latex', freshenv=True,  # use freshenv to check warnings
          confoverrides={'latex_documents': [
              ('contents', 'SphinxTests.tex', 'Sphinx Tests Documentation',
               'Georg Brandl \\and someone else', 'howto'),
          ]},
          srcdir='latex_howto')
def test_latex_howto(app, status, warning):
    LaTeXTranslator.ignore_missing_images = True
    app.builder.build_all()
    latex_warnings = warning.getvalue().replace(os.sep, '/')
    latex_warnings_exp = LATEX_WARNINGS % {
        'root': re.escape(app.srcdir.replace(os.sep, '/'))}
    assert re.match(latex_warnings_exp + '$', latex_warnings), \
        'Warnings don\'t match:\n' + \
        '--- Expected (regex):\n' + latex_warnings_exp + \
        '--- Got:\n' + latex_warnings

    # file from latex_additional_files
    assert (app.outdir / 'svgimg.svg').isfile()

    # only run latex if all needed packages are there
    def kpsetest(filename):
        try:
            p = Popen(['kpsewhich', filename], stdout=PIPE)
        except OSError:
            # no kpsewhich... either no tex distribution is installed or it is
            # a "strange" one -- don't bother running latex
            return None
        else:
            p.communicate()
            if p.returncode != 0:
                # not found
                return False
            # found
            return True

    if kpsetest('article.sty') is None:
        raise SkipTest('not running latex, it doesn\'t seem to be installed')
    for filename in ['fancyhdr.sty', 'fancybox.sty', 'titlesec.sty',
                     'amsmath.sty', 'framed.sty', 'color.sty', 'fancyvrb.sty',
                     'threeparttable.sty']:
        if not kpsetest(filename):
            raise SkipTest('not running latex, the %s package doesn\'t '
                           'seem to be installed' % filename)

    # now, try to run latex over it
    cwd = os.getcwd()
    os.chdir(app.outdir)
    try:
        try:
            p = Popen(['pdflatex', '--interaction=nonstopmode',
                       'SphinxTests.tex'], stdout=PIPE, stderr=PIPE)
        except OSError:
            raise SkipTest  # most likely pdflatex was not found
        else:
            stdout, stderr = p.communicate()
            if p.returncode != 0:
                print(stdout)
                print(stderr)
                app.cleanup()
                assert False, 'latex exited with return code %s' % p.returncode
    finally:
        os.chdir(cwd)


@with_app(buildername='latex', testroot='numfig',
          confoverrides={'numfig': True})
def test_numref(app, status, warning):
    app.builder.build_all()
    result = (app.outdir / 'Python.tex').text(encoding='utf8')
    print(result)
    print(status.getvalue())
    print(warning.getvalue())
    assert '\\addto\\captionsenglish{\\renewcommand{\\figurename}{Fig. }}' in result
    assert '\\addto\\captionsenglish{\\renewcommand{\\tablename}{Table }}' in result
    assert '\\SetupFloatingEnvironment{literal-block}{name=Listing }' in result
    assert '\\hyperref[index:fig1]{Fig. \\ref{index:fig1}}' in result
    assert '\\hyperref[baz:fig22]{Figure\\ref{baz:fig22}}' in result
    assert '\\hyperref[index:table-1]{Table \\ref{index:table-1}}' in result
    assert '\\hyperref[baz:table22]{Table:\\ref{baz:table22}}' in result
    assert '\\hyperref[index:code-1]{Listing \\ref{index:code-1}}' in result
    assert '\\hyperref[baz:code22]{Code-\\ref{baz:code22}}' in result


@with_app(buildername='latex', testroot='numfig',
          confoverrides={'numfig': True,
                         'numfig_format': {'figure': 'Figure:%s',
                                           'table': 'Tab_%s',
                                           'code-block': 'Code-%s'}})
def test_numref_with_prefix1(app, status, warning):
    app.builder.build_all()
    result = (app.outdir / 'Python.tex').text(encoding='utf8')
    print(result)
    print(status.getvalue())
    print(warning.getvalue())
    assert '\\addto\\captionsenglish{\\renewcommand{\\figurename}{Figure:}}' in result
    assert '\\addto\\captionsenglish{\\renewcommand{\\tablename}{Tab\\_}}' in result
    assert '\\SetupFloatingEnvironment{literal-block}{name=Code-}' in result
    assert '\\ref{index:fig1}' in result
    assert '\\ref{baz:fig22}' in result
    assert '\\ref{index:table-1}' in result
    assert '\\ref{baz:table22}' in result
    assert '\\ref{index:code-1}' in result
    assert '\\ref{baz:code22}' in result
    assert '\\hyperref[index:fig1]{Figure:\\ref{index:fig1}}' in result
    assert '\\hyperref[baz:fig22]{Figure\\ref{baz:fig22}}' in result
    assert '\\hyperref[index:table-1]{Tab\\_\\ref{index:table-1}}' in result
    assert '\\hyperref[baz:table22]{Table:\\ref{baz:table22}}' in result
    assert '\\hyperref[index:code-1]{Code-\\ref{index:code-1}}' in result
    assert '\\hyperref[baz:code22]{Code-\\ref{baz:code22}}' in result


@with_app(buildername='latex', testroot='numfig',
          confoverrides={'numfig': True,
                         'numfig_format': {'figure': 'Figure:%s.',
                                           'table': 'Tab_%s:',
                                           'code-block': 'Code-%s | '}})
def test_numref_with_prefix2(app, status, warning):
    app.builder.build_all()
    result = (app.outdir / 'Python.tex').text(encoding='utf8')
    print(result)
    print(status.getvalue())
    print(warning.getvalue())
    assert '\\addto\\captionsenglish{\\renewcommand{\\figurename}{Figure:}}' in result
    assert '\\def\\fnum@figure{\\figurename\\thefigure.}' in result
    assert '\\addto\\captionsenglish{\\renewcommand{\\tablename}{Tab\\_}}' in result
    assert '\\def\\fnum@table{\\tablename\\thetable:}' in result
    assert '\\SetupFloatingEnvironment{literal-block}{name=Code-}' in result
    assert '\\hyperref[index:fig1]{Figure:\\ref{index:fig1}.}' in result
    assert '\\hyperref[baz:fig22]{Figure\\ref{baz:fig22}}' in result
    assert '\\hyperref[index:table-1]{Tab\\_\\ref{index:table-1}:}' in result
    assert '\\hyperref[baz:table22]{Table:\\ref{baz:table22}}' in result
    assert '\\hyperref[index:code-1]{Code-\\ref{index:code-1} \\textbar{} }' in result
    assert '\\hyperref[baz:code22]{Code-\\ref{baz:code22}}' in result


@with_app(buildername='latex', testroot='numfig',
          confoverrides={'numfig': True, 'language': 'el'})
def test_numref_with_language_el(app, status, warning):
    app.builder.build_all()
    result = (app.outdir / 'Python.tex').text(encoding='utf8')
    print(result)
    print(status.getvalue())
    print(warning.getvalue())
    assert '\\addto\\captionsgreek{\\renewcommand{\\figurename}{Fig. }}' in result
    assert '\\addto\\captionsgreek{\\renewcommand{\\tablename}{Table }}' in result
    assert '\\SetupFloatingEnvironment{literal-block}{name=Listing }' in result
    assert '\\hyperref[index:fig1]{Fig. \\ref{index:fig1}}' in result
    assert '\\hyperref[baz:fig22]{Figure\\ref{baz:fig22}}' in result
    assert '\\hyperref[index:table-1]{Table \\ref{index:table-1}}' in result
    assert '\\hyperref[baz:table22]{Table:\\ref{baz:table22}}' in result
    assert '\\hyperref[index:code-1]{Listing \\ref{index:code-1}}' in result
    assert '\\hyperref[baz:code22]{Code-\\ref{baz:code22}}' in result


@with_app(buildername='latex', testroot='numfig',
          confoverrides={'numfig': True, 'language': 'ja'})
def test_numref_with_language_ja(app, status, warning):
    app.builder.build_all()
    result = (app.outdir / 'Python.tex').text(encoding='utf8')
    print(result)
    print(status.getvalue())
    print(warning.getvalue())
    assert u'\\renewcommand{\\figurename}{\u56f3 }' in result
    assert '\\renewcommand{\\tablename}{TABLE }' in result
    assert '\\SetupFloatingEnvironment{literal-block}{name=LIST }' in result
    assert u'\\hyperref[index:fig1]{\u56f3 \\ref{index:fig1}}' in result
    assert '\\hyperref[baz:fig22]{Figure\\ref{baz:fig22}}' in result
    assert '\\hyperref[index:table-1]{TABLE \\ref{index:table-1}}' in result
    assert '\\hyperref[baz:table22]{Table:\\ref{baz:table22}}' in result
    assert '\\hyperref[index:code-1]{LIST \\ref{index:code-1}}' in result
    assert '\\hyperref[baz:code22]{Code-\\ref{baz:code22}}' in result


@with_app(buildername='latex', testroot='numfig',
          confoverrides={'numfig': True, 'language': 'ru', 'latex_elements': {'babel': ''}})
def test_numref_on_bable_disabled(app, status, warning):
    app.builder.build_all()
    result = (app.outdir / 'Python.tex').text(encoding='utf8')
    print(result)
    print(status.getvalue())
    print(warning.getvalue())
    assert '\\renewcommand{\\figurename}{Fig. }' in result
    assert '\\renewcommand{\\tablename}{Table }' in result
    assert '\\SetupFloatingEnvironment{literal-block}{name=Listing }' in result
    assert '\\hyperref[index:fig1]{Fig. \\ref{index:fig1}}' in result
    assert '\\hyperref[baz:fig22]{Figure\\ref{baz:fig22}}' in result
    assert '\\hyperref[index:table-1]{Table \\ref{index:table-1}}' in result
    assert '\\hyperref[baz:table22]{Table:\\ref{baz:table22}}' in result
    assert '\\hyperref[index:code-1]{Listing \\ref{index:code-1}}' in result
    assert '\\hyperref[baz:code22]{Code-\\ref{baz:code22}}' in result


@with_app(buildername='latex')
def test_latex_add_latex_package(app, status, warning):
    app.add_latex_package('foo')
    app.add_latex_package('bar', 'baz')
    app.builder.build_all()
    result = (app.outdir / 'SphinxTests.tex').text(encoding='utf8')
    assert '\\usepackage{foo}' in result
    assert '\\usepackage[baz]{bar}' in result


@with_app(buildername='latex', testroot='contentsname')
def test_contentsname(app, status, warning):
    app.builder.build_all()
    result = (app.outdir / 'Python.tex').text(encoding='utf8')
    print(result)
    print(status.getvalue())
    print(warning.getvalue())
    assert ('\\addto\\captionsenglish{\\renewcommand{\\contentsname}{Table of content}}'
            in result)


@with_app(buildername='latex', testroot='contentsname',
          confoverrides={'language': 'ja'})
def test_contentsname_with_language_ja(app, status, warning):
    app.builder.build_all()
    result = (app.outdir / 'Python.tex').text(encoding='utf8')
    print(result)
    print(status.getvalue())
    print(warning.getvalue())
    assert '\\renewcommand{\\contentsname}{Table of content}' in result


@with_app(buildername='latex')
def test_footnote(app, status, warning):
    app.builder.build_all()
    result = (app.outdir / 'SphinxTests.tex').text(encoding='utf8')
    print(result)
    print(status.getvalue())
    print(warning.getvalue())
    assert '\\footnote[1]{\nnumbered\n}' in result
    assert '\\footnote[2]{\nauto numbered\n}' in result
    assert '\\footnote[3]{\nnamed\n}' in result
    assert '{\\hyperref[footnote:bar]{\\emph{{[}bar{]}}}}' in result
    assert '\\bibitem[bar]{bar}{\\phantomsection\\label{footnote:bar} ' in result
    assert '\\bibitem[bar]{bar}{\\phantomsection\\label{footnote:bar} \ncite' in result
    assert '\\bibitem[bar]{bar}{\\phantomsection\\label{footnote:bar} \ncite\n}' in result
    assert '\\capstart\\caption{Table caption \\protect\\footnotemark[4]}' in result
    assert 'name \\protect\\footnotemark[5]' in result
    assert ('\\end{threeparttable}\n\n'
            '\\footnotetext[4]{\nfootnotes in table caption\n}'
            '\\footnotetext[5]{\nfootnotes in table\n}' in result)


@with_app(buildername='latex', testroot='footnotes')
def test_reference_in_caption(app, status, warning):
    app.builder.build_all()
    result = (app.outdir / 'Python.tex').text(encoding='utf8')
    print(result)
    print(status.getvalue())
    print(warning.getvalue())
    assert ('\\caption{This is the figure caption with a reference to \\label{index:id2}'
            '{\\hyperref[index:authoryear]{\\emph{{[}AuthorYear{]}}}}.}' in result)
    assert '\\chapter{The section with a reference to {[}AuthorYear{]}}' in result
    assert '\\caption{The table title with a reference to {[}AuthorYear{]}}' in result
    assert '\\paragraph{The rubric title with a reference to {[}AuthorYear{]}}' in result
    assert ('\\chapter{The section with a reference to \\protect\\footnotemark[4]}\n'
            '\\label{index:the-section-with-a-reference-to}'
            '\\footnotetext[4]{\nFootnote in section\n}' in result)
    assert ('\\caption{This is the figure caption with a footnote to '
            '\\protect\\footnotemark[6].}\end{figure}\n'
            '\\footnotetext[6]{\nFootnote in caption\n}')in result
    assert ('\\caption{footnote \\protect\\footnotemark[7] '
            'in caption of normal table}') in result
    assert '\\end{threeparttable}\n\n\\footnotetext[7]{\nFoot note in table\n}' in result
    assert '\\caption{footnote \\protect\\footnotemark[8] in caption of longtable}' in result
    assert '\end{longtable}\n\n\\footnotetext[8]{\nFoot note in longtable\n}' in result


@with_app(buildername='latex', testroot='footnotes',
          confoverrides={'latex_show_urls': 'inline'})
def test_latex_show_urls_is_inline(app, status, warning):
    app.builder.build_all()
    result = (app.outdir / 'Python.tex').text(encoding='utf8')
    print(result)
    print(status.getvalue())
    print(warning.getvalue())
    assert 'Same footnote number \\footnote[1]{\nfootnote in bar\n} in bar.rst' in result
    assert 'Auto footnote number \\footnote[1]{\nfootnote in baz\n} in baz.rst' in result
    assert ('\\phantomsection\\label{index:id26}{\\hyperref[index:the\\string-section'
            '\\string-with\\string-a\\string-reference\\string-to\\string-authoryear]'
            '{\\emph{The section with a reference to \\phantomsection\\label{index:id1}'
            '{\\hyperref[index:authoryear]{\\emph{{[}AuthorYear{]}}}}}}}' in result)
    assert ('\\phantomsection\\label{index:id27}{\\hyperref[index:the\\string-section'
            '\\string-with\\string-a\\string-reference\\string-to]{\\emph{The section '
            'with a reference to }}}' in result)
    assert 'First footnote: \\footnote[2]{\nFirst\n}' in result
    assert 'Second footnote: \\footnote[1]{\nSecond\n}' in result
    assert '\\href{http://sphinx-doc.org/}{Sphinx} (http://sphinx-doc.org/)' in result
    assert 'Third footnote: \\footnote[3]{\nThird\n}' in result
    assert ('\\href{http://sphinx-doc.org/~test/}{URL including tilde} '
            '(http://sphinx-doc.org/\\textasciitilde{}test/)' in result)
    assert ('\\item[{\\href{http://sphinx-doc.org/}{URL in term} (http://sphinx-doc.org/)}] '
            '\\leavevmode\nDescription' in result)
    assert ('\\item[{Footnote in term \\protect\\footnotemark[5]}] '
            '\\leavevmode\\footnotetext[5]{\nFootnote in term\n}\nDescription' in result)
    assert ('\\item[{\\href{http://sphinx-doc.org/}{Term in deflist} '
            '(http://sphinx-doc.org/)}] \\leavevmode\nDescription' in result)
    assert ('\\href{https://github.com/sphinx-doc/sphinx}'
            '{https://github.com/sphinx-doc/sphinx}\n' in result)
    assert ('\\href{mailto:sphinx-dev@googlegroups.com}'
            '{sphinx-dev@googlegroups.com}' in result)


@with_app(buildername='latex', testroot='footnotes',
          confoverrides={'latex_show_urls': 'footnote'})
def test_latex_show_urls_is_footnote(app, status, warning):
    app.builder.build_all()
    result = (app.outdir / 'Python.tex').text(encoding='utf8')
    print(result)
    print(status.getvalue())
    print(warning.getvalue())
    assert 'Same footnote number \\footnote[1]{\nfootnote in bar\n} in bar.rst' in result
    assert 'Auto footnote number \\footnote[2]{\nfootnote in baz\n} in baz.rst' in result
    assert ('\\phantomsection\\label{index:id26}{\\hyperref[index:the\\string-section'
            '\\string-with\\string-a\\string-reference\\string-to\\string-authoryear]'
            '{\\emph{The section with a reference to \\phantomsection\\label{index:id1}'
            '{\\hyperref[index:authoryear]{\\emph{{[}AuthorYear{]}}}}}}}' in result)
    assert ('\\phantomsection\\label{index:id27}{\\hyperref[index:the\\string-section'
            '\\string-with\\string-a\\string-reference\\string-to]{\\emph{The section '
            'with a reference to }}}' in result)
    assert 'First footnote: \\footnote[3]{\nFirst\n}' in result
    assert 'Second footnote: \\footnote[1]{\nSecond\n}' in result
    assert ('\\href{http://sphinx-doc.org/}{Sphinx}'
            '\\footnote[4]{\nhttp://sphinx-doc.org/\n}' in result)
    assert 'Third footnote: \\footnote[6]{\nThird\n}' in result
    assert ('\\href{http://sphinx-doc.org/~test/}{URL including tilde}'
            '\\footnote[5]{\nhttp://sphinx-doc.org/\\textasciitilde{}test/\n}' in result)
    assert ('\\item[{\\href{http://sphinx-doc.org/}{URL in term}\\protect\\footnotemark[8]}] '
            '\\leavevmode\\footnotetext[8]{\nhttp://sphinx-doc.org/\n}\nDescription' in result)
    assert ('\\item[{Footnote in term \\protect\\footnotemark[10]}] '
            '\\leavevmode\\footnotetext[10]{\nFootnote in term\n}\nDescription' in result)
    assert ('\\item[{\\href{http://sphinx-doc.org/}{Term in deflist}\\protect'
            '\\footnotemark[9]}] '
            '\\leavevmode\\footnotetext[9]{\nhttp://sphinx-doc.org/\n}\nDescription' in result)
    assert ('\\href{https://github.com/sphinx-doc/sphinx}'
            '{https://github.com/sphinx-doc/sphinx}\n' in result)
    assert ('\\href{mailto:sphinx-dev@googlegroups.com}'
            '{sphinx-dev@googlegroups.com}\n' in result)


@with_app(buildername='latex', testroot='footnotes',
          confoverrides={'latex_show_urls': 'no'})
def test_latex_show_urls_is_no(app, status, warning):
    app.builder.build_all()
    result = (app.outdir / 'Python.tex').text(encoding='utf8')
    print(result)
    print(status.getvalue())
    print(warning.getvalue())
    assert 'Same footnote number \\footnote[1]{\nfootnote in bar\n} in bar.rst' in result
    assert 'Auto footnote number \\footnote[1]{\nfootnote in baz\n} in baz.rst' in result
    assert ('\\phantomsection\\label{index:id26}{\\hyperref[index:the\\string-section'
            '\\string-with\\string-a\\string-reference\\string-to\\string-authoryear]'
            '{\\emph{The section with a reference to \\phantomsection\\label{index:id1}'
            '{\\hyperref[index:authoryear]{\\emph{{[}AuthorYear{]}}}}}}}' in result)
    assert ('\\phantomsection\\label{index:id27}{\\hyperref[index:the\\string-section'
            '\\string-with\\string-a\\string-reference\\string-to]{\\emph{The section '
            'with a reference to }}}' in result)
    assert 'First footnote: \\footnote[2]{\nFirst\n}' in result
    assert 'Second footnote: \\footnote[1]{\nSecond\n}' in result
    assert '\\href{http://sphinx-doc.org/}{Sphinx}' in result
    assert 'Third footnote: \\footnote[3]{\nThird\n}' in result
    assert '\\href{http://sphinx-doc.org/~test/}{URL including tilde}' in result
    assert ('\\item[{\\href{http://sphinx-doc.org/}{URL in term}}] '
            '\\leavevmode\nDescription' in result)
    assert ('\\item[{Footnote in term \\protect\\footnotemark[5]}] '
            '\\leavevmode\\footnotetext[5]{\nFootnote in term\n}\nDescription' in result)
    assert ('\\item[{\\href{http://sphinx-doc.org/}{Term in deflist}}] '
            '\\leavevmode\nDescription' in result)
    assert ('\\href{https://github.com/sphinx-doc/sphinx}'
            '{https://github.com/sphinx-doc/sphinx}\n' in result)
    assert ('\\href{mailto:sphinx-dev@googlegroups.com}'
            '{sphinx-dev@googlegroups.com}\n' in result)


@with_app(buildername='latex', testroot='image-in-section')
def test_image_in_section(app, status, warning):
    app.builder.build_all()
    result = (app.outdir / 'Python.tex').text(encoding='utf8')
    print(result)
    print(status.getvalue())
    print(warning.getvalue())
    assert ('\chapter[Test section]'
            '{\includegraphics[width=15pt,height=15pt]{{pic}.png} Test section}'
            in result)
    assert ('\chapter[Other {[}blah{]} section]{Other {[}blah{]} '
            '\includegraphics[width=15pt,height=15pt]{{pic}.png} section}' in result)
    assert ('\chapter{Another section}' in result)


@with_app(buildername='latex', confoverrides={'latex_logo': 'notfound.jpg'})
def test_latex_logo_if_not_found(app, status, warning):
    try:
        app.builder.build_all()
        assert False  # SphinxError not raised
    except Exception as exc:
        assert isinstance(exc, SphinxError)


@with_app(buildername='latex', testroot='toctree-maxdepth',
          confoverrides={'latex_documents': [
              ('index', 'SphinxTests.tex', 'Sphinx Tests Documentation',
               'Georg Brandl', 'manual'),
          ]})
def test_toctree_maxdepth_manual(app, status, warning):
    app.builder.build_all()
    result = (app.outdir / 'SphinxTests.tex').text(encoding='utf8')
    print(result)
    print(status.getvalue())
    print(warning.getvalue())
    assert '\\setcounter{tocdepth}{1}' in result


@with_app(buildername='latex', testroot='toctree-maxdepth',
          confoverrides={'latex_documents': [
              ('index', 'SphinxTests.tex', 'Sphinx Tests Documentation',
               'Georg Brandl', 'howto'),
          ]})
def test_toctree_maxdepth_howto(app, status, warning):
    app.builder.build_all()
    result = (app.outdir / 'SphinxTests.tex').text(encoding='utf8')
    print(result)
    print(status.getvalue())
    print(warning.getvalue())
    assert '\\setcounter{tocdepth}{2}' in result


@with_app(buildername='latex', testroot='toctree-maxdepth',
          confoverrides={'master_doc': 'foo'})
def test_toctree_not_found(app, status, warning):
    app.builder.build_all()
    result = (app.outdir / 'Python.tex').text(encoding='utf8')
    print(result)
    print(status.getvalue())
    print(warning.getvalue())
    assert '\\setcounter{tocdepth}' not in result


@with_app(buildername='latex', testroot='toctree-maxdepth',
          confoverrides={'master_doc': 'bar'})
def test_toctree_without_maxdepth(app, status, warning):
    app.builder.build_all()
    result = (app.outdir / 'Python.tex').text(encoding='utf8')
    print(result)
    print(status.getvalue())
    print(warning.getvalue())
    assert '\\setcounter{tocdepth}' not in result