looking for equivalence to LaTeX algorithm package
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
Maybe you could typeset the page with (Xe)LaTeX and include the pdf as page in your ConTeXt doc. Zhaopeng Xing wrote:
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 ___________________________________________________________________________________
Am 30.11.2008 um 17:09 schrieb Zhaopeng Xing:
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.
Feel free to write your own module. \definefloat[algorithm][algorithms] \definestartstop [algorithm] [before=\startlines, after=\stoplines, commands=\directsetup{algorithm}] \startsetups algorithm \def\STATE {\hskip1em} \def\REQUIRE {{\bf Require: }} \def\ENSURE {{\bf Ensure: }} \def\IF ##1{\bgroup\doadaptleftskip{1em}{\bf if} ##1 {\bf then}} \def\ENDIF {{\bf end if}\par\egroup} \def\WHILE ##1{\bgroup\doadaptleftskip{1em}{\bf while} ##1 {\bf do}} \def\ENDWHILE {{\bf end while}\par\egroup} \definecomplexorsimple\ELSE \def\simpleELSE {{\bf else}} \def\complexELSE[##1]{{\bf else} $//$ ##1} \stopsetups %\setuplines[before=,after=] \starttext \startbuffer[algorithm] \startalgorithm \REQUIRE $n \geq 0 \vee x \neq 0$ \ENSURE $y = x^n$ \STATE $y \Leftarrow 1$ \IF{$n < 0$} \STATE $X \Leftarrow 1 / x$ \STATE $N \Leftarrow -n$ \ELSE \STATE $X \Leftarrow x$ \STATE $N \Leftarrow n$ \ENDIF \WHILE{$N \neq 0$} \IF{$N$ is even} \STATE $X \Leftarrow X \times X$ \STATE $N \Leftarrow N / 2$ \ELSE[$N$ is odd] \STATE $y \Leftarrow y \times X$ \STATE $N \Leftarrow N - 1$ \ENDIF \ENDWHILE \stopalgorithm \stopbuffer \typebuffer \getbuffer %\placealgorithm % {Calculate $y = x^n$} % {\framed[frame=off,align=right,width=fit,strut=no] {\getbuffer[algorithm]}} \stoptext Wolfgang
On Sun, Nov 30, 2008 at 5:09 PM, Zhaopeng Xing
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.
\starttext \setuplines[space=yes] \startlines $sum \leftarrow 0$ \bold{for} $i \leftarrow 1,n$ \bold{do} $sum \leftarrow sum + i$ \bold{end for} \stoplines \stoptext Wolfgang
Thank you, Walfgang. I will try. It is a good exercise.
2008/12/1 Wolfgang Schuster
On Sun, Nov 30, 2008 at 5:09 PM, Zhaopeng Xing
wrote: 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.
\starttext
\setuplines[space=yes]
\startlines $sum \leftarrow 0$ \bold{for} $i \leftarrow 1,n$ \bold{do} $sum \leftarrow sum + i$ \bold{end for} \stoplines
\stoptext
Wolfgang
___________________________________________________________________________________ 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
___________________________________________________________________________________
-- Zhaopeng XING Tinbergen Institute
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) ============================================================================== % 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* %=======================================================================
Am 01.12.2008 um 14:34 schrieb Richard Rascher-Friesenhausen:
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.
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...
It's ok for a private module but before you can put it on the garden a few things can be done better. - define the commands (IF, WHILE etc.) local and use protected names in the code, users can user similiar names in their documents and you have to take care of this - you can use \doadaptleftskip to increase/decrease the left margin with each \IF/\ENDIF ... pair - you can define \Algorithm with \defineframedtext[Algorithm] Thanks for sharing it with the rest of the community. Wolfgang
On Sun, Nov 30, 2008 at 5:09 PM, Zhaopeng Xing
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.
xml based solution by Hans: http://archive.contextgarden.net/message/20050125.164829.e244f458.en.html Wolfgang
participants (4)
-
Mohamed Bana
-
Richard Rascher-Friesenhausen
-
Wolfgang Schuster
-
Zhaopeng Xing