## How to export from LyX to LaTeX

All of this information is out there, but it took me more than a few hours to successfully manage this on my Mac, so here are the steps, using LyX and TeXShop.

1. Go to File->Export->LyX Archive
This generates a zipped tarball of your .lyx file and, crucially, all the other elements (such as graphics and bibliography) in a hierarchy of files.
2. Unroll the tar ball (i.e. `tar -xvzf yourarchive.tar.gz`) in a suitable place.
You now have all the files you need in a standalone hierarchy (best to place your tarball in its own directory before you do this as the subdirectories you create could go under your root directory etc)
3. Convert the LyX file to raw LaTeX.
At this point all you have a LyX archive and if you really need LaTeX you need to convert the LyX file. On a Mac the easiest way to do this is to point LyX.app at the .lyx file in your archive and open it, then run another export – this time to LaTeX (pdflatex). This will create a .tex file in your archive. (I messed this stage up in the original posting – thanks, as always to Paul Rubin for putting me on the straight and narrow here.)

4. Make sure your bibliography is in the right place.
Your bibliography needs to be in the same directory. So if your .tex file is in the bizarro directory, your bib file must be too. (I said before it should have the same name as your .tex file but that is not necessary.)
5. Open your .tex file in TeXShop.
You may need to do some editing, for instance if your .tex file refers to your bibliography  under some path, so for the example above you need to make your bibliography reference look like this:
```\bibliography{bizarrothings} ```

6. Run the following sequence of commands in TeXShop:
Typeset LaTeX
Typeset BibTeX
Typeset LaTeX
Typeset LaTeX

Hopefully you now have compiled a PDF file with all the correct references, which means if you package up your archive directory it will now contain the correct .tex file (it will also contain the PDF and .lyx file unless you delete them first).

Hope this is helpful – if I have missed anything, let me know in the comments.

### 4 responses to “How to export from LyX to LaTeX”

1. prubin73

I’m curious why you are taking this approach, as opposed to the usual one (for LyX users): Document > View [PDF (pdflatex)] to make sure all the bits look correct, then File > Export > PDF (pdflatex) to export a compiled PDF file. You can substitute an alternative to pdflatex in both commands if you prefer. Does this not work for you?

2. A collaborator, namely my PhD supervisor, wants to edit the paper for length with a view to submitting it for publication.
He’s a LaTeX rather than LyX guy, though I think he’s used LyX before.

3. prubin73

Okay, I see. The non-LyX-using coauthor is a common problem. One other thing: You said to run texi2pdf against the .lyx file? Does that work? I thought you would have to export to a .tex file.

1. Ah, you’ve spotted the flaw! I think I have elided two steps there. I’ll have to edit that and fix it in the morning. Thanks (as always!)