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.

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 would like to take a string containing underscores and convert it to CamelCase. I am attempting to do this using the stringstrings package. Here is my code:


\convertchar[q]{test_string}{\textunderscore}{ ??? }


I am not sure what to put as the third argument to \convertchar to convert the underscores to spaces. I have tried ~, quad, and . They all produce strange errors. What can I use as the third argument, or, is there another way to obtain camelcase?

share|improve this question
As you are dealing with "magic chars" I guess you have to provide the [e] (encoded) option instead of [q] to stringstrings functions. – Daniel Nov 19 '13 at 8:23
@Daniel Ah! I didn't realize. Thanks for pointing that out. – Sean Mackesey Nov 19 '13 at 8:34
I have provided this now as an answer. If this answer serves your needs better as the other answer (wrt. using stringstrings and providing the CamelCase), you should move the accept mark to it, as this helps further visitors to figure what has solved your requirements. Note that at this site it is considered generally a good idea to wait for a couple of days before accepting an answer. – Daniel Nov 19 '13 at 9:21
@Daniel is right. Feel free to give him the checkmark if his answer is more satisfactory than mine is. – Jubobs Nov 19 '13 at 10:07
up vote 4 down vote accepted

When chaining stringstrings commands, you should work with the encoded form (given by the [e] option) until the very last command:


\convertchar[e]{test_string}{_}{ }


enter image description here

Basically, [e]-mode works like [q]-mode in that it does not produce any output, but makes sure that special characters (such as _) do not get expanded prematurely. This is generally required, if \thestring is fed into another stringstring command. The big benefit of this approach is that you can prevent \expandafter chains if composing string manipulation commands. §2 of the stringstrings manual explains this in detail.

share|improve this answer

Here is an easy way of substituting spaces for underscores in a string (with the xstring package).

enter image description here




\StrSubstitute{\myStringWithUnderscores}{_}{ }[\myStringWithSpaces]

% just for showing the results
Original string & \texttt{\expandafter\detokenize\expandafter{\myStringWithUnderscores}}\\
Final string    & \texttt{\myStringWithSpaces}


As for converting to CamelCase, well, that's not specific enough for a computer, which wouldn't automatically know which letter to make uppercase/lowercase. I guess 'converting to CamelCase' is not something that can be easily automated to great effect, and you'll probably have to do it on a string-by-string basis.

share|improve this answer
CamelCase usually just means uppercasing all words and joining them together, no other processing needed, e.g. ManIsARationalAnimalSoAtLeastIHaveBeenTold – SztupY Nov 19 '13 at 11:04
In that case, that's easy; but I'm not sure that's exactly what the OP wants. – Jubobs Nov 19 '13 at 11:21

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.