1 ;; 05-latex.el --- LaTeX Settings
3 ;; Copyright (C) 2007 - 2021 Steve Youngs
5 ;; Author: Steve Youngs <steve@sxemacs.org>
6 ;; Maintainer: Steve Youngs <steve@sxemacs.org>
7 ;; Created: <2007-12-02>
8 ;; Time-stamp: <Monday 12 Apr 2021 13:42:36 (steve)>
9 ;; Download: <https://downloads.sxemacs.org/SYinits/>
10 ;; HTMLised: <https://www.sxemacs.org/SYinits/05-latex.html>
11 ;; Git Repo: git clone https://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 ;:*=======================
67 (require 'reftex-vars)
68 (require 'latex-units)
70 (require 'latex-toolbar)
72 ;:*=======================
74 ;; LaTeX or latex ??? It doesn't really matter because LaTeX-mode is
75 ;; an alias to latex-mode, I just prefer the former name and like to
76 ;; keep things less messy.
78 ;; Remove the ones set from tex-mode.el in the texinfo pkg that use
80 (remove-alist 'auto-mode-alist "\\.\\(?:sty\\|cls\\|bbl\\)\\'")
81 (remove-alist 'auto-mode-alist "\\.[tT]e[xX]\\'")
82 (remove-alist 'auto-mode-alist "\\.ltx\\'")
83 ;; Add them back for LaTeX-mode
84 (add-to-list 'auto-mode-alist '("\\.\\(?:sty\\|cls\\|bbl\\)\\'" . LaTeX-mode))
85 (add-to-list 'auto-mode-alist '("\\.[tT]e[xX]\\'" . LaTeX-mode))
86 (add-to-list 'auto-mode-alist '("\\.ltx\\'" . LaTeX-mode))
87 (add-to-list 'auto-mode-alist '("\\.drv\\'" . LaTeX-mode))
89 (add-to-list 'auto-mode-alist '("\\.dtx\\'" . doctex-mode))
91 ;:*=======================
92 ;:* Shutup the byte-compiler
93 (defvar ispell-extra-args)
94 (defvar LaTeX-mode-map)
100 TeX-arg-footnote-number-p t
101 TeX-arg-item-label-p nil
102 TeX-auto-parse-length 999999999
104 (file-name-as-directory
105 (expand-file-name "documents/TeXauto" (getenv "HOME")))
107 TeX-debug-bad-boxes nil
109 (file-name-as-directory
110 (expand-file-name "documents/TeX" (getenv "HOME")))
111 TeX-outline-extra nil
113 TeX-printer-default "Single Colour"
115 '(("Duplex Colour" "dvips -f %s|lpr -PDuplex_Colour" "lpq -PDuplex_Colour")
116 ("Single Colour" "dvips -f %s|lpr -PSingle_Colour" "lpq -PSingle_Colour")
117 ("Duplex Grey" "dvips -f %s|lpr -PDuplex_Grey" "lpq -PDuplex_Grey")
118 ("Single Grey" "dvips -f %s|lpr -PSingle_Grey" "lpq -PSingle_Grey")
119 ("Photo" "dvips -f %s|lpr -PPhoto" "lpq -PPhoto")
120 ("DL Envelope" "dvips -f %s|lpr -PDL_Envelope" "lpq -PDL_Envelope")))
122 (setq-default LaTeX-default-options "a4paper,12pt")
123 (setq-default TeX-master t)
125 (setq TeX-view-style '(("^a5$" "xdvi -thorough %d -paper a5")
126 ("^landscape$" "xdvi -thorough %d -paper a4r -s 4")
127 ("." "xdvi -thorough %d")))
129 ;:*=======================
130 ;:* Count words in a TeX text
131 (defun sds-word-count (start end)
132 "Count lines/words/characters from START to END.
133 Replacement for count-lines-region."
135 (let ((ost (syntax-table))
136 (nst (copy-syntax-table)))
137 (modify-syntax-entry ?_ "w" nst)
138 (modify-syntax-entry ?- "w" nst)
141 (narrow-to-region start end)
142 (goto-char (min start end))
144 (progn (set-syntax-table nst)
146 "Region (%d to %d) has: %d lines; %d words; %d characters."
147 start end (count-lines start end)
148 (string-to-number (how-many "\\<"))
150 (set-syntax-table ost))))))
152 ;:*=======================
153 ;:* RefTeX Minor Mode
155 ;; Turn on RefTeX Minor Mode for all LaTeX files
156 (autoload 'reftex-mode "reftex" "RefTeX Minor Mode" t)
157 (autoload 'turn-on-reftex "reftex" "RefTeX Minor Mode" nil)
158 (autoload 'reftex-citation "reftex-cite" "Make citation" nil)
160 ;: RefTeX is a minor mode with distinct support for \ref, \label and
161 ;: \cite commands in (multi-file) LaTeX documents.
163 reftex-default-label-alist-entries
164 '(Sideways AMSTeX amsmath endnotes fancybox floatfig longtable
165 picinpar rotating sidecap subfigure supertab wrapfig LaTeX)
166 reftex-enable-partial-scans t
167 reftex-extra-bindings t
168 reftex-guess-label-type t
169 reftex-initialize-temporary-buffers t
170 reftex-insert-label-flags '(t t)
171 reftex-keep-temporary-buffers t
173 '((nil ?s nil nil nil ("Capital" "Cap." "Section" "Part") -3)
174 (nil ?e nil nil nil ("Equation" "Eq.") -3)
175 (nil ?t nil nil nil ("Table") -3)
176 (nil ?f nil nil nil ("Figure" "Illustration" "Ill.") -3)
177 (nil ?n nil nil nil ("Comment") -3)
178 (nil ?i nil nil nil ("Point") -3))
179 reftex-label-menu-flags '(t t t t t t t t)
180 reftex-plug-into-AUCTeX t
181 reftex-save-parse-info t
182 reftex-toc-follow-mode t
183 reftex-toc-include-labels t
184 reftex-use-multiple-selection-buffers t
185 reftex-vref-is-default t)
187 ;:*=======================
189 ;;When writing a document with an index you will probably define
190 ;;additional macros which make entries into the index. Let's look at an
192 ;; \newcommand{\ix}[1]{#1\index{#1}}
193 ;; \newcommand{\nindex}[1]{\textit{#1}\index[name]{#1}}
194 (setq reftex-index-macros '(("\\ix{*}" "idx" ?x "" nil nil)
195 ("\\nindex{*}" "name" ?n "" nil nil)
198 (defun return-created-string ()
199 "Return a \"Created:\" string."
200 (let ((time (current-time-string)))
201 (concat "Created at: "
202 (substring time 0 20)
203 (nth 1 (current-time-zone))
205 (substring time -4) " ")))
207 ;:*=======================
209 (defun sy-LaTeX-toolbar ()
211 (set-specifier left-toolbar-width (cons (current-buffer) 32))
212 (latex-toolbar-install))
214 (defun sy-LaTeX-mode-hook ()
216 (setq TeX-shell "/bin/zsh")
217 (make-local-variable 'ispell-extra-args)
218 (push "-t" ispell-extra-args)
220 (add-to-list 'TeX-command-list
221 '("xpdf" "xpdf %s.pdf" TeX-run-silent t nil))
222 (add-to-list 'TeX-command-list
223 '("gv" "gv %s.ps" TeX-run-silent t nil))
224 (add-to-list 'TeX-command-list
225 '("pdflatex" "pdflatex -interaction=nonstopmode %t"
226 TeX-run-command nil t))
227 (when (device-on-window-system-p)
228 (outl-mouse-minor-mode 1)
229 ;; I can't get my extra toolbar to display from the hook, I don't
230 ;; yet know why, so instead I bind `S-H-t' locally to load it.
231 (local-set-key [(super hyper t)] #'sy-LaTeX-toolbar)))
233 (add-hook 'LaTeX-mode-hook #'sy-LaTeX-mode-hook 'append)
235 (setq LaTeX-section-hook
236 '(LaTeX-section-heading
239 LaTeX-section-section
240 LaTeX-section-label))
242 ;:*=======================
244 ;; Jumping through hoops to ensure that we DO NOT get the AUCTeX
245 ;; tex-info. The texinfo.el from the "texinfo" (S)XEmacs package is
246 ;; older, but far, far, superior. Honestly, the AUCTeX / GNU people
247 ;; have no idea what they're missing.
248 (eval-after-load 'tex-info
250 (delq 'texinfo-mode TeX-modes)
251 (defalias 'texinfo-mode #'ignore)
254 (set-face-parent 'texinfo-heading-face 'font-lock-function-name-face)
257 (setq texinfo-font-lock-keywords
258 `(("@\\([a-zA-Z]+\\|[^ \t\n]\\)" 1 font-lock-keyword-face) ;commands
259 ("^\\*\\([^\n:]*\\)" 1 font-lock-function-name-face t) ;menu items
260 ("@\\(emph\\|i\\|sc\\){\\([^}]+\\)" 2 'italic)
261 ("@\\(strong\\|b\\){\\([^}]+\\)" 2 'bold)
262 ("@\\(kbd\\|key\\|url\\|uref\\){\\([^}]+\\)" 2 font-lock-string-face)
263 ("@\\(file\\|email\\){\\([^}]+\\)" 2 font-lock-string-face keep)
264 ("@\\(samp\\|code\\|var\\|math\\|env\\|command\\|option\\){\\([^}]+\\)"
265 2 font-lock-variable-name-face keep)
266 ("@\\(cite\\|x?ref\\|pxref\\|dfn\\|inforef\\){\\([^}]+\\)"
267 2 font-lock-reference-face) ;; #### XEmacs change
268 ("@\\(anchor\\){\\([^}]+\\)" 2 font-lock-type-face)
269 ("@\\(dmn\\|acronym\\|value\\){\\([^}]+\\)" 2 font-lock-builtin-face)
270 ("@\\(end\\|itemx?\\) +\\(.+\\)" 2 font-lock-keyword-face keep)
271 (,(concat "^@\\(" (regexp-opt (mapcar 'car texinfo-section-list) t)
272 "\\)\\(.*\n\\)") 3 texinfo-heading-face t)
273 ("@c\\(omment\\)? \\(.*$\\)" 2 font-lock-comment-face)
274 ("@node \\(.*$\\)" 1 font-lock-warning-face)
275 ("^@[cfvkpt]index \\(.*$\\)" 1 font-lock-variable-name-face)))
277 (defun sy-texinfo-menu ()
278 (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")