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
12 IDENTIFICATION="lytodvi.sh $VERSION"
14 echo "$IDENTIFICATION" 1>&2
18 # - add "Creator: " line to output
21 # - multiple input files to make score from several files
22 # (extra files assumed to be Lilypond output)
23 # - cp dvi-file instead of mv, to allow for xdvi reload
24 # - check for illegal long options
25 # - put in pt in text width, if not given
26 # - put in \nonstopmode in LaTeX file
27 # - restored LaTeX exit value check
30 # - temporarily omit LaTeX exit value check
31 # - remove ALL temporary files
34 # - fix for solaris - included from 0.1.jcn1
35 # - long option hack - included from 0.1.jcn1 - modified
36 # - moved help into function - NOT included from 0.1.jcn1 yet
37 # - various improvements - included from 0.1.jcn1
38 # - find mudela definitions from titledefs.tex
39 # - find papersize from lilypond output file (mudelapapersize),
40 # overridden by option '-p size' or '--papersize=size'
41 # - option -l lang or --language=lang overrides
42 # lilypond output file definition (mudelalanguage)
43 # - textwidth from lilypond output file (mudelapaperlinewidth)
48 # - moved help into function
51 # Exit value, when needed
56 # Keywords defined in titledefs.tex
57 # Isn't there a way to ask LaTeX for the location of titledefs.tex?
59 TF=/usr/lib/texmf/tex/lilypond/titledefs.tex
63 MU_DEF=`egrep "^.newcommand...mudela" $TF | \\
64 sed -e s/^.newcommand...//g | sed -e "s/\\}.*$//"`
69 MU_DEF="mudelatitle mudelasubtitle mudelacomposer \
70 mudelaarranger mudelainstrument"
80 # Find command line options and switches
82 # "x:" x takes argument
87 # ugh, "\-" is a hack to support long options
88 # while getopts \-:$options$switches O
89 # must be in double quotes for bash-2.0
90 while getopts "\-:$options$switches" O
92 $debug_echo "O: \`$O'"
93 $debug_echo "arg: \`$OPTARG'"
115 $debug_echo "long option: \`$OPTARG'"
124 LNG=`echo $OPTARG | sed -e s/"^.*="//`
127 PSZ=`echo $OPTARG | sed -e s/"^.*="//`
133 echo $0": illegal option -- "$OPTARG;
140 shift `expr $OPTIND - 1`
144 if [ "$HELP" != "Y" ]
150 $0 - no input file name given
158 # Check if input file exists...
160 if [ "$HELP" != "Y" ]
169 $0 - input file $GF not found
184 Generate dvi file from mudela or lilypond output
185 Usage: $0 [options] file
188 -D, --debug set debug mode
189 -h, --help this help text
190 -k, --keep keep LaTeX file
191 -l, --language= give LaTeX language (babel)
192 -p, --papersize= give LaTeX papersize (eg. a4paper)
194 file may be input to or output from lilypond(1)
206 # Check whether input file is the input to or output from lilypond
209 OP=`echo $L1 | grep "^% Creator: GNU LilyPond"`
213 # OK - it's the output from lilypond.
214 # Get lilypond source file name
217 IFL=`grep mudelafilename $OF`
220 IF=`echo $IFL | sed -e s/^.*{// | sed -e s/"}*.$"//`
222 # Check if source file exists
228 $0 - mudela file not found.
236 $0 - mudela file name not found.
243 # I have to assume this is the lilypond input file
244 # Find output file name, if defined
247 OFS=`egrep "paper|midi|output" $IF`
248 OF1=`echo $OFS | sed -e s/".midi.*$"// | sed -e s/"^.*paper"//`
251 OF1=`echo $OFS | sed -e s/"^.*paper"// | sed -e s/".midi.*$"//`
257 OF2=`echo $OF1 | grep output`
262 OF=`echo $OF2 | sed -e "s/\\";.*$//" | sed -e "s/^.*\\"//"`
270 # Remove the output file, to avoid being misled by an old one
277 # Run lilypond - exit if unsuccessfull
279 lilypond $IF || exit 3
281 # Check if output file is generated
287 $0 - hmm, I could not find the output file $OF
300 TWL=`grep linewidth $IF`
301 TWS=`echo $TWL | grep -v "^%"`
304 TW=`echo $TWS | sed -e s/^.*=// | sed -e s/";.*$"// | \\
305 sed -e s/.mm/mm/ | sed -e s/.cm/cm/ | sed -e s/.p/p/`
325 if [ "$KEEP" != "Y" ]
335 $0 - temporary directory $TMP not found, set to /tmp
341 BN=`basename $OF .tex`
345 BN=`basename $OF .tex`
350 # Find if a paper size is defined
354 PSZ=`egrep ".def.mudelapapersize" $OF | \\
355 sed -e s/.def.mudelapapersize// | \\
356 sed -e s/^{// | sed -e s/}.*$//`
365 # Find if a language is defined
369 LNG=`egrep ".def.mudelalanguage" $OF | \\
370 sed -e s/.def.mudelalanguage// | \\
371 sed -e s/^{// | sed -e s/}.*$//`
375 LLNG="\usepackage["$LNG"]{babel}"
381 # Find if a textwidth is defined
383 TWN=`egrep ".def.mudelapaperlinewidth" $OF | \\
384 sed -e s/.def.mudelapaperlinewidth// | \\
385 sed -e s/^{// | sed -e s/}.*$//`
400 $debug_echo "Text width = "$TW
407 % Creator: $IDENTIFICATION
408 % Automatically generated from $IF, $NOW
410 \documentclass$PAPER{article}
413 \usepackage[T1]{fontenc}
414 \addtolength{\oddsidemargin}{-1cm}
415 \addtolength{\topmargin}{-1cm}
416 \setlength{\textwidth}{$TW}
422 # Include \def\mudela-definitions
426 LL=`grep ".def."$L $OF`
429 LLL=`echo $LL | sed -e s/^.def.$L// | \\
430 sed -e s/^{// | sed -e s/}.*$//`
433 echo '\'$L'{'$LLL'}%' >> $LF
442 for EX in $*; do echo "\input{"$EX"}%" >> $LF; done
444 \vfill\hfill{(\LilyIdString)}
455 Take care - LaTeX exit value check temporarily omitted!
469 if [ "$KEEP" != "Y" ]
478 $0 - dvi file name is $BN.dvi