I need to define a macro or do some special action every time a new page is encountered. In some sense I want to "number" tikzpictures but have all the tikzpictures on the same page contain the same number. (It's more complex than this but it is just a simple example)
Basically all I want to do is define a macro at the start of every new page. I'll use that macro to in my tikzpictures to do some special things and they may delete the macro depending on something(which is why I need to set it on each new page so it get's reset each page).
The macro needs to be defined at the start of every new page before any tex in my document is executed.
Basically I want to avoid having to add the macro in the document myself for each new page(which is hard to control and clutters up the thing).
My case: I have several tikspictures scattered throughout my document but some are on the same page.
I want the first one on the page to have special treatment(like put a caption on it). BUT I may add or remove text which may change the ordering and I don't want to have to update the code.
-New Page Text Img1 * Img2 -New Page Img3 * Text Img4 Img5 -New Page Img6 *
Because Img 1 3 and 6 are the first on the page I want to do something to them. BUT I do not want to hard code this because it may easily change(when I add text it may push put some images on a new page, i.e.,
-New Page Text Img1 * -New Page Img2 Img3 * Text Img4 -New Page Img5 Img6 *
and notice how * does not correspond to the first image on the page(like I want it). i.e., this is what will happen if you hard code the things I want to do.
Also, Because tex first has to calculate image bbox to determine if it is on the current page or not I need code that will work since my images will depend on if they are the first image on the page or not.
My "Special" action is only horizontally centering the image and so shouldn't effect layout.
The issue stems from
and I'm trying to streamline and automate the process. I need to apply the master and slave pattern in the way I have describe. The first image on the page should get the master style and the remaining should get the slave BUT not hard coded since it causes the problem I gave above.
(Note how Jake's answer has hard coded master and slave. This causes major problems if you add text which pushes some images on a new page. (since the first image on the page should be master but by hard coded it you could get a slave as the first image)