如何实际引用代码中的罗马数字页面以将背景图像 AddToHook 到第 ii 页而不是第 2 页

如何实际引用代码中的罗马数字页面以将背景图像 AddToHook 到第 ii 页而不是第 2 页

我需要向特定页面添加背景图像。以下是 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 Title Page和之间的页面之一the Main Document。它们以罗马数字编号,所以我想要的图像所在的页面实际上page ii不是page 2。因此,使用上述代码,图像最终被放置在page 2主文档上,而主文档当然是用阿拉伯数字编号的。
那么我如何在 Tex 代码中实际引用罗马数字编号的页面,特别是在AddToHook我上面提到的代码中?我如何让 Tex 知道我想要我的图像在page ii而不是 上page 2

答案1

您必须将扩展\thepage与所需的字符串进行比较,例如:

\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}

或者使用稍微修改过的示例版本:

% !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}

注意:我删除了几个\pagenumering命令,因为如果您将\frontmatter和移到\mainmatter正确的位置,这些命令已经改变了编号样式。我还替换了您的\pagenumbering{gobble},因为这样,您就没有罗马页码,也没有现有的页码。

但是,由于您尚未将钩子代码放入文档前言中。有一种更简单的方法,使用包eso-pic及其一次性的 add-to-hook 命令:

% !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}

这也适用于\pagenumbering{gobble},因为它不依赖于页码或页码样式。

相关内容