Article View: comp.sys.next.software
Article #1768Re: TeX backslash (\) on the NeXT
From: Bill Vrotney
Date: Wed, 27 Jan 1993 08:02
Date: Wed, 27 Jan 1993 08:02
133 lines
5232 bytes
5232 bytes
In article <C1H4KB.M8y@utstat.toronto.edu> reid@utstat.toronto.edu (Nancy
Reid) writes:
> Newsgroups: comp.sys.next.software
> Path: ads.com!ames!saimiri.primate.wisc.edu!usenet.coe.montana.edu!rpi!utcsri!utgpu!utstat!reid
> From: reid@utstat.toronto.edu (Nancy Reid)
> Organization: U of Toronto Statistics
> Distribution: comp.sys.next.software
> Date: Tue, 26 Jan 1993 18:26:34 GMT
> Lines: 3
>
> Is there a way to redefine keys on the NeXT keyboard so that the
> backslash character (\) is in a more convenient place, thus making
> TeX and LateX files much easier to type?
I have done this one better. If you like to use EMACS I have generated a
function and keybindings for TeX mode so that you can insert any TeX
commands \<command> (that the user specifies in a table) with a single
keystroke. With this you will never have to enter a \ in TeX again. This
same function will also insert various TeX brackets depending on its
argument. An argument of 0 would insert the \<command> by itself. For
example
largetext C-cC-c l
would result in
{\large largetext}
where as
ESC 0 C-cC-c l
would result in
\large
Hitting C-cC-c RET would display the table of command keys. I placed the
elisp code below for anyone who wants it.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Define commands for inserting TeX bracketed commands.
; (you can add to or modify this table).
(defconst ct:*TeX-brackets*
'((?\[ "em")
(?\] "bf")
(?' "tt")
(?. "item" ?\[)
(?= "verbatim")
(?/ "index")
(?\t "noindent")
(?0 "document")
(?1 "section" ?\{)
(?2 "subsection" ?\{)
(?3 "subsubsection" ?\{)
(?d "description")
(?e "enumerate")
(?i "itemize")
(?l "large")
(?n "normalsize")
(?p "samepage")
(?q "quote")
(?r "rm")
(?s "small")
(?t "tabular")
(?v "vspace" ?\{)))
(defun ct:TeX-bracket (arg)
"Given a selection character brackets previous word with the TeX command
associated with the selection in the variable ct:*TeX-brackets*.
If ARG = n brackets previous n words (-n brackets next n words).
If ARG = 1 brackets region.
If ARG = 0 just inserts the TeX command.
If ARG = CNTL-U brackets region with begin and end TeX commands."
(interactive "P")
(message "Enter selection character (RETURN gives selections) :")
(let* ((selection (read-char))
(bracket-spec (if (eq selection ?\r) nil
(cdr (assoc selection ct:*TeX-brackets*))))
(special-bracket (if (= (length bracket-spec) 2)
(nth 1 bracket-spec)))
(left-bracket (char-to-string (if special-bracket special-bracket
?\{)))
(right-bracket (cond ((string= left-bracket "[") "]")
((string= left-bracket "{") "}")))
(TeX-word (car bracket-spec))
(new-line "\n")
(begin-insert
(cond
((consp arg)
(concat "\\begin" left-bracket TeX-word right-bracket new-line))
((and (numberp arg) (= arg 0)) (concat "\\" TeX-word))
(special-bracket (concat "\\" TeX-word left-bracket))
(t (concat left-bracket "\\" TeX-word " "))))
(end-insert
(if (consp arg)
(concat "\\end" left-bracket TeX-word right-bracket new-line)
right-bracket)))
(if (not arg) (setq arg 1)
(if (and (numberp arg) (= arg 1)) (setq arg nil)))
(if bracket-spec
(cond
((and (numberp arg) (= arg 0)) (insert begin-insert))
(t (let (begin end)
(cond ((listp arg)
(setq begin (region-beginning)) (setq end (region-end)))
(t
(if (< arg 0) (setq begin (point)) (setq end (point)))
(backward-word arg)
(if (< arg 0) (setq end (point)) (setq begin (point)))))
(goto-char begin) (insert begin-insert)
(goto-char (+ end (length begin-insert))) (insert end-insert))))
(ct:show-TeX-brackets))))
(defun ct:show-TeX-brackets ()
(with-output-to-temp-buffer "*TeX-bracket-selections*"
(buffer-flush-undo standard-output)
(let ((n 0))
(mapcar
'(lambda (bracket-spec)
(terpri) (princ (char-to-string (car bracket-spec))) (princ " = ")
(princ (car (cdr bracket-spec))))
ct:*TeX-brackets*))))
(define-key TeX-mode-map "\C-c\C-c" 'ct:TeX-bracket)
--
Bill Vrotney
BAH/Advanced Decision Systems
Technical Details
Message-ID:
<1993Jan27.080245.333@ads.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!UB.com!pacbell.com!decwrl!ads.com!bvrotneyShow Full Headers
Complete Article Headers
Newsgroups: comp.sys.next.software Path: arc1-ca.pugleaf.net!sparky!uunet!UB.com!pacbell.com!decwrl!ads.com!bvrotney From: bvrotney@ADS.COM (Bill Vrotney) Subject: Re: TeX backslash (\) on the NeXT In-Reply-To: reid@utstat.toronto.edu's message of Tue, 26 Jan 1993 18:26:34 GMT Message-ID: <1993Jan27.080245.333@ads.com> Sender: usenet@ads.com (USENET News) Organization: Advanced Decision Systems, Mtn. View, CA (415) 960-7300 Distribution: comp.sys.next.software Date: Wed, 27 Jan 1993 08:02:45 GMT Lines: 133