# How to code “if (#3 is not empty) then (do something) endif” in LaTeX? [duplicate]

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}
#2
\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}
#2
\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?

## marked as duplicate by David Carlisle macros StackExchange.ready(function() { if (StackExchange.options.isMobile) return; $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() { var$hover = $(this).addClass('hover-bound'),$msg = $hover.siblings('.dupe-hammer-message');$hover.hover( function() { $hover.showInfoMessage('', { messageElement:$msg.clone().show(), transient: false, position: { my: 'bottom left', at: 'top center', offsetTop: -7 }, dismissable: false, relativeToBody: true }); }, function() { StackExchange.helpers.removeMessages(); } ); }); }); Nov 6 '15 at 17:20

• \ifx\relax\detokenize{#3}\relax \else <do something>\fi (needs e-TeX) – Henri Menke Nov 6 '15 at 17:12
• Is e-tex a required package? – nilo de roock Nov 6 '15 at 17:13
• Still, I would suggest you define these commands using xparse. It offers some neat features to check if arguments are empty. – Henri Menke Nov 6 '15 at 17:13
• xparse is 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 6 '15 at 17:16
• @ndroock1 if you are using a latex command from this century it is already using etex, that will not be an issue. although personally I don't usually bother and would use \ifx\valign#3\valign which is theoretically less safe as #3 might start \valign, but in practice ... – David Carlisle Nov 6 '15 at 17:17