2
$\begingroup$

I’d like to have a TemplateBox that interprets as its content boxes:

MakeExpression[TemplateBox[{boxes_}, "RawBoxes", ___], form_] := boxes

but e.g. the input box TemplateBox[{"0"}, "RawBoxes"] refuses to be interpreted leading to

Syntax::sntxi: Incomplete expression; more input is needed .

Simplifying the rule to the constant one does not eliminate the error:

MakeExpression[TemplateBox[{boxes_}, "Const0", ___], form_] := "0"

Evaluating MakeExpression explicitly works fine.

This makes me be confused about how interpreting boxes in Mathematica works. What do I miss? What am I doing wrong? What is a right way to write ‘MakeExpression’ redefinitions? Thanks.

$\endgroup$
2
$\begingroup$

MakeExpression needs to return a HoldComplete object. So, the following might do what you want:

MakeExpression[TemplateBox[{boxes_}, "RawBoxes", ___], StandardForm] := HoldComplete[boxes]

For example:

CellPrint @ Cell[
    BoxData @ TemplateBox[
        {RowBox[{"0", "+", "1"}]},
        "RawBoxes",
        DisplayFunction->(#&)
    ],
    "Input"
]

enter image description here

Evaluating the above cell yields:

RowBox[{"0", "+", "1"}]

$\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.