In the past few months, I’ve written several articles about the ways LyX can be customized. These included a brief introduction to layout files and how they relate to document classes in addition to a tour of character styles and how you can add them to the LyX local layout. What I have not written about, though, is one of the most important ways of extending LyX, the module.
Ever since version 1.6 of LyX, the core LyX developers have worked very hard to make LyX a modular system. Instead of hard coding values and options – as they had done previously – they’ve instead placed all of the needed information in configuration files that can be edited and modified by users. This is a Very Good Thng. It means that (given enough motivation), you can customize LyX to behave exactly was you wish. You can change the default document classes, styles, fonts and anything else that your little heart desires. It also means that any extensions you create will exist as first-class citizens. They have access to all of the internal wizardry as the default document classes and features.
In order to make this transition work, it was necessary to have certain chunks of code that could be switched on when needed and switched off when not required, and that’s how “modules” were born. In a lot of ways, you might think of modules as document plugins. They let you do stuff that, while not required, can greatly improve your editing experience. (Modules are switched on and off from the “Document Settings” pane.)
They let you do things like run Sweave code, add additional theorem environments, or apply a different style to your text. But unlike a layout file, they are not tied to any particular document class or type; which makes them very powerful. In fact, nearly all of them they can be used with any document type that LyX supports.
There are two main types of modules:
- Modules that contain all of the code needed to implement a particular feature (or modify an existing one) and do not reference external packages.
- Modules that load existing LaTeX styles/packages and translate their features into insets, commands and headings.
In both cases, modules serve as a container for the code. You can use a module to package code that would normally live in a document layout file, or you can use code that might have been placed in the local layout. The code may be a document header, a new LaTeX command, a character style, a custom inset, or any other type of user customization that LyX supports.
The biggest difference between using a module instead of a layout, of course, is that when the code is placed in a module, you can then add it to any document on your system. This makes modules a tremendously flexible way to reuse customizations that you’ve created. In fact, in nearly all cases, they are the best way to package your customizations for use on your own system or for sharing with others.
In this article, I’d like to introduce the module. I will explain its position in the larger LyX/LaTeX “big picture”, its internal anatomy and provide a few examples of how it can be used to add new features.
Show me more… »