This file is indexed.

/usr/share/emacs/site-lisp/maxima/imath.el is in maxima-emacs 5.24.0-1build1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
;;;; imath.el --- Imath minor mode

;; Copyright (C) 2004, 2008 Yasuaki Honda
;; Copyright (C) 2007 bohumir for the {eps eps} formula support

;; Author: Yasuaki Honda (yhonda@mac.com)
;; Created: 7 Nov 2004
;; Version: 1.0b
;; Keywords: maxima

;; $Id: imath.el,v 1.5 2009/02/22 09:18:27 yasu-honda Exp $

;; This program 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 of
;; the License, or (at your option) any later version.
;;
;; This program 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 this program; if not, write to the Free
;; Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
;; MA 02111-1307 USA

;; How to install imath minor mode
;;  1. You need to install imaxima properly. (./configure;make;make install)
;;  2. Put (autoload 'imath-mode "imath" "Interactive Math minor mode." t)
;;  in the .emacs.el file.
;;
;; How to use imath minor node
;;  1. In a buffer, M-x imath-mode to enable imath minor mode.
;;  2. C-c [ to insert a template maxima form.
;;     C-c ] to insert a template latex form.
;;  3. Type any Maxima command input in the maxima template form:
;;     Ex: {maxima diff(f(x),x) maxima}
;;     Type any LaTeX command in the latex template form:
;;     Ex: {latex  \ifracd{d}{d\*x}\*f\left(x\right) latex}
;;  4. Type C-c ! to obtain an image of the formula.
;;  5. If you want to edit the maxima or latex command, place cursor
;;     right after the image and type C-c & to obtain the original
;;     maxima or latex form.
;;  6. You can save the buffer, however discarding all then formula
;;     images.  Formulas are saved as maxima forms or latex forms or
;;     both. On visiting the saved file, you can restore all the
;;     images by enabling the imath minor mode and then type C-c $.
;;  7. Imath mode can be automatically set by having the first line
;;     of the file like this:
;;     ;; -*- mode: imath -*-
;;  8. Imath mode enables you to export the buffer contents to
;;     HTML document. You can do so by typing M-x imath-to-html .
;;     A buffer is created to convert imath text to HTML. C-x C-s
;;     saves the buffer to the file whose name is the same as the
;;     original file but file extension being .html in the same
;;     folder as the original file.
;;     A folder is created to store all the formula images. They
;;     are referenced from the HTML document by using <IMG> tag.

(require 'cl)
(require 'imaxima)

(if (featurep 'xemacs)
    (require 'atomic-extents))

(define-minor-mode imath-mode
  "Toggle MathEdit mode.
     With no argument, this command toggles the mode.
     Non-null prefix argument turns on the mode.
     Null prefix argument turns off the mode.

The imath minor mode provides a small set of functions to aid
insert math formulas into plain text. 

A math formula is written using a Maxima form whose syntax is
{maxima a formula maxima} where a formula is a string which can
be accepted as Maxima command input. C-c [ inserts a template
for a maxima form. 

The other way to write a math formula is to use LaTeX form
whose syntax is {latex a formula latex} where a formula is 
a valid LaTeX commands. C-c ] inserts a template for a latex
form.

Example maxima and latex forms are:
{maxima integrate(f(x),x) maxima}
{maxima sum(a[n],n,0,i) maxima}
{latex  \\int {f\\left(x\\right)}{\\;dx} latex}
{latex  \\sum_{n=0}^{i}{a_{n}} latex}

Version 1.0 beta and later supports inline graph. You can use
the following six maxima commands in maxima forms:
wxplot2d(), wxplot3d(), wxdraw2d(), wxdraw3d(), wximplicit_plot(),
wxcontour_plot().

Example maxima forms for inline graph are:
{maxima wxplot2d(sin(5*x)/x,[x,-5,5]) maxima}
{maxima wxplot3d(sin(x)*y,[x,-5,5],[y,-5,5]) maxima}
{maxima wxdraw2d(implicit(x^2+y^3=5,x,-5,5,y,-5,5)) maxima}

Removing the prefix \"wx\" from the commands above, you obtain
command names that are described in Maxima manual. The documentation
applies to the \"wx\" version of the commands.

Version 1.0 beta and later supports inline EPS image. You can
insert arbitrary image files in EPS format using the following
syntax:
{eps filename eps}

An example is:
{eps /home/george/image1.eps eps}

Assuming the cursor position is right after a form or in the
middle, C-c ! transforms the form into the formula image using
the Imaxima functionality.

If the resulting image is not what you want, you may want to edit
the formula again. To do this, place the cursor right after the
image and C-c &. Then the image is removed and original form
appears at the position.

When saving the buffer into a file, images are
discarded. However, maxima forms and their correspoding latex
forms are kept there in the text. If the text is loaded again
into Emacs and imath minor mode is enabled, you can type C-c $ to
restore all the images for the forms in the buffer.

Imath mode enables you to export the buffer contents to
HTML document. You can do so by typing M-x imath-to-html .
A buffer is created to convert imath text to HTML. C-x C-s
saves the buffer to the file whose name is the same as the
original file but file extension being .html in the same
folder as the original file.

A folder is created to store all the formula images. They
are referenced from the HTML document by using <IMG> tag.
"
     
  ;; The initial value.
  nil
  ;; The indicator for the mode line.
  " iMath"
  ;; The minor mode bindings.
  '(("\C-c[" . compose-maxima-formula)
    ("\C-c]" . compose-latex-formula)
    ("\C-c!" . form-to-image)
    ("\C-c$" . buffer-formula-to-image)
    ("\C-c&" . remove-maxima-formula-image)
    )
  ;; body
  ;; Imath requires *imaxima* running.
  (progn
    (let ((cur-buf (current-buffer)))
      (save-current-buffer
	(imaxima))
      (switch-to-buffer cur-buf))))

;;; Continuation is used between maxima-to-image function and
;;; get-image-from-imaxima. The value is either nil or a list of
;;; buffer, pos1, and pos2, where pos1 and pos2 are the beginning and
;;; end of current maxima formula.
;;  (func buffer pos1 pos2)

(defvar continuation nil)
(defvar maxima-start "{maxima ")
(defvar maxima-end " maxima}")
(defvar latex-start "{latex ")
(defvar latex-end " latex}")
(defvar eps-start "{eps ")
(defvar eps-end " eps}")

(defun compose-maxima-formula ()
  "Insert maxima form template at the current position."
  (interactive "")
  (insert "{maxima  maxima}")
  (backward-char 8))

(defun compose-latex-formula ()
  "Insert maxima form template at the current position."
  (interactive "")
  (insert "{latex  latex}")
  (backward-char 7))

(defun* find-formula (ftype)
  (let (start-symbol end-symbol tmpresult)
    (cond ((eql ftype 'maxima)
	   (setq start-symbol maxima-start
		 end-symbol maxima-end))
	  ((eql ftype 'latex)
	   (setq start-symbol latex-start
		 end-symbol latex-end))
          ((eql ftype 'eps)
	   (setq start-symbol eps-start
		 end-symbol eps-end))
	  ((eql ftype 'both)
	   (save-excursion
	     (multiple-value-bind (la-start la-end la-type)
		 (find-formula 'latex)
	       (if (not (and la-start la-end la-type))
		   (return-from find-formula nil)
		 (goto-char (1- la-start))
		 (if (not (string= (buffer-substring (point) (1+ (point)))
				   "&"))
		     (return-from find-formula nil))
		 (multiple-value-bind (mx-start mx-end mx-type)
		     (find-formula 'maxima)
		   (if (not (and mx-start mx-end mx-type))
		       (return-from find-formula nil))
		   (return-from find-formula
		     (values mx-start la-end 'both)))))))
	  ((eql ftype 'any)
	   (cond ((setq tmpresult (find-formula 'both))
		  (return-from find-formula tmpresult))
		 ((setq tmpresult (find-formula 'latex))
		  (return-from find-formula tmpresult))
		 ((setq tmpresult (find-formula 'maxima))
		  (return-from find-formula tmpresult))
		 ((setq tmpresult (find-formula 'eps))
		  (return-from find-formula tmpresult))
		 (t 
		  (return-from find-formula nil))))
	  (t (return-from find-formula nil)))
    (save-excursion
      (let (begin end (curpos (point)))
	(setq begin (search-backward start-symbol (point-min) t))
	(setq end (search-forward end-symbol (point-max) t))
	(if (and (numberp begin) (numberp end) ;; {start-symbol ... end-symbol} is found.
		 (or (and (> end curpos) (> curpos begin)) ;; {start-symbol ... curpos ... end-symbol}
		     (= curpos end))) ;;  {start-symbol ... end-symbol}}curpos
	    (values begin end ftype)
	  nil)))))

(defun remove-maxima-formula-image (arg)
  (interactive "P")
  (save-excursion
    (multiple-value-bind (begin end ftype)
	(find-formula 'any)
      (when (and begin end ftype)
	(if (featurep 'xemacs)
	    (let ((ext (extent-at begin)))
	      (if ext (delete-extent ext)))
	  (remove-text-properties begin end '(display) (current-buffer)))
	(if (eql ftype 'both)
	    (multiple-value-bind (la-begin la-end la-ftype)
		(find-formula 'latex)
	      (when (and (not arg) la-begin la-end la-ftype)
		;; remove & between the maxima formula and latex formula
		;; if that is the case.
		(if (eql ftype 'both) (decf la-begin))
		(delete-region la-begin la-end))))))))

(defun form-to-image ()
  "Convert any form to image based on form types"
  (interactive "")
  (multiple-value-bind (start end ftype)
      (find-formula 'any)
    (if (and start end ftype)
	(cond ((eql ftype 'maxima)
	       (maxima-to-image))
	      ((eql ftype 'eps)
	       (get-image-from-imaxima 'eps))
	      ((or (eql ftype 'both)
		   (eql ftype 'latex))
	       (get-image-from-imaxima 'latex)
	       )
	      )
      )
    )
  )

(defun* maxima-to-image (&aux maxcmd)
  "Transform a maxima form which is placed just before current point or
is surrounding the current point into a formula image."
  (interactive "")
  (save-excursion
    (multiple-value-bind (begin end)
	(find-formula 'maxima)
      (let (curpos (point))
	(when (and begin end)
	  (setq maxcmd (buffer-substring (+ begin (length maxima-start))
				      (- end (length maxima-end))))
	  (kill-new (buffer-substring (+ begin (length maxima-start))
				      (- end (length maxima-end))))
	  (save-excursion
	    (set-buffer (if imaxima-use-maxima-mode-flag
			    "*maxima*"
			  "*imaxima*"))
	    (yank)
	    (insert ";")
	    (comint-send-input))))
      (if continuation
	  (debug-imaxima-filter "continuation exits"))
      (setq continuation (list (if (string-match "[ 	]*wx\\(plot2d\\|plot3d\\|draw\\|draw2d\\|draw3d\\|implicit_plot\\|contour_plot\\).*" maxcmd)
				   #'get-inline-graph
				 #'get-image-from-imaxima-1)
			       (current-buffer) begin end)))))

(defun* maxima-to-image-all (&aux maxcmd)
  "Transform a maxima form which is placed just before current point or
is surrounding the current point into a formula image."
  (interactive "")
  (if (not (re-search-forward "maxima}[^&]" (point-max) 0))
      (progn
	(setq continuation nil)
	(return-from maxima-to-image-all nil)))
  (backward-char)
  (multiple-value-bind (begin end)
      (find-formula 'maxima)
    (when (and begin end)
      (setq maxcmd (buffer-substring (+ begin (length maxima-start))
				     (- end (length maxima-end))))
      (kill-new (buffer-substring (+ begin (length maxima-start))
				  (- end (length maxima-end))))
      (save-excursion
	(set-buffer (if imaxima-use-maxima-mode-flag
			"*maxima*"
		      "*imaxima*"))
	(yank)
	(insert ";")
	(comint-send-input))
      (if continuation
	  (debug-imaxima-filter "continuation exits"))
      (setq continuation (list (if (string-match "[ 	]*wx\\(plot2d\\|plot3d\\|draw\\|draw2d\\|draw3d\\|implicit_plot\\|contour_plot\\).*" maxcmd)
				   #'(lambda (arg)
				   (let ((cont continuation))
				     (funcall #'get-inline-graph arg)
				     (save-current-buffer
				       (set-buffer (nth 1 cont))
				       (maxima-to-image-all))))
			     #'(lambda (arg)
				 (let ((cont continuation))
				   (funcall #'get-image-from-imaxima-1 arg)
				   (save-current-buffer
				     (set-buffer (nth 1 cont))
				     (maxima-to-image-all)))))
			   (current-buffer) begin end)))))


(defun* get-image-from-imaxima (eps-or-latex)
  "Converts a both form or a latex form into a formula image when
placed right after the form."
  (interactive "")
  (let (la-start la-end la-ftype entire-start entire-end entire-ftype
		 entire-string latex-formula-or-epsfile)

    (multiple-value-bind (la-start la-end la-ftype)
	(find-formula eps-or-latex)
      (when (and la-start la-end la-ftype)
	(setq entire-string (buffer-substring la-start la-end))
	(cond ((eql eps-or-latex 'latex)
	       (setq latex-formula-or-epsfile (substring entire-string
							 (length latex-start)
							 (- (length entire-string)
							    (length latex-end))))
	       )
	      ((eql eps-or-latex 'eps)
	       (setq latex-formula-or-epsfile (substring entire-string
							 (length eps-start)
							 (- (length entire-string)
							    (length eps-end))))
	       )
	      )
	(multiple-value-bind (entire-start entire-end entire-ftype)
	    (find-formula 'any)
	  (when (and entire-start entire-end entire-ftype)
	    (if (featurep 'xemacs)
		(progn
		  (let ((ext (extent-at entire-start)))
		    (if ext
			(return-from get-image-from-imaxima nil)))
		  
		  (cond ((eql eps-or-latex 'latex)
			 (let ((ext (extent-at 0 (imaxima-make-image latex-formula-or-epsfile eps-or-latex  t))))
			   (if ext
			       (insert-extent ext entire-start entire-end t (current-buffer))))
			 )
			((eql eps-or-latex 'eps)
			 (let ((ext (extent-at 0 (imaxima-make-image latex-formula-or-epsfile eps-or-latex  t))))
			   (if ext
			       (insert-extent ext entire-start entire-end t (current-buffer))))
			 )
			)
		  )

	      ;; FSF Emacs
	      (add-text-properties entire-start entire-end
				   (list 'display
					 (get-text-property 1
							    'display
							    (imaxima-make-image latex-formula-or-epsfile eps-or-latex t)))
				   (current-buffer)))))))))

(defun get-image-from-imaxima-1 (latex-string)
  (setq latex-string (copy-sequence latex-string))
  (if (featurep 'xemacs)
      (let ((ext (extent-at 0 latex-string)))
	(if ext (set-extent-property ext 'duplicable nil))))
  (while (string-match "^([\\%a-zA-Z0-9]+)" latex-string)
    (setq latex-string (replace-match "" t t latex-string)))
  (if continuation
      (let ((maxima-string (save-current-buffer
			     (set-buffer (nth 1 continuation))
			     (buffer-substring (nth 2 continuation)
					       (nth 3 continuation))))
	    pos)
	(save-current-buffer
	  (set-buffer (nth 1 continuation))
	  (setq pos (copy-marker (nth 2 continuation) t))
	  (delete-region (nth 2 continuation) (nth 3 continuation))
	  (setq continuation nil)
	  (let ((str-to-insert (concat maxima-string "&{latex " latex-string " latex}")))
	    (if (featurep 'xemacs)
		(let ((ext (extent-at 0 (imaxima-make-image latex-string 'latex t))))
		  (if ext
		      (insert-extent ext 0 (length str-to-insert) t str-to-insert)))
	      (add-text-properties 0 (length str-to-insert)
				   (list 'display
					 (get-text-property 1
							    'display
							    (imaxima-make-image latex-string 'latex  t)))
				   str-to-insert))
	    (goto-char pos)
	    (insert str-to-insert))))))

(defun get-inline-graph (latex-string)
  (setq latex-string (copy-sequence latex-string))
  (if (featurep 'xemacs)
      (let ((ext (extent-at 0 latex-string)))
	(if ext (set-extent-property ext 'duplicable nil))))
  (when (string-match "^([\\%a-zA-Z0-9]+)" latex-string)
    (setq latex-string (replace-match "" t t latex-string)))
  (if continuation
      (let ((maxima-string (save-current-buffer
			     (set-buffer (nth 1 continuation))
			     (buffer-substring (nth 2 continuation)
					       (nth 3 continuation)))))
	(save-current-buffer
	  (set-buffer (nth 1 continuation))
	  (delete-region (nth 2 continuation) (nth 3 continuation))
	  (setq continuation nil)
	  (let ((str-to-insert maxima-string))
	    (if (featurep 'xemacs)
		(let ((ext (extent-at 0 (imaxima-make-image latex-string 'latex t))))
		  (if ext
		      (insert-extent ext 0 (length str-to-insert) t str-to-insert)))
	      (add-text-properties 0 (length str-to-insert)
				   (list 'display
					 (get-text-property 1 'display latex-string))
				   str-to-insert))
	    (insert str-to-insert))))))


(defun buffer-formula-to-image ()
  "Transform all the latex forms and maxima&latex forms into
formula images." 
  (interactive "")
  (beginning-of-buffer)
  (let ((msg "Converting latex"))
    (message msg)
    (while (search-forward latex-end nil 1)
      (get-image-from-imaxima 'latex)
      (setq msg (concat msg "."))
      (message msg))
    (message (concat msg ".done.")))
  (beginning-of-buffer)
  (let ((msg "Converting eps"))
    (while (search-forward eps-end nil 1)
      (get-image-from-imaxima 'eps)
      (setq msg (concat msg "."))
      (message msg))
    (message (concat msg ".done.")))
  (beginning-of-buffer)
  (let ((msg "Converting maxima..."))
    (message msg)
    (maxima-to-image-all)
    (message (concat msg "done.")))
  (set-buffer-modified-p nil))


(provide 'imath)

;;; imath.el ends here