2

In a class file, I have set (to automatically set PDF information fields):

\hypersetup{pdfinfo={Title={\@doctitle}, Author={\@docauthor}, Subject={\@docsubject}, Producer={LaTeX}, Version={\@docversion}, Date={\@docdate}, Institution={\@universityname}}}

However, when I typeset documents using this class file (which works fine in every other respect), and look at document properties for the PDF, I get literal strings 'doctitle', 'docauthor' etc. for the various fields. That suggests that the LaTeX commands (which are defined and used elsewhere in class file) are not getting expanded.

What am I missing? Do I need to escape the '\' (which seems to be escaping the ampersand)?

So, \\@doctitle, and not \@doctitle. Or are the contents of {} simply treated as literal strings? If so, how do I achieve what I am trying to do.

  • Yes, I have, at various locations. None affecting these items. – user2751530 Jun 28 '15 at 10:39
2

It seems, you have the wrong category code of @. Then TeX will not see the token \@doctitle but the tokens \@, d, o, t, i, t, t, l, e. The first token \@ is filtered out (the command sets the space factor) and the string doctitle remains.

In the class file, the category of @ is usually "letter", thus that @ can be used in command names. Maybe you have changed it somewhere via \makeatother.

Category code checking

You can check the category code of @ by

\showthe\catcode`\@ % or \showthe\catcode64

This throws an error like message, which shows the number of the category code. It should be 11 for letter. 12 means other character, the effect of \makeatother.

Also the category code value can be print on the screen and the log file:

\typeout{* Category code of @ = \the\catcode`\@}

However, the place for the category code check is tricky. It should the time of tokenization of \@doctitle, not the execution time.

Example:

<A>\def\macro{<B>\@doctitle...}

\@doctitle is tokenized, when the definition of \macro is made. Therefore <B> is too late, it would be the time, when \macro is executed, somewhere later in the document.

<A> could be the right place, if the macro definition is "top-level", not inside macros or hooks. Example:

<C>\AtBeginDocument{<A>\def\macro{<B>\@doctitle}}

Then <A> would be too late, because the macro definition of \macro is already tokenized as argument of \AtBeginDocument. Then <C> is the better place.

| improve this answer | |
  • Thank you Heiko. However, I have not changed catcodes anywhere that I can tell. I am using \@xxx for lot of other variables as well. They are not impacted when they are used elsewhere in the class file. Further, \@doctitle etc produce the correct expansions when used elsewhere in the class file. It is only in pdfinfo that they are failing. What do I need to check? – user2751530 Jun 28 '15 at 10:41
  • @user2751530 It's time to post a minimal working example (MWE). When the problem can be reproduced, it can be analyzed. – Heiko Oberdiek Jun 28 '15 at 10:59
  • Wish I could. The class file is not only a few thousand lines long, it also contains data that I do not have the right to distribute (logos, etc. coded as tikz code). Thanks for making the attempt to help. I will try to figure it out on my own. – user2751530 Jun 28 '15 at 11:04
  • @user2751530 That would not be a minimal working example. You have to strip down the class in a way, that it becomes much more smaller, but still shows the error. Have you tried setting \makeatletter at top level before the \hypersetup line? – Heiko Oberdiek Jun 28 '15 at 11:09
  • @user2751530 I have added a section about checking category codes. However it's not trivial, because some knowledge about TeX's tokenization process is required. – Heiko Oberdiek Jun 29 '15 at 8:03

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.