EDIT: Answer found here: How to check if a macro value is empty or will not create text with plain TeX conditionals?
Consider the following code snippet from a .sty file
\makeatletter
\newcommand{\Snippet}[3]{%
\@namedef{csh#1}{\sremA{#2}{#3}}%
\@namedef{bea#1}{\sremB{#2}{#3}}%
}%
\newcommand{\sremB}[2]{
\begin{frame}
\frametitle{#1}
\begin{shadedrem}
#2
\end{shadedrem}
\end{frame}
}
I want to change this code to
\makeatletter
\newcommand{\Snippet}[4]{%
\@namedef{csh#1}{\sremA{#2}{#3}}%
\@namedef{bea#1}{\sremB{#2}{#3}{#4}}%
}%
\newcommand{\sremB}[3]{
\begin{frame}
\frametitle{#1}
\begin{shadedrem}
#2
\end{shadedrem}
\end{frame}
%%% Pseudo code
if #3 is not empty then
( here I will process text in #3 )
endif
}
I have the following questions. How to code the "if #3 is not empty then"?, and is it possible to create a command where the last argument is optional? Such that
\cmd{#1}
\cmd{#1}{#2}
both work?
\ifx\relax\detokenize{#3}\relax \else <do something>\fi(needs e-TeX) – Henri Menke Nov 06 '15 at 17:12xparse. It offers some neat features to check if arguments are empty. – Henri Menke Nov 06 '15 at 17:13\detokenize. This extensions are available inpdftex,luatex, andxetex. – Henri Menke Nov 06 '15 at 17:14xparseis a candidate component of the LaTeX3 format to define commands. If you dislike the future though, stick with the solution proposed in my first comment. – Henri Menke Nov 06 '15 at 17:16xparseis very stable and reliable. – Nov 06 '15 at 17:17\ifx\valign#3\valignwhich is theoretically less safe as#3might start\valign, but in practice ... – David Carlisle Nov 06 '15 at 17:17MWE. It would be nice to post such ones, not just fragments of code, out of context – Nov 06 '15 at 17:21xparsewould do this very easily. – Nov 06 '15 at 17:26