3

The pdfx package documentation recommends to use a file \jobname.xmpdata to supply PDF metadata. This can be handled by using the filecontents environment. However, that makes macros useless, making it non-trivial to include the document wide title and author.

Are there any ways in plain LaTeX to work around having to type the metadata in more than one place of the document? Something like sed scripts would not be expected to work on all platforms.

\documentclass{article}
\usepackage[a-1b]{pdfx}

\title{Example}
\author{John Doe}

\makeatletter

\begin{filecontents}{\jobname.xmpdata}
\Title{\@title}
\Author{\@author}
\end{filecontents}

\makeatother

\begin{document}
test
\end{document}

which results in the following xmpdata, using non-escaped title and author

%% LaTeX2e file `main.xmpdata'
%% generated by the `filecontents' environment
%% from source `main' on 2017/06/03.
%%
\Title{\@title}
\Author{\@author}
6

You could do it the other way round and reuse the data from the xmpdata:

\RequirePackage{filecontents} %if filecontents should overwrite old files

\begin{filecontents}{\jobname.xmpdata}
\Title{My Title}
\Author{John Doe}
\end{filecontents}

\documentclass{article}
\usepackage[a-1b]{pdfx}

\makeatletter
\title{\xmp@Title}
\author{\xmp@Author}
\makeatother

\begin{document}
\maketitle
test
\end{document}

You can also define your title in a third place. It will not be in the xmpdate file, but when it it read, the content will be expanded:

\newcommand\mytitle{My Title}
\RequirePackage{filecontents}

\begin{filecontents}{\jobname.xmpdata}
\Title{\mytitle}
\Author{John Doe}
\end{filecontents}

\documentclass{article}
\usepackage[a-1b]{pdfx}

\makeatletter
\title{\mytitle \\ and some subtitle}
\author{\xmp@Author}
\makeatother

\begin{document}
\maketitle
test
\end{document}
  • In order to format the title page, would it be possible to split up the metadata in a main title and subtitle? – svenper Jun 3 '17 at 22:17
  • The metadata don't have subtitle, but I added an alternative that gives you more freedom. – Ulrike Fischer Jun 3 '17 at 22:26
  • So is the trick to define the command before \documentclass? Where can I learn more about this? – svenper Jun 4 '17 at 0:05
  • And I'm running into problems when the title defined contains Unicode characters. Replacing them with TeX macros does not work either: Command \a unavailable in encoding T1 – svenper Jun 4 '17 at 0:12
  • With hypersetup I was able to set the title of the pdf with \AtBeginDocument{\hypersetup{pdftitle=\@mytitle}} where \def\@mytitle{DummyTitle}. I'm not able to use the\@mytitle variable inside the filecontents block. Why? – Wollmich Apr 11 '18 at 11:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.