]> git.donarmstrong.com Git - lilypond.git/blob - scripts/ly2dvi-old.sh
patch::: 1.1.0.jcn1: tegen nul
[lilypond.git] / scripts / ly2dvi-old.sh
1 #!/bin/sh
2 #
3 # Script to make a LaTeX file for Lilypond
4 #
5 # Written by Jan Arne Fagertun <Jan.A.Fagertun@energy.sintef.no>
6 #  Sat Nov 22 22:26:43 CET 1997
7 #
8 # $Id: ly2dvi.sh,v 1.16 1998/05/08 21:18:34 janaf Exp $
9 #
10 #  Original LaTeX file made by Mats Bengtsson, 17/8 1997
11 #
12
13 VERSION="0.12.jcn1"
14 NAME=ly2dvi.sh
15 IDENTIFICATION="$NAME $VERSION" 
16 NOW=`date`
17 echo "$IDENTIFICATION" 1>&2
18
19 # TODO:
20 #  prevent orphaned "Lily is here" strings
21
22 # NEWS
23
24 # 0.12.jcn1
25 #  - mudelaDefs really fixed (sorry, PC)
26
27 # 0.12
28 #  - -S/--sourcedir switch
29
30 #
31 #0.11.jcn3
32 # - mudelaDefs fixes, (thanks PC)
33 #0.11.jcn2
34 # - pass -I, --include to Lily
35 # - bf: split $LILYINCLUDE and try all dirs
36 # - bf: geometry left/top
37 #
38 #0.11.pc
39 # - fix backslash gobbling, reduce number of separate processes used
40 # - require readable rc files, allow rc file in /usr/local/share/lilypond/lilyrc
41 # - use latex path, not tex path
42 # - Don't override if kpsepath returns non-NULL
43 # - Don't clobber x.tex if it wasn't created by ly2dvi
44 #
45 #
46 #0.11.jcn1
47 # - find .fly files too
48 #
49 #0.11.hwn1
50 # - height vs heigth
51 # - robustification: give \nonstopmode as LaTeX arg; no hanging if no TeX file.
52 # - robustification: notice failed cp.
53
54 #0.11
55 #       - more papersizes (thanks Han-Wen) - don't expect LaTeX to accept all...
56 #       - -W,--Width=       : set paper width  (points)
57 #       - -H,--Height=      : set paper height (points)
58 #       - -H and -W is used only when an unknown papersize is to be specified,
59 #         and has to be combined with a papersize option known to LaTeX
60 #NB!    - -F,--headers=     : name of additional LaTeX headers input file.
61 #NB!      Changed from -H to -F
62 #       - -d,--dependencies : passed to lilypond
63
64
65 #0.10.jcn1
66 #       - HEIGHT -> HEIGHT
67 #       - vertical margins (for a4), same on both sides
68 #       - textheight from lilypond output file (mudelapapertextheight)
69 #       - piece titling
70 #       - mudelapiece, mudelaopus
71 #
72 #0.10
73 #       - -K,--keeplilypond : Keep lilypond output files (default delete)
74 #       - -k,--keeply2dvi   : Keep ly2dvi   output files (default delete)
75 #       - -L,--landscape    : Set landscape orientation
76 #       - -N,--nonumber     : Turn off page numbering (\pagestyle{empty})
77 #       - Could not reinsert "\usepackage[T1]{fontenc}" because
78 #         "los-toros" won't work with it
79 #       - Ekstra LaTeX headers from input file
80 #0.9.hwn1
81 #       - option to remove output of lily
82 # 0.9
83 #       - Trap Lilypond abort
84 #       - Replaced "\usepackage[T1]{fontenc}" with
85 #         \usepackage[latin1]{inputenc} (takk, Mats)
86 #       - Removed "()" around "\LilyIdString" (Janne didn't want it)
87 # 0.8   - Trap Lilypond segmentation fault
88 #       - Function for cleanup
89 #       - Trap line
90 #       - More human-readable variables
91 #       - Some logics concerning rc-files
92 # 0.7
93 #       - Improved Lilypond error checking
94 #       - Output orientation (landscape...). Overrides mudela file
95 #         variable orientation="landscape";
96 #       - Paper width and height put into variables (only A4!)
97 #       - Adjusted top margin to default.....
98 #
99 #TODO
100 #       - Include more papersizes.
101 #       - Manual page.......
102 # 0.6.jaf2
103 #       - LILYINCLUDE update
104 #
105 # 0.6.hwn1
106 #       - handle LILYINCLUDE
107 #       - --output
108 #
109 # 0.6
110 #       - Source rc-files, if present. Files are:
111 #         /usr/local/share/lilyrc /etc/lilyrc $HOME/.lilyrc ./.lilyrc
112 #       - tee output from Lilypond
113 #       - Handles margins for A4 paper (equal on both sides)
114 #       - new option -s (--separate) for one LaTeX run per file,
115 #         else all files are run together
116 #
117 # 0.5
118 #       - More useful ("two-level") debug.
119 #       - The Q&D hack to find file names and not handling \include
120 #         is replaced by grabbing output file names from Lilypond.
121 #       = Detects multiple output files - adds them when running
122 #         LaTeX.
123 #       - Works with multiple input files - no matter if they are
124 #         (a mix of) input to or output from Lilypond.
125 #
126 #TODO
127 #       - Still no margins handling.
128 #       - We have to discuss how to handle multiple output files
129 #         from Lilypond - 'ly2dvi standchen' gives a rather odd
130 #         result....
131
132 # 0.4.1
133 #       - Always exit after printing help info
134 # 0.4
135 #       - Changes to ensure for more strict grep'ing of parameters
136 #         Thanks to from G.B.Stott@bolton.ac.uk
137 #       - More efficient use of sed -e 's///' -e 's///'
138 #         Thanks to Johan Vromans <jvromans@squirrel.nl> and GBS
139 #       - Ask tex for location of titledefs.tex (Thanks to JV)
140 #       - Accept only exact match of "\def\mudelacomposer{"
141 #         (or whatever mudela* defined in titledefs.tex)
142 #       - Even more efficient use of sed (Thanks to JV)
143 #       - Default file name for single output file implemented.
144 #       - Moved help into function - finally included from 0.1.jcn1
145 #
146 #TODO
147 #       - Still doesn't handle \include
148 #       - The Q&D for finding output file name from the sequence of
149 #         \paper \output \midi \output really needs to be looked at.
150 #         I have improved it a lot, but it's only capable of finding
151 #         one (the last) file name.
152 #         Well, I have to rewrite this entirely to handle \include,
153 #         then I can fix it.
154 #       - Still no margins handling.
155 #
156 #WARNING
157 #       - Some lines of output from lilypond do NOT start
158 #         at first character position, therefore I have removed "^"
159 #         in sed'ing and grep'ing.
160
161 # 0.3.hwn1
162 #       - add "Creator: " line to output
163 #
164 # 0.3
165 #       - multiple input files to make score from several files
166 #         (extra files assumed to be Lilypond output)
167 #       - cp dvi-file instead of mv, to allow for xdvi reload
168 #       - check for illegal long options
169 #       - put in pt in text width, if not given
170 #       - put in \nonstopmode in LaTeX file
171 #       - restored LaTeX exit value check
172  
173 # 0.2.1
174 #       - temporarily omit LaTeX exit value check
175 #       - remove ALL temporary files
176
177 # 0.2
178 #       - fix for solaris          - included from 0.1.jcn1
179 #       - long option hack         - included from 0.1.jcn1 - modified
180 #       - moved help into function - NOT included from 0.1.jcn1 yet
181 #       - various improvements     - included from 0.1.jcn1
182 #       - find mudela definitions from titledefs.tex
183 #       - find papersize from lilypond output file (mudelapapersize),
184 #         overridden by option '-p size' or '--papersize=size'
185 #       - option -l lang or --language=lang overrides
186 #         lilypond output file definition (mudelalanguage)
187 #       - textwidth from lilypond output file (mudelapaperlinewidth)
188
189 # 0.1.jcn1
190 #       - fix for solaris
191 #       - long option hack
192 #       - moved help into function
193
194 #
195 # Clean up
196 #
197 cleanup() {
198   if [ "$KEEP_LY2DVI_OUTPUT" != "Y" ]
199   then
200     [ -n "$LatF" -a -f "$LatF" ]       && rm -f $LatF
201     [ -n "$LOGFILE" -a -f "$LOGFILE" ] && rm -f $LOGFILE
202     [ -n "$FN" ]                       && rm -f $FN.*
203     for F in *$$* $TMP/*$$*
204     do
205       rm -f $F
206     done
207   fi
208   if [ "$KEEP_LILY_OUTPUT" != "Y" ]
209   then
210     for F in $LILY_OUTPUT_FILES
211     do
212       [ -f $F ] && rm -f $F
213     done
214   fi
215 }
216
217 #
218 # print usage
219 #
220 help() {
221   cat << EOF
222 Generate dvi file from mudela or lilypond output
223 Usage: $0 [OPTION]... [FILE]...
224
225 Options:
226   -D,--debug           increase verbosity
227   -F,--headers=        name of additional LaTeX headers file
228   -H,--Height=         set paper height (points) (see manual page)
229   -I,--include=DIR     add DIR to search path of LilyPond
230   -K,--keeplilypond    keep lilypond output files
231   -L,--landscape       set landscape orientation
232   -N,--nonumber        switch off page numbering
233   -O,--orientation=    set orientation (obsolete - use -L instead) 
234   -W,--Width=          set paper width (points) (see manual page)
235   -d,--dependencies    tell lilypond make a dependencies file
236   -h,--help            this help text
237   -k,--keeply2dvi      keep ly2dvi output files
238   -l,--language=       give LaTeX language (babel)
239   -o,--output=         set output directory
240   -p,--papersize=      give LaTeX papersize (eg. a4)
241   -s,--separate        run all files separately through LaTeX
242   -S,--sourcedir       set sourcedir 
243
244   files may be (a mix of) input to or output from lilypond(1)
245 EOF
246 }
247
248
249 #
250 # SVr4 echo swallows backslashes, and there's no way to turn it off.
251 # Therefore use Echo whenever backslashes may be important.
252 # printf is in the posix.2 standard -- which means it's in 
253 # all modern shells.
254 #
255 Echo() {
256         printf "%s\n" "$@"
257 }
258
259 #
260 setPaperZize() {
261 case "$PAPERSIZE" in
262   a0*)
263     PWIDTH=2389
264     PHEIGHT=3381
265     PAPERSIZE=a0paper
266     ;;
267   a1|a1p*)
268     PWIDTH=1690
269     PHEIGHT=2389
270     PAPERSIZE=a1paper
271     ;;
272   a2*)
273     PWIDTH=1194
274     PHEIGHT=1690
275     PAPERSIZE=a2paper
276     ;;
277   a3*)
278     PWIDTH=845
279     PHEIGHT=1194
280     PAPERSIZE=a3paper
281     ;;
282   a4*)
283     PWIDTH=597
284     PHEIGHT=845
285     PAPERSIZE=a4paper
286     ;;
287   a5*)
288     PWIDTH=423
289     PHEIGHT=597
290     PAPERSIZE=a5paper
291     ;;
292   a6*)
293     PWIDTH=298
294     PHEIGHT=423
295     PAPERSIZE=a6paper
296     ;;
297   a7*)
298     PWIDTH=211
299     PHEIGHT=298
300     PAPERSIZE=a7paper
301     ;;
302   a8*)
303     PWIDTH=305
304     PHEIGHT=211
305     PAPERSIZE=a8paper
306     ;;
307   a9*)
308     PWIDTH=105
309     PHEIGHT=305
310     PAPERSIZE=a9paper
311     ;;
312   a10*)
313     PWIDTH=74
314     PHEIGHT=105
315     PAPERSIZE=a10paper
316     ;;
317   b0*)
318     PWIDTH=2847
319     PHEIGHT=4023
320     PAPERSIZE=b0paper
321     ;;
322   b1*)
323     PWIDTH=2012
324     PHEIGHT=2847
325     PAPERSIZE=b1paper
326     ;;
327   b2*)
328     PWIDTH=1423
329     PHEIGHT=2012
330     PAPERSIZE=b2paper
331     ;;
332   b3*)
333     PWIDTH=1006
334     PHEIGHT=1423
335     PAPERSIZE=b3paper
336     ;;
337   b4*)
338     PWIDTH=712
339     PHEIGHT=1006
340     PAPERSIZE=b4paper
341     ;;
342   b5*)
343     PWIDTH=503
344     PHEIGHT=712
345     PAPERSIZE=b5paper
346     ;;
347   archA)
348     PWIDTH=650
349     PHEIGHT=867
350     ;;
351   archB)
352     PWIDTH=867
353     PHEIGHT=1301
354     ;;
355   archC)
356     PWIDTH=1301
357     PHEIGHT=1734
358     ;;
359   archD)
360     PWIDTH=1734
361     PHEIGHT=2602
362     ;;
363   archE)
364     PWIDTH=2602
365     PHEIGHT=3469
366     ;;
367   flsa|flse)
368     PWIDTH=614
369     PHEIGHT=940
370     ;;
371   halfletter)
372     PWIDTH=397
373     PHEIGHT=614
374     ;;
375   ledger)
376     PWIDTH=1229
377     PHEIGHT=795
378     ;;
379   legal)
380     PWIDTH=614
381     PHEIGHT=1012
382     ;;
383   letter)
384     PWIDTH=614
385     PHEIGHT=795
386     ;;
387   note)
388     PWIDTH=542
389     PHEIGHT=723
390     ;;
391   *)
392     echo ""
393     echo $0": unknown papersize -- "$PAPERSIZE
394     echo ""
395     ;;
396 esac
397 }
398
399 doRcFiles()
400 {
401 #
402 # RC-files ?
403 #
404 for D in /usr/local/share/ /usr/local/share/lilypond/ /etc/ $HOME/. ./.
405 do
406   RCfile=$D"lilyrc"
407   [ -r $RCfile ] && . $RCfile
408 done
409 fORI=$ORIENTATION
410 fLNG=$LANGUAGE
411 fPSZ=$PAPERSIZE
412 fLHF=$LATEXHF
413 unset ORIENTATION LANGUAGE PAPERSIZE LATEXHF
414 }
415
416
417
418 #
419 # Trap function (cleanup)
420 #
421
422
423
424 trap cleanup 0 9 15
425
426
427
428 #
429 # Various defaults
430 #
431 [ -z "$TMP" ] && TMP=/tmp
432 if [ ! -d $TMP ]
433 then
434   $debug_echo $IDENTIFICATION": temporary directory "$TMP" not found, set to /tmp"
435   TMP=/tmp
436 fi
437 LOGFILE=$TMP/lilylog.$$                 # Logfile for lilypond
438 PAPERSIZE=a4                            # Default papersize name
439 PWIDTH=597                              # Default paperwidth
440 PHEIGHT=845                             # Default paperheight
441 PNUM="%"                                # Page numbering on
442 LILYOPTS=""                             # Options to lilypond
443 SOURCEDIR=""
444 LILYPOND_EXECUTABLE=lilypond
445 doRcFiles
446
447
448
449 # Keywords defined in titledefs.tex
450 #
451 TF="`kpsewhich -n latex tex titledefs.tex`"
452 MU_DEF=""
453 if [ -r "${TF:=/usr/local/share/texmf/tex/lilypond/titledefs.tex}" ]
454 then
455   MU_DEF=`sed -n -e 's/.*newcommand\*{.\(mudela[^}]*\)}.*$/\1/p' "$TF"`
456 fi
457
458 : "${MU_DEF:=mudelatitle mudelasubtitle mudelacomposer \
459           mudelameter mudelaopus mudelaarranger mudelapiece \
460           mudelapoet mudelainstrument \
461           }"
462
463 #
464 # debugging
465 #
466 debug_echo=:
467 #
468 # All files in one LaTeX run
469 #
470 SEPFILE=N
471 #
472 # Find command line options and switches
473 #
474 # "x:" x takes argument
475 #
476 switches="DF:H:I:KLNO:W:dhkl:o:p:S:s\?"
477 options=""
478 #
479 # ugh, "\-" is a hack to support long options
480 # while getopts \-:$options$switches O
481 # must be in double quotes for bash-2.0
482 while getopts "\-:$options$switches" O
483 do
484   $debug_echo "O: \`$O'"
485   $debug_echo "arg: \`$OPTARG'"
486   case $O in
487     D  )
488       [ $debug_echo = echo ] && set -x
489       debug_echo=echo
490       ;;
491     F  )
492       LATEXHF=$OPTARG
493       ;;
494     H  )
495       PHEIGHT=$OPTARG
496       ;;
497     I  )
498       LILYOPTS="$LILYOPTS -I $OPTARG"
499       LILYINCLUDE="$LILYINCLUDE:$OPTARG"
500       ;;
501     K  )
502       KEEP_LILY_OUTPUT=Y
503       ;;
504     L  )
505       ORIENTATION=landscape
506       ;;
507     O  )
508       ORIENTATION=$OPTARG
509       ;;
510     N  )
511       PNUM="\pagestyle{empty}"
512       ;;
513     W  )
514       PWIDTH=$OPTARG
515       ;;
516     d  )
517       LILYOPTS=$LILYOPTS" -d"
518       ;;
519     h  )
520       help;
521       exit 0
522       ;;
523     k  )
524       KEEP_LY2DVI_OUTPUT=Y
525       ;;
526     l  )
527       LANGUAGE=$OPTARG
528       ;;
529     o  )
530       OUTPUTDIR=$OPTARG
531       ;;
532     p  )
533       PAPERSIZE=$OPTARG
534       ;;
535     s  )
536       SEPFILE=Y
537       ;;
538     S  )
539       SOURCEDIR=$OPTARG
540       ;;
541     \? )
542       help;
543       exit -1
544       ;;
545     # a long option!
546     -)
547       $debug_echo "long option: \`$OPTARG'"
548       case "$OPTARG" in
549         He*|-He*)
550           PHEIGHT"`expr \"$OPTARG\" ':' '[^=]*=\(.*\)'`"=
551           ;;
552         W*|-W*)
553           PWIDTH="`expr \"$OPTARG\" ':' '[^=]*=\(.*\)'`"
554           ;;
555         dep*|-dep*)
556           LILYOPTS="$LILYOPTS -d"
557           ;;
558         d*|-d*)
559           [ $debug_echo = echo ] && set -x
560           debug_echo=echo
561           ;;
562         hea*|-hea*)
563           LATEXHF="`expr \"$OPTARG\" ':' '[^=]*=\(.*\)'`"
564           ;;
565         h*|-h*)
566           help;
567           exit 0
568           ;;
569         i*|-i*)
570           dir="`expr \"$OPTARG\" ':' '[^=]*=\(.*\)'`"
571           LILYOPTS="$LILYOPTS --include=$dir"
572           LILYINCLUDE="$LILYINCLUDE:$dir"
573           ;;
574         keepli*|-keepli*)
575           KEEP_LILY_OUTPUT=Y
576           ;;
577         k*|-k*)
578           KEEP_LY2DVI_OUTPUT=Y
579           ;;
580         land*|-land*)
581           ORIENTATION=landscape
582           ;;
583         lang*|-lang*)
584           LANGUAGE="`expr \"$OPTARG\" ':' '[^=]*=\(.*\)'`"
585           ;;
586         n*|-n*)
587           PNUM="\pagestyle{empty}"
588           ;;
589         or*|-or*)
590           ORIENTATION="`expr \"$OPTARG\" ':' '[^=]*=\(.*\)'`"
591           ;;
592         ou*|-ou*)
593           OUTPUTDIR="`expr \"$OPTARG\" ':' '[^=]*=\(.*\)'`"
594           ;;
595         p*|-p*)
596           PAPERSIZE="`expr \"$OPTARG\" ':' '[^=]*=\(.*\)'`"
597           ;;
598         separa*|-sep*)
599           SEPFILE=Y
600           ;;
601         sourcedir*|-sourcedir*)
602           SOURCEDIR=$OPTARG
603           ;;
604         *|-*)
605           echo "$0: illegal option -- \"$OPTARG\""
606           help;
607           exit -1
608           ;;
609       esac
610   esac
611 done
612 shift `expr $OPTIND - 1`
613
614 if [ "$SOURCEDIR" != "" ]; then
615 # apparently MakeTeXTFM can't handle relative dirs
616         SOURCEDIR=`cd $SOURCEDIR; pwd`
617         LILYINCLUDE="$SOURCEDIR/init:$SOURCEDIR/mf/out:$LILYINCLUDE"
618         TEXINPUTS="$SOURCEDIR/tex:$TEXINPUTS:"
619         MFINPUTS="$SOURCEDIR/mf:$MFINPUTS:"
620         LILYPOND_EXECUTABLE="$SOURCEDIR/lily/out/lilypond"
621         export MFINPUTS LILYPOND_EXECUTABLE TEXINPUTS SOURCEDIR 
622 fi
623
624 #
625 # Input file name
626 #
627 if [ "$1" = "" ]
628 then
629   help
630   $debug_echo "$IDENTIFICATION: No input file name given"
631   exit 1
632 fi
633 # regexp_quote -- quote a string as a regular expression for egrep or sed
634 regexp_quote(){
635         Echo "$@" | sed 's/\([]\[\.*?+^$]\)/\\\1/g'
636 }
637 #
638 #
639 mudelaDefs(){
640 # Include \def\mudela-definitions
641 # The aim here is to pick up the definition for the 
642 # current file, then any other file.
643 #
644 mudelatmp=$TMP/mudelaDefs$$
645 # Use `cat' to prevent filenames being prepended
646
647 cat "$File" $OF | fgrep "$MU_DEF" > $mudelatmp
648 for L in $MU_DEF
649 do
650     # This converts \def\mudelatitle{fred}
651     # to \mudelatitle{fred} or to
652     # \def\mudelatitle{fred}
653     # and stops after the first one found.
654     sed -n '/\\def\\'"$L"'{\([^}]*\)}.*$/{
655         s//'"`regexp_quote \"$1\"`"'\\'"$L"'{\1}%/p
656         q
657     }'  $mudelatmp  >> $LatF
658 done
659 rm -f $mudelatmp
660 }
661 #
662 #
663 startFile(){
664 #
665 # LaTeX file name
666 #
667 BN=`basename "$File" .tex`
668 FN="$BN.$$"
669 if [ "$KEEP_LY2DVI_OUTPUT" != "Y" ]
670 then
671   LatF="$TMP/$FN.tex"
672 else
673   LatF="$FN.tex"
674 fi
675 #
676 # Find:
677 #   paper size        (PAPERSIZE, overridden by command line option -p)
678 #   paper orientation (ORIENTATION, overridden by option -o)
679 #   language          (LANGUAGE, overridden by option -l)
680 #   textwidth
681 #
682 eval `sed -n \\
683   -e 's/\\\\def\\\\mudelalanguage{\([^}]*\).*$/fLNG=\1;/p' \\
684   -e 's/\\\\def\\\\mudelalatexheaders{\([^}]*\).*$/fLHF=\1;/p' \\
685   -e 's/\\\\def\\\\mudelaorientation{\([^}]*\).*$/fORI=\1;/p' \\
686   -e 's/\\\\def\\\\mudelapaperlinewidth{\([^}]*\).*$/TWN=\1;/p' \\
687   -e 's/\\\\def\\\\mudelapapertextheight{\([^}]*\).*$/THN=\1;/p' \\
688   -e 's/\\\\def\\\\mudelapapersize{\([^}]*\).*$/fPSZ=\1;/p' \\
689     "$File"`
690 #
691 if [ -z "$LATEXHF" ]
692 then
693   LATEXHF="$fLHF"
694 fi
695 LLHF="%"
696 if [ -n "$LATEXHF" ]
697 then
698   [ -f  "$LATEXHF" ] && LLHF="\input{$LATEXHF}"
699 fi
700 #
701 if [ -z "$PAPERSIZE" ]
702 then
703   PAPERSIZE="$fPSZ"
704 fi
705 if [ -n "$PAPERSIZE" ]
706 then
707   setPaperZize
708   PAPEROPT="$PAPERSIZE"
709 fi
710 #
711 if [ -z "$ORIENTATION" ]
712 then
713   ORIENTATION="$fORI"
714 fi
715 if [ -n "$ORIENTATION" ]
716 then
717   if [ -z "$PAPEROPT" ]
718   then
719     PAPEROPT="$ORIENTATION"
720   else
721     PAPEROPT="$PAPEROPT,$ORIENTATION"
722   fi
723 fi
724 #
725 if [ -n "$PAPEROPT" ]
726 then
727   PAPER="[$PAPEROPT]"
728 fi
729 #
730 if [ -z "$LANGUAGE" ]
731 then
732   LANGUAGE="$fLNG"
733 fi
734 if [ -n "$LANGUAGE" ]
735 then
736   LLNG="\usepackage[$LANGUAGE]{babel}"
737 else
738   LLNG="%"
739 fi
740
741 #
742 # Find textwidth
743 #
744 if [ -n "$TWN" ]
745 then
746   TW="$TWN"
747   case "$TW" in
748     *mm)
749       ;;
750     *cm)
751       ;;
752     *pt)
753       ;;
754     *)
755       TW="${TW}pt"
756       ;;
757   esac
758   $debug_echo "Text width = $TW"
759 fi
760 TWp=`Echo $TW | sed -e 's/\..*$//'`
761 PWp="$PWIDTH"
762 #
763 # Find textheight
764 #
765 if [ -n "$THN" ]
766 then
767   TH=$THN
768   case $TH in
769     *mm)
770       ;;
771     *cm)
772       ;;
773     *pt)
774       ;;
775     *)
776       TH="${TH}pt"
777       ;;
778   esac
779   $debug_echo "Text height = $TH"
780 fi
781 THp="`echo $TH | sed -e 's/\..*$//'`"
782 PHp="$PHEIGHT"
783 if [ "$ORIENTATION" = "landscape" ]
784 then
785   PWp="$PHEIGHT"
786   PHp="$PWIDTH"
787 fi
788 HMARG="`expr '(' $PWp - $TWp ')' / 2`"pt
789 $debug_echo "Text left = $HMARG"
790 VMARG="`expr '(' $PHp - $THp ')' / 2`"pt
791 $debug_echo "Text top = $VMARG"
792 #
793 # Geometry: /var/lib/texmf/latex/geometry/geometry.dvi
794 #
795 #
796 # Write LaTeX file
797 #
798 cat << EOF > $LatF
799 % Creator: $IDENTIFICATION
800 % Automatically generated from  $IF, $NOW
801
802 \documentclass$PAPER{article}
803
804 $LLNG
805 \usepackage{geometry}
806 \usepackage[latin1]{inputenc}
807 %\usepackage[T1]{fontenc}
808 $PNUM
809 %\addtolength{\oddsidemargin}{-1cm}
810 %\addtolength{\topmargin}{-1cm}
811 %\setlength{\textwidth}{$TW}
812 %\setlength{\textheight}{$TH}
813 \geometry{width=$TW, left=$HMARG, height=$TH, top=$VMARG}
814 \input lilyponddefs
815 \input titledefs
816 $LLHF
817 \begin{document}
818 EOF
819 mudelaDefs
820 cat << EOF >> $LatF
821 \cmrtwenty% ugh
822 \makelilytitle
823 EOF
824 }
825 nextFile(){
826 cat << EOF >> $LatF
827 \def\theopus{}%
828 \def\thepiece{}%
829 \def\mudelaopus{}%
830 \def\mudelapiece{}%
831 EOF
832 mudelaDefs "\\def"
833 cat << EOF >> $LatF
834 \def\theopus{\mudelaopus}% ugh
835 \def\thepiece{\mudelapiece}%
836 \makelilypiecetitle
837 EOF
838 }
839 #
840 # Conclusion
841 #
842 endFile(){
843 cat << EOF >> $LatF
844 \vfill\hfill{\LilyIdString}
845 \end{document}
846 EOF
847 #
848 # Run LaTeX
849 #
850 latex '\nonstopmode \input '$LatF || exit 5
851 #
852 # Rename dvi file
853 #
854 if [ -f $FN.dvi ]
855 then
856     RESULT="$BN.dvi"
857     [ -n "$OUTPUTDIR" ] && RESULT="$OUTPUTDIR/$RESULT"
858     
859     cp "$FN.dvi" "$RESULT" || exit 5
860 fi
861 #
862 # Output some info
863 #
864 cat << EOF
865
866 $IDENTIFICATION: dvi file name is $RESULT
867
868 EOF
869 }
870
871 # ugh. GF is side-effect.
872 findInput() {
873 # should check for LILYINCLUDE
874   OIFS="$IFS"
875   IFS=':'
876   x=`echo $LILYINCLUDE | sed "s!:! !g"`
877   IFS="$OIFS"
878   for lypath in . $x
879   do
880     if [ -f "$lypath/$1" ]
881     then
882       GF="$lypath/$1"
883       return
884     fi
885
886     if [ -f "$lypath/$1.ly" ]
887     then
888       GF="$lypath/$1.ly"
889       return
890     fi
891     if [ -f "$lypath/$1.fly" ]
892     then
893        GF="$lypath/$1.fly"
894        return
895     fi
896   done
897   $debug_echo "$IDENTIFICATION: Input file \"$GF\" not found"
898   echo "$NAME: Input file \"$GF\" not found"                       1>&2
899   exit 2
900 }
901 #
902 # Loop through all files
903 #
904
905 LILY_OUTPUT_FILES=
906
907 for GF 
908 do
909     findInput $GF
910
911   #
912   # Check whether the file is input to or output from lilypond
913   #
914   L1=`head -1 $GF` 
915   OP=`echo $L1 | grep "^% Creator: GNU LilyPond"`
916   if [ -n "$OP" ]
917   then
918     #
919     # OK - it's the output from lilypond.
920     #
921     # Get lilypond source file name
922     #
923     OF=$GF
924     IFL=`grep mudelafilename $OF`
925     if [ "$IFL" != "" ]
926     then
927       IF=`echo $IFL | sed -e 's/.*{//' -e 's/}*.$//'`
928       #
929       # Check if source file exists
930       #
931       if [ ! -f $IF ]
932       then
933         $debug_echo $IDENTIFICATION": Mudela file not found."
934         TW=15.5cm
935         TH=25.0cm
936       fi
937     else
938       $debug_echo $IDENTIFICATION": Mudela file name not found."
939       TW=15.5cm
940       TH=25.0cm
941     fi
942   else
943     #
944     # I have to assume this is the lilypond input file
945     # Find output file name, if defined
946     #
947     IF=$GF
948     #
949     # Run lilypond
950     # Grab output file names
951     #
952     $debug_echo "lilypond "$LILYOPTS $IF
953
954     $LILYPOND_EXECUTABLE $LILYOPTS $IF 2>&1  | tee $LOGFILE
955     OF="`sed -n -e 's/TeX output to \([^\.]*\.tex\)\.\.\.$/\1/p' $LOGFILE`"
956     $debug_echo "==> $OF"
957     LILY_OUTPUT_FILES="$LILY_OUTPUT_FILES $OF"
958     STATUS=`egrep -i "error|segmentation|abort" $LOGFILE`
959     echo $STATUS
960     if [ ! -z "$STATUS" ]
961     then
962       exit 10
963     fi
964   fi
965   #
966   # "Spin through" all the files
967   #
968   for File in $OF
969   do
970     $debug_echo "--- "$File
971     #
972     # Check if output file is generated
973     #
974     if [ ! -f "$File" ]
975     then
976       $debug_echo "$IDENTIFICATION: hmm, I could not find the output file $File"
977       exit 4
978     fi
979     #
980     # Is this the first file?
981     #
982     if [ -z "$FFile" ]
983     then
984       FFile="$File"
985       startFile
986     else
987       nextFile
988     fi
989     cat << EOF >> $LatF
990 \input{$File}
991 EOF
992     if [ $SEPFILE = Y ]
993     then
994       FFile=""
995       endFile
996     fi
997   done
998 done
999 if [ $SEPFILE = N ]
1000 then
1001   endFile
1002 fi
1003 #
1004 # OK - finished
1005 #