Skip to content

sgomezsal/typ2anki

Repository files navigation

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

  2. Usage

  3. Troubleshooting

  4. Roadmap

  5. Future Plans

  6. Contributing

  7. 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 to learn more.

  3. Restart Anki to activate the add-on.

  4. Verify that AnkiConnect is running by visiting 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.
  2. Install the Typ2Anki package using cargo

[!Note] It is recommended to get cargo-binstall for faster installation, as the build process of typ2anki can take some time.

cargo binstall typ2anki --locked || cargo install typ2anki --locked
  1. Verify the installation:

    typ2anki --help

Nix Flake

On systems with nix installed and flakes enabled, the python package can be executed with the following command:

nix run github:sgomezsal/typ2anki

Installing the Typst Package

Method 1: Using Package Manager (Recommended)

  1. Add the Typ2Anki package to your Typst document:

    #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:

    typ2anki --install-typst-pkg
  2. Navigate to your flashcards directory:

    cd ~/Documents/Flashcards/  # or your preferred location
  3. Create your ankiconf.typ file with basic configurations:

    // 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):

    #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:

    typ2anki .

Method 3: Manual Installation

If you encounter issues with the package import, you can set up the package manually:

  1. Clone the repository:

    git clone https://github.com/sgomezsal/typ2anki
    cd typ2anki
  2. Create the local package directory:

    mkdir -p ~/.local/share/typst/packages/local/typ2anki/0.1.0
  3. Copy the package files (note the -r flag for recursive copy):

    cp -r src/ typst.toml ~/.local/share/typst/packages/local/typ2anki/0.1.0
  4. Navigate to your flashcards directory:

    cd ~/Documents/Flashcards/  # or your preferred location
  5. Create your ankiconf.typ file with basic configurations:

    // 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):

    #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:

    typ2anki .

Usage

Basic Workflow

  1. Create a Typst file with flashcards:

    #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:

    // 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:

    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 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:

#let custom-card(
  id: "",
  q: "",
  a: "",
  ..args
) = {
  card(
    id: id,
    q: q,
    a: a,
    container: true,
    show-labels: true
  )
}

Example repositories:


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.


Developed with ❤️ by sgomezsal. Let’s make learning efficient and enjoyable!

About

Typ2Anki is a tool that converts Typst documents into Anki flashcards.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •