TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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}
share|improve this question
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 11 hours ago
2  
... and there is a spurious { before f_1 in the denominator. – Ian Thompson 11 hours ago
up vote 6 down vote accepted

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

share|improve this answer
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 11 hours ago
1  
You may also want to point out that the parentheses around the \frac expression are strictly optional. – Mico 11 hours ago
    
@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 11 hours ago
1  
@Au101: The comment came while I was typing and coding. Thank you, that you pointed me at it. I edited my answer. – Jan 11 hours ago
    
thank you so much! – Luk 10 hours ago

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.