AlphAlph 和 clist_item 之间的字符串比较失败

AlphAlph 和 clist_item 之间的字符串比较失败

我正在尝试比较逗号分隔列表的结果AlphAlph和索引。为什么这不起作用?

平均能量损失

%! TEX PROGRAM = pdflatex
\documentclass[a4paper]{article}

\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{alphalph,xparse,ifthen}

\ExplSyntaxOn
\NewDocumentCommand { \giveme } { m m }
{\clist_item:nn {#1}{#2}}

\NewDocumentCommand{\test}{m}{
\edef\first{\AlphAlph{1}\AlphAlph{1}}
\edef\second{\giveme{#1}{1}}
Values\\
\first\\
\second\\

\ifthenelse{\equal{\detokenize{\first}}{\detokenize{\second}}}
    {True}
    {False}
}
\ExplSyntaxOff
\begin{document}
\test{AA,AB,AC,BA,BB,BC,CA,CB,CC}

\end{document}

答案1

您应该移除\detokenize并使其\giveme可扩展。

\documentclass[a4paper]{article}

\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{alphalph,xparse,ifthen}

\ExplSyntaxOn
\NewExpandableDocumentCommand { \giveme } { m m }
 {
  \clist_item:nn {#1}{#2}
 }

\NewDocumentCommand{\test}{m}
 {
  \edef\first{\AlphAlph{1}\AlphAlph{1}}
  \edef\second{\giveme{#1}{1}}
  \noindent Values\\
  \first\\
  \second\\
  \ifthenelse{\equal{\first}{\second}}
    {True}
    {False}
}
\ExplSyntaxOff

\begin{document}

\test{AA,AB,AC,BA,BB,BC,CA,CB,CC}

\end{document}

在此处输入图片描述

ifthen当然没有必要。

\documentclass[a4paper]{article}

\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{alphalph,xparse}

\ExplSyntaxOn
\NewDocumentCommand{\test}{m}
 {
  \noindent Values\\
  \AlphAlph{1}\AlphAlph{1}\\
  \clist_item:nn {#1}{1}\\
  \str_if_eq:eeTF { \AlphAlph{1}\AlphAlph{1} } { \clist_item:nn {#1}{1} }
    {True}
    {False}
}
\ExplSyntaxOff

\begin{document}

\test{AA,AB,AC,BA,BB,BC,CA,CB,CC}

\end{document}

相关内容