% \iffalse
%<*class>
 % ###################################################################
 % 
 %  FILE: "photoprint.dtx"
 %                                    created: 2003-03-03 13:53:42 
 %                                last update: 2006-09-28 17:06:43 
 %  Author: Fr\'ed\'eric Boulanger
 %  E-mail: Frederic.Boulanger@supelec.fr
 %    mail: Sup\'elec - Service Informatique
 %          3 rue Joliot-Curie, F-91192 Gif-sur-Yvette cedex
 %     www: http://wwwsi.supelec.fr/fb/
 %  
 %  Description: 
 % 
 %  Photoprint is a document class to print photographs and contact 
 %  sheets. A file named "photoprint.job" should contain one line
 %  for each file to print. The line should contains the name of the
 %  picture file which may be followed by a '*' character and the
 %  number of copies of this picture to print. If the "*<num>" part
 %  is omitted, one copy of the picture will be printed.
 %  When printing contact sheets, the number of copies is ignored, 
 %  and each picture in the file is shown once in the contact sheet.
 %  
 %  Options:
 %    cropmarks     print crop marks to help cut the pictures
 %    
 %    whitemargins  use the smallest margin of the printable area
 %                  as the size of the white space left around pictures.
 %                  This allows to have an even white border around 
 %                  the pictures after they are cut.
 %    
 %    fullpictures  prevents cropping when the aspect ratio of the 
 %                  picture is not the same as the aspect ratio of the
 %                  printing slot on the paper. When this option is 
 %                  set, the picture is scaled down so that it fits 
 %                  entirely in the slot, with white margins.
 %                  The default behavior is to crop the picture so 
 %                  that there is no white band aside it.
 %    
 %    landscape     use paper in landscape orientation.
 %    
 %    showdate      print the date in the lower right corner of the pictures.
 %                  The printed date is read from a map file which keeps 
 %                  information about pictures.
 %                  The file should be named !Name_Map.can or !Name_Map.mav. 
 %                  Each line should contain 4 items between braces :
 %                    {<seconds>} {<filename>} {<original>} {<date>}
 %                  Only the <filename> and the <date> are used by photoprint.
 %                  <seconds>  is the number of seconds since january 1 1904 
 %                             (the epoch on the Macintosh)
 %                  <filename> is the file name of the picture
 %                  <original> is the file name of the original picture as taken
 %                             by the camera
 %                  <date>     is the date and time at which the picture was 
 %                             taken in ISO format : YYYY-MM-DDThh:mm:ssZ, where 
 %                             YYYY is the year, MM the month (1-12), DD the day 
 %                             of month (1-31), hh the hour (0-23), mm the 
 %                             minutes (0-59) and ss is the seconds (0-59).
 %    
 %  Commands:
 %    \photodir{<directory path>}
 %                          sets the name of the directory in which 
 %                          the photos will be searched. If not used, 
 %                          the photos are searched in the current 
 %                          directory. <directory path> must end with 
 %                          a path separator ('/' on Unix, '\' on 
 %                          Windows).
 %                          
 %    \photosperline{<num>} sets the number of photos which will 
 %                          appear on the same line. Default value
 %                          is two.
 %                          
 %    \photospercol{<num>}  sets the number of photos which will
 %                          appear on the same column. Default value
 %                          is two.
 %  
 %    \photopaper{<top>}{<left>}{<bottom>}{<right>}
 %                          sets the margins of the printable area on
 %                          the paper. Defaults to 0.5cm 0.5cm 1cm 0.5cm
 %                          which is OK for most inkjet printers 
 %                          (tested with a Canon S800).
 %                          <top>, <left>, <bottom> and <right> are 
 %                          relative to the portrait orientation of the
 %                          paper. If the document is printed in 
 %                          landscape mode, <top> will be the left  
 %                          margin and so on, so you don't have to  
 %                          care about printing orientation when you 
 %                          define the printing area of your printer.
 %            
 %    \printphotos[<job-file>]
 %                          prints the photographs as described in
 %                          <job-file>. <job-file> is an optional
 %                          argument and defaults to "photoprint.job".
 %    
 %    \datecolor{<color>}   sets the color used to print the date on pictures
 %                          when the showdate option is active. It defaults
 %                          to black.
 %                          
 %    \datestyle{<style>}   sets the style used to print the date on pictures
 %                          when the showdate option is active. <style> should be
 %                          a series of text-style declarations. The default is:
 %                          \sffamily\small
 %                          
 %    \infostyle{<style>}   sets the style used to print information about 
 %                          pictures on the contact sheets (date and name).
 %                          <style> should be a series of text-style 
 %                          declarations. The default is: \sffamily\footnotesize
 %                          
 %    \contactsheet[<job-file>]
 %                          prints the contact sheets for the 
 %                          photographs listed in <job-file>.
 %                          Numbers of copies in <job-file> are ignored.
 %                          Photos are printed 5 by line and 4 by 
 %                          column, so a landscape orientation is 
 %                          recommended.
 %                          If the \cstitle macro is defined, it will 
 %                          be used as the title of the contact sheet.
 %    
 %    \photohmargin{<length>} sets the white space left horizontaly 
 %                            around pictures. Consecutive pictures 
 %                            will be separated by twice this length.
 %
 %    \photovmargin{<length>} sets the white space left verticaly 
 %                            around pictures. Consecutive pictures 
 %                            will be separated by twice this length.
 %
 %    \photomargins{<length>} sets the white space left in both directions 
 %                            around pictures. Consecutive pictures 
 %                            will be separated by twice this length.
 %
 %  History
 % 
 %  modified   by  rev reason
 %  ---------- --- --- -----------
 %  2002-09-30 FBO 1.0 original
 %  2002-10-11 FBO 1.1 added support for .JPG, show photo dates
 %  2004-02-22 FBO 1.2 do not use geometry any longer
 %  2006-09-28 FBO 1.3 added \photodir macro to set picture folder.
 % ###################################################################
 %%
%</class>
%<*gobble>
\input docstrip

\preamble
\endpreamble

\postamble
\endpostamble

\generate{
  \file{photoprint.drv}{\from{photoprint.dtx}{driver}}
  \file{photoprint.cls}{\from{photoprint.dtx}{class}}
  \file{contactsheet.tex}{\from{photoprint.dtx}{contactsheet}}
  \file{photos.tex}{\from{photoprint.dtx}{photos}}
  \file{largephotos.tex}{\from{photoprint.dtx}{largephotos}}
}

%% The following files are shell scripts, so \MetaPrefix must be
%% adapted to the shell comment character.
\edef\MetaPrefix{\string#}
%% We redefine \ds@heading so that the first line of the
%% scripts indicates they must be interpreted by /bin/sh
\bgroup\catcode`\@=11
\global\let\ds@heading@ori\ds@heading
\xdef\ds@heading{%
  \string#!/bin/sh^^J%
  \ds@heading@ori
}\egroup

\preamble
\endpreamble

\postamble
\endpostamble

\generate{
  \file{mkphoto.}{\from{photoprint.dtx}{mkphoto}}
  \file{mkcs.}{\from{photoprint.dtx}{mkcs}}
}
\global\let\ds@heading\ds@heading@ori

%% The following file is a Windows batch file, so \MetaPrefix must be
%% adapted to the Windows shell comment string.
\edef\MetaPrefix{REM}

\preamble
\endpreamble

\postamble
\endpostamble

\generate{
  \file{PPrlist.bat}{\from{photoprint.dtx}{PPrlist}}
}

\endbatchfile
%</gobble>
%<*driver>
\documentclass[%
  a4paper,
%  twoside % marginal notes in twoside mode seem to be broken.
]{ltxdoc}
\usepackage[T1]{fontenc}
\usepackage[francais,english]{babel}

\usepackage[%
  a4paper,
%   twoside,
  top=2cm,
  bottom=1cm,
  nofoot,
  left=3.5cm,
  right=3.5cm,
]{geometry}

\usepackage{graphicx}
\graphicspath{{./examples/}}

\IfFileExists{hyperref.sty}{%
  \usepackage[%
    pdftitle={Printing digital photographs with LaTeX},
    pdfauthor={Fr\'ed\'eric Boulanger},
    bookmarks,
    pdfpagemode=None,
    pdfstartview=XYZ,
    pdffitwindow,
    colorlinks,
    linkcolor=black
  ]{hyperref}
}{
  \providecommand{\url}[1]{%
    \textsf{#1}%
  }
}

\newenvironment{resume}{%
  \selectlanguage{francais}
  \def\abstractname{R\'esum\'e}
  \begin{abstract}
}{%
  \end{abstract}
  \selectlanguage{english}
}

\pagestyle{headings}

\DeclareRobustCommand*{\textdegree}{\r{}}
\newcommand{\filename}[1]{\textsf{#1}}
\newcommand{\class}[1]{\textsf{#1}}

\newenvironment{macrosyntax}{%
  \par\small\noindent
  \ \ 
}{%
  \par\noindent
}

\let\verbatimORI\verbatim
\renewcommand{\verbatim}{%
  \vspace{-0.3\baselineskip}%
  \bgroup\small
  \verbatimORI
}
\let\endverbatimORI\endverbatim
\renewcommand{\endverbatim}{%
  \endverbatimORI
  \egroup
  \vspace{-0.2\baselineskip}%
}

\makeatletter
\newenvironment{longlinesverb}{%
  \bgroup
  \ttfamily
  \if@twocolumn
    \setlength{\parindent}{1ex}%
    \par
    \fontsize{6}{8}\selectfont
  \fi
  \catcode`\{=11\catcode`\}=11\catcode`\_=11%
  \obeylines\obeyspaces
}{%
  \egroup
}
\makeatother
\bgroup
\catcode`\[=1\catcode`\]=2
\catcode`\{=11\catcode`\}=11
\gdef\end{longlinesverb}[\end[longlinesverb]]%
\egroup

