5

I need to write pseudocode in ConTeXt. Since there is no documentation of the t-algorithmic module, and because I don't have so much to write, I decided to format the code myself.

Here is what I tried:

\def\>{\space\space\space\space}

{\bf for all} $i \in [0, 43[$\\
\>  blah blah

Sadly, this doesn't work. How can I indent a specific line ? Or an entire paragraph.

Thanks !

  • 4
    The documentation for the algorithmic module can be found on BitBucket. Consider using it. To your problem: You can use \setupindenting[yes,big] \let\>\indent. And watch out, TeX does not eat the space after the >. – Marco Jul 24 '13 at 9:41
  • \setupindenting adds indentation for all the paragraphs of the document, how can I avoid this ? Thanks for the documentation ! :) – Simon Jul 24 '13 at 9:48
  • 1
    Switch the indentation off after you're done with your algorithm: \setupindenting[no] – Marco Jul 24 '13 at 9:52
  • 1
    Also, for indenting multiple lines you can use the \{start,stop}narrower environment. – Philipp Gesang Jul 24 '13 at 10:25
  • 1
    If you really want to use the minimal markup that use have, use \def\>{\null\qquad}. Adding the \null ensures that the space at the beinining of the line is not eaten. Another option is to use the lines environment with space=yes – Aditya Jul 24 '13 at 14:44
8

The documentation for the algorithmic module can be found on BitBucket.. Here I present three solutions, one using the algorithmic module, one which uses the lines environment and your custom \> macro and one which uses the lines environment combined with the narrower environment, which is rather verbose.

\usemodule[algorithmic]
\starttext

  \subject{\mono{algorithmic:}}

  \startalgorithmic
    \FORALL {\math{i \in [0, 43[}}
      \STATE blah blah
      \STATE more lines
    \ENDFOR
  \stopalgorithmic

  \subject{\mono{lines} and custom macro:}

  \def\>{\quad}
  \startlines
    {\bf for all} \math{i \in [0, 43[}
    \>blah blah
    \>more lines
  \stoplines

  \subject{\mono{lines} and \mono{narrower}:}

  \startlines
    {\bf for all} \math{i \in [0, 43[}
    \startnarrower
      blah blah
      more lines
    \stopnarrower
  \stoplines

\stoptext

result

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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