# Written by Jan Arne Fagertun <Jan.A.Fagertun@energy.sintef.no>
# Sat Nov 22 22:26:43 CET 1997
#
+# $Id: ly2dvi.sh,v 1.16 1998/05/08 21:18:34 janaf Exp $
+#
# Original LaTeX file made by Mats Bengtsson, 17/8 1997
#
-VERSION="0.10"
+VERSION="0.11.hwn1"
NAME=ly2dvi.sh
IDENTIFICATION="$NAME $VERSION"
NOW=`date`
echo "$IDENTIFICATION" 1>&2
+# TODO:
+# prevent orphaned "Lily is here" strings
+
# NEWS
+#0.11.hwn1
+# - height vs heigth
+# - robustification: give \nonstopmode as LaTeX arg; no hanging if no TeX file.
+# - robustification: notice failed cp.
+
+#0.11
+# - more papersizes (thanks Han-Wen) - don't expect LaTeX to accept all...
+# - -W,--Width= : set paper width (points)
+# - -H,--Height= : set paper height (points)
+# - -H and -W is used only when an unknown papersize is to be specified,
+# and has to be combined with a papersize option known to LaTeX
+#NB! - -F,--headers= : name of additional LaTeX headers input file.
+#NB! Changed from -H to -F
+# - -d,--dependencies : passed to lilypond
+
+
+#0.10.jcn1
+# - HEIGHT -> HEIGHT
+# - vertical margins (for a4), same on both sides
+# - textheight from lilypond output file (mudelapapertextheight)
+# - piece titling
+# - mudelapiece, mudelaopus
+#
#0.10
# - -K,--keeplilypond : Keep lilypond output files (default delete)
# - -k,--keeply2dvi : Keep ly2dvi output files (default delete)
# - Could not reinsert "\usepackage[T1]{fontenc}" because
# "los-toros" won't work with it
# - Ekstra LaTeX headers from input file
-
#0.9.hwn1
# - option to remove output of lily
-# 0.9 - Trap Lilypond abort
+# 0.9
+# - Trap Lilypond abort
# - Replaced "\usepackage[T1]{fontenc}" with
# \usepackage[latin1]{inputenc} (takk, Mats)
# - Removed "()" around "\LilyIdString" (Janne didn't want it)
# - Improved Lilypond error checking
# - Output orientation (landscape...). Overrides mudela file
# variable orientation="landscape";
-# - Paper width and heigth put into variables (only A4!)
+# - Paper width and height put into variables (only A4!)
# - Adjusted top margin to default.....
#
#TODO
Options:
-D,--debug set debug mode
- -H,--headers= name of additional LaTeX headers file
+ -F,--headers= name of additional LaTeX headers file
+ -H,--Height= set paper height (points) (see manual page)
-K,--keeplilypond keep lilypond output files
-L,--landscape set landscape orientation
-N,--nonumber switch off page numbering
- -O,--orientation= set orientation (landscape or portrait (default))
- -o,--output= set output directory
+ -O,--orientation= set orientation (obsolete - use -L instead)
+ -W,--Width= set paper width (points) (see manual page)
+ -d,--dependencies tell lilypond make a dependencies file
-h,--help this help text
-k,--keeply2dvi keep ly2dvi output files
-l,--language= give LaTeX language (babel)
- -p,--papersize= give LaTeX papersize (eg. a4paper)
+ -o,--output= set output directory
+ -p,--papersize= give LaTeX papersize (eg. a4)
-s,--separate run all files separately through LaTeX
files may be (a mix of) input to or output from lilypond(1)
$debug_echo $IDENTIFICATION": temporary directory "$TMP" not found, set to /tmp"
TMP=/tmp
fi
-LOGFILE=$TMP/lilylog.$$ # Logfile for lilypond
-PWIDTH=600; # Width of A4 paper!
-PHEIGTH=845; # Heigth of A4 paper!
+LOGFILE=$TMP/lilylog.$$ # Logfile for lilypond
+PAPERSIZE=a4 # Default papersize name
+PWIDTH=597 # Default paperwidth
+PHEIGHT=845 # Default paperheight
PNUM="%" # Page numbering on
+LILYOPTS="" # Options to lilypond
+#
+setPaperZize() {
+case "$PAPERSIZE" in
+ a0*)
+ PWIDTH=2389
+ PHEIGHT=3381
+ PAPERSIZE=a0paper
+ ;;
+ a1|a1p*)
+ PWIDTH=1690
+ PHEIGHT=2389
+ PAPERSIZE=a1paper
+ ;;
+ a2*)
+ PWIDTH=1194
+ PHEIGHT=1690
+ PAPERSIZE=a2paper
+ ;;
+ a3*)
+ PWIDTH=845
+ PHEIGHT=1194
+ PAPERSIZE=a3paper
+ ;;
+ a4*)
+ PWIDTH=597
+ PHEIGHT=845
+ PAPERSIZE=a4paper
+ ;;
+ a5*)
+ PWIDTH=423
+ PHEIGHT=597
+ PAPERSIZE=a5paper
+ ;;
+ a6*)
+ PWIDTH=298
+ PHEIGHT=423
+ PAPERSIZE=a6paper
+ ;;
+ a7*)
+ PWIDTH=211
+ PHEIGHT=298
+ PAPERSIZE=a7paper
+ ;;
+ a8*)
+ PWIDTH=305
+ PHEIGHT=211
+ PAPERSIZE=a8paper
+ ;;
+ a9*)
+ PWIDTH=105
+ PHEIGHT=305
+ PAPERSIZE=a9paper
+ ;;
+ a10*)
+ PWIDTH=74
+ PHEIGHT=105
+ PAPERSIZE=a10paper
+ ;;
+ b0*)
+ PWIDTH=2847
+ PHEIGHT=4023
+ PAPERSIZE=b0paper
+ ;;
+ b1*)
+ PWIDTH=2012
+ PHEIGHT=2847
+ PAPERSIZE=b1paper
+ ;;
+ b2*)
+ PWIDTH=1423
+ PHEIGHT=2012
+ PAPERSIZE=b2paper
+ ;;
+ b3*)
+ PWIDTH=1006
+ PHEIGHT=1423
+ PAPERSIZE=b3paper
+ ;;
+ b4*)
+ PWIDTH=712
+ PHEIGHT=1006
+ PAPERSIZE=b4paper
+ ;;
+ b5*)
+ PWIDTH=503
+ PHEIGHT=712
+ PAPERSIZE=b5paper
+ ;;
+ archA)
+ PWIDTH=650
+ PHEIGHT=867
+ ;;
+ archB)
+ PWIDTH=867
+ PHEIGHT=1301
+ ;;
+ archC)
+ PWIDTH=1301
+ PHEIGHT=1734
+ ;;
+ archD)
+ PWIDTH=1734
+ PHEIGHT=2602
+ ;;
+ archE)
+ PWIDTH=2602
+ PHEIGHT=3469
+ ;;
+ flsa|flse)
+ PWIDTH=614
+ PHEIGHT=940
+ ;;
+ halfletter)
+ PWIDTH=397
+ PHEIGHT=614
+ ;;
+ ledger)
+ PWIDTH=1229
+ PHEIGHT=795
+ ;;
+ legal)
+ PWIDTH=614
+ PHEIGHT=1012
+ ;;
+ letter)
+ PWIDTH=614
+ PHEIGHT=795
+ ;;
+ note)
+ PWIDTH=542
+ PHEIGHT=723
+ ;;
+ *)
+ echo ""
+ echo $0": unknown papersize -- "$PAPERSIZE
+ echo ""
+ ;;
+esac
+}
#
# RC-files ?
#
if [ -z "$MU_DEF" ]
then
MU_DEF="mudelatitle mudelasubtitle mudelacomposer \
- mudelaarranger mudelainstrument"
+ mudelaopus mudelaarranger mudelapiece mudelainstrument"
fi
#
#
# "x:" x takes argument
#
-switches="DH:KLNO:hkl:o:p:s\?"
+switches="DF:H:KLNO:W:dhkl:o:p:s\?"
options=""
#
# ugh, "\-" is a hack to support long options
[ $debug_echo = echo ] && set -x
debug_echo=echo
;;
- H )
+ F )
LATEXHF=$OPTARG
;;
+ H )
+ PHEIGHT=$OPTARG
+ ;;
K )
KEEP_LILY_OUTPUT=Y
;;
N )
PNUM="\pagestyle{empty}"
;;
+ W )
+ PWIDTH=$OPTARG
+ ;;
+ d )
+ LILYOPTS=$LILYOPTS" -d"
+ ;;
h )
help;
exit 0
-)
$debug_echo "long option: \`$OPTARG'"
case "$OPTARG" in
+ He*|-He*)
+ PHEIGHT=`echo $OPTARG | sed -e s/"^.*="//`
+ ;;
+ W*|-W*)
+ PWIDTH=`echo $OPTARG | sed -e s/"^.*="//`
+ ;;
+ dep*|-dep*)
+ LILYOPTS=$LILYOPTS" -d"
+ ;;
d*|-d*)
[ $debug_echo = echo ] && set -x
debug_echo=echo
exit 1
fi
#
+#
+mudelaDefs(){
+# Include \def\mudela-definitions
+#
+for L in $MU_DEF
+do
+ SS=$1
+ # LL=`egrep '^\\\\def.'$L'{' $OF`
+ LL=`egrep '^\\\\def.'$L'{' $File`
+ if [ "$LL" = "" ]
+ then
+ LL=`egrep '^\\\\def.'$L'{' $OF`
+ fi
+ if [ "$LL" != "" ]
+ then
+ ##{
+ LLL=`echo $LL | sed -e 's/}.*$//' -e 's/.*{//'`
+ ##}{
+ if [ "$LLL" != "" ]
+ then
+ echo "$SS\\"$L'{'$LLL'}%' >> $LatF
+ fi
+ fi
+done
+}
startFile(){
#
# LaTeX file name
-e 's/\\\\def\\\\mudelalatexheaders{\([^}]*\).*$/fLHF=\1;/p' \\
-e 's/\\\\def\\\\mudelaorientation{\([^}]*\).*$/fORI=\1;/p' \\
-e 's/\\\\def\\\\mudelapaperlinewidth{\([^}]*\).*$/TWN=\1;/p' \\
+ -e 's/\\\\def\\\\mudelapapertextheight{\([^}]*\).*$/THN=\1;/p' \\
-e 's/\\\\def\\\\mudelapapersize{\([^}]*\).*$/fPSZ=\1;/p' \\
$File`
#
fi
if [ -n "$PAPERSIZE" ]
then
+ setPaperZize
PAPEROPT=$PAPERSIZE
fi
#
fi
TWp=`echo $TW | sed -e 's/\..*$//'`
PWp=$PWIDTH
+#
+# Find textheight
+#
+if [ -n "$THN" ]
+then
+ TH=$THN
+ case $TH in
+ *mm)
+ ;;
+ *cm)
+ ;;
+ *pt)
+ ;;
+ *)
+ TH=$TH"pt"
+ ;;
+ esac
+ $debug_echo "Text height = "$TH
+fi
+THp=`echo $TH | sed -e 's/\..*$//'`
+PHp=$PHEIGHT
if [ "$ORIENTATION" = "landscape" ]
then
- PWp=$PHEIGTH
+ PWp=$PHEIGHT
+ PHp=$PWIDTH
fi
-MARG=`expr $PWp - $TWp`
-MARG=`expr $MARG / 2`"pt"
+HMARG=`expr $PWp - $TWp`
+HMARG=`expr $HMARG / 2`"pt"
+$debug_echo "Text left = "$HMARG
+VMARG=`expr $PHp - $THp`
+VMARG=`expr $VMARG / 2`"pt"
+$debug_echo "Text top = "$VMARG
#
# Geometry: /var/lib/texmf/latex/geometry/geometry.dvi
#
% Automatically generated from $IF, $NOW
\documentclass$PAPER{article}
-\nonstopmode
+
$LLNG
\usepackage{geometry}
\usepackage[latin1]{inputenc}
$PNUM
%\addtolength{\oddsidemargin}{-1cm}
%\addtolength{\topmargin}{-1cm}
-\setlength{\textwidth}{$TW}
-%\geometry{width=$TW, left=$MARG, top=1cm}
-\geometry{width=$TW, left=$MARG}
+%\setlength{\textwidth}{$TW}
+%\setlength{\textheight}{$TH}
+%\geometry{width=$TW, left=$HMARG, top=1cm}
+%\geometry{width=$TW, left=$HMARG}
+%\geometry{height=$TH, top=$VMARG}
+% \geometry{body={$PWp pt, $PHp pt}, width=$TW, top=$HMARG, height=$TH, top=$VMARG}
+\geometry{width=$TW, top=$HMARG, height=$TH, top=$VMARG}
\input lilyponddefs
\input titledefs
$LLHF
\begin{document}
EOF
-#
-# Include \def\mudela-definitions
-#
-for L in $MU_DEF
-do
- LL=`egrep '^\\\\def.'$L'{' $OF`
- if [ "$LL" != "" ]
- then
- LLL=`echo $LL | sed -e 's/}.*$//' -e 's/.*{//'`
- if [ "$LLL" != "" ]
- then
- echo "\\"$L'{'$LLL'}%' >> $LatF
- fi
- fi
-done
-#
+mudelaDefs
cat << EOF >> $LatF
\makelilytitle
EOF
}
+nextFile(){
+cat << EOF >> $LatF
+\def\theopus{}%
+\def\thepiece{}%
+EOF
+mudelaDefs "\\def"
+cat << EOF >> $LatF
+\def\theopus{\mudelaopus}% ugh
+\def\thepiece{\mudelapiece}%
+\makelilypiecetitle
+EOF
+}
#
# Conclusion
#
#
# Run LaTeX
#
-latex $LatF || exit 5
+latex '\nonstopmode \input '$LatF || exit 5
#
# Rename dvi file
#
then
RESULT=$BN.dvi
[ -n "$OUTPUTDIR" ] && RESULT="$OUTPUTDIR/$RESULT"
- cp $FN.dvi $RESULT
+
+ cp $FN.dvi $RESULT || exit 5
+
fi
#
# Output some info
then
$debug_echo $IDENTIFICATION": Mudela file not found."
TW=15.5cm
+ TH=25cm
fi
else
$debug_echo $IDENTIFICATION": Mudela file name not found."
TW=15.5cm
+ TH=25cm
fi
else
#
# Run lilypond
# Grab output file names
#
- $debug_echo "lilypond "$IF
+ $debug_echo "lilypond "$LILYOPTS $IF
- lilypond $IF 2>&1 | tee $LOGFILE
+ lilypond $LILYOPTS $IF 2>&1 | tee $LOGFILE
OF=`egrep '^TeX output to ' $LOGFILE | \\
sed -e 's/TeX output to//' -e 's/\.\.\.//'`
$debug_echo "==> "$OF
then
FFile=$File
startFile
+ else
+ nextFile
fi
cat << EOF >> $LatF
\input{$File}