[XeTeX] papersize special and memoir (and other?) documentclasses

Jonathan Kew jonathan_kew at sil.org
Wed May 24 09:52:22 CEST 2006

On 23 May 2006, at 11:55 pm, Jonathan Kew wrote:

> On 23 May 2006, at 2:02 pm, William Adams wrote:
>> On May 22, 2006, at 4:45 PM, Jonathan Kew wrote:
>>> I haven't looked at memoir in particular, but I'm fairly confident
>>> that this means the class is doing something to generate output
>>> before the \special from \AtBeginDvi. This can happen if the class
>>> modifies the \output routine, for example, and wraps something  
>>> around
>>> the normal output (to which \AtBeginDvi gets prefixed). There was a
>>> similar problem with crop.sty, IIRC, and some discussion of a patch/
>>> workaround... try the list archives. That might point you towards a
>>> solution for memoir.
>> I dunno.
>> The following file %!TEX encoding = UTF-8 Unicode
>> \documentclass[dvips, showtrims]{memoir}
>> .....
>> \renewcommand*{\trimmarks}{\special{papersize=\the\stockwidth, \the
>> \stockheight}{%
>> .....
>> works on the first page when generated w/ latex at the command line
>> and checked out with dvitype (starts with 87: xxx
>> 'papersize=650.43pt, 849.17249pt' ).
>> But it comes out with two different page sizes when I switch to
>> processing it with xelatex.

Here's a bit more about this issue. When you ask memoir.cls to  
"showtrims", it intercepts the box that LaTeX would normally  
\shipout, and wraps its trim marks around it. But \AtBeginDvi, used  
to put the papersize \special at the beginning of the output, is  
inside LaTeX's version of the output box, and therefore once memoir  
has inserted the trim marks, it is no longer at the beginning.

This doesn't matter to some drivers, as they pre-scan the page for  
\specials such as papersize, but xdv2pdf doesn't do this because it  
is (normally) reading the input from a pipe, not a regular file, and  
so it doesn't have random access to the entire file.

You can verify what's going on by using
or similar, to log the actual material being shipped out.

With your redefinition of \trimmarks, adding the \special at the  
beginning, it works OK (though xdv2pdf gives a warning when it sees  
the original \special that memoir generated, which is no longer at  

A better solution (IMO) is to override memoir's redefinition of  
\shipout, so as to move the place where \AtBeginDvi material gets  
inserted when trim marks are requested. This is a more general  
solution, as it would apply to anything specified with \AtBeginDvi,  
not only the papersize \special. (Try setting a page background  
color, for example.)

So here's my suggested fix. When showtrims is enabled, this cancels  
the execution of \@begindvi when LaTeX is packaging the page, and  
instead executes it when memoir is adding the trim marks:

%%%%% add to preamble when using memoir.cls %%%%%
   \renewcommand*\shipout{\let\real at begindvi=\@begindvi\let\@begindvi= 
     \afterassignment\mem at shipi\setbox\@cclv=}
   \renewcommand*\mem at shipii{\mem at oldshipout\vbox{\real at begindvi 

Something similar may be needed with other classes or packages (e.g.,  
crop.sty -- see earlier thread) that wrap stuff around LaTeX's normal  
output, and don't take care to manage the \@begindvi content properly.


More information about the XeTeX mailing list