From 40d8b3acea01f57969cd6a0b79a8a310c45b5d98 Mon Sep 17 00:00:00 2001 From: TEC Date: Fri, 5 Jan 2024 15:23:59 +0800 Subject: [PATCH] org-latex-preview: Simplify color formatting * lisp/org-latex-preview.el (org-latex-preview--format-color, org-latex-preview--normalize-color): Use three decimal places, and remove the now-obsolete `org-latex-preview--normalize-color'. * lisp/org-compat.el (org-normalize-color): With the removal of the `org-latex-preview--normalize-color' alias, mark `org-normalize-color' as obsolete. --- lisp/org-compat.el | 8 ++++++-- lisp/org-latex-preview.el | 11 ++++------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lisp/org-compat.el b/lisp/org-compat.el index 4d9632035..eaa601ad8 100644 --- a/lisp/org-compat.el +++ b/lisp/org-compat.el @@ -704,8 +704,6 @@ This constant, for example, makes the below code not err: 'org-latex-color-format 'org-latex-preview--format-color "9.7") (define-obsolete-function-alias 'org-latex-color 'org-latex-preview--attr-color "9.7") -(define-obsolete-function-alias - 'org-normalize-color 'org-latex-preview--normalize-color "9.7") ;; MathML related functions from org-latex-preview.el (define-obsolete-variable-alias 'org-latex-to-mathml-jar-file 'org-mathml-converter-jar-file "9.7") @@ -760,6 +758,12 @@ This constant, for example, makes the below code not err: (make-obsolete 'org-dvipng-color-format "to be removed" "9.7") +;; FIXME: Unused; obsoleted; to be removed. +(defun org-normalize-color (value) + "Return string to be used as color value for an RGB component." + (format "%g" (/ value 65535.0))) +(make-obsolete 'org-normalize-color "to be removed" "9.7") + ;; FIXME: Unused; obsoleted; to be removed. (defcustom org-preview-latex-image-directory "ltximg/" "Path to store latex preview images. diff --git a/lisp/org-latex-preview.el b/lisp/org-latex-preview.el index 6b6349133..07d712bd2 100644 --- a/lisp/org-latex-preview.el +++ b/lisp/org-latex-preview.el @@ -2397,14 +2397,11 @@ used it can be worth storing the results to avoid re-computing.") "Convert COLOR-NAME to a RGB color value." (or (alist-get color-name org-latex-preview--format-color-cache nil nil #'equal) (cdar (push (cons color-name - (apply #'format "%s,%s,%s" - (mapcar 'org-latex-preview--normalize-color - (color-values color-name)))) + (apply #'format "%.3f,%.3f,%.3f" + (mapcar + (lambda (v) (/ v 65535.0)) + (color-values color-name)))) org-latex-preview--format-color-cache)))) -(defun org-latex-preview--normalize-color (value) - "Return string to be used as color value for an RGB component." - (format "%g" (/ value 65535.0))) - (provide 'org-latex-preview) ;;; org-latex-preview.el ends here