On Mon, May 30, 2011 at 06:58:11PM +0200, Michal wrote:

> On Sat, 28 May 2011 18:12:13 +0200
> Michal <ms-li...@ms.sebdan.com> wrote:
> 
> > Recently I've reinstalled both MiKTeX and LyX from scratch
> > using official installers for both, and my documents are not
> > compilable anymore, instead I get the following messsage:
> > 
> >     ! LaTeX Error: File `preambles/common.sty' not found.
>     I've investigated this further and it turned out that configure.py
> incorrectly sets the option
> 
>     \tex_expects_windows_paths
> 
> to 'false' on my system, which in turn causes the \def\input@path{{...}}
> line in temporary .tex files generated by LyX to contain cygwin-specific
> path (starting with '/cygdrive/'), which was the reason of LaTeX not
> finding external files.
> 
>     The reason for this 'misbehavior' is the following line in
> configure.py, taken from checkTeXPaths():
> 
> latex_out = cmdOutput(r'latex "\nonstopmode\input{%s}"' % inpname)
> 
>     Latex executed this way won't work as intended when there are spaces
> in inpname (which is a full path to temporary file). It still works most
> of the times because inpname for some reason contains the DOS 8+3 path
> whenever it is available, for example on test system of mine:
> 
>     c:/docume\string~1/ms/ustawi\string~1/temp/tmpyhdnnl.ltx
> 
> ('\string' is added a few lines earlier before each tilde) but on a
> system I'm currently using it contained:
>     c:/documents and settings/ms/ustawienia lokalne/temp/tmp_fnkii.ltx
> 
> which confused LaTeX and resulted in a problem I've experienced.

I could reproduce the problem by setting the TEMP env var to a path
with spaces.

>     The more correct way of executing LaTeX is for example used in
> checkTeXAllowSpaces():
> 
> if os.name == 'nt':
>     latex_out = cmdOutput(LATEX + r""""\nonstopmode\input{\"a b\"}" """)
> else:
>     latex_out = cmdOutput(LATEX + r"""'\nonstopmode\input{"a b"}' """)
> 
> ... and it additionally uses the LATEX variable, so I think
> checkTeXPaths() should be corrected similarly. BTW: isn't it another bug
> to not to add space after LATEX? Also: shouldn't checkTeXPaths() also
> rely on the previously executed checkTeXAllowSpaces() result and try to
> avoid spaces when these are unsupported (couldn't test it, because
> MikTeX's latex.exe apparently supports spaces)?
> 
>     Anyway, the attached patch (wrt LyX 2.0 'official' configure.py)
> helped and my problem is now gone.
> 
>     Could someone test and apply this patch (I'm not a LyX developer
> myself)?

Your patch would not work if TeX doesn't allow spaces in filenames, so
I committed the attached patch that simply transforms the path in its
short form.

-- 
Enrico
Index: lib/configure.py
===================================================================
--- lib/configure.py    (revisione 38892)
+++ lib/configure.py    (copia locale)
@@ -102,7 +102,14 @@ def checkTeXPaths():
         from tempfile import mkstemp
         fd, tmpfname = mkstemp(suffix='.ltx')
         if os.name == 'nt':
-            inpname = tmpfname.replace('\\', '/')
+            from ctypes import windll, create_unicode_buffer
+            GetShortPathName = windll.kernel32.GetShortPathNameW
+            longname = unicode(tmpfname)
+            shortname = create_unicode_buffer(len(longname)+1)
+            if GetShortPathName(longname, shortname, len(longname)+1):
+                inpname = shortname.value.replace('\\', '/')
+            else:
+                inpname = tmpfname.replace('\\', '/')
         else:
             inpname = cmdOutput('cygpath -m ' + tmpfname)
         logname = os.path.basename(inpname.replace('.ltx', '.log'))

Reply via email to