Re: [O] Make latex preview formulas the same color as text face

2012-08-03 Thread Bastien
Hi Abdó,

Abdó Roig-Maranges  writes:

> 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.

The patch is good -- but I cannot accept until you sign the FSF papers.

Please fill this form and send it to ass...@gnu.org if you want to sign
the FSF papers:

  
http://orgmode.org/w/?p=org-mode.git;a=blob_plain;f=request-assign-future.txt;hb=HEAD

If you don't plan to sign them, please don't send patches as it will
prevent me from applying the associated changes.  In this case, just 
give directions/suggestions and I'll make the change.

Thanks for your understanding!

-- 
 Bastien



[O] Make latex preview formulas the same color as text face

2012-08-03 Thread Abdó Roig-Maranges

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ó Roig.

>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-la