]> git.donarmstrong.com Git - lilypond.git/commitdiff
lilypond-book: Use 550.0 as textwidth when autodetection fails.
authorJulien Rioux <jrioux@physics.utoronto.ca>
Thu, 21 Feb 2013 20:35:25 +0000 (15:35 -0500)
committerJulien Rioux <jrioux@physics.utoronto.ca>
Sun, 21 Apr 2013 18:21:14 +0000 (14:21 -0400)
python/book_latex.py

index e1eda89983f2e3850df4695a1be838ff27e0ba7c..8d2104b08dd5e5a880a4dc3c9b6dc363e570315c 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}
@@ -239,12 +240,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