\CodelineIndex

% \OnlyDescription

\begin{document}
  \DocInput{photoprint.dtx}
  
%   \PrintIndex
\end{document}
%</driver>
% \fi
% 
% \title{Printing digital photographs with \LaTeX}
% \author{%
%    Fr\'ed\'eric Boulanger \\
%    Sup\'{e}lec -- Service Informatique \\
%    Plateau de Moulon, 3 rue Joliot-Curie \\
%    F-91192 Gif-sur-Yvette cedex \\
%    \sffamily\small
%    \href{mailto:Frederic.Boulanger@supelec.fr}%
%         {\sffamily\small Frederic.Boulanger@supelec.fr} \\
%    \href{http://wwwsi.supelec.fr/fb/}%
%         {\sffamily\small http://wwwsi.supelec.fr/fb/}
% }
% \maketitle
% \thispagestyle{empty}
% 
% %\renewcommand{\textfraction}{.1}
% 
% \begin{resume}
%   Des appareils photographiques num\'{e}riques et des imprimantes \`{a} jets
%   d'encre de prix abordables permettent aujourd'hui d'obtenir des
%   tirages papier d'une qualit\'{e} \'{e}quivalente, sinon meilleure, \`{a}
%   celle obtenue avec un appareil argentique compact et un tirage
%   standard. Toutefois, l'impression en quantit\'{e} de photographies en
%   nombre de copies variable sur du papier de taille standard devient
%   rapidement malais\'{e}e. Il existe des programmes permettant de placer
%   des photos dans un album pour l'imprimer ensuite, mais ils exigent
%   g\'{e}n\'{e}ralement un placement manuel de chaque photographie. La classe
%   de documents \LaTeX\ \class{photoprint} est une tentative
%   d'automatisation de l'impression de photographies sur du papier de
%   taille standard. Elle s'appuie sur une liste de photographies
%   associ\'{e}es au nombre de copies d\'{e}sir\'{e}es et sur un d\'{e}coupage de
%   chaque feuille en \og~emplacements d'impression~\fg. Elle g\`{e}re la
%   rotation, la mise \`{a} l'\'{e}chelle et le rognage des photographies pour
%   les faire tenir au mieux dans les emplacements. Elle permet aussi
%   d'obtenir un index des photographies qui facilite le choix des
%   retirages, peut imprimer des marques rep\`{e}res pour le d\'{e}coupage, et
%   afficher la date en surimpression.
% \end{resume}
% 
% \begin{abstract}
%   Affordable digital cameras and photo inkjet printers make it
%   possible to obtain digital prints with a quality which is generally
%   as good as, and often better than with an inexpensive conventional camera and
%   standard processing. However, printing many photographs in various
%   number of copies on standard-size paper may be cumbersome. There are
%   programs to build albums and print them, but they generally force
%   you to lay out photographs by hand on each page. The
%   \class{photoprint} \LaTeX\ document class is an attempt to
%   automatize the printing of digital photographs on standard-size
%   paper. It uses a list of photographs tagged with the number of
%   copies to print, divides the paper into ``print slots'', and
%   takes care of rotating, cropping or scaling the photographs to
%   make them fit into the slots. It can also build an index of the
%   photographs to help people choose the prints they want, add crop
%   marks to the printed pages to help cut the prints or overprint the
%   date on the prints.
% \end{abstract}
% 
% \section{Introduction}
% 
% Printing photographs from a family wish list can make you busy
% during a whole week-end: you must find the photographs to print,
% lay out them on pages, taking the total number of copies of each 
% into account, rotate them if they do not match the page 
% orientation, resize and crop them so they match the paper
% size, wait for the printer, and finally cut the pages
% into prints. Of course, you can use special photo-paper with 
% pre-cut margins, but it is more expensive than standard-size paper,
% yields less clean edges, works only for a given brand of 
% printers because its margins are adapted to the print area of 
% the printer, and it limits you to one print size.
% 
% Using standard-size paper (for instance A4 paper) gives you more 
% freedom since you can use it for prints from \(10\times 14\)~cm
% up to \(20\times 28\)~cm. You can even produce smaller prints, for 
% instance to make stamps printed on self-adhesive paper. But this 
% freedom comes at the cost of the layout of the photographs on 
% the paper.
% 
% Regular digital photographs have a \(\frac{4}{3}\) aspect 
% ratio, while A4 paper has a \(\sqrt{2}\) aspect ratio. So, to use 
% the largest part of the expensive sheets, the photos must be 
% cropped. Some photos are in portrait orientation (their longer 
% side is vertical), while others are in landscape orientation 
% (their longer side is horizontal), so the photos which don't
% have the same orientation as the paper must be rotated.
% 
% The \class{photoprint} \LaTeX\ document class divides pages into 
% ``print slots'' and lays out photographs on these pages. It 
% reads the name of the photographs and the number of copies of 
% each from a file. This file can be written by hand, created by a
% shell script, or generated by a helper Java application which 
% provides a contactsheet-like view of the photographs from
% which you can select pictures and choose the number of copies.
% 
% Since most digital cameras yield JPEG files, it is much easier to
% use \class{photoprint} with pdflatex. However, nothing in 
% \class{photoprint} is hardcoded for pdflatex, so if you provide 
% bounding box files for your JPEG pictures so that \class{graphicx}
% can determine their size, you can use \class{photoprint} with
% ordinary latex.
% 
% \section{Basic setup}
% 
% Since \class{photoprint} is a regular \LaTeX\ document class, you 
% just write:
% \begin{verbatim}
%   \documentclass[a4paper,landscape]{photoprint}
% \end{verbatim}
% \noindent
% to use it with A4 paper in landscape orientation. Then, you have 
% to specify the size of the printable area of your printer. Since 
% this does not depend on the orientation of the paper, 
% \class{photoprint} uses the top, left, bottom and right margins 
% from the edges of the paper in portrait orientation to describe 
% the print area. \DescribeMacro{\photopaper}The command used to 
% set the print area is:
% \begin{macrosyntax}
%   \cs{photopaper}\marg{top}\marg{left}\marg{bottom}\marg{right}
% \end{macrosyntax}
% For instance:
% \begin{verbatim}
%   \photopaper{0.5cm}{0.5cm}{1cm}{0.5cm}
% \end{verbatim}
% \noindent
% says that your printer can print as close as 0.5~cm from the top
% edge, 0.5~cm from the left edge, 1~cm from the bottom edge, and
% 0.5cm from the right edge of a sheet of paper. These are the 
% default setting if you don't use \verb|\photopaper|.
% 
% You can consider that the \verb|\photopaper| command
% takes a physical description of the print area in which \textsf{top}
% is the side which comes out of the printer first, \textsf{bottom} is
% the side which comes out last, and \textsf{left} and \textsf{right}
% are defined relatively to \textsf{top} and \textsf{bottom}, without
% consideration of the printing orientation.
% 
% The bottom margin is generally larger than the other margins 
% because the printer must still be able to hold the paper between 
% its rolls while printing the bottom of the page.
% If you print in landscape orientation, the bottom margin will be on
% the left of the printed page. 
% 
% Next, you have to decide how you want to divide a sheet of paper. 
% For this, you give the number of print slots per line (so it is
% a number of columns), and the number of print slots per 
% column (the number of lines). \DescribeMacro{\photosperline}You 
% set the number of photographs on a line with the:
% \begin{macrosyntax}
%   \cs{photosperline}\marg{number}
% \end{macrosyntax}
% command, and \DescribeMacro{\photospercol} the number of 
% photographs in a column with the:
% \begin{macrosyntax}
%   \cs{photospercol}\marg{number}
% \end{macrosyntax}
% command. For instance:
% \begin{verbatim}
%   \photosperline{2}
%   \photospercol{2}
% \end{verbatim}
% \noindent
% sets four print slots. This is the default setting which yields
% about \(10\times 14\)~cm prints on A4 paper.
% 
% \begin{figure*}[!htb]
% \begin{center}
%   \fbox{\includegraphics[width=0.95\linewidth]{photos}}
%   \caption{Result of \texttt{pdflatex photos.tex}}
%   \label{fig:photos}
% \end{center}
% \end{figure*}
% 
% \begin{figure*}[!htb]
% \begin{center}
%   \fbox{\includegraphics[width=0.95\linewidth]{largephotos}}
%   \caption{Result (first page only) of \texttt{pdflatex largephotos.tex}}
%   \label{fig:largephotos}
% \end{center}
% \end{figure*}
% 
% \begin{figure*}[!htb]
% \begin{center}
%   \fbox{\includegraphics[width=0.95\linewidth]{contactsheet}}
%   \caption{Result of \texttt{pdflatex contactsheet.tex}}
%   \label{fig:contactsheet}
% \end{center}
% \end{figure*}
% 
% \begin{figure*}[!htb]
% \begin{center}
%   \fbox{\includegraphics[width=0.95\linewidth]{whitemargins}}
%   \caption{Effect of \texttt{whitemargins} option}
%   \label{fig:whitemargins}
% \end{center}
% \end{figure*}
% 
% \begin{figure*}[!htb]
% \begin{center}
%   \fbox{\includegraphics[width=0.95\linewidth]{fullpictures}}
%   \caption{Effect of the \texttt{fullpictures} option}
%   \label{fig:fullpictures}
% \end{center}
% \end{figure*}
% 
% \begin{figure*}[!htb]
%   \begin{center}
%     \fbox{\includegraphics[width=0.9\linewidth]{showdate}}
%     \caption{Effect (exaggerated) of the \texttt{showdate} option}
%     \label{fig:showdate}
%   \end{center}
% \end{figure*}
% 
% To print a contact sheet, in landscape orientation, you could
% use:
% \begin{verbatim}
%   \photosperline{5}
%   \photospercol{4}
% \end{verbatim}
% \noindent
% which makes for 4 rows of 5 pictures on each page. However, since
% printing contact sheets is a quite common operation, \class{photoprint}
% has a \verb|\contactsheet| command for this which does more than printing the pictures.
% 
% Last, in the body of your document, you will lay out the pictures,
% using as many pages as necessary, with the
% command\DescribeMacro{\printphotos}:
% 
% \begin{macrosyntax}
%   \cs{printphotos}\oarg{filename}
% \end{macrosyntax}
% \meta{filename} is the name of the file which contains the list
% and number of copies of the pictures to print. It defaults to
% \filename{photoprint.job}. To use the list
% \filename{photosfordad.job}, write:
% 
% \begin{verbatim}
%   \printphotos[photosfordad.job]
% \end{verbatim}
% 
% The format of the \filename{photoprint.job} file is very simple: each 
% line contains the name of a picture file, optionally followed by 
% a \verb|*| and the number of copies to print. For instance, the 
% following asks for one copy of \filename{001-23-IMG\_0375.jpg}, 
% two copies of \filename{004-20-IMG\_0949.jpg}, one copy of 
% \filename{006-22-IMG\_1126.jpg}, and no copy of the other 
% pictures:
% 
% \begin{verbatim}
%   001-23-IMG_0375.jpg*1
%   002-28-IMG_0425.jpg*0
%   003-27-IMG_0707.jpg*0
%   004-20-IMG_0949.jpg*2
%   005-20-IMG_1091.jpg*0
%   006-22-IMG_1126.jpg*1
%   007-25-IMG_1313.JPG*0
%   008-05-IMG_1549.jpg*0
% \end{verbatim}
% 
% If you want contact sheets, use
% \DescribeMacro{\contactsheet}\verb|\contactsheet| instead of
% \verb|\printphotos|. \verb|\contactsheet| will ignore any
% \verb|\photosperline| and \verb|\photospercol| settings and print
% four rows of 5 pictures per page, with a header, and the name and
% indice of each photo printed below it. You may obtain strange
% results if you don't use landscape orientation when printing
% contact sheets. When printing contact sheets, \class{photoprint}
% ignores the number of copies requested for each photo, and puts
% each photo once on the contact sheet.
% 
% \section{Convenience files}
% 
% Some settings are so common that two files can be used to print 
% photos without writing any \LaTeX\ commands. The file
% \filename{photos.tex} prints four pictures by page in landscape
% orientation:
% \begin{verbatim}
%   \documentclass[%
%     a4paper,
%     landscape,
%     cropmarks
%   ]{photoprint}
%   \photosperline{2}
%   \photospercol{2}
%   \begin{document}
%     \printphotos%[name-of-photo-list]
%   \end{document}
% \end{verbatim}
% 
% With the contents of the \filename{photoprint.job} file as shown
% above, running 
% \begin{verbatim}
%   pdflatex photos.tex
% \end{verbatim}
% \noindent
% yields the result shown on figure~\ref{fig:photos}.
% 
% The file \filename{largephotos.tex} prints two pictures by page 
% and yields \(14\times 20\)~cm prints on A4 paper:
% \begin{verbatim}
%   \documentclass[%
%     a4paper,
%     landscape,
%     cropmarks
%   ]{photoprint}
%   \photosperline{2}
%   \photospercol{1}
%   \begin{document}
%     \printphotos%[name-of-photo-list]
%   \end{document}
% \end{verbatim}
% 
% With the contents of the \filename{photoprint.job} file as shown 
% above, running 
% \begin{verbatim}
%   pdflatex largephotos.tex
% \end{verbatim}
% \noindent
% yields the result shown on figure~\ref{fig:largephotos}.
% 
% The file \filename{contactsheet.tex} prints contact sheets for the
% pictures listed in \filename{photoprint.job}. It ignores the 
% number of copies and makes each photo appear once on the 
% contact sheet.
% %
% With the contents of the \filename{photoprint.job} file as shown 
% above, running
% \begin{verbatim}
%   pdflatex contactsheet.tex
% \end{verbatim}
% \noindent
% yields the result shown on figure~\ref{fig:contactsheet}.
% 
% For Unix systems (Linux, Mac~OS~X and others), \class{photoprint}
% is distributed with two shell scripts. The \filename{mkphoto} script
% builds a \filename{photoprint.job} file containing the list of 
% all JPEG files in the current directory, with a number of copies 
% set to 0. This script considers files as JPEG if their extension 
% is \verb|.jpg| or \verb|.jpeg|, in either lower or upper case. The 
% \filename{mkcs} script builds a contact sheet from the 
% \filename{photoprint.job} file in the current directory. It uses 
% the name of the current directory as the title of the contact sheet.
% 
% When installing \class{photoprint}, since \class{docstrip} adds a dot
% at the end of the name of both scripts when they are extracted, you
% should rename these scripts and make them executable with the
% \verb|chmod| Unix command. For instance \verb|chmod a+x mkcs| will
% make \filename{mkcs} executable by any user.
% 
% \section{Document class options}
% On the examples of the previous section, you can
% see black lines in the margins of the pages.
% \DescribeMacro{cropmarks}This is the effect of the
% \verb|cropmarks| option. These marks help adjust the position of
% the page on the paper cutter. The default is not to print crop
% marks.
% 
% If you want white margins around your prints once they are cut, use the
% \DescribeMacro{whitemargins}\verb|whitemargins| option. The length
% of the smallest margin of the printable area is used as the white
% margin, making for an even white border around the prints when
% they are cut.
% 
% The effect of the \verb|whitemargins| option is shown in
% Figure~\ref{fig:whitemargins}.
% 
% Some photographs may contain important details even at their
% edges, and cropping them to adapt their aspect ratio may lead to
% bad results with important details removed.
% \DescribeMacro{fullpictures}The \verb|fullpictures| option
% prevents \class{photoprint} from cropping pictures. This makes
% less optimal use of the paper since the aspect ratio of the
% pictures can no longer be adapted to the print slots, as shown
% on figure~\ref{fig:fullpictures}, where the white band down the middle 
% is wasted space.
% 
% The \DescribeMacro{landscape}\verb|landscape| option makes
% \class{photoprint} use the paper in landscape orientation (largest
% edge is horizontal). It should always be used for contactsheets. When
% printing photographs, the \verb|landscape| option does not change the
% aspect ratio of the prints. It only changes the way they are laid on
% the pages.
% 
% The \DescribeMacro{showdate}\verb|showdate| option prints the date in
% the lower right corner of the pictures; it may be useful to know when
% a picture was taken. The date is read from a file which should be
% named \filename{!Name\_Map.can} or \filename{!Name\_Map.mav} and
% contains information about the photographs. The name and format of
% this file are set for historical reasons from the tools I use to
% manage my digital photographs. Each line of the file describes a
% photograph with four items delimited by braces:
% 
% \begin{enumerate}
% 
%   \item the number of seconds since january 1 1904 (the epoch on
%   the Macintosh). This item is not used by \class{photoprint} and
%   may be left empty (but is must be present);
%   
%   \item the file name of the photograph;
%   
%   \item the file name of the unmodified picture (if it was kept as a 
%   backup). This item is not used by \class{photoprint} and may be 
%   left empty;
%   
%   \item the date and time at which the photograph was taken, in
%   ISO format: \\
%   \hfill\verb|YYYY-MM-DDThh:mm:ssZ|\hfill\\
%   where \verb|YYYY| is
%   the year, \verb|MM| the month (1 for January, 12 for December),
%   \verb|DD| is the day of month, \verb|T| the separator between
%   date and time in the ISO format, \verb|hh| the hour (0--23),
%   \verb|mm| the minutes (0--59), \verb|ss| the seconds (0--59),
%   and \verb|Z| is the time zone. The letter \verb|Z| indicates UTC
%   time. It may be replaced by the signed offset of the time with
%   regard to Universal Time (for instance \verb|+01:00| is the
%   offset of the French local time in winter). Everything after the
%   \verb|T| is ignored by \class{photoprint}.
% 
% \end{enumerate}
% %
% For instance, the file used to store information about the example
% pictures has the following contents:
% 
% \begin{longlinesverb}
%   {3078749666} {001-23-IMG_0375.jpg} {} {2001-07-23T16:14:26+01:00}
%   {3079183448} {002-28-IMG_0425.jpg} {} {2001-07-28T16:44:08+01:00}
%   {3081773514} {003-27-IMG_0707.jpg} {} {2001-08-27T16:11:54+01:00}
%   {3094393350} {004-20-IMG_0949.jpg} {} {2002-01-20T17:42:30+01:00}
%   {3097077318} {005-20-IMG_1091.jpg} {} {2002-02-20T19:15:18+01:00}
%   {3097226436} {006-22-IMG_1126.jpg} {} {2002-02-22T12:40:36+01:00}
%   {3110471962} {007-25-IMG_1313.JPG} {} {2002-07-25T19:59:22+01:00}
%   {3124602926} {008-05-IMG_1549.jpg} {} {2003-01-05T09:15:26+01:00}
% \end{longlinesverb}
% 
% The effect of the \verb|showdate| option is shown on 
% figure~\ref{fig:showdate} where unusal settings have been chosen
% to make the date very visible (\verb|\datecolor{red}| and
% \verb|\datestyle{\Huge\sffamily\bfseries}|).
% 
% Other options (for instance \verb|a4paper|) are passed to the 
% \class{article} document class.
% 
% \section{Finer tuning}
% 
% Several commands allow changing the default behavior of 
% \class{photoprint}:
% 
% \begin{description}
% 
%   \item[\cs{datecolor}\marg{color}]
%   \DescribeMacro{\datecolor}sets the color used to print the date
%   on pictures when the \verb|showdate| option is active. The
%   default is \verb|black|.
%   
%   \item[\cs{datestyle}\marg{style}]
%   \DescribeMacro{\datestyle}sets the text style used for the
%   date on pictures when the \verb|showdate| option is active.
%   \textsf{\slshape style} should be a series of text style
%   declarations. The default is \verb|\sffamily\small|.
%   
%   \item[\cs{infostyle}\marg{style}]
%   \DescribeMacro{\infostyle}sets the text style which is used to print
%   information about the pictures on contact sheets (date and
%   name). \textsf{\slshape style} should be a series of text style
%   declarations. The default is \verb|\sffamily\footnotesize|.
%   
%   \item[\cs{cstitle}] \DescribeMacro{\cstitle}If this command is 
%   defined, its value will be used as the title of the contact sheet
%   by the \cs{contactsheet} command. For instance:
%   
%   \begin{verbatim}
%   \newcommand{\cstitle}{Summer 2002}
%   \contactsheet
%   \end{verbatim}
%   will produce a contact sheet with title ``Summer 2002''.
%   
%   \item[\cs{photohmargin}\marg{length}]
%   \DescribeMacro{\photohmargin}sets the amount of horizontal white
%   space left around pictures. Consecutive pictures will be
%   separated horizontally by twice this length. The default value
%   is 0~pt (or the smallest margin of the print area when the
%   \verb|whitemargins| option is active).
%   
%   \item[\cs{photovmargin}\marg{length}]
%   \DescribeMacro{\photovmargin}sets the amount of vertical white
%   space left around pictures. Consecutive pictures will be
%   separated vertically by twice this length. The default value is
%   0~pt (or the smallest margin of the print area when the
%   \verb|whitemargins| option is active).
%   
%   \item[\cs{photomargins}\marg{length}]
%   \DescribeMacro{\photomargins}sets the amount of white space left
%   around pictures, both vertically and horizontally. Consecutive
%   pictures will be separated by twice this length. The default
%   value is 0~pt (or the smallest margin of the print area when
%   the \verb|whitemargins| option is active).
%   
% \end{description}
% %
% \section{Requirements}
% 
% The \class{photoprint} document class relies on the standard
% \LaTeX\ document class \class{article}, on the standard \LaTeX\
% packages \class{calc}, \class{ifthen}, \class{graphicx}, 
% \class{color} and \class{fontenc}. It also needs the 
% \class{geometry} package.
% 
% Althought \class{photoprint} does not make any assumption about the
% \TeX\ engine used, and uses the \class{graphicx} package to include
% pictures, it is much easier to use with pdftex since digital 
% photographs are generally in JPEG format.
% %
% 
% \section{The tasks of \class{photoprint}}
% 
% \begin{figure*}[!htb]
% \begin{center}
% \setlength{\unitlength}{0.9\linewidth}
% \begin{picture}(1,0.7)
%   \put(0,0){\framebox(1,0.7){}}
%   \put(0.045,0.05){\line(-1,0){0.02}}
%   \put(0.05,0.045){\line(0,-1){0.02}}
%   \put(0.905,0.05){\line(1,0){0.02}}
%   \put(0.9,0.045){\line(0,-1){0.02}}
%   \put(0.905,0.65){\line(1,0){0.02}}
%   \put(0.9,0.655){\line(0,1){0.02}}
%   \put(0.045,0.65){\line(-1,0){0.02}}
%   \put(0.05,0.655){\line(0,1){0.02}}
%   \put(0.05,0.05){\framebox(0.37,0.25){}}
%   \put(0.53,0.05){\framebox(0.37,0.25){}}
%   \put(0.05,0.4){\framebox(0.37,0.25){}}
%   \put(0.53,0.4){\framebox(0.37,0.25){}}
%   %
%   \put(0,0.5){\vector(-1,0){0}}
%   \put(0,0.5){\vector(1,0){0.05}}
%   \put(0.025,0.505){\makebox(0,0)[b]{\rotatebox{90}{\textsf{\small top}}}}
%   %
%   \put(0.25,0){\vector(0,-1){0}}
%   \put(0.25,0){\vector(0,1){0.05}}
%   \put(0.255,0.025){\makebox(0,0)[l]{\textsf{\small left}}}
%   %
%   \put(0.9,0.2){\vector(-1,0){0}}
%   \put(0.9,0.2){\vector(1,0){0.1}}
%   \put(0.95,0.205){\makebox(0,0)[b]{\rotatebox{90}{\textsf{\small bottom}}}}
%   %
%   \put(0.7,0.7){\vector(0,1){0}}
%   \put(0.7,0.7){\vector(0,-1){0.05}}
%   \put(0.705,0.675){\makebox(0,0)[l]{\textsf{\small right}}}
%   %
%   \put(0.4,0.3){\vector(0,-1){0}}
%   \put(0.4,0.3){\vector(0,1){0.1}}
%   \put(0.395,0.35){\makebox(0,0)[r]{\textsf{\small\(2\times\)photohmargin}}}
%   %
%   \put(0.42,0.42){\vector(-1,0){0}}
%   \put(0.42,0.42){\vector(1,0){0.11}}
%   \put(0.475,0.425){\makebox(0,0)[b]{\rotatebox{90}{%
%     \textsf{\small\(2\times\)photovmargin}}}%
%   }
% \end{picture}
% \caption{Dividing the print area}
% \label{fig:pslots}
% \end{center}
% \end{figure*}
% 
% \begin{figure*}[!htb]
% \begin{center}
%   \includegraphics[width=0.45\linewidth]{cropw}\hfil
%   \includegraphics[width=0.45\linewidth]{croph}
%   
%   Print slot is too narrow\hfil
%   Print slot is too shallow
%   \caption{Fitting a picture into a print slot}
%   \label{fig:crop}
% \end{center}
% \end{figure*}
% 
% The class \class{photoprint} performs several tasks to prepare pages of 
% prints from the list of photographs and the selected layout:
% \begin{enumerate}
%   \item from the dimensions of the print area, the orientation
%   of the paper, and the number of photographs to print per page,
%   \class{photoprint} computes the size and position of the 
%   ``print slots'' (the areas where pictures will be placed).
%   
%   \item from the list of photographs and the number of copies to 
%   print, \class{photoprint} builds a list of pictures to lay out.
%   
%   \item for each picture in this list, \class{photoprint} compares
%   the orientation of the picture and the orientation of the 
%   current print slot. If they differ, the picture is rotated 
%   by 90~\textdegree.
%   
%   \item the picture is then scaled to fit into the print slot.
%   
%   \item when the last print slot on a page has been used, a 
%   new page is started.
% \end{enumerate}
% 
% \subsection{Determining print slots}
% 
% \class{photoprint} considers only the print area of a page, and
% divides it according to the required number of photos per line
% and per column. The horizontal and vertical margins around prints
% are also taken into account to determine the size of the print
% slots. Figure~\ref{fig:pslots} shows how print slots are 
% determined in landscape orientation, with two photos per line
% and per column.
% 
% \subsection{Reading the list of photos}
% 
% The default name for the file which contains the list of 
% photographs is \filename{photoprint.job}. In this file, 
% each line should be formated as:
% \begin{center}
%   \meta{filename}*\meta{num}
% \end{center}
% or as:
% \begin{center}
%   \meta{filename}
% \end{center}
% where \meta{filename} is the name of a picture file, and \meta{num}
% is the requested number of copies for this photograph.
% If the ``*\meta{num}'' part is ommited, a value of one is assumed.
% 
% \class{photoprint} stops reading the file as soon as it reads an 
% empty string, so the file should not contain empty lines excepted 
% at its end. There is no special character to mark a line as a 
% comment.
% %
% \subsection{Putting the photos in the print slots}
% 
% The print slots are used starting from the upper left one, and 
% ending with the lower right one, from top to bottom and from left
% to right. Each picture is put in the first unused slot on the page.
% 
% For each picture, \class{photoprint} compares the orientation
% (landscape or portrait) of the print slot and the orientation
% of the picture. If they differ, the picture is rotated by 
% 90~\textdegree\ counter-clockwise.
% 
% Then, \class{photoprint} computes the width the picture would have
% if it were scaled by a factor \(s_{h}\) so that its height would be
% exactly the height of the print slot. This width is called the
% \emph{scaled width} of the picture. \class{photoprint} also
% computes the height the picture would have if it was scaled by a
% factor \(s_{w}\) so that its width were exactly the width of the
% print slot. This height is called the \emph{scaled height} of
% the picture.
% 
% If the scaled width of the picture is larger than the width of the 
% print slot, \class{photoprint} scales the picture by \(s_{h}\) 
% and trims its left and right edges by half the difference between
% the scaled width and the width of the slot.
% 
% If the scaled height of the picture is larger than the height of the 
% print slot, \class{photoprint} scales the picture by \(s_{w}\) 
% and trims its top and bottom edges by half the difference between
% the scaled height and the height of the slot.
% 
% In both cases, the picture fills the print slot, but it is 
% cropped, as shown on figure~\ref{fig:crop}.
% 
% However, when the \verb|fullpictures| option is on, 
% \class{photoprint} uses the smallest of \(s_{h}\) and \(s_{w}\)
% so that the picture fits entirely inside the print slot, 
% between equal white bands to fill the slot.
% 
% \subsection{Contact sheets}
% 
% Contact sheets are a special case in which \class{photoprint} 
% reserves space at the top of the page to display the title of
% the contact sheet and the picture range (there are 20 pictures
% on each page of a contact sheet). It also reserves space between
% the rows of pictures to display their names, indices and date if
% available.
% 
% \section{Related software}
% 
% Photoprint started as a Java application, but I never managed to
% make it print my picture the right way. This is why I started 
% writing the \class{photoprint} document class (everybody knows
% that it is much easier to develop in \LaTeX\ than in Java\dots)
% 
% However, the Java Photoprint application still exists and allows 
% to choose pictures to print and to set the number of copies of 
% each. So I added a menu item to save the current selection of 
% pictures to a file whose default name is \dots
% \filename{photoprint.job}.
% 
% This Java application has never been released, but I plan to make
% it available as a helper to \class{photoprint}. It may even
% launch pdftex and open the result in Acrobat so that people who
% don't like command-line tools feel more at ease. Keep an eye
% on
% \begin{center}
% \url{http://wwwsi.supelec.fr/fb/Development.html}
% \end{center}
% \noindent for a release.
%
% \StopEventually{}
% 
% \section{The implementation}
% 
% \class{photoprint} works only in \LaTeX2e, and is a document class.
% We load the \class{ifthen} package early since it is used to 
% process options.
% 
% \begin{macrocode}
%<*class>
\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesClass{photoprint}
              [2004/02/22 v1.2]

\RequirePackage{ifthen}
%    \end{macrocode}
% 
% We need some boolean values to remember which options are active.
% 
% \begin{macrocode}
\newboolean{photo@cropmarks}
\newboolean{photo@whitemargins}
\newboolean{photo@landscapepaper}
\newboolean{photo@fullpictures}
\newboolean{photo@showdate}

%    \end{macrocode}
% 
% We declare the supported options, and pass other options to the
% article class. The |landscape| option is also passed to  the
% \class{geometry} package.
% 
% \begin{macrocode}
\DeclareOption{cropmarks}{\setboolean{photo@cropmarks}{true}}
\DeclareOption{whitemargins}{\setboolean{photo@whitemargins}{true}}
\DeclareOption{fullpictures}{\setboolean{photo@fullpictures}{true}}
\DeclareOption{showdate}{\setboolean{photo@showdate}{true}}
\DeclareOption{landscape}{%
  \setboolean{photo@landscapepaper}{true}%
  \PassOptionsToClass{\CurrentOption}{article}%
  \PassOptionsToPackage{\CurrentOption}{geometry}%
}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\ProcessOptions\relax

%    \end{macrocode}
% 
% Then, we load the \class{article} class and all the packages we need.
% \class{calc} is used for easier computations, \class{geometry} is 
% used to set the margins, \class{graphicx} is used to include the
% photographs,  and \class{color} is used to set the color of the date
% when the |showdate| option is active. We use the T1 font encoding 
% to avoid issues with special characters in file names. For 
% instance, if a file name (read from the list of photos) contains an
% underscore, it will be displayed correctly on the contact sheet 
% only in T1 encoding. If we use OT1, we get something which looks 
% like a degree symbol instead.
% 
% \begin{macrocode}
\LoadClass{article}
\RequirePackage{calc}
%\RequirePackage{geometry}
\RequirePackage{graphicx}
\RequirePackage{color}
\RequirePackage[T1]{fontenc}

%    \end{macrocode}
% 
% We tell \class{graphicx} that |.JPG| files should be handled the
% same as |.jpg| files.
% 
% \begin{macrocode}
\DeclareGraphicsRule{.JPG}{jpg}{*}{}

%    \end{macrocode}
% 
% We set |\parindent| to 0 to avoid unwanted space before the photos,
% and we choose an empty page style.
% 
% \begin{macrocode}
\setlength{\parindent}{0pt}
\pagestyle{empty}

% \end{macrocode}
% 
% The \cs{photo@dir} macro contains the path to the directory which
% contains the pictures. When its is empty, the local directory is 
% used (more precisely, the pictures are searched according to the
% use of \cs{graphicspath} macro of the graphics package).
% 
% \begin{macro}{\photodir}
% The \cs{photodir} macro sets the value of \cs{photo@dir}.
% 
% \begin{macrocode}
\newcommand*{\photo@dir}{}

\newcommand*{\photodir}[1]{%
  \renewcommand*{\photo@dir}{#1}%
}

% \end{macrocode}
% \end{macro}
%
% The following counters hold the number of photos per line
% and per column.
% 
% \begin{macrocode}
\newcounter{photo@perline}
\newcounter{photo@percol}

%    \end{macrocode}
% 
% These counters are set by the \cs{photosperline} and 
% \cs{photospercol} macros.
% \begin{macro}{\photosperline}
% \mbox{}
% 
% \begin{macrocode}
\newcommand{\photosperline}[1]{%
  \setcounter{photo@perline}{#1}%
}

%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\photospercol}
% \mbox{}
% 
% \begin{macrocode}
\newcommand{\photospercol}[1]{%
  \setcounter{photo@percol}{#1}%
}

%    \end{macrocode}
% \end{macro}
% 
% The \cs{photo@date@color} macro contains the color used to
% display the date when the |showdate| option is active.
% 
% \begin{macro}{\datecolor}
% It is set by the \cs{datecolor} macro.
% 
% \begin{macrocode}
\newcommand{\photo@date@color}{black}
\newcommand{\datecolor}[1]{%
  \renewcommand{\photo@date@color}{#1}%
}

%    \end{macrocode}
% \end{macro}
% 
% The \cs{photo@date@style} macro contains the style used to
% display the date when the |showdate| option is active.
% 
% \begin{macro}{\datestyle}
% It is set by the \cs{datestyle} macro.
% 
% \begin{macrocode}
\newcommand{\photo@date@style}{\sffamily\small}
\newcommand{\datestyle}[1]{%
  \renewcommand{\photo@date@style}{#1}%
}

%    \end{macrocode}
% \end{macro}
% 
% The \cs{photo@info@style} macro contains the style used to
% display the information about photos in the contact sheet.
% 
% \begin{macro}{\infostyle}
% It is set by the \cs{infostyle} macro.
% 
% \begin{macrocode}
\newcommand{\photo@info@style}{\sffamily\footnotesize}
\newcommand{\infostyle}[1]{%
  \renewcommand{\photo@info@style}{#1}%
}

%    \end{macrocode}
% \end{macro}
% 
% The following lengths are the margins of the printing area
% with respect to the edges of a page in portrait orientation.
% 
% \begin{macrocode}
\newlength{\photo@top}
\newlength{\photo@left}
\newlength{\photo@bottom}
\newlength{\photo@right}

%    \end{macrocode}
% 
% \begin{macro}{\photopaper}
% The \cs{photopaper} macro sets the margins of the printing
% area. These margins are given in the order top, left, bottom, right
% and are measured with respect to the portrait orientation of the page.
% 
% 
% \begin{macrocode}
\newcommand{\photopaper}[4]{% top left bottom right
  \setlength{\photo@top}{#1}
  \setlength{\photo@left}{#2}
  \setlength{\photo@bottom}{#3}
  \setlength{\photo@right}{#4}
  \calc@photomargins
}

%    \end{macrocode}
% 
% The \cs{calc@photomargins} macro computes and sets the margins
% from the effective orientation of the paper and the size of the 
% printing area.
% \end{macro}
% 
% \class{photoprint} uses a picture environment to place the 
% photographs on each page. This environment must be opened
% at the beginning of a page, and closed at the end. The boolean
% |photo@inpicture| is used to know whether we are inside a picture
% environment or not.
% 
% \begin{macrocode}
\newboolean{photo@inpicture}
\setboolean{photo@inpicture}{false}

%    \end{macrocode}
% 
% The index of the current photography is hold in the |photo@num| 
% counter. The index of the first photography on the current page is
% stored in the |photo@firstnum| counter and is used to print the
% range of photographs on each page of a contact sheet.
% 
% \begin{macrocode}
\newcounter{photo@num}
\newcounter{photo@firstnum}

%    \end{macrocode}
% 
% \cs{photo@list} is the stream used to read the name and number of 
% copies of the photographs from the photoprint file.
% 
% \begin{macrocode}
\newread\photo@list

%    \end{macrocode}
% 
% \begin{macro}{\printphotos}
% The \cs{printphotos} macro reads the photoprint file and
% places the photographs on pages according to the document
% settings. Its optional argument is the name of the
% photoprint file, which defaults to \filename{photoprint.job}.
% 
% \begin{macrocode}
\newcommand{\printphotos}[1][photoprint.job]{%
%    \end{macrocode}
% 
% The first thing to do is to compute the margins and the spacing
% of photos according to the number of photos per line and per 
% column, the dimensions of the printing area and the margins
% around pictures.
% \begin{macrocode}
  \calc@photodim
%    \end{macrocode}
% 
% Then, if we must print the date on the pictures, or if we are making
% a contact sheet, we check for a file named \filename{!Name\_Map.can}
% or \filename{!Name\_Map.mav} and read it to get the date of the 
% pictures. If no such file can be found, we give a warning and 
% disable the display of dates.
% 
% \begin{macrocode}
  \ifthenelse{\boolean{photo@showdate}\OR\boolean{photo@contactsheet}}{%
    \IfFileExists{!Name_Map.can}{%
      \photo@read@map[!Name_Map.can]%
    }{%
      \IfFileExists{!Name_Map.mav}{%
        \photo@read@map[!Name_Map.mav]%
      }{%
        \ClassWarningNoLine{photoprint}{%
          No map file were found. Dates won't be shown.
        }%
        \setboolean{photo@showdate}{false}%
      }%
    }%
  }{}%
%    \end{macrocode}
% 
% After intializing the |photo@num| counter, we open the photoprint 
% file and read it. The photographs are placed on the pages as their 
% name is read from the file.
% 
% \begin{macrocode}
  \setcounter{photo@num}{0}%
  \immediate\openin\photo@list=#1
  \photo@read
%    \end{macrocode}
% 
% If the last photography is on an uncomplete page, the |picture| 
% environment is still open. So we draw the crop marks if requested
% and then close the |picture| environment.
% 
% \begin{macrocode}
  \ifthenelse{\boolean{photo@inpicture}}{%
    \photo@drawticks
    \end{picture}%
  }{}%
}

%    \end{macrocode}
% \end{macro}
% 
% We use the |photo@contactsheet| boolean to know whether we are
% building a contactsheet or preparing regular prints.
% 
% \begin{macrocode}
\newboolean{photo@contactsheet}

%    \end{macrocode}
% 
% \begin{macro}{\contactsheet}
% The \cs{contactsheet} macro is similar to \cs{printphotos} but
% builds a contact sheet instead of print sheets. It uses the same
% photoprint file as \cs{printphotos}, but ignores the number of
% copies and puts each photo once on the contactsheet.
% 
% \cs{contactsheet} uses a predefined layout and shows information
% (name and date) about each picture.
% 
% \begin{macrocode}
\newcommand{\contactsheet}[1][photoprint.job]{%
%    \end{macrocode}
% 
% Since we use the \cs{printphotos} macro to build contact sheets, we
% must disable the |whitemargins| and |cropmarks| options, and inform
% \cs{printphotos} that we are building a contact sheet.
% 
% \begin{macrocode}
  \setboolean{photo@contactsheet}{true}%
  \setboolean{photo@whitemargins}{false}%
  \setboolean{photo@cropmarks}{false}%
%    \end{macrocode}
% 
% We reduce the printing area to be able to put a title at the top
% and some information about the last row of pictures at the bottom.
% Since the printing area is defined in portrait orientation, what we 
% call the top and bottom of the contact sheet depends on the 
% orientation of the pages.
% 
% After changing these dimensions, we must update the lengths used by
% \class{photoprint} with \cs{calc@photomargins}.
% 
% \begin{macrocode}
  \ifthenelse{\boolean{photo@landscapepaper}}{%
    \addtolength{\photo@right}{1cm}%
    \addtolength{\photo@left}{0.5cm}%
  }{%
    \addtolength{\photo@top}{1cm}%
    \addtolength{\photo@bottom}{0.5cm}%
  }%
  \calc@photomargins
%    \end{macrocode}
% 
% For contact sheets, we put 5 photographs per line and 4 per column
% (this is optimized for landscape A4 paper). We set the margins 
% around the thumbnails to 2~mm horizontally, and to 4~mm 
% vertically. The last margin is used to print the name, date and
% index of each photo below its thumbnail.
% 
% We then use \cs{printphotos} to layout the photos.
% 
% \begin{macrocode}
  \photosperline{5}%
  \photospercol{4}%
  \photohmargin{2mm}%
  \photovmargin{4mm}%
  \printphotos[#1]%
}

%    \end{macrocode}
% \end{macro}
% 
% To make computations easier in the picture environment, we convert
% lengths to counters. \cs{photo@unitlength} is the length unit as
% a \LaTeX\ length. |photo@unitconv| is the value of this length once
% stored in a \LaTeX\ counter.
% 
% \begin{macrocode}
\newlength{\photo@unitlength}
\newcounter{photo@unitconv}
\setlength{\photo@unitlength}{0.1mm}
\setcounter{photo@unitconv}{\photo@unitlength}

%    \end{macrocode}
% 
% \cs{photo@tmplen} is used to store length temporary. |photo@hgap| 
% and |photo@vgap| are the horizontal and vertical photo margin 
% converted to units of the |picture| environment.
% 
% \begin{macrocode}
\newlength{\photo@tmplen}
\newcounter{photo@hgap}
\newcounter{photo@vgap}

%    \end{macrocode}
% 
% \begin{macro}{\photohmargin}
% The \cs{photohmargin} sets the horizontal margin around 
% photographs.
% 
% \begin{macrocode}
\newcommand{\photohmargin}[1]{%
  \setlength{\photo@tmplen}{#1}%
  \setcounter{photo@hgap}{\photo@tmplen / \value{photo@unitconv}}%
}

%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\photovmargin}
% The \cs{photovmargin} sets the vertical margin around 
% photographs.
% 
% \begin{macrocode}
\newcommand{\photovmargin}[1]{%
  \setlength{\photo@tmplen}{#1}%
  \setcounter{photo@vgap}{\photo@tmplen / \value{photo@unitconv}}%
}

%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\photomargins}
% The \cs{photomargins} sets both the vertical and the horizontal 
% margins around photographs to the same value.
% 
% \begin{macrocode}
\newcommand{\photomargins}[1]{%
  \photovmargin{#1}%
  \photohmargin{#1}%
}

%    \end{macrocode}
% \end{macro}
% 
% The default is not to put margins around photographs.
% 
% \begin{macrocode}
\photomargins{0pt}

%    \end{macrocode}
% 
% The \cs{photo@minmargin} length is the smallest margin of the
% printing area. It is used as the margin around photographs
% where the |whitemargins| option is active.
% 
% \begin{macrocode}
\newlength{\photo@minmargin}

%    \end{macrocode}
% 
% \begin{macro}{\calc@photomargins}
% The \cs{calc@photomargins} sets the margins of the document
% using the \class{geometry} package, and computes the smallest 
% margin of the printing area.
% 
% Since the dimensions of the printing area are defined in
% portrait orientation, the parameters of the \cs{geometry}
% command depend on the effective orienttaion of the pages.
% 
% \begin{macrocode}
\newcommand{\calc@photomargins}{%
  \setlength{\headheight}{0pt}%
  \setlength{\headsep}{0pt}%
  \setlength{\footskip}{0pt}%
  \ifthenelse{\boolean{photo@landscapepaper}}{
    \setlength{\topmargin}{\photo@right-1in}%
    \setlength{\textheight}{\paperheight-\photo@right-\photo@left}%
    \setlength{\oddsidemargin}{\photo@top-1in}%
    \setlength{\evensidemargin}{\photo@top-1in}%
    \setlength{\textwidth}{\paperwidth-\photo@top-\photo@bottom}%
%     \geometry{%
%       nohead,nofoot,
%       top=\photo@right,
%       left=\photo@top,
%       bottom=\photo@left,
%       right=\photo@bottom
%     }
  }{
    \setlength{\topmargin}{\photo@top-1in}%
    \setlength{\textheight}{\paperheight-\photo@top-\photo@bottom}%
    \setlength{\oddsidemargin}{\photo@left-1in}%
    \setlength{\evensidemargin}{\photo@left-1in}%
    \setlength{\textwidth}{\paperwidth-\photo@left-\photo@right}%
%     \geometry{%
%       nohead,nofoot,
%       top=\photo@top,
%       left=\photo@left,
%       bottom=\photo@bottom,
%       right=\photo@right
%     }
  }
  \setlength{\photo@minmargin}{\photo@top}%
  \ifthenelse{\photo@left < \photo@minmargin}{%
    \setlength{\photo@minmargin}{\photo@left}%
  }{}%
  \ifthenelse{\photo@bottom < \photo@minmargin}{%
    \setlength{\photo@minmargin}{\photo@bottom}%
  }{}%
  \ifthenelse{\photo@right < \photo@minmargin}{%
    \setlength{\photo@minmargin}{\photo@right}%
  }{}%
}

%    \end{macrocode}
% \end{macro}
% 
% The next counters contain the dimensions of the pages and
% of the printing slots in units of the |picture| environment.
% 
% \begin{macrocode}
\newcounter{paper@width}
\newcounter{paper@height}
\newcounter{photo@width}
\newcounter{photo@height}

%    \end{macrocode}
% 
% We use the |photo@landscape| counter to store the orientation
% of the print slots. Its value is 1 if the width of the print slots
% is larger than their height (landscape orientation), and -1 in the
% other case. This convention allows us to use a product to determine
% if a photo has the same orientation as the prin slot. Using a 
% boolean would have made things a bit more complex.
% 
% \begin{macrocode}
\newcounter{photo@landscape}

%    \end{macrocode}
% 
% The next counters contain the \(x\) and \(y\) coordinate, and the
% number of the line and of the row of the current print slot.
% 
% \begin{macrocode}
\newcounter{photo@x}
\newcounter{photo@y}
\newcounter{photo@line}
\newcounter{photo@row}

%    \end{macrocode}
% 
% The next counters contain the \(x\) and \(y\) coordinate, and the
% number of the line and of the row of the current print slot.
% 
% \begin{macro}{\calc@photodim}
% The \cs{calc@photodim} macro computes the dimensions of the print
% slots and initializes the coordinates of the first print slot to use.
% 
% \begin{macrocode}
\newcommand{\calc@photodim}{%
%    \end{macrocode}
% 
% If the |whitemargins| option is active, we set the margins around 
% the photographs to the smallest margin of the print area.
% 
% \begin{macrocode}
  \ifthenelse{\boolean{photo@whitemargins}}{%
    \photomargins{\photo@minmargin}%
  }{}%
%    \end{macrocode}
% 
% We convert the dimensions of the print area to counters for use in
% a |picture| environment.
% 
% \begin{macrocode}
  \setcounter{paper@width}{\textwidth / \value{photo@unitconv}}%
  \setcounter{paper@height}{\textheight / \value{photo@unitconv}}%
  %
%    \end{macrocode}
% 
% The width of a print slot is the width of the print area minus the
% width of the spacing between photos, divided by the number of
% photos per line. The horizontal spacing between photos is twice the
% horizontal margin since each photo must have its own margin once
% it is cut.
% 
% \begin{macrocode}
  \setcounter{photo@width}{\value{paper@width}}%
  \addtocounter{photo@width}{-2*(\value{photo@perline}-1)*\value{photo@hgap}}
  \setcounter{photo@width}{\value{photo@width}/\value{photo@perline}}%
  %
%    \end{macrocode}
% 
% The height of a print slot is the height of the print area minus the
% height of the spacing between photos, divided by the number of
% photos per column. The vertical spacing between photos is twice the
% vertical margin since each photo must have its own margin once
% it is cut.
% 
% \begin{macrocode}
  \setcounter{photo@height}{\value{paper@height}}%
  \addtocounter{photo@height}{-2*(\value{photo@percol}-1)*\value{photo@vgap}}
  \setcounter{photo@height}{\value{photo@height}/\value{photo@percol}}%
  %
%    \end{macrocode}
% 
% Once we know the dimensions of the print slots, it is easy to 
% determine if the photos will be printed in landscape or portrait
% orientation.
% 
% \begin{macrocode}
  \ifthenelse{\value{photo@width}>\value{photo@height}}{%
    \setcounter{photo@landscape}{1}%
  }{%
    \setcounter{photo@landscape}{-1}%
  }%
%    \end{macrocode}
% 
% Last, we prepare for using the first print slot which is the 
% leftmost one (\(x=0\)) at the top of the page (\(y\) is at the top
% minus the height of the printing slot). This slot is on the first 
% row of the first line.
% 
% \begin{macrocode}
  \setcounter{photo@x}{0}%
  \setcounter{photo@y}{\value{paper@height}-\value{photo@height}}%
  \setcounter{photo@line}{1}%
  \setcounter{photo@row}{1}%
}

%    \end{macrocode}
% \end{macro}
% 
% The |photo@ex| counter is used to store the number of copies 
% requested for the current photography.
% 
% \begin{macrocode}
\newcounter{photo@ex}

%    \end{macrocode}
% 
% \begin{macro}{\parse@photo}
% The \cs{parse@photo} macro is used to parse a line of the 
% photoprint file. Each line contains the name of the picture file
% and the number of copies to print. The name and the number are 
% separated by a |*|. Since the number part is optional, this macro 
% is always used with |*\end| after its parameter.
% 
% When the number is omited, we set it to 1. When it is given, we 
% have an extra |*| at its end, so we use another macro to remove it
% and set the |photo@ex| counter.
% 
% \begin{macrocode}
\def\parse@photo#1*#2\end{
  \gdef\photo@name{#1}%
  \if |#2|\relax
    \setcounter{photo@ex}{1}%
  \else
    \set@photo@ex#2%
  \fi
}

%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\set@photo@ex}
% 
% The \cs{set@photo@ex} macro is used to set the |photo@ex| counter
% to the value read in the photoprint file. This value has a 
% trailing |*| which is eliminated by the argument list of this macro.
% 
% \begin{macrocode}
\def\set@photo@ex#1*{%
  \setcounter{photo@ex}{#1}%
}

%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\photo@read}
% 
% The \cs{photo@read} macro reads the photoprint file until its end
% or an empty line is reached.
% 
% \begin{macrocode}
\newcommand{\photo@read}{%
  \let\next\photo@read
  \ifeof\photo@list
    \immediate\closein\photo@list
    \let\next=\relax
  \else
    {%
      \endlinechar=-1
      \immediate\global\read\photo@list to \photo@name
    }%
    \if |\photo@name|
      \immediate\closein\photo@list
      \let\next=\relax
    \else
      \expandafter\parse@photo\photo@name*\end
      \ifphoto@contactsheet
        \setcounter{photo@ex}{1}%
      \else
        \message{Photo "\photo@name" x \thephoto@ex^^J}%
      \fi
      \stepcounter{photo@num}%
      \place@image
    \fi
  \fi
  \next
}

%    \end{macrocode}
% \end{macro}
% 
% 
% \begin{macrocode}
\newsavebox{\photo@box}
\newcounter{this@photo@width}
\newcounter{this@photo@height}
\newcounter{this@photo@landscape}
\newcounter{photo@angle}
\newcounter{photo@tmpcount}
\newcounter{photo@date@x}
\newcounter{photo@date@y}
\newcounter{photo@date@width}

\newlength{\photo@offset}
\newlength{\photo@width}
\newlength{\photo@height}
\newlength{\this@photo@width}
\newlength{\this@photo@height}
\newlength{\scaled@photo@width}
\newlength{\scaled@photo@height}

\newlength{\photo@trimleft}
\newlength{\photo@trimbot}
\newlength{\photo@trimright}
\newlength{\photo@trimtop}

\newboolean{photo@too@wide}

\newcommand{\place@image}{%
  \ifthenelse{\value{photo@ex}>0}{%
    \global\let\next@place=\place@image
    \ifthenelse{\(\value{photo@line}=1\)\and\(\value{photo@row}=1\)}{%
      \setlength{\unitlength}{\photo@unitlength}%
      \thispagestyle{empty}%
      \setcounter{photo@firstnum}{\value{photo@num}}%
      \begin{picture}(\value{paper@width},\value{paper@height})%
      \setboolean{photo@inpicture}{true}%
    }{}%
    \edef\photo@fname{\photo@dir\photo@name}%
    \savebox{\photo@box}{\includegraphics{\photo@fname}}%
    \setlength{\this@photo@width}{\wd\photo@box}%
    \setlength{\this@photo@height}{\ht\photo@box}%
    \setcounter{this@photo@width}{\this@photo@width / \value{photo@unitconv}}%
    \setcounter{this@photo@height}{\this@photo@height / \value{photo@unitconv}}%
    \ifthenelse{\this@photo@width > \this@photo@height}{%
      \setcounter{this@photo@landscape}{1}%
    }{%
      \setcounter{this@photo@landscape}{-1}%
    }%
    \setcounter{photo@tmpcount}{%
      \value{photo@landscape}*\value{this@photo@landscape}%
    }%
    \ifthenelse{\value{photo@tmpcount} < 0}{%
      \setcounter{photo@angle}{90}%
      \setcounter{photo@tmpcount}{\value{this@photo@width}}%
      \setcounter{this@photo@width}{\value{this@photo@height}}%
      \setcounter{this@photo@height}{\value{photo@tmpcount}}%
      \setlength{\photo@tmplen}{\this@photo@width}%
      \setlength{\this@photo@width}{\this@photo@height}%
      \setlength{\this@photo@height}{\photo@tmplen}%
    }{%
      \setcounter{photo@angle}{0}%
    }%
    \setlength{\unitlength}{\photo@unitlength}%
    \setlength{\photo@width}{\value{photo@width}\unitlength}%
    \setlength{\photo@height}{\value{photo@height}\unitlength}%
    %
    \setlength{\scaled@photo@width}{%
      \this@photo@width*\ratio{\photo@height}{\this@photo@height}%
    }%
    \setlength{\scaled@photo@height}{%
      \this@photo@height*\ratio{\photo@width}{\this@photo@width}%
    }%
    \ifthenelse{%
      \(\(\scaled@photo@width>\photo@width\)\AND\NOT\boolean{photo@fullpictures}\)
      \OR
      \(\(\scaled@photo@width<\photo@width\)\AND\boolean{photo@fullpictures}\)
    }{%
      \setboolean{photo@too@wide}{true}%
    }{%
      \setboolean{photo@too@wide}{false}%
    }
    \ifthenelse{\boolean{photo@too@wide}}{%
      % photo is too wide
      \setlength{\photo@offset}{%
        (\this@photo@width-\photo@width*\ratio{\this@photo@height}{\photo@height})/2
      }%
      \ifthenelse{\value{photo@angle}=0}{%
        \setlength{\photo@trimleft}{\photo@offset}%
        \setlength{\photo@trimbot}{0pt}%
      }{%
        \setlength{\photo@trimleft}{0pt}%
        \setlength{\photo@trimbot}{\photo@offset}%
      }%
    }{%
      % photo is too high
      \setlength{\photo@offset}{%
        (\this@photo@height-\photo@height*\ratio{\this@photo@width}{\photo@width})/2
      }%
      \ifthenelse{\value{photo@angle}=0}{%
        \setlength{\photo@trimleft}{0pt}%
        \setlength{\photo@trimbot}{\photo@offset}%
      }{%
        \setlength{\photo@trimleft}{\photo@offset}%
        \setlength{\photo@trimbot}{0pt}%
      }%
    }
    \setlength{\photo@trimright}{\photo@trimleft}%
    \setlength{\photo@trimtop}{\photo@trimbot}%
    \edef\photo@fname{\photo@dir\photo@name}%
    \put(\thephoto@x,\thephoto@y){%
      \includegraphics[%
        angle=\thephoto@angle,%
        trim=\photo@trimleft{} \photo@trimbot{} \photo@trimright{} \photo@trimtop{},%
        width=\photo@width,%
        height=\photo@height,%
        clip%
      ]{\photo@fname}}%
    \ifthenelse{\boolean{photo@contactsheet}}{%
      \put(\thephoto@x,\thephoto@y){\framebox(\thephoto@width,\thephoto@height){}}%
      \setcounter{photo@tmpcount}{\value{photo@y}-10}%
      \put(\thephoto@x,\thephoto@tmpcount){%
        \makebox(\thephoto@width,0)[ts]{%
          {\photo@info@style
           \photo@get@date{\photo@name}\hss
           % \photo@name may contain special characters
           \escapechar=-1{\expandafter\string\csname\photo@name\endcsname}\hss
          }\textsf{\thephoto@num}%
        }%
      }%
    }{%
      \ifthenelse{\boolean{photo@showdate}}{%
        \ifthenelse{\value{photo@angle}>0}{%
          \setcounter{photo@date@x}{\value{photo@x}+\value{photo@width}-20}%
          \setcounter{photo@date@y}{\value{photo@y}}%
          \setcounter{photo@date@width}{\value{photo@height}-20}%
          \put(\thephoto@date@x,\thephoto@date@y){%
            \rotatebox{90}{%
              \makebox(\value{photo@date@width},0)[br]{%
                \photo@date@style{%
                  \textcolor{\photo@date@color}{\photo@get@date{\photo@name}}%
                }%
              }%
            }%
          }%
        }{%
          \setcounter{photo@date@x}{\value{photo@x}}%
          \setcounter{photo@date@y}{\value{photo@y}+20}%
          \setcounter{photo@date@width}{\value{photo@width}-20}%
          \put(\thephoto@date@x,\thephoto@date@y){%
            \makebox(\value{photo@date@width},0)[br]{%
              \textcolor{\photo@date@color}{%
                \photo@date@style\photo@get@date{\photo@name}%
              }%
            }%
          }%
        }%
      }{}%
    }%
    %
    \addtocounter{photo@ex}{-1}%
    \stepcounter{photo@row}%
    \ifthenelse{\value{photo@row}>\value{photo@perline}}{%
      \setcounter{photo@row}{1}%
      \stepcounter{photo@line}%
      \setcounter{photo@x}{0}%
      \addtocounter{photo@y}{-\value{photo@height}}%
      \addtocounter{photo@y}{-2*\value{photo@vgap}}%
    }{%
      \addtocounter{photo@x}{\value{photo@width}}%
      \addtocounter{photo@x}{2*\value{photo@hgap}}%
    }%
    \ifthenelse{\value{photo@line}>\value{photo@percol}}{%
      \setcounter{photo@row}{1}%
      \setcounter{photo@line}{1}%
      \setcounter{photo@x}{0}%
      \setcounter{photo@y}{\value{paper@height}-\value{photo@height}}%
      \photo@drawticks
      \end{picture}\newpage
      \setboolean{photo@inpicture}{false}%
    }{}%
  }{%
    \let\next@place=\relax
  }%
  \next@place
}

\newcounter{photo@tick@x}
\newcounter{photo@tick@y}
\newcounter{photo@tick@line}
\newcounter{photo@tick@col}
\newcommand{\photo@drawticks}{%
  \ifthenelse{\boolean{photo@cropmarks}}{%
    \setcounter{photo@tick@col}{-1}%
    \setcounter{photo@tick@x}{-\value{photo@hgap}}%
    \setcounter{photo@tick@y}{-\value{photo@vgap}-1}%
    \whiledo{\value{photo@tick@col}<\value{photo@perline}}{%
      \put(\thephoto@tick@x, \thephoto@tick@y){\line(0,-1){40}}%
      \stepcounter{photo@tick@col}%
      \addtocounter{photo@tick@x}{2*\value{photo@hgap}}%
      \addtocounter{photo@tick@x}{\value{photo@width}}%
    }
    \setcounter{photo@tick@line}{-1}%
    \setcounter{photo@tick@x}{\value{paper@width}+\value{photo@hgap}+1}%
    \setcounter{photo@tmpcount}{-\value{photo@hgap}-1}%
    \setcounter{photo@tick@y}{-\value{photo@vgap}}%
    \whiledo{\value{photo@tick@line}<\value{photo@percol}}{%
      \put(\thephoto@tmpcount, \thephoto@tick@y){\line(-1,0){40}}%
      \put(\thephoto@tick@x, \thephoto@tick@y){\line(1,0){40}}%
      \stepcounter{photo@tick@line}%
      \addtocounter{photo@tick@y}{2*\value{photo@vgap}}%
      \addtocounter{photo@tick@y}{\value{photo@height}}%
    }%
    \setcounter{photo@tick@col}{-1}%
    \setcounter{photo@tick@x}{-\value{photo@hgap}}%
    \setcounter{photo@tick@y}{\value{paper@height} + \value{photo@vgap} + 1}%
    \whiledo{\value{photo@tick@col}<\value{photo@perline}}{%
      \put(\thephoto@tick@x, \thephoto@tick@y){\line(0,1){40}}%
      \stepcounter{photo@tick@col}%
      \addtocounter{photo@tick@x}{2*\value{photo@hgap}}%
      \addtocounter{photo@tick@x}{\value{photo@width}}%
    }%
  }{}%
  \ifthenelse{\boolean{photo@contactsheet}}{%
    \setcounter{photo@tick@y}{\value{paper@height}+50}%
    \setcounter{photo@tick@x}{0}%
    \put(\thephoto@tick@x,\thephoto@tick@y){\line(1,0){\value{paper@width}}}%
    \addtocounter{photo@tick@y}{10}%
    \put(\thephoto@tick@x,\thephoto@tick@y){\textsf{\textbf{\large PhotoIndex}}}%
    \put(\thephoto@tick@x,\thephoto@tick@y){%
      \makebox(\value{paper@width},0)[br]{%
        \textsf{\large\thephoto@firstnum{} -- \thephoto@num}%
      }%
    }%
    \put(\thephoto@tick@x,\thephoto@tick@y){%
      \makebox(\value{paper@width},0)[b]{%
        \textsf{\large\bfseries\csname cstitle\endcsname}%
      }%
    }%
  }{}%
}
%%
% Map reading
% 
\newread\photo@mapfile

\newcommand{\photo@readmap@entry}{%
  \let\next@read=\relax
  \ifeof\photo@mapfile
    \immediate\closein\photo@mapfile
  \else
    {\endlinechar=-1\immediate\global\read\photo@mapfile to \photo@map@entry}%
    \if|\photo@map@entry|
      \immediate\closein\photo@mapfile
    \else
      \let\next@read=\photo@readmap@entry
      \photo@parse@entry\photo@map@entry
    \fi
  \fi
  \next@read
}

\newcommand{\photo@parse@entry}[1]{%
  \expandafter\photo@eval@entry#1
}

\newcommand{\photo@eval@entry}[4]{%
  \expandafter\expandafter\expandafter
  \def\expandafter\expandafter
    \csname #2\endcsname\expandafter{\photo@parse@isodate#4\end}%
}

\newcommand{\photo@parse@isodate}{}
\def\photo@parse@isodate#1T#2\end{%
  #1%
}

\newcommand{\photo@get@date}[1]{%
  \expandafter\csname#1\endcsname
}

\newcommand{\photo@read@map}[1][!Name_Map.can]{%
  \immediate\openin\photo@mapfile=#1
  \photo@readmap@entry
}

% Default settings
\photopaper{0.5cm}{0.5cm}{1cm}{0.5cm} % default for Canon S800
\photosperline{2}
\photospercol{2}
%</class>
%    \end{macrocode}
%
% \section{Helper files}
% 
% \subsection{Creating a contactsheet}
% 
% The file \filename{contactsheet.tex} can be used to create a contactsheet
% using the \filename{photoprint.job} file in the current directory, for 
% instance with the command: \verb|pdflatex contactsheet|.
% 
% \begin{macrocode}
%<*contactsheet>
\documentclass[a4paper,landscape]{photoprint}
\begin{document}
  \contactsheet%[name-of-photo-list] % defaults to photoprint.job
\end{document}
%</contactsheet>
%    \end{macrocode}
%
% \subsection{Printing regular size photos}
% 
% The file \filename{photos.tex} can be used to print four photos per
% page (what makes 10\,cm by 13\,cm prints on A4 paper) using the
% \filename{photoprint.job} file in the current directory, for
% instance with the command: \verb|pdflatex photos|.
% 
% \begin{macrocode}
%<*photos>
\documentclass[a4paper,landscape,cropmarks]{photoprint}
\photosperline{2}
\photospercol{2}
\begin{document}
  \printphotos%[name-of-photo-list] % defaults to photoprint.job
\end{document}
%</photos>
%    \end{macrocode}
%
% \subsection{Printing large photos}
% 
% The file \filename{largesphotos.tex} can be used to print two photos per
% page (what makes 14\,cm by 18\,cm prints on A4 paper) using the
% \filename{photoprint.job} file in the current directory, for
% instance with the command: \verb|pdflatex largephotos|.
% \begin{macrocode}
%<*largephotos>
\documentclass[a4paper,landscape,cropmarks]{photoprint}
\photosperline{2}
\photospercol{1}
\begin{document}
  \printphotos%[name-of-photo-list] % defaults to photoprint.job
\end{document}
%</largephotos>
%    \end{macrocode}
%
% \subsection{Building a photoprint.job file}
% 
% A quick way to build a \filename{photoprint.job} file is to run the
% \filename{mkphoto} shell script in a directory. This will add all 
% JPEG pictures to the file, with a number of copies set to 0. It can 
% be edited later to set the effective number of copies to print.
% 
% Note that \class{docstrip} will extract this file as 
% \filename{mkphoto.}, so you will have to remove the dot at the
% end of its name. You will also have to make it executable, for 
% instance with the Unix command \verb|chmod 555 mkphoto|.
%
% \begin{verbatim}
%<*mkphoto>
cat /dev/null > photoprint.job
for f in *.[jJ][pP][gG] *.[jJ][pP][eE][gG]
do
  echo "$f*0" >> photoprint.job
done
%</mkphoto>
% \end{verbatim}
%
% For Windows users, Peter Zimmerman has written a 
% \filename{PPrlist.bat} batch file that does the same thing as 
% \filename{mkphoto}:
% 
% \begin{verbatim}
%<*PPrlist>
@echo off
REM PPrlist.bat
REM Author: Peter Zimmerman
REM Create jpg-filelist for PhotoPrint.cls
if exist "Photoprint.jbu" del    Photoprint.jbu > nul
if exist "Photoprint.job" echo   "Backup Photoprint.job --> Photoprint.jbu"
if exist "Photoprint.job" rename Photoprint.job Photoprint.jbu
for %%e in (*.jpg) do echo %%e*1 >> Photoprint.job
if exist "Photoprint.job" echo   "Photoprint.job created."
%</PPrlist>
% \end{verbatim}
%
% \subsection{Contactsheet with name of directory}
% 
% To create a contactsheet which shows the name of the directory
% containing the pictures (useful to know where to look when someone
% wants copies of the pictures), you can use the following 
% \filename{mkcs} shell script.
% 
% Note that \class{docstrip} will extract this file as 
% \filename{mkcs.}, so you will have to remove the dot at the
% end of its name. You will also have to make it executable, for 
% instance with the Unix command \verb|chmod 555 mkcs|.
% 
% \begin{verbatim}
%<*mkcs>
pdflatex \\def\\cstitle{`basename "$PWD"`} \\input contactsheet
rm contactsheet.aux contactsheet.log
%</mkcs>
% \end{verbatim}
% \CheckSum{874}
% \Finale
\endinput
