I have this command, which I would like to take two optional parameters: \pubtitle[title][symbol]{custom}
.
Here is the command (MWE):
\documentclass{article}
\usepackage{xcolor}
\usepackage{fontawesome}
\definecolor{icons}{HTML}{46A247}
\ExplSyntaxOn
\cs_new_protected:Nn \pubtitle_symbolheading:nn
{
\group_begin:
{\large\textcolor{icons}{#1}\hspace{10pt}\textbf{#2}}
\group_end:
}
\NewDocumentCommand{\pubtitle}{m}
{
\pubtitle_pubtitle:n { #1 }
}
\cs_new_protected:Nn \pubtitle_pubtitle:n
{
\str_case:nnF { #1 }
{
{book}{\pubtitle_symbolheading:nn{\faBook}{Book}}
{article}{\pubtitle_symbolheading:nn{\faFileText}{Article}}
% other cases
}
{% none of the above
\PackageError{pubtitle}
{
Unsupported ~ entry ~ field ~ '#1' ~ \MessageBreak for bibliography}
{
Perhaps ~ you ~ meant ~ '\string\pubtitle{custom}'
}
}
}
\ExplSyntaxOff
\begin{document}
\pubtitle{book}
\pubtitle{article}
\pubtitle{invalidArgument}
\end{document}
This returns an error for an "unsupported" mandatory parameter. What I would like is to be able to provide two optional parameters (one for each in the \pubtitle_symbolheading:nn
command) when the mandatory parameter custom
is given. The output of MWE is:
What I want is to be able to change the bold text and symbol in the output with optional parameters (but only if custom
is given as the mandatory parameter).
I would like to be able to change the title without the symbol, i.e. \pubtitle[title]{custom}
.
Best Answer
The following provides two internally identical solutions with a different document interface. The first, called
\pubtitle
uses two optional arguments followed by a mandatory one. The second, called\Pubtitle
uses the interface you showed in your question with a single optional argument in which the two things are split by a comma.Also, the third argument will be normalised by
\str_foldcase:n
.The following uses default values for the title and icon if
custom
was used. If you specify both optional arguments (or in the variant with a comma the variant with a separation) then the first will be the title and the second the icon. If you specify only one optional argument, if that contains only a single token/braced group that will be used as the icon and the title will be the default one. If you only specify one optional argument and it contains more than a single token/group it'll be the title and the default icon is used.