开发者

How to write "C++" in LaTeX

开发者 https://www.devze.com 2022-12-28 04:15 出处:网络
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.The standard solution for ca

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.


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

\verb!C++!


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}


You could try and use a typewriter font.

\texttt{C++}


I've found that the following gives good results:

\def\Cplusplus{C\raisebox{0.5ex}{\tiny\textbf{++}}}


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.


This answer, for the same question on the tex site, gives what I find to be a good looking way to 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{\#}}}


There is a \cpluspluslogo command "with the ‘+’ signs properly positioned" in the package texlogos.

An other discussion on TeX - LaTeX Stack Exchange: Prettiest way to typeset “C++” (cplusplus)?.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号