git.iko.soy/typeable/pandoc
on master help sign in
LaTeX writer: Don't rely on the enumerate package.

Instead, use standard LaTeX commands to change numbering style.

commite1be934dc2ff061e5200017d6503280686983e1f authorJohn MacFarlane <jgm@berkeley.edu> dateSun 16 Sep 2012, 22:24 (14 years ago) parent1e2b20f
3 files changed+62−42
src/Text/Pandoc/Writers/LaTeX.hs+27−17 templates+1−1 tests/writer.latex+34−24
src/Text/Pandoc/Writers/LaTeX.hs+27−17
@@ -53,7 +53,6 @@ data WriterState =
5353 , stOLLevel :: Int -- level of ordered list nesting
5454 , stOptions :: WriterOptions -- writer options, so they don't have to be parameter
5555 , stVerbInNote :: Bool -- true if document has verbatim text in note
56− , stEnumerate :: Bool -- true if document needs fancy enumerated lists
5756 , stTable :: Bool -- true if document has a table
5857 , stStrikeout :: Bool -- true if document has strikeout
5958 , stUrl :: Bool -- true if document has visible URL link
@@ -73,7 +72,7 @@ writeLaTeX options document =
7372 evalState (pandocToLaTeX options document) $
7473 WriterState { stInNote = False, stInTable = False,
7574 stTableNotes = [], stOLLevel = 1, stOptions = options,
76− stVerbInNote = False, stEnumerate = False,
75+ stVerbInNote = False,
7776 stTable = False, stStrikeout = False,
7877 stUrl = False, stGraphics = False,
7978 stLHS = False, stBook = writerChapters options,
@@ -144,7 +143,6 @@ pandocToLaTeX options (Pandoc (Meta title authors date) blocks) = do
144143 else "article") ] ++
145144 [ ("author", a) | a <- authorsText ] ++
146145 [ ("verbatim-in-note", "yes") | stVerbInNote st ] ++
147− [ ("fancy-enums", "yes") | stEnumerate st ] ++
148146 [ ("tables", "yes") | stTable st ] ++
149147 [ ("strikeout", "yes") | stStrikeout st ] ++
150148 [ ("url", "yes") | stUrl st ] ++
@@ -354,20 +352,32 @@ blockToLaTeX (OrderedList (start, numstyle, numdelim) lst) = do
354352 put $ st {stOLLevel = oldlevel + 1}
355353 items <- mapM listItemToLaTeX lst
356354 modify (\s -> s {stOLLevel = oldlevel})
357− exemplar <- if numstyle /= DefaultStyle || numdelim /= DefaultDelim
358− then do
359− modify $ \s -> s{ stEnumerate = True }
360− return $ char '[' <>
361− text (head (orderedListMarkers (1, numstyle,
362− numdelim))) <> char ']'
363− else return empty
364− let resetcounter = if start /= 1 && oldlevel <= 4
365− then text $ "\\setcounter{enum" ++
366− map toLower (toRomanNumeral oldlevel) ++
367− "}{" ++ show (start - 1) ++ "}"
368− else empty
369− return $ text ("\\begin{enumerate}" ++ inc) <> exemplar $$ resetcounter $$
370− vcat items $$ "\\end{enumerate}"
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)
368+ let stylecommand = if numstyle == DefaultStyle && numdelim == DefaultDelim
369+ then empty
370+ else "\\def" <> "\\label" <> enum <>
371+ braces (todelim $ tostyle enum)
372+ let resetcounter = if start == 1 || oldlevel > 4
373+ then empty
374+ else "\\setcounter" <> braces enum <>
375+ braces (text $ show $ start - 1)
376+ return $ text ("\\begin{enumerate}" ++ inc)
377+ $$ stylecommand
378+ $$ resetcounter
379+ $$ vcat items
380+ $$ "\\end{enumerate}"
371381blockToLaTeX (DefinitionList lst) = do
372382 incremental <- gets stIncremental
373383 let inc = if incremental then "[<+->]" else ""
templates+1−1

Submodule changed.

