Math & ScienceRightarrow gives Missing $ inserted error

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
thinkpadder
Posts: 11
Joined: Fri May 21, 2021 12:01 pm

Rightarrow gives Missing $ inserted error

Post by thinkpadder »

On this very basic math formula:

Code: Select all

\documentclass[a5paper,12pt]{article}
\usepackage{amsmath}
\begin{document}

if $n = 0$ then $a_n = 0$; if $n \geq 1$ then $a_n = 1$ 

\end{document}
I'd like to replace the if and then words with one \Rightarrow so that it will look better

but when I do it and write:

Code: Select all

\documentclass[a5paper,12pt]{article}
\usepackage{amsmath}
\begin{document}

$n = 0$ \Rightarrow $a_n = 0$; $n \geq 1$ \rightarrow $a_n = 1$ 

\end{document}
it gives error (using Miktex pdflatex. exe or xelatex.exe)

Code: Select all

! Missing $ inserted.
<inserted text>
                $
l.5 $n = 0$ \Rightarrow
                        $a_n = 0$; $n \geq 1$ \rightarrow $a_n = 1$
?
Considering \Rightarrow is found inside the amssymb package I add \usepackage{amssymb} but the same error.

How to add \Rightarrow inside those math expressions?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Ijon Tichy
Posts: 640
Joined: Mon Dec 24, 2018 10:12 am

Rightarrow gives Missing $ inserted error

Post by Ijon Tichy »

Just stay in math mode for the whole formula:

Code: Select all

\documentclass[a5paper,12pt]{article}
\usepackage{amsmath}
\begin{document}

Use either:
$n = 0 \Rightarrow a_n = 0; n \geq 1 \rightarrow a_n = 1$ 
for an inline formula or
\[ 
n = 0 \Rightarrow a_n = 0; n \geq 1 \rightarrow a_n = 1
\]
for displayed math.

\end{document}
BTW: You don't need amsmath for this. Nevertheless amsmath is a recommended package for math. I even would recommend mathtools, an extension of amsmath. See the manuals for more information.
Sorry, but I can no longer participate here as the administrator is trampling on my wishes on one of his other platforms. :cry:
thinkpadder
Posts: 11
Joined: Fri May 21, 2021 12:01 pm

Rightarrow gives Missing $ inserted error

Post by thinkpadder »

Ijon Tichy wrote:Just stay in math mode for the whole formula
Ops! Yep! Just couldn't imagine that those extra $'s were causing the error. Thanks.
Post Reply