The usrguide
section 2.9 outtlines the =short text
method for picking up optional arguments as either keys or text, such as the short toc title in commands like caption etc. I need some code to grab these arguments and put them in either booleans or macros. There is a case that does not seem to be covered by the method provided, how to capture both the short title text and a set of keys, as for example:
\mycaption[=short title{,key1,key2=value etc}]{A very long title}
This type of to work both with and without a star. With a star I will provide a key to save or not save the short title in the toc. I would appreciate some help here. In the code below, the red result is the short title. It reacts correctly (never had any doubt!), except in the combined case of having a short title and some option key-list.
\documentclass{article}
\usepackage{xcolor}
\def\savetitle#1{
\def\savedtitle{{\bfseries #1}}
}
\def\saveshorttitlekeyval#1{
\def\savedshorttitleaux##1=##2;{{\color{red}##2}}
\def\savedshorttitle{
\savedshorttitleaux#1;
}
}
\ExplSyntaxOn
\NewDocumentCommand
\mycaption{s ={short-mytext} +O{#3} +m }
{%
\IfBooleanTF{#1}{
{hasstar ~} \saveshorttitlekeyval{#2}
}{nostar~ \saveshorttitlekeyval{#2}}
\savetitle{#3}
}
\ExplSyntaxOff
\begin{document}
1. \mycaption[=some short title]{long title}\savedtitle \savedshorttitle
2. \mycaption[some short title]{long title}\savedtitle \savedshorttitle
3. \mycaption[={size=10pt,color=blue}]{long title}\savedtitle \savedshorttitle
4. \mycaption{Only my caption}\savedtitle \savedshorttitle
5. \mycaption*{Starred my caption}\savedtitle \savedshorttitle %
6. \mycaption*{Starred short title and long title} \savedtitle \savedshorttitle
\end{document}
I would rather provide an extra key short
that is exactly what this system does you define a key sayshort
and for all internal processing treat it as a normal keyval ist,. but (for legacy compatiblity) if the option has no key=value then the whole option is read asshort=the value
short
, but you can't then pick up if a user actually tries to use an unknown key. (this doesn't have anything to do with the=
syntax.)