forked from typ2anki/typ2anki
Includes real example files or problematic files
May be used for automated tests
- Rust 68.8%
- Typst 18.3%
- Nix 6.6%
- Handlebars 3.3%
- Shell 3%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| .forgejo/workflows | ||
| nix | ||
| src | ||
| typ | ||
| .envrc | ||
| .gitignore | ||
| .gitmodules | ||
| about.hbs | ||
| about.toml | ||
| Cargo.lock | ||
| Cargo.toml | ||
| flake.lock | ||
| flake.nix | ||
| LICENSE | ||
| README.md | ||
Typ2anki
Write Anki-Notes with typst
Anki-connect
You need Anki-connect. This allows us to write the files to anki.
Add the following addon:
2055492159
Note: Anki needs to be restarted after the installation.
Steps
Cloning the repo
git clone https://code.ole.blue/typ2anki/typ2anki.git --recurse-submodules
Compile the program
Nix
nix build .?submodules=1#
Or as a flake input
inputs = {
...
typ2anki.url = "git+https://code.ole.blue/typ2anki/typ2anki?submodules=1";
}
then include the package
environment.systemPackages = [
...
inputs.typ2anki.packages.x86_64-linux.default
];
Install the library
typ2anki install
Write typst files
Include the lib
import "@local/typ2anki-rs:0.1.0": card, note, show_all
#show: show_all
If you get a white card with nothing on it, make sure you only have this show rule (
#show)
Define a note type
#note(
name: "MyNoteName",
fields: ("Field1", "Field2"),
cards: (
(name: "Front-and-back", front: "{{Field1}}", back: "{{Field2}}"),
(name: "Back-and-front", front: "{{Field2}}", back: "{{Field1}}")
)
// optionally provide css
css: "
.card {
text-align: center;
}
"
)
And then just create your notes
#card(
// this id will be used to track changes to the card. Don't change it, otherwise your learning progress in anki will be lost.
id: "1",
deck: "MyDeck", // or nested with "MyDeck::SubDeck"
note_type: "MyNoteName",
Field1: [Some Question],
Field2: [Some Answer]
)
#card(
id: "2",
deck: "MyDeck",
note_type: "MyNoteName",
Field1: [Some other Question],
Field2: [Some other Answer]
)
As this can be very repetitive, you can override the card function with default values:
#let card = card.with(deck: "MyDeck", note_type: "MyNoteName")
#card(
id: "1",
Field1: [Some Question],
Field2: [Some Answer]
)
#card(
id: "2",
Field1: [Some other Question],
Field2: [Some other Answer]
)
Write your files to anki
Make sure you have anki open and run:
typ2anki build file <input.typ>
All your notes have been compiled and pushed to anki.
Examples
Physics SI values (German)
#import "@local/typ2anki-rs:0.1.0": card, note, show_all
#show: show_all
#let card = card.with(render: true, deck: "Physik::Einheiten", note_type: "Einheiten")
#note(
name: "Einheiten",
fields: ("Basisgröße", "Basiseinheit"),
cards: (
(name: "Front-Back", front: "{{Basisgröße}}", back: "{{Basiseinheit}}"),
(name: "Back-Front", front: "{{Basiseinheit}}", back: "{{Basisgröße}}"),
),
css: "
.card {
text-align: center;
}
",
)
#card(
id: "1",
Basisgröße: [Stoffmenge],
Basiseinheit: [Mol: _mol_]
)
#card(
id: "2",
Basisgröße: [Lichtstärke],
Basiseinheit: [Candela: _cd_]
)
#card(
id: "3",
Basisgröße: [Ladung in einer Sekunde durch die \ Querschnittsfläche eines Leiters, wenn $A"(mpere)" = 1$],
Basiseinheit: [Coulomb: _C_]
)