3

I'm using the font family mathptmx and I want to use baskervald only for the alphabet Q (not always but in many specific situation). So I defined

\def\Q{{\fontfamily{ybv}\selectfont
Q}}

But this does not work. How should I modify this?

  • 1
    E.g. \def\Q{{\fontfamily{ybv}\fontsize{1cm}{2cm}\selectfont Q}}, see e.g. https://tex.stackexchange.com/a/153659. It is general not recommended to use a single-letter macro like \Q, nor to use \def to define them (rather you should use \newcommand. –  Feb 20 '20 at 05:12

1 Answers1

5

If I try this code

\documentclass{article}

\usepackage{mathptmx}

\def\Q{{\fontfamily{ybv}\selectfont Q}}

\begin{document}

Q\Q

\end{document}

I get the following warning on the console

LaTeX Font Warning: Font shape `OT1/ybv/m/n' undefined
(Font)              using `OT1/cmr/m/n' instead on input line 8.

It means that Baskervald is not available in the default OT1 encoding.

Changing this to

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{mathptmx}

\def\Q{{\fontfamily{ybv}\selectfont Q}}

\begin{document}

Q\Q

\end{document}

might seem to solve the issue. However, you should be aware of two problems:

  1. mathptmx has been created a couple of decades ago as a way to get not too heavy PostScript output from LaTeX documents;

  2. \def is quite a dangerous command for being used by a beginner (or even an advanced user).

Issue 1 is solved by using a properly designed Times-like typeface with accompanying math font; issue 2 is solved by \newcommand.

\documentclass{article}

\usepackage[T1]{fontenc}
\usepackage{newtxtext,newtxmath}

\newcommand\Q{{\fontfamily{ybv}\selectfont Q}}

\begin{document}

Q\Q

\end{document}

enter image description here

egreg
  • 1,121,712
  • Thanks so much! This completely solves my problem. By the way, could you explain a bit more why \def is dangerous? Is \newcommand better than \def in most of the situation? – quasi-mathematician Feb 20 '20 at 18:18
  • @HLEE You can easily see the problem if you do \def\box#1{\framebox[2\width]{#1}} (silly definition, just to make you see the issue) and use \box{ABC} in the document. With \newcommand you don't risk to redefine a command you don't know about. – egreg Feb 20 '20 at 18:23