Take the 2-minute tour ×
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.

It is possible to make AUCTeX load the spelling dictionary of the language which babel is loaded with. One further convenience would be for it to appropriately react to changes of language within a document. Such changes can be made with macros of babel and csquotes. So, is it possible to make AUCTeX spell check in the correct language according to the language macros of a document?

Here follows a test document. A solution would make AUCTeX automatically spell check the first paragraph in English and the other paragraphs should be spell checked according to the specified language.

\documentclass{article}

\usepackage[danish,english]{babel}
\usepackage{csquotes}

\begin{document}

In computing, a spell checker (or spell check) is an application
program that flags words in a document that may not be spelled
correctly.

\foreignquote{danish}{I computerterminologi er en stavekontrol en
design feature eller et software program designet til at tjekke
stavningen af ord i et dokument og som normalt kan komme med forslag
til stavningsforslag.}

\hyphenquote{danish}{I computerterminologi er en stavekontrol en
design feature eller et software program designet til at tjekke
stavningen af ord i et dokument og som normalt kan komme med forslag
til stavningsforslag.}

\foreignlanguage{danish}{I computerterminologi er en stavekontrol en
design feature eller et software program designet til at tjekke
stavningen af ord i et dokument og som normalt kan komme med forslag
til stavningsforslag.}

\begin{hyphenrules}{danish} I computerterminologi er en stavekontrol
en design feature eller et software program designet til at tjekke
stavningen af ord i et dokument og som normalt kan komme med forslag
til stavningsforslag.
\end{hyphenrules}

This sentence should be spell checked with an English dictionary.

\end{document}
share|improve this question
    
I do not use Emacs nor I type these days in any other language than English but I think this a very interesting question. Personally, I use ispell and a custom key binding to call it from nvi to do spell checking interactively (I like to confirm changes). Basically what you are asking is much more sophisticated script which will terminate ispell when Danish is encountered change default dictionary to Danish and continue spelling. I will ask my CS students to try to come up with something. –  Predrag Punosevac Jan 14 '12 at 3:04
    
@PredragPunosevac I would also like for it to work with fly spell because that what I currently use for spell checking. Would appreciate any lead on this issue. Make answering my question your students' home work! –  N.N. Jan 14 '12 at 17:00
    
I am not sure about the homework but a small project yes. Emacs is written in Lisp so they will have to hack Lisp code not shell script as I described for nvi but I think it should be duable. –  Predrag Punosevac Jan 14 '12 at 17:09
    
I think this is rather difficult. I could imagine to advise ispell-region accordingly, but, probably, the only way to go is to use a spell checker backend providing this – certainly useful – feature. –  mhp Mar 28 '12 at 19:09
    
@mhp Why so pessimistic? Given Emacs extensibility I think it is very possible. It is just a matter of coming up with an appropriate logic and implementing it. One way would be for flyspell to start spell checking in some default language then change dictionary every time there is some babel expression changing language. This seems doable as long as you can come up with the right lisp code to recognize the babel expressions, i.e. some regular expressions. –  N.N. Mar 28 '12 at 19:25
show 1 more comment

1 Answer 1

up vote 6 down vote accepted

Assuming you are using flyspell, yes it is possible!

The package flyspell-babel.el should do exactly what you want : read inline language changes for babel, and start a flyspell process for that language.

According to the documentation :

The parsing done by this package has its limits limited, and so it will not work with arbitrary LaTeX code. I hope that these restrictions will not in practice impinge on the typical usage of most people. The first language declaration is usually determined by the final language option passed to the babel \usepackage command, which takes effect after \begin{document}. Thereafter, you can switch the declared language with \selectlanguage statements, otherlanguage environments, and \foreignlanguage commands. You can also define your own language-switching commands, and register these with flyspell-babel.

Therefore, you may have to make your other language change commands, such as \foreignquote, known to flyspell-babel.

This package requires the package flyspell-multi.el to start several flyspell processes at the same time, to avoid slowdowns when scrolling through a file with language changes.

Installation instructions

Put the files flyspell-babel.el and flyspell-multi.el somewhere in the load-path and add the following lines to your .emacs:

(autoload 'flyspell-babel-setup "flyspell-babel")
(add-hook 'latex-mode-hook 'flyspell-babel-setup)

To add support for other commands, add the following lines to your .emacs:

(add-to-list 'flyspell-babel-command-alist ("hyphenquote" "hyphenquote"))
(add-to-list 'flyspell-babel-command-alist ("foreignquote" "foreignquote"))
(add-to-list 'flyspell-babel-environment-alist ("hyphenrules" "hyphenrules"))

All credit goes to the author of these two packages.

share|improve this answer
    
Your answer would be even better if you also provided descriptions on how install and use the packages. –  N.N. Nov 10 '12 at 16:02
    
@N.N. Instructions can usually be found in the comments of the .el file, but you are right, I might as well post them in the above. –  T. Verron Nov 10 '12 at 16:28
    
I tried your installation instructions and it works for \foreignlanguage in my example but neither of the other macros. Perhaps you could include instructions on how to cover them as well. –  N.N. Nov 10 '12 at 16:57
    
@N.N. I editted my answer with what I think will work, but I'm not pro at elisp, and I don't have flyspell on this computer to try out myself... I think the syntax should be more or less correct, but it may miss a few quotes or parentheses. –  T. Verron Nov 10 '12 at 17:34
add comment

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.