# tikzposter and doi package conflict?

When using the doi package with tikzposter, I get the following error when compiling with pdflatex:

! LaTeX Error: Can be used only in preamble.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
...

l.4 \HyperFirstAtBeginDocument
{\ifx\hyper@anchor\@undefined
?


However, if I kill the failed compilation and run pdflatex a second time without deleting the *.aux file then it compiles successfully.

Is this a known conflict, and is there any way to fix this so that it compiles the first time? Thanks in advance for your help.

MWE

\documentclass{tikzposter}
\usepackage{doi}
\begin{document}
\end{document}

• doi is not involved other than it loads hyperref you get the same error if you change doi to hyperref in the above – David Carlisle May 16 '16 at 15:18

Looks like a hyperref or tikz bug (not fully tracked it down) but you can do this:

\documentclass{tikzposter}
\usepackage{doi}

\def\HyperFirstAtBeginDocument#1{#1}
\begin{document}

\end{document}


The additional line should be the last thing in the preamble, just before \begin{document}

• tikzposter adds \begin{tikzpicture} to \AtBeginDocument and \end{tikzpicture} to \AtEndDocument and so introduce a group. Not quite sure if this is a good idea ... – Ulrike Fischer May 16 '16 at 15:48
• @UlrikeFischer oh excellent, thanks! that means it's a tikz bug not a hyperref one, so I don't have to fix it:-) – David Carlisle May 16 '16 at 15:55
• ; -). Imho there is somewhere here a discussion regarding environments in begin/end document but can't look now, I'm off to dinner... – Ulrike Fischer May 16 '16 at 16:08