Path: utzoo!attcan!uunet!tank!ncar!asuvax!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!brutus.cs.uiuc.edu!apple!rutgers!aramis.rutgers.edu!paul.rutgers.edu!halldors From: halldors@paul.rutgers.edu (Magnus M Halldorsson) Newsgroups: comp.text.tex Subject: Re: Environment for algorithms Message-ID: Date: 15 Mar 90 20:58:41 GMT References: Distribution: comp Organization: Rutgers Univ., New Brunswick, N.J. Lines: 51 In article mpf@triplea.cs.umd.edu (Martin Farach) writes: > Does anyone have an environment for formating algorithms in LaTeX. I have one, thanks to Martin Carroll. ----- algorithm.sty ----- %The following code creates an environment that works just like the %figure environment, except that it's for algorithms. That is, its %captions look like % % Algorithm 2.1: An algorithm. % %The algorithms are numbered independently of the figures. %It also produces a .loa file, which can be used to create a list of %algorithms via the command \listofalgorithms. % Author: Martin Carroll \def\listofalgorithms{\@restonecolfalse\if@twocolumn\@restonecoltrue\onecolumn \fi\chapter*{List of Algorithms\@mkboth {LIST OF ALGORITHMS}{LIST OF ALGORITHMS}}\@starttoc{loa}\if@restonecol\twocolumn \fi} \def\l@algorithm{\@dottedtocline{1}{1.5em}{2.3em}} \newcounter{algorithm}[chapter] \def\thealgorithm{\thechapter.\@arabic\c@algorithm} \def\fps@algorithm{tbp} \def\ftype@algorithm{4} \def\ext@algorithm{loa} \def\fnum@algorithm{Algorithm \thealgorithm} \def\algorithm{\@float{algorithm}} \let\endalgorithm\end@float \@namedef{algorithm*}{\@dblfloat{algorithm}} \@namedef{endalgorithm*}{\end@dblfloat} ----------------------------------------- The only problem with it is that it assumes chapters in the document (i.e. that the document is a book). As a quick and dirty solution I use another file when doing, say, articles, changing only these two lines: \newcounter{algorithm}[chapter] \def\thealgorithm{\thechapter.\@arabic\c@algorithm} to \newcounter{algorithm}[section] \def\thealgorithm{\thesection.\@arabic\c@algorithm} Magnus