]> git.lyx.org Git - features.git/commitdiff
tex2lyx: support for multiple indices and subindices
authorUwe Stöhr <uwestoehr@lyx.org>
Sun, 17 Feb 2013 05:18:42 +0000 (06:18 +0100)
committerUwe Stöhr <uwestoehr@lyx.org>
Sun, 17 Feb 2013 05:18:42 +0000 (06:18 +0100)
src/tex2lyx/Preamble.cpp
src/tex2lyx/Preamble.h
src/tex2lyx/TODO.txt
src/tex2lyx/test/Dummy Document.lyx
src/tex2lyx/test/DummyDocument.lyx
src/tex2lyx/test/Dummy~Document.lyx
src/tex2lyx/test/test-insets.lyx.lyx
src/tex2lyx/test/test-insets.tex
src/tex2lyx/text.cpp

index 148c9abf42d8c4676aff99cecb1103298bc68f18..4b4bb73217efbfbd0f797d19ff0fc52a169f04dd 100644 (file)
@@ -185,6 +185,9 @@ const char * const known_lyx_packages[] = {"amsbsy", "amsmath", "amssymb",
 "setspace", "subscript", "textcomp", "tipa", "tipx", "ulem", "url", "varioref",
 "verbatim", "wrapfig", "xunicode", 0};
 
+// used for the handling of \newindex
+int index_number = 0;
+
 // codes used to remove packages that are loaded automatically by LyX.
 // Syntax: package_beg_sep<name>package_mid_sep<package loading code>package_end_sep
 const char package_beg_sep = '\001';
@@ -469,7 +472,7 @@ Preamble::Preamble() : one_language(true), title_layout_found(false),
        h_html_be_strict          = "false";
        h_html_css_as_file        = "0";
        h_html_math_output        = "0";
-       h_index                   = "Index";
+       h_index[0]                = "Index";
        h_index_command           = "default";
        h_inputencoding           = "auto";
        h_justification           = "true";
@@ -508,7 +511,7 @@ Preamble::Preamble() : one_language(true), title_layout_found(false),
        //h_pdf_quoted_options;
        h_quotes_language         = "english";
        h_secnumdepth             = "3";
-       h_shortcut                = "idx";
+       h_shortcut[0]             = "idx";
        h_spacing                 = "single";
        h_suppress_date           = "false";
        h_textclass               = "article";
@@ -1141,10 +1144,19 @@ bool Preamble::writeLyXHeader(ostream & os, bool subdoc)
                os << "\\backgroundcolor " << h_backgroundcolor << '\n';
        if (!h_boxbgcolor.empty())
                os << "\\boxbgcolor " << h_boxbgcolor << '\n';
-       os << "\\index " << h_index << '\n'
-          << "\\shortcut " << h_shortcut << '\n'
-          << "\\color " << h_color << '\n'
-          << "\\end_index\n";
+       if (index_number != 0)
+               for (int i = 0; i < index_number; i++) {
+                       os << "\\index " << h_index[i] << '\n'
+                          << "\\shortcut " << h_shortcut[i] << '\n'
+                          << "\\color " << h_color << '\n'
+                          << "\\end_index\n";
+               }
+       else {
+               os << "\\index " << h_index[0] << '\n'
+                  << "\\shortcut " << h_shortcut[0] << '\n'
+                  << "\\color " << h_color << '\n'
+                  << "\\end_index\n";
+       }
        os << h_margins
           << "\\secnumdepth " << h_secnumdepth << "\n"
           << "\\tocdepth " << h_tocdepth << "\n"
@@ -1369,6 +1381,23 @@ void Preamble::parse(Parser & p, string const & forceclass,
                        p.setCatcode('@', catOther);
                }
 
