comparison yatexadd.el @ 77:1b172d26b55e

Fix auto-fill movement on Emacs21. Fix YaTeX:ref. Support jump/change on AMS-LaTeX's parentheses.
author yuuji
date Thu, 01 May 2003 13:38:27 +0000
parents f41b01fef5d6
children 0734be649cb8
comparison
equal deleted inserted replaced
76:c16a10460ce5 77:1b172d26b55e
1 ;;; -*- Emacs-Lisp -*- 1 ;;; -*- Emacs-Lisp -*-
2 ;;; YaTeX add-in functions. 2 ;;; YaTeX add-in functions.
3 ;;; yatexadd.el rev.14 3 ;;; yatexadd.el rev.15
4 ;;; (c )1991-2000 by HIROSE Yuuji.[yuuji@yatex.org] 4 ;;; (c )1991-2003 by HIROSE Yuuji.[yuuji@yatex.org]
5 ;;; Last modified Sat Sep 29 23:17:06 2001 on duke 5 ;;; Last modified Mon Mar 17 16:46:01 2003 on serow
6 ;;; $Id$ 6 ;;; $Id$
7 7
8 ;;; 8 ;;;
9 ;;Sample functions for LaTeX environment. 9 ;;Sample functions for LaTeX environment.
10 ;;; 10 ;;;
142 (concat (YaTeX:read-position "cbt") 142 (concat (YaTeX:read-position "cbt")
143 "{" (read-string "Width: ") "}")) 143 "{" (read-string "Width: ") "}"))
144 144
145 (defun YaTeX:thebibliography () 145 (defun YaTeX:thebibliography ()
146 (setq YaTeX-section-name "bibitem") 146 (setq YaTeX-section-name "bibitem")
147 "") 147 (concat "{" (read-string "Longest label: ") "}"))
148 148
149 ;;; 149 ;;;
150 ;;Sample functions for section-type command. 150 ;;Sample functions for section-type command.
151 ;;; 151 ;;;
152 (defun YaTeX:multiput () 152 (defun YaTeX:multiput ()
490 ((looking-at YaTeX-sectioning-regexp) 490 ((looking-at YaTeX-sectioning-regexp)
491 (skip-chars-forward "^{") 491 (skip-chars-forward "^{")
492 (forward-list 1) 492 (forward-list 1)
493 (skip-chars-forward " \t\n") 493 (skip-chars-forward " \t\n")
494 ;(setq boundary "[^\\]") 494 ;(setq boundary "[^\\]")
495 (setq inspoint (point))
495 (setq boundary 496 (setq boundary
496 (save-excursion 497 (save-excursion
497 (if (YaTeX-re-search-active-forward "[^\\]" r-escape nil 1) 498 (if (YaTeX-re-search-active-forward
499 (concat YaTeX-ec-regexp
500 "\\(" YaTeX-sectioning-regexp "\\|"
501 "begin\\|item\\)")
502 r-escape nil 1)
498 (match-beginning 0) 503 (match-beginning 0)
499 (1- (point)))))) 504 (1- (point))))))
500 ((looking-at "item\\s ") 505 ((looking-at "item\\s ")
501 (setq cc (+ cc 6)) 506 (setq cc (+ cc 6))
502 ;(setq boundary (concat YaTeX-ec-regexp "\\(item\\|begin\\|end\\)\\b")) 507 ;(setq boundary (concat YaTeX-ec-regexp "\\(item\\|begin\\|end\\)\\b"))
504 (save-excursion 509 (save-excursion
505 (if (YaTeX-re-search-active-forward 510 (if (YaTeX-re-search-active-forward
506 (concat YaTeX-ec-regexp "\\(item\\|begin\\|end\\)\\b") 511 (concat YaTeX-ec-regexp "\\(item\\|begin\\|end\\)\\b")
507 r-escape nil 1) 512 r-escape nil 1)
508 (match-beginning 0) 513 (match-beginning 0)
509 (1- (point)))))) 514 (1- (point))))
515 inspoint boundary))
510 ((looking-at "bibitem") 516 ((looking-at "bibitem")
511 (setq labelholder "bibitem") ; label holder is bibitem itself 517 (setq labelholder "bibitem") ; label holder is bibitem itself
512 (setq boundary 518 (setq boundary
513 (save-excursion 519 (save-excursion
514 (if (YaTeX-re-search-active-forward 520 (if (YaTeX-re-search-active-forward
515 (concat YaTeX-ec-regexp "\\(bibitem\\|end\\)\\b") 521 (concat YaTeX-ec-regexp "\\(bibitem\\|end\\)\\b")
516 r-escape nil 1) 522 r-escape nil 1)
517 (match-beginning 0) 523 (match-beginning 0)
518 (1- (point)))))) 524 (1- (point))))
525 inspoint boundary))
519 ((string-match YaTeX::ref-mathenv-regexp 526 ((string-match YaTeX::ref-mathenv-regexp
520 (setq env (or (YaTeX-inner-environment t) "document"))) 527 (setq env (or (YaTeX-inner-environment t) "document")))
521 (setq mathp t) 528 (setq mathp t)
522 ;;(setq boundary (concat YaTeX-ec-regexp "\\(\\\\\\|end{" env "}\\)")) 529 ;;(setq boundary (concat YaTeX-ec-regexp "\\(\\\\\\|end{" env "}\\)"))
523 (setq boundary 530 (setq boundary
524 (save-excursion 531 (save-excursion
525 (if (YaTeX-re-search-active-forward 532 (if (YaTeX-re-search-active-forward
526 (concat YaTeX-ec-regexp "\\(\\\\\\|end{" env "}\\)") 533 (concat YaTeX-ec-regexp "\\(\\\\\\|end{" env "}\\)")
527 r-escape nil 1) 534 r-escape nil 1)
528 (match-beginning 0) 535 (match-beginning 0)
529 (1- (point)))))) 536 (1- (point))))
537 inspoint boundary))
530 ((looking-at "footnote\\s *{") 538 ((looking-at "footnote\\s *{")
531 (skip-chars-forward "^{") ;move onto `{' 539 (skip-chars-forward "^{") ;move onto `{'
532 (setq boundary 540 (setq boundary
533 (save-excursion 541 (save-excursion
534 (condition-case err 542 (condition-case err
535 (forward-list 1) 543 (forward-list 1)
536 (error (error "\\\\footnote at point %s's brace not closed" 544 (error (error "\\\\footnote at point %s's brace not closed"
537 (point)))) 545 (point))))
538 (1- (point))))) 546 (1- (point)))
547 inspoint boundary))
539 ((looking-at "caption\\|\\(begin\\)") 548 ((looking-at "caption\\|\\(begin\\)")
540 (skip-chars-forward "^{") 549 (skip-chars-forward "^{")
541 (if (match-beginning 1) (forward-list 1)) 550 ;;;;;;(if (match-beginning 1) (forward-list 1))
551 ;; caption can be treated as mathenv, is it right??
552 (forward-list 1)
542 ;;(setq boundary (concat YaTeX-ec-regexp "\\(begin\\|end\\)\\b")) 553 ;;(setq boundary (concat YaTeX-ec-regexp "\\(begin\\|end\\)\\b"))
554 (setq inspoint (point))
543 (setq boundary 555 (setq boundary
544 (save-excursion 556 (save-excursion
545 (if (YaTeX-re-search-active-forward 557 (if (YaTeX-re-search-active-forward
546 (concat YaTeX-ec-regexp "\\(begin\\|end\\)\\b") 558 (concat YaTeX-ec-regexp "\\(begin\\|end\\)\\b")
547 r-escape nil 1) 559 r-escape nil 1)
564 (skip-chars-forward "^{") (1+ (point))) 576 (skip-chars-forward "^{") (1+ (point)))
565 (progn 577 (progn
566 (forward-sexp 1) (1- (point)))) 578 (forward-sexp 1) (1- (point))))
567 ;;else make a label 579 ;;else make a label
568 ;(goto-char (match-beginning 0)) 580 ;(goto-char (match-beginning 0))
569 (goto-char boundary) 581 (goto-char inspoint)
570 (skip-chars-backward " \t\n") 582 (skip-chars-backward " \t\n")
571 (save-excursion (setq newlabel (YaTeX::ref-generate-label))) 583 (save-excursion (setq newlabel (YaTeX::ref-generate-label)))
572 (delete-region (point) (progn (skip-chars-backward " \t") (point))) 584 (delete-region (point) (progn (skip-chars-backward " \t") (point)))
573 (if mathp nil 585 (if mathp nil
574 (insert "\n") 586 (insert "\n")
576 (insert (format "\\label{%s}" newlabel)) 588 (insert (format "\\label{%s}" newlabel))
577 newlabel)))) 589 newlabel))))
578 590
579 (defvar YaTeX::ref-labeling-regexp-alist 591 (defvar YaTeX::ref-labeling-regexp-alist
580 '(("\\\\begin{java}{\\([^}]+\\)}" . 1) 592 '(("\\\\begin{java}{\\([^}]+\\)}" . 1)
581 ("\\\\elabel{\\([^}]+\\)}" . 1))) 593 ("\\\\label{\\([^}]+\\)}" . 1)))
582 (defvar YaTeX::ref-labeling-regexp 594 (defvar YaTeX::ref-labeling-regexp
583 (mapconcat 'car YaTeX::ref-labeling-regexp-alist "\\|")) 595 (mapconcat 'car YaTeX::ref-labeling-regexp-alist "\\|"))
584 (defvar YaTeX::ref-mathenv-regexp 596 (defvar YaTeX::ref-mathenv-regexp
585 "equation\\|eqnarray\\|align\\|gather\\|alignat\\|xalignat") 597 "equation\\|eqnarray\\|align\\|gather\\|alignat\\|xalignat")
586 (defvar YaTeX::ref-enumerateenv-regexp 598 (defvar YaTeX::ref-enumerateenv-regexp
612 (lambda (s) 624 (lambda (s)
613 (if (>= llv (cdr s)) 625 (if (>= llv (cdr s))
614 (car s)))) 626 (car s))))
615 YaTeX-sectioning-level)) 627 YaTeX-sectioning-level))
616 "\\|") 628 "\\|")
617 "\\|caption\\|footnote\\){" 629 "\\|caption\\(\\[[^]]+\\]\\)?\\|footnote\\){"
618 "\\|\\(begin{\\(" mathenvs "\\|" enums "\\)\\)\\)"))) 630 "\\|\\(begin{\\(" mathenvs "\\|" enums "\\)\\)\\)")))
619 (regexp (concat "\\(" counter 631 (regexp (concat "\\(" counter
620 "\\)\\|\\(" YaTeX::ref-labeling-regexp "\\)")) 632 "\\)\\|\\(" YaTeX::ref-labeling-regexp "\\)"))
621 (itemsep (concat YaTeX-ec-regexp 633 (itemsep (concat YaTeX-ec-regexp
622 "\\(\\(bib\\)?item\\|begin\\|end\\)")) 634 "\\(\\(bib\\)?item\\|begin\\|end\\)"))
704 (if (re-search-forward itemsep nil t) 716 (if (re-search-forward itemsep nil t)
705 (progn (goto-char (match-beginning 0)) 717 (progn (goto-char (match-beginning 0))
706 (skip-chars-backward " \t") 718 (skip-chars-backward " \t")
707 (1- (point))) 719 (1- (point)))
708 (point-end-of-line))) 720 (point-end-of-line)))
709 x)))) 721 x))
710 722 (setq e0 (point-max))))
723 ;;else, simple section-type counter
711 ((= (char-after (1- (point))) ?{) 724 ((= (char-after (1- (point))) ?{)
712 (setq label (buffer-substring 725 (setq label (buffer-substring
713 (match-beginning 0) 726 (match-beginning 0)
714 (progn (forward-char -1) 727 (progn (forward-char -1)
715 (forward-list 1) 728 (forward-list 1)
716 (point)))) 729 (point))))
717 (funcall output label match-point)) 730 (funcall output label match-point)
731 ;; Skip preceding label if exists
732 (if (save-excursion
733 (skip-chars-forward "\t \n")
734 (looking-at YaTeX::ref-labeling-regexp))
735 (setq e0 (match-end 0))))
718 (t 736 (t
719 (skip-chars-forward " \t") 737 (skip-chars-forward " \t")
720 (setq label (buffer-substring 738 (setq label (buffer-substring
721 (match-beginning 0) 739 (match-beginning 0)
722 (if (re-search-forward 740 (if (re-search-forward
726 (goto-char (match-beginning 0)) 744 (goto-char (match-beginning 0))
727 (skip-chars-backward " \t") 745 (skip-chars-backward " \t")
728 (1- (point))) 746 (1- (point)))
729 (point-end-of-line)))) 747 (point-end-of-line))))
730 (funcall output label match-point) 748 (funcall output label match-point)
731 )) 749 (if (save-excursion
750 (skip-chars-forward "\t \n")
751 (looking-at YaTeX::ref-labeling-regexp))
752 (setq e0 (match-end 0)))))
732 ) ;;put label buffer 753 ) ;;put label buffer
733 ;; 754 ;;
734 ;; if user defined label found 755 ;; if user defined label found
735 (t 756 (t
736 ;; memorize line number and label into property 757 ;; memorize line number and label into property
832 (forward-char 1) 853 (forward-char 1)
833 (skip-chars-forward "^,")) 854 (skip-chars-forward "^,"))
834 (point))))))))) 855 (point)))))))))
835 (setq files (cdr files)))))) 856 (setq files (cdr files))))))
836 857
858 (defvar YaTeX::cite-bibitem-macro-regexp "bibitem\\|harvarditem"
859 "*Regexp of macro name of bibitem definition")
860
837 (defun YaTeX::cite-collect-bibs-internal () 861 (defun YaTeX::cite-collect-bibs-internal ()
838 "Collect bibentry in the current buffer and print them to standard output." 862 "Collect bibentry in the current buffer and print them to standard output."
839 (let ((ptn (concat YaTeX-ec-regexp "bibitem\\b")) 863 (let ((ptn (concat YaTeX-ec-regexp
864 "\\(" YaTeX::cite-bibitem-macro-regexp "\\)\\b"))
840 (pcnt (regexp-quote YaTeX-comment-prefix))) 865 (pcnt (regexp-quote YaTeX-comment-prefix)))
841 (save-excursion 866 (save-excursion
842 (while (YaTeX-re-search-active-forward ptn pcnt nil t) 867 (while (YaTeX-re-search-active-forward ptn pcnt nil t)
843 (skip-chars-forward "^{\n") 868 (skip-chars-forward "^{\n")
844 (or (eolp) 869 (or (eolp)
882 (YaTeX-match-string 1) ","))) 907 (YaTeX-match-string 1) ",")))
883 ;;(2)search internal 908 ;;(2)search internal
884 (YaTeX::cite-collect-bibs-internal))) 909 (YaTeX::cite-collect-bibs-internal)))
885 ;;Now bbuf holds the list of bibitem 910 ;;Now bbuf holds the list of bibitem
886 (set-buffer bbuf) 911 (set-buffer bbuf)
887 (YaTeX::ref argp "\\\\\\(bibitem\\)\\(\\[.*\\]\\)?" "cite")))) 912 (YaTeX::ref
888 913 argp
914 (concat "\\\\\\("
915 YaTeX::cite-bibitem-macro-regexp
916 "\\)\\(\\[.*\\]\\)?")
917 "cite"))))
918
889 (t nil))) 919 (t nil)))
890 920
921 ;;; for AMS-LaTeX
891 (and YaTeX-use-AMS-LaTeX (fset 'YaTeX::eqref 'YaTeX::ref)) 922 (and YaTeX-use-AMS-LaTeX (fset 'YaTeX::eqref 'YaTeX::ref))
923 ;;; for Harvard citation style
924 (fset 'YaTeX::citeasnoun 'YaTeX::cite)
925 (fset 'YaTeX::possessivecite 'YaTeX::cite)
926 (fset 'YaTeX::citeyear 'YaTeX::cite)
927 (fset 'YaTeX::citename 'YaTeX::cite)
892 928
893 (defun YaTeX-yatex-buffer-list () 929 (defun YaTeX-yatex-buffer-list ()
894 (save-excursion 930 (save-excursion
895 (delq nil (mapcar (function (lambda (buf) 931 (delq nil (mapcar (function (lambda (buf)
896 (set-buffer buf) 932 (set-buffer buf)

yatex.org