ytliu74_obsidian-pseudocode/README.md

128 lines
5.5 KiB
Markdown
Raw Permalink Normal View History

2023-03-13 11:40:56 +00:00
# Obsidian-Pseudocode
2023-04-24 07:32:30 +00:00
- [Obsidian-Pseudocode](#obsidian-pseudocode)
- [Features](#features)
- [Future Features](#future-features)
- [Usage](#usage)
2023-05-22 08:21:22 +00:00
- [Basic](#basic)
2023-05-19 13:31:46 +00:00
- [Preamble style customization](#preamble-style-customization)
2023-06-07 16:24:43 +00:00
- [Use a `.sty` file](#use-a-sty-file)
- [Use in-block preamble](#use-in-block-preamble)
- [Supported macros](#supported-macros)
2023-05-22 08:21:22 +00:00
- [Export to a compilable LaTeX file](#export-to-a-compilable-latex-file)
2023-04-24 07:32:30 +00:00
- [Installation](#installation)
- [Credits](#credits)
2023-03-13 07:05:19 +00:00
2023-03-13 11:40:56 +00:00
This is a plugin for [Obsidian](https://obsidian.md/) that allows you to render LaTeX-style pseudocode inside a code block. The plugin is based on [pseudocode.js](https://github.com/SaswatPadhi/pseudocode.js), a JavaScript library that typesets pseudocode beautifully to HTML.
2023-03-13 07:05:19 +00:00
2023-03-13 11:40:56 +00:00
## Features
2023-03-13 07:05:19 +00:00
2023-03-13 11:40:56 +00:00
- Intuitive grammar: The plugin takes a LaTeX-style input that supports the algorithmic constructs from LaTeX's algorithm packages. With or without LaTeX experience, a user should find the grammar fairly intuitive.
- Print quality: The HTML output produced by the plugin is (almost) identical with the pretty algorithms printed on publications that are typeset by LaTeX.
- Math formula support: Inserting math formulas in the pseudocode is as easy as LaTeX. Just enclose math expression in `$...$` or `\(...\)`.
2023-05-19 13:31:46 +00:00
- Auto-completion inside `pseudo` code block. (Release 1.1.0)
2023-06-07 16:24:43 +00:00
- [Preamble style (macros) customization.](#preamble-style-customization) (Release 1.2.0 & 1.5.0)
2023-05-22 08:21:22 +00:00
- [Export a LaTeX file that can be compiled, including any required additional macros.](#export-to-a-compilable-latex-file) (Release 1.3.0)
2025-02-04 01:08:36 +00:00
- Pseudocode block follows Obsidian theme and supports both light and dark ones. (Release 1.6.0)
2023-03-13 07:05:19 +00:00
2023-03-13 11:40:56 +00:00
### Future Features
2023-03-13 07:05:19 +00:00
2023-03-13 11:40:56 +00:00
- [ ] Syntax highlighting.
2023-03-13 07:05:19 +00:00
2023-03-13 11:40:56 +00:00
## Usage
2023-03-13 07:05:19 +00:00
2023-05-22 08:21:22 +00:00
### Basic
2023-03-19 03:53:35 +00:00
To use the plugin, simply create a code block in your Obsidian note and add your pseudocode inside it. Then, add the language specifier `pseudo` (short for "pseudocode") to the code block. The plugin will automatically render the pseudocode as LaTeX.
2023-03-13 07:05:19 +00:00
2023-03-24 12:05:41 +00:00
**Rocommend: use the command `Pseudocode: Insert a new pseudocode block` to start.**
2023-03-23 08:53:48 +00:00
2023-03-13 11:40:56 +00:00
Here is an example:
2023-03-13 07:05:19 +00:00
2023-03-13 11:40:56 +00:00
```
2023-03-19 03:53:35 +00:00
```pseudo
2023-03-13 11:40:56 +00:00
\begin{algorithm}
\caption{Quicksort}
\begin{algorithmic}
2023-04-24 07:32:30 +00:00
\Procedure{Quicksort}{$A, p, r$}
\If{$p < r$}
\State $q \gets $ \Call{Partition}{$A, p, r$}
\State \Call{Quicksort}{$A, p, q - 1$}
\State \Call{Quicksort}{$A, q + 1, r$}
\EndIf
\EndProcedure
\Procedure{Partition}{$A, p, r$}
\State $x \gets A[r]$
\State $i \gets p - 1$
\For{$j \gets p$ \To $r - 1$}
\If{$A[j] < x$}
\State $i \gets i + 1$
\State exchange
2023-03-13 11:40:56 +00:00
$A[i]$ with $A[j]$
2023-04-24 07:32:30 +00:00
\EndIf
\State exchange $A[i]$ with $A[r]$
\EndFor
\EndProcedure
2023-03-13 11:40:56 +00:00
\end{algorithmic}
\end{algorithm}
```
```
2023-03-13 07:05:19 +00:00
2023-06-05 11:49:50 +00:00
This will be rendered as (to render line number, you need to toggle it in setting tab):
2023-03-13 11:45:07 +00:00
2023-04-24 07:32:30 +00:00
<div align="center">
2023-03-13 11:45:07 +00:00
<img src="assets/example.png" alt="example" width="70%">
2023-04-24 07:32:30 +00:00
</div>
2023-03-13 07:05:19 +00:00
2023-05-19 13:31:46 +00:00
### Preamble style customization
2023-06-07 16:24:43 +00:00
#### Use a `.sty` file
You can use a `.sty` file (actually the suffix does not matter) to customize with some macros. The plugin will locate the file according to the setting. The default path is `preamble.sty`.
Please reload the plugin after you change the preamble file.
#### Use in-block preamble
You can simply write your own macros in the pseudocode block before `\begin{algorithm}`. These macros will only be applicable within this specific block.
#### Supported macros
Currently supported macros can be found at [this link](https://katex.org/docs/supported.html#macros) and below(might not be fully supported):
2023-05-21 11:36:01 +00:00
1. `\DeclarePairedDelimiter`
2. `\DeclareMathOperator*`
3. `\DeclareMathOperator`
2023-05-19 13:31:46 +00:00
2023-05-19 13:39:53 +00:00
2023-05-22 08:21:22 +00:00
### Export to a compilable LaTeX file
You can easily export a compilable LaTeX file by clicking the `Export to clipboard` button at the bottom right corner for each pseudocode block. The plugin will automatically generate a compilable LaTeX file, including any required additional macros, to your clipboard.
2023-03-13 11:40:56 +00:00
## Installation
2023-03-13 07:05:19 +00:00
<!-- ### Install from the Community Plugins in Obsidian. -->
2023-04-16 03:39:55 +00:00
:tada: The Pseudocode plugin is now available in the Community Plugins section of Obsidian. To install it, simply search for **Pseudocode** and click on the installation button.
<!-- ### Use [BRAT](https://github.com/TfTHacker/obsidian42-brat#Quick-Guide-for-using-BRAT)
2023-03-30 14:56:45 +00:00
1. Install **Obsidian-42 BRAT** from the Community Plugins in Obsidian.
2. Open the command palette and run the command `BRAT: Add a beta plugin for testing`. Input this repo's URL `https://github.com/Yaotian-Liu/obsidian-pseudocode`.
3. Click on **Add Plugin** -- wait a few seconds and BRAT will tell you what is going on.
4. After BRAT confirms the installation, in Settings go to the **Community plugins** tab.
5. Refresh the list, find `Pseudocode` and enable it.
### Manual install
2023-03-30 05:54:18 +00:00
1. Create a folder named `pseudocode-in-obs` in your Obsidian vault plugin folder (which is {Your Vault}/.obsidian/plugins).
2. Download `main.js`, `manifest.json` and `styles.css` from the [releases page](https://github.com/yaotian-liu/obsidian-pseudocode/releases/latest), to the folder you just created in step 1.
3. Open your Obsidian, and enable the plugin in "Community Plugins" setting page.
4. Enjoy. -->
2023-03-13 07:05:19 +00:00
2023-03-30 14:56:45 +00:00
<!-- ## Known Issues -->
2023-03-13 07:05:19 +00:00
2023-03-13 11:40:56 +00:00
## Credits
2023-03-13 07:05:19 +00:00
2023-03-13 11:40:56 +00:00
This plugin is based on [pseudocode.js](https://github.com/SaswatPadhi/pseudocode.js), a JavaScript library that typesets pseudocode beautifully to HTML. Many thanks to the pseudocode.js team for their great work!