1
$\begingroup$

I am developing a project where I have a lot of functions and complex tasks rannanble from a single notebook. I would like to use a version control like git, but using it with a single notebook is not ideal, as the notebook increases the size of the project, having a lot of lines changing even without having edited something, plus it's a single file. I tried to save it as .m and then running Import[file.m] or something like that from another notebook, but the m file won't get run when loaded. If I set it as "initialization group" before saving it to .m, then it load succesfully. I wanted to ask if there are other ways to obtain what I want. Note that, I tried several times in the past to convert my notebooks in what are called mathematica packages, but this never seems to work, I think it's because of the context of the variables. My tasks usually get messed up when the notebook is converted into a package. I would prefer just something simper that lets me load the .m file and that's it.

$\endgroup$
4
  • $\begingroup$ Please be specific about what the problem is. First you say that setting cells to be initialization cells works. Then you ask if there is another way. Why is this way not good? Then you say "it never seems to work", contradicting your earlier statement that it worked. $\endgroup$
    – Szabolcs
    Commented May 18, 2020 at 9:44
  • $\begingroup$ Get will simply evaluate all Mathematica code present in a plain text file. How you edit or create that plain text file is up to you. You can use Mathematica's editor, or another editor. You can write in it directly, or you can copy and paste from a notebook. $\endgroup$
    – Szabolcs
    Commented May 18, 2020 at 9:48
  • 2
    $\begingroup$ A plain text file is not really a "package". It's just that: a file with Mathematica code in it, which you can conveniently evaluate with Get. If you want to create a proper package, you must follow certain conventions. However, this is not generally necessary to create a proper package if all you want is to evaluate a bunch of definitions at the same time. For that, simply write the definitions in a text file, ideally use the .m or .wl extesnions (not strictly necessary) and then load it with Get. $\endgroup$
    – Szabolcs
    Commented May 18, 2020 at 9:49
  • $\begingroup$ Using version control with notebooks has certain prerequisites. $\endgroup$
    – Alan
    Commented May 18, 2020 at 12:55

0

Your Answer

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

Browse other questions tagged or ask your own question.