Has anyone tried drawing musical notes in Typst?

Hi Everyone,
I have been looking for ways to write out musical notation in typst. I know there is the chordx and conchord pachages for guitar chords. But has anyone tried to draw full musical notation?

2 Likes

The only thing I have seen so far is this one. I recommend looking at the examples to see what it is capable of (spoiler: not much). I guess it could be kind of starting point if you want to work in this direction.

Unfortunately, the task is quite hard. I wanted to try it related to conchord tabs, but gave up quickly. Rendering (a very large amount) symbols properly is not enough, to make it usable you should also implement several layout features. A very simple example would be scaling of the distance between symbols the way that a number of bars is an integer (that feature is actually implemented at conchord for tabs).

So nope, I can’t say that would be easy. But if you have time and skills to invest, having a music notation package would be very nice!

4 Likes

I’m currently facing the same challenge and have some preliminary thoughts on the matter.

I’ve noticed that abcjs is a powerful open-source library capable of converting ABC notation into SVG vector graphics (see https://www.abcjs.net/). Some markdown renderers also support ABC notation directly. Unfortunately, Typst does not allow importing JavaScript code.

However, Typst can import WebAssembly (WASM) modules, which could potentially serve as a bridge to call libraries written in other languages. The process of converting JavaScript (like abcjs) to WASM—while unconventional—appears complex and is beyond my current capabilities. Nevertheless, I believe this approach would be significantly more convenient and powerful than implementing ABC notation support purely within Typst.

I’m sharing this observation here in the hope it might inspire others to tackle this issue. If someone succeeds in implementing such a solution, please notify me.

The packages jogs – Typst Universe and ctxjs – Typst Universe provide Javascript runtimes as WASM plugins, so running abcjs “directly” is maybe an option. Would be interesting and valuable to see if that works!

I found a program written in C that compiles abc to svg. Unfortunately, it is no longer maintained. But if we accept this one drawback, this program is actually the closest to our goal

https://chiselapp.com/user/moinejf/repository/abc2svg/doc/trunk/README.md

If we are not satisfied, we will have this project. However, this is written in JavaScript.

On my side, I use lilypond with SVG output and embed the result in typst as a simple image.
Here is the command line I use to generate the svg:

lilypond --svg "-duse-paper-size-for-page=#f" "-dno-point-and-click" -o "output.svg" "input.ly"

My music code is not embedded in typst code, but i much prefer the lilypond output over various abc engines.
I would indeed prefer to have a way to call lilypond from typst directly, but that’s another story.