Tell me more ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm using the following configuration for aspell in my .emacs file

(setq ispell-program-name "/opt/local/bin/aspell")
(setq ispell-list-command "list")
(setq ispell-extra-args '("--dont-tex-check-comments"))

and my ~/.aspell.conf contains the following line

add-tex-command bibliographystyle p

trying this latex file:

\documentclass{article}
\begin{document}
\bibliographystyle{plainnat}
\end{document}

emacs flyspell mode shows me plainnat as an error.

enter image description here

When I invoke aspell from the command line with the following command

aspell --dont-tex-check-comments -c ~/test.tex

it shows no errors. Flyspell does not seem to use aspell or the aspell config. How can I change this in such a manner that I only have to maintain one config for my spell checking needs and not have an extra config for flyspell?

share|improve this question
When I try your test case aspell --dont-tex-check-comments does show "plainnat" as a spelling error. This seems correct seeing that plainnat is not a TeX comment. To ignore plainnat properly the spell checker would need to be able to differentiate between e.g. \bibliographystyle and \emph and ignore the content of the former but not the latter. If it matters I am using International Ispell Version 3.1.20 (but really Aspell 0.60.7-20110707). – N.N. Jun 28 '12 at 14:24
To clarify this a little more: aspell is able to ignore tex commands. This is what the "add-tex-command bibliographystyle p" line does. This line excludes the first parameter of bibliographystyle from the spellcheck. Which is does when I invoke aspell from the commandline but not during a flyspell run. – Kungi Jul 3 '12 at 11:42

1 Answer

up vote 6 down vote accepted

Flyspell uses a mode-specific function called flyspell-generic-check-word-predicate to identify areas to ignore when highlighting spelling errors. This is slightly more involved than normal customizations.

As I understand it, there are three steps. First, set the flyspell-mode-predicate property of LaTeX-mode to the name of your custom function. Second, define a function that will return t when point is on a word you want to ignore. Third, add a hook to LaTeX-mode to define flyspell-generic-check-word-predicate to use this new function whenever you enter LaTeX mode.

(The order doesn't really matter, so long as all three steps are done before you open a latex file.)

If you don't know elisp, that probably doesn't make much sense to you. Adding the following to your .emacs file and restarting Emacs should solve the problem. If you want to add additional regions to ignore, the part to play with is the (save-excursion ... ) form.

(put 'LaTeX-mode 'flyspell-mode-predicate 'auctex-mode-flyspell-verify)
(defun auctex-mode-flyspell-verify ()
  "Function used for `flyspell-generic-check-word-predicate' in auctex mode."
  (save-excursion
    (forward-word -2)
    (not (looking-at "bibliographystyle{"))))

(add-hook 'LaTeX-mode-hook
  (lambda () (setq flyspell-generic-check-word-predicate    
    'auctex-mode-flyspell-verify)))            
share|improve this answer
Why are you using the (forward-word -2) here? Where is the point exactly when this function gets invoced? – Kungi Jul 25 '12 at 9:29
(forward-word -2) backs up to the beginning of the previous word. -1 backs up to the beginning of the current word. The point is to see if the previous word is bibliography style. If it is, don't flyspell the current word. Most of the work is done behind the scenes by flyspell. – Tyler Jul 25 '12 at 11:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.