Skip to content

Character sequences used for string representation of boxes should be treated as single characters in string character-wise manipulation operations. #1699

@mmatera

Description

@mmatera

The escaped sequences lije \!, \), and \( in WMA are encoded as the special characters with Unicode encoding:

sequence character meaning
")" "\uf7c0" End raw boxes
"!" "\uf7c1" Parse what follows as a raw box expression
"@" "\uf7c2" SqrtBox
"%" "\uf7c5" last argument (like SqrtBox[A,B] or UnderOverScriptBox[A,B,C]
"^" "\uf7c6" SuperscriptBox
"&" "\uf7c7" UnderscriptBox
"*" "\uf7c8" Construct boxes from input
"(" "\uf7c9" Open Raw Boxes
"_" "\uf7cA" SubscriptBox
"+" "\uf7cB" UnderscriptBox
"/" "\uf7cC" FractionBox
"`" "\uf7cD" FormBox

(see https://reference.wolfram.com/language/tutorial/TextualInputAndOutput.html#28564)

When some of these sequences appear in a string, they are stored as a single character, disregarding the expression is a valid box structure. For example, in WMA,

In[1]:= StringLength["\!A"]
Out[1] = 2
In[2]:= StringTake["\!A",{1}]
Out[2] = \!
In[3]:= StringLength["\!\(A\)"]
Out[3] = 4

In Mathics3, we get

In[1]:=  StringLength["\!A"]
Out[1]= 2

In[2]:=  StringTake["\!A",{1}]
Out[2]= "!"

In[3]:=  StringLength["\!\(A\)"]
Out[3]= 6

When a valid sequence of these characters appears inside a String, the string is converted to boxes as if blocks ... \!\( ... \) ... where a RowBox expression:

In[5]:= "This is a GridBox with a subscript: \!\(\*GridBox[{{a,b},{c,d}}]\_n\), 
yes, it is!"                                                                    

Out[5]= This is a GridBox with a subscript: a   b , yes, it is!
                                                 n
                                            c   d

Nothing of this currently works in Mathics3.

The ability to generate and render strings in this way would be useful to serialize box expressions in the same way that WMA does. Also, this is related to the expected output in ToString expressions (see #1678).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions