[XeTeX] Generating cropped PDF graphics file

Ross Moore ross at ics.mq.edu.au
Thu Apr 17 04:14:23 CEST 2008


Hi Chandra,

On 16/04/2008, at 5:47 PM, R (Chandra) Chandrasekhar wrote:
> Ross Moore wrote:
>> You can \shipout just a box containing the contents that you want.

>> Similar coding should work with XeTeX as it also
>> uses  \pdfpageheight  and  \pdfpagewidth .
>
> Thanks, Ross. I have now used \newbox, \sbox, and \usebox in  
> XeLaTeX for the
> logo text. But I have not been able to use the above commands  
> starting with
> \setbox with XeLaTeX to get the desired output. Is there a LaTeX/ 
> XeLaTeX
> equivalent for these commands?

This works just fine for me, with XeLaTeX
(XeTeX v. 0.997 )

\documentclass[dvipdfmx,12pt]{article}
\usepackage{graphicx}
\newbox\shipoutbox
\begin{document}
\setbox\shipoutbox=\hbox{%
  The quick brown fox jumps over the lazy dog.
}%
\setbox0=\vbox{%
  \kern-1truein
  \hbox{%
   \kern-1truein
    \framebox{\box\shipoutbox}%
   \kern1truein
  }\kern1truein
}%
\dimen0\ht0\advance\dimen0\dp0
\pdfpageheight\dimen0
\pdfpagewidth\wd0
\shipout\box0
\end{document}


And so does the following:

\documentclass[10pt,a4paper,onecolumn]{article}%
\usepackage[nomath]{fontspec}
\usepackage{xunicode}
\usepackage{xltxtra}
\usepackage[margin=25mm]{geometry}

\usepackage[cmyk,xetex]{xcolor}
\newbox\shipoutbox
\newlength{\mlength}
\newsavebox{\logobox}
%\setmainfont{Minion Pro}  % I don't have this font
\setmainfont{Lucida Grande}%

\definecolor[named]{lettercolor}{cmyk}{0, 0.75, 0.75, 0.50}
\definecolor[named]{linecolor}{cmyk}{0.5, 0.1, 0.5, 0.25}%

\begin{document}
\settowidth{\mlength}{\Huge{M}}
\sbox{\logobox}{%
   \begin{tabular}{c}
   \color{linecolor}\rule[0.0em]{\mlength}{2pt}\\
   \color{lettercolor}\Huge{M}\\[-6pt]
   \color{linecolor}\rule[0.0em]{\mlength}{2pt}
   \end{tabular}%
}%
\begingroup
\setbox0=\vbox{\kern-1truein
    \hbox{\kern-1truein
      \usebox{\logobox}%<--- contents goes here
     \kern1 truein}%
    \kern1truein}%
   \dimen0\ht0 \advance\dimen0\dp0
   \pdfpageheight\dimen0
   \pdfpagewidth\wd0
  \shipout\box0
\endgroup
\usebox{\logobox}%  see it on the page also
\end{document}


All the package solutions do basically this, plus often
a lot more stuff which is frequently quite redundant.
You don't need to know the size in advance; and parameters
such as margins, topskip, h-offset, v-offset, baselines
etc. are completely irrelevant.

You can add (coloured) frames, put colour in the background,
apply scaling effects or transformations from the graphics(x)
package, or whatever.


>
> Chandra
> 16 Apr 08


Hope this helps,

	Ross


------------------------------------------------------------------------
Ross Moore                                       ross at maths.mq.edu.au
Mathematics Department                           office: E7A-419
Macquarie University                             tel: +61 (0)2 9850 8955
Sydney, Australia  2109                          fax: +61 (0)2 9850 8114
------------------------------------------------------------------------





More information about the XeTeX mailing list