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 # - LILYINCLUDE update
23 # - handle LILYINCLUDE
27 # - Source rc-files, if present. Files are:
28 # /usr/local/share/lilyrc /etc/lilyrc $HOME/.lilyrc ./.lilyrc
29 # - tee output from Lilypond
30 # - Handles margins for A4 paper (equal on both sides)
31 # - new option -s (--separate) for one LaTeX run per file,
32 # else all files are run together
35 # - More useful ("two-level") debug.
36 # - The Q&D hack to find file names and not handling \include
37 # is replaced by grabbing output file names from Lilypond.
38 # = Detects multiple output files - adds them when running
40 # - Works with multiple input files - no matter if they are
41 # (a mix of) input to or output from Lilypond.
44 # - Still no margins handling.
45 # - We have to discuss how to handle multiple output files
46 # from Lilypond - 'ly2dvi standchen' gives a rather odd
50 # - Always exit after printing help info
52 # - Changes to ensure for more strict grep'ing of parameters
53 # Thanks to from G.B.Stott@bolton.ac.uk
54 # - More efficient use of sed -e 's///' -e 's///'
55 # Thanks to Johan Vromans <jvromans@squirrel.nl> and GBS
56 # - Ask tex for location of titledefs.tex (Thanks to JV)
57 # - Accept only exact match of "\def\mudelacomposer{"
58 # (or whatever mudela* defined in titledefs.tex)
59 # - Even more efficient use of sed (Thanks to JV)
60 # - Default file name for single output file implemented.
61 # - Moved help into function - finally included from 0.1.jcn1
64 # - Still doesn't handle \include
65 # - The Q&D for finding output file name from the sequence of
66 # \paper \output \midi \output really needs to be looked at.
67 # I have improved it a lot, but it's only capable of finding
68 # one (the last) file name.
69 # Well, I have to rewrite this entirely to handle \include,
71 # - Still no margins handling.
74 # - Some lines of output from lilypond do NOT start
75 # at first character position, therefore I have removed "^"
76 # in sed'ing and grep'ing.
79 # - add "Creator: " line to output
82 # - multiple input files to make score from several files
83 # (extra files assumed to be Lilypond output)
84 # - cp dvi-file instead of mv, to allow for xdvi reload
85 # - check for illegal long options
86 # - put in pt in text width, if not given
87 # - put in \nonstopmode in LaTeX file
88 # - restored LaTeX exit value check
91 # - temporarily omit LaTeX exit value check
92 # - remove ALL temporary files
95 # - fix for solaris - included from 0.1.jcn1
96 # - long option hack - included from 0.1.jcn1 - modified
97 # - moved help into function - NOT included from 0.1.jcn1 yet
98 # - various improvements - included from 0.1.jcn1
99 # - find mudela definitions from titledefs.tex
100 # - find papersize from lilypond output file (mudelapapersize),
101 # overridden by option '-p size' or '--papersize=size'
102 # - option -l lang or --language=lang overrides
103 # lilypond output file definition (mudelalanguage)
104 # - textwidth from lilypond output file (mudelapaperlinewidth)
109 # - moved help into function
116 Generate dvi file from mudela or lilypond output
117 Usage: $0 [options] file[s]
120 -D, --debug set debug mode
121 -o, --output set output directory
122 -h, --help this help text
123 -k, --keep keep LaTeX file
124 -l, --language= give LaTeX language (babel)
125 -p, --papersize= give LaTeX papersize (eg. a4paper)
126 -s, --separate run all files separately through LaTeX
128 files may be (a mix of) input to or output from lilypond(1)
135 for D in /usr/local/share/ /etc/ $HOME/. ./.
138 [ -f $RCfile ] && . $RCfile
142 # Keywords defined in titledefs.tex
144 TF=`kpsewhich -n tex tex titledefs.tex`
147 TF=/usr/lib/texmf/tex/lilypond/titledefs.tex
152 MU_DEF=`egrep "^.newcommand...mudela" $TF | \\
153 sed -e 's/^.newcommand...//' -e 's/\\}.*$//'`
158 MU_DEF="mudelatitle mudelasubtitle mudelacomposer \
159 mudelaarranger mudelainstrument"
167 # All files in one LaTeX run
171 # Find command line options and switches
173 # "x:" x takes argument
175 switches="Do:hkl:p:s\?"
178 # ugh, "\-" is a hack to support long options
179 # while getopts \-:$options$switches O
180 # must be in double quotes for bash-2.0
181 while getopts "\-:$options$switches" O
183 $debug_echo "O: \`$O'"
184 $debug_echo "arg: \`$OPTARG'"
187 if [ $debug_echo = echo ]
218 $debug_echo "long option: \`$OPTARG'"
221 if [ $debug_echo = echo ]
235 LNG=`echo $OPTARG | sed -e s/"^.*="//`
238 PSZ=`echo $OPTARG | sed -e s/"^.*="//`
247 echo $0": illegal option -- "$OPTARG;
254 shift `expr $OPTIND - 1`
261 $debug_echo $IDENTIFICATION": No input file name given"
269 if [ "$KEEP" != "Y" ]
277 $debug_echo $IDENTIFICATION": temporary directory "$TMP" not found, set to /tmp"
281 BN=`basename $File .tex`
285 BN=`basename $File .tex`
291 # paper size (PSZ, overridden by command line option -p)
292 # language (LNG, overridden by command line option -l)
296 -e 's/\\\\def\\\\mudelapapersize{\([^}]*\).*$/fPSZ=\1;/p' \\
297 -e 's/\\\\def\\\\mudelalanguage{\([^}]*\).*$/fLNG=\1;/p' \\
298 -e 's/\\\\def\\\\mudelapaperlinewidth{\([^}]*\).*$/TWN=\1;/p' \\
315 LLNG="\usepackage["$LNG"]{babel}"
337 $debug_echo "Text width = "$TW
339 TWp=`echo $TW | sed -e 's/\..*$//'`
340 PWp=600; # Width of A4 paper!
341 MARG=`expr $PWp - $TWp`
342 MARG=`expr $MARG / 2`"pt"
344 # Geometry: /var/lib/texmf/latex/geometry/geometry.dvi
350 % Creator: $IDENTIFICATION
351 % Automatically generated from $IF, $NOW
353 \documentclass$PAPER{article}
356 \usepackage{geometry}
357 \usepackage[T1]{fontenc}
358 %\addtolength{\oddsidemargin}{-1cm}
359 %\addtolength{\topmargin}{-1cm}
360 \setlength{\textwidth}{$TW}
361 \geometry{width=$TW, left=$MARG, top=1cm}
367 # Include \def\mudela-definitions
371 LL=`egrep '^\\\\def.'$L'{' $OF`
374 LLL=`echo $LL | sed -e 's/}.*$//' -e 's/.*{//'`
377 echo '\'$L'{'$LLL'}%' >> $LF
391 \vfill\hfill{\small\LilyIdString}
404 if [ x$OUTPUTDIR != x ]; then
405 RESULT="$OUTPUTDIR/$RESULT"
412 if [ "$KEEP" != "Y" ]
421 $IDENTIFICATION: dvi file name is $RESULT
426 # ugh. GF is side-effect.
428 # should check for LILYINCLUDE
429 for lypath in "." `echo $LILYINCLUDE| sed 's/:/ /g'`
431 if [ -f "$lypath/$1" ]
437 if [ -f "$lypath/$1.ly" ]
443 $debug_echo $IDENTIFICATION": Input file "$GF" not found"
444 echo $NAME": Input file "$GF" not found" 1>&2
448 # Loop through all files
455 # Check whether the file is input to or output from lilypond
458 OP=`echo $L1 | grep "^% Creator: GNU LilyPond"`
462 # OK - it's the output from lilypond.
464 # Get lilypond source file name
467 IFL=`grep mudelafilename $OF`
470 IF=`echo $IFL | sed -e 's/.*{//' -e 's/}*.$//'`
472 # Check if source file exists
476 $debug_echo $IDENTIFICATION": Mudela file not found."
480 $debug_echo $IDENTIFICATION": Mudela file name not found."
485 # I have to assume this is the lilypond input file
486 # Find output file name, if defined
491 # Grab output file names
493 $debug_echo "lilypond "$IF
495 lilypond $IF 2>&1 | tee /tmp/lilylog.$$
496 OF=`egrep '^TeX output to ' /tmp/lilylog.$$ | \\
497 sed -e 's/TeX output to//' -e 's/\.\.\.//'`
499 $debug_echo "==> "$OF
502 # "Spin through" all the files
506 $debug_echo "--- "$File
508 # Check if output file is generated
512 $debug_echo $IDENTIFICATION": hmm, I could not find the output file "$File
516 # Is this the first file?