Function: reftex-section-number

reftex-section-number is an autoloaded and byte-compiled function defined in reftex-parse.el.gz.

Signature

(reftex-section-number &optional LEVEL STAR)

Documentation

Return a string with the current section number.

When LEVEL is non-nil, increase section numbers on that level.

Source Code

;; Defined in /usr/src/emacs/lisp/textmodes/reftex-parse.el.gz
;;;###autoload
(defun reftex-section-number (&optional level star)
  "Return a string with the current section number.
When LEVEL is non-nil, increase section numbers on that level."
  (let* ((depth (1- (length reftex-section-numbers))) idx n (string "")
         (appendix (get 'reftex-section-numbers 'appendix))
         (partspecial (and (not reftex-part-resets-chapter)
                           (equal level 0))))
    ;; partspecial means, this is a part statement.
    ;; Parts do not reset the chapter counter, and the part number is
    ;; not included in the numbering of other sectioning levels.
    (when level
      (when (and (> level -1) (not star))
        (aset reftex-section-numbers
              level (1+ (aref reftex-section-numbers level))))
      (setq idx (1+ level))
      (when (not star)
        (while (<= idx depth)
          (if (or (not partspecial)
                  (not (= idx 1)))
              (aset reftex-section-numbers idx 0))
          (incf idx))))
    (if partspecial
        (setq string (concat "Part " (reftex-roman-number
                                      (aref reftex-section-numbers 0))))
      (setq idx (if reftex-part-resets-chapter 0 1))
      (while (<= idx depth)
        (setq n (aref reftex-section-numbers idx))
        (if (not (and partspecial (not (equal string ""))))
            (setq string (concat string (if (not (string= string "")) "." "")
                                 (int-to-string n))))
        (incf idx))
      (save-match-data
        (if (string-match "\\`\\([@0]\\.\\)+" string)
            (setq string (replace-match "" nil nil string)))
        (if (string-match "\\(\\.0\\)+\\'" string)
            (setq string (replace-match "" nil nil string)))
        (if (and appendix
                 (string-match "\\`[0-9]+" string))
            (setq string
                  (concat
                   (char-to-string
                    (1- (+ ?A (string-to-number (match-string 0 string)))))
                   (substring string (match-end 0))))))
      (if star
          (concat (make-string (1- (length string)) ?\ ) "*")
        string))))