0

I'm trying to compare a and b from \f{a} and \g{b}. It could be done by redefining \f and \g so that they expand to their argument, then comparing the arguments and finally resetting \f and \g's values. But that seems really ugly. Is there a better way to do that? Something like \skip\f{x}{x}?

Thank you in advance for your answers.


I apparently failed at minimizing my problem so here is the whole thing:

\ExplSyntaxOn
\DeclareExpandableDocumentCommand \eatstart { m m } { \eat_loop:NN #1 #2 }
\DeclareExpandableDocumentCommand \eatstop { m } {}
\cs_new:Npn \eat_loop:NN #1 #2
{
  \token_if_eq_meaning:NNTF { #2 } { \eatstop }
  {
    #2
  }
  {
    \eat_loop_not_stop:NN { #1 } { #2 }
  }
}
\cs_new:Npn \eat_loop_not_stop:NN #1 #2
{
  \token_if_eq_meaning:NNTF { #2 } { #1 }
  {
    \eat_loop:NN { #1 }
  }
  {
    \token_if_expandable:NTF { #2 }
    {
      \expandafter\eat_loop:NN\expandafter#1#2
    }
    {
      #2
    }
  }
}
\ExplSyntaxOff


\begin{document}
\newcommand{\plop}{o}
\newcommand{\plip}{i}
[] = [\eatstart{\plop}\plop\eatstop{\plip}\plop\eatstop{\plop}]
\end{document}

The idea is that after a \starteat\thing, all the \things are removed until a \eatstop\thing or a character is reached. My problem is that at the moment it stops at any \eatstop and I don't know how to make it stop only after a \eatstop\thing.

  • Sorry, but this is very unclear. – egreg Aug 6 '15 at 17:33
  • If you just want to gobble the macro and leave its argument, then you can use \newcommand{\gobble}[1]{}. – Werner Aug 6 '15 at 17:36
  • It's still unclear. – egreg Aug 6 '15 at 20:10
1

Are you looking for something like the following (plain TeX syntax, which also works in LaTeX, because I do not know, what you are using):

\def\comparearguments#1#2#3#4{%
  \def\argI{#2}%
  \def\argII{#4}%
  \ifx\argI\argII
    \immediate\write16{* Arguments are equal.}%
  \else
    \immediate\write16{* Arguments are not equal.}%
  \fi
}

\comparearguments\f{a}\g{b}
\comparearguments\f{abc}\g{abc}
\comparearguments\f{a}\f{b}

Result:

* Arguments are not equal.
* Arguments are equal.
* Arguments are not equal.
  • I'm sorry. I hadn't stated my problem clearly. I updated the question. – xavierm02 Aug 6 '15 at 19:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.