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);
466 // reset the font as we start a new layout and if the font is
467 // not ALL_INHERIT,document_language then it will be set to the
468 // right values after this tag (Jug 20020420)
469 font = LyXFont(LyXFont::ALL_INHERIT, params.language);
470 if (file_format < 216 && params.language->lang() == "hebrew")
471 font.setLanguage(default_language);
474 string layoutname = lex.getString();
476 LyXTextClass const & tclass = textclasslist[params.textclass];
478 if (layoutname.empty()) {
479 layoutname = tclass.defaultLayoutName();
481 #ifndef NO_COMPABILITY
482 if (compare_no_case(layoutname, "latex") == 0) {
483 ert_comp.active = true;
484 ert_comp.font = font;
487 bool hasLayout = tclass.hasLayout(layoutname);
489 lyxerr << "Layout '" << layoutname << "' does not"
490 << " exist in textclass '" << tclass.name()
492 lyxerr << "Trying to use default layout instead."
494 layoutname = tclass.defaultLayoutName();
498 // The is the compability reading of layout caption.
499 // It can be removed in LyX version 1.3.0. (Lgb)
500 if (compare_no_case(layoutname, "caption") == 0) {
501 // We expect that the par we are now working on is
502 // really inside a InsetText inside a InsetFloat.
503 // We also know that captions can only be
504 // one paragraph. (Lgb)
506 // We should now read until the next "\layout"
508 // This is probably not good enough, what if the
509 // caption is the last par in the document (Lgb)
510 istream & ist = lex.getStream();
516 if (prefixIs(line, "\\layout")) {
520 if (prefixIs(line, "\\begin_inset"))
522 if (prefixIs(line, "\\end_inset")) {
533 // Now we should have the whole layout in ss
534 // we should now be able to give this to the
536 ss << "\\end_inset\n";
538 // This seems like a bug in stringstream.
539 // We really should be able to use ss
541 istringstream is(ss.str());
543 tmplex.setStream(is);
544 Inset * inset = new InsetCaption;
545 inset->Read(this, tmplex);
546 par->InsertInset(pos, inset, font);
553 par = new Paragraph(par);
554 par->layout(textclasslist[params.textclass].defaultLayoutName());
557 par->layout(layoutname);
558 // Test whether the layout is obsolete.
559 LyXLayout const & layout =
560 textclasslist[params.textclass][par->layout()];
561 if (!layout.obsoleted_by().empty())
562 par->layout(layout.obsoleted_by());
563 par->params().depth(depth);
568 #ifndef NO_COMPABILITY
569 } else if (token == "\\begin_float") {
570 insertErtContents(par, pos);
571 //insertErtContents(par, pos, false);
572 //ert_stack.push(ert_comp);
573 //ert_comp = ErtComp();
575 // This is the compability reader. It can be removed in
576 // LyX version 1.3.0. (Lgb)
578 string const tmptok = lex.getString();
579 //lyxerr << "old float: " << tmptok << endl;
582 stringstream old_float;
584 if (tmptok == "footnote") {
585 inset = new InsetFoot(params);
586 old_float << "collapsed true\n";
587 } else if (tmptok == "margin") {
588 inset = new InsetMarginal(params);
589 old_float << "collapsed true\n";
590 } else if (tmptok == "fig") {
591 inset = new InsetFloat(params, "figure");
592 old_float << "placement htbp\n"
594 << "collapsed false\n";
595 } else if (tmptok == "tab") {
596 inset = new InsetFloat(params, "table");
597 old_float << "placement htbp\n"
599 << "collapsed false\n";
600 } else if (tmptok == "alg") {
601 inset = new InsetFloat(params, "algorithm");
602 old_float << "placement htbp\n"
604 << "collapsed false\n";
605 } else if (tmptok == "wide-fig") {
606 inset = new InsetFloat(params, "figure");
607 //InsetFloat * tmp = new InsetFloat("figure");
610 old_float << "placement htbp\n"
612 << "collapsed false\n";
613 } else if (tmptok == "wide-tab") {
614 inset = new InsetFloat(params, "table");
615 //InsetFloat * tmp = new InsetFloat("table");
618 old_float << "placement htbp\n"
620 << "collapsed false\n";
624 #ifndef NO_PEXTRA_REALLY
627 return false; // no end read yet
630 // Here we need to check for \end_deeper and handle that
631 // before we do the footnote parsing.
632 // This _is_ a hack! (Lgb)
635 string const tmp = lex.getString();
636 if (tmp == "\\end_deeper") {
637 //lyxerr << "\\end_deeper caught!" << endl;
639 lex.printError("\\end_deeper: "
640 "depth is already null");
645 old_float << tmp << ' ';
650 old_float << lex.getLongString("\\end_float")
651 << "\n\\end_inset\n";
652 //lyxerr << "Float Body:\n" << old_float.str() << endl;
653 // That this does not work seems like a bug
654 // in stringstream. (Lgb)
655 istringstream istr(old_float.str());
657 nylex.setStream(istr);
658 inset->read(this, nylex);
660 par->insertInset(pos, inset, font);
662 insertErtContents(par, pos);
664 // we have to reset the font as in the old format after a float
665 // the font was automatically reset!
666 font = LyXFont(LyXFont::ALL_INHERIT, params.language);
668 } else if (token == "\\begin_deeper") {
670 } else if (token == "\\end_deeper") {
672 lex.printError("\\end_deeper: "
673 "depth is already null");
677 } else if (token == "\\begin_preamble") {
678 params.readPreamble(lex);
679 } else if (token == "\\textclass") {
681 pair<bool, textclass_type> pp =
682 textclasslist.NumberOfClass(lex.getString());
684 params.textclass = pp.second;
686 Alert::alert(string(_("Textclass error")),
687 string(_("The document uses an unknown textclass \"")) +
688 lex.getString() + string("\"."),
689 string(_("LyX will not be able to produce output correctly.")));
690 params.textclass = 0;
692 if (!textclasslist[params.textclass].load()) {
693 // if the textclass wasn't loaded properly
694 // we need to either substitute another
695 // or stop loading the file.
696 // I can substitute but I don't see how I can
697 // stop loading... ideas?? ARRae980418
698 Alert::alert(_("Textclass Loading Error!"),
699 string(_("Can't load textclass ")) +
700 textclasslist[params.textclass].name(),
701 _("-- substituting default"));
702 params.textclass = 0;
704 } else if (token == "\\options") {
706 params.options = lex.getString();
707 } else if (token == "\\language") {
708 params.readLanguage(lex);
709 } else if (token == "\\fontencoding") {
711 } else if (token == "\\inputencoding") {
713 params.inputenc = lex.getString();
714 } else if (token == "\\graphics") {
715 params.readGraphicsDriver(lex);
716 } else if (token == "\\fontscheme") {
718 params.fonts = lex.getString();
719 } else if (token == "\\noindent") {
720 par->params().noindent(true);
721 } else if (token == "\\fill_top") {
722 par->params().spaceTop(VSpace(VSpace::VFILL));
723 } else if (token == "\\fill_bottom") {
724 par->params().spaceBottom(VSpace(VSpace::VFILL));
725 } else if (token == "\\line_top") {
726 par->params().lineTop(true);
727 } else if (token == "\\line_bottom") {
728 par->params().lineBottom(true);
729 } else if (token == "\\pagebreak_top") {
730 par->params().pagebreakTop(true);
731 } else if (token == "\\pagebreak_bottom") {
732 par->params().pagebreakBottom(true);
733 } else if (token == "\\start_of_appendix") {
734 par->params().startOfAppendix(true);
735 } else if (token == "\\paragraph_separation") {
736 int tmpret = lex.findToken(string_paragraph_separation);
739 if (tmpret != LYX_LAYOUT_DEFAULT)
740 params.paragraph_separation =
741 static_cast<BufferParams::PARSEP>(tmpret);
742 } else if (token == "\\defskip") {
744 params.defskip = VSpace(lex.getString());
745 #ifndef NO_COMPABILITY
746 } else if (token == "\\epsfig") { // obsolete
747 // Indeed it is obsolete, but we HAVE to be backwards
748 // compatible until 0.14, because otherwise all figures
749 // in existing documents are irretrivably lost. (Asger)
750 params.readGraphicsDriver(lex);
752 } else if (token == "\\quotes_language") {
753 int tmpret = lex.findToken(string_quotes_language);
756 if (tmpret != LYX_LAYOUT_DEFAULT) {
757 InsetQuotes::quote_language tmpl =
758 InsetQuotes::EnglishQ;
761 tmpl = InsetQuotes::EnglishQ;
764 tmpl = InsetQuotes::SwedishQ;
767 tmpl = InsetQuotes::GermanQ;
770 tmpl = InsetQuotes::PolishQ;
773 tmpl = InsetQuotes::FrenchQ;
776 tmpl = InsetQuotes::DanishQ;
779 params.quotes_language = tmpl;
781 } else if (token == "\\quotes_times") {
783 switch (lex.getInteger()) {
785 params.quotes_times = InsetQuotes::SingleQ;
788 params.quotes_times = InsetQuotes::DoubleQ;
791 } else if (token == "\\papersize") {
792 int tmpret = lex.findToken(string_papersize);
796 params.papersize2 = tmpret;
797 } else if (token == "\\paperpackage") {
798 int tmpret = lex.findToken(string_paperpackages);
801 params.paperpackage = BufferParams::PACKAGE_NONE;
803 params.paperpackage = tmpret;
804 } else if (token == "\\use_geometry") {
806 params.use_geometry = lex.getInteger();
807 } else if (token == "\\use_amsmath") {
809 params.use_amsmath = lex.getInteger();
810 } else if (token == "\\use_natbib") {
812 params.use_natbib = lex.getInteger();
813 } else if (token == "\\use_numerical_citations") {
815 params.use_numerical_citations = lex.getInteger();
816 } else if (token == "\\paperorientation") {
817 int tmpret = lex.findToken(string_orientation);
820 if (tmpret != LYX_LAYOUT_DEFAULT)
821 params.orientation = static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
822 } else if (token == "\\paperwidth") {
824 params.paperwidth = lex.getString();
825 } else if (token == "\\paperheight") {
827 params.paperheight = lex.getString();
828 } else if (token == "\\leftmargin") {
830 params.leftmargin = lex.getString();
831 } else if (token == "\\topmargin") {
833 params.topmargin = lex.getString();
834 } else if (token == "\\rightmargin") {
836 params.rightmargin = lex.getString();
837 } else if (token == "\\bottommargin") {
839 params.bottommargin = lex.getString();
840 } else if (token == "\\headheight") {
842 params.headheight = lex.getString();
843 } else if (token == "\\headsep") {
845 params.headsep = lex.getString();
846 } else if (token == "\\footskip") {
848 params.footskip = lex.getString();
849 } else if (token == "\\paperfontsize") {
851 params.fontsize = strip(lex.getString());
852 } else if (token == "\\papercolumns") {
854 params.columns = lex.getInteger();
855 } else if (token == "\\papersides") {
857 switch (lex.getInteger()) {
859 case 1: params.sides = LyXTextClass::OneSide; break;
860 case 2: params.sides = LyXTextClass::TwoSides; break;
862 } else if (token == "\\paperpagestyle") {
864 params.pagestyle = strip(lex.getString());
865 } else if (token == "\\bullet") {
867 int const index = lex.getInteger();
869 int temp_int = lex.getInteger();
870 params.user_defined_bullets[index].setFont(temp_int);
871 params.temp_bullets[index].setFont(temp_int);
873 temp_int = lex.getInteger();
874 params.user_defined_bullets[index].setCharacter(temp_int);
875 params.temp_bullets[index].setCharacter(temp_int);
877 temp_int = lex.getInteger();
878 params.user_defined_bullets[index].setSize(temp_int);
879 params.temp_bullets[index].setSize(temp_int);
881 string const temp_str = lex.getString();
882 if (temp_str != "\\end_bullet") {
883 // this element isn't really necessary for
884 // parsing but is easier for humans
885 // to understand bullets. Put it back and
886 // set a debug message?
887 lex.printError("\\end_bullet expected, got" + temp_str);
888 //how can I put it back?
890 } else if (token == "\\bulletLaTeX") {
891 // The bullet class should be able to read this.
893 int const index = lex.getInteger();
895 string temp_str = lex.getString();
897 while (temp_str != "\\end_bullet") {
898 // this loop structure is needed when user
899 // enters an empty string since the first
900 // thing returned will be the \\end_bullet
902 // if the LaTeX entry has spaces. Each element
903 // therefore needs to be read in turn
906 temp_str = lex.getString();
909 params.user_defined_bullets[index].setText(sum_str);
910 params.temp_bullets[index].setText(sum_str);
911 } else if (token == "\\secnumdepth") {
913 params.secnumdepth = lex.getInteger();
914 } else if (token == "\\tocdepth") {
916 params.tocdepth = lex.getInteger();
917 } else if (token == "\\spacing") {
919 string const tmp = strip(lex.getString());
920 Spacing::Space tmp_space = Spacing::Default;
922 if (tmp == "single") {
923 tmp_space = Spacing::Single;
924 } else if (tmp == "onehalf") {
925 tmp_space = Spacing::Onehalf;
926 } else if (tmp == "double") {
927 tmp_space = Spacing::Double;
928 } else if (tmp == "other") {
930 tmp_space = Spacing::Other;
931 tmp_val = lex.getFloat();
933 lex.printError("Unknown spacing token: '$$Token'");
935 // Small hack so that files written with klyx will be
938 par->params().spacing(Spacing(tmp_space, tmp_val));
940 params.spacing.set(tmp_space, tmp_val);
942 } else if (token == "\\paragraph_spacing") {
944 string const tmp = strip(lex.getString());
945 if (tmp == "single") {
946 par->params().spacing(Spacing(Spacing::Single));
947 } else if (tmp == "onehalf") {
948 par->params().spacing(Spacing(Spacing::Onehalf));
949 } else if (tmp == "double") {
950 par->params().spacing(Spacing(Spacing::Double));
951 } else if (tmp == "other") {
953 par->params().spacing(Spacing(Spacing::Other,
956 lex.printError("Unknown spacing token: '$$Token'");
958 } else if (token == "\\float_placement") {
960 params.float_placement = lex.getString();
961 } else if (token == "\\family") {
963 font.setLyXFamily(lex.getString());
964 } else if (token == "\\series") {
966 font.setLyXSeries(lex.getString());
967 } else if (token == "\\shape") {
969 font.setLyXShape(lex.getString());
970 } else if (token == "\\size") {
972 font.setLyXSize(lex.getString());
973 #ifndef NO_COMPABILITY
974 } else if (token == "\\latex") {
976 string const tok = lex.getString();
977 if (tok == "no_latex") {
979 insertErtContents(par, pos);
980 } else if (tok == "latex") {
981 ert_comp.active = true;
982 ert_comp.font = font;
983 } else if (tok == "default") {
985 insertErtContents(par, pos);
987 lex.printError("Unknown LaTeX font flag "
991 } else if (token == "\\lang") {
993 string const tok = lex.getString();
994 Language const * lang = languages.getLanguage(tok);
996 font.setLanguage(lang);
998 font.setLanguage(params.language);
999 lex.printError("Unknown language `$$Token'");
1001 } else if (token == "\\numeric") {
1003 font.setNumber(font.setLyXMisc(lex.getString()));
1004 } else if (token == "\\emph") {
1006 font.setEmph(font.setLyXMisc(lex.getString()));
1007 } else if (token == "\\bar") {
1009 string const tok = lex.getString();
1010 // This is dirty, but gone with LyX3. (Asger)
1012 font.setUnderbar(LyXFont::ON);
1013 else if (tok == "no")
1014 font.setUnderbar(LyXFont::OFF);
1015 else if (tok == "default")
1016 font.setUnderbar(LyXFont::INHERIT);
1018 lex.printError("Unknown bar font flag "
1020 } else if (token == "\\noun") {
1022 font.setNoun(font.setLyXMisc(lex.getString()));
1023 } else if (token == "\\color") {
1025 font.setLyXColor(lex.getString());
1026 } else if (token == "\\align") {
1027 int tmpret = lex.findToken(string_align);
1028 if (tmpret == -1) ++tmpret;
1029 if (tmpret != LYX_LAYOUT_DEFAULT) { // tmpret != 99 ???
1030 int const tmpret2 = int(pow(2.0, tmpret));
1031 //lyxerr << "Tmpret2 = " << tmpret2 << endl;
1032 par->params().align(LyXAlignment(tmpret2));
1034 } else if (token == "\\added_space_top") {
1036 VSpace value = VSpace(lex.getString());
1037 if ((value.length().len().value() != 0) ||
1038 (value.kind() != VSpace::LENGTH))
1039 par->params().spaceTop(value);
1040 } else if (token == "\\added_space_bottom") {
1042 VSpace value = VSpace(lex.getString());
1043 if ((value.length().len().value() != 0) ||
1044 (value.kind() != VSpace::LENGTH))
1045 par->params().spaceBottom(value);
1046 #ifndef NO_COMPABILITY
1047 #ifndef NO_PEXTRA_REALLY
1048 } else if (token == "\\pextra_type") {
1050 par->params().pextraType(lex.getInteger());
1051 } else if (token == "\\pextra_width") {
1053 par->params().pextraWidth(lex.getString());
1054 } else if (token == "\\pextra_widthp") {
1056 par->params().pextraWidthp(lex.getString());
1057 } else if (token == "\\pextra_alignment") {
1059 par->params().pextraAlignment(lex.getInteger());
1060 } else if (token == "\\pextra_hfill") {
1062 par->params().pextraHfill(lex.getInteger());
1063 } else if (token == "\\pextra_start_minipage") {
1065 par->params().pextraStartMinipage(lex.getInteger());
1068 } else if (token == "\\labelwidthstring") {
1070 par->params().labelWidthString(lex.getString());
1071 // do not delete this token, it is still needed!
1072 } else if (token == "\\end_inset") {
1073 lyxerr << "Solitary \\end_inset. Missing \\begin_inset?.\n"
1074 << "Last inset read was: " << last_inset_read
1076 // Simply ignore this. The insets do not have
1078 // But insets should read it, it is a part of
1079 // the inset isn't it? Lgb.
1080 } else if (token == "\\begin_inset") {
1081 #ifndef NO_COMPABILITY
1082 insertErtContents(par, pos, false);
1083 ert_stack.push(ert_comp);
1084 ert_comp = ErtComp();
1086 readInset(lex, par, pos, font);
1087 #ifndef NO_COMPABILITY
1088 ert_comp = ert_stack.top();
1090 insertErtContents(par, pos);
1092 } else if (token == "\\SpecialChar") {
1093 LyXLayout const & layout =
1094 textclasslist[params.textclass][par->layout()];
1096 // Insets don't make sense in a free-spacing context! ---Kayvan
1097 if (layout.free_spacing || par->isFreeSpacing()) {
1100 string next_token = lex.getString();
1101 if (next_token == "\\-") {
1102 par->insertChar(pos, '-', font);
1103 } else if (next_token == "\\protected_separator"
1104 || next_token == "~") {
1105 par->insertChar(pos, ' ', font);
1107 lex.printError("Token `$$Token' "
1109 "paragraph layout!");
1114 Inset * inset = new InsetSpecialChar;
1115 inset->read(this, lex);
1116 par->insertInset(pos, inset, font);
1119 } else if (token == "\\newline") {
1120 #ifndef NO_COMPABILITY
1121 if (!ert_comp.in_tabular && ert_comp.active) {
1122 ert_comp.contents += char(Paragraph::META_NEWLINE);
1124 // Since we cannot know it this is only a regular
1125 // newline or a tabular cell delimter we have to
1126 // handle the ERT here.
1127 insertErtContents(par, pos, false);
1129 par->insertChar(pos, Paragraph::META_NEWLINE, font);
1133 par->insertChar(pos, Paragraph::META_NEWLINE, font);
1136 } else if (token == "\\LyXTable") {
1137 #ifndef NO_COMPABILITY
1138 ert_comp.in_tabular = true;
1140 Inset * inset = new InsetTabular(*this);
1141 inset->read(this, lex);
1142 par->insertInset(pos, inset, font);
1144 } else if (token == "\\hfill") {
1145 par->insertChar(pos, Paragraph::META_HFILL, font);
1147 } else if (token == "\\protected_separator") { // obsolete
1148 // This is a backward compability thingie. (Lgb)
1149 // Remove it later some time...introduced with fileformat
1151 LyXLayout const & layout =
1152 textclasslist[params.textclass][par->layout()];
1154 if (layout.free_spacing || par->isFreeSpacing()) {
1155 par->insertChar(pos, ' ', font);
1157 Inset * inset = new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
1158 par->insertInset(pos, inset, font);
1161 } else if (token == "\\bibitem") { // ale970302
1163 InsetCommandParams p("bibitem", "dummy");
1164 par->bibkey = new InsetBibKey(p);
1166 par->bibkey->read(this, lex);
1167 } else if (token == "\\backslash") {
1168 #ifndef NO_COMPABILITY
1169 if (ert_comp.active) {
1170 ert_comp.contents += "\\";
1173 par->insertChar(pos, '\\', font);
1175 #ifndef NO_COMPABILITY
1178 } else if (token == "\\the_end") {
1179 #ifndef NO_COMPABILITY
1180 // If we still have some ert active here we have to insert
1181 // it so we don't loose it. (Lgb)
1182 insertErtContents(par, pos);
1184 the_end_read = true;
1185 #ifndef NO_COMPABILITY
1186 #ifndef NO_PEXTRA_REALLY
1189 minipar = parBeforeMinipage = 0;
1193 #ifndef NO_COMPABILITY
1194 if (ert_comp.active) {
1195 ert_comp.contents += token;
1198 // This should be insurance for the future: (Asger)
1201 string const s = _("Unknown token: ") + token
1202 + " " + lex.text() + "\n";
1203 // we can do this here this way because we're actually reading
1204 // the buffer and don't care about LyXText right now.
1205 InsetError * new_inset = new InsetError(s);
1206 par->insertInset(pos, new_inset, LyXFont(LyXFont::ALL_INHERIT,
1209 #ifndef NO_COMPABILITY
1214 #ifndef NO_COMPABILITY
1215 #ifndef NO_PEXTRA_REALLY
1216 // I wonder if we could use this blanket fix for all the
1217 // checkminipage cases...
1218 // don't forget about ert paragraphs and compatibility read for'em
1219 if (par && (par->size() || !ert_comp.contents.empty())) {
1220 // It is possible that this will check to often,
1221 // but that should not be an correctness issue.
1222 // Only a speed issue.
1223 checkminipage = true;
1226 // now check if we have a minipage paragraph as at this
1227 // point we already read all the necessary data!
1228 // this cannot be done in layout because there we did
1229 // not read yet the paragraph PEXTRA-params (Jug)
1231 // BEGIN pextra_minipage compability
1232 // This should be removed in 1.3.x (Lgb)
1233 // I don't think we should remove this so fast (Jug)
1235 // This compability code is not perfect. In a couple
1236 // of rand cases it fails. When the minipage par is
1237 // the first par in the document, and when there are
1238 // none or only one regular paragraphs after the
1239 // minipage. Currently I am not investing any effort
1240 // in fixing those cases.
1242 // lyxerr << "Call depth: " << call_depth << endl;
1243 // lyxerr << "Checkminipage: " << checkminipage << endl;
1245 if (checkminipage && (call_depth == 1)) {
1246 checkminipage = false;
1247 if (minipar && (minipar != par) &&
1248 (par->params().pextraType() == Paragraph::PEXTRA_MINIPAGE)) {
1249 lyxerr << "minipages in a row" << endl;
1250 if (par->params().pextraStartMinipage()) {
1251 lyxerr << "start new minipage" << endl;
1252 // minipages in a row
1253 par->previous()->next(0);
1256 Paragraph * tmp = minipar;
1258 tmp->params().pextraType(0);
1259 tmp->params().pextraWidth(string());
1260 tmp->params().pextraWidthp(string());
1261 tmp->params().pextraAlignment(0);
1262 tmp->params().pextraHfill(false);
1263 tmp->params().pextraStartMinipage(false);
1266 // create a new paragraph to insert the
1267 // minipages in the following case
1268 if (par->params().pextraStartMinipage() &&
1269 !par->params().pextraHfill()) {
1270 Paragraph * p = new Paragraph;
1271 p->layout(textclasslist[params.textclass].defaultLayoutName());
1273 p->previous(parBeforeMinipage);
1274 parBeforeMinipage->next(p);
1276 p->params().depth(parBeforeMinipage->params().depth());
1277 parBeforeMinipage = p;
1279 InsetMinipage * mini = new InsetMinipage(params);
1280 mini->pos(static_cast<InsetMinipage::Position>(par->params().pextraAlignment()));
1281 mini->pageWidth(LyXLength(par->params().pextraWidth()));
1282 if (!par->params().pextraWidthp().empty()) {
1283 lyxerr << "WP:" << mini->pageWidth().asString() << endl;
1284 mini->pageWidth(LyXLength((par->params().pextraWidthp())+"col%"));
1286 Paragraph * op = mini->firstParagraph();
1287 mini->inset.paragraph(par);
1289 // and free the old ones!
1292 Paragraph * pp = op->next();
1296 // Insert the minipage last in the
1297 // previous paragraph.
1298 if (par->params().pextraHfill()) {
1299 parBeforeMinipage->insertChar
1300 (parBeforeMinipage->size(),
1301 Paragraph::META_HFILL, font);
1303 parBeforeMinipage->insertInset
1304 (parBeforeMinipage->size(), mini, font);
1308 lyxerr << "new minipage par" << endl;
1309 //nothing to do just continue reading
1312 } else if (minipar && (minipar != par)) {
1313 lyxerr << "last minipage par read" << endl;
1314 // The last paragraph read was not part of a
1315 // minipage but the par linked list is...
1316 // So we need to remove the last par from the
1318 if (par->previous())
1319 par->previous()->next(0);
1320 par->previous(parBeforeMinipage);
1321 parBeforeMinipage->next(par);
1322 Paragraph * tmp = minipar;
1324 tmp->params().pextraType(0);
1325 tmp->params().pextraWidth(string());
1326 tmp->params().pextraWidthp(string());
1327 tmp->params().pextraAlignment(0);
1328 tmp->params().pextraHfill(false);
1329 tmp->params().pextraStartMinipage(false);
1332 depth = parBeforeMinipage->params().depth();
1333 // and set this depth on the par as it has not been set already
1334 par->params().depth(depth);
1335 minipar = parBeforeMinipage = 0;
1336 } else if (!minipar &&
1337 (par->params().pextraType() == Paragraph::PEXTRA_MINIPAGE)) {
1338 // par is the first paragraph in a minipage
1339 lyxerr << "begin minipage" << endl;
1340 // To minimize problems for
1341 // the users we will insert
1342 // the first minipage in
1343 // a sequence of minipages
1344 // in its own paragraph.
1345 Paragraph * p = new Paragraph;
1346 p->layout(textclasslist[params.textclass].defaultLayoutName());
1347 p->previous(par->previous());
1349 p->params().depth(depth);
1350 par->params().depth(0);
1352 if (par->previous())
1353 par->previous()->next(p);
1355 parBeforeMinipage = p;
1357 if (!first_par || (first_par == par))
1360 InsetMinipage * mini = new InsetMinipage(params);
1361 mini->pos(static_cast<InsetMinipage::Position>(minipar->params().pextraAlignment()));
1362 mini->pageWidth(LyXLength(minipar->params().pextraWidth()));
1363 if (!par->params().pextraWidthp().empty()) {
1364 lyxerr << "WP:" << mini->pageWidth().asString() << endl;
1365 mini->pageWidth(LyXLength((par->params().pextraWidthp())+"col%"));
1368 Paragraph * op = mini->firstParagraph();
1369 mini->inset.paragraph(minipar);
1371 // and free the old ones!
1374 Paragraph * pp = op->next();
1379 // Insert the minipage last in the
1380 // previous paragraph.
1381 if (minipar->params().pextraHfill()) {
1382 parBeforeMinipage->insertChar
1383 (parBeforeMinipage->size(),
1384 Paragraph::META_HFILL, font);
1386 parBeforeMinipage->insertInset
1387 (parBeforeMinipage->size(), mini, font);
1390 // End of pextra_minipage compability
1394 return the_end_read;
1397 // needed to insert the selection
1398 void Buffer::insertStringAsLines(Paragraph *& par, pos_type & pos,
1399 LyXFont const & fn,string const & str) const
1401 LyXLayout const & layout =
1402 textclasslist[params.textclass][par->layout()];
1405 par->checkInsertChar(font);
1406 // insert the string, don't insert doublespace
1407 bool space_inserted = true;
1408 bool autobreakrows = !par->inInset() ||
1409 static_cast<InsetText *>(par->inInset())->getAutoBreakRows();
1410 for(string::const_iterator cit = str.begin();
1411 cit != str.end(); ++cit) {
1413 if (autobreakrows && (par->size() || layout.keepempty)) {
1414 par->breakParagraph(params, pos,
1415 layout.isEnvironment());
1418 space_inserted = true;
1422 // do not insert consecutive spaces if !free_spacing
1423 } else if ((*cit == ' ' || *cit == '\t') &&
1424 space_inserted && !layout.free_spacing &&
1425 !par->isFreeSpacing())
1428 } else if (*cit == '\t') {
1429 if (!layout.free_spacing && !par->isFreeSpacing()) {
1430 // tabs are like spaces here
1431 par->insertChar(pos, ' ', font);
1433 space_inserted = true;
1435 const pos_type nb = 8 - pos % 8;
1436 for (pos_type a = 0; a < nb ; ++a) {
1437 par->insertChar(pos, ' ', font);
1440 space_inserted = true;
1442 } else if (!IsPrintable(*cit)) {
1443 // Ignore unprintables
1446 // just insert the character
1447 par->insertChar(pos, *cit, font);
1449 space_inserted = (*cit == ' ');
1456 void Buffer::readInset(LyXLex & lex, Paragraph *& par,
1457 int & pos, LyXFont & font)
1459 // consistency check
1460 if (lex.getString() != "\\begin_inset") {
1461 lyxerr << "Buffer::readInset: Consistency check failed."
1468 string const tmptok = lex.getString();
1469 last_inset_read = tmptok;
1471 // test the different insets
1472 if (tmptok == "LatexCommand") {
1473 InsetCommandParams inscmd;
1476 string const cmdName = inscmd.getCmdName();
1478 // This strange command allows LyX to recognize "natbib" style
1479 // citations: citet, citep, Citet etc.
1480 if (compare_no_case(cmdName, "cite", 4) == 0) {
1481 inset = new InsetCitation(inscmd);
1482 } else if (cmdName == "bibitem") {
1483 lex.printError("Wrong place for bibitem");
1484 inset = new InsetBibKey(inscmd);
1485 } else if (cmdName == "BibTeX") {
1486 inset = new InsetBibtex(inscmd);
1487 } else if (cmdName == "index") {
1488 inset = new InsetIndex(inscmd);
1489 } else if (cmdName == "include") {
1490 inset = new InsetInclude(inscmd, *this);
1491 } else if (cmdName == "label") {
1492 inset = new InsetLabel(inscmd);
1493 } else if (cmdName == "url"
1494 || cmdName == "htmlurl") {
1495 inset = new InsetUrl(inscmd);
1496 } else if (cmdName == "ref"
1497 || cmdName == "pageref"
1498 || cmdName == "vref"
1499 || cmdName == "vpageref"
1500 || cmdName == "prettyref") {
1501 if (!inscmd.getOptions().empty()
1502 || !inscmd.getContents().empty()) {
1503 inset = new InsetRef(inscmd, *this);
1505 } else if (cmdName == "tableofcontents") {
1506 inset = new InsetTOC(inscmd);
1507 } else if (cmdName == "listofalgorithms") {
1508 inset = new InsetFloatList("algorithm");
1509 } else if (cmdName == "listoffigures") {
1510 inset = new InsetFloatList("figure");
1511 } else if (cmdName == "listoftables") {
1512 inset = new InsetFloatList("table");
1513 } else if (cmdName == "printindex") {
1514 inset = new InsetPrintIndex(inscmd);
1515 } else if (cmdName == "lyxparent") {
1516 inset = new InsetParent(inscmd, *this);
1519 bool alreadyread = false;
1520 if (tmptok == "Quotes") {
1521 inset = new InsetQuotes;
1522 } else if (tmptok == "External") {
1523 inset = new InsetExternal;
1524 } else if (tmptok == "FormulaMacro") {
1525 inset = new InsetFormulaMacro;
1526 } else if (tmptok == "Formula") {
1527 inset = new InsetFormula;
1528 } else if (tmptok == "Figure") { // Backward compatibility
1529 // inset = new InsetFig(100, 100, *this);
1530 inset = new InsetGraphics;
1531 } else if (tmptok == "Graphics") {
1532 inset = new InsetGraphics;
1533 } else if (tmptok == "Info") {// backwards compatibility
1534 inset = new InsetNote(this,
1535 lex.getLongString("\\end_inset"),
1538 } else if (tmptok == "Note") {
1539 inset = new InsetNote(params);
1540 } else if (tmptok == "Include") {
1541 InsetCommandParams p("Include");
1542 inset = new InsetInclude(p, *this);
1543 } else if (tmptok == "ERT") {
1544 inset = new InsetERT(params);
1545 } else if (tmptok == "Tabular") {
1546 inset = new InsetTabular(*this);
1547 } else if (tmptok == "Text") {
1548 inset = new InsetText(params);
1549 } else if (tmptok == "Foot") {
1550 inset = new InsetFoot(params);
1551 } else if (tmptok == "Marginal") {
1552 inset = new InsetMarginal(params);
1553 } else if (tmptok == "Minipage") {
1554 inset = new InsetMinipage(params);
1555 } else if (tmptok == "Float") {
1557 string tmptok = lex.getString();
1558 inset = new InsetFloat(params, tmptok);
1560 } else if (tmptok == "List") {
1561 inset = new InsetList;
1562 } else if (tmptok == "Theorem") {
1563 inset = new InsetList;
1565 } else if (tmptok == "Caption") {
1566 inset = new InsetCaption(params);
1567 } else if (tmptok == "FloatList") {
1568 inset = new InsetFloatList;
1571 if (inset && !alreadyread) inset->read(this, lex);
1575 par->insertInset(pos, inset, font);
1581 bool Buffer::readFile(LyXLex & lex, Paragraph * par)
1585 string const token(lex.getString());
1586 if (token == "\\lyxformat") { // the first token _must_ be...
1588 string tmp_format = lex.getString();
1589 //lyxerr << "LyX Format: `" << tmp_format << "'" << endl;
1590 // if present remove ".," from string.
1591 string::size_type dot = tmp_format.find_first_of(".,");
1592 //lyxerr << " dot found at " << dot << endl;
1593 if (dot != string::npos)
1594 tmp_format.erase(dot, 1);
1595 file_format = strToInt(tmp_format);
1596 if (file_format == LYX_FORMAT) {
1598 } else if (file_format > LYX_FORMAT) {
1600 Alert::alert(_("Warning!"),
1601 _("LyX file format is newer that what"),
1602 _("is supported in this LyX version. Expect some problems."));
1604 } else if (file_format < LYX_FORMAT) {
1606 if (file_format < 200) {
1607 Alert::alert(_("ERROR!"),
1608 _("Old LyX file format found. "
1609 "Use LyX 0.10.x to read this!"));
1613 bool the_end = readLyXformat2(lex, par);
1614 params.setPaperStuff();
1615 // the_end was added in 213
1616 if (file_format < 213)
1620 Alert::alert(_("Warning!"),
1621 _("Reading of document is not complete"),
1622 _("Maybe the document is truncated"));
1625 } else { // "\\lyxformat" not found
1626 Alert::alert(_("ERROR!"), _("Not a LyX file!"));
1629 Alert::alert(_("ERROR!"), _("Unable to read file!"));
1634 // Should probably be moved to somewhere else: BufferView? LyXView?
1635 bool Buffer::save() const
1637 // We don't need autosaves in the immediate future. (Asger)
1638 resetAutosaveTimers();
1642 if (lyxrc.make_backup) {
1643 s = fileName() + '~';
1644 if (!lyxrc.backupdir_path.empty())
1645 s = AddName(lyxrc.backupdir_path,
1646 subst(os::slashify_path(s),'/','!'));
1648 // Rename is the wrong way of making a backup,
1649 // this is the correct way.
1650 /* truss cp fil fil2:
1651 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
1652 stat("LyXVC.lyx", 0xEFFFF688) = 0
1653 open("LyXVC.lyx", O_RDONLY) = 3
1654 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
1655 fstat(4, 0xEFFFF508) = 0
1656 fstat(3, 0xEFFFF508) = 0
1657 read(3, " # T h i s f i l e w".., 8192) = 5579
1658 write(4, " # T h i s f i l e w".., 5579) = 5579
1659 read(3, 0xEFFFD4A0, 8192) = 0
1662 chmod("LyXVC3.lyx", 0100644) = 0
1663 lseek(0, 0, SEEK_CUR) = 46440
1667 // Should probably have some more error checking here.
1668 // Should be cleaned up in 0.13, at least a bit.
1669 // Doing it this way, also makes the inodes stay the same.
1670 // This is still not a very good solution, in particular we
1671 // might loose the owner of the backup.
1672 FileInfo finfo(fileName());
1673 if (finfo.exist()) {
1674 mode_t fmode = finfo.getMode();
1675 struct utimbuf times = {
1676 finfo.getAccessTime(),
1677 finfo.getModificationTime() };
1679 ifstream ifs(fileName().c_str());
1680 ofstream ofs(s.c_str(), ios::out|ios::trunc);
1685 ::chmod(s.c_str(), fmode);
1687 if (::utime(s.c_str(), ×)) {
1688 lyxerr << "utime error." << endl;
1691 lyxerr << "LyX was not able to make "
1692 "backup copy. Beware." << endl;
1697 if (writeFile(fileName(), false)) {
1699 removeAutosaveFile(fileName());
1701 // Saving failed, so backup is not backup
1702 if (lyxrc.make_backup) {
1703 lyx::rename(s, fileName());
1711 // Returns false if unsuccesful
1712 bool Buffer::writeFile(string const & fname, bool flag) const
1714 // if flag is false writeFile will not create any GUI
1715 // warnings, only cerr.
1716 // Needed for autosave in background or panic save (Matthias 120496)
1718 if (read_only && (fname == fileName())) {
1719 // Here we should come with a question if we should
1720 // perform the write anyway.
1722 lyxerr << _("Error! Document is read-only: ")
1725 Alert::alert(_("Error! Document is read-only: "),
1730 FileInfo finfo(fname);
1731 if (finfo.exist() && !finfo.writable()) {
1732 // Here we should come with a question if we should
1733 // try to do the save anyway. (i.e. do a chmod first)
1735 lyxerr << _("Error! Cannot write file: ")
1738 Alert::err_alert(_("Error! Cannot write file: "),
1743 ofstream ofs(fname.c_str());
1746 lyxerr << _("Error! Cannot open file: ")
1749 Alert::err_alert(_("Error! Cannot open file: "),
1755 // Use the standard "C" locale for file output.
1756 ofs.imbue(std::locale::classic());
1759 // The top of the file should not be written by params.
1761 // write out a comment in the top of the file
1762 ofs << '#' << lyx_docversion
1763 << " created this file. For more info see http://www.lyx.org/\n"
1764 << "\\lyxformat " << LYX_FORMAT << "\n";
1766 // now write out the buffer paramters.
1767 params.writeFile(ofs);
1769 Paragraph::depth_type depth = 0;
1771 // this will write out all the paragraphs
1772 // using recursive descent.
1773 paragraph->writeFile(this, ofs, params, depth);
1775 // Write marker that shows file is complete
1776 ofs << "\n\\the_end" << endl;
1780 // how to check if close went ok?
1781 // Following is an attempt... (BE 20001011)
1783 // good() returns false if any error occured, including some
1784 // formatting error.
1785 // bad() returns true if something bad happened in the buffer,
1786 // which should include file system full errors.
1793 lyxerr << "Buffer::writeFile: BAD ERROR!" << endl;
1795 lyxerr << "Buffer::writeFile: NOT SO BAD ERROR!"
1807 pair<int, string> const addDepth(int depth, int ldepth)
1811 d += (ldepth - depth) * 2;
1812 return make_pair(d, string(d, ' '));
1818 string const Buffer::asciiParagraph(Paragraph const * par,
1819 unsigned int linelen,
1820 bool noparbreak) const
1822 ostringstream buffer;
1823 Paragraph::depth_type depth = 0;
1825 Paragraph::depth_type ltype_depth = 0;
1826 bool ref_printed = false;
1827 // if (!par->previous()) {
1829 // begins or ends a deeper area ?
1830 if (depth != par->params().depth()) {
1831 if (par->params().depth() > depth) {
1832 while (par->params().depth() > depth) {
1836 while (par->params().depth() < depth) {
1842 depth = par->params().depth();
1845 // First write the layout
1846 string const & tmp = par->layout();
1847 if (compare_no_case(tmp, "itemize") == 0) {
1849 ltype_depth = depth + 1;
1850 } else if (compare_no_case(tmp, "enumerate") == 0) {
1852 ltype_depth = depth + 1;
1853 } else if (contains(lowercase(tmp), "ection")) {
1855 ltype_depth = depth + 1;
1856 } else if (contains(lowercase(tmp), "aragraph")) {
1858 ltype_depth = depth + 1;
1859 } else if (compare_no_case(tmp, "description") == 0) {
1861 ltype_depth = depth + 1;
1862 } else if (compare_no_case(tmp, "abstract") == 0) {
1865 } else if (compare_no_case(tmp, "bibliography") == 0) {
1873 /* maybe some vertical spaces */
1875 /* the labelwidthstring used in lists */
1879 /* some pagebreaks? */
1883 /* what about the alignment */
1885 // lyxerr << "Should this ever happen?" << endl;
1888 // linelen <= 0 is special and means we don't have pargraph breaks
1890 string::size_type currlinelen = 0;
1896 buffer << string(depth * 2, ' ');
1897 currlinelen += depth * 2;
1900 // we should probably change to the paragraph language in the
1901 // gettext here (if possible) so that strings are outputted in
1902 // the correct language! (20012712 Jug)
1906 case 4: // (Sub)Paragraph
1907 case 5: // Description
1911 buffer << _("Abstract") << "\n\n";
1914 string const abst = _("Abstract: ");
1916 currlinelen += abst.length();
1919 case 7: // Bibliography
1922 buffer << _("References") << "\n\n";
1925 string const refs = _("References: ");
1927 currlinelen += refs.length();
1935 string const parlab = par->params().labelString();
1936 buffer << parlab << " ";
1937 currlinelen += parlab.length() + 1;
1945 pair<int, string> p = addDepth(depth, ltype_depth);
1947 currlinelen += p.first;
1950 // this is to change the linebreak to do it by word a bit more
1951 // intelligent hopefully! (only in the case where we have a
1952 // max linelenght!) (Jug)
1956 for (pos_type i = 0; i < par->size(); ++i) {
1957 char c = par->getUChar(params, i);
1959 case Paragraph::META_INSET:
1961 Inset const * inset = par->getInset(i);
1965 currlinelen += word.length();
1968 if (inset->ascii(this, buffer, linelen)) {
1969 // to be sure it breaks paragraph
1970 currlinelen += linelen;
1976 case Paragraph::META_NEWLINE:
1978 buffer << word << "\n";
1981 pair<int, string> p = addDepth(depth,
1984 currlinelen = p.first;
1988 case Paragraph::META_HFILL:
1989 buffer << word << "\t";
1990 currlinelen += word.length() + 1;
1997 currlinelen + word.length() > linelen - 10) {
1999 pair<int, string> p =
2000 addDepth(depth, ltype_depth);
2002 currlinelen = p.first;
2005 buffer << word << ' ';
2006 currlinelen += word.length() + 1;
2013 lyxerr[Debug::INFO] <<
2014 "writeAsciiFile: NULL char in structure." << endl;
2016 if ((linelen > 0) &&
2017 (currlinelen + word.length()) > linelen)
2021 pair<int, string> p =
2022 addDepth(depth, ltype_depth);
2024 currlinelen = p.first;
2031 return buffer.str().c_str();
2035 void Buffer::writeFileAscii(string const & fname, int linelen)
2037 ofstream ofs(fname.c_str());
2039 Alert::err_alert(_("Error: Cannot write file:"), fname);
2042 writeFileAscii(ofs, linelen);
2046 void Buffer::writeFileAscii(ostream & ofs, int linelen)
2048 Paragraph * par = paragraph;
2050 ofs << asciiParagraph(par, linelen, par->previous() == 0);
2060 void Buffer::makeLaTeXFile(string const & fname,
2061 string const & original_path,
2062 bool nice, bool only_body)
2064 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
2066 ofstream ofs(fname.c_str());
2068 Alert::err_alert(_("Error: Cannot open file: "), fname);
2072 niceFile = nice; // this will be used by Insetincludes.
2074 tex_code_break_column = lyxrc.ascii_linelen;
2076 // validate the buffer.
2077 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
2078 LaTeXFeatures features(params);
2080 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
2083 // The starting paragraph of the coming rows is the
2084 // first paragraph of the document. (Asger)
2085 texrow.start(paragraph, 0);
2087 if (!only_body && nice) {
2088 ofs << "%% " << lyx_docversion << " created this file. "
2089 "For more info, see http://www.lyx.org/.\n"
2090 "%% Do not edit unless you really know what "
2095 lyxerr[Debug::INFO] << "lyx header finished" << endl;
2096 // There are a few differences between nice LaTeX and usual files:
2097 // usual is \batchmode and has a
2098 // special input@path to allow the including of figures
2099 // with either \input or \includegraphics (what figinsets do).
2100 // batchmode is not set if there is a tex_code_break_column.
2101 // In this case somebody is interested in the generated LaTeX,
2102 // so this is OK. input@path is set when the actual parameter
2103 // original_path is set. This is done for usual tex-file, but not
2104 // for nice-latex-file. (Matthias 250696)
2107 // code for usual, NOT nice-latex-file
2108 ofs << "\\batchmode\n"; // changed
2109 // from \nonstopmode
2112 if (!original_path.empty()) {
2113 string inputpath = os::external_path(original_path);
2114 subst(inputpath, "~", "\\string~");
2115 ofs << "\\makeatletter\n"
2116 << "\\def\\input@path{{"
2117 << inputpath << "/}}\n"
2118 << "\\makeatother\n";
2124 ofs << "\\documentclass";
2126 LyXTextClass const & tclass = textclasslist[params.textclass];
2128 ostringstream options; // the document class options.
2130 if (tokenPos(tclass.opt_fontsize(),
2131 '|', params.fontsize) >= 0) {
2132 // only write if existing in list (and not default)
2133 options << params.fontsize << "pt,";
2137 if (!params.use_geometry &&
2138 (params.paperpackage == BufferParams::PACKAGE_NONE)) {
2139 switch (params.papersize) {
2140 case BufferParams::PAPER_A4PAPER:
2141 options << "a4paper,";
2143 case BufferParams::PAPER_USLETTER:
2144 options << "letterpaper,";
2146 case BufferParams::PAPER_A5PAPER:
2147 options << "a5paper,";
2149 case BufferParams::PAPER_B5PAPER:
2150 options << "b5paper,";
2152 case BufferParams::PAPER_EXECUTIVEPAPER:
2153 options << "executivepaper,";
2155 case BufferParams::PAPER_LEGALPAPER:
2156 options << "legalpaper,";
2162 if (params.sides != tclass.sides()) {
2163 switch (params.sides) {
2164 case LyXTextClass::OneSide:
2165 options << "oneside,";
2167 case LyXTextClass::TwoSides:
2168 options << "twoside,";
2174 if (params.columns != tclass.columns()) {
2175 if (params.columns == 2)
2176 options << "twocolumn,";
2178 options << "onecolumn,";
2181 if (!params.use_geometry
2182 && params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
2183 options << "landscape,";
2185 // language should be a parameter to \documentclass
2187 ostringstream language_options;
2188 if (params.language->babel() == "hebrew"
2189 && default_language->babel() != "hebrew")
2190 // This seems necessary
2191 features.useLanguage(default_language);
2193 if (lyxrc.language_use_babel ||
2194 params.language->lang() != lyxrc.default_language ||
2195 features.hasLanguages()) {
2197 language_options << features.getLanguages();
2198 language_options << params.language->babel();
2199 if (lyxrc.language_global_options)
2200 options << language_options.str() << ',';
2203 // the user-defined options
2204 if (!params.options.empty()) {
2205 options << params.options << ',';
2208 string strOptions(options.str().c_str());
2209 if (!strOptions.empty()) {
2210 strOptions = strip(strOptions, ',');
2211 ofs << '[' << strOptions << ']';
2214 ofs << '{' << tclass.latexname() << "}\n";
2216 // end of \documentclass defs
2218 // font selection must be done before loading fontenc.sty
2219 // The ae package is not needed when using OT1 font encoding.
2220 if (params.fonts != "default" &&
2221 (params.fonts != "ae" || lyxrc.fontenc != "default")) {
2222 ofs << "\\usepackage{" << params.fonts << "}\n";
2224 if (params.fonts == "ae") {
2225 ofs << "\\usepackage{aecompl}\n";
2229 // this one is not per buffer
2230 if (lyxrc.fontenc != "default") {
2231 ofs << "\\usepackage[" << lyxrc.fontenc
2236 if (params.inputenc == "auto") {
2237 string const doc_encoding =
2238 params.language->encoding()->LatexName();
2240 // Create a list with all the input encodings used
2242 set<string> encodings = features.getEncodingSet(doc_encoding);
2244 ofs << "\\usepackage[";
2245 std::copy(encodings.begin(), encodings.end(),
2246 std::ostream_iterator<string>(ofs, ","));
2247 ofs << doc_encoding << "]{inputenc}\n";
2249 } else if (params.inputenc != "default") {
2250 ofs << "\\usepackage[" << params.inputenc
2255 // At the very beginning the text parameters.
2256 if (params.paperpackage != BufferParams::PACKAGE_NONE) {
2257 switch (params.paperpackage) {
2258 case BufferParams::PACKAGE_A4:
2259 ofs << "\\usepackage{a4}\n";
2262 case BufferParams::PACKAGE_A4WIDE:
2263 ofs << "\\usepackage{a4wide}\n";
2266 case BufferParams::PACKAGE_WIDEMARGINSA4:
2267 ofs << "\\usepackage[widemargins]{a4}\n";
2272 if (params.use_geometry) {
2273 ofs << "\\usepackage{geometry}\n";
2275 ofs << "\\geometry{verbose";
2276 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
2277 ofs << ",landscape";
2278 switch (params.papersize2) {
2279 case BufferParams::VM_PAPER_CUSTOM:
2280 if (!params.paperwidth.empty())
2281 ofs << ",paperwidth="
2282 << params.paperwidth;
2283 if (!params.paperheight.empty())
2284 ofs << ",paperheight="
2285 << params.paperheight;
2287 case BufferParams::VM_PAPER_USLETTER:
2288 ofs << ",letterpaper";
2290 case BufferParams::VM_PAPER_USLEGAL:
2291 ofs << ",legalpaper";
2293 case BufferParams::VM_PAPER_USEXECUTIVE:
2294 ofs << ",executivepaper";
2296 case BufferParams::VM_PAPER_A3:
2299 case BufferParams::VM_PAPER_A4:
2302 case BufferParams::VM_PAPER_A5:
2305 case BufferParams::VM_PAPER_B3:
2308 case BufferParams::VM_PAPER_B4:
2311 case BufferParams::VM_PAPER_B5:
2315 // default papersize ie BufferParams::VM_PAPER_DEFAULT
2316 switch (lyxrc.default_papersize) {
2317 case BufferParams::PAPER_DEFAULT: // keep compiler happy
2318 case BufferParams::PAPER_USLETTER:
2319 ofs << ",letterpaper";
2321 case BufferParams::PAPER_LEGALPAPER:
2322 ofs << ",legalpaper";
2324 case BufferParams::PAPER_EXECUTIVEPAPER:
2325 ofs << ",executivepaper";
2327 case BufferParams::PAPER_A3PAPER:
2330 case BufferParams::PAPER_A4PAPER:
2333 case BufferParams::PAPER_A5PAPER:
2336 case BufferParams::PAPER_B5PAPER:
2341 if (!params.topmargin.empty())
2342 ofs << ",tmargin=" << params.topmargin;
2343 if (!params.bottommargin.empty())
2344 ofs << ",bmargin=" << params.bottommargin;
2345 if (!params.leftmargin.empty())
2346 ofs << ",lmargin=" << params.leftmargin;
2347 if (!params.rightmargin.empty())
2348 ofs << ",rmargin=" << params.rightmargin;
2349 if (!params.headheight.empty())
2350 ofs << ",headheight=" << params.headheight;
2351 if (!params.headsep.empty())
2352 ofs << ",headsep=" << params.headsep;
2353 if (!params.footskip.empty())
2354 ofs << ",footskip=" << params.footskip;
2359 if (tokenPos(tclass.opt_pagestyle(),
2360 '|', params.pagestyle) >= 0) {
2361 if (params.pagestyle == "fancy") {
2362 ofs << "\\usepackage{fancyhdr}\n";
2365 ofs << "\\pagestyle{" << params.pagestyle << "}\n";
2369 if (params.secnumdepth != tclass.secnumdepth()) {
2370 ofs << "\\setcounter{secnumdepth}{"
2371 << params.secnumdepth
2375 if (params.tocdepth != tclass.tocdepth()) {
2376 ofs << "\\setcounter{tocdepth}{"
2382 if (params.paragraph_separation) {
2383 switch (params.defskip.kind()) {
2384 case VSpace::SMALLSKIP:
2385 ofs << "\\setlength\\parskip{\\smallskipamount}\n";
2387 case VSpace::MEDSKIP:
2388 ofs << "\\setlength\\parskip{\\medskipamount}\n";
2390 case VSpace::BIGSKIP:
2391 ofs << "\\setlength\\parskip{\\bigskipamount}\n";
2393 case VSpace::LENGTH:
2394 ofs << "\\setlength\\parskip{"
2395 << params.defskip.length().asLatexString()
2398 default: // should never happen // Then delete it.
2399 ofs << "\\setlength\\parskip{\\medskipamount}\n";
2404 ofs << "\\setlength\\parindent{0pt}\n";
2408 // Now insert the LyX specific LaTeX commands...
2410 // The optional packages;
2411 string preamble(features.getPackages());
2413 // this might be useful...
2414 preamble += "\n\\makeatletter\n";
2416 // Some macros LyX will need
2417 string tmppreamble(features.getMacros());
2419 if (!tmppreamble.empty()) {
2420 preamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2421 "LyX specific LaTeX commands.\n"
2422 + tmppreamble + '\n';
2425 // the text class specific preamble
2426 tmppreamble = features.getTClassPreamble();
2427 if (!tmppreamble.empty()) {
2428 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2429 "Textclass specific LaTeX commands.\n"
2430 + tmppreamble + '\n';
2433 /* the user-defined preamble */
2434 if (!params.preamble.empty()) {
2435 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2436 "User specified LaTeX commands.\n"
2437 + params.preamble + '\n';
2440 preamble += "\\makeatother\n";
2442 // Itemize bullet settings need to be last in case the user
2443 // defines their own bullets that use a package included
2444 // in the user-defined preamble -- ARRae
2445 // Actually it has to be done much later than that
2446 // since some packages like frenchb make modifications
2447 // at \begin{document} time -- JMarc
2449 for (int i = 0; i < 4; ++i) {
2450 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
2451 if (bullets_def.empty())
2452 bullets_def="\\AtBeginDocument{\n";
2453 bullets_def += " \\renewcommand{\\labelitemi";
2455 // `i' is one less than the item to modify
2462 bullets_def += "ii";
2468 bullets_def += "}{" +
2469 params.user_defined_bullets[i].getText()
2474 if (!bullets_def.empty())
2475 preamble += bullets_def + "}\n\n";
2478 int(lyx::count(preamble.begin(), preamble.end(), '\n'));
2479 for (int j = 0; j != nlines; ++j) {
2485 // We try to load babel late, in case it interferes
2486 // with other packages.
2488 string tmp = lyxrc.language_package;
2489 if (!lyxrc.language_global_options
2490 && tmp == "\\usepackage{babel}")
2491 tmp = string("\\usepackage[") +
2492 language_options.str().c_str() +
2499 ofs << "\\begin{document}\n";
2502 lyxerr[Debug::INFO] << "preamble finished, now the body." << endl;
2504 if (!lyxrc.language_auto_begin) {
2505 ofs << subst(lyxrc.language_command_begin, "$$lang",
2506 params.language->babel())
2511 latexParagraphs(ofs, paragraph, 0, texrow);
2513 // add this just in case after all the paragraphs
2517 if (!lyxrc.language_auto_end) {
2518 ofs << subst(lyxrc.language_command_end, "$$lang",
2519 params.language->babel())
2525 ofs << "\\end{document}\n";
2528 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
2530 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
2534 // Just to be sure. (Asger)
2537 // tex_code_break_column's value is used to decide
2538 // if we are in batchmode or not (within mathed_write()
2539 // in math_write.C) so we must set it to a non-zero
2540 // value when we leave otherwise we save incorrect .lyx files.
2541 tex_code_break_column = lyxrc.ascii_linelen;
2545 lyxerr << "File was not closed properly." << endl;
2548 lyxerr[Debug::INFO] << "Finished making latex file." << endl;
2549 lyxerr[Debug::INFO] << "Row count was " << texrow.rows()-1 << "." << endl;
2551 // we want this to be true outside previews (for insetexternal)
2557 // LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
2559 void Buffer::latexParagraphs(ostream & ofs, Paragraph * par,
2560 Paragraph * endpar, TexRow & texrow) const
2562 bool was_title = false;
2563 bool already_title = false;
2566 while (par != endpar) {
2567 Inset * in = par->inInset();
2568 // well we have to check if we are in an inset with unlimited
2569 // lenght (all in one row) if that is true then we don't allow
2570 // any special options in the paragraph and also we don't allow
2571 // any environment other then "Standard" to be valid!
2572 if ((in == 0) || !in->forceDefaultParagraphs(in)) {
2573 LyXLayout const & layout =
2574 textclasslist[params.textclass][par->layout()];
2576 if (layout.intitle) {
2577 if (already_title) {
2578 lyxerr <<"Error in latexParagraphs: You"
2579 " should not mix title layouts"
2580 " with normal ones." << endl;
2583 } else if (was_title && !already_title) {
2584 ofs << "\\maketitle\n";
2586 already_title = true;
2590 if (layout.isEnvironment()) {
2591 par = par->TeXEnvironment(this, params, ofs, texrow);
2593 par = par->TeXOnePar(this, params, ofs, texrow, false);
2596 par = par->TeXOnePar(this, params, ofs, texrow, false);
2599 // It might be that we only have a title in this document
2600 if (was_title && !already_title) {
2601 ofs << "\\maketitle\n";
2607 bool Buffer::isLatex() const
2609 return textclasslist[params.textclass].outputType() == LATEX;
2613 bool Buffer::isLinuxDoc() const
2615 return textclasslist[params.textclass].outputType() == LINUXDOC;
2619 bool Buffer::isLiterate() const
2621 return textclasslist[params.textclass].outputType() == LITERATE;
2625 bool Buffer::isDocBook() const
2627 return textclasslist[params.textclass].outputType() == DOCBOOK;
2631 bool Buffer::isSGML() const
2633 LyXTextClass const & tclass = textclasslist[params.textclass];
2635 return tclass.outputType() == LINUXDOC ||
2636 tclass.outputType() == DOCBOOK;
2640 void Buffer::sgmlOpenTag(ostream & os, Paragraph::depth_type,
2641 string const & latexname) const
2643 if (!latexname.empty() && latexname != "!-- --")
2644 //os << "<!-- " << depth << " -->" << "<" << latexname << ">";
2645 os << "<" << latexname << ">";
2649 void Buffer::sgmlCloseTag(ostream & os, Paragraph::depth_type,
2650 string const & latexname) const
2652 if (!latexname.empty() && latexname != "!-- --")
2653 //os << "<!-- " << depth << " -->" << "</" << latexname << ">\n";
2654 os << "</" << latexname << ">";
2658 void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
2660 ofstream ofs(fname.c_str());
2663 Alert::alert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2667 niceFile = nice; // this will be used by included files.
2669 LaTeXFeatures features(params);
2675 LyXTextClass const & tclass = textclasslist[params.textclass];
2677 string top_element = tclass.latexname();
2680 ofs << "<!doctype linuxdoc system";
2682 string preamble = params.preamble;
2683 const string name = nice ? ChangeExtension(filename_, ".sgml")
2685 preamble += features.getIncludedFiles(name);
2686 preamble += features.getLyXSGMLEntities();
2688 if (!preamble.empty()) {
2689 ofs << " [ " << preamble << " ]";
2693 if (params.options.empty())
2694 sgmlOpenTag(ofs, 0, top_element);
2696 string top = top_element;
2698 top += params.options;
2699 sgmlOpenTag(ofs, 0, top);
2703 ofs << "<!-- " << lyx_docversion
2704 << " created this file. For more info see http://www.lyx.org/"
2707 Paragraph::depth_type depth = 0; // paragraph depth
2708 Paragraph * par = paragraph;
2710 vector<string> environment_stack(5);
2713 LyXLayout const & style = tclass[par->layout()];
2715 // treat <toc> as a special case for compatibility with old code
2716 if (par->isInset(0)) {
2717 Inset * inset = par->getInset(0);
2718 Inset::Code lyx_code = inset->lyxCode();
2719 if (lyx_code == Inset::TOC_CODE) {
2720 string const temp = "toc";
2721 sgmlOpenTag(ofs, depth, temp);
2728 // environment tag closing
2729 for (; depth > par->params().depth(); --depth) {
2730 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2731 environment_stack[depth].erase();
2734 // write opening SGML tags
2735 switch (style.latextype) {
2736 case LATEX_PARAGRAPH:
2737 if (depth == par->params().depth()
2738 && !environment_stack[depth].empty()) {
2739 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2740 environment_stack[depth].erase();
2746 sgmlOpenTag(ofs, depth, style.latexname());
2752 _("Error : Wrong depth for"
2753 " LatexType Command.\n"));
2755 if (!environment_stack[depth].empty()) {
2756 sgmlCloseTag(ofs, depth,
2757 environment_stack[depth]);
2761 environment_stack[depth].erase();
2762 sgmlOpenTag(ofs, depth, style.latexname());
2765 case LATEX_ENVIRONMENT:
2766 case LATEX_ITEM_ENVIRONMENT:
2767 if (depth == par->params().depth()
2768 && environment_stack[depth] != style.latexname()) {
2769 sgmlCloseTag(ofs, depth,
2770 environment_stack[depth]);
2771 environment_stack[depth].erase();
2773 if (depth < par->params().depth()) {
2774 depth = par->params().depth();
2775 environment_stack[depth].erase();
2777 if (environment_stack[depth] != style.latexname()) {
2779 sgmlOpenTag(ofs, depth, "p");
2781 sgmlOpenTag(ofs, depth, style.latexname());
2783 if (environment_stack.size() == depth + 1)
2784 environment_stack.push_back("!-- --");
2785 environment_stack[depth] = style.latexname();
2788 if (style.latexparam() == "CDATA")
2791 if (style.latextype == LATEX_ENVIRONMENT) break;
2793 if (style.labeltype == LABEL_MANUAL)
2798 sgmlOpenTag(ofs, depth + 1, item_name);
2801 sgmlOpenTag(ofs, depth, style.latexname());
2805 simpleLinuxDocOnePar(ofs, par, depth);
2810 // write closing SGML tags
2811 switch (style.latextype) {
2814 case LATEX_ENVIRONMENT:
2815 case LATEX_ITEM_ENVIRONMENT:
2816 if (style.latexparam() == "CDATA")
2820 sgmlCloseTag(ofs, depth, style.latexname());
2826 for (int i=depth; i >= 0; --i)
2827 sgmlCloseTag(ofs, depth, environment_stack[i]);
2831 sgmlCloseTag(ofs, 0, top_element);
2835 // How to check for successful close
2837 // we want this to be true outside previews (for insetexternal)
2842 // checks, if newcol chars should be put into this line
2843 // writes newline, if necessary.
2846 void sgmlLineBreak(ostream & os, string::size_type & colcount,
2847 string::size_type newcol)
2850 if (colcount > lyxrc.ascii_linelen) {
2852 colcount = newcol; // assume write after this call
2867 string tag_name(PAR_TAG const & pt) {
2869 case NONE: return "!-- --";
2870 case TT: return "tt";
2871 case SF: return "sf";
2872 case BF: return "bf";
2873 case IT: return "it";
2874 case SL: return "sl";
2875 case EM: return "em";
2882 void operator|=(PAR_TAG & p1, PAR_TAG const & p2)
2884 p1 = static_cast<PAR_TAG>(p1 | p2);
2889 void reset(PAR_TAG & p1, PAR_TAG const & p2)
2891 p1 = static_cast<PAR_TAG>(p1 & ~p2);
2897 // Handle internal paragraph parsing -- layout already processed.
2898 void Buffer::simpleLinuxDocOnePar(ostream & os,
2900 Paragraph::depth_type /*depth*/)
2902 LyXLayout const & style =
2903 textclasslist[params.textclass][par->layout()];
2904 string::size_type char_line_count = 5; // Heuristic choice ;-)
2906 // gets paragraph main font
2909 if (style.labeltype == LABEL_MANUAL) {
2910 font_old = style.labelfont;
2913 font_old = style.font;
2917 LyXFont::FONT_FAMILY family_type = LyXFont::ROMAN_FAMILY;
2918 LyXFont::FONT_SERIES series_type = LyXFont::MEDIUM_SERIES;
2919 LyXFont::FONT_SHAPE shape_type = LyXFont::UP_SHAPE;
2922 stack<PAR_TAG> tag_state;
2923 // parsing main loop
2924 for (pos_type i = 0; i < par->size(); ++i) {
2926 PAR_TAG tag_close = NONE;
2927 list < PAR_TAG > tag_open;
2929 LyXFont const font = par->getFont(params, i);
2931 if (font_old.family() != font.family()) {
2932 switch (family_type) {
2933 case LyXFont::SANS_FAMILY:
2936 case LyXFont::TYPEWRITER_FAMILY:
2943 family_type = font.family();
2945 switch (family_type) {
2946 case LyXFont::SANS_FAMILY:
2947 tag_open.push_back(SF);
2949 case LyXFont::TYPEWRITER_FAMILY:
2950 tag_open.push_back(TT);
2957 if (font_old.series() != font.series()) {
2958 switch (series_type) {
2959 case LyXFont::BOLD_SERIES:
2966 series_type = font.series();
2968 switch (series_type) {
2969 case LyXFont::BOLD_SERIES:
2970 tag_open.push_back(BF);
2978 if (font_old.shape() != font.shape()) {
2979 switch (shape_type) {
2980 case LyXFont::ITALIC_SHAPE:
2983 case LyXFont::SLANTED_SHAPE:
2990 shape_type = font.shape();
2992 switch (shape_type) {
2993 case LyXFont::ITALIC_SHAPE:
2994 tag_open.push_back(IT);
2996 case LyXFont::SLANTED_SHAPE:
2997 tag_open.push_back(SL);
3004 if (font_old.emph() != font.emph()) {
3005 if (font.emph() == LyXFont::ON) {
3006 tag_open.push_back(EM);
3015 list < PAR_TAG > temp;
3016 while (!tag_state.empty() && tag_close) {
3017 PAR_TAG k = tag_state.top();
3019 os << "</" << tag_name(k) << ">";
3026 for(list< PAR_TAG >::const_iterator j = temp.begin();
3027 j != temp.end(); ++j) {
3029 os << "<" << tag_name(*j) << ">";
3032 for(list< PAR_TAG >::const_iterator j = tag_open.begin();
3033 j != tag_open.end(); ++j) {
3035 os << "<" << tag_name(*j) << ">";
3038 char c = par->getChar(i);
3040 if (c == Paragraph::META_INSET) {
3041 Inset * inset = par->getInset(i);
3042 inset->linuxdoc(this, os);
3047 if (style.latexparam() == "CDATA") {
3048 // "TeX"-Mode on == > SGML-Mode on.
3054 if (par->sgmlConvertChar(c, sgml_string)
3055 && !style.free_spacing && !par->isFreeSpacing())
3057 // in freespacing mode, spaces are
3058 // non-breaking characters
3059 if (desc_on) {// if char is ' ' then...
3062 sgmlLineBreak(os, char_line_count, 6);
3066 sgmlLineBreak(os, char_line_count, 1);
3071 char_line_count += sgml_string.length();
3077 while (!tag_state.empty()) {
3078 os << "</" << tag_name(tag_state.top()) << ">";
3082 // resets description flag correctly
3084 // <tag> not closed...
3085 sgmlLineBreak(os, char_line_count, 6);
3091 // Print an error message.
3092 void Buffer::sgmlError(Paragraph * /*par*/, int /*pos*/,
3093 string const & /*message*/) const
3095 #warning This is wrong we cannot insert an inset like this!!!
3096 // I guess this was Jose' so I explain you more or less why this
3097 // is wrong. This way you insert something in the paragraph and
3098 // don't tell it to LyXText (row rebreaking and undo handling!!!)
3099 // I deactivate this code, have a look at BufferView::insertErrors
3100 // how you should do this correctly! (Jug 20020315)
3102 // insert an error marker in text
3103 InsetError * new_inset = new InsetError(message);
3104 par->insertInset(pos, new_inset, LyXFont(LyXFont::ALL_INHERIT,
3110 void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
3112 ofstream ofs(fname.c_str());
3114 Alert::alert(_("LYX_ERROR:"), _("Cannot write file"), fname);
3118 Paragraph * par = paragraph;
3120 niceFile = nice; // this will be used by Insetincludes.
3122 LaTeXFeatures features(params);
3127 LyXTextClass const & tclass = textclasslist[params.textclass];
3128 string top_element = tclass.latexname();
3131 ofs << "<!DOCTYPE " << top_element
3132 << " PUBLIC \"-//OASIS//DTD DocBook V4.1//EN\"";
3134 string preamble = params.preamble;
3135 const string name = nice ? ChangeExtension(filename_, ".sgml")
3137 preamble += features.getIncludedFiles(name);
3138 preamble += features.getLyXSGMLEntities();
3140 if (!preamble.empty()) {
3141 ofs << "\n [ " << preamble << " ]";
3146 string top = top_element;
3148 top += params.language->code();
3151 if (!params.options.empty()) {
3153 top += params.options;
3155 sgmlOpenTag(ofs, 0, top);
3157 ofs << "<!-- DocBook file was created by " << lyx_docversion
3158 << "\n See http://www.lyx.org/ for more information -->\n";
3160 vector<string> environment_stack(10);
3161 vector<string> environment_inner(10);
3162 vector<string> command_stack(10);
3164 bool command_flag = false;
3165 Paragraph::depth_type command_depth = 0;
3166 Paragraph::depth_type command_base = 0;
3167 Paragraph::depth_type cmd_depth = 0;
3168 Paragraph::depth_type depth = 0; // paragraph depth
3171 string command_name;
3177 int desc_on = 0; // description mode
3179 LyXLayout const & style = tclass[par->layout()];
3181 // environment tag closing
3182 for (; depth > par->params().depth(); --depth) {
3183 if (environment_inner[depth] != "!-- --") {
3184 item_name = "listitem";
3185 sgmlCloseTag(ofs, command_depth + depth,
3187 if (environment_inner[depth] == "varlistentry")
3188 sgmlCloseTag(ofs, depth+command_depth,
3189 environment_inner[depth]);
3191 sgmlCloseTag(ofs, depth + command_depth,
3192 environment_stack[depth]);
3193 environment_stack[depth].erase();
3194 environment_inner[depth].erase();
3197 if (depth == par->params().depth()
3198 && environment_stack[depth] != style.latexname()
3199 && !environment_stack[depth].empty()) {
3200 if (environment_inner[depth] != "!-- --") {
3201 item_name= "listitem";
3202 sgmlCloseTag(ofs, command_depth+depth,
3204 if (environment_inner[depth] == "varlistentry")
3206 depth + command_depth,
3207 environment_inner[depth]);
3210 sgmlCloseTag(ofs, depth + command_depth,
3211 environment_stack[depth]);
3213 environment_stack[depth].erase();
3214 environment_inner[depth].erase();
3217 // Write opening SGML tags.
3218 switch (style.latextype) {
3219 case LATEX_PARAGRAPH:
3220 sgmlOpenTag(ofs, depth + command_depth,
3227 _("Error : Wrong depth for "
3228 "LatexType Command.\n"));
3230 command_name = style.latexname();
3232 sgmlparam = style.latexparam();
3233 c_params = split(sgmlparam, c_depth,'|');
3235 cmd_depth = lyx::atoi(c_depth);
3238 if (cmd_depth < command_base) {
3239 for (Paragraph::depth_type j = command_depth;
3240 j >= command_base; --j) {
3241 sgmlCloseTag(ofs, j, command_stack[j]);
3244 command_depth = command_base = cmd_depth;
3245 } else if (cmd_depth <= command_depth) {
3246 for (int j = command_depth;
3247 j >= int(cmd_depth); --j) {
3248 sgmlCloseTag(ofs, j, command_stack[j]);
3251 command_depth = cmd_depth;
3253 command_depth = cmd_depth;
3255 command_depth = command_base = cmd_depth;
3256 command_flag = true;
3258 if (command_stack.size() == command_depth + 1)
3259 command_stack.push_back(string());
3260 command_stack[command_depth] = command_name;
3262 // treat label as a special case for
3263 // more WYSIWYM handling.
3264 // This is a hack while paragraphs can't have
3265 // attributes, like id in this case.
3266 if (par->isInset(0)) {
3267 Inset * inset = par->getInset(0);
3268 Inset::Code lyx_code = inset->lyxCode();
3269 if (lyx_code == Inset::LABEL_CODE) {
3270 command_name += " id=\"";
3271 command_name += (static_cast<InsetCommand *>(inset))->getContents();
3272 command_name += "\"";
3277 sgmlOpenTag(ofs, depth + command_depth, command_name);
3278 if (c_params.empty())
3279 item_name = "title";
3281 item_name = c_params;
3282 sgmlOpenTag(ofs, depth + 1 + command_depth, item_name);
3285 case LATEX_ENVIRONMENT:
3286 case LATEX_ITEM_ENVIRONMENT:
3287 if (depth < par->params().depth()) {
3288 depth = par->params().depth();
3289 environment_stack[depth].erase();
3292 if (environment_stack[depth] != style.latexname()) {
3293 if (environment_stack.size() == depth + 1) {
3294 environment_stack.push_back("!-- --");
3295 environment_inner.push_back("!-- --");
3297 environment_stack[depth] = style.latexname();
3298 environment_inner[depth] = "!-- --";
3299 sgmlOpenTag(ofs, depth + command_depth,
3300 environment_stack[depth]);
3302 if (environment_inner[depth] != "!-- --") {
3303 item_name= "listitem";
3305 command_depth + depth,
3307 if (environment_inner[depth] == "varlistentry")
3309 depth + command_depth,
3310 environment_inner[depth]);
3314 if (style.latextype == LATEX_ENVIRONMENT) {
3315 if (!style.latexparam().empty()) {
3316 if (style.latexparam() == "CDATA")
3319 sgmlOpenTag(ofs, depth + command_depth,
3320 style.latexparam());
3325 desc_on = (style.labeltype == LABEL_MANUAL);
3328 environment_inner[depth]= "varlistentry";
3330 environment_inner[depth]= "listitem";
3332 sgmlOpenTag(ofs, depth + 1 + command_depth,
3333 environment_inner[depth]);
3337 sgmlOpenTag(ofs, depth + 1 + command_depth,
3341 sgmlOpenTag(ofs, depth + 1 + command_depth,
3346 sgmlOpenTag(ofs, depth + command_depth,
3351 simpleDocBookOnePar(ofs, par, desc_on, depth+1+command_depth);
3355 // write closing SGML tags
3356 switch (style.latextype) {
3358 if (c_params.empty())
3362 sgmlCloseTag(ofs, depth + command_depth, end_tag);
3364 case LATEX_ENVIRONMENT:
3365 if (!style.latexparam().empty()) {
3366 if (style.latexparam() == "CDATA")
3369 sgmlCloseTag(ofs, depth + command_depth,
3370 style.latexparam());
3373 case LATEX_ITEM_ENVIRONMENT:
3374 if (desc_on == 1) break;
3376 sgmlCloseTag(ofs, depth + 1 + command_depth, end_tag);
3378 case LATEX_PARAGRAPH:
3379 sgmlCloseTag(ofs, depth + command_depth, style.latexname());
3382 sgmlCloseTag(ofs, depth + command_depth, style.latexname());
3388 for (int d = depth; d >= 0; --d) {
3389 if (!environment_stack[depth].empty()) {
3390 if (environment_inner[depth] != "!-- --") {
3391 item_name = "listitem";
3392 sgmlCloseTag(ofs, command_depth + depth,
3394 if (environment_inner[depth] == "varlistentry")
3395 sgmlCloseTag(ofs, depth + command_depth,
3396 environment_inner[depth]);
3399 sgmlCloseTag(ofs, depth + command_depth,
3400 environment_stack[depth]);
3404 for (int j = command_depth; j >= 0 ; --j)
3405 if (!command_stack[j].empty()) {
3406 sgmlCloseTag(ofs, j, command_stack[j]);
3411 sgmlCloseTag(ofs, 0, top_element);
3414 // How to check for successful close
3416 // we want this to be true outside previews (for insetexternal)
3421 void Buffer::simpleDocBookOnePar(ostream & os,
3422 Paragraph * par, int & desc_on,
3423 Paragraph::depth_type depth) const
3425 bool emph_flag = false;
3427 LyXLayout const & style =
3428 textclasslist[params.textclass][par->layout()];
3430 LyXFont font_old = style.labeltype == LABEL_MANUAL ? style.labelfont : style.font;
3432 int char_line_count = depth;
3433 //if (!style.free_spacing)
3434 // os << string(depth,' ');
3436 // parsing main loop
3437 for (pos_type i = 0; i < par->size(); ++i) {
3438 LyXFont font = par->getFont(params, i);
3440 // handle <emphasis> tag
3441 if (font_old.emph() != font.emph()) {
3442 if (font.emph() == LyXFont::ON) {
3443 if(style.latexparam() == "CDATA")
3446 if(style.latexparam() == "CDATA")
3450 if(style.latexparam() == "CDATA")
3452 os << "</emphasis>";
3453 if(style.latexparam() == "CDATA")
3460 if (par->isInset(i)) {
3461 Inset * inset = par->getInset(i);
3462 // don't print the inset in position 0 if desc_on == 3 (label)
3463 if ( i || desc_on != 3) {
3464 if(style.latexparam() == "CDATA")
3466 inset->docbook(this, os);
3467 if(style.latexparam() == "CDATA")
3471 char c = par->getChar(i);
3473 par->sgmlConvertChar(c, sgml_string);
3475 if (style.pass_thru) {
3477 } else if (style.free_spacing || par->isFreeSpacing() || c != ' ') {
3479 } else if (desc_on ==1) {
3481 os << "\n</term><listitem><para>";
3491 if(style.latexparam() == "CDATA")
3493 os << "</emphasis>";
3494 if(style.latexparam() == "CDATA")
3498 // resets description flag correctly
3500 // <term> not closed...
3501 os << "</term>\n<listitem><para> </para>";
3503 if (style.free_spacing) os << '\n';
3507 // This should be enabled when the Chktex class is implemented. (Asger)
3508 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
3509 // Other flags: -wall -v0 -x
3510 int Buffer::runChktex()
3512 if (!users->text) return 0;
3514 users->owner()->prohibitInput();
3516 // get LaTeX-Filename
3517 string const name = getLatexName();
3518 string path = filePath();
3520 string const org_path = path;
3521 if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
3525 Path p(path); // path to LaTeX file
3526 users->owner()->message(_("Running chktex..."));
3528 // Remove all error insets
3529 bool const removedErrorInsets = users->removeAutoInsets();
3531 // Generate the LaTeX file if neccessary
3532 makeLaTeXFile(name, org_path, false);
3535 Chktex chktex(lyxrc.chktex_command, name, filePath());
3536 int res = chktex.run(terr); // run chktex
3539 Alert::alert(_("chktex did not work!"),
3540 _("Could not run with file:"), name);
3541 } else if (res > 0) {
3542 // Insert all errors as errors boxes
3543 users->insertErrors(terr);
3546 // if we removed error insets before we ran chktex or if we inserted
3547 // error insets after we ran chktex, this must be run:
3548 if (removedErrorInsets || res) {
3552 users->owner()->allowInput();
3558 void Buffer::validate(LaTeXFeatures & features) const
3560 Paragraph * par = paragraph;
3561 LyXTextClass const & tclass = textclasslist[params.textclass];
3563 // AMS Style is at document level
3564 if (params.use_amsmath || tclass.provides(LyXTextClass::amsmath))
3565 features.require("amsmath");
3568 // We don't use "lyxerr.debug" because of speed. (Asger)
3569 if (lyxerr.debugging(Debug::LATEX))
3570 lyxerr << "Paragraph: " << par << endl;
3572 // Now just follow the list of paragraphs and run
3573 // validate on each of them.
3574 par->validate(features);
3576 // and then the next paragraph
3580 // the bullet shapes are buffer level not paragraph level
3581 // so they are tested here
3582 for (int i = 0; i < 4; ++i) {
3583 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
3584 int const font = params.user_defined_bullets[i].getFont();
3586 int const c = params
3587 .user_defined_bullets[i]
3594 features.require("latexsym");
3596 } else if (font == 1) {
3597 features.require("amssymb");
3598 } else if ((font >= 2 && font <= 5)) {
3599 features.require("pifont");
3604 if (lyxerr.debugging(Debug::LATEX)) {
3605 features.showStruct();
3610 // This function should be in Buffer because it's a buffer's property (ale)
3611 string const Buffer::getIncludeonlyList(char delim)
3614 for (inset_iterator it = inset_iterator_begin();
3615 it != inset_iterator_end(); ++it) {
3616 if ((*it)->lyxCode() == Inset::INCLUDE_CODE) {
3617 InsetInclude * insetinc =
3618 static_cast<InsetInclude *>(*it);
3619 if (insetinc->isIncludeOnly()) {
3622 lst += insetinc->getRelFileBaseName();
3626 lyxerr[Debug::INFO] << "Includeonly(" << lst << ')' << endl;
3631 vector<string> const Buffer::getLabelList()
3633 /// if this is a child document and the parent is already loaded
3634 /// Use the parent's list instead [ale990407]
3635 if (!params.parentname.empty()
3636 && bufferlist.exists(params.parentname)) {
3637 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3639 return tmp->getLabelList();
3642 vector<string> label_list;
3643 for (inset_iterator it = inset_iterator_begin();
3644 it != inset_iterator_end(); ++it) {
3645 vector<string> const l = (*it)->getLabelList();
3646 label_list.insert(label_list.end(), l.begin(), l.end());
3652 Buffer::Lists const Buffer::getLists() const
3655 Paragraph * par = paragraph;
3657 LyXTextClass const & textclass = textclasslist[params.textclass];
3658 bool found = textclass.hasLayout("Caption");
3659 string const layout("Caption");
3662 char const labeltype = textclass[par->layout()].labeltype;
3664 if (labeltype >= LABEL_COUNTER_CHAPTER
3665 && labeltype <= LABEL_COUNTER_CHAPTER + params.tocdepth) {
3666 // insert this into the table of contents
3667 SingleList & item = l["TOC"];
3670 textclass.maxcounter());
3671 item.push_back(TocItem(par, depth, par->asString(this, true)));
3673 // For each paragrph, traverse its insets and look for
3677 Paragraph::inset_iterator it =
3678 par->inset_iterator_begin();
3679 Paragraph::inset_iterator end =
3680 par->inset_iterator_end();
3682 for (; it != end; ++it) {
3683 if ((*it)->lyxCode() == Inset::FLOAT_CODE) {
3685 static_cast<InsetFloat*>(*it);
3687 string const type = il->type();
3689 // Now find the caption in the float...
3690 // We now tranverse the paragraphs of
3692 Paragraph * tmp = il->inset.paragraph();
3694 if (tmp->layout() == layout) {
3695 SingleList & item = l[type];
3697 tostr(item.size()+1) + ". " + tmp->asString(this, false);
3698 item.push_back(TocItem(tmp, 0 , str));
3705 lyxerr << "Caption not found" << endl;
3714 // This is also a buffer property (ale)
3715 vector<pair<string, string> > const Buffer::getBibkeyList() const
3717 typedef pair<string, string> StringPair;
3718 /// if this is a child document and the parent is already loaded
3719 /// Use the parent's list instead [ale990412]
3720 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3721 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
3723 return tmp->getBibkeyList();
3726 vector<StringPair> keys;
3727 Paragraph * par = paragraph;
3730 string const key = par->bibkey->getContents();
3731 string const opt = par->bibkey->getOptions();
3732 string const ref = par->asString(this, false);
3733 string const info = opt + "TheBibliographyRef" + ref;
3735 keys.push_back(StringPair(key, info));
3740 // Might be either using bibtex or a child has bibliography
3742 for (inset_iterator it = inset_const_iterator_begin();
3743 it != inset_const_iterator_end(); ++it) {
3744 // Search for Bibtex or Include inset
3745 if ((*it)->lyxCode() == Inset::BIBTEX_CODE) {
3746 vector<StringPair> tmp =
3747 static_cast<InsetBibtex*>(*it)->getKeys(this);
3748 keys.insert(keys.end(), tmp.begin(), tmp.end());
3749 } else if ((*it)->lyxCode() == Inset::INCLUDE_CODE) {
3750 vector<StringPair> const tmp =
3751 static_cast<InsetInclude*>(*it)->getKeys();
3752 keys.insert(keys.end(), tmp.begin(), tmp.end());
3761 bool Buffer::isDepClean(string const & name) const
3763 DEPCLEAN * item = dep_clean;
3764 while (item && item->master != name)
3766 if (!item) return true;
3771 void Buffer::markDepClean(string const & name)
3774 dep_clean = new DEPCLEAN;
3775 dep_clean->clean = true;
3776 dep_clean->master = name;
3777 dep_clean->next = 0;
3779 DEPCLEAN * item = dep_clean;
3780 while (item && item->master != name)
3785 item = new DEPCLEAN;
3787 item->master = name;
3794 bool Buffer::dispatch(string const & command)
3796 // Split command string into command and argument
3798 string line = frontStrip(command);
3799 string const arg = strip(frontStrip(split(line, cmd, ' ')));
3801 return dispatch(lyxaction.LookupFunc(cmd), arg);
3805 bool Buffer::dispatch(int action, string const & argument)
3807 bool dispatched = true;
3810 Exporter::Export(this, argument, false);
3820 void Buffer::resizeInsets(BufferView * bv)
3822 /// then remove all LyXText in text-insets
3823 Paragraph * par = paragraph;
3824 for (; par; par = par->next()) {
3825 par->resizeInsetsLyXText(bv);
3830 void Buffer::redraw()
3837 void Buffer::changeLanguage(Language const * from, Language const * to)
3840 ParIterator end = par_iterator_end();
3841 for (ParIterator it = par_iterator_begin(); it != end; ++it)
3842 (*it)->changeLanguage(params, from, to);
3846 bool Buffer::isMultiLingual()
3848 ParIterator end = par_iterator_end();
3849 for (ParIterator it = par_iterator_begin(); it != end; ++it)
3850 if ((*it)->isMultiLingual(params))
3857 Buffer::inset_iterator::inset_iterator(Paragraph * paragraph, pos_type pos)
3860 it = par->InsetIterator(pos);
3861 if (it == par->inset_iterator_end()) {
3868 void Buffer::inset_iterator::setParagraph()
3871 it = par->inset_iterator_begin();
3872 if (it != par->inset_iterator_end())
3877 // We maintain an invariant that whenever par = 0 then it = 0
3881 Inset * Buffer::getInsetFromID(int id_arg) const
3883 for (inset_iterator it = inset_const_iterator_begin();
3884 it != inset_const_iterator_end(); ++it)
3886 if ((*it)->id() == id_arg)
3888 Inset * in = (*it)->getInsetFromID(id_arg);
3896 Paragraph * Buffer::getParFromID(int id) const
3898 if (id < 0) return 0;
3899 Paragraph * par = paragraph;
3901 if (par->id() == id) {
3904 Paragraph * tmp = par->getParFromID(id);
3914 ParIterator Buffer::par_iterator_begin()
3916 return ParIterator(paragraph);
3920 ParIterator Buffer::par_iterator_end()
3922 return ParIterator();