开发者

Mathematica "\<...\>" syntax

开发者 https://www.devze.com 2023-03-07 16:21 出处:网络
In an answer to another SO question, passing mention was made to a Mathematica string escape syntax that looks like 开发者_如何学编程this: \"\\<...\\>\".Apparently, this syntax is useful for dea

In an answer to another SO question, passing mention was made to a Mathematica string escape syntax that looks like 开发者_如何学编程this: "\<...\>". Apparently, this syntax is useful for dealing with embedded newlines in strings. I've tried searching for documentation using various terms in the Mathematica help browser (and Google), but to no avail. Where can I find documentation on this syntax?

Answer Summary

@Mark points out that the construct is documented in Section 2.8.6 of the V5 Mathematica book. It is also mentioned in Section 2.8.7 of the V5.2 Mathematica Book. In both of those locations, the documentation states that Mathematica ignores line breaks and following tabs in strings -- unless they are enclosed between \< and \> in which case the line breaks (but not tabs) are retained.

In the corresponding section of the V6 documentation, it states that line breaks are retained in strings. Therefore, it appears that the escape syntax is no longer needed starting in V6 -- and is therefore no longer documented.

Note that many notebooks still use this syntax internally, even in V8. @Alexey points out that the cell expressions for strings that contain line breaks still use the syntax.


It's mentioned briefly in section 2.8.6 of the most recent edition of The Mathematica Book. Of course, that's for V5 of Mathematica. In fact, I just tried the following in both V5.2 and V6.0.3:

"Hi
There"

The results were quite different. In particular, V5.2 returned a single line, with no newline character. V6.0.3 returned two lines with the newline character formatted as expected. Strings were improved considerably in V6, so perhaps the `"\<...\>" construct is no longer required.

And perhaps I've been using Mathematica for way too long. :)

0

精彩评论

暂无评论...
验证码 换一张
取 消