mirror of
https://github.com/jgm/pandoc.git
synced 2026-08-25 17:56:32 +00:00
LaTeX writer: export writeBeamer.
Removed writerBeamer from WriterOptions.
This commit is contained in:
@@ -313,7 +313,6 @@ convertWithOpts opts args = do
|
||||
writerHtmlQTags = htmlQTags,
|
||||
writerTopLevelDivision = topLevelDivision,
|
||||
writerListings = listings,
|
||||
writerBeamer = False,
|
||||
writerSlideLevel = slideLevel,
|
||||
writerHighlightStyle = highlightStyle,
|
||||
writerSetextHeaders = setextHeaders,
|
||||
|
||||
+2
-2
@@ -97,6 +97,7 @@ module Text.Pandoc
|
||||
, writePlain
|
||||
, writeRST
|
||||
, writeLaTeX
|
||||
, writeBeamer
|
||||
, writeConTeXt
|
||||
, writeTexinfo
|
||||
, writeHtml4
|
||||
@@ -304,8 +305,7 @@ writers = [
|
||||
,("opml" , StringWriter writeOPML)
|
||||
,("opendocument" , StringWriter writeOpenDocument)
|
||||
,("latex" , StringWriter writeLaTeX)
|
||||
,("beamer" , StringWriter $ \o ->
|
||||
writeLaTeX o{ writerBeamer = True })
|
||||
,("beamer" , StringWriter writeBeamer)
|
||||
,("context" , StringWriter writeConTeXt)
|
||||
,("texinfo" , StringWriter writeTexinfo)
|
||||
,("man" , StringWriter writeMan)
|
||||
|
||||
@@ -167,7 +167,6 @@ data WriterOptions = WriterOptions
|
||||
, writerUserDataDir :: Maybe FilePath -- ^ Path of user data directory
|
||||
, writerCiteMethod :: CiteMethod -- ^ How to print cites
|
||||
, writerHtmlQTags :: Bool -- ^ Use @<q>@ tags for quotes in HTML
|
||||
, writerBeamer :: Bool -- ^ Produce beamer LaTeX slide show
|
||||
, writerSlideLevel :: Maybe Int -- ^ Force header level of slides
|
||||
, writerTopLevelDivision :: TopLevelDivision -- ^ Type of top-level divisions
|
||||
, writerListings :: Bool -- ^ Use listings package for code
|
||||
@@ -205,7 +204,6 @@ instance Default WriterOptions where
|
||||
, writerUserDataDir = Nothing
|
||||
, writerCiteMethod = Citeproc
|
||||
, writerHtmlQTags = False
|
||||
, writerBeamer = False
|
||||
, writerSlideLevel = Nothing
|
||||
, writerTopLevelDivision = TopLevelDefault
|
||||
, writerListings = False
|
||||
|
||||
@@ -29,7 +29,10 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Conversion of 'Pandoc' format into LaTeX.
|
||||
-}
|
||||
module Text.Pandoc.Writers.LaTeX ( writeLaTeX ) where
|
||||
module Text.Pandoc.Writers.LaTeX (
|
||||
writeLaTeX
|
||||
, writeBeamer
|
||||
) where
|
||||
import Text.Pandoc.Definition
|
||||
import Text.Pandoc.Walk
|
||||
import Text.Pandoc.Shared
|
||||
@@ -76,26 +79,46 @@ data WriterState =
|
||||
, stIncremental :: Bool -- true if beamer lists should be displayed bit by bit
|
||||
, stInternalLinks :: [String] -- list of internal link targets
|
||||
, stUsesEuro :: Bool -- true if euro symbol used
|
||||
, stBeamer :: Bool -- produce beamer
|
||||
}
|
||||
|
||||
startingState :: WriterOptions -> WriterState
|
||||
startingState options = WriterState {
|
||||
stInNote = False
|
||||
, stInQuote = False
|
||||
, stInMinipage = False
|
||||
, stInHeading = False
|
||||
, stNotes = []
|
||||
, stOLLevel = 1
|
||||
, stOptions = options
|
||||
, stVerbInNote = False
|
||||
, stTable = False
|
||||
, stStrikeout = False
|
||||
, stUrl = False
|
||||
, stGraphics = False
|
||||
, stLHS = False
|
||||
, stBook = (case writerTopLevelDivision options of
|
||||
TopLevelPart -> True
|
||||
TopLevelChapter -> True
|
||||
_ -> False)
|
||||
, stCsquotes = False
|
||||
, stHighlighting = False
|
||||
, stIncremental = writerIncremental options
|
||||
, stInternalLinks = []
|
||||
, stUsesEuro = False
|
||||
, stBeamer = False }
|
||||
|
||||
-- | Convert Pandoc to LaTeX.
|
||||
writeLaTeX :: PandocMonad m => WriterOptions -> Pandoc -> m String
|
||||
writeLaTeX options document = return $
|
||||
evalState (pandocToLaTeX options document) $
|
||||
WriterState { stInNote = False, stInQuote = False,
|
||||
stInMinipage = False, stInHeading = False,
|
||||
stNotes = [], stOLLevel = 1,
|
||||
stOptions = options, stVerbInNote = False,
|
||||
stTable = False, stStrikeout = False,
|
||||
stUrl = False, stGraphics = False,
|
||||
stLHS = False,
|
||||
stBook = (case writerTopLevelDivision options of
|
||||
TopLevelPart -> True
|
||||
TopLevelChapter -> True
|
||||
_ -> False),
|
||||
stCsquotes = False, stHighlighting = False,
|
||||
stIncremental = writerIncremental options,
|
||||
stInternalLinks = [], stUsesEuro = False }
|
||||
startingState options
|
||||
|
||||
-- | Convert Pandoc to LaTeX Beamer.
|
||||
writeBeamer :: PandocMonad m => WriterOptions -> Pandoc -> m String
|
||||
writeBeamer options document = return $
|
||||
evalState (pandocToLaTeX options document) $
|
||||
(startingState options){ stBeamer = True }
|
||||
|
||||
pandocToLaTeX :: WriterOptions -> Pandoc -> State WriterState String
|
||||
pandocToLaTeX options (Pandoc meta blocks) = do
|
||||
@@ -144,7 +167,8 @@ pandocToLaTeX options (Pandoc meta blocks) = do
|
||||
else case last blocks' of
|
||||
Header 1 _ il -> (init blocks', il)
|
||||
_ -> (blocks', [])
|
||||
blocks''' <- if writerBeamer options
|
||||
beamer <- gets stBeamer
|
||||
blocks''' <- if beamer
|
||||
then toSlides blocks''
|
||||
else return blocks''
|
||||
body <- mapM (elementToLaTeX options) $ hierarchicalize blocks'''
|
||||
@@ -171,7 +195,7 @@ pandocToLaTeX options (Pandoc meta blocks) = do
|
||||
defField "body" main $
|
||||
defField "title-meta" titleMeta $
|
||||
defField "author-meta" (intercalate "; " authorsMeta) $
|
||||
defField "documentclass" (if writerBeamer options
|
||||
defField "documentclass" (if beamer
|
||||
then ("beamer" :: String)
|
||||
else if stBook st
|
||||
then "book"
|
||||
@@ -186,7 +210,7 @@ pandocToLaTeX options (Pandoc meta blocks) = do
|
||||
defField "book-class" (stBook st) $
|
||||
defField "euro" (stUsesEuro st) $
|
||||
defField "listings" (writerListings options || stLHS st) $
|
||||
defField "beamer" (writerBeamer options) $
|
||||
defField "beamer" beamer $
|
||||
(if stHighlighting st
|
||||
then case writerHighlightStyle options of
|
||||
Just sty ->
|
||||
@@ -388,7 +412,7 @@ blockToLaTeX :: Block -- ^ Block to convert
|
||||
-> State WriterState Doc
|
||||
blockToLaTeX Null = return empty
|
||||
blockToLaTeX (Div (identifier,classes,kvs) bs) = do
|
||||
beamer <- writerBeamer `fmap` gets stOptions
|
||||
beamer <- gets stBeamer
|
||||
ref <- toLabel identifier
|
||||
let linkAnchor = if null identifier
|
||||
then empty
|
||||
@@ -439,7 +463,7 @@ blockToLaTeX (Para [Image attr@(ident, _, _) txt (src,'f':'i':'g':':':tit)]) = d
|
||||
else figure $$ footnotes
|
||||
-- . . . indicates pause in beamer slides
|
||||
blockToLaTeX (Para [Str ".",Space,Str ".",Space,Str "."]) = do
|
||||
beamer <- writerBeamer `fmap` gets stOptions
|
||||
beamer <- gets stBeamer
|
||||
if beamer
|
||||
then blockToLaTeX (RawBlock "latex" "\\pause")
|
||||
else inlineListToLaTeX [Str ".",Space,Str ".",Space,Str "."]
|
||||
@@ -448,7 +472,7 @@ blockToLaTeX (Para lst) =
|
||||
blockToLaTeX (LineBlock lns) = do
|
||||
blockToLaTeX $ linesToPara lns
|
||||
blockToLaTeX (BlockQuote lst) = do
|
||||
beamer <- writerBeamer `fmap` gets stOptions
|
||||
beamer <- gets stBeamer
|
||||
case lst of
|
||||
[b] | beamer && isListBlock b -> do
|
||||
oldIncremental <- gets stIncremental
|
||||
@@ -527,7 +551,7 @@ blockToLaTeX (RawBlock f x)
|
||||
blockToLaTeX (BulletList []) = return empty -- otherwise latex error
|
||||
blockToLaTeX (BulletList lst) = do
|
||||
incremental <- gets stIncremental
|
||||
beamer <- writerBeamer `fmap` gets stOptions
|
||||
beamer <- gets stBeamer
|
||||
let inc = if beamer && incremental then "[<+->]" else ""
|
||||
items <- mapM listItemToLaTeX lst
|
||||
let spacing = if isTightList lst
|
||||
@@ -772,7 +796,8 @@ sectionHeader unnumbered ident level lst = do
|
||||
let topLevelDivision = if book && writerTopLevelDivision opts == TopLevelDefault
|
||||
then TopLevelChapter
|
||||
else writerTopLevelDivision opts
|
||||
let level' = if writerBeamer opts &&
|
||||
beamer <- gets stBeamer
|
||||
let level' = if beamer &&
|
||||
topLevelDivision `elem` [TopLevelPart, TopLevelChapter]
|
||||
-- beamer has parts but no chapters
|
||||
then if level == 1 then -1 else level - 1
|
||||
@@ -1022,9 +1047,9 @@ inlineToLaTeX (Note contents) = do
|
||||
(CodeBlock _ _ : _) -> cr
|
||||
_ -> empty
|
||||
let noteContents = nest 2 contents' <> optnl
|
||||
opts <- gets stOptions
|
||||
beamer <- gets stBeamer
|
||||
-- in beamer slides, display footnote from current overlay forward
|
||||
let beamerMark = if writerBeamer opts
|
||||
let beamerMark = if beamer
|
||||
then text "<.->"
|
||||
else empty
|
||||
modify $ \st -> st{ stNotes = noteContents : stNotes st }
|
||||
|
||||
@@ -16,6 +16,9 @@ latexListing = latexWithOpts def{ writerListings = True }
|
||||
latexWithOpts :: (ToPandoc a) => WriterOptions -> a -> String
|
||||
latexWithOpts opts = purely (writeLaTeX opts) . toPandoc
|
||||
|
||||
beamerWithOpts :: (ToPandoc a) => WriterOptions -> a -> String
|
||||
beamerWithOpts opts = purely (writeBeamer opts) . toPandoc
|
||||
|
||||
{-
|
||||
"my test" =: X =?> Y
|
||||
|
||||
@@ -95,8 +98,7 @@ tests = [ testGroup "code blocks"
|
||||
beamerTopLevelDiv :: (ToPandoc a)
|
||||
=> TopLevelDivision -> a -> String
|
||||
beamerTopLevelDiv division =
|
||||
latexWithOpts def { writerTopLevelDivision = division
|
||||
, writerBeamer = True }
|
||||
beamerWithOpts def { writerTopLevelDivision = division }
|
||||
in
|
||||
[ test (latexTopLevelDiv TopLevelSection)
|
||||
"sections as top-level" $ headers =?>
|
||||
|
||||
Reference in New Issue
Block a user