From b09e7454f87f22dff8dd6f5fa2a085f1295532d4 Mon Sep 17 00:00:00 2001
From: Karl Berry <karl@freefriends.org>
Date: Wed, 11 May 2016 21:27:08 +0000
Subject: pdfx (11may16)

git-svn-id: svn://tug.org/texlive/trunk@41039 c570f23f-e606-0410-a88d-b1316a301751
---
 Master/texmf-dist/source/latex/pdfx/pdfx.dtx | 3250 ++++++++++++++++++++++----
 1 file changed, 2765 insertions(+), 485 deletions(-)

(limited to 'Master/texmf-dist/source/latex/pdfx/pdfx.dtx')

diff --git a/Master/texmf-dist/source/latex/pdfx/pdfx.dtx b/Master/texmf-dist/source/latex/pdfx/pdfx.dtx
index 186e2f8abb7..ffd326defab 100644
--- a/Master/texmf-dist/source/latex/pdfx/pdfx.dtx
+++ b/Master/texmf-dist/source/latex/pdfx/pdfx.dtx
@@ -19,14 +19,33 @@
 %
 % \fi
 %
-% \CheckSum{2209}
+% \CheckSum{3863}
 % \iffalse
 %
 %<*driver>
-\documentclass[a4paper]{ltxdoc}
+\pdfcompresslevel 9
 \providecommand{\pdfxopt}{a-2u}
-\usepackage{rvdtx}
+\providecommand{\thisyear}{2016}
+\begin{filecontents*}{./\jobname.xmpdata}
+\Title{Generation of PDF/X- and PDF/A-compliant PDFs with pdfTeX \textemdash\ pdfx.sty}
+\Author{\CVR\sep \Thanh\sep Ross~Moore\sep Peter Selinger}
+\Subject{This package supports generation of PDF/X-, PDF/A- and PDF/E-compliant documents, in most of their variants, using pdfLaTeX, LuaLaTeX and XeLaTeX.}
+\Keywords{PDF/X-, PDF/A- and PDF/E-compliance\sep Multilingual Metadata\sep installation\sep \TeX Live \thisyear}
+\PublicationType{manual}
+\Copyright{Public domain.\textLF An earlier version of this documentation was published as: TUGboat 36, No.2, pp.136\textendash 142 (2015)}
+\Copyrighted{False}
+\CopyrightURL{http://tug.org/texlive/}
+\CoverDisplayDate{May \thisyear}
+\CoverDate{\thisyear-05-03}
+\CreatorTool{pdfTeX + pdfx.sty with option \pdfxopt, from TeX Live 2016}
+\pdfxEnableCommands{%
+ \def\CVR{C.V. Radhakrishnan}\def\Thanh{H^^c3^^a0n Th\eee Thanh}%
+ \def\eee{^^c3^^aa^^cc^^81 }}
+\end{filecontents*}
+\documentclass[a4paper]{ltxdoc}
 \usepackage[\pdfxopt]{pdfx}
+\usepackage{rvdtx}
+\usepackage{graphicx}
 \usepackage[T1]{fontenc}
 \hypersetup{citecolor=blue}
 \EnableCrossrefs         
@@ -99,16 +118,27 @@
 %   removed spurious '?' in XMP packets; improved handling of Color Profiles;
 %   ensure  Hy@pdfatrue  when building PDF/A, for link flags;
 %   properly enables  xcolor  conversion of color models.}
+% \changes{v1.5.7}{2016/02/17}{Removed UTF-8 characters that appear in 
+%   the documentation only, within comments in the package source,
+%   but result in a validation failure. Language support in XMP metadata.
+%   Added macros for Windows and Mac system color profile directories.}
+% \changes{v1.5.8}{2016/05/03}{MediaBox, TrimBox, etc. derived from
+%   the paperheight, paperwidth. Improved language support, incl. KOI8-R
+%   encoded cyrillics, Armenian OT6, and LGR Greek encoding, incl. polytonic Greek.
+%   All the encodings Latin-1--9 are supported for upper 8-bit characters.
+%   Fixed the quoted file-name problem, evident with LuaTeX.
+%   Method to generate correct bookmarks with non-active (transliterated) input.
+%   Added support for XeLaTeX, improvements with LuaTeX. Updated documentation.} 
 %
 % \title{Generation of PDF/X- and PDF/A-compliant PDFs
 %  with pdf\TeX{} --- \texttt{pdfx.sty}}
-% \date{2016/02/05}
-% \version{1.5.6}
-% \keywords{PDF, PDF/A, PDF/X, pdf\TeX, \LaTeX}
+% \date{2016/05/03}
+% \version{1.5.8}
+% \keywords{PDF, PDF/A, PDF/X, pdf\TeX, \LaTeX, Multilingual Metadata}
 % \author{C.\,V.\,Radhakrishnan, \Thanh, Ross~Moore {\upshape\small
 % and} Peter Selinger}
-% \contact{\texttt{[cvr,thanh]@river-valley.org},
-% \texttt{ross.moore@mq.edu.au}, \texttt{selinger@mathstat.dal.ca}}
+% \contact{\texttt{[cvr,thanh]@river-valley.org},\\%
+% \texttt{ross.moore@mq.edu.au}, \texttt{selinger@mathstat.dal.ca}\hss}
 % 
 % \maketitle
 %
@@ -117,15 +147,20 @@
 % \section[Introduction]{Introduction}
 %
 % This package\footnote{A slightly earlier version of this documentation 
-% was published as \cite{pdfx}.}
-% currently supports generation of PDF/X- and 
-% PDF/A-compliant documents using \pdftex, in some of their variants. 
-% Support for additional standards, such as PDF/E, PDF/VT 
-% is also available; see the complete list in Section~\ref{ssec-options} below. 
+% was published as \cite{pdfx}. All the changes since then have been developed
+% and coded by the 3rd-listed author.}
+% currently supports generation of PDF/X-, PDF/A- and PDF/E-compliant 
+% documents,  using \pdftex, in most of their variants;
+% see the complete list in Section~\ref{ssec-options} below.
+% As of \TeX\,Live 2016 it now also works with Lua\LaTeX\ and Xe\LaTeX,
+% when using appropriate command-line options\footnote{%
+% The required invokation is:\quad
+%  |xelatex --shell-escape -output-driver="xdvipdfmx -z 0" <filename>.tex |}, but
+% with some limitations --- see Sections~\ref{sssec-xetex} and \ref{sssec-luatex}.
 % By `supports', we mean that the package provides correct and sufficient  
 % means to declare that a document conforms with a stated PDF variant
-% (PDF/X, PDF/A, PDF/E, PDF/VT, etc.) along with the version 
-% and/or level of conformance.
+% (PDF/X, PDF/A, PDF/E, PDF/VT, etc.) along with the version and/or 
+% level of conformance.
 % This package also allows appropriate metadata and color profile
 % to be specified, according to the requirements of the PDF variant.
 %
@@ -135,7 +170,8 @@
 % information as well as a large range of optional data, a fully validating
 % PDF file cannot be achieved. The PDF can be created, having the correct
 % visual appearance on all pages, but it will not pass validation checks.
-% Section~\ref{ssec-metadata} describes how this file should be constructed.
+% Sections~\ref{ssec-metadata} and \ref{ssec-multi} describe 
+% how this file should be constructed.
 %
 % \medskip
 % What this package \emph{does not} do is to check for all the details
@@ -152,7 +188,6 @@
 % However, with extra \pdftex-based software that \emph{is} capable 
 % of producing `Tagged PDF', this package can be used as part of 
 % the overall workflow to produce fully conforming documents.
-% It is also reported to have been successfully used with Lua\TeX. 
 %
 %
 % \subsection{PDF standards}\label{ssec-standards}
@@ -194,8 +229,13 @@
 % The others are the subject of further work; revised versions of this
 % package can be expected in later years.
 %
+% More complete descriptions of these standards and their usage can be
+% found on Wikipedia pages~\cite{wikiPDF}. These pages also include
+% comprehensive links to web resources, guides, commentaries, discussions
+% and whatever else is relevant to how the standards have been established
+% and how they can be used.
 %
-% \section[Usage]{Usage}
+% \section[Usage]{Usage}\label{sec-usage}
 %
 % The package can be loaded with the command:
 % \begin{decl}
@@ -279,9 +319,9 @@
 % PDF/X is an ISO standard intended for graphics interchange. It
 % emphasizes printing-related requirements, such as embedded fonts and
 % color profiles. The PDF/X standard has a large number of variants
-% and conformance levels. The basic variants are known as X-1, X-1a,
+% and conformance levels. The basic variants are X-1, X-1a,
 % X-3, X-4, and X-5. (Note that a revised version of the X-2 standard 
-% was published in 2003, but withdrawn as an ISO standard in 2011, 
+% was published in 2003 but withdrawn as an ISO standard in 2011, 
 % basically due to lack of interest in using it). 
 % The PDF/X-1a standard exists in revisions of 2001 and 2003, 
 % the PDF/X-3 standard exists in revisions of 2002 and 2003, 
@@ -326,39 +366,109 @@
 %   experimental and may break with future updates to the |xmpincl|
 %   package.
 % \item |noBOM|: do not generate the optional byte-order marker. (default)
+% \item |noerr|: avoids stopping when making PDF/X with an RGB profile,
+%  and at other unusual situations.
 % \item |pdf13|: use PDF 1.3, overriding the version specified by the
-% applicable standard. This may produce a non-standard-conforming PDF file.
+% applicable standard.\\This may produce a non-standard-conforming PDF file.
 % \item |pdf14|: use PDF 1.4, overriding the version specified by the
-% applicable standard. This may produce a non-standard-conforming PDF file.
+% applicable standard.\\This may produce a non-standard-conforming PDF file.
 % \item |pdf15|: use PDF 1.5, overriding the version specified by the
-% applicable standard. This may produce a non-standard-conforming PDF file.
+% applicable standard.\\This may produce a non-standard-conforming PDF file.
 % \item |pdf16|: use PDF 1.6, overriding the version specified by the
-% applicable standard. This may produce a non-standard-conforming PDF file.
+% applicable standard.\\This may produce a non-standard-conforming PDF file.
 % \item |pdf17|: use PDF 1.7, overriding the version specified by the
-% applicable standard. This may produce a non-standard-conforming PDF file.
+% applicable standard.\\This may produce a non-standard-conforming PDF file.
 % \end{itemize} 
 %
+% \subsubsection{XMP language options}\label{ssec-xmplang}
+%
+% These options allow for characters in alphabets other than those  
+% used for English and Western European languages to be used 
+% within the |.xmpdata| file (see Section~\ref{ssec-metadata}), 
+% supported through \LaTeX\ character representation macros.
+% \begin{itemize}
+% \item |latxmp|: extended Latin blocks, |Ux0180|--|Ux024F| 
+%    and |Ux1E00|--|Ux1EFF| 
+% \item |armxmp|: armenian letters and ligatures, |Ux0530|--|Ux058F|, 
+%    via macros |\armyba|, |\armfe|, |\armcomma|, etc.
+% \item |cyrxmp|: cyrillic letters and accents, |Ux0400|--|Ux04FF|
+%    and |Ux0500|--|Ux0527| via macros |\cyra|, |\CYRN|, etc.
+% \item |grkxmp|: greek letters and diacritics, |Ux0370|--|Ux03FF|
+%    and |Ux1F00|--|Ux1FFF| via macros |\textalpha|, |\textPi|, etc.
+% \item |hebxmp|: some hebrew letters and marks, |Ux05C0|--|Ux05F4|
+%    via macros |\hebalef|, |\hebtav|, |\doubleyod|, etc.
+% \item |arbxmp|: some arabic letters and marks, |Ux0600|--|Ux06FF|
+%    via macros |\hamza|, |\alef|, |\sukun|, etc.
+% \item |vnmxmp|: vietnamese letters and accents, |Ux1EA0|--|Ux1EFF|
+%    via macros |\abreve|, |\uhorn|, |\ECIRCUMFLEX|, etc.
+% \item |ipaxmp|: phonetic extensions, |Ux0250|--|Ux02AF|
+%    and |Ux1D00|--|Ux1DFF|
+% \item |mathxmp|: mathematical letters, symbols, operators 
+%    arrows, alphanumeric forms. 
+% \item |allxmp|: all of the above, as well as those listed next.
+% \end{itemize}
+% The characters supported by these options include those supported
+% by |hyperref.sty| via the |PDFdoc| encodings (|PD1| and |PU|)
+% for inclusion in PDF files. Extra supported is provided for math
+% alphabets. For Armenian, the macros defined by Arm\TeX\ are supported.
+%
+% \medskip
+% Further options allow direct (enclosed) input of upper 8-bit
+% characters, from encodings such as Latin-1--Latin-9, KOI8-R,
+% LGR (Greek), ArmSSCI8, and a few more.
+% Use of these requires a carefully controlled parsing regime. 
+% Here we list the package options that declare such content
+% may be present in the |.xmpdata| file.
+% A detailed account of how these are used is given 
+% in~Section~\ref{ssec-multi} (``Multilingual Metadata'').
+% \begin{itemize}
+% \item |LATxmp|: support for direct use of the upper-range characters 
+%  (byte codes 160--255) for input encodings Latin1--Latin9, for
+%  Latin-based alphabets as used in European countries and elsewhere.
+%  This defines parser macros |\textLAT|, |\textLII|, \dots, |\textLIX|.
+%  All support from |latxmp| is loaded also.
+% \item |KOIxmp|: support for direct use of cyrillic letters by use
+%  of upper-range characters (byte codes 148--255) under input
+%  encodings KOI8-R and KOIR8-RU, using |\textKOI| as parser macro.
+%  All support from |cyrxmp| is loaded also.
+% \item |LGRxmp|: support for greek letters entered using either 
+%  the LGR input transliteration of ASCII characters, or the ISO-8859-7
+%  encoding of upper-range characters (byte codes 160--255),
+%  or a combination of both, using |\textLGR| as parser macro.
+%  All support from |grkxmp| is loaded also.
+% \item |AR8xmp|: support for armenian letters entered using the
+%  Arm\TeX~2.0 input transliteration of ASCII characters, or the
+%  ArmSCII8 encoding of upper-range characters (byte codes 160--255),
+%  or a combination of both, using |\textARM| as parser macro. 
+%  All support from |armxmp| is loaded also.
+% \end{itemize}
+% These `parser' options have received limited testing, so please 
+% report any mistakes in the UTF-8 output that you may encounter.
+%
 % \subsection{Data file for metadata}\label{ssec-metadata}
 %
 % As mentioned above, standards-compliant PDF documents require metadata
-% to be included. The |pdfx| package expects the metadata to be
+% to be included. The |pdfx| package expects metadata be
 % supplied in a special data file called |\jobname.xmpdata|. Here,
 % |\jobname| is usually the basename of the document's main |.tex|
 % file. For example, if your document source is in the file
 % |main.tex|, then the metadata must be in a file called
 % |main.xmpdata|. None of the individual metadata fields are
 % mandatory, but for most documents, it makes sense to define at least
-% the title and the author. Here is an example of a short |.xmpdata|
-% file:
-% \begin{verbatim}
-%   \Title{Baking through the ages}
-%   \Author{A. Baker\sep C. Kneader}
-%   \Keywords{cookies\sep muffins\sep cakes}
-%   \Publisher{Baking International}
-% \end{verbatim}
+% the title and the author. For more technical aspects of metadata
+% and its uses, consult the work of the Dublin Core Initiative~\cite{DC}
+% and PRISM~\cite{PRISM}.
+%
+% Here is a short |.xmpdata| file:
+% \begin{decl}[]
+%   |\Title{Baking through the ages}|\\
+%   |\Author{A. Baker\sep C. Kneader}|\\
+%   |\Keywords{cookies\sep muffins\sep cakes}|\\
+%   |\Publisher{Baking International}|
+% \end{decl}
 % You should note that multiple authors and keywords have been separated
-% by |\sep|. The |\sep| macro is only permitted in within the
-% |\Author|, |\Keywords|, and |\Publisher| fields.
+% by |\sep|. This |\sep| macro serves a technical purpose and is only 
+% permitted within the |\Author|, |\Keywords|, and |\Publisher| fields.
 %
 % After processing, the local directory contains a file named such as
 % |pdfa.xmpi| or |pdfx.xmpi| according to the PDF variant required.
@@ -367,15 +477,55 @@
 % \href{http://www.pdflib.com/knowledge-base/xmp-metadata/free-xmp-validator/}{www.pdflib.com}.
 % 
 % \textbf{Warning}: The |\jobname.xmpdata| file may be included in the
-% main document source, within a |{filecontents}| environment, 
+% main document source, within a |{filecontents*}| environment, 
+% provided this comes \emph{before} the |\documentclass| command, as follows.
+% \begin{decl}[]
+% |\begin{filecontents*}{\jobname.xmpdata}|\\
+% |  \Title{Baking through the ages}|\\
+% |  \Author{A. Baker\sep C. Kneader}|\\
+% |  \Keywords{cookies\sep muffins\sep cakes}|\\
+% |  \Publisher{Baking International}|\\
+% |\end{filecontents*}|\\
+% |\documentclass[11pt,a4paper]{article}|\\
+% |...|
+% \end{decl}
+% Including the metadata with the \LaTeX\ source is very convenient.
+% Having it at the top of the file also brings attention to it, placing
+% emphasis on the desirability of including metadata, and keeping it
+% accurate while the main content of the document is subject to changes 
+% or revision. Macro definitions can also occur prior to the |\documentclass|
+% command, including any that may be needed within the metadata. An example
+% of this is apparent in Figure~\ref{koi8-code} occurring later.
+%
+% However, this ordering is also extremely important, else any non-ascii 
+% UTF-8 byte sequences can become active characters and expand upon data 
+% being written out, rather than remaining as inactive bytes.
+% If you edit the metadata supplied this way, remember to remove the
+% existing copy of |\jobname.xmpdata| file before the next processing run,
+% as \LaTeX\ does not write a new copy of the file when it exists on disk
+% already, within the current working directory or elsewhere that \LaTeX\ may find.
+% In development or testing situations the filename may need to be given as
+% |./\jobname.xmpdata|, else an older version may be loaded in error.
+% 
+% Experienced users/programmers can employ the \verb|\write18| mechanism%
+% \footnote{If you don't already know what this is, they you probably 
+% should not try using it |:-)|.}, together with the |--shell-escape| command-line 
+% option, to automatically execute a shell command that removes |\jobname.xmpdata| 
+% on every (or on selected) processing runs. 
+% This is only useful when the metadata changes, for whatever reason.
+%
+% \medskip
+% Other places for the |{filecontents*}| environment can work, 
 % but \emph{only} when it contains \emph{no} non-ascii UTF-8 byte sequences.
-% See Section~\ref{ssec-symbols} below for more information.
+% See Section~\ref{ssec-symbols} below for more information on the macros
+% that can be safely used within |.xmpdata| metadata files.
 % 
 % \subsection{List of supported metadata fields}
 % 
 % Here is a complete list of user-definable metadata fields currently
-% supported, and their meanings. More may be added in the future.
-% These commands can only be used in the |.xmpdata| file.
+% supported, and the kind of information they convey. 
+% More may be added in the future.
+% These commands can \emph{only} be used within the |.xmpdata| file.
 % 
 % \subsubsection{General information:}
 % 
@@ -385,10 +535,11 @@
 % \item |\Title|: the document's title.
 % \item |\Keywords|: list of keywords, separated with |\sep|.
 % \item |\Subject|: the abstract.
-% \item |\Publisher|: the publisher.
+% \item |\Publisher|: the publisher. Multiple pieces in a publishing
+%  chain should be separated with |\sep|.
 % \end{itemize}
 %
-% \subsubsection{Copyright information:}
+% \subsubsection{Copyright information:}\label{sssec-copy}
 %
 % \begin{itemize}
 % \item |\Copyright|: a copyright statement.
@@ -396,13 +547,16 @@
 %   and/or rights statement for this document.
 % \item |\Copyrighted|: `True' if the document is copyrighted, 
 %  and `False' if it isn't. This is automatically set to `True' 
-%  if either |\Copyright| or |\CopyrightURL| is specified, but can 
-%  be overridden. For example, if the copyright statement is 
-%  `Public Domain', this should be set to `False'.
+%  if either |\Copyright| or |\CopyrightURL| is specified, but this 
+%  can be overridden. 
+%  For example, if the copyright statement is `Public Domain', 
+%  then specify also |\Copyrighted{False}|.
 % \end{itemize}
 % 
-% \subsubsection{Publication information:}
-%
+% \subsubsection{Publication information:}\label{sssec-publ}
+% The following macros allow for inclusion of metadata fields, 
+% as specified by the Dublin Core Initiative~\cite{DC}
+% and by PRISM~\cite{PRISM} to meet publishing requirements. 
 % \begin{itemize}
 % \item |\PublicationType|: The type of publication. If defined, must
 %   be one of `book', `catalog', `feed', `journal', `magazine', `manual',
@@ -424,8 +578,10 @@
 %   as a human-readable text string.
 % \item |\CoverDate|: Date on the cover of the journal issue, in a
 %   format suitable for storing in a database field with a `date'
-%   data type; e.g. YYYY-MM, or YYYY-MM-DD.
+%   data type; e.g. |YYYY-MM|, or |YYYY-MM-DD|.
 % \end{itemize}
+% This is an area which can be expanded, to deal with more kinds
+% of publication.
 %
 % \subsubsection{Backward Compatibility}
 % The following macros are also recognised, for backward compatibility 
@@ -440,8 +596,7 @@
 % \subsection{Symbols permitted in metadata}\label{ssec-symbols}
 %
 % Within the metadata, all printable ASCII characters except
