Automating layout with Tetex or Lyx

Q I would like to print an image, JPEG or BMP, and a text file in one report. Is there any freeware that would allow me to do this easily via the command line? I want to pre-generate reports via a script automatically.

A Yes, there are a number of ways to do this. Which one you choose depends on the quality of output you need and how much time you are prepared to spend implementing it. The easiest way is to write the report to HTML, which can be viewed or printed in a browser. The following shell script will take the names of an image and a text file and write the HTML to standard output. It's a very basic example, but you'll get the idea.

#!/bin/sh
echo "<html><head><title>My Report</title></
head><body>"
echo "<img src=\"$1\" align=\"right\">"
cat $2
echo "</body></html>"

At the other end of the spectrum would be one of the Tex-based packages, such as Tetex or Lyx. These are typesetting programs that give you a great deal of control over the finished document's layout. The learning curve is steep, but the results may justify it. Tex source files are plain text, so it would be easy to generate them from the command line using a template file and a short shell script. Lyx provides a somewhat simpler means of producing Tex files. It is a graphical application, but once you have created your template you could manipulate it with a shell script. You have a choice of splitting the template into three and doing something like this:

cat template1.lyx >report.lyx
echo /path/to/my/image >>report.lyx
cat template2.lyx report.txt template3.lyx >>report.lyx

Or you could do something more complex by using sed to replace parts of the template with your text and image files. Once you have the report.lyx file, you can output it in a number of formats, all at the highest quality. For example,

lyx --export pdf report.lyx

will produce a PDF report. Lyx is a powerful program with detailed online help. Give it a try. An alternative is to use the scripting capabilities of a word processor or page layout program such as OpenOffice.org, AbiWord or Scribus.

Follow us on Identi.ca or Twitter

Username:   Password:
Create Account | About TuxRadar