4

Using xelatex... when I apply a \clipbox upon a \scalebox of a box that uses the optional argument, the clip is not performed properly.

The problem goes away if:

  1. using pdflatex,

  2. the optional argument to the \scalebox is omitted, or

  3. the \clipbox is omitted.

Here is an unanswered 2014 question that perhaps describes the same problem: clipbox with bidi.

\documentclass{article}
\usepackage{trimclip,graphicx}
\begin{document}
Works OK without scalebox opt.{} argument

\setbox0=\hbox{XXX}
  \scalebox{1}{\copy0}%
. Now clip it:
\clipbox{0pt 0pt 10pt 0pt}{%
  \scalebox{1}{\copy0}%
}.   

Breaks with scalebox opt.{} argument

\setbox0=\hbox{XXX}
  \scalebox{1}[.5]{\copy0}%
. Now clip it:
\clipbox{0pt 0pt 10pt 0pt}{%
  \scalebox{1}[.5]{\copy0}%
}.   
\end{document}

While I use the temporary \box0 for simplicity, the problem arises also if I use a permanent \savebox. Package loading order has no effect.

Below, the top image is pdflatex, the bottom with xelatex. Note the bottom-right of the bottom image, which shows an empty result for the clip.

enter image description here

NOTE: This question arose when Hiemanshu Sharma asked why my method at Draw Text in different shapes did not work with xelatex. I boiled it down to the above MWE.

0

1 Answer 1

5

The code in trimclip is an earlier version of the material that is now in the expl3 drivers. In particular, there are some refinements that are in the XeTeX drivers that are not in trimclip. To see this, try the example

\documentclass{article}
\usepackage{expl3}
\begin{document}

A%
\ExplSyntaxOn
\hbox_set:Nn \l_tmpa_box { XXX }
\box_scale:Nnn \l_tmpa_box { 1 } { 0.5 }
\box_trim:Nnnnn \l_tmpa_box { 0pt } { 0pt } { 10pt } { 0pt }
\box_clip:N \l_tmpa_box
\box_use:N \l_tmpa_box
\ExplSyntaxOff
B

\end{document}

with pdfTeX and XeTeX.

The code in trimclip can be fixed by taking the newer definition and applying it:

\documentclass{article}
\usepackage{trimclip,graphicx}
\begin{document}
\makeatletter
\ifdefined\XeTeXversion
  \def\@cliptoboxdim#1{%
    \setbox #1=\hbox{%
      \Gin@defaultbp\WIDTH{\wd #1}%
      \Gin@defaultbp \DEPTH {\dp #1}%
      \@tempdima \ht #1%
      \advance\@tempdima\dp#1%
      \Gin@defaultbp \TOTALHEIGHT {\@tempdima }%
      \special{pdf:literal q}% 
      \special{pdf:literal 0 -\DEPTH \space \WIDTH \space \TOTALHEIGHT \space re W n }%
      \rlap{\copy #1}%
      \special {pdf:literal Q}%
      \hskip\wd#1%
    }%
  }
\fi
\makeatother

\setbox0=\hbox{XXX}

A%
\clipbox{0pt 0pt 10pt 0pt}{%
  \scalebox{1}[0.5]{\copy0}%
}%
B
\end{document}
1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .