解决 Mathematica Notation 错误的方法?

发布于 2024-08-23 04:00:09 字数 355 浏览 9 评论 0原文

Mathematica 提供了 Notation 包来定义自定义符号,它似乎工作得很好,直到我将带有自定义符号的笔记本保存为包并尝试使用 Needs["..."] 导入新的符号。正如 Mathematica 邮件列表 中所述,这会导致奇怪的语法错误在评估对 Notation[] 的任何调用时。建议的解决方案是手动打开符号笔记本并将其评估到内核中,但这对于我计划分发的文件来说是一个痛苦。如果有人有更好的解决方法来解决该问题,我将非常感谢您的帮助!

Mathematica offers the Notation package to define custom notation, and it seems to work great until I save a notebook with custom notation as a package and try to use Needs["..."] to import the new notation. As documented on the Mathematica mailing list, this causes bizarre syntax errors when evaluating any call to Notation[]. The suggested solution is to manually open the notation notebook and evaluate it into the kernel, but this is a pain for files that I plan on distributing. If anyone has a better workaround for the problem, I'd really appreciate the help!

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

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

发布评论

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

评论(1

风月客 2024-08-30 04:00:09

我认为你的问题在于 Mathematica 处理 Notation[] 的方式,引用

当定义你自己的符号时,它是
使用至关重要
符号模板。原因是
这个限制是模板
粘贴到笔记本中包含
嵌入的基本标签框
正确的方法。

可能根本不可能有一个包文件调用 Notation[],但建议使用 ParsedBoxWrapper 我现在没有时间玩。

对于您的问题,有一种笨拙的解决方案,即您将所有 Notation[] 分配放入笔记本的一个单元格中,并将其设为初始化单元格(右键单击单元格边缘 -->初始化单元)。顺便说一句,这还会创建一个仅包含该单元格内容的 .m 文件(但遗憾的是,该文件无法与 Needs[]<< 一起使用) 。之后,您可以折叠单元格,使其不可编辑、不可评估,然后嘿,快点!和你想要的差不多。

我应该注意到,从分发的角度来看,这种拼凑相当不错,因为每次加载主文件时都会重新生成 .m 文件,因此您不需要发送多个文件。唯一的缺点是笔记本有点丑(即一个隐藏单元),并且每当您第一次评估该笔记本中的某些内容时,都会弹出一个窗口询问您是否要评估该笔记本的初始化单元。

I think your problem lies in the way Mathematica treats Notation[], quote:

When defining your own notations it is
critically important to use the
notation templates. The reason for
this restriction is that the templates
pasted into a notebook contain
essential tag boxes embedded in the
correct way.

It may not be possible at all to have a package file call Notation[], but there is a suggestion of using ParsedBoxWrapper which I didn't have time to play around with right now.

There is a kludgy solution to your problem, which is that you put all the Notation[] assignments into one cell of the Notebook and make it an initialization cell (right click on the cell edge --> Initalization Cell). This will incidentally also create a .m file with just the contents of that cell (but this file will, alas, not work with Needs[] or <<). After that you can collapse the cell, make it uneditable, unevaluatable, and hey presto! Almost like what you want.

I should note that from a distribution point of view this kludge is rather nice since the .m file gets regenerated every time you load the main file so you don't need to ship multiple files. The only downside is a slightly ugly Notebook (i.e. one hidden cell), and a pop up asking whether you want to evaluate the initialization cells of the Notebook whenever you first evaluate something in that Notebook.

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