Text Formattingcommand textbackslash invalid in math mode

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
Tayco
Posts: 1
Joined: Mon Feb 10, 2020 10:52 am

command textbackslash invalid in math mode

Post by Tayco »

Hi there could someone help me with this error messgage:

command textbackslash invalid in math mode

Code: Select all

{\fontsize{10pt}{12.0pt}\selectfont  $\textbackslash$ def$\textbackslash$ cp$ \{ $ $\textbackslash$ textit$ \{ $ cp.$ \} $ $ \} $ \  \par}\par
It compiles source code in PDF not as an text but as simple pdf version of code text.
Last edited by cgnieder on Sun Feb 23, 2020 10:58 am, edited 1 time in total.

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

command textbackslash invalid in math mode

Post by Ijon Tichy »

Why do you switch to the math mode to use the text command \textbackslash?

What is the expected result?

Code: Select all

\documentclass{article}

\begin{document}
{\fontsize{10pt}{12.0pt}\selectfont \textbackslash def\textbackslash cp \{ \textbackslash textit \{ cp. \} \} \ \par}\par

\end{document}
or

Code: Select all

\documentclass{article}

\newcommand*{\cp}{\textit{cp.}}
\begin{document}
\cp
\end{document}
or

Code: Select all

\documentclass{article}
\begin{document}
\verb|\def\cp{\textit{cp.}}|
\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:
Post Reply