3

Consider the following LaTeX manuscript:

\documentclass{article}
\usepackage{fontspec}
\setmainfont{Times}
\begin{document}
    \fontsize{50}{50}\selectfont
    Hello, world!
\end{document}

When processed with xelatex, it renders the text as follows. In particular, the font size is 50pt, as expected:

Big size

If I now move the \fontsize...\selectfont commands to the preamble, like this:

\documentclass{article}
\usepackage{fontspec}
\setmainfont{Times}
\fontsize{50}{50}\selectfont
\begin{document}
    Hello, world!
\end{document}

xelatex ignores the size specifications, and the text renders small:

Small size

Why is this?

Evan Aad
  • 11,066
  • 4
    If I'm not mistaken begin document contains a normalize declaration to ensure fonts gave been setup correctly. – daleif Jul 29 '17 at 06:31
  • 3
    \begin{document} calls for \normalsize which negates your font size setting. See https://tex.stackexchange.com/a/152085/117534 – Troy Jul 29 '17 at 06:32
  • @daleif: So there's no general way of setting the default font size in the preamble? – Evan Aad Jul 29 '17 at 06:33
  • 1
    @EvanAad try: \AtBeginDocument{\fontsize{50}{50}\selectfont} – koleygr Jul 29 '17 at 06:42
  • Use a class that supports custom font sizes and make a custom clo file. – daleif Jul 29 '17 at 09:08
  • @daleif: Could you give an example for such a class, please? – Evan Aad Jul 29 '17 at 09:12
  • Memoir supports it and I'm guessing KOMA classes have something similar. Might not be well described in the manuals. Why would you even have a 50pt font set from the preamble? – daleif Jul 29 '17 at 09:14
  • @daleif: Mostly for experimentation purposes, but it Just seems cleaner to set it in the preamble. – Evan Aad Jul 29 '17 at 09:15
  • I've never seen others try to do it that way, most just do that kind of experiments in the doc it self. Saves having to write your own clo file. – daleif Jul 29 '17 at 09:17

3 Answers3

5

Setting up a new "normal" font size involves also changing \Large, \small and some other commands and also spacings (e.g. for lists). Check size10.clo (loaded by your document) or scrsize11.clo (loaded by mine) to get an idea what is involved. There exist a number of .clo-files for other fontsizes, but if you want to change to an arbitrary fontsize you should better use a class like scrartcl from the KOMA-bundle:

\documentclass{scrartcl}
\KOMAoptions{fontsize=50pt}
\usepackage{fontspec}
\setmainfont{Times New Roman}


\begin{document}
Test, \Large large, \tiny tiny
\end{document}

enter image description here

Ulrike Fischer
  • 327,261
3

When latex or xelatex reads \begin{document} it changes fontsize back to \normalsize... Try the next code to see it:

\documentclass{article}
\usepackage{fontspec}
\setmainfont{Linux Libertine O}
\renewcommand\normalsize{\fontsize{50}{50}\selectfont}

\begin{document}
   Hello, world!
\end{document}

The problem is that if you use the above command, then \Large, \small etc has also to be changed. So, a better solution is to make the command be read at begin of document:

\documentclass{article}
\usepackage{fontspec}
\setmainfont{Linux Libertine O}
\AtBeginDocument{\fontsize{50}{50}\selectfont}

\begin{document}
   Hello, world!
\end{document}

Edit: (the below is not true) This way it will give you the desired results even if you start a section, or use \Large etc

Unfortunately you have to change manually every size:

See here: Change font size of \Large etc.

koleygr
  • 20,105
2

If your aim is just to print a line with big font size, just do the declaration when you want to output the line. I see no real advantage in issuing the declaration in the preamble. There's always

\AtBeginDocument{\fontsize{50}{50}\selectfont}

that will do.

For the more general problem of defining a larger base font size, since you're using XeLaTeX or LuaLaTeX, there is a simple (or perhaps simplistic) solution to the fact that LaTeX issues \normalsize at begin document. Note you need to also set the sans and mono font at the same scale, if you use them.

\documentclass{article}
\usepackage[a3paper]{geometry}
\usepackage{fontspec}

\setmainfont{Times New Roman}[Scale=5]
\linespread{5}

\begin{document}

\section{Humongous}

Some text at 50pt size.
Some text at 50pt size.
Some text at 50pt size.
Some text at 50pt size.
Some text at 50pt size.
Some text at 50pt size.
Some text at 50pt size.
Some text at 50pt size.
Some text at 50pt size.
Some text at 50pt size.
Some text at 50pt size.

\end{document}

enter image description here

I add the info window

enter image description here

egreg
  • 1,121,712
  • The "scale" option is less than ideal, since in the case of outline fonts (which is what I was interested in yesterday when I wrote this post), it pumps up the outline's line width relative to a font that is the same size, but not scaled. – Evan Aad Jul 30 '17 at 03:08
  • @EvanAad Click on this link: one line uses \fontsize{50}{50}, the other one the font at natural size, but defined with Scale=5. I won't tell which is which: can you guess? – egreg Jul 30 '17 at 06:23
  • No, I can't. Sorry. I thought fontspec's Scale was similar to PGF's canvas scale, which changes line widths. But then when you tell fontspec to scale a font by x amount, relative to what does it scale it? Can you specify the normal size relative to which the scaling should take place? – Evan Aad Jul 30 '17 at 06:47
  • @EvanAad Unless the font has optical sizes, such as Latin Modern, it is designed at a single size. – egreg Jul 30 '17 at 07:04
  • Is there a way to tell what this size is? – Evan Aad Jul 30 '17 at 07:12
  • @EvanAad It should be in the font information. Usually 10pt (or 10bp) – egreg Jul 30 '17 at 07:18
  • What do you mean by "font information"? The .ttf file? – Evan Aad Aug 01 '17 at 09:33
  • @EvanAad Where, otherwise? – egreg Aug 01 '17 at 09:35
  • I've asked in a font designers forum, and I was told physical font size is not normally stored in .ttf files. – Evan Aad Aug 01 '17 at 09:37
  • @EvanAad OpenType fonts usually have the information. – egreg Aug 01 '17 at 09:42
  • I was told that a typeface is implemented based on abstract length units called upm (units per em) that have no inherent physical interpretation. The font file (.ttf or what have you) doesn't provide a default physical font size. The font size would be set by the document class or by the user by issuing \fontsize commands. – Evan Aad Aug 01 '17 at 09:53
  • @EvanAad You were told wrong. If I do otfinfo -z /Library/Fonts/ebgaramond/EBGaramond12-Regular.otf, the output is design size 12 pt, size range (9.5 pt, 120 pt], subfamily ID 1, subfamily name Regular – egreg Aug 01 '17 at 10:22