amake / orgro

An Org Mode file viewer for iOS and Android
https://orgro.org
GNU General Public License v3.0
452 stars 21 forks source link

Support user-defined pretty entities #84

Closed vitaminace33 closed 7 months ago

vitaminace33 commented 8 months ago

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

amake commented 8 months ago

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

vitaminace33 commented 8 months ago

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

amake commented 8 months ago

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

vitaminace33 commented 8 months ago

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 commented 8 months ago

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 ```org * COMMENT Local Variables # Local Variables: # 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 "⇔" "<=>" "<=>" "⇔") # ("from" "\\leftarrow" t "←" "<-" "<-" "←") # ("mapsto" "\\mapsto" t "&x21A6;" "->" "->" "↦") # ("leadsto" "\\leadsto" t "&x21DD;" "->" "->" "⇝") # ("pm" "\\mp" nil "±" "+-" "±" "±") # ("mp" "\\pm" nil "∓" "-+" "-±" "∓") # ("sqrt" "\\sqrt" t "√" "sqrt" "sqrt" "√") # ("cbrt" "\\sqrt[3]" t "∛" "cbrt" "cbrt" "∛") # ("frrt" "\\sqrt[4]" t "∜" "frrt" "frrt" "∜")) # End: ```
vitaminace33 commented 8 months ago

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 commented 8 months ago

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 commented 8 months ago

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 commented 8 months ago

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 commented 8 months ago

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 commented 8 months ago

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 commented 8 months ago

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

amake commented 7 months ago

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 https://github.com/amake/orgro/issues/84#issuecomment-1774132523

vitaminace33 commented 7 months ago

Nice! I'm gonna give it a try.

amake commented 7 months ago

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

vitaminace33 commented 7 months ago

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

amake commented 6 months ago

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