Discussion:
`-bg Transparent` option isn't ignored when background color is set in dvi file
Sébastien Miquel
2021-05-17 17:41:11 UTC
Permalink
Hi,

The manual says that the `-bg` option is ignored if a background color
is set in the DVI, however this doesn't seem to be the case if `-bg
Transparent` is used.

To reproduce, I used a tex file with the following content.
#+BEGIN_SRC latex
\documentclass{article}
\usepackage{xcolor}
\title{Text}
\begin{document}
\maketitle
\definecolor{bg}{rgb}{0.858, 0.188, 0.478} % magenta
\pagecolor{bg}
\end{document}
#+END_SRC

Then compile it using
#+BEGIN_SRC bash
latex -interaction nonstopmode test_latex_bg.tex
dvipng -bg Transparent -o test.png test_latex_bg.dvi
#+END_SRC

The resulting png is Transparent instead of magenta. If I specify `-bg
Blue` instead, the background is set to magenta, as expected.

Is this behaviour intended ?

Regards,
--
Sébastien Miquel
Jan-Åke Larsson
2021-05-17 18:53:57 UTC
Permalink
Hi,

That was intended, yes, the manual should probably have said "The
background color given will be ignored if there is a background color
\special in the DVI."

"Transparent" doesn't change the background color, it enables the alpha
channel.

The actual background color (visible, say, in a reader without the
alpha channel) is controlled by the color spec, and overridden by a
color \special.

Did you want this to work differently, or was the problem that you were
surprised by the behavior?

Best
Jan-Åke
Post by Sébastien Miquel
Hi,
The manual says that the `-bg` option is ignored if a background color
is set in the DVI, however this doesn't seem to be the case if `-bg
Transparent` is used.
To reproduce, I used a tex file with the following content.
#+BEGIN_SRC latex
\documentclass{article}
\usepackage{xcolor}
\title{Text}
\begin{document}
\maketitle
\definecolor{bg}{rgb}{0.858, 0.188, 0.478} % magenta
\pagecolor{bg}
\end{document}
#+END_SRC
Then compile it using
#+BEGIN_SRC bash
latex -interaction nonstopmode test_latex_bg.tex
dvipng -bg Transparent -o test.png test_latex_bg.dvi
#+END_SRC
The resulting png is Transparent instead of magenta. If I specify `-bg
Blue` instead, the background is set to magenta, as expected.
Is this behaviour intended ?
Regards,
Sébastien Miquel
2021-05-17 21:30:25 UTC
Permalink
Post by Jan-Åke Larsson
That was intended, yes, the manual should probably have said "The
background color given will be ignored if there is a background color
\special in the DVI."
"Transparent" doesn't change the background color, it enables the
alpha channel.
The actual background color (visible, say, in a reader without the
alpha channel) is controlled by the color spec, and overridden by a
color \special.
Thank you for your reply and the explanation.
Post by Jan-Åke Larsson
Did you want this to work differently, or was the problem that you
were surprised by the behavior?
Some time ago, a change in org-mode (emacs package) introduced a bug
because this behavior was unexpected.

Org-mode uses latex > dvipng to generate images to be included in an
emacs buffer. If the user specifies a background color, it is set using
the latex commands, otherwise the image should be transparent.


I assume there's no way to get dvipng to behave like this ?

Regards,
--
Sébastien Miquel
Jan-Åke Larsson
2021-05-17 21:55:42 UTC
Permalink
Post by Sébastien Miquel
Post by Jan-Åke Larsson
That was intended, yes, the manual should probably have said "The
background color given will be ignored if there is a background
color \special in the DVI."
"Transparent" doesn't change the background color, it enables the
alpha channel.
The actual background color (visible, say, in a reader without the
alpha channel) is controlled by the color spec, and overridden by a
color \special.
Thank you for your reply and the explanation.
Post by Jan-Åke Larsson
Did you want this to work differently, or was the problem that you
were surprised by the behavior?
Some time ago, a change in org-mode (emacs package) introduced a bug
because this behavior was unexpected.
Org-mode uses latex > dvipng to generate images to be included in an
emacs buffer. If the user specifies a background color, it is set
using the latex commands, otherwise the image should be transparent.
Dvipng is written for preview-latex for exactly this purpose:
generating images for inclusion in emacs.Preview-latex is an add-on in
AUCTeX
Post by Sébastien Miquel
I assume there's no way to get dvipng to behave like this ?
If you want to
- adapt to the background color in emacs by using a transparent
background,
- except when the user sets the background color explicitly in the
latex source,

I suggest you instead
- use the known emacs background color in the dvipng call.
- Then the explicit \special will override the command-line
specification.

Transparent background was intended for the math on the web, where math
authors might have little control over the background.
Nowadays I'd recommend Mathjax for that purpose.

Best
Jan-Åke
Sébastien Miquel
2021-05-18 06:00:57 UTC
Permalink
Dvipng is written for preview-latex for exactly this purpose: generating images for inclusion in emacs.
Ah, I did not know that.
If you want to
- adapt to the background color in emacs by using a transparent
background,
- except when the user sets the background color explicitly in the
latex source,
I suggest you instead
- use the known emacs background color in the dvipng call.
- Then the explicit \special will override the command-line specification.
Transparent background was intended for the math on the web, where
math authors might have little control over the background.
Nowadays I'd recommend Mathjax for that purpose.
Yes, it used to work in a similar fashion.
I think the point of the change was that, despite emacs' poor support
for transparent png, you could change your emacs theme and reload the
buffer to get the right background color, instead of regenerating all
images.

Regards,
--
Sébastien Miquel
Loading...