[Tex/LaTex] Very strange result while writing a trace of matrix

matrices

My Jacobian matrix evaluated at the equilibrium is denoted by J_E. I typed for its trace as

tr\textit{J_E}.

And the result is very strange. tr appears good but \textit{J_E} part is unlimitedly repeated with its size gradually decreasing.

It looks something like:

Like this

where the J_E part is gradually getting smaller.

What is happening here?

Best Answer

Why should you type \textit{J_E}? This is wrong for several reasons.

  1. _ requires math mode and the argument to \textit is typeset in text mode (as the command name suggests).

  2. \textit is the wrong command for typesetting a math variable: math mode should be used.

  3. You're right that “tr” for the trace should be in upright type, but typesetting a formula not in math mode just for this is misusing the tool.

\documentclass{article}
\usepackage{amsmath}

\DeclareMathOperator{\tr}{tr}

\begin{document}
$\tr J_{E}$ is the trace of $J_{E}$.
\end{document}

Now, why the four repetitions? You first of all get an error message that says

! Missing $ inserted.
<inserted text> 
                $
l.8 \textit{J_E}

(the line number can be different, of course). After this the output is unpredictable, because when TeX discovers the error it's too late for doing a sensible fix.