all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Subscript with parenthesis
@ 2023-09-21 22:45 Tom Alexander
  2023-09-21 23:02 ` Tom Alexander
  0 siblings, 1 reply; 12+ messages in thread
From: Tom Alexander @ 2023-09-21 22:45 UTC (permalink / raw)
  To: emacs-orgmode

The org-mode documentation[1] states that the SCRIPT portion of the subscript/superscript is either an asterisk, the standard set of objects wrapped in balanced curly braces, or an optional sign followed by "Either the empty string, or a string consisting of any number of alphanumeric characters, commas, backslashes, and dots"

But I'm seeing the following test document parse as containing a subscript despite using parenthesis which I do not think matches any of the above criteria:
```
foo_(bar)
```

[1] https://orgmode.org/worg/org-syntax.html#Subscript_and_Superscript

--
Tom Alexander



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Subscript with parenthesis
  2023-09-21 22:45 Subscript with parenthesis Tom Alexander
@ 2023-09-21 23:02 ` Tom Alexander
  2023-09-22  9:14   ` Ihor Radchenko
  0 siblings, 1 reply; 12+ messages in thread
From: Tom Alexander @ 2023-09-21 23:02 UTC (permalink / raw)
  To: emacs-orgmode

Some additional things I'm noticing:

- when using parenthesis, :use-brackets-p is nil, so they're not equivalent to curly braces.
- it does not support objects inside the parenthesis, just plain text, which again means they're not equivalent to braces.
- it, however, seems to require that the parenthesis are balanced because this test document does NOT contain a subscript:
```
foo_(b(ar)
```
which is closer to the curly braces requirement since that seems to be the only part of the subscript/superscript documentation that mentions needing balance.

-- 
Tom Alexander


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Subscript with parenthesis
  2023-09-21 23:02 ` Tom Alexander
@ 2023-09-22  9:14   ` Ihor Radchenko
  2023-09-29 16:12     ` Tom Alexander
  2024-02-17 14:06     ` [DISCUSSION] What should we do with undocumented x^(superscript inside /round/ braces) syntax? (was: Subscript with parenthesis) Ihor Radchenko
  0 siblings, 2 replies; 12+ messages in thread
From: Ihor Radchenko @ 2023-09-22  9:14 UTC (permalink / raw)
  To: Tom Alexander; +Cc: emacs-orgmode

"Tom Alexander" <tom@fizz.buzz> writes:

> Some additional things I'm noticing:
>
> - when using parenthesis, :use-brackets-p is nil, so they're not equivalent to curly braces.

`org-element-subscript-parser' uses `org-match-substring-regexp', which
indeed allows foo_(...). This is not documented in org-syntax.org and in
the manual (12.3 Subscripts and Superscripts).

> - it does not support objects inside the parenthesis, just plain text, which again means they're not equivalent to braces.

Not true. I tried

b^(*asd*) and bold inside superscript does get parsed.

> - it, however, seems to require that the parenthesis are balanced because this test document does NOT contain a subscript:
> ```
> foo_(b(ar)
> ```
> which is closer to the curly braces requirement since that seems to be the only part of the subscript/superscript documentation that mentions needing balance.

Yup - the regexp used is the same with what we do for curly braces:

(defconst org-match-substring-regexp
  (concat
   "\\(\\S-\\)\\([_^]\\)\\("
   "\\(?:" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
   "\\|"
   "\\(?:" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth) "\\)"
   "\\|"
   "\\(?:\\*\\|[+-]?[[:alnum:].,\\]*[[:alnum:]]\\)\\)")
  "The regular expression matching a sub- or superscript.")

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Subscript with parenthesis
  2023-09-22  9:14   ` Ihor Radchenko
@ 2023-09-29 16:12     ` Tom Alexander
  2024-02-17 14:06     ` [DISCUSSION] What should we do with undocumented x^(superscript inside /round/ braces) syntax? (was: Subscript with parenthesis) Ihor Radchenko
  1 sibling, 0 replies; 12+ messages in thread
From: Tom Alexander @ 2023-09-29 16:12 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: emacs-orgmode

> Not true. I tried
>
> b^(*asd*) and bold inside superscript does get parsed.

Ah thanks for double-checking! You're right, that is getting parsed. Not sure what test document I was using to make me think objects didn't work inside the parenthesis.

--
Tom Alexander
pgp: https://fizz.buzz/pgp.asc


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [DISCUSSION] What should we do with undocumented x^(superscript inside /round/ braces) syntax? (was: Subscript with parenthesis)
  2023-09-22  9:14   ` Ihor Radchenko
  2023-09-29 16:12     ` Tom Alexander
@ 2024-02-17 14:06     ` Ihor Radchenko
  2024-02-17 19:36       ` William Denton
                         ` (2 more replies)
  1 sibling, 3 replies; 12+ messages in thread
