2

How do I do this? Programming TeX is still a bit too tough for me. I want all the @online entries that have github.com as their domain names to have their own category so I can add them separately in the reference list.

I know I can do it semi-automatically with keywords, but I want to try to do it automatically.

I got the following working, provided the url had github.com as value and not the complete link. I am not totally sure if this is a MWE since I had to comment a lot of things out.

\documentclass[12pt,a4paper,twoside,openright]{report}

\usepackage{biblatex}
\addbibresource{references.bib}

\DeclareBibliographyCategory{github}

\AtEveryCitekey{%
    \ifentrytype{online}{
        \iffieldequalstr{url}{github.com}{
            \addtocategory{github}{\thefield{entrykey}}%
        }
    }
}



\begin{document}
\cite{ximpel_react_github}
\cite{ximpel_react_github}
\cite{ximpel_react_github}
\cite{smilStatus}
\cite{smilStatus}
\cite{smilStatus}

\printbibliography[heading=subbibliography, category=github, title={Github repositories}]
\printbibliography[heading=subbibliography, type=online, title={Other online sources}]
\end{document}

Here is the bibliography:

@online{ximpel_react_github,
    author = "Melvin Roest",
    title = "XIMPEL React",
    url = "github.com",
    year = "2018",
    urldate = "2018-05-04"
}
@online{smilStatus,
    author = "W3C",
    title = "SMIL Current Status - W3C",
    url = "https://www.w3.org/standards/techs/smil#w3c_all",
    year = "2017",
    urldate = "2017-09-29"
}

\AtEveryCitekey already gave problems when you cited the same in-text citation multiple times. Moreover, it doesn't match to the substring.

I couldn't solve these problems after 1 to 2 hours of Googling.

There was a simlar(ish question, but it had to do with source maps and I don't think source maps were appropriate here. I did try it with source maps though.

  • 1
    I'd say source mappings are the right tool here. You can use source maps to set a keyword based on the domain name. Then you can use keyword=... instead of category=... and should be good. – moewe Apr 05 '18 at 16:43
  • Thanks for pointing me in the right direction! It worked. – Melvin Roest Apr 05 '18 at 16:54

1 Answers1

1

I'm in a hurry but want to answer my own question, because thanks to moewe's help the following worked. It is not the most robust code, but it works!

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map{
      \step[fieldsource=url, match=\regexp{github.com}]
      \step[fieldset=keywords, fieldvalue={$1}]
    }
  }
}

In the document:

\printbibliography[heading=subbibliography, keyword=github.com, title={Github repositories}]
\printbibliography[heading=subbibliography, type=online, notkeyword=github.com, title={Other online sources}]
  • 2
    If you are already using keywords in your .bib file you may want to have a look at https://tex.stackexchange.com/q/420294/35864 – moewe Apr 05 '18 at 16:57