@@ -29,7 +29,10 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30Conversion of 'Pandoc' format into LaTeX.
30Conversion of 'Pandoc' format into LaTeX.
32−module Text.Pandoc.Writers.LaTeX ( writeLaTeX ) where
32+module Text.Pandoc.Writers.LaTeX (
33import Text.Pandoc.Definition
36import Text.Pandoc.Definition
34import Text.Pandoc.Walk
37import Text.Pandoc.Walk
35import Text.Pandoc.Shared
38import Text.Pandoc.Shared
@@ -76,26 +79,46 @@ data WriterState =
76 , stIncremental :: Bool -- true if beamer lists should be displayed bit by bit
79 , stIncremental :: Bool -- true if beamer lists should be displayed bit by bit
77 , stInternalLinks :: [String] -- list of internal link targets
80 , stInternalLinks :: [String] -- list of internal link targets
78 , stUsesEuro :: Bool -- true if euro symbol used
81 , stUsesEuro :: Bool -- true if euro symbol used
82+ , stBeamer :: Bool -- produce beamer
85+startingState :: WriterOptions -> WriterState
86+startingState options = WriterState {
89+ , stInMinipage = False
90+ , stInHeading = False
93+ , stOptions = options
94+ , stVerbInNote = False
96+ , stStrikeout = False
100+ , stBook = (case writerTopLevelDivision options of
101+ TopLevelPart -> True
102+ TopLevelChapter -> True
104+ , stCsquotes = False
105+ , stHighlighting = False
106+ , stIncremental = writerIncremental options
107+ , stInternalLinks = []
108+ , stUsesEuro = False
109+ , stBeamer = False }
81-- | Convert Pandoc to LaTeX.
111-- | Convert Pandoc to LaTeX.
82writeLaTeX :: PandocMonad m => WriterOptions -> Pandoc -> m String
112writeLaTeX :: PandocMonad m => WriterOptions -> Pandoc -> m String
83writeLaTeX options document = return $
113writeLaTeX options document = return $
84 evalState (pandocToLaTeX options document) $
114 evalState (pandocToLaTeX options document) $
85− WriterState { stInNote = False, stInQuote = False,
115+ startingState options
86− stInMinipage = False, stInHeading = False,
116+
87− stNotes = [], stOLLevel = 1,
117+-- | Convert Pandoc to LaTeX Beamer.
88− stOptions = options, stVerbInNote = False,
118+writeBeamer :: PandocMonad m => WriterOptions -> Pandoc -> m String
89− stTable = False, stStrikeout = False,
119+writeBeamer options document = return $
90− stUrl = False, stGraphics = False,
120+ evalState (pandocToLaTeX options document) $
91− stLHS = False,
121+ (startingState options){ stBeamer = True }
92− stBook = (case writerTopLevelDivision options of
94− TopLevelChapter -> True
96− stCsquotes = False, stHighlighting = False,
97− stIncremental = writerIncremental options,
98− stInternalLinks = [], stUsesEuro = False }
100pandocToLaTeX :: WriterOptions -> Pandoc -> State WriterState String
123pandocToLaTeX :: WriterOptions -> Pandoc -> State WriterState String
101pandocToLaTeX options (Pandoc meta blocks) = do
124pandocToLaTeX options (Pandoc meta blocks) = do
@@ -144,7 +167,8 @@ pandocToLaTeX options (Pandoc meta blocks) = do
144 else case last blocks' of
167 else case last blocks' of
145 Header 1 _ il -> (init blocks', il)
168 Header 1 _ il -> (init blocks', il)
146 _ -> (blocks', [])
169 _ -> (blocks', [])
147− blocks''' <- if writerBeamer options
170+ beamer <- gets stBeamer
171+ blocks''' <- if beamer
148 then toSlides blocks''
172 then toSlides blocks''
149 else return blocks''
173 else return blocks''
150 body <- mapM (elementToLaTeX options) $ hierarchicalize blocks'''
174 body <- mapM (elementToLaTeX options) $ hierarchicalize blocks'''
@@ -171,7 +195,7 @@ pandocToLaTeX options (Pandoc meta blocks) = do
171 defField "body" main $
195 defField "body" main $
172 defField "title-meta" titleMeta $
196 defField "title-meta" titleMeta $
173 defField "author-meta" (intercalate "; " authorsMeta) $
197 defField "author-meta" (intercalate "; " authorsMeta) $
174− defField "documentclass" (if writerBeamer options
198+ defField "documentclass" (if beamer
175 then ("beamer" :: String)
199 then ("beamer" :: String)
176 else if stBook st
200 else if stBook st
177 then "book"
201 then "book"
@@ -186,7 +210,7 @@ pandocToLaTeX options (Pandoc meta blocks) = do
186 defField "book-class" (stBook st) $
210 defField "book-class" (stBook st) $
187 defField "euro" (stUsesEuro st) $
211 defField "euro" (stUsesEuro st) $
188 defField "listings" (writerListings options || stLHS st) $
212 defField "listings" (writerListings options || stLHS st) $
189− defField "beamer" (writerBeamer options) $
213+ defField "beamer" beamer $
190 (if stHighlighting st
214 (if stHighlighting st
191 then case writerHighlightStyle options of
215 then case writerHighlightStyle options of
192 Just sty ->
216 Just sty ->
@@ -388,7 +412,7 @@ blockToLaTeX :: Block -- ^ Block to convert
388 -> State WriterState Doc
412 -> State WriterState Doc
389blockToLaTeX Null = return empty
413blockToLaTeX Null = return empty
390blockToLaTeX (Div (identifier,classes,kvs) bs) = do
414blockToLaTeX (Div (identifier,classes,kvs) bs) = do
391− beamer <- writerBeamer `fmap` gets stOptions
415+ beamer <- gets stBeamer
392 ref <- toLabel identifier
416 ref <- toLabel identifier
393 let linkAnchor = if null identifier
417 let linkAnchor = if null identifier
394 then empty
418 then empty
@@ -439,7 +463,7 @@ blockToLaTeX (Para [Image attr@(ident, _, _) txt (src,'f':'i':'g':':':tit)]) = d
439 else figure $$ footnotes
463 else figure $$ footnotes
440-- . . . indicates pause in beamer slides
464-- . . . indicates pause in beamer slides
441blockToLaTeX (Para [Str ".",Space,Str ".",Space,Str "."]) = do
465blockToLaTeX (Para [Str ".",Space,Str ".",Space,Str "."]) = do
442− beamer <- writerBeamer `fmap` gets stOptions
466+ beamer <- gets stBeamer
443 if beamer
467 if beamer
444 then blockToLaTeX (RawBlock "latex" "\\pause")
468 then blockToLaTeX (RawBlock "latex" "\\pause")
445 else inlineListToLaTeX [Str ".",Space,Str ".",Space,Str "."]
469 else inlineListToLaTeX [Str ".",Space,Str ".",Space,Str "."]
@@ -448,7 +472,7 @@ blockToLaTeX (Para lst) =
448blockToLaTeX (LineBlock lns) = do
472blockToLaTeX (LineBlock lns) = do
449 blockToLaTeX $ linesToPara lns
473 blockToLaTeX $ linesToPara lns
450blockToLaTeX (BlockQuote lst) = do
474blockToLaTeX (BlockQuote lst) = do
451− beamer <- writerBeamer `fmap` gets stOptions
475+ beamer <- gets stBeamer
452 case lst of
476 case lst of
453 [b] | beamer && isListBlock b -> do
477 [b] | beamer && isListBlock b -> do
454 oldIncremental <- gets stIncremental
478 oldIncremental <- gets stIncremental
@@ -527,7 +551,7 @@ blockToLaTeX (RawBlock f x)
527blockToLaTeX (BulletList []) = return empty -- otherwise latex error
551blockToLaTeX (BulletList []) = return empty -- otherwise latex error
528blockToLaTeX (BulletList lst) = do
552blockToLaTeX (BulletList lst) = do
529 incremental <- gets stIncremental
553 incremental <- gets stIncremental
530− beamer <- writerBeamer `fmap` gets stOptions
554+ beamer <- gets stBeamer
531 let inc = if beamer && incremental then "[<+->]" else ""
555 let inc = if beamer && incremental then "[<+->]" else ""
532 items <- mapM listItemToLaTeX lst
556 items <- mapM listItemToLaTeX lst
533 let spacing = if isTightList lst
557 let spacing = if isTightList lst
@@ -772,7 +796,8 @@ sectionHeader unnumbered ident level lst = do
772 let topLevelDivision = if book && writerTopLevelDivision opts == TopLevelDefault
796 let topLevelDivision = if book && writerTopLevelDivision opts == TopLevelDefault
773 then TopLevelChapter
797 then TopLevelChapter
774 else writerTopLevelDivision opts
798 else writerTopLevelDivision opts
799+ beamer <- gets stBeamer
775− let level' = if writerBeamer opts &&
800+ let level' = if beamer &&
776 topLevelDivision `elem` [TopLevelPart, TopLevelChapter]
801 topLevelDivision `elem` [TopLevelPart, TopLevelChapter]
777 -- beamer has parts but no chapters
802 -- beamer has parts but no chapters
778 then if level == 1 then -1 else level - 1
803 then if level == 1 then -1 else level - 1
@@ -1022,9 +1047,9 @@ inlineToLaTeX (Note contents) = do
1022 (CodeBlock _ _ : _) -> cr
1047 (CodeBlock _ _ : _) -> cr
1023 _ -> empty
1048 _ -> empty
1024 let noteContents = nest 2 contents' <> optnl
1049 let noteContents = nest 2 contents' <> optnl
1025− opts <- gets stOptions
1050+ beamer <- gets stBeamer
1026 -- in beamer slides, display footnote from current overlay forward
1051 -- in beamer slides, display footnote from current overlay forward
1027− let beamerMark = if writerBeamer opts
1052+ let beamerMark = if beamer
1028 then text "<.->"
1053 then text "<.->"
1029 else empty
1054 else empty
1030 modify $ \st -> st{ stNotes = noteContents : stNotes st }
1055 modify $ \st -> st{ stNotes = noteContents : stNotes st }