3

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 enter image description here 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?

AzJ
  • 697
  • 4
  • 14

1 Answers1

3

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: enter image description here

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 enter image description here

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

AzJ
  • 697
  • 4
  • 14