1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2001 The LyX Team.
9 * This file is Copyright 1996-2001
12 * ======================================================
18 #pragma implementation
22 #include "bufferlist.h"
24 #include "LyXAction.h"
27 #include "tex-strings.h"
29 #include "bufferview_funcs.h"
36 #include "LaTeXFeatures.h"
43 #include "converter.h"
44 #include "BufferView.h"
45 #include "ParagraphParameters.h"
46 #include "iterators.h"
47 #include "lyxtextclasslist.h"
49 #include "mathed/formulamacro.h"
50 #include "mathed/formula.h"
52 #include "insets/inset.h"
53 #include "insets/inseterror.h"
54 #include "insets/insetlabel.h"
55 #include "insets/insetref.h"
56 #include "insets/inseturl.h"
57 #include "insets/insetnote.h"
58 #include "insets/insetquotes.h"
59 #include "insets/insetlatexaccent.h"
60 #include "insets/insetbib.h"
61 #include "insets/insetcite.h"
62 #include "insets/insetexternal.h"
63 #include "insets/insetindex.h"
64 #include "insets/insetinclude.h"
65 #include "insets/insettoc.h"
66 #include "insets/insetparent.h"
67 #include "insets/insetspecialchar.h"
68 #include "insets/insettext.h"
69 #include "insets/insetert.h"
70 #include "insets/insetgraphics.h"
71 #include "insets/insetfoot.h"
72 #include "insets/insetmarginal.h"
73 #include "insets/insetminipage.h"
74 #include "insets/insetfloat.h"
75 #include "insets/insettabular.h"
77 #include "insets/insettheorem.h"
78 #include "insets/insetlist.h"
80 #include "insets/insetcaption.h"
81 #include "insets/insetfloatlist.h"
83 #include "frontends/Dialogs.h"
84 #include "frontends/Alert.h"
86 #include "support/textutils.h"
87 #include "support/filetools.h"
88 #include "support/path.h"
89 #include "support/os.h"
90 #include "support/lyxlib.h"
91 #include "support/FileInfo.h"
92 #include "support/lyxmanip.h"
93 #include "support/lyxalgo.h" // for lyx::count
105 #include <sys/types.h>
122 using std::make_pair;
131 using lyx::textclass_type;
133 // all these externs should eventually be removed.
134 extern BufferList bufferlist;
136 extern LyXAction lyxaction;
140 const int LYX_FORMAT = 220;
144 extern int tex_code_break_column;
147 Buffer::Buffer(string const & file, bool ronly)
148 : paragraph(0), niceFile(true), lyx_clean(true), bak_clean(true),
149 unnamed(false), dep_clean(0), read_only(ronly),
150 filename_(file), users(0)
152 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
154 filepath_ = OnlyPath(file);
159 // read_only = ronly;
163 if (read_only || lyxrc.use_tempdir) {
164 tmppath = CreateBufferTmpDir();
173 lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
174 // here the buffer should take care that it is
175 // saved properly, before it goes into the void.
177 // make sure that views using this buffer
182 if (!tmppath.empty()) {
183 DestroyBufferTmpDir(tmppath);
186 Paragraph * par = paragraph;
189 tmppar = par->next();
197 string const Buffer::getLatexName(bool no_path) const
199 string const name = ChangeExtension(MakeLatexName(fileName()), ".tex");
201 return OnlyFilename(name);
207 pair<Buffer::LogType, string> const Buffer::getLogName(void) const
209 string const filename = getLatexName(false);
211 if (filename.empty())
212 return make_pair(Buffer::latexlog, string());
214 string path = OnlyPath(filename);
216 if (lyxrc.use_tempdir || !IsDirWriteable(path))
219 string const fname = AddName(path,
220 OnlyFilename(ChangeExtension(filename,
223 AddName(path, OnlyFilename(
224 ChangeExtension(filename,
225 formats.extension("literate") + ".out")));
227 // If no Latex log or Build log is newer, show Build log
229 FileInfo const f_fi(fname);
230 FileInfo const b_fi(bname);
233 (!f_fi.exist() || f_fi.getModificationTime() < b_fi.getModificationTime())) {
234 lyxerr[Debug::FILES] << "Log name calculated as : " << bname << endl;
235 return make_pair(Buffer::buildlog, bname);
237 lyxerr[Debug::FILES] << "Log name calculated as : " << fname << endl;
238 return make_pair(Buffer::latexlog, fname);
242 void Buffer::setReadonly(bool flag)
244 if (read_only != flag) {
247 users->owner()->getDialogs()->updateBufferDependent(false);
252 /// Update window titles of all users
253 // Should work on a list
254 void Buffer::updateTitles() const
257 users->owner()->updateWindowTitle();
261 /// Reset autosave timer of all users
262 // Should work on a list
263 void Buffer::resetAutosaveTimers() const
266 users->owner()->resetAutosaveTimer();
270 void Buffer::setFileName(string const & newfile)
272 filename_ = MakeAbsPath(newfile);
273 filepath_ = OnlyPath(filename_);
274 setReadonly(IsFileWriteable(filename_) == 0);
279 // We'll remove this later. (Lgb)
282 string last_inset_read;
284 #ifndef NO_COMPABILITY
287 ErtComp() : active(false), in_tabular(false) {
295 std::stack<ErtComp> ert_stack;
300 #warning And _why_ is this here? (Lgb)
308 // candidate for move to BufferView
309 // (at least some parts in the beginning of the func)
312 // changed to be public and have one parameter
313 // if par = 0 normal behavior
314 // else insert behavior
315 // Returns false if "\the_end" is not read for formats >= 2.13. (Asger)
316 bool Buffer::readLyXformat2(LyXLex & lex, Paragraph * par)
320 #ifndef NO_COMPABILITY
321 ert_comp.contents.erase();
322 ert_comp.active = false;
323 ert_comp.in_tabular = false;
326 Paragraph::depth_type depth = 0;
327 bool the_end_read = false;
329 Paragraph * first_par = 0;
330 LyXFont font(LyXFont::ALL_INHERIT, params.language);
331 if (file_format < 216 && params.language->lang() == "hebrew")
332 font.setLanguage(default_language);
336 par->layout(textclasslist[params.textclass].defaultLayoutName());
338 // We are inserting into an existing document
339 users->text->breakParagraph(users);
340 first_par = users->text->ownerParagraph();
343 // We don't want to adopt the parameters from the
344 // document we insert, so we skip until the text begins:
347 string const pretoken = lex.getString();
348 if (pretoken == "\\layout") {
349 lex.pushToken(pretoken);
357 string const token = lex.getString();
359 if (token.empty()) continue;
361 lyxerr[Debug::PARSER] << "Handling token: `"
362 << token << "'" << endl;
365 parseSingleLyXformat2Token(lex, par, first_par,
373 paragraph = first_par;
375 if (unknown_layouts > 0) {
376 string s = _("Couldn't set the layout for ");
377 if (unknown_layouts == 1) {
378 s += _("one paragraph");
380 s += tostr(unknown_layouts);
381 s += _(" paragraphs");
383 Alert::alert(_("Textclass Loading Error!"), s,
384 _("When reading " + fileName()));
387 if (unknown_tokens > 0) {
388 string s = _("Encountered ");
389 if (unknown_tokens == 1) {
390 s += _("one unknown token");
392 s += tostr(unknown_tokens);
393 s += _(" unknown tokens");
395 Alert::alert(_("Textclass Loading Error!"), s,
396 _("When reading " + fileName()));
403 #ifndef NO_COMPABILITY
404 void Buffer::insertErtContents(Paragraph * par, int & pos, bool set_inactive)
406 if (!ert_comp.contents.empty()) {
407 lyxerr[Debug::INSETS] << "ERT contents:\n'"
408 << ert_comp.contents << "'" << endl;
409 Inset * inset = new InsetERT(params, params.language,
410 ert_comp.contents, true);
411 par->insertInset(pos++, inset, ert_comp.font);
412 ert_comp.contents.erase();
415 ert_comp.active = false;
422 Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
423 Paragraph *& first_par,
424 string const & token, int & pos,
425 Paragraph::depth_type & depth,
429 bool the_end_read = false;
430 #ifndef NO_COMPABILITY
431 #ifndef NO_PEXTRA_REALLY
432 // This is super temporary but is needed to get the compability
433 // mode for minipages work correctly together with new tabulars.
434 static int call_depth;
436 bool checkminipage = false;
437 static Paragraph * minipar = 0;
438 static Paragraph * parBeforeMinipage;
441 if (token[0] != '\\') {
442 #ifndef NO_COMPABILITY
443 if (ert_comp.active) {
444 ert_comp.contents += token;
447 for (string::const_iterator cit = token.begin();
448 cit != token.end(); ++cit) {
449 par->insertChar(pos, (*cit), font);
452 #ifndef NO_COMPABILITY
455 } else if (token == "\\i") {
456 Inset * inset = new InsetLatexAccent;
457 inset->read(this, lex);
458 par->insertInset(pos, inset, font);
460 } else if (token == "\\layout") {
461 #ifndef NO_COMPABILITY
462 ert_comp.in_tabular = false;
464 insertErtContents(par, pos);
467 string layoutname = lex.getString();
469 LyXTextClass const & tclass = textclasslist[params.textclass];
471 if (layoutname.empty()) {
472 layoutname = tclass.defaultLayoutName();
475 bool hasLayout = tclass.hasLayout(layoutname);
477 lyxerr << "Layout '" << layoutname << "' does not"
478 << " exist in textclass '" << tclass.name()
480 lyxerr << "Trying to use default layout instead."
482 layoutname = tclass.defaultLayoutName();
485 #ifndef NO_COMPABILITY
486 if (compare_no_case(layoutname, "latex") == 0) {
487 ert_comp.active = true;
488 ert_comp.font = font;
492 // The is the compability reading of layout caption.
493 // It can be removed in LyX version 1.3.0. (Lgb)
494 if (compare_no_case(layoutname, "caption") == 0) {
495 // We expect that the par we are now working on is
496 // really inside a InsetText inside a InsetFloat.
497 // We also know that captions can only be
498 // one paragraph. (Lgb)
500 // We should now read until the next "\layout"
502 // This is probably not good enough, what if the
503 // caption is the last par in the document (Lgb)
504 istream & ist = lex.getStream();
510 if (prefixIs(line, "\\layout")) {
514 if (prefixIs(line, "\\begin_inset"))
516 if (prefixIs(line, "\\end_inset")) {
527 // Now we should have the whole layout in ss
528 // we should now be able to give this to the
530 ss << "\\end_inset\n";
532 // This seems like a bug in stringstream.
533 // We really should be able to use ss
535 istringstream is(ss.str());
537 tmplex.setStream(is);
538 Inset * inset = new InsetCaption;
539 inset->Read(this, tmplex);
540 par->InsertInset(pos, inset, font);
547 par = new Paragraph(par);
548 par->layout(textclasslist[params.textclass].defaultLayoutName());
551 par->layout(layoutname);
552 // Test whether the layout is obsolete.
553 LyXLayout const & layout =
554 textclasslist[params.textclass][par->layout()];
555 if (!layout.obsoleted_by().empty())
556 par->layout(layout.obsoleted_by());
557 par->params().depth(depth);
558 font = LyXFont(LyXFont::ALL_INHERIT, params.language);
559 if (file_format < 216
560 && params.language->lang() == "hebrew")
561 font.setLanguage(default_language);
566 #ifndef NO_COMPABILITY
567 } else if (token == "\\begin_float") {
568 insertErtContents(par, pos);
569 //insertErtContents(par, pos, false);
570 //ert_stack.push(ert_comp);
571 //ert_comp = ErtComp();
573 // This is the compability reader. It can be removed in
574 // LyX version 1.3.0. (Lgb)
576 string const tmptok = lex.getString();
577 //lyxerr << "old float: " << tmptok << endl;
580 stringstream old_float;
582 if (tmptok == "footnote") {
583 inset = new InsetFoot(params);
584 old_float << "collapsed true\n";
585 } else if (tmptok == "margin") {
586 inset = new InsetMarginal(params);
587 old_float << "collapsed true\n";
588 } else if (tmptok == "fig") {
589 inset = new InsetFloat(params, "figure");
590 old_float << "placement htbp\n"
592 << "collapsed false\n";
593 } else if (tmptok == "tab") {
594 inset = new InsetFloat(params, "table");
595 old_float << "placement htbp\n"
597 << "collapsed false\n";
598 } else if (tmptok == "alg") {
599 inset = new InsetFloat(params, "algorithm");
600 old_float << "placement htbp\n"
602 << "collapsed false\n";
603 } else if (tmptok == "wide-fig") {
604 inset = new InsetFloat(params, "figure");
605 //InsetFloat * tmp = new InsetFloat("figure");
608 old_float << "placement htbp\n"
610 << "collapsed false\n";
611 } else if (tmptok == "wide-tab") {
612 inset = new InsetFloat(params, "table");
613 //InsetFloat * tmp = new InsetFloat("table");
616 old_float << "placement htbp\n"
618 << "collapsed false\n";
622 #ifndef NO_PEXTRA_REALLY
625 return false; // no end read yet
628 // we have to reset the font as in the old format after a float
629 // the font was automatically reset!
630 font = LyXFont(LyXFont::ALL_INHERIT, params.language);
632 // Here we need to check for \end_deeper and handle that
633 // before we do the footnote parsing.
634 // This _is_ a hack! (Lgb)
637 string const tmp = lex.getString();
638 if (tmp == "\\end_deeper") {
639 //lyxerr << "\\end_deeper caught!" << endl;
641 lex.printError("\\end_deeper: "
642 "depth is already null");
647 old_float << tmp << ' ';
652 old_float << lex.getLongString("\\end_float")
653 << "\n\\end_inset\n";
654 //lyxerr << "Float Body:\n" << old_float.str() << endl;
655 // That this does not work seems like a bug
656 // in stringstream. (Lgb)
657 istringstream istr(old_float.str());
659 nylex.setStream(istr);
660 inset->read(this, nylex);
661 par->insertInset(pos, inset, font);
663 insertErtContents(par, pos);
665 } else if (token == "\\begin_deeper") {
667 } else if (token == "\\end_deeper") {
669 lex.printError("\\end_deeper: "
670 "depth is already null");
674 } else if (token == "\\begin_preamble") {
675 params.readPreamble(lex);
676 } else if (token == "\\textclass") {
678 pair<bool, textclass_type> pp =
679 textclasslist.NumberOfClass(lex.getString());
681 params.textclass = pp.second;
683 Alert::alert(string(_("Textclass error")),
684 string(_("The document uses an unknown textclass \"")) +
685 lex.getString() + string("\"."),
686 string(_("LyX will not be able to produce output correctly.")));
687 params.textclass = 0;
689 if (!textclasslist[params.textclass].load()) {
690 // if the textclass wasn't loaded properly
691 // we need to either substitute another
692 // or stop loading the file.
693 // I can substitute but I don't see how I can
694 // stop loading... ideas?? ARRae980418
695 Alert::alert(_("Textclass Loading Error!"),
696 string(_("Can't load textclass ")) +
697 textclasslist[params.textclass].name(),
698 _("-- substituting default"));
699 params.textclass = 0;
701 } else if (token == "\\options") {
703 params.options = lex.getString();
704 } else if (token == "\\language") {
705 params.readLanguage(lex);
706 } else if (token == "\\fontencoding") {
708 } else if (token == "\\inputencoding") {
710 params.inputenc = lex.getString();
711 } else if (token == "\\graphics") {
712 params.readGraphicsDriver(lex);
713 } else if (token == "\\fontscheme") {
715 params.fonts = lex.getString();
716 } else if (token == "\\noindent") {
717 par->params().noindent(true);
718 } else if (token == "\\fill_top") {
719 par->params().spaceTop(VSpace(VSpace::VFILL));
720 } else if (token == "\\fill_bottom") {
721 par->params().spaceBottom(VSpace(VSpace::VFILL));
722 } else if (token == "\\line_top") {
723 par->params().lineTop(true);
724 } else if (token == "\\line_bottom") {
725 par->params().lineBottom(true);
726 } else if (token == "\\pagebreak_top") {
727 par->params().pagebreakTop(true);
728 } else if (token == "\\pagebreak_bottom") {
729 par->params().pagebreakBottom(true);
730 } else if (token == "\\start_of_appendix") {
731 par->params().startOfAppendix(true);
732 } else if (token == "\\paragraph_separation") {
733 int tmpret = lex.findToken(string_paragraph_separation);
736 if (tmpret != LYX_LAYOUT_DEFAULT)
737 params.paragraph_separation =
738 static_cast<BufferParams::PARSEP>(tmpret);
739 } else if (token == "\\defskip") {
741 params.defskip = VSpace(lex.getString());
742 #ifndef NO_COMPABILITY
743 } else if (token == "\\epsfig") { // obsolete
744 // Indeed it is obsolete, but we HAVE to be backwards
745 // compatible until 0.14, because otherwise all figures
746 // in existing documents are irretrivably lost. (Asger)
747 params.readGraphicsDriver(lex);
749 } else if (token == "\\quotes_language") {
750 int tmpret = lex.findToken(string_quotes_language);
753 if (tmpret != LYX_LAYOUT_DEFAULT) {
754 InsetQuotes::quote_language tmpl =
755 InsetQuotes::EnglishQ;
758 tmpl = InsetQuotes::EnglishQ;
761 tmpl = InsetQuotes::SwedishQ;
764 tmpl = InsetQuotes::GermanQ;
767 tmpl = InsetQuotes::PolishQ;
770 tmpl = InsetQuotes::FrenchQ;
773 tmpl = InsetQuotes::DanishQ;
776 params.quotes_language = tmpl;
778 } else if (token == "\\quotes_times") {
780 switch (lex.getInteger()) {
782 params.quotes_times = InsetQuotes::SingleQ;
785 params.quotes_times = InsetQuotes::DoubleQ;
788 } else if (token == "\\papersize") {
789 int tmpret = lex.findToken(string_papersize);
793 params.papersize2 = tmpret;
794 } else if (token == "\\paperpackage") {
795 int tmpret = lex.findToken(string_paperpackages);
798 params.paperpackage = BufferParams::PACKAGE_NONE;
800 params.paperpackage = tmpret;
801 } else if (token == "\\use_geometry") {
803 params.use_geometry = lex.getInteger();
804 } else if (token == "\\use_amsmath") {
806 params.use_amsmath = lex.getInteger();
807 } else if (token == "\\use_natbib") {
809 params.use_natbib = lex.getInteger();
810 } else if (token == "\\use_numerical_citations") {
812 params.use_numerical_citations = lex.getInteger();
813 } else if (token == "\\paperorientation") {
814 int tmpret = lex.findToken(string_orientation);
817 if (tmpret != LYX_LAYOUT_DEFAULT)
818 params.orientation = static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
819 } else if (token == "\\paperwidth") {
821 params.paperwidth = lex.getString();
822 } else if (token == "\\paperheight") {
824 params.paperheight = lex.getString();
825 } else if (token == "\\leftmargin") {
827 params.leftmargin = lex.getString();
828 } else if (token == "\\topmargin") {
830 params.topmargin = lex.getString();
831 } else if (token == "\\rightmargin") {
833 params.rightmargin = lex.getString();
834 } else if (token == "\\bottommargin") {
836 params.bottommargin = lex.getString();
837 } else if (token == "\\headheight") {
839 params.headheight = lex.getString();
840 } else if (token == "\\headsep") {
842 params.headsep = lex.getString();
843 } else if (token == "\\footskip") {
845 params.footskip = lex.getString();
846 } else if (token == "\\paperfontsize") {
848 params.fontsize = strip(lex.getString());
849 } else if (token == "\\papercolumns") {
851 params.columns = lex.getInteger();
852 } else if (token == "\\papersides") {
854 switch (lex.getInteger()) {
856 case 1: params.sides = LyXTextClass::OneSide; break;
857 case 2: params.sides = LyXTextClass::TwoSides; break;
859 } else if (token == "\\paperpagestyle") {
861 params.pagestyle = strip(lex.getString());
862 } else if (token == "\\bullet") {
864 int const index = lex.getInteger();
866 int temp_int = lex.getInteger();
867 params.user_defined_bullets[index].setFont(temp_int);
868 params.temp_bullets[index].setFont(temp_int);
870 temp_int = lex.getInteger();
871 params.user_defined_bullets[index].setCharacter(temp_int);
872 params.temp_bullets[index].setCharacter(temp_int);
874 temp_int = lex.getInteger();
875 params.user_defined_bullets[index].setSize(temp_int);
876 params.temp_bullets[index].setSize(temp_int);
878 string const temp_str = lex.getString();
879 if (temp_str != "\\end_bullet") {
880 // this element isn't really necessary for
881 // parsing but is easier for humans
882 // to understand bullets. Put it back and
883 // set a debug message?
884 lex.printError("\\end_bullet expected, got" + temp_str);
885 //how can I put it back?
887 } else if (token == "\\bulletLaTeX") {
888 // The bullet class should be able to read this.
890 int const index = lex.getInteger();
892 string temp_str = lex.getString();
894 while (temp_str != "\\end_bullet") {
895 // this loop structure is needed when user
896 // enters an empty string since the first
897 // thing returned will be the \\end_bullet
899 // if the LaTeX entry has spaces. Each element
900 // therefore needs to be read in turn
903 temp_str = lex.getString();
906 params.user_defined_bullets[index].setText(sum_str);
907 params.temp_bullets[index].setText(sum_str);
908 } else if (token == "\\secnumdepth") {
910 params.secnumdepth = lex.getInteger();
911 } else if (token == "\\tocdepth") {
913 params.tocdepth = lex.getInteger();
914 } else if (token == "\\spacing") {
916 string const tmp = strip(lex.getString());
917 Spacing::Space tmp_space = Spacing::Default;
919 if (tmp == "single") {
920 tmp_space = Spacing::Single;
921 } else if (tmp == "onehalf") {
922 tmp_space = Spacing::Onehalf;
923 } else if (tmp == "double") {
924 tmp_space = Spacing::Double;
925 } else if (tmp == "other") {
927 tmp_space = Spacing::Other;
928 tmp_val = lex.getFloat();
930 lex.printError("Unknown spacing token: '$$Token'");
932 // Small hack so that files written with klyx will be
935 par->params().spacing(Spacing(tmp_space, tmp_val));
937 params.spacing.set(tmp_space, tmp_val);
939 } else if (token == "\\paragraph_spacing") {
941 string const tmp = strip(lex.getString());
942 if (tmp == "single") {
943 par->params().spacing(Spacing(Spacing::Single));
944 } else if (tmp == "onehalf") {
945 par->params().spacing(Spacing(Spacing::Onehalf));
946 } else if (tmp == "double") {
947 par->params().spacing(Spacing(Spacing::Double));
948 } else if (tmp == "other") {
950 par->params().spacing(Spacing(Spacing::Other,
953 lex.printError("Unknown spacing token: '$$Token'");
955 } else if (token == "\\float_placement") {
957 params.float_placement = lex.getString();
958 } else if (token == "\\family") {
960 font.setLyXFamily(lex.getString());
961 } else if (token == "\\series") {
963 font.setLyXSeries(lex.getString());
964 } else if (token == "\\shape") {
966 font.setLyXShape(lex.getString());
967 } else if (token == "\\size") {
969 font.setLyXSize(lex.getString());
970 #ifndef NO_COMPABILITY
971 } else if (token == "\\latex") {
973 string const tok = lex.getString();
974 if (tok == "no_latex") {
976 insertErtContents(par, pos);
977 } else if (tok == "latex") {
978 ert_comp.active = true;
979 ert_comp.font = font;
980 } else if (tok == "default") {
982 insertErtContents(par, pos);
984 lex.printError("Unknown LaTeX font flag "
988 } else if (token == "\\lang") {
990 string const tok = lex.getString();
991 Language const * lang = languages.getLanguage(tok);
993 font.setLanguage(lang);
995 font.setLanguage(params.language);
996 lex.printError("Unknown language `$$Token'");
998 } else if (token == "\\numeric") {
1000 font.setNumber(font.setLyXMisc(lex.getString()));
1001 } else if (token == "\\emph") {
1003 font.setEmph(font.setLyXMisc(lex.getString()));
1004 } else if (token == "\\bar") {
1006 string const tok = lex.getString();
1007 // This is dirty, but gone with LyX3. (Asger)
1009 font.setUnderbar(LyXFont::ON);
1010 else if (tok == "no")
1011 font.setUnderbar(LyXFont::OFF);
1012 else if (tok == "default")
1013 font.setUnderbar(LyXFont::INHERIT);
1015 lex.printError("Unknown bar font flag "
1017 } else if (token == "\\noun") {
1019 font.setNoun(font.setLyXMisc(lex.getString()));
1020 } else if (token == "\\color") {
1022 font.setLyXColor(lex.getString());
1023 } else if (token == "\\align") {
1024 int tmpret = lex.findToken(string_align);
1025 if (tmpret == -1) ++tmpret;
1026 if (tmpret != LYX_LAYOUT_DEFAULT) { // tmpret != 99 ???
1027 int const tmpret2 = int(pow(2.0, tmpret));
1028 //lyxerr << "Tmpret2 = " << tmpret2 << endl;
1029 par->params().align(LyXAlignment(tmpret2));
1031 } else if (token == "\\added_space_top") {
1033 VSpace value = VSpace(lex.getString());
1034 if ((value.length().len().value() != 0) ||
1035 (value.kind() != VSpace::LENGTH))
1036 par->params().spaceTop(value);
1037 } else if (token == "\\added_space_bottom") {
1039 VSpace value = VSpace(lex.getString());
1040 if ((value.length().len().value() != 0) ||
1041 (value.kind() != VSpace::LENGTH))
1042 par->params().spaceBottom(value);
1043 #ifndef NO_COMPABILITY
1044 #ifndef NO_PEXTRA_REALLY
1045 } else if (token == "\\pextra_type") {
1047 par->params().pextraType(lex.getInteger());
1048 } else if (token == "\\pextra_width") {
1050 par->params().pextraWidth(lex.getString());
1051 } else if (token == "\\pextra_widthp") {
1053 par->params().pextraWidthp(lex.getString());
1054 } else if (token == "\\pextra_alignment") {
1056 par->params().pextraAlignment(lex.getInteger());
1057 } else if (token == "\\pextra_hfill") {
1059 par->params().pextraHfill(lex.getInteger());
1060 } else if (token == "\\pextra_start_minipage") {
1062 par->params().pextraStartMinipage(lex.getInteger());
1065 } else if (token == "\\labelwidthstring") {
1067 par->params().labelWidthString(lex.getString());
1068 // do not delete this token, it is still needed!
1069 } else if (token == "\\end_inset") {
1070 lyxerr << "Solitary \\end_inset. Missing \\begin_inset?.\n"
1071 << "Last inset read was: " << last_inset_read
1073 // Simply ignore this. The insets do not have
1075 // But insets should read it, it is a part of
1076 // the inset isn't it? Lgb.
1077 } else if (token == "\\begin_inset") {
1078 #ifndef NO_COMPABILITY
1079 insertErtContents(par, pos, false);
1080 ert_stack.push(ert_comp);
1081 ert_comp = ErtComp();
1083 readInset(lex, par, pos, font);
1084 #ifndef NO_COMPABILITY
1085 ert_comp = ert_stack.top();
1087 insertErtContents(par, pos);
1089 } else if (token == "\\SpecialChar") {
1090 LyXLayout const & layout =
1091 textclasslist[params.textclass][par->layout()];
1093 // Insets don't make sense in a free-spacing context! ---Kayvan
1094 if (layout.free_spacing || par->isFreeSpacing()) {
1097 string next_token = lex.getString();
1098 if (next_token == "\\-") {
1099 par->insertChar(pos, '-', font);
1100 } else if (next_token == "\\protected_separator"
1101 || next_token == "~") {
1102 par->insertChar(pos, ' ', font);
1104 lex.printError("Token `$$Token' "
1106 "paragraph layout!");
1111 Inset * inset = new InsetSpecialChar;
1112 inset->read(this, lex);
1113 par->insertInset(pos, inset, font);
1116 } else if (token == "\\newline") {
1117 #ifndef NO_COMPABILITY
1118 if (!ert_comp.in_tabular && ert_comp.active) {
1119 ert_comp.contents += char(Paragraph::META_NEWLINE);
1121 // Since we cannot know it this is only a regular
1122 // newline or a tabular cell delimter we have to
1123 // handle the ERT here.
1124 insertErtContents(par, pos, false);
1126 par->insertChar(pos, Paragraph::META_NEWLINE, font);
1130 par->insertChar(pos, Paragraph::META_NEWLINE, font);
1133 } else if (token == "\\LyXTable") {
1134 #ifndef NO_COMPABILITY
1135 ert_comp.in_tabular = true;
1137 Inset * inset = new InsetTabular(*this);
1138 inset->read(this, lex);
1139 par->insertInset(pos, inset, font);
1141 } else if (token == "\\hfill") {
1142 par->insertChar(pos, Paragraph::META_HFILL, font);
1144 } else if (token == "\\protected_separator") { // obsolete
1145 // This is a backward compability thingie. (Lgb)
1146 // Remove it later some time...introduced with fileformat
1148 LyXLayout const & layout =
1149 textclasslist[params.textclass][par->layout()];
1151 if (layout.free_spacing || par->isFreeSpacing()) {
1152 par->insertChar(pos, ' ', font);
1154 Inset * inset = new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
1155 par->insertInset(pos, inset, font);
1158 } else if (token == "\\bibitem") { // ale970302
1160 InsetCommandParams p("bibitem", "dummy");
1161 par->bibkey = new InsetBibKey(p);
1163 par->bibkey->read(this, lex);
1164 } else if (token == "\\backslash") {
1165 #ifndef NO_COMPABILITY
1166 if (ert_comp.active) {
1167 ert_comp.contents += "\\";
1170 par->insertChar(pos, '\\', font);
1172 #ifndef NO_COMPABILITY
1175 } else if (token == "\\the_end") {
1176 #ifndef NO_COMPABILITY
1177 // If we still have some ert active here we have to insert
1178 // it so we don't loose it. (Lgb)
1179 insertErtContents(par, pos);
1181 the_end_read = true;
1182 #ifndef NO_COMPABILITY
1183 #ifndef NO_PEXTRA_REALLY
1186 minipar = parBeforeMinipage = 0;
1190 #ifndef NO_COMPABILITY
1191 if (ert_comp.active) {
1192 ert_comp.contents += token;
1195 // This should be insurance for the future: (Asger)
1198 string const s = _("Unknown token: ") + token
1199 + " " + lex.text() + "\n";
1200 // we can do this here this way because we're actually reading
1201 // the buffer and don't care about LyXText right now.
1202 InsetError * new_inset = new InsetError(s);
1203 par->insertInset(pos, new_inset, LyXFont(LyXFont::ALL_INHERIT,
1206 #ifndef NO_COMPABILITY
1211 #ifndef NO_COMPABILITY
1212 #ifndef NO_PEXTRA_REALLY
1213 // I wonder if we could use this blanket fix for all the
1214 // checkminipage cases...
1215 // don't forget about ert paragraphs and compatibility read for'em
1216 if (par && (par->size() || !ert_comp.contents.empty())) {
1217 // It is possible that this will check to often,
1218 // but that should not be an correctness issue.
1219 // Only a speed issue.
1220 checkminipage = true;
1223 // now check if we have a minipage paragraph as at this
1224 // point we already read all the necessary data!
1225 // this cannot be done in layout because there we did
1226 // not read yet the paragraph PEXTRA-params (Jug)
1228 // BEGIN pextra_minipage compability
1229 // This should be removed in 1.3.x (Lgb)
1230 // I don't think we should remove this so fast (Jug)
1232 // This compability code is not perfect. In a couple
1233 // of rand cases it fails. When the minipage par is
1234 // the first par in the document, and when there are
1235 // none or only one regular paragraphs after the
1236 // minipage. Currently I am not investing any effort
1237 // in fixing those cases.
1239 //lyxerr << "Call depth: " << call_depth << endl;
1240 if (checkminipage && (call_depth == 1)) {
1241 checkminipage = false;
1242 if (minipar && (minipar != par) &&
1243 (par->params().pextraType() == Paragraph::PEXTRA_MINIPAGE))
1245 lyxerr << "minipages in a row" << endl;
1246 if (par->params().pextraStartMinipage()) {
1247 lyxerr << "start new minipage" << endl;
1248 // minipages in a row
1249 par->previous()->next(0);
1252 Paragraph * tmp = minipar;
1254 tmp->params().pextraType(0);
1255 tmp->params().pextraWidth(string());
1256 tmp->params().pextraWidthp(string());
1257 tmp->params().pextraAlignment(0);
1258 tmp->params().pextraHfill(false);
1259 tmp->params().pextraStartMinipage(false);
1262 // create a new paragraph to insert the
1263 // minipages in the following case
1264 if (par->params().pextraStartMinipage() &&
1265 !par->params().pextraHfill()) {
1266 Paragraph * p = new Paragraph;
1267 p->layout(textclasslist[params.textclass].defaultLayoutName());
1269 p->previous(parBeforeMinipage);
1270 parBeforeMinipage->next(p);
1272 p->params().depth(parBeforeMinipage->params().depth());
1273 parBeforeMinipage = p;
1275 InsetMinipage * mini = new InsetMinipage(params);
1276 mini->pos(static_cast<InsetMinipage::Position>(par->params().pextraAlignment()));
1277 mini->pageWidth(LyXLength(par->params().pextraWidth()));
1278 if (!par->params().pextraWidthp().empty()) {
1279 lyxerr << "WP:" << mini->pageWidth().asString() << endl;
1280 mini->pageWidth(LyXLength((par->params().pextraWidthp())+"col%"));
1282 Paragraph * op = mini->firstParagraph();
1283 mini->inset.paragraph(par);
1285 // and free the old ones!
1288 Paragraph * pp = op->next();
1292 // Insert the minipage last in the
1293 // previous paragraph.
1294 if (par->params().pextraHfill()) {
1295 parBeforeMinipage->insertChar
1296 (parBeforeMinipage->size(),
1297 Paragraph::META_HFILL, font);
1299 parBeforeMinipage->insertInset
1300 (parBeforeMinipage->size(), mini, font);
1304 lyxerr << "new minipage par" << endl;
1305 //nothing to do just continue reading
1308 } else if (minipar && (minipar != par)) {
1309 lyxerr << "last minipage par read" << endl;
1310 // The last paragraph read was not part of a
1311 // minipage but the par linked list is...
1312 // So we need to remove the last par from the
1314 if (par->previous())
1315 par->previous()->next(0);
1316 par->previous(parBeforeMinipage);
1317 parBeforeMinipage->next(par);
1318 Paragraph * tmp = minipar;
1320 tmp->params().pextraType(0);
1321 tmp->params().pextraWidth(string());
1322 tmp->params().pextraWidthp(string());
1323 tmp->params().pextraAlignment(0);
1324 tmp->params().pextraHfill(false);
1325 tmp->params().pextraStartMinipage(false);
1328 depth = parBeforeMinipage->params().depth();
1329 // and set this depth on the par as it has not been set already
1330 par->params().depth(depth);
1331 minipar = parBeforeMinipage = 0;
1332 } else if (!minipar &&
1333 (par->params().pextraType() == Paragraph::PEXTRA_MINIPAGE))
1335 // par is the first paragraph in a minipage
1336 lyxerr << "begin minipage" << endl;
1337 // To minimize problems for
1338 // the users we will insert
1339 // the first minipage in
1340 // a sequence of minipages
1341 // in its own paragraph.
1342 Paragraph * p = new Paragraph;
1343 p->layout(textclasslist[params.textclass].defaultLayoutName());
1344 p->previous(par->previous());
1346 p->params().depth(depth);
1347 par->params().depth(0);
1349 if (par->previous())
1350 par->previous()->next(p);
1352 parBeforeMinipage = p;
1354 if (!first_par || (first_par == par))
1357 InsetMinipage * mini = new InsetMinipage(params);
1358 mini->pos(static_cast<InsetMinipage::Position>(minipar->params().pextraAlignment()));
1359 mini->pageWidth(LyXLength(minipar->params().pextraWidth()));
1360 if (!par->params().pextraWidthp().empty()) {
1361 lyxerr << "WP:" << mini->pageWidth().asString() << endl;
1362 mini->pageWidth(LyXLength((par->params().pextraWidthp())+"col%"));
1365 Paragraph * op = mini->firstParagraph();
1366 mini->inset.paragraph(minipar);
1368 // and free the old ones!
1371 Paragraph * pp = op->next();
1376 // Insert the minipage last in the
1377 // previous paragraph.
1378 if (minipar->params().pextraHfill()) {
1379 parBeforeMinipage->insertChar
1380 (parBeforeMinipage->size(),
1381 Paragraph::META_HFILL, font);
1383 parBeforeMinipage->insertInset
1384 (parBeforeMinipage->size(), mini, font);
1387 // End of pextra_minipage compability
1391 return the_end_read;
1394 // needed to insert the selection
1395 void Buffer::insertStringAsLines(Paragraph *& par, pos_type & pos,
1396 LyXFont const & fn,string const & str) const
1398 LyXLayout const & layout =
1399 textclasslist[params.textclass][par->layout()];
1402 par->checkInsertChar(font);
1403 // insert the string, don't insert doublespace
1404 bool space_inserted = true;
1405 bool autobreakrows = !par->inInset() ||
1406 static_cast<InsetText *>(par->inInset())->getAutoBreakRows();
1407 for(string::const_iterator cit = str.begin();
1408 cit != str.end(); ++cit) {
1410 if (autobreakrows && (par->size() || layout.keepempty)) {
1411 par->breakParagraph(params, pos,
1412 layout.isEnvironment());
1415 space_inserted = true;
1419 // do not insert consecutive spaces if !free_spacing
1420 } else if ((*cit == ' ' || *cit == '\t') &&
1421 space_inserted && !layout.free_spacing &&
1422 !par->isFreeSpacing())
1425 } else if (*cit == '\t') {
1426 if (!layout.free_spacing && !par->isFreeSpacing()) {
1427 // tabs are like spaces here
1428 par->insertChar(pos, ' ', font);
1430 space_inserted = true;
1432 const pos_type nb = 8 - pos % 8;
1433 for (pos_type a = 0; a < nb ; ++a) {
1434 par->insertChar(pos, ' ', font);
1437 space_inserted = true;
1439 } else if (!IsPrintable(*cit)) {
1440 // Ignore unprintables
1443 // just insert the character
1444 par->insertChar(pos, *cit, font);
1446 space_inserted = (*cit == ' ');
1453 void Buffer::readInset(LyXLex & lex, Paragraph *& par,
1454 int & pos, LyXFont & font)
1456 // consistency check
1457 if (lex.getString() != "\\begin_inset") {
1458 lyxerr << "Buffer::readInset: Consistency check failed."
1465 string const tmptok = lex.getString();
1466 last_inset_read = tmptok;
1468 // test the different insets
1469 if (tmptok == "LatexCommand") {
1470 InsetCommandParams inscmd;
1473 string const cmdName = inscmd.getCmdName();
1475 // This strange command allows LyX to recognize "natbib" style
1476 // citations: citet, citep, Citet etc.
1477 if (compare_no_case(cmdName, "cite", 4) == 0) {
1478 inset = new InsetCitation(inscmd);
1479 } else if (cmdName == "bibitem") {
1480 lex.printError("Wrong place for bibitem");
1481 inset = new InsetBibKey(inscmd);
1482 } else if (cmdName == "BibTeX") {
1483 inset = new InsetBibtex(inscmd);
1484 } else if (cmdName == "index") {
1485 inset = new InsetIndex(inscmd);
1486 } else if (cmdName == "include") {
1487 inset = new InsetInclude(inscmd, *this);
1488 } else if (cmdName == "label") {
1489 inset = new InsetLabel(inscmd);
1490 } else if (cmdName == "url"
1491 || cmdName == "htmlurl") {
1492 inset = new InsetUrl(inscmd);
1493 } else if (cmdName == "ref"
1494 || cmdName == "pageref"
1495 || cmdName == "vref"
1496 || cmdName == "vpageref"
1497 || cmdName == "prettyref") {
1498 if (!inscmd.getOptions().empty()
1499 || !inscmd.getContents().empty()) {
1500 inset = new InsetRef(inscmd, *this);
1502 } else if (cmdName == "tableofcontents") {
1503 inset = new InsetTOC(inscmd);
1504 } else if (cmdName == "listofalgorithms") {
1505 inset = new InsetFloatList("algorithm");
1506 } else if (cmdName == "listoffigures") {
1507 inset = new InsetFloatList("figure");
1508 } else if (cmdName == "listoftables") {
1509 inset = new InsetFloatList("table");
1510 } else if (cmdName == "printindex") {
1511 inset = new InsetPrintIndex(inscmd);
1512 } else if (cmdName == "lyxparent") {
1513 inset = new InsetParent(inscmd, *this);
1516 bool alreadyread = false;
1517 if (tmptok == "Quotes") {
1518 inset = new InsetQuotes;
1519 } else if (tmptok == "External") {
1520 inset = new InsetExternal;
1521 } else if (tmptok == "FormulaMacro") {
1522 inset = new InsetFormulaMacro;
1523 } else if (tmptok == "Formula") {
1524 inset = new InsetFormula;
1525 } else if (tmptok == "Figure") { // Backward compatibility
1526 // inset = new InsetFig(100, 100, *this);
1527 inset = new InsetGraphics;
1528 } else if (tmptok == "Graphics") {
1529 inset = new InsetGraphics;
1530 } else if (tmptok == "Info") {// backwards compatibility
1531 inset = new InsetNote(this,
1532 lex.getLongString("\\end_inset"),
1535 } else if (tmptok == "Note") {
1536 inset = new InsetNote(params);
1537 } else if (tmptok == "Include") {
1538 InsetCommandParams p("Include");
1539 inset = new InsetInclude(p, *this);
1540 } else if (tmptok == "ERT") {
1541 inset = new InsetERT(params);
1542 } else if (tmptok == "Tabular") {
1543 inset = new InsetTabular(*this);
1544 } else if (tmptok == "Text") {
1545 inset = new InsetText(params);
1546 } else if (tmptok == "Foot") {
1547 inset = new InsetFoot(params);
1548 } else if (tmptok == "Marginal") {
1549 inset = new InsetMarginal(params);
1550 } else if (tmptok == "Minipage") {
1551 inset = new InsetMinipage(params);
1552 } else if (tmptok == "Float") {
1554 string tmptok = lex.getString();
1555 inset = new InsetFloat(params, tmptok);
1557 } else if (tmptok == "List") {
1558 inset = new InsetList;
1559 } else if (tmptok == "Theorem") {
1560 inset = new InsetList;
1562 } else if (tmptok == "Caption") {
1563 inset = new InsetCaption(params);
1564 } else if (tmptok == "FloatList") {
1565 inset = new InsetFloatList;
1568 if (inset && !alreadyread) inset->read(this, lex);
1572 par->insertInset(pos, inset, font);
1578 bool Buffer::readFile(LyXLex & lex, Paragraph * par)
1582 string const token(lex.getString());
1583 if (token == "\\lyxformat") { // the first token _must_ be...
1585 string tmp_format = lex.getString();
1586 //lyxerr << "LyX Format: `" << tmp_format << "'" << endl;
1587 // if present remove ".," from string.
1588 string::size_type dot = tmp_format.find_first_of(".,");
1589 //lyxerr << " dot found at " << dot << endl;
1590 if (dot != string::npos)
1591 tmp_format.erase(dot, 1);
1592 file_format = strToInt(tmp_format);
1593 if (file_format == LYX_FORMAT) {
1595 } else if (file_format > LYX_FORMAT) {
1597 Alert::alert(_("Warning!"),
1598 _("LyX file format is newer that what"),
1599 _("is supported in this LyX version. Expect some problems."));
1601 } else if (file_format < LYX_FORMAT) {
1603 if (file_format < 200) {
1604 Alert::alert(_("ERROR!"),
1605 _("Old LyX file format found. "
1606 "Use LyX 0.10.x to read this!"));
1610 bool the_end = readLyXformat2(lex, par);
1611 params.setPaperStuff();
1612 // the_end was added in 213
1613 if (file_format < 213)
1617 Alert::alert(_("Warning!"),
1618 _("Reading of document is not complete"),
1619 _("Maybe the document is truncated"));
1622 } else { // "\\lyxformat" not found
1623 Alert::alert(_("ERROR!"), _("Not a LyX file!"));
1626 Alert::alert(_("ERROR!"), _("Unable to read file!"));
1631 // Should probably be moved to somewhere else: BufferView? LyXView?
1632 bool Buffer::save() const
1634 // We don't need autosaves in the immediate future. (Asger)
1635 resetAutosaveTimers();
1639 if (lyxrc.make_backup) {
1640 s = fileName() + '~';
1641 if (!lyxrc.backupdir_path.empty())
1642 s = AddName(lyxrc.backupdir_path,
1643 subst(os::slashify_path(s),'/','!'));
1645 // Rename is the wrong way of making a backup,
1646 // this is the correct way.
1647 /* truss cp fil fil2:
1648 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
1649 stat("LyXVC.lyx", 0xEFFFF688) = 0
1650 open("LyXVC.lyx", O_RDONLY) = 3
1651 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
1652 fstat(4, 0xEFFFF508) = 0
1653 fstat(3, 0xEFFFF508) = 0
1654 read(3, " # T h i s f i l e w".., 8192) = 5579
1655 write(4, " # T h i s f i l e w".., 5579) = 5579
1656 read(3, 0xEFFFD4A0, 8192) = 0
1659 chmod("LyXVC3.lyx", 0100644) = 0
1660 lseek(0, 0, SEEK_CUR) = 46440
1664 // Should probably have some more error checking here.
1665 // Should be cleaned up in 0.13, at least a bit.
1666 // Doing it this way, also makes the inodes stay the same.
1667 // This is still not a very good solution, in particular we
1668 // might loose the owner of the backup.
1669 FileInfo finfo(fileName());
1670 if (finfo.exist()) {
1671 mode_t fmode = finfo.getMode();
1672 struct utimbuf times = {
1673 finfo.getAccessTime(),
1674 finfo.getModificationTime() };
1676 ifstream ifs(fileName().c_str());
1677 ofstream ofs(s.c_str(), ios::out|ios::trunc);
1682 ::chmod(s.c_str(), fmode);
1684 if (::utime(s.c_str(), ×)) {
1685 lyxerr << "utime error." << endl;
1688 lyxerr << "LyX was not able to make "
1689 "backup copy. Beware." << endl;
1694 if (writeFile(fileName(), false)) {
1696 removeAutosaveFile(fileName());
1698 // Saving failed, so backup is not backup
1699 if (lyxrc.make_backup) {
1700 lyx::rename(s, fileName());
1708 // Returns false if unsuccesful
1709 bool Buffer::writeFile(string const & fname, bool flag) const
1711 // if flag is false writeFile will not create any GUI
1712 // warnings, only cerr.
1713 // Needed for autosave in background or panic save (Matthias 120496)
1715 if (read_only && (fname == fileName())) {
1716 // Here we should come with a question if we should
1717 // perform the write anyway.
1719 lyxerr << _("Error! Document is read-only: ")
1722 Alert::alert(_("Error! Document is read-only: "),
1727 FileInfo finfo(fname);
1728 if (finfo.exist() && !finfo.writable()) {
1729 // Here we should come with a question if we should
1730 // try to do the save anyway. (i.e. do a chmod first)
1732 lyxerr << _("Error! Cannot write file: ")
1735 Alert::err_alert(_("Error! Cannot write file: "),
1740 ofstream ofs(fname.c_str());
1743 lyxerr << _("Error! Cannot open file: ")
1746 Alert::err_alert(_("Error! Cannot open file: "),
1752 // Use the standard "C" locale for file output.
1753 ofs.imbue(std::locale::classic());
1756 // The top of the file should not be written by params.
1758 // write out a comment in the top of the file
1759 ofs << '#' << lyx_docversion
1760 << " created this file. For more info see http://www.lyx.org/\n"
1761 << "\\lyxformat " << LYX_FORMAT << "\n";
1763 // now write out the buffer paramters.
1764 params.writeFile(ofs);
1766 Paragraph::depth_type depth = 0;
1768 // this will write out all the paragraphs
1769 // using recursive descent.
1770 paragraph->writeFile(this, ofs, params, depth);
1772 // Write marker that shows file is complete
1773 ofs << "\n\\the_end" << endl;
1777 // how to check if close went ok?
1778 // Following is an attempt... (BE 20001011)
1780 // good() returns false if any error occured, including some
1781 // formatting error.
1782 // bad() returns true if something bad happened in the buffer,
1783 // which should include file system full errors.
1790 lyxerr << "Buffer::writeFile: BAD ERROR!" << endl;
1792 lyxerr << "Buffer::writeFile: NOT SO BAD ERROR!"
1804 pair<int, string> const addDepth(int depth, int ldepth)
1808 d += (ldepth - depth) * 2;
1809 return make_pair(d, string(d, ' '));
1815 string const Buffer::asciiParagraph(Paragraph const * par,
1816 unsigned int linelen,
1817 bool noparbreak) const
1819 ostringstream buffer;
1820 Paragraph::depth_type depth = 0;
1822 Paragraph::depth_type ltype_depth = 0;
1823 bool ref_printed = false;
1824 // if (!par->previous()) {
1826 // begins or ends a deeper area ?
1827 if (depth != par->params().depth()) {
1828 if (par->params().depth() > depth) {
1829 while (par->params().depth() > depth) {
1833 while (par->params().depth() < depth) {
1839 depth = par->params().depth();
1842 // First write the layout
1843 string const & tmp = par->layout();
1844 if (compare_no_case(tmp, "itemize") == 0) {
1846 ltype_depth = depth + 1;
1847 } else if (compare_no_case(tmp, "enumerate") == 0) {
1849 ltype_depth = depth + 1;
1850 } else if (contains(lowercase(tmp), "ection")) {
1852 ltype_depth = depth + 1;
1853 } else if (contains(lowercase(tmp), "aragraph")) {
1855 ltype_depth = depth + 1;
1856 } else if (compare_no_case(tmp, "description") == 0) {
1858 ltype_depth = depth + 1;
1859 } else if (compare_no_case(tmp, "abstract") == 0) {
1862 } else if (compare_no_case(tmp, "bibliography") == 0) {
1870 /* maybe some vertical spaces */
1872 /* the labelwidthstring used in lists */
1876 /* some pagebreaks? */
1880 /* what about the alignment */
1882 // lyxerr << "Should this ever happen?" << endl;
1885 // linelen <= 0 is special and means we don't have pargraph breaks
1887 string::size_type currlinelen = 0;
1893 buffer << string(depth * 2, ' ');
1894 currlinelen += depth * 2;
1897 // we should probably change to the paragraph language in the
1898 // gettext here (if possible) so that strings are outputted in
1899 // the correct language! (20012712 Jug)
1903 case 4: // (Sub)Paragraph
1904 case 5: // Description
1908 buffer << _("Abstract") << "\n\n";
1911 string const abst = _("Abstract: ");
1913 currlinelen += abst.length();
1916 case 7: // Bibliography
1919 buffer << _("References") << "\n\n";
1922 string const refs = _("References: ");
1924 currlinelen += refs.length();
1932 string const parlab = par->params().labelString();
1933 buffer << parlab << " ";
1934 currlinelen += parlab.length() + 1;
1942 pair<int, string> p = addDepth(depth, ltype_depth);
1944 currlinelen += p.first;
1947 // this is to change the linebreak to do it by word a bit more
1948 // intelligent hopefully! (only in the case where we have a
1949 // max linelenght!) (Jug)
1953 for (pos_type i = 0; i < par->size(); ++i) {
1954 char c = par->getUChar(params, i);
1956 case Paragraph::META_INSET:
1958 Inset const * inset = par->getInset(i);
1962 currlinelen += word.length();
1965 if (inset->ascii(this, buffer, linelen)) {
1966 // to be sure it breaks paragraph
1967 currlinelen += linelen;
1973 case Paragraph::META_NEWLINE:
1975 buffer << word << "\n";
1978 pair<int, string> p = addDepth(depth,
1981 currlinelen = p.first;
1985 case Paragraph::META_HFILL:
1986 buffer << word << "\t";
1987 currlinelen += word.length() + 1;
1994 currlinelen + word.length() > linelen - 10) {
1996 pair<int, string> p =
1997 addDepth(depth, ltype_depth);
1999 currlinelen = p.first;
2002 buffer << word << ' ';
2003 currlinelen += word.length() + 1;
2010 lyxerr[Debug::INFO] <<
2011 "writeAsciiFile: NULL char in structure." << endl;
2013 if ((linelen > 0) &&
2014 (currlinelen + word.length()) > linelen)
2018 pair<int, string> p =
2019 addDepth(depth, ltype_depth);
2021 currlinelen = p.first;
2028 return buffer.str().c_str();
2032 void Buffer::writeFileAscii(string const & fname, int linelen)
2034 ofstream ofs(fname.c_str());
2036 Alert::err_alert(_("Error: Cannot write file:"), fname);
2039 writeFileAscii(ofs, linelen);
2043 void Buffer::writeFileAscii(ostream & ofs, int linelen)
2045 Paragraph * par = paragraph;
2047 ofs << asciiParagraph(par, linelen, par->previous() == 0);
2057 void Buffer::makeLaTeXFile(string const & fname,
2058 string const & original_path,
2059 bool nice, bool only_body)
2061 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
2063 ofstream ofs(fname.c_str());
2065 Alert::err_alert(_("Error: Cannot open file: "), fname);
2069 niceFile = nice; // this will be used by Insetincludes.
2071 tex_code_break_column = lyxrc.ascii_linelen;
2073 // validate the buffer.
2074 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
2075 LaTeXFeatures features(params);
2077 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
2080 // The starting paragraph of the coming rows is the
2081 // first paragraph of the document. (Asger)
2082 texrow.start(paragraph, 0);
2084 if (!only_body && nice) {
2085 ofs << "%% " << lyx_docversion << " created this file. "
2086 "For more info, see http://www.lyx.org/.\n"
2087 "%% Do not edit unless you really know what "
2092 lyxerr[Debug::INFO] << "lyx header finished" << endl;
2093 // There are a few differences between nice LaTeX and usual files:
2094 // usual is \batchmode and has a
2095 // special input@path to allow the including of figures
2096 // with either \input or \includegraphics (what figinsets do).
2097 // batchmode is not set if there is a tex_code_break_column.
2098 // In this case somebody is interested in the generated LaTeX,
2099 // so this is OK. input@path is set when the actual parameter
2100 // original_path is set. This is done for usual tex-file, but not
2101 // for nice-latex-file. (Matthias 250696)
2104 // code for usual, NOT nice-latex-file
2105 ofs << "\\batchmode\n"; // changed
2106 // from \nonstopmode
2109 if (!original_path.empty()) {
2110 string inputpath = os::external_path(original_path);
2111 subst(inputpath, "~", "\\string~");
2112 ofs << "\\makeatletter\n"
2113 << "\\def\\input@path{{"
2114 << inputpath << "/}}\n"
2115 << "\\makeatother\n";
2121 ofs << "\\documentclass";
2123 LyXTextClass const & tclass = textclasslist[params.textclass];
2125 ostringstream options; // the document class options.
2127 if (tokenPos(tclass.opt_fontsize(),
2128 '|', params.fontsize) >= 0) {
2129 // only write if existing in list (and not default)
2130 options << params.fontsize << "pt,";
2134 if (!params.use_geometry &&
2135 (params.paperpackage == BufferParams::PACKAGE_NONE)) {
2136 switch (params.papersize) {
2137 case BufferParams::PAPER_A4PAPER:
2138 options << "a4paper,";
2140 case BufferParams::PAPER_USLETTER:
2141 options << "letterpaper,";
2143 case BufferParams::PAPER_A5PAPER:
2144 options << "a5paper,";
2146 case BufferParams::PAPER_B5PAPER:
2147 options << "b5paper,";
2149 case BufferParams::PAPER_EXECUTIVEPAPER:
2150 options << "executivepaper,";
2152 case BufferParams::PAPER_LEGALPAPER:
2153 options << "legalpaper,";
2159 if (params.sides != tclass.sides()) {
2160 switch (params.sides) {
2161 case LyXTextClass::OneSide:
2162 options << "oneside,";
2164 case LyXTextClass::TwoSides:
2165 options << "twoside,";
2171 if (params.columns != tclass.columns()) {
2172 if (params.columns == 2)
2173 options << "twocolumn,";
2175 options << "onecolumn,";
2178 if (!params.use_geometry
2179 && params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
2180 options << "landscape,";
2182 // language should be a parameter to \documentclass
2184 ostringstream language_options;
2185 if (params.language->babel() == "hebrew"
2186 && default_language->babel() != "hebrew")
2187 // This seems necessary
2188 features.useLanguage(default_language);
2190 if (lyxrc.language_use_babel ||
2191 params.language->lang() != lyxrc.default_language ||
2192 !features.hasLanguages()) {
2194 language_options << features.getLanguages();
2195 language_options << params.language->babel();
2196 if (lyxrc.language_global_options)
2197 options << language_options.str() << ',';
2200 // the user-defined options
2201 if (!params.options.empty()) {
2202 options << params.options << ',';
2205 string strOptions(options.str().c_str());
2206 if (!strOptions.empty()) {
2207 strOptions = strip(strOptions, ',');
2208 ofs << '[' << strOptions << ']';
2211 ofs << '{' << tclass.latexname() << "}\n";
2213 // end of \documentclass defs
2215 // font selection must be done before loading fontenc.sty
2216 // The ae package is not needed when using OT1 font encoding.
2217 if (params.fonts != "default" &&
2218 (params.fonts != "ae" || lyxrc.fontenc != "default")) {
2219 ofs << "\\usepackage{" << params.fonts << "}\n";
2221 if (params.fonts == "ae") {
2222 ofs << "\\usepackage{aecompl}\n";
2226 // this one is not per buffer
2227 if (lyxrc.fontenc != "default") {
2228 ofs << "\\usepackage[" << lyxrc.fontenc
2233 if (params.inputenc == "auto") {
2234 string const doc_encoding =
2235 params.language->encoding()->LatexName();
2237 // Create a list with all the input encodings used
2239 set<string> encodings = features.getEncodingSet(doc_encoding);
2241 ofs << "\\usepackage[";
2242 std::copy(encodings.begin(), encodings.end(),
2243 std::ostream_iterator<string>(ofs, ","));
2244 ofs << doc_encoding << "]{inputenc}\n";
2246 } else if (params.inputenc != "default") {
2247 ofs << "\\usepackage[" << params.inputenc
2252 // At the very beginning the text parameters.
2253 if (params.paperpackage != BufferParams::PACKAGE_NONE) {
2254 switch (params.paperpackage) {
2255 case BufferParams::PACKAGE_A4:
2256 ofs << "\\usepackage{a4}\n";
2259 case BufferParams::PACKAGE_A4WIDE:
2260 ofs << "\\usepackage{a4wide}\n";
2263 case BufferParams::PACKAGE_WIDEMARGINSA4:
2264 ofs << "\\usepackage[widemargins]{a4}\n";
2269 if (params.use_geometry) {
2270 ofs << "\\usepackage{geometry}\n";
2272 ofs << "\\geometry{verbose";
2273 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
2274 ofs << ",landscape";
2275 switch (params.papersize2) {
2276 case BufferParams::VM_PAPER_CUSTOM:
2277 if (!params.paperwidth.empty())
2278 ofs << ",paperwidth="
2279 << params.paperwidth;
2280 if (!params.paperheight.empty())
2281 ofs << ",paperheight="
2282 << params.paperheight;
2284 case BufferParams::VM_PAPER_USLETTER:
2285 ofs << ",letterpaper";
2287 case BufferParams::VM_PAPER_USLEGAL:
2288 ofs << ",legalpaper";
2290 case BufferParams::VM_PAPER_USEXECUTIVE:
2291 ofs << ",executivepaper";
2293 case BufferParams::VM_PAPER_A3:
2296 case BufferParams::VM_PAPER_A4:
2299 case BufferParams::VM_PAPER_A5:
2302 case BufferParams::VM_PAPER_B3:
2305 case BufferParams::VM_PAPER_B4:
2308 case BufferParams::VM_PAPER_B5:
2312 // default papersize ie BufferParams::VM_PAPER_DEFAULT
2313 switch (lyxrc.default_papersize) {
2314 case BufferParams::PAPER_DEFAULT: // keep compiler happy
2315 case BufferParams::PAPER_USLETTER:
2316 ofs << ",letterpaper";
2318 case BufferParams::PAPER_LEGALPAPER:
2319 ofs << ",legalpaper";
2321 case BufferParams::PAPER_EXECUTIVEPAPER:
2322 ofs << ",executivepaper";
2324 case BufferParams::PAPER_A3PAPER:
2327 case BufferParams::PAPER_A4PAPER:
2330 case BufferParams::PAPER_A5PAPER:
2333 case BufferParams::PAPER_B5PAPER:
2338 if (!params.topmargin.empty())
2339 ofs << ",tmargin=" << params.topmargin;
2340 if (!params.bottommargin.empty())
2341 ofs << ",bmargin=" << params.bottommargin;
2342 if (!params.leftmargin.empty())
2343 ofs << ",lmargin=" << params.leftmargin;
2344 if (!params.rightmargin.empty())
2345 ofs << ",rmargin=" << params.rightmargin;
2346 if (!params.headheight.empty())
2347 ofs << ",headheight=" << params.headheight;
2348 if (!params.headsep.empty())
2349 ofs << ",headsep=" << params.headsep;
2350 if (!params.footskip.empty())
2351 ofs << ",footskip=" << params.footskip;
2356 if (tokenPos(tclass.opt_pagestyle(),
2357 '|', params.pagestyle) >= 0) {
2358 if (params.pagestyle == "fancy") {
2359 ofs << "\\usepackage{fancyhdr}\n";
2362 ofs << "\\pagestyle{" << params.pagestyle << "}\n";
2366 if (params.secnumdepth != tclass.secnumdepth()) {
2367 ofs << "\\setcounter{secnumdepth}{"
2368 << params.secnumdepth
2372 if (params.tocdepth != tclass.tocdepth()) {
2373 ofs << "\\setcounter{tocdepth}{"
2379 if (params.paragraph_separation) {
2380 switch (params.defskip.kind()) {
2381 case VSpace::SMALLSKIP:
2382 ofs << "\\setlength\\parskip{\\smallskipamount}\n";
2384 case VSpace::MEDSKIP:
2385 ofs << "\\setlength\\parskip{\\medskipamount}\n";
2387 case VSpace::BIGSKIP:
2388 ofs << "\\setlength\\parskip{\\bigskipamount}\n";
2390 case VSpace::LENGTH:
2391 ofs << "\\setlength\\parskip{"
2392 << params.defskip.length().asLatexString()
2395 default: // should never happen // Then delete it.
2396 ofs << "\\setlength\\parskip{\\medskipamount}\n";
2401 ofs << "\\setlength\\parindent{0pt}\n";
2405 // Now insert the LyX specific LaTeX commands...
2407 // The optional packages;
2408 string preamble(features.getPackages());
2410 // this might be useful...
2411 preamble += "\n\\makeatletter\n";
2413 // Some macros LyX will need
2414 string tmppreamble(features.getMacros());
2416 if (!tmppreamble.empty()) {
2417 preamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2418 "LyX specific LaTeX commands.\n"
2419 + tmppreamble + '\n';
2422 // the text class specific preamble
2423 tmppreamble = features.getTClassPreamble();
2424 if (!tmppreamble.empty()) {
2425 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2426 "Textclass specific LaTeX commands.\n"
2427 + tmppreamble + '\n';
2430 /* the user-defined preamble */
2431 if (!params.preamble.empty()) {
2432 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2433 "User specified LaTeX commands.\n"
2434 + params.preamble + '\n';
2437 preamble += "\\makeatother\n";
2439 // Itemize bullet settings need to be last in case the user
2440 // defines their own bullets that use a package included
2441 // in the user-defined preamble -- ARRae
2442 // Actually it has to be done much later than that
2443 // since some packages like frenchb make modifications
2444 // at \begin{document} time -- JMarc
2446 for (int i = 0; i < 4; ++i) {
2447 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
2448 if (bullets_def.empty())
2449 bullets_def="\\AtBeginDocument{\n";
2450 bullets_def += " \\renewcommand{\\labelitemi";
2452 // `i' is one less than the item to modify
2459 bullets_def += "ii";
2465 bullets_def += "}{" +
2466 params.user_defined_bullets[i].getText()
2471 if (!bullets_def.empty())
2472 preamble += bullets_def + "}\n\n";
2475 int(lyx::count(preamble.begin(), preamble.end(), '\n'));
2476 for (int j = 0; j != nlines; ++j) {
2482 // We try to load babel late, in case it interferes
2483 // with other packages.
2485 string tmp = lyxrc.language_package;
2486 if (!lyxrc.language_global_options
2487 && tmp == "\\usepackage{babel}")
2488 tmp = string("\\usepackage[") +
2489 language_options.str().c_str() +
2496 ofs << "\\begin{document}\n";
2499 lyxerr[Debug::INFO] << "preamble finished, now the body." << endl;
2501 if (!lyxrc.language_auto_begin) {
2502 ofs << subst(lyxrc.language_command_begin, "$$lang",
2503 params.language->babel())
2508 latexParagraphs(ofs, paragraph, 0, texrow);
2510 // add this just in case after all the paragraphs
2514 if (!lyxrc.language_auto_end) {
2515 ofs << subst(lyxrc.language_command_end, "$$lang",
2516 params.language->babel())
2522 ofs << "\\end{document}\n";
2525 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
2527 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
2531 // Just to be sure. (Asger)
2534 // tex_code_break_column's value is used to decide
2535 // if we are in batchmode or not (within mathed_write()
2536 // in math_write.C) so we must set it to a non-zero
2537 // value when we leave otherwise we save incorrect .lyx files.
2538 tex_code_break_column = lyxrc.ascii_linelen;
2542 lyxerr << "File was not closed properly." << endl;
2545 lyxerr[Debug::INFO] << "Finished making latex file." << endl;
2546 lyxerr[Debug::INFO] << "Row count was " << texrow.rows()-1 << "." << endl;
2548 // we want this to be true outside previews (for insetexternal)
2554 // LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
2556 void Buffer::latexParagraphs(ostream & ofs, Paragraph * par,
2557 Paragraph * endpar, TexRow & texrow) const
2559 bool was_title = false;
2560 bool already_title = false;
2563 while (par != endpar) {
2564 Inset * in = par->inInset();
2565 // well we have to check if we are in an inset with unlimited
2566 // lenght (all in one row) if that is true then we don't allow
2567 // any special options in the paragraph and also we don't allow
2568 // any environment other then "Standard" to be valid!
2569 if ((in == 0) || !in->forceDefaultParagraphs(in)) {
2570 LyXLayout const & layout =
2571 textclasslist[params.textclass][par->layout()];
2573 if (layout.intitle) {
2574 if (already_title) {
2575 lyxerr <<"Error in latexParagraphs: You"
2576 " should not mix title layouts"
2577 " with normal ones." << endl;
2580 } else if (was_title && !already_title) {
2581 ofs << "\\maketitle\n";
2583 already_title = true;
2587 if (layout.isEnvironment()) {
2588 par = par->TeXEnvironment(this, params, ofs, texrow);
2590 par = par->TeXOnePar(this, params, ofs, texrow, false);
2593 par = par->TeXOnePar(this, params, ofs, texrow, false);
2596 // It might be that we only have a title in this document
2597 if (was_title && !already_title) {
2598 ofs << "\\maketitle\n";
2604 bool Buffer::isLatex() const
2606 return textclasslist[params.textclass].outputType() == LATEX;
2610 bool Buffer::isLinuxDoc() const
2612 return textclasslist[params.textclass].outputType() == LINUXDOC;
2616 bool Buffer::isLiterate() const
2618 return textclasslist[params.textclass].outputType() == LITERATE;
2622 bool Buffer::isDocBook() const
2624 return textclasslist[params.textclass].outputType() == DOCBOOK;
2628 bool Buffer::isSGML() const
2630 LyXTextClass const & tclass = textclasslist[params.textclass];
2632 return tclass.outputType() == LINUXDOC ||
2633 tclass.outputType() == DOCBOOK;
2637 void Buffer::sgmlOpenTag(ostream & os, Paragraph::depth_type,
2638 string const & latexname) const
2640 if (!latexname.empty() && latexname != "!-- --")
2641 //os << "<!-- " << depth << " -->" << "<" << latexname << ">";
2642 os << "<" << latexname << ">";
2646 void Buffer::sgmlCloseTag(ostream & os, Paragraph::depth_type,
2647 string const & latexname) const
2649 if (!latexname.empty() && latexname != "!-- --")
2650 //os << "<!-- " << depth << " -->" << "</" << latexname << ">\n";
2651 os << "</" << latexname << ">";
2655 void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
2657 ofstream ofs(fname.c_str());
2660 Alert::alert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2664 niceFile = nice; // this will be used by included files.
2666 LaTeXFeatures features(params);
2672 LyXTextClass const & tclass = textclasslist[params.textclass];
2674 string top_element = tclass.latexname();
2677 ofs << "<!doctype linuxdoc system";
2679 string preamble = params.preamble;
2680 const string name = nice ? ChangeExtension(filename_, ".sgml")
2682 preamble += features.getIncludedFiles(name);
2683 preamble += features.getLyXSGMLEntities();
2685 if (!preamble.empty()) {
2686 ofs << " [ " << preamble << " ]";
2690 if (params.options.empty())
2691 sgmlOpenTag(ofs, 0, top_element);
2693 string top = top_element;
2695 top += params.options;
2696 sgmlOpenTag(ofs, 0, top);
2700 ofs << "<!-- " << lyx_docversion
2701 << " created this file. For more info see http://www.lyx.org/"
2704 Paragraph::depth_type depth = 0; // paragraph depth
2705 Paragraph * par = paragraph;
2707 vector<string> environment_stack(5);
2710 LyXLayout const & style = tclass[par->layout()];
2712 // treat <toc> as a special case for compatibility with old code
2713 if (par->isInset(0)) {
2714 Inset * inset = par->getInset(0);
2715 Inset::Code lyx_code = inset->lyxCode();
2716 if (lyx_code == Inset::TOC_CODE) {
2717 string const temp = "toc";
2718 sgmlOpenTag(ofs, depth, temp);
2725 // environment tag closing
2726 for (; depth > par->params().depth(); --depth) {
2727 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2728 environment_stack[depth].erase();
2731 // write opening SGML tags
2732 switch (style.latextype) {
2733 case LATEX_PARAGRAPH:
2734 if (depth == par->params().depth()
2735 && !environment_stack[depth].empty()) {
2736 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2737 environment_stack[depth].erase();
2743 sgmlOpenTag(ofs, depth, style.latexname());
2749 _("Error : Wrong depth for"
2750 " LatexType Command.\n"));
2752 if (!environment_stack[depth].empty()) {
2753 sgmlCloseTag(ofs, depth,
2754 environment_stack[depth]);
2758 environment_stack[depth].erase();
2759 sgmlOpenTag(ofs, depth, style.latexname());
2762 case LATEX_ENVIRONMENT:
2763 case LATEX_ITEM_ENVIRONMENT:
2764 if (depth == par->params().depth()
2765 && environment_stack[depth] != style.latexname()) {
2766 sgmlCloseTag(ofs, depth,
2767 environment_stack[depth]);
2768 environment_stack[depth].erase();
2770 if (depth < par->params().depth()) {
2771 depth = par->params().depth();
2772 environment_stack[depth].erase();
2774 if (environment_stack[depth] != style.latexname()) {
2776 sgmlOpenTag(ofs, depth, "p");
2778 sgmlOpenTag(ofs, depth, style.latexname());
2780 if (environment_stack.size() == depth + 1)
2781 environment_stack.push_back("!-- --");
2782 environment_stack[depth] = style.latexname();
2785 if (style.latexparam() == "CDATA")
2788 if (style.latextype == LATEX_ENVIRONMENT) break;
2790 if (style.labeltype == LABEL_MANUAL)
2795 sgmlOpenTag(ofs, depth + 1, item_name);
2798 sgmlOpenTag(ofs, depth, style.latexname());
2802 simpleLinuxDocOnePar(ofs, par, depth);
2807 // write closing SGML tags
2808 switch (style.latextype) {
2811 case LATEX_ENVIRONMENT:
2812 case LATEX_ITEM_ENVIRONMENT:
2813 if (style.latexparam() == "CDATA")
2817 sgmlCloseTag(ofs, depth, style.latexname());
2823 for (int i=depth; i >= 0; --i)
2824 sgmlCloseTag(ofs, depth, environment_stack[i]);
2828 sgmlCloseTag(ofs, 0, top_element);
2832 // How to check for successful close
2834 // we want this to be true outside previews (for insetexternal)
2839 // checks, if newcol chars should be put into this line
2840 // writes newline, if necessary.
2843 void sgmlLineBreak(ostream & os, string::size_type & colcount,
2844 string::size_type newcol)
2847 if (colcount > lyxrc.ascii_linelen) {
2849 colcount = newcol; // assume write after this call
2864 string tag_name(PAR_TAG const & pt) {
2866 case NONE: return "!-- --";
2867 case TT: return "tt";
2868 case SF: return "sf";
2869 case BF: return "bf";
2870 case IT: return "it";
2871 case SL: return "sl";
2872 case EM: return "em";
2879 void operator|=(PAR_TAG & p1, PAR_TAG const & p2)
2881 p1 = static_cast<PAR_TAG>(p1 | p2);
2886 void reset(PAR_TAG & p1, PAR_TAG const & p2)
2888 p1 = static_cast<PAR_TAG>(p1 & ~p2);
2894 // Handle internal paragraph parsing -- layout already processed.
2895 void Buffer::simpleLinuxDocOnePar(ostream & os,
2897 Paragraph::depth_type /*depth*/)
2899 LyXLayout const & style =
2900 textclasslist[params.textclass][par->layout()];
2901 string::size_type char_line_count = 5; // Heuristic choice ;-)
2903 // gets paragraph main font
2906 if (style.labeltype == LABEL_MANUAL) {
2907 font_old = style.labelfont;
2910 font_old = style.font;
2914 LyXFont::FONT_FAMILY family_type = LyXFont::ROMAN_FAMILY;
2915 LyXFont::FONT_SERIES series_type = LyXFont::MEDIUM_SERIES;
2916 LyXFont::FONT_SHAPE shape_type = LyXFont::UP_SHAPE;
2919 stack<PAR_TAG> tag_state;
2920 // parsing main loop
2921 for (pos_type i = 0; i < par->size(); ++i) {
2923 PAR_TAG tag_close = NONE;
2924 list < PAR_TAG > tag_open;
2926 LyXFont const font = par->getFont(params, i);
2928 if (font_old.family() != font.family()) {
2929 switch (family_type) {
2930 case LyXFont::SANS_FAMILY:
2933 case LyXFont::TYPEWRITER_FAMILY:
2940 family_type = font.family();
2942 switch (family_type) {
2943 case LyXFont::SANS_FAMILY:
2944 tag_open.push_back(SF);
2946 case LyXFont::TYPEWRITER_FAMILY:
2947 tag_open.push_back(TT);
2954 if (font_old.series() != font.series()) {
2955 switch (series_type) {
2956 case LyXFont::BOLD_SERIES:
2963 series_type = font.series();
2965 switch (series_type) {
2966 case LyXFont::BOLD_SERIES:
2967 tag_open.push_back(BF);
2975 if (font_old.shape() != font.shape()) {
2976 switch (shape_type) {
2977 case LyXFont::ITALIC_SHAPE:
2980 case LyXFont::SLANTED_SHAPE:
2987 shape_type = font.shape();
2989 switch (shape_type) {
2990 case LyXFont::ITALIC_SHAPE:
2991 tag_open.push_back(IT);
2993 case LyXFont::SLANTED_SHAPE:
2994 tag_open.push_back(SL);
3001 if (font_old.emph() != font.emph()) {
3002 if (font.emph() == LyXFont::ON) {
3003 tag_open.push_back(EM);
3012 list < PAR_TAG > temp;
3013 while (!tag_state.empty() && tag_close) {
3014 PAR_TAG k = tag_state.top();
3016 os << "</" << tag_name(k) << ">";
3023 for(list< PAR_TAG >::const_iterator j = temp.begin();
3024 j != temp.end(); ++j) {
3026 os << "<" << tag_name(*j) << ">";
3029 for(list< PAR_TAG >::const_iterator j = tag_open.begin();
3030 j != tag_open.end(); ++j) {
3032 os << "<" << tag_name(*j) << ">";
3035 char c = par->getChar(i);
3037 if (c == Paragraph::META_INSET) {
3038 Inset * inset = par->getInset(i);
3039 inset->linuxdoc(this, os);
3044 if (style.latexparam() == "CDATA") {
3045 // "TeX"-Mode on == > SGML-Mode on.
3051 if (par->sgmlConvertChar(c, sgml_string)
3052 && !style.free_spacing && !par->isFreeSpacing())
3054 // in freespacing mode, spaces are
3055 // non-breaking characters
3056 if (desc_on) {// if char is ' ' then...
3059 sgmlLineBreak(os, char_line_count, 6);
3063 sgmlLineBreak(os, char_line_count, 1);
3068 char_line_count += sgml_string.length();
3074 while (!tag_state.empty()) {
3075 os << "</" << tag_name(tag_state.top()) << ">";
3079 // resets description flag correctly
3081 // <tag> not closed...
3082 sgmlLineBreak(os, char_line_count, 6);
3088 // Print an error message.
3089 void Buffer::sgmlError(Paragraph * /*par*/, int /*pos*/,
3090 string const & /*message*/) const
3092 #warning This is wrong we cannot insert an inset like this!!!
3093 // I guess this was Jose' so I explain you more or less why this
3094 // is wrong. This way you insert something in the paragraph and
3095 // don't tell it to LyXText (row rebreaking and undo handling!!!)
3096 // I deactivate this code, have a look at BufferView::insertErrors
3097 // how you should do this correctly! (Jug 20020315)
3099 // insert an error marker in text
3100 InsetError * new_inset = new InsetError(message);
3101 par->insertInset(pos, new_inset, LyXFont(LyXFont::ALL_INHERIT,
3107 void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
3109 ofstream ofs(fname.c_str());
3111 Alert::alert(_("LYX_ERROR:"), _("Cannot write file"), fname);
3115 Paragraph * par = paragraph;
3117 niceFile = nice; // this will be used by Insetincludes.
3119 LaTeXFeatures features(params);
3124 LyXTextClass const & tclass = textclasslist[params.textclass];
3125 string top_element = tclass.latexname();
3128 ofs << "<!DOCTYPE " << top_element
3129 << " PUBLIC \"-//OASIS//DTD DocBook V4.1//EN\"";
3131 string preamble = params.preamble;
3132 const string name = nice ? ChangeExtension(filename_, ".sgml")
3134 preamble += features.getIncludedFiles(name);
3135 preamble += features.getLyXSGMLEntities();
3137 if (!preamble.empty()) {
3138 ofs << "\n [ " << preamble << " ]";
3143 string top = top_element;
3145 top += params.language->code();
3148 if (!params.options.empty()) {
3150 top += params.options;
3152 sgmlOpenTag(ofs, 0, top);
3154 ofs << "<!-- DocBook file was created by " << lyx_docversion
3155 << "\n See http://www.lyx.org/ for more information -->\n";
3157 vector<string> environment_stack(10);
3158 vector<string> environment_inner(10);
3159 vector<string> command_stack(10);
3161 bool command_flag = false;
3162 Paragraph::depth_type command_depth = 0;
3163 Paragraph::depth_type command_base = 0;
3164 Paragraph::depth_type cmd_depth = 0;
3165 Paragraph::depth_type depth = 0; // paragraph depth
3168 string command_name;
3174 int desc_on = 0; // description mode
3176 LyXLayout const & style = tclass[par->layout()];
3178 // environment tag closing
3179 for (; depth > par->params().depth(); --depth) {
3180 if (environment_inner[depth] != "!-- --") {
3181 item_name = "listitem";
3182 sgmlCloseTag(ofs, command_depth + depth,
3184 if (environment_inner[depth] == "varlistentry")
3185 sgmlCloseTag(ofs, depth+command_depth,
3186 environment_inner[depth]);
3188 sgmlCloseTag(ofs, depth + command_depth,
3189 environment_stack[depth]);
3190 environment_stack[depth].erase();
3191 environment_inner[depth].erase();
3194 if (depth == par->params().depth()
3195 && environment_stack[depth] != style.latexname()
3196 && !environment_stack[depth].empty()) {
3197 if (environment_inner[depth] != "!-- --") {
3198 item_name= "listitem";
3199 sgmlCloseTag(ofs, command_depth+depth,
3201 if (environment_inner[depth] == "varlistentry")
3203 depth + command_depth,
3204 environment_inner[depth]);
3207 sgmlCloseTag(ofs, depth + command_depth,
3208 environment_stack[depth]);
3210 environment_stack[depth].erase();
3211 environment_inner[depth].erase();
3214 // Write opening SGML tags.
3215 switch (style.latextype) {
3216 case LATEX_PARAGRAPH:
3217 sgmlOpenTag(ofs, depth + command_depth,
3224 _("Error : Wrong depth for "
3225 "LatexType Command.\n"));
3227 command_name = style.latexname();
3229 sgmlparam = style.latexparam();
3230 c_params = split(sgmlparam, c_depth,'|');
3232 cmd_depth = lyx::atoi(c_depth);
3235 if (cmd_depth < command_base) {
3236 for (Paragraph::depth_type j = command_depth; j >= command_base; --j)
3237 sgmlCloseTag(ofs, j, command_stack[j]);
3238 command_depth = command_base = cmd_depth;
3239 } else if (cmd_depth <= command_depth) {
3240 for (int j = command_depth; j >= int(cmd_depth); --j)
3241 sgmlCloseTag(ofs, j, command_stack[j]);
3242 command_depth = cmd_depth;
3244 command_depth = cmd_depth;
3246 command_depth = command_base = cmd_depth;
3247 command_flag = true;
3249 if (command_stack.size() == command_depth + 1)
3250 command_stack.push_back(string());
3251 command_stack[command_depth] = command_name;
3253 // treat label as a special case for
3254 // more WYSIWYM handling.
3255 // This is a hack while paragraphs can't have
3256 // attributes, like id in this case.
3257 if (par->isInset(0)) {
3258 Inset * inset = par->getInset(0);
3259 Inset::Code lyx_code = inset->lyxCode();
3260 if (lyx_code == Inset::LABEL_CODE) {
3261 command_name += " id=\"";
3262 command_name += (static_cast<InsetCommand *>(inset))->getContents();
3263 command_name += "\"";
3268 sgmlOpenTag(ofs, depth + command_depth, command_name);
3269 if (c_params.empty())
3270 item_name = "title";
3272 item_name = c_params;
3273 sgmlOpenTag(ofs, depth + 1 + command_depth, item_name);
3276 case LATEX_ENVIRONMENT:
3277 case LATEX_ITEM_ENVIRONMENT:
3278 if (depth < par->params().depth()) {
3279 depth = par->params().depth();
3280 environment_stack[depth].erase();
3283 if (environment_stack[depth] != style.latexname()) {
3284 if (environment_stack.size() == depth + 1) {
3285 environment_stack.push_back("!-- --");
3286 environment_inner.push_back("!-- --");
3288 environment_stack[depth] = style.latexname();
3289 environment_inner[depth] = "!-- --";
3290 sgmlOpenTag(ofs, depth + command_depth,
3291 environment_stack[depth]);
3293 if (environment_inner[depth] != "!-- --") {
3294 item_name= "listitem";
3296 command_depth + depth,
3298 if (environment_inner[depth] == "varlistentry")
3300 depth + command_depth,
3301 environment_inner[depth]);
3305 if (style.latextype == LATEX_ENVIRONMENT) {
3306 if (!style.latexparam().empty()) {
3307 if (style.latexparam() == "CDATA")
3310 sgmlOpenTag(ofs, depth + command_depth,
3311 style.latexparam());
3316 desc_on = (style.labeltype == LABEL_MANUAL);
3319 environment_inner[depth]= "varlistentry";
3321 environment_inner[depth]= "listitem";
3323 sgmlOpenTag(ofs, depth + 1 + command_depth,
3324 environment_inner[depth]);
3328 sgmlOpenTag(ofs, depth + 1 + command_depth,
3332 sgmlOpenTag(ofs, depth + 1 + command_depth,
3337 sgmlOpenTag(ofs, depth + command_depth,
3342 simpleDocBookOnePar(ofs, par, desc_on, depth+1+command_depth);
3346 // write closing SGML tags
3347 switch (style.latextype) {
3349 if (c_params.empty())
3353 sgmlCloseTag(ofs, depth + command_depth, end_tag);
3355 case LATEX_ENVIRONMENT:
3356 if (!style.latexparam().empty()) {
3357 if (style.latexparam() == "CDATA")
3360 sgmlCloseTag(ofs, depth + command_depth,
3361 style.latexparam());
3364 case LATEX_ITEM_ENVIRONMENT:
3365 if (desc_on == 1) break;
3367 sgmlCloseTag(ofs, depth + 1 + command_depth, end_tag);
3369 case LATEX_PARAGRAPH:
3370 sgmlCloseTag(ofs, depth + command_depth, style.latexname());
3373 sgmlCloseTag(ofs, depth + command_depth, style.latexname());
3379 for (int d = depth; d >= 0; --d) {
3380 if (!environment_stack[depth].empty()) {
3381 if (environment_inner[depth] != "!-- --") {
3382 item_name = "listitem";
3383 sgmlCloseTag(ofs, command_depth + depth,
3385 if (environment_inner[depth] == "varlistentry")
3386 sgmlCloseTag(ofs, depth + command_depth,
3387 environment_inner[depth]);
3390 sgmlCloseTag(ofs, depth + command_depth,
3391 environment_stack[depth]);
3395 for (int j = command_depth; j >= 0 ; --j)
3396 if (!command_stack[j].empty())
3397 sgmlCloseTag(ofs, j, command_stack[j]);
3400 sgmlCloseTag(ofs, 0, top_element);
3403 // How to check for successful close
3405 // we want this to be true outside previews (for insetexternal)
3410 void Buffer::simpleDocBookOnePar(ostream & os,
3411 Paragraph * par, int & desc_on,
3412 Paragraph::depth_type depth) const
3414 bool emph_flag = false;
3416 LyXLayout const & style =
3417 textclasslist[params.textclass][par->layout()];
3419 LyXFont font_old = style.labeltype == LABEL_MANUAL ? style.labelfont : style.font;
3421 int char_line_count = depth;
3422 //if (!style.free_spacing)
3423 // os << string(depth,' ');
3425 // parsing main loop
3426 for (pos_type i = 0; i < par->size(); ++i) {
3427 LyXFont font = par->getFont(params, i);
3429 // handle <emphasis> tag
3430 if (font_old.emph() != font.emph()) {
3431 if (font.emph() == LyXFont::ON) {
3435 os << "</emphasis>";
3441 if (par->isInset(i)) {
3442 Inset * inset = par->getInset(i);
3443 // don't print the inset in position 0 if desc_on == 3 (label)
3444 if ( i || desc_on != 3) {
3445 if(style.latexparam() == "CDATA")
3447 inset->docbook(this, os);
3448 if(style.latexparam() == "CDATA")
3452 char c = par->getChar(i);
3454 par->sgmlConvertChar(c, sgml_string);
3456 if (style.pass_thru) {
3458 } else if (style.free_spacing || par->isFreeSpacing() || c != ' ') {
3460 } else if (desc_on ==1) {
3462 os << "\n</term><listitem><para>";
3472 os << "</emphasis>";
3475 // resets description flag correctly
3477 // <term> not closed...
3478 os << "</term>\n<listitem><para> </para>";
3480 if (style.free_spacing) os << '\n';
3484 // This should be enabled when the Chktex class is implemented. (Asger)
3485 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
3486 // Other flags: -wall -v0 -x
3487 int Buffer::runChktex()
3489 if (!users->text) return 0;
3491 users->owner()->prohibitInput();
3493 // get LaTeX-Filename
3494 string const name = getLatexName();
3495 string path = filePath();
3497 string const org_path = path;
3498 if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
3502 Path p(path); // path to LaTeX file
3503 users->owner()->message(_("Running chktex..."));
3505 // Remove all error insets
3506 bool const removedErrorInsets = users->removeAutoInsets();
3508 // Generate the LaTeX file if neccessary
3509 makeLaTeXFile(name, org_path, false);
3512 Chktex chktex(lyxrc.chktex_command, name, filePath());
3513 int res = chktex.run(terr); // run chktex
3516 Alert::alert(_("chktex did not work!"),
3517 _("Could not run with file:"), name);
3518 } else if (res > 0) {
3519 // Insert all errors as errors boxes
3520 users->insertErrors(terr);
3523 // if we removed error insets before we ran chktex or if we inserted
3524 // error insets after we ran chktex, this must be run:
3525 if (removedErrorInsets || res) {
3529 users->owner()->allowInput();
3535 void Buffer::validate(LaTeXFeatures & features) const
3537 Paragraph * par = paragraph;
3538 LyXTextClass const & tclass = textclasslist[params.textclass];
3540 // AMS Style is at document level
3541 if (params.use_amsmath || tclass.provides(LyXTextClass::amsmath))
3542 features.require("amsmath");
3545 // We don't use "lyxerr.debug" because of speed. (Asger)
3546 if (lyxerr.debugging(Debug::LATEX))
3547 lyxerr << "Paragraph: " << par << endl;
3549 // Now just follow the list of paragraphs and run
3550 // validate on each of them.
3551 par->validate(features);
3553 // and then the next paragraph
3557 // the bullet shapes are buffer level not paragraph level
3558 // so they are tested here
3559 for (int i = 0; i < 4; ++i) {
3560 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
3561 int const font = params.user_defined_bullets[i].getFont();
3563 int const c = params
3564 .user_defined_bullets[i]
3571 features.require("latexsym");
3573 } else if (font == 1) {
3574 features.require("amssymb");
3575 } else if ((font >= 2 && font <= 5)) {
3576 features.require("pifont");
3581 if (lyxerr.debugging(Debug::LATEX)) {
3582 features.showStruct();
3587 // This function should be in Buffer because it's a buffer's property (ale)
3588 string const Buffer::getIncludeonlyList(char delim)
3591 for (inset_iterator it = inset_iterator_begin();
3592 it != inset_iterator_end(); ++it) {
3593 if ((*it)->lyxCode() == Inset::INCLUDE_CODE) {
3594 InsetInclude * insetinc =
3595 static_cast<InsetInclude *>(*it);
3596 if (insetinc->isIncludeOnly()) {
3599 lst += insetinc->getRelFileBaseName();
3603 lyxerr[Debug::INFO] << "Includeonly(" << lst << ')' << endl;
3608 vector<string> const Buffer::getLabelList()
3610 /// if this is a child document and the parent is already loaded
3611 /// Use the parent's list instead [ale990407]
3612 if (!params.parentname.empty()
3613 && bufferlist.exists(params.parentname)) {
3614 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3616 return tmp->getLabelList();
3619 vector<string> label_list;
3620 for (inset_iterator it = inset_iterator_begin();
3621 it != inset_iterator_end(); ++it) {
3622 vector<string> const l = (*it)->getLabelList();
3623 label_list.insert(label_list.end(), l.begin(), l.end());
3629 Buffer::Lists const Buffer::getLists() const
3632 Paragraph * par = paragraph;
3634 LyXTextClass const & textclass = textclasslist[params.textclass];
3635 bool found = textclass.hasLayout("Caption");
3636 string const layout("Caption");
3639 char const labeltype = textclass[par->layout()].labeltype;
3641 if (labeltype >= LABEL_COUNTER_CHAPTER
3642 && labeltype <= LABEL_COUNTER_CHAPTER + params.tocdepth) {
3643 // insert this into the table of contents
3644 SingleList & item = l["TOC"];
3647 textclass.maxcounter());
3648 item.push_back(TocItem(par, depth, par->asString(this, true)));
3650 // For each paragrph, traverse its insets and look for
3654 Paragraph::inset_iterator it =
3655 par->inset_iterator_begin();
3656 Paragraph::inset_iterator end =
3657 par->inset_iterator_end();
3659 for (; it != end; ++it) {
3660 if ((*it)->lyxCode() == Inset::FLOAT_CODE) {
3662 static_cast<InsetFloat*>(*it);
3664 string const type = il->type();
3666 // Now find the caption in the float...
3667 // We now tranverse the paragraphs of
3669 Paragraph * tmp = il->inset.paragraph();
3671 if (tmp->layout() == layout) {
3672 SingleList & item = l[type];
3674 tostr(item.size()+1) + ". " + tmp->asString(this, false);
3675 item.push_back(TocItem(tmp, 0 , str));
3682 lyxerr << "Caption not found" << endl;
3691 // This is also a buffer property (ale)
3692 vector<pair<string, string> > const Buffer::getBibkeyList() const
3694 typedef pair<string, string> StringPair;
3695 /// if this is a child document and the parent is already loaded
3696 /// Use the parent's list instead [ale990412]
3697 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3698 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
3700 return tmp->getBibkeyList();
3703 vector<StringPair> keys;
3704 Paragraph * par = paragraph;
3707 string const key = par->bibkey->getContents();
3708 string const opt = par->bibkey->getOptions();
3709 string const ref = par->asString(this, false);
3710 string const info = opt + "TheBibliographyRef" + ref;
3712 keys.push_back(StringPair(key, info));
3717 // Might be either using bibtex or a child has bibliography
3719 for (inset_iterator it = inset_const_iterator_begin();
3720 it != inset_const_iterator_end(); ++it) {
3721 // Search for Bibtex or Include inset
3722 if ((*it)->lyxCode() == Inset::BIBTEX_CODE) {
3723 vector<StringPair> tmp =
3724 static_cast<InsetBibtex*>(*it)->getKeys(this);
3725 keys.insert(keys.end(), tmp.begin(), tmp.end());
3726 } else if ((*it)->lyxCode() == Inset::INCLUDE_CODE) {
3727 vector<StringPair> const tmp =
3728 static_cast<InsetInclude*>(*it)->getKeys();
3729 keys.insert(keys.end(), tmp.begin(), tmp.end());
3738 bool Buffer::isDepClean(string const & name) const
3740 DEPCLEAN * item = dep_clean;
3741 while (item && item->master != name)
3743 if (!item) return true;
3748 void Buffer::markDepClean(string const & name)
3751 dep_clean = new DEPCLEAN;
3752 dep_clean->clean = true;
3753 dep_clean->master = name;
3754 dep_clean->next = 0;
3756 DEPCLEAN * item = dep_clean;
3757 while (item && item->master != name)
3762 item = new DEPCLEAN;
3764 item->master = name;
3771 bool Buffer::dispatch(string const & command)
3773 // Split command string into command and argument
3775 string line = frontStrip(command);
3776 string const arg = strip(frontStrip(split(line, cmd, ' ')));
3778 return dispatch(lyxaction.LookupFunc(cmd), arg);
3782 bool Buffer::dispatch(int action, string const & argument)
3784 bool dispatched = true;
3787 Exporter::Export(this, argument, false);
3797 void Buffer::resizeInsets(BufferView * bv)
3799 /// then remove all LyXText in text-insets
3800 Paragraph * par = paragraph;
3801 for (; par; par = par->next()) {
3802 par->resizeInsetsLyXText(bv);
3807 void Buffer::redraw()
3814 void Buffer::changeLanguage(Language const * from, Language const * to)
3817 ParIterator end = par_iterator_end();
3818 for (ParIterator it = par_iterator_begin(); it != end; ++it)
3819 (*it)->changeLanguage(params, from, to);
3823 bool Buffer::isMultiLingual()
3825 ParIterator end = par_iterator_end();
3826 for (ParIterator it = par_iterator_begin(); it != end; ++it)
3827 if ((*it)->isMultiLingual(params))
3834 Buffer::inset_iterator::inset_iterator(Paragraph * paragraph, pos_type pos)
3837 it = par->InsetIterator(pos);
3838 if (it == par->inset_iterator_end()) {
3845 void Buffer::inset_iterator::setParagraph()
3848 it = par->inset_iterator_begin();
3849 if (it != par->inset_iterator_end())
3854 // We maintain an invariant that whenever par = 0 then it = 0
3858 Inset * Buffer::getInsetFromID(int id_arg) const
3860 for (inset_iterator it = inset_const_iterator_begin();
3861 it != inset_const_iterator_end(); ++it)
3863 if ((*it)->id() == id_arg)
3865 Inset * in = (*it)->getInsetFromID(id_arg);
3873 Paragraph * Buffer::getParFromID(int id) const
3875 if (id < 0) return 0;
3876 Paragraph * par = paragraph;
3878 if (par->id() == id) {
3881 Paragraph * tmp = par->getParFromID(id);
3891 ParIterator Buffer::par_iterator_begin()
3893 return ParIterator(paragraph);
3897 ParIterator Buffer::par_iterator_end()
3899 return ParIterator();