12

I have recently been trying to use the breqn package to automatically break up my equations. However, I use emacs (and/or Aquamacs, depending on the machine I'm on) with Auctex, and it does not recognize these environments as math environments which is a bit of a headache.

Is there a list somewhere or a lisp command I can put in a .emacs file that tells auctex to recognize the math environments introduced by breqn as math environments?

11

You can tell auctex about additional math environments using LaTeX-add-environments. For example, I sometimes use math environments named thm, prop, lem, cor, defn, not, rem, ex, notation, and equation*, and I tell auctex about them with the following lines in my .xemacs/init.el file:

(add-hook 'LaTeX-mode-hook 'add-my-latex-environments)
(defun add-my-latex-environments ()
  (LaTeX-add-environments
   '("thm" LaTeX-env-label)
   '("prop" LaTeX-env-label)
   '("lem" LaTeX-env-label)
   '("cor" LaTeX-env-label)
   '("defn" LaTeX-env-label)
   '("not" LaTeX-env-label)
   '("rem" LaTeX-env-label)
   '("ex" LaTeX-env-label)
   '("notation" LaTeX-env-label)
   '("equation*" LaTeX-env-label)))

Edit: In addition, here's some code suggested by thequark to have proper syntax highlighting for the dmath environment under auctex, plus a couple of other improvements:

(add-hook 'LaTeX-mode-hook 'add-my-latex-environments) 
(defun add-my-latex-environments () 
  (LaTeX-add-environments 
     '("dmath" LaTeX-env-label))) 

;; Code I added to make syntax highlighting work in Auctex 

(custom-set-variables 
 '(font-latex-math-environments (quote  
     ("display" "displaymath" "equation" "eqnarray" "gather" "multline"  
      "align" "alignat" "xalignat" "dmath"))) 
  '(TeX-insert-braces nil)) ;;Stops putting {} on argumentless commands to "save" whitespace 

;; Additionally, reftex code to recognize this environment as an equation 
(setq reftex-label-alist 
  '(("dmath" ?e nil nil t))) 
  • Thanks! This is definitely a step in the right direction; Now LaTeX recognizes the environments, but they still don't show up highlighted for math (and backtick-a still outputs \alpha{} not \alpha, so auctex thinks I'm inserting text, not math). Is there a way to have auctex recognize these environments as math? – qgp07 Sep 5 '11 at 17:09
  • I had to had a few more lines to get this to work as a math environment. If you edit your answer to include these lines of code, I'd be happy to accept it. (This example is for dmath in particular.) gist.github.com/1195737 – qgp07 Sep 5 '11 at 19:37
  • Thanks a lot, guys! One more thing though: how can I make preview (C-c C-p C-b) to recognise the environment and show the typeset text over the environment, not below it? – honey_badger Aug 1 '17 at 22:53
1

If you want the environment to be recognized by texmathp (used for instance by company-auctex), you can do it the following way.

(add-to-list 'texmathp-tex-commands '("breqn" env-on))
(texmathp-compile)
  • Thanks for this. I needed to modify your code a bit to get it to work: (add-hook 'LaTeX-mode-hook #'(lambda () (texmathp-compile))) (custom-set-variables '(texmathp-tex-commands (append texmathp-tex-commands-default '(("breqn" env-on))))). – Edward H Sep 17 '17 at 17:46

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.