Function: LaTeX-209-to-2e

LaTeX-209-to-2e is an interactive and byte-compiled function defined in latex.el.

Signature

(LaTeX-209-to-2e)

Documentation

Make a stab at changing 2.09 doc header to 2e style.

Key Bindings

Source Code

;; Defined in ~/.emacs.d/elpa/auctex-14.1.2/latex.el
(defun LaTeX-209-to-2e ()
  "Make a stab at changing 2.09 doc header to 2e style."
  (declare (modes LaTeX-mode))
  (interactive)
  (TeX-home-buffer)
  (let (optstr optlist 2eoptlist 2epackages docline docstyle)
    (goto-char (point-min))
    (if
        (search-forward-regexp
         "\\\\documentstyle\\[\\([^]]*\\)\\]{\\([^}]*\\)}"
         (point-max) t)
        (setq optstr (TeX-match-buffer 1)
              docstyle (TeX-match-buffer 2)
              optlist (split-string optstr ","))
      (if (search-forward-regexp
           "\\\\documentstyle{\\([^}]*\\)}"
           (point-max) t)
          (setq docstyle (TeX-match-buffer 1))
        (error "No documentstyle defined")))
    (beginning-of-line 1)
    (setq docline (point))
    (insert "%%%")
    (while optlist
      (if (member (car optlist) LaTeX-builtin-opts)
          (setq 2eoptlist (cons (car optlist) 2eoptlist))
        (setq 2epackages (cons (car optlist) 2epackages)))
      (setq optlist (cdr optlist)))
    ;;(message (format "%S %S" 2eoptlist 2epackages))
    (goto-char docline)
    (forward-line 1)
    (insert "\\documentclass")
    (if 2eoptlist
        (insert "["
                (mapconcat (lambda (x) x)
                           (nreverse 2eoptlist) ",") "]"))
    (insert "{" docstyle "}\n")
    (if 2epackages
        (insert "\\usepackage{"
                (mapconcat (lambda (x) x)
                           (nreverse 2epackages) "}\n\\usepackage{") "}\n"))
    (if (equal docstyle "slides")
        (progn
          (goto-char (point-min))
          (while (re-search-forward "\\\\blackandwhite{" nil t)
            (replace-match "\\\\input{" nil nil)))))
  (TeX-normal-mode nil))