# Changing fontfamily in environment lets pdflatex hang

In a book I defined an individual table as follows:

\newenvironment{tbl}[3]%
{%
%\fontfamily{\sffamily}\selectfont
% Caption
\if\relax\detokenize{#2}\relax
\newcommand{\tblcaption}{}
\else
\newcommand{\tblcaption}{\caption{#2}}
\fi
% Label
\if\relax\detokenize{#3}\relax
\newcommand{\tbllabel}{}
\else
\newcommand{\tbllabel}{\label{#3}}
\fi
\footnotesize
\rowcolors{2}{white}{dark-green!5}
\begin{longtable}[c]{#1}
}{%
\hiderowcolors%
\tblcaption%
\tbllabel%
\end{longtable}
\normalsize
%\fontfamily{\rmfamily}\selectfont
}


When I uncomment the two \fontfamily statements, pdflatex.exe is running forever. This happens independently of the TeX editor I am using and the TeX distribution (TeX Live and MiKTeX).

I guess that something in the environment definition must cause the problem, but I cannot figure out, what that might be.

• Welcome! \fontfamily expects something like phv as an argument. If you just want the default serif, use \rmfamily - no need for \fontfamily or \selectfont. Similarly for \sffamily. If you need more help please post compilable code or code which produces the error when we try to compile it. – cfr Jun 23 '18 at 0:31
• I will give \sffamily / \rmfamily a try - thank you! I took the code from other postings, that I read about changing the font in an environment. – StackExchange42 Jun 23 '18 at 0:37
• Either you misunderstood something or the code you found is erroneous. Do you have a link? If it is on this site, it should be corrected if it is really as you say. – cfr Jun 23 '18 at 0:39
• I read tex.stackexchange.com/questions/28494/… - and that made me think that this were the way to go - but I probably misunderstood the thread. – StackExchange42 Jun 23 '18 at 1:39
• I think you are just trying to mix bits from different answers/comments which are of different kinds. Note that the example with \fontfamily{} uses a name and not a macro in the argument, pcr. Moreover, as noted in the comments, just using \ttfamily instead of \fontfamily{pcr}\selectfont would be better (simpler, more flexible, more consistent). Maybe you read the suggestion as saying to just substitute the pcr rather than the whole line? – cfr Jun 23 '18 at 1:44

## 1 Answer

\rmfamily, \sffamily and \ttfamily are self-sufficient font switches. You do not need \fontfamily or \selectfont with these and they aren't suitable as arguments to \selectfont.

\fontfamily expects the name of a font family e.g. phv, clm2dj or AnnSton. You can't give it an argument which is itself a font-switching macro.

So just use

\sffamily


and

\rmfamily


alone.

If you need further help, please post code for a minimal document we can compile to reproduce the problem.