From: Ihor Radchenko @ 2024-02-17 14:06 UTC (permalink / raw)
  To: Tom Alexander; +Cc: emacs-orgmode

Ihor Radchenko <yantar92@posteo.net> writes:

> "Tom Alexander" <tom@fizz.buzz> writes:
>
>> Some additional things I'm noticing:
>>
>> - when using parenthesis, :use-brackets-p is nil, so they're not equivalent to curly braces.
>
> `org-element-subscript-parser' uses `org-match-substring-regexp', which
> indeed allows foo_(...). This is not documented in org-syntax.org and in
> the manual (12.3 Subscripts and Superscripts).

Inconsistent with LaTeX syntax, Org mode not only allows
x^{superscript}, but also x^(superscript) with round braces used for
grouping.

This does not seem to be documented in the manual and is only vaguely
mentioned in the `org-use-sub-superscripts' docstring in a single
example:

 x_{i^2} or   x^(2-i)    braces or parenthesis do grouping.

The rest of the docstring only refers to {} or just to genetic "braces".

This situation is awkward, because such subtle inconsistency between Org
and LaTeX syntax can be very surprising.

To demonstrate, try to export the following to pdf:

# ---
Direct latex code =$foo^(bar)$= :: @@latex:$foo^(bar)$@@

Org mode markup =foo^(bar)= :: foo^(bar)
# ---

The first line will only create superscript for "(", while the second
line will make the whole "(bar)" into superscript.

-----

I tentatively propose to remove the x^(2-i) example from the docstring
and mark the ^(...) syntax deprecated.

WDYT?

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [DISCUSSION] What should we do with undocumented x^(superscript inside /round/ braces) syntax? (was: Subscript with parenthesis)
  2024-02-17 14:06     ` [DISCUSSION] What should we do with undocumented x^(superscript inside /round/ braces) syntax? (was: Subscript with parenthesis) Ihor Radchenko
@ 2024-02-17 19:36       ` William Denton
  2024-02-17 20:03         ` Thomas Dye
  2024-02-17 21:22       ` Mark Barton
  2024-02-19 18:15       ` [DISCUSSION] What should we do with undocumented x^(superscript inside /round/ braces) syntax? Fraga, Eric
  2 siblings, 1 reply; 12+ messages in thread
From: William Denton @ 2024-02-17 19:36 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: emacs-orgmode

On Saturday, February 17th, 2024 at 07:07, Ihor Radchenko <yantar92@posteo.net> wrote:

> I tentatively propose to remove the x^(2-i) example from the docstring
> and mark the ^(...) syntax deprecated.
> 
> WDYT?

I think it's very sensible.  It's surprising ^(...) works like this, and if anyone was using it (perhaps by accident) it will be easy to change when necessary.


Bill

--
William Denton
https://www.miskatonic.org/
Librarian, artist and licensed private investigator.
Toronto, Canada



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [DISCUSSION] What should we do with undocumented x^(superscript inside /round/ braces) syntax? (was: Subscript with parenthesis)
  2024-02-17 19:36       ` William Denton
@ 2024-02-17 20:03         ` Thomas Dye
  0 siblings, 0 replies; 12+ messages in thread
From: Thomas Dye @ 2024-02-17 20:03 UTC (permalink / raw)
  To: William Denton; +Cc: Ihor Radchenko, emacs-orgmode

+1

Tom

