]> git.lyx.org Git - lyx.git/commitdiff
Support for command argument placement after the workarea argument
authorJuergen Spitzmueller <spitz@lyx.org>
Fri, 28 Dec 2012 10:21:24 +0000 (11:21 +0100)
committerJuergen Spitzmueller <spitz@lyx.org>
Fri, 28 Dec 2012 10:21:24 +0000 (11:21 +0100)
14 files changed:
lib/doc/Customization.lyx
src/Layout.cpp
src/Layout.h
src/Paragraph.cpp
src/frontends/qt4/Menus.cpp
src/insets/InsetArgument.cpp
src/insets/InsetFloat.cpp
src/insets/InsetLayout.cpp
src/insets/InsetLayout.h
src/insets/InsetListings.cpp
src/insets/InsetText.cpp
src/insets/InsetText.h
src/output_latex.cpp
src/output_latex.h

index 86925af50fdafe735979399d5840ea4d3363d702..2802dc013c0c6afb21ebdbc638df5e7dbdb3abcf 100644 (file)
@@ -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
index 7e0308db9bf1d8fbe1a646e2b262e3bb5607b173..1eaa38aa5fa3b495a590ba70f858bfa736a6eb47 100644 (file)
@@ -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;
 }
 
index 39f784638e2bcfc5248fb706567a94485ba7099c..b02c5289be2a9f315b3c40dbca3197b0913a5a5e 100644 (file)
@@ -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_;
 };
 
index 6d4433f1139c079ef5a81a51be76e89306b3cb10..ea2c8366a06755a8e818d9654c6d8cfa64d7d673 100644 (file)
@@ -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);
                }
index 2e545c3f305b5a3ad7549fdee0f60850db67e157..a6fdfe5330a7e581f083e28a6b529ef496a81fd8 100644 (file)
@@ -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();
index ca76d08a029a7eeb1636c57f71d5c418fc72eab1..c5d5138da2ac9d727e36bbf8300b8be81e9382bb 100644 (file)
@@ -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();
        }
        
index 99d6c43402dd73f7d23380eeb678f604dfa5b8da..333702a6372281674f0a4bb5f194a26fdec281c0 100644 (file)
@@ -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);
index b6dcf582dd51a9eb6578ba0c16276b2545a573f8..0dc7914dde7f6db102ba17b9a40dff32191f3d02 100644 (file)
@@ -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;
        }
index 6bad059232ec7f390bc54315094879e3224c8c87..687561f0a21cc30d7004bca8d5631f67ab8c5919 100644 (file)
@@ -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_;
 };
 
 ///
index 0d61af671a02f8a45877b2011389674da79c13ee..603f46ffb0006e97052dbd1efba6c7a96dfea7a4 100644 (file)
@@ -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={}
index fd96fef0beb5e7cd086fdaa28824b083ec2d9692..3ec6f40492288ea6c56736bfa6336c8db74c141b 100644 (file)
@@ -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 =
                &paragraphs()[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());
 }
 
 
index 0113e174dd2061aab2b1fb16e9b057f00a64f526..b1d1502393f0baf9f51e7e51917fa52cf9cb721f 100644 (file)
@@ -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,
index 62d7b4511e426f22414109d346a75ac34d1ef97f..cd67e1729fff468ac6042a24ec22bb4b87307df7 100644 (file)
@@ -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())
index c3cb2db78c97933f6cc930d878a5d6153e6b6d55..89f8ac6a383aeb5614addd41d1fe0149c81a4653 100644 (file)
@@ -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.