]> code.delx.au - gnu-emacs/blobdiff - lisp/textmodes/tex-mode.el
Fix minor quoting problems in doc strings
[gnu-emacs] / lisp / textmodes / tex-mode.el
index fad90473aaeb45f92bdc9cf665bc1272c8bb8508..535b885767736851692b1302662082189759cc45 100644 (file)
@@ -1,6 +1,6 @@
 ;;; tex-mode.el --- TeX, LaTeX, and SliTeX mode commands -*- coding: utf-8 -*-
 
-;; Copyright (C) 1985-1986, 1989, 1992, 1994-1999, 2001-2014 Free
+;; Copyright (C) 1985-1986, 1989, 1992, 1994-1999, 2001-2015 Free
 ;; Software Foundation, Inc.
 
 ;; Maintainer: emacs-devel@gnu.org
@@ -1034,7 +1034,7 @@ says which mode to use."
 (define-derived-mode plain-tex-mode tex-mode "TeX"
   "Major mode for editing files of input for plain TeX.
 Makes $ and } display the characters they match.
-Makes \" insert `` when it seems to be the beginning of a quotation,
+Makes \" insert \\=`\\=` when it seems to be the beginning of a quotation,
 and '' when it appears to be the end; it inserts \" only after a \\.
 
 Use \\[tex-region] to run TeX on the current region, plus a \"header\"
@@ -1080,7 +1080,7 @@ special subshell is initiated, the hook `tex-shell-hook' is run."
 (define-derived-mode latex-mode tex-mode "LaTeX"
   "Major mode for editing files of input for LaTeX.
 Makes $ and } display the characters they match.
-Makes \" insert `` when it seems to be the beginning of a quotation,
+Makes \" insert \\=`\\=` when it seems to be the beginning of a quotation,
 and '' when it appears to be the end; it inserts \" only after a \\.
 
 Use \\[tex-region] to run LaTeX on the current region, plus the preamble
@@ -1162,7 +1162,7 @@ subshell is initiated, `tex-shell-hook' is run."
 (define-derived-mode slitex-mode latex-mode "SliTeX"
   "Major mode for editing files of input for SliTeX.
 Makes $ and } display the characters they match.
-Makes \" insert `` when it seems to be the beginning of a quotation,
+Makes \" insert \\=`\\=` when it seems to be the beginning of a quotation,
 and '' when it appears to be the end; it inserts \" only after a \\.
 
 Use \\[tex-region] to run SliTeX on the current region, plus the preamble
@@ -1203,9 +1203,32 @@ Entering SliTeX mode runs the hook `text-mode-hook', then the hook
   (setq tex-command slitex-run-command)
   (setq tex-start-of-header "\\\\documentstyle{slides}\\|\\\\documentclass{slides}"))
 
+(defvar tildify-space-string)
+(defvar tildify-foreach-region-function)
+
 (defun tex-common-initialization ()
   ;; Regexp isearch should accept newline and formfeed as whitespace.
   (setq-local search-whitespace-regexp "[ \t\r\n\f]+")
+  ;; Use tilde as hard-space character in tildify package.
+  (setq-local tildify-space-string "~")
+  ;; FIXME: Use the fact that we're parsing the document already
+  ;; rather than using regex-based filtering.
+  (setq-local tildify-foreach-region-function
+              (apply-partially
+               'tildify-foreach-ignore-environments
+               `(("\\\\\\\\" . "") ; do not remove this
+                 (,(eval-when-compile
+                     (concat "\\\\begin{\\("
+                             (regexp-opt '("verbatim" "math" "displaymath"
+                                           "equation" "eqnarray" "eqnarray*"))
+                             "\\)}"))
+                  . ("\\\\end{" 1 "}"))
+                 ("\\\\verb\\*?\\(.\\)" . (1))
+                 ("\\$\\$?" . (0))
+                 ("\\\\(" . "\\\\)")
+                 ("\\\\[[]" . "\\\\[]]")
+                 ("\\\\[a-zA-Z]+\\( +\\|{}\\)[a-zA-Z]*" . "")
+                 ("%" . "$"))))
   ;; A line containing just $$ is treated as a paragraph separator.
   (setq-local paragraph-start "[ \t]*$\\|[\f\\\\%]\\|[ \t]*\\$\\$")
   ;; A line starting with $$ starts a paragraph,
