34

I am new to LaTeX and I am using it to write a report with several chapters (main page in which I include the other pages). I got this error:

C:\Users\hussam\Desktop\thèse\latex\thèse\thèse.brf

! Missing $ inserted.

<inserted text> 

                $

l.52

without any other information.

thèse.brf is a totally white page. I looked at line 52 of all my documents but couldn't find any problem.

3
  • 20
    Using accented characters in file names is very dangerous.
    – egreg
    Apr 21, 2012 at 12:36
  • i assume this thèse.brf is being input? what encoding is the file in, and what packages do you have loaded? my guess is latex is confused by your file name into thinking that it contains something dedicated to maths (like ^, _ or the like. fwiw, i agree with @egreg: remember that tex dates from the days when ascii was an exciting new standard, and it's notorious for being confused by non-ascii characters; we could really do with a minimal example (a stripped-down version of your document that still fails) Apr 22, 2012 at 13:47
  • Found the simplest solution. Just put a single $ sign on both sides of the line. Jul 5, 2016 at 14:23

7 Answers 7

35

I had the same problem and solved it by correctly escaping ^, _, and |. Looks like LaTeX sets both $s itself if you seem to have forgotten them. Everything that may intend being a math formula causes this error.

3
  • 3
    I had to escape the _ in my .bib file, so it's not just the .tex file you have to worry about.
    – pd12
    Sep 9, 2016 at 7:21
  • 2
    I had to escape the & in my .bib file. Including \usepackage{url} can be helpful to avoid this. Mar 3, 2019 at 1:07
  • @user2723494 thanks. The \usepackage{url} solved my issue.
    – muammar
    Jan 9, 2020 at 0:26
16

This error usually appears because you used a $ somewhere previously that needs to be matched by an ending $. You haven't given us very much to work with, but here are some troubleshooting steps.

  • Look at the lines before line 52. Are there any $ that you see that maybe need to be matched with something?

  • If you hit ENTER in your console, will your file keep compiling? If so, keep hitting ENTER (or type Q) until it finishes, and then look at the output if possible. If you've been typing math, do you see a whole bunch of italicized stuff that has funny spacing? If so, that's a sign that LaTeX thinks you're still in math mode (so it's typesetting your text as math), so around there is where you should look for your missing $.

6

I had this problem too, and it wasn't anywhere near the line number given in the logs.

Building on Leah's answer, if you press Q, then look in the logs, you'll see the message:

I've inserted something that you may have forgotten.
(See the <inserted text> above.)
With luck, this will get me unwedged. But if you
really didn't forget anything, try typing `2' now; then
my insertion and my current dilemma will both disappear.

So on the next run, try pressing 2 at the error prompt, which tells latex to ignore the problem, and continue, instead of trying to fix it. In doing so, it'll print out the last bit of text it read (near the problem), and that should give you a clue where the problem is (you might need to do this a couple of times).

Turns out my problem was on line 366 of my .bib file, and no-where near line 20 as reported. It was caused by a ~ in a url that hadn't been converted by the zotero exporter. Deleting that line removed the error.

5

I have been struggling with a similar error. For debugging it's sometimes helpful to have a look before the actual error message to see numbers in brackets such as [2] telling you which page is compiling at that stage. Nevertheless, hit Enter (several times). If the document gets compiled and you can open the document, have a closer look at the page which was indicated before. Sometimes you can spot some text that is not rendered correctly which is the error. You can then fix the corresponding passage.

Here another important hint: Remember to also check the bibliography entries in the bibliography which on those page are referred to. Although the entries themselves are not on that page, the error message would point you to the page where the reference is rendered. (In my case, I could spot an underscore that I did not escape with \_ in the .bib file. The underscore itself was not on the page that was rendered but the reference to the corresponding entry in the bibliography -- this was a bit tricky.)

3

In LaTeX, $ is a special symbol. When two $'s are placed around an equation, this tells LaTeX that this information is math, and not just regular text, e.g.:

$4+3=7$

When typing $, or the dollar sign, in a document in LaTeX, such as “I have $3.”, you must place a \ before, for e.g.:

I have \$3.

You probably tried to type a dollar sign in the document, but LaTeX believed you wanted math mode, so it is looking for the closing $.

2

Consider given code:

\begin{align*}
    $ {\bar S} &= \emptyset $ \\
    $ {\bar \emptyset} &= S $
\end{align*}

In the following snippet, I have used $ to make it look more mathematical. Also, focus that each $ symbol have been separated apart from others but still given code will give the exact error you faced.

Therefore, to recover from such problems, a better advice is do not use $ along with align.

Below code compiles smoothly,

\begin{align*}
     {\bar S} &= \emptyset  \\
     {\bar \emptyset} &= S
\end{align*}
1
  • This solution removes the error in your code example but it perhaps misses the point: in TeX, $...$ is used for mathematics mode and if you want to insert the dollar sign symbol you have to use \$. Unfortunately, it is not at all clear that the OP's error is caused by something like this...and we can't tell since they did not provide a minimal working example.
    – user30471
    Jun 7, 2017 at 2:17
1

In case you are facing this problem in your references .bib file, do not escape any characters inside your url's and doi's. Only make sure that you have:

  1. Your doi's properly enclosed in doi = { }
  2. Your url's properly enclosed in url = { }
  3. Imported the 'url' package using: \usepackage{url} in your main.tex file (or whatever is your main file name).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .