# TeXForm of symbols

For reasons unknown, TeXForm seems to produce different results when acting on symbols that are one character long versus longer characters:

TeXForm[f]

f

TeXForm[fc]

\text{fc}


The question is is there a way to suppress this adding of the \text{} wrapper around symbols that are more than one character long, either in general, or can I at least redefine it for a particular symbol?

• It's a bad idea to do this because TeX will then treat each letter in the symbol as a separate variable name (even when there aren't any spaces). That affects the typesetting. Is this really what you want? Or do you just want the symbol to be italicized in the TeX output while still being treated as a unit? – Jens Aug 4 '18 at 20:30
• I know what TeX does, and whether there should be a \text{} wrapper around a symbol depends on the context, and it may or may not be a bad idea. In the particular context that I'm working in, having \text{} appear in several hundred places (which I then have to manually erase) doesn't help. – Bojan Aug 6 '18 at 12:43
• Then this could be considered a duplicate of the more general Q&A: Format and TeXForm does not work as expected. It also explains the code in Carl's answer. – Jens Aug 6 '18 at 16:23

TeXForm works by converting the expression to TraditionalForm boxes, and then processing those boxes. The TraditionalForm boxes for fc is "fc", while the TraditionalForm boxes for a string like "fc" is \""fc\"". The following code modifies the TeX conversion rules for strings that come from symbols:

SystemConvertTeXFormDumpmaketex[s_String] /; !stringQ[s] := Replace[
s,
{
n_ /; StringMatchQ[n, NumberString] :> n
}
]

stringQ[s_] := StringMatchQ[s, "\""~~___~~"\""] || !SyntaxQ[s, TeXForm]


ToString[fc, TeXForm]
`