@@ -1273,7 +1296,7 @@ Entering SliTeX mode runs the hook `text-mode-hook', then the hook
 
 (defun tex-insert-quote (arg)
   "Insert the appropriate quote marks for TeX.
-Inserts the value of `tex-open-quote' (normally ``) or `tex-close-quote'
+Inserts the value of `tex-open-quote' (normally \\=`\\=`) or `tex-close-quote'
 \(normally '') depending on the context.  With prefix argument, always
 inserts \" characters."
   (interactive "*P")
@@ -1308,7 +1331,9 @@ inserts \" characters."
           (goto-char saved)
           (insert (if (> saved (mark)) tex-close-quote tex-open-quote)))
       (if (or (memq (char-syntax (preceding-char)) '(?\( ?> ?\s))
-              (memq (preceding-char) '(?~)))
+              (memq (preceding-char) '(?~ ?')))
+          ;; We're in an "opening" context
+          ;;
           (if electric-pair-mode
               (if (looking-at (regexp-quote tex-close-quote))
                   (forward-char (length tex-close-quote))
@@ -1316,6 +1341,8 @@ inserts \" characters."
                 (insert tex-close-quote)
                 (backward-char (length tex-close-quote)))
             (insert tex-open-quote))
+        ;; We're in a "closing" context.
+        ;;
         (if (looking-at (regexp-quote tex-close-quote))
             (forward-char (length tex-close-quote))
           (insert tex-close-quote))))))
@@ -1738,13 +1765,13 @@ Mark is left at original location."
        ;; A better way to handle this, \( .. \) etc, is probably to
        ;; temporarily change the syntax of the \ in \( to punctuation.
        ((and latex-handle-escaped-parens
-            (looking-back "\\\\[])}]"))
+            (looking-back "\\\\[])}]" (- (point) 2)))
        (signal 'scan-error
                (list "Containing expression ends prematurely"
                      (- (point) 2) (prog1 (point)
                                      (goto-char pos)))))
        ((and latex-handle-escaped-parens
-            (looking-back "\\\\\\([({[]\\)"))
+            (looking-back "\\\\\\([({[]\\)" (- (point) 2)))
        (tex-next-unmatched-eparen (match-string 1)))
        (t (goto-char newpos))))))
 
@@ -2603,18 +2630,28 @@ line LINE of the window, or centered if LINE is nil."
                      (prefix-numeric-value linenum)
                    (/ (window-height) 2)))))))
 
+(defcustom tex-print-file-extension ".dvi"
+  "The TeX-compiled file extension for viewing and printing.
+If you use pdflatex instead of latex, set this to \".pdf\" and modify
+ `tex-dvi-view-command' and `tex-dvi-print-command' appropriately."
+  :type 'string
+  :group 'tex-view
+  :version "25.1")
+
 (defun tex-print (&optional alt)
   "Print the .dvi file made by \\[tex-region], \\[tex-buffer] or \\[tex-file].
 Runs the shell command defined by `tex-dvi-print-command'.  If prefix argument
 is provided, use the alternative command, `tex-alt-dvi-print-command'."
   (interactive "P")
-  (let ((print-file-name-dvi (tex-append tex-print-file ".dvi"))
+  (let ((print-file-name-dvi (tex-append tex-print-file
+                                         tex-print-file-extension))
        test-name)
     (if (and (not (equal (current-buffer) tex-last-buffer-texed))
             (buffer-file-name)
             ;; Check that this buffer's printed file is up to date.
             (file-newer-than-file-p
-             (setq test-name (tex-append (buffer-file-name) ".dvi"))
+             (setq test-name (tex-append (buffer-file-name)
+                                          tex-print-file-extension))
              (buffer-file-name)))
        (setq print-file-name-dvi test-name))
     (if (not (file-exists-p print-file-name-dvi))