\@ifnextchar
s ?General ⇒ \@ifnextchar for more characters
-
- Posts: 132
- Joined: Wed Feb 11, 2009 11:38 pm
\@ifnextchar for more characters
Is there a simpler way to check whether the next character is one of several than nesting
Last edited by cgnieder on Sun Oct 13, 2013 6:23 pm, edited 1 time in total.
NEW: TikZ book now 40% off at Amazon.com for a short time.

\@ifnextchar for more characters
How about this:
Regards
Code: Select all
\documentclass{article}
\usepackage{etoolbox,ltxcmds}
\makeatletter
% --------------------------------------------------------------------------
% list parser with no separator:
\DeclareListParser*\laurentius@add@tokens{}
% the list that holds the tokens to be checked:
\def\laurentius@tokens@list{}
% set the tokens list (the parser does not like blank lists):
\newrobustcmd*\laurentius@set@tokens[1]{%
\def\laurentius@tokens@list{}%
\ifblank{#1}
{}
{\laurentius@add@tokens{\listadd\laurentius@tokens@list}{#1}}%
}
% --------------------------------------------------------------------------
% check for token but leave it where it is:
\newrobustcmd\laurentius@iftokens[3]{%
\laurentius@set@tokens{#1}%
\ltx@ifnextchar{ }
{\laurentius@iftokens@aux{#2}{#3}{}}
{\laurentius@iftokens@aux{#2}{#3}}%
}
\newrobustcmd\laurentius@iftokens@aux[3]{%
\ifblank{#3}{#2}{%
\ifinlist{#3}{\laurentius@tokens@list}
{#1}
{#2}%
}%
#3%
}
\newcommand*\checkmylist{\laurentius@iftokens{([*}{in my list}{not in my list}}
\makeatother
\begin{document}
\checkmylist[]
\checkmylist{}
\checkmylist()
\checkmylist*
\checkmylist/
\end{document}
site moderator & package author
-
- Posts: 132
- Joined: Wed Feb 11, 2009 11:38 pm
Re: \@ifnextchar for more characters
Nice. That's pretty advanced. Thanks.
-- Lorenz
-- Lorenz