0

I need to add a background image to a specific page. Here's the MWE:

% !TEX TS-program = LuaLaTeX
\documentclass[11pt,twoside,openany]{book}
\pagestyle{plain}

\usepackage[english, russian]{babel}
\usepackage{fontspec}
\setmainfont{EB Garamond}[
]

\usepackage{microtype}
\usepackage[shortcuts]{extdash} 
\usepackage[pagewise]{lineno}
\usepackage[
  paperwidth=6in,
  paperheight=9in,
  inner=15mm,
  top=15mm,
  outer=20mm,
  bottom=24mm, 
  heightrounded 
]{geometry} 

\setlength{\parskip}{0ex} 
\usepackage{graphicx}
\usepackage[dvipsnames]{xcolor}

\usepackage{mwe} %___YOUR PACKAGE FOR ROMAN NUMERALS


\usepackage{fancyhdr}
\fancyhf{} 
\renewcommand{\headrulewidth}{0ex} 
\fancyfoot[LE,RO]{\thepage} 
\pagestyle{fancy}
\fancypagestyle{plain}{%
  \fancyhf{}%
  \renewcommand{\headrulewidth}{0ex}%
  \fancyhf[lef,rof]{\thepage}%
}

\begin{document}

\pagestyle{plain}
\pagenumbering{roman}

\pagenumbering{gobble} %___WHEN USED, HIDES THE ROMAN NUMBERS BUT PREVENTS THE REFERRAL FROM WORKING
\addtocounter{page}{-4}


\vspace*{0ex}  
\begin{center}
{\fontsize{5ex}{5ex}\selectfont\bfseries\raggedleft\textcolor{Black} {BLANK PAGE}\par}
\end{center}
\vspace*{10ex} 
\begin{center}
{\fontsize{2ex}{2ex}\selectfont\bfseries\raggedleft\textcolor{Black} {do not print}\par}
\end{center}
\clearpage


\vspace*{0ex}  
\begin{center}
{\fontsize{5ex}{5ex}\selectfont\bfseries\raggedleft\textcolor{Black} {PRE-TITLE PAGE1}\par}
\end{center}
\clearpage


\vspace*{0ex}  
\begin{center}
{\fontsize{5ex}{5ex}\selectfont\bfseries\raggedleft\textcolor{Black} {PRE-TITLE PAGE2}\par}
\end{center}
\clearpage


\vspace*{0ex}  
\begin{center}
{\fontsize{5ex}{5ex}\selectfont\bfseries\raggedleft\textcolor{Black} {PRE-TITLE PAGE3}\par}
\end{center}
\clearpage

    
\begin{titlepage}
    \begin{center}
        {\fontsize{20ex}{20ex}\selectfont\bfseries\textcolor{Black} {TITLE PAGE}\par}
\end{center}
\end{titlepage}
\clearpage


\vspace*{16ex} 
\begin{center}
{\fontsize{5ex}{5ex}\selectfont\bfseries\textcolor{Black} {POST-TITLE PAGE1}\par}
\end{center} 
\ExplSyntaxOn %___YOUR CODE FOR ROMAN PAGE REFERRAL
\AddToHook{shipout/background}{%
  \put(0mm,-240mm){\str_if_eq:eeT{\thepage}{ii}{\includegraphics[width=200mm,height=250mm,keepaspectratio]{example-image}}}}
\ExplSyntaxOff
\clearpage


\vspace*{16ex} 
\begin{center}
{\fontsize{5ex}{5ex}\selectfont\bfseries\textcolor{Black} {POST-TITLE PAGE2}\par}
\end{center} 
\clearpage


\vspace*{16ex} 
\begin{center}
{\fontsize{5ex}{5ex}\selectfont\bfseries\textcolor{Black} {POST-TITLE PAGE3}\par}
\end{center} 
\clearpage


\vspace*{16ex} 
\begin{center}
{\fontsize{5ex}{5ex}\selectfont\bfseries\textcolor{Black} {POST-TITLE PAGE4}\par}
\end{center} 
\clearpage


\vspace*{16ex} 
\begin{center}
{\fontsize{5ex}{5ex}\selectfont\bfseries\textcolor{Black} {POST-TITLE PAGE5}\par}
\end{center} 
\clearpage

\frontmatter


\mainmatter

\pagenumbering{arabic}

Main document text 

\clearpage
  \end{document}

The problem is that the page I want the background image on is one of those pages between the Title Page and the Main Document. They are numerated in Roman numerals so the page I want the image on is actually page ii NOT page 2. So with the above code the image ends up being placed on page 2 of the main document which is of course numerated in Arabic.
So how do I actually refer to the Roman numbered page in Tex code, specifically in AddToHook code I mentioned above? How do I let the Tex know that I want my image on page ii and NOT page 2?

2
  • Please always show a minimal working example not only a code snippet. Doing so makes things clearer and easier for everybody.
    – cabohah
    Nov 4, 2022 at 13:11
  • I updated the original Q with the MWE.
    – tryingout
    Nov 4, 2022 at 13:42

1 Answer 1

2

You have to compare expansion of \thepage with the wanted string, e.g.:

