lilypond-1.3.129
[lilypond.git] / bin / lytodvi.sh
blobe303f5c3b96697125933e86ae816d57489c6079a
1 #!/bin/sh
3 # Written by Jan Arne Fagertun <Jan.A.Fagertun@energy.sintef.no>
4 # Sat Nov 22 22:26:43 CET 1997
6 # Script to make a latex file for Lilypond
8 # Find options given
11 # should use header info or locale --HWN
12 LANGUAGE="english"
13 VERSION="0.0"
16 echo "lytodvi.sh $VERSION" 1>&2
17 while getopts Dhk O
19 case $O in
20 D ) set -x;DEBUG="-v";;
21 h ) HELP=Y;;
22 k ) KEEP=Y;;
23 \? ) HELP=Y;;
24 esac
25 done
26 shift `expr $OPTIND - 1`
29 # Input file name
31 if [ "$HELP" != "Y" ]
32 then
33 if [ "$1" = "" ]
34 then
35 echo $0" - no input file name given" 1>&2
36 HELP=Y
40 # Check if input file exists...
42 if [ "$HELP" != "Y" ]
43 then
44 if [ ! -f $1 ]
45 then
46 echo $0" - input file not found " 1>&2
47 HELP=Y
51 # Help info
53 if [ "$HELP" = "Y" ]
54 then
55 echo
56 echo "usage : "$0" [-D -h -k] file"
57 cat << EOF
58 -D = set debug mode
59 -h = this help text
60 -k = keep latex file
61 file may be input to or output from lilypond
62 EOF
63 echo
64 exit 1
67 # Check whether input file is the input to or output from lilypond
69 L1=`head -1 $1`
70 OP=`echo $L1 | grep "^% Creator: GNU LilyPond"`
71 if [ "$OP" != "" ]
72 then
74 # OK - it's the output from lilypond.
75 # Get lilypond source file name
77 OF=$1
78 IFL=`grep mudelafilename $OF`
79 if [ "$IFL" != "" ]
80 then
81 IF=`echo $IFL | sed -e s/^.*{// | sed -e s/"}*.$"//`
83 # Check if source file exists
85 if [ ! -f $IF ]
86 then
87 echo $0" - mudela file not found."
88 TW=15.5cm
90 else
91 echo $0" - mudela file name not found."
92 TW=15.5cm
94 else
96 # I have to assume this is the lilypond input file
97 # Find output file name, if defined
99 IF=$1
100 OFS=`egrep "paper|midi|output" $IF`
101 OF1=`echo $OFS | sed -e s/".midi.*$"// | sed -e s/"^.*paper"//`
102 if [ "$OF1" = "" ]
103 then
104 OF1=`echo $OFS | sed -e s/"^.*paper"// | sed -e s/".midi.*$"//`
106 if [ "$OF1" = "" ]
107 then
108 OF=lelie.tex
109 else
110 OF2=`echo $OF1 | grep output`
111 if [ "$OF2" = "" ]
112 then
113 OF=lelie.tex
114 else
115 OF=`echo $OF2 | sed -e s/'";.*'$// | sed -e s/^'.*"'//`
117 if [ "$OF2" = "" ]
118 then
119 OF=lelie.tex
123 # Run lilypond - exit if unsuccessfull
125 lilypond $IF || exit 3
128 # Find textwidth
130 if [ "$IF" != "" ]
131 then
132 if [ -f $IF ]
133 then
134 TWL=`grep linewidth $IF`
135 if [ "$TWL" != "" ]
136 then
137 TW=`echo $TWL | sed -e s/^.*=// | sed -e s/";.*$"// | \\
138 sed -e s/.mm/mm/ | sed -e s/.cm/cm/ | sed -e s/.p/p/`
139 else
140 TW=15.5cm
145 # More parameters from input file
147 # Well - seems like some more info is needed:
148 # Arranger (I use mudelacopyright now)
149 # Instrument (I use mudelaremarks now)
151 # Latex file
153 if [ "$KEEP" != "Y" ]
154 then
155 if [ "$TMP" = "" ]
156 then
157 TMP=/tmp
159 if [ ! -d $TMP ]
160 then
161 echo $0" - temporary directory "$TMP" not found, set to /tmp"
162 TMP=/tmp
165 LF=$TMP/$OF.tex
166 else
167 LF=$OF.tex
170 # Should copy a "header file" instead....
172 cat << EOF > $LF
173 \documentclass[a4paper]{article}
174 \usepackage[$LANGUAGE]{babel}
175 \usepackage[T1]{fontenc}
176 \addtolength{\oddsidemargin}{-1cm}
177 \addtolength{\topmargin}{-1cm}
180 # why two <<EOF constructs? --HWN
181 echo "\setlength{\textwidth}{"$TW"}" >> $LF
182 cat << EOF >> $LF
183 \input lilyponddefs
184 \input titledefs
185 \begin{document}
189 # Include \def\mudela-definitions - strip off \def\mudela.
190 # Hmm - why not just change titledefs?
192 for L in mudelatitle mudelasubtitle mudelacomposer mudelaarranger mudelainstrument
194 LL=`grep $L $OF`
195 if [ "$LL" != "" ]
196 then
197 echo $LL | sed -e s/d.*mudela//g >> $LF
199 done
201 echo "\makelilytitle" >> $LF
202 echo "\input{"$OF"}" >> $LF
203 echo "\vfill\hfill{(\LilyIdString)}" >> $LF
204 echo "\end{document}" >> $LF
207 # Run latex
209 latex $LF
211 # Clean up
213 if [ "$KEEP" != "Y" ]
214 then
215 rm $LF