From dd993980aaed320742b3d1b4ecc8a84c1dd10a79 Mon Sep 17 00:00:00 2001 From: grubert Date: Wed, 7 Jul 2004 07:56:26 +0000 Subject: [PATCH] Indent literal-blocks. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2423 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- HISTORY.txt | 2 ++ docutils/writers/latex2e.py | 16 +++++++++------- test/functional/expected/standalone_rst_latex.tex | 8 ++++---- test/test_writers/test_latex2e.py | 12 ++++++------ 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/HISTORY.txt b/HISTORY.txt index 3cef21713..38c448fbc 100644 --- a/HISTORY.txt +++ b/HISTORY.txt @@ -125,6 +125,8 @@ Specific: width. - Fix: encode pdfbookmark titles, ``#`` broke pdflatex. - A few unicode replacements, if output_encoding != utf + - Add "--graphicx-option". + - Indent literal-blocks. * docs/index.txt: "Docutils Project Documentation Overview", added to project. diff --git a/docutils/writers/latex2e.py b/docutils/writers/latex2e.py index 740c6acee..a4952d692 100644 --- a/docutils/writers/latex2e.py +++ b/docutils/writers/latex2e.py @@ -1532,29 +1532,31 @@ class LaTeXTranslator(nodes.NodeVisitor): # in case of a parsed-literal containing just a "**bold**" word: and isinstance(node[0], nodes.Text)): self.verbatim = 1 - self.body.append('\\begin{verbatim}\n') + self.body.append('\\begin{quote}\\begin{verbatim}\n') else: self.literal_block = 1 self.insert_none_breaking_blanks = 1 if self.active_table.is_open(): self.body.append('\n{\\ttfamily \\raggedright \\noindent\n') - else: - self.body.append('\\begin{ttfamily}') - self.body.append('\\begin{flushleft}\n') + else: + # no quote inside tables, to avoid vertical sppace between + # table border and literal block. + # BUG: fails if normal text preceeds the literal block. + self.body.append('\\begin{quote}') + self.body.append('{\\ttfamily \\raggedright \\noindent\n') # * obey..: is from julien and never worked for me (grubert). # self.body.append('{\\obeylines\\obeyspaces\\ttfamily\n') def depart_literal_block(self, node): if self.verbatim: - self.body.append('\n\\end{verbatim}\n') + self.body.append('\n\\end{verbatim}\\end{quote}\n') self.verbatim = 0 else: if self.active_table.is_open(): self.body.append('\n}\n') else: self.body.append('\n') - self.body.append('\\end{flushleft}') - self.body.append('\\end{ttfamily}\n') + self.body.append('}\\end{quote}\n') self.insert_none_breaking_blanks = 0 self.literal_block = 0 # obey end: self.body.append('}\n') diff --git a/test/functional/expected/standalone_rst_latex.tex b/test/functional/expected/standalone_rst_latex.tex index 159ffd03f..eed860f05 100644 --- a/test/functional/expected/standalone_rst_latex.tex +++ b/test/functional/expected/standalone_rst_latex.tex @@ -536,19 +536,19 @@ description. Literal blocks are indicated with a double-colon (``::'') at the end of the preceding paragraph (over there \texttt{-->}). They can be indented: -\begin{ttfamily}\begin{flushleft} +\begin{quote}{\ttfamily \raggedright \noindent if~literal{\underline{~}}block:~\\ ~~~~text~=~'is~left~as-is'~\\ ~~~~spaces{\underline{~}}and{\underline{~}}linebreaks~=~'are~preserved'~\\ ~~~~markup{\underline{~}}processing~=~None -\end{flushleft}\end{ttfamily} +}\end{quote} Or they can be quoted without indentation: -\begin{ttfamily}\begin{flushleft} +\begin{quote}{\ttfamily \raggedright \noindent >>~Great~idea!~\\ >~\\ >~Why~didn't~I~think~of~that? -\end{flushleft}\end{ttfamily} +}\end{quote} %___________________________________________________________________________ diff --git a/test/test_writers/test_latex2e.py b/test/test_writers/test_latex2e.py index 4fa2472ed..924ad9bfd 100644 --- a/test/test_writers/test_latex2e.py +++ b/test/test_writers/test_latex2e.py @@ -253,14 +253,14 @@ Expecting ``en'' here. Inside literal blocks quotes should be left untouched (use only two quotes in test code makes life easier for the python interpreter running the test): -\\begin{ttfamily}\\begin{flushleft} +\\begin{quote}{\\ttfamily \\raggedright \\noindent ""~\\\\ This~is~left~"untouched"~also~*this*.~\\\\ "" -\\end{flushleft}\\end{ttfamily} -\\begin{ttfamily}\\begin{flushleft} +}\\end{quote} +\\begin{quote}{\\ttfamily \\raggedright \\noindent should~get~"quotes"~and~\\emph{italics}. -\\end{flushleft}\\end{ttfamily} +}\\end{quote} Inline \\texttt{literal "quotes"} should be kept. @@ -325,13 +325,13 @@ latex_head + """\ \\setlength{\\locallinewidth}{\\linewidth} -\\begin{ttfamily}\\begin{flushleft} +\\begin{quote}{\\ttfamily \\raggedright \\noindent something~before~to~get~a~end~of~line.~\\\\ {[}~\\\\ ~\\\\ the~empty~line~gets~tested~too~\\\\ ] -\\end{flushleft}\\end{ttfamily} +}\\end{quote} \\end{document} """], -- 2.11.4.GIT