Endless Parentheses

Concise ramblings on Emacs productivity.

Improving LaTeX equations with font-lock

It’s difficult for me to spend much time interacting with a major-mode and not find something to tweak. Even when that mode is my oldest companion in the world of Emacs, something will surely pop up. So it’s only fitting that in the final week of my thesis submission deadline I start tinkering with latex-mode again.

I wrote the following snippet after compiling a recent Emacs snapshot which defines a myriad of rules for prettify-symbols-mode in tex-mode. Equations become much easier to read when you replace the verbose math symbols like \alpha with α, but that only makes all the LaTeX styling commands stand out even more. Suddenly, all those \left, \right, \! and \;, are sticking out like that mole on a hag’s nose.

What do we do about that? We hide them away. Not completely, of course. We still need to see those commands. We just tuck them away a little, where we can see them without having to see them.

(defface endless/unimportant-latex-face
  '((t :height 0.7
       :inherit font-lock-comment-face))
  "Face used on less relevant math commands.")

(font-lock-add-keywords
 'latex-mode
 `((,(rx (or (and "\\" (or (any ",.!;")
                           (and (or "left" "right"
                                    "big" "Big")
                                symbol-end)))
             (any "_^")))
    0 'endless/unimportant-latex-face prepend))
 'end)

Here’s a sample of what it might look like for you.

latex-unimportant-font-lock.png

Tags: font-lock, latex, init.el, emacs

Say thanks on Gratipay
comments powered by Disqus