🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.text.tex
Article #1396

Re: Environment for algorithms

#1396
From: Magnus M Halldorsson
Date: Thu, 15 Mar 1990 20:58
51 lines
2247 bytes
In article <MPF.90Mar14220157@triplea.cs.umd.edu> 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
Technical Details
Message-ID: <Mar.15.15.58.40.1990.28352@paul.rutgers.edu>
Path: arc1-ca.pugleaf.net!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
References: <MPF.90Mar14220157@triplea.cs.umd.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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: <Mar.15.15.58.40.1990.28352@paul.rutgers.edu>
Date: 15 Mar 90 20:58:41 GMT
References: <MPF.90Mar14220157@triplea.cs.umd.edu>
Distribution: comp
Organization: Rutgers Univ., New Brunswick, N.J.
Lines: 51