1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-1999 The LyX Team.
9 * This file is Copyright 1996-1999
12 * ======================================================
17 // 23/03/98 Heinrich Bauer (heinrich.bauer@t-mobil.de)
18 // Spots marked "changed Heinrich Bauer, 23/03/98" modified due to the
19 // following bug: dvi file export did not work after printing (or previewing)
20 // and vice versa as long as the same file was concerned. This happened
21 // every time the LyX-file was left unchanged between the two actions mentioned
39 #pragma implementation "buffer.h"
43 #include "bufferlist.h"
45 #include "lyx_gui_misc.h"
46 #include "LyXAction.h"
49 #include "tex-strings.h"
52 #include "minibuffer.h"
55 #include "mathed/formulamacro.h"
56 #include "insets/lyxinset.h"
57 #include "insets/inseterror.h"
58 #include "insets/insetlabel.h"
59 #include "insets/insetref.h"
60 #include "insets/inseturl.h"
61 #include "insets/insetinfo.h"
62 #include "insets/insetquotes.h"
64 #include "insets/insetlatex.h"
66 #include "insets/insetlatexaccent.h"
67 #include "insets/insetbib.h"
68 #include "insets/insetindex.h"
69 #include "insets/insetinclude.h"
70 #include "insets/insettoc.h"
71 #include "insets/insetlof.h"
72 #include "insets/insetlot.h"
73 #include "insets/insetloa.h"
74 #include "insets/insetparent.h"
75 #include "insets/insetspecialchar.h"
76 #include "insets/figinset.h"
77 #include "support/filetools.h"
78 #include "support/path.h"
84 #include "LaTeXFeatures.h"
85 #include "support/syscall.h"
86 #include "support/lyxlib.h"
87 #include "support/FileInfo.h"
91 // Uncomment this line to enable a workaround for the weird behaviour
92 // of the cursor between a displayed inset and last character
93 // at the upper line. (Alejandro 20.9.96)
94 // #define BREAK_BEFORE_INSET
96 /* Lars, when changing this file sometime in the future to a list,
97 * please check out the figinsets-sideeffects described at the
98 * beginning of figinset.C Matthias (04.07.1996)
102 // all these externs should eventually be removed.
103 extern BufferList bufferlist;
105 extern void MenuExport(Buffer *, string const &);
106 extern LyXAction lyxaction;
109 static const float LYX_FORMAT = 2.15;
111 extern int tex_code_break_column;
113 extern void FreeUpdateTimer();
116 Buffer::Buffer(string const & file, LyXRC * lyxrc, bool ronly)
118 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
120 filepath = OnlyPath(file);
124 dvi_clean_orgd = false; // Heinrich Bauer, 23/03/98
125 dvi_clean_tmpd = false; // Heinrich Bauer, 23/03/98
130 if (read_only || (lyxrc && lyxrc->use_tempdir)) {
131 tmppath = CreateBufferTmpDir();
132 } else tmppath.clear();
138 lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
139 // here the buffer should take care that it is
140 // saved properly, before it goes into the void.
142 // make sure that views using this buffer
147 if (!tmppath.empty()) {
148 DestroyBufferTmpDir(tmppath);
151 LyXParagraph * par = paragraph;
152 LyXParagraph * tmppar;
162 bool Buffer::saveParamsAsDefaults()
164 string fname = AddName(AddPath(user_lyxdir, "templates/"),
166 Buffer defaults = Buffer(fname);
168 // Use the current buffer's parameters as default
169 defaults.params = params;
171 // add an empty paragraph. Is this enough?
172 defaults.paragraph = new LyXParagraph;
174 return defaults.writeFile(defaults.filename, false);
178 /// Update window titles of all users
179 // Should work on a list
180 void Buffer::updateTitles()
182 if (users) users->owner()->updateWindowTitle();
186 /// Reset autosave timer of all users
187 // Should work on a list
188 void Buffer::resetAutosaveTimers()
190 if (users) users->owner()->resetAutosaveTimer();
194 void Buffer::fileName(string const & newfile)
196 filename = MakeAbsPath(newfile);
197 filepath = OnlyPath(filename);
198 setReadonly(IsFileWriteable(filename) == 0);
203 // Inserts a file into current document
204 bool BufferView::insertLyXFile(string const & filen)
206 // (c) CHT Software Service GmbH
209 // Insert a Lyxformat - file into current buffer
211 // Moved from lyx_cb.C (Lgb)
213 if (filen.empty()) return false;
215 string fname = MakeAbsPath(filen);
217 // check if file exist
220 if (!fi.readable()) {
221 WriteAlert(_("Error!"),
222 _("Specified file is unreadable: "),
223 MakeDisplayPath(fname, 50));
229 ifstream ifs(fname.c_str());
231 WriteAlert(_("Error!"),
232 _("Cannot open specified file: "),
233 MakeDisplayPath(fname, 50));
244 lyxerr.debug() << "Will insert file with header" << endl;
245 res = buffer()->readFile(lex, text->cursor.par);
247 lyxerr.debug() << "Will insert file without header" << endl;
248 res = buffer()->readLyXformat2(lex, text->cursor.par);
256 // candidate for move to BufferView
257 // (at least some parts in the beginning of the func)
260 // changed to be public and have one parameter
261 // if par = 0 normal behavior
262 // else insert behavior
263 // Returns false if "\the_end" is not read for formats >= 2.13. (Asger)
264 bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par)
270 char depth = 0; // signed or unsigned?
271 LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
272 LyXParagraph::footnote_kind footnotekind = LyXParagraph::FOOTNOTE;
273 bool the_end_read = false;
275 LyXParagraph * return_par = 0;
276 LyXFont font = LyXFont(LyXFont::ALL_INHERIT);
278 // If we are inserting, we cheat and get a token in advance
279 bool has_token = false;
283 par = new LyXParagraph;
285 users->text->BreakParagraph();
286 return_par = users->text->FirstParagraph();
289 // We don't want to adopt the parameters from the
290 // document we insert, so we skip until the text begins:
293 pretoken = lex.GetString();
294 if (pretoken == "\\layout") {
306 pretoken = lex.GetString();
309 // Profiling show this should give a lot: (Asger)
310 string const token = pretoken;
314 else if (token[0] != '\\') {
315 int n = token.length();
316 for (int i = 0; i < n; ++i) {
317 par->InsertChar(pos, token[i]);
318 par->SetFont(pos, font);
321 } else if (token == "\\i") {
322 inset = new InsetLatexAccent;
324 par->InsertChar(pos, LyXParagraph::META_INSET);
326 par->InsertInset(pos, inset);
327 par->SetFont(pos, font);
329 } else if (token == "\\layout") {
333 par->text.resize(par->text.size());
334 par = new LyXParagraph(par);
338 string layoutname = lex.GetString();
339 pair<bool, LyXTextClass::LayoutList::size_type> pp
340 = textclasslist.NumberOfLayout(params.textclass,
343 par->layout = pp.second;
344 } else { // layout not found
345 // use default layout "Standard" (0)
348 // Test whether the layout is obsolete.
349 LyXLayout const & layout = textclasslist.Style(params.textclass,
351 if (!layout.obsoleted_by().empty())
353 textclasslist.NumberOfLayout(params.textclass,
354 layout.obsoleted_by()).second;
355 par->footnoteflag = footnoteflag;
356 par->footnotekind = footnotekind;
358 font = LyXFont(LyXFont::ALL_INHERIT);
359 } else if (token == "\\end_float") {
363 par->text.resize(par->text.size());
364 par = new LyXParagraph(par);
366 footnotekind = LyXParagraph::FOOTNOTE;
367 footnoteflag = LyXParagraph::NO_FOOTNOTE;
370 par->layout = LYX_DUMMY_LAYOUT;
371 font = LyXFont(LyXFont::ALL_INHERIT);
372 } else if (token == "\\begin_float") {
373 tmpret = lex.FindToken(string_footnotekinds);
374 if (tmpret == -1) ++tmpret;
375 if (tmpret != LYX_LAYOUT_DEFAULT)
376 footnotekind = static_cast<LyXParagraph::footnote_kind>(tmpret); // bad
377 if (footnotekind == LyXParagraph::FOOTNOTE
378 || footnotekind == LyXParagraph::MARGIN)
379 footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
381 footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
382 } else if (token == "\\begin_deeper") {
384 } else if (token == "\\end_deeper") {
386 lex.printError("\\end_deeper: "
387 "depth is already null");
391 } else if (token == "\\begin_preamble") {
392 params.readPreamble(lex);
393 } else if (token == "\\textclass") {
395 pair<bool, LyXTextClassList::size_type> pp =
396 textclasslist.NumberOfClass(lex.GetString());
398 params.textclass = pp.second;
400 lex.printError("Unknown textclass `$$Token'");
401 params.textclass = 0;
403 if (!textclasslist.Load(params.textclass)) {
404 // if the textclass wasn't loaded properly
405 // we need to either substitute another
406 // or stop loading the file.
407 // I can substitute but I don't see how I can
408 // stop loading... ideas?? ARRae980418
409 WriteAlert(_("Textclass Loading Error!"),
410 string(_("Can't load textclass ")) +
411 textclasslist.NameOfClass(params.textclass),
412 _("-- substituting default"));
413 params.textclass = 0;
415 } else if (token == "\\options") {
417 params.options = lex.GetString();
418 } else if (token == "\\language") {
419 params.readLanguage(lex);
420 } else if (token == "\\fontencoding") {
422 } else if (token == "\\inputencoding") {
424 params.inputenc = lex.GetString();
425 } else if (token == "\\graphics") {
426 params.readGraphicsDriver(lex);
427 } else if (token == "\\fontscheme") {
429 params.fonts = lex.GetString();
430 } else if (token == "\\noindent") {
431 par->noindent = true;
432 } else if (token == "\\fill_top") {
433 par->added_space_top = VSpace(VSpace::VFILL);
434 } else if (token == "\\fill_bottom") {
435 par->added_space_bottom = VSpace(VSpace::VFILL);
436 } else if (token == "\\line_top") {
437 par->line_top = true;
438 } else if (token == "\\line_bottom") {
439 par->line_bottom = true;
440 } else if (token == "\\pagebreak_top") {
441 par->pagebreak_top = true;
442 } else if (token == "\\pagebreak_bottom") {
443 par->pagebreak_bottom = true;
444 } else if (token == "\\start_of_appendix") {
445 par->start_of_appendix = true;
446 } else if (token == "\\paragraph_separation") {
447 tmpret = lex.FindToken(string_paragraph_separation);
448 if (tmpret == -1) tmpret++;
449 if (tmpret != LYX_LAYOUT_DEFAULT)
450 params.paragraph_separation =
451 static_cast<BufferParams::PARSEP>(tmpret);
452 } else if (token == "\\defskip") {
454 params.defskip = VSpace(lex.GetString());
455 } else if (token == "\\no_isolatin1") { // obsolete
457 } else if (token == "\\no_babel") { // obsolete
459 } else if (token == "\\no_epsfig") { // obsolete
461 } else if (token == "\\epsfig") { // obsolete
462 // Indeed it is obsolete, but we HAVE to be backwards
463 // compatible until 0.14, because otherwise all figures
464 // in existing documents are irretrivably lost. (Asger)
465 params.readGraphicsDriver(lex);
466 } else if (token == "\\quotes_language") {
467 tmpret = lex.FindToken(string_quotes_language);
468 if (tmpret == -1) tmpret++;
469 if (tmpret != LYX_LAYOUT_DEFAULT) {
470 InsetQuotes::quote_language tmpl =
471 InsetQuotes::EnglishQ;
474 tmpl = InsetQuotes::EnglishQ;
477 tmpl = InsetQuotes::SwedishQ;
480 tmpl = InsetQuotes::GermanQ;
483 tmpl = InsetQuotes::PolishQ;
486 tmpl = InsetQuotes::FrenchQ;
489 tmpl = InsetQuotes::DanishQ;
492 params.quotes_language = tmpl;
494 } else if (token == "\\quotes_times") {
496 switch(lex.GetInteger()) {
498 params.quotes_times = InsetQuotes::SingleQ;
501 params.quotes_times = InsetQuotes::DoubleQ;
504 } else if (token == "\\papersize") {
508 tmpret = lex.FindToken(string_papersize);
511 tmpret = lex.FindToken(string_oldpapersize);
516 params.papersize2 = tmpret;
517 } else if (token == "\\paperpackage") {
518 tmpret = lex.FindToken(string_paperpackages);
521 params.paperpackage = BufferParams::PACKAGE_NONE;
523 params.paperpackage = tmpret;
524 } else if (token == "\\use_geometry") {
526 params.use_geometry = lex.GetInteger();
527 } else if (token == "\\use_amsmath") {
529 params.use_amsmath = lex.GetInteger();
530 } else if (token == "\\paperorientation") {
531 tmpret = lex.FindToken(string_orientation);
532 if (tmpret == -1) tmpret++;
533 if (tmpret != LYX_LAYOUT_DEFAULT)
534 params.orientation = static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
535 } else if (token == "\\paperwidth") {
537 params.paperwidth = lex.GetString();
538 } else if (token == "\\paperheight") {
540 params.paperheight = lex.GetString();
541 } else if (token == "\\leftmargin") {
543 params.leftmargin = lex.GetString();
544 } else if (token == "\\topmargin") {
546 params.topmargin = lex.GetString();
547 } else if (token == "\\rightmargin") {
549 params.rightmargin = lex.GetString();
550 } else if (token == "\\bottommargin") {
552 params.bottommargin = lex.GetString();
553 } else if (token == "\\headheight") {
555 params.headheight = lex.GetString();
556 } else if (token == "\\headsep") {
558 params.headsep = lex.GetString();
559 } else if (token == "\\footskip") {
561 params.footskip = lex.GetString();
562 } else if (token == "\\paperfontsize") {
564 params.fontsize = strip(lex.GetString());
565 } else if (token == "\\papercolumns") {
567 params.columns = lex.GetInteger();
568 } else if (token == "\\papersides") {
570 switch(lex.GetInteger()) {
572 case 1: params.sides = LyXTextClass::OneSide; break;
573 case 2: params.sides = LyXTextClass::TwoSides; break;
575 } else if (token == "\\paperpagestyle") {
577 params.pagestyle = strip(lex.GetString());
578 } else if (token == "\\bullet") {
580 int index = lex.GetInteger();
582 int temp_int = lex.GetInteger();
583 params.user_defined_bullets[index].setFont(temp_int);
584 params.temp_bullets[index].setFont(temp_int);
586 temp_int = lex.GetInteger();
587 params.user_defined_bullets[index].setCharacter(temp_int);
588 params.temp_bullets[index].setCharacter(temp_int);
590 temp_int = lex.GetInteger();
591 params.user_defined_bullets[index].setSize(temp_int);
592 params.temp_bullets[index].setSize(temp_int);
594 string temp_str = lex.GetString();
595 if (temp_str != "\\end_bullet") {
596 // this element isn't really necessary for
597 // parsing but is easier for humans
598 // to understand bullets. Put it back and
599 // set a debug message?
600 lex.printError("\\end_bullet expected, got" + temp_str);
601 //how can I put it back?
603 } else if (token == "\\bulletLaTeX") {
605 int index = lex.GetInteger();
607 string temp_str = lex.GetString(), sum_str;
608 while (temp_str != "\\end_bullet") {
609 // this loop structure is needed when user
610 // enters an empty string since the first
611 // thing returned will be the \\end_bullet
613 // if the LaTeX entry has spaces. Each element
614 // therefore needs to be read in turn
617 temp_str = lex.GetString();
619 params.user_defined_bullets[index].setText(sum_str);
620 params.temp_bullets[index].setText(sum_str);
621 } else if (token == "\\secnumdepth") {
623 params.secnumdepth = lex.GetInteger();
624 } else if (token == "\\tocdepth") {
626 params.tocdepth = lex.GetInteger();
627 } else if (token == "\\baselinestretch") { // obsolete
628 lex.nextToken(); // should not be used directly
630 // Will probably keep a kind of support just for
632 params.spacing.set(Spacing::Other, lex.GetFloat());
633 } else if (token == "\\spacing") {
635 string tmp = strip(lex.GetString());
636 if (tmp == "single") {
637 params.spacing.set(Spacing::Single);
638 } else if (tmp == "onehalf") {
639 params.spacing.set(Spacing::Onehalf);
640 } else if (tmp == "double") {
641 params.spacing.set(Spacing::Double);
642 } else if (tmp == "other") {
644 params.spacing.set(Spacing::Other,
647 lex.printError("Unknown spacing token: '$$Token'");
649 } else if (token == "\\float_placement") {
651 params.float_placement = lex.GetString();
652 } else if (token == "\\cursor") { // obsolete
653 // this is obsolete, so we just skip it.
655 } else if (token == "\\family") {
657 font.setLyXFamily(lex.GetString());
658 } else if (token == "\\series") {
660 font.setLyXSeries(lex.GetString());
661 } else if (token == "\\shape") {
663 font.setLyXShape(lex.GetString());
664 } else if (token == "\\size") {
666 font.setLyXSize(lex.GetString());
667 } else if (token == "\\latex") {
669 string tok = lex.GetString();
670 // This is dirty, but gone with LyX3. (Asger)
671 if (tok == "no_latex")
672 font.setLatex(LyXFont::OFF);
673 else if (tok == "latex")
674 font.setLatex(LyXFont::ON);
675 else if (tok == "default")
676 font.setLatex(LyXFont::INHERIT);
678 lex.printError("Unknown LaTeX font flag "
680 } else if (token == "\\emph") {
682 font.setEmph(font.setLyXMisc(lex.GetString()));
683 } else if (token == "\\bar") {
685 string tok = lex.GetString();
686 // This is dirty, but gone with LyX3. (Asger)
688 font.setUnderbar(LyXFont::ON);
689 else if (tok == "no")
690 font.setUnderbar(LyXFont::OFF);
691 else if (tok == "default")
692 font.setUnderbar(LyXFont::INHERIT);
694 lex.printError("Unknown bar font flag "
696 } else if (token == "\\noun") {
698 font.setNoun(font.setLyXMisc(lex.GetString()));
699 } else if (token == "\\color") {
701 font.setLyXColor(lex.GetString());
702 } else if (token == "\\align") {
703 tmpret = lex.FindToken(string_align);
704 if (tmpret == -1) tmpret++;
705 if (tmpret != LYX_LAYOUT_DEFAULT) { // tmpret != 99 ???
707 for (; tmpret > 0; --tmpret)
708 tmpret2 = tmpret2 * 2;
709 par->align = LyXAlignment(tmpret2);
711 } else if (token == "\\added_space_top") {
713 par->added_space_top = lex.GetString();
714 } else if (token == "\\added_space_bottom") {
716 par->added_space_bottom = lex.GetString();
717 } else if (token == "\\pextra_type") {
719 par->pextra_type = lex.GetInteger();
720 } else if (token == "\\pextra_width") {
722 par->pextra_width = lex.GetString();
723 } else if (token == "\\pextra_widthp") {
725 par->pextra_widthp = lex.GetString();
726 } else if (token == "\\pextra_alignment") {
728 par->pextra_alignment = lex.GetInteger();
729 } else if (token == "\\pextra_hfill") {
731 par->pextra_hfill = lex.GetInteger();
732 } else if (token == "\\pextra_start_minipage") {
734 par->pextra_start_minipage = lex.GetInteger();
735 } else if (token == "\\labelwidthstring") {
737 par->labelwidthstring = lex.GetString();
738 /* do not delete this token, it is still needed! */
739 } else if (token == "\\end_inset") {
740 /* simple ignore this. The insets do not have
742 // but insets should read it, it is a part of
743 //the inset isn't it? Lgb.
744 } else if (token == "\\begin_inset") {
746 tmptok = lex.GetString();
747 /* test the different insets */
748 if (tmptok == "Quotes") {
749 inset = new InsetQuotes;
751 par->InsertChar(pos, LyXParagraph::META_INSET);
752 par->InsertInset(pos, inset);
753 par->SetFont(pos, font);
755 #if 0 // should not be used any more
756 } else if (tmptok == "Latex") {
757 // This one is on its way out
759 tmptok = strip(lex.GetString());
760 //lyxerr <<string(tmptok[0]));
761 if (tmptok[0] == '\\') {
762 // then this latex is a
764 InsetCommand *tmpinset =
766 tmpinset->scanCommand(tmptok);
769 // This should not use InsetLaTexDel
770 // it should rather insert text into
771 // the paragraph and mark it as tex.
772 inset = new InsetLatex(tmptok);
774 par->InsertChar(pos, LyXParagraph::META_INSET);
775 par->InsertInset(pos, inset);
776 par->SetFont(pos, font);
779 #if 0 // should not be used any more
780 } else if (tmptok == "LatexDel") {
781 // This one is on its way out...
783 tmptok = strip(lex.GetString());
784 //lyxerr <<string(tmptok[0]));
785 if (tmptok == "\\tableofcontents") {
786 inset = new InsetTOC(this);
787 } else if (tmptok == "\\listoffigures") {
788 inset = new InsetLOF(this);
789 } else if (tmptok == "\\listoftables") {
790 inset = new InsetLOT(this);
791 } else if (tmptok == "\\listofalgorithms") {
792 inset = new InsetLOA(this);
793 } else if (contains(tmptok, "\\ref{")
794 || contains(tmptok, "\\pageref{")) {
795 inset = new InsetRef(tmptok, this);
796 } else if (contains(tmptok, "\\url{")
797 || contains(tmptok, "\\htmlurl{")) {
798 string cont, opt, tmptmptok, cmdname;
800 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
805 tmptmptok = lex.GetString();
806 if(tmptmptok[0] == '\\') {
807 if( tmptmptok == "\\backslash")
817 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
822 tmptmptok = lex.GetString();
823 if(tmptmptok[0] == '\\') {
824 if( tmptmptok == "\\backslash")
834 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
837 if(contains(tmptok, "\\url{"))
838 cmdname = string("url");
840 cmdname = string("htmlurl");
843 inset = new InsetUrl(cmdname, cont, opt);
844 } else if (tmptok[0] == '\\') {
845 // then this latex del is a
847 InsetCommand * tmpinset =
849 tmpinset->scanCommand(tmptok);
852 par->InsertChar(pos, LyXParagraph::META_INSET);
853 par->InsertInset(pos, inset);
854 par->SetFont(pos, font);
857 } else if (tmptok == "\\i") {
858 inset = new InsetLatexAccent;
860 par->InsertChar(pos, LyXParagraph::META_INSET);
861 par->InsertInset(pos, inset);
862 par->SetFont(pos, font);
864 } else if (tmptok == "FormulaMacro") {
865 inset = new InsetFormulaMacro;
867 par->InsertChar(pos, LyXParagraph::META_INSET);
868 par->InsertInset(pos, inset);
869 par->SetFont(pos, font);
871 } else if (tmptok == "Formula") {
872 inset = new InsetFormula;
874 par->InsertChar(pos, LyXParagraph::META_INSET);
875 par->InsertInset(pos, inset);
876 par->SetFont(pos, font);
878 } else if (tmptok == "Figure") {
879 inset = new InsetFig(100, 100, this);
881 par->InsertChar(pos, LyXParagraph::META_INSET);
882 par->InsertInset(pos, inset);
883 par->SetFont(pos, font);
886 } else if (tmptok == "Label") {
887 // Kept for compability. Remove in 0.13.
889 string tmp = "\\label{";
890 tmp += lex.GetString();
892 inset = new InsetLabel(tmp);
893 par->InsertChar(pos, LyXParagraph::META_INSET);
894 par->InsertInset(pos, inset);
895 par->SetFont(pos, font);
899 } else if (tmptok == "Info") {
900 inset = new InsetInfo;
902 par->InsertChar(pos, LyXParagraph::META_INSET);
903 par->InsertInset(pos, inset);
904 par->SetFont(pos, font);
906 } else if (tmptok == "Include") {
907 inset = new InsetInclude(string(), this);
909 par->InsertChar(pos, LyXParagraph::META_INSET);
910 par->InsertInset(pos, inset);
911 par->SetFont(pos, font);
913 } else if (tmptok == "LatexCommand") {
916 if (inscmd.getCmdName() == "cite") {
917 inset = new InsetCitation(inscmd.getContents(), inscmd.getOptions());
918 } else if (inscmd.getCmdName() == "bibitem") {
919 lex.printError("Wrong place for bibitem");
920 inset = inscmd.Clone();
921 } else if (inscmd.getCmdName() == "BibTeX") {
922 inset = new InsetBibtex(inscmd.getContents(), inscmd.getOptions(), this);
923 } else if (inscmd.getCmdName() == "index") {
924 inset = new InsetIndex(inscmd.getContents());
925 } else if (inscmd.getCmdName() == "include") {
926 inset = new InsetInclude(inscmd.getContents(), this);
927 } else if (inscmd.getCmdName() == "label") {
928 inset = new InsetLabel(inscmd.getCommand());
929 } else if (inscmd.getCmdName() == "url"
930 || inscmd.getCmdName() == "htmlurl") {
931 inset = new InsetUrl(inscmd.getCommand());
932 } else if (inscmd.getCmdName() == "ref"
933 || inscmd.getCmdName() == "pageref") {
934 if (!inscmd.getOptions().empty() || !inscmd.getContents().empty()) {
935 inset = new InsetRef(inscmd, this);
937 // This condition comes from a
938 // temporary solution to the latexdel
939 // ref inset that was transformed to
940 // an empty ref inset plus the body
941 // surronded by latexdel insets
943 string cont, opt, tmptmptok, cmdname;
945 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
950 tmptmptok = lex.GetString();
951 if(tmptmptok[0] == '\\') {
952 if( tmptmptok == "\\backslash")
962 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
967 tmptmptok = lex.GetString();
968 if(tmptmptok[0] == '\\') {
969 if( tmptmptok == "\\backslash")
979 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
985 cmdname = "\\" + inscmd.getCmdName();
986 cmdname += "[" + cont + "]";
987 cmdname += "{" + opt + "}";
988 inset = new InsetRef(cmdname, this);
990 } else if (inscmd.getCmdName() == "tableofcontents") {
991 inset = new InsetTOC(this);
992 } else if (inscmd.getCmdName() == "listoffigures") {
993 inset = new InsetLOF(this);
994 } else if (inscmd.getCmdName() == "listofalgorithms") {
995 inset = new InsetLOA(this);
996 } else if (inscmd.getCmdName() == "listoftables") {
997 inset = new InsetLOT(this);
998 } else if (inscmd.getCmdName() == "printindex") {
999 inset = new InsetPrintIndex(this);
1000 } else if (inscmd.getCmdName() == "lyxparent") {
1001 inset = new InsetParent(inscmd.getContents(), this);
1004 // Do we need this at all now?
1006 // The following three are only for compatibility
1007 if (inscmd.getCmdName() == "-") {
1008 inset = new InsetSpecialChar(InsetSpecialChar::HYPHENATION);
1009 } else if (inscmd.getCmdName() == "@.") {
1010 inset = new InsetSpecialChar(InsetSpecialChar::END_OF_SENTENCE);
1011 } else if (inscmd.getCmdName() == "ldots") {
1012 inset = new InsetSpecialChar(InsetSpecialChar::LDOTS);
1014 inset = inscmd.Clone();
1018 par->InsertChar(pos, LyXParagraph::META_INSET);
1019 par->InsertInset(pos, inset);
1020 par->SetFont(pos, font);
1024 } else if (token == "\\InsetQuotes") {
1025 inset = new InsetQuotes;
1027 par->InsertChar(pos, LyXParagraph::META_INSET);
1028 par->InsertInset(pos, inset);
1029 par->SetFont(pos, font);
1032 } else if (token == "\\InsetLatex") {
1033 inset = new InsetLatex;
1035 par->InsertChar(pos, LyXParagraph::META_INSET);
1036 par->InsertInset(pos, inset);
1037 par->SetFont(pos, font);
1039 } else if (token == "\\InsetLatexDel") {
1040 lex.printError(_("Warning: Ignoring Old Inset"));
1042 } else if (token == "\\InsetFormula") {
1043 inset = new InsetFormula;
1045 par->InsertChar(pos, LyXParagraph::META_INSET);
1046 par->InsertInset(pos, inset);
1047 par->SetFont(pos, font);
1049 } else if (token == "\\SpecialChar") {
1050 inset = new InsetSpecialChar;
1052 par->InsertChar(pos, LyXParagraph::META_INSET);
1053 par->InsertInset(pos, inset);
1054 par->SetFont(pos, font);
1056 } else if (token == "\\Figure") {
1057 inset = new InsetFig(100, 100, this);
1059 par->InsertChar(pos, LyXParagraph::META_INSET);
1060 par->InsertInset(pos, inset);
1061 par->SetFont(pos, font);
1063 } else if (token == "\\newline") {
1064 par->InsertChar(pos, LyXParagraph::META_NEWLINE);
1065 par->SetFont(pos, font);
1067 } else if (token == "\\LyXTable") {
1068 par->table = new LyXTable(lex);
1069 } else if (token == "\\hfill") {
1070 par->InsertChar(pos, LyXParagraph::META_HFILL);
1071 par->SetFont(pos, font);
1073 } else if (token == "\\protected_separator") {
1074 par->InsertChar(pos, LyXParagraph::META_PROTECTED_SEPARATOR);
1075 par->SetFont(pos, font);
1077 } else if (token == "\\bibitem") { // ale970302
1079 par->bibkey = new InsetBibKey;
1080 par->bibkey->Read(lex);
1081 }else if (token == "\\backslash") {
1082 par->InsertChar(pos, '\\');
1083 par->SetFont(pos, font);
1085 }else if (token == "\\the_end") {
1086 the_end_read = true;
1088 // This should be insurance for the future: (Asger)
1089 lex.printError("Unknown token `$$Token'. "
1090 "Inserting as text.");
1091 int n = token.length();
1092 for (int i = 0; i < n; ++i) {
1093 par->InsertChar(pos, token[i]);
1094 par->SetFont(pos, font);
1103 paragraph = return_par;
1105 return the_end_read;
1109 bool Buffer::readFile(LyXLex & lex, LyXParagraph * par)
1115 token = lex.GetString();
1116 if (token == "\\lyxformat") { // the first token _must_ be...
1118 format = lex.GetFloat();
1120 if (LYX_FORMAT - format > 0.05) {
1121 printf(_("Warning: need lyxformat %.2f but found %.2f\n"),
1122 LYX_FORMAT, format);
1124 if (format - LYX_FORMAT > 0.05) {
1125 printf(_("ERROR: need lyxformat %.2f but found %.2f\n"),
1126 LYX_FORMAT, format);
1128 bool the_end = readLyXformat2(lex, par);
1129 // Formats >= 2.13 support "\the_end" marker
1133 // Formats >= 2.14 changed papersize stuff
1134 if (format < 2.14) {
1143 WriteAlert(_("Warning!"),
1144 _("Reading of document is not complete"),
1145 _("Maybe the document is truncated"));
1146 // We simulate a safe reading anyways to allow
1147 // users to take the chance... (Asger)
1151 WriteAlert(_("ERROR!"),
1152 _("Old LyX file format found. "
1153 "Use LyX 0.10.x to read this!"));
1157 } else { // "\\lyxformat" not found
1158 WriteAlert(_("ERROR!"), _("Not a LyX file!"));
1161 WriteAlert(_("ERROR!"), _("Unable to read file!"));
1166 // Returns false if unsuccesful
1167 bool Buffer::writeFile(string const & fname, bool flag)
1169 // if flag is false writeFile will not create any GUI
1170 // warnings, only cerr.
1171 // Needed for autosave in background or panic save (Matthias 120496)
1173 if (read_only && (fname == filename)) {
1174 // Here we should come with a question if we should
1175 // perform the write anyway.
1177 lyxerr << _("Error! Document is read-only: ")
1180 WriteAlert(_("Error! Document is read-only: "),
1185 FileInfo finfo(fname);
1186 if (finfo.exist() && !finfo.writable()) {
1187 // Here we should come with a question if we should
1188 // try to do the save anyway. (i.e. do a chmod first)
1190 lyxerr << _("Error! Cannot write file: ")
1193 WriteFSAlert(_("Error! Cannot write file: "),
1198 ofstream ofs(fname.c_str());
1201 lyxerr << _("Error! Cannot open file: ")
1204 WriteFSAlert(_("Error! Cannot open file: "),
1208 // The top of the file should not be written by params.
1210 // write out a comment in the top of the file
1211 ofs << '#' << LYX_DOCVERSION
1212 << " created this file. For more info see http://www.lyx.org/\n";
1213 ofs.setf(ios::showpoint|ios::fixed);
1215 ofs << "\\lyxformat " << setw(4) << LYX_FORMAT << "\n";
1217 // now write out the buffer paramters.
1218 params.writeFile(ofs);
1220 char footnoteflag = 0;
1223 // this will write out all the paragraphs
1224 // using recursive descent.
1225 paragraph->writeFile(ofs, params, footnoteflag, depth);
1227 // Write marker that shows file is complete
1228 ofs << "\n\\the_end" << endl;
1230 // how to check if close went ok?
1235 void Buffer::writeFileAscii(string const & fname, int linelen)
1237 LyXFont font1, font2;
1239 char c, footnoteflag = 0, depth = 0;
1241 LyXParagraph::size_type i;
1242 int j, h, ltype = 0, ltype_depth = 0,
1243 * clen = 0, actcell = 0, actpos = 0, cell = 0, cells = 0,
1246 bool ref_printed = false;
1248 ofstream ofs(fname.c_str());
1250 WriteFSAlert(_("Error: Cannot write file:"), fname);
1254 string fname1 = TmpFileName();
1255 LyXParagraph * par = paragraph;
1259 if (par->footnoteflag != LyXParagraph::NO_FOOTNOTE ||
1261 par->previous->footnoteflag == LyXParagraph::NO_FOOTNOTE){
1263 /* begins a footnote environment ? */
1264 if (footnoteflag != par->footnoteflag) {
1265 footnoteflag = par->footnoteflag;
1267 j = strlen(string_footnotekinds[par->footnotekind])+4;
1268 if (currlinelen + j > linelen)
1271 << string_footnotekinds[par->footnotekind] << "] ";
1276 /* begins or ends a deeper area ?*/
1277 if (depth != par->depth) {
1278 if (par->depth > depth) {
1279 while (par->depth > depth) {
1284 while (par->depth < depth) {
1290 /* First write the layout */
1291 tmp = textclasslist.NameOfLayout(params.textclass, par->layout);
1292 if (tmp == "Itemize") {
1294 ltype_depth = depth+1;
1295 } else if (tmp == "Enumerate") {
1297 ltype_depth = depth+1;
1298 } else if (strstr(tmp.c_str(), "ection")) {
1300 ltype_depth = depth+1;
1301 } else if (strstr(tmp.c_str(), "aragraph")) {
1303 ltype_depth = depth+1;
1304 } else if (tmp == "Description") {
1306 ltype_depth = depth+1;
1307 } else if (tmp == "Abstract") {
1310 } else if (tmp == "Bibliography") {
1318 /* maybe some vertical spaces */
1320 /* the labelwidthstring used in lists */
1324 /* some pagebreaks? */
1328 /* what about the alignment */
1331 /* dummy layout, that means a footnote ended */
1332 footnoteflag = LyXParagraph::NO_FOOTNOTE;
1337 /* It might be a table */
1339 if (!lyxrc->ascii_roff_command.empty() &&
1340 lyxrc->ascii_roff_command != "none") {
1341 RoffAsciiTable(ofs, par);
1347 cells = par->table->columns;
1348 clen = new int [cells];
1349 memset(clen, 0, sizeof(int) * cells);
1350 for (i = 0, j = 0, h = 1; i < par->size(); ++i, ++h) {
1351 c = par->GetChar(i);
1352 if (c == LyXParagraph::META_INSET) {
1353 if ((inset = par->GetInset(i))) {
1354 ofstream fs(fname1.c_str());
1356 WriteFSAlert(_("Error: Cannot open temporary file:"), fname1);
1359 inset->Latex(fs, -1);
1360 h += fs.tellp() - 1;
1361 remove(fname1.c_str());
1363 } else if (c == LyXParagraph::META_NEWLINE) {
1367 j = (++j) % par->table->NumberOfCellsInRow(actcell);
1375 font1 = LyXFont(LyXFont::ALL_INHERIT);
1377 for (i = 0, actpos = 1; i < par->size(); ++i, ++actpos) {
1378 if (!i && !footnoteflag && !noparbreak){
1380 for(j = 0; j < depth; ++j)
1382 currlinelen = depth * 2;
1384 case 0: /* Standart */
1385 case 4: /* (Sub)Paragraph */
1386 case 5: /* Description */
1388 case 6: /* Abstract */
1389 ofs << "Abstract\n\n";
1391 case 7: /* Bibliography */
1393 ofs << "References\n\n";
1398 ofs << par->labelstring << " ";
1401 if (ltype_depth > depth) {
1402 for(j = ltype_depth - 1; j > depth; --j)
1404 currlinelen += (ltype_depth-depth)*2;
1407 for(j = 0; j < cells; ++j) {
1409 for(h = 0; h < (clen[j] + 1);
1414 for(j = 0; j < depth; ++j)
1416 currlinelen = depth * 2;
1417 if (ltype_depth > depth) {
1418 for(j = ltype_depth;
1421 currlinelen += (ltype_depth-depth)*2;
1426 font2 = par->GetFontSettings(i);
1427 if (font1.latex() != font2.latex()) {
1428 if (font2.latex() == LyXFont::OFF)
1436 c = par->GetChar(i);
1440 case LyXParagraph::META_INSET:
1441 if ((inset = par->GetInset(i))) {
1443 inset->Latex(ofs, -1);
1444 currlinelen += (ofs.tellp() - fpos);
1445 actpos += (ofs.tellp() - fpos) - 1;
1448 case LyXParagraph::META_NEWLINE:
1450 if (par->table->NumberOfCellsInRow(actcell) <= cell) {
1451 for(j = actpos; j < clen[cell-1];j++)
1454 for(j = 0; j < depth; ++j)
1456 currlinelen = depth*2;
1457 if (ltype_depth > depth) {
1458 for(j = ltype_depth; j > depth; --j)
1460 currlinelen += (ltype_depth-depth) * 2;
1462 for(j = 0; j < cells; ++j) {
1464 for(h = 0; h < (clen[j] + 1); ++h)
1468 for(j = 0; j < depth; ++j)
1470 currlinelen = depth * 2;
1471 if (ltype_depth > depth) {
1472 for(j = ltype_depth;
1475 currlinelen += (ltype_depth-depth)*2;
1481 j < clen[cell - 1]; ++j)
1487 currlinelen = actpos = 0;
1490 for(j = 0; j < depth; ++j)
1492 currlinelen = depth * 2;
1493 if (ltype_depth > depth) {
1494 for(j = ltype_depth;
1497 currlinelen += (ltype_depth - depth) * 2;
1501 case LyXParagraph::META_HFILL:
1504 case LyXParagraph::META_PROTECTED_SEPARATOR:
1511 if (currlinelen > linelen - 10
1512 && c == ' ' && i + 2 < par->size()) {
1514 for(j = 0; j < depth; ++j)
1516 currlinelen = depth * 2;
1517 if (ltype_depth > depth) {
1518 for(j = ltype_depth;
1521 currlinelen += (ltype_depth-depth)*2;
1523 } else if (c != '\0')
1526 lyxerr.debug() << "writeAsciiFile: NULL char in structure." << endl;
1532 for(j = actpos; j < clen[cell - 1]; ++j)
1535 for(j = 0; j < depth; ++j)
1537 currlinelen = depth * 2;
1538 if (ltype_depth > depth) {
1539 for(j = ltype_depth; j > depth; --j)
1541 currlinelen += (ltype_depth - depth) * 2;
1543 for(j = 0; j < cells; ++j) {
1545 for(h = 0; h < (clen[j] + 1); ++h)
1558 void Buffer::makeLaTeXFile(string const & fname,
1559 string const & original_path,
1560 bool nice, bool only_body)
1562 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
1564 // How the **** can this be needed?
1565 //params.textclass = current_view->buffer()->params.textclass;
1567 niceFile = nice; // this will be used by Insetincludes.
1569 tex_code_break_column = lyxrc->ascii_linelen;
1571 LyXTextClass const & tclass =
1572 textclasslist.TextClass(params.textclass);
1574 ofstream ofs(fname.c_str());
1576 WriteFSAlert(_("Error: Cannot open file: "), fname);
1580 // validate the buffer.
1581 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
1582 LaTeXFeatures features(tclass.numLayouts());
1584 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
1587 // The starting paragraph of the coming rows is the
1588 // first paragraph of the document. (Asger)
1589 texrow.start(paragraph, 0);
1591 string userName(getUserName());
1594 if (!only_body && nice) {
1595 LFile += "%% " LYX_DOCVERSION " created this file. "
1596 "For more info, see http://www.lyx.org/.\n";
1597 LFile += "%% Do not edit unless you really know what you are doing.\n";
1601 lyxerr.debug() << "lyx header finished" << endl;
1602 // There are a few differences between nice LaTeX and usual files:
1603 // usual is \batchmode and has a
1604 // special input@path to allow the including of figures
1605 // with either \input or \includegraphics (what figinsets do).
1606 // batchmode is not set if there is a tex_code_break_column.
1607 // In this case somebody is interested in the generated LaTeX,
1608 // so this is OK. input@path is set when the actual parameter
1609 // original_path is set. This is done for usual tex-file, but not
1610 // for nice-latex-file. (Matthias 250696)
1613 // code for usual, NOT nice-latex-file
1614 LFile += "\\batchmode\n"; // changed
1615 // from \nonstopmode
1618 if (!original_path.empty()) {
1619 LFile += "\\makeatletter\n";
1621 LFile += "\\def\\input@path{{" + original_path
1624 LFile += "\\makeatother\n";
1628 LFile += "\\documentclass";
1630 string options; // the document class options.
1632 if (tokenPos(tclass.opt_fontsize(), '|', params.fontsize) >= 0) {
1633 // only write if existing in list (and not default)
1634 options += params.fontsize;
1639 if (!params.use_geometry &&
1640 (params.paperpackage == BufferParams::PACKAGE_NONE)) {
1641 switch (params.papersize) {
1642 case BufferParams::PAPER_A4PAPER:
1643 options += "a4paper,";
1645 case BufferParams::PAPER_USLETTER:
1646 options += "letterpaper,";
1648 case BufferParams::PAPER_A5PAPER:
1649 options += "a5paper,";
1651 case BufferParams::PAPER_B5PAPER:
1652 options += "b5paper,";
1654 case BufferParams::PAPER_EXECUTIVEPAPER:
1655 options += "executivepaper,";
1657 case BufferParams::PAPER_LEGALPAPER:
1658 options += "legalpaper,";
1664 if (params.sides != tclass.sides()) {
1665 if (params.sides == 2)
1666 options += "twoside,";
1668 options += "oneside,";
1672 if (params.columns != tclass.columns()) {
1673 if (params.columns == 2)
1674 options += "twocolumn,";
1676 options += "onecolumn,";
1679 if (!params.use_geometry
1680 && params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1681 options += "landscape,";
1683 // language should be a parameter to \documentclass
1684 if (params.language != "default") {
1685 options += params.language + ',';
1688 // the user-defined options
1689 if (!params.options.empty()) {
1690 options += params.options + ',';
1693 if (!options.empty()){
1694 options = strip(options, ',');
1701 LFile += textclasslist.LatexnameOfClass(params.textclass);
1704 // end of \documentclass defs
1706 // font selection must be done before loading fontenc.sty
1707 if (params.fonts != "default") {
1708 LFile += "\\usepackage{" + params.fonts + "}\n";
1711 // this one is not per buffer
1712 if (lyxrc->fontenc != "default") {
1713 LFile += "\\usepackage[" + lyxrc->fontenc
1717 if (params.inputenc != "default") {
1718 LFile += "\\usepackage[" + params.inputenc
1723 /* at the very beginning the text parameters */
1724 if (params.paperpackage != BufferParams::PACKAGE_NONE) {
1725 switch (params.paperpackage) {
1726 case BufferParams::PACKAGE_A4:
1727 LFile += "\\usepackage{a4}\n";
1730 case BufferParams::PACKAGE_A4WIDE:
1731 LFile += "\\usepackage{a4wide}\n";
1734 case BufferParams::PACKAGE_WIDEMARGINSA4:
1735 LFile += "\\usepackage[widemargins]{a4}\n";
1740 if (params.use_geometry) {
1741 LFile += "\\usepackage{geometry}\n";
1743 LFile += "\\geometry{verbose";
1744 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1745 LFile += ",landscape";
1746 switch (params.papersize2) {
1747 case BufferParams::VM_PAPER_CUSTOM:
1748 if (!params.paperwidth.empty())
1749 LFile += ",paperwidth="
1750 + params.paperwidth;
1751 if (!params.paperheight.empty())
1752 LFile += ",paperheight="
1753 + params.paperheight;
1755 case BufferParams::VM_PAPER_USLETTER:
1756 LFile += ",letterpaper";
1758 case BufferParams::VM_PAPER_USLEGAL:
1759 LFile += ",legalpaper";
1761 case BufferParams::VM_PAPER_USEXECUTIVE:
1762 LFile += ",executivepaper";
1764 case BufferParams::VM_PAPER_A3:
1765 LFile += ",a3paper";
1767 case BufferParams::VM_PAPER_A4:
1768 LFile += ",a4paper";
1770 case BufferParams::VM_PAPER_A5:
1771 LFile += ",a5paper";
1773 case BufferParams::VM_PAPER_B3:
1774 LFile += ",b3paper";
1776 case BufferParams::VM_PAPER_B4:
1777 LFile += ",b4paper";
1779 case BufferParams::VM_PAPER_B5:
1780 LFile += ",b5paper";
1783 // default papersize ie BufferParams::VM_PAPER_DEFAULT
1784 switch (lyxrc->default_papersize) {
1785 case BufferParams::PAPER_DEFAULT: // keep compiler happy
1786 case BufferParams::PAPER_USLETTER:
1787 LFile += ",letterpaper";
1789 case BufferParams::PAPER_LEGALPAPER:
1790 LFile += ",legalpaper";
1792 case BufferParams::PAPER_EXECUTIVEPAPER:
1793 LFile += ",executivepaper";
1795 case BufferParams::PAPER_A3PAPER:
1796 LFile += ",a3paper";
1798 case BufferParams::PAPER_A4PAPER:
1799 LFile += ",a4paper";
1801 case BufferParams::PAPER_A5PAPER:
1802 LFile += ",a5paper";
1804 case BufferParams::PAPER_B5PAPER:
1805 LFile += ",b5paper";
1809 if (!params.topmargin.empty())
1810 LFile += ",tmargin=" + params.topmargin;
1811 if (!params.bottommargin.empty())
1812 LFile += ",bmargin=" + params.bottommargin;
1813 if (!params.leftmargin.empty())
1814 LFile += ",lmargin=" + params.leftmargin;
1815 if (!params.rightmargin.empty())
1816 LFile += ",rmargin=" + params.rightmargin;
1817 if (!params.headheight.empty())
1818 LFile += ",headheight=" + params.headheight;
1819 if (!params.headsep.empty())
1820 LFile += ",headsep=" + params.headsep;
1821 if (!params.footskip.empty())
1822 LFile += ",footskip=" + params.footskip;
1826 if (params.use_amsmath
1827 && !prefixIs(textclasslist.LatexnameOfClass(params.textclass), "ams")) {
1828 LFile += "\\usepackage{amsmath}\n";
1831 if (tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle) >= 0) {
1832 if (params.pagestyle == "fancy") {
1833 LFile += "\\usepackage{fancyhdr}\n";
1836 LFile += "\\pagestyle{" + params.pagestyle + "}\n";
1840 // We try to load babel late, in case it interferes
1841 // with other packages.
1842 if (params.language != "default") {
1843 LFile += "\\usepackage{babel}\n";
1847 if (params.secnumdepth != tclass.secnumdepth()) {
1848 LFile += "\\setcounter{secnumdepth}{";
1849 LFile += tostr(params.secnumdepth);
1853 if (params.tocdepth != tclass.tocdepth()) {
1854 LFile += "\\setcounter{tocdepth}{";
1855 LFile += tostr(params.tocdepth);
1860 if (params.paragraph_separation) {
1861 switch (params.defskip.kind()) {
1862 case VSpace::SMALLSKIP:
1863 LFile += "\\setlength\\parskip{\\smallskipamount}\n";
1865 case VSpace::MEDSKIP:
1866 LFile += "\\setlength\\parskip{\\medskipamount}\n";
1868 case VSpace::BIGSKIP:
1869 LFile += "\\setlength\\parskip{\\bigskipamount}\n";
1871 case VSpace::LENGTH:
1872 LFile += "\\setlength\\parskip{"
1873 + params.defskip.length().asLatexString()
1876 default: // should never happen // Then delete it.
1877 LFile += "\\setlength\\parskip{\\medskipamount}\n";
1882 LFile += "\\setlength\\parindent{0pt}\n";
1886 // Write out what we've generated so far...and reset LFile
1890 // Now insert the LyX specific LaTeX commands...
1891 string preamble, tmppreamble;
1893 // The optional packages;
1894 preamble = features.getPackages(params);
1896 // this might be useful...
1897 preamble += "\n\\makeatletter\n\n";
1899 // Some macros LyX will need
1900 tmppreamble = features.getMacros(params);
1902 if (!tmppreamble.empty()) {
1903 preamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1904 "LyX specific LaTeX commands.\n"
1905 + tmppreamble + '\n';
1908 // the text class specific preamble
1909 tmppreamble = features.getTClassPreamble(params);
1910 if (!tmppreamble.empty()) {
1911 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1912 "Textclass specific LaTeX commands.\n"
1913 + tmppreamble + '\n';
1916 /* the user-defined preamble */
1917 if (!params.preamble.empty()) {
1918 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1919 "User specified LaTeX commands.\n"
1920 + params.preamble + '\n';
1923 preamble += "\\makeatother\n\n";
1925 // Itemize bullet settings need to be last in case the user
1926 // defines their own bullets that use a package included
1927 // in the user-defined preamble -- ARRae
1928 // Actually it has to be done much later than that
1929 // since some packages like frenchb make modifications
1930 // at \begin{document} time -- JMarc
1932 for (int i = 0; i < 4; ++i) {
1933 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
1934 if (bullets_def.empty())
1935 bullets_def="\\AtBeginDocument{\n";
1936 bullets_def += " \\renewcommand{\\labelitemi";
1938 // `i' is one less than the item to modify
1945 bullets_def += "ii";
1951 bullets_def += "}{" +
1952 params.user_defined_bullets[i].getText()
1957 if (!bullets_def.empty())
1958 preamble += bullets_def + "}\n\n";
1960 for (int j = countChar(preamble, '\n'); j-- ;) {
1967 LFile += "\\begin{document}\n\n";
1971 lyxerr.debug() << "preamble finished, now the body." << endl;
1973 bool was_title = false;
1974 bool already_title = false;
1980 LyXParagraph * par = paragraph;
1986 lyxerr[Debug::LATEX] << "Error in MakeLateXFile."
1988 LyXLayout const & layout = textclasslist.Style(params.textclass,
1991 if (layout.intitle) {
1992 if (already_title) {
1993 lyxerr <<"Error in MakeLatexFile: You"
1994 " should not mix title layouts"
1995 " with normal ones." << endl;
1998 } else if (was_title && !already_title) {
1999 LFile += "\\maketitle\n";
2001 already_title = true;
2004 // We are at depth 0 so we can just use
2005 // ordinary \footnote{} generation
2006 // flag this with ftcount
2008 if (layout.isEnvironment()
2009 || par->pextra_type != LyXParagraph::PEXTRA_NONE) {
2010 par = par->TeXEnvironment(LFile, texrow,
2011 ftnote, ft_texrow, ftcount);
2013 par = par->TeXOnePar(LFile, texrow,
2014 ftnote, ft_texrow, ftcount);
2017 // Write out what we've generated...and reset LFile
2020 LFile += "\\addtocounter{footnote}{-";
2021 LFile += tostr(ftcount - 1);
2025 texrow += ft_texrow;
2030 if (loop_count == 2) {
2031 // fwrite()ing every second time through the loop
2032 // gains a few extra % of speed; going higher than
2033 // 2 will slow things down again. I'll look at
2034 // LFile.length() in a future revision. ARRae
2041 // It might be that we only have a title in this document
2042 if (was_title && !already_title) {
2043 LFile += "\\maketitle\n";
2048 LFile += "\\end{document}\n";
2051 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
2053 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
2057 // Just to be sure. (Asger)
2060 // Write out what we've generated...and reset LFile
2064 // tex_code_break_column's value is used to decide
2065 // if we are in batchmode or not (within mathed_write()
2066 // in math_write.C) so we must set it to a non-zero
2067 // value when we leave otherwise we save incorrect .lyx files.
2068 tex_code_break_column = lyxrc->ascii_linelen;
2070 // How to check if the close went ok when using fstreams
2072 lyxerr.debug() << "Finished making latex file." << endl;
2076 bool Buffer::isLatex() const
2078 return textclasslist.TextClass(params.textclass).outputType() == LATEX;
2082 bool Buffer::isLinuxDoc() const
2084 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC;
2088 bool Buffer::isLiterate() const
2090 return textclasslist.TextClass(params.textclass).outputType() == LITERATE;
2094 bool Buffer::isDocBook() const
2096 return textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2100 bool Buffer::isSGML() const
2102 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC ||
2103 textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2107 void Buffer::sgmlOpenTag(ostream & os, int depth,
2108 string const & latexname) const
2110 os << string(depth, ' ') << "<" << latexname << ">\n";
2114 void Buffer::sgmlCloseTag(ostream & os, int depth,
2115 string const & latexname) const
2117 os << string(depth, ' ') << "</" << latexname << ">\n";
2121 void Buffer::makeLinuxDocFile(string const & fname, int column)
2123 LyXParagraph * par = paragraph;
2125 string top_element = textclasslist.LatexnameOfClass(params.textclass);
2126 string environment_stack[10];
2129 int depth = 0; /* paragraph depth */
2131 ofstream ofs(fname.c_str());
2134 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2138 tex_code_break_column = column;
2141 if (params.preamble.empty()) {
2142 ofs << "<!doctype linuxdoc system>\n\n";
2145 ofs << "<!doctype linuxdoc system \n [ "
2146 << params.preamble << " \n]>\n\n";
2149 string userName(getUserName());
2150 ofs << "<!-- LinuxDoc file was created by LyX 1.0 (C) 1995-1999 "
2151 << "by <" << userName << "> " << date() << " -->\n";
2153 if(params.options.empty())
2154 sgmlOpenTag(ofs, 0, top_element);
2156 string top = top_element;
2158 top += params.options;
2159 sgmlOpenTag(ofs, 0, top);
2163 int desc_on = 0; /* description mode*/
2164 LyXLayout const & style =
2165 textclasslist.Style(users->buffer()->params.textclass,
2167 par->AutoDeleteInsets();
2169 /* treat <toc> as a special case for compatibility with old code */
2170 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2171 Inset * inset = par->GetInset(0);
2172 char lyx_code = inset->LyxCode();
2173 if (lyx_code == Inset::TOC_CODE){
2174 string temp = "toc";
2175 sgmlOpenTag(ofs, depth, temp);
2178 linuxDocHandleFootnote(ofs, par, depth);
2183 // environment tag closing
2184 for( ; depth > par->depth; --depth) {
2185 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2186 environment_stack[depth].clear();
2189 // write opening SGML tags
2190 switch(style.latextype) {
2191 case LATEX_PARAGRAPH:
2192 if(depth == par->depth
2193 && !environment_stack[depth].empty()) {
2194 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2195 environment_stack[depth].clear();
2201 sgmlOpenTag(ofs, depth, style.latexname());
2206 LinuxDocError(par, 0, _("Error : Wrong depth for LatexType Command.\n"));
2208 if (!environment_stack[depth].empty()){
2209 sgmlCloseTag(ofs, depth,
2210 environment_stack[depth]);
2214 environment_stack[depth].clear();
2215 sgmlOpenTag(ofs, depth, style.latexname());
2218 case LATEX_ENVIRONMENT:
2219 case LATEX_ITEM_ENVIRONMENT:
2220 if(depth == par->depth
2221 && environment_stack[depth] != style.latexname()
2222 && !environment_stack[depth].empty()) {
2224 sgmlCloseTag(ofs, depth,
2225 environment_stack[depth]);
2226 environment_stack[depth].clear();
2228 if (depth < par->depth) {
2230 environment_stack[depth].clear();
2232 if (environment_stack[depth] != style.latexname()) {
2235 sgmlOpenTag(ofs, depth, temp);
2237 environment_stack[depth] = style.latexname();
2238 sgmlOpenTag(ofs, depth, environment_stack[depth]);
2240 if(style.latextype == LATEX_ENVIRONMENT) break;
2242 desc_on = (style.labeltype == LABEL_MANUAL);
2249 sgmlOpenTag(ofs, depth + 1, item_name);
2252 sgmlOpenTag(ofs, depth, style.latexname());
2257 SimpleLinuxDocOnePar(ofs, par, desc_on, depth);
2260 linuxDocHandleFootnote(ofs, par, depth);
2262 while(par && par->IsDummy());
2265 /* write closing SGML tags */
2266 switch(style.latextype) {
2268 case LATEX_ENVIRONMENT:
2269 case LATEX_ITEM_ENVIRONMENT:
2272 sgmlCloseTag(ofs, depth, style.latexname());
2277 /* Close open tags */
2278 for(; depth > 0; --depth)
2279 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2281 if(!environment_stack[depth].empty())
2282 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2285 sgmlCloseTag(ofs, 0, top_element);
2288 // How to check for successful close
2292 void Buffer::linuxDocHandleFootnote(ostream & os, LyXParagraph * & par,
2295 string tag = "footnote";
2297 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2298 sgmlOpenTag(os, depth + 1, tag);
2299 SimpleLinuxDocOnePar(os, par, 0, depth + 1);
2300 sgmlCloseTag(os, depth + 1, tag);
2306 void Buffer::DocBookHandleCaption(ostream & os, string & inner_tag,
2307 int const depth, int desc_on,
2308 LyXParagraph * & par)
2310 LyXParagraph * tpar = par;
2311 string tmp_par, extra_par;
2312 while (tpar && (tpar->footnoteflag != LyXParagraph::NO_FOOTNOTE) &&
2313 (tpar->layout != textclasslist.NumberOfLayout(params.textclass,
2317 tpar->layout == textclasslist.NumberOfLayout(params.textclass,
2318 "Caption").second) {
2319 sgmlOpenTag(os, depth + 1, inner_tag);
2320 SimpleDocBookOnePar(tmp_par, extra_par, tpar,
2321 desc_on, depth + 2);
2322 tmp_par = strip(tmp_par);
2323 tmp_par = frontStrip(tmp_par);
2325 sgmlCloseTag(os, depth+1, inner_tag);
2326 if(!extra_par.empty())
2332 void Buffer::DocBookHandleFootnote(ostream & os, LyXParagraph * & par,
2335 string tag, inner_tag;
2336 string tmp_par, extra_par;
2337 bool inner_span = false;
2340 // This is not how I like to see enums. They should not be anonymous
2341 // and variables of its type should not be declared right after the
2342 // last brace. (Lgb)
2349 } last = NO_ONE, present = FOOTNOTE_LIKE;
2351 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2352 if(last == present) {
2354 if(!tmp_par.empty()) {
2357 sgmlCloseTag(os, depth+1, inner_tag);
2358 sgmlOpenTag(os, depth+1, inner_tag);
2365 if(!inner_tag.empty()) sgmlCloseTag(os, depth+1, inner_tag);
2366 if(!extra_par.empty()) os << extra_par;
2367 if(!tag.empty()) sgmlCloseTag(os, depth, tag);
2370 switch (par->footnotekind) {
2371 case LyXParagraph::FOOTNOTE:
2372 case LyXParagraph::ALGORITHM:
2375 present = FOOTNOTE_LIKE;
2378 case LyXParagraph::MARGIN:
2381 present = MARGIN_LIKE;
2384 case LyXParagraph::FIG:
2385 case LyXParagraph::WIDE_FIG:
2387 inner_tag = "title";
2391 case LyXParagraph::TAB:
2392 case LyXParagraph::WIDE_TAB:
2394 inner_tag = "title";
2399 sgmlOpenTag(os, depth, tag);
2400 if ((present == TAB_LIKE) || (present == FIG_LIKE)) {
2401 DocBookHandleCaption(os, inner_tag, depth,
2405 sgmlOpenTag(os, depth + 1, inner_tag);
2408 // ignore all caption here, we processed them above!!!
2409 if (par->layout != textclasslist.NumberOfLayout(params.textclass,
2410 "Caption").second) {
2411 SimpleDocBookOnePar(tmp_par, extra_par, par,
2412 desc_on, depth + 2);
2414 tmp_par = frontStrip(strip(tmp_par));
2420 if(!inner_tag.empty()) sgmlCloseTag(os, depth+1, inner_tag);
2421 if(!extra_par.empty()) os << extra_par;
2422 if(!tag.empty()) sgmlCloseTag(os, depth, tag);
2426 /* push a tag in a style stack */
2427 void Buffer::push_tag(ostream & os, char const * tag,
2428 int & pos, char stack[5][3])
2430 /* pop all previous tags */
2431 for (int j = pos; j >= 0; --j)
2432 os << "</" << stack[j] << ">";
2435 sprintf(stack[++pos], "%s", tag);
2438 for (int i = 0; i <= pos; ++i)
2439 os << "<" << stack[i] << ">";
2443 // pop a tag from a style stack
2444 void Buffer::pop_tag(ostream & os, char const * tag,
2445 int & pos, char stack[5][3])
2447 // pop all tags till specified one
2448 for (int j = pos; (j >= 0) && (strcmp(stack[j], tag)); --j)
2449 os << "</" << stack[j] << ">";
2452 os << "</" << tag << ">";
2454 // push all tags, but the specified one
2455 for (int i = 0; i <= pos; ++i) {
2456 os << "<" << stack[i] << ">";
2457 strcpy(stack[i - 1], stack[i]);
2463 /* handle internal paragraph parsing -- layout already processed */
2465 // checks, if newcol chars should be put into this line
2466 // writes newline, if necessary.
2468 void linux_doc_line_break(ostream & os, unsigned int & colcount,
2469 const unsigned int newcol)
2472 if (colcount > lyxrc->ascii_linelen) {
2474 colcount = newcol; // assume write after this call
2479 void Buffer::SimpleLinuxDocOnePar(ostream & os, LyXParagraph * par,
2480 int desc_on, int const /*depth*/)
2482 LyXFont font1, font2;
2485 LyXParagraph::size_type main_body;
2487 LyXLayout const & style = textclasslist.Style(params.textclass,
2490 char family_type = 0; // family font flag
2491 bool is_bold = false; // series font flag
2492 char shape_type = 0; // shape font flag
2493 bool is_em = false; // emphasis (italic) font flag
2495 int stack_num = -1; // style stack position
2496 char stack[5][3]; // style stack
2497 unsigned int char_line_count = 5; // Heuristic choice ;-)
2499 if (style.labeltype != LABEL_MANUAL)
2502 main_body = par->BeginningOfMainBody();
2504 /* gets paragraph main font */
2506 font1 = style.labelfont;
2511 /* parsing main loop */
2512 for (LyXParagraph::size_type i = 0;
2513 i < par->size(); ++i) {
2515 /* handle quote tag */
2516 if (i == main_body && !par->IsDummy()) {
2521 font2 = par->getFont(i);
2523 if (font1.family() != font2.family()) {
2524 switch(family_type) {
2526 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2527 push_tag(os, "tt", stack_num, stack);
2530 else if (font2.family() == LyXFont::SANS_FAMILY) {
2531 push_tag(os, "sf", stack_num, stack);
2536 pop_tag(os, "tt", stack_num, stack);
2537 if (font2.family() == LyXFont::SANS_FAMILY) {
2538 push_tag(os, "sf", stack_num, stack);
2546 pop_tag(os, "sf", stack_num, stack);
2547 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2548 push_tag(os, "tt", stack_num, stack);
2557 /* handle bold face */
2558 if (font1.series() != font2.series()) {
2559 if (font2.series() == LyXFont::BOLD_SERIES) {
2560 push_tag(os, "bf", stack_num, stack);
2564 pop_tag(os, "bf", stack_num, stack);
2569 /* handle italic and slanted fonts */
2570 if (font1.shape() != font2.shape()) {
2571 switch(shape_type) {
2573 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2574 push_tag(os, "it", stack_num, stack);
2577 else if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2578 push_tag(os, "sl", stack_num, stack);
2583 pop_tag(os, "it", stack_num, stack);
2584 if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2585 push_tag(os, "sl", stack_num, stack);
2593 pop_tag(os, "sl", stack_num, stack);
2594 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2595 push_tag(os, "it", stack_num, stack);
2603 /* handle <em> tag */
2604 if (font1.emph() != font2.emph()) {
2605 if (font2.emph() == LyXFont::ON) {
2606 push_tag(os, "em", stack_num, stack);
2609 pop_tag(os, "em", stack_num, stack);
2614 c = par->GetChar(i);
2616 if (font2.latex() == LyXFont::ON) {
2617 // "TeX"-Mode on == > SGML-Mode on.
2619 os << c; // see LaTeX-Generation...
2621 } else if (c == LyXParagraph::META_INSET) {
2622 inset = par->GetInset(i);
2624 inset->Linuxdoc(tmp_out);
2629 if (par->linuxDocConvertChar(c, sgml_string)
2630 && !style.free_spacing) { // in freespacing
2632 // non-breaking characters
2636 linux_doc_line_break(os, char_line_count, 6);
2641 linux_doc_line_break(os, char_line_count, 1);
2647 char_line_count += sgml_string.length();
2653 /* needed if there is an optional argument but no contents */
2654 if (main_body > 0 && main_body == par->size()) {
2658 /* pop all defined Styles */
2659 for (j = stack_num; j >= 0; --j) {
2660 linux_doc_line_break(os,
2662 3 + strlen(stack[j]));
2663 os << "</" << stack[j] << ">";
2666 /* resets description flag correctly */
2669 /* <tag> not closed... */
2670 linux_doc_line_break(os, char_line_count, 6);
2674 /* fprintf(file, "</p>");*/
2680 /* print an error message */
2681 void Buffer::LinuxDocError(LyXParagraph * par, int pos,
2682 char const * message)
2684 InsetError * new_inset;
2686 /* insert an error marker in text */
2687 new_inset = new InsetError(message);
2688 par->InsertChar(pos, LyXParagraph::META_INSET);
2689 par->InsertInset(pos, new_inset);
2692 // This constant defines the maximum number of
2693 // environment layouts that can be nesteded.
2694 // The same applies for command layouts.
2695 // These values should be more than enough.
2696 // José Matos (1999/07/22)
2698 enum { MAX_NEST_LEVEL = 25};
2700 void Buffer::makeDocBookFile(string const & fname, int column)
2702 LyXParagraph * par = paragraph;
2704 string top_element= textclasslist.LatexnameOfClass(params.textclass);
2705 string environment_stack[MAX_NEST_LEVEL];
2706 string environment_inner[MAX_NEST_LEVEL];
2707 string command_stack[MAX_NEST_LEVEL];
2708 bool command_flag= false;
2709 int command_depth= 0, command_base= 0, cmd_depth= 0;
2711 string item_name, command_name;
2712 string c_depth, c_params, tmps;
2714 int depth= 0; /* paragraph depth */
2716 tex_code_break_column = column;
2718 ofstream ofs(fname.c_str());
2720 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2726 ofs << "<!doctype " << top_element
2727 << " public \"-//OASIS//DTD DocBook V3.1//EN\"";
2729 if (params.preamble.empty())
2732 ofs << "\n [ " << params.preamble << " \n]>\n\n";
2734 ofs << "<!-- DocBook file was created by " << LYX_DOCVERSION
2735 << "\n See http://www.lyx.org/ for more information -->\n";
2737 if(params.options.empty())
2738 sgmlOpenTag(ofs, 0, top_element);
2740 string top = top_element;
2742 top += params.options;
2743 sgmlOpenTag(ofs, 0, top);
2747 int desc_on= 0; /* description mode*/
2748 LyXLayout const & style = textclasslist.Style(users->buffer()->params.textclass,
2750 par->AutoDeleteInsets();
2752 /* environment tag closing */
2753 for( ; depth > par->depth; --depth) {
2754 if(environment_inner[depth] != "!-- --") {
2755 item_name= "listitem";
2756 sgmlCloseTag(ofs, command_depth + depth,
2758 if( environment_inner[depth] == "varlistentry")
2759 sgmlCloseTag(ofs, depth+command_depth,
2760 environment_inner[depth]);
2762 sgmlCloseTag(ofs, depth + command_depth,
2763 environment_stack[depth]);
2764 environment_stack[depth].clear();
2765 environment_inner[depth].clear();
2768 if(depth == par->depth
2769 && environment_stack[depth] != style.latexname()
2770 && !environment_stack[depth].empty()) {
2771 if(environment_inner[depth] != "!-- --") {
2772 item_name= "listitem";
2773 sgmlCloseTag(ofs, command_depth+depth,
2775 if( environment_inner[depth] == "varlistentry")
2777 depth + command_depth,
2778 environment_inner[depth]);
2781 sgmlCloseTag(ofs, depth + command_depth,
2782 environment_stack[depth]);
2784 environment_stack[depth].clear();
2785 environment_inner[depth].clear();
2788 // Write opening SGML tags.
2789 switch(style.latextype) {
2790 case LATEX_PARAGRAPH:
2791 if(style.latexname() != "dummy")
2792 sgmlOpenTag(ofs, depth+command_depth,
2798 LinuxDocError(par, 0,
2799 _("Error : Wrong depth for "
2800 "LatexType Command.\n"));
2802 command_name = style.latexname();
2804 tmps = style.latexparam();
2805 c_params = split(tmps, c_depth,'|');
2807 cmd_depth= atoi(c_depth.c_str());
2810 if(cmd_depth<command_base) {
2811 for(int j = command_depth;
2812 j >= command_base; --j)
2813 if(!command_stack[j].empty())
2814 sgmlCloseTag(ofs, j, command_stack[j]);
2815 command_depth= command_base= cmd_depth;
2817 else if(cmd_depth <= command_depth) {
2818 for(int j = command_depth;
2819 j >= cmd_depth; --j)
2821 if(!command_stack[j].empty())
2822 sgmlCloseTag(ofs, j, command_stack[j]);
2823 command_depth= cmd_depth;
2826 command_depth= cmd_depth;
2829 command_depth = command_base = cmd_depth;
2830 command_flag = true;
2832 command_stack[command_depth]= command_name;
2834 // treat label as a special case for
2835 // more WYSIWYM handling.
2836 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2837 Inset * inset = par->GetInset(0);
2838 char lyx_code = inset->LyxCode();
2839 if (lyx_code == Inset::LABEL_CODE){
2840 command_name += " id=\"";
2841 command_name += (static_cast<InsetCommand *>(inset))->getContents();
2842 command_name += "\"";
2847 sgmlOpenTag(ofs, depth+command_depth, command_name);
2848 item_name = "title";
2849 sgmlOpenTag(ofs, depth + 1 + command_depth, item_name);
2852 case LATEX_ENVIRONMENT:
2853 case LATEX_ITEM_ENVIRONMENT:
2854 if (depth < par->depth) {
2856 environment_stack[depth].clear();
2859 if (environment_stack[depth] != style.latexname()) {
2860 environment_stack[depth] = style.latexname();
2861 environment_inner[depth] = "!-- --";
2862 sgmlOpenTag(ofs, depth + command_depth,
2863 environment_stack[depth]);
2865 if(environment_inner[depth] != "!-- --") {
2866 item_name= "listitem";
2868 command_depth + depth,
2870 if (environment_inner[depth] == "varlistentry")
2872 depth + command_depth,
2873 environment_inner[depth]);
2877 if(style.latextype == LATEX_ENVIRONMENT) {
2878 if(!style.latexparam().empty())
2879 sgmlOpenTag(ofs, depth + command_depth,
2880 style.latexparam());
2884 desc_on = (style.labeltype == LABEL_MANUAL);
2887 environment_inner[depth]= "varlistentry";
2889 environment_inner[depth]= "listitem";
2891 sgmlOpenTag(ofs, depth + 1 + command_depth,
2892 environment_inner[depth]);
2896 sgmlOpenTag(ofs, depth + 1 + command_depth,
2901 sgmlOpenTag(ofs, depth + 1 + command_depth,
2906 sgmlOpenTag(ofs, depth + command_depth,
2912 string tmp_par, extra_par;
2914 SimpleDocBookOnePar(tmp_par, extra_par, par, desc_on,
2915 depth + 1 + command_depth);
2919 DocBookHandleFootnote(ofs, par,
2920 depth + 1 + command_depth);
2922 while(par && par->IsDummy());
2925 /* write closing SGML tags */
2926 switch(style.latextype) {
2929 sgmlCloseTag(ofs, depth + command_depth, end_tag);
2931 case LATEX_ENVIRONMENT:
2932 if(!style.latexparam().empty())
2933 sgmlCloseTag(ofs, depth + command_depth,
2934 style.latexparam());
2936 case LATEX_ITEM_ENVIRONMENT:
2937 if(desc_on == 1) break;
2939 sgmlCloseTag(ofs, depth + 1 + command_depth, end_tag);
2941 case LATEX_PARAGRAPH:
2942 if(style.latexname() != "dummy")
2943 sgmlCloseTag(ofs, depth + command_depth,
2947 sgmlCloseTag(ofs, depth + command_depth,
2954 for(; depth >= 0; --depth) {
2955 if(!environment_stack[depth].empty()) {
2956 if(environment_inner[depth] != "!-- --") {
2957 item_name= "listitem";
2958 sgmlCloseTag(ofs, command_depth + depth,
2960 if( environment_inner[depth] == "varlistentry")
2961 sgmlCloseTag(ofs, depth + command_depth,
2962 environment_inner[depth]);
2965 sgmlCloseTag(ofs, depth + command_depth,
2966 environment_stack[depth]);
2970 for(int j = command_depth; j >= command_base; --j)
2971 if(!command_stack[j].empty())
2972 sgmlCloseTag(ofs, j, command_stack[j]);
2975 sgmlCloseTag(ofs, 0, top_element);
2978 // How to check for successful close
2982 void Buffer::SimpleDocBookOnePar(string & file, string & extra,
2983 LyXParagraph * par, int & desc_on,
2987 par->SimpleDocBookOneTablePar(file, extra, desc_on, depth);
2990 LyXFont font1, font2;
2993 LyXParagraph::size_type main_body;
2995 string emph= "emphasis";
2996 bool emph_flag= false;
2997 int char_line_count= 0;
2999 LyXLayout const & style = textclasslist.Style(params.textclass,
3002 if (style.labeltype != LABEL_MANUAL)
3005 main_body = par->BeginningOfMainBody();
3007 /* gets paragraph main font */
3009 font1 = style.labelfont;
3013 char_line_count = depth;
3014 if(!style.free_spacing)
3015 for (j= 0;j< depth;j++)
3018 /* parsing main loop */
3019 for (LyXParagraph::size_type i = 0;
3020 i < par->size(); ++i) {
3021 font2 = par->getFont(i);
3023 /* handle <emphasis> tag */
3024 if (font1.emph() != font2.emph() && i) {
3025 if (font2.emph() == LyXFont::ON) {
3026 file += "<emphasis>";
3029 file += "</emphasis>";
3034 c = par->GetChar(i);
3036 if (c == LyXParagraph::META_INSET) {
3037 inset = par->GetInset(i);
3039 inset->DocBook(tmp_out);
3041 // This code needs some explanation:
3042 // Two insets are treated specially
3043 // label if it is the first element in a command paragraph
3045 // graphics inside tables or figure floats can't go on
3046 // title (the equivalente in latex for this case is caption
3047 // and title should come first
3050 if(desc_on!= 3 || i!= 0) {
3051 if(!tmp_out.empty() && tmp_out[0] == '@') {
3053 extra += frontStrip(tmp_out, '@');
3055 file += frontStrip(tmp_out, '@');
3060 } else if (font2.latex() == LyXFont::ON) {
3061 // "TeX"-Mode on ==> SGML-Mode on.
3068 if (par->linuxDocConvertChar(c, sgml_string)
3069 && !style.free_spacing) { // in freespacing
3071 // non-breaking characters
3076 file += "</term><listitem><para>";
3084 file += sgml_string;
3090 /* needed if there is an optional argument but no contents */
3091 if (main_body > 0 && main_body == par->size()) {
3095 file += "</emphasis>";
3098 /* resets description flag correctly */
3101 /* <term> not closed... */
3109 bool BufferView::removeAutoInsets()
3111 LyXParagraph * par = buffer()->paragraph;
3113 LyXCursor cursor = text->cursor;
3114 LyXCursor tmpcursor = cursor;
3115 cursor.par = tmpcursor.par->ParFromPos(tmpcursor.pos);
3116 cursor.pos = tmpcursor.par->PositionInParFromPos(tmpcursor.pos);
3120 if (par->AutoDeleteInsets()){
3122 if (par->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE){
3123 // this is possible now, since SetCursor takes
3124 // care about footnotes
3125 text->SetCursorIntern(par, 0);
3126 text->RedoParagraphs(text->cursor,
3127 text->cursor.par->Next());
3128 text->FullRebreak();
3133 // avoid forbidden cursor positions caused by error removing
3134 if (cursor.pos > cursor.par->Last())
3135 cursor.pos = cursor.par->Last();
3136 text->SetCursorIntern(cursor.par, cursor.pos);
3142 int Buffer::runLaTeX()
3144 if (!users->text) return 0;
3148 // get LaTeX-Filename
3149 string name = getLatexName();
3151 string path = OnlyPath(filename);
3153 string org_path = path;
3154 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
3158 Path p(path); // path to LaTeX file
3159 users->owner()->getMiniBuffer()->Set(_("Running LaTeX..."));
3161 // Remove all error insets
3162 bool a = users->removeAutoInsets();
3164 // Always generate the LaTeX file
3165 makeLaTeXFile(name, org_path, false);
3168 // do the LaTex run(s)
3170 string latex_command = lyxrc->pdf_mode ?
3171 lyxrc->pdflatex_command : lyxrc->latex_command;
3172 LaTeX latex(latex_command, name, filepath);
3173 int res = latex.run(terr,
3174 users->owner()->getMiniBuffer()); // running latex
3176 // check return value from latex.run().
3177 if ((res & LaTeX::NO_LOGFILE)) {
3178 WriteAlert(_("LaTeX did not work!"),
3179 _("Missing log file:"), name);
3180 } else if ((res & LaTeX::ERRORS)) {
3181 users->owner()->getMiniBuffer()->Set(_("Done"));
3182 // Insert all errors as errors boxes
3183 users->insertErrors(terr);
3185 // Dvi should also be kept dirty if the latex run
3186 // ends up with errors. However it should be possible
3187 // to view a dirty dvi too.
3189 //no errors or any other things to think about so:
3190 users->owner()->getMiniBuffer()->Set(_("Done"));
3194 // if we removed error insets before we ran LaTeX or if we inserted
3195 // error insets after we ran LaTeX this must be run:
3196 if (a || (res & LaTeX::ERRORS)){
3199 users->updateScrollbar();
3203 return latex.getNumErrors();
3207 int Buffer::runLiterate()
3209 if (!users->text) return 0;
3213 // get LaTeX-Filename
3214 string name = getLatexName();
3215 // get Literate-Filename
3216 string lit_name = ChangeExtension (getLatexName(),
3217 lyxrc->literate_extension, true);
3219 string path = OnlyPath(filename);
3221 string org_path = path;
3222 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
3226 Path p(path); // path to Literate file
3227 users->owner()->getMiniBuffer()->Set(_("Running Literate..."));
3229 // Remove all error insets
3230 bool a = users->removeAutoInsets();
3232 // generate the Literate file if necessary
3233 if (!isDviClean() || a) {
3234 makeLaTeXFile(lit_name, org_path, false);
3238 string latex_command = lyxrc->pdf_mode ?
3239 lyxrc->pdflatex_command : lyxrc->latex_command;
3240 Literate literate(latex_command, name, filepath,
3242 lyxrc->literate_command, lyxrc->literate_error_filter,
3243 lyxrc->build_command, lyxrc->build_error_filter);
3245 int res = literate.weave(terr, users->owner()->getMiniBuffer());
3247 // check return value from literate.weave().
3248 if ((res & Literate::NO_LOGFILE)) {
3249 WriteAlert(_("Literate command did not work!"),
3250 _("Missing log file:"), name);
3251 } else if ((res & Literate::ERRORS)) {
3252 users->owner()->getMiniBuffer()->Set(_("Done"));
3253 // Insert all errors as errors boxes
3254 users->insertErrors(terr);
3256 // Dvi should also be kept dirty if the latex run
3257 // ends up with errors. However it should be possible
3258 // to view a dirty dvi too.
3260 //no errors or any other things to think about so:
3261 users->owner()->getMiniBuffer()->Set(_("Done"));
3265 // if we removed error insets before we ran LaTeX or if we inserted
3266 // error insets after we ran LaTeX this must be run:
3267 if (a || (res & Literate::ERRORS)){
3270 users->updateScrollbar();
3274 return literate.getNumErrors();
3278 int Buffer::buildProgram()
3280 if (!users->text) return 0;
3284 // get LaTeX-Filename
3285 string name = getLatexName();
3286 // get Literate-Filename
3287 string lit_name = ChangeExtension(getLatexName(),
3288 lyxrc->literate_extension, true);
3290 string path = OnlyPath(filename);
3292 string org_path = path;
3293 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
3297 Path p(path); // path to Literate file
3298 users->owner()->getMiniBuffer()->Set(_("Building Program..."));
3300 // Remove all error insets
3301 bool a = users->removeAutoInsets();
3303 // generate the LaTeX file if necessary
3304 if (!isNwClean() || a) {
3305 makeLaTeXFile(lit_name, org_path, false);
3309 string latex_command = lyxrc->pdf_mode ?
3310 lyxrc->pdflatex_command : lyxrc->latex_command;
3311 Literate literate(latex_command, name, filepath,
3313 lyxrc->literate_command, lyxrc->literate_error_filter,
3314 lyxrc->build_command, lyxrc->build_error_filter);
3316 int res = literate.build(terr, users->owner()->getMiniBuffer());
3318 // check return value from literate.build().
3319 if ((res & Literate::NO_LOGFILE)) {
3320 WriteAlert(_("Build did not work!"),
3321 _("Missing log file:"), name);
3322 } else if ((res & Literate::ERRORS)) {
3323 users->owner()->getMiniBuffer()->Set(_("Done"));
3324 // Insert all errors as errors boxes
3325 users->insertErrors(terr);
3327 // Literate files should also be kept dirty if the literate
3328 // command run ends up with errors.
3330 //no errors or any other things to think about so:
3331 users->owner()->getMiniBuffer()->Set(_("Done"));
3335 // if we removed error insets before we ran Literate/Build or if we inserted
3336 // error insets after we ran Literate/Build this must be run:
3337 if (a || (res & Literate::ERRORS)){
3340 users->updateScrollbar();
3344 return literate.getNumErrors();
3348 // This should be enabled when the Chktex class is implemented. (Asger)
3349 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
3350 // Other flags: -wall -v0 -x
3351 int Buffer::runChktex()
3353 if (!users->text) return 0;
3357 // get LaTeX-Filename
3358 string name = getLatexName();
3359 string path = OnlyPath(filename);
3361 string org_path = path;
3362 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
3366 Path p(path); // path to LaTeX file
3367 users->owner()->getMiniBuffer()->Set(_("Running chktex..."));
3369 // Remove all error insets
3370 bool a = users->removeAutoInsets();
3372 // Generate the LaTeX file if neccessary
3373 if (!isDviClean() || a) {
3374 makeLaTeXFile(name, org_path, false);
3379 Chktex chktex(lyxrc->chktex_command, name, filepath);
3380 int res = chktex.run(terr); // run chktex
3383 WriteAlert(_("chktex did not work!"),
3384 _("Could not run with file:"), name);
3385 } else if (res > 0) {
3386 // Insert all errors as errors boxes
3387 users->insertErrors(terr);
3390 // if we removed error insets before we ran chktex or if we inserted
3391 // error insets after we ran chktex, this must be run:
3395 users->updateScrollbar();
3403 void BufferView::insertErrors(TeXErrors & terr)
3405 // Save the cursor position
3406 LyXCursor cursor = text->cursor;
3408 // This is drastic, but it's the only fix, I could find. (Asger)
3412 for (TeXErrors::Errors::const_iterator cit = terr.begin();
3415 string desctext((*cit).error_desc);
3416 string errortext((*cit).error_text);
3417 string msgtxt = desctext + '\n' + errortext;
3418 int errorrow = (*cit).error_in_line;
3420 // Insert error string for row number
3424 buffer()->texrow.getIdFromRow(errorrow, tmpid, tmppos);
3426 LyXParagraph * texrowpar = 0;
3429 texrowpar = text->FirstParagraph();
3432 texrowpar = text->GetParFromID(tmpid);
3438 InsetError * new_inset = new InsetError(msgtxt);
3439 text->SetCursorIntern(texrowpar, tmppos);
3440 text->InsertInset(new_inset);
3441 text->FullRebreak();
3443 // Restore the cursor position
3444 text->SetCursorIntern(cursor.par, cursor.pos);
3448 void BufferView::setCursorFromRow(int row)
3453 buffer()->texrow.getIdFromRow(row, tmpid, tmppos);
3455 LyXParagraph * texrowpar;
3458 texrowpar = text->FirstParagraph();
3461 texrowpar = text->GetParFromID(tmpid);
3463 text->SetCursor(texrowpar, tmppos);
3467 void Buffer::RoffAsciiTable(ostream & os, LyXParagraph * par)
3469 LyXFont font1 = LyXFont(LyXFont::ALL_INHERIT);
3472 LyXParagraph::size_type i;
3476 string fname1 = TmpFileName(string(), "RAT1");
3477 string fname2 = TmpFileName(string(), "RAT2");
3479 ofstream ofs(fname1.c_str());
3481 WriteAlert(_("LYX_ERROR:"),
3482 _("Cannot open temporary file:"), fname1);
3485 par->table->RoffEndOfCell(ofs, -1);
3486 for (i = 0; i < par->size(); ++i) {
3487 c = par->GetChar(i);
3488 if (par->table->IsContRow(cell)) {
3489 if (c == LyXParagraph::META_NEWLINE)
3493 font2 = par->GetFontSettings(i);
3494 if (font1.latex() != font2.latex()) {
3495 if (font2.latex() != LyXFont::OFF)
3499 case LyXParagraph::META_INSET:
3500 if ((inset = par->GetInset(i))) {
3501 fstream fs(fname2.c_str(), ios::in|ios::out);
3503 WriteAlert(_("LYX_ERROR:"),
3504 _("Cannot open temporary file:"), fname2);
3506 remove(fname1.c_str());
3509 inset->Latex(fs, -1);
3522 case LyXParagraph::META_NEWLINE:
3523 if (par->table->CellHasContRow(cell)>= 0)
3524 par->RoffContTableRows(ofs, i+1, cell);
3525 par->table->RoffEndOfCell(ofs, cell);
3528 case LyXParagraph::META_HFILL:
3530 case LyXParagraph::META_PROTECTED_SEPARATOR:
3540 << "RoffAsciiTable:"
3541 " NULL char in structure." << endl;
3545 par->table->RoffEndOfCell(ofs, cell);
3547 string cmd = lyxrc->ascii_roff_command + " >" + fname2;
3548 cmd = subst(cmd, "$$FName", fname1);
3549 Systemcalls one(Systemcalls::System, cmd);
3550 if (!(lyxerr.debugging(Debug::ROFF))) {
3551 remove(fname1.c_str());
3553 ifstream ifs(fname2.c_str());
3555 WriteFSAlert(_("Error! Can't open temporary file:"), fname2);
3558 // now output the produced file
3562 WriteAlert(_("Error!"),
3563 _("Error executing *roff command on table"));
3564 // overread leading blank lines
3565 while(!ifs && (c == '\n'))
3568 for(j = 0; j < par->depth; ++j)
3570 while(!ifs && (c != '\n')) {
3575 // overread trailing blank lines
3576 while(!ifs && (c == '\n'))
3580 remove(fname2.c_str());
3584 /// changed Heinrich Bauer, 23/03/98
3585 bool Buffer::isDviClean()
3587 if (lyxrc->use_tempdir)
3588 return dvi_clean_tmpd;
3590 return dvi_clean_orgd;
3594 /// changed Heinrich Bauer, 23/03/98
3595 void Buffer::markDviClean()
3597 if (lyxrc->use_tempdir)
3598 dvi_clean_tmpd = true;
3600 dvi_clean_orgd = true;
3604 /// changed Heinrich Bauer, 23/03/98
3605 void Buffer::markDviDirty()
3607 if (lyxrc->use_tempdir)
3608 dvi_clean_tmpd = false;
3610 dvi_clean_orgd = false;
3614 void Buffer::validate(LaTeXFeatures & features)
3616 LyXParagraph * par = paragraph;
3617 LyXTextClass const & tclass =
3618 textclasslist.TextClass(params.textclass);
3620 // AMS Style is at document level
3622 features.amsstyle = (params.use_amsmath ||
3623 tclass.provides(LyXTextClass::amsmath));
3626 // We don't use "lyxerr.debug" because of speed. (Asger)
3627 if (lyxerr.debugging(Debug::LATEX))
3628 lyxerr << "Paragraph: " << par << endl;
3630 // Now just follow the list of paragraphs and run
3631 // validate on each of them.
3632 par->validate(features);
3634 // and then the next paragraph
3638 // the bullet shapes are buffer level not paragraph level
3639 // so they are tested here
3640 for (int i = 0; i < 4; ++i) {
3641 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
3642 int font = params.user_defined_bullets[i].getFont();
3645 .user_defined_bullets[i]
3652 features.latexsym = true;
3656 features.amssymb = true;
3658 else if ((font >= 2 && font <= 5)) {
3659 features.pifont = true;
3664 if (lyxerr.debugging(Debug::LATEX)) {
3665 features.showStruct(params);
3670 void Buffer::setPaperStuff()
3672 params.papersize = BufferParams::PAPER_DEFAULT;
3673 char c1 = params.paperpackage;
3674 if (c1 == BufferParams::PACKAGE_NONE) {
3675 char c2 = params.papersize2;
3676 if (c2 == BufferParams::VM_PAPER_USLETTER)
3677 params.papersize = BufferParams::PAPER_USLETTER;
3678 else if (c2 == BufferParams::VM_PAPER_USLEGAL)
3679 params.papersize = BufferParams::PAPER_LEGALPAPER;
3680 else if (c2 == BufferParams::VM_PAPER_USEXECUTIVE)
3681 params.papersize = BufferParams::PAPER_EXECUTIVEPAPER;
3682 else if (c2 == BufferParams::VM_PAPER_A3)
3683 params.papersize = BufferParams::PAPER_A3PAPER;
3684 else if (c2 == BufferParams::VM_PAPER_A4)
3685 params.papersize = BufferParams::PAPER_A4PAPER;
3686 else if (c2 == BufferParams::VM_PAPER_A5)
3687 params.papersize = BufferParams::PAPER_A5PAPER;
3688 else if ((c2 == BufferParams::VM_PAPER_B3) || (c2 == BufferParams::VM_PAPER_B4) ||
3689 (c2 == BufferParams::VM_PAPER_B5))
3690 params.papersize = BufferParams::PAPER_B5PAPER;
3691 } else if ((c1 == BufferParams::PACKAGE_A4) || (c1 == BufferParams::PACKAGE_A4WIDE) ||
3692 (c1 == BufferParams::PACKAGE_WIDEMARGINSA4))
3693 params.papersize = BufferParams::PAPER_A4PAPER;
3698 void Buffer::setOldPaperStuff()
3700 char c = params.papersize = params.papersize2;
3701 params.papersize2 = BufferParams::VM_PAPER_DEFAULT;
3702 params.paperpackage = BufferParams::PACKAGE_NONE;
3703 if (c == OLD_PAPER_A4PAPER)
3704 params.papersize2 = BufferParams::VM_PAPER_A4;
3705 else if (c == OLD_PAPER_A4)
3706 params.paperpackage = BufferParams::PACKAGE_A4;
3707 else if (c == OLD_PAPER_A4WIDE)
3708 params.paperpackage = BufferParams::PACKAGE_A4WIDE;
3709 else if (c == OLD_PAPER_WIDEMARGINSA4)
3710 params.paperpackage = BufferParams::PACKAGE_WIDEMARGINSA4;
3711 else if (c == OLD_PAPER_USLETTER)
3712 params.papersize2 = BufferParams::VM_PAPER_USLETTER;
3713 else if (c == OLD_PAPER_A5PAPER)
3714 params.papersize2 = BufferParams::VM_PAPER_A5;
3715 else if (c == OLD_PAPER_B5PAPER)
3716 params.papersize2 = BufferParams::VM_PAPER_B5;
3717 else if (c == OLD_PAPER_EXECUTIVEPAPER)
3718 params.papersize2 = BufferParams::VM_PAPER_USEXECUTIVE;
3719 else if (c == OLD_PAPER_LEGALPAPER)
3720 params.papersize2 = BufferParams::VM_PAPER_USLEGAL;
3726 void BufferView::insertInset(Inset * inset, string const & lout,
3729 // check for table/list in tables
3730 if (no_table && text->cursor.par->table){
3731 WriteAlert(_("Impossible Operation!"),
3732 _("Cannot insert table/list in table."),
3736 // not quite sure if we want this...
3737 text->SetCursorParUndo();
3741 if (!lout.empty()) {
3743 text->BreakParagraph();
3746 if (text->cursor.par->Last()) {
3749 text->BreakParagraph();
3753 int lay = textclasslist.NumberOfLayout(buffer()->params.textclass,
3755 if (lay == -1) // layout not found
3756 // use default layout "Standard" (0)
3759 text->SetLayout(lay);
3761 text->SetParagraph(0, 0,
3763 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3769 text->current_font.setLatex(LyXFont::OFF);
3772 text->InsertInset(inset);
3775 text->UnFreezeUndo();
3779 // Open and lock an updatable inset
3780 void BufferView::open_new_inset(UpdatableInset * new_inset)
3784 insertInset(new_inset);
3787 new_inset->Edit(0, 0);
3791 // This function should be in Buffer because it's a buffer's property (ale)
3792 string Buffer::getIncludeonlyList(char delim)
3795 LyXParagraph * par = paragraph;
3796 LyXParagraph::size_type pos;
3800 while ((inset = par->ReturnNextInsetPointer(pos))){
3801 if (inset->LyxCode() == Inset::INCLUDE_CODE) {
3802 InsetInclude * insetinc =
3803 static_cast<InsetInclude*>(inset);
3804 if (insetinc->isInclude()
3805 && insetinc->isNoLoad()) {
3808 lst += ChangeExtension(insetinc->getContents(), string(), true);
3815 lyxerr.debug() << "Includeonly(" << lst << ')' << endl;
3820 // This is also a buffer property (ale)
3821 string Buffer::getReferenceList(char delim)
3823 /// if this is a child document and the parent is already loaded
3824 /// Use the parent's list instead [ale990407]
3825 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3826 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3828 return tmp->getReferenceList(delim);
3831 LyXParagraph * par = paragraph;
3832 LyXParagraph::size_type pos;
3837 while ((inset = par->ReturnNextInsetPointer(pos))){
3838 for (int i = 0; i < inset->GetNumberOfLabels(); i++) {
3841 lst += inset->getLabel(i);
3847 lyxerr.debug() << "References(" << lst << ")" << endl;
3852 // This is also a buffer property (ale)
3853 string Buffer::getBibkeyList(char delim)
3855 /// if this is a child document and the parent is already loaded
3856 /// Use the parent's list instead [ale990412]
3857 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3858 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3860 return tmp->getBibkeyList(delim);
3864 LyXParagraph * par = paragraph;
3867 if (!bibkeys.empty())
3869 bibkeys += par->bibkey->getContents();
3874 // Might be either using bibtex or a child has bibliography
3875 if (bibkeys.empty()) {
3879 LyXParagraph::size_type pos = -1;
3881 // Search for Bibtex or Include inset
3882 while ((inset = par->ReturnNextInsetPointer(pos))) {
3883 if (inset-> LyxCode() == Inset::BIBTEX_CODE) {
3884 if (!bibkeys.empty())
3886 bibkeys += static_cast<InsetBibtex*>(inset)->getKeys(delim);
3887 } else if (inset-> LyxCode() == Inset::INCLUDE_CODE) {
3888 string bk = static_cast<InsetInclude*>(inset)->getKeys(delim);
3890 if (!bibkeys.empty())
3901 lyxerr.debug() << "Bibkeys(" << bibkeys << ")" << endl;
3906 /* This is also a buffer property (ale) */
3907 // Not so sure about that. a goto Label function can not be buffer local, just
3908 // think how this will work in a multiwindo/buffer environment, all the
3909 // cursors in all the views showing this buffer will move. (Lgb)
3910 // OK, then no cursor action should be allowed in buffer. (ale)
3911 bool BufferView::gotoLabel(string const & label)
3914 LyXParagraph * par = buffer()->paragraph;
3915 LyXParagraph::size_type pos;
3919 while ((inset = par->ReturnNextInsetPointer(pos))){
3920 for (int i = 0; i < inset->GetNumberOfLabels(); i++) {
3921 if (label == inset->getLabel(i)) {
3923 text->SetCursor(par, pos);
3924 text->sel_cursor = text->cursor;
3937 bool Buffer::isDepClean(string const & name) const
3939 DEPCLEAN * item = dep_clean;
3940 while (item && item->master != name)
3942 if (!item) return true;
3947 void Buffer::markDepClean(string const & name)
3950 dep_clean = new DEPCLEAN;
3951 dep_clean->clean = true;
3952 dep_clean->master = name;
3953 dep_clean->next = 0;
3955 DEPCLEAN* item = dep_clean;
3956 while (item && item->master != name)
3961 item = new DEPCLEAN;
3963 item->master = name;
3970 void Buffer::Dispatch(string const & command)
3972 // Split command string into command and argument
3973 string cmd, line = frontStrip(command);
3974 string arg = strip(frontStrip(split(line, cmd, ' ')));
3976 Dispatch(lyxaction.LookupFunc(cmd.c_str()), arg.c_str());
3980 void Buffer::Dispatch(int action, string const & argument)
3984 MenuExport(this, argument);
3988 lyxerr << "A truly unknown func!" << endl;