TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 10 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.