Latex Missing Inserted. To Be Read Again

Contents

  • one How to fix this error
    • ane.one The main causes of Missing $ inserted
    • i.2 Examples of errors and their solutions
      • ane.two.1 Symbol commands must be used in math way
        • one.2.1.1 Fixing errors acquired by LaTeX symbol commands
        • 1.2.ane.two A list of LaTeX symbols
      • i.2.ii Using math-fashion-merely characters outside math fashion
        • 1.ii.2.1 Using underscores outside of math mode
        • one.2.two.2 Using underscores in URLs
        • i.ii.2.3 Underscores in .bib file URLs
      • one.ii.3 Using commands not permitted in math mode
      • 1.ii.4 Blank lines in mathematics
      • 1.2.5 Using $ inside math environments
  • ii Background to the Missing $ inserted mistake
    • 2.1 There are no missing $ signs simply I still get the fault
    • 2.2 Of modes, and when
      • two.2.1 Math mode
      • ii.two.2 Triggering TeX math modes
      • 2.2.iii Macros: testing for math mode
  • 3 Avant-garde: An explanation of TeX's error recovery mechanism
    • three.i Worked example

How to fix this error

This error can exist triggered in unlike ways and, especially for those new to LaTeX, it'due south not ever immediately obvious why it happened, or, more than importantly, how to resolve it. Nosotros'll start with an overview of the general conditions which trigger this error and then listing some of the more than common causes and how to fix them. The latter parts of this article offer more than in-depth material for readers wishing to augment their agreement.

Annotation: In this article we use the terms "TeX", "LaTeX" and "TeX engine" but if you lot aren't certain of their dissimilar meanings you tin can observe out in the Overleaf commodity What's in a Name: A Guide to the Many Flavours of TeX.

The chief causes of Missing $ inserted

In that location are three main reasons why (La)TeX generates this error:

  1. You've made an explicit error in your math markup, such as writing $y=f(x)$$—we look at other examples after in this article.
  2. TeX has detected a graphic symbol or command designed to be used but when TeX is typesetting mathematics but that character or command has been used when TeX was not typesetting mathematics.
    • TeXnically speaking: TeX detected a character or control designed to work inside math style but you've tried to use it outside math style. To clarify the issue with "characters" designed to piece of work in math mode, what nosotros really hateful is using characters assigned certain category codes designed to operate within mathematical material.
  3. TeX has detected a command designed to exist used only when TeX is non typesetting mathematics but that command was detected (used) whilst TeX was typesetting mathematical cloth.
    • TeXnically speaking: TeX detected a command designed to work outside math way but you've tried to utilise it inside math mode.

Examples of errors and their solutions

The post-obit examples demonstrate some ways in which the Missing $ inserted fault can exist triggered, together with providing solutions to resolve the error.

Symbol commands must be used in math mode

Many math symbols in LaTeX are accessed using commands which must merely be used when TeX is typesetting math; i.e., at a time when TeX is in math fashion.

Examples of commonly-used symbol commands include those for Greek messages: \blastoff \((\alpha)\), \beta \((\beta)\), \gamma (\(\gamma)\), \delta \((\delta)\), \Delta \((\Delta)\) and so forth. Many other LaTeX commands, such equally those for modifiers: \vec{x} \((\vec{x})\), \tilde{x} \((\tilde{x})\), \hat{x} \((\lid{x})\) etc., are as well designed for utilize in math mode.

Using modifiers, symbol commands—and many other math-related commands—outside of typesetting mathematical content will generate a Missing $ inserted error and force the compiler to enter into math way.

The post-obit example shows what happens if you endeavour to use the command \alpha \((\alpha)\) outside of math (mode):

            Writing            \verb|\alpha| outside math style volition generate an error:            \alpha            so this text volition not be typeset correctly...          

 Open up this error-producing example in Overleaf

The following epitome shows role of the output produced past the LaTeX code above, demonstrating the error acquired by using \blastoff outside of math mode:

\alpha outside math mode

Fixing errors caused by LaTeX symbol commands

To employ modifiers, or Greek math symbols, within sentences they must always be wrapped in single dollar signs $...$, or LaTeX's \(...\) syntax, in order for TeX to process them in inline math mode, as shown below.

            When writing the Greek letter alpha in a sentence, it must exist written as            \verb|$            \alpha            $| to generate            $            \blastoff            $,  or as            \verb|\(            \alpha            \)| which also generates            \(            \alpha            \).   When writing a vector 10 in a sentence, it must be written every bit            \verb|$            \vec            {x}            $| to produce            $            \vec            {ten}            $            or as            \verb|\(            \vec            {x}            \)| which besides yields            \(            \vec            {10}            \).          

 Open this example in Overleaf

A list of LaTeX symbols

