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

Support user-defined pretty entities #84

Closed
vitaminace33 opened this issue Oct 22, 2023 · 17 comments
Closed

Support user-defined pretty entities #84

vitaminace33 opened this issue Oct 22, 2023 · 17 comments
Labels
enhancement New feature or request

Comments

@vitaminace33
Copy link

Orgro supports pretty entities. Does it allow to set new org-entities through org-entities-user?

@amake
Copy link
Owner

amake commented Oct 22, 2023

No, there is currently no way to influence the available entities.

@amake amake added the enhancement New feature or request label Oct 22, 2023
@amake amake changed the title pretty entities Support user-defined pretty entities Oct 22, 2023
@vitaminace33
Copy link
Author

I hope this feature can be included in a near future. Nice app in any case.

@amake
Copy link
Owner

amake commented Oct 22, 2023

Can you give an example entry or your org-entities-user setting?

@vitaminace33
Copy link
Author

vitaminace33 commented Oct 22, 2023

Sure.

The Emacs variable description of org-entities-user is

The order of the fields is the following

name                 As a string, without the leading backslash.
LaTeX replacement    In ready LaTeX, no further processing will take place.
LaTeX mathp          Either t or nil.  When t this entity needs to be in
                     math mode.
HTML replacement     In ready HTML, no further processing will take place.
                     Usually this will be an &...; entity.
ASCII replacement    Plain ASCII, no extensions.
Latin1 replacement   Use the special characters available in latin1.
utf-8 replacement    Use the special characters available in utf-8.

At the moment, mine has the following value.

(setq org-entities-user   '(
  ("primes"      "\\mathbb{P}" t "ℙ"      "P" "P" "")
  ("naturals"    "\\mathbb{N}" t "ℕ"    "N" "P" "")
  ("integers"    "\\mathbb{Z}" t "ℤ"    "Z" "Z" "")
  ("rationals"   "\\mathbb{Q}" t "ℚ"   "Q" "Q" "")
  ("irrationals" "\\mathbb{I}" t "𝕀"        "I" "I" "𝕀")
  ("reals"       "\\mathbb{R}" t "ℝ"       "R" "R" "")
  ("complexes"   "\\mathbb{C}" t "ℂ"   "C" "C" "")
  ("quaternions" "\\mathbb{H}" t "ℍ" "H" "H" "")
  ("scalars"     "\\mathbb{K}" t "𝕂"        "K" "K" "𝕂")
  ("coloneq" "\\coloneqq" t "≔" ":=" ":=" "")
  ("eqcolon" "\\eqqcolon" t "≕" "=:" "=:" "")
  ("then" "\\Rightarrow" t "⇒" "=>" "=>" "")
  ("iff" "\\Leftrightarrow" t "&hArr;" "<=>" "<=>" "")
  ("from" "\\leftarrow" t "&larr;" "<-" "<-" "")
  ("mapsto" "\\mapsto" t "&x21A6;" "->" "->" "")
  ("leadsto" "\\leadsto" t "&x21DD;" "->" "->" "")
  ("pm" "\\mp" nil "&pm;" "+-" "±" "±")
  ("mp" "\\pm" nil "&mp;" "-+" "" "")
  ("sqrt" "\\sqrt" t "&Sqrt;" "sqrt" "sqrt" "")
  ("cbrt" "\\sqrt[3]" t "&#x221B;" "cbrt" "cbrt" "")
  ("frrt" "\\sqrt[4]" t "&#x221C;" "frrt" "frrt" "")
))

I believe only the first and last "columns" are of interest to Orgro.

I hope it is of help.

@amake
Copy link
Owner

amake commented Oct 22, 2023

I've strenuously avoided adding settings to Orgro itself, and I'd prefer to keep it that way for this as well.

What I'm thinking now is to support parsing and interpreting org-entities-user set via the local variables list.

You could hide such a section from export via the noexport tag or the COMMENT keyword.

Your setting would look like this at the bottom of your file:

* COMMENT Local Variables
# Local Variables:
# org-entities-user: (("primes" "\\mathbb{P}" t "&primes;" "P" "P" "ℙ") ("naturals" "\\mathbb{N}" t "&naturals;" "N" "P" "ℕ") ("integers" "\\mathbb{Z}" t "&integers;" "Z" "Z" "ℤ") ("rationals" "\\mathbb{Q}" t "&rationals;" "Q" "Q" "ℚ") ("irrationals" "\\mathbb{I}" t "&Iopf;" "I" "I" "𝕀") ("reals" "\\mathbb{R}" t "&reals;" "R" "R" "ℝ") ("complexes" "\\mathbb{C}" t "&complexes;" "C" "C" "ℂ") ("quaternions" "\\mathbb{H}" t "&quaternions;" "H" "H" "ℍ") ("scalars" "\\mathbb{K}" t "&Kopf;" "K" "K" "𝕂") ("coloneq" "\\coloneqq" t "&coloneq;" ":=" ":=" "≔") ("eqcolon" "\\eqqcolon" t "&eqcolon;" "=:" "=:" "≕") ("then" "\\Rightarrow" t "&rArr;" "=>" "=>" "⇒") ("iff" "\\Leftrightarrow" t "&hArr;" "<=>" "<=>" "⇔") ("from" "\\leftarrow" t "&larr;" "<-" "<-" "←") ("mapsto" "\\mapsto" t "&x21A6;" "->" "->" "↦") ("leadsto" "\\leadsto" t "&x21DD;" "->" "->" "⇝") ("pm" "\\mp" nil "&pm;" "+-" "±" "±") ("mp" "\\pm" nil "&mp;" "-+" "-±" "∓") ("sqrt" "\\sqrt" t "&Sqrt;" "sqrt" "sqrt" "√") ("cbrt" "\\sqrt[3]" t "&#x221B;" "cbrt" "cbrt" "∛") ("frrt" "\\sqrt[4]" t "&#x221C;" "frrt" "frrt" "∜"))
# End:

(The single-line form I got from doing M-x add-file-local-variable and pasting in your value. You can also have it written item-by-item like below.)

Line-by-line version
* COMMENT Local Variables
# Local Variables:
# org-entities-user: (
#   ("primes" "\\mathbb{P}" t "&primes;" "P" "P" "ℙ")
#   ("naturals" "\\mathbb{N}" t "&naturals;" "N" "P" "ℕ")
#   ("integers" "\\mathbb{Z}" t "&integers;" "Z" "Z" "ℤ")
#   ("rationals" "\\mathbb{Q}" t "&rationals;" "Q" "Q" "ℚ")
#   ("irrationals" "\\mathbb{I}" t "&Iopf;" "I" "I" "𝕀")
#   ("reals" "\\mathbb{R}" t "&reals;" "R" "R" "ℝ")
#   ("complexes" "\\mathbb{C}" t "&complexes;" "C" "C" "ℂ")
#   ("quaternions" "\\mathbb{H}" t "&quaternions;" "H" "H" "ℍ")
#   ("scalars" "\\mathbb{K}" t "&Kopf;" "K" "K" "𝕂")
#   ("coloneq" "\\coloneqq" t "&coloneq;" ":=" ":=" "≔")
#   ("eqcolon" "\\eqqcolon" t "&eqcolon;" "=:" "=:" "≕")
#   ("then" "\\Rightarrow" t "&rArr;" "=>" "=>" "⇒")
#   ("iff" "\\Leftrightarrow" t "&hArr;" "<=>" "<=>" "⇔")
#   ("from" "\\leftarrow" t "&larr;" "<-" "<-" "←")
#   ("mapsto" "\\mapsto" t "&x21A6;" "->" "->" "↦")
#   ("leadsto" "\\leadsto" t "&x21DD;" "->" "->" "⇝")
#   ("pm" "\\mp" nil "&pm;" "+-" "±" "±")
#   ("mp" "\\pm" nil "&mp;" "-+" "-±" "∓")
#   ("sqrt" "\\sqrt" t "&Sqrt;" "sqrt" "sqrt" "√")
#   ("cbrt" "\\sqrt[3]" t "&#x221B;" "cbrt" "cbrt" "∛")
#   ("frrt" "\\sqrt[4]" t "&#x221C;" "frrt" "frrt" "∜"))
# End:

