# LaTeX Inline Block Toggle [Repository](https://github.com/JM-FRANK/Obisian-Latex-inline-block-toggle) · [Releases](https://github.com/JM-FRANK/Obisian-Latex-inline-block-toggle/releases) · [Changelog](CHANGELOG.md) Convert LaTeX math between inline (`$...$`) and display block (`$$...$$`) styles directly in the Obsidian editor. ## Features - Two editor commands: - `Toggle math inline/block` - `Merge consecutive block formulas` - Commands are registered through Obsidian's official command system so users can set their own hotkeys. - Both actions are available in the editor right-click context menu (configurable). - Selection-aware behavior: - If text is selected, conversion runs on the selection. - Without a selection, toggle converts the block at the cursor to inline math, or all inline formulas on the current line to blocks. - Merge combines adjacent blocks into an `aligned` environment. - Friendly `Notice` messages when conversion cannot be safely performed. - Settings for context menu visibility and whitespace trimming. Block output is multiline. ## Demo (Text) ### Block to inline Input: ```latex $$ \lim_{n \to \infty} a_n = L. $$ ``` Output: ```latex $\lim_{n \to \infty} a_n = L.$ ``` ### Inline to block Input: ```latex $\lim_{n \to \infty} a_n = L.$ ``` Output (multiline block): ```latex $$ \lim_{n \to \infty} a_n = L. $$ ``` ## Installation (Manual Sideload) 1. Download `main.js`, `manifest.json`, and `styles.css` from the [latest release](https://github.com/JM-FRANK/Obisian-Latex-inline-block-toggle/releases/latest), or build the plugin (see below). 2. Create a folder in your vault: - `.obsidian/plugins/latex-inline-block-toggle/` 3. Copy these files into that folder: - `main.js` - `manifest.json` - `styles.css` 4. In Obsidian: - Open `Settings -> Community plugins` - Disable Safe mode (if needed) - Enable `LaTeX Inline Block Toggle` ## Compatibility The minimum app version remains **1.5.0**, on desktop and mobile. On 1.13+, the two settings use Obsidian's declarative API for settings search; older versions use the existing settings UI. Command IDs and setting keys are unchanged by the API update. External settings reload is available on 1.5.7+. If upgrading from the old `obisian-latex-inline-block-toggle` ID, disable the old plugin first. Keep a copy of its `data.json`, install into the new folder above, and copy that file into it before enabling. The earlier ID rename changes Obsidian's command namespace, so reassign custom hotkeys to the new plugin. Do not enable both copies. See [official API references and validation notes](docs/obsidian-1.13-compatibility.md). ## Development Setup 1. Clone this repository. 2. Install dependencies: ```bash npm ci ``` 3. For development watch mode: ```bash npm run dev ``` 4. For a production build: ```bash npm run build ``` Run `npm run typecheck` and `npm test` to check types and run the lightweight regression suite (no extra test dependencies). ## Build Instructions - `npm run dev`: - Watches `main.ts` and rebuilds `main.js` on changes. - `npm run build`: - Creates a production bundle (`main.js`). - `npm run version`: - Updates `versions.json` using `manifest.json` values. ## How Commands Work ### Toggle math inline/block Select an inline expression or a block to convert it. Without a selection, the command converts the block at the cursor to inline math; otherwise it converts inline expressions on the current line into separate multiline blocks. Block-to-inline conversion can join neighboring text lines with matching quote prefixes. ### Output format Inline-to-block conversion always places the opening and closing `$$` delimiters on separate lines. For example, `$formula$` becomes: ```latex $$ formula $$ ``` Block-to-inline conversion flattens line breaks and produces `$formula$`. Existing single-line display blocks are also accepted as input: ```latex $$ formula $$ ``` Toggling this block produces `$formula$` with the default whitespace trimming setting. Toggling it again produces the multiline block shown above. There is no setting to generate single-line display blocks. ### Merge consecutive block formulas Select consecutive blocks, or place the cursor in one of them, to merge the group into a single `aligned` block. Intervening text prevents merging. ## Settings Open `Settings -> Community plugins -> LaTeX Inline Block Toggle`: - `Show commands in editor context menu` (default: `true`) - Show/hide the conversion actions in the editor right-click menu. - `Trim surrounding whitespace when converting` (default: `true`) - Trims extracted math content during conversion. ## Edge Cases and Limitations - Inline detection is intentionally restricted to the current line. - Escaped dollar signs (`\$`) are not treated as delimiters. - The plugin distinguishes single-dollar and double-dollar delimiters. - Heuristics are used to avoid obvious currency false positives, but not every ambiguous case can be perfectly inferred. - Malformed or deeply ambiguous delimiter patterns are safely rejected with a notice. - Fenced math blocks like ```` ```math ```` are not supported (by design). - This plugin does not implement a full LaTeX parser. ## License MIT. See [LICENSE](LICENSE).