Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

BoundingBox of a LaTeX page?

275 views
Skip to first unread message

Ryo

unread,
May 13, 2012, 7:45:57 AM5/13/12
to
Hi all,

I'm puzzled why tools like ps2eps and ps2epsi cannot compute the
bounding box of a latex page.

$ cat tmp.tex
\documentclass{article}
\pagestyle{empty}
\begin{document}
hello
\end{document}
$ latex tmp.tex
$ dvips tmp
$ ps2epsi tmp.ps

The LaTeX page contains only the letters "hello", but ps2epsi cannot
find the bounding box that surrounds the letters. The one it sets is
a lot larger.

I thought ps2epsi and friends render the page on ghostview at a high
resolution and determine the bounding box by looking at the pixels.
As far as I can see on the screen, there is no object other than the
letters in the PostScript output dvips generates. What is ps2epsi
seeing?

Regards,
Ryo

Marc van Dongen

unread,
May 13, 2012, 9:03:33 AM5/13/12
to
It's probably because latex sets the bounding box to the bounding box of the page dimension, not what's in the page.

$ pdflatex tmp.tex > /dev/null
$ pdfinfo tmp.pdf
Creator: TeX
Producer: pdfTeX-1.40.12
CreationDate: Sun May 13 13:56:35 2012
ModDate: Sun May 13 13:56:35 2012
Tagged: no
Pages: 1
Encrypted: no
Page size: 595.276 x 841.89 pts (A4) <---------------
File size: 10094 bytes
Optimized: no
PDF version: 1.5

If you really want to get an external picture file that only contains small sub-pictures, you could use the tikz package. (There must be other ways to do this but this is the only one I know.)

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{external}
\tikzexternalize{tmp}
\begin{document}
\begin{tikzpicture}
\node{hello};
\end{tikzpicture}
\end{document}

$ pdflatex -shell-escape tmp.tex > /dev/null

530 hermitage ~
$ pdfinfo tmp-figure0.pdf
Creator: TeX
Producer: pdfTeX-1.40.12
CreationDate: Sun May 13 14:02:07 2012
ModDate: Sun May 13 14:02:07 2012
Tagged: no
Pages: 1
Encrypted: no
Page size: 27.12 x 13.56 pts <----------------
File size: 10263 bytes
Optimized: no
PDF version: 1.5

Regards,


Marc van Dongen

Ryo

unread,
May 13, 2012, 10:44:23 PM5/13/12
to
On May 13, 3:03 am, Marc van Dongen <don...@cs.ucc.ie> wrote:
> On Sunday, May 13, 2012 12:45:57 PM UTC+1, Ryo wrote:
[. . .]
> > I'm puzzled why tools like ps2eps and ps2epsi cannot compute the
> > bounding box of a latex page.
[ . . .]
> > I thought ps2epsi and friends render the page on ghostview at a high
> > resolution and determine the bounding box by looking at the pixels.
> > As far as I can see on the screen, there is no object other than the
> > letters in the PostScript output dvips generates.  What is ps2epsi
> > seeing?
[. . .]
> It's probably because latex sets the bounding
> box to the bounding box of the page dimension,
> not what's in the page.

You are right! Thanks for correcting me.

It turns out that the problem is the BoundingBox setting in the
PostScript file generated by dvips. The boundingbox-calculating tools
I use were simply honoring the original boundingbox. Ugh.

I've found that ps2eps (http://tm.uka.de/~bless/ps2eps) has an option
to ignore the original boundingbox (--ignoreBB).

However, the PostScript file from dvips still has the setting "%
%DocumentPaperSizes: a4", which still confuses the PostScript viewer I
use. So, having identified the problems, I've decided to filter the
offending lines out using "sed":

sed '/^%%BoundingBox:\|^%%DocumentPaperSizes:/d' myfile.ps >
myfile2.ps
ps2eps myfile2.ps

Cheers,
Ryo

Peter Flynn

unread,
May 15, 2012, 6:03:38 PM5/15/12
to
On 13/05/12 12:45, Ryo wrote:
> Hi all,
>
> I'm puzzled why tools like ps2eps and ps2epsi cannot compute the
> bounding box of a latex page.
>
> $ cat tmp.tex
> \documentclass{article}
> \pagestyle{empty}
> \begin{document}
> hello
> \end{document}
> $ latex tmp.tex
> $ dvips tmp

dvips -E will try to create a tight bounding box (EPS). Without it, you
get the BB of the page, not the text on it.

///Peter
0 new messages