From 477a4da1a248c84fad4ebe61df27d16711cafe1a Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Mon, 23 Apr 2007 18:33:36 +0000 Subject: [PATCH] make the nomencl inset work with older versions of nomencl.sty * src/LaTeXFeatures.C (LaTeXFeatures::getPackages): Do not require newest nomencl.sty, output compatibility code instead * src/LaTeX.C (LaTeX::deleteFilesOnError): delete .gls file (LaTeX::run): Check .glo and .gls files, too (handleFoundFile): do not ignore .glo files (LaTeX::deplog): add regex for old nomencl version * src/LaTeX.[Ch] (LaTeX::runMakeIndexNomencl) new method, factored out to avoid code duplication git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@17923 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/LaTeX.C | 67 ++++++++++++++++++++++++--------------------- src/LaTeX.h | 4 +++ src/LaTeXFeatures.C | 10 +++++-- 3 files changed, 48 insertions(+), 33 deletions(-) diff --git a/src/LaTeX.C b/src/LaTeX.C index ab6c953983..29a7d6b2db 100644 --- a/src/LaTeX.C +++ b/src/LaTeX.C @@ -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 .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 & f, OutputParams const & runparams, } +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 const LaTeX::scanAuxFiles(FileName const & file) { @@ -862,7 +863,9 @@ bool handleFoundFile(string const & ff, DepTable & head) // 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) "\tf@toc=\write" (for MikTeX) diff --git a/src/LaTeX.h b/src/LaTeX.h index bc310ec1db..821aa0f5b8 100644 --- a/src/LaTeX.h +++ b/src/LaTeX.h @@ -171,6 +171,10 @@ private: bool runMakeIndex(std::string const &, OutputParams const &, std::string const & = std::string()); + /// + bool runMakeIndexNomencl(support::FileName const &, OutputParams const &, + std::string const &, std::string const &); + /// std::vector const scanAuxFiles(support::FileName const &); diff --git a/src/LaTeXFeatures.C b/src/LaTeXFeatures.C index 185ac193a4..8736b111c5 100644 --- a/src/LaTeXFeatures.C +++ b/src/LaTeXFeatures.C @@ -404,8 +404,14 @@ string const LaTeXFeatures::getPackages() const 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 compatibility option since it is + // incompatible to other packages. + packages << "\\usepackage{nomencl}\n" + "% the following is useful when we have the old nomencl.sty package\n" + "\\providecommand{\\printnomenclature}{\\printglossary}\n" + "\\providecommand{\\makenomenclature}{\\makeglossary}\n" + "\\makenomenclature\n"; } return packages.str();