4

I want to include a logo in the pdf pages included in Beamer.

I tried writing macro and progressed so far.

\documentclass[fleqn,xcolor=dvipsnames]{beamer}

\newlength{\logosize}
\setlength{\logosize}{7.50mm}

\newlength{\logoXinpdf}
\newlength{\logoYinpdf}
\setlength{\logoXinpdf}{0.9\textwidth}
\setlength{\logoYinpdf}{0.8\textheight}


\usepackage{pdfpages}

\def\getpdfpages#1#2{\begingroup
  \setbeamercolor{background canvas}{bg=}
  \includepdf[pages={#1},picturecommand={\put(\logoXinpdf,\logoYinpdf){\pgfimage[width=\logosize]{mylogo}}}]{#2}
  \endgroup}


\begin{document}


\getpdfpages{{9,12}}{mypdf.pdf}


\end{document}

However, when I run pdfLaTeX, I get an error in the line of,

! A <box> was supposed to be here.
<to be read again> 
                   \unitlength 
l.23 \getpdfpages{{9,12}}{mypdf.pdf}

I understand that the problem is with the \put command. If I replace the \logoXinpdf,\logoYinpdf lengths with absolute numbers, everything works fine.

Is there a way I can use these defined lengths with the \put command?

3
  • 1
    Your mistake here is that arguments of \put are in \unitlength units, not an usual length. Try to include fp package and compute coordinates by dividing your lengths by value of \unitlength. – Eddy_Em Feb 3 '13 at 7:50
  • Thanks, @Eddy_Em. Modifying the code in the following manner solved my problem, \makeatletter \FPdiv{\logoX}{\strip@pt\logoXinpdf}{\strip@pt\unitlength} \FPdiv{\logoY}{\strip@pt\logoYinpdf}{\strip@pt \unitlength} \makeatother \def\getpdfpages#1#2{\begingroup \setbeamercolor{background canvas}{bg=} \includepdf[pages={#1},picturecommand={\put(\logoX,\logoY){\pgfimage[width=\logosize]{buetlogo}}}]{#2} \endgroup} – Masroor Feb 3 '13 at 8:36
  • @MMA: If this solved your problem please post it as an self-answer (after the waiting period) and accept it in order to conclude the question. – Martin Scharrer Feb 3 '13 at 10:07
6

It's actually sufficient just to locally disable \unitlength (assuming this is a picture mode command internally.

\def\getpdfpages#1#2{\begingroup
  \setbeamercolor{background canvas}{bg=}
  \includepdf[pages={#1},picturecommand={{\def\unitlength{}\put(\logoXinpdf,\logoYinpdf){\pgfimage[width=\logosize]{mylogo}}}}]{#2}
  \endgroup}

\put expects a multiplier and does essentially

\setlength\something{#1\unitlength}
\setlength\somethingelse{#2\unitlength}

So if \unitlength is empty it is OK to pass lengths to put. Heiko's picture package takes this a bit further and adds some conditional logic so that you can use either a length or a multiplier, so that \unitlength becomes essentially a default unit. So it is probably enough just to load picture and make no change to your code.

2
  • Any chance LaTeX will be upgraded to have this as a setting or an option on {picture}? – Donald Arseneau Mar 14 '20 at 1:33
  • @DonaldArseneau not impossible, Heiko's package does something along these lines as I noted above. You could open a feature request at github.com/latex3/latex2e/issues so we don't forget until this post next pops up in another 7 years:-) – David Carlisle Mar 14 '20 at 8:30

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.