Article View: comp.text.tex
Article #1402Re: Environment for algorithms
From: Eamonn McManus
Date: Thu, 15 Mar 1990 22:35
Date: Thu, 15 Mar 1990 22:35
40 lines
2121 bytes
2121 bytes
mpf@triplea.cs.umd.edu (Martin Farach) writes:
>Does anyone have an environment for formating algorithms in LaTeX?
You could try using my recently-posted macros for formatting C programs.
They are not very dependent on C syntax and format algorithms in a
reasonable way. Each line in the input corresponds to a line in the
output, and tabs can be used to control indentation.
Your example could be rendered like this:
\begin{figure}\caption{Name of Algorithm}
\begin{cprog}
i = 1
for j = 0 to 100
i = i + j
\end{cprog}
\end{figure}
All the text is rendered in the normal text font, except that comments in
/*...*/ will be in a slanted font, and strings in "..." or '...' in
typewriter. Character pairs like <= and != get converted into single
symbols like $\le$ and $\ne$.
The {cprog} environment is a verbatim one, so you can't use TeX commands to
change fonts or whatever within it. It would be easy to hack cprog.sty so
that \, {, and } still have their usual meanings. Just remove commands
that say \makeactive\\, \makeactive{, and \makeactive}, and those that say
\def{[...], \def}[...], \expandafter\def\activebackslash[...]. Also remove
\begingroup and \cprogarg from the definitions of \cprog and \cprog*, and
\endgroup from the definition of \endcprog. I think this would be
sufficient.
If you do this, rename the style file and the environment so there won't
be mutant cprog.sty files around.
--
Eamonn McManus <emcmanus@cs.tcd.ie> <emcmanus%cs.tcd.ie@cunyvm.cuny.edu>
One of the 0% of Americans who are not Americans.
Technical Details
Message-ID:
<1712@tws8.cs.tcd.ie>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!think!mintaka!bloom-beacon!eru!luth!sunic!mcsun!ukc!tcdcs!swift.cs.tcd.ie!emcmanusReferences:
<MPF.90Mar14220157@triplea.cs.umd.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!think!mintaka!bloom-beacon!eru!luth!sunic!mcsun!ukc!tcdcs!swift.cs.tcd.ie!emcmanus From: emcmanus@cs.tcd.ie (Eamonn McManus) Newsgroups: comp.text.tex Subject: Re: Environment for algorithms Summary: Could use cprog.sty Message-ID: <1712@tws8.cs.tcd.ie> Date: 15 Mar 90 22:35:12 GMT References: <MPF.90Mar14220157@triplea.cs.umd.edu> Distribution: comp Organization: Computer Science Department, Trinity College Dublin Lines: 40