I'm trying to write a command that wraps \href with a QR code to the given URL. For this I need to generate a temp file and reuse it later, so I wrote a \mktemp command that wraps the mktemp utility:

% Created 2023-06-03 Sat 13:05
% Intended LaTeX compiler: pdflatex


  %% /tmp/tempfile.png

  \immediate\write18{qrencode #2 -o #1}
  \href{#2}{#3 \includegraphics[]{#1}}

\hrefqr{www.example.com}{This is example.com}

If I hard-code the \mktep filename, the document above compiles, but when I replace the hard-coded filename with \input|"mktemp", I get a weird error:

 This is pdfTeX, Version 3.14159265-2.6-1.40.21 (TeX Live 2020/Debian) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
LaTeX2e <2020-10-01> patch level 4
L3 programming layer <2021-01-09> xparse <2020-03-03>
Document Class: article 2020/04/10 v1.4m Standard LaTeX document class
(./test.aux) (/usr/share/texlive/texmf-dist/tex/context/base/mkii/supp-pdf.mkii

[Loading MPS to PDF converter (version 2006.09.02).]
) (/usr/share/texlive/texmf-dist/tex/latex/epstopdf-pkg/epstopdf-base.sty
(./test.out) (./test.out)
! Use of \\hrefqr doesn't match its definition.
\@ifnextchar ... \reserved@d =#1\def \reserved@a {
                                                  #2}\def \reserved@b {#3}\f...
l.20 \hrefqr{www.example.com}{This is example.com}
!  ==> Fatal error occurred, no output PDF file produced!
Transcript written on test.log.

I tried looking into the test.log but couldn't find any meaningful debug info.

  1. What is the proper way to pipe the output of a command like mktemp into another command?
  2. What is a good general way to debug obscure-looking latex compile errors?
  3. I've seen references to a \tempfile command, but I just get: ! Undefined control sequence. \mktemp -> \tempfile when trying to use it. Where is this \tempfile command defined?

I should note that I have modified my textmf.cnf to allow the commands qrencode and mktemp:

shell_escape_commands = \
  • catchfile package
    – user202729
    Jun 5, 2023 at 1:02
  • Just a note: QR codes can be generated without shell escape, e.g., using package qrcode. There are several other possibilities.
    – cabohah
    Jun 5, 2023 at 6:27
  • @cabohah thanks, the qrcode package is what I needed, please feel free to turn your comment into an answer.
    – user84207
    Jun 5, 2023 at 6:59

1 Answer 1


This seems to be a XY problem and you should have asked for making QR codes with LaTeX. There are several packages for this. Here a short example using package qrcode:


\qrcode*{This is example.com without link}

\href{www.example.com}{\qrcode*{This is example.com}}



three qr codes, first without, second and third with link

  • There are 3 questions, one is about how to embed a qr code. The other two are about how to use and debug latex macros. Your answer is helpful and answers one of the questions. Perhaps I should have asked 3 separate questions instead.
    – user84207
    Jun 5, 2023 at 18:41
  • @user84207 Yes, you should always ask only one question. And I've even not answered any of your questions, but the underlying problem. You should also always tell your real problem, not only the problem with your try to solve it. See the first link in my answer.
    – cabohah
    Jun 6, 2023 at 8:59
  • Even if I know how to use the qrcode package, which is very helpful, in general I would also like to know how to implement such a utility myself and to debug latex programs.
    – user84207
    Jun 6, 2023 at 16:35
  • @user84207 Just ask more questions — if they have not already have been asked like tex.stackexchange.com/questions/538/how-to-best-debug-latex or if the current questions and answers are not sufficient. In last case, you should explain your difference resp. additional needs.
    – cabohah
    Jun 7, 2023 at 9:10

You must log in to answer this question.

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