Add support for multiple indexes in Memoir

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!
This commit is contained in:
Juergen Spitzmueller 2024-07-26 12:48:12 +02:00
parent fe1a3b57df
commit d4f58c96b5
9 changed files with 87 additions and 9 deletions

View File

@ -18,6 +18,8 @@ PageSize letter
Provides makeidx 1 Provides makeidx 1
Provides framed 1 Provides framed 1
Provides subscript 1 Provides subscript 1
# Memoir has its own implementation
Provides memoir-idx 1
# Geometry is supported, but the package options and paper sizes # Geometry is supported, but the package options and paper sizes
# are ignored # are ignored
Provides geometry-light 1 Provides geometry-light 1

View File

@ -1886,6 +1886,7 @@ Buffer::ExportStatus Buffer::writeLaTeXSource(otexstream & os,
runparams.use_hyperref = features.isRequired("hyperref") runparams.use_hyperref = features.isRequired("hyperref")
|| features.isProvided("hyperref"); || features.isProvided("hyperref");
runparams.use_CJK = features.mustProvide("CJK"); runparams.use_CJK = features.mustProvide("CJK");
runparams.use_memindex = features.isProvided("memoir-idx");
} }
LYXERR(Debug::OUTFILE, " Buffer validation done."); 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_babel = features.useBabel();
runparams.use_hyperref = features.isRequired("hyperref") runparams.use_hyperref = features.isRequired("hyperref")
|| features.isProvided("hyperref"); || features.isProvided("hyperref");
runparams.use_memindex = features.isProvided("memoir-idx");
// latex or literate // latex or literate
otexstream ots(os); otexstream ots(os);
// output above // output above

View File

@ -2279,8 +2279,16 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features,
// Additional Indices // Additional Indices
if (features.isRequired("splitidx")) { if (features.isRequired("splitidx")) {
for (auto const & idx : indiceslist()) { for (auto const & idx : indiceslist()) {
if (features.isProvided("memoir-idx")) {
if (idx.shortcut() == "idx")
continue;
os << "\\makeindex[";
} else
os << "\\newindex{"; os << "\\newindex{";
os << escape(idx.shortcut()); os << escape(idx.shortcut());
if (features.isProvided("memoir-idx"))
os << "]\n";
else
os << "}\n"; os << "}\n";
} }
} }

View File

@ -21,6 +21,7 @@
#include "Format.h" #include "Format.h"
#include "InsetList.h" #include "InsetList.h"
#include "Language.h" #include "Language.h"
#include "LaTeXFeatures.h"
#include "LaTeX.h" #include "LaTeX.h"
#include "LyXRC.h" #include "LyXRC.h"
#include "Mover.h" #include "Mover.h"
@ -555,6 +556,15 @@ Converters::RetVal Converters::convert(Buffer const * buffer,
"tmpfile.out")); "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 if (buffer && buffer->params().use_minted
&& lyxrc.pygmentize_command.empty() && conv.latex()) { && lyxrc.pygmentize_command.empty() && conv.latex()) {
bool dowarn = false; bool dowarn = false;

View File

@ -20,6 +20,7 @@
#include "Buffer.h" #include "Buffer.h"
#include "BufferList.h" #include "BufferList.h"
#include "BufferParams.h" #include "BufferParams.h"
#include "IndicesList.h"
#include "LyXRC.h" #include "LyXRC.h"
#include "LyX.h" #include "LyX.h"
#include "DepTable.h" #include "DepTable.h"
@ -466,6 +467,41 @@ int LaTeX::run(TeXErrors & terr)
iscanres = scanIlgFile(terr); iscanres = scanIlgFile(terr);
rerun = true; 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) { if (run_nomencl) {
int const ret = runMakeIndexNomencl(file, ".nlo", ".nls"); int const ret = runMakeIndexNomencl(file, ".nlo", ".nls");
if (ret == Systemcall::KILLED || ret == Systemcall::TIMEOUT) 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, "$$lang", doc_lang->babel());
tmp = subst(tmp, "$$lcode", doc_lang->code()); 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); tmp = lyxrc.splitindex_command + " -m " + quoteName(tmp);
LYXERR(Debug::OUTFILE, LYXERR(Debug::OUTFILE,
"Multiple indices. Using splitindex command: " << tmp); "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); LYXERR(Debug::OUTFILE, "Scanning ilg file: " << ilg_file);
ifstream ifs(ilg_file.toFilesystemEncoding().c_str()); ifstream ifs(ilg_file.toFilesystemEncoding().c_str());

View File

@ -230,7 +230,7 @@ private:
int scanBlgFile(DepTable & head, TeXErrors & terr); 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 &, bool runBibTeX(std::vector<AuxInfo> const &,

View File

@ -1360,7 +1360,7 @@ string const LaTeXFeatures::getPackages() const
if (isRequired("makeidx") || isRequired("splitidx")) { if (isRequired("makeidx") || isRequired("splitidx")) {
if (!isProvided("makeidx") && !isRequired("splitidx")) if (!isProvided("makeidx") && !isRequired("splitidx"))
packages << "\\usepackage{makeidx}\n"; packages << "\\usepackage{makeidx}\n";
if (mustProvide("splitidx")) if (mustProvide("splitidx") && !isProvided("memoir-idx"))
packages << "\\usepackage{splitidx}\n"; packages << "\\usepackage{splitidx}\n";
packages << "\\makeindex\n"; packages << "\\makeindex\n";
} }

View File

@ -223,6 +223,11 @@ public:
*/ */
bool use_indices = false; bool use_indices = false;
/** Are we using the memoir way to
* to multiple indices?
*/
bool use_memindex = false;
/** Are we using japanese (pLaTeX)? /** Are we using japanese (pLaTeX)?
*/ */
bool use_japanese = false; bool use_japanese = false;

View File

@ -142,6 +142,9 @@ void InsetIndex::latex(otexstream & ios, OutputParams const & runparams_in) cons
if (buffer().masterBuffer()->params().use_indices && !params_.index.empty() if (buffer().masterBuffer()->params().use_indices && !params_.index.empty()
&& params_.index != "idx") { && params_.index != "idx") {
if (runparams.use_memindex)
os << "\\index[";
else
os << "\\sindex["; os << "\\sindex[";
os << escape(params_.index); os << escape(params_.index);
os << "]{"; os << "]{";
@ -1406,6 +1409,16 @@ void InsetPrintIndex::latex(otexstream & os, OutputParams const & runparams_in)
return; return;
} }
OutputParams runparams = runparams_in; OutputParams runparams = runparams_in;
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); os << getCommand(runparams);
} }