5
$\begingroup$

I have two quite large notebooks with minimal differences. To compare them, I currently put them side by side and compare with my eyes, which feels quite inefficient. What are better ways to do this?

I have done some searching but only found questions from 8/9 years ago, they didn't work for me. In Mathmatica 12 I could not find a function like "Notebookdiff" and I also do not use Wolfram Workbench.

$\endgroup$
5
  • 2
    $\begingroup$ Mathematica notebooks are filled with formatting and meta data so comparing the .nb-Files in a text editor might be quite difficult. One possibility would be to export the two notebooks as .txt which should work fine for input and output cells containing text. Comparing those files with a text editor might be an option depending on what kind of content is in the notebooks.The underlying problem here is the same one preventing versioning tools (git,...) from working efficiently/properly. $\endgroup$
    – N0va
    Commented Nov 30, 2020 at 13:54
  • $\begingroup$ At least closely related: How to effectively diff a notebook? see also: github.com/JP-Ellis/mathematica-notebook-filter $\endgroup$
    – Kuba
    Commented Nov 30, 2020 at 22:17
  • $\begingroup$ @Kuba Thats one of the old questions I was referring to - the github project you are linking looks interesting, but it hasn't been updated in a while and according to the CI Pipeline it's broken. $\endgroup$
    – abti
    Commented Dec 1, 2020 at 10:40
  • $\begingroup$ Since you didn't link them let me leave them. There were talks about GitLink`NotebookDiff but that package is not evolving too fast on GitHub. $\endgroup$
    – Kuba
    Commented Dec 1, 2020 at 12:39
  • $\begingroup$ There is notebook diffing coming in 14.1 later this summer $\endgroup$
    – user5601
    Commented Jun 5 at 4:13

1 Answer 1

1
$\begingroup$

If you want to compare the input lines in 2 notebooks, go to File/Save As and save the notebooks as "wolfram language script". The .wls is very clean and easy to compare with any line-by-line text compare tool.

At least in version 14.0 File/Save as "text" doesn't differentiate input and output, and contains all output from when the notebook last ran. It is very noisy.

Each section of inputs in the .wls file from a notebook begins with

(* ::Input:: *)

--- various input lines ---

(**)

It often ends before the (**) but sometimes the input lines are after the (* *)

There are sections for explicitly printed lines that begin with (* ::Print:: *)

Git diff works really well. Any command-line tool you know will work.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.