# Background colouring (highlighting) for maths formula in Lyx?

I want to highlight selected maths formulas in Lyx.

Is there a simple way of doing this from the GUI ?

I have tried selecting and right-clicking -> Text style , but that seems to change the font colour, not the background colour :

I have also tried the box menu -> shaded highlight, but the highlighting runs all the way across the page for some reason (in the PDF as well as in the Lyx GUI):

I am able to do this by entering Latex code for the highlighting and the formula, but I was hoping this highlighting from the Lyx GUI.

I am using Lyx version 2.2.3 with TexLive.

• It runs across the whole page because that is the default configuration of a Shaded background box. You can change the width in the settings. Unrelated: when writing ln and exp, use \ln and \exp, then they are properly typeset. May 31, 2018 at 13:49
• Currently, 'Settings..' says 'minipage'. Do i need to change that to 'parbox' or 'none' ? Also, yes there is a width setting, but do i need to type in (guess) a value ? May 31, 2018 at 14:01
• No need to change type. As far as I can see, you have set the width manually, yes. At least with that method, I don't know if LyX has any other options built-in. By the way, you said you could do it by writing code. Exactly how did you do it? May 31, 2018 at 14:04
• I normally use TexStudio rather than Lyx, and I use this: {code} %%highlight with \hl \usepackage{xcolor} \usepackage{soul} \colorlet{highlightgreen}{green!10} \colorlet{highlightgray}{gray!20} \sethlcolor{highlightgreen} {code} then i can use \hl{} with the formula inside May 31, 2018 at 14:09
• You could use the old trick of writing \hl{ in an ERT, then write the inline math using LyX's GUI, and finally another ERT with }. May 31, 2018 at 14:13

A quick hack for using \hl, is to write only \hl{ and } in ERTs, and write the math stuff using the LyX GUI. So it might look like this:

Another option is to define a new custom inset for \hl. Go to Document --> Settings --> Local layout, and add this:

InsetLayout Flex:highlight
LyxType               custom
LabelString           hl
LatexType             command
LatexName             hl
Font
Series              Bold
EndFont
Preamble
\usepackage{xcolor}
\usepackage{soul}
\colorlet{highlightgreen}{green!10}
\colorlet{highlightgray}{gray!20}
\sethlcolor{highlightgreen}
EndPreamble
InToc                 false
HTMLTag               strong
ResetsFont true
End


(Alternatively skip the Preamble block, and add those to the preamble manually.)

Now you should find hightlight under Insert -> Custom insets:

Add one of those insets, and add the inline math inside it. Might look like this: