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
32 #pragma implementation "buffer.h"
36 #include "bufferlist.h"
38 #include "lyx_gui_misc.h"
41 #include "tex-strings.h"
44 #include "minibuffer.h"
46 #include "mathed/formulamacro.h"
47 #include "insets/lyxinset.h"
48 #include "insets/inseterror.h"
49 #include "insets/insetlabel.h"
50 #include "insets/insetref.h"
51 #include "insets/inseturl.h"
52 #include "insets/insetinfo.h"
53 #include "insets/insetquotes.h"
55 #include "insets/insetlatex.h"
57 #include "insets/insetlatexaccent.h"
58 #include "insets/insetbib.h"
59 #include "insets/insetindex.h"
60 #include "insets/insetinclude.h"
61 #include "insets/insettoc.h"
62 #include "insets/insetlof.h"
63 #include "insets/insetlot.h"
64 #include "insets/insetloa.h"
65 #include "insets/insetparent.h"
66 #include "insets/insetspecialchar.h"
67 #include "insets/figinset.h"
68 #include "support/filetools.h"
69 #include "support/path.h"
75 #include "LaTeXFeatures.h"
76 #include "support/syscall.h"
77 #include "support/lyxlib.h"
78 #include "support/FileInfo.h"
82 // Uncomment this line to enable a workaround for the weird behaviour
83 // of the cursor between a displayed inset and last character
84 // at the upper line. (Alejandro 20.9.96)
85 // #define BREAK_BEFORE_INSET
87 /* Lars, when changing this file sometime in the future to a list,
88 * please check out the figinsets-sideeffects described at the
89 * beginning of figinset.C Matthias (04.07.1996)
93 // all these externs should eventually be removed.
94 extern BufferList bufferlist;
95 extern void SmallUpdate(signed char);
96 extern unsigned char GetCurrentTextClass();
97 extern void BeforeChange();
99 static const float LYX_FORMAT = 2.15;
101 extern int tex_code_break_column;
103 extern void FreeUpdateTimer();
106 Buffer::Buffer(string const & file, LyXRC * lyxrc, bool ronly)
108 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
110 filepath = OnlyPath(file);
113 the_locking_inset = 0;
116 dvi_clean_orgd = false; // Heinrich Bauer, 23/03/98
117 dvi_clean_tmpd = false; // Heinrich Bauer, 23/03/98
123 if (read_only || (lyxrc && lyxrc->use_tempdir)) {
124 tmppath = CreateBufferTmpDir();
125 } else tmppath.clear();
131 lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
132 // here the buffer should take care that it is
133 // saved properly, before it goes into the void.
135 // make sure that views using this buffer
140 if (!tmppath.empty()) {
141 DestroyBufferTmpDir(tmppath);
144 LyXParagraph * par = paragraph;
145 LyXParagraph * tmppar;
156 bool Buffer::saveParamsAsDefaults()
158 string fname = AddName(AddPath(user_lyxdir, "templates/"),
160 Buffer defaults = Buffer(fname);
162 // Use the current buffer's parameters as default
163 defaults.params = params;
165 // add an empty paragraph. Is this enough?
166 defaults.paragraph = new LyXParagraph;
168 return defaults.writeFile(defaults.filename, false);
172 /// Update window titles of all users
173 // Should work on a list
174 void Buffer::updateTitles()
176 if (users) users->owner()->updateWindowTitle();
180 /// Reset autosave timer of all users
181 // Should work on a list
182 void Buffer::resetAutosaveTimers()
184 if (users) users->owner()->resetAutosaveTimer();
188 void Buffer::setFileName(string const & newfile)
190 filename = MakeAbsPath(newfile);
191 filepath = OnlyPath(filename);
192 setReadonly(IsFileWriteable(filename) == 0);
196 void Buffer::InsetUnlock()
198 if (the_locking_inset) {
199 if (!inset_slept) the_locking_inset->InsetUnlock();
200 the_locking_inset = 0;
207 // Inserts a file into current document
208 bool Buffer::insertLyXFile(string const & filen)
210 // (c) CHT Software Service GmbH
213 // Insert a Lyxformat - file into current buffer
215 // Moved from lyx_cb.C (Lgb)
217 if (filen.empty()) return false;
219 string filename = MakeAbsPath(filen);
221 // check if file exist
222 FileInfo fi(filename);
224 if (!fi.readable()) {
225 WriteAlert(_("Error!"),
226 _("Specified file is unreadable: "),
227 MakeDisplayPath(filename, 50));
233 FilePtr myfile(filename, FilePtr::read);
235 WriteAlert(_("Error!"),
236 _("Cannot open specified file: "),
237 MakeDisplayPath(filename, 50));
242 int c = fgetc(myfile());
248 lyxerr.debug() << "Will insert file with header" << endl;
249 res = readFile(lex, text->cursor.par);
251 lyxerr.debug() << "Will insert file without header" << endl;
252 res = readLyXformat2(lex, text->cursor.par);
261 // changed to be public and have one parameter
262 // if par = 0 normal behavior
263 // else insert behavior
264 // Returns false if "\the_end" is not read for formats >= 2.13. (Asger)
265 bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par)
271 char depth = 0; // signed or unsigned?
272 LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
273 LyXParagraph::footnote_kind footnotekind = LyXParagraph::FOOTNOTE;
274 bool the_end_read = false;
276 LyXParagraph * return_par = 0;
277 LyXFont font = LyXFont(LyXFont::ALL_INHERIT);
279 // If we are inserting, we cheat and get a token in advance
280 bool has_token = false;
284 par = new LyXParagraph;
286 text->BreakParagraph();
287 return_par = text->FirstParagraph();
290 // We don't want to adopt the parameters from the
291 // document we insert, so we skip until the text begins:
294 pretoken = lex.GetString();
295 if (pretoken == "\\layout") {
307 pretoken = lex.GetString();
310 // Profiling show this should give a lot: (Asger)
311 string const token = pretoken;
315 else if (token[0] != '\\') {
316 int n = token.length();
317 for (int i = 0; i < n; i++) {
318 par->InsertChar(pos, token[i]);
319 par->SetFont(pos, font);
322 } else if (token == "\\i") {
323 inset = new InsetLatexAccent;
325 par->InsertChar(pos, LyXParagraph::META_INSET);
327 par->InsertInset(pos, inset);
328 par->SetFont(pos, font);
330 } else if (token == "\\layout") {
334 par->text.resize(par->text.size());
335 par = new LyXParagraph(par);
339 string layoutname = lex.GetString();
340 pair<bool, LyXTextClass::LayoutList::size_type> pp
341 = textclasslist.NumberOfLayout(params.textclass,
344 par->layout = pp.second;
345 } else { // layout not found
346 // use default layout "Standard" (0)
349 // Test whether the layout is obsolete.
350 LyXLayout const & layout = textclasslist.Style(params.textclass,
352 if (!layout.obsoleted_by().empty())
354 textclasslist.NumberOfLayout(params.textclass,
355 layout.obsoleted_by()).second;
356 par->footnoteflag = footnoteflag;
357 par->footnotekind = footnotekind;
359 font = LyXFont(LyXFont::ALL_INHERIT);
360 } else if (token == "\\end_float") {
364 par->text.resize(par->text.size());
365 par = new LyXParagraph(par);
367 footnotekind = LyXParagraph::FOOTNOTE;
368 footnoteflag = LyXParagraph::NO_FOOTNOTE;
371 par->layout = LYX_DUMMY_LAYOUT;
372 font = LyXFont(LyXFont::ALL_INHERIT);
373 } else if (token == "\\begin_float") {
374 tmpret = lex.FindToken(string_footnotekinds);
375 if (tmpret == -1) tmpret++;
376 if (tmpret != LYX_LAYOUT_DEFAULT)
377 footnotekind = (LyXParagraph::footnote_kind)tmpret; // bad
378 if (footnotekind == LyXParagraph::FOOTNOTE
379 || footnotekind == LyXParagraph::MARGIN)
380 footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
382 footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
383 } else if (token == "\\begin_deeper") {
385 } else if (token == "\\end_deeper") {
387 lex.printError("\\end_deeper: "
388 "depth is already null");
392 } else if (token == "\\begin_preamble") {
393 params.readPreamble(lex);
394 } else if (token == "\\textclass") {
396 pair<bool, LyXTextClassList::ClassList::size_type> pp =
397 textclasslist.NumberOfClass(lex.GetString());
399 params.textclass = pp.second;
401 lex.printError("Unknown textclass `$$Token'");
402 params.textclass = 0;
404 if (!textclasslist.Load(params.textclass)) {
405 // if the textclass wasn't loaded properly
406 // we need to either substitute another
407 // or stop loading the file.
408 // I can substitute but I don't see how I can
409 // stop loading... ideas?? ARRae980418
410 WriteAlert(_("Textclass Loading Error!"),
411 string(_("Can't load textclass ")) +
412 textclasslist.NameOfClass(params.textclass),
413 _("-- substituting default"));
414 params.textclass = 0;
416 } else if (token == "\\options") {
418 params.options = lex.GetString();
419 } else if (token == "\\language") {
420 params.readLanguage(lex);
421 } else if (token == "\\fontencoding") {
423 } else if (token == "\\inputencoding") {
425 params.inputenc = lex.GetString();
426 } else if (token == "\\graphics") {
427 params.readGraphicsDriver(lex);
428 } else if (token == "\\fontscheme") {
430 params.fonts = lex.GetString();
431 } else if (token == "\\noindent") {
432 par->noindent = true;
433 } else if (token == "\\fill_top") {
434 par->added_space_top = VSpace(VSpace::VFILL);
435 } else if (token == "\\fill_bottom") {
436 par->added_space_bottom = VSpace(VSpace::VFILL);
437 } else if (token == "\\line_top") {
438 par->line_top = true;
439 } else if (token == "\\line_bottom") {
440 par->line_bottom = true;
441 } else if (token == "\\pagebreak_top") {
442 par->pagebreak_top = true;
443 } else if (token == "\\pagebreak_bottom") {
444 par->pagebreak_bottom = true;
445 } else if (token == "\\start_of_appendix") {
446 par->start_of_appendix = true;
447 } else if (token == "\\paragraph_separation") {
448 tmpret = lex.FindToken(string_paragraph_separation);
449 if (tmpret == -1) tmpret++;
450 if (tmpret != LYX_LAYOUT_DEFAULT)
451 params.paragraph_separation =
452 static_cast<BufferParams::PARSEP>(tmpret);
453 } else if (token == "\\defskip") {
455 params.defskip = VSpace(lex.GetString());
456 } else if (token == "\\no_isolatin1") {
458 } else if (token == "\\no_babel") {
460 } else if (token == "\\no_epsfig") {
462 } else if (token == "\\epsfig") { // obsolete
463 // Indeed it is obsolete, but we HAVE to be backwards
464 // compatible until 0.14, because otherwise all figures
465 // in existing documents are irretrivably lost. (Asger)
466 params.readGraphicsDriver(lex);
467 } else if (token == "\\quotes_language") {
468 tmpret = lex.FindToken(string_quotes_language);
469 if (tmpret == -1) tmpret++;
470 if (tmpret != LYX_LAYOUT_DEFAULT) {
471 InsetQuotes::quote_language tmpl =
472 InsetQuotes::EnglishQ;
475 tmpl = InsetQuotes::EnglishQ;
478 tmpl = InsetQuotes::SwedishQ;
481 tmpl = InsetQuotes::GermanQ;
484 tmpl = InsetQuotes::PolishQ;
487 tmpl = InsetQuotes::FrenchQ;
490 tmpl = InsetQuotes::DanishQ;
493 params.quotes_language = tmpl;
495 } else if (token == "\\quotes_times") {
497 switch(lex.GetInteger()) {
499 params.quotes_times = InsetQuotes::SingleQ;
502 params.quotes_times = InsetQuotes::DoubleQ;
505 } else if (token == "\\papersize") {
509 tmpret = lex.FindToken(string_papersize);
512 tmpret = lex.FindToken(string_oldpapersize);
517 params.papersize2 = tmpret;
518 } else if (token == "\\paperpackage") {
519 tmpret = lex.FindToken(string_paperpackages);
522 params.paperpackage = BufferParams::PACKAGE_NONE;
524 params.paperpackage = tmpret;
525 } else if (token == "\\use_geometry") {
527 params.use_geometry = lex.GetInteger();
528 } else if (token == "\\use_amsmath") {
530 params.use_amsmath = lex.GetInteger();
531 } else if (token == "\\paperorientation") {
532 tmpret = lex.FindToken(string_orientation);
533 if (tmpret == -1) tmpret++;
534 if (tmpret != LYX_LAYOUT_DEFAULT)
535 params.orientation = static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
536 } else if (token == "\\paperwidth") {
538 params.paperwidth = lex.GetString();
539 } else if (token == "\\paperheight") {
541 params.paperheight = lex.GetString();
542 } else if (token == "\\leftmargin") {
544 params.leftmargin = lex.GetString();
545 } else if (token == "\\topmargin") {
547 params.topmargin = lex.GetString();
548 } else if (token == "\\rightmargin") {
550 params.rightmargin = lex.GetString();
551 } else if (token == "\\bottommargin") {
553 params.bottommargin = lex.GetString();
554 } else if (token == "\\headheight") {
556 params.headheight = lex.GetString();
557 } else if (token == "\\headsep") {
559 params.headsep = lex.GetString();
560 } else if (token == "\\footskip") {
562 params.footskip = lex.GetString();
563 } else if (token == "\\paperfontsize") {
565 params.fontsize = strip(lex.GetString());
566 } else if (token == "\\papercolumns") {
568 params.columns = lex.GetInteger();
569 } else if (token == "\\papersides") {
571 switch(lex.GetInteger()) {
573 case 1: params.sides = LyXTextClass::OneSide; break;
574 case 2: params.sides = LyXTextClass::TwoSides; break;
576 } else if (token == "\\paperpagestyle") {
578 params.pagestyle = strip(lex.GetString());
579 } else if (token == "\\bullet") {
581 int index = lex.GetInteger();
583 int temp_int = lex.GetInteger();
584 params.user_defined_bullets[index].setFont(temp_int);
585 params.temp_bullets[index].setFont(temp_int);
587 temp_int = lex.GetInteger();
588 params.user_defined_bullets[index].setCharacter(temp_int);
589 params.temp_bullets[index].setCharacter(temp_int);
591 temp_int = lex.GetInteger();
592 params.user_defined_bullets[index].setSize(temp_int);
593 params.temp_bullets[index].setSize(temp_int);
595 string temp_str = lex.GetString();
596 if (temp_str != "\\end_bullet") {
597 // this element isn't really necessary for
598 // parsing but is easier for humans
599 // to understand bullets. Put it back and
600 // set a debug message?
601 lex.printError("\\end_bullet expected, got" + temp_str);
602 //how can I put it back?
604 } else if (token == "\\bulletLaTeX") {
606 int index = lex.GetInteger();
608 string temp_str = lex.GetString(), sum_str;
609 while (temp_str != "\\end_bullet") {
610 // this loop structure is needed when user
611 // enters an empty string since the first
612 // thing returned will be the \\end_bullet
614 // if the LaTeX entry has spaces. Each element
615 // therefore needs to be read in turn
618 temp_str = lex.GetString();
620 params.user_defined_bullets[index].setText(sum_str);
621 params.temp_bullets[index].setText(sum_str);
622 } else if (token == "\\secnumdepth") {
624 params.secnumdepth = lex.GetInteger();
625 } else if (token == "\\tocdepth") {
627 params.tocdepth = lex.GetInteger();
628 } else if (token == "\\baselinestretch") { // now obsolete
629 lex.nextToken(); // should not be used directly
631 // Will probably keep a kind of support just for
633 params.spacing.set(Spacing::Other, lex.GetFloat());
634 } else if (token == "\\spacing") {
636 string tmp = strip(lex.GetString());
637 if (tmp == "single") {
638 params.spacing.set(Spacing::Single);
639 } else if (tmp == "onehalf") {
640 params.spacing.set(Spacing::Onehalf);
641 } else if (tmp == "double") {
642 params.spacing.set(Spacing::Double);
643 } else if (tmp == "other") {
645 params.spacing.set(Spacing::Other,
648 lex.printError("Unknown spacing token: '$$Token'");
650 } else if (token == "\\float_placement") {
652 params.float_placement = lex.GetString();
653 } else if (token == "\\cursor") {
654 // this is obsolete, so we just skip it.
656 } else if (token == "\\family") {
658 font.setLyXFamily(lex.GetString());
659 } else if (token == "\\series") {
661 font.setLyXSeries(lex.GetString());
662 } else if (token == "\\shape") {
664 font.setLyXShape(lex.GetString());
665 } else if (token == "\\size") {
667 font.setLyXSize(lex.GetString());
668 } else if (token == "\\latex") {
670 string tok = lex.GetString();
671 // This is dirty, but gone with LyX3. (Asger)
672 if (tok == "no_latex")
673 font.setLatex(LyXFont::OFF);
674 else if (tok == "latex")
675 font.setLatex(LyXFont::ON);
676 else if (tok == "default")
677 font.setLatex(LyXFont::INHERIT);
679 lex.printError("Unknown LaTeX font flag "
681 } else if (token == "\\emph") {
683 font.setEmph(font.setLyXMisc(lex.GetString()));
684 } else if (token == "\\bar") {
686 string tok = lex.GetString();
687 // This is dirty, but gone with LyX3. (Asger)
689 font.setUnderbar(LyXFont::ON);
690 else if (tok == "no")
691 font.setUnderbar(LyXFont::OFF);
692 else if (tok == "default")
693 font.setUnderbar(LyXFont::INHERIT);
695 lex.printError("Unknown bar font flag "
697 } else if (token == "\\noun") {
699 font.setNoun(font.setLyXMisc(lex.GetString()));
700 } else if (token == "\\color") {
702 font.setLyXColor(lex.GetString());
703 } else if (token == "\\align") {
704 tmpret = lex.FindToken(string_align);
705 if (tmpret == -1) tmpret++;
706 if (tmpret != LYX_LAYOUT_DEFAULT) {
708 for (; tmpret>0; tmpret--)
709 tmpret2 = tmpret2 * 2;
710 par->align = LyXAlignment(tmpret2);
712 } else if (token == "\\added_space_top"){
714 par->added_space_top = lex.GetString();
715 } else if (token == "\\added_space_bottom") {
717 par->added_space_bottom = lex.GetString();
718 } else if (token == "\\pextra_type") {
720 par->pextra_type = lex.GetInteger();
721 } else if (token == "\\pextra_width") {
723 par->pextra_width = lex.GetString();
724 } else if (token == "\\pextra_widthp") {
726 par->pextra_widthp = lex.GetString();
727 } else if (token == "\\pextra_alignment") {
729 par->pextra_alignment = lex.GetInteger();
730 } else if (token == "\\pextra_hfill") {
732 par->pextra_hfill = lex.GetInteger();
733 } else if (token == "\\pextra_start_minipage") {
735 par->pextra_start_minipage = lex.GetInteger();
736 } else if (token == "\\labelwidthstring") {
738 par->labelwidthstring = lex.GetString();
739 /* do not delete this token, it is still needed! */
740 } else if (token == "\\end_inset") {
741 /* simple ignore this. The insets do not have
743 // but insets should read it, it is a part of
744 //the inset isn't it? Lgb.
745 } else if (token == "\\begin_inset") {
747 tmptok = lex.GetString();
748 /* test the different insets */
749 if (tmptok == "Quotes") {
750 inset = new InsetQuotes;
752 par->InsertChar(pos, LyXParagraph::META_INSET);
753 par->InsertInset(pos, inset);
754 par->SetFont(pos, font);
756 #if 0 // should not be used any more
757 } else if (tmptok == "Latex") {
758 // This one is on its way out
760 tmptok = strip(lex.GetString());
761 //lyxerr <<string(tmptok[0]));
762 if (tmptok[0] == '\\') {
763 // then this latex is a
765 InsetCommand *tmpinset =
767 tmpinset->scanCommand(tmptok);
770 // This should not use InsetLaTexDel
771 // it should rather insert text into
772 // the paragraph and mark it as tex.
773 inset = new InsetLatex(tmptok);
775 par->InsertChar(pos, LyXParagraph::META_INSET);
776 par->InsertInset(pos, inset);
777 par->SetFont(pos, font);
780 #if 0 // should not be used any more
781 } else if (tmptok == "LatexDel") {
782 // This one is on its way out...
784 tmptok = strip(lex.GetString());
785 //lyxerr <<string(tmptok[0]));
786 if (tmptok == "\\tableofcontents") {
787 inset = new InsetTOC(this);
788 } else if (tmptok == "\\listoffigures") {
789 inset = new InsetLOF(this);
790 } else if (tmptok == "\\listoftables") {
791 inset = new InsetLOT(this);
792 } else if (tmptok == "\\listofalgorithms") {
793 inset = new InsetLOA(this);
794 } else if (contains(tmptok, "\\ref{")
795 || contains(tmptok, "\\pageref{")) {
796 inset = new InsetRef(tmptok, this);
797 } else if (contains(tmptok, "\\url{")
798 || contains(tmptok, "\\htmlurl{")) {
799 string cont, opt, tmptmptok, cmdname;
801 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
806 tmptmptok = lex.GetString();
807 if(tmptmptok[0] == '\\') {
808 if( tmptmptok == "\\backslash")
818 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
823 tmptmptok = lex.GetString();
824 if(tmptmptok[0] == '\\') {
825 if( tmptmptok == "\\backslash")
835 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
838 if(contains(tmptok, "\\url{"))
839 cmdname = string("url");
841 cmdname = string("htmlurl");
844 inset = new InsetUrl(cmdname, cont, opt);
845 } else if (tmptok[0] == '\\') {
846 // then this latex del is a
848 InsetCommand * tmpinset =
850 tmpinset->scanCommand(tmptok);
853 par->InsertChar(pos, LyXParagraph::META_INSET);
854 par->InsertInset(pos, inset);
855 par->SetFont(pos, font);
858 } else if (tmptok == "\\i") {
859 inset = new InsetLatexAccent;
861 par->InsertChar(pos, LyXParagraph::META_INSET);
862 par->InsertInset(pos, inset);
863 par->SetFont(pos, font);
865 } else if (tmptok == "FormulaMacro") {
866 inset = new InsetFormulaMacro;
868 par->InsertChar(pos, LyXParagraph::META_INSET);
869 par->InsertInset(pos, inset);
870 par->SetFont(pos, font);
872 } else if (tmptok == "Formula") {
873 inset = new InsetFormula;
875 par->InsertChar(pos, LyXParagraph::META_INSET);
876 par->InsertInset(pos, inset);
877 par->SetFont(pos, font);
879 } else if (tmptok == "Figure") {
880 inset = new InsetFig(100, 100, this);
882 par->InsertChar(pos, LyXParagraph::META_INSET);
883 par->InsertInset(pos, inset);
884 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);
898 } else if (tmptok == "Info") {
899 inset = new InsetInfo;
901 par->InsertChar(pos, LyXParagraph::META_INSET);
902 par->InsertInset(pos, inset);
903 par->SetFont(pos, font);
905 } else if (tmptok == "Include") {
906 inset = new InsetInclude(string(), this);
908 par->InsertChar(pos, LyXParagraph::META_INSET);
909 par->InsertInset(pos, inset);
910 par->SetFont(pos, font);
912 } else if (tmptok == "LatexCommand") {
915 if (inscmd.getCmdName() == "cite") {
916 inset = new InsetCitation(inscmd.getContents(), inscmd.getOptions());
917 } else if (inscmd.getCmdName() == "bibitem") {
918 lex.printError("Wrong place for bibitem");
919 inset = inscmd.Clone();
920 } else if (inscmd.getCmdName() == "BibTeX") {
921 inset = new InsetBibtex(inscmd.getContents(), inscmd.getOptions(), this);
922 } else if (inscmd.getCmdName() == "index") {
923 inset = new InsetIndex(inscmd.getContents());
924 } else if (inscmd.getCmdName() == "include") {
925 inset = new InsetInclude(inscmd.getContents(), this);
926 } else if (inscmd.getCmdName() == "label") {
927 inset = new InsetLabel(inscmd.getCommand());
928 } else if (inscmd.getCmdName() == "url"
929 || inscmd.getCmdName() == "htmlurl") {
930 inset = new InsetUrl(inscmd.getCommand());
931 } else if (inscmd.getCmdName() == "ref"
932 || inscmd.getCmdName() == "pageref") {
933 if (!inscmd.getOptions().empty() || !inscmd.getContents().empty()) {
934 inset = new InsetRef(inscmd, this);
936 /* This condition comes from a temporary solution
937 to the latexdel ref inset that was transformed to an empty ref
938 inset plus the body surronded by latexdel insets */
940 string cont, opt, tmptmptok, cmdname;
942 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
947 tmptmptok = lex.GetString();
948 if(tmptmptok[0] == '\\') {
949 if( tmptmptok == "\\backslash")
959 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
964 tmptmptok = lex.GetString();
965 if(tmptmptok[0] == '\\') {
966 if( tmptmptok == "\\backslash")
976 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
982 cmdname = "\\" + inscmd.getCmdName();
983 cmdname += "[" + cont + "]";
984 cmdname += "{" + opt + "}";
985 inset = new InsetRef(cmdname, this);
987 } else if (inscmd.getCmdName() == "tableofcontents") {
988 inset = new InsetTOC(this);
989 } else if (inscmd.getCmdName() == "listoffigures") {
990 inset = new InsetLOF(this);
991 } else if (inscmd.getCmdName() == "listofalgorithms") {
992 inset = new InsetLOA(this);
993 } else if (inscmd.getCmdName() == "listoftables") {
994 inset = new InsetLOT(this);
995 } else if (inscmd.getCmdName() == "printindex") {
996 inset = new InsetPrintIndex(this);
997 } else if (inscmd.getCmdName() == "lyxparent") {
998 inset = new InsetParent(inscmd.getContents(), this);
1000 // The following three are only for compatibility
1001 if (inscmd.getCmdName() == "-") {
1002 inset = new InsetSpecialChar(InsetSpecialChar::HYPHENATION);
1003 } else if (inscmd.getCmdName() == "@.") {
1004 inset = new InsetSpecialChar(InsetSpecialChar::END_OF_SENTENCE);
1005 } else if (inscmd.getCmdName() == "ldots") {
1006 inset = new InsetSpecialChar(InsetSpecialChar::LDOTS);
1008 inset = inscmd.Clone();
1011 par->InsertChar(pos, LyXParagraph::META_INSET);
1012 par->InsertInset(pos, inset);
1013 par->SetFont(pos, font);
1017 } else if (token == "\\InsetQuotes") {
1018 inset = new InsetQuotes;
1020 par->InsertChar(pos, LyXParagraph::META_INSET);
1021 par->InsertInset(pos, inset);
1022 par->SetFont(pos, font);
1025 } else if (token == "\\InsetLatex") {
1026 inset = new InsetLatex;
1028 par->InsertChar(pos, LyXParagraph::META_INSET);
1029 par->InsertInset(pos, inset);
1030 par->SetFont(pos, font);
1032 } else if (token == "\\InsetLatexDel") {
1033 lex.printError(_("Warning: Ignoring Old Inset"));
1035 } else if (token == "\\InsetFormula") {
1036 inset = new InsetFormula;
1038 par->InsertChar(pos, LyXParagraph::META_INSET);
1039 par->InsertInset(pos, inset);
1040 par->SetFont(pos, font);
1042 } else if (token == "\\SpecialChar") {
1043 inset = new InsetSpecialChar;
1045 par->InsertChar(pos, LyXParagraph::META_INSET);
1046 par->InsertInset(pos, inset);
1047 par->SetFont(pos, font);
1049 } else if (token == "\\Figure") {
1050 inset = new InsetFig(100, 100, this);
1052 par->InsertChar(pos, LyXParagraph::META_INSET);
1053 par->InsertInset(pos, inset);
1054 par->SetFont(pos, font);
1056 } else if (token == "\\newline") {
1057 par->InsertChar(pos, LyXParagraph::META_NEWLINE);
1058 par->SetFont(pos, font);
1060 } else if (token == "\\LyXTable") {
1061 par->table = new LyXTable(lex);
1062 } else if (token == "\\hfill") {
1063 par->InsertChar(pos, LyXParagraph::META_HFILL);
1064 par->SetFont(pos, font);
1066 } else if (token == "\\protected_separator") {
1067 par->InsertChar(pos, LyXParagraph::META_PROTECTED_SEPARATOR);
1068 par->SetFont(pos, font);
1070 } else if (token == "\\bibitem") { // ale970302
1072 par->bibkey = new InsetBibKey;
1073 par->bibkey->Read(lex);
1074 }else if (token == "\\backslash") {
1075 par->InsertChar(pos, '\\');
1076 par->SetFont(pos, font);
1078 }else if (token == "\\the_end") {
1079 the_end_read = true;
1081 // This should be insurance for the future: (Asger)
1082 lex.printError("Unknown token `$$Token'. "
1083 "Inserting as text.");
1084 int n = token.length();
1085 for (int i = 0; i < n; i++) {
1086 par->InsertChar(pos, token[i]);
1087 par->SetFont(pos, font);
1096 paragraph = return_par;
1098 return the_end_read;
1102 bool Buffer::readFile(LyXLex & lex, LyXParagraph * par)
1108 token = lex.GetString();
1109 if (token == "\\lyxformat") { // the first token _must_ be...
1111 format = lex.GetFloat();
1113 if (LYX_FORMAT - format > 0.05) {
1114 printf(_("Warning: need lyxformat %.2f but found %.2f\n"),
1115 LYX_FORMAT, format);
1117 if (format - LYX_FORMAT > 0.05) {
1118 printf(_("ERROR: need lyxformat %.2f but found %.2f\n"),
1119 LYX_FORMAT, format);
1121 bool the_end = readLyXformat2(lex, par);
1122 // Formats >= 2.13 support "\the_end" marker
1126 // Formats >= 2.14 changed papersize stuff
1127 if (format < 2.14) {
1136 WriteAlert(_("Warning!"),
1137 _("Reading of document is not complete"),
1138 _("Maybe the document is truncated"));
1139 // We simulate a safe reading anyways to allow
1140 // users to take the chance... (Asger)
1144 WriteAlert(_("ERROR!"),
1145 _("Old LyX file format found. "
1146 "Use LyX 0.10.x to read this!"));
1150 } else { // "\\lyxformat" not found
1151 WriteAlert(_("ERROR!"), _("Not a LyX file!"));
1154 WriteAlert(_("ERROR!"), _("Unable to read file!"));
1159 // Returns false if unsuccesful
1160 bool Buffer::writeFile(string const & filename, bool flag)
1162 // if flag is false writeFile will not create any GUI
1163 // warnings, only cerr.
1164 // Needed for autosave in background or panic save (Matthias 120496)
1166 if (read_only && (filename == this->filename)) {
1167 // Here we should come with a question if we should
1168 // perform the write anyway.
1170 lyxerr << _("Error! Document is read-only: ")
1171 << filename << endl;
1173 WriteAlert(_("Error! Document is read-only: "),
1178 FileInfo finfo(filename);
1179 if (finfo.exist() && !finfo.writable()) {
1180 // Here we should come with a question if we should
1181 // try to do the save anyway. (i.e. do a chmod first)
1183 lyxerr << _("Error! Cannot write file: ")
1184 << filename << endl;
1186 WriteFSAlert(_("Error! Cannot write file: "),
1191 ofstream ofs(filename.c_str());
1194 lyxerr << _("Error! Cannot open file: ")
1195 << filename << endl;
1197 WriteFSAlert(_("Error! Canno open file:"),
1201 // The top of the file should not be written by params.
1202 // collect some very important information
1203 string userName(getUserName()) ;
1205 // write out a comment in the top of the file
1206 ofs << "#LyX 1.1 Copyright 1995-1999 Matthias Ettrich"
1207 " and the LyX Team\n";
1208 ofs.setf(ios::showpoint|ios::fixed);
1210 ofs << "\\lyxformat " << setw(4) << LYX_FORMAT << "\n";
1212 // now write out the buffer paramters.
1213 params.writeFile(ofs);
1215 char footnoteflag = 0;
1218 // this will write out all the paragraphs
1219 // using recursive descent.
1220 paragraph->writeFile(ofs, params, footnoteflag, depth);
1222 // Write marker that shows file is complete
1223 ofs << "\n\\the_end" << endl;
1225 // how to check if close went ok?
1230 void Buffer::writeFileAscii(string const & filename, int linelen)
1232 LyXFont font1, font2;
1234 char c, footnoteflag = 0, depth = 0;
1236 LyXParagraph::size_type i;
1237 int j, h, ltype = 0, ltype_depth = 0,
1238 * clen = 0, actcell = 0, actpos = 0, cell = 0, cells = 0,
1241 bool ref_printed = false;
1243 ofstream ofs(filename.c_str());
1245 WriteFSAlert(_("Error: Cannot write file:"), filename);
1249 string fname1 = TmpFileName();
1250 LyXParagraph * par = paragraph;
1254 if (par->footnoteflag != LyXParagraph::NO_FOOTNOTE ||
1256 par->previous->footnoteflag == LyXParagraph::NO_FOOTNOTE){
1258 /* begins a footnote environment ? */
1259 if (footnoteflag != par->footnoteflag) {
1260 footnoteflag = par->footnoteflag;
1262 j = strlen(string_footnotekinds[par->footnotekind])+4;
1263 if (currlinelen + j > linelen)
1266 << string_footnotekinds[par->footnotekind] << "] ";
1271 /* begins or ends a deeper area ?*/
1272 if (depth != par->depth) {
1273 if (par->depth > depth) {
1274 while (par->depth > depth) {
1279 while (par->depth < depth) {
1285 /* First write the layout */
1286 tmp = textclasslist.NameOfLayout(params.textclass, par->layout);
1287 if (tmp == "Itemize") {
1289 ltype_depth = depth+1;
1290 } else if (tmp == "Enumerate") {
1292 ltype_depth = depth+1;
1293 } else if (strstr(tmp.c_str(), "ection")) {
1295 ltype_depth = depth+1;
1296 } else if (strstr(tmp.c_str(), "aragraph")) {
1298 ltype_depth = depth+1;
1299 } else if (tmp == "Description") {
1301 ltype_depth = depth+1;
1302 } else if (tmp == "Abstract") {
1305 } else if (tmp == "Bibliography") {
1313 /* maybe some vertical spaces */
1315 /* the labelwidthstring used in lists */
1319 /* some pagebreaks? */
1323 /* what about the alignment */
1326 /* dummy layout, that means a footnote ended */
1327 footnoteflag = LyXParagraph::NO_FOOTNOTE;
1332 /* It might be a table */
1334 if (!lyxrc->ascii_roff_command.empty() &&
1335 lyxrc->ascii_roff_command != "none") {
1336 RoffAsciiTable(ofs, par);
1342 cells = par->table->columns;
1343 clen = new int [cells];
1344 memset(clen, 0, sizeof(int) * cells);
1345 for (i = 0, j = 0, h = 1; i < par->size(); ++i, ++h) {
1346 c = par->GetChar(i);
1347 if (c == LyXParagraph::META_INSET) {
1348 if ((inset = par->GetInset(i))) {
1349 ofstream fs(fname1.c_str());
1351 WriteFSAlert(_("Error: Cannot open temporary file:"), fname1);
1354 inset->Latex(fs, -1);
1355 h += fs.tellp() - 1;
1356 remove(fname1.c_str());
1358 } else if (c == LyXParagraph::META_NEWLINE) {
1362 j = (++j) % par->table->NumberOfCellsInRow(actcell);
1370 font1 = LyXFont(LyXFont::ALL_INHERIT);
1372 for (i = 0, actpos = 1; i < par->size(); ++i, ++actpos) {
1373 if (!i && !footnoteflag && !noparbreak){
1375 for(j = 0; j < depth; ++j)
1377 currlinelen = depth * 2;
1379 case 0: /* Standart */
1380 case 4: /* (Sub)Paragraph */
1381 case 5: /* Description */
1383 case 6: /* Abstract */
1384 ofs << "Abstract\n\n";
1386 case 7: /* Bibliography */
1388 ofs << "References\n\n";
1393 ofs << par->labelstring << " ";
1396 if (ltype_depth > depth) {
1397 for(j = ltype_depth-1; j>depth; j--)
1399 currlinelen += (ltype_depth-depth)*2;
1402 for(j = 0;j<cells;j++) {
1404 for(h = 0; h < (clen[j]+1); h++)
1408 for(j = 0; j<depth; j++)
1410 currlinelen = depth*2;
1411 if (ltype_depth > depth) {
1412 for(j = ltype_depth; j>depth; j--)
1414 currlinelen += (ltype_depth-depth)*2;
1419 font2 = par->GetFontSettings(i);
1420 if (font1.latex() != font2.latex()) {
1421 if (font2.latex() == LyXFont::OFF)
1429 c = par->GetChar(i);
1433 case LyXParagraph::META_INSET:
1434 if ((inset = par->GetInset(i))) {
1436 inset->Latex(ofs, -1);
1437 currlinelen += (ofs.tellp() - fpos);
1438 actpos += (ofs.tellp() - fpos) - 1;
1441 case LyXParagraph::META_NEWLINE:
1443 if (par->table->NumberOfCellsInRow(actcell) <= cell) {
1444 for(j = actpos; j < clen[cell-1];j++)
1447 for(j = 0; j<depth; j++)
1449 currlinelen = depth*2;
1450 if (ltype_depth > depth) {
1451 for(j = ltype_depth; j>depth; j--)
1453 currlinelen += (ltype_depth-depth)*2;
1455 for(j = 0;j<cells;j++) {
1457 for(h = 0; h < (clen[j]+1); ++h)
1461 for(j = 0; j<depth; j++)
1463 currlinelen = depth*2;
1464 if (ltype_depth > depth) {
1465 for(j = ltype_depth; j>depth; j--)
1467 currlinelen += (ltype_depth-depth)*2;
1472 for(j = actpos; j<clen[cell-1]; j++)
1478 currlinelen = actpos = 0;
1481 for(j = 0; j<depth; j++)
1483 currlinelen = depth * 2;
1484 if (ltype_depth > depth) {
1485 for(j = ltype_depth; j>depth; j--)
1487 currlinelen += (ltype_depth-depth)*2;
1491 case LyXParagraph::META_HFILL:
1494 case LyXParagraph::META_PROTECTED_SEPARATOR:
1501 if (currlinelen > linelen - 10
1502 && c == ' ' && i + 2 < par->size()) {
1504 for(j = 0; j < depth; ++j)
1506 currlinelen = depth * 2;
1507 if (ltype_depth > depth) {
1508 for(j = ltype_depth;
1511 currlinelen += (ltype_depth-depth)*2;
1513 } else if (c != '\0')
1516 lyxerr.debug() << "writeAsciiFile: NULL char in structure." << endl;
1522 for(j = actpos; j < clen[cell - 1]; ++j)
1525 for(j = 0; j<depth; j++)
1527 currlinelen = depth * 2;
1528 if (ltype_depth > depth) {
1529 for(j = ltype_depth; j > depth; --j)
1531 currlinelen += (ltype_depth-depth)*2;
1533 for(j = 0;j<cells; ++j) {
1535 for(h = 0; h < (clen[j] + 1); ++h)
1548 void Buffer::makeLaTeXFile(string const & filename,
1549 string const & original_path,
1550 bool nice, bool only_body)
1552 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
1553 params.textclass = GetCurrentTextClass();
1554 niceFile = nice; // this will be used by Insetincludes.
1556 tex_code_break_column = lyxrc->ascii_linelen;
1558 LyXTextClass const & tclass =
1559 textclasslist.TextClass(params.textclass);
1561 ofstream ofs(filename.c_str());
1563 WriteFSAlert(_("Error: Cannot open file:"), filename);
1567 // validate the buffer.
1568 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
1569 LaTeXFeatures features(tclass.numLayouts());
1571 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
1574 // The starting paragraph of the coming rows is the
1575 // first paragraph of the document. (Asger)
1576 texrow.start(paragraph, 0);
1578 string userName(getUserName());
1581 if (!only_body && nice) {
1582 LFile += "%% This LaTeX-file was created by <";
1583 LFile += userName + "> " + date();
1584 LFile += "%% LyX 1.0 (C) 1995-1999 by Matthias Ettrich and the LyX Team\n";
1585 LFile += "\n%% Do not edit this file unless you know what you are doing.\n";
1591 lyxerr.debug() << "lyx header finished" << endl;
1592 // There are a few differences between nice LaTeX and usual files:
1593 // usual is \batchmode, uses \listfiles and has a
1594 // special input@path to allow the including of figures
1595 // with either \input or \includegraphics (what figinsets do).
1596 // batchmode is not set if there is a tex_code_break_column.
1597 // In this case somebody is interested in the generated LaTeX,
1598 // so this is OK. input@path is set when the actual parameter
1599 // original_path is set. This is done for usual tex-file, but not
1600 // for nice-latex-file. (Matthias 250696)
1603 // code for usual, NOT nice-latex-file
1604 LFile += "\\batchmode\n"; // changed
1605 // from \nonstopmode
1607 // We don't need listfiles anymore
1608 //LFile += "\\listfiles\n";
1611 if (!original_path.empty()) {
1612 LFile += "\\makeatletter\n";
1614 LFile += "\\def\\input@path{{" + original_path
1617 LFile += "\\makeatother\n";
1621 LFile += "\\documentclass";
1623 string options; // the document class options.
1625 if (tokenPos(tclass.opt_fontsize(), '|', params.fontsize) >= 0) {
1626 // only write if existing in list (and not default)
1627 options += params.fontsize;
1632 if (!params.use_geometry &&
1633 (params.paperpackage == BufferParams::PACKAGE_NONE)) {
1634 switch (params.papersize) {
1635 case BufferParams::PAPER_A4PAPER:
1636 options += "a4paper,";
1638 case BufferParams::PAPER_USLETTER:
1639 options += "letterpaper,";
1641 case BufferParams::PAPER_A5PAPER:
1642 options += "a5paper,";
1644 case BufferParams::PAPER_B5PAPER:
1645 options += "b5paper,";
1647 case BufferParams::PAPER_EXECUTIVEPAPER:
1648 options += "executivepaper,";
1650 case BufferParams::PAPER_LEGALPAPER:
1651 options += "legalpaper,";
1657 if (params.sides != tclass.sides()) {
1658 if (params.sides == 2)
1659 options += "twoside,";
1661 options += "oneside,";
1665 if (params.columns != tclass.columns()) {
1666 if (params.columns == 2)
1667 options += "twocolumn,";
1669 options += "onecolumn,";
1672 if (!params.use_geometry && params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1673 options += "landscape,";
1675 // language should be a parameter to \documentclass
1676 if (params.language != "default") {
1677 options += params.language + ',';
1680 // the user-defined options
1681 if (!params.options.empty()) {
1682 options += params.options + ',';
1685 if (!options.empty()){
1686 options = strip(options, ',');
1693 LFile += textclasslist.LatexnameOfClass(params.textclass);
1696 // end of \documentclass defs
1698 // font selection must be done before loading fontenc.sty
1699 if (params.fonts != "default") {
1700 LFile += "\\usepackage{" + params.fonts + "}\n";
1703 // this one is not per buffer
1704 if (lyxrc->fontenc != "default") {
1705 LFile += "\\usepackage[" + lyxrc->fontenc
1709 if (params.inputenc != "default") {
1710 LFile += "\\usepackage[" + params.inputenc
1715 /* at the very beginning the text parameters */
1716 if (params.paperpackage != BufferParams::PACKAGE_NONE) {
1717 switch (params.paperpackage) {
1718 case BufferParams::PACKAGE_A4:
1719 LFile += "\\usepackage{a4}\n";
1722 case BufferParams::PACKAGE_A4WIDE:
1723 LFile += "\\usepackage{a4wide}\n";
1726 case BufferParams::PACKAGE_WIDEMARGINSA4:
1727 LFile += "\\usepackage[widemargins]{a4}\n";
1732 if (params.use_geometry) {
1733 LFile += "\\usepackage{geometry}\n";
1735 LFile += "\\geometry{verbose";
1736 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1737 LFile += ",landscape";
1738 switch (params.papersize2) {
1739 case BufferParams::VM_PAPER_CUSTOM:
1740 if (!params.paperwidth.empty())
1741 LFile += ",paperwidth="
1742 + params.paperwidth;
1743 if (!params.paperheight.empty())
1744 LFile += ",paperheight="
1745 + params.paperheight;
1747 case BufferParams::VM_PAPER_USLETTER:
1748 LFile += ",letterpaper";
1750 case BufferParams::VM_PAPER_USLEGAL:
1751 LFile += ",legalpaper";
1753 case BufferParams::VM_PAPER_USEXECUTIVE:
1754 LFile += ",executivepaper";
1756 case BufferParams::VM_PAPER_A3:
1757 LFile += ",a3paper";
1759 case BufferParams::VM_PAPER_A4:
1760 LFile += ",a4paper";
1762 case BufferParams::VM_PAPER_A5:
1763 LFile += ",a5paper";
1765 case BufferParams::VM_PAPER_B3:
1766 LFile += ",b3paper";
1768 case BufferParams::VM_PAPER_B4:
1769 LFile += ",b4paper";
1771 case BufferParams::VM_PAPER_B5:
1772 LFile += ",b5paper";
1775 // default papersize ie BufferParams::VM_PAPER_DEFAULT
1776 switch (lyxrc->default_papersize) {
1777 case BufferParams::PAPER_DEFAULT: // keep compiler happy
1778 case BufferParams::PAPER_USLETTER:
1779 LFile += ",letterpaper";
1781 case BufferParams::PAPER_LEGALPAPER:
1782 LFile += ",legalpaper";
1784 case BufferParams::PAPER_EXECUTIVEPAPER:
1785 LFile += ",executivepaper";
1787 case BufferParams::PAPER_A3PAPER:
1788 LFile += ",a3paper";
1790 case BufferParams::PAPER_A4PAPER:
1791 LFile += ",a4paper";
1793 case BufferParams::PAPER_A5PAPER:
1794 LFile += ",a5paper";
1796 case BufferParams::PAPER_B5PAPER:
1797 LFile += ",b5paper";
1801 if (!params.topmargin.empty())
1802 LFile += ",tmargin=" + params.topmargin;
1803 if (!params.bottommargin.empty())
1804 LFile += ",bmargin=" + params.bottommargin;
1805 if (!params.leftmargin.empty())
1806 LFile += ",lmargin=" + params.leftmargin;
1807 if (!params.rightmargin.empty())
1808 LFile += ",rmargin=" + params.rightmargin;
1809 if (!params.headheight.empty())
1810 LFile += ",headheight=" + params.headheight;
1811 if (!params.headsep.empty())
1812 LFile += ",headsep=" + params.headsep;
1813 if (!params.footskip.empty())
1814 LFile += ",footskip=" + params.footskip;
1818 if (params.use_amsmath
1819 && !prefixIs(textclasslist.LatexnameOfClass(params.textclass), "ams")) {
1820 LFile += "\\usepackage{amsmath}\n";
1823 if (tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle) >= 0) {
1824 if (params.pagestyle == "fancy") {
1825 LFile += "\\usepackage{fancyhdr}\n";
1828 LFile += "\\pagestyle{" + params.pagestyle + "}\n";
1832 // We try to load babel late, in case it interferes
1833 // with other packages.
1834 if (params.language != "default") {
1835 LFile += "\\usepackage{babel}\n";
1839 if (params.secnumdepth != tclass.secnumdepth()) {
1840 LFile += "\\setcounter{secnumdepth}{";
1841 LFile += tostr(params.secnumdepth);
1845 if (params.tocdepth != tclass.tocdepth()) {
1846 LFile += "\\setcounter{tocdepth}{";
1847 LFile += tostr(params.tocdepth);
1852 if (params.paragraph_separation) {
1853 switch (params.defskip.kind()) {
1854 case VSpace::SMALLSKIP:
1855 LFile += "\\setlength\\parskip{\\smallskipamount}\n";
1857 case VSpace::MEDSKIP:
1858 LFile += "\\setlength\\parskip{\\medskipamount}\n";
1860 case VSpace::BIGSKIP:
1861 LFile += "\\setlength\\parskip{\\bigskipamount}\n";
1863 case VSpace::LENGTH:
1864 LFile += "\\setlength\\parskip{"
1865 + params.defskip.length().asLatexString()
1868 default: // should never happen // Then delete it.
1869 LFile += "\\setlength\\parskip{\\medskipamount}\n";
1874 LFile += "\\setlength\\parindent{0pt}\n";
1878 // Write out what we've generated so far...and reset LFile
1882 // Now insert the LyX specific LaTeX commands...
1883 string preamble, tmppreamble;
1885 // The optional packages;
1886 preamble = features.getPackages(params);
1888 // this might be useful...
1889 preamble += "\n\\makeatletter\n\n";
1891 // Some macros LyX will need
1892 tmppreamble = features.getMacros(params);
1894 if (!tmppreamble.empty()) {
1895 preamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1896 "LyX specific LaTeX commands.\n"
1897 + tmppreamble + '\n';
1900 // the text class specific preamble
1901 tmppreamble = features.getTClassPreamble(params);
1902 if (!tmppreamble.empty()) {
1903 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1904 "Textclass specific LaTeX commands.\n"
1905 + tmppreamble + '\n';
1908 /* the user-defined preamble */
1909 if (!params.preamble.empty()) {
1910 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1911 "User specified LaTeX commands.\n"
1912 + params.preamble + '\n';
1915 preamble += "\\makeatother\n\n";
1917 // Itemize bullet settings need to be last in case the user
1918 // defines their own bullets that use a package included
1919 // in the user-defined preamble -- ARRae
1920 // Actually it has to be done much later than that
1921 // since some packages like frenchb make modifications
1922 // at \begin{document} time -- JMarc
1924 for (int i = 0; i < 4; ++i) {
1925 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
1926 if (bullets_def.empty())
1927 bullets_def="\\AtBeginDocument{\n";
1928 bullets_def += " \\renewcommand{\\labelitemi";
1930 // `i' is one less than the item to modify
1937 bullets_def += "ii";
1943 bullets_def += "}{" +
1944 params.user_defined_bullets[i].getText()
1949 if (!bullets_def.empty())
1950 preamble += bullets_def + "}\n\n";
1952 for (int j = countChar(preamble, '\n'); j-- ;) {
1959 LFile += "\\begin{document}\n\n";
1963 lyxerr.debug() << "preamble finished, now the body." << endl;
1965 bool was_title = false;
1966 bool already_title = false;
1972 LyXParagraph * par = paragraph;
1978 lyxerr[Debug::LATEX] << "Error in MakeLateXFile."
1980 LyXLayout const & layout = textclasslist.Style(params.textclass,
1983 if (layout.intitle) {
1984 if (already_title) {
1985 lyxerr <<"Error in MakeLatexFile: You"
1986 " should not mix title layouts"
1987 " with normal ones." << endl;
1990 } else if (was_title && !already_title) {
1991 LFile += "\\maketitle\n";
1993 already_title = true;
1996 // We are at depth 0 so we can just use
1997 // ordinary \footnote{} generation
1998 // flag this with ftcount
2000 if (layout.isEnvironment()
2001 || par->pextra_type != LyXParagraph::PEXTRA_NONE) {
2002 par = par->TeXEnvironment(LFile, texrow,
2003 ftnote, ft_texrow, ftcount);
2005 par = par->TeXOnePar(LFile, texrow,
2006 ftnote, ft_texrow, ftcount);
2009 // Write out what we've generated...and reset LFile
2012 LFile += "\\addtocounter{footnote}{-";
2013 LFile += tostr(ftcount - 1);
2017 texrow += ft_texrow;
2022 if (loop_count == 2) {
2023 // fwrite()ing every second time through the loop
2024 // gains a few extra % of speed; going higher than
2025 // 2 will slow things down again. I'll look at
2026 // LFile.length() in a future revision. ARRae
2033 // It might be that we only have a title in this document
2034 if (was_title && !already_title) {
2035 LFile += "\\maketitle\n";
2040 LFile += "\\end{document}\n";
2043 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
2045 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
2049 // Just to be sure. (Asger)
2052 // Write out what we've generated...and reset LFile
2056 // tex_code_break_column's value is used to decide
2057 // if we are in batchmode or not (within mathed_write()
2058 // in math_write.C) so we must set it to a non-zero
2059 // value when we leave otherwise we save incorrect .lyx files.
2060 tex_code_break_column = lyxrc->ascii_linelen;
2062 // How to check if the close went ok when using fstreams
2064 lyxerr.debug() << "Finished making latex file." << endl;
2068 bool Buffer::isLatex() const
2070 return textclasslist.TextClass(params.textclass).outputType() == LATEX;
2074 bool Buffer::isLinuxDoc() const
2076 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC;
2080 bool Buffer::isLiterate() const
2082 return textclasslist.TextClass(params.textclass).outputType() == LITERATE;
2086 bool Buffer::isDocBook() const
2088 return textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2092 bool Buffer::isSGML() const
2094 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC ||
2095 textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2099 void Buffer::sgmlOpenTag(ostream & os, int depth,
2100 string const & latexname) const
2102 static char * space[] = {" "," ", " ", " ", " ", " ",
2107 os << space[depth] << "<" << latexname << ">\n";
2111 void Buffer::sgmlCloseTag(ostream & os, int depth,
2112 string const & latexname) const
2114 static char * space[] = {" ", " ", " ", " ", " ",
2118 os << space[depth] << "</" << latexname << ">\n";
2122 void Buffer::makeLinuxDocFile(string const & filename, int column)
2124 LyXParagraph * par = paragraph;
2126 string top_element = textclasslist.LatexnameOfClass(params.textclass);
2127 string environment_stack[10];
2130 int depth = 0; /* paragraph depth */
2132 ofstream ofs(filename.c_str());
2135 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), filename);
2139 tex_code_break_column = column;
2142 if (params.preamble.empty()) {
2143 ofs << "<!doctype linuxdoc system>\n\n";
2146 ofs << "<!doctype linuxdoc system \n [ "
2147 << params.preamble << " \n]>\n\n";
2150 string userName(getUserName());
2151 ofs << "<!-- LinuxDoc file was created by LyX 1.0 (C) 1995-1999 "
2152 << "by <" << userName << "> " << (char*)date() << " -->\n";
2154 if(params.options.empty())
2155 sgmlOpenTag(ofs, 0, top_element);
2157 string top = top_element;
2159 top += params.options;
2160 sgmlOpenTag(ofs, 0, top);
2164 int desc_on = 0; /* description mode*/
2165 LyXLayout const & style =
2166 textclasslist.Style(GetCurrentTextClass(),
2168 par->AutoDeleteInsets();
2170 /* treat <toc> as a special case for compatibility with old code */
2171 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2172 Inset * inset = par->GetInset(0);
2173 char lyx_code = inset->LyxCode();
2174 if (lyx_code == Inset::TOC_CODE){
2175 string temp = "toc";
2176 sgmlOpenTag(ofs, depth, temp);
2179 linuxDocHandleFootnote(ofs, par, depth);
2184 /* environment tag closing */
2185 for( ; depth > par->depth; --depth) {
2186 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2187 environment_stack[depth].clear();
2190 /* write opening SGML tags */
2191 switch(style.latextype) {
2192 case LATEX_PARAGRAPH:
2193 if(depth == par->depth
2194 && !environment_stack[depth].empty()) {
2195 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2196 environment_stack[depth].clear();
2202 sgmlOpenTag(ofs, depth, style.latexname());
2207 LinuxDocError(par, 0, _("Error : Wrong depth for LatexType Command.\n"));
2209 if (!environment_stack[depth].empty()){
2210 sgmlCloseTag(ofs, depth,
2211 environment_stack[depth]);
2215 environment_stack[depth].clear();
2216 sgmlOpenTag(ofs, depth, style.latexname());
2219 case LATEX_ENVIRONMENT:
2220 case LATEX_ITEM_ENVIRONMENT:
2221 if(depth == par->depth
2222 && environment_stack[depth] != style.latexname()
2223 && !environment_stack[depth].empty()) {
2225 sgmlCloseTag(ofs, depth,
2226 environment_stack[depth]);
2227 environment_stack[depth].clear();
2229 if (depth < par->depth) {
2231 environment_stack[depth].clear();
2233 if (environment_stack[depth] != style.latexname()) {
2236 sgmlOpenTag(ofs, depth, temp);
2238 environment_stack[depth] = style.latexname();
2239 sgmlOpenTag(ofs, depth, environment_stack[depth]);
2241 if(style.latextype == LATEX_ENVIRONMENT) break;
2243 desc_on = (style.labeltype == LABEL_MANUAL);
2250 sgmlOpenTag(ofs, depth + 1, item_name);
2253 sgmlOpenTag(ofs, depth, style.latexname());
2258 SimpleLinuxDocOnePar(ofs, par, desc_on, depth);
2261 linuxDocHandleFootnote(ofs, par, depth);
2263 while(par && par->IsDummy());
2266 /* write closing SGML tags */
2267 switch(style.latextype) {
2269 case LATEX_ENVIRONMENT:
2270 case LATEX_ITEM_ENVIRONMENT:
2273 sgmlCloseTag(ofs, depth, style.latexname());
2278 /* Close open tags */
2279 for(; depth > 0; --depth)
2280 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2282 if(!environment_stack[depth].empty())
2283 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2286 sgmlCloseTag(ofs, 0, top_element);
2289 // How to check for successful close
2293 void Buffer::linuxDocHandleFootnote(ostream & os, LyXParagraph * & par,
2296 string tag = "footnote";
2298 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2299 sgmlOpenTag(os, depth + 1, tag);
2300 SimpleLinuxDocOnePar(os, par, 0, depth + 1);
2301 sgmlCloseTag(os, depth + 1, tag);
2307 void Buffer::DocBookHandleCaption(ostream & os, string & inner_tag,
2308 int const depth, int desc_on,
2309 LyXParagraph * & par)
2311 LyXParagraph * tpar = par;
2312 string tmp_par, extra_par;
2313 while (tpar && (tpar->footnoteflag != LyXParagraph::NO_FOOTNOTE) &&
2314 (tpar->layout != textclasslist.NumberOfLayout(params.textclass,
2318 tpar->layout == textclasslist.NumberOfLayout(params.textclass,
2319 "Caption").second) {
2320 sgmlOpenTag(os, depth + 1, inner_tag);
2321 SimpleDocBookOnePar(tmp_par, extra_par, tpar,
2322 desc_on, depth + 2);
2323 tmp_par = strip(tmp_par);
2324 tmp_par = frontStrip(tmp_par);
2326 sgmlCloseTag(os, depth+1, inner_tag);
2327 if(!extra_par.empty())
2333 void Buffer::DocBookHandleFootnote(ostream & os, LyXParagraph * & par,
2336 string tag, inner_tag;
2337 string tmp_par, extra_par;
2338 bool inner_span = false;
2341 // This is not how I like to see enums. They should not be anonymous
2342 // and variables of its type should not be declared right after the
2343 // last brace. (Lgb)
2350 } last = NO_ONE, present = FOOTNOTE_LIKE;
2352 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2353 if(last == present) {
2355 if(!tmp_par.empty()) {
2358 sgmlCloseTag(os, depth+1, inner_tag);
2359 sgmlOpenTag(os, depth+1, inner_tag);
2366 if(!inner_tag.empty()) sgmlCloseTag(os, depth+1, inner_tag);
2367 if(!extra_par.empty()) os << extra_par;
2368 if(!tag.empty()) sgmlCloseTag(os, depth, tag);
2371 switch (par->footnotekind) {
2372 case LyXParagraph::FOOTNOTE:
2373 case LyXParagraph::ALGORITHM:
2376 present = FOOTNOTE_LIKE;
2379 case LyXParagraph::MARGIN:
2382 present = MARGIN_LIKE;
2385 case LyXParagraph::FIG:
2386 case LyXParagraph::WIDE_FIG:
2388 inner_tag = "title";
2392 case LyXParagraph::TAB:
2393 case LyXParagraph::WIDE_TAB:
2395 inner_tag = "title";
2400 sgmlOpenTag(os, depth, tag);
2401 if ((present == TAB_LIKE) || (present == FIG_LIKE)) {
2402 DocBookHandleCaption(os, inner_tag, depth,
2406 sgmlOpenTag(os, depth + 1, inner_tag);
2409 // ignore all caption here, we processed them above!!!
2410 if (par->layout != textclasslist.NumberOfLayout(params.textclass,
2411 "Caption").second) {
2412 SimpleDocBookOnePar(tmp_par, extra_par, par,
2413 desc_on, depth + 2);
2415 tmp_par = frontStrip(strip(tmp_par));
2421 if(!inner_tag.empty()) sgmlCloseTag(os, depth+1, inner_tag);
2422 if(!extra_par.empty()) os << extra_par;
2423 if(!tag.empty()) sgmlCloseTag(os, depth, tag);
2427 /* push a tag in a style stack */
2428 void Buffer::push_tag(ostream & os, char const * tag,
2429 int & pos, char stack[5][3])
2433 /* pop all previous tags */
2434 for (j = pos; j >= 0; --j)
2435 os << "</" << stack[j] << ">";
2438 sprintf(stack[++pos], "%s", tag);
2441 for (j = 0; j <= pos; ++j)
2442 os << "<" << stack[j] << ">";
2446 // pop a tag from a style stack
2447 void Buffer::pop_tag(ostream & os, char const * tag,
2448 int & pos, char stack[5][3])
2452 // pop all tags till specified one
2453 for (j = pos; (j >= 0) && (strcmp(stack[j], tag)); --j)
2454 os << "</" << stack[j] << ">";
2457 os << "</" << tag << ">";
2459 // push all tags, but the specified one
2460 for (j = j + 1; j <= pos; ++j) {
2461 os << "<" << stack[j] << ">";
2462 strcpy(stack[j-1], stack[j]);
2468 /* handle internal paragraph parsing -- layout already processed */
2470 // checks, if newcol chars should be put into this line
2471 // writes newline, if necessary.
2473 void linux_doc_line_break(ostream & os, unsigned int & colcount,
2474 const unsigned int newcol)
2477 if (colcount > lyxrc->ascii_linelen) {
2479 colcount = newcol; // assume write after this call
2484 void Buffer::SimpleLinuxDocOnePar(ostream & os, LyXParagraph * par,
2485 int desc_on, int const depth)
2487 LyXFont font1, font2;
2490 LyXParagraph::size_type main_body;
2492 LyXLayout const & style = textclasslist.Style(params.textclass,
2495 char family_type = 0; // family font flag
2496 bool is_bold = false; // series font flag
2497 char shape_type = 0; // shape font flag
2498 bool is_em = false; // emphasis (italic) font flag
2500 int stack_num = -1; // style stack position
2501 char stack[5][3]; // style stack
2502 unsigned int char_line_count = 5; // Heuristic choice ;-)
2504 if (style.labeltype != LABEL_MANUAL)
2507 main_body = par->BeginningOfMainBody();
2509 /* gets paragraph main font */
2511 font1 = style.labelfont;
2516 /* parsing main loop */
2517 for (LyXParagraph::size_type i = 0;
2518 i < par->size(); ++i) {
2520 /* handle quote tag */
2521 if (i == main_body && !par->IsDummy()) {
2526 font2 = par->getFont(i);
2528 if (font1.family() != font2.family()) {
2529 switch(family_type) {
2531 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2532 push_tag(os, "tt", stack_num, stack);
2535 else if (font2.family() == LyXFont::SANS_FAMILY) {
2536 push_tag(os, "sf", stack_num, stack);
2541 pop_tag(os, "tt", stack_num, stack);
2542 if (font2.family() == LyXFont::SANS_FAMILY) {
2543 push_tag(os, "sf", stack_num, stack);
2551 pop_tag(os, "sf", stack_num, stack);
2552 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2553 push_tag(os, "tt", stack_num, stack);
2562 /* handle bold face */
2563 if (font1.series() != font2.series()) {
2564 if (font2.series() == LyXFont::BOLD_SERIES) {
2565 push_tag(os, "bf", stack_num, stack);
2569 pop_tag(os, "bf", stack_num, stack);
2574 /* handle italic and slanted fonts */
2575 if (font1.shape() != font2.shape()) {
2576 switch(shape_type) {
2578 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2579 push_tag(os, "it", stack_num, stack);
2582 else if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2583 push_tag(os, "sl", stack_num, stack);
2588 pop_tag(os, "it", stack_num, stack);
2589 if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2590 push_tag(os, "sl", stack_num, stack);
2598 pop_tag(os, "sl", stack_num, stack);
2599 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2600 push_tag(os, "it", stack_num, stack);
2608 /* handle <em> tag */
2609 if (font1.emph() != font2.emph()) {
2610 if (font2.emph() == LyXFont::ON) {
2611 push_tag(os, "em", stack_num, stack);
2614 pop_tag(os, "em", stack_num, stack);
2619 c = par->GetChar(i);
2621 if (font2.latex() == LyXFont::ON) {
2622 // "TeX"-Mode on == > SGML-Mode on.
2624 os << c; // see LaTeX-Generation...
2626 } else if (c == LyXParagraph::META_INSET) {
2627 inset = par->GetInset(i);
2629 inset->Linuxdoc(tmp_out);
2634 if (par->linuxDocConvertChar(c, sgml_string)
2635 && !style.free_spacing) { // in freespacing
2637 // non-breaking characters
2641 linux_doc_line_break(os, char_line_count, 6);
2646 linux_doc_line_break(os, char_line_count, 1);
2652 char_line_count += sgml_string.length();
2658 /* needed if there is an optional argument but no contents */
2659 if (main_body > 0 && main_body == par->size()) {
2663 /* pop all defined Styles */
2664 for (j = stack_num; j >= 0; --j) {
2665 linux_doc_line_break(os,
2667 3 + strlen(stack[j]));
2668 os << "</" << stack[j] << ">";
2671 /* resets description flag correctly */
2674 /* <tag> not closed... */
2675 linux_doc_line_break(os, char_line_count, 6);
2679 /* fprintf(file, "</p>");*/
2685 /* print an error message */
2686 void Buffer::LinuxDocError(LyXParagraph * par, int pos,
2687 char const * message)
2689 InsetError * new_inset;
2691 /* insert an error marker in text */
2692 new_inset = new InsetError(message);
2693 par->InsertChar(pos, LyXParagraph::META_INSET);
2694 par->InsertInset(pos, new_inset);
2697 // This constant defines the maximum number of
2698 // environment layouts that can be nesteded.
2699 // The same applies for command layouts.
2700 // These values should be more than enough.
2701 // José Matos (1999/07/22)
2703 enum { MAX_NEST_LEVEL = 25};
2705 void Buffer::makeDocBookFile(string const & filename, int column)
2707 LyXParagraph * par = paragraph;
2709 string top_element= textclasslist.LatexnameOfClass(params.textclass);
2710 string environment_stack[MAX_NEST_LEVEL];
2711 string environment_inner[MAX_NEST_LEVEL];
2712 string command_stack[MAX_NEST_LEVEL];
2713 bool command_flag= false;
2714 int command_depth= 0, command_base= 0, cmd_depth= 0;
2716 string item_name, command_name;
2717 string c_depth, c_params, tmps;
2719 int depth= 0; /* paragraph depth */
2721 tex_code_break_column = column;
2723 ofstream ofs(filename.c_str());
2725 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), filename);
2732 ofs << "<!doctype " << top_element
2733 << " public \"-//OASIS//DTD DocBook V3.1//EN\"";
2735 if (params.preamble.empty())
2738 ofs << "\n [ " << params.preamble << " \n]>\n\n";
2740 string userName(getUserName());
2741 ofs << "<!-- DocBook file was created by LyX 1.0 (C) 1995-1999\n"
2742 << "by <" << userName << "> " << (char*)date() << " -->\n";
2744 if(params.options.empty())
2745 sgmlOpenTag(ofs, 0, top_element);
2747 string top = top_element;
2749 top += params.options;
2750 sgmlOpenTag(ofs, 0, top);
2754 int desc_on= 0; /* description mode*/
2755 LyXLayout const & style = textclasslist.Style(GetCurrentTextClass(),
2757 par->AutoDeleteInsets();
2759 /* environment tag closing */
2760 for( ; depth > par->depth; --depth) {
2761 if(environment_inner[depth] != "!-- --") {
2762 item_name= "listitem";
2763 sgmlCloseTag(ofs, command_depth + depth,
2765 if( environment_inner[depth] == "varlistentry")
2766 sgmlCloseTag(ofs, depth+command_depth,
2767 environment_inner[depth]);
2769 sgmlCloseTag(ofs, depth + command_depth,
2770 environment_stack[depth]);
2771 environment_stack[depth].clear();
2772 environment_inner[depth].clear();
2775 if(depth == par->depth
2776 && environment_stack[depth] != style.latexname()
2777 && !environment_stack[depth].empty()) {
2778 if(environment_inner[depth] != "!-- --") {
2779 item_name= "listitem";
2780 sgmlCloseTag(ofs, command_depth+depth,
2782 if( environment_inner[depth] == "varlistentry")
2784 depth + command_depth,
2785 environment_inner[depth]);
2788 sgmlCloseTag(ofs, depth + command_depth,
2789 environment_stack[depth]);
2791 environment_stack[depth].clear();
2792 environment_inner[depth].clear();
2795 // Write opening SGML tags.
2796 switch(style.latextype) {
2797 case LATEX_PARAGRAPH:
2798 if(style.latexname() != "dummy")
2799 sgmlOpenTag(ofs, depth+command_depth,
2805 LinuxDocError(par, 0,
2806 _("Error : Wrong depth for "
2807 "LatexType Command.\n"));
2809 command_name = style.latexname();
2811 tmps = style.latexparam();
2812 c_params = split(tmps, c_depth,'|');
2814 cmd_depth= atoi(c_depth.c_str());
2817 if(cmd_depth<command_base) {
2818 for(int j = command_depth;
2819 j >= command_base; --j)
2820 if(!command_stack[j].empty())
2821 sgmlCloseTag(ofs, j, command_stack[j]);
2822 command_depth= command_base= cmd_depth;
2824 else if(cmd_depth <= command_depth) {
2825 for(int j = command_depth;
2826 j >= cmd_depth; --j)
2828 if(!command_stack[j].empty())
2829 sgmlCloseTag(ofs, j, command_stack[j]);
2830 command_depth= cmd_depth;
2833 command_depth= cmd_depth;
2836 command_depth = command_base = cmd_depth;
2837 command_flag = true;
2839 command_stack[command_depth]= command_name;
2841 // treat label as a special case for
2842 // more WYSIWYM handling.
2843 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2844 Inset * inset = par->GetInset(0);
2845 char lyx_code = inset->LyxCode();
2846 if (lyx_code == Inset::LABEL_CODE){
2847 command_name += " id=\"";
2848 command_name += (static_cast<InsetCommand *>(inset))->getContents();
2849 command_name += "\"";
2854 sgmlOpenTag(ofs, depth+command_depth, command_name);
2855 item_name = "title";
2856 sgmlOpenTag(ofs, depth + 1 + command_depth, item_name);
2859 case LATEX_ENVIRONMENT:
2860 case LATEX_ITEM_ENVIRONMENT:
2861 if (depth < par->depth) {
2863 environment_stack[depth].clear();
2866 if (environment_stack[depth] != style.latexname()) {
2867 environment_stack[depth] = style.latexname();
2868 environment_inner[depth] = "!-- --";
2869 sgmlOpenTag(ofs, depth + command_depth,
2870 environment_stack[depth]);
2872 if(environment_inner[depth] != "!-- --") {
2873 item_name= "listitem";
2875 command_depth + depth,
2877 if (environment_inner[depth] == "varlistentry")
2879 depth + command_depth,
2880 environment_inner[depth]);
2884 if(style.latextype == LATEX_ENVIRONMENT) {
2885 if(!style.latexparam().empty())
2886 sgmlOpenTag(ofs, depth + command_depth,
2887 style.latexparam());
2891 desc_on = (style.labeltype == LABEL_MANUAL);
2894 environment_inner[depth]= "varlistentry";
2896 environment_inner[depth]= "listitem";
2898 sgmlOpenTag(ofs, depth + 1 + command_depth,
2899 environment_inner[depth]);
2903 sgmlOpenTag(ofs, depth + 1 + command_depth,
2908 sgmlOpenTag(ofs, depth + 1 + command_depth,
2913 sgmlOpenTag(ofs, depth + command_depth,
2919 string tmp_par, extra_par;
2921 SimpleDocBookOnePar(tmp_par, extra_par, par, desc_on,
2922 depth + 1 + command_depth);
2926 DocBookHandleFootnote(ofs, par,
2927 depth + 1 + command_depth);
2929 while(par && par->IsDummy());
2932 /* write closing SGML tags */
2933 switch(style.latextype) {
2936 sgmlCloseTag(ofs, depth + command_depth, end_tag);
2938 case LATEX_ENVIRONMENT:
2939 if(!style.latexparam().empty())
2940 sgmlCloseTag(ofs, depth + command_depth,
2941 style.latexparam());
2943 case LATEX_ITEM_ENVIRONMENT:
2944 if(desc_on == 1) break;
2946 sgmlCloseTag(ofs, depth + 1 + command_depth, end_tag);
2948 case LATEX_PARAGRAPH:
2949 if(style.latexname() != "dummy")
2950 sgmlCloseTag(ofs, depth + command_depth,
2954 sgmlCloseTag(ofs, depth + command_depth,
2961 for(; depth >= 0; --depth) {
2962 if(!environment_stack[depth].empty()) {
2963 if(environment_inner[depth] != "!-- --") {
2964 item_name= "listitem";
2965 sgmlCloseTag(ofs, command_depth + depth,
2967 if( environment_inner[depth] == "varlistentry")
2968 sgmlCloseTag(ofs, depth + command_depth,
2969 environment_inner[depth]);
2972 sgmlCloseTag(ofs, depth + command_depth,
2973 environment_stack[depth]);
2977 for(int j = command_depth; j >= command_base; --j)
2978 if(!command_stack[j].empty())
2979 sgmlCloseTag(ofs, j, command_stack[j]);
2982 sgmlCloseTag(ofs, 0, top_element);
2985 // How to check for successful close
2989 void Buffer::SimpleDocBookOnePar(string & file, string & extra,
2990 LyXParagraph * par, int & desc_on,
2994 par->SimpleDocBookOneTablePar(file, extra, desc_on, depth);
2997 LyXFont font1, font2;
3000 LyXParagraph::size_type main_body;
3002 string emph= "emphasis";
3003 bool emph_flag= false;
3004 int char_line_count= 0;
3006 LyXLayout const & style = textclasslist.Style(params.textclass,
3009 if (style.labeltype != LABEL_MANUAL)
3012 main_body = par->BeginningOfMainBody();
3014 /* gets paragraph main font */
3016 font1 = style.labelfont;
3020 char_line_count = depth;
3021 if(!style.free_spacing)
3022 for (j= 0;j< depth;j++)
3025 /* parsing main loop */
3026 for (LyXParagraph::size_type i = 0;
3027 i < par->size(); ++i) {
3028 font2 = par->getFont(i);
3030 /* handle <emphasis> tag */
3031 if (font1.emph() != font2.emph() && i) {
3032 if (font2.emph() == LyXFont::ON) {
3033 file += "<emphasis>";
3036 file += "</emphasis>";
3041 c = par->GetChar(i);
3043 if (c == LyXParagraph::META_INSET) {
3044 inset = par->GetInset(i);
3046 inset->DocBook(tmp_out);
3048 // This code needs some explanation:
3049 // Two insets are treated specially
3050 // label if it is the first element in a command paragraph
3052 // graphics inside tables or figure floats can't go on
3053 // title (the equivalente in latex for this case is caption
3054 // and title should come first
3057 if(desc_on!= 3 || i!= 0) {
3058 if(tmp_out[0] == '@') {
3060 extra += frontStrip(tmp_out, '@');
3062 file += frontStrip(tmp_out, '@');
3067 } else if (font2.latex() == LyXFont::ON) {
3068 // "TeX"-Mode on ==> SGML-Mode on.
3075 if (par->linuxDocConvertChar(c, sgml_string)
3076 && !style.free_spacing) { // in freespacing
3078 // non-breaking characters
3083 file += "</term><listitem><para>";
3091 file += sgml_string;
3097 /* needed if there is an optional argument but no contents */
3098 if (main_body > 0 && main_body == par->size()) {
3102 file += "</emphasis>";
3105 /* resets description flag correctly */
3108 /* <term> not closed... */
3116 bool Buffer::removeAutoInsets()
3118 LyXParagraph *par = paragraph;
3120 LyXCursor cursor = text->cursor;
3121 LyXCursor tmpcursor = cursor;
3122 cursor.par = tmpcursor.par->ParFromPos(tmpcursor.pos);
3123 cursor.pos = tmpcursor.par->PositionInParFromPos(tmpcursor.pos);
3127 if (par->AutoDeleteInsets()){
3129 if (par->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE){
3130 /* this is possible now, since SetCursor takes
3131 care about footnotes */
3132 text->SetCursorIntern(par, 0);
3133 text->RedoParagraphs(text->cursor, text->cursor.par->Next());
3134 text->FullRebreak();
3139 /* avoid forbidden cursor positions caused by error removing */
3140 if (cursor.pos > cursor.par->Last())
3141 cursor.pos = cursor.par->Last();
3142 text->SetCursorIntern(cursor.par, cursor.pos);
3148 int Buffer::runLaTeX()
3150 if (!text) return 0;
3154 // get LaTeX-Filename
3155 string name = getLatexName();
3157 string path = OnlyPath(filename);
3159 string org_path = path;
3160 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
3164 Path p(path); // path to LaTeX file
3165 users->owner()->getMiniBuffer()->Set(_("Running LaTeX..."));
3167 // Remove all error insets
3168 bool a = removeAutoInsets();
3170 // Always generate the LaTeX file
3171 makeLaTeXFile(name, org_path, false);
3174 // do the LaTex run(s)
3176 LaTeX latex(lyxrc->latex_command, name, filepath);
3177 int res = latex.run(terr,
3178 users->owner()->getMiniBuffer()); // running latex
3180 // check return value from latex.run().
3181 if ((res & LaTeX::NO_LOGFILE)) {
3182 WriteAlert(_("LaTeX did not work!"),
3183 _("Missing log file:"), name);
3184 } else if ((res & LaTeX::ERRORS)) {
3185 users->owner()->getMiniBuffer()->Set(_("Done"));
3186 // Insert all errors as errors boxes
3189 // Dvi should also be kept dirty if the latex run
3190 // ends up with errors. However it should be possible
3191 // to view a dirty dvi too.
3193 //no errors or any other things to think about so:
3194 users->owner()->getMiniBuffer()->Set(_("Done"));
3198 // if we removed error insets before we ran LaTeX or if we inserted
3199 // error insets after we ran LaTeX this must be run:
3200 if (a || (res & LaTeX::ERRORS)){
3203 users->updateScrollbar();
3207 return latex.getNumErrors();
3211 int Buffer::runLiterate()
3213 if (!text) return 0;
3217 // get LaTeX-Filename
3218 string name = getLatexName();
3219 // get Literate-Filename
3220 string lit_name = ChangeExtension (getLatexName(),
3221 lyxrc->literate_extension, true);
3223 string path = OnlyPath(filename);
3225 string org_path = path;
3226 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
3230 Path p(path); // path to Literate file
3231 users->owner()->getMiniBuffer()->Set(_("Running Literate..."));
3233 // Remove all error insets
3234 bool a = removeAutoInsets();
3236 // generate the Literate file if necessary
3237 if (!isDviClean() || a) {
3238 makeLaTeXFile(lit_name, org_path, false);
3242 Literate literate(lyxrc->latex_command, name, filepath,
3244 lyxrc->literate_command, lyxrc->literate_error_filter,
3245 lyxrc->build_command, lyxrc->build_error_filter);
3247 int res = literate.weave(terr, users->owner()->getMiniBuffer());
3249 // check return value from literate.weave().
3250 if ((res & Literate::NO_LOGFILE)) {
3251 WriteAlert(_("Literate command did not work!"),
3252 _("Missing log file:"), name);
3253 } else if ((res & Literate::ERRORS)) {
3254 users->owner()->getMiniBuffer()->Set(_("Done"));
3255 // Insert all errors as errors boxes
3258 // Dvi should also be kept dirty if the latex run
3259 // ends up with errors. However it should be possible
3260 // to view a dirty dvi too.
3262 //no errors or any other things to think about so:
3263 users->owner()->getMiniBuffer()->Set(_("Done"));
3267 // if we removed error insets before we ran LaTeX or if we inserted
3268 // error insets after we ran LaTeX this must be run:
3269 if (a || (res & Literate::ERRORS)){
3272 users->updateScrollbar();
3276 return literate.getNumErrors();
3280 int Buffer::buildProgram()
3282 if (!text) return 0;
3286 // get LaTeX-Filename
3287 string name = getLatexName();
3288 // get Literate-Filename
3289 string lit_name = ChangeExtension(getLatexName(),
3290 lyxrc->literate_extension, true);
3292 string path = OnlyPath(filename);
3294 string org_path = path;
3295 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
3299 Path p(path); // path to Literate file
3300 users->owner()->getMiniBuffer()->Set(_("Building Program..."));
3302 // Remove all error insets
3303 bool a = removeAutoInsets();
3305 // generate the LaTeX file if necessary
3306 if (!isNwClean() || a) {
3307 makeLaTeXFile(lit_name, org_path, false);
3311 Literate literate(lyxrc->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
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 (!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 = 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
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 extern void AllFloats(char, char);
3406 void Buffer::insertErrors(TeXErrors & terr)
3408 // Save the cursor position
3409 LyXCursor cursor = text->cursor;
3411 // This is drastic, but it's the only fix, I could find. (Asger)
3415 for (TeXErrors::Errors::const_iterator cit = terr.begin();
3418 string desctext((*cit).error_desc);
3419 string errortext((*cit).error_text);
3420 string msgtxt = desctext + '\n' + errortext;
3421 int errorrow = (*cit).error_in_line;
3423 // Insert error string for row number
3427 texrow.getIdFromRow(errorrow, tmpid, tmppos);
3429 LyXParagraph* texrowpar;
3432 texrowpar = text->FirstParagraph();
3435 texrowpar = text->GetParFromID(tmpid);
3441 InsetError * new_inset = new InsetError(msgtxt);
3443 text->SetCursorIntern(texrowpar, tmppos);
3444 text->InsertInset(new_inset);
3445 text->FullRebreak();
3447 // Restore the cursor position
3448 text->SetCursorIntern(cursor.par, cursor.pos);
3452 void Buffer::setCursorFromRow (int row)
3457 texrow.getIdFromRow(row, tmpid, tmppos);
3459 LyXParagraph* texrowpar;
3462 texrowpar = text->FirstParagraph();
3465 texrowpar = text->GetParFromID(tmpid);
3467 text->SetCursor(texrowpar, tmppos);
3471 void Buffer::RoffAsciiTable(ostream & os, LyXParagraph * par)
3473 LyXFont font1 = LyXFont(LyXFont::ALL_INHERIT);
3476 LyXParagraph::size_type i;
3480 string fname1 = TmpFileName(string(), "RAT1");
3481 string fname2 = TmpFileName(string(), "RAT2");
3483 ofstream ofs(fname1.c_str());
3485 WriteAlert(_("LYX_ERROR:"),
3486 _("Cannot open temporary file:"), fname1);
3489 par->table->RoffEndOfCell(ofs, -1);
3490 for (i = 0; i < par->size(); ++i) {
3491 c = par->GetChar(i);
3492 if (par->table->IsContRow(cell)) {
3493 if (c == LyXParagraph::META_NEWLINE)
3497 font2 = par->GetFontSettings(i);
3498 if (font1.latex() != font2.latex()) {
3499 if (font2.latex() != LyXFont::OFF)
3503 case LyXParagraph::META_INSET:
3504 if ((inset = par->GetInset(i))) {
3505 fstream fs(fname2.c_str(), ios::in|ios::out);
3507 WriteAlert(_("LYX_ERROR:"),
3508 _("Cannot open temporary file:"), fname2);
3510 remove(fname1.c_str());
3513 inset->Latex(fs, -1);
3526 case LyXParagraph::META_NEWLINE:
3527 if (par->table->CellHasContRow(cell)>= 0)
3528 par->RoffContTableRows(ofs, i+1, cell);
3529 par->table->RoffEndOfCell(ofs, cell);
3532 case LyXParagraph::META_HFILL:
3534 case LyXParagraph::META_PROTECTED_SEPARATOR:
3544 << "RoffAsciiTable:"
3545 " NULL char in structure." << endl;
3549 par->table->RoffEndOfCell(ofs, cell);
3551 string cmd = lyxrc->ascii_roff_command + " >" + fname2;
3552 cmd = subst(cmd, "$$FName", fname1);
3553 Systemcalls one(Systemcalls::System, cmd);
3554 if (!(lyxerr.debugging(Debug::ROFF))) {
3555 remove(fname1.c_str());
3557 ifstream ifs(fname2.c_str());
3559 WriteFSAlert(_("Error! Can't open temporary file:"), fname2);
3562 // now output the produced file
3566 WriteAlert(_("Error!"),
3567 _("Error executing *roff command on table"));
3568 // overread leading blank lines
3569 while(!ifs && (c == '\n'))
3572 for(j = 0; j < par->depth; ++j)
3574 while(!ifs && (c != '\n')) {
3579 // overread trailing blank lines
3580 while(!ifs && (c == '\n'))
3584 remove(fname2.c_str());
3588 /// changed Heinrich Bauer, 23/03/98
3589 bool Buffer::isDviClean()
3591 if (lyxrc->use_tempdir)
3592 return dvi_clean_tmpd;
3594 return dvi_clean_orgd;
3598 /// changed Heinrich Bauer, 23/03/98
3599 void Buffer::markDviClean()
3601 if (lyxrc->use_tempdir)
3602 dvi_clean_tmpd = true;
3604 dvi_clean_orgd = true;
3608 /// changed Heinrich Bauer, 23/03/98
3609 void Buffer::markDviDirty()
3611 if (lyxrc->use_tempdir)
3612 dvi_clean_tmpd = false;
3614 dvi_clean_orgd = false;
3618 void Buffer::update(signed char f)
3622 users->owner()->updateLayoutChoice();
3624 if (!text->selection && f > -3)
3625 text->sel_cursor = text->cursor;
3628 text->FullRebreak();
3631 if (f != 3 && f != -3) {
3633 users->updateScrollbar();
3636 if (f == 1 || f == -1) {
3639 users->owner()->getMiniBuffer()->setTimer(4);
3647 void Buffer::validate(LaTeXFeatures & features)
3649 LyXParagraph * par = paragraph;
3650 LyXTextClass const & tclass =
3651 textclasslist.TextClass(params.textclass);
3653 // AMS Style is at document level
3655 features.amsstyle = (params.use_amsmath ||
3656 tclass.provides(LyXTextClass::amsmath));
3659 // We don't use "lyxerr.debug" because of speed. (Asger)
3660 if (lyxerr.debugging(Debug::LATEX))
3661 lyxerr << "Paragraph: " << par << endl;
3663 // Now just follow the list of paragraphs and run
3664 // validate on each of them.
3665 par->validate(features);
3667 // and then the next paragraph
3671 // the bullet shapes are buffer level not paragraph level
3672 // so they are tested here
3673 for (int i = 0; i < 4; ++i) {
3674 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
3675 int font = params.user_defined_bullets[i].getFont();
3678 .user_defined_bullets[i]
3685 features.latexsym = true;
3689 features.amssymb = true;
3691 else if ((font >= 2 && font <= 5)) {
3692 features.pifont = true;
3697 if (lyxerr.debugging(Debug::LATEX)) {
3698 features.showStruct(params);
3703 void Buffer::setPaperStuff()
3705 params.papersize = BufferParams::PAPER_DEFAULT;
3706 char c1 = params.paperpackage;
3707 if (c1 == BufferParams::PACKAGE_NONE) {
3708 char c2 = params.papersize2;
3709 if (c2 == BufferParams::VM_PAPER_USLETTER)
3710 params.papersize = BufferParams::PAPER_USLETTER;
3711 else if (c2 == BufferParams::VM_PAPER_USLEGAL)
3712 params.papersize = BufferParams::PAPER_LEGALPAPER;
3713 else if (c2 == BufferParams::VM_PAPER_USEXECUTIVE)
3714 params.papersize = BufferParams::PAPER_EXECUTIVEPAPER;
3715 else if (c2 == BufferParams::VM_PAPER_A3)
3716 params.papersize = BufferParams::PAPER_A3PAPER;
3717 else if (c2 == BufferParams::VM_PAPER_A4)
3718 params.papersize = BufferParams::PAPER_A4PAPER;
3719 else if (c2 == BufferParams::VM_PAPER_A5)
3720 params.papersize = BufferParams::PAPER_A5PAPER;
3721 else if ((c2 == BufferParams::VM_PAPER_B3) || (c2 == BufferParams::VM_PAPER_B4) ||
3722 (c2 == BufferParams::VM_PAPER_B5))
3723 params.papersize = BufferParams::PAPER_B5PAPER;
3724 } else if ((c1 == BufferParams::PACKAGE_A4) || (c1 == BufferParams::PACKAGE_A4WIDE) ||
3725 (c1 == BufferParams::PACKAGE_WIDEMARGINSA4))
3726 params.papersize = BufferParams::PAPER_A4PAPER;
3731 void Buffer::setOldPaperStuff()
3733 char c = params.papersize = params.papersize2;
3734 params.papersize2 = BufferParams::VM_PAPER_DEFAULT;
3735 params.paperpackage = BufferParams::PACKAGE_NONE;
3736 if (c == OLD_PAPER_A4PAPER)
3737 params.papersize2 = BufferParams::VM_PAPER_A4;
3738 else if (c == OLD_PAPER_A4)
3739 params.paperpackage = BufferParams::PACKAGE_A4;
3740 else if (c == OLD_PAPER_A4WIDE)
3741 params.paperpackage = BufferParams::PACKAGE_A4WIDE;
3742 else if (c == OLD_PAPER_WIDEMARGINSA4)
3743 params.paperpackage = BufferParams::PACKAGE_WIDEMARGINSA4;
3744 else if (c == OLD_PAPER_USLETTER)
3745 params.papersize2 = BufferParams::VM_PAPER_USLETTER;
3746 else if (c == OLD_PAPER_A5PAPER)
3747 params.papersize2 = BufferParams::VM_PAPER_A5;
3748 else if (c == OLD_PAPER_B5PAPER)
3749 params.papersize2 = BufferParams::VM_PAPER_B5;
3750 else if (c == OLD_PAPER_EXECUTIVEPAPER)
3751 params.papersize2 = BufferParams::VM_PAPER_USEXECUTIVE;
3752 else if (c == OLD_PAPER_LEGALPAPER)
3753 params.papersize2 = BufferParams::VM_PAPER_USLEGAL;
3758 void Buffer::insertInset(Inset * inset, string const & lout,
3761 // check for table/list in tables
3762 if (no_table && text->cursor.par->table){
3763 WriteAlert(_("Impossible Operation!"),
3764 _("Cannot insert table/list in table."),
3768 // not quite sure if we want this...
3769 text->SetCursorParUndo();
3773 if (!lout.empty()) {
3775 text->BreakParagraph();
3778 if (text->cursor.par->Last()) {
3781 text->BreakParagraph();
3785 int lay = textclasslist.NumberOfLayout(params.textclass,
3787 if (lay == -1) // layout not found
3788 // use default layout "Standard" (0)
3791 text->SetLayout(lay);
3793 text->SetParagraph(0, 0,
3795 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3801 text->current_font.setLatex(LyXFont::OFF);
3804 text->InsertInset(inset);
3807 text->UnFreezeUndo();
3811 // Open and lock an updatable inset
3812 void Buffer::open_new_inset(UpdatableInset * new_inset)
3816 insertInset(new_inset);
3819 new_inset->Edit(0, 0);
3823 /* This function should be in Buffer because it's a buffer's property (ale) */
3824 string Buffer::getIncludeonlyList(char delim)
3827 LyXParagraph * par = paragraph;
3828 LyXParagraph::size_type pos;
3832 while ((inset = par->ReturnNextInsetPointer(pos))){
3833 if (inset->LyxCode() == Inset::INCLUDE_CODE) {
3834 InsetInclude * insetinc =
3835 static_cast<InsetInclude*>(inset);
3836 if (insetinc->isInclude()
3837 && insetinc->isNoLoad()) {
3840 lst += ChangeExtension(insetinc->getContents(), string(), true);
3847 lyxerr.debug() << "Includeonly(" << lst << ')' << endl;
3852 /* This is also a buffer property (ale) */
3853 string Buffer::getReferenceList(char delim)
3855 /// if this is a child document and the parent is already loaded
3856 /// Use the parent's list instead [ale990407]
3857 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3858 Buffer *tmp = bufferlist.getBuffer(params.parentname);
3860 return tmp->getReferenceList(delim);
3863 LyXParagraph *par = paragraph;
3864 LyXParagraph::size_type pos;
3869 while ((inset = par->ReturnNextInsetPointer(pos))){
3870 for (int i = 0; i < inset->GetNumberOfLabels(); i++) {
3873 lst += inset->getLabel(i);
3879 lyxerr.debug() << "References(" << lst << ")" << endl;
3884 /* This is also a buffer property (ale) */
3885 string Buffer::getBibkeyList(char delim)
3887 /// if this is a child document and the parent is already loaded
3888 /// Use the parent's list instead [ale990412]
3889 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3890 Buffer *tmp = bufferlist.getBuffer(params.parentname);
3892 return tmp->getBibkeyList(delim);
3896 LyXParagraph * par = paragraph;
3899 if (!bibkeys.empty())
3901 bibkeys += par->bibkey->getContents();
3906 // Might be either using bibtex or a child has bibliography
3907 if (bibkeys.empty()) {
3911 LyXParagraph::size_type pos = -1;
3913 // Search for Bibtex or Include inset
3914 while ((inset = par->ReturnNextInsetPointer(pos))) {
3915 if (inset-> LyxCode() == Inset::BIBTEX_CODE) {
3916 if (!bibkeys.empty())
3918 bibkeys += static_cast<InsetBibtex*>(inset)->getKeys();
3919 } else if (inset-> LyxCode() == Inset::INCLUDE_CODE) {
3920 string bk = static_cast<InsetInclude*>(inset)->getKeys();
3922 if (!bibkeys.empty())
3933 lyxerr.debug() << "Bibkeys(" << bibkeys << ")" << endl;
3938 /* This is also a buffer property (ale) */
3939 // Not so sure about that. a goto Label function can not be buffer local, just
3940 // think how this will work in a multiwindo/buffer environment, all the
3941 // cursors in all the views showing this buffer will move. (Lgb)
3942 // OK, then no cursor action should be allowed in buffer. (ale)
3943 bool Buffer::gotoLabel(string const & label)
3946 LyXParagraph * par = paragraph;
3947 LyXParagraph::size_type pos;
3951 while ((inset = par->ReturnNextInsetPointer(pos))){
3952 for (int i = 0; i < inset->GetNumberOfLabels(); i++) {
3953 if (label == inset->getLabel(i)) {
3955 text->SetCursor(par, pos);
3956 text->sel_cursor = text->cursor;
3969 bool Buffer::isDepClean(string const & name) const
3971 DEPCLEAN * item = dep_clean;
3972 while (item && item->master != name)
3974 if (!item) return true;
3979 void Buffer::markDepClean(string const & name)
3982 dep_clean = new DEPCLEAN;
3983 dep_clean->clean = true;
3984 dep_clean->master = name;
3985 dep_clean->next = 0;
3987 DEPCLEAN* item = dep_clean;
3988 while (item && item->master != name)
3993 item = new DEPCLEAN;
3995 item->master = name;