citar icon indicating copy to clipboard operation
citar copied to clipboard

Typst support

Open ashton314 opened this issue 2 months ago • 16 comments

Adding support for Typst would be pretty nifty; it seems to be gaining some momentum.

ashton314 avatar Oct 27 '25 18:10 ashton314

If I end up using Typst more I will definitely see if I can put together the PR for this.

ashton314 avatar Oct 27 '25 18:10 ashton314

I'm a fan, so agree; the latest release added typography features that bring it up to par now with the best of the LaTeX world.

But I also don't use it for academic stuff. Am not really sure what their citation support is like now.

bdarcus avatar Oct 27 '25 18:10 bdarcus

Looks like the support CSL files! Docs: https://typst.app/docs/reference/model/bibliography/

ashton314 avatar Oct 27 '25 20:10 ashton314

Looks like the support CSL files! Docs: https://typst.app/docs/reference/model/bibliography/

Yes, I do know that; I submitted the original FR for that. I assumed you knew.

I don't know, however, what they do with the actual citations.

bdarcus avatar Oct 27 '25 20:10 bdarcus

I assumed you knew.

Ah, no. I'd been observing Typst from afar until this past week. Some of other PhD students in my lab are pretty excited about it, so I decided to see what all the fuss was about—I don't know much historical context.

ashton314 avatar Oct 27 '25 20:10 ashton314

Update: I am slowly working on citar-typst.el in a fork here. I can already read the local bibliography file and insert citations. This covers like 95% of my use cases. I'll try to fill out the remaining important functions.

Something I haven't thought much about yet is whether or not to support Typst's bespoke bibliography format.

ashton314 avatar Nov 03 '25 20:11 ashton314

@bdarcus If you get a minute, would you mind taking a look at my fork to tell me if I'm on the right track?

If I'm understanding correctly, a citation is composed of one or more keys, like you'd have in a \cite{key1, key2} in LaTeX. Typst seems to let keys be space-separated with no delimiters around them. Typst docs have an example.

That branch is very rough—I'm not particularly experience with Emacs Lisp. Any corrections or a "keep going!" would be welcome. :)

ashton314 avatar Nov 30 '25 06:11 ashton314

Hey @ashton314 I've not for awhile had my head in this code, so nothing immediately occurs to me.

But I'm wondering, now that I think about it, if it would be better to spin this off as a separate project; e.g. citar-typst? In theory, the design should facilitate that, without having to do any kind of funky hacking. If it doesn't, perhaps there are some tweaks we can make here to ensure that it does?

cc @roshanshariff, who IIRC has also been thinking about spinning off some of what we currently have into separate packages?

bdarcus avatar Nov 30 '25 15:11 bdarcus

For spinning off, AFAICT the only thing I'd need to do is push the requisite function mapping into citar-major-mode-functions, correct?

Pros and cons to a separate project that I can see:

  • Pro As a separate package, it's easier for me to develop it.
  • Pro The citar-typst package can have stronger dependency requirements (e.g. Emacs 29 or better) if I want to continue to rely on the treesit package. (Maybe there's something in compat that can help me with this—I haven't looked.)
  • Pro/Con I don't get to take advantage of your lovely testing infrastructure. ;) I'll have to learn how to set up a similar CI system and do Elisp testing, which might be a good thing.
  • Con Discoverability would be hampered: Typst users would need to not only know about Citar but the citar-typst package as well. Possible solution: something like what embark-consult does and add some small code to Citar to alert the user if they open a .typ file without citar-typst installed.

The last issue of discoverability seems non-negligible to me, but it's been done before with this and other packages. Typst support seems better-suited to direct integration than, say, the (excellent) citar-denote package, but keeping it separate has its benefits too. If you've been thinking about spinning some things off then this would definitely be a good add-on.

The other thing that that I haven't looked at much yet Typst's custom Hayagriva bibliography format. I don't use this in my work at all, but I imagine it'd be nice to future-proof the thing. Looks like Hayagriva is just YAML, so it should be easy to parse and load into whatever format Citar expects it to be in—at least, that's my hope.

(xkcd disclaimer: I liked em-dashes and bulleted lists before LLMs)

ashton314 avatar Dec 01 '25 17:12 ashton314

  • Discoverability would be hampered: Typst users would need to not only know about Citar but the citar-typst package as well. Possible solution: something like what embark-consult does and add some small code to Citar to alert the user if they open a .typ file without citar-typst installed.

Could also include a link to it on the README here?

The other thing that that I haven't looked at much yet Typst's custom Hayagriva bibliography format.

It is compliant YAML, but of course with it's own model. Perhaps there's ways to benefit from generic YAML support in Emacs, but also somehow customize it?

bdarcus avatar Dec 01 '25 17:12 bdarcus

The other thing that that I haven't looked at much yet Typst's custom Hayagriva bibliography format.

It is compliant YAML, but of course with it's own model. Perhaps there's ways to benefit from generic YAML support in Emacs, but also somehow customize it?

Since we already have parsebib, and parsebib already supports Bib(La)TeX and CSL-JSON, it might make sense to add support for Hayagriva to it? There's a YAML parser on GNU ELPA: https://elpa.gnu.org/packages/yaml.html, which IME works well. All that would need to be decided then is how to represent the data in Emacs. As is already the case with BibTeX/biblatex and CSL-JSON, there should probably be two modes for reading the data: one that faithfully represents the contents of the file, and one that makes it suitable for display. The latter should probably at least remove the parent entries and move their key/value pairs to the containing entry.

joostkremers avatar Dec 01 '25 18:12 joostkremers

Since we already have parsebib, and parsebib already supports Bib(La)TeX and CSL-JSON, it might make sense to add support for Hayagriva to it?

Seems a great idea, though I have a feeling it would also be valuable support editing of these files.

Maybe in that case, parsebib would read the data and make it available for display, but citar-typst could add support for the editing?

bdarcus avatar Dec 01 '25 18:12 bdarcus

parsebib

That looks like a great place to to put the parsing of Hayagriva files!

citar-typst could add support for the editing?

What kind of facilities do you think would be useful? Navigation, a capf for keys, and validation checker maybe?

ashton314 avatar Dec 01 '25 23:12 ashton314

What kind of facilities do you think would be useful? Navigation, a capf for keys, and validation checker maybe?

I imagine ideal would be auto-completion of fields and entries, I guess via a capf?

I'm a bit out of my element on this, since I've never used Emacs for editing bib files; or at least not creating them. But if you want to add an article, for example, it should help you do that.

bdarcus avatar Dec 02 '25 13:12 bdarcus

I'm a bit out of my element on this, since I've never used Emacs for editing bib files; or at least not creating them. But if you want to add an article, for example, it should help you do that.

I guess there would be the immediate question of where that functionality should live; in a general typst major mode, in a typst bib mode, or in this hypothetical citar-typst?

bdarcus avatar Dec 03 '25 13:12 bdarcus

I'm thinking now that a bibliography-editing mode would do best on its own. Maybe I can make a citar-typst package that 1.) allows Citar to work in .typ files, and 2.) includes a hayagriva-mode for editing the YAML-based bib files.

I'll start working on this as a separate package. It's gonna take me a minute to get started though because I've got my quals this week 😬

ashton314 avatar Dec 03 '25 18:12 ashton314