\documentclass{article}
\usepackage{mwe}
\ExplSyntaxOn
\AddToHook{shipout/background}{%
  \put(0mm,-240mm){\str_if_eq:eeT{\thepage}{ii}{\includegraphics[width=200mm]{example-image}}}}
\ExplSyntaxOff

\begin{document}
\pagenumbering{roman}
\Blindtext[10]
\cleardoublepage
\pagenumbering{arabic}
\Blindtext[10]
\end{document}

Or with a slightly modified version of your example:

% !TEX TS-program = LuaLaTeX
\documentclass[11pt,twoside,openany]{book}
\pagestyle{plain}

\usepackage[english, russian]{babel}
\usepackage{fontspec}
\setmainfont{EB Garamond}[
]

\usepackage{microtype}
\usepackage[shortcuts]{extdash} 
\usepackage[pagewise]{lineno}
\usepackage[
  paperwidth=6in,
  paperheight=9in,
  inner=15mm,
  top=15mm,
  outer=20mm,
  bottom=24mm, 
  heightrounded 
]{geometry} 

\setlength{\parskip}{0ex}
\usepackage{graphicx}
\usepackage[dvipsnames]{xcolor}

\usepackage{mwe} %___YOUR PACKAGE FOR ROMAN NUMERALS


\usepackage{fancyhdr}
\fancyhf{} 
\renewcommand{\headrulewidth}{0ex} 
\fancyfoot[LE,RO]{\thepage} 
\pagestyle{fancy}
\fancypagestyle{plain}{%
  \fancyhf{}%
  \renewcommand{\headrulewidth}{0ex}%
  \fancyhf[lef,rof]{\thepage}%
}

\begin{document}

\frontmatter
\pagestyle{empty}
\setcounter{page}{-4}% strange!

\vspace*{0ex}  
\begin{center}
{\fontsize{5ex}{5ex}\selectfont\bfseries\raggedleft\textcolor{Black} {BLANK PAGE}\par}
\end{center}
\vspace*{10ex} 
\begin{center}
{\fontsize{2ex}{2ex}\selectfont\bfseries\raggedleft\textcolor{Black} {do not print}\par}
\end{center}
\clearpage


\vspace*{0ex}  
\begin{center}
{\fontsize{5ex}{5ex}\selectfont\bfseries\raggedleft\textcolor{Black} {PRE-TITLE PAGE1}\par}
\end{center}
\clearpage


\vspace*{0ex}  
\begin{center}
{\fontsize{5ex}{5ex}\selectfont\bfseries\raggedleft\textcolor{Black} {PRE-TITLE PAGE2}\par}
\end{center}
\clearpage


\vspace*{0ex}  
\begin{center}
{\fontsize{5ex}{5ex}\selectfont\bfseries\raggedleft\textcolor{Black} {PRE-TITLE PAGE3}\par}
\end{center}
\clearpage

\ExplSyntaxOn
\AddToHook{shipout/background}{%
  \put(0mm,-240mm){\str_if_eq:eeT{\thepage}{ii}{\includegraphics[width=200mm]{example-image}}}}
\ExplSyntaxOff
    
\begin{titlepage}% Note: titlepage also resets page counter!
  \centering
  \fontsize{20ex}{20ex}\selectfont\bfseries\textcolor{Black} {TITLE PAGE}\par
\end{titlepage}
\clearpage


\vspace*{16ex} 
\begin{center}
{\fontsize{5ex}{5ex}\selectfont\bfseries\textcolor{Black} {POST-TITLE PAGE1}\par}
\end{center} 
\clearpage


\vspace*{16ex} 
\begin{center}
{\fontsize{5ex}{5ex}\selectfont\bfseries\textcolor{Black} {POST-TITLE PAGE2}\par}
\end{center} 
\clearpage


\vspace*{16ex} 
\begin{center}
{\fontsize{5ex}{5ex}\selectfont\bfseries\textcolor{Black} {POST-TITLE PAGE3}\par}
\end{center} 
\clearpage


\vspace*{16ex} 
\begin{center}
{\fontsize{5ex}{5ex}\selectfont\bfseries\textcolor{Black} {POST-TITLE PAGE4}\par}
\end{center} 
\clearpage


\vspace*{16ex} 
\begin{center}
{\fontsize{5ex}{5ex}\selectfont\bfseries\textcolor{Black} {POST-TITLE PAGE5}\par}
\end{center} 
\clearpage

\mainmatter

\pagestyle{plain}% or \pagestyle{fancy}?

Main document text 

\clearpage
\end{document}

Note: I've removed several of your \pagenumering commands, because if you move the \frontmatter and \mainmatter to the correct places, these commands already change the numbering style. I've also replaced your \pagenumbering{gobble}, because with this, you do not have roman page numbers, but not existing page numbers.

However, because you already do not place the hook code into the document preamble. There is a easier method using package eso-pic and it's one-time add-to-hook command:

% !TEX TS-program = LuaLaTeX
\documentclass[11pt,twoside,openany]{book}
\pagestyle{plain}

