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.
This commit is contained in:
John MacFarlane 2016-06-24 14:46:47 -07:00
parent 5bdf217135
commit a4294800bf
2 changed files with 19 additions and 12 deletions

2
README
View file

@ -949,6 +949,8 @@ Math rendering in HTML
: Render TeX formulas using an external script that converts TeX
formulas to images. The formula will be concatenated with the URL
provided. If *URL* is not specified, the Google Chart API will be used.
Note: the `--webtex` option will affect Markdown output
as well as HTML.
`--katex`[`=`*URL*]

View file

@ -55,6 +55,7 @@ import qualified Data.HashMap.Strict as H
import qualified Data.Vector as V
import qualified Data.Text as T
import qualified Data.Set as Set
import Network.HTTP ( urlEncode )
type Notes = [[Block]]
type Ref = ([Inline], Target, Attr)
@ -856,18 +857,22 @@ inlineToMarkdown opts (Str str) = do
if stPlain st
then return $ text str
else return $ text $ escapeString opts str
inlineToMarkdown opts (Math InlineMath str)
| isEnabled Ext_tex_math_dollars opts =
return $ "$" <> text str <> "$"
| isEnabled Ext_tex_math_single_backslash opts =
return $ "\\(" <> text str <> "\\)"
| isEnabled Ext_tex_math_double_backslash opts =
return $ "\\\\(" <> text str <> "\\\\)"
| otherwise = do
plain <- gets stPlain
inlineListToMarkdown opts $
(if plain then makeMathPlainer else id) $
texMathToInlines InlineMath str
inlineToMarkdown opts (Math InlineMath str) =
case writerHTMLMathMethod opts of
WebTeX url ->
inlineToMarkdown opts (Image nullAttr [Str str]
(url ++ urlEncode str, str))
_ | isEnabled Ext_tex_math_dollars opts ->
return $ "$" <> text str <> "$"
| isEnabled Ext_tex_math_single_backslash opts ->
return $ "\\(" <> text str <> "\\)"
| isEnabled Ext_tex_math_double_backslash opts ->
return $ "\\\\(" <> text str <> "\\\\)"
| otherwise -> do
plain <- gets stPlain
inlineListToMarkdown opts $
(if plain then makeMathPlainer else id) $
texMathToInlines InlineMath str
inlineToMarkdown opts (Math DisplayMath str)
| isEnabled Ext_tex_math_dollars opts =
return $ "$$" <> text str <> "$$"