Edit Links |
Tips /
CommandSequencesCategories: Uncategorized << | Page list | >>Table of contents (hide)
1. Creating keyboard macrosYou 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
2. ExamplesBelow is a list of miscellanous command sequences that can be used for defining your own keyboard macros. 2.1 Convert to latex commandThis 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 commandEx: "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 ERTThis 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 classThis 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" paragraphsThese 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 bufferThis 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 figureInsert 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 tableVery 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 sideThe 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.
2.11 Shortcuts for math-text-super/subscriptsMath 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:
Note: if you have copied and pasted the above correctly, you should have exactly 8 lines (each starting with either 2.12 Shortcuts for vector operatorsThese 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.
|