}
-docstring selection(size_t sel_index, DocumentClassConstPtr docclass)
+docstring selection(size_t sel_index, DocumentClassConstPtr docclass, bool for_math)
{
if (sel_index >= theCuts.size())
return docstring();
if (!buffer)
return docstring();
- return buffer->paragraphs().back().asString(AS_STR_INSETS | AS_STR_NEWLINES);
+ int options = AS_STR_INSETS | AS_STR_NEWLINES;
+ if (for_math)
+ options |= AS_STR_MATHED;
+
+ return buffer->paragraphs().back().asString(options);
}
std::vector<docstring> availableSelections(Buffer const *);
/// Get the number of available elements in the cut buffer.
size_type numberOfSelections();
-/// Get the sel_index-th element of the cut buffer in plain text format.
-docstring selection(size_t sel_index, DocumentClassConstPtr docclass);
+/**
+ * Get the sel_index-th element of the cut buffer in plain text format
+ * or, if \param for_math is true, in a format suitable for mathed.
+ */
+docstring selection(size_t sel_index, DocumentClassConstPtr docclass, bool for_math = false);
/**
* Replace using the font of the first selected character and select
if (c == META_INSET && (options & AS_STR_PLAINTEXT)) {
LASSERT(runparams != nullptr, return docstring());
getInset(i)->plaintext(os, *runparams);
+ } else if (c == META_INSET && (options & AS_STR_MATHED)
+ && getInset(i)->lyxCode() == REF_CODE) {
+ Buffer const & buf = getInset(i)->buffer();
+ OutputParams rp(&buf.params().encoding());
+ Font const font(inherit_font, buf.params().language);
+ rp.local_font = &font;
+ otexstream ots(os);
+ getInset(i)->latex(ots, rp);
} else {
getInset(i)->toString(os);
}
AS_STR_INSETS = 2, ///< Go into insets.
AS_STR_NEWLINES = 4, ///< Get also newline characters.
AS_STR_SKIPDELETE = 8, ///< Skip deleted text in change tracking.
- AS_STR_PLAINTEXT = 16 ///< Don't export formatting when descending into insets.
+ AS_STR_PLAINTEXT = 16, ///< Don't export formatting when descending into insets.
+ AS_STR_MATHED = 32 ///< Use a format suitable for mathed (eg. for InsetRef).
};
idocstringstream is(cmd.argument());
int n = 0;
is >> n;
- topaste = cap::selection(n, buffer().params().documentClassPtr());
+ topaste = cap::selection(n, buffer().params().documentClassPtr(), true);
}
InsetMathGrid grid(buffer_, 1, 1);
if (!topaste.empty())