> On Feb 17, 2024, at 9:38 AM, William Denton <william@williamdenton.org> wrote:
> 
> On Saturday, February 17th, 2024 at 07:07, Ihor Radchenko <yantar92@posteo.net> wrote:
> 
>> I tentatively propose to remove the x^(2-i) example from the docstring
>> and mark the ^(...) syntax deprecated.
>> 
>> WDYT?
> 
> I think it's very sensible.  It's surprising ^(...) works like this, and if anyone was using it (perhaps by accident) it will be easy to change when necessary.
> 
> 
> Bill
> 
> --
> William Denton
> https://www.miskatonic.org/
> Librarian, artist and licensed private investigator.
> Toronto, Canada
> 
> 



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [DISCUSSION] What should we do with undocumented x^(superscript inside /round/ braces) syntax? (was: Subscript with parenthesis)
  2024-02-17 14:06     ` [DISCUSSION] What should we do with undocumented x^(superscript inside /round/ braces) syntax? (was: Subscript with parenthesis) Ihor Radchenko
  2024-02-17 19:36       ` William Denton
@ 2024-02-17 21:22       ` Mark Barton
  2024-02-19 18:15       ` [DISCUSSION] What should we do with undocumented x^(superscript inside /round/ braces) syntax? Fraga, Eric
  2 siblings, 0 replies; 12+ messages in thread
From: Mark Barton @ 2024-02-17 21:22 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Tom Alexander, emacs-orgmode



> On Feb 17, 2024, at 5:33 AM, Ihor Radchenko <yantar92@posteo.net> wrote:
> 
> WDYT?
+1

I use the curly braces since I often use underscores for other reasons. There would be no impact to me and this is the first I ever heard that parentheses would work. 



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [DISCUSSION] What should we do with undocumented x^(superscript inside /round/ braces) syntax?
  2024-02-17 14:06     ` [DISCUSSION] What should we do with undocumented x^(superscript inside /round/ braces) syntax? (was: Subscript with parenthesis) Ihor Radchenko
  2024-02-17 19:36       ` William Denton
  2024-02-17 21:22       ` Mark Barton
@ 2024-02-19 18:15       ` Fraga, Eric
  2024-02-19 18:30         ` Ihor Radchenko
  2 siblings, 1 reply; 12+ messages in thread
From: Fraga, Eric @ 2024-02-19 18:15 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Tom Alexander, emacs-orgmode@gnu.org

On Saturday, 17 Feb 2024 at 14:06, Ihor Radchenko wrote:
> Inconsistent with LaTeX syntax, Org mode not only allows
> x^{superscript}, but also x^(superscript) with round braces used for
> grouping.

Inconsistent with LaTeX is not a sufficient reason for removing this, in
my opinion.  Org has /dwim/ elements which make it easier to write some
expressions than in LaTeX.  Another example is ~x^-1~ which works as I
want but would make no sense in LaTeX (where only the "-" would be
superscripted, not the 1).

-- 
: Eric S Fraga, with org release_9.6.18-1158-g8e2ed4 in Emacs 30.0.50

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [DISCUSSION] What should we do with undocumented x^(superscript inside /round/ braces) syntax?
  2024-02-19 18:15       ` [DISCUSSION] What should we do with undocumented x^(superscript inside /round/ braces) syntax? Fraga, Eric
@ 2024-02-19 18:30         ` Ihor Radchenko
  2024-03-20 13:57           ` Ihor Radchenko
  0 siblings, 1 reply; 12+ messages in thread
From: Ihor Radchenko @ 2024-02-19 18:30 UTC (permalink / raw)
  To: Fraga, Eric; +Cc: Tom Alexander, emacs-orgmode@gnu.org

"Fraga, Eric" <e.fraga@ucl.ac.uk> writes:

> On Saturday, 17 Feb 2024 at 14:06, Ihor Radchenko wrote:
>> Inconsistent with LaTeX syntax, Org mode not only allows
>> x^{superscript}, but also x^(superscript) with round braces used for
>> grouping.
>
> Inconsistent with LaTeX is not a sufficient reason for removing this, in
> my opinion.  Org has /dwim/ elements which make it easier to write some
> expressions than in LaTeX.  Another example is ~x^-1~ which works as I
> want but would make no sense in LaTeX (where only the "-" would be
> superscripted, not the 1).

