# Converting LyX to LaTeX

I'm working with a colleague who uses LyX (I use LaTeX), and we have a hard time exchanging documents because of conversion issues. Is there any easy way to convert LyX to LaTeX and vice versa?

-

Exporting Lyx to Latex is easy, although it is quite possible to have documents that look fine in Lyx, but which correspond to Latex code that doesn't compile. This happens if you have odd Latex code in the preamble or in Tex code boxes. But these are obvious enough to the Lyx user, because you can't produce dvi/pdf from the document. — Addendum: Another possible problem: inclusion of local files; then the document might compiler locally, but not when transferred. But this can be a Lyx to Lyx problem, also.

The other way is more likely to be problematic. Some possible problems:

1. Parsing — When Lyx imports Latex code, it has to parse it to recognise the structure of the document: section headings, formulae, &c. If it doesn't manage to parse a part of the Latex source, it gobbles up the code until it does recognise something and puts the part not understood inside a Tex code box. These code boxes might contain structure Lyx should have spotted, which is very easy to do if you use, say, packages that Lyx has not been programmed to digest. Unless you are doing anything very strange, you should be able to edit text paragraphs in the usual way. The Tex code boxes could be a problem for your colleague;
2. Character encoding — Make sure you use ASCII or UTF8 as your character encoding in your Latex source;
3. Lyx preamble — Lyx puts some code in the document preamble. There is the possibility that this inclusion will clash with the imported Latex preamble.

I'd say the course of least resistance is to use Lyx yourself. You have a fair bit of freedom mess about with Lyx's appearance using the preamble and Tex code boxes, and Lyx is pretty intuitive to a Latex user.

-

I'm using the export feature a lot nowadays. I actually always build PDFs with a script calling pdfLaTeX and don't use the PDF export feature of LyX. You don't have to use the GUI to export from LyX to LaTeX. This does the same on the commandline (replace pdflatex with latex if you're not using pdfLaTeX):

`````` \$ lyx --force-overwrite --export pdflatex document.lyx
``````

There is also a commandline version for importing, but since your colleague is using LyX anyway the GUI is probably good enough.

-