# polyglossia with XeLaTeX produces different pagebreaks than babel

I have observed some strange behavior and I would like to know if this is a bug, and if so, then whose bug it is.

When using polyglossia with XeLaTeX, I sometimes get different pagebreaks than when using babel with either PDFLaTeX or XeLaTeX; moreover, this seems to be related to the use of KOMA-Script and of mathtools with fleqn option. The PDF file produced with polyglossia has more pages.

However, the linebreaks are the same, at least in the following example.

Here is an example which is made to be compiled with

xelatex -jobname='with-babel' text.tex
xelatex -jobname='with-polyglossia' text.tex


to produce with-polyglossia.pdf and with-babel.pdf using, respectively, polyglossia and babel:

% test.tex

\documentclass[12pt,a4paper]{scrartcl}

\usepackage{etoolbox}

%% **fontspec** (LuaLaTeX, XeLaTeX)
%%     -- Advanced font selection in X∃LATEX and LuaLATEX
%%
%% This package is needed for **babel**.
%%
%% NOTE: the no-math option is needed to avoid a strange conflicts with
%%   AMS packages.
\usepackage[no-math]{fontspec}

%% NOTE: i do not know how this works, but it works
\expandafter\ifstrequal\expandafter{\jobname}{with-polyglossia}{
\usepackage{polyglossia}
\setdefaultlanguage{french}
}{
\usepackage[french]{babel}
}

%% **mathtools** (is supposed to require internally **amsmath**)
%%     -- Mathematical tools to use with amsmath
\usepackage[fleqn]{mathtools}

\begin{document}

\subsection*{Propriétés algébriques}

Les opérations algébriques dans $\mathbf{K}(X)$ satisfont les propriétés
suivantes :
\begin{enumerate}
\item
pour tous $F, G, H\in \mathbf{K}(X)$,
$(F + G) + H = F + (G + H),$
\item
pour tous $F, G\in \mathbf{K}(X)$,
$F + G = G + F,$
\item
pour tout $F\in \mathbf{K}(X)$,
$F + 0 = 0 + F = F,$
\item
pour tout $F\in \mathbf{K}(X)$,
$F + (-F) = (-F) + F = 0,$
\item
pour tous $F, G, H\in \mathbf{K}(X)$,
$(FG)H = F(GH),$
\item
pour tous $F, G\in \mathbf{K}(X)$,
$FG = GF,$
\item
pour tout $F\in \mathbf{K}(X)$,
$F\cdot 1 = 1\cdot F = F,$
\item
pour tout $F\in \mathbf{K}(X)$, si $F \ne 0$, alors
$FF^{-1} = F^{-1}F = 1,$
\item
pour tous $F, G, H\in \mathbf{K}(X)$,
$(F + G)H = FH + GH,\qquad F(G + H) = FG + FH.$
\end{enumerate}

Autrement dit, $\mathbf{K}(X)$ est un « corps commutatif ».

