|
From: <mi...@us...> - 2017-04-19 16:45:35
|
Revision: 8058
http://sourceforge.net/p/docutils/code/8058
Author: milde
Date: 2017-04-19 16:45:32 +0000 (Wed, 19 Apr 2017)
Log Message:
-----------
LaTeX: Define required Unicode characters in the preamble.
If the encoding is utf8, we can define missing characters once in the
preamble instead of translating every occurence into a LaTeX command.
Modified Paths:
--------------
trunk/docutils/docutils/writers/latex2e/__init__.py
trunk/docutils/test/functional/expected/latex_babel.tex
trunk/docutils/test/functional/expected/standalone_rst_latex.tex
trunk/docutils/test/test_writers/test_latex2e.py
Modified: trunk/docutils/docutils/writers/latex2e/__init__.py
===================================================================
--- trunk/docutils/docutils/writers/latex2e/__init__.py 2017-04-15 19:09:59 UTC (rev 8057)
+++ trunk/docutils/docutils/writers/latex2e/__init__.py 2017-04-19 16:45:32 UTC (rev 8058)
@@ -727,19 +727,31 @@
}
# Unicode chars that are not recognized by LaTeX's utf8 encoding
unsupported_unicode = {
- 0x00A0: ur'~', # NO-BREAK SPACE
# TODO: ensure white space also at the beginning of a line?
# 0x00A0: ur'\leavevmode\nobreak\vadjust{}~'
+ 0x2000: ur'\enskip', # EN QUAD
+ 0x2001: ur'\quad', # EM QUAD
+ 0x2002: ur'\enskip', # EN SPACE
+ 0x2003: ur'\quad', # EM SPACE
0x2008: ur'\,', # PUNCTUATION SPACE
+ 0x200b: ur'\hspace{0pt}', # ZERO WIDTH SPACE
+ 0x202F: ur'\,', # NARROW NO-BREAK SPACE
+ # 0x02d8: ur'\\u{ }', # BREVE
0x2011: ur'\hbox{-}', # NON-BREAKING HYPHEN
- 0x202F: ur'\,', # NARROW NO-BREAK SPACE
- 0x21d4: ur'$\Leftrightarrow$',
+ 0x212b: ur'\AA', # ANGSTROM SIGN
+ 0x21d4: ur'\ensuremath{\Leftrightarrow}',
# Docutils footnote symbols:
- 0x2660: ur'$\spadesuit$',
- 0x2663: ur'$\clubsuit$',
+ 0x2660: ur'\ensuremath{\spadesuit}',
+ 0x2663: ur'\ensuremath{\clubsuit}',
+ 0xfb00: ur'ff', # LATIN SMALL LIGATURE FF
+ 0xfb01: ur'fi', # LATIN SMALL LIGATURE FI
+ 0xfb02: ur'fl', # LATIN SMALL LIGATURE FL
+ 0xfb03: ur'ffi', # LATIN SMALL LIGATURE FFI
+ 0xfb04: ur'ffl', # LATIN SMALL LIGATURE FFL
}
# Unicode chars that are recognized by LaTeX's utf8 encoding
utf8_supported_unicode = {
+ 0x00A0: ur'~', # NO-BREAK SPACE
0x00AB: ur'\guillemotleft{}', # LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
0x00bb: ur'\guillemotright{}', # RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
0x200C: ur'\textcompwordmark{}', # ZERO WIDTH NON-JOINER
@@ -1503,17 +1515,24 @@
table[ord(' ')] = ur'~'
# Unicode replacements for 8-bit tex engines (not required with XeTeX/LuaTeX):
if not self.is_xetex:
- table.update(CharMaps.unsupported_unicode)
if not self.latex_encoding.startswith('utf8'):
+ table.update(CharMaps.unsupported_unicode)
table.update(CharMaps.utf8_supported_unicode)
table.update(CharMaps.textcomp)
table.update(CharMaps.pifont)
# Characters that require a feature/package to render
- if [True for ch in text if ord(ch) in CharMaps.textcomp]:
- self.requirements['textcomp'] = PreambleCmds.textcomp
- if [True for ch in text if ord(ch) in CharMaps.pifont]:
+ for ch in text:
+ cp = ord(ch)
+ if cp in CharMaps.textcomp:
+ self.requirements['textcomp'] = PreambleCmds.textcomp
+ elif cp in CharMaps.pifont:
self.requirements['pifont'] = '\\usepackage{pifont}'
-
+ # preamble-definitions for unsupported Unicode characters
+ elif (self.latex_encoding == 'utf8'
+ and cp in CharMaps.unsupported_unicode):
+ self.requirements['_inputenc'+str(cp)] = (
+ '\\DeclareUnicodeCharacter{%04X}{%s}'
+ % (cp, CharMaps.unsupported_unicode[cp]))
text = text.translate(table)
# Break up input ligatures e.g. '--' to '-{}-'.
Modified: trunk/docutils/test/functional/expected/latex_babel.tex
===================================================================
--- trunk/docutils/test/functional/expected/latex_babel.tex 2017-04-15 19:09:59 UTC (rev 8057)
+++ trunk/docutils/test/functional/expected/latex_babel.tex 2017-04-19 16:45:32 UTC (rev 8058)
@@ -40,17 +40,17 @@
quote (\textquotedbl{}). Problematic is the tilde character (\textasciitilde{}) which is regularely used
for no-break spaces but redefined by some language definition files:
-English: 'an' \textquotedbl{}active\textquotedbl{}-quote, \textasciicircum{}circumflex, and~no-break~spaces
+English: 'an' \textquotedbl{}active\textquotedbl{}-quote, \textasciicircum{}circumflex, and no-break spaces
-\foreignlanguage{basque}{Basque: 'an' \textquotedbl{}active\textquotedbl{}-quote, \textasciicircum{}circumflex, and~no-break~spaces}
+\foreignlanguage{basque}{Basque: 'an' \textquotedbl{}active\textquotedbl{}-quote, \textasciicircum{}circumflex, and no-break spaces}
-\foreignlanguage{esperanto}{Esperanto: 'an' \textquotedbl{}active\textquotedbl{}-quote, \textasciicircum{}circumflex, and~no-break~spaces}
+\foreignlanguage{esperanto}{Esperanto: 'an' \textquotedbl{}active\textquotedbl{}-quote, \textasciicircum{}circumflex, and no-break spaces}
-\foreignlanguage{estonian}{Estonian: 'an' \textquotedbl{}active\textquotedbl{}-quote, \textasciicircum{}circumflex, and~no-break~spaces}
+\foreignlanguage{estonian}{Estonian: 'an' \textquotedbl{}active\textquotedbl{}-quote, \textasciicircum{}circumflex, and no-break spaces}
-\foreignlanguage{galician}{Galician: 'an' \textquotedbl{}active\textquotedbl{}-quote, \textasciicircum{}circumflex, and~no-break~spaces}
+\foreignlanguage{galician}{Galician: 'an' \textquotedbl{}active\textquotedbl{}-quote, \textasciicircum{}circumflex, and no-break spaces}
-\foreignlanguage{ngerman}{German: 'an' \textquotedbl{}active\textquotedbl{}-quote, \textasciicircum{}circumflex, and~no-break~spaces}
+\foreignlanguage{ngerman}{German: 'an' \textquotedbl{}active\textquotedbl{}-quote, \textasciicircum{}circumflex, and no-break spaces}
Spanish: option clash with Galician!
Modified: trunk/docutils/test/functional/expected/standalone_rst_latex.tex
===================================================================
--- trunk/docutils/test/functional/expected/standalone_rst_latex.tex 2017-04-15 19:09:59 UTC (rev 8057)
+++ trunk/docutils/test/functional/expected/standalone_rst_latex.tex 2017-04-19 16:45:32 UTC (rev 8058)
@@ -4,6 +4,9 @@
\usepackage{ifthen}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
+\DeclareUnicodeCharacter{21D4}{\ensuremath{\Leftrightarrow}}
+\DeclareUnicodeCharacter{2660}{\ensuremath{\spadesuit}}
+\DeclareUnicodeCharacter{2663}{\ensuremath{\clubsuit}}
\usepackage{amsmath}
\usepackage[british,french,ngerman,english]{babel}
% Prevent side-effects if French hyphenation patterns are not loaded:
@@ -289,12 +292,12 @@
\tableofcontents
-\section{1~~~Structural Elements%
+\section{1 Structural Elements%
\label{structural-elements}%
}
-\subsection{1.1~~~Section Title%
+\subsection{1.1 Section Title%
\label{section-title}%
}
\subsubsection*{Section Subtitle}
@@ -304,12 +307,12 @@
\texttt{sectsubtitle-xform} configuration value.
-\subsection{1.2~~~Empty Section%
+\subsection{1.2 Empty Section%
\label{empty-section}%
}
-\subsection{1.3~~~Transitions%
+\subsection{1.3 Transitions%
\label{transitions}%
}
@@ -324,12 +327,12 @@
\DUtransition
-\section{2~~~Body Elements%
+\section{2 Body Elements%
\label{body-elements}%
}
-\subsection{2.1~~~Paragraphs%
+\subsection{2.1 Paragraphs%
\label{paragraphs}%
}
@@ -336,7 +339,7 @@
A paragraph.
-\subsubsection{2.1.1~~~Inline Markup%
+\subsubsection{2.1.1 Inline Markup%
\label{inline-markup}%
}
@@ -375,7 +378,7 @@
live link to PEP 258 here.
-\subsection{2.2~~~Bullet Lists%
+\subsection{2.2 Bullet Lists%
\label{bullet-lists}%
}
@@ -413,7 +416,7 @@
\end{itemize}
-\subsection{2.3~~~Enumerated Lists%
+\subsection{2.3 Enumerated Lists%
\label{enumerated-lists}%
}
@@ -466,7 +469,7 @@
\end{enumerate}
-\subsection{2.4~~~Definition Lists%
+\subsection{2.4 Definition Lists%
\label{definition-lists}%
}
@@ -488,7 +491,7 @@
\end{description}
-\subsection{2.5~~~Field Lists%
+\subsection{2.5 Field Lists%
\label{field-lists}%
}
@@ -511,7 +514,7 @@
\end{DUfieldlist}
-\subsection{2.6~~~Option Lists%
+\subsection{2.6 Option Lists%
\label{option-lists}%
}
@@ -546,7 +549,7 @@
description.
-\subsection{2.7~~~Literal Blocks%
+\subsection{2.7 Literal Blocks%
\label{literal-blocks}%
}
@@ -573,7 +576,7 @@
\end{quote}
-\subsection{2.8~~~Line Blocks%
+\subsection{2.8 Line Blocks%
\label{line-blocks}%
}
@@ -659,7 +662,7 @@
\item[] Durch ihres Rumpfs verengten Schacht
\item[] fließt weißes Mondlicht
\item[] still und heiter
-\item[] auf ~ ihren
+\item[] auf ihren
\item[] Waldweg
\item[] u. s.
\item[] w.
@@ -668,7 +671,7 @@
\end{selectlanguage}
-\subsection{2.9~~~Block Quotes%
+\subsection{2.9 Block Quotes%
\label{block-quotes}%
}
@@ -698,7 +701,7 @@
\end{selectlanguage}
-\subsection{2.10~~~Doctest Blocks%
+\subsection{2.10 Doctest Blocks%
\label{doctest-blocks}%
}
@@ -712,7 +715,7 @@
\end{quote}
-\subsection{2.11~~~Footnotes%
+\subsection{2.11 Footnotes%
\label{footnotes}%
}
%
@@ -755,7 +758,7 @@
}
-\subsection{2.12~~~Citations%
+\subsection{2.12 Citations%
\label{citations}%
}
\begin{figure}[b]\raisebox{1em}{\hypertarget{cit2002}{}}[CIT2002]
@@ -768,7 +771,7 @@
citation.
-\subsection{2.13~~~Targets%
+\subsection{2.13 Targets%
\label{targets}%
\label{another-target}%
}
@@ -792,7 +795,7 @@
error.
-\subsubsection{2.13.1~~~Duplicate Target Names%
+\subsubsection{2.13.1 Duplicate Target Names%
\label{duplicate-target-names}%
}
@@ -801,7 +804,7 @@
explicit targets will generate “warning” (level-2) system messages.
-\subsubsection{2.13.2~~~Duplicate Target Names%
+\subsubsection{2.13.2 Duplicate Target Names%
\label{id21}%
}
@@ -811,7 +814,7 @@
\raisebox{1em}{\hypertarget{id50}{}}\hyperlink{id49}{\textbf{\color{red}`Duplicate Target Names`\_}}), an error is generated.
-\subsection{2.14~~~Directives%
+\subsection{2.14 Directives%
\label{directives}%
}
@@ -821,7 +824,7 @@
\url{http://docutils.sourceforge.net/docs/ref/rst/directives.html}.
-\subsubsection{2.14.1~~~Document Parts%
+\subsubsection{2.14.1 Document Parts%
\label{document-parts}%
}
@@ -830,7 +833,7 @@
document (a document-wide \hyperref[table-of-contents]{table of contents}).
-\subsubsection{2.14.2~~~Images and Figures%
+\subsubsection{2.14.2 Images and Figures%
\label{images-and-figures}%
}
@@ -1117,7 +1120,7 @@
\label{target2}\label{target1}
-\subsubsection{2.14.3~~~Admonitions%
+\subsubsection{2.14.3 Admonitions%
\label{admonitions}%
}
@@ -1191,7 +1194,7 @@
}
-\subsubsection{2.14.4~~~Topics, Sidebars, and Rubrics%
+\subsubsection{2.14.4 Topics, Sidebars, and Rubrics%
\label{topics-sidebars-and-rubrics}%
}
@@ -1231,7 +1234,7 @@
allowed (e.g. inside a directive).
-\subsubsection{2.14.5~~~Target Footnotes%
+\subsubsection{2.14.5 Target Footnotes%
\label{target-footnotes}%
}
%
@@ -1256,7 +1259,7 @@
}
-\subsubsection{2.14.6~~~Replacement Text%
+\subsubsection{2.14.6 Replacement Text%
\label{replacement-text}%
}
@@ -1263,7 +1266,7 @@
I recommend you try \href{http://www.python.org/}{Python, \emph{the} best language around}\DUfootnotemark{id32}{id29}{5}.
-\subsubsection{2.14.7~~~Compound Paragraph%
+\subsubsection{2.14.7 Compound Paragraph%
\label{compound-paragraph}%
}
@@ -1400,7 +1403,7 @@
\end{DUclass}
-\subsubsection{2.14.8~~~Parsed Literal Blocks%
+\subsubsection{2.14.8 Parsed Literal Blocks%
\label{parsed-literal-blocks}%
}
@@ -1418,7 +1421,7 @@
\end{quote}
-\subsubsection{2.14.9~~~Code%
+\subsubsection{2.14.9 Code%
\label{code}%
}
@@ -1477,7 +1480,7 @@
\end{DUclass}
-\subsection{2.15~~~Substitution Definitions%
+\subsection{2.15 Substitution Definitions%
\label{substitution-definitions}%
}
@@ -1486,7 +1489,7 @@
(Substitution definitions are not visible in the HTML source.)
-\subsection{2.16~~~Comments%
+\subsection{2.16 Comments%
\label{comments}%
}
@@ -1503,7 +1506,7 @@
(View the HTML source to see the comment.)
-\subsection{2.17~~~Raw text%
+\subsection{2.17 Raw text%
\label{raw-text}%
}
@@ -1522,7 +1525,7 @@
Fifth test in LaTeX.\\Line two.
-\subsection{2.18~~~Container%
+\subsection{2.18 Container%
\label{container}%
}
@@ -1537,7 +1540,7 @@
% .. include:: data/header_footer.txt
-\subsection{2.19~~~Colspanning tables%
+\subsection{2.19 Colspanning tables%
\label{colspanning-tables}%
}
@@ -1615,7 +1618,7 @@
\end{longtable*}
-\subsection{2.20~~~Rowspanning tables%
+\subsection{2.20 Rowspanning tables%
\label{rowspanning-tables}%
}
@@ -1674,7 +1677,7 @@
\end{longtable*}
-\subsection{2.21~~~Custom Roles%
+\subsection{2.21 Custom Roles%
\label{custom-roles}%
}
@@ -1718,7 +1721,7 @@
\end{itemize}
-\subsection{2.22~~~Mathematics%
+\subsection{2.22 Mathematics%
\label{mathematics}%
}
@@ -1844,7 +1847,7 @@
\end{cases}
\end{equation*}
-\section{3~~~Tests for the LaTeX writer%
+\section{3 Tests for the LaTeX writer%
\label{tests-for-the-latex-writer}%
}
@@ -1852,7 +1855,7 @@
not need to be tested with other writers (e.g. the HTML writer).
-\subsection{3.1~~~Custom Roles in LaTeX%
+\subsection{3.1 Custom Roles in LaTeX%
\label{custom-roles-in-latex}%
}
@@ -1895,7 +1898,7 @@
\end{itemize}
-\subsection{3.2~~~class handling%
+\subsection{3.2 class handling%
\label{class-handling}%
}
@@ -1997,7 +2000,7 @@
\end{DUlineblock}
-\subsection{3.3~~~More Tables%
+\subsection{3.3 More Tables%
\label{more-tables}%
}
@@ -2099,7 +2102,7 @@
% This file is used by the standalone_rst_latex test.
-\subsection{3.4~~~Option lists%
+\subsection{3.4 Option lists%
\label{id23}%
}
@@ -2129,7 +2132,7 @@
\end{description}
-\subsection{3.5~~~Monospaced non-alphanumeric characters%
+\subsection{3.5 Monospaced non-alphanumeric characters%
\label{monospaced-non-alphanumeric-characters}%
}
@@ -2145,7 +2148,7 @@
width as the third line.
-\subsection{3.6~~~Non-ASCII characters%
+\subsection{3.6 Non-ASCII characters%
\label{non-ascii-characters}%
}
@@ -2227,13 +2230,13 @@
\\
\hline
-$\spadesuit$
+♠
&
black spade suit
\\
\hline
-$\clubsuit$
+♣
&
black club suit
\\
@@ -2251,7 +2254,7 @@
\\
\hline
-$\Leftrightarrow$
+⇔
&
left-right double arrow
\\
@@ -2521,7 +2524,7 @@
\item The following line should not be wrapped, because it uses
no-break spaces (\textbackslash{}u00a0):
-X~X~X~X~X~X~X~X~X~X~X~X~X~X~X~X~X~X~X~X~X~X~X~X~X~X~X~X~X~X~X~X~X~X~X~X~X~X~X~X~X~X~X~X~X~X~X~X~X~X~X~X~X~X~X~X~X~X~X~X~X~X~X~X~X~X
+X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X
\item Line wrapping with/without breakpoints marked by soft hyphens
(\textbackslash{}u00ad):
@@ -2532,7 +2535,7 @@
\end{itemize}
-\subsection{3.7~~~Encoding special chars%
+\subsection{3.7 Encoding special chars%
\label{encoding-special-chars}%
}
@@ -2595,7 +2598,7 @@
\end{quote}
-\subsection{3.8~~~Hyperlinks and -targets%
+\subsection{3.8 Hyperlinks and -targets%
\label{hyperlinks-and-targets}%
}
@@ -2641,7 +2644,7 @@
\hyperref[image-label]{image label}.
-\subsection{3.9~~~External references%
+\subsection{3.9 External references%
\label{external-references}%
}
@@ -2723,22 +2726,22 @@
\end{itemize}
-\subsection{3.10~~~Section titles with \hyperref[inline-markup]{inline markup}%
+\subsection{3.10 Section titles with \hyperref[inline-markup]{inline markup}%
\label{section-titles-with-inline-markup}%
}
-\subsubsection{3.10.1~~~\emph{emphasized}, H\textsubscript{2}O and $x^2$%
+\subsubsection{3.10.1 \emph{emphasized}, H\textsubscript{2}O and $x^2$%
\label{emphasized-h2o-and-x-2}%
}
-\subsubsection{3.10.2~~~Substitutions work%
+\subsubsection{3.10.2 Substitutions work%
\label{substitutions-fail}%
}
-\subsection{3.11~~~Deeply nested sections%
+\subsection{3.11 Deeply nested sections%
\label{deeply-nested-sections}%
}
@@ -2745,7 +2748,7 @@
In LaTeX and HTML,
-\subsubsection{3.11.1~~~Level 3%
+\subsubsection{3.11.1 Level 3%
\label{level-3}%
}
@@ -2752,7 +2755,7 @@
nested sections
-\paragraph{3.11.1.1~~~level 4%
+\paragraph{3.11.1.1 level 4%
\label{level-4}%
}
@@ -2759,7 +2762,7 @@
reach at some level
-\subparagraph{3.11.1.1.1~~~level 5%
+\subparagraph{3.11.1.1.1 level 5%
\label{level-5}%
}
@@ -2766,7 +2769,7 @@
(depending on the document class)
-\DUtitle[sectionVI]{3.11.1.1.1.1~~~level 6%
+\DUtitle[sectionVI]{3.11.1.1.1.1 level 6%
\label{level-6}%
}
@@ -2778,7 +2781,7 @@
% Preface for System Messages:
-\section{4~~~Error Handling%
+\section{4 Error Handling%
\label{error-handling}%
}
Modified: trunk/docutils/test/test_writers/test_latex2e.py
===================================================================
--- trunk/docutils/test/test_writers/test_latex2e.py 2017-04-15 19:09:59 UTC (rev 8057)
+++ trunk/docutils/test/test_writers/test_latex2e.py 2017-04-19 16:45:32 UTC (rev 8058)
@@ -309,7 +309,7 @@
\tableofcontents
-\section{1~~~first section%
+\section{1 first section%
\label{first-section}%
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|