Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write "C++" in LaTeX

Tags:

latex

How can I write "C++" in LaTeX so that the output looks nice. For example C$++$ doesn't look good: the plus signs are too big and there is too much space.

like image 225
mjsr Avatar asked Apr 27 '10 20:04

mjsr


People also ask

How do I type a symbol in LaTeX?

You may be wondering how to insert symbols in LaTeX. It is possible to add certain symbols in-text while others require LaTeX's math mode to be activated. ”, you can use the command \star in your code.

How do you write temperature degrees in LaTeX?

In LaTeX, the packages gensymb and textcomp provide the commands \degree and \textdegree , respectively. In the absence of these packages one can write the degree symbol as ^{\circ} in math mode. In other words, it is written as the empty circle glyph circ as a superscript.

How do you make special characters in LaTeX?

If you simply want the character to be printed just as any other letter, include a \ in front of the character. For example, \$ will produce $ in your output. The exception to the rule is the \ itself because \\ has its own special meaning. A \ is produced by typing $\backslash$ in your file.

What is the degrees Celsius symbol?

The degree Celsius (symbol: °C) can refer to a specific temperature on the Celsius scale or a unit to indicate a difference or range between two temperatures. It is named after the Swedish astronomer Anders Celsius (1701–1744), who developed a similar temperature scale in 1742.


2 Answers

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

\verb!C++! 
like image 151
Michael Mrozek Avatar answered Oct 04 '22 10:10

Michael Mrozek


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} 
like image 27
Habi Avatar answered Oct 04 '22 10:10

Habi