Skip to main content
Tweak SyntaxForm
Source Link
Carl Woll
  • 131.7k
  • 6
  • 246
  • 359

I think you're looking for SyntaxForm. For example:

foo /: MakeBoxes[foo[x,y], StandardForm] := TemplateBox[
    {MakeBoxes[x], MakeBoxes[y]},
    "foo",
    DisplayFunction->(RowBox[{#1, "\[CenterDot]", #2}]&),
    SyntaxForm->"\[Star]">Star
]

I used Star for the SyntaxForm since its precedence is 390, as requested, in between the precedences for Plus and Times:

Precedence /@ {Plus, Star, Times}

{310., 390., 400.}

Then:

a + foo[x, y]
a * foo[x, y]

enter image description hereenter image description here

I think you're looking for SyntaxForm. For example:

foo /: MakeBoxes[foo[x,y], StandardForm] := TemplateBox[
    {MakeBoxes[x], MakeBoxes[y]},
    "foo",
    DisplayFunction->(RowBox[{#1, "\[CenterDot]", #2}]&),
    SyntaxForm->"\[Star]"
]

I used Star for the SyntaxForm since its precedence is 390, as requested, in between the precedences for Plus and Times:

Precedence /@ {Plus, Star, Times}

{310., 390., 400.}

Then:

a + foo[x, y]
a * foo[x, y]

enter image description here

I think you're looking for SyntaxForm. For example:

foo /: MakeBoxes[foo[x,y], StandardForm] := TemplateBox[
    {MakeBoxes[x], MakeBoxes[y]},
    "foo",
    DisplayFunction->(RowBox[{#1, "\[CenterDot]", #2}]&),
    SyntaxForm->Star
]

I used Star for the SyntaxForm since its precedence is 390, as requested, in between the precedences for Plus and Times:

Precedence /@ {Plus, Star, Times}

{310., 390., 400.}

Then:

a + foo[x, y]
a * foo[x, y]

enter image description here

Source Link
Carl Woll
  • 131.7k
  • 6
  • 246
  • 359

I think you're looking for SyntaxForm. For example:

foo /: MakeBoxes[foo[x,y], StandardForm] := TemplateBox[
    {MakeBoxes[x], MakeBoxes[y]},
    "foo",
    DisplayFunction->(RowBox[{#1, "\[CenterDot]", #2}]&),
    SyntaxForm->"\[Star]"
]

I used Star for the SyntaxForm since its precedence is 390, as requested, in between the precedences for Plus and Times:

Precedence /@ {Plus, Star, Times}

{310., 390., 400.}

Then:

a + foo[x, y]
a * foo[x, y]

enter image description here