# Color highlighting text and environments in LyX

I am using LyX 2.0.5 with document class article and 'Theorems (AMS)' in the modules. I am wondering if it is possible to make it so that the titles of different environments will be highlighted in different colors ("highlighted" in the sense of a highlight marker. I.e., having a colored background, w/o changing the font color). E.g., in the Theorem environment the words Theorem 12.1 will be typeset with red highlight, in the Definition environment the words Definition 5.9 will be typeset with yellow highlight, etc.

I am guessing the will require changing the module?

## 1 Answer

(Note: there are parts of this solution that are sub-optimal, and I'm aware of that, but I'll have to fix that later. I'll remove this note when I find the time to improve things.)

You can change the files theorems-ams.module and theorems-ams.inc, or better create copies as described in my answer to How to make "claim" environments look like "theorem" environment?

In theorems-ams.module, add xcolor to the required packages. I.e. where it says

Requires    amsmath,amsthm

edit this to

Requires    amsmath,amsthm,xcolor

(This bit is untested, but I assume it will work.)

In theorems-ams.inc, find the style you want to change, for example the block defining the look of theorems starts with Style Theorem.

In the Style block there is a sub block Preamble, which by default looks like

Preamble
\theoremstyle{plain}
\newtheorem{thm}{\protect\theoremname}
EndPreamble

Using code taken from egreg's answer to amsthm environment and colorbox, edit this to read

Preamble
\newtheoremstyle{Coloredtheo}%
{3pt}    %Space above
{3pt}    %Space below
{}   %Body font
{}   %Indent amount
{\bfseries}    %Theorem head font
{}   %Punctuation after theorem head
{0.25em} %Space after theorem head
{\colorbox{red}{\color{black}\thmname{#1}%
\thmnumber{\@ifnotempty{#1}{ }\@upn{#2}}}%
\thmnote{ {--- \the\thm@notefont#3.}}%
}   %Theorem head spec
\theoremstyle{Coloredtheo}
\newtheorem{thm}{\protect\theoremname}
EndPreamble

Note that this will not change the view in LyX, only in the PDF. Do similarly for Definition, but use a different name for the \newtheoremstyle. The background colour is set by the first argument to \colorbox, here red.

For a single document, you could use the Local layout under Documents --> Settings. Add the entire Style block to the local layout. You may need to also include \usepackage{xcolor} to the Preamble block.

• Thanks! But actually I meant "highlight" in the sense of having the background colored (like with a highlight marker), w/o changing the text color. I will edit the original post to make it clearer. In any case, I tried your solution but it only changed the font color in LyX (and not in the PDF output). Am I missing something? – doodle Mar 26 '14 at 20:55
• @doodle I edited my answer. It's not perfect, but I think it's closer to answering your question now. – Torbjørn T. Mar 26 '14 at 21:51
• Amazing! One little thing though: The dot that usually appears after the theorem number is gone. I tried changing {} to {.} in the %Punctuation, but this adds the dot outside of the color box. – doodle Mar 26 '14 at 23:27
• OK, got it. I changed \@upn{#2}} to \@upn{#2}}{.} in your code. That took care of that dot. // Also, I kept the Color Red parameter under Label Font, which you mentioned before your edit. It's not what I was looking for as far as end result in the PDF, but it does make LyX look slightly more like the PDF. Thanks again! – doodle Mar 26 '14 at 23:47