Some time ago I've suggested to allow for differentiating preambles wrt branches, ie. allowing different preambles for different branches in the same document.
Granted, this change was probably too big, and too little would be gained... but now I have some idea which, as I suppose, would be far easier to implement. The idea is to use the "preamble inset", which will look just like the ERT, but instead of inserting the TeX code inside the document, it will append this code to the end of the preamble (preferably with a newline at the end). That way the goal of multiple preambles could easily be achieved by putting such "preamble insets" inside branches. Additional benefit would be that if someone wants to use some package only because some particular feature used only in one place (some single function plot), the "\usepackage" command, along with the related parameters, could be grouped together with the requiring part of the document, which will improve readability in such cases. For reference, similar ideas appeared briefly in 1999 and in 2003: http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg04013.html http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg57149.html Unfortunately, I don't know LyX internals at all, so I am unqualified to code it myself. However, I do hope that this idea is worth implementing. Regards, MichaĆ Skrzypek