Carpe diem (Felix's blog)

I am a happy developer

Handcraft Algorithm Environment in Kramdown

I love $\LaTeX$. The typesetting in $\LaTeX$ is so beautiful that that no other typesetting system can compete with. Unfortunately, I cannot write $\LaTeX$ for blog post. I have to use kramdown or other wiki/markup languages, because $\LaTeX$ doesn’t perform well in HTML output. However, I missed some features in $\LaTeX$. One of those is Algorithm and Pseudocode packages. So, I discovered some tricks to form algorithm-like typesettings.

  1. Use \begin{align} to align the lines.
  2. Use \mbox{text...} to put descriptions in.
  3. Use \quad and \qquad to make indentions.

Here is the example input:

1
2
3
4
5
6
7
8
9
10
11
$$
\begin{align}
   Q=& \mbox{On input string $w$:} \\
     & 1.\; \mbox{Construct the following Turing machine $P_w$} \\
     & \quad    P_w = \mbox{On any input:} \\
     & \qquad   1.\; \mbox{Erase input.} \\
     & \qquad   2.\; \mbox{Write w on the tape.} \\
     & \qquad   3.\; \mbox{Halt.}  \\
     & 2.\; \mbox{Output }\langle P_w\rangle  \\
\end{align}
$$

and Voilà!

Comments