The subfiles
package as workaround
A simpler workaround would be using the \subfile
command of the subfiles
package, which automatically strips the document skeleton.
It's meant for making child documents compilable on their own, but by extension also fits this usecase.
Using a parent/child pair for export without preamble.
It does not help, if the purpose is to export to latex for inclusion in a journal template, where loading extra packages isn't allowed. In this case a viable workaround is to create a file main.lyx
with child document child.lyx
, and export from main.lyx
recursively, which produces a preamble-free child.tex
.
Automation as a script
This could also be easily automated as a script, by exploiting the straight-forward file-format of .lyx
documents:
- Create a
.tmp.lyx
with the same \begin_header ... \end_header
as child.lyx
to ensure consistent export of styles and insets.
- Make its
\begin_body ... \end_body
contain only the child-document link.
- Export
.tmp.lyx
to .tmp.tex
. This will create the desired child.tex
.
- Remove the unnecessary
.tmp.*
files.