summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormilde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2013-09-05 09:37:41 +0000
committermilde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2013-09-05 09:37:41 +0000
commit288374b7827b7dd3b609cfbea579188f6e9d5ee1 (patch)
tree7c431e10dae86c4af895110c69d85fe3d843211a
parentbd30bcb0bcb75089739017730f4c48cbb528a84d (diff)
downloaddocutils-288374b7827b7dd3b609cfbea579188f6e9d5ee1.tar.gz
LaTeX writer: fix basic syntax highlight definitions for code role and directive.
git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@7719 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
-rw-r--r--docutils/writers/latex2e/__init__.py13
-rw-r--r--test/functional/expected/standalone_rst_latex.tex7
-rw-r--r--test/functional/expected/standalone_rst_xetex.tex7
-rwxr-xr-xtest/test_writers/test_latex2e.py35
4 files changed, 44 insertions, 18 deletions
diff --git a/docutils/writers/latex2e/__init__.py b/docutils/writers/latex2e/__init__.py
index b45325255..28c1fbfad 100644
--- a/docutils/writers/latex2e/__init__.py
+++ b/docutils/writers/latex2e/__init__.py
@@ -480,7 +480,7 @@ class PreambleCmds(object):
PreambleCmds.abstract = r"""
% abstract title
-\providecommand*{\DUtitleabstract}[1]{\centerline{\textbf{#1}}}"""
+\providecommand*{\DUtitleabstract}[1]{\centering\textbf{#1}}"""
PreambleCmds.admonition = r"""
% admonition (specially marked topic)
@@ -2402,9 +2402,10 @@ class LaTeXTranslator(nodes.NodeVisitor):
def visit_literal(self, node):
self.literal = True
- if 'code' in node.get('classes', []):
+ if 'code' in node['classes'] and (
+ self.settings.syntax_highlight != 'none'):
self.requirements['color'] = PreambleCmds.color
- self.requirements['code'] = PreambleCmds.highlight_rules
+ self.fallbacks['code'] = PreambleCmds.highlight_rules
self.out.append('\\texttt{')
if node['classes']:
self.visit_inline(node)
@@ -2446,7 +2447,7 @@ class LaTeXTranslator(nodes.NodeVisitor):
if not self.active_table.is_open():
# no quote inside tables, to avoid vertical space between
# table border and literal block.
- # BUG: fails if normal text preceeds the literal block.
+ # BUG: fails if normal text precedes the literal block.
self.out.append('%\n\\begin{quote}')
self.context.append('\n\\end{quote}\n')
else:
@@ -2462,6 +2463,10 @@ class LaTeXTranslator(nodes.NodeVisitor):
self.literal = True
self.insert_newline = True
self.insert_non_breaking_blanks = True
+ if 'code' in node['classes'] and (
+ self.settings.syntax_highlight != 'none'):
+ self.requirements['color'] = PreambleCmds.color
+ self.fallbacks['code'] = PreambleCmds.highlight_rules
self.out.append('{\\ttfamily \\raggedright \\noindent\n')
def depart_literal_block(self, node):
diff --git a/test/functional/expected/standalone_rst_latex.tex b/test/functional/expected/standalone_rst_latex.tex
index 54308b6c0..6e652c0c6 100644
--- a/test/functional/expected/standalone_rst_latex.tex
+++ b/test/functional/expected/standalone_rst_latex.tex
@@ -10,11 +10,6 @@
% Prevent side-effects if French hyphenation patterns are not loaded:
\frenchbsetup{StandardLayout}
\AtBeginDocument{\selectlanguage{english}\noextrasfrench}
-% basic code highlight:
-\providecommand*\DUrolecomment[1]{\textcolor[rgb]{0.40,0.40,0.40}{#1}}
-\providecommand*\DUroledeleted[1]{\textcolor[rgb]{0.40,0.40,0.40}{#1}}
-\providecommand*\DUrolekeyword[1]{\textbf{#1}}
-\providecommand*\DUrolestring[1]{\textit{#1}}
\usepackage{color}
\usepackage{float} % float configuration
\floatplacement{figure}{H} % place figures here definitely
@@ -44,7 +39,7 @@
}
% abstract title
-\providecommand*{\DUtitleabstract}[1]{\centerline{\textbf{#1}}}
+\providecommand*{\DUtitleabstract}[1]{\centering\textbf{#1}}
% admonition (specially marked topic)
\providecommand{\DUadmonition}[2][class-arg]{%
diff --git a/test/functional/expected/standalone_rst_xetex.tex b/test/functional/expected/standalone_rst_xetex.tex
index a5abbb198..730e4c835 100644
--- a/test/functional/expected/standalone_rst_xetex.tex
+++ b/test/functional/expected/standalone_rst_xetex.tex
@@ -8,11 +8,6 @@
\usepackage{polyglossia}
\setdefaultlanguage{english}
\setotherlanguages{british,french,german}
-% basic code highlight:
-\providecommand*\DUrolecomment[1]{\textcolor[rgb]{0.40,0.40,0.40}{#1}}
-\providecommand*\DUroledeleted[1]{\textcolor[rgb]{0.40,0.40,0.40}{#1}}
-\providecommand*\DUrolekeyword[1]{\textbf{#1}}
-\providecommand*\DUrolestring[1]{\textit{#1}}
\usepackage{color}
\usepackage{float} % float configuration
\floatplacement{figure}{H} % place figures here definitely
@@ -40,7 +35,7 @@
}
% abstract title
-\providecommand*{\DUtitleabstract}[1]{\centerline{\textbf{#1}}}
+\providecommand*{\DUtitleabstract}[1]{\centering\textbf{#1}}
% admonition (specially marked topic)
\providecommand{\DUadmonition}[2][class-arg]{%
diff --git a/test/test_writers/test_latex2e.py b/test/test_writers/test_latex2e.py
index e81c1430b..97ac130a0 100755
--- a/test/test_writers/test_latex2e.py
+++ b/test/test_writers/test_latex2e.py
@@ -61,6 +61,26 @@ latex_preamble = r"""% PDF Standard Fonts
""",
stylesheet = '',
fallbacks = '',
+fallbacks_highlight = r"""% basic code highlight:
+\providecommand*\DUrolecomment[1]{\textcolor[rgb]{0.40,0.40,0.40}{#1}}
+\providecommand*\DUroledeleted[1]{\textcolor[rgb]{0.40,0.40,0.40}{#1}}
+\providecommand*\DUrolekeyword[1]{\textbf{#1}}
+\providecommand*\DUrolestring[1]{\textit{#1}}
+
+% inline markup (custom roles)
+% \DUrole{#1}{#2} tries \DUrole#1{#2}
+\providecommand*{\DUrole}[2]{%
+ \ifcsname DUrole#1\endcsname%
+ \csname DUrole#1\endcsname{#2}%
+ \else% backwards compatibility: try \docutilsrole#1{#2}
+ \ifcsname docutilsrole#1\endcsname%
+ \csname docutilsrole#1\endcsname{#2}%
+ \else%
+ #2%
+ \fi%
+ \fi%
+}
+""",
pdfsetup = r"""
% hyperlinks:
\ifthenelse{\isundefined{\hypersetup}}{
@@ -124,6 +144,17 @@ Und damit \foreignlanguage{spanish}{basta}!
"""],
]
+totest['code role'] = [
+[":code:`x=1`",
+head_template.substitute(dict(parts, requirements = parts['requirements']+
+r"""\usepackage{color}
+""", fallbacks = parts['fallbacks_highlight'])) + r"""
+\texttt{\DUrole{code}{x=1}}
+
+\end{document}
+"""],
+]
+
totest['table_of_contents'] = [
# input
["""\
@@ -485,7 +516,7 @@ head_table + r"""
# The "[" needs to be protected (otherwise it will be seen as an
# option to "\\", "\item", etc. ).
-totest['brackett_protection'] = [
+totest['bracket_protection'] = [
# input
["""\
::
@@ -549,7 +580,7 @@ This is a *section title*
This is the *document*.
""",
-head_template.substitute(dict(parts,
+head_template.substitute(dict(parts,
requirements=parts['requirements'] + '\\setcounter{secnumdepth}{0}\n',
pdfsetup=parts['pdfsetup'] + r"""\hypersetup{
pdftitle={This is the Title},