* displaying subscripts and superscripts
@ 2010-04-18 22:31 Mirko
2010-04-19 3:19 ` Stefan Monnier
0 siblings, 1 reply; 5+ messages in thread
From: Mirko @ 2010-04-18 22:31 UTC (permalink / raw)
To: help-gnu-emacs
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: displaying subscripts and superscripts
2010-04-18 22:31 displaying subscripts and superscripts Mirko
@ 2010-04-19 3:19 ` Stefan Monnier
2010-04-19 23:29 ` Glenn Morris
2010-04-20 0:14 ` Mirko
0 siblings, 2 replies; 5+ messages in thread
From: Stefan Monnier @ 2010-04-19 3:19 UTC (permalink / raw)
To: help-gnu-emacs
> (defun suscript-height (height)
[...]
> (defface superscript
> '((t :height suscript-height))
> "Face used for superscripts.")
The :height attribute cannot be a function. You probably just want to
use 0.8 (or suscript-height-ratio) here instead.
Stefan
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: displaying subscripts and superscripts
2010-04-19 3:19 ` Stefan Monnier
@ 2010-04-19 23:29 ` Glenn Morris
2010-04-21 18:18 ` Stefan Monnier
2010-04-20 0:14 ` Mirko
1 sibling, 1 reply; 5+ messages in thread
From: Glenn Morris @ 2010-04-19 23:29 UTC (permalink / raw)
To: help-gnu-emacs
Stefan Monnier wrote:
>> (defun suscript-height (height)
> [...]
>> (defface superscript
>> '((t :height suscript-height))
>> "Face used for superscripts.")
>
> The :height attribute cannot be a function.
Err, tex-mode.el uses a function for :height, and it seems to work...
The elisp manual says :height can be a function.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: displaying subscripts and superscripts
2010-04-19 3:19 ` Stefan Monnier
2010-04-19 23:29 ` Glenn Morris
@ 2010-04-20 0:14 ` Mirko
1 sibling, 0 replies; 5+ messages in thread
From: Mirko @ 2010-04-20 0:14 UTC (permalink / raw)
To: help-gnu-emacs
On Apr 18, 11:19 pm, Stefan Monnier <monn...@iro.umontreal.ca> wrote:
> > (defun suscript-height (height)
> [...]
> > (defface superscript
> > '((t :height suscript-height))
> > "Face used for superscripts.")
>
> The :height attribute cannot be a function. You probably just want to
> use 0.8 (or suscript-height-ratio) here instead.
>
> Stefan
Well, I tried that, and that did not work. But one more thing may be
amiss. In tex-mode.el, the subscript is defined as belonging to the
`tex group.
(defface subscript
'((t :height tex-suscript-height)) ;; :raise -0.2
"Face used for subscripts."
:group 'tex)
I will look into that next.
Thanks,
Mirko
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: displaying subscripts and superscripts
2010-04-19 23:29 ` Glenn Morris
@ 2010-04-21 18:18 ` Stefan Monnier
0 siblings, 0 replies; 5+ messages in thread
From: Stefan Monnier @ 2010-04-21 18:18 UTC (permalink / raw)
To: help-gnu-emacs
>>> (defun suscript-height (height)
>> [...]
>>> (defface superscript
>>> '((t :height suscript-height))
>>> "Face used for superscripts.")
>> The :height attribute cannot be a function.
> Err, tex-mode.el uses a function for :height, and it seems to work...
> The elisp manual says :height can be a function.
Huh!? Indeed!
Stefan "This tex-suscript-height is really overkill, BTW"
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2010-04-21 18:18 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-04-18 22:31 displaying subscripts and superscripts Mirko
2010-04-19 3:19 ` Stefan Monnier
2010-04-19 23:29 ` Glenn Morris
2010-04-21 18:18 ` Stefan Monnier
2010-04-20 0:14 ` Mirko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).