1

I'm using XeLaTeX with the ucharclasses package to automatically switch font family on unicode classes.

The problem is that the transition commands also switch the text in the header.

First page, which is OK:

page with header sans-serif

Next page, which is KO:

page with header serif

How can I isolate the change to the content of the chapter?

\documentclass[10pt,a5paper,twoside,openright]{book}

\usepackage[french]{babel}
\usepackage{relsize}
\usepackage{titling}
\usepackage{emptypage}
\usepackage[center]{titlesec}
\usepackage[]{lipsum}
\usepackage[]{fontspec}

% Fallback management.
\usepackage[]{ucharclasses}

\usepackage[
    papersize={152mm,214mm}, % A5 papersize + 2mm bleed.
    layout=a5paper,
    layouthoffset=2mm, % Bleed offset.
    layoutvoffset=2mm, % Bleed offset.
    bindingoffset=6mm,
    left=16.5mm,
    right=16.5mm,
    top=22mm,
    bottom=20mm,
    headsep=12mm,
]{geometry}

\author{NemuLumeN}
\title{Book title \\ 1 : first book}
\date{2022}

% Helps build better header and footer; places the page number in the footer.
\usepackage[]{fancyhdr}

% Redefine fancy style.
\fancypagestyle{fancy}{
    \fancyhf{}
    \fancyhead[EL]{\smaller{\smaller{\texttechnic{\MakeUppercase{\vspace{\baselineskip} \\ \thetitle}}}}}
    \fancyhead[OR]{\smaller{\smaller{\texttechnic\MakeUppercase{\chaptername\ \thechapter\ \\ \leftmark}}}}
    \renewcommand{\headrulewidth}{1pt}
    \fancyfoot[LE,RO]{\smaller{\thepage}}}

\newfontfamily\aserif{Times New Roman}

\newfontfamily\textfallbackserif[]{Times New Roman}

\newfontfamily\texttechnic{Arial}

\newenvironment{realbody}{%
    \setDefaultTransitions{\aserif}{\aserif}%
    \setTransitionsFor{Latin}{\aserif}{\aserif}%
    \setTransitionsFor{BlockElements}{\textfallbackserif}{\aserif}%
}{}

\pagestyle{fancy}

\begin{document}
\lipsum[1-5]

\begin{realbody}

\frontmatter

\maketitle

\tableofcontents

\mainmatter

\chapter{Chapter 1}

\lipsum[1-5]

\end{realbody}

\end{document}

I use the Times New Roman and Arial fonts, but you can switch to the font you have on your system.

4
  • 2
    unrelated but never use \usepackage[utf8]{inputenc} with xelatex (all it does is make a warning that it should not be used) Feb 11 at 20:25
  • why do you show an example with special fonts? It only makes testing difficult. Use instead something available on every system like e.g. tex gyre heros and tex gyre termes? Feb 12 at 8:57
  • Thank you @DavidCarlisle
    – NemuLumeN
    Feb 12 at 20:06
  • @UlrikeFischer , thank you for your interest. You are right, this is a little inconvenient. I tried to look for tex gyre fonts, but they were not installed. Were they supposed to come with the LaTeX installation (I use Windows + MiKTeX)? In the meantime, I have simplified the font part by using Arial and Times New Roman. The issue stays the same.
    – NemuLumeN
    Feb 12 at 20:17

1 Answer 1

0

You can turn off character classes in the heading

\fancypagestyle{fancy}{
    \fancyhf{}
    \fancyhead[EL]{%
     \XeTeXinterchartokenstate=0 %<<<<<<<<<<<<<<<<<<<<<<<<
      \smaller{\smaller{\texttechnic{\MakeUppercase{\vspace{\baselineskip} \\ \texttechnic\thetitle}}}}}
    \fancyhead[OR]{\smaller{\smaller{\texttechnic\MakeUppercase{\chaptername\ \thechapter\ \\ \leftmark}}}}
    \renewcommand{\headrulewidth}{1pt}
    \fancyfoot[LE,RO]{\normalfont\smaller{\thepage}}}

1
  • It worked. I also had to apply the same method to the other header parts. Thank you.
    – NemuLumeN
    Feb 12 at 21:37

You must log in to answer this question.

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