Skip to content

Instantly share code, notes, and snippets.

@shreevatsa
Created November 9, 2017 15:36
Show Gist options
  • Save shreevatsa/7be352a692fef4cdccc76d03b9f12bf8 to your computer and use it in GitHub Desktop.
Save shreevatsa/7be352a692fef4cdccc76d03b9f12bf8 to your computer and use it in GitHub Desktop.
Simpler (slower) version of pandoc-tex2svg.hs, without caching
{-# LANGUAGE ScopedTypeVariables #-}
module Main where
import Text.Pandoc.JSON
import Control.Monad (when)
import System.Exit
import System.Process
import System.Directory (findExecutable)
import System.IO (stderr, hPutStrLn)
main :: IO ()
main = toJSONFilter tex2svg
tex2svg :: Inline -> IO Inline
tex2svg (Math mt math) = do
mbfp <- findExecutable "tex2svg"
when (mbfp == Nothing) $ do
hPutStrLn stderr $ "The tex2svg program was not found in the path.\n" ++
"Install MathJax-node (https://github.com/mathjax/MathJax-node)\n" ++
"and ensure that tex2svg is in your path."
exitWith $ ExitFailure 1
svg <- readProcess "tex2svg" (["--inline" | mt == InlineMath] ++ [math]) ""
if null svg -- indicates an error -- tex2svg doesn't return error status
then do
hPutStrLn stderr $ "Could not convert: " ++ math
return $ Math mt math
else return $ RawInline (Format "html") $
"<span class=\"math " ++
(if mt == InlineMath then "inline" else "display") ++ "\">" ++
svg ++ "</span>"
tex2svg il = return il
@shreevatsa
Copy link
Author

Based on https://github.com/jgm/pandoc-tex2svg/blob/f415448/pandoc-tex2svg.hs but with caching removed. For jgm/pandoc#3153 — removing the caching so that it's easier to measure how long this takes, for input without repetition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment