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)?.
Related
Sorry for bad english
I have a problem with my Latex code (I'm not very good in coding). I want an output like this:
Part I
Chapter I
Chapter II
Part II
Chapter I
Chapter II
I also wanted to create a box around my title of the parts , this doesn't work like I wanted, so I used \part* and \addcontentsline{toc}{part}{PART I} (to write the line in the table of content).So the code is:
\fbox{\begin{minipage}{\linewidth}
\part*{\begin{center}
PART I
\end{center}}
\end{minipage}}
\addcontentsline{toc}{part}{PART I}
\vspace{0.7cm}
I saw this methode to reset the counter of the chapters:
\makeatletter
\#addtoreset{chapter}{part}
\makeatother
but this doesn't work, I think it's due to use of \part*.
Has anyone an idea? THNANKS!
Hope the example bellow can help:)
\documentclass[a4paper,11pt,]{report}
\usepackage{hyperref}
\begin{document}
\tableofcontents
\newpage
\fbox{\begin{minipage}{\linewidth}
\part*{\begin{center}
INTRODUCTION
\end{center}}
\end{minipage}}
\addcontentsline{toc}{part}{INTRODUCTION}
\vspace{0.7cm}
\chapter{Hello}
\section{my}
\newpage
\fbox{\begin{minipage}{\linewidth}
\part*{\begin{center}
CONCLUSION
\end{center}}
\end{minipage}}
\addcontentsline{toc}{part}{CONCLUSION}
\vspace{0.7cm}
\chapter{name}
\section{is}
\end{document}
As you already know the solution for \part, how about simply using this and make it look like \part*? This has the advantage that you could add the boxes around the part titles automatically.
\documentclass[a4paper,11pt,]{report}
\usepackage[newparttoc]{titlesec}
\titleformat{\part}[frame]
{\normalfont}
{}
{8pt}
{\Large\bfseries\filcenter}
\usepackage{titletoc}
\titlecontents{part}[0em]
{\vspace{2em}\large\bfseries\sffamily\relax}
{\contentslabel[\relax]{0em}}{}{\hfill\contentspage}
\usepackage{hyperref}
\makeatletter
\#addtoreset{chapter}{part}
\makeatother
\begin{document}
\tableofcontents
\part{INTRODUCTION}
\chapter{Hello}
\section{my}
\part{CONCLUSION}
\chapter{name}
\section{is}
\end{document}
This question has already been answered once (wrap LaTeX command in environment), yet I still struggle to make my own rather simple new environment command work.
What I wanted to do is to convert the following LaTex block, which shows the output of some code, into a command I can reuse.
\fbox{\begin{minipage}{\textwidth}
\texttt{
>> CODE OUTPUT
\end{minipage}}
It is clear that in order to make a new environment command that replicates what I do above, I will have to make use of wrappers. (Because of the \fbox and the \texttt command.)
I would like to do this without having to download yet another package, or going into the secret realms of LaTex with some predefined \dir command that is only there to do the same job twice.
Checking the link from before, it seems that a productive solution is to use \bgroup and \egroup. I would therefore write something like this:
\newenvironment{CodeOutput}
{\fbox\bgroup\begin{minipage}{\textwidth}\texttt\bgroup}
{\egroup\end{minipage}\egroup}
Yet this will still not work. (On Overleaf at least.) It would be great if there was a straightforward way of making commands like these. Thanks for any useful suggestions!
If want to write a command that does what you're after, then the following would work:
\newcommand{\mycmd}[1]{%
\fbox{%
\begin{minipage}{\dimexpr\linewidth-2\fboxrule-2\fboxsep}
\ttfamily #1
\end{minipage}%
}%
}
The idea here works because the <arg>ument supplied to \mycmd{<arg>} is replaced by #1 in its entirety. If you want want to rewrite this as an environment, it's a little more difficult, purely because of \fbox. \fbox is doesn't have an environment-form equivalent the same way \texttt has \ttfamily (which is technically a font switch). There is a quick way around it provided by environ - it allows you to capture the contents of an environment in a macro \BODY:
\usepackage{environ}
\NewEnviron{myenvA}{%
\fbox{%
\begin{minipage}{\dimexpr\linewidth-2\fboxrule-2\fboxsep}
\ttfamily \BODY
\end{minipage}%
}%
}
However, you do have the option by capturing the content of an environment inside a box and then setting the box inside an \fbox:
\newsavebox{\codebox}% To store the content of myenvB
\newenvironment{myenvB}{%
\begin{lrbox}{\codebox}%
\ttfamily\ignorespaces
}{%
\end{lrbox}%
\fbox{\begin{minipage}{\dimexpr\linewidth-2\fboxrule-2\fboxsep}
\usebox{\codebox}%
\end{minipage}}%
}
The following minimal example shows all the above cases:
\documentclass{article}
\usepackage{environ}
\newcommand{\mycmd}[1]{%
\fbox{%
\begin{minipage}{\dimexpr\linewidth-2\fboxrule-2\fboxsep}
\ttfamily #1
\end{minipage}%
}%
}
\NewEnviron{myenvA}{%
\fbox{%
\begin{minipage}{\dimexpr\linewidth-2\fboxrule-2\fboxsep}
\ttfamily \BODY
\end{minipage}%
}%
}
\newsavebox{\codebox}
\newenvironment{myenvB}{%
\begin{lrbox}{\codebox}%
\ttfamily\ignorespaces
}{%
\end{lrbox}%
\fbox{\begin{minipage}{\dimexpr\linewidth-2\fboxrule-2\fboxsep}
\usebox{\codebox}%
\end{minipage}}%
}
\begin{document}
\noindent
\fbox{\begin{minipage}{\dimexpr\linewidth-2\fboxrule-2\fboxsep}
\ttfamily SoMe CoDe HeRe
\end{minipage}}
\bigskip
\noindent
\mycmd{SoMe CoDe HeRe}
\bigskip
\noindent
\begin{myenvA}
SoMe CoDe HeRe
\end{myenvA}
\bigskip
\begin{lrbox}{\codebox}
\ttfamily SoMe CoDe HeRe
\end{lrbox}
\noindent
\fbox{\begin{minipage}{\dimexpr\linewidth-2\fboxrule-2\fboxsep}
\usebox{\codebox}
\end{minipage}}
\bigskip
\noindent
\begin{myenvB}
SoMe CoDe HeRe
\end{myenvB}
\end{document}
How do I remove the default date that a documentclass{article} adds in LaTeX?
Thanks
Try using \date{}.
use \date{} before "\begin{document}"
Also ensure that you dont have any variation of this in your code.
{\large \today}
A blank \date{} will still use some vertical spacing. Check this post on TeX Exchange for a comprehensive list of alternatives, like the titling package.
The command
\documentclass{article}
\begin{document}
\title{text}
\author{names}
\maketitle
\date{}
\end{document}
will give the out put as shown here:
But the code:
\documentclass{article}
\begin{document}
\title{text}
\author{names}
\date{}
\maketitle
\end{document}
will give the desired output, I believe, you want:
The command \date{} should be put after \author{names} and before \maketitle.
The exact code snippet to "copy and paste" is as follows:
\date{}
\begin{document}
I am wondering how I can get the document title in LaTex, for use elsewhere in the document. I just want to be able to echo it.
Using \#title does not work because \maketitle clears \#title. This seems silly to me but that's the way it is. One solution is to redefine \title to save the title somewhere else. For instance,
\def\title#1{\gdef\#title{#1}\gdef\THETITLE{#1}}
then use \THETITLE.
You can do the other way around: \def\MYTITLE{...} then \title{\MYTITLE} and later use \MYTITLE again.
I had success just writing a new command.
\newcommand{\mytitle}{...}
\title{\mytitle}
There is a package called authoraftertitle that does exactly this
\documentclass{article}
\usepackage{authoraftertitle}
\setlength\parindent{0 pt}
\begin{document}
\title{a good title}
\author{a better author}
\date{the best date}
\maketitle
the title is: \textbf{\MyTitle} \\
the author is: \textbf{\MyAuthor} \\
the data is: \textbf{\MyDate} \\
\end{document}
This is a workaround...
\let\titleoriginal\title % save original \title macro
\renewcommand{\title}[1]{ % substitute for a new \title
\titleoriginal{#1}% % define the real title
\newcommand{\thetitle}{#1} % define \thetitle
}
\title{This is my title}
\begin{document}
\thetitle
\end{document}
The short version of the title was ignored here...
\documentclass{book}
\usepackage{amsmath}
\usepackage[german]{babel}
\usepackage{amssymb}
\usepackage{amsxtra}
\usepackage[dvips]{epsfig,psfrag}
\usepackage{listings}
\newcommand{\refchapter}[1]{Kapitel~\ref{#1}}
\newcommand{\refsec}[1]{Sektion~\ref{#1}}
\newcommand{\refeqn}[1]{Gleichung~(\ref{#1})}
\newcommand{\reffig}[1]{Abbildung~\ref{#1}}
\title{\bf Grundz\"uge der Softwareentwicklung \\
{\small Analyse- und Entwurfsdokument} \vspace{1cm}\\
\centering
\epsfig{file=figures/logo.eps,width=.4\textwidth}
}
\author{Uschi Musterfrau, Detlef Mustermann und Ralf Auchmustermann}
\date{Matr.-Nr. 0815, 0816 und 0817 \\
email: {\tt [uschi|detlef|ralf]#rwth-aachen.de}
}
\begin{document}
\lstloadlanguages{[ISO]C++}
\lstset{basicstyle=\small, numbers=left, numberstyle=\footnotesize,
stepnumber=1, numbersep=5pt, breaklines=true, escapeinside={/*#}{#*/}}
\pagestyle{headings}
\maketitle
\tableofcontents
\include{vorwort}
\include{analyse}
\include{entwurf}
\include{nutzerdoc}
\include{entwicklerdoc}
\bibliographystyle{plain}
\bibliography{analyse_entwurf}
\appendix
\include{quellcode}
\end{document}
this is how my file starts. I didn't even edit it, I received it like this. However, if I want to make a pdf, it gives me the undefined control sequence error at the first line... What is wrong??
My guess is that you're trying to use TeX instead of LaTeX. TeX won't recognize the \documentclass command. Make sure you use LaTeX.
It might be that one of the tools in your tool chain gets irritated by a Byte-Order Mark (BOM), which is a special Unicode character to indicate the endianness used in your file.
Unfortunately, a BOM may have unwanted side-effects.
You might try to save the file with another editor which won't add this mark in the beginning, or remove it with a hex editor.
try getting rid of \usepackage[dvips]{epsfig,psfrag} if you're using pdflatex.
Perhaps TeXshop doesn't recognize your file as a LaTeX file and runs it with plain TeX or ConTeXt. If you can post your logfile (the beginning) here, we can help you for sure.