2

I'm working with a book, and I'd like to change an arbitrary page number from arabic to alph without relying on any markers or references in the document's text. I have no clue where to start. This question is similar, I think, but I wasn't able to translate any of those solutions to my issue.

In the MWE below, I'd like to change the page number "3" in the main matter to "three", while leaving all of the other page numbers as-is.

\documentclass{book}
\usepackage[english]{babel}
\usepackage{blindtext}

\begin{document}

\frontmatter
\blinddocument

\mainmatter
\blinddocument

\end{document}

So the final page counts in the main matter would be would be (1, 2, three, 4).

UPDATE: I realized that in my simple example I (foolishly) didn't specify how the pages were stylized, and it makes the implementation a bit trickier. I went ahead with Christian's suggestion not to change any \the... macros -- even though I found Henri's solution to be more straightforward to implement -- because I'm using a table of contents. My original code was:

\RequirePackage[markcase=used]{scrlayer-scrpage}
\providepairofpagestyles{mystyle}{%
    \clearpairofpagestyles%
    \automark[chapter]{chapter}
    \ihead{\headmark}
    \ohead[\pagemark]{\pagemark}
}

Updated to:

\def\targetpage{3}
\def\pagestring{\numberstringnum{\targetpage}}

\RequirePackage[markcase=used]{scrlayer-scrpage}
\providepairofpagestyles{mystyle}{%
    \clearpairofpagestyles%
    \automark[chapter]{chapter}
    \ihead{\headmark}
    \ohead[\ifnum\value{page}=\targetpage\pagestring\else\thepage\fi]{\ifnum\value{page}=\targetpage\pagestring\else\thepage\fi}
} 

There are probably better ways to do this, but it seems to work!

2
  • Welcome to TeX.SE. Why would one want to use such a 'numbering'?
    – user31729
    Commented Jul 10, 2017 at 23:34
  • It's for a personal project that I'm working on; I like look of spelled-out page numbers, but I'd only like to do this for certain numbers. I thought this would be a pretty simple tweak to my document but I've been trying to figure this out for a few hours to no avail.
    – Brad
    Commented Jul 10, 2017 at 23:43

2 Answers 2

1

This assumes the plain pagestyle to be applied after \mainmatter and checks whether the page number is equal to some predefined number, say 3, and applies the \numberstringnum macro then.

\documentclass{book}
\usepackage[english]{babel}

\usepackage{fmtcount}
\usepackage{fancyhdr}
\usepackage{blindtext}

\def\theliteralpage{3}

\fancypagestyle{plain}{%
  \fancyhf{}
  \renewcommand{\headrulewidth}{0pt}
  \cfoot{\ifnum\theliteralpage=\value{page}\numberstringnum{\theliteralpage}\else\thepage\fi}
}

\begin{document}
\frontmatter
\blinddocument

\mainmatter
\pagestyle{plain}
\blinddocument

\end{document}

enter image description here

1

You can redefine \thepage to print in the desired format. The \mainmatter command redefines \thepage as well, so you have to place the redefiniton after that.

\documentclass{book}
\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage{fmtcount}
\begin{document}

\frontmatter
\blinddocument

\mainmatter
\renewcommand\thepage{%
  \ifnum\value{page}=3
    \numberstring{page}%
  \else
    \arabic{page}%
  \fi}

\blinddocument

\end{document}
1
  • Some LaTeX gurus always recommend to prevent redefinitions of \the... macros in order to perform something more than non-standard formatting. Here, three would enter the ToC as well (if there's a ToC), for example
    – user31729
    Commented Jul 11, 2017 at 0:20

You must log in to answer this question.

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