]> git.donarmstrong.com Git - lilypond.git/blobdiff - scripts/ly2dvi.py
release: 1.3.107
[lilypond.git] / scripts / ly2dvi.py
index e9a09c595915f956acc3bd0aa71d7963ba1cae73..635932dc28bb3a0d50ff7c33ca116034fdd93ce9 100644 (file)
@@ -1,11 +1,12 @@
 #!@PYTHON@
 
 
-# TODO: Rewrite this.  The control structure is too hairy.
-#
-
 # TODO:
-# Should use files in /tmp/ only.  This potentially messes with
+#
+# * Rewrite this.  The control structure is too hairy.
+# * (c) on page 1
+# * more helpful info on lily crashes
+# * Should use files in /tmp/ only.  This potentially messes with
 # usergenerated files in the CWD
 
 
@@ -150,7 +151,7 @@ class Input:
 
         titles={}
         for line in this.__fd.readlines():
-            m=re.match('\\\\def\\\\mudela([\w]+){(.*)}',line)
+            m=re.match('\\\\def\\\\lilypond([\w]+){(.*)}',line)
             if m:
                 for var in varTable:
                     if m.group(1) == var[0]:
@@ -170,7 +171,7 @@ class TeXOutput:
     This class handles all ly2dvi.py output file methods
 
     private methods:
-     __mudelaDefs(opt)  Send title info to output file
+     __lilypondDefs(opt)  Send title info to output file
 
     Public methods:
     __init__()  Constructor
@@ -191,7 +192,7 @@ class TeXOutput:
     #
     # __medelaDefs
     #
-    def __mudelaDefs(this,opt):
+    def __lilypondDefs(this,opt):
         """
         Write titles to output
 
@@ -202,7 +203,7 @@ class TeXOutput:
 
         titles = Props.get('titles')
         for key in titles.keys():
-            this.write('%s\\mudela%s{%s}%%\n' % (opt,key,titles[key]))
+            this.write('%s\\lilypond%s{%s}%%\n' % (opt,key,titles[key]))
 
     #
     # write
@@ -245,8 +246,6 @@ class TeXOutput:
             pageheight = Props.get('pageheight')
             pagewidth = Props.get('pagewidth')
                                 
-        horizontalMarginArg =  ( (pagewidth - linewidth)/2 )   
-        verticalMarginArg =  ( (pageheight - textheight)/2  )
 
         top= r"""
 %% Creator: %s
@@ -258,25 +257,26 @@ class TeXOutput:
 \usepackage{geometry}
 \usepackage[latin1]{inputenc} 
 %%\usepackage[T1]{fontenc} 
+%%
 %s 
-%%\addtolength{\oddsidemargin}{-1cm} 
-%%\addtolength{\topmargin}{-1cm} 
-%%\setlength{\textwidth}{%s} 
-%%\setlength{\textheight}{%s} 
-\geometry{width=%spt, left=%spt, height=%spt, top=%spt, nohead} 
-\input lilyponddefs 
-\input titledefs 
+%% don not waste unused space at bottom of page
+%% (unless we have footnotes ...)
+%%\headheight9pt
+%%\headsep0pt
+%% Maybe this is too drastic, but let us give it a try.
+\geometry{width=%spt, textheight=%spt,headheight=2mm,headsep=0pt,footskip=2mm} 
+\input{titledefs}
 %s
 \makeatletter
-\renewcommand{\@oddhead}{\hfil{\small\theheader\quad\textbf{\thepage}}}%%
+\renewcommand{\@oddhead}{\parbox{\textwidth}%%
+    {\mbox{}\small\theheader\hfill\textbf{\thepage}}}%%
 %% UGR.
-%%\renewcommand{\@evenhead}{eve!{\small\mudelainstrument{,}\quad\textbf{\thepage}}\hfil}%%
-\renewcommand{\@oddfoot}{{\thefooter}\hfil}%%
+%%\renewcommand{\@evenhead}{eve!{\small\lilypondinstrument{,}\quad\textbf{\thepage}}\hfil}%%
+\renewcommand{\@oddfoot}{\parbox{\textwidth}{\mbox{}\thefooter}}%%
 \begin{document}
 """ % ( program_id(), Props.get('filename'), now, Props.get('papersize'),
-        Props.get('language'), Props.get('pagenumber'), linewidth, textheight,
-        linewidth, horizontalMarginArg, textheight, verticalMarginArg,
-        Props.get('header') )
+        Props.get('language'), Props.get('pagenumber'), linewidth,
+        textheight, Props.get('header') )
         
         base, ext = os.path.splitext(file)
         this.__base = base
@@ -289,7 +289,7 @@ class TeXOutput:
         except:
             sys.exit('ExitNoWrite', this.__outfile)
         this.write(top)
-        this.__mudelaDefs('')
+        this.__lilypondDefs('')
         this.write("""\
 \\makelilytitle
 """) 
@@ -311,13 +311,13 @@ class TeXOutput:
         this.write("""\
 \\def\\theopus{}%
 \\def\\thepiece{}%
-\\def\\mudelaopus{}%
-\\def\\mudelapiece{}%
+\\def\\lilypondopus{}%
+\\def\\lilypondpiece{}%
 """)
-        this.__mudelaDefs("\\def")
+        this.__lilypondDefs("\\def")
         this.write("""\
