From 1d6573a330791fb34541f4092cd49e4559972489 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Uwe=20St=C3=B6hr?= Date: Sun, 17 Feb 2013 06:18:42 +0100 Subject: [PATCH] tex2lyx: support for multiple indices and subindices --- src/tex2lyx/Preamble.cpp | 41 ++++++++++++-- src/tex2lyx/Preamble.h | 4 +- src/tex2lyx/TODO.txt | 2 - src/tex2lyx/test/Dummy Document.lyx | 8 +++ src/tex2lyx/test/DummyDocument.lyx | 8 +++ src/tex2lyx/test/Dummy~Document.lyx | 8 +++ src/tex2lyx/test/test-insets.lyx.lyx | 83 +++++++++++++++++++++++++++- src/tex2lyx/test/test-insets.tex | 26 ++++++++- src/tex2lyx/text.cpp | 19 ++++++- 9 files changed, 183 insertions(+), 16 deletions(-) diff --git a/src/tex2lyx/Preamble.cpp b/src/tex2lyx/Preamble.cpp index 148c9abf42..4b4bb73217 100644 --- a/src/tex2lyx/Preamble.cpp +++ b/src/tex2lyx/Preamble.cpp @@ -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_seppackage_mid_seppackage_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(); diff --git a/src/tex2lyx/Preamble.h b/src/tex2lyx/Preamble.h index e10c96d939..f86c414dfc 100644 --- a/src/tex2lyx/Preamble.h +++ b/src/tex2lyx/Preamble.h @@ -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; diff --git a/src/tex2lyx/TODO.txt b/src/tex2lyx/TODO.txt index ee197f4612..f4f9009224 100644 --- a/src/tex2lyx/TODO.txt +++ b/src/tex2lyx/TODO.txt @@ -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 diff --git a/src/tex2lyx/test/Dummy Document.lyx b/src/tex2lyx/test/Dummy Document.lyx index 22e0ee63d8..f9a4d91e8a 100644 --- a/src/tex2lyx/test/Dummy Document.lyx +++ b/src/tex2lyx/test/Dummy Document.lyx @@ -60,6 +60,14 @@ \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 diff --git a/src/tex2lyx/test/DummyDocument.lyx b/src/tex2lyx/test/DummyDocument.lyx index 948e95981d..92ec53cb32 100644 --- a/src/tex2lyx/test/DummyDocument.lyx +++ b/src/tex2lyx/test/DummyDocument.lyx @@ -60,6 +60,14 @@ \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 diff --git a/src/tex2lyx/test/Dummy~Document.lyx b/src/tex2lyx/test/Dummy~Document.lyx index a879813206..da5ab722b0 100644 --- a/src/tex2lyx/test/Dummy~Document.lyx +++ b/src/tex2lyx/test/Dummy~Document.lyx @@ -60,6 +60,14 @@ \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 diff --git a/src/tex2lyx/test/test-insets.lyx.lyx b/src/tex2lyx/test/test-insets.lyx.lyx index cbe373609b..b5dcfef22d 100644 --- a/src/tex2lyx/test/test-insets.lyx.lyx +++ b/src/tex2lyx/test/test-insets.lyx.lyx @@ -66,6 +66,14 @@ \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,7 @@ options "bibtotoc,test" \end_layout \begin_layout Standard -normal index: +undefined index: \end_layout \begin_layout Standard @@ -6269,6 +6277,79 @@ type "idx" \end_inset +\end_layout + +\begin_layout Standard +index "idx": +\end_layout + +\begin_layout Standard + +\begin_inset CommandInset index_print +LatexCommand printindex +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 diff --git a/src/tex2lyx/test/test-insets.tex b/src/tex2lyx/test/test-insets.tex index 9d70ad8108..cbbce838ae 100644 --- a/src/tex2lyx/test/test-insets.tex +++ b/src/tex2lyx/test/test-insets.tex @@ -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 diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp index 6ac1888c84..6c84024bbc 100644 --- a/src/tex2lyx/text.cpp +++ b/src/tex2lyx/text.cpp @@ -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");