14

I'm using LyX for technical documentation and want to automate the process of creating PDF files.

Within LyX, I can simply click the button "View PDF (XeTeX)", and LyX performs the whole build process for me: it creates a .tex file, does some bibliography magic, and uses XeTeX to create the final PDF file.

What I'm looking for is a way to call LyX from the command line and get the same result. So far, I've only managed to generate a plain .tex file (using --export-to xetex). However, when I run xelatex on the generated file, it keeps showing errors that don't occur when building using LyX. Is there a way to get LyX to do the work?

My system: Windows 7 64bit, LyX 2.1.0

  • I could have sworn this didn't work before, but now it works great. @HarishKumar: If you make this an answer, I'll accept it. For the record: The "short name" of "PDF (XeTex)" is "pdf4". – Daniel Wolf May 5 '14 at 9:28
  • Daniel: I have added an answer. Thanks for the pdf4 thing :) – user11232 May 5 '14 at 9:45
  • You can go to Tools > Preferences > Editing > Shortcuts and create new key-bindings for buffer-export xetex and buffer-export pdf4. You can refer to Help > Lyx Functions for the command syntax including specifying a destination. – user21820 Mar 15 '15 at 5:18
8

The command sequence for exporting .lyx files to pdf/dvi (etc) from command prompt 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. You may see the File Formats pane in LyX's preferences dialog for a list of the available formats.

For example, to convert .lyx file to pdf using xelatex, the command will be

lyx --export pdf4 myfile.lyx

On the other hand, you may prefer to use a .bat file so that you can put the .bat file in the same directory as your .lyx file and simply double click on it.

@ECHO ON
cls

REM export lyx files to pdf using xelatex

CD /D %~dp0
SET Programa="lyx.exe"
for %%A in (*.lyx) do %Programa%  --export pdf4 %%A
Pause

Save the above as lyxbatch.bat (say), in the same folder as your .lyx file. Double clicking on this file will export all .lyx files in the current folder to pdf files using xelatex. You have to havelyx.exe` added to your system path.

Untested as I don't have lyx installed in this computer. If there are any hassles please let me know.

  • 2
    Just to add that as noted on the LyX Wiki, you may have to add start /wait to the front of the command, e.g. start /wait lyx --export FORMAT myfile.lyx. – Kenny LJ Oct 24 '18 at 9:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.