summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2022-09-29 09:31:39 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2022-09-29 09:31:39 -0700
commit1393037f4eb04ebad849d79b53a8b3e354aa0bdb (patch)
tree42455e86436d033fe42f4d320a3d889e8c37a87f /src
parent7aaecc6ae18c5e7b07f49bd87ba434c9c198d322 (diff)
LaTeX writer: use `\includesvg` for SVGs...
...and include the `svg` package. Closes #8334.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Writers/LaTeX.hs8
-rw-r--r--src/Text/Pandoc/Writers/LaTeX/Types.hs2
2 files changed, 8 insertions, 2 deletions
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