8

In a beamer document, I have $ expressions embedded in displayed equations (using tikz to make, e.g., colored boxes around some expressions). I put \everymath{\displaystyle} in the preamble so that these expressions aren't show in text style. However, when the $ expression is in an AMS equation environment rather than equation, this \everymath is not honored:

\documentclass{beamer}

\usepackage{tikz}
\usepackage{amsmath}

\everymath{\displaystyle}

\begin{document}
  $\sum_i$ \$ expr\\                 % works
  \tikz \node {$\sum_i$ \$ in tikz}; % works
  \begin{equation}
    \tikz \node {$\sum_i$ tikz in equation}; % works
    \text{$\sum_i$ text in equation}         % works
  \end{equation}
  \begin{gather}
    \tikz \node {$\sum_i$ tikz in gather};   % problem
    \text{$\sum_i$ text in gather}           % works
  \end{gather}
\end{document}

Note that this happens only inside \tikz, not \text; and only with the beamer document class. I am intrigued: why does this happen? And is there a simple workaround?

(Of course there is a simple workaround: put \displaymath in every $ expression ... But maybe something more elegant?)

3
  • A very handful and simple method to highlight equations is provided by the \tcbhighmath command from the tcolorbox package. Using this, you don't have to do manual adjustments. Commented Aug 7, 2013 at 19:37
  • You basically can't use \everymath in LaTeX because math mode is used and abused behind the scenes in many unexpected ways. I wouldn't trust something as intricate as Beamer to leave it alone at all.
    – Ryan Reich
    Commented Aug 8, 2013 at 5:44
  • @Gonzalo: Thanks for the suggestion. However, in my real document I also use tikz to draw arrows between nodes, so I think I want to stay with that (apart from not wanting to learn yet another package ...) @Ryan: I read about this problem in the context of coloring equations. I thought for \displaystyle it would not be an issue, because that will affect nothing that is not actually math.
    – xebtl
    Commented Aug 8, 2013 at 7:41

3 Answers 3

6

Something that I'm not sure yet resets the math rendering (probably due to the box font settings or something related to the gather but I'm not really good at that math settings differences about amsmath package). So if you push the command to be executed at every start of the node, it looks like the problem is gone. Also I recommend mathtools instead of amsmath.

\documentclass{beamer}

\usepackage{tikz}
\usepackage{mathtools,lmodern}

\everymath{\displaystyle}
\tikzset{execute at begin node={\everymath{\displaystyle}}} 
\begin{document}
\begin{frame}
  $\sum_i$ \$ expr\\                 % works
  \tikz \node {$\sum_i$ \$ in tikz}; % works
  \begin{equation}
    \tikz[baseline] \node {$\sum_i$ tikz in equation}; % works
    \text{$\sum_i$ text in equation}         % works
  \end{equation}
  \begin{gather}
    \tikz[baseline] \node {$\sum_i$ tikz in gather};   % problem
    \text{$\sum_i$ text in gather}           % works
  \end{gather}
\end{frame}
\end{document}

enter image description here

5

beamerbasecolor.sty (loaded by beamer.cls) redefines \start@gather to execute \donotcoloroutermaths which in turn does

\everymath{\everymath{\beamer@setmathcolor}}

You can solve the issue by adding \displaystyle:

\documentclass{beamer}

\usepackage{tikz}
\usepackage{amsmath}

\everymath{\displaystyle}
\makeatletter
\renewcommand\donotcoloroutermaths{%
  \everymath{\everymath{\displaystyle\beamer@setmathcolor}}%
}
\makeatother

\begin{document}
\begin{gather}
  \tikz \node {$\sum_i$ tikz in gather};
\end{gather}
\end{document}

The fix should work also with align and the other amsmath environments.

0
1

egreg and percusse both provided answers that solved the problem for the test case I provided. However, in my real document, things got a bit more complicated, so I thought I would share what I learned.

Specifically, I have one \tikz inside an \intertext, and that only works with percusse's solution. On the other hand, I have one $ expression inside a tabular, and that only works with egreg's solution:

\documentclass{beamer}

\usepackage{tikz}
\usepackage{amsmath}

\everymath{\displaystyle}

% percusse
\tikzset{execute at begin node={\everymath{\displaystyle}}} 

% egreg
\makeatletter
\renewcommand\donotcoloroutermaths{%
  \everymath{\everymath{\displaystyle\beamer@setmathcolor}}%
}
\makeatother

\begin{document}
\begin{gather}
  \tikz \node {$\sum_i$ tikz in gather};    % works with either solution
  \intertext{                               % works with percusse's solution
    \tikz \node {
      $\sum_i$ tikz in intertext
    };
  }
\end{gather}

\begin{tabular}{l}
  $\sum_i$                                  % works with egreg's solution
\end{tabular}
\end{document}

So in the end, I am using both solutions combined.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .