Some warning fixes
[syinit] / 05-latex-sy.el
1 ;; 05-latex-sy.el --- LaTeX Settings   -*- Emacs-Lisp -*-
2
3 ;; Copyright (C) 2007 - 2012 Steve Youngs
4
5 ;;     Author: Steve Youngs <steve@sxemacs.org>
6 ;; Maintainer: Steve Youngs <steve@sxemacs.org>
7 ;;    Created: <2007-12-02>
8 ;; Time-stamp: <Saturday Jun 23, 2012 13:00:04 steve>
9 ;;   Download: <http://bastard.steveyoungs.com/~steve/SXEmacs/inits/>
10 ;;   HTMLised: <http://bastard.steveyoungs.com/~steve/SXEmacs/htmlinits/05-latex-sy.html>
11 ;;   Git Repo: git clone http://git.sxemacs.org/syinit
12 ;;   Keywords: init, compile
13
14 ;; This file is part of SYinit
15
16 ;; Redistribution and use in source and binary forms, with or without
17 ;; modification, are permitted provided that the following conditions
18 ;; are met:
19 ;;
20 ;; 1. Redistributions of source code must retain the above copyright
21 ;;    notice, this list of conditions and the following disclaimer.
22 ;;
23 ;; 2. Redistributions in binary form must reproduce the above copyright
24 ;;    notice, this list of conditions and the following disclaimer in the
25 ;;    documentation and/or other materials provided with the distribution.
26 ;;
27 ;; 3. Neither the name of the author nor the names of any contributors
28 ;;    may be used to endorse or promote products derived from this
29 ;;    software without specific prior written permission.
30 ;;
31 ;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
32 ;; IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
33 ;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
34 ;; DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
35 ;; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
36 ;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
37 ;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
38 ;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
39 ;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
40 ;; OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
41 ;; IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42
43 ;;; Commentary:
44 ;;
45 ;;   Do you remember back in the old days when you'd write a letter
46 ;;   on a piece of paper, stick it in an envelope, put a stamp on it
47 ;;   and have the postal service deliver it for you?  Well I still do
48 ;;   that and LaTeX is how I get it done.  At least the writing,
49 ;;   formatting, and printing side of it anyway.
50
51 ;;; Credits:
52 ;;
53 ;;   The HTML version of this file was created with Hrvoje Niksic's
54 ;;   htmlize.el which is part of the XEmacs "text-modes" package.
55 ;;
56
57 ;;; Todo:
58 ;;
59 ;;     
60
61 ;;; Code:
62 ;:*=======================
63 ;:* Initialise aucTeX
64 (require 'tex-site)
65 ;; Latest auctex causes a split window on (S)XEmacs start up without
66 ;; this defvaralias because of a defadvice in tex.el
67 (defvaralias 'minor-mode-list 'minor-mode-alist)
68 (require 'latex)
69 (require 'reftex)
70 (require 'reftex-vars)
71 ;(require 'latex-units)
72 (require 'font-latex)
73
74 ;:*=======================
75 ;:* Shutup the byte-compiler
76 (defvar ispell-extra-args)
77 (defvar LaTeX-mode-map)
78 (defvar TeX-shell)
79
80 (setq
81  LaTeX-float nil
82  TeX-arg-cite-note-p t
83  TeX-arg-footnote-number-p t
84  TeX-arg-item-label-p nil
85  TeX-auto-parse-length 999999999
86  TeX-auto-private
87  (file-name-as-directory
88   (expand-file-name "documents/TeXauto" (getenv "HOME")))
89  TeX-auto-save t
90  TeX-debug-bad-boxes nil
91  TeX-macro-private
92  (file-name-as-directory
93   (expand-file-name "documents/TeX" (getenv "HOME")))
94  TeX-outline-extra nil
95  TeX-parse-self t
96  TeX-printer-default "HP Single"
97  TeX-printer-list 
98  '(("HP Single" "dvips -f %s|lpr -PHP_Single@bastard" "lpq -PHP_Single@bastard")
99    ("HP Duplex" "dvips -f %s|lpr -PHP_Duplex@bastard" "lpq -PHP_Duplex@bastard")
100    ("HP Photo" "dvips -f %s|lpr -PHP_Photo@bastard" "lpq -PHP_Photo@bastard")
101    ("HP draft" "dvips -f %s|lpr -PHP_draft@bastard" "lpq -PHP_draft@bastard")))
102
103 (setq-default LaTeX-default-options "a4paper,12pt")
104 (setq-default TeX-master t)
105
106 (setq TeX-view-style '(("^a5$" "xdvi -thorough %d -paper a5")
107                        ("^landscape$" "xdvi -thorough %d -paper a4r -s 4")
108                        ("." "xdvi -thorough %d")))
109
110 ;:*=======================
111 ;:* Count words in a TeX text
112 (defun sds-word-count (start end)
113   "Count lines/words/characters from START to END.
114 Replacement for count-lines-region."
115   (interactive "r")
116   (let ((ost (syntax-table)) 
117         (nst (copy-syntax-table)))
118     (modify-syntax-entry ?_ "w" nst)
119     (modify-syntax-entry ?- "w" nst)
120     (save-excursion
121       (save-restriction
122         (narrow-to-region start end)
123         (goto-char (min start end))
124         (unwind-protect
125             (progn (set-syntax-table nst)
126                    (message 
127                     "Region (%d to %d) has: %d lines; %d words; %d characters."
128                              start end (count-lines start end)
129                              (string-to-number (how-many "\\<"))
130                              (- end start)))
131           (set-syntax-table ost))))))
132
133 ;:*=======================
134 ;:*  RefTeX Minor Mode 
135
136 ;; Turn on RefTeX Minor Mode for all LaTeX files
137 (autoload 'reftex-mode     "reftex" "RefTeX Minor Mode" t)
138 (autoload 'turn-on-reftex  "reftex" "RefTeX Minor Mode" nil)
139 (autoload 'reftex-citation "reftex-cite" "Make citation" nil)
140
141 ;: RefTeX is a minor mode with distinct support for \ref, \label and
142 ;: \cite commands in (multi-file) LaTeX documents.
143 (setq 
144  reftex-default-label-alist-entries '(Sideways 
145                                       AMSTeX 
146                                       amsmath
147                                       endnotes
148                                       fancybox
149                                       floatfig
150                                       longtable
151                                       picinpar
152                                       rotating
153                                       sidecap
154                                       subfigure
155                                       supertab
156                                       wrapfig
157                                       LaTeX)
158  reftex-enable-partial-scans t
159  reftex-extra-bindings t
160  reftex-guess-label-type t
161  reftex-initialize-temporary-buffers t
162  reftex-insert-label-flags '(t t)
163  reftex-keep-temporary-buffers t
164  reftex-label-alist 
165  '((nil ?s nil nil nil ("Capital" "Cap." "Section" "Part") -3)
166    (nil ?e nil nil nil ("Equation" "Eq.") -3)
167    (nil ?t nil nil nil ("Table") -3)
168    (nil ?f nil nil nil ("Figure" "Illustration" "Ill.") -3)
169    (nil ?n nil nil nil ("Comment") -3)
170    (nil ?i nil nil nil ("Point") -3))
171  reftex-label-menu-flags '(t t t t t t t t)
172  reftex-plug-into-AUCTeX t
173  reftex-save-parse-info t
174  reftex-toc-follow-mode t
175  reftex-toc-include-labels t
176  reftex-use-multiple-selection-buffers t
177  reftex-vref-is-default t)
178
179 ;:*=======================
180 ;:* Index support
181 ;;When writing a document with an index you will probably define
182 ;;additional macros which make entries into the index.  Let's look at an
183 ;;example.
184 ;;     \newcommand{\ix}[1]{#1\index{#1}}
185 ;;     \newcommand{\nindex}[1]{\textit{#1}\index[name]{#1}}
186 (setq reftex-index-macros '(("\\ix{*}" "idx" ?x "" nil nil)
187                             ("\\nindex{*}" "name" ?n "" nil nil)
188                             index))
189
190 (defun return-created-string ()
191   "Return a \"Created:\" string."
192   (let ((time (current-time-string)))
193     (concat "Created at: "
194             (substring time 0 20)
195             (nth 1 (current-time-zone))
196             " "
197             (substring time -4) " ")))
198
199 ;:*=======================
200 ;:* outl-mouse-minor-mode for all LaTeX files
201 (defun turn-on-outl-mouse-minor-mode ()
202   (outl-mouse-minor-mode 1))
203
204 ;:*=======================
205 ;* Hooks.
206 (add-hook 'reftex-load-hook
207           #'(lambda ()
208               (define-key reftex-mode-map [(shift button2)]
209                 'reftex-mouse-view-crossref)))
210
211 (add-hook 'LaTeX-mode-hook 
212           #'(lambda () 
213               (turn-on-auto-fill)
214               (setq TeX-shell "/bin/bash")
215               (make-local-variable 'ispell-extra-args)
216               (push "-t" ispell-extra-args)
217               (turn-on-reftex)
218               (add-to-list
219                'TeX-command-list
220                '("xpdf" "xpdf %s.pdf" TeX-run-silent t nil))
221               (add-to-list
222                'TeX-command-list
223                '("gv" "gv %s.ps" TeX-run-silent t nil))
224               (add-to-list
225                'TeX-command-list
226                '("pdflatex" "pdflatex -interaction=nonstopmode %t"
227                  TeX-run-command nil t))))
228
229 ;; Add a couple more things if we're in X
230 ;;(when (and (device-on-window-system-p)
231 ;;         (featurep 'latex-toolbar)
232 ;;         (featurep 'outl-mouse))
233 ;;  (add-hook 'LaTeX-mode-hook
234 ;;          #'(lambda ()
235 ;;              (turn-on-outl-mouse-minor-mode)
236 ;;              (latex-toolbar-install))))
237
238 (setq LaTeX-section-hook
239       '(LaTeX-section-heading
240         LaTeX-section-title
241         LaTeX-section-toc
242         LaTeX-section-section
243         LaTeX-section-label))
244 ;:*=======================
245 ;:* Texinfo
246 ;; This is _NOT_ the texinfo-mode that comes with AucTeX, because that
247 ;; sucks.  AucTeX actually loads `texinfo.el' and then overwrites
248 ;; everything with the DAK-inspired crap!  So I explicitly load it
249 ;; here to reinstate the better `texinfo-mode'.
250 (require 'texinfo)
251
252 ;; `texinfo.el' uses the GNU `:inherit' property which (S)XEmacs
253 ;; doesn't have... a quick `set-face-parent' fixes that.
254 ;; Update: SXEmacs does have `:inherit' now, at least, I'm pretty sure
255 ;; it does
256 (set-face-parent 'texinfo-heading-face 'font-lock-function-name-face)
257
258 ;; Perdy colours!
259 (setq texinfo-font-lock-keywords
260       `(("@\\([a-zA-Z]+\\|[^ \t\n]\\)" 1 font-lock-keyword-face) ;commands
261         ("^\\*\\([^\n:]*\\)" 1 font-lock-function-name-face t) ;menu items
262         ("@\\(emph\\|i\\|sc\\){\\([^}]+\\)" 2 'italic)
263         ("@\\(strong\\|b\\){\\([^}]+\\)" 2 'bold)
264         ("@\\(kbd\\|key\\|url\\|uref\\){\\([^}]+\\)" 2 font-lock-string-face)
265         ("@\\(file\\|email\\){\\([^}]+\\)" 2 font-lock-string-face keep)
266         ("@\\(samp\\|code\\|var\\|math\\|env\\|command\\|option\\){\\([^}]+\\)"
267          2 font-lock-variable-name-face keep)
268         ("@\\(cite\\|x?ref\\|pxref\\|dfn\\|inforef\\){\\([^}]+\\)"
269          2 font-lock-reference-face) ;; #### XEmacs change
270         ("@\\(anchor\\){\\([^}]+\\)" 2 font-lock-type-face)
271         ("@\\(dmn\\|acronym\\|value\\){\\([^}]+\\)" 2 font-lock-builtin-face)
272         ("@\\(end\\|itemx?\\) +\\(.+\\)" 2 font-lock-keyword-face keep)
273         (,(concat "^@\\(" (regexp-opt (mapcar 'car texinfo-section-list) t)
274                   "\\)\\(.*\n\\)") 3 texinfo-heading-face t)
275         ("@c\\(omment\\)? \\(.*$\\)" 2 font-lock-comment-face)
276         ("@node \\(.*$\\)" 1 font-lock-warning-face)
277         ("^@[cfvkpt]index \\(.*$\\)" 1 font-lock-variable-name-face)))
278
279 (defun sy-texinfo-menu () (easy-menu-add texinfo-mode-menu))
280 (add-hook 'texinfo-mode-hook #'sy-texinfo-menu)
281 (add-hook 'texinfo-mode-hook #'font-lock-mode)
282 ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*
283 (message "LaTeX initialised")