I'm trying to add some ornaments to every page using pgfornament, in the way it's described in that package's documentation. I ran into some problems there which -- I think -- relate to eso-pic and \AddToShipoutPicture; some things being \put on the page don't show up where they should. Here's a fairly minimal example:
\documentclass{article}
\usepackage[a6paper]{geometry}
\usepackage{eso-pic}
\usepackage{calc}
\usepackage{lipsum}
\makeatletter
\AddToShipoutPicture{%
\begingroup
\setlength{\@tempdima}{2mm}%
\setlength{\@tempdimb}{\paperwidth-\@tempdima-2cm}%
\setlength{\@tempdimc}{\paperheight-\@tempdima}%
\put(\LenToUnit{\@tempdima},\LenToUnit{\@tempdimc}){OK} % upper left
\put(\LenToUnit{\@tempdima},\LenToUnit{\@tempdima}){OK} % lower left
\put(\LenToUnit{\@tempdimb},\LenToUnit{\@tempdimc}){wrong} % upper right
\put(\LenToUnit{\@tempdimb},\LenToUnit{\@tempdima}){OK} % lower right
\endgroup
}
\makeatother
\begin{document}
\lipsum[1]
\end{document}
This produces the following:
So as you can see, one of the added labels is in the wrong spot, and I have absolutely no idea why. The same thing also happens with e.g. the code from Gonzalo's answer to this question (which apparently worked for him when he posted it).
Would appreciate any help, I'm not even sure how to begin debugging this. eso-pic is current, there's nothing unusual in the log file.

\putand see what happens. Additionally note that if you have a modern latex instalation (after october 2020), then the eso-pic functionally is build into the new hook feature, here as a background hook (which is actually howeso-picis implemented these days) – daleif Feb 03 '22 at 09:23\@tempdimcgetting overwriten. Note that you don't needcalcyou can just use\dimexpr length calc(sometimes ended by a\relax) – daleif Feb 03 '22 at 09:33yiou can use lengths directly in recent latex (presumably you have a new enough latex, as otherwise you would not have an issue with@tempdimc`) – David Carlisle Feb 03 '22 at 09:36\@tempdimc(as well as pretty much everything else) is from thepgfornamentdocumentation, so perhaps I should raise an issue there to have the example code fixed. – chsk Feb 03 '22 at 10:18