* Make latex preview formulas the same color as text face
@ 2012-08-03 17:20 Abdó Roig-Maranges
2012-08-03 17:57 ` Bastien
0 siblings, 1 reply; 2+ messages in thread
From: Abdó Roig-Maranges @ 2012-08-03 17:20 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 233 bytes --]
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.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: the patch --]
[-- Type: text/x-patch, Size: 5669 bytes --]
From f6ede272f226fbeb2cf43fb747ae75be911ad3ce Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Abd=C3=B3=20Roig-Maranges?= <abdo.roig@gmail.com>
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: Make latex preview formulas the same color as text face
2012-08-03 17:20 Make latex preview formulas the same color as text face Abdó Roig-Maranges
@ 2012-08-03 17:57 ` Bastien
0 siblings, 0 replies; 2+ messages in thread
From: Bastien @ 2012-08-03 17:57 UTC (permalink / raw)
To: Abdó Roig-Maranges; +Cc: emacs-orgmode
Hi Abdó,
Abdó Roig-Maranges <abdo.roig@gmail.com> 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 assign@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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-08-03 17:57 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-03 17:20 Make latex preview formulas the same color as text face Abdó Roig-Maranges
2012-08-03 17:57 ` Bastien
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).