1

I'm trying to include some math in tcolorbox title, but LyX keeps escaping them. For example:

Color Box Options: title={$\psi_{T}$}

gives

\begin{tcolorbox}[title={\$\psi\_{T}\$}]

But I want

\begin{tcolorbox}[title={$\psi_{T}$}]

How to stop LyX from escaping $ and _?


Update:

I am using LyX provided color box support. Here is the screenshot

LyX colorbox screenshot

2 Answers 2

1

I finally found a way to do this without going to TeX mode. After digging into LyX source code, I found layout definition for Color_Box:

InsetLayout Flex:Color_Box
  LyXType               custom
  Decoration            classic
  LabelString           "Color Box"
  LatexType             environment
  LatexName             tcolorbox
  Requires              tcolorbox
  Argument 1
    LabelString         "Color Box Options"
    Tooltip             "Insert the color box options here (see tcolorbox manual)"
    PassThruChars       "\[]{}"
    DocBookTag          IGNORE
  EndArgument
  ResetsFont            true
  DocBookTag            phrase
  DocBookAttr           role='color-box'
End

PassThruChars means the white-listed chars. In this case I just need to add $_ to it.

So I created a new layout and added these lines:

InsetLayout Flex:Color_Box_With_Math
  LyXType               custom
  Decoration            classic
  LabelString           "Color Box Math"
  LatexType             environment
  LatexName             tcolorbox
  Requires              tcolorbox
  Argument 1
    LabelString         "Color Box Options"
    Tooltip             "Insert the color box options here (see tcolorbox manual)"
    PassThruChars       "\[]{}$_"
    DocBookTag          IGNORE
  EndArgument
  ResetsFont            true
  DocBookTag            phrase
  DocBookAttr           role='color-box'
End

Now it's correct:

correct result

1
  • I didn't know LyX (I use it only to answer here) has support for tcolorbox, interesting.
    – CarLaTeX
    Mar 2, 2022 at 6:38
0

Are you using Insert > TeX Code?

Because I have your desired output if I put \usepackage{tcolorbox} in Document > Setting > LaTeX preamble and I wrote this

\begin{tcolorbox}[title={$\psi_{T}$}]
a box
\end{tcolorbox}

as LaTeX code (I have the Italian version of LyX, so the tabs are in Italian):

enter image description here

Result:

enter image description here

1
  • Thanks for your answer! But what I really want is doing this without going to TeX mode. I have figured it out, updated the question and posted my own answer. Mar 2, 2022 at 3:08

You must log in to answer this question.

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