# Having trouble with IfStrEq from xstring

precondition: The filename is lab00.tex

\def\fn{\jobname}

\StrLeft{\fn}{1}[\firstChar]

\IfStrEq{\firstChar}{l}{true}{false}


The result is “false”, because although the package claims to compare “strings”, it actually takes into consideration category codes.

The first character in your \jobname is an l of category code 12, by general rule of TeX about generated strings of characters. However, you're comparing it with a standard category code 11 l.

You could do

\def\fn{\jobname}
\StrLeft{\fn}{1}[\firstChar]
\IfStrEq{\firstChar}{\detokenize{l}}{true}{false}


because \detokenize uses the same internal machinery that outputs characters with category code 12.

• Perfect! Thanks! Sep 6, 2020 at 18:55