Am Freitag, 20. April 2007 11:59 schrieb Ozgur Ugras BARAN:
> If you have a solution, go ahead, since I haven't got one but got an idea
> only :). I just try to act responsible  :)

Good guy :-)

Here are my solutions: config.diff follows the idea suggested by Jean-Marc: 
Test for the nomencl version in chkconfig.ltx and put either "nomencl" 
or "nomencl" and "oldnomencl" to the packages.list file. Then the 
availability of "oldnomencl" is tested to determine the version, define 
the needed commands in the preamble and use the correct invocations of 
makeindex.
The advantage of this solution is that there are no checks in the document. 
The disadvantage is that you need to reconfigure if the nomencl version 
changes.

The other version in doc.diff was almost finished before Jean-Marc made his 
suggestion, so I finished it and present it here, too. It moves the check 
for the version into the document preamble, and simply checks for the 
presence of the .glo file to decide whether makeindex should be run for 
the old version.
The advantage of this solution is that the exported .tex file works with 
both versions. A possible disadvantage is that makeindex could produce 
errors if you use another glossary package that produces a .glo file (did 
not test that).

Which solution should go in? Note that I did not handle the case when 
nomencl is not installed, and I don't intend to do that.


Georg
Index: src/LaTeXFeatures.C
===================================================================
--- src/LaTeXFeatures.C	(Revision 17909)
+++ src/LaTeXFeatures.C	(Arbeitskopie)
@@ -404,8 +404,15 @@ string const LaTeXFeatures::getPackages(
 		packages << "\\usepackage[all]{xy}\n";
 
 	if (mustProvide("nomencl")) {
-		packages << "\\usepackage{nomencl}[2005/09/22]\n"
-			 << "\\makenomenclature\n";
+		// Make it work with the new and old version of the package,
+		// but don't use the compatibilty option since it is
+		// incompatible to other packages.
+		packages << "\\let\\printnomenclature\\relax\n"
+	                    "\\let\\makenomenclature\\relax\n"
+	                    "\\usepackage{nomencl}\n"
+	                    "\\ifx\\printnomenclature\\relax\\let\\printnomenclature\\printglossary\\fi\n"
+	                    "\\ifx\\makenomenclature\\relax\\let\\makenomenclature\\makeglossary\\fi\n"
+		            "\\makenomenclature\n";
 	}
  
 	return packages.str();
Index: src/LaTeX.C
===================================================================
--- src/LaTeX.C	(Revision 17909)
+++ src/LaTeX.C	(Arbeitskopie)
@@ -168,6 +168,10 @@ void LaTeX::deleteFilesOnError() const
 	FileName const nls(changeExtension(file.absFilename(), ".nls"));
 	unlink(nls);
 
+	// nomencl file (old version of the package)
+	FileName const gls(changeExtension(file.absFilename(), ".gls"));
+	unlink(gls);
+
 	// Also remove the aux file
 	FileName const aux(changeExtension(file.absFilename(), ".aux"));
 	unlink(aux);
@@ -300,20 +304,12 @@ int LaTeX::run(TeXErrors & terr)
 		rerun |= runMakeIndex(onlyFilename(idxfile.absFilename()),
 				runparams);
 	}
-	if (head.haschanged(FileName(changeExtension(file.absFilename(), ".nlo")))) {
-		LYXERR(Debug::LATEX) 
-			<< "Running MakeIndex for nomencl."
-			<< endl;
-		message(_("Running MakeIndex for nomencl."));
-		// onlyFilename() is needed for cygwin
-		string const nomenclstr = " -s nomencl.ist -o " 
-			+ onlyFilename(changeExtension(
-				file.toFilesystemEncoding(), ".nls"));
-		rerun |= runMakeIndex(onlyFilename(changeExtension(
-				file.absFilename(), ".nlo")),
-				runparams,
-				nomenclstr);
-	}
+	FileName const nlofile(changeExtension(file.absFilename(), ".nlo"));
+	if (head.haschanged(nlofile))
+		rerun |= runMakeIndexNomencl(file, runparams, ".nlo", ".nls");
+	FileName const glofile(changeExtension(file.absFilename(), ".glo"));
+	if (head.haschanged(glofile))
+		rerun |= runMakeIndexNomencl(file, runparams, ".glo", ".gls");
 
 	// run bibtex
 	// if (scanres & UNDEF_CIT || scanres & RERUN || run_bibtex)
