latex3 / pdfresources

LaTeX PDF resource management
LaTeX Project Public License v1.3c
22 stars 5 forks source link

Inconsistent behavior of pdfmanagement_add between pdflatex and lualatex? #40

Closed lstngr closed 1 year ago

lstngr commented 1 year ago

I've been trying to set the TrimBox of my document based on layout computed by the geometry package. The idea being to implement something along the lines of Ulrike Fischer's answer on the TeX StackExchange. In her* answer, the computed TrimBox values are stored in a token list and written to the PDF page attributes.

I've tried replicating this answer using the pdfmanagement-testphase package, but noticed that the MWE below behaves differently when compiling with pdflatex or lualatex. With pdflatex, \t_soli_trimbox is correctly expanded when passed to pdfmanagement_add. However, lualatex seems to "sometimes" expand it.

With pdflatex

pdflatex example.tex
pdfinfo -box example.pdf
% Reports "TrimBox:            21.26    31.18   574.02   810.71"
grep -ai example.pdf
% Reports:
% /TrimBox [21.25983 31.18109 574.01576 810.70866]
% /TrimBox [21.25983 31.18109 574.01576 810.70866]

With lualatex,

pdflatex example.tex
pdfinfo -box example.pdf
% Reports "TrimBox:             0.00     0.00   595.28   841.89"
grep -ai example.pdf
% Reports:
% << /Type /Page /Contents 7 0 R /Resources 5 0 R /MediaBox [ 0 0 595.276 841.89 ] /TrimBox [\l_soli_trimbox_tl ] /Parent 11 0 R >>
% << /Type /Pages /TrimBox [21.25983 31.18109 574.01576 810.70866]   /Count 1 /Kids [ 6 0 R ] >>

I was wondering if this was a bug, or expected behavior, since the pdfmanagement-testphase mentions backend dependent behavior in some cases. Being unfamiliar with the expl3 syntax, pardon me if this was expected (and I'd be glad if you'd let me know what could have been done better!).

\RequirePackage{pdfmanagement-testphase}
\DeclareDocumentMetadata{uncompress}
\documentclass{article}

\ExplSyntaxOn
% Try to set the TrimBox from a token list. Fails with LuaLaTeX
\tl_new:N\l_soli_trimbox_tl
\tl_set:Nx\l_soli_trimbox_tl{21.25983~31.18109~574.01576~810.70866}
\pdfmanagement_add:nnn{Pages}{TrimBox}{[\l_soli_trimbox_tl]}
\pdfmanagement_add:nnn{Page}{TrimBox}{[\l_soli_trimbox_tl]}
% Make sure the token list is correctly set
\wlog{My~box~has~the~value:~\l_soli_trimbox_tl}

% Setting the TrimBox explicitly works
% \pdfmanagement_add:nnn{Pages}{TrimBox}{[21.25983~31.18109~574.01576~810.70866]}
% \pdfmanagement_add:nnn{Page}{TrimBox}{[21.25983~31.18109~574.01576~810.70866]}
\ExplSyntaxOff

\begin{document}
Hello there.
\end{document}

Edit: below are the versions of pdflatex and lualatex that were used.

pdflatex --version
pdfTeX 3.141592653-2.6-1.40.24 (TeX Live 2022/Arch Linux)
kpathsea version 6.3.4
Copyright 2022 Han The Thanh (pdfTeX) et al.
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: Han The Thanh (pdfTeX) et al.
Compiled with libpng 1.6.38; using libpng 1.6.38
Compiled with zlib 1.2.13; using zlib 1.2.13
Compiled with xpdf version 4.03

lualatex --version
This is LuaHBTeX, Version 1.15.0 (TeX Live 2022/Arch Linux)
Development id: 7509

Execute  'luahbtex --credits'  for credits and version details.

There is NO warranty. Redistribution of this software is covered by
the terms of the GNU General Public License, version 2 or (at your option)
any later version. For more information about these matters, see the file
named COPYING and the LuaTeX source.

LuaTeX is Copyright 2022 Taco Hoekwater and the LuaTeX Team.
u-fischer commented 1 year ago

In his answer

in her answer. I'm a women.

I was wondering if this was a bug, or expected behavior

I will have to check but probably more expected behaviour then bug. In any case you shouldn't rely on internal expansion, but expand yourself by using the "x" argument type:

\pdfmanagement_add:nnx{Pages}{TrimBox}{[\l_soli_trimbox_tl]}
\pdfmanagement_add:nnx{Page}{TrimBox}{[\l_soli_trimbox_tl]}

In a current LaTeX you can/should also replace

\RequirePackage{pdfmanagement-testphase}
\DeclareDocumentMetadata{uncompress}

by

\DocumentMetadata{uncompress}
lstngr commented 1 year ago

in her answer. I'm a women.

Sorry, I should have checked.

Thank you for the prompt and useful help, it indeed looks like a misunderstanding of expl3 on my side, sorry for the "pollution" this issue caused!