]> git.donarmstrong.com Git - lilypond.git/blobdiff - python/book_latex.py
Merge remote-tracking branch 'origin/translation'
[lilypond.git] / python / book_latex.py
index e1eda89983f2e3850df4695a1be838ff27e0ba7c..a3b2b18b78907134b3b9c0e4035d473fc6f3d52a 100644 (file)
@@ -166,12 +166,13 @@ LATEX_INSPECTION_DOCUMENT = r'''
 
 # Do we need anything else besides `textwidth'?
 def get_latex_textwidth (source, global_options):
+    # default value
+    textwidth = 550.0
+
     m = re.search (r'''(?P<preamble>\\begin\s*{document})''', source)
     if m == None:
         warning (_ ("cannot find \\begin{document} in LaTeX document"))
-
-        ## what's a sensible default?
-        return 550.0
+        return textwidth
 
     preamble = source[:m.start (0)]
     latex_document = LATEX_INSPECTION_DOCUMENT % {'preamble': preamble}
@@ -188,16 +189,18 @@ def get_latex_textwidth (source, global_options):
 
     progress (_ ("Running `%s' on file `%s' to detect default page settings.\n")
               % (global_options.latex_program, tmpfile))
-    cmd = 'TEXINPUTS=%s:$TEXINPUTS %s %s' \
-        % (global_options.input_dir, global_options.latex_program, tmpfile)
+    cmd = '%s %s' % (global_options.latex_program, tmpfile)
     debug ("Executing: %s\n" % cmd)
     run_env = os.environ.copy()
     run_env['LC_ALL'] = 'C'
+    run_env['TEXINPUTS'] = '%s:%s' % \
+                           (global_options.input_dir, run_env.get('TEXINPUTS',""))
 
     ### unknown why this is necessary
     universal_newlines = True
     if sys.platform == 'mingw32':
         universal_newlines = False
+    if (sys.platform == 'mingw32') and (sys.version_info < (2, 6)):
         ### use os.system to avoid weird sleep() problems on
         ### GUB's python 2.4.2 on mingw
         # make file to write to
@@ -239,12 +242,22 @@ def get_latex_textwidth (source, global_options):
     if m:
         columnsep = float (m.group (1))
 
-    textwidth = 0
     m = re.search ('textwidth=([0-9.]+)pt', parameter_string)
     if m:
         textwidth = float (m.group (1))
-        if columns:
-            textwidth = (textwidth - columnsep) / columns
+    else:
+        warning (_ ("cannot detect textwidth from LaTeX"))
+        return textwidth
+
+    debug ('Detected values:')
+    debug ('  columns = %s' % columns)
+    debug ('  columnsep = %s' % columnsep)
+    debug ('  textwidth = %s' % textwidth)
+
+    if m and columns:
+        textwidth = (textwidth - columnsep) / columns
+        debug ('Adjusted value:')
+        debug ('  textwidth = %s' % textwidth)
 
     return textwidth
 
@@ -285,9 +298,10 @@ class BookLatexOutputFormat (BookBase.BookOutputFormat):
     def input_fullname (self, input_filename):
         # Use kpsewhich if available, otherwise fall back to the default:
         if ly.search_exe_path ('kpsewhich'):
-            return os.popen ('kpsewhich ' + input_filename).read()[:-1]
-        else:
-            return BookBase.BookOutputFormat.input_fullname (self, input_filename)
+            trial = os.popen ('kpsewhich ' + input_filename).read()[:-1]
+            if trial:
+                return trial
+        return BookBase.BookOutputFormat.input_fullname (self, input_filename)
 
     def process_chunks (self, chunks):
         for c in chunks: