GeneralHow to amalgamate commands?

LaTeX specific issues not fitting into one of the other forums of this category.
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

How to amalgamate commands?

Post by gmedina »

After re-reading this thread, I still wonder, as localghost did, in which way would that make typesetting easier?
1,1,2,3,5,8,13,21,34,55,89,144,233,...

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

How to amalgamate commands?

Post by Juanjo »

Summing up, the problem posed in the first post can be stated as follows: given a command, say \foo, which applies to single characters, find a simple way to define, for any character X, a command \fooX that behaves as \foo{X}. After seeking a solution, I conclude that the more stable (even simplest) way to do that is by defining individually each \fooX command. In fact, it seems that things, when needed, are done in the reverse order: first one has the \fooX commands, then one defines \foo so as \foo{X} acts as \fooX. At least, this is what gaius reports about the wrisym package.
gmedina wrote: After re-reading this thread, I still wonder, as localghost did, in which way would that make typesetting easier?

In my opinion, there is no real interest in having at one's disposal the \fooX commands. Perhaps this may save some keystrokes or be helpful when doing searches in the source files (it is easier to search for \fooX than for \foo{X} and variations as \foo X, \foo <carriage return> X,...) I don't see much more applications.

Anyway, the problem is challenging and helps learn a bit more about the intricacies of TeX.
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

How to amalgamate commands?

Post by gmedina »

Juanjo wrote: In my opinion, there is no real interest in having at one's disposal the \fooX commands. Perhaps this may save some keystrokes or be helpful when doing searches in the source files (it is easier to search for \fooX than for \foo{X} and variations as \foo X, \foo <carriage return> X,...) I don't see much more applications.

Anyway, the problem is challenging and helps learn a bit more about the intricacies of TeX.

Agreed, it's challenging. But I guess it would generate some ¿major? modifications to the parsing procedures used by TeX, or maybe not? After all, some commands allow this kind of syntax:
\newcommand{\foo}[1]{...}
and
\newcommand\foo[1]{...}
are treated equivalently.
But what if there's more than one expected token?
1,1,2,3,5,8,13,21,34,55,89,144,233,...
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

How to amalgamate commands?

Post by Juanjo »

gmedina wrote: But I guess it would generate some ¿major? modifications to the parsing procedures used by TeX, or maybe not? After all, some commands allow this kind of syntax:
\newcommand{\foo}[1]{...}
and
\newcommand\foo[1]{...}
are treated equivalently.
But what if there's more than one expected token?

I think that the definition of the \fooX commands is just a convenience of some users, as shorthands. The parsing procedures of TeX are not affected. Likewise, if more than one token is expected as argument of the \foo command, one can apply the same principle. Try the following, which refers to the case of two tokens:

Code: Select all

\documentclass{article}
\newcommand{\foo}[2]{These are letters~\fbox{#1} and~\fbox{#2}}
\makeatletter
 \@for\tempa:={A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z}\do{%
   \@for\tempb:={A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z}\do{%
      \expandafter\edef\csname foo\tempa\tempb\endcsname{\foo{\tempa}{\tempb}}}}
\makeatother
\begin{document}
\fooAA. \fooAB. \fooAC\ldots\fooAZ\ldots \par
\fooMA. \fooMB. \fooMC\ldots\fooZZ.
\end{document}
Post Reply