-% |\|, |{|, |}| and |%| 
-% represent themselves. Also, all printable
+% |\|, |{|, |}| and |%| represent themselves. Also, all printable
 % Unicode characters from the basic multilingual plane (i.e., up to
 % code point U+FFFF) can be used directly with the UTF-8 encoding.
 % (Please note: encodings other than UTF-8 are not currently supported
@@ -459,10 +614,10 @@
 % \item |\copyright|:   the copyright symbol \textcopyright
 % \end{itemize}
 % The macro |\sep| is only permitted within |\Author|, |\Keywords|,
-% and |\Publisher|. It's intention is to separate multiple authors,
-% keywords, etc. However for validation purposes, multiple authors
-% and keywords must not really be separated. The package takes care
-% of this, even when |\sep| is used.
+% and |\Publisher|. It's purpose is to separate multiple authors,
+% keywords, etc. appropriately and consistently in the different ways
+% that such information is represented within the PDF file. 
+% The package takes care of this when |\sep| is used.
 %
 % \medskip
 % Other \TeX\ macros actually can be used, provided the author is very 
@@ -472,24 +627,23 @@
 % perhaps with a simple parameter. A special macro |\pdfxEnableCommands{...}| 
 % is provided to help resolve difficulties that may arise.
 %
-% Here is an example of the use of |\pdfxEnableCommands|, which occurs 
-% with the name of one of our authors {(H\`an Th\'{\^e} Thanh)} 
+% Here is an example\footnote{ Other use cases are discussed with regard to
+% Figures~\ref{arm-code} and \ref{math-wflow}.} of the use of |\pdfxEnableCommands|, 
+% which occurs with the name of one of our authors {(H\`an Th\'{\^e} Thanh)} 
 % due to the doubly-accented letter \'{\^e}.
 % It is usual to define a macro such as: |\def\thanh{H\`an Th\'{\^e} Thanh}|.
-%
 % In previous versions of the |pdfx| package, use of such a macro 
 % within the |.xmpdata| file, in the |Copyright| information say,
 % could result in the accent macros expanding into internal primitives, such as 
-% \begin{verbatim}
-%  H\unhbox \voidb@x \bgroup \let \unhbox \voidb@x \setbox \@tempboxa ...
-% \end{verbatim}
-% \removelastskip\noindent
+% \begin{decl}[]
+% | H\unhbox \voidb@x \bgroup \let \unhbox \voidb@x \setbox \@tempboxa ... |
+% \end{decl}
 % going on for many lines. This clearly has no place within the XMP Metadata.
 % To get around this, one could try using simplified macro definitions
-% \begin{verbatim}
-%   \pdfxEnableCommands{
-%       \def\`#1{#1^^cc^80}\def\'#1{#1^^cc^81}\def\^#1{#1^^cc^82}}
-% \end{verbatim}
+% \begin{decl}[]
+% |  \pdfxEnableCommands{|\\
+% |      \def\`#1{#1^^cc^80}\def\'#1{#1^^cc^81}\def\^#1{#1^^cc^82}}|
+% \end{decl}
 % \removelastskip\noindent
 % where the |^^cc^80|, |^^cc^81|, |^^cc^82| cause \TeX\ to generate the correct 
 % UTF-8 bytes for `combining accent' characters.
@@ -497,10 +651,10 @@
 % This works fine for metadata fields that appear just in the XMP packet.
 % However, it is not sufficient for the PDF |/Author| key, which must exactly match
 % with the |dc:creator| Metadata element. What is needed instead is
-% \begin{verbatim}
-%   \pdfxEnableCommands{
-%        \def\thanh{H^^c3^^a0n Th\eee Thanh}\def\eee{^^c3^^aa^^cc^^81 }}
-% \end{verbatim}
+% \begin{decl}[]
+% |  \pdfxEnableCommands{|\\
+% |       \def\thanh{H^^c3^^a0n Th\eee Thanh}\def\eee{^^c3^^aa^^cc^^81 }}|
+% \end{decl}
 % \removelastskip\noindent
 % or the above with `\`a' typed directly as UTF-8 instead of |^^c3^^a0| 
 % and `\^e' in UTF-8 for |^^c3^^aa|.
@@ -510,25 +664,26 @@
 % If the Metadata does not have the same, irrespective of Unicode normalisation, 
 % then validation fails.
 %
-% With this latest version (1.5.6) of the |pdfx| package, such difficulties
+% With version (1.5.6) of the |pdfx| package, such difficulties
 % have been overcome, at least for characters used in Western European, 
 % Latin-based languages. The input encoding used when reading the |.xmpdata| 
 % file now includes interpretations of \TeX's usual accent commands to 
 % produce the required UTF-8 byte sequences.
-% Work is ongoing to extend this input encoding to include macro definitions 
-% for more special characters (e.g., extended Latin, Cyrillic, Greek, etc.). 
+%
+% \medskip
+% This current version (1.5.8) now extends this input encoding to include 
+% macro definitions covering \LaTeX's internal character representation
+% of other alphabets (e.g., extended Latin, Cyrillic, Greek, etc.).
+% However this can become memory intensive, requiring a large number of
+% macro definitions, most of which will never be used. So loading options
+% are provided, enabling a document author to choose only those that may
+% be relevant. Currently these are as in Section~\ref{ssec-xmplang}.
+%
 % A significant portion of the Unicode Basic Plane characters can be covered
 % this way. Modules could even be provided for CJK character sets and 
-% mathematical symbols, etc. However, this can become memory intensive,
-% so significant testing will be required before this becomes a standard
+% mathematical symbols, etc. However, as this can become memory intensive,
+% significant testing will be required before these become a standard
 % part of the |pdfx| package. 
-% 
-% \textbf{Warning}: This encoding of macros, using ascii characters only,
-% allows for the convenience of including the |\jobname.xmpdata| file 
-% in the main \LaTeX\ source preamble, within a |{filecontents}| environment.
-% This \emph{only} works when it contains \emph{no} non-ascii UTF-8 byte 
-% sequences. The |{filecontents}| environment is best placed immediately
-% \emph{before} the |\usepackage[...]{pdfx}| command.
 %
 % 
 % \subsection{Color profiles}
@@ -551,9 +706,12 @@
 % For users who have a specific color profile they wish to use, it is
 % possible to do so by including a |\setRGBcolorprofile| or
 % |\setCMYKcolorprofile| command in the |.xmpdata| file. Note that
-% PDF/A and PDF/E require an RGB color profile, and PDF/X and PDF/VT
-% require a CMYK color profile. Use the following commands to specify
-% an RGB or CMYK color profile, respectively:
+% PDF/A and PDF/E require a profile of type `|mnrt|' (monitor) which 
+% is usually an RGB color profile, while PDF/X and PDF/VT require type `|prtr|' 
+% (printer) which is usually a CMYK color profile; but valid documents
+% can be created with the correct type designed for the other color space.
+% Use the following commands to specify an RGB or CMYK color profile, 
+% respectively:
 % 
 % \begin{decl}
 % \defmacro{setRGBcolorprofile}\marg{filename}\marg{identifier}\marg{info
@@ -565,18 +723,16 @@
 % Within the arguments of these macros, the characters |<|, |>|, |&|,
 % |^|, |_|, |#|, |$|, and |~| can be used as themselves, but
 % |%| must be escaped as |\%|. The defaults are:
-% \begin{verbatim}
-% \setRGBcolorprofile{sRGB_IEC61966-2-1_black_scaled.icc}
-%                    {sRGB_IEC61966-2-1_black_scaled}
-%                    {sRGB IEC61966 v2.1 with black scaling}
-%                    {http://www.color.org}
-%
-% \setCMYKcolorprofile{coated_FOGRA39L_argl.icc}
-%                     {Coated FOGRA39}
-%                     {FOGRA39 (ISO Coated v2 300\% (ECI))}
-%                     {http://www.argyllcms.com/}
-% \end{verbatim}
-%
+% \begin{decl}[]
+% |\setRGBcolorprofile{sRGB_IEC61966-2-1_black_scaled.icc}|\\
+% |                   {sRGB_IEC61966-2-1_black_scaled}|\\
+% |                   {sRGB IEC61966 v2.1 with black scaling}|\\
+% |                   {http://www.color.org}|\\[4pt]
+% |\setCMYKcolorprofile{coated_FOGRA39L_argl.icc}|\\
+% |                    {Coated FOGRA39}|\\
+% |                    {FOGRA39 (ISO Coated v2 300\% (ECI))}|\\
+% |                    {http://www.argyllcms.com/}|
+% \end{decl}
 % Some color profile files may be obtained from the International
 % Color Consortium.  Please take a look at
 % \url{http://www.color.org/iccprofile.xalter}.
@@ -591,7 +747,7 @@
 % with PDF/X-4p and PDF/X-5pg, which do not require color profiles to
 % be embedded, while the former can be used with other PDF/X variants.
 % Both define commands to use Color Profiles as follows.
-% \begin{center}
+% \begin{decl}[]
 % \begin{tabular}{ll}
 %  \texttt{\string\FOGRAXXXIX} & Coated FOGRA39 (ISO 12647-2:2004)\\    
 %  \texttt{\string\SWOPCGATSI} & U.S. Web Coated (SWOP) v2\\
@@ -611,7 +767,7 @@
 %  \texttt{\string\IFRAXXVI} & ISOnewspaper26v4 ISO/DIS 12647-3:2004\\
 %  \texttt{\string\IFRAXXX} & ISOnewspaper30v4 ISO/DIS 12647-3:2004\\
 % \end{tabular}
-% \end{center}
+% \end{decl}
 % As of the time of writing, only the first six of these result in PDFs
 % which can validate with external profiles (i.e., for PDF/X-4p and PDF/X-5pg)
 % using current versions of Adobe Acrobat Pro software. It is unclear
@@ -625,16 +781,25 @@
 %  \defmacro{pdfxSetRGBcolorProfileDir}\marg{path to RGB color profiles}\\
 %  \defmacro{pdfxSetCMYKcolorProfileDir}\marg{path to CMYK profiles}
 % \end{decl}
-% On a Macintosh, one can use \texttt{\string\AdobeMacOSdir} which expands to 
-% the path \texttt{/Library/Application Support/\allowbreak 
-%  Adobe/\allowbreak Color\allowbreak /Profiles/\allowbreak Recommended/}.
-% Under Windows the corresponding macro is \texttt{\string\WindowsColordir}
-% which expands: 
-% \texttt{C:\string\Windows\allowbreak\string\System32\allowbreak
-%  \string\Spool\allowbreak\string\Drivers\allowbreak\string\Color\string/}.
+% On a Macintosh, one uses either a macro |\MacOSColordir| which expands
+% into the path for system-provided profiles:
+% \begin{decl}[]
+% |/System/Library/ColorSync/Profiles/|  
+% \end{decl}
+% or |\AdobeMacOSdir| which expands into the path:
+% \begin{decl}[]
+% |/Library/Application Support/Adobe/Color/Profiles/Recommended/|
+% \end{decl}
+% Under Windows the macro is |\WindowsColordir| which expands: 
+% \begin{decl}[]
+% |C:\Windows\System32\Spool\Drivers\Color/|
+% \end{decl}
+% being the common location for color profiles.
 % Use these within the \verb|.xmpdata| file as, e.g., 
-%  |\pdfxSetCMYKcolorProfileDir{\AdobeMacOSdir}|.
-% Authors should change the paths to suit their own circumstances, either
+% \begin{decl}[]
+%  |\pdfxSetCMYKcolorProfileDir{\AdobeMacOSdir}|
+% \end{decl}
+% Authors may change the paths to suit their own circumstances, either
 % \emph{before} loading |pdfx.sty| or within the \verb|.xmpdata| file. 
 %
 % PDF/A and PDF/E usually need an RGB profile, while PDF/X and PDF/VT
@@ -671,9 +836,9 @@
 % particular field of metadata that you need and that is not currently
 % supported, please contact the package authors.
 %
-% |pdfx| makes use of the |xmpincl| package to include |xmp| data into
+% |pdfx| makes use of the |xmpincl| package to include XMP data into
 % the PDF.  The documentation of |xmpincl| package may help interested
-% users to understand the process of |xmp| data inclusion.
+% users to understand the process of XMP data inclusion.
 % 
 % \subsection{Tutorials and technical notes}
 %
@@ -705,22 +870,147 @@
 % % the included |Makefile|, which will also regenerate the index.
 %
 % To install the package, first extract the program code; i.e., the
-% file |pdfx.sty|, by running \LaTeX{} or \TeX{} on the file
-% |pdfx.ins|. Create a directory named |pdfx| under |$TEXMF/tex/latex|
-% and copy the files |pdfx.sty|, |8bit.def|, |glyphtounicode-cmr.tex|,
-% as well as the |*.icc| and |*.xmp| files, into it. Then update \TeX's
-% file database using the appropriate command for your distribution and
-% operating system (such as |texhash| or |mktexlsr|, or similar).
+% file |pdfx.sty|, by running \LaTeX{} or \TeX{} on the file |pdfx.ins|. 
+% Create a directory named |pdfx| under |$TEXMF/tex/latex| and copy the files
+%  |pdfx.sty|, |8bit.def|, |glyphtounicode-cmr.tex|, as well as the other
+%  |*.tex|, |l8u*.def|, |*.icc| and |*.xmp| files, into it. Then update
+% \TeX's file database using the appropriate command for your distribution
+% and operating system (such as |texhash| or |mktexlsr|, or similar).
 % 
 % \subsection{Limitations and dependencies}
 % 
-%  |pdfx.sty| works with \pdftex\ and also Lua\TeX.  
-%  It further depends on the following other packages:
-%  \begin{enumerate}
+% The |pdfx.sty| package works with \pdftex\ and also Lua\TeX\ and Xe\TeX\ 
+% with some limitations.  
+% It further depends on the following other packages.
+% \begin{enumerate}
 %  \item |xmpincl|  for insertion of metadata into PDF.
-%  \item |hyperref| for hyperlinking, bookmarks, etc.
-%  \item |glyphtounicode.tex| maps glyph names to corresponding Unicode.
-%  \end{enumerate}
+%  \item |inputenc|  to establish input-encoding infrastructure ---
+%    see Section~\ref{ssec-L8U}.
+%  \item |hyperref| for ensuring data is correctly encoded when being
+%   written into the PDF file, and supporting features such as
+%   hyperlinking, bookmarks, etc.
+%  \item |xcolor| for ensuring consistent use of the color model
+%    appropriate the PDF variant, within text and hyperlinks
+%   (when allowed).
+%  \item |glyphtounicode.tex| (\pdftex\ only) maps glyph names 
+%   to corresponding Unicode code-points.
+%  \item |ifluatex|  allowing coding specific to Lua\LaTeX.
+%  \item |ifxetex|  allowing coding specific to Xe\LaTeX.
+%  \item |luatex85| or |pdftexcmds| (Lua\TeX\ only) for access 
+%   to primitive commands using \pdftex\ macro names.
+%  \item |stringenc| used to help generate proper bookmarks with transliterated input; 
+%    e.g., with |\textLGR| or |\textARM| --- see Section~\ref{sssec-arm}.
+% \end{enumerate}
+% Other files and packages are loaded as sub-packages or as
+% configuration files for these. Since some of these packages 
+% may be loaded by existing documents we provide here advice on 
+% how to deal with potential loading and option conflicts.
+%
+% Firstly, it is best if |pdfx| is the first package loaded; e.g.,
+% directly after the |\documentclass| line. This is not a strict requirement, 
+% but it is worthwhile to deal with the metadata at the top of your \LaTeX\ source,
+% allowing correct options to be loaded to cope with validation aspects.
+%
+% Secondly, replace |\usepackage[<options>]{hyperref}| with |\hypersetup{<options>}|.
+% This deals with most loading issues with the |hyperref| package. 
+% Note that PDF/X is a format intended for printing. 
+% It forbids inclusion of hyperlinks and other actions, including via bookmarks.
+% To produce a validating PDF/X document, |pdfx| overrides internal macros
+% while keeping colors associated with link anchors.
+% To inhibit these colors also, you could specify options as follows.
+% \begin{decl}[]
+%  |\hypersetup{colorlinks,allcolors=black}|
+% \end{decl}
+% Furthermore, options to set metadata components (such as |pdfauthor|,
+% |pdftitle|, |pdfsubject|, |pdfkeywords|, etc.) are disabled, since
+% |pdfx| has already taken care of this information.
+% 
+% Thirdly, conflicts with other packages may be dealt with by simply
+% changing |\usepackage| to |\RequirePackage| within the document's
+% preamble. But this may not be possible when the |\usepackage| 
+% or |\RequirePackage| command occurs within another package, or with
+% a specific set of options, thereby causing processing to stop. 
+% Few packages have a command analogous to |\hypersetup|. 
+% Instead |\PassOptionsToPackage{<options>}{<package>}| can help.
+% For |<options>| specify the ones associated with the loading yet to come.
+% This can give a smooth processing run, but you'll need to check whether
+% the results from those options have actually taken effect.
+% Some examples of this can be seen later, in Figures~\ref{koi8-code} 
+% and \ref{tldoc-pol}.
+%
+% \subsubsection{Limitations using Xe\LaTeX}\label{sssec-xetex}
+%
+% To process a file using Xe\LaTeX, to produce a document that can 
+% validate to a particular PDF standard, one need to use a command
+% to run the \TeX\ engine, as follows.
+% \begin{decl}[]
+%   |xelatex -shell-escape -output-driver="xdvipdfmx -z 0" <filename>.tex |
+% \end{decl}
+% The |-shell-escape| option allows a command-line task to be run,
+% which writes the creation-date \& time of the running job into 
+% a small file on disk. This data, written in a specific format, is then 
+% read by the job for inclusion into several metadata fields.
+% This emulates the result of \pdftex's |\pdfcreationdate| primitive.
+% As there are security implications in allowing arbitrary commands to be run,
+% this need for |-shell-escape| must be viewed as imposing a limitation on the 
+% work-flows in which this can be safely used.
+%
+% More severe is the need for the |-z 0| output-driver option, which disables 
+% all compression in the final PDF output.
+% This is needed since all the PDF standards require the XMP metadata
+% packet to be present as uncompressed plain text, in UTF-8 format.
+% The only way to achieve this with Xe\LaTeX\ is for no compression being
+% used at all by the |xdvipdfmx| driver program. The result can be file sizes
+% more than $10\times$ what is produced by \TeX\ engines using compression.
+%
+% Xe\TeX\ is designed for processing UTF-8 input only. When presented
+% with a \LaTeX\ source using a legacy encoding, such as |latin2| or |koi8-r|, 
+% the input is accepted and a PDF produced. Yet there will be garbage 
+% characters corresponding to each character entered from the upper range
+% (128--255). This is evident in the PDF content and bookmarks; 
+% yet |pdfx| produces the correct XMP metadata packet.
+% So while the techniques explained later in Section~\ref{ssec-multi} are
+% valid, the PDF itself does not contain correct content.
+%
+% Not all fonts, in particular Open-Type fonts (OTF), naturally come with
+% mappings of the glyphs to Unicode code points. This is a requirement
+% with PDF/A and PDF/E standards. 
+% Use of such fonts can result in validation errors, such as:
+% \begin{itemize}
+% \item
+%  CIDset in subset font is incomplete (font contains glyphs that are not listed).
+% \item
+%  Type 2 CID font: CIDToGID map is invalid or missing.
+% \end{itemize}
+% 
+% If one has access to Adobe's |Acrobat Pro| software, then its |Preflight|
+% utility can rewrite the uncompressed output from Xe\LaTeX\ into a valid
+% PDF standard, using compression of the contents but not of the XMP packet.
+% Similarly |Preflight| can fix the missing font information.
+%
+%
+% \subsubsection{Limitations using Lua\LaTeX}\label{sssec-luatex}
+%
+% Lua\LaTeX\ can handle the OTF font issues mentioned for Xe\LaTeX,
+% so can produce valid PDF/A documents where Xe\LaTeX\ fails.
+% However, since Lua\TeX\ expects all input source to be UTF8-encoded,  
+% it cannot work at all with documents using older legacy encodings.
+% Instead one gets error messages such as:
+%\begin{decl}
+% |! String contains an invalid utf-8 sequence.|\\
+% |l.5 \Copyright{\textLII{UWAGA dla recenzent|\\
+% |                                         �w/t³umaczy}}|\\
+% |? |
+%\end{decl}
+% from a document using |latin2| encoded characters.
+% Thus most of Section~\ref{ssec-multi} is just not applicable for Lua\LaTeX,
+% whereas it is for \pdftex.
+% This is essentially the same problem as described above for Xe\TeX,
+% but here Lua\TeX\ advises that there are problems as soon as it
+% encounters an invalid (for UTF-8) character. Some would regard
+% this as better than having the job run to completion, only to later
+% discover garbage content within the PDF.
+%
 %
 % \subsection{Files included}
 %
@@ -737,6 +1027,14 @@
 % \item |pdfx.xmp| --- specimen |xmp| template for PDF/X.
 % \item |8bit.def| --- custom input encoding.
 % \item |l8uenc.def| --- input encoding macro declarations.
+% \item |l8uarb.def| --- input macro declarations for Arabic.
+% \item |l8uarm.def| --- input macro declarations for Armenian.
+% \item |armglyphs.dfu| --- Unicode mapping for Armenian letters.
+% \item |l8ucyr.def| --- input macro declarations for Cyrillic alphabet.
+% \item |l8udev.def| --- input macro declarations for Devanagari.
+% \item |l8ugrk.def| --- input macro declarations for Greek alphabet.
+% \item |l8ulat.def| --- input macro declarations for Latin 1--9 encodings.
+% \item |l8umath.def| --- input macro declarations for mathematical symbols.
 % \item |glyphtounicode-cmr.tex| --- maps glyph names to corresponding
 %   Unicode for Computer Modern and other \TeX-specific fonts.
 % \item |coated_FOGRA39L_argl.icc| --- CMYK color profile 
@@ -748,15 +1046,14 @@
 % \item |AdobeExternalProfiles.tex| --- macros for use of external color profiles.
 % \end{itemize}
 % 
-% \subsubsection{Documentation}
+% \subsubsection{Documentation \& Examples}
 % 
 % \begin{itemize}
 % \item |README| --- usual top-level information.
 % \item |manifest.txt| --- file list.
-% \item |sample.tex|, |sample.xmpdata| --- a sample file with sample
-%   metadata.
-% \item |small2e-pdfx.tex|, |small2e-pdfx.xmpdata| --- another sample
-%   file with sample metadata.
+% \item |pdfx.pdf| --- package documentation.
+% \item |sample.tex|, |sample.xmpdata| --- a sample file with sample metadata.
+% \item |small2e-pdfx.tex| --- sample file with included metadata.
 % \end{itemize}
 % 
 % \subsubsection{Sources}
@@ -767,6 +1064,10 @@
 % \item |src/pdfx.xmpdata| --- metadata for the documentation.
 % \item |src/rvdtx.sty| --- used by |pdfx.dtx|.
 % \item |src/Makefile| --- a Makefile for building the documentation.
+% \item |src/{arm-start,koi8-example,koi8-example2,latin2-example}.tex| 
+%   --- used in the documentation with figures showing example coding.
+% \item |src/{TL-POL-meta,TL-RU-LICRs,TL-RU-metadata,TL-RU-toc,armtex-meta,usage-meta,|\\
+%   |math-assign5}.png| --- screenshot images showing multilingual and other metadata.
 % \end{itemize}
 %
 % \subsection{Miscellaneous information}
@@ -781,7 +1082,1009 @@
 % \href{mailto:ross.moore@mq.edu.au}{\ttfamily ross.moore@mq.edu.au}
 % and/or
 % \href{mailto:selinger@mathstat.dal.ca}{\ttfamily selinger@mathstat.dal.ca}.
+%
+%
+% \section[Multilingual and Technical Considerations]{Multilingual and Technical Considerations}\label{sec-meta}
+% 
+% \TeX\ and \LaTeX\ have an on-going practice of including metadata within 
+% the source files and package documentation. Usually this is done as comments 
+% at the beginning of the file; such as the following from the English
+% language version of the 2015 \TeX\ Live documentation\footnote{%
+% found at |/usr/local/texlive/2016/texmf-dist/doc/texlive/texlive-en/|.}.
+% \begin{decl}[]
+% |$Id: texlive-en.tex 37205 2015-05-05 21:36:33Z karl $|\\
+% |TeX Live documentation.  Originally written by Sebastian Rahtz and|\\
+% |Michel Goossens, now maintained by Karl Berry and others.|\\
+% |Public domain.|
+% \end{decl}
+% This provides information, ideally suited for copyright metadata 
+% fields, as in Section~\ref{sssec-copy}, as well as for |\Subject| 
+% and |\CoverDate| from Section~\ref{sssec-publ}. 
+% 
+% Also near the top of the file one finds front-matter content
+% \begin{decl}[]
+% |\title{%|\\
+% | {\huge \textit{The \TeX\ Live Guide---2015}}|\\
+% |}|\\
+% |\author{Karl Berry, editor \\[3mm]|\\
+% |       \url{http://tug.org/texlive/}|\\
+% |      }|\\
+% |\date{May 2015}|
+% \end{decl}
+% which supplies metadata information for the commands |\Title|, |\Author|, 
+% |\CoverDisplayDate| also from Section~\ref{sssec-publ}, and |\CopyrightURL|.
+%
+% Most of the hundreds of thousands, if not millions of documents prepared
+% using \TeX, \LaTeX\ and other \TeX-based formats, include similar
+% metadata information, much of which currently does not accompany the
+% resulting PDF. It is becoming increasingly common, if not yet a legal
+% requirement, for PDFs to satisfy a standard that includes inclusion
+% of metadata. This is especially so for government agencies and institutions
+% receiving government funding, in several countries around the world.
+% 
+% It is an aim of the |pdfx| to simplify the process of capturing and
+% including metadata within \LaTeX-produced PDFs, from both the author's 
+% view and that of archivists. The extra features introduced with version 
+% 1.5.8 take a large step in that direction. 
+% This includes the ability, described in the next subsection, to reliably
+% include data presented in different text encodings, rather than being
+% restricted to UTF-8 only. It is a role of the software to make the 
+% conversion, rather than rely on some 3rd party for a translation.
+%
+%
+% \subsection[Multilingual Metadata]{Multilingual Metadata}\label{ssec-multi}
+%
+% A cursory search of the documentation (|.../texmf-dist/doc|) subtree
+% of the forthcoming \TeX\,Live 2016 release reveals more than 730 different
+% |.tex| or |.dtx| document sources which specify an input encoding,
+% via the |\usepackage[...]{inputenc}| command. Roughly 380 (a bit more 
+% than half) declare UTF-8 as the input encoding. 
+% Of the remainder there are $\approx 20$ other encodings specified, 
+% covering a range of languages for at least part of their content. 
+% At some point in time, these documents may be required to have accurate
+% accompanying metadata, as part of conformance to a designated PDF 
+% (or other) standard. There are libraries and archives that already must 
+% meet such standards.
+%
+% We have shown above, in Section~\ref{ssec-metadata}, how the |.xmpdata| 
+% file can be inserted into the document source, which then ensures that 
+% metadata is reliably transferred along with the source itself.
+% This seems a good strategy, but are there any problems with it,
+% especially in a multi-lingual context?
+% 
+% Modern editing software can require an encoding to be associated 
+% with each file. This is what allows the correct characters to be shown, 
+% from what is otherwise just a sequence of 8-bit bytes. The flip-side 
+% is that arbitrary editing is not permitted. Add some UTF-8 data into 
+% a file that is encoded as Latin-2 then try to save it. You may be asked 
+% to specify a new encoding, or the application may even crash out entirely.
+% Maybe this happens \emph{accidentally}. It is not hard for a curly quote 
+% (`) or endash (--) to be included; many editors have settings which can 
+% do this with normal ascii input. Turn \emph{off} such settings.
+%
+% The approach that we advocate is that when editing to add metadata,
+% best is to: 
+% \begin{enumerate}
+% \item 
+%  use the \emph{same encoding} as is specified for the file itself, 
+%  if known (as is usually the case);
+% \item 
+%  even if 1. is not possible, use Copy/Paste \emph{within} the document source 
+%  (e.g., for authors' names, addresses, affiliations, etc.) and from comments, 
+%  as in Section~\ref{sec-meta} above;
+% \item
+%  avoid typing new characters, especially quotes and dashes, and be extra
+%  careful with back-spacing to preserve the real meaning of copied content.
+% \end{enumerate}
+% Even if the original encoding is not known, use of Copy/Paste from other
+% parts of the document is normally not going to change its encoding.
+% This should not cause the file to become invalid due to mixed content.
+% In some situations it may be necessary to use an ASCII-only representation,
+% such as \LaTeX's LICR\footnote{LICR: \LaTeX\ Internal Character Representation;
+% or think `I $=$ Interchange'.} macros~\cite[\S\,7.11]{LC2}.
+%
+% \begin{figure}[htb]
+% \centering
+% \includegraphics[scale=.35]{TL-RU-metadata}
+% \caption{Metadata generated from the coding shown in Figure~\ref{koi8-code},
+%  viewed using Acrobat Pro's `Additional Metadata \dots' panel.}\label{koi8-meta}
+% \end{figure}
+%
+% \subsubsection[Metadata with Cyrillics]{Metadata with Cyrillics}\label{sssec-cyr}
+%
+% Here is a `real-world' example, with Figure~\ref{koi8-meta} showing the metadata
+% as could be produced for the Russian language version of the \TeX\ Live documentation,
+% from coding as shown in Figure~\ref{koi8-code}.
+% The source file itself is actually encoded for KOI8-R, as indicated by 
+% |\usepackage[koi8-r]{inputenc}|, 
+% but is deliberately shown here encoded as |T1|~\cite[p.\,449]{LC2}.
+% This difference is immaterial for checking the validity of the metadata.
+% For example, the stream of upper (accents, etc.) characters within
+% |\Title{\textKOI{ ... }}| is the same as within |\title{...\textit{ ... }}|.
+% Similarly for |\Author{\textKOI{...}}| and |\author{...}|, and |\CoverDate| and |\date|.
+% Strings for the |\Subject| and |\Keywords| are taken from the first actual paragraph
+% in the document, and from early subsection titles.
+%
+% \begin{figure}[htb]
+% \begin{decl}[]
+% \input{koi8-example}
+% \end{decl}
+% \setbox0=\hbox{\kern-10cm\texttt{\`{ }\^{ }\~{ }\"{ }\r{ }\^{ }\u{ }\H{ }\'{ }\k{ }\v{ }\.{ }\i}}%
+% \ht0=0pt\dp0=0pt\box0\vskip-\baselineskip
+% \caption{Example of cyrillics in metadata, shown as if \texttt{T1}-encoded.
+%  See Figure~\ref{koi8-meta} for the actual result.}\label{koi8-code}
+% \end{figure}
+% It is the `parser' command/macro |\textKOI{ ... }| that indicates that the upper range
+% characters (having byte codes 128--255) are to be treated as KOI8-R characters, 
+% rather than as part of UTF-8 byte sequences. It works by examining each byte in sequence,
+% and returning the appropriate UTF-8 2-byte sequence for the required cyrillic character. 
+% This happens during the processing of data from |\jobname.xmpdata| for fleshing-out 
+% the XMP metadata packet to be included within the final PDF/A document.
+%
+% The `parser' macros defined for various encodings, are given in figure~\ref{parsers}.
+% In Section~\ref{ssec-xmplang} the package options are given 
+% for loading the appropriate support for desired languages or alphabets.
+% Support for other encodings can be added, if there proves to be a need.
+% 
+%\begin{figure}[ht]
+% \centering
+% \begin{tabular}{lll}\hline
+%  macro & encodings & bytes 128--255 with languages\\\hline
+%  |\textLAT| & Latin-1 & Western European \\
+%  |\textLII| & Latin-2 & Middle European \\
+%  |\textLIII| & Latin-3 & South European \\
+%  |\textLIV| & Latin-4 & North European \\
+%  |\textLTV| & Latin-5 & Turkish \\
+%  |\textLVI| & Latin-6 & Nordic \\
+%  |\textLVII| & Latin-7 & Baltic Rim \\
+%  |\textLIIX| & Latin-8 & Celtic \\
+%  |\textLIX| & Latin-9 & Western European, incl. \texteuro \\
+%  |\textKOI| & KOI8-R, KOI8-RU & cyrillic alphabets \\
+%  |\textLGR| & LGR, ISO-8859-7 & Greek \& Polytonic Greek\\
+%  |\textARM| & Arm\TeX, ArmSCII8 & Armenian\\
+%  |\(...\)| & parses simple mathematical expressions\\\hline
+% \end{tabular}
+% \caption{Parser macros, defined for specific types of input.}\label{parsers}
+% \end{figure}
+%
+% With encoded characters marked in this way with a `parser' macro, 
+% it is actually possible to mix UTF-8 metadata with other bytes;
+% provided, of course, you have an editor that allows such a file
+% to be created and saved. On the other hand, if you are unhappy with mixing
+% content having different encodings, then there is another way, based upon
+% \LaTeX's LICR macros~\cite[\S\,7.11]{LC2} for representing accented 
+% and non-latin characters. 
+% These are normally hidden away (`I $=$ Internal') but in fact can be seen
+% within auxiliary files, such as |.aux| and |.toc|, |.lof| and |.lot|.
+% This is how \LaTeX\ stores the knowledge of such characters for use in
+% a part of the document processing which may not have the same encoding
+% as the document as a whole, or may require characters generated using several
+% different encodings. Thus LICRs allow for a reliable representation
+% passed to a different context; think `I $=$ Interchange'.
+%
+% \begin{figure}[htbp]
+% \centering
+% \includegraphics[scale=.5]{TL-RU-LICRs}
+% \caption{How to see LICRs in the \texttt{.log} window.}\label{koi8-LICR}
+% \end{figure}
+% \begin{figure}[htbp]
+% \begin{decl}[]
+% \input{koi8-example2}
+% \end{decl}
+% \caption{Example of cyrillics in metadata, using LICRs.}\label{koi8-code2}
+% \end{figure}
+% Figure~\ref{koi8-LICR} shows how to see this. 
+% The document source in the lower portion clearly shows the cyrillic
+% input, whereas the |.log| messages in a command-line window above
+% reveal the LICR representation. A command |\showLICRs| is available
+% with |pdfx.sty| version 1.5.8, specifically to allow this.
+% Now the LICR representation can be copied directly from the |.log| file, 
+% modulo slight difficulties due to the way long lines are broken.
+% As this representation is entirely with ASCII characters, it should not
+% cause any conflict with any UTF-8 metadata that you want within the same file.
+% The |.xmpdata| file might now look as in Figure~\ref{koi8-code2}.
+% Although very verbose, this should be resistant to any corruption due to
+% character encodings, and produces the same result within the PDF, 
+% as in Figure~{koi8-meta}.
+% 
+% Alternatively one can exploit the |.toc| file, using \LaTeX's command
+% |\addtocontents|, as shown in Figure~\ref{koi8-toc}.
+% After processing the file, you can copy the LICR representations out
+% of the |.toc| file, taking care to remove anything of a non-character
+% nature (e.g., implementing the size and spacing of the letters in \TeX).
+%
+% \begin{figure}[htb]
+% \centering
+% \includegraphics[scale=.5]{TL-RU-toc}
+% \caption{How to get desired LICRs into the \texttt{.toc} file.}\label{koi8-toc}
+% \end{figure}
+%
+% Of course once you have harvested the metadata in this format, remove
+% or comment-out those extra |\showLICRs| to get uninterrupted processing.
+% Similarly comment-out the extra |\addtocontents| lines, else the real 
+% Table-of-Contents will become corrupted with unwanted entries.
+% A couple more \LaTeX\ processing runs should restore the PDF to the
+% way you want it.
+%
+% \subsubsection[Metadata with Polish]{Metadata with Polish}\label{sssec-pol}
+% 
+% The next example has upper-range bytes intended to represent Latin-2 encoded 
+% characters, as used in Polish. 
+% With the \LaTeX\ source starting as in Figure~\ref{tldoc-pol}, 
+% the resulting metadata is shown in Figure~\ref{tlmeta-pol}.
+% 
+%\begin{figure}[htb]
+% \centering
+% \includegraphics[scale=.45]{TL-POL-meta}
+%\caption{Metadata generated from the coding shown in Figure~\ref{tldoc-pol}
+% for the Polish version of \TeX\ Live 2015 documentation, showing Latin-2 encoded 
+% characters. The document is valid for PDF/A-2, after having been processed with 
+% pdf-\LaTeX.}\label{tlmeta-pol}
+%\end{figure}
+%
+%\begin{figure}[!htp]
+%\begin{decl}[]
+% \input{latin2-example}
+%\end{decl}
+%\caption{Start of the \LaTeX\ source for the Polish version of \TeX\ Live 
+% documentation. Although Latin-2 encoded, the bytes are shown here using 
+% \LaTeX's \texttt{T1} encoding \cite[p.\,449]{LC2}.}\label{tldoc-pol}
+%\end{figure}
+%
+% Here the `parser macro' is |\textLII|, which can be seen in Figure~\ref{tldoc-pol}
+% to surround either complete metadata entries, or just those parts containing 
+% polish accented (or other) characters in entries that also contain english words.
+% The macro |\textLF| provides a line-feed character for the UTF-8 output.
+%
+% As a technical note, the |\jobname.xmpdata| file is read with |\obeyspaces|
+% in effect. This causes space runs in the input to be replaced by a single
+% `active space' character, which ultimately expands into a normal space upon output.
+% This is needed to preserve inter-word spaces, which would otherwise
+% get lost during parsing, due to \TeX's pattern matching when reading macro arguments.
+% Each byte is examined individually, with normal letters |a-zA-Z| and most punctuation
+% characters passed through unchanged.
+%
+% \medskip\goodbreak
+% Let's understand better how this example was created. There are three files involved.
+%\begin{itemize}
+% \item |pdfx.dtx|, the source for this documentation, open in an editor with
+% encoding declared as UTF-8; 
+% \item |texlive-pl.tex| the Polish documentation for \TeX\ Live, open in the
+% same editor with Latin-2 encoding;
+% \item |latin2-example.tex| which starts life as an empty file on disk.
+%\end{itemize}
+% \noindent
+% This latter file must be opened in the editor, with encoding declared as 
+% Latin-2 (ISO-8859-2).
+% Next the preamble is copied from |texlive-pl.tex| and pasted into |latin2-example.tex|
+% which is then saved to disk. Further editing is done to |latin2-example.tex| to
+% add verbatim markers (\texttt{$\vert$...$\vert$}) and adjust line lengths for display
+% within Figure~\ref{tldoc-pol}. This file's contents is included as part of the 
+% documentation via |\input{latin2-example}| within an environment that handles 
+% presentation aspects.
+%
+% What \emph{cannot} be done is to paste the preamble content directly into |pdfx.dtx|.
+% Consider what would then happen, using `t{\l}umaczy' (`translators', on line 10 
+% following `UWAGA'). This word shows correctly in the Latin-2 encoded files. 
+% It was typeset here using |\l| for the `\l' letter, having Unicode code-point 
+% |Ux0142| (so UTF-8 byte pair |"C5|\,|"82|). 
+% However, it occurs at slot |"B3| within Latin-2 encoding. 
+% In the |T1| font encoding \cite[p.\,449]{LC2} the character glyph name 
+% for slot |"B3| is |/scedilla|, which is what shows in Figure~\ref{tldoc-pol}. 
+% When the `\l' is pasted directly into 
+% a UTF-8 file and shown verbatim, the result is the pair of glyphs 
+% |"C5| (|/Aring|) and |"82| (|/Cacute|); \emph{viz.} |tłumaczy|.
+%
+% As with Figure~\ref{koi8-code} it is not important that the correct characters
+% are shown here, but that the metadata in |\jobname.xmpdata| corresponds to what
+% is used on the titlepage of the PDF; e.g., the contents of |\Title| and |\title|,
+% |\Author| and |\author|, etc.
+% 
+%
+% \subsubsection[Metadata with Greek]{Metadata with Greek}\label{sssec-grk}
+%
+%\begin{figure}[!hb]
+% \centering
+% \includegraphics[scale=.43]{usage-meta}
+%\caption{Metadata generated from the coding shown in Figure~\ref{greek-code}
+% using the greek language specified via the LGR encoding.}\label{greek-meta}
+%\end{figure}
+%
+%\begin{figure}[!htp]
+%\begin{decl}[]
+%|% ... |\\
+%|% This file is part of the Babel system.|\\
+%|% --------------------------------------|\\
+%|% |\\
+%|% It may be distributed and/or modified under the |\\
+%|% conditions of the LaTeX Project Public License, either version 1.3|\\
+%|% ... |\\
+%{\color{verbcolor}\texttt{\% The Current Maintainer of this work is G\"unter Milde.}}\\
+%|% ... |\\
+%| |\\
+%|\providecommand{\pdfxopts}{a-2u,LGRxmp,LATxmp}|\\
+%|\begin{filecontents*}{\jobname.xmpdata}|\\
+%|\Title{Writing Greek with the "greek" option of the "babel" package}|\\
+%{\color{verbcolor}\texttt{\string\Author\{Apostolos Syropoulos\string\sep\ G\"unter Milde\}}}\\
+%|\Subject{This document describes the use of the Latin transliteration for Greek that is |\\
+%| defined by the LGR font encoding. Today, all modern LaTeX distributions support literal|\\
+%| input of Greek, which is the preferred method for new documents. [G. Milde 2013/12/02]}|\\
+%|\Keywords{\textLGR{monotonik'o}\sep \textLGR{polutonik'o}\sep \textgreek{oxe'ia} \sep |\\
+%{\catcode `\|=11 \color{verbcolor}
+%\texttt{\ \ \string\textgreek\{>a'erac\}\string\sep\ \string\textgreek\{>anate'ilh|\}\string\sep\ \string\textgreek\{qa"ide'uh|c\}\}}}| \sep |\\
+%|  \textgreek{D'uskoloc} of \textgreek{M'enandroc}\textLF \textLGR{T'i f'hic? <Id`wn |\\
+%|  >enj'ede pa~id'' >eleuj'eran\textLF t`ac plhs'ion N'umfac stefano~usan, S'wstrate,|\\
+%|  \textLF >er~wn 'ap~hljec e>uj'uc? \sep |\\
+%|  \textaristerikeraia\textalpha\textsampi\textqoppa\textzeta\textdexiakeraia\sep |\\
+%|  \textaristerikeraia\textAlpha\textSampi\textQoppa\textZeta\textdexiakeraia}}|\\
+%|\CoverDate{1997-10-15}|\\
+%|\CoverDisplayDate{October 15, 1997}|\\
+%|\Copyright{This file is part of the Babel system.\textLF This file may be distributed and/or|\\ 
+%| modified under the conditions of the LaTeX Project Public License, either version 1.3 |\\
+%| of this license or (at your option) any later version.}|\\
+%|\CopyrightURL{http://www.latex-project.org/lppl.txt}|\\
+%|\end{filecontents*}|\\
+%|%|\\
+%|\documentclass[11pt]{article}|\\
+%|\usepackage[\pdfxopts]{pdfx}[2016/04/13]|\\
+%|\hypersetup{colorlinks,allcolors=blue}|\\
+%|\usepackage[american,greek]{babel}|\\
+%|\languageattribute{greek}{polutoniko}|\\
+%|\usepackage{athnum,grmath}|\\
+%|\newcommand{\sg}{\selectlanguage{greek}}|\\
+%|\newcommand{\sa}{\selectlanguage{american}}|\\
+%|\begin{document}|\\
+%|\selectlanguage{american}|\\
+%|\title{Writing Greek with the \ttfamily greek\rmfamily\  option of the |\\
+%| \ttfamily babel\rmfamily\ package}|\\
+%|\author{Apostolos Syropoulos\\|\\
+%|        ...\\...}|\\
+%|\date{October 15, 1997}|\\
+%|\maketitle|\\
+%|\abstract{\noindent|\\
+%|This document describes the use of the Latin transliteration for Greek that|\\
+%|is defined by the LGR font encoding. Today, all modern LaTeX distributions|\\
+%|support literal input of Greek, which is the preferred method for new|\\
+%|documents. [G. Milde 2013/12/02]}|
+%\end{decl}
+%\caption{Start of enriched \LaTeX\ source for a document describing how to typeset
+% in Greek, with added metadata demonstrating the LGR transliteration encoding.
+% }\label{greek-code}
+%\end{figure}
+%
+% Prior to proper support for UTF-8 input, a method for preparing document source
+% for the modern Greek language (and also for polytonic Greek), involved the use
+% of LGR encoded fonts. Such a font has Greek (instead of Latin) letters in the 
+% slots for |a-zA-Z|, see~\cite[\S9.4.2]{LC2}. Thus ordinary ASCII letters are used
+% to produce the Greek characters; the mapping of ASCII to Greek is referred to as
+% a `transliteration' scheme. It serves as \emph{both} an input encoding, and as 
+% a font encoding. Accents and diacritic marks are provided through ligatures 
+% built-in to the fonts. Various documents can be found on the web\footnote{e.g., 
+% \url{http://milde.users.sourceforge.net/LGR/}} and
+% within \TeX\ Live distributions\footnote{%
+% TeXLive: \textcolor{urlcolor}{\texttt{.../2016/texmf-dist/doc/generic/babel-greek/}}}. 
+%
+% Indeed the current maintainer G\"unther Milde states
+% ``The LGR transliteration does not work for PDF metadata''.
+% This is because there is no translation of LGR input into \LaTeX\ LICRs,
+% as happens with say |\usepackage[utf8]{inputenc}| for UTF-8 input,
+% or when upper 8-bit characters are present using |\usepackage[iso-8859-7]{inputenc}|.  
+% With these, LICRs such as |\textAlpha|, |\textOmicron|, \dots, |\textomega| 
+% are produced, which result in the correct characters for metadata and bookmarks,
+% perhaps employing Unicode `combining' characters for accented letters.
+% Using |pdfx| the UTF-8 characters can be put directly into the |.xmpdata| file;
+% LICRs are interpreted provided the |grkxmp| loading option has been specified.
+% 
+% Using the methods of |pdfx| the metadata difficulty is remedied, as can be seen in 
+% Figure~\ref{greek-meta} using coding as shown in Figure~\ref{greek-code}. This requires 
+% the |LGRxmp| option and |\textLGR| `parser' macro. The original document source, 
+% called |usage.tex|, can be found in the directory specified in the footnote below.
+% As this document is essentially an English description of how to use LGR for Greek,
+% we have used the `Keywords' field to provide examples of such usage. 
+% Since a macro |\textgreek| can be used for greek portions within such documents, 
+% this macro name is aliased to |\textLGR| within the context where metadata is processed.
+% Furthermore, parsing using |\textLGR| generates correct pre-composed characters 
+% for letters with accents or diacritics. Bookmarks can also be generated from
+% LGR input, using a technique described in Section~\ref{sssec-arm}.
+%
+% \bigskip\noindent
+% The features available with different loading options are summarised here.
+% \begin{itemize}
+% \item 
+%  no option: all metadata in |.xmpdata| file is in UTF-8 (incl. ASCII)
+% \item
+%  |grkxmp|: LICRs can be present; e.g. |\textAlpha|, |\textOmega|, etc. 
+% \item
+%  |LGRxmp|: supports LGR-encoded input and |ISO-8859-7| upper range characters,
+%    using the |\textLGR| `parser' macro.         
+% \end{itemize}
+% With |LGRxmp| specified, the features of |grkxmp| are also available; so any 
+% lower-listed option allows data to be mixed with that for higher-listed ones.
+%
+%
+% The final piece to get validation for PDF/A from LGR input, is to specify
+% a Unicode point for the `|v|' used only in the strong `|sv|' ligature to obtain 
+% a non-final `sigma' typeset in isolation. 
+%\begin{decl}[]
+% |\pdfglyphtounicode{internalchar2}{200D}|
+%\end{decl}
+% This gives an interpretation as `zero-width joiner'.
+% There are two instances of this within |usage.tex|. Copy/Paste works as desired.
+% Using \pdftex\ the above command is done automatically. 
+% Drivers, such as Xe\LaTeX\ lacking an implementation of |\pdfglyphtounicode|, 
+% can fail to produce a valid PDF due to this rather minor deficiency.
 % 
+% Greek numerals, using |\greeknumeral| or |\Greeknumeral| cannot work directly within
+% a |.xmpdata| file. However if such is desired, the following technique allows
+% correct LICRs to be found for use in the metadata. 
+% At any convenient place within the \LaTeX\ source; e.g., near where the required  
+% number is used, insert coding such as:
+% \begin{decl}[]
+% |{\pdfxGreeknumeralsHack \textgreek{\edef\num{\greeknumeral{1997}}\show\num}}%|
+% \end{decl}
+% Upon processing, the following will be written to the console or |.log|-window.
+% \begin{decl}[]
+%|> \num=macro:|\\
+%|->\LGR\textaristerikeraia \LGR\textalpha \LGR\textsampi \let \protect \LGR\text|\\
+%|dexiakeraia \LGR\textqoppa \let \protect \LGR\textdexiakeraia \LGR\textzeta \le|\\
+%|t \protect \LGR\textdexiakeraia \protect \LGR\textdexiakeraia .|\\
+%|<argument> ...um {\greeknumeral {1997}}\show \num |\\
+%|                                                  |\\
+%|l.90 ...k{\edef\num{\greeknumeral{1997}}\show\num}|\\
+%|                                                  }|\\
+%|? |
+% \end{decl}
+% from which the desired string of LICRs, is extracted; \emph{viz}.
+% \begin{decl}[]
+% |\textaristerikeraia\textalpha\textsampi\textqoppa\textzeta\textdexiakeraia|
+% \end{decl}
+% The corresponding trick does not work with |\Greeknumeral|, but the uppercasing
+% can be done by manually from the string obtained using |\greeknumeral|,
+% \begin{decl}[]
+% |\textaristerikeraia\textAlpha\textSampi\textQoppa\textZeta\textdexiakeraia|
+% \end{decl}
+% leaving the initial and final |\text...keraia| macros as all lowercase.
+% For smooth processing, remove or comment-out the added line after collecting the LICRs.
+%
+%
+% \def\ArmTeX{Arm\kern -0.15em\TeX}%
+% \subsubsection[Metadata with Armenian]{Metadata with Armenian}\label{sssec-arm}
+% 
+% \begin{figure}[!htbp]
+% \centering
+% \includegraphics[scale=.42]{armtex-meta}
+%\caption{Metadata generated from the coding shown in Figure~\ref{arm-code}
+% using the Armenian language specified using \ArmTeX\ transliteration.
+% Bookmarks have been generated in Armenian. Figure ~\ref{ex-arm} explains
+% how the word indicated in red is obtained via parsing.}\label{arm-meta}
+% \end{figure}
+%
+% \begin{figure}[!htp]
+% \begin{decl}[]
+% \input{arm-start.tex}%
+% \end{decl}
+%\caption{Enriched \LaTeX\ source for the Armenian version of the \ArmTeX\ manual,
+% with added metadata demonstrating the \ArmTeX\ transliteration scheme for \texttt{OT6} encoding.
+% Also shown is coding used to produce bookmarks from the transliteration.}\label{arm-code}
+% \end{figure} 
+% 
+% The \ArmTeX\ package\footnote{documentation: %
+%  TeXLive: \textcolor{urlcolor}{\texttt{.../2016/texmf-dist/doc/generic/armenian/}}}
+% provides the method to typeset Armenian, with input being specified in various ways 
+% including a transliteration scheme from ASCII input. This transliteration is directed 
+% at the use of fonts using the |OT6| encoding, developed for this purpose.
+% Each way is supported by |pdfx.sty| with appropriate loading options, similar
+% to the support for Greek~(see Section~\ref{sssec-grk}). 
+% \begin{itemize}
+% \item 
+%  no option: all metadata in |.xmpdata| file is in UTF-8 (incl. ASCII)  
+% \item
+%   |armxmp|: using LICR-like macro names; e.g. |\armAyb|, |\armsha|, |\armfe| etc. 
+% \item
+%   |AR8xmp|: using the \ArmTeX\ (|OT6|) transliteration scheme or with upper-range
+%    characters in |ArmSCII8| encoding, using the `parser' macro |\textARM|.
+% \end{itemize}
+% There are 39 letters in the Armenian alphabet, so the transliteration includes
+% many 2-letter combinations to specify the desired character. Whereas Greek uses
+% punctuation symbols to specify diacritics, Armenian requires either ligatures
+% implemented in the |OT6|-encoded font, or careful parsing of the input into
+% LICR-like macros.
+% \LaTeX\ source\footnote{TeXLive: %
+% \textcolor{urlcolor}{\texttt{.../2016/texmf-dist/doc/generic/armenian/examples/latex/}}} 
+% for the \ArmTeX\ documentation is available in both English and Armenian. 
+% Figure~\ref{arm-meta} shows the result of enriching the Armenian version with relevant 
+%  metadata, using coding as shown in Figure~\ref{arm-code}.
+%
+% As in earlier examples, that metadata has come from the extensive comments at the head
+% of the \LaTeX\ source file (represented by |...| in Figure~\ref{arm-code}), and other
+% title-page material, such as title and author names in both English and Armenian.
+% Within the keywords are armenian words that are mentioned in the documentation as being
+% slightly tricky to represent in transliteration, to verify that the required tricks have
+% been correctly implemented.
+%
+% Also apparent in Figure~\ref{arm-meta} is the use of Armenian letters in the Bookmarks
+% pane, having been generated from the transliteration source. This requires a 3-step
+% process, as follows.
+% \begin{enumerate}
+% \item
+%  conversion of transliterated source into UTF-8. 
+%  This is done as the |.xmpdata| file is processed, using |\pdfxEnableCommands|
+%  to make global definitions; e.g, 
+%\begin{decl}[]
+% |\xdef\sectAtitle{\textARM{Nerac'uthyun}}| 
+%\end{decl}
+%  capturing the section title in the form supplied in the \LaTeX\ source.
+%  This can be seen in Figure~\ref{arm-code}, near the end of the |{filecontents*}|
+%  environment, and at the bottom where the |\section| command would occur.
+% \item
+%  conversion of the UTF-8 representation into |UTF16-be|, suitable for bookmark
+%  strings within the PDF file. With \pdftex\ thishis is done using 
+%  |\StringEncodingConvert| from Heiko Oberdiek's |stringenc.sty| package.
+%  Lua\LaTeX\ and Xe\LaTeX\ can use the UTF-8 representation directly.
+% \item
+%  integration of the |UTF16-be| string (\pdftex) or UTF-8 string (Lua\TeX\ and Xe\TeX)
+%  into the coding that would normally generate the bookmark from a provided section title,
+%  in transliterated form.
+% \end{enumerate}
+% These last two steps are combined into a single command, to replace the usual
+% command for a section title; |\section|, |\subsection|, etc.
+% \begin{decl}[]
+% |\pdfxBookmark{\section}{\sectAtitle}{Nerac'uthyun}|
+% \end{decl}
+% Now |\pdfxBookmark| first checks that the macro passed as the 2nd argument
+% actually exists. If it does not, an error message is given and upon continuation
+% would just do |\section{Nerac'uthyun}| as normal. 
+% When it does exist, then step 2 is done (by \pdftex) storing the result as |\pdfx@temp|. 
+% With Lua\TeX\ and Xe\TeX, |\pdfx@temp| stores a copy of the UTF-8 data.
+% Then the commands needing to be executed are essentially
+%\begin{decl}[]
+% |\pdfstringdefDisableCommands{\let\sectAtitle\pdfx@temp}|\\
+% |\def\sectAtitle{Nerac'uthyun}|\\
+% |\section{\sectAtitle}|
+%\end{decl}
+% so that the correct section heading is displayed on the page,
+% but when |\sectAtitle| is processed to create a bookmark it is replaced
+% by the pre-prepared contents of |\pdfx@temp|.
+% There are some technicalities\footnote{In fact a small change is made 
+% to how \textcolor{verbcolor}{\texttt{\string\@@writetorep}} is used.} 
+% to make this work cleanly, 
+% as just doing these commands would interfere with other uses of |\pdfstringdef|.
+% In case a long sectioning command has an optional argument, or a $*$-variant
+% in needed, then include it this way.
+%\begin{decl}[]
+% |\pdfxBookmark[Ar'avot e'r]{\section*}{\sectAtitle}{Ar'avot e'r, Araratyan dashti ...}|
+%\end{decl}
+%
+%
+% \subsubsection[Other Languages]{Other Languages}\label{sssec-other}
+% 
+% There is support for Metadata using characters from other languages,
+% with corresponding loading options, as follows. 
+% \begin{itemize}
+%  \item  |arbxmp| : Arabic; 
+% via LICRs |\textarabicalef|, |\textarabicqaf|,\\ |\textarabicaleflowerhamza|, etc.
+%  \item  |devxmp| : Devanagari; 
+% via LICRs |\textdevanagaria|, |\textdevanagarivocalicr|,\\ |\textdevanagaricandrabindu|, etc.
+%  \item  |hebxmp| : Hebrew;
+% via LICRs |\hebalef|, |\hebsamekh|, |\hebfinalpe| and accent marks |\segol|, |\qubuts|, etc.
+%  \item  |vnmxmp| : Vietnamese; 
+% via LICRs |\ABREVE|, |\OCIRCUMFLEX|, |\uhorn| etc. and the combinations of multiple accents
+%  applied as usual via |\'|, |\`|, |\^|, etc.
+% \end{itemize}
+% The LICRs include support mapping accented letters to precomposed glyphs, falling back on
+% `combining characters' only in unusual situations. Special input conventions or methods,
+% such as transliteration schemes, are \emph{not yet} supported. 
+% Indeed, these options are largely untested, so any difficulties encountered should 
+% be reported to the package authors. Requests to support extra input methods or other
+% language blocks should also be directed to the authors, along with pointers to where
+% the desired input methods are fully described. 
+% Sample `real-world' documents would be greatly appreciated.
+%
+%
+% \subsection[L8U Encoding]{L8U Encoding}\label{ssec-L8U}
+%  
+% To understand how |pdfx| handles the translation into UTF-8 of input that is not already
+% in that format, we'll briefly discuss \LaTeX's font-encoding mechanism, which is the
+% basis for LICR macros~\cite[\S\,7.11]{LC2}. As an example, consider the macro |\textgamma|
+% representing the lowercase Greek letter $\gamma$.
+% Various \LaTeX\ packages declare this as LICR in different ways, for different purposes.
+%\begin{decl}[]
+% |greek-fontenc/lgrenc.def:\DeclareTextSymbol{\textgamma}{LGR}{103}|\\
+% |greek-fontenc/greek-euenc.def:\DeclareTextCommand{\textgamma}{\LastDeclaredEncoding}{γ}|\\
+% |hyperref/puenc.def:\DeclareTextCommand{\textgamma}{PU}{\83\263}%* U+03B3|\\
+% |tipa/t3enc.def:\DeclareTextSymbol\textgamma{T3}{71}             % Gamma|\\
+% |ucs/data/uni-2.def:\uc@dclc{611}{tipa}{\textgamma}%|\\
+% |ucs/data/uni-3.def:\uc@dclc{947}{default}{\textgamma}%|
+% \end{decl}
+% Here the |\uc@dclc| commands associate UTF-8 input of |Ux0263| (IPA small letter gamma)
+% and |Ux03B3| (Greek small letter gamma) internally with |\textgamma|, 
+% whereas the others deal with output formats\footnote{Whereas {\color{verbcolor}\texttt{ucs.sty}}
+% handles UTF-8 input, mapping it to LICRs, with {\color{verbcolor}\texttt{pdfx.sty}} 
+% we need the reverse mapping into UTF-8, not just from LICRs but also from legacy
+% 8-bit encodings and transliteration schemes.}. 
+% The |LGR| refers to greek fonts, encoded as explained in Section~\ref{sssec-grk},
+% whereas |PU| is used to create bookmark strings, and other PDF string inclusions,
+% using |\pdfstringdef| from the |hyperref| package. 
+% IPA phonetics use the |T3| encoding, allowing |\textgamma| to refer to a character
+% from a completely different Unicode block.
+% With |greek-euenc.def| designed for Xe\TeX\ and Lua\TeX, the encoding can be variable, 
+% with the output bytes being those for the UTF-8 encoding of $\gamma$, namely |^^ce^^b3|, 
+% shown here as the |T1|-encoded pair |γ|. 
+%
+% Thus there are 4 output forms for this character,
+% and we've not even considered how $\gamma$ is used in mathematics!
+% To handle these concurrently, one has internally defined control-sequence names
+% \begin{decl}[] 
+%  |\LGR\textgamma=\char"67| \qquad where $6\times 16 + 7 = 103$\\
+%  |\PU\textgamma=\long macro:->\83\263|\\
+%  |\T3\textgamma=\char"47| \qquad where $4\times 16 + 7 = 71$\\
+%  |\L8U\textgamma=\long macro:->γ|
+% \end{decl}
+% where the 2nd `\textbackslash' is part of the name\footnote{%
+% obtained using {\color{verbcolor}%
+% \texttt{\string\csname\space LGR\string\string\string\textgamma\string\endcsname}}.}. 
+% The latter macro is explained below.
+% To use the specific version of the macro, \LaTeX\ maintains a `font-encoding'
+% parameter, set using |\fontencoding{...}| local to the surrounding environment grouping.
+% 
+% To the above declarations of |\textgamma|, to deal with conversion to UTF-8, 
+% the |pdfx| package adds the following declarations when the |LGRxmp| option is used.
+% \begin{decl}[]
+% |pdfx/l8ugrk.def:\DeclareTextCommand{\textgamma}{L8U}{γ}|\\
+% |pdfx/l8ugrk.def:\DeclareTextCompositeCommand{\textLGRenc}{L8U}{\textgamma}{γ}|\\
+% |pdfx/l8ugrk.def:\DeclareTextCompositeCommand{\textLGRenc}{L8U}{g}{γ} |\\
+% |pdfx/l8ugrk.def:\DeclareTextCompositeCommand{\textLGRenc}{L8U}{^^e3}{γ}|
+% \end{decl}
+% The encoding name |L8U| indicates \textbf{L}ocal conversion into UTF-\textbf{8} \textbf{U}nicode, 
+% as required for metadata, using |pdfx.sty|. Currently this encoding is used in one place
+% only; during the interpretation of information supplied through the |\jobname.xmpdata| file.
+% This happens as part of the |pdfx| package, \emph{before} it uses |xmpincl.sty|.
+% Such specificity justifies being called a `Local' encoding. 
+% However, other tasks may emerge requiring on-the-fly conversion to UTF-8.
+% In this case all the functionality of this encoding could be shifted into a separate package,
+% and the name of the encoding changed to reflect this more general usage.
+% Bookmarks from transliterated input, as described in Section~\ref{sssec-arm},
+% is possibly a sufficient reason to have a separate package. Another possibility is to
+% generate on-the-fly creation of UTF-8 strings, to be sent to Xe\TeX\ or Lua\TeX\ running
+% as a slave process to generate images of string using OTF fonts, which \pdftex\ currently
+% cannot handle. The result would then be imported back into the running job as an image. 
+% The authors invite suggestions of how this |L8U| encoding functionality can be put to
+% good use.
+%
+% \medskip
+% Accented letters normally use (e.g., from |t1enc.def|)
+%\begin{decl}[]
+% |\DeclareTextComposite{\`}{T1}{A}{192}|
+%\end{decl}
+% to get the pre-composed `\`A', rather than a composite built from \`{} and `A'.
+% The last parameter is an index into a font; however the |\DeclareTextCompositeCommand| 
+% variant allows arbitrary coding as that final parameter, so can be the bytes for the
+% UTF-8 representation of a character.
+% In the above code lines, macros are defined as follows
+%\begin{decl}[]
+% |\\L8U\textLGRenc-\textgamma=macro:->γ|\\
+% |\\L8U\textLGRenc-g=macro:->γ|\\
+% |\\L8U\textLGRenc-|{\color{verbcolor}\texttt{\~a}}|=macro:->γ|
+%\end{decl}
+% where now the 2nd and 3rd (and perhaps 4th) `\textbackslash' are part of the name\footnote{%
+% obtained using {\color{verbcolor}%
+% \texttt{\string\csname\string\string\string\LGR\string\string\string\textLGRenc-\string\string\string\textgamma\string\endcsname}}.}.
+% This shows how the ascii letter `g' is associated with the UTF-8 bytes for $\gamma$,
+% and how the upper 8-bit character from |^^e3| can be similarly associated,
+% as in |ISO-8859-7| encoding.
+%
+% All these associations come together in the `parser' macro |\textLGR| which works as follows.
+% Firstly, |\textLGR| is declared for |L8U| encoding only, where it expands as follows.
+%\begin{decl}[]
+% |\L8U\textLGR #1->\textgreekLGRstring {#1}|\\
+% |\L8U\textgreekLGRstring #1->\textgreekLGR@ii #1\@empty \@empty|\\
+% |\textgreekLGR@ii #1#2\@empty -> ... |  coding to test what is in |#2|\\
+% | ...  \textLGRenc{#1}\@empty | \quad if |#2| is |\@empty|\\
+% | ...  \textLGRenc{#1}\textgreekLGR@i #2\@empty | \quad if |#2| has more tokens\\
+% |\textgreekLGR@i #1->\textgreekLGR@ii #1|
+%\end{decl}
+% Thus |\textLGRenc| is called on each token in the argument of |\textLGR|. 
+% Now |\textLGRenc|, which is applicable only when |L8U| encoding is in effect,
+% has a default expansion of just passing the character through unchanged; \emph{viz.}
+%\begin{decl}[]
+% |\DeclareTextCommand{\textLGRenc}{L8U}[1]{#1}|
+%\end{decl}
+% but by using |\DeclareTextCompositeCommand{\textLGRenc}{L8U}{...}{...}|,
+% alternate expansions apply with specific arguments, as shown above. 
+% In particular, that final argument can include coding that `looks ahead' to find the next
+% character. This is used, for example, with diacritics in Greek, multi-letter sequences
+% for Armenian letters, and other special cases related to ligatures and punctuation symbols.
+% To illustrate this Figure~\ref{ex-arm} follows the conversion of a specific word, 
+% given in the transliteration for Armenian~(see Section~\ref{sssec-arm}).
+% This conversion occurs using only \TeX's macro-expansion ability.
+% Some of the details relevant to this example are explained there.
+%
+%\begin{figure}[!htp]
+%\begin{decl}[]
+% |\textARM{Se\armuh van}|\\
+% |\textarmenARMstring {Se\armuh van}|\\
+% |\textarmenARM@ii Se\armuh  van\@empty \@empty|\\
+% |\textARMenc {S}\textarmenARM@i e\armuh  van\@empty \@empty|\\
+% |\arm@en{S}{Ս}{\arm@nc{h}{Շ}{\arm@nc{H}{Շ}{Ս}}}\textarmenARM@i e\armuh  van\@empty ...|\\
+% |\arm@nc{h}{Շ}{\arm@nc{H}{Շ}{Ս}}\textarmenARM@i e\armuh  van\@empty \@empty|\\
+% |\arm@nc{H}{Շ}{Ս}\textarmenARM@i e\armuh  van\@empty \@empty|\\
+% |Ս\textarmenARM@i e\armuh  van\@empty \@empty|\\
+% |Ս\textARMenc {e}\textarmenARM@i \armuh  van\@empty \@empty|\\
+% |Ս\textARMenc {e}\textarmenARM@i \armuh  van\@empty \@empty|\\
+% |Ս\arm@en{e}{ե}{\arm@nc{'}{է}{\arm@nc{v}{և}{ե}}}\textarmenARM@i \armuh  van\@empty ...|\\
+% |Ս\arm@nc{'}{է}{\arm@nc{v}{և}{ե}}\textarmenARM@i \armuh  van\@empty \@empty|\\
+% |Ս\arm@nc{v}{և}{ե}\textarmenARM@i \armuh  van\@empty \@empty|\\
+% |Սե\textarmenARM@i \armuh  van\@empty \@empty|\\
+% |Սե\textARMenc {\armuh }\textarmenARM@i  van\@empty \@empty|\\
+% |Սե\textarmuh\textarmenARM@i  van\@empty \@empty|\\
+% |Սե\\L8U\textarmuh-\textarmenARM@i  van\@empty \@empty|\\
+% |Սե\textarmgobblespace  van\@empty \@empty|\\
+% |Սե\\L8U\textarmgobblespace- van\@empty \@empty|\\
+% |Սե\textarmenARM@i van\@empty \@empty|\\
+% |Սե\textARMenc {v}\textarmenARM@i an\@empty \@empty|\\
+% |Սե\arm@en{v}{վ}{\arm@nc{n}{ﬖ}{վ}}\textarmenARM@i an\@empty \@empty|\\
+% |Սե\arm@nc{n}{ﬖ}{վ}\textarmenARM@i an\@empty \@empty|\\
+% |Սեվ\textarmenARM@i an\@empty \@empty|\\
+% |Սեվ\textARMenc {a}\textarmenARM@i n\@empty \@empty|\\
+% |Սեվա\textarmenARM@i n\@empty \@empty|\\
+% |Սեվա\textARMenc {n}\@empty|\\
+% |Սեվան\@empty|\\
+% |Սեվան|
+%\end{decl}
+% The macro |\armen@en| (named for \textbf{e}mpty or \textbf{n}ext),
+% looks ahead to see if the 5th-next argument token is |\@empty|,
+% signifying that there is nothing left of the original input. 
+% (A closed bracing |{...}| counts as a single argument.) If |\@empty| the tokens in 
+% the 2nd bracing are substituted, otherwise those in the 3rd bracing.
+% Similarly |\armen@nc| (named for \textbf{n}ext \textbf{c}haracter) 
+% looks to see whether that 5th argument token matches with the character in the
+% 1st bracing. If so, the 2nd bracing's tokens are substituted, else those of the 3rd bracing.
+% This is how to cope with `Sh' or `Sh', implemented as ligatures in an |OT6| encoded font, 
+% denoting a different letter from a single `S'. The macro |\armuh| is used here 
+% to \emph{prevent} a ligature from |ev| that would otherwise occur.
+% But then one must have written |e\armuh v| to get the separate letters.
+% The space becoming an active token, which explains the need for |\textarmgobblespace| 
+% to restart parsing appropriately. Of course |\textarmenARM@i| behaves like |\textgreekLGR@i| 
+% as explained earlier, with a test for |\@empty| as the 2nd token. 
+% At the end, any remaining |\@empty| expand into nothing.
+%
+% \caption{Partial tracing of the conversion of an Armenian word, indicated by the red oval
+% in Figure~\ref{arm-meta}, from {\color{verbcolor}\texttt{OT6}} transliterated form into UTF-8 bytes.
+% In each line, \TeX\ expansion occurs at the position of the left-most `\textbackslash'. 
+% The resulting bytes are shown here in {\color{verbcolor}\texttt{T1}} encoding, 
+% as in previous examples.}\label{ex-arm}
+%\end{figure}
+%
+% Note how in Figure~\ref{ex-arm} the Arm\TeX\ user macro |\armuh| gets aliased
+% to an LICR called |\textarmuh|. Since |\armuh| is already defined, not as an LICR,
+% it cannot be declared to be one without creating problems.
+% Instead, within the environment grouping where |L8U| encoding is specified,
+% one uses |\let\armuh\textarmuh| within a `rebinding' macro command 
+%  |\LIIXUmaparmenianletters|\footnote{The start of the macro name is derived from pseudo-Roman 
+% numerals: IX = 9, IIX = 8}.
+% to get LICR functionality from user-commands.
+%\begin{decl}[]
+% |\def\LIIXUmaparmenianletters{%|\\
+% |  \let\ArmTeX\textArmTeX|\\
+% |  \let\Armayb\textArmayb|\\
+% |  ... |\\
+% |  \let\armuh\textarmuh |\\
+% |  ... |\\
+% |   \def\armbf{}%|\\
+% |  ... }|
+%\end{decl}
+% As well as rebinding each command for a letter, the font style-switching commands 
+% are aliased to do nothing, as these are not relevant to creating UTF-8 output.
+% Being localised by the |L8U| grouping, this causes no problem elsewhere within the document.
+% This is similar to |\psdaliasnames| and |\psdmapshortnames| from |hyperref.sty|
+% which rebind user macros to LICRs, so that |PU| encoded versions of LICRs can be used.
+%
+% Several other `rebinding' commands are defined, mostly with package-loading options.
+%\begin{itemize}
+% \item |\LIIXUmapTeXnames| always defined
+% \item |\LIIXUmaparabicletters| with |arbxmp|
+% \item |\LIIXUmapgreekletters| with |grkxmp| and |LGRxmp|
+% \item |\LIIXUmaplatinchars| and |\LIIXUcancelfontswitches| with |LATxmp|
+% \item |\LIIXUmapmathletterlikes| always defined
+% \item |\LIIXUmapmathspaces| always defined
+% \item |\LIIXUmapmath...| with |mathxmp| --- see Section~\ref{ssec-math} below. 
+%\end{itemize}
+% It may well be that more macro names can be added to some of these commands,
+% to allow more user macros to be used within the metadata. Suggestions for such additions
+% should be sent to the |pdfx| package authors.
+% 
+%
+% \subsection[Nested Parsing\,\textemdash\,Mathematics in Metadata]%
+%  {Nested Parsing\,\textemdash\,Mathematics in Metadata}\label{ssec-math}
+% 
+% Macro commands for many mathematical symbols can be used directly in metadata without extra
+% support; e.g., basic arithmetic operations, letter-like symbols, spacing commands.
+% Super- and subscripted letters and numerals can use |\textsuperscript| and |\textsubscript|
+% when there is an appropriate Unicode character (digits, comma, $+$/$-$/$=$, parentheses, 
+% many letters but not all).
+% 
+% When the |mathxmp| loading option is specified, many more symbols become available,
+% using `rebinding' macros. These are necessary, as the macros for mathematical symbols
+% are generally \emph{not} defined as LICRs, but use |\mathchar|. Thus new LICRs are needed,
+% and existing names bound to these.
+%\begin{decl}[]
+% |\LIIXUmapmathaccents| using `combining' characters from Unicode ranges at |Ux0300|, |Ux1DC0|, |Ux20D0|\\
+% |\LIIXUmapisomathgreek| using |Ux0391|--|Ux03F8| for greek symbols\\
+% |\LIIXUmapmatharrowsA| supporting symbols in the |Ux2190|--|Ux21FF| block\\
+% |\LIIXUmapmathoperatorsA| supporting symbols in the |Ux2200|--|Ux227F| block\\
+% |\LIIXUmapmathoperatorsB| supporting symbols in the |Ux2280|--|Ux22FF| block\\
+% |\LIIXUmapmiscmathsymbolsA| supporting some symbols in the |Ux27C0|--|Ux27EF| range\\
+% |\LIIXUmapsupparrowsA| supporting some symbols in the |Ux27F0|--|Ux27FF| block\\
+% |\LIIXUmapsupparrowsB| supporting some symbols in the |Ux2900|-–|Ux297F| block\\
+% |\LIIXUmapmiscmathsymbolsB| supporting symbols in the |Ux2980|--|Ux29FF| block\\
+% |\LIIXUmapsuppmathoperators| supporting symbols in the |Ux2A00|--|Ux2AFF| block\\
+% |\LIIXUmapunimathgreek| using |Ux1D6E2|--|Ux1D71B| for greek symbols\\
+% |\LIIXUmapmathalphabets| allows access to symbols in the |Ux1D400|--|Ux1D755| block
+%\end{decl}
+%
+% The `parser' macro idea can extends to handle a large class of mathematical expressions.
+%\begin{decl}[]
+% |\let\(\textinlinemath|\\
+% |\DeclareTextCommand{\textinlinemath}{L8U}{\liixu@getinlinemath}|\\
+% |\def\liixu@getinlinemath#1\){\space\textmathnormalstring{#1}\space}|\\
+% |\DeclareTextCommand{\textmathnormalstring}{L8U}[1]{\textmathnormal@ii#1\@empty\@empty}|\\
+% |\textmathnormal@ii #1#2\@empty -> ... |  coding to test what is in |#2|\\
+% | ...  \textmathnormal{#1}\@empty | \quad if |#2| is |\@empty|\\
+% | ...  \textmathnormal{#1}\textmathnormal@i #2\@empty | \quad if |#2| has more tokens\\
+% |\let\[\textdisplaymath| defined similarly to call |\textmathnormalstring|
+%\end{decl}
+% This allows |\textmathnormal| to test each token, in particular mapping letters A--Za--z
+% into the Unicode range |Ux1D44E|--|Ux1D467| (except for $h$).
+% Mathematical styles, such as |\mathrm|, |\mathbf|, |\mathbb| etc. can now be handled
+% using declarations such as:
+%\begin{decl}[]
+% |\Dec...positeCommand{\textmathnormal}{L8U}{\mathrm}{\liixu@mathreorder\textmathrmstring}|\\
+% |\Dec...positeCommand{\textmathnormal}{L8U}{\mathbf}{\liixu@mathreorder\textmathbfstring}|\\
+%\end{decl}
+% where |\liixu@mathreorder| uses some \TeX\ pattern-matching to allow the |\textmathrmstring|
+% parser macro to work on the argument to |\mathrm| before allowing |\textmathnormal| parsing
+% to continue afterwards. We refer to this as `nested parsing'.
+% 
+% Similarly `nested parsing' can be used with superscripts and subscripts using |^{...}| and |_{...}| 
+% and to specify linebreaks, and even super-/subscripts within styles; viz.
+%\begin{decl}[]
+% |\Declar...CompositeCommand{\textmathnormal}{L8U}{^}{\liixu@mathreorder\textsuperstring}|\\
+% |\DeclareTextCompositeCommand{\textmathnormal}{L8U}{_}{\liixu@mathreorder\textsubstring}|\\
+% |\DeclareTextCompositeCommand{\textmathnormal}{L8U}{\\}{\textLF}|\\
+% |\DeclareTextCompositeCommand{\textmathnormal}{L8U}{\cr}{\textLF}|\\
+% |\DeclareTextCompositeCommand{\textmathrm}{L8U}{^}{\liixu@mathreorder\textsuperstring}|\\
+% |\DeclareTextCompositeCommand{\textmathrm}{L8U}{_}{\liixu@mathreorder\textsubstring}|
+%\end{decl}
+% Such `nested parsing' seems to be quite robust\footnote{%
+% ... so far, barring multi-line aligned environments.}, but a great deal more testing
+% is required to uncover cases which may require special handling.
+% An ultimate aim is to be able to just copy the \LaTeX\ source for the `Abstract' of a technical
+% paper into the |\Subject{...}| field of the |.xmpdata| file, with a large expectation that
+% it will `just work', or need only trivial edits to make it so. 
+%
+%
+% \subsection[Metadata in a Production Workflow]{Metadata in a Production Workflow}\label{ssec-wflow}
+%
+%\begin{figure}[htbp]
+% \centering
+% \includegraphics[scale=.45]{math-assign5.png}
+% \caption{Metadata from student assignment papers, using information drawn from a database.
+% The start of the \LaTeX\ coding for this example is shown in Figure~\ref{math-wflow}.}\label{wflow-meta}
+%\end{figure}
+% \noindent
+% At Macquarie University, the Mathematics Department produces personalised topmatter
+% or coversheets for student assignments and tutorial papers using \LaTeX, incorporating
+% information that has been stored in a database. This is done by writing extra definitions 
+% at the top of a copy of the \LaTeX\ source as prepared by the lecturers. 
+% For example information analogous to the following
+%\begin{decl}[]
+% |\def\thestudentname{\utext{Moore} Ross}|\\
+% |\def\thestudentid{55507247}|\\
+% |\def\theunitcode{MATH337}|\\
+% |\def\theoffering{S116}|\\
+% |\def\thetaskname{Assignment 5}|\\
+% |\def\theassignmentnumber{5}|\\
+% |\def\theduedate{09/05 2016}|\\
+% |...|
+%\end{decl}
+% is prepended to the file shown in Figure~\ref{math-wflow}, 
+% for each student downloading their personalised assignment paper.
+% The \LaTeX\ source makes use of this information, including recording some of it
+% within the Metadata.
+%\begin{figure}[!htbp]
+%\begin{decl}[]
+% |\providecommand{\theassignmentnumber}{5}|\\
+% |\providecommand{\assignLecturer}{Dr Ross Moore}|\\
+% |\providecommand{\theunitcode}{MATH337}|\\
+% |\providecommand{\theunitname}{Algebra IIIA}|\\
+% |\providecommand{\theyear}{2016}|\\
+% |...|\\
+% |\def\assigntopics{orbits, stabilisers, groups of matrices}|\\
+% |\providecommand{\pdfxopts}{a-1b}|\\
+% |%% XMP metadata for PDF/A conformance|\\
+% |\begin{filecontents*}{\jobname.xmpdata}|\\
+% |\Title{\theunitcode\ \theoffering: Assignment \theassignmentnumber}|\\
+% |\Author{\assignLecturer}|\\
+% |\Copyright{Macquarie University, Mathematics Department}|\\
+% |\Subject{Assignment \theassignmentnumber, with coversheet personalised for \thestudentname,|\\
+% |    id = \thestudentid}|\\
+% |\Keywords{\assigntopics}|\\
+% |\Creator{pdfTeX + pdfx.sty with \pdfxopts\space option}|\\
+% |\pdfxEnableCommands{\def\utext#1{#1,}}|\\
+% |\end{filecontents*}|\\
+% ||\\
+% |\documentclass[a4paper,11pt]{article}|\\
+% |\RequirePackage{assignments}|\\
+% |\usepackage[\pdfxopts]{pdfx}|
+%\end{decl}
+% \caption{Start of the \LaTeX\ source for an assignment paper, using macro expansion values
+%  supplied via definitions prepended to this file.}\label{math-wflow}
+%\end{figure}
+% When preparing such documents \LaTeX's |\providecommand| is used to supply default values,
+% not drawn from the database; but when actually used, these are ignored as the required
+% information has been supplied using \TeX's |\def| command.
+% The resulting metadata is as in Figure~\ref{wflow-meta}, showing also how the information
+% is displayed at the top of the PDF file that is produced.
+% Notice how a command |\utext| is included to obtain the underlining of the surname within
+% the produced PDF. This is modified, using |\pdfxEnableCommands| in the |\jobname.xmpdata|
+% file, to just place a comma after the surname in the metadata, as it precedes the given name.
+%
+%\bigskip
+% Another way that jobs can be customised using essentially the same \LaTeX\ source,
+% is via the command used to initiate the job. For example the file |sample.tex|,
+% accompanying the |pdfx| distribution, can be used to test the loading options to create
+% PDFs conforming to the various flavours of PDF/A, PDF/E and PDF/X. 
+% Consider a shell script containing the following (Unix/Linux) commands.
+%\begin{decl}[]
+% |pdflatex "\def\pdfxopt{a-2b}\input sample.tex"|\\
+% |pdflatex "\def\pdfxopt{a-2b}\input sample.tex"|\\
+% |mv sample.pdf sample-a2b.pdf|\\
+% ||\\
+% |pdflatex "\def\pdfxopt{a-2u}\input sample.tex"|\\
+% |pdflatex "\def\pdfxopt{a-2u}\input sample.tex"|\\
+% |mv sample.pdf sample-a2u.pdf|\\
+% |...|
+%\end{decl}
+% With a 3-line block for each flavour, this produces a corresponding PDF
+% from the same \LaTeX\ source, named according to each particular variant.
+% A default |\providecommand{\pdfxopt}{a-1b}| at the start of |sample.tex| catches the case
+% of normal typesetting, doing nothing when |\pdfxopt| already has an expansion value.
+% 
+%
+% \subsection[Further Developments]{Further Developments}\label{ssec-further}
+%
+% Prospects for further development of the |pdfx| package are as follows, 
+% listed not necessarily in order of perceived importance.
+% \begin{itemize}
+%  \item
+%    Support for the |dvips| driver with Ghostscript as PDF producer.
+%  \item
+%    Separate the |L8U| encoding support into a separate package.
+%  \item
+%    Conformance to multiple PDF standards; e.g. both PDF/A and PDF/E,
+%     both PDF/A and PDF/X with RGB or CMYK color profile, other combinations.
+%  \item
+%    Explore delaying the processing of metadata until |\begin{document}|, 
+%    thereby allowing some fields to be set automatically from other information
+%    supplied within the document preamble.
+%  \item
+%    Support for input using other legacy 8-bit encodings and transliterations.
+%  \item
+%    Support for more mathematical environments within the metadata.
+%  \item
+%    Support for more PRISM metadata fields, incl. PRISM 3.0~\cite{PRISM}.
+%  \item
+%    Explore ways to overcome difficulties that may arise with other packages.
+%  \item
+%    Full support for PDF/VT.
+%  \item
+%    Support for some aspects of PDF/UA and `Tagged PDF'.
+%  \item
+%    Develop ways to usefully use |L8U| apart from metadata and bookmarks.
+% \end{itemize}
+%
+%
+% \clearpage
 % \section[Bibliography]{Bibliography}
 % \begin{thebibliography}{999}
 %
@@ -791,10 +2094,10 @@
 % \url{http://www.adobe.com/devnet/pdf/pdf_reference.html}.
 %
 % \bibitem{DC}
-% Dublin Core Metadata Element Set, Version 1.1, October 2010 
+% Dublin Core Metadata Element Set, Version 1.1, October 2010\\ 
 % \url{http://dublincore.org/documents/dces/}
 %
-% \bibitem{PDFA}ISO\,19005-1:2005;
+% \bibitem{PDFA}ISO\,19005-1:2005; 
 % Document Management --- Electronic document file format for long term preservation
 % --- Part 1: Use of PDF\,1.4\,(PDF/A-1);
 % Technical Committee ISO/TC\,171/SC\,2  (Sept. 2005).
@@ -804,7 +2107,7 @@
 %
 % \bibitem{PDFA2}ISO\,19005-2:2011;
 % Document Management --- Electronic document file format for long term preservation
-% --- Part 2: Use of ISO\,32000-1\,(PDF/A-2);
+% --- Part 2: Use of ISO\,32000-1\,(PDF/A-2); \hfil
 % Technical Committee ISO/TC\,171/SC\,2 (June 2011).
 % \url{http://www.iso.org/iso/catalogue_detail?csnumber=50655}. 
 %
@@ -840,16 +2143,16 @@
 %
 % \bibitem{PDF-UA}
 % PDF/UA Technical Implementation Guide: Understanding ISO\,14289-1 (PDF/UA-1). \penalty-200
-% AIIM Global Community of Information Professionals. 
+% AIIM Global Community of Information Professionals. \hfil
 % \href{http://www.aiim.org/Research-and-Publications/standards/committees/PDFUA/Technical-Implementation-Guide}%
-% {{\tt http://www.aiim.org/Re\penalty-200 search-and-Publications/standards/committees/PDFUA/Technical-Implementation\penalty-200 -Guide}}.
+% {\small\tt http://www.aiim.org/Re\penalty-200 search-and-Publications/standards/committees/PDFUA/Technical-Implementation\penalty-200 -Guide}.
 %
 %
 % \bibitem{PDFVT}ISO\,16612-2:2010;
-% Graphic technology\,---\,Variable data exchange\,---\,Part 2: 
+% Graphic technology\,---\,Variable data exchange\,---\,Part 2:\hfil
 % Using PDF/X-4 \penalty-5000 and PDF/X-5 (PDF/VT-1 and PDF/VT-2).
-% Technical Committee ISO/TC\,130 (December 2005).
-% \href{http://www.iso.org/iso/home/store/catalogue_tc/catalogue_detail.htm?csnumber=38013}{{\tt http://www.iso.org/iso/home/store/catalogue\_tc/catalogue\_detail.htm?\penalty-200csnumber=38013}}.
+% Technical Committee ISO/TC\,130 (December 2005). \hfil
+% \href{http://www.iso.org/iso/home/store/catalogue_tc/catalogue_detail.htm?csnumber=38013}{{\small\tt http://www.iso.org/iso/home/store/catalogue\_tc/catalogue\_detail.htm?\penalty-200csnumber=38013}}.
 %
 %
 % \bibitem{PDFX}ISO\,15930-1:2001;
@@ -884,12 +2187,20 @@
 %
 % \bibitem{PDFX5}ISO\,15930-8:2010;
 % Graphic technology --- Prepress digital data exchange --- Use of PDF --- Part 8: 
-% Partial exchange of printing data using PDF 1.6 (PDF/X-5).
-% Technical Committee ISO/TC\,130 (July 2010).
+% Partial exchange of printing data using PDF 1.6 (PDF/X-5). \hfil
+% Technical Committee ISO/TC\,130 (July 2010). \hfil
 % \url{http://www.iso.org/iso/home/store/catalogue_tc/catalogue_detail.htm?csnumber=55844}.
 % Revision via Corrigendum: ISO\,15930-8:2010/Cor\,1:2011 (August 2011);
 % \url{http://www.iso.org/iso/home/store/catalogue_tc/catalogue_detail.htm?csnumber=60210}.
 %
+% \bibitem{LC2} F.\,Mittelbach, M.\,Goossens with J.\,Braams, D.\,Carlisle, C.\,Rowley;
+% The \LaTeX\ Companion --- 2nd edition. Addison--Wesley (now Pearson Education Inc.), 2004.
+% ISBN 0-201-36299-6 (paperback).
+%
+% \bibitem{PRISM}PRISM; Publishing Requirements for Industry Standard Metadata. 
+% PRISM Metadata Initiative; Idealliance Working Group.
+% \url{http://www.idealliance.org/specifications/prism-metadata-initiative/prism}
+%
 % \bibitem{XMP}ISO\,16684-1:2012;
 % Graphic technology --- Extensible metadata platform (XMP) specification --- Part 1: 
 % Data model, serialization and core properties.
@@ -899,29 +2210,42 @@
 % \bibitem{pdfx}C.\,V.\,Radhakrishnan, \Thanh, Ross Moore, Peter Selinger;
 % Generation of PDF/X- and PDF/A-compliant PDFs with pdf\TeX{} --- \texttt{pdfx.sty}.
 % TUGboat Vol.\,36, No.\,2; TUG 2015 Conference Proceedings. \TeX\ Users Group, 2015; pp.\,136--142.
+%
+% \bibitem{wikiPDF}Wikipedia; 
+% PDF/A: \url{https://en.wikipedia.org/wiki/PDF/A}\newline
+% PDF/E: \url{https://en.wikipedia.org/wiki/PDF/E}\newline
+% PDF/VT: \url{https://en.wikipedia.org/wiki/PDF/VT}\newline
+% PDF/UA: \url{https://en.wikipedia.org/wiki/PDF/UA}\newline
+% PDF/X: \url{https://en.wikipedia.org/wiki/PDF/X}
+%
 % \end{thebibliography}
-% \end{document}
+% \goodbreak
 % \section[Implementation]{Implementation}
 % 
 % \iffalse
 %<*package>
-% \fi
+% \fi \hfuzz=2.5pt%
 %    \begin{macrocode}
 \@ifpackageloaded{pdfxmult}{%
  \PackageError{pdfx}%
-  {^^JThis package may not be used in conjunction with the \space pdfxmult \space package}%
-  {Type \space x <return> \space to exit; or just \space <return> \space to continue without this package.}%
+  {^^JThis package may not be used in conjunction with the \space
+   pdfxmult \space package}%
+  {Type \space x <return> \space to exit; or just \space <return> \space
+   to continue without this package.}%
  \expandafter\let\csname opt@pdfx.sty\endcsname\@empty\endinput
 }{}%
 \NeedsTeXFormat{LaTeX2e}
 \ProvidesPackage{pdfx}
-  [2016/02/04 v1.5.6 PDF/X and PDF/A support (CVR/HTH/RRM/PS)]
+  [2016/05/03 v1.5.8 PDF/X and PDF/A support (CVR/HTH/RRM/PS)]
 
 \newif\ifpdfx@noBOM \pdfx@noBOMfalse   % use a BOM in the XMP packet
 \newif\ifpdfx@x \pdfx@xfalse   % PDF/X mode
 \newif\ifpdfx@e \pdfx@efalse   % PDF/E mode; not implemented yet
 \newif\ifpdfx@vt \pdfx@vtfalse   % PDF/VT mode, extension of  PDF/X
 \newif\ifno@iccprofile   % used with PDF/X-4p and PDF/X-5pg
+\newif\ifpdfx@noerr   % error messages become just warnings
+
+\DeclareOption{noerr}{\pdfx@noerrtrue}
 
 %% Not all combinations of the following parameters are meaningful.
 \def\xmp@Part{1}               % PDF/A part: 1, 2, or 3
@@ -929,62 +2253,122 @@
 \def\xmp@ReleaseDate{2005}     % 2001 for PDF/X-1, 2005 for PDF/A-1,
                                % 2010 for PDF/A-2, 2012 for PDF/A-3.
 
-%%  default is to create  PDF/A-1b   
-%%  options can change this for PDF/X or higher levels of PDF/A 
-\DeclareOption{a-1a}{\global\pdfx@xfalse\def\xmp@Part{1}\def\xmp@Conformance{A}\def\xmp@ReleaseDate{2005}}
-\DeclareOption{a-1b}{\global\pdfx@xfalse\def\xmp@Part{1}\def\xmp@Conformance{B}\def\xmp@ReleaseDate{2005}}
-\DeclareOption{a-2a}{\global\pdfx@xfalse\def\xmp@Part{2}\def\xmp@Conformance{A}\def\xmp@ReleaseDate{2010}}
-\DeclareOption{a-2b}{\global\pdfx@xfalse\def\xmp@Part{2}\def\xmp@Conformance{B}\def\xmp@ReleaseDate{2010}}
-\DeclareOption{a-2u}{\global\pdfx@xfalse\def\xmp@Part{2}\def\xmp@Conformance{U}\def\xmp@ReleaseDate{2010}}
-\DeclareOption{a-3a}{\global\pdfx@xfalse\def\xmp@Part{3}\def\xmp@Conformance{A}\def\xmp@ReleaseDate{2012}}
-\DeclareOption{a-3b}{\global\pdfx@xfalse\def\xmp@Part{3}\def\xmp@Conformance{B}\def\xmp@ReleaseDate{2012}}
-\DeclareOption{a-3u}{\global\pdfx@xfalse\def\xmp@Part{3}\def\xmp@Conformance{U}\def\xmp@ReleaseDate{2012}}
-\DeclareOption{x-1}{\global\pdfx@xtrue\def\xmp@Part{1}\def\xmp@Conformance{a}\def\xmp@ReleaseDate{2001}\global\pdfminorversion=3 }
-\DeclareOption{x-1a}{\global\pdfx@xtrue\def\xmp@Part{1}\def\xmp@Conformance{a}\def\xmp@ReleaseDate{2003}\global\pdfminorversion=3 }
-\DeclareOption{x-1a1}{\global\pdfx@xtrue\def\xmp@Part{1}\def\xmp@Conformance{a}\def\xmp@ReleaseDate{2001}\global\pdfminorversion=3 }
-\DeclareOption{x-1a3}{\global\pdfx@xtrue\def\xmp@Part{1}\def\xmp@Conformance{a}\def\xmp@ReleaseDate{2003}\global\pdfminorversion=3 }
-\DeclareOption{x-2}{\global\pdfx@xtrue\def\xmp@Part{2}\def\xmp@Conformance{}\def\xmp@ReleaseDate{2002}\global\pdfminorversion=4 }
-\DeclareOption{x-3}{\global\pdfx@xtrue\def\xmp@Part{3}\def\xmp@Conformance{}\def\xmp@ReleaseDate{2002}\global\pdfminorversion=3 }
-\DeclareOption{x-302}{\global\pdfx@xtrue\def\xmp@Part{3}\def\xmp@Conformance{}\def\xmp@ReleaseDate{2002}\global\pdfminorversion=3 }
-\DeclareOption{x-303}{\global\pdfx@xtrue\def\xmp@Part{3}\def\xmp@Conformance{}\def\xmp@ReleaseDate{2003}\global\pdfminorversion=4 }
+%%  default is to create  PDF/A-1b
+%%  options can change this for PDF/X or higher levels of PDF/A
+\DeclareOption{a-1a}{\global\pdfx@xfalse\def\xmp@Part{1}%
+ \def\xmp@Conformance{A}\def\xmp@ReleaseDate{2005}}
+\DeclareOption{a-1b}{\global\pdfx@xfalse\def\xmp@Part{1}%
+ \def\xmp@Conformance{B}\def\xmp@ReleaseDate{2005}}
+\DeclareOption{a-2a}{\global\pdfx@xfalse\def\xmp@Part{2}%
+ \def\xmp@Conformance{A}\def\xmp@ReleaseDate{2010}}
+\DeclareOption{a-2b}{\global\pdfx@xfalse\def\xmp@Part{2}%
+ \def\xmp@Conformance{B}\def\xmp@ReleaseDate{2010}}
+\DeclareOption{a-2u}{\global\pdfx@xfalse\def\xmp@Part{2}%
+ \def\xmp@Conformance{U}\def\xmp@ReleaseDate{2010}}
+\DeclareOption{a-3a}{\global\pdfx@xfalse\def\xmp@Part{3}%
+ \def\xmp@Conformance{A}\def\xmp@ReleaseDate{2012}}
+\DeclareOption{a-3b}{\global\pdfx@xfalse\def\xmp@Part{3}%
+ \def\xmp@Conformance{B}\def\xmp@ReleaseDate{2012}}
+\DeclareOption{a-3u}{\global\pdfx@xfalse\def\xmp@Part{3}%
+ \def\xmp@Conformance{U}\def\xmp@ReleaseDate{2012}}
+\DeclareOption{x-1}{\global\pdfx@xtrue\def\xmp@Part{1}%
+ \def\xmp@Conformance{a}\def\xmp@ReleaseDate{2001}%
+ \global\pdfminorversion=3 }
+\DeclareOption{x-1a}{\global\pdfx@xtrue\def\xmp@Part{1}%
+ \def\xmp@Conformance{a}\def\xmp@ReleaseDate{2003}%
+ \global\pdfminorversion=3 }
+\DeclareOption{x-1a1}{\global\pdfx@xtrue\def\xmp@Part{1}%
+ \def\xmp@Conformance{a}\def\xmp@ReleaseDate{2001}%
+ \global\pdfminorversion=3 }
+\DeclareOption{x-1a3}{\global\pdfx@xtrue\def\xmp@Part{1}%
+ \def\xmp@Conformance{a}\def\xmp@ReleaseDate{2003}%
+ \global\pdfminorversion=3 }
+\DeclareOption{x-2}{\global\pdfx@xtrue\def\xmp@Part{2}%
+ \def\xmp@Conformance{}\def\xmp@ReleaseDate{2002}%
+ \global\pdfminorversion=4 }
+\DeclareOption{x-3}{\global\pdfx@xtrue\def\xmp@Part{3}%
+ \def\xmp@Conformance{}\def\xmp@ReleaseDate{2002}%
+ \global\pdfminorversion=3 }
+\DeclareOption{x-302}{\global\pdfx@xtrue\def\xmp@Part{3}%
+ \def\xmp@Conformance{}\def\xmp@ReleaseDate{2002}%
+ \global\pdfminorversion=3 }
+\DeclareOption{x-303}{\global\pdfx@xtrue\def\xmp@Part{3}%
+ \def\xmp@Conformance{}\def\xmp@ReleaseDate{2003}%
+ \global\pdfminorversion=4 }
 %%%  Later versions, yet to be fully implemented
-\DeclareOption{x-4}{\global\pdfx@xtrue\def\xmp@Part{4}\def\xmp@Conformance{}\def\xmp@ReleaseDate{2008}\global\pdfminorversion=6 }
+\DeclareOption{x-4}{\global\pdfx@xtrue\def\xmp@Part{4}%
+ \def\xmp@Conformance{}\def\xmp@ReleaseDate{2008}%
+ \global\pdfminorversion=6 }
 \DeclareOption{x-4p}{\global\pdfx@xtrue\global\no@iccprofiletrue
-  \def\xmp@Part{4}\def\xmp@Conformance{p}\def\xmp@ReleaseDate{2008}\global\pdfminorversion=6 }
-\DeclareOption{x-408}{\global\pdfx@xtrue\def\xmp@Part{4}\def\xmp@Conformance{}\def\xmp@ReleaseDate{2008}\global\pdfminorversion=6 }
-\DeclareOption{x-410}{\global\pdfx@xtrue\def\xmp@Part{4}\def\xmp@Conformance{}\def\xmp@ReleaseDate{2010}\global\pdfminorversion=6 }
+  \def\xmp@Part{4}\def\xmp@Conformance{p}\def\xmp@ReleaseDate{2008}%
+  \global\pdfminorversion=6 }
+\DeclareOption{x-408}{\global\pdfx@xtrue\def\xmp@Part{4}%
+ \def\xmp@Conformance{}\def\xmp@ReleaseDate{2008}%
+ \global\pdfminorversion=6 }
+\DeclareOption{x-410}{\global\pdfx@xtrue\def\xmp@Part{4}%
+ \def\xmp@Conformance{}\def\xmp@ReleaseDate{2010}%
+ \global\pdfminorversion=6 }
 \DeclareOption{x-4p08}{\global\pdfx@xtrue\global\no@iccprofiletrue
-  \def\xmp@Part{4}\def\xmp@Conformance{p}\def\xmp@ReleaseDate{2008}\global\pdfminorversion=6 }
+  \def\xmp@Part{4}\def\xmp@Conformance{p}\def\xmp@ReleaseDate{2008}%
+  \global\pdfminorversion=6 }
 \DeclareOption{x-4p10}{\global\pdfx@xtrue\global\no@iccprofiletrue
-  \def\xmp@Part{4}\def\xmp@Conformance{p}\def\xmp@ReleaseDate{2010}\global\pdfminorversion=6 }
-\DeclareOption{x-5}{\global\pdfx@xtrue\def\xmp@Part{5}\def\xmp@Conformance{}\def\xmp@ReleaseDate{2008}\global\pdfminorversion=6 }
-\DeclareOption{x-5g}{\global\pdfx@xtrue\def\xmp@Part{5}\def\xmp@Conformance{g}\def\xmp@ReleaseDate{2008}\global\pdfminorversion=6 }
-\DeclareOption{x-5n}{\global\pdfx@xtrue\def\xmp@Part{5}\def\xmp@Conformance{n}\def\xmp@ReleaseDate{2008}\global\pdfminorversion=6 }
+  \def\xmp@Part{4}\def\xmp@Conformance{p}\def\xmp@ReleaseDate{2010}%
+  \global\pdfminorversion=6 }
+\DeclareOption{x-5}{\global\pdfx@xtrue\def\xmp@Part{5}%
+ \def\xmp@Conformance{}\def\xmp@ReleaseDate{2008}%
+ \global\pdfminorversion=6 }
+\DeclareOption{x-5g}{\global\pdfx@xtrue\def\xmp@Part{5}%
+ \def\xmp@Conformance{g}\def\xmp@ReleaseDate{2008}%
+ \global\pdfminorversion=6 }
+\DeclareOption{x-5n}{\global\pdfx@xtrue\def\xmp@Part{5}%
+ \def\xmp@Conformance{n}\def\xmp@ReleaseDate{2008}%
+ \global\pdfminorversion=6 }
 \DeclareOption{x-5pg}{\global\pdfx@xtrue\global\no@iccprofiletrue
-  \def\xmp@Part{5}\def\xmp@Conformance{pg}\def\xmp@ReleaseDate{2008}\global\pdfminorversion=6 }
-\DeclareOption{x-508}{\global\pdfx@xtrue\def\xmp@Part{5}\def\xmp@Conformance{}\def\xmp@ReleaseDate{2008}\global\pdfminorversion=6 }
-\DeclareOption{x-5g08}{\global\pdfx@xtrue\def\xmp@Part{5}\def\xmp@Conformance{g}\def\xmp@ReleaseDate{2008}\global\pdfminorversion=6 }
-\DeclareOption{x-5n08}{\global\pdfx@xtrue\def\xmp@Part{5}\def\xmp@Conformance{n}\def\xmp@ReleaseDate{2008}\global\pdfminorversion=6 }
+  \def\xmp@Part{5}\def\xmp@Conformance{pg}\def\xmp@ReleaseDate{2008}%
+  \global\pdfminorversion=6 }
+\DeclareOption{x-508}{\global\pdfx@xtrue\def\xmp@Part{5}%
+ \def\xmp@Conformance{}\def\xmp@ReleaseDate{2008}%
+ \global\pdfminorversion=6 }
+\DeclareOption{x-5g08}{\global\pdfx@xtrue\def\xmp@Part{5}%
+ \def\xmp@Conformance{g}\def\xmp@ReleaseDate{2008}%
+ \global\pdfminorversion=6 }
+\DeclareOption{x-5n08}{\global\pdfx@xtrue\def\xmp@Part{5}%
+ \def\xmp@Conformance{n}\def\xmp@ReleaseDate{2008}%
+ \global\pdfminorversion=6 }
 \DeclareOption{x-5pg08}{\global\pdfx@xtrue\global\no@iccprofiletrue
-  \def\xmp@Part{5}\def\xmp@Conformance{pg}\def\xmp@ReleaseDate{2008}\global\pdfminorversion=6 }
-\DeclareOption{x-510}{\global\pdfx@xtrue\def\xmp@Part{5}\def\xmp@Conformance{}\def\xmp@ReleaseDate{2010}\global\pdfminorversion=6 }
-\DeclareOption{x-5g10}{\global\pdfx@xtrue\def\xmp@Part{5}\def\xmp@Conformance{g}\def\xmp@ReleaseDate{2010}\global\pdfminorversion=6 }
-\DeclareOption{x-5n10}{\global\pdfx@xtrue\def\xmp@Part{5}\def\xmp@Conformance{n}\def\xmp@ReleaseDate{2010}\global\pdfminorversion=6 }
+  \def\xmp@Part{5}\def\xmp@Conformance{pg}\def\xmp@ReleaseDate{2008}%
+  \global\pdfminorversion=6 }
+\DeclareOption{x-510}{\global\pdfx@xtrue\def\xmp@Part{5}%
+ \def\xmp@Conformance{}\def\xmp@ReleaseDate{2010}%
+ \global\pdfminorversion=6 }
+\DeclareOption{x-5g10}{\global\pdfx@xtrue\def\xmp@Part{5}%
+ \def\xmp@Conformance{g}\def\xmp@ReleaseDate{2010}%
+ \global\pdfminorversion=6 }
+\DeclareOption{x-5n10}{\global\pdfx@xtrue\def\xmp@Part{5}%
+ \def\xmp@Conformance{n}\def\xmp@ReleaseDate{2010}%
+ \global\pdfminorversion=6 }
 \DeclareOption{x-5pg10}{\global\pdfx@xtrue\global\no@iccprofiletrue
-  \def\xmp@Part{5}\def\xmp@Conformance{pg}\def\xmp@ReleaseDate{2010}\global\pdfminorversion=6 }
+  \def\xmp@Part{5}\def\xmp@Conformance{pg}\def\xmp@ReleaseDate{2010}%
+  \global\pdfminorversion=6 }
 \DeclareOption{e-1}{\global\pdfx@xfalse\global\pdfx@etrue
-  \def\xmp@Part{1}\def\xmp@Conformance{}\def\xmp@ReleaseDate{2008}\global\pdfminorversion=6 }
+  \def\xmp@Part{1}\def\xmp@Conformance{}\def\xmp@ReleaseDate{2008}%
+  \global\pdfminorversion=6 }
 \DeclareOption{vt-1}{\global\pdfx@xtrue\global\pdfx@vttrue
-  \def\xmp@Part{4}\def\xmp@vtPart{1}\def\xmp@Conformance{}\def\xmp@vtConformance{}%
-  \def\xmp@ReleaseDate{2010}\global\pdfminorversion=6 }
-\DeclareOption{vt-2}{\global\pdfx@xtrue\global\pdfx@vttrue\global\no@iccprofiletrue
-  \def\xmp@Part{5}\def\xmp@vtPart{2}\def\xmp@Conformance{pg}\def\xmp@vtConformance{}%
-  \def\xmp@ReleaseDate{2010}\global\pdfminorversion=6 }
-\DeclareOption{vt-2s}{\global\pdfx@xtrue\global\pdfx@vttrue\global\no@iccprofiletrue
-  \def\xmp@Part{5}\def\xmp@vtPart{2}\def\xmp@Conformance{pg}\def\xmp@vtConformance{s}%
-  \def\xmp@ReleaseDate{2010}\global\pdfminorversion=6 }
-
-%% extra options to alter the PDF minor version, in case needed in special circumstances
+  \def\xmp@Part{4}\def\xmp@vtPart{1}\def\xmp@Conformance{}%
+  \def\xmp@vtConformance{}\def\xmp@ReleaseDate{2010}%
+  \global\pdfminorversion=6 }
+\DeclareOption{vt-2}{\global\pdfx@xtrue\global\pdfx@vttrue
+  \global\no@iccprofiletrue
+  \def\xmp@Part{5}\def\xmp@vtPart{2}\def\xmp@Conformance{pg}%
+  \def\xmp@vtConformance{}\def\xmp@ReleaseDate{2010}%
+  \global\pdfminorversion=6 }
+\DeclareOption{vt-2s}{\global\pdfx@xtrue\global\pdfx@vttrue
+  \global\no@iccprofiletrue
+  \def\xmp@Part{5}\def\xmp@vtPart{2}\def\xmp@Conformance{pg}%
+  \def\xmp@vtConformance{s}\def\xmp@ReleaseDate{2010}%
+  \global\pdfminorversion=6 }
+
+%% options to alter PDF minor version, in case needed in special circumstances
 \DeclareOption{pdf13}{\global\pdfminorversion=3 }
 \DeclareOption{pdf14}{\global\pdfminorversion=4 }
 \DeclareOption{pdf15}{\global\pdfminorversion=5 }
@@ -995,35 +2379,157 @@
 \DeclareOption{noBOM}{\pdfx@noBOMtrue}
 \DeclareOption{useBOM}{\pdfx@noBOMfalse}
 
-\pdfminorversion=4 %  assumed for PDF/A ;  options may change this for  PDF/X
+\expandafter\ifx\csname pdfminorversion\endcsname\relax
+ \gdef\thepdfminorversion{4}% assumed with XeTeX
+ \def\pdf@minorversion@xetex=#1{\gdef\thepdfminorversion{#1}}%
+ \let\pdfminorversion\pdf@minorversion@xetex
+\else
+ \pdfminorversion=4 %  assumed for PDF/A ;  options may change this for  PDF/X
+\fi
 \expandafter\ifx\csname pdfresetpageorigin\endcsname\relax\else
  \pdfresetpageorigin=0
 \fi
 
+%% options for language character macros in XMP metadata
+\newif\ifcyrxmp
+\newif\ifcyrKOIxmp
+\newif\ifgrkxmp
+\newif\ifgrkLGRxmp
+\newif\ifhebxmp
+\newif\ifarbxmp
+\newif\ifarmxmp
+\newif\ifarmSCIxmp
+\newif\ifvnmxmp
+\newif\iflatEXTxmp
+\newif\iflatLATxmp
+\newif\ifipaxmp
+\newif\ifmathxmp
+
+\DeclareOption{latxmp}{\global\latEXTxmptrue}
+\DeclareOption{LATxmp}{\global\latLATxmptrue\global\latEXTxmptrue}
+\DeclareOption{cyrxmp}{\global\cyrxmptrue}
+\DeclareOption{KOIxmp}{\global\cyrKOIxmptrue\global\cyrxmptrue}
+\DeclareOption{grkxmp}{\global\grkxmptrue}
+\DeclareOption{LGRxmp}{\global\grkLGRxmptrue\global\grkxmptrue}
+\DeclareOption{hebxmp}{\global\hebxmptrue}
+\DeclareOption{arbxmp}{\global\arbxmptrue}
+\DeclareOption{armxmp}{\global\armxmptrue}
+\DeclareOption{AR8xmp}{\global\armSCIxmptrue\global\armxmptrue}
+\DeclareOption{vnmxmp}{\global\vnmxmptrue}
+\DeclareOption{ipaxmp}{\global\ipaxmptrue\global\latEXTxmptrue}
+\DeclareOption{mathxmp}{\global\mathxmptrue\global\grkxmptrue}
+
+%% all the above
+\DeclareOption{allxmp}{%
+ \global\cyrxmptrue
+ \global\cyrKOIxmptrue
+ \global\grkxmptrue
+ \global\grkLGRxmptrue
+ \global\hebxmptrue
+ \global\arbxmptrue
+ \global\armxmptrue
+ \global\armSCIxmptrue
+ \global\vnmxmptrue
+ \global\latEXTxmptrue
+ \global\latLATxmptrue
+ \global\ipaxmptrue
+ \global\mathxmptrue
+}
+
 \ExecuteOptions{noBOM,a-1b}
 \ProcessOptions
 
+\expandafter\ifx\csname thepdfminorversion\endcsname\relax
+ \xdef\thepdfminorversion{\the\pdfminorversion}
+\fi
+
+\newif\ifpdfx@nopdfinfo
+\ifmathxmp\pdfx@nopdfinfotrue
+\else
+ \iflatLATxmp\pdfx@nopdfinfotrue
+\else
+ \ifgrkLGRxmp\pdfx@nopdfinfotrue
+\else
+ \ifcyrKOIxmp\pdfx@nopdfinfotrue
+\else
+ \ifarmSCIxmp\pdfx@nopdfinfotrue
+\fi\fi\fi\fi\fi
+
+\newif\ifpdfx@useactivespaces
+\iflatLATxmp\pdfx@useactivespacestrue\fi
+\ifgrkLGRxmp\pdfx@useactivespacestrue\fi
+\ifcyrKOIxmp\pdfx@useactivespacestrue\fi
+\ifarmSCIxmp\pdfx@useactivespacestrue\fi
+
+\newif\ifpdfx@transliterated
+\ifgrkLGRxmp\pdfx@transliteratedtrue\fi
+\ifarmSCIxmp\pdfx@transliteratedtrue\fi
+
+%% Support for pdfTeX primitives when using XeTeX:
+\RequirePackage{ifxetex}
+\ifxetex
+ \def\pdfx@pages@xetex#1{\special{pdf:put @pages <<#1>>}}
+ \def\pdfx@docinfo@xetex#1{\special{pdf:put @docinfo <<#1>>}}
+ \def\pdfx@catalog@xetex#1{\special{pdf:put @catalog <<#1>>}}
+ \def\pdfx@mapline@xetex#1{}
+ \def\pdf@compress@xetex=#1{}
+%%
+ \let\pdfpageattr\pdfx@pages@xetex
+ \let\pdfinfo\pdfx@docinfo@xetex
+ \let\pdfcatalog\pdfx@catalog@xetex
+ \let\pdfmapline\pdfx@mapline@xetex
+ \let\pdfcompresslevel\pdf@compress@xetex
+ \let\pdfobjcompresslevel\pdf@compress@xetex
+\fi
+
 \RequirePackage{ifluatex}
-\ifluatex 
+\ifluatex
+ \IfFileExists{luatex85.sty}{% 2016+
+  \RequirePackage{luatex85}%
+  \edef\pdfcreationdate{\pdfcreationdate}%
+ }{%  earlier versions
+ }%
  \RequirePackage{pdftexcmds}%
  \let\pdfx@mdfivesum\pdf@mdfivesum
 \else
- \let\pdfx@mdfivesum\pdfmdfivesum
+ \ifxetex
+  \usepackage{everyshi}%
+  \expandafter\ifx\csname mdfivesum\endcsname\relax
+   %  too early a version of  XeTeX
+   \let\pdfx@mdfivesum\relax
+  \else
+   %  since mid-2015
+   \let\pdfx@mdfivesum\mdfivesum
+  \fi
+ \else
+  \let\pdfx@mdfivesum\pdfmdfivesum
+ \fi
 \fi
- \def\pdfx@encodingfile{l8uenc.def}
-
-{\endlinechar=-1
- \everyeof{\noexpand}%
- \xdef\pdfx@bannerstring{\expandafter\scantokens\expandafter{\pdftexbanner}}
-}%
-\def\pdfx@testbannerstr{%
- This is pdfTeX, Version 3.14159265-2.6-1.40.15 (TeX Live 2014/dev) kpathsea version 6.2.0dev}%
-\ifx\pdfx@bannerstring\pdfx@testbannerstr
- \typeout{This version of pdfTeX cannot write out upper-range character bytes, 128-255.}%
- \typeout{Any UTF-8 Unicode characters in the Metadata will not be written correctly.}%
- \typeout{Please update to a more stable version of pdfTeX.^^J}%
+\def\pdfx@encodingfile{l8uenc.def}
+
+\expandafter\ifx\csname pdftexbanner\endcsname\relax
+ \expandafter\ifx\csname luatexbanner\endcsname\relax
+ \else %  luatex85
+  \let\pdftexbanner\luatexbanner
+ \fi
+\else %  pdfTeX, but which version ???
+ {\endlinechar=-1
+  \everyeof{\noexpand}%
+  \xdef\pdfx@bannerstring{\expandafter\scantokens\expandafter{\pdftexbanner}}
+ }%
+ \def\pdfx@testbannerstr{%
+  This is pdfTeX, Version 3.14159265-2.6-1.40.15 (TeX Live 2014/dev)
+  kpathsea version 6.2.0dev}%
+ \ifx\pdfx@bannerstring\pdfx@testbannerstr
+  \typeout{This version of pdfTeX cannot write out upper-range character bytes,
+   128-255.}%
+  \typeout{Any UTF-8 Unicode characters in the Metadata will not be written
+   correctly.}%
+  \typeout{Please update to a more stable version of pdfTeX.^^J}%
+ \fi
 \fi
 
+%% How to support XeTeX here ?
 \ifpdfx@x
  \pdfobjcompresslevel=0 \relax
  \expandafter\ifx\csname pdfinterwordspaceoff\endcsname\relax\else
@@ -1034,50 +2540,67 @@
  \expandafter\ifx\csname pdfgeninterwordspace\endcsname\relax\else
   \pdfgeninterwordspace=0 \relax
  \fi
- \pdfpageattr{/MediaBox[0 0 595 793]
-              /BleedBox[0 0 595 793]
-              /TrimBox[25 20 570 773]}
-\fi
-\ifnum\pdfminorversion >3 \relax
- \expandafter\ifx\csname pdfsuppresswarningdupmap\endcsname\relax
-  \pdfmapline{+dummy-space <dummy-space.pfb}
- \else
-  \advance\pdfsuppresswarningdupmap 1
-  \pdfmapline{+dummy-space <dummy-space.pfb}
-  \advance\pdfsuppresswarningdupmap -1
- \fi
- \expandafter\ifx\csname pdfgeninterwordspace\endcsname\relax\else
-  \pdfgeninterwordspace=1 \relax
+ \begingroup
+  \dimen0=0.996264009963\paperwidth\relax
+  \edef\pdfx@mwidth{\strip@pt\dimen0}%
+  \advance\dimen0 -25\p@
+  \edef\pdfx@twidth{\strip@pt\dimen0}%
+  \dimen0=0.996264009963\paperheight\relax
+  \edef\pdfx@mheight{\strip@pt\dimen0}%
+  \advance\dimen0 -20\p@
+  \edef\pdfx@theight{\strip@pt\dimen0}%
+  \ifxetex
+   \xdef\pdfx@everypage@xetex{%
+    /MediaBox[0 0 \pdfx@mwidth\space \pdfx@mheight]^^J
+    /TrimBox[25 20 \pdfx@twidth\space \pdfx@theight]%
+   }%
+  \fi
+  \edef\next{\endgroup\pdfpageattr{%
+    /MediaBox[0 0 \pdfx@mwidth\space \pdfx@mheight]^^J
+%%    /ArtBox[0 0 \pdfx@mwidth\space \pdfx@mheight]^^J
+    /BleedBox[0 0 \pdfx@mwidth\space \pdfx@mheight]^^J
+    /TrimBox[25 20 \pdfx@twidth\space \pdfx@theight]}
+  }\next
+ \ifxetex
+  \AtBeginDvi{%
+   \immediate\special{pdf:put @thispage <<\pdfx@everypage@xetex>>}}%
+  \EveryShipout{%
+   \immediate\special{pdf:put @thispage <<\pdfx@everypage@xetex>>}}%
  \fi
 \fi
-%% the "pdftex" option seems to work fine with LuaTeX 
-\ifpdfx@x
- \@ifpackageloaded{hyperref}{%
-  \hypersetup{draft,pdftex,pdfpagemode=UseNone,bookmarks=false,pdfversion=1.\the\pdfminorversion]}
- }{%
-  \RequirePackage[draft,pdftex,pdfpagemode=UseNone,bookmarks=false,pdfversion=1.\the\pdfminorversion]{hyperref}
- }%
+\ifxetex
+%% How to support XeTeX here ?
 \else
- \ifpdfx@e
-  \@ifpackageloaded{hyperref}{%
-   \hypersetup{draft,pdftex,pdfpagemode=UseNone,bookmarks=false,pdfversion=1.\the\pdfminorversion]}
-  }{%
-   \RequirePackage[draft,pdftex,pdfpagemode=UseNone,bookmarks=false,pdfversion=1.\the\pdfminorversion]{hyperref}
-  }%
- \else
- \@ifpackageloaded{hyperref}{%
-  \hypersetup{pdftex,pdfa}%
-  \Hy@pdfatrue
- }{%
-  \RequirePackage[pdftex,pdfa]{hyperref}
-  \Hy@pdfatrue
- }%
-\fi\fi
-\hypersetup{pdfencoding=auto}%  unicode
+ \ifnum\thepdfminorversion >3 \relax
+  \expandafter\ifx\csname pdfsuppresswarningdupmap\endcsname\relax
+   \expandafter\ifx\csname pdfmapline\endcsname\relax\else
+    \pdfmapline{+dummy-space <dummy-space.pfb}
+   \fi
+  \else
+   \advance\pdfsuppresswarningdupmap 1
+   \pdfmapline{+dummy-space <dummy-space.pfb}
+   \advance\pdfsuppresswarningdupmap -1
+  \fi
+  \expandafter\ifx\csname pdfgeninterwordspace\endcsname\relax\else
+   \pdfgeninterwordspace=1 \relax
+  \fi
+ \fi
+\fi
 
 \ifluatex\else
- \RequirePackage{inputenc}
+ \@ifpackageloaded{inputenc}{%
+ }{%
+  \RequirePackage{inputenc}
+ % allow this to be loaded again cleanly
+ \expandafter\let\csname ver@inputenc.sty\endcsname\relax
+ }
 \fi
+
+%% pseudo-declare the L8U encoding
+\expandafter\let\csname L8U-cmd\expandafter\endcsname\csname OT1-cmd\endcsname
+\@namedef{T@L8U}{}%
+\@namedef{D@L8U}{}%
+\@namedef{M@L8U}{}%
 \InputIfFileExists{\pdfx@encodingfile}{}{}
 
 %%----------------------------------------------------------------------
@@ -1093,6 +2616,7 @@
  \begingroup
  \catcode`\<=13\catcode`\>=13\catcode`\&=13\catcode`\^=12
  \catcode`\_=12\catcode`\#=12\catcode`\$=12\catcode`\~=12
+ \ifpdfx@useactivespaces\obeyspaces\fi % capture spaces as active characters
  \xmp@doparse{#1}%
 }
 \def\xmp@doparse#1#2{%
@@ -1127,7 +2651,10 @@
    \ifx\xmp@PublicationType\@empty\gdef\xmp@PublicationType{journal}\fi}}
  \def\Journalnumber{\xmp@parse{\global\let\xmp@Journalnumber\@this}}
  \def\Publisher{\xmp@parse{\global\let\xmp@Publisher\@this}}
- \def\AuthoritativeDomain{\xmp@parse{\global\let\xmp@AuthoritativeDomain\@this}} % currently unused; for backward compatibility
+%%
+%% currently unused; for backward compatibility only
+ \def\AuthoritativeDomain{\xmp@parse
+   {\global\let\xmp@AuthoritativeDomain\@this}}
  \let\Creator\CreatorTool  % for backward compatibility
  \let\Org\Publisher        % for backward compatibility
  \let\WebStatement\CopyrightURL  % for backward compatibility
@@ -1135,18 +2662,18 @@
 
 %%----------------------------------------------------------------------
 %% The following characters and markup can be used within the XMP data
-%% defined by \Author, \Title, and so on. 
+%% defined by \Author, \Title, and so on.
 %%
 %% * All printable non-whitespace ASCII characters except
 %%   '%', '{', '}', '\' can be used as themselves.
-%% 
+%%
 %% * All printable non-whitespace UTF-8 encoded Unicode characters
 %%   from the basic multilingual plane can be used as themselves.
-%% 
+%%
 %% * As usual, consecutive whitespace characters are contracted to a
 %%   single space. Whitespace after a macro such as \copyright is
-%%   ignored. Blank lines are not permitted. 
-%% 
+%%   ignored. Blank lines are not permitted.
+%%
 %% * The following markup can be used:
 %%   '\ '        - a literal space  (for example after a macro)
 %%   \%          - a literal '%'
@@ -1156,7 +2683,7 @@
 %%   \copyright  - the (c) copyright symbol
 %%
 %%   \sep        - only permitted within \Author, \Keywords, \Publisher.
-%% 
+%%
 %% * For backward compatibility, \& and \TextCopyright are also
 %%   provided. Their use is deprecated.
 
@@ -1178,64 +2705,131 @@
 %%----------------------------------------------------------------------
 %% Markup bindings to be used during XMP generation.
 
-{\obeyspaces\gdef\pdfx@sep{</rdf:li>^^J     <rdf:li>}}
+{\obeyspaces\ifpdfx@useactivespaces%
+\xdef\pdfx@sep {</rdf:li>^^J     <rdf:li>}%
+\else\gdef\pdfx@sep{</rdf:li>^^J     <rdf:li>}%
+\fi}
 
-\def\pdfx@xmpmarkup{
+\def\pdfx@xmpmarkup{%
  \pdfx@actives
- \edef\@amp{\expandafter\@gobble\string\&}
- \edef\@hash{\expandafter\@gobble\string\#}
- \edef\ {\expandafter\@gobble\string\ }
- \edef\%{\expandafter\@gobble\string\%}
- \edef\{{\expandafter\@gobble\string\{}
- \edef\}{\expandafter\@gobble\string\}}
- \edef\backslash{\expandafter\@gobble\string\\}
- \def\@unicode##1{\@amp\@hash x##1;}
- \def\pdfx@amp{\@unicode{0026}}
- \def\pdfx@lt{\@unicode{003c}}
- \def\pdfx@gt{\@unicode{003e}}
- \def\copyright{\@unicode{00A9}}
+ \edef\@amp{\expandafter\@gobble\string\&}%
+ \edef\@hash{\expandafter\@gobble\string\#}%
+ \edef\ {\expandafter\@gobble\string\ }%
+ \edef\%{\expandafter\@gobble\string\%}%
+ \edef\{{\expandafter\@gobble\string\{}%
+ \edef\}{\expandafter\@gobble\string\}}%
+ \edef\backslash{\expandafter\@gobble\string\\}%
+ \def\@unicode##1{\@amp\@hash x##1;}%
+ \def\pdfx@amp{\@unicode{0026}}%
+ \def\pdfx@lt{\@unicode{003c}}%
+ \def\pdfx@gt{\@unicode{003e}}%
+ \def\copyright{\@unicode{00A9}}%
  \let\&\pdfx@amp               % for backward compatibility
  \let\TextCopyright\copyright  % for backward compatibility
  \let\sep\pdfx@sep
+ \pdfx@xmpunimarkup   % only need this when writing XMP
  \the\pdfxsafeforxmp@toks
 }
 
+%% cope with active spaces with LGR encoding
+%% and the spaces written out with \IeC in KOI8-r
+%% It's possible to have both together.
+\def\liixu@IeC#1#{\liixu@IeCi}
+\def\liixu@IeCi#1{\liixu@IeCii#1}
+\def\liixu@IeCii#1#2{#1}
+\def\liixu@enableIeC{\ifpdfx@useactivespaces
+ \let\IeC\liixu@IeC\else\def\IeC##1{##1}\fi}
+\def\liixu@numberline#1#{\liixu@numberlinei}
+\def\liixu@numberlinei#1{\liixu@numberlineii#1}
+\def\liixu@numberlineii#1{\textLF #1. }
+\def\liixu@enablenumberline{\ifpdfx@useactivespaces
+ \let\numberline\liixu@numberline
+ \else\def\numberline##1{\textLF ##1. }\fi}
+
+\def\pdfx@xmpunimarkup{%
+ \liixu@enableIeC
+ \liixu@enablenumberline
+ \def\empty{}% used in LICR patterns
+ \let\sp\textsuperstring
+ \let\sb\textsubstring
+ \let\textsuperscript\dotextsuperscript
+ \LIIXUmapTeXnames
+%%  from Hyperref's  psdextra.def
+ \csname psdmapshortnames\endcsname
+ \csname psdaliasnames\endcsname
+%% from  lu8enc.def
+ \csname LIIXUmapmathletterlikes\endcsname
+ \csname LIIXUmapmathspaces\endcsname
+ \iflatLATxmp
+  \LIIXUmaplatinchars
+  \LIIXUcancelfontswitches
+ \fi
+ \ifmathxmp
+  \let\(\textinlinemath
+  \let\[\textdisplaymath
+  \LIIXUmapmathaccents
+  \LIIXUmapisomathgreek
+  \LIIXUmapmatharrowsA
+  \LIIXUmapmathoperatorsA
+  \LIIXUmapmathoperatorsB
+  \LIIXUmapmiscmathsymbolsA
+  \LIIXUmapsupparrowsA
+  \LIIXUmapsupparrowsB
+  \LIIXUmapmiscmathsymbolsB
+  \LIIXUmapsuppmathoperators
+  \LIIXUmapunimathgreek
+  \LIIXUmapmathalphabets
+ \fi
+ \ifarbxmp \LIIXUmaparabicletters\fi
+ \ifarmxmp \LIIXUmaparmenianletters\fi
+ \ifgrkxmp \LIIXUmapgreekletters\fi
+}
+
 %% In case macros are used in XMP Metadata, need a way to map these
 %% to simple text, rather than specific font characters, or whatever:
 \newtoks\pdfxsafeforxmp@toks
-\def\pdfxEnableCommands#1{%   user command
+\def\pdfxEnableCommands{%   user command
+ \begingroup
+  \ifpdfx@useactivespaces\obeyspaces\fi
+  \pdfx@EnableCommands
+}
+\def\pdfx@EnableCommands#1{%   internal command
  \expandafter\global\expandafter\pdfxsafeforxmp@toks
-  \expandafter{\the\pdfxsafeforxmp@toks#1}}
+  \expandafter{\the\pdfxsafeforxmp@toks#1}%
+ \endgroup
+}
 
 %%----------------------------------------------------------------------
 %% Markup bindings to be used during PDF string generation.
 
-\def\pdfx@pdfmarkup{
+\def\pdfx@pdfmarkup{%
  \pdfx@actives
- \edef\%{\expandafter\@gobble\string\%}
- \edef\{{\expandafter\@gobble\string\{}
- \edef\}{\expandafter\@gobble\string\}}
- \edef\pdfx@backslash{\expandafter\@gobble\string\\}
- \def\backslash{\pdfx@backslash000\pdfx@backslash134}
- \edef\pdfx@amp{\expandafter\@gobble\string\&}
- \edef\pdfx@lt{\expandafter\@gobble\string\<}
- \edef\pdfx@gt{\expandafter\@gobble\string\>}
+ \edef\%{\expandafter\@gobble\string\%}%
+ \edef\{{\expandafter\@gobble\string\{}%
+ \edef\}{\expandafter\@gobble\string\}}%
+ \edef\pdfx@backslash{\expandafter\@gobble\string\\}%
+ \def\backslash{\pdfx@backslash000\pdfx@backslash134}%
+ \edef\pdfx@amp{\expandafter\@gobble\string\&}%
+ \edef\pdfx@lt{\expandafter\@gobble\string\<}%
+ \edef\pdfx@gt{\expandafter\@gobble\string\>}%
  \let\TextCopyright\copyright  % for backward compatibility
- \def\sep{, }
+ \def\sep{; }%
+ %\let\sep\pdfx@sep
 %% Note: '\ ', \&, \copyright are already predefined by hyperref.
  \the\pdfxsafeforxmp@toks
 }
 
 %%----------------------------------------------------------------------
 %% Defaults
-
-\ifluatex
+\ifxetex
+ \def\xmp@Producer{XeTeX}
+\else\ifluatex
  \def\xmp@Producer{LuaTeX}
 \else
  \def\xmp@Producer{pdfTeX}
-\fi
-\edef\xmp@CreatorTool{\@pdfcreator}
+\fi\fi
 
+\global\let\xmp@CreatorTool\@empty
 \global\let\xmp@Title\@empty
 \global\let\xmp@Author\@empty
 \global\let\xmp@Keywords\@empty
@@ -1245,6 +2839,7 @@
 \global\let\xmp@CoverDisplayDate\@empty
 \global\let\xmp@CoverDate\@empty
 \global\let\xmp@Copyright\@empty
+\global\let\xmp@Copyrighted\@empty
 \global\let\xmp@CopyrightURL\@empty
 \gdef\xmp@WebStatement{\xmp@CopyrightURL}
 \global\let\xmp@Doi\@empty
@@ -1257,6 +2852,35 @@
 \gdef\xmp@Org{\xmp@Publisher}
 \global\let\xmp@AuthoritativeDomain\@empty
 
+%%----------------------------------------------------------------------
+%%  Alternative way to get the CreationDate using Lua  for XeTeX
+\ifdefined\pdfcreationdate\else
+\begin{filecontents*}{creationdate.lua}
+ os.remove("creationdate.timestamp")
+ io.output("creationdate.timestamp"):write(os.date("\\edef\\tempa{\\string D:%Y%m%d%H%M%S}\n\\def\\tempb{%z}"))
+\end{filecontents*}
+ \ifnum\shellescape=1
+  \begingroup
+   \immediate\write18{texlua creationdate.lua}
+   \input{creationdate.timestamp}
+   \def\tempc#1#2#3#4#5{#1#2#3'#4#5'}
+   \edef\tempb{\expandafter\tempc\tempb}
+   \edef\x{\endgroup\def\noexpand\pdfcreationdate{\tempa\tempb}}\x
+ \else
+  \ifpdfx@noerr
+   \PackageWarning{pdfx}{%
+    CreationDate is not properly supported;^^J
+    PDF validation may fail. To avoid this problem use:^^J
+     xelatex -shell-escape -output-driver="xdvipdfmx -z 0" <filename>^^J}
+  \else
+   \PackageError{pdfx}{%
+    CreationDate is not properly supported;^^J
+    PDF validation may fail.}{To avoid this problem use:^^J
+     xelatex -shell-escape -output-driver="xdvipdfmx -z 0" <filename> }
+  \fi
+ \fi
+\fi
+
 %%----------------------------------------------------------------------
 \def\pdfx@findUUID#1{\edef\pdfx@tmpstring{\pdfx@mdfivesum{#1}}
      \expandafter\pdfx@eightofnine\pdfx@tmpstring\end}
@@ -1276,46 +2900,172 @@
           \pdfx@tfourchars-%
           \pdfx@laststring}
 
-\pdfx@findUUID{\jobname.pdf}
-\edef\xmp@docid{\pdfx@uuid}
-\pdfx@findUUID{\pdfcreationdate}
-\edef\xmp@instid{\pdfx@uuid}
+\expandafter\ifx\csname pdfx@mdfivesum\endcsname\relax
+  \PackageError{pdfx}{%
+    No implementation for \string\pdfx@mdfivesum.^^J
+    \ifxetex XeTeX needs to be 2015 or later\fi
+   }{%
+    Continue without, but the PDF will not validate.
+   }%
+ \def\xmp@docid{}%
+ \def\pdfx@findUUID#1{}%
+ \def\pdfx@uuid{}%
+\else
+ \pdfx@findUUID{\jobname.pdf}
+ \edef\xmp@docid{\pdfx@uuid}
+\fi
+
+\expandafter\ifx\csname pdfcreationdate\endcsname\relax\relax
+  \PackageWarning{pdfx}{%
+   No implementation for \string\pdfxcreation .
+  }%
+ \def\xmp@instid{}%
+%%
+\else   %% use the MD5 sum methods
+%%
+ \pdfx@findUUID{\pdfcreationdate}%
+ \edef\xmp@instid{\pdfx@uuid}
+\fi
 
+%%----------------------------------------------------------------------
+%% load  xcolor  before  hyperref  to get the link colors correct
+%%
+\ifpdfx@x
+ \RequirePackage[cmyk,hyperref]{xcolor}
+\else
+%% \RequirePackage[rgb,hyperref]{xcolor}
+\fi
+
+%% the "pdftex" option seems to work fine with LuaTeX
+
+%% Hyperref options for PDF/X
+\def\pdfx@pdfX@opts@pdftex{%
+  draft,pdftex,pdfpagemode=UseNone,bookmarks=false,%
+    pdfversion=1.\thepdfminorversion,pdfstartview=}
+\def\pdfx@pdfX@opts@xetex{%
+  draft,xetex,pdfpagemode=UseNone,bookmarks=false,%
+  pdfversion=1.\thepdfminorversion,pdfstartview=}
+\def\pdfx@pdfX@opts@luatex{%
+  draft,pdftex,pdfpagemode=UseNone,bookmarks=false,%
+  pdfversion=1.\thepdfminorversion,pdfstartview=}
+
+%% Hyperref options for PDF/A and PDF/E
+\def\pdfx@pdfAE@opts@pdftex{pdftex,pdfa,pdfversion=1.\thepdfminorversion}%
+\def\pdfx@pdfAE@opts@xetex{xetex,pdfa,pdfversion=1.\thepdfminorversion}%
+\def\pdfx@pdfAE@opts@luatex{pdftex,pdfa,pdfversion=1.\thepdfminorversion}%
+    
+\ifpdfx@x
+ \@ifpackageloaded{hyperref}{%
+  \ifxetex
+   \hypersetup{\pdfx@pdfX@opts@xetex}
+  \else\ifluatex
+   \hypersetup{\pdfx@pdfX@opts@luatex}
+  \else
+   \hypersetup{\pdfx@pdfX@opts@pdftex}
+  \fi\fi
+ }{%
+  \ifxetex
+   \RequirePackage[\pdfx@pdfX@opts@xetex]{hyperref}
+  \else\ifluatex
+   \RequirePackage[\pdfx@pdfX@opts@luatex]{hyperref}
+  \else
+   \RequirePackage[\pdfx@pdfX@opts@pdftex]{hyperref}
+  \fi\fi
+ }%
+\else
+ \ifpdfx@e
+  \@ifpackageloaded{hyperref}{%
+   \ifxetex
+    \hypersetup{\pdfx@pdfAE@opts@xetex}
+   \else\ifluatex
+    \hypersetup{\pdfx@pdfAE@opts@luatex}
+   \else
+    \hypersetup{\pdfx@pdfAE@opts@pdftex}
+   \fi\fi
+  }{%
+   \ifxetex
+    \RequirePackage[\pdfx@pdfAE@opts@xetex]{hyperref}
+   \else\ifluatex
+    \RequirePackage[\pdfx@pdfAE@opts@luatex]{hyperref}
+   \else
+    \RequirePackage[\pdfx@pdfAE@opts@pdftex]{hyperref}
+   \fi\fi
+  }%
+ \else % generating PDF/A or ...
+  \@ifpackageloaded{hyperref}{%
+   \ifxetex
+    \hypersetup{\pdfx@pdfAE@opts@xetex}%
+   \else\ifluatex
+    \hypersetup{\pdfx@pdfAE@opts@luatex}%
+   \else
+    \hypersetup{\pdfx@pdfAE@opts@pdftex}%
+   \fi\fi
+  }{%
+   \ifxetex
+    \RequirePackage[\pdfx@pdfAE@opts@xetex]{hyperref}
+   \else\ifluatex
+    \RequirePackage[\pdfx@pdfAE@opts@luatex]{hyperref}
+   \else
+    \RequirePackage[\pdfx@pdfAE@opts@pdftex]{hyperref}
+   \fi\fi
+ }%
+\fi\fi
+\hypersetup{pdfencoding=auto}%  unicode
+\expandafter\ifx\csname KV@Hyp@psdextra\endcsname\relax\else
+ \hypersetup{psdextra}
+\fi
+
+\ifx\xmp@CreatorTool\@empty
+ \edef\xmp@CreatorTool{\@pdfcreator}
+\fi
+
+\newif\ifpdfx@cmyk
+\ifpdfx@x   %  PDF/X  normally needs a CMYK color profile for printing
+ \global\pdfx@cmyktrue
+\fi
 %%----------------------------------------------------------------------
 %% -----   Color Profiles  -------
 %% Define how to specify the profile, so the default
 %% can be over-ridden in the  .xmpdata  file.
 %%
-%%   --- user-command ---   RGB profile needed with  PDF/A-??  files
-%%   \setRGBcolorprofile{<filename>}{<identifier>}{<info string>}{<registry URL>}
+%%   --- user-command ---   RGB profile needed with  PDF/A-??
+%% \setRGBcolorprofile{<filename>}{<identifier>}
+%%    {<info string>}{<registry URL>}
 \def\setRGBcolorprofile{%
  \begingroup
-  \catcode`\_ 11\relax\catcode`\& 11\relax\catcode`\~ 11\relax\catcode`\% 11\relax
+  \catcode`\_ 11\relax\catcode`\& 11\relax\catcode`\~ 11\relax
+  \catcode`\% 11\relax
   \edef\({\string\(}\edef\){\string\)}%
   \pdfx@setrgbprofile}
 %%
-%%  --- user-command ---   CMYK profile needed with  PDF/X-??  files
-%%  \setCMYKcolorprofile{<filename>}{<output intent>}{<identifier>}{<registry URL>}
+%%  --- user-command ---   CMYK profile needed with  PDF/X-??
+%% \setCMYKcolorprofile{<filename>}{<output intent>}
+%%    {<identifier>}{<registry URL>}
 \def\setCMYKcolorprofile{%
  \begingroup
-  \catcode`\_ 11\relax\catcode`\& 11\relax\catcode`\~ 11\relax\catcode`\% 11\relax
+  \catcode`\_ 11\relax\catcode`\& 11\relax\catcode`\~ 11\relax
+  \catcode`\% 11\relax
   \edef\({\string\(}\edef\){\string\)}%
   \pdfx@setcmykprofile}
 %%
-%%  --- user-command ---   DeviceGray profile needed with  PDF/E-1  files
-%%  \setGRAYcolorprofile{<filename>}{<output intent>}{<identifier>}{<registry URL>}
+%%  --- user-command ---   DeviceGray profile needed with  PDF/E-1
+%% \setGRAYcolorprofile{<filename>}{<output intent>}
+%%    {<identifier>}{<registry URL>}
 \def\setGRAYcolorprofile{%
  \begingroup
-  \catcode`\_ 11\relax\catcode`\& 11\relax\catcode`\~ 11\relax\catcode`\% 11\relax
+  \catcode`\_ 11\relax\catcode`\& 11\relax\catcode`\~ 11\relax
+  \catcode`\% 11\relax
   \edef\({\string\(}\edef\){\string\)}%
   \pdfx@setgrayprofile}
 %%
-%%  --- user-command ---   External profile needed with  PDF/X-4p  and PDF/X-5pg  files
-%%  \setEXTERNALprofile{<profilename>}{<output intent>}{<identifier>}{<registry URL>}%
-%%    {<color-space>}{<ICC Version>}{<provider URL>}{<extra info>}{<Check Sum>}
+%%  --- user-command ---  External profile with  PDF/X-4p and PDF/X-5pg
+%% \setEXTERNALprofile{<profilename>}{<output intent>}
+%%    {<identifier>}{<registry URL>}{<color-space>}%
+%%    {<ICC Version>}{<provider URL>}{<extra info>}{<Check Sum>}
 \def\setEXTERNALprofile{%
  \begingroup
-  \catcode`\_ 11\relax\catcode`\& 11\relax\catcode`\~ 11\relax\catcode`\% 11\relax
+  \catcode`\_ 11\relax\catcode`\& 11\relax\catcode`\~ 11\relax
+  \catcode`\% 11\relax
   \edef\({\string\(}\edef\){\string\)}%
   \pdfx@externalprofile}
 %%
@@ -1330,33 +3080,44 @@
 \pdfx@setCMYKcolorprofiledir{}
 
 %% This does indeed work!  Use it in  .xmpdata  files
-\providecommand{\AdobeMacOSdir}{/Library/Application Support/Adobe/Color/Profiles/Recommended/}
-\edef\pdfx@tmp{C:\string\Windows\string\System32\string\Spool\string\Drivers\string\Color\string/}
-\expandafter\providecommand\expandafter{\expandafter\WindowsColordir\expandafter}\expandafter{\pdfx@tmp}
+\providecommand{\MacOSColordir}%
+  {/System/Library/ColorSync/Profiles/}
+\providecommand{\AdobeMacOSdir}%
+  {/Library/Application Support/Adobe/Color/Profiles/Recommended/}
+\edef\pdfx@tmp{C:\string\Windows\string\System32\string\Spool%
+  \string\Drivers\string\Color\string/}
+\expandafter\providecommand\expandafter
+  {\expandafter\WindowsColordir\expandafter}\expandafter{\pdfx@tmp}
 %%\pdfx@setcolorprofiledir{\AdobeMacOSdir}
 
 %% overide that value using the following commands:
 \let\pdfxSetCMYKcolorProfileDir\pdfx@setCMYKcolorprofiledir
 \let\pdfxSetRGBcolorProfileDir\pdfx@setRGBcolorprofiledir
-\let\pdfxSetColorProfileDir\pdfxSetCMYKcolorProfileDir % for back-compatibility
+%%  for back-compatibility
+\let\pdfxSetColorProfileDir\pdfxSetCMYKcolorProfileDir
 %%
 \def\pdfx@setrgbprofile#1#2#3#4{%
  \xdef\pdfx@rgb@profile{\pdfx@RGBcolorprofiledir#1}%  valid file name
  \gdef\pdfx@rgb@identifier{#2}%
  \gdef\pdfx@rgb@info{#3}%
  \pdfstringdef\pdfx@rgb@registry{#4}%  valid URL
- \endgroup}%  closes-off  \setRGBcolorprofile
+ \endgroup
+ \global\pdfx@cmykfalse
+ }%  closes-off  \setRGBcolorprofile
 %%
 \def\pdfx@setcmykprofile#1#2#3#4{%
  \xdef\pdfx@cmyk@profile{\pdfx@CMYKcolorprofiledir#1}%  valid file name
-%% \expandafter\gdef\expandafter\pdfx@cmyk@profile\expandafter{\pdfx@colorprofiledir#1}%  valid file name
+%% \expandafter\gdef\expandafter\pdfx@cmyk@profile\expandafter
+%%    {\pdfx@colorprofiledir#1}%  valid file name
  \gdef\pdfx@cmyk@intent{#2}%
 %% \pdfstringdef\pdfx@cmyk@intent{#2}%  color intent
  \gdef\pdfx@cmyk@identifier{#3}%
 %% \pdfstringdef\pdfx@cmyk@identifier{#3}%  text string identifier
  \gdef\pdfx@cmyk@registry{#4}%
 %% \pdfstringdef\pdfx@cmyk@registry{#4}%  valid URL
- \endgroup}%  closes-off  \setCMYKcolorprofile
+ \endgroup
+ \global\pdfx@cmyktrue
+ }%  closes-off  \setCMYKcolorprofile
 %%
 \def\pdfx@setgrayprofile#1#2#3#4{%
  \gdef\pdfx@gray@profile{#1}%  valid file name
@@ -1366,15 +3127,15 @@
  \endgroup}%  closes-off  \setGRAYcolorprofile
 %%
 \def\pdfx@externalprofile#1#2#3#4#5#6#7#8#9{%
- \gdef\pdfx@extprofile{#1}% PDF string for /ProfileName 
+ \gdef\pdfx@extprofile{#1}% PDF string for /ProfileName
  \gdef\pdfx@cmyk@intent{#2}% PDF string for /OutputCondition
  \gdef\pdfx@cmyk@identifier{#3}% PDF string for /OutputConditionIdentifier
- \gdef\pdfx@cmyk@registry{#4}% {http://www.color.org}% 
+ \gdef\pdfx@cmyk@registry{#4}% {http://www.color.org}%
  \gdef\pdfx@profileCS{#5}%  4 bytes for /ProfileCS
  \gdef\pdfx@iccversion{#6}%  Hex string for /ICCVersion < ... >
- \gdef\pdfx@colorURL{#7}%  URL  
- \gdef\pdfx@cmyk@info{#8}%  for /Info 
- \gdef\pdfx@profile@checksum{#9}%  Hex string for /CheckSum < ... > 
+ \gdef\pdfx@colorURL{#7}%  URL
+ \gdef\pdfx@cmyk@info{#8}%  for /Info
+ \gdef\pdfx@profile@checksum{#9}%  Hex string for /CheckSum < ... >
  \endgroup}%  closes-off  \setEXTERNALprofile
 %%
 %% default color profiles
@@ -1394,7 +3155,7 @@
 %%
 %% Copyright International Color Consortium, 2009  -- http://www.color.org/
 %%
-%% It is hereby acknowledged that the file "sRGB_IEC61966-2-1_black_scaled.icc" 
+%% It is hereby acknowledged that the file "sRGB_IEC61966-2-1_black_scaled.icc"
 %% is provided "AS IS" WITH NO EXPRESS OR IMPLIED WARRANTY.
 %%
 %% Licensing
@@ -1407,28 +3168,32 @@
 %%
 %% Terms of use
 %%
-%% To anyone who acknowledges that the file "sRGB_IEC61966-2-1_black_scaled.icc" is provided "AS IS" WITH NO EXPRESS 
-%% OR IMPLIED WARRANTY, permission to use, copy and distribute these file for any purpose is hereby granted without fee, 
-%% provided that the file is not changed including the ICC copyright notice tag, and that the name of ICC shall not be used 
-%% in advertising or publicity pertaining to distribution of the software without specific, written prior permission. 
-%% ICC makes no representations about the suitability of this software for any purpose.
+%% To anyone who acknowledges that the file "sRGB_IEC61966-2-1_black_scaled.icc"
+%% is provided "AS IS" WITH NO EXPRESS OR IMPLIED WARRANTY, permission to use,
+%% copy and distribute these file for any purpose is hereby granted without fee,
+%% provided that the file is not changed including the ICC copyright notice tag,
+%% and that the name of ICC shall not be used in advertising or publicity
+%% pertaining to distribution of the software without specific, written prior
+%% permission. ICC makes no representations about the suitability of this
+%% software for any purpose.
 %%
 %%----------------------------------------------------------------------
 {\catcode`\| 14 \catcode`\% 12 \catcode`\_ 12
  \edef\@bchar{\expandafter\@gobble\string\\}|
  \edef\({\string\(}\edef\){\string\)}|
  \begingroup | \endgroup occurs within the macro expansion
-\expandafter\pdfx@setrgbprofile\expandafter{sRGB_IEC61966-2-1_black_scaled.icc}|
+\expandafter\pdfx@setrgbprofile\expandafter
+ {sRGB_IEC61966-2-1_black_scaled.icc}|
  {sRGB_IEC61966-2-1_black_scaled}|
  {sRGB IEC61966 v2.1 with black scaling}|
  {http://www.color.org}|
  \begingroup | \endgroup occurs within the macro expansion
-\pdfx@setcmykprofile{coated_FOGRA39L_argl.icc}|{FOGRA39L.icc}| coated_FOGRA39L_argl.icc
+\pdfx@setcmykprofile{coated_FOGRA39L_argl.icc}| coated_FOGRA39L_argl.icc
  {Coated FOGRA39}|
  {FOGRA39 \string\(ISO Coated v2 300%\space \string\(ECI\string\)\string\)}|
  {http://www.argyllcms.com/}|{http://www.color.org}|
  \begingroup | \endgroup occurs within the macro expansion
-\pdfx@setgrayprofile{Gray_linear.icc}| 
+\pdfx@setgrayprofile{Gray_linear.icc}|
  {}|
  {Custom}|
  {http://www.freedesktop.org/wiki/OpenIcc}|
@@ -1474,76 +3239,80 @@
 
 \begingroup
 %% override unneeded color-profile specifier
- \ifpdfx@x 
-  \ifno@iccprofile %  PDF/X-4p  and  PDF/X-5pg  PDF/VT-2
-   \begingroup 
+ \ifpdfx@x
+  \ifno@iccprofile %  PDF/X-4p and PDF/X-5pg  PDF/VT-2
+   \begingroup
     \def\pdfx@extprofiles@store{AdobeExternalProfiles.tex}%
     \InputIfFileExists{\pdfx@extprofiles@store}%
      {\global\externalICCprofilestrue \catcode `\# 12\relax}%
-     {\typeout{** pdfx: No file \pdfx@extprofiles@store\space found for PDF/X-4p or PDF/X-5pg}}%
+     {\typeout{** pdfx: No file \pdfx@extprofiles@store\space
+       found for PDF/X-4p or PDF/X-5pg}}%
    \endgroup
   \else
-   \begingroup 
+   \begingroup
     \def\pdfx@profiles@store{AdobeColorProfiles.tex}%
     \InputIfFileExists{\pdfx@profiles@store}%
      {\global\externalICCprofilesfalse \catcode `\# 12\relax}%
-     {\typeout{** pdfx: No file \pdfx@profiles@store\space found for PDF/X variants}}%
+     {\typeout{** pdfx: No file \pdfx@profiles@store\space
+       found for PDF/X variants}}%
    \endgroup
-   \def\setRGBcolorprofile#1#2#3#4{}%
+%%   \def\setRGBcolorprofile#1#2#3#4{%
+%%    \PackageError{pdfx}{PDF/X requires a CMYK color profile}%
+%%     {Just continue using the default CMYK profile.^^J}}%
   \fi
  \else
 %% load it, in case the macros are used in .xmpdata
   \InputIfFileExists{AdobeColorProfiles.tex}{}{}%
-  \ifpdfx@e 
+  \ifpdfx@e
   \else
    \def\setCMYKcolorprofile#1#2#3#4{}%
    \def\setGRAYcolorprofile#1#2#3#4{}%
  \fi\fi
 %%
- \ifluatex\else
+ \ifluatex\else\ifxetex\else
   \inputencoding{8bit}%
- \fi
+ \fi\fi
  \makeatletter
  \pdfx@localcommands
 %%
  \InputIfFileExists{\jobname.xmpdata}%
-  {\typeout{** pdfx: Metadata file  \jobname.xmpdata  read successfully.}}%
-  {\typeout{** pdfx: No file  \jobname.xmpdata . Metadata will be incomplete!}}
+  {\typeout{** pdfx: Metadata file \jobname.xmpdata  read successfully.}}%
+  {\typeout{** pdfx: No file  \jobname.xmpdata .
+    Metadata will be incomplete!}}
 \endgroup
 
 %% ----------------------------------------------------------------------
-\newif\ifpdfx@cmyk
 \begingroup
-\ifpdfx@x   %  PDF/X  needs a CMYK color profile for printing
- \global\pdfx@cmyktrue
+\ifpdfx@x   %  PDF/X  needs a CMYK or RGB color profile for printing
  \edef\@pctchar{\expandafter\@gobble\string\%}
  \edef\@bchar{\expandafter\@gobble\string\\}
  \edef\0{\string\0}
  \edef\({\string\(}
  \edef\){\string\)}
- \catcode`\_ 12 
- \ifno@iccprofile %  PDF/X-4p  and  PDF/X-5pg
-   \immediate\pdfobj {<</FS/URL/F(\pdfx@colorURL)>>} 
-   \edef\OBJ@URLs{\the\pdflastobj}%
-%%   \xdef\pdfx@cmyk@intent{Offset commercial and specialty printing according to ISO 12647-2:2004 / Amd 1, %
-%%    paper type 1 or 2 \(gloss or matte coated offset, 115 g/m2\), screen frequency 60/cm.0}%
-%%   \xdef\pdfx@cmyk@info{Coated FOGRA39 \(ISO 12647-2:2004\)}%
-%%   \xdef\pdfx@cmyk@name{Coated FOGRA39 \(ISO 12647-2:2004\)}%
-%%   \xdef\pdfx@cmyk@identifier{FOGRA39}%
+ \catcode`\_ 12
+ \ifno@iccprofile %  PDF/X-4p and PDF/X-5pg
+  \ifxetex
+   \special{pdf:obj @colorURL <</FS/URL/F(\pdfx@colorURL)>>}%
+   \special{pdf:obj @colorprofile <<%
+     /CheckSum <\pdfx@profile@checksum>^^J%
+     /ICCVersion <\pdfx@iccversion>%
+     /ProfileCS (\pdfx@profileCS)^^J%
+     /ProfileName (\pdfx@extprofile)^^J%
+     /URLs [ @colorURL ]
+    >>}
+   \def\OBJ@ICC{@colorprofile}%
+  \else
+   \immediate\pdfobj {<</FS/URL/F(\pdfx@colorURL)>>}%
+   \edef\OBJ@URLs{\the\pdflastobj\space 0 R}%
    \immediate\pdfobj {<<%
      /CheckSum <\pdfx@profile@checksum>^^J%
      /ICCVersion <\pdfx@iccversion>%
      /ProfileCS (\pdfx@profileCS)^^J%
-     /ProfileName (\pdfx@extprofile)^^J%  
-     /URLs [\OBJ@URLs\space 0 R ]
+     /ProfileName (\pdfx@extprofile)^^J%
+     /URLs [\OBJ@URLs ]
     >>} %
-  \edef\OBJ@ICC{\the\pdflastobj}%
-%%  \IfFileExists{\pdfx@rgb@profile}{%
-%%   \immediate\pdfobj stream attr{/N 3^^J /Alternate /DeviceRGB} file{\pdfx@rgb@profile}%
-%%   \edef\OBJ@RGB{\the\pdflastobj}%
-%%  }{%
-%%   \errmessage{No color profile found to use for RGB screen colors.}%
-%%  }%
+   \edef\OBJ@ICC{\the\pdflastobj\space 0 R}%
+  \fi
   \pdfcatalog{%
    /OutputIntents [ <<
    /Type/OutputIntent
@@ -1552,16 +3321,22 @@
    /OutputConditionIdentifier (\pdfx@cmyk@identifier)%
    /Info(\pdfx@cmyk@intent)%
    /RegistryName(\pdfx@cmyk@registry)
-%% extra dictionary required for PDF/X-4p and  PDF/X-5pg
-   /DestOutputProfileRef \OBJ@ICC\space 0 R 
-  >> ]}%
+%% extra dictionary required for  PDF/X-4p and PDF/X-5pg
+   /DestOutputProfileRef \OBJ@ICC
+   >> ]}%
 %%
  \else  %  PDF/X-1 , PDF/X-1a , PDF/X-3 , PDF/X-4 , PDF/X-5g
 %%
-  \IfFileExists{"\pdfx@cmyk@profile"}{%
+  \ifpdfx@cmyk
+   \IfFileExists{"\pdfx@cmyk@profile"}{%
   %  embedded CMYK color profile
-  \immediate\pdfobj stream attr{/N 4} file{"\pdfx@cmyk@profile"}%
-  \edef\OBJ@CMYK{\the\pdflastobj}%
+  \ifxetex
+   \immediate\special{pdf:fstream @colorprofile (\pdfx@cmyk@profile) <</N 4>>}
+   \def\OBJ@CMYK{@colorprofile}%
+  \else
+   \immediate\pdfobj stream attr{/N 4} file{\pdfx@cmyk@profile}%
+   \edef\OBJ@CMYK{\the\pdflastobj\space 0 R}%
+  \fi
   \pdfcatalog{%
    /OutputIntents [ <<
    /Type/OutputIntent
@@ -1570,59 +3345,154 @@
    /OutputConditionIdentifier (\pdfx@cmyk@identifier)%
    /Info(\pdfx@cmyk@intent)%
    /RegistryName(\pdfx@cmyk@registry)
-   /DestOutputProfile \OBJ@CMYK\space 0 R 
-  >> ]}%
- }{%
-  \errmessage{No color profile \pdfx@cmyk@profile\ found to use for CMYK printing colors.}%
- }%
+   /DestOutputProfile \OBJ@CMYK
+   >> ]}%
+  }{%
+   \errmessage{No color profile \pdfx@cmyk@profile\ found
+     to use for CMYK printing colors.}%
+  }%
+  \else  % allow RGB profile with PDF/X   ???
+   \ifpdfx@noerr
+    \PackageWarning{pdfx}{PDF/X normally requires a CMYK color profile.^^J
+      Assuming RGB profile is of type 'prtr' not 'mntr'.^^J^^J}%
+   \else
+    \PackageError{pdfx}{PDF/X normally requires a CMYK color profile.}%
+      {To use RGB ensure profile is of type 'prtr' not 'mntr'.^^J^^J}%
+   \fi
+   \IfFileExists{"\pdfx@rgb@profile"}{%
+    \ifxetex
+     \immediate\special{pdf:fstream @colorprofile (\pdfx@rgb@profile) <<
+       /N 3 /Alternate/DeviceRGB >>}
+     \def\OBJ@RGB{@colorprofile}%
+    \else
+     \immediate\pdfobj stream attr{/N 3^^J/Alternate/DeviceRGB}
+       file{\pdfx@rgb@profile}%
+     \edef\OBJ@RGB{\the\pdflastobj\space 0 R}%
+    \fi
+    \edef\pdfx@outintent@dict{%
+      /Type /OutputIntent
+      /S/GTS_PDFX
+      /OutputConditionIdentifier (\pdfx@rgb@identifier)%
+      /DestOutputProfile \OBJ@RGB
+      /Info(\pdfx@rgb@info)
+      /RegistryName(\pdfx@rgb@registry)
+    }%
+    \ifxetex
+     \special{pdf:obj @outintent@dict << \pdfx@outintent@dict >>}
+     \edef\pdfx@outintent@dict{ @outintent@dict }%
+    \else
+%%     pdfTeX or LuaTeX
+    \fi
+    \ifxetex
+     \immediate\special{pdf:obj @outintentsarray [ ]}%
+     \immediate\special{pdf:put @outintentsarray \pdfx@outintent@dict}%
+     \def\pdfx@outintents{@outintentsarray}%
+    \else
+     \immediate\pdfobj{<<\pdfx@outintent@dict>>}
+     \edef\pdfx@outintents{[\the\pdflastobj\space 0 R]}%
+    \fi
+    \pdfcatalog{%
+     /ViewerPreferences <</DisplayDocTitle true >>
+     /OutputIntents \pdfx@outintents
+    }%
+   }{%
+    \errmessage{No color profile found to use for RGB screen colors.}%
+   }%
+  \fi % end of \ifpdfx@cmyk
  \fi % end of  \ifno@iccprofile
 \else
-%%  PDF/A  and  PDF/E  can specify a CMYK profile 
+%%  PDF/A and PDF/E  can specify a CMYK profile
  \expandafter\ifx\expandafter\relax\pdfx@rgb@profile\relax
   \global\pdfx@cmyktrue
   \IfFileExists{"\pdfx@cmyk@profile"}{%
   %  embedded CMYK color profile
-  \immediate\pdfobj stream attr{/N 4} file{"\pdfx@cmyk@profile"}%
-  \edef\OBJ@CMYK{\the\pdflastobj}%
-  \pdfcatalog{%
-   /ViewerPreferences <</DisplayDocTitle true >>
-   /OutputIntents [ <<
-   /Type /OutputIntent
+%% How to support XeTeX here ?
+  \ifxetex
+   \special{pdf:fstream @colorprofile (\pdfx@cmyk@profile) <</N 4>>}
+   \def\OBJ@CMYK{@colorprofile}%
+  \else
+   \immediate\pdfobj stream attr{/N 4} file{\pdfx@cmyk@profile}%
+   \edef\OBJ@CMYK{\the\pdflastobj\space 0 R}%
+  \fi
+  \edef\pdfx@outintent@dict{%
+    /Type /OutputIntent
    \ifpdfx@e
     /S/ISO_PDFE1
    \else
     /S/GTS_PDFA1
    \fi
-   /OutputCondition (\pdfx@cmyk@intent)%  use this or  /Info ?
-   /OutputConditionIdentifier (\pdfx@cmyk@identifier)%
-   /DestOutputProfile \OBJ@CMYK\space 0 R 
-   /Info(\pdfx@cmyk@intent)%
-   /RegistryName(\pdfx@cmyk@registry)
-  >> ]}%
+    /OutputCondition (\pdfx@cmyk@intent)%  use this or  /Info ?
+    /OutputConditionIdentifier (\pdfx@cmyk@identifier)%
+    /DestOutputProfile \OBJ@CMYK
+    /Info(\pdfx@cmyk@intent)%
+    /RegistryName(\pdfx@cmyk@registry)
+  }
+  \ifxetex
+   \special{pdf:obj @outintent@dict << \pdfx@outintent@dict >>}
+   \edef\pdfx@outintent@dict{ @outintent@dict }%
+  \else
+%%  pdfTeX
+  \fi
+  \ifxetex
+   \immediate\special{pdf:obj @outintentsarray [ ]}%
+   \immediate\special{pdf:put @outintentsarray \pdfx@outintent@dict}%
+   \def\pdfx@outintents{@outintentsarray}%
+  \else
+   \immediate\pdfobj{<<\pdfx@outintent@dict>>}
+   \edef\pdfx@outintents{[\the\pdflastobj\space 0 R]}%
+  \fi
+  \pdfcatalog{%
+   /ViewerPreferences <</DisplayDocTitle true >>
+   /OutputIntents \pdfx@outintents
+  }
  }{%
-  \errmessage{No color profile \pdfx@cmyk@profile\ found to use for CMYK screen colors.}%
- }% 
- \else 
-%%  PDF/A and  PDF/E usually need an RGB color profile for on-screen rendering
+  \errmessage{No color profile \pdfx@cmyk@profile\ found
+    to use for CMYK screen colors.}%
+ }%
+ \else
+%%  PDF/A and PDF/E  usually need an RGB color profile for on-screen rendering
  \global\pdfx@cmykfalse
  \IfFileExists{"\pdfx@rgb@profile"}{%
-  \immediate\pdfobj stream attr{/N 3^^J/Alternate/DeviceRGB} file{"\pdfx@rgb@profile"}%
-  \edef\OBJ@RGB{\the\pdflastobj}%
-  \pdfcatalog{%
-   /ViewerPreferences <</DisplayDocTitle true >>
-   /OutputIntents [ <<
-   /Type /OutputIntent
+%% How to support XeTeX here ?
+  \ifxetex
+   \immediate\special{pdf:fstream @colorprofile (\pdfx@rgb@profile) <<
+     /N 3 /Alternate/DeviceRGB >>}
+   \def\OBJ@RGB{@colorprofile}%
+  \else
+   \immediate\pdfobj stream attr{/N 3^^J/Alternate/DeviceRGB}
+     file{\pdfx@rgb@profile}%
+   \edef\OBJ@RGB{\the\pdflastobj\space 0 R}%
+  \fi
+  \edef\pdfx@outintent@dict{%
+    /Type /OutputIntent
    \ifpdfx@e
     /S/ISO_PDFE1
    \else
     /S/GTS_PDFA1
    \fi
-   /OutputConditionIdentifier (\pdfx@rgb@identifier)%
-   /DestOutputProfile \OBJ@RGB\space 0 R
-   /Info(\pdfx@rgb@info)
-   /RegistryName(\pdfx@rgb@registry)
-  >> 
- ]}%
+    /OutputConditionIdentifier (\pdfx@rgb@identifier)%
+    /DestOutputProfile \OBJ@RGB
+    /Info(\pdfx@rgb@info)
+    /RegistryName(\pdfx@rgb@registry)
+  }%
+  \ifxetex
+   \special{pdf:obj @outintent@dict << \pdfx@outintent@dict >>}
+   \edef\pdfx@outintent@dict{ @outintent@dict }%
+  \else
+%%  pdfTeX
+  \fi
+  \ifxetex
+   \immediate\special{pdf:obj @outintentsarray [ ]}%
+   \immediate\special{pdf:put @outintentsarray \pdfx@outintent@dict}%
+   \def\pdfx@outintents{@outintentsarray}%
+  \else
+   \immediate\pdfobj{<<\pdfx@outintent@dict>>}
+   \edef\pdfx@outintents{[\the\pdflastobj\space 0 R]}%
+  \fi
+  \pdfcatalog{%
+   /ViewerPreferences <</DisplayDocTitle true >>
+   /OutputIntents \pdfx@outintents
+  }%
  }{%
   \errmessage{No color profile found to use for RGB screen colors.}%
  }%
@@ -1640,18 +3510,25 @@
 %% Therefore, it's safer to always separate authors by commas.
 
 \begingroup
+ \let\pdfx@xmpunimarkup\relax
  \pdfx@xmpmarkup
- \def\sep{, }%
- \ifluatex\else
+ \ifluatex\else\ifxetex\else
   \inputencoding{8bit}%
- \fi
+ \fi\fi
  \makeatletter
  \IfFileExists{\pdfx@encodingfile}{%
-  \def\cf@encoding{U}\fontencoding{U}%
+%%  \def\cf@encoding{U}\fontencoding{U}%
+  \def\cf@encoding{L8U}\fontencoding{L8U}%
  }{}%
- \xdef\xmp@@Keywords{\xmp@Keywords}
- \xdef\xmp@@Author{\xmp@Author}
- \xdef\xmp@@Copyright{\xmp@Copyright}
+%% \xdef\xmp@@Author{\xmp@Author}% no need to expand
+ \global\let\xmp@@Author\xmp@Author
+ \def\sep{; }%  expand to replace \sep   !!!  no longer needed
+%% \xdef\xmp@@Copyright{\xmp@Copyright}%
+ \global\let\xmp@@Copyright\xmp@Copyright
+%% \xdef\xmp@@Keywords{\xmp@Keywords}%
+%% \global\let\xmp@@Keywords\xmp@Keywords
+%% \global\let\xmp@Keywords\@empty %
+ \global\let\xmp@@Keywords\@empty % don't use  pdf:Keywords
 \endgroup
 
 %% ----------------------------------------------------------------------
@@ -1683,9 +3560,18 @@
 \gdef\pdfx@getTzminus -#1'#2'#3\pdfx@getTzend{%
  \edef\pdfx@xTzh{-#1}\edef\pdfx@xTzm{#2}%
  \ifx\relax#2\relax\def\pdfx@xTzm{00}\fi}
-\expandafter\xmp@convertDate\pdfcreationdate''\pdfx@getTzend
-\xdef\pdfx@convDate{\pdfx@xYear\pdfx@xMonth\pdfx@xDay\pdfx@xHour\pdfx@xMin\pdfx@xSec\pdfx@xTzh'\pdfx@xTzm'}%
-\xdef\xmp@convDate{\pdfx@xYear-\pdfx@xMonth-\pdfx@xDay T\pdfx@xHour:\pdfx@xMin:\pdfx@xSec\pdfx@xTzh:\pdfx@xTzm}%
+%%
+%% How to support XeTeX here ?
+\expandafter\ifx\csname pdfcreationdate\endcsname\relax
+%% \xdef\pdfx@convDate{2016-04-01}%  April fool!
+%% \xdef\xmp@convDate{2016-04-01}%  April fool!
+\else
+ \expandafter\expandafter\expandafter\xmp@convertDate\pdfcreationdate''\pdfx@getTzend
+ \xdef\pdfx@convDate{\pdfx@xYear\pdfx@xMonth\pdfx@xDay\pdfx@xHour
+  \pdfx@xMin\pdfx@xSec\pdfx@xTzh'\pdfx@xTzm'}%
+ \xdef\xmp@convDate{\pdfx@xYear-\pdfx@xMonth-\pdfx@xDay
+  T\pdfx@xHour:\pdfx@xMin:\pdfx@xSec\pdfx@xTzh:\pdfx@xTzm}%
+\fi
 }% end of \catcode
 
 %% ----------------------------------------------------------------------
@@ -1708,72 +3594,271 @@
  \fi
 }
 
+%% ----------------------------------------------------------------------
+%% if high-bit characters are already encoded as active
+%% then  \pdfstringdef  probably changes their meaning
+%% so save these for later reversion.
+%%
+\newif\ifpdf@activechars
+\ifcat ^^c0\active \pdf@activecharstrue\fi
+%%
+%% normally not used with XeTeX
+%%
+
+\ifpdf@activechars
+ \global\let\pdfx@save@co ^^c0\relax
+ \global\let\pdfx@save@ci ^^c1\relax
+ \global\let\pdfx@save@cii ^^c2\relax
+ \global\let\pdfx@save@ciii ^^c3\relax
+ \global\let\pdfx@save@civ ^^c4\relax
+ \global\let\pdfx@save@cv ^^c5\relax
+ \global\let\pdfx@save@cvi ^^c6\relax
+ \global\let\pdfx@save@cvii ^^c7\relax
+ \global\let\pdfx@save@cviii ^^c8\relax
+ \global\let\pdfx@save@cix ^^c9\relax
+ \global\let\pdfx@save@ca ^^ca\relax
+ \global\let\pdfx@save@cb ^^cb\relax
+ \global\let\pdfx@save@cc ^^cc\relax
+ \global\let\pdfx@save@cd ^^cd\relax
+ \global\let\pdfx@save@ce ^^ce\relax
+ \global\let\pdfx@save@cf ^^cf\relax
+ \global\let\pdfx@save@do ^^d0\relax
+ \global\let\pdfx@save@di ^^d1\relax
+ \global\let\pdfx@save@dii ^^d2\relax
+ \global\let\pdfx@save@diii ^^d3\relax
+ \global\let\pdfx@save@div ^^d4\relax
+ \global\let\pdfx@save@dv ^^d5\relax
+ \global\let\pdfx@save@dvi ^^d6\relax
+ \global\let\pdfx@save@dvii ^^d7\relax
+ \global\let\pdfx@save@dviii ^^d8\relax
+ \global\let\pdfx@save@dix ^^d9\relax
+ \global\let\pdfx@save@da ^^da\relax
+ \global\let\pdfx@save@db ^^db\relax
+ \global\let\pdfx@save@dc ^^dc\relax
+ \global\let\pdfx@save@dd ^^dd\relax
+ \global\let\pdfx@save@de ^^de\relax
+ \global\let\pdfx@save@df ^^df\relax
+ \global\let\pdfx@save@eo ^^e0\relax
+ \global\let\pdfx@save@ei ^^e1\relax
+ \global\let\pdfx@save@eii ^^e2\relax
+ \global\let\pdfx@save@eiii ^^e3\relax
+ \global\let\pdfx@save@eiv ^^e4\relax
+ \global\let\pdfx@save@ev ^^e5\relax
+ \global\let\pdfx@save@evi ^^e6\relax
+ \global\let\pdfx@save@evii ^^e7\relax
+ \global\let\pdfx@save@eviii ^^e8\relax
+ \global\let\pdfx@save@eix ^^e9\relax
+ \global\let\pdfx@save@ea ^^ea\relax
+ \global\let\pdfx@save@eb ^^eb\relax
+ \global\let\pdfx@save@ec ^^ec\relax
+ \global\let\pdfx@save@ed ^^ed\relax
+ \global\let\pdfx@save@ee ^^ee\relax
+ \global\let\pdfx@save@ef ^^ef\relax
+ \global\let\pdfx@save@fo ^^f0\relax
+ \global\let\pdfx@save@fi ^^f1\relax
+ \global\let\pdfx@save@fii ^^f2\relax
+ \global\let\pdfx@save@fiii ^^f3\relax
+\fi
+
+%% ----------------------------------------------------------------------
+%% detect when \sep is used for multiple authors
+%% then suppress the /Author field in PDF /Info
+\newif\ifpdfx@sepinAuthor
+\let\pdfx@endparse\relax
+\def\pdfx@parseforsep#1\sep#2\pdfx@endparse{%
+ \ifx\relax#2\relax\else\pdfx@sepinAuthortrue\fi
+}
+
 %% Convert the relevant XMP properties to PDF strings, expanding markup
 %% (such as \sep, \&, \copyright, etc) in an appropriate way.
+%% These PDF strings are actually not necessary, but if supplied they
+%% must match exactly what is in the XMP version. This may be impossible
+%% if math symbols are used; e.g. Plane-1 alphanumerics.
+%% Generally, it is better to *not* provide PDF-info strings;
+%% instead just providing metadata through XMP.
+%% This is not always enough — a driver may add it by default!
+%%
 \begingroup
  \pdfx@pdfmarkup
- \pdfx@topdfstring\pdfx@Title\xmp@Title
- \pdfx@topdfstring\pdfx@Author\xmp@Author
- \pdfx@topdfstring\pdfx@Subject\xmp@Subject
- \pdfx@topdfstring\pdfx@Keywords\xmp@Keywords
+ \global\let\pdfx@Title\@empty
+ \global\let\pdfx@Subject\@empty
+ \global\let\pdfx@Keywords\@empty
+ \ifpdfx@nopdfinfo\else
+  \pdfx@topdfstring\pdfx@Title\xmp@Title
+  \ifpdfx@e\else\ifpdfx@x\else
+   \pdfx@topdfstring\pdfx@Subject\xmp@Subject
+  \fi\fi
+%%  \pdfx@topdfstring\pdfx@Keywords\xmp@Keywords
+ \fi
  \pdfx@topdfstring\pdfx@CreatorTool\xmp@CreatorTool
  \pdfx@topdfstring\pdfx@Producer\xmp@Producer
+ \expandafter\pdfx@parseforsep\xmp@Author\sep\pdfx@endparse
+ \ifpdfx@sepinAuthor
+  \aftergroup\let\aftergroup\pdfx@Author\aftergroup\@empty
+ \else
+  \aftergroup\let\aftergroup\pdfx@Author\aftergroup\@empty
+%%  \pdfx@topdfstring\pdfx@Author\xmp@Author
+ \fi
 \endgroup
 
-\input glyphtounicode.tex
-\input glyphtounicode-cmr.tex
-\pdfgentounicode=1
+%% How to support XeTeX here ?
+\ifxetex\else
+ \input glyphtounicode.tex
+ \input glyphtounicode-cmr.tex
+ \pdfgentounicode=1
+ \ifgrkLGRxmp
+  \pdfglyphtounicode{internalchar2}{200D}%
+ \fi
+\fi
+
+\def\pdfx@linkfile@pdfX#1#2#3{%
+ \Hy@colorlink\@filecolor#1\Hy@xspace@end}
+\def\pdfx@linkstart@pdfX#1#2#3{%
+ \Hy@colorlink\@linkcolor#3\endgroup\Hy@xspace@end}
+\def\pdfx@linkurl@pdfX#1#2{%
+ \Hy@colorlink\@urlcolor#1\endgroup\Hy@xspace@end}
+\def\pdfx@StartlinkName@pdfX#1#2{}
+\def\pdfx@close@pdflink{\Hy@VerboseLinkStop\Hy@endcolorlink}%
 
 \ifpdfx@x
- {\def\sep{,}%
-  \pdfinfo{%   order of these dictionary keys should not matter
-   \ifx\pdfx@Author\@empty\else /Author(\pdfx@Author)\fi
-   /CreationDate(D:\pdfx@convDate)%
-   /Creator(\pdfx@CreatorTool)%
-   \ifnum\xmp@Part=1 
-     /GTS_PDFXVersion(PDF/X-1\ifnum\xmp@ReleaseDate>2001\xmp@Conformance\fi:\xmp@ReleaseDate)%
-   \else
-    /GTS_PDFXVersion(PDF/X-\xmp@Part\xmp@Conformance\ifnum\xmp@Part< 4 :\xmp@ReleaseDate\fi)%
-   \fi
-   \ifnum\xmp@Part < 3 
-      /GTS_PDFXConformance(PDF/X-\xmp@Part\xmp@Conformance:\xmp@ReleaseDate)%
-   \fi
-   \ifpdfx@vt %  support for PDF/VT extensions of  PDF/X-4  and PDF/X-5 
+ \let\hyper@linkfile\pdfx@linkfile@pdfX
+ \let\hyper@linkurl\pdfx@linkurl@pdfX
+ \let\hyper@linkstart\pdfx@linkstart@pdfX
+ \let\hyper@linkend\relax
+ \let\Hy@StartlinkName\pdfx@StartlinkName@pdfX
+ \let\close@pdflink\pdfx@close@pdflink
+ \Hy@bookmarksfalse
+%% {\def\sep{;}% should not be needed, but just in case
+  \AtBeginDocument{%
+   % cancel annotations and links
+   %
+   \def\PDF@FinishDoc{%  ??? What uses this ???
+    \Hy@UseMaketitleInfos
+    {\def\sep{; }% should not be needed, but just in case
+     \pdfinfo{%
+      \ifx\pdfx@Title\@empty\else /Title(\pdfx@Title)\fi
+      \ifx\pdfx@Author\@empty\else /Author(\pdfx@Author)\fi
+      \ifx\pdfx@Subject\@empty\else /Subject(\pdfx@Subject)\fi
+      \ifx\pdfx@Keywords\@empty\else /Keywords(\pdfx@Keywords)\fi
+       /Creator(\pdfx@CreatorTool)%
+      \ifx\@pdfcreationdate\@empty
+       /CreationDate(D:\pdfx@convDate)%
+      \else
+       \ifxetex\else
+        /CreationDate(\@pdfcreationdate)%
+      \fi\fi
+      \ifx\@pdfmoddate\@empty
+       /ModDate(D:\pdfx@convDate)%
+      \else
+       /ModDate(\@pdfmoddate)%
+      \fi
+      /Producer(\pdfx@Producer)%
+      /Trapped/False
+      \ifnum\xmp@Part=1
+       /GTS_PDFXVersion(PDF/X-1\ifnum\xmp@ReleaseDate>2001
+        \xmp@Conformance\fi:\xmp@ReleaseDate)%
+      \else
+       /GTS_PDFXVersion(PDF/X-\xmp@Part\xmp@Conformance
+        \ifnum\xmp@Part< 4 :\xmp@ReleaseDate\fi)%
+      \fi
+      \ifnum\xmp@Part < 3
+        /GTS_PDFXConformance(PDF/X-\xmp@Part\xmp@Conformance
+          :\xmp@ReleaseDate)%
+      \fi
+      \ifpdfx@vt
+%%   support for PDF/VT extensions of  PDF/X-4 and PDF/X-5
+       /GTS_PDFVTVersion(PDF/VT-\xmp@vtPart\xmp@vtConformance)%
+      \fi
+     }%  end of  PDF/X  info
+    }% end of scope for  \sep
+   }% end of  \PDF@FinishDoc
+  }% end of  \AtBeginDocument
+%%  \pdfinfo{%   order of these dictionary keys should not matter
+%%   \ifx\pdfx@Author\@empty\else /Author(\pdfx@Author)\fi
+%%   /CreationDate(D:\pdfx@convDate)%
+%%   /Creator(\pdfx@CreatorTool)%
+%%   \ifnum\xmp@Part=1
+%%     /GTS_PDFXVersion(PDF/X-1\ifnum\xmp@ReleaseDate>2001
+%%      \xmp@Conformance\fi:\xmp@ReleaseDate)%
+%%   \else
+%%    /GTS_PDFXVersion(PDF/X-\xmp@Part\xmp@Conformance
+%%     \ifnum\xmp@Part< 4 :\xmp@ReleaseDate\fi)%
+%%   \fi
+%%   \ifnum\xmp@Part < 3
+%%      /GTS_PDFXConformance(PDF/X-\xmp@Part\xmp@Conformance
+%%        :\xmp@ReleaseDate)%
+%%   \fi
+%%
+%%   \ifpdfx@vt
+%%%   support for PDF/VT extensions of  PDF/X-4 and PDF/X-5
 %%     /GTS_PDFVTVersion(PDF/VT-\xmp@vtPart\xmp@vtConformance)%
-   \fi
-   \ifx\pdfx@Keywords\@empty\else /Keywords(\pdfx@Keywords)\fi
-   /ModDate(D:\pdfx@convDate)%
-   /Producer(\pdfx@Producer)%
-   \ifx\pdfx@Subject\@empty\else /Subject(\pdfx@Subject)\fi
-   \ifx\pdfx@Title\@empty\else /Title(\pdfx@Title)\fi
-   /Trapped/False%
-  }%  end of  PDF/X  info
- }% end of scope for  \sep
+%%   \fi
+%%   \ifx\pdfx@Keywords\@empty\else /Keywords(\pdfx@Keywords)\fi
+%%   /ModDate(D:\pdfx@convDate)%
+%%   /Producer(\pdfx@Producer)%
+%%   \ifx\pdfx@Subject\@empty\else /Subject(\pdfx@Subject)\fi
+%%   \ifx\pdfx@Title\@empty\else /Title(\pdfx@Title)\fi
+%%   /Trapped/False%
+%%  }%  end of  PDF/X  info
+%% }% end of scope for  \sep
 \else
  \ifpdfx@e
- {\def\sep{,}%
-  \pdfinfo{%   order of these dictionary keys should not matter
-   \ifx\pdfx@Author\@empty\else /Author(\pdfx@Author)\fi
-   /CreationDate(D:\pdfx@convDate)%
-   /Creator(\pdfx@CreatorTool)%
-   /GTS_PDFEVersion(PDF/E-1\xmp@Conformance:\xmp@ReleaseDate)%
-   \ifx\pdfx@Keywords\@empty\else /Keywords(\pdfx@Keywords)\fi
-   /ModDate(D:\pdfx@convDate)%
-   /Producer(\pdfx@Producer)%
-   \ifx\pdfx@Subject\@empty\else /Subject(\pdfx@Subject)\fi
-   \ifx\pdfx@Title\@empty\else /Title(\pdfx@Title)\fi
-   /Trapped/False%   
-  }%  end of  PDF/E  info
- }% end of scope for  \sep
+  \AtBeginDocument{%
+   \def\PDF@FinishDoc{%  ??? What uses this ???
+    \Hy@UseMaketitleInfos
+    {\def\sep{; }% should not be needed, but just in case
+     \pdfinfo{%
+      \ifx\pdfx@Title\@empty\else /Title(\pdfx@Title)\fi
+      \ifx\pdfx@Author\@empty\else /Author(\pdfx@Author)\fi
+      \ifx\pdfx@Subject\@empty\else /Subject(\pdfx@Subject)\fi
+      \ifx\pdfx@Keywords\@empty\else /Keywords(\pdfx@Keywords)\fi
+       /Creator(\pdfx@CreatorTool)%
+      \ifx\@pdfcreationdate\@empty
+       /CreationDate(D:\pdfx@convDate)%
+      \else
+       \ifxetex\else
+        /CreationDate(\@pdfcreationdate)%
+      \fi\fi
+      \ifx\@pdfmoddate\@empty
+       /ModDate(D:\pdfx@convDate)%
+      \else
+       /ModDate(\@pdfmoddate)%
+      \fi
+      /Producer(\pdfx@Producer)%
+      /Trapped/False
+      /GTS_PDFEVersion(PDF/E-1\xmp@Conformance:\xmp@ReleaseDate)%
+     }%  end of  PDF/E  info
+    }% end of scope for  \sep
+   }% end of  \PDF@FinishDoc
+  }% end of  \AtBeginDocument
+%% {\def\sep{;}% should not be needed, but just in case
+%%  \pdfinfo{%   order of these dictionary keys should not matter
+%%     \ifx\pdfx@Title\@empty\else /Title(\pdfx@Title)\fi
+%%     \ifx\pdfx@Author\@empty\else /Author(\pdfx@Author)\fi
+%%     \ifx\pdfx@Subject\@empty\else /Subject(\pdfx@Subject)\fi
+%%     \ifx\pdfx@Keywords\@empty\else /Keywords(\pdfx@Keywords)\fi
+%%   \ifx\pdfx@Author\@empty\else /Author(\pdfx@Author)\fi
+%%   /CreationDate(\pdfx@convDate)%
+%%   /Creator(\pdfx@CreatorTool)%
+%%   /GTS_PDFEVersion(PDF/E-1\xmp@Conformance:\xmp@ReleaseDate)%
+%%   \ifx\pdfx@Keywords\@empty\else /Keywords(\pdfx@Keywords)\fi
+%%   /ModDate(D:\pdfx@convDate)%
+%%   /Producer(\pdfx@Producer)%
+%%   \ifx\pdfx@Subject\@empty\else /Subject(\pdfx@Subject)\fi
+%%   \ifx\pdfx@Title\@empty\else /Title(\pdfx@Title)\fi
+%%   /Trapped/False%
+%%  }%  end of  PDF/E  info
+%% }% end of scope for  \sep
  \else
- \def\pdfx@confA{a}%
- \def\pdfx@confB{b}%
- \def\pdfx@confU{u}%
- \expandafter\def\expandafter\xmp@conf\expandafter{\csname pdfx@conf\xmp@Conformance\endcsname}%
- \AtBeginDocument{%
-  \def\PDF@FinishDoc{%
-   \Hy@UseMaketitleInfos
-   {\def\sep{, }%
+  \def\pdfx@confA{a}%
+  \def\pdfx@confB{b}%
+  \def\pdfx@confU{u}%
+  \expandafter\def\expandafter\xmp@conf\expandafter
+   {\csname pdfx@conf\xmp@Conformance\endcsname}%
+  \AtBeginDocument{%
+   \def\PDF@FinishDoc{%  ??? What uses this ???
+    \Hy@UseMaketitleInfos
+    {\def\sep{; }% should not be needed, but just in case
     \pdfinfo{%
      \ifx\pdfx@Title\@empty\else /Title(\pdfx@Title)\fi
      \ifx\pdfx@Author\@empty\else /Author(\pdfx@Author)\fi
@@ -1783,8 +3868,9 @@
      \ifx\@pdfcreationdate\@empty
       /CreationDate(D:\pdfx@convDate)%
      \else
-      /CreationDate(\@pdfcreationdate)%
-     \fi
+      \ifxetex\else
+       /CreationDate(\@pdfcreationdate)%
+     \fi\fi
      \ifx\@pdfmoddate\@empty
       /ModDate(D:\pdfx@convDate)%
      \else
@@ -1800,7 +3886,50 @@
 \fi\fi
 
 %%----------------------------------------------------------------------
+\ifxetex
+ % override the \ifpdf check
+ \pdftrue
+\else\ifluatex
+ \pdftrue
+\fi\fi
 \RequirePackage{xmpincl}
+\ifxetex
+ % revert \ifpdf
+ \pdffalse
+\else\ifluatex
+ \pdffalse
+\fi\fi
+
+%% combine coding from  xmpincl  and  hyperxml to support XeTeX
+\def\pdfx@xmpincl@xetex#1{%
+ \IfFileExists{#1.xmp}{%
+  \mcs@xmpincl@patchFile{#1}%
+  \begingroup
+   \special{pdf:fstream @pdfx@Metadata (#1.xmpi)
+    <<
+      /Type /Metadata
+      /Subtype /XML
+    >>
+   }%
+   \special{pdf:put @catalog
+    <<
+      /Metadata @pdfx@Metadata
+    >>
+   }%
+  \endgroup
+ }{%
+  \newcommand{\mcs@xmpincl@filename}{#1.xmp}%
+    \PackageError{xmpincl}%
+    {The file \mcs@xmpincl@filename\space was not found}%
+    {The file \mcs@xmpincl@filename\space The metadata file
+     wasn't found.\MessageBreak Oops.}%
+ }
+}
+\ifxetex
+ \let\includexmp\pdfx@xmpincl@xetex
+\fi
+
+%%----------------------------------------------------------------------
 \begingroup
  \ifpdfx@x
   \ifpdfx@vt
@@ -1814,7 +3943,7 @@
   \else
    \def\xmp@template{pdfa}%
  \fi\fi
-%% patch commands from  xmpincl.sty  …
+%% patch commands from  xmpincl.sty  ...
  \def\pdfx@xmpinclStart{% supply byte-order marker
   <?xpacket begin='^^ef^^bb^^be' id='W5M0MpCehiHzreSzNTczkc9d' ?> %
  }%
@@ -1830,7 +3959,7 @@
   \let\mcs@xmpinclStart\pdfx@xmpinclStartAlt
  \fi
  \let\mcs@xmpinclEnd\pdfx@xmpinclEnd
-%% … preventing their redefinition
+%% ... preventing their redefinition
  \def\newcommand#1#2{}%
 %%
 %% \def\pdfx@endeval{%
@@ -1838,57 +3967,207 @@
 %%  \noexpand \TE@setvalfalse \noexpand \fi
 %%   \noexpand \TE@negatefalse \noexpand \fi}%
 %% \let\TE@endeval\pdfx@endeval
- \ifluatex\else
+ \ifluatex\else\ifxetex\else
   \inputencoding{8bit}%
- \fi
+ \fi\fi
  \makeatletter
-%% \let\&=\xmpAmp
  \pdfx@xmpmarkup
- \def\cf@encoding{U}\fontencoding{U}%
+ \expandafter\global\expandafter
+  \let\csname L8U-cmd\expandafter\endcsname\csname U-cmd\endcsname
+ \def\cf@encoding{L8U}\fontencoding{L8U}%
  \providecommand{\ifnot@empty}[2]{\ifx#1\@empty\relax\else#2\fi}%
-%% \catcode `\_ 12
- \obeyspaces%  beware of 128 space characters in the next line -- for padding end of XMP packet
+ \obeyspaces%
+%% beware 128 space characters -- for padding end of XMP packet
  \gdef\paddingline{                                                                                                                                }%
  \typeout{Using XMP template file: \xmp@template.xmp}%
- \includexmp{\xmp@template}
+ \includexmp{\xmp@template}%
 \endgroup
 
+%%
+%% revert active characters to previous encoding
+%%
+\ifpdf@activechars
+ \global\let ^^c0\pdfx@save@co
+ \global\let ^^c1\pdfx@save@ci
+ \global\let ^^c2\pdfx@save@cii
+ \global\let ^^c3\pdfx@save@ciii
+ \global\let ^^c4\pdfx@save@civ
+ \global\let ^^c5\pdfx@save@cv
+ \global\let ^^c6\pdfx@save@cvi
+ \global\let ^^c7\pdfx@save@cvii
+ \global\let ^^c8\pdfx@save@cviii
+ \global\let ^^c9\pdfx@save@cix
+ \global\let ^^ca\pdfx@save@ca
+ \global\let ^^cb\pdfx@save@cb
+ \global\let ^^cc\pdfx@save@cc
+ \global\let ^^cd\pdfx@save@cd
+ \global\let ^^ce\pdfx@save@ce
+ \global\let ^^cf\pdfx@save@cf
+ \global\let ^^d0\pdfx@save@do
+ \global\let ^^d1\pdfx@save@di
+ \global\let ^^d2\pdfx@save@dii
+ \global\let ^^d3\pdfx@save@diii
+ \global\let ^^d4\pdfx@save@div
+ \global\let ^^d5\pdfx@save@dv
+ \global\let ^^d6\pdfx@save@dvi
+ \global\let ^^d7\pdfx@save@dvii
+ \global\let ^^d8\pdfx@save@dviii
+ \global\let ^^d9\pdfx@save@dix
+ \global\let ^^da\pdfx@save@da
+ \global\let ^^db\pdfx@save@db
+ \global\let ^^dc\pdfx@save@dc
+ \global\let ^^dd\pdfx@save@dd
+ \global\let ^^de\pdfx@save@de
+ \global\let ^^df\pdfx@save@df
+ \global\let ^^e0\pdfx@save@eo
+ \global\let ^^e1\pdfx@save@ei
+ \global\let ^^e2\pdfx@save@eii
+ \global\let ^^e3\pdfx@save@eiii
+ \global\let ^^e4\pdfx@save@eiv
+ \global\let ^^e5\pdfx@save@ev
+ \global\let ^^e6\pdfx@save@evi
+ \global\let ^^e7\pdfx@save@evii
+ \global\let ^^e8\pdfx@save@eviii
+ \global\let ^^e9\pdfx@save@eix
+ \global\let ^^ea\pdfx@save@ea
+ \global\let ^^eb\pdfx@save@eb
+ \global\let ^^ec\pdfx@save@ec
+ \global\let ^^ed\pdfx@save@ed
+ \global\let ^^ee\pdfx@save@ee
+ \global\let ^^ef\pdfx@save@ef
+ \global\let ^^f0\pdfx@save@fo
+ \global\let ^^f1\pdfx@save@fi
+ \global\let ^^f2\pdfx@save@fii
+ \global\let ^^f3\pdfx@save@fiii
+\fi
+
 %%
 %% controls the color model and conversions with  xcolor  package
 %%
 \ifpdfx@cmyk
+ %
+ % this will have been done already for PDF/X
+ %
  \PassOptionsToPackage{xcolor}{cmyk,hyperref}
- \def\pdfx@handlexcolor{\selectcolormodel{cmyk}\convertcolorsUtrue\convertcolorsDtrue}
-%%\hypersetup{allbordercolors=black,allcolors=black}%  else link borders use RGB
- \ifpdfx@x\else
-  \AtBeginDocument{%
-   \def\@linkcolor{0 1 1 0}%
-   \def\@anchorcolor{0 0 0 1}%
-   \def\@citecolor{1 0 1 0}%
-   \def\@filecolor{.5 0 0 .5}%
-   \def\@urlcolor{0 1 0 0}%
-   \def\@menucolor{0 1 1 0}%
-   \def\@runcolor{.5 0 0 .5}%
-   \def\@linkbordercolor{0 1 1 0}%
-   \def\@citebordercolor{1 0 1 0}%
-   \def\@filebordercolor{.5 0 0 .5}%
-   \def\@urlbordercolor{1 0 0 0}%
-   \def\@menubordercolor{0 1 1 0}%
-   \def\@runbordercolor{.7 0 0 .3}%
-   \def\Fld@bcolor{0 0 0 0}%
-   \def\Fld@bordercolor{0 1 1 0}%
-  }
+ \def\pdfx@handlexcolor{\def\@@mod{cmyk}\selectcolormodel{cmyk}%
+   \convertcolorsUtrue\convertcolorsDtrue}
+ \ifpdfx@x
+ \else
+%%  \AtBeginDocument{%
+%%   \def\@linkcolor{0 1 1 0}%
+%%   \def\@anchorcolor{0 0 0 1}%
+%%   \def\@citecolor{1 0 1 0}%
+%%   \def\@filecolor{.5 0 0 .5}%
+%%   \def\@urlcolor{0 1 0 0}%
+%%   \def\@menucolor{0 1 1 0}%
+%%   \def\@runcolor{.5 0 0 .5}%
+%%   \def\@linkbordercolor{0 1 1 0}%
+%%   \def\@citebordercolor{1 0 1 0}%
+%%   \def\@filebordercolor{.5 0 0 .5}%
+%%   \def\@urlbordercolor{1 0 0 0}%
+%%   \def\@menubordercolor{0 1 1 0}%
+%%   \def\@runbordercolor{.7 0 0 .3}%
+%%   \def\Fld@bcolor{0 0 0 0}%
+%%   \def\Fld@bordercolor{0 1 1 0}%
+%%  }
  \fi
 \else
  \PassOptionsToPackage{xcolor}{rgb,hyperref}
- \def\pdfx@handlexcolor{\selectcolormodel{rgb}\convertcolorsUtrue\convertcolorsDtrue}
+ \def\pdfx@handlexcolor{\def\@@mod{rgb}\selectcolormodel{rgb}%
+   \convertcolorsUtrue\convertcolorsDtrue}
 \fi
-\@ifpackageloaded{xcolor}{\pdfx@handlexcolor}{%
+\@ifpackageloaded{xcolor}{\pdfx@handlexcolor
+ \ifpdfx@cmyk\else\color{black}\fi}{%
  \AtBeginDocument{\@ifpackageloaded{xcolor}{\pdfx@handlexcolor}{}}
 }
 
+%%----------------------------------------------------------------------
+\ifpdfx@transliterated
+%% support for bookmarks with transliterated input
+ \RequirePackage{stringenc}
+ \ifxetex\let\pdf@escapehex\empty\fi  % don't need it
+ \expandafter\ifx\csname pdf@escapehex\endcsname\relax
+  \PackageWarning{pdfx}{%
+   Missing an implementation of \string\pdf@escapehex ^^J
+   Translated Bookmarks cannot be generated.^^J}%
+  \newcommand{\pdfxBookmark}[4][]{#2[#1]{#4}}%
+ \else
+  \def\pdfx@GeneratePdfString#1#2{%
+   % converts a UTF-8 string to UTF-16be
+   \StringEncodingConvert{#1}{#2}{utf8}{utf16be}%
+   \edef#1{\string\376\string\377\pdfescapestring{#1}}%
+  }
+  \newtoks\pdfx@DisabledCommands
+  \def\pdfxDisableCommands#1{%
+  \expandafter\pdfx@DisabledCommands
+   \expandafter{\the\pdfx@DisabledCommands#1}}
+  \pdfxDisableCommands{%
+   \def\80{}%    else   \000\( --> \000\80\050   \000\000\050
+   \aftergroup\let\aftergroup\HyPsd@ConvertToUnicode\aftergroup\@gobble}
+  \let\Hy@@writetorep\@@writetorep
+  \def\pdfx@@writetorep#1#2#3#4#5{%
+   \begingroup
+    \pdfx@prebookmark
+    \edef\pdfstringdefPreHook{%\pdfstringdefPreHook
+     \the\pdfx@DisabledCommands}%
+    \Hy@@writetorep{#1}{#2}{#3}{#4}{#5}%
+   \endgroup
+  }
+  \newcommand{\pdfxBookmark}[4][]{%
+   \ifx\relax#3\relax
+    \PackageError{pdfx}{Unknown macro \string#3.
+      A proper bookmark cannot be created}%
+     {Proceed to process the \string#1 as usual.}%
+    #2{#4}%
+   \else
+    \ifluatex  % use the utf8 directly
+     \let\pdfx@temp#3\relax
+     \def\pdfx@prebookmark{%
+      \pdfx@DisabledCommands{}%
+      \let#3\pdfx@temp
+     }%
+    \else\ifxetex  % use the utf8 directly
+     \let\pdfx@temp#3\relax
+     \def\pdfx@prebookmark{%
+      \pdfx@DisabledCommands{}%
+      \let#3\pdfx@temp
+     }%
+    \else
+     % convert the utf8 to utf16be
+     \pdfxBookmarkString\pdfx@temp{#3}%
+    \fi\fi
+    \let\@@writetorep\pdfx@@writetorep
+    \ifx\empty#1\empty
+     \def#3{#4}%
+     #2{#3}%
+    \else
+     \def#3{#1}%
+     #2[#3]{#4}%
+    \fi
+    \let\@@writetorep\Hy@@writetorep
+   \fi
+   \ignorespaces
+  }
+%%  use as:  \pdfxBookmark{\section}{\sectAtitle}{...}
+%%  use as:  \pdfxBookmark[<opt-title>]{\section}{\sectAtitle}{...}
+%%  only needed by pdfTeX --- Lua-/XeTeX use the utf8 directly
+  \def\pdfxBookmarkString#1#2{%
+   \pdfx@GeneratePdfString#1{#2}%
+   \def\pdfx@prebookmark{%
+    \pdfxDisableCommands{\let#2#1}%
+   }%
+  }
+%% use as:  \pdfxBookmarkString\PdfSectA\sectAtitle
+%%  where \sectAtitle has been defined by e.g.
+%%  \pdfxEnableCommands{\xdef\sectAtitle{\textLGR{...}}}
+
+ \fi % end of \ifx\pdf@escapehex\relax
+\fi % end of \ifpdfx@transliterated
+
+%%----------------------------------------------------------------------
 
-%% disable hyperref options, to prevent changes that will cause an incompatibility
+%% disable hyperref options,
+%%   to prevent changes that will cause an incompatibility
  \Hy@DisableOption{pdfauthor}%
  \Hy@DisableOption{pdftitle}%
  \Hy@DisableOption{pdfsubject}%
@@ -1906,5 +4185,6 @@
 % \fi
 % \Finale
 % \newpage\PrintIndex
+% \section[Change History]{Change History}
 % \PrintChanges
 % \endinput
-- 
cgit v1.2.3

