[Tex/LaTex] Using biblatex to modify specific citation commands depending on reference type

biblatex

I need to modify specific citation commands to use certain fields, and not others, depending on the type of reference being cited. Is there a way to do this using BibLaTeX (with a bibtex backend)?

Specifically, I would like to redefine

  • \citeyearpar for patents so that it prints just the patent number (and no parentheses), and
  • \citealp for patents so that it prints the patent number with the abbreviated country name associated with the patent type (from § 4.9.2.19 of the BibLaTeX documentation; e.g. "US") prepended (no space);

and I would like to define some additional (helper) citations including

  • \citepatass to print the assignee,
  • \citepatissue to print the issue date, and
  • \citepatlabel to a long identifying the issuing country, e.g. "U.S. Patent".

For a variety of reasons I need to limit the citation commands I use (primarily) to the natbib commands (e.g. \citep, \citet and all the others listed in § 3.6.9 of the BibLaTeX documentation). Generally I will be using the verbose style for both citations and my bibliography.

Additionally I'd like for citations of patents after the first to behave like the commands show the patent number rather than shortened verbose output.


\documentclass[nobib]{tufte-handout}
\RequirePackage{xpatch}     % For the patches below
\RequirePackage{hyphenat}   % See -- http://code.google.com/p/tufte-latex/issues/detail?id=60
\RequirePackage[
    backend=bibtex, 
    natbib=true, 
    bibstyle=verbose, citestyle=verbose,    % bibstyle extensively modifed below
    doi=true, url=true,                     % excluded from citations below
    citecounter=true, citetracker=true,
    block=space, 
    backref=true, backrefstyle=two,
    abbreviate=false            % Ideally, I'd like to abbreviate the patent locations, but nothing else
]{biblatex}

% For tufte-like behavior (I never use \cite itself); see -- http://tex.stackexchange.com/a/47763/7844
% Not directly related to the question but included for completeness
\let\citep\footcite 

% Some reordering and exclusions; see -- http://tex.stackexchange.com/q/46804/7844
% Not directly related to the question but included for completeness
\newbibmacro*{addendum+pubstate+pageref}{%
    \usebibmacro{addendum+pubstate}%
    \clearfield{addendum}%
    \clearfield{pubstate}%
    \setunit{\bibpagerefpunct}\newblock
    \usebibmacro{pageref}%
    \clearlist{pageref}%
    \setunit{\adddot\par\nobreak}}

\xpretobibmacro{doi+eprint+url}{\usebibmacro{addendum+pubstate+pageref}}{}{}
\xpretobibmacro{eprint}{\usebibmacro{addendum+pubstate+pageref}}{}{}
\xpretobibmacro{url+urldate}{\usebibmacro{addendum+pubstate+pageref}}{}{}


% Better patent numbers, from -- http://tex.stackexchange.com/a/45584/7844
% Not directly related to the question but included for completeness
\def\mkcommasep#1#2#3#4#5#6{#1#2#3,#4#5#6}
\DeclareFieldFormat[patent]{number}{\mkcommasep#1}

\begin{filecontents}{\jobname.bib}
@book{edisonbook1,
     author = {Edison, Thomas},
     title = {I'm too busy inventing to write books},
     year = {1920}}
@book{edisonbook2,
     author = {Edison, Thomas},
     title = {Another book I don't have the time to write},
     year = {1921}}
@patent{edisonpatant1,
    author = {Edison, Thomas},
    title = {My first great invention},
    type={patentus},location={countryus},
    month = jan, year = {1911},
    number = {266701}}
@patent{edisonpatant2,
    author = {Edison, Thomas},
    title = {A second fantastic invention}, 
    type={patentus},location={countryus},
    month = feb, year = {1912},
    number = {266702}}
@patent{edisonpatant3,
    author = {Edison, Thomas},
    title = {A third remarkable contraption},   
    type={patentus},location={countryus},
    month = mar, year = {1913},
    number = {266703},
    year = {1913}}
\end{filecontents}

\addbibresource{\jobname.bib}

\begin{document}
\subsection*{Some things that already work correctly}
This citation\citep{edisonpatant1} of an \citeauthor{edisonpatant1} patent works pretty much as desired. Note that I use \texttt{citep} to generate citations as footnotes. While other \texttt{natbib} citations commands do not.\footnote{This is necessary so that they can be used in footnotes. For example, citing \citealt{edisonpatant2} here embeds the verbose description; similarly for the author (\citeauthor{edisonpatant2}) or the year for a non-patent (\citeyear{edisonbook1})}. 
\subsection*{Basic patent-related citation changes}
I'd like to use at least one of the basic \texttt{natbib} macros that do not produce verbose output to print the  \textit{patent number}, in place of its default behavior. For example, instead of the year, for \texttt{citeyear}, instead of "\citeyear{edisonpatant1,edisonpatant2,edisonpatant3}" I want to have "266,701; 266,7021; 266,703". Additionally I'd like to co-opt another command (perhaps  \texttt{citealp}) to work similarly, but prepend the type string, e.g. US 266,701; US 266,7021; US 266,703". I realize that there are issues with combining such output with the normal behavior of these macros, and am happy to accept an error if patents are combined with non-patents in a single such macro invocation.
\subsection*{Patent behavior for subsequent citations}
Finally, I'd like for citations of patents after the first to behave like the commands above: they should show the patent number\footnote{US 266,701} rather than the normal shortened verbose output\citep{edisonpatant1}.
\subsection*{But wait, there's more}
While I'm at it (and only because perhaps it's easier to do in context of these modifications), I'd like to abbreviate \textit{only} the location in the bibliography (even with \texttt{abbreviate=false} in the options to \texttt{biblatex}), and omit location entirely from citations.
\printbibliography
\end{document}

Best Answer

Citation commands should be able to cope with multiple keys in their mandatory argument, and those keys may be of different entry types. Also, the \citeyearpar command will wrap its output (the content of one or multiple year fields) into a single set of parentheses. Therefore I don't think it's a good idea (though it may be possible) to redefine \citeyearpar according to the entry type of one of its multiple keys. Instead, I suggest to define a \citenumber macro which resembles \citeyearpar, but prints the content of the number field(s) and omits the surrounding parentheses.

Your suggested redefinition of \citealp faces an additional obstacle: The country name strings of section 4.9.2.19 of the biblatex manual are used in the patent's location field, but this field is optional and (as a list field) allows multiple entries, so the output of a possible \citelocnumber macro may not be as pretty as you expect.

\documentclass{article}

\usepackage[style=verbose,backend=bibtex8,natbib=true]{biblatex}

\DeclareCiteCommand{\citepatnumber}
  {\boolfalse{citetracker}%
   \boolfalse{pagetracker}%
   \usebibmacro{prenote}}
  {\ifentrytype{patent}{\printfield{number}}{\GenericError{}{Not a patent entry}{}{}}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\citepatlocnumber}
  {\boolfalse{citetracker}%
   \boolfalse{pagetracker}%
   \usebibmacro{prenote}}
  {\printlist[][-\value{listtotal}]{location}%
   \ifentrytype{patent}{\printfield{number}}{\GenericError{}{Not a patent entry}{}{}}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\addbibresource{biblatex-examples.bib}

\begin{document}

\citepatnumber{kowalik,almendro}

\citepatlocnumber{kowalik,almendro}

% Commenting the following in will raise a generic error
% \citepatnumber{knuth:ct:a}

\printbibliography

\end{document}

enter image description here