0

I'm working with the stringstrings package. It has a command called \gobblechar which removes the first character in a string or token. Kindly see my MWE below.

\documentclass{article}
\usepackage{stringstrings}
\begin{document}
\def\myAnyString{\gobblechar{v}{Any String}}
\myAnyString
\end{document}

I'm expecting that the first character of "Any String" will be removed. Thus, I'm expecting the output of \myAnyString will be ny String.

However, the output is still Any String.

In the documentation, it says that the result of \gobblechar is \def'ed, instead of \edef'ed. I'm not sure at the moment about the relevance of this, but I know it is very important.

Im thinking no macro expansion has happened in my MWE. But since i have given/executed the command \myAnyString, then it must have expanded already. However, it seems it has not.

There are other packages that can do the job, like \StrGobbleLeft of the xstring package, but if the argument contains commands (for example, if Any String becomes \textbf{Any String}), \StrGobbleLeft fails. But \gobblechar{v}{\textbf{Any String}} will still work, but its output is still Any String only in bold, but the first character is still not removed.

Kindly seeking your help.

David Carlisle
  • 757,742

1 Answers1

1

You're misunderstanding what v is for:

\gobblechar[v]{Any String}

will output “ny String”, but \gobblechar{v} will output nothing. Note the brackets instead of the braces. And [v] can be omitted.

However, your \def does not set \myAnyString to ny String. In order to do that you need

\gobblechar[q]{Any String}\edef\myAnyString{\thestring}

but note that the space will become \ (backslash-space).

Since it's not really clear what your aim is, I cannot tell more.

egreg
  • 1,121,712
  • hi sir egreg, thank you about the [v] vs {v}. i think the documentation has some unclear/conflicting portions. it says that there are 2 arguments to gobblechar in its definition, that is why i used braces for the first and second arguments. nevertheless, as regards the gobblechar, indeed your suggestion \gobblechar[q]{Any String}\edef\myAnyString{\thestring} worked. – beethovengg14 Jun 18 '21 at 14:55
  • however, i failed to mention that my real interest is in the case where the input string is composed of not only pure strings, but a combination of pure strings and other commands where the first character is alphabetic. for example, for the command \gobblechar[q]{Normal Text and \textbf{Bold Text} and \textit{Italic Text} and $\mathcommands\here$}\edef\myAnyString{\thestring}, I am expecting the result ''ormal Text and \textbf{Bold Text} and \textit{Italic Text} and $\mathcommands\here$'', that is, only the first character was removed, but the other strings and commands remain as is. – beethovengg14 Jun 18 '21 at 14:55
  • may i seek your help how to do this? is this not as simple as it looks? – beethovengg14 Jun 18 '21 at 14:55
  • 1
    @beethovengg14 Please, make a new question with the details – egreg Jun 18 '21 at 15:08
  • new question was asked: https://tex.stackexchange.com/questions/601801/removing-the-first-character-in-a-combination-of-strings-and-commands-tokens-usi – beethovengg14 Jun 18 '21 at 15:30