4

For a book, an Indian publisher wants me to include what they call "forma numbers" (not sure what the standard term is, if there is one) with the book name abbreviation on every sixteenth absolute page, starting from absolute page number 17, irrespective of the page style (e.g. even on a blank page which has \thispagestyle{empty}). Needless to say, these will all be recto pages, on which book chapters may begin (so the page can have no header or footer, as the first pages of my chapter have \thispagestyle{empty}). This is what I want to achieve.

  • Page 1 of the PDF: Nothing to be printed on the left in the footer
  • Page 17 of the PDF: "2 KKS" to be printed on the left in the footer
  • Page 33 of the PDF: "3 KKS" to be printed on the left in the footer
  • Page 49 of the PDF: "4 KKS" to be printed on the left in the footer
  • and so on, on every sixteenth page

On all other pages, the left side of the footer will be empty.

I figured out that I need to use \usepackage{zref-user,zref-abspage} and \arabic{abspage} to get the absolute page numbers (which start with zero).

I also figured out that I need \intcalcMod from intcalc modulo division, as pointed out here

So now I need two things

  1. Check whether \arabic{abspage} mod 16 is 0 (as \arabic{abspage} begins with 0 and not 1). This should be something like \ifthenelse{\equal{\intcalcMod{\value{abspage}}{16}}{0}}. If it is then I print \intcalcDiv{\value{abspage}}{16} and the abbreviation on the left side of the footer.
  2. This needs to override \thispagestyle{empty} which could be in force for pages on which a chapter begins.

How do I achieve (1) and (2) above?

For (1), the following works but gives the absolute page number (which is not what I want)

\fancyfoot[L]{
\ifthenelse{\equal{\intcalcMod{\value{abspage}}{16}}{0}}{\arabic{abspage} KKS}{}
}

I tried integer division with the following but it fails

\fancyfoot[L]{
\ifthenelse{\equal{\intcalcMod{\value{abspage}}{16}}{0}}{\arabic{\intcalcDiv{\value{abspage}}{16}} KKS}{}
}

For (2), I can probably redefine pagestyle{empty} to include the solution from (1).

user22209
  • 921

3 Answers3

1

Perhaps something around the lines below. The code calculates modulo of abspage and 16. The \fpeval{} provides a required mathematical function. The leftfooter{} is a auxiliary macro, which depending on the page either displays a comment (provided by an argument) or displays nothing. Then macro is fed to \fancyfoot[L]{}

\documentclass[12pt]{article}
\usepackage{zref-user,zref-abspage}
\usepackage{xfp}   % Required only before 2022-06-01 latex release
\usepackage{fancyhdr}
    \fancyhf{}
    \fancyfoot[C]{\thepage}
    \fancyfoot[L]{\leftfooter{Comment something here}}
    \renewcommand{\headrulewidth}{0pt}
    \pagestyle{fancy}
\usepackage{blindtext}

\NewDocumentCommand\leftfooter{m}{% \ifnum\theabspage>15 \ifnum\numexpr\fpeval{floor(\theabspage/16)=(\theabspage/16) ? 1 : -1}=1% #1\fi\fi}

\begin{document} \Blinddocument

\Blinddocument \end{document}

Celdor
  • 9,058
1

I would suggest an approach like this:

\documentclass{article}
\usepackage{blindtext}
\usepackage{zref-abspage}

\usepackage{fancyhdr} \pagestyle{fancy} \lfoot{\signaturemark}

\makeatletter \newcommand\signaturemark{% \makebox[0pt][l]{% \ifnum \numexpr((\zref@getcurrent{abspage}/16)*16 -1)\relax= \numexpr(\zref@getcurrent{abspage}-1)\relax \tiny\the\numexpr ((\zref@getcurrent{abspage}/16)+1)\relax ~KKS% \fi }% } \makeatother

\begin{document} \Blinddocument \Blinddocument \Blinddocument \end{document}

Ingmar
  • 6,690
  • 5
  • 26
  • 47
1

I define a \specialfooter command that checks whether abspage is positive (as explained in the documentation of zref this counter starts from 0); in this case the command checks whether abspage is a multiple of 16 and in this case it prints the quotient by 16 plus 1.

Fix the parameters for fancyhdr to your liking.

\documentclass[12pt]{book}

\usepackage[a6paper,heightrounded]{geometry} % just for more pages with less text

\usepackage{zref-user,zref-abspage} \usepackage{fancyhdr}

\usepackage{kantlipsum} % for mock text

\fancyhf{} \fancyfoot[C]{\thepage} \fancyfoot[L]{\specialfooter} \renewcommand{\headrulewidth}{0pt} % in case a chapter page is special \fancypagestyle{plain}{% \fancyhf{}% \fancyfoot[C]{\thepage}% \fancyfoot[L]{\specialfooter}% \renewcommand{\headrulewidth}{0pt}% } % for safety also the page style empty is redefined \fancypagestyle{empty}{% \fancyhf{}% \fancyfoot[L]{\specialfooter}% \renewcommand{\headrulewidth}{0pt}% } \pagestyle{fancy}

\ExplSyntaxOn \NewExpandableDocumentCommand{\specialfooter}{} { \int_compare:nT { \value{abspage} > 0 } { \int_compare:nT { \int_mod:nn { \value{abspage} } { 16 } = 0 } { \int_eval:n { \int_div_truncate:nn { \value{abspage} } { 16 } + 1 }~KKS } } } \ExplSyntaxOff

\begin{document}

\sloppy % just for the example

%\frontmatter

%\tableofcontents

\mainmatter

\chapter{First}

\kant[1-26]

\chapter{Second}

\kant[1-22]

\end{document}

enter image description here

enter image description here

enter image description here

You can check that the special footer is also present on page 33 where a chapter starts (because of \fancypagesyle{plain}).

If you uncomment the \frontmatter\tableofcontents part, you can see that the TOC takes two pages and so the special footers will be at pages 15, 31 and so on.

egreg
  • 1,121,712