From 76a4e7127be1116b67ae531f56aadb05963813b5 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Fri, 14 May 2021 10:09:02 -0700 Subject: Beamer writer: support exampleblock and alertblock. A block will be rendered as an exampleblock if the heading has class `example` and alertblock if it has class `alert`. Closes #7278. --- MANUAL.txt | 6 +++++- src/Text/Pandoc/Writers/LaTeX.hs | 11 ++++++++--- test/command/7278.md | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 test/command/7278.md diff --git a/MANUAL.txt b/MANUAL.txt index 6f06d1e8a..cdfb0e332 100644 --- a/MANUAL.txt +++ b/MANUAL.txt @@ -5666,7 +5666,11 @@ rules: * A heading at the slide level always starts a new slide. * Headings *below* the slide level in the hierarchy create - headings *within* a slide. + headings *within* a slide. (In beamer, a "block" will be + created. If the heading has the class `example`, an + `exampleblock` environment will be used; if it has the class + `alert`, an `alertblock` will be used; otherwise a regular + `block` will be used.) * Headings *above* the slide level in the hierarchy create "title slides," which just contain the section title diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs index 8b1f3df1d..d8722876e 100644 --- a/src/Text/Pandoc/Writers/LaTeX.hs +++ b/src/Text/Pandoc/Writers/LaTeX.hs @@ -290,7 +290,12 @@ blockToLaTeX :: PandocMonad m => Block -- ^ Block to convert -> LW m (Doc Text) blockToLaTeX Null = return empty -blockToLaTeX (Div attr@(identifier,"block":_,_) (Header _ _ ils : bs)) = do +blockToLaTeX (Div attr@(identifier,"block":dclasses,_) + (Header _ _ ils : bs)) = do + let blockname + | "example" `elem` dclasses = "exampleblock" + | "alert" `elem` dclasses = "alertblock" + | otherwise = "block" ref <- toLabel identifier let anchor = if T.null identifier then empty @@ -298,8 +303,8 @@ blockToLaTeX (Div attr@(identifier,"block":_,_) (Header _ _ ils : bs)) = do braces (literal ref) <> braces empty title' <- inlineListToLaTeX ils contents <- blockListToLaTeX bs - wrapDiv attr $ ("\\begin{block}" <> braces title' <> anchor) $$ - contents $$ "\\end{block}" + wrapDiv attr $ ("\\begin" <> braces blockname <> braces title' <> anchor) $$ + contents $$ "\\end" <> braces blockname blockToLaTeX (Div (identifier,"slide":dclasses,dkvs) (Header _ (_,hclasses,hkvs) ils : bs)) = do -- note: [fragile] is required or verbatim breaks diff --git a/test/command/7278.md b/test/command/7278.md new file mode 100644 index 000000000..dcf71c29f --- /dev/null +++ b/test/command/7278.md @@ -0,0 +1,38 @@ +``` +% pandoc -t beamer +# Slide + +Some blocks: + +## example block title {.example} + +text in block + +## alert block title {.alert} + +text in block + +## block title + +text in block +^D +\begin{frame}{Slide} +\protect\hypertarget{slide}{} +Some blocks: + +\begin{exampleblock}{example block title} +\protect\hypertarget{example-block-title}{} +text in block +\end{exampleblock} + +\begin{alertblock}{alert block title} +\protect\hypertarget{alert-block-title}{} +text in block +\end{alertblock} + +\begin{block}{block title} +\protect\hypertarget{block-title}{} +text in block +\end{block} +\end{frame} +``` -- cgit v1.2.3