4

I am encountering unexpected behavior when using the \Huge and \tiny commands with the anyfontsize package.

Below are two snippets of LaTeX code illustrating the issue. The expectation is for \Huge and \tiny to reset the font size to their original respective sizes after they have been changed using \fontsize{<size>}{<line space>}\selectfont, but instead, they seem to retain the last set size. When the class is loaded with [12pt], then \huge command will also result in a wrong size.

First case (\Huge):

\documentclass[10pt]{article}
\usepackage{anyfontsize}

\begin{document}
{\Huge This is a Huge text.}

{\fontsize{30}{40}\selectfont This is a very Huge text.}

{\Huge This is a Huge text.} % This should be original Huge size, but it's too HUGE!

{\Large This is a large text.\par}
{\large This is a large text.\par}

{\Huge This is a Huge text again.} % This should be original Huge size, but it's too HUGE!

{\fontsize{40}{50}\selectfont This is a very HUGE text.}

{\Huge This is a Huge text again.} % This should be original Huge size, but it's even more HUGE!
\end{document}

Second case (\tiny):

\documentclass[10pt]{article}
\usepackage{anyfontsize}

\begin{document}
{\tiny This is a tiny text.}

{\fontsize{2}{2}\selectfont This is a very tiny text.}

{\tiny This is a tiny text.} % This should be original tiny size, but it's too tiny!
\end{document}

When I look inside the anyfontsize package, it is overriding \externalfont using:

\def\anyfontsize@set#1 #2\hfuzz{%
  \@tempdimb=\f@user@size\p@%
  \edef\external@font{#1 at\the\@tempdimb}%
}%

However, I couldn't find any reasons why it changes the behavior of \Huge and \tiny. I guess something is happening behind the scenes.

I want to know what is causing this unexpected behavior of \Huge and \tiny commands, (or is it an expected behavior?) Is there a better solution for setting the font size, while maintaining the behavior of \Huge and \tiny command?

3
  • for the cm fonts, \usepackage{type1cm} is a better option. All other fonts imho nowadays scale anyway, so simply drop that package. Mar 3 at 7:47
  • Yes, using type1cm is also working well, achieving my goal.
    – JSLee
    Mar 3 at 16:37
  • 1
    fix-cm is better, it supports also T1-encoding (I was in hurry this morning and mixed up the names). Mar 3 at 16:52

1 Answer 1

5

Let's have a look at anyfontsize.sty

% anyfontsize.sty -- allow font size substitutions
% by Péter Szabó <[email protected]> at Sat Feb  3 13:56:49 CET 2007
[...]
%** Overrides \externalfont by specifying the ` at <requested-fontsize>pt'
%** clause. The requested font size is in \f@user@size.
\def\anyfontsize@set#1 #2\hfuzz{%
  \@tempdimb=\f@user@size\p@%
  \edef\external@font{#1 at\the\@tempdimb}%
}%

%** Overrides definition in latex.ltx
%** See %%%% pts %%%% for the overridden part.
\gdef\tryif@simple#1-#2\tryif@simple{%
[...]
      %%%% pts %%%%
      \expandafter\anyfontsize@set\external@font\hfuzz
[...]

It's basically a 17-year-old hack. And if I test your examples with TeX Live 2012, the problem is exactly the same.

Note that even before anyfontsize was issued, the base LaTeX distribution had fix-cm that aims at solving the same problem for the Computer Modern fonts.

Just don't use anyfontsize. If you plan to use Computer Modern fonts (or European Modern in the T1 encoding), load

\RequirePackage{fix-cm}

before \documentclass. For other font packages, you needn't worry about sizes. There are quite specialized fonts, for instance RSFS for calligraphic capitals in math mode, that might need special treatment, but it's usually quite simple to change the font definitions by hand.

In ursfs.fd we find

\DeclareFontFamily{U}{rsfs}{\skewchar\font127 }
\DeclareFontShape{U}{rsfs}{m}{n}{%
   <5> <6> rsfs5
   <7> rsfs7
   <8> <9> <10> <10.95> <12> <14.4> <17.28> <20.74> <24.88> rsfs10
}{}

One can just add, in the document,

\DeclareFontFamily{U}{rsfs}{\skewchar\font127 }
\DeclareFontShape{U}{rsfs}{m}{n}{<-6> rsfs5 <6-8> rsfs7 <8-> rsfs10}{}

and the font will be available at any size.

2
  • 1
    Thank you for detailed answer. Using fix-cm package is indeed working well! Yet, I'm wondering what caused such unexpected behavior in anyfontsize. Also, how is the approach of fix-cm package differs from anyfontsize?
    – JSLee
    Mar 3 at 16:36
  • 1
    @JSLee fix-cm properly declares the font sizes, while anyfontsize tries to patch an internal latex command (and doesn't do it right). Mar 3 at 16:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .