QUESTION: How do I write macros that run a control sequence
\C(for example print a figure on the page or slide, a) right after the next page break (or new slide), or b) right before the next page break (or new slide)?
ANSWER: I am looking for general methods illustrated with a simple example each, to learn from. If several answers are useful, several increasing bounties. (Of course the users most likely answer the question already have enormous rep I suppose .. )
If only possible for presentations, beamer or powerdot, seeing how a new frame is a user typed control sequence in that case, that would answer the question too. Particularly interested in article class however.
Perhaps use page numbers output as proxy for pagebreak: define the macro to take the page number counter as #1, and redefine the page number printing algorithm to contain
\c at the end. Another control sequence then hides or unhides, if needed, the page numbers themselves by printing say a white square at their position?
\futurelet must be used, please suggest how to use it in a nonfragile manner! That would be an answer. (It reads the next line inside the group it's in, does nothing if new frame control sequence is not present, else expands into
\c if that is present, and so on.)
What's the point? Why not manually do it as usual? The question ultimately concerns something possibly of wide general usage, this being to construct evolving technical figure animation keyframes, that contain independent tikz figures, with automatic context specific markup and descriptions in panels as necessary. That is, instead of doing it one by one, which is tedious, at several frames per every couple seconds. Such a document can be batch extracted to .png sequences.
Consider a document whose content are series of figures generated by a foreach, such that some are, if some parameters are in sum above a threshold, displayed over not one per page but one per several frames or pages, with all permutations of variations in one particular parameter, and the certain images or text are automatically added in that case as markup.
I know: articles or various presentation classes are not intended for this: but so what? It can be done, and is rather useful I suggest. (Record audio, assemble keyframes from several such documents into video, and you've generated a particularly slick lecture!)
The reason for the question is that while the general document filling macro is straightforward, depending on the figure a series of stacked
\foreachs, it complicates rapidly with if-then sequences for corresponding floating text markup and text panels that is same across several frames, if the feature requested in this question is absent. I am not sufficiently knowledgable in core macros (but learning!) to construct this particular feature, no idea where to begin with it. Perhaps it is very easy, and I am silly to be unaware of it.