git.iko.soy/typeable/pandoc
on master help sign in
Use texmath 0.7 interface.
commit40d8100d440dd7924068d027e052f5a3de65e70f authorJohn MacFarlane <jgm@berkeley.edu> dateMon 4 Aug 2014, 11:13 (12 years ago) parent4630cff
8 files changed+32−24
src/Text/Pandoc/Parsing.hs+2−1 src/Text/Pandoc/Readers/HTML.hs+2−2 src/Text/Pandoc/Readers/Org.hs+5−2 src/Text/Pandoc/Readers/TeXMath.hs+4−3 src/Text/Pandoc/Writers/Docbook.hs+8−7 src/Text/Pandoc/Writers/Docx.hs+2−2 src/Text/Pandoc/Writers/HTML.hs+7−6 src/Text/Pandoc/Writers/ODT.hs+2−1
src/Text/Pandoc/Parsing.hs+2−1
@@ -178,7 +178,8 @@ import Data.Char ( toLower, toUpper, ord, chr, isAscii, isAlphaNum,
178178import Data.List ( intercalate, transpose )
179179import Text.Pandoc.Shared
180180import qualified Data.Map as M
181−import Text.TeXMath.Macros (applyMacros, Macro, parseMacroDefinitions)
181+import Text.TeXMath.Readers.TeX.Macros (applyMacros, Macro,
182+ parseMacroDefinitions)
182183import Text.Pandoc.Compat.TagSoupEntity ( lookupEntity )
183184import Text.Pandoc.Asciify (toAsciiChar)
184185import Data.Default
src/Text/Pandoc/Readers/HTML.hs+2−2
@@ -57,7 +57,7 @@ import Control.Applicative ( (<$>), (<$), (<*), (*>), (<|>))
5757import Data.Monoid (mconcat, Monoid, mempty, (<>), First (..))
5858import Text.Printf (printf)
5959import Debug.Trace (trace)
60−import Text.TeXMath (readMathML, writeTeXMath)
60+import Text.TeXMath (readMathML, writeTeX)
6161import Data.Default (Default (..), def)
6262import Control.Monad.Reader (Reader,ask, asks, local, runReader)
6363
@@ -572,7 +572,7 @@ pRawHtmlInline = do
572572 else return mempty
573573
574574mathMLToTeXMath :: String -> Either String String
575−mathMLToTeXMath s = writeTeXMath <$> readMathML s
575+mathMLToTeXMath s = writeTeX <$> readMathML s
576576
577577pMath :: Bool -> TagParser Inlines
578578pMath inCase = try $ do
src/Text/Pandoc/Readers/Org.hs+5−2
@@ -41,7 +41,7 @@ import Text.Pandoc.Parsing hiding ( F, unF, askF, asksF, runF
4141 )
4242import Text.Pandoc.Readers.LaTeX (inlineCommand, rawLaTeXInline)
4343import Text.Pandoc.Shared (compactify', compactify'DL)
44−import Text.TeXMath (texMathToPandoc, DisplayType(..))
44+import Text.TeXMath (readTeX, writePandoc, DisplayType(..))
4545
4646import Control.Applicative ( Applicative, pure
4747 , (<$>), (<$), (<*>), (<*), (*>) )
@@ -1383,7 +1383,7 @@ inlineLaTeX = try $ do
13831383 maybe mzero returnF $ parseAsMath cmd `mplus` parseAsInlineLaTeX cmd
13841384 where
13851385 parseAsMath :: String -> Maybe Inlines
1386− parseAsMath cs = maybeRight $ B.fromList <$> texMathToPandoc DisplayInline cs
1386+ parseAsMath cs = B.fromList <$> texMathToPandoc cs
13871387
13881388 parseAsInlineLaTeX :: String -> Maybe Inlines
13891389 parseAsInlineLaTeX cs = maybeRight $ runParser inlineCommand state "" cs
@@ -1391,6 +1391,9 @@ inlineLaTeX = try $ do
13911391 state :: ParserState
13921392 state = def{ stateOptions = def{ readerParseRaw = True }}
13931393
1394+ texMathToPandoc inp = (maybeRight $ readTeX inp) >>=
1395+ writePandoc DisplayInline
1396+
13941397maybeRight :: Either a b -> Maybe b
13951398maybeRight = either (const Nothing) Just
13961399
src/Text/Pandoc/Readers/TeXMath.hs+4−3
@@ -38,9 +38,10 @@ import Text.TeXMath
3838texMathToInlines :: MathType
3939 -> String -- ^ String to parse (assumes @'\n'@ line endings)
4040 -> [Inline]
41−texMathToInlines mt inp = case texMathToPandoc dt inp of
42− Left _ -> [Str (delim ++ inp ++ delim)]
43− Right res -> res
41+texMathToInlines mt inp =
42+ case writePandoc dt `fmap` readTeX inp of
43+ Right (Just ils) -> ils
44+ _ -> [Str (delim ++ inp ++ delim)]
4445 where (dt, delim) = case mt of
4546 DisplayMath -> (DisplayBlock, "$$")
4647 InlineMath -> (DisplayInline, "$")
src/Text/Pandoc/Writers/Docbook.hs+8−7
@@ -39,6 +39,7 @@ import Text.Pandoc.Templates (renderTemplate')
3939import Text.Pandoc.Readers.TeXMath
4040import Data.List ( isPrefixOf, intercalate, isSuffixOf )
4141import Data.Char ( toLower )
42+import Control.Applicative ((<$>))
4243import Data.Monoid ( Any(..) )
4344import Text.Pandoc.Highlighting ( languages, languagesByExtension )
4445import Text.Pandoc.Pretty
@@ -293,13 +294,13 @@ inlineToDocbook _ (Code _ str) =
293294 inTagsSimple "literal" $ text (escapeStringForXML str)
294295inlineToDocbook opts (Math t str)
295296 | isMathML (writerHTMLMathMethod opts) =
296− case texMathToMathML dt str of
297− Right r -> inTagsSimple tagtype
298− $ text $ Xml.ppcElement conf
299− $ fixNS
300− $ removeAttr r
301− Left _ -> inlinesToDocbook opts
302− $ texMathToInlines t str
297+ case writeMathML dt <$> readTeX str of
298+ Right r -> inTagsSimple tagtype
299+ $ text $ Xml.ppcElement conf
300+ $ fixNS
301+ $ removeAttr r
302+ Left _ -> inlinesToDocbook opts
303+ $ texMathToInlines t str
303304 | otherwise = inlinesToDocbook opts $ texMathToInlines t str
304305 where (dt, tagtype) = case t of
305306 InlineMath -> (DisplayInline,"inlineequation")
src/Text/Pandoc/Writers/Docx.hs+2−2
@@ -58,7 +58,7 @@ import System.Random (randomRIO)
5858import Text.Printf (printf)
5959import qualified Control.Exception as E
6060import Text.Pandoc.MIME (getMimeType, extensionFromMimeType)
61−import Control.Applicative ((<|>))
61+import Control.Applicative ((<|>), (<$>))
6262import Data.Maybe (mapMaybe)
6363
6464data ListMarker = NoMarker
@@ -767,7 +767,7 @@ inlineToOpenXML opts (Math mathType str) = do
767767 let displayType = if mathType == DisplayMath
768768 then DisplayBlock
769769 else DisplayInline
770− case texMathToOMML displayType str of
770+ case writeOMML displayType <$> readTeX str of
771771 Right r -> return [r]
772772 Left _ -> inlinesToOpenXML opts (texMathToInlines mathType str)
773773inlineToOpenXML opts (Cite _ lst) = inlinesToOpenXML opts lst
src/Text/Pandoc/Writers/HTML.hs+7−6
@@ -63,6 +63,7 @@ import Text.XML.Light.Output
6363import System.FilePath (takeExtension)
6464import Data.Monoid
6565import Data.Aeson (Value)
66+import Control.Applicative ((<$>))
6667
6768data WriterState = WriterState
6869 { stNotes :: [Html] -- ^ List of notes
@@ -700,12 +701,12 @@ inlineToHtml opts inline =
700701 else DisplayBlock
701702 let conf = useShortEmptyTags (const False)
702703 defaultConfigPP
703− case texMathToMathML dt str of
704− Right r -> return $ preEscapedString $
705− ppcElement conf r
706− Left _ -> inlineListToHtml opts
707− (texMathToInlines t str) >>= return .
708− (H.span ! A.class_ "math")
704+ case writeMathML dt <$> readTeX str of
705+ Right r -> return $ preEscapedString $
706+ ppcElement conf r
707+ Left _ -> inlineListToHtml opts
708+ (texMathToInlines t str) >>=
709+ return . (H.span ! A.class_ "math")
709710 MathJax _ -> return $ H.span ! A.class_ "math" $ toHtml $
710711 case t of
711712 InlineMath -> "\\(" ++ str ++ "\\)"
src/Text/Pandoc/Writers/ODT.hs+2−1
@@ -37,6 +37,7 @@ import Text.TeXMath
3737import qualified Data.ByteString.Lazy as B
3838import Text.Pandoc.UTF8 ( fromStringLazy )
3939import Codec.Archive.Zip
40+import Control.Applicative ((<$>))
4041import Text.Pandoc.Options ( WriterOptions(..) )
4142import Text.Pandoc.Shared ( stringify, readDataFile, fetchItem', warn )
4243import Text.Pandoc.ImageSize ( imageSize, sizeInPoints )
@@ -150,7 +151,7 @@ transformPicMath opts entriesRef (Image lab (src,_)) = do
150151transformPicMath _ entriesRef (Math t math) = do
151152 entries <- readIORef entriesRef
152153 let dt = if t == InlineMath then DisplayInline else DisplayBlock
153− case texMathToMathML dt math of
154+ case writeMathML dt <$> readTeX math of
154155 Left _ -> return $ Math t math
155156 Right r -> do
156157 let conf = useShortEmptyTags (const False) defaultConfigPP