@@ -41,6 +41,7 @@ import Data.Char ( toLower, isPunctuation )
4141import Control.Monad.State
4242import Text.Pandoc.Pretty
4343import System.FilePath (dropExtension)
44+import Text.Pandoc.Slides
4445import Text.Pandoc.Highlighting (highlight, styleToLaTeX,
4546 formatLaTeXInline, formatLaTeXBlock)
4647
@@ -62,7 +63,6 @@ data WriterState =
6263 , stBook :: Bool -- true if document uses book or memoir class
6364 , stCsquotes :: Bool -- true if document uses csquotes
6465 , stHighlighting :: Bool -- true if document has highlighted code
65− , stFirstFrame :: Bool -- true til we've written first beamer frame
6666 , stIncremental :: Bool -- true if beamer lists should be displayed bit by bit
6767 , stInternalLinks :: [String] -- list of internal link targets
6868 }
@@ -78,7 +78,7 @@ writeLaTeX options document =
7878 stUrl = False, stGraphics = False,
7979 stLHS = False, stBook = writerChapters options,
8080 stCsquotes = False, stHighlighting = False,
81− stFirstFrame = True, stIncremental = writerIncremental options,
81+ stIncremental = writerIncremental options,
8282 stInternalLinks = [] }
8383
8484pandocToLaTeX :: WriterOptions -> Pandoc -> State WriterState String
@@ -200,34 +200,22 @@ inCmd :: String -> Doc -> Doc
200200inCmd cmd contents = char '\\' <> text cmd <> braces contents
201201
202202toSlides :: [Block] -> State WriterState [Block]
203−toSlides (Header n ils : bs) = do
204− tit <- inlineListToLaTeX ils
205− firstFrame <- gets stFirstFrame
206− modify $ \s -> s{ stFirstFrame = False }
203+toSlides bs = concat `fmap` (mapM slideToBeamer $ toSlideElements bs)
204+
205+slideToBeamer :: SlideElement -> State WriterState [Block]
206+slideToBeamer (SectionSlide lvl tit) = return [Header lvl tit]
207+slideToBeamer (ContentSlide tit bs) = do
208+ tit' <- inlineListToLaTeX tit
207209 -- note: [fragile] is required or verbatim breaks
208− result <- ((Header n ils :) .
209− (RawBlock "latex" ("\\begin{frame}[fragile]\n" ++
210− "\\frametitle{" ++ render Nothing tit ++ "}") :))
211− `fmap` toSlides bs
212− if firstFrame
213− then return result
214− else return $ RawBlock "latex" "\\end{frame}" : result
215−toSlides (HorizontalRule : Header n ils : bs) =
216− toSlides (Header n ils : bs)
217−toSlides (HorizontalRule : bs) = do
218− firstFrame <- gets stFirstFrame
219− modify $ \s -> s{ stFirstFrame = False }
220− result <- (RawBlock "latex" "\\begin{frame}[fragile]" :)
221− `fmap` toSlides bs
222− if firstFrame
223− then return result
224− else return $ RawBlock "latex" "\\end{frame}" : result
225−toSlides (b:bs) = (b:) `fmap` toSlides bs
226−toSlides [] = do
227− firstFrame <- gets stFirstFrame
228− if firstFrame
229− then return []
230− else return [RawBlock "latex" "\\end{frame}"]
210+ let slideStart = RawBlock "latex" ("\\begin{frame}[fragile]\n" ++
211+ "\\frametitle{" ++ render Nothing tit' ++ "}")
212+ let slideEnd = RawBlock "latex" "\\end{frame}"
213+ -- now carve up slide into blocks if there are sections inside
214+ let eltToBlocks (Blk b) = [b]
215+ eltToBlocks (Sec _ _ _ lab xs) =
216+ Para (RawInline "latex" "\\begin{block}{" : lab ++ [RawInline "latex" "}"])
217+ : concatMap eltToBlocks xs ++ [RawBlock "latex" "\\end{block}"]
218+ return $ slideStart : concatMap eltToBlocks (hierarchicalize bs) ++ [slideEnd]
231219
232220isListBlock :: Block -> Bool
233221isListBlock (BulletList _) = True