# TeXForm: control processing spelt-out names of Greek letters

In a notebook, type in

theta^2


then select it and use Copy As → LaTeX. The resulting LaTeX code is

\text {theta}^2


Now try

TeXForm[theta^2]
(* \theta ^2 *)


Note that theta turned into \theta in the second case.

Why is there a difference between copying and using TeXForm directly? How can I control whether spelt-out names of greek letters, such as theta, will be converted into the actual Greek letter, i.e. \theta?

One possible, but slightly inconvenient way to prevent the processing of such names is to replace them with strings, theta -> "theta". I do not usually mind this processing (I actually prefer it), I am simply looking for a way to control it.

It has something to do with these: ConvertTeXBoxesToTeX[ToBoxes[theta^2]] and ConvertTeXExpressionToTeX[theta^2]. That and copying from a notebook deals with boxes and TeXForm deals with expressions. ConvertTeXExpressionToTeX calls ConvertTeXBoxesToTeX with the option

"BoxRules" -> SystemConvertTeXFormDump$GreekWords  but copying as TeX does not. Managing TeXForm TeXForm[expr] applies the list of rules SystemConvertTeXFormDump$GreekWords when it is typeset.

Demonstration:

Block[{SystemConvertTeXFormDump$GreekWords = {}}, CellPrint@ExpressionCell[TeXForm[theta^2], "Output"] ]  Note that Block[{SystemConvertTeXFormDump$GreekWords = {}},
TeXForm[theta^2]
]


does not work because the output is TeXForm[theta^2], which is then typeset after exiting the Block[]. One can set the value of $GreekWords globally, so that TeXForm[theta^2] would be typeset without converting words to letters. Managing CopyAs > LaTeX This is but a partial answer. Setting the following option should work to make CopyAs > LaTeX convert Greek letter names to letters, assuming SystemConvertTeXFormDump$GreekWords retains its default value:

SetOptions[ConvertTeXBoxesToTeX,
"BoxRules" -> SystemConvertTeXFormDump\$GreekWords];


On a Mac, it works when I use the context menu (CTRL-click, CopyAs > LaTeX). However, I find it does not work with the menu-bar command Edit > CopyAs > LaTeX. (I have no clue why as yet, nor how it works on other systems.)

• FrontEndCopyAsTeX does not override the default options to ConvertTeXBoxesToTeX, fwiw. Nov 26, 2016 at 14:39
• This works though: Block[{...}, ToString[theta^2, TeXForm]] or Block[{...}, ToString@TeXForm[...]]`. Great spelunking, thanks! Nov 26, 2016 at 16:12