1

I would like to input the body of a lyx file into a tex file.

Currently I convert the .lyx file (say child.lyx) to child.tex in Lyx with File > Export > Latex, and use \input{child.tex} in the main .tex document, also using the standalone package to only copy the body, which works.

Somehow, if I have my main document in LyX and use \input{} in Lyx (Insert > File > Child Document ...), it works as well, but directly using \input{child.lyx} in LaTeX doesn't work.

Is there a way to avoid the conversion step, so that I could simply write in child.lyx and compile main.tex file, without having to convert the lyx file first each time?

Ingmar
  • 6,690
  • 5
  • 26
  • 47
  • there is no way to insert a LyX document with \input{} inside LaTeX. Only the other way round is possible. – user187802 Jul 06 '23 at 17:46
  • I see. But is there any way I could input the tex code in the code preview pane that I see in Lyx into a tex document besides copy-pasting it? – Alexei Alexei Jul 06 '23 at 18:37
  • Please refer https://tex.stackexchange.com/questions/2950/converting-lyx-to-latex – MadyYuvi Jul 08 '23 at 11:57

1 Answers1

1

LyX is mainly a front-end to LaTeX format (and other formats, but this is another history) and it seems able to convert the main and child LyX files to a PDF directly, but in the background, making the PDFs is the exclusive business of LaTeX.

LaTeX is not at all a front-end of LyX, it have no idea about any other format, so simply it cannot manage \input{child.lyx}.

In the screen you can see Input: child.lyx but if you open un the menu the Code Preview Pane you will see that the latex version will be \input{child.tex}. LyX will take care of export the child files behind the scenes when needed, but for LaTeX, the LyX files are a parallel universe.

Note that in LaTeX he extension .tex is assumed when \input or \include have an argument without extension tha is not found (e.g.: \input{foo} search first for file foo.tex and if this file does not exist, will search only foo). For some unknown reason, LyX omit the extension only for \include, so Include: child.lyx will be exported as \include{child} instead of \include{child.tex} but in any case Latex will search for child.tex.

mwe

Fran
  • 80,769