How to Use a New Latex Class in Lyx

Let's say we have a custom new Latex class called "newclass.cls" which we want to be able to use with Lyx under Windows.

  1. Copy the new Latex class file "newclass.cls" into the MikTeX directory within your user settings folder like so: C:\Users\UserName\AppData\Roaming\MiKTeX\2.8\tex\latex\newclass\newclass.cls. Remember to replace UserName with your own Windows username.

  2. Update the MikTeX list of classes by clicking the Windows Start button and typing cmd into the search box. When the black command line window displays, type texhash and hit Enter.

  3. Next we need to create a layout file for Lyx to work with. This file contains instructions on how to roughly format a document when displayed within the Lyx program itself. More importantly, the layout file points to the Latex class for generating the final output. It is helpful to start by just modifying an existing layout file which is similar in purpose to the Latex class we are trying to add. For example, if our new Latex class is a template for an article, we might want to start by copying article.layout from C:\Program Files (x86)\LyX20\Resources\layouts and pasting it into C:\Users\UserName\AppData\Roaming\LyX2.0\layouts. Rename the file to match your class name, say, "newclass.layout"

  4. Open up your new layout file, and look at the second line. Replace it with:
    # \DeclareLaTeXClass[newclass]{Title of Class}
    Enter your class name within the [] brackets, and enter whatever descriptive name you want to call the class within the {} braces.

  5. Open Lyx, and click Tools > Reconfigure. Restart the Lyx program when it prompts you to do so.

That's it! When you start a new document in Lyx, your new class should appear within the drop-down box for Document Class in the Document Settings window (Document > Settings).

Tested with Lyx 2.0 and MikTeX 2.8 under Windows 7.

1 comment

  • Cyberz says:

    Hey bro, nice tutorial.

    I've been getting an error, and I'd be please if you could help me.

    I did everything you've told me, so, when I try to preview or to update, I get this message:

    ! LaTeX Error: Option clash for package inputenc.
    See the LaTeX manual or LaTeX Companion for explanation.
    Type H for immediate help.
    ...
    l.8 \usepackage{amsthm}
    The package inputenc has already been loaded with options:
    [ansinew]
    There has now been an attempt to load it with options
    [latin9]
    Adding the global options:
    ansinew,latin9
    to your \documentclass declaration may fix this.
    Try typing to proceed.

    So I tryied looking at the .cls file and the .style file and the only reference to the package I found was at the .cls file, which was:

    \RequirePackage{amsmath, amssymb, amsfonts, amsthm}

    1

Comments are closed.