[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[AUCTeX] sub & superscript faces in .lisp files

From: Mirko Vukovic
Subject: [AUCTeX] sub & superscript faces in .lisp files
Date: Sun, 25 Apr 2010 14:03:40 -0400


I am trying to implement the sub- and superscripting fonts in display
of common-lisp files.  I hacked the relevant parts of tex-mode.el, but
without success.  You can see my code below.

I will appreciate in pointers in how to display sub & superscripts.

Thank you

---------- Forwarded message ----------
From: Mirko Vukovic <address@hidden>
Date: Mon, Apr 19, 2010 at 8:30 PM
Subject: sub & superscript faces in .lisp files
To: address@hidden


Apologies for this slightly off-topic question, but it may relate to
slime's `group' settings
(Much off this email is a copy of a post to

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
Not smaller than the value set by `tex-suscript-height-minimum'."
 (ceiling (max (if (integerp 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'"
 (setq suscript-flk
          (1 (face subscript display (raise 0.2))))
          (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'"
 (font-lock-remove-keywords nil suscript-flk))

The contents `font-lock-keywords' are as follows:

 (("_\\(.*?\\)[_^  )$-]"
   (face subscript display
         (raise 0.2))))
 ("\\^\\(.*?\\)[_^        )$-]"
   (face superscript display
         (raise -0.2))))

My question is whether I need to specify a group in the `defface'
commands.  For example:
(defface superscript
 '((t :height 0.8));;suscript-height))
 "Face used for superscripts."
 :group 'slime-mode-faces)

I found several groups in slime.el, and I am not sure which one to
apply in defface.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]