git.iko.soy/typeable/pandoc
on master help sign in
LaTeX writer: Use a declaration for tight lists

Currently, pandoc has hard-coded the following in order to make tight lists in LaTeX: ```hs text "\\itemsep1pt\\parskip0pt\\parsep0pt" ``` Which is fine, but does not allow customizations. For example, the `memoir` class already has a `\tightlist` declaration for this purpose: ```tex \newcommand{\tightlist}{% \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}} ``` I'm proposing to use a similar solution: ```diff @@ In Writers/LaTeX.hs: -then text "\\itemsep1pt\\parskip0pt\\parsep0pt" +then text "\\tightlist" @@ In templates/default.latex: +\newcommand{\tightlist}{% + \setlength{\itemsep}{1pt}\setlength{\parskip}{0pt}\setlength{\parsep}{0pt}} ``` This allows us to customize the tightness to our needs. Backward Compatibility If a person is using a custom LaTeX template (not based upon the `memoir` class), the `\tightlist` declaration must be added.

commit9557eb6f8efafaff2e3a61e43e4cc7e4717ad9eb authorJose Luis Duran <jlduran@users.noreply.github.com> dateWed 27 Aug 2014, 20:35 (12 years ago) parent3533218
6 files changed+40−34
data/templates+1−1 src/Text/Pandoc/Writers/LaTeX.hs+3−3 tests/Tests/Writers/LaTeX.hs+1−1 tests/lhs-test.latex+2 tests/lhs-test.latex+lhs+2 tests/writer.latex+31−29
data/templates+1−1

Submodule changed.

