I'm trying to include images and overlay them with their width and height info in mm. I save the image to a box and then use the calculator package to calculate the mm width and height of that box. Then I use a picture environment to place the image and, on top of it, a fcolorbox with the measurements.

What happens is that I get additional spacing before the picture environment, but only when using the commands from the calculator package. Is there a bug or am I doing something wrong?

Here's my example, with a \rule as a dummy for the image; page 1 with calculated measurements, page 2 with measurements entered manually:

    \savebox{\tmpboxa}{\rule{\textwidth}{50mm}}% This is where the image will be includegraphicsed
    \begin{picture}(\breite mm, \hoehe mm)%
        \put(1mm,1mm){\makebox(0,0)[bl]{\fcolorbox{black}{black!15}{\strut \Breite\,mm $\times$ \Hoehe\,mm}}}%
    \begin{picture}(\textwidth, 50mm)%
        \put(1mm,1mm){\makebox(0,0)[bl]{\fcolorbox{black}{black!15}{\strut 121.25\,mm $\times$ 50\,mm}}}%

If you do

    \savebox{\tmpboxa}{\rule{\textwidth}{50mm}}% This is where the image will be includegraphicsed

you'll see

> \box0=
.\glue 3.33333 plus 1.66666 minus 1.11111
.\glue 3.33333 plus 1.66666 minus 1.11111

so as you suspected these commands are adding two spaces (probably missing % at ends of lines in its code). If you want to use them a simple workaround would be to move the \noindent to just before \begin{picture} so that the calculations happen in vertical mode where spaces are ignored.

The package is clearly not expecting calculations in horizontal mode, it would need dozens of % and \relax adding to protect against white space, but in this case you can just fix \LENGTHDIVIDE and the two spaces go:

Add this after loading the package.

  • I'll want the whole stuff inside a macro that will kind of replace `\includegraphics', and it will sometimes be called from within a wrapfigure environment. Guess I'll have to look for a different package to do the calculations with. – Blackface Oct 28 '14 at 10:31
  • 1
    @Blackface updated with a fix (for this one command) It may be worth contacting the package maintainer – David Carlisle Oct 28 '14 at 10:50
  • @DavidCarlisle Most of the \UPPERCASE commands in calculator have \ignorespaces at their end; the author forgot to mask several end-of-lines where those commands aren't used. Also the \@UPPERCASE command were forgotten, so fixing the package is quite a mess. – egreg Oct 28 '14 at 11:27
  • Pity. @David's patch works fine for me and for now, but for the future: Is there a less messy alternative? Preferably documented, unlike fp? BTW, I also wrote a mail to the author. – Blackface Oct 28 '14 at 14:35
  • Thank you, Blackface and David. I will try to find the parts of the package where unwanted spaces appears. – Robert Fuster Oct 30 '14 at 8:09

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.