Impossible to mimic `\bibliographystyle{alpha}` in Typst?

Hello, I want to mimic \bibliographystyle{alpha} in Typst. Creating citations and bibliography as can be found here: https://www.bibtex.com/s/bibliography-style-base-alpha/.

The Typst bibliography style “alphanumeric” is not equivalent and does not correctly handle the complex citation style of the bibtex style alpha. Ex creating [Che+17] instead of the wanted [CKKS17] for this paper.

From what I can find this is a fundamental limitation of basing citation style definition on CSL, as it can’t handle more complex citation styles.

Is there a hack to solve this, or is there any expectation to move away from .CSL towards a way that supports complex styles like bibtex “alpha”?

Hello.

Typst doesn’t give [Che17] for the citation.

#let csl = ```xml
<?xml version="1.0" encoding="utf-8"?>
<style xmlns="http://purl.org/net/xbiblio/csl" class="in-text" version="1.0">
  <info>
    <title>Alphanumeric</title>
    <id>http://typst.org/csl/alphanumeric</id>
    <author>
      <name>Martin Haug</name>
      <email>martin.haug@typst.app</email>
    </author>
    <author>
      <name>Laurenz Mädje</name>
      <email>laurenz.maedje@typst.app</email>
    </author>
    <category citation-format="label" />
    <rights>MIT OR Apache-2.0</rights>
    <summary>Alphanumeric citations</summary>
  </info>
  <citation collapse="citation-number" after-collapse-delimiter="; "
    disambiguate-add-year-suffix="true">
    <sort>
      <key variable="author" />
      <key variable="issued" />
    </sort>
    <layout prefix="[" suffix="]" delimiter=", ">
      <group delimiter=", ">
        <group>
            <text variable="citation-label" />
            <text variable="year-suffix" />
        </group>
        <text variable="locator" />
      </group>
    </layout>
  </citation>
