How to parse BibTex "@incollection" or Hayagriva "type: anthos, parent-type: anthology" entry in CSL?

Hi all,

I’m trying to parse a BibTex entry of type “incollection” with a custom CSL style file in the typst web app - either directly, or by first converting the .bib file to .yml with Hayagriva CLI.

When trying to parse the .bib file directly, I only get it to work if I change the entry type to “inbook”: then CSL understands the .bib entry as a chapter in a book, correctly showing up in the bibliography, using “booktitle” from .bib as “container-title” in .csl. However, if leaving the .bib entry as “incollection”, I don’t get it to show up in the bibliography at all.

When converting the incollection entry from the .bib file to a .yml file with Hayagriva CLI, the entry type in the .yml file is converted to “anthos” and the parent type to “anthology”. This is correct. However, again I don’t get it to show up in the bibliography at all. It only works, if I change the entry type to “chapter” instead of “anthos” (then it works, no matter if the parent type is “anthology” or “book”).

So this .bib entry works:

@inbook{Example2025,
 title = {Title},
 booktitle = {Anthology title},
}

…as does this corresponding conversion to .yml:

Example2025:
  type: chapter
  title: Title
  parent:
    type: book
    title: Anthology title

The original Bib(La)Tex entry, however, I can’t get to parse with CSL:

@incollection{Example2025,
 title = {Title},
 booktitle = {Anthology title},
}

…and neither this corresponding conversion to .yml:

Example2025:
  type: anthos
  title: Title
  parent:
    type: anthology
    title: Anthology title

Any advice? Is it just not possible to parse Bib(La)Tex “incollection” or Hayagriva “type: anthos” entries in CSL (but if so, why does Hayagriva converts “incollection” to “type: anthos” in the first place)? Or did I just miss the corresponding types in CSL that these types map to?

The relevant part in my .csl file looks like this (excerpt):

<if type="chapter" match="any">
  <text variable="title" suffix=". "/>
  <text variable="container-title" suffix=". "/>
</if>

As said this works if entry type is “inbook” or “type: chapter”. What type instead of “chapter” would work for parsing “type: anthos” entries in hayagriva.yml?

Hello,
According to the relevant code[1], it appears that you have to set type: anthology in your YAML (hayagriva format) bibliography, as well as check for type="collection" in your CSL file.

type: anthos is not at all translated for CSL styles to use, which could be a bug. Consider opening an issue on GitHub - typst/hayagriva: Rusty bibliography management. so we can discuss if and how this should be changed. Thanks!


  1. Hayagriva source code:

    ↩︎

Hi Peter,

I found the same issue. As PgBiel mentioned, the "anthos"type is not translated into a CSL type. I am creating a CSL style and added a debug macro that compares bibliography entries with all CSL types and print the one that match. My macro print “unknown” if no match is found. My CSL style with the macro function is hidden below:

Summary
<?xml version="1.0" encoding="utf-8"?>
<style xmlns="http://purl.org/net/xbiblio/csl" class="in-text" version="1.0" demote-non-dropping-particle="never">
  <info>
    <title>DACT’s ABNT Numeric</title>
    <id>dact-abnt-numeric</id>
  </info>
  <macro name="debug">
