git.iko.soy/typeable/pandoc
on master help sign in
LaTeX writer: export writeBeamer.

Removed writerBeamer from WriterOptions.

commitd2e0592e0174d4890ef0971bd4d47bbb45a98c3a authorJohn MacFarlane <jgm@berkeley.edu> dateSat 28 Jan 2017, 09:52 (10 years ago) parent91cdcc7
5 files changed+56−32
pandoc.hs−1 src/Text/Pandoc.hs+2−2 src/Text/Pandoc/Options.hs−2 src/Text/Pandoc/Writers/LaTeX.hs+50−25 tests/Tests/Writers/LaTeX.hs+4−2
pandoc.hs−1
@@ -313,7 +313,6 @@ convertWithOpts opts args = do
313313 writerHtmlQTags = htmlQTags,
314314 writerTopLevelDivision = topLevelDivision,
315315 writerListings = listings,
316− writerBeamer = False,
317316 writerSlideLevel = slideLevel,
318317 writerHighlightStyle = highlightStyle,
319318 writerSetextHeaders = setextHeaders,
src/Text/Pandoc.hs+2−2
@@ -97,6 +97,7 @@ module Text.Pandoc
9797 , writePlain
9898 , writeRST
9999 , writeLaTeX
100+ , writeBeamer
100101 , writeConTeXt
101102 , writeTexinfo
102103 , writeHtml4
@@ -304,8 +305,7 @@ writers = [
304305 ,("opml" , StringWriter writeOPML)
305306 ,("opendocument" , StringWriter writeOpenDocument)
306307 ,("latex" , StringWriter writeLaTeX)
307− ,("beamer" , StringWriter $ \o ->
308− writeLaTeX o{ writerBeamer = True })
308+ ,("beamer" , StringWriter writeBeamer)
309309 ,("context" , StringWriter writeConTeXt)
310310 ,("texinfo" , StringWriter writeTexinfo)
311311 ,("man" , StringWriter writeMan)
src/Text/Pandoc/Options.hs−2
@@ -167,7 +167,6 @@ data WriterOptions = WriterOptions
167167 , writerUserDataDir :: Maybe FilePath -- ^ Path of user data directory
168168 , writerCiteMethod :: CiteMethod -- ^ How to print cites
169169 , writerHtmlQTags :: Bool -- ^ Use @<q>@ tags for quotes in HTML
170− , writerBeamer :: Bool -- ^ Produce beamer LaTeX slide show
171170 , writerSlideLevel :: Maybe Int -- ^ Force header level of slides
172171 , writerTopLevelDivision :: TopLevelDivision -- ^ Type of top-level divisions
173172 , writerListings :: Bool -- ^ Use listings package for code
@@ -205,7 +204,6 @@ instance Default WriterOptions where
205204 , writerUserDataDir = Nothing
206205 , writerCiteMethod = Citeproc
207206 , writerHtmlQTags = False
208− , writerBeamer = False
209207 , writerSlideLevel = Nothing
210208 , writerTopLevelDivision = TopLevelDefault
211209 , writerListings = False
src/Text/Pandoc/Writers/LaTeX.hs+50−25
@@ -29,7 +29,10 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2929
3030Conversion of 'Pandoc' format into LaTeX.
3131-}
32−module Text.Pandoc.Writers.LaTeX ( writeLaTeX ) where
32+module Text.Pandoc.Writers.LaTeX (
33+ writeLaTeX
34+ , writeBeamer
35+ ) where
3336import Text.Pandoc.Definition
3437import Text.Pandoc.Walk
3538import Text.Pandoc.Shared
@@ -76,26 +79,46 @@ data WriterState =
7679 , stIncremental :: Bool -- true if beamer lists should be displayed bit by bit
7780 , stInternalLinks :: [String] -- list of internal link targets
7881 , stUsesEuro :: Bool -- true if euro symbol used
82+ , stBeamer :: Bool -- produce beamer
7983 }
8084
85+startingState :: WriterOptions -> WriterState
86+startingState options = WriterState {
87+ stInNote = False
88+ , stInQuote = False
89+ , stInMinipage = False
90+ , stInHeading = False
91+ , stNotes = []
92+ , stOLLevel = 1
93+ , stOptions = options
94+ , stVerbInNote = False
95+ , stTable = False
96+ , stStrikeout = False
97+ , stUrl = False
98+ , stGraphics = False
99+ , stLHS = False
100+ , stBook = (case writerTopLevelDivision options of
101+ TopLevelPart -> True
102+ TopLevelChapter -> True
103+ _ -> False)
104+ , stCsquotes = False
105+ , stHighlighting = False
106+ , stIncremental = writerIncremental options
107+ , stInternalLinks = []
108+ , stUsesEuro = False
109+ , stBeamer = False }
110+
81111-- | Convert Pandoc to LaTeX.
82112writeLaTeX :: PandocMonad m => WriterOptions -> Pandoc -> m String
83113writeLaTeX options document = return $
84114 evalState (pandocToLaTeX options document) $
85− WriterState { stInNote = False, stInQuote = False,
86− stInMinipage = False, stInHeading = False,
87− stNotes = [], stOLLevel = 1,
88− stOptions = options, stVerbInNote = False,
89− stTable = False, stStrikeout = False,
90− stUrl = False, stGraphics = False,
91− stLHS = False,
92− stBook = (case writerTopLevelDivision options of
93− TopLevelPart -> True
94− TopLevelChapter -> True
95− _ -> False),
96− stCsquotes = False, stHighlighting = False,
97− stIncremental = writerIncremental options,
98− stInternalLinks = [], stUsesEuro = False }
115+ startingState options
116+
117+-- | Convert Pandoc to LaTeX Beamer.
118+writeBeamer :: PandocMonad m => WriterOptions -> Pandoc -> m String
119+writeBeamer options document = return $
120+ evalState (pandocToLaTeX options document) $
121+ (startingState options){ stBeamer = True }
99122
100123pandocToLaTeX :: WriterOptions -> Pandoc -> State WriterState String
101124pandocToLaTeX options (Pandoc meta blocks) = do
@@ -144,7 +167,8 @@ pandocToLaTeX options (Pandoc meta blocks) = do
144167 else case last blocks' of
145168 Header 1 _ il -> (init blocks', il)
146169 _ -> (blocks', [])
147− blocks''' <- if writerBeamer options
170+ beamer <- gets stBeamer
171+ blocks''' <- if beamer
148172 then toSlides blocks''
149173 else return blocks''
150174 body <- mapM (elementToLaTeX options) $ hierarchicalize blocks'''
@@ -171,7 +195,7 @@ pandocToLaTeX options (Pandoc meta blocks) = do
171195 defField "body" main $
172196 defField "title-meta" titleMeta $
173197 defField "author-meta" (intercalate "; " authorsMeta) $
174− defField "documentclass" (if writerBeamer options
198+ defField "documentclass" (if beamer
175199 then ("beamer" :: String)
176200 else if stBook st
177201 then "book"
@@ -186,7 +210,7 @@ pandocToLaTeX options (Pandoc meta blocks) = do
186210 defField "book-class" (stBook st) $
187211 defField "euro" (stUsesEuro st) $
188212 defField "listings" (writerListings options || stLHS st) $
189− defField "beamer" (writerBeamer options) $
213+ defField "beamer" beamer $
190214 (if stHighlighting st
191215 then case writerHighlightStyle options of
192216 Just sty ->
@@ -388,7 +412,7 @@ blockToLaTeX :: Block -- ^ Block to convert
388412 -> State WriterState Doc
389413blockToLaTeX Null = return empty
390414blockToLaTeX (Div (identifier,classes,kvs) bs) = do
391− beamer <- writerBeamer `fmap` gets stOptions
415+ beamer <- gets stBeamer
392416 ref <- toLabel identifier
393417 let linkAnchor = if null identifier
394418 then empty
@@ -439,7 +463,7 @@ blockToLaTeX (Para [Image attr@(ident, _, _) txt (src,'f':'i':'g':':':tit)]) = d
439463 else figure $$ footnotes
440464-- . . . indicates pause in beamer slides
441465blockToLaTeX (Para [Str ".",Space,Str ".",Space,Str "."]) = do
442− beamer <- writerBeamer `fmap` gets stOptions
466+ beamer <- gets stBeamer
443467 if beamer
444468 then blockToLaTeX (RawBlock "latex" "\\pause")
445469 else inlineListToLaTeX [Str ".",Space,Str ".",Space,Str "."]
@@ -448,7 +472,7 @@ blockToLaTeX (Para lst) =
448472blockToLaTeX (LineBlock lns) = do
449473 blockToLaTeX $ linesToPara lns
450474blockToLaTeX (BlockQuote lst) = do
451− beamer <- writerBeamer `fmap` gets stOptions
475+ beamer <- gets stBeamer
452476 case lst of
453477 [b] | beamer && isListBlock b -> do
454478 oldIncremental <- gets stIncremental
@@ -527,7 +551,7 @@ blockToLaTeX (RawBlock f x)
527551blockToLaTeX (BulletList []) = return empty -- otherwise latex error
528552blockToLaTeX (BulletList lst) = do
529553 incremental <- gets stIncremental
530− beamer <- writerBeamer `fmap` gets stOptions
554+ beamer <- gets stBeamer
531555 let inc = if beamer && incremental then "[<+->]" else ""
532556 items <- mapM listItemToLaTeX lst
533557 let spacing = if isTightList lst
@@ -772,7 +796,8 @@ sectionHeader unnumbered ident level lst = do
772796 let topLevelDivision = if book && writerTopLevelDivision opts == TopLevelDefault
773797 then TopLevelChapter
774798 else writerTopLevelDivision opts
775− let level' = if writerBeamer opts &&
799+ beamer <- gets stBeamer
800+ let level' = if beamer &&
776801 topLevelDivision `elem` [TopLevelPart, TopLevelChapter]
777802 -- beamer has parts but no chapters
778803 then if level == 1 then -1 else level - 1
@@ -1022,9 +1047,9 @@ inlineToLaTeX (Note contents) = do
10221047 (CodeBlock _ _ : _) -> cr
10231048 _ -> empty
10241049 let noteContents = nest 2 contents' <> optnl
1025− opts <- gets stOptions
1050+ beamer <- gets stBeamer
10261051 -- in beamer slides, display footnote from current overlay forward
1027− let beamerMark = if writerBeamer opts
1052+ let beamerMark = if beamer
10281053 then text "<.->"
10291054 else empty
10301055 modify $ \st -> st{ stNotes = noteContents : stNotes st }
tests/Tests/Writers/LaTeX.hs+4−2
@@ -16,6 +16,9 @@ latexListing = latexWithOpts def{ writerListings = True }
1616latexWithOpts :: (ToPandoc a) => WriterOptions -> a -> String
1717latexWithOpts opts = purely (writeLaTeX opts) . toPandoc
1818
19+beamerWithOpts :: (ToPandoc a) => WriterOptions -> a -> String
20+beamerWithOpts opts = purely (writeBeamer opts) . toPandoc
21+
1922{-
2023 "my test" =: X =?> Y
2124
@@ -95,8 +98,7 @@ tests = [ testGroup "code blocks"
9598 beamerTopLevelDiv :: (ToPandoc a)
9699 => TopLevelDivision -> a -> String
97100 beamerTopLevelDiv division =
98− latexWithOpts def { writerTopLevelDivision = division
99− , writerBeamer = True }
101+ beamerWithOpts def { writerTopLevelDivision = division }
100102 in
101103 [ test (latexTopLevelDiv TopLevelSection)
102104 "sections as top-level" $ headers =?>