# qrcode wont work inside a caption

i'd like to use a \qrcode inside of a \caption, like:

% !TeX program = lualatex
\documentclass{scrartcl}
\usepackage{polyglossia}\setdefaultlanguage{german}
\usepackage{graphicx, qrcode}

\begin{document}

\begin{figure}
%\includegraphics[width=\linewidth]{02-794.jpg}
\caption{\qrcode{https://www.scinexx.de/fotos/schiffsspuren-in-den-wolken/} }
\end{figure}

\end{document}


but \qrcode seems only to work outside of a \caption… The code above produces the error:

! Argument of \@caption has an extra }.
<inserted text>
\par
l.12 ...exx.de/fotos/schiffsspuren-in-den-wolken/} }


what is the meaning of this error? How can i solve this?

• Untested \protect\qrcode Sep 27 at 17:15
• Do you want that QR code to also show up in the list of figures? If not, \caption[<caption-for-list-of-figures>]{<caption-with-qr-code>} should do the job. Sep 27 at 17:23
• I confirm \protect\qrcode works. Be sure to remove the .aux file before running again LuaLaTeX after adding \protect (this removal isjust once). Sep 27 at 17:58
• thank you very much! I also confirm, that \protect does the trick – but only for rather simple input: \listoffigures \begin{figure} \caption{\protect\qrcode{https} } \end{figure} works fine (even with an qr-code in the listoffigures), but not with \qrcode{https://www.scinexx.de/fotos/schiffsspuren-in-den-wolken/} – then the following error occurs: ! Missing \endcsname inserted. <to be read again> \datablock@2 l.10 ...exx.de/fotos/schiffsspuren-in-den-wolken/} } Sep 27 at 21:11

thank you daleif, Skillmon and egreg. While your \protect is a solution for qr-codes, which link to maximum-two-character-links like: \caption{\protect\qrcode{https://ab.com}} is doesn't work for more-than-two-character-links…

A workaround for those situations could be:

\documentclass{standalone}
\usepackage{qrcode}
\begin{document}
\qrcode{https://tex.stackexchange.com}
\end{document}


combined with an:

\caption{\includegraphics{standalone_qrcode.pdf}}