3

Using lualatex, recent TeXlive, Linux. I have searched here, and discovered that \pdfvariable trailerid {value} can be used for creating a specifid Info /ID in the PDF dictionary. It does work, if the value is in proper plain text, without requiring macro expansion. But it fails if the value is created from a macro. MWE:

\documentclass{article} % compile with lualatex
\usepackage{fontspec}
\pdfvariable compresslevel=0
\pdfvariable objcompresslevel=0
\def\yada{3a88e6fb9021cd0033aa000000000000}
\def\bada{5a88e6f44021cd0033ba000000000333}
\edef\yadabada{[ <\yada> <\bada> ]}
\pdfvariable trailerid {\yadabada} % Preceding with \expandafter does not help.
\begin{document}
foo
\end{document}

Inspection of the PDF in a plain text editor, shows that the Info /ID is literally \yadabada rather than the expanded pair of hex strings. The most obvious attempt to fix this, is to precede \pdfvariable with \expandafter, but that has no effect.

What to do, if anything can be done?

Note that I am not using (and cannot use, in this workflow) \DocumentMetadata.

4
  • prepending \pdfvariable with \expandafter will just expand the t, as far as I know. I'm not sure if that is what you tried or you meant something else?
    – cfr
    Commented Apr 4 at 18:18
  • @cfr I tried typing at random (my only method of programming). Didn't bring my sledge hammer with me today.
    – rallg
    Commented Apr 4 at 18:21
  • 1
    You can define a new macro \newcommand{\pdfvartrailerid}[1]{\pdfvariable trailerid{#1}} then use \ExpandArgs{o}\pdfvartrailerid{\yadabada} (or \ExpandArgs{e})
    – mbert
    Commented Apr 4 at 18:34
  • @mbert Thanks. That is essentially what is done in the accepted answer. The underlying trick is the \Expandargs{e} call.
    – rallg
    Commented Apr 4 at 18:54

3 Answers 3

2

I'm not sure exactly what you tried but maybe something like

\expandafter\pdfvariable trailerid {\yadabada}

This will do a great job of expanding the token following \pdfvariable before expanding \pdfvariable. That is, it will expand t (once) before expanding \pdfvariable. Since t can't be expanded, this is equivalent to

\pdfvariable trailerid {\yadabada}

Some combination of \expandafters and \noexpands could work magic here, but it would be a clunky and inconvenient magic.

A more straightforward form of magic1 is to use expl3 or, avoiding the need for tiresome \ExplSyntaxOn/\ExplSyntaxOff switches, \ExpandArgs. Then we can directly requrest \yadabada be fully expanded before it is passed to \pdfvariable.

Since trailerid includes an annoying number of tokens, we can also make things easier by defining a wrapper. Even better, we can copy-paste the definition from the docs.

Borrowing from the LuaTeX manual:

\edef\pdftrailerid {\pdfvariable trailerid }
\edef\yadabada{[ <\yada> <\bada> ]}
\ExpandArgs {e} \pdftrailerid{\yadabada}

1AKA Magic for the Rest of Us

3
  • So easy! For a moment, I thought about letting my neighbor's cat walk across the keyboard (my other method of programming, without sledgehammer).
    – rallg
    Commented Apr 4 at 18:52
  • 2
    @rallg you need to be a bit careful with cat codes.
    – cfr
    Commented Apr 4 at 18:55
  • No problem with cat codes. The cats were fixed at the vet.
    – rallg
    Commented Apr 5 at 1:32
4

You only need to put the \expandafter into the right place:

\pdfvariable trailerid \expandafter {\yadabada}

If you don't want to expand the command before, you could do

\def\yadabada{[ <\yada> <\bada> ]}
\pdfvariable trailerid \expandafter{\expanded{\yadabada}}
0
2

\pdfvariable triggers expansion of the following tokens in order to find a keyword (the name of the variable):

\pdfvariable compresslevel=0
\pdfvariable objcompresslevel=0

\documentclass{article}
\usepackage{fontspec}

\def\yada{3a88e6fb9021cd0033aa000000000000}
\def\bada{5a88e6f44021cd0033ba000000000333}
\edef\yadabada{[ <\yada> <\bada> ]}
\pdfvariable \expanded{trailerid {\yadabada}}

\begin{document}
foo
\end{document}

Alternatively,

\expanded{\pdfvariable trailerid {\yadabada}}

In the PDF file we see

trailer
<< /Size 14 /Root 12 0 R /Info 13 0 R /ID [ <3a88e6fb9021cd0033aa000000000000> <5a88e6f44021cd0033ba000000000333> ] >>

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.