6

i'd like to test if a string, once transformed into lowercase is equal to a given string. Here a MWE of what i'm talking about :

\documentclass[a4paper,10pt]{report}
\usepackage[francais]{babel}
\begin{document} 

\def\planeone{AirForce1}
\def\planetwo{airforce1}
\edef\planethree{\lowercase{\planeone}}

\planetwo{ and  }\planethree{ are }
\ifx\planetwo\planethree{the same}\else{not the same}\fi.

\end{document}

Of course when i test \meaning\planetwo and \meaning\planethree i can see the two commands are not the same, but i just want to test what they expand to.

I tried a few \expandafter here and there, but without any success.

11

\lowercase is not expandable, so you're doing the same as

\def\planethree{\lowercase{AirForce1}}

and therefore \planethree is different from \planetwo.

You can do

\lowercase\expandafter{\expandafter\def\expandafter\planethree\expandafter{\planeone}}

but a different strategy can be better for more complex situations:

\begingroup\edef\x{%
\lowercase{\endgroup
  \def\noexpand\planethree{\planeone}}}%
\x

With this code you delay the application of \lowercase when the replacement text for \planethree has already been completely expanded.

Let's see how it works.

  1. The \begingroup is used just to set a temporary value to \x

  2. We \edef the macro \x, so \planeone will be completely expanded as it should, but \lowercase, \def and \planethree are left untouched

  3. After the \edef, the replacement text of \x will be

    \lowercase{\endgroup\def\planethree{Airforce1}}
    
  4. Executing \x will do the \lowercase that will change the case of the letters

  5. After that operation,

    \endgroup\def\planethree{airforce1}
    

    is put back in the main input stream, so the group started with \begingroup is ended and the definition is performed.

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.