https://github.com/sgomezsal/typ2anki
Typ2Anki is a tool that converts Typst documents into Anki flashcards.
https://github.com/sgomezsal/typ2anki
anki typst
Last synced: 3 months ago
JSON representation
Typ2Anki is a tool that converts Typst documents into Anki flashcards.
- Host: GitHub
- URL: https://github.com/sgomezsal/typ2anki
- Owner: sgomezsal
- License: mit
- Created: 2024-12-23T05:37:02.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2026-01-14T14:22:11.000Z (5 months ago)
- Last Synced: 2026-01-14T17:59:46.647Z (5 months ago)
- Topics: anki, typst
- Language: Rust
- Homepage:
- Size: 66 MB
- Stars: 36
- Watchers: 3
- Forks: 4
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Typ2Anki
**Typ2Anki** is a tool designed to integrate flashcard creation seamlessly into your Typst-based notes. By utilizing a custom Typst package, you can create cards directly in your notes and sync them effortlessly to a selected Anki deck. This enables you to transform study material into flashcards without disrupting your Typst workflow.
- Create flashcards directly within your Typst documents.
- Sync these flashcards to a chosen Anki deck effortlessly.
- Streamlined workflow for note-taking and spaced repetition learning.
---
## Table of Contents
1. **[Installation and Configuration](#installation-and-configuration)**
- [Installing AnkiConnect](#installing-ankiconnect)
- [Installing the Rust](#installing-the-rust-package)
- [Installing the Typst Package](#installing-the-typst-package)
2. **[Usage](#usage)**
- [Basic Workflow](#basic-workflow)
- [Extra functionality and configuration](#extra-functionality-and-configuration)
- [Customizing Cards](#customizing-cards)
- [Example repositories](#example-repositories)
3. **[Troubleshooting](#troubleshooting)**
- [Common Issues](#common-issues)
4. **[Roadmap](#roadmap)**
5. **[Future Plans](#future-plans)**
6. **[Contributing](#contributing)**
7. **[License](#license)**
---
## Installation and Configuration
### Installing AnkiConnect
1. Open Anki and navigate to **Tools > Add-ons**.
2. Click **Get Add-ons** and enter the following code to install AnkiConnect:
```
2055492159
```
Alternatively, visit the [AnkiConnect Add-on page](https://ankiweb.net/shared/info/2055492159) to learn more.
3. Restart Anki to activate the add-on.
4. Verify that AnkiConnect is running by visiting [http://localhost:8765](http://localhost:8765) in your browser. If it loads, the add-on is properly installed and functioning.
---
### Installing the Rust Package
1. Install Rust and Cargo by following the instructions at [https://www.rust-lang.org/tools/install](https://www.rust-lang.org/tools/install).
2. Install the Typ2Anki package using cargo
> [!Note] It is recommended to get [cargo-binstall](https://github.com/cargo-bins/cargo-binstall) for faster installation, as the build process of typ2anki can take some time.
```bash
cargo binstall typ2anki --locked || cargo install typ2anki --locked
```
3. Verify the installation:
```bash
typ2anki --help
```
#### Nix Flake
On systems with nix installed and flakes enabled, the
python package can be executed with the following command:
```sh
nix run github:sgomezsal/typ2anki
```
---
### Installing the Typst Package
#### Method 1: Using Package Manager (Recommended)
1. Add the Typ2Anki package to your Typst document:
```typst
#import "@preview/typ2anki:0.1.0": *
```
#### Method 2: Using the Rust Package
1. After installing the Rust package, you can run the following command to set up the Typst package:
```bash
typ2anki --install-typst-pkg
```
2. Navigate to your flashcards directory:
```bash
cd ~/Documents/Flashcards/ # or your preferred location
```
3. Create your `ankiconf.typ` file with basic configurations:
```typst
// Custom imports for flashcards
#import "@local/typ2anki:0.1.0": *
#import "@preview/pkgs"
#let conf(
doc,
) = {
// Custom configurations
doc
}
```
4. Create a new Typst document (e.g., `main.typ`):
```typst
#import "ankiconf.typ": *
#show: doc => conf(doc)
#card(
id: "001",
target-deck: "Target-Deck",
q: "Question",
a: "Answer"
)
```
5. Run typ2anki in your project directory:
```bash
typ2anki .
```
#### Method 3: Manual Installation
If you encounter issues with the package import, you can set up the package manually:
1. Clone the repository:
```bash
git clone https://github.com/sgomezsal/typ2anki
cd typ2anki
```
2. Create the local package directory:
```bash
mkdir -p ~/.local/share/typst/packages/local/typ2anki/0.1.0
```
3. Copy the package files (note the `-r` flag for recursive copy):
```bash
cp -r src/ typst.toml ~/.local/share/typst/packages/local/typ2anki/0.1.0
```
4. Navigate to your flashcards directory:
```bash
cd ~/Documents/Flashcards/ # or your preferred location
```
5. Create your `ankiconf.typ` file with basic configurations:
```typst
// Custom imports for flashcards
#import "@local/typ2anki:0.1.0": *
#import "@preview/pkgs"
#let conf(
doc,
) = {
// Custom configurations
doc
}
```
6. Create a new Typst document (e.g., `main.typ`):
```typst
#import "ankiconf.typ": *
#show: doc => conf(doc)
#card(
id: "001",
target-deck: "Target-Deck",
q: "Question",
a: "Answer"
)
```
7. Run typ2anki in your project directory:
```bash
typ2anki .
```
---
## Usage
### Basic Workflow
1. Create a Typst file with flashcards:
```typst
#import "ankiconf.typ": *
#show: doc => conf(doc)
#card(
id: "001",
target-deck: "Typst",
q: "What is Typst?",
a: "A modern typesetting system."
)
```
2. Create your `ankiconf.typ` file with basic configurations:
```typst
// Custom imports for flashcards
#import "@preview/typ2anki:0.1.0"
#import "@preview/pkgs"
#let conf(
doc,
) = {
// Custom configurations that will run on the document
doc
}
// Any other global variables or settings can go here - they will be accessible in all cards
```
3. Use Typ2Anki to compile all files in the project directory:
```bash
typ2anki ./path/to/your/project
```
4. Open your Anki deck to check the newly added flashcards.
---
### Extra functionality and configuration
- **Command line options**: Do `typ2anki --help` to see all available options.
- Options include: specifying a max width for cards (to make sure they fit on phones - ex: `--max-card-width 430pt`), excluding files or decks
- **Configuration file**: You can create a `typ2anki.toml` file in your project directory to customize the behavior of `typ2anki`. This file can include default command line options for the project, so you don't have to specify them every time you run the command.
- **Compiling from .zip**: You can pass a `.zip` file to `typ2anki` to compile all Typst files inside it. This is useful so that if you use [typst.app](https://typst.app) you can download your project as a `.zip` and compile it with `typ2anki` without having to extract it first.
---
### Customizing Cards
To modify card appearance, you can define custom card logic:
```typst
#let custom-card(
id: "",
q: "",
a: "",
..args
) = {
card(
id: id,
q: q,
a: a,
container: true,
show-labels: true
)
}
```
---
### Example repositories:
- See [examples](https://github.com/sgomezsal/typ2anki/tree/main/examples) for a few cards
- Some math cards made using typ2anki: [itsvyle/typ2anki-demo](https://github.com/itsvyle/typ2anki-demo)
---
## Troubleshooting
### Common Issues
- **AnkiConnect not responding**:
- Ensure Anki is running and AnkiConnect is installed correctly.
- **Typst file compilation errors**:
- Check for syntax issues in your Typst file.
- Ensure your `ankiconf.typ` contains the necessary imports and configurations.
- Do note that inside a given card you only have access to the scope that's in the current card. You cannot have any "global" variables in a given file. Any "global" or "shared" variables should be defined in the `ankiconf.typ` file.
---
## Roadmap
1. **Command to Delete Cards**: Implement a feature to remove specific cards from Anki.
2. **Efficiency Improvements**: Optimize the syncing process for speed and reliability.
3. **Support for Other Card Types**: Expand compatibility to include more complex card formats.
4. **Support to use what's previously been set in the file**: Allow using context from the file, and not just `ankiconf.typ`
---
## Future Plans
- Enhance user experience with more robust error handling and syncing options.
- Broaden integration with Typst to support various output formats.
---
## Contributing
Contributions are welcome! Feel free to open issues or submit pull requests for bug fixes, feature enhancements, or documentation improvements.
---
## License
This project is licensed under the [MIT License](LICENSE).
---
Developed with ❤️ by [sgomezsal](https://github.com/sgomezsal). Let’s make learning efficient and enjoyable!