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

Clipping support with XeLaTeX?

447 views
Skip to first unread message

Martin Scharrer

unread,
Jul 11, 2011, 8:18:54 AM7/11/11
to
When using the `clip,trim=..` options of \includegraphics XeLaTeX
prints the error:

Package xetex.def Warning: No clipping support in XeTeX yet

However, clipping within TikZ works fine with text and the image as
shown by the example code below.
Can it be that the `xetex.def` driver file is outdated and the support
got actually implemented in the meantime?
I don't see a reason why that driver doesn't use the same technique as
the XeTeX system driver of PGF/TikZ.
Do you see this wrong?

I don't use XeLaTeX myself but wanted to add lower level clipping
support for my `adjustbox` package to avoid the dependency on PGF/
TikZ.

% Compile with xelatex
\documentclass{article}
\usepackage{tikz}
\begin{document}%
\frame{%
\begin{tikzpicture}%
\clip (0,0) rectangle (1em,1ex);
\node {Hello};
\end{tikzpicture}%
}

\frame{\includegraphics[trim=5cm 5cm 5cm 5cm,clip]{tiger.pdf}}% does
not clip

\setbox0\hbox{\includegraphics{tiger.pdf}}

% Clips fine
\frame{%
\begin{tikzpicture}%
\clip (5cm,5cm) rectangle (\wd0-5cm,\ht0-5cm);
\node [above right] {\usebox0};
\end{tikzpicture}%
}
\end{document}

GL

unread,
Jul 11, 2011, 8:23:18 AM7/11/11
to
Le 11/07/2011 14:18, Martin Scharrer a écrit :
> When using the `clip,trim=..` options of \includegraphics XeLaTeX
> prints the error:
>
> Package xetex.def Warning: No clipping support in XeTeX yet
>
> However, clipping within TikZ works fine with text and the image as
> shown by the example code below.

in your adjustbox package, why don't you use \pgfpathqclip ?

Thanks in advance.

Martin Scharrer

unread,
Jul 11, 2011, 8:28:28 AM7/11/11
to
On Jul 11, 1:23 pm, GL <gouail...@gmail.com> wrote:
> Le 11/07/2011 14:18, Martin Scharrer a écrit :
>
> > When using the `clip,trim=..` options of \includegraphics XeLaTeX
> > prints the error:
>
> >         Package xetex.def Warning: No clipping support in XeTeX yet
>
> > However, clipping within TikZ works fine with text and the image as
> > shown by the example code below.
>
> in your adjustbox package, why don't you use \pgfpathqclip ?
>
> Thanks in advance.

Originally I used TikZ code and then translated it to the PGF
equivalent without checking if there is such a better macro.
I'm planning now to replace the use of PGF/TikZ altogether. I already
found out how to do it with pdftex (`\pdfxform`) but still
have to crack `dvips` and other output drivers.

Best,
Martin

GL

unread,
Jul 11, 2011, 9:09:27 AM7/11/11
to

No \pdfxform must not be used for clipping, though it clips as a side
effect. If you use \pdfxform each time you clip, your pdf file will
grow up because \pdfxform inserts the box in the catalog each time.

Clipping with pdfTeX can be done with \pdfliteral.

\pdfxform (like \pdfximage) must be used when a same form (box) or
image have to be inserted many time in the document.

Regards.

>
> Best,
> Martin

Martin Scharrer

unread,
Jul 11, 2011, 9:54:20 AM7/11/11
to

The `pdftex.def` driver used by `graphics/x` uses:

\expandafter\pdfxform\GPT@temp\@tempboxa
\pdfrefxform\pdflastxform

Where `\GPT@temp` is either empty or an attribute.

I don't mind either way.
Please give me an example how to clip a given TeX box using four
parameters (llx, lly, urx, ury).

Best,
Martin

GL

unread,
Jul 11, 2011, 10:51:37 AM7/11/11
to

Just \setbox 0=\hbox{\tikz { \clip ...}}

And then \showbox 0 => look at the \pdfliteral code and you will know
how to proceed. This is what i've done for TabU images (and some leaders)

Each time you use \pdfxform, the form is inserted into the calatog.


I think pdftex.def does not provide clipping but for \includegraphics.

In this case, using \pdfxform or \pdfximage makes sense. It's just
non optimal if the same image is inserted many times in the document.

