# About some shortcuts used in LyX

Please tell me how to use shortcuts in LyX to implement the codes below

$\sum\limits_{\substack{0<k<p\\\gcd\left( k,p\right) =1}}$


Notice that do not use the function of inserting TeX code in LyX!

By the way, it is very easily implemented in Scientific Workplace.

Just like that

1. Ctrl+sum

2. Ctrl+F5

3. TAB

4. ENTER

5. Ctrl+l

6. 0<k<p

7. ENTER

8. gcd(k,p)=1

That's all!

The primary difficulty in LyX is that the Step 8 can not be easily implemented, so I ask the question here.

Wait for your elegant solution...

-

## 2 Answers

To define complex shortcuts in LyX, the command-sequence functionality is very useful.

To construct exactly a sum with the limits as described, and position the cursor after the sum sign, but still in the math box, you can use

command-sequence math-insert \sum \limits _{}; down; math-insert \substack{}; newline-insert newline; math-insert 0<k<p; down; math-insert \gcd \left( k,p \right); char-forward; char-forward


Here, the ; marks a new command. The newline-insert newline does the trick of Enter. The cursor is moved by down and char-forward. Not used here, but available, are also up and char-backwards

(This is a cumbersome way of doing so, and could be replaced by command-sequence math-insert \sum\limits_{\substack{0<k<p\\\gcd\left( k,p\right) =1}}; char-forward; char-forward -- it is merely meant to illustrate the constructions used).

To produce just the sum with the two-rowed substack and the cursor in the top row, use

command-sequence math-insert \sum \limits _{}; down; math-insert \substack{}; newline-insert newline


From there, you should be able to move with the arrow keys and just type what you want (combined with shortcuts for \gcd etc. as suggested in Torsbjørns answer).

-

I'm not that familiar with LyX, but I think you have to add three new shortcuts to be able to add all of that using keyboard shortcuts only. If you do not know how to do this, see my answer to Shortcuts for Lemma, Claim, Theorem etc.

I added keyboard shortcuts for \substack, \gcd and \left( \right). The LyX functions (and keyboard shortcuts) I used were as follows. You can of course choose whichever keyboard shortcut that suits you and doesn't conflict with existing ones.

• math-insert \substack

Ctrl+Alt+Shift+0

• math-insert \gcd

Ctrl+Alt+Shift+G

• math-insert \left( \right)

Ctrl+Alt+Shift+P

The sequence for inputting your example will then be as follows, assuming you are in math mode:

1. Alt+MU - enters summation sign
2. Alt+MX - adds subscript
3. Alt+ML - adds \limits
4. Ctrl+Alt+Shift+0 - see above, begins a \substack.
5. 0<k<p
6. Ctrl+Enter - starts a new line in the substack ...
7. - ... but doesn't move the cursor it seems.
8. Ctrl+Alt+Shift+G - see above, enters \gcd
9. Ctrl+Alt+Shift+P - see above, enters \left( \right)

(these two can be done as one, hold down the modifiers and hit G followed by P)

10. k,p
11. = 1
-