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

% !TeX program = lualatex 
\usepackage{graphicx, qrcode} 

\caption{\qrcode{https://www.scinexx.de/fotos/schiffsspuren-in-den-wolken/} }

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

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

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

  • 2
    Untested \protect\qrcode
    – daleif
    Sep 27 at 17:15
  • 3
    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.
    – Skillmon
    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).
    – egreg
    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:


combined with an:


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.