-
Notifications
You must be signed in to change notification settings - Fork 16
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
"current color" handling #204
Comments
Looks like the key question is, why
Sorry I'm tired to do further digging today. I find places where I have a feeling that |
Basically yes (I already investigated pgf-tikz a lot too), but I didn't want to do all at once. If you see missing interface, then please report them to xcolor. (Side remark: l3color doesn't know the concept of global colors, and that could be a problem in some places). |
The reason for the implementation was a very time consuming trial and error process to iron out color bleeding problems years ago. As far as I remember, closing a problem here opened a problem there. Also, pdflatex, lualatex, xelatex all had their own special cases of problems. The current implementation is a working compromise. I do not want to open Pandora's box. But, anyway, I'm open for suggestions for improvement. Currently, I have no time to look into it (hopefully, next week or the week after). |
It is a bit difficult to test properly and the code is rather complex due to the various boxes. But I have some doubts about this in the breakable library
|
Here, the idea is to initialize the color stack with the current color. The current color is given by Instead of |
To sum up a little history: In version Therefore, I reverted back to the old/current handling with |
I'm not completly sure that I get your meaning but I think that you have a misunderstanding here.
I will try to look later what is going on there. |
I took a look. I could reproduce the error from #120 with version 4.32 in a texlive 2019 but it disappears in texlive 2020. I'm not completly sure why, but looking at the logs and \showoutput, my hunch would be that with the advent of LaTeX hooks pgf stopped to doing low-level manipulations with everyshi. |
That is interesting and (hopefully) good news. I will do tests with an approach similar to 4.32 with cleaner code and see, if the |
I try to come up with an MWE to test a proper a color stack usage for breakable boxes. It should simplify what happens (or should happen) with a The MWE uses
\documentclass{article}
\usepackage[a4paper]{geometry}
\usepackage{tikz}
\usepackage{pdfcol}
\newbox\upperbox
\newbox\lowerbox
\newbox\partbox
\pdfcolInitStack{mystack}% remove to disable color stack
\begin{document}
\setbox\upperbox=\vbox{%
\hsize=5cm%
\begingroup%
\pdfcolIfStackExists{mystack}{%
\pdfcolSwitchStack{mystack}%
\leavevmode\color{red}}{}%
1 red 1 red 1 red 1 red 1 red 1 red 1 red 1 red
1 red 1 red 1 red 1 red 1 red 1 red 1 red 1 red
1 red 1 red 1 red 1 red 1 red 1 red 1 red 1 red
\color{blue}
1 blue 1 blue 1 blue 1 blue 1 blue 1 blue 1 blue 1 blue
1 blue 1 blue 1 blue 1 blue 1 blue 1 blue 1 blue 1 blue
1 blue 1 blue 1 blue 1 blue 1 blue 1 blue 1 blue 1 blue
1 blue 1 blue 1 blue 1 blue 1 blue 1 blue 1 blue 1 blue
1 blue 1 blue 1 blue 1 blue 1 blue 1 blue 1 blue 1 blue
\endgroup
}
\setbox\lowerbox=\vbox{%
\hsize=5cm%
\begingroup%
\pdfcolIfStackExists{mystack}{%
\pdfcolSwitchStack{mystack}%
\leavevmode\color{green}}{}%
2 green 2 green 2 green 2 green 2 green 2 green
2 green 2 green 2 green 2 green 2 green 2 green
2 green 2 green 2 green 2 green 2 green 2 green
\color{yellow}
2 yellow 2 yellow 2 yellow 2 yellow 2 yellow 2 yellow
2 yellow 2 yellow 2 yellow 2 yellow 2 yellow 2 yellow
2 yellow 2 yellow 2 yellow 2 yellow 2 yellow 2 yellow
2 yellow 2 yellow 2 yellow 2 yellow 2 yellow 2 yellow
2 yellow 2 yellow 2 yellow 2 yellow 2 yellow 2 yellow
\endgroup
}
\noindent text before picture
\bigskip
\noindent%
\begin{tikzpicture}
\setbox\partbox=\vsplit\upperbox to 1cm%
\draw[gray] (0,-1) -- (0,0) -- (5,0) -- (5,-1);
\draw[gray] (6,-1) -- (6,0) -- (11,0) -- (11,-1);
\pgftext[x=0cm,y=0cm,left,top]{%
\begingroup
\pdfcolIfStackExists{mystack}{\pdfcolSetCurrent{mystack}}{\color{red}}%
\box\partbox
\endgroup
}
\setbox\partbox=\vsplit\upperbox to 2cm%
\pgftext[x=0cm,y=-1.5cm,left,top]{%
\begingroup%
\pdfcolIfStackExists{mystack}{\pdfcolSetCurrent{mystack}}{\color{red}}%
\box\partbox%
\endgroup%
}
\pgftext[x=0cm,y=-4cm,left,top]{%
\begingroup%
\pdfcolIfStackExists{mystack}{\pdfcolSetCurrent{mystack}}{\color{red}}%
\box\upperbox%
\endgroup%
}
\setbox\partbox=\vsplit\lowerbox to 1cm%
\pgftext[x=6cm,y=0cm,left,top]{%
\begingroup%
\pdfcolIfStackExists{mystack}{\pdfcolSetCurrent{mystack}}{\color{green}}%
\box\partbox%
\endgroup%
}
\setbox\partbox=\vsplit\lowerbox to 2cm%
\pgftext[x=6cm,y=-1.5cm,left,top]{%
\begingroup%
\pdfcolIfStackExists{mystack}{\pdfcolSetCurrent{mystack}}{\color{green}}%
\box\partbox%
\endgroup%
}
\pgftext[x=6cm,y=-4cm,left,top]{%
\begingroup%
\pdfcolIfStackExists{mystack}{\pdfcolSetCurrent{mystack}}{\color{green}}%
\box\lowerbox%
\endgroup%
}
\end{tikzpicture}
\bigskip
\noindent text after picture
\end{document} For pdflatex and lualatex this gives: For xelatex this gives (as has to be expected): This second output is also what we get, if the color stack handling is removed. I am open for improvements for this MWE code:
If this code has no fundamental flaws, my next step would be changing the real implementation following that pattern. |
The grouping is wrong. If you look into the log you will see message like this:
This means that you pushed colors on your stack (1) but pop them from the main stack 0.
For your boxes this means something like this
Yes, my main problem there is the use of "internals". As soon as package use only user interface I can change the backend as needed. |
Thank you for your helpful explanations. I would never figured out the necessity for two group layers. |
I integrated the changes into the actual The situation is: If no color stack is used, the box content is saved without coloring into a Problems arise with things like \documentclass{article}
\usepackage[a4paper]{geometry}
\usepackage{tikz}
\newbox\upperbox
\begin{document}
\color{blue}
\noindent Blue text.
% miracle code to trick the current color to red without inserting
% a whatsit and without using internals
\setbox\upperbox=\vbox{%
\hsize=5cm%
\begingroup%
%\color{red}% inserts a whatsit (no visual effect in this MWE)
\begin{itemize}
\item Item 1
\item Item 2
\end{itemize}
\endgroup%
}
\noindent%
\begin{tikzpicture}
\pgftext[x=0cm,y=0cm,left,top]{%
\begingroup
\color{red}%
\box\upperbox
\endgroup
}
\end{tikzpicture}
\noindent Text after picture.
\end{document} This gives blue bullets instead of red bullets: I see two possibilites:
|
The bullets are black as their code "ensure" the current color (as does \sbox) with
If this works for you generally, I could think about some user interface, e.g. \noensurecurrent or something like that. (I don't have much time today). |
A possible problem with this could be that if the box has complex content (boxes in boxes, all kind of stuff), this could give a lot of side effects (worse than the original hack which is overwritten with every internal color setting). I test-implemented the other approach (color insertion at the begin of every \documentclass{article}
\usepackage[a4paper]{geometry}
\usepackage{tcolorbox}
\tcbuselibrary{breakable,skins}
\NewTColorBox{testbox}{ O{} m }{%
draft,
size = tight,
colupper = red,
collower = yellow,
title = {#2},
#1
}
\begin{document}
(A) Simple:
\begin{testbox}{Basic box}
Upper color red.\par
\color{green} Something in green.
\end{testbox}
\begin{testbox}[breakable]{Breakable box}
Upper color red.\par
\color{green} Something in green.
\end{testbox}
\begin{testbox}[breakable,use color stack]{Breakable box with color stack}
Upper color red.\par
\color{green} Something in green.
\end{testbox}
(B) Itemize:
\begin{testbox}{Basic box}
\begin{itemize}
\item Item 1
\item Item 2
\end{itemize}
\end{testbox}
\begin{testbox}[breakable]{Breakable box}
\begin{itemize}
\item Item 1
\item Item 2
\end{itemize}
\end{testbox}
\begin{testbox}[breakable,use color stack]{Breakable box with color stack}
\begin{itemize}
\item Item 1
\item Item 2
\end{itemize}
\end{testbox}
(C) Itemize with with color change:
\begin{testbox}{Basic box}
\begin{itemize}
\item Item red
\color{green}
\item Item green
\end{itemize}
\end{testbox}
\begin{testbox}[breakable]{Breakable box}
\begin{itemize}
\item Item red
\color{green}
\item Item green
\end{itemize}
\end{testbox}
\begin{testbox}[breakable,use color stack]{Breakable box with color stack}
\begin{itemize}
\item Item red
\color{green}
\item Item green
\end{itemize}
\end{testbox}
\end{document} Most notably is test example (C) which gives with the current implemenation and pdflatex: The new test implementation with color setting at begin of every A made compilations with pdflatex, lualatex, and xelatex with a variants. The following rough table displays the height of the upper box: My current considerations are:
I will come back to this end of next week, but my current feeling is, that I should go for the color setting implementation (which needs no hacks and therefore is cleaner). |
regarding the additional spacing: you could try if hyperref's method (which has to suppress spaces from anchors) helps. Basically it does in vmode (see e.g. https://tex.stackexchange.com/a/600142/2388)
(but I didn't test ...) |
There was no difference with this code... Changing the implementation to direct color setting at the begin of a box, which is IMHO the natural thing to do but was avoided with tricks until now, will add additional spacing at begin of a
Also see the following example which displays the effects with boxed enumeration lists AND side effects coming from just including \documentclass{article}
\usepackage{color}
%\usepackage{hyperref}
\begin{document}
\fbox{%
\begin{minipage}{10cm}%
\begin{enumerate}
\item abc
\end{enumerate}
\end{minipage}%
}
\fbox{%
\begin{minipage}{10cm}%
\color{red}%
\begin{enumerate}
\item abc
\end{enumerate}
\end{minipage}%
}
\end{document} Here, the additional space is clearly seen. Now, if Presumably, From my current point of view I see two ways for
|
Yes, I realized that it wasn't useful as you aren't on the main galley but in a box.
The problem is the \refstepcounter (which is issued before the item) and sets an anchor, which is a whatsits like the color, and whatsits are sometimes quite a pain ;-) With hyperref and lists one could resolve the problem: hyperref could set the anchor later, when the paragraph has started, but with color it is bit more difficult unless you use luatex and luacolor ;-). If you have control, you naturally can try to move the color setting:
|
Yes, that's the basic idea of the current |
Just an additional remark: |
I uploaded a preview version of There were several side effects, especially for the |
luacolor is much more safer and easy to use ;-) One reason why we explore https://github.com/latex3/xpdftex. |
Regarding lists and color/hyperref whatsits at the begin of boxes: latex3/latex2e#989. I can't be completly sure, but I think it will also resolve the tcolorbox problems. At least if I insert manually a color command before the list (in the second box) then I get this with the new code: compared to this with the old code: |
I'm trying to improve the use of spot colors in LaTeX. For some background see https://www.tug.org/TUGboat/tb43-2/tb134fischer-spotcolor.pdf.
A good solution for this problem requires the switch to the color commands provided the l3color module. This is complicated as various packages use "internal" commands of the color and xcolor package and would break if these internal commands change. (This is not meant as a reproach, due to the long history of these packages I'm quite aware that the border between internal and public interfaces are quite blurry and that some uses of internal commands simply reflect the fact that some interfaces were or still are missing.)
An example from tcolorbox is this
This is from my point of view problematic as
\current@color
which should be only done by the color code when a color is actually selected (and so the current color actually changes)\current@color
by mapping it to\@nameuse{\string\color@#1}
.
I would be grateful to get some feedback why this is done this way. Why e.g. doesn't the code do something like
\colorlet{tcb@tempcolor}{#1}
and then use\color{tcb@tempcolor}
later?The text was updated successfully, but these errors were encountered: