Search:   Help



LyX documentation


Shared groups



Categories: Uncategorized
<< | Page list | >>

1.  Creating keyboard macros

You can make your own keyboard macros by by adding a line like this to your .bind-file, (create your own bind-files in the LyX/UserDir)

 \bind "C-a"  "command-sequence math-mode; math-insert \myPI;"   

\myPI is just some made up latex-command in this example. Also see Tips.KeyboardShortcuts.

1.1  Tips for creating command sequences

  • See CommandSequencesTips for tips on how to create and test your command sequences using the mini-buffer in LyX.
  • See LyxFunctions for a list of LFUNs (i.e. commands) that can be used in command sequences.
  • The LFUN self-insert is very useful. Note that it can insert several characters at once: "command-sequence self-insert All of this is inserted;"

2.  Examples

Below is a list of miscellanous command sequences that can be used for defining your own keyboard macros.

2.1  Convert to latex command

This sequence converts the marked region into a latex command (i.e. '\' is added in front and {} is appended):

 "command-sequence cut; ert-insert; self-insert \; paste; self-insert {}; inset-toggle;"  

This sequence selects the current word, cuts and pastes it inside an ERT as a latex command:

 "command-sequence word-select; cut; ert-insert; self-insert \; paste; self-insert {}; inset-toggle;"  

2.2  Convert selection to argument of a latex command

Ex: "Using EFDO gives bla bla" -> "Using \lsc{EFDO} gives bla bla"

 "command-sequence cut; ert-insert; self-insert \lsc{; paste; self-insert }; inset-toggle;"  

2.3  Indent marked text using ERT

This command sequence cuts the marked text, inserts an ERT, the marked text and then a second ERT. The ERT's adjusts the left margin, making the text become indented."

 "command-sequence cut; ert-insert; self-insert {\addtolength{\leftskip}{1cm}; inset-toggle; paste; break-paragraph; ert-insert; self-insert }; inset-toggle;"  

Note that the entire first paragraph that is marked will be indented. Also note that a break-paragraph will be inserted just before the last ERT, which means that if the selected text ends in the middle of a paragraph, the paragraph will be broken there.

2.4  Songbook class

This sequence is used to cut marked characters and paste them into a math-macro called \Ch (short for Chord).

  \bind "M-S-C"   "command-sequence math-mode; line-end; math-insert \Ch; char-backward; line-begin-select; cut; char-forward; paste; down;"  

The preceding doesn't seem to work in Lyx 2.0.6 in Ubuntu 13.10. The following does work (type the chord over the asterisk)

  \bind "M-S-C" "command-sequence math-mode; char-forward; word-forward-select; math-insert \Ch\ ; inset-toggle; line-end; char-forward; math-insert *; inset-toggle; char-backward-select;"

2.5  Cursor movement up/down "between" paragraphs

These bindings requires a patch by Alfredo, that makes the cursor become horizontal when a new paragraph is inserted. This is a patch under development, and not part of the standard lyx versions.

 \bind "C-Up" "command-sequence paragraph-up; break-paragraph;"
\bind "C-Down" "command-sequence char-forward; paragraph-down; break-paragraph;"  

2.6  Adding a comment with the text: "Add stuff"

This sequence adds a new paragraph in the Comment layout, with the text "Add stuff". It's supposed to be a reminder for you to add stuff later on"

 "command-sequence paragraph-down; char-backward; line-end; break-paragraph; depth-increment; layout Comment; self-insert Add stuff\?;"   

2.7  Starting the spellchecker from the beginning of the buffer

This command sequence places a bookmark (called before-spellcheck) at the current position, then goes to the beginning of the buffer, and finally starts the spellchecking.

 "command-sequence bookmark-save before-spellcheck; buffer-begin; spellchecker;"  

You can use this command sequence to go to the bookmark.

 "command-sequence bookmark-goto before-spellcheck;"  

These two command sequences could then be bound as follows: \bind "S-F7" "command-sequence bookmark-save before-spellcheck; buffer-begin; spellchecker;" \bind "C-F7" "command-sequence bookmark-goto before-spellcheck;"

It doesn't work to put "bookmark-goto before-spellcheck" at the end of the first command sequence, since you get some kind of interference between the spellchecker and going to the bookmark.

2.8  Inserting a figure float with centered figure

Insert a figure float, open a paragraph for the actual figure, insert \centering as ERT, open the figure-file dialog

\bind "C-S-B"     "command-sequence float-insert figure; char-left;up;ert-insert; self-insert \centering; inset-toggle; char-right;dialog-show-new-inset graphics"

2.9  Inserting a table float with centered paragraph for future table

Very useful if you work with lots of tables!

"command-sequence float-insert table; down; paragraph-params-apply \align center;"

2.10  Inserting two figures side by side

The example from FiguresSideBySide needs a lot of mice/keyboard interaction to write, and if you want to reuse it, you will find copying the float, and modifying it to avoid rewriting it. A more elegant approach is with a command sequence.

command-sequence float-insert figure ; escape ; char-delete-backward ; paragraph-params-apply \align center ; box-insert Frameless ; word-backward ; inset-modify box Box Frameless position "t" hor_pos "c" has_inner_box 1 inner_pos "t" use_parbox 0 use_makebox 0 width "45line%" special "none" height "1in" height_special "totalheight" ; word-forward ; inset-insert space \hfill{} ; box-insert Frameless ; word-backward ; inset-modify box Box Frameless position "t" hor_pos "c" has_inner_box 1 inner_pos "t" use_parbox 0 use_makebox 0 width "45line%" special "none" height "1in" height_special "totalheight" ;

2.11  Shortcuts for math-text-super/subscripts

Math superscripts/subscripts do look OK if you place the text you want to super/subscript inside a \text{} command, with the added benefit of being able to preview the effect in LyX. You can set up some nice keyboard shortcuts to do this by adding the following to your .bind-file:

% Control-Alt-equals - Replace selected text with text subscript
\bind "C-M-equal" "command-sequence cut;math-mode; math-subscript; math-insert \text{;paste;math-insert };char-right;char-right;char-right"
% Control-equals - Enter text subscript mode
\bind "C-equal" "command-sequence math-mode; math-subscript; math-insert \text{};char-right;char-right;char-right;char-left;down;char-left;"
% Control-Shift-Alt-equals - Replace selected text with text superscript
\bind "C-S-M-plus" "command-sequence cut;math-mode; math-superscript; math-insert \text{;paste;math-insert };char-right;char-right;char-right"
% Control-Shift-equals - Enter text superscript mode
\bind "C-S-plus" "command-sequence math-mode; math-superscript; math-insert \text{};char-right;char-right;char-right;char-left;up;char-left;"

Note: if you have copied and pasted the above correctly, you should have exactly 8 lines (each starting with either \bind or %).

2.12  Shortcuts for vector operators

These somewhat elaborated shortcuts should be a useful source of inspiration for LyX users looking for shortcut examples. I have put an arrow on vector quantities, in accordance with the french tradition on the subject.

% curl
\bind "M-j c" "command-sequence math-insert \\vec;font-roman;math-insert curl;char-forward;char-forward;space-insert protected;"
% divergence
\bind "M-j d" "command-sequence math-insert;font-roman;math-insert div;char-forward;space-insert protected;"
% gradient
\bind "M-j g" "command-sequence math-insert \\vec;font-roman;math-insert grad;char-forward;char-forward;space-insert protected;"


Edit - History - Print - Recent Changes - All Recent Changes - Search
Page last modified on 2015-02-16 09:05 UTC