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.
Rule
instead ofRuleDelayed
in yourTemplateBox
definition. $\endgroup$RuleDelayed
is acceptable in aTemplateBox
, so I don't think it's a bad question $\endgroup$ToBoxes
instead ofMakeBoxes
, on RHS, introduces evaluation leaks. $\endgroup$