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.
This commit is contained in:
parent
8757da76b0
commit
57a91f3b6a
6 changed files with 70 additions and 30 deletions
30
README
30
README
|
@ -351,8 +351,8 @@ For further documentation, see the `pandoc(1)` man page.
|
||||||
directly; this provides portability at the price of efficiency. If
|
directly; this provides portability at the price of efficiency. If
|
||||||
you plan to use math on several pages, it is much better to link to
|
you plan to use math on several pages, it is much better to link to
|
||||||
a copy of `LaTeXMathML.js`, which can be cached. (See `--jsmath`,
|
a copy of `LaTeXMathML.js`, which can be cached. (See `--jsmath`,
|
||||||
`--gladtex`, and `--mimetex` for alternative ways of dealing with
|
`--gladtex`, `--webtex`, and `--mimetex` for alternative ways of
|
||||||
math in HTML.)
|
dealing with math in HTML.)
|
||||||
|
|
||||||
`--mathml`
|
`--mathml`
|
||||||
: causes `pandoc` to convert all TeX math to MathML.
|
: causes `pandoc` to convert all TeX math to MathML.
|
||||||
|
@ -364,21 +364,29 @@ For further documentation, see the `pandoc(1)` man page.
|
||||||
TeX math in HTML, Slidy, or S5. The *url* should point to the jsMath
|
TeX math in HTML, Slidy, or S5. The *url* should point to the jsMath
|
||||||
load script (e.g. `jsMath/easy/load.js`). If it is provided, a link
|
load script (e.g. `jsMath/easy/load.js`). If it is provided, a link
|
||||||
to it will be included in the header of standalone HTML documents.
|
to it will be included in the header of standalone HTML documents.
|
||||||
(See `--latexmathml`, `--mimetex`, and `--gladtex` for alternative
|
(See `--latexmathml`, `--mimetex`, `--webtex`, and `--gladtex` for
|
||||||
ways of dealing with math in HTML.)
|
alternative ways of dealing with math in HTML.)
|
||||||
|
|
||||||
`--gladtex`*[=url]*
|
`--gladtex`*[=url]*
|
||||||
: causes TeX formulas to be enclosed in `<eq>` tags in HTML, Slidy, or
|
: causes TeX formulas to be enclosed in `<eq>` tags in HTML, Slidy, or
|
||||||
S5 output. This output can then be processed by [gladTeX] to produce
|
S5 output. This output can then be processed by [gladTeX] to produce
|
||||||
links to images with the typeset formulas. (See `--latexmathml`,
|
links to images with the typeset formulas. (See `--latexmathml`,
|
||||||
`--jsmath`, and `--mimetex` for alternative ways of dealing with
|
`--jsmath`, `--webtex`, and `--mimetex` for alternative ways of
|
||||||
math in HTML.)
|
dealing with math in HTML.)
|
||||||
|
|
||||||
`--mimetex`*[=url]*
|
`--mimetex`*[=url]*
|
||||||
: causes TeX formulas to be replaced by `<img>` tags linking to the
|
: causes TeX formulas to be replaced by `<img>` tags linking to the
|
||||||
[mimeTeX] CGI script, which will produce images with the typeset
|
[mimeTeX] CGI script, which will produce images with the typeset
|
||||||
formulas. (See `--latexmathml`, `--jsmath`, and `--gladtex` for alternative
|
formulas. (See `--latexmathml`, `--jsmath`, `--webtex`, and
|
||||||
ways of dealing with math in HTML.)
|
`--gladtex` for alternative ways of dealing with math in HTML.)
|
||||||
|
|
||||||
|
`--webtex`*[=url]*
|
||||||
|
: causes TeX formulas to be replaced by `<img>` tags linking to an
|
||||||
|
external service that converts TeX formulas to images. The formula
|
||||||
|
will be concatenated with the URL provided. If no URL
|
||||||
|
is specified, the Google Chart API is used. (See `--latexmathml`,
|
||||||
|
`--jsmath`, `--mimetex`, and `--gladtex` for alternative ways of
|
||||||
|
dealing with math in HTML.)
|
||||||
|
|
||||||
`-i` or `--incremental`
|
`-i` or `--incremental`
|
||||||
: causes all lists in Slidy or S5 output to be displayed incrementally by
|
: causes all lists in Slidy or S5 output to be displayed incrementally by
|
||||||
|
@ -1241,6 +1249,12 @@ command-line options selected:
|
||||||
gladtex -d myfile-images myfile.htex
|
gladtex -d myfile-images myfile.htex
|
||||||
# produces myfile.html and images in myfile-images
|
# produces myfile.html and images in myfile-images
|
||||||
|
|
||||||
|
6. If the `--webtex` option is used, TeX formulas will be converted
|
||||||
|
to `<img>` tags that link to an external script that converts
|
||||||
|
formulas to images. The formula will be URL-encoded and concatenated
|
||||||
|
with the URL provided. If no URL is specified, the Google Chart
|
||||||
|
API will be used (`http://chart.apis.google.com/chart?cht=tx&chl=`).
|
||||||
|
|
||||||
Inline TeX
|
Inline TeX
|
||||||
----------
|
----------
|
||||||
|
|
||||||
|
|
|
@ -136,6 +136,11 @@ should pipe input and output through `iconv`:
|
||||||
: Render TeX math using the mimeTeX CGI script. If *URL* is not specified,
|
: Render TeX math using the mimeTeX CGI script. If *URL* is not specified,
|
||||||
it is assumed that the script is at `/cgi-bin/mimetex.cgi`.
|
it is assumed that the script is at `/cgi-bin/mimetex.cgi`.
|
||||||
|
|
||||||
|
\--webtex=*URL*
|
||||||
|
: Render TeX math using an external script. The formula will be
|
||||||
|
concatenated with the URL provided. If *URL* is not specified, the
|
||||||
|
Google Chart API will be used.
|
||||||
|
|
||||||
-i, \--incremental
|
-i, \--incremental
|
||||||
: Make list items in Slidy or S5 display incrementally (one by one).
|
: Make list items in Slidy or S5 display incrementally (one by one).
|
||||||
|
|
||||||
|
|
|
@ -457,7 +457,7 @@ data HTMLMathMethod = PlainMath
|
||||||
| LaTeXMathML (Maybe String) -- url of LaTeXMathML.js
|
| LaTeXMathML (Maybe String) -- url of LaTeXMathML.js
|
||||||
| JsMath (Maybe String) -- url of jsMath load script
|
| JsMath (Maybe String) -- url of jsMath load script
|
||||||
| GladTeX
|
| GladTeX
|
||||||
| MimeTeX String -- url of mimetex.cgi
|
| WebTeX String -- url of TeX->image script.
|
||||||
| MathML (Maybe String) -- url of MathMLinHTML.js
|
| MathML (Maybe String) -- url of MathMLinHTML.js
|
||||||
deriving (Show, Read, Eq)
|
deriving (Show, Read, Eq)
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,7 @@ import Text.Pandoc.Templates
|
||||||
import Text.Pandoc.Readers.TeXMath
|
import Text.Pandoc.Readers.TeXMath
|
||||||
import Text.Pandoc.Highlighting ( highlightHtml )
|
import Text.Pandoc.Highlighting ( highlightHtml )
|
||||||
import Text.Pandoc.XML (stripTags, escapeStringForXML)
|
import Text.Pandoc.XML (stripTags, escapeStringForXML)
|
||||||
|
import Network.HTTP ( urlEncode )
|
||||||
import Numeric ( showHex )
|
import Numeric ( showHex )
|
||||||
import Data.Char ( ord, toLower )
|
import Data.Char ( ord, toLower )
|
||||||
import Data.List ( isPrefixOf, intersperse )
|
import Data.List ( isPrefixOf, intersperse )
|
||||||
|
@ -462,16 +463,20 @@ inlineToHtml opts inline =
|
||||||
-- non-math elements on the page from being treated as math by
|
-- non-math elements on the page from being treated as math by
|
||||||
-- the javascript
|
-- the javascript
|
||||||
return $ thespan ! [theclass "LaTeX"] $
|
return $ thespan ! [theclass "LaTeX"] $
|
||||||
if t == InlineMath
|
case t of
|
||||||
then primHtml ("$" ++ str ++ "$")
|
InlineMath -> primHtml ("$" ++ str ++ "$")
|
||||||
else primHtml ("$$" ++ str ++ "$$")
|
DisplayMath -> primHtml ("$$" ++ str ++ "$$")
|
||||||
JsMath _ ->
|
JsMath _ -> do
|
||||||
return $ if t == InlineMath
|
let m = primHtml str
|
||||||
then thespan ! [theclass "math"] $ primHtml str
|
return $ case t of
|
||||||
else thediv ! [theclass "math"] $ primHtml str
|
InlineMath -> thespan ! [theclass "math"] $ m
|
||||||
MimeTeX url ->
|
DisplayMath -> thediv ! [theclass "math"] $ m
|
||||||
return $ image ! [src (url ++ "?" ++ str),
|
WebTeX url -> do
|
||||||
alt str, title str]
|
let m = image ! [src (url ++ urlEncode str),
|
||||||
|
alt str, title str]
|
||||||
|
return $ case t of
|
||||||
|
InlineMath -> m
|
||||||
|
DisplayMath -> br +++ m +++ br
|
||||||
GladTeX ->
|
GladTeX ->
|
||||||
return $ primHtml $ "<EQ>" ++ str ++ "</EQ>"
|
return $ primHtml $ "<EQ>" ++ str ++ "</EQ>"
|
||||||
MathML _ -> do
|
MathML _ -> do
|
||||||
|
@ -484,12 +489,14 @@ inlineToHtml opts inline =
|
||||||
Right r -> return $ primHtml $
|
Right r -> return $ primHtml $
|
||||||
ppcElement conf r
|
ppcElement conf r
|
||||||
Left _ -> inlineListToHtml opts
|
Left _ -> inlineListToHtml opts
|
||||||
(readTeXMath str) >>=
|
(readTeXMath str) >>= return .
|
||||||
return . (thespan !
|
(thespan ! [theclass "math"])
|
||||||
[theclass "math"])
|
PlainMath -> do
|
||||||
PlainMath ->
|
x <- inlineListToHtml opts (readTeXMath str)
|
||||||
inlineListToHtml opts (readTeXMath str) >>=
|
let m = thespan ! [theclass "math"] $ x
|
||||||
return . (thespan ! [theclass "math"]) )
|
return $ case t of
|
||||||
|
InlineMath -> m
|
||||||
|
DisplayMath -> br +++ m +++ br )
|
||||||
(TeX str) -> case writerHTMLMathMethod opts of
|
(TeX str) -> case writerHTMLMathMethod opts of
|
||||||
LaTeXMathML _ -> do modify (\st -> st {stMath = True})
|
LaTeXMathML _ -> do modify (\st -> st {stMath = True})
|
||||||
return $ primHtml str
|
return $ primHtml str
|
||||||
|
|
|
@ -40,7 +40,6 @@ import System.Environment ( getArgs, getProgName, getEnvironment )
|
||||||
import System.Exit ( exitWith, ExitCode (..) )
|
import System.Exit ( exitWith, ExitCode (..) )
|
||||||
import System.FilePath
|
import System.FilePath
|
||||||
import System.Console.GetOpt
|
import System.Console.GetOpt
|
||||||
import Data.Maybe ( fromMaybe )
|
|
||||||
import Data.Char ( toLower, isDigit )
|
import Data.Char ( toLower, isDigit )
|
||||||
import Data.List ( intercalate, isSuffixOf )
|
import Data.List ( intercalate, isSuffixOf )
|
||||||
import System.Directory ( getAppUserDataDirectory )
|
import System.Directory ( getAppUserDataDirectory )
|
||||||
|
@ -282,11 +281,24 @@ options =
|
||||||
|
|
||||||
, Option "" ["mimetex"]
|
, Option "" ["mimetex"]
|
||||||
(OptArg
|
(OptArg
|
||||||
(\arg opt -> return opt { optHTMLMathMethod = MimeTeX
|
(\arg opt -> do
|
||||||
(fromMaybe "/cgi-bin/mimetex.cgi" arg)})
|
let url = case arg of
|
||||||
|
Just u -> u ++ "?"
|
||||||
|
Nothing -> "/cgi-bin/mimetex.cgi?"
|
||||||
|
return opt { optHTMLMathMethod = WebTeX url })
|
||||||
"URL")
|
"URL")
|
||||||
"" -- "Use mimetex for HTML math"
|
"" -- "Use mimetex for HTML math"
|
||||||
|
|
||||||
|
, Option "" ["webtex"]
|
||||||
|
(OptArg
|
||||||
|
(\arg opt -> do
|
||||||
|
let url = case arg of
|
||||||
|
Just u -> u
|
||||||
|
Nothing -> "http://chart.apis.google.com/chart?cht=tx&chl="
|
||||||
|
return opt { optHTMLMathMethod = WebTeX url })
|
||||||
|
"URL")
|
||||||
|
"" -- "Use web service for HTML math"
|
||||||
|
|
||||||
, Option "" ["jsmath"]
|
, Option "" ["jsmath"]
|
||||||
(OptArg
|
(OptArg
|
||||||
(\arg opt -> return opt { optHTMLMathMethod = JsMath arg})
|
(\arg opt -> return opt { optHTMLMathMethod = JsMath arg})
|
||||||
|
|
|
@ -855,9 +855,11 @@ Blah
|
||||||
></span
|
></span
|
||||||
>-Tree</li
|
>-Tree</li
|
||||||
><li
|
><li
|
||||||
>Here’s some display math: <span class="math"
|
>Here’s some display math: <br
|
||||||
|
/><span class="math"
|
||||||
>$\frac{d}{dx}f(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}$</span
|
>$\frac{d}{dx}f(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}$</span
|
||||||
></li
|
><br
|
||||||
|
/></li
|
||||||
><li
|
><li
|
||||||
>Here’s one that has a line break in it: <span class="math"
|
>Here’s one that has a line break in it: <span class="math"
|
||||||
>α + ω × <em
|
>α + ω × <em
|
||||||
|
|
Loading…
Add table
Reference in a new issue