Is it possible to create a custom macro files in LyX, and importing it to documents (even automatically, via settings)?

I have some macros that I use frequently, and I don't want to type them/copy them every to every single document.

How can I avoid it?

Thanks in advance. :)

2 Answers 2


If you want the same macros to be loaded in all your documents, make a new, empty file, go to Document --> Settings --> LaTeX preamble, add your macros here, and then click the button Save as Document defaults. All new documents you create afterwards will have those same macro definitions in the preamble.

If you want different defaults, I'm not sure what's the best way. You could just make different .tex files, and \input the appropriate one in the preamble.

Another option could be to make your own modules. This is described in Help --> Customization, section 5.3. A very simple example is something like this:

#Provides some macros I frequently use

#Author: Some Bloke

Format 60


Save this as homework.module, in the layouts subfolder in your LyX user directory (https://wiki.lyx.org/LyX/UserDir). E.g. on my system, that's in ~/.lyx/layouts. Restart LyX (possibly run Tools --> Reconfigure, but not sure if that's necessary), and in Document --> Settings --> Modules, you should see homework at the bottom of the list.

  • But what if I want to have different documents into which I have those macros? For different uses, for example, a homework file, a file for an exam, etc. Then I couldn't use multiple default document. Mar 4, 2017 at 11:23
  • @GalGrünfeld No, that's true. I edited my answer. Note that you can do a more with modules than just add macros to the preamble, e.g. make new styles that will be available from the style-dropdown menu, but I'm really not familiar with such LyX customizations, so reading the mentioned Help-document is my best advice. Mar 4, 2017 at 11:50

You can create a LyX file that contains your macros, then import it into another LyX document using the menu option Insert > File > Child Document.

You must log in to answer this question.

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