# * (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
+# user generated files in the CWD
"""
import glob
import tempfile
-os.environ['LANG'] = '' # Can't grep localized msgs
+# Can't grep localized msgs
+os.environ['LC_ALL'] = ''
+os.environ['LANG'] = ''
+os.environ['LC_LANG'] = ''
varTable = [
# regexp set method
# ------ ----------
- ( 'language', Props.setLanguage ),
- ( 'latexheaders', Props.setHeader ),
- ( 'orientation', Props.setOrientation ),
- ( 'paperpapersize', Props.setPaperZize ),
- ( 'papertextheight', Props.setTextHeight ),
- ( 'paperlinewidth', Props.setLineWidth ),
- ( 'filename', Props.setFilename ),
+ ( 'language', Props.setLanguage ),
+ ( 'latexheaders', Props.setHeader ),
+ ( 'latexpackages', Props.setPackages ),
+ ( 'paperorientation', Props.setOrientation ),
+ ( 'paperpapersize', Props.setPaperZize ),
+ ( 'papertextheight', Props.setTextHeight ),
+ ( 'paperlinewidth', Props.setLineWidth ),
+ ( 'filename', Props.setFilename ),
]
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]:
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
#
# __medelaDefs
#
- def __mudelaDefs(this,opt):
+ def __lilypondDefs(this,opt):
"""
Write titles to output
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
#
def start(this,file):
"""
- Start LaTeX file. Calculates the horizontal and vertical
- margin using pagewidth, pageheight, linewidth, and textheight.
- Creates temporary output filename and opens it for write.
- Sends the LaTeX header information to output. Lastly sends
- the title information to output.
+ Start LaTeX file. Sets the linewidth (and possibly the
+ textheight) and leaves the page layout to the geometry
+ package. Creates temporary output filename and opens it
+ for write. Sends the LaTeX header information to output.
+ Lastly sends the title information to output.
input: file output file name
output: None
"""
now=time.asctime(time.localtime(time.time()))
- linewidth = Props.get('linewidth')
- textheight = Props.get('textheight')
- if Props.get('orientation') == 'landscape':
- pagewidth = Props.get('pageheight')
- pageheight = Props.get('pagewidth')
+ # Only set the textheight if it was explicitly set by the user,
+ # otherwise use the default. Helps to handle landscape correctly!
+ if Props.get('textheight') > 0:
+ textheightsetting = ',textheight=' + `Props.get('textheight')` + 'pt'
else:
- pageheight = Props.get('pageheight')
- pagewidth = Props.get('pagewidth')
-
+ textheightsetting = ''
+
top= r"""
%% Creator: %s
-%% Automatically generated from %s, %s
+%% Generated automatically by: %s, from %s, at %s
\documentclass[%s]{article}
\usepackage[latin1]{inputenc}
%%\usepackage[T1]{fontenc}
%%
-%s
%% 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}
+\geometry{width=%spt%s,headheight=2mm,headsep=0pt,footskip=2mm,%s}
\input{titledefs}
%s
\makeatletter
\renewcommand{\@oddhead}{\parbox{\textwidth}%%
{\mbox{}\small\theheader\hfill\textbf{\thepage}}}%%
%% UGR.
-%%\renewcommand{\@evenhead}{eve!{\small\mudelainstrument{,}\quad\textbf{\thepage}}\hfil}%%
+%%\renewcommand{\@evenhead}{eve!{\small\lilypondinstrument{,}\quad\textbf{\thepage}}\hfil}%%
\renewcommand{\@oddfoot}{\parbox{\textwidth}{\mbox{}\thefooter}}%%
+%s
\begin{document}
-""" % ( program_id(), Props.get('filename'), now, Props.get('papersize'),
- Props.get('language'), Props.get('pagenumber'), linewidth,
- textheight, Props.get('header') )
+""" % ( program_id(), program_id(), Props.get('filename'), now, Props.get('papersize'),
+ Props.get('language'), Props.get('linewidth'), textheightsetting,
+ Props.get('orientation'), Props.get('header'), Props.get('pagenumber'))
base, ext = os.path.splitext(file)
this.__base = base
except:
sys.exit('ExitNoWrite', this.__outfile)
this.write(top)
- this.__mudelaDefs('')
+ this.__lilypondDefs('')
this.write("""\
\\makelilytitle
""")
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
""")
outfile=this.__base + '.dvi'
if Props.get('output') != '':
+ if not os.path.exists(Props.get('output')):
+ os.mkdir(Props.get('output'))
+
outfile = os.path.join(Props.get('output'), outfile )
this.write(r"""
-%% \vfill\hfill{\mudelatagline}
+%% \vfill\hfill{\lilypondtagline}
\makeatletter
-\renewcommand{\@oddfoot}{\parbox{\textwidth}{\mbox{}\mudelatagline}}%%
+\renewcommand{\@oddfoot}{\parbox{\textwidth}{\mbox{}\lilypondtagline}}%%
\makeatother
\end{document}
""")
% (outfile))
if Props.get('postscript'):
+ dvipsopts=''
+ if Props.get('orientation') == 'landscape':
+ dvipsopts=dvipsopts + ' -t landscape'
psoutfile=this.__base + '.ps'
if Props.get('output') != '':
psoutfile = os.path.join(Props.get('output'), psoutfile )
- stat = os.system('dvips -o %s %s' % (psoutfile,outfile))
+ stat = os.system('dvips %s -o %s %s' % (dvipsopts,psoutfile,outfile))
if stat:
sys.exit('ExitBadPostscript')
this.__roverrideTable[i[1]]=i[0]
this.__data = {
- 'pagewidth' : [597, this.__overrideTable['init']],
- 'pageheight' : [845, this.__overrideTable['init']],
'papersize' : ['a4paper', this.__overrideTable['init']],
'textheight' : [0, this.__overrideTable['init']],
'linewidth' : [500, this.__overrideTable['init']],
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
( 'KEEPLY2DVI', this.setKeeply2dvi ),
( 'LANGUAGE', this.setLanguage ),
( 'LATEXHF', this.setHeader ),
+ ( 'LATEXPKG', this.setPackages ),
( 'LILYINCLUDE', this.setInclude ),
( 'LILYPONDPREFIX', this.setRoot ),
( 'NONUMBER', this.setNonumber ),
for paper in paperTable:
if re.match(paper[0],size):
found=1
- this.__set('pagewidth',paper[1],requester)
- this.__set('pageheight',paper[2],requester)
this.__set('papersize',paper[3],requester)
break
# Set latex header name
#
def setHeader(this,head, requester):
- this.__set('header','\\input{' + head + '}',requester)
+ this.__set('header','\\input{' + head + '}'+this.get('header'),requester)
+
+ #
+ # Set latex package name
+ #
+ def setPackages(this,pkgs, requester):
+ this.__set('header','\\usepackage{' + pkgs + '}'+this.get('header'),requester)
#
# Set or Clear Dependencies flag to generate makefile dependencies
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)
inc = ''
if len(Props.get('include')) > 0:
inc = string.join (map (lambda x: '-I "%s"' % x, Props.get('include')))
- else:
-
- if Props.get('dependencies'):
- dep=' -M'
- else:
- dep=''
- return inc + dep
- return inc
+ dep=''
+ if Props.get('dependencies'):
+ dep=' --dependencies'
+ return inc + dep
def writeLilylog(file,contents):
if Props.get('keeplilypond'):
else:
return texfiles
+def getDepFiles (log):
+ files=[]
+ for line in string.split (log,'\n'):
+ m = re.search ("dependencies output to (.+)\.\.\.", line)
+ if m:
+ files.append (m.group (1))
+ return files
+
def unc2dos(path):
"""
Convert a path of format //<drive>/this/that/the/other to
-h,--help this help text
-k,--keeply2dvi keep ly2dvi output files
-l,--language= give LaTeX language (babel)
- -o,--output= set output directory
+ -o,--outdir= set output directory
+ --output= set output directory
-p,--papersize= give LaTeX papersize (eg. a4)
-s,--separate run all files separately through LaTeX
'include=', 'keeplilypond', 'landscape',
'nonumber', 'Width=', 'dependencies',
'help', 'keeply2dvi', 'language=',
- 'output=', 'version', 'papersize=', 'separate',
- 'postscript'])
+ 'outdir=', 'output=', 'version',
+ 'papersize=', 'separate', 'postscript'])
for opt in options:
o = opt[0]
Props.setKeeply2dvi(1,'commandline')
elif o == '--language' or o == '-l':
Props.setLanguage(a,'commandline')
- elif o == '--output' or o == '-o':
+ elif o == '--outdir' or o == '-o' or o == '--output':
Props.setOutput(a,'commandline')
elif o == '--papersize' or o == '-p':
Props.setPaperZize(a,'commandline')
if stat:
sys.exit('ExitBadLily', cmd )
texFiles=getTeXFile(log)
+ depFiles=getDepFiles (log)
writeLilylog(file,log)
Props.addLilyOutputFiles(texFiles,'program')
texInputFiles = texInputFiles + texFiles
firstfile=0
if not Props.get('separate'):
outfile.end()
+
+ # --outdir mess
+ if Props.get ('output'):
+ outdir=Props.get ('output')
+ for i in depFiles:
+ text=open (i).read ()
+ # ugh, should use lilypond -o DIR/foo.tex
+ # or --dep-prefix to fix dependencies
+ text=re.sub ('\n([^:]*).tex', '\n' + outdir + '/\\1.dvi', text)
+ text=re.sub (' ([^:]*).tex', ' ' + outdir + '/\\1.dvi', text)
+ open (os.path.join (outdir, i), 'w').write (text)
+ os.remove (i)
+
else:
help()
sys.exit('ExitBadArgs','No files specified')