tests/writer.latex+34−24
@@ -17,13 +17,6 @@
1717 \newcommand{\euro}{€}
1818\fi
1919\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}
2720\usepackage{graphicx}
2821% We will generate all images so they have a width \maxwidth. This means
2922% that they will get their normal width if they fit onto the page, but
@@ -127,7 +120,8 @@ sub status {
127120
128121A list:
129122
130−\begin{enumerate}[1.]
123+\begin{enumerate}
124+\def\labelenumi{\arabic{enumi}.}
131125\item
132126 item one
133127\item
@@ -249,7 +243,8 @@ Minuses loose:
249243
250244Tight:
251245
252−\begin{enumerate}[1.]
246+\begin{enumerate}
247+\def\labelenumi{\arabic{enumi}.}
253248\item
254249 First
255250\item
@@ -260,7 +255,8 @@ Tight:
260255
261256and:
262257
263−\begin{enumerate}[1.]
258+\begin{enumerate}
259+\def\labelenumi{\arabic{enumi}.}
264260\item
265261 One
266262\item
@@ -271,7 +267,8 @@ and:
271267
272268Loose using tabs:
273269
274−\begin{enumerate}[1.]
270+\begin{enumerate}
271+\def\labelenumi{\arabic{enumi}.}
275272\item
276273 First
277274\item
@@ -282,7 +279,8 @@ Loose using tabs:
282279
283280and using spaces:
284281
285−\begin{enumerate}[1.]
282+\begin{enumerate}
283+\def\labelenumi{\arabic{enumi}.}
286284\item
287285 One
288286\item
@@ -293,7 +291,8 @@ and using spaces:
293291
294292Multiple paragraphs:
295293
296−\begin{enumerate}[1.]
294+\begin{enumerate}
295+\def\labelenumi{\arabic{enumi}.}
297296\item
298297 Item 1, graf one.
299298
@@ -323,7 +322,8 @@ Multiple paragraphs:
323322
324323Here's another:
325324
326−\begin{enumerate}[1.]
325+\begin{enumerate}
326+\def\labelenumi{\arabic{enumi}.}
327327\item
328328 First
329329\item
@@ -343,7 +343,8 @@ Here's another:
343343
344344Same thing but with paragraphs:
345345
346−\begin{enumerate}[1.]
346+\begin{enumerate}
347+\def\labelenumi{\arabic{enumi}.}
347348\item
348349 First
349350\item
@@ -379,7 +380,8 @@ Same thing but with paragraphs:
379380
380381\subsection{Fancy list markers}
381382
382−\begin{enumerate}[(1)]
383+\begin{enumerate}
384+\def\labelenumi{(\arabic{enumi})}
383385\setcounter{enumi}{1}
384386\item
385387 begins with 2
@@ -388,14 +390,16 @@ Same thing but with paragraphs:
388390
389391 with a continuation
390392
391− \begin{enumerate}[i.]
393+ \begin{enumerate}
394+ \def\labelenumii{\roman{enumii}.}
392395 \setcounter{enumii}{3}
393396 \item
394397 sublist with roman numerals, starting with 4
395398 \item
396399 more items
397400
398− \begin{enumerate}[(A)]
401+ \begin{enumerate}
402+ \def\labelenumiii{(\Alph{enumiii})}
399403 \item
400404 a subsublist
401405 \item
@@ -406,20 +410,24 @@ Same thing but with paragraphs:
406410
407411Nesting:
408412
409−\begin{enumerate}[A.]
413+\begin{enumerate}
414+\def\labelenumi{\Alph{enumi}.}
410415\item
411416 Upper Alpha
412417
413− \begin{enumerate}[I.]
418+ \begin{enumerate}
419+ \def\labelenumii{\Roman{enumii}.}
414420 \item
415421 Upper Roman.
416422
417− \begin{enumerate}[(1)]
423+ \begin{enumerate}
424+ \def\labelenumiii{(\arabic{enumiii})}
418425 \setcounter{enumiii}{5}
419426 \item
420427 Decimal start with 6
421428
422− \begin{enumerate}[a)]
429+ \begin{enumerate}
430+ \def\labelenumiv{\alph{enumiv})}
423431 \setcounter{enumiv}{2}
424432 \item
425433 Lower alpha with paren
@@ -540,7 +548,8 @@ computer
540548\item[orange]
541549orange fruit
542550
543−\begin{enumerate}[1.]
551+\begin{enumerate}
552+\def\labelenumi{\arabic{enumi}.}
544553\item
545554 sublist
546555\item
@@ -900,7 +909,8 @@ note.\footnote{This is \emph{easier} to type. Inline notes may contain
900909Notes can go in quotes.\footnote{In quote.}
901910\end{quote}
902911
903−\begin{enumerate}[1.]
912+\begin{enumerate}
913+\def\labelenumi{\arabic{enumi}.}
904914\item
905915 And in list items.\footnote{In list.}
906916\end{enumerate}