git.iko.soy/typeable/pandoc
on master help sign in
Improved spacing around LaTeX block environments.

verbatim, itemize, description, enumerate.

commit9961dc274ac29698f68bb7ac47d0259df93563e4 authorJohn MacFarlane <fiddlosopher@gmail.com> dateMon 30 Apr 2012, 09:26 (14 years ago) parent8201257
4 files changed+55−8
src/Text/Pandoc/Writers/LaTeX.hs+11−5 tests/lhs-test.latex+1 tests/lhs-test.latex+lhs+1 tests/writer.latex+42−3
src/Text/Pandoc/Writers/LaTeX.hs+11−5
@@ -298,7 +298,11 @@ blockToLaTeX (CodeBlock (_,classes,keyvalAttr) str) = do
298298 return "Verbatim"
299299 else return "verbatim"
300300 return $ flush (text ("\\begin{" ++ env ++ "}") $$ text str $$
301− text ("\\end{" ++ env ++ "}")) $$ cr -- final cr because of notes
301+ text ("\\end{" ++ env ++ "}")) <> text "\n" <> blankline
302+ -- note: we use 'text "\n"' instead of cr to make this
303+ -- resistant to the 'chomp' in footnotes; a footnote
304+ -- ending with a Verbatim environment must have a
305+ -- cr before the closing }
302306 listingsCodeBlock = do
303307 st <- get
304308 let params = if writerListings (stOptions st)
@@ -339,7 +343,8 @@ blockToLaTeX (BulletList lst) = do
339343 incremental <- gets stIncremental
340344 let inc = if incremental then "[<+->]" else ""
341345 items <- mapM listItemToLaTeX lst
342− return $ text ("\\begin{itemize}" ++ inc) $$ vcat items $$ "\\end{itemize}"
346+ return $ text ("\\begin{itemize}" ++ inc) $$ chomp (vcat items) $$
347+ "\\end{itemize}" <> blankline
343348blockToLaTeX (OrderedList (start, numstyle, numdelim) lst) = do
344349 st <- get
345350 let inc = if stIncremental st then "[<+->]" else ""
@@ -360,12 +365,13 @@ blockToLaTeX (OrderedList (start, numstyle, numdelim) lst) = do
360365 "}{" ++ show (start - 1) ++ "}"
361366 else empty
362367 return $ text ("\\begin{enumerate}" ++ inc) <> exemplar $$ resetcounter $$
363− vcat items $$ "\\end{enumerate}"
368+ chomp (vcat items) $$ "\\end{enumerate}" <> blankline
364369blockToLaTeX (DefinitionList lst) = do
365370 incremental <- gets stIncremental
366371 let inc = if incremental then "[<+->]" else ""
367372 items <- mapM defListItemToLaTeX lst
368− return $ text ("\\begin{description}" ++ inc) $$ vcat items $$ "\\end{description}"
373+ return $ text ("\\begin{description}" ++ inc) $$ chomp (vcat items) $$
374+ "\\end{description}" <> blankline
369375blockToLaTeX HorizontalRule = return $
370376 "\\begin{center}\\rule{3in}{0.4pt}\\end{center}" $$ blankline
371377blockToLaTeX (Header level lst) = sectionHeader "" level lst
@@ -595,7 +601,7 @@ inlineToLaTeX (Note contents) = do
595601 let marker = cycle ['a'..'z'] !! length curnotes
596602 modify $ \s -> s{ stTableNotes = (marker, contents') : curnotes }
597603 return $ "\\tmark" <> brackets (char marker) <> space
598− else return $ "\\footnote" <> braces (nest 2 contents')
604+ else return $ "\\footnote" <> braces (chomp $ nest 2 contents')
599605 -- note: a \n before } needed when note ends with a Verbatim environment
600606
601607citationsToNatbib :: [Citation] -> State WriterState Doc
tests/lhs-test.latex+1
@@ -82,6 +82,7 @@ the second item of the pair).
8282\begin{verbatim}
8383f *** g = first f >>> second g
8484\end{verbatim}
85+
8586Block quote:
8687
8788\begin{quote}
tests/lhs-test.latex+lhs+1
@@ -62,6 +62,7 @@ the second item of the pair).
6262\begin{verbatim}
6363f *** g = first f >>> second g
6464\end{verbatim}
65+
6566Block quote:
6667
6768\begin{quote}
tests/writer.latex+42−3
@@ -129,6 +129,7 @@ sub status {
129129 print "working";
130130}
131131\end{verbatim}
132+
132133A list:
133134
134135\begin{enumerate}[1.]
@@ -137,6 +138,7 @@ A list:
137138\item
138139 item two
139140\end{enumerate}
141+
140142Nested block quotes:
141143
142144\begin{quote}
@@ -167,6 +169,7 @@ sub status {
167169
168170this code block is indented by one tab
169171\end{verbatim}
172+
170173And:
171174
172175\begin{verbatim}
@@ -174,6 +177,7 @@ And:
174177
175178These should not be escaped: \$ \\ \> \[ \{
176179\end{verbatim}
180+
177181\begin{center}\rule{3in}{0.4pt}\end{center}
178182
179183\section{Lists}
@@ -190,6 +194,7 @@ Asterisks tight:
190194\item
191195 asterisk 3
192196\end{itemize}
197+
193198Asterisks loose:
194199
195200\begin{itemize}
@@ -200,6 +205,7 @@ Asterisks loose:
200205\item
201206 asterisk 3
202207\end{itemize}
208+
203209Pluses tight:
204210
205211\begin{itemize}
@@ -210,6 +216,7 @@ Pluses tight:
210216\item
211217 Plus 3
212218\end{itemize}
219+
213220Pluses loose:
214221
215222\begin{itemize}
@@ -220,6 +227,7 @@ Pluses loose:
220227\item
221228 Plus 3
222229\end{itemize}
230+
223231Minuses tight:
224232
225233\begin{itemize}
@@ -230,6 +238,7 @@ Minuses tight:
230238\item
231239 Minus 3
232240\end{itemize}
241+
233242Minuses loose:
234243
235244\begin{itemize}
@@ -240,6 +249,7 @@ Minuses loose:
240249\item
241250 Minus 3
242251\end{itemize}
252+
243253\subsection{Ordered}
244254
245255Tight:
@@ -252,6 +262,7 @@ Tight:
252262\item
253263 Third
254264\end{enumerate}
265+
255266and:
256267
257268\begin{enumerate}[1.]
@@ -262,6 +273,7 @@ and:
262273\item
263274 Three
264275\end{enumerate}
276+
265277Loose using tabs:
266278
267279\begin{enumerate}[1.]
@@ -272,6 +284,7 @@ Loose using tabs:
272284\item
273285 Third
274286\end{enumerate}
287+
275288and using spaces:
276289
277290\begin{enumerate}[1.]
@@ -282,6 +295,7 @@ and using spaces:
282295\item
283296 Three
284297\end{enumerate}
298+
285299Multiple paragraphs:
286300
287301\begin{enumerate}[1.]
@@ -294,6 +308,7 @@ Multiple paragraphs:
294308\item
295309 Item 3.
296310\end{enumerate}
311+
297312\subsection{Nested}
298313
299314\begin{itemize}
@@ -308,6 +323,7 @@ Multiple paragraphs:
308323 \end{itemize}
309324 \end{itemize}
310325\end{itemize}
326+
311327Here's another:
312328
313329\begin{enumerate}[1.]
@@ -326,6 +342,7 @@ Here's another:
326342\item
327343 Third
328344\end{enumerate}
345+
329346Same thing but with paragraphs:
330347
331348\begin{enumerate}[1.]
@@ -345,6 +362,7 @@ Same thing but with paragraphs:
345362\item
346363 Third
347364\end{enumerate}
365+
348366\subsection{Tabs and spaces}
349367
350368\begin{itemize}
@@ -360,6 +378,7 @@ Same thing but with paragraphs:
360378 this is an example list item indented with spaces
361379 \end{itemize}
362380\end{itemize}
381+
363382\subsection{Fancy list markers}
364383
365384\begin{enumerate}[(1)]
@@ -385,6 +404,7 @@ Same thing but with paragraphs:
385404 \end{enumerate}
386405 \end{enumerate}
387406\end{enumerate}
407+
388408Nesting:
389409
390410\begin{enumerate}[A.]
@@ -405,6 +425,7 @@ Nesting:
405425 \end{enumerate}
406426 \end{enumerate}
407427\end{enumerate}
428+
408429Autonumbering:
409430
410431\begin{enumerate}
@@ -417,6 +438,7 @@ Autonumbering:
417438 Nested.
418439 \end{enumerate}
419440\end{enumerate}
441+
420442Should not be a list item:
421443
422444M.A.~2007
@@ -437,6 +459,7 @@ orange fruit
437459\item[banana]
438460yellow fruit
439461\end{description}
462+
440463Tight using tabs:
441464
442465\begin{description}
@@ -447,6 +470,7 @@ orange fruit
447470\item[banana]
448471yellow fruit
449472\end{description}
473+
450474Loose:
451475
452476\begin{description}
@@ -458,8 +482,8 @@ orange fruit
458482
459483\item[banana]
460484yellow fruit
461−
462485\end{description}
486+
463487Multiple blocks with italics:
464488
465489\begin{description}
@@ -474,11 +498,12 @@ orange fruit
474498\begin{verbatim}
475499{ orange code block }
476500\end{verbatim}
501+
477502\begin{quote}
478503orange block quote
479504\end{quote}
480−
481505\end{description}
506+
482507Multiple definitions, tight:
483508
484509\begin{description}
@@ -491,6 +516,7 @@ orange fruit
491516
492517bank
493518\end{description}
519+
494520Multiple definitions, loose:
495521
496522\begin{description}
@@ -503,8 +529,8 @@ computer
503529orange fruit
504530
505531bank
506−
507532\end{description}
533+
508534Blank line after term, indented marker, alternate markers:
509535
510536\begin{description}
@@ -523,6 +549,7 @@ orange fruit
523549 sublist
524550\end{enumerate}
525551\end{description}
552+
526553\section{HTML Blocks}
527554
528555Simple block on one line:
@@ -546,11 +573,13 @@ This should be a code block, though:
546573 foo
547574</div>
548575\end{verbatim}
576+
549577As should this:
550578
551579\begin{verbatim}
552580<div>foo</div>
553581\end{verbatim}
582+
554583Now, nested:
555584
556585foo
@@ -563,6 +592,7 @@ Code block:
563592\begin{verbatim}
564593<!-- Comment -->
565594\end{verbatim}
595+
566596Just plain comment, with trailing spaces on the line:
567597
568598Code:
@@ -570,6 +600,7 @@ Code:
570600\begin{verbatim}
571601<hr />
572602\end{verbatim}
603+
573604Hr's:
574605
575606\begin{center}\rule{3in}{0.4pt}\end{center}
@@ -648,6 +679,7 @@ Ellipses\ldots{}and\ldots{}and\ldots{}.
648679\item
649680 Here's one that has a line break in it: $\alpha + \omega \times x^2$.
650681\end{itemize}
682+
651683These shouldn't be math:
652684
653685\begin{itemize}
@@ -661,6 +693,7 @@ These shouldn't be math:
661693\item
662694 Escaped \texttt{\$}: \$73 \emph{this should be emphasized} 23\$.
663695\end{itemize}
696+
664697Here's a LaTeX table:
665698
666699\begin{tabular}{|l|l|}\hline
@@ -687,6 +720,7 @@ Here is some unicode:
687720\item
688721 copyright: ©
689722\end{itemize}
723+
690724AT\&T has an ampersand in their name.
691725
692726AT\&T is another way to write it.
@@ -776,6 +810,7 @@ This should {[}not{]}{[}{]} be a link.
776810\begin{verbatim}
777811[not]: /url
778812\end{verbatim}
813+
779814Foo \href{/url/}{bar}.
780815
781816Foo \href{/url/}{biz}.
@@ -804,6 +839,7 @@ With an ampersand: \url{http://example.com/?foo=1&bar=2}
804839\item
805840 It should.
806841\end{itemize}
842+
807843An e-mail address:
808844\href{mailto:nobody@nowhere.net}{\texttt{nobody@nowhere.net}}
809845
@@ -817,6 +853,7 @@ Auto-links should not occur here:
817853\begin{verbatim}
818854or here: <http://example.com/>
819855\end{verbatim}
856+
820857\begin{center}\rule{3in}{0.4pt}\end{center}
821858
822859\section{Images}
@@ -846,6 +883,7 @@ Here is a footnote reference,\footnote{Here is the footnote. It can go
846883\begin{Verbatim}
847884 { <code> }
848885\end{Verbatim}
886+
849887 If you want, you can indent every line, but you can also be lazy and just
850888 indent the first line of each block.} This should \emph{not} be a footnote
851889reference, because it contains a space.{[}\^{}my note{]} Here is an inline
@@ -861,6 +899,7 @@ Notes can go in quotes.\footnote{In quote.}
861899\item
862900 And in list items.\footnote{In list.}
863901\end{enumerate}
902+
864903This paragraph should not be part of the note, as it is not indented.
865904
866905\end{document}