# $Id: __init__.py 9331 2023-03-25 17:54:40Z aa-turner $
# Author: Engelbert Gruber, Günter Milde
# Maintainer: docutils-develop@lists.sourceforge.net
# Copyright: This module has been placed in the public domain.
"""LaTeX2e document tree Writer."""
__docformat__ = 'reStructuredText'
# code contributions from several people included, thanks to all.
# some named: David Abrahams, Julien Letessier, Lele Gaifax, and others.
#
# convention deactivate code by two # i.e. ##.
from pathlib import Path
import re
import string
from urllib.request import url2pathname
import warnings
try:
import roman
except ImportError:
import docutils.utils.roman as roman
from docutils import frontend, nodes, languages, writers, utils
from docutils.transforms import writer_aux
from docutils.utils.math import pick_math_environment, unichar2tex
LATEX_WRITER_DIR = Path(__file__).parent
class Writer(writers.Writer):
supported = ('latex', 'latex2e')
"""Formats this writer supports."""
default_template = 'default.tex'
default_template_path = LATEX_WRITER_DIR
default_preamble = ('% PDF Standard Fonts\n'
'\\usepackage{mathptmx} % Times\n'
'\\usepackage[scaled=.90]{helvet}\n'
'\\usepackage{courier}')
table_style_values = [ # TODO: align-left, align-center, align-right, ??
'booktabs', 'borderless', 'colwidths-auto',
'nolines', 'standard']
settings_spec = (
'LaTeX-Specific Options',
None,
(('Specify LaTeX documentclass. Default: "article".',
['--documentclass'],
{'default': 'article', }),
('Specify document options. Multiple options can be given, '
'separated by commas. Default: "a4paper".',
['--documentoptions'],
{'default': 'a4paper', }),
('Format for footnote references: one of "superscript" or '
'"brackets". Default: "superscript".',
['--footnote-references'],
{'choices': ['superscript', 'brackets'], 'default': 'superscript',
'metavar': '',
'overrides': 'trim_footnote_reference_space'}),
('Use \\cite command for citations. (future default)',
['--use-latex-citations'],
{'default': None, 'action': 'store_true',
'validator': frontend.validate_boolean}),
('Use figure floats for citations '
'(might get mixed with real figures). (provisional default)',
['--figure-citations'],
{'dest': 'use_latex_citations', 'action': 'store_false',
'validator': frontend.validate_boolean}),
('Format for block quote attributions: one of "dash" (em-dash '
'prefix), "parentheses"/"parens", or "none". Default: "dash".',
['--attribution'],
{'choices': ['dash', 'parentheses', 'parens', 'none'],
'default': 'dash', 'metavar': ''}),
('Specify LaTeX packages/stylesheets. '
'A style is referenced with "\\usepackage" if extension is '
'".sty" or omitted and with "\\input" else. '
' Overrides previous --stylesheet and --stylesheet-path settings.',
['--stylesheet'],
{'default': '', 'metavar': '',
'overrides': 'stylesheet_path',
'validator': frontend.validate_comma_separated_list}),
('Comma separated list of LaTeX packages/stylesheets. '
'Relative paths are expanded if a matching file is found in '
'the --stylesheet-dirs. With --link-stylesheet, '
'the path is rewritten relative to the output *.tex file. ',
['--stylesheet-path'],
{'metavar': '', 'overrides': 'stylesheet',
'validator': frontend.validate_comma_separated_list}),
('Link to the stylesheet(s) in the output file. (default)',
['--link-stylesheet'],
{'dest': 'embed_stylesheet', 'action': 'store_false'}),
('Embed the stylesheet(s) in the output file. '
'Stylesheets must be accessible during processing. ',
['--embed-stylesheet'],
{'default': False, 'action': 'store_true',
'validator': frontend.validate_boolean}),
('Comma-separated list of directories where stylesheets are found. '
'Used by --stylesheet-path when expanding relative path arguments. '
'Default: ".".',
['--stylesheet-dirs'],
{'metavar': '',
'validator': frontend.validate_comma_separated_list,
'default': ['.']}),
('Customization by LaTeX code in the preamble. '
'Default: select PDF standard fonts (Times, Helvetica, Courier).',
['--latex-preamble'],
{'default': default_preamble}),
('Specify the template file. Default: "%s".' % default_template,
['--template'],
{'default': default_template, 'metavar': ''}),
('Table of contents by LaTeX. (default)',
['--use-latex-toc'],
{'default': True, 'action': 'store_true',
'validator': frontend.validate_boolean}),
('Table of contents by Docutils (without page numbers).',
['--use-docutils-toc'],
{'dest': 'use_latex_toc', 'action': 'store_false',
'validator': frontend.validate_boolean}),
('Add parts on top of the section hierarchy.',
['--use-part-section'],
{'default': False, 'action': 'store_true',
'validator': frontend.validate_boolean}),
('Attach author and date to the document info table. (default)',
['--use-docutils-docinfo'],
{'dest': 'use_latex_docinfo', 'action': 'store_false',
'validator': frontend.validate_boolean}),
('Attach author and date to the document title.',
['--use-latex-docinfo'],
{'default': False, 'action': 'store_true',
'validator': frontend.validate_boolean}),
("Typeset abstract as topic. (default)",
['--topic-abstract'],
{'dest': 'use_latex_abstract', 'action': 'store_false',
'validator': frontend.validate_boolean}),
("Use LaTeX abstract environment for the document's abstract.",
['--use-latex-abstract'],
{'default': False, 'action': 'store_true',
'validator': frontend.validate_boolean}),
('Color of any hyperlinks embedded in text. '
'Default: "blue" (use "false" to disable).',
['--hyperlink-color'], {'default': 'blue'}),
('Additional options to the "hyperref" package.',
['--hyperref-options'], {'default': ''}),
('Enable compound enumerators for nested enumerated lists '
'(e.g. "1.2.a.ii").',
['--compound-enumerators'],
{'default': False, 'action': 'store_true',
'validator': frontend.validate_boolean}),
('Disable compound enumerators for nested enumerated lists. '
'(default)',
['--no-compound-enumerators'],
{'action': 'store_false', 'dest': 'compound_enumerators'}),
('Enable section ("." subsection ...) prefixes for compound '
'enumerators. This has no effect without --compound-enumerators.',
['--section-prefix-for-enumerators'],
{'default': None, 'action': 'store_true',
'validator': frontend.validate_boolean}),
('Disable section prefixes for compound enumerators. (default)',
['--no-section-prefix-for-enumerators'],
{'action': 'store_false', 'dest': 'section_prefix_for_enumerators'}),
('Set the separator between section number and enumerator '
'for compound enumerated lists. Default: "-".',
['--section-enumerator-separator'],
{'default': '-', 'metavar': ''}),
('When possible, use the specified environment for literal-blocks. '
'Default: "" (fall back to "alltt").',
['--literal-block-env'],
{'default': ''}),
('Deprecated alias for "--literal-block-env=verbatim".',
['--use-verbatim-when-possible'],
{'action': 'store_true',
'validator': frontend.validate_boolean}),
('Table style. "standard" with horizontal and vertical lines, '
'"booktabs" (LaTeX booktabs style) only horizontal lines '
'above and below the table and below the header, or "borderless". '
'Default: "standard"',
['--table-style'],
{'default': ['standard'],
'metavar': '',
'action': 'append',
'validator': frontend.validate_comma_separated_list,
'choices': table_style_values}),
('LaTeX graphicx package option. '
'Possible values are "dvipdfmx", "dvips", "dvisvgm", '
'"luatex", "pdftex", and "xetex".'
'Default: "".',
['--graphicx-option'],
{'default': ''}),
('LaTeX font encoding. '
'Possible values are "", "T1" (default), "OT1", "LGR,T1" or '
'any other combination of options to the `fontenc` package. ',
['--font-encoding'],
{'default': 'T1'}),
('Per default the latex-writer puts the reference title into '
'hyperreferences. Specify "ref*" or "pageref*" to get the section '
'number or the page number.',
['--reference-label'],
{'default': ''}),
('Specify style and database(s) for bibtex, for example '
'"--use-bibtex=unsrt,mydb1,mydb2". Provisional!',
['--use-bibtex'],
{'default': '',
'metavar': '