From 9a95a8e746f2afb7015aea9f8df962351f758670 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Mon, 2 Nov 2020 21:55:35 +0000 Subject: hyperxmp (2nov20) git-svn-id: svn://tug.org/texlive/trunk@56839 c570f23f-e606-0410-a88d-b1316a301751 --- .../texmf-dist/source/latex/hyperxmp/hyperxmp.dtx | 135 +++++++++++++++++++-- 1 file changed, 123 insertions(+), 12 deletions(-) (limited to 'Master/texmf-dist/source') diff --git a/Master/texmf-dist/source/latex/hyperxmp/hyperxmp.dtx b/Master/texmf-dist/source/latex/hyperxmp/hyperxmp.dtx index eab2cc39405..a6dd612e77e 100644 --- a/Master/texmf-dist/source/latex/hyperxmp/hyperxmp.dtx +++ b/Master/texmf-dist/source/latex/hyperxmp/hyperxmp.dtx @@ -22,7 +22,7 @@ %\NeedsTeXFormat{LaTeX2e}[1999/12/01] %\ProvidesPackage{hyperxmp} %<*package> - [2020/10/05 v5.6 Store hyperref metadata in XMP format] + [2020/11/01 v5.7 Store hyperref metadata in XMP format] % % %<*driver> @@ -264,6 +264,8 @@ % \newcounter{note} % \newcommand{\usagenote}[1]{^^A % \refstepcounter{note}^^A +% \Needspace{\baselineskip}^^A +% \belowpdfbookmark{Note \thenote: #1}{note.\thenote}^^A % \paragraph{Note~\thenote: #1}% % } % @@ -302,6 +304,9 @@ % \DeclareRobustCommand{\Dvips}{^^A % \texorpdfstring{Dvips\SortIndex{dvips}{\texttt{dvips}}}{Dvips}^^A % } +% \DeclareRobustCommand{\progname}[1]{^^A +% \texttt{#1}\SortIndex{#1}{\texttt{#1}}^^A +% } % \DeclareRobustCommand{\Lua}{^^A % Lua\index{Lua}^^A % } @@ -1338,8 +1343,8 @@ % via the \Koma\ letter classes (e.g.,~\clsname{scrlttr2}) and the % \ACMclass\ article class (\clsname{acmart}). % -% If a document uses either or \pkgname{babel} or \pkgname{polyglossia} -% package, it is recommended that it \emph{not} explicitly set +% If a document uses either the \pkgname{babel} or \pkgname{polyglossia} +% packages it is recommended that it \emph{not} explicitly set % \optname{pdflang}. \optname{pdflang} accepts only a single language % name while \pkgname{hyperxmp} can automatically query \pkgname{babel} % and \pkgname{polyglossia} for a list of all languages used in the @@ -1430,6 +1435,7 @@ % \pkgname{totpages} package help generate \optname{pdfpagerange}. For % documents numbered from~1 to~$n$, a simple % +% \Needspace{3\baselineskip} % \begin{verbatim} % \hypersetup{% % pdfpagerange={1-\ref*{TotPages}} @@ -1475,6 +1481,77 @@ % } % \end{verbatim} % +% \usagenote{Automatic computation of the PDF byte count} +% \label{note:auto-byte-count} +% +% The \schema[PRISM Basic Metadata]{\protect\acro{PRISM} Basic Metadata} +% schema~\cite{PRISM2012:basic-meta} defines a \xmpprop{prism:byteCount} +% 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 +% \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). +% +% \iffalse +%<*listings> +% \fi +\begin{figure} + \begin{lstlisting}[ + language=perl, + columns=fullflexible, + frame=single, + basicstyle=\footnotesize, + showstringspaces=false + ] +$pdflatex = 'internal mylatex %O %S'; + +sub mylatex { + my @args = @_; + $retval = system 'pdflatex', @args; + get_pdf_size(); + return $retval; +} + +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"; + } + close(AUX); +} + \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} +% \iffalse +% +% \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. +% % % \StopEventually{^^A % \section{Help Wanted} @@ -2653,6 +2730,7 @@ % \end{macro} % % \begin{macro}{\hyxmp@concated@metadata} +% \begin{macro}{\hyxmp@aep@toks} % Assume that if the document loaded either \pkgname{babel} or % \pkgname{polyglossia} it will eventually define one or more languages % that \pkgname{hyperxmp} can list within a \xmpprop{dc:language} @@ -2675,6 +2753,7 @@ } % \end{macrocode} % \end{macro} +% \end{macro} % % \begin{macro}{\hyxmp@warn@if@no@metadata} % \begin{macro}{\hyxmp@concated@metadata} @@ -2792,6 +2871,7 @@ % \end{macro} % \end{macro} % +% \begin{macro}{\hyxmp@aep@toks} % Right before we reach the |\begin{document}| we check if % \pkgname{hyperref} was loaded. In normal usage, the document will % already have done a |\usepackage{hyperref}| because otherwise, @@ -2857,6 +2937,7 @@ }% } % \end{macrocode} +% \end{macro} % % When we reach the |\end{document}| we need to gather up the metadata % specified explicitly by the user, infer additional metadata where @@ -3094,11 +3175,25 @@ % \end{macrocode} % % Determine the size of the output file from the \emph{previous} run of -% \LuaLaTeX\ or \pdfLaTeX\@. This action has to be performed before the +% \LuaLaTeX\@. This action has to be performed before the % |\begin{document}| because at that point the size of the output file % is reset to zero. We use |\jobname.pdf| as the name of the output -% file even in the \LuaLaTeX\ case because |status.output_file_name| is -% not defined at this point. +% file because |status.output_file_name| is not defined at this point. +% +% It's possible to use \pdfLaTeX's \cs{pdffilesize} primitive to query +% the size of |\jobname.pdf| under \pdfLaTeX\@. Unfortunately, doing so +% has a side effect of making \progname{latexmk} view the +% \acro{PDF} file as an input file, which puts \progname{latexmk} in an +% infinite build loop. (This was the case for \pkgname{hyperxmp} v5.5 +% and v5.6.) See the discussion at +% \url{https://github.com/borisveytsman/acmart/issues/413} for more +% information. +% \changes{v5.7}{2020/11/01}{Do not automatically compute the +% \protect\acro{PDF} file size under \protect\pdfLaTeX\ because this confuses +% \protect\progname{latexmk}. Thanks to John Collins, Nelson Posse Lago, +% 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''} % \begin{macrocode} \ifLuaTeX \edef\hyxmp@prev@pdf@size{% @@ -3109,10 +3204,6 @@ if nbytes then end }% }% -\else - \ifPDFTeX - \edef\hyxmp@prev@pdf@size{\pdffilesize{\hyxmp@jobname.pdf}}% - \fi \fi % \end{macrocode} % @@ -5609,6 +5700,28 @@ ______^^J% % % \begin{schemadesc}[XMP Media Management]{\protect\acro{XMP} Media Management} % +% \begin{macro}{\hyxmp@aep@toks} +% Once we reach the end of the preamble and know that \cs{@pdftitle} and +% \cs{@pdfauthor} are no longer expected to change we use those macros +% (and others) to define one \acro{UUID} for the document +% (\cs{hyxmp@DocumentID}) and one for the document instance +% (\cs{hyxmp@InstanceID}). As explained in +% Section~\ref{sec:initial-prep}, we defer the invocation of +% \cs{AtEndPreamble} to the end of the file. +% \changes{v5.7}{2020/10/13}{As requested by Moritz Heckscher, define +% \protect\cs{hyxmp@DocumentID} and \protect\cs{hyxmp@InstanceID} at +% the end of the preamble instead of at the end of the document} +% \begin{macrocode} +\expandafter\hyxmp@aep@toks\expandafter=\expandafter{% + \the\hyxmp@aep@toks + \AtEndPreamble{% + \@ifmtargexp{\hyxmp@DocumentID}{\hyxmp@def@DocumentID}{}% + \@ifmtargexp{\hyxmp@InstanceID}{\hyxmp@def@InstanceID}{}% + }% +} +% \end{macrocode} +% \end{macro} +% % \begin{macro}{\hyxmp@mm@schema} % Add properties defined by the \acro{XMP} Media Management schema to % the |\hyxmp@xml| macro. According to the \acro{XMP} specification, @@ -5629,8 +5742,6 @@ ______^^J% % the \protect\acro{XMP} packet} % \begin{macrocode} \gdef\hyxmp@mm@schema{% - \@ifmtargexp{\hyxmp@DocumentID}{\hyxmp@def@DocumentID}{}% - \@ifmtargexp{\hyxmp@InstanceID}{\hyxmp@def@InstanceID}{}% \hyxmp@add@simple{xmpMM:DocumentID}{\hyxmp@DocumentID}% \hyxmp@add@simple{xmpMM:InstanceID}{\hyxmp@InstanceID}% \hyxmp@add@simple{xmpMM:VersionID}{\@pdfversionid}% -- cgit v1.2.3