I would like to do a simple \StrSplit (from the xstring package) on a string I have, however, the string in question may contain a \par, and it appears that \@xs@StrSpl@t@@, which I can only imagine is an internal xstring macro, is not a long macro, so it causes an error.

Are there any workarounds? Other packages with similar functionality that accept long strings? A way to remove \par temporarily and put it back later?

EDIT: I only actually need to split off the first character, so if there's a way to do that directly on arbitrary strings (with the semantics of \noexpand), that would work too.


You can try this to get the first character:



\test{This is \par something}


The macro gets the first letter and stores it in another macro called storeone. I am not sure what you want to do exactly, other than get the first letter, perhaps you can expand on your question a bit. You can also have a look at source2e, there are similar commands such as \@firstoftwo.

  • Why the makeatletter there? You don't seem to use @. – coppro Jan 14 '13 at 5:58
  • @centrifugal force:) You right they are not needed, I just typed them planning to use @ and then thought I maybe obscuring the concepts. – Yiannis Lazarides Jan 14 '13 at 6:19
  • Also, this solution doesn't work if the string contains a semicolon; I need it to work for (nearly) arbitrary text. I was thinking maybe something clever with \futurelet to remove a token from the stream and then put it back. EDIT: picked a dummy command as a delimiter. Still doesn't handle curly-brace constructs well. I'm thinking maybe there's a futurelet trick? – coppro Jan 14 '13 at 6:28
  • @copro The delimiting is not a big issue, you can delimit it with anything else you want (say @end). However, if you want to catch any type of character is another issue. Then futurelet is the answer. See how \@ifnextchar works, you need to clarify your case a bit better. – Yiannis Lazarides Jan 14 '13 at 6:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.