3

I have a custom class file where I define some variables to be filled by users such as: \author, \title ...

And I would like to generate a .xmpdata file that grabs these information.

For these I have the following class file:

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{foo}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\ProcessOptions\relax
\LoadClass[a4paper]{article}

\RequirePackage{luatextra}
\RequirePackage[pdftex]{pdflscape}
\RequirePackage[a-3u]{pdfx}
\RequirePackage[usenames,dvipsnames,svgnames]{xcolor}
\RequirePackage{etoolbox}
\begin{filecontents}{\jobname.xmpdata}
    \Keywords{\@keywords}
    \Title{\@title}
    \Author{\@author}
    \Org{\@org}
\end{filecontents}

\AtEndPreamble{%
    \makeatletter
    \hypersetup{ 
        unicode     = true,
        final       = true,
        colorlinks  = true,
        urlcolor    = blue,
        citecolor   = blue,
        linkcolor   = MidnightBlue,
        unicode     = true,
        linktoc     = section,
        pdflang     = fr-FR
    }
    \makeatother
}{}

\def\date#1{\def\@date{#1}}
\let\@date\@empty

\def\author#1{\def\@author{#1}}
\let\@author\@empty

\def\org#1{\def\@org{#1}}
\let\@org\@empty

\def\title#1{\def\@title{#1}}
\let\@title\@empty

\def\keywords#1{\def\@keywords{#1}}
\let\@keywords\@empty

And this main tex file to test it:

% !TeX encoding = utf8
% !TeX spellcheck = fr_FR
\documentclass{foo}

\author{foo}
\title{bar}
\keywords{baz}
\org{foz}

\begin{document}
 it is a MWE
\end{document}

I used here lualatex as engine, and the .xmpdata file is created but the variables are not expanded:

cat bar.xmpdata
%% LaTeX2e file `bar.xmpdata'
%% generated by the `filecontents' environment
%% from source `bar' on 2017/02/23.
%%
    \Keywords{\@keywords}
    \Title{\@title}
    \Author{\@author}
    \Org{\@org}

Expected file:

\Title{bar}
\Author{foo}
\Keywords{baz}
\Publisher{foz}

Maybe by using \directlua there is a better way?

I do not understand the answer given in: https://tex.stackexchange.com/a/349521/24790

  • Can you please show an example of the expected format for the .xmpdata file? – egreg Feb 23 '17 at 21:30
  • Hi egreg, I updtaed at end the end the expected file. The file format follow specification given at http://mirrors.standaloneinstaller.com/ctan/macros/latex/contrib/pdfx/pdfx.pdf – bioinfornatics Feb 24 '17 at 08:59

1 Answers1

2

If your end result is PDF/X (paper print) rather than PDF/A (E-book), then have a look at my own document class on GitHub. Just put it there, earlier this week. It uses a heavily modified portion of the pdfx code, but does the XMP in a somewhat different manner. Since my code is LPPL licensed, you can rip whatever you need for your own. Of all the files, the two you most need to look at are novel-pdfx.sty and novel-xmppacket.sty.

https://github.com/daniel-j/novel

Note that my code does not provide for keywords, only because they are useless in the print-to-paper market. Could have been added.

EDIT: When a document is compiled with my class, it does not export the XMP file unless requested. That is performed by using xml (not xmp) as a class option.

Rob Rose
  • 103
  • 4
  • thanks for your answer, you have done a really good work. for this reason I upvoted your answer. Unfortunately it is for an archivable file (online). – bioinfornatics Feb 24 '17 at 09:01
  • All right. Note that the part of the code you need will still be OK for digital files. But I did not include data fields such as keywords, DOI, etc. –  Feb 24 '17 at 15:25