How can i use custom .csl files in my template?

I was making a template for an academic paper, and needed to make the citations (@book) be formatted to the right style. I found on the Parameter reference that i could use a custom .csl file that would configure the citations for me. I then wrote this on my template:

#bibliography("./bibliografia.bib", style: "./res/abnt.csl")

I have a file called abnt.csl in the folder res that on got on this github repo, but when i tried to compile, this error appeared.

[20:40:05] compiled with errors

error: failed to load CSL style (data did not match any variant of untagged enum StyleCategory)
    โ”Œโ”€ res/abnt.csl:1:0
    โ”‚  
  1 โ”‚ โ•ญ ๏ปฟ<?xml version="1.0" encoding="utf-8"?>
  2 โ”‚ โ”‚ <style xmlns="http://purl.org/net/xbiblio/csl" class="in-text" version="1.0">
  3 โ”‚ โ”‚   <!-- This style was edited with the Visual CSL Editor (https://editor.citationstyles.org/visualEditor/) -->
  4 โ”‚ โ”‚   <info>
    ยท โ”‚
725 โ”‚ โ”‚ </style>
726 โ”‚ โ”‚ 
    โ”‚ โ•ฐ^

help: error occurred in this call of function `bibliography`
    โ”Œโ”€ tcc.typ:259:3
    โ”‚
259 โ”‚   #bibliography("./bibliografia.bib", style: "./res/abnt.csl")
    โ”‚    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


I am honestly not sure what is going wrong and trying to ask AI for help did not work (as with most things with Typst and AI).

I cannot test if the file works, as i did not even know what a csl file was before today. could someone help?

1 Like

It seems like your CSL / XML file is invalid somehow. Maybe Visual CSL Editor can help?

I found this to be useful to validate custom CSL files: https://validator.citationstyles.org/

1 Like

Workaround

Delete the empty <category/> and <else/>.

--- a/abnt-nbr-6023-2018-nbr-10520-2023-%E2%80%93-citaca%CC%83o-numerica.csl
+++ b/abnt-nbr-6023-2018-nbr-10520-2023-%E2%80%93-citaca%CC%83o-numerica.csl
@@ -19,7 +19,6 @@
     <category citation-format="numeric"/>
     <updated>2023-09-25T04:22:28+00:00</updated>
     <rights>v0.18 (2023-09-25)</rights>
-    <category/>
   </info>
   <locale xml:lang="pt-BR">
     <terms>
@@ -582,7 +581,6 @@
                     <text macro="container-contributors"/>
                   </group>
                 </if>
-                <else/>
               </choose>
               <text macro="container-title" font-weight="normal"/>
               <text macro="advisor-or-recipient"/>
@@ -632,7 +630,6 @@
                   <if match="all" variable="title author">
                     <text term="in" text-case="capitalize-first" font-style="italic"/>
                   </if>
-                  <else/>
                 </choose>
                 <group delimiter=". ">
                   <text macro="container-contributors" text-case="uppercase"/>

According to StyleCategory in citationberg - Rust, <category> should have either citation-format or field, but that category has neither.

Also, quoting the CSL 1.0.2 spec:

As an empty cs:else element would be superfluous, cs:else must contain at least one rendering element.


Nevertheless, typst should really improve the error message for parsing CSL files.

1 Like