add latexCfgChunks

This commit is contained in:
Krantz-XRF 2020-10-11 16:40:17 +08:00 committed by David Himmelstrup
commit 9944af167e

View file

@ -109,17 +109,23 @@ someTexWithHeaders engine exec dvi args headers postscript tex =
where where
script = mkTexScript exec args headers (T.unlines (postscript ++ [tex])) script = mkTexScript exec args headers (T.unlines (postscript ++ [tex]))
-- | Invoke latex and separate results. -- | Invoke latex using a given configuration and separate results.
latexChunks :: [T.Text] -> [Tree] latexCfgChunks :: TexConfig -> [T.Text] -> [Tree]
latexChunks chunks | pNoExternals = map mkText chunks latexCfgChunks _cfg chunks | pNoExternals = map mkText chunks
latexChunks chunks = worker (svgGlyphs $ latex $ T.concat chunks) chunks latexCfgChunks cfg chunks = worker chunks $ svgGlyphs $ tex $ T.concat chunks
where where
tex = latexCfg cfg
merge lst = mkGroup [fmt svg | (fmt, _, svg) <- lst] merge lst = mkGroup [fmt svg | (fmt, _, svg) <- lst]
worker [] [] = [] worker [] [] = []
worker _ [] = error "latex chunk mismatch" worker [] _ = error "latex chunk mismatch"
worker everything (x : xs) = worker (x : xs) everything =
let width = length $ svgGlyphs (latex x) let width = length $ svgGlyphs (tex x)
in merge (take width everything) : worker (drop width everything) xs (first, rest) = splitAt width everything
in merge first : worker xs rest
-- | Invoke latex and separate results.
latexChunks :: [T.Text] -> [Tree]
latexChunks = latexCfgChunks (TexConfig LaTeX [] [])
-- | Invoke xelatex and import the result as an SVG object. SVG objects are -- | Invoke xelatex and import the result as an SVG object. SVG objects are
-- cached to improve performance. Xelatex has support for non-western scripts. -- cached to improve performance. Xelatex has support for non-western scripts.