]> mj.ucw.cz Git - diplomky.git/commitdiff
Create xmpdata file from metadata automatically
authorMartin Mares <mj@ucw.cz>
Wed, 21 Feb 2024 12:16:14 +0000 (13:16 +0100)
committerMartin Mares <mj@ucw.cz>
Wed, 21 Feb 2024 17:54:09 +0000 (18:54 +0100)
This requires changing format of \Keywords.

Makefile
metadata.tex
thesis.tex
thesis.xmpdata [deleted file]
title.tex
xmp.tex [new file with mode: 0644]

index bd66b3f4df82effde96ba31634dcd32b0b6614be..b48a16a41369be8bf04b751f9a5fd908c0be4da5 100644 (file)
--- 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
index ba5b20e424c42ec91a4bd68dfa9704191228edd1..f2d03b2d2e77d92a6b9bae573168b402ed53a684 100644 (file)
@@ -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{%
index ac97df18d73cfc1032f62409fbaf9e8a7a7152f6..95c20cb0151bd813596cfe288c9a47fe32360771 100644 (file)
@@ -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 (file)
index c9babd8..0000000
+++ /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}
index 127be7ad0dfa8b765442e45cee15a14cb1430763..b05f5c5a3cbb81a73c01e9ace33260553b97b1ec 100644 (file)
--- 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 (file)
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
+}