summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/hyperxmp
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2020-11-22 22:19:22 +0000
committerKarl Berry <karl@freefriends.org>2020-11-22 22:19:22 +0000
commitd21f0a146ce9ce0249c46751cdb849738768e38c (patch)
tree838bff9d089df460ba9ef8fb2c9d3977543960d0 /Master/texmf-dist/source/latex/hyperxmp
parent04277ac5c3816f69a3699299d9f5fc7fb1a5a01d (diff)
hyperxmp (22nov20)
git-svn-id: svn://tug.org/texlive/trunk@56984 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/source/latex/hyperxmp')
-rw-r--r--Master/texmf-dist/source/latex/hyperxmp/hyperxmp.dtx216
1 files changed, 167 insertions, 49 deletions
diff --git a/Master/texmf-dist/source/latex/hyperxmp/hyperxmp.dtx b/Master/texmf-dist/source/latex/hyperxmp/hyperxmp.dtx
index a6dd612e77e..4fad6b29d0a 100644
--- a/Master/texmf-dist/source/latex/hyperxmp/hyperxmp.dtx
+++ b/Master/texmf-dist/source/latex/hyperxmp/hyperxmp.dtx
@@ -22,7 +22,7 @@
%<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
%<package>\ProvidesPackage{hyperxmp}
%<*package>
- [2020/11/01 v5.7 Store hyperref metadata in XMP format]
+ [2020/11/22 v5.9 Store hyperref metadata in XMP format]
%</package>
%
%<*driver>
@@ -116,7 +116,7 @@
%</driver>
% \fi
%
-% \CheckSum{2826}
+% \CheckSum{2836}
%
% \CharacterTable
% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
@@ -305,7 +305,7 @@
% \texorpdfstring{Dvips\SortIndex{dvips}{\texttt{dvips}}}{Dvips}^^A
% }
% \DeclareRobustCommand{\progname}[1]{^^A
-% \texttt{#1}\SortIndex{#1}{\texttt{#1}}^^A
+% \mbox{\texttt{#1}}\SortIndex{#1}{\texttt{#1}}^^A
% }
% \DeclareRobustCommand{\Lua}{^^A
% Lua\index{Lua}^^A
@@ -1489,68 +1489,88 @@
% property that indicates the \acro{PDF} file size in bytes.
% \pkgname{hyperxmp} computes this value automatically when the document
% is built using \LuaLaTeX\ but not when using any other \TeX\ engine.
-% (Note that \pkgname{hyperxmp} uses the file size from the
+% Note that \pkgname{hyperxmp} uses the file size from the
% \emph{previous} run of \LuaLaTeX\ because the new \acro{PDF} file is
-% not yet complete.)
-%
-% The \progname{latexmk} build tool can be configured to automatically
-% append a line of the form ``|\hypersetup{pdfbytes=|\meta{number}|}|''
-% to the generated |.aux| file. The subsequent build of the document
-% will read the |.aux| file at the end of the preamble and set
-% \optname{pdfbytes} accordingly. The Perl code shown in
-% Figure~\ref{fig:latexmkrc}, derived from code posted by Nelson Posse
-% Lago and John Collins on
-% \url{https://github.com/borisveytsman/acmart/issues/413}, can be
-% included in a \progname{latexmk} configuration file to set
-% \optname{pdfbytes} automatically whenever \progname{latexmk} builds a
-% \pkgname{hyperxmp}-based document using
-% \pdfLaTeX\ (\progname{latexmk}'s |--pdf| option). The code can be
-% adapted, \textit{mutatis mutandis}, to work with \XeLaTeX\ builds
-% (\progname{latexmk}'s |--pdfxe| or |--xelatex| option).
+% not yet complete. Consequently, one extra compilation is needed for
+% the byte count to converge relative to the the number of compilations
+% that would otherwise be required.
+%
+% Starting with \pkgname{hyperxmp}~v5.9, the \pkgname{hyperxmp}
+% distribution includes a Perl\index{Perl} script called
+% \progname{hyperxmp-add-bytecount} that edits a \acro{PDF} file in
+% place, adding or replacing the \xmpprop{prism:byteCount} property with
+% one that specifies the final file size.\footnote{The script was in
+% fact introduced with \progname{hyperxmp}~v5.8 and was then called
+% \texttt{add\_byteCount}.} Run the script as
+% ``\progname{hyperxmp-add-bytecount} \meta{filename.pdf}''.
+%
+% The \progname{latexmk} build tool can be configured to run
+% \progname{hyperxmp-add-bytecount} automatically every time a \acro{PDF} file
+% is generated. Simply add the code shown in Figure~\ref{fig:latexmkrc}
+% to your \progname{latexmk} configuration file. See
+% \href{http://mirrors.ctan.org/support/latexmk/latexmk.pdf}{the
+% \progname{latexmk} manual} for information on configuration-file
+% naming on different operating systems and explanations of the hook
+% functions used in Figure~\ref{fig:latexmkrc}.
+%
+% \changes{v5.8}{2020/11/18}{Distribute an
+% \protect\progname{add\_byteCount} script and document some sample
+% \protect\progname{latexmk} configuration code that invokes it.
+% Thanks to John Collins for providing both of those}
+% \changes{v5.9}{2020/11/22}{At Karl Berry's request, rename
+% \protect\progname{add\_byteCount} to the less generic-sounding
+% \protect\progname{hyperxmp-add-bytecount}}
%
% \iffalse
%<*listings>
% \fi
-\begin{figure}
+\newsavebox{\latexmkrcbox}
+\begin{lrbox}{\latexmkrcbox}
\begin{lstlisting}[
language=perl,
columns=fullflexible,
+ linewidth=19pc,
frame=single,
basicstyle=\footnotesize,
- showstringspaces=false
+ showstringspaces=false,
+ upquote=true,
+ literate={-}{-}{1}
]
-$pdflatex = 'internal mylatex %O %S';
-
-sub mylatex {
- my @args = @_;
- $retval = system 'pdflatex', @args;
- get_pdf_size();
- return $retval;
+foreach my $cmd ( "latex", "lualatex", "pdflatex", "xelatex",
+ "dvipdf", "xdvipdfmx", "ps2pdf" ) {
+ ${$cmd} = "internal mycmd ${$cmd}";
}
-sub get_pdf_size {
- my $size = (stat($out_dir1 . $root_filename . ".pdf"))[7];
- open(AUX, '>>', $aux_dir1 . $root_filename . ".aux")
- || die "Can't open file " . $aux_dir1 . $root_filename . ".aux: $!";
- if (defined($size)) {
- print AUX "\\\@ifpackageloaded{hyperxmp}{\\hypersetup{pdfbytes=$size}}{}\n";
+sub mycmd {
+ my $retval = system @_;
+ if ( $$Pdest =~ /\.pdf$/ ) {
+ system 'hyperxmp-add-bytecount', $$Pdest;
}
- close(AUX);
+ return $retval;
}
\end{lstlisting}
- \caption{Code to include in a \progname{latexmk} configuration file
- to automate the assignment of \pkgname{hyperxmp}'s
- \optname{pdfbytes} option when building with \pdfLaTeX}
- \label{fig:latexmkrc}
-\end{figure}
+\end{lrbox}
% \iffalse
%</listings>
% \fi
%
-% See \href{http://mirrors.ctan.org/support/latexmk/latexmk.pdf}{the
-% \progname{latexmk} manual} for information on configuration-file
-% naming on different operating systems and explanations of the hooks
-% used in the Figure~\ref{fig:latexmkrc} code.
+% \begin{figure}
+% \centering
+% \usebox{\latexmkrcbox}
+% \caption{ \progname{latexmk} configuration-file code for
+% automatically invoking \progname{hyperxmp-add-bytecount} every time a
+% \acro{PDF} file is generated}
+% \label{fig:latexmkrc}
+% \end{figure}
+%
+% Even though \pkgname{hyperxmp} can compute the byte count
+% automatically when run from \LuaLaTeX, users of \progname{latexmk}
+% need to use configuration-file code like that shown in
+% Figure~\ref{fig:latexmkrc}. Otherwise, \progname{latexmk} would
+% compile the document one time too few for the byte count to
+% converge. It is recommended that those who use both \progname{latexmk}
+% and \pkgname{hyperxmp} configure \progname{latexmk} to be
+% \pkgname{hyperxmp}-aware.
%
%
% \StopEventually{^^A
@@ -3194,13 +3214,111 @@ sub get_pdf_size {
% Derek Dreyer, and the other contributors to
% \protect\href{https://github.com/borisveytsman/acmart/issues/413}{\protect\pkgname{acmart} issue \#413},
% ``Latexmk goes into an infinite loop even on sample files from ACM''}
+% \changes{v5.8}{2020/11/05}{Take
+% \protect\mbox{\protect\texttt{-\kern0pt-output-directory}} into
+% consideration when querying the output file size. Thanks to John
+% Collins for pointing out that the user can change the output
+% directory}
% \begin{macrocode}
\ifLuaTeX
- \edef\hyxmp@prev@pdf@size{%
- \luadirect{%
-local nbytes = lfs.attributes("\hyxmp@jobname.pdf", "size")
+% \end{macrocode}
+% Now that we know we're running \LuaLaTeX\ we define a Lua function,
+% |get_pdf_size|, that takes the base name of the output file and
+% returns the number of bytes in the corresponding \acro{PDF} file. One
+% difficulty is that, at the time of this writing, \LuaTeX\ lacks a
+% mechanism for querying the full name of the output file. Our
+% workaround is a tad kludgy but seems to work. We walk the list of
+% command-line arguments for
+% \mbox{``|-\kern0pt-output-directory=|\meta{dir}''}. (We in fact
+% accept either one or two initial dashes and abbreviations as terse as
+% \mbox{``|-output-d|''}.) Then, we concatenate the output directory
+% (or ``|.|'' if unspecified), a path separator, the given base name of
+% the job, and a ``|.pdf|'' extension. Alas, different operating
+% systems use different path separators so we have to query the
+% operating-system type to select an appropriate separator: ``|\|'' on
+% Windows/\acro{DOS} and ``|/|'' on everything else.
+%
+% |get_pdf_size| is called regardless of whether we're producing
+% \acro{PDF} or \acro{DVI} output. We assume that even if the user
+% specified |--output-format=dvi|, the user's intention is eventually to
+% convert the document to \acro{PDF}.
+% \begin{macrocode}
+ \begin{luacode*}
+function get_pdf_size (bname)
+% \end{macrocode}
+% Search the list of command-line arguments for the output directory.
+% \begin{macrocode}
+ local odir = ""
+ for _, opt in ipairs(arg) do
+ local m = string.match(opt, "%-output%-d.-=(.*)")
+ if m then
+ odir = m
+ end
+ end
+% \end{macrocode}
+% Set the path separator to either ``|/|'' or ``|\|'', depending on the
+% operating system.
+% \begin{macrocode}
+ local sep = "/"
+ if os.type == "windows" or os.type == "msdos" then
+ sep = "\\\\"
+ end
+% \end{macrocode}
+% Concatenate the output directory, path separator, base name, and
+% \texttt{.pdf} extension. Do not insert a path separator if either
+% (1)~no output directory was specified, (2)~the output directory
+% already ends with the path separator, or (3)~the output directory ends
+% in a colon (and is therefore a relative directory) on
+% Windows/\acro{DOS}. As a few examples,
+%
+% \bigskip
+% \noindent
+% \begingroup
+% \let\bs=\textbackslash
+% \begin{tabular}{@{\quad\textbullet~}l@{~+~}l@{~+~}l@{~+~``\texttt{.pdf}''~=~}l@{}}
+% ``'' & ``\texttt{/}'' & ``\texttt{myfile}''
+% & ``\texttt{myfile.pdf}'' \\
+% ``\texttt{/docs}'' & ``\texttt{/}'' & ``\texttt{myfile}''
+% & ``\texttt{/docs/myfile.pdf}'' \\
+% ``\texttt{/docs/}'' & ``\texttt{/}'' & ``\texttt{myfile}''
+% & ``\texttt{/docs/myfile.pdf}'' \\
+% ``\texttt{C:\bs docs}'' & ``\texttt{\bs}'' & ``\texttt{myfile}''
+% & ``\texttt{C:\bs docs\bs myfile.pdf}'' \\
+% ``\texttt{C:\bs docs\bs}'' & ``\texttt{\bs}'' & ``\texttt{myfile}''
+% & ``\texttt{C:\bs docs\bs myfile.pdf}'' \\
+% ``\texttt{C:\bs}'' & ``\texttt{\bs}'' & ``\texttt{myfile}''
+% & ``\texttt{C:\bs myfile.pdf}'' \\
+% ``\texttt{C:}'' & ``\texttt{\bs}'' & ``\texttt{myfile}''
+% & ``\texttt{C:myfile.pdf}'' \\
+% \end{tabular}
+% \endgroup
+% \bigskip
+% \begin{macrocode}
+ local dlast = string.sub(odir, -1)
+ if odir == "" or dlast == sep or (dlast == ":" and sep == "\\\\") then
+ sep = ""
+ end
+ local fname = odir .. sep .. bname .. ".pdf"
+% \end{macrocode}
+% Query the file size and return it.
+% \begin{macrocode}
+ local nbytes = lfs.attributes(fname, "size")
+ return nbytes
+end
+ \end{luacode*}
+% \end{macrocode}
+% Now that we've defined |get_pdf_size| we invoke it, passing it
+% \cs{hyxmp@jobname} as the base name of the job. (Recall that
+% \cs{hyxmp@jobname} is the same as \cs{jobname} but with any
+% surrounding double quotes removed.) We store |get_pdf_size|'s
+% output---which will be empty if the \acro{PDF} file doesn't yet
+% exist---in \cs{hyxmp@prev@pdf@size}.
+% \begin{macrocode}
+ \xdef\hyxmp@prev@pdf@size{%
+ \luadirect{
+nbytes = get_pdf_size("\hyxmp@jobname")
if nbytes then
- tex.write(nbytes)
+ tex.write(nbytes)
end
}%
}%