# Extra } or forgotten $in equation with begin{cases} I've been staring at this for an hour now and don't see why I'm getting this error....can anyone help? $k_\alpha = \begin{cases}
\frac{\log n}{\log \frac{n \log n}{m}} \left(1 + \alpha \frac{\log^2 \frac{n \log n}{m}}{\log \frac{n \log n}{m}} \right), & \text{if $\frac{n}{\text{polylog}(n)} \leq m \ll n \log n$} \\
\frac{m}{n} + \alpha \sqrt{2 \frac{m}{n} \log n} & \text{ if }n \log n \ll m \leq n \dot \text{polylog}(n) \\
\frac{m}{n} + \alpha \sqrt{2 \frac{m}{n} \log n \left( 1 - \frac{1}{\alpha} \frac{\log^2 n}{2 \log n} right)}, & \text{if $m \gg n \log(n)^3$}
\end{cases}$ • You ahould post a whole (almost) compilable document, so that folks here can cut and paste to test. One possible problem: you are writing inline mathematics with $ ... $. Perhaps you need display mode $...$ And there are way too many internal $...$. Once you're in a math environment for cases you don't need any of those. Finally: try debugging with a really small example, not this long one. – Ethan Bolker May 2 '17 at 23:14 • Not helpful to debug a simple example, my problem is with this one. I need the$ $b/c they are inside \text{ } – user341502 May 2 '17 at 23:32 • @user341502 It is helpful to debug this simple example because people need to try this in order to see the exact behavior of TeX. TeX reports much more than only "extra } or forgotten$" and these messages can help. If somebody want to help you, he need to add these \documentclass etc. Note that the accepted answer includes full document. – wipet May 3 '17 at 6:37

You had wrong nesting of \text and math in the second line.

I suggest to use dcases* from mathtools, which automatically typesets the “conditions” part in text mode and use display style for the “formula” part.

\documentclass{article}
\usepackage{amsmath,mathtools}

\DeclareMathOperator{\polylog}{polylog}

\begin{document}

$k_\alpha = \begin{dcases*} \frac{\log n}{\log \frac{n \log n}{m}} \left( 1 + \alpha \frac{\log^2 \frac{n \log n}{m}} {\log \frac{n \log n}{m}} \right), & if \dfrac{n}{\polylog(n)} \leq m \ll n \log n \\ \frac{m}{n} + \alpha \sqrt{2 \frac{m}{n} \log n} & if n \log n \ll m \leq n\polylog(n) \\ \frac{m}{n} + \alpha \sqrt{2 \frac{m}{n} \log n \left( 1 - \frac{1}{\alpha} \frac{\log^2 n}{2 \log n} \right)}, & if m \gg n \log^3 n \end{dcases*}$

\end{document}


Note also the definition for \polylog. I removed the multiplication sign which you probably used because of bad spacing with \text{polylog} and should have been \cdot (not \dot). I also changed \log(n)^3 into \log^3 n for consistency.

• @egreg: I tried almost the same solution, with \DeclareMathOperator, and I can see there's a spacing problem between n and polylog, which isn't the same as between n and log. Do you know the reason for this? – Bernard May 2 '17 at 23:45
• @Bernard: Probably n \dot \polylog(n) is not what was actually intended… ;-) – GuM May 2 '17 at 23:53
• @GustavoMezzetti Most likely! I'll fix it later. – egreg May 3 '17 at 6:03

At least part of your difficulty keeping track of the $ signs is in contructions like \text{if$\frac{n}{\text ...

which should be

\text{ if } \frac{n}{\text ...


so that don't have to enter math mode inside the \text{ } .

• To the contrary, I find it recommendable. – egreg May 3 '17 at 6:20
• @egreg I understand that it makes somewhat more semantic sense that way, but I think it's much harder to get right. I guess we see the tradeoff differently. That said, I'm a little hesitant to disagree with someone with your well deserved reputation, who's helped me a lot here. – Ethan Bolker May 3 '17 at 12:05