`\str_if_in:nnTF` 的布林版本 — expl3

`\str_if_in:nnTF` 的布林版本 — expl3

我如何將其用作\str_if_in:nnTF布林函數,即不帶TF參數,以便我可以在內部使用它

\bool_lazy_and:nnTF
      { \str_if_in:nn {abc} {a} }
      { ... }
      {
        true code
      }{
        false code
      }

答案1

您可以使用該套件,它定義了(named )etl的完全可擴充形式。請注意, 的函數比等效函數慢,因此只有在必須可擴展時才應該使用它。\tl_if_in:nnTF\etl_if_in:nnTFetlexpl3

\documentclass{article}

\usepackage{etl}
\ExplSyntaxOn
\cs_generate_variant:Nn \etl_if_in:nnTF { oo }
\prg_new_conditional:Npnn \antshar_str_if_in:nn #1#2 {p, TF, T, F}
  {
    \etl_if_in:ooTF { \tl_to_str:n {#1} } { \tl_to_str:n {#2} }
      \prg_return_true:
      \prg_return_false:
  }
\NewExpandableDocumentCommand \antshartest { m m }
  {
    \bool_lazy_and:nnTF
      { !\tl_if_empty_p:n {#1} }
      { \antshar_str_if_in_p:nn {#1} {#2} }
      { true }
      { false }
  }
\ExplSyntaxOff

\begin{document}
\antshartest{}{abc}

\antshartest{def{abc}def}{abc}
\end{document}

答案2

這是一個替代解決方案functional包裹:

\documentclass{article}
\usepackage{functional}
\begin{document}

\IgnoreSpacesOn
\boolVarAndTF {\strIfIn {abc} {a}} {\intCompare {1} < {2}} {
  \prgReturn{True}
} {
  \prgReturn{False}
}
\IgnoreSpacesOff

\end{document}

在此輸入影像描述

相關內容