11

I'm used to using the algorithmic package in LaTeX, but don't see an easy way to use it in LyX. I even tried this, but it didn't work. Further, it required me to change my document type, which is a problem for me, as I am writing my thesis and require a specific document type.

How may I go about using the algorithmic package in LyX?

Technical specs:

  • Mac OS X 10.7.5 (Lion)
  • LyX 2.0.6

3 Answers3

13

The mentioned Algorithm-Style Package for LyX (version 0.3) does not provide LyX module support since it was written for an older LyX version without module support. My approach creates a LyX module that can be used with every document class. Hence, it circumvents the necessity of the original package to use a certain document class.

The instructions below will install the package and add module support. Actually they replace the instructions of Readme.txt of the package. The files algorithm.inc and article-algo.layout of the original package are not needed anymore. $HOME will stand for your home directory.

  1. unpack the archive algo-0.3.tar.gz,
  2. copy the file algorithm.inc to $HOME/.lyx/layouts and rename it to algolyx.module,
  3. insert the following lines at the very beginning of the file algolyx.module

    #\DeclareLyXModule{Algorithm support for LyX}
    #DescriptionBegin
    #This module provides a text style to write algorithms using the
    #packages "algorithm" and "algorithmic".
    #DescriptionEnd
    

    (Now algolyx.module became the needed module.)

  4. in LyX run "Tools > Reconfigure" and restart LyX,

  5. copy the file algolyx.sty to the directory $HOME/texmf/tex/latex (needs to be created possibly) and run texhash (or alternatively, copy the file algolyx.sty into each directory that contains a LyX document using this module).

For your document, add the module "Algorithm support for LyX" under "Document settings > Modules". In an algorithm float ("Insert > Float > Algorithm") choose the text style "Algorithm" and write an algorithm. The indentation is controlled by using nesting of lists, that is, "Increase depth" Alt+Shift+Right and "Decrease depth" Alt+Shift+Left. Each statement starting without any keyword must be preceded by a star *. Here is an example:

enter image description here

For more examples, have a look at my answer here or the example provided by algo-0.3.tar.gz (to get it working with the modified setup, you need to add the module "Algorithm support for LyX" and change the document class to "article").

e-birk
  • 4,373
  • I mention in my question that I can't change the document type, as I am writing my thesis. I explained that as a result, the algo package, which I linked to in my question, doesn't work for me – inspectorG4dget May 23 '13 at 14:16
  • @inspectorG4dget Yes, I know that restriction and therefore I showed in my answer how to circumvent it... My answer shows how to create a LyX module for the package and how to set it up. (Not all files of the original package are needed anymore!) BTW, a LyX module can be added to a document without changing the document class. – e-birk May 23 '13 at 16:29
  • Followed your instructions to the tee and even tried suggestions from here. I was ultimately unable to find "Algorithm support for LyX" under "Document settings > Modules". – inspectorG4dget May 24 '13 at 21:14
  • @inspectorG4dget It seems that the LyX module "Algorithm support for LyX" which was newly created in step 2 and 3 was not recognized. Did you put the file "algolyx.module" (which should look like this) into the directory ~/Library/Application Support/LyX-2.0/layout instead of ~/.lyx/layout since you are using Mac? – e-birk May 25 '13 at 17:17
  • Yes. I tried putting the module in both locations, which still didn't work – inspectorG4dget May 25 '13 at 17:21
  • @inspectorG4dget I guess you ran "reconfigure" and restarted LyX afterward as described in http://tex.stackexchange.com/q/9389. I'm out of ideas but the problem seems about installing a new LyX module. – e-birk May 25 '13 at 17:40
  • After running texhash I had to Reconfigure and restart lyx again. Also on debian I had to put algolyx.sty under /usr/local/share/texmf/ as root.

    Now it works, thanks.

    – Kasper Ziemianek Jan 02 '15 at 13:17
  • Is there a way to add a keyword? – Jerry Nov 18 '15 at 21:03
  • How do you use tabulation in this float window? – zygimantus Jan 17 '16 at 18:07
9

The LyX way of inserting algorithms:

  1. Insert->Float->Algorithm
  2. Insert->TeX Code
  3. Paste your algorithmic code from your favorite editor Ctrl+Shift+V.
Werner
  • 603,163
juliohm
  • 3,452
0

In Windows 7,algolyx.module has to be put under %APPDATA%\LyX2.0\layouts, where the value of %APPDATA% can be checked by running "set" in command prompt.

Werner
  • 603,163
sudar
  • 1