;; 05-latex-sy.el --- LaTeX Settings -*- Emacs-Lisp -*- ;; Copyright (C) 2007 - 2012 Steve Youngs ;; Author: Steve Youngs ;; Maintainer: Steve Youngs ;; Created: <2007-12-02> ;; Time-stamp: ;; Download: ;; HTMLised: ;; Git Repo: git clone http://git.sxemacs.org/syinit ;; Keywords: init, compile ;; This file is part of SYinit ;; Redistribution and use in source and binary forms, with or without ;; modification, are permitted provided that the following conditions ;; are met: ;; ;; 1. Redistributions of source code must retain the above copyright ;; notice, this list of conditions and the following disclaimer. ;; ;; 2. Redistributions in binary form must reproduce the above copyright ;; notice, this list of conditions and the following disclaimer in the ;; documentation and/or other materials provided with the distribution. ;; ;; 3. Neither the name of the author nor the names of any contributors ;; may be used to endorse or promote products derived from this ;; software without specific prior written permission. ;; ;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR ;; IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE ;; DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE ;; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR ;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF ;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR ;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, ;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE ;; OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN ;; IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ;;; Commentary: ;; ;; Do you remember back in the old days when you'd write a letter ;; on a piece of paper, stick it in an envelope, put a stamp on it ;; and have the postal service deliver it for you? Well I still do ;; that and LaTeX is how I get it done. At least the writing, ;; formatting, and printing side of it anyway. ;;; Credits: ;; ;; The HTML version of this file was created with Hrvoje Niksic's ;; htmlize.el which is part of the XEmacs "text-modes" package. ;; ;;; Todo: ;; ;; ;;; Code: ;:*======================= ;:* Initialise aucTeX (require 'tex-site) ;; Latest auctex causes a split window on (S)XEmacs start up without ;; this defvaralias because of a defadvice in tex.el (defvaralias 'minor-mode-list 'minor-mode-alist) (require 'latex) (require 'reftex) (require 'reftex-vars) ;(require 'latex-units) (require 'font-latex) ;:*======================= ;:* 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-private (file-name-as-directory (expand-file-name "documents/TeX" (getenv "HOME"))) TeX-outline-extra nil TeX-parse-self t TeX-printer-default "HP Single" TeX-printer-list '(("HP Single" "dvips -f %s|lpr -PHP_Single@bastard" "lpq -PHP_Single@bastard") ("HP Duplex" "dvips -f %s|lpr -PHP_Duplex@bastard" "lpq -PHP_Duplex@bastard") ("HP Photo" "dvips -f %s|lpr -PHP_Photo@bastard" "lpq -PHP_Photo@bastard") ("HP draft" "dvips -f %s|lpr -PHP_draft@bastard" "lpq -PHP_draft@bastard"))) (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 button2)] 'reftex-mouse-view-crossref))) (add-hook 'LaTeX-mode-hook #'(lambda () (turn-on-auto-fill) (setq TeX-shell "/bin/bash") (make-local-variable 'ispell-extra-args) (push "-t" ispell-extra-args) (turn-on-reftex) (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-to-list 'TeX-command-list '("pdflatex" "pdflatex -interaction=nonstopmode %t" TeX-run-command nil t)))) ;; 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)) ;:*======================= ;:* Texinfo ;; This is _NOT_ the texinfo-mode that comes with AucTeX, because that ;; sucks. AucTeX actually loads `texinfo.el' and then overwrites ;; everything with the DAK-inspired crap! So I explicitly load it ;; here to reinstate the better `texinfo-mode'. (require 'texinfo) ;; `texinfo.el' uses the GNU `:inherit' property which (S)XEmacs ;; doesn't have... a quick `set-face-parent' fixes that. ;; Update: SXEmacs does have `:inherit' now, at least, I'm pretty sure ;; it does (set-face-parent 'texinfo-heading-face 'font-lock-function-name-face) ;; Perdy colours! (setq texinfo-font-lock-keywords `(("@\\([a-zA-Z]+\\|[^ \t\n]\\)" 1 font-lock-keyword-face) ;commands ("^\\*\\([^\n:]*\\)" 1 font-lock-function-name-face t) ;menu items ("@\\(emph\\|i\\|sc\\){\\([^}]+\\)" 2 'italic) ("@\\(strong\\|b\\){\\([^}]+\\)" 2 'bold) ("@\\(kbd\\|key\\|url\\|uref\\){\\([^}]+\\)" 2 font-lock-string-face) ("@\\(file\\|email\\){\\([^}]+\\)" 2 font-lock-string-face keep) ("@\\(samp\\|code\\|var\\|math\\|env\\|command\\|option\\){\\([^}]+\\)" 2 font-lock-variable-name-face keep) ("@\\(cite\\|x?ref\\|pxref\\|dfn\\|inforef\\){\\([^}]+\\)" 2 font-lock-reference-face) ;; #### XEmacs change ("@\\(anchor\\){\\([^}]+\\)" 2 font-lock-type-face) ("@\\(dmn\\|acronym\\|value\\){\\([^}]+\\)" 2 font-lock-builtin-face) ("@\\(end\\|itemx?\\) +\\(.+\\)" 2 font-lock-keyword-face keep) (,(concat "^@\\(" (regexp-opt (mapcar 'car texinfo-section-list) t) "\\)\\(.*\n\\)") 3 texinfo-heading-face t) ("@c\\(omment\\)? \\(.*$\\)" 2 font-lock-comment-face) ("@node \\(.*$\\)" 1 font-lock-warning-face) ("^@[cfvkpt]index \\(.*$\\)" 1 font-lock-variable-name-face))) (defun sy-texinfo-menu () (easy-menu-add texinfo-mode-menu)) (add-hook 'texinfo-mode-hook #'sy-texinfo-menu) (add-hook 'texinfo-mode-hook #'font-lock-mode) ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::* (message "LaTeX initialised")