-\\def\\theopus{\\mudelaopus}% ugh
-\\def\\thepiece{\\mudelapiece}%
+\\def\\theopus{\\lilypondopus}% ugh
+\\def\\thepiece{\\lilypondpiece}%
 \\makelilypiecetitle
 """)
 
@@ -339,9 +339,9 @@ class TeXOutput:
             outfile = os.path.join(Props.get('output'), outfile )
             
         this.write(r"""
-%% \vfill\hfill{\mudelatagline}
+%% \vfill\hfill{\lilypondtagline}
 \makeatletter
-\renewcommand{\@oddfoot}{\thefooter\hfill{\mudelatagline}}%
+\renewcommand{\@oddfoot}{\parbox{\textwidth}{\mbox{}\lilypondtagline}}%%
 \makeatother
 \end{document}
 """)
@@ -397,7 +397,7 @@ class Properties:
         # Requester     Description
         # ---------     -----------
         # init          Initial default values
-        # file          The values found in the lilypond generated TeX files
+        # file          The values found in the LilyPond generated TeX files
         # environment   Envrionment variables LILYINCLUDE, LILYPONDPREFIX
         # rcfile        $LILYPONDPREFIX/.lilyrc
         # rcfile        $HOME/.lilyrc
@@ -494,7 +494,7 @@ class Properties:
         mudefs=[]    
 
         for line in fd.readlines():
-            m=re.match('\\\\newcommand\*{\\\\mudela([\w]+)}',line)
+            m=re.match('\\\\newcommand\*{\\\\lilypond([\w]+)}',line)
             if m:
                 mudefs.append(m.group(1))
        fd.close
@@ -817,7 +817,7 @@ class Properties:
     # Set latex header name
     #
     def setHeader(this,head, requester):
-       this.__set('header',head,requester)
+       this.__set('header','\\input{' + head + '}',requester)
 
     #
     # Set or Clear Dependencies flag to generate makefile dependencies
@@ -839,7 +839,7 @@ class Properties:
        this.__set('tmp',dir,requester)
 
     #
-    # Set mudela source file name
+    # Set lilypond source file name
     #
     def setFilename(this,file, requester):     
        this.__set('filename',file,requester)
@@ -880,7 +880,7 @@ class Properties:
     #
     def setRoot(this,path, requester): 
         """
-        Set lilypond root directory
+        Set LilyPond root directory
         """
 
         os.environ['LILYPONDPREFIX'] = path
@@ -960,7 +960,7 @@ def unc2dos(path):
     
 
 def program_id ():
-    return 'ly2dvi (GNU lilypond) ' + version;
+    return 'ly2dvi (GNU LilyPond) ' + version;
 
 
 def mailaddress():
@@ -980,20 +980,20 @@ def help ():
     sys.stdout.write (
 """Usage: %s [OPTION]... [FILE]...
 
-Generate dvi file from mudela or lilypond output
+Generate dvi file from LilyPond source/output
 
 Options:
   -D,--debug           increase verbosity
   -F,--headers=        name of additional LaTeX headers file
   -H,--Height=         set paper height (points) (see manual page)
   -I,--include=DIR     add DIR to LilyPond\'s search path
-  -K,--keeplilypond    keep lilypond output files
+  -K,--keeplilypond    keep LilyPond output files
   -L,--landscape       set landscape orientation
   -N,--nonumber        switch off page numbering
-  -O,--orientation=    set orientation (obsolete - use -L instead)
-  -P,--postscript      generate postscript file
+  -O,--orientation=    set orientation (obsolete -- use -L instead)
+  -P,--postscript      generate PostScript file
   -W,--Width=          set paper width (points) (see manual page)
-  -M,--dependencies    tell lilypond make a dependencies file
+  -M,--dependencies    tell LilyPond to make a dependencies file
   -h,--help            this help text
   -k,--keeply2dvi      keep ly2dvi output files
   -l,--language=       give LaTeX language (babel)
@@ -1001,7 +1001,7 @@ Options:
   -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)
+files may be (a mix of) input to or output from LilyPond(1)
 """ % name)
 
 \f
@@ -1011,7 +1011,7 @@ files may be (a mix of) input to or output from lilypond(1)
 #
 
 def main():
-    """Generate dvi files from lilypond source/output"""
+    """Generate dvi files from LilyPond source/output"""
 
     infile = Input()
     outfile = TeXOutput()
@@ -1026,6 +1026,7 @@ def main():
                                        'help', 'keeply2dvi', 'language=',
                                        'output=', 'version', 'papersize=', 'separate',
                                        'postscript'])
+
     for opt in options:
         o = opt[0]
         a = opt[1]
@@ -1065,6 +1066,9 @@ def main():
        elif o == '--version':
            print_version ()
            return 0
+       else:
+           print o
+           raise getopt.error
            
     identify()
     Props.read_titledefs ()
@@ -1144,8 +1148,8 @@ ExitTable = {
     'ExitBadWidth'         : ['Invalid Width specification', 6 ],
     'ExitBadOrient'        : ['Invalid Orientation specification', 7 ],
     'ExitNoWrite'          : ['Permission denied', 8 ],
-    'ExitNoTeXName'        : ['hmm, I could not find an output file name', 9 ],
-    'ExitBadLily'          : ['Lilypond failed', 10 ],
+    'ExitNoTeXName'        : ['Hmm, I could not find an output file name', 9 ],
+    'ExitBadLily'          : ['LilyPond failed', 10 ],
     'ExitBadLatex'         : ['Latex failed', 11 ],
     'ExitBadPostscript'    : ['Postscript failed', 12 ],
     'ExitUnknown'          : ['Unknown Exit Code', 20 ],