# Creating a Macros File for Lyx

I've created a set of macros in Lyx that I use continuously. I want to automatically include them in all my .lyx documents.

From what I've been reading in the forums, perhaps the most elegant way is to create a .sty file with my macros in it, save it in some folder, and then add stuff to the LaTeX preamble in the document settings of Lyx.

What I wasn't able to find is how to actually do the above, given that I'm not an experienced Tex/Lyx user. So my questions are:

1. How do you create and edit a .sty file?
2. What exactly do you need to type in the .sty file? Say I want the macro (I'm typing it as it appears in Lyx).

\sequence{#1}:=(#1)^\infty _{n=1}

I understand the above should be wrapped by some extra code (\newcommand etc.), but I don't know the precise format.

1. Where do you place your .sty file such that it can be included in all *.lyx documents globally? I'm a Windows user if it matters and I want to avoid adding it to every folder that contains a lyx document.
2. What do I need to type in the preamble? or more generally, how do I implement it in my document defaults?

Thanks!

• I'm not an expert on this, but I think you could just use a .tex file and \input that in the preamble. To save the preamble so it is used by default for all files, you can click on "Save as Document Defaults" in the Document > Settings dialog. A different approach would be to create a module. For more information on this, see Help > Customization. – scottkosty Mar 13 '17 at 19:17
• To be clear, are you speaking of LyX macros or LaTeX macros? From your example it seems that you want the former. – G.M. Mar 13 '17 at 20:15
• I'm not exactly sure on the definition, so assuming Lyx macros are a "composition" of math symbols and LaTex macros are more similar to ERT, then indeed the former, but I'm not sure whether my interpretation is correct. I want to add stuff such as integer symbols and vectors etc. by means of \Integers etc. – Yoni Mar 13 '17 at 21:59
• @Yoni Don't forget to notify the person your comment is targeted to. To do so, use the @ key, followed by the user name. Otherwise, they will not know that you directed a comment at them (unless they happen to check back on their own but usually this does not happen). – scottkosty Mar 14 '17 at 7:25
• @scottkosty Thanks for the tip. Also, are .tex files relevant for Lyx macros? If so, how do you make them and what is the correct formalism for macros? – Yoni Mar 14 '17 at 8:01

1. Define your macros as LyX macros as explained in Help > Math > Math macros in a file macros.lyx.
2. Use Insert > File > Sub-document to include macros.lyx at the beginning of your documents.
In practice, the macro file evolves with time so to avoid breaking the compilation or appearance of old documents you must create a new version (macros2.lyx...) before every major iteration.