# Using of functions and lists from other Mathematica files

I have a code in which I have to use some functions and lists and use them in the body of the code. If I want to type all of them in a file in Mathematica, that file becomes very very long. For example, I have

Func1[x1_,x2_,x3_,x4_,x5_]:=f(x1,x2,x3,x4,x5);
Func2[x1_,x2_,x3_,x4_,x5_]:=f(x1,x2,x3,x4,x5);
Func3[x1_,x2_,x3_,x4_,x5_]:=f(x1,x2,x3,x4,x5);
Func4[x1_,x2_,x3_,x4_,x5_]:=f(x1,x2,x3,x4,x5);
Func5[x1_,x2_,x3_,x4_,x5_]:=f(x1,x2,x3,x4,x5); ...

List1={...};
List2={...};
List3={...};
List4={...};
List5={...}; ...

the body of my code...


I have to use them these functions and lists in the body of my code. Is it possible to type those functions and lists in a separate file and call them in the body of the code then use them?

• – kglr Sep 22 '18 at 18:21
• If you have the expressions already in another notebook, then you can just evaluate that notebook using NotebookEvaluate. – bill s Sep 22 '18 at 18:27
• Could you please give me a simple code as an example? – AYBRXQD Sep 22 '18 at 18:35

## 1 Answer

Say you have a notebook called "stuff.nb". In my case, I made one that has a single line:

a=100;


Now in another notebook (located in the same directory as stuff.nb), evaluate:

NotebookEvaluate[NotebookDirectory[] <> "stuff.nb"]


Everything in stuff.nb is evaluated and so $$a$$ takes on the value $$100$$. If you are not in the same directory, then you would need to use the correct path to get to stuff.nb

• Is there a way to hide this code in a notebook so it executes but are not shown at print out? I would like to have the PDF clean of "initiations" and only relevant computations for the reader to see. – mf67 Sep 23 '18 at 2:46
• Thanks dear @bill s – AYBRXQD Sep 23 '18 at 4:21
• @mf67 -- Place it in an initialization cell and close the cell. Then it will be executed when you first run something in the new notebook. – bill s Sep 23 '18 at 14:28