Using \@ifnextchar one can detect if e.g. the next Character is a [, e.g.:
\@ifnextchar[%
{
%% code to execute if [ scanned.
}{
%% code to execute if [ scanned.
}
However, I can’t seem to use \@ifnextchar{
to test if the next Character is {.
Is there any way to use \@ifnextchar to detect a {?
Is there any way at all to detect a {?
If so, please let me know.
Update 1: Okay, I think that \bgroup is a successful Answer. I think I know now (sort of) why it didn’t work when I first used it.
The Purpose I needed it for was to be able to have a Macro that can take an indefinite Number of Arguments. (E.g. listing out Authors.) These seems to run into issues once we want to place the resulting String in an Header.
Update 2: Regarding my secondary Problem (which was my original Application for all of this), is there a way to delay Commands in TeX. In particular, I want to first run a Macro which waits for an arbitrary Amount of Arguments, then run a second Command on this.
Here is the kind of thing I’m trying to do:
\def\headerauth#1{\rhead{#1\ifnextchar\bgroup{\@headerauth}{.}}}
\def\@headerauth#1{\& #1\ifnextchar\bgroup{\@headerauth}{.}}}
Without the \rhead, Things work fine. But once I use \rhead, it will only read the first Argument. The others are ignored. E.g.
\headerauth{S. Mishkin}{L. Polotov}
results in »S. Mishkin.« being placed in the Header, and »L. Polotov« placed in the main Text.
Whereas if I define \headerauth omitting the \rhead, and then use:
\rhead{\headerauth{S. Mishkin}{L. Polotov}}
I obtain »S. Mishkin & L. Polotov.« in the Header as desired.
Why doesn’t the first Thing work? (I realise that this Question probably belongs to a new Topic…)
P.s. *@doncherry* & @Yossi Farjoun: I’ve figured it out — turns out I was using the wrong Key Combination to access the ` Symbol on my Keyboard. (The same Key produces `'˚´ depending on Key Combinations.) (Took me a short while to figure out how to quote-not-use the Symbol ` (as well as \) via \` and \\ — ah, the Standard coding Tricks. Glad to see it’s very logical.)
\`` (not apostrophes') where you referred to code within a line of normal text; so the source code of your first few words is ``Using@ifnextchar` one``. For more information, check out http://tex.stackexchange.com/editing-help#code, http://meta.tex.stackexchange.com/questions/863/how-do-i-mark-inline-code, and http://meta.tex.stackexchange.com/questions/1192/how-do-i-mark-code-blocks. – doncherry Nov 02 '11 at 14:39