Pages

3/31/2011

Lyx: Convert Latex .cls file to .layout in Lyx

I just started using Lyx.
The problem is I already have latex (.tex) files and the document class file (.cls)

Basically, Lyx comes with a converter called "tex2lyx", which be able to convert any .tex file into .lyx file to be used in Lyx.

So, what I did is to import the main tex file "thesis.tex" which has content like this:
% This is a template for Ph.D. dissertations in the UCI format.

% All fonts, including those for sub- and superscripts, must be 10 points or larger.
% Recommended sizes are 14-point for chapter headings, 12-point for the main body of text
% and figure/table titles, and 10-point for footnotes, sub- and super-scripts, and text in
% figures and tables.
\documentclass[12pt,fleqn]{ucithesis}

...

\include{introduction}

\include{background}

\include{relatedwork}

...


Unfortunately, when I tried to import I found this error.
$ tex2lyx -f thesis.tex 
Error: Could not find layout file for textclass "ucithesis".

After searching for awhile, I found that Lyx does not use and cannot understand ".cls" file in Tex. The only Lyx can understand the format of the document is to use ".layout" file. So, how to convert .cls to .layout , and how to use it??

I also found this http://www.paulkiddie.com/2010/02/adding-custom-class-files-cls-to-lyx-in-windows-vista-windows-7-environment/

It shows a way to use ".cls" in Lyx, but it is for Windows, I need to adapt it for using it in Linux.


To summarize, the idea from the link above can be separated into 2 parts:
1. Create new document class for Latex in your system:
2. Set Lyx to recognize the style

1. Create new document class for Latex
  • go to main folder of Latex. Mine is at /usr/share/texmf/tex/latex
  • create new folder the same name as the class file. So I'll have /usr/share/texmf/tex/latex/ucithesis
  • move .cls file into that folder. For this move my "ucithesis.cls" into the folder.
/usr/share/texmf/tex/latex/
----------ucithesis/
---------------------ucithesis.cls
 2. Set Lyx to know that
  • go to layout folder of Lyx. Mine is at /usr/share/lyx/layouts
  • create a .layout file. I want to use class "ucithesis", so I create "ucithesis.layout"
  • put this text into that file (replace "ucithesis" with whatever class name you want") :
#% Do not delete the line below; configure depends on this
# \DeclareLaTeXClass[ucithesis]{article (ucithesis)}
# Input general definitions
Input stdclass.inc
  • this will add new layout into Lyx, but Lyx doesn't know it yet.
  • to let Lyx knows it, open Lyx program, then go to Tools --> Reconfigure
  • restart Lyx for it to take effect.
 At this point I can import my main Tex file into Lyx program.

Moreover, if you want to set document class for the current open document,
go to Document --> Settings... --> Change Document class to what you want

11 comments:

  1. Thank you very much!!!!!!!

    This is exactly what I was looking for two days now.
    Regards HoWil

    ReplyDelete
  2. Same for me !
    Thank you

    ReplyDelete
  3. Thank you, for solving my problem by a perfect how-to. I was facing exactly the same problem.

    Regards

    ReplyDelete
  4. Also worked for me.
    Thank you!

    ReplyDelete
  5. I got the following error:
    The selected document class
    article(myarticlename)
    requires external files that are not available. The document class can still be used, but the document cannot be compiled until the following prerequisites are installed:
    myarticlename.cls
    See section 3.1.2.2 (Class Availability) of the User's Guide for more information

    So what is wrong? I followed exactly the same procedure as listed above

    ReplyDelete
  6. I also got the same error as the above user has.
    what is wrong?
    I even use sudo texhash to do it.

    ReplyDelete
  7. I got the same error as the Anonymous3/10/2012 06:59:00 AM.

    ReplyDelete
  8. Same problem - prerequisites are not installed.

    ReplyDelete
  9. I had the same problem as everybody above. That was because, as the source http://www.paulkiddie.com/2010/02/adding-custom-class-files-cls-to-lyx-in-windows-vista-windows-7-environment/ instructs, the command `texhash` needs to be run before reconfiguring LyX. Of course, in Linux that would be `sudo texhash`.

    ReplyDelete
  10. Samples supply a helpful motivation which empowers you to canvas get a handle on the ideas like java,j2ee,spring,Hibernate.java

    ReplyDelete
  11. Currently, one of the most popular file sharing programs is Aries, an open-source application that allows users to share almost any kind of digital file.
    download shareit app

    ReplyDelete