TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've run into a problem when converting a book manuscript from LaTeX to XeLaTeX. The problem is that my image sizing and placement has not survived the conversion.

The book has numerous picture inclusions where the source is a .png file. While .png has much to recommend itself, it does not include bounding box information in the file itself. So I use a script to cache the bounding box information in a separate file which I then use to set the bounding box of the image. In my document, I prepare the way with:


I created the .bb files with a Q&D (Quick and Dirty) perl script.

With LaTeX, all was now well. Images were of the correct size and correctly placed on each page. Then I switched to XeLaTeX only to have my carefully crafted scheme join the aft gang aglay crowd!

What's going wrong? The bounding boxes are the same and yet the images are no longer placed correctly in my document?

share|improve this question
Contributions such as this are more than welcome, but I think it would work better if phrased as a question and an answer. Since this is a Q&A site, people expect posts to have a certain format. It would also make it clearer to a casual reader what circumstances your script is useful for. – Loop Space Jan 23 '13 at 10:11
@AndrewStacey Excellent point---one that I was unsure of since this is my first attempt at this form. You are correct but perhaps the posting with your comment will also be useful to those who 'drop by'...(will phrase the next such offering accordingly---thank you!) – hsmyers Jan 23 '13 at 11:07
@tohecz Edit looks good! thanks... – hsmyers Jan 23 '13 at 11:08
My comment isn't really enough -- comments aren't always read and can change order (or even not be immediately displayed). So it really would be better if you rephrased this one as a question and an answer. – Loop Space Jan 23 '13 at 11:31
ALL---I bow to group dynamics (I'd say peer presure, but you are all master craftsmen to my lowly apprentice so hardly peer :) ) and have split the post to question and answer. As usual I have no problem with anyone who wishes to improve or tidy---edit away! – hsmyers Jan 23 '13 at 13:29

The solution to my problem of bad sizing on the images when I switched to XeLaTeX was solved when I discovered the difference in dpi one to another. The original version of this script did not allow for 72 versus 96---it does now and I offer it to others in the hope that it might be of use. This is a sort of Thank You! to the community. Please use and enjoy! For those who worry about IP and permissions, this is released into the wild without restriction or warrenty---free as in free beer.

# box2bb.pl -- create image.type.bb files for LaTeX
# if xelatex is first option on command line, changes to 72dpi from 96dpi
use strict;
use warnings;
use diagnostics;
use Image::Magick;
use POSIX qw(ceil);

our $VERSION = '0.03';

my $option = shift @ARGV;

if ($option ne 'xelatex') {
for (map { glob } @ARGV) {
    my $h;
    my $w;
    my $p = new Image::Magick;
    my $fh;

    ($w,$h) = $p->Get('width','height');
    $w = convertPX2PT($w);
    $h = convertPX2PT($h);
    print $fh "\%\%BoundingBox: 0 0 $w $h\n";

sub convertPX2PT {
    if ($option eq 'xelatex') {
        return ceil(((shift) / 72.0) * 72.27);
    else {
        return ceil(((shift) / 96.0) * 72.27);
share|improve this answer
Bitmap images can have different resolutions (if the resolution is provided at all). pdfTeX respects them, in case of XeTeX, the script that generates the Bounding Box files should respect them. In case of dvipdfm(x), package bmpsize helps. – Heiko Oberdiek Jan 23 '13 at 14:58

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.