# Text Editors

## For advanced writers

The tools outlined in this section allow you to work with the DocBook tags directly. If you are not comfortable working with markup languages you may want to use a word processor instead. Word processors that support DocBook are described in .

If you are comfortable working with markup languages and text editors, you'll probably want to customize your current editor of choice to handle DocBook files. Below are some of the more common text editors that can, with some tweaking, handle DocBook files.

&configure-emacs;

## nedit

http://sourceforge.net/projects/nedit/

To be fair, nedit is more for programmers, so it might seem a bit of overkill for new users and especially non-programmers. All that aside, it's extremely powerful, allowing for syntax highlighting. nedit doesn't allow you to automatically insert tags or automatically validate your code. However, it does allow for shell commands to be run against the contents of the window (as opposed to saving the file, then checking).

### nedit screen shot

The nedit program can provide line numbers across the left side of the screen, handy for when `nsgmls` complains of errors

### Using nedit

When you open your DocBook file, nedit should already have syntax highlighting enabled. If it does not you can turn it on explicitly using: Preferences Language Mode SGML HTML

If you have line numbers turned on (using Preferences Show Line Numbers) then finding validation errors is much simpler. nsgmls, the validation tool we'll use, lists errors by their line number.

### Configuring nedit

Since you can feed the contents of your window to outside programs, you can easily extend nedit to perform repetitive functions. The example you'll see here is to validate your document using nsgmls. For more information about nsgmls and validating documents please read .

- Select Preferences Default SettingsCustomize MenusShell Menu.... This will bring up the Shell Command dialog box, with all the shell commands nedit has listed under the Shell menu.

- Under Menu Entry, enter Validate DocBook. This will be the entry you'll see on the screen.

- Under Accelerator, press AltS. Once this menu item is set up, you can press AltS to have the Validate DocBook automatically run.

- Under Command Input, select window, and under Command Output, select dialog.

- Under Command to Execute, enter `nsgmls `-sv``. Using `-v` outputs the version number is output to the screen so that you know the command has run.

  #### Check the PATH

  Note that nsgmls has to be in your `PATH` for this to work properly.

#### Adding shell commands to nedit

- Click OK and you'll now be back at the main nedit screen. Load up an XML file, and select Shell Validate DocBook or press AltS.

- The `nedit` program will fire up and check the contents of the window.

- If all you see is a version number for nsgml then your document is valid. Any errors are reported by line number in your document.

#### nsgmls output on success

If nsgmls reports success, it merely reports the version of nsgmls

## VIM

http://www.vim.org

No mention of text editors is complete without talking about vi. The VIM (Vi IMproved) editor has the functionality of regular vi and includes syntax highlighting of tags.

### Getting Started

There are many versions of vi. New authors will likely want one of the more feature-packed versions for syntax highlighting and a graphical interface including mouse control.

Red Hat users will want the following packages: vim-common, vim-minimal and vim-enhanced. Debian users will want the following package: vim. For an X interface (including GUI menus and mouse control) users will want gvim. The g in gvim is for Graphical.

VIM compiles very easy should you need to build your own. Both `vim` and `gvim` are built by default. Syntax highlighting is included but not enabled by default if you have to start from scratch; use the `:syntax enable` command in VIM to turn this feature on.

### Creating New DocBook XML Files

In both vim and gvim, `.xml` files will be recognized and enter into SGML mode. A series of known DocBook tags and attributes have been entered into vim and will be highlighted one color if the name is known and another if it is not (for this author the colors are yellow and blue).

Having the correct document type declaration at the top of your document should add the syntax highlighting. If you do not see this highlighting you will need to force VIM into SGML mode (even for XML files) using the command `:set ft=sgml`. If you are working with multiple files for a single XML document you can add your document type in <-- comments --> to the top of the file to get the correct syntax highlighting (you will need to restart the program to see the change in highlighting). The top line of this file (`tools-text-editors.xml`) looks like this:

    <!-- <!DOCTYPE book PUBLIC '-//OASIS//DTD DocBook XML V4.2//EN'> -->

### Spell Check

As in Emacs, Vim, will work quite happily with aspell. It can be run from within Vim with the following: `:! aspell -c %`.

For more sophisticated spell check alternatives, give Cream or vimspell a try.

### Tag Completion

The following information is provided by Kwan Lowe.

Vim has a DocBook helper script which can be easily copied into your `.vimscripts` directory and used to auto complete tags while writing DocBook documents. The script can be downloaded from: .

> Grab the file, then untar it. Copy the `dbhelper.vim` to your `.vimscripts` directory if you have one.

>       	$ mkdir .vimscripts
>     	$ cp dbhelper.vim .vimscripts

> You'll also have to convert the `dbhelper.vim` file to unix formatting:

>     	$ dos2unix dbhelper.vim

> Next, edit your `.vimrc` file and add the line: `source /home/yourname/.vimscripts/dbhelper.vim`

> To use the scripts, enter vi and go into insert mode. Press , (comma) followed by the shortcut. For example: `,dtbk`

## XMLForm

This web-based application allows you to put in the URL for XML source, or copy and paste the XML directly into the web form. The application then breaks down your document into a series of form fields that hide the DocBook tags so that you may edit the content directly. Version 5 is available from . This application is best on shorter documents (less than 20 pages printed).

As this is an on-line tool, it will be good for small updates only.

## XMLmind XML Editor (XXE)

David Horton offers the following information:

> I am a big fan of XMLMind's XXE editor and XFC FO converter. It is free as in beer, but not necessarily free as in speech. Very liberal license for personal use however. It's Java-based so it works on all sorts of OS's.