5

I really like the ornaments that this block of code makes for me:

\usepackage{eso-pic}
\makeatletter
\AddToShipoutPicture{%
\begingroup
\setlength{\@tempdima}{2mm}%
\setlength{\@tempdimb}{\paperwidth-\@tempdima-2cm}%
\setlength{\@tempdimc}{\paperheight-\@tempdima}%
\put(\LenToUnit{\@tempdima},\LenToUnit{\@tempdimc}){%
\pgfornament[anchor=north west,width=2cm]{63}}
\put(\LenToUnit{\@tempdima},\LenToUnit{\@tempdima}){%
\pgfornament[anchor=south west,width=2cm,symmetry=h]{63}}
\put(\LenToUnit{\@tempdimb},\LenToUnit{\@tempdimc}){%
\pgfornament[anchor=north east,width=2cm,symmetry=v]{63}}
\put(\LenToUnit{\@tempdimb},\LenToUnit{\@tempdima}){%
\pgfornament[anchor=south east,width=2cm,symmetry=c]{63}}
\endgroup
}
\makeatother

It comes from page 11 of pgfornament and it makes all four corners have these pretty ornaments that you see in the linked PDF.

Last year I used it myself for several of my documents and achieved identical results as what you see in the linked PDF, but this year it seems to be breaking with no informative error message. Instead of all four corners getting these nice ornaments, now only the two left corners get the ornaments and the typesetting process halts with this error message for every decorated page:

Missing number, treated as zero.
<to be read again>
\relax

I think I must have upgraded one or more packages since I last used this code successfully and that's probably why it's breaking, but I'm mystified by the error message and clueless as to how to fix the problem. I've confirmed (by commenting out the block of code) that this code is definitely what is throwing the error message, and even though I can continue compiling with "s", the PDF output no longer has all 4 corners decorated, so I'd like to fix it.

Any suggestions on how to fix this?

TeXnewbie
  • 1,489

1 Answers1

7

Since you are performing some additions/subtractions with lengths, you need to either load the calc package:

\documentclass{article}
\usepackage[a6paper]{geometry}% just for the exmaple
\usepackage{pgfornament}
\usepackage{eso-pic}
\usepackage{calc}

\makeatletter
\AddToShipoutPicture{%
\begingroup
\setlength{\@tempdima}{2mm}%
\setlength{\@tempdimb}{\paperwidth-\@tempdima-2cm}%
\setlength{\@tempdimc}{\paperheight-\@tempdima}%
\put(\LenToUnit{\@tempdima},\LenToUnit{\@tempdimc}){%
\pgfornament[anchor=north west,width=2cm]{63}}
\put(\LenToUnit{\@tempdima},\LenToUnit{\@tempdima}){%
\pgfornament[anchor=south west,width=2cm,symmetry=h]{63}}
\put(\LenToUnit{\@tempdimb},\LenToUnit{\@tempdimc}){%
\pgfornament[anchor=north east,width=2cm,symmetry=v]{63}}
\put(\LenToUnit{\@tempdimb},\LenToUnit{\@tempdima}){%
\pgfornament[anchor=south east,width=2cm,symmetry=c]{63}}
\endgroup
}
\makeatother

\begin{document}

Test

\end{document}

or to use \dimexpr:

\documentclass{article}
\usepackage[a6paper]{geometry}% just for the exmaple
\usepackage{pgfornament}
\usepackage{eso-pic}

\makeatletter
\AddToShipoutPicture{%
\begingroup
\setlength{\@tempdima}{2mm}%
\setlength{\@tempdimb}{\dimexpr\paperwidth-\@tempdima-2cm\relax}%
\setlength{\@tempdimc}{\dimexpr\paperheight-\@tempdima\relax}%
\put(\LenToUnit{\@tempdima},\LenToUnit{\@tempdimc}){%
\pgfornament[anchor=north west,width=2cm]{63}}
\put(\LenToUnit{\@tempdima},\LenToUnit{\@tempdima}){%
\pgfornament[anchor=south west,width=2cm,symmetry=h]{63}}
\put(\LenToUnit{\@tempdimb},\LenToUnit{\@tempdimc}){%
\pgfornament[anchor=north east,width=2cm,symmetry=v]{63}}
\put(\LenToUnit{\@tempdimb},\LenToUnit{\@tempdima}){%
\pgfornament[anchor=south east,width=2cm,symmetry=c]{63}}
\endgroup
}
\makeatother

\begin{document}

Test

\end{document}

The result in both cases:

enter image description here

Gonzalo Medina
  • 505,128
  • That fixed it. That's so interesting! Curious: what changed in the last 6-12 months for this code to require the calc package? I definitely was not using it before, and it worked fine then. Thanks for your help! – TeXnewbie Jul 16 '14 at 22:21
  • @TeXnewbie The code has always required one of my two solutions. Perhaps you were loading some package which internally loaded calc and then you stop loading it? – Gonzalo Medina Jul 16 '14 at 23:30
  • 1
    Note you should not use \@tempdimc here with newer latex implementations, see https://tex.stackexchange.com/a/632509/1090 – David Carlisle Feb 03 '22 at 10:22