Duck, Duck, Gnu: Mallard and DocBook 5 support in EmacsPublished on 2010-08-29
Edit: I recommend checking out Paul Frields' post about Emacs and nXML mode, and also looking at the Fedora wiki page that he created. I think his approach is a bit simpler and cleaner than what I've provided below. Feel free to peruse what I've written, though, as some of my links to "getting started" references should still be helpful.
I've been doing some documentation work with Mallard and DocBook 5 recently, and have been looking for software that supports them well. The trick is that both Mallard and DocBook 5 are based on RelaxNG schemas, and while there are many XML tools out there, there are few that are open source, and fewer still that support RelaxNG.
After perusing my options, I decided to try Emacs with nXML-mode. Emacs' nXML-mode provides real-time validation for RelaxNG-based documents, something which no other open source authoring tool provides. But while nXML-mode can validate XML documents on-the-fly, the default installation is not set up to validate against the recently-developed Mallard and DocBook 5 schemas.
Thus, to take full advantage of the latest in duck-[based](http://www.docbook.org/tdg5/en/htm l/docbook.html) documentation technologies, I needed to modify my .emacs file and the nxml-mode files themselves. What follows is an overview of exactly what I did in the hopes that others can make use of the same changes, too.
An nXML-mode foundation
Before we get started, though, you should know that much of what follows is derived from information on this website. I encourage you to visit the site, as it provides an introduction to how nXML-mode is configured, and enough of an introduction to using nXML-mode to make you at least modestly productive right away.
Part One: Setting up your .emacs file
The first step in setting up nXML-mode for Mallard and DocBook 5 is to make a few changes to your .emacs file. If you are new to Emacs, your .emacs file sits in your home directory, and serves as a personalized Emacs configuration file. You may need to create the .emacs file if it doesn't already exist.
The above .emacs configuration tells Emacs where to look for detailed XML processing instructions, and also causes Emacs to automatically use nXML-mode for XML-related files. (Did I tell you that Emacs might have a bit of a learning curve? Yeah, that's true.)
Part Two: Modifying the nXML-mode configuration files
The second step is to modify the nXML-mode configuration files themselves. This will add the appropriate nXML-mode secret sauce to handle Mallard and DocBook 5 documents.
Fortunately for you, I grabbed the latest nXML-mode source files from the nXML-mode website, and made the appropriate modifications myself. You can download my customized nXML-mode files from this archive.
Here's what I changed from the default setup:
- I added the docbookxi.rnc and mallard-1.0.rnc schemas to the schemas directory
- I modified the schemas.xml file, thus including the docbookxi.rnc and mallard-1.0.rnc schemas as part of the XML-validation process.
Note that I have used the DocBook 5 "docbookxi.rnc" schema which allows for xinclude functionality. If you want to use the schema that does not allow for use of xinclude features, you'll need to adjust the files accordingly. The current DocBook 5 schemas are available here.
Part Three: Copy your nXML-mode files to the proper location
The final step is to copy the nXML-mode files to the proper location on your file system. As indicated in our .emacs file, that location is: /usr/share/emacs/site-lisp/nxml/. Thus, you should copy all of the files in the downloaded "nxml" folder into that directory. You will need administrative privileges (using root or sudo) to do this.
That's it, though. You should now have a functioning nXML-mode environment that will allow you to fire-up Emacs and start writing Relax-NG-based documents, getting all of the real-time-validation features that Emacs provides. If you can think of any ways in which I could improve my approach, please let me know. Otherwise, I encourage you to head-on over to the nXML-mode website, and view some of the nXML-mode information and resources that are available as you get started.