Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Is there a way to specify the color along with the font name when using simplefonts? At the moment, I use the following to setup my default fonts.

\usemodule[simplefonts]
\setmainfont[Ubuntu]
\setsansfont[charter] % the reversal of serif and sans roles was intentional
\setmonofont[FreeMono]
\setmathfont[euler]

This is working as expected. However, I'd like to have all math to be shown in dark red. I can switch it manually every time like so:

\color[darkred]{$my+new+equation$}
  1. Is there something I can add to \setmathfont so that it changes the color without having to type the extra color commands every time? Ideally, it should work for all the commands used for display-math and inline-math.
  2. In addition to that, when the surrounding text overrides the color, the color should be in the new, overriding color instead. So, \color[green]{Important: you need to tune $x$ to use the above.}, should be set entirely in green.
share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

A solution for the first of your two points is to use \appendtoks like in this example:

% For inline math
% \appendtoks\green\to\everymath

% For display math
% \appendtoks\green\to\everydisplay

% For inline and display math
\appendtoks\green\to\everymathematics

\starttext

\math{a^2+b^2=c^2}

\startformula
    a^2+b^2=c^2
\stopformula

\stoptext

The green colour switch is applied to inline and display math.

Edit: Changes applied to \everydisplay or \everymathematics affect text included in the display math as well. I'm not sure if there's a clean solution for this, but you can inject code directly before the \text is printed. Here I print the text inside the display math in blue:

\unprotect
\unexpanded\def\mathtext
  {\mathortext\blue\math_text_choice\hbox}
\protect

Example:

\appendtoks\green\to\everymathematics

\unprotect
\unexpanded\def\mathtext
  {\mathortext\blue\math_text_choice\hbox}
\protect

\starttext

\math{a^2+b^2=c^2}

\startformula
    a^2+b^2=c^2
\stopformula

\stoptext

The result:

result

share|improve this answer
    
Thanks! I am using this for now, but it colors even the \text{} sections within formulas, which I prefer it avoid. Though a font-based solution would work better for me, I like this is a good default for the time being. –  prash Feb 28 '12 at 22:48
    
@prash Thanks for the obervation, I edited my answer accordingly. –  Marco Feb 29 '12 at 10:37
    
It's been very useful! –  prash Mar 2 '12 at 0:10
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.