# Can't make font (of different family from main) bold in new environment

My document's main text is set as follows:

\renewcommand{\familydefault}{\sfdefault}       % sans serif to default
\usepackage[defaultsans,osfigures,scale=1]{opensans}  % change main font here


So that the main body is the Open Sans font. I've styled section headings with the serif Computer Modern using sectsty. I created a new environment to make certain parts of the document (for example, page number, title, names on title page) Computer Modern as well with the following custom environment:

\newenvironment{compmod}{\fontfamily{cm}\selectfont}


And it works fine. Except, I want to make a new environment like above that is bold faced, (or styled as I please) as well, but the following does not work:

\newenvironment{compmod}{\fontfamily{cm}\fontseries{b}\selectfont}


I've tried a few other things to no avail. My hunch is that because I set the main font to another family (and sans-serif), there is some clashing.

Any insight is appreciated.

• Welcome to TeX SX! Did you try with \rmdefault? Apr 23, 2019 at 19:39
• you have not provided a usable test file nor shown a log file of the error, but there is not normally a cm family, there are cmr and cmss families, also the bold is usually bx (bold extended) rather than b Apr 23, 2019 at 19:48
• There are no errors. But you answered my question by suggesting cmr. Thank you! Apr 23, 2019 at 19:54
• Not errors but there must have been font substitution warnings in the log detailing the font you specified is not available and specifying the fallback fonts being used. Apr 23, 2019 at 20:01

The choice of fonts seems disputable.

\documentclass{article}

\let\CMserif\rmdefault % save the default font family name

\usepackage[defaultsans,osfigures,scale=1]{opensans}  % change main font here
\usepackage{sectsty}

\renewcommand{\familydefault}{\sfdefault}

\allsectionsfont{\serifbold}

\newcommand{\serifbold}{\fontfamily{\CMserif}\bfseries}
\newenvironment{compmod}{\serifbold}{}

\begin{document}

\section{This title is serif}

This text is sans serif, \begin{compmod}and this is serif bold\end{compmod}.

\end{document}


If you scale down OpenSans, at least the height matches.

\documentclass{article}

\let\CMserif\rmdefault % save the default family name

\usepackage[defaultsans,osfigures,scale=0.82]{opensans}  % change main font here
\usepackage{sectsty}

\renewcommand{\familydefault}{\sfdefault}

\allsectionsfont{\serifbold}

\newcommand{\serifbold}{\fontfamily{\CMserif}\bfseries}
\newenvironment{compmod}{\serifbold}{}

\begin{document}

\section{This title is serif}

This text is sans serif, \begin{compmod}and this is serif bold\end{compmod}.

\end{document}


• Thank you for the tip on scaling to match the height (my hack was to simply adjust the document point size and enlarge the computer modern text). Are there any serif fonts you'd recommend that go well with CMR? (besides the default sans-serif) Apr 24, 2019 at 14:09
• @likethevegetable The choice of serif for titles and other inserts with the main text sans serif is quite unusual. Apr 24, 2019 at 14:14

There is not normally a cm family, there are cmr and cmss families, also the bold is usually bx (bold extended) rather than b

You did not say but on the terminal and in the log you presumably got a warning such as

LaTeX Font Warning: Font shape OT1/cm/b/n' undefined
(Font)              using OT1/cmr/m/n' instead on input line 5.