1 ;; 05-latex-sy.el --- LaTeX Settings -*- Emacs-Lisp -*-
3 ;; Copyright (C) 2007 - 2013 Steve Youngs
5 ;; Author: Steve Youngs <steve@sxemacs.org>
6 ;; Maintainer: Steve Youngs <steve@sxemacs.org>
7 ;; Created: <2007-12-02>
8 ;; Time-stamp: <Friday Aug 16, 2013 09:44:34 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)
72 ;(require 'font-latex)
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
145 '(Sideways AMSTeX amsmath endnotes fancybox floatfig longtable
146 picinpar rotating sidecap subfigure supertab wrapfig LaTeX)
147 reftex-enable-partial-scans t
148 reftex-extra-bindings t
149 reftex-guess-label-type t
150 reftex-initialize-temporary-buffers t
151 reftex-insert-label-flags '(t t)
152 reftex-keep-temporary-buffers t
154 '((nil ?s nil nil nil ("Capital" "Cap." "Section" "Part") -3)
155 (nil ?e nil nil nil ("Equation" "Eq.") -3)
156 (nil ?t nil nil nil ("Table") -3)
157 (nil ?f nil nil nil ("Figure" "Illustration" "Ill.") -3)
158 (nil ?n nil nil nil ("Comment") -3)
159 (nil ?i nil nil nil ("Point") -3))
160 reftex-label-menu-flags '(t t t t t t t t)
161 reftex-plug-into-AUCTeX t
162 reftex-save-parse-info t
163 reftex-toc-follow-mode t
164 reftex-toc-include-labels t
165 reftex-use-multiple-selection-buffers t
166 reftex-vref-is-default t)
168 ;:*=======================
170 ;;When writing a document with an index you will probably define
171 ;;additional macros which make entries into the index. Let's look at an
173 ;; \newcommand{\ix}[1]{#1\index{#1}}
174 ;; \newcommand{\nindex}[1]{\textit{#1}\index[name]{#1}}
175 (setq reftex-index-macros '(("\\ix{*}" "idx" ?x "" nil nil)
176 ("\\nindex{*}" "name" ?n "" nil nil)
179 (defun return-created-string ()
180 "Return a \"Created:\" string."
181 (let ((time (current-time-string)))
182 (concat "Created at: "
183 (substring time 0 20)
184 (nth 1 (current-time-zone))
186 (substring time -4) " ")))
188 ;:*=======================
189 ;:* outl-mouse-minor-mode for all LaTeX files
190 (defun turn-on-outl-mouse-minor-mode ()
191 (outl-mouse-minor-mode 1))
193 ;:*=======================
195 (add-hook 'reftex-load-hook
197 (define-key reftex-mode-map [(shift button2)]
198 'reftex-mouse-view-crossref)))
200 (add-hook 'LaTeX-mode-hook
203 (setq TeX-shell "/bin/bash")
204 (make-local-variable 'ispell-extra-args)
205 (push "-t" ispell-extra-args)
209 '("xpdf" "xpdf %s.pdf" TeX-run-silent t nil))
212 '("gv" "gv %s.ps" TeX-run-silent t nil))
215 '("pdflatex" "pdflatex -interaction=nonstopmode %t"
216 TeX-run-command nil t))))
218 ;; Add a couple more things if we're in X
219 ;;(when (and (device-on-window-system-p)
220 ;; (featurep 'latex-toolbar)
221 ;; (featurep 'outl-mouse))
222 ;; (add-hook 'LaTeX-mode-hook
224 ;; (turn-on-outl-mouse-minor-mode)
225 ;; (latex-toolbar-install))))
227 (setq LaTeX-section-hook
228 '(LaTeX-section-heading
231 LaTeX-section-section
232 LaTeX-section-label))
233 ;:*=======================
235 ;; This is _NOT_ the texinfo-mode that comes with AucTeX, because that
236 ;; sucks. AucTeX actually loads `texinfo.el' and then overwrites
237 ;; everything with the DAK-inspired crap! So I explicitly load it
238 ;; here to reinstate the better `texinfo-mode'.
241 ;; `texinfo.el' uses the GNU `:inherit' property which (S)XEmacs
242 ;; doesn't have... a quick `set-face-parent' fixes that.
243 ;; Update: SXEmacs does have `:inherit' now, at least, I'm pretty sure
245 (set-face-parent 'texinfo-heading-face 'font-lock-function-name-face)
248 (setq texinfo-font-lock-keywords
249 `(("@\\([a-zA-Z]+\\|[^ \t\n]\\)" 1 font-lock-keyword-face) ;commands
250 ("^\\*\\([^\n:]*\\)" 1 font-lock-function-name-face t) ;menu items
251 ("@\\(emph\\|i\\|sc\\){\\([^}]+\\)" 2 'italic)
252 ("@\\(strong\\|b\\){\\([^}]+\\)" 2 'bold)
253 ("@\\(kbd\\|key\\|url\\|uref\\){\\([^}]+\\)" 2 font-lock-string-face)
254 ("@\\(file\\|email\\){\\([^}]+\\)" 2 font-lock-string-face keep)
255 ("@\\(samp\\|code\\|var\\|math\\|env\\|command\\|option\\){\\([^}]+\\)"
256 2 font-lock-variable-name-face keep)
257 ("@\\(cite\\|x?ref\\|pxref\\|dfn\\|inforef\\){\\([^}]+\\)"
258 2 font-lock-reference-face) ;; #### XEmacs change
259 ("@\\(anchor\\){\\([^}]+\\)" 2 font-lock-type-face)
260 ("@\\(dmn\\|acronym\\|value\\){\\([^}]+\\)" 2 font-lock-builtin-face)
261 ("@\\(end\\|itemx?\\) +\\(.+\\)" 2 font-lock-keyword-face keep)
262 (,(concat "^@\\(" (regexp-opt (mapcar 'car texinfo-section-list) t)
263 "\\)\\(.*\n\\)") 3 texinfo-heading-face t)
264 ("@c\\(omment\\)? \\(.*$\\)" 2 font-lock-comment-face)
265 ("@node \\(.*$\\)" 1 font-lock-warning-face)
266 ("^@[cfvkpt]index \\(.*$\\)" 1 font-lock-variable-name-face)))
268 (defun sy-texinfo-menu () (easy-menu-add texinfo-mode-menu))
269 (add-hook 'texinfo-mode-hook #'sy-texinfo-menu)
270 (add-hook 'texinfo-mode-hook #'font-lock-mode)
271 ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*
272 (message "LaTeX initialised")