latex: escape \releasename and \indexname

This commit is contained in:
Takeshi KOMIYA 2018-10-07 13:49:14 +09:00
parent 6eb5b29484
commit 75fdf1363e
3 changed files with 17 additions and 3 deletions

View File

@ -48,7 +48,7 @@
\author{<%= author %>} \author{<%= author %>}
\newcommand{\sphinxlogo}{<%= logo %>} \newcommand{\sphinxlogo}{<%= logo %>}
<%- if releasename or release %> <%- if releasename or release %>
\renewcommand{\releasename}{<%= releasename or _('Release') %>} \renewcommand{\releasename}{<%= releasename or _('Release') | e %>}
<%- else %> <%- else %>
\renewcommand{\releasename}{} \renewcommand{\releasename}{}
<%- endif %> <%- endif %>
@ -63,6 +63,6 @@
<%= body %> <%= body %>
<%= atendofbody %> <%= atendofbody %>
<%= indices %> <%= indices %>
\renewcommand{\indexname}{<%= _('Index') %>} \renewcommand{\indexname}{<%= _('Index') | e %>}
<%= printindex %> <%= printindex %>
\end{document} \end{document}

View File

@ -16,6 +16,7 @@ from jinja2.sandbox import SandboxedEnvironment
from sphinx import package_dir from sphinx import package_dir
from sphinx.jinja2glue import SphinxFileSystemLoader from sphinx.jinja2glue import SphinxFileSystemLoader
from sphinx.locale import get_translator from sphinx.locale import get_translator
from sphinx.util import texescape
if False: if False:
# For type annotation # For type annotation
@ -72,6 +73,10 @@ class LaTeXRenderer(SphinxRenderer):
template_path = os.path.join(package_dir, 'templates', 'latex') template_path = os.path.join(package_dir, 'templates', 'latex')
super(LaTeXRenderer, self).__init__(template_path) super(LaTeXRenderer, self).__init__(template_path)
# use texescape as escape filter
self.env.filters['e'] = texescape.escape
self.env.filters['escape'] = texescape.escape
# use JSP/eRuby like tagging instead because curly bracket; the default # use JSP/eRuby like tagging instead because curly bracket; the default
# tagging of jinja2 is not good for LaTeX sources. # tagging of jinja2 is not good for LaTeX sources.
self.env.variable_start_string = '<%=' self.env.variable_start_string = '<%='

View File

@ -11,6 +11,10 @@
from __future__ import unicode_literals from __future__ import unicode_literals
if False:
# For type annotation
from typing import Dict # NOQA
tex_replacements = [ tex_replacements = [
# map TeX special chars # map TeX special chars
('$', r'\$'), ('$', r'\$'),
@ -117,11 +121,16 @@ tex_replacements = [
('', r'\(\Omega\)'), ('', r'\(\Omega\)'),
] ]
tex_escape_map = {} tex_escape_map = {} # type: Dict[int, unicode]
tex_replace_map = {} tex_replace_map = {}
tex_hl_escape_map_new = {} tex_hl_escape_map_new = {}
def escape(s):
# type: (unicode) -> unicode
return s.translate(tex_escape_map)
def init(): def init():
# type: () -> None # type: () -> None
for a, b in tex_replacements: for a, b in tex_replacements: