LaTeX forum ⇒ Text Formattingcommand textbackslash invalid in math mode

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

command textbackslash invalid in math mode

Postby Tayco » Mon Feb 10, 2020 12:48 pm

Hi there could someone help me with this error messgage:

command textbackslash invalid in math mode

{\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.

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

Postby Ijon Tichy » Mon Feb 10, 2020 2:14 pm

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

What is the expected result?
Code: [Select all] [Expand/Collapse] [Download] ({untitled.tex})
  1. \documentclass{article}
  2.  
  3. \begin{document}
  4. {\fontsize{10pt}{12.0pt}\selectfont \textbackslash def\textbackslash cp \{ \textbackslash textit \{ cp. \} \} \ \par}\par
  5.  
  6. \end{document}

or
Code: [Select all] [Expand/Collapse] [Download] ({untitled.tex})
  1. \documentclass{article}
  2.  
  3. \newcommand*{\cp}{\textit{cp.}}
  4. \begin{document}
  5. \cp
  6. \end{document}

or
Code: [Select all] [Expand/Collapse] [Download] ({untitled.tex})
  1. \documentclass{article}
  2. \begin{document}
  3. \verb|\def\cp{\textit{cp.}}|
  4. \end{document}


Return to “Text Formatting”

Who is online

Users browsing this forum: No registered users and 4 guests