3

When compiling a beamer document using lualatex, I use fontspec package without problems. However, when setting up its encoding as in this MWE, I always get this error

Option clash for package fontspec

should I load fontspec without specifying the encoding, or is there something missing here?

\documentclass[lualatex]{beamer}
\usepackage{pgfpages,blindtext}
\usetheme{metropolis}

\usepackage[tuenc]{fontspec}

\begin{document}

\begin{frame}
    \blindtext
\end{frame}

\end{document}
0

2 Answers 2

6
\documentclass[lualatex]{beamer}
\usepackage{pgfpages,blindtext}
\usetheme{metropolis}
\begin{document}

    \begin{frame}
        \blindtext
    \end{frame}

\end{document}

should be ok. When running lualatex fontspec is already loaded with the tuenc definition file:

[...] (/usr/local/texlive/2017/texmf-dist/tex/latex/fontspec/fontspec-luatex.sty (/usr/local/texlive/2017/texmf-dist/tex/latex/base/fontenc.sty (/usr/local/texlive/2017/texmf-dist/tex/latex/base/tuenc.def)) (/usr/local/texlive/2017/texmf-dist/tex/latex/fontspec/fontspec.cfg)(load luc: [...]

3
  • Thanks for your explanation. I found a lot of answers loading fontspec with lualatex, so your answer implies that such a practice is useless.
    – Diaa
    Commented Apr 27, 2017 at 13:43
  • 1
    no, not in general! The style metropolis loads fontspec and fontspec itself uses by default tuenc.def.
    – user2478
    Commented Apr 27, 2017 at 13:52
  • Ohh I see. Many thanks for your consideration.
    – Diaa
    Commented Apr 27, 2017 at 13:58
3

Internally the metropolis theme does the following for xetex or luatex:

\@ifpackageloaded{fontspec}{
  \PassOptionsToPackage{no-math}{fontspec}
}{
  \RequirePackage[no-math]{fontspec}
}

To avoid this, one could use the moloch theme instead of metropolis. moloch is an updated fork of the metropolis theme which does not mess with font and thus allows you load the fontspec package in whatever way you like:

% !TeX TS-program = lualatex
\documentclass{beamer}
\usetheme{moloch}% modern fork of the metropolis theme

\usepackage[
%  whatever options you like
]{fontspec}

\begin{document}

\begin{frame}
  content
\end{frame}

\end{document}

In case you'd like to keep using the metropolis theme, update your tex distribution as there have been some changed to loading packages with options and the error no longer persists.


Old answer:

This means, just switching the order you load your packages (fontspec before metropolis) will remove the option-clash error. However, as pointed out by Ulrike Fischer in her comment, passing options to an already loaded package does not make much sense either. So you could:

\documentclass[lualatex]{beamer}
\usepackage{pgfpages,blindtext}

\PassOptionsToPackage{tuenc}{fontspec}
\usetheme{metropolis}

\begin{document}

\begin{frame}
    \blindtext
\end{frame}

\end{document}
7
  • You didn't try ... loading a package with two distinct option sets always give a clash, regardless of the order. Beside this: the code metropolis is senseless, you can't pass an option to a package that has already been loaded. Commented Apr 27, 2017 at 12:43
  • @UlrikeFischer I did try. If the package is already loaded, the branch \PassOptionsToPackage{no-math}{fontspec} of the if will be used. I did not test if this has any effect, but it won't create an option clash. Worst case, tuenc won't be passed to fontspec, but per Herberts answer, it seems to be used anyway. Commented Apr 27, 2017 at 12:44
  • Oh sorry, I had a local version in my path. But the code is senseless nevertheless ;-) Commented Apr 27, 2017 at 12:50
  • @UlrikeFischer I agree, just removing the line should have the same effect Commented Apr 27, 2017 at 12:53
  • 1
    @DiaaAbidou No idea Commented Apr 27, 2017 at 13:48

You must log in to answer this question.

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