;: -*- emacs-lisp -*-
;:* $Id: latex-sy.el,v 1.1 2003-10-18 00:51:27+10 steve Exp steve $

;:*=======================
;:* Initialise aucTeX
(require 'tex-site)
(require 'latex)
(require 'reftex)
(require 'reftex-vars)
(require 'latex-units)
;; Having a toolbar only makes sense if we're in a windowing environment.
(eval-and-compile
  (when (device-on-window-system-p)
    (require 'latex-toolbar)))
(require 'font-latex)
(eval-and-compile
  (require 'outl-mouse))

;:*=======================
;:* Shutup the byte-compiler
(defvar ispell-extra-args)
(defvar LaTeX-mode-map)
(defvar TeX-shell)

(setq
 LaTeX-float nil
 TeX-arg-cite-note-p t
 TeX-arg-footnote-number-p t
 TeX-arg-item-label-p nil
 TeX-auto-parse-length 999999999
 TeX-auto-private
 (file-name-as-directory
  (expand-file-name "documents/TeXauto" (getenv "HOME")))
 TeX-auto-save t
 TeX-debug-bad-boxes nil
 TeX-macro-global
 (file-name-as-directory (expand-file-name "/usr/share/texmf/tex"))
 TeX-macro-private
 (file-name-as-directory
  (expand-file-name "documents/TeX" (getenv "HOME")))
 TeX-outline-extra nil
 TeX-parse-self t
 TeX-printer-default "Draft Quality"
 TeX-printer-list 
 '(("Draft Quality" "dvips -f %s | lpr -Plow-quality" "lpq -Plow-quality")
   ("Medium Quality" "dvips -f %s | lpr -Pmed-quality" "lpq -Pmed-quality")
   ("High Quality" "dvips -f %s | lpr -Phigh-quality" "lpq -Phigh-quality")
   ("Photo Quality" "dvips -f %s | lpr -Pphoto-quality" "lpq -Pphoto-quality")))

(setq-default LaTeX-default-options "a4paper,12pt")
(setq-default TeX-master t)

(setq TeX-view-style '(("^a5$" "xdvi -thorough %d -paper a5")
                       ("^landscape$" "xdvi -thorough %d -paper a4r -s 4")
                       ("." "xdvi -thorough %d")))

;:*=======================
;:* Count words in a TeX text
(defun sds-word-count (start end)
  "Count lines/words/characters from START to END.
Replacement for count-lines-region."
  (interactive "r")
  (let ((ost (syntax-table)) 
        (nst (copy-syntax-table)))
    (modify-syntax-entry ?_ "w" nst)
    (modify-syntax-entry ?- "w" nst)
    (save-excursion
      (save-restriction
        (narrow-to-region start end)
        (goto-char (min start end))
        (unwind-protect
            (progn (set-syntax-table nst)
                   (message 
                    "Region (%d to %d) has: %d lines; %d words; %d characters."
                             start end (count-lines start end)
                             (string-to-number (how-many "\\<"))
                             (- end start)))
          (set-syntax-table ost))))))

;:*=======================
;:*  RefTeX Minor Mode 

;; Turn on RefTeX Minor Mode for all LaTeX files
(autoload 'reftex-mode     "reftex" "RefTeX Minor Mode" t)
(autoload 'turn-on-reftex  "reftex" "RefTeX Minor Mode" nil)
(autoload 'reftex-citation "reftex-cite" "Make citation" nil)

;: RefTeX is a minor mode with distinct support for \ref, \label and
;: \cite commands in (multi-file) LaTeX documents.
(setq 
 reftex-default-label-alist-entries '(Sideways 
                                      AMSTeX 
                                      amsmath
                                      endnotes
                                      fancybox
                                      floatfig
                                      longtable
                                      picinpar
                                      rotating
                                      sidecap
                                      subfigure
                                      supertab
                                      wrapfig
                                      LaTeX)
 reftex-enable-partial-scans t
 reftex-extra-bindings t
 reftex-guess-label-type t
 reftex-initialize-temporary-buffers t
 reftex-insert-label-flags '(t t)
 reftex-keep-temporary-buffers t
 reftex-label-alist 
 '((nil ?s nil nil nil ("Capital" "Cap." "Section" "Part") -3)
   (nil ?e nil nil nil ("Equation" "Eq.") -3)
   (nil ?t nil nil nil ("Table") -3)
   (nil ?f nil nil nil ("Figure" "Illustration" "Ill.") -3)
   (nil ?n nil nil nil ("Comment") -3)
   (nil ?i nil nil nil ("Point") -3))
 reftex-label-menu-flags '(t t t t t t t t)
 reftex-plug-into-AUCTeX t
 reftex-save-parse-info t
 reftex-toc-follow-mode t
 reftex-toc-include-labels t
 reftex-use-multiple-selection-buffers t
 reftex-vref-is-default t)

;:*=======================
;:* Index support
;;When writing a document with an index you will probably define
;;additional macros which make entries into the index.  Let's look at an
;;example.
;;     \newcommand{\ix}[1]{#1\index{#1}}
;;     \newcommand{\nindex}[1]{\textit{#1}\index[name]{#1}}
(setq reftex-index-macros '(("\\ix{*}" "idx" ?x "" nil nil)
                            ("\\nindex{*}" "name" ?n "" nil nil)
                            index))

(defun return-created-string ()
  "Return a \"Created:\" string."
  (let ((time (current-time-string)))
    (concat "Created at: "
            (substring time 0 20)
            (nth 1 (current-time-zone))
            " "
            (substring time -4) " ")))

;:*=======================
;:* outl-mouse-minor-mode for all LaTeX files
(defun turn-on-outl-mouse-minor-mode ()
  (outl-mouse-minor-mode 1))

;:*=======================
;* Hooks.
(add-hook 'reftex-load-hook
          '(lambda ()
             (define-key reftex-mode-map [(shift mouse-2)]
               'reftex-mouse-view-crossref)))

(add-hook 'LaTeX-mode-hook 
          '(lambda () 
             (turn-on-auto-fill)
             (setq TeX-shell "/bin/bash")
             (setq ispell-extra-args '("-t"))
             (turn-on-reftex)
             (add-to-list
              'TeX-command-list
              '("Acroread" "acroread %s.pdf"
                TeX-run-silent t nil))
             (add-to-list
              'TeX-command-list
              '("xpdf" "xpdf %s.pdf" TeX-run-silent t nil))
             (add-to-list
              'TeX-command-list
              '("gv" "gv %s.ps" TeX-run-silent t nil))))

;; Add a couple more things if we're in X
(when (and (device-on-window-system-p)
           (featurep 'latex-toolbar)
           (featurep 'outl-mouse))
  (add-hook 'LaTeX-mode-hook
            '(lambda ()
               (turn-on-outl-mouse-minor-mode)
               (latex-toolbar-install))))

(setq LaTeX-section-hook
      '(LaTeX-section-heading
        LaTeX-section-title
        LaTeX-section-toc
        LaTeX-section-section
        LaTeX-section-label))
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*
(message "LaTeX initialised")

Created with XEmacs Valid HTML 4.01! Valid CSS!
Copyright © 2003 Steve Youngs
Verbatim copying and distribution is permitted in any medium, providing this notice is preserved.
Last modified: Sat Oct 18 02:11:30 EST 2003