I use LyX especially for writing math, and I created my own bind file for my preferred shortcuts.

Among other commands, I defined shortcuts that insert a command-sequence, for inserting long data easily. for example, I have the following shortcut assigned:

\bind "C-S-L x 1 n" "command-sequence self-insert x; math-subscript; self-insert 1; char-forward; self-insert ,; math-insert \ldots; self-insert ,; self-insert x; math-subscript; self-insert n; char-forward;"

This sequence generates a list of variables, named x_1 to x_n, separated by dots and commas. As can be seen, I use a shortcut that defines exactly the variable type I want to insert, and the needed range for the sequeunce. Soon enough, I realized I want all sorts of these sequences that only differ in their variable name ('x', here) and their range (1 to n, here).

My question is - is there any way to define a 'dynamic' shortcut, in that sense it will generate the wanted sequence according to three given arguments, instead of defining each of these as a separate shortcut?

Thanks for the help.


Why don't you use math macros? In LyX menu: Help/Math/22.2 Math macros. If you still need a special shortcut afterwards, you just bind the shortcut to inserting the command of your macro and that should simplify editing even more.

  • thanks for the tip. I still prefer to use command sequences as I described above, since inserting them gives exactly the requested expression. Using math macro, though, as far as I get it, only lets me create some kind of patterns. After inserting a macro I have to go back and fill in the data manually - and that's exactly what I don't want to do (mostly for typing speed reasons). Besides, macro are only available in the document where they were defined - and that means redefining them for each document, but binding a command sequence is available globally.
    – Mosheke
    Jul 13 '12 at 16:12
  • @Moasheke: I am not sure I understand what you mean. A math-macro defines a new command with the name of the math macro. A macro can have zero arguments, i.e., it defines a static math expression. It can however also have arguments so that your macro can be arbitrarily parametrised. Now let's say you need all sorts of expressions of the template <var>_1,\ldots,<var>_<range>. You define a macro with two arguments for <var> and <range> and all occurences of those will get automagically filled in. Macros can be reused as well.
    – walkmanyi
    Jul 13 '12 at 22:43
  • I understand that macros can be set to be fixed expressions ("zero arguments") or some kind of templates (taking arguments). Still, when using a macro, this template is inserted and I have to manually fill in the arguments. Is there any way to give the arguments together with the macro name in advance - so as soon as the expression is generated it will hold the given args? otherwise it means going (almost) from box to box filling them up - which doesn't take too long, but I just want to make sure. Also, how do I use macro in another document without redefining it every time? tnx.
    – Mosheke
    Jul 14 '12 at 23:08
  • Macros: I think the best way to find out is to play with it. Again: macros are in fact just new commands. I.e., macro is not only a template. Consider it an arbitrary expression optionally with placeholders for parameters of your interest (variable name, index range). As for the second question regarding macro re-use, you are right, you would need to redefine it again and again. But in my case copy&paste are working just OK for the set of macros I use often.
    – walkmanyi
    Jul 14 '12 at 23:25
  • Is there some way to get LyX to not replace \foo from a two argument macro \foo{#1}{#2} with the LyX graphical representation before both arguments have been typed in as well?
    – Rasmus
    May 10 '14 at 21:29

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.