1 ;; 05-latex-sy.el --- LaTeX Settings -*- Emacs-Lisp -*-
3 ;; Copyright (C) 2007 - 2012 Steve Youngs
5 ;; Author: Steve Youngs <steve@sxemacs.org>
6 ;; Maintainer: Steve Youngs <steve@sxemacs.org>
7 ;; Created: <2007-12-02>
8 ;; Time-stamp: <Sunday Jun 10, 2012 10:55:18 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
14 ;; This file is part of SYinit
16 ;; Redistribution and use in source and binary forms, with or without
17 ;; modification, are permitted provided that the following conditions
20 ;; 1. Redistributions of source code must retain the above copyright
21 ;; notice, this list of conditions and the following disclaimer.
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.
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.
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.
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.
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.
62 ;:*=======================
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)
70 (require 'reftex-vars)
71 ;(require 'latex-units)
74 ;:*=======================
75 ;:* Shutup the byte-compiler
76 (defvar ispell-extra-args)
77 (defvar LaTeX-mode-map)
83 TeX-arg-footnote-number-p t
84 TeX-arg-item-label-p nil
85 TeX-auto-parse-length 999999999
87 (file-name-as-directory
88 (expand-file-name "documents/TeXauto" (getenv "HOME")))
90 TeX-debug-bad-boxes nil
92 (file-name-as-directory
93 (expand-file-name "documents/TeX" (getenv "HOME")))
96 TeX-printer-default "HP Single"
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")))
103 (setq-default LaTeX-default-options "a4paper,12pt")
104 (setq-default TeX-master t)
106 (setq TeX-view-style '(("^a5$" "xdvi -thorough %d -paper a5")
107 ("^landscape$" "xdvi -thorough %d -paper a4r -s 4")
108 ("." "xdvi -thorough %d")))
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."
116 (let ((ost (syntax-table))
117 (nst (copy-syntax-table)))
118 (modify-syntax-entry ?_ "w" nst)
119 (modify-syntax-entry ?- "w" nst)
122 (narrow-to-region start end)
123 (goto-char (min start end))
125 (progn (set-syntax-table nst)
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 "\\<"))
131 (set-syntax-table ost))))))
133 ;:*=======================
134 ;:* RefTeX Minor Mode
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)
141 ;: RefTeX is a minor mode with distinct support for \ref, \label and
142 ;: \cite commands in (multi-file) LaTeX documents.
144 reftex-default-label-alist-entries '(Sideways
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
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)
179 ;:*=======================
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
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)
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))
197 (substring time -4) " ")))
199 ;:*=======================
200 ;:* outl-mouse-minor-mode for all LaTeX files
201 (defun turn-on-outl-mouse-minor-mode ()
202 (outl-mouse-minor-mode 1))
204 ;:*=======================
206 (add-hook 'reftex-load-hook
208 (define-key reftex-mode-map [(shift button2)]
209 'reftex-mouse-view-crossref)))
211 (add-hook 'LaTeX-mode-hook
214 (setq TeX-shell "/bin/bash")
215 (make-local-variable 'ispell-extra-args)
216 (push "-t" ispell-extra-args)
220 '("xpdf" "xpdf %s.pdf" TeX-run-silent t nil))
223 '("gv" "gv %s.ps" TeX-run-silent t nil))
226 '("pdflatex" "pdflatex -interaction=nonstopmode %t"
227 TeX-run-command nil t))))
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
235 (turn-on-outl-mouse-minor-mode)
236 (latex-toolbar-install))))
238 (setq LaTeX-section-hook
239 '(LaTeX-section-heading
242 LaTeX-section-section
243 LaTeX-section-label))
244 ;:*=======================
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'.
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
256 (set-face-parent 'texinfo-heading-face 'font-lock-function-name-face)
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)))
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")