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 IDENTIFICATION="$NAME $VERSION"
15 echo "$IDENTIFICATION" 1>&2
20 # - handle LILYINCLUDE
24 # - Source rc-files, if present. Files are:
25 # /usr/local/share/lilyrc /etc/lilyrc $HOME/.lilyrc ./.lilyrc
26 # - tee output from Lilypond
27 # - Handles margins for A4 paper (equal on both sides)
28 # - new option -s (--separate) for one LaTeX run per file,
29 # else all files are run together
32 # - More useful ("two-level") debug.
33 # - The Q&D hack to find file names and not handling \include
34 # is replaced by grabbing output file names from Lilypond.
35 # = Detects multiple output files - adds them when running
37 # - Works with multiple input files - no matter if they are
38 # (a mix of) input to or output from Lilypond.
41 # - Still no margins handling.
42 # - We have to discuss how to handle multiple output files
43 # from Lilypond - 'ly2dvi standchen' gives a rather odd
47 # - Always exit after printing help info
49 # - Changes to ensure for more strict grep'ing of parameters
50 # Thanks to from G.B.Stott@bolton.ac.uk
51 # - More efficient use of sed -e 's///' -e 's///'
52 # Thanks to Johan Vromans <jvromans@squirrel.nl> and GBS
53 # - Ask tex for location of titledefs.tex (Thanks to JV)
54 # - Accept only exact match of "\def\mudelacomposer{"
55 # (or whatever mudela* defined in titledefs.tex)
56 # - Even more efficient use of sed (Thanks to JV)
57 # - Default file name for single output file implemented.
58 # - Moved help into function - finally included from 0.1.jcn1
61 # - Still doesn't handle \include
62 # - The Q&D for finding output file name from the sequence of
63 # \paper \output \midi \output really needs to be looked at.
64 # I have improved it a lot, but it's only capable of finding
65 # one (the last) file name.
66 # Well, I have to rewrite this entirely to handle \include,
68 # - Still no margins handling.
71 # - Some lines of output from lilypond do NOT start
72 # at first character position, therefore I have removed "^"
73 # in sed'ing and grep'ing.
76 # - add "Creator: " line to output
79 # - multiple input files to make score from several files
80 # (extra files assumed to be Lilypond output)
81 # - cp dvi-file instead of mv, to allow for xdvi reload
82 # - check for illegal long options
83 # - put in pt in text width, if not given
84 # - put in \nonstopmode in LaTeX file
85 # - restored LaTeX exit value check
88 # - temporarily omit LaTeX exit value check
89 # - remove ALL temporary files
92 # - fix for solaris - included from 0.1.jcn1
93 # - long option hack - included from 0.1.jcn1 - modified
94 # - moved help into function - NOT included from 0.1.jcn1 yet
95 # - various improvements - included from 0.1.jcn1
96 # - find mudela definitions from titledefs.tex
97 # - find papersize from lilypond output file (mudelapapersize),
98 # overridden by option '-p size' or '--papersize=size'
99 # - option -l lang or --language=lang overrides
100 # lilypond output file definition (mudelalanguage)
101 # - textwidth from lilypond output file (mudelapaperlinewidth)
106 # - moved help into function
113 Generate dvi file from mudela or lilypond output
114 Usage: $0 [options] file[s]
117 -D, --debug set debug mode
118 -o, --output set output directory
119 -h, --help this help text
120 -k, --keep keep LaTeX file
121 -l, --language= give LaTeX language (babel)
122 -p, --papersize= give LaTeX papersize (eg. a4paper)
123 -s, --separate run all files separately through LaTeX
125 files may be (a mix of) input to or output from lilypond(1)
132 for D in /usr/local/share/ /etc/ $HOME/. ./.
135 [ -f $RCfile ] && . $RCfile
139 # Keywords defined in titledefs.tex
141 TF=`kpsewhich -n tex tex titledefs.tex`
144 TF=/usr/lib/texmf/tex/lilypond/titledefs.tex
149 MU_DEF=`egrep "^.newcommand...mudela" $TF | \\
150 sed -e 's/^.newcommand...//' -e 's/\\}.*$//'`
155 MU_DEF="mudelatitle mudelasubtitle mudelacomposer \
156 mudelaarranger mudelainstrument"
164 # All files in one LaTeX run
168 # Find command line options and switches
170 # "x:" x takes argument
172 switches="Do:hkl:p:s\?"
175 # ugh, "\-" is a hack to support long options
176 # while getopts \-:$options$switches O
177 # must be in double quotes for bash-2.0
178 while getopts "\-:$options$switches" O
180 $debug_echo "O: \`$O'"
181 $debug_echo "arg: \`$OPTARG'"
184 if [ $debug_echo = echo ]
215 $debug_echo "long option: \`$OPTARG'"
218 if [ $debug_echo = echo ]
232 LNG=`echo $OPTARG | sed -e s/"^.*="//`
235 PSZ=`echo $OPTARG | sed -e s/"^.*="//`
244 echo $0": illegal option -- "$OPTARG;
251 shift `expr $OPTIND - 1`
258 $debug_echo $IDENTIFICATION": No input file name given"
266 if [ "$KEEP" != "Y" ]
274 $debug_echo $IDENTIFICATION": temporary directory "$TMP" not found, set to /tmp"
278 BN=`basename $File .tex`
282 BN=`basename $File .tex`
288 # paper size (PSZ, overridden by command line option -p)
289 # language (LNG, overridden by command line option -l)
293 -e 's/\\\\def\\\\mudelapapersize{\([^}]*\).*$/fPSZ=\1;/p' \\
294 -e 's/\\\\def\\\\mudelalanguage{\([^}]*\).*$/fLNG=\1;/p' \\
295 -e 's/\\\\def\\\\mudelapaperlinewidth{\([^}]*\).*$/TWN=\1;/p' \\
312 LLNG="\usepackage["$LNG"]{babel}"
334 $debug_echo "Text width = "$TW
336 TWp=`echo $TW | sed -e 's/\..*$//'`
337 PWp=600; # Width of A4 paper!
338 MARG=`expr $PWp - $TWp`
339 MARG=`expr $MARG / 2`"pt"
341 # Geometry: /var/lib/texmf/latex/geometry/geometry.dvi
347 % Creator: $IDENTIFICATION
348 % Automatically generated from $IF, $NOW
350 \documentclass$PAPER{article}
353 \usepackage{geometry}
354 \usepackage[T1]{fontenc}
355 %\addtolength{\oddsidemargin}{-1cm}
356 %\addtolength{\topmargin}{-1cm}
357 \setlength{\textwidth}{$TW}
358 \geometry{width=$TW, left=$MARG, top=1cm}
364 # Include \def\mudela-definitions
368 LL=`egrep '^\\\\def.'$L'{' $OF`
371 LLL=`echo $LL | sed -e 's/}.*$//' -e 's/.*{//'`
374 echo '\'$L'{'$LLL'}%' >> $LF
388 \vfill\hfill{(\LilyIdString)}
401 if [ x$OUTPUTDIR != x ]; then
402 RESULT="$OUTPUTDIR/$RESULT"
409 if [ "$KEEP" != "Y" ]
418 $IDENTIFICATION: dvi file name is $RESULT
423 # ugh. GF is side-effect.
425 # should check for LILYINCLUDE
426 for lypath in `echo $LILYINCLUDE| sed 's/:/ /g'`
433 if [ -f "$lypath/$1" ]
439 if [ -f "$lypath/$1.ly" ]
445 $debug_echo $IDENTIFICATION": Input file "$GF" not found"
446 echo $NAME": Input file "$GF" not found" 1>&2
450 # Loop through all files
457 # Check whether the file is input to or output from lilypond
460 OP=`echo $L1 | grep "^% Creator: GNU LilyPond"`
464 # OK - it's the output from lilypond.
466 # Get lilypond source file name
469 IFL=`grep mudelafilename $OF`
472 IF=`echo $IFL | sed -e 's/.*{//' -e 's/}*.$//'`
474 # Check if source file exists
478 $debug_echo $IDENTIFICATION": Mudela file not found."
482 $debug_echo $IDENTIFICATION": Mudela file name not found."
487 # I have to assume this is the lilypond input file
488 # Find output file name, if defined
493 # Grab output file names
495 $debug_echo "lilypond "$IF
497 lilypond $IF 2>&1 | tee /tmp/lilylog.$$
498 OF=`egrep '^TeX output to ' /tmp/lilylog.$$ | \\
499 sed -e 's/TeX output to//' -e 's/\.\.\.//'`
501 $debug_echo "==> "$OF
504 # "Spin through" all the files
508 $debug_echo "--- "$File
510 # Check if output file is generated
514 $debug_echo $IDENTIFICATION": hmm, I could not find the output file "$File
518 # Is this the first file?