I have a .pdf figure generated by R/ggplot2, which renders correctly when viewed as a standalone file, but when embedded in a document by pdftex, one character is missing. I've cut the problem down to this R script...

cairo_pdf("arghfig.pdf", width=2, height=0.5)
grid.text(label = "Bias (\U01d712\u00b2 odds ratio)") # 𝜒²

plus this wrapper LaTeX file:


The actual PDFs produced by this are available from https://hacks.owlfolio.org/scratchpad/font-inclusion-bug-2016-03-18/. (For your convenience, the -q variants of the PDFs have been internally decompressed using QPDF.) Here's what the standalone file looks like...

correctly rendered standalone file; text reads "Bias (𝜒² odds ratio)"

and here's what happens to it when passed through pdflatex...

incorrectly rendered full document; text reads "Bias (𝜒  odds ratio)", with a blank space where a superscript 2 should be

\pdfinclusioncopyfonts=1 is a workaround, but I have a lot of text-heavy figures in this document and it doesn't appear that one can activate this mode for just one figure, so I'd prefer not to have to do that. Also I would like to understand why only the superscript 2 is affected, when it's my understanding that \pdfinclusioncopyfonts problems should affect all characters that aren't used in the surrounding document's text, and this wrapper document has no text.

Useful answers to this question would include any or all of:

  • an explanation of exactly what has gone wrong here
  • an informed opinion as to whether this is a bug in R core, grid, cairo, pdftex, or what
  • suggested workarounds in the R script (note: grid is mandatory, because ggplot2, and plotmath is forbidden unless you know a way to do multi-line plotmath captions with sensible amounts of line-spacing, i.e. not atop())
  • suggested workarounds in pdftex other than \pdfinclusioncopyfonts=1 (note: luatex is not an option, because egregious and unmodifiable journal style file).
  • suggested workarounds via hand-hacking the PDF figure (not kidding! I have to do that anyway)

Note that there are two embedded fonts in both documents...

$ pdffonts arghfig.pdf
name                            type          encoding     emb sub uni object ID
------------------------------- ------------- ------------ --- --- --- ---------
HLICDJ+TeXGyreHeros-Regular     Type 1C       WinAnsi      yes yes yes      5  0
JMSOLB+FreeSerif                CID Type 0C   Identity-H   yes yes yes      6  0

$ pdffonts argh.pdf
name                            type          encoding     emb sub uni object ID
------------------------------- ------------- ------------ --- --- --- ---------
ZJEQCD+TeXGyreHeros-Regular     Type 1        Custom       yes yes yes     11  0
JMSOLB+FreeSerif                CID Type 0C   Identity-H   yes yes yes     12  0

... but the superscript 2 is coming from the Type 1(C) font, not the wacky "CID Type 0C" thing. That font only provides the 𝜒 character.


When you compile your example you can see in the log that it loads a font. In my case this one:


The font is obviously not for some text in the document (which would use a cm-font anyway), but for the text in the graphic.

It should be clear that a font on my PC is not identical with the font used when you created your graphic. pdflatex is guessing that the fonts fits -- and is almost right, with the exception of the superscript – which is not really surprising as normal chars like A-Z are seldom a problem, but the encoding of special chars like ² can differ a lot – WinAnsi is not an encoding tex would produce.

\pdfinclusioncopyfonts=1 forces pdflatex to use the font in graphic instead of searching a replacement, imho this is the right thing to do if you can't change the way the graphic embeds and uses the font.

The only alternative I can think of is to find the font the graphic used and to try to force pdftex to load this (but if you want to use heros in the text too, this could have side-effects).

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.