This code uses LaTeX3, the xparse-package and in particular the \IfNoValueTF command as explained in Will Robertson's answer to the OP "Different command definitions with and without optional argument".
It sounds a little bit strange if you want to use a command called \IfNoValueTF, of which the name seems to suggest it checks for whether or not an argument contains any value, to have to ask a question to force a return as if the check resulted in a "non-value", in a case where in everyday language one would argue there is no non-empty-value in that argument indeed.
But, quite on the contrary ... \IfNoValueTF only seems to check whether or not there are any brackets. Please take a look at the self-explanatory MWE below, which checks whether or not a third argument is included.
Of course, quite possibly I have just misunderstood how to use either \IfNoValueTF or \DeclareDocumentCommand \mainentry { m m o } {%.
MWE
\documentclass[a4paper]{article}
\usepackage{xparse}
\DeclareDocumentCommand \mainentry { m m o } {%
\IfNoValueTF {#3} {%
\Large {\bfseries#1} \endgraf #2 \scriptsize NO \normalsize \vskip 1cm
}{%
\Large {\bfseries#1} \endgraf #2 \endgraf #3 \scriptsize YES \normalsize \vskip 1cm
}%
}
\begin{document}
A) There should be a YES here. OK.
\mainentry{
first
}{
second
}[
third
]
B) There should be a NO here. OK.
\mainentry{
first
}{
second
}
C) There should be a NO here. FAIL.
\mainentry{
first
}{
second
}[]
D) There should be a NO here. FAIL.
\mainentry{
first
}{
second
}[
]
E) There should be a NO here. FAIL.
\mainentry{
first
}{
second
}[
%
]
\end{document}
\ifblankfrom etoolbox, or\tl_if_blank:nTFfrom expl3. – Ulrike Fischer Oct 07 '17 at 13:07\tl_if_blank:nTFbut because I am so unexperienced I couldn't make it happen. – O0123 Oct 07 '17 at 13:25\ExplSyntaxOn \NewDocumentCommand \mainentry { m m O{} } { .. \tl_if_blank:nTF { #3 } { NO } { YES } .. } \ExplSyntaxOff. – Manuel Oct 07 '17 at 13:28{ m m o }into{ m m O{} }please? – O0123 Oct 07 '17 at 13:37ois something that works precisely for\IfValuetests.O{}is just an optional argument with default empty value (if you didO{asdf}thenasdfwould be the default value), and with that one you can have a correct\tl_if_blank:test (no optional = blank, optional but empty = blank, optional with something inside = not blank). – Manuel Oct 07 '17 at 13:46\mainentry{a}{b}[], then the final argument is not optional. – egreg Oct 07 '17 at 17:05