# How to change a \NewDocumentCommand-based \cite command to accept biblatex-style arguments?

Over at How to quote encyclopedia articles differently from books, magazines, etc. with Biblatex?, I was greatly helped with a macro which solved the question as it was asked.

I'd now like to change this macro so that it works like a regular Biblatex cite command. Below is what I've attempted so far. Unfortunately it doesn't compile:

\documentclass{scrartcl}

\usepackage{csquotes}
\usepackage{polyglossia}
\setmainlanguage[spelling=new]{german}

% example bib file

\begin{filecontents}{test.bib}
@mvreference{ml,
title = {Müllers Lexikon},
}

@inreference{ml:thermoskanne,
crossref = {ml},
title = {Thermoskanne},
volume = {2},
}
\end{filecontents}

\usepackage[backend=biber,citestyle=authoryear-icomp]{biblatex}

% no quotes, italic font instead

\DeclareFieldFormat*{citetitle}{\emph{#1}}

% shot at a solution based on cfr's original answer

\usepackage{xparse}

\NewDocumentCommand{\parencitetitle}
{ > { \SplitArgument { 1 } { : } } m }
{ \myparencitetitle #1 }

\NewDocumentCommand{\myparencitetitle}
{ m m }
{
\boolfalse{citetracker}
\boolfalse{pagetracker}
\usebibmacro{prenote}
\parentext{\mkbibemph{\MakeUppercase{#1}}:\citetitle{#1:#2}}
\usebibmacro{postnote}
}

% some sample text, etc.

\begin{document}

Some things need to be said, some things need to be written. One place to put them in is an encyclopedia.
This is what it should look like, just without the space: (cf. \citetitle[\emph{ML:}][]{ml:thermoskanne}, 234).
And this is what it looks like right now: \parencitetitle[cf.][234]{ml:thermoskanne}.

\printbibliography

\end{document}


From what I understand so far, it is wrong (and impossible) to try and use Biblatex's prenotes and postnotes commands with this approach, and instead SplitArgument should be further exploited (how, though?)

• Poor TeX code can hardly make you look like a disgrace to the human race! Anyway, your code is far from disgraceful. (It doesn't work but that doesn't make it disgraceful.) Apart from the bit that doesn't work, it looks perfectly fine. (Believe me, that is not always the case!) – cfr Jul 28 '15 at 16:48
• Of course your new command would somehow have to know that its crossref ml is to be displayed as "ML". We would have to have something like that in the .bib file. I would suggest changing to @inreference instead of @incollection (even if you didn't like the idea in your earlier question). As far as I can tell you will not need substantial modifications to your bib style, but it will make our life here much easier (you will have to change your .bib file of course, but probably not a lot). – moewe Jul 28 '15 at 17:08
• Thank you :) Well, one question I had about your original code is why you put the first command after the second - it compiles, obviously, but I find it unintuitive that way (so it might just be a matter of taste). Also, why do people in the TeX world end lines with comment marks (%)? As for this thing here, am I right in assuming that only SplitArgument is a command of package xparse? – Sixtyfive Jul 28 '15 at 17:10
• The main problem we have with this question here is that I'm not really sure whether one can make \DeclareCiteCommand accept additional arguments without a lot of fuss. What one could try to do (not what your title asks for exactly) is to replicate the behaviour of biblatex's \cite commands as defined via DeclareCiteCommand in \NewDocumentCommand \myparencitetitle (xparse is quite powerful, and we will just need pre and postnotes). – moewe Jul 28 '15 at 17:13
• According to the Biblatex documentation, @inreference and @mvreference are practically the same as @incollection and @mvcollection. If I understand correctly (which does not necessarily have to be the case, of course) the connection between the two is made solely by crossref. Since you say it will help, though, l've changed them here in the example. In real life, the change is a bit more complicated as it hinges on the resolution of github.com/ZotPlus/zotero-better-bibtex/issues/…. – Sixtyfive Jul 28 '15 at 17:14

A Biblatex solution may well be more elegant and efficient. I will leave that to moewe, I think ;). Here is a non-Biblatex solution which uses xparse to emulate the behaviour of the citation commands. I know that you expressed a preference for a Biblatex solution (option 2 in chat) rather than emulation (option 1) but perhaps this will be useful to somebody. Anyway, I was curious and, on the upside, this does not require making any changes to your .bib file because, on the downside, it knows zilch about that stuff.

Note that this adds a space after the colon. However, if you don't want this space, just uncomment the appropriate line and comment the one above it. I'm not sure which space you'd like to be without.

\begin{filecontents}{\jobname.bib}
@mvreference{ml,
title = {Müllers Lexikon},
}
@inreference{ml:thermoskanne,
crossref = {ml},
title = {Thermoskanne},
volume = {2},
}
\end{filecontents}
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[backend=biber,citestyle=authoryear-icomp]{biblatex}
\DeclareFieldFormat*{citetitle}{\emph{#1}}

% shot at a solution based on cfr's original answer
\usepackage{xparse}
\NewDocumentCommand\parencitetitle
{ o o > { \SplitArgument { 1 } { : } } m }
{%
\IfNoValueTF {#2}%
{% there is no second optional argument
\IfValueTF {#1}%
{% there's a first optional argument - pass as a postnote
\myparencitetitle [] [#1] #3%
}{% neither pre- or postnotes
\myparencitetitle #3%
}%
}{% there's a second optional argument, so there must be a first as well
}%
}

\NewDocumentCommand{\myparencitetitle}
{ O {} O {}  m m }
%{\parentext{#1\mkbibemph{\MakeUppercase{#3}}\addcolon\citetitle[#2]{#3:#4}}}% use this line if you don't want a space after the colon (I'm not sure which space you want to be without)

\begin{document}

Some things need to be said, some things need to be written. One place to put them in is an encyclopedia.
This is what it should look like, just without the space: (cf. \citetitle[\emph{ML:}][]{ml:thermoskanne}, 234).
And this is what it looks like right now: \parencitetitle[cf.][234]{ml:thermoskanne}.

\parencitetitle[cf.][234]{ml:thermoskanne}

\parencitetitle[cf.][]{ml:thermoskanne}

\parencitetitle[234]{ml:thermoskanne}

\parencitetitle{ml:thermoskanne}

\printbibliography

\end{document}


• Accepted this one for the correctly working space. Surprisingly, both answers here are shorter than the Biblatex-based answer over at the original question. – Sixtyfive Jul 29 '15 at 15:04
• @RainerVerteidiger Look! I figured out how to get the space working with the blended solution ;). But I can only ping egreg there so I'm abusing the comment space here instead. – cfr Jul 30 '15 at 2:16

Here's an attempt to blend xparse with Biblatex.

\begin{filecontents}{\jobname.bib}
@mvreference{ml,
title = {Müllers Lexikon},
}
@inreference{ml:thermoskanne,
crossref = {ml},
title = {Thermoskanne},
volume = {2},
}
\end{filecontents}
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[backend=biber,citestyle=authoryear-icomp]{biblatex}
\DeclareFieldFormat*{citetitle}{\emph{#1}}

% shot at a solution based on cfr's original answer
\usepackage{xparse}
\NewDocumentCommand\myparencitetitle
{ > {\SplitArgument{ 1 }{ : } } m }%
{%
\prefixparencitetitle#1}

\NewDocumentCommand\prefixparencitetitle
{ m m }%
{%

\DeclareCiteCommand{\parencitetitle}
[\mkbibparens]%
{\boolfalse{citetracker}%
\boolfalse{pagetracker}%
\iffieldundef{prenote}
{}%
{\printfield{prenote}%
\newunit{\prenotedelim}}}%
{\ifciteindex%
{\indexfield{indextitle}}%
{}%
\myparencitetitle{#3}%
\printfield[citetitle]{labeltitle}}%
{\multicitedelim}%
{\usebibmacro{postnote}}

\begin{document}

Some things need to be said, some things need to be written. One place to put them in is an encyclopedia.
This is what it should look like, just without the space: (cf. \citetitle[\emph{ML:}][]{ml:thermoskanne}, 234).
And this is what it looks like right now: \parencitetitle[cf.][234]{ml:thermoskanne}.

\parencitetitle[cf.][234]{ml:thermoskanne}

\parencitetitle[cf.][]{ml:thermoskanne}

\parencitetitle[234]{ml:thermoskanne}

\parencitetitle{ml:thermoskanne}

\printbibliography

\end{document}


# EDIT

Fixed spacing issue, I think!

• filecontents should go before \documentclass; precisely, before loading inputenc or the ü in the title will be interpreted and not written out literally. – egreg Jul 29 '15 at 13:18
• @egreg Thanks. I didn't know that. I don't know where the environment is documented, although I think I have tried to find it. (I assume it is distinct from the documentation for the package.) – cfr Jul 29 '15 at 15:42
• It's in the official LaTeX manual. The problem would be the same also with the package. – egreg Jul 29 '15 at 16:26
• @egreg Lamport's book? I don't have it. Oh, well. – cfr Jul 29 '15 at 18:05