6

I wanted to use the exercise package in a LaTeX-document that is processed with LuaLaTeX. In this case, I encountered the problem that numbering and formatting of questions does not work correctly.

How can I use both package, i.e. how do I debug and fix such an incompatibility?

I reduced this problem to a MWE which is as follows:

\documentclass{book}

\usepackage{amsmath}
\usepackage[lastexercise,answerdelayed]{exercise}
\usepackage{polyglossia}
\setmainlanguage{english}
\usepackage{unicode-math}% Incompatible with exercise package
\usepackage{fontspec}% I want to select a different font

\setmainfont{Linux Libertine O}
\setmathfont{Tex Gyre Pagella Math}% this requires unicode-math

\begin{document}

\chapter{List of problems}
\begin{ExerciseList}
    \Exercise Prove Bernoulli's inequality
    \[
        (1+x)^n \geq 1+nx, \text{ for } x\geq -1 \text{ and } n\geq 0.
    \]
    \Exercise Find out if the following equations are true.
        \Question $(1 + 5)^2 \geq 11$
        \Question $1 < 5$
        \Question $1 > 5$
\end{ExerciseList}

\end{document}

Processing this with lualatex (or xelatex -- both using the -8bit option) yields a document where the questions are not numbered correctly.

Omitting the \usepackage{unicode-math} and the \setmathfont{...} (which requires unicode-math), then the output is as expected.

1
5

The unicode-math package defines \Question as a math symbol, precisely U+2047 DOUBLE QUESTION MARK, that is, ⁇.

\documentclass{book}

\usepackage{amsmath}
\usepackage[lastexercise,answerdelayed]{exercise}
\usepackage{polyglossia}
\usepackage{unicode-math}

\setmainlanguage{english}

\setmainfont{TeX Gyre Pagella}
\setmathfont{TeX Gyre Pagella Math}% this requires unicode-math

\let\exerciseQuestion\Question
\AtBeginDocument{%
  \let\mathQuestion\Question
  \let\Question\exerciseQuestion
}

\begin{document}

\chapter{List of problems}
\begin{ExerciseList}
    \Exercise Prove Bernoulli's inequality
    \[
        (1+x)^n \geq 1+nx, \text{ for } x\geq -1 \text{ and } n\geq 0.
    \]
    \Exercise Find out if the following equations are true.
        \Question $(1 + 5)^2 \geq 11$
        \Question $1 < 5$
        \Question $1 > 5$
\end{ExerciseList}

\end{document}

enter image description here

1
  • Thanks a lot for this solution, it works fine. Actually, I already had the suspicion that the \Question caused the conflict, but I was not sure and more particularly, I did not understand how to solve this. Is your proposal a typical "idiom" for resolving a name clash of two packages? – King Thrushbeard Jul 5 '17 at 14:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.