是否可以从命令行调用 Mathematica 的 diff 功能?

发布于 2024-12-18 20:28:27 字数 1646 浏览 4 评论 0原文

TortoiseSVN (以及 其他 Tortoise 客户端)包括 脚本diff 笔记本文件数学。 Mathematica 的差异功能在 AuthorTools 包中实现(也许有更好的东西?)

该脚本当前的工作方式是在临时目录中创建一个小笔记本文件,然后在前端打开它。笔记本电脑有一个大按钮,可以进行比较,并且可以对文件名进行硬编码比较。

缺点是带有 diff 代码的笔记本将保留在临时目录中,并且不会被清理。每次我们进行比较时似乎也没有必要打开辅助笔记本。

是否可以从命令行启动 diff 功能以避免浏览临时笔记本?或者是否有任何其他强大方法来改进此过程并避免临时文件夹中乱放辅助笔记本?

欢迎提出任何改进比较体验的建议!

请注意,由于 TortoiseSVN 是一个 Windows 程序,因此我主要对基于 Windows 的解决方案感兴趣。


这是脚本生成的示例笔记本。我意识到它需要清理,但上次我检查它在版本 5 中也能工作(!),所以我不想不必要地触及它(没有明显改进的东西)。

Notebook[{ 
  Cell[BoxData[ButtonBox["\<\"Compare Notebooks\"\>", 
       ButtonFrame->"DialogBox", Active->True, ButtonEvaluator->Automatic,
       ButtonFunction:>(Needs["AuthorTools`"]; NotebookPut[Symbol["NotebookDiff"]["one.nb", "two.nb"]])
  ]], NotebookDefault] },
  Saveable->False, Editable->False, Selectable->False, WindowToolbars->{}, 
  WindowFrame->ModelessDialog, WindowElements->{}, 
  WindowFrameElements->CloseBox, WindowTitle->"Diff", 
  ShowCellBracket->False, WindowSize->{Fit,Fit}
]

TortoiseSVN (as well as other Tortoise clients) include a script to diff notebook files in Mathematica. Diff functionality for Mathematica is implemented in the AuthorTools package (perhaps there is something better?)

The script currently works by creating a small notebook file in the temp directory, and opening it in the front end. The notebook has a big button that will do the diff and has the file names to be diffed hard coded.

A disadvantage is that the notebook with the diff code will be left in the temp directory, and won't be cleaned up. It also seems unnecessary to have an auxiliary notebook open every time we do a diff.

Is it possible to launch the diff functionality from the command line to avoid going through the temporary notebook? Or is there any other robust way to improve this process and avoid littering the temp folder with auxiliary notebooks?

Any suggestions to improve the diffing experience are welcome!

Note that since TortoiseSVN is a Windows program, I am primarily interested in Windows-based solutions.


Here's an example notebook that the script generates. I realize it's in need of cleanup, but last time I checked it worked in version 5 too (!), so I did not want to touch it unnecessarily (without visibly improving something).

Notebook[{ 
  Cell[BoxData[ButtonBox["\<\"Compare Notebooks\"\>", 
       ButtonFrame->"DialogBox", Active->True, ButtonEvaluator->Automatic,
       ButtonFunction:>(Needs["AuthorTools`"]; NotebookPut[Symbol["NotebookDiff"]["one.nb", "two.nb"]])
  ]], NotebookDefault] },
  Saveable->False, Editable->False, Selectable->False, WindowToolbars->{}, 
  WindowFrame->ModelessDialog, WindowElements->{}, 
  WindowFrameElements->CloseBox, WindowTitle->"Diff", 
  ShowCellBracket->False, WindowSize->{Fit,Fit}
]

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

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

发布评论

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

评论(1

梦与时光遇 2024-12-25 20:28:27

这是使用 Mathematica 脚本生成笔记本差异的简单示例。

将以下内容保存为 diff.m

Needs["AuthorTools`"]
If[Length[$ScriptCommandLine]>=3, 
    {f1, f2} = $ScriptCommandLine[[{2,3}]], 
    {f1, f2} = {"one.nb", "two.nb"}]
diff = FileNameJoin[{$TemporaryDirectory, "diff.nb"}]
Put[NotebookDiff[f1, f2], diff]
Run["Mathematica " <> diff]
DeleteFile[diff]
Exit[]

然后使用 MathematicaScript -script diff.m "one.nb" "two.nb" 从命令行调用它。这适用于我的系统(Ubuntu 11.10、Mathematica 8.0.1)并且应该与平台无关。
如果您使用的 Mathematica 版本早于 v8,那么您必须使用 MathKernel -noprompt -run diff.m 而不是 MathematicaScript 并且将使用 {f1, f2} 的默认值。

Here's a simple example of producing the notebook diff using a Mathematica script.

Save the following as diff.m

Needs["AuthorTools`"]
If[Length[$ScriptCommandLine]>=3, 
    {f1, f2} = $ScriptCommandLine[[{2,3}]], 
    {f1, f2} = {"one.nb", "two.nb"}]
diff = FileNameJoin[{$TemporaryDirectory, "diff.nb"}]
Put[NotebookDiff[f1, f2], diff]
Run["Mathematica " <> diff]
DeleteFile[diff]
Exit[]

Then call it from the command line using MathematicaScript -script diff.m "one.nb" "two.nb". This works on my system (Ubuntu 11.10, Mathematica 8.0.1) and should be platform independent.
If you're using a version of Mathematica older than v8, then you'd have to use MathKernel -noprompt -run < diff.m instead of MathematicaScript and the default values for {f1, f2} will be used.

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