@@ -379,7 +375,7 @@ int LaTeX::run(TeXErrors & terr)
 	// more after this.
 
 	// run makeindex if the <file>.idx has changed or was generated.
-	if (head.haschanged(FileName(changeExtension(file.absFilename(), ".idx")))) {
+	if (head.haschanged(idxfile)) {
 		// no checks for now
 		LYXERR(Debug::LATEX) << "Running MakeIndex." << endl;
 		message(_("Running MakeIndex."));
@@ -389,20 +385,10 @@ int LaTeX::run(TeXErrors & terr)
 	}
 
 	// I am not pretty sure if need this twice.
-	if (head.haschanged(FileName(changeExtension(file.absFilename(), ".nlo")))) {
-		LYXERR(Debug::LATEX) 
-			<< "Running MakeIndex for nomencl."
-			<< endl;
-		message(_("Running MakeIndex for nomencl."));
-		// onlyFilename() is needed for cygwin
-		string nomenclstr = " -s nomencl.ist -o " 
-			+ onlyFilename(changeExtension(
-				file.toFilesystemEncoding(), ".nls"));
-		rerun |= runMakeIndex(onlyFilename(changeExtension(
-				file.absFilename(), ".nlo")),
-				runparams,
-				nomenclstr);
-	}
+	if (head.haschanged(nlofile))
+		rerun |= runMakeIndexNomencl(file, runparams, ".nlo", ".nls");
+	if (head.haschanged(glofile))
+		rerun |= runMakeIndexNomencl(file, runparams, ".glo", ".gls");
 
 	// 2
 	// we will only run latex more if the log file asks for it.
@@ -468,6 +454,21 @@ bool LaTeX::runMakeIndex(string const & 
 }
 
 
+bool LaTeX::runMakeIndexNomencl(FileName const & file,
+		OutputParams const & runparams,
+		string const & nlo, string const & nls)
+{
+	LYXERR(Debug::LATEX) << "Running MakeIndex for nomencl." << endl;
+	message(_("Running MakeIndex for nomencl."));
+	// onlyFilename() is needed for cygwin
+	string const nomenclstr = " -s nomencl.ist -o "
+		+ onlyFilename(changeExtension(file.toFilesystemEncoding(), nls));
+	return runMakeIndex(
+			onlyFilename(changeExtension(file.absFilename(), nlo)),
+			runparams, nomenclstr);
+}
+
+
 vector<Aux_Info> const
 LaTeX::scanAuxFiles(FileName const & file)
 {
@@ -862,7 +863,9 @@ bool handleFoundFile(string const & ff, 
 	//     insert it into head
 	if (exists(absname) &&
 	    !fs::is_directory(absname.toFilesystemEncoding())) {
-		static regex unwanted("^.*\\.(aux|log|dvi|bbl|ind|glo)$");
+		// FIXME: This regex contained glo, but glo is used by the old
+		// version of nomencl.sty. Do we need to put it back?
+		static regex unwanted("^.*\\.(aux|log|dvi|bbl|ind)$");
 		if (regex_match(onlyfile, unwanted)) {
 			LYXERR(Debug::DEPEND)
 				<< "We don't want "
@@ -927,6 +930,7 @@ void LaTeX::deplog(DepTable & head)
 	static regex reg4("Writing index file (.+).*");
 	// files also can be enclosed in <...>
 	static regex reg5("<([^>]+)(.).*");
+	static regex regoldnomencl("Writing glossary file (.+).*");
 	static regex regnomencl("Writing nomenclature file (.+).*");
 	// If a toc should be created, MikTex does not write a line like
 	//    \openout# = `sample.toc'.
@@ -1030,7 +1034,8 @@ void LaTeX::deplog(DepTable & head)
 				// probable line break
 				found_file = false;
 		// (6) "Writing nomenclature file file.ext"
-		} else if (regex_match(token, sub, regnomencl))
+		} else if (regex_match(token, sub, regnomencl) ||
+		           regex_match(token, sub, regoldnomencl))
 			// check for dot
 			found_file = checkLineBreak(sub.str(1), head);
 		// (7) "[EMAIL PROTECTED]<nr>" (for MikTeX)
Index: src/LaTeX.h
===================================================================
--- src/LaTeX.h	(Revision 17909)
+++ src/LaTeX.h	(Arbeitskopie)
@@ -172,6 +172,10 @@ private:
 	                  std::string const & = std::string());
 
 	///
+	bool runMakeIndexNomencl(support::FileName const &, OutputParams const &,
+	                         std::string const &, std::string const &);
+
+	///
 	std::vector<Aux_Info> const scanAuxFiles(support::FileName const &);
 
 	///
Index: src/LaTeXFeatures.C
===================================================================
--- src/LaTeXFeatures.C	(Revision 17909)
+++ src/LaTeXFeatures.C	(Arbeitskopie)
@@ -404,8 +404,16 @@ string const LaTeXFeatures::getPackages(
 		packages << "\\usepackage[all]{xy}\n";
 
 	if (mustProvide("nomencl")) {
-		packages << "\\usepackage{nomencl}[2005/09/22]\n"
-			 << "\\makenomenclature\n";
+		if (isAvailable("oldnomencl"))
+			// Old version of the package - we need to define the
+			// new commands since we use the new interface
+			packages << "\\usepackage{nomencl}\n"
+		                    "\\let\\printnomenclature\\printglossary\n"
+			            "\\makeglossary\n";
+		else
+			// New version or not installed
+			packages << "\\usepackage{nomencl}\n"
+			            "\\makenomenclature\n";
 	}
  
 	return packages.str();
Index: src/LaTeX.C
===================================================================
--- src/LaTeX.C	(Revision 17909)
+++ src/LaTeX.C	(Arbeitskopie)
@@ -17,6 +17,7 @@
 
 #include "bufferlist.h"
 #include "LaTeX.h"
+#include "LaTeXFeatures.h"
 #include "gettext.h"
 #include "lyxrc.h"
 #include "debug.h"
@@ -165,7 +166,8 @@ void LaTeX::deleteFilesOnError() const
 	unlink(ind);
 
 	// nomencl file
-	FileName const nls(changeExtension(file.absFilename(), ".nls"));
+	string const ext = LaTeXFeatures::isAvailable("oldnomencl") ? ".gls" : ".nls";
+	FileName const nls(changeExtension(file.absFilename(), ext));
 	unlink(nls);
 
 	// Also remove the aux file
@@ -300,7 +302,11 @@ int LaTeX::run(TeXErrors & terr)
 		rerun |= runMakeIndex(onlyFilename(idxfile.absFilename()),
 				runparams);
 	}
-	if (head.haschanged(FileName(changeExtension(file.absFilename(), ".nlo")))) {
+	bool const oldnomencl = LaTeXFeatures::isAvailable("oldnomencl");
+	string const nlo = oldnomencl ? ".glo" : ".nlo";
+	string const nls = oldnomencl ? ".gls" : ".nls";
+	FileName const nlofile(changeExtension(file.absFilename(), nlo));
+	if (head.haschanged(nlofile)) {
 		LYXERR(Debug::LATEX) 
 			<< "Running MakeIndex for nomencl."
 			<< endl;
@@ -308,9 +314,9 @@ int LaTeX::run(TeXErrors & terr)
 		// onlyFilename() is needed for cygwin
 		string const nomenclstr = " -s nomencl.ist -o " 
 			+ onlyFilename(changeExtension(
-				file.toFilesystemEncoding(), ".nls"));
+				file.toFilesystemEncoding(), nls));
 		rerun |= runMakeIndex(onlyFilename(changeExtension(
-				file.absFilename(), ".nlo")),
+				file.absFilename(), nlo)),
 				runparams,
 				nomenclstr);
 	}
