This might be a stupid question but I simply don't get my head around this. I'm trying to define variables and functions in different files (tried everything: nb, m, ...) and include them for use in a NoteBook (or whatever would work).

Mathematica seems to overcomplicate everything. I simply want to include code which is written in one file into another! Can't be that hard... But obviously I did not understand the very concept of using this properly.

Here's what I have so far:

This is my config.m


BranchName::usage = "Returns Branch Name";
BranchInfo::usage = "Retruns Branch Info";
PrimaryVariables::usage = "use";

BranchName = "TAPIR 1D - Atmospheric Accretion around Planets";
BranchInfo = 
"Dynamical accretion of primordial atmospheres around planets.";
PrimaryVariables = {
{1, R, "MR", "Grid Equation"},
{2, m, "MM", "Poisson Equation"},
{3, rho, "MD", "Continuity Equation"},
{4, rhoAv, "MDa", "Continuity Equation (averaged density)"},
{5, e, "ME", "Energy Equation (internal gas energy density)"},
{6, u, "MU", "Equation of Motion"},
{7, J, "MJ", "Equation of Radiation-Flux Energy Density"},
{8, H, "MH", "Equation of Radiation-Flux"},
{9, uT, "MT", "Equation of Turbulent Convection"}

(* Protect Config Variables *)


This then should be called from my notebook: test.nb

<< config.m;


What is it what I don't understand?


Update ---

Sorry totally forgot to add the output. This is it:

  • $\begingroup$ We can't read your mind, so maybe you should tell us what went wrong instead of asking us to tell you what you don't understand? There are many examples of this kind of thing online; here's one example you could look at (github.com/noahbenson/Neurotica), specifically the Installation section of the main README/page. $\endgroup$
    – nben
    Commented Mar 2, 2018 at 16:16
  • $\begingroup$ Hi! Thank's for the link but unfortunately this is not what I was looking for. It does not really explain how to use packages. $\endgroup$ Commented Mar 2, 2018 at 16:30
  • 1
    $\begingroup$ Did you make all the code input cells in your package file initialization cells before you saved it? $\endgroup$
    – m_goldberg
    Commented Mar 2, 2018 at 16:32
  • $\begingroup$ I guess not. How do I do that? When I go to Cell->Convert To I only have the options: InputForm, Raw InputForm, OutputForm, StandardForm, TraditionalForm, Bitmap $\endgroup$ Commented Mar 2, 2018 at 16:36
  • $\begingroup$ I do see it in the Notebook as I used the variable in order to show me the content. Like if I define a=1 and evaluate, i will get 1 as an output $\endgroup$ Commented Mar 2, 2018 at 16:47

1 Answer 1


I finally found the solution! Thanks to @m_goldberg it was simly because the cell was not formatted as initialization cell.

So if anyone followed all the tutorials but was missing out this part just select the cell(s) which contain your code and go to

Cell->Cell Properties->Initialization Cell


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