The methods suggested by David and István already do the job perfectly, but one could add something to the collection:

As described in the documentation on Operators without Built-in Meanings, there are some two-dimensional forms such as `Subscript`

and `UnderBar`

which can be re-defined to your liking. This is particularly useful if you need the 'N' with additional decorations anyway, such as $\text{N}_1$, $\text{N}_\text{total}$ or $\underline{\text{N}}$.

For these kinds of symbols you don't re-define `N`

directly, but instead add a definition that is associated with the two-dimensional form in which the symbol appears. For example, I can set the following (note that the form `Subscript["N", 0]`

can be entered more conveniently using keyboard shortcuts, but that wouldn't display so nicely here):

```
ClearAll[Subscript];
Subscript["N", 0] = 6
(* ==> 6 *)
7 Subscript["N", 0]
(* ==> 42 *)
DownValues[Subscript]
(* ==> {HoldPattern[Subscript["N", 0]] :> 6} *)
```

The last line shows how the definition is stored as a definition associated with `DownValues[Subscript]`

. The fact that we get `42`

from the multiplication shows that the definition of the subscript works as expected.

To erase the definition, I can either use `ClearAll[Subscript]`

or more specifically

```
Subscript["N", 0] =.
```

The shortcut to input the subscript is to type `"N"`

followed by `Ctrl``-`

and then `0`

.

You can also use strings in the subscript, instead of numbers. That allows you to get a "variable" that displays as $N$ without decoration by entering

```
Subscript["N", ""]
```

Again you could assign things to this subscripted form as well. Another use for a string subscript would be (here I'll copy the two-dimensional form in box notation, it should look nicer when copied into the notebook):

```
\!\(\*SubscriptBox[\("\<N\>"\), \("\<total\>"\)]\) = 100
(* ==> 100 *)
Sum[i, {i,
\!\(\*SubscriptBox[\("\<N\>"\), \("\<total\>"\)]\)}]
(* ==> 5050 *)
```

Of course one can use these re-defined operators as a substitute for `Format`

as well. For example, here is some symbolic input and symbolic output:

```
nn = Subscript["N", ""]
```

$\text{N}$

```
Sum[i, {i, nn}]
```

$\frac{1}{2} \text{N}_{\text{}}\left(\text{N}_{\text{}}+1\right)$

You can then keep working with `nn`

as the symbolic variable for computations but get the capital $\text{N}$ in the displayed output.

But you can also do numerical substitutions in the usual way, as here:

```
% /. Subscript["N", ""] -> 100
(* ==> 5050 *)
```

(again, all the expressions looking like `Subscript`

above can be made to appear more naturally by using the two-dimensional keyboard input methods).

Finally, everything I said here about `Subscript`

also applies to things like `UnderBar["N"]`

which displays as $\underline{\text{N}}$.

The `Subscript`

combined with strings can also be useful when defining a whole set of similarly named variables automatically using something like this:

```
normalVector =
Array[Subscript["N", {"x", "y", "z"}[[#]]] &, 3]
```

$\left\{\text{N}_{\text{x}},\text{N}_{\text{y}},\text{N}_{\text{z}}\right\}$

```
Norm[normalVector] /. {
\!\(\*SubscriptBox[\("\<N\>"\), \("\<x\>"\)]\) -> 1,
\!\(\*SubscriptBox[\("\<N\>"\), \("\<y\>"\)]\) -> 0,
\!\(\*SubscriptBox[\("\<N\>"\), \("\<z\>"\)]\) -> 0}
(* ==> 1 *)
```

For even better formatting, you could replace `normalVector`

by `"N"`

`Ctrl`'7' `esc``vec`

`esc` which displays as $\vec{\text{N}}$.

Input and Output are different matters as far as I know. You might and should use defintions starting with a lowercase letter to be on the safe side regarding conflicts but that does not hinder you to format any output like you want it to appear? – gwr – 2012-06-22T10:37:22.990

1Writing up the paper and writing code to do the computations are two different things ... surely the name of the variable can't be that big an issue? Even in a CDF, the visual presentation doesn't need to match the underlying code. You can label stuff using $N$ even if in the code it's represented using a variable of a different name. – Szabolcs – 2012-06-22T10:44:52.337

2You can use

`\[FormalCapitalN]`

instead of`N`

. It looks almost like`N`

. – Artes – 2012-06-22T10:46:42.5073...or

`\[ScriptCapitalN]`

, or`\[CapitalNu]`

, or... why doyouneed $N$ to be a variable anyway? How sure are you that your paperwon'tneed the actual functionality of`N[]`

? – J. M.'s ennui – 2012-06-22T10:59:05.930Here I'm giving you a gun to shoot your self. This is a bad idea. But of course everything is possible:

`Unprotect[N]; N=5; N*3`

– Ajasja – 2012-06-22T11:06:03.1472If you want to display an equation, you could work with

`n`

in intermediate steps and in the final display step do a replacement.`/.n->"N"`

should be save – Sjoerd C. de Vries – 2012-06-22T11:13:53.9637@Ajasja That's not a gun, that's a land mine. At least a gun has a safety catch. – Heike – 2012-06-22T11:32:50.287

1I think this question could be the flagship of all the similar questions about modifying built-in symbols, as it is rather concise and straightforward. There are other ways (like locally redefine symbols) which might worth a mentioning here. – István Zachar – 2012-06-22T12:11:57.520

Thank you very much to all the commenters for their very helpful suggestions. It's true, I don't need to use N as the variable name, but it is quite a common choice to stand for the number of something, e.g. the number of molecules in the kinetic theory of gases. The question applies if I wanted to give a formula incorporating the natural-seeming "N" as might be found in conventional textbooks, while also using Mathematica to differentiate it, plot it, etc. In the past, I have worked around by using a different symbol, but I wondered if there was another way. – Marc Widdowson – 2012-06-22T13:41:48.397

Related: (117)

– Mr.Wizard – 2016-09-06T20:17:51.250