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 Answers 3

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.
3
  • Though it is an improvement, it seems so tedious. Is there no better way? May 23, 2013 at 0:04
  • @inspectorG4dget: See the updated answer.
    – juliohm
    May 23, 2013 at 0:20
  • @inspectorG4dget Yes, there is another way. It is possible to use the mentioned package but in a modified way - see my answer...
    – e-birk
    May 23, 2013 at 10:34
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").

9
  • 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 May 23, 2013 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, 2013 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". May 24, 2013 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, 2013 at 17:17
  • Yes. I tried putting the module in both locations, which still didn't work May 25, 2013 at 17:21
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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .