From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Mirko Newsgroups: gmane.emacs.help Subject: displaying subscripts and superscripts Date: Sun, 18 Apr 2010 15:31:39 -0700 (PDT) Organization: http://groups.google.com Message-ID: <08eeb820-8cbd-48a1-a6f4-2407d1e6d717@c42g2000yqn.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: dough.gmane.org 1273010393 23382 80.91.229.12 (4 May 2010 21:59:53 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 4 May 2010 21:59:53 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue May 04 23:59:52 2010 connect(): No such file or directory Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1O9Q9g-0003qq-Cd for geh-help-gnu-emacs@m.gmane.org; Tue, 04 May 2010 23:59:52 +0200 Original-Received: from localhost ([127.0.0.1]:55050 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O9Q9f-0002iX-Vg for geh-help-gnu-emacs@m.gmane.org; Tue, 04 May 2010 17:59:52 -0400 Original-Path: usenet.stanford.edu!postnews.google.com!c42g2000yqn.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 80 Original-NNTP-Posting-Host: 74.76.172.207 Original-X-Trace: posting.google.com 1271629899 10125 127.0.0.1 (18 Apr 2010 22:31:39 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Sun, 18 Apr 2010 22:31:39 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: c42g2000yqn.googlegroups.com; posting-host=74.76.172.207; posting-account=yS7ZzQoAAACbDncxMo9UeCyhsLtcDWPM User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6,gzip(gfe) Original-Xref: usenet.stanford.edu gnu.emacs.help:177772 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:73213 Archived-At: Hello, I am trying to display text following an underscore as a subscript and following a caret as a superscript. By looking at various pieces of code (tex-mode.el and pretty-greek.el from Pascal Bourgignon), I came up with the following (which, of course does not work): (defvar suscript-height-minimum 0) (defvar suscript-height-ratio 0.8) (defun suscript-height (height) "Return the integer height of subscript/superscript font in 1/10 points. Not smaller than the value set by `tex-suscript-height-minimum'." (ceiling (max (if (integerp suscript-height-minimum) suscript-height-minimum ;; For bootstrapping. (condition-case nil (* suscript-height-minimum (face-attribute 'default :height)) (error 0))) ;; NB assumes height is integer. (* height suscript-height-ratio)))) (defface superscript '((t :height suscript-height)) "Face used for superscripts.") (defface subscript '((t :height suscript-height)) "Face used for subscripts.") (defun suscript-match-regexp (escape-char) "regexp for suscripted text match in common-lisp code" (let ((terminating-string (format "_^ )$-"))) (format "%s\\(.*?\\)[%s]" escape-char terminating-string terminating-string))) (defvar subscript-match (suscript-match-regexp "_") "Matches _whatever[_|^|SPACE|TAB|)") (defvar superscript-match (suscript-match-regexp "\\^") "Matches ^whatever[_|^|SPACE|TAB|)") (defun pretty-suscript () "Load super&subscript keywords into `suscript-flk' and load that into `font-lock-keywords'" (interactive) (setq suscript-flk `((,subscript-match (1 (face subscript display (raise 0.2)))) (,superscript-match (1 (face superscript display (raise -0.2)))))) (font-lock-add-keywords nil suscript-flk)) (defun cancel-pretty-suscript () "Remove `suscript-flk' keywords from `font-lock-keywords'" (interactive) (font-lock-remove-keywords nil suscript-flk)) The contents `font-lock-keywords' are as follows: (t (("_\\(.*?\\)[_^ )$-]" (1 (face subscript display (raise 0.2)))) ("\\^\\(.*?\\)[_^ )$-]" (1 (face superscript display (raise -0.2)))) ...) To my untrained eyes, it looks OK, when compared to entries produced by pretty-greek.el So, where am I going wrong? (Hopefully the list is finite). Thank you, Mirko