diff options
Diffstat (limited to 'lisp/textmodes/tex-mode.el')
-rw-r--r-- | lisp/textmodes/tex-mode.el | 71 |
1 files changed, 47 insertions, 24 deletions
diff --git a/lisp/textmodes/tex-mode.el b/lisp/textmodes/tex-mode.el index c8476b0d15c..240ebbcb229 100644 --- a/lisp/textmodes/tex-mode.el +++ b/lisp/textmodes/tex-mode.el @@ -243,6 +243,21 @@ Normally set to either `plain-tex-mode' or `latex-mode'." :options '("''" "\">" "\"'" ">>" "ยป") :group 'tex) +(defcustom tex-fontify-script t + "If non-nil, fontify subscript and superscript strings." + :type 'boolean + :group 'tex) +(put 'tex-fontify-script 'safe-local-variable 'booleanp) + +(defcustom tex-font-script-display '(-0.2 . 0.2) + "Display specification for subscript and superscript content. +The car is used for subscript, the cdr is used for superscripts." + :group 'tex + :type '(cons (choice (float :tag "Subscript") + (const :tag "No lowering" nil)) + (choice (float :tag "Superscript") + (const :tag "No raising" nil)))) + (defvar tex-last-temp-file nil "Latest temporary file generated by \\[tex-region] and \\[tex-buffer]. Deleted when the \\[tex-region] or \\[tex-buffer] is next run, or when the @@ -527,6 +542,8 @@ An alternative value is \" . \", if you use a font with a narrow period." (citations (regexp-opt '("label" "ref" "pageref" "vref" "eqref" "cite" "nocite" "index" "glossary" "bibitem" + ;; natbib's two variants of \cite: + "citep" "citet" ;; These are text, rather than citations. ;; "caption" "footnote" "footnotemark" "footnotetext" ) @@ -591,13 +608,14 @@ An alternative value is \" . \", if you use a font with a narrow period." (setq pos (1- pos) odd (not odd))) odd)) (if (eq (char-after pos) ?_) - '(face subscript display (raise -0.3)) - '(face superscript display (raise +0.3))))) + `(face subscript display (raise ,(car tex-font-script-display))) + `(face superscript display (raise ,(cdr tex-font-script-display)))))) (defun tex-font-lock-match-suscript (limit) "Match subscript and superscript patterns up to LIMIT." - (when (re-search-forward "[_^] *\\([^\n\\{}]\\|\ -\\\\\\([a-zA-Z@]+\\|[^ \t\n]\\)\\|\\({\\)\\)" limit t) + (when (and tex-fontify-script + (re-search-forward "[_^] *\\([^\n\\{}]\\|\ +\\\\\\([a-zA-Z@]+\\|[^ \t\n]\\)\\|\\({\\)\\)" limit t)) (when (match-end 3) (let ((beg (match-beginning 3)) (end (save-restriction @@ -619,26 +637,31 @@ An alternative value is \" . \", if you use a font with a narrow period." (defvar tex-verbatim-environments '("verbatim" "verbatim*")) +(put 'tex-verbatim-environments 'safe-local-variable + (lambda (x) (require 'cl) (every 'stringp x))) (defvar tex-font-lock-syntactic-keywords - (let ((verbs (regexp-opt tex-verbatim-environments t))) - `((,(concat "^\\\\begin *{" verbs "}.*\\(\n\\)") 2 "|") - ;; Technically, we'd like to put the "|" property on the \n preceding - ;; the \end, but this would have 2 disadvantages: - ;; 1 - it's wrong if the verbatim env is empty (the same \n is used to - ;; start and end the fenced-string). - ;; 2 - font-lock considers the preceding \n as being part of the - ;; preceding line, so things gets screwed every time the previous - ;; line is re-font-locked on its own. - ;; There's a hack in tex-font-lock-keywords-1 to remove the verbatim - ;; face from the \ but C-M-f still jumps to the wrong spot :-( --Stef - (,(concat "^\\(\\\\\\)end *{" verbs "}\\(.?\\)") (1 "|") (3 "<")) - ;; ("^\\(\\\\\\)begin *{comment}" 1 "< b") - ;; ("^\\\\end *{comment}.*\\(\n\\)" 1 "> b") - ("\\\\verb\\**\\([^a-z@*]\\)" - ;; Do it last, because it uses syntax-ppss which needs the - ;; syntax-table properties of previous entries. - 1 (tex-font-lock-verb (match-end 1)))))) + '((eval . `(,(concat "^\\\\begin *{" + (regexp-opt tex-verbatim-environments t) + "}.*\\(\n\\)") 2 "|")) + ;; Technically, we'd like to put the "|" property on the \n preceding + ;; the \end, but this would have 2 disadvantages: + ;; 1 - it's wrong if the verbatim env is empty (the same \n is used to + ;; start and end the fenced-string). + ;; 2 - font-lock considers the preceding \n as being part of the + ;; preceding line, so things gets screwed every time the previous + ;; line is re-font-locked on its own. + ;; There's a hack in tex-font-lock-keywords-1 to remove the verbatim + ;; face from the \ but C-M-f still jumps to the wrong spot :-( --Stef + (eval . `(,(concat "^\\(\\\\\\)end *{" + (regexp-opt tex-verbatim-environments t) + "}\\(.?\\)") (1 "|") (3 "<"))) + ;; ("^\\(\\\\\\)begin *{comment}" 1 "< b") + ;; ("^\\\\end *{comment}.*\\(\n\\)" 1 "> b") + ("\\\\verb\\**\\([^a-z@*]\\)" + ;; Do it last, because it uses syntax-ppss which needs the + ;; syntax-table properties of previous entries. + 1 (tex-font-lock-verb (match-end 1))))) (defun tex-font-lock-unfontify-region (beg end) (font-lock-default-unfontify-region beg end) @@ -652,11 +675,11 @@ An alternative value is \" . \", if you use a font with a narrow period." (setq beg next)))) (defface superscript - '((t :height 0.8)) ;; :raise 0.3 + '((t :height 0.8)) ;; :raise 0.2 "Face used for superscripts." :group 'tex) (defface subscript - '((t :height 0.8)) ;; :raise -0.3 + '((t :height 0.8)) ;; :raise -0.2 "Face used for subscripts." :group 'tex) |