From: Juergen Spitzmueller Date: Fri, 28 Dec 2012 10:21:24 +0000 (+0100) Subject: Support for command argument placement after the workarea argument X-Git-Tag: 2.1.0beta1~1041 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=37f41fd4b56c54764014c93c003be555f3fd6421;hp=e018ab2c1246179e509793b4355019aba1fc3532;p=lyx.git Support for command argument placement after the workarea argument --- diff --git a/lib/doc/Customization.lyx b/lib/doc/Customization.lyx index 86925af50f..2802dc013c 100644 --- a/lib/doc/Customization.lyx +++ b/lib/doc/Customization.lyx @@ -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 diff --git a/src/Layout.cpp b/src/Layout.cpp index 7e0308db9b..1eaa38aa5f 100644 --- a/src/Layout.cpp +++ b/src/Layout.cpp @@ -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; } diff --git a/src/Layout.h b/src/Layout.h index 39f784638e..b02c5289be 100644 --- a/src/Layout.h +++ b/src/Layout.h @@ -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_; }; diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp index 6d4433f113..ea2c8366a0 100644 --- a/src/Paragraph.cpp +++ b/src/Paragraph.cpp @@ -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); } diff --git a/src/frontends/qt4/Menus.cpp b/src/frontends/qt4/Menus.cpp index 2e545c3f30..a6fdfe5330 100644 --- a/src/frontends/qt4/Menus.cpp +++ b/src/frontends/qt4/Menus.cpp @@ -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(); diff --git a/src/insets/InsetArgument.cpp b/src/insets/InsetArgument.cpp index ca76d08a02..c5d5138da2 100644 --- a/src/insets/InsetArgument.cpp +++ b/src/insets/InsetArgument.cpp @@ -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(); } diff --git a/src/insets/InsetFloat.cpp b/src/insets/InsetFloat.cpp index 99d6c43402..333702a637 100644 --- a/src/insets/InsetFloat.cpp +++ b/src/insets/InsetFloat.cpp @@ -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); diff --git a/src/insets/InsetLayout.cpp b/src/insets/InsetLayout.cpp index b6dcf582dd..0dc7914dde 100644 --- a/src/insets/InsetLayout.cpp +++ b/src/insets/InsetLayout.cpp @@ -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; } diff --git a/src/insets/InsetLayout.h b/src/insets/InsetLayout.h index 6bad059232..687561f0a2 100644 --- a/src/insets/InsetLayout.h +++ b/src/insets/InsetLayout.h @@ -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_; }; /// diff --git a/src/insets/InsetListings.cpp b/src/insets/InsetListings.cpp index 0d61af671a..603f46ffb0 100644 --- a/src/insets/InsetListings.cpp +++ b/src/insets/InsetListings.cpp @@ -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={} diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp index fd96fef0be..3ec6f40492 100644 --- a/src/insets/InsetText.cpp +++ b/src/insets/InsetText.cpp @@ -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()); } diff --git a/src/insets/InsetText.h b/src/insets/InsetText.h index 0113e174dd..b1d1502393 100644 --- a/src/insets/InsetText.h +++ b/src/insets/InsetText.h @@ -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, diff --git a/src/output_latex.cpp b/src/output_latex.cpp index 62d7b4511e..cd67e1729f 100644 --- a/src/output_latex.cpp +++ b/src/output_latex.cpp @@ -314,7 +314,7 @@ void TeXEnvironment(Buffer const & buf, Text const & text, void getArgInsets(otexstream & os, OutputParams const & runparams, Layout::LaTeXArgMap const & latexargs, - map ilist, vector required, bool item) + map ilist, vector 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(i) : convert(i); + string const name = prefix + convert(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 ilist; vector 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(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 ilist; vector 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(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()) diff --git a/src/output_latex.h b/src/output_latex.h index c3cb2db78c..89f8ac6a38 100644 --- a/src/output_latex.h +++ b/src/output_latex.h @@ -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.