Eagle4398 ec5caf32a8 feat(snip): expand into next line with correct indent (#13)
* New snippet type. Expand from nonempty line into next line.

* Fix trigger to ' dm' instead of 'dm'

* style: format code

* minor: improve regex

---------

Co-authored-by: arne314 <73391160+arne314@users.noreply.github.com>
2025-03-22 10:02:26 +01:00
2024-12-22 18:21:28 +01:00
2024-12-22 18:21:28 +01:00
2025-01-09 01:48:18 +01:00
2025-01-22 23:35:56 +00:00
2025-01-22 23:35:56 +00:00
2025-03-10 20:23:50 +01:00
2025-02-07 11:58:19 +01:00
2025-03-10 20:23:50 +01:00

Typstar

Neovim plugin for efficient note taking in Typst

Features

Usage

Snippets

Use :TypstarToggleSnippets to toggle all snippets at any time. Available snippets can mostly be intuitively derived from here, they include:

Markup snippets:

Math snippets:

  • Many shorthands for mathematical expressions
  • Alphanumeric characters: :<char>$<char>$ in markup (e.g. :X$X$ , :5$5$ )
  • Greek letters: ;<latin><greek> in math and $<greek>$ in markup (e.g. ;aalpha/$alpha$ )
  • Common indices (numbers and letters i-n): <letter><index> <letter>_<index> in math and $<letter>$<index> $<letter>_<index>$ in markup (e.g A314 A_314 , $alpha$n $alpha_n$ )
  • Series of numbered letters: <letter> ot<optional last index> <letter>_1, <letter>_2, ... (e.g. a ot a_1, a_2, ... , a ot4 a_1, a_2, a_3, a_4 , alpha otk alpha_1, alpha_2, ..., alpha_k )
  • Wrapping of any mathematical expression (see operations, works nested, multiline and in visual mode via the selection key): <expression><operation><operation>(<expression>) (e.g. (a^2+b^2)rtsqrt(a^2+b^2), lambdatdtilde(lambda), (1+1)sQ[1+1], (1+1)sq[(1+1)])
  • Matrices: <size>ma and <size>lma (e.g. 23ma → 2x3 matrix)

Note that you can customize (enable, disable and modify) every snippet.

Excalidraw

  • Use :TypstarInsertExcalidraw to create a new drawing using the configured template, insert a figure displaying it and open it in Obsidian.
  • To open an inserted drawing in Obsidian, simply run :TypstarOpenExcalidraw while your cursor is on a line referencing the drawing.

Anki

Use the flA snippet to create a new flashcard

#flashcard(0, "My first flashcard")[
  Typst is awesome $a^2+b^2=c^2$
]

or the fla snippet to add a more complex front

#flashcard(0)[I love Typst $pi$][
  This is the back of my second flashcard
]

To render the flashcard in your document as well add some code like this

#let flashcard(id, front, back) = {
  strong(front)
  [\ ]
  back
}
  • Add a comment like // ANKI: MY::DECK to your document to set a deck used for all flashcards after this comment (You can use multiple decks per file)
  • Add a file named .anki containing a deck name to define a default deck on a directory base
  • Add a file named .anki.typ to define a preamble on a directory base. You can find the default preamble here.
  • Tip: Despite the use of SVGs you can still search your flashcards in Anki as the typst source is added into an invisible html paragraph

Neovim

  • Use :TypstarAnkiScan to scan the current nvim working directory and compile all flashcards in its context, unchanged files will be ignored
  • Use :TypstarAnkiForce to force compilation of all flashcards in the current working directory even if the files haven't changed since the last scan (e.g. on preamble change)
  • Use :TypstarAnkiForceCurrent to force compilation of all flashcards in the file currently edited
  • Use :TypstarAnkiReimport to also add flashcards that have already been asigned an id but are not currently present in Anki
  • Use :TypstarAnkiForceReimport and :TypstarAnkiForceCurrentReimport to combine features accordingly

Standalone

  • Run typstar-anki --help to show the available options

Installation

Install the plugin in Neovim (see Nix instructions) and run the plugin setup.

require('typstar').setup({ -- depending on your neovim plugin system
   -- your typstar config goes here
})

Snippets

  1. Install LuaSnip, set enable_autosnippets = true and set a visual mode selection key (e.g. store_selection_keys = '<Tab>') in the configuration
  2. Install jsregexp as described here (You will see a warning on startup if jsregexp isn't installed properly)
  3. Install nvim-treesitter and run :TSInstall typst
  4. Optional: Setup ctheorems with names like here

Excalidraw

  1. Install Obsidian and create a vault in your typst note taking directory
  2. Install the obsidian-excalidraw-plugin and enable Auto-export SVG (in plugin settings at Embedding Excalidraw into your Notes and Exporting > Export Settings > Auto-export Settings)
  3. Have the xdg-open command working or set a different command at uriOpenCommand in the config
  4. If you encounter issues try cloning the repo into ~/typstar or setting the typstarRoot config accordingly, feel free to open an issue

Anki

  1. Typst version 0.12.0 or higher is required
  2. Install Anki
  3. Install Anki-Connect and make sure http://localhost is added to webCorsOriginList in the Add-on config (should be added by default)
  4. Install the typstar python package (I recommend using pipx via pipx install git+https://github.com/arne314/typstar, you will need to have python build tools and clang installed) [Note: this may take a while]
  5. Make sure the typstar-anki command is available in your PATH or modify the typstarAnkiCmd option in the config

In a Nix Flake (optional)

You can add typstar to your nix-flake like so

# `flake.nix`
inputs = {
  # ... other inputs
  typstar = {
    url = "github:arne314/typstar";
    flake = false;
  };
}

Now you can use typstar in any package-set

with pkgs; [
  # ... other packges
  (pkgs.vimUtils.buildVimPlugin {
     name = "typstar";
     src = inputs.typstar; 
     buildInputs = [
        vimPlugins.luasnip 
        vimPlugins.nvim-treesitter-parsers.typst
     ];
  })
]

Configuration

Configuration options can be intuitively derived from the table here.

Custom snippets

The config allows you to

  • disable all snippets via snippets.enable = false
  • only include specific modules from the snippets folder via e.g. snippets.modules = { 'letters' }
  • exclude specific triggers via e.g. snippets.exclude = { 'dx', 'ddx' }

For further customization you can make use of the provided wrappers from within your LuaSnip config. Let's say you prefer the short => arrow over the long ==> one and would like to change the ip trigger to imp. Your typstar config could look like

require('typstar').setup({
    snippets = {
        exclude = { 'ip' },
    },
})

while your LuaSnip typst.lua could look like this (< and > require escaping as <> introduces a new node)

local tp = require('typstar.autosnippets')
local snip = tp.snip
local math = tp.in_math
local markup = tp.in_markup

return {
    -- add a new snippet (the old one is excluded via the config)
    snip('imp', '=>> ', {}, math),

    -- override existing triggers by setting a high priority
    snip('ib', '<<= ', {}, math, 2000),
    snip('iff', '<<=>> ', {}, math, 2000),

    -- setup markup snippets accordingly
    snip('IMP', '$=>>$ ', {}, markup, 2000),
    snip('IFF', '$<<=>>$ ', {}, markup, 2000),
}
Description
No description provided
Readme 357 KiB
Languages
Lua 63.2%
Python 32.7%
Nix 4.1%