]> git.lyx.org Git - lyx.git/commitdiff
Support for \item arguments
authorJuergen Spitzmueller <spitz@lyx.org>
Thu, 29 Nov 2012 14:34:20 +0000 (15:34 +0100)
committerJuergen Spitzmueller <spitz@lyx.org>
Thu, 29 Nov 2012 14:34:20 +0000 (15:34 +0100)
17 files changed:
development/FORMAT
lib/doc/Customization.lyx
lib/layouts/apa.layout
lib/layouts/egs.layout
lib/layouts/stdlists.inc
lib/lyx2lyx/lyx_2_1.py
src/Layout.cpp
src/Layout.h
src/Text3.cpp
src/frontends/qt4/Menus.cpp
src/insets/InsetArgument.cpp
src/insets/InsetLayout.cpp
src/insets/InsetText.cpp
src/output_latex.cpp
src/output_latex.h
src/tex2lyx/TODO.txt
src/version.h

index 07f7cc4121badb77b61a1d96dab91150141e11b4..9eb9839554efa384d0bcd234482cf7a0fd16f0b1 100644 (file)
@@ -12,6 +12,15 @@ adjustments are made to tex2lyx and bugs are fixed in lyx2lyx.
 -----------------------
 
 
+2012-11-29 Jürgen Spitzmüller <spitz@lyx.org>
+       * Format incremented to 449: Support for \item arguments.
+         Item arguments have the prefix "item:" and a number determining
+         the order.
+            \begin_inset Argument item:1
+            ...
+            \end_inset
+         => \item[...]
+
 2012-11-25 Kayvan Sylvan <kayvan@sylvan.com>
        * Format incremented to 448: Change Noweb literate style Scrap
          to Chunk to be consistent with all the other literate tools
index 4e70704d7bdf88d464bbbb39de9433e2089994e1..52abb0be78b655d2a7f729ef20ec3a79c36062ad 100644 (file)
@@ -1,5 +1,5 @@
 #LyX 2.1 created this file. For more info see http://www.lyx.org/
-\lyxformat 448
+\lyxformat 449
 \begin_document
 \begin_header
 \textclass scrbook
@@ -10815,6 +10815,79 @@ Classic
 \end_inset
 
 .
+\change_inserted 155139281 1354198988
+
+\end_layout
+
+\begin_layout Standard
+
+\change_inserted 155139281 1354199102
+Arguments for list 
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted 155139281 1354199013
+
+\backslash
+item
+\change_unchanged
+
+\end_layout
+
+\end_inset
+
+s (as in 
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted 155139281 1354199102
+
+\backslash
+item[foo]
+\change_unchanged
+
+\end_layout
+
+\end_inset
+
+) have the prefix 
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted 155139281 1354199044
+item:
+\change_unchanged
+
+\end_layout
+
+\end_inset
+
+ followed by the number (e.
+\begin_inset space \thinspace{}
+\end_inset
+
+g.
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted 155139281 1354199064
+Argument item:1
+\change_unchanged
+
+\end_layout
+
+\end_inset
+
+)
 \change_unchanged
 
 \end_layout
index f3be8246d34e2d6dd963d67efe54015371bd6fa4..74697c1030516fc9ce6f2c88247505d95cd9b448 100644 (file)
@@ -354,6 +354,10 @@ Style Itemize
        Align                 Block
        AlignPossible         Block, Left
        LabelType             Itemize
+       Argument item:1
+               LabelString   "Custom Item|s"
+               Tooltip       "A customized item string"
+       EndArgument
 End
 
 
@@ -373,6 +377,10 @@ Style Enumerate
        AlignPossible         Block, Left
        LabelType             Enumerate
        RefPrefix             enu
+       Argument item:1
+               LabelString   "Custom Item|s"
+               Tooltip       "A customized item string"
+       EndArgument
 End
 
 
index 6fcc72478198bdc4aee55cb7b67e13202ee71afd..1af9a5be5e6d3eae7475989848f3177c283e5896 100644 (file)
@@ -163,6 +163,10 @@ Style Enumerate
        AlignPossible         Block, Left
        LabelType             Enumerate
        RefPrefix             enu
+       Argument item:1
+               LabelString   "Custom Item|s"
+               Tooltip       "A customized item string"
+       EndArgument
 End
 
 
@@ -180,6 +184,10 @@ Style Itemize
        Align                 Block
        AlignPossible         Block, Left
        LabelType             Itemize
