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...
Emacs Stack Exchange is a question and answer site for those using, extending or developing Emacs. It only takes a minute to sign up.
Sign up to join this communityI'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...
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
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
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.