
AUCTEX/emacs 中是否有產生這些轉義括號的捷徑:
“內聯數學環境”的簡寫
\( <cursor here> \)
這將遊標置於這個“迷你環境事物”的中間
這樣我就可以在句子中間寫數學。
我已經嘗試過備忘單和宏,但我無法讓它將遊標留在中間。
歡迎替代方案/提示(我是一名本科生,試圖在業餘時間學習 AUCTEX)
答案1
AUCTeX 為您提供了幾個開箱即用的選項,無需您自己定義函數。它們都在手冊中進行了描述,並且並不相互排斥,您可以同時激活並使用它們
第一的:TeX-electric-math
(add-hook 'plain-TeX-mode-hook
(lambda () (set (make-local-variable 'TeX-electric-math)
(cons "$" "$"))))
(add-hook 'LaTeX-mode-hook
(lambda () (set (make-local-variable 'TeX-electric-math)
(cons "\\(" "\\)"))))
使用此代碼,您只需按一下即可$進入\(...\)
LaTeX-mode
第二:LaTeX-electric-left-right-brace
(setq LaTeX-electric-left-right-brace t)
這樣,您可以鍵入內容\(
,結束語\)
將會新增到點之後。
答案2
為了滿足我所有的配對需求,我使用了一個很棒的套件智慧括號。若要包含您需要的對,請執行以下操作:
首先,安裝(使用 Melpa 或其他)smartparenthesis
然後載入它。我用usepackage
它,但包的作者建議的方法是簡單地運行這個:
(require 'smartparens-config)
重要的程式碼來了:
(sp-with-modes '(tex-mode plain-tex-mode latex-mode)
(sp-local-pair "\\\(" "\\\)"))
請注意,您首先轉義初始的\
,因此:\\
,然後轉義左括號,因此:\(
,這會產生完整的序列:\\\(
。結束語也是如此。
您可以添加所有您心愛的LaTeX
配對。這是我自己的完整配置(部分複製自其他人):
(sp-with-modes '(tex-mode
plain-tex-mode
latex-mode
)
;; math modes, yay. The :actions are provided automatically if
; these pairs do not have global definition.
(sp-local-pair "$" "$")
(sp-local-pair "\[" "\]")
(sp-local-pair "\{" "\}")
(sp-local-pair "‘" "’")
(sp-local-pair "“" "”")
(sp-local-pair "\\begin" "\\end")
;;; tex-mode latex-mode
(sp-local-tag "i" "\"<" "\">")
(sp-local-pair "\\[" nil :unless '(sp-point-before-word-p))
(sp-local-pair "$" nil :unless '(sp-point-before-word-p))
)
答案3
使用 @Phil Hirschhorn 的優秀示例,我創建了一個函數,當您按 Alt-m 時插入“轉義括號”
將其添加到您的
.emacs
M-m
啟用設定
(defun escape-parentheses ()
"we insert escape parenthesis for math-mode
and move the cursor to the center"
(interactive)
(progn
(insert "\\( \\)")
(backward-char 4)
)
)
(global-set-key "\em" 'escape-parentheses)