When using the math-insert
LyX function to create an element that can contains other elements, the caret ends up inside that cell, and if some text is selected when the function is called, that text will also get inside that cell.
Now, this is usually a blessed behavior, but there are some occasions when I want it to behave like a math-insert
command that inserts an element that can't contain other elements – that is, I want the inserted TeX code to replace – not contain – whatever is selected, and the caret to end up after the the element, not inside it.
For example, when I want to bind some keys to math-insert \mathbb{R}
– a command that adds the symbol of the real numbers field. When I run this command, I don't want my caret to get inside the mathbb
element, and I don't want anything selected to get inside either – I just want to add the real numbers field symbol, the same way I add a Greek letter.
So, is there any other function that can help me, or an argument I can send to math-insert
, or anything else to solve that problem?
Best Answer
This is perhaps not very elegant, but you can use the following function for the shortcut:
math-insert \mathbb{R}
inserts a math inset with an ℝ, and the cursor to the left of the ℝ. The firstchar-forward
moves the cursor to the right of ℝ, but still within the\mathbb{}
. The secondchar-forward
moves the cursor outside the\mathbb{}
, but it is still within the math inset. Adding a thirdchar-forward
will move the cursor outside the math inset.