Skip to content

Instantly share code, notes, and snippets.

@mpickering
Created December 7, 2014 00:53
Show Gist options
  • Save mpickering/f1718fcdc4c56273ed52 to your computer and use it in GitHub Desktop.
Save mpickering/f1718fcdc4c56273ed52 to your computer and use it in GitHub Desktop.
LaTeX Argument Parser
{-# LANGUAGE ViewPatterns #-}
module InTex where
import Text.Pandoc.JSON
import Text.Pandoc
import Data.List
main :: IO ()
main = toJSONFilter readFootnotes
readFootnotes :: Inline -> Inline
readFootnotes (footnoteText -> Just args) = RawInline (Format "tex") res
where
parsed = writeLaTeX def . readMarkdown def
res = fnString ++ parsed args ++ "}"
readFootnotes i = i
fnString = "\\footnotetext{"
footnoteText :: Inline -> Maybe String
footnoteText (RawInline (Format "tex") s) =
if fnString `isPrefixOf` s
then Just . init . drop (length fnString) $ s -- Remove closing brace
else Nothing
footnoteText x = Nothing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment