7

I got a weird problem with the fontspec package and the graphicx package. Let's see the MWE first.

%!TEX program = xelatex
\documentclass{article}
\usepackage{graphicx}
\usepackage{fontspec}
\setmainfont{Times New Roman}
\newfontfamily\test[AutoFakeBold = 5]{Times New Roman}
\begin{document}
\test
Test
\textbf{Bold Test}

\includegraphics[scale = 0.1]{photo}

Words that shouldn't be bolded. Even if \textmd{textmd-ed}.
\end{document}

In the preamble, I loaded the graphicx package and the fontspec package, then I set Times New Roman as the default font of the text as well as the font of the test command. In the definition of \test, I enabled AutoFakeBold. In the document body, between the two chains of text, I inserted a photo with the \includegraphics command.

It's a normal manuscript, except that AutoFakeBold was set to 5 to make the abnormal output more remarkable. After the compilation, however, the later line of text presented an unexpected output. That is, this line of text shouldn't be bolded.

Even more surprising is that, if one

  • cancel the option passed to \includegraphics,
  • or put some more text after \textbf{},

the problem will go away.

I suspect the problem lies in the FakeBold mechanism of the fontspec package and/or the key-val mechanism of the graphicx package, but unfortunately, I don't read LaTeX3 codes, so I cannot locate it.

Maybe an issue should be posted to fontspec or graphicx, but before that, could someone provide me a quick fix to this problem?


EDIT 2015/01/05

Thanks to the help of qingkuan@bbs.ctex.org, it seems to be a bug of XeTeX. See the new MWE.

% !TeX program = xetex

\font\x="[cmunrm.otf]"
\font\bx="[cmunrm.otf]:embolden=5;"

\x Test
{\bx Bold Test}
\XeTeXpicfile "example-image.png"  width 1cm\relax
Words that shouldn't be bolded.


\tracingoutput=1
\showboxbreadth=\maxdimen
\showboxdepth=\maxdimen

\bye

I made a ticket on xetex.sf and hope this will be fixed soon.

2

Nice test file, a workaround is to put some text after the bold text, even invisible text such as a zero width space seems to be enough:

enter image description here

\documentclass{article}
\usepackage{graphicx}
\usepackage{fontspec}
\setmainfont{Times New Roman}
\newfontfamily\test[AutoFakeBold = 5]{Times New Roman}
\begin{document}
\test
Test
\textbf{Bold Test}

\includegraphics[scale = 0.1]{photo}

Words that shouldn't be bolded. Even if \textmd{textmd-ed}.

\textbf{Bold Test}^^^^200b

\includegraphics[scale = 0.1]{photo}

Words that shouldn't be bolded. Even if \textmd{textmd-ed}.
\end{document}
  • This is an answer or only pointing that there is something wrong? – wipet Jan 3 '15 at 11:16
  • @wipet it depends how soon the OP wants their document. It is certainly not the correct fix, but if someone needs the document today it may be the answer. I tried looking with \tracingall at the two versions and couldn't see any difference (although the printed output is clearly different, so I don't offer a real fix. – David Carlisle Jan 3 '15 at 11:39
  • @DavidCarlisle Thanks! Yes indeed this workaround works fine, but as I posted in the question, I did know that some text after \textbf{} kicks the problem away, for example \textcolor{white}{.}. Anyway, ^^^^200b is better. Actually, I'd uploaded my manuscript to the publisher (before your answer), so I could wait for a real fix. Thank you for this answer, and for your year after year effort on this site. : ) – Ch'en Meng Jan 3 '15 at 12:04
  • Hi David, please see my update. – Ch'en Meng Jan 5 '15 at 16:45

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.