The branch, master, has been updated.

- Log -----------------------------------------------------------------

commit 1500e44cbad09d0d2aecdd1511f69ea5ae084633
Author: Juergen Spitzmueller <[email protected]>
Date:   Thu Nov 29 15:34:20 2012 +0100

    Support for \item arguments

diff --git a/development/FORMAT b/development/FORMAT
index 07f7cc4..9eb9839 100644
--- a/development/FORMAT
+++ b/development/FORMAT
@@ -12,6 +12,15 @@ adjustments are made to tex2lyx and bugs are fixed in 
lyx2lyx.
 -----------------------
 
 
+2012-11-29 Jürgen Spitzmüller <[email protected]>
+       * 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 <[email protected]>
        * Format incremented to 448: Change Noweb literate style Scrap
          to Chunk to be consistent with all the other literate tools
diff --git a/lib/doc/Customization.lyx b/lib/doc/Customization.lyx
index 4e70704..52abb0b 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 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
diff --git a/lib/layouts/apa.layout b/lib/layouts/apa.layout
index f3be824..74697c1 100644
--- a/lib/layouts/apa.layout
+++ b/lib/layouts/apa.layout
@@ -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
 
 
diff --git a/lib/layouts/egs.layout b/lib/layouts/egs.layout
index 6fcc724..1af9a5b 100644
--- a/lib/layouts/egs.layout
+++ b/lib/layouts/egs.layout
@@ -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
 
 
diff --git a/lib/layouts/stdlists.inc b/lib/layouts/stdlists.inc
index 9f7a774..108c734 100644
--- a/lib/layouts/stdlists.inc
+++ b/lib/layouts/stdlists.inc
@@ -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
diff --git a/lib/lyx2lyx/lyx_2_1.py b/lib/lyx2lyx/lyx_2_1.py
index ec4ed6c..503a038 100644
--- a/lib/lyx2lyx/lyx_2_1.py
+++ b/lib/lyx2lyx/lyx_2_1.py
@@ -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]],
diff --git a/src/Layout.cpp b/src/Layout.cpp
index 7fcf882..95cb28b 100644
--- a/src/Layout.cpp
+++ b/src/Layout.cpp
@@ -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;
 }
 
 
diff --git a/src/Layout.h b/src/Layout.h
index b0c3ac5..f8c1ed4 100644
--- a/src/Layout.h
+++ b/src/Layout.h
@@ -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
diff --git a/src/Text3.cpp b/src/Text3.cpp
index 9cace0d..b685129 100644
--- a/src/Text3.cpp
+++ b/src/Text3.cpp
@@ -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();
diff --git a/src/frontends/qt4/Menus.cpp b/src/frontends/qt4/Menus.cpp
index aa3d860..a0da724 100644
--- a/src/frontends/qt4/Menus.cpp
+++ b/src/frontends/qt4/Menus.cpp
@@ -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))));
        }
 }
 
diff --git a/src/insets/InsetArgument.cpp b/src/insets/InsetArgument.cpp
index 533c423..e4acd6b 100644
--- a/src/insets/InsetArgument.cpp
+++ b/src/insets/InsetArgument.cpp
@@ -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();
diff --git a/src/insets/InsetLayout.cpp b/src/insets/InsetLayout.cpp
index 9c9c7f2..aa9672e 100644
--- a/src/insets/InsetLayout.cpp
+++ b/src/insets/InsetLayout.cpp
@@ -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();
diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp
index d1c8000..b48684f 100644
--- a/src/insets/InsetText.cpp
+++ b/src/insets/InsetText.cpp
@@ -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();
diff --git a/src/output_latex.cpp b/src/output_latex.cpp
index 6785c27..9d609ee 100644
--- a/src/output_latex.cpp
+++ b/src/output_latex.cpp
@@ -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
diff --git a/src/output_latex.h b/src/output_latex.h
index fa07ca6..99c2220 100644
--- a/src/output_latex.h
+++ b/src/output_latex.h
@@ -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
diff --git a/src/tex2lyx/TODO.txt b/src/tex2lyx/TODO.txt
index 3e4c02d..88f46dc 100644
--- a/src/tex2lyx/TODO.txt
+++ b/src/tex2lyx/TODO.txt
@@ -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
diff --git a/src/version.h b/src/version.h
index 41ed5b9..44a46bf 100644
--- a/src/version.h
+++ b/src/version.h
@@ -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

-----------------------------------------------------------------------

Summary of changes:
 development/FORMAT           |    9 +++++
 lib/doc/Customization.lyx    |   75 +++++++++++++++++++++++++++++++++++++++++-
 lib/layouts/apa.layout       |    8 ++++
 lib/layouts/egs.layout       |    8 ++++
 lib/layouts/stdlists.inc     |    8 ++++
 lib/lyx2lyx/lyx_2_1.py       |   27 +++++++++++++--
 src/Layout.cpp               |   14 +++++--
 src/Layout.h                 |    6 +++-
 src/Text3.cpp                |    5 ++-
 src/frontends/qt4/Menus.cpp  |   13 +++++--
 src/insets/InsetArgument.cpp |   12 ++++---
 src/insets/InsetLayout.cpp   |    2 +-
 src/insets/InsetText.cpp     |    6 ++--
 src/output_latex.cpp         |   22 ++++++++----
 src/output_latex.h           |    2 +-
 src/tex2lyx/TODO.txt         |    4 ++
 src/version.h                |    4 +-
 17 files changed, 190 insertions(+), 35 deletions(-)


hooks/post-receive
-- 
The LyX Source Repository

Reply via email to