git.iko.soy/typeable/pandoc
on master help sign in
Added --webtex option for HTML math.

+ Added --webtex command-line option, with optional parameter. (Defaults to using google charts API.) + Added WebTeX HTMLMathMethod. + Removed MimeTeX HTMLMathMethod. (WebTeX is generic and subsumes it.) + Modified --mimetex option to use WebTeX. + Thanks to lpeterse for the idea and some of the code.

commit57a91f3b6add303ef70aa29a14a8c67123ec7c0f authorJohn MacFarlane <jgm@berkeley.edu> dateThu 15 Jul 2010, 19:01 (16 years ago) parent8757da7
6 files changed+70−30
README+22−8 man/man1/pandoc.1.md+5 src/Text/Pandoc/Shared.hs+1−1 src/Text/Pandoc/Writers/HTML.hs+23−16 src/pandoc.hs+15−3 tests/writer.html+4−2
README+22−8
@@ -351,8 +351,8 @@ For further documentation, see the `pandoc(1)` man page.
351351 directly; this provides portability at the price of efficiency. If
352352 you plan to use math on several pages, it is much better to link to
353353 a copy of `LaTeXMathML.js`, which can be cached. (See `--jsmath`,
354− `--gladtex`, and `--mimetex` for alternative ways of dealing with
355− math in HTML.)
354+ `--gladtex`, `--webtex`, and `--mimetex` for alternative ways of
355+ dealing with math in HTML.)
356356
357357`--mathml`
358358: causes `pandoc` to convert all TeX math to MathML.
@@ -364,21 +364,29 @@ For further documentation, see the `pandoc(1)` man page.
364364 TeX math in HTML, Slidy, or S5. The *url* should point to the jsMath
365365 load script (e.g. `jsMath/easy/load.js`). If it is provided, a link
366366 to it will be included in the header of standalone HTML documents.
367− (See `--latexmathml`, `--mimetex`, and `--gladtex` for alternative
368− ways of dealing with math in HTML.)
367+ (See `--latexmathml`, `--mimetex`, `--webtex`, and `--gladtex` for
368+ alternative ways of dealing with math in HTML.)
369369
370370`--gladtex`*[=url]*
371371: causes TeX formulas to be enclosed in `<eq>` tags in HTML, Slidy, or
372372 S5 output. This output can then be processed by [gladTeX] to produce
373373 links to images with the typeset formulas. (See `--latexmathml`,
374− `--jsmath`, and `--mimetex` for alternative ways of dealing with
375− math in HTML.)
374+ `--jsmath`, `--webtex`, and `--mimetex` for alternative ways of
375+ dealing with math in HTML.)
376376
377377`--mimetex`*[=url]*
378378: causes TeX formulas to be replaced by `<img>` tags linking to the
379379 [mimeTeX] CGI script, which will produce images with the typeset
380− formulas. (See `--latexmathml`, `--jsmath`, and `--gladtex` for alternative
381− ways of dealing with math in HTML.)
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
389+ dealing with math in HTML.)
382390
383391`-i` or `--incremental`
384392: causes all lists in Slidy or S5 output to be displayed incrementally by
@@ -1241,6 +1249,12 @@ command-line options selected:
12411249 gladtex -d myfile-images myfile.htex
12421250 # produces myfile.html and images in myfile-images
12431251
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+
12441258Inline TeX
12451259----------
12461260
man/man1/pandoc.1.md+5
@@ -136,6 +136,11 @@ should pipe input and output through `iconv`:
136136: Render TeX math using the mimeTeX CGI script. If *URL* is not specified,
137137 it is assumed that the script is at `/cgi-bin/mimetex.cgi`.
138138
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+
139144-i, \--incremental
140145: Make list items in Slidy or S5 display incrementally (one by one).
141146
src/Text/Pandoc/Shared.hs+1−1
@@ -457,7 +457,7 @@ data HTMLMathMethod = PlainMath
457457 | LaTeXMathML (Maybe String) -- url of LaTeXMathML.js
458458 | JsMath (Maybe String) -- url of jsMath load script
459459 | GladTeX
460− | MimeTeX String -- url of mimetex.cgi
460+ | WebTeX String -- url of TeX->image script.
461461 | MathML (Maybe String) -- url of MathMLinHTML.js
462462 deriving (Show, Read, Eq)
463463
src/Text/Pandoc/Writers/HTML.hs+23−16
@@ -36,6 +36,7 @@ import Text.Pandoc.Templates
3636import Text.Pandoc.Readers.TeXMath
3737import Text.Pandoc.Highlighting ( highlightHtml )
3838import Text.Pandoc.XML (stripTags, escapeStringForXML)
39+import Network.HTTP ( urlEncode )
3940import Numeric ( showHex )
4041import Data.Char ( ord, toLower )
4142import Data.List ( isPrefixOf, intersperse )
@@ -462,16 +463,20 @@ inlineToHtml opts inline =
462463 -- non-math elements on the page from being treated as math by
463464 -- the javascript
464465 return $ thespan ! [theclass "LaTeX"] $
465− if t == InlineMath
466− then primHtml ("$" ++ str ++ "$")
467− else primHtml ("$$" ++ str ++ "$$")
468− JsMath _ ->
469− return $ if t == InlineMath
470− then thespan ! [theclass "math"] $ primHtml str
471− else thediv ! [theclass "math"] $ primHtml str
472− MimeTeX url ->
473− return $ image ! [src (url ++ "?" ++ str),
474− alt str, title str]
466+ case t of
467+ InlineMath -> primHtml ("$" ++ str ++ "$")
468+ DisplayMath -> primHtml ("$$" ++ str ++ "$$")
469+ JsMath _ -> do
470+ let m = primHtml str
471+ return $ case t of
472+ InlineMath -> thespan ! [theclass "math"] $ m
473+ DisplayMath -> thediv ! [theclass "math"] $ m
474+ WebTeX url -> do
475+ let m = image ! [src (url ++ urlEncode str),
476+ alt str, title str]
477+ return $ case t of
478+ InlineMath -> m
479+ DisplayMath -> br +++ m +++ br
475480 GladTeX ->
476481 return $ primHtml $ "<EQ>" ++ str ++ "</EQ>"
477482 MathML _ -> do
@@ -484,12 +489,14 @@ inlineToHtml opts inline =
484489 Right r -> return $ primHtml $
485490 ppcElement conf r
486491 Left _ -> inlineListToHtml opts
487− (readTeXMath str) >>=
488− return . (thespan !
489− [theclass "math"])
490− PlainMath ->
491− inlineListToHtml opts (readTeXMath str) >>=
492− return . (thespan ! [theclass "math"]) )
492+ (readTeXMath str) >>= return .
493+ (thespan ! [theclass "math"])
494+ PlainMath -> do
495+ x <- inlineListToHtml opts (readTeXMath str)
496+ let m = thespan ! [theclass "math"] $ x
497+ return $ case t of
498+ InlineMath -> m
499+ DisplayMath -> br +++ m +++ br )
493500 (TeX str) -> case writerHTMLMathMethod opts of
494501 LaTeXMathML _ -> do modify (\st -> st {stMath = True})
495502 return $ primHtml str
src/pandoc.hs+15−3
@@ -40,7 +40,6 @@ import System.Environment ( getArgs, getProgName, getEnvironment )
4040import System.Exit ( exitWith, ExitCode (..) )
4141import System.FilePath
4242import System.Console.GetOpt
43−import Data.Maybe ( fromMaybe )
4443import Data.Char ( toLower, isDigit )
4544import Data.List ( intercalate, isSuffixOf )
4645import System.Directory ( getAppUserDataDirectory )
@@ -282,11 +281,24 @@ options =
282281
283282 , Option "" ["mimetex"]
284283 (OptArg
285− (\arg opt -> return opt { optHTMLMathMethod = MimeTeX
286− (fromMaybe "/cgi-bin/mimetex.cgi" arg)})
284+ (\arg opt -> do
285+ let url = case arg of
286+ Just u -> u ++ "?"
287+ Nothing -> "/cgi-bin/mimetex.cgi?"
288+ return opt { optHTMLMathMethod = WebTeX url })
287289 "URL")
288290 "" -- "Use mimetex for HTML math"
289291
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+
290302 , Option "" ["jsmath"]
291303 (OptArg
292304 (\arg opt -> return opt { optHTMLMathMethod = JsMath arg})
tests/writer.html+4−2
@@ -855,9 +855,11 @@ Blah
855855 ></span
856856 >-Tree</li
857857 ><li
858− >Here’s some display math: <span class="math"
858+ >Here’s some display math: <br
859+ /><span class="math"
859860 >$\frac{d}{dx}f(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}$</span
860− ></li
861+ ><br
862+ /></li
861863 ><li
862864 >Here’s one that has a line break in it: <span class="math"
863865 >α + ω × <em