src/Text/Pandoc/Writers/LaTeX.hs+3−3
@@ -411,7 +411,7 @@ blockToLaTeX (BulletList lst) = do
411411 let inc = if incremental then "[<+->]" else ""
412412 items <- mapM listItemToLaTeX lst
413413 let spacing = if isTightList lst
414− then text "\\itemsep1pt\\parskip0pt\\parsep0pt"
414+ then text "\\tightlist"
415415 else empty
416416 return $ text ("\\begin{itemize}" ++ inc) $$ spacing $$ vcat items $$
417417 "\\end{itemize}"
@@ -446,7 +446,7 @@ blockToLaTeX (OrderedList (start, numstyle, numdelim) lst) = do
446446 else "\\setcounter" <> braces enum <>
447447 braces (text $ show $ start - 1)
448448 let spacing = if isTightList lst
449− then text "\\itemsep1pt\\parskip0pt\\parsep0pt"
449+ then text "\\tightlist"
450450 else empty
451451 return $ text ("\\begin{enumerate}" ++ inc)
452452 $$ stylecommand
@@ -460,7 +460,7 @@ blockToLaTeX (DefinitionList lst) = do
460460 let inc = if incremental then "[<+->]" else ""
461461 items <- mapM defListItemToLaTeX lst
462462 let spacing = if all isTightList (map snd lst)
463− then text "\\itemsep1pt\\parskip0pt\\parsep0pt"
463+ then text "\\tightlist"
464464 else empty
465465 return $ text ("\\begin{description}" ++ inc) $$ spacing $$ vcat items $$
466466 "\\end{description}"
tests/Tests/Writers/LaTeX.hs+1−1
@@ -42,7 +42,7 @@ tests = [ testGroup "code blocks"
4242 , testGroup "definition lists"
4343 [ "with internal link" =: definitionList [(link "#go" "" (str "testing"),
4444 [plain (text "hi there")])] =?>
45− "\\begin{description}\n\\itemsep1pt\\parskip0pt\\parsep0pt\n\\item[{\\hyperref[go]{testing}}]\nhi there\n\\end{description}"
45+ "\\begin{description}\n\\tightlist\n\\item[{\\hyperref[go]{testing}}]\nhi there\n\\end{description}"
4646 ]
4747 , testGroup "math"
4848 [ "escape |" =: para (math "\\sigma|_{\\{x\\}}") =?>
tests/lhs-test.latex+2
@@ -64,6 +64,8 @@
6464\setlength{\parindent}{0pt}
6565\setlength{\parskip}{6pt plus 2pt minus 1pt}
6666\setlength{\emergencystretch}{3em} % prevent overfull lines
67+\newcommand{\tightlist}{%
68+ \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
6769\setcounter{secnumdepth}{0}
6870
6971\date{}
tests/lhs-test.latex+lhs+2
@@ -45,6 +45,8 @@
4545\setlength{\parindent}{0pt}
4646\setlength{\parskip}{6pt plus 2pt minus 1pt}
4747\setlength{\emergencystretch}{3em} % prevent overfull lines
48+\newcommand{\tightlist}{%
49+ \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
4850\setcounter{secnumdepth}{0}
4951
5052\date{}
tests/writer.latex+31−29
@@ -56,6 +56,8 @@
5656\setlength{\parindent}{0pt}
5757\setlength{\parskip}{6pt plus 2pt minus 1pt}
5858\setlength{\emergencystretch}{3em} % prevent overfull lines
59+\newcommand{\tightlist}{%
60+ \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
5961\setcounter{secnumdepth}{0}
6062\VerbatimFootnotes % allows verbatim text in footnotes
6163
@@ -131,7 +133,7 @@ A list:
131133
132134\begin{enumerate}
133135\def\labelenumi{\arabic{enumi}.}
134−\itemsep1pt\parskip0pt\parsep0pt
136+\tightlist
135137\item
136138 item one
137139\item
@@ -186,7 +188,7 @@ These should not be escaped: \$ \\ \> \[ \{
186188Asterisks tight:
187189
188190\begin{itemize}
189−\itemsep1pt\parskip0pt\parsep0pt
191+\tightlist
190192\item
191193 asterisk 1
192194\item
@@ -209,7 +211,7 @@ Asterisks loose:
209211Pluses tight:
210212
211213\begin{itemize}
212−\itemsep1pt\parskip0pt\parsep0pt
214+\tightlist
213215\item
214216 Plus 1
215217\item
@@ -232,7 +234,7 @@ Pluses loose:
232234Minuses tight:
233235
234236\begin{itemize}
235−\itemsep1pt\parskip0pt\parsep0pt
237+\tightlist
236238\item
237239 Minus 1
238240\item
@@ -258,7 +260,7 @@ Tight:
258260
259261\begin{enumerate}
260262\def\labelenumi{\arabic{enumi}.}
261−\itemsep1pt\parskip0pt\parsep0pt
263+\tightlist
262264\item
263265 First
264266\item
@@ -271,7 +273,7 @@ and:
271273
272274\begin{enumerate}
273275\def\labelenumi{\arabic{enumi}.}
274−\itemsep1pt\parskip0pt\parsep0pt
276+\tightlist
275277\item
276278 One
277279\item
@@ -321,17 +323,17 @@ Multiple paragraphs:
321323\subsection{Nested}\label{nested}
322324
323325\begin{itemize}
324−\itemsep1pt\parskip0pt\parsep0pt
326+\tightlist
325327\item
326328 Tab
327329
328330 \begin{itemize}
329− \itemsep1pt\parskip0pt\parsep0pt
331+ \tightlist
330332 \item
331333 Tab
332334
333335 \begin{itemize}
334− \itemsep1pt\parskip0pt\parsep0pt
336+ \tightlist
335337 \item
336338 Tab
337339 \end{itemize}
@@ -342,14 +344,14 @@ Here's another:
342344
343345\begin{enumerate}
344346\def\labelenumi{\arabic{enumi}.}
345−\itemsep1pt\parskip0pt\parsep0pt
347+\tightlist
346348\item
347349 First
348350\item
349351 Second:
350352
351353 \begin{itemize}
352− \itemsep1pt\parskip0pt\parsep0pt
354+ \tightlist
353355 \item
354356 Fee
355357 \item
@@ -371,7 +373,7 @@ Same thing but with paragraphs:
371373 Second:
372374
373375 \begin{itemize}
374− \itemsep1pt\parskip0pt\parsep0pt
376+ \tightlist
375377 \item
376378 Fee
377379 \item
@@ -414,7 +416,7 @@ Same thing but with paragraphs:
414416 \begin{enumerate}
415417 \def\labelenumii{\roman{enumii}.}
416418 \setcounter{enumii}{3}
417− \itemsep1pt\parskip0pt\parsep0pt
419+ \tightlist
418420 \item
419421 sublist with roman numerals, starting with 4
420422 \item
@@ -422,7 +424,7 @@ Same thing but with paragraphs:
422424
423425 \begin{enumerate}
424426 \def\labelenumiii{(\Alph{enumiii})}
425− \itemsep1pt\parskip0pt\parsep0pt
427+ \tightlist
426428 \item
427429 a subsublist
428430 \item
@@ -435,27 +437,27 @@ Nesting:
435437
436438\begin{enumerate}
437439\def\labelenumi{\Alph{enumi}.}
438−\itemsep1pt\parskip0pt\parsep0pt
440+\tightlist
439441\item
440442 Upper Alpha
441443
442444 \begin{enumerate}
443445 \def\labelenumii{\Roman{enumii}.}
444− \itemsep1pt\parskip0pt\parsep0pt
446+ \tightlist
445447 \item
446448 Upper Roman.
447449
448450 \begin{enumerate}
449451 \def\labelenumiii{(\arabic{enumiii})}
450452 \setcounter{enumiii}{5}
451− \itemsep1pt\parskip0pt\parsep0pt
453+ \tightlist
452454 \item
453455 Decimal start with 6
454456
455457 \begin{enumerate}
456458 \def\labelenumiv{\alph{enumiv})}
457459 \setcounter{enumiv}{2}
458− \itemsep1pt\parskip0pt\parsep0pt
460+ \tightlist
459461 \item
460462 Lower alpha with paren
461463 \end{enumerate}
@@ -466,14 +468,14 @@ Nesting:
466468Autonumbering:
467469
468470\begin{enumerate}
469−\itemsep1pt\parskip0pt\parsep0pt
471+\tightlist
470472\item
471473 Autonumber.
472474\item
473475 More.
474476
475477 \begin{enumerate}
476− \itemsep1pt\parskip0pt\parsep0pt
478+ \tightlist
477479 \item
478480 Nested.
479481 \end{enumerate}
@@ -492,7 +494,7 @@ B. Williams
492494Tight using spaces:
493495
494496\begin{description}
495−\itemsep1pt\parskip0pt\parsep0pt
497+\tightlist
496498\item[apple]
497499red fruit
498500\item[orange]
@@ -504,7 +506,7 @@ yellow fruit
504506Tight using tabs:
505507
506508\begin{description}
507−\itemsep1pt\parskip0pt\parsep0pt
509+\tightlist
508510\item[apple]
509511red fruit
510512\item[orange]
@@ -546,7 +548,7 @@ orange block quote
546548Multiple definitions, tight:
547549
548550\begin{description}
549−\itemsep1pt\parskip0pt\parsep0pt
551+\tightlist
550552\item[apple]
551553red fruit
552554
@@ -582,7 +584,7 @@ orange fruit
582584
583585\begin{enumerate}
584586\def\labelenumi{\arabic{enumi}.}
585−\itemsep1pt\parskip0pt\parsep0pt
587+\tightlist
586588\item
587589 sublist
588590\item
@@ -708,7 +710,7 @@ Ellipses\ldots{}and\ldots{}and\ldots{}.
708710\section{LaTeX}\label{latex}
709711
710712\begin{itemize}
711−\itemsep1pt\parskip0pt\parsep0pt
713+\tightlist
712714\item
713715 \cite[22-23]{smith.1899}
714716\item
@@ -731,7 +733,7 @@ Ellipses\ldots{}and\ldots{}and\ldots{}.
731733These shouldn't be math:
732734
733735\begin{itemize}
734−\itemsep1pt\parskip0pt\parsep0pt
736+\tightlist
735737\item
736738 To get the famous equation, write \texttt{\$e = mc\^{}2\$}.
737739\item
@@ -758,7 +760,7 @@ Cat & 1 \\ \hline
758760Here is some unicode:
759761
760762\begin{itemize}
761−\itemsep1pt\parskip0pt\parsep0pt
763+\tightlist
762764\item
763765 I hat: Î
764766\item
@@ -882,7 +884,7 @@ Here's an \href{/script?foo=1\&bar=2}{inline link in pointy braces}.
882884With an ampersand: \url{http://example.com/?foo=1\&bar=2}
883885
884886\begin{itemize}
885−\itemsep1pt\parskip0pt\parsep0pt
887+\tightlist
886888\item
887889 In a list?
888890\item
@@ -948,7 +950,7 @@ Notes can go in quotes.\footnote{In quote.}
948950
949951\begin{enumerate}
950952\def\labelenumi{\arabic{enumi}.}
951−\itemsep1pt\parskip0pt\parsep0pt
953+\tightlist
952954\item
953955 And in list items.\footnote{In list.}
954956\end{enumerate}