TortoiseSVN (以及 other Tortoise clients )包括一个 script至 diff Mathematica 中的笔记本文件。 Mathematica 的 Diff 功能在 AuthorTools 中实现包(也许有更好的东西?)
该脚本目前通过在临时目录中创建一个小笔记本文件并在前端打开它来工作。笔记本有一个大按钮,可以进行差异,并具有要进行硬编码的文件名。
一个缺点是带有 diff 代码的笔记本将留在临时目录中,并且不会被清理。每次我们做 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}
]
最佳答案
这是一个使用 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)并且应该是独立于平台的。如果您使用的是早于 v8 的 Mathematica 版本,那么您必须使用
MathKernel -noprompt -run < diff.m
而不是 MathematicaScript
和 {f1, f2}
的默认值将会被使用。
关于tortoisesvn - 是否可以从命令行调用 Mathematica 的 diff 功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8313379/