• Adding custom class files (.cls) to Lyx in Windows Vista / Windows 7 environment

    by  • February 22, 2010 • lyx, TeX, windows • 6 Comments

    When writing for publication, you may be offered a .cls file from the journal in question in which to format a TeX document to their specification. Whilst this works great in TeX, usually by copying the class.cls file in your working directory where all your .tex files reside and adding \documentclass{class} in the preamble (before \begin{document}), using these custom classes isn’t so straightforward in Lyx, so I’ll describe the steps required. I’m using the eethesis.cls class file as an example, which you can obtain from http://www.latex-site.info/. This class file aids in the presentation of a thesis or progress report which meets the requirements of formatting at the University Of Birmingham, UK.

    There are a couple of posts I ran across which deal with this specific issue, here and here. None were specific to Windows Vista/Windows 7, so I’ll deal with that here. This assumes version 2.8 of Miktex and version 1.6 of Lyx. If you are using an earlier or later versions, replace with the correct version numbers where I’ve used them.

    1. Get a copy of the class file, and copy it into a folder with the same name into C:\Users\\AppData\Roaming\MiKTeX\2.8\tex\latex. So, for eethesis.cls, you should have a folder called eethesis within C:\Users\\AppData\Roaming\MiKTeX\2.8\tex\latex. This is Windows Vista / Windows 7 specific, you will soon see why…
    2. Create a new file and paste the following into it:
      #% Do not delete the line below; configure depends on this
      # \DeclareLaTeXClass[xxx]{article (xxx)}
      # Input general definitions
      Input stdclass.inc

      replacing xxx with the class name (without the .cls extension). In my case, xxx is eethesis, and the code above becomes:

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

      Thanks goes out to http://wastedmonkeys.com/2007/09/27/adding-a-new-class-in-lyx-windows for this.

    3. Save this file to C:\Program Files\LyX16\Resources\layouts, naming it eethesis.layout.
    4. In a command prompt (type cmd in start menu), type texhash. What you will now see it doing is iterating through several folders for new classes, one of which (C:\Users\AppData\Roaming\MiKTeX\2.8\) is where we copied the eethesis.cls class file into.
    5. Within Lyx, hit Tools > Reconfigure, then restart Lyx.
    6. Open a document and click Document > Settings. Click on ‘Document Class’, expand the drop down menu and you should see ‘article (xxx)’ is visible, and usable, (like below) within the drop down menu.

    lyx-document-classes

    About

    Web Developer for MRM Meteorite. Awarded a PhD in research into novel techniques to detect misbehaviour in peer-to-peer wireless networks. Experienced C# and ASP.net developer, with an interest in SOA, RIA and moble app development.

    http://www.paulkiddie.com

    6 Responses to Adding custom class files (.cls) to Lyx in Windows Vista / Windows 7 environment

    1. Rei
      August 2, 2010 at 5:59 pm

      Good one! It worked…I was going crazy with the LyX and MikTeX configuration for a new class! Thanks

    2. wh0g3
      October 21, 2010 at 3:33 am

      thank you! =)

    3. October 26, 2010 at 9:11 pm

      Thank you! I hadn’t realized the class needed to be put under the Roaming folder in windows 7.

    4. June 9, 2011 at 12:56 pm

      I have done all the step above, but I still get the error message :
      LaTeX Error : File ‘ociamthesis.sty’ not found

      could you help me please?thanks for your kindness

    5. Steph Bredenhann
      June 22, 2011 at 6:08 pm

      Thanks for this. Me first problem is that there is no such folder as C:\Users\\AppData\Roaming\MiKTeX\2.8\tex\latex, I only have C:\Users\\AppData\Roaming\MiKTeX\2.9\tex\\generic. Must I make a subfolder …\latex\myclass?

      Thanks

    6. Lastalda
      August 15, 2011 at 10:07 am

      I followed this tutorial exactly, but still can’t find the new class in Lyx.
      Is it maybe because the texhash command skips the Roaming folder?

      (When I execute texhash, even in real admin mode (Win 7 here), I get
      Skipping user root directory (C:\Users\\AppData\Roaming\MiKTeX\2.9)…
      Skipping user root directory (C:\Users\\AppData\Local\MiKTeX\2.9)…
      Skipping user root directory (oot)…)

      Help, please?

    Leave a Reply

    Your email address will not be published. Required fields are marked *