[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
austex.el
From: |
Joe Corneli |
Subject: |
austex.el |
Date: |
Mon, 04 Oct 2004 18:12:58 -0500 |
I decided that it would be worth posting my latex-under-emacs
"suite" for other people to take a look at and use if they are
interested. Even though the name of this package sounds like
"AUCTeX", I don't use AUCTeX and this code is independent, and
considerably simpler.
The best thing it has to offer (currently) is a collection of speedy
bindings for lots of things that one needs to type to write math in
LaTeX.
These bindings depend on a modified keyboard layout. For people who
can type on Dvorak keyboards and/or who do their own modifier
remapping, the learning curve for this system should not be too
steep -- and it may make you happy whether or not you are interested
in typing LaTeX. I am appending three sample xmodmap config files
below, and my modifications to the keyboard layout are described in
detail in comments in the elisp file austex-bindings.el.
;;; austex.el -- general latex utilities
;; Copyright (C) 2004 Joseph Corneli <address@hidden>
;; Time-stamp: <jac -- Mon Oct 4 18:03:07 CDT 2004>
;; This file is not part of GNU Emacs, but it is distributed under
;; the same terms as GNU Emacs.
;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published
;; by the Free Software Foundation; either version 2, or (at your
;; option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;; Commentary:
;; This file collects my code for working with LaTeX under Emacs. I
;; use these commands together with LaTeX mode. I tend to have no
;; trouble typing math "in real time", as I take lecture notes for
;; example.
;; Since this file makes available a large number of functions that
;; one needs to be able to select and execute very quickly, the choice
;; of bindings is important (see austex-bindings.el).
;; In order to use these commands and bindings with LaTeX mode, place
;;
;; (add-hook 'latex-mode-hook 'austex-mode)
;;
;; in your .emacs configuration file.
;; Some people might wonder why I don't just use AUCTeX. Other than
;; the simple answer that I think my bindings are better, there are
;; two additional reasons. When I was learning to type math with
;; Emacs, the AUCTeX learning curve seemed too steep. Also, AUCTeX's
;; advertised functionality seemed like overkill for what I wanted to
;; do. Eventually, if I continue to develop this code, I will
;; probably cherrypick things I like from AUCTeX's code. The name of
;; this file is a joke on AUCTeX and AUStin TEXas.
;; Some people are sure to frown on the duplication of effort and the
;; fact that my code is not as nice in many ways. Perhaps others will
;; appreciate the speed and simplicity of the approach I've been
;; using. The speediness probably comes down to choice of bindings.
;; The simplicity is mainly a side-effect of the fact that I haven't
;; made any effort to provide an additional customization layer: if
;; you want to change the way this package works, change the code. No
;; effort has been made to be fully general, so you may well have to
;; do some editing to get this file to do what you want.
;; Thanks to Klaus Berndl for help with the macro evaluation strategy.
;; An alternative approach was suggested by Daniel Pittman, viz.,
;;
;; (dolist (name '("alpha" "beta"))
;; (fset (intern (concat "austex-" name))
;; `(lambda () (interactive) (insert "\\" ,name))))
;;
;; And this is tighter...
;;; History:
;; I decided to revise my LaTeX-under-Emacs code into this
;; "publishable" form following email conversations with Ross Moore
;; about what makes a good LaTeX macro. Many "convenience" LaTeX
;; macros should actually be handled at the editor-macro level. My
;; hope is that this code will be a positive contribution to the
;; development of a tightly integrated and correctly divied up editing
;; environment for mathematical writing.
;;; Future:
;; Specific code requests:
;; Should have a function for converting quickly between displayed and
;; non-displayed equations.
;; General remarks:
;; Hopefully the collection of efficiency-enhancing functions provided
;; here grow over time. With an eye to the distant future, let me
;; mention that I am interested in developing software that can parse
;; and "understand" mathematical writing. Some beginning steps
;; towards linguistic analysis of mathematical writing may
;; (eventually) be included in this package.
;;; Code:
;;; Basic math mode and navigation:
;; The basic pattern "$<math>$" has to be filled in time and again.
;; We provide some simple commands related to this pattern. Note that
;; these should probably be made to work with other math environments,
;; as in auctex's texmathp.el.
;; Some commands to skip _over_ a math environment or a block of text
;; between two math environments would be handy.
(defun austex-math ()
"Insert a matched pair of $$'s and position the point between them."
(interactive)
(insert "$$")
(backward-char 1))
(defun austex-end-of-math ()
"Jump forwards past text, positioning cursor just before the next $."
(interactive)
(search-forward "$")
(backward-char 1))
(defun austex-beginning-of-math ()
"Jump backwards past text, positioning cursor just after the previous $."
(interactive)
(search-backward "$")
(forward-char 1))
(defun austex-out-of-math ()
"Jump past next $ and insert a space (if there isn't one already)."
(interactive)
(search-forward "$")
(just-one-space))
;; these require that you are inside of a "field" to start with. This
;; is not fully general. I'm not sure that they work anyway. These
;; "fields" are something like sexps and perhaps the code for moving
;; around between sexps can be modified to produce the desired effect
;; here.
(defun austex-next-field ()
"Jump to next } or $."
(interactive)
(up-list)
(unless (search-forward "}" nil t)
(search-forward "$"))
(backward-char 1))
(defun austex-previous-field ()
"Jump to previous } or $."
(interactive)
(backward-up-list)
(unless (search-backward "}" nil t)
(search-backward "$")))
;; Even more questionable...
(defun austex-next-bracket ()
(interactive)
(search-forward "{}")
(backward-char))
;;; Environments:
(defmacro austex-define-tex-environment (name)
"Create a function that inserts the TeX environment NAME."
`(defun ,(intern (concat "austex-" name)) ()
(interactive)
(insert "\\begin{" ,name "}")
(newline)
(insert "\\end{" ,name "}")
(beginning-of-line)
(newline)
(backward-char)))
(dolist
(elt '("defn" "eqnarray*" "proof" "quote"))
(eval `(austex-define-tex-environment ,elt)))
;; this is to be used in combination with `mmm-mode' and `multi-task'.
;; the purpose is to have a nice literate programming environment for
;; elisp/whatever. We only get fancy if `mmm-mode' is available
;; however.
(if (require 'mmm-mode nil t)
(defun austex-verbatim ()
(interactive)
(let ((beg (point)))
(insert "\\begin{verbatim}")
(newline)
(insert "\\end{verbatim}")
(let ((end (point)))
(beginning-of-line)
(newline)
(backward-char)
(mmm-parse-region beg (1+ end))))
(message nil))
(austex-define-tex-environment "verbatim"))
;;; Lists:
(defmacro austex-define-tex-list (name)
"Create a function that inserts the TeX list NAME."
`(defun ,(intern (concat "austex-" name)) ()
(interactive)
(insert
"\\begin{" ,name "}
\\item
\\end{" ,name "}")
(search-backward "item ")
(end-of-line)))
(dolist
(elt '("enumerate" "itemize"))
(eval `(austex-define-tex-list ,elt)))
(defun austex-item ()
(interactive)
(newline)
(insert
"%------------------------------------------------------------------*
\\item "))
;;; Greek letters and other simple symbols:
(defmacro austex-define-tex-symbol (name)
"Create a function that inserts the TeX symbol NAME."
`(defun ,(intern (concat "austex-" name)) ()
(interactive)
(insert "\\" ,name)))
(dolist
(elt '("alpha" "beta" "gamma" "delta" "epsilon" "zeta" "eta" "theta"
"iota" "kappa" "lambda" "mu" "nu" "xi" "omicron" "pi" "rho"
"sigma" "tau" "upsilon" "phi" "chi" "psi" "omega" "varphi"
;; Some capital greek letters need nonstandard LaTeX support
"Alpha" "Beta" "Gamma" "Delta" "Epsilon" "Zeta" "Eta" "Theta"
"Iota" "Kappa" "Lambda" "Mu" "Nu" "Xi" "Omicron" "Pi" "Rho"
"Sigma" "Tau" "Upsilon" "Phi" "Chi" "Psi" "Omega"))
(eval `(austex-define-tex-symbol ,elt)))
(defmacro austex-define-tex-symbol-1 (name)
"Create a function that inserts the TeX symbol NAME, followed by a space."
`(defun ,(intern (concat "austex-" name)) ()
(interactive)
(insert "\\" ,name " ")))
(dolist
(elt '("Leftarrow" "Leftrightarrow" "Rightarrow" "Subset" "Supset"
"approx" "cap" "cdot" "cdots" "circ" "cong" "cup" "equiv"
"exists" "forall" "geq" "in" "infty" "int" "ldots" "leq"
"nabla" "ni" "neq" "openset" "otimes" "partial"
"rightarrow" "setminus" "sim" "simeq" "square" "subset"
"supset" "times" "triangle" "vdots" "vee" "wedge"))
(eval `(austex-define-tex-symbol-1 ,elt)))
;; Th openset symbol is part of Unicode now I think, though not yet
;; part of a standardard LaTeX font as far as I know.
;;; Fontification and unary operators:
(defmacro austex-define-tex-unary-markup (name)
"Create a function that inserts the TeX unary markup command NAME.
Examples of such commands are emph, mathop, mathrm, and hat."
`(defun ,(intern (concat "austex-" name)) ()
(interactive)
(insert "\\" ,name "{}")
(backward-char 1)))
(dolist
(elt '("bar" "check" "dot" "emph" "hat" "mathbf" "mathit" "mathop"
"mathrm" "overdoubledot" "text" "tilde"))
(eval `(austex-define-tex-unary-markup ,elt)))
;;; Fancy exponents:
(defun austex-complement ()
(interactive)
(insert "^{\\complement}"))
(defun austex-inverse ()
(interactive)
(insert "^{-1}"))
(defun austex-to-the-star ()
(interactive)
(insert "^{\\star}"))
(defun austex-to-the-ast ()
(interactive)
(insert "^*"))
;;; Math forms to fill in:
(defun austex-exponent ()
(interactive)
(insert "^{}")
(backward-char 1))
(defun austex-subscript ()
(interactive)
(insert "_{}")
(backward-char 1))
(defun austex-langle-rangle ()
(interactive)
(insert "\\langle,\\rangle")
(backward-char 8))
(defun austex-set ()
(interactive)
(insert "\\{\\}")
(backward-char 2))
(defun austex-norm ()
(interactive)
(insert "\\|\\|")
(backward-char 2))
(defun austex-absolute-value ()
(interactive)
(insert "||")
(backward-char 1))
(defun austex-sqrt ()
(interactive)
(insert "\\sqrt{}")
(backward-char 1))
(defun austex-frac ()
(interactive)
(insert "\\frac{}{}")
(backward-char 3))
(defun austex-partial-derivative ()
(interactive)
(insert "\\frac{\\partial}{\\partial }")
(backward-char 1))
(defun austex-derivative ()
(interactive)
(insert "\\frac{d}{d }")
(backward-char 1))
(defun austex-prod ()
(interactive)
(insert "\\prod_{}")
(backward-char))
(defun austex-sum ()
(interactive)
(insert "\\sum_{}")
(backward-char))
;;; Operations on the current equation:
;; The simplest thing is just selecting the text of the current
;; equation. Should add this.
;; Eventually it might be cool to be able to select previous equations
;; by number (like you can do with alternative spellings under
;; ispell). That would involve some fancy work.
;; this macro lets you operate on just the current equation, nothing
;; else. It could do a little bit better checking to see whether or
;; not we are inside an equation according to e.g. fontlock, which
;; tends to do a pretty good job of keeping track of this stuff.
(defmacro austex-narrowed-to-current-equation (&rest args)
"Run ARGS on the current equation."
`(save-excursion
;; this should match one _or_ two $'s
(search-forward-regexp "\\$+")
(let ((end (point)))
(goto-char (match-beginning 0))
(search-backward-regexp "\\$+")
(save-restriction
(narrow-to-region (point) end)
,@args))))
(defmacro austex-narrowed-to-current-equation-excursive (&rest args)
"Run ARGS on the current equation.
Point is allowed to move."
`(progn
;; this should match one _or_ two $'s
(search-forward-regexp "\\$+")
(let ((end (point)))
(goto-char (match-beginning 0))
(search-backward-regexp "\\$+")
(save-restriction
(narrow-to-region (point) end)
,@args))))
(defun austex-turn-current-equation-into-equation-array (&optional prefix)
"Turn a simple equation into an unnumbered equation array.
A non-nil PREFIX argument switches to a full replacement mode for
inequalities. With no prefix, the equal sign is treated as the
only comparison operator. This is to ones advantage e.g. when
greater-than or less-than signs are used inside some of the
members of an equation."
(interactive "p")
(austex-narrowed-to-current-equation
(let ((bs (buffer-substring-no-properties (point-min) (point-max))))
;; replace dollar signs at the beginning and end of the equation
;; with empty string
(delete-region (point-min) (point-max))
(insert (replace-regexp-in-string "\\(^\\$+\\)\\|\\(\\$+$\\)" "" bs)))
(goto-char (point-min))
(insert "\n\\begin{eqnarray*}\n")
(let ((past-first nil))
;; more different equation separators could be added to this list
;; and the regexp could be optimized.
(while (re-search-forward
(if prefix
"\\s-?[=><]\\|\\(\\\\geq\\)\\|\\(\\\\leq\\)\\s-?"
"\\s-?=\\s-?")
nil t)
(if past-first
(replace-match "\\\\\\\\\n&\\&& ")
;; we could be fancy and record the number of characters by
;; which the comparison operator is inserted, then use this
;; number of spaces later on. But it isn't clear that this
;; makes for more readable code (esp. in the case of long
;; equations!). More ideally, we'd have another function for
;; fixing up equation arrays to look like that.
(replace-match " &\\&& ")
(setq past-first t))))
(goto-char (point-max))
(insert "\n\\end{eqnarray*}")))
;;; Sequences:
;; This section still has quite a ways to go. The idea is to speed up
;; the entry of sequences.
;; It would be good to have a two-level prefix as used
;; for example with ¡rectangles! that would allow you to
;; input various different kinds of sequences cleanly.
;; It would also be cool to have a "graphical" way
;; to select inputs, maybe using something like ratmen
;; to input things by moving down the branches of some
;; tree.
;; But anyway, the different kinds of sequences we might
;; want are as follows:
;; a_0, a_1, ..., a_n
;; a_1, a_2, ..., a_n
;; a_1, a_2, ..., a_{n+1}
;; TODO: check that the subscript is a number, and
;; iterate the number. But this provides basic
;; functionality.
(defun austex-insert-sequence-of-variables
(term substart subend interterm)
;; read in three strings; if subend is empty,
;; we will insert "..." at the end of the sequence.
(interactive (list (read-string
"Term: ")
(read-string
"Subscript starting: ")
(read-string
"Subscript ending: ")
(read-string
"What goes between terms?: ")))
(insert term
"_"
(if (> (length substart) 1)
(concat "{" substart "}")
substart)
interterm
;; would be good to be able to specify
;; that we want ldots with some
;; prefix argument.
"\\cdots"
interterm
(if (not (equal subend ""))
(concat term
"_"
(if (> (length subend) 1)
(concat "{" subend "}")
subend))
"\\ldots")))
;;; Bonus Features:
;; Basically copied right out of register.el, I find this variant to
;; be more natural in general. For the public, this is only turned on
;; in `austex-mode'.
(defun austex-insert-register (register &optional arg)
"Insert contents of register REGISTER. (REGISTER is a character.)
Normally puts point before and mark after the inserted text.
If optional second arg is non-nil, puts mark before and point after.
Interactively, second arg is non-nil if prefix arg is supplied."
(interactive "*cInsert register: \nP")
(push-mark)
(let ((val (get-register register)))
(cond
((consp val)
(insert-rectangle val))
((stringp val)
(insert-for-yank val))
((numberp val)
(princ val (current-buffer)))
((and (markerp val) (marker-position val))
(princ (marker-position val) (current-buffer)))
(t
(error "Register does not contain text")))))
(defun quote-marks ()
"Insert a pair of matching quote marks and position cursor between them."
(interactive)
(insert "\"\"")
(backward-char))
(defun parentheses ()
"Insert a pair of matching parentheses and position cursor between them."
(interactive)
(insert "()")
(backward-char))
(defun braces ()
"Insert a pair of matching brackets and position cursor between them."
(interactive)
(insert "{}")
(backward-char))
(defun brackets ()
"Insert a pair of matching brackets and position cursor between them."
(interactive)
(insert "{}")
(backward-char))
(defun parenthesize ()
"Add parentheses around everything on this line (modulo whitespace)."
(interactive)
(save-excursion
(end-of-line)
(delete-horizontal-space)
(insert ")")
(beginning-of-line)
(while (looking-at " \\|\t")
(forward-char 1))
(insert "(")))
(when (require 'mmm-mode nil t)
(defun multi-task ()
(interactive)
(mmm-ify-by-regexp
(quote emacs-lisp-mode)
"\\\\begin{verbatim}" 0 "\\\\end{verbatim}" 0 25)))
(require 'austex-bindings)
(provide 'austex)
;;; austex.el ends here
;;; austex-bindings.el -- bindings for the austex latex utilities
;; Copyright (C) 2004 Joseph Corneli <address@hidden>
;; Time-stamp: <jac -- Mon Oct 4 12:53:24 CDT 2004>
;; This file is not part of GNU Emacs, but it is distributed under
;; the same terms as GNU Emacs.
;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published
;; by the Free Software Foundation; either version 2, or (at your
;; option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;; Commentary:
;; This file includes the bindings I use with AusTeX (see austex.el).
;; The long-term goal is to make this into an "optimal" keyboard
;; layout in the sense of Dvorak. Right now it is just a good one in
;; the sense of the default Emacs map. The bindings are built on top
;; of a Dvorak layout, and so some of them may appear awkward or
;; confusing to users of other layouts. If you are already a Dvorak
;; user, adding these bindings to your repertoire should not be very
;; hard. On the other hand, if you are not a Dvorak user and you
;; still want to use AusTeX, you have at least three options: (1) see
;; if the bindings make sense to you with your layout after all; (2)
;; port the bindings to your layout in such a way that they do make
;; sense; (3) learn Dvorak.
;; Unlike what you may be used to in Emacs, these bindings involve
;; using a lot of modifiers! It is helpful to have a sense of the
;; physical layout of modifiers on my keyboard, even if you use some
;; other layout.
;; I actually have two Xmodmap setups; I will describe the one I use
;; on my laptop first, because it turns out that I seem to spend the
;; majority of my time typing on the laptop, especially when I am
;; taking lecture notes.
;; I replaced the number row on my laptop by modifiers. The layout is
;;
;; A H S C M G E G M C S H A
;;
;; where
;;
;; A = Alt
;; H = Hyper
;; S = Super
;; C = Control
;; M = Meta
;; G = AltGr (Mode_switch)
;; E = Escape
;;
;; The reason for the choice of the order is not arbitrary. The basic
;; principle that is I want commonly-used modifiers to be reachable
;; without moving my wrists. I can reach Mode_switch, Meta, Control,
;; and Super just by extending my fingers. The Escape key, a longer
;; reach, is not actually a modifier key at all, but rather, a prefix
;; key that gives the keyboard over to my window manager of choice,
;; ratpoison. Hyper is again a longer reach, and if I try to press
;; Alt without lifting my hand up and moving it, I definitely feel a
;; bit tweaked in the wrist.
;; As for what happens to the numbers -- they have been moved to the
;; AltGr layer in the right hand, in a traditional "embedded keypad"
;; arrangement. In my view, a better configuration would probably
;; require a better keyboard layout to begin with and/or better logic
;; in the keyboard, together with a more robust system of modifiers
;; inside of X.
;; This setup makes the two-modifier chords Super+Control,
;; Control+Meta, Super+Meta easy to reach as well. Hyper+Super and
;; Hyper+Control aren't that bad either, but they aren't quite as
;; nice. Other two-modifier chords aren't particularly comfortable.
;; Though three-modifier chords may seem silly, Hyper+Super+Control
;; and Super+Control+Meta are not very hard to press down using this
;; keyboard layout. I don't bind to these much yet.
;; In general, the main benefit of using modifiers (and modifier
;; chords) instead of prefix keys is *speed*. It takes less time, for
;; example, to press C-n than it does to press C-c n. Sometimes
;; keypresses within the same modifier can be faster than you'd
;; expect, e.g. C-t C-t or G-. G-, (i.e., Up followed by backspace,
;; according to my Xmodmap).
;; Single keypresses tend to be the fastest, then single modifiers
;; plus single keys, then two modifiers plus single keys, then a
;; prefix key followed by a single key.
;; A time-savings is also afforded by finding the keys right where you
;; seek them. This is not quite the same as knowing the keyboard
;; layout: it also means that the layout should have some internal
;; logic that is easy to understand. Subjectively, the Dvorak layout
;; seems to be quite good in this regard. One goal for this file is
;; to map out some of the psychological space behind the act of typing
;; math.
;; The second Xmodmap file I use is the one I have set up for typing
;; with my Kinesis Classic keyboard. It is similar to the one I use
;; with my laptop's keyboard, but because the Kinesis keyboard comes
;; with an extra row of easy-to-reach keys below the standard four
;; rows, it is not necessary to replace the number row with modifiers.
;; This is the main difference between the two Xmodmap files. Because
;; I don't have to remap the number row, I don't use an embedded
;; number keypad approach with this keyboard, instead, I have two
;; symmetrical "editing" keypads. Because the extra fifth row has
;; only four keys for either hand, I do not bind the Alt modifier in
;; the same place with this Xmodmap file (rather it is bound to one of
;; the Kinesis "thumb keys").
;; There seems to be some risk associated with trying to share
;; something as "personal" as a keyboard layout. However, I think
;; I've put enough work into these bindings to make them worth sharing
;; with anyone who's interested. I've reduced the risk by not
;; including all of my bindings! For anyone who is _really_
;; interested, the rest of the bindings (and various nonstandard
;; functions that are bound) are available on my website. Oh yes, and
;; finally, the xmodmap files described above are also available on my
;; website.
;;; Code:
;; This is a very long variable definition...
(defvar austex-mode-map
(let ((map (make-sparse-keymap)))
;;; Latin-1 (AltGr layer on standard keys):
;; The layout on my keyboards are:
;;
;; Laptop
;; ` BS Up Del = + 7 8 9 ^
;; ¡ Left Down Right ¿ - 4 5 6 _
;; [ ] { } ¥ ¤ 1 2 3 0
;;
;; Kinesis
;; ` BS Up Del = + BS Up Del ^
;; ¡ Left Down Right ¿ - Left Down Right _
;; [ ] { } ¥ ¤ { } ( )
(define-key map (quote [2212]) 'austex-math) ; currency
(define-key map (quote [2213]) 'austex-out-of-math) ; yen
;; This is used sort of like "tab", and when the function
;; `austex-next-field' is written, this should probably be bound to
;; that instead of `austex-end-of-math'.
(define-key map (quote [2239]) 'austex-end-of-math) ;
questiondown
;; This probably won't be used very much (I might be wrong). The
;; main use would seem to be for selecting text, and there should
;; be a seperate function that does that.
(define-key map (quote [2209]) 'austex-beginning-of-math) ;
exclamdown
;;; Latin-1 (Peripheral keys):
(define-key map [insert] 'parentheses)
(define-key map [select] 'parenthesize)
;; it would be cool to have something bound to dabbrev expand.
;; I'll think about that.
(define-key map (quote [end]) 'end-of-line)
;; Everything that doesn't have to take place very quickly should
;; probably not be bound in this section. `austex-math' and
;; `austex-out-of-math' are two examples of functions that need to
;; be able to be called very quickly.
;;; Control Characters:
;; These are things like C-w, C-y, etc. Usually they are bound by
;; default in Emacs. Some of these keys have been cannibalized to
;; make prefix keymaps (see below). It is worth knowing the
;; default bindings!!
;;; Keymaps:
;; Things just got more interesting. These keymaps let us bind
;; lots more editor commands to speedy (though not lightning fast)
;; keyboard shortcuts. The sections that give the bindings with
;; the associated "prefix commands" appear in later sections. Not
;; sure whether these should be sparse keymaps or not?
(define-key map [?\C-.] (make-keymap))
(define-key map [?\C-,] (make-keymap))
(define-key map [?\C-'] (make-keymap))
(define-key map [?\C-\;] (make-keymap))
;; Setting up hyper and super for a non-X-enabled Emacs. Though
;; these are not strictly speaking keymaps, they are "prefix
;; commands" in the sense that you have to press the key, release
;; it, then find the next key in the sequence.
(define-key function-key-map "\e[17~" 'event-apply-hyper-modifier); f6
(define-key function-key-map "\e[20~" 'event-apply-super-modifier); f9
;; Next follow several sections of "single modifier plus
;; character" bindings.
;;; Alt:
;; Use of this modifier will probably tweak your wrists! Beware!
;;; Hyper:
(define-key map [(hyper ,)] 'austex-leq)
(define-key map [(hyper .)] 'austex-geq)
(define-key map [(hyper ?')] 'austex-neq)
(define-key map [(hyper ?\040)] 'austex-out-of-math) ; H-SPC
(define-key map [(hyper ?\134)] 'austex-pipe) ; H-\
(define-key map [(hyper ?\;)] 'austex-sim)
(define-key map [(hyper a)] 'austex-alpha)
(define-key map [(hyper b)] 'austex-beta)
(define-key map [(hyper c)] 'austex-psi)
(define-key map [(hyper d)] 'austex-delta)
(define-key map [(hyper e)] 'austex-epsilon)
(define-key map [(hyper f)] 'austex-varphi)
(define-key map [(hyper g)] 'austex-gamma)
(define-key map [(hyper h)] 'austex-theta)
(define-key map [(hyper i)] 'austex-iota)
(define-key map [(hyper j)] 'austex-ldots)
(define-key map [(hyper k)] 'austex-kappa)
(define-key map [(hyper l)] 'austex-lambda)
(define-key map [(hyper m)] 'austex-mu)
(define-key map [(hyper n)] 'austex-nu)
(define-key map [(hyper o)] 'austex-omicron)
(define-key map [(hyper o)] 'austex-phi)
(define-key map [(hyper p)] 'austex-pi)
(define-key map [(hyper q)] 'austex-chi)
(define-key map [(hyper r)] 'austex-rho)
(define-key map [(hyper s)] 'austex-sigma)
(define-key map [(hyper t)] 'austex-tau)
(define-key map [(hyper u)] 'austex-upsilon)
(define-key map [(hyper v)] 'austex-infty)
(define-key map [(hyper w)] 'austex-omega)
(define-key map [(hyper x)] 'austex-xi)
(define-key map [(hyper y)] 'austex-eta)
(define-key map [(hyper z)] 'austex-zeta)
;;; Super:
;; Math symbols and the simplest math forms.
;; I have a sort of weird "graphical" mnemonic for these symbols.
;; It tends to work out pretty well, the only difficulty that
;; stands out to be being that I seem to forget which finger to
;; use for \cap and which to use for \cup. Some of the other
;; commands require a little bit of hunt-and-peck activity as
;; well. Eventually it would be good to optimize this layout in a
;; Dvorakian way or find other means of reorganizing the confusing
;; symbols to make them easier to find.
;; I tend to use this super binding on the laptop and the
;; corresponding Latin 1 binding with the Kinesis. It might
;; actually be better to use one binding all the time.
(define-key map [(super ?\040)] 'austex-math) ; s-SPC
(define-key map [(super ,)] 'austex-subset)
(define-key map [(super .)] 'austex-supset)
(define-key map [(super <)] 'austex-Subset)
(define-key map [(super >)] 'austex-Supset)
(define-key map [(super ?\134)] 'austex-setminus) ; s-\
(define-key map [(super \')] 'austex-equiv)
(define-key map [(super \;)] 'austex-cong)
(define-key map [(super a)] 'austex-simeq)
(define-key map [(super b)] 'austex-nabla)
(define-key map [(super c)] 'austex-cap)
(define-key map [(super d)] 'austex-forall)
(define-key map [(super e)] 'austex-ni)
(define-key map [(super f)] 'austex-frac)
(define-key map [(super g)] 'austex-integral)
(define-key map [(super h)] 'austex-circ)
(define-key map [(super i)] 'austex-exists)
(define-key map [(super j)] 'austex-cdots)
(define-key map [(super k)] 'austex-wedge)
(define-key map [(super l)] 'austex-Leftrightarrow)
(define-key map [(super m)] 'austex-vee)
(define-key map [(super n)] 'austex-rightarrow)
(define-key map [(super o)] 'austex-in)
(define-key map [(super p)] 'austex-partial)
(define-key map [(super q)] 'austex-vdots)
(define-key map [(super r)] 'austex-cup)
(define-key map [(super s)] 'austex-Rightarrow)
(define-key map [(super t)] 'austex-cdot)
(define-key map [(super u)] 'austex-times)
;; we assume that there will be a subscript. Not always true in
;; all math writing, but there _could_ always be one.
(define-key map [(super v)] 'austex-sum)
(define-key map [(super w)] 'austex-prod)
(define-key map [(super x)] 'austex-triangle)
(define-key map [(super y)] 'austex-sqrt)
(define-key map [(super z)] 'austex-Leftarrow)
;;; Hyper+Super
;; Additional symbols, LaTeX environments and forms, fancy
;; exponents.
;; Symbols can be moved back and forth with Super until they are
;; all settled.
;; Some environments probably need to be fast, others can be as slow
;; as a prefix map. Forms need to be fast.
;; Probably all the fancy exponents could be moved to a prefix map.
;; On the other hand, if there aren't enough other things to put here,
;; they might as well stay.
(define-key map [(hyper super ,)] 'austex-openset)
(define-key map [(hyper super .)] 'austex-alist)
(define-key map [(hyper super a)] 'austex-absolute-value)
(define-key map [(hyper super b)] 'austex-next-bracket)
(define-key map [(hyper super c)] 'austex-complement)
(define-key map [(hyper super d)] 'austex-defn)
(define-key map [(hyper super e)] 'austex-emph)
(define-key map [(hyper super i)] 'austex-inverse)
(define-key map [(hyper super l)] 'austex-langle-rangle)
(define-key map [(hyper super o)] 'austex-otimes)
(define-key map [(hyper super p)] 'austex-proof)
(define-key map [(hyper super q)] 'austex-quote)
(define-key map [(hyper super r)] 'austex-eqnarray*)
(define-key map [(hyper super s)] 'austex-set)
(define-key map [(hyper super v)] 'austex-verbatim)
;; "w" here stands for "wave equation"
(define-key map [(hyper super w)] 'austex-square)
(define-key map [(hyper super x)] 'austex-to-the-ast)
(define-key map [(hyper super y)] 'austex-to-the-star)
;;; Hyper+Control:
;; Nothing here yet.
;;; Hyper+Meta:
;; Nothing here yet.
;;; Super+Control:
;; "fontification" and other unary-style macros, with a few
;; missing Emacs functions thrown in, and some math forms. A nice
;; varied collection.
;; Note: There is a somewhat clear division between Hyper and
;; Super modified characters, namely, the former are mostly greek
;; letters and the latter are mostly math symbols. It might be
;; sensible to have similar clear division between Hyper+Super and
;; Super+Control modified characters (shuttling anything that
;; doesn't fit into our categories off into another double
;; modifier group or prefix mapping).
;; Probably it would be best for the more infrequently-used
;; decorations to be placed into a prefix map (and perhaps all of
;; the decorations should go in the same place)
(define-key map [(super control b)] 'austex-bar)
(define-key map [(super control c)] 'austex-check)
(define-key map [(super control d)] 'austex-derivative)
(define-key map [(super control f)] 'austex-mathbf)
(define-key map [(super control h)] 'austex-hat)
(define-key map (quote [8388617]) 'austex-mathit) ; s-C-i =
s-TAB
(define-key map [(super control o)] 'austex-mathop)
(define-key map [(super control p)] 'austex-partial-derivative)
(define-key map [(super control r)] 'austex-mathrm)
(define-key map [(super control s)] 'austex-subscript)
(define-key map [(super control t)] 'austex-text)
(define-key map [(super control l)] 'austex-exponent)
(define-key map [(super control w)] 'austex-tilde)
;;; Super+Meta:
;; Nothing here yet.
;;; Control+Meta:
;; Plenty here by default.
;; Next follow several sections of "three modifiers plus
;; character" bindings.
;;; Hyper+Super+Control:
;; Nothing here yet.
;;; Super+Control+Meta:
;; Nothing here yet.
;;; Control x prefix:
;; this overrides the standard behavior for this key sequence
(define-key map "\C-xri" 'austex-insert-register)
;;; Control . prefix:
;; Mainly for commands that are supposed to take place in the
;; "math mode" parts of a latex buffer.
;; These two are also duplicated in the Latin 1 section above,
;; where they should be even faster to execute.
(define-key map [?\C-.?a] 'austex-beginning-of-math)
(define-key map [?\C-.?e] 'austex-end-of-math)
;; `austex-next-bracket' is another alternate name for the same
;; sort of function, I think. The question now is whether any of
;; these functions work the way they should.
(define-key map [?\C-.?n] 'austex-next-field)
(define-key map [?\C-.?p] 'austex-previous-field)
;; How to make this function behave better when there are equality
;; operators inside of the terms that this set of equations is
;; talking about (e.g. "P(X=0)")? Maybe something sort of like
;; ispell to select which comparison operators to transform? That
;; would be reasonable. Some kind of parenthesis counting would
;; be sufficient to deal with these examples from probability.
(define-key map [?\C-.?r] 'austex-turn-current-equation-into-equation-array)
;;; Control , prefix:
;; Currently mostly taken up by capital greek letters.
;; Note that a number of the greek letters don't have a
;; capitalized variant. I am inserting something sort of ugly,
;; like "\textsc{A}" to take the place of such missing things.
;; This would appear to be a place where some LaTeX macros to fill
;; the gap (e.g. \Alpha) would come in handy.
(define-key map [?\C-,?a] 'austex-Alpha)
(define-key map [?\C-,?b] 'austex-Beta)
(define-key map [?\C-,?g] 'austex-Gamma)
(define-key map [?\C-,?d] 'austex-Delta)
(define-key map [?\C-,?e] 'austex-Epsilon)
(define-key map [?\C-,?z] 'austex-Zeta)
(define-key map [?\C-,?y] 'austex-Eta)
(define-key map [?\C-,?h] 'austex-Theta)
(define-key map [?\C-,?i] 'austex-Iota)
(define-key map [?\C-,?k] 'austex-Kappa)
(define-key map [?\C-,?l] 'austex-Lambda)
(define-key map [?\C-,?m] 'austex-Mu)
(define-key map [?\C-,?n] 'austex-Nu)
(define-key map [?\C-,?x] 'austex-Xi)
(define-key map [?\C-,?o] 'austex-Omicron)
(define-key map [?\C-,?p] 'austex-Pi)
(define-key map [?\C-,?r] 'austex-Rho)
(define-key map [?\C-,?s] 'austex-Sigma)
(define-key map [?\C-,?t] 'austex-Tau)
(define-key map [?\C-,?u] 'austex-Upsilon)
(define-key map [?\C-,?f] 'austex-Phi)
(define-key map [?\C-,?q] 'austex-chi)
(define-key map [?\C-,?c] 'austex-Psi)
(define-key map [?\C-,?w] 'austex-Omega)
;;; Control ' prefix:
;; Miscellaneous stuff (add things here as needed).
(define-key map [?\C-\'?'] '(lambda () (interactive) (yow t)))
;;; Control ; prefix:
;; Miscellaneous stuff (add things here as needed).
(define-key map [?\C-\;?\;] 'force-lisp-indent) ; see below
map)
"Keymap for AusTeX minor mode.")
;; OK! we're finally done defining `austex-mode-map'!
;;; Minor mode:
(define-minor-mode austex-mode
"Toggle AusTeX minor mode.
With no argument, this command toggles the mode.
Non-null prefix argument turns on the mode.
Null prefix argument turns off the mode.
AusTeX mode provides many useful LaTeX functions and key bindings."
:init-value nil
:lighter " ATX")
;;; Hacks:
;; This is a section for code that is used to maintain this file.
;; I think it is a little bit strange that single-semicolon comments
;; are not sent to the `comment-column' by TAB when there are other
;; things on the line. This accomplishes the desired end-result.
(defun force-lisp-indent ()
"Move comments on this line to comment column.
Unlike with `lisp-indent-line', this effect is accomplished even
when there is other text on the line."
(interactive)
(goto-char (line-beginning-position))
(search-forward-regexp " +\\(;[^\n]*\\)" (line-end-position) t)
(let ((comment (match-string 1)))
(replace-match "")
(goto-char (line-beginning-position))
(let ((count comment-column))
(while (looking-at "[^\n]")
(forward-char 1)
(decf count))
(insert-char (string-to-char " ") count)
(insert comment))))
;; Local Variables:
;; mode:Emacs-Lisp
;; comment-column:70
;; End:
(provide 'austex-bindings)
;;; End of austex-bindings.el
! xmodmap for Apple iBook
keycode 8 = a A exclamdown
keycode 9 = o O Left
keycode 10 = e E Down
keycode 11 = u U Right
keycode 12 = d D minus
keycode 13 = i I questiondown
keycode 14 = semicolon colon bracketleft
keycode 15 = q Q bracketright
keycode 16 = j J braceleft
keycode 17 = k K braceright
keycode 19 = x X yen
keycode 20 = apostrophe quotedbl grave
keycode 21 = comma less BackSpace
keycode 22 = period greater Up
keycode 23 = p P Delete
keycode 24 = f F plus
keycode 25 = y Y equal
keycode 26 = Hyper_L exclam
keycode 27 = Super_L at
keycode 28 = Control_L numbersign 3
keycode 29 = Meta_L dollar
keycode 30 = F6 asciicircum
keycode 31 = Mode_switch percent
keycode 32 = Alt_R
keycode 33 = Control_R parenleft NoSymbol
keycode 34 = Mode_switch ampersand NoSymbol
keycode 35 = Hyper_R minus underscore
keycode 36 = Meta_L asterisk NoSymbol
keycode 37 = Super_R parenright NoSymbol
keycode 38 = Prior threequarters thorn
keycode 39 = r R 9
keycode 40 = g G 7
keycode 41 = slash question asciitilde
keycode 42 = c C 8
keycode 43 = l L asciicircum
keycode 44 = Return
keycode 45 = n N 6
keycode 46 = h H 4
keycode 47 = backslash bar
keycode 48 = t T 5
keycode 49 = s S underscore
keycode 50 = Next onequarter Eth
keycode 51 = w W 2
keycode 52 = z Z 0
keycode 53 = b B currency
keycode 54 = m M 1
keycode 55 = v V 3
keycode 56 = Tab Select Insert
keycode 57 = space Select Insert
keycode 58 = Alt_L
keycode 59 = BackSpace
keycode 60 = Return
keycode 61 = Caps_Lock Escape
keycode 63 = Meta_L
keycode 64 = Shift_L
keycode 65 = Return Insert
keycode 66 = Hyper_L
keycode 67 = Control_L
keycode 68 = Shift_R
keycode 69 = Hyper_L
keycode 70 = Control_R
keycode 71 = Super_L
keycode 73 = KP_Decimal
! keyboard multiply??
keycode 74 = NoSymbol asterisk
! apparently not
keycode 75 = KP_Multiply
keycode 77 = KP_Add
! again, weird.
keycode 78 = NoSymbol plus
keycode 79 = Escape
keycode 80 = equal question asciitilde
keycode 83 = KP_Divide
keycode 84 = KP_Enter
keycode 85 = z Z
keycode 86 = KP_Subtract
keycode 89 = KP_Equal
keycode 90 = KP_0
keycode 91 = KP_1
keycode 92 = KP_2
keycode 93 = KP_3
keycode 94 = KP_4
keycode 95 = KP_5
keycode 96 = KP_6
keycode 97 = KP_7
keycode 99 = KP_8
keycode 100= KP_9
keycode 104= F5
keycode 105= F6
keycode 106= 1 F7 6
keycode 107= F3
keycode 108= 2 F8 7
keycode 109= 3 F9 8
keycode 111= 5 F11 0
keycode 113= F13
keycode 115= F14
keycode 117= 4 F10 9
keycode 119= F12
keycode 121= F15
keycode 122= Hyper_L
keycode 123= Home
keycode 124= Prior
keycode 125= Delete
keycode 126= F4
keycode 127= End
keycode 128= F2
keycode 129= Next
keycode 130= F1
keycode 131= Left exclam percent notsign
keycode 132= Right numbersign ampersand mu
keycode 133= Down at asciicircum thorn
keycode 134= Up dollar asterisk brokenbar
clear Lock
clear control
clear mod1
clear mod2
clear mod3
clear mod4
clear mod5
add Lock = Caps_Lock
add Control = Control_L Control_R
add mod1 = Mode_switch
add mod2 = Meta_L Meta_R
add mod3 = Hyper_L Hyper_R
add mod4 = Super_L Super_R
add mod5 = Alt_L Alt_R
! xmodmap file for kinesis classic
keycode 8 = a A 6
keycode 9 = o O Left
keycode 10 = e E Down
keycode 11 = u U Right
keycode 12 = d D minus
keycode 13 = i I asciicircum
keycode 14 = semicolon colon bracketleft
keycode 15 = q Q bracketright
keycode 16 = j J braceleft
keycode 17 = k K braceright
keycode 19 = x X dollar
keycode 20 = apostrophe quotedbl grave
keycode 21 = comma less BackSpace
keycode 22 = period greater Up
keycode 23 = p P Delete
keycode 24 = f F plus
keycode 25 = y Y equal
keycode 26 = 1 exclam
keycode 27 = 2 at
keycode 28 = 3 numbersign
keycode 29 = 4 dollar
keycode 30 = 6 asciicircum
keycode 31 = 5 percent Sys_Req
keycode 32 = sterling yen yen
keycode 33 = 9 parenleft
keycode 34 = 7 ampersand
keycode 35 = slash question asciitilde
keycode 36 = 8 asterisk
keycode 37 = 0 parenright
! bracketleft braceleft
keycode 38 = Hyper_R
keycode 39 = r R Delete
keycode 40 = g G BackSpace
keycode 41 = Super_R
keycode 42 = c C Up
keycode 43 = l L asciicircum
keycode 44 = Mode_switch NoSymbol Insert
keycode 45 = n N Right
keycode 46 = h H Left
keycode 47 = backslash bar
keycode 48 = t T Down
keycode 49 = s S underscore
keycode 50 = eacute
keycode 51 = w W braceright
keycode 52 = z Z parenright
keycode 53 = b B currency
keycode 54 = m M braceleft
keycode 55 = v V parenleft
keycode 56 = egrave
keycode 57 = space space currency
keycode 58 = Hyper_L
keycode 59 = BackSpace BackSpace section
keycode 60 = Return
keycode 61 = Escape
keycode 63 = Tab
keycode 64 = Shift_L NoSymbol NoSymbol NoSymbol
keycode 65 = NoSymbol
keycode 66 = Tab
keycode 67 = Return
keycode 68 = backslash bar
keycode 69 = Return
keycode 70 = Super_L
keycode 71 = Hyper_L
keycode 73 = KP_Decimal
keycode 74 = NoSymbol asterisk
keycode 75 = KP_Multiply
keycode 77 = KP_Add
keycode 78 = NoSymbol plus
keycode 79 = Escape
keycode 80 = equal plus
keycode 83 = KP_Divide
keycode 84 = KP_Enter
keycode 85 = 0 0 0
keycode 86 = KP_Subtract
keycode 89 = KP_Equal
keycode 90 = KP_0
keycode 91 = KP_1
keycode 92 = KP_2
keycode 93 = KP_3
keycode 94 = KP_4
keycode 95 = KP_5
keycode 96 = KP_6
keycode 97 = KP_7
keycode 99 = KP_8
keycode 100= KP_9
keycode 104= Select Insert
keycode 105= agrave
keycode 106= Control_R
keycode 107= F3
keycode 108= F8
keycode 109= F9
keycode 111= Alt_L
keycode 113= Left Home
! ditto
keycode 115= Left Home
keycode 116= m
keycode 117= Left Home
keycode 119= F12
keycode 121= Left Home
keycode 122= Super_L
keycode 123= aacute
keycode 124= agrave
keycode 125= Mode_switch NoSymbol Insert
keycode 126= F4
keycode 127= Alt_L
keycode 128= F2
keycode 129= Alt_L
keycode 130= F1
keycode 131= Control_L
keycode 132= Meta_L
keycode 133= Control_R
keycode 134= Meta_L
clear Lock
clear control
clear mod1
clear mod2
clear mod3
clear mod4
clear mod5
add Lock = Caps_Lock
add Control = Control_L Control_R
add mod1 = Mode_switch
add mod2 = Meta_L
add mod3 = Hyper_L Hyper_R
add mod4 = Super_L Super_R
add mod5 = Alt_L Alt_R
! an Xmodmap file to put Dvorak on the lousy lab keyboards
keycode 10 = exclam
keycode 11 = at
keycode 12 = Control_L numbersign
keycode 13 = Meta_L dollar
keycode 14 = Mode_switch percent
keycode 15 = F6 asciicircum
keycode 16 = Mode_switch ampersand
keycode 17 = Meta_L asterisk
keycode 18 = Control_R parenleft
keycode 19 = parenright
keycode 24 = apostrophe quotedbl grave
keycode 25 = comma less BackSpace
keycode 26 = period greater Up
keycode 27 = p P Delete
keycode 28 = y Y equal
keycode 29 = f F plus
keycode 30 = g G BackSpace
keycode 31 = c C Up
keycode 32 = r R Delete
keycode 33 = l L
keycode 34 = slash question asciitilde
keycode 38 = a A
keycode 39 = o O Left
keycode 40 = e E Down
keycode 41 = u U Right
keycode 42 = i I minus
keycode 43 = d D minus
keycode 44 = h H Left
keycode 45 = t T Down
keycode 46 = n N Right
keycode 47 = s S underscore
keycode 48 = backslash bar
keycode 52 = semicolon colon bracketleft
keycode 53 = q Q bracketright
keycode 54 = j J braceleft
keycode 55 = k K braceright
keycode 56 = x X dollar
keycode 57 = b B
keycode 58 = m M braceleft
keycode 59 = w W braceright
keycode 60 = v V parenleft
keycode 61 = z Z parenright
keycode 74 = 1 6 6
keycode 75 = 2 7 7
keycode 76 = 3 8 8
keycode 95 = 4 9 9
keycode 96 = 5 0 0
! The Caps_Lock key is much better as a second return key.
keycode 66 = Return
clear lock
clear control
clear mod1
clear mod2
clear mod3
clear mod4
clear mod5
add Control = Control_L Control_R
add mod1 = Mode_switch
add mod2 = Meta_L Meta_R
add mod3 = Hyper_L Hyper_R
add mod4 = Super_L Super_R
add mod5 = Alt_L Alt_R
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- austex.el,
Joe Corneli <=