public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
* Proposal: Extend math rendering in HTML with --svgtex[=URL]
@ 2015-02-07 23:29 Serge Stroobandt
       [not found] ` <bdf4eaf4-2f55-4c77-b64f-dfca5f4097fc-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 12+ messages in thread
From: Serge Stroobandt @ 2015-02-07 23:29 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw


[-- Attachment #1.1: Type: text/plain, Size: 5992 bytes --]

*Proposal details:*
The purpose of this extension is to inject SVG math directly into the 
(X)HTML rendered by Pandoc.
To do so, Pandoc's HTML writer needs to be extended with a --svgtex[=URL] 
option for rendering math with SvgTex,
similar as in 
http://johnmacfarlane.net/pandoc/README.html#math-rendering-in-html

The proposed option would typically set:
--svgtex='http://localhost:16000/'
with 16000 being the port where PhantomJS running SvgTex is listening.
(SvgTex installation instructions are provided at the end of this proposal.)

Here is what Pandoc should do,
...for inline math:
match: <span class="math">$\LaTeX$</span>
replace by: <span style="font-size:100%; 
display:inline-block;">..SVG..</span> 
where ..SVG.. is the output of: curl -d 'type=tex&q=\LaTeX' 
http://localhost:16000/

...for display math:
match: <span class="math">$$\LaTeX$$</span>
replace by: <span style="text-align: center;">..SVG..</span>
where ..SVG.. is the output of: curl -d 'type=tex&q=\LaTeX' 
http://localhost:16000/

This information is also available at:
https://github.com/agrbin/svgtex/wiki#how-to-integrate

*Rationale & usefulness:*
All major modern web browsers offer good support for viewing embedded 
scalable vector graphics (SVG). SVG browser support is much better than 
current MathML support. The proposed feature would create self-contained 
(X)HTML files with embedded SVG for math.

Pandoc currently offers support for HTML rendering with MathJax and KaTeX. 
However, both options require the viewer to have a browser with internet 
connection and JavaScript support. Viewing HTML math generated with SvgTex 
only requires a modern browser; an internet connection is optional. Since 
SvgTex uses MathJax, the math rendering quality is equally high and far 
superior to that of MathML.

Mathoid (https://github.com/wikimedia/mathoid), builds on SvgTex and is 
further developed and used by Wikipedia.
Unlike SvgTex, a Mathoid server returns JSON objects, not plain SVG. 
Mathoid installation instructions are not as clear as those of SvgTex. I 
would consider Mathoid support for Pandoc as a separate, slightly more 
complex proposal.

Pandoc generated XHTML with embedded SvgTeX math and CSS layout could serve 
as input for the proprietary Prince XML software (http://www.princexml.com/). 
Prince XML currently only has limited JavaScript support and cannot render 
math with MathJax nor KaTeX.
MathML rendered by Prince XML is of low quality. This proposal would allow 
the extremely fast unattended CSS-typesetting using Prince XML of complex 
PDFs containing high-quality rendered math ---think academic journals. 
Unattended typesetting of complex documents is currently not really 
possible with LaTeX nor ConTeXt. Both have issues with complex page breaks. 
Nor do LaTeX or ConTeXt offer CSS support. Furthermore, rendering with 
LaTeX and ConTeXt is extremely slow compared to Prince XML rendering. 
For an example of using Pandoc in combination with Prince XML (albeit with 
MathML), please, refer to:
http://hamwaves.com/cl-ocfd/en/index.html
This page also contains a link to its own makefile which is very 
instructive to Pandoc users.

*Drawbacks:*
When the --svgtex[=URL] option is enabled for HTML writing, the PhantomJS 
engine needs to be running SvgTex whilst being connected to MathJax.org 
over the Internet.

XHTML containing SVG cannot be validated, simply because it was not 
foreseen in the XHTML specification.
W3C has plans for an XHTML5 specification. Anyhow, the resulting XHTML is 
perfectly usable in browsers and Prince XML.
(See also: http://dh.obdurodon.org/svg-embedding.xhtml)
HTML5 validation should work but is currently experimental.

*Backwards compatibility:*
The proposed HTML writer extension is fully backwards compatible.

*Additional library dependencies:*
A Haskell binding to the libcurl library or similar would be required.

*Performance:*
Pandoc performance without the --svgtex[=URL] option enabled remains 
unaffected.
HTML writing with the --svgtex[=URL] option enabled will be a tad slower.
The main speed limitation will be the internet connection to MathJax.org.
Nevertheless, calls to PhantomJS running SvgTex are inherently fast.
Loading HTML pages containing math generated by SvgTex will be much faster 
than viewing those using MathJax or KaTeX Javascript callbacks.

*SvgTex installation instructions:*
On a Debian-derived GNU/Linux distribution, run the following commands:

$ sudo apt-get install phantomjs
$ cd && git clone https://github.com/agrbin/svgtex/ && cd svgtex

Information is also available 
https://github.com/agrbin/svgtex/wiki

*Starting the PhantomJS engine with SvgTeX:*
$ cd $HOME/svgtex
$ phantomjs main.js &

One might consider adding above lines to a bash script for achieving 
automatic PhantomJS starting at session start.

*Testing the PhantomJS engine with SvgTeX:*
Browsing to http://localhost:16000 should show the svgtex tester interface.

Browsing to:
http://localhost:16000/?type=tex&q=L_{dB}=10\cdot\log_{10}{\frac{P_{out}}{P_{in}}}
should show a formula in SVG.

On the command line, the following command should render the same formula 
as an SVG object to standard output:
curl -d 'type=tex&q=L_{dB}=10\cdot\log_{10}{\frac{P_{out}}{P_{in}}}' 
http://localhost:16000/


Finally, to John:
Thank you for giving the world Pandoc and for continuing to make Pandoc 
even greater!

Kind regards,
Serge Y. Stroobandt

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/bdf4eaf4-2f55-4c77-b64f-dfca5f4097fc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #1.2: Type: text/html, Size: 8135 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2015-02-15  9:36 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-07 23:29 Proposal: Extend math rendering in HTML with --svgtex[=URL] Serge Stroobandt
     [not found] ` <bdf4eaf4-2f55-4c77-b64f-dfca5f4097fc-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2015-02-08  4:16   ` John MacFarlane
     [not found]     ` <20150208041648.GC12050-nFAEphtLEs/fysO+viCLMa55KtNWUUjk@public.gmane.org>
2015-02-08 12:10       ` Serge Stroobandt
     [not found]         ` <214388e6-544c-4721-a96e-eadf519a83ca-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2015-02-08 15:13           ` Daniel Staal
2015-02-08 16:34             ` John MacFarlane
2015-02-08 10:47   ` Anton Grbin
2015-02-08 17:39   ` Ghlen Livid
     [not found]     ` <0f834812-ad8c-4289-871f-8d24af8dfc82-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2015-02-08 19:25       ` Serge Stroobandt
     [not found]         ` <a1da5444-4fe7-401a-96bc-79adfff6a2b6-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2015-02-08 23:30           ` Ghlen Livid
2015-02-08 23:46           ` Ghlen Livid
     [not found]             ` <448e6862-7143-4a01-80e0-2c3f7e4804df-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2015-02-15  8:11               ` Serge Stroobandt
     [not found]                 ` <edfac9a6-c015-4cc5-8d28-55fcc077fe8a-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2015-02-15  9:36                   ` Serge Stroobandt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).