\ifdefstring 與邏輯運算符,可能嗎?

\ifdefstring 與邏輯運算符,可能嗎?
        \ifdefstring{command}{str1 OR str2}{yes}{no}

需要實現類似上述的目標。是否可以對 \ifdefstring 的字串部分使用邏輯運算子?

包裹 :etoolbox

命令=字串類型

我添加etoolbox到這個項目並使用\ifdefstring 來源:https://github.com/posquit0/Awesome-CV

答案1

您可以建立一個布林表達式:

\documentclass{article}
\usepackage{etoolbox}

\makeatletter
\newcommand{\ifdefstringor}[2]{%
  \begingroup\edef\x{\endgroup
    \noexpand\ifboolexpr{
      test {\noexpand\ifdefstring{\noexpand#1}{\@firstoftwo#2}}
      or
      test {\noexpand\ifdefstring{\noexpand#1}{\@secondoftwo#2}}
    }%
  }\x
}
\makeatother

\newcommand{\fooA}{str1}
\newcommand{\fooB}{str2}
\newcommand{\fooC}{str3}

\begin{document}

\ifdefstringor{\fooA}{{str1}{str2}}{yes}{no}

\ifdefstringor{\fooB}{{str1}{str2}}{yes}{no}

\ifdefstringor{\fooC}{{str1}{str2}}{yes}{no}

\ifdefstringor{\fooD}{{str1}{str2}}{yes}{no}

\end{document}

在此輸入影像描述

相關內容