2

xsavebox has the ability to color saved boxes according to the ambient text. tikzpictures have the same ability. However, the combination of these does not seem to have this ability.

\documentclass{article}
\usepackage{tikz}
\usepackage{xsavebox}
\begin{xlrbox*}{SavedPar}%
boxed paragraph 
\end{xlrbox*}
\newcommand\TestTikZ{\begin{tikzpicture}
\draw circle[radius=1cm];
\end{tikzpicture}}
\begin{xlrbox*}{SavedTikZ}%
\TestTikZ
\end{xlrbox*}

\begin{document} test, \theSavedPar, \TestTikZ, \theSavedTikZ

\vskip1cm \textcolor{red}{test, \theSavedPar, \TestTikZ, \theSavedTikZ} \end{document}

enter image description here

As you can see, the circle on the bottom left is not colored even though the tikzpicture from the macro and the saved text box are.

The question is whether one can make the saved tikzpicture also become color sensitive.

P.S. I experimented with this thread, but could not make this work either.

  • 1
    you can't. tikz initialize and add colors when you store it in a box, so the colors are fix then. – Ulrike Fischer Apr 03 '21 at 10:36
  • The sentence does not even make sense grammatically. If it is meant to say that "tikz initializes colors when you store a tikzpicture in a box", then surely this is because of some code, which one may eventually modify. –  Apr 03 '21 at 14:16
  • well sure theoretically you can disable it: use \tracingmacros=1 to check which code pgf is using and then rewrite all the commands not to use colors without breaking other things (e.g. the places where you actually want color). But be aware that tikz is about graphics and colors are an intrinsic part of it and so color commands are used in various places. – Ulrike Fischer Apr 03 '21 at 14:26
  • Not sure I find the comment helpful. The example already shows that it does not work. Now you suggest that I use \tracingmacros=1 to find out what is going on? Well, this question is to find out if somebody already has figured out what is going on, and can detail a way that works. One possible application is to create monochromatic symbols with TikZ, which acquire the color of the surrounding text. This works if you put the plain tikzpicture but not when you save the tikzpicture in a box. –  Apr 03 '21 at 14:33
  • you could try \def\pgfsetcolor#1{} before the tikzpicture when saving it. But I'm not giving a garanty that it doesn't explode somewhere if you use more complicated examples. – Ulrike Fischer Apr 03 '21 at 15:34
  • 1
    Yes, this seems to work. Thanks! So this shows that there is, at least in principle, a solution. As you say, it may not be the most robust solution, so maybe someone else has a somewhat more gentle one, but it does appear that for the purpose of creating monochromatic symbols your proposal is already pretty good. –  Apr 03 '21 at 16:09

0 Answers0