How can I write “C ++” in LaTeX so that the result looks good. For example, C$++$ does not look good: the plus signs are too large and there is too much space.
C$++$
The standard solution for such cases is to use verbatim:
\verb!C++!
I use the code below to create pretty C ++ in my master's work. The code was copied verbatim from the german forum . You should be able to simply copy all the code into a new .tex document and choose the right material for you ...
\documentclass{article} \usepackage{relsize} \usepackage{lipsum} %c from texinfo.tex \def\ifmonospace{\ifdim\fontdimen3\font=0pt } %c C plus plus \def\C++{% \ifmonospace% C++% \else% C\kern-.1667em\raise.30ex\hbox{\smaller{++}}% \fi% \spacefactor1000 } %c C sharp \def\Csharp{% \ifmonospace% C\#% \else% C\kern-.1667em\raise.30ex\hbox{\smaller{\#}}% \fi% \spacefactor1000 } \begin{document} \begin{center} {\Huge C++ $\rightarrow$ \C++ \& \Huge C\# $\rightarrow$ \Csharp}\\ \bigskip \ttfamily {\Huge C++ $\rightarrow$ \C++ \& \Huge C\# $\rightarrow$ \Csharp}\\ \bigskip \sffamily {\Huge C++ $\rightarrow$ \C++ \& \Huge C\# $\rightarrow$ \Csharp} \end{center} \section{\C++} \lipsum[1] \subsection{\Csharp} \lipsum[1] \end{document}
You can try and use a typewriter font.
\texttt{C++}
This is what I used loooong back:
\newcommand*{\Cpp}{C\ensuremath{++}\xspace}
for use as \Cpp ( xspace package xspace ). But, as you said, this is not very beautiful.
\Cpp
xspace
I found that the following gives good results:
\def\Cplusplus{C\raisebox{0.5ex}{\tiny\textbf{++}}}
This answer , on the same question on the tex website, gives what I think is a good way to do this.
%C++ \newcommand\Cpp{C\nolinebreak[4]\hspace{-.05em}\raisebox{.4ex}{\relsize{-3}{\textbf{++}}}} %C# \newcommand\Csh{C\nolinebreak[4]\hspace{-.05em}\raisebox{.4ex}{\relsize{-3}{\textbf{\#}}}