If I define the TraditionalForm formatting of myFunction without TemplateBox, then
TeXForm works properly:
ClearAll[myFunction]
myFunction /: HoldPattern[MakeBoxes[myFunction[a_, b_, c_], TraditionalForm]] :=
SubsuperscriptBox[ToBoxes[a], ToBoxes[b], ToBoxes[c]]
myFunction[h, 1, 2] // TeXForm
(* h_1^2 *)
But if I try to define it using TemplateBox,
ClearAll[myFunction]
myFunction /: HoldPattern[MakeBoxes[myFunction[a_, b_, c_], TraditionalForm]] :=
TemplateBox[
{ToBoxes[a], ToBoxes[b], ToBoxes[c]}, "myFunctionTag",
DisplayFunction :> (SubsuperscriptBox[#1, #2, #3] &)
];
TraditionalForm works correctly,
myFunction[h, 1, 2] // TraditionalForm
(* $h_1^2$ *)
but TeXForm does not return code to format the expression as in TraditionalForm:
myFunction[h, 1, 2] // TeXForm
(* \text{myFunctionTag}[h,1,2] *)
Instead, it is just replacing the head of the function with the tag of TemplateBox. What is the correct way to make TeXForm generate code out of a TemplateBox? I'm looking for a solution that can be programmed into a package.
Ruleinstead ofRuleDelayedin yourTemplateBoxdefinition. – Carl Woll Jul 30 '17 at 21:46RuleDelayedis acceptable in aTemplateBox, so I don't think it's a bad question – Carl Woll Jul 30 '17 at 22:34ToBoxesinstead ofMakeBoxes, on RHS, introduces evaluation leaks. – jkuczm Aug 01 '17 at 10:00