Good point.
Although, do note that unlike x^word, x^(some text) is not documented.
Moreover, options like ^:{} create an impression that only curly braces
are accepted.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [DISCUSSION] What should we do with undocumented x^(superscript inside /round/ braces) syntax?
  2024-02-19 18:30         ` Ihor Radchenko
@ 2024-03-20 13:57           ` Ihor Radchenko
  2024-04-21  9:44             ` Ihor Radchenko
  0 siblings, 1 reply; 12+ messages in thread
From: Ihor Radchenko @ 2024-03-20 13:57 UTC (permalink / raw)
  To: Fraga, Eric; +Cc: Tom Alexander, emacs-orgmode@gnu.org

Ihor Radchenko <yantar92@posteo.net> writes:

> "Fraga, Eric" <e.fraga@ucl.ac.uk> writes:
>
>> On Saturday, 17 Feb 2024 at 14:06, Ihor Radchenko wrote:
>>> Inconsistent with LaTeX syntax, Org mode not only allows
>>> x^{superscript}, but also x^(superscript) with round braces used for
>>> grouping.
>>
>> Inconsistent with LaTeX is not a sufficient reason for removing this, in
>> my opinion.  Org has /dwim/ elements which make it easier to write some
>> expressions than in LaTeX.  Another example is ~x^-1~ which works as I
>> want but would make no sense in LaTeX (where only the "-" would be
>> superscripted, not the 1).
>
> Good point.
> Although, do note that unlike x^word, x^(some text) is not documented.
> Moreover, options like ^:{} create an impression that only curly braces
> are accepted.

Upon further examination, I found that ^:{} does accept _only_ curly
braces:

#+options: ^:{}
x^word
x^{word}
x^(word)

yields (in latex export):

x\^{}word
x\textsuperscript{word}
x\^{}(word)

So, round braces can be seen as another variant of DWIM behavior.

I conclude that there is no reason to change the existing syntax.

I will need to update `org-use-sub-superscripts' docstring and
https://orgmode.org/worg/org-syntax.html#Subscript_and_Superscript to
document this special case.

Maybe also update the manual section 12.3 Subscripts and Superscripts.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [DISCUSSION] What should we do with undocumented x^(superscript inside /round/ braces) syntax?
  2024-03-20 13:57           ` Ihor Radchenko
@ 2024-04-21  9:44             ` Ihor Radchenko
  0 siblings, 0 replies; 12+ messages in thread
From: Ihor Radchenko @ 2024-04-21  9:44 UTC (permalink / raw)
  To: Fraga, Eric; +Cc: Tom Alexander, emacs-orgmode@gnu.org

Ihor Radchenko <yantar92@posteo.net> writes:

> Upon further examination, I found that ^:{} does accept _only_ curly
> braces:
> ...
> So, round braces can be seen as another variant of DWIM behavior.
>
> I conclude that there is no reason to change the existing syntax.
>
> I will need to update `org-use-sub-superscripts' docstring and
> https://orgmode.org/worg/org-syntax.html#Subscript_and_Superscript to
> document this special case.
>
> Maybe also update the manual section 12.3 Subscripts and Superscripts.

All done on main.
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=36d092804
https://git.sr.ht/~bzg/worg/commit/834ac25e

Closed.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2024-04-21  9:45 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-21 22:45 Subscript with parenthesis Tom Alexander
2023-09-21 23:02 ` Tom Alexander
2023-09-22  9:14   ` Ihor Radchenko
2023-09-29 16:12     ` Tom Alexander
2024-02-17 14:06     ` [DISCUSSION] What should we do with undocumented x^(superscript inside /round/ braces) syntax? (was: Subscript with parenthesis) Ihor Radchenko
2024-02-17 19:36       ` William Denton
2024-02-17 20:03         ` Thomas Dye
2024-02-17 21:22       ` Mark Barton
2024-02-19 18:15       ` [DISCUSSION] What should we do with undocumented x^(superscript inside /round/ braces) syntax? Fraga, Eric
2024-02-19 18:30         ` Ihor Radchenko
2024-03-20 13:57           ` Ihor Radchenko
2024-04-21  9:44             ` Ihor Radchenko

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.