0

I'm using ShareLatex and I was getting a ! Missing $ inserted. error. Saw that there are lots of posts with this topic, but the fixes I found weren't working with my code. The one I didn't try was to tell latex to ignore the problem, and continue, instead of trying to fix it. I eventually found the error provoking text by cutting part of the code and compiling to find where was it coming from (which took a long time). Turns out it was a \mu that ShareLatex was wrapping as $\mu$. The problem was that the error message was saying the error was in the \end{frame} line (not helpful at all), it would've been nice to know in which line the problem was to address it.

  • @jon I don't think it is a complaint about auto-completion. The OP thinks that the Missing $ inserted means that ShareLaTeX is altering the code at compile time and, thus, making the error more difficult to find. I think it is confusion about who the message is from more than anything else. The OP wants to shoot the messenger.... – cfr Sep 17 '15 at 2:01
  • @cfr -- Actually, I think you are right. I only meant to point out that \mu (normally) needs to be in mathmode so the "insertion" is actually on point in a sense (regardless of what entity did the insertion). But my earlier comment is not clear, so I shall delete it. (+1s for the answers instead.) – jon Sep 17 '15 at 2:08
  • @jon Which is entirely right, of course. But I think the OP was complaining that the editor adding in the $ made it harder to figure out where a $ had been missed in the code. So I don't think the need for maths mode was an issue. – cfr Sep 17 '15 at 2:12
  • @cfr this is right, I also wanted to know why that happened and Werner answered that. My problem was that I didn't know greek letters needed to be on math mode, I just thought that if they're letters they didn't need a special mode. – izxle Sep 17 '15 at 2:20
3

You mention \end{frame}, which points to you using beamer (or the like).

beamer reads the entire frame before constructing the content, as it needs to negotiate possible overlay specifications (to break the frame into different slides). As such, since it's read the entire frame, any errors within the frame will translate to point at \end{frame}.

Here is a minimal example replicating your problem:

\documentclass{beamer}
\begin{document}
\begin{frame}
\mu

abc
\end{frame}
\end{document}

Here is another minimal example point to the wrong location for an error:

\documentclass{article}
\usepackage{tabularx}
\begin{document}

\begin{tabularx}{\linewidth}{c}
  \mu \\ a \\ b \\ c
\end{tabularx}

\end{document}

The reason (again) is that tabularx handles the contents within differently than regular tabulars, just like beamer handles frames differently than regular document text.

One way of getting around this (very) particular problem is to redefine the way \mu works:

\let\oldmu\mu
\renewcommand{\mu}{\ensuremath{\oldmu}}

The above makes \mu condition on inserting $s as needed, depending on whether or not it is placed in math or text mode.

  • See this? Maybe fits your answer better? – cfr Sep 17 '15 at 2:35
4

I wonder if there is some confusion here. You report the error

! Missing $ inserted

and ask how to stop ShareLaTeX wrapping your \mu in $s.

But this reflects a misunderstanding. ShareLaTeX is not responsible for the error or the insertion of the dollar sign. This is TeX attempting to figure out what is going on and to correct the error it thinks might be responsible for the problems it is having compiling your document.

This is a fundamental part of how TeX works. It parses stuff, tries to make sense of it, and takes various steps if it runs into problems. You can control this to some extent in a 'big picture' way. For example, you can tell it to stop when it runs into trouble, or to try to keep going, or to ask you what to do.

The crucial thing to know here is that the message is not from ShareLaTeX. It is from TeX. You may also get messages from LaTeX or from packages you load. I doubt you will get messages here from ShareLaTeX. It is just passing the messages onto you.

  • I'm new to LaTeX, so yes, I am very confused, thanks for the info. So, is there a way to tell ShareLaTeX (so it tells the appropriate program) to, as you say, stop when it runs into trouble? – izxle Sep 17 '15 at 2:12
  • @izxle Sorry. I've never used it. I have some experience with Overleaf, but have only ever done serious work with a local installation. Overleaf seems to halt on error by default, though. – cfr Sep 17 '15 at 2:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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