Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 8 down vote accepted

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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