0

This question already has an answer here:

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?

marked as duplicate by David Carlisle macros Nov 6 '15 at 17:20

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 2
    \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
  • 1
    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
  • 2
    @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

Browse other questions tagged or ask your own question.