The Overleaf commodity List of Greek messages and math symbols provides a list of symbols which are exclusive to math fashion, together with links to further useful resource.

Using math-mode-only characters outside math style

Traditionally, TeX/LaTeX reserve sure common characters for use inside math mode:

  • ^: reserved for creating superscripts
  • _: reserved for creating subscripts
  • $: reserved for starting/stopping math way

Using them directly outside math mode triggers errors.

  • To blazon $ exterior math fashion utilize \$
  • To type _ exterior math mode use \_
  • Multiple means to type ^ outside math mode. A listing is provided on tex.stackexchange
Using underscores outside of math mode

A common crusade of the Missing $ inserted error is using underscores (_), a math mode character, exterior of math mode—such every bit underscores nowadays in filenames: an example of this is shown below.

            Using a math graphic symbol, such as an underscore, in a file name: math_example.tex.          

 Open up this mistake-generating code on Overleaf


Considering the underscore character is assigned category lawmaking 8 it is reserved for creating subscripts when the TeX engine is in math mode. Consequently, when (La)TeX detects the _ in the file name math_example.tex it does so exterior of math mode, which triggers an error and results in erroneous typesetting of subsequent text:

\(\text{Using a math character, such as an underscore, in a file name: math}_example.tex.\)

The _ character (technically its category lawmaking of 8) triggers an fault and causes TeX to enter math style: the letter e following immediately later on the _ is treated as a grapheme to be typeset as a subscript. Processing then continues in math fashion resulting in the italicized text and, additionally, there is no way here for TeX to gracefully leave math mode, which will trigger further errors.

In gild to avoid this detail mistake, you must ever use _ in math way—i.e., within $..$, $$...$$ or, preferably, inside LaTeX's notation of \(...\) and \[...\].

Outside math way you need to write \_ to employ or typeset an underscore, as shown in the corrected version of the instance:

            To utilise the math-manner underscore graphic symbol in a file proper noun, write it like this: math\_example.tex.          

 Open this corrected version on Overleaf

Using underscores in URLs

