1

I have a command that (beyond my control) evaluate into a token list, and I want to compare it to a given string, I tried to follow this answer and create a variant on \tl_if_eq:

\ExplSyntaxOn

\NewDocumentCommand{\cmp}{mm}
{
    \tl_set:Nn \l_r_tl { #1 }
    \cs_generate_variant:Nn \tl_if_eq:nnTF { o }
    \tl_if_eq:onTF { \l_r_tl } { #2 } { True } { False }
    %% I also tried:
    % \tl_if_eq:onTF { #1 } { #2 } { True } { False }
}
\tl_new:N \l_r_tl

% The actual command I am using retrieve values using `\sys_get_shell`, so I don't have control over it
\NewDocumentCommand{\dummy}{m}{
    \tl_set:Nn \l_d_tl { #1 }
    \l_d_tl
}
\tl_new:N \l_d_tl

\ExplSyntaxOff

But seems like this doesn't seem to work if my value is passes through "dummy":

\begin{document}
\maketitle
    \cmp{test}{test} % True
    \cmp{\dummy{test}}{test} % False
    \dummy{test} % test
\end{document}

How can I get it to evaluate to "True" even when I pass on a tl from a different command?

Edit: Adding MWE as requested:

\documentclass[12pt,reqno]{article}

\usepackage{expl3}

\ExplSyntaxOn

\NewDocumentCommand{\cmp}{mm}
{
    \tl_set:Nn \l_r_tl { #1 }
    \cs_generate_variant:Nn \tl_if_eq:nnTF { o }
    \tl_if_eq:onTF { \l_r_tl } { #2 } { True } { False }
    %% I also tried:
    % \tl_if_eq:onTF { #1 } { #2 } { True } { False }
}
\tl_new:N \l_r_tl

% The actual command I am using retrieve values using `\sys_get_shell`, so I don't have control over it
\NewDocumentCommand{\dummy}{m}{
    \tl_set:Nn \l_d_tl { #1 }
    \l_d_tl
}
\tl_new:N \l_d_tl

\ExplSyntaxOff

\begin{document}
    \cmp{test}{test} % True
    \cmp{\dummy{test}}{test} % False
    \dummy{test} % test
\end{document}
5
  • Welcome to TeX.SE! Nice first question, could you edit your code to begin with your \documentclass{} and end with \end{document} though please, a Minimal Working Example (MWE) please. It makes copy and pasting easier when the code can be compiled as-is
    – JamesT
    May 27, 2023 at 15:00
  • 2
    @JamesT added a full working example May 27, 2023 at 15:05
  • Special case 2 of tex.stackexchange.com/questions/645995/… . That having said , here if you really don't have control over dummy then the problem is not solvable. Try to look at the documentation to see if the dummy has an alternative command that stores the result into some token list, then read from that token list (for which it's impossible to give a more specific answer without you explaining what the dummy is)
    – user202729
    May 27, 2023 at 15:07
  • 1
    @user202729 Thanks! \dummy is a call to \sys_get_shell:nnN, which does store the result in a tl, I inlined the call and used that variable and now it works! May 27, 2023 at 15:23
  • you should move \cs_generate_variant:Nn \tl_if_eq:nnTF { o } outside your definition you only need it once not every time May 28, 2023 at 11:27

0

You must log in to answer this question.

Browse other questions tagged .