aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/maths-menu.el
blob: 9e308faa588cd8dcb2ed2a3e5fb0d6018eb08d6c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
;;; maths-menu.el --- insert maths characters from a menu  -*-coding: iso-2022-7bit;-*-

;; Copyright (C) 2003  Free Software Foundation, Inc.

;; Author: Dave Love <fx@gnu.org>
;; Keywords: convenience
;; $Revision$

;; This file 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.

;; This file 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:

;; Defines a minor mode which defines a menu bar item allowing a wide
;; range of maths/technical characters (roughly the LaTeX repertoire)
;; to be inserted into the buffer by selecting menu items.

;; Menu display only works properly under X with Gtk menus and if the
;; menu uses a font with a suitable repertoire.  (Lucid and Motif
;; toolkit menus can't display multilingual text.  I don't know about
;; MS Windows menus.)  It will work with tmm in tty mode iff the tty
;; displays Unicode.  The tmm version (via F10) is also useful under a
;; window system when the menus don't display the characters
;; correctly, but where the symbols have word syntax, tmm won't
;; provide an ASCII selector for them, which can be a pain to use
;; without a mouse.

;; See also the TeX and sgml Quail input modes.  These will probably
;; behave better if you can remember the input sequences.  For
;; instance, this minor mode won't give you the ability to insert into
;; the minibuffer via the menu, though presumably it could be added to
;; the minibuffer menu.

;;; Code:

(defun maths-menu-build-menu (spec)
  (let ((map (make-sparse-keymap "Characters")))
    (dolist (pane spec)
      (let* ((name (pop pane))
	     (pane-map (make-sparse-keymap name)))
	(define-key-after map (vector (intern name)) (cons name pane-map))
	(dolist (elt pane)
	  (define-key-after pane-map
	    (vector (intern (string (car elt)))) ; convenient unique symbol
	    (cons (format "%c  (%s)" (car elt) (cadr elt))
		  ;; Using a string here doesn't work.  You get a
		  ;; `Wrong type argument: commandp,' error.
		  ;; That looks like a bug, since
		  ;;   (commandp "a") => t
		  `(lambda ()
		     (interactive)
		     (insert ,(car elt))))))))
    map))

