Here is a proposal for a layout allowing to create algorithms more friendly through lyx. Your comments and feelings on it are welcome. As I really don't know latex, don't hesitate to make remarks and evolutions. As attached file are: 1) article-algo.layout: the layout to install 2) algo.lyx: an example lyx file using the layout, and explaining how to use it. Thus, before reading it, install the article-algo.layout and reconfigure lyx. BG.
#% Do not delete the line below; configure depends on this # \DeclareLaTeXClass[article]{Article (algo)} # Report textclass definition file. Taken from initial LyX source code # Author : Matthias Ettrich <[EMAIL PROTECTED]> # Transposed by Pascal André <[EMAIL PROTECTED]> # Heavily modifed and enhanced by serveral developers. # Input general definitions Input stdclass.inc # There are no chapters in an article. NoStyle Chapter NoStyle Chapter* MaxCounter Counter_Section SecNumDepth 3 TocDepth 3 # Change a bit Part and Part* Style Part Align Left AlignPossible Left TopSep 2 BottomSep 1.5 Font Size Larger EndFont End Style Part* Align Left AlignPossible Left TopSep 2 BottomSep 1.5 Font Size Larger EndFont End # New style to write some algorithms Style Algorithm # Margin First_Dynamic LatexType Item_Environment LatexName algor NextNoIndent 1 LeftMargin MM LabelSep xxx ItemSep 0 TopSep 0.5 BottomSep 0.5 ParSep 0 Align Block AlignPossible Block, Left LabelType Manual LabelString MM FreeSpacing 0 # standard font definition Font Family Typewriter EndFont # label font definition LabelFont Series Bold EndFont Preamble %% Needed packages \usepackage{algorithm} \usepackage{algorithmic} %% Default screen keywords definition \newcommand{\keyif}{if} \newcommand{\keyelseif}{elseif} \newcommand{\keyelse}{else} \newcommand{\keyendif}{endif} \newcommand{\keyfor}{for} \newcommand{\keywhile}{while} \newcommand{\keyrepeat}{repeat} \newcommand{\keyuntil}{until} \newcommand{\keyendfor}{endfor} \newcommand{\keyendwhile}{endwhile} %% Two arguments needed %% \def\mytalg[#1](#2){% \let\item=\stditem \ifthenelse{\equal{#1}{\keyif}}{\IF{#2}}{% \ifthenelse{\equal{#1}{\keyelseif}}{\ELSIF{#2}}{% \ifthenelse{\equal{#1}{\keyfor}}{\FOR{#2}}{% \ifthenelse{\equal{#1}{\keywhile}}{\WHILE{#2}}{% \ifthenelse{\equal{#1}{\keyuntil}}{\UNTIL{#2}}{% \STATE #1(#2)}}}}} \let\item=\myalg } %% Only one real argument used %% \def\myoalg[#1]#2{% \let\item=\stditem \ifthenelse{\equal{#1}{\keyelse}}{\ELSE}{% \ifthenelse{\equal{#1}{\keyendif}}{\ENDIF}{% \ifthenelse{\equal{#1}{\keyendfor}}{\ENDFOR}{% \ifthenelse{\equal{#1}{\keyendwhile}}{\ENDWHILE}{% \ifthenelse{\equal{#1}{\keyrepeat}}{\REPEAT}{% \STATE }}}}} \let\item=\myalg } %% Main command %% \def\myalg[#1]{% \@ifnextchar({\mytalg[#1]}{% \@ifnextchar~{\myoalg[#1]}{\myoalg[#1]{ }}} } \newenvironment{algor} { \@ifundefined{stditem}{% \begin{algorithmic} \let\stditem=\item \let\item=\myalg \newcounter{algcount} \setcounter{algcount}{1} }{% \addtocounter{algcount}\@ne } }{ \addtocounter{algcount}\m@ne \ifnum \value{algcount}=0 \let\item=\stditem \end{algorithmic} \fi } EndPreamble End
#LyX 1.1 created this file. For more info see http://www.lyx.org/ \lyxformat 2.15 \textclass article-algo \language default \inputencoding latin1 \fontscheme default \graphics default \paperfontsize default \spacing single \papersize Default \paperpackage a4 \use_geometry 0 \use_amsmath 0 \paperorientation portrait \secnumdepth 3 \tocdepth 3 \paragraph_separation indent \defskip medskip \quotes_language english \quotes_times 2 \papercolumns 1 \papersides 1 \paperpagestyle default \layout Title Proposal for a LyX Algorithm Style \layout Date 17 september 2000 \layout Standard \begin_inset LatexCommand \tableofcontents{} \end_inset \layout Section Introduction \layout Standard This file is an example file using a customised layout that allows to write algorithms without using any LaTeX command in a lyx document. The layout is built in order to fulfill the WYSIWYM principles. \layout Section Document class \layout Standard When \family typewriter article-algo.layout \family default is installed (in the \family typewriter ~/.lyx/layout \family default directory), and lyx is reconfigured, the \family typewriter Article \protected_separator (algo) \family default class should be available. This is the current class of this document. \layout Section Using the \family typewriter Algorithm \family default style \layout Standard To use the lyx algorithm style, simply select the \family typewriter Algorithm \family default style, and respect the following rules: \layout Itemize The style is derived from the Enumerate style, and thus the first word of each item has a special meaning. The first word you write (bold typed) must be one of the predefined algorithmic keywords (if, else, etc.). \layout Itemize If the first word is not recognised as a predefined keyword, then it is assimilated to the algorithmic environment \backslash STATE keyword. \layout Itemize For the keywords that need extra parameters (such as: if, else \protected_separator if, until, while), these parameters must be between parentheses. \layout Itemize If the item levels are used (only for screen viewing purpose), they must be consistent, i.e. at the end of the algorithm, the deep level must come to zero. \layout Standard The screen viewing of the written algorithm can be customised as follow: \layout Itemize Use the item levels to indent the algorithm blocks. Besides the screen aspect, the item levels are not used. \layout Itemize Customise the algorithm keywords with your own language keywords (see \begin_inset LatexCommand \ref{sec:screen-keys} \end_inset ). \layout Standard The algorithms \begin_inset LatexCommand \ref{alg:small-example} \end_inset and \begin_inset LatexCommand \ref{alg:big-example} \end_inset are two examples, in which the \backslash STATE items are defined with \begin_inset Quotes eld \end_inset - \begin_inset Quotes eld \end_inset as first word. \layout Standard \begin_float alg \layout Algorithm if (something is true) \layout Algorithm - do action 1 \layout Algorithm - do action 2 \layout Algorithm elseif (something else is true) \layout Algorithm - perform the specific action \layout Algorithm repeat \layout Algorithm - run action 3 \layout Algorithm until (everything is done) \layout Algorithm endif \layout Caption \begin_inset LatexCommand \label{alg:small-example} \end_inset Example without (screen) indentation \end_float \layout Standard \begin_float alg \layout Algorithm if (something is true) \begin_deeper \layout Algorithm - do action 1 \layout Algorithm - do action 2 \end_deeper \layout Algorithm elseif (something else is true) \begin_deeper \layout Algorithm - perform the specific action \layout Algorithm repeat \begin_deeper \layout Algorithm - run action 3 \end_deeper \layout Algorithm until (everything is done) \end_deeper \layout Algorithm else \begin_deeper \layout Algorithm - do action 4 \layout Algorithm if (another thing is true) \begin_deeper \layout Algorithm for ( \begin_inset Formula \( i=0;\, i<10;\, i++ \) \end_inset ) \begin_deeper \layout Algorithm - process the iteration \end_deeper \layout Algorithm endfor \layout Algorithm while (it stills true) \begin_deeper \layout Algorithm - run action 5 \end_deeper \layout Algorithm endwhile \end_deeper \layout Algorithm endif \end_deeper \layout Algorithm endif \layout Caption \begin_inset LatexCommand \label{alg:big-example} \end_inset Example with (screen) indentation \end_float \layout Section Customisation \layout Standard The lyx algorithm style can be used in any language, by redefining the following macro commands in the latex preamble: \layout Subsection \begin_inset LatexCommand \label{sec:screen-keys} \end_inset Screen keywords \layout Standard It deals with the words written in the lyx document, and that appears on the screen. In the document, the tokens that define \backslash IF, \backslash ELSE, etc. used in the algorithms are \begin_inset Quotes eld \end_inset if \begin_inset Quotes erd \end_inset , \begin_inset Quotes eld \end_inset else \begin_inset Quotes erd \end_inset , etc. These are redefinable macros. Their default definitions are: \layout LyX-Code \backslash newcommand{ \backslash keyif}{if} \layout LyX-Code \backslash newcommand{ \backslash keyelseif}{elseif} \layout LyX-Code \backslash newcommand{ \backslash keyelse}{else} \layout LyX-Code \backslash newcommand{ \backslash keyendif}{endif} \layout LyX-Code \backslash newcommand{ \backslash keyfor}{for} \layout LyX-Code \backslash newcommand{ \backslash keywhile}{while} \layout LyX-Code \backslash newcommand{ \backslash keyrepeat}{repeat} \layout LyX-Code \backslash newcommand{ \backslash keyuntil}{until} \layout LyX-Code \backslash newcommand{ \backslash keyendfor}{endfor} \layout LyX-Code \backslash newcommand{ \backslash keyendwhile}{endwhile} \layout Subsection Output keywords \layout Standard To customise the algorithm words in the output, redefine the algorithmic environment macros. The default definitions of these macros are: \layout LyX-Code \backslash newcommand{ \backslash algorithmicrequire}{ \backslash textbf{Require:}} \layout LyX-Code \backslash newcommand{ \backslash algorithmicensure}{ \backslash textbf{Ensure:}} \layout LyX-Code \backslash newcommand{ \backslash algorithmiccomment}[1]{ \backslash {#1 \backslash }} \layout LyX-Code \backslash newcommand{ \backslash algorithmicend}{ \backslash textbf{end}} \layout LyX-Code \backslash newcommand{ \backslash algorithmicif}{ \backslash textbf{if}} \layout LyX-Code \backslash newcommand{ \backslash algorithmicthen}{ \backslash textbf{then}} \layout LyX-Code \backslash newcommand{ \backslash algorithmicelse}{ \backslash textbf{else}} \layout LyX-Code \backslash newcommand{ \backslash algorithmicelsif}{ \backslash algorithmicelse \backslash \backslash algorithmicif} \layout LyX-Code \backslash newcommand{ \backslash algorithmicendif}{ \backslash algorithmicend \backslash \backslash algorithmicif} \layout LyX-Code \backslash newcommand{ \backslash algorithmicfor}{ \backslash textbf{for}} \layout LyX-Code \backslash newcommand{ \backslash algorithmicforall}{ \backslash textbf{for all}} \layout LyX-Code \backslash newcommand{ \backslash algorithmicdo}{ \backslash textbf{do}} \layout LyX-Code \backslash newcommand{ \backslash algorithmicendfor}{ \backslash algorithmicend \backslash \backslash algorithmicfor} \layout LyX-Code \backslash newcommand{ \backslash algorithmicwhile}{ \backslash textbf{while}} \layout LyX-Code \backslash newcommand{ \backslash algorithmicendwhile}{ \backslash algorithmicend \backslash \backslash algorithmicwhile} \layout LyX-Code \backslash newcommand{ \backslash algorithmicloop}{ \backslash textbf{loop}} \layout LyX-Code \backslash newcommand{ \backslash algorithmicendloop}{ \backslash algorithmicend \backslash \backslash algorithmicloop} \layout LyX-Code \backslash newcommand{ \backslash algorithmicrepeat}{ \backslash textbf{repeat}} \layout LyX-Code \backslash newcommand{ \backslash algorithmicuntil}{ \backslash textbf{until}} \layout Section Limitations \layout Standard This lyx algorithm style has (at least) the following limitations: \layout Itemize Its behaviour is not robust, and errors can appears silently. \layout Itemize The use of double-parentheses for extra parameters (e.g: if ((something is true)) ) does not work fine. \layout Itemize All the algorithmic package specific words are not supported (e.g: require, ensure, etc.). \the_end