From: Julien Rioux <jrioux@physics.utoronto.ca>
Date: Wed, 23 Jan 2013 23:21:22 +0000 (-0500)
Subject: lilypond-book: Textwidth detection with included file (issue 3136).
X-Git-Tag: release/2.17.17-1~24
X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=aefc5a4057a0a61f1d7e4411cc1c5061d9aea6b7;p=lilypond.git

lilypond-book: Textwidth detection with included file (issue 3136).

Fix the automatic textwidth detection performed by lilypond-book.
This failed for lytex files that include an external file in the
preamble, when such file was compiled in an --output directory
different from the working directory, because then the included
file was missing. We use TEXINPUTS to let the latex process know
where to look for input files.
---

diff --git a/input/regression/lilypond-book/include/def.tex b/input/regression/lilypond-book/include/def.tex
new file mode 100644
index 0000000000..e9879a2681
--- /dev/null
+++ b/input/regression/lilypond-book/include/def.tex
@@ -0,0 +1 @@
+\def\signature{The LilyPond Team}
diff --git a/input/regression/lilypond-book/tex-include-preamble.lytex b/input/regression/lilypond-book/tex-include-preamble.lytex
new file mode 100644
index 0000000000..a3815f21e2
--- /dev/null
+++ b/input/regression/lilypond-book/tex-include-preamble.lytex
@@ -0,0 +1,20 @@
+\documentclass{article}
+
+\input{include/def.tex}
+
+\begin{document}
+
+If the include file in the preamble is not available,
+the automatic line width detection would fail and the
+snippet below would have only one bar per line.
+
+\begin{lilypond}
+\relative c' {
+  a d a c e d a c
+  f g d e a d a c
+}
+\end{lilypond}
+
+Brought to you by \signature.
+
+\end{document}
diff --git a/python/book_latex.py b/python/book_latex.py
index f2aa5e36cf..e1eda89983 100644
--- a/python/book_latex.py
+++ b/python/book_latex.py
@@ -13,6 +13,7 @@ global _;_=ly._
 progress = ly.progress
 warning = ly.warning
 error = ly.error
+debug = ly.debug_output
 
 # Recognize special sequences in the input.
 #
@@ -186,9 +187,10 @@ def get_latex_textwidth (source, global_options):
     tmp_handle.close ()
 
     progress (_ ("Running `%s' on file `%s' to detect default page settings.\n")
-              % (global_options.latex_program, tmpfile));
-    cmd = '%s %s' % (global_options.latex_program, tmpfile);
-    ly.debug_output ("Executing: %s\n" % cmd);
+              % (global_options.latex_program, tmpfile))
+    cmd = 'TEXINPUTS=%s:$TEXINPUTS %s %s' \
+        % (global_options.input_dir, global_options.latex_program, tmpfile)
+    debug ("Executing: %s\n" % cmd)
     run_env = os.environ.copy()
     run_env['LC_ALL'] = 'C'
 
diff --git a/scripts/lilypond-book.py b/scripts/lilypond-book.py
index 903e5e5221..6d424a1852 100644
--- a/scripts/lilypond-book.py
+++ b/scripts/lilypond-book.py
@@ -544,10 +544,12 @@ def do_file (input_filename, included=False):
         in_handle = file (input_fullname)
 
     if input_filename == '-':
+        global_options.input_dir = os.getcwd ()
         input_base = 'stdin'
     elif included:
         input_base = os.path.splitext (input_filename)[0]
     else:
+        global_options.input_dir = os.path.split (input_absname)[0]
         input_base = os.path.basename (
             os.path.splitext (input_filename)[0])