commit 96e7fcd4e0c600c3dd99e901ff84ff1480167cf8
Author: Jean-Marc Lasgouttes <[email protected]>
Date: Mon Jul 18 00:50:33 2022 +0200
When pasting as LaTeX, honor textclass and modules
There are several small parts that are needed here:
* Implement LayoutModuleList::asString() that returns a comma-separated
list of modules.
* in Converter::convert(), handle the new tokens $$c for the current
textclass and $$m for the list of modules.
* in Buffer::importFile(), pass the current buffer as parameter instead
of nullptr.
* in pasteClipboardText(), copy the parameters of the current buffer to
the internal one used for importation, so that the textclass and
modules information is available to convert().
* finally, modify configure.py to pass "-c $$c -m $$m" to tex2lyx for
the latexclipoard->lyx converter.
Fixes bug #11312.
---
lib/configure.py | 2 +-
src/Buffer.cpp | 2 +-
src/Converter.cpp | 15 +++++++++++++--
src/CutAndPaste.cpp | 1 +
src/LayoutModuleList.cpp | 12 ++++++++++++
src/LayoutModuleList.h | 2 ++
6 files changed, 30 insertions(+), 4 deletions(-)
diff --git a/lib/configure.py b/lib/configure.py
index f81aa3a..132141d 100644
--- a/lib/configure.py
+++ b/lib/configure.py
@@ -901,7 +901,7 @@ def checkConverterEntries():
path, t2l = checkProg('a LaTeX/Noweb -> LyX converter',
[quoteIfSpace(in_binary_subdir), quoteIfSpace(in_binary_subdir +
version_suffix), quoteIfSpace(in_binary_dir), quoteIfSpace(in_binary_dir +
version_suffix), 'tex2lyx' + version_suffix, 'tex2lyx'],
rc_entry = [r'''\converter latex lyx "%% -f $$i $$o"
""
-\converter latexclipboard lyx "%% -fixedenc utf8 -f $$i $$o" ""
+\converter latexclipboard lyx "%% -fixedenc utf8 -c $$c -m $$m -f $$i
$$o" ""
\converter literate lyx "%% -n -m noweb -f $$i $$o" ""
\converter sweave lyx "%% -n -m sweave -f $$i $$o" ""
\converter knitr lyx "%% -n -m knitr -f $$i $$o" ""'''],
not_found = 'tex2lyx')
diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index 1867e75..96005b9 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -1145,7 +1145,7 @@ bool Buffer::importFile(string const & format, FileName
const & name, ErrorList
FileName const lyx = tempFileName("Buffer_importFileXXXXXX.lyx");
Converters::RetVal const retval =
- theConverters().convert(nullptr, name, lyx, name, format,
"lyx", errorList);
+ theConverters().convert(this, name, lyx, name, format, "lyx",
errorList);
if (retval == Converters::SUCCESS) {
bool const success = readFile(lyx) == ReadSuccess;
removeTempFile(lyx);
diff --git a/src/Converter.cpp b/src/Converter.cpp
index 7bb998d..172b2a2 100644
--- a/src/Converter.cpp
+++ b/src/Converter.cpp
@@ -15,6 +15,7 @@
#include "Buffer.h"
#include "BufferParams.h"
#include "ConverterCache.h"
+#include "TextClass.h"
#include "Encoding.h"
#include "ErrorList.h"
#include "Format.h"
@@ -58,6 +59,8 @@ string const token_to("$$o");
string const token_path("$$p");
string const token_orig_path("$$r");
string const token_orig_from("$$f");
+string const token_textclass("$$c");
+string const token_modules("$$m");
string const token_encoding("$$e");
string const token_latex_encoding("$$E");
string const token_python("$${python}");
@@ -472,7 +475,7 @@ Converters::RetVal Converters::convert(Buffer const *
buffer,
return FAILURE;
}
- // buffer is only invalid for importing, and then runparams is not
+ // buffer can only be null for importing, and then runparams is not
// used anyway.
OutputParams runparams(buffer ? &buffer->params().encoding() : nullptr);
runparams.flavor = getFlavor(edgepath, buffer);
@@ -649,7 +652,15 @@ Converters::RetVal Converters::convert(Buffer const *
buffer,
command = subst(command, token_path,
quoteName(onlyPath(infile.absFileName())));
command = subst(command, token_orig_path,
quoteName(onlyPath(orig_from.absFileName())));
command = subst(command, token_orig_from,
quoteName(onlyFileName(orig_from.absFileName())));
- command = subst(command, token_encoding, buffer ?
buffer->params().encoding().iconvName() : string());
+ command = subst(command, token_textclass,
+ buffer ?
quoteName(buffer->params().documentClass().name())
+ : string());
+ command = subst(command, token_modules,
+ buffer ?
quoteName(buffer->params().getModules().asString())
+ : string());
+ command = subst(command, token_encoding,
+ buffer ?
quoteName(buffer->params().encoding().iconvName())
+ : string());
command = subst(command, token_python, os::python());
if (!conv.parselog().empty())
diff --git a/src/CutAndPaste.cpp b/src/CutAndPaste.cpp
index f79d4ac..f127f1b 100644
--- a/src/CutAndPaste.cpp
+++ b/src/CutAndPaste.cpp
@@ -1299,6 +1299,7 @@ bool pasteClipboardText(Cursor & cur, ErrorList &
errorList, bool asParagraphs,
Buffer buffer(string(), false);
buffer.setInternal(true);
buffer.setUnnamed(true);
+ buffer.params() = cur.buffer()->params();
available = buffer.importString(names[i], text,
errorList);
if (available)
available =
!buffer.paragraphs().empty();
diff --git a/src/LayoutModuleList.cpp b/src/LayoutModuleList.cpp
index b2e9067..de1324c 100644
--- a/src/LayoutModuleList.cpp
+++ b/src/LayoutModuleList.cpp
@@ -53,6 +53,18 @@ bool LayoutModuleList::adaptToBaseClass(LayoutFile const *
const lay,
}
+string LayoutModuleList::asString() const
+{
+ string mods;
+ for (auto const & mod : lml_)
+ mods += mod + ',';
+ // remove trailing comma
+ if (!mods.empty())
+ mods.pop_back();
+ return mods;
+}
+
+
bool LayoutModuleList::moduleCanBeAdded(string const & modName,
LayoutFile const * const lay) const
{
diff --git a/src/LayoutModuleList.h b/src/LayoutModuleList.h
index 6018029..babd760 100644
--- a/src/LayoutModuleList.h
+++ b/src/LayoutModuleList.h
@@ -55,6 +55,8 @@ public:
/// This is needed in GuiDocument. It seems better than an
/// implicit conversion.
std::list<std::string> const & list() const { return lml_; }
+ /// List of modules as a comma-separated string
+ std::string asString() const;
/// Checks to make sure module's requriements are satisfied, that it
does
/// not conflict with already-present modules, isn't already loaded,
etc.
bool moduleCanBeAdded(std::string const & modName,
--
lyx-cvs mailing list
[email protected]
http://lists.lyx.org/mailman/listinfo/lyx-cvs