[Tex/LaTex] LyX use \newcommand

lyx

I'm migrating from standard LaTeX to LyX and I'm having issues with using \newcommand.

I like to leave around my texts some highlighted red texts (the idea is that I should fix something afterwards). I've done this in Latex just by including \newcommand{\replace}[1]{{\bf\color{red}{#1}}}
and afterwards just write \replace{ Confirm this ! } to leave the message.

I'm not being able to find on the internet a way of creating a "non-math" command with an input in LyX. Is there a way?

Thanks !

Best Answer

LyX supports the concept of Character Styles one can select from the Text Style menu.

enter image description here

However, to be available, character styles have to be defined inside a .layout file or in the document-local Local Layout field available under Document Setting. (The Local Layout basically can be understood as the LyX-specific preamble of the document.)

Add the following to the Local Layout:

## Character Style to be used for whatever Fancisco intends :-)
Format 49
InsetLayout Flex:replace
  LyxType               charstyle
  LabelString           Replace 
  LatexType             command
  LatexName             replace
  Font
    Series              Bold
    Color               Red
  EndFont
  LabelFont
    Series              Medium
    Color               Red
    Shape               Up
    Size                Tiny
    Family              Sans              
  EndFont
  Preamble
      \newcommand{\replace}[1]{\textbf{\textcolor{red}{#1}}}
  EndPreamble
  ResetsFont true
End

Now you have a new character style Replace available in your document.