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.

When I try to compile the minimal example below, I get an error:

! Argument of \@xs@StrLeft has an extra }.
<inserted text> 
                \par 
l.33 \setInSCCF{abcdef}

If I switch the usage of \setInSC to \textbf in the \setInSCCF command, then it works. So there must be something related to the \setInSC command. However, \setInSC works fine when used on its own. I tried expanding the argument first but to no avail (don't know if I did it correctly, though).

\documentclass[a4paper, 11pt]{article}

\usepackage{textcase}
\usepackage{xstring}

\makeatletter
\DeclareRobustCommand{\setInSC}[1]{%
  \ifx\f@shape\code@Roman
    \expandafter\textsc{\MakeTextLowercase{#1}}%
  \else
    \ifdim\fontdimen\@ne\font>\z@
      \begingroup
      \check@mathfonts
      \fontsize\sf@size\z@\selectfont
      \let\MakeTextLowercase\@firstofone
      \expandafter\MakeUppercase{#1}%
      \endgroup
    \else
      \expandafter\MakeTextUppercase{#1}%
    \fi
  \fi
}
\newcommand*{\code@Roman}{n}
\newcommand*{\code@Italics}{it}
\makeatother

\DeclareRobustCommand{\setInSCCF}[1]{%
  \StrLeft{#1}{1}\setInSC{\StrGobbleLeft{#1}{1}{}}%
}


\begin{document}
\setInSCCF{abcdef}
\end{document}
share|improve this question
    
Would you tell us what the macros are supposed to do? –  egreg Jan 5 '12 at 19:04
    
@egreg: The macro is suppose to always capitalize the first letter, and set the remainder in small caps using \setInSC. Just realized now that the first letter is just left untouched, but that's another problem. =) –  gablin Jan 5 '12 at 19:08
    
None of the \expandafter do anything here. –  Bruno Le Floch Jan 5 '12 at 19:50

1 Answer 1

up vote 2 down vote accepted

You cant use StrGobbleLeft as an argument of a command. You need a temp-command to save the result.

\DeclareRobustCommand{\setInSCCF}[1]{%
  \StrLeft{#1}{1}%
  \StrGobbleLeft{#1}{1}[\tempa]%
  \setInSC{\tempa}%
}

The complete example:

\documentclass[a4paper, 11pt]{article}

\usepackage{textcase}
\usepackage{xstring}

\makeatletter
\DeclareRobustCommand{\setInSC}[1]{%
  \ifx\f@shape\code@Roman
    \textsc{\MakeTextLowercase{#1}}%
  \else
    \ifdim\fontdimen\@ne\font>\z@
      \begingroup
      \check@mathfonts
      \fontsize\sf@size\z@\selectfont
      \let\MakeTextLowercase\@firstofone
      \MakeUppercase{#1}%
      \endgroup
    \else
      \MakeTextUppercase{#1}%
    \fi
  \fi
}
\newcommand*{\code@Roman}{n}
\newcommand*{\code@Italics}{it}
\makeatother

\DeclareRobustCommand{\setInSCCF}[1]{%
  \StrLeft{#1}{1}%
  \StrGobbleLeft{#1}{1}[\tempa]%
  \setInSC{\tempa}%
}


\begin{document}
\setInSCCF{abcdef}
\end{document}

To split the string you can avoid xstring with the following code:

\documentclass[a4paper, 11pt]{article}
\makeatletter
\def\setIn#1{\@setIn#1\@nil}
\def\@setIn#1#2\@nil{%
Input One: #1\par
Input two: #2%
}
\makeatother
\begin{document}
\setIn{abcdef}
\end{document}
share|improve this answer
    
No, because you've removed the macro \setInSCCF, which was the one I had problems with. \setInSCCF invokes \setInSC, which works fine. –  gablin Jan 5 '12 at 19:27
    
I want to capitalize the first letter, and set the remainder in small caps. For this, I need to split the string, for which I use xstring. –  gablin Jan 5 '12 at 19:36
    
@gablin: Now I understand your question. Please see my edits –  Marco Daniel Jan 5 '12 at 19:44
    
I read up on how xstring works and realized the same thing (that the xstring commands cannot be expanded), but I'll accept your answer since you probably beat me to it. =) –  gablin Jan 5 '12 at 19:57

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.