# How to Custominze the Output of TeXForm

When working with complicated expressions I would like to easily export specific expressions to LaTex.

The ideal solution for me is the TeXForm command, but many times when using it I would like to customize the output.

For example TeXForm produces There are several things I would like to change about the about output

• removing \text around the variables
• changing \bar to \overline when needed.
• removing \left and \right
• changing \varepsilon to \epsilon

My question is

Is there a general way that I can parse the output of TeXForm (or any LaTex output method) so that it is format it to my preferences?

• probably it is not possible to do all of these, but for some, you can check this is-it-possible-to-change-customize-some-conversions-done-by-texform – Nasser Jan 24 '18 at 18:35
• @Nasser Is there a general method of parsing strings in Mathematica? e.g. The mathematica equivalent to docs.python.org/2/library/string.html – AzJ Jan 24 '18 at 18:47
• Yes, you can use either StringPatterns or you can also use standard RegularExpression as well. – Nasser Jan 24 '18 at 18:49
• \[Epsilon] // TeXForm gives \epsilon; \[CurlyEpsilon] // TeXForm gives \varepsilon. You get what you inserted. Moreover, what's wrong with \left and \right? – corey979 Jan 24 '18 at 18:54
• Nothing is wrong with \left and \right but sometimes I prefer that they are removed as they make very long Tex expressions hard to read. – AzJ Jan 24 '18 at 19:12

I came up with a work around for my problem, please comment or edit this question if you have suggestions.

For example I starting with the expression:

I can use the a variety of replacement rules and a function

exper // TraditionalForm
repRules = {
"\\varepsilon" -> "\\epsilon",
"\\epsilon " -> "\\epsilon",
"\\delta " -> "\\sigma",
"\\text{B1}" -> "B_1",
"\\text{B2}" -> "B_2",
"\\text{K1}" -> "K_1",
"\\text{K2}" -> "K_2",
"\\text{d1}" -> "d_1",
"\\text{r1}" -> "r_1",
"\\text{r2}" -> "r_2",
"\\text{d1}" -> "d_1",
"\\text{d2}" -> "d_2",
"\\left" -> "",
"\\right" -> "",
"i " -> "I "};
ToTeX[equation_] :=
StringReplace[repRules][ToString[TeXForm[equation]]];
ToTeX[exper]


to get my desired output

Is there any way to change it so that Mathematica outputs plain text?(this eliminates an extra step)