latex: Introduce ADDITIONAL_SETTINGS to support default settings for each LaTeX engine

This commit is contained in:
Takeshi KOMIYA 2016-10-19 12:21:32 +09:00
parent 41609f15b8
commit 1ced210d74

View File

@ -45,6 +45,67 @@ DEFAULT_TEMPLATE = 'latex/content.tex_t'
URI_SCHEMES = ('mailto:', 'http:', 'https:', 'ftp:')
SECNUMDEPTH = 3
DEFAULT_SETTINGS = {
'papersize': 'letterpaper',
'pointsize': '10pt',
'pxunit': '49336sp',
'classoptions': '',
'extraclassoptions': '',
'passoptionstopackages': '',
'geometry': '\\usepackage[margin=1in,marginparwidth=0.5in]'
'{geometry}',
'inputenc': '',
'utf8extra': ('\\ifdefined\\DeclareUnicodeCharacter\n'
' \\DeclareUnicodeCharacter{00A0}{\\nobreakspace}\n'
'\\fi'),
'cmappkg': '\\usepackage{cmap}',
'fontenc': '\\usepackage[T1]{fontenc}',
'amsmath': '\\usepackage{amsmath,amssymb,amstext}',
'babel': '\\usepackage{babel}',
'fontpkg': '\\usepackage{times}',
'fncychap': '\\usepackage[Bjarne]{fncychap}',
'longtable': '\\usepackage{longtable}',
'hyperref': ('% Include hyperref last.\n'
'\\usepackage[colorlinks,breaklinks,%\n'
' '
'linkcolor=InnerLinkColor,filecolor=OuterLinkColor,%\n'
' '
'menucolor=OuterLinkColor,urlcolor=OuterLinkColor,%\n'
' '
'citecolor=InnerLinkColor]{hyperref}\n'
'% Fix anchor placement for figures with captions.\n'
'\\usepackage{hypcap}% it must be loaded after hyperref.\n'
'% Set up styles of URL: it should be placed after hyperref.\n'
'\\urlstyle{same}'),
'usepackages': '',
'numfig_format': '',
'contentsname': '',
'preamble': '',
'title': '',
'date': '',
'release': '',
'author': '',
'logo': '',
'releasename': 'Release',
'makeindex': '\\makeindex',
'shorthandoff': '',
'maketitle': '\\maketitle',
'tableofcontents': '\\sphinxtableofcontents',
'postamble': '',
'printindex': '\\printindex',
'transition': '\n\n\\bigskip\\hrule{}\\bigskip\n\n',
'figure_align': 'htbp',
'tocdepth': '',
'secnumdepth': '',
'pageautorefname': '',
}
ADDITIONAL_SETTINGS = {
'pdflatex': {
'inputenc': '\\usepackage[utf8]{inputenc}',
},
}
class collected_footnote(nodes.footnote):
"""Footnotes that are collected are assigned this class."""
@ -258,61 +319,6 @@ class LaTeXTranslator(nodes.NodeVisitor):
ignore_missing_images = False
default_elements = {
'papersize': 'letterpaper',
'pointsize': '10pt',
'pxunit': '49336sp',
'classoptions': '',
'extraclassoptions': '',
'passoptionstopackages': '',
'geometry': '\\usepackage[margin=1in,marginparwidth=0.5in]'
'{geometry}',
'inputenc': '',
'utf8extra': ('\\ifdefined\\DeclareUnicodeCharacter\n'
' \\DeclareUnicodeCharacter{00A0}{\\nobreakspace}\n'
'\\fi'),
'cmappkg': '\\usepackage{cmap}',
'fontenc': '\\usepackage[T1]{fontenc}',
'amsmath': '\\usepackage{amsmath,amssymb,amstext}',
'babel': '\\usepackage{babel}',
'fontpkg': '\\usepackage{times}',
'fncychap': '\\usepackage[Bjarne]{fncychap}',
'longtable': '\\usepackage{longtable}',
'hyperref': ('% Include hyperref last.\n'
'\\usepackage[colorlinks,breaklinks,%\n'
' '
'linkcolor=InnerLinkColor,filecolor=OuterLinkColor,%\n'
' '
'menucolor=OuterLinkColor,urlcolor=OuterLinkColor,%\n'
' '
'citecolor=InnerLinkColor]{hyperref}\n'
'% Fix anchor placement for figures with captions.\n'
'\\usepackage{hypcap}% it must be loaded after hyperref.\n'
'% Set up styles of URL: it should be placed after hyperref.\n'
'\\urlstyle{same}'),
'usepackages': '',
'numfig_format': '',
'contentsname': '',
'preamble': '',
'title': '',
'date': '',
'release': '',
'author': '',
'logo': '',
'releasename': 'Release',
'makeindex': '\\makeindex',
'shorthandoff': '',
'maketitle': '\\maketitle',
'tableofcontents': '\\sphinxtableofcontents',
'postamble': '',
'printindex': '\\printindex',
'transition': '\n\n\\bigskip\\hrule{}\\bigskip\n\n',
'figure_align': 'htbp',
'tocdepth': '',
'secnumdepth': '',
'pageautorefname': '',
}
# sphinx specific document classes
docclasses = ('howto', 'manual')
@ -350,7 +356,8 @@ class LaTeXTranslator(nodes.NodeVisitor):
self.top_sectionlevel = 1
# sort out some elements
self.elements = self.default_elements.copy()
self.elements = DEFAULT_SETTINGS.copy()
self.elements.update(ADDITIONAL_SETTINGS.get(builder.config.latex_engine, {}))
self.elements.update({
'wrapperclass': self.format_docclass(document.settings.docclass),
# if empty, the title is set to the first section title
@ -371,8 +378,6 @@ class LaTeXTranslator(nodes.NodeVisitor):
else:
docclass = builder.config.latex_docclass.get('manual', 'report')
self.elements['docclass'] = docclass
if builder.config.latex_engine == 'pdflatex':
self.elements['inputenc'] = '\\usepackage[utf8]{inputenc}'
if builder.config.today:
self.elements['date'] = builder.config.today
else: