General ⇒ How to amalgamate commands?
How to amalgamate commands?
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis
How to amalgamate commands?
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.
How to amalgamate commands?
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?
How to amalgamate commands?
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}