2

I would like to use a specific template in LyX. When I try using it, however, LyX returns the following message:

"The document class can still be used, but the document cannot be complied until the following prerequisites are installed:

"A.cls"

How do I get this *.cls file?

Thanks!

4

There aren't many LyX users on here, and probably fewer who play with LyX layout files.

I have done this before, and the general steps involved are:

  1. Find the Customising LyX: Features for the Advanced User document and go to section 5: Installing New Document Classes, Layouts and Templates. Section 5.2.3 talks specifically about .cls files. I highly recommend you read this first, as it's very easy to break your layout file... this would happen to me multiple times a day when I was writing mine, but luckily I was being paid to make a working product.
  2. Create a .layout file, for example A.layout. On Windows, you will need to save this in: C:\Users\~Username~\AppData\Roaming\LyX2.1\layouts. You will also need to save the A.cls file there.
  3. Your layout file must begin with: # \DeclareLaTeXClass[<class name>]{<Name to be displayed in LyX>}. If you want it to be grouped in the drop down list, then you can specify: # \DeclareCategory{Books} to make it appear in the drop down category for books (found in Document > Settings > Document Class)
  4. Now say in A.cls you have a custom environment called foo. If you are happy with ERT (Evil Red Text), then you can specify \begin{foo} and \end{foo} in your LyX document as LaTeX code. However, if you want a more eligant approach, read on...
  5. For each custom environment or command, you want to specify how they will be displayed in LyX. Below is a sample of my code: Lyx Layout Sample Rather unfortunately StackExchange doesn't recognise lyx layout coding and the hash tags (the comment system for LyX) wreaks havoc on my answer, which is why my sample is a picture.

The picture I included is only a sample of what you can do in a layout file, and more detail can be found in Section 5.3 The layout file format if you are interested.

Very basically though, you specify if it is an Environment or a Command from your custom class (LatexType), specify the name of environment/command (Latexname) and then you specify how that environment/command will look in Lyx (LabelType, Label Font, LeftMargin, etc etc)

This should enable you to include your custom class in Lyx and, if you have the time, reduce the amount of ERT required.

Also note that it is possible to specify your own module rather than create an entire layout file, but I am not familiar with that particular process.

EDIT: As per AJN's comment, I forgot to mention that you will need to reconfigure LyX after the first time you add in your layout file. This is found in Tools > Reconfigure. Note that you do not have to reconfigure LyX every time you make a change to you layout file (I found that out the hard way after spending ages reconfiguring after every change I made in my layout file).

  • +1. When I pass from LyX to plain LaTeX a major reason was not to deal with layout files. – Fran Jan 13 '16 at 3:26
  • 1
    You may also have to restart and/or press reconfigure button in Lyx for the changes to be visible in the GUI. – AJN Jan 13 '16 at 5:24
  • Ahh, yes definitely! I forgot to say that, I'll add that in now :) – Alwin Jan 13 '16 at 5:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.