In TabU for example, the images are stored in a buffer, in order not
to insert the same image more than once (because images can be easily
replicated as backgrounds of cells). The same would apply for a tiled
wallpaper.

However, if you clip 1 squared centimeter of a A1 image, the full A1
image will be inserted in the pdf catalog with \pdfxform... This is not
what "clipping means" and pgf uses appropriately \pdfliteral to clip.

>
> Best,
> Martin

Martin Scharrer

unread,
Jul 11, 2011, 11:32:36 AM7/11/11
to
\pdfxform itself doesn't even produce any output as long it is not
referenced
using \pdfrefxform.


> I think pdftex.def does not provide clipping but for \includegraphics.
>
> In this case, using \pdfxform or \pdfximage makes sense. It's just
> non optimal if the same image is inserted many times in the document.
>
> In TabU for example, the images are stored in a buffer, in order not
> to insert the same image more than once (because images can be easily
> replicated as backgrounds of cells). The same would apply for a tiled
> wallpaper.

I don't see it:

Using:

\documentclass{article}
\usepackage{graphicx}
\begin{document}
\includegraphics[clip,trim=1cm 1cm 1cm 1cm]{tiger}
\includegraphics[clip,trim=1cm 1cm 10cm 1cm]{tiger}
\includegraphics[clip,trim=1cm 10cm 1cm 1cm]{tiger}
\includegraphics[clip,trim=1cm 10cm 1cm 10cm]{tiger}
\end{document}

I get:

<tiger.pdf, id=1, 612.2875pt x 644.4075pt> <use tiger.pdf> <use
tiger.pdf>
<use tiger.pdf> <use tiger.pdf>

and a PDF of 42k where the tiger.pdf (comes with PStricks) is 34k.
With only one image I get 40k.
The image isn't stored multiple times.


> However, if you clip 1 squared centimeter of a A1 image, the full A1
> image will be inserted in the pdf catalog with \pdfxform... This is not
> what "clipping means" and pgf uses appropriately \pdfliteral to clip.

Does \pdfliteral then strip all material of the A1 image which isn't
displayed?
It would surprise me.

Martin

GL

unread,
Jul 11, 2011, 12:14:30 PM7/11/11
to

Sorry this does not work for me with a .jpg image...
Don't know why.

Martin Scharrer

unread,
Jul 11, 2011, 2:08:02 PM7/11/11
to

It works for me with an JPG image as well.


pdfTeX 3.1415926-1.40.11-2.2 (TeX Live 2010)
kpathsea version 6.0.0
Copyright 2010 Peter Breitenlohner (eTeX)/Han The Thanh (pdfTeX).
There is NO warranty. Redistribution of this software is
covered by the terms of both the pdfTeX copyright and
the Lesser GNU General Public License.
For more information about these matters, see the file
named COPYING and the pdfTeX source.
Primary author of pdfTeX: Peter Breitenlohner (eTeX)/Han The Thanh
(pdfTeX).
Compiled with libpng 1.2.40; using libpng 1.2.40
Compiled with zlib 1.2.3; using zlib 1.2.3
Compiled with xpdf version 3.02pl4


Martin

Ulrike Fischer

unread,
Jul 12, 2011, 4:47:46 AM7/12/11
to
Am Mon, 11 Jul 2011 05:18:54 -0700 (PDT) schrieb Martin Scharrer:

> When using the `clip,trim=..` options of \includegraphics XeLaTeX
> prints the error:
>
> Package xetex.def Warning: No clipping support in XeTeX yet
>
> However, clipping within TikZ works fine with text and the image as
> shown by the example code below.
> Can it be that the `xetex.def` driver file is outdated and the support
> got actually implemented in the meantime?
> I don't see a reason why that driver doesn't use the same technique as
> the XeTeX system driver of PGF/TikZ.
> Do you see this wrong?

I agree with you: it should be technically possible. The problem is
to find someone who can update the code of xetex.def. Jonathan Kew
wrote two or three years ago about it in the xetex mailing list.
Another idea would be the (x)dvipdfmx team. In their mailing list I
saw that Jin-Hwan Cho wrote the driver files for pgf.

--
Ulrike Fischer

Martin Scharrer

