`\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

パッケージを使用できますetl。これは、 の完全に拡張可能な形式\tl_if_in:nnTF( という名前\etl_if_in:nnTF) を定義します。 の関数は同等のものetlよりも遅いためexpl3、拡張可能にする必要がある場合にのみこれを使用する必要があることに注意してください。

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

ここに画像の説明を入力してください

関連情報