+       Argument item:1
+               LabelString   "Custom Item|s"
+               Tooltip       "A customized item string"
+       EndArgument
 End
 
 
index 9f7a774bef3964c9c9bebeba81a0450178b12c7d..108c734c15dc88a816ee72af02fed438aba8715e 100644 (file)
@@ -28,6 +28,10 @@ Style Itemize
        HTMLTag               ul
        HTMLItem              li
        HTMLLabel             NONE
+       Argument item:1
+               LabelString   "Custom Item|s"
+               Tooltip       "A customized item string"
+       EndArgument
 End
 
 
@@ -52,6 +56,10 @@ Style Enumerate
        HTMLItem              li
        HTMLLabel             NONE
        RefPrefix             enu
+       Argument item:1
+               LabelString   "Custom Item|s"
+               Tooltip       "A customized item string"
+       EndArgument
 End
 
 Style Description
index ec4ed6c7c8a27d3b01e641f8e89a45e0d7794021..503a038aed11e0a62380cb2f45d5232ebf6186ed 100644 (file)
@@ -25,13 +25,13 @@ import sys, os
 
 # Uncomment only what you need to import, please.
 
-from parser_tools import del_token, find_token, find_end_of, find_end_of_inset, \
+from parser_tools import del_token, find_token, find_token_backwards, find_end_of, find_end_of_inset, \
     find_end_of_layout, find_re, get_option_value, get_value, get_quoted_value, \
     set_option_value
 
 #from parser_tools import find_token, find_end_of, find_tokens, \
   #find_token_exact, find_end_of_inset, find_end_of_layout, \
-  #find_token_backwards, is_in_inset, del_token, check_token
+  #is_in_inset, del_token, check_token
 
 from lyx2lyx_tools import add_to_preamble, put_cmd_in_ert, get_ert
 
