1
$\begingroup$

Mathematica is using definitions from other open files in the same folder.

I want variables not defined in a particular file to be treated as undefined variables. I do not want Mathematica to pick the expression of these variables from other files. Is there any way to go about this?

$\endgroup$
  • $\begingroup$ Maybe run Exit[] in your current notebook before you execute anything else in it? That should unload all the definitions. $\endgroup$ – Shredderroy Jun 28 '18 at 7:42
  • $\begingroup$ @Shredderroy That works. Thanks! $\endgroup$ – cord Jun 28 '18 at 7:47
  • $\begingroup$ Have a look to this question, you can also set a context "unique to this Notebook" $\endgroup$ – rhermans Jun 28 '18 at 7:49
  • $\begingroup$ @rhermans Thanks for the second link. Changing the global policy for CellContext to "Notebook" does exactly what I was looking for. $\endgroup$ – cord Jun 28 '18 at 7:56
3
$\begingroup$

Set the option value for CellContext to Notebook:

SetOptions[EvaluationNotebook[], CellContext -> Notebook]

Use $FrontEndSession (respectively, $FrontEnd) in place of EvaluationNotebook[] for the option setting to apply to all the notebooks in the current session (respectively, to all notebooks globally).

enter image description here

$\endgroup$
  • $\begingroup$ This works, but changing the default global policy for CellContext was more convenient for me. Link for future reference $\endgroup$ – cord Jun 28 '18 at 8:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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