From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?utf-8?Q?Abd=C3=B3?= Roig-Maranges Subject: Make latex preview formulas the same color as text face Date: Fri, 03 Aug 2012 19:20:51 +0200 Message-ID: <87zk6b99jg.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([208.118.235.92]:33397) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SxLYW-0002pR-EE for emacs-orgmode@gnu.org; Fri, 03 Aug 2012 13:20:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SxLYV-0005aE-0y for emacs-orgmode@gnu.org; Fri, 03 Aug 2012 13:20:56 -0400 Received: from mail-wg0-f49.google.com ([74.125.82.49]:52656) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SxLYU-0005a3-NL for emacs-orgmode@gnu.org; Fri, 03 Aug 2012 13:20:54 -0400 Received: by wgbez12 with SMTP id ez12so604928wgb.30 for ; Fri, 03 Aug 2012 10:20:54 -0700 (PDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi I attach a patch with an enhancement to the latex preview code. When :foreground or :background colors are set to auto, it choses the appropriate color according to the properties of the actual text face. Abd=C3=B3 Roig. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=color-latex-preview.patch Content-Description: the patch >From f6ede272f226fbeb2cf43fb747ae75be911ad3ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abd=C3=B3=20Roig-Maranges?= Date: Thu, 2 Aug 2012 00:50:24 +0200 Subject: [PATCH] Option to get latex preview in the same color as text face * org.el (org-format-latex-options): added `auto' to docstring. (org-format-latex): Get face colors at point and put them inside opt. (org-create-formula-image-with-dvipng): Corrected bug when colors are not `default'. (org-create-formula-image-with-imagemagick): Corrected bug in the handling of "Transparent" bg color. (org-dvipng-color-format): Same as org-latex-color-format for dvipng-style color specification. If `auto' is used for the :foreground or :background value in org-format-latex-options, the the appropriate color is chosen from the face in which the formula is displayed. --- lisp/org.el | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index f49a9ac..2cc137d 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -3346,8 +3346,10 @@ points to a file, `org-agenda-diary-entry' will be used instead." This is a property list with the following properties: :foreground the foreground color for images embedded in Emacs, e.g. \"Black\". `default' means use the foreground of the default face. + `auto' means use the foreground from the text face. :background the background color, or \"Transparent\". `default' means use the background of the default face. + `auto' means use the background from the text face. :scale a scaling factor for the size of the images, to get more pixels :html-foreground, :html-background, :html-scale the same numbers for HTML export. @@ -17168,6 +17170,7 @@ Some of the options can be changed using the variable (absprefix (expand-file-name prefix dir)) (todir (file-name-directory absprefix)) (opt org-format-latex-options) + (optnew org-format-latex-options) (matchers (plist-get opt :matchers)) (re-list org-latex-regexps) (org-format-latex-header-extra @@ -17213,14 +17216,27 @@ Some of the options can be changed using the variable (setq txt (match-string n) beg (match-beginning n) end (match-end n) cnt (1+ cnt)) - (let (print-length print-level) ; make sure full list is printed + (let ((face (face-at-point)) + (fg (plist-get opt :foreground)) + (bg (plist-get opt :background)) + print-length print-level) ; make sure full list is printed + (when forbuffer + ; Get the colors from the face at point + (goto-char beg) + (when (eq fg 'auto) + (setq fg (face-attribute face :foreground nil 'default))) + (when (eq bg 'auto) + (setq bg (face-attribute face :background nil 'default))) + (setq optnew (copy-sequence opt)) + (plist-put optnew :foreground fg) + (plist-put optnew :background bg)) (setq hash (sha1 (prin1-to-string (list org-format-latex-header org-format-latex-header-extra org-export-latex-default-packages-alist org-export-latex-packages-alist org-format-latex-options - forbuffer txt))) + forbuffer txt fg bg))) linkfile (format "%s_%s.png" prefix hash) movefile (format "%s_%s.png" absprefix hash))) (setq link (concat block "[[file:" linkfile "]]" block)) @@ -17239,7 +17255,7 @@ Some of the options can be changed using the variable (setq executables-checked t)) (unless (file-exists-p movefile) (org-create-formula-image-with-dvipng - txt movefile opt forbuffer))) + txt movefile optnew forbuffer))) ((eq processing-type 'imagemagick) (unless executables-checked (org-check-external-command @@ -17247,7 +17263,7 @@ Some of the options can be changed using the variable (setq executables-checked t)) (unless (file-exists-p movefile) (org-create-formula-image-with-imagemagick - txt movefile opt forbuffer)))) + txt movefile optnew forbuffer)))) (if overlays (progn (mapc (lambda (o) @@ -17403,8 +17419,10 @@ inspection." "Black")) (bg (or (plist-get options (if buffer :background :html-background)) "Transparent"))) - (if (eq fg 'default) (setq fg (org-dvipng-color :foreground))) - (if (eq bg 'default) (setq bg (org-dvipng-color :background))) + (if (eq fg 'default) (setq fg (org-dvipng-color :foreground)) + (setq fg (org-dvipng-color-format fg))) + (if (eq bg 'default) (setq bg (org-dvipng-color :background)) + (setq bg (org-dvipng-color-format bg))) (with-temp-file texfile (insert (org-splice-latex-header org-format-latex-header @@ -17475,7 +17493,7 @@ inspection." (setq fg (org-latex-color-format fg))) (if (eq bg 'default) (setq bg (org-latex-color :background)) (setq bg (org-latex-color-format - (if (string= bg "Transparent")(setq bg "white"))))) + (if (string= bg "Transparent") "white" bg)))) (with-temp-file texfile (insert (org-splice-latex-header org-format-latex-header @@ -17626,6 +17644,12 @@ SNIPPETS-P indicates if this is run to create snippet images for HTML." ((eq attr :background) 'background)))) (color-values (face-attribute 'default attr nil)))))) +(defun org-dvipng-color-format (color-name) + "Convert COLOR-NAME to a RGB color value for dvipng." + (apply 'format "rgb %s %s %s" + (mapcar 'org-normalize-color + (color-values color-name)))) + (defun org-latex-color (attr) "Return a RGB color for the LaTeX color package." (apply 'format "%s,%s,%s" -- 1.7.11.3 --=-=-=--