latex3 icon indicating copy to clipboard operation
latex3 copied to clipboard

add pagesize setting to the backend

Open u-fischer opened this issue 2 years ago • 4 comments

This adds the code to set the mediabox /pagesize currently used in graphics-def into l3backend so that the mediabox are set always and not only if packages like graphics or geometry are loaded.

There is no public interface currently (changing the pagesize in mid-document doesn't work for all engines with these functions) and testfiles are still missing.

u-fischer avatar Jun 21 '22 10:06 u-fischer

Just a brief comment for now:

More generally, the whole of the backend, together with its related files such as l3pdf etc., will need a major cleanup/reworking before moving anything out of the experimental 'pdf-management/latex-lab' world.

car222222 avatar Jun 22 '22 03:06 car222222

I've looked over the code and it strikes me that we really want to use DocStrip to keep the similar approaches together. There are basically two:

  • pdfTeX/LuaTeX/XeTeX want one using \pdfpage... (the 'pdfTeX approach')
  • dvips/dvipdfmx want one using \__kernel_backend_literal:e (the 'dvips approach')

For the pdfTeX approach, I see why the code needs to be in the \@kernel@before@begindocument hook. But I'm not sure the dvips one does: as it's set in \__kernel_backend_first_shipout:n and not expanded when set up, I think we don't need a second hook use.

I'm really not sure the \mag or 0pt tests are needed - both feel like they are aiming at pathological cases and reflect the supporting-plain TeX history of the .def files, which we don't need to carry forward if we are going for a LaTeX-only solution. (On that - we need skip this entire area if LaTeX is not in use). The \mag test would do nothing is \mag is set, which feels like a cop-out: if we want to support \mag, we should I think be scaling the PDF size. If the user has managed to set a 0pt size, they've broken their document and I think deserve an error, either from us or from their PDF viewer.

If the above looks reasonable, it removes much the common code and we are left only with handling \stock... somewhere. That one looks more tricky: memoir has (arguably) altered the semantics of \pageheight/\pagewidth and I think that likely wants some thought. However that is addressed, we presumably want that common area moving to l3pdf, which would leave something like \@@_backend_pagesize_set:nn which contains within in the hook setup.

Done that way, a decision to call \@@_backend_pagesize_set:nn would be moved to l3pdf, which then could have the (common) conditional which deals with the wider issue of 'can we apply this to existing documents'.

If that sounds reasonable I'll add a commit that implements it to the PR: want to check first that my thinking feels solid.

josephwright avatar Jun 22 '22 05:06 josephwright

I'm really not sure the \mag or 0pt tests are needed

This was a historic compromise at the time to avoid breaking existing platex setup and in paticular avoiding timing issues over package loading order. With expl3 being in the format and so simplifying possible load orders, we can probably look at that again, with the platex maintainers.

I think we don't need a second hook use.

Origially some dvi drivers had a "first page setting wins" and some had "last page setting wins" and some had "last page setting wins, but must be on first page". That meant finding a place to insert the code was interesting. But dvips changed its default and other dvi drivers have dropped out of use and I believe all supported back ends work in essentially the same way now with regard to timing, and as you say just spilt on needing a \special or setting internal registers

davidcarlisle avatar Jun 22 '22 08:06 davidcarlisle

I'm working on ideas in https://github.com/latex3/latex3/tree/setpdfpagesize-alt backend part is done, but I want a common interface in l3pdf (to follow later).

josephwright avatar Jun 22 '22 12:06 josephwright

Handled in a slightly different way after discussion.

josephwright avatar Sep 28 '22 07:09 josephwright