commit e6f6c0bdd3a9ce352c260681cf7e51a0f12a4cad
Author: Juergen Spitzmueller <[email protected]>
Date: Sun May 11 18:16:05 2025 +0200
tex2lyx: find textclass if it differs from LaTeX class name
---
src/LayoutFile.cpp | 14 ++++++++++++++
src/LayoutFile.h | 2 ++
src/tex2lyx/Preamble.cpp | 24 +++++++++++++++++++++---
3 files changed, 37 insertions(+), 3 deletions(-)
diff --git a/src/LayoutFile.cpp b/src/LayoutFile.cpp
index 3ed3676129..f17617f3ca 100644
--- a/src/LayoutFile.cpp
+++ b/src/LayoutFile.cpp
@@ -74,6 +74,20 @@ bool LayoutFileList::haveClass(string const & classname)
const
}
+vector<string> LayoutFileList::getClasses(string const & latexname) const
+{
+ vector<string> res;
+ ClassMap::const_iterator it = classmap_.begin();
+ ClassMap::const_iterator en = classmap_.end();
+ for (; it != en; ++it) {
+ if (it->second->latexname_ == latexname)
+ res.push_back(it->first);
+ }
+ return res;
+}
+
+
+
LayoutFile const & LayoutFileList::operator[](string const & classname) const
{
LATTEST(haveClass(classname));
diff --git a/src/LayoutFile.h b/src/LayoutFile.h
index ad7effdab6..6359bf6299 100644
--- a/src/LayoutFile.h
+++ b/src/LayoutFile.h
@@ -96,6 +96,8 @@ public:
bool empty() const { return classmap_.empty(); }
///
bool haveClass(std::string const & classname) const;
+ ///
+ std::vector<std::string> getClasses(std::string const & latexname)
const;
/// Note that this will assert if we don't have classname, so
/// check via haveClass() first.
LayoutFile const & operator[](std::string const & classname) const;
diff --git a/src/tex2lyx/Preamble.cpp b/src/tex2lyx/Preamble.cpp
index 6252b99ab6..eecf54a055 100644
--- a/src/tex2lyx/Preamble.cpp
+++ b/src/tex2lyx/Preamble.cpp
@@ -838,8 +838,26 @@ void Preamble::setTextClass(string const & tclass,
TeX2LyXDocClass & tc)
h_textclass = tclass;
tc.setName(h_textclass);
if (!LayoutFileList::get().haveClass(h_textclass) || !tc.load()) {
- error_message("Could not read layout file for textclass \"" +
h_textclass + "\".");
- exit(EXIT_FAILURE);
+ // No layout file could be found. Check whether we can find it
via
+ // the latex name
+ vector<string> const tryclass =
LayoutFileList::get().getClasses(h_textclass);
+ if (!tryclass.empty()) {
+ if (tryclass.size() > 1) {
+ warning_message("Several LyX layout files
available for the latex class \"" + h_textclass + "\":");
+ warning_message(getStringFromVector(tryclass));
+ warning_message("Will use \"" +
tryclass.front() + "\".");
+ warning_message("Please use the -c option if
you want a different layout.");
+ }
+ h_textclass = tryclass.front();
+ tc.setName(h_textclass);
+ if (!tc.load()) {
+ error_message("Could not read layout file for
textclass \"" + h_textclass + "\".");
+ exit(EXIT_FAILURE);
+ }
+ } else {
+ error_message("Could not read layout file for textclass
\"" + h_textclass + "\".");
+ exit(EXIT_FAILURE);
+ }
}
}
@@ -3636,7 +3654,7 @@ void Preamble::parse(Parser & p, string const &
forceclass,
}
// set textclass if not yet done (snippets without \documentclass and
forced class)
- if (!class_set)
+ if (!class_set)
setTextClass(h_textclass, tc);
// remove the whitespace
--
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs