Created
November 9, 2017 15:36
-
-
Save shreevatsa/7be352a692fef4cdccc76d03b9f12bf8 to your computer and use it in GitHub Desktop.
Simpler (slower) version of pandoc-tex2svg.hs, without caching
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.