Adding a Custom Layout to LyX

Sept. 30, 2018, 6 p.m.

by ORDINATECHNIC

LyX, referred to as "The Document Processor" by its developers and maintainers, greatly simplifies the process of preparing documents with TeX/LaTeX, by hiding much of the details of its LaTeX beackend (which hides the pain of its TeX backend). It does however require users to convert LaTeX formats into native its native formats in certain case. This article provides some hints on creating a LyX layout from a LaTeX class.

Introduction

The files I am adding are those provided by the AIAA for their publications; they distribute the files:

  • new-aiaa.bst, a BibTeX bibliography format
  • new-aiaa.class, a LaTeX class based on the standard Article class with two options, journal and conf

The desired LaTeX class can be added to either the local TeX tree for all users or to an individual user's TeX tree. It is however easire to add it to an individual user's tree. In either case the location of the trees on the filesystem must be determined.

The texmf.cnf file specifies the locations of these trees using the environment variables $TEXMFLOCAL and $TEMFHOME. If these are not set, they need to be set. To find the location of the texmf.cnf file use the command kpsewhich texmf.cnf. In Fedora 28 and Manjaro neither of these variables are set. I set the $TEXMFHOME variable by adding export $TEXMFOME=~/texmf to my .bashrc file. This is necessary so that latex and tex and lyx can find.

  • The TeX Distribution's Environment Variables
    These variables are referred to in texmf.cnf. If these variables are not set, they can be added to the user's .bashrc
  • The TeX Distribution's Environment Variables
    The most important variable set in the .bashrc required for adding a latex files to the user's TeX tree.
The TeX Distribution's Environment Variables
These variables are referred to in texmf.cnf. If these variables are not set, they can be added to the user's .bashrc

Procedure

Add the LaTeX Class to the TeX (texlive) Installation

  1. Make a directory ~/texmf.
    mkdir ~/texmf
  2. Create paths in ~/texmf for our new files needed for the new LyX layout, reproducing the main systemwide TeX distribution's directory structure, in the case of Manjaro -- /usr/share/texmf-dist.
  3. mkdir ~/texmf/bibtex/bst/new-aiaa/,
    mkdir ~/texmf/tex/latex/new-aiaa/,
  4. Place our new files in these locations -- the bst file in ~/texmf/bibtex/bst/new-aiaa/ and the cls file in ~/texmf/bibtex/bst/new-aiaa/
  5. Run texhash from a terminal.
    texhash,
Files Added to the User's TeX Tree
The LaTeX files distributed by the publisher added to the user's TeX tree.

Procedure

Add the LaTeX Class to the TeX (texlive) Installation

For Lyx to be able to use this newly installed LaTeX class, a corresponding Lyx .layout file needs to be created with the same name as the class. Again I chose to make this file available per user instead of systemwide, placing the file in ~/.lyx. The .layout file can also be conveniently be placed in the same folder as the document being prepared.

I found the it difficult to add all of the neccessary elements to the layout file as I didn't have the necessary knowledge, but produced a working layout file conforming to the publisher's requirements using the following procedure, which was made possible by the fact the AIAA distributes a sample document that uses the class and bibliography files.

  1. Edit the document metadata specific elements of the sample file. In my case I edited the \title, \author, and \affil parameters of the sample document.
  2. Cut the top part of the sample .tex document, making sure it remains available in the desktop environment's clipboard.
  3. Use Lyx's File > Import > Latex (clipboard) function and select the remaining portion of the sample .tex file.
  4. With the new LyX document displayed use Document > Settings to select Latex Preamble and paste the portion of the sample .tex file previously cut.
  5. Some of the declarations in the file may be redundant because the class specifies them as default. Comment out the duplicates.
  6. Then in LyX select LyX > Settings > Reconfigure.

    References

    LyX Configuration Manual Section 5.

    blog comments powered by Disqus