# Figures from PDF pages according to their labeleing in latex

I have dozens of figures in my latex named all differently. I want to put them into a single PDF file and call each figure from there via something like \includegraphics[page="label3"]{foo} instead of \includegraphics[page=3]{foo}. In other words I want to call figures from a PDF according to their proper labeling [assigned in creation of this single PDF file containing all figures].

-
May we know why? I'm happy to have each image in a different file, so I can change them at will. So they don't clutter everything up, I've got the segregated into a directory. – vonbrand Apr 13 '13 at 16:31
For my thesis. I don't want to zip figures and instead send thesis.tex and a pdf. – Laura Apr 13 '13 at 16:32
What's wrong with a zipfile, or a tar? My thesis was a dozen or so troff files (yes, a long time back), my current lecture notes is 41 LaTeX files and 240 images, and a bunch or supporting/scaffolding. – vonbrand Apr 13 '13 at 16:33
Then I have to explain how to unzip and where to put folder etc. By the way, my question is similar to this one: tex.stackexchange.com/questions/29323/… – Laura Apr 13 '13 at 16:34

You could do it by defining the labels to macros which expand to the page number. I would use a custom macro to first create the multi-page PDF and then, with a different definition, to create the label list.

Because this is difficult to understand here some code:

Create a .tex file which contains only the following:

% filelist.tex
\myimagelist{some label}{some path/pdffile1}
\myimagelist{some other label}{some path/pdffile2}
% ....


To create the multi-page document use the following document:

% allpdfs.tex
\documentclass{article}
\usepackage{pdfpages}
\newcommand{\myimagelist}[2]{\includepdf[fitpaper=true]{#2}}

\begin{document}
\input{filelist}
\end{document}


This will put every (single page) PDF as a page of the resulting PDF, where every page still has to original size.

In your real document could look like this:

\documentclass{book}
\usepackage{graphicx}
\newcommand{\mylabel}[1]{\csname mylabel #1\endcsname}
\newcounter{mycounter}
\newcommand{\myimagelist}[2]{%
\stepcounter{mycounter}%
\expandafter\edef\csname mylabel #1\endcsname{\arabic{mycounter}}%
}
\input{filelist}

\begin{document}

\includegraphics[page=\mylabel{some label}]{allpdfs}

or use:

\newcommand{\imagebylabel}[2][]{\includegraphics[page=\mylabel{#2},#1]{allpdfs}}

\imagebylabel{some other label}

\end{document}


I couldn't test the code, because I'm currently sitting on a family PC without installed LaTeX, but you should get the principle idea.

-
I have tried you code. First, the figures are all in the 8x11 inch pages, instead of in their original sizes. Second, in the main document I am getting following error: Illegal parameter number in definition of \mylabel ...{\mylabel}[1]{\csname mylabel #2\endcsname} Missing number, treated as zero ...aphics[page=\mylabel{some label}]{allpdfs} Missing \endcsname inserted ...aphics[page=\mylabel{some label}]{allpdfs} – Laura Apr 13 '13 at 16:54
The #2 should be a #1 and I forgot the fitpaper option for \includepdf. I edited my answer. Please try again. – Martin Scharrer Apr 13 '13 at 16:59
Martin, is there a way to include EPS figures in the filelist.tex? – Laura Apr 13 '13 at 17:19
@Lara: You need to convert them to PDF first, e.g. using epstopdf or a similar tool. – Martin Scharrer Apr 13 '13 at 17:36
Martin, one last question. Is there any easy way to create bookmarks in allpdfs according to the figure titles [or their labels]? – Laura Apr 13 '13 at 17:42