Tikz Error Missing Endcsname Inserted to Be Read Again Relax

Contents

  • i How to set this mistake
    • i.ane The main causes of Missing $ inserted
    • i.ii Examples of errors and their solutions
      • 1.2.1 Symbol commands must be used in math fashion
        • 1.2.1.ane Fixing errors caused by LaTeX symbol commands
        • one.2.i.2 A list of LaTeX symbols
      • 1.2.two Using math-mode-only characters outside math mode
        • 1.2.ii.1 Using underscores exterior of math mode
        • 1.2.2.ii Using underscores in URLs
        • 1.2.ii.3 Underscores in .bib file URLs
      • 1.2.3 Using commands non permitted in math mode
      • 1.2.4 Blank lines in mathematics
      • 1.2.5 Using $ inside math environments
  • 2 Background to the Missing $ inserted error
    • 2.i There are no missing $ signs simply I still get the error
    • ii.2 Of modes, and when
      • ii.2.1 Math mode
      • 2.ii.2 Triggering TeX math modes
      • 2.2.3 Macros: testing for math mode
  • 3 Advanced: An explanation of TeX'south mistake recovery mechanism
    • iii.1 Worked case

How to gear up this error

This fault can be triggered in dissimilar means and, peculiarly for those new to LaTeX, information technology's not e'er immediately obvious why it happened, or, more importantly, how to resolve it. We'll kickoff with an overview of the general atmospheric condition which trigger this fault then list some of the more mutual causes and how to fix them. The latter parts of this article offer more in-depth material for readers wishing to broaden their understanding.

Note: In this article nosotros use the terms "TeX", "LaTeX" and "TeX engine" only if you lot aren't sure of their different meanings you tin can find out in the Overleaf article What's in a Name: A Guide to the Many Flavours of TeX.

The main causes of Missing $ inserted

There are three chief reasons why (La)TeX generates this error:

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

Examples of errors and their solutions

The following examples demonstrate some ways in which the Missing $ inserted mistake can be triggered, together with providing solutions to resolve the error.

Symbol commands must be used in math manner

Many math symbols in LaTeX are accessed using commands which must only exist used when TeX is typesetting math; i.east., at a time when TeX is in math style.

Examples of commonly-used symbol commands include those for Greek letters: \alpha \((\alpha)\), \beta \((\beta)\), \gamma (\(\gamma)\), \delta \((\delta)\), \Delta \((\Delta)\) then forth. Many other LaTeX commands, such every bit those for modifiers: \vec{x} \((\vec{x})\), \tilde{x} \((\tilde{x})\), \lid{x} \((\hat{10})\) etc., are also designed for apply in math fashion.

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 style.

The following example shows what happens if you endeavor to use the command \alpha \((\alpha)\) outside of math (style):

            Writing            \verb|\alpha| outside math mode will generate an mistake:            \alpha            then this text will not be typeset correctly...          

 Open this error-producing example in Overleaf

The post-obit image shows office of the output produced by the LaTeX code above, demonstrating the mistake caused by using \alpha exterior of math mode:

\alpha outside math mode

Fixing errors caused by LaTeX symbol commands

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

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

 Open this example in Overleaf

A list of LaTeX symbols

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

Using math-mode-only characters outside math mode

Traditionally, TeX/LaTeX reserve certain common characters for use within math way:

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

Using them straight outside math mode triggers errors.

  • To type $ outside math mode utilize \$
  • To type _ outside math manner use \_
  • Multiple ways to blazon ^ outside math mode. A list is provided on tex.stackexchange
Using underscores outside of math style

A common crusade of the Missing $ inserted error is using underscores (_), a math style character, outside of math mode—such as underscores present in filenames: an instance of this is shown below.

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

 Open this fault-generating lawmaking on Overleaf


Considering the underscore character is assigned category code 8 information technology is reserved for creating subscripts when the TeX engine is in math fashion. Consequently, when (La)TeX detects the _ in the file name math_example.tex it does and then outside of math mode, which triggers an fault and results in erroneous typesetting of subsequent text:

\(\text{Using a math graphic symbol, such as an underscore, in a file proper noun: math}_example.tex.\)

The _ character (technically its category code of eight) triggers an error and causes TeX to enter math mode: the letter east following immediately after the _ is treated as a character to be typeset equally a subscript. Processing then continues in math mode resulting in the italicized text and, additionally, at that place is no way here for TeX to gracefully exit math mode, which volition trigger further errors.

In club to avoid this particular error, you must e'er utilize _ in math manner—i.east., inside $..$, $$...$$ or, preferably, inside LaTeX's notation of \(...\) and \[...\].

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

            To utilise the math-mode underscore character in a file name, write it like this: math\_example.tex.          

 Open this corrected version on Overleaf