@@ -379,7 +385,7 @@ int LaTeX::run(TeXErrors & terr)
 	// more after this.
 
 	// run makeindex if the <file>.idx has changed or was generated.
-	if (head.haschanged(FileName(changeExtension(file.absFilename(), ".idx")))) {
+	if (head.haschanged(idxfile)) {
 		// no checks for now
 		LYXERR(Debug::LATEX) << "Running MakeIndex." << endl;
 		message(_("Running MakeIndex."));
@@ -389,7 +395,7 @@ int LaTeX::run(TeXErrors & terr)
 	}
 
 	// I am not pretty sure if need this twice.
-	if (head.haschanged(FileName(changeExtension(file.absFilename(), ".nlo")))) {
+	if (head.haschanged(nlofile)) {
 		LYXERR(Debug::LATEX) 
 			<< "Running MakeIndex for nomencl."
 			<< endl;
@@ -397,9 +403,9 @@ int LaTeX::run(TeXErrors & terr)
 		// onlyFilename() is needed for cygwin
 		string nomenclstr = " -s nomencl.ist -o " 
 			+ onlyFilename(changeExtension(
-				file.toFilesystemEncoding(), ".nls"));
+				file.toFilesystemEncoding(), nls));
 		rerun |= runMakeIndex(onlyFilename(changeExtension(
-				file.absFilename(), ".nlo")),
+				file.absFilename(), nlo)),
 				runparams,
 				nomenclstr);
 	}
@@ -862,7 +868,9 @@ bool handleFoundFile(string const & ff, 
 	//     insert it into head
 	if (exists(absname) &&
 	    !fs::is_directory(absname.toFilesystemEncoding())) {
-		static regex unwanted("^.*\\.(aux|log|dvi|bbl|ind|glo)$");
+		// FIXME: This regex contained glo, but glo is used by the old
+		// version of nomencl.sty. Do we need to put it back?
+		static regex unwanted("^.*\\.(aux|log|dvi|bbl|ind)$");
 		if (regex_match(onlyfile, unwanted)) {
 			LYXERR(Debug::DEPEND)
 				<< "We don't want "
@@ -928,6 +936,8 @@ void LaTeX::deplog(DepTable & head)
 	// files also can be enclosed in <...>
 	static regex reg5("<([^>]+)(.).*");
 	static regex regnomencl("Writing nomenclature file (.+).*");
+	static regex regoldnomencl("Writing glossary file (.+).*");
+	bool const oldnomencl = LaTeXFeatures::isAvailable("oldnomencl");
 	// If a toc should be created, MikTex does not write a line like
 	//    \openout# = `sample.toc'.
 	// but only a line like this into the log:
@@ -1030,7 +1040,8 @@ void LaTeX::deplog(DepTable & head)
 				// probable line break
 				found_file = false;
 		// (6) "Writing nomenclature file file.ext"
-		} else if (regex_match(token, sub, regnomencl))
+		} else if (regex_match(token, sub,
+		                       oldnomencl ? regoldnomencl : regnomencl))
 			// check for dot
 			found_file = checkLineBreak(sub.str(1), head);
 		// (7) "[EMAIL PROTECTED]<nr>" (for MikTeX)
Index: lib/chkconfig.ltx
===================================================================
--- lib/chkconfig.ltx	(Revision 17909)
+++ lib/chkconfig.ltx	(Arbeitskopie)
@@ -95,6 +95,23 @@
 \newcommand{\TestPackage}[2][\default]{
   \TestItem[#1]{#2}{package}{sty}{\AddPackage{#2}}{}}
 
+% Add the nomencl package. This is a bit tricky since we need to know whether
+% we are using the old or new version.
+\newcommand{\AddNomencl}{
+  \let\printglossary\relax
+  % \usepackage does not work without \documentclass.
+  \documentclass{article}
+  % We can use \usepackage since this code is only called if nomencl.sty
+  % is available
+  \usepackage{nomencl}
+  \ifx\printglossary\relax
+    \AddPackage{nomencl}
+  \else
+    \AddPackage{nomencl}
+    \AddPackage{oldnomencl}
+  \fi
+}
+
 \newcommand{\TestDocClass}[2]{
    \def\layoutname{#1}  % remember the name of the layout file
    [EMAIL PROTECTED]@#1}
@@ -237,7 +254,9 @@
 \TestPackage{latex8}
 \TestPackage{longtable}
 \TestPackage{natbib}
-\TestPackage{nomencl}
+%\TestPackage{nomencl}
+%\TestNomencl
+\TestItem{nomencl}{package}{sty}{\AddNomencl}{}
 \TestPackage{prettyref}
 \TestPackage{preview}
 \TestPackage{rotating}

Reply via email to