# How can I prevent LGR encoding from switching font size?

I am using 12pt fonts with what is essentially the article class. (That is, I'm using a custom class which is parasitic on article.cls.)

In order to set an appropriate headheight for fancyhdr using \geometry{}, I test the font size at the end of the preamble using \AtEndPreamble{} from etoolbox. The height is then adjusted according to whether 10pt, 11pt or 12pt is being used.

This all works fine with the following code:

\documentclass[12pt]{article}
\usepackage{etoolbox}
\usepackage[T1]{fontenc}
\makeatletter
\AtEndPreamble{%
\PackageWarning{mine}{font size is \f@size}
}
\makeatother

\begin{document}

some text

\end{document}


The log contains:

Package mine Warning: font size is 12 on input line 13.


However, if I need to typeset Greek, I want to use:

\documentclass[12pt]{article}
\usepackage{etoolbox}
\usepackage[LGR,T1]{fontenc}
\makeatletter
\AtEndPreamble{%
\PackageWarning{mine}{font size is \f@size}
}
\makeatother

\begin{document}

some text

\end{document}


Only now the log contains:

Package mine Warning: font size is 10 on input line 13.


Why does loading the LGR encoding change the font size at all? And why does it change it even when T1 is the default encoding?

How can I prevent or work around this problem?

Note that I am aware that I could use XeTeX or LuaTeX or ConTeXt to avoid this. However, for better or worse, this question is about a (pdf)TeX solution.

If there is an alternative way of typesetting small amounts of Greek text using (pdf)TeX, that would be perfectly satisfactory. I use the above with utf8 and inputenc which allows me to input the odd Greek phrase in unicode characters and have everything typeset nicely. Anything which supports that would work fine.

This question seemed related but I am using TeX Live and already have the relevant type1 fonts installed (e.g. /usr/local/texlive/2014/texmf-dist/fonts/type1/public/cbfonts/grmn1200.pfb).

• @jon Unfortunately, that won't work. \AtEndPreamble is a test in a class/package file which tests which font size has been selected in the document. It would defeat the purpose to hard code a value since in that case, I might as well just hard code the headheight. – cfr Sep 27 '14 at 21:26
• I've removed the pdftex tag as this also applies to 'classical' TeX! – Joseph Wright Sep 27 '14 at 21:33
• @JosephWright Thanks. I tried to find a suitable tag for (TeX + pdfTeX) but couldn't find one. I wanted one for that group as opposed to ConTeXt/LuaTeX/XeTeX. Is there a tag for that? – cfr Sep 27 '14 at 21:50
• @cfr No. We had some discussion I think about input encodings on meta: as encodings are essentially TeX90/e-TeX/pdfTeX rather than XeTeX/LuaTeX issues it seemed natural for this to follow from an encoding tag. – Joseph Wright Sep 27 '14 at 21:51
• My feeling is that you can rely on the font size only after \normalsize has been issued, which it is at \begin{document}. – egreg Sep 27 '14 at 23:35

You can rely on the font size only after \normalsize has been issued. This is part of \begin{document}.

I see no problem in setting \headheight as part of

\AtBeginDocument{...}


rather than \AtEndPreamble. However, doing

\AtEndPreamble{%
\normalsize
\PackageWarning{mine}{font size is \f@size}
}


prints

Package mine Warning: font size is 12 on input line 11.


in the .log file.

• Thanks. I was using \AtBeginDocument{} but I switched to \AtEndPreamble{} as it was not effective. I'm using \geometry{} to set headheight. As I understand it, I need to do this in the preamble. If I do it in the document, I can use \newgeometry{} but I don't want to wipe everything else. I only want to change headheight at this point. Using \AtEndPreamble seemed to solve that issue until I tried using LGR encoding. However, if I can use \normalsize in \AtEndPreamble, that would indeed solve the issue. – cfr Sep 27 '14 at 23:43
• \normalsize in \AtEndPreamble seems to work well with using \geometry{headheight= }. Thanks! – cfr Sep 27 '14 at 23:52

The file lgrenc.def includes the line

\DeclareErrorFont{LGR}{cmr}{m}{n}{10}


and it's this that causes the change of font size. This command resets \f@size amongst other things (taken from ltfssbas.dtx):

%  \begin{macro}{\DeclareErrorFont}
%    Declare the last resort shape! We assume that in this fontshape
%    there is a 10pt font but it doesn't really matter. We only loose
%    one macro name if the assumption is false. But at least the font
%    should be there!
%    \begin{macrocode}
\def\DeclareErrorFont#1#2#3#4#5{%
\xdef\error@fontshape{%
\noexpand\expandafter\noexpand\split@name\noexpand\string
\expandafter\noexpand\csname#1/#2/#3/#4/#5\endcsname
\noexpand\@nil}%
%    \end{macrocode}
%    Initialize all those internal variables which may or may not have
%    values in the first seconds of NFSS' bootstraping process. Later
%    on such values will be updated when an encoding is selected, etc.
%
%    We definitely don't want to set |\f@encoding|; we can set all the
%    others since if they are left blank'' any selection would grap
%    error default values'' as well. However, this probably should
%    go also.
% \changes{v2.1n}{1994/05/14}{Don't set \cs{f@encoding}}
%    \begin{macrocode}
%      \gdef\f@encoding{#1}%
\gdef\default@family{#2}%
\gdef\default@series{#3}%
\gdef\default@shape{#4}%
\global\let\f@family\default@family
\global\let\f@series\default@series
\global\let\f@shape\default@shape
\gdef\f@size{#5}%
\gdef\f@baselineskip{#5pt}%
}
\@onlypreamble\DeclareErrorFont
%    \end{macrocode}
%  \end{macro}


As you can see, this is based on the idea some other reset will take place later.

Other encodings don't alter the fall-back, so you never see the fact that this also resets the size.

I guess in terms of 'how do I prevent this', you would have to locally disable \DeclareErrorFont (not ideal!).

\documentclass[12pt]{article}
\usepackage{etoolbox}
\let\savedDeclareErrorFont\DeclareErrorFont
\def\DeclareErrorFont#1#2#3#4#5{}
\usepackage[LGR,T1]{fontenc}
\let\DeclareErrorFont\savedDeclareErrorFont
\makeatletter
\AtEndPreamble{%
\PackageWarning{mine}{font size is \f@size}
}
\makeatother

\begin{document}

some text

\end{document}

• Interesting. Is there a good way to avoid the issues this raises? – cfr Sep 27 '14 at 21:48
• @cfr Report it as a LaTeX bug, perhaps? – Joseph Wright Sep 27 '14 at 21:55
• Hmmm... Thanks. Would it be possible to save the font size early in the class/package and then restore it at the end of the preamble? I tried \global\let\save@fontsize\f@size to save it and \global\let\f@size\save@fontsize to restore it - which seemed to work but I'm not sure whether it is at all safe. [Actually, this isn't what I tried first but this is the first thing which did not send pdfTeX into an infinite hang.] I see that \DeclareErrorFont also sets baselineskip to the same value. That seems odd? – cfr Sep 27 '14 at 22:16
• Where do LaTeX bugs get reported? – cfr Sep 27 '14 at 22:18
• – Joseph Wright Sep 28 '14 at 7:12