summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/hyperxmp
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2016-07-04 21:57:47 +0000
committerKarl Berry <karl@freefriends.org>2016-07-04 21:57:47 +0000
commitb23525e6e9edb32c2ef53c319ba3e03f3b408dda (patch)
treec5cb6eb8354f68f4b10c88f4addfb96293d2d65b /Master/texmf-dist/source/latex/hyperxmp
parente093ae9cb5b99013ee9136f7b85741486cdb166a (diff)
hyperxmp (4jul16)
git-svn-id: svn://tug.org/texlive/trunk@41626 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/source/latex/hyperxmp')
-rw-r--r--Master/texmf-dist/source/latex/hyperxmp/hyperxmp.dtx310
1 files changed, 242 insertions, 68 deletions
diff --git a/Master/texmf-dist/source/latex/hyperxmp/hyperxmp.dtx b/Master/texmf-dist/source/latex/hyperxmp/hyperxmp.dtx
index e1fcca6c69d..dad0acc32a9 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>
- [2016/04/27 v2.9 Store hyperref metadata in XMP format]
+ [2016/07/04 v3.0 Store hyperref metadata in XMP format]
%</package>
%
%<*driver>
@@ -81,7 +81,7 @@
%</driver>
% \fi
%
-% \CheckSum{1551}
+% \CheckSum{1593}
%
% \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
@@ -123,18 +123,22 @@
% \changes{v2.9}{2016/04/26}{Introduced the \protect\optname{pdftype}
% package option, which enables an author to specify the type of
% document being produced}
+% \changes{v3.0}{2016/07/02}{Made the code compatible with \string\LuaTeX~0.85.
+% Thanks to Robert Schlicht, Leonid Sinev, and David Carlisle for bug
+% reports and to Leonid Sinev for helping test the new
+% \protect\pkgname{hyperxmp} code}
%
% \GetFileInfo{hyperxmp.dtx}
%
-% \DoNotIndex{\!,\",\#,\^,\(,\),\*,\,,\<,\>,\\,\^,\_,\~,\ }
-% \DoNotIndex{\@cons,\@empty,\@ifpackageloaded,\@ifundefined,\@nil}
-% \DoNotIndex{\@tempcnta,\@tempcntb,\MessageBreak,\advance,\afterassignment}
-% \DoNotIndex{\aftergroup,\begingroup,\bgroup,\catcode,\csname,\def,\divide}
-% \DoNotIndex{\edef,\egroup,\else,\endcsname,\endgroup,\expandafter,\fi}
-% \DoNotIndex{\futurelet,\g@addto@macro,\gdef,\global,\if,\ifcase,\ifnum}
-% \DoNotIndex{\ifx,\immediate,\lccode,\let,\loop,\lowercase,\multiply}
-% \DoNotIndex{\newcommand,\noexpand,\or,\relax,\repeat,\space,\string,\the}
-% \DoNotIndex{\toks,\uccode,\uppercase,\usepackage,\xdef}
+% \DoNotIndex{,\,\ ,\!,\",\#,\(,\),\*,\<,\>,\@cons,\@empty}
+% \DoNotIndex{\@ifpackageloaded,\@ifundefined,\@nil,\@tempcnta,\@tempcntb}
+% \DoNotIndex{\MessageBreak,\\,\^,\^,\_,\advance,\afterassignment}
+% \DoNotIndex{\aftergroup,\begin,\begingroup,\bgroup,\catcode,\csname,\def}
+% \DoNotIndex{\divide,\edef,\egroup,\else,\end,\endcsname,\endgroup}
+% \DoNotIndex{\expandafter,\fi,\futurelet,\g@addto@macro,\gdef,\global,\if}
+% \DoNotIndex{\ifcase,\ifnum,\ifx,\immediate,\lccode,\let,\loop,\lowercase}
+% \DoNotIndex{\multiply,\newcommand,\noexpand,\or,\relax,\repeat,\space}
+% \DoNotIndex{\string,\the,\toks,\uccode,\uppercase,\usepackage,\xdef,\~}
%
% ^^A Define a few logical styles.
% \DeclareRobustCommand{\term}[1]{#1\SortIndex{#1}{#1}}
@@ -199,6 +203,28 @@
% \DeclareRobustCommand{\Dvips}{^^A
% \texorpdfstring{Dvips\SortIndex{dvips}{\texttt{dvips}}}{Dvips}^^A
% }
+% \DeclareRobustCommand{\Lua}{^^A
+% Lua\index{Lua}^^A
+% }
+%
+% ^^A Define an environment just like macro but for Lua functions.
+% \makeatletter
+% \newenvironment{luafunc}{^^A
+% \begingroup
+% \catcode`\_=11
+% \def\PrintMacroName##1{\strut\MacroFont\string##1\ }^^A
+% \def\SpecialIndex@##1##2{^^A
+% \@bsphack
+% \special@index{\string##1\actualchar
+% \string\verb\quotechar*\verbatimchar##1\verbatimchar##2}^^A
+% \@esphack
+% }^^A
+% \begin{macro}^^A
+% }{^^A
+% \end{macro}^^A
+% \endgroup
+% }
+% \makeatother
%
% ^^A Pack figures a bit tighter onto the page.
% \renewcommand{\floatpagefraction}{0.8}
@@ -600,18 +626,38 @@
% \end{verbatim}
%
%
-% \paragraph{Note~3: \XeLaTeX\ object compression}
-% \XeLaTeX\ (or, more precisely, the \cmdname{xdvipdfmx} back end),
-% compresses \emph{all} \acro{PDF} objects, including the ones
-% containing \acro{XMP} metadata. While Adobe Acrobat can still detect
-% and utilize the \acro{XMP} metadata, non-\acro{PDF}-aware applications
-% are unlikely to see the metadata. Three options to consider are to
-% (1)~use a different program (e.g.,~\LuaLaTeX), (2)~pass the
-% |--output-driver="xdvipdfmx -z0"| option to \XeLaTeX\ to instruct
-% \cmdname{xdvipdfmx} to turn off all compression (which will of course
-% make the \acro{PDF} file substantially larger), or (3)~postprocess the
-% generated \acro{PDF} file by loading it into the commercial version of
-% Adobe Acrobat and re-saving it with the Save As\dots\ menu option.
+% \paragraph{Note~3: Object compression}
+% One intention of \acro{XMP} is that metadata embedded in a file be
+% readable even without knowledge of the file's format. That is, the
+% metadata are expected to appear as plain text. Although
+% \pkgname{hyperxmp} does its best to honor that intention, it faces
+% a few challenges:
+%
+% \begin{enumerate}
+% \item When run with versions of \LuaLaTeX\ earlier than 0.85,
+% \pkgname{hyperxmp} leaves all \acro{PDF} objects uncompressed. This
+% is due to \LuaLaTeX\ treating object compression as a global
+% parameter, unlike \pdfLaTeX, which treats it as a local parameter.
+% Hence, when \pkgname{hyperxmp} requests that the \acro{XMP} packet
+% be left uncompressed, \LuaLaTeX\ in fact leaves \emph{all}
+% \acro{PDF} streams uncompressed. Beginning with version~3.0,
+% \pkgname{hyperxmp} includes a workaround that correctly leaves only
+% the \acro{XMP} metadata uncompressed, but this workaround is
+% implemented only for \LuaLaTeX\ v0.85 onwards.
+%
+% \item \XeLaTeX\ (or, more precisely, the \cmdname{xdvipdfmx} back end)
+% exhibits the opposite problem. It compresses \emph{all} \acro{PDF}
+% objects, including the ones containing \acro{XMP} metadata. While
+% Adobe Acrobat can still detect and utilize the \acro{XMP} metadata,
+% non-\acro{PDF}-aware applications are unlikely to see the metadata.
+% Three options to consider are to (1)~use a different program
+% (e.g.,~\LuaLaTeX), (2)~pass the |--output-driver="xdvipdfmx -z0"|
+% option to \XeLaTeX\ to instruct \cmdname{xdvipdfmx} to turn off all
+% compression (which will of course make the \acro{PDF} file
+% substantially larger), or (3)~postprocess the generated \acro{PDF}
+% file by loading it into the commercial version of Adobe Acrobat and
+% re-saving it with the Save As\dots\ menu option.
+% \end{enumerate}
%
%
% \paragraph{Note~4: Literal commas}
@@ -723,7 +769,6 @@
%
% \input{einstein-xmp}
%
-%
% \begin{thebibliography}{1}
% \bibitem{Adobe2010:pdfmark}
% Adobe Systems, Inc., San Jose, California.
@@ -2316,13 +2361,13 @@ disabled}%
% The \acro{XMP} specification recommends leaving approximately
% 2000~bytes of whitespace at the end of each \acro{XMP} packet to
% facilitate editing the packet in place~\cite{Adobe2012:XMP}.
-% |\hyxmp@padding| is defined to contain 32~lines of 50~spaces and a
-% newline apiece for a total of 1632 characters of whitespace.
+% |\hyxmp@padding| is defined to contain 32~lines of 63~spaces and a
+% newline apiece for a total of 2048 characters of whitespace.
% \begin{macrocode}
\bgroup
\xdef\hyxmp@xml{}%
\hyxmp@add@to@xml{%
-__________________________________________________^^J%
+_______________________________________________________________^^J%
}
\xdef\hyxmp@padding{\hyxmp@xml}%
\egroup
@@ -2338,18 +2383,28 @@ __________________________________________________^^J%
% \begin{macro}{\hyxmp@pdf@to@xmp@date}
% Convert a timestamp from \acro{PDF}'s
% |D:|\textsc{yyyymmdd}hhmmss|-|\textsc{tt}|'|tt|'| format
-% \expandafter\ifx\csname pdfcreationdate\endcsname\relax
-% \else
-% (e.g.,~\texttt{\pdfcreationdate})
-% \fi
+% \makeatletter
+% \@ifundefined{pdffeedback}{^^A
+% \@ifundefined{pdfcreationdate}{^^A
+% }{^^A
+% (e.g.,~\texttt{\pdfcreationdate})
+% }^^A
+% }{^^A
+% (e.g.,~\texttt{\pdffeedback creationdate})
+% }
+% \makeatother
% to \acro{XMP}'s
% \textsc{yyyy}|-|\textsc{mm}|-|\textsc{dd}|T|hh|:|mm|:|ss|+|\textsc{tt}|:|tt format
% \makeatletter
-% \expandafter\ifx\csname pdfcreationdate\endcsname\relax
-% \unskip
-% \else
-% (e.g.,~\texttt{\expandafter\hyxmp@pdf@to@xmp@date\pdfcreationdate})^^A
-% \fi
+% \@ifundefined{pdffeedback}{^^A
+% \@ifundefined{pdfcreationdate}{^^A
+% \unskip
+% }{^^A
+% (e.g.,~\texttt{\expandafter\hyxmp@pdf@to@xmp@date\pdfcreationdate})^^A
+% }^^A
+% }{^^A
+% (e.g.,~\texttt{\expandafter\hyxmp@pdf@to@xmp@date\pdffeedback creationdate})^^A
+% }^^A
% \makeatother
% ~\cite{Adobe2012:XMP}. This macro is fully expandable.^^A
% \changes{v2.4}{2013/12/24}{Added this macro}
@@ -2413,22 +2468,23 @@ __________________________________________________^^J%
% \end{macro}
%
% \begin{macro}{\hyxmp@today@define}
-% Use \TeX's |\year|, |\month|, and |\day| primitives to define
-% |\hyxmp@today| as today's date in
-% \textsc{yyyy}-\textsc{mm}-\textsc{dd} format.
+% Use \TeX's |\year|, |\month|, and |\day| primitives to define a given
+% macro as today's date in \textsc{yyyy}-\textsc{mm}-\textsc{dd} format.
% \changes{v2.4}{2013/12/21}{Added this macro}
+% \changes{v3.0}{2016/07/03}{Modified to accept the name of a macro
+% to define}
% \begin{macrocode}
-\def\hyxmp@today@define{%
- \xdef\hyxmp@today{\the\year}%
+\def\hyxmp@today@define#1{%
+ \xdef#1{\the\year}%
\ifnum\month<10
- \xdef\hyxmp@today{\hyxmp@today-0\the\month}%
+ \xdef#1{#1-0\the\month}%
\else
- \xdef\hyxmp@today{\hyxmp@today-\the\month}%
+ \xdef#1{#1-\the\month}%
\fi
\ifnum\day<10
- \xdef\hyxmp@today{\hyxmp@today-0\the\day}%
+ \xdef#1{#1-0\the\day}%
\else
- \xdef\hyxmp@today{\hyxmp@today-\the\day}%
+ \xdef#1{#1-\the\day}%
\fi
}
% \end{macrocode}
@@ -2441,11 +2497,25 @@ __________________________________________________^^J%
% timezone from \texttt{\string\string\string\pdfcreationdate}, as
% proposed by Florian Breitwieser}
% \begin{macrocode}
-\expandafter\ifx\csname pdfcreationdate\endcsname\relax
- \hyxmp@today@define
-\else
- \edef\hyxmp@today{\expandafter\hyxmp@pdf@to@xmp@date\pdfcreationdate}%
-\fi
+\@ifundefined{pdffeedback}{%
+ \@ifundefined{pdfcreationdate}{%
+% \end{macrocode}
+% Case 1: Neither |\pdffeedback| nor |\pdfcreationdate| is defined
+% (\XeLaTeX\ and regular \LaTeX).
+% \begin{macrocode}
+ \hyxmp@today@define\hyxmp@today
+ }{%
+% \end{macrocode}
+% Case 2: |\pdfcreationdate| is defined (\pdfLaTeX\ and pre-0.85 \LuaLaTeX).
+% \begin{macrocode}
+ \edef\hyxmp@today{\expandafter\hyxmp@pdf@to@xmp@date\pdfcreationdate}%
+ }%
+}{%
+% \end{macrocode}
+% Case 3: |\pdffeedback| is defined (\LuaLaTeX~0.85+).
+% \begin{macrocode}
+ \edef\hyxmp@today{\expandafter\hyxmp@pdf@to@xmp@date\pdffeedback creationdate}%
+}
% \end{macrocode}
% \end{macro}
%
@@ -2493,8 +2563,23 @@ ___________xmlns:pdf="http://ns.adobe.com/pdf/1.3/">^^J%
}%
\hyxmp@add@simple@var{pdf:Keywords}{@pdfkeywords}%
\hyxmp@add@simple@var{pdf:Producer}{@pdfproducer}%
- \@ifundefined{pdfminorversion}{}{%
- \hyxmp@add@simple{pdf:PDFVersion}{1.\the\pdfminorversion}%
+ \@ifundefined{pdfvariable}{%
+ \@ifundefined{pdfminorversion}{%
+% \end{macrocode}
+% Case 1: Neither |\pdfvariable| nor |\pdfminorversion| is defined
+% (\XeLaTeX\ and regular \LaTeX).
+% \begin{macrocode}
+ }{%
+% \end{macrocode}
+% Case 2: |\pdfminorversion| is defined (\pdfLaTeX\ and pre-0.85 \LuaLaTeX).
+% \begin{macrocode}
+ \hyxmp@add@simple{pdf:PDFVersion}{1.\the\pdfminorversion}%
+ }%
+ }{%
+% \end{macrocode}
+% Case 3: |\pdfvariable| is defined (\LuaLaTeX~0.85+).
+% \begin{macrocode}
+ \hyxmp@add@simple{pdf:PDFVersion}{1.\the\pdfvariable minorversion}%
}%
\hyxmp@add@to@xml{%
______</rdf:Description>^^J%
@@ -2799,21 +2884,58 @@ ______</rdf:Description>^^J%
% \subsubsection{The XMP Basic schema}
% \label{sec:xmp-basic}
%
+% \begin{macro}{\hyxmp@define@createdate}
+% \begin{macro}{\hyxmp@createdate}
+% Define |\hyxmp@createdate| as the document's creation date but in
+% \acro{XMP} date format, not \acro{PDF} date format. We use
+% |\hyxmp@createdate| for the \xmpterm{CreateDate},
+% \xmpterm{ModifyDate}, and \xmpterm{MetadataDate} fields.
+% \begin{macrocode}
+\newcommand*{\hyxmp@define@createdate}{%
+ \@ifundefined{pdffeedback}{%
+ \@ifundefined{pdfcreationdate}{%
+% \end{macrocode}
+% Case 1: Neither |\pdffeedback| nor |\pdfcreationdate| is defined
+% (\XeLaTeX\ and regular \LaTeX).
+% \begin{macrocode}
+ \hyxmp@today@define\hyxmp@createdate
+ }{%
+% \end{macrocode}
+% Case 2: |\pdfcreationdate| is defined (\pdfLaTeX\ and pre-0.85 \LuaLaTeX).
+% \begin{macrocode}
+ \edef\hyxmp@createdate{\expandafter\hyxmp@pdf@to@xmp@date\pdfcreationdate}%
+ }%
+ }{%
+% \end{macrocode}
+% Case 3: |\pdffeedback| is defined (\LuaLaTeX~0.85+).
+% \begin{macrocode}
+ \edef\hyxmp@createdate{\expandafter\hyxmp@pdf@to@xmp@date\pdffeedback creationdate}%
+ }%
+}
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
% \begin{macro}{\hyxmp@xmp@basic@schema}
% Add properties defined by the \acro{XMP} Basic schema to the
% |\hyxmp@xml| macro. These include a bunch of dates (all set to the
% same value) and the base \acro{URL} for the document if specified with
% \optname{baseurl}.
% \changes{v2.0}{2012/08/26}{Added this macro}
+% \changes{v3.0}{2016/07/04}{Made the \protect\acro{XMP}
+% \protect\xmpterm{CreateDate}, \protect\xmpterm{ModifyDate}, and
+% \protect\xmpterm{MetadataDate} match the \protect\acro{PDF}
+% \protect\pdfterm{CreationDate}}
% \begin{macrocode}
\newcommand*{\hyxmp@xmp@basic@schema}{%
\hyxmp@add@to@xml{%
______<rdf:Description rdf:about=""^^J%
____________xmlns:xmp="http://ns.adobe.com/xap/1.0/">^^J%
}%
- \hyxmp@add@simple{xmp:CreateDate}{\hyxmp@today}%
- \hyxmp@add@simple{xmp:ModifyDate}{\hyxmp@today}%
- \hyxmp@add@simple{xmp:MetadataDate}{\hyxmp@today}%
+ \hyxmp@define@createdate
+ \hyxmp@add@simple{xmp:CreateDate}{\hyxmp@createdate}%
+ \hyxmp@add@simple{xmp:ModifyDate}{\hyxmp@createdate}%
+ \hyxmp@add@simple{xmp:MetadataDate}{\hyxmp@createdate}%
\hyxmp@add@simple{xmp:CreatorTool}{\@pdfcreator}%
\hyxmp@add@simple{xmp:BaseURL}{\@baseurl}%
\hyxmp@add@to@xml{%
@@ -3205,22 +3327,27 @@ ___</rdf:RDF>^^J%
\ifx\hyxmp@driver\Hy@driver
\hyxmp@embed@packet@pdftex
\else
- \def\hyxmp@driver{hdvipdfm}%
+ \def\hyxmp@driver{hluatex}%
\ifx\hyxmp@driver\Hy@driver
- \hyxmp@embed@packet@dvipdfm
+ \hyxmp@embed@packet@luatex
\else
- \def\hyxmp@driver{hxetex}%
+ \def\hyxmp@driver{hdvipdfm}%
\ifx\hyxmp@driver\Hy@driver
- \hyxmp@embed@packet@xetex
+ \hyxmp@embed@packet@dvipdfm
\else
- \@ifundefined{pdfmark}{%
- \PackageWarningNoLine{hyperxmp}{%
- Unrecognized hyperref driver `\Hy@driver'.\MessageBreak
- \jobname.tex's XMP metadata will *not* be\MessageBreak
- embedded in the resulting file}%
- }{%
- \hyxmp@embed@packet@pdfmark
- }%
+ \def\hyxmp@driver{hxetex}%
+ \ifx\hyxmp@driver\Hy@driver
+ \hyxmp@embed@packet@xetex
+ \else
+ \@ifundefined{pdfmark}{%
+ \PackageWarningNoLine{hyperxmp}{%
+ Unrecognized hyperref driver `\Hy@driver'.\MessageBreak
+ \jobname.tex's XMP metadata will *not* be\MessageBreak
+ embedded in the resulting file}%
+ }{%
+ \hyxmp@embed@packet@pdfmark
+ }%
+ \fi
\fi
\fi
\fi
@@ -3232,7 +3359,8 @@ ___</rdf:RDF>^^J%
% \subsubsection{Embedding using \pdfTeX}
%
% \begin{macro}{\hyxmp@embed@packet@pdftex}
-% Embed the \acro{XMP} packet using \pdfTeX\ primitives.
+% Embed the \acro{XMP} packet using \pdfTeX\ primitives, which are
+% supported by both \pdfTeX\ and pre-0.85 \LuaTeX.
% \begin{macrocode}
\newcommand*{\hyxmp@embed@packet@pdftex}{%
\bgroup
@@ -3247,6 +3375,52 @@ ___</rdf:RDF>^^J%
% \end{macrocode}
% \end{macro}
%
+% \subsubsection{Embedding using \LuaTeX~0.85+}
+%
+% If we're running \LuaLaTeX~0.85+ we apparently need to use \Lua\
+% directly to leave uncompressed the \acro{PDF} object holding the
+% \acro{XMP} packet. The \pkgname{luacode} package facilitates the
+% inclusion of Lua code in a \LaTeX\ document.
+% \begin{macrocode}
+\expandafter\ifx\csname pdffeedback\endcsname\relax
+\else
+ \RequirePackage{luacode}%
+% \end{macrocode}
+%
+% \begin{luafunc}{hyxmp_embed_packet}
+% We define a \Lua\ function, |hyxmp_embed_packet|, that embeds a string
+% as an uncompressed \acro{PDF} object of tyoe \xmpterm{Metadata}.
+% \changes{v3.0}{2016/07/02}{Added this \protect\Lua\ function}
+% \begin{macrocode}
+ \begin{luacode*}
+ function hyxmp_embed_packet (contents)
+ local n = pdf.obj {
+ type = "stream",
+ attr = [[
+/Type /Metadata
+/Subtype /XML
+ ]],
+ compresslevel = 0,
+ string = contents
+ }
+ pdf.refobj(n)
+ end
+ \end{luacode*}
+\fi
+% \end{macrocode}
+% \end{luafunc}
+%
+% \begin{macro}{\hyxmp@embed@packet@luatex}
+% Embed the \acro{XMP} packet using \LuaTeX~0.85+ primitives.
+% \changes{v3.0}{2016/07/02}{Added this macro}
+% \begin{macrocode}
+\newcommand*{\hyxmp@embed@packet@luatex}{%
+ \luadirect{hyxmp_embed_packet(\luastring{\hyxmp@xml})}%
+ \pdfextension catalog {/Metadata \the\numexpr\pdffeedback lastobj\relax\space 0 R}%
+}
+% \end{macrocode}
+% \end{macro}
+%
% \subsubsection{Embedding using any \texttt{pdfmark}-based backend}
%
% \begin{macro}{\hyxmp@embed@packet@pdfmark}