[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]

*Subject*: **Re: Aw: Re: Re: [docbook] LaTeX math inside docbook, on-the-fly MathML conversion?**

*From*:**Fredrik Unger <fred@tree.se>***To*: docbook@lists.oasis-open.org*Date*: Fri, 30 Jan 2015 09:20:52 +0100

Hi, On 01/29/2015 10:14 PM, Marco Giebel wrote:

Because typing complicated math with MathML is too time-consuming, I want to include math as LaTeX formulas. This LaTeX needs to be converted to MathML, before I can apply my processing tools.

My xslt knowledge is a bit lacking especially with external tools. Maybe it is possible to call external converter tools on special tags. I have built docbook->website translator in python. http://source.tree.se/treecutter/ the step "Expand xinclude parse text" method could work in this case as a preprocessor, but without using the xlinclude tag, but something like : <equation role="latex"><alt>COMPLEX LATEX EQUATION</alt></equation> You would have to write a small python program that does something like the routine prepare in https://source.tree.se/git/treecutter.git/blob/HEAD:/treecutter/page.py Where I find xinclude :

you would have to find u"//equation[@role='latex'] Then take the text inside the alt tag as input for a Subprocess: exe in your case an external tool : xml = subprocess.Popen(exe,stdout=subprocess.PIPE, stderr=subprocess.PIPE)

In my case I have just limited size of input. Then let the tool do the transform to stdout As for Latex to MathML I saw 4 tools here : http://www.w3.org/Math/wiki/Tools

You can also use an external script as I use. You can see example of xinclude scripts here : https://source.tree.se/git/treecutter.git/tree/HEAD:/xinclude

xstr = etree.fromstring(stdout) # inserting the generated code and remove the xinclude reference idp = c.getparent() idp.insert(idp.index(c)+1,xstr) idp.remove(c)

It can be that you need to add proper namespacing for python lxml.

vi/emacs docbook.latex.xml python convert.py docbook.latex.xml docbook.mathml.xml ./process docbook.mathml.xml This is the most flexible way to preprocess docbook I have found so far. Python have many libraries that you can use to treat special data. I process images, encrypt data, select data to include using python, but keeping the pure but somewhat expanded docbook at the end. If this method would suit you and if you need more information let me know. Sincerely, Fredrik Unger

**Follow-Ups**:**Re: Aw: Re: Re: [docbook] LaTeX math inside docbook, on-the-fly MathML conversion?***From:*Fredrik Unger <fred@tree.se>

**References**:**LaTeX math inside docbook, on-the-fly MathML conversion?***From:*"Marco Giebel" <marco-giebel@gmx.de>

**Re: [docbook] LaTeX math inside docbook, on-the-fly MathML conversion?***From:*maxwell <maxwell@umiacs.umd.edu>

**Aw: Re: [docbook] LaTeX math inside docbook, on-the-fly MathML conversion?***From:*"Marco Giebel" <marco-giebel@gmx.de>

**Re: Aw: Re: [docbook] LaTeX math inside docbook, on-the-fly MathML conversion?***From:*maxwell <maxwell@umiacs.umd.edu>

**Aw: Re: Re: [docbook] LaTeX math inside docbook, on-the-fly MathML conversion?***From:*"Marco Giebel" <marco-giebel@gmx.de>