9

As I understand it, embedding (as metadata) the typesetting engine that was used to produce a PDF document is good practice. Here is an example of how this can be done using the hyperref package:

\hypersetup{pdfcreator={pdflatex 1.40.14}}

However, hardcoding this information is error-prone. What if, between now and the final version of my document, I decide to switch typesetting engine, or what if a new version gets released, and I forget to update the metadata?

If possible, I'd like to avoid hardcoding the typesetting engine (name and version) used... Is there an easy way of accessing that information during a run of that engine on my tex file?

  • 1
    Related: tex.stackexchange.com/questions/26178/… – cslstr May 6 '14 at 19:58
  • In fact, \pdftexbanner may solve your whole problem...? Though it is a bit more verbose than desired, perhaps. – cslstr May 6 '14 at 20:00
  • @cslstr Thanks; the question (and its answers) you link to is interesting. It doesn't completely answer my question, though. I'd like to format the string as in my example. – jub0bs May 6 '14 at 20:13
  • 1
    @Jubobs: pdflatex is a mixup of pdfTeX and LaTeX, both have version numbers, e.g. 1.40.15 and 2014/05/01. – Heiko Oberdiek May 6 '14 at 20:15
12

pdfTeX

The TeX compiler pdfTeX already sets some keys as default:

/Producer (pdfTeX-1.40.15)
/Creator (TeX)
/CreationDate (D:20140506215840+02'00')
/ModDate (D:20140506215840+02'00')
/Trapped /False
/PTEX.Fullbanner (This is pdfTeX, Version 3.14159265-2.6-1.40.15 (TeX Live 2014) kpathsea version 6.2.0)

Some of these entries can be overwritten via \pdfinfo or via \hypersetup if hyperref is loaded. A nice feature of pdfTeX is, that if it detects the setting of standard keys in \pdfinfo, then pdfTeX suppresses its setting to avoid duplicate keys in the same dictionary with different values. Therefore it is possible for the user or hyperref to override the setting of pdfTeX.

The default of hyperref's values are (line breaks added for better readability):

/Author()
/Title()
/Subject()
/Creator(LaTeX with hyperref package)
/Producer(pdfTeX-1.40.15)
/Keywords()

Also the other entries can be set by hyperref (pdfcreationdate, pdfmoddate, ...)

Version number of pdfTeX

Since the version number scheme of pdfTeX has changed in the past, the algorithm for the versions specification is quite complex, from hpdftex.def:

\def\@pdfproducer{pdfTeX}%
\ifx\eTeXversion\@undefined
\else
  \ifx\eTeXversion\relax
  \else
    \ifnum\eTeXversion>0 %
      \def\@pdfproducer{pdfeTeX}%
    \fi
  \fi
\fi
\ifx\pdftexversion\@undefined
\else
  \ifnum\pdftexversion<100 %
    \edef\@pdfproducer{%
      \@pdfproducer
      \the\pdftexversion.\pdftexrevision
    }%
  \else
    \ifnum\pdftexversion<130 %
      \edef\@pdfproducer{%
        \@pdfproducer-%
        \expandafter\@car\the\pdftexversion\@empty\@nil.%
        \expandafter\@cdr\the\pdftexversion\@empty\@nil
        \pdftexrevision
      }%
    \else
      \ifnum\pdftexversion<140 %
      \else
        \def\@pdfproducer{pdfTeX}%
      \fi
      \edef\@pdfproducer{%
        \@pdfproducer-%
        \expandafter\@car\the\pdftexversion\@empty\@nil.%
        \expandafter\@cdr\the\pdftexversion\@empty\@nil.%
        \pdftexrevision
      }%
    \fi
  \fi
\fi

Other drivers

Package hyperref also sets information entries with the other drives. But it can happen, that the driver insists of its setting for some of the keys (/Creator, ...).

  • Aaah... thanks for that. So far, I had always hardcoded this info using \hypersetup; I hadn't realised pdfTeX already fills the relevant fields exactly as desired. Thanks again. – jub0bs May 6 '14 at 20:32
9

\pdftexbanner (introduced in pdfTeX 1.20a; see the pdfTeX user manual) produces the output:

This is pdfTeX, Version 3.1415926-2.5-1.40.14 (TeX Live 2013/W32TeX) kpathsea version 6.1.1

and contains the version of pdfTeX being used to process the document. You can extract just the pdfTex version using the following:

\makeatletter
\def\extractpdftexversion#1-#2-#3 #4\@nil{#3}
\edef\pdftexversion{\expandafter\extractpdftexversion\pdftexbanner\@nil}
\makeatother

Here \extractpdftexversion expects an argument text of the form <stuffA>-<stuffB>-<stuffC> <stuffD>\@nil, and only returns <stuffC> (that is, the text delimited on the left by - and on the right by a space ). You can add it to your PDF document properties using

\pdfinfo{
  /Producer (pdfTeX \pdftexversion)
}

enter image description here

\documentclass{article}
\makeatletter
\def\extractpdftexversion#1-#2-#3 #4\@nil{#3}
\edef\pdftexversion{\expandafter\extractpdftexversion\pdftexbanner\@nil}
\makeatother
\pdfinfo{
  /Producer (pdfTeX \pdftexversion)
}
\begin{document}
\pdftexbanner
\end{document}

No explicit need to use hyperref (see Is hyperref really the best way to add metadata to a TeX file?).

0

Solution applicable to many engines

This solution will work independent of the typesetting engine (tested on PdfLaTeX and LuaTeX) and uses the banner string.

It uses the xstring package. The metadata is set in the preamble using the hyperref package (alternatively, you could also use the facilities provided by the pdfx, or hyperxmp packages. pdfx internally uses the low-level metadata setting facilities provided by the xmpincl package.)

\documentclass{article}
\usepackage{xstring}
% uncomment one of the two lines below suitably
% \StrBetween{\luatexbanner}{\detokenize{n }}{\detokenize{.0 (}}[\luatexversionused] % obtain luatex version used. Uncomment for luatex
% \StrBetween{\pdftexbanner}{\detokenize{n }}{\detokenize{.0 (}}[\luatexversionused] % obtain pdftex version used. Uncomment for pdftex
\usepackage{hyperref}
% uncomment one of the two lines below suitably
% \hypersetup{pdfcreator = {LuaTeX \luatexversionused} % for luatex
% \hypersetup{pdfcreator = {pdfTeX \pdftexversionused} % for pdftex
\begin{document}
blah blah....
\end{document}

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.