You lot may too run across this error when trying to typeset URLs with underscores, due east.m. https://www.overleaf.com/learn/latex/Subscripts_and_superscripts. Instead of escaping each underscore character, you may want to load the url or hyperref package, and then use the \url command similar this:

                        \documentclass            {article}            \usepackage            {url}            \begin            {document}            \url            {https://www.overleaf.com/learn/latex/Subscripts_and_superscripts}            \finish            {document}          

 Open this example in Overleaf

Underscores in .bib file URLs

If such URLs are in your bibliography .bib file, causing errors to exist reported from the .bbl file, so make sure you employ the url or doi fields to record these fields in the .bib file:

doi = {10.1007/978-94-015-6859-3_4}, url = {https://abc.com/latest_news_1.html}

and load the url or hyperref package in your preamble, if necessary. Most bibliography style files will so be able to automatically wrap these values in a \url{...} control.

Using commands not permitted in math mode

A number of low-level built-in TeX commands (called primitives) are not permitted in math mode and their use in math way volition trigger the Missing $ inserted mistake. Although most users are unlikely to utilise these commands in day-to-day LaTeX code, we brand a note hither considering information technology'south possible they could be contained inside LaTeX commands (macros) being used in math mode.

The following example tries to utilise the TeX command \vskip within mathematical cloth. This is not permitted and generates an error.

                        \documentclass            {article}            \begin            {certificate}            I want to add some space, only this is not the way to do it...            \[            y            =            f            (            10            )                                    \vskip            5            pt z            =            f            (            y            )            \]            $            y            =            f            (            10            )                                    \vskip            5            pt z            =            f            (            y            )            $            \end            {document}          

 Open this error-generating code on Overleaf

Other TeX (primitive) commands not permitted when TeX is in math mode include \par, \hrule, \unvbox, \unvcopy and \valign.

Blank lines in mathematics

                        \documentclass            {article}            \begin            {document}            \begin            {equation}            y=10^3,  z=10^3            \terminate            {equation}            \end            {document}          

 Open this error-generating lawmaking on Overleaf

Crusade: The blank line between the formulae is converted to a \par command which is not immune in math fashion. You tin also see this by writing

                        \documentclass            {article}            \begin            {certificate}            \[            y            =            x^            iii            ,            \par                          z            =            ten^            iii            \]            \end            {document}          

 Open up this error-generating lawmaking on Overleaf

To set up this, either delete the blank lines or comment them out:

                        \documentclass            {article}            \begin            {document}            \begin            {equation}            y=x^iii,            % This will suppress the blank line            z=x^iii            \stop            {equation}            \end            {document}          

 Open up this corrected version on Overleaf

Using $ inside math environments

Some LaTeX environments, such as the marshal and equation environments, do not crave math to be wrapped in $ signs, or utilise of LaTeX's math syntax: \(...\) or \[...\]. The LaTeX lawmaking which implements those environments takes care of entering and exiting math manner.

The following example shows apply of the $ sign inside an amsmath marshal environment, which triggers a Missing $ inserted error, among many others....

                        \documentclass            {article}            \usepackage            {amsmath}            \begin            {certificate}            \begin            {align*}            $            2            x                        -                                    5            y &            =                                    8                                    \\                                    3            ten                        +                                    nine            y &            =                                    -            12            $            \cease            {align*}            \end            {document}          

 Open up this error-generating code on Overleaf

The correct mode to write these equations is:

                        \documentclass            {article}            \usepackage            {amsmath}            \begin            {document}            \begin            {marshal*}            2x - 5y            &=  eight            \\            3x + 9y            &=  -12            \end            {marshal*}            \terminate            {document}          

 Open up this corrected version on Overleaf

Background to the Missing $ inserted error

The following section is for readers wishing to meliorate empathize the reasons behind the error Missing $ inserted. Information technology'south not essential reading but it may assistance you with finding and fixing errors.

In that location are no missing $ signs simply I still go the error

In some circumstances the Missing $ inserted fault tin can exist very confusing because your LaTeX code might not actually have any problems with visibly missing $ characters. For example, the LaTeX fragment \(\verb|$$y=f(x)\par$$|\) superficially looks correct: the \(\verb|$$|\) pairs are counterbalanced simply information technology will trigger the "missing $" error. Here, it is due to the \par command which is not immune in math style:

                        \documentclass            {article}            \begin            {certificate}            This case generates the error            \verb|Missing            $                          inserted|:                        $$            y            =            f            (            x            )            \par            $$                        \end            {document}          

 Open this to see a Missing $ inserted error

The in a higher place LaTeX code really triggers a cascade of errors, equally shown below, so clearly you should not utilize \par inside math!

! Missing $ inserted. <inserted text>                  $ 50.12 $$y=f(x)\par                  $$ I've inserted a begin-math/end-math symbol since I think you left ane out. Proceed, with fingers crossed.  ! Brandish math should terminate with $$. <to be read once again>                     \par  l.12 $$y=f(x)\par                  $$ The `$' that I but saw supposedly matches a previous `$$'. So I shall assume that you typed `$$' both times.  ! Missing $ inserted. <inserted text>                  $ fifty.13 \terminate{certificate}                     I've inserted a brainstorm-math/end-math symbol since I call up you left one out. Proceed, with fingers crossed.  ! Brandish math should end with $$. <to be read again>                     \par  50.13 \finish{document}                     The `$' that I simply saw supposedly matches a previous `$$'. So I shall assume that y'all typed `$$' both times.          

When the Missing $ inserted mistake occurs the TeX engine software is trying to recover and "go back on rails" so it tin continue processing after the bespeak where the error occurred. The department Advanced: An explanation of TeX'due south error recovery mechanism will help y'all understand why this cascade of errors arises due to TeX'due south attempts at trying to set the initial fault.

Of modes, and when

Internally, TeX engines are designed operate using three "states of mind", called modes, which depend on the type of material a TeX engine is currently typesetting. The manner a TeX engine is in at whatever point during typesetting is called its current manner, which changes throughout the process of typesetting the content of your LaTeX certificate.

For each of a TeX engine'due south modes in that location are certain commands and characters (or, more correctly, category codes) which are "incompatible" with TeX'due south current fashion: they shouldn't be used whilst TeX is in that specific mode. If you lot effort to utilize those inappropriate characters or commands TeX will issue an mistake such as Missing $ inserted to tell you something is wrong.

Math way

This error Missing $ inserted is related to TeX'south math mode—i.due east., the way a TeX engine is in when you ask LaTeX to typeset some maths.

Just for completeness nosotros'll note there are two types of math mode, reflecting the creation of inline or brandish math:

  • inline math way
  • brandish math mode

TeX needs these two dissimilar math modes considering it applies different rules for spacing, symbols sizes etc when typesetting math destined for inline or brandish.

Triggering TeX math modes

There are multiple ways to trigger a TeX engine to enter and then go out math mode.

  • You can utilise explicit markup such equally:
    • LaTeX syntax: \(...\) to enter \( then leave \) inline math fashion or \[...\] to enter \[ and then go out \] display math mode;
    • (historic) TeX syntax: $...$ to enter (first $) then get out (second $) inline math mode or $$...$$ to enter (outset $$ pair) then leave (second $$ pair) display math way;
  • or any one of the LaTeX math environments:
    • \brainstorm{align}...\end{align} etc. Backside the scenes these surroundings accept intendance of entering and leaving math fashion.

The bodily text of the message Missing $ inserted is built into ("hardcoded" in) TeX engine software, which is why yous volition still see Missing $ even if you lot are not using $ characters to typeset mathematics and apply purely LaTeX syntax to markup the math in your document. This can exist confusing to new users of LaTeX but there's niggling that tin exist done to change this error message text without modifying the source code of TeX engines!

Macros: testing for math mode

Information technology'southward possible to test if TeX is currently in math way using the primitive command \ifmmode; that manner yous can write macros whose behavior can suit to avoid generating manner-related errors. Here is a very basic example to demonstrate the principle, which prints Yes. or No. depending whether or not TeX is in math mode at the point of "executing" the macro.

                        \documentclass            {article}            \brainstorm            {document}            \newcommand            {            \mytest            }{            \ifmmode            \mathrm            {Yeah}            \else            No\fi.}            Is the macro being used in math style?            $            \mytest            $            Is the macro being used in math fashion?            $$            \mytest            $$            Is the macro beingness used in math style?            \(            \mytest            \)            Is the macro being used in math mode?            \[            \mytest            \]            Is the macro existence used in math mode?            \mytest            \cease            {document}          

 Open up this example in Overleaf

The post-obit graphic shows the output produced by the example above:

LaTeX macro to test math mode

Advanced: An explanation of TeX's error recovery machinery

The fault message Missing $ inserted is not output by Overleaf, LaTeX, or LaTeX packages; information technology actually originates from within the executable program responsible for typesetting your LaTeX document: that executable plan is called a TeX engine—you can think of information technology as "driving" the typesetting process.

Within the source code of the TeX software, its writer (Donald Knuth), makes this ascertainment about the code responsible for generating the Missing $ inserted error:

Here is a list of cases where the user has probably gotten into or out of math mode by mistake. TeX will insert a dollar sign and rescan the current token.

At the heart of the Missing $ inserted error is TeX detecting "something" that should not have been used inside math manner, or "something" expressly designed for math typesetting beingness used outside math mode.

The task facing TeX is: How do I recover from this? TeX does exactly what Knuth writes: it inserts a dollar sign and rescans the current token—a "token" is TeX'south internal numeric (integer) value which represents the grapheme or control it has just read in. Withal, due to the precise context of the fault, this strategy may, or may non, exist successful—as the error text goes on to say "Proceed, with fingers crossed."!

Worked instance

Let'southward explore Knuth's comments by taking a closer look at the post-obit example: \(\verb|$y=f(ten)$$\vskip3pt|\). If you open the code below yous'll run into information technology triggers the error Missing $ inserted.

            Writing            \verb|$            y            =            f            (            x            )            $$            \vskip            three            pt| produces...            $y=f(10)$$            \vskip            3            pt Start new line...          

 Open up this example in Overleaf

To review why this triggers an mistake permit'due south write subscripts to identify each \(\verb|$|\) in the expression to obtain \(\verb|$|_{\mathtt1}\verb|y=f(x)|\verb|$|_{\mathtt2}\verb|$|_{\mathtt3}\verb|\vskip3pt|\). TeX is able to correctly procedure the first function \(\verb|$|_{\mathtt1}\verb|y=f(ten)|\verb|$|_{\mathtt2}\) which is treated as a correctly formatted piece of inline math, producing \(y=f(x)\). Immediately after processing \(\verb|$|_{\mathtt2}\) TeX temporarily exits inline math mode—in our case nosotros are creating inline math in a paragraph so information technology briefly enters then-chosen horizontal mode.

Information technology's what happens side by side that triggers the mistake. TeX continues to process the \(\verb|$|_{\mathtt3}\) which triggers TeX to re-enter inline math style. TeX now reads the next token which is the \(\verb|\vskip|\) command—it has not however read the \(\verb|3pt|\). At this bespeak, TeX sees \(\verb|\vskip|\) but it's in inline math mode: \(\verb|\vskip|\) is not allowed at that place so it triggers TeX's error-handling procedure as described by Knuth:

TeX volition insert a dollar sign and rescan the electric current token.

Hither, the current token is the \(\verb|\vskip|\) command so what TeX does is place a new $ into its input, allow's call it \(\verb|$|_{\mathtt4}\). At this indicate, TeX is however in inline math style but now information technology goes back to read the equivalent of \(\verb|$|_{\mathtt4}\verb|\vskip|\) which is read in inline math mode. The \(\verb|$|_{\mathtt4}\), inserted by TeX itself, now closes the current inline math mode and TeX goes on to read the \(\verb|\vskip|\) command outside inline math way—here, TeX is in a paragraph so the \(\verb|\vskip3pt|\) causes the electric current paragraph to be ended and \(\verb|3pt|\) of infinite placed after it.

coledefir2001.blogspot.com

Source: https://www.overleaf.com/learn/latex/Errors/Missing_$_inserted

0 Response to "Latex Missing Inserted. To Be Read Again"

Publicar un comentario

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel