Conditional moving of markup

I have prepared a tufte-like style with a large margin alternating from the right hand side on odd pages, to the left hand side on even pages. These margins are about a third of the width and are used for marginal notes. I have written a wide-figure macro which displays a table larger than the body of the text and <move>s it to the left on an even page, in order to center it.

The problem is that I have done this with (undocumented) <specific|odd|> and <specific|even|> tags that display content only on odd and even pages respectively, with the content taking no space, so I needed a phantom and now it works but the usual cursor positioning issues that arise when one abuses moving routines make it barely usable.

Instead I would like to: <move|my content|<if|page-is-even|<minus|some distance>|>>. Since the page number is not available at typesetting, I thought of checking the position of the box: if the left-most coordinate is larger than some amount, then we are in an even page, because those have large margins on the left. However, this does not work. Either because the box length l is relative to the body of the document or because it’s not available inside the if, or some other obscure reason.

I would be grateful for any suggestions.


From, combining label and pageref gives the page number, which though I haven’t been able to use inside a plus macro so I do not know how to use it to determine if the page is even or odd.

1 Like

The solution of @pireddag seems nice. Page numbers are not available because you have to typeset the content, and even you do not really know where the box is because the boxes are typeset independently and then put into a vertical list, since the typesetter has to perform both line and page breaking (this is how far I understand the problem). So the boxes are not absolutely positioned until very late. I’m not sure if there is some primitive which could allow to hack this behaviour. I think labels, which record the results of previous typesetting passes could be the solution, alternatively you can create you own variables which have a default value and which after the pass could (maybe) retrieve the information on the page location and eventually use it aftwards. Maybe loci could be used for this?

I do not yet see how to use it to modify the placement of a box: I am not able to figure out automatically from that if the page is even or odd.

Maybe give a look at how \pageref works and find the page number. This could give you an hint on how retrieve the information. At worst we can use some scheme to do it.

I haven’t been able to find the definition of pageref in the c++ code.
For what regards the info on the position of the box, first mentioned by @mdbenito, I found that it is calculated through the C++ function typeset_as_atomic, whose name suggests that the output does not depend of the position where box-info is invoked.
On the other hand, there is the function box-intersects in graphics-utils.scm which depends on a scheme version of box-info, and its name suggests that the output depends on the position of the boxes. So I have to investigate more.

Thanks for the answers!

After talking to Joris, it seems like the best (only) way to do this for now is indeed to use specific with odd and even and then a phantom to simulate the space that the markup would take (because specific removes it from the flow). This is how it’s done for the marginal-note too.

I will push my “tuftey” style to tm-forge some time soon so that others can use and improve it (it’s currently a hack with tons of hard-coded lengths and rather ugly macro definitions)


Do you mean the vertical space?

Thank you, @mdbenito, for your hard work. :+1:
I was looking for such a style for a long time.
Do you think implementing wide and marginal table/figure could be achieved too with the current design ?

This guy below, developed a modern implementation of the Tufte layout :

The original one for those who are not familiar with it :

There is also a tufte CSS style somewhere. Would be cool if we can export the document to HTML and use that style.


1 Like

The jupyterbook project (Myst markdown) uses also this kind of layout style for the margin figure, table notes.

@pireddag Yes, vertical space.

:sweat_smile: Before you open the champagne, I have to say that what even though I like a nice layout, there will be a lot of room for improvement.

Yes, I have already implemented wide figures (that’s what caused this post to begin with) and side figures, both as figures in the margin, as well as in the main text with captions on the side.

1 Like

Up’s … too late … it was a crazy party here :partying_face::tada:

So let’s say it’s like a good wine, it gets better over time.
Anyway thank you very much for this style which I am sure will make many happy like me.
Thanks :+1:

Hi Miguel, I tried (not very hard) to find your style file. Is it available somewhere?

Hi Joris, it was a private repo in github because it is far from finished, with the logos of my company in it, etc. But I made it public anyway because it doesn’t look like I will have time to improve it in the foreseeable future. Here:

I’m sure there is tons of room for improvement. For one, I have hardcoded sizes and probably done a few hacks.