mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 10:00:33 +00:00
Support for command argument placement after the workarea argument
This commit is contained in:
parent
e018ab2c12
commit
37f41fd4b5
@ -1,5 +1,5 @@
|
||||
#LyX 2.1 created this file. For more info see http://www.lyx.org/
|
||||
\lyxformat 453
|
||||
\lyxformat 455
|
||||
\begin_document
|
||||
\begin_header
|
||||
\textclass scrbook
|
||||
@ -11021,6 +11021,99 @@ layout can be automatically inserted.
|
||||
|
||||
\begin_layout Standard
|
||||
|
||||
\change_inserted -712698321 1356689813
|
||||
By default, the text entered in the LyX workarea in the respective layout
|
||||
is the last (mandatory) argument of a command if the
|
||||
\begin_inset Flex Code
|
||||
status collapsed
|
||||
|
||||
\begin_layout Plain Layout
|
||||
|
||||
\change_inserted -712698321 1356689619
|
||||
LatexType
|
||||
\change_unchanged
|
||||
|
||||
\end_layout
|
||||
|
||||
\end_inset
|
||||
|
||||
is
|
||||
\begin_inset Flex Code
|
||||
status collapsed
|
||||
|
||||
\begin_layout Plain Layout
|
||||
|
||||
\change_inserted -712698321 1356689629
|
||||
Command
|
||||
\change_unchanged
|
||||
|
||||
\end_layout
|
||||
|
||||
\end_inset
|
||||
|
||||
.
|
||||
However, arguments with the prefix
|
||||
\begin_inset Flex Code
|
||||
status collapsed
|
||||
|
||||
\begin_layout Plain Layout
|
||||
|
||||
\change_inserted -712698321 1356689679
|
||||
post:
|
||||
\change_unchanged
|
||||
|
||||
\end_layout
|
||||
|
||||
\end_inset
|
||||
|
||||
are output after this workarea argument.
|
||||
Note that post-argument numbering restarts at 1, so the first argument
|
||||
following the workarea argument is
|
||||
\begin_inset Flex Code
|
||||
status collapsed
|
||||
|
||||
\begin_layout Plain Layout
|
||||
|
||||
\change_inserted -712698321 1356689813
|
||||
post:1
|
||||
\change_unchanged
|
||||
|
||||
\end_layout
|
||||
|
||||
\end_inset
|
||||
|
||||
.
|
||||
Post-arguments are ignored in any other
|
||||
\begin_inset Flex Code
|
||||
status collapsed
|
||||
|
||||
\begin_layout Plain Layout
|
||||
|
||||
\change_inserted -712698321 1356689801
|
||||
LatexType
|
||||
\end_layout
|
||||
|
||||
\end_inset
|
||||
|
||||
than
|
||||
\begin_inset Flex Code
|
||||
status collapsed
|
||||
|
||||
\begin_layout Plain Layout
|
||||
|
||||
\change_inserted -712698321 1356689801
|
||||
Command
|
||||
\end_layout
|
||||
|
||||
\end_inset
|
||||
|
||||
.
|
||||
\change_unchanged
|
||||
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
|
||||
\change_inserted 155139281 1354199102
|
||||
Arguments for list
|
||||
\begin_inset Flex Code
|
||||
|
@ -896,6 +896,7 @@ void Layout::readArgument(Lexer & lex)
|
||||
string id;
|
||||
lex >> id;
|
||||
bool const itemarg = prefixIs(id, "item:");
|
||||
bool const postcmd = prefixIs(id, "post:");
|
||||
|
||||
while (!finished && lex.isOK() && !error) {
|
||||
lex.next();
|
||||
@ -952,6 +953,8 @@ void Layout::readArgument(Lexer & lex)
|
||||
LYXERR0("Incomplete Argument definition!");
|
||||
else if (itemarg)
|
||||
itemargs_[id] = arg;
|
||||
else if (postcmd)
|
||||
postcommandargs_[id] = arg;
|
||||
else
|
||||
latexargs_[id] = arg;
|
||||
}
|
||||
@ -960,6 +963,8 @@ void Layout::readArgument(Lexer & lex)
|
||||
Layout::LaTeXArgMap Layout::args() const
|
||||
{
|
||||
LaTeXArgMap args = latexargs_;
|
||||
if (!postcommandargs_.empty())
|
||||
args.insert(postcommandargs_.begin(), postcommandargs_.end());
|
||||
if (!itemargs_.empty())
|
||||
args.insert(itemargs_.begin(), itemargs_.end());
|
||||
return args;
|
||||
@ -974,6 +979,11 @@ int Layout::optArgs() const
|
||||
if (!(*it).second.mandatory)
|
||||
++nr;
|
||||
}
|
||||
LaTeXArgMap::const_iterator iit = postcommandargs_.begin();
|
||||
for (; iit != postcommandargs_.end(); ++iit) {
|
||||
if (!(*iit).second.mandatory)
|
||||
++nr;
|
||||
}
|
||||
return nr;
|
||||
}
|
||||
|
||||
@ -986,6 +996,11 @@ int Layout::requiredArgs() const
|
||||
if ((*it).second.mandatory)
|
||||
++nr;
|
||||
}
|
||||
LaTeXArgMap::const_iterator iit = postcommandargs_.begin();
|
||||
for (; iit != postcommandargs_.end(); ++iit) {
|
||||
if (!(*iit).second.mandatory)
|
||||
++nr;
|
||||
}
|
||||
return nr;
|
||||
}
|
||||
|
||||
|
@ -111,6 +111,8 @@ public:
|
||||
///
|
||||
LaTeXArgMap const & latexargs() const { return latexargs_; }
|
||||
///
|
||||
LaTeXArgMap const & postcommandargs() const { return postcommandargs_; }
|
||||
///
|
||||
LaTeXArgMap const & itemargs() const { return itemargs_; }
|
||||
///
|
||||
int optArgs() const;
|
||||
@ -411,6 +413,8 @@ private:
|
||||
///
|
||||
LaTeXArgMap latexargs_;
|
||||
///
|
||||
LaTeXArgMap postcommandargs_;
|
||||
///
|
||||
LaTeXArgMap itemargs_;
|
||||
};
|
||||
|
||||
|
@ -1472,8 +1472,14 @@ void Paragraph::Private::validate(LaTeXFeatures & features) const
|
||||
// this will output "{" at the beginning, but not at the end
|
||||
owner_->latex(bp, f, os, features.runparams(), 0, -1, true);
|
||||
if (ods.str().length() > length) {
|
||||
if (is_command)
|
||||
if (is_command) {
|
||||
ods << '}';
|
||||
if (!layout_->postcommandargs().empty()) {
|
||||
OutputParams rp = features.runparams();
|
||||
rp.local_font = &owner_->getFirstFontSettings(bp);
|
||||
latexArgInsets(*owner_, os, rp, layout_->postcommandargs(), "post:");
|
||||
}
|
||||
}
|
||||
string const snippet = to_utf8(ods.str());
|
||||
features.addPreambleSnippet(snippet);
|
||||
}
|
||||
|
@ -1556,7 +1556,7 @@ void MenuDefinition::expandArguments(BufferView const * bv, bool switcharg)
|
||||
Inset const * inset = &bv->cursor().inset();
|
||||
Layout::LaTeXArgMap args = bv->cursor().paragraph().layout().args();
|
||||
if (inset && args.empty())
|
||||
args = inset->getLayout().latexargs();
|
||||
args = inset->getLayout().args();
|
||||
if (args.empty() || (switcharg && args.size() == 1))
|
||||
return;
|
||||
Layout::LaTeXArgMap::const_iterator lait = args.begin();
|
||||
|
@ -61,7 +61,7 @@ void InsetArgument::updateBuffer(ParIterator const & it, UpdateType utype)
|
||||
pass_thru_ = it.paragraph().layout().pass_thru;
|
||||
bool const insetlayout = &it.inset() && args.empty();
|
||||
if (insetlayout) {
|
||||
args = it.inset().getLayout().latexargs();
|
||||
args = it.inset().getLayout().args();
|
||||
pass_thru_ = it.inset().getLayout().isPassThru();
|
||||
}
|
||||
|
||||
|
@ -482,7 +482,7 @@ docstring InsetFloat::getCaption(OutputParams const & runparams) const
|
||||
TexRow texrow;
|
||||
odocstringstream ods;
|
||||
otexstream os(ods, texrow);
|
||||
ins->getOptArg(os, runparams);
|
||||
ins->getArgs(os, runparams);
|
||||
ods << '[';
|
||||
odocstringstream odss;
|
||||
otexstream oss(odss, texrow);
|
||||
|
@ -518,6 +518,7 @@ void InsetLayout::readArgument(Lexer & lex)
|
||||
arg.labelfont = inherit_font;
|
||||
string nr;
|
||||
lex >> nr;
|
||||
bool const postcmd = support::prefixIs(nr, "post:");
|
||||
while (!finished && lex.isOK() && !error) {
|
||||
lex.next();
|
||||
string const tok = support::ascii_lowercase(lex.getString());
|
||||
@ -571,15 +572,27 @@ void InsetLayout::readArgument(Lexer & lex)
|
||||
}
|
||||
if (arg.labelstring.empty())
|
||||
LYXERR0("Incomplete Argument definition!");
|
||||
else if (postcmd)
|
||||
postcommandargs_[nr] = arg;
|
||||
else
|
||||
latexargs_[nr] = arg;
|
||||
}
|
||||
|
||||
|
||||
Layout::LaTeXArgMap InsetLayout::args() const
|
||||
{
|
||||
Layout::LaTeXArgMap args = latexargs_;
|
||||
if (!postcommandargs_.empty())
|
||||
args.insert(postcommandargs_.begin(), postcommandargs_.end());
|
||||
return args;
|
||||
}
|
||||
|
||||
|
||||
unsigned int InsetLayout::optArgs() const
|
||||
{
|
||||
unsigned int nr = 0;
|
||||
Layout::LaTeXArgMap::const_iterator it = latexargs_.begin();
|
||||
for (; it != latexargs_.end(); ++it) {
|
||||
Layout::LaTeXArgMap::const_iterator it = args().begin();
|
||||
for (; it != args().end(); ++it) {
|
||||
if (!(*it).second.mandatory)
|
||||
++nr;
|
||||
}
|
||||
@ -590,8 +603,8 @@ unsigned int InsetLayout::optArgs() const
|
||||
unsigned int InsetLayout::requiredArgs() const
|
||||
{
|
||||
unsigned int nr = 0;
|
||||
Layout::LaTeXArgMap::const_iterator it = latexargs_.begin();
|
||||
for (; it != latexargs_.end(); ++it) {
|
||||
Layout::LaTeXArgMap::const_iterator it = args().begin();
|
||||
for (; it != args().end(); ++it) {
|
||||
if ((*it).second.mandatory)
|
||||
++nr;
|
||||
}
|
||||
|
@ -86,8 +86,12 @@ public:
|
||||
///
|
||||
ColorCode bgcolor() const { return bgcolor_; }
|
||||
///
|
||||
Layout::LaTeXArgMap args() const;
|
||||
///
|
||||
Layout::LaTeXArgMap latexargs() const { return latexargs_; }
|
||||
///
|
||||
Layout::LaTeXArgMap postcommandargs() const { return postcommandargs_; }
|
||||
///
|
||||
unsigned int optArgs() const;
|
||||
///
|
||||
unsigned int requiredArgs() const;
|
||||
@ -268,6 +272,8 @@ private:
|
||||
bool forcelocalfontswitch_;
|
||||
///
|
||||
Layout::LaTeXArgMap latexargs_;
|
||||
///
|
||||
Layout::LaTeXArgMap postcommandargs_;
|
||||
};
|
||||
|
||||
///
|
||||
|
@ -384,7 +384,7 @@ docstring InsetListings::getCaption(OutputParams const & runparams) const
|
||||
TexRow texrow;
|
||||
odocstringstream ods;
|
||||
otexstream os(ods, texrow);
|
||||
ins->getOptArg(os, runparams);
|
||||
ins->getArgs(os, runparams);
|
||||
ins->getArgument(os, runparams);
|
||||
// the caption may contain \label{} but the listings
|
||||
// package prefer caption={}, label={}
|
||||
|
@ -345,7 +345,7 @@ bool InsetText::getStatus(Cursor & cur, FuncRequest const & cmd,
|
||||
if (&buffer().inset() == this || !cur.paragraph().layout().args().empty())
|
||||
return text_.getStatus(cur, cmd, status);
|
||||
|
||||
Layout::LaTeXArgMap args = getLayout().latexargs();
|
||||
Layout::LaTeXArgMap args = getLayout().args();
|
||||
Layout::LaTeXArgMap::const_iterator const lait = args.find(arg);
|
||||
if (lait != args.end()) {
|
||||
status.setEnabled(true);
|
||||
@ -444,7 +444,7 @@ void InsetText::latex(otexstream & os, OutputParams const & runparams) const
|
||||
os << "\\protect";
|
||||
os << '\\' << from_utf8(il.latexname());
|
||||
if (!il.latexargs().empty())
|
||||
getOptArg(os, runparams);
|
||||
getArgs(os, runparams);
|
||||
if (!il.latexparam().empty())
|
||||
os << from_utf8(il.latexparam());
|
||||
os << '{';
|
||||
@ -458,14 +458,14 @@ void InsetText::latex(otexstream & os, OutputParams const & runparams) const
|
||||
runparams.lastpos);
|
||||
os << "\\begin{" << from_utf8(il.latexname()) << "}";
|
||||
if (!il.latexargs().empty())
|
||||
getOptArg(os, runparams);
|
||||
getArgs(os, runparams);
|
||||
if (!il.latexparam().empty())
|
||||
os << from_utf8(il.latexparam());
|
||||
os << '\n';
|
||||
}
|
||||
} else {
|
||||
if (!il.latexargs().empty())
|
||||
getOptArg(os, runparams);
|
||||
getArgs(os, runparams);
|
||||
if (!il.latexparam().empty())
|
||||
os << from_utf8(il.latexparam());
|
||||
}
|
||||
@ -491,12 +491,14 @@ void InsetText::latex(otexstream & os, OutputParams const & runparams) const
|
||||
if (!il.latexname().empty()) {
|
||||
if (il.latextype() == InsetLayout::COMMAND) {
|
||||
os << "}";
|
||||
if (!il.postcommandargs().empty())
|
||||
getArgs(os, runparams, true);
|
||||
} else if (il.latextype() == InsetLayout::ENVIRONMENT) {
|
||||
// A comment environment doesn't need a % before \n\end
|
||||
if (il.isDisplay() || runparams.inComment)
|
||||
os << breakln;
|
||||
os << breakln;
|
||||
else
|
||||
os << safebreakln;
|
||||
os << safebreakln;
|
||||
os << "\\end{" << from_utf8(il.latexname()) << "}\n";
|
||||
if (!il.isDisplay())
|
||||
os.protectSpace(true);
|
||||
@ -622,15 +624,18 @@ docstring InsetText::insetAsXHTML(XHTMLStream & xs, OutputParams const & rp,
|
||||
return docstring();
|
||||
}
|
||||
|
||||
void InsetText::getOptArg(otexstream & os,
|
||||
OutputParams const & runparams_in) const
|
||||
void InsetText::getArgs(otexstream & os, OutputParams const & runparams_in,
|
||||
bool const post) const
|
||||
{
|
||||
OutputParams runparams = runparams_in;
|
||||
runparams.local_font =
|
||||
¶graphs()[0].getFirstFontSettings(buffer().masterBuffer()->params());
|
||||
if (isPassThru())
|
||||
runparams.pass_thru = true;
|
||||
latexArgInsets(paragraphs(), paragraphs().begin(), os, runparams, getLayout().latexargs());
|
||||
if (post)
|
||||
latexArgInsets(paragraphs(), paragraphs().begin(), os, runparams, getLayout().postcommandargs(), "post:");
|
||||
else
|
||||
latexArgInsets(paragraphs(), paragraphs().begin(), os, runparams, getLayout().latexargs());
|
||||
}
|
||||
|
||||
|
||||
|
@ -94,8 +94,8 @@ public:
|
||||
///
|
||||
void validate(LaTeXFeatures & features) const;
|
||||
|
||||
/// return the optional argument(s) only
|
||||
void getOptArg(otexstream & os, OutputParams const &) const;
|
||||
/// return the argument(s) only
|
||||
void getArgs(otexstream & os, OutputParams const &, bool const post = false) const;
|
||||
|
||||
/// return x,y of given position relative to the inset's baseline
|
||||
void cursorPos(BufferView const & bv, CursorSlice const & sl,
|
||||
|
@ -314,7 +314,7 @@ void TeXEnvironment(Buffer const & buf, Text const & text,
|
||||
|
||||
|
||||
void getArgInsets(otexstream & os, OutputParams const & runparams, Layout::LaTeXArgMap const & latexargs,
|
||||
map<int, lyx::InsetArgument const *> ilist, vector<string> required, bool item)
|
||||
map<int, lyx::InsetArgument const *> ilist, vector<string> required, string const & prefix)
|
||||
{
|
||||
unsigned int const argnr = latexargs.size();
|
||||
if (argnr == 0)
|
||||
@ -347,7 +347,7 @@ void getArgInsets(otexstream & os, OutputParams const & runparams, Layout::LaTeX
|
||||
Layout::LaTeXArgMap::const_iterator lait = latexargs.begin();
|
||||
Layout::LaTeXArgMap::const_iterator const laend = latexargs.end();
|
||||
for (; lait != laend; ++lait) {
|
||||
string const name = item ? "item:" + convert<string>(i) : convert<string>(i);
|
||||
string const name = prefix + convert<string>(i);
|
||||
if ((*lait).first == name) {
|
||||
Layout::latexarg arg = (*lait).second;
|
||||
if (arg.mandatory) {
|
||||
@ -386,7 +386,7 @@ void getArgInsets(otexstream & os, OutputParams const & runparams, Layout::LaTeX
|
||||
|
||||
|
||||
void latexArgInsets(Paragraph const & par, otexstream & os,
|
||||
OutputParams const & runparams, Layout::LaTeXArgMap const & latexargs, bool item)
|
||||
OutputParams const & runparams, Layout::LaTeXArgMap const & latexargs, string const & prefix)
|
||||
{
|
||||
map<int, InsetArgument const *> ilist;
|
||||
vector<string> required;
|
||||
@ -400,7 +400,7 @@ void latexArgInsets(Paragraph const & par, otexstream & os,
|
||||
if (ins->name().empty())
|
||||
LYXERR0("Error: Unnamed argument inset!");
|
||||
else {
|
||||
string const name = item ? split(ins->name(), ':') : ins->name();
|
||||
string const name = prefix.empty() ? ins->name() : split(ins->name(), ':');
|
||||
unsigned int const nr = convert<unsigned int>(name);
|
||||
ilist[nr] = ins;
|
||||
Layout::LaTeXArgMap::const_iterator const lit =
|
||||
@ -415,12 +415,13 @@ void latexArgInsets(Paragraph const & par, otexstream & os,
|
||||
}
|
||||
}
|
||||
}
|
||||
getArgInsets(os, runparams, latexargs, ilist, required, item);
|
||||
getArgInsets(os, runparams, latexargs, ilist, required, prefix);
|
||||
}
|
||||
|
||||
|
||||
void latexArgInsets(ParagraphList const & pars, ParagraphList::const_iterator pit,
|
||||
otexstream & os, OutputParams const & runparams, Layout::LaTeXArgMap const & latexargs)
|
||||
otexstream & os, OutputParams const & runparams, Layout::LaTeXArgMap const & latexargs,
|
||||
string const & prefix)
|
||||
{
|
||||
map<int, InsetArgument const *> ilist;
|
||||
vector<string> required;
|
||||
@ -457,7 +458,7 @@ void latexArgInsets(ParagraphList const & pars, ParagraphList::const_iterator pi
|
||||
if (ins->name().empty())
|
||||
LYXERR0("Error: Unnamed argument inset!");
|
||||
else {
|
||||
string const name = ins->name();
|
||||
string const name = prefix.empty() ? ins->name() : split(ins->name(), ':');
|
||||
unsigned int const nr = convert<unsigned int>(name);
|
||||
if (ilist.find(nr) == ilist.end())
|
||||
ilist[nr] = ins;
|
||||
@ -474,7 +475,7 @@ void latexArgInsets(ParagraphList const & pars, ParagraphList::const_iterator pi
|
||||
}
|
||||
}
|
||||
}
|
||||
getArgInsets(os, runparams, latexargs, ilist, required, false);
|
||||
getArgInsets(os, runparams, latexargs, ilist, required, prefix);
|
||||
}
|
||||
|
||||
namespace {
|
||||
@ -497,7 +498,7 @@ void parStartCommand(Paragraph const & par, otexstream & os,
|
||||
os << "\\" + style.itemcommand();
|
||||
// Item arguments
|
||||
if (!style.itemargs().empty())
|
||||
latexArgInsets(par, os, runparams, style.itemargs(), true);
|
||||
latexArgInsets(par, os, runparams, style.itemargs(), "item:");
|
||||
os << " ";
|
||||
break;
|
||||
case LATEX_BIB_ENVIRONMENT:
|
||||
@ -837,6 +838,8 @@ void TeXOnePar(Buffer const & buf,
|
||||
os << "\\" << from_ascii(font.latexSize()) << " \\par}";
|
||||
} else if (is_command) {
|
||||
os << '}';
|
||||
if (!style.postcommandargs().empty())
|
||||
latexArgInsets(par, os, runparams, style.postcommandargs(), "post:");
|
||||
if (runparams.encoding != prev_encoding) {
|
||||
runparams.encoding = prev_encoding;
|
||||
if (!runparams.isFullUnicode())
|
||||
|
@ -37,11 +37,13 @@ class Text;
|
||||
*/
|
||||
void latexArgInsets(Paragraph const & par,
|
||||
otexstream & os, OutputParams const & runparams,
|
||||
Layout::LaTeXArgMap const & latexargs, bool item = false);
|
||||
Layout::LaTeXArgMap const & latexargs,
|
||||
std::string const & prefix = std::string());
|
||||
/// Same for multi-par sequences (e.g. merged environments or InsetLayouts)
|
||||
void latexArgInsets(ParagraphList const & pars, ParagraphList::const_iterator pit,
|
||||
otexstream & os, OutputParams const & runparams,
|
||||
Layout::LaTeXArgMap const & latexargs);
|
||||
Layout::LaTeXArgMap const & latexargs,
|
||||
std::string const & prefix = std::string());
|
||||
/** Export \p paragraphs of buffer \p buf to LaTeX.
|
||||
Don't use a temporary stringstream for \p os if the final output is
|
||||
supposed to go to a file.
|
||||
|
Loading…
Reference in New Issue
Block a user