-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LaTeX: avoid quotes and TeX ligature replacements in PDF output #6891
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,12 +29,6 @@ | |
# map chars to avoid mis-interpretation in LaTeX | ||
('[', r'{[}'), | ||
(']', r'{]}'), | ||
# map chars to avoid TeX ligatures | ||
# 1. ' - and , not here for some legacy reason | ||
# 2. no effect with lualatex (done otherwise: #5790) | ||
('`', r'{}`'), | ||
('<', r'\textless{}'), | ||
('>', r'\textgreater{}'), | ||
# map special Unicode characters to TeX commands | ||
('✓', r'\(\checkmark\)'), | ||
('✔', r'\(\pmb{\checkmark}\)'), | ||
|
@@ -49,6 +43,23 @@ | |
# OHM SIGN U+2126 is handled by LaTeX textcomp package | ||
] | ||
|
||
# A map to avoid TeX ligatures or character replacements in PDF output | ||
# xelatex/lualatex/uplatex are handled differently (#5790, #6888) | ||
ascii_tex_replacements = [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would prefer tex_ascii_replacements but the other one was already called unicode_tex_replacements ... |
||
# Note: the " renders curly in OT1 encoding but straight in T1, T2A, LY1... | ||
# escaping it to \textquotedbl would break documents using OT1 | ||
# Sphinx does \shorthandoff{"} to avoid problems with some languages | ||
# There is no \text... LaTeX escape for the hyphen character - | ||
('-', r'\sphinxhyphen{}'), # -- and --- are TeX ligatures | ||
# ,, is a TeX ligature in T1 encoding, but escaping the comma adds | ||
# complications (whether by {}, or a macro) and is not done | ||
# the next two require textcomp package | ||
("'", r'\textquotesingle{}'), # else ' renders curly, and '' is a ligature | ||
('`', r'\textasciigrave{}'), # else \` and \`\` render curly | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It will be possible to allow line-breaks in parsed literals at the left and right ticks by updating Actually all escaping should be to |
||
('<', r'\textless{}'), # < is inv. exclam in OT1, << is a T1-ligature | ||
('>', r'\textgreater{}'), # > is inv. quest. mark in 0T1, >> a T1-ligature | ||
] | ||
|
||
# A map Unicode characters to LaTeX representation | ||
# (for LaTeX engines which don't support unicode) | ||
unicode_tex_replacements = [ | ||
|
@@ -85,6 +96,11 @@ | |
('₉', r'\(\sb{\text{9}}\)'), | ||
] | ||
|
||
# TODO: this should be called tex_idescape_map because its only use is in | ||
# sphinx.writers.latex.LaTeXTranslator.idescape() | ||
# %, {, }, \, #, and ~ are the only ones which must be replaced by _ character | ||
# It would be simpler to define it entirely here rather than in init(). | ||
# Unicode replacements are superfluous, as idescape() uses backslashreplace | ||
tex_replace_map = {} # type: Dict[int, str] | ||
|
||
_tex_escape_map = {} # type: Dict[int, str] | ||
|
@@ -130,8 +146,17 @@ def init() -> None: | |
_tex_escape_map_without_unicode[ord(a)] = b | ||
tex_replace_map[ord(a)] = '_' | ||
|
||
# no reason to do this for _tex_escape_map_without_unicode | ||
for a, b in ascii_tex_replacements: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the idea is that this will not be done for the _tex_hlescape_map and _tex_hlescape_map_without_unicode. One reason is that highlighter tex escaping includes the option of Verbatim which are comma separated and replacing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (this comment is now partially obsolete because the escaping of the comma has been removed) |
||
_tex_escape_map[ord(a)] = b | ||
|
||
# but the hyphen has a specific PDF bookmark problem | ||
# https://github.com/latex3/hyperref/issues/112 | ||
_tex_escape_map_without_unicode[ord('-')] = r'\sphinxhyphen{}' | ||
|
||
for a, b in unicode_tex_replacements: | ||
_tex_escape_map[ord(a)] = b | ||
# This is actually unneeded: | ||
tex_replace_map[ord(a)] = '_' | ||
|
||
for a, b in tex_replacements: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
by the way, shouldn't sphinx.util.texescape.escape() treats uplatex like xelatex and lualatex (untested). In fact the comment assumed that but it is not yet the case.