# Unable to change font using LuaLaTeX with usage of chemnum package

I can't seem to change the font in LuaLaTeX using chemnum as a package. I would like to use Calibri (not Times New Roman) as the case is now. Here is my code:

\documentclass[12pt]{report}
\usepackage[a4paper,width=150mm,top=25mm,bottom=25mm]{geometry}
\usepackage{fancyhdr}
\usepackage{achemso}
\usepackage{chemnum}
\usepackage{psfrag}
\usepackage[crop=off]{auto-pst-pdf}
\usepackage{graphicx}
\usepackage{wrapfig}

\begin{document}
\tableofcontents

\subsection{Here is an example}

\begin{wrapfigure}{l}{0.35\textwidth}
\vspace{-20pt} % removes 'white-space'
\begin{center}
\cmpdref{benzene} % replaces TMP1
\includegraphics{images/benzene.eps}
\end{center}
\vspace{-20pt}
\end{wrapfigure}

Add any text here and use \refcmpd{benzene} to refer to the compound. This way if you add a new figure in front of this one the numbering will automatically be changed. \\
Not totally sure if .eps is require or if only benzene would be sufficient.\\

Note: you need lualatex --shell-escape  -synctex=1 -interaction=nonstopmode %.tex in the configure texmaker for the lualatex.

\end{document}


• If you don't use the center environment but \centering instead you won't have to use the \vspaces anymore – clemens Oct 1 '14 at 21:12

You have to load package fontspec and to define the main font:

\documentclass[12pt]{report}
\usepackage{achemso}
\usepackage{chemnum}
\usepackage{fontspec}
\setmainfont{Calibri}
\begin{document}

Add any text here and use to refer to the compound. This way if you add a new figure
in front of this one the numbering will automatically be changed.

Not totally sure if .eps is require or if only benzene would be sufficient.
\end{document}


Herbet's answer is correct if you want to change the default font for the whole document. However, if it is just the labels produced by chemnum that you want to change then load fontspec and define a font for use and place its name in the format for the compound labels as follows:

\usepackage{fontspec}

\newfontface\chemnumface[Scale=MatchUppercase]{Calibri}
\setchemnum{format=\chemnumface}


However you also need this to work with psfrag and auto-pst-pdf. This requires some care switiching in and out of packages: the main file is run with lualatex which supports fontspec but the auto-pst-pdf runs with just latex which does not. You should load in the following order with ifluatex tests:

\usepackage{ifluatex}
\ifluatex
\usepackage{fontspec}
\newfontface\chemnumface[Scale=MatchUppercase]{Calibri}
\setchemnum{format=\chemnumface}
\else
\usepackage{psfrag}
\fi
\usepackage[crop=off]{auto-pst-pdf}


\documentclass[12pt]{report}

\usepackage[a4paper,width=150mm,top=25mm,bottom=25mm]{geometry}
\usepackage{fancyhdr}
\usepackage{achemso}
\usepackage{chemnum}
\usepackage{ifluatex}
\ifluatex
\usepackage{fontspec}
\newfontface\chemnumface[Scale=MatchUppercase]{Calibri}
\setchemnum{format=\chemnumface}
\else
\usepackage{psfrag}
\fi
\usepackage[crop=off]{auto-pst-pdf}
\usepackage{graphicx}
\usepackage{wrapfig}

\begin{document}

\begin{wrapfigure}{l}{0.35\textwidth}
\centering
\replacecmpd{benzene} % replaces TMP1
%\includegraphics{benzene.eps}
\end{wrapfigure}

Add any text here and use \refcmpd{benzene} to refer to the
compound. This way if you add a new figure in front of this one the
numbering will automatically be changed. Here is another compound
\cmpd{xx.one}

\end{document}


I don't have your benzene.eps file so have commented out that line.

• Let's start with only changing the font for the whole document. If I add \usepackage{fontspec} and \setmainfont{Calibri}. I get the following error:! Package pdftex.def Error: File sample-pics.pdf' not found. See the pdftex.def package documentation for explanation. Type H <return> for immediate help. ... l.28 \includegraphics{images/benzene.eps} Using draft setting for this image. Try typing <return> to proceed. If that doesn't work, type X <return> to quit. LaTeX Font Info: Try loading font information for EU2+lmtt on input line 28. – Evi Oct 2 '14 at 8:27
• This sounds like a problem loading the graphics and should be unrelated to loading fontspec - I presume you are running lualatex as your source indicated. The graphics concerned is images/benzene.eps, which I commented out of my code as I don't have a copy. – Andrew Swann Oct 2 '14 at 11:18
• Yes I am running lualatex as source indicated. I added a png picture of the file (couldn't add an eps file), please convert to a eps yourself. – Evi Oct 2 '14 at 12:10
• @Evi A PNG picture is useless. The text in the original EPS is lost in the PNG hence a newly converted EPS won't contain a text string! This means psfrag (and thus chemnum`) won't find any text marker to replace... => the original EPS is needed – clemens Oct 2 '14 at 14:23
• I know it's me but how can I add an eps file to a question or comment? If I want to add a picture I can only add jpeg, png, tiff, gif or bmp files, no eps. Am unable to find it on the site to add an eps file to a question. So if anyone knows please let me know. – Evi Oct 2 '14 at 18:25