astoff / tikz-cd

Commutative diagrams with TikZ
46 stars 3 forks source link

Beamer and tikz-cd, styling issue #5

Closed wstomv closed 5 months ago

wstomv commented 5 years ago

If you use the LaTeX beamer package, and set a color for math material using

\setbeamercolor{math text}{fg=green}

then styling applied within a tikzcd environment only affacts the arrows, but not the nodes or arrow labels.

With the default setting for math text, things work fine in tikzcd. It always works in regular equations. Any idea what is going on, and how to work around this?

Here is a small example (output with and without setbeamercolor attached):

\documentclass{beamer}
\usepackage{tikz-cd}
\setbeamercolor{math text}{fg=green}% also try without this line

\begin{document}

\begin{frame}[fragile]
\begin{equation}
  e^{\alert{\pi i}} + 1 = \color{blue}{0}
\end{equation}

\begin{tikzcd}
[tikzcd-test-not-good.pdf](https://github.com/astoff/tikz-cd/files/3442564/tikzcd-test-not-good.pdf)
[tikzcd-test-not-good.pdf](https://github.com/astoff/tikz-cd/files/3442566/tikzcd-test-not-good.pdf)
[tikzcd-test-comparison.pdf](https://github.com/astoff/tikz-cd/files/3442572/tikzcd-test-comparison.pdf)

  |[alert]| A
      \ar[r, "f", alert]
      \ar[d, "h"]
    & |[blue]| B
      \ar[d, "h'", blue] \\
  C
      \ar[r, "g", orange]
    & D
\end{tikzcd}
\end{frame}

\end{document}

tikzcd-test-with tikzcd-test-without

astoff commented 5 years ago

I don't know Beamer's implementation details, but I assume the command you mentioned uses \everymath internally. Thus, it is executed after and hence takes priority over the tikzcd settings. I'd say this is actually the expected behavior.

The reason why the arrow labels change color is because tikzcd redefines the \everymath parameter for labels (namely, to make them print in \scriptstyle). This could be considered a bug, and we should append to \everymath instead. Do you care about this?

wstomv commented 5 years ago

@astoff Yes, apparently \setbeamercolor{math text}{fg=...} works via \everymath (according to the Beamer manual Section 17.3). So, for now, I will not use that command, because this mechanism is too blunt.

By the way, if you use a command like \color{blue} with a node or arrow label itself (rather than using tikz styling), like

\begin{tikzcd}
  A \ar[d, "\color{blue}f"] &  \color{orange}B
\end{tikzcd}

then that will override the color set by \setbeamercolor{math text}{fg=...}, because in that case the color command ends up inside the math material, and will be applied after \everymath has taken effect.

It would certainly be good to append to, rather than just redefine, \everymath. But the coloring of the arrow labels already agrees with that of nodes. So, that won't improve anything. To be more explicit: when you use \setbeamercolor{math text}{fg=...}, this affects both the coloring of the nodes and of the arrow labels. It does not affect the coloring of the arrows themselves.

The latter could be considered undesirable, since the arrows are part of the math as well. But the user of tikz-cd can easily fix that by issuing

\tikzcdset{every arrow/.append style = {green}}

By the way, for some reason

\tikzcdset{every node/.append style = {green}}

does not work as expected.

Concerning \scriptstyle: I don't like that default behavior of tikz-cd. So, after loading tikz-cd, my code does

\tikzcdset{every label/.append style = {font = \normalsize}}

to revert it.

My final conclusion is that this issue is not with tikz-cd, but rather with the combination of tikz and beamer.

A solution could be for tikz to apply styling to math material by temporarily appending the relevant commands to \everymath. (I have no idea how it does it now. I may drop it is as an issue there.)

astoff commented 5 months ago

My final conclusion is that this issue is not with tikz-cd, but rather with the combination of tikz and beamer.

I agree, so I will close this ticket and hope the situation can be improved upstream.