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

    by  • February 22, 2010 • lyx, TeX, windows • 23 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\your_user_name\AppData\Roaming\MiKTeX\2.8\tex\latex. So, for eethesis.cls, you should have a folder called eethesis within C:\Users\your_user_name\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\your_user_name\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.



    .NET developer at thetrainline.com, previously web developer at MRM Meteorite. Awarded a PhD in misbehaviour detection in wireless ad-hoc networks. A keen C# ASP.net developer bridging the gap with APIs and JavaScript frameworks, one web app at a time.


    23 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?


    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?

    7. Pat B.
      December 8, 2011 at 11:50 pm

      I followed the eethesis example excactly.

      This is the output from texhash:

      Creating fndb for user root directory (C:\Users\beach\AppData\Roaming\MiKTeX\2.9)…
      Creating fndb for user root directory (C:\Users\beach\AppData\Local\MiKTeX\2.9)…
      Skipping common root directory (C:\ProgramData\MiKTeX\2.9)…
      Skipping common root directory (“C:\Program Files (x86)\MiKTeX 2.9”)…

      But I don’t get it in my document class list.

      Help please.


    8. February 9, 2012 at 11:25 pm

      I’ve got the german version of windows 7 and so i can’t find the path C:\Users\\AppData\Roaming\MiKTeX\2.8\tex\latex. I found a similar path, but it didn’t work.
      Please help me, I want to add svmono (Springer).

    9. February 12, 2012 at 7:41 pm

      @radolf_schnittler, thanks for your comment – I’ve just noticed that my blogging engine has been stripping some of the path used in the post.

      The actual folder you are looking for is C:\Users\your_user_name\AppData\Roaming\MiKTeX\2.8\, of course, replacing your_user_name with your login.

      HTH, Paul

    10. sara
      April 2, 2012 at 10:10 am

      I can not find my Miketex2.9 in the path you mentioned. it is installed in programfilesx86. I have done the same step in my miketex2.9 folder in programfiles. But when I run ‘texhash’ command nothing happen!

      Thank you

    11. September 1, 2012 at 12:51 pm

      I need to call any classfile from the latex global path but there is no such directory as “texmf” in my directory list. I have used the command texhash also but still nothing is done. If I put the classfile in my local folder it works. Pls. suggest how I could access any classfile from the tex directory

    12. Rishon
      September 20, 2012 at 8:37 pm

      I am having trouble creating the layout for the class I am trying to add. Can anyone help me out with this?

    13. Lokesh
      October 4, 2012 at 5:40 am

      I am having the same problem as for @Lastalda and @Pat B. Please help…

    14. A Belle
      October 24, 2012 at 10:55 pm

      Excellent post. I hope my solution below might give those with better understanding a clue to finding the .cls files.

      As a Newbie to Lyx on Windows the lack of .cls files (including the default ones like article, book etc effectively made me give up. I have reinstalled Lyx “available to all “rather than “for myself only”, or whatever the options titles at this step was. Since then everything is working sweet, including your instructions. I previously tried entering my own directory into Lyx under the Preferences>Path> setting, but failed. Everything else I read about loading .cls files failed. MAKING THE INSTALL AVAILABLE TO ALL WORKED. I suspect Lyx is running foul of Windows software access constraints and assumes all files are accessible (as Windows files used to be).

    15. annie
      January 9, 2013 at 7:07 am

      I have done exactly as mentioned and got the class in document class of lyx.

      Once the created file is selected lyx hangs.

      Please help.

    16. Albaraa
      January 24, 2013 at 11:08 am

      Great .. Very clear declarations. I followed a step by step and dragged successfully my new Layout style into Lyx..
      To share what problems I faced:
      1. First I forgot to make a directory as in the first step with the same .cls file name. May be that was not clear for me only, but I re-read the article again critically, then I found that I didn’t make this folder. I made the folder and past my .cls file into it.
      2. Second, my university offered also a .layout file. So, I just copy that file and past it into the directory
      C:\Program Files\LyX16\Resources\layouts
      3. Open Lyx, go to Tools>Reconfigure.
      4. Restart Lyx. Restart means close the program and reopen it again since there is no command to restart the Lyx as I was thought that.
      5. Go to Document > Settings; you can see your new Layout available there, but not under category “unavailable”
      Dr. Paul Kiddie, I hope my post could contribute positively ..

    17. January 24, 2013 at 2:33 pm

      Thanks for the kind words and the extra steps you found necessary – I haven’t looked into this for a year or so, so the process may have changed. Your comments will be helpful for other readers!

    18. Hale
      February 2, 2013 at 11:39 am

      It doesn’t work with the latest LYX.
      Creating fndb for user root directory (C:\Users\xxx\AppData\Roaming\Mi…
      Creating fndb for user root directory (C:\Users\xxx\AppData\Local\MiKT.
      Skipping common root directory (C:\ProgramData\MiKTeX\2.9)…
      Skipping common root directory (“C:\Program Files (x86)\MiKTeX”)…

      I’ve tried putting my ieice.cls in
      C:\Program Files (x86)\MiKTeX\tex\latex
      C:\Program Files (x86)\MiKTeX\tex\latex\ieice

      Nothing works :-(

      HOW! can I add this class?

      Those f***ng rules force us to use latex, but nobody cares to provide any working distributive or complete steps to starting latex editors in Windows environment.

    19. June 15, 2013 at 4:15 am

      It worked great, thanks, I used it in Windows XP, the path were one must copy the class file is: C:\Documents and Settings\USER\local configuration\ProgramData\MiKTeX\2.8\tex\latex

      I had to create the folder “latex” within the “tex” folder, because it didn’t exist.

    20. W VDE
      July 14, 2013 at 6:35 pm

      Thank you very much, this info was really useful to me!

    21. Sheikh
      July 31, 2013 at 12:26 am

      Receiving “You don’t have permission to save in this location. Contact the administrator to obtain permission.” in LyX20.
      Kindly Help Earliest.

    22. Paul
      February 17, 2014 at 11:03 am

      Thanks a lot!!!

    23. May 13, 2014 at 3:46 pm

      Thanks for the info. But it worked for me when I put the .cls file in: C:\Users\Administrador\AppData\Local\MiKTeX\2.9\tex\latex\
      I am using windows 7, administrador is my windows user. I also had to create the “tex” and “latex” folder.

    Leave a Reply

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