prettify-symbols-mode is a recent feature of Emacs and it’s very nice. And it looks like it can replace TeX-fold-mode in the future. But, at the time of writing, prettify-symbols-mode doesn’t seem to work well with AUCTeX unless you enable two workarounds together.
- AUCTeX 11.89.7 (latest version from GNU ELPA)
- GNU Emacs 25.1
Usual way to enable pretty symbols
If you want to enable it for elisp buffers, you can add:
(add-hook 'emacs-lisp-mode-hook 'prettify-symbols-mode)
Then something like (lambda () (blah)) in elisp buffers should display as (λ () (blah)).
If you want to enable it also for other lisp buffers, scheme mode buffers etc, you can adjust the following code:
(dolist (mode '(scheme emacs-lisp lisp clojure)) (let ((here (intern (concat (symbol-name mode) "-mode-hook")))) ;; (add-hook here 'paredit-mode) (add-hook here 'prettify-symbols-mode)))
If you want to enable for all buffers, you can add:
And then for major modes of your interest, you may want to adjust the buffer-local prettify-symbols-alist accordingly, following the simple example code you can find from the documentation for prettify-symbols-mode.
Expected way to use with AUCTeX
Following code may be expected to work:
(add-hook 'TeX-mode-hook 'prettify-symbols-mode)
If it works, then \alpha, \beta, \leftarrow and so on should display as α, β, ←, … for TeX file buffers. I do not doubt that it will just work fine in future versions of AUCTeX, and if you are reading this as an old article, it is possible that just upgrading your AUCTeX package may be enough to make that line work as you expected. If it doesn’t work, then try making the following two changes.
Instead of adding to the hook directly, try adding a delayed version, like so:
(defun my-delayed-prettify () (run-with-idle-timer 0 nil (lambda () (prettify-symbols-mode 1)))) (add-hook 'TeX-mode-hook 'my-delayed-prettify)
This way, (prettify-symbols-mode 1) is guaranteed to run after the style hooks and not before. I don’t know what style hooks do, but it looks like they may reset/erase font-lock stuff you have set up.
If pretty symbols still don’t show up in AUCTeX buffers, then try adding the following change, in addition to the above change.
This one isn’t really about adding something. It is about removing. Remove the following line from your dotemacs if any:
tex.el will load anyway if you visit a TeX file with Emacs. This is a strange change to make, indeed.
You should also remove the following line that is commonly used with miktex users:
tex-mik.el is a good small library but tex-mik.el loads tex.el. Feel free to copy parts of tex-mik.el and paste to your dotemacs if you want.
You can ensure you have removed every call of (require ‘tex) from your dotemacs by appending the following line to the end of dotemacs and then restarting Emacs to see if the warning message shows up:
(if (featurep 'tex) (warn "(require 'tex) is still somewhere!"))
If there was some code in dotemacs that relied on the fact that (require ‘tex) was called before, then you have to wrap that code with the with-eval-after-load macro, like this:
(with-eval-after-load 'tex (add-to-list 'TeX-view-program-selection '(output-pdf "SumatraPDF")) (add-to-list 'TeX-view-program-list `("SumatraPDF" my--sumatrapdf)))