# Why does setmonofont change the justifying of normal text using the same font?

I usually use a different font for URLs e.g. email adresses. Today, I tried to change it in a letter to use the same font als the normal text and it cancelled the justification in the main body of the letter. A MWE is here:

\documentclass[fromemail=true]{scrlttr2}
\usepackage{fontspec}
\setmainfont[Ligatures=TeX]{TeX Gyre Pagella}
% \setmonofont[Ligatures=TeX]{TeX Gyre Pagella}
\usepackage{url}
\setkomavar{fromname}{John Doe}
\setkomavar{fromemail}{\url{john.doe@example.com}}
\usepackage{lipsum}
\begin{document}

\begin{letter}{irgendwas}
\setkomavar{toname}{People, who understand \LaTeX{} better than me}
\setkomavar{subject}{Is this a bug?}

\opening{Dear,}

\lipsum[1]

\closing{Regards}
\end{letter}
\end{document}


Compiling this (with LuaLaTeX) yields fine justification. But after uncommenting the commented line, there is no more justification in the main body.

Is this a bug or am I misunderstanding some features of LuaLaTeX, KOMAscript, fontspec or url?

• Strange, but are you looking for \urlstyle{rm} instead? – Andrew Swann Dec 8 '18 at 11:36

The monospaced font is assigned rigid interword space, which of course makes justification essentially impossible.

For efficiency reasons, a font is loaded only once, so your declaration has the effect of setting rigid interword space also for the main font.

Switch the order of declarations, as the “monospaced” font having flexible interword space should not be a concern.

\documentclass[fromemail=true]{scrlttr2}
\usepackage{fontspec}
\setmonofont[Ligatures=TeX]{TeX Gyre Pagella}
\setmainfont[Ligatures=TeX]{TeX Gyre Pagella}
\usepackage{url}
\setkomavar{fromname}{John Doe}
\setkomavar{fromemail}{\url{john.doe@example.com}}
\usepackage{lipsum}
\begin{document}

\begin{letter}{irgendwas}
\setkomavar{toname}{People, who understand \LaTeX{} better than me}
\setkomavar{subject}{Is this a bug?}

\opening{Dear,}

\lipsum[1]

\closing{Regards}
\end{letter}
\end{document}


On the other hand, using \urlstyle{rm} seems much easier.

\documentclass[fromemail=true]{scrlttr2}
\usepackage{fontspec}
\setmainfont[Ligatures=TeX]{TeX Gyre Pagella}
\usepackage{url}
\setkomavar{fromname}{John Doe}
\setkomavar{fromemail}{\url{john.doe@example.com}}
\urlstyle{rm}

\usepackage{lipsum}
\begin{document}

\begin{letter}{irgendwas}
\setkomavar{toname}{People, who understand \LaTeX{} better than me}
\setkomavar{subject}{Is this a bug?}

\opening{Dear,}

\lipsum[1]

\closing{Regards}
\end{letter}
\end{document}

• OK, understood. But it seems to be unnecessary means to increase effiency. If I declare a different font, it also has to be loaded. By happenstance it was the same font, but for a different goal. If I want to really only load one font, I could say something like '\let\ttdefault\rmdefault'. And it is also intransparent. – Toscho Dec 9 '18 at 10:59
• @Toscho Remember that when TeX was born memory was scarce, so loading twice a font could hinder loading others. XeTeX follows essentially the same model, just allowing different types of fonts to be loaded: a new font selector that points to the same external font as another font selector, the new one is made equivalent to the previous. You could load the font with a slightly different magnification (Scale=1.001 should do). – egreg Dec 9 '18 at 11:12
• When XeTeX and LuaTeX were born, memory was no relevant ressource any more. And I see no reasony to differentiate between loading a font with a different scaling and loading it with fixed/variable interword space. – Toscho Dec 10 '18 at 8:11
• @Toscho I don't know about LuaTeX, but XeTeX hooked in TeX without making changes where not necessary. That's a documented behavior. – egreg Dec 10 '18 at 8:24