3 # Script to make a LaTeX file for Lilypond
5 # Written by Jan Arne Fagertun <Jan.A.Fagertun@energy.sintef.no>
6 # Sat Nov 22 22:26:43 CET 1997
8 # Original LaTeX file made by Mats Bengtsson, 17/8 1997
13 echo "lytodvi.sh $VERSION" 1>&2
17 # - multiple input files to make score from several files
18 # (extra files assumed to be Lilypond output)
19 # - cp dvi-file instead of mv, to allow for xdvi reload
20 # - check for illegal long options
21 # - put in pt in text width, if not given
22 # - put in \nonstopmode in LaTeX file
23 # - restored LaTeX exit value check
26 # - temporarily omit LaTeX exit value check
27 # - remove ALL temporary files
30 # - fix for solaris - included from 0.1.jcn1
31 # - long option hack - included from 0.1.jcn1 - modified
32 # - moved help into function - NOT included from 0.1.jcn1 yet
33 # - various improvements - included from 0.1.jcn1
34 # - find mudela definitions from titledefs.tex
35 # - find papersize from lilypond output file (mudelapapersize),
36 # overridden by option '-p size' or '--papersize=size'
37 # - option -l lang or --language=lang overrides
38 # lilypond output file definition (mudelalanguage)
39 # - textwidth from lilypond output file (mudelapaperlinewidth)
44 # - moved help into function
47 # Exit value, when needed
52 # Keywords defined in titledefs.tex
53 # Isn't there a way to ask LaTeX for the location of titledefs.tex?
55 TF=/usr/lib/texmf/tex/lilypond/titledefs.tex
59 MU_DEF=`egrep "^.newcommand...mudela" $TF | \\
60 sed -e s/^.newcommand...//g | sed -e "s/\\}.*$//"`
65 MU_DEF="mudelatitle mudelasubtitle mudelacomposer \
66 mudelaarranger mudelainstrument"
76 # Find command line options and switches
78 # "x:" x takes argument
83 # ugh, "\-" is a hack to support long options
84 # while getopts \-:$options$switches O
85 # must be in double quotes for bash-2.0
86 while getopts "\-:$options$switches" O
88 $debug_echo "O: \`$O'"
89 $debug_echo "arg: \`$OPTARG'"
111 $debug_echo "long option: \`$OPTARG'"
120 LNG=`echo $OPTARG | sed -e s/"^.*="//`
123 PSZ=`echo $OPTARG | sed -e s/"^.*="//`
129 echo $0": illegal option -- "$OPTARG;
136 shift `expr $OPTIND - 1`
140 if [ "$HELP" != "Y" ]
146 $0 - no input file name given
154 # Check if input file exists...
156 if [ "$HELP" != "Y" ]
165 $0 - input file $GF not found
180 Generate dvi file from mudela or lilypond output
181 Usage: $0 [options] file
184 -D, --debug set debug mode
185 -h, --help this help text
186 -k, --keep keep LaTeX file
187 -l, --language= give LaTeX language (babel)
188 -p, --papersize= give LaTeX papersize (eg. a4paper)
190 file may be input to or output from lilypond(1)
202 # Check whether input file is the input to or output from lilypond
205 OP=`echo $L1 | grep "^% Creator: GNU LilyPond"`
209 # OK - it's the output from lilypond.
210 # Get lilypond source file name
213 IFL=`grep mudelafilename $OF`
216 IF=`echo $IFL | sed -e s/^.*{// | sed -e s/"}*.$"//`
218 # Check if source file exists
224 $0 - mudela file not found.
232 $0 - mudela file name not found.
239 # I have to assume this is the lilypond input file
240 # Find output file name, if defined
243 OFS=`egrep "paper|midi|output" $IF`
244 OF1=`echo $OFS | sed -e s/".midi.*$"// | sed -e s/"^.*paper"//`
247 OF1=`echo $OFS | sed -e s/"^.*paper"// | sed -e s/".midi.*$"//`
253 OF2=`echo $OF1 | grep output`
258 OF=`echo $OF2 | sed -e "s/\\";.*$//" | sed -e "s/^.*\\"//"`
266 # Remove the output file, to avoid being misled by an old one
273 # Run lilypond - exit if unsuccessfull
275 lilypond $IF || exit 3
277 # Check if output file is generated
283 $0 - hmm, I could not find the output file $OF
296 TWL=`grep linewidth $IF`
297 TWS=`echo $TWL | grep -v "^%"`
300 TW=`echo $TWS | sed -e s/^.*=// | sed -e s/";.*$"// | \\
301 sed -e s/.mm/mm/ | sed -e s/.cm/cm/ | sed -e s/.p/p/`
321 if [ "$KEEP" != "Y" ]
331 $0 - temporary directory $TMP not found, set to /tmp
337 BN=`basename $OF .tex`
341 BN=`basename $OF .tex`
346 # Find if a paper size is defined
350 PSZ=`egrep ".def.mudelapapersize" $OF | \\
351 sed -e s/.def.mudelapapersize// | \\
352 sed -e s/^{// | sed -e s/}.*$//`
361 # Find if a language is defined
365 LNG=`egrep ".def.mudelalanguage" $OF | \\
366 sed -e s/.def.mudelalanguage// | \\
367 sed -e s/^{// | sed -e s/}.*$//`
371 LLNG="\usepackage["$LNG"]{babel}"
377 # Find if a textwidth is defined
379 TWN=`egrep ".def.mudelapaperlinewidth" $OF | \\
380 sed -e s/.def.mudelapaperlinewidth// | \\
381 sed -e s/^{// | sed -e s/}.*$//`
396 $debug_echo "Text width = "$TW
403 \documentclass$PAPER{article}
406 \usepackage[T1]{fontenc}
407 \addtolength{\oddsidemargin}{-1cm}
408 \addtolength{\topmargin}{-1cm}
409 \setlength{\textwidth}{$TW}
415 # Include \def\mudela-definitions
419 LL=`grep ".def."$L $OF`
422 LLL=`echo $LL | sed -e s/^.def.$L// | \\
423 sed -e s/^{// | sed -e s/}.*$//`
426 echo '\'$L'{'$LLL'}%' >> $LF
435 for EX in $*; do echo "\input{"$EX"}%" >> $LF; done
437 \vfill\hfill{(\LilyIdString)}
448 Take care - LaTeX exit value check temporarily omitted!
462 if [ "$KEEP" != "Y" ]
471 $0 - dvi file name is $BN.dvi