Skip to content

Commit

Permalink
Improved spacing around LaTeX block environments.
Browse files Browse the repository at this point in the history
verbatim, itemize, description, enumerate.
  • Loading branch information
jgm committed Apr 30, 2012
1 parent 8201257 commit 9961dc2
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 8 deletions.
16 changes: 11 additions & 5 deletions src/Text/Pandoc/Writers/LaTeX.hs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -298,7 +298,11 @@ blockToLaTeX (CodeBlock (_,classes,keyvalAttr) str) = do
return "Verbatim" return "Verbatim"
else return "verbatim" else return "verbatim"
return $ flush (text ("\\begin{" ++ env ++ "}") $$ text str $$ return $ flush (text ("\\begin{" ++ env ++ "}") $$ text str $$
text ("\\end{" ++ env ++ "}")) $$ cr -- final cr because of notes text ("\\end{" ++ env ++ "}")) <> text "\n" <> blankline
-- note: we use 'text "\n"' instead of cr to make this
-- resistant to the 'chomp' in footnotes; a footnote
-- ending with a Verbatim environment must have a
-- cr before the closing }
listingsCodeBlock = do listingsCodeBlock = do
st <- get st <- get
let params = if writerListings (stOptions st) let params = if writerListings (stOptions st)
Expand Down Expand Up @@ -339,7 +343,8 @@ blockToLaTeX (BulletList lst) = do
incremental <- gets stIncremental incremental <- gets stIncremental
let inc = if incremental then "[<+->]" else "" let inc = if incremental then "[<+->]" else ""
items <- mapM listItemToLaTeX lst items <- mapM listItemToLaTeX lst
return $ text ("\\begin{itemize}" ++ inc) $$ vcat items $$ "\\end{itemize}" return $ text ("\\begin{itemize}" ++ inc) $$ chomp (vcat items) $$
"\\end{itemize}" <> blankline
blockToLaTeX (OrderedList (start, numstyle, numdelim) lst) = do blockToLaTeX (OrderedList (start, numstyle, numdelim) lst) = do
st <- get st <- get
let inc = if stIncremental st then "[<+->]" else "" let inc = if stIncremental st then "[<+->]" else ""
Expand All @@ -360,12 +365,13 @@ blockToLaTeX (OrderedList (start, numstyle, numdelim) lst) = do
"}{" ++ show (start - 1) ++ "}" "}{" ++ show (start - 1) ++ "}"
else empty else empty
return $ text ("\\begin{enumerate}" ++ inc) <> exemplar $$ resetcounter $$ return $ text ("\\begin{enumerate}" ++ inc) <> exemplar $$ resetcounter $$
vcat items $$ "\\end{enumerate}" chomp (vcat items) $$ "\\end{enumerate}" <> blankline
blockToLaTeX (DefinitionList lst) = do blockToLaTeX (DefinitionList lst) = do
incremental <- gets stIncremental incremental <- gets stIncremental
let inc = if incremental then "[<+->]" else "" let inc = if incremental then "[<+->]" else ""
items <- mapM defListItemToLaTeX lst items <- mapM defListItemToLaTeX lst
return $ text ("\\begin{description}" ++ inc) $$ vcat items $$ "\\end{description}" return $ text ("\\begin{description}" ++ inc) $$ chomp (vcat items) $$
"\\end{description}" <> blankline
blockToLaTeX HorizontalRule = return $ blockToLaTeX HorizontalRule = return $
"\\begin{center}\\rule{3in}{0.4pt}\\end{center}" $$ blankline "\\begin{center}\\rule{3in}{0.4pt}\\end{center}" $$ blankline
blockToLaTeX (Header level lst) = sectionHeader "" level lst blockToLaTeX (Header level lst) = sectionHeader "" level lst
Expand Down Expand Up @@ -595,7 +601,7 @@ inlineToLaTeX (Note contents) = do
let marker = cycle ['a'..'z'] !! length curnotes let marker = cycle ['a'..'z'] !! length curnotes
modify $ \s -> s{ stTableNotes = (marker, contents') : curnotes } modify $ \s -> s{ stTableNotes = (marker, contents') : curnotes }
return $ "\\tmark" <> brackets (char marker) <> space return $ "\\tmark" <> brackets (char marker) <> space
else return $ "\\footnote" <> braces (nest 2 contents') else return $ "\\footnote" <> braces (chomp $ nest 2 contents')
-- note: a \n before } needed when note ends with a Verbatim environment -- note: a \n before } needed when note ends with a Verbatim environment


