What exactly do \>
and \<
do in Mathematica strings (e.g. "ab\>c"
)?
They sure exhibit some weird behavior! If you evaluate a string containing either of these, it completely disappears from the string: "ab\>c"
evaluates to "abc"
.
And this isn't some formatting trickery: StringLength["ab\>c"]
evaluates to 3
; indeed, "a\<b\>c" == "abc"
(and even "a\<b\>c" === "abc"
) evaluates to True
.
Viewing the box structure of the input and output with CmdShiftE, in addition to reconfirming that the outputs are exactly the same, perhaps shows us a clue: evaluating "abc"
and viewing the box structure of the output yields
Cell[BoxData["\<\"abc\"\>"], "Output", ...]
(Oddly enough, viewing the box structure for the input cell containing "abc"
yields Cell[BoxData["\"\<abc\>\""], "Input", ...]
—the escaped quotes, \"
, are now outside the \<
, \>
"brackets".)
Notice that these seem to be exclusively "string-enclosing brackets": viewing the box structure of 3
yields Cell[BoxData["3"], ...]
But what actually is their purpose? When does Mathematica use them, and maybe more importantly, why? Neither the documentation for BoxData
nor String
seem to offer any clues—searching the documentation for \>
doesn't yield any results, either.
"ab\\>c"
or"ab\\<c"
work as you would expect. $\endgroup$