[Tex/LaTex] LuaLaTeX: option clash for package graphicx when loaded after fontspec

fontspecgraphicsluatex

I don't know if it is stated in any documentation somewhere, but I can't figure out why I can't compile this MWE when \usepackage[draft]{graphicx}is loaded after \usepackage{fontspec}

\RequirePackage{luatex85}
\documentclass{article}

\usepackage{fontspec}
\usepackage[draft]{graphicx}

\begin{document}
    Text
\end{document}

with error

Option clash for package graphicx

However, loading \usepackage[draft]{graphicx} before \usepackage{fontspec} makes the compilation go smooth as in

\RequirePackage{luatex85}
\documentclass{article}

\usepackage[draft]{graphicx}
\usepackage{fontspec}

\begin{document}
    Text
\end{document}

Best Answer

Package fontspec loads fontspec-luatex.sty, if used with LuaTeX. Then package xunicode is loaded that loads package graphicx without options.

The LaTeX reaches \usepackage[draft]{graphicx}. The package is already loaded. Therefore, LaTeX only checks the options. If there is any new option (here: draft) it throws the error message.

Solutions:

  • Load package graphicx with all needed options before \usepackage{fontspec} as in the question.

  • \PassOptionsToPackage{draft}{graphicx} before \usepackage{fontspec}.