git.iko.soy/typeable/pandoc
on master help sign in
Make --webtex work with the Markdown writer.

Closes #1177. This is a convenient option for people using websites whose Markdown flavors don't provide for math.

commita4294800bfe91976697239ff15c1f87f518df6e8 authorJohn MacFarlane <jgm@berkeley.edu> dateFri 24 Jun 2016, 14:46 (10 years ago) parent5bdf217
2 files changed+19−12
README+2 src/Text/Pandoc/Writers/Markdown.hs+17−12
README+2
@@ -949,6 +949,8 @@ Math rendering in HTML
949949: Render TeX formulas using an external script that converts TeX
950950 formulas to images. The formula will be concatenated with the URL
951951 provided. If *URL* is not specified, the Google Chart API will be used.
952+ Note: the `--webtex` option will affect Markdown output
953+ as well as HTML.
952954
953955`--katex`[`=`*URL*]
954956
src/Text/Pandoc/Writers/Markdown.hs+17−12
@@ -55,6 +55,7 @@ import qualified Data.HashMap.Strict as H
5555import qualified Data.Vector as V
5656import qualified Data.Text as T
5757import qualified Data.Set as Set
58+import Network.HTTP ( urlEncode )
5859
5960type Notes = [[Block]]
6061type Ref = ([Inline], Target, Attr)
@@ -856,18 +857,22 @@ inlineToMarkdown opts (Str str) = do
856857 if stPlain st
857858 then return $ text str
858859 else return $ text $ escapeString opts str
859−inlineToMarkdown opts (Math InlineMath str)
860− | isEnabled Ext_tex_math_dollars opts =
861− return $ "$" <> text str <> "$"
862− | isEnabled Ext_tex_math_single_backslash opts =
863− return $ "\\(" <> text str <> "\\)"
864− | isEnabled Ext_tex_math_double_backslash opts =
865− return $ "\\\\(" <> text str <> "\\\\)"
866− | otherwise = do
867− plain <- gets stPlain
868− inlineListToMarkdown opts $
869− (if plain then makeMathPlainer else id) $
870− texMathToInlines InlineMath str
860+inlineToMarkdown opts (Math InlineMath str) =
861+ case writerHTMLMathMethod opts of
862+ WebTeX url ->
863+ inlineToMarkdown opts (Image nullAttr [Str str]
864+ (url ++ urlEncode str, str))
865+ _ | isEnabled Ext_tex_math_dollars opts ->
866+ return $ "$" <> text str <> "$"
867+ | isEnabled Ext_tex_math_single_backslash opts ->
868+ return $ "\\(" <> text str <> "\\)"
869+ | isEnabled Ext_tex_math_double_backslash opts ->
870+ return $ "\\\\(" <> text str <> "\\\\)"
871+ | otherwise -> do
872+ plain <- gets stPlain
873+ inlineListToMarkdown opts $
874+ (if plain then makeMathPlainer else id) $
875+ texMathToInlines InlineMath str
871876inlineToMarkdown opts (Math DisplayMath str)
872877 | isEnabled Ext_tex_math_dollars opts =
873878 return $ "$$" <> text str <> "$$"