I am confused about the packages for writing simple "algorithms". There are too many options, and it is confusing when to use what. For example, if I use algpseudocode
, then I can't add algorithmic
because it is already included in the algorithm
package.
Is there any definitive guidelines for a streamlined approach?
Any suggestion will be appreciated.
Best Answer
TL;DR version:
algorithmicx
.I use
algorithmicx
withalgpseudocode
since they are superior toalgorithmic
. I thinkalgorithmicx
offers the same functionality compared toalgorithm2e
, but I find its syntax clearer than the one provided byalgorithm2e
.Detailed version
algorithm
Float wrapper for algorithms. It is similar to block commands
table
orfigure
, which you wrap around your table/figure to give it a number and to prevent it being split over two pages. The documentation says:Example:
algorithmic
This is the environment in which you write your pseudocode. You have predefined commands for common structures such as
if
,while
,procedure
. All the commands are capitalized, e.g.\IF{cond} ... \ELSE ...
. The documentation1 says:Example:
algorithmicx
This package is like
algorithmic
upgraded. It enables you to define custom commands, which is somethingalgorithmic
can't do. So if you don't want to write your (crazy) custom commands, you will be fine withalgorithmic
. You usealgorithmicx
the same way you usealgorithmic
, only the syntax and details are slightly different. See the example below for details. The documentation says:Example:
algpseudocode
This is just a layout for
algorithmicx
which tries to be as simillar as possible toalgorithmic
. There are also other layouts, such as:algcompatible
(fully compatible with the algorithmic package),algpascal
(aims to create a formatted pascal program, you can transform a pascal program into analgpascal
algorithm description with some basic substitution rules).algc
(just like the algpascal, but for c. This layout is incomplete).The documentation says:
See the example for
algorithmicx
, it uses thealgpseudocode
layout.algorithm2e
This is another algorithm environment just like
algorithmic
oralgorithmicx
. The documentation says:Example: