I believe I am looking for a LaTeX3 type syntax solution to more appropriately detect a missing argument. To me I would have expected key={} to be a valueless, blank, or empty argument key. After searching through questions I expected \tl_if_blank:nF and IfNoValueF to be my best bet, but either my key variable is not a compatible argument for these functions, or the key has to fail to be produced in order to return a TRUE on these functions. In the MWE below, I can tell it is still being executed because of the extra lines that get included.
I know it would be better if I could avoid including the keys when blank, but at the moment this is out of my control as someone else is responsible for the script that is parsing a database into the content filled syntax block simulated below in \SampleBlock. So I am trying to detect an empty key value but it's not working as I expected.
MWE:
\documentclass[10pt]{article}
\usepackage{xparse}
%--------------------New Commands for consistent formatting ---------------
\ExplSyntaxOn
% define the variable before using it:
\tl_new:N \l_heading_tl
\tl_new:N \l_subheading_tl
\tl_new:N \l_paragraph_tl
% define key:
\keys_define:nn { Sample }
{
key-heading .tl_set:N = \l_heading_tl
, key-subheading .tl_set:N = \l_subheading_tl
, key-paragraph .tl_set:N = \l_paragraph_tl
}
\DeclareDocumentCommand{\SampleBlock}{ o }
{
%TODO some residual debugging may be needed for omitted keys
\group_begin:% start a group to keep key setting local:
% set keys if optional argument #1 is given:
\IfNoValueF {#1} { \keys_set:nn {Sample} {#1} }
\IfNoValueF{\l_heading_tl}{\noindent\textbf{\l_heading_tl} \\}
\IfNoValueF{\l_subheading_tl}{\emph{\l_subheading_tl} \\}
\tl_if_blank:nF{\l_paragraph_tl}{\l_paragraph_tl}
\group_end:
}
\ExplSyntaxOff
%--------------------BEGIN DOCUMENT----------------------
\begin{document}
\SampleBlock[%
key-heading={Title here},
key-subheading={Sub Heading here},
key-paragraph={A paragraph of text will go here. Maybe I will say hello world, maybe I will describe how the quick brown fox jumped over the lazy brown dog. Really, the possibilities are endless. Oh wait, I could have used lipsum. Doh!}]
\medskip \medskip\medskip \medskip\medskip \medskip
\SampleBlock[%
key-heading={No subheading but there will still be a space for it on the next line...},
key-subheading={},
key-paragraph={A paragraph of text will go here. Maybe I will say hello world, maybe I will describe how the quick brown fox jumped over the lazy brown dog. Really, the possibilities are endless. Oh wait, I could have used lipsum. Doh!}]
\end{document}
key = {}is not the same as justkey? – Joseph Wright Nov 26 '15 at 09:06keywithout an equals sign in the example. Thekey-subheading={}bit can be omitted, as the corresponding token list is empty by default. – egreg Nov 26 '15 at 09:58key = {}means that no value has been given, whereas it has (an empty value). – Joseph Wright Nov 26 '15 at 10:06