I have been using fontspec in a lualatex document where as instructed by the manual I set my main/sans/mono font in my preamble with some default features.
However at some point I wish to temporarily redefine the mono font (in my particular case in a longtabu, but any thing which spans multiple page behave the same way.)
an additional feature of the document is that I have my email address in my header inside a \url{}
.
trying things out I enclosed my longtabu in a group and call setmonofont in the group before the table. This works fine, the text in mono font in the table is changed appropriately, the text in monofont outside the table is as defined in the preamble, but the email address in the header of the first page containing the multiple page table is changed to the redefined monofont (the header of the second page has the correct font).
I originally thought it was a bug in longtabu, then reproduced it with longtable, but then also reproduced it with simply have a group with text spanning 2 pages.
I guess it could also be a bug in fancyhdr but the same behaviour occurs with scrpage2. So either it is a bug in fontspec or I am doing something wrong. The manual specifically says that the \set{main,sans,mono}font
command should happen in the preamble. If this is the case, how can I redefined or addfeatures to a set font temporarily.
I do not want to use the \addfeatures{} in the group indescrimitately as I only want to affect the text in \texttt
and in \url
within that group hence the redefinition of the monofont.
compiling the following MWE, you can see that on page 1, the text is changed as it should, on page 2 however, the text in the page is fine but the header changes as well as the text in the group, while on page 3 the header is back to normal.
\documentclass[a4paper]{article}
\usepackage{fontspec}
\usepackage{lipsum}
\usepackage{longtable}
\usepackage{url}
%\usepackage{scrpage2}
\usepackage{fancyhdr}
\usepackage{hyperref}
\setmainfont{Iwona}
\setmonofont{Inconsolata}
%\clearscrheadfoot
\lhead{\href{mailto:[email protected]}{\nolinkurl{[email protected]}}}
\rhead{\texttt{\thepage}}
%\pagestyle{scrheadings}
\pagestyle{fancy}
\begin{document}
\lipsum[1]
\texttt{some text in monospace font}
\lipsum[2]
{\setmonofont{Courier New}
\lipsum[3]
\texttt{some text in monospace font}
\lipsum[4]
}
\newpage
\lipsum[5]
\texttt{some text in monospace font}
\lipsum[6]
\begingroup
\setmonofont{Courier New}
\lipsum[7]
\texttt{some text in monospace font}
\lipsum[8-9]
\texttt{some text in monospace font}
\lipsum[10-11]
\texttt{some text in monospace font}
\lipsum[12]
\endgroup
\lipsum[13]
\texttt{some text in monospace font}
\lipsum[14]
\end{document}
I apologise for the length of the MWE but I guess in this case it really is a MNWE.
I guess my question is what I am doing wrong, and if the answer is "nothing", how can I fix the bug.
\url{}
to use the newly defined mono font.