Re: tex-symb
Masayuki Ataka <[email protected]> Wed, 09 Mar 2005 07:10:12 +0900 (JST)
| Newsgroups | gmane.emacs.auc-tex |
|---|---|
| Message-ID | <[email protected]> |
A new tex-symb.el is attached. From: Ralf Angeli <[email protected]> Subject: Re: tex-symb Date: Tue, 08 Mar 2005 10:20:40 +0100 > * Masayuki Ataka (2005-03-07) writes: > > > From: Ralf Angeli <[email protected]> > > [folding classes] > > > How about preparing the buffer local variable, which holds > > which features are folded. For example, in tex-symb.el, > > TeX-symb-ascii-arrow-list has the fuature that allows are > > displayed with ascii text, where allows are displayed with > > unicode font, by default. We can choose how to display allows > > with ascii or unicode. > > I'd like to have a more explicit mechanism than that. There would > have to be a variable where the user can (in the customization buffer) > activate or deactivate certain classes by clicking on check boxes. > Hm, maybe we can prepare the menu, like this Fold Mode ========= [] Section [] Label [] Item [] Footnote [] Cite [] Index [] Math [] Greek [] Arrow... [] UNICODE arrow [] ASCII arrow [] Binary Operator [] Accent char [] Misc Don't ask me the code, this is one idea ;) > > Similarly, we can divide > > TeX-fold-macro-spec-list by section, item, footnote, ref, and > > label. And add their variables into TeX-fold-macro-spec-list, > > if we want to fold them. > > Yes, that's the other side of the problem. I am currently not too > happy with how `TeX-fold-macro-spec-list' is looking, especially that > the keyword lists for macros where the content of an argument should > be shown are inside it. In case folding classes are added it will > probably be better to split this variable in separate ones for every > folding class. For each class there will probably have to be a > variable for the system default and one holding additions made by the > user (similar to what is currently done for font locking). We need a > good scheme for that and have to keep in mind how this relates to the > other keyword lists we currently have in AUCTeX. As written before, > it would be nice to have these consolidated. > New tex-symb.el has following variables. (defvar TeX-fold-item-list '(("*" ("item")))) (defvar TeX-fold-footnote-list '(("[f]" ("footnote")))) (defvar TeX-fold-marginpar-list '(("[mp]" ("marginpar")))) (defvar TeX-fold-cite-list '(("[c]" ("cite")))) (defvar TeX-fold-label-list '(("[l]" ("label")))) (defvar TeX-fold-ref-list '(("[r]" ("ref" "eqref")))) (defvar TeX-fold-index-list '(("[i]" ("index" "glossary")))) (defvar TeX-fold-section-list '((1 ("part" "chapter" "section" "subsection" "subsubsection" "paragraph" "subparagraph" "part*" "chapter*" "section*" "subsection*" "subsubsection*" "paragraph*" "subparagraph*")))) (defvar TeX-fold-text-font-list '((1 ("emph" "textit" "textsl" "textmd" "textrm" "textsf" "texttt" "textbf" "textsc" "textup")))) Sorry, they are not consolidated, yet. From: Masayuki Ataka <[email protected]> Subject: tex-symb Date: Sat, 05 Mar 2005 20:13:57 +0900 (JST) > * Bugs / Problems / Limitations > Sometimes, tex-symb does not fold TeX macros in CVS Emacs. > In such a case: > \leq\alpha > \leq is not folded because regexp `\\_>' in TeX-fold-region > matches `\'. New tex-symb.el overwrite TeX-fold-region, just fix not to use `\\_>' in CVS Emacs. I'm not sure if `\\_>' should match `\' in TeX source. > Currently, The argument of \sqrt becomes invisible, because TeX (snip) > Similar TeX commands (ex. hat, bar, vec, etc...) have the same > problems. Fixed. regards, --- email: [email protected] Name:: Masayuki Ataka // (Japan)
tex-symb.el
(text/plain, 7.5 KB)
;;; tex-symb.el --- TeX symbol macros. ;; Copyright (C) 2005 Free Software Foundation. ;; Author: Masayuki Ataka <[email protected]> ;; Maintainer: [email protected] ;; Created: 2005-03-03 ;; Keywords: tex, wp ;; This file is part of AUCTeX. ;; AUCTeX is free software; you can redistribute it and/or modify it ;; under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 2, or (at your option) ;; any later version. ;; AUCTeX is distributed in the hope that it will be useful, but ;; WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;; General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with AUCTeX; see the file COPYING. If not, write to the Free ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA ;; 02111-1307, USA. ;;; Commentary: ;; This file provides additional support for tex-fold.el. ;;; Code: (require 'tex-fold) (defun TeX-fold-region (start end &optional type) "Fold all items in region starting at position START and ending at END. If optional parameter TYPE is given, fold only items of the specified type. TYPE can be one of the symbols 'env for environments or 'macro for macros." (interactive "r") (if (null type) (progn (TeX-fold-region start end 'env) (TeX-fold-region start end 'macro)) (when (or (and (eq type 'env) (not (eq major-mode 'plain-tex-mode))) (eq type 'macro)) (save-excursion (let (fold-list item-list regexp) (dolist (item (if (eq type 'env) TeX-fold-env-spec-list TeX-fold-macro-spec-list)) (dolist (i (cadr item)) (add-to-list 'fold-list (list i (car item))) (add-to-list 'item-list i))) (setq regexp (cond ((and (eq type 'env) (eq major-mode 'context-mode)) (concat (regexp-quote TeX-esc) "start" (regexp-opt item-list t))) ((and (eq type 'env) (eq major-mode 'texinfo-mode)) (concat (regexp-quote TeX-esc) (regexp-opt item-list t))) ((eq type 'env) (concat (regexp-quote TeX-esc) "begin[ \t]*{" (regexp-opt item-list t) "}")) (t ;; "\\_>" is only available with Emacs ;; 21.4 or later (checked into CVS Emacs ;; on 2004-05-19). (This could be used in ;; font-latex as well for ;; `font-latex-match-variable-make' and ;; friends instead of "\\>" and would fix ;; issues with starred macros.) (concat (regexp-quote TeX-esc) (regexp-opt item-list t) "[^A-Za-z@*]")))) (save-restriction (narrow-to-region start end) ;; Start from the bottom so that it is easier to prioritize ;; nested macros. (goto-char (point-max)) (let ((case-fold-search nil)) (while (re-search-backward regexp nil t) (when (not (and TeX-fold-preserve-comments (TeX-in-commented-line))) (let* ((item-start (match-beginning 0)) (display-string-spec (cadr (assoc (match-string 1) fold-list))) (item-end (cond ((and (eq type 'env) (eq major-mode 'context-mode)) (save-excursion (goto-char (match-end 0)) (ConTeXt-find-matching-stop) (point))) ((and (eq type 'env) (eq major-mode 'texinfo-mode)) (save-excursion (goto-char (match-end 0)) (Texinfo-find-env-end) (point))) ((eq type 'env) (save-excursion (goto-char (match-end 0)) (LaTeX-find-matching-end) (point))) (t (save-excursion (goto-char item-start) (TeX-find-macro-end))))) (display-string (if (integerp display-string-spec) (or (TeX-fold-macro-nth-arg display-string-spec item-start (when (eq type 'macro) item-end)) "[Error: No content found]") display-string-spec)) (ov (TeX-fold-make-overlay item-start item-end type display-string-spec display-string))) (TeX-fold-hide-item ov))))))))))) (defun TeX-fold-prioritize (start end) "Calculate a priority for an overlay extending from START to END. The calculated priority is lower than the minimum of priorities of surrounding overlays and higher than the maximum of enclosed overlays." (let (outer-priority inner-priority) (dolist (ov (overlays-in start end)) (when (or (eq (overlay-get ov 'category) 'TeX-fold) (overlay-get ov 'preview-map)) (let ((ov-priority (overlay-get ov 'priority))) (if (>= (overlay-start ov) start) (setq inner-priority (max ov-priority (or inner-priority ov-priority))) (setq outer-priority (min ov-priority (or outer-priority ov-priority))))))) (cond ((and inner-priority (not outer-priority)) (+ inner-priority TeX-fold-priority-step)) ((and (not inner-priority) outer-priority) (/ outer-priority 2)) ((and inner-priority outer-priority) (/ (- outer-priority inner-priority) 2)) (t TeX-fold-priority-step)))) (defvar TeX-fold-macro-list '(("..." ("dots")))) (defvar TeX-fold-item-list '(("*" ("item")))) (defvar TeX-fold-footnote-list '(("[f]" ("footnote")))) (defvar TeX-fold-marginpar-list '(("[mp]" ("marginpar")))) (defvar TeX-fold-cite-list '(("[c]" ("cite")))) (defvar TeX-fold-label-list '(("[l]" ("label")))) (defvar TeX-fold-ref-list '(("[r]" ("ref" "eqref")))) (defvar TeX-fold-index-list '(("[i]" ("index" "glossary")))) (defvar TeX-fold-section-list '((1 ("part" "chapter" "section" "subsection" "subsubsection" "paragraph" "subparagraph" "part*" "chapter*" "section*" "subsection*" "subsubsection*" "paragraph*" "subparagraph*")))) (defvar TeX-fold-text-font-list '((1 ("emph" "textit" "textsl" "textmd" "textrm" "textsf" "texttt" "textbf" "textsc" "textup")))) ;; Arrow (defvar TeX-symb-ascii-text-list '(("(C)" ("copyright")) ("(R)" ("textregistered")) ("TM" ("texttrademark")) )) (defvar TeX-symb-ascii-arrow-list '(;; <- ("<-" ("leftarrow" "gets")) ("<=" ("Leftarrow")) ("<--" ("longleftarrow")) ("<==" ("Longleftarrow")) ;; -> ("->" ("rightarrow" "to")) ("=>" ("Rightarrow")) ("-->" ("longrightarrow")) ("==>" ("Longrightarrow")) ;; <-> ("<->" ("leftrightarrow")) ("<=>" ("Leftrightarrow")) ("<-->" ("longleftrightarrow")) ("<==>" ("Longleftrightarrow"))) "List of arrow (ascii)") (defvar TeX-symb-utf-math-list nil) (unless TeX-symb-utf-math-list (setq TeX-symb-utf-math-list (delete nil (mapcar (lambda (elt) (let* ((tex (nth 1 elt)) (submenu (nth 2 elt)) noarg (unicode (nth 3 elt)) (uchar (and (integerp unicode) (decode-char 'ucs unicode)))) (if (listp submenu) (setq submenu (nth 1 submenu))) (setq noarg (not (string-match (concat "^" (regexp-opt '("Constructs" "Accents"))) submenu))) (when (and (stringp tex) (integerp uchar) noarg) (list (char-to-string uchar) (list tex))))) `((nil "to" "" 8594) (nil "gets" "" 8592) ,@LaTeX-math-default))))) (setq TeX-fold-macro-spec-list (append ; TeX-symb-ascii-arrow-list TeX-symb-utf-math-list TeX-fold-text-font-list TeX-fold-item-list TeX-fold-footnote-list TeX-fold-marginpar-list TeX-fold-cite-list TeX-fold-label-list ; TeX-fold-ref-list TeX-fold-index-list ; TeX-fold-section-list TeX-fold-macro-list)) ;; Provide ourselves: (provide 'tex-symb) ;;; tex-symb.el ends here