I'm trying to define a command with \NewDocumentCommand
that create a subsection with a given name (mandatory) and optionally some descriptive paragraph. Since I don't want these paragraph to be printed out when they're empty, I've tried taking advantage of the \IfBlankF
functionality by excluding the paragraph altogether if their respective content is empty.
The command I've defined is as follows:
\documentclass{article}
\begin{document}
\NewDocumentCommand{\newrule}{ m O{} O{} O{} O{} }{
\subsubsection{#1}
\IfBlankF{#2}{
\paragraph{Addendum}
#2
}
\IfBlankF{#3}{
\paragraph{Rationale}
#3
}
\IfBlankF{#4}{
\paragraph{Examples}
#4
}
\IfBlankF{#5}{
\paragraph{Exceptions}
#5
}
}
\section{Section}
\subsection{Subsection}
\newrule{Rule 1}{blah blah}{}{}{}
\end{document}
This works almost as intended, except that whenever the arguments are non empty, the paragraph name leading up to them are not present. The same happens with any other kind of content replacing the \paragraph{...} part.
However, if I invert the behavior by e.g. writing
\IfBlankF{#2}{
\paragraph{Addendum} abcdef
#2
}
both the paragraph names and subsequent content works. What am I doing wrong?
\documentclass{...}
, the required\usepackage
's,\begin{document}
, and\end{document}
. That may seem tedious to you, but think of the extra work it represents for the users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem.\newrule{Rule 1}[blah blah][][][]
or\newrule{Rule 1}[blah blah]