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.

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.

  • nice workaround! but I'm still wondering why things like \hat work flawlessly – Sparkler Dec 4 '15 at 2: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 4 '15 at 3: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.

  • It works, but I don't understand how... – Sparkler Dec 4 '15 at 4: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: tex.stackexchange.com/questions/208510/… – scottkosty Dec 4 '15 at 4:57
  • I meant self-insert (I know all the other ones...) – Sparkler Dec 4 '15 at 4: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 4 '15 at 5:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.