[XeTeX] Default values of \pdfpage{width, height}

Ross Moore ross at ics.mq.edu.au
Fri Aug 3 06:19:10 CEST 2007


Hi Andreas, and Jonathan,

On 03/08/2007, at 10:42 AM, Andreas Matthias wrote:

> Jonathan Kew wrote:
>
>>> Andreas Matthias wrote:
>>>>
>>>> \documentclass{article}
>>>> %\pdfpagewidth=\paperwidth
>>>> %\pdfpageheight=\paperheight
>>>> \begin{document}
>>>> aaa
>>>> \newpage
>>>> \begingroup
>>>> \pdfpagewidth=80mm
>>>> \pdfpageheight=150mm
>>>> bbb
>>>> \newpage
>>>> \endgroup
>>>> ccc
>>>> \end{document}
>
>> What happens in your example is that if the parameters are initially
>> unset, you get the driver's default paper size. Then you set them
>> within a group, and xetex writes a papersize \special at the
>> beginning of the second page.
>
> Agreed.
>
>> Then you end the group, and the
>> parameters become unset.... so no further \specials are written, and
>> the setting from within the group persists beyond where you'd expect.
>
> The local settings within the group persist beyond the group. Hmm...
> I didn't want to say it, but I would call this a bug. Anyway, does this
> `feature' have any advantage? Or is it used by anyone? If not I think
> it wouldn't hurt to change this behaviour.

But the \pdfpagewidth  and  \pdfpageheight
are not parameters that are meant to be changed willy-nilly
throughout a document.
You set them once, in the preamble if not the initialisation,
and leave them like that.

Changing within the middle of a document is quite incompatible
with the asynchronous way that TeX processes a document and
builds pages for shipping out.
It can read as much as 1 or 2 pages ahead before deciding when
a page is complete. Under these circumstances you cannot
easily control what will be the page-size settings for each page.


Of course TeX is actually much smarter than that, allowing you
to have such control, by various methods.

One such is to reprogram the  \output  routine; but then you are
going beyond anything that is described in LaTeX documentation.

Another way, that is quite easy, and which certainly works with pdfTeX ,
is to use the \shipout  primitive directly --- alternatively, within 
your own
private macros.

The principle is that *any* \vbox can be shipped-out, at any time.
This allows you to build pages of different sizes within the same
PDF document. Essentially you just build your contents within
an (outer) \vbox{....} at the \hsize and \vsize that you want.
Or you build it within an (inner) \vbox that inherits its size from
the contents itself; then measure the box for this size.

You then set the  \pdfpagewidth  and \pdfpageheight locally
within a grouping,  and set \hoffset=0pt  \voffset=0pt ,
then use   \immediate\shipout  to actually place the page contents
directly into the PDF file being built.
On exiting the group the  \pdfpage...  settings revert to what you
want for the rest of the job, and the special page has been fully
processed and output.

If you want headers and footers (with the correct page-numbering)
then you have to handle this yourself for such special pages.


With XeTeX there are no   \pdfpagewidth  and \pdfpageheight
primitives, but by inserting a  \special{papersize= .... } at the
top of the  \vbox  that is actually shipped-out, the same effect
should be achieved.

It may be that there is a problem in that the effect of this  \special
is unscoped, so affects all subsequent pages too,.
One way to avoid this is to have another  \special{papersize=<default>}
inserted after each special page has been output.

Jonathan, would this migrate to the top of the next page that is output
normally, or is a separate hook required for this?


>
>> So another option might be to
>> write a "papersize=default" \special instead if the \pdfpage
>> {width,height} parameters are unset; the driver would then revert to
>> its default media size (from a config-file or command-line).
>
> That should be sufficient. I agree with that.

Where does this  \special  need to occur within the output, for it
to have the correct effect with the back-end driver programs:
   xdv2pdf    and   xdvipdfmx  ?
Does it have to be at the top of the page, or is anywhere sufficient ?


> Ciao
> Andreas


Hope this helps,

	Ross



More information about the XeTeX mailing list