sasozivanovic / memoize

A cross-format package for externalization of graphics and memoization of compilation results in general
LaTeX Project Public License v1.3c
16 stars 3 forks source link

Memoize perpetually creates memos in landscape environment if pdflscape is used #25

Open cfr42 opened 4 months ago

cfr42 commented 4 months ago

Compiled with pdfTeX, the following code reports

Package memoize Warning: The compilation produced 1 new extern on input line 11
52.

on every compilation and, indeed, an additional page with the memoized picture is perpetually present in the PDF regardless of how many times the source is compiled.

\documentclass {article}
\usepackage{memoize}
\mmzset{prefix=memos/}
\usepackage{tikz}
\usepackage{pdflscape}
\usepackage{kantlipsum}
\begin{document}
\begin{landscape}
  \begin{tikzpicture}[baseline=(n.center)] \node (n) [rotate=90, scale=9, opacity=0.15, black, inner sep=1pt] {PRELIMINARY};\end{tikzpicture}%
\kant[11]
\end{landscape}
\end{document}

.mmz:

\mmzPrefix {memos/}
\mmzUsedCMemo {memos/0FE7150AB04FD73095EA399A0F6B28BD.memo}
\mmzUsedCCMemo {memos/0FE7150AB04FD73095EA399A0F6B28BD-E778DCCCB8AAB0BBD3F6CFEEFD2421F8.memo}
\mmzNewCMemo {memos/0FE7150AB04FD73095EA399A0F6B28BD.memo}
\mmzNewCCMemo {memos/0FE7150AB04FD73095EA399A0F6B28BD-E778DCCCB8AAB0BBD3F6CFEEFD2421F8.memo}
\mmzNewExtern {memos/0FE7150AB04FD73095EA399A0F6B28BD-E778DCCCB8AAB0BBD3F6CFEEFD2421F8.pdf}{1}{224.0398pt}{816.29105pt}
\endinput

memos/

0FE7150AB04FD73095EA399A0F6B28BD-E778DCCCB8AAB0BBD3F6CFEEFD2421F8.memo  0FE7150AB04FD73095EA399A0F6B28BD.memo

.mmz.log:

\PackageInfo{memoize (perl-based extraction)}{Extracting new externs listed in 'prawf.mmz' from 'prawf.pdf' using Perl modulePDF::API2}
\PackageWarning{memoize (perl-based extraction)}{\space\space I refuse to extract page 1 from prawf.pdf, because its size (816.28965pt x 224.037pt) is not what I expected (224.0398pt x 816.29105pt)}
\PackageInfo{memoize (perl-based extraction)}{Done}
\endinput

Note that there is no problem if lscape is used rather than pdflscape. This surprised me because I thought pdflscape was primarily concerned with instructing the PDF viewer rather than changing the PDF.

I don't know whether this is evidence of memoize's security features or a bug, but I'm also not sure what the solution would be. I didn't try this, but my first thought was to capture the landscape environment, but that won't work in the original case which arose from a question in which the picture was stamped as a watermark over the regular page content by inclusion in the shipout box. In that case, landscape might cover several pages, so it wouldn't work to capture everything as an image and I imagine that would not cooperate well with the shipout hooks either.

For example,

\documentclass {article}
\usepackage{memoize}
\mmzset{prefix=memos/}
\usepackage{tikz}
\usepackage{pdflscape}
\usepackage{kantlipsum}
\begin{document}
\begin{landscape}
  \AddToHook{shipout/foreground}{%
    \put (.5\paperwidth,-\paperheight){%
      \begin{tikzpicture}[] \node (n) [rotate=90, scale=9, opacity=0.15, black, inner sep=1pt] {PRELIMINARY};\end{tikzpicture}%
    }%
  }%
\kant[1-10]
\end{landscape}
\end{document}

Code arises from https://tex.stackexchange.com/a/719506/. (I would link the question but it has a rather problematic preamble.)

sasozivanovic commented 4 months ago

Sorry, I'm a bit swamped here, but I'll try to look into it asap.

This surprised me because I thought pdflscape was primarily concerned with instructing the PDF viewer rather than changing the PDF.

If this is the case, I'm not surprised: Memoize stores the PDF page size. I had no idea that the PDF viewer can be instructed otherwise.

cfr42 commented 4 months ago

Sorry, I'm a bit swamped here, but I'll try to look into it asap.

Sure. Take your time.

This surprised me because I thought pdflscape was primarily concerned with instructing the PDF viewer rather than changing the PDF.

If this is the case, I'm not surprised: Memoize stores the PDF page size. I had no idea that the PDF viewer can be instructed otherwise.

Sorry. I'm trying to reconstruct what surprised me about the difference between the result of using lscape versus pdflscape ....

TeX SE refs on pdflscape/lscape

Semi-random selection: