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.




\renewcommand{\tmpc}{abcdefg} \noindent tmpc: \tmpc \\
\renewcommand{\tmpa}{\meaning\tmpc} tmpa: \tmpa \\
len: \StrLen{\tmpa} \\
char(20): \StrChar{\tmpa}{20}[\tmpb] \tmpb \\
pos(f): \StrPosition{\tmpa}{f} 



tmpc: abcdefg

tmpa: \long macro:->abcdefg

len: 21

char(20): f

pos(f): 0  

Why? tmpa obviously contains character 'f' on the position of 20 as we can find it with \StrChar. But that 'f' not the same as the one we are trying to find with StrPos. I thought about catcode differences, but did not find anything usable (I might be wrong with changing catcode of 'f' before searching for it).

share|improve this question

1 Answer 1

up vote 6 down vote accepted

\meaning\tmpc produces a string where all characters have category code 12 (but spaces have category code 10). When you compare the strings, the category code 11 f is not found.

The working of \StrPosition uses delimited argument macros and the delimiter must be the same both for character code and category code.

Indeed, if you say \StrPosition{\tmpa}{\string f} the printed result is 20 (\StrPosition does complete expansion).

share|improve this answer
this "delimited argument macros and the delimiter" slightly obscure to me, but alltoghether, I understand and well, I am new in latex.:) –  pmks Apr 16 '12 at 7:31
the use of \string f is clear but how can I use \string before a macro? e.g. \string\mymacro results in "\mymacro" –  pmks Apr 16 '12 at 7:42
@pmks Yes, that's what's expected. What are you trying to achieve? –  egreg Apr 16 '12 at 11:09
I store data using \markright (counter value and sectionname) and try to get them back using \StrBetween{\firstmark}{{\delim}{\delim} but with package babel \firstmark is full of macros and \StrBetween can not cope with them. So I use \StrBetween{\meaning\firstmark}... and decently get my values. With accented chars and inputenc I get coded strings like this in my output:\IeC {\’\i }\’a\H o\’o\"u\"o. I thought that it might help to change (’) to (') and I used \StrSubstitute and run into this problem. After all, now I can change normal chars but no (’) :( –  pmks Apr 16 '12 at 13:51
@pmks It would be better to state clearly your problem about header manipulation. –  egreg Apr 16 '12 at 13:59

Your Answer


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.