2

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[breaklinks=true,colorlinks=true,linkcolor=black,citecolor=black,urlcolor=black]{hyperref}
\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.

A Feldman
  • 3,930
  • 1
    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 –  Oct 17 '15 at 16:13
  • 1
    What is Bates numbering? –  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
  • well, in this case, may be the question is: help my translate this program (algorithm) to (La)TeX .... algorithm... (the actual question is not clear, at least for me) – touhami Oct 17 '15 at 19:04
  • I hope that my recent edit clarified the question. This is me attempting to "stand on the shoulders of giants", as I don't understand how the macro in the code that I've included works. – A Feldman Oct 18 '15 at 14:58

1 Answers1

2

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[breaklinks=true,colorlinks=true,linkcolor=black,citecolor=black,urlcolor=black]{hyperref}
\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}

I modified slightly your command.

  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[breaklinks=true,colorlinks=true,linkcolor=black,citecolor=black,urlcolor=black]{hyperref}
\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}
touhami
  • 19,520
  • 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 Happy to be helped :-) – touhami Oct 21 '15 at 19:14
  • I am very appreciative. Truly standing on the shoulders of giants...btw- is this possible in xelatex? – A Feldman Oct 21 '15 at 19:26
  • @AFeldman yes you can, add this \newcount\pdflastximagepages \def\pdfximage#1{\pdflastximagepages=\XeTeXpdfpagecount"#1"\relax} to preambul, see http://tex.stackexchange.com/a/47880/71471 – touhami Oct 21 '15 at 20:49
  • I was wondering, can this be adopted to use lualatex using fontspec to load various fonts instead of fontenc ? – A Feldman Jul 02 '16 at 15:18
  • @AFeldman i will try. – touhami Jul 02 '16 at 15:41
  • Thank you. Actually I just got it to work with lualatex, seems it is compatible. – A Feldman Jul 02 '16 at 16:27
  • Actually only partially working :). – A Feldman Jul 02 '16 at 16:30
  • For some reasons the references to what should be page numbers only now includes the page description. (R. at Verified Complaint Dec 4, 20081234 ) instead of (R. at 1234) – A Feldman Jul 02 '16 at 16:36
  • 1
    @AFeldman answer updated :-) – touhami Jul 02 '16 at 18:25
  • I was trying to set this up again on another laptop. This time using texlive 2016 rather than texlive 2015. I think the update broke something. I'm getting `! Undefined control sequence. \picTEST [#1][#2]#3#4#5->\pdfximage {#4} \setcounter {imagepage}{0} @while... l.81 ...}{~\ Summons with Notice, February 1, 2008}

    ? ! Emergency stop.`

    – A Feldman Aug 02 '16 at 22:44
  • 1
    @AlanMunn solved the immediately above problem. Adding \usepackage{luatex85} solves the compatibility problem. – A Feldman Aug 03 '16 at 00:17