%%
%% The LaTeX Companion, 3ed
%%
%% Example A-1-13 on page II-640 in "Testing for optional argument values or optional tokens".
%%
%% Copyright (C) 2022 Frank Mittelbach
%%
%% It may be distributed and/or modified under the conditions
%% of the LaTeX Project Public License, either version 1.3c
%% of this license or (at your option) any later version.
%%
%% See https://www.latex-project.org/lppl.txt for details.
%%

\documentclass{tlc3exa}
\pagestyle{empty}
\setcounter{page}{6}
\setlength\textwidth{123.0pt}

 \setlength\parindent{0pt}

%StartShownPreambleCommands
\NewDocumentCommand\foo{m!o}{\par #1:
  \IfNoValueTF{#2}{No optional}%
                  {\IfBlankTF{#2}{Blanks in or empty}%
                                 {Real content in}}%
                   \space argument!}
%StopShownPreambleCommands

\begin{document}
\foo{1}[bar] \foo{2}[  ] \foo{3}[] \foo{4}[\space] \foo{5} [x]
\end{document}