6

I use extensively pinlabel package in my project, which I compile with LuaLaTeX. After recent MiKTeX 2.9 upgrade, I cannot compile the project any more, getting numerous errors like

! Undefined control sequence. <argument> \pdfximagebbox 
               \pdflastximage 1 
l.19    \includegraphics[width=5cm]{pdf_figure}

and

! Undefined control sequence. 
 <argument> \pdfximagebbox 
               \pdflastximage 2 l.19    \includegraphics[width=5cm]{pdf_figure}

After analysing the log files and reading similar error reports here on TSE, I think the problem might be caused by LuaTeX 0.95 and the following lines in pinlabel, determining the bounding box of a pdf image:

%  Next five lines of code supplied by Mark Petelier
%  
%  Read BB from pdf file:
%
         \pdfximage cropbox {\@filestem.pdf}
         \@p@@sbbllx{\pdfximagebbox\pdflastximage 1}
         \@p@@sbblly{\pdfximagebbox\pdflastximage 2}
         \@p@@sbburx{\pdfximagebbox\pdflastximage 3}
         \@p@@sbbury{\pdfximagebbox\pdflastximage 4}

The LuaTeX manual suggests I should use external applications or img library to replace \pdfximagebbox command, however, my knowledge of (Lua)TeX is not enough to implement it. Thus my question is: what's the best way to get pinlabel work with LuaTeX 0.95?

MWE:

% !TeX TXS-program:compile = txs:///lualatex/
\documentclass[11pt,twoside,a4paper]{article}
% the following package seems to be necessary to enable use of pdf images with pinlabel after upgrade to luatex 0.95 
\usepackage{luatex85}
\usepackage{pinlabel}
\usepackage{graphicx}

\begin{document}
    Math in graphics: \\
    \labellist    
    \pinlabel $X$ at 200 200
    \endlabellist
%   Two cases, uncomment one of them
%
%   MWE compiles well with the following line; the BB information is taken from the corresponding example-image.eps file, I guess
%   \includegraphics[width=5cm]{example-image}
%
%   MWE does not compile with lualatex 0.95 if using any pdf file without corresponding eps file. The examle compiles well usin pdftex.
    \includegraphics[width=5cm]{pdf_figure}
\end{document}
  • 1
    From the LuaTeX manual: “The introspective primitives \pdflastximagecolordepth and \pdfximagebbox have been removed. One can use external applications to determine these properties or use the built-in img library.” As usual, there is no example whatsoever. :( – egreg May 30 '16 at 9:24
  • @egreg I think it's a question of doing a = img.new({filename='foo.pdf'}) then a.bbox and a.colordepth – Joseph Wright May 30 '16 at 15:11
  • @JosephWright or here I think you can just scan for height and depth, see below – David Carlisle May 31 '16 at 8:44
5

I think you can patch the code to use the lua image library like so:

enter image description here

\documentclass[11pt,twoside,a4paper]{article}
% the following package seems to be necessary to enable use of pdf images with pinlabel after upgrade to luatex 0.95 
\usepackage{luatex85}
\usepackage{pinlabel}
\usepackage{graphicx}

\makeatletter
\def\foo#1\pdfximage#2\no@bbfalse#3\foo{%
\def\scan@header{#1%
         \directlua{a = img.scan { filename = "\@filestem.pdf"}
tex.print(\the\catcodetable@atletter,
"\string\\@p@@sbburx{" .. a.width .. "sp}\string\\@p@@sbbury{" .. a.height .. "sp}")
}%
         \@p@@sbbllx{\z@}%
         \@p@@sbblly{\z@}%
        %
\no@bbfalse#3}}%
\expandafter\foo\scan@header\foo
\makeatother

\begin{document}
    Math in graphics: \\
    \labellist    
    \pinlabel $X$ at 200 200
    \endlabellist
%   Two cases, uncomment one of them
%
%   MWE compiles well with the following line; the BB information is taken from the corresponding example-image.eps file, I guess
%   \includegraphics[width=5cm]{example-image}
%
%   MWE does not compile with lualatex 0.95 if using any pdf file without corresponding eps file. The examle compiles well usin pdftex.
    \includegraphics[width=5cm]{pdf_figure}
\end{document}

perhaps could use bbox instead of height +depth, but for pdf file inclusion I think llx and lly will always be 0 anyway.

  • Thanks a lot, this works perfectly! I have a question -- why the patch here is not ended by \makeatother as usual? Moreover, MWE doesn't compile if I add this command. – Oleg Soloviev May 31 '16 at 8:55
  • @OlegSoloviev try now: I forced the tex.print to use the correct catcodes even when @ is set back to normal. – David Carlisle May 31 '16 at 9:00
  • Thanks again; I've just checked it not only with MWE, but with my 200 pages project; with addition of pgfsys-luatex.def I can now work even after updating to LuaTeX 0.95 :-) – Oleg Soloviev May 31 '16 at 9:29

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.