I've created an environment for which various parameters are set through key values. Instead of creating a hornet's nest of various booleans, I would just like to have a slight variant form for some of the keys to handle some of the formatting.
In particular, while none of the keys are mandatory, I need a way of handling things if I omit some of the keys. So, I figured I'd create starred variants.
To help you understand what I'm trying to do in the following MWE, here's the basic idea: I have three optional tags to add to a quote (title, description, and author). Each is meant to show up on its own line, when used. If the key is not used, then nothing should be done. But if the author key is not called, then I need a means of handling the line breaks to avoid unwanted extra whitespace. The starred variants are to be used in such a situation.
Here's a MWE:
\documentclass{article}
\newcommand{\attrib}[1]{\nopagebreak{\par\raggedleft\footnotesize #1\par}}
%%----------
\makeatletter
%%----------
\let\ae@source@title\relax
\let\ae@source@description\relax
\let\ae@source@author\relax
%%----------
\newlength{\widthofwidestline}
\newlength{\afterEpigraphSkip}
\setlength{\widthofwidestline}{3in}
\setlength{\afterEpigraphSkip}{1\baselineskip}
%%----------
\RequirePackage{pgfkeys}
\pgfkeys
{
/ae/my/epigraph/environment/set/options/.cd,
title/.code = {\def\ae@source@title{#1\\}},
description/.code = {\def\ae@source@description{#1\\}},
author/.code = {\def\ae@source@author{#1}},
%% variants for handling `title` and `description` when `author`
%% (and possibly other keys) are missing.
title*/.code = {\def\ae@source@title{#1}},
description*/.code = {\def\ae@source@description{#1}},
%% length parameters
longest line/.code = {\settowidth{\widthofwidestline}{#1}},
afterskip/.code = {\setlength{\afterEpigraphSkip}{#1}},
}
\newenvironment{epigraph}[1]
{\pgfkeys{ /ae/my/epigraph/environment/set/options/.cd, #1 }%
\par\hspace*{\fill}%
\begin{minipage}[t]{\dimexpr\widthofwidestline+1em}%
}
{\attrib{%
\ae@source@title
\ae@source@description
\ae@source@author
\makebox[0pt][r]{\rule[-0.8pt]{1in}{0.4pt}}%
}%
\end{minipage}%
\hspace*{\fill}%
\vspace{\afterEpigraphSkip}%
}
\makeatother
\pagestyle{empty}
\begin{document}
\begin{epigraph}{title={title},
description={description},
author={me},
longest line=abcdefghijklm}
Scenario 1
\end{epigraph}
\begin{epigraph}{author={me},
longest line=abcdefghijklm}
Scenario 2
\end{epigraph}
\begin{epigraph}{title={title},
description={description},
longest line=abcdefghijklm}
Scenario 3
\end{epigraph}
\begin{epigraph}{title={title},
description*={description},
longest line=abcdefghijklm}
Scenario 4
\end{epigraph}
\begin{epigraph}{title*={title},
longest line=abcdefghijklm}
Scenario 5
\end{epigraph}
\begin{epigraph}{description*={description},
longest line=abcdefghijklm}
Scenario 6
\end{epigraph}
\end{document}
Scenario 3 illustrates what I want to avoid. This MWE produces:

I'm not so much interested in creating a new epigraph command: I know there are such packages. I also know that I could set and process booleans to handle this issue automatically. But as I mentioned, I really would like to avoid creating boolean switches.
I'm more interested in a larger issue where key values are being used, but where occasionally you might want to handle some of the keys in a slightly different manner than usual: hence the starred-variant.
I haven't found anything in the documentation that would allow for this. I also didn't find anything on this site related to starred variants of keys.
I'm primarily interested in feedback about best practices in such a situation.


title/.style={title*={#1\\}}. By the way, is there a reason you use.codehandlers that simply define a macro? You could just use an actual value-key (handler:.initial) and reduce the overhead. – Qrrbrbirlbel Jul 22 '13 at 19:32.stylemethod would work. Could you elaborate? – A.Ellett Jul 22 '13 at 19:36.code. If you could illustrate how to avoid making so many calls via.code, I'd be very interested. After all, I'm more interested in best practices here than just some hack that gets the job done. – A.Ellett Jul 22 '13 at 19:41titleandtitle*that I see is that the un-starred version includes a final\\. If you definetitleas a key that simply forwards its argument appended by\\totitle*. On the other hand, I would actually post-process the values so that the user doesn’t need to work so much; of course, this would involve some checking for empty values and is probably depending on how complex the input scenarios can get. – Qrrbrbirlbel Jul 22 '13 at 19:43titlekey, are you suggesting something more along the lines oftitle*/.initial=#1,followed bytitle/.style={title*={#1\\}}? – A.Ellett Jul 22 '13 at 19:43title*/.initial=sets the value to an empty string. The.styleitself implies one argument. Though, as I said, I’d check for empty values as egreg did but withpgfkeys, of course. – Qrrbrbirlbel Jul 22 '13 at 20:19pgfkeys. – A.Ellett Jul 22 '13 at 21:40