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 // Here we need to check for \end_deeper and handle that
629 // before we do the footnote parsing.
630 // This _is_ a hack! (Lgb)
633 string const tmp = lex.getString();
634 if (tmp == "\\end_deeper") {
635 //lyxerr << "\\end_deeper caught!" << endl;
637 lex.printError("\\end_deeper: "
638 "depth is already null");
643 old_float << tmp << ' ';
648 old_float << lex.getLongString("\\end_float")
649 << "\n\\end_inset\n";
650 //lyxerr << "Float Body:\n" << old_float.str() << endl;
651 // That this does not work seems like a bug
652 // in stringstream. (Lgb)
653 istringstream istr(old_float.str());
655 nylex.setStream(istr);
656 inset->read(this, nylex);
658 // we have to reset the font as in the old format after a float
659 // the font was automatically reset!
660 //font = LyXFont(LyXFont::ALL_INHERIT, params.language);
661 // This is not true (Dekel).
663 par->insertInset(pos, inset, font);
665 insertErtContents(par, pos);
667 } else if (token == "\\begin_deeper") {
669 } else if (token == "\\end_deeper") {
671 lex.printError("\\end_deeper: "
672 "depth is already null");
676 } else if (token == "\\begin_preamble") {
677 params.readPreamble(lex);
678 } else if (token == "\\textclass") {
680 pair<bool, textclass_type> pp =
681 textclasslist.NumberOfClass(lex.getString());
683 params.textclass = pp.second;
685 Alert::alert(string(_("Textclass error")),
686 string(_("The document uses an unknown textclass \"")) +
687 lex.getString() + string("\"."),
688 string(_("LyX will not be able to produce output correctly.")));
689 params.textclass = 0;
691 if (!textclasslist[params.textclass].load()) {
692 // if the textclass wasn't loaded properly
693 // we need to either substitute another
694 // or stop loading the file.
695 // I can substitute but I don't see how I can
696 // stop loading... ideas?? ARRae980418
697 Alert::alert(_("Textclass Loading Error!"),
698 string(_("Can't load textclass ")) +
699 textclasslist[params.textclass].name(),
700 _("-- substituting default"));
701 params.textclass = 0;
703 } else if (token == "\\options") {
705 params.options = lex.getString();
706 } else if (token == "\\language") {
707 params.readLanguage(lex);
708 } else if (token == "\\fontencoding") {
710 } else if (token == "\\inputencoding") {
712 params.inputenc = lex.getString();
713 } else if (token == "\\graphics") {
714 params.readGraphicsDriver(lex);
715 } else if (token == "\\fontscheme") {
717 params.fonts = lex.getString();
718 } else if (token == "\\noindent") {
719 par->params().noindent(true);
720 } else if (token == "\\fill_top") {
721 par->params().spaceTop(VSpace(VSpace::VFILL));
722 } else if (token == "\\fill_bottom") {
723 par->params().spaceBottom(VSpace(VSpace::VFILL));
724 } else if (token == "\\line_top") {
725 par->params().lineTop(true);
726 } else if (token == "\\line_bottom") {
727 par->params().lineBottom(true);
728 } else if (token == "\\pagebreak_top") {
729 par->params().pagebreakTop(true);
730 } else if (token == "\\pagebreak_bottom") {
731 par->params().pagebreakBottom(true);
732 } else if (token == "\\start_of_appendix") {
733 par->params().startOfAppendix(true);
734 } else if (token == "\\paragraph_separation") {
735 int tmpret = lex.findToken(string_paragraph_separation);
738 if (tmpret != LYX_LAYOUT_DEFAULT)
739 params.paragraph_separation =
740 static_cast<BufferParams::PARSEP>(tmpret);
741 } else if (token == "\\defskip") {
743 params.defskip = VSpace(lex.getString());
744 #ifndef NO_COMPABILITY
745 } else if (token == "\\epsfig") { // obsolete
746 // Indeed it is obsolete, but we HAVE to be backwards
747 // compatible until 0.14, because otherwise all figures
748 // in existing documents are irretrivably lost. (Asger)
749 params.readGraphicsDriver(lex);
751 } else if (token == "\\quotes_language") {
752 int tmpret = lex.findToken(string_quotes_language);
755 if (tmpret != LYX_LAYOUT_DEFAULT) {
756 InsetQuotes::quote_language tmpl =
757 InsetQuotes::EnglishQ;
760 tmpl = InsetQuotes::EnglishQ;
763 tmpl = InsetQuotes::SwedishQ;
766 tmpl = InsetQuotes::GermanQ;
769 tmpl = InsetQuotes::PolishQ;
772 tmpl = InsetQuotes::FrenchQ;
775 tmpl = InsetQuotes::DanishQ;
778 params.quotes_language = tmpl;
780 } else if (token == "\\quotes_times") {
782 switch (lex.getInteger()) {
784 params.quotes_times = InsetQuotes::SingleQ;
787 params.quotes_times = InsetQuotes::DoubleQ;
790 } else if (token == "\\papersize") {
791 int tmpret = lex.findToken(string_papersize);
795 params.papersize2 = tmpret;
796 } else if (token == "\\paperpackage") {
797 int tmpret = lex.findToken(string_paperpackages);
800 params.paperpackage = BufferParams::PACKAGE_NONE;
802 params.paperpackage = tmpret;
803 } else if (token == "\\use_geometry") {
805 params.use_geometry = lex.getInteger();
806 } else if (token == "\\use_amsmath") {
808 params.use_amsmath = lex.getInteger();
809 } else if (token == "\\use_natbib") {
811 params.use_natbib = lex.getInteger();
812 } else if (token == "\\use_numerical_citations") {
814 params.use_numerical_citations = lex.getInteger();
815 } else if (token == "\\paperorientation") {
816 int tmpret = lex.findToken(string_orientation);
819 if (tmpret != LYX_LAYOUT_DEFAULT)
820 params.orientation = static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
821 } else if (token == "\\paperwidth") {
823 params.paperwidth = lex.getString();
824 } else if (token == "\\paperheight") {
826 params.paperheight = lex.getString();
827 } else if (token == "\\leftmargin") {
829 params.leftmargin = lex.getString();
830 } else if (token == "\\topmargin") {
832 params.topmargin = lex.getString();
833 } else if (token == "\\rightmargin") {
835 params.rightmargin = lex.getString();
836 } else if (token == "\\bottommargin") {
838 params.bottommargin = lex.getString();
839 } else if (token == "\\headheight") {
841 params.headheight = lex.getString();
842 } else if (token == "\\headsep") {
844 params.headsep = lex.getString();
845 } else if (token == "\\footskip") {
847 params.footskip = lex.getString();
848 } else if (token == "\\paperfontsize") {
850 params.fontsize = strip(lex.getString());
851 } else if (token == "\\papercolumns") {
853 params.columns = lex.getInteger();
854 } else if (token == "\\papersides") {
856 switch (lex.getInteger()) {
858 case 1: params.sides = LyXTextClass::OneSide; break;
859 case 2: params.sides = LyXTextClass::TwoSides; break;
861 } else if (token == "\\paperpagestyle") {
863 params.pagestyle = strip(lex.getString());
864 } else if (token == "\\bullet") {
866 int const index = lex.getInteger();
868 int temp_int = lex.getInteger();
869 params.user_defined_bullets[index].setFont(temp_int);
870 params.temp_bullets[index].setFont(temp_int);
872 temp_int = lex.getInteger();
873 params.user_defined_bullets[index].setCharacter(temp_int);
874 params.temp_bullets[index].setCharacter(temp_int);
876 temp_int = lex.getInteger();
877 params.user_defined_bullets[index].setSize(temp_int);
878 params.temp_bullets[index].setSize(temp_int);
880 string const temp_str = lex.getString();
881 if (temp_str != "\\end_bullet") {
882 // this element isn't really necessary for
883 // parsing but is easier for humans
884 // to understand bullets. Put it back and
885 // set a debug message?
886 lex.printError("\\end_bullet expected, got" + temp_str);
887 //how can I put it back?
889 } else if (token == "\\bulletLaTeX") {
890 // The bullet class should be able to read this.
892 int const index = lex.getInteger();
894 string temp_str = lex.getString();
896 while (temp_str != "\\end_bullet") {
897 // this loop structure is needed when user
898 // enters an empty string since the first
899 // thing returned will be the \\end_bullet
901 // if the LaTeX entry has spaces. Each element
902 // therefore needs to be read in turn
905 temp_str = lex.getString();
908 params.user_defined_bullets[index].setText(sum_str);
909 params.temp_bullets[index].setText(sum_str);
910 } else if (token == "\\secnumdepth") {
912 params.secnumdepth = lex.getInteger();
913 } else if (token == "\\tocdepth") {
915 params.tocdepth = lex.getInteger();
916 } else if (token == "\\spacing") {
918 string const tmp = strip(lex.getString());
919 Spacing::Space tmp_space = Spacing::Default;
921 if (tmp == "single") {
922 tmp_space = Spacing::Single;
923 } else if (tmp == "onehalf") {
924 tmp_space = Spacing::Onehalf;
925 } else if (tmp == "double") {
926 tmp_space = Spacing::Double;
927 } else if (tmp == "other") {
929 tmp_space = Spacing::Other;
930 tmp_val = lex.getFloat();
932 lex.printError("Unknown spacing token: '$$Token'");
934 // Small hack so that files written with klyx will be
937 par->params().spacing(Spacing(tmp_space, tmp_val));
939 params.spacing.set(tmp_space, tmp_val);
941 } else if (token == "\\paragraph_spacing") {
943 string const tmp = strip(lex.getString());
944 if (tmp == "single") {
945 par->params().spacing(Spacing(Spacing::Single));
946 } else if (tmp == "onehalf") {
947 par->params().spacing(Spacing(Spacing::Onehalf));
948 } else if (tmp == "double") {
949 par->params().spacing(Spacing(Spacing::Double));
950 } else if (tmp == "other") {
952 par->params().spacing(Spacing(Spacing::Other,
955 lex.printError("Unknown spacing token: '$$Token'");
957 } else if (token == "\\float_placement") {
959 params.float_placement = lex.getString();
960 } else if (token == "\\family") {
962 font.setLyXFamily(lex.getString());
963 } else if (token == "\\series") {
965 font.setLyXSeries(lex.getString());
966 } else if (token == "\\shape") {
968 font.setLyXShape(lex.getString());
969 } else if (token == "\\size") {
971 font.setLyXSize(lex.getString());
972 #ifndef NO_COMPABILITY
973 } else if (token == "\\latex") {
975 string const tok = lex.getString();
976 if (tok == "no_latex") {
978 insertErtContents(par, pos);
979 } else if (tok == "latex") {
980 ert_comp.active = true;
981 ert_comp.font = font;
982 } else if (tok == "default") {
984 insertErtContents(par, pos);
986 lex.printError("Unknown LaTeX font flag "
990 } else if (token == "\\lang") {
992 string const tok = lex.getString();
993 Language const * lang = languages.getLanguage(tok);
995 font.setLanguage(lang);
997 font.setLanguage(params.language);
998 lex.printError("Unknown language `$$Token'");
1000 } else if (token == "\\numeric") {
1002 font.setNumber(font.setLyXMisc(lex.getString()));
1003 } else if (token == "\\emph") {
1005 font.setEmph(font.setLyXMisc(lex.getString()));
1006 } else if (token == "\\bar") {
1008 string const tok = lex.getString();
1009 // This is dirty, but gone with LyX3. (Asger)
1011 font.setUnderbar(LyXFont::ON);
1012 else if (tok == "no")
1013 font.setUnderbar(LyXFont::OFF);
1014 else if (tok == "default")
1015 font.setUnderbar(LyXFont::INHERIT);
1017 lex.printError("Unknown bar font flag "
1019 } else if (token == "\\noun") {
1021 font.setNoun(font.setLyXMisc(lex.getString()));
1022 } else if (token == "\\color") {
1024 font.setLyXColor(lex.getString());
1025 } else if (token == "\\align") {
1026 int tmpret = lex.findToken(string_align);
1027 if (tmpret == -1) ++tmpret;
1028 if (tmpret != LYX_LAYOUT_DEFAULT) { // tmpret != 99 ???
1029 int const tmpret2 = int(pow(2.0, tmpret));
1030 //lyxerr << "Tmpret2 = " << tmpret2 << endl;
1031 par->params().align(LyXAlignment(tmpret2));
1033 } else if (token == "\\added_space_top") {
1035 VSpace value = VSpace(lex.getString());
1036 if ((value.length().len().value() != 0) ||
1037 (value.kind() != VSpace::LENGTH))
1038 par->params().spaceTop(value);
1039 } else if (token == "\\added_space_bottom") {
1041 VSpace value = VSpace(lex.getString());
1042 if ((value.length().len().value() != 0) ||
1043 (value.kind() != VSpace::LENGTH))
1044 par->params().spaceBottom(value);
1045 #ifndef NO_COMPABILITY
1046 #ifndef NO_PEXTRA_REALLY
1047 } else if (token == "\\pextra_type") {
1049 par->params().pextraType(lex.getInteger());
1050 } else if (token == "\\pextra_width") {
1052 par->params().pextraWidth(lex.getString());
1053 } else if (token == "\\pextra_widthp") {
1055 par->params().pextraWidthp(lex.getString());
1056 } else if (token == "\\pextra_alignment") {
1058 par->params().pextraAlignment(lex.getInteger());
1059 } else if (token == "\\pextra_hfill") {
1061 par->params().pextraHfill(lex.getInteger());
1062 } else if (token == "\\pextra_start_minipage") {
1064 par->params().pextraStartMinipage(lex.getInteger());
1067 } else if (token == "\\labelwidthstring") {
1069 par->params().labelWidthString(lex.getString());
1070 // do not delete this token, it is still needed!
1071 } else if (token == "\\end_inset") {
1072 lyxerr << "Solitary \\end_inset. Missing \\begin_inset?.\n"
1073 << "Last inset read was: " << last_inset_read
1075 // Simply ignore this. The insets do not have
1077 // But insets should read it, it is a part of
1078 // the inset isn't it? Lgb.
1079 } else if (token == "\\begin_inset") {
1080 #ifndef NO_COMPABILITY
1081 insertErtContents(par, pos, false);
1082 ert_stack.push(ert_comp);
1083 ert_comp = ErtComp();
1085 readInset(lex, par, pos, font);
1086 #ifndef NO_COMPABILITY
1087 ert_comp = ert_stack.top();
1089 insertErtContents(par, pos);
1091 } else if (token == "\\SpecialChar") {
1092 LyXLayout const & layout =
1093 textclasslist[params.textclass][par->layout()];
1095 // Insets don't make sense in a free-spacing context! ---Kayvan
1096 if (layout.free_spacing || par->isFreeSpacing()) {
1099 string next_token = lex.getString();
1100 if (next_token == "\\-") {
1101 par->insertChar(pos, '-', font);
1102 } else if (next_token == "\\protected_separator"
1103 || next_token == "~") {
1104 par->insertChar(pos, ' ', font);
1106 lex.printError("Token `$$Token' "
1108 "paragraph layout!");
1113 Inset * inset = new InsetSpecialChar;
1114 inset->read(this, lex);
1115 par->insertInset(pos, inset, font);
1118 } else if (token == "\\newline") {
1119 #ifndef NO_COMPABILITY
1120 if (!ert_comp.in_tabular && ert_comp.active) {
1121 ert_comp.contents += char(Paragraph::META_NEWLINE);
1123 // Since we cannot know it this is only a regular
1124 // newline or a tabular cell delimter we have to
1125 // handle the ERT here.
1126 insertErtContents(par, pos, false);
1128 par->insertChar(pos, Paragraph::META_NEWLINE, font);
1132 par->insertChar(pos, Paragraph::META_NEWLINE, font);
1135 } else if (token == "\\LyXTable") {
1136 #ifndef NO_COMPABILITY
1137 ert_comp.in_tabular = true;
1139 Inset * inset = new InsetTabular(*this);
1140 inset->read(this, lex);
1141 par->insertInset(pos, inset, font);
1143 } else if (token == "\\hfill") {
1144 par->insertChar(pos, Paragraph::META_HFILL, font);
1146 } else if (token == "\\protected_separator") { // obsolete
1147 // This is a backward compability thingie. (Lgb)
1148 // Remove it later some time...introduced with fileformat
1150 LyXLayout const & layout =
1151 textclasslist[params.textclass][par->layout()];
1153 if (layout.free_spacing || par->isFreeSpacing()) {
1154 par->insertChar(pos, ' ', font);
1156 Inset * inset = new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
1157 par->insertInset(pos, inset, font);
1160 } else if (token == "\\bibitem") { // ale970302
1162 InsetCommandParams p("bibitem", "dummy");
1163 par->bibkey = new InsetBibKey(p);
1165 par->bibkey->read(this, lex);
1166 } else if (token == "\\backslash") {
1167 #ifndef NO_COMPABILITY
1168 if (ert_comp.active) {
1169 ert_comp.contents += "\\";
1172 par->insertChar(pos, '\\', font);
1174 #ifndef NO_COMPABILITY
1177 } else if (token == "\\the_end") {
1178 #ifndef NO_COMPABILITY
1179 // If we still have some ert active here we have to insert
1180 // it so we don't loose it. (Lgb)
1181 insertErtContents(par, pos);
1183 the_end_read = true;
1184 #ifndef NO_COMPABILITY
1185 #ifndef NO_PEXTRA_REALLY
1188 minipar = parBeforeMinipage = 0;
1192 #ifndef NO_COMPABILITY
1193 if (ert_comp.active) {
1194 ert_comp.contents += token;
1197 // This should be insurance for the future: (Asger)
1200 string const s = _("Unknown token: ") + token
1201 + " " + lex.text() + "\n";
1202 // we can do this here this way because we're actually reading
1203 // the buffer and don't care about LyXText right now.
1204 InsetError * new_inset = new InsetError(s);
1205 par->insertInset(pos, new_inset, LyXFont(LyXFont::ALL_INHERIT,
1208 #ifndef NO_COMPABILITY
1213 #ifndef NO_COMPABILITY
1214 #ifndef NO_PEXTRA_REALLY
1215 // I wonder if we could use this blanket fix for all the
1216 // checkminipage cases...
1217 // don't forget about ert paragraphs and compatibility read for'em
1218 if (par && (par->size() || !ert_comp.contents.empty())) {
1219 // It is possible that this will check to often,
1220 // but that should not be an correctness issue.
1221 // Only a speed issue.
1222 checkminipage = true;
1225 // now check if we have a minipage paragraph as at this
1226 // point we already read all the necessary data!
1227 // this cannot be done in layout because there we did
1228 // not read yet the paragraph PEXTRA-params (Jug)
1230 // BEGIN pextra_minipage compability
1231 // This should be removed in 1.3.x (Lgb)
1232 // I don't think we should remove this so fast (Jug)
1234 // This compability code is not perfect. In a couple
1235 // of rand cases it fails. When the minipage par is
1236 // the first par in the document, and when there are
1237 // none or only one regular paragraphs after the
1238 // minipage. Currently I am not investing any effort
1239 // in fixing those cases.
1241 //lyxerr << "Call depth: " << call_depth << endl;
1242 if (checkminipage && (call_depth == 1)) {
1243 checkminipage = false;
1244 if (minipar && (minipar != par) &&
1245 (par->params().pextraType() == Paragraph::PEXTRA_MINIPAGE))
1247 lyxerr << "minipages in a row" << endl;
1248 if (par->params().pextraStartMinipage()) {
1249 lyxerr << "start new minipage" << endl;
1250 // minipages in a row
1251 par->previous()->next(0);
1254 Paragraph * tmp = minipar;
1256 tmp->params().pextraType(0);
1257 tmp->params().pextraWidth(string());
1258 tmp->params().pextraWidthp(string());
1259 tmp->params().pextraAlignment(0);
1260 tmp->params().pextraHfill(false);
1261 tmp->params().pextraStartMinipage(false);
1264 // create a new paragraph to insert the
1265 // minipages in the following case
1266 if (par->params().pextraStartMinipage() &&
1267 !par->params().pextraHfill()) {
1268 Paragraph * p = new Paragraph;
1269 p->layout(textclasslist[params.textclass].defaultLayoutName());
1271 p->previous(parBeforeMinipage);
1272 parBeforeMinipage->next(p);
1274 p->params().depth(parBeforeMinipage->params().depth());
1275 parBeforeMinipage = p;
1277 InsetMinipage * mini = new InsetMinipage(params);
1278 mini->pos(static_cast<InsetMinipage::Position>(par->params().pextraAlignment()));
1279 mini->pageWidth(LyXLength(par->params().pextraWidth()));
1280 if (!par->params().pextraWidthp().empty()) {
1281 lyxerr << "WP:" << mini->pageWidth().asString() << endl;
1282 mini->pageWidth(LyXLength((par->params().pextraWidthp())+"col%"));
1284 Paragraph * op = mini->firstParagraph();
1285 mini->inset.paragraph(par);
1287 // and free the old ones!
1290 Paragraph * pp = op->next();
1294 // Insert the minipage last in the
1295 // previous paragraph.
1296 if (par->params().pextraHfill()) {
1297 parBeforeMinipage->insertChar
1298 (parBeforeMinipage->size(),
1299 Paragraph::META_HFILL, font);
1301 parBeforeMinipage->insertInset
1302 (parBeforeMinipage->size(), mini, font);
1306 lyxerr << "new minipage par" << endl;
1307 //nothing to do just continue reading
1310 } else if (minipar && (minipar != par)) {
1311 lyxerr << "last minipage par read" << endl;
1312 // The last paragraph read was not part of a
1313 // minipage but the par linked list is...
1314 // So we need to remove the last par from the
1316 if (par->previous())
1317 par->previous()->next(0);
1318 par->previous(parBeforeMinipage);
1319 parBeforeMinipage->next(par);
1320 Paragraph * tmp = minipar;
1322 tmp->params().pextraType(0);
1323 tmp->params().pextraWidth(string());
1324 tmp->params().pextraWidthp(string());
1325 tmp->params().pextraAlignment(0);
1326 tmp->params().pextraHfill(false);
1327 tmp->params().pextraStartMinipage(false);
1330 depth = parBeforeMinipage->params().depth();
1331 // and set this depth on the par as it has not been set already
1332 par->params().depth(depth);
1333 minipar = parBeforeMinipage = 0;
1334 } else if (!minipar &&
1335 (par->params().pextraType() == Paragraph::PEXTRA_MINIPAGE))
1337 // par is the first paragraph in a minipage
1338 lyxerr << "begin minipage" << endl;
1339 // To minimize problems for
1340 // the users we will insert
1341 // the first minipage in
1342 // a sequence of minipages
1343 // in its own paragraph.
1344 Paragraph * p = new Paragraph;
1345 p->layout(textclasslist[params.textclass].defaultLayoutName());
1346 p->previous(par->previous());
1348 p->params().depth(depth);
1349 par->params().depth(0);
1351 if (par->previous())
1352 par->previous()->next(p);
1354 parBeforeMinipage = p;
1356 if (!first_par || (first_par == par))
1359 InsetMinipage * mini = new InsetMinipage(params);
1360 mini->pos(static_cast<InsetMinipage::Position>(minipar->params().pextraAlignment()));
1361 mini->pageWidth(LyXLength(minipar->params().pextraWidth()));
1362 if (!par->params().pextraWidthp().empty()) {
1363 lyxerr << "WP:" << mini->pageWidth().asString() << endl;
1364 mini->pageWidth(LyXLength((par->params().pextraWidthp())+"col%"));
1367 Paragraph * op = mini->firstParagraph();
1368 mini->inset.paragraph(minipar);
1370 // and free the old ones!
1373 Paragraph * pp = op->next();
1378 // Insert the minipage last in the
1379 // previous paragraph.
1380 if (minipar->params().pextraHfill()) {
1381 parBeforeMinipage->insertChar
1382 (parBeforeMinipage->size(),
1383 Paragraph::META_HFILL, font);
1385 parBeforeMinipage->insertInset
1386 (parBeforeMinipage->size(), mini, font);
1389 // End of pextra_minipage compability
1393 return the_end_read;
1396 // needed to insert the selection
1397 void Buffer::insertStringAsLines(Paragraph *& par, pos_type & pos,
1398 LyXFont const & fn,string const & str) const
1400 LyXLayout const & layout =
1401 textclasslist[params.textclass][par->layout()];
1404 par->checkInsertChar(font);
1405 // insert the string, don't insert doublespace
1406 bool space_inserted = true;
1407 bool autobreakrows = !par->inInset() ||
1408 static_cast<InsetText *>(par->inInset())->getAutoBreakRows();
1409 for(string::const_iterator cit = str.begin();
1410 cit != str.end(); ++cit) {
1412 if (autobreakrows && (par->size() || layout.keepempty)) {
1413 par->breakParagraph(params, pos,
1414 layout.isEnvironment());
1417 space_inserted = true;
1421 // do not insert consecutive spaces if !free_spacing
1422 } else if ((*cit == ' ' || *cit == '\t') &&
1423 space_inserted && !layout.free_spacing &&
1424 !par->isFreeSpacing())
1427 } else if (*cit == '\t') {
1428 if (!layout.free_spacing && !par->isFreeSpacing()) {
1429 // tabs are like spaces here
1430 par->insertChar(pos, ' ', font);
1432 space_inserted = true;
1434 const pos_type nb = 8 - pos % 8;
1435 for (pos_type a = 0; a < nb ; ++a) {
1436 par->insertChar(pos, ' ', font);
1439 space_inserted = true;
1441 } else if (!IsPrintable(*cit)) {
1442 // Ignore unprintables
1445 // just insert the character
1446 par->insertChar(pos, *cit, font);
1448 space_inserted = (*cit == ' ');
1455 void Buffer::readInset(LyXLex & lex, Paragraph *& par,
1456 int & pos, LyXFont & font)
1458 // consistency check
1459 if (lex.getString() != "\\begin_inset") {
1460 lyxerr << "Buffer::readInset: Consistency check failed."
1467 string const tmptok = lex.getString();
1468 last_inset_read = tmptok;
1470 // test the different insets
1471 if (tmptok == "LatexCommand") {
1472 InsetCommandParams inscmd;
1475 string const cmdName = inscmd.getCmdName();
1477 // This strange command allows LyX to recognize "natbib" style
1478 // citations: citet, citep, Citet etc.
1479 if (compare_no_case(cmdName, "cite", 4) == 0) {
1480 inset = new InsetCitation(inscmd);
1481 } else if (cmdName == "bibitem") {
1482 lex.printError("Wrong place for bibitem");
1483 inset = new InsetBibKey(inscmd);
1484 } else if (cmdName == "BibTeX") {
1485 inset = new InsetBibtex(inscmd);
1486 } else if (cmdName == "index") {
1487 inset = new InsetIndex(inscmd);
1488 } else if (cmdName == "include") {
1489 inset = new InsetInclude(inscmd, *this);
1490 } else if (cmdName == "label") {
1491 inset = new InsetLabel(inscmd);
1492 } else if (cmdName == "url"
1493 || cmdName == "htmlurl") {
1494 inset = new InsetUrl(inscmd);
1495 } else if (cmdName == "ref"
1496 || cmdName == "pageref"
1497 || cmdName == "vref"
1498 || cmdName == "vpageref"
1499 || cmdName == "prettyref") {
1500 if (!inscmd.getOptions().empty()
1501 || !inscmd.getContents().empty()) {
1502 inset = new InsetRef(inscmd, *this);
1504 } else if (cmdName == "tableofcontents") {
1505 inset = new InsetTOC(inscmd);
1506 } else if (cmdName == "listofalgorithms") {
1507 inset = new InsetFloatList("algorithm");
1508 } else if (cmdName == "listoffigures") {
1509 inset = new InsetFloatList("figure");
1510 } else if (cmdName == "listoftables") {
1511 inset = new InsetFloatList("table");
1512 } else if (cmdName == "printindex") {
1513 inset = new InsetPrintIndex(inscmd);
1514 } else if (cmdName == "lyxparent") {
1515 inset = new InsetParent(inscmd, *this);
1518 bool alreadyread = false;
1519 if (tmptok == "Quotes") {
1520 inset = new InsetQuotes;
1521 } else if (tmptok == "External") {
1522 inset = new InsetExternal;
1523 } else if (tmptok == "FormulaMacro") {
1524 inset = new InsetFormulaMacro;
1525 } else if (tmptok == "Formula") {
1526 inset = new InsetFormula;
1527 } else if (tmptok == "Figure") { // Backward compatibility
1528 // inset = new InsetFig(100, 100, *this);
1529 inset = new InsetGraphics;
1530 } else if (tmptok == "Graphics") {
1531 inset = new InsetGraphics;
1532 } else if (tmptok == "Info") {// backwards compatibility
1533 inset = new InsetNote(this,
1534 lex.getLongString("\\end_inset"),
1537 } else if (tmptok == "Note") {
1538 inset = new InsetNote(params);
1539 } else if (tmptok == "Include") {
1540 InsetCommandParams p("Include");
1541 inset = new InsetInclude(p, *this);
1542 } else if (tmptok == "ERT") {
1543 inset = new InsetERT(params);
1544 } else if (tmptok == "Tabular") {
1545 inset = new InsetTabular(*this);
1546 } else if (tmptok == "Text") {
1547 inset = new InsetText(params);
1548 } else if (tmptok == "Foot") {
1549 inset = new InsetFoot(params);
1550 } else if (tmptok == "Marginal") {
1551 inset = new InsetMarginal(params);
1552 } else if (tmptok == "Minipage") {
1553 inset = new InsetMinipage(params);
1554 } else if (tmptok == "Float") {
1556 string tmptok = lex.getString();
1557 inset = new InsetFloat(params, tmptok);
1559 } else if (tmptok == "List") {
1560 inset = new InsetList;
1561 } else if (tmptok == "Theorem") {
1562 inset = new InsetList;
1564 } else if (tmptok == "Caption") {
1565 inset = new InsetCaption(params);
1566 } else if (tmptok == "FloatList") {
1567 inset = new InsetFloatList;
1570 if (inset && !alreadyread) inset->read(this, lex);
1574 par->insertInset(pos, inset, font);
1580 bool Buffer::readFile(LyXLex & lex, Paragraph * par)
1584 string const token(lex.getString());
1585 if (token == "\\lyxformat") { // the first token _must_ be...
1587 string tmp_format = lex.getString();
1588 //lyxerr << "LyX Format: `" << tmp_format << "'" << endl;
1589 // if present remove ".," from string.
1590 string::size_type dot = tmp_format.find_first_of(".,");
1591 //lyxerr << " dot found at " << dot << endl;
1592 if (dot != string::npos)
1593 tmp_format.erase(dot, 1);
1594 file_format = strToInt(tmp_format);
1595 if (file_format == LYX_FORMAT) {
1597 } else if (file_format > LYX_FORMAT) {
1599 Alert::alert(_("Warning!"),
1600 _("LyX file format is newer that what"),
1601 _("is supported in this LyX version. Expect some problems."));
1603 } else if (file_format < LYX_FORMAT) {
1605 if (file_format < 200) {
1606 Alert::alert(_("ERROR!"),
1607 _("Old LyX file format found. "
1608 "Use LyX 0.10.x to read this!"));
1612 bool the_end = readLyXformat2(lex, par);
1613 params.setPaperStuff();
1614 // the_end was added in 213
1615 if (file_format < 213)
1619 Alert::alert(_("Warning!"),
1620 _("Reading of document is not complete"),
1621 _("Maybe the document is truncated"));
1624 } else { // "\\lyxformat" not found
1625 Alert::alert(_("ERROR!"), _("Not a LyX file!"));
1628 Alert::alert(_("ERROR!"), _("Unable to read file!"));
1633 // Should probably be moved to somewhere else: BufferView? LyXView?
1634 bool Buffer::save() const
1636 // We don't need autosaves in the immediate future. (Asger)
1637 resetAutosaveTimers();
1641 if (lyxrc.make_backup) {
1642 s = fileName() + '~';
1643 if (!lyxrc.backupdir_path.empty())
1644 s = AddName(lyxrc.backupdir_path,
1645 subst(os::slashify_path(s),'/','!'));
1647 // Rename is the wrong way of making a backup,
1648 // this is the correct way.
1649 /* truss cp fil fil2:
1650 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
1651 stat("LyXVC.lyx", 0xEFFFF688) = 0
1652 open("LyXVC.lyx", O_RDONLY) = 3
1653 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
1654 fstat(4, 0xEFFFF508) = 0
1655 fstat(3, 0xEFFFF508) = 0
1656 read(3, " # T h i s f i l e w".., 8192) = 5579
1657 write(4, " # T h i s f i l e w".., 5579) = 5579
1658 read(3, 0xEFFFD4A0, 8192) = 0
1661 chmod("LyXVC3.lyx", 0100644) = 0
1662 lseek(0, 0, SEEK_CUR) = 46440
1666 // Should probably have some more error checking here.
1667 // Should be cleaned up in 0.13, at least a bit.
1668 // Doing it this way, also makes the inodes stay the same.
1669 // This is still not a very good solution, in particular we
1670 // might loose the owner of the backup.
1671 FileInfo finfo(fileName());
1672 if (finfo.exist()) {
1673 mode_t fmode = finfo.getMode();
1674 struct utimbuf times = {
1675 finfo.getAccessTime(),
1676 finfo.getModificationTime() };
1678 ifstream ifs(fileName().c_str());
1679 ofstream ofs(s.c_str(), ios::out|ios::trunc);
1684 ::chmod(s.c_str(), fmode);
1686 if (::utime(s.c_str(), ×)) {
1687 lyxerr << "utime error." << endl;
1690 lyxerr << "LyX was not able to make "
1691 "backup copy. Beware." << endl;
1696 if (writeFile(fileName(), false)) {
1698 removeAutosaveFile(fileName());
1700 // Saving failed, so backup is not backup
1701 if (lyxrc.make_backup) {
1702 lyx::rename(s, fileName());
1710 // Returns false if unsuccesful
1711 bool Buffer::writeFile(string const & fname, bool flag) const
1713 // if flag is false writeFile will not create any GUI
1714 // warnings, only cerr.
1715 // Needed for autosave in background or panic save (Matthias 120496)
1717 if (read_only && (fname == fileName())) {
1718 // Here we should come with a question if we should
1719 // perform the write anyway.
1721 lyxerr << _("Error! Document is read-only: ")
1724 Alert::alert(_("Error! Document is read-only: "),
1729 FileInfo finfo(fname);
1730 if (finfo.exist() && !finfo.writable()) {
1731 // Here we should come with a question if we should
1732 // try to do the save anyway. (i.e. do a chmod first)
1734 lyxerr << _("Error! Cannot write file: ")
1737 Alert::err_alert(_("Error! Cannot write file: "),
1742 ofstream ofs(fname.c_str());
1745 lyxerr << _("Error! Cannot open file: ")
1748 Alert::err_alert(_("Error! Cannot open file: "),
1754 // Use the standard "C" locale for file output.
1755 ofs.imbue(std::locale::classic());
1758 // The top of the file should not be written by params.
1760 // write out a comment in the top of the file
1761 ofs << '#' << lyx_docversion
1762 << " created this file. For more info see http://www.lyx.org/\n"
1763 << "\\lyxformat " << LYX_FORMAT << "\n";
1765 // now write out the buffer paramters.
1766 params.writeFile(ofs);
1768 Paragraph::depth_type depth = 0;
1770 // this will write out all the paragraphs
1771 // using recursive descent.
1772 paragraph->writeFile(this, ofs, params, depth);
1774 // Write marker that shows file is complete
1775 ofs << "\n\\the_end" << endl;
1779 // how to check if close went ok?
1780 // Following is an attempt... (BE 20001011)
1782 // good() returns false if any error occured, including some
1783 // formatting error.
1784 // bad() returns true if something bad happened in the buffer,
1785 // which should include file system full errors.
1792 lyxerr << "Buffer::writeFile: BAD ERROR!" << endl;
1794 lyxerr << "Buffer::writeFile: NOT SO BAD ERROR!"
1806 pair<int, string> const addDepth(int depth, int ldepth)
1810 d += (ldepth - depth) * 2;
1811 return make_pair(d, string(d, ' '));
1817 string const Buffer::asciiParagraph(Paragraph const * par,
1818 unsigned int linelen,
1819 bool noparbreak) const
1821 ostringstream buffer;
1822 Paragraph::depth_type depth = 0;
1824 Paragraph::depth_type ltype_depth = 0;
1825 bool ref_printed = false;
1826 // if (!par->previous()) {
1828 // begins or ends a deeper area ?
1829 if (depth != par->params().depth()) {
1830 if (par->params().depth() > depth) {
1831 while (par->params().depth() > depth) {
1835 while (par->params().depth() < depth) {
1841 depth = par->params().depth();
1844 // First write the layout
1845 string const & tmp = par->layout();
1846 if (compare_no_case(tmp, "itemize") == 0) {
1848 ltype_depth = depth + 1;
1849 } else if (compare_no_case(tmp, "enumerate") == 0) {
1851 ltype_depth = depth + 1;
1852 } else if (contains(lowercase(tmp), "ection")) {
1854 ltype_depth = depth + 1;
1855 } else if (contains(lowercase(tmp), "aragraph")) {
1857 ltype_depth = depth + 1;
1858 } else if (compare_no_case(tmp, "description") == 0) {
1860 ltype_depth = depth + 1;
1861 } else if (compare_no_case(tmp, "abstract") == 0) {
1864 } else if (compare_no_case(tmp, "bibliography") == 0) {
1872 /* maybe some vertical spaces */
1874 /* the labelwidthstring used in lists */
1878 /* some pagebreaks? */
1882 /* what about the alignment */
1884 // lyxerr << "Should this ever happen?" << endl;
1887 // linelen <= 0 is special and means we don't have pargraph breaks
1889 string::size_type currlinelen = 0;
1895 buffer << string(depth * 2, ' ');
1896 currlinelen += depth * 2;
1899 // we should probably change to the paragraph language in the
1900 // gettext here (if possible) so that strings are outputted in
1901 // the correct language! (20012712 Jug)
1905 case 4: // (Sub)Paragraph
1906 case 5: // Description
1910 buffer << _("Abstract") << "\n\n";
1913 string const abst = _("Abstract: ");
1915 currlinelen += abst.length();
1918 case 7: // Bibliography
1921 buffer << _("References") << "\n\n";
1924 string const refs = _("References: ");
1926 currlinelen += refs.length();
1934 string const parlab = par->params().labelString();
1935 buffer << parlab << " ";
1936 currlinelen += parlab.length() + 1;
1944 pair<int, string> p = addDepth(depth, ltype_depth);
1946 currlinelen += p.first;
1949 // this is to change the linebreak to do it by word a bit more
1950 // intelligent hopefully! (only in the case where we have a
1951 // max linelenght!) (Jug)
1955 for (pos_type i = 0; i < par->size(); ++i) {
1956 char c = par->getUChar(params, i);
1958 case Paragraph::META_INSET:
1960 Inset const * inset = par->getInset(i);
1964 currlinelen += word.length();
1967 if (inset->ascii(this, buffer, linelen)) {
1968 // to be sure it breaks paragraph
1969 currlinelen += linelen;
1975 case Paragraph::META_NEWLINE:
1977 buffer << word << "\n";
1980 pair<int, string> p = addDepth(depth,
1983 currlinelen = p.first;
1987 case Paragraph::META_HFILL:
1988 buffer << word << "\t";
1989 currlinelen += word.length() + 1;
1996 currlinelen + word.length() > linelen - 10) {
1998 pair<int, string> p =
1999 addDepth(depth, ltype_depth);
2001 currlinelen = p.first;
2004 buffer << word << ' ';
2005 currlinelen += word.length() + 1;
2012 lyxerr[Debug::INFO] <<
2013 "writeAsciiFile: NULL char in structure." << endl;
2015 if ((linelen > 0) &&
2016 (currlinelen + word.length()) > linelen)
2020 pair<int, string> p =
2021 addDepth(depth, ltype_depth);
2023 currlinelen = p.first;
2030 return buffer.str().c_str();
2034 void Buffer::writeFileAscii(string const & fname, int linelen)
2036 ofstream ofs(fname.c_str());
2038 Alert::err_alert(_("Error: Cannot write file:"), fname);
2041 writeFileAscii(ofs, linelen);
2045 void Buffer::writeFileAscii(ostream & ofs, int linelen)
2047 Paragraph * par = paragraph;
2049 ofs << asciiParagraph(par, linelen, par->previous() == 0);
2059 void Buffer::makeLaTeXFile(string const & fname,
2060 string const & original_path,
2061 bool nice, bool only_body)
2063 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
2065 ofstream ofs(fname.c_str());
2067 Alert::err_alert(_("Error: Cannot open file: "), fname);
2071 niceFile = nice; // this will be used by Insetincludes.
2073 tex_code_break_column = lyxrc.ascii_linelen;
2075 // validate the buffer.
2076 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
2077 LaTeXFeatures features(params);
2079 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
2082 // The starting paragraph of the coming rows is the
2083 // first paragraph of the document. (Asger)
2084 texrow.start(paragraph, 0);
2086 if (!only_body && nice) {
2087 ofs << "%% " << lyx_docversion << " created this file. "
2088 "For more info, see http://www.lyx.org/.\n"
2089 "%% Do not edit unless you really know what "
2094 lyxerr[Debug::INFO] << "lyx header finished" << endl;
2095 // There are a few differences between nice LaTeX and usual files:
2096 // usual is \batchmode and has a
2097 // special input@path to allow the including of figures
2098 // with either \input or \includegraphics (what figinsets do).
2099 // batchmode is not set if there is a tex_code_break_column.
2100 // In this case somebody is interested in the generated LaTeX,
2101 // so this is OK. input@path is set when the actual parameter
2102 // original_path is set. This is done for usual tex-file, but not
2103 // for nice-latex-file. (Matthias 250696)
2106 // code for usual, NOT nice-latex-file
2107 ofs << "\\batchmode\n"; // changed
2108 // from \nonstopmode
2111 if (!original_path.empty()) {
2112 string inputpath = os::external_path(original_path);
2113 subst(inputpath, "~", "\\string~");
2114 ofs << "\\makeatletter\n"
2115 << "\\def\\input@path{{"
2116 << inputpath << "/}}\n"
2117 << "\\makeatother\n";
2123 ofs << "\\documentclass";
2125 LyXTextClass const & tclass = textclasslist[params.textclass];
2127 ostringstream options; // the document class options.
2129 if (tokenPos(tclass.opt_fontsize(),
2130 '|', params.fontsize) >= 0) {
2131 // only write if existing in list (and not default)
2132 options << params.fontsize << "pt,";
2136 if (!params.use_geometry &&
2137 (params.paperpackage == BufferParams::PACKAGE_NONE)) {
2138 switch (params.papersize) {
2139 case BufferParams::PAPER_A4PAPER:
2140 options << "a4paper,";
2142 case BufferParams::PAPER_USLETTER:
2143 options << "letterpaper,";
2145 case BufferParams::PAPER_A5PAPER:
2146 options << "a5paper,";
2148 case BufferParams::PAPER_B5PAPER:
2149 options << "b5paper,";
2151 case BufferParams::PAPER_EXECUTIVEPAPER:
2152 options << "executivepaper,";
2154 case BufferParams::PAPER_LEGALPAPER:
2155 options << "legalpaper,";
2161 if (params.sides != tclass.sides()) {
2162 switch (params.sides) {
2163 case LyXTextClass::OneSide:
2164 options << "oneside,";
2166 case LyXTextClass::TwoSides:
2167 options << "twoside,";
2173 if (params.columns != tclass.columns()) {
2174 if (params.columns == 2)
2175 options << "twocolumn,";
2177 options << "onecolumn,";
2180 if (!params.use_geometry
2181 && params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
2182 options << "landscape,";
2184 // language should be a parameter to \documentclass
2186 ostringstream language_options;
2187 if (params.language->babel() == "hebrew"
2188 && default_language->babel() != "hebrew")
2189 // This seems necessary
2190 features.useLanguage(default_language);
2192 if (lyxrc.language_use_babel ||
2193 params.language->lang() != lyxrc.default_language ||
2194 features.hasLanguages()) {
2196 language_options << features.getLanguages();
2197 language_options << params.language->babel();
2198 if (lyxrc.language_global_options)
2199 options << language_options.str() << ',';
2202 // the user-defined options
2203 if (!params.options.empty()) {
2204 options << params.options << ',';
2207 string strOptions(options.str().c_str());
2208 if (!strOptions.empty()) {
2209 strOptions = strip(strOptions, ',');
2210 ofs << '[' << strOptions << ']';
2213 ofs << '{' << tclass.latexname() << "}\n";
2215 // end of \documentclass defs
2217 // font selection must be done before loading fontenc.sty
2218 // The ae package is not needed when using OT1 font encoding.
2219 if (params.fonts != "default" &&
2220 (params.fonts != "ae" || lyxrc.fontenc != "default")) {
2221 ofs << "\\usepackage{" << params.fonts << "}\n";
2223 if (params.fonts == "ae") {
2224 ofs << "\\usepackage{aecompl}\n";
2228 // this one is not per buffer
2229 if (lyxrc.fontenc != "default") {
2230 ofs << "\\usepackage[" << lyxrc.fontenc
2235 if (params.inputenc == "auto") {
2236 string const doc_encoding =
2237 params.language->encoding()->LatexName();
2239 // Create a list with all the input encodings used
2241 set<string> encodings = features.getEncodingSet(doc_encoding);
2243 ofs << "\\usepackage[";
2244 std::copy(encodings.begin(), encodings.end(),
2245 std::ostream_iterator<string>(ofs, ","));
2246 ofs << doc_encoding << "]{inputenc}\n";
2248 } else if (params.inputenc != "default") {
2249 ofs << "\\usepackage[" << params.inputenc
2254 // At the very beginning the text parameters.
2255 if (params.paperpackage != BufferParams::PACKAGE_NONE) {
2256 switch (params.paperpackage) {
2257 case BufferParams::PACKAGE_A4:
2258 ofs << "\\usepackage{a4}\n";
2261 case BufferParams::PACKAGE_A4WIDE:
2262 ofs << "\\usepackage{a4wide}\n";
2265 case BufferParams::PACKAGE_WIDEMARGINSA4:
2266 ofs << "\\usepackage[widemargins]{a4}\n";
2271 if (params.use_geometry) {
2272 ofs << "\\usepackage{geometry}\n";
2274 ofs << "\\geometry{verbose";
2275 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
2276 ofs << ",landscape";
2277 switch (params.papersize2) {
2278 case BufferParams::VM_PAPER_CUSTOM:
2279 if (!params.paperwidth.empty())
2280 ofs << ",paperwidth="
2281 << params.paperwidth;
2282 if (!params.paperheight.empty())
2283 ofs << ",paperheight="
2284 << params.paperheight;
2286 case BufferParams::VM_PAPER_USLETTER:
2287 ofs << ",letterpaper";
2289 case BufferParams::VM_PAPER_USLEGAL:
2290 ofs << ",legalpaper";
2292 case BufferParams::VM_PAPER_USEXECUTIVE:
2293 ofs << ",executivepaper";
2295 case BufferParams::VM_PAPER_A3:
2298 case BufferParams::VM_PAPER_A4:
2301 case BufferParams::VM_PAPER_A5:
2304 case BufferParams::VM_PAPER_B3:
2307 case BufferParams::VM_PAPER_B4:
2310 case BufferParams::VM_PAPER_B5:
2314 // default papersize ie BufferParams::VM_PAPER_DEFAULT
2315 switch (lyxrc.default_papersize) {
2316 case BufferParams::PAPER_DEFAULT: // keep compiler happy
2317 case BufferParams::PAPER_USLETTER:
2318 ofs << ",letterpaper";
2320 case BufferParams::PAPER_LEGALPAPER:
2321 ofs << ",legalpaper";
2323 case BufferParams::PAPER_EXECUTIVEPAPER:
2324 ofs << ",executivepaper";
2326 case BufferParams::PAPER_A3PAPER:
2329 case BufferParams::PAPER_A4PAPER:
2332 case BufferParams::PAPER_A5PAPER:
2335 case BufferParams::PAPER_B5PAPER:
2340 if (!params.topmargin.empty())
2341 ofs << ",tmargin=" << params.topmargin;
2342 if (!params.bottommargin.empty())
2343 ofs << ",bmargin=" << params.bottommargin;
2344 if (!params.leftmargin.empty())
2345 ofs << ",lmargin=" << params.leftmargin;
2346 if (!params.rightmargin.empty())
2347 ofs << ",rmargin=" << params.rightmargin;
2348 if (!params.headheight.empty())
2349 ofs << ",headheight=" << params.headheight;
2350 if (!params.headsep.empty())
2351 ofs << ",headsep=" << params.headsep;
2352 if (!params.footskip.empty())
2353 ofs << ",footskip=" << params.footskip;
2358 if (tokenPos(tclass.opt_pagestyle(),
2359 '|', params.pagestyle) >= 0) {
2360 if (params.pagestyle == "fancy") {
2361 ofs << "\\usepackage{fancyhdr}\n";
2364 ofs << "\\pagestyle{" << params.pagestyle << "}\n";
2368 if (params.secnumdepth != tclass.secnumdepth()) {
2369 ofs << "\\setcounter{secnumdepth}{"
2370 << params.secnumdepth
2374 if (params.tocdepth != tclass.tocdepth()) {
2375 ofs << "\\setcounter{tocdepth}{"
2381 if (params.paragraph_separation) {
2382 switch (params.defskip.kind()) {
2383 case VSpace::SMALLSKIP:
2384 ofs << "\\setlength\\parskip{\\smallskipamount}\n";
2386 case VSpace::MEDSKIP:
2387 ofs << "\\setlength\\parskip{\\medskipamount}\n";
2389 case VSpace::BIGSKIP:
2390 ofs << "\\setlength\\parskip{\\bigskipamount}\n";
2392 case VSpace::LENGTH:
2393 ofs << "\\setlength\\parskip{"
2394 << params.defskip.length().asLatexString()
2397 default: // should never happen // Then delete it.
2398 ofs << "\\setlength\\parskip{\\medskipamount}\n";
2403 ofs << "\\setlength\\parindent{0pt}\n";
2407 // Now insert the LyX specific LaTeX commands...
2409 // The optional packages;
2410 string preamble(features.getPackages());
2412 // this might be useful...
2413 preamble += "\n\\makeatletter\n";
2415 // Some macros LyX will need
2416 string tmppreamble(features.getMacros());
2418 if (!tmppreamble.empty()) {
2419 preamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2420 "LyX specific LaTeX commands.\n"
2421 + tmppreamble + '\n';
2424 // the text class specific preamble
2425 tmppreamble = features.getTClassPreamble();
2426 if (!tmppreamble.empty()) {
2427 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2428 "Textclass specific LaTeX commands.\n"
2429 + tmppreamble + '\n';
2432 /* the user-defined preamble */
2433 if (!params.preamble.empty()) {
2434 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2435 "User specified LaTeX commands.\n"
2436 + params.preamble + '\n';
2439 preamble += "\\makeatother\n";
2441 // Itemize bullet settings need to be last in case the user
2442 // defines their own bullets that use a package included
2443 // in the user-defined preamble -- ARRae
2444 // Actually it has to be done much later than that
2445 // since some packages like frenchb make modifications
2446 // at \begin{document} time -- JMarc
2448 for (int i = 0; i < 4; ++i) {
2449 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
2450 if (bullets_def.empty())
2451 bullets_def="\\AtBeginDocument{\n";
2452 bullets_def += " \\renewcommand{\\labelitemi";
2454 // `i' is one less than the item to modify
2461 bullets_def += "ii";
2467 bullets_def += "}{" +
2468 params.user_defined_bullets[i].getText()
2473 if (!bullets_def.empty())
2474 preamble += bullets_def + "}\n\n";
2477 int(lyx::count(preamble.begin(), preamble.end(), '\n'));
2478 for (int j = 0; j != nlines; ++j) {
2484 // We try to load babel late, in case it interferes
2485 // with other packages.
2487 string tmp = lyxrc.language_package;
2488 if (!lyxrc.language_global_options
2489 && tmp == "\\usepackage{babel}")
2490 tmp = string("\\usepackage[") +
2491 language_options.str().c_str() +
2498 ofs << "\\begin{document}\n";
2501 lyxerr[Debug::INFO] << "preamble finished, now the body." << endl;
2503 if (!lyxrc.language_auto_begin) {
2504 ofs << subst(lyxrc.language_command_begin, "$$lang",
2505 params.language->babel())
2510 latexParagraphs(ofs, paragraph, 0, texrow);
2512 // add this just in case after all the paragraphs
2516 if (!lyxrc.language_auto_end) {
2517 ofs << subst(lyxrc.language_command_end, "$$lang",
2518 params.language->babel())
2524 ofs << "\\end{document}\n";
2527 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
2529 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
2533 // Just to be sure. (Asger)
2536 // tex_code_break_column's value is used to decide
2537 // if we are in batchmode or not (within mathed_write()
2538 // in math_write.C) so we must set it to a non-zero
2539 // value when we leave otherwise we save incorrect .lyx files.
2540 tex_code_break_column = lyxrc.ascii_linelen;
2544 lyxerr << "File was not closed properly." << endl;
2547 lyxerr[Debug::INFO] << "Finished making latex file." << endl;
2548 lyxerr[Debug::INFO] << "Row count was " << texrow.rows()-1 << "." << endl;
2550 // we want this to be true outside previews (for insetexternal)
2556 // LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
2558 void Buffer::latexParagraphs(ostream & ofs, Paragraph * par,
2559 Paragraph * endpar, TexRow & texrow) const
2561 bool was_title = false;
2562 bool already_title = false;
2565 while (par != endpar) {
2566 Inset * in = par->inInset();
2567 // well we have to check if we are in an inset with unlimited
2568 // lenght (all in one row) if that is true then we don't allow
2569 // any special options in the paragraph and also we don't allow
2570 // any environment other then "Standard" to be valid!
2571 if ((in == 0) || !in->forceDefaultParagraphs(in)) {
2572 LyXLayout const & layout =
2573 textclasslist[params.textclass][par->layout()];
2575 if (layout.intitle) {
2576 if (already_title) {
2577 lyxerr <<"Error in latexParagraphs: You"
2578 " should not mix title layouts"
2579 " with normal ones." << endl;
2582 } else if (was_title && !already_title) {
2583 ofs << "\\maketitle\n";
2585 already_title = true;
2589 if (layout.isEnvironment()) {
2590 par = par->TeXEnvironment(this, params, ofs, texrow);
2592 par = par->TeXOnePar(this, params, ofs, texrow, false);
2595 par = par->TeXOnePar(this, params, ofs, texrow, false);
2598 // It might be that we only have a title in this document
2599 if (was_title && !already_title) {
2600 ofs << "\\maketitle\n";
2606 bool Buffer::isLatex() const
2608 return textclasslist[params.textclass].outputType() == LATEX;
2612 bool Buffer::isLinuxDoc() const
2614 return textclasslist[params.textclass].outputType() == LINUXDOC;
2618 bool Buffer::isLiterate() const
2620 return textclasslist[params.textclass].outputType() == LITERATE;
2624 bool Buffer::isDocBook() const
2626 return textclasslist[params.textclass].outputType() == DOCBOOK;
2630 bool Buffer::isSGML() const
2632 LyXTextClass const & tclass = textclasslist[params.textclass];
2634 return tclass.outputType() == LINUXDOC ||
2635 tclass.outputType() == DOCBOOK;
2639 void Buffer::sgmlOpenTag(ostream & os, Paragraph::depth_type,
2640 string const & latexname) const
2642 if (!latexname.empty() && latexname != "!-- --")
2643 //os << "<!-- " << depth << " -->" << "<" << latexname << ">";
2644 os << "<" << latexname << ">";
2648 void Buffer::sgmlCloseTag(ostream & os, Paragraph::depth_type,
2649 string const & latexname) const
2651 if (!latexname.empty() && latexname != "!-- --")
2652 //os << "<!-- " << depth << " -->" << "</" << latexname << ">\n";
2653 os << "</" << latexname << ">";
2657 void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
2659 ofstream ofs(fname.c_str());
2662 Alert::alert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2666 niceFile = nice; // this will be used by included files.
2668 LaTeXFeatures features(params);
2674 LyXTextClass const & tclass = textclasslist[params.textclass];
2676 string top_element = tclass.latexname();
2679 ofs << "<!doctype linuxdoc system";
2681 string preamble = params.preamble;
2682 const string name = nice ? ChangeExtension(filename_, ".sgml")
2684 preamble += features.getIncludedFiles(name);
2685 preamble += features.getLyXSGMLEntities();
2687 if (!preamble.empty()) {
2688 ofs << " [ " << preamble << " ]";
2692 if (params.options.empty())
2693 sgmlOpenTag(ofs, 0, top_element);
2695 string top = top_element;
2697 top += params.options;
2698 sgmlOpenTag(ofs, 0, top);
2702 ofs << "<!-- " << lyx_docversion
2703 << " created this file. For more info see http://www.lyx.org/"
2706 Paragraph::depth_type depth = 0; // paragraph depth
2707 Paragraph * par = paragraph;
2709 vector<string> environment_stack(5);
2712 LyXLayout const & style = tclass[par->layout()];
2714 // treat <toc> as a special case for compatibility with old code
2715 if (par->isInset(0)) {
2716 Inset * inset = par->getInset(0);
2717 Inset::Code lyx_code = inset->lyxCode();
2718 if (lyx_code == Inset::TOC_CODE) {
2719 string const temp = "toc";
2720 sgmlOpenTag(ofs, depth, temp);
2727 // environment tag closing
2728 for (; depth > par->params().depth(); --depth) {
2729 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2730 environment_stack[depth].erase();
2733 // write opening SGML tags
2734 switch (style.latextype) {
2735 case LATEX_PARAGRAPH:
2736 if (depth == par->params().depth()
2737 && !environment_stack[depth].empty()) {
2738 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2739 environment_stack[depth].erase();
2745 sgmlOpenTag(ofs, depth, style.latexname());
2751 _("Error : Wrong depth for"
2752 " LatexType Command.\n"));
2754 if (!environment_stack[depth].empty()) {
2755 sgmlCloseTag(ofs, depth,
2756 environment_stack[depth]);
2760 environment_stack[depth].erase();
2761 sgmlOpenTag(ofs, depth, style.latexname());
2764 case LATEX_ENVIRONMENT:
2765 case LATEX_ITEM_ENVIRONMENT:
2766 if (depth == par->params().depth()
2767 && environment_stack[depth] != style.latexname()) {
2768 sgmlCloseTag(ofs, depth,
2769 environment_stack[depth]);
2770 environment_stack[depth].erase();
2772 if (depth < par->params().depth()) {
2773 depth = par->params().depth();
2774 environment_stack[depth].erase();
2776 if (environment_stack[depth] != style.latexname()) {
2778 sgmlOpenTag(ofs, depth, "p");
2780 sgmlOpenTag(ofs, depth, style.latexname());
2782 if (environment_stack.size() == depth + 1)
2783 environment_stack.push_back("!-- --");
2784 environment_stack[depth] = style.latexname();
2787 if (style.latexparam() == "CDATA")
2790 if (style.latextype == LATEX_ENVIRONMENT) break;
2792 if (style.labeltype == LABEL_MANUAL)
2797 sgmlOpenTag(ofs, depth + 1, item_name);
2800 sgmlOpenTag(ofs, depth, style.latexname());
2804 simpleLinuxDocOnePar(ofs, par, depth);
2809 // write closing SGML tags
2810 switch (style.latextype) {
2813 case LATEX_ENVIRONMENT:
2814 case LATEX_ITEM_ENVIRONMENT:
2815 if (style.latexparam() == "CDATA")
2819 sgmlCloseTag(ofs, depth, style.latexname());
2825 for (int i=depth; i >= 0; --i)
2826 sgmlCloseTag(ofs, depth, environment_stack[i]);
2830 sgmlCloseTag(ofs, 0, top_element);
2834 // How to check for successful close
2836 // we want this to be true outside previews (for insetexternal)
2841 // checks, if newcol chars should be put into this line
2842 // writes newline, if necessary.
2845 void sgmlLineBreak(ostream & os, string::size_type & colcount,
2846 string::size_type newcol)
2849 if (colcount > lyxrc.ascii_linelen) {
2851 colcount = newcol; // assume write after this call
2866 string tag_name(PAR_TAG const & pt) {
2868 case NONE: return "!-- --";
2869 case TT: return "tt";
2870 case SF: return "sf";
2871 case BF: return "bf";
2872 case IT: return "it";
2873 case SL: return "sl";
2874 case EM: return "em";
2881 void operator|=(PAR_TAG & p1, PAR_TAG const & p2)
2883 p1 = static_cast<PAR_TAG>(p1 | p2);
2888 void reset(PAR_TAG & p1, PAR_TAG const & p2)
2890 p1 = static_cast<PAR_TAG>(p1 & ~p2);
2896 // Handle internal paragraph parsing -- layout already processed.
2897 void Buffer::simpleLinuxDocOnePar(ostream & os,
2899 Paragraph::depth_type /*depth*/)
2901 LyXLayout const & style =
2902 textclasslist[params.textclass][par->layout()];
2903 string::size_type char_line_count = 5; // Heuristic choice ;-)
2905 // gets paragraph main font
2908 if (style.labeltype == LABEL_MANUAL) {
2909 font_old = style.labelfont;
2912 font_old = style.font;
2916 LyXFont::FONT_FAMILY family_type = LyXFont::ROMAN_FAMILY;
2917 LyXFont::FONT_SERIES series_type = LyXFont::MEDIUM_SERIES;
2918 LyXFont::FONT_SHAPE shape_type = LyXFont::UP_SHAPE;
2921 stack<PAR_TAG> tag_state;
2922 // parsing main loop
2923 for (pos_type i = 0; i < par->size(); ++i) {
2925 PAR_TAG tag_close = NONE;
2926 list < PAR_TAG > tag_open;
2928 LyXFont const font = par->getFont(params, i);
2930 if (font_old.family() != font.family()) {
2931 switch (family_type) {
2932 case LyXFont::SANS_FAMILY:
2935 case LyXFont::TYPEWRITER_FAMILY:
2942 family_type = font.family();
2944 switch (family_type) {
2945 case LyXFont::SANS_FAMILY:
2946 tag_open.push_back(SF);
2948 case LyXFont::TYPEWRITER_FAMILY:
2949 tag_open.push_back(TT);
2956 if (font_old.series() != font.series()) {
2957 switch (series_type) {
2958 case LyXFont::BOLD_SERIES:
2965 series_type = font.series();
2967 switch (series_type) {
2968 case LyXFont::BOLD_SERIES:
2969 tag_open.push_back(BF);
2977 if (font_old.shape() != font.shape()) {
2978 switch (shape_type) {
2979 case LyXFont::ITALIC_SHAPE:
2982 case LyXFont::SLANTED_SHAPE:
2989 shape_type = font.shape();
2991 switch (shape_type) {
2992 case LyXFont::ITALIC_SHAPE:
2993 tag_open.push_back(IT);
2995 case LyXFont::SLANTED_SHAPE:
2996 tag_open.push_back(SL);
3003 if (font_old.emph() != font.emph()) {
3004 if (font.emph() == LyXFont::ON) {
3005 tag_open.push_back(EM);
3014 list < PAR_TAG > temp;
3015 while (!tag_state.empty() && tag_close) {
3016 PAR_TAG k = tag_state.top();
3018 os << "</" << tag_name(k) << ">";
3025 for(list< PAR_TAG >::const_iterator j = temp.begin();
3026 j != temp.end(); ++j) {
3028 os << "<" << tag_name(*j) << ">";
3031 for(list< PAR_TAG >::const_iterator j = tag_open.begin();
3032 j != tag_open.end(); ++j) {
3034 os << "<" << tag_name(*j) << ">";
3037 char c = par->getChar(i);
3039 if (c == Paragraph::META_INSET) {
3040 Inset * inset = par->getInset(i);
3041 inset->linuxdoc(this, os);
3046 if (style.latexparam() == "CDATA") {
3047 // "TeX"-Mode on == > SGML-Mode on.
3053 if (par->sgmlConvertChar(c, sgml_string)
3054 && !style.free_spacing && !par->isFreeSpacing())
3056 // in freespacing mode, spaces are
3057 // non-breaking characters
3058 if (desc_on) {// if char is ' ' then...
3061 sgmlLineBreak(os, char_line_count, 6);
3065 sgmlLineBreak(os, char_line_count, 1);
3070 char_line_count += sgml_string.length();
3076 while (!tag_state.empty()) {
3077 os << "</" << tag_name(tag_state.top()) << ">";
3081 // resets description flag correctly
3083 // <tag> not closed...
3084 sgmlLineBreak(os, char_line_count, 6);
3090 // Print an error message.
3091 void Buffer::sgmlError(Paragraph * /*par*/, int /*pos*/,
3092 string const & /*message*/) const
3094 #warning This is wrong we cannot insert an inset like this!!!
3095 // I guess this was Jose' so I explain you more or less why this
3096 // is wrong. This way you insert something in the paragraph and
3097 // don't tell it to LyXText (row rebreaking and undo handling!!!)
3098 // I deactivate this code, have a look at BufferView::insertErrors
3099 // how you should do this correctly! (Jug 20020315)
3101 // insert an error marker in text
3102 InsetError * new_inset = new InsetError(message);
3103 par->insertInset(pos, new_inset, LyXFont(LyXFont::ALL_INHERIT,
3109 void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
3111 ofstream ofs(fname.c_str());
3113 Alert::alert(_("LYX_ERROR:"), _("Cannot write file"), fname);
3117 Paragraph * par = paragraph;
3119 niceFile = nice; // this will be used by Insetincludes.
3121 LaTeXFeatures features(params);
3126 LyXTextClass const & tclass = textclasslist[params.textclass];
3127 string top_element = tclass.latexname();
3130 ofs << "<!DOCTYPE " << top_element
3131 << " PUBLIC \"-//OASIS//DTD DocBook V4.1//EN\"";
3133 string preamble = params.preamble;
3134 const string name = nice ? ChangeExtension(filename_, ".sgml")
3136 preamble += features.getIncludedFiles(name);
3137 preamble += features.getLyXSGMLEntities();
3139 if (!preamble.empty()) {
3140 ofs << "\n [ " << preamble << " ]";
3145 string top = top_element;
3147 top += params.language->code();
3150 if (!params.options.empty()) {
3152 top += params.options;
3154 sgmlOpenTag(ofs, 0, top);
3156 ofs << "<!-- DocBook file was created by " << lyx_docversion
3157 << "\n See http://www.lyx.org/ for more information -->\n";
3159 vector<string> environment_stack(10);
3160 vector<string> environment_inner(10);
3161 vector<string> command_stack(10);
3163 bool command_flag = false;
3164 Paragraph::depth_type command_depth = 0;
3165 Paragraph::depth_type command_base = 0;
3166 Paragraph::depth_type cmd_depth = 0;
3167 Paragraph::depth_type depth = 0; // paragraph depth
3170 string command_name;
3176 int desc_on = 0; // description mode
3178 LyXLayout const & style = tclass[par->layout()];
3180 // environment tag closing
3181 for (; depth > par->params().depth(); --depth) {
3182 if (environment_inner[depth] != "!-- --") {
3183 item_name = "listitem";
3184 sgmlCloseTag(ofs, command_depth + depth,
3186 if (environment_inner[depth] == "varlistentry")
3187 sgmlCloseTag(ofs, depth+command_depth,
3188 environment_inner[depth]);
3190 sgmlCloseTag(ofs, depth + command_depth,
3191 environment_stack[depth]);
3192 environment_stack[depth].erase();
3193 environment_inner[depth].erase();
3196 if (depth == par->params().depth()
3197 && environment_stack[depth] != style.latexname()
3198 && !environment_stack[depth].empty()) {
3199 if (environment_inner[depth] != "!-- --") {
3200 item_name= "listitem";
3201 sgmlCloseTag(ofs, command_depth+depth,
3203 if (environment_inner[depth] == "varlistentry")
3205 depth + command_depth,
3206 environment_inner[depth]);
3209 sgmlCloseTag(ofs, depth + command_depth,
3210 environment_stack[depth]);
3212 environment_stack[depth].erase();
3213 environment_inner[depth].erase();
3216 // Write opening SGML tags.
3217 switch (style.latextype) {
3218 case LATEX_PARAGRAPH:
3219 sgmlOpenTag(ofs, depth + command_depth,
3226 _("Error : Wrong depth for "
3227 "LatexType Command.\n"));
3229 command_name = style.latexname();
3231 sgmlparam = style.latexparam();
3232 c_params = split(sgmlparam, c_depth,'|');
3234 cmd_depth = lyx::atoi(c_depth);
3237 if (cmd_depth < command_base) {
3238 for (Paragraph::depth_type j = command_depth; j >= command_base; --j)
3239 sgmlCloseTag(ofs, j, command_stack[j]);
3240 command_depth = command_base = cmd_depth;
3241 } else if (cmd_depth <= command_depth) {
3242 for (int j = command_depth; j >= int(cmd_depth); --j)
3243 sgmlCloseTag(ofs, j, command_stack[j]);
3244 command_depth = cmd_depth;
3246 command_depth = cmd_depth;
3248 command_depth = command_base = cmd_depth;
3249 command_flag = true;
3251 if (command_stack.size() == command_depth + 1)
3252 command_stack.push_back(string());
3253 command_stack[command_depth] = command_name;
3255 // treat label as a special case for
3256 // more WYSIWYM handling.
3257 // This is a hack while paragraphs can't have
3258 // attributes, like id in this case.
3259 if (par->isInset(0)) {
3260 Inset * inset = par->getInset(0);
3261 Inset::Code lyx_code = inset->lyxCode();
3262 if (lyx_code == Inset::LABEL_CODE) {
3263 command_name += " id=\"";
3264 command_name += (static_cast<InsetCommand *>(inset))->getContents();
3265 command_name += "\"";
3270 sgmlOpenTag(ofs, depth + command_depth, command_name);
3271 if (c_params.empty())
3272 item_name = "title";
3274 item_name = c_params;
3275 sgmlOpenTag(ofs, depth + 1 + command_depth, item_name);
3278 case LATEX_ENVIRONMENT:
3279 case LATEX_ITEM_ENVIRONMENT:
3280 if (depth < par->params().depth()) {
3281 depth = par->params().depth();
3282 environment_stack[depth].erase();
3285 if (environment_stack[depth] != style.latexname()) {
3286 if (environment_stack.size() == depth + 1) {
3287 environment_stack.push_back("!-- --");
3288 environment_inner.push_back("!-- --");
3290 environment_stack[depth] = style.latexname();
3291 environment_inner[depth] = "!-- --";
3292 sgmlOpenTag(ofs, depth + command_depth,
3293 environment_stack[depth]);
3295 if (environment_inner[depth] != "!-- --") {
3296 item_name= "listitem";
3298 command_depth + depth,
3300 if (environment_inner[depth] == "varlistentry")
3302 depth + command_depth,
3303 environment_inner[depth]);
3307 if (style.latextype == LATEX_ENVIRONMENT) {
3308 if (!style.latexparam().empty()) {
3309 if (style.latexparam() == "CDATA")
3312 sgmlOpenTag(ofs, depth + command_depth,
3313 style.latexparam());
3318 desc_on = (style.labeltype == LABEL_MANUAL);
3321 environment_inner[depth]= "varlistentry";
3323 environment_inner[depth]= "listitem";
3325 sgmlOpenTag(ofs, depth + 1 + command_depth,
3326 environment_inner[depth]);
3330 sgmlOpenTag(ofs, depth + 1 + command_depth,
3334 sgmlOpenTag(ofs, depth + 1 + command_depth,
3339 sgmlOpenTag(ofs, depth + command_depth,
3344 simpleDocBookOnePar(ofs, par, desc_on, depth+1+command_depth);
3348 // write closing SGML tags
3349 switch (style.latextype) {
3351 if (c_params.empty())
3355 sgmlCloseTag(ofs, depth + command_depth, end_tag);
3357 case LATEX_ENVIRONMENT:
3358 if (!style.latexparam().empty()) {
3359 if (style.latexparam() == "CDATA")
3362 sgmlCloseTag(ofs, depth + command_depth,
3363 style.latexparam());
3366 case LATEX_ITEM_ENVIRONMENT:
3367 if (desc_on == 1) break;
3369 sgmlCloseTag(ofs, depth + 1 + command_depth, end_tag);
3371 case LATEX_PARAGRAPH:
3372 sgmlCloseTag(ofs, depth + command_depth, style.latexname());
3375 sgmlCloseTag(ofs, depth + command_depth, style.latexname());
3381 for (int d = depth; d >= 0; --d) {
3382 if (!environment_stack[depth].empty()) {
3383 if (environment_inner[depth] != "!-- --") {
3384 item_name = "listitem";
3385 sgmlCloseTag(ofs, command_depth + depth,
3387 if (environment_inner[depth] == "varlistentry")
3388 sgmlCloseTag(ofs, depth + command_depth,
3389 environment_inner[depth]);
3392 sgmlCloseTag(ofs, depth + command_depth,
3393 environment_stack[depth]);
3397 for (int j = command_depth; j >= 0 ; --j)
3398 if (!command_stack[j].empty())
3399 sgmlCloseTag(ofs, j, command_stack[j]);
3402 sgmlCloseTag(ofs, 0, top_element);
3405 // How to check for successful close
3407 // we want this to be true outside previews (for insetexternal)
3412 void Buffer::simpleDocBookOnePar(ostream & os,
3413 Paragraph * par, int & desc_on,
3414 Paragraph::depth_type depth) const
3416 bool emph_flag = false;
3418 LyXLayout const & style =
3419 textclasslist[params.textclass][par->layout()];
3421 LyXFont font_old = style.labeltype == LABEL_MANUAL ? style.labelfont : style.font;
3423 int char_line_count = depth;
3424 //if (!style.free_spacing)
3425 // os << string(depth,' ');
3427 // parsing main loop
3428 for (pos_type i = 0; i < par->size(); ++i) {
3429 LyXFont font = par->getFont(params, i);
3431 // handle <emphasis> tag
3432 if (font_old.emph() != font.emph()) {
3433 if (font.emph() == LyXFont::ON) {
3437 os << "</emphasis>";
3443 if (par->isInset(i)) {
3444 Inset * inset = par->getInset(i);
3445 // don't print the inset in position 0 if desc_on == 3 (label)
3446 if ( i || desc_on != 3) {
3447 if(style.latexparam() == "CDATA")
3449 inset->docbook(this, os);
3450 if(style.latexparam() == "CDATA")
3454 char c = par->getChar(i);
3456 par->sgmlConvertChar(c, sgml_string);
3458 if (style.pass_thru) {
3460 } else if (style.free_spacing || par->isFreeSpacing() || c != ' ') {
3462 } else if (desc_on ==1) {
3464 os << "\n</term><listitem><para>";
3474 os << "</emphasis>";
3477 // resets description flag correctly
3479 // <term> not closed...
3480 os << "</term>\n<listitem><para> </para>";
3482 if (style.free_spacing) os << '\n';
3486 // This should be enabled when the Chktex class is implemented. (Asger)
3487 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
3488 // Other flags: -wall -v0 -x
3489 int Buffer::runChktex()
3491 if (!users->text) return 0;
3493 users->owner()->prohibitInput();
3495 // get LaTeX-Filename
3496 string const name = getLatexName();
3497 string path = filePath();
3499 string const org_path = path;
3500 if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
3504 Path p(path); // path to LaTeX file
3505 users->owner()->message(_("Running chktex..."));
3507 // Remove all error insets
3508 bool const removedErrorInsets = users->removeAutoInsets();
3510 // Generate the LaTeX file if neccessary
3511 makeLaTeXFile(name, org_path, false);
3514 Chktex chktex(lyxrc.chktex_command, name, filePath());
3515 int res = chktex.run(terr); // run chktex
3518 Alert::alert(_("chktex did not work!"),
3519 _("Could not run with file:"), name);
3520 } else if (res > 0) {
3521 // Insert all errors as errors boxes
3522 users->insertErrors(terr);
3525 // if we removed error insets before we ran chktex or if we inserted
3526 // error insets after we ran chktex, this must be run:
3527 if (removedErrorInsets || res) {
3531 users->owner()->allowInput();
3537 void Buffer::validate(LaTeXFeatures & features) const
3539 Paragraph * par = paragraph;
3540 LyXTextClass const & tclass = textclasslist[params.textclass];
3542 // AMS Style is at document level
3543 if (params.use_amsmath || tclass.provides(LyXTextClass::amsmath))
3544 features.require("amsmath");
3547 // We don't use "lyxerr.debug" because of speed. (Asger)
3548 if (lyxerr.debugging(Debug::LATEX))
3549 lyxerr << "Paragraph: " << par << endl;
3551 // Now just follow the list of paragraphs and run
3552 // validate on each of them.
3553 par->validate(features);
3555 // and then the next paragraph
3559 // the bullet shapes are buffer level not paragraph level
3560 // so they are tested here
3561 for (int i = 0; i < 4; ++i) {
3562 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
3563 int const font = params.user_defined_bullets[i].getFont();
3565 int const c = params
3566 .user_defined_bullets[i]
3573 features.require("latexsym");
3575 } else if (font == 1) {
3576 features.require("amssymb");
3577 } else if ((font >= 2 && font <= 5)) {
3578 features.require("pifont");
3583 if (lyxerr.debugging(Debug::LATEX)) {
3584 features.showStruct();
3589 // This function should be in Buffer because it's a buffer's property (ale)
3590 string const Buffer::getIncludeonlyList(char delim)
3593 for (inset_iterator it = inset_iterator_begin();
3594 it != inset_iterator_end(); ++it) {
3595 if ((*it)->lyxCode() == Inset::INCLUDE_CODE) {
3596 InsetInclude * insetinc =
3597 static_cast<InsetInclude *>(*it);
3598 if (insetinc->isIncludeOnly()) {
3601 lst += insetinc->getRelFileBaseName();
3605 lyxerr[Debug::INFO] << "Includeonly(" << lst << ')' << endl;
3610 vector<string> const Buffer::getLabelList()
3612 /// if this is a child document and the parent is already loaded
3613 /// Use the parent's list instead [ale990407]
3614 if (!params.parentname.empty()
3615 && bufferlist.exists(params.parentname)) {
3616 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3618 return tmp->getLabelList();
3621 vector<string> label_list;
3622 for (inset_iterator it = inset_iterator_begin();
3623 it != inset_iterator_end(); ++it) {
3624 vector<string> const l = (*it)->getLabelList();
3625 label_list.insert(label_list.end(), l.begin(), l.end());
3631 Buffer::Lists const Buffer::getLists() const
3634 Paragraph * par = paragraph;
3636 LyXTextClass const & textclass = textclasslist[params.textclass];
3637 bool found = textclass.hasLayout("Caption");
3638 string const layout("Caption");
3641 char const labeltype = textclass[par->layout()].labeltype;
3643 if (labeltype >= LABEL_COUNTER_CHAPTER
3644 && labeltype <= LABEL_COUNTER_CHAPTER + params.tocdepth) {
3645 // insert this into the table of contents
3646 SingleList & item = l["TOC"];
3649 textclass.maxcounter());
3650 item.push_back(TocItem(par, depth, par->asString(this, true)));
3652 // For each paragrph, traverse its insets and look for
3656 Paragraph::inset_iterator it =
3657 par->inset_iterator_begin();
3658 Paragraph::inset_iterator end =
3659 par->inset_iterator_end();
3661 for (; it != end; ++it) {
3662 if ((*it)->lyxCode() == Inset::FLOAT_CODE) {
3664 static_cast<InsetFloat*>(*it);
3666 string const type = il->type();
3668 // Now find the caption in the float...
3669 // We now tranverse the paragraphs of
3671 Paragraph * tmp = il->inset.paragraph();
3673 if (tmp->layout() == layout) {
3674 SingleList & item = l[type];
3676 tostr(item.size()+1) + ". " + tmp->asString(this, false);
3677 item.push_back(TocItem(tmp, 0 , str));
3684 lyxerr << "Caption not found" << endl;
3693 // This is also a buffer property (ale)
3694 vector<pair<string, string> > const Buffer::getBibkeyList() const
3696 typedef pair<string, string> StringPair;
3697 /// if this is a child document and the parent is already loaded
3698 /// Use the parent's list instead [ale990412]
3699 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3700 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
3702 return tmp->getBibkeyList();
3705 vector<StringPair> keys;
3706 Paragraph * par = paragraph;
3709 string const key = par->bibkey->getContents();
3710 string const opt = par->bibkey->getOptions();
3711 string const ref = par->asString(this, false);
3712 string const info = opt + "TheBibliographyRef" + ref;
3714 keys.push_back(StringPair(key, info));
3719 // Might be either using bibtex or a child has bibliography
3721 for (inset_iterator it = inset_const_iterator_begin();
3722 it != inset_const_iterator_end(); ++it) {
3723 // Search for Bibtex or Include inset
3724 if ((*it)->lyxCode() == Inset::BIBTEX_CODE) {
3725 vector<StringPair> tmp =
3726 static_cast<InsetBibtex*>(*it)->getKeys(this);
3727 keys.insert(keys.end(), tmp.begin(), tmp.end());
3728 } else if ((*it)->lyxCode() == Inset::INCLUDE_CODE) {
3729 vector<StringPair> const tmp =
3730 static_cast<InsetInclude*>(*it)->getKeys();
3731 keys.insert(keys.end(), tmp.begin(), tmp.end());
3740 bool Buffer::isDepClean(string const & name) const
3742 DEPCLEAN * item = dep_clean;
3743 while (item && item->master != name)
3745 if (!item) return true;
3750 void Buffer::markDepClean(string const & name)
3753 dep_clean = new DEPCLEAN;
3754 dep_clean->clean = true;
3755 dep_clean->master = name;
3756 dep_clean->next = 0;
3758 DEPCLEAN * item = dep_clean;
3759 while (item && item->master != name)
3764 item = new DEPCLEAN;
3766 item->master = name;
3773 bool Buffer::dispatch(string const & command)
3775 // Split command string into command and argument
3777 string line = frontStrip(command);
3778 string const arg = strip(frontStrip(split(line, cmd, ' ')));
3780 return dispatch(lyxaction.LookupFunc(cmd), arg);
3784 bool Buffer::dispatch(int action, string const & argument)
3786 bool dispatched = true;
3789 Exporter::Export(this, argument, false);
3799 void Buffer::resizeInsets(BufferView * bv)
3801 /// then remove all LyXText in text-insets
3802 Paragraph * par = paragraph;
3803 for (; par; par = par->next()) {
3804 par->resizeInsetsLyXText(bv);
3809 void Buffer::redraw()
3816 void Buffer::changeLanguage(Language const * from, Language const * to)
3819 ParIterator end = par_iterator_end();
3820 for (ParIterator it = par_iterator_begin(); it != end; ++it)
3821 (*it)->changeLanguage(params, from, to);
3825 bool Buffer::isMultiLingual()
3827 ParIterator end = par_iterator_end();
3828 for (ParIterator it = par_iterator_begin(); it != end; ++it)
3829 if ((*it)->isMultiLingual(params))
3836 Buffer::inset_iterator::inset_iterator(Paragraph * paragraph, pos_type pos)
3839 it = par->InsetIterator(pos);
3840 if (it == par->inset_iterator_end()) {
3847 void Buffer::inset_iterator::setParagraph()
3850 it = par->inset_iterator_begin();
3851 if (it != par->inset_iterator_end())
3856 // We maintain an invariant that whenever par = 0 then it = 0
3860 Inset * Buffer::getInsetFromID(int id_arg) const
3862 for (inset_iterator it = inset_const_iterator_begin();
3863 it != inset_const_iterator_end(); ++it)
3865 if ((*it)->id() == id_arg)
3867 Inset * in = (*it)->getInsetFromID(id_arg);
3875 Paragraph * Buffer::getParFromID(int id) const
3877 if (id < 0) return 0;
3878 Paragraph * par = paragraph;
3880 if (par->id() == id) {
3883 Paragraph * tmp = par->getParFromID(id);
3893 ParIterator Buffer::par_iterator_begin()
3895 return ParIterator(paragraph);
3899 ParIterator Buffer::par_iterator_end()
3901 return ParIterator();