Obsidian Latex Suite

repository·main·Indexed 25 days ago

https://github.com/artisticat1/obsidian-latex-suite

A plugin for Obsidian designed to accelerate LaTeX typesetting through snippets, auto-expansions, and editor enhancements. Features include auto-fraction expansion, matrix shortcuts, a 'Conceal mode' for readable math display, and Tabout for equation navigation. Users can define custom snippets using triggers, replacements, and behavior flags (such as math mode or regex), as well as create visual snippets to wrap selections in LaTeX annotation commands.

Tokens
10.1K
Snippets
16
Records
54
Agent score
81%

What's inside obsidian-latex-suite

  1. Understand keymap execution order

    main

    When multiple keymaps are assigned to the same key, the plugin executes them in the following priority order:

    1. Auto delete $
    2. Expand snippets automatic snippets
    3. Expand manual snippets (using triggerKey or the default triggerKey)
    4. Select the next tabstop
    5. Select the previous tabstop
    6. Auto fraction
    7. Priority tabout (e.g., only tabout when the cursor is inside brackets)
    8. Add \ and a newline in a matrix
    9. Add a new cell/ & in a matrix
    10. Go to the next line in a matrix
    11. Tabout to the next closing bracket or exit the equation
    12. Tabout if you type a closing delimiter (e.g. },],))

    Note: If a feature is disabled in settings, it is skipped in this order.

  2. Quickstart with Obsidian Latex Suite

    main

    To begin typesetting LaTeX, type dm to enter display math mode. The plugin uses snippets to expand shorthand into full LaTeX commands.

    Common default examples:

    • xsrx^{2}
    • x/y + <kbd>Tab</kbd>\frac{x}{y}
    • sin @t\sin \theta (where @t is a tabstop)
    • par + <kbd>Tab</kbd> + f + <kbd>Tab</kbd> + x + <kbd>Tab</kbd>\frac{\partial f}{\partial x}
  3. Use Matrix shortcuts

    main

    When your cursor is inside a matrix, array, align, or cases environment, you can use these keyboard shortcuts to navigate and edit:

    • <kbd>Tab</kbd>: Insert the & symbol (column separator).
    • <kbd>Enter</kbd>: Insert \\ and move to a new line.
    • <kbd>Shift + Enter</kbd>: Move to the end of the next line (useful for exiting the matrix environment).
  4. Use Visual snippets for math annotation

    main

    Select a portion of math with your cursor and press a single character to wrap it in LaTeX annotation commands:

    • U: Surround with \underbrace
    • O: Surround with \overbrace
    • C: Surround with \cancel
    • K: Surround with \cancelto
    • B: Surround with \underset
  5. Load snippet variables from a file or folder

    main

    Snippet variables allow you to define reusable strings (like lists of Greek letters) that can be used within your snippets.

    Setup:

    1. Enable Advanced editor settings > Snippet variables > Load snippet variables from file or folder.
    2. Provide a path relative to your vault.

    File Format: A snippet variable file is a JavaScript object or a JavaScript module with a export default of an object.

    Key Syntax: Keys can be written with or without quotes. The ${} wrapper around a key is optional.

    Example formats for a key VARIABLE:

    • "${VARIABLE}": "value"
    • "VARIABLE": "value"
    • VARIABLE: "value"
    export default {
      "${GREEK}": "alpha|beta|gamma|Gamma|delta|Delta|epsilon|varepsilon|zeta|eta|theta|vartheta|Theta|iota|kappa|lambda|Lambda|mu|nu|xi|omicron|pi|rho|varrho|sigma|Sigma|tau|upsilon|Upsilon|phi|varphi|Phi|chi|psi|omega|Omega",
      "SYMBOL": "parallel|perp|partial|nabla|hbar|ell|infty|oplus|ominus|otimes|oslash|square|star|dagger|vee|wedge|subseteq|subset|supseteq|supset|emptyset|exists|nexists|forall|implies|impliedby|iff|setminus|neg|lor|land|bigcup|bigcap|cdot|times|simeq|approx",
      MORE_SYMBOLS: "leq|geq|neq|gg|ll|equiv|sim|propto|rightarrow|leftarrow|Rightarrow|Leftarrow|leftrightarrow|to|mapsto|cap|cup|in|sum|prod|exp|ln|log|det|dots|vdots|ddots|pm|mp|int|iint|iiint|oint"
    }
  6. Create Visual Snippets

    main

    Visual snippets allow you to wrap a current selection with specific text or transform it.

    String-based Visual Snippets

    Use the v option and include the special string ${VISUAL} in your replacement string. The ${VISUAL} placeholder is replaced by the current selection.

    {trigger: "U", replacement: "\\underbrace{ ${VISUAL} }_{ $0 }", options: "mA"}

    Function-based Visual Snippets

    Use the v option and provide a function that takes the selection (sel) as an argument. The function must return a string or false (to ignore the snippet).

    // Wraps selection in \cancelto{...}
    {trigger: "K", replacement: (sel) => ("\\cancelto{ $0 }{" + sel + "}"), options: "mv"}
    
    // Converts spaces in selection to hyphens
    {trigger: "-", replacement: sel => { if (!sel.includes(" ")) { return false } return sel.replaceAll(/\s+/g, "-")}, options: "vA"}
    {
      trigger: "U", 
      replacement: "\\underbrace{ ${VISUAL} }_{ $0 }", 
      options: "mA"
    }
    
    {
      trigger: "K", 
      replacement: (sel) => ("\\cancelto{ $0 }{" + sel + "}"), 
      options: "mv"
    }
    
    {
      trigger: "-", 
      replacement: sel => { if (!sel.includes(" ")) { return false } return sel.replaceAll(/\s+/g, "-")},
      options: "vA"
    }
  7. Load snippets from a file or folder

    main

    You can externalize your snippets by loading them from a specific file or an entire folder within your vault.

    Setup:

    1. Enable the setting Snippets > Load snippets from file or folder.
    2. Provide a path relative to your vault root.
    3. Ensure the file/folder is not in a hidden directory (like .obsidian/).

    File Format: A snippet file must be a JavaScript module with a export default of an array of snippet objects. For best syntax highlighting in external editors, use the .js extension. To edit snippets directly inside Obsidian with syntax highlighting, you can use a .md file with a specific comment-wrapping pattern.

    Note: A JavaScript module can only have one export default.

    export default [
    	{trigger: "mk", replacement: "$$0$", options: "tA"},
    	{trigger: "dm", replacement: "$$\n$0\n$$", options: "tAw"},
    	{trigger: /([A-Za-z])(\d)/, replacement: "[[0]]_{[[1]]}", options: "mA"}
    ]
  8. Use Tabout for equation navigation

    main

    Tabout improves navigation when working with equations:

    • Exit Equation: If the cursor is at the end of an equation, pressing <kbd>Tab</kbd> moves the cursor outside the $ symbols.
    • Jump Delimiters: If inside a \left ... \right pair, <kbd>Tab</kbd> jumps to the position after the \right command.
    • Jump Brackets: Otherwise, <kbd>Tab</kbd> advances the cursor to the next closing bracket: ), ], }, \rangle, or \rvert.
  9. Use Auto-fraction expansion

    main

    The Auto-fraction feature allows you to type a fraction using the / symbol. Typing numerator/ will expand to \frac{numerator}{} and place your cursor inside the denominator brackets. Press <kbd>Tab</kbd> to exit the fraction once finished.

    Examples:

    • x/\frac{x}{}
    • (a + b(c + d))/\frac{a + b(c + d)}{}
  10. Configure Vim mode and Select mode shortcuts

    main

    The plugin supports a subset of Vim keybindings via codemirror-vim.

    Visual Snippets in Vim: Visual snippets can be triggered in Insert mode, but not in Visual mode. To bridge this, you can define a custom Vim shortcut in settings that switches from Visual mode to Insert mode while maintaining the selection.

    Setup:

    1. Enable Vim mode in both Obsidian and the plugin settings.
    2. Define a shortcut in settings using a Vim keybinding with no spaces (e.g., :imap <C-a> <Esc>).

    Limitations:

    • The shift key (<S-a>) is known not to work for these mappings.
    • Macros are not currently supported for visual snippets.
  11. Create Regex Snippets

    main

    Regex snippets allow for dynamic expansion based on match patterns. To use them, either use the r option or provide a RegExp literal as the trigger.

    Capturing Groups

    • In the trigger, use () to create capturing groups.
    • In the replacement string, use [[X]] to insert the match from capturing group X (starting from 0).

    Example

    Expanding x2 to x_{2}:

    {trigger: "([A-Za-z])(\\d)", replacement: "[[0]]_{[[1]]}", options: "rA"}

    Or using a RegExp literal:

    {trigger: /([A-Za-z])(\d)/, replacement: "[[0]]_{[[1]]}", options: "A"}

    Warning: Special characters like \, +, and . must be escaped with double backslashes (\\) in string-based triggers.

    {
      trigger: "([A-Za-z])(\\d)", 
      replacement: "[[0]]_{[[1]]}", 
      options: "rA"
    }
    
    {
      trigger: /([A-Za-z])(\d)/, 
      replacement: "[[0]]_{[[1]]}", 
      options: "A"
    }
  12. Enable and configure Conceal mode

    main

    Conceal mode hides LaTeX markup and displays math in a pretty, readable format (e.g., \dot{x}^{2} becomes ẋ²).

    Setup Requirements:

    1. Enable the feature in the plugin settings.
    2. Font Support: Your Obsidian monospace font must support these symbols. It is recommended to use JuliaMono.

    If you don't want to install the font system-wide, add this to your Obsidian CSS file:

    @font-face {
        font-family: JuliaMono;
        src: url(https://github.com/cormullion/juliamono/raw/refs/heads/master/webfonts/JuliaMono-Regular.woff2) format("woff2");
        text-rendering: optimizeLegibility;
    }
    
    body {
      --font-monospace-override: JuliaMono;
    }

    Usage:

    • Move your cursor over a concealed equation to reveal the LaTeX syntax.
    • You can configure a delay for the reveal in settings to make arrow-key navigation more intuitive.