4

For some reason, when I try to run this code in LaTeX, it gives the error: File ended while scanning use of \frac

I don't see my mistake. Also, my editor gives a warning considering the label: Reference 'eq6' on page 4 undefined. I assume it is, because I am using the reference before the label. But I want to name the formula in the text, before giving the formula.

\documentclass[11pt,a4paper, oneside]{article}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage[free-standing-units]{siunitx}

\begin{equation} 
D_3 = -10 \log(\frac{P_2(2 f_{1,2} \pm f_{2,1}){P_2({f_1,f_2)})
\label{eq6}
\end{equation}
2
  • 2
    As it says, you have not closed your first pair of \frac braces. Should be \frac{P_2(2 f_{1,2} \pm f_{2,1})}
    – Au101
    Feb 1, 2017 at 19:19
  • 2
    ... and there is a spurious { before f_1 in the denominator. Feb 1, 2017 at 19:32

2 Answers 2

5

Solution

As Au101 already pointed out: There was a } missing and according to Ian Thompson a { too much. (Sorry Ian, for having missed your comment.)

Also, for this code to compile, you don't need any extra package in your MWE. Instead the \begin{document} ... \end{document} was missing.

To get nicer braces, you should use \left and \right before the (). Remember: you have to use \left and \right always in combination. You can't use the one without the other. The delimiters though don't have to match. You can combine \left( with \right\updownarrow, just to name an example. Hence, I also added those.

Example Code

\documentclass[11pt,a4paper, oneside]{article}

\begin{document}
\begin{equation} 
  D_3 = -10 \log \left(\frac{P_2(2 f_{1,2} \pm f_{2,1})}
     {P_2(f_1,f_2)}\right)
\label{eq6}
\end{equation}
\end{document}

Result

enter image description here

4
  • 2
    This is a really nice answer (+1) and I appreciate the credit, but I can only take credit for half of the diagnosis, Ian Thompson did the rest :)
    – Au101
    Feb 1, 2017 at 19:51
  • 1
    You may also want to point out that the parentheses around the \frac expression are strictly optional.
    – Mico
    Feb 1, 2017 at 19:52
  • @Mico, I must confess, that I am not a mathematician. You are correct, that it seems to be logical, that the log must be acting on the fraction. But it may also be convenient or even usual in some disciplines. I can not tell. It was present in the authors question, so I corrected it.
    – Jan
    Feb 1, 2017 at 19:57
  • 1
    @Au101: The comment came while I was typing and coding. Thank you, that you pointed me at it. I edited my answer.
    – Jan
    Feb 1, 2017 at 19:58
4

See the fixes below. The example includes the same equation using the mathtools package which makes it easier to keep track of brackets of various sorts.

\documentclass{article}

\usepackage{mathtools}
\DeclarePairedDelimiter{\parens}()
\begin{document}


\begin{equation} 
D_3 = -10 \log(\frac{P_2(2 f_{1,2} \pm f_{2,1})}{P_2(f_1,f_2)})
\label{eq1}
\end{equation}


\begin{equation} 
D_3 = -10 \log\parens[\bigg]{\frac{P_2\parens{2 f_{1,2} \pm f_{2,1}}}{P_2\parens{f_1,f_2}}}
\label{eq2}
\end{equation}

Easier not to ef up the brackets with \eqref{eq2} than it is with \eqref{eq1}.
\end{document}

enter image description here

You must log in to answer this question.