\@ifnextchar
s ?General ⇒ \@ifnextchar for more characters
-
- Posts: 132
- Joined: Wed Feb 11, 2009 11:38 pm
\@ifnextchar for more characters
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
\@ifnextchar for more characters
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}
-
- Posts: 132
- Joined: Wed Feb 11, 2009 11:38 pm
Re: \@ifnextchar for more characters
-- Lorenz