(defun LaTeX-abbrev-refs-label (name &optional type) "Insert a Label for NAME at point. The optional TYPE argument can be either environment or section: in the former case this function looks up `LaTeX-label-alist' to choose which prefix to use for the label, in the latter case `LaTeX-section-label' will be looked up instead. If TYPE is nil, you will be always prompted for a label, with an empty default prefix. If `LaTeX-label-function' is a valid function, LaTeX label will transfer the job to this function. The inserted label is returned, nil if it is empty." (let ((TeX-read-label-prefix (cond ((eq type 'environment) (cdr (assoc name LaTeX-label-alist))) ((eq type 'section) (if (assoc name LaTeX-section-list) (if (stringp LaTeX-section-label) LaTeX-section-label (and (listp LaTeX-section-label) (cdr (assoc name LaTeX-section-label)))) "")) ((null type) "") (t nil))) label) (when (symbolp TeX-read-label-prefix) (setq TeX-read-label-prefix (symbol-value TeX-read-label-prefix))) (when TeX-read-label-prefix (if (and (boundp 'LaTeX-label-function) LaTeX-label-function (fboundp LaTeX-label-function)) (setq label (funcall LaTeX-label-function name)) ;; Use completing-read as we do with `C-c C-m \label RET' (setq label (TeX-read-label t "What label" t)) ;; No label or empty string entered? (if (or (string= TeX-read-label-prefix label) (string= "" label)) (setq label nil) ;; Modification start: Insert "Label" instead of "label" (insert TeX-esc "Label" TeX-grop label TeX-grcl)) ; Modification end (if label (progn (LaTeX-add-labels label) label) nil))))) (defun LaTeX-abbrev-refs-section-label () "Hook to insert a label after the sectioning command. Insert this hook into `LaTeX-section-hook' to prompt for a label to be inserted after the sectioning command. The behaviour of this hook is controlled by variable `LaTeX-section-label'." (and (LaTeX-abbrev-refs-label name 'section) (LaTeX-newline))) (TeX-add-style-hook "abbreviated-refs" (lambda () (TeX-add-symbols '("Label" TeX-arg-define-label) '("myref" TeX-arg-ref)) ;; Alter LaTeX-section-hook: Replace `LaTeX-section-label' w/ ;; `LaTeX-abbrev-refs-section-label': (make-local-variable 'LaTeX-section-hook) (setq LaTeX-section-hook '(LaTeX-section-heading LaTeX-section-title LaTeX-section-section LaTeX-abbrev-refs-section-label)) ;; Cater Reftex support: (when (boundp 'reftex-label-alist) (add-to-list 'reftex-label-alist '("\\Label{*}" nil nil nil nil) t)) ;; Fontification (when (and (featurep 'font-latex) (eq TeX-install-font-lock 'font-latex-setup)) (font-latex-add-keywords '(("Label" "{") ("myref" "{")) 'reference))) LaTeX-dialect)