* prettify-symbols-mode to handle "\alpha-\beta" ...
@ 2021-02-04 1:24 pietru
2021-02-04 2:08 ` Óscar Fuentes
` (2 more replies)
0 siblings, 3 replies; 36+ messages in thread
From: pietru @ 2021-02-04 1:24 UTC (permalink / raw)
To: emacs-devel
I am using prettify-symbols-mode for displaying greek command using
the corresponding greek glyph when using mathematical expressions
in texinfo.
Here is an example
(push '("\\alpha" . ?α) prettify-symbols-alist)
(push '("\\beta" . ?β) prettify-symbols-alist)
This works well when using "\alpha\beta", "\alpha - \beta"
But the expression fails when using "\alpha-\beta" or
"\alpha_i", "\alpha_{ij}", "\beta^i", "\beta+\alpha".
The expressions are all valid mathematical expressions
when using tex.
Would you be so kind to update "prettify-symbols-mode"
so the substitutions can become possible to handle.
Does this require that SYMBOL in (SYMBOL . CHARACTER) be
a regexp?
Regards
Pietru
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: prettify-symbols-mode to handle "\alpha-\beta" ...
2021-02-04 1:24 prettify-symbols-mode to handle "\alpha-\beta" pietru
@ 2021-02-04 2:08 ` Óscar Fuentes
2021-02-04 3:03 ` pietru
2021-02-04 3:46 ` Ihor Radchenko
2021-02-04 8:44 ` tomas
2 siblings, 1 reply; 36+ messages in thread
From: Óscar Fuentes @ 2021-02-04 2:08 UTC (permalink / raw)
To: emacs-devel
pietru@caramail.com writes:
> I am using prettify-symbols-mode for displaying greek command using
> the corresponding greek glyph when using mathematical expressions
> in texinfo.
>
> Here is an example
>
> (push '("\\alpha" . ?α) prettify-symbols-alist)
> (push '("\\beta" . ?β) prettify-symbols-alist)
>
> This works well when using "\alpha\beta", "\alpha - \beta"
> But the expression fails when using "\alpha-\beta" or
> "\alpha_i", "\alpha_{ij}", "\beta^i", "\beta+\alpha".
> The expressions are all valid mathematical expressions
> when using tex.
>
> Would you be so kind to update "prettify-symbols-mode"
> so the substitutions can become possible to handle.
>
> Does this require that SYMBOL in (SYMBOL . CHARACTER) be
> a regexp?
The docstring of prettify-symbols-alist says:
Each element looks like (SYMBOL . CHARACTER), where the symbol
matching SYMBOL (a string, not a regexp) will be shown as CHARACTER
instead.
so no, SYMBOL *must* *not* be a regexp.
I can't reproduce the problem you are describing. After starting Emacs:
emacs -Q
if I evaluate this in *scratch*:
(push '("\\alpha" . ?α) prettify-symbols-alist)
then open a .tex file, write \alpha_i, M-x prettify-symbols-alist, the
string is transformed to α_i.
Please note that the definition of SYMBOL depends on the major mode of
the buffer, so make sure that your current major mode is tex-mode.
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: prettify-symbols-mode to handle "\alpha-\beta" ...
2021-02-04 2:08 ` Óscar Fuentes
@ 2021-02-04 3:03 ` pietru
2021-02-04 3:39 ` Óscar Fuentes
0 siblings, 1 reply; 36+ messages in thread
From: pietru @ 2021-02-04 3:03 UTC (permalink / raw)
To: Óscar Fuentes; +Cc: emacs-devel
> Sent: Thursday, February 04, 2021 at 2:08 PM
> From: "Óscar Fuentes" <ofv@wanadoo.es>
> To: emacs-devel@gnu.org
> Subject: Re: prettify-symbols-mode to handle "\alpha-\beta" ...
>
> pietru@caramail.com writes:
>
> > I am using prettify-symbols-mode for displaying greek command using
> > the corresponding greek glyph when using mathematical expressions
> > in texinfo.
> >
> > Here is an example
> >
> > (push '("\\alpha" . ?α) prettify-symbols-alist)
> > (push '("\\beta" . ?β) prettify-symbols-alist)
> >
> > This works well when using "\alpha\beta", "\alpha - \beta"
> > But the expression fails when using "\alpha-\beta" or
> > "\alpha_i", "\alpha_{ij}", "\beta^i", "\beta+\alpha".
> > The expressions are all valid mathematical expressions
> > when using tex.
> >
> > Would you be so kind to update "prettify-symbols-mode"
> > so the substitutions can become possible to handle.
> >
> > Does this require that SYMBOL in (SYMBOL . CHARACTER) be
> > a regexp?
>
> The docstring of prettify-symbols-alist says:
>
> Each element looks like (SYMBOL . CHARACTER), where the symbol
> matching SYMBOL (a string, not a regexp) will be shown as CHARACTER
> instead.
>
> so no, SYMBOL *must* *not* be a regexp.
>
> I can't reproduce the problem you are describing. After starting Emacs:
>
> emacs -Q
>
> if I evaluate this in *scratch*:
>
> (push '("\\alpha" . ?α) prettify-symbols-alist)
>
> then open a .tex file, write \alpha_i, M-x prettify-symbols-alist, the
> string is transformed to α_i.
>
> Please note that the definition of SYMBOL depends on the major mode of
> the buffer, so make sure that your current major mode is tex-mode.
>
No, the major mode is texinfo-mode. Texinfo allows mathematics to be
displayed using the usual tex expressions. Could this functionality
be put for use in texinfo-mode?
>
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: prettify-symbols-mode to handle "\alpha-\beta" ...
2021-02-04 3:03 ` pietru
@ 2021-02-04 3:39 ` Óscar Fuentes
2021-02-04 3:46 ` Christopher Dimech
` (2 more replies)
0 siblings, 3 replies; 36+ messages in thread
From: Óscar Fuentes @ 2021-02-04 3:39 UTC (permalink / raw)
To: emacs-devel
pietru@caramail.com writes:
>> The docstring of prettify-symbols-alist says:
>>
>> Each element looks like (SYMBOL . CHARACTER), where the symbol
>> matching SYMBOL (a string, not a regexp) will be shown as CHARACTER
>> instead.
>>
>> so no, SYMBOL *must* *not* be a regexp.
>>
>> I can't reproduce the problem you are describing. After starting Emacs:
>>
>> emacs -Q
>>
>> if I evaluate this in *scratch*:
>>
>> (push '("\\alpha" . ?α) prettify-symbols-alist)
>>
>> then open a .tex file, write \alpha_i, M-x prettify-symbols-alist, the
>> string is transformed to α_i.
>>
>> Please note that the definition of SYMBOL depends on the major mode of
>> the buffer, so make sure that your current major mode is tex-mode.
>>
>
> No, the major mode is texinfo-mode. Texinfo allows mathematics to be
> displayed using the usual tex expressions. Could this functionality
> be put for use in texinfo-mode?
I missed the texinfo bit on your original message, sorry.
Supporting what you want would require either changing what texinfo
considers a symbol or changing prettify-symbols-mode to work on
something else instead of symbols.
Probably the easiest route for you is to derive a mode from texinfo-mode
that modifies the syntax table defined in texinfo.el to suit your needs
(see "Syntax Tables" in the Elisp manual).
If you insist on changing texinfo-mode itself, put those modifications
on the mode's syntax table and submit the change to the Emacs
maintainers, but my guess is that you will need to give pretty solid
reasons for the change to be accepted, and then wait a long time until
Emacs 28 is released and becomes widespread enough among your target
users.
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: prettify-symbols-mode to handle "\alpha-\beta" ...
2021-02-04 3:39 ` Óscar Fuentes
@ 2021-02-04 3:46 ` Christopher Dimech
2021-02-04 3:51 ` pietru
2021-02-04 4:04 ` Stefan Monnier
2 siblings, 0 replies; 36+ messages in thread
From: Christopher Dimech @ 2021-02-04 3:46 UTC (permalink / raw)
To: Óscar Fuentes; +Cc: emacs-devel
There could be a minor mode that one can use with texinfo-mode.
---------------------
Christopher Dimech
General Administrator - Naiad Informatics - GNU Project (Geocomputation)
- Geophysical Simulation
- Geological Subsurface Mapping
- Disaster Preparedness and Mitigation
- Natural Resource Exploration and Production
- Free Software Advocacy
> Sent: Thursday, February 04, 2021 at 3:39 PM
> From: "Óscar Fuentes" <ofv@wanadoo.es>
> To: emacs-devel@gnu.org
> Subject: Re: prettify-symbols-mode to handle "\alpha-\beta" ...
>
> pietru@caramail.com writes:
>
> >> The docstring of prettify-symbols-alist says:
> >>
> >> Each element looks like (SYMBOL . CHARACTER), where the symbol
> >> matching SYMBOL (a string, not a regexp) will be shown as CHARACTER
> >> instead.
> >>
> >> so no, SYMBOL *must* *not* be a regexp.
> >>
> >> I can't reproduce the problem you are describing. After starting Emacs:
> >>
> >> emacs -Q
> >>
> >> if I evaluate this in *scratch*:
> >>
> >> (push '("\\alpha" . ?α) prettify-symbols-alist)
> >>
> >> then open a .tex file, write \alpha_i, M-x prettify-symbols-alist, the
> >> string is transformed to α_i.
> >>
> >> Please note that the definition of SYMBOL depends on the major mode of
> >> the buffer, so make sure that your current major mode is tex-mode.
> >>
> >
> > No, the major mode is texinfo-mode. Texinfo allows mathematics to be
> > displayed using the usual tex expressions. Could this functionality
> > be put for use in texinfo-mode?
>
> I missed the texinfo bit on your original message, sorry.
>
> Supporting what you want would require either changing what texinfo
> considers a symbol or changing prettify-symbols-mode to work on
> something else instead of symbols.
>
> Probably the easiest route for you is to derive a mode from texinfo-mode
> that modifies the syntax table defined in texinfo.el to suit your needs
> (see "Syntax Tables" in the Elisp manual).
>
> If you insist on changing texinfo-mode itself, put those modifications
> on the mode's syntax table and submit the change to the Emacs
> maintainers, but my guess is that you will need to give pretty solid
> reasons for the change to be accepted, and then wait a long time until
> Emacs 28 is released and becomes widespread enough among your target
> users.
>
>
>
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: prettify-symbols-mode to handle "\alpha-\beta" ...
2021-02-04 3:39 ` Óscar Fuentes
2021-02-04 3:46 ` Christopher Dimech
@ 2021-02-04 3:51 ` pietru
2021-02-04 4:04 ` Stefan Monnier
2 siblings, 0 replies; 36+ messages in thread
From: pietru @ 2021-02-04 3:51 UTC (permalink / raw)
To: Óscar Fuentes; +Cc: emacs-devel
Recently texinfo has been improved to better handle the display
of mathematics. For instance, it now also uses mathjax where
one is able to scale the text. Traditionally texinfo did have some
support for mathematical expressions, but since last year the support
has been expanded considerably.
> Sent: Thursday, February 04, 2021 at 3:39 PM
> From: "Óscar Fuentes" <ofv@wanadoo.es>
> To: emacs-devel@gnu.org
> Subject: Re: prettify-symbols-mode to handle "\alpha-\beta" ...
>
> pietru@caramail.com writes:
>
> >> The docstring of prettify-symbols-alist says:
> >>
> >> Each element looks like (SYMBOL . CHARACTER), where the symbol
> >> matching SYMBOL (a string, not a regexp) will be shown as CHARACTER
> >> instead.
> >>
> >> so no, SYMBOL *must* *not* be a regexp.
> >>
> >> I can't reproduce the problem you are describing. After starting Emacs:
> >>
> >> emacs -Q
> >>
> >> if I evaluate this in *scratch*:
> >>
> >> (push '("\\alpha" . ?α) prettify-symbols-alist)
> >>
> >> then open a .tex file, write \alpha_i, M-x prettify-symbols-alist, the
> >> string is transformed to α_i.
> >>
> >> Please note that the definition of SYMBOL depends on the major mode of
> >> the buffer, so make sure that your current major mode is tex-mode.
> >>
> >
> > No, the major mode is texinfo-mode. Texinfo allows mathematics to be
> > displayed using the usual tex expressions. Could this functionality
> > be put for use in texinfo-mode?
>
> I missed the texinfo bit on your original message, sorry.
>
> Supporting what you want would require either changing what texinfo
> considers a symbol or changing prettify-symbols-mode to work on
> something else instead of symbols.
>
> Probably the easiest route for you is to derive a mode from texinfo-mode
> that modifies the syntax table defined in texinfo.el to suit your needs
> (see "Syntax Tables" in the Elisp manual).
>
> If you insist on changing texinfo-mode itself, put those modifications
> on the mode's syntax table and submit the change to the Emacs
> maintainers, but my guess is that you will need to give pretty solid
> reasons for the change to be accepted, and then wait a long time until
> Emacs 28 is released and becomes widespread enough among your target
> users.
>
>
>
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: prettify-symbols-mode to handle "\alpha-\beta" ...
2021-02-04 3:39 ` Óscar Fuentes
2021-02-04 3:46 ` Christopher Dimech
2021-02-04 3:51 ` pietru
@ 2021-02-04 4:04 ` Stefan Monnier
2021-02-04 4:21 ` Christopher Dimech
2 siblings, 1 reply; 36+ messages in thread
From: Stefan Monnier @ 2021-02-04 4:04 UTC (permalink / raw)
To: Óscar Fuentes; +Cc: emacs-devel
> Supporting what you want would require either changing what texinfo
> considers a symbol or changing prettify-symbols-mode to work on
> something else instead of symbols.
The second can be done without changing the code of
`prettify-symbols-mode`: you want to change
`prettify-symbols-compose-predicate` which contains the function that decides
whether a given occurrence should be prettified or not.
E.g. the default is the function `prettify-symbols-default-compose-p`
defined as follows:
(defun prettify-symbols-default-compose-p (start end _match)
"Return true iff the symbol MATCH should be composed.
The symbol starts at position START and ends at position END.
This is the default for `prettify-symbols-compose-predicate'
which is suitable for most programming languages such as C or Lisp."
;; Check that the chars should really be composed into a symbol.
(let* ((syntaxes-beg (if (memq (char-syntax (char-after start)) '(?w ?_))
'(?w ?_) '(?. ?\\)))
(syntaxes-end (if (memq (char-syntax (char-before end)) '(?w ?_))
'(?w ?_) '(?. ?\\))))
(not (or (memq (char-syntax (or (char-before start) ?\s)) syntaxes-beg)
(memq (char-syntax (or (char-after end) ?\s)) syntaxes-end)
(nth 8 (syntax-ppss))))))
You'd presumably want to then define your own such function which does
pretty much the same except that it doesn't accept the syntax `_`:
(defun texinf-prettify-symbols-compose-p (start end _match)
;; We know the matches all start with a backslash and end with
;; a word-element.
(not (or (memq (char-before start) '(?\\))
(memq (char-syntax (or (char-after end) ?\s)) '(?w))
(nth 8 (syntax-ppss)))))
-- Stefan
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: prettify-symbols-mode to handle "\alpha-\beta" ...
2021-02-04 4:04 ` Stefan Monnier
@ 2021-02-04 4:21 ` Christopher Dimech
2021-02-04 16:12 ` Stefan Monnier
0 siblings, 1 reply; 36+ messages in thread
From: Christopher Dimech @ 2021-02-04 4:21 UTC (permalink / raw)
To: Stefan Monnier; +Cc: Óscar Fuentes, emacs-devel
We should find the best way to do this rather than a hack
that is likely to be rejected by emacs-devel. pretty-symbols
is a good candidate for this because it is intended for use
with general programming modes. Texinfo has today evolved
like a programming language with its support for plain-tex
and commands for mathjax.
Whilst texinfo.el takes care of texinfo commands, it completely
disregards the use of tex constructs and the focus on displaying
mathematical expressions within texinfo.
---------------------
Christopher Dimech
General Administrator - Naiad Informatics - GNU Project (Geocomputation)
- Geophysical Simulation
- Geological Subsurface Mapping
- Disaster Preparedness and Mitigation
- Natural Resource Exploration and Production
- Free Software Advocacy
> Sent: Thursday, February 04, 2021 at 4:04 PM
> From: "Stefan Monnier" <monnier@iro.umontreal.ca>
> To: "Óscar Fuentes" <ofv@wanadoo.es>
> Cc: emacs-devel@gnu.org
> Subject: Re: prettify-symbols-mode to handle "\alpha-\beta" ...
>
> > Supporting what you want would require either changing what texinfo
> > considers a symbol or changing prettify-symbols-mode to work on
> > something else instead of symbols.
>
> The second can be done without changing the code of
> `prettify-symbols-mode`: you want to change
> `prettify-symbols-compose-predicate` which contains the function that decides
> whether a given occurrence should be prettified or not.
>
> E.g. the default is the function `prettify-symbols-default-compose-p`
> defined as follows:
>
> (defun prettify-symbols-default-compose-p (start end _match)
> "Return true iff the symbol MATCH should be composed.
> The symbol starts at position START and ends at position END.
> This is the default for `prettify-symbols-compose-predicate'
> which is suitable for most programming languages such as C or Lisp."
> ;; Check that the chars should really be composed into a symbol.
> (let* ((syntaxes-beg (if (memq (char-syntax (char-after start)) '(?w ?_))
> '(?w ?_) '(?. ?\\)))
> (syntaxes-end (if (memq (char-syntax (char-before end)) '(?w ?_))
> '(?w ?_) '(?. ?\\))))
> (not (or (memq (char-syntax (or (char-before start) ?\s)) syntaxes-beg)
> (memq (char-syntax (or (char-after end) ?\s)) syntaxes-end)
> (nth 8 (syntax-ppss))))))
>
> You'd presumably want to then define your own such function which does
> pretty much the same except that it doesn't accept the syntax `_`:
>
> (defun texinf-prettify-symbols-compose-p (start end _match)
> ;; We know the matches all start with a backslash and end with
> ;; a word-element.
> (not (or (memq (char-before start) '(?\\))
> (memq (char-syntax (or (char-after end) ?\s)) '(?w))
> (nth 8 (syntax-ppss)))))
>
>
> -- Stefan
>
>
>
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: prettify-symbols-mode to handle "\alpha-\beta" ...
2021-02-04 4:21 ` Christopher Dimech
@ 2021-02-04 16:12 ` Stefan Monnier
2021-02-04 18:09 ` Christopher Dimech
2021-02-04 18:15 ` Christopher Dimech
0 siblings, 2 replies; 36+ messages in thread
From: Stefan Monnier @ 2021-02-04 16:12 UTC (permalink / raw)
To: Christopher Dimech; +Cc: Óscar Fuentes, emacs-devel
> We should find the best way to do this rather than a hack
> that is likely to be rejected by emacs-devel.
I don't know what hack you're referring to.
> Whilst texinfo.el takes care of texinfo commands, it completely
> disregards the use of tex constructs and the focus on displaying
> mathematical expressions within texinfo.
`texinfo.el` deserves some extra love, yes.
I don't think anyone has contributed to it in the last several years :-(
Stefan
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: prettify-symbols-mode to handle "\alpha-\beta" ...
2021-02-04 16:12 ` Stefan Monnier
@ 2021-02-04 18:09 ` Christopher Dimech
2021-02-04 18:21 ` Stefan Monnier
2021-02-04 18:15 ` Christopher Dimech
1 sibling, 1 reply; 36+ messages in thread
From: Christopher Dimech @ 2021-02-04 18:09 UTC (permalink / raw)
To: Stefan Monnier; +Cc: Óscar Fuentes, emacs-devel
> Sent: Friday, February 05, 2021 at 4:12 AM
> From: "Stefan Monnier" <monnier@iro.umontreal.ca>
> To: "Christopher Dimech" <dimech@gmx.com>
> Cc: "Óscar Fuentes" <ofv@wanadoo.es>, emacs-devel@gnu.org
> Subject: Re: prettify-symbols-mode to handle "\alpha-\beta" ...
>
> > We should find the best way to do this rather than a hack
> > that is likely to be rejected by emacs-devel.
>
> I don't know what hack you're referring to.
Because I saw a few different implementations of prettify
in various files and packages all trying to do the same
kind of thing.
> > Whilst texinfo.el takes care of texinfo commands, it completely
> > disregards the use of tex constructs and the focus on displaying
> > mathematical expressions within texinfo.
>
> `texinfo.el` deserves some extra love, yes.
> I don't think anyone has contributed to it in the last several years :-(
Óscar Fuentes, I think wrote that if I insist on changing texinfo-mode
itself would require me to to give a very solid reason for the change
to be accepted.
As you recognise that it deserves additional work, my reason should be
solid enough.
> Stefan
>
>
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: prettify-symbols-mode to handle "\alpha-\beta" ...
2021-02-04 18:09 ` Christopher Dimech
@ 2021-02-04 18:21 ` Stefan Monnier
2021-02-04 20:14 ` Christopher Dimech
0 siblings, 1 reply; 36+ messages in thread
From: Stefan Monnier @ 2021-02-04 18:21 UTC (permalink / raw)
To: Christopher Dimech; +Cc: Óscar Fuentes, emacs-devel
>> I don't know what hack you're referring to.
> Because I saw a few different implementations of prettify
> in various files and packages all trying to do the same
> kind of thing.
It's still a bit vague.
>> > Whilst texinfo.el takes care of texinfo commands, it completely
>> > disregards the use of tex constructs and the focus on displaying
>> > mathematical expressions within texinfo.
>> `texinfo.el` deserves some extra love, yes.
>> I don't think anyone has contributed to it in the last several years :-(
> Óscar Fuentes, I think wrote that if I insist on changing texinfo-mode
> itself would require me to to give a very solid reason for the change
> to be accepted.
> As you recognise that it deserves additional work, my reason should be
> solid enough.
Changing the buffer's syntax table just for `prettify-symbols-mode`
would likely encounter resistance (since it's likely to introduce
regression in other parts of the code), but if it comes with
corresponding updates elsewhere to accommodate that change (and those
changes don't make the code worse), then it might be acceptable.
Of course, as I pointed out, it's not necessary to change the buffer's
syntax table just for the immediate needs of \alpha and \beta in
`prettify-symbols-mode`. But in order to accommodate more TeX-style
code it might indeed be a good idea (or not: I can't say without
spending more time investigating the issue).
Stefan
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: prettify-symbols-mode to handle "\alpha-\beta" ...
2021-02-04 18:21 ` Stefan Monnier
@ 2021-02-04 20:14 ` Christopher Dimech
0 siblings, 0 replies; 36+ messages in thread
From: Christopher Dimech @ 2021-02-04 20:14 UTC (permalink / raw)
To: Stefan Monnier; +Cc: Óscar Fuentes, emacs-devel
> Sent: Friday, February 05, 2021 at 6:21 AM
> From: "Stefan Monnier" <monnier@iro.umontreal.ca>
> To: "Christopher Dimech" <dimech@gmx.com>
> Cc: "Óscar Fuentes" <ofv@wanadoo.es>, emacs-devel@gnu.org
> Subject: Re: prettify-symbols-mode to handle "\alpha-\beta" ...
>
> >> I don't know what hack you're referring to.
> > Because I saw a few different implementations of prettify
> > in various files and packages all trying to do the same
> > kind of thing.
>
> It's still a bit vague.
>
> >> > Whilst texinfo.el takes care of texinfo commands, it completely
> >> > disregards the use of tex constructs and the focus on displaying
> >> > mathematical expressions within texinfo.
> >> `texinfo.el` deserves some extra love, yes.
> >> I don't think anyone has contributed to it in the last several years :-(
> > Óscar Fuentes, I think wrote that if I insist on changing texinfo-mode
> > itself would require me to to give a very solid reason for the change
> > to be accepted.
> > As you recognise that it deserves additional work, my reason should be
> > solid enough.
>
> Changing the buffer's syntax table just for `prettify-symbols-mode`
> would likely encounter resistance (since it's likely to introduce
> regression in other parts of the code), but if it comes with
> corresponding updates elsewhere to accommodate that change (and those
> changes don't make the code worse), then it might be acceptable.
>
> Of course, as I pointed out, it's not necessary to change the buffer's
> syntax table just for the immediate needs of \alpha and \beta in
> `prettify-symbols-mode`. But in order to accommodate more TeX-style
> code it might indeed be a good idea (or not: I can't say without
> spending more time investigating the issue).
Sure, it must support a generalised scheme that can tackle the variety
of languages and what could be done with each. prog-mode.tex already
seems to be intended as a general framework to support a variety of
languages. texinfo.el can then call prog-mode.tex framework for
support with general prettify functionality.
> Stefan
>
>
>
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: prettify-symbols-mode to handle "\alpha-\beta" ...
2021-02-04 16:12 ` Stefan Monnier
2021-02-04 18:09 ` Christopher Dimech
@ 2021-02-04 18:15 ` Christopher Dimech
2021-02-04 18:23 ` Stefan Monnier
1 sibling, 1 reply; 36+ messages in thread
From: Christopher Dimech @ 2021-02-04 18:15 UTC (permalink / raw)
To: Stefan Monnier; +Cc: Óscar Fuentes, emacs-devel
> Sent: Friday, February 05, 2021 at 4:12 AM
> From: "Stefan Monnier" <monnier@iro.umontreal.ca>
> To: "Christopher Dimech" <dimech@gmx.com>
> Cc: "Óscar Fuentes" <ofv@wanadoo.es>, emacs-devel@gnu.org
> Subject: Re: prettify-symbols-mode to handle "\alpha-\beta" ...
>
> > We should find the best way to do this rather than a hack
> > that is likely to be rejected by emacs-devel.
>
> I don't know what hack you're referring to.
The way I see it, is that the improvement should be put in
prog-mode.el, and then the other major modes can rely on
prog-mode.el fon a minor mode that implements the prettify
functionality.
We need to get to some degree of agreement, as I
do not wish that people end up doing work of no
value to emacs.
> > Whilst texinfo.el takes care of texinfo commands, it completely
> > disregards the use of tex constructs and the focus on displaying
> > mathematical expressions within texinfo.
>
> `texinfo.el` deserves some extra love, yes.
> I don't think anyone has contributed to it in the last several years :-(
>
>
> Stefan
>
>
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: prettify-symbols-mode to handle "\alpha-\beta" ...
2021-02-04 18:15 ` Christopher Dimech
@ 2021-02-04 18:23 ` Stefan Monnier
2021-02-04 20:22 ` Christopher Dimech
2021-02-04 20:34 ` Christopher Dimech
0 siblings, 2 replies; 36+ messages in thread
From: Stefan Monnier @ 2021-02-04 18:23 UTC (permalink / raw)
To: Christopher Dimech; +Cc: Óscar Fuentes, emacs-devel
> The way I see it, is that the improvement should be put in
> prog-mode.el,
What is "the" improvement you're referring to?
> and then the other major modes can rely on prog-mode.el fon a minor
> mode that implements the prettify functionality.
I think that's the case already, thanks to `prettify-symbols-mode`.
I'm not saying it can't be improved, of course,
Stefan
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: prettify-symbols-mode to handle "\alpha-\beta" ...
2021-02-04 18:23 ` Stefan Monnier
@ 2021-02-04 20:22 ` Christopher Dimech
2021-02-04 20:38 ` Stefan Monnier
2021-02-04 20:34 ` Christopher Dimech
1 sibling, 1 reply; 36+ messages in thread
From: Christopher Dimech @ 2021-02-04 20:22 UTC (permalink / raw)
To: Stefan Monnier; +Cc: Óscar Fuentes, emacs-devel
> Sent: Friday, February 05, 2021 at 6:23 AM
> From: "Stefan Monnier" <monnier@iro.umontreal.ca>
> To: "Christopher Dimech" <dimech@gmx.com>
> Cc: "Óscar Fuentes" <ofv@wanadoo.es>, emacs-devel@gnu.org
> Subject: Re: prettify-symbols-mode to handle "\alpha-\beta" ...
>
> > The way I see it, is that the improvement should be put in
> > prog-mode.el,
>
> What is "the" improvement you're referring to?
Improvement for prog-mode.el to be able to handle the prettifying
the tex commands as well. Prettify greek letters and math symbols,
Binary operations and other relations, and arrows.
> > and then the other major modes can rely on prog-mode.el fon a minor
> > mode that implements the prettify functionality.
>
> I think that's the case already, thanks to `prettify-symbols-mode`.
> I'm not saying it can't be improved, of course,
>
>
> Stefan
>
>
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: prettify-symbols-mode to handle "\alpha-\beta" ...
2021-02-04 20:22 ` Christopher Dimech
@ 2021-02-04 20:38 ` Stefan Monnier
2021-02-04 20:54 ` Christopher Dimech
2021-02-05 20:32 ` pietru
0 siblings, 2 replies; 36+ messages in thread
From: Stefan Monnier @ 2021-02-04 20:38 UTC (permalink / raw)
To: Christopher Dimech; +Cc: Óscar Fuentes, emacs-devel
>> What is "the" improvement you're referring to?
> Improvement for prog-mode.el to be able to handle the prettifying
> the tex commands as well. Prettify greek letters and math symbols,
> Binary operations and other relations, and arrows.
prog-mode.el shouldn't try to prettify TeX commands, but yes, it should
provide the means to do it. AFAICT what it provides is already
sufficient to prettify any of TeX's symbols. It might fall short when
you try to prettify other things like \frac, negative space,
superscript, ...
Stefan
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: prettify-symbols-mode to handle "\alpha-\beta" ...
2021-02-04 20:38 ` Stefan Monnier
@ 2021-02-04 20:54 ` Christopher Dimech
2021-02-05 20:32 ` pietru
1 sibling, 0 replies; 36+ messages in thread
From: Christopher Dimech @ 2021-02-04 20:54 UTC (permalink / raw)
To: Stefan Monnier; +Cc: Óscar Fuentes, emacs-devel
> Sent: Friday, February 05, 2021 at 8:38 AM
> From: "Stefan Monnier" <monnier@iro.umontreal.ca>
> To: "Christopher Dimech" <dimech@gmx.com>
> Cc: "Óscar Fuentes" <ofv@wanadoo.es>, emacs-devel@gnu.org
> Subject: Re: prettify-symbols-mode to handle "\alpha-\beta" ...
>
> >> What is "the" improvement you're referring to?
> > Improvement for prog-mode.el to be able to handle the prettifying
> > the tex commands as well. Prettify greek letters and math symbols,
> > Binary operations and other relations, and arrows.
>
> prog-mode.el shouldn't try to prettify TeX commands, but yes, it should
> provide the means to do it. AFAICT what it provides is already
> sufficient to prettify any of TeX's symbols. It might fall short when
> you try to prettify other things like \frac, negative space,
> superscript, ...
Correct, it should provide the framework to support the keyword operations
and how they are prettified. But prettify can be made dependent on language.
And pointed out, for tex, prettify falls short in some aspects. The improvement
would be for prettify to handle them. Superscript and subscripts can be handled.
Originally, TeX's symbols were considered the same way as programming language.
But that assumption is not completely correct because the construction
of mathematical expressions differs in important ways from standard programming
syntax.
Could make a minor mode for texinfo to set things up using functionality
from prog-mode.el. The minor mode could also handle superscripts and
subscripts.
> Stefan
>
>
>
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: prettify-symbols-mode to handle "\alpha-\beta" ...
2021-02-04 20:38 ` Stefan Monnier
2021-02-04 20:54 ` Christopher Dimech
@ 2021-02-05 20:32 ` pietru
2021-02-05 21:01 ` Stefan Monnier
2021-02-05 22:09 ` Gregory Heytings
1 sibling, 2 replies; 36+ messages in thread
From: pietru @ 2021-02-05 20:32 UTC (permalink / raw)
To: Stefan Monnier; +Cc: Óscar Fuentes, emacs-devel
Would allowing a regexp solve the expression \alpha-\beta,
\alpha+\beta, \alpha/\beta, so that \alpha and \beta are
prettified seperately?
> Sent: Friday, February 05, 2021 at 8:38 AM
> From: "Stefan Monnier" <monnier@iro.umontreal.ca>
> To: "Christopher Dimech" <dimech@gmx.com>
> Cc: "Óscar Fuentes" <ofv@wanadoo.es>, emacs-devel@gnu.org
> Subject: Re: prettify-symbols-mode to handle "\alpha-\beta" ...
>
> >> What is "the" improvement you're referring to?
> > Improvement for prog-mode.el to be able to handle the prettifying
> > the tex commands as well. Prettify greek letters and math symbols,
> > Binary operations and other relations, and arrows.
>
> prog-mode.el shouldn't try to prettify TeX commands, but yes, it should
> provide the means to do it. AFAICT what it provides is already
> sufficient to prettify any of TeX's symbols. It might fall short when
> you try to prettify other things like \frac, negative space,
> superscript, ...
>
>
> Stefan
>
>
>
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: prettify-symbols-mode to handle "\alpha-\beta" ...
2021-02-05 20:32 ` pietru
@ 2021-02-05 21:01 ` Stefan Monnier
2021-02-05 21:05 ` Christopher Dimech
2021-02-05 22:09 ` Gregory Heytings
1 sibling, 1 reply; 36+ messages in thread
From: Stefan Monnier @ 2021-02-05 21:01 UTC (permalink / raw)
To: pietru; +Cc: Óscar Fuentes, emacs-devel
> Would allowing a regexp solve the expression \alpha-\beta,
> \alpha+\beta, \alpha/\beta, so that \alpha and \beta are
> prettified seperately?
I don't see how a regexp would help in those cases.
Stefan
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: prettify-symbols-mode to handle "\alpha-\beta" ...
2021-02-05 21:01 ` Stefan Monnier
@ 2021-02-05 21:05 ` Christopher Dimech
2021-02-05 21:54 ` Christopher Dimech
2021-02-05 21:57 ` Stefan Monnier
0 siblings, 2 replies; 36+ messages in thread
From: Christopher Dimech @ 2021-02-05 21:05 UTC (permalink / raw)
To: Stefan Monnier; +Cc: Óscar Fuentes, emacs-devel
> Sent: Saturday, February 06, 2021 at 9:01 AM
> From: "Stefan Monnier" <monnier@iro.umontreal.ca>
> To: pietru@caramail.com
> Cc: "Óscar Fuentes" <ofv@wanadoo.es>, emacs-devel@gnu.org
> Subject: Re: prettify-symbols-mode to handle "\alpha-\beta" ...
>
> > Would allowing a regexp solve the expression \alpha-\beta,
> > \alpha+\beta, \alpha/\beta, so that \alpha and \beta are
> > prettified seperately?
>
> I don't see how a regexp would help in those cases.
We could somehow employ 'split-string', which will target hyphens (or
whatever regexp of separators) and split every occurence of a composite
as two separate strings which can then be checked separately for
equality against alist.
> Stefan
>
>
>
---------------------
Christopher Dimech
General Administrator - Naiad Informatics - GNU Project (Geocomputation)
- Geophysical Simulation
- Geological Subsurface Mapping
- Disaster Preparedness and Mitigation
- Natural Resource Exploration and Production
- Free Software Advocacy
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: prettify-symbols-mode to handle "\alpha-\beta" ...
2021-02-05 21:05 ` Christopher Dimech
@ 2021-02-05 21:54 ` Christopher Dimech
2021-02-05 21:57 ` Stefan Monnier
1 sibling, 0 replies; 36+ messages in thread
From: Christopher Dimech @ 2021-02-05 21:54 UTC (permalink / raw)
To: Christopher Dimech; +Cc: Óscar Fuentes, Stefan Monnier, emacs-devel
> Sent: Saturday, February 06, 2021 at 9:05 AM
> From: "Christopher Dimech" <dimech@gmx.com>
> To: "Stefan Monnier" <monnier@iro.umontreal.ca>
> Cc: "Óscar Fuentes" <ofv@wanadoo.es>, emacs-devel@gnu.org
> Subject: Re: prettify-symbols-mode to handle "\alpha-\beta" ...
>
> > Sent: Saturday, February 06, 2021 at 9:01 AM
> > From: "Stefan Monnier" <monnier@iro.umontreal.ca>
> > To: pietru@caramail.com
> > Cc: "Óscar Fuentes" <ofv@wanadoo.es>, emacs-devel@gnu.org
> > Subject: Re: prettify-symbols-mode to handle "\alpha-\beta" ...
> >
> > > Would allowing a regexp solve the expression \alpha-\beta,
> > > \alpha+\beta, \alpha/\beta, so that \alpha and \beta are
> > > prettified seperately?
> >
> > I don't see how a regexp would help in those cases.
>
> We could somehow employ 'split-string', which will target hyphens (or
> whatever regexp of separators) and split every occurence of a composite
> as two separate strings which can then be checked separately for
> equality against alist.
Perhaps the predicate function could somehow employ 'split-string', which
will target hyphens (or whatever regexp of separators) and split every
occurence of a composite as two separate strings which can then be checked
separately for equality against the alist.
(split-string "\\alpha-\\beta" "-")
=> ("\\alpha" "\\beta")
Still, do people think that that prog-mode should also work with regexp
and what would the benefits be.
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: prettify-symbols-mode to handle "\alpha-\beta" ...
2021-02-05 21:05 ` Christopher Dimech
2021-02-05 21:54 ` Christopher Dimech
@ 2021-02-05 21:57 ` Stefan Monnier
1 sibling, 0 replies; 36+ messages in thread
From: Stefan Monnier @ 2021-02-05 21:57 UTC (permalink / raw)
To: Christopher Dimech; +Cc: Óscar Fuentes, emacs-devel
>> > Would allowing a regexp solve the expression \alpha-\beta,
>> > \alpha+\beta, \alpha/\beta, so that \alpha and \beta are
>> > prettified seperately?
>> I don't see how a regexp would help in those cases.
> We could somehow employ 'split-string', which will target hyphens (or
> whatever regexp of separators) and split every occurence of a composite
> as two separate strings which can then be checked separately for
> equality against alist.
It seems more complex and less efficient than the current solution
(which uses the non-regexp alist directly and then checks the context
using the predicate function to see if it's a valid occurrence).
I've been tempted to add support for regexps many times, but so far
I haven't found a use case for them ;-)
I suspect that they'll only make sense when we try to move further than
just "replace occurrences of this identifier with that character".
Stefan
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: prettify-symbols-mode to handle "\alpha-\beta" ...
2021-02-05 20:32 ` pietru
2021-02-05 21:01 ` Stefan Monnier
@ 2021-02-05 22:09 ` Gregory Heytings
2021-02-05 22:22 ` pietru
1 sibling, 1 reply; 36+ messages in thread
From: Gregory Heytings @ 2021-02-05 22:09 UTC (permalink / raw)
To: pietru; +Cc: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 850 bytes --]
>
> Would allowing a regexp solve the expression \alpha-\beta, \alpha+\beta,
> \alpha/\beta, so that \alpha and \beta are prettified seperately?
>
That's not necessary. Just follow Stefan's advice:
(defun texinfo-prettify-symbols-compose-p (start end _match)
;; We know the matches all start with a backslash and end with
;; a word-element.
(not (or (memq (char-before start) '(?\\))
(memq (char-syntax (or (char-after end) ?\s)) '(?w))
(nth 8 (syntax-ppss)))))
(add-hook 'texinfo-mode-hook
(lambda ()
(push '("\\alpha" . ?α) prettify-symbols-alist)
(push '("\\beta" . ?β) prettify-symbols-alist)
(setq prettify-symbols-compose-predicate 'texinfo-prettify-symbols-compose-p)
(prettify-symbols-mode)))
This does what you want.
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: prettify-symbols-mode to handle "\alpha-\beta" ...
2021-02-05 22:09 ` Gregory Heytings
@ 2021-02-05 22:22 ` pietru
2021-02-05 22:45 ` Gregory Heytings
0 siblings, 1 reply; 36+ messages in thread
From: pietru @ 2021-02-05 22:22 UTC (permalink / raw)
To: Gregory Heytings; +Cc: emacs-devel
> Sent: Saturday, February 06, 2021 at 10:09 AM
> From: "Gregory Heytings" <gregory@heytings.org>
> To: pietru@caramail.com
> Cc: emacs-devel@gnu.org
> Subject: Re: prettify-symbols-mode to handle "\alpha-\beta" ...
>
>
> >
> > Would allowing a regexp solve the expression \alpha-\beta, \alpha+\beta,
> > \alpha/\beta, so that \alpha and \beta are prettified seperately?
> >
>
> That's not necessary. Just follow Stefan's advice:
>
> (defun texinfo-prettify-symbols-compose-p (start end _match)
> ;; We know the matches all start with a backslash and end with
> ;; a word-element.
> (not (or (memq (char-before start) '(?\\))
> (memq (char-syntax (or (char-after end) ?\s)) '(?w))
> (nth 8 (syntax-ppss)))))
> (add-hook 'texinfo-mode-hook
> (lambda ()
> (push '("\\alpha" . ?α) prettify-symbols-alist)
> (push '("\\beta" . ?β) prettify-symbols-alist)
> (setq prettify-symbols-compose-predicate 'texinfo-prettify-symbols-compose-p)
> (prettify-symbols-mode)))
>
> This does what you want.
That is not completely correct because for "\alpha-\beta", only \beta is prettified.
However, \alpha, \alpha. \alpha() \alpha[] work well with \alpha being prettifyied
even though the next character is a comma, period and parenthesis.
To cater for prettifying tex, we could have another function where one can construct
the prettify.
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: prettify-symbols-mode to handle "\alpha-\beta" ...
2021-02-05 22:22 ` pietru
@ 2021-02-05 22:45 ` Gregory Heytings
2021-02-05 22:56 ` pietru
0 siblings, 1 reply; 36+ messages in thread
From: Gregory Heytings @ 2021-02-05 22:45 UTC (permalink / raw)
To: pietru; +Cc: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 1085 bytes --]
>>> Would allowing a regexp solve the expression \alpha-\beta,
>>> \alpha+\beta, \alpha/\beta, so that \alpha and \beta are prettified
>>> seperately?
>>
>> That's not necessary. Just follow Stefan's advice:
>>
>> (defun texinfo-prettify-symbols-compose-p (start end _match)
>> ;; We know the matches all start with a backslash and end with
>> ;; a word-element.
>> (not (or (memq (char-before start) '(?\\))
>> (memq (char-syntax (or (char-after end) ?\s)) '(?w))
>> (nth 8 (syntax-ppss)))))
>> (add-hook 'texinfo-mode-hook
>> (lambda ()
>> (push '("\\alpha" . ?α) prettify-symbols-alist)
>> (push '("\\beta" . ?β) prettify-symbols-alist)
>> (setq prettify-symbols-compose-predicate 'texinfo-prettify-symbols-compose-p)
>> (prettify-symbols-mode)))
>>
>> This does what you want.
>
> That is not completely correct because for "\alpha-\beta", only \beta is
> prettified.
>
No, \alpha-\beta is prettified correctly. Tested with Emacs 25, 26, 27
and 28.
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: prettify-symbols-mode to handle "\alpha-\beta" ...
2021-02-05 22:45 ` Gregory Heytings
@ 2021-02-05 22:56 ` pietru
2021-02-05 23:04 ` Gregory Heytings
0 siblings, 1 reply; 36+ messages in thread
From: pietru @ 2021-02-05 22:56 UTC (permalink / raw)
To: Gregory Heytings; +Cc: emacs-devel
> Sent: Saturday, February 06, 2021 at 10:45 AM
> From: "Gregory Heytings" <gregory@heytings.org>
> To: pietru@caramail.com
> Cc: emacs-devel@gnu.org
> Subject: Re: prettify-symbols-mode to handle "\alpha-\beta" ...
>
>
> >>> Would allowing a regexp solve the expression \alpha-\beta,
> >>> \alpha+\beta, \alpha/\beta, so that \alpha and \beta are prettified
> >>> seperately?
> >>
> >> That's not necessary. Just follow Stefan's advice:
> >>
> >> (defun texinfo-prettify-symbols-compose-p (start end _match)
> >> ;; We know the matches all start with a backslash and end with
> >> ;; a word-element.
> >> (not (or (memq (char-before start) '(?\\))
> >> (memq (char-syntax (or (char-after end) ?\s)) '(?w))
> >> (nth 8 (syntax-ppss)))))
> >> (add-hook 'texinfo-mode-hook
> >> (lambda ()
> >> (push '("\\alpha" . ?α) prettify-symbols-alist)
> >> (push '("\\beta" . ?β) prettify-symbols-alist)
> >> (setq prettify-symbols-compose-predicate 'texinfo-prettify-symbols-compose-p)
> >> (prettify-symbols-mode)))
> >>
> >> This does what you want.
> >
> > That is not completely correct because for "\alpha-\beta", only \beta is
> > prettified.
> >
>
> No, \alpha-\beta is prettified correctly. Tested with Emacs 25, 26, 27
> and 28.
Have tried it in a texinfo document using
@tex
$\alpha -\beta \gamma \alpha - \beta \gamma \alpha, \alpha. \alpha- \alpha() \alpha[]$
@end tex
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: prettify-symbols-mode to handle "\alpha-\beta" ...
2021-02-05 22:56 ` pietru
@ 2021-02-05 23:04 ` Gregory Heytings
2021-02-05 23:15 ` pietru
0 siblings, 1 reply; 36+ messages in thread
From: Gregory Heytings @ 2021-02-05 23:04 UTC (permalink / raw)
To: pietru; +Cc: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 1116 bytes --]
>>>> (defun texinfo-prettify-symbols-compose-p (start end _match)
>>>> ;; We know the matches all start with a backslash and end with
>>>> ;; a word-element.
>>>> (not (or (memq (char-before start) '(?\\))
>>>> (memq (char-syntax (or (char-after end) ?\s)) '(?w))
>>>> (nth 8 (syntax-ppss)))))
>>>> (add-hook 'texinfo-mode-hook
>>>> (lambda ()
>>>> (push '("\\alpha" . ?α) prettify-symbols-alist)
>>>> (push '("\\beta" . ?β) prettify-symbols-alist)
>>>> (setq prettify-symbols-compose-predicate 'texinfo-prettify-symbols-compose-p)
>>>> (prettify-symbols-mode)))
>>>
>>> That is not completely correct because for "\alpha-\beta", only \beta
>>> is prettified.
>>
>> No, \alpha-\beta is prettified correctly. Tested with Emacs 25, 26, 27
>> and 28.
>
> Have tried it in a texinfo document using
>
> @tex
> $\alpha -\beta \gamma \alpha - \beta \gamma \alpha, \alpha. \alpha- \alpha() \alpha[]$
> @end tex
>
This works correctly with vanilla Emacs, with the "defun" and "add-hook"
above.
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: prettify-symbols-mode to handle "\alpha-\beta" ...
2021-02-05 23:04 ` Gregory Heytings
@ 2021-02-05 23:15 ` pietru
2021-02-05 23:22 ` Gregory Heytings
0 siblings, 1 reply; 36+ messages in thread
From: pietru @ 2021-02-05 23:15 UTC (permalink / raw)
To: Gregory Heytings; +Cc: emacs-devel
> Sent: Saturday, February 06, 2021 at 11:04 AM
> From: "Gregory Heytings" <gregory@heytings.org>
> To: pietru@caramail.com
> Cc: emacs-devel@gnu.org
> Subject: Re: prettify-symbols-mode to handle "\alpha-\beta" ...
>
>
> >>>> (defun texinfo-prettify-symbols-compose-p (start end _match)
> >>>> ;; We know the matches all start with a backslash and end with
> >>>> ;; a word-element.
> >>>> (not (or (memq (char-before start) '(?\\))
> >>>> (memq (char-syntax (or (char-after end) ?\s)) '(?w))
> >>>> (nth 8 (syntax-ppss)))))
> >>>> (add-hook 'texinfo-mode-hook
> >>>> (lambda ()
> >>>> (push '("\\alpha" . ?α) prettify-symbols-alist)
> >>>> (push '("\\beta" . ?β) prettify-symbols-alist)
> >>>> (setq prettify-symbols-compose-predicate 'texinfo-prettify-symbols-compose-p)
> >>>> (prettify-symbols-mode)))
> >>>
> >>> That is not completely correct because for "\alpha-\beta", only \beta
> >>> is prettified.
> >>
> >> No, \alpha-\beta is prettified correctly. Tested with Emacs 25, 26, 27
> >> and 28.
> >
> > Have tried it in a texinfo document using
> >
> > @tex
> > $\alpha -\beta \gamma \alpha - \beta \gamma \alpha, \alpha. \alpha- \alpha() \alpha[]$
> > @end tex
> >
>
> This works correctly with vanilla Emacs, with the "defun" and "add-hook"
> above.
So I have to add the following defun in prog-mode.el?
(defun texinfo-prettify-symbols-compose-p (start end _match)
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: prettify-symbols-mode to handle "\alpha-\beta" ...
2021-02-05 23:15 ` pietru
@ 2021-02-05 23:22 ` Gregory Heytings
2021-02-05 23:43 ` Christopher Dimech
` (2 more replies)
0 siblings, 3 replies; 36+ messages in thread
From: Gregory Heytings @ 2021-02-05 23:22 UTC (permalink / raw)
To: pietru; +Cc: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 1161 bytes --]
>> (defun texinfo-prettify-symbols-compose-p (start end _match)
>> ;; We know the matches all start with a backslash and end with
>> ;; a word-element.
>> (not (or (memq (char-before start) '(?\\))
>> (memq (char-syntax (or (char-after end) ?\s)) '(?w))
>> (nth 8 (syntax-ppss)))))
>> (add-hook 'texinfo-mode-hook
>> (lambda ()
>> (push '("\\alpha" . ?α) prettify-symbols-alist)
>> (push '("\\beta" . ?β) prettify-symbols-alist)
>> (setq prettify-symbols-compose-predicate 'texinfo-prettify-symbols-compose-p)
>> (prettify-symbols-mode)))
>
> So I have to add the following defun in prog-mode.el?
>
> (defun texinfo-prettify-symbols-compose-p (start end _match)
>
I don't know what you're trying to do. If you're trying to do something
just for yourself, just add the above lines in your .emacs file. If you
want to improve texinfo-mode, the defun above should probably go into
texinfo.el, with the "(setq prettify-symbols-compose-predicate
'texinfo-prettify-symbols-compose-p)" inside the "(define-derived-mode
texinfo-mode ...".
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: prettify-symbols-mode to handle "\alpha-\beta" ...
2021-02-05 23:22 ` Gregory Heytings
@ 2021-02-05 23:43 ` Christopher Dimech
2021-02-05 23:44 ` pietru
2021-02-06 0:05 ` pietru
2 siblings, 0 replies; 36+ messages in thread
From: Christopher Dimech @ 2021-02-05 23:43 UTC (permalink / raw)
To: Gregory Heytings; +Cc: emacs-devel
> Sent: Saturday, February 06, 2021 at 11:22 AM
> From: "Gregory Heytings" <gregory@heytings.org>
> To: pietru@caramail.com
> Cc: emacs-devel@gnu.org
> Subject: Re: prettify-symbols-mode to handle "\alpha-\beta" ...
>
>
> >> (defun texinfo-prettify-symbols-compose-p (start end _match)
> >> ;; We know the matches all start with a backslash and end with
> >> ;; a word-element.
> >> (not (or (memq (char-before start) '(?\\))
> >> (memq (char-syntax (or (char-after end) ?\s)) '(?w))
> >> (nth 8 (syntax-ppss)))))
> >> (add-hook 'texinfo-mode-hook
> >> (lambda ()
> >> (push '("\\alpha" . ?α) prettify-symbols-alist)
> >> (push '("\\beta" . ?β) prettify-symbols-alist)
> >> (setq prettify-symbols-compose-predicate 'texinfo-prettify-symbols-compose-p)
> >> (prettify-symbols-mode)))
> >
> > So I have to add the following defun in prog-mode.el?
> >
> > (defun texinfo-prettify-symbols-compose-p (start end _match)
> >
>
> I don't know what you're trying to do. If you're trying to do something
> just for yourself, just add the above lines in your .emacs file. If you
> want to improve texinfo-mode, the defun above should probably go into
> texinfo.el, with the "(setq prettify-symbols-compose-predicate
> 'texinfo-prettify-symbols-compose-p)" inside the "(define-derived-mode
> texinfo-mode ...".
Have tried the following expressions, which display correctly.
\alpha-\beta \alpha+\beta \alpha_{i\beta} \alpha/{i\beta} \alpha^{i\beta} \alpha. \beta, \beta?
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: prettify-symbols-mode to handle "\alpha-\beta" ...
2021-02-05 23:22 ` Gregory Heytings
2021-02-05 23:43 ` Christopher Dimech
@ 2021-02-05 23:44 ` pietru
2021-02-06 0:05 ` pietru
2 siblings, 0 replies; 36+ messages in thread
From: pietru @ 2021-02-05 23:44 UTC (permalink / raw)
To: Gregory Heytings; +Cc: emacs-devel
Currently I am trying to see things work for myself, then finally decide what
to use and improve texinfo later on.
> Sent: Saturday, February 06, 2021 at 11:22 AM
> From: "Gregory Heytings" <gregory@heytings.org>
> To: pietru@caramail.com
> Cc: emacs-devel@gnu.org
> Subject: Re: prettify-symbols-mode to handle "\alpha-\beta" ...
>
>
> >> (defun texinfo-prettify-symbols-compose-p (start end _match)
> >> ;; We know the matches all start with a backslash and end with
> >> ;; a word-element.
> >> (not (or (memq (char-before start) '(?\\))
> >> (memq (char-syntax (or (char-after end) ?\s)) '(?w))
> >> (nth 8 (syntax-ppss)))))
> >> (add-hook 'texinfo-mode-hook
> >> (lambda ()
> >> (push '("\\alpha" . ?α) prettify-symbols-alist)
> >> (push '("\\beta" . ?β) prettify-symbols-alist)
> >> (setq prettify-symbols-compose-predicate 'texinfo-prettify-symbols-compose-p)
> >> (prettify-symbols-mode)))
> >
> > So I have to add the following defun in prog-mode.el?
> >
> > (defun texinfo-prettify-symbols-compose-p (start end _match)
> >
>
> I don't know what you're trying to do. If you're trying to do something
> just for yourself, just add the above lines in your .emacs file. If you
> want to improve texinfo-mode, the defun above should probably go into
> texinfo.el, with the "(setq prettify-symbols-compose-predicate
> 'texinfo-prettify-symbols-compose-p)" inside the "(define-derived-mode
> texinfo-mode ...".
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: prettify-symbols-mode to handle "\alpha-\beta" ...
2021-02-05 23:22 ` Gregory Heytings
2021-02-05 23:43 ` Christopher Dimech
2021-02-05 23:44 ` pietru
@ 2021-02-06 0:05 ` pietru
2 siblings, 0 replies; 36+ messages in thread
From: pietru @ 2021-02-06 0:05 UTC (permalink / raw)
To: Gregory Heytings; +Cc: emacs-devel
> Sent: Saturday, February 06, 2021 at 11:22 AM
> From: "Gregory Heytings" <gregory@heytings.org>
> To: pietru@caramail.com
> Cc: emacs-devel@gnu.org
> Subject: Re: prettify-symbols-mode to handle "\alpha-\beta" ...
>
>
> >> (defun texinfo-prettify-symbols-compose-p (start end _match)
> >> ;; We know the matches all start with a backslash and end with
> >> ;; a word-element.
> >> (not (or (memq (char-before start) '(?\\))
> >> (memq (char-syntax (or (char-after end) ?\s)) '(?w))
> >> (nth 8 (syntax-ppss)))))
> >> (add-hook 'texinfo-mode-hook
> >> (lambda ()
> >> (push '("\\alpha" . ?α) prettify-symbols-alist)
> >> (push '("\\beta" . ?β) prettify-symbols-alist)
> >> (setq prettify-symbols-compose-predicate 'texinfo-prettify-symbols-compose-p)
> >> (prettify-symbols-mode)))
> >
> > So I have to add the following defun in prog-mode.el?
> >
> > (defun texinfo-prettify-symbols-compose-p (start end _match)
> >
>
> I don't know what you're trying to do. If you're trying to do something
> just for yourself, just add the above lines in your .emacs file. If you
> want to improve texinfo-mode, the defun above should probably go into
> texinfo.el, with the "(setq prettify-symbols-compose-predicate
> 'texinfo-prettify-symbols-compose-p)" inside the "(define-derived-mode
> texinfo-mode ...".
I found it strange how \alpha+\beta displays \alpha and \beta separately
when using plain-tex-mode, but behaves differently when using texinfo-mode.
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: prettify-symbols-mode to handle "\alpha-\beta" ...
2021-02-04 18:23 ` Stefan Monnier
2021-02-04 20:22 ` Christopher Dimech
@ 2021-02-04 20:34 ` Christopher Dimech
1 sibling, 0 replies; 36+ messages in thread
From: Christopher Dimech @ 2021-02-04 20:34 UTC (permalink / raw)
To: Stefan Monnier; +Cc: Óscar Fuentes, emacs-devel
> Sent: Friday, February 05, 2021 at 6:23 AM
> From: "Stefan Monnier" <monnier@iro.umontreal.ca>
> To: "Christopher Dimech" <dimech@gmx.com>
> Cc: "Óscar Fuentes" <ofv@wanadoo.es>, emacs-devel@gnu.org
> Subject: Re: prettify-symbols-mode to handle "\alpha-\beta" ...
>
> > The way I see it, is that the improvement should be put in
> > prog-mode.el,
>
> What is "the" improvement you're referring to?
>
> > and then the other major modes can rely on prog-mode.el fon a minor
> > mode that implements the prettify functionality.
>
> I think that's the case already, thanks to `prettify-symbols-mode`.
> I'm not saying it can't be improved, of course,
It is good for separate languages. But texinfo
and org are quite special cases, because they allow
one to use syntax from other languages. From what
I have seen, prettify is not aware of how mathematical
expressions in texinfo could be constructed. The way
mathematical expressions are written differ from simply
focusing on a keyword as is done for programming language
keywords.
>
> Stefan
>
>
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: prettify-symbols-mode to handle "\alpha-\beta" ...
2021-02-04 1:24 prettify-symbols-mode to handle "\alpha-\beta" pietru
2021-02-04 2:08 ` Óscar Fuentes
@ 2021-02-04 3:46 ` Ihor Radchenko
2021-02-04 3:59 ` Christopher Dimech
2021-02-04 8:44 ` tomas
2 siblings, 1 reply; 36+ messages in thread
From: Ihor Radchenko @ 2021-02-04 3:46 UTC (permalink / raw)
To: pietru, emacs-devel
pietru@caramail.com writes:
> Would you be so kind to update "prettify-symbols-mode"
> so the substitutions can become possible to handle.
Note that pretty-symbols package from Melpa does support using regex
patterns.
Best,
Ihor
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: prettify-symbols-mode to handle "\alpha-\beta" ...
2021-02-04 3:46 ` Ihor Radchenko
@ 2021-02-04 3:59 ` Christopher Dimech
0 siblings, 0 replies; 36+ messages in thread
From: Christopher Dimech @ 2021-02-04 3:59 UTC (permalink / raw)
To: Ihor Radchenko; +Cc: emacs-devel
I suggest that prettify-symbols on emacs is updated so its capabilities
can be extended. It would be good to have the functionality of
prettify-symbols usable for general use, particularly for texinfo
purposes. For instance, it wauld be very useful for Gnu Package
Manuals with focus on geomathematical computation such as Behistun.
> Sent: Thursday, February 04, 2021 at 3:46 PM
> From: "Ihor Radchenko" <yantar92@gmail.com>
> To: pietru@caramail.com, emacs-devel@gnu.org
> Subject: Re: prettify-symbols-mode to handle "\alpha-\beta" ...
>
> pietru@caramail.com writes:
>
> > Would you be so kind to update "prettify-symbols-mode"
> > so the substitutions can become possible to handle.
>
> Note that pretty-symbols package from Melpa does support using regex
> patterns.
>
> Best,
> Ihor
>
>
>
>
---------------------
Christopher Dimech
General Administrator - Naiad Informatics - GNU Project (Geocomputation)
- Geophysical Simulation
- Geological Subsurface Mapping
- Disaster Preparedness and Mitigation
- Natural Resource Exploration and Production
- Free Software Advocacy
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: prettify-symbols-mode to handle "\alpha-\beta" ...
2021-02-04 1:24 prettify-symbols-mode to handle "\alpha-\beta" pietru
2021-02-04 2:08 ` Óscar Fuentes
2021-02-04 3:46 ` Ihor Radchenko
@ 2021-02-04 8:44 ` tomas
2 siblings, 0 replies; 36+ messages in thread
From: tomas @ 2021-02-04 8:44 UTC (permalink / raw)
To: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 2244 bytes --]
On Thu, Feb 04, 2021 at 02:24:42AM +0100, pietru@caramail.com wrote:
>
> I am using prettify-symbols-mode for displaying greek command using
> the corresponding greek glyph when using mathematical expressions
> in texinfo.
>
> Here is an example
>
> (push '("\\alpha" . ?α) prettify-symbols-alist)
> (push '("\\beta" . ?β) prettify-symbols-alist)
>
> This works well when using "\alpha\beta", "\alpha - \beta"
> But the expression fails when using "\alpha-\beta" or
> "\alpha_i", "\alpha_{ij}", "\beta^i", "\beta+\alpha".
> The expressions are all valid mathematical expressions
> when using tex.
>
> Would you be so kind to update "prettify-symbols-mode"
> so the substitutions can become possible to handle.
>
> Does this require that SYMBOL in (SYMBOL . CHARACTER) be
> a regexp?
Quoth the doc, "26.11 Other Features Useful for Editing Programs":
"Prettify Symbols mode is a buffer-local minor mode that
replaces certain strings with more attractive versions for
display purposes. For example, in Emacs Lisp mode, it replaces
the string ‘lambda’ with the Greek lambda character
‘λ’. In a TeX buffer, it will replace ‘\alpha’
... ‘\omega’ and other math macros with their Unicode
characters. You may wish to use this in non-programming modes
as well. You can customize the mode by adding more entries to
‘prettify-symbols-alist’. More elaborate customization is
available via customizing ‘prettify-symbols-compose-predicate’
if its default value ‘prettify-symbols-default-compose-p’
is not appropriate. There is also a global version,
‘global-prettify-symbols-mode’, which enables the mode in
all buffers that support it.
The symbol at point can be shown in its original form. This is
controlled by the variable ‘prettify-symbols-unprettify-at-point’:
if non-‘nil’, the original form of symbol at point will be restored
for as long as point is at it."
So I'd look around the variable's docstrings (C-h v) of
- prettify-symbols-alist (this you already know)
- prettify-symbols-compose-predicate
This might answer (at least part of) your questions.
Cheers
- t
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]
^ permalink raw reply [flat|nested] 36+ messages in thread
end of thread, other threads:[~2021-02-06 0:05 UTC | newest]
Thread overview: 36+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-02-04 1:24 prettify-symbols-mode to handle "\alpha-\beta" pietru
2021-02-04 2:08 ` Óscar Fuentes
2021-02-04 3:03 ` pietru
2021-02-04 3:39 ` Óscar Fuentes
2021-02-04 3:46 ` Christopher Dimech
2021-02-04 3:51 ` pietru
2021-02-04 4:04 ` Stefan Monnier
2021-02-04 4:21 ` Christopher Dimech
2021-02-04 16:12 ` Stefan Monnier
2021-02-04 18:09 ` Christopher Dimech
2021-02-04 18:21 ` Stefan Monnier
2021-02-04 20:14 ` Christopher Dimech
2021-02-04 18:15 ` Christopher Dimech
2021-02-04 18:23 ` Stefan Monnier
2021-02-04 20:22 ` Christopher Dimech
2021-02-04 20:38 ` Stefan Monnier
2021-02-04 20:54 ` Christopher Dimech
2021-02-05 20:32 ` pietru
2021-02-05 21:01 ` Stefan Monnier
2021-02-05 21:05 ` Christopher Dimech
2021-02-05 21:54 ` Christopher Dimech
2021-02-05 21:57 ` Stefan Monnier
2021-02-05 22:09 ` Gregory Heytings
2021-02-05 22:22 ` pietru
2021-02-05 22:45 ` Gregory Heytings
2021-02-05 22:56 ` pietru
2021-02-05 23:04 ` Gregory Heytings
2021-02-05 23:15 ` pietru
2021-02-05 23:22 ` Gregory Heytings
2021-02-05 23:43 ` Christopher Dimech
2021-02-05 23:44 ` pietru
2021-02-06 0:05 ` pietru
2021-02-04 20:34 ` Christopher Dimech
2021-02-04 3:46 ` Ihor Radchenko
2021-02-04 3:59 ` Christopher Dimech
2021-02-04 8:44 ` tomas
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
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).