git.iko.soy/typeable/pandoc
on master help sign in
LaTeX writer: Don't rely on the enumerate package.
e1be934John MacFarlane
src/Text/Pandoc/Writers/LaTeX.hs+27−17
@@ -53,7 +53,6 @@ data WriterState =
53 , stOLLevel :: Int -- level of ordered list nesting
53 , stOLLevel :: Int -- level of ordered list nesting
54 , stOptions :: WriterOptions -- writer options, so they don't have to be parameter
54 , stOptions :: WriterOptions -- writer options, so they don't have to be parameter
55 , stVerbInNote :: Bool -- true if document has verbatim text in note
55 , stVerbInNote :: Bool -- true if document has verbatim text in note
56− , stEnumerate :: Bool -- true if document needs fancy enumerated lists
57 , stTable :: Bool -- true if document has a table
56 , stTable :: Bool -- true if document has a table
58 , stStrikeout :: Bool -- true if document has strikeout
57 , stStrikeout :: Bool -- true if document has strikeout
59 , stUrl :: Bool -- true if document has visible URL link
58 , stUrl :: Bool -- true if document has visible URL link
@@ -73,7 +72,7 @@ writeLaTeX options document =
73 evalState (pandocToLaTeX options document) $
72 evalState (pandocToLaTeX options document) $
74 WriterState { stInNote = False, stInTable = False,
73 WriterState { stInNote = False, stInTable = False,
75 stTableNotes = [], stOLLevel = 1, stOptions = options,
74 stTableNotes = [], stOLLevel = 1, stOptions = options,
76− stVerbInNote = False, stEnumerate = False,
75+ stVerbInNote = False,
77 stTable = False, stStrikeout = False,
76 stTable = False, stStrikeout = False,
78 stUrl = False, stGraphics = False,
77 stUrl = False, stGraphics = False,
79 stLHS = False, stBook = writerChapters options,
78 stLHS = False, stBook = writerChapters options,
@@ -144,7 +143,6 @@ pandocToLaTeX options (Pandoc (Meta title authors date) blocks) = do
144 else "article") ] ++
143 else "article") ] ++
145 [ ("author", a) | a <- authorsText ] ++
144 [ ("author", a) | a <- authorsText ] ++
146 [ ("verbatim-in-note", "yes") | stVerbInNote st ] ++
145 [ ("verbatim-in-note", "yes") | stVerbInNote st ] ++
147− [ ("fancy-enums", "yes") | stEnumerate st ] ++
148 [ ("tables", "yes") | stTable st ] ++
146 [ ("tables", "yes") | stTable st ] ++
149 [ ("strikeout", "yes") | stStrikeout st ] ++
147 [ ("strikeout", "yes") | stStrikeout st ] ++
150 [ ("url", "yes") | stUrl st ] ++
148 [ ("url", "yes") | stUrl st ] ++
@@ -354,20 +352,32 @@ blockToLaTeX (OrderedList (start, numstyle, numdelim) lst) = do
354 put $ st {stOLLevel = oldlevel + 1}
352 put $ st {stOLLevel = oldlevel + 1}
355 items <- mapM listItemToLaTeX lst
353 items <- mapM listItemToLaTeX lst
356 modify (\s -> s {stOLLevel = oldlevel})
354 modify (\s -> s {stOLLevel = oldlevel})
355+ let tostyle x = case numstyle of
356+ Decimal -> "\\arabic" <> braces x
357+ UpperRoman -> "\\Roman" <> braces x
358+ LowerRoman -> "\\roman" <> braces x
359+ UpperAlpha -> "\\Alph" <> braces x
360+ LowerAlpha -> "\\alph" <> braces x
361+ _ -> x
362+ let todelim x = case numdelim of
363+ OneParen -> x <> ")"
364+ TwoParens -> parens x
365+ Period -> x <> "."
366+ _ -> x <> "."
367+ let enum = text $ "enum" ++ map toLower (toRomanNumeral oldlevel)
357− exemplar <- if numstyle /= DefaultStyle || numdelim /= DefaultDelim
368+ let stylecommand = if numstyle == DefaultStyle && numdelim == DefaultDelim
358− then do
369+ then empty
359− modify $ \s -> s{ stEnumerate = True }
370+ else "\\def" <> "\\label" <> enum <>
360− return $ char '[' <>
371+ braces (todelim $ tostyle enum)
361− text (head (orderedListMarkers (1, numstyle,
372+ let resetcounter = if start == 1 || oldlevel > 4
362− numdelim))) <> char ']'
373+ then empty
363− else return empty
364− let resetcounter = if start /= 1 && oldlevel <= 4
365− then text $ "\\setcounter{enum" ++
374+ else "\\setcounter" <> braces enum <>
366− map toLower (toRomanNumeral oldlevel) ++
367− "}{" ++ show (start - 1) ++ "}"
375+ braces (text $ show $ start - 1)
368− else empty
369− return $ text ("\\begin{enumerate}" ++ inc) <> exemplar $$ resetcounter $$
376+ return $ text ("\\begin{enumerate}" ++ inc)
377+ $$ stylecommand
378+ $$ resetcounter
379+ $$ vcat items
370− vcat items $$ "\\end{enumerate}"
380+ $$ "\\end{enumerate}"
371blockToLaTeX (DefinitionList lst) = do
381blockToLaTeX (DefinitionList lst) = do
372 incremental <- gets stIncremental
382 incremental <- gets stIncremental
373 let inc = if incremental then "[<+->]" else ""
383 let inc = if incremental then "[<+->]" else ""
templates+1−1

Submodule changed.

tests/writer.latex+34−24
@@ -17,13 +17,6 @@
17 \newcommand{\euro}{€}
17 \newcommand{\euro}{€}
18\fi
18\fi
19\usepackage{fancyvrb}
19\usepackage{fancyvrb}
20−% Redefine labelwidth for lists; otherwise, the enumerate package will cause
21−% markers to extend beyond the left margin.
22−\makeatletter\AtBeginDocument{%
23− \renewcommand{\@listi}
24− {\setlength{\labelwidth}{4em}}
25−}\makeatother
26−\usepackage{enumerate}
27\usepackage{graphicx}
20\usepackage{graphicx}
28% We will generate all images so they have a width \maxwidth. This means
21% We will generate all images so they have a width \maxwidth. This means
29% that they will get their normal width if they fit onto the page, but
22% that they will get their normal width if they fit onto the page, but
@@ -127,7 +120,8 @@ sub status {
127
120
128A list:
121A list:
129
122
130−\begin{enumerate}[1.]
123+\begin{enumerate}
124+\def\labelenumi{\arabic{enumi}.}
131\item
125\item
132 item one
126 item one
133\item
127\item
@@ -249,7 +243,8 @@ Minuses loose:
249
243
250Tight:
244Tight:
251
245
252−\begin{enumerate}[1.]
246+\begin{enumerate}
247+\def\labelenumi{\arabic{enumi}.}
253\item
248\item
254 First
249 First
255\item
250\item
@@ -260,7 +255,8 @@ Tight:
260
255
261and:
256and:
262
257
263−\begin{enumerate}[1.]
258+\begin{enumerate}
259+\def\labelenumi{\arabic{enumi}.}
264\item
260\item
265 One
261 One
266\item
262\item
@@ -271,7 +267,8 @@ and:
271
267
272Loose using tabs:
268Loose using tabs:
273
269
274−\begin{enumerate}[1.]
270+\begin{enumerate}
271+\def\labelenumi{\arabic{enumi}.}
275\item
272\item
276 First
273 First
277\item
274\item
@@ -282,7 +279,8 @@ Loose using tabs:
282
279
283and using spaces:
280and using spaces:
284
281
285−\begin{enumerate}[1.]
282+\begin{enumerate}
283+\def\labelenumi{\arabic{enumi}.}
286\item
284\item
287 One
285 One
288\item
286\item
@@ -293,7 +291,8 @@ and using spaces:
293
291
294Multiple paragraphs:
292Multiple paragraphs:
295
293
296−\begin{enumerate}[1.]
294+\begin{enumerate}
295+\def\labelenumi{\arabic{enumi}.}
297\item
296\item
298 Item 1, graf one.
297 Item 1, graf one.
299
298
@@ -323,7 +322,8 @@ Multiple paragraphs:
323
322
324Here's another:
323Here's another:
325
324
326−\begin{enumerate}[1.]
325+\begin{enumerate}
326+\def\labelenumi{\arabic{enumi}.}
327\item
327\item
328 First
328 First
329\item
329\item
@@ -343,7 +343,8 @@ Here's another:
343
343
344Same thing but with paragraphs:
344Same thing but with paragraphs:
345
345
346−\begin{enumerate}[1.]
346+\begin{enumerate}
347+\def\labelenumi{\arabic{enumi}.}
347\item
348\item
348 First
349 First
349\item
350\item
@@ -379,7 +380,8 @@ Same thing but with paragraphs:
379
380
380\subsection{Fancy list markers}
381\subsection{Fancy list markers}
381
382
382−\begin{enumerate}[(1)]
383+\begin{enumerate}
384+\def\labelenumi{(\arabic{enumi})}
383\setcounter{enumi}{1}
385\setcounter{enumi}{1}
384\item
386\item
385 begins with 2
387 begins with 2
@@ -388,14 +390,16 @@ Same thing but with paragraphs:
388
390
389 with a continuation
391 with a continuation
390
392
391− \begin{enumerate}[i.]
393+ \begin{enumerate}
394+ \def\labelenumii{\roman{enumii}.}
392 \setcounter{enumii}{3}
395 \setcounter{enumii}{3}
393 \item
396 \item
394 sublist with roman numerals, starting with 4
397 sublist with roman numerals, starting with 4
395 \item
398 \item
396 more items
399 more items
397
400
398− \begin{enumerate}[(A)]
401+ \begin{enumerate}
402+ \def\labelenumiii{(\Alph{enumiii})}
399 \item
403 \item
400 a subsublist
404 a subsublist
401 \item
405 \item
@@ -406,20 +410,24 @@ Same thing but with paragraphs:
406
410
407Nesting:
411Nesting:
408
412
409−\begin{enumerate}[A.]
413+\begin{enumerate}
414+\def\labelenumi{\Alph{enumi}.}
410\item
415\item
411 Upper Alpha
416 Upper Alpha
412
417
413− \begin{enumerate}[I.]
418+ \begin{enumerate}
419+ \def\labelenumii{\Roman{enumii}.}
414 \item
420 \item
415 Upper Roman.
421 Upper Roman.
416
422
417− \begin{enumerate}[(1)]
423+ \begin{enumerate}
424+ \def\labelenumiii{(\arabic{enumiii})}
418 \setcounter{enumiii}{5}
425 \setcounter{enumiii}{5}
419 \item
426 \item
420 Decimal start with 6
427 Decimal start with 6
421
428
422− \begin{enumerate}[a)]
429+ \begin{enumerate}
430+ \def\labelenumiv{\alph{enumiv})}
423 \setcounter{enumiv}{2}
431 \setcounter{enumiv}{2}
424 \item
432 \item
425 Lower alpha with paren
433 Lower alpha with paren
@@ -540,7 +548,8 @@ computer
540\item[orange]
548\item[orange]
541orange fruit
549orange fruit
542
550
543−\begin{enumerate}[1.]
551+\begin{enumerate}
552+\def\labelenumi{\arabic{enumi}.}
544\item
553\item
545 sublist
554 sublist
546\item
555\item
@@ -900,7 +909,8 @@ note.\footnote{This is \emph{easier} to type. Inline notes may contain
900Notes can go in quotes.\footnote{In quote.}
909Notes can go in quotes.\footnote{In quote.}
901\end{quote}
910\end{quote}
902
911
903−\begin{enumerate}[1.]
912+\begin{enumerate}
913+\def\labelenumi{\arabic{enumi}.}
904\item
914\item
905 And in list items.\footnote{In list.}
915 And in list items.\footnote{In list.}
906\end{enumerate}
916\end{enumerate}