tags:

views:

519

answers:

5

maybe is a noob question but i can't find the solution in the web, i need to write C++ in Latex. I write C$++$ but the result is like crap, the signs are too big and there is too much space between C and the first plus sign.

Previously i needed to write the sharp symbol for C#....c$\sharp$ it also looks like crap but with a escape character it looks nice, for the plus sign i can't do the same.

+2  A: 

You could try and use a typewriter font.

\texttt{C++}
henrikh
+1  A: 

The standard solution for cases like this is to use verbatim:

\verb!C++!
Michael Mrozek
i like this solution but the C looks bad...not like the other text, so i want to append the plusplus sign to a normal Ci try with this but not work: C \thinspace\verb!++!
voodoomsr
i got it C{}\verb!++!...that looks how i want it.
voodoomsr
A: 

This is what I used loooong time ago:

\newcommand*{\Cpp}{C\ensuremath{++}\xspace}

to be used like \Cpp (needs xspace package). But as you said, it is not really beautiful.

Patrick
+1  A: 

I've been using the code below to typset a nice looking C++ in my Master-Thesis. The code has been copied verbatim from a german forum. You should be able to just copy-paste all the code in a new .tex-document and pick the relevant stuff 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}
Habi
thanks!! the results are nice...one questions that i don't understand in the code...how can you put C++ without math environment or \verb after \Huge?
voodoomsr
sorry, I don't understand your question. The \Huge is just in the code to make it a bit more visible. If you're using the definitions at the beginning of the file, you should be able to just write \C++ anywhere in any environment...
Habi
ok thanks, i was a little confused with the use of the plus sign. I tough that the math environment was indispensable but now i realized that not. xD
voodoomsr
A: 

You can use the listings package:

The second link shows the (in my opinion, nice) output on an example.

Amit Kumar