Introduction
LaTeX has long been my main typesetting environment. This post has some handy dandy codes that I daily use.
Embedding a PDF File within
The following command
is used in the document
environment and embeds the specified PDF
file.
\portitem
{} % title
{./path-to/file.pdf} % file name
{n} % n = page number + 1
To achieve a clean layout, remove headers and footers in file.pdf
. Typically, outer PDF
will carry out its headers and footers. This approach also provides a seamless integration.
Command in preamble:
\newcommand{\portitem}[3]{
\phantomsection \addcontentsline{toc}{section}{#1} % toc entry
\rhead{\textsc{#1}}
\setcounter{pg}{1}
\whiledo{\value{pg}<#3}{ % page number +1
\includepdf[pages=\thepg,scale=1,pagecommand={\pagestyle{fancy}}]{#2} % file name
\addtocounter{pg}{1}
}
}
Package dependencies in preamble:
\usepackage{pdfpages}
\usepackage{ifthen}
\newcounter{pg}
Stamping Unique IDs
Often I print out documents with multiple copies. When it comes to exams, usually I scan the documents and do my grading electronically. Having unique IDs on every copy printed provides better file handling in this process.
\documentclass[letterpaper,10pt]{article}
\usepackage{pdfpages}
\usepackage{fancyhdr}
\usepackage{color}
\usepackage{multido}
% What is the starting number?
\def\startnumber{1}
% How many exams do we need?
\def\numberofexams{90}
% Which is the input PDF file?
\def\examfile{CHEM111-lab-manuals-2022-08-25}
% This is to control the placement of the number.
\textwidth 440pt
\textheight 590pt
% We use headers to output the serial number
\pagestyle{fancy}
\renewcommand{\headrulewidth}{0pt} % No header line
\renewcommand{\footrulewidth}{0pt} % No footer line
\cfoot{}
% Actual command to include the serial number
\rfoot{\Huge\textcolor{gray!25}{\textsf{%
% Some number padding - for up to 999 exams
\ifnum\numberexam<100 0\fi%
\ifnum\numberexam<10 0\fi%
\numberexam}
}}
% And here comes the single loop across all documents
% pagecommand by itself adds nothing,
% but causes our new headers and footers to be printed
\begin{document}
\multido{\numberexam=\startnumber+1}{\numberofexams}{%
\includepdf[pages=-,pagecommand=\strut]{\examfile}
}
\end{document}