[Tex/LaTex] How to optimize the keyboard for frequent LaTeX input

keyboard

I have started the practice of live-texing my math/physics notes. Although I am not practicising it in a live-lecture, I am doing it for the online lectures I am viewing to get fast and accustomed to it. I am not a pro touch typer, but have a decent speed of about 60 wpm. Some of the tricks I have used are to use lots of \newcommand to ease it down.

Most helpful would be something to substitute equation delimiters that do not involve pressing a dead key. For various reasons (portability to an online CMS) I have begun using \(..\) instead of $..$ the former involves six key strokes and the latter involves three. For the display mode the former style involves four keystrokes while the latter involves five. I would like to accomplish that in a single keystroke. What keyboard shortcuts can I set, or is there something I can do within latex?

Similarly, is it possible to have one keystroke for { ,},_,^ etc?

At present I ignore the delimiters when the lecturer is going really fast, and after the lecture have an extremely buggy and ugly tex file which I have to edit. I would like to have as finished a file as possible. Normal sentences do not pose much of a problem, but the math is slowing me down. I would prefer not to download another keyboard though.

Best Answer

If you're using a good enough editor, you can set up all sorts of things to happen with a single keystroke. For example, I use xemacs, and I have

  • Alt-p (or escape-p) insert a pair of parentheses and put point in between them,
  • alt-m (or escape-m) insert a pair of dollar signs and put point in between them,
  • alt-o (or escape-o) insert a pair of braces and put point in between them,
  • alt-p (or escape-p) insert a pair of parentheses and put point in between them,

plus a few other things. To get out of them, I have alt-j (or escape-j) "jump out" of any of these, i.e., it moves forward until after the first right paren, right brace, or right bracket. I also have the key ^ insert that character along with a pair of braces and put point inside the braces, the key _ insert that character along with a pair of braces and put point inside the braces, and the key [ insert a pair of brackets and put point in between them.

I set this all up in my .xemacs/init.el file; I'll append the relevant part of that file here.

;; Set up my LaTeX-mode keybindings:

(add-hook 'LaTeX-mode-hook 'add-my-latex-keybindings)
(defun add-my-latex-keybindings ()
  (progn
    (local-set-key "[" 'bracket-pair)
    (local-set-key "^" 'superscript-braces)
    (local-set-key "_" 'subscript-braces)))

;;--------------------------------------------------------------------
;;--------------------------------------------------------------------

;; This begins the definitions of our own functions:

;;--------------------------------------------------------------------
;;--------------------------------------------------------------------
(defun dollar-pair ()
  "We insert a pair of dollar signs and position
    point in between them."
  (interactive)
  (progn
    (insert "$$")
    (backward-char)))
;;---------------------------------------------------------------
;;---------------------------------------------------------------
(defun paren-pair (arg)
 "We insert a pair of parentheses and position point in between them.
  If called with an argument, then we insert \"\\bigl(\\bigr)\"
  and position point inside of that."
  (interactive "P")
      (if arg
    (progn
      (insert "\\bigl(")
      (save-excursion (insert "\\bigr)")))
        (progn
          (insert "()")
          (backward-char))))
;;---------------------------------------------------------------
;;---------------------------------------------------------------
(defun brace-pair ()
  "We insert a pair of braces and position
    point in between them."
  (interactive)
  (progn
    (insert "{}")
    (backward-char)))
;;---------------------------------------------------------------
;;---------------------------------------------------------------
(defun bracket-pair ()
  "We insert a pair of brackets and position
    point in between them."
  (interactive)
  (progn
    (insert "[]")
    (backward-char)))
;;--------------------------------------------------------------------
;;--------------------------------------------------------------------
(defun superscript-braces ()
  "We insert a superscript symbol followed by a pair of braces
    and position point in between the braces."
  (interactive)
  (progn
    (insert "^")
    (brace-pair)))
;;--------------------------------------------------------------------
;;--------------------------------------------------------------------
(defun subscript-braces ()
  "We insert a subscript symbol followed by a pair of braces
    and position point in between the braces."
  (interactive)
  (progn
    (insert "_")
    (brace-pair)))
;;--------------------------------------------------------------------
;;--------------------------------------------------------------------
(defun insert-verbatim ()
  "We insert  \\verb\"\" and position point in between the quotes."
  (interactive)
  (progn
    (insert "\\verb\"\"")
    (backward-char)))
;;--------------------------------------------------------------------
;;--------------------------------------------------------------------
(defun jump-out ()
  "We first expand the abbrev before point (if there is an abbrev
    before point), and then we move point forward in the file until we
    pass the first dollar sign, right paren, right bracket, right brace
    or double quote."
  (interactive)
  (progn
    (expand-abbrev)
    (re-search-forward "[])}$\"]")))
;;--------------------------------------------------------------------
;;--------------------------------------------------------------------
(defun fontchange-em ()
  "We insert  \\emph{} and position point before the right brace."
  (interactive)
  (progn
    (insert "\\emph{}")
    (backward-char)))
;;---------------------------------------------------------------
;;---------------------------------------------------------------
;; Key bindings:


(global-set-key "\ej"     'jump-out)
(global-set-key "\C-cj"   'jump-out)
(global-set-key "\em"     'dollar-pair)
(global-set-key "\C-cm"   'dollar-pair)
(global-set-key "\ep"     'paren-pair)
(global-set-key "\C-cp"   'paren-pair)
(global-set-key "\eo"     'brace-pair)
(global-set-key "\C-co"   'brace-pair)
(global-set-key "\en"     'insert-verbatim)
(global-set-key "\C-cn"   'insert-verbatim)
(global-set-key "\ee"     'LaTeX-environment)
(global-set-key "\C-ce"   'LaTeX-environment)
(global-set-key "\ek"     'fontchange-em)
(global-set-key "\C-ck"   'fontchange-em)