</style>
```.text

#let bib = ```bib
@InProceedings{10.1007/978-3-319-70694-8_15,
  author="Cheon, Jung Hee and Kim, Andrey and Kim, Miran and Song, Yongsoo",
  editor="Takagi, Tsuyoshi and Peyrin, Thomas",
  title="Homomorphic Encryption for Arithmetic of Approximate Numbers",
  booktitle="Advances in Cryptology -- ASIACRYPT 2017",
  year="2017",
  publisher="Springer International Publishing",
  address="Cham",
  pages="409--437",
  abstract="We suggest a method to construct a homomorphic encryption scheme for approximate arithmetic. It supports an approximate addition and multiplication of encrypted messages, together with a new rescaling procedure for managing the magnitude of plaintext. This procedure truncates a ciphertext into a smaller modulus, which leads to rounding of plaintext. The main idea is to add a noise following significant figures which contain a main message. This noise is originally added to the plaintext for security, but considered to be a part of error occurring during approximate computations that is reduced along with plaintext by rescaling. As a result, our decryption structure outputs an approximate value of plaintext with a predetermined precision.",
  isbn="978-3-319-70694-8"
}
```.text

#set cite(style: bytes(csl))

#cite(label("10.1007/978-3-319-70694-8_15"))

#bibliography(bytes(bib))

citation-label is assignable by the CSL processor. This is part of Citation label issues · Issue #118 · typst/hayagriva · GitHub.

Thank you. I’ve now corrected that. However, in essence, my question has nothing to do with Typst’s alphanumeric style. I just know it’s been brought up as an acceptable replacement in other forums, which it isn’t in my case.

Your last line seems to attempt to answer my question, though it really doesn’t get me anywhere.

As I understand it, the correct way to solve this in Typst would be to modify the CSL file. However, CSL doesn’t support the scripting capabilities needed to implement such a style. If it did, it would’ve been easy to find in the standard CSL databases, as it is a relatively common citation style used in many journals.

So, to restate my questions: Is it possible to work around this, creating a custom citation style/bibliography without CSL in Typst to mimic \bibliographystyle{alpha}? And is there any ongoing work towards distancing Typst bibliographies from CSL? It currently serves as a major weak point hindering the adoption of Typst for me and my colleagues.

I linked to the issue that describes the same use case, which means you can’t do anything about it unless you patch Typst. The hayagriva crate is the CSL processor used by Typst.

No. Again, see citation-label.

When Bibliography customization from within Typst · Issue #942 · typst/typst · GitHub is closed, you can customize bibliography (and probably citations) however you like. There are several workarounds in that thread, in the meantime. Or you can patch the same thing but in alexandria – Typst Universe, and use a custom package with standard Typst compiler.

Okok, I take this to mean that the standard #bibliography functionality is likely to remain based on CSL—thereby not supporting the citation/bibliography styles I want to create, and that the best solution would likely be to work around this limitation by reimplementing the bibliography/cite functionalities.

Please elaborate. As far as I can tell, this is not a configurable property, unless I am to hardcode the definition of my style/citation label into a patch of hayagriva/csl/citation_label.rs. Are you saying I can somehow easily overwrite how this property is defined, potentially directly in my typst document? How? Or what are you referring to?

It will always be based on CSL, this is what publishers and other entities provide, nothing else.

Well, not right now, until Bibliography customization from within Typst · Issue #942 · typst/typst · GitHub.

Use either those workarounds to somehow modify/recreate bibliography items/citations, or patch the Hayagriva code, since this one attribute is CSL processor dependent.

Referencing

The comment refers to the fact that you literally can’t do anything by modifying CSL file. I included it, and it doesn’t implement the citation-label attribute. The docs say that it’s not modifiable within CSL.

Hard-code won’t work if you have several entries, unless you want to make a mapping. The solution is to fix the logic of how the label is being constructed, which honestly doesn’t even sound that hard to do, but it’s probably not fixed because it very low in priority.

You state this as fact, but it is not the case. CSL is not generally adopted and is not a direct replacement for the bibliography style definitions provided by publishers, like those who use \bibliographystyle{alpha}.

I agree I’m not able to achieve what I want by modifying the CSL definition. However, my reading of the typst documentation seems to point me towards modifying the CSL if I wanted another (maybe custom) bibliography style. The alpha style is by all definitions a bibliography style, it’s just that CSL is not powerful enough to support it.

Ait. Though I’m surprised this is the case. Correct citations and bibliographies is a MAJOR hurdle before typst can be adopted in scientific writing. Typst can in no way replace latex unless this is dealt with, and I feel like the direction to focus on CSL as the main definition of bibliography/citation styles is fundamentally flawed.

There are a lot of MAJOR hurdles for Typst mass adoption (like EPUB, tagged PDF, etc.), however it is already adopted in the scientific writing by IJIMAI and JUTI journals. So for those, and many other things, it already replaced LaTeX. Just depends on the use case. I’ve used Typst since mid 2023, and haven’t used anything else for creating documents or presentations.

tl;dr: I think it’s best to open a feature request at either typst/hayagriva, or typst/biblatex to support reading of bst files. This would be a rather major feature request. This is related to Not possible to resolve `@String` which is defined in style file · Issue #63 · typst/biblatex · GitHub.

Historically, bst files were provided by publishers along with a document class to format your submission. You can consider csl to be a successor for the bst format, as much as biblatex is a successor to bibtex.

As for whether CSL is adopted more or less than bst, who really knows? I can however say one thing: many journals have not migrated from bibtex to biblatex after nearly two decades. Why break something that works? Support for CSL in LaTeX is quite recent, but it does work.

You are right to point out that bst cannot be translated automatically to CSL, and so CSL is not a direct replacement in that sense.

I believe that many publishers do have in fact in addition to the existing bst definitions, also a csl one. It’s always best to ask the editor/publisher.

Without wanting to go out of topic too much, on that particular comment, I have to say that this is not representative of “scientific writing” as a whole, but rather of a small subset of people who decided to explictly accept Typst. I wouldn’t use that as a credible argument for arguing in favour of actual adoption of Typst.

1 Like