2

I have three .bib files with the bibliography of my CV split into "journals", "conferences" and "thesis". I count the amount of entries for each .bib file following this method for the three types:

\newtotcounter{no_journals}

\AtEveryBibitem{
    \ifkeyword{journal}{\stepcounter{no_journals}}{}%
}

\defbibheading{journals}{International Journals}
\addbibresource[label=journals]{journals}

... and thenn I print the result in a specific section as follows:

\begin{refsection}[journals.bib]
\nocite{*}
\begin{refcontext}
\printbibliography
\end{refcontext}
\end{refsection}

\begin{itemize}
    \item Number of International Journals: \total{no_journals}\
\end{itemize}

For my long CV it works fine; however for the résumé, I only want to put the total amount of journals, conferences and thesis WITHOUT printing the full bibliography. For this purpose, I have the following command:

\begin{refsection}[journals.bib]
\nocite{*}
\begin{refcontext}
\printbibliography
\end{refcontext}
\end{refsection}

\begin{itemize}
    \item International Journals: \total{no_journals}\, International Conferences: \total{no_conferences}\, Thesis Conducted: \total{no_thesis}\
\end{itemize}

As you can see in the command itself, if I do not invoke "\printbibliography" for each of the types (journals, conferences and thesis), the entries in the bibliography files are not counted.

  • Is there any way in which I can count them without invoking "\printbibliography"?
  • If there is no other chance than having to invoke "\printbibliography" mandatory, can I make it not print the bibliography? Like a "dry-run" method?
3
  • 2
    Without testing: \setbox0\vbox{\printbibliography} doesn't print anything and still evaluates \printbibliography.
    – Skillmon
    Dec 2, 2017 at 23:00
  • 1
    Please make your code snippets compilable ...
    – Mensch
    Dec 2, 2017 at 23:03
  • @Skillmon : that answer is correct, it works. Would you please post this as an answer, so that I can mark it right?
    – nsx
    Dec 2, 2017 at 23:23

2 Answers 2

3

To execute some code without printing it you can execute it in a \setbox, this stores the result in the used box, so \setbox0 stores the results in box register 0 (which is a scratch register for temporary use). It also requires the type of box where we choose \vbox because this allows more stuff than \hbox to be its content. So to use \printbibliography without typesetting it, you can use:

\setbox0\vbox{\printbibliography}
4

If the entries are \nocite'd or \cite'd you can use \AtDataInput instead of \AtEveryBibitem

\documentclass{article}
\usepackage{biblatex}
\addbibresource{biblatex-examples.bib}

\newcounter{no_journals}
\newcounter{no_conferences}
\newcounter{no_thesis}

\AtDataInput{%
  \ifentrytype{article}
    {\stepcounter{no_journals}}
    {\ifentrytype{inproceedings}
       {\stepcounter{no_conferences}}
       {\ifentrytype{thesis}
          {\stepcounter{no_thesis}}
          {}}}}

\begin{document}
\nocite{sigfridsson,worman,baez/article,geer}

journals: \arabic{no_journals}, theses: \arabic{no_thesis}
\end{document}

\AtDataInput is executed once per refsection for every entry in the .bbl when the .bbl file is read. \AtEveryBibitem is executed for every item printed in \printbibliography.

2
  • That doesn't tell me how many items would be printed when calling \printbibliography, though, because I could have filters applied. Is there a way to get the number of entries actually printed (or matching a filter)? Dec 2, 2021 at 13:29
  • @FrederickNord I suggest you ask a new question with an MWE and a detailed list of requirements if you are still interested in an answer. It is pretty tricky to discuss things like this in the comments (and even trickier to offer code as solutions).
    – moewe
    Dec 2, 2021 at 20:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .