Plugin: use LaTeX style pseudocode right in your Obsidian note!

Hey everyone, I’m excited to announce the release of my new Obsidian plugin! You can check it out here.

It allows you to render LaTeX-style pseudocode inside a code block. The plugin is based on the pseudocode.js library and supports intuitive grammar and print quality. You can even insert math formulas in the pseudocode with ease. Plus, it comes with syntax highlighting (under construction) and auto-completion inside the code blocks. You can download the latest release from the releases page.

I am still waiting for my request to add this plugin to the official community plugins. I hope you can try it out, and if there are any issues, I will do my best to assist you.

Hope you like it! :smiley:

1 Like

Here is an example:

    ```pcode
    \begin{algorithm}
    \caption{Quicksort}
    \begin{algorithmic}
      \PROCEDURE{Quicksort}{$A, p, r$}
        \IF{$p < r$}
          \STATE $q = $ \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 = A[r]$
        \STATE $i = p - 1$
        \FOR{$j = p$ \TO $r - 1$}
          \IF{$A[j] < x$}
            \STATE $i = i + 1$
            \STATE exchange
            $A[i]$ with $A[j]$
          \ENDIF
        \STATE exchange $A[i]$ with $A[r]$
        \ENDFOR
      \ENDPROCEDURE
      \end{algorithmic}
    \end{algorithm}
    ```

This will be rendered as:

3 Likes

The plugin now supports auto-completion. Please try it out.

Thank you @YT-Liu for the plugin! Great to log down some thoughts inside Obsidian.
It does not support “tap in” with the auto-completion though (have to use “enter” which is not so intuitive).

Hi @YT-Liu, this looks nice. Just to be sure - if I copy & paste the pseudocode over to LaTeX, that should just work, correct?

The project is based on a library SaswatPadhi/pseudocode.js: Beautiful pseudocode for the Web (github.com). You can just use below packages in your LaTeX project and it will work:

\usepackage{algorithm,algpseudocode}

Be aware that all commands should look like \State instead of \STATE. But I just use all-capital in the demo, which would make the code not work in LaTeX. Good news is that the library is case-insensitive.
I will modified my demo and auto-completion within this week.

Yes, this could be annoying. I’ll investigate the official API and attempt to add support for this.

I have add a new feature in Release 1.3.0, which helps to export a compilable LaTeX file with needed macros.

Hey this plugin is exactly what I was looking for!
i use a black theme, then the pseudocode is not so nice.
To solve this issue, i wrote a css as follows to make the background white.
Here’s the code in case others need it:

div.ps-root {
  background-color: white;
  opacity: 1;
  color: black
}

It would be great if you allow the plugin to change the bg color.

Apologies for the delayed response; I haven’t visited this forum in a while.

Your proposal is appreciated and I’ll incorporate this feature soon. For any further issues, please reach out to me on GitHub.