Kugcro · 2022-02-05 19:22
When editing .tex files in AUCTEX mode everything works as expected, but in org mode the variable ‘prettify-symbols-alist is empty. I tried to set it value same as in tex--prettify-symbols-alist with code
(setq my-org-tex-prettify-list
'(("\\alpha" . 945)
("\\beta" . 946)
...................
("\\textcircledP" . 8471)
("\\textreferencemark" . 8251))
)
(defun my-configure-prettify-symbols-alist-in-org-mode ()
"Set up symbols for prettify-symbols mode in org, same as in
AUCTEX package"
(setq prettify-symbols-alist 'my-org-tex-prettify-list))
(defun my-activate-prettify-symbols-mode-org ()
(my-configure-prettify-symbols-alist-in-org-mode)
(prettify-symbols-mode t))
(add-hook 'org-mode-hook 'my-activate-prettify-symbols-mode-org)
but it didn't work and I don't understand why.
Didn't find a solution in google either.
**edit new**
I found that org has built in functionality for that with org-toggle-pretty-entities, code bellow does the trick
(add-hook 'org-mode-hook 'org-toggle-pretty-entities)
Results are a bit different from auctex prettify-symbols-mode: it hides '\_' and '\^' I hope it's a matter of habit, and it as convenient to use as in auctex.
​
[random equation in org](https://preview.redd.it/02agu3hs76g81.png?width=289&format=png&auto=webp&s=e975be158be5612c772273412df4839d95abfa46)
​
[same equationi in auctex](https://preview.redd.it/c73aeh7v76g81.png?width=340&format=png&auto=webp&s=2c187db1d54a01bc4eb0ab59873814f5099f0bd9)
Now will try to import highlighting syntax from auctex.
**edit old**
I figured out what was wrong, should've used
(setq prettify-symbols-alist
(copy-list my-org-tex-prettify-list)
instead of
(setq prettify-symbols-alist 'my-org-tex-prettify-list)
Results aren't what I expected.
​
[random formula](https://preview.redd.it/4dbtdzkz76g81.png?width=428&format=png&auto=webp&s=c4d3ffb18bb5ada372830bdebab781b1f7de603c)
It's code with prettify-symbols-mode. It brakes with underscore '\_', so it's not shows indexes correctly and previous symbol.
https://preview.redd.it/q146jss286g81.png?width=372&format=png&auto=webp&s=4e2600caec934b051cc0eae15c2146b8eca019b0
This is code without prettify-symbols-mode.
https://preview.redd.it/qy9u2bu786g81.png?width=502&format=png&auto=webp&s=5c71a2ca375e3432156aefc53509b3ef7fd13cea
ypote · 2022-02-06 07:40
Screenshot to see the results?
Kugcro · 2022-02-06 08:13
Thank you, it didn't appear to me that it can be interesting to see, now I added screenshots.
_viz_ · 2022-02-08 13:57
I share your sentiment regarding the org prettify feature. It makes
editing really annoying and leaving it turned off becomes inconvenient
once you are used to the fancy display. So I do the following two
things:
a. Use prettify-symbols-mode to show org entities as the unicode
characters.
(defvar vz/org-prettify-symbols nil
"Alist for `prettify-symbols-mode'.")
(defun vz/org-prettify--set-prettify-symbols-alist ()
(dolist (entity (append org-entities-user org-entities))
(when (listp entity) ; `org-entities' has strings too
(when-let* ((match-for (car entity))
(replace-with (car (last entity)))
(_ (length= replace-with 1)))
(add-to-list 'vz/org-prettify-symbols
(cons (concat "\\" match-for) replace-with))))))
(vz/org-prettify--set-prettify-symbols-alist)
(defun vz/org-prettify--predicate (_start end _match)
;; There's no need the check the character before the entity match
;; since all of them start with \. The characters that are
;; acceptable after the match are mathematical operators and some
;; special characters.
(seq-contains-p '(?\C-j ?} ?{ ?\\ ?_ ?- ?+ ?^ ?\( ?\) ?$ ? ?/ ?| ?. ?, ?\;)
(char-after end)))
(define-minor-mode vz/org-prettify-mode
"Use `prettify-symbols-mode' to prettify org entities."
:lighter " ℘"
(if vz/org-prettify-mode
(progn
(setq-local prettify-symbols-alist vz/org-prettify-symbols
prettify-symbols-unprettify-at-point 'right-edge
prettify-symbols-compose-predicate #'vz/org-prettify--predicate)
(prettify-symbols-mode 1))
(setq-local prettify-symbols-alist nil
prettify-symbols-unprettify-at-point nil
prettify-symbols-compose-predicate #'prettify-symbols-default-compose-p)
(prettify-symbols-mode -1)))
(defvar vz/org-startup-prettified nil
"Prettify org entites when non-nil.")
(add-to-list 'org-startup-options '("prettify" vz/org-startup-prettified t))
b. Advise org-raise-scripts to not hide {} in sub-/super-script
markers.
(defun vz/org-raise-scripts (limit)
"Differences from `org-raise-scripts' are:
· It doesn't actually hide the markup used for super and subscript.
· It uses a custom face to highlight the markup---vz/org-script-markers.
· It doesn't require `org-pretty-entities' to be t."
(when (and org-pretty-entities-include-sub-superscripts
(re-search-forward
(if (eq org-use-sub-superscripts t)
org-match-substring-regexp
org-match-substring-with-braces-regexp)
limit t))
(let* ((pos (point)) table-p comment-p
(mpos (match-beginning 3))
(emph-p (get-text-property mpos 'org-emphasis))
(link-p (get-text-property mpos 'mouse-face))
(keyw-p (eq 'org-special-keyword (get-text-property mpos 'face))))
(goto-char (point-at-bol))
(setq table-p (looking-at-p org-table-dataline-regexp)
comment-p (looking-at-p "^[ \t]*#[ +]"))
(goto-char pos)
;; Handle a_b^c
(when (member (char-after) '(?_ ?^)) (goto-char (1- pos)))
(unless (or comment-p emph-p link-p keyw-p)
(put-text-property (match-beginning 3) (match-end 0)
'display
(if (equal (char-after (match-beginning 2)) ?^)
(nth 3 org-script-display) ;; (nth (if table-p 3 1) org-script-display)
(nth 2 org-script-display) ;; (nth (if table-p 2 0) org-script-display)
))
(put-text-property (match-beginning 2) (match-end 2)
'face 'vz/org-script-markers)
(when (and (eq (char-after (match-beginning 3)) ?{)
(eq (char-before (match-end 3)) ?}))
(put-text-property (match-beginning 3) (1+ (match-beginning 3))
'face 'vz/org-script-markers)
(put-text-property (1- (match-end 3)) (match-end 3)
'face 'vz/org-script-markers)))
t)))
(advice-add 'org-raise-scripts :override
#'vz/org-raise-scripts)
Kugcro · 2022-02-08 18:31
Wow! Thanks, I will investigate in this, looks like it really what I
wanted to do.
Kugcro · 2022-02-14 09:55
Can't run it, I've got an error message:
Debugger entered--Lisp error: (void-function length=).
Was trying to write length= function:
(defun length= (a b)
"compare length of objects"
(eq (length a) (length b)) )
and got this error:
Debugger entered--Lisp error: (wrong-type-argument sequencep 1) length(1) (eq (length a) (length b))
Can you explain where can I get "length=" function, or what I'm doing wrong?
_viz_ · 2022-02-15 02:43
length= was added in Emacs 28 so you should define it only on Emacs<28. B should be an integer, not a sequence. So, (= (length a) b).
It looks I didnt copy the face definition of vz/org-script-markers so create that.
Kugcro · 2022-02-15 11:52
Thank you! It worked! You really saved me a lot of time browsing and trying to figuring it out on my own.
For other people, who might run in the same problem, I placed before your code:
(defun length= (a b)
"compare length of object a with integer b"
(eq (length a) b)
)
and after it:
(add-hook 'org-mode-hook 'vz/org-prettify-mode)