[Tex/LaTex] Missing $ inserted. Extra }, or forgotten $. Missing } inserted

math-mode

I know this gets asked pretty often but I can not find my error. And since the code renders just fine I am really at odds here.

\begin{equation} 
 \frac{\Delta {f}}{f} = -\frac{\pi\textrm{r^3}}{W} \frac{\epsilon_r-1}{\epsilon_r+2}\epsilon_0{|{E_0}^2|}
 \label{eq. 5}
\end{equation}

Best Answer

The \textrm{...} command converts the contents of command to text mode, consequently r^3 cannot work. Instead it you should use \marthrm{r^3} as suggested @Sebastiano in his answer (+1) or better and more correct \mathrm{r}^3 as suggested @GuM in his comment. However, I wonder why you like to write variable in roman shape. They are usually written in italic shape. So to my opinion is better write your equation as follows:

\documentclass{article}
\usepackage{mathtools}
\DeclarePairedDelimiter\abs{\lvert}{\rvert} % new, it better align vertical bars

\begin{document}
\begin{equation}
 \frac{\Delta{f}}{f} 
    = - \frac{\pi r^3}{W} 
        \frac{\epsilon_r - 1}{\epsilon_r + 2}\epsilon_0 \abs*{E_0^2}
 \label{eq. 5}
\end{equation}
\end{document}

which gives:

enter image description here

If you persist to use upshape r, than you need to be consistent:

\documentclass{article}
\usepackage{mathtools}
\DeclarePairedDelimiter\abs{\lvert}{\rvert}

\begin{document}
\begin{equation}
 \frac{\Delta{f}}{f} 
    = - \frac{\pi \mathrm{r}^3}{W} 
        \frac{\epsilon_{\mathrm{r}} - 1}{\epsilon_{\mathrm{r}} + 2}\epsilon_0 \abs*{E_0^2}
 \label{eq. 5}
\end{equation}
\end{document}

which gives:

enter image description here