#! /usr/bin/awk -f # # Inserts index entries in a LyX file for all items read from a # third file. Example of use: # # awkscr_insert_index_items indexitems - < EN-Book-noindexitems.lyx > EN-Book-indexitems.lyx # # indexitems: A file that contains the index entries (words), one per line # EN-Book-noindexitems.lyx: The file without index entries # EN-Book-indexitems.lyx: The file with index entries # # The "-" is important on the command line call, # see Chapter 8.4.3 ("A Glossary Lookup Script") of "sed & awk" # # To create a file without index entries, like EN-Book-noindexitems.lyx above, from one that # contains some, use the sedscr_delete_index_items script: # # sedscr_delete_index_items EN-Book.lyx > EN-Book-noindexitems.lyx # # To get a list of all index entries in a LyX file, use sedscr_list_index_items script: # # sedscr_list_index_items EN-Book.lyx > indexitems # Set input field separator to semicolon. BEGIN { FS = ";" } # Read index items into an associative array named "index". # The index items are held, one per line, in the indexitems file. FILENAME == "indexitems" { n++ indexentry[$1] = $1 next } /#LyX/,/\\layout Title/ { print; next } /\\begin_inset/,/\\end_inset/ { print; next } /\\SpecialChar/ { print; next } /\\layout SGML/ { layout = "SGML"; print; next } /\\layout Chapter/ { layout = "Chapter"; print; next } /\\layout Section/ { layout = "Section"; print; next } /\\layout Subsection/ { layout = "Subsection"; print; next } /\\layout Subsubsection/ { layout = "Subsubsection"; print; next } /\\layout Standard/ { layout = "Standard"; print; next } /\\layout Code/ { layout = "Code"; print; next } /\\layout Itemize/ { layout = "Itemize"; print; next } /\\layout Quotation/ { layout = "Quotation"; print; next } /\\layout Abstract/ { layout = "Abstract"; print; next } /\\layout Description/ { layout = "Description"; print; next } /\\layout Title/ { layout = "Title"; print; next } /\\layout Comment/ { layout = "Comment"; print; next } /\\layout Caption/ { layout = "Caption"; print; next } { if (layout == "Standard" || layout == "Itemize" || layout == "Quotation" || layout == "Description" ) { for (item in indexentry) { if (gsub(item "$", item "\n\\begin_inset LatexCommand \\index{" indexentry[item] "}\n\n\\end_inset \n")) { print; next } else if (gsub(item ":", item ":\n\\begin_inset LatexCommand \\index{" indexentry[item] "}\n\n\\end_inset \n")) { print; next } else if (gsub(item "\\.", item ".\n\\begin_inset LatexCommand \\index{" indexentry[item] "}\n\n\\end_inset \n")) { print; next } else if (gsub(item ",", item ",\n\\begin_inset LatexCommand \\index{" indexentry[item] "}\n\n\\end_inset \n")) { print; next } else if (gsub(item "\\?", item "?\n\\begin_inset LatexCommand \\index{" indexentry[item] "}\n\n\\end_inset \n")) { print; next } else if (gsub(item ";", item ";\n\\begin_inset LatexCommand \\index{" indexentry[item] "}\n\n\\end_inset \n")) { print; next } else if (gsub("\"" item "\"", "\"" item "\"\n\\begin_inset LatexCommand \\index{" indexentry[item] "}\n\n\\end_inset \n")) { print; next } } } } {print}