How to put signature number in footer (derived from page number)?

To make my book easier to bind I'd like to automatically put the signature number with small type in the footer of the first page of each octavo signature (except the first one which is given since it has the title page).

So that means I want to do this:

If
(page number) == ( [some number that is evenly dividable with 16] + 1 )
then
write "Book title --- ( ( [page number]-1 ) / 16)"
with small type in the footer of the page

• How can this be achieved in Context?
• How can this be achieved in Plain Tex?

Happy for any pointers or examples. Thanks!

-
Actually the number printed should really be "( ( ( [page number]-1 ) / 16)+1 )" to print the correct signature number. The above example and below answers prints the number of the signature before ... But his is easily corrected by adding 1 to the calculated number before printing it. –  PetaspeedBeaver Apr 3 '13 at 11:05

Plain tex version (using e-tex arithmetic could be written in classic tex if needed)

\vsize 4\baselineskip
\hsize 5cm
\pdfpageheight\dimexpr6\baselineskip+2in\relax
\pdfpagewidth\dimexpr\hsize+2in\relax

\footline={
\hss\tenrm
[original plain footer: \folio]
\ifnum\numexpr ((\pageno-1)/16)*16\relax=\numexpr\pageno-1\relax
{\fiverm
[The title
(page \the\pageno)
signature \the\numexpr ((\pageno-1)/16)+1\relax]
}\fi
\hss
}

\raggedright\raggedbottom
\def\a{Red yellow blue green }
\def\b{\a\a\par\a\a\a\par}
\def\c{One two three four \a\a\a five six seven\par}
\def\d{\c\c\c\c\par\a\b\c\a\a\b\b\c\c\a\b\c\c}

\d\d

\bye

-
@PetaspeedBeaver updated –  David Carlisle Apr 2 '13 at 11:18

Here is one way to do this in ConTeXt:

% Set footnotes in small size
\setupfooter[style=small]

% Determine footnote content based on lua code
\setupfootertexts[\luasetup{footer}]

% Get the page number. If page % 16 == 1, typeset content
\startluasetups footer
local counters = structures.counters

local page = counters.value("userpage")
local signature
if page > 1 and page % 16 == 1 then
signature = (page - 1)/16
context("Book title (%s)", signature)
end
\stopluasetups

% Example
\starttext
\dorecurse{60}{\input knuth \page}
\stoptext

-