将 shell 命令输出通过管道传输到另一个命令

将 shell 命令输出通过管道传输到另一个命令

我正在尝试编写一个命令,将\href二维码包装到给定的 URL。为此,我需要生成一个临时文件并在以后重复使用它,因此我编写了一个\mktemp包装mktemp实用程序的命令:

% 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}

如果我对 \mktep 文件名进行硬编码,则上述文档会进行编译,但是当我用 替换硬编码文件名时\input|"mktemp",会出现一个奇怪的错误:

 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.

我尝试查看test.log但找不到任何有意义的调试信息。

  1. 将一个命令的输出通过管道传输mktemp到另一个命令的正确方法是什么?
  2. 调试模糊的乳胶编译错误的好通用方法是什么?
  3. 我见过参考命令\tempfile,但我! Undefined control sequence. \mktemp -> \tempfile尝试使用它时只得到:。这个\tempfile命令在哪里定义?

我应该注意,我已经修改了我的textmf.cnf以允许命令qrencodemktemp

shell_escape_commands = \
bibtex,bibtex8,\
extractbb,\
gregorio,\
kpsewhich,\
makeindex,\
repstopdf,\
r-mpost,\
texosquery-jre8,\
qrencode,\
touch,\
mktemp,\
tr,\
mktemp-no-newline.sh,\

答案1

这似乎是一个XY问题你应该要求用 LaTeX 制作二维码。有几个包用于此.下面是一个简短的例子包裹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}

三个二维码,第一个没有链接,第二个和第三个有链接

相关内容