1

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

\documentclass[11pt]{article}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{pdftexcmds}

\newcommand{\mktemp}[0]{
  \input|"mktemp"
  %% /tmp/tempfile.png
}

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

\begin{document}
\hrefqr{www.example.com}{This is example.com}
\end{document}

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
(/home/ealfonso/git/keto/test.tex
LaTeX2e <2020-10-01> patch level 4
L3 programming layer <2021-01-09> xparse <2020-03-03>
(/usr/share/texlive/texmf-dist/tex/latex/base/article.cls
Document Class: article 2020/04/10 v1.4m Standard LaTeX document class
(/usr/share/texlive/texmf-dist/tex/latex/base/size11.clo))
(/usr/share/texlive/texmf-dist/tex/latex/graphics/graphicx.sty
(/usr/share/texlive/texmf-dist/tex/latex/graphics/keyval.sty)
(/usr/share/texlive/texmf-dist/tex/latex/graphics/graphics.sty
(/usr/share/texlive/texmf-dist/tex/latex/graphics/trig.sty)
(/usr/share/texlive/texmf-dist/tex/latex/graphics-cfg/graphics.cfg)
(/usr/share/texlive/texmf-dist/tex/latex/graphics-def/pdftex.def)))
(/usr/share/texlive/texmf-dist/tex/latex/hyperref/hyperref.sty
(/usr/share/texlive/texmf-dist/tex/generic/ltxcmds/ltxcmds.sty)
(/usr/share/texlive/texmf-dist/tex/generic/iftex/iftex.sty)
(/usr/share/texlive/texmf-dist/tex/generic/pdftexcmds/pdftexcmds.sty
(/usr/share/texlive/texmf-dist/tex/generic/infwarerr/infwarerr.sty))
(/usr/share/texlive/texmf-dist/tex/generic/kvsetkeys/kvsetkeys.sty)
(/usr/share/texlive/texmf-dist/tex/generic/kvdefinekeys/kvdefinekeys.sty)
(/usr/share/texlive/texmf-dist/tex/generic/pdfescape/pdfescape.sty)
(/usr/share/texlive/texmf-dist/tex/latex/hycolor/hycolor.sty)
(/usr/share/texlive/texmf-dist/tex/latex/letltxmacro/letltxmacro.sty)
(/usr/share/texlive/texmf-dist/tex/latex/auxhook/auxhook.sty)
(/usr/share/texlive/texmf-dist/tex/latex/kvoptions/kvoptions.sty)
(/usr/share/texlive/texmf-dist/tex/latex/hyperref/pd1enc.def)
(/usr/share/texlive/texmf-dist/tex/generic/intcalc/intcalc.sty)
(/usr/share/texlive/texmf-dist/tex/generic/etexcmds/etexcmds.sty)
(/usr/share/texlive/texmf-dist/tex/latex/url/url.sty)
(/usr/share/texlive/texmf-dist/tex/generic/bitset/bitset.sty
(/usr/share/texlive/texmf-dist/tex/generic/bigintcalc/bigintcalc.sty))
(/usr/share/texlive/texmf-dist/tex/latex/base/atbegshi-ltx.sty))
(/usr/share/texlive/texmf-dist/tex/latex/hyperref/hpdftex.def
(/usr/share/texlive/texmf-dist/tex/latex/base/atveryend-ltx.sty)
(/usr/share/texlive/texmf-dist/tex/latex/rerunfilecheck/rerunfilecheck.sty
(/usr/share/texlive/texmf-dist/tex/generic/uniquecounter/uniquecounter.sty)))
(/usr/share/texlive/texmf-dist/tex/latex/l3backend/l3backend-pdftex.def)
(./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
(/usr/share/texlive/texmf-dist/tex/latex/latexconfig/epstopdf-sys.cfg))
(/usr/share/texlive/texmf-dist/tex/latex/hyperref/nameref.sty
(/usr/share/texlive/texmf-dist/tex/latex/refcount/refcount.sty)
(/usr/share/texlive/texmf-dist/tex/generic/gettitlestring/gettitlestring.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 = \
bibtex,bibtex8,\
extractbb,\
gregorio,\
kpsewhich,\
makeindex,\
repstopdf,\
r-mpost,\
texosquery-jre8,\
qrencode,\
touch,\
mktemp,\
tr,\
mktemp-no-newline.sh,\
3
  • 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

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:

\documentclass[11pt]{article}
\usepackage{qrcode}
\usepackage{hyperref}

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

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

\qrcode{www.example.com}

\end{document}

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

4
  • 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 .