# Conflict between fontspec and geometry

Using the option lines=x of geometry does not give the expected result when the fontspec package is used in the same document. For example, declaring lines=40 does not result in 40 lines per page but 29:

\documentclass[a4paper,11pt]{article}
\usepackage{fontspec}
\usepackage{geometry}
\geometry{lines=40}
\usepackage{lipsum,lineno}

\begin{document}
\linenumbers
\lipsum
\end{document}


This hapens with standard classes (book, article), but not with the KOMA classes nor with memoir.

Loading geometry before fontspec and using newgeometry instead of geometry produces the expected result, but I would like to know what the problem is and how to resolve it.

• You can avoid the problem by putting \normalsize before geometry. For some reason fontspec changes the baselineskip, but it needs some investigation to find out why exactly. – Ulrike Fischer Dec 6 '15 at 21:57
• that's odd, without geometry it's 13.6pt then 10pt after fontspec until begin document, then 13.6 again. – David Carlisle Dec 6 '15 at 22:13
• @DavidCarlisle: It is caused by the \DeclareErrorFont from eu2enc. You get the same problem without fontspec and e.g. LGR. The KOMA-classes are not affected as they patch \selectfont. So imho it is a geometry bug, it shouldn't rely on a correct baselineskip but call \normalsize. – Ulrike Fischer Dec 6 '15 at 23:00
• @UlrikeFischer thanks now you say that, I've seen that before somewhere:-) yes geometry could do \normalsize but it's not clear that fontspec really should be leaving a 10pt baselinskip in the preamble. eu2enc.def could do \DeclareErrorFont{EU2}{lmr}{m}{n}{\baselineskip} for example. – David Carlisle Dec 6 '15 at 23:12
• @DavidCarlisle: As I wrote LGR does the same. And I grepped and found quite a number of \DeclareErrorFont declaration -- and all with fix sizes (one of them in latex.ltx). Also it doesn't look right to set the fontsize to \baselineskip. And why is \baselineskip set to the fontsize when \DeclareErrorFont is used? – Ulrike Fischer Dec 6 '15 at 23:31

The problem is that \baselineskip is "wrong" (10pt instead of 13.4pt) when geometry calculates the lines as an \DeclareErrorFont from the euenc package changes it.

It is a bit unclear if it is a latex "bug" that \DeclareErrorFont resets the \baselineskip but even without this change geometry can err. E.g. This example

\documentclass[a4paper,11pt]{article}
\usepackage{setspace}
\onehalfspacing
\usepackage{geometry}
\geometry{lines=40}
\usepackage{lipsum,lineno}
\begin{document}
\linenumbers
\lipsum
\end{document}


gives a different layout then this one

\documentclass[a4paper,11pt]{article}
\usepackage{setspace}
\usepackage{geometry}
\geometry{lines=40}
\usepackage{lipsum,lineno}
\onehalfspacing
\begin{document}
\linenumbers
\lipsum
\end{document}


I can imagine other szenarios and imho geometry can't catch all possible cases, so if you want to use the lines option (and heighrounded) you will sometimes have to help it a bit to get the correct/wanted line height. In your cases by issuing \normalsize before \geometry{lines=40}. Or by setting the option with \newgeometry only at the begin of the document.