Permalink
Cannot retrieve contributors at this time
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
39 lines (31 sloc)
1013 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { loadMathJax, Plugin } from 'obsidian'; | |
| const DEFAULT_PREAMBLE_PATH = "preamble.sty"; | |
| export default class JaxPlugin extends Plugin { | |
| async read_preamble () { | |
| return await this.app.vault.adapter.read(DEFAULT_PREAMBLE_PATH); | |
| } | |
| async onload() { | |
| // Load MathJax so that we can modify it | |
| // Otherwise, it would not be loaded when this plugin is loaded | |
| await loadMathJax(); | |
| if (!MathJax) { | |
| console.warn("MathJax was not defined despite loading it."); | |
| return; | |
| } | |
| // Read the preamble out from the file | |
| let preamble = await this.read_preamble(); | |
| if (MathJax.tex2chtml == undefined) { | |
| MathJax.startup.ready = () => { | |
| MathJax.startup.defaultReady(); | |
| MathJax.tex2chtml(preamble); | |
| }; | |
| } else { | |
| MathJax.tex2chtml(preamble); | |
| } | |
| // TODO: Refresh view? | |
| } | |
| onunload() { | |
| // TODO: Is it possible to remove our definitions? | |
| console.log('Unloading Extended MathJax'); | |
| } | |
| } |