## January 1, 2007

### TeX Macros

Instiki provides a (broken, but it’s there) output to LaTeX option. Now that we’re producing a significant amount of interesting XHTML+MathML content, there’s general interest in being able to reuse that content in (La)TeX. A lot of effort has gone into converters from TeX-like input into XHTML+MathML. Not so much has gone into converters which go the other way.

Since we have access both to the original Markdown+itex markup and the final XHTML+MathML, there seem to be two approachs

1. Operate on the original markup, converting Markdown to TeX, but copying the equations directly to the output. This seems easier: **foo** becomes \textbf{foo} and one doesn’t have to deal with the complexity of MathML. On the other hand, since Markdown allows you to embed arbitrary (X)HTML in the input, to really do the conversion right is complicated.
2. Operate on the XHTML+MathML. Here, at least, everything is in a canonical form. **foo** and <strong>foo</strong> are not separate cases to be dealt with. They are both rendered to the latter form. One can also use XSLT to write the converter, which has the advantage of portability.

I’m not sure which approach to take, but I’m leaning towards the latter.

Ultimately, however, there will be a certain impedance mismatch because there are a few constructs, like <mroot>, <munderover>, <mmultiscripts>, that exist in MathML (and in itex) but which have no direct analogue in LaTeX. The best approach would be to define LaTeX macros. Here are some examples of macros which translate an itex command into the corresponding AMSLaTeX

\newcommand{\root}[2]{\sqrt[#1]{#2}}
\newcommand{\underoverset}[3]{\overset{#2}{\underset{#1}{#3}}}

I’d like to throw it open to the TeXnicians among you to come up with macros1 for \tensor{}{} and \multiscripts{}{}{}.

1 For example \tensor{R}{_i_^j^k_l} produces $\tensor{R}{_i_^j^k_l}$ and \multiscripts{_2}{F}{_1} produces $\multiscripts{_2}{F}{_1}$. The second argument of \tensor and the first and third argument of \multiscripts consist of an arbitrary number of subscript-superscript pairs ({_a^b_c^d...}). And it’s possible, as in the above examples, to omit a subscript or superscript from the pair, when the result is otherwise unambiguous.

Posted by distler at January 1, 2007 11:59 PM

TrackBack URL for this Entry:   http://golem.ph.utexas.edu/cgi-bin/MT-3.0/dxy-tb.fcgi/1095

### Re: TeX Macros

I like the second option too, since one could then use your program on other web pages (even other blogs just like yours, only without a planned LaTeX export option).

I can program a bit in TeX, and these macros don’t look difficult. I’m too busy to write them today, and I’ll probably have limited computer access for the next several days. However, if nobody else writes them in a couple of weeks, then send me email asking me to do it.

Posted by: Toby Bartels on January 3, 2007 5:08 PM | Permalink | Reply to this

### Re: TeX Macros

Maruku provides a pretty serviceable LaTeX export (as I discuss here). It passes the equations straight through to the output.

Which means, I guess, that I want those LaTeX macros, now!

Posted by: Jacques Distler on January 25, 2007 10:06 AM | Permalink | PGP Sig | Reply to this

Post a New Comment