Margin figures like in APEX Calculus

14 views
Skip to first unread message

Stephan Boltzmann

unread,
Dec 15, 2025, 11:29:54 AM (2 days ago) Dec 15
to PreTeXt support
Hello everybody out there using PreTeXt,

The authors of APEX calculus did amazing work in generating beautiful PDF output.
Placing some figures on the margin avoids disturbing the flow of reading texts and I would also like to adapt it.

I looked at the APEX code on GitHub and I think the implementation of this layout feature is in the xsl files introduced after the comment "we want images in margin to be the full margin width".

Does PreTeXt offer similar functionality out of the box?
It has a `aside` class, but this rather seems to affect HTML and not LaTeX (PDF) output.

Kind regards
Stephan

Oscar Levin

unread,
Dec 15, 2025, 11:43:18 AM (2 days ago) Dec 15
to pretext...@googlegroups.com
Hi Stephan,

No, this is fully a feature that Sean implemented himself for APEX.  I'm sure he can say more.  As I understand it, this is a tricky thing to manage, even if you give some "hints" in the source that say you would like an image or other block in the margin.  Page breaks are brittle and I think Sean has to do a fair amount of tweaking before releasing the PDF.  

Oscar.

--
You received this message because you are subscribed to the Google Groups "PreTeXt support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pretext-suppo...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/pretext-support/c61b867c-7982-4bc3-a255-4b10e028351dn%40googlegroups.com.

Sean Fitzpatrick

unread,
Dec 15, 2025, 12:06:59 PM (2 days ago) Dec 15
to pretext...@googlegroups.com
Probably 60% of the XSL is related to getting figures in the margin.

There are a few LaTeX packages that can accomplish it, but the one I'm using is called "xcoffins". The LaTeX preamble code is loaded on lines 149-193.
In the original LaTeX for APEX, Greg wrote a custom apex.sty file that created custom commands like 'mfigure' and 'mtable'.
These had an argument that was a number between 0 and 1, and this was an absolute position on the page. In any case, I never figured out how to implement something like this in PreTeXt.

The xcoffins package uses relative position, but of course you don't always get things automatically placed where you want them, so there is some adjusting that needs to be done.

Other considerations: the use of tcolorbox affects horizontal placement of margin figures. So I had to do a lot initially with guidelines turned on to figure out the horizontal shift in various cases: a figure that is a peer of <p> in the main text, a figure within an example, a figure within a list, a figure within a list within an example, etc. There is XSL logic to sort into the various cases and provide the right shift.

After several years of having to spend days building the PDF, adjusting placements (hand-editing the .tex file from PreTeXt), rebuilding, checking, adjusting some more, I decided to add some additional XSL to handle this for me.
So there are some additional attributes in APEX that are not part of PreTeXt, like "vshift" as an attribute on a figure, image, table, etc.
This attribute is the logic trigger in the XSL to place the object in the margin, and it also tries to put everything in the right place.
Of course, every year the text changes slightly, and some of these numbers have to be adjusted.

The rest of our XSL handles things like YouTube videos, exercise geometry, etc.

Stephan Boltzmann

unread,
Dec 16, 2025, 9:07:58 AM (yesterday) Dec 16
to pretext...@googlegroups.com
Dear Oscar, dear Sean,

Thanks a lot for your answer and explanations.
The beautiful result is definitely worth the extra efforts!
Figures in the margin as pioneered and explained by Edward R. Tufte (https://www.edwardtufte.com/) make books with complicated, dense content a lot easier to read.
Had you considered using the tufte-latex package (https://tufte-latex.github.io/tufte-latex/ and https://ctan.org/pkg/tufte-latex?lang=en) for realizing a layout with figures in the margin?
I'm not sure whether this would work in combination with PreTeXt.
I would be very happy if the possibility to place figures in the margin of PDF output would become an integral part of PreTeXt!
It's great that the source code for APEX calculus was made accessible via GitHub allowing other people to build on this excellent work!

Kind regards
Stephan



You received this message because you are subscribed to a topic in the Google Groups "PreTeXt support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pretext-support/DBvXWbfiaDM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pretext-suppo...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/pretext-support/CAH%2BNcPb0GGSwm1AYg-g5rX9828KGrpxwYEBefdFKtj6Jep1O9g%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages