# Set colour of equations when using preview package

I use the preview package to export a pdf containing only my equations by putting the following in the preamble

\usepackage[active,tightpage,displaymath,textmath]{preview}
\setlength\PreviewBorder{2pt}
\PreviewEnvironment{equation*}
\makeatletter\renewcommand\@eqnnum{}\makeatother


I would like to set the colour of the exported equations. How can I specify the colour such that the preview package will see it?

It isn't clear what specific document class you are using, but I am able to get (for example) red equations by using the color package and setting the color within the equation environment.

\ifPreview can be used as shown to turn coloring off when not in preview mode. The package should be disabled by removing the active option to \usepackage so as to keep \ifPreview defined (as opposed to disabling the entire package, which would break things).

A MWE:

\documentclass[12pt]{article}

\usepackage[active,tightpage,displaymath,textmath]{preview}
\setlength\PreviewBorder{2pt}
\PreviewEnvironment{equation*}
\makeatletter\renewcommand\@eqnnum{}\makeatother

\usepackage{color}

\usepackage{lipsum}

\begin{document}

\lipsum[1]

$$\ifPreview\color{red}\fi a^2 + b^2 = \frac{1}{\sqrt{\pi r^3}}$$

\lipsum[2]

\end{document}


Gives previews as:

But when disabled, appears as:

• \ifPreview works well. To avoid rewriting all my equations and because I'm actually using Lyx, I put this in the preamble \ifPreview\usepackage{etoolbox}\AtBeginEnvironment{equation}{\color{red}}\fi I suspect if may be incorrect/fragile but seems to work for me. Mar 19, 2014 at 9:37