unread,
Jul 12, 2011, 7:11:19 AM7/12/11
to ne...@nililand.de
On Tuesday, July 12, 2011 9:47:46 AM UTC+1, Ulrike Fischer wrote:
> Am Mon, 11 Jul 2011 05:18:54 -0700 (PDT) schrieb Martin Scharrer:
>
> > When using the `clip,trim=..` options of \includegraphics XeLaTeX
> > prints the error:
> >
> > Package xetex.def Warning: No clipping support in XeTeX yet
> >
> > However, clipping within TikZ works fine with text and the image as
> > shown by the example code below.
> > Can it be that the `xetex.def` driver file is outdated and the support
> > got actually implemented in the meantime?
> > I don't see a reason why that driver doesn't use the same technique as
> > the XeTeX system driver of PGF/TikZ.
> > Do you see this wrong?
>
> I agree with you: it should be technically possible.
Thanks for confirming this.

> The problem is
> to find someone who can update the code of xetex.def. Jonathan Kew
> wrote two or three years ago about it in the xetex mailing list.
> Another idea would be the (x)dvipdfmx team. In their mailing list I
> saw that Jin-Hwan Cho wrote the driver files for pgf.

I simply would base the xetex.def code on the PGF driver, so that author would be indeed a good choice to contact. Who would be in charge to accept the new version?

--
Best Regards,

Martin Scharrer

agmad...@gmail.com

unread,
Sep 14, 2014, 1:50:23 PM9/14/14
to
I am trying the given code to center image but its not working.

\begin{figure}[ht]
\centering
\includegraphics[trim=0cm 0cm 0cm 0cm, clip=true,width=\linewidth]{twsd.jpg}
\caption{Types of WSD}
\label{fig:my_2}
\end{figure}

and showing a warning:

`h' float specifier changed to `ht'.

output of the above code:
![here is the output image][1]

At starting i was using compiler `latex` and it was working correctly. But now am using `xelatex`, and the images alignment changed automatically.
Please suggest me some way to center the images.


[1]: http://i.stack.imgur.com/KTxg2.jpg

Axel Berger

unread,
Sep 14, 2014, 4:21:00 PM9/14/14
to
agmadhavi11 wrote on Sun, 14-09-14 19:50:
>Please suggest me some way to center the images.

Something is wrong here. At <width=\linewidth> there can't be any
centering. It seems to me your inserted image has a wide invisible
(white) right margin.

Axel

Ulrike Fischer

unread,
Sep 15, 2014, 3:15:27 AM9/15/14
to
Am Sun, 14 Sep 2014 10:50:23 -0700 (PDT) schrieb
agmad...@gmail.com:

> I am trying the given code to center image but its not working.
>
> \begin{figure}[ht]
> \centering
> \includegraphics[trim=0cm 0cm 0cm 0cm, clip=true,width=\linewidth]{twsd.jpg}
> \caption{Types of WSD}
> \label{fig:my_2}
> \end{figure}

You are't trimming anything so there is no clipping. As an example
your code is useless.

> At starting i was using compiler `latex` and it was working
> correctly. But now am using `xelatex`, and the images alignment
> changed automatically.

Make sure that you have an current system. Clipping depends on the
graphicx driver and at least in the case of xetex there has been
changes.


--
Ulrike Fischer
http://www.troubleshooting-tex.de/

Axel Berger

unread,
Sep 15, 2014, 6:49:00 AM9/15/14
to
Ulrike Fischer wrote on Mon, 14-09-15 09:15:
>You are't trimming anything so there is no clipping. As an example your
>code is useless.

Sorry, but that seems irrelevant here. The width= is applied after
trimming and clipping, and if that's the full linewidth, nothing can
get centred. If it looks moved out of centre, that must be part of the
image itself.

Ulrike Fischer

unread,
Sep 16, 2014, 3:22:24 AM9/16/14
to
Am Mon, 15 Sep 2014 12:49:00 +0200 schrieb Axel Berger:

>>You are't trimming anything so there is no clipping. As an example your
>>code is useless.

> Sorry, but that seems irrelevant here.

The subject of the question is about "clipping support".

> The width= is applied after trimming and clipping, and if that's
> the full linewidth, nothing can get centred. If it looks moved
> out of centre, that must be part of the image itself.

You are trying to make sense from an example which -- as you proved
yourself -- can't be real as it can't have worked with latex either.
I don't see a point to discuss what could have happened when parts
of the example are a lie.
0 new messages