git.iko.soy/typeable/pandoc
on master help sign in
Added --webtex option for HTML math.
57a91f3John MacFarlane
README+22−8
@@ -351,8 +351,8 @@ For further documentation, see the `pandoc(1)` man page.
351 directly; this provides portability at the price of efficiency. If
351 directly; this provides portability at the price of efficiency. If
352 you plan to use math on several pages, it is much better to link to
352 you plan to use math on several pages, it is much better to link to
353 a copy of `LaTeXMathML.js`, which can be cached. (See `--jsmath`,
353 a copy of `LaTeXMathML.js`, which can be cached. (See `--jsmath`,
354− `--gladtex`, and `--mimetex` for alternative ways of dealing with
354+ `--gladtex`, `--webtex`, and `--mimetex` for alternative ways of
355− math in HTML.)
355+ dealing with math in HTML.)
356
356
357`--mathml`
357`--mathml`
358: causes `pandoc` to convert all TeX math to MathML.
358: causes `pandoc` to convert all TeX math to MathML.
@@ -364,21 +364,29 @@ For further documentation, see the `pandoc(1)` man page.
364 TeX math in HTML, Slidy, or S5. The *url* should point to the jsMath
364 TeX math in HTML, Slidy, or S5. The *url* should point to the jsMath
365 load script (e.g. `jsMath/easy/load.js`). If it is provided, a link
365 load script (e.g. `jsMath/easy/load.js`). If it is provided, a link
366 to it will be included in the header of standalone HTML documents.
366 to it will be included in the header of standalone HTML documents.
367− (See `--latexmathml`, `--mimetex`, and `--gladtex` for alternative
367+ (See `--latexmathml`, `--mimetex`, `--webtex`, and `--gladtex` for
368− ways of dealing with math in HTML.)
368+ alternative ways of dealing with math in HTML.)
369
369
370`--gladtex`*[=url]*
370`--gladtex`*[=url]*
371: causes TeX formulas to be enclosed in `<eq>` tags in HTML, Slidy, or
371: causes TeX formulas to be enclosed in `<eq>` tags in HTML, Slidy, or
372 S5 output. This output can then be processed by [gladTeX] to produce
372 S5 output. This output can then be processed by [gladTeX] to produce
373 links to images with the typeset formulas. (See `--latexmathml`,
373 links to images with the typeset formulas. (See `--latexmathml`,
374− `--jsmath`, and `--mimetex` for alternative ways of dealing with
374+ `--jsmath`, `--webtex`, and `--mimetex` for alternative ways of
375− math in HTML.)
375+ dealing with math in HTML.)
376
376
377`--mimetex`*[=url]*
377`--mimetex`*[=url]*
378: causes TeX formulas to be replaced by `<img>` tags linking to the
378: causes TeX formulas to be replaced by `<img>` tags linking to the
379 [mimeTeX] CGI script, which will produce images with the typeset
379 [mimeTeX] CGI script, which will produce images with the typeset
380− formulas. (See `--latexmathml`, `--jsmath`, and `--gladtex` for alternative
380+ formulas. (See `--latexmathml`, `--jsmath`, `--webtex`, and
381+ `--gladtex` for alternative ways of dealing with math in HTML.)
382+
383+`--webtex`*[=url]*
384+: causes TeX formulas to be replaced by `<img>` tags linking to an
385+ external service that converts TeX formulas to images. The formula
386+ will be concatenated with the URL provided. If no URL
387+ is specified, the Google Chart API is used. (See `--latexmathml`,
388+ `--jsmath`, `--mimetex`, and `--gladtex` for alternative ways of
381− ways of dealing with math in HTML.)
389+ dealing with math in HTML.)
382
390
383`-i` or `--incremental`
391`-i` or `--incremental`
384: causes all lists in Slidy or S5 output to be displayed incrementally by
392: causes all lists in Slidy or S5 output to be displayed incrementally by
@@ -1241,6 +1249,12 @@ command-line options selected:
1241 gladtex -d myfile-images myfile.htex
1249 gladtex -d myfile-images myfile.htex
1242 # produces myfile.html and images in myfile-images
1250 # produces myfile.html and images in myfile-images
1243
1251
1252+6. If the `--webtex` option is used, TeX formulas will be converted
1253+ to `<img>` tags that link to an external script that converts
1254+ formulas to images. The formula will be URL-encoded and concatenated
1255+ with the URL provided. If no URL is specified, the Google Chart
1256+ API will be used (`http://chart.apis.google.com/chart?cht=tx&chl=`).
1257+
1244Inline TeX
1258Inline TeX
1245----------
1259----------
1246
1260
man/man1/pandoc.1.md+5
@@ -136,6 +136,11 @@ should pipe input and output through `iconv`:
136: Render TeX math using the mimeTeX CGI script. If *URL* is not specified,
136: Render TeX math using the mimeTeX CGI script. If *URL* is not specified,
137 it is assumed that the script is at `/cgi-bin/mimetex.cgi`.
137 it is assumed that the script is at `/cgi-bin/mimetex.cgi`.
138
138
139+\--webtex=*URL*
140+: Render TeX math using an external script. The formula will be
141+ concatenated with the URL provided. If *URL* is not specified, the
142+ Google Chart API will be used.
143+
139-i, \--incremental
144-i, \--incremental
140: Make list items in Slidy or S5 display incrementally (one by one).
145: Make list items in Slidy or S5 display incrementally (one by one).
141
146
src/Text/Pandoc/Shared.hs+1−1
@@ -457,7 +457,7 @@ data HTMLMathMethod = PlainMath
457 | LaTeXMathML (Maybe String) -- url of LaTeXMathML.js
457 | LaTeXMathML (Maybe String) -- url of LaTeXMathML.js
458 | JsMath (Maybe String) -- url of jsMath load script
458 | JsMath (Maybe String) -- url of jsMath load script
459 | GladTeX
459 | GladTeX
460− | MimeTeX String -- url of mimetex.cgi
460+ | WebTeX String -- url of TeX->image script.
461 | MathML (Maybe String) -- url of MathMLinHTML.js
461 | MathML (Maybe String) -- url of MathMLinHTML.js
462 deriving (Show, Read, Eq)
462 deriving (Show, Read, Eq)
463
463
src/Text/Pandoc/Writers/HTML.hs+23−16
@@ -36,6 +36,7 @@ import Text.Pandoc.Templates
36import Text.Pandoc.Readers.TeXMath
36import Text.Pandoc.Readers.TeXMath
37import Text.Pandoc.Highlighting ( highlightHtml )
37import Text.Pandoc.Highlighting ( highlightHtml )
38import Text.Pandoc.XML (stripTags, escapeStringForXML)
38import Text.Pandoc.XML (stripTags, escapeStringForXML)
39+import Network.HTTP ( urlEncode )
39import Numeric ( showHex )
40import Numeric ( showHex )
40import Data.Char ( ord, toLower )
41import Data.Char ( ord, toLower )
41import Data.List ( isPrefixOf, intersperse )
42import Data.List ( isPrefixOf, intersperse )
@@ -462,16 +463,20 @@ inlineToHtml opts inline =
462 -- non-math elements on the page from being treated as math by
463 -- non-math elements on the page from being treated as math by
463 -- the javascript
464 -- the javascript
464 return $ thespan ! [theclass "LaTeX"] $
465 return $ thespan ! [theclass "LaTeX"] $
465− if t == InlineMath
466+ case t of
466− then primHtml ("$" ++ str ++ "$")
467+ InlineMath -> primHtml ("$" ++ str ++ "$")
467− else primHtml ("$$" ++ str ++ "$$")
468+ DisplayMath -> primHtml ("$$" ++ str ++ "$$")
468− JsMath _ ->
469+ JsMath _ -> do
470+ let m = primHtml str
469− return $ if t == InlineMath
471+ return $ case t of
470− then thespan ! [theclass "math"] $ primHtml str
472+ InlineMath -> thespan ! [theclass "math"] $ m
471− else thediv ! [theclass "math"] $ primHtml str
473+ DisplayMath -> thediv ! [theclass "math"] $ m
472− MimeTeX url ->
474+ WebTeX url -> do
473− return $ image ! [src (url ++ "?" ++ str),
475+ let m = image ! [src (url ++ urlEncode str),
474− alt str, title str]
476+ alt str, title str]
477+ return $ case t of
478+ InlineMath -> m
479+ DisplayMath -> br +++ m +++ br
475 GladTeX ->
480 GladTeX ->
476 return $ primHtml $ "<EQ>" ++ str ++ "</EQ>"
481 return $ primHtml $ "<EQ>" ++ str ++ "</EQ>"
477 MathML _ -> do
482 MathML _ -> do
@@ -484,12 +489,14 @@ inlineToHtml opts inline =
484 Right r -> return $ primHtml $
489 Right r -> return $ primHtml $
485 ppcElement conf r
490 ppcElement conf r
486 Left _ -> inlineListToHtml opts
491 Left _ -> inlineListToHtml opts
487− (readTeXMath str) >>=
492+ (readTeXMath str) >>= return .
488− return . (thespan !
489− [theclass "math"])
493+ (thespan ! [theclass "math"])
490− PlainMath ->
494+ PlainMath -> do
491− inlineListToHtml opts (readTeXMath str) >>=
495+ x <- inlineListToHtml opts (readTeXMath str)
492− return . (thespan ! [theclass "math"]) )
496+ let m = thespan ! [theclass "math"] $ x
497+ return $ case t of
498+ InlineMath -> m
499+ DisplayMath -> br +++ m +++ br )
493 (TeX str) -> case writerHTMLMathMethod opts of
500 (TeX str) -> case writerHTMLMathMethod opts of
494 LaTeXMathML _ -> do modify (\st -> st {stMath = True})
501 LaTeXMathML _ -> do modify (\st -> st {stMath = True})
495 return $ primHtml str
502 return $ primHtml str
src/pandoc.hs+15−3
@@ -40,7 +40,6 @@ import System.Environment ( getArgs, getProgName, getEnvironment )
40import System.Exit ( exitWith, ExitCode (..) )
40import System.Exit ( exitWith, ExitCode (..) )
41import System.FilePath
41import System.FilePath
42import System.Console.GetOpt
42import System.Console.GetOpt
43−import Data.Maybe ( fromMaybe )
44import Data.Char ( toLower, isDigit )
43import Data.Char ( toLower, isDigit )
45import Data.List ( intercalate, isSuffixOf )
44import Data.List ( intercalate, isSuffixOf )
46import System.Directory ( getAppUserDataDirectory )
45import System.Directory ( getAppUserDataDirectory )
@@ -282,11 +281,24 @@ options =
282
281
283 , Option "" ["mimetex"]
282 , Option "" ["mimetex"]
284 (OptArg
283 (OptArg
285− (\arg opt -> return opt { optHTMLMathMethod = MimeTeX
284+ (\arg opt -> do
285+ let url = case arg of
286+ Just u -> u ++ "?"
286− (fromMaybe "/cgi-bin/mimetex.cgi" arg)})
287+ Nothing -> "/cgi-bin/mimetex.cgi?"
288+ return opt { optHTMLMathMethod = WebTeX url })
287 "URL")
289 "URL")
288 "" -- "Use mimetex for HTML math"
290 "" -- "Use mimetex for HTML math"
289
291
292+ , Option "" ["webtex"]
293+ (OptArg
294+ (\arg opt -> do
295+ let url = case arg of
296+ Just u -> u
297+ Nothing -> "http://chart.apis.google.com/chart?cht=tx&chl="
298+ return opt { optHTMLMathMethod = WebTeX url })
299+ "URL")
300+ "" -- "Use web service for HTML math"
301+
290 , Option "" ["jsmath"]
302 , Option "" ["jsmath"]
291 (OptArg
303 (OptArg
292 (\arg opt -> return opt { optHTMLMathMethod = JsMath arg})
304 (\arg opt -> return opt { optHTMLMathMethod = JsMath arg})
tests/writer.html+4−2
@@ -855,9 +855,11 @@ Blah
855 ></span
855 ></span
856 >-Tree</li
856 >-Tree</li
857 ><li
857 ><li
858− >Here’s some display math: <span class="math"
858+ >Here’s some display math: <br
859+ /><span class="math"
859 >$\frac{d}{dx}f(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}$</span
860 >$\frac{d}{dx}f(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}$</span
861+ ><br
860− ></li
862+ /></li
861 ><li
863 ><li
862 >Here’s one that has a line break in it: <span class="math"
864 >Here’s one that has a line break in it: <span class="math"
863 >α + ω × <em
865 >α + ω × <em