# Does using \font cause problems?

While editing a LaTeX file in Vim with the LaTeX-Box and syntastic plugins and compiling using XeLaTeX, I got this warning:

Don't use "\font" in LaTeX documents


for these two lines:

\font\ttfstandard Ubuntu at12pt
\font\ttfbold "Ubuntu Bold" at12pt


Is \font deprecated or otherwise harmful? If not, why would I have got this message? What should I use instead?

• Yes, it's deprecated. Load fontspec instead. – egreg Jul 17 '15 at 20:03

Yes, using \font in LaTeX is deprecated. The reason is very simple: try the following sample file.

\documentclass[12pt]{article}

\font\ttfstandard="Ubuntu" at 12pt
\font\ttfbold="Ubuntu Bold" at 12pt

\begin{document}

\section{A title with an {\ttfstandard Ubuntu} word}

Some text and an {\ttfstandard Ubuntu} word.

\end{document}


As you clearly see, the font doesn't honor the size changing commands.

\documentclass[12pt]{article}

\usepackage{fontspec}

\setsansfont[Scale=MatchLowercase]{Ubuntu}

\begin{document}

\section{A title with an \textsf{Ubuntu} word}

Some text and an \textsf{Ubuntu} word.

\end{document}


You can see that the size is honored and also that boldface is automatically selected in the section title.

You may want to have Scale=MatchUppercase, which would give

The choice depends much on how you want to use the sans serif type. If in isolation, MatchUppercase may be preferable; if interspersed with serif type, I'd go with MatchLowercase.

• Thanks. Do fontenc and fontspec work well together? Or does that warrant a different question? – muru Jul 17 '15 at 20:34
• You do not need fontenc nor inputenc with xelatex. Just load fontspec – MaxNoe Jul 17 '15 at 20:37