Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sub- and superscript detection #346

Open
saf-dmitry opened this issue Jul 11, 2018 · 9 comments · May be fixed by #521
Open

Sub- and superscript detection #346

saf-dmitry opened this issue Jul 11, 2018 · 9 comments · May be fixed by #521

Comments

@saf-dmitry
Copy link
Contributor

I find the current sub- and superscript detection too restrictive. What is the reason to limit sub- and superscript expression to just alphanumeric characters?

@jrblevin
Copy link
Owner

I don't think there's a reason; that's just how the original patch was written. Here are Pandoc's rules: http://pandoc.org/MANUAL.html#superscripts-and-subscripts.

@saf-dmitry
Copy link
Contributor Author

saf-dmitry commented Jul 16, 2018

Here are Pandoc's rules: http://pandoc.org/MANUAL.html#superscripts-and-subscripts.

Well, in this case sub- and superscript can still contain escaped spaces, punctuation, and other symbols.

Therefore I suggest following regexp. This regexp allows any backslash-escaped symbol, incl. whitespace, or any other symbol excl. space and tab to be part of sub- or superscript expression.

(defconst markdown-regex-sub-superscript
  "\\(?:^\\|[^\\~^]\\)\\(\\([~^]\\)\\(\\(?:\\\\.\\|[^[:space:]]\\)+?\\)\\(\\2\\)\\)"
  "The regular expression matching a sub- or superscript.
The leading un-numbered group matches the character before the
opening tilde or caret, if any, ensuring that it is not a
backslash escape, caret, or tilde.
Group 1 matches the entire expression, including markup.
Group 2 matches the opening markup--a tilde or caret.
Group 3 matches the text inside the delimiters.
Group 4 matches the closing markup--a tilde or caret.")

@saf-dmitry saf-dmitry linked a pull request Aug 12, 2020 that will close this issue
9 tasks
@steveb-123
Copy link

If there is a way to implement this functionality it would be of broad use to many doing scientific writing.

Rendering in buffer of a common scientific usage of superscripts, like in 1.0 × 10^−15^ or similar, is broken currently, for me at least (markdown-mode ver 20220116.209)

1.0 × 10^15^ renders as expected.

Thanks :)

@syohex
Copy link
Collaborator

syohex commented Jan 17, 2022

@steveb-123 How about latest version ? It highlights as below screenshot.

superscript

@steveb-123
Copy link

steveb-123 commented Jan 17, 2022

yup, that fixed it thanks!

I was surprised how far back the ELPA version was actually.

I got a little confused as I didnt noticed you merged that just now! It took me a minute to work out how to switch to the Github branch in Doom Emacs. For any fellow Doomers, adding this to packages.el got me onto the github source of the package with no further config:

(package! markdown-mode :recipe (:host github :repo "jrblevin/markdown-mode"))

@saf-dmitry
Copy link
Contributor Author

saf-dmitry commented Jan 17, 2022

@syohex That's nice! However, what about Unicode minus sign U+2212? I would suggest allowing it in sub- and superscripts too.

@steveb-123
Copy link

Well said, I didn't notice that minus was not in there.

I think both plus and minus would keep many chemists and biochemists happy also.

@saf-dmitry
Copy link
Contributor Author

I think both plus and minus would keep many chemists and biochemists happy also

Therefore I suggest this regexp #346 (comment). The regexp allows any backslash-escaped symbol, incl. whitespace, or any other symbol excl. space and tab to be part of sub- or superscript expression.

@saf-dmitry
Copy link
Contributor Author

I think both plus and minus would keep many chemists and biochemists happy also.

Speaking of chemistry: Unfortunately, since plus and minus are allowed as leading signs only, we still cannot use superscripts for denoting ions, like Fe^2+^.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants