Writing "C++" in plain text results in an ugly setting, as the '+' signs are too big and too spaced:

"C++" in plain text

I've seen around the web several marcos for typesetting the "C++" symbol, ranging from mild kerning to shrinking, raising and lowering the '+' signs. What is your version of a \cpp{} macro?

10 Answers 10


By general request (or something of the like at least), I made it an answer.

The C++ FAQ mentions this specific problem: https://isocpp.org/wiki/faq/misc-environmental-issues#latex-macros. The two things they wish to provide are a better typesetting and prevention of line breaks, two possibilities are given:

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

The first one prevents a linebreak, raises the ++'s a little and puts them closer together.

version 1

The second only prevents a linebreak and raises the ++ a bit.

version 2

Both options put the ++'s in bold and typeset them a little smaller. Two more are given in the link, but I fail to see why they matter, line break prevention seems the must have for such a macro.

Edit: In case you want to use relative sizes you can use the relsize package, the code becomes


I don't have a favourite though, never needed to typeset C++ :). After experimenting a little, the second one is definitely my favourite, the version with kerning looks too much like the Haskell operator.

| improve this answer | |
  • 15
    Hmm. Using \tiny here isn’t a good idea – what if I want to typeset “C++” in a header or in a footnote? – Konrad Rudolph Oct 19 '10 at 14:59
  • @Pieter: the Haskell operator is usually set with a lot more overlap (when any is used at all, of course). – SamB Dec 19 '10 at 6:02
  • 1
    Is there any way to use these commands within a \section{} declaration, eg. \section{\CC Revision}? I keep getting an error message about a brace not matching. – Steve May 30 '11 at 11:54
  • 2
    You'll have to write \section{\protect\CC Revision}. – Pieter May 30 '11 at 13:05
  • 2
    Yes, I have included the package. I've just managed to get it to work. My definition is \protected\def\CC{{C\nolinebreak[4]\hspace{-.05em}\raisebox{.4ex}{\relsize{-3}\bf ++}}} and then I can simply use \section{\CC Revision}. I'm not sure why I cannot get it to work following your suggestion, but you gave me a vital hint about protecting the command. By the way, I also use the \xspace macro at the end of the definition to handle spacing (not shown above). Apologies for the formatting - I am not sure how to markup code in the comments. – Steve May 30 '11 at 15:19

Personally, I like the look of C\texttt{++} the best. It's also very simple!


| improve this answer | |
  • 4
    Follows the KISS principle. +1 – Shautieh Mar 20 '17 at 7:38

Here's how C++ is typeset in the C++ standard:


That looks like this:

enter image description here

| improve this answer | |
  • 4
    ... and \smaller is provided by relzise package. – Paul Gaborit Jun 18 '15 at 21:15
  • ... and \xspace is provided by the xspace package. That said, \xspace introduces its own set of problems and it may be wise to avoid it. – Richard Smith Jun 23 '15 at 19:46
  • @PaulGaborit I think that you meant the relsize package (rather than relzise) – daneel Feb 19 at 21:03

I’ve previously used the following definition (using \scalebox from the graphicx package):



Note that it doesn’t do some things that Pieter’s solution does, in particular it doesn’t prevent a line break (is this even possible here?) – but this could be amended easily by putting it into an \mbox. I’ve also modified the kerning to make the two plusses merge into one. Whether this looks good somewhat depends on the font, though.

In hindsight, the plusses are too high for my taste.

| improve this answer | |

Another "correct" way is to use the texlogos package, which defines the C++ logo as:


 enter image description here

That said, I do prefer the appearance shown in other posts, particularly Pieter's second.

| improve this answer | |
  • +1 for the correctness. Not very good looking though. – Bex May 2 at 9:28

I think it depends quite a bit on the font you use. I just tried the recommended macros with Lucida Bright, and in general the +'s were way too small and way too high. I got a reasonable result with the macros recommended in the C++ FAQ, but replacing \tiny by \small and raising the boxes only .2ex instead of .4ex. I suggest you experiment with your font.

| improve this answer | |
  • 1
    But having to think about font is very unLatex. (It goes against the whole Content without worry of formatting) – Lyndon White Feb 12 '12 at 9:36
  • In my experience there is nothing that can be done about this. It does depend on the font how high the ++ has to go. To the best of my knowledge there is no way to extract this knowledge somehow. Using the x-height is already the best you can do but it still depends on the shape of the 'C'. – Christian May 16 '12 at 15:52
  • 1
    @Oxinabox -- logos aren't to be considered "traditional typography" -- they're often custom designed (even perhaps more often than not; the latex logo itself is not font-neutral). therefore, assuming that they're "automatic" in latex isn't appropriate. – barbara beeton Feb 10 '14 at 23:23

The question doesn't specifically ask for LaTeX, yet all answers so far are in LaTeX, none in TeX. My solution, which, of course, you can put into a \def or simply straight into the text if you only need it once:

C\raise .8ex \hbox{$_{++}$}

Assuming 10pt size of the font; the '++' is in script style, which is size 7. Would it be better to use scriptscript style, having something like the following?

C\raise ??? \hbox{$_{_{++}}$}

| improve this answer | |

I liked @kundors solution, but modified it so that C and + uses the same font and has the same weight. Here you can see the difference and decide your self:

C\texttt{++} \texttt{C++} 


| improve this answer | |

I found that the suggestion from the C++ FAQ looks bad in many contexts. So I abused inline math to build something that also looks good in titles etc.:


This takes the standard version as an optional argument: \CC typesets C++, \CC[17] typesets C++17.

The following shot demonstrates \CC[14] and \CC in context:

enter image description here

| improve this answer | |

Another in the string of correct ways is to use the Middlescript macros by V. Eijkhout, which adjusts to the font centerline and covers size changes pretty well (about as well as standard subscript and superscript). I won't copypaste the macro code since it's just a SE link, but with it you can use:

C\textmidscript{++}         % text-mode
$\mathrm{C\midscript{++}}$  % math-mode
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.