diff options
| author | John MacFarlane <jgm@berkeley.edu> | 2022-09-29 09:31:39 -0700 |
|---|---|---|
| committer | John MacFarlane <jgm@berkeley.edu> | 2022-09-29 09:31:39 -0700 |
| commit | 1393037f4eb04ebad849d79b53a8b3e354aa0bdb (patch) | |
| tree | 42455e86436d033fe42f4d320a3d889e8c37a87f | |
| parent | 7aaecc6ae18c5e7b07f49bd87ba434c9c198d322 (diff) | |
LaTeX writer: use `\includesvg` for SVGs...
...and include the `svg` package.
Closes #8334.
| -rw-r--r-- | data/templates/default.latex | 3 | ||||
| -rw-r--r-- | src/Text/Pandoc/Writers/LaTeX.hs | 8 | ||||
| -rw-r--r-- | src/Text/Pandoc/Writers/LaTeX/Types.hs | 2 |
3 files changed, 11 insertions, 2 deletions
diff --git a/data/templates/default.latex b/data/templates/default.latex index e3b54ec4a..7b02262a3 100644 --- a/data/templates/default.latex +++ b/data/templates/default.latex @@ -270,6 +270,9 @@ $if(graphics)$ \def\fps@figure{htbp} \makeatother $endif$ +$if(svg)$ +\usepackage{svg} +$endif$ $if(strikeout)$ $-- also used for underline \usepackage[normalem]{ulem} diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs index cd1f59056..31dff78bf 100644 --- a/src/Text/Pandoc/Writers/LaTeX.hs +++ b/src/Text/Pandoc/Writers/LaTeX.hs @@ -165,6 +165,7 @@ pandocToLaTeX options (Pandoc meta blocks) = do defField "numbersections" (writerNumberSections options) $ defField "lhs" (stLHS st) $ defField "graphics" (stGraphics st) $ + defField "svg" (stSVG st) $ defField "has-chapters" (stHasChapters st) $ defField "has-frontmatter" (documentClass `elem` frontmatterClasses) $ defField "listings" (writerListings options || stLHS st) $ @@ -934,7 +935,9 @@ inlineToLaTeX il@(Image _ _ (src, _)) return empty inlineToLaTeX (Image attr@(_,_,kvs) _ (source, _)) = do setEmptyLine False - modify $ \s -> s{ stGraphics = True } + let isSVG = ".svg" `T.isSuffixOf` source || ".SVG" `T.isSuffixOf` source + modify $ \s -> s{ stGraphics = True + , stSVG = stSVG s || isSVG } opts <- gets stOptions let showDim dir = let d = text (show dir) <> "=" in case dimension dir attr of @@ -968,7 +971,8 @@ inlineToLaTeX (Image attr@(_,_,kvs) _ (source, _)) = do source'' <- stringToLaTeX URLString source' inHeading <- gets stInHeading return $ - (if inHeading then "\\protect\\includegraphics" else "\\includegraphics") <> + (if inHeading then "\\protect" else "") <> + (if isSVG then "\\includesvg" else "\\includegraphics") <> options <> braces (literal source'') inlineToLaTeX (Note contents) = do setEmptyLine False diff --git a/src/Text/Pandoc/Writers/LaTeX/Types.hs b/src/Text/Pandoc/Writers/LaTeX/Types.hs index c06b7e923..ff5b22cad 100644 --- a/src/Text/Pandoc/Writers/LaTeX/Types.hs +++ b/src/Text/Pandoc/Writers/LaTeX/Types.hs @@ -35,6 +35,7 @@ data WriterState = , stStrikeout :: Bool -- ^ true if document has strikeout , stUrl :: Bool -- ^ true if document has visible URL link , stGraphics :: Bool -- ^ true if document contains images + , stSVG :: Bool -- ^ true if document contains SVGs , stLHS :: Bool -- ^ true if document has literate haskell code , stHasChapters :: Bool -- ^ true if document has chapters , stCsquotes :: Bool -- ^ true if document uses csquotes @@ -66,6 +67,7 @@ startingState options = , stStrikeout = False , stUrl = False , stGraphics = False + , stSVG = False , stLHS = False , stHasChapters = case writerTopLevelDivision options of TopLevelPart -> True |
