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.

What's wrong with this:

\documentclass{minimal}
\usepackage{xstring}
\begin{document}
\newcommand{\cim}{c1095}
\StrMid{\MakeUppercase{\cim}}{1}{1}
\StrMid{\cim}{2}{100}
\end{document}

\MakeUppercase{\cim} works but \StrMid{\MakeUppercase{\cim}}{1}{1} doesn't work. Why?

share|improve this question
    
Perhaps try \MakeUppercase{\noexpand\StrMid{\cim}{1}{1}}? Not sure the \noexpand is needed, and I can't test on this computer. –  Bruno Le Floch Jan 16 '12 at 18:45
add comment

2 Answers

up vote 5 down vote accepted

Since you don't need to uppercase the string beforehand, this is a way:

\StrMid{\cim}{1}{1}[\temp]
\expandafter\MakeUppercase\expandafter{\temp}

We store the extracted string in a temporary macro and then apply \MakeUppercase to the result.

If strings are formed by "safe" characters (printable ASCII characters), the simpler \uppercase can be used:

\StrMid{\cim}{1}{1}[\temp]\uppercase\expandafter{\temp}
share|improve this answer
    
Thanks, that works –  balping Nov 6 '11 at 14:00
add comment

The xstring package carries out an \edef (exhaustive expansion) on its argument. Stefan has suggested on approach, but depending on what you want to achieve an alternative is to create an expandable version of the upper case command. There is one built-in to expl3, which needs renaming for use in a document:

\documentclass{article}
\usepackage{xstring,expl3}
\ExplSyntaxOn
\let\MakeExpandableUppercase\tl_expandable_uppercase:n
\ExplSyntaxOff
\begin{document}
\newcommand{\cim}{c1095}
\StrMid{\MakeExpandableUppercase{\cim}}{1}{1}\space or 
\StrMid{\expandafter\MakeExpandableUppercase\expandafter{\cim}}{1}{1} ?
\StrMid{\cim}{2}{100} 
\end{document}

As I've indicated, I'm not sure what order you want the case change to happen in, relative to the string extraction.

share|improve this answer
add comment

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.