mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-26 03:11:59 +00:00
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.
This commit is contained in:
parent
f771f77c67
commit
96e7fcd4e0
@ -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'],
|
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" ""
|
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 literate lyx "%% -n -m noweb -f $$i $$o" ""
|
||||||
\converter sweave lyx "%% -n -m sweave -f $$i $$o" ""
|
\converter sweave lyx "%% -n -m sweave -f $$i $$o" ""
|
||||||
\converter knitr lyx "%% -n -m knitr -f $$i $$o" ""'''], not_found = 'tex2lyx')
|
\converter knitr lyx "%% -n -m knitr -f $$i $$o" ""'''], not_found = 'tex2lyx')
|
||||||
|
@ -1145,7 +1145,7 @@ bool Buffer::importFile(string const & format, FileName const & name, ErrorList
|
|||||||
|
|
||||||
FileName const lyx = tempFileName("Buffer_importFileXXXXXX.lyx");
|
FileName const lyx = tempFileName("Buffer_importFileXXXXXX.lyx");
|
||||||
Converters::RetVal const retval =
|
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) {
|
if (retval == Converters::SUCCESS) {
|
||||||
bool const success = readFile(lyx) == ReadSuccess;
|
bool const success = readFile(lyx) == ReadSuccess;
|
||||||
removeTempFile(lyx);
|
removeTempFile(lyx);
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
#include "Buffer.h"
|
#include "Buffer.h"
|
||||||
#include "BufferParams.h"
|
#include "BufferParams.h"
|
||||||
#include "ConverterCache.h"
|
#include "ConverterCache.h"
|
||||||
|
#include "TextClass.h"
|
||||||
#include "Encoding.h"
|
#include "Encoding.h"
|
||||||
#include "ErrorList.h"
|
#include "ErrorList.h"
|
||||||
#include "Format.h"
|
#include "Format.h"
|
||||||
@ -58,6 +59,8 @@ string const token_to("$$o");
|
|||||||
string const token_path("$$p");
|
string const token_path("$$p");
|
||||||
string const token_orig_path("$$r");
|
string const token_orig_path("$$r");
|
||||||
string const token_orig_from("$$f");
|
string const token_orig_from("$$f");
|
||||||
|
string const token_textclass("$$c");
|
||||||
|
string const token_modules("$$m");
|
||||||
string const token_encoding("$$e");
|
string const token_encoding("$$e");
|
||||||
string const token_latex_encoding("$$E");
|
string const token_latex_encoding("$$E");
|
||||||
string const token_python("$${python}");
|
string const token_python("$${python}");
|
||||||
@ -472,7 +475,7 @@ Converters::RetVal Converters::convert(Buffer const * buffer,
|
|||||||
return FAILURE;
|
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.
|
// used anyway.
|
||||||
OutputParams runparams(buffer ? &buffer->params().encoding() : nullptr);
|
OutputParams runparams(buffer ? &buffer->params().encoding() : nullptr);
|
||||||
runparams.flavor = getFlavor(edgepath, buffer);
|
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_path, quoteName(onlyPath(infile.absFileName())));
|
||||||
command = subst(command, token_orig_path, quoteName(onlyPath(orig_from.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_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());
|
command = subst(command, token_python, os::python());
|
||||||
|
|
||||||
if (!conv.parselog().empty())
|
if (!conv.parselog().empty())
|
||||||
|
@ -1299,6 +1299,7 @@ bool pasteClipboardText(Cursor & cur, ErrorList & errorList, bool asParagraphs,
|
|||||||
Buffer buffer(string(), false);
|
Buffer buffer(string(), false);
|
||||||
buffer.setInternal(true);
|
buffer.setInternal(true);
|
||||||
buffer.setUnnamed(true);
|
buffer.setUnnamed(true);
|
||||||
|
buffer.params() = cur.buffer()->params();
|
||||||
available = buffer.importString(names[i], text, errorList);
|
available = buffer.importString(names[i], text, errorList);
|
||||||
if (available)
|
if (available)
|
||||||
available = !buffer.paragraphs().empty();
|
available = !buffer.paragraphs().empty();
|
||||||
|
@ -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,
|
bool LayoutModuleList::moduleCanBeAdded(string const & modName,
|
||||||
LayoutFile const * const lay) const
|
LayoutFile const * const lay) const
|
||||||
{
|
{
|
||||||
|
@ -55,6 +55,8 @@ public:
|
|||||||
/// This is needed in GuiDocument. It seems better than an
|
/// This is needed in GuiDocument. It seems better than an
|
||||||
/// implicit conversion.
|
/// implicit conversion.
|
||||||
std::list<std::string> const & list() const { return lml_; }
|
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
|
/// Checks to make sure module's requriements are satisfied, that it does
|
||||||
/// not conflict with already-present modules, isn't already loaded, etc.
|
/// not conflict with already-present modules, isn't already loaded, etc.
|
||||||
bool moduleCanBeAdded(std::string const & modName,
|
bool moduleCanBeAdded(std::string const & modName,
|
||||||
|
Loading…
Reference in New Issue
Block a user