If I enter a string (say, "abc"
) in a cell, and then switch to box representation (Shift+Ctrl+E or menu item Cell ► Show Expression
), I see the following:
Cell[BoxData["\"\\""], "Input",
CellChangeTimes->{{3.662918813714031*^9, 3.6629188530623317`*^9}}]
I understand everything in this expression except the delimiters \<
and \>
. They look like escape sequences (e.g. \\
, \"
) or like symbols used in string representation of boxes (e.g. \(
, \!
, \*
, etc), but I could not find their description anywhere. I experimented a little, and it looks they are ignored within strings (for example StringLength["\<"]
evaluates to 0
) and rejected as an incorrect input elsewhere.
What do \<
and \>
mean inside of a string? For what purpose they are automatically added into the low-level representation of a cell? What are their use cases?
$Version
"10.2.0 for Microsoft Windows (64-bit) (July 7, 2015)"
Answer
Thanks to andre's comment (where this link is provided), I now see the effect of those delimiters (I tested it in Mathematica 11 and also some earlier versions). When I add 2 newlines to the box representation of the cell:
Cell[BoxData["\"\
bc\>\""], "Input",
CellChangeTimes->{{3.662918813714031*^9, 3.6629188530623317`*^9}}]
and switch back using Shift+Ctrl+E
, then the cell look like this:
"a
bc"
But if I remove those delimiters:
Cell[BoxData["\"a
bc\""], "Input",
CellChangeTimes->{{3.662918813714031*^9, 3.6629188530623317`*^9}}]
and switch back, then the cell looks like this:
"a bc"
It seems that the purpose of \<
,\>
is to delimit ranges within string literals in raw box representations of cells where newlines should be exactly preserved. It looks like they only have effect in that context and are ignored in normal input in newer versions of Mathematica. The legacy documentation suggests that in Mathematica 5 they were significant in all string literals.
Update: I found an old discussion on this topic: [1],[2],[3].
Comments
Post a Comment