Emacs, how to auto turn on flyspell for LaTeX file
Asked Answered
F

2

3

I use Emacs only for \LaTeX and python programming. Is there a way to automatically turn on flyspell-mode when I work on a .tex file, and turn on flyspell-prog-mode when I work on a .py file? How can I do this in my .emacs file?

Fonsie answered 2/3, 2013 at 9:41 Comment(0)
D
11

Add those functions to hooks of python-mode and latex-mode

(require 'python)

;; If you use tex-mode
(require 'tex-mode)`
(add-hook 'latex-mode-hook 'flyspell-mode)

;; If you use AUCTeX
(load "auctex.el" nil t t)`
(add-hook 'LaTeX-mode-hook 'flyspell-mode)


(add-hook 'python-mode-hook 'flyspell-prog-mode)
Dah answered 2/3, 2013 at 11:8 Comment(6)
Thanks for your help. I added your code to the end of my .emacs file but it didn't work. I updated my question with my entire .emacs file, could you tell where I went wrong?Fonsie
Can you confirm that python-mode is running when you open a python file? If it is on then the above add-hook should work just fine. I don't think you need to (require 'python) after you have already (require 'pyhthon-mode).Phobos
@Phobos Yes, python-mode is running when I open a python file. This is really strange, your method is not working for me.Fonsie
@Fonsie thanks for fixing my typo. But your fix is something wrong. You should write 'latex-mode-hook, not 'LaTeX-mode-hook. Please write correctly and retry.Dah
@jrichter, That's strange, on my computer it's actually LaTeX-mode-hook, that's how I got it working. Lower case did not work. Maybe it's the emacs version? I'm using GNU Emacs 24 for Windows.Fonsie
@Fonsie Sorry, you should use LaTeX-mode-hookif you use AUCTeX, but you should use latex-mode-hook if you use tex-mode(standard package). And you should load before add-hook AUCTeX if you use AUCTex.Dah
L
0

Something like this should work.

(setq auto-mode-alist (cons '("\\.tex\\'" . flyspell-mode) auto-mode-alist))
(setq auto-mode-alist (cons '("\\.py\\'" . flyspell-prog-mode) auto-mode-alist))
Lina answered 2/3, 2013 at 10:35 Comment(1)
This method works, it turned on the flyspell but it completely turned off the syntax highlighting, and it does not recognize non-word such as math equations and things like \emph{}. It marked them all as typos.Fonsie

© 2022 - 2024 — McMap. All rights reserved.