0

I'm trying to get AddToHook to work to add a background image and unfortunately, it always shows "Draft" in read written diagonally over the page instead of the background image image.png that I provide and which lies in the same directory. While in the end I want to have more complex logic, I reduced my problem to a minimal example:

\documentclass{book}%
\usepackage[T1]{fontenc}%
\usepackage[utf8]{inputenc}%
\usepackage{atbegshi}%
\usepackage[paperwidth=15cm,paperheight=20cm,inner=1.91cm,outer=3.09cm,top=2.186cm,bottom=3.537cm]{geometry}%
\usepackage{graphicx}%
\usepackage{background}%
\AddToHook{shipout / background}{\put(0pt, -\paperheight) {\includegraphics[width =\paperwidth, height =\paperheight]{image.png}}}%
%
\begin{document}%
x
\end{document}

What's wrong here and needs to be fixed so that image.png gets displayed?

David Carlisle
  • 757,742
Christian
  • 341

1 Answers1

4

enter image description here

Remove atbegshi and background as you are using new hook code, not these legacy packages, and avoid space around / I also removed inputenc which is not needed in any format new enough to have shipout hook code.

\documentclass{book}%
\usepackage[T1]{fontenc}%

\usepackage[paperwidth=15cm,paperheight=20cm,inner=1.91cm,outer=3.09cm,top=2.186cm,bottom=3.537cm]{geometry}% \usepackage{graphicx}%

\AddToHook{shipout/background}{\put(0pt, -\paperheight) {\includegraphics[width =\paperwidth, height =\paperheight]{example-image.png}}}% % \begin{document}% x \end{document}

David Carlisle
  • 757,742
  • With that example code I get the error "! Undefined control sequence. l.2 \pgfsyspdfmark {pgfid1}{4736286}{32557310}" – Christian Jan 16 '23 at 16:42
  • just run latex again, (or delete the aux file after removing background package) @Christian – David Carlisle Jan 16 '23 at 16:44
  • @DavidCarlisle It is possible to fix the opacity of your background figure? – Raffaele Santoro Jan 16 '23 at 17:08
  • @RaffaeleSantoro well the hook just runs whatever code is supplied, the OP just used includegraphics you could adjust things using tikz or transparent packages or by adjusting the image in a bitmap editor before including – David Carlisle Jan 16 '23 at 17:13
  • @DavidCarlisle Thanks. I thinked to this but searched for a shortest way. Thanks again. – Raffaele Santoro Jan 16 '23 at 17:19
  • @RaffaeleSantoro as the image is at the back making it opaque isn't really needed, that is just a complicated way of making it lighter, I'd just edit the image before including. – David Carlisle Jan 16 '23 at 17:31