Using underscores in URLs

You may besides encounter this mistake when trying to typeset URLs with underscores, e.g. https://www.overleaf.com/learn/latex/Subscripts_and_superscripts. Instead of escaping each underscore graphic symbol, you may desire to load the url or hyperref package, and so utilize the \url control similar this:

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

 Open up this instance in Overleaf

Underscores in .bib file URLs

If such URLs are in your bibliography .bib file, causing errors to be reported from the .bbl file, then 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 packet in your preamble, if necessary. Most bibliography style files will then be able to automatically wrap these values in a \url{...} control.

Using commands non permitted in math manner

A number of low-level congenital-in TeX commands (chosen primitives) are non permitted in math mode and their employ in math mode volition trigger the Missing $ inserted error. Although well-nigh users are unlikely to use these commands in day-to-day LaTeX code, we make a note here because it'southward possible they could be contained within LaTeX commands (macros) beingness used in math way.

The following example tries to utilize the TeX command \vskip inside mathematical material. This is non permitted and generates an error.

                        \documentclass            {commodity}            \begin            {document}            I want to add some infinite, but this is non the mode to exercise information technology...            \[            y            =            f            (            x            )                                    \vskip            5            pt z            =            f            (            y            )            \]            $            y            =            f            (            ten            )                                    \vskip            v            pt z            =            f            (            y            )            $            \end            {document}          

 Open up 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.

Bare lines in mathematics

                        \documentclass            {article}            \brainstorm            {document}            \begin            {equation}            y=x^3,  z=10^3            \stop            {equation}            \end            {certificate}          

 Open this mistake-generating code on Overleaf

Cause: The blank line between the formulae is converted to a \par control which is non allowed in math way. You can likewise see this by writing

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

 Open this error-generating lawmaking on Overleaf

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

                        \documentclass            {article}            \brainstorm            {document}            \brainstorm            {equation}            y=x^3,            % This volition suppress the blank line            z=x^3            \end            {equation}            \stop            {document}          

 Open this corrected version on Overleaf

Using $ inside math environments

Some LaTeX environments, such as the marshal and equation environments, do non crave math to exist wrapped in $ signs, or use of LaTeX'due south math syntax: \(...\) or \[...\]. The LaTeX lawmaking which implements those environments takes care of entering and exiting math mode.

The following example shows use of the $ sign within an amsmath marshal environs, which triggers a Missing $ inserted fault, amid many others....

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

 Open this error-generating code on Overleaf

The correct manner to write these equations is:

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

 Open this corrected version on Overleaf

Groundwork to the Missing $ inserted error

The following department is for readers wishing to improve understand the reasons backside the mistake Missing $ inserted. Information technology's non essential reading but information technology may assistance you lot with finding and fixing errors.

There are no missing $ signs but I still become the error

In some circumstances the Missing $ inserted mistake can be very disruptive because your LaTeX code might non really take whatever problems with visibly missing $ characters. For case, the LaTeX fragment \(\verb|$$y=f(10)\par$$|\) superficially looks correct: the \(\verb|$$|\) pairs are balanced just it will trigger the "missing $" error. Hither, it is due to the \par command which is not allowed in math mode:

                        \documentclass            {commodity}            \begin            {document}            This example generates the fault            \verb|Missing            $                          inserted|:                        $$            y            =            f            (            x            )            \par            $$                        \end            {document}          

 Open this to meet a Missing $ inserted error

The in a higher place LaTeX code actually triggers a cascade of errors, equally shown below, so conspicuously y'all should non use \par inside math!

! Missing $ inserted. <inserted text>                  $ l.12 $$y=f(x)\par                  $$ I've inserted a begin-math/end-math symbol since I think yous left ane out. Proceed, with fingers crossed.  ! Display math should end with $$. <to be read over again>                     \par  fifty.12 $$y=f(x)\par                  $$ The `$' that I just saw supposedly matches a previous `$$'. So I shall assume that you typed `$$' both times.  ! Missing $ inserted. <inserted text>                  $ l.13 \finish{document}                     I've inserted a begin-math/cease-math symbol since I retrieve you left one out. Proceed, with fingers crossed.  ! Display math should end with $$. <to be read again>                     \par  l.13 \end{document}                     The `$' that I just saw supposedly matches a previous `$$'. So I shall assume that you typed `$$' both times.          

When the Missing $ inserted mistake occurs the TeX engine software is trying to recover and "become dorsum on track" and so it can go on processing after the point where the error occurred. The department Advanced: An explanation of TeX's error recovery mechanism will help y'all understand why this cascade of errors arises due to TeX's attempts at trying to fix the initial mistake.

