ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Richard Rascher-Friesenhausen <richard.rascher-friesenhausen@mevis.de>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: looking for equivalence to LaTeX algorithm package
Date: Mon, 01 Dec 2008 14:34:40 +0100	[thread overview]
Message-ID: <4933E7F0.70204@mevis.de> (raw)
In-Reply-To: <72c60e910811300809jab384aaw2bae79960b076d7f@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1754 bytes --]

Zhaopeng Xing schrieb:
> Hi,
>
> Does anyone know how to describe algorithm procedures in similar way 
> as LaTeX algorithmic and algorithm packages? I tried to search it on 
> wiki but found nothing. Thanks.
>
> -- 
> Zhaopeng XING
>
> Tinbergen Institute
> ------------------------------------------------------------------------
>
> ___________________________________________________________________________________
> If your question is of interest to others as well, please add an entry to the Wiki!
>
> maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
> webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
> archive  : https://foundry.supelec.fr/projects/contextrev/
> wiki     : http://contextgarden.net
> ___________________________________________________________________________________
>   
Hello,

I once tried to copy the LaTeX environment to ConTeXt. And this is, what 
came out of it: *t-algorithmic.tex* It works for me, but i'm open to new 
and better implementations...

richard rascher-friesenhausen

-- 

==============================================================================
Dr. Richard Rascher-Friesenhausen
Hochschule Bremerhaven, Studiengang Medizintechnik
An der Karlstadt 8
27568 Bremerhaven

und

MeVis Research GmbH
Universitaetsallee 29
D-28359 Bremen

Amtsgericht Bremen, HRB 16222
Geschäftsführer: Prof. Dr. Heinz-Otto Peitgen

email: richard@mevis.de, richard.rascher-friesenhausen@hs-bremerhaven.de
www  : http://www.mevis-research.de/, http://www.hs-bremerhaven.de/
fon  : +49 - 421 - 218 7707 (mevis)
fax  : +49 - 421 - 218 4236 (mevis)
==============================================================================


[-- Attachment #2: t-algorithmic.tex --]
[-- Type: text/plain, Size: 6707 bytes --]

% output=pdf
%=======================================================================
% begin of file *t-algorithmic.tex*
%=======================================================================
% richard@mevis.de (c) 2003, 2004, 2005

%D \module
%D   [       file=algorithmic.tex,
%D        version=2005.02.12,
%D          title=Environments for algorithms,
%D         author=richard rascher friesenhausen,
%D           date=\currentdate,
%D      copyright={richard@home}]

%D algorithmic defs
\definefloat[algorithm][algorithms]
\setupfloat[algorithm][location=middle]
\setuplabeltext[de][algorithm={Algorithmus\,}]

\define[1]\Algorithm{%
\startframedtext[frame=off,%leftframe=on,%bottomframe=on,
                 framecolor=darkyellow,
                 background=screen,offset=none]
%  \setuplinenumbering[location=intext]
%  \startlinenumbering 
    #1 
%  \stoplinenumbering
\stopframedtext
}

%D names
\def\algorithmicend{{\bf end}}
\def\algorithmicif{{\bf if}}
\def\algorithmicthen{{\bf then}}
\def\algorithmicelse{{\bf else}}
\def\algorithmicelseif{\algorithmicelse\algorithmicif}
\def\algorithmicendif{\algorithmicend{\bf.}\algorithmicif}

\def\algorithmicfor{{\bf for}}
\def\algorithmicendfor{\algorithmicend{\bf.}\algorithmicfor}
\def\algorithmicforall{{\bf for all}}
\def\algorithmicdo{{\bf do}}

\def\algorithmicwhile{{\bf while}}
\def\algorithmicendwhile{\algorithmicend{\bf.}\algorithmicwhile}

\def\algorithmicrepeat{{\bf repeat}}
\def\algorithmicuntil{{\bf until}}

%D macros
\newdimen\algorithmicindent \algorithmicindent=0cm
\newdimen\algorithmicskip   \algorithmicskip=.5cm
\newcount\algorithmicline   \algorithmicline=0
\def\startIF{\advance\algorithmicindent by  \algorithmicskip}
\def\stopIF {\advance\algorithmicindent by -\algorithmicskip}

\let\startFOR=\startIF
\let\stopFOR =\stopIF

\let\startWHILE=\startIF
\let\stopWHILE =\stopIF

\let\startREPEAT=\startIF
\let\stopREPEAT =\stopIF

\def\algorithmiclineintro{%
  \inframed[width=.5cm,frame=off,offset=none,
            background=color,backgroundcolor=darkyellow]
    {\strut\hfill\color[black]{\the\algorithmicline}\,}\quad
  \hskip\algorithmicindent%
}
%D if then elseif else endif
\def\IF#1{%
  \advance\algorithmicline by 1
  \hbox{%
    \algorithmiclineintro
    \algorithmicif\ #1\ \algorithmicthen
  }\par
  \startIF
}
\def\ENDIF{%
  \stopIF
  \advance\algorithmicline by 1
  \hbox{%
    \algorithmiclineintro
%  \the\algorithmicline\ \hskip\algorithmicindent%
    \algorithmicendif
  }\par
}
\def\ELSE{%
  \stopIF
  \advance\algorithmicline by 1
  \hbox{%
    \algorithmiclineintro
%  \the\algorithmicline\ \hskip\algorithmicindent%
    \algorithmicelse
  }\par
  \startIF
}

\def\ELSEIF#1{%
  \stopIF
  \advance\algorithmicline by 1
  \hbox{%
    \algorithmiclineintro  
    \algorithmicelseif\ #1\ \algorithmicthen
  }\par
  \startIF
}

