7
$\begingroup$

Do we have something for more convenient pseudocode typing? The current setup is not very user-friendly:

  • Manual indentation (with \quad's or whatever)
  • No standard constructs like "for", "if", "while", etc.
  • No visual help, like line numbering and vertical lines for scope (like vlined option from algorithm2e)

Even typing a small piece of code is pretty annoying, and I would need to brace myself for a large piece of code. Do we have a better alternative? I want to be able to do something like

\begin{algorithm}[<options>]
    $s \gets 0$
    \For{$i = 1..n$} {
        $a_i \gets i^2$ \\
        $s \gets s + a_i$
    }
\end{algorithm}

At the very least, do we have some pseudo-code tutorial? If we do, it should be easy to find for an asker (since I don't know one and even searching in the help center doesn't work, it's not easy to find). When someone uses a code block, we should also show a message like "consider using a pseudocode [link]".

$\endgroup$
1
  • $\begingroup$ I support adding such a mechanism. Current code environments cannot handle MathJax. $\endgroup$ – Yuval Filmus Apr 10 at 21:55
3
$\begingroup$

You can use fenced code blocks with syntax highlighting; just pick a language that roughly maches your favorite style of pseudo code, or maybe adopt a style that emulates a real programming language close enough.

You can get information using the editor help that's right there: enter image description here

That form of math-y LaTeX-y pseudo code, well ... I know it's popular in textbooks, but I think its usefulness is overrated. Maybe try something close to a programming language and see where you land.

$\endgroup$
2
  • 3
    $\begingroup$ It's also popular in papers. Code is designed for computers. Pseudocode is aimed at humans. $\endgroup$ – Yuval Filmus Apr 13 at 8:30
  • 2
    $\begingroup$ @YuvalFilmus That's a very narrow view on programming code that probably hails from the 1970s. Nowadays, the industry is very aware that code is read by humans more often than written, and modern languages tend to make this a priority (and let the compilers do more work). As such, the endeavouring CS content creator should have little trouble finding real languages that provide a level of abstraction that's close enough to their comfort zone so as to be useful when writing answers on this page (which are not publication-quality articles, after all). $\endgroup$ – Raphael Apr 19 at 9:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .