1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-01-30 04:10:54 -08:00

Improve prettification of (La)TeX symbols

* lisp/textmodes/tex-mode.el (tex--prettify-symbols-alist): Remove
entry for "\\newline", which resulted in an invisible display.
Prettify "\\ " with OPEN BOX instead of BOTTOM SQUARE BRACKET.
(tex--prettify-symbols-compose-p): Skip composition when the
control backslash is itself escaped (bug#78752).
This commit is contained in:
Paul Nelson 2025-07-14 17:31:36 +02:00 committed by Stefan Monnier
parent f01fc3d614
commit c8b6e90b4e

View file

@ -3369,7 +3369,6 @@ There might be text before point."
("\\neg" . )
("\\neq" . ?≠)
("\\nequiv" . ?≢)
("\\newline" . ?)
("\\nexists" . ?∄)
("\\ngeq" . ?≱)
("\\ngeqq" . ?≱)
@ -3840,32 +3839,38 @@ There might be text before point."
("\\S" . )
("\\Finv" . ?Ⅎ)
("\\Game" . ?⅁)
("\\ " . 9141) ; Literal ?⎵ breaks indentation
("\\ " . ?␣) ; Use ?␣ (OPEN BOX) and not ?⎵ (BOTTOM SQUARE BRACKET)
("\\lvert" . ?|)
("\\rvert" . ?|)
("\\lVert" . ?‖)
("\\rVert" . ?‖))
"A `prettify-symbols-alist' usable for (La)TeX modes.")
(defun tex--prettify-symbols-compose-p (_start end _match)
(or
;; If the matched symbol doesn't end in a word character, then we
;; simply allow composition. The symbol is probably something like
;; \|, \(, etc.
(not (eq ?w (char-syntax (char-before end))))
;; Else we look at what follows the match in order to decide.
(let* ((after-char (char-after end))
(after-syntax (char-syntax after-char)))
(not (or
;; Don't compose \alpha@foo.
(eq after-char ?@)
;; The \alpha in \alpha2 or \alpha-\beta may be composed but
;; of course \alphax may not.
(and (eq after-syntax ?w)
(not (memq after-char
'(?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9 ?+ ?- ?' ?\"))))
;; Don't compose inside verbatim blocks.
(eq 2 (nth 7 (syntax-ppss))))))))
(defun tex--prettify-symbols-compose-p (start end _match)
(if (save-excursion
(goto-char start)
;; Skip composition when the control backslash at START is
;; itself escaped, as in constructs like \"\\\\S\".
(not (zerop (mod (skip-chars-backward "\\\\") 2))))
nil
(or
;; If the matched symbol doesn't end in a word character, then we
;; simply allow composition. The symbol is probably something like
;; \|, \(, etc.
(not (eq ?w (char-syntax (char-before end))))
;; Else we look at what follows the match in order to decide.
(let* ((after-char (char-after end))
(after-syntax (char-syntax after-char)))
(not (or
;; Don't compose \alpha@foo.
(eq after-char ?@)
;; The \alpha in \alpha2 or \alpha-\beta may be composed but
;; of course \alphax may not.
(and (eq after-syntax ?w)
(not (memq after-char
'(?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9 ?+ ?- ?' ?\"))))
;; Don't compose inside verbatim blocks.
(eq 2 (nth 7 (syntax-ppss)))))))))
;;; Flymake support