zhaoshenzhai / obsidian-mathlinks

An Obsidian.md plugin to render MathJax in your links.
MIT License
61 stars 4 forks source link
mathjax obsidian-plugins typescript

Obsidian MathLinks

An Obsidian.md plugin to render and manage MathJax in your links.

Associate a mathLink to your note, containing arbitrary MathJax, and have it displayed in all links to the note.

Description and Usage

Assigning a mathLink in the YAML frontmatter of note.md as shown below will make all links of the form [[note]] and [note](note.md) display as the rendered MathJax of yourMathLink. No changes are made to your notes, and updates to yourMathLink will be reflected (almost) instantaneously.

---
mathLink: yourMathLink
---

Content starts here.

This plugin also makes Wikilinks and Markdown Links compatible with MathJax, so links like [[note|yourAlias]] and [yourAlias](note.md) will be displayed as the rendered MathJax of yourAlias. A mathLink in note, if present, will be overridden by yourAlias.

Links to Blocks/Headings

Additionally, Obsidian also supports links to blocks [[note#^block-id]] and headings like [[note#section]]. Any MathJax in #section will be rendered (both in the note and in the Outline view), and you can associate a mathLink to ^block-id as well by adding a YAML frontmatter like so:

---
mathLink-blocks:
    block-id: yourMathLink
---

Templates

Oftentimes, mathLinks of notes involve replacing some text with its math counterpart. For instance, you might have many notes whose title is of the form ... iff ....

Instead of setting the mathLinks of each note manually as ... $\Leftrightarrow$ ..., simply use mathLink: auto. This will generate its mathLink via a template that replaces iff with $\Leftrightarrow$. A template consists of a string to be matched (iff), its replacement ($\Leftrightarrow$), and some options (global match, case sensitive, and match whole words). They are created and maintained in the MathLinks settings window.

Settings

Templates

Each template has the following options, which can be configured when the template is created/edited.

Field Description Default
Match for String to be matched and replaced. Do not include regex.
Replace with String to replace matches. Do not escape backslashes.
Global match Match all instances (instead of just the first). true
Case sensitive Matches will be case sensitive. true
Match whole words Only match whole words. true

Excluded Files

MathLinks will ignore those files. If a directory is selected, all files under that directory will be ignored.

Links to Blocks/Headings

MathLinks supports links to blocks and headings like [[note#^block-id]] and [[note#section]]. You can modify how they are rendered by:

Source Mode

Enable MathLinks in Source Mode (Default: false). Currently, only Wikilinks are supported.

MathLinks API

MathLinks exposes an API, allowing other community plugins to utilize its powerful "dynamic aliases" feature. You can find more information and a simple sample plugin at this repo: https://github.com/RyotaUshio/obsidian-mathlinks-api-sample-plugin.

Contributing

If you would like to point out a bug, add support, or have a feature request, don't hesitate to open an issue/pull request! Thank you to all who have contributed.

Changelog

0.5.x: Source Mode and Outline support.