# Bates numbering of multiple pdfs with label reference to the page numbers

I really didn't think this was even possible until I came across, cross-referencing-to-included-pdf-with-counter-and-argument-in-the-label, reading that post gave me some hope.

I have a document, where the text will include references to a Bates numbered record, to be cited like this:

I really think that x proves y. [R page 132]

The problem I have is that my record consists of many pdf files, and some may be added, after I have started to draft references to that record.

The code I would like to modify, from the referenced post, is below:

\documentclass[12pt,a4paper,fleqn,parskip=half]{scrartcl}

\usepackage{lscape}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[demo]{graphicx}
\usepackage[scaled]{helvet}
\usepackage{caption}
\usepackage{xargs}

%---------------------------------------------------------------------
%   % Macro to find the number of pages of included PDF document
%---------------------------------------------------------------------
\makeatletter
\newcounter{imagepage}
\newcommand*{\foreachpage}[2]{
\begingroup
\sbox0{\includegraphics{#1}}
\xdef\foreachpage@num{\the\pdflastximagepages}
\endgroup
\setcounter{imagepage}{0}
\@whilenum\value{imagepage}<\foreachpage@num\do{%
\stepcounter{imagepage}
#2\relax
}
}
\makeatother

%---------------------------------------------------------------------
%   % Macro to include PDF document with page numbers in caption and label
%---------------------------------------------------------------------
\makeatletter
\newcommandx{\picTEST}[5][1=0.9, 2=0]
{
\foreachpage{#4}
{
\begin{figure}[h!]
\centering
\makebox[\textwidth]{\includegraphics[width=#1\hsize,page=\value{imagepage},angle=#2]{#4}}
\caption{#5 - Page \arabic{imagepage} of {\the\pdflastximagepages}}
\label{#3\theimagepage}
\end{figure}
\clearpage
}
}
\makeatother

\begin{document}

\section{Some Text}
Here is reference to page \ref{Document1_Label_Page3} of the included PDF document.

\newpage
\section{Some insert of PDF document}
\picTEST{Document1_Label_Page}{quickcode.pdf}{Document1}

\end{document}


The above referenced code could be used for this if:

1. Multiple pdfs can be output as "bates" numbering across the entire set of pdfs. For instance for two 10 page pdf documents the first pdf document is numbered 1-10, the second numbered 11-20 etc.

2. The word "figure" could be replaced with the word "record" and the printing of the pdf filename completely supressed.

3. The pdf produced could be bigger and centered instead of off to the right.

Thanks.

• Can you show us some code what you do and can you give concrete examples of entrys with problems? – Mensch Oct 17 '15 at 15:51
• I have answered the question in the link above, but at the moment I don't see the real connection between those two questions – user31729 Oct 17 '15 at 16:13
• What is Bates numbering? – user31729 Oct 17 '15 at 16:33
• Bates numbering is when you take a bunch of documents, which may have their own numbers or not, and sequentially number the whole bunch of documents. It used to be done by stamping the documents with a stamper that automatically incremented by 1 each time it was stamped. link – A Feldman Oct 17 '15 at 18:05
• To a real programmer the answer to this might be obvious. But I just don't have the tex programming chops to even begin to modify the code in the link to make the numbering on all the included pdfs sequential as well as make the pdfs bigger on the page. – A Feldman Oct 17 '15 at 18:08

Not an answer but more than a comment

\documentclass[12pt,a4paper,fleqn,parskip=half]{scrartcl}

\usepackage{lscape}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[demo]{graphicx}
\usepackage[scaled]{helvet}
\usepackage{caption}
\usepackage{xargs}

%---------------------------------------------------------------------
%   % Macro to include PDF document with page numbers in caption and label
%---------------------------------------------------------------------
\newcounter{imagepage}

\makeatletter
\newcommandx{\picTEST}[5][1=0.9, 2=0]
{\pdfximage{#4}
\setcounter{imagepage}{0}
\@whilenum\value{imagepage}<\pdflastximagepages\do{%
\stepcounter{imagepage}
\begin{figure}[h!]
\centering
\includegraphics[width=#1\textwidth,page=\value{imagepage},angle=#2]{#4}
\caption{#5 - Page \arabic{imagepage} of {\the\pdflastximagepages}}
\label{#3\theimagepage}
\end{figure}
\clearpage}}
\makeatother

\begin{document}

\section{Some Text}
Here is reference to page \ref{Document1_Label_Page3} of the included PDF document.

\clearpage
\begingroup
\areaset{\paperwidth}{\paperheight}
\renewcommand{\figurename}{Record}
\section{Some insert of PDF document}
\picTEST{Document1_Label_Page}{quickcode.pdf}{Document1}

\picTEST{Document2_Label_Page}{quick.pdf}{MTDocument}
\endgroup

\end{document}


1. Not clear for me (sorry) see the update :-)
2. use \renewcommand{\figurename}{Record}
3. use \areaset{\paperwidth}{\paperheight} this set margins to 0 and allow the use of the full page. If this is not suffisante, you can try with option trim.

Example

\makeatletter
\newcommandx{\picTEST}[5][1=1, 2=0]
{\pdfximage{#4}
\setcounter{imagepage}{0}
\@whilenum\value{imagepage}<\pdflastximagepages\do{%
\stepcounter{imagepage}
\begin{figure}[h!]
\centering
\includegraphics[width=#1\textwidth,page=\value{imagepage},angle=#2,trim=0mm 30mm 0mm 15mm,clip]{#4}
\caption{#5 - Page \arabic{imagepage} of {\the\pdflastximagepages}}
\label{#3\theimagepage}
\end{figure}
\clearpage}}
\makeatother


Update if I understand 1) the code we need is

\newcounter{imagepage}
\newcommand*\sumpages{0}

\makeatletter
\newcommandx{\picTEST}[5][1=1, 2=0]
{\pdfximage{#4}
\setcounter{imagepage}{0}
\@whilenum\value{imagepage}<\pdflastximagepages\do{%
\stepcounter{imagepage}
\begin{figure}[h!]
\centering
\includegraphics[width=#1\textwidth,page=\value{imagepage},angle=#2,trim=0mm 30mm 0mm 15mm,clip]{#4}
\caption{#5 - Page \the\numexpr\value{imagepage}+\sumpages\relax\ of {\the\numexpr\pdflastximagepages+\sumpages\relax}}
\label{#3\theimagepage}
\end{figure}
\clearpage}
\xdef\sumpages{\the\pdflastximagepages}}
\makeatother


Question: do you need angle?

Update (for xelatex, lualatex) from egreg's answer

\usepackage{ifxetex}
\usepackage{ifluatex}

\ifluatex
\usepackage{luatextra}
\usepackage{unicode-math}
\usepackage[utf8]{luainputenc}
\else\ifxetex
\usepackage{xltxtra} % also loads fontspec, xunicode
\usepackage{unicode-math}
\XeTeXinputencoding utf8

\newcount\pdflastximagepages
\def\pdfximage#1{\pdflastximagepages=\XeTeXpdfpagecount"#1"\relax}
\else
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\fi\fi


MWE

\documentclass[12pt,a4paper,fleqn,parskip=half]{scrartcl}

\usepackage{lscape}

\usepackage{ifxetex}
\usepackage{ifluatex}

\ifluatex
\usepackage{luatextra}
\usepackage{unicode-math}
\usepackage[utf8]{luainputenc}
\else\ifxetex
\usepackage{xltxtra} % also loads fontspec, xunicode
\usepackage{unicode-math}
\XeTeXinputencoding utf8

\newcount\pdflastximagepages
\def\pdfximage#1{\pdflastximagepages=\XeTeXpdfpagecount"#1"\relax}
\else
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\fi\fi
\usepackage[scaled]{helvet}
\usepackage{caption}
\usepackage{xargs}

%---------------------------------------------------------------------
%   % Macro to include PDF document with page numbers in caption and label
%---------------------------------------------------------------------
\newcounter{imagepage}
\newcommand*\sumpages{0}

\makeatletter
\newcommandx{\picTEST}[5][1=1, 2=0]
{\pdfximage{#4}
\setcounter{imagepage}{0}
\@whilenum\value{imagepage}<\pdflastximagepages\do{%
\stepcounter{imagepage}
\begin{figure}[h!]
\centering
\includegraphics[width=#1\textwidth,page=\value{imagepage},angle=#2,trim=0mm 30mm 0mm 15mm,clip]{#4}
\caption{#5 - Page \the\numexpr\value{imagepage}+\sumpages\relax\ of {\the\numexpr\pdflastximagepages+\sumpages\relax}}
\label{#3\theimagepage}
\end{figure}
\clearpage}
\xdef\sumpages{\the\pdflastximagepages}}
\makeatother

\begin{document}

\section{Some Text}
Here is reference to page \ref{Document1_Label_Page3} of the included PDF document.

\clearpage
\begingroup
\areaset{\paperwidth}{\paperheight}
\renewcommand{\figurename}{Record}
\section{Some insert of PDF document}
\picTEST{Document1_Label_Page}{quickcode.pdf}{Document1}

\picTEST{Document2_Label_Page}{quick.pdf}{MTDocument}
\endgroup

\end{document}

• Thanks so much!! I am still fooling around with it now. It seems to do basically what I need. What is angle? – A Feldman Oct 21 '15 at 18:15
• @AFeldman it's \includegraphics option that allow to rotate image by specific value, in your code you use it angle=#2 and #2=0 so no rotating, it seems for me that you don't need it. – touhami Oct 21 '15 at 18:34
• The only thing I needed to change in your wonderfully clear instructions was I had to substitute trim=0mm 5mm 0mm 15mm,clip]{#4} for trim=0mm 30mm 0mm 15mm,clip]{#4} in order to not cut off the bottom of the exhibits. Otherwise, per your comments I added \areaset{612}{742pt} and \renewcommand{\figurename}{Record, Page } – A Feldman Oct 21 '15 at 19:09
• @AFeldman answer updated :-) – touhami Jul 2 '16 at 18:25
• @AlanMunn solved the immediately above problem. Adding \usepackage{luatex85} solves the compatibility problem. – A Feldman Aug 3 '16 at 0:17