1

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.

1 Answer 1

2

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

3
  • 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
    Commented Feb 28, 2012 at 22:48
  • @prash Thanks for the obervation, I edited my answer accordingly.
    – Marco
    Commented Feb 29, 2012 at 10:37
  • It's been very useful!
    – prash
    Commented Mar 2, 2012 at 0:10

You must log in to answer this question.

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