]> git.lyx.org Git - lyx.git/commitdiff
Add support for multiple indexes in Memoir
authorJuergen Spitzmueller <spitz@lyx.org>
Fri, 26 Jul 2024 10:48:12 +0000 (12:48 +0200)
committerJuergen Spitzmueller <spitz@lyx.org>
Fri, 26 Jul 2024 10:48:12 +0000 (12:48 +0200)
As with almost everything, this class bakes its own cake also with
multiple indexes. So we need to account for this to produce
compilable output.

Not very nice, but there you go!

lib/layouts/memoir.layout
src/Buffer.cpp
src/BufferParams.cpp
src/Converter.cpp
src/LaTeX.cpp
src/LaTeX.h
src/LaTeXFeatures.cpp
src/OutputParams.h
src/insets/InsetIndex.cpp

index 61184d2398aea4cec5255841541354b07082f5df..89f0da70db76c1f803952a59069c7509df8fbc2d 100644 (file)
@@ -18,6 +18,8 @@ PageSize           letter
 Provides makeidx   1
 Provides framed    1
 Provides subscript 1
+# Memoir has its own implementation
+Provides memoir-idx 1
 # Geometry is supported, but the package options and paper sizes
 # are ignored
 Provides geometry-light  1
index a13c8e5f9f9443a06ce3f757527a15f5ac53745a..efa6492863a31ee618730d3e524a84462d9882ff 100644 (file)
@@ -1886,6 +1886,7 @@ Buffer::ExportStatus Buffer::writeLaTeXSource(otexstream & os,
                runparams.use_hyperref = features.isRequired("hyperref")
                                || features.isProvided("hyperref");
                runparams.use_CJK = features.mustProvide("CJK");
+               runparams.use_memindex = features.isProvided("memoir-idx");
        }
        LYXERR(Debug::OUTFILE, "  Buffer validation done.");
 
@@ -4220,6 +4221,7 @@ unique_ptr<TexRow> Buffer::getSourceCode(odocstream & os, string const & format,
                        runparams.use_babel = features.useBabel();
                        runparams.use_hyperref = features.isRequired("hyperref")
                                || features.isProvided("hyperref");
+                       runparams.use_memindex = features.isProvided("memoir-idx");
                        // latex or literate
                        otexstream ots(os);
                        // output above
index a5215f6fc85ef874e870836b3d34e14e13f2cd1e..0a01f9bb4f0bbd5e8047473bc8006d7e7e0c6310 100644 (file)
@@ -2279,9 +2279,17 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features,
        // Additional Indices
        if (features.isRequired("splitidx")) {
                for (auto const & idx : indiceslist()) {
-                       os << "\\newindex{";
+                       if (features.isProvided("memoir-idx")) {
+                               if (idx.shortcut() == "idx")
+                                       continue;
+                               os << "\\makeindex[";
+                       } else
+                               os << "\\newindex{";
                        os << escape(idx.shortcut());
-                       os << "}\n";
+                       if (features.isProvided("memoir-idx"))
+                               os << "]\n";
+                       else
+                               os << "}\n";
                }
        }
 
index 881aac6bd394ef243ac92f0af098cccc17709387..21c193839898dc3d6f31d3c17c6b516b08dac052 100644 (file)
@@ -21,6 +21,7 @@
 #include "Format.h"
 #include "InsetList.h"
 #include "Language.h"
+#include "LaTeXFeatures.h"
 #include "LaTeX.h"
 #include "LyXRC.h"
 #include "Mover.h"
@@ -555,6 +556,15 @@ Converters::RetVal Converters::convert(Buffer const * buffer,
                                                   "tmpfile.out"));
                }
 
+               if (buffer && buffer->params().use_indices && conv.latex()) {
+                       // We need to validate the buffer to get access to features.
+                       // FIXME Not nice that we need to do this here.
+                       LYXERR(Debug::OUTFILE, "  Validating buffer...");
+                       LaTeXFeatures features(*buffer, buffer->params(), runparams);
+                       buffer->validate(features);
+                       runparams.use_memindex = features.isProvided("memoir-idx");
+               }
+
                if (buffer && buffer->params().use_minted
                    && lyxrc.pygmentize_command.empty() && conv.latex()) {
                        bool dowarn = false;
index 84141d83416d0f040440a86878f17ac908bf1cdd..afc3eb5c32825dd46dce891cb628263a8b5c57f6 100644 (file)
@@ -20,6 +20,7 @@
 #include "Buffer.h"
 #include "BufferList.h"
 #include "BufferParams.h"
+#include "IndicesList.h"
 #include "LyXRC.h"
 #include "LyX.h"
 #include "DepTable.h"
@@ -466,6 +467,41 @@ int LaTeX::run(TeXErrors & terr)
                        iscanres = scanIlgFile(terr);
                rerun = true;
        }
+       // This is Memoir's multi-index idiosyncracy
+       if (runparams.use_indices && runparams.use_memindex) {
+               Buffer const * buf = theBufferList().getBufferFromTmp(file.absFileName());
+               if (buf) {
+                       IndicesList const & indiceslist = buf->params().indiceslist();
+                       if (!indiceslist.empty()) {
+                               IndicesList::const_iterator it = indiceslist.begin();
+                               IndicesList::const_iterator const end = indiceslist.end();
+                               for (; it != end; ++it) {
+                                       docstring const & ci = it->shortcut();
+                                       if (ci == "idx")
+                                               continue;
+                                       FileName const aidxfile(to_utf8(ci + ".idx"));
+                                       LYXERR(Debug::OUTFILE, "Running Index Processor for " << ci);
+                                       message(_("Running Index Processor."));
+                                       // onlyFileName() is needed for cygwin
+                                       int const ret = 
+                                                       runMakeIndex(onlyFileName(aidxfile.absFileName()), runparams);
+                                       if (ret == Systemcall::KILLED || ret == Systemcall::TIMEOUT)
+                                               return ret;
+                                       else if (ret != Systemcall::OK) {
+                                               iscanres |= INDEX_ERROR;
+                                               terr.insertError(0,
+                                                                _("Index Processor Error"),
+                                                                _("The index processor did not run successfully. "
+                                                                  "Please check the output of View > Messages Pane!"));
+                                       }
+                                       FileName const ailgfile(changeExtension(aidxfile.absFileName(), ".ilg"));
+                                       if (ailgfile.exists())
+                                               iscanres = scanIlgFile(terr, ailgfile);
+                                       rerun = true;
+                               }
+                       }
+               }
+       }
        if (run_nomencl) {
                int const ret = runMakeIndexNomencl(file, ".nlo", ".nls");
                if (ret == Systemcall::KILLED || ret == Systemcall::TIMEOUT)
@@ -592,7 +628,7 @@ int LaTeX::runMakeIndex(string const & f, OutputParams const & rp,
                tmp = subst(tmp, "$$lang", doc_lang->babel());
                tmp = subst(tmp, "$$lcode", doc_lang->code());
        }
-       if (rp.use_indices) {
+       if (rp.use_indices && !rp.use_memindex) {
                tmp = lyxrc.splitindex_command + " -m " + quoteName(tmp);
                LYXERR(Debug::OUTFILE,
                "Multiple indices. Using splitindex command: " << tmp);
@@ -1640,9 +1676,11 @@ int LaTeX::scanBlgFile(DepTable & dep, TeXErrors & terr)
 }
 
 
-int LaTeX::scanIlgFile(TeXErrors & terr)
+int LaTeX::scanIlgFile(TeXErrors & terr, FileName const fn)
 {
-       FileName const ilg_file(changeExtension(file.absFileName(), "ilg"));
+       FileName const ilg_file = fn.empty()
+                       ? FileName(changeExtension(file.absFileName(), "ilg"))
+                       : fn;
        LYXERR(Debug::OUTFILE, "Scanning ilg file: " << ilg_file);
 
        ifstream ifs(ilg_file.toFilesystemEncoding().c_str());
index 569114d369899f6072ae02b0b5528178a0b6988c..502834348b94f67ade297bb7dd9d264be0ec1b1e 100644 (file)
@@ -230,7 +230,7 @@ private:
        int scanBlgFile(DepTable & head, TeXErrors & terr);
 
        ///
-       int scanIlgFile(TeXErrors & terr);
+       int scanIlgFile(TeXErrors & terr, support::FileName const fn = support::FileName());
 
        ///
        bool runBibTeX(std::vector<AuxInfo> const &,
index 74941459e60faca3b1fb943937d70f8438076e8c..81022cad01b1060b346de92e0cb3340081ecb819 100644 (file)
@@ -1360,7 +1360,7 @@ string const LaTeXFeatures::getPackages() const
        if (isRequired("makeidx") || isRequired("splitidx")) {
                if (!isProvided("makeidx") && !isRequired("splitidx"))
                        packages << "\\usepackage{makeidx}\n";
-               if (mustProvide("splitidx"))
+               if (mustProvide("splitidx") && !isProvided("memoir-idx"))
                        packages << "\\usepackage{splitidx}\n";
                packages << "\\makeindex\n";
        }
index 671bc23892bb5588b7816823bcdb9331d9e5fcf4..306087dfdfaa8264959a69e4397ae0a1e8abcc1c 100644 (file)
@@ -223,6 +223,11 @@ public:
        */
        bool use_indices = false;
 
+       /** Are we using the memoir way to
+        *  to multiple indices?
+       */
+       bool use_memindex = false;
+
        /** Are we using japanese (pLaTeX)?
        */
        bool use_japanese = false;
index 4a4c036a99414e90e1c4bdd85596acada149a42c..81870f8282a6c63d4abd5b165da082c8d35d8f64 100644 (file)
@@ -142,7 +142,10 @@ void InsetIndex::latex(otexstream & ios, OutputParams const & runparams_in) cons
 
        if (buffer().masterBuffer()->params().use_indices && !params_.index.empty()
                && params_.index != "idx") {
-               os << "\\sindex[";
+               if (runparams.use_memindex)
+                       os << "\\index[";
+               else
+                       os << "\\sindex[";
                os << escape(params_.index);
                os << "]{";
        } else {
@@ -1406,7 +1409,17 @@ void InsetPrintIndex::latex(otexstream & os, OutputParams const & runparams_in)
                return;
        }
        OutputParams runparams = runparams_in;
-       os << getCommand(runparams);
+       if (runparams.use_memindex) {
+               if (getParam("type") == from_ascii("idx"))
+                       os << "\\printindex" << termcmd;
+               else {
+                       os << "\\begingroup" << breakln;
+                       os << "\\renewcommand{\\indexname}{" << getParam("name") << "}" << breakln;
+                       os << "\\printindex[" << getParam("type") << "]" << breakln;
+                       os << "\\endgroup" << breakln;
+               }
+       } else
+               os << getCommand(runparams);
 }