summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjfbu <jfbu@free.fr>2019-11-15 19:35:01 +0100
committerjfbu <jfbu@free.fr>2019-11-16 10:36:41 +0100
commit38926cf708fac6770c67423eb87fc74dc8f02896 (patch)
treeb7c739b3088edbf11c52411f61979e91b607a689
parentaf9a404de84c98a4ae94f4e4e77c6aacec5ea3fc (diff)
downloadsphinx-git-38926cf708fac6770c67423eb87fc74dc8f02896.tar.gz
LaTeX: escape fewer Unicode chars if engine is lualatex or xelatex
-rw-r--r--CHANGES3
-rw-r--r--sphinx/util/texescape.py30
2 files changed, 20 insertions, 13 deletions
diff --git a/CHANGES b/CHANGES
index 9d3b51cc4..250e9589c 100644
--- a/CHANGES
+++ b/CHANGES
@@ -43,7 +43,8 @@ Bugs fixed
.. _latex3/latex2e#173: https://github.com/latex3/latex2e/issues/173
* #6618: LaTeX: Avoid section names at the end of a page
* #6738: LaTeX: Do not replace unicode characters by LaTeX macros on unicode
- supported LaTeX engines
+ supported LaTeX engines: ¶, §, €, ∞, ±, →, ‣, –, superscript and subscript
+ digits go through "as is" (as default OpenType font supports them)
* #6704: linkcheck: Be defensive and handle newly defined HTTP error code
* #6655: image URLs containing ``data:`` causes gettext builder crashed
* #6584: i18n: Error when compiling message catalogs on Hindi
diff --git a/sphinx/util/texescape.py b/sphinx/util/texescape.py
index c3231d3d3..e3c45adb4 100644
--- a/sphinx/util/texescape.py
+++ b/sphinx/util/texescape.py
@@ -20,29 +20,28 @@ tex_replacements = [
('_', r'\_'),
('{', r'\{'),
('}', r'\}'),
+ ('\\', r'\textbackslash{}'),
+ ('~', r'\textasciitilde{}'),
+ ('^', r'\textasciicircum{}'),
+ # 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'\textbackslash{}'),
- ('~', r'\textasciitilde{}'),
('<', r'\textless{}'),
('>', r'\textgreater{}'),
- ('^', r'\textasciicircum{}'),
+ # map char for some unknown reason. TODO: remove this?
+ ('|', r'\textbar{}'),
# map special Unicode characters to TeX commands
- ('¶', r'\P{}'),
- ('§', r'\S{}'),
- ('€', r'\texteuro{}'),
- ('±', r'\(\pm\)'),
- ('→', r'\(\rightarrow\)'),
- ('‣', r'\(\rightarrow\)'),
('✓', r'\(\checkmark\)'),
('✔', r'\(\pmb{\checkmark}\)'),
# used to separate -- in options
('', r'{}'),
# map some special Unicode characters to similar ASCII ones
+ # (even for Unicode LaTeX as may not be supported by OpenType font)
('⎽', r'\_'),
- ('–', r'\textendash{}'),
- ('|', r'\textbar{}'),
('ℯ', r'e'),
('ⅈ', r'i'),
# Greek alphabet not escaped: pdflatex handles it via textalpha and inputenc
@@ -52,8 +51,15 @@ tex_replacements = [
# A map Unicode characters to LaTeX representation
# (for LaTeX engines which don't support unicode)
unicode_tex_replacements = [
- # map special Unicode characters to TeX commands
+ # map some more common Unicode characters to TeX commands
+ ('¶', r'\P{}'),
+ ('§', r'\S{}'),
+ ('€', r'\texteuro{}'),
('∞', r'\(\infty\)'),
+ ('±', r'\(\pm\)'),
+ ('→', r'\(\rightarrow\)'),
+ ('‣', r'\(\rightarrow\)'),
+ ('–', r'\textendash{}'),
# superscript
('⁰', r'\(\sp{\text{0}}\)'),
('¹', r'\(\sp{\text{1}}\)'),