3

My problem is that I want my math functions and drawing illustrations to be in different colors. I want my colors to be defined at the beginning so they will automatically change the color of math and illustration as i like. I was never working with math and drawing before so that's why it is a bit problem for me. Thank you very much for your help.

WORKING CODE:

\documentclass[svgnames]{report}
\usepackage{tikz}
\usepackage[cp1250]{inputenc}
\usepackage[slovak]{babel}
\usepackage{kpfonts}



\definecolor{colMATH}{RGB}{255,0,0} % color of the math functions
\definecolor{colILLUS}{RGB}{0,0,255} % line color in illustration

% example
\begin{document}

% MATH
            $$detA=|A|= \left|\begin{array}{cccc}
            a_11 & a_12 & \ldots & a_{1n} \\
            a_21 & a_22 & \ldots & a_{2n} \\
            . & . &  & . \\
            . & . &  & . \\
            . & . &  & . \\
            a_{n1} & a_{n2} & \ldots & a_{nn} \\
            \end{array} \right|=\sum{(-1)^ja_{1k_1}\cdot a_{2k_2}\cdot a_{3k_3}\cdot...\cdot a_{nk_n}} $$                                       


% ILLUSTRATION
\setlength{\unitlength}{1mm}
\begin{picture}(120,100)(-8,0)
   \put(35,5){\vector(1,0){50}}
   \put(88,5){\makebox(0,0){$h$}}
   \put(40,2){\makebox(0,0){$h_A$}}
   \put(70,2){\makebox(0,0){$h_B$}}
   \multiput(40,5)(30,0){2}{\line(0,1){90}}
   \multiput(40,5)(0,10){7}{\line(1,1){30}}
   \multiput(40,35)(6,0){5}{\line(1,0){3}}
   \multiput(40,65)(6,0){5}{\line(1,0){3}}
   \multiput(40,5)(0,30){3}{\circle*{2}}
   \multiput(70,35)(0,15){3}{\circle*{2}}
   \multiput(40,35)(0,30){2}{\line(1,-1){30}}
   \multiput(39.75,15)(.25,0){3}{\line(0,1){10}}
   \multiput(39,15)(0,10){2}{\line(1,0){2}}
   \multiput(69.75,55)(.25,0){3}{\line(0,1){10}}
   \multiput(69.75,40)(.25,0){3}{\line(0,1){5}}
   \multiput(69,35)(0,5){7}{\line(1,0){2}}
   \put(97,60){\makebox(0,0){$
     \left\}\rule[-4mm]{0mm}{8mm}\right.\leftarrow
     \Delta\tau = 2T_{Cs}\mbox{(lokale Uhr)}
     $}}
   \put(98,50){\makebox(0,0){$\leftarrow$ \emph{Explosion der 2. Uhr}}}
   \put(96,42.5){\makebox(0,0){$\left\}\rule[-1.5mm]{0mm}{3mm}\right.
     \hskip1mm\leftarrow\Delta\tau = T_{Cs}\mbox{(lokale Uhr)}$}}
   \put(25,20){\makebox(0,0){$\Delta\tau = T_{Cs}\rightarrow
     \left\{\rule[-4mm]{0mm}{8mm}\right.$}}  %}
   \put(38,8){\makebox(0,0){1}}
   \put(17,35){\makebox(0,0){ \emph{Start der 1. Uhr} $\rightarrow$ 2$A$}}
   \put(13,65){\makebox(0,0)
                {\emph{Explosion der 1. Uhr} $\rightarrow$ 3$A$}}
   \put(93,35){\makebox(0,0)
                { 2$B \leftarrow$ \emph{Start der 2. Uhr}}}
   \put(74,68){\makebox(0,0){$3B$}}
\end{picture}

\end{document}

THIS IS WHAT I WANT TO HAVE: enter image description here

David Carlisle
  • 757,742
Banny
  • 345

2 Answers2

5

In your example, it can be solved using \everydisplay for displayed math and the etoolbox package for the pictures:

\everydisplay{\color{colMATH}}
\usepackage{etoolbox}
\AtBeginEnvironment{picture}{\color{colILLUS}}

colored environments

Some advice: your should not use $$, further better use math operators such as \det, consider using TikZ (or PSTricks), for more math features use amsmath. The latter can have problems with \everydisplay though.

Stefan Kottwitz
  • 231,401
  • This is a partial solution. I've been playing with this as well. The problem is that it doesn't work for ordinary math. You can use \everymath to set the color but then the colour of any text after ordinary math in a Tikz node will revert to black. (So \draw node {blah $a=b$ blur}; will colour blah $a=b$ as requird but will colour blur in the default colour.) –  Jan 14 '12 at 13:41
  • I notice your solution is for the picture environment, so I should have rephrased my comment. Still it would be nice to also make it work for TikZ. –  Jan 14 '12 at 13:45
  • 1
    For finer control over the colour of maths, see Will Robertson's answer to http://tex.stackexchange.com/q/335/86 – Andrew Stacey Jan 14 '12 at 14:05
  • @Andrew Thanks for the link. Unfortunately, it's not for pdflatex. –  Jan 14 '12 at 14:30
  • @MarcvanDongen True. It's what switched me to xelatex, as it happens. – Andrew Stacey Jan 14 '12 at 14:34
  • @Andrew I tried switching to XeLaTeX twice and it works nice, but I reverted to pdflatex again because it has proper microtype support, which XeLaTeX is currently still lacking. (I'd love OpenType support 'a la XeLaTeX in pdflatex.) –  Jan 14 '12 at 14:37
  • 1
    Allegedly, it's on its way (see http://tex.stackexchange.com/q/2986/86) – Andrew Stacey Jan 14 '12 at 14:51
  • @Stefan Kottwitz THX for the pictures...works perfectly. – Banny Jan 15 '12 at 16:28
  • @Andrew Stacey pdflatex is my priority here so i can't use that solution on xelatex but thank you. – Banny Jan 15 '12 at 16:29
2

I have found a solution for math but it is not super cool. Is there any other possibility to make it work like this?

CODE:

\definecolor{colMATH}{RGB}{255,0,0} % color of the math functions


\let\oldbmath\[
\renewcommand{\[}{\begingroup\color{colMATH}\oldbmath}
\let\endoldmath\]
\renewcommand{\]}{\endoldmath\endgroup}


%math function
\[
detA=|A|=
\left|\begin{array}{cccc}
       a_11 & a_12   & \ldots & a_{1n} \\
       a_21 & a_22   & \ldots & a_{2n} \\
          . & .      &        & . \\
          . & .      &        & . \\
          . & .      &        & . \\
     a_{n1} & a_{n2} & \ldots & a_{nn} \\
\end{array}
\right|=\sum{(-1)^ja_{1k_1}\cdot a_{2k_2}\cdot a_{3k_3}\cdot...\cdot 
a_{nk_n}}
\]
David Carlisle
  • 757,742
Banny
  • 345
  • 3
    What's bad about Stefan Kottwitz's answer? This one won't work for other display math environments. – egreg Jan 15 '12 at 17:41