3
$\begingroup$

The following definition for boxes in TraditionalForm formats as $\{a,b\}\{c,d\}$ (for simplicty, it matches only if the arguments literally are a, b, c, d):

f /: MakeBoxes[f[a, b, c, d], TraditionalForm] := 
   RowBox[{RowBox[{"{", "a", "b", "}"}], RowBox[{"{", "c", "d", "}"}]}]:

Here is an example:

f[a, b, c, d] // TraditionalForm

$\{a,b\}\{c,d\}$

However, when this object is multiplied by something, I get an unwanted parenthesis:

2*f[a, b, c, d] // TraditionalForm

$2\,(\{a,b\}\{c,d\})$

How do I modify the box definition above to avoid the parenthesis?

$\endgroup$
  • 1
    $\begingroup$ maybe ClearAll[f]; f /: MakeBoxes[f[a, b, c, d], TraditionalForm] := RowBox[{"{", "a", "b", "}", "{", "c", "d", "}"}]? ` $\endgroup$ – kglr Dec 31 '19 at 1:52
3
$\begingroup$

Use an InterpretationBox, TagBox or TemplateBox with a SyntaxForm option. For example:

MakeBoxes[f[a, b, c, d], TraditionalForm] ^:= InterpretationBox[
    RowBox[{RowBox[{"{","a","b","}"}], RowBox[{"{","c","d","}"}]}],
    f[a,b,c,d],
    SyntaxForm->"^"
]

Then:

2 f[a,b,c,d] //TraditionalForm

2 {a b}{c d}

|improve this answer|||||
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.