499 |
(bold (regexp-opt '("textbf" "textsc" "textup" |
(bold (regexp-opt '("textbf" "textsc" "textup" |
500 |
"boldsymbol" "pmb") t)) |
"boldsymbol" "pmb") t)) |
501 |
(italic (regexp-opt '("textit" "textsl" "emph") t)) |
(italic (regexp-opt '("textit" "textsl" "emph") t)) |
502 |
(type (regexp-opt '("texttt" "textmd" "textrm" "textsf") t)) |
;; FIXME: unimplemented yet. |
503 |
|
;; (type (regexp-opt '("texttt" "textmd" "textrm" "textsf") t)) |
504 |
;; |
;; |
505 |
;; Names of commands whose arg should be fontified as a citation. |
;; Names of commands whose arg should be fontified as a citation. |
506 |
(citations (regexp-opt |
(citations (regexp-opt |
714 |
(defvar latex-mode-map |
(defvar latex-mode-map |
715 |
(let ((map (make-sparse-keymap))) |
(let ((map (make-sparse-keymap))) |
716 |
(set-keymap-parent map tex-mode-map) |
(set-keymap-parent map tex-mode-map) |
717 |
|
(define-key map "\C-c\C-s" 'latex-split-block) |
718 |
map) |
map) |
719 |
"Keymap for `latex-mode'. See also `tex-mode-map'.") |
"Keymap for `latex-mode'. See also `tex-mode-map'.") |
720 |
|
|
747 |
|
|
748 |
;; This would be a lot simpler if we just used a regexp search, |
;; This would be a lot simpler if we just used a regexp search, |
749 |
;; but then it would be too slow. |
;; but then it would be too slow. |
750 |
;;;###autoload |
(defun tex-guess-mode () |
|
(defun tex-mode () |
|
|
"Major mode for editing files of input for TeX, LaTeX, or SliTeX. |
|
|
Tries to determine (by looking at the beginning of the file) whether |
|
|
this file is for plain TeX, LaTeX, or SliTeX and calls `plain-tex-mode', |
|
|
`latex-mode', or `slitex-mode', respectively. If it cannot be determined, |
|
|
such as if there are no commands in the file, the value of `tex-default-mode' |
|
|
says which mode to use." |
|
|
(interactive) |
|
751 |
(let ((mode tex-default-mode) slash comment) |
(let ((mode tex-default-mode) slash comment) |
752 |
(save-excursion |
(save-excursion |
753 |
(goto-char (point-min)) |
(goto-char (point-min)) |
772 |
'plain-tex-mode)))) |
'plain-tex-mode)))) |
773 |
(funcall mode))) |
(funcall mode))) |
774 |
|
|
775 |
|
;; `tex-mode' plays two roles: it's the parent of several sub-modes |
776 |
|
;; but it's also the function that chooses between those submodes. |
777 |
|
;; To tell the difference between those two cases where the function |
778 |
|
;; might be called, we check `delay-mode-hooks'. |
779 |
|
;;;###autoload |
780 |
|
(define-derived-mode tex-mode text-mode "generic-TeX" |
781 |
|
(tex-common-initialization)) |
782 |
|
(fset 'tex-mode |
783 |
|
`(lambda () |
784 |
|
"Major mode for editing files of input for TeX, LaTeX, or SliTeX. |
785 |
|
Tries to determine (by looking at the beginning of the file) whether |
786 |
|
this file is for plain TeX, LaTeX, or SliTeX and calls `plain-tex-mode', |
787 |
|
`latex-mode', or `slitex-mode', respectively. If it cannot be determined, |
788 |
|
such as if there are no commands in the file, the value of `tex-default-mode' |
789 |
|
says which mode to use." |
790 |
|
(interactive) |
791 |
|
(if delay-mode-hooks |
792 |
|
;; We're called from one of the children already. |
793 |
|
(funcall ,(symbol-function 'tex-mode)) |
794 |
|
(tex-guess-mode)))) |
795 |
|
|
796 |
;;;###autoload |
;;;###autoload |
797 |
(defalias 'TeX-mode 'tex-mode) |
(defalias 'TeX-mode 'tex-mode) |
798 |
;;;###autoload |
;;;###autoload |
801 |
(defalias 'LaTeX-mode 'latex-mode) |
(defalias 'LaTeX-mode 'latex-mode) |
802 |
|
|
803 |
;;;###autoload |
;;;###autoload |
804 |
(define-derived-mode plain-tex-mode text-mode "TeX" |
(define-derived-mode plain-tex-mode tex-mode "TeX" |
805 |
"Major mode for editing files of input for plain TeX. |
"Major mode for editing files of input for plain TeX. |
806 |
Makes $ and } display the characters they match. |
Makes $ and } display the characters they match. |
807 |
Makes \" insert `` when it seems to be the beginning of a quotation, |
Makes \" insert `` when it seems to be the beginning of a quotation, |
841 |
Entering Plain-tex mode runs the hook `text-mode-hook', then the hook |
Entering Plain-tex mode runs the hook `text-mode-hook', then the hook |
842 |
`tex-mode-hook', and finally the hook `plain-tex-mode-hook'. When the |
`tex-mode-hook', and finally the hook `plain-tex-mode-hook'. When the |
843 |
special subshell is initiated, the hook `tex-shell-hook' is run." |
special subshell is initiated, the hook `tex-shell-hook' is run." |
844 |
(tex-common-initialization) |
(set (make-local-variable 'tex-command) tex-run-command) |
845 |
(setq tex-command tex-run-command) |
(set (make-local-variable 'tex-start-of-header) "%\\*\\*start of header") |
846 |
(setq tex-start-of-header "%\\*\\*start of header") |
(set (make-local-variable 'tex-end-of-header) "%\\*\\*end of header") |
847 |
(setq tex-end-of-header "%\\*\\*end of header") |
(set (make-local-variable 'tex-trailer) "\\bye\n")) |
|
(setq tex-trailer "\\bye\n") |
|
|
(run-hooks 'tex-mode-hook)) |
|
848 |
|
|
849 |
;;;###autoload |
;;;###autoload |
850 |
(define-derived-mode latex-mode text-mode "LaTeX" |
(define-derived-mode latex-mode tex-mode "LaTeX" |
851 |
"Major mode for editing files of input for LaTeX. |
"Major mode for editing files of input for LaTeX. |
852 |
Makes $ and } display the characters they match. |
Makes $ and } display the characters they match. |
853 |
Makes \" insert `` when it seems to be the beginning of a quotation, |
Makes \" insert `` when it seems to be the beginning of a quotation, |
887 |
Entering Latex mode runs the hook `text-mode-hook', then |
Entering Latex mode runs the hook `text-mode-hook', then |
888 |
`tex-mode-hook', and finally `latex-mode-hook'. When the special |
`tex-mode-hook', and finally `latex-mode-hook'. When the special |
889 |
subshell is initiated, `tex-shell-hook' is run." |
subshell is initiated, `tex-shell-hook' is run." |
890 |
(tex-common-initialization) |
(set (make-local-variable 'tex-command) latex-run-command) |
891 |
(setq tex-command latex-run-command) |
(set (make-local-variable 'tex-start-of-header) |
892 |
(setq tex-start-of-header "\\\\document\\(style\\|class\\)") |
"\\\\document\\(style\\|class\\)") |
893 |
(setq tex-end-of-header "\\\\begin\\s-*{document}") |
(set (make-local-variable 'tex-end-of-header) "\\\\begin\\s-*{document}") |
894 |
(setq tex-trailer "\\end\\s-*{document}\n") |
(set (make-local-variable 'tex-trailer) "\\end\\s-*{document}\n") |
895 |
;; A line containing just $$ is treated as a paragraph separator. |
;; A line containing just $$ is treated as a paragraph separator. |
896 |
;; A line starting with $$ starts a paragraph, |
;; A line starting with $$ starts a paragraph, |
897 |
;; but does not separate paragraphs if it has more stuff on it. |
;; but does not separate paragraphs if it has more stuff on it. |
898 |
(setq paragraph-start |
(setq paragraph-start |
899 |
(concat "[\f%]\\|[ \t]*\\($\\|\\$\\$\\|" |
(concat "[ \t]*\\(\\$\\$\\|" |
900 |
"\\\\[][]\\|" |
"\\\\[][]\\|" |
901 |
"\\\\" (regexp-opt (append |
"\\\\" (regexp-opt (append |
902 |
(mapcar 'car latex-section-alist) |
(mapcar 'car latex-section-alist) |
926 |
(set (make-local-variable 'outline-regexp) latex-outline-regexp) |
(set (make-local-variable 'outline-regexp) latex-outline-regexp) |
927 |
(set (make-local-variable 'outline-level) 'latex-outline-level) |
(set (make-local-variable 'outline-level) 'latex-outline-level) |
928 |
(set (make-local-variable 'forward-sexp-function) 'latex-forward-sexp) |
(set (make-local-variable 'forward-sexp-function) 'latex-forward-sexp) |
929 |
(set (make-local-variable 'skeleton-end-hook) nil) |
(set (make-local-variable 'skeleton-end-hook) nil)) |
|
(run-hooks 'tex-mode-hook)) |
|
930 |
|
|
931 |
;;;###autoload |
;;;###autoload |
932 |
(define-derived-mode slitex-mode latex-mode "SliTeX" |
(define-derived-mode slitex-mode latex-mode "SliTeX" |
974 |
(setq tex-start-of-header "\\\\documentstyle{slides}\\|\\\\documentclass{slides}")) |
(setq tex-start-of-header "\\\\documentstyle{slides}\\|\\\\documentclass{slides}")) |
975 |
|
|
976 |
(defun tex-common-initialization () |
(defun tex-common-initialization () |
|
(set-syntax-table tex-mode-syntax-table) |
|
977 |
;; Regexp isearch should accept newline and formfeed as whitespace. |
;; Regexp isearch should accept newline and formfeed as whitespace. |
978 |
(set (make-local-variable 'search-whitespace-regexp) "[ \t\r\n\f]+") |
(set (make-local-variable 'search-whitespace-regexp) "[ \t\r\n\f]+") |
979 |
;; A line containing just $$ is treated as a paragraph separator. |
;; A line containing just $$ is treated as a paragraph separator. |
1080 |
(num-matches 0)) |
(num-matches 0)) |
1081 |
(with-output-to-temp-buffer "*Occur*" |
(with-output-to-temp-buffer "*Occur*" |
1082 |
(princ "Mismatches:\n") |
(princ "Mismatches:\n") |
1083 |
(save-excursion |
(with-current-buffer standard-output |
|
(set-buffer standard-output) |
|
1084 |
(occur-mode) |
(occur-mode) |
1085 |
;; This won't actually work...Really, this whole thing should |
;; This won't actually work...Really, this whole thing should |
1086 |
;; be rewritten instead of being a hack on top of occur. |
;; be rewritten instead of being a hack on top of occur. |
1097 |
(forward-char 2)) |
(forward-char 2)) |
1098 |
(goto-char (setq prev-end (point-min)))) |
(goto-char (setq prev-end (point-min)))) |
1099 |
(or (tex-validate-region (point) end) |
(or (tex-validate-region (point) end) |
1100 |
(let* ((oend end) |
(let* ((end (line-beginning-position 2)) |
|
(end (save-excursion (forward-line 1) (point))) |
|
1101 |
start tem) |
start tem) |
1102 |
(beginning-of-line) |
(beginning-of-line) |
1103 |
(setq start (point)) |
(setq start (point)) |
1853 |
line LINE of the window, or centered if LINE is nil." |
line LINE of the window, or centered if LINE is nil." |
1854 |
(interactive "P") |
(interactive "P") |
1855 |
(let ((tex-shell (get-buffer "*tex-shell*")) |
(let ((tex-shell (get-buffer "*tex-shell*")) |
|
(old-buffer (current-buffer)) |
|
1856 |
(window)) |
(window)) |
1857 |
(if (null tex-shell) |
(if (null tex-shell) |
1858 |
(message "No TeX output buffer") |
(message "No TeX output buffer") |
1979 |
(defun latex-indent (&optional arg) |
(defun latex-indent (&optional arg) |
1980 |
(if (and (eq (get-text-property (line-beginning-position) 'face) |
(if (and (eq (get-text-property (line-beginning-position) 'face) |
1981 |
tex-verbatim-face)) |
tex-verbatim-face)) |
1982 |
(indent-relative) |
'noindent |
1983 |
(with-syntax-table tex-latex-indent-syntax-table |
(with-syntax-table tex-latex-indent-syntax-table |
1984 |
;; TODO: Rather than ignore $, we should try to be more clever about it. |
;; TODO: Rather than ignore $, we should try to be more clever about it. |
1985 |
(let ((indent |
(let ((indent |
2066 |
(min (current-column) (+ tex-indent-arg col)) |
(min (current-column) (+ tex-indent-arg col)) |
2067 |
(skip-syntax-forward " ") |
(skip-syntax-forward " ") |
2068 |
(current-column)))))))))) |
(current-column)))))))))) |
2069 |
|
;;; DocTeX support |
2070 |
|
|
2071 |
|
(defun doctex-font-lock-^^A () |
2072 |
|
(if (eq (char-after (line-beginning-position)) ?\%) |
2073 |
|
(progn |
2074 |
|
(put-text-property |
2075 |
|
(1- (match-beginning 1)) (match-beginning 1) |
2076 |
|
'syntax-table |
2077 |
|
(if (= (1+ (line-beginning-position)) (match-beginning 1)) |
2078 |
|
;; The `%' is a single-char comment, which Emacs |
2079 |
|
;; syntax-table can't deal with. We could turn it |
2080 |
|
;; into a non-comment, or use `\n%' or `%^' as the comment. |
2081 |
|
;; Instead, we include it in the ^^A comment. |
2082 |
|
(eval-when-compile (string-to-syntax "< b")) |
2083 |
|
(eval-when-compile (string-to-syntax ">")))) |
2084 |
|
(let ((end (line-end-position))) |
2085 |
|
(if (< end (point-max)) |
2086 |
|
(put-text-property |
2087 |
|
end (1+ end) |
2088 |
|
'syntax-table |
2089 |
|
(eval-when-compile (string-to-syntax "> b"))))) |
2090 |
|
(eval-when-compile (string-to-syntax "< b"))))) |
2091 |
|
|
2092 |
|
(defun doctex-font-lock-syntactic-face-function (state) |
2093 |
|
;; Mark DocTeX documentation, which is parsed as a style A comment |
2094 |
|
;; starting in column 0. |
2095 |
|
(if (or (nth 3 state) (nth 7 state) |
2096 |
|
(not (memq (char-before (nth 8 state)) |
2097 |
|
'(?\n nil)))) |
2098 |
|
;; Anything else is just as for LaTeX. |
2099 |
|
(tex-font-lock-syntactic-face-function state) |
2100 |
|
font-lock-doc-face)) |
2101 |
|
|
2102 |
|
(defvar doctex-font-lock-syntactic-keywords |
2103 |
|
(append |
2104 |
|
tex-font-lock-syntactic-keywords |
2105 |
|
;; For DocTeX comment-in-doc. |
2106 |
|
`(("\\(\\^\\)\\^A" (1 (doctex-font-lock-^^A)))))) |
2107 |
|
|
2108 |
|
(defvar doctex-font-lock-keywords |
2109 |
|
(append tex-font-lock-keywords |
2110 |
|
'(("^%<[^>]*>" (0 font-lock-preprocessor-face t))))) |
2111 |
|
|
2112 |
|
;;;###autoload |
2113 |
|
(define-derived-mode doctex-mode latex-mode "DocTeX" |
2114 |
|
"Major mode to edit DocTeX files." |
2115 |
|
(setq font-lock-defaults |
2116 |
|
(cons (append (car font-lock-defaults) '(doctex-font-lock-keywords)) |
2117 |
|
(mapcar |
2118 |
|
(lambda (x) |
2119 |
|
(case (car-safe x) |
2120 |
|
(font-lock-syntactic-keywords |
2121 |
|
(cons (car x) 'doctex-font-lock-syntactic-keywords)) |
2122 |
|
(font-lock-syntactic-face-function |
2123 |
|
(cons (car x) 'doctex-font-lock-syntactic-face-function)) |
2124 |
|
(t x))) |
2125 |
|
(cdr font-lock-defaults))))) |
2126 |
|
|
2127 |
(run-hooks 'tex-mode-load-hook) |
(run-hooks 'tex-mode-load-hook) |
2128 |
|
|