<choose>
<if type="article">
<text value="article"/>
</if>
<else-if type="article-journal">
<text value="article-journal"/>
</else-if>
<else-if type="article-magazine">
<text value="article-magazine"/>
</else-if>
<else-if type="article-newspaper">
<text value="article-newspaper"/>
</else-if>
<else-if type="bill">
<text value="bill"/>
</else-if>
<else-if type="book">
<text value="book"/>
</else-if>
<else-if type="broadcast">
<text value="broadcast"/>
</else-if>
<else-if type="chapter">
<text value="chapter"/>
</else-if>
<else-if type="classic">
<text value="classic"/>
</else-if>
<else-if type="collection">
<text value="collection"/>
</else-if>
<else-if type="dataset">
<text value="dataset"/>
</else-if>
<else-if type="document">
<text value="document"/>
</else-if>
<else-if type="entry">
<text value="entry"/>
</else-if>
<else-if type="entry-dictionary">
<text value="entry-dictionary"/>
</else-if>
<else-if type="entry-encyclopedia">
<text value="entry-encyclopedia"/>
</else-if>
<else-if type="event">
<text value="event"/>
</else-if>
<else-if type="figure">
<text value="figure"/>
</else-if>
<else-if type="graphic">
<text value="graphic"/>
</else-if>
<else-if type="hearing">
<text value="hearing"/>
</else-if>
<else-if type="interview">
<text value="interview"/>
</else-if>
<else-if type="legal_case">
<text value="legal_case"/>
</else-if>
<else-if type="legislation">
<text value="legislation"/>
</else-if>
<else-if type="manuscript">
<text value="manuscript"/>
</else-if>
<else-if type="map">
<text value="map"/>
</else-if>
<else-if type="motion_picture">
<text value="motion_picture"/>
</else-if>
<else-if type="musical_score">
<text value="musical_score"/>
</else-if>
<else-if type="pamphlet">
<text value="pamphlet"/>
</else-if>
<else-if type="paper-conference">
<text value="paper-conference"/>
</else-if>
<else-if type="patent">
<text value="patent"/>
</else-if>
<else-if type="performance">
<text value="performance"/>
</else-if>
<else-if type="periodical">
<text value="periodical"/>
</else-if>
<else-if type="personal_communication">
<text value="personal_communication"/>
</else-if>
<else-if type="post">
<text value="post"/>
</else-if>
<else-if type="post-weblog">
<text value="post-weblog"/>
</else-if>
<else-if type="regulation">
<text value="regulation"/>
</else-if>
<else-if type="report">
<text value="report"/>
</else-if>
<else-if type="review">
<text value="review"/>
</else-if>
<else-if type="review-book">
<text value="review-book"/>
</else-if>
<else-if type="software">
<text value="software"/>
</else-if>
<else-if type="song">
<text value="song"/>
</else-if>
<else-if type="speech">
<text value="speech"/>
</else-if>
<else-if type="standard">
<text value="standard"/>
</else-if>
<else-if type="thesis">
<text value="thesis"/>
</else-if>
<else-if type="treaty">
<text value="treaty"/>
</else-if>
<else-if type="webpage">
<text value="webpage"/>
</else-if>
<else>
<text value="unknown"/>
</else>
</choose>
</macro>
  <macro name="title">
    <choose>
      <if type="book collection report" match="any">
        <text variable="title" font-style="italic" text-case="title"/>
      </if>
      <else>
        <text variable="title" text-case="title"/>
      </else>
    </choose>
  </macro>
  <!-- I use &#160; as non-breaking space -->
  <citation collapse="citation-number">
    <layout vertical-align="sup" delimiter=",&#160;">
      <group delimiter=",&#160;">
        <text variable="citation-number"/>
        <group delimiter="&#160;">
          <label variable="locator" form="short"/>
          <text variable="locator"/>
        </group>
      </group>
    </layout>
  </citation>
  <bibliography second-field-align="flush">
    <layout>
      <text variable="citation-number"/>
      <group delimiter=". " suffix=".">
        <names variable="author">
          <name delimiter="; " initialize-with="." name-as-sort-order="all"/>
          <label form="short" prefix=" (" suffix=")"/>
          <substitute>
            <names variable="editor"/>
          </substitute>
        </names>
        <text macro="title"/>
        <text variable="edition" suffix=". ed."/>
        <group delimiter=", ">
          <group>
            <text variable="publisher-place"/>
            <text variable="publisher" prefix=": "/>
          </group>
          <text variable="container-title" font-style="italic"/>
          <text variable="volume" prefix="v. "/>
          <text variable="issue" prefix="n. "/>
          <text variable="page" prefix="p. "/>
          <date variable="issued" delimiter=" ">
            <date-part name="day"/>
            <date-part name="month" form="short"/>
            <date-part name="year"/>
          </date>
        </group>
        <text variable="DOI" prefix="DOI: "/>
      </group>
      <text macro="debug" prefix=" <debug>" suffix="</debug>"/>
    </layout>
  </bibliography>
</style>

Example in Typst:

#show regex("<debug>.*?</debug>"): it => {
  set text(fill: blue)
  show regex("unknown"): set text(fill: red)
  show "<debug>": ""
  show "</debug>": ""
  it
}

#bibliography("bibliography.yml", style: "dact-abnt-numeric.csl")

Note that reference 2 is of type “anthology”, and it is correctly translated into a CSL “collection”. Reference 5, however, is of type “anthos” and a CSL type is not assigned. The Hayagriva source:

Jones2001:
  type: anthology
  title: Wind stress over the ocean
  editor:
    - Jones, Ian S. F.
    - Toba, Yoshiaki
  date: 2001
  publisher:
    name: University Press
    location: Cambridge

Donelan1979:
  type: anthos
  title: On the fraction of wind momentum retained by waves
  author: Donelan, M.
  date: 1979
  page-range: 141-159
  parent:
    title: "Marine forecasting: predictability and modelling in ocean hydrodynamics"
    editor: Nihoul, Jacques C. J.
    publisher:
      name: Elsevier
      location: Amsterdam
  serial-number:
    doi: 10.1016/s0422-9894(08)71128-0

For now, I think I will use the “chapter” type, which is translated to CSL “chapter” type, though I am not sure if it is semantically appropriate for this type of work. Perhaps I could define parent type as “anthology” since “chapter” parent is “book” by default.

I will open an issue in Hayagriva’s repo if there is not already one.

1 Like