2

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. it has been revised as per inputs from @egreg.

\documentclass{article}
\usepackage{amsmath}
\usepackage{stringstrings}
\begin{document}
\gobblechar[q]{Normal Text and \textbf{Bold Text} and \textit{Italic Text} and math commands like $a_{\text{c}}=\frac{v^2}{r}$}
\edef\myAnyString{\thestring}
\myAnyString
\end{document}

I'm expecting my argument to \gobblechar to be a combination of strings and commands, where the first character is alphabetic.

in the MWE above, the argument is

Normal Text and \textbf{Bold Text} and \textit{Italic Text} and math commands like `$a_{\text{c}}=\frac{v^2}{r}$

and the first character, ''N'', is alphabetic. I'm trying to output the same argument but without the first character.

Thus, my expected output is

ormal Text and Bold Text and Italic Text and math commands like $a_{\text{c}}=\frac{v^2}{r}$.

Note that there is no problem if the argument were a pure string. for example, if the argument is ''Normal Text'', the output of the MWE above is ''ormal Text''. The problem, I believe, is when the argument is a combination of strings and commands.

Kindly seeking your help how to achieve this. Im beginning to think the problem is not so simple as it looks.

5
  • the argument may come from book or article titles which may contain both pure strings and commands – beethovengg14 Jun 18 at 15:32
  • i forgot, i should include \usepackage{amsmath} – beethovengg14 Jun 18 at 15:34
  • 1
    Why are you gobbling? Are you perhaps wanting to do some case changing? – Joseph Wright Jun 18 at 15:52
  • @JosephWright yes, i wanted to separate my amsrefs content and publisher house styles, like that of apa7th edition. amsrefs bibliography will print it as is. but in case a different style is needed, like that of apa (or another style) which converts everything to lowercase, what i would want is for some capitalized texts in the title to remain capitalized eventhough everything else was lowercased. this makes sense and is more accurate. i have tried numerouse built in commands, to no avail, or i guess i still have to learn a lot from TeX/LaTeX – beethovengg14 Jun 18 at 15:58
  • once i have gobbled, and obtained the new text, i can just apply a lowercasing command to it. the capitalized portions in the text will not be affected by the lowercasing commands since these capitalized texts were \MakeUppercase'd – beethovengg14 Jun 18 at 16:00
3

This looks like an X-Y question. Anyway, you can use expl3 instead:

\documentclass{article}
\usepackage{amsmath}

\ExplSyntaxOn

\NewExpandableDocumentCommand{\gobblefirst}{m}
 {
  \tl_tail:n { #1 }
 }

\ExplSyntaxOff

\begin{document}

\gobblefirst{Normal Text and \textbf{Bold Text} and \textit{Italic Text} 
  and math commands like $a_{\mathrm{c}}=\frac{v^2}{r}$}

\end{document}

enter image description here

6
  • hi @egreg, thank you! i will try this solution of yours. may i just ask what expl3 is. – beethovengg14 Jun 18 at 16:09
  • hi @egreg, your solution worked! may i know what an X-Y question is? thank you – beethovengg14 Jun 18 at 16:10
  • 1
    @beethovengg14 An X-Y issue is where you ask something (X) but really need to solve something else (Y) – Joseph Wright Jun 18 at 16:11
  • just realized expl3 is Wrapper package for experimental LaTeX3 – beethovengg14 Jun 18 at 16:33
  • @JosephWright oh ok. i think it's the same in my line of work in math and engg. you have to solve some big problem (Y), but actually you can solve it by just solving a smaller problem (X). thank you sir – beethovengg14 Jun 18 at 16:37
3

This looks like a job for expl3

\documentclass{article}
\usepackage{amsmath}
\ExplSyntaxOn

\NewExpandableDocumentCommand{\ExplTitlecase}{m}
 {
  \text_titlecase:n { #1 }
 }

\ExplSyntaxOff

\begin{document}

\ExplTitlecase{Normal Text and \textbf{Bold Text} and \textit{Italic Text} 
  and math commands like $a_{\mathrm{c}}=\frac{v^2}{r}$}
  
\ExplTitlecase{normal Text and \textbf{Bold Text} and \textit{Italic Text} 
  and math commands like $a_{\mathrm{c}}=\frac{v^2}{r}$}

\ExplTitlecase{$a$ text and \textbf{Bold Text} and \textit{Italic Text} 
  and math commands like $a_{\mathrm{c}}=\frac{v^2}{r}$}

\end{document}
5
  • thank you sir. i will also try your perspective... – beethovengg14 Jun 18 at 16:17
  • sir your solution also worked. it employed the straightforward approach. both yours and egreg' solution answered by question. thank you. i gues i need to study this expl3 thing – beethovengg14 Jun 18 at 16:29
  • just realized expl3 is Wrapper package for experimental LaTeX3 – beethovengg14 Jun 18 at 16:34
  • 1
    @beethovengg14 Not really any more: it's just the name of the programming layer developed by the LaTeX team – Joseph Wright Jun 18 at 16:35
  • hi sir @JosephWright, i have posted a new question, "Preserving the mixed-case of a word within a set of words that was previously set in title case", tex.stackexchange.com/questions/606307/…, wherein I used a command you suggested. kindly seeking help – beethovengg14 Jul 25 at 7:12

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.