2

I tried assigning two different shortcuts to inserting powers of ten:

command-sequence math-insert 10^{ }; up;
math-insert 10^{ }

However, if I select some text and then use one of the shortcuts, the selected text is replaced instead of being used as the superscript content.

In contrast, a "system-defined" math-insert command such as math-insert \hat does work both ways: if nothing is selected, a hat is inserted and the cursor is placed under the hat; if any text is selected, it is moved under the hat.

How can I make use of selected text when creating custom commands and command sequences?

EDIT: Curiously, this underbrace sequence works too

command-sequence math-insert \underbrace; char-forward; math-subscript;

unlike the power-of-ten example.

Sparkler
  • 929

2 Answers2

1

You can use cut/paste for this:

command-sequence cut; math-insert 10^{ }; up; paste

It has the unfortunate side-effect of modifying your clipboard. Hopefully there will be a way around this in the future.

scottkosty
  • 13,164
  • nice workaround! but I'm still wondering why things like \hat work flawlessly – Sparkler Dec 04 '15 at 02:31
  • @Sparkler you can. This is just a more general answer for how to use selections. I will give a separate answer that you might prefer. – scottkosty Dec 04 '15 at 03:48
1

Highlight the text and run the following command:

command-sequence math-insert ^; down; self-insert 10; up

which would for for both cases.

Sparkler
  • 929
scottkosty
  • 13,164
  • It works, but I don't understand how... – Sparkler Dec 04 '15 at 04:04
  • It works just like math-insert \hat above. math-insert says that the following argument will be a math command to operate on the selected text. The argument ^ says to put in the numerator, whereas \hat says to put a hat over the text. By the way you might be interested in this answer which discusses how to figure out which commands to use: http://tex.stackexchange.com/questions/208510/lyx-commands-to-insert-wysiwyg-horizontal-line-for-keyboard-shortcut/208531#208531 – scottkosty Dec 04 '15 at 04:57
  • I meant self-insert (I know all the other ones...) – Sparkler Dec 04 '15 at 04:59
  • ah, self-insert just inserts the following text directly. You might be interested in Help > LyX Functions which documents the usage of functions and gives examples. – scottkosty Dec 04 '15 at 05:07