3

I could write a simple program for this in a programming language I know (or just terminal, I suppose), but is there a simple way to do this in LaTeX?

Maybe this could be done in LuaLaTeX? The regex to get the reference types is just @.*\{ (at least in Sublime Text).

I have entries like @online and @article but I don't know which ones I have and which ones I don't and my bibliography file is pretty big. I want to make a reference list that is sorted per type, but in order to do that I need to know what article types I have first!

I found a way to do it in Sublime (copy/paste bib file in Sublime --> select all with the regex @.*\{ --> alt + enter --> go to edit --> permute lines --> unique), but I am still leaving the question open for a (Lua)LaTeX style answer.

Now I can do it as stated in Sectioning bibliography by type of referred item

I currently have to type:

\printbibliography[type=article,title={Articles}]
\printbibliography[type=inproceedings,title={Conference papers}]
\printbibliography[type=book,title={Books}]
\printbibliography[type=inbook,title={Book Chapters}]
\printbibliography[type=incollection,title={Chapters in a Collection}]
\printbibliography[type=MastersThesis,title={Master Theses}]
\printbibliography[type=techreport,title={Tech Reports}]
\printbibliography[type=misc,title={Misc}]

Which is fine but I am still wondering how one can do it more automatically.

  • 2
    Ideally you don't need to know that and everything happens automatically. Do you want a split bibliography with different subheadings, or just really only sorting by type? – moewe Apr 5 '18 at 12:43
  • I want to sort by type and perhaps give a semi-generalized name to it. And I know that I don't need to it ideally but when I look at the BibLaTeX tutorials on how to divide everything up in sub-headings it seems pretty manual. For example: tex.stackexchange.com/questions/20246/… – Melvin Roest Apr 5 '18 at 12:46
  • I suppose a sourcemap and a bibbycategory could automate things somewhat. – gusbrs Apr 5 '18 at 13:01
  • But another alternative would be to devise a way to check you your current \printbibliography statements are exhaustive. A hook and a alreadyinbib category should do the job. – gusbrs Apr 5 '18 at 13:04
2

This does what you originally asked for. It generates a list of entry types used

\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{csquotes}

\usepackage[style=authoryear, backend=biber]{biblatex}
\addbibresource{biblatex-examples.bib}

\newcommand*{\usedbiblatextypes}{}
\AtDataInput{%
  \xifinlist{\thefield{entrytype}}{\usedbiblatextypes}
    {}
    {\listxadd{\usedbiblatextypes}{\thefield{entrytype}}}}

\newcommand*{\printallentrytypes}{%
  \ifdefvoid{\usedbiblatextypes}
    {}
    {You used the following entry types:
     \begin{itemize}
     \forlistloop{\item}{\usedbiblatextypes}%
     \end{itemize}}}

\begin{document}
\cite{sigfridsson,worman,geer}
\printbibliography

\printallentrytypes
\end{document}

enter image description here

  • Amazing! This is indeed what I originally asked for. I wonder what a good resource is to start LaTeX programming. I understand half of it. I have never programmed in LaTeX. – Melvin Roest Apr 5 '18 at 13:26
1

I suggest you take a simpler approach than you had initially imagined. I understand you'd like to have your bibliography split among the entrytypes, but are looking for a safe way to "not leave anything out".

The below provides an easy way to check whether you have left something out or not. Essentially, you can create a category alreadyinbib and add a AtEverybibitem hook to add any referenced entry to that category. With this, you can catch any remaining entries with a \printbibliography[notcategory=alreadyinbib]. If there are any entries in there, find what their entrytypes are, add them to your list, until the alreadyinbib bibliography results empty.

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage[style=authoryear]{biblatex}

\addbibresource{biblatex-examples.bib}

\DeclareBibliographyCategory{alreadyinbib}

\AtEveryBibitem{%
  \addtocategory{alreadyinbib}{\thefield{entrykey}}%
}

\begin{document}

\nocite{*}

\printbibliography[type=article,title={Articles}]
\printbibliography[type=inproceedings,title={Conference papers}]
\printbibliography[type=book,title={Books}]
\printbibliography[type=inbook,title={Book Chapters}]
\printbibliography[type=incollection,title={Chapters in a Collection}]
\printbibliography[type=MastersThesis,title={Master Theses}]
\printbibliography[type=techreport,title={Tech Reports}]
\printbibliography[type=misc,title={Misc}]
\printbibliography[notcategory=alreadyinbib,title={Missing Entrytypes}]

\end{document}
  • This is a good approach. I did frame the question a bit too implementation specific originally. – Melvin Roest Apr 5 '18 at 13:32
  • 2
    Indeed, there is a tinge of XY problem in your question, in my view. That's why I thought it would be worth to suggest you another approach. – gusbrs Apr 5 '18 at 13:35

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.
https://tex.stackexchange.com/questions/424984/biblatex-generate-which-reference-types-you-have-in-your-bib-file-for-automati
tex.stackexchange.com
crawl=CC-MAIN-2019-30
155276
application/http; msgtype=response
sha1:XW53XLBYWXFVIZZPRRKESITHMZYJAB3U
<urn:uuid:f0148e46-43f4-4cbd-9f4a-9bf806c84dac>
2019-07-18T01:41:34Z
151.101.1.69
text/html
sha1:KXDW6ZHAV4TESGAWI7A352QU54RJ3UVD
<urn:uuid:d21a7418-595c-4ac4-9938-152116a4739a>
https://tex.stackexchange.com/questions/424984/biblatex-generate-which-reference-types-you-have-in-your-bib-file-for-automati
response
<urn:uuid:17483ca2-2869-4bf7-afab-5b2e3b089c06>
isPartOf: CC-MAIN-2019-30
publisher: Common Crawl
description: Wide crawl of the web for July 2019
operator: Common Crawl Admin (info@commoncrawl.org)
hostname: ip-10-99-166-38.ec2.internal
software: Apache Nutch 1.15 (modified, https://github.com/commoncrawl/nutch/)
robots: checked via crawler-commons 1.1-SNAPSHOT (https://github.com/crawler-commons/crawler-commons)
format: WARC File Format 1.1
conformsTo: http://iipc.github.io/warc-specifications/specifications/warc-format/warc-1.1/