3

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}
lockstep
  • 250,273
orome
  • 10,459
  • 2
    Please provide a minimal example. – Marco Daniel Mar 23 '12 at 15:32
  • @MarcoDaniel: MWE added. – orome Mar 23 '12 at 17:41
  • @raxacoricofallapatorius So you only use 6-digit patent numbers and indicate one country in the location list field? I'm busy ATM, but if this post goes without additional answers for a few days I'll try to post one for you. – Audrey Mar 23 '12 at 17:51
  • @Audrey: I can't be sure what the constraints on the patent numbers might be, they could have arbitrary digits (or even letters); it's only currently that I assume 6 digits for the purpose of formatting US patent numbers. But yes, one "location", actually the "type" -- i.e the issuing country. The key thing is to this behavior be automatic for the relevant (co-opted) basic natbib macros. E.g. automatically invoking something like lockstep's suggested new macros below, when patents are supplied to, for example, \citealp. – orome Mar 23 '12 at 17:57
  • @Audrey: FWIW, much (nearly all, for practical purposes) of what I need is simply to always use the patent number in place of the year, for all citation styles, whenever the reference is a patent and the style doesn't already show the number. E.g. "Edison 1925, US453125, US454531; Gates US874184" – orome Mar 23 '12 at 22:10
  • @raxacoricofallapatorius But not all styles use year in the citation label. This example ("Edison 1925, US453125...") looks a like authoryear-comp and yet you're using verbose. Are you wanting to combine those two styles? Feel free to respond via chat. – Audrey Mar 24 '12 at 17:49
  • @Audrey: Sort of. I want to be able to switch between them; I will often need to produce the same document in at least two different forms, with different bibliographic styles. But I'd also like for the verbose style to abbreviate to "US453125" or perhaps "Edison, US453125" rather than "1915", or "Edison "1915" on subsequent citations; and would like for at least one of the "short" natbib styles to act that way too. – orome Mar 25 '12 at 22:13
  • 1
    @raxacoricofallapatorius I think I'll leave you with lockstep's answer as dedicated citation commands are probably the way to go. Your request for compact, sorted citations based on location and patent number can't be met without some style restrictions and biber. – Audrey Mar 26 '12 at 14:02
  • I think I'll go with that for now. The full solution is probably to create a completely new style that handles patent numbers differently, but I won't invest in that until I can switch to biber. – orome Mar 26 '12 at 16:51
  • @raxacoricofallapatorius authoryear-comp is a good basis for what you need. It can be modified to output verbose citations the first time each entry is cited. I can edit that linked post to clarify my last comment - the answer needs some improvement anyway. – Audrey Mar 26 '12 at 20:30

1 Answers1

4

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

lockstep
  • 250,273
  • I see the problem. Is there a way to define the macros as you propose, and then detect, within, for example, \citeyearpar whether all of the arguments are patents, "switching" to your \citenumber if they are (and perhaps logging an error if the user attempts to combine patents and non-patents)? – orome Mar 23 '12 at 16:57
  • @raxacoricofallapatorius Right now, I have no idea. Maybe some one else (e.g., Audrey) will come up with something. – lockstep Mar 23 '12 at 17:03
  • @raxacoricofallapatorius biblatex processes the entries in a citation list one at a time. So what you're asking for will require two passes through the list. It can be done - \textcite in the verbose styles is an example. Can you at least partly fulfill Marco's request for a MWE? Some concrete examples with a bib file would be helpful. – Audrey Mar 23 '12 at 17:34
  • @Audrey: MWE added. – orome Mar 23 '12 at 17:42
  • @lockstep: Regardless of how I proceed, I think something like DeclareCiteCommand will be very useful (what's "missing" may be unattainable: a way to automatically invoke it from standard macros like \citeyear when patents are the arguments). – orome Mar 23 '12 at 22:04
  • @lockstep: In order for it to be perfect though I'd appreciate help with a few improvements: (1) it should "count" as a citation (I think I can get that just by commenting out some lines); (2) it should give an error if the arguments aren't patents; and (3) it should prepend the (short) issuing country (e.g. "US"), (4) just once for multiple patents from the same country (e.g. "US 123,456; 876,765; 983,817) – orome Mar 23 '12 at 22:04
  • 1
    @raxacoricofallapatorius I added a generic error message. Requirements (3) and (4) are tricky, and I can't promise anything. – lockstep Mar 23 '12 at 22:28
  • @lockstep: Thanks! I can get part way to (3) by prepending \printfield{type} to the number, but that's a long string in the mode I'm in ("U.S. Patent") and I'd like it short ("US"). In fact, if I had that, I could pass on (4). – orome Mar 23 '12 at 22:38
  • @raxacoricofallapatorius Can't you add a location field with exactly one location for each bibentry and then use the \citepatlocnumber macro? – lockstep Mar 23 '12 at 22:55