Simple key-value example
I'm not sure what you really need. This can be something to start...
Assigning to title
or author
actually runs the code defined in pgfkeys
. Nothing is stored.
\documentclass{article}
\usepackage{pgfkeys}
\pgfkeys{
/bibliography/.cd, % family
title/.code = {\ifx#1\empty A\else{\textbf{Title} #1\par}\fi},
author/.code = {\ifx#1\empty A\else{\textbf{Author} #1\par}\fi},
}
\newcommand{\mycommand}[1]{
\pgfkeys{
/bibliography/.cd,
#1,
}
\pgfkeysvalueof{/bibliography/title}
\pgfkeysvalueof{/bibliography/author}
}
\begin{document}
One:\par
\mycommand{title = {Tikz \& PGF}, author={JD}}
Two:\par
\mycommand{author={JD}}
Three:\par
\mycommand{title = {Tikz \& PGF}}
Four:\par
\mycommand{}
Five:\par
\mycommand{title=, author=}
\end{document}
Edit
Please note that the .code
is executed at "parameter time", so \mycommand{author={JD}, title = {Tikz \& PGF}}
will print the author before the title.
Edit 2
This version uses \bibtitle
and \bibauthor
to store the data. As theses macros are global, you have to clear them (set to empty) in each call, otherwise previous values are remembered.
\documentclass{article}
\usepackage{pgfkeys}
\pgfkeys{
/bibliography/.cd, % family
title/.store in = \bibtitle,
author/.store in = \bibauthor,
}
\newcommand{\mycommand}[1]{
\pgfkeys{
/bibliography/.cd,
title = {}, % clear title
author = {}, % clear author
#1,
}
\ifx\bibtitle\empty\else\textbf{Title:} \bibtitle\par\fi
\ifx\bibauthor\empty\else\textbf{Author:} \bibauthor\par\fi
}
\begin{document}
One:\par
\mycommand{title = {Tikz \& PGF}, author={JD}}
\mycommand{author={JD}, title = {Tikz \& PGF}}
\vspace{2ex}
Two:\par
\mycommand{author={JD}}
\vspace{2ex}
Three:\par
\mycommand{title = {Tikz \& PGF}}
\vspace{2ex}
Four:\par
\mycommand{}
\vspace{2ex}
Five:\par
\mycommand{title=, author=}
\end{document}