From 89b6a5f0bb4c2c1ae32c47aee92f309f4263000a Mon Sep 17 00:00:00 2001
From: Karl Berry <karl@freefriends.org>
Date: Thu, 6 Dec 2018 22:14:29 +0000
Subject: pdfx (6dec18)

git-svn-id: svn://tug.org/texlive/trunk@49333 c570f23f-e606-0410-a88d-b1316a301751
---
 Master/texmf-dist/tex/latex/pdfx/pdfx.sty | 1553 +++++++++++++++++++++++------
 1 file changed, 1260 insertions(+), 293 deletions(-)

(limited to 'Master/texmf-dist/tex/latex/pdfx/pdfx.sty')

diff --git a/Master/texmf-dist/tex/latex/pdfx/pdfx.sty b/Master/texmf-dist/tex/latex/pdfx/pdfx.sty
index 0d2fb58b38f..51e70d637c5 100644
--- a/Master/texmf-dist/tex/latex/pdfx/pdfx.sty
+++ b/Master/texmf-dist/tex/latex/pdfx/pdfx.sty
@@ -6,7 +6,7 @@
 %%
 %% pdfx.dtx  (with options: `package')
 %% 
-%%  Copyright (c) 2017, CV Radhakrishnan <cvr@river-valley.org>,
+%%  Copyright (c) 2018, CV Radhakrishnan <cvr@river-valley.org>,
 %%    Han The Thanh <thanh@river-valley.org>,
 %%    Ross Moore <ross.moore@mq.edu.au>,
 %%    Peter Selinger <selinger@mathstat.dal.ca>
@@ -31,11 +31,12 @@
 }{}%
 \NeedsTeXFormat{LaTeX2e}
 \ProvidesPackage{pdfx}
-  [2017/05/18 v1.5.84 PDF/X and PDF/A support (CVR/HTH/RRM/PS)]
+  [2018/11/29 v1.6 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@e \pdfx@efalse   % PDF/E mode; not fully implemented yet
+\newif\ifpdfx@ua\pdfx@uafalse   % PDF/UA mode; not fully 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
@@ -48,6 +49,25 @@
 \def\xmp@ReleaseDate{2005}     % 2001 for PDF/X-1, 2005 for PDF/A-1,
                                % 2010 for PDF/A-2, 2012 for PDF/A-3.
 
+\newcount\pdfx@minorversion
+\expandafter\ifx\csname pdfminorversion\endcsname\relax
+\else
+ \global\pdfx@minorversion=\the\pdfminorversion
+\fi
+
+\def\pdfx@ErrorWarning#1#2#3#4{%
+ \ifpdfx@noerr \PackageWarning{pdfx}{#1.^^J  #2#3.^^J}%
+ \else \PackageError{pdfx}{#1}{#2#4.^^J
+    Use option 'noerr' to avoid this message.^^J}%
+ \fi}
+
+\def\pdfx@Xvn@message{%
+ \pdfx@ErrorWarning{PDF/X-5n has no default profile}%
+   {Provide your own}{; continuing to build a non-valid document}%
+   {, else continue to build a non-valid document}%
+}
+
+%% PDF/A options
 %%  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}%
@@ -66,135 +86,160 @@
  \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}%
+%%
+%% PDF/X options
+%% comments added, using
+%% https://www.eci.org/_media/downloads/pdfx/pdfx_faq_english_nov05.pdf
+%% https://en.wikipedia.org/wiki/PDF/X#List_of_the_PDF.2FX_standards
+%%
+\DeclareOption{x-1}{\global\pdfx@xtrue\def\xmp@Part{1}%  obsolete
+ \def\xmp@Conformance{a}\def\xmp@ReleaseDate{1999}% CMYK only
+ \global\pdfx@minorversion=2\relax
+ \pdfx@ErrorWarning{PDF/X-1:1999 is no longer an accepted standard}%
+    {Use option  x-1a1 or  x-1a3 }{; continuing to build a non-valid document}%
+    {, else continue to build a non-valid document.}%
+ }%  effectively same as  x-1a1
+\DeclareOption{x-1a}{\global\pdfx@xtrue\def\xmp@Part{1}% CMYK only
  \def\xmp@Conformance{a}\def\xmp@ReleaseDate{2003}%
- \global\pdfminorversion=3 }
+ \global\pdfx@minorversion=3 }%  same as  x-1a3
 \DeclareOption{x-1a1}{\global\pdfx@xtrue\def\xmp@Part{1}%
- \def\xmp@Conformance{a}\def\xmp@ReleaseDate{2001}%
- \global\pdfminorversion=3 }
+ \def\xmp@Conformance{a}\def\xmp@ReleaseDate{2001}%  ISO 15930-1:2001
+ \global\pdfx@minorversion=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 }
+ \def\xmp@Conformance{a}\def\xmp@ReleaseDate{2003}%  ISO 15930-4:2003
+ \global\pdfx@minorversion=3 }
+\DeclareOption{x-2}{\global\pdfx@xtrue\def\xmp@Part{2}%  XMP Metadata
+%% \def\xmp@Conformance{}\def\xmp@ReleaseDate{2002}%  ISO 15930-2:2003
+ \def\xmp@Conformance{}\def\xmp@ReleaseDate{2003}%   ISO 15930-5, withdrawn 2011
+ \global\pdfx@minorversion=4\relax
+ \pdfx@ErrorWarning{PDF/X-2:2003 was never published as a standard}%
+   {Use option  x-1a or  x-3 }{; continuing to build a non-valid document}%
+   {, else continue to build a non-valid document}%
+ }%  external OPI workflow, i.e. multiple files involved
+\DeclareOption{x-3}{\global\pdfx@xtrue\def\xmp@Part{3}% RGB allowed, but rare!
+ \def\xmp@Conformance{}\def\xmp@ReleaseDate{2003}%
+ \global\pdfminorversion=4 }%  same as x-303
 \DeclareOption{x-302}{\global\pdfx@xtrue\def\xmp@Part{3}%
- \def\xmp@Conformance{}\def\xmp@ReleaseDate{2002}%
- \global\pdfminorversion=3 }
+ \def\xmp@Conformance{}\def\xmp@ReleaseDate{2002}%   ISO 15930-3:2002
+ \global\pdfx@minorversion=3 }
 \DeclareOption{x-303}{\global\pdfx@xtrue\def\xmp@Part{3}%
- \def\xmp@Conformance{}\def\xmp@ReleaseDate{2003}%
- \global\pdfminorversion=4 }
+ \def\xmp@Conformance{}\def\xmp@ReleaseDate{2003}%  ISO 15930-6:2003
+ \global\pdfx@minorversion=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 }
+ \def\xmp@Conformance{}\def\xmp@ReleaseDate{2010}%  ISO 15930-7:2010
+ \global\pdfx@minorversion=6 }%  same as  x-410
 \DeclareOption{x-4p}{\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{2010}%
+  \global\pdfx@minorversion=6 }%  same as  x-4p10
 \DeclareOption{x-408}{\global\pdfx@xtrue\def\xmp@Part{4}%
- \def\xmp@Conformance{}\def\xmp@ReleaseDate{2008}%
- \global\pdfminorversion=6 }
+ \def\xmp@Conformance{}\def\xmp@ReleaseDate{2008}%  ISO 15930-7:2008
+ \global\pdfx@minorversion=6 }
 \DeclareOption{x-410}{\global\pdfx@xtrue\def\xmp@Part{4}%
- \def\xmp@Conformance{}\def\xmp@ReleaseDate{2010}%
- \global\pdfminorversion=6 }
+ \def\xmp@Conformance{}\def\xmp@ReleaseDate{2010}%  ISO 15930-7:2010
+ \global\pdfx@minorversion=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 }
+  \global\pdfx@minorversion=6 }%   ISO 15930-7:2010
 \DeclareOption{x-4p10}{\global\pdfx@xtrue\global\no@iccprofiletrue
   \def\xmp@Part{4}\def\xmp@Conformance{p}\def\xmp@ReleaseDate{2010}%
-  \global\pdfminorversion=6 }
+  \global\pdfx@minorversion=6 }%   ISO 15930-7:2010
 \DeclareOption{x-5}{\global\pdfx@xtrue\def\xmp@Part{5}%
- \def\xmp@Conformance{}\def\xmp@ReleaseDate{2008}%
- \global\pdfminorversion=6 }
+ \def\xmp@Conformance{g}\def\xmp@ReleaseDate{2008}%
+ \global\pdfx@minorversion=6 }%   ISO 15930-8:2010
 \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 }
+ \global\pdfx@minorversion=6 }%   ISO 15930-8:2010
+\DeclareOption{x-5n}{\global\pdfx@xtrue %\global\no@iccprofiletrue
+ \def\xmp@Part{5}\def\xmp@Conformance{n}\def\xmp@ReleaseDate{2010}%
+ \global\pdfx@minorversion=6 \pdfx@Xvn@message}%   ISO 15930-8:2010
 \DeclareOption{x-5pg}{\global\pdfx@xtrue\global\no@iccprofiletrue
-  \def\xmp@Part{5}\def\xmp@Conformance{pg}\def\xmp@ReleaseDate{2008}%
-  \global\pdfminorversion=6 }
+  \def\xmp@Part{5}\def\xmp@Conformance{pg}\def\xmp@ReleaseDate{2010}%
+  \global\pdfx@minorversion=6 }%  ISO 15930-8:2010
 \DeclareOption{x-508}{\global\pdfx@xtrue\def\xmp@Part{5}%
- \def\xmp@Conformance{}\def\xmp@ReleaseDate{2008}%
- \global\pdfminorversion=6 }
+ \def\xmp@Conformance{g}\def\xmp@ReleaseDate{2008}%
+ \global\pdfx@minorversion=6 }%   ISO 15930-8:2008
 \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 }
+ \global\pdfx@minorversion=6 }%   ISO 15930-8:2008
+\DeclareOption{x-5n08}{\global\pdfx@xtrue %\global\no@iccprofiletrue
+ \def\xmp@Part{5}\def\xmp@Conformance{n}\def\xmp@ReleaseDate{2008}%
+ \global\pdfx@minorversion=6 \pdfx@Xvn@message}%   ISO 15930-8:2008
 \DeclareOption{x-5pg08}{\global\pdfx@xtrue\global\no@iccprofiletrue
   \def\xmp@Part{5}\def\xmp@Conformance{pg}\def\xmp@ReleaseDate{2008}%
-  \global\pdfminorversion=6 }
+  \global\pdfx@minorversion=6 }%  ISO 15930-8:2008
 \DeclareOption{x-510}{\global\pdfx@xtrue\def\xmp@Part{5}%
- \def\xmp@Conformance{}\def\xmp@ReleaseDate{2010}%
- \global\pdfminorversion=6 }
+ \def\xmp@Conformance{g}\def\xmp@ReleaseDate{2010}%
+ \global\pdfx@minorversion=6 }%  ISO 15930-8:2010
 \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 }
+ \global\pdfx@minorversion=6 }%  ISO 15930-8:2010
+\DeclareOption{x-5n10}{\global\pdfx@xtrue %\global\no@iccprofiletrue
+ \def\xmp@Part{5}\def\xmp@Conformance{n}\def\xmp@ReleaseDate{2010}%
+ \global\pdfx@minorversion=6 \pdfx@Xvn@message}%  ISO 15930-8:2010
 \DeclareOption{x-5pg10}{\global\pdfx@xtrue\global\no@iccprofiletrue
   \def\xmp@Part{5}\def\xmp@Conformance{pg}\def\xmp@ReleaseDate{2010}%
-  \global\pdfminorversion=6 }
+  \global\pdfx@minorversion=6 }%  ISO 15930-8:2010
+%%
+%% PDF/E options
+%%
+\DeclareOption{e}{\global\pdfx@xfalse\global\pdfx@etrue
+  \def\xmp@Part{1}\def\xmp@Conformance{}\def\xmp@ReleaseDate{2008}%
+  \gdef\thepdfminorversion{6}%   same as  e-1
+  }
 \DeclareOption{e-1}{\global\pdfx@xfalse\global\pdfx@etrue
   \def\xmp@Part{1}\def\xmp@Conformance{}\def\xmp@ReleaseDate{2008}%
-  \global\pdfminorversion=6 }
+  \gdef\thepdfminorversion{6}%  ISO 24517-1:2008
+  }
+%% PDF/UA options
+%%
+\let\xmp@PDFUA\@empty
+\DeclareOption{ua}{\global\pdfx@uatrue % ISO 14289-1:2012, 2014
+  \def\xmp@UAlevel{1}\let\xmp@PDFUA\relax}%   same as  ua-1
+\DeclareOption{ua-1}{\global\pdfx@uatrue % ISO 14289-1:2012, 2014
+  \def\xmp@UAlevel{1}\let\xmp@PDFUA\relax}
+%%
+%% PDF/VT options
+%%
 \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 }
+  \gdef\xmpMM@VersionID{1}%
+  \global\pdfx@minorversion=6 }
 \DeclareOption{vt-2}{\global\pdfx@xtrue\global\pdfx@vttrue
-  \global\no@iccprofiletrue
+  \global\no@iccprofiletrue   \gdef\xmpMM@VersionID{1}%
   \def\xmp@Part{5}\def\xmp@vtPart{2}\def\xmp@Conformance{pg}%
   \def\xmp@vtConformance{}\def\xmp@ReleaseDate{2010}%
-  \global\pdfminorversion=6 }
+  \global\pdfx@minorversion=6 }
 \DeclareOption{vt-2s}{\global\pdfx@xtrue\global\pdfx@vttrue
-  \global\no@iccprofiletrue
+  \global\no@iccprofiletrue   \gdef\xmpMM@VersionID{1}%
   \def\xmp@Part{5}\def\xmp@vtPart{2}\def\xmp@Conformance{pg}%
   \def\xmp@vtConformance{s}\def\xmp@ReleaseDate{2010}%
-  \global\pdfminorversion=6 }
+  \global\pdfx@minorversion=6 }
 
 %% options to alter PDF minor version, in case needed in special circumstances
-\DeclareOption{pdf12}{\global\pdfminorversion=2 }
-\DeclareOption{pdf13}{\global\pdfminorversion=3 }
-\DeclareOption{pdf14}{\global\pdfminorversion=4 }
-\DeclareOption{pdf15}{\global\pdfminorversion=5 }
-\DeclareOption{pdf16}{\global\pdfminorversion=6 }
-\DeclareOption{pdf17}{\global\pdfminorversion=7 }
+\DeclareOption{pdf12}{\global\pdfx@minorversion=2 }%  1999
+\DeclareOption{pdf13}{\global\pdfx@minorversion=3 }%  2001  Acrobat 4 (ISBN 0-201-61588-6)
+\DeclareOption{pdf14}{\global\pdfx@minorversion=4 }%  2003  Acrobat 5 (ISBN 0-201-75839-3)
+\DeclareOption{pdf15}{\global\pdfx@minorversion=5 }%  2005  Acrobat 6
+\DeclareOption{pdf16}{\global\pdfx@minorversion=6 }%  2006  Acrobat 7 (ISBN 0-321-30474-8)
+\DeclareOption{pdf17}{\global\pdfx@minorversion=7 }%  2008  ISO 32000-1:2008
 
 %% inhibits writing the XMP byte-order marker
 \DeclareOption{noBOM}{\pdfx@noBOMtrue}
 \DeclareOption{useBOM}{\pdfx@noBOMfalse}
 
-\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\ifhebHEBxmp
 \newif\ifarbxmp
 \newif\ifarmxmp
 \newif\ifarmSCIxmp
+\newif\ifdevxmp
 \newif\ifvnmxmp
 \newif\iflatEXTxmp
 \newif\iflatLATxmp
@@ -208,9 +253,11 @@
 \DeclareOption{grkxmp}{\global\grkxmptrue}
 \DeclareOption{LGRxmp}{\global\grkLGRxmptrue\global\grkxmptrue}
 \DeclareOption{hebxmp}{\global\hebxmptrue}
+\DeclareOption{HEBxmp}{\global\hebHEBxmptrue\global\hebxmptrue}
 \DeclareOption{arbxmp}{\global\arbxmptrue}
 \DeclareOption{armxmp}{\global\armxmptrue}
 \DeclareOption{AR8xmp}{\global\armSCIxmptrue\global\armxmptrue}
+\DeclareOption{devxmp}{\global\devxmptrue}
 \DeclareOption{vnmxmp}{\global\vnmxmptrue}
 \DeclareOption{ipaxmp}{\global\ipaxmptrue\global\latEXTxmptrue}
 \DeclareOption{mathxmp}{\global\mathxmptrue\global\grkxmptrue}
@@ -222,9 +269,11 @@
  \global\grkxmptrue
  \global\grkLGRxmptrue
  \global\hebxmptrue
+ \global\hebHEBxmptrue
  \global\arbxmptrue
  \global\armxmptrue
  \global\armSCIxmptrue
+ \global\devxmptrue
  \global\vnmxmptrue
  \global\latEXTxmptrue
  \global\latLATxmptrue
@@ -239,8 +288,61 @@
 \ExecuteOptions{noBOM,a-1b}
 \ProcessOptions
 
+\ifpdfx@ua\ifpdfx@x\else
+ \expandafter\if\xmp@Conformance A\else
+ \pdfx@ErrorWarning{PDF/UA requires 'Tagged PDF' for any structure.^^J
+  Then PDF/A Conformance must be 'a'}%
+  {Use option 'a-\xmp@Part a'}%
+  {; continuing with a likely invalid document}%
+  {, or continue for a likely invalid document}%
+%%%  \gdef\xmp@Conformance{A}%   do we want this?
+\fi\fi\fi
+
+\expandafter\ifx\csname pdflastobj\endcsname\relax
+\else
+ \ifnum\pdflastobj >\z@ % pdftex  has already written objects
+  \ifnum\pdfx@minorversion=\pdfminorversion\else
+   \PackageError{pdfx}%
+    {^^J(pdfx)    Cannot change the \string\pdfminorversion^^J%
+     (pdfx)   PDF version remains at 1.\the\pdfminorversion.^^J%
+     (pdfx)   Use \string\pdfminorversion=\the\pdfx@minorversion\space
+      before \string\documentclass}%
+    {(pdfx)   Another package or document-class has written objects into the PDF.^^J%
+     (pdfx)   Hit return to continue with PDF version 1.\the\pdfminorversion.%
+    }%
+   \global\pdfx@minorversion=\the\pdfminorversion
+  \fi
+ \else
+  \global\pdfminorversion\pdfx@minorversion
+ \fi
+\fi
+
 \expandafter\ifx\csname thepdfminorversion\endcsname\relax
- \xdef\thepdfminorversion{\the\pdfminorversion}
+ \expandafter\ifx\csname pdfminorversion\endcsname\relax
+ \else
+  \xdef\thepdfminorversion{\the\pdfminorversion}
+\fi\fi
+
+\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
+ \ifnum\pdfminorversion < 4\relax
+  \ifpdfx@x
+    % more testing needed with PDF/X
+  \else
+   \pdfminorversion=4\relax %  assumed for PDF/A ;  options may change this for  PDF/X
+   \gdef\thepdfminorversion{4}%
+  \fi
+ \else
+  \ifnum\pdfminorversion<\thepdfminorversion\relax
+   \global\pdfminorversion=\thepdfminorversion\relax
+  \fi
+ \fi
+\fi
+\expandafter\ifx\csname pdfresetpageorigin\endcsname\relax\else
+ \pdfresetpageorigin=0
 \fi
 
 \newif\ifpdfx@nopdfinfo
@@ -249,21 +351,27 @@
  \iflatLATxmp\pdfx@nopdfinfotrue
 \else
  \ifgrkLGRxmp\pdfx@nopdfinfotrue
+\else
+ \ifhebHEBxmp\pdfx@nopdfinfotrue
 \else
  \ifcyrKOIxmp\pdfx@nopdfinfotrue
 \else
  \ifarmSCIxmp\pdfx@nopdfinfotrue
-\fi\fi\fi\fi\fi
+\fi\fi\fi\fi\fi\fi
 
 \iflatLATxmp\pdfx@useactivespacestrue\fi
 \ifgrkLGRxmp\pdfx@useactivespacestrue\fi
+\ifhebHEBxmp\pdfx@useactivespacestrue\fi
 \ifcyrKOIxmp\pdfx@useactivespacestrue\fi
 \ifarmSCIxmp\pdfx@useactivespacestrue\fi
 
 \newif\ifpdfx@transliterated
 \ifgrkLGRxmp\pdfx@transliteratedtrue\fi
+\ifhebHEBxmp\pdfx@transliteratedtrue\fi
 \ifarmSCIxmp\pdfx@transliteratedtrue\fi
 
+\RequirePackage{iftex}
+\RequirePackage{ifpdf}
 %% Support for pdfTeX primitives when using XeTeX:
 \RequirePackage{ifxetex}
 \ifxetex
@@ -281,6 +389,8 @@
  \let\pdfobjcompresslevel\pdf@compress@xetex
 \fi
 
+%%\newif\ifpdfx@pdfmark  %  control future support for  dvips
+
 \RequirePackage{ifluatex}
 \ifluatex
  \IfFileExists{luatex85.sty}{% 2016+
@@ -290,6 +400,7 @@
  }%
  \RequirePackage{pdftexcmds}%
  \let\pdfx@mdfivesum\pdf@mdfivesum
+ \let\pdfescapestring\pdf@escapestring
 \else
  \ifxetex
   \usepackage{everyshi}%
@@ -304,7 +415,7 @@
   \let\pdfx@mdfivesum\pdfmdfivesum
  \fi
 \fi
-\def\pdfx@encodingfile{l8uenc.def}
+\def\pdfx@encodingfile{l8u-penc.def}
 
 \expandafter\ifx\csname pdftexbanner\endcsname\relax
  \expandafter\ifx\csname luatexbanner\endcsname\relax
@@ -358,6 +469,7 @@
     /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
+    /CropBox[0 0 \pdfx@mwidth\space \pdfx@mheight]^^J
     /TrimBox[25 20 \pdfx@twidth\space \pdfx@theight]}
   }\next
  \ifxetex
@@ -366,6 +478,13 @@
   \EveryShipout{%
    \immediate\special{pdf:put @thispage <<\pdfx@everypage@xetex>>}}%
  \fi
+\else
+%%  PDF/A-1b  doesn't allow object compression
+ \ifnum\xmp@ReleaseDate=2005\relax
+  \expandafter\ifx\csname pdfobjcompresslevel\endcsname\relax
+  \else
+   \pdfobjcompresslevel=0\relax
+ \fi \fi
 \fi
 \ifxetex
 %% How to support XeTeX here ?
@@ -400,7 +519,32 @@
 \@namedef{T@L8U}{}%
 \@namedef{D@L8U}{}%
 \@namedef{M@L8U}{}%
+
+%% adjust to LaTeX's 2018 change to the default encoding
+\expandafter\ifx\csname inputencodingname\endcsname\relax
+\else
+ \def\pdfx@restoreencoding#1{%
+  \@tempcnta=128
+  \loop
+   \catcode\@tempcnta=13
+   \advance\@tempcnta\@ne
+  \ifnum\@tempcnta<256
+  \repeat
+  \inputencoding{#1}%
+  }%
+  \AtEndOfPackage{\pdfx@restoreencoding\pdfx@inputencodingname}%
+  \let\pdfx@inputencodingname\inputencodingname
+  \let\pdfx@DeclareUnicodeCharacter\DeclareUnicodeCharacter
+  \UseRawInputEncoding
+\fi
 \InputIfFileExists{\pdfx@encodingfile}{}{}
+\expandafter\ifx\csname pdfx@inputencodingname\endcsname\relax
+\else
+  \let\inputencodingname\pdfx@inputencodingname
+  \let\DeclareUnicodeCharacter\pdfx@DeclareUnicodeCharacter
+  \let\DeclareFontEncoding@\DeclareFontEncoding@saved
+  \inputencoding{\inputencodingname}%
+\fi
 
 %%----------------------------------------------------------------------
 %% Macros for reading XMP data with special catcodes. Usage:
@@ -418,42 +562,425 @@
  \ifpdfx@useactivespaces\obeyspaces\fi % capture spaces as active characters
  \xmp@doparse{#1}%
 }
+\def\afterxmp@parse{}% methods may change this
 \def\xmp@doparse#1#2{%
  \def\@this{#2}#1
  \endgroup
+ % do any post-processing
+ \afterxmp@parse
+ \def\afterxmp@parse{}%
 }
 
 %%----------------------------------------------------------------------
 %% Local commands. They are only brought into scope during the reading
-%% of xmpdata.
+%% of xmpdata. Some fields can have a 'xml:lang' attribute; others must have.
+%%  LANG values as in:  (BCP 47)  https://tools.ietf.org/html/rfc5646#appendix-A
+%%
+\def\xmp@lang@Default{x-default}
+\let\xmp@lang@Title\xmp@lang@Default
+\let\xmp@lang@Author\xmp@lang@Default
+\let\xmp@lang@Keywords\xmp@lang@Default
+\let\xmp@lang@Subject\xmp@lang@Default
+%%\def\xmp@lang@CreatorTool{\xmp@lang@Default}
+\let\xmp@lang@Producer\xmp@lang@Default
+%%\def\xmp@lang@Volume{\xmp@lang@Default}
+%%\def\xmp@lang@Issue{\xmp@lang@Default}
+\let\xmp@lang@Copyright\xmp@lang@Default
+\let\xmp@lang@PublicationType\xmp@lang@Default
+\let\xmp@lang@Publisher\xmp@lang@Default
+\let\xmp@lang@Coverage\xmp@lang@Default
+\let\xmp@lang@Contributor\xmp@lang@Default
+\let\xmp@lang@Relation\xmp@lang@Default
+%%%  PRISM fields
+\let\xmp@lang@CoverDisplayDate\xmp@lang@Default
+\let\xmp@lang@JournalTitle\xmp@lang@Default
+%%\def\xmp@lang@JournalNumber{\xmp@lang@Default}
+%%%  xmp:  &  xmpRights:  fields
+\let\xmp@lang@Advisory\xmp@lang@Default
+\let\xmp@lang@Identifier\xmp@lang@Default
+\let\xmp@lang@Nickname\xmp@lang@Default
+\let\xmp@lang@Owner\xmp@lang@Default
+
+%% some validators require a language attribute for
+%%   dc:title                 set via  \Title
+%%   dc:description   set via  \Subject
+%%   dc:rights              set via  \Copyright
+%%   xmpRights:UsageTerms   set via \Copyright
+%%
+{\catcode `\" 12 \catcode`\: 12 \catcode`\= 12
+ \gdef\pdfx@xmp@checklang#1{%
+  \ifx #1\xmp@lang@Default\else\space xml:lang="#1"\fi}
+ \gdef\pdfx@xmp@strictlang#1{\space xml:lang="#1"}
+}%  end of  \catcodes
+\let\xmp@checklang\pdfx@xmp@checklang
+\let\xmp@strictlang\pdfx@xmp@strictlang
+
+\newcommand{\pdfx@Title}[1][]{%
+ \ifx\relax#1\relax\else\gdef\xmp@lang@Title{#1}\fi
+ \xmp@parse{\global\let\xmp@Title\@this}}
+
+%% allow for multiple authors, keywords and languages
+%%  also:  contributor, date, relation, type, thumbnails
+%%  and  AuthoritativeDomain, Advisory, Identifier, Owner
+\newcommand{\pdfx@Author}[1][]{%
+ \ifx\relax#1\relax\else\gdef\xmp@lang@Author{#1}\fi
+ \def\afterxmp@parse{\let\Author\pdfx@extraAuthor}%
+ \xmp@parse{\global\let\xmp@Author\@this}}
+\newcommand{\pdfx@Keywords}[1][]{%
+ \ifx\relax#1\relax\else\gdef\xmp@lang@Keywords{#1}\fi
+ \def\afterxmp@parse{\let\Keywords\pdfx@extraKeywords}%
+ \xmp@parse{\global\let\xmp@Keywords\@this}}
+\newcommand{\pdfx@Language}{%
+ \def\afterxmp@parse{\let\Language\pdfx@extraLanguages}%
+ \xmp@parse{\global\let\xmp@Language\@this}}
+
+\newcommand{\pdfx@AuthoritativeDomain}{%
+ \def\afterxmp@parse{\let\AuthoritativeDomain\pdfx@extraAuthoritativeDomain}%
+ \xmp@parse{\global\let\xmp@AuthoritativeDomain\@this}}
+\newcommand{\pdfx@Date}{%
+ \def\afterxmp@parse{\let\Date\pdfx@extraDate}%
+ \xmp@parse{\global\let\xmp@Date\@this}}
+\newcommand{\pdfx@Contributor}[1][]{%
+ \ifx\relax#1\relax\else\gdef\xmp@lang@Contributor{#1}\fi
+ \def\afterxmp@parse{\let\Contributor\pdfx@extraContributor}%
+ \xmp@parse{\global\let\xmp@Contributor\@this}}
+\newcommand{\pdfx@Relation}[1][]{%
+ \ifx\relax#1\relax\else\gdef\xmp@lang@Relation{#1}\fi
+ \def\afterxmp@parse{\let\Relation\pdfx@extraRelation}%
+ \xmp@parse{\global\let\xmp@Relation\@this}}
+%%\newcommand{\pdfx@Type}[1][]{%
+%% \ifx\relax#1\relax\else\gdef\xmp@lang@Type{#1}\fi
+%% \def\afterxmp@parse{\let\Type\pdfx@extraType}%
+%% \xmp@parse{\global\let\xmp@Type\@this}}
+
+\newcommand{\pdfx@Advisory}[1][]{%
+ \ifx\relax#1\relax\else\gdef\xmp@lang@Advisory{#1}\fi
+ \def\afterxmp@parse{\let\Advisory\pdfx@extraAdvisory}%
+ \xmp@parse{\global\let\xmp@Advisory\@this}}
+\newcommand{\pdfx@Identifier}[1][]{%
+ \ifx\relax#1\relax\else\gdef\xmp@lang@Identifier{#1}\fi
+ \def\afterxmp@parse{\let\Identifier\pdfx@extraIdentifier}%
+ \xmp@parse{\global\let\xmp@Identifier\@this}}
+\newcommand{\pdfx@Thumbnails}{%
+ \def\afterxmp@parse{\let\Thumbnails\pdfx@extraThumbnails}%
+ \xmp@parse{\global\let\xmp@Thumbnails\@this}}
+
+\newcommand{\pdfx@Owner}[1][]{%
+ \ifx\relax#1\relax\else\gdef\xmp@lang@Owner{#1}\fi
+ \def\afterxmp@parse{\let\Owner\pdfx@extraOwner}%
+ \xmp@parse{\global\let\xmp@Owner\@this}}
+
+{\obeyspaces%
+ \ifpdfx@useactivespaces\gdef\pdfx@insert@sep{\sep }%
+ \else\gdef\pdfx@insert@sep{\sep}\fi%
+}
+\newcommand{\pdfx@extraAuthor}[1][]{%
+ \ifx\relax#1\relax
+  \expandafter\expandafter\expandafter\gdef
+   \expandafter\expandafter\expandafter\xmp@Author
+    \expandafter\expandafter\expandafter{%
+     \expandafter\xmp@Author\pdfx@insert@sep}%
+ \else
+  \expandafter\expandafter\expandafter\gdef
+   \expandafter\expandafter\expandafter\xmp@Author
+    \expandafter\expandafter\expandafter{%
+     \expandafter\xmp@Author\pdfx@insert@sep[#1]}%
+ \fi
+ \def\afterxmp@parse{%
+  \expandafter\expandafter\expandafter\gdef
+   \expandafter\expandafter\expandafter\xmp@Author
+   \expandafter\expandafter\expandafter{%
+    \expandafter\xmp@Author\xmp@extraAuthor}%
+   }%
+ \xmp@parse{\global\let\xmp@extraAuthor\@this}%
+ }%
+\newcommand{\pdfx@extraKeywords}[1][]{%
+ \ifx\relax#1\relax
+  \expandafter\expandafter\expandafter\gdef
+   \expandafter\expandafter\expandafter\xmp@Keywords
+    \expandafter\expandafter\expandafter{%
+     \expandafter\xmp@Keywords\pdfx@insert@sep}%
+ \else%
+  \expandafter\expandafter\expandafter\gdef
+   \expandafter\expandafter\expandafter\xmp@Keywords
+    \expandafter\expandafter\expandafter{%
+     \expandafter\xmp@Keywords\pdfx@insert@sep[#1]}%
+ \fi%
+ \def\afterxmp@parse{%
+  \expandafter\expandafter\expandafter\gdef
+   \expandafter\expandafter\expandafter\xmp@Keywords
+   \expandafter\expandafter\expandafter{%
+    \expandafter\xmp@Keywords\xmp@extraKeywords}}%
+ \xmp@parse{\global\let\xmp@extraKeywords\@this}%
+ }%
+\newcommand{\pdfx@extraLanguages}{%
+  \expandafter\expandafter\expandafter\gdef
+   \expandafter\expandafter\expandafter\xmp@Language
+    \expandafter\expandafter\expandafter{%
+     \expandafter\xmp@Language\pdfx@insert@sep}%
+ \def\afterxmp@parse{%
+  \expandafter\expandafter\expandafter\gdef
+   \expandafter\expandafter\expandafter\xmp@Language
+   \expandafter\expandafter\expandafter{%
+    \expandafter\xmp@Language\xmp@extraLanguages}}%
+ \xmp@parse{\global\let\xmp@extraLanguages\@this}%
+ }%
+
+\newcommand{\pdfx@extraContributor}[1][]{%
+ \ifx\relax#1\relax
+  \expandafter\expandafter\expandafter\gdef
+   \expandafter\expandafter\expandafter\xmp@Contributor
+    \expandafter\expandafter\expandafter{%
+     \expandafter\xmp@Contributor\pdfx@insert@sep}%
+ \else
+  \expandafter\expandafter\expandafter\gdef
+   \expandafter\expandafter\expandafter\xmp@Contributor
+    \expandafter\expandafter\expandafter{%
+     \expandafter\xmp@Contributor\pdfx@insert@sep[#1]}%
+ \fi
+ \def\afterxmp@parse{%
+  \expandafter\expandafter\expandafter\gdef
+   \expandafter\expandafter\expandafter\xmp@Contributor
+   \expandafter\expandafter\expandafter{%
+    \expandafter\xmp@Contributor\xmp@extraContributor}%
+   }%
+ \xmp@parse{\global\let\xmp@extraContributor\@this}%
+ }%
+
+\newcommand{\pdfx@extraAuthoritativeDomain}{%
+  \expandafter\expandafter\expandafter\gdef
+   \expandafter\expandafter\expandafter\xmp@AuthoritativeDomain
+    \expandafter\expandafter\expandafter{%
+     \expandafter\xmp@AuthoritativeDomain\pdfx@insert@sep}%
+ \def\afterxmp@parse{%
+  \expandafter\expandafter\expandafter\gdef
+   \expandafter\expandafter\expandafter\xmp@AuthoritativeDomain
+   \expandafter\expandafter\expandafter{%
+    \expandafter\xmp@AuthoritativeDomain\xmp@extraAuthoritativeDomain}%
+   }%
+ \xmp@parse{\global\let\xmp@extraAuthoritativeDomain\@this}%
+ }%
+
+\newcommand{\pdfx@extraDate}{%
+  \expandafter\expandafter\expandafter\gdef
+   \expandafter\expandafter\expandafter\xmp@Date
+    \expandafter\expandafter\expandafter{%
+     \expandafter\xmp@Date\pdfx@insert@sep}%
+ \def\afterxmp@parse{%
+  \expandafter\expandafter\expandafter\gdef
+   \expandafter\expandafter\expandafter\xmp@Date
+   \expandafter\expandafter\expandafter{%
+    \expandafter\xmp@Date\xmp@extraDate}%
+   }%
+ \xmp@parse{\global\let\xmp@extraDate\@this}%
+ }%
+
+\newcommand{\pdfx@extraRelation}[1][]{%
+ \ifx\relax#1\relax
+  \expandafter\expandafter\expandafter\gdef
+   \expandafter\expandafter\expandafter\xmp@Relation
+    \expandafter\expandafter\expandafter{%
+     \expandafter\xmp@Relation\pdfx@insert@sep}%
+ \else
+  \expandafter\expandafter\expandafter\gdef
+   \expandafter\expandafter\expandafter\xmp@Relation
+    \expandafter\expandafter\expandafter{%
+     \expandafter\xmp@Relation\pdfx@insert@sep[#1]}%
+ \fi
+ \def\afterxmp@parse{%
+  \expandafter\expandafter\expandafter\gdef
+   \expandafter\expandafter\expandafter\xmp@Relation
+   \expandafter\expandafter\expandafter{%
+    \expandafter\xmp@Relation\xmp@extraRelation}%
+   }%
+ \xmp@parse{\global\let\xmp@extraRelation\@this}%
+ }%
+
+%%\newcommand{\pdfx@extraType}[1][]{%
+%%% \show\xmp@Type
+%% \ifx\relax#1\relax
+%%  \expandafter\expandafter\expandafter\gdef
+%%   \expandafter\expandafter\expandafter\xmp@Type
+%%    \expandafter\expandafter\expandafter{%
+%%     \expandafter\xmp@Type\pdfx@insert@sep}%
+%% \else
+%%  \expandafter\expandafter\expandafter\gdef
+%%   \expandafter\expandafter\expandafter\xmp@Type
+%%    \expandafter\expandafter\expandafter{%
+%%     \expandafter\xmp@Type\pdfx@insert@sep[#1]}%
+%% \fi
+%% \def\afterxmp@parse{%
+%%  \expandafter\expandafter\expandafter\gdef
+%%   \expandafter\expandafter\expandafter\xmp@Type
+%%   \expandafter\expandafter\expandafter{%
+%%    \expandafter\xmp@Type\xmp@extraType}%
+%%   %\show\xmp@Type
+%%   }%
+%% \xmp@parse{\global\let\xmp@extraType\@this}%
+%% }%
+
+\newcommand{\pdfx@extraAdvisory}[1][]{%
+ \ifx\relax#1\relax
+  \expandafter\expandafter\expandafter\gdef
+   \expandafter\expandafter\expandafter\xmp@Advisory
+    \expandafter\expandafter\expandafter{%
+     \expandafter\xmp@Advisory\pdfx@insert@sep}%
+ \else
+  \expandafter\expandafter\expandafter\gdef
+   \expandafter\expandafter\expandafter\xmp@Advisory
+    \expandafter\expandafter\expandafter{%
+     \expandafter\xmp@Advisory\pdfx@insert@sep[#1]}%
+ \fi
+ \def\afterxmp@parse{%
+  \expandafter\expandafter\expandafter\gdef
+   \expandafter\expandafter\expandafter\xmp@Advisory
+   \expandafter\expandafter\expandafter{%
+    \expandafter\xmp@Advisory\xmp@extraAdvisory}%
+   }%
+ \xmp@parse{\global\let\xmp@extraAdvisory\@this}%
+ }%
+
+\newcommand{\pdfx@extraIdentifier}[1][]{%
+ \ifx\relax#1\relax
+  \expandafter\expandafter\expandafter\gdef
+   \expandafter\expandafter\expandafter\xmp@Identifier
+    \expandafter\expandafter\expandafter{%
+     \expandafter\xmp@Identifier\pdfx@insert@sep}%
+ \else
+  \expandafter\expandafter\expandafter\gdef
+   \expandafter\expandafter\expandafter\xmp@Identifier
+    \expandafter\expandafter\expandafter{%
+     \expandafter\xmp@Identifier\pdfx@insert@sep[#1]}%
+ \fi
+ \def\afterxmp@parse{%
+  \expandafter\expandafter\expandafter\gdef
+   \expandafter\expandafter\expandafter\xmp@Identifier
+   \expandafter\expandafter\expandafter{%
+    \expandafter\xmp@Identifier\xmp@extraIdentifier}%
+   }%
+ \xmp@parse{\global\let\xmp@extraIdentifier\@this}%
+ }%
+
+\newcommand{\pdfx@extraThumbnails}[1][]{%
+ \ifx\relax#1\relax
+  \expandafter\expandafter\expandafter\gdef
+   \expandafter\expandafter\expandafter\xmp@Thumbnails
+    \expandafter\expandafter\expandafter{%
+     \expandafter\xmp@Thumbnails\pdfx@insert@sep}%
+ \else
+  \expandafter\expandafter\expandafter\gdef
+   \expandafter\expandafter\expandafter\xmp@Thumbnails
+    \expandafter\expandafter\expandafter{%
+     \expandafter\xmp@Thumbnails\pdfx@insert@sep[#1]}%
+ \fi
+ \def\afterxmp@parse{%
+  \expandafter\expandafter\expandafter\gdef
+   \expandafter\expandafter\expandafter\xmp@Thumbnails
+   \expandafter\expandafter\expandafter{%
+    \expandafter\xmp@Thumbnails\xmp@extraThumbnails}%
+   }%
+ \xmp@parse{\global\let\xmp@extraThumbnails\@this}%
+ }%
+
+\newcommand{\pdfx@extraOwner}[1][]{%
+ \ifx\relax#1\relax
+  \expandafter\expandafter\expandafter\gdef
+   \expandafter\expandafter\expandafter\xmp@Owner
+    \expandafter\expandafter\expandafter{%
+     \expandafter\xmp@Owner\pdfx@insert@sep}%
+ \else
+  \expandafter\expandafter\expandafter\gdef
+   \expandafter\expandafter\expandafter\xmp@Owner
+    \expandafter\expandafter\expandafter{%
+     \expandafter\xmp@Owner\pdfx@insert@sep[#1]}%
+ \fi
+ \def\afterxmp@parse{%
+  \expandafter\expandafter\expandafter\gdef
+   \expandafter\expandafter\expandafter\xmp@Owner
+   \expandafter\expandafter\expandafter{%
+    \expandafter\xmp@Owner\xmp@extraOwner}%
+   }%
+ \xmp@parse{\global\let\xmp@extraOwner\@this}%
+ }%
+
+\newcommand{\pdfx@Subject}[1][]{%
+ \ifx\relax#1\relax\else\gdef\xmp@lang@Subject{#1}\fi
+ \xmp@parse{\global\let\xmp@Subject\@this}}
+\newcommand{\pdfx@Producer}[1][]{%
+ \ifx\relax#1\relax\else\gdef\xmp@lang@Producer{#1}\fi
+ \xmp@parse{\global\let\xmp@Producer\@this}}
+\newcommand{\pdfx@Publisher}[1][]{%
+ \ifx\relax#1\relax\else\gdef\xmp@lang@Publisher{#1}\fi
+ \xmp@parse{\global\let\xmp@Publisher\@this}}
+\newcommand{\pdfx@Copyright}[1][]{%
+ \ifx\relax#1\relax\else\gdef\xmp@lang@Copyright{#1}\fi
+ \xmp@parse{\global\let\xmp@Copyright\@this%
+  \ifx\xmp@Copyrighted\@empty\gdef\xmp@Copyrighted{True}\fi}}
+
+\newcommand{\pdfx@Coverage}[1][]{%
+ \ifx\relax#1\relax\else\gdef\xmp@lang@Coverage{#1}\fi
+ \xmp@parse{\global\let\xmp@Coverage\@this}}
+
+%%  PRISM Text fields
+\newcommand{\pdfx@CoverDisplayDate}[1][]{%
+ \ifx\relax#1\relax\else\gdef\xmp@lang@CoverDisplayDate{#1}\fi
+ \xmp@parse{\global\let\xmp@CoverDisplayDate\@this}}
+\newcommand{\pdfx@JournalTitle}[1][]{%
+ \ifx\relax#1\relax\else\gdef\xmp@lang@JournalTitle{#1}\fi
+ \ifx\xmp@PublicationType\@empty\gdef\xmp@PublicationType{journal}\fi
+ \xmp@parse{\global\let\xmp@JournalTitle\@this}}
+
+%%  Uses PRISM Controlled Vocabulary:
+%%    http://prismstandard.org/vocabularies/3.0/aggregationtype.xml
+%%  blog, book, bookazine, catalog, feed, journal, magazine, manual
+%%  newsletter, newspaper, other, report, pamphlet, vook, whitepaper
+%%
+\newcommand{\pdfx@PublicationType}[1][]{%
+ \ifx\relax#1\relax\else\gdef\xmp@lang@PublicationType{#1}\fi
+ \xmp@parse{\global\let\xmp@PublicationType\@this}}
+
 \def\pdfx@localcommands{
- \def\Title{\xmp@parse{\global\let\xmp@Title\@this}}
- \def\Author{\xmp@parse{\global\let\xmp@Author\@this}}
- \def\Keywords{\xmp@parse{\global\let\xmp@Keywords\@this}}
- \def\Subject{\xmp@parse{\global\let\xmp@Subject\@this}}
+ \let\Title\pdfx@Title
+ \let\Author\pdfx@Author
+ \let\Keywords\pdfx@Keywords
+ \let\Subject\pdfx@Subject
+ \let\Language\pdfx@Language
  \def\CreatorTool{\xmp@parse{\global\let\xmp@CreatorTool\@this}}
- \def\Producer{\xmp@parse{\global\let\xmp@Producer\@this}}
+ \let\Producer\pdfx@Producer
  \def\Volume{\xmp@parse{\global\let\xmp@Volume\@this}}
  \def\Issue{\xmp@parse{\global\let\xmp@Issue\@this}}
- \def\CoverDisplayDate{\xmp@parse{\global\let\xmp@CoverDisplayDate\@this}}
+ \let\CoverDisplayDate\pdfx@CoverDisplayDate
  \def\CoverDate{\xmp@parse{\global\let\xmp@CoverDate\@this}}
- \def\Copyright{\xmp@parse{\global\let\xmp@Copyright\@this%
-   \ifx\xmp@Copyrighted\@empty\gdef\xmp@Copyrighted{True}\fi}}
+ \let\Copyright\pdfx@Copyright
  \def\CopyrightURL{\xmp@parse{\global\let\xmp@CopyrightURL\@this%
    \ifx\xmp@Copyrighted\@empty\gdef\xmp@Copyrighted{True}\fi}}
  \def\Copyrighted{\xmp@parse{\global\let\xmp@Copyrighted\@this}}
  \def\Doi{\xmp@parse{\global\let\xmp@Doi\@this}}
+ \def\ISBN{\xmp@parse{\global\let\xmp@ISBN\@this}}
+ \def\URLlink{\xmp@parse{\global\let\xmp@URL\@this}}
  \def\Lastpage{\xmp@parse{\global\let\xmp@Lastpage\@this}}
  \def\Firstpage{\xmp@parse{\global\let\xmp@Firstpage\@this}}
- \def\PublicationType{\xmp@parse{\global\let\xmp@PublicationType\@this}}
- \def\Journaltitle{\xmp@parse{\global\let\xmp@Journaltitle\@this%
-   \ifx\xmp@PublicationType\@empty\gdef\xmp@PublicationType{journal}\fi}}
+ \let\PublicationType\pdfx@PublicationType
+ \let\Journaltitle\pdfx@JournalTitle
  \def\Journalnumber{\xmp@parse{\global\let\xmp@Journalnumber\@this}}
- \def\Publisher{\xmp@parse{\global\let\xmp@Publisher\@this}}
+ \let\Publisher\pdfx@Publisher
+ \let\Coverage\pdfx@Coverage
+ \def\Source{\xmp@parse{\global\let\xmp@Source\@this}}
+ \let\Contributor\pdfx@Contributor
+ \let\Date\pdfx@Date
+ \let\Relation\pdfx@Relation
+ \let\Advisory\pdfx@Advisory
+ \def\BaseURL{\xmp@parse{\global\let\xmp@BaseURL\@this}}
+ \let\Identifier\pdfx@Identifier
+ \let\Nickname\pdfx@Nickname
+ \let\Thumbnails\pdfx@Thumbnails
+ \let\Owner\pdfx@Owner
+ \def\CertificateURL{\xmp@parse{\global\let\xmp@CertificateURL\@this}}
+ \def\MMversionID{\xmp@parse{\global\let\xmpMM@versionID\@this}}
+%% \let\Type\pdfx@Type
 %%
 %% currently unused; for backward compatibility only
- \def\AuthoritativeDomain{\xmp@parse
-   {\global\let\xmp@AuthoritativeDomain\@this}}
+ \let\AuthoritativeDomain\pdfx@AuthoritativeDomain
  \let\Creator\CreatorTool  % for backward compatibility
  \let\Org\Publisher        % for backward compatibility
  \let\WebStatement\CopyrightURL  % for backward compatibility
@@ -504,10 +1031,21 @@
 %%----------------------------------------------------------------------
 %% Markup bindings to be used during XMP generation.
 
-{\obeyspaces\ifpdfx@useactivespaces%
-\xdef\pdfx@sep {</rdf:li>^^J     <rdf:li>}%
-\else\gdef\pdfx@sep{</rdf:li>^^J     <rdf:li>}%
-\fi}
+{%
+ \catcode`\<=12 \catcode`\>=12 \catcode`\/=12 \catcode`\:=12 \catcode`\"=12
+\obeyspaces\ifpdfx@useactivespaces%
+ \gdef\pdfx@sep {\pdfx@check@lang}%
+\else%
+ \gdef\pdfx@sep{\pdfx@check@lang}%
+\fi%
+ \xdef\pdfx@sep@nolang{</rdf:li>^^J     <rdf:li>}%
+ \xdef\pdfx@sep@lang[#1]{</rdf:li>^^J     <rdf:li xml:lang="#1">}%
+}% end of \obeyspaces and \catcode ....
+
+\def\pdfx@check@lang#1{%
+ \ifx[#1\expandafter\@firstoftwo
+ \else\expandafter\@secondoftwo\fi
+ {\pdfx@sep@lang#1}{\pdfx@sep@nolang#1}}
 
 \def\pdfx@xmpmarkup{%
  \pdfx@actives
@@ -580,7 +1118,9 @@
  \fi
  \ifarbxmp \LIIXUmaparabicletters\fi
  \ifarmxmp \LIIXUmaparmenianletters\fi
+ \ifdevxmp\LIIXUmapdevaccents\fi
  \ifgrkxmp \LIIXUmapgreekletters\fi
+ \ifhebxmp \LIIXUmaphebrewletters\fi
 }
 
 %% In case macros are used in XMP Metadata, need a way to map these
@@ -614,6 +1154,12 @@
  \def\sep{; }%
  %\let\sep\pdfx@sep
 %% Note: '\ ', \&, \copyright are already predefined by hyperref.
+%% allow LICRs to expand into PDF strings
+ \def\cf@encoding{PU}%
+ \def\9##1{\ifcase##1\string\0\or\string\1\or\string\2\or\string\3\fi}%
+ \def\8{\string\00}%
+ \def\0{\string\0}\def\1{\string\1}\def\2{\string\2}\def\3{\string\3}%
+ \pdfx@xmpunimarkup
  \the\pdfxsafeforxmp@toks
 }
 
@@ -626,12 +1172,14 @@
 \else
  \def\xmp@Producer{pdfTeX}
 \fi\fi
+\global\let\pdfxProducer\xmp@Producer
 
 \global\let\xmp@CreatorTool\@empty
 \global\let\xmp@Title\@empty
 \global\let\xmp@Author\@empty
 \global\let\xmp@Keywords\@empty
 \global\let\xmp@Subject\@empty
+\global\let\xmp@Language\@empty
 \global\let\xmp@Volume\@empty
 \global\let\xmp@Issue\@empty
 \global\let\xmp@CoverDisplayDate\@empty
@@ -641,41 +1189,67 @@
 \global\let\xmp@CopyrightURL\@empty
 \gdef\xmp@WebStatement{\xmp@CopyrightURL}
 \global\let\xmp@Doi\@empty
+\global\let\xmp@ISBN\@empty
+\global\let\xmp@URL\@empty
 \global\let\xmp@Lastpage\@empty
 \global\let\xmp@Firstpage\@empty
 \global\let\xmp@PublicationType\@empty
 \global\let\xmp@Journaltitle\@empty
 \global\let\xmp@Journalnumber\@empty
+%%\global\let\xmp@Type\@empty
+\global\let\xmp@Contributor\@empty
+\global\let\xmp@Coverage\@empty
+\global\let\xmp@Date\@empty
+\global\let\xmp@Relation\@empty
+\global\let\xmp@Source\@empty
 \global\let\xmp@Publisher\@empty
 \gdef\xmp@Org{\xmp@Publisher}
 \global\let\xmp@AuthoritativeDomain\@empty
+\global\let\xmp@Advisory\@empty
+\global\let\xmp@BaseURL\@empty
+\global\let\xmp@Identifier\@empty
+\global\let\xmp@Nickname\@empty
+\global\let\xmp@Thumbnails\@empty
+\global\let\xmp@Owner\@empty
+\global\let\xmp@CertificateURL\@empty
 
 %%----------------------------------------------------------------------
 %%  Alternative way to get the CreationDate using Lua  for XeTeX
 \ifdefined\pdfcreationdate\else
+ \begingroup  %% ensure correct catcodes, not done by \dospecials
+ \catcode`\:=12 \catcode`\.=12
 \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*}
+ \endgroup
  \ifnum\shellescape=1
-  \begingroup
+  \begingroup  %% ensure correct catcodes when file is read in
+   \catcode`\'=12 \catcode`\.=12 \catcode`\:=12 \catcode`\+=12
    \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
+  \begingroup  %% ensure correct catcodes in the error/warning messages
+  \catcode`\<=12 \catcode`\>=12 \catcode`\"=12 \catcode`\-=12
+  \catcode`\: 12 \catcode`\' 12 \catcode`\= 12
   \ifpdfx@noerr
    \PackageWarning{pdfx}{%
     CreationDate is not properly supported;^^J
     PDF validation may fail. To avoid this problem use:^^J
-     xelatex -shell-escape <filename>^^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 <filename> }
+     xelatex -shell-escape  -output-driver="xdvipdfmx -z 0" <filename> }
   \fi
+  %% Using a constant date, to allow processing to finish smoothly.
+  \edef\x{\endgroup
+   \def\noexpand\pdfcreationdate{\string D:20181028075445+10'00'}}%
+   \x
  \fi
 \fi
 
@@ -728,29 +1302,69 @@
 %%----------------------------------------------------------------------
 %% load  xcolor  before  hyperref  to get the link colors correct
 %%
+\PassOptionsToPackage{nosetpagesize}{color}
+\PassOptionsToPackage{nosetpagesize}{graphics}
+\@ifpackageloaded{xcolor}{%
+ % Beamer will have already loaded  xcolor
+ % need to understand what options it used
+}{
 \ifpdfx@x
  \RequirePackage[cmyk,hyperref]{xcolor}
 \else
-%% \RequirePackage[rgb,hyperref]{xcolor}
+ \RequirePackage[rgb,hyperref]{xcolor}
 \fi
+}%
+
+%%  loading  puenc.def  will kill a lot of what  mathtext.sty  established
+\@ifpackageloaded{mathtext}{%
+ \PackageWarningNoLine{pdfx}{pdfx.sty  and hyperref.sty should be loaded^^J
+  before mathtext.sty , otherwise text symbols may not show in math mode.}%
+}{}
+
+\newif\ifpdfx@hluatex
+\IfFileExists{hluatex.def}{\pdfx@hluatextrue}{\pdfx@hluatexfalse}
 
 %% the "pdftex" option seems to work fine with LuaTeX
+\def\pdfx@luatest{\ifpdfx@hluatex luatex\else pdftex \fi}
 
 %% Hyperref options for PDF/X
 \edef\pdfx@pdfX@opts@pdftex{%
-  draft,pdftex,pdfpagemode=UseNone,bookmarks=false,%
-    pdfversion=1.\thepdfminorversion,pdfstartview=}
+   draft,pdftex,pdfpagemode=UseNone,bookmarks=false,%
+   pdfversion=1.\thepdfminorversion,pdfstartview=}
 \edef\pdfx@pdfX@opts@xetex{%
-  draft,xetex,pdfpagemode=UseNone,bookmarks=false,%
-  pdfversion=1.\thepdfminorversion,pdfstartview=}
-\edef\pdfx@pdfX@opts@luatex{%
-  draft,luatex,pdfpagemode=UseNone,bookmarks=false,%
-  pdfversion=1.\thepdfminorversion,pdfstartview=}
+   draft,xetex,pdfpagemode=UseNone,bookmarks=false,%
+   pdfversion=1.\thepdfminorversion,pdfstartview=}
+ \edef\pdfx@pdfX@opts@luatex{%
+   draft,\pdfx@luatest,pdfpagemode=UseNone,bookmarks=false,%
+   pdfversion=1.\thepdfminorversion,pdfstartview=}%
+
+\newif\ifpdfx@hyperrefloaded
+\expandafter\ifx\csname ifHy@pdfa\endcsname\relax\else\pdfx@hyperrefloadedtrue\fi
 
 %% Hyperref options for PDF/A and PDF/E
-\edef\pdfx@pdfAE@opts@pdftex{pdftex,pdfa,pdfversion=1.\thepdfminorversion}%
-\edef\pdfx@pdfAE@opts@xetex{xetex,pdfa,pdfversion=1.\thepdfminorversion}%
-\edef\pdfx@pdfAE@opts@luatex{luatex,pdfa,pdfversion=1.\thepdfminorversion}%
+\newtoks\pdfx@tmptoks
+\pdfx@tmptoks{%
+\ifHy@pdfa
+   \edef\pdfx@pdfAE@opts@pdftex{pdftex}%
+   \edef\pdfx@pdfAE@opts@xetex{xetex,pdfversion=1.\thepdfminorversion}%
+   \edef\pdfx@pdfAE@opts@luatex{\pdfx@luatest,pdfversion=1.\thepdfminorversion}%
+   \edef\pdfx@pdfAE@opts@pdfmark{pdfmark,pdfversion=1.\thepdfminorversion}%
+  \else
+   \edef\pdfx@pdfAE@opts@pdftex{pdftex,pdfa}%
+   \edef\pdfx@pdfAE@opts@xetex{xetex,pdfa,pdfversion=1.\thepdfminorversion}%
+   \edef\pdfx@pdfAE@opts@luatex{\pdfx@luatest,pdfa,pdfversion=1.\thepdfminorversion}%
+   \edef\pdfx@pdfAE@opts@pdfmark{pdfmark,pdfa,pdfversion=1.\thepdfminorversion}%
+  \fi
+}
+\ifpdfx@hyperrefloaded
+ \the\pdfx@tmptoks\relax
+\else
+ \edef\pdfx@pdfAE@opts@pdftex{pdftex,pdfa}%
+ \edef\pdfx@pdfAE@opts@xetex{xetex,pdfa,pdfversion=1.\thepdfminorversion}%
+ \edef\pdfx@pdfAE@opts@luatex{\pdfx@luatest,pdfa,pdfversion=1.\thepdfminorversion}%
+ \edef\pdfx@pdfAE@opts@pdfmark{pdfmark,pdfa,pdfversion=1.\thepdfminorversion}%
+\fi
+\pdfx@tmptoks{}%
 
 \ifpdfx@x
  \@ifpackageloaded{hyperref}{%
@@ -823,6 +1437,7 @@
 \fi
 
 \newif\ifpdfx@cmyk
+\newif\ifpdfx@custom
 \ifpdfx@x   %  PDF/X  normally needs a CMYK color profile for printing
  \global\pdfx@cmyktrue
 \fi
@@ -870,21 +1485,26 @@
   \catcode`\_ 11\relax\catcode`\& 11\relax\catcode`\~ 11\relax
   \catcode`\% 11\relax
   \edef\({\string\(}\edef\){\string\)}%
-  \pdfx@externalprofile}
+  \ifno@iccprofile
+   \expandafter\pdfx@externalprofile
+   \else
+    \expandafter\pdfx@externalprofile@gobble
+   \fi
+  }
 %%
 %%
 \def\pdfx@setRGBcolorprofiledir#1{%
- \gdef\pdfx@RGBcolorprofiledir{#1}%
+ \xdef\pdfx@RGBcolorprofiledir{#1}%
 }
 \def\pdfx@setCMYKcolorprofiledir#1{%
- \gdef\pdfx@CMYKcolorprofiledir{#1}%
+ \xdef\pdfx@CMYKcolorprofiledir{#1}%
 }
 \pdfx@setRGBcolorprofiledir{}
 \pdfx@setCMYKcolorprofiledir{}
 
 %% This does indeed work!  Use it in  .xmpdata  files
-\providecommand{\MacOSColordir}%
-  {/System/Library/ColorSync/Profiles/}
+\providecommand{\MacOSColordir}{/System/Library/ColorSync/Profiles/}
+\providecommand{\MacOSLibraryColordir}{/Library/ColorSync/Profiles/}
 \providecommand{\AdobeMacOSdir}%
   {/Library/Application Support/Adobe/Color/Profiles/Recommended/}
 \edef\pdfx@tmp{C:\string\Windows\string\System32\string\Spool%
@@ -900,7 +1520,8 @@
 \let\pdfxSetColorProfileDir\pdfxSetCMYKcolorProfileDir
 %%
 \def\pdfx@setrgbprofile#1#2#3#4{%
- \xdef\pdfx@rgb@profile{\pdfx@RGBcolorprofiledir#1}%  valid file name
+ \xdef\pdfx@rgb@profile{\pdfx@RGBcolorprofiledir#1}%  valid file path/name
+ \xdef\pdfx@rgb@profilename{#1}%  valid file name
  \gdef\pdfx@rgb@identifier{#2}%
  \gdef\pdfx@rgb@info{#3}%
  \pdfstringdef\pdfx@rgb@registry{#4}%  valid URL
@@ -909,7 +1530,8 @@
  }%  closes-off  \setRGBcolorprofile
 %%
 \def\pdfx@setcmykprofile#1#2#3#4{%
- \xdef\pdfx@cmyk@profile{\pdfx@CMYKcolorprofiledir#1}%  valid file name
+ \xdef\pdfx@cmyk@profile{\pdfx@CMYKcolorprofiledir#1}%  valid file path/name
+ \xdef\pdfx@cmyk@profilename{#1}%  valid file name
 %% \expandafter\gdef\expandafter\pdfx@cmyk@profile\expandafter
 %%    {\pdfx@colorprofiledir#1}%  valid file name
  \gdef\pdfx@cmyk@intent{#2}%
@@ -920,7 +1542,28 @@
 %% \pdfstringdef\pdfx@cmyk@registry{#4}%  valid URL
  \endgroup
  \global\pdfx@cmyktrue
- }%  closes-off  \setCMYKcolorprofile
+ }%  closes-off  \setcmykcolorprofile
+%%
+\def\setCUSTOMcolorprofile{%
+ \begingroup
+  \catcode`\_ 11\relax\catcode`\& 11\relax\catcode`\~ 11\relax
+  \catcode`\% 11\relax
+  \edef\({\string\(}\edef\){\string\)}%
+  \pdfx@setcustomprofile
+}
+\def\pdfx@setcustomprofile#1#2#3#4#5#6#7#8{%
+ \xdef\pdfx@customcolorprofiledir{#2}% valid directory location
+ \xdef\pdfx@custom@profile{#1}%  valid file name
+ \gdef\pdfx@custom@identifier{#3}%
+ \gdef\pdfx@custom@registry{#4}%
+ \gdef\pdfx@custom@numcolors{#5}% num-colors specifier
+ \gdef\pdfx@iccversion{#6}%  Hex string for /ICCVersion < ... >
+ \gdef\pdfx@custom@colornames{#7}%
+ \gdef\pdfx@profile@checksum{#8}%  Hex string for /CheckSum < ... >
+\endgroup
+ \global\pdfx@cmykfalse
+ \global\pdfx@customtrue
+ }%  closes-off  \pdfx@setcustomprofile
 %%
 \def\pdfx@setgrayprofile#1#2#3#4{%
  \gdef\pdfx@gray@profile{#1}%  valid file name
@@ -940,8 +1583,13 @@
  \gdef\pdfx@cmyk@info{#8}%  for /Info
  \gdef\pdfx@profile@checksum{#9}%  Hex string for /CheckSum < ... >
  \endgroup}%  closes-off  \setEXTERNALprofile
+\def\pdfx@externalprofile@gobble#1#2#3#4#5#6#7#8#9{%
+  \PackageError{pdfx}{Wrong option for using an External Color profile}%
+   {Use one of the options: x-4p , x-4p08 , x-4p10 or  x-5pg .}%
+ \endgroup}
 %%
 %% default color profiles
+
 {\catcode`\_ 12 \catcode`\& 12 \catcode`\~ 12
  \gdef\pdfx@xprofile@cmykdefault{coated_FOGRA39L_argl.icc}
  \gdef\pdfx@aprofile@rgbdefault{sRGB_IEC61966-2-1_black_scaled.icc}
@@ -981,9 +1629,43 @@
 %% software for any purpose.
 %%
 %%----------------------------------------------------------------------
-{\catcode`\| 14 \catcode`\% 12 \catcode`\_ 12
+
+\newif\ifpdfx@tryoldprofiles
+
+%%  The  colorprofiles package was added to  TeXLive  in October 2018.
+%%  It allows the default Color Profiles to be maintained independent
+%%  of the  pdfx  package.
+%%  In particular  sRGB_IEC61966-2-1_black_scaled.icc  is no longer
+%%  distributed with TeXLive 2018 and later.
+%%  Older versions still have this file.
+%%
+\IfFileExists{colorprofiles.tex}{%
+  \RequirePackage{colorprofiles}[2018/11/01]%
+  \ifx\colorpro@rgb@profile\relax
+    \expandafter\pdfx@tryoldprofilestrue
+   \else
+    \begingroup %%  \endgroup occurs within the macro expansion
+     \pdfx@setrgbprofile{\colorpro@rgb@profile
+     }{\colorpro@rgb@identifier
+     }{\colorpro@rgb@info
+     }{\colorpro@rgb@registry
+     }%
+    \begingroup %%  \endgroup occurs within the macro expansion
+    \pdfx@setcmykprofile{\colorpro@cmyk@profile
+     }{\colorpro@cmyk@intent
+     }{\colorpro@cmyk@identifier
+     }{\colorpro@cmyk@registry
+     }%
+    \expandafter\pdfx@tryoldprofilesfalse
+   \fi
+}{\pdfx@tryoldprofilestrue}
+
+{\catcode`\| 14 \catcode`\% 12 \catcode`\_ 12 \catcode`\: 12
+ \catcode`\. 12 \catcode`\- 12 \catcode`\/ 12
  \edef\@bchar{\expandafter\@gobble\string\\}|
  \edef\({\string\(}\edef\){\string\)}|
+\ifpdfx@tryoldprofiles
+ || this will be used by TeXLive installations up to 2017.
  \begingroup | \endgroup occurs within the macro expansion
 \expandafter\pdfx@setrgbprofile\expandafter
  {sRGB_IEC61966-2-1_black_scaled.icc}|
@@ -995,6 +1677,7 @@
  {Coated FOGRA39}|
  {FOGRA39 \string\(ISO Coated v2 300%\space \string\(ECI\string\)\string\)}|
  {http://www.argyllcms.com/}|{http://www.color.org}|
+\fi  ||  end of   \ifpdfx@tryoldprofiles
  \begingroup | \endgroup occurs within the macro expansion
 \pdfx@setgrayprofile{Gray_linear.icc}|
  {}|
@@ -1010,6 +1693,7 @@
    {Coated FOGRA39 \(ISO 12647-2:2004\)}{74FF62F330BF0DBE4495B5720542D511}|
 \fi
 }% end of \catcode
+
 %%
 %%----------------------------------------------------------------------
 %% License for the file  coated_FOGRA39L_argl.icc :
@@ -1039,6 +1723,7 @@
 %%----------------------------------------------------------------------
 
 \newif\ifexternalICCprofiles
+\newif\ifpdfx@noXMPdata
 
 \begingroup
 %% override unneeded color-profile specifier
@@ -1077,70 +1762,104 @@
  \fi\fi
  \makeatletter
  \pdfx@localcommands
-%%
+%% Do this in a box, so any stray characters don't get into TeX's lists.
+\setbox0\hbox{%
  \InputIfFileExists{\jobname.xmpdata}%
   {\typeout{** pdfx: Metadata file \jobname.xmpdata  read successfully.}}%
   {\typeout{** pdfx: No file  \jobname.xmpdata .
-    Metadata will be incomplete!}}
+    Metadata will be incomplete!}\aftergroup\pdfx@noXMPdatatrue}}
 \endgroup
+%% ----------------------------------------------------------------------
+
+\def\pdfx@LanguageSpec{}
+\def\pdfx@mainLanguage{en-US}%  absolute default
+\def\pdfx@checkfor@sep#1#2\sep#3\pdfx@endparse{\def#1{#2}}
+\ifx\@empty\xmp@Language\else
+ \expandafter\pdfx@checkfor@sep\expandafter\pdfx@mainLanguage\xmp@Language
+  \sep\pdfx@endparse
+\fi
+\edef\pdfx@LanguageSpec{/Lang (\pdfx@mainLanguage)}
 
 %% ----------------------------------------------------------------------
 \begingroup
-\ifpdfx@x   %  PDF/X  needs a CMYK or RGB color profile for printing
+ \catcode`\_ 12 \catcode`\" 12 \catcode`\' 12
+ \catcode`\< 12 \catcode`\> 12 \catcode`\/ 12 \catcode`\[ 12 \catcode`\] 12
  \edef\@pctchar{\expandafter\@gobble\string\%}
  \edef\@bchar{\expandafter\@gobble\string\\}
  \edef\0{\string\0}
  \edef\({\string\(}
  \edef\){\string\)}
- \catcode`\_ 12
+%%
+ \def\pdfx@outcatalog@dict{%
+  \pdfx@LanguageSpec
+  /ViewerPreferences <</DisplayDocTitle true >>
+  /OutputIntents \pdfx@outintents % needs appropriate expansion
+ }%
+\ifpdfx@x   %  PDF/X  needs a CMYK or RGB color profile for printing
  \ifno@iccprofile %  PDF/X-4p and PDF/X-5pg
-  \ifxetex
-   \special{pdf:obj @colorURL <</FS/URL/F(\pdfx@colorURL)>>}%
-   \special{pdf:obj @colorprofile <<%
+%%
+%% URL and metadata for the desired external Color Profile
+%%
+  \edef\pdfx@colorURL@dict{<</FS/URL/F(\pdfx@colorURL)>>}
+  \def\pdfx@colorprofile@dict{<< %
      /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)>>}%
+     /URLs [\OBJ@URLs] >>
+  }
+%% How to specify the PDF objects with different drivers
+  \ifxetex
+   \def\OBJ@URLs{ @colorURL }%
+   \def\OBJ@ICC{ @colorprofile }%
+   \immediate\special{pdf:obj \OBJ@URLs \pdfx@colorURL@dict }%
+   \immediate\special{pdf:obj \OBJ@ICC \pdfx@colorprofile@dict }%
+  \else %  pdfTeX & LuaTeX
+   \immediate\pdfobj{\pdfx@colorURL@dict}%
    \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 ]
-    >>} %
+   \immediate\pdfobj{\pdfx@colorprofile@dict}%
    \edef\OBJ@ICC{\the\pdflastobj\space 0 R}%
   \fi
-  \pdfcatalog{%
-   /OutputIntents [ <<
-   /Type/OutputIntent
-   /S/GTS_PDFX
-   /OutputCondition (\pdfx@cmyk@intent)%
-   /OutputConditionIdentifier (\pdfx@cmyk@identifier)%
-   /Info(\pdfx@cmyk@intent)%
-   /RegistryName(\pdfx@cmyk@registry)
+%%  Output Intent dictionary, with object reference
+  \edef\pdfx@outintent@dict{%
+    /Type/OutputIntent
+    /S/GTS_PDFX^^J
+    /OutputCondition (\pdfx@cmyk@intent)^^J
+    /OutputConditionIdentifier (\pdfx@cmyk@identifier)^^J
+    /Info(\pdfx@cmyk@intent)^^J
+    /RegistryName(\pdfx@cmyk@registry)^^J
 %% extra dictionary required for  PDF/X-4p and PDF/X-5pg
-   /DestOutputProfileRef \OBJ@ICC
-   >> ]}%
+    /DestOutputProfileRef \OBJ@ICC
+  }%
 %%
  \else  %  PDF/X-1 , PDF/X-1a , PDF/X-3 , PDF/X-4 , PDF/X-5g
 %%
   \ifpdfx@cmyk
    \IfFileExists{"\pdfx@cmyk@profile"}{%
   %  embedded CMYK color profile
+  %%
+  %%  Output Intent dictionary, with object reference
+  \def\pdfx@outintent@dict{%
+    /Type/OutputIntent
+    /S/GTS_PDFX^^J
+    /OutputCondition (\pdfx@cmyk@intent)^^J
+    /OutputConditionIdentifier (\pdfx@cmyk@identifier)^^J
+    /Info(\pdfx@cmyk@intent)^^J
+    /RegistryName(\pdfx@cmyk@registry)
+    /DestOutputProfile \OBJ@CMYK
+   }%
+  \def\pdfx@numcoords{/N 4}%
+%%
   \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}%
+   \immediate\special{%
+     pdf:fstream \OBJ@CMYK (\pdfx@cmyk@profile) <<\pdfx@numcoords >>}%
+  \else % pdfTeX
+   \immediate\pdfobj stream attr{\pdfx@numcoords} file {\pdfx@cmyk@profile}%
    \edef\OBJ@CMYK{\the\pdflastobj\space 0 R}%
   \fi
   \pdfcatalog{%
+   \pdfx@LanguageSpec
    /OutputIntents [ <<
    /Type/OutputIntent
    /S/GTS_PDFX
@@ -1151,9 +1870,63 @@
    /DestOutputProfile \OBJ@CMYK
    >> ]}%
   }{%
-   \errmessage{No color profile \pdfx@cmyk@profile\ found
+   \PackageError{pdfx}{No color profile \pdfx@cmyk@profilename\space found
      to use for CMYK printing colors.}%
+     {Is this the correct directory: \pdfx@CMYKcolorprofiledir\space  ?}%
+  }% end of \IfFileExists for CMYK
+  \else\ifpdfx@custom
+%%  allow Custom profile with PDF/X-5n
+   \IfFileExists{"\pdfx@customcolorprofiledir\pdfx@custom@profile"}{%
+%%  embedded Custom color profile
+%%
+  %%  Output Intent dictionary, with object reference
+  \def\pdfx@outintent@dict{%
+    /Type/OutputIntent
+    /S/GTS_PDFX^^J
+    /OutputConditionIdentifier (Custom)^^J
+    /OutputCondition (\pdfx@custom@identifier)^^J
+    /Info(\pdfx@custom@profile)^^J
+    /RegistryName(\pdfx@custom@registry)
+    /Registry(\pdfx@custom@registry)
+    /DestOutputProfileRef \OBJ@CustomDir
+   }%
+ \def\OBJ@CustomDir{<<
+   \pdfx@numcoords^^J
+    /URLs [ << /Type /Filespec ^^J/EF \OBJ@CustomFile^^J
+     /F (\pdfx@custom@profile) /UF (\pdfx@custom@profile)  >>]^^J
+    >>}
+%% need more attributes:
+  \def\pdfx@numcoords{%
+    /CheckSum <\pdfx@profile@checksum>^^J%
+    /ICCVersion <\pdfx@iccversion>%
+    /ProfileName (\pdfx@custom@profile)^^J%
+    /ProfileCS (\pdfx@custom@numcolors)^^J%
+    /ColorantTable [\pdfx@custom@colornames]
+   }%
+  \def\pdfx@custom@filespec{%
+      /Type /EmbeddedFile >>^^J
+      /Subtype (application/vnd.iccprofile )
   }%
+%%
+  \ifxetex
+   \def\OBJ@CustomFile{@colorprofile}%
+   \immediate\special{pdf:fstream \OBJ@CustomFile
+     (\pdfx@customcolorprofiledir\pdfx@custom@profile) <<\pdfx@custom@filespec >>}%
+  \else % pdfTeX
+   \immediate\pdfobj stream attr{\pdfx@custom@filespec} file %
+     {\pdfx@customcolorprofiledir\pdfx@custom@profile}%
+   \edef\OBJ@CustomFile{\the\pdflastobj\space 0 R}%
+  \fi
+  \pdfcatalog{%
+   \pdfx@LanguageSpec
+   /OutputIntents [ << \pdfx@outintent@dict >>]}%
+  }{%
+    \PackageError{pdfx}%
+     {No color profile \pdfx@custom@profile\space found to use for Custom printing colors.}%
+     {Is this the correct directory: \pdfx@customcolorprofiledir\space  ?}%
+  }% end of \IfFileExists for Custom
+  \global\pdfx@cmyktrue  % for TeX coloring
+%%
   \else  % allow RGB profile with PDF/X   ???
    \ifpdfx@noerr
     \PackageWarning{pdfx}{PDF/X normally requires a CMYK color profile.^^J
@@ -1162,14 +1935,25 @@
     \PackageError{pdfx}{PDF/X normally requires a CMYK color profile.}%
       {To use RGB ensure profile is of type 'prtr' not 'mntr'.^^J^^J}%
    \fi
+   %  embedded RGB color profile
+   %%
+   %%  Output Intent dictionary, with object reference
+   \def\pdfx@outintent@dict{%
+     /Type /OutputIntent
+     /S/GTS_PDFX^^J
+     /OutputConditionIdentifier (\pdfx@rgb@identifier)^^J
+     /DestOutputProfile \OBJ@RGB^^J
+     /Info(\pdfx@rgb@info)^^J
+     /RegistryName(\pdfx@rgb@registry)
+   }%
    \IfFileExists{"\pdfx@rgb@profile"}{%
+    \def\pdfx@numcoords{/N 3 /Alternate/DeviceRGB}
     \ifxetex
-     \immediate\special{pdf:fstream @colorprofile (\pdfx@rgb@profile) <<
-       /N 3 /Alternate/DeviceRGB >>}
+     \immediate\special{%
+      pdf:fstream @colorprofile (\pdfx@rgb@profile) << \pdfx@numcoords >>}
      \def\OBJ@RGB{@colorprofile}%
     \else
-     \immediate\pdfobj stream attr{/N 3^^J/Alternate/DeviceRGB}
-       file{\pdfx@rgb@profile}%
+     \immediate\pdfobj stream attr{\pdfx@numcoords} file{\pdfx@rgb@profile}%
      \edef\OBJ@RGB{\the\pdflastobj\space 0 R}%
     \fi
     \edef\pdfx@outintent@dict{%
@@ -1181,90 +1965,65 @@
       /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
-    }%
+     \def\OBJ@RGB{ @colorprofile }%
+     \immediate\special{%
+       pdf:fstream @colorprofile (\pdfx@rgb@profile) <<\pdfx@numcoords >>}
+    \else  %%     pdfTeX or LuaTeX
+      \immediate\pdfobj stream attr{\pdfx@numcoords} file{\pdfx@rgb@profile}%
+      \edef\OBJ@RGB{\the\pdflastobj\space 0 R}%
+     \fi
    }{%
-    \errmessage{No color profile found to use for RGB screen colors.}%
-   }%
+    \PackageError{pdfx}%
+     {No color profile \pdfx@rgb@profilename\space found to use for RGB screen colors.}%
+     {Is this the correct directory: \pdfx@RGBcolorprofiledir\space  ?}%
+   }% end of \IfFileExists for RGB
+   \fi % end of \ifpdfx@custom
   \fi % end of \ifpdfx@cmyk
  \fi % end of  \ifno@iccprofile
+%%  end of PDF/X
 \else
 %%  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"}{%
+   \def\pdfx@numcoords{/N 4}
   %  embedded CMYK color profile
-%% 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
+   \ifxetex
+    \def\OBJ@CMYK{@colorprofile}%
+    \special{pdf:fstream @colorprofile (\pdfx@cmyk@profile) <<\pdfx@numcoords >>}
+   \else  %% pdfTeX or LuaTeX
+    \immediate\pdfobj stream attr{\pdfx@numcoords} 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
     /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.}%
- }%
+   \PackageError{pdfx}{No color profile \pdfx@cmyk@profilename\space found
+     to use for CMYK printing colors.}%
+     {Is this the correct directory: \pdfx@CMYKcolorprofiledir\space  ?}%
+ }% end of \IfFileExists for CMYK
  \else
 %%  PDF/A and PDF/E  usually need an RGB color profile for on-screen rendering
  \global\pdfx@cmykfalse
- \IfFileExists{"\pdfx@rgb@profile"}{%
-%% How to support XeTeX here ?
+  \expandafter\IfFileExists\expandafter{\pdfx@rgb@profile}{%
+   \def\pdfx@numcoords{/N 3 /Alternate/DeviceRGB}
   \ifxetex
-   \immediate\special{pdf:fstream @colorprofile (\pdfx@rgb@profile) <<
-     /N 3 /Alternate/DeviceRGB >>}
-   \def\OBJ@RGB{@colorprofile}%
+    \def\OBJ@RGB{ @colorprofile }%
+    \immediate\special{pdf:fstream @colorprofile (\pdfx@rgb@profile) <<\pdfx@numcoords >>}
   \else
-   \immediate\pdfobj stream attr{/N 3^^J/Alternate/DeviceRGB}
-     file{\pdfx@rgb@profile}%
-   \edef\OBJ@RGB{\the\pdflastobj\space 0 R}%
+    \immediate\pdfobj stream attr{\pdfx@numcoords} file{\pdfx@rgb@profile}%
+    \edef\OBJ@RGB{\the\pdflastobj\space 0 R}%
   \fi
   \edef\pdfx@outintent@dict{%
     /Type /OutputIntent
@@ -1278,29 +2037,37 @@
     /Info(\pdfx@rgb@info)
     /RegistryName(\pdfx@rgb@registry)
   }%
+ }{%
+   \PackageError{pdfx}%
+    {No color profile \pdfx@rgb@profilename\space found to use for RGB screen colors.}%
+    {Is this the correct directory: \pdfx@RGBcolorprofiledir\space  ?}%
+ }% end of \IfFileExists for RGB
+ \fi % end of ifx  for PDF/A or PDF/E
+\fi % end of  ifpdfx@x
+%%
+ \expandafter\ifx\csname pdfx@outintent@dict\endcsname\relax
+ \else
+%%
+%% build the OutputIntent array
+%%
   \ifxetex
-   \special{pdf:obj @outintent@dict << \pdfx@outintent@dict >>}
-   \edef\pdfx@outintent@dict{ @outintent@dict }%
+   \def\pdfx@outintents{ @outintentsarray }%
+   \def\pdfx@outintentref{ @outintent@dict }%
+   \immediate\special{pdf:obj \pdfx@outintentref << \pdfx@outintent@dict >>}
+   \immediate\special{pdf:obj \pdfx@outintents [ ]}%
+   \immediate\special{pdf:put \pdfx@outintents \pdfx@outintentref }%
   \else
-%%  pdfTeX
+   \immediate\pdfobj{<<\pdfx@outintent@dict>>}%
+   \edef\pdfx@outintents{[\the\pdflastobj\space 0 R]}%
   \fi
-  \ifxetex
-   \immediate\special{pdf:obj @outintentsarray [ ]}%
-   \immediate\special{pdf:put @outintentsarray \pdfx@outintent@dict}%
-   \def\pdfx@outintents{@outintentsarray}%
+%%
+%% make the Catalog entry, if not already done
+%%
+  \ifx\pdfx@outcatalog@dict\relax
   \else
-   \immediate\pdfobj{<<\pdfx@outintent@dict>>}
-   \edef\pdfx@outintents{[\the\pdflastobj\space 0 R]}%
+   \pdfcatalog{\pdfx@outcatalog@dict}%
   \fi
-  \pdfcatalog{%
-   /ViewerPreferences <</DisplayDocTitle true >>
-   /OutputIntents \pdfx@outintents
-  }%
- }{%
-  \errmessage{No color profile found to use for RGB screen colors.}%
- }%
- \fi % end of \ifx
-\fi % end of  \ifpdfx@x
+\fi  % end of  OutputIntent array and Catalog entry
 \endgroup
 
 %% ----------------------------------------------------------------------
@@ -1320,9 +2087,10 @@
  \fi\fi
  \makeatletter
  \IfFileExists{\pdfx@encodingfile}{%
-%%  \def\cf@encoding{U}\fontencoding{U}%
   \def\cf@encoding{L8U}\fontencoding{L8U}%
  }{}%
+ \let\protect\@typeset@protect
+ \pdfx@xmpmarkup %%  !!!!! no longer needed
 %% \xdef\xmp@@Author{\xmp@Author}% no need to expand
  \global\let\xmp@@Author\xmp@Author
  \def\sep{; }%  expand to replace \sep   !!!  no longer needed
@@ -1405,7 +2173,7 @@
 \newif\ifpdf@activechars
 {\ifnum\catcode`^^c0 = 13\relax \aftergroup\pdf@activecharstrue\fi}%
 %%
-%% normally not used with XeTeX
+%% normally not used with XeTeX or LuaTeX
 %%
 
 \ifpdf@activechars
@@ -1466,54 +2234,218 @@
 %% ----------------------------------------------------------------------
 %% detect when \sep is used for multiple authors
 %% then suppress the /Author field in PDF /Info
-\newif\ifpdfx@sepinAuthor
+\newif\ifpdfx@sep@infield@
 \let\pdfx@endparse\relax
 \def\pdfx@parseforsep#1\sep#2\pdfx@endparse{%
- \ifx\relax#2\relax\else\pdfx@sepinAuthortrue\fi
+ \pdfx@sep@infield@false
+ \ifx\relax#2\relax\else\pdfx@sep@infield@true\fi
+}
+
+\begingroup
+ \let\CATCODE\catcode
+ \let\ENDGROUP\endgroup
+ \let\GDEF\gdef
+ \CATCODE`\m 12 \CATCODE`\a 12 \CATCODE`\c 12 \CATCODE`\r 12 \CATCODE`\o 12
+ \CATCODE`\: 12 \CATCODE`\- 12 \CATCODE`\> 12
+ \GDEF\pdfx@DOSTRIP@MACRO macro:->#1\@{#1}%
+\ENDGROUP
+\def\pdfx@strip@macro#1{%
+  \expandafter\edef\expandafter#1\expandafter{%
+    \expandafter\pdfx@DOSTRIP@MACRO\meaning#1\@}%
 }
 
 %% 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
+%% These PDF strings are actually not always 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!
 %%
+%% But some PDF readers don't support XMP, so it is nice to have
+%%  /Info fields, when this can be done reliably.
+%%
 \begingroup
+ \RequirePackage{stringenc}%
+ \expandafter\ifx\csname pdf@escapehex\endcsname\relax
+  \PackageWarning{pdfx}{%
+   Missing an implementation of \string\pdf@escapehex ^^J
+   Translated Metadata cannot be generated as PDF strings.^^J}%
+  \def\pdfx@GeneratePdfString#1#2{}%
+  \def\pdfx@ConvertUTFtoBE#1#2{}%
+ \else
+  \def\pdfx@GeneratePdfString#1#2{%
+   % converts a UTF-8 string to UTF-16be
+   \StringEncodingConvert{#1}{#2}{utf8}{utf16be}%
+   \xdef#1{\string\376\string\377\pdfescapestring{#1}}%
+  }%
+  \def\pdfx@ConvertUTFtoBE#1#2{%
+   \setbox0=\hbox{% catch any rubbish escaping to the MVL
+    \def\cf@encoding{L8U}\fontencoding{L8U}%
+    \ifluatex
+     \let\pdfescapestring\luaescapestring
+    \else\ifxetex\else
+     \inputencoding{8bit}%
+    \fi\fi
+%%    \pdfx@xmpmarkup %% don't want some things
+    \pdfx@xmpunimarkup
+    \let\backslash\textbackslash
+    \edef\pdfx@temp{#2}% ensure XMP expands to UTF8
+    \pdfx@GeneratePdfString{#1}{\pdfx@temp}%
+   }%
+  }%
+ \fi
  \pdfx@pdfmarkup
- \global\let\pdfx@Title\@empty
- \global\let\pdfx@Subject\@empty
- \global\let\pdfx@Keywords\@empty
- \ifpdfx@nopdfinfo\else
-  \pdfx@topdfstring\pdfx@Title\xmp@Title
+ \global\let\pdfx@pdfAuthor\@empty
+ \global\let\pdfx@pdfTitle\@empty
+ \global\let\pdfx@pdfSubject\@empty
+ \global\let\pdfx@pdfKeywords\@empty
+ \ifpdfx@nopdfinfo  %  transliterated strings present
+%% RRM: this may still work with parser macros   ???
+ \ifluatex
+  %%  \pdf@escapehex   gets it wrong!!
+  %%   Is there a better way ?
+ \else
+  \pdfx@ConvertUTFtoBE\pdfx@pdfTitle\xmp@Title
+  \pdfx@ConvertUTFtoBE\pdfx@pdfSubject\xmp@Subject
+ \fi
+\else
+  \pdfx@topdfstring\pdfx@pdfTitle\xmp@Title
   \ifpdfx@e\else\ifpdfx@x\else
-   \pdfx@topdfstring\pdfx@Subject\xmp@Subject
+   \pdfx@topdfstring\pdfx@pdfSubject\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
+%%  \pdfescapestring  needed
+ \expandafter\ifx\csname pdfescapestring\endcsname\relax
+  \else
+    \expandafter\ifx\expandafter\relax\xmp@Author\relax
+    \else
+%%  check for multiple authors with parser macro
+     \expandafter\pdfx@parseforsep\xmp@Author\sep\pdfx@endparse
+     \ifpdfx@sep@infield@
+     \else
+      \pdfx@ConvertUTFtoBE{\pdfx@pdfAuthor}{\xmp@Author}%
+     \fi %% end of  \ifpdfx@sep@infield@
+    \fi  %%  end of  \xmp@Author  test
+    \expandafter\ifx\expandafter\relax\xmp@Keywords\relax
+    \else
+%%  check for multiple keywords with parser macro
+     \expandafter\pdfx@parseforsep\xmp@Keywords\sep\pdfx@endparse
+     \ifpdfx@sep@infield@\else
+      \ifluatex\else
+      \pdfx@ConvertUTFtoBE{\pdfx@pdfKeywords}{\xmp@Keywords}%
+     \fi
+     \fi %% end of  \ifpdfx@sep@infield@
+    \fi  %%  end of  \xmp@Keywords  test
+%%
+  \fi  %%  end of \pdfescapestring  test
 \endgroup
 
-%% How to support XeTeX here ?
-\ifxetex\else
+%% Affects CMap creation for certain fonts, according to glyph names
+%%  How to support XeTeX here ?
+%%  Maybe it's best to be using an updated  mmap.sty  ?
+\ifxetex
+\else
  \input glyphtounicode.tex
  \input glyphtounicode-cmr.tex
+ \input glyphtounicode-ntx.tex
  \pdfgentounicode=1
- \ifgrkLGRxmp
-  \pdfglyphtounicode{internalchar2}{200D}%
- \fi
 \fi
+\ifgrkLGRxmp
+ \ifxetex\else
+  \pdfglyphtounicode{internalchar2}{200D}%
+\fi \fi
+
+%% patch to place accents *after* the base character, rather than before
+%%  based on coding from  mmap.sty  by RRM
+\newif\ifPDFX@inaccent
+\let\LTX@add@accent\add@accent
+\def\PDFX@add@accent#1#2{%
+ \hmode@bgroup
+  \let \hmode@start@before@group \@firstofone
+  \setbox\@tempboxa\hbox{\PDFX@inaccenttrue
+   #2\global\mathchardef\accent@spacefactor\spacefactor}%
+  #2\kern-\wd\@tempboxa
+%%  \ifdim\ht\@tempboxa>1ex\relax
+   \dimen@=\ht\@tempboxa\advance\dimen@-1ex\relax
+%%% reduce how much a nested accent is raised
+   \ifPDFX@inaccent\advance\dimen@-.2ex\relax\fi
+   \raise\dimen@\hbox to\wd\@tempboxa{\hss
+    \accent#1{\vphantom{#2}}\hss}%
+%%  \else
+%%  \accent#1{%\vphantom{#2}
+%%   \vrule width\z@ height\ht\@tempboxa depth\dp\@tempboxa}%
+%% \fi
+ \egroup
+ \spacefactor\accent@spacefactor
+}
+
+%% How to support XeTeX here ?
+%%%%%  adjust accent characters to the Unicode Combining variant  %%%%
+\def\PDFX@combiningchars@unicode{%
+ \pdfglyphtounicode{grave}{0300}%
+ \pdfglyphtounicode{acute}{0301}%
+ \pdfglyphtounicode{circumflex}{0302}%
+ \pdfglyphtounicode{tilde}{0303}%
+ \pdfglyphtounicode{macron}{0304}%
+ \pdfglyphtounicode{Macronsmall}{0304}%
+ \pdfglyphtounicode{breve}{0306}%
+ \pdfglyphtounicode{dotaccent}{0307}%
+ \pdfglyphtounicode{Dotaccent}{0307}%
+ \pdfglyphtounicode{Dotaccentsmall}{0307}%
+ \pdfglyphtounicode{dieresis}{0308}%
+ \pdfglyphtounicode{ogonek}{0309}%
+ \pdfglyphtounicode{ring}{030A}%
+ \pdfglyphtounicode{hungarumlaut}{030B}%
+ \pdfglyphtounicode{caron}{030C}%
+ \pdfglyphtounicode{cedilla}{0327}%
+ \pdfglyphtounicode{commaaccent}{0326}%   droid
+ %  tie accents in  berenisadf  lm  stix  and others
+ \pdfglyphtounicode{tieaccentlowercase}{0311}%
+ \pdfglyphtounicode{tieaccentcapital}{0361}%
+ \pdfglyphtounicode{newtieaccentlowercase}{0311}%
+ \pdfglyphtounicode{newtieaccentcapital}{0361}%
+ % cm-unicode
+ \pdfglyphtounicode{space_uni030D}{030D}%
+ \pdfglyphtounicode{space_uni030E}{030E}%
+ \pdfglyphtounicode{space_uni030F}{030F}%
+ \pdfglyphtounicode{space_uni0311}{0311}%
+ \pdfglyphtounicode{space_uni0321}{0321}%
+ \pdfglyphtounicode{space_uni0322}{0322}%
+ \pdfglyphtounicode{space_uni032A}{032A}%
+ \pdfglyphtounicode{space_uni032B}{032B}%
+ \pdfglyphtounicode{space_uni0335}{0335}%
+ \pdfglyphtounicode{space_uni0337}{0337}%
+ \pdfglyphtounicode{space_uni033A}{033A}%
+ \pdfglyphtounicode{space_uni033B}{033B}%
+ \pdfglyphtounicode{space_uni033C}{033C}%
+ \pdfglyphtounicode{space_uni034D}{034D}%
+}
 
+\AtBeginDocument{%
+ \ifx\add@accent\LTX@add@accent
+  \let\add@accent\PDFX@add@accent
+ \else
+  \expandafter\ifx\csname MT@orig@add@accent\endcsname\relax
+  \TPDF@error{another package has already patched \string\add@accent }%
+  \else
+   \expandafter\let\csname MT@orig@add@accent\endcsname\PDFX@add@accent
+ \fi\fi
+ \ifxetex
+ \else
+  \PDFX@combiningchars@unicode
+  \@ifpackageloaded{newtxmath}{%
+    \pdfglyphtounicode{vec}{20D7}%
+    \pdfglyphtounicode{rvec}{20D6}%
+    \pdfglyphtounicode{lrvec}{20E1}%
+   }{}%
+  \fi %  end of   \ifxetex
+}
+
+%%  suppress hyperlinks when generating  PDF/X
 \def\pdfx@linkfile@pdfX#1#2#3{%
  \Hy@colorlink\@filecolor#1\Hy@xspace@end}
 \def\pdfx@linkstart@pdfX#1#2#3{%
@@ -1522,6 +2454,7 @@
  \Hy@colorlink\@urlcolor#1\endgroup\Hy@xspace@end}
 \def\pdfx@StartlinkName@pdfX#1#2{}
 \def\pdfx@close@pdflink{\Hy@VerboseLinkStop\Hy@endcolorlink}%
+\def\pdfx@Acrobatmenu@noaction#1#2{#2}
 
 \ifpdfx@x
  \let\hyper@linkfile\pdfx@linkfile@pdfX
@@ -1530,19 +2463,20 @@
  \let\hyper@linkend\relax
  \let\Hy@StartlinkName\pdfx@StartlinkName@pdfX
  \let\close@pdflink\pdfx@close@pdflink
+ \let\AcrobatMenu\pdfx@Acrobatmenu@noaction
  \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
+    \begingroup
+     \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
+      \ifx\pdfx@pdfTitle\@empty\else /Title(\pdfx@pdfTitle)\fi
+      \ifx\pdfx@pdfAuthor\@empty\else /Author(\pdfx@pdfAuthor)\fi
+      \ifx\pdfx@pdfSubject\@empty\else /Subject(\pdfx@pdfSubject)\fi
+      \ifx\pdfx@pdfKeywords\@empty\else /Keywords(\pdfx@pdfKeywords)\fi
        /Creator(\pdfx@CreatorTool)%
       \ifx\@pdfcreationdate\@empty
        /CreationDate(D:\pdfx@convDate)%
@@ -1572,9 +2506,9 @@
 %%   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  PDF/X  info
+    \endgroup   %%  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
@@ -1605,16 +2539,16 @@
 %%  }%  end of  PDF/X  info
 %% }% end of scope for  \sep
 \else
- \ifpdfx@e
+ \ifpdfx@e   %% PDF/E
   \AtBeginDocument{%
    \def\PDF@FinishDoc{%  ??? What uses this ???
-    \Hy@UseMaketitleInfos
-    {\def\sep{; }% should not be needed, but just in case
+    \begingroup
+     \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
+      \ifx\pdfx@pdfTitle\@empty\else /Title(\pdfx@pdfTitle)\fi
+      \ifx\pdfx@pdfAuthor\@empty\else /Author(\pdfx@pdfAuthor)\fi
+      \ifx\pdfx@pdfSubject\@empty\else /Subject(\pdfx@pdfSubject)\fi
+      \ifx\pdfx@pdfKeywords\@empty\else /Keywords(\pdfx@pdfKeywords)\fi
        /Creator(\pdfx@CreatorTool)%
       \ifx\@pdfcreationdate\@empty
        /CreationDate(D:\pdfx@convDate)%
@@ -1631,7 +2565,7 @@
       /Trapped/False
       /GTS_PDFEVersion(PDF/E-1\xmp@Conformance:\xmp@ReleaseDate)%
      }%  end of  PDF/E  info
-    }% end of scope for  \sep
+    \endgroup  %% end of scope for  \sep
    }% end of  \PDF@FinishDoc
   }% end of  \AtBeginDocument
 %% {\def\sep{;}% should not be needed, but just in case
@@ -1652,7 +2586,7 @@
 %%   /Trapped/False%
 %%  }%  end of  PDF/E  info
 %% }% end of scope for  \sep
- \else
+ \else  %%  PDF/A
   \def\pdfx@confA{a}%
   \def\pdfx@confB{b}%
   \def\pdfx@confU{u}%
@@ -1660,13 +2594,13 @@
    {\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
+   \begingroup
+    \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
+     \ifx\pdfx@pdfTitle\@empty\else /Title(\pdfx@pdfTitle)\fi
+     \ifx\pdfx@pdfAuthor\@empty\else /Author(\pdfx@pdfAuthor)\fi
+     \ifx\pdfx@pdfSubject\@empty\else /Subject(\pdfx@pdfSubject)\fi
+     \ifx\pdfx@pdfKeywords\@empty\else /Keywords(\pdfx@pdfKeywords)\fi
       /Creator(\pdfx@CreatorTool)%
      \ifx\@pdfcreationdate\@empty
       /CreationDate(D:\pdfx@convDate)%
@@ -1683,14 +2617,15 @@
      /Trapped/False
      /GTS_PDFA1Version (PDF/A-\xmp@Part\xmp@conf:\xmp@ReleaseDate)%
     }%  end of  PDF/A  info
-   }% end of scope for  \sep
+   \endgroup  %%  end of scope for  \sep
   }% end of  \PDF@FinishDoc
  }% end of  \AtBeginDocument
 \fi\fi
 
 %%----------------------------------------------------------------------
+\begingroup
+%% override the \ifpdf  check of  xmpincl  package
 \ifxetex
- % override the \ifpdf check
  \pdftrue
 \else\ifluatex
  \pdftrue
@@ -1732,7 +2667,7 @@
  \let\includexmp\pdfx@xmpincl@xetex
 \fi
 
-%% macro provided by Leonardo E. Segovia on 2007-05-15
+%% macro provided by Leonardo E. Segovia on 2017-05-15
 %% <leonardo.segovia@cs.uns.edu.ar>
 \def\pdfx@xmpincl@luatex#1{%
  \IfFileExists{#1.xmp}{%
@@ -1741,7 +2676,8 @@
    \pdfcompresslevel=0
    \immediate\pdfobj uncompressed stream attr {/Type /Metadata /Subtype /XML}
    file{#1.xmpi}%
-   \pdfcatalog{/Metadata \the\pdflastobj\space 0 R}%
+   \pdfcatalog{%\pdfx@LanguageSpec
+    /Metadata \the\pdflastobj\space 0 R}%
    \endgroup
  }{%
   \newcommand{\mcs@xmpincl@filename}{#1.xmp}%
@@ -1769,6 +2705,8 @@
   \else
    \def\xmp@template{pdfa}%
  \fi\fi
+ \catcode`\'=12 \catcode`\<=12 \catcode`\>=12 \catcode`\?=12
+ \catcode`\"=12 \catcode`\= 12 %% used within the template file
 %% patch commands from  xmpincl.sty  ...
  \def\pdfx@xmpinclStart{% supply byte-order marker
   <?xpacket begin='^^ef^^bb^^be' id='W5M0MpCehiHzreSzNTczkc9d' ?> %
@@ -1797,8 +2735,10 @@
   \inputencoding{8bit}%
  \fi\fi
  \makeatletter
+ \def\cf@encoding{L8U}\fontencoding{L8U}%
+ \providecommand{\ifnot@empty}[2]{\ifx#1\@empty\relax\else#2\fi}%
  \pdfx@xmpmarkup
- \expandafter\global\expandafter
+\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}%
@@ -1867,6 +2807,8 @@
  \global\let ^^f3\pdfx@save@fiii
 \fi
 
+\endgroup
+
 %%
 %% controls the color model and conversions with  xcolor  package
 %%
@@ -1907,6 +2849,30 @@
  \AtBeginDocument{\@ifpackageloaded{xcolor}{\pdfx@handlexcolor}{}}
 }
 
+%%----------------------------------------------------------------------
+%%  Disable some actions in Beamer navigation
+\@ifclassloaded{beamer}{%
+ \let\real@insertslidenavigationsymbol
+   \insertslidenavigationsymbol
+ \let\real@insertbackfindforwardnavigationsymbol
+   \insertbackfindforwardnavigationsymbol
+ \def\pdfx@insertslidenavigationsymbol{{%
+  \let\Acrobatmenu\pdfx@Acrobatmenu@noaction
+  \real@insertslidenavigationsymbol
+ }}%
+ \def\pdfx@insertbackfindforwardnavigationsymbol{{%
+  \let\Acrobatmenu\pdfx@Acrobatmenu@noaction
+  \real@insertbackfindforwardnavigationsymbol
+ }}%
+ \AtBeginDocument{%
+  \ifHy@pdfa
+   \let\insertslidenavigationsymbol
+     \pdfx@insertslidenavigationsymbol
+   \let\insertbackfindforwardnavigationsymbol
+     \pdfx@insertbackfindforwardnavigationsymbol
+  \fi}%
+}{}
+
 %%----------------------------------------------------------------------
 \ifpdfx@transliterated
 %% support for bookmarks with transliterated input
@@ -1933,6 +2899,7 @@
   \let\Hy@@writetorep\@@writetorep
   \def\pdfx@@writetorep#1#2#3#4#5{%
    \begingroup
+    \pdfx@xmpunimarkup
     \pdfx@prebookmark
     \edef\pdfstringdefPreHook{%\pdfstringdefPreHook
      \the\pdfx@DisabledCommands}%
-- 
cgit v1.2.3

