9

I have several references in a document. I'd like to display some statistics regarding the references - for example,

  • citations with author Smith,
  • citations between year xxxx and yyyy,
  • citations published in Journal foo,
  • citations not published in a journal (I think that I only have @inproceedings and @book types).

I'm using biblatex.

There are several questions about counting the total number of citations used: for example, this, and this. These are similar to what I want to do, but the answers aren't extensible to my use-case.

From here, I can count the citations published between two years using:

\usepackage{etoolbox}
\AtDataInput{
    \ifboolexpr{ test { \ifnumless  {\thefield{year}+0}{2005}} and
                 test {\ifnumgreater{\thefield{year}+0}{2000}}}
                 { \stepcounter{c_years} }{}
 {}
}

I'm trying to do something similar to count the authors with name Smith and publications in journal foo:

\usepackage{xstring}
\newcounter{c_foo}
\AtDataInput{
    \IfSubStr{\strfield{booktitle}}{foo}{ \stepcounter{c_foo} }{}
 {}
}

I step a counter if foo is a substring of \strfield{booktitle}. However, this doesn't work (the counter remains at 0). I've tried with \thefield, which also doesn't work.

I thought perhaps foo wasn't surrounded by whitespace, and that xstrings \IfSubStr wasn't picking it up, but these both work:

\IfSubStr{The foo bear}{foo}{ \stepcounter{c_foo} }{}
\IfSubStr{Thefoobear}{foo}{ \stepcounter{c_foo_two} }{}

I'm taking this approach because when it works, I should be able to check for substrings of any of the fields, which is an extensible solution.

How can I increment a counter if foo is a substring of one of the fields of my references?

4

It's a problem of category codes. The string returned by \strfield is composed by category code 12 characters, which are not matched by the category code 11 ones you use in the search string.

Solution:

\IfSubStr{\strfield{booktitle}}{\detokenize{foo}}{\stepcounter{c_foo}}{}
  • Excellent, thanks - I wouldn't have found that. For future viewers, see this question for more detail regarding TeX category codes. – simont Aug 26 '13 at 9:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.