My goal is to achieve colorings in the output document, that are similar to the syntax highlighting I use in my editor, so switching between the editing and viewing the document becomes easier on the eyes.
I figured I can use the color
package to define some colors using \definecolor
and then set the foreground and backgroundcolors using \color{fg}
and \pagecolor{bg}
, respectively.
What I'd like to do now, is assing certain colors to certain commands and environments. For simple commands like \emph
I can do
\let\oldemph\emph
\renewcommand\emph[1]{{\color{emph}\oldemph{#1}}}
but I haven't figured out how to change the color of environments like align*
and others.
Any help on how I could achieve this? Maybe theres even a generic way to do this, a package for semantic coloring like this would be cool.
EDIT: I managed to color environments using
\usepackage{etoolbox}
\AtBeginEnvironment{align*}{\color{equation}}
\AtBeginEnvironment{align}{\color{equation}}
\AtBeginEnvironment{equation*}{\color{equation}}
\AtBeginEnvironment{equation}{\color{equation}}
Inline-math can be colored using \everymath{\color{inlinemath}}
, but this overrides the colors of the align*
environment (not of the equation*
environment though). How to fix this?
EDIT: If I'm correct, align*
-environments switch between mathmode and non-mathmode to obtain the correct spacing. So if I use \everymath
to set a color, it will be set inside align*
environments, overriding what I did with \AtBeginEnvironment
. For equation*
it works, because there is only a single math block and \AtBeginEnvironment
will put the color setting inside. The only way I can think of to fix this, would be somehow setting a color only for $...$
, instead of using \everymath
. Is this possible?
etoolbox
patches might be able to achieve what I'm looking for, though I never used that package before.