Re: Automatic setting TEXINPUTS environment for lyx provided files

2017-07-16 Thread Kornel Benko
Am Sonntag, 16. Juli 2017 um 20:14:21, schrieb Enrico Forestieri 

> On Wed, Jul 12, 2017 at 11:46:31AM +0200, Kornel Benko wrote:
> > 
> > I implemented it now in cmake build. At first, everything seemed to work.
> > Reconfiguring lyx...
> > Load examples/chessgame.lyx
> > --> The selected document class Chess requires external files ...
> > Pdf creation is OK though.
> > So the "configure.py" apparently does not honour the lyxrc.dist entry
> > '\texinputs_prefix ".:/usr/local/share/lyx2.3/tex"'
> > but compilation in lyx does (as can be seen in
> > Tools->Preferences...->Paths->TEXINPUTS prefix:)
> > 
> > In fact, the entries in clsFiles.lst are missing now.
> 
> This is because TeXFiles.py is called without setting TEXINPUTS.
> Moreover, there is also the issue that MikTeX's kpsewhich completely
> ignores TEXINPUTS. However, the attached patch works for me on any
> platform I have access to and with any TeX engine.
> 

Thanks. Your patch is indeed what I was lurking for.
The only drawback is that it does not help to compile exported latex.
OTOH, someone who uses exported .tex files may be expected to be able
to set TEXINPUTS locally too.

Kornel

signature.asc
Description: This is a digitally signed message part.


Re: Automatic setting TEXINPUTS environment for lyx provided files

2017-07-16 Thread Enrico Forestieri
On Wed, Jul 12, 2017 at 11:46:31AM +0200, Kornel Benko wrote:
> 
> I implemented it now in cmake build. At first, everything seemed to work.
> Reconfiguring lyx...
> Load examples/chessgame.lyx
>   --> The selected document class Chess requires external files ...
> Pdf creation is OK though.
> So the "configure.py" apparently does not honour the lyxrc.dist entry
> '\texinputs_prefix ".:/usr/local/share/lyx2.3/tex"'
> but compilation in lyx does (as can be seen in
> Tools->Preferences...->Paths->TEXINPUTS prefix:)
> 
> In fact, the entries in clsFiles.lst are missing now.

This is because TeXFiles.py is called without setting TEXINPUTS.
Moreover, there is also the issue that MikTeX's kpsewhich completely
ignores TEXINPUTS. However, the attached patch works for me on any
platform I have access to and with any TeX engine.

-- 
Enrico
diff --git a/lib/scripts/TeXFiles.py b/lib/scripts/TeXFiles.py
index aac29bc9d0..ab1659f3b0 100755
--- a/lib/scripts/TeXFiles.py
+++ b/lib/scripts/TeXFiles.py
@@ -77,11 +77,24 @@ else:
 # Cygwin, where we could have either teTeX (using `:') or MikTeX (using `;').
 # Create a variable that holds the right character to be used by the scripts.
 path_sep = os.pathsep
+texinputs_sep = path_sep
 if sys.platform == 'cygwin':
 if ';' in cmdOutput('kpsewhich --show-path=.tex'):
 path_sep = ';'
-else:
-path_sep = ':'
+if "TEXINPUTS" in os.environ and ';' in os.environ["TEXINPUTS"]:
+texinputs_sep = ';'
+
+# Account for absolute paths in TEXINPUTS
+texinputs_dirs = list()
+if "TEXINPUTS" in os.environ:
+texinputs_alldirs = os.environ["TEXINPUTS"].split(texinputs_sep)
+for dir in texinputs_alldirs:
+if dir != "":
+texdir = dir
+if sys.platform == 'cygwin' and texinputs_sep == ';':
+texdir = cmdOutput('cygpath "%s"' % dir).strip()
+if os.path.isabs(texdir):
+texinputs_dirs.append(texdir)
 
 # process each file type
 for type in types:
@@ -89,21 +102,27 @@ for type in types:
 if type == 'cls':
 outfile = cls_stylefile
 kpsetype = '.tex'
+extra_dirs = texinputs_dirs
 elif type == 'sty':
 outfile = sty_stylefile
 kpsetype = '.tex'
+extra_dirs = texinputs_dirs
 elif type == 'bst':
 outfile = bst_stylefile
 kpsetype = '.bst'
+extra_dirs = list()
 elif type == 'bib':
 outfile = bib_files
 kpsetype = '.bib'
+extra_dirs = list()
 elif type == 'bbx':
 outfile = bbx_files
 kpsetype = '.tex'
+extra_dirs = list()
 elif type == 'cbx':
 outfile = cbx_files
 kpsetype = '.tex'
+extra_dirs = list()
 
 dirs = cmdOutput('kpsewhich --show-path=' + kpsetype).replace('!!', 
'').strip()
 # remove excessive //
@@ -111,7 +130,7 @@ for type in types:
 
 file_ext = '.' + type
 out = open(outfile, 'w')
-for dir in dirs.split(path_sep):
+for dir in dirs.split(path_sep) + extra_dirs:
 # for each valid directory
 if not os.path.isdir(dir):
 continue
diff --git a/src/frontends/qt4/qt_helpers.cpp b/src/frontends/qt4/qt_helpers.cpp
index 3d3e36819f..6580ad2394 100644
--- a/src/frontends/qt4/qt_helpers.cpp
+++ b/src/frontends/qt4/qt_helpers.cpp
@@ -298,7 +298,9 @@ void rescanTexStyles(string const & arg)
string const command = os::python() + ' ' +
quoteName(prog.toFilesystemEncoding()) + ' ' +
arg;
-   int const status = one.startscript(Systemcall::Wait, command);
+   // Force using TEXINPUTS with "." unchanged.
+   string const curdir = ".";
+   int const status = one.startscript(Systemcall::Wait, command, curdir);
if (status == 0)
return;
// FIXME UNICODE
diff --git a/src/support/Package.cpp b/src/support/Package.cpp
index 75d6e1a2f8..1f7ee674b7 100644
--- a/src/support/Package.cpp
+++ b/src/support/Package.cpp
@@ -169,7 +169,10 @@ int Package::reconfigureUserLyXDir(string const & option) 
const
lyxerr << to_utf8(_("LyX: reconfiguring user directory")) << endl;
PathChanger p(user_support());
Systemcall one;
-   int const ret = one.startscript(Systemcall::Wait, configure_command_ + 
option);
+   // Force using TEXINPUTS with "." unchanged.
+   string const curdir = ".";
+   int const ret = one.startscript(Systemcall::Wait,
+   configure_command_ + option, curdir);
lyxerr << "LyX: " << to_utf8(_("Done!")) << endl;
return ret;
 }


Re: Automatic setting TEXINPUTS environment for lyx provided files

2017-07-12 Thread Kornel Benko
Am Mittwoch, 12. Juli 2017 um 10:08:37, schrieb Kornel Benko 
> > I think this is not a problem. The tex files can be moved to the correct
> > location (which may be different for different platforms) by the packager
> > (this is what Debian does, for example), or lyxrc.dist can be used to
> > augment the TEXINPUTS path.
> 
> Good idea. But until now, there are only 
> "development/(MacOSX|cygwin)/lyxrc.dist.in" present.

I implemented it now in cmake build. At first, everything seemed to work.
Reconfiguring lyx...
Load examples/chessgame.lyx
--> The selected document class Chess requires external files ...
Pdf creation is OK though.
So the "configure.py" apparently does not honour the lyxrc.dist entry 
'\texinputs_prefix ".:/usr/local/share/lyx2.3/tex"'
but compilation in lyx does (as can be seen in 
Tools->Preferences...->Paths->TEXINPUTS prefix:)

In fact, the entries in clsFiles.lst are missing now.

Kornel




signature.asc
Description: This is a digitally signed message part.


Re: Automatic setting TEXINPUTS environment for lyx provided files

2017-07-12 Thread Kornel Benko
Am Dienstag, 11. Juli 2017 um 23:09:34, schrieb Enrico Forestieri 

> On Tue, Jul 11, 2017 at 02:07:51PM +0200, Kornel Benko wrote:
> > Hi,
> > I am struggling on the best install directory for our tex files.
> > ATM, automake installs them for unix at lyx-system-dir/tex.
> > But this dir is not part of the list 'kpsepath tex'.
> > If a new user starts lyx, he/she has either set the environment TEXINPUTS
> > or expand the path in preferences.
> > 
> > Under cmake we add the data to "/usr/(local/)?share/texmf/tex/latex/lyx2.3",
> > but that requires that this directory is used by kpsepath. Which is not the 
> > case
> > if using texlive from CTAN.
> > The situation is not better than the one from automake.
> > 
> > So, from my POV, I'd prefer if lyx be able to add its own path to TEXINPUTS 
> > or
> > set the default in lyxrc.texinputs_prefix from "." to ".:system-dir/tex"
> > 
> > What do others think?
> 
> I think this is not a problem. The tex files can be moved to the correct
> location (which may be different for different platforms) by the packager
> (this is what Debian does, for example), or lyxrc.dist can be used to
> augment the TEXINPUTS path.

Good idea. But until now, there are only 
"development/(MacOSX|cygwin)/lyxrc.dist.in" present.

> So, LyX (with automake, at least) is doing the
> right thing, which is not to second guess where the files should go.

Yes, but only half-hearted.

> Moreover, note that this has not been a problem for decades.
> 

Probably because we say the people how to handle this case?
https://wiki.lyx.org/FAQ/InstallLatexConfigure

I'd like to omit it.

Kornel

signature.asc
Description: This is a digitally signed message part.


Re: Automatic setting TEXINPUTS environment for lyx provided files

2017-07-11 Thread Enrico Forestieri
On Tue, Jul 11, 2017 at 02:07:51PM +0200, Kornel Benko wrote:
> Hi,
> I am struggling on the best install directory for our tex files.
> ATM, automake installs them for unix at lyx-system-dir/tex.
> But this dir is not part of the list 'kpsepath tex'.
> If a new user starts lyx, he/she has either set the environment TEXINPUTS
> or expand the path in preferences.
> 
> Under cmake we add the data to "/usr/(local/)?share/texmf/tex/latex/lyx2.3",
> but that requires that this directory is used by kpsepath. Which is not the 
> case
> if using texlive from CTAN.
> The situation is not better than the one from automake.
> 
> So, from my POV, I'd prefer if lyx be able to add its own path to TEXINPUTS or
> set the default in lyxrc.texinputs_prefix from "." to ".:system-dir/tex"
> 
> What do others think?

I think this is not a problem. The tex files can be moved to the correct
location (which may be different for different platforms) by the packager
(this is what Debian does, for example), or lyxrc.dist can be used to
augment the TEXINPUTS path. So, LyX (with automake, at least) is doing the
right thing, which is not to second guess where the files should go.
Moreover, note that this has not been a problem for decades.

-- 
Enrico