Using custom LaTeX document classes in LyX

21 September, 2006 - 10:23
Categories:

For writing with LaTeX I prefer using LyX because it hides the ugliness of LaTeX source code behind a pseudo-WYSIWYG frontend (the developers call it WYSIWYM: what you see is what you mean). Including mathematical expressions, however, is very LaTeX minded and comfortable: you type LaTeX math constructs (stuff with _, ^, \sum, ...) and LyX directly visualises it as a pretty printed formula. For the advanced LaTeX constructions not available in LyX's interface one can always fall back om "raw LaTeX" input fields. In short, I think LyX is a very handy compromise between the power of LaTeX and the user friendliness of a WYSIWYG system.

Sometimes, for example when writing an article for a conference, one need to use a custom LaTeX document class, recommended by the conference author guidelines. The procedure to make LyX using this custom document class is non obvious and a bit involved. It is broadly explained in the LyX manual (Part Customization, Chapter 5 Installing New Document Classes, Layouts, and Templates), but here is the short version (for teTeX on Linux or related systems, I don't know about Windows):

  • Get the LaTeX document class file, e.g. funkyarticle.cls.
  • Put this class file where LaTeX could find it. I use for example the directory ~/texmf/tex/latex/ in my own home directory (it has to be precisely the ~/texmf/tex/latex/ directory structure, otherwise it does not work). That way I don't have to mess with my system (for example in directories as /usr/share/texmf/tex/latex/) as administrator. This pages is more elaborate on installing custom LaTeX stuff
  • Run texhash from the command line. This updates (La)TeX's database (it creates ls-R files, e.g. look at ~/texmf/ls-R).
  • Make a LyX layout file matching the custom LaTeX class file, e.g. funkyarticle.layout. Put it where LyX can find it, e.g. in ~/.lyx/layouts/.

    The LyX layout file declares how LyX has to format your text (LyX does not use the LaTeX layout system and settings). A very minimal LyX layout file could be this:

    #% Do not delete the line below; configure depends on this
    #  \DeclareLaTeXClass[funkyarticle]{article (funky)}
     
    # Input general definitions
    Input stdclass.inc

    For conference articles I use for example something like

    #% Do not delete the line below; configure depends on this
    #  \DeclareLaTeXClass[funkyarticle]{article (funky)}
     
    # Input general definitions
    Input stdclass.inc
     
    MaxCounter      Counter_Section
     
    Style Section
        Align Center
        Font
            Shape SmallCaps
        EndFont
    End

    You can find more elaborate examples to base your layout file on in your global LyX layout directory (/usr/share/lyx/layouts/ in my case, search for *.layout files).

    The second line of the layout file is very important and has to be tailored to your particular case: in \DeclareLaTeXClass[foo]{bar} the foo refers to the LaTeX class file foo.cls and bar is how this class will be called in the LyX interface.

  • Start LyX and choose "Edit" > "Reconfigure". Close Lyx.
  • Restart LyX. Under "Layout" > "Document" > "Layout" > "Document class" the newly created LaTeX/LyX class should now be selectable (as "article (funky)" in our example)
27 May, 2011 - 11:36

Great article

Rajshekar (not verified)

That was simple enough! Very useful article.. Thank you.

26 October, 2010 - 17:51

Capitalization and Styles

Jonathan (not verified)

Worked wonderfully. Just note the .cls file type has to be in small caps. (Unlike PNASTWO.CLS for instance).

Any crash manual on using custom .sty files?

12 May, 2010 - 18:04

Awesome! thanks, works for me

lgriffiths (not verified)

Awesome!
thanks, works for me lyx 1.6.4

23 April, 2010 - 12:46

Worked for me

BG (not verified)

I followed the basic layout file and got it working for Roger Cortesi's Handout Class. (On Lyx 1.6.5)

http://rogercortesi.com/portf/latex/

Thanks!

8 April, 2010 - 23:59

I have followed the

sajjad (not verified)

I have followed the instruction and when i load LyX , it finds the custom document class but when i select it, the application hangs.

Any idea?

Regards
Sajjad

7 September, 2007 - 00:10

llncs

Anonymous

Thanks very much, it worked for me with lyx 1.4.4

9 October, 2008 - 01:46

problem with lyx

Anonymous (not verified)

Hello,

I have done all your recommendations but I am still having the same problem. Lyx cannot find the class.

I have installed lyx 1.5.6 in kubutun.

thanks

Carlos Sosa

11 October, 2009 - 14:11

I also get the same problem

Anonymous (not verified)

I also get the same problem with Lyx 1.5.6 in Windows.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • No HTML tags allowed
  • Lines and paragraphs break automatically.

More information about formatting options