Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have several Mathematica expressions in which subscripts are expressed with square brackets. E.g. x[12] is meant to represent x12, etc. If I evaluate TeXForm on such an expression, x[12], e.g., gets converted to x(12). Is there a way to get it to produce the x_{12} form instead?

share|improve this question
    
The problem is then telling apart x[2] which is meant to be $x_2$ and f[x] or f[0] which are $f(x)$ or $f(0)$. –  Szabolcs Jan 12 '13 at 23:10

1 Answer 1

up vote 12 down vote accepted

Probably the easiest solution here is to use

Format[x[arg_],TraditionalForm]:=Subscript[x, arg]

This makes sure that the subscript form is used when the display is in TraditionalForm, which is also an intermediate step in creating TeXForm. Then you get for example

1+x[13]//TeXForm

$x_{13}+1$

The Format can't be specified directly for TeXForm because then expressions where your x[12] is surrounded by other things as in 1 + x[12] won't get translated correctly.

share|improve this answer
    
Your answer suggests that Mathematica itself can render TeX. Can it? –  kjo Jan 12 '13 at 22:29
2  
To a certain extent you can render $\LaTeX$, but it's very incomplete. The general idea is to use something like TraditionalForm@ToExpression["\\sin\\alpha", TeXForm, HoldForm]. I discussed this in this answer –  Jens Jan 12 '13 at 22:50
2  
I just realized you may be looking for something simpler: when we say "render" $\LaTeX$, it could also mean to produce traditional-looking formulas from Mathematica standard form input. That is simply done by wrapping any such input in TraditionalForm[ ...]. You could say TraditionalForm is Mathematica's "pretty-print formula" typesetting mode. –  Jens Jan 13 '13 at 0:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.