# Managing variable names in notebooks?

**URL:** <https://community.wolfram.com/t/managing-variable-names-in-notebooks/17697>\
**Category:** Questions\
**Tags:** mathematica, computational-notebooks\
**Created:** [February 26, 2021, 7:33pm UTC](https://community.wolfram.com/t/managing-variable-names-in-notebooks/17697 "2021-02-26T19:33:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jgourle2](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/jgourle2/32/4175_2.png) [@jgourle2](https://community.wolfram.com/u/jgourle2)\
**Post date:** [February 26, 2021, 7:33pm UTC](https://community.wolfram.com/t/managing-variable-names-in-notebooks/17697/1 "2021-02-26T19:33:44Z")

</div>

I’m new to Mathematica. Where do I find documentation explaining how functions and variables that I define are handled when I have multiple notebooks open? I need to know things like:

1. How do I list names I’ve defined in a specific notebook? For  
instance, I define f:=x^2 and y=x. I want an easy way to see  
that names f and y are defined.
2. What is the Mathematica terminology that distinguishes between names  
I’ve used (like x above) verses names that have assigned meaning  
(like f and y above)?
3. How do I get Mathematica to remind me what the definition of f in  
this notebook, as opposed to telling me what f is in all open  
notebooks?
4. Is there a way to partition a notebook so that names don’t interfere  
with each other?

---

<div class="post-metadata">

**Author:** ![mikebesso](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/mikebesso/32/22282_2.png) [@mikebesso](https://community.wolfram.com/u/mikebesso)\
**Post date:** [February 26, 2021, 7:50pm UTC](https://community.wolfram.com/t/managing-variable-names-in-notebooks/17697/2 "2021-02-26T19:50:03Z")

</div>

Jay: You will find the answer to all of your questions in the documentation.

One thing to note, is by default, all of your open notebooks share the same kernel. Therefore, the same names are defined in all open notebooks. Of course, there are ways to override this default setting, but I have found it to be useful.

As a starting point, check out the [Names[] function](https://reference.wolframcloud.com/language/ref/Names.html).

---

<div class="post-metadata">

**Author:** ![jfklein](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/jfklein/32/6867_2.png) [@jfklein](https://community.wolfram.com/u/jfklein)\
**Post date:** [February 26, 2021, 8:11pm UTC](https://community.wolfram.com/t/managing-variable-names-in-notebooks/17697/3 "2021-02-26T20:11:25Z")

</div>

You should also be aware of “contexts”. In a notebook, the current context is `Global` `, given by `$Context`. If you want to get a list of symbols you have created, evaluate `Names["Global`\*"]`.

Some theory that may be helpful: there’s a concept in programming of static vs. dynamic. Static things are those you can read in the source, which in this case is the notebook. Dynamic is the things that happen at runtime. When you ask “what variables have I defined in my notebook”, it’s a static question. If you really mean “what variables have I defined so far”, it’s a dynamic question. The `Names` function is answering the dynamic question.

Partitioning different parts of the notebook will not be very convenient, in my estimation, but of course you can do it. Generally you can partition symbols by putting them in different contexts. You can do this by using packages (BeginPackage or Begin). But if you use the same “simple” name, like `x`, in different contexts, but both contexts are on the $ContextPath, you’ll get a shadowing error: only one `x` from one context can “win” (be the one that gets used) and the other symbol(s) will be shadowed (hidden). The one that wins, that gets used, is the one whose context comes first on the $ContextPath. The way to resolve the ambiguity is to “fully qualify” the variable name (basically like adding a last name to differentiate two people with the same first name), like `Section1`x` or `Section2`x`. Usually what I would do is just use longer names.

---

<div class="post-metadata">

**Author:** ![rohitnamjoshi](https://avatars.discourse-cdn.com/v4/letter/r/f1d935/32.png) [@rohitnamjoshi](https://community.wolfram.com/u/rohitnamjoshi)\
**Post date:** [February 26, 2021, 10:01pm UTC](https://community.wolfram.com/t/managing-variable-names-in-notebooks/17697/4 "2021-02-26T22:01:27Z")

</div>

Hi Jay,

When I share a notebook with someone else I add an initialization cell with

```
CurrentValue[$FrontEndSession, CellContext] = Notebook

```

so any symbol definitions are scoped to a unique context specific to the notebook. That way I don’t pollute their `Global` context with my stuff and vice-versa.

I prefer working with notebook specific contexts all the time. The setting can be make permanent by evaluating

```
CurrentValue[$FrontEnd, CellContext] = Notebook

```

---

<div class="post-metadata">

**Author:** ![churchboy316](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/churchboy316/32/11164_2.png) [@churchboy316](https://community.wolfram.com/u/churchboy316)\
**Post date:** [February 28, 2021, 6:51am UTC](https://community.wolfram.com/t/managing-variable-names-in-notebooks/17697/5 "2021-02-28T06:51:27Z")

</div>

I do a lot of practice with two or three notebooks open. So I simply clear all Global Variables at the beginning of each document, ClearAll[“Global`\*”]. Useful for stuff only I’m going to see.
