From 36cc6c13b63ab51f517f30f507091d0346a31be6 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Wed, 21 Feb 2024 13:16:14 +0100 Subject: [PATCH] Create xmpdata file from metadata automatically This requires changing format of \Keywords. --- Makefile | 4 ++-- metadata.tex | 18 +++++++++++++----- thesis.tex | 9 ++++++--- thesis.xmpdata | 7 ------- title.tex | 7 ++----- xmp.tex | 33 +++++++++++++++++++++++++++++++++ 6 files changed, 56 insertions(+), 22 deletions(-) delete mode 100644 thesis.xmpdata create mode 100644 xmp.tex diff --git a/Makefile b/Makefile index bd66b3f..b48a16a 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ export TEXINPUTS=../tex//: all: thesis.pdf abstract.pdf # LaTeX must be run multiple times to get references right -thesis.pdf: thesis.tex $(wildcard *.tex) bibliography.bib thesis.xmpdata +thesis.pdf: thesis.tex $(wildcard *.tex) bibliography.bib pdflatex $< bibtex thesis pdflatex $< @@ -13,5 +13,5 @@ abstract.pdf: abstract.tex abstract.xmpdata pdflatex $< clean: - rm -f *.log *.dvi *.aux *.toc *.lof *.lot *.out *.bbl *.blg *.xmpi + rm -f *.log *.dvi *.aux *.toc *.lof *.lot *.out *.bbl *.blg *.xmpi *.xmpdata rm -f thesis.pdf abstract.pdf diff --git a/metadata.tex b/metadata.tex index ba5b20e..f2d03b2 100644 --- a/metadata.tex +++ b/metadata.tex @@ -59,13 +59,21 @@ increases the probability of getting a reviewer who will like the thesis.} \X{This is not a~copy of your thesis assignment!} } -% 3 to 5 keywords (recommended), each enclosed in curly braces. +% 3 to 5 keywords (recommended) separated by \sep % Keywords are useful for indexing and searching for the theses by topic. -\def\Keywords{% -\xxx{{key} {words}} +\def\ThesisKeywords{% +\xxx{keyword\sep key phrase} \X{usually 3 to~5 key words or phrases} } +% If any of your metadata strings contains TeX macros, you need to provide +% a plain-text version for use in XMP metadata embedded in the output PDF file. +% If you are not sure, check the generated thesis.xmpdata file. +\def\ThesisAuthorXMP{\ThesisAuthor} +\def\ThesisTitleXMP{\ThesisTitle} +\def\ThesisKeywordsXMP{\ThesisKeywords} +\def\AbstractXMP{\Abstract} + % If your abstracts are long and do not fit in the infopage, you can make the % fonts a bit smaller by this setting. (Also, you should try to compress your abstract more.) \def\InfoPageFont{} @@ -80,8 +88,8 @@ increases the probability of getting a reviewer who will like the thesis.} \def\SupervisorsDepartmentCS{\xxx{katedra vedoucího}} \def\StudyProgrammeCS{\xxx{studijní program}} -\def\KeywordsCS{% -\xxx{{klíčová} {slova}} +\def\ThesisKeywordsCS{% +\xxx{klíčová slova\sep klíčové fráze} } \def\AbstractCS{% diff --git a/thesis.tex b/thesis.tex index ac97df1..95c20cb 100644 --- a/thesis.tex +++ b/thesis.tex @@ -1,5 +1,11 @@ %%% The main file. It contains definitions of basic parameters and includes all other parts. +% Meta-data of your thesis (please edit) +\input metadata.tex + +% Generate metadata in XMP format for use by the pdfx package +\input xmp.tex + %% Settings for single-side (simplex) printing % Margins: left 40mm, right 25mm, top and bottom 25mm % (but beware, LaTeX adds 1in implicitly) @@ -57,9 +63,6 @@ \hypersetup{unicode} \hypersetup{breaklinks=true} -% Meta-data of your thesis (please edit) -\include{metadata.tex} - % Definitions of macros (see description inside) \include{macros} diff --git a/thesis.xmpdata b/thesis.xmpdata deleted file mode 100644 index c9babd8..0000000 --- a/thesis.xmpdata +++ /dev/null @@ -1,7 +0,0 @@ -% Metadata to be stored in PDF, see documentation of the pdfx package for more details. - -\Author{Name Surname} -\Title{Thesis title} -\Keywords{keywords\sep more such\sep yet another} -\Subject{Abstract of thesis} -\Publisher{Charles University} diff --git a/title.tex b/title.tex index 127be7a..b05f5c5 100644 --- a/title.tex +++ b/title.tex @@ -136,10 +136,7 @@ Abstract: \Abstract Keywords: -\Keywords - -\XXX{This information must be stored as PDF meta-data, too. Please refer to the {\tt README} file.} -\vss} +{\def\sep{\unskip, }\ThesisKeywords} % In Czech study programmes, it is mandatory to include Czech meta-data: @@ -165,7 +162,7 @@ Abstrakt: \AbstractCS Klíčová slova: -\KeywordsCS +{\def\sep{\unskip, }\ThesisKeywordsCS} } \fi diff --git a/xmp.tex b/xmp.tex new file mode 100644 index 0000000..d1a6daa --- /dev/null +++ b/xmp.tex @@ -0,0 +1,33 @@ +% Generate XMP metadata file (*.xmpdata) from thesis metadata +% The format of the xmpdata file is described in the documentation +% of the "pdfx" LaTeX package. + +{ +% Define \percenthack macro that expands to a literal "%" character. +% (We can use neither \char\`% nor \% as they are interpreted by TeX's +% main processor which is too late for our purposes.) +\catcode`\%=12 +\global\edef\percenthack{%} +} + +{ +% Override some macros +\def\xxx#1{#1} +\def\X#1{} +\def\sep{\string\sep\space} +\let~=\space + +% Generate *.xmpdata +% It is tempting to use LaTeX's filecontents environment, but it does not +% expand macros. We need to dive deeper... +\newwrite\xmp +\immediate\openout\xmp=\jobname.xmpdata +\immediate\write\xmp{\percenthack\space Generated automatically from metadata.tex, please don't edit here.} +\def\xmpitem#1#2{\immediate\write\xmp{\string#1{#2}}} +\xmpitem\Author\ThesisAuthorXMP +\xmpitem\Title\ThesisTitleXMP +\xmpitem\Keywords\ThesisKeywordsXMP +\xmpitem\Subject\AbstractXMP +\xmpitem\Publisher{Charles University} +\immediate\closeout\xmp +} -- 2.39.5