2

With AucTeX, one can insert many LaTeX commands using shortcuts.

For example in a math environment (e.g., between $ $), the shortcut `g insert \gamma. Normally right after \gamma if I would like to type a letter I should make a space, for example $\gamma a=1$, but if I would like to type a number, a symbol or another latex command, it is not necessary, for example $\gamma\alpha=1$ or $\gamma*1=\gamma$ or $\gamma1=\gamma$, or $\gamma^1=\gamma$.

Is there a way in AucTeX to insert a space right after a latex command (inserted by an AucTeX shortcut, e.g. `g) if the next keystroke is a letter?

I think this can significantly increase the speed of typing, because the space should be inserted anyway.

I have added the requirement inserted by an AucTeX shortcut to avoid the complicated situations like \leq and \leqslant.

1
  • Here is a rough idea for a solution: Put a function on post-self-insert-hook. The function should examine last-command, and if it is whatever auctex uses to expand shortcuts, it should examine the character just inserted and optionally insert a space in front of it. Commented Oct 30, 2016 at 11:42

1 Answer 1

2
 (defun my-insert-space-if-alnum (orig-func &rest args) "Insert an extra space if the char read is alphabetical or a number." (let ((c (read-char))) (when (memq (get-char-code-property c 'general-category) '(Ll Lu Nd)) (insert ?\ )) (insert c))) (dolist (f '( LaTeX-math-alpha LaTeX-math-beta LaTeX-math-delta LaTeX-math-Delta LaTeX-math-epsilon LaTeX-math-phi LaTeX-math-Phi LaTeX-math-gamma LaTeX-math-Gamma LaTeX-math-eta LaTeX-math-theta LaTeX-math-Theta LaTeX-math-kappa LaTeX-math-lambda LaTeX-math-Lambda LaTeX-math-mu LaTeX-math-nu LaTeX-math-nabla LaTeX-math-pi LaTeX-math-Pi LaTeX-math-chi LaTeX-math-rho LaTeX-math-sigma LaTeX-math-Sigma LaTeX-math-tau LaTeX-math-upsilon LaTeX-math-Upsilon LaTeX-math-omega LaTeX-math-Omega LaTeX-math-xi LaTeX-math-Xi LaTeX-math-psi LaTeX-math-Psi LaTeX-math-zeta )) (advice-add f :after #'my-insert-space-if-alnum)) 
1
  • This works well for the commands in the list, would be nice if it would be possible to detect the command manually in order to not miss something like like \rightarrow. But this is a very good step toward a complete solution. Commented Nov 4, 2016 at 16:51

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.