\usepackage[english, russian]{babel}
\usepackage{fontspec}
\setmainfont{EB Garamond}[
]

\usepackage{microtype}
\usepackage[shortcuts]{extdash} 
\usepackage[pagewise]{lineno}
\usepackage[
  paperwidth=6in,
  paperheight=9in,
  inner=15mm,
  top=15mm,
  outer=20mm,
  bottom=24mm, 
  heightrounded 
]{geometry} 

\setlength{\parskip}{0ex}
\usepackage{graphicx}
\usepackage[dvipsnames]{xcolor}

\usepackage{mwe} %___YOUR PACKAGE FOR ROMAN NUMERALS

\usepackage{eso-pic}

\usepackage{fancyhdr}
\fancyhf{} 
\renewcommand{\headrulewidth}{0ex} 
\fancyfoot[LE,RO]{\thepage} 
\pagestyle{fancy}
\fancypagestyle{plain}{%
  \fancyhf{}%
  \renewcommand{\headrulewidth}{0ex}%
  \fancyhf[lef,rof]{\thepage}%
}

\begin{document}

\frontmatter
\pagestyle{empty}
\setcounter{page}{-4}% strange!

\vspace*{0ex}  
\begin{center}
{\fontsize{5ex}{5ex}\selectfont\bfseries\raggedleft\textcolor{Black} {BLANK PAGE}\par}
\end{center}
\vspace*{10ex} 
\begin{center}
{\fontsize{2ex}{2ex}\selectfont\bfseries\raggedleft\textcolor{Black} {do not print}\par}
\end{center}
\clearpage


\vspace*{0ex}  
\begin{center}
{\fontsize{5ex}{5ex}\selectfont\bfseries\raggedleft\textcolor{Black} {PRE-TITLE PAGE1}\par}
\end{center}
\clearpage


\vspace*{0ex}  
\begin{center}
{\fontsize{5ex}{5ex}\selectfont\bfseries\raggedleft\textcolor{Black} {PRE-TITLE PAGE2}\par}
\end{center}
\clearpage


\vspace*{0ex}  
\begin{center}
{\fontsize{5ex}{5ex}\selectfont\bfseries\raggedleft\textcolor{Black} {PRE-TITLE PAGE3}\par}
\end{center}
\clearpage

 
\begin{titlepage}% Note: titlepage also resets page counter!
  \centering
  \fontsize{20ex}{20ex}\selectfont\bfseries\textcolor{Black} {TITLE PAGE}\par
\end{titlepage}
\clearpage

\AddToShipoutPicture*{%
  \AtPageLowerLeft{%
    \includegraphics[width=200mm]{example-image}%
  }
}

\vspace*{16ex} 
\begin{center}
{\fontsize{5ex}{5ex}\selectfont\bfseries\textcolor{Black} {POST-TITLE PAGE1}\par}
\end{center} 
\clearpage


\vspace*{16ex} 
\begin{center}
{\fontsize{5ex}{5ex}\selectfont\bfseries\textcolor{Black} {POST-TITLE PAGE2}\par}
\end{center} 
\clearpage


\vspace*{16ex} 
\begin{center}
{\fontsize{5ex}{5ex}\selectfont\bfseries\textcolor{Black} {POST-TITLE PAGE3}\par}
\end{center} 
\clearpage


\vspace*{16ex} 
\begin{center}
{\fontsize{5ex}{5ex}\selectfont\bfseries\textcolor{Black} {POST-TITLE PAGE4}\par}
\end{center} 
\clearpage


\vspace*{16ex} 
\begin{center}
{\fontsize{5ex}{5ex}\selectfont\bfseries\textcolor{Black} {POST-TITLE PAGE5}\par}
\end{center} 
\clearpage

\mainmatter

\pagestyle{plain}% or \pagestyle{fancy}?

Main document text 

\clearpage
\end{document}

This would also work with \pagenumbering{gobble}, because it does not depend on page numbers or page numbering style.

7
  • I updated the original Q with the MWE. Your code works BUT only if \pagenumbering{gobble} is suppressed. Since I don't want the roman numbers to be visible I need that code to stay active. But when it's active, your code stops working.
    – tryingout
    Nov 4, 2022 at 13:42
  • @tryingout With \pagenumbering{gobble} you do not have roman page numbers, but invisible (gobbled) page numbers. This is something completely different. I recommend to remove the \pagenumbering{gobble} and use \pagestyle{empty} instead. And where you are currently using \pagenumbering{arabic} just add \pagestyle{plain} or \pagestyle{fancy}.
    – cabohah
    Nov 4, 2022 at 14:08
  • Hm?! So is there a way to refer the code to a gobbled page number? Or should I rephrase the very question?
    – tryingout
    Nov 4, 2022 at 14:12
  • @tryingout See my two newly added alternatives for doing it.
    – cabohah
    Nov 4, 2022 at 14:25
  • Your solution with \usepackage{eso-pic} works perfectly! However is there a way to specify the exact location of the image? Instead of \AtPageLowerLeft use something like \put(0mm,-240mm) as I did in my original code?
    – tryingout
    Nov 4, 2022 at 16:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .