7

When using flyspell in emacs, it can be useful to configure flyspell to ignore the contents of certain environments, e.g. tikzcd or tikzpicture.

For example, in the document below one would like to flyspell to ignore the word "asdf" inside the environment myenv.

\documentclass{standalone}

\newenvironment{myenv}{}{}

\begin{document}

\begin{myenv}
  asdf
\end{myenv}

\end{document}

How to achieve this?

1 Answer 1

6

Adding the following code to your ~/.emacs file tells flyspell to ignore the content of the environments myenv1, myenv2 and myenv3:

(put 'LaTeX-mode 'flyspell-mode-predicate 'auctex-mode-flyspell-skip-myenv)
(defun auctex-mode-flyspell-skip-myenv ()
  (save-excursion
    (widen)
    (let ((p (point))
          (count 0))
      (not (or (and (re-search-backward "\\\\begin{\\(myenv1\\|myenv2\\|myenv3\\)}" nil t)
                    (> p (point))
                    (or (not (re-search-forward "^\\\\end{\\(myenv1\\|myenv2\\|myenv3\\)}" nil t))
                        (< p (point))))
               (eq 1 (progn (while (re-search-backward "`" (line-beginning-position) t)
                              (setq count (1+ count)))
                            (- count (* 2 (/ count 2)))))))))
  )
(add-hook 'LaTeX-mode-hook (lambda () (setq flyspell-generic-check-word-predicate 
                        'auctex-mode-flyspell-skip-myenv)))

One can append environments as necessary in lines 7 and 9 simultaneously.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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