Of modes, and when

Internally, TeX engines are designed operate using 3 "states of listen", called modes, which depend on the blazon of material a TeX engine is currently typesetting. The manner a TeX engine is in at any betoken during typesetting is called its current fashion, which changes throughout the procedure of typesetting the content of your LaTeX document.

For each of a TeX engine'south modes there are certain commands and characters (or, more than correctly, category codes) which are "incompatible" with TeX'south current manner: they shouldn't be used whilst TeX is in that specific style. If yous try to use those inappropriate characters or commands TeX volition consequence an fault such as Missing $ inserted to tell you something is wrong.

Math mode

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

Only for completeness we'll notation there are two types of math mode, reflecting the creation of inline or display math:

  • inline math way
  • display math mode

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

Triggering TeX math modes

In that location are multiple ways to trigger a TeX engine to enter and then exit math mode.

  • Yous can use explicit markup such as:
    • LaTeX syntax: \(...\) to enter \( then exit \) inline math style or \[...\] to enter \[ so leave \] brandish math mode;
    • (historic) TeX syntax: $...$ to enter (commencement $) so go out (second $) inline math fashion or $$...$$ to enter (start $$ pair) then exit (second $$ pair) brandish math style;
  • or any ane of the LaTeX math environments:
    • \begin{marshal}...\stop{align} etc. Behind the scenes these environs have care of entering and leaving math mode.

The actual text of the message Missing $ inserted is congenital into ("hardcoded" in) TeX engine software, which is why you will still see Missing $ fifty-fifty if yous are not using $ characters to typeset mathematics and use purely LaTeX syntax to markup the math in your document. This tin can be confusing to new users of LaTeX merely at that place's little that can be washed to modify this error message text without modifying the source code of TeX engines!

Macros: testing for math mode

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

                        \documentclass            {commodity}            \brainstorm            {document}            \newcommand            {            \mytest            }{            \ifmmode            \mathrm            {Yes}            \else            No\fi.}            Is the macro being used in math mode?            $            \mytest            $            Is the macro being used in math style?            $$            \mytest            $$            Is the macro beingness used in math mode?            \(            \mytest            \)            Is the macro being used in math mode?            \[            \mytest            \]            Is the macro being used in math mode?            \mytest            \end            {document}          

 Open this example in Overleaf

The post-obit graphic shows the output produced by the example in a higher place:

LaTeX macro to test math mode

Advanced: An explanation of TeX'due south fault recovery mechanism

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

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

Here is a list of cases where the user has probably gotten into or out of math style past 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 within math mode, or "something" expressly designed for math typesetting being used outside math mode.

The chore facing TeX is: How exercise I recover from this? TeX does exactly what Knuth writes: information technology inserts a dollar sign and rescans the current token—a "token" is TeX's internal numeric (integer) value which represents the graphic symbol or command it has just read in. However, due to the precise context of the error, this strategy may, or may not, exist successful—as the error text goes on to say "Continue, with fingers crossed."!

Worked example

Let's explore Knuth's comments past taking a closer await at the following example: \(\verb|$y=f(x)$$\vskip3pt|\). If you lot open the lawmaking below you lot'll see it triggers the mistake Missing $ inserted.

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

 Open this example in Overleaf

To review why this triggers an mistake allow's write subscripts to place each \(\verb|$|\) in the expression to obtain \(\verb|$|_{\mathtt1}\verb|y=f(10)|\verb|$|_{\mathtt2}\verb|$|_{\mathtt3}\verb|\vskip3pt|\). TeX is able to correctly process the beginning part \(\verb|$|_{\mathtt1}\verb|y=f(x)|\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 manner—in our example nosotros are creating inline math in a paragraph so it briefly enters so-called horizontal mode.

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

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

Here, the current token is the \(\verb|\vskip|\) command so what TeX does is place a new $ into its input, let's call information technology \(\verb|$|_{\mathtt4}\). At this point, TeX is still in inline math mode merely now information technology goes dorsum to read the equivalent of \(\verb|$|_{\mathtt4}\verb|\vskip|\) which is read in inline math fashion. The \(\verb|$|_{\mathtt4}\), inserted by TeX itself, now closes the current inline math fashion and TeX goes on to read the \(\verb|\vskip|\) command outside inline math mode—here, TeX is in a paragraph so the \(\verb|\vskip3pt|\) causes the current paragraph to be ended and \(\verb|3pt|\) of infinite placed afterward it.

penalizabilings.blogspot.com

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

0 Response to "Tikz Error Missing Endcsname Inserted to Be Read Again Relax"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel