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

2015-01-30 Thread Fredrik Unger

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=latexaltCOMPLEX 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 :
code = 
self._doc.xpath(u//xi:include[@parse='text'],namespaces=const.XPATH)


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)

How you move the latex text to the tool of choise you have to think 
about. Either write a temp file with the content and supply that file in 
the exe command, or maybe stdin is possible.

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
I can not make any recommendations regarding tools as I have not used 
math in docbook much.


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
Ex. address.py. Given an address it generates an map and builds xml to 
present it.
There you see how much control you have over generating/validating the 
mathml.


Once the tool is done you take the stdout result, parse it and insert it 
in the tree again :

 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)
In your case not removing equation but the alt tag or keeping it 
inserting the mml: tree under equation.


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

Now you just have to write the tree to disk, and continue to use your 
toolchain.


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

-
To unsubscribe, e-mail: docbook-unsubscr...@lists.oasis-open.org
For additional commands, e-mail: docbook-h...@lists.oasis-open.org



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

2015-01-30 Thread Fredrik Unger

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.



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 created a small preprocessing tool and submitted it to docbook-apps

https://lists.oasis-open.org/archives/docbook-apps/201501/msg00036.html

I hope this solves your problem.

Sincerely,

Fredrik Unger

-
To unsubscribe, e-mail: docbook-unsubscr...@lists.oasis-open.org
For additional commands, e-mail: docbook-h...@lists.oasis-open.org



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

2015-01-29 Thread Marco Giebel

Please read my initial question.



I write my documents using docbook.



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.



Gesendet:Donnerstag, 29. Januar 2015 um 22:08 Uhr
Von:maxwell maxw...@umiacs.umd.edu
An:Marco Giebel marco-gie...@gmx.de
Cc:docbook@lists.oasis-open.org
Betreff:Re: Aw: Re: [docbook] LaTeX math inside docbook, on-the-fly MathML conversion?

On 2015-01-29 16:02, Marco Giebel wrote:
 And what does dblatex have to do with converting latex to MathML?
 As you write it converts docbook to latex which is something like the
 opposite.

If youre already using LaTeX, why would you need to convert it to
MathML?

-
To unsubscribe, e-mail: docbook-unsubscr...@lists.oasis-open.org
For additional commands, e-mail: docbook-h...@lists.oasis-open.org





-
To unsubscribe, e-mail: docbook-unsubscr...@lists.oasis-open.org
For additional commands, e-mail: docbook-h...@lists.oasis-open.org