Hello,

A little shell script to translate lyx documents to pdf has come into being!

Maybe someone can make use of it or someone is in the mood to integrate some
parts of it in the LyX code. A PDF-export function would be nice ...

Thanks to Herbert Voss and Matej Cepl for telling me how the translation works.

And ... feel free to improve it! :-)

Cheers

  Steffen

PS: I am only on the user list.
#!/bin/bash

#      lyx2pdf - script for translating lyx docs to pdf
#
#      Copyright (C) 2000 by Steffen Evers ([EMAIL PROTECTED])
#
#      This program is free software; you can redistribute it and/or modify
#      it under the terms of the GNU General Public License as published by
#      the Free Software Foundation; either version 2 of the License, or
#      (at your option) any later version.
#
#      This program is distributed in the hope that it will be useful,
#      but WITHOUT ANY WARRANTY; without even the implied warranty of
#      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#      GNU General Public License for more details.
#
#      You should have received a copy of the GNU General Public License
#      along with this program; if not, write to the Free Software
#      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
# Credits:
# Thanks to Matej Cepl and Herbert Voss for helping me with latex stuff!
#
# Version History:
#
# Aug 13th, 2000 -- Version 1.2
#   initial version
#

##### You will need pdftex and epstopdf for the translation!
##### See pdftex homepage for details: http://tug.org/applications/pdftex/
##### Have fun!!!

###### set environment variables
LYXDOC=$1
DOCUMENTBASE=`basename $LYXDOC .lyx`
LYXPATH=`echo $LYXDOC | sed -e "s/^\(.*\)$DOCUMENTBASE\.lyx/\1/"`
TEXDOC=${LYXPATH}${DOCUMENTBASE}.tex

##### some variables not usedi ...
#VERSION=`rlog ${LYXPATH}$DOCUMENTBASE.lyx,v | sed -n "s/^head: 
\([[:digit:].]*\)$/\1/1p"`
#TRANSTIME=`date`

##### export TEX file with lyx (needs a display!)
mv $TEXDOC $TEXDOC~
lyx --export tex $1

##### get title, author and images from the produced tex file
TITLE=`sed -n "s/^.title{\(.*\)}.*$/\1/1p" $TEXDOC`
AUTHOR=`sed -n "s/^.author{\(.*\)}.*$/\1/1p" $TEXDOC`
IMAGES=`sed -n "s/^.*includegraphics{\([^}]\+\.\(e\)*ps\)}.*$/\1 /p" $TEXDOC`

echo
echo Document title: $TITLE
echo Document author: $AUTHOR
echo "Identified images (.eps/.ps):" $IMAGES
echo

####### Insert pdf conversation tags in tex file and write to foo-pdf.tex
### some possible colors:red, green, cyan, blue, magenta, black
### some possible paper sizes: a4paper, letterpaper, legalpaper, executivepaper
### see hyperref manual for more:/usr/share/texmf/doc/latex/hyperref/manual.pdf
sed -e "s/\(\\includegraphics{[^}]\+\.\)\(e\)*ps}/\1pdf}/g" -e '/^\\makeatother$/{i 
\\usepackage{pslatex}
i \\usepackage[pdftex,pdftitle={'"$TITLE}, 
pdfauthor={$AUTHOR},linktocpage,a4paper,colorlinks=true,urlcolor=blue,citecolor=magenta]{hyperref}
p;d}" $TEXDOC > ${LYXPATH}${DOCUMENTBASE}-pdf.tex

####### Convert eps images to pdf
PDFIMAGES=
for image in $IMAGES
do
 IMAGENAME=`basename $image`
 IMAGEPATH=`echo "$image" | sed -n "s/^\(.*\)$IMAGENAME$/\1/p"`
 IMAGEBASE=`basename $IMAGENAME .eps`
 IMAGEBASE=`basename $IMAGEBASE .ps`
   if [ `echo $image | cut -c 1` != "/" ]
   then
      # relative pathname
      IMAGEPATH=${LYXPATH}$IMAGEPATH
   fi
   echo Converting image ${IMAGENAME} to pdf
   epstopdf -outfile=${IMAGEPATH}${IMAGEBASE}.pdf ${IMAGEPATH}${IMAGENAME}
   PDFIMAGES="$PDFIMAGES ${IMAGEPATH}${IMAGEBASE}.pdf"
done

######## Run pdflatex 9 times
for runno in 1 2 3 4 5 6 7 8 9
do
   echo
   echo "************ PDF Latex run no. $runno *************"
   echo
   pdflatex ${LYXPATH}${DOCUMENTBASE}-pdf.tex 
done

### Clean up
mv ${LYXPATH}${DOCUMENTBASE}-pdf.pdf ${LYXPATH}${DOCUMENTBASE}.pdf
rm ${LYXPATH}${DOCUMENTBASE}-pdf.* $PDFIMAGES

echo
echo "The new pdf file is: ${LYXPATH}${DOCUMENTBASE}.pdf"
echo

Reply via email to