mirror of
https://github.com/reanimate/reanimate.git
synced 2026-09-14 09:32:22 +00:00
Parse the SVG file output from latex.
This commit is contained in:
parent
8cc7e76efc
commit
3483413e07
2 changed files with 27 additions and 19 deletions
|
|
@ -23,7 +23,7 @@ library
|
|||
Reanimate.LaTeX
|
||||
build-depends: base >=4.12 && <4.13,
|
||||
lucid-svg, time, text, unix, lucid, filepath, process, directory,
|
||||
containers
|
||||
containers, svg-tree, xml, bytestring
|
||||
|
||||
executable reanimate-viewer
|
||||
main-is: SvgViewer.hs
|
||||
|
|
@ -35,6 +35,7 @@ executable reanimate-viewer
|
|||
Reanimate.LaTeX
|
||||
build-depends: base >=4.12 && <4.13, cairo >=0.13 && <0.14, gtk,
|
||||
svgcairo, lucid-svg, time, text, unix, lucid, reanimate,
|
||||
filepath, process, directory, containers
|
||||
filepath, process, directory, containers, svg-tree, xml,
|
||||
bytestring
|
||||
hs-source-dirs: src
|
||||
default-language: Haskell2010
|
||||
|
|
|
|||
|
|
@ -1,18 +1,24 @@
|
|||
{-# LANGUAGE ScopedTypeVariables, OverloadedStrings #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
{-# LANGUAGE ScopedTypeVariables #-}
|
||||
module Reanimate.LaTeX (latex) where
|
||||
|
||||
import Data.IORef
|
||||
import qualified Data.Map as Map
|
||||
import Data.Map (Map)
|
||||
import System.Process
|
||||
import System.Exit
|
||||
import System.IO
|
||||
import System.IO.Unsafe
|
||||
import System.FilePath
|
||||
import System.Directory
|
||||
import Control.Exception
|
||||
import Lucid (toHtmlRaw, toHtml)
|
||||
import Lucid.Svg (Svg, text_, font_size_, fill_)
|
||||
import Control.Exception
|
||||
import qualified Data.ByteString as B
|
||||
import Data.IORef
|
||||
import Data.Map (Map)
|
||||
import qualified Data.Map as Map
|
||||
import Lucid (toHtml, toHtmlRaw)
|
||||
import Lucid.Svg (Svg, fill_, font_size_, text_)
|
||||
import System.Directory
|
||||
import System.Exit
|
||||
import System.FilePath
|
||||
import System.IO
|
||||
import System.IO.Unsafe
|
||||
import System.Process
|
||||
|
||||
import Graphics.Svg (loadSvgFile, parseSvgFile,
|
||||
xmlOfDocument)
|
||||
import Text.XML.Light.Output (ppcElement, prettyConfigPP)
|
||||
|
||||
{-# NOINLINE cache #-}
|
||||
cache :: IORef (Map String (Svg ()))
|
||||
|
|
@ -43,9 +49,10 @@ latexToSVG tex = handle (\(e::SomeException) -> return (failedSvg tex)) $ do
|
|||
, "--bbox=1,1" -- increase bbox size.
|
||||
, "--no-fonts" -- use glyphs instead of fonts.
|
||||
,"--verbosity=0", "-o",svg_file]
|
||||
svg_data <- readFile svg_file
|
||||
evaluate (length svg_data)
|
||||
return $ toHtmlRaw $ unlines $ drop 1 $ lines svg_data
|
||||
svg_data <- B.readFile svg_file
|
||||
case parseSvgFile svg_file svg_data of
|
||||
Nothing -> error "Malformed svg"
|
||||
Just svg -> return $ toHtmlRaw $ ppcElement prettyConfigPP (xmlOfDocument svg)
|
||||
|
||||
failedSvg :: String -> Svg ()
|
||||
failedSvg tex =
|
||||
|
|
@ -82,7 +89,7 @@ requireExecutable :: String -> IO FilePath
|
|||
requireExecutable exec = do
|
||||
mbPath <- findExecutable exec
|
||||
case mbPath of
|
||||
Nothing -> error $ "Couldn't find executable: " ++ exec
|
||||
Nothing -> error $ "Couldn't find executable: " ++ exec
|
||||
Just path -> return path
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue