lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

lilypond-book.py can hang on Windows 10; I know why; I need help to fix


From: Jean Abou Samra
Subject: lilypond-book.py can hang on Windows 10; I know why; I need help to fix it
Date: Thu, 4 Feb 2021 20:44:49 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.5.0

Back on January 12, 2021, I wrote to this forum about a problem I was having running the example from https://lilypond.org/doc/v2.19/Documentation/usage/an-example-of-a-musicological-document <https://lilypond.org/doc/v2.19/Documentation/usage/an-example-of-a-musicological-document> for embedding Lilypond code inside a LaTeX document.  The python script, lilypond-book.py starts up, I get a few lines of output, and then the program hangs.  One reader of this forum wrote to me that the script works for him, so I knew there was something about my installation of Lilypond or version of Python or something.  By the way, I had no problems with lilypond-book on Linux.

Today I began to read through the python code that runs when lilypond-book.py is invoked.  The authors of the python code cleverly, in python-latex.py, create a temporary .tex file that is run with pdflatex to extract some information about the linewidth and column separation.  The authors import the python library tempfile and use the method mkstemp to create the filename for the temporary file.  I sprinkled some print functions into the python code to trace what was going on and discovered that the temporary file gets created on my Windows 10 system in:
C:\Users\<user_id>\AppData\Local\Temp
where <user_id> is my Windows user account name.  My user_id has 9 characters in it, for example DanABCDEF. However, the path for the temporary file was shown by one of my debugging print statements to be C:\Users\DanABCD~F\AppData\Local\Temp.  This is an old DOS "8.3" file naming convention DOS used to deal with "long" path and filenames.

After creating this temporary file, pdflatex tries to run on it and pdflatex gags because it can't find the file; pdflatex can't deal with the "~" in the file pathname.  The process that is running pdflatex tries to prompt me to enter another name.  However that process' output isn't shown and all I see is a hung program.

So because my user_id is more than 8 characters long the temporary file pathname gets trashed.  I bet the user who wrote me that lilypond-book worked for him has a short Windows user_id!

I've looked around a little bit in Python to see if there are options when the mkstemp is called to create a Windows temporary filename without the "8.3" legacy DOS naming convention.  I didn't see anything.  Some of my Google searches suggested there is an additional library that could be imported that deals with long filenames.

I am turning this over to any follower of this forum who is more skilled than I am in Python to come up with a fix.

By the way, I am using Lilypond and lilypond-book to engrave a short piece of music into a lab assignment handout sheet that I create in LaTeX that I give to my digital signal processing (DSP) students.  They have to synthesize the music on a DSP hardware board.

Thank you for your help.

Dan

Hi,

Wow, Windows is even worse than I thought!

Maybe try the following diff (but I don't have a Windows machine to test it):


diff --git a/python/book_latex.py b/python/book_latex.py
index 2530fd75ba..1e2cfb36e4 100644
--- a/python/book_latex.py
+++ b/python/book_latex.py
@@ -204,7 +204,7 @@ def get_latex_textwidth(source, global_options):
     preamble = source[:m.start(0)]
     latex_document = LATEX_INSPECTION_DOCUMENT % {'preamble': preamble}

-    (handle, tmpfile) = tempfile.mkstemp('.tex')
+    (handle, tmpfile) = tempfile.mkstemp('.tex', dir=".") # create temporary file in current directory
     tmpfileroot = os.path.splitext(tmpfile)[0]
     tmpfileroot = os.path.split(tmpfileroot)[1]
     auxfile = tmpfileroot + '.aux'
@@ -216,7 +216,7 @@ 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 = '%s %s' % (global_options.latex_program, tmpfile)
+    cmd = '%s %s' % (global_options.latex_program, os.path.relpath(tmpfile)) # convert to relative path so there isn't any tilde
     debug("Executing: %s\n" % cmd)
     run_env = os.environ.copy()
     run_env['LC_ALL'] = 'C'


In general, I would not recommend using lilypond-book. lyLuaTeX is so much better: https://mirrors.ircam.fr/pub/CTAN/support/lyluatex/lyluatex.pdf

Best,
Jean




reply via email to

[Prev in Thread] Current Thread [Next in Thread]