\subsection*{Degré d'une fraction rationnelle}

Pour toute fraction rationnelle $F = \frac{A}{B} \in \mathbf{K}(X)$, on
définit le \emph{degré\/} de $F$ par la formule :
$\deg F \stackrel{\text{déf}}{=} \deg A - \deg B.$
Comme $B \ne 0$ (donc $\deg B \in \mathbf{N}$), cette soustraction a un sens
même si $A = 0$, dans quel cas l'on trouve $\deg 0 = - \infty$.
Cependant, pour être certain que la définition a bien un sens,
il faut vérifier qu'elle ne dépend pas de l'écriture particulière
choisie pour $F$.
Supposons donc que $F = \frac{A_{1}}{B_{1}} = \frac{A_{2}}{B_{2}}$.
On a :
\begin{align*}
A_{1} B_{2} = A_{2} B_{1}
&\Rightarrow
\deg A_{1} + \deg B_{2} = \deg A_{2} + \deg B_{1} \\
&\Rightarrow
\deg A_{1} - \deg B_{1} = \deg A_{2} - \deg B_{2},
\end{align*}
car on peut soustraire $\deg B_{1} + \deg B_{2} \ne -\infty$.
Pour calculer $\deg F$, on peut donc indifféremment utiliser l'écriture
$F = \frac{A_1}{B_1}$ ou l'écriture
$F = \frac{A_2}{B_2}$.

\end{document}


Here is a Makefile to get at once with-polyglossia.pdf and with-babel.pdf:

# Makefile

.DELETE_ON_ERROR:

.PHONY: all
all: babel polyglossia

.PHONY: babel
babel: with-babel.pdf

.PHONY: polyglossia
polyglossia: with-polyglossia.pdf

with-babel.pdf: test.tex
latexmk -xelatex -jobname='with-babel' '$<' with-polyglossia.pdf: test.tex latexmk -xelatex -jobname='with-polyglossia' '$<'

.PHONY: mostlyclean
mostlyclean:
rm -f *.log *.synctex.gz

.PHONY: clean
clean: mostlyclean
rm -f *.aux *.out *.toc *.fdb_latexmk *.fls

.PHONY: distclean
distclean: clean
rm -f with-babel.pdf with-polyglossia.pdf

• Using ~: is wrong with either polyglossia or babel. Similarly for «~ and ~» – egreg Aug 16 '16 at 21:38
• You can use babel also with XeLaTeX. – egreg Aug 16 '16 at 21:45
• @egreg, i see your point: i can just ask about XeLaTeX then, without mentioning PDFLaTeX. – Alexey Aug 17 '16 at 12:37

I am not a French speaker, however, this is what I found out: It typesets with the space before : even if you type it in source without the space before :. So my suggestion is not to insert the spaces in source and then check that all the spaces around are in the rendered PDF, they appear to be there.

Also, maybe impnattypo might be of some interest to you.

UPDATE

If you abandon polyglossia and use babel even for XeLaTeX with relevant parts of preamble like the following and using guillemets and colons without preceding space, you will get almost the same result:

\ifxetex
\usepackage{fontspec}
\usepackage{lmodern}
\else
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\fi

\ifxetex
%\usepackage{polyglossia}
%\setdefaultlanguage{french}

\usepackage[frenchb]{babel}
\frenchbsetup{og=\«, fg=\»}

\else
\usepackage[frenchb]{babel}
\frenchbsetup{og=\«, fg=\»}
\fi


I am not sure if this is helping, for me, polyglossia is not babel and thus the results are different and there is nothing that can reasonably be done about it except maybe filling bug reports for one or the other.

UPDATE 2

So I have experimented with your second XeLaTeX only MWE. I think that the page breaking culprit is in the French babel package. From frenchb.pdf, p. 2, item 3:

vertical spacing in general LATEX lists is shortened

And indeed, if I change the setup, I get almost the same layout. In the MWE it results in the same page break.

\usepackage[french]{babel}
\frenchbsetup{og=\«, fg=\», ReduceListSpacing=false}


So I think that polyglossia does not have this reduced vertical spacing in lists for French and thus the page break is different.

• I do not see how this can resolve the difference in pagebreaks. I also find it strange to skip spaces in the source. – Alexey Aug 17 '16 at 12:51
• Thanks for the link to impnattypo package, i havn't heard of it. – Alexey Aug 17 '16 at 12:53
• @Alexey: Everything fits on one page for me, so no page breaks in the MWE. – wilx Aug 17 '16 at 13:12
• Strange, I have 1 and 2 pages. Can it be related to a different paper size (not A4) somewhere on your system? – Alexey Aug 17 '16 at 14:19
• I have updated my MWE to use only XeLaTeX. I still do not understand why different people get different output PDFs. – Alexey Aug 17 '16 at 18:42

Pour toute fraction rationnelle $F = \frac{A}{B} \in \mathbf{K}(X)$, on
définit le \emph{degré\/} de $F$ par la formule :


which babel french changes as I recall to essentially ~: at the end but apparently not with polyglossia so it linebreaks before the :

that makes the last section a line longer so it doesn't fit on the page.

Actually that's not the full story, changing the : to ~: makes the line breaking the same but page breaking is still differemt (of course, it's using different fonts and a different tex engine so nothing guarantees it being the same, but still....)

I'll leave this open in case it gives someone a start at a more complete analysis I'm out of time now.

• Did you really get different line breaks? I get the same linebreaks but different pagebreaks. – Alexey Aug 17 '16 at 12:29
• @Alexey: The renderings will always differ between individual LaTeX engines, IME. – wilx Aug 17 '16 at 12:58
• @Alexey yes if I run your file with xetex I get a linebreak before : as I say. – David Carlisle Aug 17 '16 at 13:04
• @wilx not usually so much the latex test suite compares box output of several hundred files and only very few we have to store separate base result for xetex and pdftex. (although in principle same breaks can not be guaranteed, different hyphenation is the usual cause but that isn't the case here) – David Carlisle Aug 17 '16 at 13:05
• Strange, apparently different people get different output from my file. I do not get line breaks before : and i get 1 page with PDFLaTeX and 2 pages with XeLaTeX. – Alexey Aug 17 '16 at 14:30