1

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.

5
  • pls ignore the apostrophes in Any String. I wrote it as ``Any String'', but the first quotation marks were removed. :) Jun 18 at 6:24
  • 1
    the backick does not make a left quote it is the markdown for the start of a verbatim code section, or three bacticks for a multi-line code block, I fixedup the markdown. Jun 18 at 7:25
  • 1
    The \gobblechar macro uses a single argument ! Try \gooblechar{Any String}... Jun 18 at 8:02
  • hi @PaulGaborit, thank you. \gooblechar{Any String} indeed works! Jun 18 at 14:57
  • hi @DavidCarlisle, thank you for editing. Jun 18 at 14:58
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.

5
  • 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. Jun 18 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. Jun 18 at 14:55
  • may i seek your help how to do this? is this not as simple as it looks? Jun 18 at 14:55
  • 1
    @beethovengg14 Please, make a new question with the details
    – egreg
    Jun 18 at 15:08
  • new question was asked: tex.stackexchange.com/questions/601801/… Jun 18 at 15:30

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.