(defun LaTeX-abbrev-ref-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'. Also, search back and replace \\label with \\seclabel. The search is limited to the sectioning command just inserted in order not to replace any other \\label commands if no \\label is inserted, e.g. after \\section*." (and (LaTeX-label name 'section) (LaTeX-newline)) (let ((labelpos (save-excursion (re-search-backward (concat (regexp-quote TeX-esc) "label") (save-excursion (re-search-backward (concat (regexp-quote TeX-esc) name))) t)))) (when labelpos (save-excursion (goto-char (1+ labelpos)) (insert "sec"))))) (TeX-add-style-hook "abbrev-ref" (lambda () (TeX-add-symbols '("seclabel" TeX-arg-define-label) '("secref" TeX-arg-ref)) ;; Alter LaTeX-section-hook: Replace `LaTeX-section-label' w/ ;; `LaTeX-abbrev-ref-section-label': (make-local-variable 'LaTeX-section-hook) (setq LaTeX-section-hook '(LaTeX-section-heading LaTeX-section-title LaTeX-section-section LaTeX-abbrev-ref-section-label)) ;; Cater Reftex support: (when (boundp 'reftex-label-alist) (add-to-list 'reftex-label-alist '("\\seclabel{*}" nil nil nil nil) t)) ;; Fontification (when (and (featurep 'font-latex) (eq TeX-install-font-lock 'font-latex-setup)) (font-latex-add-keywords '(("seclabel" "{") ("secref" "{")) 'reference))) LaTeX-dialect) ;;; abbrev-ref.el ends here