4

sometimes I change the fonts I used to build a latex document to see how it looks. So I have few old pdf files build with different fonts.

Is there latex command to print, inside the PDF when it is compiled, the official font name or specs used for text and for math? so this information is not lost or hard to find?

I know some PDF readers will allow one to find the fonts used in the PDF but sometimes this is hard to find and not all readers has this feature. I also like to print this in the document itself, may be on the margin or as footnote somewhere so it is easy to see.

Here is a MWE

\documentclass[12pt]{article}
\usepackage{amsmath}

\usepackage[T1]{fontenc}
\usepackage{fourier}
\usepackage{baskervald}

\begin{document}

%\footnote{This document was compiled using text font \textFontName 
%and math font \mathFontName} 

This is some math $\sin(x)$
\end{document}

I'd like to do something like the commented code above if there is a way to do it. Let assume there is only one font used in the document, as in the example above.

For example, for default font, I expect the footnote will be

  This document was compiled using text font "Computer Modern"
  and math font "Computer Modern"

Using TL 2018

4

My answer can be improved for math, but it has up to 16 groups, you can check what \makeatletter\meaning\mv@normal\makeatother produces to get an idea of what is involved.

\documentclass[12pt]{article}
\usepackage{amsmath}

\usepackage[T1]{fontenc}
\usepackage{fourier}
\usepackage{baskervald}

\begin{document}

%\footnote{This document was compiled using text font \textFontName 
%and math font \mathFontName} 

This is some math $\sin(x)$.

\makeatletter
\edef\textFontName{\fontname\csname
  \f@encoding/\f@family/\f@series/\f@shape/\f@size\endcsname}
\edef\mathFontName{\fontname\textfont0}
\edef\mathLetterFontName{\fontname\textfont1}
\makeatother

See\footnote{Text Font: \textFontName

Math Operator Font: \mathFontName

Math Letter Font: \mathLetterFontName\par
}
\end{document}

enter image description here


With xetex:

\documentclass[12pt]{article}
\usepackage{amsmath}

\usepackage{fontspec}

\begin{document}

%\footnote{This document was compiled using text font \textFontName 
%and math font \mathFontName} 

This is some math $\sin(x)$.

\makeatletter
\edef\textFontName{\fontname\csname
  \f@encoding/\f@family/\f@series/\f@shape/\f@size\endcsname}
\edef\mathFontName{\fontname\textfont0}
\edef\mathLetterFontName{\fontname\textfont1}
\makeatother

See\footnote{Text Font: \texttt{\textFontName}

Math Operator Font: \texttt{\mathFontName}

Math Letter Font: \texttt{\mathLetterFontName}\par
}
\end{document}

enter image description here

| improve this answer | |
1

Yes, but it won’t give you the display name you want. The \f@family macro will expand to something like cmr instead of Computer Modern Roman, and \the\fam in math mode is a number.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.