How to write "C ++" in LaTeX

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.

+48
latex
Apr 27 2018-10-18T00:
source share
6 answers

The standard solution for such cases is to use verbatim:

 \verb!C++! 
+27
Apr 27 '10 at 20:26
source share

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} 
+18
Apr 28 2018-10-10T00:
source share

You can try and use a typewriter font.

 \texttt{C++} 
+13
Apr 27 '10 at 20:24
source share

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.

+5
Apr 27 '10 at 20:29
source share

I found that the following gives good results:

 \def\Cplusplus{C\raisebox{0.5ex}{\tiny\textbf{++}}} 
+3
Jan 9 '14 at 19:00
source share

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{\#}}} 
+1
Dec 13 '13 at 23:52
source share



All Articles