Math & ScienceWhy is command \textendash invalid in math mode?

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
yaozhao
Posts: 57
Joined: Sat Oct 27, 2018 10:38 pm

Why is command \textendash invalid in math mode?

Post by yaozhao »

Code: Select all

\[Q_O^D = 75 – 5 P_O + P_C + 2I\]
Overleaf gives command \textendash invalid in math mode on input line 34.
(34 is the line of this code in my file)

But it can still give my pdf. Why is this warning? What's the meaning? Should I just ignore it?

Recommended reading 2024:

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

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

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

Why is command \textendash invalid in math mode?

Post by Ijon Tichy »

The warning message is, because you've used an endash: , instead of a minus: -, in your equation. You should not ignore the message, but change your equation like here:

Code: Select all

\documentclass{article}
\begin{document}
    \[Q_O^D = 75 - 5 P_O + P_C + 2I\]
\end{document}
BTW: Please always post a Infominimal working example instead of a code snippet. (Note: Because of the one line code snippet, I've made my own MWE for my first studies and just input the one line instead of copying it with the result, that I had no error or warning. With a real MWE I've never hit on the idea to not copy your code. So one more reason for real MWEs.)
Sorry, but I can no longer participate here as the administrator is trampling on my wishes on one of his other platforms. :cry:
yaozhao
Posts: 57
Joined: Sat Oct 27, 2018 10:38 pm

Why is command \textendash invalid in math mode?

Post by yaozhao »

I see. Yes, after using your code, the warning message disappeared. But how to type minus in my Mac?
yaozhao
Posts: 57
Joined: Sat Oct 27, 2018 10:38 pm

Why is command \textendash invalid in math mode?

Post by yaozhao »

Code: Select all

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
 Q_O^D &= 75 – 5 P_O + P_C + 2I \\
 Q_O^D &= 75 – 5 P_O + 5 + (2\times 10) 
\end{align*}
\end{document}
Overleaf gives command \textendash invalid in math mode on input line 34.
(34 is the line of \end{align*})

But it can still give my pdf. Why is this warning? What's the meaning? Should I just ignore it?
User avatar
Ijon Tichy
Posts: 640
Joined: Mon Dec 24, 2018 10:12 am

Why is command \textendash invalid in math mode?

Post by Ijon Tichy »

Depends on the keyboard layout/locale. AFAIK on a German or US keyboard type the - one time without AltGr or similar modifier key.
Sorry, but I can no longer participate here as the administrator is trampling on my wishes on one of his other platforms. :cry:
User avatar
Ijon Tichy
Posts: 640
Joined: Mon Dec 24, 2018 10:12 am

Why is command \textendash invalid in math mode?

Post by Ijon Tichy »

Please don't open a new thread for the same question. If you have additional information (like a Infominimal working example) add them to the already existing question (or a new posting at the thread of that question).
Sorry, but I can no longer participate here as the administrator is trampling on my wishes on one of his other platforms. :cry:
yaozhao
Posts: 57
Joined: Sat Oct 27, 2018 10:38 pm

Why is command \textendash invalid in math mode?

Post by yaozhao »

Not the same question. The problems are different.
User avatar
Ijon Tichy
Posts: 640
Joined: Mon Dec 24, 2018 10:12 am

Why is command \textendash invalid in math mode?

Post by Ijon Tichy »

No, it's exactly the same. Again, you've used instead of -. With - it works:

Code: Select all

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
 Q_O^D &= 75 - 5 P_O + P_C + 2I \\
 Q_O^D &= 75 - 5 P_O + 5 + (2\times 10) 
\end{align*}
\end{document}
Sorry, but I can no longer participate here as the administrator is trampling on my wishes on one of his other platforms. :cry:
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Why is command \textendash invalid in math mode?

Post by cgnieder »

I have merged both topics as they are essentially the same post.
site moderator & package author
Post Reply