@@ -1232,7 +1232,7 @@ def revert_IEEEtran(document):
 def convert_Argument_to_TeX_brace(document, line, n, nmax, environment):
     '''
     Converts TeX code to an InsetArgument
-    !!! Be careful if the braces are different in your case as exppected here:
+    !!! Be careful if the braces are different in your case as expected here:
     - }{ separates mandatory arguments of commands
     - { and } surround a mandatory argument of an environment
     usage:
@@ -1429,6 +1429,23 @@ def convert_literate(document):
         document.body[i] = "\\begin_layout Chunk"
         i = i + 1
 
+def revert_itemargs(document):
+    " Reverts \\item arguments to TeX-code "
+    while True:
+        i = find_token(document.body, "\\begin_inset Argument item:", 0)
+        j = find_end_of_inset(document.body, i)
+        if i == -1:
+            break
+        lastlay = find_token_backwards(document.body, "\\begin_layout", i)
+        beginPlain = find_token(document.body, "\\begin_layout Plain Layout", i)
+        endLayout = find_token(document.body, "\\end_layout", beginPlain)
+        endInset = find_token(document.body, "\\end_inset", endLayout)
+        content = document.body[beginPlain + 1 : endLayout]
+        del document.body[i:j+1]
+        subst = put_cmd_in_ert("[") + content + put_cmd_in_ert("]")
+        document.body[lastlay + 1:lastlay + 1] = subst
+        i = i + 1
+
 ##
 # Conversion hub
 #
@@ -1469,10 +1486,12 @@ convert = [
            [445, []],
            [446, [convert_latexargs]],
            [447, [convert_IEEEtran, convert_AASTeX, convert_AGUTeX, convert_IJMP]],
-           [448, [convert_literate]]
+           [448, [convert_literate]],
+           [449, []]
           ]
 
 revert =  [
+           [448, [revert_itemargs]],
            [447, [revert_literate]],
            [446, [revert_IEEEtran, revert_AASTeX, revert_AGUTeX, revert_IJMP]],
            [445, [revert_latexargs]],
index 7fcf882e818e8f908fe485eebab876168430b05e..95cb28bdbea65c3d9dd7387718e6d94ad47d37e6 100644 (file)
@@ -322,8 +322,10 @@ bool Layout::read(Lexer & lex, TextClass const & tclass)
                case LT_RESETARGS:
                        bool reset;
                        lex >> reset;
-                       if (reset)
+                       if (reset) {
                                latexargs_.clear();
+                               itemargs_.clear();
+                       }
                        break;
 
                case LT_ARGUMENT:
@@ -879,8 +881,10 @@ void Layout::readArgument(Lexer & lex)
        bool finished = false;
        arg.font = inherit_font;
        arg.labelfont = inherit_font;
-       unsigned int nr;
-       lex >> nr;
+       string id;
+       lex >> id;
+       bool const itemarg = prefixIs(id, "item:");
+
        while (!finished && lex.isOK() && !error) {
                lex.next();
                string const tok = ascii_lowercase(lex.getString());
@@ -921,8 +925,10 @@ void Layout::readArgument(Lexer & lex)
        }
        if (arg.labelstring.empty())
                LYXERR0("Incomplete Argument definition!");
+       else if (itemarg)
+               itemargs_[id] = arg;
        else
-               latexargs_[nr] = arg;
+               latexargs_[id] = arg;
 }
 
 
index b0c3ac5bad36eab221f67dc81bbaa0a504bff0cd..f8c1ed46f9f13e65ce1a868a6f28a01d728ab8a3 100644 (file)
@@ -100,10 +100,12 @@ public:
                FontInfo labelfont;
        };
        ///
-       typedef std::map<unsigned int, latexarg> LaTeXArgMap;
+       typedef std::map<std::string, latexarg> LaTeXArgMap;
        ///
        LaTeXArgMap const & latexargs() const { return latexargs_; }
        ///
+       LaTeXArgMap const & itemargs() const { return itemargs_; }
+       ///
        int optArgs() const;
        ///
        int requiredArgs() const;
@@ -399,6 +401,8 @@ private:
        std::set<std::string> requires_;
        ///
        LaTeXArgMap latexargs_;
+       ///
+       LaTeXArgMap itemargs_;
 };
 
 } // namespace lyx
index 9cace0df53822176dcb873b498035eb62c2c6712..b685129ba5be38d2325dbfa4cb8f1fec6d23b884 100644 (file)
@@ -2526,8 +2526,11 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
                }
                Layout const & lay = cur.paragraph().layout();
                Layout::LaTeXArgMap args = lay.latexargs();
+               Layout::LaTeXArgMap itemargs = lay.itemargs();
+               if (!itemargs.empty())
+                       args.insert(itemargs.begin(), itemargs.end());
                Layout::LaTeXArgMap::const_iterator const lait =
-                               args.find(convert<unsigned int>(arg));
+                               args.find(arg);
                if (lait != args.end()) {
                        enable = true;
                        InsetList::const_iterator it = cur.paragraph().insetList().begin();
index aa3d86000427005e005fcb4374e809904ec61be8..a0da7243c1a5d127f5dda783b29cbc1e6896e1b2 100644 (file)
@@ -1555,10 +1555,15 @@ void MenuDefinition::expandArguments(BufferView const * bv, bool switcharg)
 
        Inset const * inset = &bv->cursor().inset();
        Layout::LaTeXArgMap args;
-       if (inset && bv->cursor().paragraph().layout().latexargs().empty())
+       if (inset && bv->cursor().paragraph().layout().latexargs().empty()
+           && bv->cursor().paragraph().layout().itemargs().empty())
                args = inset->getLayout().latexargs();
-       else
+       else {
                args = bv->cursor().paragraph().layout().latexargs();
+               Layout::LaTeXArgMap itemargs = bv->cursor().paragraph().layout().itemargs();
+               if (!itemargs.empty())
+                       args.insert(itemargs.begin(), itemargs.end());
+       }
        if (args.empty() || (switcharg && args.size() == 1))
                return;
        Layout::LaTeXArgMap::const_iterator lait = args.begin();
@@ -1570,11 +1575,11 @@ void MenuDefinition::expandArguments(BufferView const * bv, bool switcharg)
                        add(MenuItem(MenuItem::Command, item,
                                     FuncRequest(LFUN_INSET_MODIFY,
                                                 from_ascii("changetype ")
-                                                + convert<docstring>((*lait).first))));
+                                                + from_ascii((*lait).first))));
                else
                        add(MenuItem(MenuItem::Command, item,
                                     FuncRequest(LFUN_ARGUMENT_INSERT,
-                                                convert<docstring>((*lait).first))));
+                                                from_ascii((*lait).first))));
        }
 }
 
index 533c4239956bbb5170ce4603221cb3f0f0f2376d..e4acd6b2367e4c0f0595cf5b31d0ad99cb80f2ff 100644 (file)
@@ -58,12 +58,16 @@ void InsetArgument::read(Lexer & lex)
 void InsetArgument::updateBuffer(ParIterator const & it, UpdateType utype)
 {
        Layout::LaTeXArgMap args;
-       bool const insetlayout = &it.inset() && it.paragraph().layout().latexargs().empty();
+       bool const insetlayout = &it.inset() && it.paragraph().layout().latexargs().empty()
+             && it.paragraph().layout().itemargs().empty();
        if (insetlayout) {
                args = it.inset().getLayout().latexargs();
                pass_thru_ = it.inset().getLayout().isPassThru();
        } else {
                args = it.paragraph().layout().latexargs();
+               Layout::LaTeXArgMap itemargs = it.paragraph().layout().itemargs();
+               if (!itemargs.empty())
+                       args.insert(itemargs.begin(), itemargs.end());
                pass_thru_ = it.paragraph().layout().pass_thru;
        }
        
@@ -102,8 +106,7 @@ void InsetArgument::updateBuffer(ParIterator const & it, UpdateType utype)
                        name_ = convert<string>(ours);
                }
        }
-       Layout::LaTeXArgMap::const_iterator const lait =
-                       args.find(convert<unsigned int>(name_));
+       Layout::LaTeXArgMap::const_iterator const lait = args.find(name_);
        if (lait != args.end()) {
                docstring label = translateIfPossible((*lait).second.labelstring);
                docstring striplabel;
@@ -179,8 +182,7 @@ bool InsetArgument::getStatus(Cursor & cur, FuncRequest const & cmd,
                                args = cur.inset().getLayout().latexargs();
                        else
                                args = cur.paragraph().layout().latexargs();
-                       Layout::LaTeXArgMap::const_iterator const lait =
-                                       args.find(convert<unsigned int>(type));
+                       Layout::LaTeXArgMap::const_iterator const lait = args.find(type);
                        if (lait != args.end()) {
                                flag.setEnabled(true);
                                InsetList::const_iterator it = cur.paragraph().insetList().begin();
index 9c9c7f2fce5ce5c726cdd4d252769955e80045f1..aa9672e96dbd8377952c05a639d9e37650886af1 100644 (file)
@@ -503,7 +503,7 @@ void InsetLayout::readArgument(Lexer & lex)
        bool finished = false;
        arg.font = inherit_font;
        arg.labelfont = inherit_font;
-       unsigned int nr;
+       string nr;
        lex >> nr;
        while (!finished && lex.isOK() && !error) {
                lex.next();
index d1c80009bae398ea07629e1a69518b79bc425ddc..b48684fe97a27c8a54fcba627e0fe75f882f939c 100644 (file)
@@ -338,11 +338,11 @@ bool InsetText::getStatus(Cursor & cur, FuncRequest const & cmd,
                        status.setEnabled(false);
                        return true;
                }
-               if (&buffer().inset() == this || !cur.paragraph().layout().latexargs().empty())
+               if (&buffer().inset() == this || !cur.paragraph().layout().latexargs().empty()
+                   || !cur.paragraph().layout().itemargs().empty())
                        return text_.getStatus(cur, cmd, status);
                Layout::LaTeXArgMap args = getLayout().latexargs();
-               Layout::LaTeXArgMap::const_iterator const lait =
-                               args.find(convert<unsigned int>(arg));
+               Layout::LaTeXArgMap::const_iterator const lait = args.find(arg);
                if (lait != args.end()) {
                        status.setEnabled(true);
                        InsetList::const_iterator it = cur.paragraph().insetList().begin();
index 6785c2749eeb83379922e84fb0032d53a30aaf29..9d609eea9c82f6d75c25803e1ab38b99fbf58b05 100644 (file)
@@ -316,7 +316,7 @@ void TeXEnvironment(Buffer const & buf, Text const & text,
 
 
 void latexArgInsets(Paragraph const & par, otexstream & os,
-       OutputParams const & runparams, Layout::LaTeXArgMap const & latexargs)
+       OutputParams const & runparams, Layout::LaTeXArgMap const & latexargs, bool item)
 {
        map<int, InsetArgument const *> ilist;
        vector<string> required;
@@ -330,10 +330,11 @@ void latexArgInsets(Paragraph const & par, otexstream & os,
                        if (ins->name().empty())
                                LYXERR0("Error: Unnamed argument inset!");
                        else {
-                               unsigned int const nr = convert<unsigned int>(ins->name());
+                               string const name = item ? split(ins->name(), ':') : ins->name();
+                               unsigned int const nr = convert<unsigned int>(name);
                                ilist[nr] = ins;
                                Layout::LaTeXArgMap::const_iterator const lit =
-                                               latexargs.find(nr);
+                                               latexargs.find(ins->name());
                                if (lit != latexargs.end()) {
                                        Layout::latexarg const & arg = (*lit).second;
                                        if (!arg.requires.empty()) {
@@ -356,7 +357,7 @@ void latexArgInsets(Paragraph const & par, otexstream & os,
                        InsetArgument const * ins = (*lit).second;
                        if (ins) {
                                Layout::LaTeXArgMap::const_iterator const lait =
-                                               latexargs.find(convert<unsigned int>(ins->name()));
+                                               latexargs.find(ins->name());
                                if (lait != latexargs.end()) {
                                        Layout::latexarg arg = (*lait).second;
                                        docstring ldelim = arg.mandatory ?
@@ -376,7 +377,8 @@ void latexArgInsets(Paragraph const & par, otexstream & os,
                        Layout::LaTeXArgMap::const_iterator lait = latexargs.begin();
                        Layout::LaTeXArgMap::const_iterator const laend = latexargs.end();
                        for (; lait != laend; ++lait) {
-                               if ((*lait).first == i) {
+                               string const name = item ? "item:" + convert<string>(i) : convert<string>(i);
+                               if ((*lait).first == name) {
                                        Layout::latexarg arg = (*lait).second;
                                        if (arg.mandatory) {
                                                docstring ldelim = arg.ldelim.empty() ?
@@ -385,7 +387,7 @@ void latexArgInsets(Paragraph const & par, otexstream & os,
                                                                from_ascii("}") : arg.rdelim;
                                                os << ldelim << rdelim;
                                        } else if (find(required.begin(), required.end(),
-                                                  convert<string>((*lait).first)) != required.end()) {
+                                                  (*lait).first) != required.end()) {
                                                docstring ldelim = arg.ldelim.empty() ?
                                                                from_ascii("[") : arg.ldelim;
                                                docstring rdelim = arg.rdelim.empty() ?
@@ -409,14 +411,18 @@ void parStartCommand(Paragraph const & par, otexstream & os,
        case LATEX_COMMAND:
                os << '\\' << from_ascii(style.latexname());
 
-               // Separate handling of optional argument inset.
+               // Command arguments
                if (!style.latexargs().empty())
                        latexArgInsets(par, os, runparams, style.latexargs());
                os << from_ascii(style.latexparam());
                break;
        case LATEX_ITEM_ENVIRONMENT:
        case LATEX_LIST_ENVIRONMENT:
-               os << "\\item ";
+               os << "\\item";
+               // Item arguments
+               if (!style.itemargs().empty())
+                       latexArgInsets(par, os, runparams, style.itemargs(), true);
+               os << " ";
                break;
        case LATEX_BIB_ENVIRONMENT:
                // ignore this, the inset will write itself
index fa07ca6ce79627f67927ed164f172fe1576d6080..99c222018749054f124321b0893668a6c1057a12 100644 (file)
@@ -38,7 +38,7 @@ class Text;
 /// must all come first.
 void latexArgInsets(Paragraph const & par,
                otexstream & os, OutputParams const & runparams,
-               Layout::LaTeXArgMap const & latexargs);
+               Layout::LaTeXArgMap const & latexargs, bool item = false);
 
 /** Export \p paragraphs of buffer \p buf to LaTeX.
     Don't use a temporary stringstream for \p os if the final output is
index 3e4c02d32e2ce151bc7009e2bfc61a9641577ed4..88f46dc8692b34acd80bf98f5cbc477107d16e7d 100644 (file)
@@ -80,6 +80,10 @@ Format LaTeX feature                        LyX feature
        \renewcommand{\sffamily}{uop}
 446    Optional and required arguments      InsetArgument
        now numbered by order
+447
+448
+449    \item[<arg>]                         \begin_inset Argument item:<nr>
+
 
 
 General
index 41ed5b98019554bf5e8bb5b45096f75602212a00..44a46bfd016b57692e3628f2e99aa2d7e910194a 100644 (file)
@@ -30,8 +30,8 @@ extern char const * const lyx_version_info;
 
 // Do not remove the comment below, so we get merge conflict in
 // independent branches. Instead add your own.
-#define LYX_FORMAT_LYX 448 // kayvan: fix for noweb literate docs
-#define LYX_FORMAT_TEX2LYX 448
+#define LYX_FORMAT_LYX 449 // spitz: support for \item arguments
+#define LYX_FORMAT_TEX2LYX 449 // spitz: support for \item arguments
 
 #if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX
 #ifndef _MSC_VER