2

I'm using a lot of articles from multi-volume encyclopedias in my work. To this end, I've set the articles up using the crossref attribute in the bibliography file. The citation style used is authoryear-icomp which is fine, basically.

To cite an encyclopedia article I use (\citetitle[\emph{ML:}][]{ml:thermoskanne}) at the moment, with the result being:

(ML: Thermoskanne)

Instead I'd love to be able to say something like \parencitetitle{ml:thermoskanne} instead and automagically get this (with Biblatex looking at both the @incollection as well as the @mvcollection:

(ML:Thermoskanne)

with the initial letters extracted from the @mvcollection's title attribute and without a space. Is there a Biblatex command you can use for something like this, or if not, how could a new command be programmed?

Edit: here's a full MWE using cfr's answer, which seems to work perfectly!

\documentclass{scrartcl}

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

% example bib file

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

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

\usepackage[backend=biber,citestyle=authoryear-icomp]{biblatex}
\addbibresource{test.bib}

% no quotes, italic font instead

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

% cfr's first suggestion

\usepackage{xparse}
\NewDocumentCommand \parencitetitle { > { \SplitArgument { 1 } { : } } m }
{%
  \myparencitetitle #1}
\NewDocumentCommand \myparencitetitle { m m }
{%
  \parentext {\mkbibemph{\MakeUppercase{#1}}:\citetitle{#1:#2}}}

% 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: (\citetitle[\emph{ML:}][]{ml:thermoskanne}).
And this is what it looks like right now: \parencitetitle{ml:thermoskanne}.

Wow! It already works!

\printbibliography

\end{document}
Sixtyfive
  • 331
  • Welcome! This won't solve the problem but it might be better to use @inreference etc. here. – cfr Jul 27 '15 at 22:15
  • Thank you! And yes, I'd love to do that, but have problems getting Better BibTeX to in turn convince Zotero to change the reference type. On the other hand it probably doesn't matter much since, according to the BibLaTeX manual, "the standard styles will treat this entry type as an alias for @mvcollection." – Sixtyfive Jul 27 '15 at 22:18
  • Yes. But it will be a pain if you later need a non-standard style which treats them differently. – cfr Jul 27 '15 at 22:57
  • It would be helpful if you'd post a Minimum Working Example people can fiddle with in trying to come up with a solution. – cfr Jul 27 '15 at 22:58
  • Regarding @mvcollection vs. @mvreference: 9 days left to go on the thesis, no change of bibliography style wanted at this point ;). Regarding the MWE: Where should I even start? I do know some things about using LaTeX, but I'm not sure if this problem here might not require real programming work. If you mean that I should make the example code I've shown into an MWE, I'll happily do that, but it doesn't actually do anything, right? – Sixtyfive Jul 27 '15 at 23:12
  • Make your code so we can copy-paste-compile it and reproduce an example of the output which you want changed. Then people can play around with ways of changing it to produce what you want. Solving puzzles appeals to people; setting them up is boring! If you set the puzzle up, people are more likely to have a go because they can start immediately. (And if they can't solve it, they haven't lost much which is another thing. I'm always reluctant to spend time on the set up if I may just find a puzzle I can't solve when I'm done.) – cfr Jul 27 '15 at 23:17
  • Well, now you beat me to it! I was trying to come up with something by reading the Biblatex manual, but it seems like your code works like a charm, so I accepted your answer. Thanks a million!!! – Sixtyfive Jul 28 '15 at 00:00
  • There may be an elegant Biblatex solution. However, since I was testing with non-bibkeys, I needed something which would work on things like a:b ;). Glad to hear it worked even so. – cfr Jul 28 '15 at 01:36
  • Good day again! So I've used this command a couple of times now and it turns out it would be good if it would understand the usual Biblatex convention of \citecommand()()[][]{}, or at least \citecommand[][]{}. I've tried myself, after reading some of the Biblatex docs (but not understanding much) to change \NewDocumentCommand into \DeclareCiteCommand and to add calls to \usebibmacro{prenote} and \usebibmacro{postnote} but can't get anything gobbled together that compiles and works as intended. What is the proper way here on tex.sx for me to request such an enhancement to an answer? – Sixtyfive Jul 28 '15 at 14:10
  • Probably best at this point would be to ask a new question and include a link to this one. Either that or you can edit your question but you shouldn't change the question in ways which would invalidate answers to the original, which I think would probably be the case here. – cfr Jul 28 '15 at 15:11

2 Answers2

2

Try this but I can't test without a proper example and biblatex-examples.bib doesn't include anything suitable.

\usepackage{xparse}
\NewDocumentCommand \parencitetitle { > { \SplitArgument { 1 } { : } } m }
{%
  \myparencitetitle #1}
\NewDocumentCommand \myparencitetitle { m m }
{%
  \parentext {\mkbibemph{\MakeUppercase{#1}}:\citetitle{#1:#2}}}
cfr
  • 198,882
2

If we use @inreference to properly distinguish reference works, we can then use \ifentrytype{inreference}. Additionally, I would add the two letters ML as shorthand to ml.

@mvreference{ml,
  title = {Müllers Lexikon},
  shorthand = {ML},
  options = {skipbib},
}

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

Here I also added skipbib to ml, such that it is not shown in the bibliography, you can of course get rid of that.

Then we define the bibmacro for citations to treat @inreferences differently

\makeatletter
\renewbibmacro*{cite}{%
\ifboolexpr{test {\ifentrytype{inreference}} and not test {\iffieldundef{crossref}}}
  {\entrydata{\thefield{crossref}}{%
     \printfield[citetitle]{shorthand}}%
   \setunit{\addcolon}%
   \usebibmacro{cite:label}}%
  {%
  \iffieldundef{shorthand}
    {\ifthenelse{\ifciteibid\AND\NOT\iffirstonpage}
       {\usebibmacro{cite:ibid}}
       {\ifthenelse{\ifnameundef{labelname}\OR\iffieldundef{labelyear}}
          {\usebibmacro{cite:label}%
           \setunit{\addspace}%
           \usebibmacro{cite:labelyear+extrayear}%
           \usebibmacro{cite:reinit}}
          {\iffieldequals{namehash}{\cbx@lasthash}
             {\ifthenelse{\iffieldequals{labelyear}{\cbx@lastyear}\AND
                          \(\value{multicitecount}=0\OR\iffieldundef{postnote}\)}
                {\setunit{\addcomma}%
                 \usebibmacro{cite:extrayear}}
                {\setunit{\compcitedelim}%
                 \usebibmacro{cite:labelyear+extrayear}%
                 \savefield{labelyear}{\cbx@lastyear}}}
             {\printnames{labelname}%
              \setunit{\nameyeardelim}%
              \usebibmacro{cite:labelyear+extrayear}%
              \savefield{namehash}{\cbx@lasthash}%
              \savefield{labelyear}{\cbx@lastyear}}}}}
    {\usebibmacro{cite:shorthand}%
     \usebibmacro{cite:reinit}}}%
  \setunit{\multicitedelim}}
\makeatother

This is just a copy of authoryear-icomp.cbx plus a few modifications at the begin.

Since we use the crossref mechanisms we also need mincrossrefs=1.

MWE

\documentclass{scrartcl}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{csquotes}
\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
  @mvreference{ml,
    title = {Müllers Lexikon},
    shorthand = {ML},
    options = {skipbib},
  }

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

\usepackage[backend=biber,citestyle=authoryear-icomp,mincrossrefs=1]{biblatex}
\addbibresource{\jobname.bib}

% no quotes, italic font instead

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


\makeatletter
\renewbibmacro*{cite}{%
\ifboolexpr{test {\ifentrytype{inreference}} and not test {\iffieldundef{crossref}}}
  {\entrydata{\thefield{crossref}}{%
     \printfield[citetitle]{shorthand}}%
   \setunit{\addcolon}%
   \usebibmacro{cite:label}}%
  {%
  \iffieldundef{shorthand}
    {\ifthenelse{\ifciteibid\AND\NOT\iffirstonpage}
       {\usebibmacro{cite:ibid}}
       {\ifthenelse{\ifnameundef{labelname}\OR\iffieldundef{labelyear}}
          {\usebibmacro{cite:label}%
           \setunit{\addspace}%
           \usebibmacro{cite:labelyear+extrayear}%
           \usebibmacro{cite:reinit}}
          {\iffieldequals{namehash}{\cbx@lasthash}
             {\ifthenelse{\iffieldequals{labelyear}{\cbx@lastyear}\AND
                          \(\value{multicitecount}=0\OR\iffieldundef{postnote}\)}
                {\setunit{\addcomma}%
                 \usebibmacro{cite:extrayear}}
                {\setunit{\compcitedelim}%
                 \usebibmacro{cite:labelyear+extrayear}%
                 \savefield{labelyear}{\cbx@lastyear}}}
             {\printnames{labelname}%
              \setunit{\nameyeardelim}%
              \usebibmacro{cite:labelyear+extrayear}%
              \savefield{namehash}{\cbx@lasthash}%
              \savefield{labelyear}{\cbx@lastyear}}}}}
    {\usebibmacro{cite:shorthand}%
     \usebibmacro{cite:reinit}}}%
  \setunit{\multicitedelim}}
\makeatother

\begin{document}
And this is what it looks like right now \cite{ml:thermoskanne}.

\printbibliography

\end{document}

Output: ML:Thermoskanne

moewe
  • 175,683
  • Given that this functions like one would expect a Biblatex cite command to work, I now accepted it, instead of @cfr's version (which hopefully, cfr won't be holding against me :)). What I find interesting (and a litlte frightening) about it is that the whole \cite command basically had to be repeated to be changed. – Sixtyfive Jul 29 '15 at 15:06
  • @RainerVerteidiger I won't ;). – cfr Jul 29 '15 at 15:45
  • @RainerVerteidiger Well, in order to change the macro I had to copy it and make the necessary modifications. Unfortunately, the cite macro in authoryear-icomp.cbx is quite a chunk of code (if you had asked for a solution for authoryear.cbx, say, the solution would have been quite a bit shorter)- There are ways to change macros without copying the entire definition (the xpatch for example), but I didn't use that here. – moewe Jul 29 '15 at 15:57
  • @RainerVerteidiger Please note that initially I had forgotten to wrap the code in \makeatletter/\makeatother, which could lead to unwanted behaviour in some cases. The problem has now been fixed. – moewe Jul 29 '15 at 16:00