Personalize Copy As LaTeX

6

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"

Rol

Posted 2020-05-18T23:05:10.843

Reputation: 327

1

You are looking for customizing the output of TeXForm. There have been questions on this in the past, and you can find solutions like this one: https://mathematica.stackexchange.com/a/180460/12 Unfortunately, TeXForm does not officially support customization, so solutions you find here may not be fully robust or may break in future versions.

– Szabolcs – 2020-05-19T06:55:13.820

Answers

4

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},
        Convert`TeX`ExpressionToTeX[e]
    ]

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],
        "*"
    ]

Check:

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?.

Carl Woll

Posted 2020-05-18T23:05:10.843

Reputation: 112 778

2

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

prog9910

Posted 2020-05-18T23:05:10.843

Reputation: 529