[Tex/LaTex] Forcing roman font in LaTeX

fontsr

I am using a LaTeX template from my university to typeset my thesis. I am making references to R and I have defined a new command with:

\newcommand{\R}{R}

in order to get the roman "R". The formatting of the thesis means that chapter titles are written in a sans serif font. When I type a chapter title e.g. "\R{} source code" it does not appear in serif, rather in the same sans serif font at the rest of the title.

Is there a way to force the "base" font to be used, regardless of which font is in use at that time?

Sorry for no minimal working example – I'm just not sure which part of the preamble causes the chapter titles to be sans serif!

Best Answer

In addition to suggestions from @bdh_dtu and @egreg you might want to also add in the xspace package:

\usepackage{xspace}
% combine suggestions from @bdh_dtu and @egreg with xspace
\newcommand{\R}{\textup{\textrm{R}}\xspace}

\xspace tries to be clever about inserting a space after the macro if there would normally be one but not if there shouldn't be one, such as when writing \R. (i.e. ending the line with \R followed by a full stop.