Function: TeX-parse-macro

TeX-parse-macro is a byte-compiled function defined in tex.el.

Signature

(TeX-parse-macro SYMBOL ARGS)

Documentation

How to parse TeX macros which takes one or more arguments.

First argument SYMBOL is the name of the macro.

If ARGS is nil, insert macro with point inside braces. Otherwise, each element in ARGS should match an argument to the TeX macro. What is done depend on the type of the element:

  string: Use the string as a prompt to prompt for the argument.

  number: Insert that many braces, leave point inside the first.

  nil: Insert empty braces.

  t: Insert empty braces, leave point between the braces.

  other symbols: Call the symbol as a function. You can define
  your own hook, or use one of the predefined argument hooks. If
  you add new hooks, you can assume that point is placed directly
  after the previous argument, or after the macro name if this is
  the first argument. Please leave point located after the
  argument you are inserting. If you want point to be located
  somewhere else after all hooks have been processed, set the
  value of TeX-exit-mark. It will point nowhere, until the
  argument hook set it. By convention, these hooks all start
  with TeX-arg-.

  list: If the car is a string, insert it as a prompt and the next
  element as initial input. Otherwise, call the car of the list
  with the remaining elements as arguments.

  vector: Optional argument. If it has more than one element,
  parse it as a list, otherwise parse the only element as above.
  Use square brackets instead of curly braces, and is not inserted
  on empty user input.

Source Code

;; Defined in ~/.emacs.d/elpa/auctex-14.1.2/tex.el
(defun TeX-parse-macro (symbol args)
  "How to parse TeX macros which takes one or more arguments.

First argument SYMBOL is the name of the macro.

If ARGS is nil, insert macro with point inside braces.
Otherwise, each element in ARGS should match an argument to the
TeX macro.  What is done depend on the type of the element:

  string: Use the string as a prompt to prompt for the argument.

  number: Insert that many braces, leave point inside the first.

  nil: Insert empty braces.

  t: Insert empty braces, leave point between the braces.

  other symbols: Call the symbol as a function.  You can define
  your own hook, or use one of the predefined argument hooks.  If
  you add new hooks, you can assume that point is placed directly
  after the previous argument, or after the macro name if this is
  the first argument.  Please leave point located after the
  argument you are inserting.  If you want point to be located
  somewhere else after all hooks have been processed, set the
  value of `TeX-exit-mark'.  It will point nowhere, until the
  argument hook set it.  By convention, these hooks all start
  with `TeX-arg-'.

  list: If the car is a string, insert it as a prompt and the next
  element as initial input.  Otherwise, call the car of the list
  with the remaining elements as arguments.

  vector: Optional argument.  If it has more than one element,
  parse it as a list, otherwise parse the only element as above.
  Use square brackets instead of curly braces, and is not inserted
  on empty user input."
  (let ((TeX-grop (if (and (or (atom args) (= (length args) 1))
                           (fboundp 'LaTeX-verbatim-macros-with-delims)
                           (member symbol (LaTeX-verbatim-macros-with-delims)))
                      LaTeX-default-verb-delimiter
                    TeX-grop))
        (TeX-grcl (if (and (or (atom args) (= (length args) 1))
                           (fboundp 'LaTeX-verbatim-macros-with-delims)
                           (member symbol (LaTeX-verbatim-macros-with-delims)))
                      LaTeX-default-verb-delimiter
                    TeX-grcl)))
    (if (and (TeX-active-mark)
             (> (point) (mark)))
        (exchange-point-and-mark))
    (insert TeX-esc symbol)
    (let ((TeX-exit-mark (make-marker))
          (position (point)))
      (TeX-parse-arguments args)
      (cond ((marker-position TeX-exit-mark)
             (goto-char (marker-position TeX-exit-mark))
             (set-marker TeX-exit-mark nil))
            ((let ((element (assoc symbol TeX-insert-braces-alist)))
               ;; If in `TeX-insert-braces-alist' there is an element associated
               ;; to the current macro, use its value to decide whether inserting
               ;; a pair of braces, otherwise use the standard criterion.
               (if element
                   (cdr element)
                 (and TeX-insert-braces
                      ;; Do not add braces if the argument is 0 or -1.
                      (not (and (= (safe-length args) 1)
                                (numberp (car args))
                                (<= (car args) 0)))
                      (equal position (point))
                      (string-match "[a-zA-Z]+" symbol))))
             (if (texmathp)
                 (when (TeX-active-mark)
                   (insert TeX-grop)
                   (exchange-point-and-mark)
                   (insert TeX-grcl))
               (insert TeX-grop)
               (if (TeX-active-mark)
                   (progn
                     (exchange-point-and-mark)
                     (insert TeX-grcl))
                 (insert TeX-grcl)
                 (backward-char))))))))