%D for forall do endfor
\def\FOR#1{%
  \advance\algorithmicline by 1
  \hbox{%
    \algorithmiclineintro
    \algorithmicfor\ #1\ \algorithmicdo
  }\par
  \startFOR
}
\def\FORALL#1{%
  \advance\algorithmicline by 1
  \hbox{%
    \algorithmiclineintro
    \algorithmicforall\ #1\ \algorithmicdo
  }\par
  \startFOR
}
\def\ENDFOR{%
  \stopFOR
  \advance\algorithmicline by 1
  \hbox{%
    \algorithmiclineintro
    \algorithmicendfor
  }\par
}

%D while do endwhile
\def\WHILE#1{%
  \advance\algorithmicline by 1
  \the\algorithmicline\ \hskip\algorithmicindent%
  \algorithmicwhile\ #1\ \algorithmicdo\par
  \startWHILE
}
\def\ENDWHILE{%
  \stopWHILE
  \advance\algorithmicline by 1
  \the\algorithmicline\ \hskip\algorithmicindent%
  \algorithmicendwhile\par
}

%D repeat until
\def\REPEAT{%
  \advance\algorithmicline by 1
  \hskip\algorithmicindent%
  \algorithmicrepeat\par
  \startREPEAT
}
\def\UNTIL#1{%
  \stopREPEAT
  \advance\algorithmicline by 1
  \the\algorithmicline\ \hskip\algorithmicindent%
  \algorithmicuntil\ #1\par
}

%D loop endloop

%D others
\def\STATE#1{%
  \advance\algorithmicline by 1
  \hbox{%
    \algorithmiclineintro
    #1
  }\par
}
  

\def\INPUT#1{%
  \hskip\algorithmicindent%
  \inframed[frame=off,width=broad,offset=1pt, %bottomframe=on,
            background=color,backgroundcolor=darkyellow]%
    {{\bf Input:}\ #1\hfill}\par}
\def\OUTPUT#1{%
  \hskip\algorithmicindent%
  \inframed[frame=off,width=broad,offset=1pt,%topframe=on,
            background=color,backgroundcolor=darkyellow]%
    {{\bf Output:}\ #1\hfill}\par}

\def\REQUIRE#1{%
  \hskip\algorithmicindent%
  \inframed[frame=off,width=broad,strut=yes,offset=0pt,
            background=color,backgroundcolor=darkyellow]
    {{\bf Require:}\ #1\hfill}\par
}
\def\ENSURE#1{%
  \hskip\algorithmicindent%
  \inframed[frame=off,width=broad,offset=1pt,
            background=color,backgroundcolor=darkyellow]%
    {{\bf Ensure:}\ #1\hfill}\par
}
\def\INVARIANT#1{%
  \hskip\algorithmicindent%
  \inframed[frame=off,width=broad,offset=none,
            background=color,backgroundcolor=darkyellow]%
    {{\bf Invariant:}\ #1\hfill}\par
}

\doifnotmode{demo}{\endinput}
%C======================================================================
%D
%D Some tests.
%D
%=======================================================================
\setupcolors[state=start]
%=======================================================================
\starttext
%=======================================================================
\startbuffer
\IF{$x=0$}
  \STATE{do it}
\ELSE
  \STATE{don't do it}
\ENDIF
\stopbuffer
\placealgorithm{ein Algorithmus}\Algorithm{\getbuffer}

\startbuffer
\FORALL{$x\in R$}
  \STATE{do it}
\ENDFOR
\stopbuffer
\placealgorithm{ein Algorithmus}\Algorithm{\getbuffer}

\startbuffer
  \INPUT{$n$ ganze Zahlen}
  \REQUIRE{$n>0$}
  \STATE{Lese $n$ Zahlen in das Feld $a_0,\ldots,a_{n-1}$ ein.}
  \FORALL{$i=0,1,\ldots,n-1$}
    \STATE{Suche das kleinste Element aus $a_i, \ldots, a_{n-1}$.}
    \STATE{Nehme an, es steht in $a_{\min}$.}
    \STATE{Vertausche $a_i$ mit $a_{\min}$.}
  \ENDFOR 
  \ENSURE{$a_0\le a_1\le \ldots\le a_{n-1}$}
  \OUTPUT{Sortierte Liste $a$ von ganzen Zahlen}
\stopbuffer
\placealgorithm{ein Algorithmus}{\setupbodyfont[10pt]\Algorithm{\getbuffer}}

\startbuffer
\IF{$i>0$}
  \STATE{$i$ ist gr\"osser als $0$}
  \FOR{$j=0,1,2$}
    \STATE{z\"ahlen...}
  \ENDFOR
\ELSEIF{$i=0$}
  \STATE{$i$ ist gleich $0$}
\ELSE
  \STATE{mmmhhh...}
\ENDIF
\stopbuffer
\placealgorithm{ein Algorithmus}\Algorithm{\getbuffer}

%=======================================================================
\stoptext
%=======================================================================
%=======================================================================
% end of file *t-algorithmic.tex*
%=======================================================================

[-- Attachment #3: Type: text/plain, Size: 487 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : https://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

  parent reply	other threads:[~2008-12-01 13:34 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-30 16:09 Zhaopeng Xing
2008-11-30 17:26 ` Mohamed Bana
2008-11-30 19:43 ` Wolfgang Schuster
2008-12-01 11:09 ` Wolfgang Schuster
2008-12-01 12:09   ` Zhaopeng Xing
2008-12-01 13:34 ` Richard Rascher-Friesenhausen [this message]
2008-12-03 16:18   ` Wolfgang Schuster
2008-12-15 10:37 ` Wolfgang Schuster

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4933E7F0.70204@mevis.de \
    --to=richard.rascher-friesenhausen@mevis.de \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).