13

I'd like to sketch out some pseudocode and then share it with other people that won't be using emacs.

Is there a nice way to do this? I'm trying to do it in org-mode, but it's not indenting properly, etc...

1
  • Someone has written a pseudocode-mode, but as of this writing it only offers syntax highlighting, no indentation.
    – Dale
    Sep 22, 2019 at 20:22

2 Answers 2

4

I don't know of a pseudo-code mode, less so support for that in org-mode.

You can, however, write pseudo-code in #+BEGIN_EXAMPLE blocks, surely without indentation, or you decide for a true language as base syntax and pseudo-code in that and get indentation and pretty syntax highlighting. Ruby might be a good candidate, or good old C/C++, maybe Java...

This is how it could look like:

#+HEADER: :exports both :results output
#+BEGIN_SRC ruby
class Pseudoclass
  def pseudofunction(items)
    add five to each item
  end
end

pseudoinstance = new Pseudoclass instance
call pseudofunction of pseudoinstance with list 2, 3, 4
#+END_SRC
0

In case you accept to share your pseudocode in LaTeX or PDF format, you could use the package minted to mix teletype & well-indented expression with LaTeX math expression. Here is an example of the well-known Prim's algorithm:

#+begin_export latex
\begin{minted}[escapeinside=||,mathescape=true]{text}
Prim's Algorithm(|$V, s$|)
|$T = \varnothing$|
|$U = \{ s \}$|
while (|$U \neq V$|)
    let |$(u, v)$| be the lowest cost edge in the cut |$(U, V-U)$|
    |$T = T \cup \{(u, v)\}$|
    |$U = U \cup \{v\}$|
\end{minted}
#+end_export

which it's rendered as enter image description here

If you want only share this pseudocode snippet, you just have to select this block and call org-latex-export-as-latex or org-latex-export-to-pdf depending on what format you want to export (you might want to slightly modify the org-mode options to have a satisfying layout). To write easily pseudocode, you can, of course, change the minted math expression separator, and use yasnippet or latex custom block to get rid of those bunch of options.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.