Author: milde Date: 2009-03-30 17:16:40 +0200 (Mon, 30 Mar 2009) New Revision: 5887 Modified: trunk/docutils/HISTORY.txt trunk/docutils/RELEASE-NOTES.txt trunk/docutils/docutils/writers/latex2e/__init__.py trunk/docutils/test/functional/expected/standalone_rst_latex.tex trunk/docutils/test/functional/input/data/custom_roles_latex.txt Log: latex2e writer: sub- and superscript as text, custom roles based on standard roles. Modified: trunk/docutils/HISTORY.txt =================================================================== --- trunk/docutils/HISTORY.txt 2009-03-23 17:30:45 UTC (rev 5886) +++ trunk/docutils/HISTORY.txt 2009-03-30 15:16:40 UTC (rev 5887) @@ -63,6 +63,7 @@ - Merge adjacent citations into one latex cite command. - Failsave implementation of custom roles. LaTeX compilation now ignores unknown classes instead of aborting with an error. + - Support custom roles based on standard roles. - Smaller document preamble: use fallback definitions, include only if needed in the document. - LaTeX packages can be used as ``--stylesheet`` arguments without @@ -71,8 +72,10 @@ - Add ``bp`` to lenghts without unit (prevents LaTex errors). - Do not convert ``px`` to ``pt`` (``px`` is supported by pdfTeX since 2005-02-04 as a configurable length unit). - - Do not use the obsolete 'ae' and 'aeguill' packages - if font-encoding is set to '' (default). + - Do not use fontenc, nor the obsolete 'ae' and 'aeguill' packages + if font-encoding is set to ''. LaTeX defaults to OT1 then. + - Set sub- and superscript role argument in text mode not as math. + Use a custom role based on sub-/superscript if you want italic shape. * docs/ref/rst/restructuredtext.txt: Modified: trunk/docutils/RELEASE-NOTES.txt =================================================================== --- trunk/docutils/RELEASE-NOTES.txt 2009-03-23 17:30:45 UTC (rev 5886) +++ trunk/docutils/RELEASE-NOTES.txt 2009-03-30 15:16:40 UTC (rev 5887) @@ -30,9 +30,9 @@ - Support LaTeX packages as ``--stylesheet`` arguments. - Add ``bp`` to lengths without unit; do not convert ``px`` to ``pt``. - - Do not use 'fontenc', not the obsolete 'ae' and 'aeguill' packages - if font-encoding is set to the empty string (default). - LaTeX defaults to OT1 then. + - Do not use 'ae' and 'aeguill' packages if font-encoding is set to ''. + - Set sub- and superscript role argument as text not math. + - Support custom roles based on standard roles. Release 0.5 (2008-06-25) Modified: trunk/docutils/docutils/writers/latex2e/__init__.py =================================================================== --- trunk/docutils/docutils/writers/latex2e/__init__.py 2009-03-23 17:30:45 UTC (rev 5886) +++ trunk/docutils/docutils/writers/latex2e/__init__.py 2009-03-30 15:16:40 UTC (rev 5887) @@ -374,7 +374,7 @@ ] } -latex_headings['DUrole'] = r"""% Custom roles: +latex_headings['DUrole'] = r"""% Custom roles: % \DUrole{NAME}{content} calls \docutilsroleNAME if it exists \providecommand{\DUrole}[2]{% \ifcsname docutilsrole#1\endcsname% @@ -875,8 +875,6 @@ self.literal_block = 0 self.literal_block_stack = [] self.literal = 0 - # true when encoding in math mode - self.mathmode = 0 def to_latex_encoding(self,docutils_encoding): """ @@ -985,9 +983,7 @@ # then dollar text = text.replace("$", '{\\$}') - if not ( self.literal_block or self.literal or self.mathmode ): - # the vertical bar: in mathmode |,\vert or \mid - # in textmode \textbar + if not ( self.literal_block or self.literal ): text = text.replace("|", '{\\textbar}') text = text.replace("<", '{\\textless}') text = text.replace(">", '{\\textgreater}') @@ -1154,23 +1150,25 @@ else: self.body.append( '\\end{itemize}\n' ) - # Imperfect superscript/subscript handling: mathmode italicizes - # all letters by default. def visit_superscript(self, node): - self.body.append('$^{') - self.mathmode = 1 + self.body.append(r'$^{\mbox{\scriptsize ') + if node.get('classes'): + self.visit_inline(node) def depart_superscript(self, node): - self.body.append('}$') - self.mathmode = 0 + if node.get('classes'): + self.depart_inline(node) + self.body.append('}}$') def visit_subscript(self, node): - self.body.append('$_{') - self.mathmode = 1 + self.body.append(r'$_{\mbox{\scriptsize ') + if node.get('classes'): + self.visit_inline(node) def depart_subscript(self, node): - self.body.append('}$') - self.mathmode = 0 + if node.get('classes'): + self.depart_inline(node) + self.body.append('}}$') def visit_caption(self, node): self.body.append( '\\caption{' ) @@ -1186,8 +1184,12 @@ def visit_title_reference(self, node): self.body.append( '\\titlereference{' ) + if node.get('classes'): + self.visit_inline(node) def depart_title_reference(self, node): + if node.get('classes'): + self.depart_inline(node) self.body.append( '}' ) def visit_citation(self, node): @@ -1424,9 +1426,13 @@ def visit_emphasis(self, node): self.body.append('\\emph{') + if node.get('classes'): + self.visit_inline(node) self.literal_block_stack.append('\\emph{') def depart_emphasis(self, node): + if node.get('classes'): + self.depart_inline(node) self.body.append('}') self.literal_block_stack.pop() @@ -1830,8 +1836,12 @@ def visit_literal(self, node): self.literal = 1 self.body.append('\\texttt{') + if node.get('classes'): + self.visit_inline(node) def depart_literal(self, node): + if node.get('classes'): + self.depart_inline(node) self.body.append('}') self.literal = 0 @@ -2048,8 +2058,12 @@ def visit_strong(self, node): self.body.append('\\textbf{') self.literal_block_stack.append('\\textbf{') + if node.get('classes'): + self.visit_inline(node) def depart_strong(self, node): + if node.get('classes'): + self.depart_inline(node) self.body.append('}') self.literal_block_stack.pop() Modified: trunk/docutils/test/functional/expected/standalone_rst_latex.tex =================================================================== --- trunk/docutils/test/functional/expected/standalone_rst_latex.tex 2009-03-23 17:30:45 UTC (rev 5886) +++ trunk/docutils/test/functional/expected/standalone_rst_latex.tex 2009-03-30 15:16:40 UTC (rev 5887) @@ -56,7 +56,7 @@ \ifthenelse{\isundefined{\hypersetup}}{ \usepackage[colorlinks=true,linkcolor=blue,urlcolor=blue]{hyperref} }{} -% Custom roles: +% Custom roles: % \DUrole{NAME}{content} calls \docutilsroleNAME if it exists \providecommand{\DUrole}[2]{% \ifcsname docutilsrole#1\endcsname% @@ -336,7 +336,7 @@ The default role for interpreted text is \titlereference{Title Reference}. Here are some explicit interpreted text roles: a PEP reference (\href{http://www.python.org/dev/peps/pep-0287}{PEP 287}); an -RFC reference (\href{http://www.faqs.org/rfcs/rfc2822.html}{RFC 2822}); a $_{subscript}$; a $^{superscript}$; +RFC reference (\href{http://www.faqs.org/rfcs/rfc2822.html}{RFC 2822}); a $_{\mbox{\scriptsize subscript}}$; a $^{\mbox{\scriptsize superscript}}$; and explicit roles for \emph{standard} \textbf{inline} \texttt{markup}. % DO NOT RE-WRAP THE FOLLOWING PARAGRAPH! @@ -1466,7 +1466,7 @@ \item {} A role based on an existing role. -\texttt{one} \texttt{two} \texttt{three} +\texttt{\DUrole{custom}{one}} \texttt{\DUrole{custom}{two}} \texttt{\DUrole{custom}{three}} \item {} A new role. @@ -1505,7 +1505,7 @@ \label{custom-roles-in-latex} \begin{itemize} \item {} -Role names and class arguments are are converted to conform to the regular +Role names and class arguments are converted to conform to the regular expression \texttt{{[}a-z{]}{[}-a-z0-9{]}*} (all non-conforming characters are replaced by a hyphen, all letters are downcased). @@ -1524,6 +1524,21 @@ \makeatother \DUrole{large}{\DUrole{custom4}{\DUrole{small-caps}{\DUrole{custom-role}{\DUrole{custom-role}{Interpreted Text}}}}} in large, bold, small-caps. +\item {} +Custom roles can be based on standard roles: + +This is a \emph{\DUrole{custom-emphasis}{customized emphasis text role}} + +This is a \texttt{\DUrole{custom-literal}{customized literal text role}} + +This is a \textbf{\DUrole{custom-strong}{customized strong text role}} + +This is a $_{\mbox{\scriptsize \DUrole{custom-subscript}{customized subscript text role}}}$ + +This is a $^{\mbox{\scriptsize \DUrole{custom-superscript}{customized superscript text role}}}$ + +This is a \titlereference{\DUrole{custom-title-reference}{customized title-reference text role}} + \end{itemize} % This file is used by the standalone_rst_latex test. Modified: trunk/docutils/test/functional/input/data/custom_roles_latex.txt =================================================================== --- trunk/docutils/test/functional/input/data/custom_roles_latex.txt 2009-03-23 17:30:45 UTC (rev 5886) +++ trunk/docutils/test/functional/input/data/custom_roles_latex.txt 2009-03-30 15:16:40 UTC (rev 5887) @@ -1,7 +1,7 @@ Custom Roles in LaTeX --------------------- -* Role names and class arguments are are converted to conform to the regular +* Role names and class arguments are converted to conform to the regular expression ``[a-z][-a-z0-9]*`` (all non-conforming characters are replaced by a hyphen, all letters are downcased). @@ -13,7 +13,6 @@ :custom4:`Interpreted Text` - * With LaTeX, roles can be styled within the document using the `raw` directive. @@ -26,3 +25,29 @@ \makeatother :custom4:`Interpreted Text` in large, bold, small-caps. + +* Custom roles can be based on standard roles: + + .. role:: custom-emphasis(emphasis) + + This is a :custom-emphasis:`customized emphasis text role` + + .. role:: custom-literal(literal) + + This is a :custom-literal:`customized literal text role` + + .. role:: custom-strong(strong) + + This is a :custom-strong:`customized strong text role` + + .. role:: custom-subscript(subscript) + + This is a :custom-subscript:`customized subscript text role` + + .. role:: custom-superscript(superscript) + + This is a :custom-superscript:`customized superscript text role` + + .. role:: custom-title-reference(title-reference) + + This is a :custom-title-reference:`customized title-reference text role` |