%%!TEX TS-program = pdflatexmk
%%!TEX encoding = UTF-8 Unicode
\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[letterpaper,body={6.0in,9.5in},vmarginratio=1:1]{geometry}
\usepackage[small,compact]{titlesec}

\usepackage{fourier}
\usepackage[scaled=0.85]{berasans}
\usepackage[scaled=0.85]{beramono}
\usepackage{microtype}

\usepackage{graphicx}
\usepackage{booktabs}

\usepackage{xcolor}
\usepackage[colorlinks, urlcolor=darkgray, linkcolor=darkgray]{hyperref}

\newcommand{\optkey}{\textsf{Opt}}
\newcommand{\ctlkey}{\textsf{Ctl}}
\newcommand{\cmdkey}{\textsf{Cmd}}
\newcommand{\esckey}{\textsf{Esc}}
\newcommand{\tabkey}{\textsf{Tab}}
\newcommand{\shiftkey}{\textsf{Shift}}

\newcommand{\mnu}[1]{\textsf{#1}}
\newcommand{\cmd}[1]{\textsf{#1}}
\newcommand{\To}{\,\(\to\)\,}

\pagestyle{plain}

\newcommand{\MacTeX}{Mac\kern-.13em\TeX}
\newcommand{\BibTeX}{B\textsc{i\kern-.025em  b}\kern-.13em\TeX}
\newcommand{\TS}{\textsf{\TeX Shop}}
\newcommand{\latexmk}{\textsf{latexmk}}

\title{Using \latexmk\ with \TS}
%\author{by\\Herbert Schulz\\\small\href{mailto:herbs2@mac.com}{herbs2@mac.com}}
\author{Herbert Schulz\\\small\href{mailto:herbs2@mac.com}{herbs2@mac.com}}
\date{}

\begin{document}
\maketitle
\thispagestyle{empty}

\section{What is \latexmk?}

Compiling a \cmd{tex} file containing cross-references, bibliographic references and/or indexes is a multi-pass process; i.e., you've got to run \cmd{(pdf/xe/lua)latex} multiple times with possible intermediate runs of \cmd{bibtex} and/or \cmd{makeindex} until all references are resolved. The \latexmk\ \cmd{perl} program, rewritten and presently maintained by John Collins\footnote{The \latexmk\ web site is <\url{http://www.phys.psu.edu/~collins/software/latexmk-jcc/}>. You can get the latest version of \latexmk\ at <\url{http://www.phys.psu.edu/~collins/software/latexmk-jcc/versions.html}>.}, automates this multi-pass process. By default it first runs \cmd{(pdf/xe/lua)latex} on a source file, determines file dependencies by examining the \cmd{log}, \cmd{aux},  etc. files  produced by the run and then automatically runs \cmd{bibtex}\footnote{As of version 4.22 \latexmk\ will automatically choose between running \cmd{bibtex} or \cmd{biber} as required.} and/or \cmd{makeindex}, if needed, and the correct number of additional runs of \cmd{(pdf/xe/lua)latex} to generate the bibliography, index and cross-references. Recent versions of \latexmk\ also work correctly with the \cmd{nomencl} package as well as the  \cmd{glossary} and \cmd{glossaries} packages and other packages that produce multiple bibliographies or indexes.

\section{Quick Start!}

This section will get you started quickly. Unless you are trying to customize the behavior of the supplied engines or want to use the more esoteric engines this really is all you need!

\subsection{Quick Install.}

To activate the \latexmk\ \cmd{engine} files simply move all the files with extension \cmd{.engine} from \path{~/Library/TeXShop/Engines/Inactive/Latexmk} two folder levels up, to \path{~/Library/TeXShop/Engines}, and (re-)start \TS. (Note: \path{~/Library} is the \cmd{Library} folder in your \cmd{HOME} folder. You can use the \mnu{TeXShop}\To\mnu{Open \path{~/Library/TeXShop}} menu item to open that folder.) When you click on the popup engine menu on the Source toolbar the newly enabled engines names should appear; see Figure (\ref{fig:popupmenus}) to see how that menu changes. \textbf{Note: the engine names will \emph{not} appear in the \mnu{Typeset} Menu.}

\subsection{Quick Use.}

At the top of your Source file place the line
\begin{verbatim}
% !TEX program = pdflatexmk
\end{verbatim}
to use the \cmd{pdflatexmk} engine which will use \cmd{pdflatex} to typeset your document. Substitute \cmd{latexmk}, \cmd{xelatexmk} or \cmd{lualatexmk} for \cmd{pdflatexmk} to use \cmd{latex}, \cmd{xelatex} or \cmd{lualatex} to typeset your Source. From then on simply using \mnu{Typeset}\To\mnu{Typeset} (\cmd{Cmd-T}) will run through the complete process of fully typesetting your document.

\section{What is here?}

There is a set of ten \cmd{engine} files to be placed in \path{~/Library/TeXShop/Engines}. There is a \cmd{tslatexmk} folder already placed in \path{~/Library/TeXShop/bin}. The files in that folder consist of the \cmd{latexmk} program, ten basic initialization (\cmd{rc}) files used by the ten \cmd{engine} files, a common file for personal settings (\cmd{latexmkrcDONTedit}) and two shell scripts used for \cmd{pdftricks} and \cmd{pst-pdf} figure processing. When any of the new engines is first run the \cmd{latexmkrcDONTedit} file will automatically be copied to \path{~/Library/TeXShop/bin/latexmkrcedit} if it doesn't already exist. You may copy the file there manually if you wish. \textbf{Any changes or additions to the configuration (e.g., new dependencies and rules) should be placed in the \cmd{laxtexmkrcedit} file. When \TS\ is updated the files in the \path{~/Library/TeXShop/bin/tslatexmk} may automatically get updated; don't edit them or your changes may get lost.}

\section{What is New with this Version}

\subsection{Command Line Options}\label{sec:CLO}

Most of the latest updated engine files now allow the passing of command line options to the underlying typesetting engine using the 
\begin{verbatim}
% !TEX parameter = …
\end{verbatim}
directive in recent versions of \TS; e.g., the lines
\begin{verbatim}
% !TEX program = pdflatexmk
% !TEX parameter = --shell-escape
\end{verbatim}
will use \cmd{pdflatex} with \cmd{shell-escape} as the typesetting engine. You can pass more than one option so that
\begin{verbatim}
% !TEX parameter = --shell-escape --nonstopmode
\end{verbatim}
will pass both of those options to the typsetting engine.

Note: the \cmd{dtxmk}, \cmd{pdftricksmk} and \cmd{pst-pdfmk} engines have \emph{not} been updated because of their specialized use.

\subsection{Project Customization File}

The engine files supplied with this version of latexmk for TeXShop now allow you to have a \cmd{platexmkrc} file, containing \cmd{latexmk} configuration information, in the same folder as the file you typeset (i.e., the root file for a distributed document). This can be useful if your project needs special configuration options for a certain task.

E.g., you wish to use \cmd{texindy} instead of \cmd{makeindex} to process the \cmd{idx} file into a \cmd{ndx} file you might include a \cmd{platexmkrc} file in the same directory as the root file of a project with contents
\begin{verbatim}
$makeindex = "texindy %O -o %D %S";
\end{verbatim}
to use \cmd{texindy} rather than the default \cmd{makeindex}; make sure you end the file with a blank line. You could also add special options to the processing for a particular situation. Make sure you understand the syntax used by \cmd{latexmk} for customizing commands before playing with this feature.

\textbf{One warning}: if you are going to use this feature understand that the \cmd{platexmkrc} file will be used for \emph{any} file in that folder that is typeset.

\section{Using \latexmk\ with \TS.}

\textbf{NOTE: If you are updating to this version of \latexmk\ for \TS\ from a previous version you need only activate the engine files, as noted above, and restart \TS\ after installing the files.}

There are ten \cmd{engine} files; two for running \cmd{latex} (one with a final run through \cmd{dvips} and \cmd{ps2pdf} [\cmd{latexmk.engine}] and one with a final run through \cmd{dvipdfmx} [\cmd{dvipdfmxmk.engine]}), two for using \cmd{pdflatex} [\cmd{pdflatexmk.engine} and \cmd{sepdflatexmk.engine}] (the second one for use when you need to use \cmd{-{}-shell-escape}: but see Sub-Section (\ref{sec:CLO}) ), one for using \cmd{xelatex} [\cmd{xelatexmk.engine}], one for using \cmd{lualatex} [\cmd{lualatexmk.engine}], two for using the \cmd{pdftricks} or \cmd{pst-pdf} packages with \cmd{pdflatex} [\cmd{pdftricksmk.engine} or \cmd{pst-pdfmk.engine} respectively] and one for use with files that use the \cmd{asymptote} package [\cmd{asymptotemk.engine}]. The final engine is a very basic engine for typesetting \cmd{dtx} files for a package into the final documentation [\cmd{dtxmk.engine}]. The exact form of the commands and options used are in the corresponding \cmd{rc} file (e.g., \cmd{latexmkrc} for the \cmd{latexmk.engine}) in \path{~/Library/TeXShop/bin/tslatexmk} and shouldn't be changed.

You can use these \cmd{engine} files by using the drop down menu on the source tool bar or placing the line
\begin{verbatim}
% !TEX program = pdflatexmk
\end{verbatim}
(for using \cmd{pdflatex}---similar lines for \cmd{latex} and \cmd{xelatex}, etc.) at the top of your document\footnote{For the dtxmk engine the line should be placed just below the initial ``\cmd{\% \textbackslash iffalse}'' line of the \cmd{dtx} file.}; then simply using \mnu{Typeset} (\cmd{\cmdkey-T}) will automatically run the proper \cmd{engine}. Note: these engines \emph{don't} appear under the \mnu{Typeset} Menu but only under the pop-up menu on the source toolbar. Figure (\ref{fig:popupmenus}) shows the default and updated pop-up menu after installing the \latexmk\ engine files.
\begin{figure}
\centering
\includegraphics[width=2in]{figs/OriginalTypesetPopup}\qquad\includegraphics[width=2in]{figs/UpdatedTypesetPopup}
\caption{Default and updated versions of the engine pop-up menu after installing the \latexmk\ engines.}\label{fig:popupmenus}
\end{figure}

%Detailed information about using \latexmk\ with the \cmd{pdftricks} and \cmd{pst-pdf} packages is discussed later.

I have only tested these engines with relatively trivial distributed documents (which include other files using \verb|\include| commands) but it appears that \latexmk\ deals with them properly. Note that when compiling a file with name \cmd{rootname.tex} a file with name \cmd{rootname.fdb\_latexmk}\footnote{The dependency file had extension \cmd{dep} in previous versions of \latexmk\ but didn't do a complete job of keeping track of those dependencies.} is created. This file contains the dependency information for the distributed document so making changes in an included file will force the recompile of the root document by \latexmk.

%\section{Noteworthy Changes with \texttt{latexmk}.}
%
%Versions of \texttt{latexmk} prior to 3.21c weren't able to deal with the \texttt{glossary}, \texttt{glossaries} or \texttt{nomencl} packages because they re-write their output file(s) with each run of \texttt{(pdf/xe)latex} or use custom file extensions. This changed with \texttt{latexmk} 3.21c. The \texttt{latexmkrcedit}, generated the first time you run one of the new engines, is set to recognize the standard file extensions produced by the these packages and process them correctly and ``auto-magically.'' If you are creating custom glossaries or indexes you will have to properly edit the \texttt{latexmkrcedit} file found in the \path{~/Library/TeXShop/bin/} directory to add the dependencies; it should be fairly clear from the contents of that file what has to be added.
%
%Another major addition in \texttt{latexmk} since 3.21c is support for packages that create multiple bibliographies and/or indexes; e.g., when the \texttt{bibunits}, \texttt{chapterbib}, \texttt{multibib}, \texttt{multind} or similar packages are used. The extra processing needed for those packages happens automatically. Unfortunately, the \texttt{index} package uses the same naming scheme\footnote{Custom extensions rather than standard extensions with custom root file names.} as the \texttt{glossary} and \texttt{glossaries} packages (see the sub-section below) so you need to define extra dependencies and processing rules in the provided \texttt{rc} files. There was a bug in \texttt{latexmk} 3.21j that didn't allow it to work properly with the \texttt{index} package when creating an ordinary index (an \texttt{.idx} file); this was corrected with version 4.01 of \texttt{latexmk}.
%
%With \texttt{latexmk} 4.11 came three bug fixes:
%\begin{inparaenum}[i)]
%\item
%Corrected a bug with distributed documents using \texttt{bibtex} where changes in bibliography citations did not always trigger a rerun of \texttt{bibtex}.
%\item
%Fixed a problem when \texttt{latexmk} did not detect changed aux files, etc., on a small document when the run of \texttt{(xe/pdf)latex} was within the 1-second granularity of file times.
%\item
%Improved start-up times on some large documents by avoiding unnecessary recalculations of md5 checksums.
%\end{inparaenum}
%In particular, the last item seems to result in a very noticeable improvement in performance.
%
%\texttt{Latexmk} 4.12 adds one feature. If you have a \texttt{tex} file and an associated \texttt{bbl} file but \emph{not} the original \texttt{bib} file the \texttt{-bibitex-cond} option tells \texttt{latexmk} \emph{not} to run \texttt{bibtex} which would overwrite the \texttt{bbl} file with an empty bibliography. If the \texttt{bib} file is present and along the standard search path \texttt{latexmk} behaves identically to its previous versions. Versions 4.13 and 4.13a have now set this option as the default behavior. The 4.16 version of \texttt{latexmk} fixes a problem with misparsed log files in some versions of pdflatex and updates documentation to mention previously undocumented feature about the use of temporary files in making ps and pdf files. Version 4.16a fixed some bugs that don't effect its behavior under \TS.
%
%\subsection{Using the \texttt{epstopdf} package with \texttt{latexmk}.}
%
%%Including \texttt{eps} graphics files directly in \texttt{pdflatex} documents requires the use of the \texttt{epstopdf} package. If you have an included \texttt{eps} file \emph{and a converted \texttt{pdf} version of the file doesn't exist} the \texttt{epstopdf} package converts the \texttt{eps} file into a corresponding \texttt{pdf} file. 
%
%%\subsubsection{Using \texttt{latexmk} with \texttt{epstopdf} version 1.4 and earlier.}
%
%%With \texttt{epstopdf} versions 1.4 and earlier once the \texttt{pdf} image file exists the conversion no longer takes place \emph{even if the \texttt{eps} file is updated}. The \texttt{pdflatexmkrc} file now contains a dependency that uses a new rule, built into \texttt{latexmk} 4.01 and later, that will  delete a previously generated \texttt{pdf} file and then run \texttt{pdflatex} so that \texttt{epstopdf} will regenerate the \texttt{pdf} image file. \textbf{Note: The file name in your \texttt{\textbackslash includegraphics} commands should \emph{not} have an \texttt{eps} extension to prevent extra, unnecessary runs of \texttt{pdflatex}.}
%
%%\subsubsection{Using \texttt{latexmk} with \texttt{epstopdf} version 1.5 and later.}
%
%\subsubsection{A word about \MacTeX\ 2009 \& 2010}
%
%% This is if embedded epstopdf in graphic(s/x) IS in MacTeX-2009
%There are two changes to the graphics sub-system that first appear in \MacTeX\ 2009:
%\begin{enumerate}
%%\item
%%The \texttt{graphic(s/x)} package now loads the \texttt{epstopdf} package when compiling with \texttt{pdflatex}. This is an attempt to make \texttt{eps} graphics inclusion under \texttt{pdflatex} a bit more transparent. (Note: This feature may not be present in the inital release of \MacTeX\ 2009.)
%\item
%The \cmd{epstopdf} package now defaults to using the \cmd{[update,append]} option. This has consequences if you don't use extensions when you include graphics files in your document.
%\item
%The default conversion is now \cmd{foo.eps}\To\cmd{foo-eps-converted-to.pdf}\footnote{This suffix can be customized.} to prevent any problems with overwriting a \cmd{foo.pdf} .
%\end{enumerate}
%The second of the changes to \cmd{epstopdf} leads to problems with \latexmk\ version 4.08 and earlier since the base file name changes. To make the latest \cmd{epstopdf} operate properly with latexmk version 4.08 and earlier I suggest creating an \cmd{epstopdf.cfg} file, to be placed in \path{~/Library/texmf/tex/latex/config} and containing the line
%\begin{verbatim}
%\epstopdfsetup{update,prepend,prefersuffix=false,suffix=}
%\end{verbatim}
%making \cmd{epstopdf} behave as before; the conversion becomes \cmd{foo.eps}\To\cmd{foo.pdf}. Using \latexmk\ version 4.10 or later requires no changes to \cmd{epstopdf} behavior but you may still do so if you wish to retain the pre-2009 behavior. You can find out the version number of the \latexmk\ program you are using by running the command
%\begin{verbatim}
%~/Library/TeXShop/bin/tslatexmk/latexmk -v
%\end{verbatim}
%in \cmd{Terminal}.
%
%Starting with \MacTeX\ 2010 the \cmd{graphic(x/s)} package will automatically load the \cmd{epstopdf} package if it detects that the file is being compiled using \cmd{pdftex} in \cmd{pdf} mode (normal for \cmd{pdflatex}). You no longer need to explicitly use the \cmd{epstopdf} package. Not only that but, if you haven't defined custom conversion and are only trying to convert \cmd{eps}\To\cmd{pdf} there isn't even a need to use the \cmd{-{}-shell-escape} flag: edit the \cmd{latexmkrcedit} file to eliminate it from all of the engines.
%
%% END of epstopdf embedded in graphic(s/x) IS in MacTeX-2009
%
%% This is if epstopdf embedded in graphic(s/x) ISN'T in MacTeX-2009
%%There are two changes\footnote{A third change, having the \texttt{graphic(s/x)} package automatically load the \texttt{epstopdf} package when compiling with \texttt{pdflatex}, as an attempt to make \texttt{eps} graphics inclusion under \texttt{pdflatex} a bit more transparent, has been postponed for the initial release of \MacTeX\ 2009. It may reappear in an update this coming year.
%%} to the graphics sub-system that first appear in \MacTeX\ 2009:
%%\begin{enumerate}
%%\item
%%The \texttt{epstopdf} package now defaults to using the \texttt{[update,append]} option. This has consequences if you don't use extensions when you include graphics files in your document.
%%\item
%%To prevent any problems with overwriting a \texttt{foo.pdf} the default conversion is now \texttt{foo.eps}\,\(\to\)\,\texttt{foo-eps-converted-to.pdf}\footnote{This suffix can be customized.}.
%%\end{enumerate}
%%The second of the changes to \texttt{epstopdf} leads to problems with \texttt{latexmk} version 4.08 and earlier since the base file name changes. To make the latest \texttt{epstopdf} operate properly with latexmk version 4.08 and earlier I suggest creating an \texttt{epstopdf.cfg} file which contains the line
%%\begin{verbatim}
%%\epstopdfsetup{update,prepend,prefersuffix=false,suffix=}
%%\end{verbatim}
%%to make \texttt{epstopdf} behave as before; the conversion becomes \texttt{foo.eps}\,\(\to\)\,\texttt{foo.pdf}. Using \texttt{latexmk} version 4.10 or later requires no changes to \texttt{epstopdf} behavior but you may still do so if you wish to retain the pre-2009 behavior. You can find out the version number of the \texttt{latexmk} program you are using by running the command
%%\begin{verbatim}
%%  ~/Library/TeXShop/bin/latexmk -v
%%\end{verbatim}
%%in \texttt{Terminal}.
%% END of epstopdf embedded in graphic(s/x) ISN'T in MacTeX-2009
%
%\subsubsection{Working with \cmd{epstopdf}.}
%
%Versions of \cmd{epstopdf} from 1.5 on will automatically update a previously generated \cmd{pdf} file if the corresponding \cmd{eps} file is updated\footnote{Versions of \cmd{epstopdf} earlier than 1.5 never updated the \cmd{pdf} file once it existed.}. To let \latexmk\ ``know'' that it should allow runs of \cmd{pdflatex} if the corresponding \cmd{eps} file is updated the necessary \cmd{rc} files (the ones that run \cmd{pdflatex} rather than \cmd{latex}; \cmd{pdflatexmkrc}, \cmd{pdftricksmkrc}, \cmd{pst-pdfmkrc} and \cmd{asymptotemkrc}) contain a special dependency and rule
%\begin{verbatim}
%add_cus_dep('eps', 'pdf', 0, 'cus_dep_require_primary_run');
%\end{verbatim}
%which passes \latexmk\ the proper behavior.
%
%If you are using \cmd{epstopdf} 1.5 or later with earlier \TeX\ distributions you should invoke it using the \cmd{[update,prepend]} options. For versions of \cmd{epstopdf} earlier than 1.5 you should edit the \cmd{pdflatexmkrc}, \cmd{pdftrcksmkrc}, \cmd{pst-pdfmkrc} and \cmd{asymptotemkrc} files by commenting out the original dependency (place a \cmd{\#} before the line
%\begin{verbatim}
%add_cus_dep('eps', 'pdf', 0, 'cus_dep_require_primary_run');
%\end{verbatim}
%in that file) and uncommenting the new dependency (remove the \cmd{\#} from the start of the line
%\begin{verbatim}
%#add_cus_dep('eps', 'pdf', 0, 'cus_dep_delete_dest');
%\end{verbatim}
%in that same file). This will have \latexmk\ remove the \cmd{pdf} file before running \cmd{pdflatex} so \cmd{epstopdf} will recreate the \cmd{pdf} file. NOTE: These files may be automatically updated when \TS\ is updated and you may lose your changes!
%
%%You can use the same (default with this distribution) processing with \texttt{epstopdf} 1.5 and later, however the \texttt{epstopdf} package, version 1.5 and later can check for an updated \texttt{eps} file and then recreate the \texttt{pdf} file if the \texttt{[update,prepend]} package options are used.  The dependency checking by \texttt{latexmk} is still important to let \texttt{latexmk} ``know'' that an included \texttt{eps} file has changed but the deletion of the \texttt{pdf} image file is unnecessary.  The \texttt{pdflatexmkrc}, etc., support files for \texttt{latexmk} 4.01 and later now contain a dependency and rule that will detect an updated \texttt{eps} file but let \texttt{epstopdf} do the conversion to \texttt{pdf}. By default this dependency is turned \emph{off} in \texttt{pdflatexmkrc}; to turn it on you should edit that file by commenting out the original dependency (place a \texttt{\#} before the line
%%\begin{verbatim}
%%add_cus_dep('eps', 'pdf', 0, 'cus_dep_delete_dest');
%%\end{verbatim}
%%in that file) and uncommenting the new dependency (remove the \texttt{\#} from the start of the line
%%\begin{verbatim}
%%#add_cus_dep('eps', 'pdf', 0, 'cus_dep_require_primary_run');
%%\end{verbatim}
%%in that same file). Remember that \texttt{latexmk} will work properly without making this change.
%
%In version 1.5 and later of the \cmd{epstopdf} package you can also specify non-default processing for the \cmd{eps} to \cmd{pdf} conversion\footnote{The default processing uses the \cmd{epstopdf} command which, in turn, uses \cmd{ghostscript}.}. Since \latexmk\ lets the \cmd{epstopdf} package to do all of the necessary processing of the \cmd{eps} file any customized processing defined in the \cmd{tex} source file will be used.
%
%%\textbf{Note: I have noticed that there are times when including the \texttt{eps} extension in \texttt{\textbackslash includegraphics} still gives rise to additional runs of \texttt{pdflatex} so I still recommend you leave off the extension in \texttt{\textbackslash includegraphics} commands.}

\subsection{Using the \cmd{pdftricks} package with \latexmk.}

The \cmd{pdftricks} package allows the inclusion of \cmd{pstricks} graphics in documents compiled with \cmd{pdflatex}. The package generates a file for each postscript figure included in the document. Each of those figure files is then processed to produce a \cmd{pdf} file containing a figure with a tight enclosing bounding box. The \cmd{pdftricksmk} engine included with this version of \latexmk\ processes the original file, the figure files, etc., all only if they have changed. To use the engine place the line
\begin{verbatim}
% !TEX program = pdftricksmk
\end{verbatim}
at the start of the file and Typeset the file. The processing steps for each of the figure files is \cmd{latex}\To\cmd{dvips}\To\cmd{ps2pdf}\To\cmd{pdfcrop} to ensure the proper bounding box is created for each figure. \textbf{NOTE: you must use the \cmd{[noshell]} option to the \cmd{pdftricks} package or \latexmk\ will get into a run-on condition. All figure processing will be taken care of by \latexmk.}

\subsection{Using the \cmd{pst-pdf} package with \latexmk.}

The \cmd{pst-pdf} package also allows the inclusion of \cmd{pstricks} graphics in documents compiled with \cmd{pdflatex}. When the source file is compiled with \cmd{latex} a \cmd{dvi} file containing all of the figures is created. Further processing through the sequence \cmd{dvips}\To\cmd{ps2pdf}\To\cmd{pdfcrop} produces a single file that contains all of the figures with proper bounding boxes. A run of \cmd{pdflatex} on the source file then includes all of the figures previously generated. The \cmd{pst-pdfmk} engine takes care of all of the intermediate processing of the figures as well as the final run(s) of \cmd{pdflatex}, etc. To use the engine place the line
\begin{verbatim}
% !TEX program = pst-pdfmk
\end{verbatim}
at the start of the file and Typeset the file.

\subsection{The \cmd{glossary}, \cmd{glossaries} and such packages.}

Packages that produce multiple and custom indexes, glossaries, etc., use one of two naming schemes for the multiple files they create:
\begin{enumerate}
\item
The first uses standard extensions but special files names for the generated files. \cmd{Latexmk} can keep track of changes in and ``knows'' how to process these files. The \cmd{multibib} and \cmd{multind} packages are examples that use this method.
\item
The second uses the source file name for the file but uses custom extensions to create the files. \cmd{Latexmk} needs ``help'' to know how to process these files in the form of dependencies and rules. Dependencies tell \latexmk\ what the input and output extensions are and which rule to use to go from input to output. The \cmd{index}, \cmd{glossary} and \cmd{glossaries} packages are examples that use this second method.
\end{enumerate}

In addition, while the \cmd{glossaries} package supersedes the \cmd{glossary} package the order of the file extensions created by acronym and custom lists, processed by \cmd{makeindex} and then read in by subsequent runs of \cmd{(xe/pdf/lua)latex} are reversed in the two packages. This latest version of \latexmk\ configured for \TS\ works correctly for both packages. If you need to create your own custom lists see the examples in the \cmd{latexmkrcedit} file for creating dependancies and rules for \latexmk.

\section{What these engines won't do, etc.}

There are many features of \latexmk\ that aren't used in these simple \cmd{engine} files. See the documentation for \latexmk\ in the supplied full distribution.

The placement of the \latexmk\ program in \path{~/Library/TeXShop/bin/tslatexmk/} is non-standard; that directory is not on the standard path. It is possible to put the program in \path{/usr/local/bin/} or use the version of \latexmk\ that is part of \MacTeX-2008 and later and it will then be usable from the command line. If you use the program in one of those locations you should modify the \cmd{engine} files to reflect the change in location.

%The contents of the \cmd{rc} files corresponds to the the settings for commands for \TS\ on my system. They are simply text files. Please read the \latexmk\ documentation before changing the contents.

%Because of the way \texttt{latexmk} gets the default path for \texttt{bib} files it will generate an inconsequential error message unless the \texttt{bib} file is in the same directory as the source file; the \texttt{bib} file will still be found by \texttt{bibtex} if it is along the standard path for \texttt{bib} files supplied by \texttt{kpsewhich}. To suppress the spurious error message the supplied \texttt{engine} files build a \emph{temporary} \texttt{BIBINPUTS} environment variable by appending the output of \verb'`kpsewhich --show-path=bib | sed -e "s/\!\!//g"`' to a possibly predefined \texttt{BIBINPUTS} variable. If there is a problem with long waits for searches over a network you can edit each of the \texttt{engine} files and customize the setting of the \texttt{BIBINPUTS} environment variable.

Finally, changes in \cmd{eps} files \emph{included in figures} created by the \cmd{pdftricks} or \cmd{pst-pdf} packages are \emph{not} detected by this packaging of \latexmk\ at this time. I hope to correct that problem at a later date.

%\section{Update for \TS\ 2.18 (and later) with \MacTeX\ 2008 (ditto).}
%
%The \cmd{rc} files for this version of \latexmk\ for use with \TS\ have been updated to allow use of \cmd{synctex}, a \cmd{tex\(\leftrightarrow\)pdf} synchronization technology, with \cmd{\MacTeX-2008} and \TS\ 2.18. If you are using \cmd{\MacTeX-2007} or earlier \TeX\ distributions and the inconsequential error message about an unknown option bothers you, remove the \cmd{-{}-synctex=1} options provided in the supplied \cmd{rc} files.
%
%\section{Update for \TS\ 2.30 (and later).}
%
%The \cmd{-{}-file-line-error} flag has been set for all compiles in the basic \cmd{rc} files. \TS\ 2.30 and later uses the information provided by this flag to localise the location of compile errors when you use the \mnu{Go to Error} command.
%
%\section{Update for \TS\ 2.32 (and later).}
%
%Starting with \TS\ 2.32 when \TS\ is updated any updates to the files in the \path{~/Library/TeXShop/bin/tslatexmk/} folder will automatically be installed. Any changes directly made to those files will be lost. Most of the extra dependencies and rules that were common to all the \cmd{rc} files have been moved to the new \path{~/Library/TeXShop/bin/latexmkrcedit} file and all additional personal dependencies and rules should be moved to that file. The \cmd{latexmkrcedit} file will \emph{not} be updated automatically.
%
%%\end{document}

\vspace{5pt plus 2pt minus 1pt}\noindent
Try it\dots\ I hope you like it.

\vspace{5pt plus 2pt minus 1pt}\noindent
Good Luck,\\
Herb Schulz\\
(\href{mailto:herbs2@mac.com}{herbs2@mac.com})

\end{document}