@vitaminace33
Copy link
Author

vitaminace33 commented Oct 22, 2023

I've strenuously avoided adding settings to Orgro itself, and I'd prefer to keep it that way for this as well.

I understand.

Your solution overwrites org-entities-user. I propose do append a local list by looping add-to-list with dolist. It is perhaps not the best/fastest solution, but I think it is quite safe.

# Local Variables:
# eval: (dolist (org-entity-local '(
#           ("cont" "\\mathcal{C}" t "&Cscr;" "C" "C" "𝒞")
#           ("neigh" "\\mathcal{E}" t "&Escr;" "E" "E" "")
#       )) (add-to-list 'org-entities-user org-entity-local t))
# End:

Thank you for pointing me to the solution. Cheerios.

@amake
Copy link
Owner

amake commented Oct 22, 2023

Your solution overwrites org-entities-user.

Ah yes, that would be a problem if you don't want to include your entire value in every document.

I propose do append a local list by looping add-to-list with dolist. It is perhaps not the best/fastest solution, but I think it is quite safe.

Now Orgro can't just parse the value; it needs to be able to run arbitrary Elisp. This is a much bigger task, and may not even be allowed on the App Store.

@vitaminace33
Copy link
Author

Now Orgro can't just parse the value; it needs to be able to run arbitrary Elisp. This is a much bigger task, and may not even be allowed on the App Store.

Does Orgro get updates from Emacs? I could contact upstream to see if it is feasible to add a new variable, org-entities-local, to be set locally per file.

@amake
Copy link
Owner

amake commented Oct 22, 2023

Orgro doesn't use any Emacs or org-mode code; I've reimplemented the relevant bits in Dart. So in principle I can just decide to support org-entities-local or even orgro-entities-user.

In general I would prefer to not invent new things here; in other words ideally org-mode would add org-entities-local and I would support that.

@vitaminace33
Copy link
Author

Orgro doesn't use any Emacs or org-mode code; I've reimplemented the relevant bits in Dart. So in principle I can just decide to support org-entities-local or even orgro-entities-user.

You should definitely give support to either org-entities-user or org-entities-local. Currently org-entities-user is the official way to extend org-entities. I assume that, if you decide to give support to orgro-entities-user, supporting afterwards org-entities-local should be a piece of cake. But I can also understand that you prefer to wait and see if the Emacs/Orgmode developers decide to implement a local solution such as org-entities-local (I let you know if it is the case).

Just to know, what is the set of entities Orgro supports? The one from org-entities? I'll be pushing a pull request to Emacs/Orgmode to update the default set of org-entities which lacks of many basic symbols such as the numeric sets I gave above.

@amake
Copy link
Owner

amake commented Oct 23, 2023

Just to know, what is the set of entities Orgro supports? The one from org-entities?

Yes, I generate the default list from org-entities:
https://github.com/amake/org_flutter/blob/d30d0091124fc66b2b181ab5b9ef798fafe2b2e6/lib/src/entity.dart

@amake
Copy link
Owner

amake commented Nov 4, 2023

Support for org-entities-user and org-entities-local will be available for testing in 1.34.0:

@amake
Copy link
Owner

amake commented Nov 23, 2023

v1.34.2 is out on the App Store and Google Play; it supports local var list definitions for org-entities-user, org-entities-local, and the formulation in #84 (comment)

@amake amake closed this as completed Nov 23, 2023
@vitaminace33
Copy link
Author

Nice! I'm gonna give it a try.

@amake
Copy link
Owner

amake commented Nov 26, 2023

v1.34.2 is now available on F-Droid as well.

@vitaminace33
Copy link
Author

I've just tried it and it seems to work correctly. Thanks for the implementation!

@amake
Copy link
Owner

amake commented Dec 12, 2023

Incidentally the "safe" predicate for org-entities-user is incorrect as of Org 9.6.13, so if you set the value via local variables Emacs will bug you to accept it.

I submitted a fix that should be in the next release.
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=1ec18b8ebcbfc6d3ad98535f80157307ccea911d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants