2

I need to produce a series of book and the typography asked me to provide documents with the total number of pages multiple of 16. I tried to follow this answer How to ensure document total page numbers is a multiple of four?, using the example working with \frontmatter and \mainmatter, but I am not able to modify it to output multiple of 16. Any advice?

EDIT: for convenience, full code below:

\usepackage{xparse}
\usepackage{refcount,lastpage,etoolbox}
\usepackage{kantlipsum}

\makeatletter
\patchcmd\mainmatter{\cleardoublepage}
  {%
   \clearpage\edef\@currentlabel{\number\numexpr\arabic{page}\ifodd\arabic{page}+1\fi\relax}%
   \label{LastFrontmatterPage}%
   \cleardoublepage
  }{}{}
\makeatother

\ExplSyntaxOn
\cs_new:Npn \egreg_int_coremainder:nn #1 #2
 {
  \int_mod:nn { #2 - \int_mod:nn { #1 } { #2 } } { #2 }
 }
\NewDocumentCommand{\checkmultipleoffour} { O{0} }
 {
  \prg_replicate:nn
   {
    \egreg_int_coremainder:nn { #1 + \getrefnumber{LastFrontmatterPage} + \getpagerefnumber{LastPage} } { 4 }
   }
   { \thispagestyle{empty}\null\clearpage }
 }
\ExplSyntaxOff
\AtEndDocument{\checkmultipleoffour}
Marco
  • 105
  • Welcome to TeX SX! Wouldn't it be for an in-octavo printing? – Bernard Sep 01 '15 at 11:31
  • Thank you, Bernard! Yes, I did not know the right word in english, sorry! – Marco Sep 01 '15 at 11:41
  • Using the cited answer, and changing the three instances of 4 to 16 seems to work fine for me. – Steven B. Segletes Sep 01 '15 at 12:00
  • Yes, I tried and it works. But if you have a document with frontmatter and mainmatter, for what I understand, you have to use the last example, which I am not able to modify to work with 16. – Marco Sep 01 '15 at 12:13
  • OK, but when I use egreg's last example, changing the one instance of 4 to 16, it also seems to work. – Steven B. Segletes Sep 01 '15 at 12:33
  • If I change 4 into 16, I get what's required. Note that you need two LaTeX runs for the \label-\ref system to get synchronized. I added a note. – egreg Sep 01 '15 at 12:40
  • Thanks to everybody for help. Using the minimal working example it works perfectly but, it's strange, on my document I am not able to make it work.. – Marco Sep 01 '15 at 12:46
  • 1
    SOLVED! It was, of course, my mistake. I positioned \frontmatter after the title page and the toc, so the calculations made were not correct. – Marco Sep 01 '15 at 12:52

0 Answers0