Mathematica“\<...\>”句法

发布于 2024-11-08 02:29:05 字数 1054 浏览 0 评论 0 原文

在回答另一个SO问题,顺便提到了 Mathematica 字符串转义语法,如下所示:"\<...\>"。显然,这种语法对于处理字符串中嵌入的换行符很有用。我尝试在 Mathematica 帮助浏览器(和 Google)中使用各种术语搜索文档,但无济于事。在哪里可以找到有关此语法的文档?

答案摘要

@Mark 指出该构造记录在 V5 Mathematica 书的第 2.8.6 节V5.2 Mathematica 书的第 2.8.7 节中也提到了它。在这两个位置,文档指出 Mathematica 会忽略字符串中的换行符和后续制表符 - 除非它们包含在 \<\> 之间,在这种情况下保留换行符(但不保留制表符)。

V6 文档的相应部分中,它指出换行符保留在字符串中。因此,从 V6 开始似乎不再需要转义语法——因此不再记录。

请注意,许多笔记本仍然在内部使用此语法,即使在 V8 中也是如此。 @Alexey 指出包含换行符的字符串的单元格表达式仍然使用该语法。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦里兽 2024-11-15 02:29:05

最新版 The Mathematica Book 的 2.8.6 节对此进行了简要提及。当然,这是 Mathematica V5 的情况。事实上,我只是在V5.2和V6.0.3中尝试了以下操作:

"Hi
There"

结果截然不同。特别是,V5.2 返回一行,没有换行符。 V6.0.3 返回两行,其中换行符的格式符合预期。 V6 中的字符串得到了显着改进,因此也许“\<...\>”不再需要构造。

也许我使用 Mathematica 的时间太长了。 :)

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. :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文