@@ -62,6 +62,8 @@ data WriterState =
6262 , stBook :: Bool -- true if document uses book or memoir class
6363 , stCsquotes :: Bool -- true if document uses csquotes
6464 , stHighlighting :: Bool -- true if document has highlighted code
65+ , stFirstFrame :: Bool -- true til we've written first beamer frame
66+ , stIncremental :: Bool -- true if beamer lists should be displayed bit by bit
6567 }
6668
6769-- | Convert Pandoc to LaTeX.
@@ -74,23 +76,24 @@ writeLaTeX options document =
7476 stTable = False, stStrikeout = False, stSubscript = False,
7577 stUrl = False, stGraphics = False,
7678 stLHS = False, stBook = writerChapters options,
77− stCsquotes = False, stHighlighting = False }
79+ stCsquotes = False, stHighlighting = False,
80+ stFirstFrame = True, stIncremental = writerIncremental options }
7881
7982pandocToLaTeX :: WriterOptions -> Pandoc -> State WriterState String
8083pandocToLaTeX options (Pandoc (Meta title authors date) blocks) = do
8184 let template = writerTemplate options
85+ let templateLines = lines template
8286 let usesBookClass x = "\\documentclass" `isPrefixOf` x &&
8387 ("{memoir}" `isSuffixOf` x || "{book}" `isSuffixOf` x ||
8488 "{report}" `isSuffixOf` x)
85− when (any usesBookClass (lines template)) $
89+ when (any usesBookClass templateLines) $
8690 modify $ \s -> s{stBook = True}
8791 -- check for \usepackage...{csquotes}; if present, we'll use
8892 -- \enquote{...} for smart quotes:
8993 when ("{csquotes}" `isInfixOf` template) $
9094 modify $ \s -> s{stCsquotes = True}
91− opts <- liftM stOptions get
92− let colwidth = if writerWrapText opts
93− then Just $ writerColumns opts
95+ let colwidth = if writerWrapText options
96+ then Just $ writerColumns options
9497 else Nothing
9598 titletext <- liftM (render colwidth) $ inlineListToLaTeX title
9699 authorsText <- mapM (liftM (render colwidth) . inlineListToLaTeX) authors
@@ -100,7 +103,10 @@ pandocToLaTeX options (Pandoc (Meta title authors date) blocks) = do
100103 else case last blocks of
101104 Header 1 il -> (init blocks, il)
102105 _ -> (blocks, [])
103− body <- blockListToLaTeX blocks'
106+ blocks'' <- if writerBeamer options
107+ then toSlides blocks'
108+ else return blocks'
109+ body <- blockListToLaTeX blocks''
104110 biblioTitle <- liftM (render colwidth) $ inlineListToLaTeX lastHeader
105111 let main = render colwidth body
106112 st <- get
@@ -119,7 +125,12 @@ pandocToLaTeX options (Pandoc (Meta title authors date) blocks) = do
119125 [ ("toc", if writerTableOfContents options then "yes" else "")
120126 , ("body", main)
121127 , ("title", titletext)
122− , ("date", dateText) ] ++
128+ , ("date", dateText)
129+ , ("documentclass", if writerBeamer options
130+ then "beamer"
131+ else if writerChapters options
132+ then "book"
133+ else "article") ] ++
123134 [ ("author", a) | a <- authorsText ] ++
124135 [ ("verbatim-in-note", "yes") | stVerbInNote st ] ++
125136 [ ("fancy-enums", "yes") | stEnumerate st ] ++
@@ -132,8 +143,9 @@ pandocToLaTeX options (Pandoc (Meta title authors date) blocks) = do
132143 [ ("graphics", "yes") | stGraphics st ] ++
133144 [ ("book-class", "yes") | stBook st] ++
134145 [ ("listings", "yes") | writerListings options || stLHS st ] ++
146+ [ ("beamer", "yes") | writerBeamer options ] ++
135147 [ ("highlighting-macros", styleToLaTeX
136− $ writerHighlightStyle opts ) | stHighlighting st ] ++
148+ $ writerHighlightStyle options ) | stHighlighting st ] ++
137149 citecontext
138150 return $ if writerStandalone options
139151 then renderTemplate context template
@@ -171,6 +183,42 @@ stringToLaTeX isUrl = escapeStringUsing latexEscapes
171183inCmd :: String -> Doc -> Doc
172184inCmd cmd contents = char '\\' <> text cmd <> braces contents
173185
186+toSlides :: [Block] -> State WriterState [Block]
187+toSlides (Header n ils : bs) = do
188+ tit <- inlineListToLaTeX ils
189+ firstFrame <- gets stFirstFrame
190+ modify $ \s -> s{ stFirstFrame = False }
191+ -- note: [fragile] is required or verbatim breaks
192+ result <- ((Header n ils :) .
193+ (RawBlock "latex" ("\\begin{frame}[fragile]\n" ++
194+ "\\frametitle{" ++ render Nothing tit ++ "}") :))
195+ `fmap` toSlides bs
196+ if firstFrame
197+ then return result
198+ else return $ RawBlock "latex" "\\end{frame}" : result
199+toSlides (HorizontalRule : Header n ils : bs) =
200+ toSlides (Header n ils : bs)
201+toSlides (HorizontalRule : bs) = do
202+ firstFrame <- gets stFirstFrame
203+ modify $ \s -> s{ stFirstFrame = False }
204+ result <- (RawBlock "latex" "\\begin{frame}[fragile]" :)
205+ `fmap` toSlides bs
206+ if firstFrame
207+ then return result
208+ else return $ RawBlock "latex" "\\end{frame}" : result
209+toSlides (b:bs) = (b:) `fmap` toSlides bs
210+toSlides [] = do
211+ firstFrame <- gets stFirstFrame
212+ if firstFrame
213+ then return []
214+ else return [RawBlock "latex" "\\end{frame}"]
215+
216+isListBlock :: Block -> Bool
217+isListBlock (BulletList _) = True
218+isListBlock (OrderedList _ _) = True
219+isListBlock (DefinitionList _) = True
220+isListBlock _ = False
221+
174222-- | Convert Pandoc block element to LaTeX.
175223blockToLaTeX :: Block -- ^ Block to convert
176224 -> State WriterState Doc
@@ -185,8 +233,17 @@ blockToLaTeX (Para lst) = do
185233 result <- inlineListToLaTeX lst
186234 return $ result <> blankline
187235blockToLaTeX (BlockQuote lst) = do
188− contents <- blockListToLaTeX lst
189− return $ "\\begin{quote}" $$ contents $$ "\\end{quote}"
236+ beamer <- writerBeamer `fmap` gets stOptions
237+ case lst of
238+ [b] | beamer && isListBlock b -> do
239+ oldIncremental <- gets stIncremental
240+ modify $ \s -> s{ stIncremental = True }
241+ result <- blockToLaTeX b
242+ modify $ \s -> s{ stIncremental = oldIncremental }
243+ return result
244+ _ -> do
245+ contents <- blockListToLaTeX lst
246+ return $ "\\begin{quote}" $$ contents $$ "\\end{quote}"
190247blockToLaTeX (CodeBlock (_,classes,keyvalAttr) str) = do
191248 opts <- gets stOptions
192249 case () of
@@ -243,10 +300,13 @@ blockToLaTeX (CodeBlock (_,classes,keyvalAttr) str) = do
243300blockToLaTeX (RawBlock "latex" x) = return $ text x <> blankline
244301blockToLaTeX (RawBlock _ _) = return empty
245302blockToLaTeX (BulletList lst) = do
303+ incremental <- gets stIncremental
304+ let inc = if incremental then "[<+->]" else ""
246305 items <- mapM listItemToLaTeX lst
247− return $ "\\begin{itemize}" $$ vcat items $$ "\\end{itemize}"
306+ return $ text ("\\begin{itemize}" ++ inc) $$ vcat items $$ "\\end{itemize}"
248307blockToLaTeX (OrderedList (start, numstyle, numdelim) lst) = do
249308 st <- get
309+ let inc = if stIncremental st then "[<+->]" else ""
250310 let oldlevel = stOLLevel st
251311 put $ st {stOLLevel = oldlevel + 1}
252312 items <- mapM listItemToLaTeX lst
@@ -263,11 +323,13 @@ blockToLaTeX (OrderedList (start, numstyle, numdelim) lst) = do
263323 map toLower (toRomanNumeral oldlevel) ++
264324 "}{" ++ show (start - 1) ++ "}"
265325 else empty
266− return $ "\\begin{enumerate}" <> exemplar $$ resetcounter $$
326+ return $ text ("\\begin{enumerate}" ++ inc) <> exemplar $$ resetcounter $$
267327 vcat items $$ "\\end{enumerate}"
268328blockToLaTeX (DefinitionList lst) = do
329+ incremental <- gets stIncremental
330+ let inc = if incremental then "[<+->]" else ""
269331 items <- mapM defListItemToLaTeX lst
270− return $ "\\begin{description}" $$ vcat items $$ "\\end{description}"
332+ return $ text ("\\begin{description}" ++ inc) $$ vcat items $$ "\\end{description}"
271333blockToLaTeX HorizontalRule = return $
272334 "\\begin{center}\\rule{3in}{0.4pt}\\end{center}" $$ blankline
273335blockToLaTeX (Header level lst) = do