1

I just try output C\C++ in LaTeX as following below:

\textit{C\backslashC\+\+}

But im getting this issue:

! Undefined control sequence.
<argument> C\backslashC 
                    \+\+
l.141 ... \textit{C\backslashC\+\+}
Filipe
  • 135

3 Answers3

10
\documentclass[preview,border=12pt]{standalone}% change it back to your own document class

\begin{document}
I love \texttt{C/C++} but not \texttt{C\char`\\ C++}.
\end{document}

enter image description here

  • 1
    style of backslash is different from that of forward slash. in \texttt, use this: \char\\ (and better yet, put an open quote before the double backslash, but that's real hard to show as a literal in this markdown environment). – barbara beeton Nov 26 '13 at 03:18
  • 1
    \char`\\ (backtick backtick slash char backtick slash slash backtick backtick) is possible as a markdown. – kiss my armpit Nov 26 '13 at 03:32
  • 1
    thanks. i'm trying to do this on an ipad, and it doesn't like to do what I tell it at the best of times. anyhow, your example looks much better now. – barbara beeton Nov 26 '13 at 03:33
  • It may be helpful to explain why the OP's code did not work, or (perhaps more reasonable) point to a resource that does. – Sean Allred Nov 26 '13 at 04:40
6

The error message says that \backslashC is undefined. You need to put something between the command and the C so LateX can see you want \backslash followed by a C. You can use a space (ignored after a command name) or a brace group: \backslash{}C. Once that error is past, you will get several more errors: \backslash is a mathmode command, and \+ is undefined. What you want is something like \textit{C$\backslash$C++}, but the spacing is all wrong. Also, one usually uses a forward slash in combinations like this. Here are two possibilities, one using a backslash (with the spacing improved) and one with a forward slash:

\textit{C$\,\backslash\!$C++}
\textit{C/C++} 
Dan
  • 6,899
0

Combining Donut E. Knot's answer with Prettiest way to typeset “C++” (cplusplus)? gives the following answer:

\documentclass[preview,border=12pt]{standalone}% change it back to your own document class

\newcommand{\CC}{C\nolinebreak\hspace{-.05em}\raisebox{.4ex}{\tiny\bf +}\nolinebreak\hspace{-.10em}\raisebox{.4ex}{\tiny\bf +}}

\begin{document} I love \texttt{C/\CC} but not \texttt{C\char`\ \CC}. \end{document}

I love C/C ++ but not C\C++

Via The Endevor

I have no idea why the original posters code does not work.

Canageek
  • 17,935