I'm using LyX all the time and over the last 2 years I've accumulated some very handy macros for my lecture notes. As it is today, every time I start a new document, I copy and paste the macros from one of my other documents. Is it possible, somehow, to automatically load macros for all files?

(I asked this on SO a while back and got no answers. I hope in this new home I'll get a response).

2 Answers 2


I am not sure if you mean LyX macros or not. But if they are standard LaTeX macros, you can make your own style file, say "rachum.sty". Put all of your macros in there, and then have it included in the preamble by default.

This is useful for (La)TeX users in general. I have a lot of common things in my own file, such as \newcommand{\Integers}{\mathbb{Z}} and such.

  • I guess I meant LaTeX macros, it's just that LyX has this pretty graphical representation of them that I don't think of it in terms of LaTeX :) I would, however, appreciate it if you could tell me what the format of the .sty file should be (headers, etc.) and what the command is to include it. Thanks. Jul 26, 2010 at 19:34
  • Just type the macros in the style file how you would normally. It doesn't need any special formatting. If you know C, pretend it's like a C include file. :) But as an example, you could very well just have \usepackage{amsmath,amsfonts} \newcommand{\Integers}{\mathbb{Z}} \newcommand{\Naturals}{\mathbb{N}} in the file. Then just \usepackage{rachum} or \input{rachum.sty} and you should be good to go. Jul 26, 2010 at 19:40
  • while this is very convenient for a user's own documents, if you are submitting a document for publication, please move just those definitions actually used in the document into that document's preamble. extraneous, unused definitions can cause a great deal of confusion in a publishing production environment, and can lead to errors that you weren't expecting when changes must be made to conform to the publication's requirements. Mar 28, 2018 at 12:57

You can put all your macros in the Preamble in Documents → Settings, then click Save as Document Defaults.

These macros should then be present in every new LyX document.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .