Benoit Guillon's Algorithm-Style Package for LyX was written in the year 2001. It makes the LaTeX package algorithmic
available to LyX in an interesting form. For writing algorithms, the potential of nested lists is used. (Because at that time LyX modules were not available there is the requirement of using a certain document class. But this could be revised...)
Now, how to print two algorithms side-by-side in a LaTeX document is shown in Diego’s CS research blog. This can be transformed into "pure" LyX almost completely.
For each algorithm-float do
set its "Placement Options" (e.g., by right click) to "Here definitely" to stop it floating -- this is important otherwise an error occurs,
enclose the float by a minipage whose width is a fraction of the column width (e.g., 45% of column width);
Remove all white spaces (including new lines) between the minipages and "Insert > Formatting > Horizontal Space..." "Horizontal Fill";
Add TeX code/ERT \begin{figure*}
before the first minipage and \end{figure*}
after the last minipage to make the block of algorithms floating again.
Here is a picture of a LyX document followed by the PDF output.
Is this what you are trying to achieve?
This is the MWE:
\documentclass{article}
\usepackage[plain]{algorithm}
\usepackage{algpascal}
\begin{document}
\algrenewcommand\textkeyword{\textrm}
\algdef{SE}{For}{End}[2]{%
\textkeyword{for} \(#1\) \textkeyword{to} \(#2\) \textkeyword{do begin}}{%
\textkeyword{end}}
\begin{algorithm}
\begin{algorithmic}[1]
\State Assign an ordering $A_{1}, ..., A_{n}$ to the nonterminals of the grammar.
\For{i = 1}{n}
\For{j = 1}{i-1}
\State for each production of the form $A_{i} \rightarrow A_{j} \alpha$
\End
\End
\end{algorithmic}
\caption{Paull's algorithm}
\end{algorithm}
\end{document}
Explanation
To match your first two requests, I've redefined the behavior of for
to have an end
statement by adding the lines:
\algdef{SE}{For}{End}[2]{%
\textkeyword{for} \(#1\) \textkeyword{to} \(#2\) \textkeyword{do begin}}{%
\textkeyword{end}}
To match your last request, it suffices to add the line:
\algrenewcommand\textkeyword{\textrm}
which redefines the font for keywords to be \textrm
instead of \textbf
.
In regards of your 3rd request, there are two ways.
If you want the algorithm to behave as an algorithm, simply load the algorithm
package with the option plain
as in the above MWE:
\usepackage[plain]{algorithm}
If you want the algorithm to behave as a figure, there is no need to load the algorithm
package, simply insert the algorithmic
environment inside a figure
, i.e. replace the lines
\begin{algorithm}
\begin{algorithmic}[1]
...
\end{algorithmic}
\caption{Paull's algorithm}
\end{algorithm}
with
\begin{figure}
\begin{algorithmic}[1]
...
\end{algorithmic}
\caption{Paull's algorithm}
\end{figure}
and you will have
Addendum
This is the complete implementation of the algorithm in the figure:
\documentclass{article}
\usepackage[plain]{algorithm}
\usepackage{algpascal}
\begin{document}
\algrenewcommand\textkeyword{\textrm}
\algdef{SE}{For}{End}[2]{%
\textkeyword{for} \(#1\) \textkeyword{to} \(#2\) \textkeyword{do begin}}{%
\textkeyword{end}}
\algdef{SE}{ForEach}{End}[1]{%
\textkeyword{for each} #1 \textkeyword{do begin}}{%
\textkeyword{end}}
\begin{algorithm}
\begin{algorithmic}[1]
\State Assign an ordering $A_{1}, \dots, A_{n}$ to the nonterminals of the grammar.
\For{i := 1}{n}
\For{j := 1}{i-1}
\ForEach{production of the form $A_{i} \rightarrow A_{j} \alpha$}
\State remove $A_{i} \rightarrow A_{j} \alpha$ from the grammar
\ForEach{production of the form $A_{j} \rightarrow \beta$}
\State add $A_{i} \rightarrow \beta\alpha$ to the grammar
\End
\End
\End
\State transform the $A_{i}$-productions to eliminate direct left recursion
\End
\end{algorithmic}
\caption{Paull's algorithm}
\end{algorithm}
\end{document}
There is the need to define a new command \ForEach
:
\algdef{SE}{ForEach}{End}[1]{%
\textkeyword{for each} #1 \textkeyword{do begin}}{%
\textkeyword{end}}
Note that I've defined \ForEach
so to take one "text" argument, because it seemed to me the best way to define it.
If you want it to take a "math" argument, then define it as
\algdef{SE}{ForEach}{End}[1]{%
\textkeyword{for each} \(#1\) \textkeyword{do begin}}{%
\textkeyword{end}}
and use it as follows (amsmath
is needed for the command \text
):
\ForEach{\text{production of the form }A_{i} \rightarrow A_{j} \alpha}
Best Answer
There is no need for
\STATE
when you're using\FOR
. The latter construction sets a\STATE
by default: