2

My requirement is printing a cookbook consisting of a set of recipes. However, there will be frequent updates of recipes and inserts of new ones. Therefore I need a solution to prevent re-printing the whole book, when only parts of it changed.

My solution draft is to handle it like some law book publishers do. They provide the book with a binding that can be opened to remove or add single pages. This way I only need to print the changed pages as well as the index.

My problem are page numbers. I search for a solution to keep page numbers steady for the inserted part and postfix them there, e.g., 21a, 21b. Is there any possibility to do that? I'm completely out of ideas where even to start searching for such a solution.

(By the way: I am not fixed on my solution above. If anyone has a better idea to handle frequently changing large documents for print, I'd be glad to hear it.)

Boldewyn
  • 123
  • 3
    if you were a BASIC programmer from the 1970s you would address this problem by numbering the pages 100,200,300.. then inserts after page 100: 110,120,... and inserts on inserts after page 120: 121,122,... – David Carlisle Apr 26 '17 at 06:57
  • Too young for that, sorry. When I started with programming, my faculty had already switched to FORTRAN 90... – Boldewyn Apr 26 '17 at 07:39
  • If one of the provided answers is satisfying you might accept it. If not, you should further specify your question. – Skillmon Apr 26 '17 at 15:41
  • Yes, I will do so, thanks for the reminder. I just didn't have the opportunity to try them, yet. – Boldewyn Apr 26 '17 at 15:59
  • @DavidCarlisle: I had to laugh reading your comment. I was a BASIC programmer – and frequently use exactly this approach to number overlay steps on complex beamer frames :-) – Daniel Apr 26 '17 at 21:56

2 Answers2

4

As you don't want to change the page numbers, I suggest making the page numbers depend upon the recipes. For example, the pages of the Carrot cake recipe could be numbered CC1, CC2, and so on -- although most recipes would probably fit on one page? You could make the "page number prefix" depend on the recipe, like this, or instead assign it in some sensible way.

The pages in the book would appear in lexicographic order, making it easy to insert new pages and finding the page that you were after.

Here is one way to implement this idea:

\documentclass{book}
\usepackage{xparse}
\usepackage{blindtext}

\let\realchapter\chapter% save the definition of \chapter for later use
\def\pageprefix{}% prefix for page numbers
\renewcommand\thepage{\pageprefix\arabic{page}}

%\chapter<page prefix>[short title]{title}
\RenewDocumentCommand\chapter{ r<> o m }{%
    \IfNoValueTF{#2}{\realchapter{#3}}%   without short title
                  {\realchapter[#2]{#3}}% with    short title
    \def\pageprefix{#1}\setcounter{page}{1}% reset page counter
}

\begin{document}

    \chapter<Pan>{Pancakes}
    \Blindtext

    \chapter<Om>{Omelettes}
    \Blindtext

    \chapter<CC>{Carrot cake}
    \Blindtext

\end{document}

So the \chapter command now has a mandatory argument that sets the page prefix. The syntax is:

\chapter<page prefix>[short title]{title}

As is the case with the \chapter command, the short title is optional and can be omitted.

Another variation on this idea would be to label the pages as aaa, aab, aac, ..., bba, bbb, bbc,... Again, this would be easy to do using the code above, by replacing the re-definition of \thepage by

\renewcommand\thepage{\pageprefix\alph{page}}
  • I really like the idea! Automatic sorting of the chapters would make it perfect (and would really interest me, as I have no idea how to implement it nicely). – Skillmon Apr 26 '17 at 07:46
  • @Skillmon I thought that the original question was just about page numbering, so automatic sorting is probably a different question:) How were you envisaging writing/typing the book? How are new recipes added? Should they all go in the same file? Are you suggesting the new recipes are just added to the end of some file and that they should be magically sorted for printing? Some details like this would be helpful. –  Apr 26 '17 at 07:52
  • @Skillmon I think that you probably want to "sort" the recipes by hand when you add new ones, as a latex solution would be too inefficient especially if the recipes are to have "complicated" formatting. Rereading your question, what you might want to do however, is add a "date" to each recipe and make it possible to print out only those recipes added before or after a certain date, or for a range of dates. This isn't so hard to do. If this interests you then please add some more details to the question - the more detail the better! –  Apr 26 '17 at 08:10
  • I'm not the original poster, but provided an answer to this question. Then I saw your answer and you said something about lexicographic order and I was just interested how to implement that. I asked just out of curiosity and do realize that this is another question, but I won't ask it. Maybe the OP if he is interested in it will ask that :) – Skillmon Apr 26 '17 at 08:59
  • @Skillmon Sorry, I should learn to read! :) By "lexicographic order" I meant simply that the reader of the recipe book could use it to navigate the pages numbers. –  Apr 26 '17 at 09:21
  • 2
    I want to bake a Chocolate Cake... So CC1 does lead me to Carrot Cake or to Chocolate Cake? ;-) –  Apr 26 '17 at 20:19
  • Thanks for the answer and the idea! Christian has a point, but I'm sure playing with the name schema could be a worthwhile path. (E.g., prefixing with recipe categories like "soup", "dessert", ...) For my current task however, Skillmon's answer works like intended. – Boldewyn Apr 27 '17 at 20:14
3

To change the numbers in a range you might do the following (I don't guarantee that this would not break things):

EDIT: I made the environment nestable. Also I changed the page numbers from \alph to \roman to allow more than 26 subpages.

\documentclass[]{article}

\usepackage{blindtext}

\makeatletter
\newcount\@subpagescount%
\newenvironment{subpages}{%
    \edef\@subpagesprefix{\thepage}%
    \@subpagescount=\c@page%
    \clearpage%
    \edef\thepage{\@subpagesprefix.\noexpand\roman{page}}%
    \setcounter{page}{1}%
}{\clearpage\setcounter{page}{\numexpr\@subpagescount+1}}
\makeatother

\begin{document}
\setcounter{page}{21}
\blindtext

\begin{subpages}
    First page in not nested \texttt{subpages}
    \clearpage
    Second page in not nested \texttt{subpages}
    \begin{subpages}
        \setcounter{page}{26}
        First page in nested \texttt{subpages}
        \clearpage
        Second page in nested \texttt{subpages}
    \end{subpages}
    After the nested \texttt{subpages}
\end{subpages}

\blindtext
\end{document}
Skillmon
  • 60,462