citationsToNatbib :: [Citation] -> State WriterState Doc citationsToNatbib :: [Citation] -> State WriterState Doc
Expand Down
1 change: 1 addition & 0 deletions tests/lhs-test.latex
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ the second item of the pair).
\begin{verbatim} \begin{verbatim}
f *** g = first f >>> second g f *** g = first f >>> second g
\end{verbatim} \end{verbatim}

Block quote: Block quote:


\begin{quote} \begin{quote}
Expand Down
1 change: 1 addition & 0 deletions tests/lhs-test.latex+lhs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ the second item of the pair).
\begin{verbatim} \begin{verbatim}
f *** g = first f >>> second g f *** g = first f >>> second g
\end{verbatim} \end{verbatim}

Block quote: Block quote:


\begin{quote} \begin{quote}
Expand Down
45 changes: 42 additions & 3 deletions tests/writer.latex
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ sub status {
print "working"; print "working";
} }
\end{verbatim} \end{verbatim}

A list: A list:


\begin{enumerate}[1.] \begin{enumerate}[1.]
Expand All @@ -137,6 +138,7 @@ A list:
\item \item
item two item two
\end{enumerate} \end{enumerate}

Nested block quotes: Nested block quotes:


\begin{quote} \begin{quote}
Expand Down Expand Up @@ -167,13 +169,15 @@ sub status {


this code block is indented by one tab this code block is indented by one tab
\end{verbatim} \end{verbatim}

And: And:


\begin{verbatim} \begin{verbatim}
this code block is indented by two tabs this code block is indented by two tabs


These should not be escaped: \$ \\ \> \[ \{ These should not be escaped: \$ \\ \> \[ \{
\end{verbatim} \end{verbatim}

\begin{center}\rule{3in}{0.4pt}\end{center} \begin{center}\rule{3in}{0.4pt}\end{center}


\section{Lists} \section{Lists}
Expand All @@ -190,6 +194,7 @@ Asterisks tight:
\item \item
asterisk 3 asterisk 3
\end{itemize} \end{itemize}

Asterisks loose: Asterisks loose:


\begin{itemize} \begin{itemize}
Expand All @@ -200,6 +205,7 @@ Asterisks loose:
\item \item
asterisk 3 asterisk 3
\end{itemize} \end{itemize}

Pluses tight: Pluses tight:


\begin{itemize} \begin{itemize}
Expand All @@ -210,6 +216,7 @@ Pluses tight:
\item \item
Plus 3 Plus 3
\end{itemize} \end{itemize}

Pluses loose: Pluses loose:


\begin{itemize} \begin{itemize}
Expand All @@ -220,6 +227,7 @@ Pluses loose:
\item \item
Plus 3 Plus 3
\end{itemize} \end{itemize}

Minuses tight: Minuses tight:


\begin{itemize} \begin{itemize}
Expand All @@ -230,6 +238,7 @@ Minuses tight:
\item \item
Minus 3 Minus 3
\end{itemize} \end{itemize}

Minuses loose: Minuses loose:


\begin{itemize} \begin{itemize}
Expand All @@ -240,6 +249,7 @@ Minuses loose:
\item \item
Minus 3 Minus 3
\end{itemize} \end{itemize}

\subsection{Ordered} \subsection{Ordered}


Tight: Tight:
Expand All @@ -252,6 +262,7 @@ Tight:
\item \item
Third Third
\end{enumerate} \end{enumerate}

and: and:


\begin{enumerate}[1.] \begin{enumerate}[1.]
Expand All @@ -262,6 +273,7 @@ and:
\item \item
Three Three
\end{enumerate} \end{enumerate}

Loose using tabs: Loose using tabs:


\begin{enumerate}[1.] \begin{enumerate}[1.]
Expand All @@ -272,6 +284,7 @@ Loose using tabs:
\item \item
Third Third
\end{enumerate} \end{enumerate}

and using spaces: and using spaces:


\begin{enumerate}[1.] \begin{enumerate}[1.]
Expand All @@ -282,6 +295,7 @@ and using spaces:
\item \item
Three Three
\end{enumerate} \end{enumerate}

Multiple paragraphs: Multiple paragraphs:


\begin{enumerate}[1.] \begin{enumerate}[1.]
Expand All @@ -294,6 +308,7 @@ Multiple paragraphs:
\item \item
Item 3. Item 3.
\end{enumerate} \end{enumerate}

\subsection{Nested} \subsection{Nested}


\begin{itemize} \begin{itemize}
Expand All @@ -308,6 +323,7 @@ Multiple paragraphs:
\end{itemize} \end{itemize}
\end{itemize} \end{itemize}
\end{itemize} \end{itemize}

Here's another: Here's another:


\begin{enumerate}[1.] \begin{enumerate}[1.]
Expand All @@ -326,6 +342,7 @@ Here's another:
\item \item
Third Third
\end{enumerate} \end{enumerate}

Same thing but with paragraphs: Same thing but with paragraphs:


\begin{enumerate}[1.] \begin{enumerate}[1.]
Expand All @@ -345,6 +362,7 @@ Same thing but with paragraphs:
\item \item
Third Third
\end{enumerate} \end{enumerate}

\subsection{Tabs and spaces} \subsection{Tabs and spaces}


\begin{itemize} \begin{itemize}
Expand All @@ -360,6 +378,7 @@ Same thing but with paragraphs:
this is an example list item indented with spaces this is an example list item indented with spaces
\end{itemize} \end{itemize}
\end{itemize} \end{itemize}

\subsection{Fancy list markers} \subsection{Fancy list markers}


\begin{enumerate}[(1)] \begin{enumerate}[(1)]
Expand All @@ -385,6 +404,7 @@ Same thing but with paragraphs:
\end{enumerate} \end{enumerate}
\end{enumerate} \end{enumerate}
\end{enumerate} \end{enumerate}

Nesting: Nesting:


\begin{enumerate}[A.] \begin{enumerate}[A.]
Expand All @@ -405,6 +425,7 @@ Nesting:
\end{enumerate} \end{enumerate}
\end{enumerate} \end{enumerate}
\end{enumerate} \end{enumerate}

Autonumbering: Autonumbering:


\begin{enumerate} \begin{enumerate}
Expand All @@ -417,6 +438,7 @@ Autonumbering:
Nested. Nested.
\end{enumerate} \end{enumerate}
\end{enumerate} \end{enumerate}

Should not be a list item: Should not be a list item:


M.A.~2007 M.A.~2007
Expand All @@ -437,6 +459,7 @@ orange fruit
\item[banana] \item[banana]
yellow fruit yellow fruit
\end{description} \end{description}

Tight using tabs: Tight using tabs:


\begin{description} \begin{description}
Expand All @@ -447,6 +470,7 @@ orange fruit
\item[banana] \item[banana]
yellow fruit yellow fruit
\end{description} \end{description}

Loose: Loose:


\begin{description} \begin{description}
Expand All @@ -458,8 +482,8 @@ orange fruit


\item[banana] \item[banana]
yellow fruit yellow fruit

\end{description} \end{description}

Multiple blocks with italics: Multiple blocks with italics:


\begin{description} \begin{description}
Expand All @@ -474,11 +498,12 @@ orange fruit
\begin{verbatim} \begin{verbatim}
{ orange code block } { orange code block }
\end{verbatim} \end{verbatim}

\begin{quote} \begin{quote}
orange block quote orange block quote
\end{quote} \end{quote}

\end{description} \end{description}

Multiple definitions, tight: Multiple definitions, tight:


\begin{description} \begin{description}
Expand All @@ -491,6 +516,7 @@ orange fruit


bank bank
\end{description} \end{description}

Multiple definitions, loose: Multiple definitions, loose:


\begin{description} \begin{description}
Expand All @@ -503,8 +529,8 @@ computer
orange fruit orange fruit


bank bank

\end{description} \end{description}

Blank line after term, indented marker, alternate markers: Blank line after term, indented marker, alternate markers:


\begin{description} \begin{description}
Expand All @@ -523,6 +549,7 @@ orange fruit
sublist sublist
\end{enumerate} \end{enumerate}
\end{description} \end{description}

\section{HTML Blocks} \section{HTML Blocks}


Simple block on one line: Simple block on one line:
Expand All @@ -546,11 +573,13 @@ This should be a code block, though:
foo foo
</div> </div>
\end{verbatim} \end{verbatim}

As should this: As should this:


\begin{verbatim} \begin{verbatim}
<div>foo</div> <div>foo</div>
\end{verbatim} \end{verbatim}

Now, nested: Now, nested:


foo foo
Expand All @@ -563,13 +592,15 @@ Code block:
\begin{verbatim} \begin{verbatim}
<!-- Comment --> <!-- Comment -->
\end{verbatim} \end{verbatim}

Just plain comment, with trailing spaces on the line: Just plain comment, with trailing spaces on the line:


Code: Code:


\begin{verbatim} \begin{verbatim}
<hr /> <hr />
\end{verbatim} \end{verbatim}

Hr's: Hr's:


\begin{center}\rule{3in}{0.4pt}\end{center} \begin{center}\rule{3in}{0.4pt}\end{center}
Expand Down Expand Up @@ -648,6 +679,7 @@ Ellipses\ldots{}and\ldots{}and\ldots{}.
\item \item
Here's one that has a line break in it: $\alpha + \omega \times x^2$. Here's one that has a line break in it: $\alpha + \omega \times x^2$.
\end{itemize} \end{itemize}

These shouldn't be math: These shouldn't be math:


\begin{itemize} \begin{itemize}
Expand All @@ -661,6 +693,7 @@ These shouldn't be math:
\item \item
Escaped \texttt{\$}: \$73 \emph{this should be emphasized} 23\$. Escaped \texttt{\$}: \$73 \emph{this should be emphasized} 23\$.
\end{itemize} \end{itemize}

Here's a LaTeX table: Here's a LaTeX table:


\begin{tabular}{|l|l|}\hline \begin{tabular}{|l|l|}\hline
Expand All @@ -687,6 +720,7 @@ Here is some unicode:
\item \item
copyright: © copyright: ©
\end{itemize} \end{itemize}

AT\&T has an ampersand in their name. AT\&T has an ampersand in their name.


AT\&T is another way to write it. AT\&T is another way to write it.
Expand Down Expand Up @@ -776,6 +810,7 @@ This should {[}not{]}{[}{]} be a link.
\begin{verbatim} \begin{verbatim}
[not]: /url [not]: /url
\end{verbatim} \end{verbatim}

Foo \href{/url/}{bar}. Foo \href{/url/}{bar}.


Foo \href{/url/}{biz}. Foo \href{/url/}{biz}.
Expand Down Expand Up @@ -804,6 +839,7 @@ With an ampersand: \url{http://example.com/?foo=1&bar=2}
\item \item
It should. It should.
\end{itemize} \end{itemize}

An e-mail address: An e-mail address:
\href{mailto:nobody@nowhere.net}{\texttt{nobody@nowhere.net}} \href{mailto:nobody@nowhere.net}{\texttt{nobody@nowhere.net}}


Expand All @@ -817,6 +853,7 @@ Auto-links should not occur here:
\begin{verbatim} \begin{verbatim}
or here: <http://example.com/> or here: <http://example.com/>
\end{verbatim} \end{verbatim}

\begin{center}\rule{3in}{0.4pt}\end{center} \begin{center}\rule{3in}{0.4pt}\end{center}


\section{Images} \section{Images}
Expand Down Expand Up @@ -846,6 +883,7 @@ Here is a footnote reference,\footnote{Here is the footnote. It can go
\begin{Verbatim} \begin{Verbatim}
{ <code> } { <code> }
\end{Verbatim} \end{Verbatim}

If you want, you can indent every line, but you can also be lazy and just If you want, you can indent every line, but you can also be lazy and just
indent the first line of each block.} This should \emph{not} be a footnote indent the first line of each block.} This should \emph{not} be a footnote
reference, because it contains a space.{[}\^{}my note{]} Here is an inline reference, because it contains a space.{[}\^{}my note{]} Here is an inline
Expand All @@ -861,6 +899,7 @@ Notes can go in quotes.\footnote{In quote.}
\item \item
And in list items.\footnote{In list.} And in list items.\footnote{In list.}
\end{enumerate} \end{enumerate}

This paragraph should not be part of the note, as it is not indented. This paragraph should not be part of the note, as it is not indented.


\end{document} \end{document}

0 comments on commit 9961dc2

Please sign in to comment.