# Using symbol “_” in subscript, mathmode

Need to use a variable "n_" in mathmode, which returns error in case to be coded like $n_{ _}$

• Welcome to TeX.SX! Please always show a minimal but working example instead of only a code snippet and please always cite the exact error message you get. Without those information we need to speculate instead of being able to analyze the problem and show you a verified solution. – Schweinebacke Oct 14 '17 at 13:38

If you need the symbol _ you can use, e.g., \_ or an \underline with a proper white space argument:

\documentclass{article}

\begin{document}
$n\_$ vs. $n\underline{\enskip}$
\end{document}


IMHO, $n_-$ is most simple and sufficient.

You can use \mathunderscore or \text{$\mathunderscore$}: they are equivalent if the symbol is only used in text style and not in subscripts/superscripts. Take your pick.

\documentclass{article}
\usepackage{amsmath}

\newcommand{\usvarA}[1]{#1\mathunderscore}
\newcommand{\usvarB}[1]{#1\text{$\mathunderscore$}}

\begin{document}

$\usvarA{n}$ and $X_{\usvarA{n}}$

$\usvarB{n}$ and $X_{\usvarB{n}}$

\end{document}