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
20 # - More useful ("two-level") debug.
21 # - The Q&D hack to find file names and not handling \include
22 # is replaced by grabbing output file names from Lilypond.
23 # = Detects multiple output files - adds them when running
25 # - Works with multiple input files - no matter if they are
26 # (a mix of) input to or output from Lilypond.
29 # - Still no margins handling.
30 # - We have to discuss how to handle multiple output files
31 # from Lilypond - 'ly2dvi standchen' gives a rather odd
35 # - Always exit after printing help info
37 # - Changes to ensure for more strict grep'ing of parameters
38 # Thanks to from G.B.Stott@bolton.ac.uk
39 # - More efficient use of sed -e 's///' -e 's///'
40 # Thanks to Johan Vromans <jvromans@squirrel.nl> and GBS
41 # - Ask tex for location of titledefs.tex (Thanks to JV)
42 # - Accept only exact match of "\def\mudelacomposer{"
43 # (or whatever mudela* defined in titledefs.tex)
44 # - Even more efficient use of sed (Thanks to JV)
45 # - Default file name for single output file implemented.
46 # - Moved help into function - finally included from 0.1.jcn1
49 # - Still doesn't handle \include
50 # - The Q&D for finding output file name from the sequence of
51 # \paper \output \midi \output really needs to be looked at.
52 # I have improved it a lot, but it's only capable of finding
53 # one (the last) file name.
54 # Well, I have to rewrite this entirely to handle \include,
56 # - Still no margins handling.
59 # - Some lines of output from lilypond do NOT start
60 # at first character position, therefore I have removed "^"
61 # in sed'ing and grep'ing.
64 # - add "Creator: " line to output
67 # - multiple input files to make score from several files
68 # (extra files assumed to be Lilypond output)
69 # - cp dvi-file instead of mv, to allow for xdvi reload
70 # - check for illegal long options
71 # - put in pt in text width, if not given
72 # - put in \nonstopmode in LaTeX file
73 # - restored LaTeX exit value check
76 # - temporarily omit LaTeX exit value check
77 # - remove ALL temporary files
80 # - fix for solaris - included from 0.1.jcn1
81 # - long option hack - included from 0.1.jcn1 - modified
82 # - moved help into function - NOT included from 0.1.jcn1 yet
83 # - various improvements - included from 0.1.jcn1
84 # - find mudela definitions from titledefs.tex
85 # - find papersize from lilypond output file (mudelapapersize),
86 # overridden by option '-p size' or '--papersize=size'
87 # - option -l lang or --language=lang overrides
88 # lilypond output file definition (mudelalanguage)
89 # - textwidth from lilypond output file (mudelapaperlinewidth)
94 # - moved help into function
101 Generate dvi file from mudela or lilypond output
102 Usage: $0 [options] file[s]
105 -D, --debug set debug mode
106 -h, --help this help text
107 -k, --keep keep LaTeX file
108 -l, --language= give LaTeX language (babel)
109 -p, --papersize= give LaTeX papersize (eg. a4paper)
111 files may be (a mix of) input to or output from lilypond(1)
115 # Keywords defined in titledefs.tex
117 TF=`kpsewhich -n tex tex titledefs.tex`
120 TF=/usr/lib/texmf/tex/lilypond/titledefs.tex
125 MU_DEF=`egrep "^.newcommand...mudela" $TF | \\
126 sed -e 's/^.newcommand...//' -e 's/\\}.*$//'`
131 MU_DEF="mudelatitle mudelasubtitle mudelacomposer \
132 mudelaarranger mudelainstrument"
141 # Find command line options and switches
143 # "x:" x takes argument
148 # ugh, "\-" is a hack to support long options
149 # while getopts \-:$options$switches O
150 # must be in double quotes for bash-2.0
151 while getopts "\-:$options$switches" O
153 $debug_echo "O: \`$O'"
154 $debug_echo "arg: \`$OPTARG'"
157 if [ $debug_echo = echo ]
182 $debug_echo "long option: \`$OPTARG'"
192 LNG=`echo $OPTARG | sed -e s/"^.*="//`
195 PSZ=`echo $OPTARG | sed -e s/"^.*="//`
198 if [ $debug_echo = echo ]
205 echo $0": illegal option -- "$OPTARG;
212 shift `expr $OPTIND - 1`
219 $debug_echo $IDENTIFICATION": No input file name given"
226 # Check if input file exists...
233 $debug_echo $IDENTIFICATION": Input file "$GF" not found"
238 # Check whether the file is input to or output from lilypond
241 OP=`echo $L1 | grep "^% Creator: GNU LilyPond"`
245 # OK - it's the output from lilypond.
247 # Get lilypond source file name
250 IFL=`grep mudelafilename $OF`
253 IF=`echo $IFL | sed -e 's/.*{//' -e 's/}*.$//'`
255 # Check if source file exists
259 $debug_echo $IDENTIFICATION": Mudela file not found."
263 $debug_echo $IDENTIFICATION": Mudela file name not found."
268 # I have to assume this is the lilypond input file
269 # Find output file name, if defined
274 # Grab output file names
276 $debug_echo "lilypond "$IF
278 lilypond $IF 2>&1 | tee /tmp/lilylog.$$
279 OF=`cat /tmp/lilylog.$$| egrep '^TeX output to ' | \\
280 sed -e 's/TeX output to//' -e 's/\.\.\.//'`
281 $debug_echo "==> "$OF
284 # Check if output file is generated
288 $debug_echo "--- "$File
291 $debug_echo $IDENTIFICATION": hmm, I could not find the output file "$File
300 if [ "$KEEP" != "Y" ]
308 $debug_echo $IDENTIFICATION": temporary directory "$TMP" not found, set to /tmp"
312 BN=`basename $FFile .tex`
316 BN=`basename $FFile .tex`
322 # paper size (PSZ, overridden by command line option -p)
323 # language (LNG, overridden by command line option -l)
327 -e 's/\\\\def\\\\mudelapapersize{\([^}]*\).*$/fPSZ=\1;/p' \\
328 -e 's/\\\\def\\\\mudelalanguage{\([^}]*\).*$/fLNG=\1;/p' \\
329 -e 's/\\\\def\\\\mudelapaperlinewidth{\([^}]*\).*$/TWN=\1;/p' \\
346 LLNG="\usepackage["$LNG"]{babel}"
368 $debug_echo "Text width = "$TW
375 % Creator: $IDENTIFICATION
376 % Automatically generated from $IF, $NOW
378 \documentclass$PAPER{article}
381 \usepackage[T1]{fontenc}
382 \addtolength{\oddsidemargin}{-1cm}
383 \addtolength{\topmargin}{-1cm}
384 \setlength{\textwidth}{$TW}
390 # Include \def\mudela-definitions
394 LL=`egrep '^\\\\def.'$L'{' $OF`
397 LLL=`echo $LL | sed -e 's/}.*$//' -e 's/.*{//'`
400 echo '\'$L'{'$LLL'}%' >> $LF
415 \vfill\hfill{(\LilyIdString)}
432 if [ "$KEEP" != "Y" ]
441 $IDENTIFICATION: dvi file name is $BN.dvi