12

As pointed out in this answer, using \( and \) in order to enter inline math mode in LaTeX is the recommended practice. However, this takes a bit longer if one compares it to $.

Is there a way to make it quicker when using emacs+auctex? What are you guys doing in order to type it in quicker?

6

I use yasnippet. awesome package for inserting snippets. there is latex snippet bundle you can use. Infact there is already a written snippet to insert exactly what you are asking for.

  • It looks like the one thing I was after. Does the LaTeX bundle include a snippet for \( \) or did you add one manually? I found only the one for \[ and \]... – Dror Sep 5 '11 at 5:43
  • Yes, its already included. I type math and hit TAB. thats it. its dead easy to write a new snippet for your needs. – kindahero Sep 5 '11 at 6:29
  • Thnx! math+TAB generates a \[ \] pair - but I managed to create the snippet I needed! Thnx again. – Dror Sep 5 '11 at 7:18
  • @kindahero I would use a simpler key, as in shorter, for inline math because it may be used very often. – N.N. Dec 30 '11 at 13:59
  • 1
    @kindahero Indeed. I just meant that you might use inline math several times per paragraph and then you will be more effective if you use a short key. – N.N. Dec 30 '11 at 15:30
3

You can setup a key binding in your .emacs file. This definition is based on the one for TeX-insert-braces (C-c{) from tex.el.

(add-hook 'LaTeX-mode-hook
  '(lambda ()
    (define-key TeX-mode-map "\C-cm" 'TeX-insert-inline-math)
    (defun TeX-insert-inline-math (arg)
      "Like TeX-insert-brackes but for \(...\)" (interactive "P")
      (if (TeX-active-mark)
        (progn
          (if (< (point) (mark)) (exchange-point-and-mark))
          (insert "\\)")
          (save-excursion (goto-char (mark)) (insert "\\(")))
          (insert "\\(")
          (save-excursion
            (if arg (forward-sexp (prefix-numeric-value arg)))
            (insert "\\)"))))))
3

As described in its documentation, AUCTeX provides the function TeX-insert-dollar which inserts the two strings of TeX-electric-math and adjusts point position to between those strings when "$" is typed.

The following elisp can be added to a hook on LaTeX-mode to insert "\(" and "\)" then place the point after the opening paren when an unmatched "$" (i.e., the "$" is not closing an existing math environment) is typed:

(add-hook 'LaTeX-mode-hook
          (lambda () (set (make-variable-buffer-local 'TeX-electric-math)
                  (cons "\\(" "\\)"))))
  • Welcome to TeX.SX. What is the difference of your answer to Tilo Wiklund ones? – Stefan Pinnow Sep 18 '17 at 18:06
  • 1
    @StefanPinnow My answer includes a link to the official documentation and includes code to actually implement the suggested solution. – lafrenierejm Sep 18 '17 at 18:08
1

Pressing $ in AUCTeX runs TeX-insert-dollar, the behaviour of which is controlled by the variable TeX-electric-math which can be set to use any pair of symbols instead of the default pair of $.

  • Pressing the dollar sign does no such thing on mine. :( – minibuffer Jul 15 '17 at 19:01

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.