emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Bug: Can't set background color of latex fragment
@ 2021-04-07 19:38 Sébastien Miquel
  2021-04-10 22:27 ` Roshan Shariff
  0 siblings, 1 reply; 6+ messages in thread
From: Sébastien Miquel @ 2021-04-07 19:38 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: roshan.shariff


To reproduce with `emacs -Q` :
  - Open an org buffer
  - Call ~(setq org-format-latex-options '(:foreground default
    :background "Black" :matchers ("$")))~
  - Call =C-c C-x C-l= (org-latex-preview) on a latex fragment such as
    $abc$

This bug was introduced by the commit 2f9e1569f which adds the option
`-bg Transparent` to the arguments of `dvipng`. According to its
manual, this option should be ignored if a background is already set,
but it doesn't seem to be. Perhaps org should set it differently.

--
Sébastien Miquel


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Bug: Can't set background color of latex fragment
  2021-04-07 19:38 Bug: Can't set background color of latex fragment Sébastien Miquel
@ 2021-04-10 22:27 ` Roshan Shariff
  2021-05-19  6:30   ` Sébastien Miquel
  0 siblings, 1 reply; 6+ messages in thread
From: Roshan Shariff @ 2021-04-10 22:27 UTC (permalink / raw)
  To: sebastien.miquel; +Cc: emacs-orgmode

I can confirm this bug with dvipng --- with the "-bg Transparent"
option, dvipng ignores the background color from the input tex file,
whereas without that option it always produces an opaque background.
There's currently no way to dynamically change command line
parameters, so I'm not sure how to solve this problem while supporting
both use cases.

On Wed, Apr 7, 2021 at 1:38 PM Sébastien Miquel
<sebastien.miquel@posteo.eu> wrote:
>
>
> To reproduce with `emacs -Q` :
>   - Open an org buffer
>   - Call ~(setq org-format-latex-options '(:foreground default
>     :background "Black" :matchers ("$")))~
>   - Call =C-c C-x C-l= (org-latex-preview) on a latex fragment such as
>     $abc$
>
> This bug was introduced by the commit 2f9e1569f which adds the option
> `-bg Transparent` to the arguments of `dvipng`. According to its
> manual, this option should be ignored if a background is already set,
> but it doesn't seem to be. Perhaps org should set it differently.
>
> --
> Sébastien Miquel


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Bug: Can't set background color of latex fragment
  2021-04-10 22:27 ` Roshan Shariff
@ 2021-05-19  6:30   ` Sébastien Miquel
  2021-05-20  0:30     ` Roshan Shariff
  0 siblings, 1 reply; 6+ messages in thread
From: Sébastien Miquel @ 2021-05-19  6:30 UTC (permalink / raw)
  To: Roshan Shariff; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1501 bytes --]

Hi Roshan,

Roshan Shariff writes:
> I can confirm this bug with dvipng --- with the "-bg Transparent"
> option, dvipng ignores the background color from the input tex file,
> whereas without that option it always produces an opaque background.
> There's currently no way to dynamically change command line
> parameters, so I'm not sure how to solve this problem while supporting
> both use cases.

I asked about this behaviour on the dvipng mailing list, and the
maintainer doesn't consider it a bug, see
https://lists.nongnu.org/archive/html/dvipng/2021-05/msg00002.html.

Can you explain the use for a `Transparent` background ? Transparent
images are poorly supported in emacs, all it does is render it with
the background color of the default face -- which may not be the
expected result.

Regards,

-- 
Sébastien Miquel


> On Wed, Apr 7, 2021 at 1:38 PM Sébastien Miquel
> <sebastien.miquel@posteo.eu>  wrote:
>> To reproduce with `emacs -Q` :
>>    - Open an org buffer
>>    - Call ~(setq org-format-latex-options '(:foreground default
>>      :background "Black" :matchers ("$")))~
>>    - Call =C-c C-x C-l= (org-latex-preview) on a latex fragment such as
>>      $abc$
>>
>> This bug was introduced by the commit 2f9e1569f which adds the option
>> `-bg Transparent` to the arguments of `dvipng`. According to its
>> manual, this option should be ignored if a background is already set,
>> but it doesn't seem to be. Perhaps org should set it differently.
>>
>> --
>> Sébastien Miquel



[-- Attachment #2: Type: text/html, Size: 2914 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Bug: Can't set background color of latex fragment
  2021-05-19  6:30   ` Sébastien Miquel
@ 2021-05-20  0:30     ` Roshan Shariff
  2021-05-23 21:01       ` Bug: [PATCH] " Sébastien Miquel
  0 siblings, 1 reply; 6+ messages in thread
From: Roshan Shariff @ 2021-05-20  0:30 UTC (permalink / raw)
  To: sebastien.miquel; +Cc: emacs-orgmode

Hi Sébastien,

I originally made my patch because otherwise adding '(:background
"Transparent") to org-format-latex-options always resulted in a white
background (\pagecolor{white} would be forcefully added to the
generated LaTeX). Then I found that dvipng still produced a white
background even without a \pagecolor{...} directive, so I added the
-bg Transparent option. This is unlike dvisvgm, which produces an
opaque background when \pagecolor{...} is present and a transparent
background otherwise.

I didn't realize that dvipng -bg Transparent would completely ignore
the \pagecolor{...} command even if it was present. Perhaps the best
solution that allows the background color to be customized with dvipng
is to remove "-bg Transparent" from the default dvipng command line.
For people who need transparency, perhaps another "dvipng
(transparent)" option can be created, or they can use dvisvgm. This is
useful for HTML export, for example.

That said, I haven't had any issues with Emacs rendering transparent
PNGs (version 27.2 on Linux and macOS). It uses the background color
of whichever face is applied to LaTeX fragments (which seems to be
org-block, along with font-latex-verbatim-face for inline formulae). I
personally find it convenient to customize these faces as needed.

Regards,
Roshan

On Wed, May 19, 2021 at 12:30 AM Sébastien Miquel
<sebastien.miquel@posteo.eu> wrote:
>
> Hi Roshan,
>
> Roshan Shariff writes:
>
> I can confirm this bug with dvipng --- with the "-bg Transparent"
> option, dvipng ignores the background color from the input tex file,
> whereas without that option it always produces an opaque background.
> There's currently no way to dynamically change command line
> parameters, so I'm not sure how to solve this problem while supporting
> both use cases.
>
>
> I asked about this behaviour on the dvipng mailing list, and the
> maintainer doesn't consider it a bug, see
> https://lists.nongnu.org/archive/html/dvipng/2021-05/msg00002.html.
>
> Can you explain the use for a `Transparent` background ? Transparent
> images are poorly supported in emacs, all it does is render it with
> the background color of the default face -- which may not be the
> expected result.
>
> Regards,
>
> --
> Sébastien Miquel
>
>
> On Wed, Apr 7, 2021 at 1:38 PM Sébastien Miquel
> <sebastien.miquel@posteo.eu> wrote:
>
> To reproduce with `emacs -Q` :
>   - Open an org buffer
>   - Call ~(setq org-format-latex-options '(:foreground default
>     :background "Black" :matchers ("$")))~
>   - Call =C-c C-x C-l= (org-latex-preview) on a latex fragment such as
>     $abc$
>
> This bug was introduced by the commit 2f9e1569f which adds the option
> `-bg Transparent` to the arguments of `dvipng`. According to its
> manual, this option should be ignored if a background is already set,
> but it doesn't seem to be. Perhaps org should set it differently.
>
> --
> Sébastien Miquel
>
>
>


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Bug: [PATCH] Can't set background color of latex fragment
  2021-05-20  0:30     ` Roshan Shariff
@ 2021-05-23 21:01       ` Sébastien Miquel
  2021-08-29  7:22         ` Sébastien Miquel
  0 siblings, 1 reply; 6+ messages in thread
From: Sébastien Miquel @ 2021-05-23 21:01 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: Roshan Shariff

[-- Attachment #1: Type: text/plain, Size: 168 bytes --]

Hi,

Here's a patch that fixes this bug by calling `dvipng' with the `-bg
Transparent' argument only when no background color is set.

Regards,

-- 
Sébastien Miquel


[-- Attachment #2: 0001-org.el-org-create-formula-image-Fix-ignored-backgrou.patch --]
[-- Type: text/x-patch, Size: 2648 bytes --]

From 5872fc3143162fbda11cf2aa5a3798567664be99 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Miquel?= <sebastien.miquel@posteo.eu>
Date: Sun, 23 May 2021 22:07:25 +0200
Subject: [PATCH] org.el (org-create-formula-image): Fix ignored background
 color

* lisp/org.el (org-preview-latex-process-alist): add a `:transparent-image-converter'
property for `dvipng'.
(org-create-formula-image): If available, use
`:transparent-image-converter' when no background color is set.
---
 lisp/org.el | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index 1bd9e02eb..d544e62fb 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -3319,7 +3319,9 @@ All available processes and theirs documents can be found in
      :image-output-type "png"
      :image-size-adjust (1.0 . 1.0)
      :latex-compiler ("latex -interaction nonstopmode -output-directory %o %f")
-     :image-converter ("dvipng -D %D -T tight -bg Transparent -o %O %f"))
+     :image-converter ("dvipng -D %D -T tight -o %O %f")
+     :transparent-image-converter
+     ("dvipng -D %D -T tight -bg Transparent -o %O %f"))
     (dvisvgm
      :programs ("latex" "dvisvgm")
      :description "dvi > svg"
@@ -3374,6 +3376,9 @@ PROPERTIES accepts the following attributes:
                       given to the shell and supports any of the following
                       place-holders defined below.

+If set, :transparent-image-converter is used instead of :image-converter to
+convert an image when the background color is nil or \"Transparent\".
+
 Place-holders used by `:image-converter' and `:latex-compiler':

   %f    input file name
@@ -16288,7 +16293,6 @@ a HTML file."
 	       org-format-latex-header
 	       'snippet)))
 	 (latex-compiler (plist-get processing-info :latex-compiler))
-	 (image-converter (plist-get processing-info :image-converter))
 	 (tmpdir temporary-file-directory)
 	 (texfilebase (make-temp-name
 		       (expand-file-name "orgtex" tmpdir)))
@@ -16302,7 +16306,11 @@ a HTML file."
 		 "Black"))
 	 (bg (or (plist-get options (if buffer :background :html-background))
 		 "Transparent"))
-	 (log-buf (get-buffer-create "*Org Preview LaTeX Output*"))
+	 (image-converter
+          (or (and (string= bg "Transparent")
+                   (plist-get processing-info :transparent-image-converter))
+              (plist-get processing-info :image-converter)))
+         (log-buf (get-buffer-create "*Org Preview LaTeX Output*"))
 	 (resize-mini-windows nil)) ;Fix Emacs flicker when creating image.
     (dolist (program programs)
       (org-check-external-command program error-message))
-- 
2.31.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: Bug: [PATCH] Can't set background color of latex fragment
  2021-05-23 21:01       ` Bug: [PATCH] " Sébastien Miquel
@ 2021-08-29  7:22         ` Sébastien Miquel
  0 siblings, 0 replies; 6+ messages in thread
From: Sébastien Miquel @ 2021-08-29  7:22 UTC (permalink / raw)
  To: emacs-orgmode

Sébastien Miquel writes:
> Here's a patch that fixes this bug by calling `dvipng' with the `-bg
> Transparent' argument only when no background color is set.

Setting X-Woof-Bug and X-Woof-Patch, as this doesn't show on 
https://updates.orgmode.org/

-- 
Sébastien Miquel



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-08-29  7:23 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-07 19:38 Bug: Can't set background color of latex fragment Sébastien Miquel
2021-04-10 22:27 ` Roshan Shariff
2021-05-19  6:30   ` Sébastien Miquel
2021-05-20  0:30     ` Roshan Shariff
2021-05-23 21:01       ` Bug: [PATCH] " Sébastien Miquel
2021-08-29  7:22         ` Sébastien Miquel

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