Page LayoutExecution of Command depending on Page Number

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
Post Reply
amygdala
Posts: 2
Joined: Sat Oct 20, 2012 12:08 am

Execution of Command depending on Page Number

Post by amygdala »

How do I run a LaTeX command once on condition that the page is not the first page?

I want to execute the command \ClearShipoutPicture on the second page of a latex letter class document. What I need is something like this:

if page reference = 2, then \ClearShipoutPicture

I am a complete LaTeX noob and don't know the first thing about conditional statements or I might be able to self research this issue.

I need a letterhead to appear on the first page of a letter and not on successive pages. I know there are a lot of different ways to do this. The way I'm doing it is to have a PDF document with just the letterhead on it and using that as a background with the eso-pic package.

The code to create a PDF background is (according to {TeX} SX):

Code: Select all

\newcommand\BackgroundPicFront{
    \put(0,0){
        \parbox[b][\paperheight]{\paperwidth}{
            \vfill
            \centering
            \includegraphics[width=\paperwidth,height=\paperheight,keepaspectratio]{/usr/share/data/in_squalus/files/office/LATEX_TEMPLATES/letter-hdr.pdf}%
            \vfill
        }
    }
}
You call this macro with the code:

Code: Select all

\AddToShipoutPicture{\BackgroundPicFront}
.

To remove the PDF background, you use the command:

Code: Select all

\ClearShipoutPicture
These on and off codes are easy to use when you have manual page breaking, but with the letter class, for example, you don't know where the page breaks are until you print it.

I currently have to generate a PDF document, view where the page breaks occur, and then insert the \ClearShipoutPicture command at some place in the document after the first page break in order to turn off the PDF background after the first page. This is not an elegant solution. If I could automatically have the command run during the build using conditional command execution, then I wouldn't have to fuzz with the letterhead placement on each letter.

thanks

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Post Reply