I wrote several similar systems, none of them for LaTeX though, probably for the good reason raised by David Carlisle, that using such macro interfaces in LaTeX would confuse users and cancel any benefits you could have from such an interface.
Let me review one of these systems, it is carefully described so that you can easily adapt these techniques to your case or other similar situations.
hbox-like interfaces in plain TeX with getoptk
One such system is the getoptk
package which you may find in tex/plain/contrib/getoptk.tex
and that were described in TUGboat 32-2, it defines new macros in plain TeX which enable the user to define commands mimicing the interface of hbox
, hfill
etc.
getoptk in action!
Using these macros, you could define a version of \includegraphics
which you could use like this:
\includegraphics
viewport{10cm 10cm 10cm 10cm}
clip
width=3cm
{example-image-a}
As you see, we crucially need a non optional argument to mark the list of our options. Preparing the definition of that revolted teen \includegraphics
requires the definition of an option dictionary:
\newgetoptkdictionary{includegraphics}
\defgetoptktoks{viewport}{\def\includegraphics@viewport{#1}}
\defgetoptkflag{clip}{\cliptrue}
\defgetoptkdimen{width}{\imagewidth=#1}
The defgetoptk*
calls define new optional arguments and behaviours. The replacement texts of these behaviours are saved as the macros
\getoptk@behaviour@includegraphics@viewport
\getoptk@behaviour@includegraphics@clip
\getoptk@behaviour@includegraphics@width
We now need to define the \includegraphics
macro itself, it looks like
\def\includegraphics{%
\setgetoptkdictionary{includegraphics}%
\getoptk\includegraphics@M
}
and the previous call to our \includegraphics
would be replaced by
\includegraphics@M{%
\getoptk@behaviour@includegraphics@viewport{10cm 10cm 10cm 10cm}
\getoptk@behaviour@includegraphics@clip
\getoptk@behaviour@includegraphics@width{3cm}%
}{example-image-a}
Neat, isn'it? The package is a bit long and uses some mid-level programming techniques in TeX (edef
, futurelet
and registers, essentially).
Other similar macros
I am the author of a hobby TeX format, branded Bhrìd TeX — I am looking for a new, funnier, name, by the way — which I started in 1999 after reading David Solomon's advanced TeX book — I decided to move to the non-advanced one a year later. But enough archeology!
If you enjoy reading french, please open the programmer's manual you should go the the section 2.6 and look for the family of macros \getoptspec
. They are similar to getoptk
but work with macros instead of keywords, which is of course easier to write! If you feel evil minded enough to play with the catcodes of .
(
and )
and a few others you may even let TeX understand that statement
deck.Take(randomCount)
.Where (card => card.Suit == "Hearts")
.Skip(2)
.Take(5)
.OrderBy (card => card.FaceValue);
But doing such tricks is not the LaTeX way.
]
). If you add that, then your syntax is just a minimal variation of the usual key-value syntax. – Stephan Lehmke Nov 29 '13 at 7:03;
and use parentheses(
and)
rather than braces, as in your initial model, then as Stephan Lehmke says, this is a rather easily equivalent variant of the[key1=value, key2=value, ...]
syntax. – user4686 Nov 29 '13 at 7:18({...})
. – Stephan Lehmke Nov 29 '13 at 7:22#{
syntax? – Stephan Lehmke Nov 29 '13 at 7:55