Search:   Help

Navigation

Groups

LyX documentation

Edit

Shared groups

Links

FAQ /

ImportExport

Categories: Import, Export, FAQ, Word, HTML
<< | Page list | >>

Importing and Exporting Other Formats

§1.  How do I convert LyX files from the command line?

The exact details depend upon how you can call LyX itself from the command line on your platform (try lyx --help), but if we ignore that, then what you want is:

lyx --export FORMAT myfile.lyx

where FORMAT is the short identifier of the format you want to export, e.g., "dvi" for DVI files or "pdf2" to export PDF via pdflatex. (See the File Formats pane in LyX's preferences dialog for a list of the available formats.) This (--export) will create the output file in the same directory as the input file. To specify the output file and path, use --export-to , or -E e.g:

lyx --export-to pdf2 c:\temp\afile.pdf afile.lyx

(win7) this results in a windows error box: "Lyx.exe has stopped working". This is avoided by using start /wait command to wait until lyx has finished.

start /wait lyx --export-to pdf2 c:\temp\afile.pdf afile.lyx

§2.  How do I select Branches when exporting?

Often the point of exporting from the commandline is to build different variants of the document.

lyx -x "command-sequence branch-activate b1; branch-deactivate b2" -E pdf2 outfile.pdf infile.lyx

§3.  Can I read and write Word files?

Yes, but not trivially, and you should not expect to be able to collaborate with someone using Word to edit your paper. You can import Word files, and you can export Word files, but going "roundtrip" is not workable.

§3.1  How can I import Word and Libreoffice/Openoffice files?

Reading Word files essentially means converting them into LaTeX and then importing that into LyX. So the real question is: How can you convert Word files into LaTeX?

There are several options, and the available converters and half-measures change rapidly. Remember to search the user's mail list, for instance at [1]. All of these have limitations, however, because Word is inherently not a markup language like LyX and LaTeX.

Here are some main options:

  1. Pandoc. If installed, LyX will configure it automatically to import from Office Open XML and OpenDocument. See this How-to on Pandoc export for instructions to install Pandoc. (If you use LyX version 2.1 or earlier you will need to set import converter commands.)
  2. the writer2latex extension for Libreoffice and Openoffice. This will produce usable LaTeX, but it tends to be pretty ugly, as Writer2latex tries to preserve the visual appearance of the document instead of its structure.
    1. Manually: open your Word or OpenDocument in Libreoffice or Openoffice. Go to File > Export, choose LaTeX2e as the export format.
    2. Rob Oakes has written a set of programs that can automate this process, allowing import directly from LyX.
  3. LyXConverter is a Microsoft Word add-in that converts Word documents directly into LyX documents without first going through LaTeX. (Commercial software with evaluation period.)

Other options include wvware (last updated 2006), which is also available from within Abiword.

§3.2  How can I export Word and Libreoffice/Openoffice files?

For exporting MS Word or Libreoffice / Openoffice documents, the main options are:

  1. Pandoc. See the Tip page on how to export Office Open XML and OpenDocument files with pandoc. This includes reasonable equation support (MathML).
  2. Latex2rtf. This converter generates rich text format (.rtf) files, which can be read by almost any word processor. See the Tip page on how to use export to RTF with Latex2rtf. This includes reasonable equation support (MathML).
  3. TeX4ht. This converter is mainly designed to produce html files, but includes a converter (oolatex) that can produce OpenDocument files. Note however that it will export many characters and special typesetting (e.g. math formulas) as images, which is unsuitable for some purposes.
  4. Export to HTML. Most word processors will import HTML, so that can be used as an intermediate format, too. See below for information on HTML export.

If LyX's configure script finds any of Pandoc, Latex2rtf or TeX4ht, it will configure the converter for you and make it available under File>Export.

§4.  How can I read and write HTML files?

To read HTML files, use a program that converts HTML files into LaTeX, such as html2latex or gnuhtml2latex, and then import the resulting LaTeX file into LyX.

For writing HTML files, there are three sorts of options:

  • LyX -> LaTeX -> HTML This relies upon an external LaTeX->HTML converter, such as htlatex (from the tex4ht package), tth, plastex, etc. If LyX finds such a converter, then it will configure it for you, and HTML output will be available under File>Export. These work pretty well for simple documents, but can get confused by more complex ones. Math is usually output as images, which are accurate, but do not scale well and cannot be edited, copied, etc.
  • LyX -> HTML: The elyxer program, by Alex Fernandez, converts LyX files directly to HTML, without the intermediary step. Math is output as HTML and CSS. Again, elyxer works well for simple documents, but complex math does not export well, and some LyX features are (as of August 2010) not supported, or have only limited support. Again, if LyX's configure script finds elyxer installed, it will configure it for you.
  • LyXHTML: As of LyX 2.0, LyX will be able to export XHTML natively, i.e., without relying upon an external converter. More information is available elsewhere.

§5.  I've got TeXinfo document source. How can I convert this into LyX format ?

Try texi2latex (http://savannah.nongnu.org/projects/texi2latex)

§6.  How can I set the length of automatic line wrapping when exporting as text (plain text, LaTeX, HTML, SGML) file?

In Tools→Preferences→Output→General, adjust the value of Output line length.

§6.1  What if I really do not want any line break?

If you do not want any line breaks within paragraphs, set Tools→Preferences→Output→General→Output line length to 0.

If you do not want any line breaks at all, use sed:

sed ':looop
 $!{
 N
 s/\n/ /
 tloop
 }' your_ASCII_file.txt > a_file_with_a_single_really_long_line.txt


§7.  Why does the filename of the exported .tex/ps/pdf differ from the filename of my .lyx-file?

In some cases, LyX changes the file name. It does so while exporting to the temporary directory (within the View/Export process) if you have a multi-part document in order to disambiguate file names, and sometimes it does so if it thinks the given file name will not work (e.g. with your version of TeX or your system encoding).

Import, Export, FAQ, Word, HTML

<< | FAQ.PageList | >>

Edit - History - Print - Recent Changes - All Recent Changes - Search
Page last modified on 2016-11-08 22:44 UTC