/****************************************************************************** * MODULE : edit_aux.gen.cc * DESCRIPTION: incorporate automatically generated data into text * COPYRIGHT : (C) 1999 Joris van der Hoeven ******************************************************************************* * This software falls under the GNU general public license and comes WITHOUT * ANY WARRANTY WHATSOEVER. See the file $TEXMACS_PATH/LICENSE for more details. * If you don't have this file, write to the Free Software Foundation, Inc., * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ******************************************************************************/ #include "Process/edit_process.hh" #include "analyze.hh" #include "file.hh" #include "convert.hh" #include "tm_buffer.hh" #include "merge_sort.hh" /****************************************************************************** * Constructors and destructors ******************************************************************************/ edit_process_rep::edit_process_rep (): math_input (false), message_l (""), message_r ("") {} edit_process_rep::~edit_process_rep () {} /****************************************************************************** * Automatically generate a bibliography ******************************************************************************/ void edit_process_rep::generate_bibliography ( string bib, string style, string fname) { if (debug (0)) cout << "TeXmacs] Generating bibliography" << " [" << bib << ", " << style << ", " << fname << "]\n"; int i; string bib_s; string fstyle= get_relative_file_name (buf->name, style, false); if (file_exists (fstyle * ".bst")) bib_s= "\\bibstyle{" * fstyle * "}\n"; else bib_s= "\\bibstyle{" * style * "}\n"; tree bib_t= buf->aux[bib]; for (i=0; iname, fname, false); if ((N(rel_name) >= 4) && (rel_name (N(rel_name)-4, N(rel_name)) == ".bib")) rel_name= rel_name (0, N(rel_name)- 4); bib_s << "\\bibdata{" << rel_name << "}\n"; save_string ("$TEXMACS_HOME_PATH/system/temp.aux", bib_s); system ("cd $TEXMACS_HOME_PATH/system; bibtex temp"); string result; if (load_string ("$TEXMACS_HOME_PATH/system/temp.bbl", result)) { set_message ("Error: bibtex failed to create bibliography", "compile bibliography"); return; } int count=1; tree t= latex_to_tree (result, "text"); if (is_document (t) && is_expand (t[0])) t= t[0]; if (is_document (t) && (N(t)>1) && is_expand (t[1])) t= t[1]; if (arity(t) == 0) return; if ((!is_expand (t, "thebibliography", 2)) || (!is_document (t[N(t)-1]))) return; t= t[N(t)-1]; tree u (DOCUMENT); for (i=0; ilabel); v << A (t[i] (1, N(t[i]))); u << v; } } if (N(u)>0) insert_tree (u); } /****************************************************************************** * Automatically generate table of contents ******************************************************************************/ void edit_process_rep::generate_table_of_contents (string toc) { if (debug (0)) cout << "TeXmacs] Generating table of contents [" << toc << "]\n"; tree toc_t= buf->aux[toc]; if (N(toc_t)>0) insert_tree (toc_t); } /****************************************************************************** * Automatically generate an index ******************************************************************************/ static hashmap followup (TUPLE); static string index_name_sub (tree t, bool all) { if (is_atomic (t)) { string s= t->label, r; int i, n= N(s); for (i=0; i= ' '))) r << s[i]; return r; } else if (is_concat (t)) { string r; int i, n= N(t); for (i=0; i& a, string s, hashmap& h) { // cout << "Insert recursively \t" << s << "\n"; int i= search_backwards ("\t", s); if (i != -1) { string r= s (0, i); if (!h->contains (r)) { tree u= h[s][0][0]; h (r)= tuple (copy (u (0, N(u)-1))); insert_recursively (a, s (0, i), h); } } a << s; } static void make_entry (tree& D, tree t) { // cout << "Make entry " << t << "\n"; int i, j, n= N(t); for (i=0; i h (""); for (i=0; icontains (l)) h (l)= r; else { tree rr= h[l]; if (!is_concat (rr)) rr= tree (CONCAT, rr); rr << ", " << r; h (l)= rr; } } for (i=0; icontains (l)) { int k= N(l); tree e (EXPAND, "index-" * as_string (k), copy (l[k-1]), h[l]); D << e; h->reset (l); } } } void edit_process_rep::generate_index (string idx) { if (debug (0)) cout << "TeXmacs] Generating index [" << idx << "]\n"; tree I= copy (buf->aux[idx]); if (N(I)>0) { followup= hashmap (TUPLE); int i, n= N(I); array entry (n); for (i=0; i h (TUPLE); for (i=0; icontains (name)) h (name)= tuple (value); else h (name) << value; } array new_entry; for (i=0; i0) && (entry[i] == entry[i-1])) continue; insert_recursively (new_entry, entry[i], h); } entry= new_entry; n= N(entry); tree D (DOCUMENT); for (i=0; iaux[gly]); if (N(G)>0) { int i, n= N(G); tree D (DOCUMENT); for (i=0; i=4) && (t[0] == "bibliography") && ((which == "") || (t[0] == which))) generate_bibliography (as_string (t[1]), as_string (t[2]), as_string (t[3])); if ((arity(t)>=2) && (t[0] == "table-of-contents") && ((which == "") || (t[0] == which))) generate_table_of_contents (as_string (t[1])); if ((arity(t)>=2) && (t[0] == "the-index") && ((which == "") || (t[0] == which))) generate_index (as_string (t[1])); if ((arity(t)>=2) && (t[0] == "the-glossary") && ((which == "") || (t[0] == which))) generate_glossary (as_string (t[1])); /* cout << "et= " << et << "\n"; cout << "tp= " << tp << "\n"; cout << "------------------------------------------------------\n\n\n"; */ } } void edit_process_rep::generate_aux (string which) { // path saved_path= tp; generate_aux_recursively (which, et, path()); // if (which == "") go_to (saved_path); // ... may be problematic if cursor was inside regenerated content }