+               else if (t.cs() == "makeindex") {
+                       // LyX will re-add this if a print index command is found
+                       p.skip_spaces();
+               }
+
+               else if (t.cs() == "newindex") {
+                       string const indexname = p.getArg('[', ']');
+                       string const shortcut = p.verbatim_item();
+                       if (!indexname.empty())
+                               h_index[index_number] = indexname;
+                       else
+                               h_index[index_number] = shortcut;
+                       h_shortcut[index_number] = shortcut;
+                       index_number += 1;
+                       p.skip_spaces();
+               }
+
                else if (t.cs() == "RS@ifundefined") {
                        string const name = p.verbatim_item();
                        string const body1 = p.verbatim_item();
index e10c96d9393780a8dc54afabcc6e0aa8c44e4006..f86c414dfccc9a3cef03a312a8921299aba6763a 100644 (file)
@@ -138,7 +138,7 @@ private:
        std::string h_html_be_strict;
        std::string h_html_css_as_file;
        std::string h_html_math_output;
-       std::string h_index;
+       std::string h_index[99];
        std::string h_index_command;
        std::string h_inputencoding;
        std::string h_justification;
@@ -178,7 +178,7 @@ private:
        std::string h_pdf_quoted_options;
        std::string h_quotes_language;
        std::string h_secnumdepth;
-       std::string h_shortcut;
+       std::string h_shortcut[99];
        std::string h_spacing;
        std::string h_suppress_date;
        std::string h_textclass;
index ee197f4612785c3ecdfe742b205358987012d79f..f4f9009224e8c3bf5886aa7500aa8cc72f3e5467 100644 (file)
@@ -29,8 +29,6 @@ Format LaTeX feature                        LyX feature
 329    master documents                     \master
 332    ?                                    InsetGraphics groupId
 343    ?                                    \use_default_options
-353    \printsubindex                       InsetIndex
-354    \printindex*, \printsubindex*        InsetIndex
 358    custom bibtex command                \bibtex_command
 358    custom makeindex command             \index_command
 363    horizontal longtable alignment       InsetTabular
index 22e0ee63d8320106537148e2b00166faa6edc847..f9a4d91e8ab0c433d6cd429da30a1fc3b57fd9fb 100644 (file)
 \shortcut idx
 \color #008000
 \end_index
+\index new
+\shortcut new
+\color #008000
+\end_index
+\index test
+\shortcut test
+\color #008000
+\end_index
 \secnumdepth 3
 \tocdepth 3
 \paragraph_separation indent
index 948e95981df015662fcb78f1735f9a14ffbb54c5..92ec53cb32627461326dffbcf78f4461754bf25a 100644 (file)
 \shortcut idx
 \color #008000
 \end_index
+\index new
+\shortcut new
+\color #008000
+\end_index
+\index test
+\shortcut test
+\color #008000
+\end_index
 \secnumdepth 3
 \tocdepth 3
 \paragraph_separation indent
index a879813206c63fc632a30868690750c43954df78..da5ab722b06229672ff7799d20fe5b9d2d23395f 100644 (file)
 \shortcut idx
 \color #008000
 \end_index
+\index new
+\shortcut new
+\color #008000
+\end_index
+\index test
+\shortcut test
+\color #008000
+\end_index
 \secnumdepth 3
 \tocdepth 3
 \paragraph_separation indent
index cbe373609b8aa9e6c161a19d6de67b8f3ac27ed5..b5dcfef22df8802998b144c3026b399b976a1954 100644 (file)
 \shortcut idx
 \color #008000
 \end_index
+\index new
+\shortcut new
+\color #008000
+\end_index
+\index test
+\shortcut test
+\color #008000
+\end_index
 \secnumdepth 3
 \tocdepth 3
 \paragraph_separation indent
@@ -6257,7 +6265,22 @@ options "bibtotoc,test"
 \end_layout
 
 \begin_layout Standard
-normal index:
+undefined index:
+\end_layout
+
+\begin_layout Standard
+
+\begin_inset CommandInset index_print
+LatexCommand printindex
+type "idx"
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Standard
+index "idx":
 \end_layout
 
 \begin_layout Standard
@@ -6269,6 +6292,64 @@ type "idx"
 \end_inset
 
 
+\end_layout
+
+\begin_layout Standard
+index "new":
+\end_layout
+
+\begin_layout Standard
+
+\begin_inset CommandInset index_print
+LatexCommand printindex
+type "new"
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Standard
+subindex "new":
+\end_layout
+
+\begin_layout Standard
+
+\begin_inset CommandInset index_print
+LatexCommand printsubindex
+type "idx"
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Standard
+index of all indices:
+\end_layout
+
+\begin_layout Standard
+
+\begin_inset CommandInset index_print
+LatexCommand printindex*
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Standard
+subindex of all indices:
+\end_layout
+
+\begin_layout Standard
+
+\begin_inset CommandInset index_print
+LatexCommand printsubindex*
+
+\end_inset
+
+
 \end_layout
 
 \begin_layout Standard
index 9d70ad8108a84a381e922b1261e2cb7ade105413..cbbce838ae566c06cc1f4952da98dad44c18c8fc 100644 (file)
@@ -21,7 +21,9 @@
 \usepackage{prettyref}
 \usepackage{splitidx}
 \makeindex
-
+\newindex[Index]{idx}
+\newindex[new]{new}
+\newindex{test}
 \usepackage{graphicx}
 \usepackage{longtable}
 \usepackage{xargs}
@@ -611,10 +613,30 @@ with \textbackslash{}addcontentsline and \textbackslash{}nocite\{{*}\}:
 \bibliography{xampl}
 
 
-normal index:
+undefined index:
 
 \printindex{}
 
+index "idx":
+
+\printindex[idx]{}
+
+index "new":
+
+\printindex[new]{}
+
+subindex "new":
+
+\printsubindex[idx]{}
+
+index of all indices:
+
+\printindex*{}
+
+subindex of all indices:
+
+\printsubindex*{}
+
 normal nomenclature:
 
 \printnomenclature hello
index 6ac1888c849656241f94a4c669e202d810f0cf04..6c84024bbcf50ea051660485044311445ea83454 100644 (file)
@@ -3526,10 +3526,23 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                        end_inset(os);
                }
 
-               else if (t.cs() == "printindex") {
+               else if (t.cs() == "printindex" || t.cs() == "printsubindex") {
                        context.check_layout(os);
-                       begin_command_inset(os, "index_print", "printindex");
-                       os << "type \"idx\"\n";
+                       string commandname = t.cs();
+                       bool star = false;
+                       if (p.next_token().asInput() == "*") {
+                               commandname += "*";
+                               star = true;
+                               p.get_token();
+                       }
+                       begin_command_inset(os, "index_print", commandname);
+                       string const indexname = p.getArg('[', ']');
+                       if (!star) {
+                               if (indexname.empty())
+                                       os << "type \"idx\"\n";
+                               else
+                                       os << "type \"" << indexname << "\"\n";
+                       }
                        end_inset(os);
                        skip_spaces_braces(p);
                        preamble.registerAutomaticallyLoadedPackage("makeidx");