(defvar maths-menu-menu
  (maths-menu-build-menu
   '(("Binops 1"
      (?,A1(B "plus-minus sign")
      (?$,1x3(B "minus-or-plus sign")
      (?,AW(B "multiplication sign")
      (?,Aw(B "division sign")
      (?$,1x2(B "minus sign")
      (?$,1x7(B "asterisk operator")
      (?$,1z&(B "star operator")
      (?$,2"+(B "white circle")
      (?$,1s"(B "bullet")
      (?,A7(B "middle dot")
      (?$,1xI(B "intersection")
      (?$,1xJ(B "union")
      (?$,1yN(B "multiset union")
      (?$,1yS(B "square cap")
      (?$,1yT(B "square cup")
      (?$,1xH(B "logical or")
      (?$,1xG(B "logical and")
      (?$,1x6(B "set minus")
      (?$,1x`(B "wreath product"))
     ("Binops 2"
      (?$,1z$(B "diamond operator")
      (?$,2!s(B "white up-pointing triangle")
      (?$,2!}(B "white down-pointing triangle")
      (?$,2"#(B "white left-pointing small triangle")
      (?$,2!y(B "white right-pointing small triangle")
      (?$,2"!(B "white left-pointing triangle")
      (?$,2!w(B "white right-pointing triangle")
      (?$,1yU(B "circled plus")
      (?$,1yV(B "circled minus")
      (?$,1yW(B "circled times")
      (?$,1yX(B "circled division slash")
      (?$,1yY(B "circled dot operator")
      (?$,2"O(B "large circle")
      (?$,1s (B "dagger")
      (?$,1s!(B "double dagger")
      (?$,1yt(B "normal subgroup of or equal to")
      (?$,1yu(B "contains as normal subgroup or equal to"))
     ("Relations 1"
      (?$,1y$(B "less-than or equal to")
      (?$,1y:(B "precedes")
      (?$,1y*(B "much less-than")
      (?$,1yB(B "subset of")
      (?$,1yF(B "subset of or equal to")
      (?$,1yO(B "square image of")
      (?$,1yQ(B "square image of or equal to")
      (?$,1x((B "element of")
      (?$,1x)(B "not an element of")
      (?$,1yb(B "right tack")
      (?$,1y%(B "greater-than or equal to")
      (?$,1y;(B "succeeds")
      (?$,1y=(B "succeeds or equal to")
      (?$,1y+(B "much greater-than")
      (?$,1yC(B "superset of")
      (?$,1yG(B "superset of or equal to")
      (?$,1yP(B "square original of")
      (?$,1yR(B "square original of or equal to")
      (?$,1x+(B "contains as member")
      (?$,1y!(B "identical to")
      (?$,1y"(B "not identical to") )
     ("Relations 2"
      (?$,1yc(B "left tack")
      (?$,1x\(B "tilde operator")
      (?$,1xc(B "asymptotically equal to")
      (?$,1xm(B "equivalent to")
      (?$,1xh(B "almost equal to")
      (?$,1xe(B "approximately equal to")
      (?$,1y (B "not equal to")
      (?$,1xp(B "approaches the limit")
      (?$,1x=(B "proportional to")
      (?$,1yg(B "models")
      (?$,1xC(B "divides")
      (?$,1xE(B "parallel to")
      (?$,1z((B "bowtie")
      (?$,1z((B "bowtie")
      (?$,1{#(B "smile")
      (?$,1{"(B "frown")
      (?$,1xy(B "estimates")
      (?$,1z_(B "z notation bag membership"))
     ("Arrows"
      (?$,1vp(B "leftwards arrow")
      (?$,1wP(B "leftwards double arrow")
      (?$,1vr(B "rightwards arrow")
      (?$,1wR(B "rightwards double arrow")
      (?$,1vt(B "left right arrow")
      (?$,1wT(B "left right double arrow")
      (?$,1w&(B "rightwards arrow from bar")
      (?$,1w)(B "leftwards arrow with hook")
      (?$,1w<(B "leftwards harpoon with barb upwards")
      (?$,1w=(B "leftwards harpoon with barb downwards")
      (?$,1wL(B "rightwards harpoon over leftwards harpoon")
      (?$,1w&(B "rightwards arrow from bar")
      (?$,1w*(B "rightwards arrow with hook")
      (?$,1w@(B "rightwards harpoon with barb upwards")
      (?$,1wA(B "rightwards harpoon with barb downwards")
      (?$,1v}(B "rightwards wave arrow")
      (?$,1vq(B "upwards arrow")
      (?$,1wQ(B "upwards double arrow")
      (?$,1vs(B "downwards arrow")
      (?$,1wS(B "downwards double arrow")
      (?$,1vu(B "up down arrow")
      (?$,1vw(B "north east arrow")
      (?$,1vx(B "south east arrow")
      (?$,1vy(B "south west arrow")
      (?$,1vv(B "north west arrow")
      (?$,1w[(B "rightwards triple arrow"))
     ("Symbols 1"
      (?$,1uu(B "alef symbol") ; don't use letter alef (avoid bidi confusion)
      (?$,1uO(B "planck constant over two pi")
      (?$,1 Q(B "latin small letter dotless i")
      (?$,1uS(B "script small l")
      (?$,1uX(B "script capital p")
      (?$,1u\(B "black-letter capital r")
      (?$,1uQ(B "black-letter capital i")
      (?$,1ug(B "inverted ohm sign")
      (?$,1s2(B "prime")
      (?$,1x%(B "empty set")
      (?$,1x'(B "nabla")
      (?$,1x:(B "square root")
      (?$,1x;(B "cube root")
      (?$,1yd(B "down tack")
      (?$,1ye(B "up tack")
      (?$,1x@(B "angle")
      (?$,1x (B "for all")
      (?$,1x#(B "there exists")
      (?$,1x$(B "there does not exist")
      (?,A,(B "not sign")
      (?$,2#o(B "music sharp sign")
      (?$,1x"(B "partial differential")
      (?$,1x>(B "infinity") )
     ("Symbols 2"
      (?$,2!a(B "white square")
      (?$,2"'(B "white diamond")
      (?$,2!u(B "white up-pointing small triangle")
      (?$,1x1(B "n-ary summation")
      (?$,1x/(B "n-ary product")
      (?$,1x0(B "n-ary coproduct")
      (?$,1xK(B "integral")
      (?$,1xN(B "contour integral")
      (?$,1z"(B "n-ary intersection")
      (?$,1z#(B "n-ary union")
      (?$,1z!(B "n-ary logical or")
      (?$,1z (B "n-ary logical and")
      (?$,1uU(B "double-struck capital n")
      (?$,1uY(B "double-struck capital p")
      (?$,1u](B "double-struck capital r")
      (?$,1ud(B "double-struck capital z")
      (?$,1uP(B "script capital i")
      (?$,1![(B "latin small letter lambda with stroke")
      (?$,1xT(B "therefore")
      (?$,1s&(B "horizontal ellipsis")
      (?$,1zO(B "midline horizontal ellipsis")
      (?$,1zN(B "vertical ellipsis")
      (?$,1zQ(B "down right diagonal ellipsis")
      (?$,1zP(B "up right diagonal ellipsis")
      (?$,2,!(B "z notation spot")
      (?$,2,"(B "z notation type colon"))
     ("Delimiters"
      (?\$,1zj(B "left floor")
      (?\$,1zh(B "left ceiling")
      (?\$,1{)(B "left-pointing angle bracket")
      (?\$,1zk(B "right floor")
      (?\$,1zi(B "right ceiling")
      (?\$,1{*(B "right-pointing angle bracket")
      (?\$,2=Z(B "left white square bracket")
      (?\$,2=[(B "right white square bracket")
      (?\$,2=J(B "left double angle bracket")
      (?\$,2=K(B "right double angle bracket")
      (?\$,2,'(B "z notation left image bracket")
      (?\$,2,((B "z notation right image bracket")
      (?\$,2,)(B "z notation left binding bracket")
      (?\$,2,*(B "z notation right binding bracket"))
     ("Greek LC"
      (?$,1'1(B "alpha")
      (?$,1'2(B "beta")
      (?$,1'3(B "gamma")
      (?$,1'4(B "delta")
      (?$,1'5(B "epsilon")
      (?$,1'6(B "zeta")
      (?$,1'7(B "eta")
      (?$,1'8(B "theta")
      (?$,1'Q(B "theta symbol")
      (?$,1'9(B "iota")
      (?$,1':(B "kappa")
      (?$,1';(B "lamda")
      (?$,1'<(B "mu")
      (?$,1'=(B "nu")
      (?$,1'>(B "xi")
      (?$,1'@(B "pi")
      (?$,1'V(B "pi symbol")
      (?$,1'A(B "rho")
      (?$,1'q(B "rho symbol")
      (?$,1'C(B "sigma")
      (?$,1'B(B "final sigma")
      (?$,1'D(B "tau")
      (?$,1'E(B "upsilon")
      (?$,1'F(B "phi")
      (?$,1'U(B "phi symbol")
      (?$,1'G(B "chi")
      (?$,1'H(B "psi")
      (?$,1'I(B "omega"))
     ("Greek UC"
      (?$,1&s(B "Gamma")
      (?$,1&t(B "Delta")
      (?$,1&x(B "Theta")
      (?$,1&{(B "Lamda")
      (?$,1&~(B "Xi")
      (?$,1' (B "Pi")
      (?$,1'#(B "Sigma")
      (?$,1'%(B "Upsilon")
      (?$,1'&(B "Phi")
      (?$,1'((B "Psi")
      (?$,1')(B "Omega"))
     ("Sub/super"
      (?$,1s}(B "superscript left parenthesis")
      (?$,1s~(B "superscript right parenthesis")
      (?$,1sz(B "superscript plus sign")
      (?$,1s{(B "superscript minus")
      (?$,1sp(B "superscript zero")
      (?,A9(B "superscript one")
      (?,A2(B "superscript two")
      (?,A3(B "superscript three")
      (?$,1st(B "superscript four")
      (?$,1su(B "superscript five")
      (?$,1sv(B "superscript six")
      (?$,1sw(B "superscript seven")
      (?$,1sx(B "superscript eight")
      (?$,1sy(B "superscript nine")
      (?$,1t-(B "subscript left parenthesis")
      (?$,1t.(B "subscript right parenthesis")
      (?$,1t*(B "subscript plus sign")
      (?$,1t+(B "subscript minus")
      (?$,1t (B "subscript zero")
      (?$,1t!(B "subscript one")
      (?$,1t"(B "subscript two")
      (?$,1t#(B "subscript three")
      (?$,1t$(B "subscript four")
      (?$,1t%(B "subscript five")
      (?$,1t&(B "subscript six")
      (?$,1t'(B "subscript seven")
      (?$,1t((B "subscript eight")
      (?$,1t)(B "subscript nine")))))

(defvar maths-menu-mode-map
  (let ((map (make-sparse-keymap)))
    (define-key map [menu-bar maths]
      `(menu-item "Maths" ,maths-menu-menu
		  :help "Menu of maths characters to insert"))
    map))

;; Unless we have Gtk menus, we probably can't display the maths
;; correctly in the menu bar.
(unless (string-match "--with-gtk" system-configuration-options)
  (define-key-after maths-menu-menu [warnl] '(menu-item "--"))
  (define-key-after maths-menu-menu [warn1]
    '(menu-item "NB. This Emacs displays"))
  (define-key-after maths-menu-menu [warn2]
    '(menu-item "the maths chars wrongly"))
  (define-key-after maths-menu-menu [warn3]
    '(menu-item "in the menus."))
  ;; Another approach:
;;;       (define-key maths-menu-mode-map [menu-bar maths]
;;; 	(cons "Maths" (lambda ()
;;; 			(interactive)
;;; 			(tmm-prompt maths-menu-menu))))
  )

;;;###autoload
(define-minor-mode maths-menu-mode
  "Install a menu for entering mathematical characters.
Uses window system menus only when they can display multilingual text.
Otherwise the menu-bar item activates the text-mode menu system.
This mode is only useful with a font which can display the maths repertoire."
  nil nil maths-menu-mode-map)

(provide 'maths-menu)
;;; maths-menu.el ends here