5

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} 

\linespread{1.3}%1.5 line spacing

\begin{document}
\tableofcontents

\chapter{This is your chapter title}

\section{This is your section title}

\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}

benzen, it is a png picture, please convert to eps

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

2 Answers2

4

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}
4

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}

Sample output

\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} 


\linespread{1.3}%1.5 line spacing

\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.

Andrew Swann
  • 95,762
  • 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 for immediate help. ... l.28 \includegraphics{images/benzene.eps} Using draft setting for this image. Try typing to proceed. If that doesn't work, type X to quit. LaTeX Font Info: Try loading font information for EU2+lmtt on input line 28. – Evi Oct 02 '14 at 08: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 02 '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 02 '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 – cgnieder Oct 02 '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 02 '14 at 18:25
  • @Evi I now understand the problem. I have updated the answer, but don't have an eps file I can test it on. Please let me know whether it works. – Andrew Swann Oct 02 '14 at 18:32
  • @AndrewSwann I don't understand the reasoning behind the \ifluatex switch: chemnum loads psfrag either way (it contains \RequirePackage{psfrag}...) – cgnieder Oct 02 '14 at 23:10
  • Thanks Andrew Swann, this does work for the numbering in the text. However, the rest of the text in the document is still Times New Roman. Do you have any idea how to change that to Calibri as well? – Evi Oct 03 '14 at 08:59
  • @Evi I think we are running in to http://tex.stackexchange.com/q/99724/15925 . The best you can do is choose a standard tex font that pdflatex knows how to load for the label in the figure. – Andrew Swann Oct 03 '14 at 09:13
  • @Evi I believe the problem is as follows: the tag replacement is done during the auxiliary compilation (through auto-pst-pdf) with pdftex. During this compilation the Calibri font is unknown so the default font is used (which can't be Times New Roman BTW but with the current setup must be Computer Modern Sans. If yours has Times New Roman then your MWE is not complete!). I don't think there's a way around this, unfortunately... – cgnieder Oct 03 '14 at 12:04
  • @AndrewSwann you can use the .ps files from chemnum's manual for testing (http://www.ctan.org/tex-archive/macros/latex/contrib/chemnum) – cgnieder Oct 03 '14 at 12:06
  • I tried to test the chemnum's manual from ctan.org/tex-archive/macros/latex/contrib/chemnum but I get the following error: ! LaTeX Error: File `libertinehologopatch.sty' not found. It also says it an error in line 200, there the libertinehologopatch.sty can't be found. Further there's an error in line one: no output PDF file produced but that could be due to the error of the libertinehologopatch.sty. – Evi Oct 03 '14 at 14:48
  • @Evi that means that you tried to compile chemnum's complete manual, right? Why do you want to do that? (BTW: https://bitbucket.org/cgnieder/libertinehologopatch) – cgnieder Oct 06 '14 at 07:32