LilyPond (sheet music typesetting) integration

AnkiWeb addon 1080109152

Renders LilyPond sheet music snippets from tags or fields into images for Anki cards, with customizable templates and mobile-friendly image fields.
AI-generated summary; may contain mistakes.

card-creationformattingcard-templatesmobile-compatible

Open on AnkiWeb GitHub Find alternatives

AnkiWeb

Votes
0 (πŸ‘ 0 Β· πŸ‘Ž 0)
Updated
2021-09-28
Anki versions
2.1.43~
License
AGPL-3.0 (from the headers of the Python files)
Virus scan
No ClamAV match A match does not prove malware. No match does not prove that the code is safe.
Languages
Python, JSON
Description language
en

Maintenance

abandoned

  • Last update or commit: 2021-09-28 (1860 days before the snapshot).
  • Commits in the last year: 0.
  • Issues are turned off.
  • Pull requests: 1 open, 0 merged.

Will it work on my Anki?

Version branches
Min AnkiMax AnkiUpdated
2.1.352.1.43+2021-09-28
History across monthly snapshots

Loading…

Similar addons

Export Anki cards as picture

Exports Anki cards as images using customizable Jinja2 HTML templates and CSS, with configurable resolution, auto-cropping, cloze replacement, excluded fields, and per-note/card-type templates.

exportcard-templates

1 votes 0% approval πŸ‘ 0 Β· πŸ‘Ž 1 ⭐ 0 Anki 24.06.2~ Updated 2024-06-18
AnkiPdffer

Exports Anki decks as print-ready PDFs or standalone offline HTML files, with customizable layouts, themes, typography, native card rendering, and an interactive image viewer.

export

14 votes 78% approval πŸ‘ 14 Β· πŸ‘Ž 0 ⭐ 8 Anki 2.1.1~ Updated 2026-06-02

Description

LilyPond integration for Anki Add sheet music snippets to your Anki deck, wrapped in [lilypond][/lilypond] tags. This addon requires LilyPond in order to work. GitHub How to use
  • Wrap inline LilyPond code in tags: [lilypond]c d e[/lilypond]
  • Create fields for LilyPond code with -lilypond at the end of the field's name, e.g. front-lilypond or back-lilypond. The entire contents of which will be rendered, tags not required: c d e
  • Create fields for LilyPond code and put [lilypond][/lilypond] tags around them in the card template. This is not recommended as music will be re-rendered every time the card is shown.
Please refer to the LilyPond homepage and documentation for details on how to write LilyPond code. Templates The styling of LilyPond output is controlled by templates. The default template looks like this: \paper{ indent=0\mm line-width=120\mm oddFooterMarkup=##f oddHeaderMarkup=##f bookTitleMarkup = ##f scoreTitleMarkup = ##f } { %ANKI% } Where %ANKI% will be replaced with the code to be rendered. You can add your own templates to the user_files directory in the addon's files (see Tools -> Addons -> LilyPond Integration -> View Files). You'll need to restart Anki after making any changes. To use a template called exampleTemplate:
  • In inline tags: [lilypond=exampleTemplate]c d e[/lilypond]
  • In a LilyPond field add -exampleTemplate to the end of the field's name, e.g. front-lilypond-exampleTemplate.
Multi-part templates You can create a template with multiple occurrences of %ANKI%, then separate sections of code with %%% which will then be substituted in to the corresponding occurrences. For example with the LilyPond code c d e %%% f g a the first occurrence of %ANKI% in the template will be replaced with c d e, and the second occurrence of %ANKI% with will be replaced with f g a. Surplus occurrences of %ANKI% in the template will be left as-is (which will cause errors in LilyPond). Surplus sections of code will be ignored. Mobile/Web support Anki addons are desktop only, so by default, LilyPond images won't appear on other platforms since those platforms won't know what to make of a [lilypond] tag or how to treat a -lilypond field. As a workaround you can use LilyPond fields and for each field create another field with the same name but ending with -lilypondimg. The desktop addon will replace the contents of this field with the rendered image. You can then use this field in your notes. For example, if your field is front-lilypond, with content c d e, create the field front-lilypondimg and use the front-lilypondimg field in your card template wherever you want the rendered music to appear. As long as you create your cards on desktop so that the plugin can generate the image this image will then be visable on all platforms. Note that the contents of the -lilypondimg field will be overwritten so don't put anything important in there.

README

LilyPond integration for Anki

Add sheet music snippets to your Anki deck, wrapped in [lilypond][/lilypond] tags.

This addon requires LilyPond in order to work.

How to use

  • Wrap inline LilyPond code in tags:

    [lilypond]c d e[/lilypond]
    
  • Create fields for LilyPond code with -lilypond at the end of the field's name, e.g. front-lilypond or back-lilypond. The entire contents of which will be rendered, tags not required:

    c d e
    
  • Create fields for LilyPond code and put [lilypond][/lilypond] tags around them in the card template. This is not recommended as music will be re-rendered every time the card is shown.

Please refer to the LilyPond homepage and documentation for details on how to write LilyPond code.

Templates

The styling of LilyPond output is controlled by templates. The default template looks like this:

\paper{
  indent=0\mm
  line-width=120\mm
  oddFooterMarkup=##f 
  oddHeaderMarkup=##f 
  bookTitleMarkup = ##f 
  scoreTitleMarkup = ##f 
}

{ %ANKI% }

Where %ANKI% will be replaced with the code to be rendered.

You can add your own templates to the user_files directory in the addon's files (see Tools -> Addons -> LilyPond Integration -> View Files). You'll need to restart Anki after making any changes. Also note that if you want to use LilyPond's \include directive you'll need to provide to full path to the file.

To use a template called exampleTemplate:

  • In inline tags:
    [lilypond=exampleTemplate]c d e[/lilypond]
    
  • In a LilyPond field add -exampleTemplate to the end of the field's name, e.g. front-lilypond-exampleTemplate.

Multi-part templates

You can create a template with multiple occurrences of %ANKI%, then separate sections of code with %%% which will then be substituted in to the corresponding occurrences.

For example with the LilyPond code

c d e
%%%
f g a

the first occurrence of %ANKI% in the template will be replaced with c d e, and the second occurrence of %ANKI% with will be replaced with f g a.

Surplus occurrences of %ANKI% in the template will be left as-is (which will cause errors in LilyPond). Surplus sections of code will be ignored.

Mobile/Web support

Anki addons are desktop only, so by default, LilyPond images won't appear on other platforms since those platforms won't know what to make of a [lilypond] tag or how to treat a -lilypond field.

As a workaround you can use LilyPond fields and for each field create another field with the same name but ending with -lilypondimg. The desktop addon will replace the contents of this field with the rendered image. You can then use this field in your notes.

For example, if your field is front-lilypond, with content c d e, create the field front-lilypondimg and use the front-lilypondimg field in your card template wherever you want the rendered music to appear. As long as you create your cards on desktop so that the plugin can generate the image this image will then be visable on all platforms.

Note that the contents of the -lilypondimg field will be overwritten so don't put anything important in there.

ToDo

  • [x] Configuration parameters for lilypond executable
  • [ ] Config options for HTML tag attributes (alt, etc.)
  • [ ] Menu integration (for templates?)
  • [ ] Menu option to regenerate all images (also reload templates)
  • [x] Use .ily files for templates
  • [ ] Allow simple pathnames for \include-s in templates