Built-in functions in formulas copied as $\LaTeX$ code from output cells are sometimes messy. I'd like to find a way to simplify the way this code is generated.

There is one concrete instance that I'd like to raise:

"Conjugate" is an exponent of blank, and adds brackets: The expression $g_1^* g_2$, which produces Out: Conjugate[Subscript[g, 1]] Subscript[g, 2] is copied as

g_2 \left(g_1\right){}^*

There is no need to use parentheses, or the exponent of blank. All this extra code just makes the expression more cluttered.

How can I personalize the way "Conjugate" is translated to Latex? My expected output would be "g_1^* g_2"


As discussed in my previous posts about TeXForm, you can achieve your goal by giving custom formats for symbols in question. To do this, it is convenient to make use of my Initial function to redefine an internal function:

Initial[Convert`TeX`ExpressionToTeX] /: 
    Convert`TeX`ExpressionToTeX[e__] /; !TrueQ@$TeX := Block[
        {$TeX = True},

Now, any TEX conditioned FormatValues will be used if defined. Next, we give Conjugate a FormatValues to do what you want:

Initial[Conjugate] /: 
    MakeBoxes[Conjugate[Subscript[g_,a_]], TraditionalForm] /; $TeX := SubsuperscriptBox[
        MakeBoxes[g, TraditionalForm],
        MakeBoxes[a, TraditionalForm],


Conjugate[Subscript[g, 1]] Subscript[g, 2] //TeXForm

g_1^* g_2

For more details see my answers to is it possible to change/customize some conversions done by TeXForm? and Multiplication sign in TeXForm?.

| improve this answer | |

There obviously isn't a plain way to do this. Except to make your own solution. Reprocess your LaTeX strings with FireMath or MathType. Or work it by hand, manage your clipboard. Create Gists on GitHub and copy/paste from them, as needed.

Get into the habit of knowing your math LTX and hand edit it. I still do, most of the time. Sorry, I can't give a better answer. (*) Unless, try //TraditionalForm, before the //TeXForm

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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