The Ispell and Aspell Command Line Spellcheckers SPELLING LESSON
Total Page:16
File Type:pdf, Size:1020Kb
Command Line: Ispell and Aspell LINUXUSER The Ispell and Aspell command line spellcheckers SPELLING LESSON www.sxc.hu Nobody is safe from typos and jumbled up words. Spellcheckers like Ispell and Aspell keep the letters in the right places. BY HEIKE JURZIK pellcheckers in office packages strate how to call both Ispell and Aspell coded, define a character set using the -T and mail programs help find while working with the Vim and option. Stypos and suggest alternative (X)Emacs editors. There is no need to specify the diction- spellings. Ispell and Aspell proofread ary and character set options each time your files at the command line, and, al- Simply Ispell you run the program; instead you can though they can’t replace a good diction- Ispell runs interactively at the command add appropriate entries to the ~/.bashrc ary, they are extremely reliable helpers. line. If the spellchecker finds an error, it Bash configuration file in your home Ispell is a mature application that has suggests an alternative spelling. If you directory: been on various Unix derivatives for decide not to accept the suggestion, you many years now. The GNU project intro- can add the word to your personal dic- export U duced Aspell as a potential successor. tionary, or just ignore the term for the DICTIONARY=dictionary name Aspell comes with dictionaries for vari- rest of the document. export U ous languages and can handle UTF-8 (in The simple command syntax is CHARSET=character set contrast to Ispell). This article shows you how to proof- ispell filename Then reparse the configuration file using read at the command line. I’ll describe the following command: some tips and tricks, and I’ll demon- You may need to run Ispell with the -d (for “dictionary”) option, depending on source ~/.bashrc Command Line the dictionary you need. A quick glance at the /usr/lib/ispell directory (Figure 1) Interaction Required Although GUIs such as KDE or GNOME are useful for various tasks, if you intend tells you which dictionaries are available Ispell uses the top line to display un- to get the most out of your Linux ma- on your system. You should see a num- known words. If the spellchecker finds chine, you will need to revert to the ber of dictionaries with the .aff suffix – similar words in the dictionary, it gives good old command line from time to Ispell uses these dictionaries to manage you an enumerated list of the alternative time. Apart from that, you will probably hyphenation and accented characters in words (Figure 2). To accept one of these be confronted with various scenarios the various languages. suggestions, simply press the key for the where some working knowledge will be Some Linux distributions use different number that appears with the word in extremely useful in finding your way names for the dictionaries. To make sure the enumerated list to tell Ispell to re- through the command line jungle. that special characters are correctly en- place the word. WWW.LINUX - MAGAZINE.COM ISSUE 63 FEBRUARY 2006 85 LINUXUSER Command Line: Ispell and Aspell Figure 1: The Ispell on our lab machine understands British and US English. Figure 2: Ispell offers similar words as alternatives. If you do not want to replace the word actually specifying the option for creat- .html or .htm suffix as an HTML file. In that Ispell thinks is wrong, you can ei- ing a backup copy. This is sometimes the this case, the spellchecker ignores any ther press the space key to ignore the default behavior as specified by the HTML tags it discovers during the spell- word once, press [A] to ignore the word package maintainer. If prefer not to cre- checking session. The only exception is for the rest of the Ispell session, or press ate backup copies, you can disable this the ALT attribute, which you can use to [I] to store the word permanently. In the feature by setting the -x flag. define alternative text for an embedded latter case, Ispell adds the term to your image. personal dictionary. Other Formats If the file suffix is missing or in capi- Your personal word lists are stored as Ispell has the ability to spellcheck the tals (.HTM), you can tell Ispell that the hidden files in your home directory. The HTML and TeX/ LaTeX formats in addi- file is HTML when launching the pro- filename is made up of .ispell_ and the tion to text files. The spellchecker auto- gram: name of the dictionary you used. For ex- matically identifies any file with the ample, if you were working with the ispell -H file.HTM ngerman dictionary, your personal word Spellcheckers in list would be .ispell_ngerman. Vim and Emacs The same thing applies to XML and If Ispell discovers an error but does Ispell and Aspell run in the background SGML files: pass the -H option to the not give you a (reasonable) alternative, in many KDE and Gnome applications, program when launching Ispell to tell you can press [R] (for “replace”) and and will check your documents at a click. the spellchecker to ignore tags when type your changes at the prompt. Ispell But it is quite easy to talk Vim and spellchecking. (Some distributions, such replaces the word throughout the text. (X)Emacs into cooperating. as Debian, use -h (with a lowercase “h”) A single line in the Vim configuration file for this option, whereas others, such as The End of the Story (~/.vimrc) gives you a macro. To map a Suse, use a capital -H.) Ispell quits after spellchecking, but you function key [F10] to the spellchecker, Ispell identifies TeX-/ LaTeX files by can alternatively press [Q] to quit the add the following line to the file for reference to the .tex file suffix and does Ispell: spellchecker and discard any changes. not spellcheck formatting instructions. Ispell will prompt you to determine if map <F10> :w!<CR>:U Ispell uses backslash, which normally you really do want to discard the !ispell %<CR>:e! %<CR> introduces control sequences in the lay- changes. You can then press either [Y] to If you prefer Aspell, use the following out system, to identify formatting, how- quit the program or [N] to carry on spell- entry instead: ever, text in curly brackets is spell- checking. The alternative is to press [X] checked. The spellchecker identifies map <F10> :w!<CR>:U to quit Ispell, but store any changes you have made. !aspell -c %<CR>:e! %<CR> Heike Jurzik studied Place any command line options you German, Computer Creating Backups need after the command. Science and English Ispell gives you a safe option if you spec- If you use Emacs or Xemacs, add the fol- at the University of Cologne, Germany. ify the -b parameter when launching the lowing line to the configuration file (~/. She discovered program. This tells the spellchecker to emacs or ~/.xemacs/custom.el): Linux in 1996 and (setq-default U create a backup for each file it checks. has been fascinated The backup copies are identifiable by a ispell-program-name "aspell") with the scope of the Linux com- .bak or ~ suffix and contain the original THEAUTHOR or: mand line ever since. In her leisure text. time you might find Heike hanging (setq-default U Many distributions have versions of out at Irish folk sessions or visiting Ispell that create backups without you ispell-program-name "ispell") Ireland. 86 ISSUE 63 FEBRUARY 2006 WWW.LINUX - MAGAZINE.COM Command Line: Ispell and Aspell LINUXUSER comments, which are escaped with the can use your package manager to install dictionaries below your home directory, percent character (%) in TeX-/ LaTeX the missing resource. Just like in Ispell, and – in a similar approach to Ispell – it files, and checks them for typos. you can use the -d option to specify a uses a combination of the word .aspell. dictionary. If you have a UTF-8 encoded and the current dictionary to identify the Aspell Alternative text, don’t forget to let Aspell know by file. Aspell is an alternative spellchecker for specifying --encoding=utf-8. Aspell also quits automatically after the command line. This program is the completing the spellcheck. You can press designated successor for Ispell, and it al- Interaction Required [X] to quit the program and store any ready offers a lot more. For example, the Aspell highlights unknown terms and changes you have made up to that point. current versions (0.60.x) support the gives you a numbered list of suggested To quit the spellchecker and discard your UTF-8 character set. The generic syntax replacements. To accept a suggestion, changes, press [B] and confirm when is as follows: press the appropriate number and press prompted. [Enter]. aspell -c filename If you need to replace a word with a A Question of Format completely different word, press [R] and Just like Ispell, Aspell supports various It is not typically necessary to explicitly type the replacement for the word you file formats. You can specify the -H (for specify a dictionary, as Aspell evaluates are replacing. In contrast to Ispell, this HTML/ SGML/ XML) or -t (for TeX/ your language settings. However, if you option in Aspell only replaces the cur- LaTeX). see an error telling you the correct dic- rent instance of the word. If you want If you would like to migrate to the tionary could not be found, you might Aspell to replace all instances of the newer spellchecker, the Aspell package like to check if you really have the nec- word in the document, you need to press includes a Perl script titled aspell-import essary dictionary installed on your sys- [Shift]+[R] instead.