3

I have been away of Beamer for a few years and I am coming back to my old notes (samples of code) that I put together and build a few new presentations.

While I was compiling the code I got the following warning:

hyperref: Token not allowed in a PDF string (PDFDocEncoding): sample.tex

I know that this warning has been asked and answered here "Hyperref warning - Token not allowed in a PDF string" and also here "Hyperref - Token not allowed [duplicate]".

I am raising the question on the same warning because I can not find an answer on how to include the date with the function \today and not produce the warning.

On my sample of code if I include the function \today I get the warning, if I remove the function and I add manually the date (e.g. 23-04-2018) the code compiles just fine.

sample.tex (Update 2: Minimal working example)

\documentclass[xcolor=pdftex,dvipsnames,table]{beamer}
\usepackage{lmodern}% http://ctan.org/pkg/lm (For special Fonts)

\author[First Last Name]{Date: \today} % (optional, for multiple authors)

\begin{document}
  \titlepage
\end{document}

So my question, is there any way to include the \today function without getting the warning? I do not want to supress the warning I know that there is there for a reason. I am asking if anyone sees if I am doing something wrong and know any work around other than updating manual the date.

3
  • @campa, I have updated the sample of code. You are right, actually I needed only 9 lines. The reason that I added all the lines was to add simply all the headers and footers that I am using. Regarding why I am putting the \today function inside the author. The only reason that I am doing so, is because the auto produced date is really far in the page and by removing vertical white space it destroys the rest of the alignments.
    – Thanos
    Apr 23, 2018 at 11:44
  • Thanks for the update! One more hint: beamer loads also hyperref by default, so you can delete one more line :-)
    – campa
    Apr 23, 2018 at 11:45
  • @campa, nice trick. I has no clue about that. Thanks for the tip. :-)
    – Thanos
    Apr 23, 2018 at 11:50

1 Answer 1

4

The default definition of \today is expandable, but loading beamer changes it:

\documentclass[xcolor=pdftex,dvipsnames,table]{beamer}
\usepackage{lmodern}% http://ctan.org/pkg/lm (For special Fonts)

\show\today

\author[First Last Name]{Date: \today} % (optional, for multiple authors)

\begin{document}
  \titlepage
\end{document}

This shows the definition of \today:

> \today=macro:
->\ifcase \month \or \translate {January}\or \translate {February}\or \translat
e {March}\or \translate {April}\or \translate {May}\or \translate {June}\or \tr
anslate {July}\or \translate {August}\or \translate {September}\or \translate {
October}\or \translate {November}\or \translate {December}\fi \space \number \d
ay , \number \year .
l.4 \show\today

The \translate command is robust and so can't expand and it's that that's causing the problem. A simple solution is to load datetime2, which changes \today back to being expandable:

\documentclass[xcolor=pdftex,dvipsnames,table]{beamer}
\usepackage{lmodern}% http://ctan.org/pkg/lm (For special Fonts)

\usepackage[en-US]{datetime2}

\author[First Last Name]{Date: \today} % (optional, for multiple authors)

\begin{document}
  \titlepage
\end{document}

This example also requires datetime2-english which is installed separately.

1
  • it works like a charm. Thanks for providing also sample of the code and analysis to the solution. :)
    – Thanos
    Apr 23, 2018 at 13:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .