Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different behavior for .mps and .eps #928

Open
rolfn opened this issue Sep 30, 2022 · 23 comments
Open

Different behavior for .mps and .eps #928

rolfn opened this issue Sep 30, 2022 · 23 comments

Comments

@rolfn
Copy link

rolfn commented Sep 30, 2022

Brief outline of the bug

The following example document loads two identical graphics files as .mps and .eps via \includegraphics. Both are valid eps files. I get different results depending on the TeX compiler:

  1. pdflatex & lualatex: first square is red, second square is black

  2. xelatex: Both squares are black

  3. latex+dvips+ps2pdf: Both squares are black

From the user's point of view, it seems advantageous to me if graphics that do not themselves cause color settings can be colored from the outside. In any case, different behavior is unfavorable.

Minimal example showing the bug

\RequirePackage{latexbug}       % <--should be always the first line (see CONTRIBUTING)!
\begin{filecontents*}[force]{foo.mps}
%!PS-Adobe-3.0 EPSF-3.0
%%BoundingBox: 0 0 1000 1000 
%%Page: 1 1
newpath 0 0 moveto
1000 0 lineto
1000 1000 lineto
0 1000 lineto
closepath fill
showpage
%%EOF
\end{filecontents*}
\begin{filecontents*}[force]{foo.eps}
%!PS-Adobe-3.0 EPSF-3.0
%%BoundingBox: 0 0 1000 1000 
%%Page: 1 1
newpath 0 0 moveto
1000 0 lineto
1000 1000 lineto
0 1000 lineto
closepath fill
showpage
%%EOF
\end{filecontents*}
\documentclass{article}
\usepackage{graphicx,xcolor}    
\begin{document}
  \color{red!70}
  \rule{10mm}{30mm}\hfill \includegraphics[height=30mm]{foo.mps} \hfill 
  \includegraphics[height=30mm]{foo.eps} \hfill \rule{10mm}{30mm}
\end{document}

grf-test2.log

@daleif
Copy link
Contributor

daleif commented Sep 30, 2022

Perhaps also mention https://tex.stackexchange.com/questions/659801/different-behavior-for-mps-and-eps, where Ulrike already gave the explanation for the difference.

Personally I can see the usefulness in both (either no effect from color or getting the effect from coloring)

@rolfn
Copy link
Author

rolfn commented Sep 30, 2022

Yes, Ulrike describes the cause correctly. However, the problem remains that different engines deliver different results.

@u-fischer
Copy link
Member

u-fischer commented Sep 30, 2022

Well at first handling of graphics is something that is engine specific. If you want the best result for more than one engine you often have to provide more than one version of the same graphic.

Apart from this I don't see what latex or graphics-def can do here. We can not add a \color{black} to \includegraphics or the the mps code of pdftex/luatex and so destroy their ability to change color only to get them in line with the other engines.

Imho it could only work if you find a ghostscript option (or convince them to add one) for the pdfwriter device so that it doesn't add the black. Then epstopdf could perhaps be changed.

@hvoss49
Copy link

hvoss49 commented Sep 30, 2022

xelatex sets also the default color to 0 g

@stale
Copy link

stale bot commented Jan 7, 2023

This issue has been automatically marked as stale because it has not had recent activity.

@josephwright
Copy link
Member

@FrankMittelbach suggests using a key to define the behaviour: I might look at l3graphics first for testing

@josephwright josephwright added this to the Release 2024 Spring milestone Nov 7, 2023
@josephwright
Copy link
Member

A key here would be able to enforce the standard colour as black across all engines: I guess what I need is a suggestion on a key name. I suppose enforce-black or ensure-black might be the most obvious: thoughts?

@josephwright
Copy link
Member

Thinking a bit more, I guess we should be talking about normalcolor here, so just normalcolor, ensure-normalcolor, apply-normalcolor, ...?

@u-fischer
Copy link
Member

normalcolor sounds imho wrong, it gives the impression the color would change if you change the normal/default color. ensure-black doesn't sounds right either, as you would get a colored and not a black square if the eps contains its own color commands.

Perhaps init-black? Or perhaps simply initcolor=color with the default value (and only value in xetex/dvips) black? This would be flexible in case some future development actually allows to change the color with xetex and/or dvips to.

Btw: you have the same problem with xform/xobjects: pdflatex and lualatex allow color injection but not the other backend.

@FrankMittelbach
Copy link
Member

I guess it should produce "normalcolor" by default but is there a usecase that it should be anyhting other than that, ie a different color? If so the key could by default use normalcolor but could explicitly set via key=color to something else?

So I would not put "normal" in the key name but perhaps initcolor or init-color. Just see that Ulrike has the same suggestion

@josephwright
Copy link
Member

OK, so we think init-color which starts with an empty value? So no value means 'whatever is prevailing', a color (expression?) means you get the colour that it defines. Documentation then deals with the fact this is only applicable (at present) in pdfTeX/LuaTeX PDF mode? I think we add the key at the same time to graphics and l3graphics.

@u-fischer
Copy link
Member

I would say

  • key is not used or initcolor=false: behaviour as now (so you get color injection with pdflatex/lualatex and black with xetex)
  • initcolor is doing initcolor=black
  • initcolor=red sets this color and we document that it doesn't work with xetex etc.

(and if people really define a color with the name false they can probably use initcolor=false!)

@FrankMittelbach
Copy link
Member

sounds good, except that I wouldn't bother with false! but just say if you define it you get it. And perhaps we should also allow initcolor=true as the long form for initicolor. Question: is it best to make the default explicitly black or should it be explicitly \normalcolor?

@u-fischer
Copy link
Member

well \default@color sounds imho more logical and consistent. But the issue started with different behavior is unfavorable. So the question is if we accept that initcolor can give different behaviour with the engines if the default color is not black and that users who want to be sure to get uniform behaviour across engines would have to use initcolor=black explicitly (and there is also the question of the color model: we then probably should ensure that black then always use 0 g)

@josephwright
Copy link
Member

and there is also the question of the color model: we then probably should ensure that black then always use 0 g

Well if the user is forcing CMYK they won't, but otherwise the standard setting for black is using the gray model.

@josephwright
Copy link
Member

  • key is not used or initcolor=false: behaviour as now (so you get color injection with pdflatex/lualatex and black with xetex)

Keys always have a value, even if it's empty ... I guess you mean that we initialise with an empty stored value, and that we set the default to black so initcolor = black and initcolor are the same.

(I favour init-color over initcolor, but I can live with either)

@josephwright
Copy link
Member

well \default@color sounds imho more logical and consistent. But the issue started with different behavior is unfavorable.

Well we can only fix stuff to some extent, and we likely don't want to break existing usage. (Perhaps \DocumentMetadata could set the key always-active, which would then given consistent behaviour and make colouring images opt-in.)

@Skillmon
Copy link
Contributor

Skillmon commented Nov 8, 2023

Just to throw another hat in the ring: fallback-color

@FrankMittelbach
Copy link
Member

that doesn't seem to fit the bill if I understand the problem. It is not a fallback color, it is a color that is explicitly set at the beginning of the graphic, for some workflow paths it is set unconditionally (without any key) and for others it is not set at all and with this key we can force pdftex and luatex to also explicitly set a color at this point

@Skillmon
Copy link
Contributor

Skillmon commented Nov 8, 2023

Well, it's a fallback in the sense that it is the colour used if the graphic file doesn't explicitly set a colour.

@FrankMittelbach
Copy link
Member

true enough as an interpretation, but when I read fallback I would think more about something is failing and then I get a fallbackcolor but not expect that "fallback color" to apply if I explicitly set "red" on the outside, whereas with init-color I can immediately see why my "red" does no longer apply.

Copy link

This issue has been automatically marked as stale because it has not had recent activity.

Copy link

github-actions bot commented Aug 5, 2024

This issue has been automatically marked as stale because it has not had recent activity.

@github-actions github-actions bot added the stale label Aug 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: In progress
Development

No branches or pull requests

7 participants