这有效
\newcommand
之内qrcode
。
\documentclass{article}
\usepackage{qrcode}
\newcommand{\aaa}{test1}
\newcommand{\aab}{test2}
\newcommand{\aac}{test3}
\begin{document}
\qrcode[height=5cm]{www.domain.tld/\aaa}
\qrcode[height=5cm]{www.domain.tld/\aab}
\qrcode[height=5cm]{www.domain.tld/\aac}
\end{document}
这也有效
\newcommand
与内的论点qrcode
。
\documentclass{article}
\usepackage{qrcode}
\newcommand{\mylink}[1]{#1}
\begin{document}
\qrcode[height=5cm]{www.domain.tld/\mylink{test1}}
\qrcode[height=5cm]{www.domain.tld/\mylink{test2}}
\qrcode[height=5cm]{www.domain.tld/\mylink{test3}}
\end{document}
这不管用
\newcommand
带有参数(包含案例) 之内qrcode
。
\documentclass{article}
\usepackage{qrcode}
\usepackage{xstring}
\newcommand{\mylink}[1]{%
\IfEqCase{#1}{%
{1}{test1}%
{2}{test2}%
{3}{test3}%
% you can add more cases here as desired
}[\PackageError{mylink}{Undefined option to tree: #1}{}]%
}%
\begin{document}
\qrcode[height=5cm]{www.domain.tld/\mylink{1}}
\qrcode[height=5cm]{www.domain.tld/\mylink{2}}
\qrcode[height=5cm]{www.domain.tld/\mylink{3}}
\end{document}
我怎样才能解决这个问题?
答案1
\IfEqCase
不可扩展,这会导致错误。请使用\ifcase
可扩展的原语:
\def\mylink#1{%
\ifcase#1\or test1\or test2\or test3\else\errmessage{something wrong}\fi
}
答案2
你需要一个可扩展案例切换:
\documentclass{article}
\usepackage{qrcode}
\usepackage{xparse}
\ExplSyntaxOn
\cs_new_eq:NN \stringcase \str_case:nnF
\ExplSyntaxOff
\newcommand{\mylink}[1]{%
\stringcase{#1}{%
{1}{test1}%
{2}{test2}%
{3}{test3}%
% you can add more cases here as desired
}{\PackageError{mylink}{Undefined option to tree: #1}{}}%
}
\begin{document}
\qrcode[height=5cm]{www.domain.tld/\mylink{1}}\par\bigskip
\qrcode[height=5cm]{www.domain.tld/\mylink{2}}\par\bigskip
\qrcode[height=5cm]{www.domain.tld/\mylink{3}}
\end{document}
日志文件有
<Reading QR code for "www.domain.tld/test1" at level 2-Q from aux file.>
<Reading QR code for "www.domain.tld/test2" at level 2-Q from aux file.>
<Reading QR code for "www.domain.tld/test3" at level 2-Q from aux file.>
需要注意的是,的参数\mylink
不仅限于数字,因此
\newcommand{\mylink}[1]{%
\stringcase{#1}{%
{One}{test1}%
{Two}{test2}%
{Three}{test3}%
% you can add more cases here as desired
}{\PackageError{mylink}{Undefined option to tree: #1}{}}%
}
等等\mylink{One}
也可以。