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
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
|
.. _builders:
========
Builders
========
.. module:: sphinx.builders
:synopsis: Available built-in builder classes.
These are the built-in Sphinx builders. More builders can be added by
:doc:`extensions </usage/extensions/index>`.
The builder's "name" must be given to the **-M** or **-b** command-line options of
:program:`sphinx-build` to select a builder.
The most common builders are:
**html**
Build HTML pages. This is the default builder.
**dirhtml**
Build HTML pages, but with a single directory per document. Makes for
prettier URLs (no ``.html``) if served from a webserver.
**singlehtml**
Build a single HTML with the whole content.
**htmlhelp**, **qthelp**, **devhelp**, **epub**
Build HTML files with additional information for building a documentation
collection in one of these formats.
**applehelp**
Build an Apple Help Book. Requires :program:`hiutil` and
:program:`codesign`, which are not Open Source and presently only
available on Mac OS X 10.6 and higher.
**latex**
Build LaTeX sources that can be compiled to a PDF document using
:program:`pdflatex`.
**man**
Build manual pages in groff format for UNIX systems.
**texinfo**
Build Texinfo files that can be processed into Info files using
:program:`makeinfo`.
**text**
Build plain text files.
**gettext**
Build gettext-style message catalogs (``.pot`` files).
**doctest**
Run all doctests in the documentation, if the :mod:`~sphinx.ext.doctest`
extension is enabled.
**linkcheck**
Check the integrity of all external links.
**xml**
Build Docutils-native XML files.
**pseudoxml**
Build compact pretty-printed "pseudo-XML" files displaying the
internal structure of the intermediate document trees.
--------------
.. module:: sphinx.builders.html
.. class:: StandaloneHTMLBuilder
This is the standard HTML builder. Its output is a directory with HTML
files, complete with style sheets and optionally the reST sources. There are
quite a few configuration values that customize the output of this builder,
see the chapter :ref:`html-options` for details.
.. autoattribute:: name
.. autoattribute:: format
.. autoattribute:: supported_image_types
.. module:: sphinx.builders.dirhtml
.. class:: DirectoryHTMLBuilder
This is a subclass of the standard HTML builder. Its output is a directory
with HTML files, where each file is called ``index.html`` and placed in a
subdirectory named like its page name. For example, the document
``markup/rest.rst`` will not result in an output file ``markup/rest.html``,
but ``markup/rest/index.html``. When generating links between pages, the
``index.html`` is omitted, so that the URL would look like ``markup/rest/``.
.. autoattribute:: name
.. autoattribute:: format
.. autoattribute:: supported_image_types
.. versionadded:: 0.6
.. module:: sphinx.builders.singlehtml
.. class:: SingleFileHTMLBuilder
This is an HTML builder that combines the whole project in one output file.
(Obviously this only works with smaller projects.) The file is named like
the root document. No indices will be generated.
.. autoattribute:: name
.. autoattribute:: format
.. autoattribute:: supported_image_types
.. versionadded:: 1.0
.. module:: sphinxcontrib.htmlhelp
.. class:: HTMLHelpBuilder
This builder produces the same output as the standalone HTML builder, but
also generates HTML Help support files that allow the Microsoft HTML Help
Workshop to compile them into a CHM file.
.. autoattribute:: name
.. autoattribute:: format
.. autoattribute:: supported_image_types
.. module:: sphinxcontrib.qthelp
.. class:: QtHelpBuilder
This builder produces the same output as the standalone HTML builder, but
also generates `Qt help`_ collection support files that allow the Qt
collection generator to compile them.
.. versionchanged:: 2.0
Moved to sphinxcontrib.qthelp from sphinx.builders package.
.. autoattribute:: name
.. autoattribute:: format
.. autoattribute:: supported_image_types
.. _Qt help: https://doc.qt.io/qt-4.8/qthelp-framework.html
.. module:: sphinxcontrib.applehelp
.. class:: AppleHelpBuilder
This builder produces an Apple Help Book based on the same output as the
standalone HTML builder.
If the source directory contains any ``.lproj`` folders, the one
corresponding to the selected language will have its contents merged with
the generated output. These folders will be ignored by all other
documentation types.
In order to generate a valid help book, this builder requires the command
line tool :program:`hiutil`, which is only available on Mac OS X 10.6 and
above. You can disable the indexing step by setting
:confval:`applehelp_disable_external_tools` to ``True``, in which case the
output will not be valid until :program:`hiutil` has been run on all of the
``.lproj`` folders within the bundle.
.. autoattribute:: name
.. autoattribute:: format
.. autoattribute:: supported_image_types
.. versionadded:: 1.3
.. versionchanged:: 2.0
Moved to sphinxcontrib.applehelp from sphinx.builders package.
.. module:: sphinxcontrib.devhelp
.. class:: DevhelpBuilder
This builder produces the same output as the standalone HTML builder, but
also generates `GNOME Devhelp <https://wiki.gnome.org/Apps/Devhelp>`__
support file that allows the GNOME Devhelp reader to view them.
.. autoattribute:: name
.. autoattribute:: format
.. autoattribute:: supported_image_types
.. versionchanged:: 2.0
Moved to sphinxcontrib.devhelp from sphinx.builders package.
.. module:: sphinx.builders.epub3
.. class:: Epub3Builder
This builder produces the same output as the standalone HTML builder, but
also generates an *epub* file for ebook readers. See :ref:`epub-faq` for
details about it. For definition of the epub format, have a look at
`<https://idpf.org/epub>`_ or `<https://en.wikipedia.org/wiki/EPUB>`_.
The builder creates *EPUB 3* files.
.. autoattribute:: name
.. autoattribute:: format
.. autoattribute:: supported_image_types
.. versionadded:: 1.4
.. versionchanged:: 1.5
Since Sphinx 1.5, the epub3 builder is used as the default epub builder.
.. module:: sphinx.builders.latex
.. class:: LaTeXBuilder
This builder produces LaTeX source files in the output directory. The
actual PDF builds happen inside this output directory and need to be
triggered in a second step. This can be done via
:program:`make all-pdf` there.
To combine the two steps into only one, use :option:`sphinx-build -M`
(i.e. ``-M latexpdf`` not ``-b latexpdf``) or :program:`make latexpdf`
at the project root.
See :confval:`latex_documents` and the chapter :ref:`latex-options` for
available options.
PDF builds need a sufficiently complete LaTeX installation.
The testing is currently (since 5.3.0) done on Ubuntu 22.04LTS,
whose LaTeX distribution matches upstream TeXLive 2021 as of 2022/02/04,
but PDF builds can be successfully done on much older LaTeX installations.
At any rate, on Ubuntu for example, following packages must all be present:
* ``texlive-latex-recommended``
* ``texlive-fonts-recommended``
* ``tex-gyre`` (if :confval:`latex_engine` left to default)
* ``texlive-latex-extra``
* ``latexmk``
.. versionchanged:: 4.0.0
TeX Gyre fonts now required for ``'pdflatex'`` engine (default).
Additional packages are needed in some circumstances:
* ``texlive-lang-cyrillic`` for Cyrillic (and also then
``cm-super`` if using the default fonts),
* ``texlive-lang-greek`` for Greek (and also then
``cm-super`` if using the default fonts),
* ``texlive-xetex`` if :confval:`latex_engine` is ``'xelatex'``,
* ``texlive-luatex`` if :confval:`latex_engine` is ``'lualatex'``,
* ``fonts-freefont-otf`` if :confval:`latex_engine` is either
``'xelatex'`` or ``'lualatex'``.
.. note::
Since 1.6, ``make latexpdf`` uses on GNU/Linux and macOS
:program:`latexmk`, as it
makes sure the needed number of runs is automatically executed.
On Windows the PDF builds execute a fix number of LaTeX runs
(three, then ``makeindex``, then two more).
One can pass to ``latexmk`` options via the ``LATEXMKOPTS``
Makefile variable. For example:
.. code-block:: console
make latexpdf LATEXMKOPTS="-silent"
reduces console output to a minimum.
Also, if ``latexmk`` is at version 4.52b or higher (January 2017)
``LATEXMKOPTS="-xelatex"`` speeds up PDF builds via XeLateX in case
of numerous graphics inclusions.
To pass options directly to the ``(pdf|xe|lua)latex`` binary, use
variable ``LATEXOPTS``, for example:
.. code-block:: console
make latexpdf LATEXOPTS="--halt-on-error"
.. autoattribute:: name
.. autoattribute:: format
.. autoattribute:: supported_image_types
Note that a direct PDF builder is being provided by `rinohtype`_. The builder's
name is ``rinoh``. Refer to the `rinohtype manual`_ for details.
.. _rinohtype: https://github.com/brechtm/rinohtype
.. _rinohtype manual: https://www.mos6581.org/rinohtype/master/quickstart.html#sphinx-builder
.. module:: sphinx.builders.text
.. class:: TextBuilder
This builder produces a text file for each reST file -- this is almost the
same as the reST source, but with much of the markup stripped for better
readability.
.. autoattribute:: name
.. autoattribute:: format
.. autoattribute:: supported_image_types
.. versionadded:: 0.4
.. module:: sphinx.builders.manpage
.. class:: ManualPageBuilder
This builder produces manual pages in the groff format. You have to specify
which documents are to be included in which manual pages via the
:confval:`man_pages` configuration value.
.. autoattribute:: name
.. autoattribute:: format
.. autoattribute:: supported_image_types
.. versionadded:: 1.0
.. module:: sphinx.builders.texinfo
.. class:: TexinfoBuilder
This builder produces Texinfo files that can be processed into Info files by
the :program:`makeinfo` program. You have to specify which documents are to
be included in which Texinfo files via the :confval:`texinfo_documents`
configuration value.
The Info format is the basis of the on-line help system used by GNU Emacs and
the terminal-based program :program:`info`. See :ref:`texinfo-faq` for more
details. The Texinfo format is the official documentation system used by the
GNU project. More information on Texinfo can be found at
`<https://www.gnu.org/software/texinfo/>`_.
.. autoattribute:: name
.. autoattribute:: format
.. autoattribute:: supported_image_types
.. versionadded:: 1.1
.. currentmodule:: sphinxcontrib.serializinghtml
.. class:: SerializingHTMLBuilder
This builder uses a module that implements the Python serialization API
(``pickle``, ``simplejson``, ``phpserialize``, and others) to dump the
generated HTML documentation. The pickle builder is a subclass of it.
A concrete subclass of this builder serializing to the `PHP serialization`_
format could look like this::
import phpserialize
class PHPSerializedBuilder(SerializingHTMLBuilder):
name = 'phpserialized'
implementation = phpserialize
out_suffix = '.file.phpdump'
globalcontext_filename = 'globalcontext.phpdump'
searchindex_filename = 'searchindex.phpdump'
.. _PHP serialization: https://pypi.org/project/phpserialize/
.. attribute:: implementation
A module that implements ``dump()``, ``load()``, ``dumps()`` and ``loads()``
functions that conform to the functions with the same names from the
pickle module. Known modules implementing this interface are
``simplejson``, ``phpserialize``, ``plistlib``, and others.
.. attribute:: out_suffix
The suffix for all regular files.
.. attribute:: globalcontext_filename
The filename for the file that contains the "global context". This
is a dict with some general configuration values such as the name
of the project.
.. attribute:: searchindex_filename
The filename for the search index Sphinx generates.
See :ref:`serialization-details` for details about the output format.
.. versionadded:: 0.5
.. class:: PickleHTMLBuilder
This builder produces a directory with pickle files containing mostly HTML
fragments and TOC information, for use of a web application (or custom
postprocessing tool) that doesn't use the standard HTML templates.
See :ref:`serialization-details` for details about the output format.
.. autoattribute:: name
The old name ``web`` still works as well.
.. autoattribute:: format
.. autoattribute:: supported_image_types
The file suffix is ``.fpickle``. The global context is called
``globalcontext.pickle``, the search index ``searchindex.pickle``.
.. class:: JSONHTMLBuilder
This builder produces a directory with JSON files containing mostly HTML
fragments and TOC information, for use of a web application (or custom
postprocessing tool) that doesn't use the standard HTML templates.
See :ref:`serialization-details` for details about the output format.
.. autoattribute:: name
.. autoattribute:: format
.. autoattribute:: supported_image_types
The file suffix is ``.fjson``. The global context is called
``globalcontext.json``, the search index ``searchindex.json``.
.. versionadded:: 0.5
.. module:: sphinx.builders.gettext
.. class:: MessageCatalogBuilder
This builder produces gettext-style message catalogs. Each top-level file or
subdirectory grows a single ``.pot`` catalog template.
See the documentation on :ref:`intl` for further reference.
.. autoattribute:: name
.. autoattribute:: format
.. autoattribute:: supported_image_types
.. versionadded:: 1.1
.. module:: sphinx.builders.changes
.. class:: ChangesBuilder
This builder produces an HTML overview of all :rst:dir:`versionadded`,
:rst:dir:`versionchanged`, :rst:dir:`deprecated` and :rst:dir:`versionremoved`
directives for the current :confval:`version`. This is useful to generate a
changelog file, for example.
.. autoattribute:: name
.. autoattribute:: format
.. autoattribute:: supported_image_types
.. module:: sphinx.builders.dummy
.. class:: DummyBuilder
This builder produces no output. The input is only parsed and checked for
consistency. This is useful for linting purposes.
.. autoattribute:: name
.. autoattribute:: supported_image_types
.. versionadded:: 1.4
.. module:: sphinx.builders.linkcheck
.. class:: CheckExternalLinksBuilder
This builder scans all documents for external links, tries to open them with
``requests``, and writes an overview which ones are broken and redirected to
standard output and to :file:`output.txt` in the output directory.
.. autoattribute:: name
.. autoattribute:: format
.. autoattribute:: supported_image_types
.. versionchanged:: 1.5
Since Sphinx 1.5, the linkcheck builder uses the requests module.
.. versionchanged:: 3.4
The linkcheck builder retries links when servers apply rate limits.
.. module:: sphinx.builders.xml
.. class:: XMLBuilder
This builder produces Docutils-native XML files. The output can be
transformed with standard XML tools such as XSLT processors into arbitrary
final forms.
.. autoattribute:: name
.. autoattribute:: format
.. autoattribute:: supported_image_types
.. versionadded:: 1.2
.. class:: PseudoXMLBuilder
This builder is used for debugging the Sphinx/Docutils "Reader to Transform
to Writer" pipeline. It produces compact pretty-printed "pseudo-XML", files
where nesting is indicated by indentation (no end-tags). External
attributes for all elements are output, and internal attributes for any
leftover "pending" elements are also given.
.. autoattribute:: name
.. autoattribute:: format
.. autoattribute:: supported_image_types
.. versionadded:: 1.2
Built-in Sphinx extensions that offer more builders are:
* :mod:`~sphinx.ext.doctest`
* :mod:`~sphinx.ext.coverage`
.. _serialization-details:
Serialization builder details
-----------------------------
All serialization builders outputs one file per source file and a few special
files. They also copy the reST source files in the directory ``_sources``
under the output directory.
The :class:`.PickleHTMLBuilder` is a builtin subclass that implements the pickle
serialization interface.
The files per source file have the extensions of
:attr:`~.SerializingHTMLBuilder.out_suffix`, and are arranged in directories
just as the source files are. They unserialize to a dictionary (or dictionary
like structure) with these keys:
``body``
The HTML "body" (that is, the HTML rendering of the source file), as rendered
by the HTML translator.
``title``
The title of the document, as HTML (may contain markup).
``toc``
The table of contents for the file, rendered as an HTML ``<ul>``.
``display_toc``
A boolean that is ``True`` if the ``toc`` contains more than one entry.
``current_page_name``
The document name of the current file.
``parents``, ``prev`` and ``next``
Information about related chapters in the TOC tree. Each relation is a
dictionary with the keys ``link`` (HREF for the relation) and ``title``
(title of the related document, as HTML). ``parents`` is a list of
relations, while ``prev`` and ``next`` are a single relation.
``sourcename``
The name of the source file under ``_sources``.
The special files are located in the root output directory. They are:
:attr:`.SerializingHTMLBuilder.globalcontext_filename`
A pickled dict with these keys:
``project``, ``copyright``, ``release``, ``version``
The same values as given in the configuration file.
``style``
:confval:`html_style`.
``last_updated``
Date of last build.
``builder``
Name of the used builder, in the case of pickles this is always
``'pickle'``.
``titles``
A dictionary of all documents' titles, as HTML strings.
:attr:`.SerializingHTMLBuilder.searchindex_filename`
An index that can be used for searching the documentation. It is a pickled
list with these entries:
* A list of indexed docnames.
* A list of document titles, as HTML strings, in the same order as the first
list.
* A dict mapping word roots (processed by an English-language stemmer) to a
list of integers, which are indices into the first list.
``environment.pickle``
The build environment. This is always a pickle file, independent of the
builder and a copy of the environment that was used when the builder was
started.
.. todo:: Document common members.
Unlike the other pickle files this pickle file requires that the ``sphinx``
package is available on unpickling.
|