1

I'd like to define a command that functions like:

\def\foo#1{...}   % function over single letters (e.g. making upper cases)
\def\bar#1{...}   % function over a paragraph by replacing each single letter with \foo

How can I reach this purpose?

OrthoPole
  • 113
  • 1
    Is this a TeX question? That is, are you interested in leaning how to achieve this using plain TeX? – Jasper Habicht Apr 04 '23 at 07:08
  • Yes. I want to define the macro \bar, but I don't know how. – OrthoPole Apr 04 '23 at 07:44
  • I've posted my own solution I've just found out. Any other ideas are welcomed. – OrthoPole Apr 04 '23 at 07:57
  • What is meant by "go through all single letters in the parameter"? Does the macro argument contain tokens other than what you consider letters so that distinguishing letters from whatsoever non-letters is needed? What is meant by letters - just a-z and A-Z? How to handle \letterA after \let\letterA=A? How to handle expandable tokens where expansion at some point might deliver letters? Might multibyte-utf-8-characters on a traditional 8-bit-TeX-engine be an issue? || You might be interested in l3regex. – Ulrich Diez Apr 04 '23 at 08:37
  • See also https://tex.stackexchange.com/questions/233085/basics-of-parsing?r=SearchResults&s=1%7C39.4642 Paragraphs are tricky. They can end with a blank line, a \par, a } or \end{...}. The only reliable method is \everypar, which runs at the begining of the next paragraph. – John Kormylo Apr 04 '23 at 12:09

1 Answers1

0

It seems that the following codes work:

\def\bar<#1#2>{\foo{#1}\if&#2&\else\bar<#2>\fi}

And \bar<Hello> will obtain HELLO if we define \def\foo\uppercase.

However, this cannot read spaces. \bar<Hello World> will obtain HELLOWORLD.

OrthoPole
  • 113