TransWikia.com

(xe)tex: How do I apply ifoddpageno logic (special) to image, based on page the box is set on, rather than when file is read

TeX - LaTeX Asked on December 27, 2021

Working in (plain) XeTeX, I would like to apply a certain transformation (mirror on vertical axis) to an image if it appears on an odd-numbered page. I’d like a fairly general solution, as in some cases the image may end up in an insert, in others the image will just be added to the vertical list.

Naively I tried this (the image has been read into box0, full code below):

defbeforeBox{ifoddpagenokernwd0special{pdf: begintransform}special{x:scale -1 1}fi}%
defafterBox{ifoddpagenospecial{pdf: endtransform}fi}%

Which expanded immediately, and so mirrors the image if it is read while the page is odd (even if it is then displayed on the following one, once page-breaking has done its thing). I.e the logic works, but is applied too early.

expandafter like this:

setbox0hbox{expandafterbeforeBoxbox0expandafterafterBox}%

seems not to help and, based on extra tracing calls included in the full code below, if I replace the expandafter with noexpand, then they are never expanded (not entirely surprisingly, but I thought I ought to check).

Is there some solution to this that doesn’t involve writing page numbers to an external file? Some kind of notimmediate that can delay logic until the page is built?

Minimal example showing problem:

defdoimage#1#2{setbox0hbox{XeTeXpicfile "#2" width #1}%
  setbox0hbox{beforeBoxbox0afterBox}%
  box0
  }
defbeforeBox{immediatewrite-1{beforeBox thepageno}ifoddpagenokernwd0special{pdf: begintransform}special{x:scale -1 1}fi}%
defafterBox{immediatewrite-1{afterBox}ifoddpagenospecial{pdf: endtransform}fi}%
defjunk{aut tempore sunt officia beatae libero ad non est autem unde reiciendis minima ut quasi sapiente atque non sed architecto et et culpa aliquam repellendus ipsam omnis qui sit est dolorem ab mollitia sed vero asperiores itaque quibusdam quos est repellat provident voluptatem fugit consequatur iste architecto temporibuspar}

hsize=20em
defpicsz{59pt}deffilename{arrow.png}
junk
doimage{picsz}{filename}
junk
doimage{picsz}{filename}
junk
doimage{picsz}{filename}
junk
doimage{picsz}{filename}
junk
doimage{picsz}{filename}
junk
doimage{picsz}{filename}

bye

Screenshot of result:

Screenshot

One Answer

Thanks to those who've answered in the comments. The solution seems to be: you can't avoid using an auxiliary file.

Answered by somloigaluska on December 27, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP