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 == "\\leftindent") {
723 LyXLength value(lex.getString());
724 par->params().leftIndent(value);
725 } else if (token == "\\fill_top") {
726 par->params().spaceTop(VSpace(VSpace::VFILL));
727 } else if (token == "\\fill_bottom") {
728 par->params().spaceBottom(VSpace(VSpace::VFILL));
729 } else if (token == "\\line_top") {
730 par->params().lineTop(true);
731 } else if (token == "\\line_bottom") {
732 par->params().lineBottom(true);
733 } else if (token == "\\pagebreak_top") {
734 par->params().pagebreakTop(true);
735 } else if (token == "\\pagebreak_bottom") {
736 par->params().pagebreakBottom(true);
737 } else if (token == "\\start_of_appendix") {
738 par->params().startOfAppendix(true);
739 } else if (token == "\\paragraph_separation") {
740 int tmpret = lex.findToken(string_paragraph_separation);
743 if (tmpret != LYX_LAYOUT_DEFAULT)
744 params.paragraph_separation =
745 static_cast<BufferParams::PARSEP>(tmpret);
746 } else if (token == "\\defskip") {
748 params.defskip = VSpace(lex.getString());
749 #ifndef NO_COMPABILITY
750 } else if (token == "\\epsfig") { // obsolete
751 // Indeed it is obsolete, but we HAVE to be backwards
752 // compatible until 0.14, because otherwise all figures
753 // in existing documents are irretrivably lost. (Asger)
754 params.readGraphicsDriver(lex);
756 } else if (token == "\\quotes_language") {
757 int tmpret = lex.findToken(string_quotes_language);
760 if (tmpret != LYX_LAYOUT_DEFAULT) {
761 InsetQuotes::quote_language tmpl =
762 InsetQuotes::EnglishQ;
765 tmpl = InsetQuotes::EnglishQ;
768 tmpl = InsetQuotes::SwedishQ;
771 tmpl = InsetQuotes::GermanQ;
774 tmpl = InsetQuotes::PolishQ;
777 tmpl = InsetQuotes::FrenchQ;
780 tmpl = InsetQuotes::DanishQ;
783 params.quotes_language = tmpl;
785 } else if (token == "\\quotes_times") {
787 switch (lex.getInteger()) {
789 params.quotes_times = InsetQuotes::SingleQ;
792 params.quotes_times = InsetQuotes::DoubleQ;
795 } else if (token == "\\papersize") {
796 int tmpret = lex.findToken(string_papersize);
800 params.papersize2 = tmpret;
801 } else if (token == "\\paperpackage") {
802 int tmpret = lex.findToken(string_paperpackages);
805 params.paperpackage = BufferParams::PACKAGE_NONE;
807 params.paperpackage = tmpret;
808 } else if (token == "\\use_geometry") {
810 params.use_geometry = lex.getInteger();
811 } else if (token == "\\use_amsmath") {
813 params.use_amsmath = lex.getInteger();
814 } else if (token == "\\use_natbib") {
816 params.use_natbib = lex.getInteger();
817 } else if (token == "\\use_numerical_citations") {
819 params.use_numerical_citations = lex.getInteger();
820 } else if (token == "\\paperorientation") {
821 int tmpret = lex.findToken(string_orientation);
824 if (tmpret != LYX_LAYOUT_DEFAULT)
825 params.orientation = static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
826 } else if (token == "\\paperwidth") {
828 params.paperwidth = lex.getString();
829 } else if (token == "\\paperheight") {
831 params.paperheight = lex.getString();
832 } else if (token == "\\leftmargin") {
834 params.leftmargin = lex.getString();
835 } else if (token == "\\topmargin") {
837 params.topmargin = lex.getString();
838 } else if (token == "\\rightmargin") {
840 params.rightmargin = lex.getString();
841 } else if (token == "\\bottommargin") {
843 params.bottommargin = lex.getString();
844 } else if (token == "\\headheight") {
846 params.headheight = lex.getString();
847 } else if (token == "\\headsep") {
849 params.headsep = lex.getString();
850 } else if (token == "\\footskip") {
852 params.footskip = lex.getString();
853 } else if (token == "\\paperfontsize") {
855 params.fontsize = strip(lex.getString());
856 } else if (token == "\\papercolumns") {
858 params.columns = lex.getInteger();
859 } else if (token == "\\papersides") {
861 switch (lex.getInteger()) {
863 case 1: params.sides = LyXTextClass::OneSide; break;
864 case 2: params.sides = LyXTextClass::TwoSides; break;
866 } else if (token == "\\paperpagestyle") {
868 params.pagestyle = strip(lex.getString());
869 } else if (token == "\\bullet") {
871 int const index = lex.getInteger();
873 int temp_int = lex.getInteger();
874 params.user_defined_bullets[index].setFont(temp_int);
875 params.temp_bullets[index].setFont(temp_int);
877 temp_int = lex.getInteger();
878 params.user_defined_bullets[index].setCharacter(temp_int);
879 params.temp_bullets[index].setCharacter(temp_int);
881 temp_int = lex.getInteger();
882 params.user_defined_bullets[index].setSize(temp_int);
883 params.temp_bullets[index].setSize(temp_int);
885 string const temp_str = lex.getString();
886 if (temp_str != "\\end_bullet") {
887 // this element isn't really necessary for
888 // parsing but is easier for humans
889 // to understand bullets. Put it back and
890 // set a debug message?
891 lex.printError("\\end_bullet expected, got" + temp_str);
892 //how can I put it back?
894 } else if (token == "\\bulletLaTeX") {
895 // The bullet class should be able to read this.
897 int const index = lex.getInteger();
899 string temp_str = lex.getString();
901 while (temp_str != "\\end_bullet") {
902 // this loop structure is needed when user
903 // enters an empty string since the first
904 // thing returned will be the \\end_bullet
906 // if the LaTeX entry has spaces. Each element
907 // therefore needs to be read in turn
910 temp_str = lex.getString();
913 params.user_defined_bullets[index].setText(sum_str);
914 params.temp_bullets[index].setText(sum_str);
915 } else if (token == "\\secnumdepth") {
917 params.secnumdepth = lex.getInteger();
918 } else if (token == "\\tocdepth") {
920 params.tocdepth = lex.getInteger();
921 } else if (token == "\\spacing") {
923 string const tmp = strip(lex.getString());
924 Spacing::Space tmp_space = Spacing::Default;
926 if (tmp == "single") {
927 tmp_space = Spacing::Single;
928 } else if (tmp == "onehalf") {
929 tmp_space = Spacing::Onehalf;
930 } else if (tmp == "double") {
931 tmp_space = Spacing::Double;
932 } else if (tmp == "other") {
934 tmp_space = Spacing::Other;
935 tmp_val = lex.getFloat();
937 lex.printError("Unknown spacing token: '$$Token'");
939 // Small hack so that files written with klyx will be
942 par->params().spacing(Spacing(tmp_space, tmp_val));
944 params.spacing.set(tmp_space, tmp_val);
946 } else if (token == "\\paragraph_spacing") {
948 string const tmp = strip(lex.getString());
949 if (tmp == "single") {
950 par->params().spacing(Spacing(Spacing::Single));
951 } else if (tmp == "onehalf") {
952 par->params().spacing(Spacing(Spacing::Onehalf));
953 } else if (tmp == "double") {
954 par->params().spacing(Spacing(Spacing::Double));
955 } else if (tmp == "other") {
957 par->params().spacing(Spacing(Spacing::Other,
960 lex.printError("Unknown spacing token: '$$Token'");
962 } else if (token == "\\float_placement") {
964 params.float_placement = lex.getString();
965 } else if (token == "\\family") {
967 font.setLyXFamily(lex.getString());
968 } else if (token == "\\series") {
970 font.setLyXSeries(lex.getString());
971 } else if (token == "\\shape") {
973 font.setLyXShape(lex.getString());
974 } else if (token == "\\size") {
976 font.setLyXSize(lex.getString());
977 #ifndef NO_COMPABILITY
978 } else if (token == "\\latex") {
980 string const tok = lex.getString();
981 if (tok == "no_latex") {
983 insertErtContents(par, pos);
984 } else if (tok == "latex") {
985 ert_comp.active = true;
986 ert_comp.font = font;
987 } else if (tok == "default") {
989 insertErtContents(par, pos);
991 lex.printError("Unknown LaTeX font flag "
995 } else if (token == "\\lang") {
997 string const tok = lex.getString();
998 Language const * lang = languages.getLanguage(tok);
1000 font.setLanguage(lang);
1002 font.setLanguage(params.language);
1003 lex.printError("Unknown language `$$Token'");
1005 } else if (token == "\\numeric") {
1007 font.setNumber(font.setLyXMisc(lex.getString()));
1008 } else if (token == "\\emph") {
1010 font.setEmph(font.setLyXMisc(lex.getString()));
1011 } else if (token == "\\bar") {
1013 string const tok = lex.getString();
1014 // This is dirty, but gone with LyX3. (Asger)
1016 font.setUnderbar(LyXFont::ON);
1017 else if (tok == "no")
1018 font.setUnderbar(LyXFont::OFF);
1019 else if (tok == "default")
1020 font.setUnderbar(LyXFont::INHERIT);
1022 lex.printError("Unknown bar font flag "
1024 } else if (token == "\\noun") {
1026 font.setNoun(font.setLyXMisc(lex.getString()));
1027 } else if (token == "\\color") {
1029 font.setLyXColor(lex.getString());
1030 } else if (token == "\\align") {
1031 int tmpret = lex.findToken(string_align);
1032 if (tmpret == -1) ++tmpret;
1033 if (tmpret != LYX_LAYOUT_DEFAULT) { // tmpret != 99 ???
1034 int const tmpret2 = int(pow(2.0, tmpret));
1035 //lyxerr << "Tmpret2 = " << tmpret2 << endl;
1036 par->params().align(LyXAlignment(tmpret2));
1038 } else if (token == "\\added_space_top") {
1040 VSpace value = VSpace(lex.getString());
1041 if ((value.length().len().value() != 0) ||
1042 (value.kind() != VSpace::LENGTH))
1043 par->params().spaceTop(value);
1044 } else if (token == "\\added_space_bottom") {
1046 VSpace value = VSpace(lex.getString());
1047 if ((value.length().len().value() != 0) ||
1048 (value.kind() != VSpace::LENGTH))
1049 par->params().spaceBottom(value);
1050 #ifndef NO_COMPABILITY
1051 #ifndef NO_PEXTRA_REALLY
1052 } else if (token == "\\pextra_type") {
1054 par->params().pextraType(lex.getInteger());
1055 } else if (token == "\\pextra_width") {
1057 par->params().pextraWidth(lex.getString());
1058 } else if (token == "\\pextra_widthp") {
1060 par->params().pextraWidthp(lex.getString());
1061 } else if (token == "\\pextra_alignment") {
1063 par->params().pextraAlignment(lex.getInteger());
1064 } else if (token == "\\pextra_hfill") {
1066 par->params().pextraHfill(lex.getInteger());
1067 } else if (token == "\\pextra_start_minipage") {
1069 par->params().pextraStartMinipage(lex.getInteger());
1072 } else if (token == "\\labelwidthstring") {
1074 par->params().labelWidthString(lex.getString());
1075 // do not delete this token, it is still needed!
1076 } else if (token == "\\end_inset") {
1077 lyxerr << "Solitary \\end_inset. Missing \\begin_inset?.\n"
1078 << "Last inset read was: " << last_inset_read
1080 // Simply ignore this. The insets do not have
1082 // But insets should read it, it is a part of
1083 // the inset isn't it? Lgb.
1084 } else if (token == "\\begin_inset") {
1085 #ifndef NO_COMPABILITY
1086 insertErtContents(par, pos, false);
1087 ert_stack.push(ert_comp);
1088 ert_comp = ErtComp();
1090 readInset(lex, par, pos, font);
1091 #ifndef NO_COMPABILITY
1092 ert_comp = ert_stack.top();
1094 insertErtContents(par, pos);
1096 } else if (token == "\\SpecialChar") {
1097 LyXLayout const & layout =
1098 textclasslist[params.textclass][par->layout()];
1100 // Insets don't make sense in a free-spacing context! ---Kayvan
1101 if (layout.free_spacing || par->isFreeSpacing()) {
1104 string next_token = lex.getString();
1105 if (next_token == "\\-") {
1106 par->insertChar(pos, '-', font);
1107 } else if (next_token == "\\protected_separator"
1108 || next_token == "~") {
1109 par->insertChar(pos, ' ', font);
1111 lex.printError("Token `$$Token' "
1113 "paragraph layout!");
1118 Inset * inset = new InsetSpecialChar;
1119 inset->read(this, lex);
1120 par->insertInset(pos, inset, font);
1123 } else if (token == "\\newline") {
1124 #ifndef NO_COMPABILITY
1125 if (!ert_comp.in_tabular && ert_comp.active) {
1126 ert_comp.contents += char(Paragraph::META_NEWLINE);
1128 // Since we cannot know it this is only a regular
1129 // newline or a tabular cell delimter we have to
1130 // handle the ERT here.
1131 insertErtContents(par, pos, false);
1133 par->insertChar(pos, Paragraph::META_NEWLINE, font);
1137 par->insertChar(pos, Paragraph::META_NEWLINE, font);
1140 } else if (token == "\\LyXTable") {
1141 #ifndef NO_COMPABILITY
1142 ert_comp.in_tabular = true;
1144 Inset * inset = new InsetTabular(*this);
1145 inset->read(this, lex);
1146 par->insertInset(pos, inset, font);
1148 } else if (token == "\\hfill") {
1149 par->insertChar(pos, Paragraph::META_HFILL, font);
1151 } else if (token == "\\protected_separator") { // obsolete
1152 // This is a backward compability thingie. (Lgb)
1153 // Remove it later some time...introduced with fileformat
1155 LyXLayout const & layout =
1156 textclasslist[params.textclass][par->layout()];
1158 if (layout.free_spacing || par->isFreeSpacing()) {
1159 par->insertChar(pos, ' ', font);
1161 Inset * inset = new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
1162 par->insertInset(pos, inset, font);
1165 } else if (token == "\\bibitem") { // ale970302
1167 InsetCommandParams p("bibitem", "dummy");
1168 par->bibkey = new InsetBibKey(p);
1170 par->bibkey->read(this, lex);
1171 } else if (token == "\\backslash") {
1172 #ifndef NO_COMPABILITY
1173 if (ert_comp.active) {
1174 ert_comp.contents += "\\";
1177 par->insertChar(pos, '\\', font);
1179 #ifndef NO_COMPABILITY
1182 } else if (token == "\\the_end") {
1183 #ifndef NO_COMPABILITY
1184 // If we still have some ert active here we have to insert
1185 // it so we don't loose it. (Lgb)
1186 insertErtContents(par, pos);
1188 the_end_read = true;
1189 #ifndef NO_COMPABILITY
1190 #ifndef NO_PEXTRA_REALLY
1193 minipar = parBeforeMinipage = 0;
1197 #ifndef NO_COMPABILITY
1198 if (ert_comp.active) {
1199 ert_comp.contents += token;
1202 // This should be insurance for the future: (Asger)
1205 string const s = _("Unknown token: ") + token
1206 + " " + lex.text() + "\n";
1207 // we can do this here this way because we're actually reading
1208 // the buffer and don't care about LyXText right now.
1209 InsetError * new_inset = new InsetError(s);
1210 par->insertInset(pos, new_inset, LyXFont(LyXFont::ALL_INHERIT,
1213 #ifndef NO_COMPABILITY
1218 #ifndef NO_COMPABILITY
1219 #ifndef NO_PEXTRA_REALLY
1220 // I wonder if we could use this blanket fix for all the
1221 // checkminipage cases...
1222 // don't forget about ert paragraphs and compatibility read for'em
1223 if (par && (par->size() || !ert_comp.contents.empty())) {
1224 // It is possible that this will check to often,
1225 // but that should not be an correctness issue.
1226 // Only a speed issue.
1227 checkminipage = true;
1230 // now check if we have a minipage paragraph as at this
1231 // point we already read all the necessary data!
1232 // this cannot be done in layout because there we did
1233 // not read yet the paragraph PEXTRA-params (Jug)
1235 // BEGIN pextra_minipage compability
1236 // This should be removed in 1.3.x (Lgb)
1237 // I don't think we should remove this so fast (Jug)
1239 // This compability code is not perfect. In a couple
1240 // of rand cases it fails. When the minipage par is
1241 // the first par in the document, and when there are
1242 // none or only one regular paragraphs after the
1243 // minipage. Currently I am not investing any effort
1244 // in fixing those cases.
1246 // lyxerr << "Call depth: " << call_depth << endl;
1247 // lyxerr << "Checkminipage: " << checkminipage << endl;
1249 if (checkminipage && (call_depth == 1)) {
1250 checkminipage = false;
1251 if (minipar && (minipar != par) &&
1252 (par->params().pextraType() == Paragraph::PEXTRA_MINIPAGE)) {
1253 lyxerr << "minipages in a row" << endl;
1254 if (par->params().pextraStartMinipage()) {
1255 lyxerr << "start new minipage" << endl;
1256 // minipages in a row
1257 par->previous()->next(0);
1260 Paragraph * tmp = minipar;
1262 tmp->params().pextraType(0);
1263 tmp->params().pextraWidth(string());
1264 tmp->params().pextraWidthp(string());
1265 tmp->params().pextraAlignment(0);
1266 tmp->params().pextraHfill(false);
1267 tmp->params().pextraStartMinipage(false);
1270 // create a new paragraph to insert the
1271 // minipages in the following case
1272 if (par->params().pextraStartMinipage() &&
1273 !par->params().pextraHfill()) {
1274 Paragraph * p = new Paragraph;
1275 p->layout(textclasslist[params.textclass].defaultLayoutName());
1277 p->previous(parBeforeMinipage);
1278 parBeforeMinipage->next(p);
1280 p->params().depth(parBeforeMinipage->params().depth());
1281 parBeforeMinipage = p;
1283 InsetMinipage * mini = new InsetMinipage(params);
1284 mini->pos(static_cast<InsetMinipage::Position>(par->params().pextraAlignment()));
1285 mini->pageWidth(LyXLength(par->params().pextraWidth()));
1286 if (!par->params().pextraWidthp().empty()) {
1287 lyxerr << "WP:" << mini->pageWidth().asString() << endl;
1288 mini->pageWidth(LyXLength((par->params().pextraWidthp())+"col%"));
1290 Paragraph * op = mini->firstParagraph();
1291 mini->inset.paragraph(par);
1293 // and free the old ones!
1296 Paragraph * pp = op->next();
1300 // Insert the minipage last in the
1301 // previous paragraph.
1302 if (par->params().pextraHfill()) {
1303 parBeforeMinipage->insertChar
1304 (parBeforeMinipage->size(),
1305 Paragraph::META_HFILL, font);
1307 parBeforeMinipage->insertInset
1308 (parBeforeMinipage->size(), mini, font);
1312 lyxerr << "new minipage par" << endl;
1313 //nothing to do just continue reading
1316 } else if (minipar && (minipar != par)) {
1317 lyxerr << "last minipage par read" << endl;
1318 // The last paragraph read was not part of a
1319 // minipage but the par linked list is...
1320 // So we need to remove the last par from the
1322 if (par->previous())
1323 par->previous()->next(0);
1324 par->previous(parBeforeMinipage);
1325 parBeforeMinipage->next(par);
1326 Paragraph * tmp = minipar;
1328 tmp->params().pextraType(0);
1329 tmp->params().pextraWidth(string());
1330 tmp->params().pextraWidthp(string());
1331 tmp->params().pextraAlignment(0);
1332 tmp->params().pextraHfill(false);
1333 tmp->params().pextraStartMinipage(false);
1336 depth = parBeforeMinipage->params().depth();
1337 // and set this depth on the par as it has not been set already
1338 par->params().depth(depth);
1339 minipar = parBeforeMinipage = 0;
1340 } else if (!minipar &&
1341 (par->params().pextraType() == Paragraph::PEXTRA_MINIPAGE)) {
1342 // par is the first paragraph in a minipage
1343 lyxerr << "begin minipage" << endl;
1344 // To minimize problems for
1345 // the users we will insert
1346 // the first minipage in
1347 // a sequence of minipages
1348 // in its own paragraph.
1349 Paragraph * p = new Paragraph;
1350 p->layout(textclasslist[params.textclass].defaultLayoutName());
1351 p->previous(par->previous());
1353 p->params().depth(depth);
1354 par->params().depth(0);
1356 if (par->previous())
1357 par->previous()->next(p);
1359 parBeforeMinipage = p;
1361 if (!first_par || (first_par == par))
1364 InsetMinipage * mini = new InsetMinipage(params);
1365 mini->pos(static_cast<InsetMinipage::Position>(minipar->params().pextraAlignment()));
1366 mini->pageWidth(LyXLength(minipar->params().pextraWidth()));
1367 if (!par->params().pextraWidthp().empty()) {
1368 lyxerr << "WP:" << mini->pageWidth().asString() << endl;
1369 mini->pageWidth(LyXLength((par->params().pextraWidthp())+"col%"));
1372 Paragraph * op = mini->firstParagraph();
1373 mini->inset.paragraph(minipar);
1375 // and free the old ones!
1378 Paragraph * pp = op->next();
1383 // Insert the minipage last in the
1384 // previous paragraph.
1385 if (minipar->params().pextraHfill()) {
1386 parBeforeMinipage->insertChar
1387 (parBeforeMinipage->size(),
1388 Paragraph::META_HFILL, font);
1390 parBeforeMinipage->insertInset
1391 (parBeforeMinipage->size(), mini, font);
1392 } else if (par->params().pextraType() == Paragraph::PEXTRA_INDENT) {
1393 par->params().leftIndent(LyXLength(par->params().pextraWidth()));
1394 if (!par->params().pextraWidthp().empty()) {
1395 par->params().leftIndent(LyXLength((par->params().pextraWidthp())+"col%"));
1399 // End of pextra_minipage compability
1403 return the_end_read;
1406 // needed to insert the selection
1407 void Buffer::insertStringAsLines(Paragraph *& par, pos_type & pos,
1408 LyXFont const & fn,string const & str) const
1410 LyXLayout const & layout =
1411 textclasslist[params.textclass][par->layout()];
1414 par->checkInsertChar(font);
1415 // insert the string, don't insert doublespace
1416 bool space_inserted = true;
1417 bool autobreakrows = !par->inInset() ||
1418 static_cast<InsetText *>(par->inInset())->getAutoBreakRows();
1419 for(string::const_iterator cit = str.begin();
1420 cit != str.end(); ++cit) {
1422 if (autobreakrows && (par->size() || layout.keepempty)) {
1423 par->breakParagraph(params, pos,
1424 layout.isEnvironment());
1427 space_inserted = true;
1431 // do not insert consecutive spaces if !free_spacing
1432 } else if ((*cit == ' ' || *cit == '\t') &&
1433 space_inserted && !layout.free_spacing &&
1434 !par->isFreeSpacing())
1437 } else if (*cit == '\t') {
1438 if (!layout.free_spacing && !par->isFreeSpacing()) {
1439 // tabs are like spaces here
1440 par->insertChar(pos, ' ', font);
1442 space_inserted = true;
1444 const pos_type nb = 8 - pos % 8;
1445 for (pos_type a = 0; a < nb ; ++a) {
1446 par->insertChar(pos, ' ', font);
1449 space_inserted = true;
1451 } else if (!IsPrintable(*cit)) {
1452 // Ignore unprintables
1455 // just insert the character
1456 par->insertChar(pos, *cit, font);
1458 space_inserted = (*cit == ' ');
1465 void Buffer::readInset(LyXLex & lex, Paragraph *& par,
1466 int & pos, LyXFont & font)
1468 // consistency check
1469 if (lex.getString() != "\\begin_inset") {
1470 lyxerr << "Buffer::readInset: Consistency check failed."
1477 string const tmptok = lex.getString();
1478 last_inset_read = tmptok;
1480 // test the different insets
1481 if (tmptok == "LatexCommand") {
1482 InsetCommandParams inscmd;
1485 string const cmdName = inscmd.getCmdName();
1487 // This strange command allows LyX to recognize "natbib" style
1488 // citations: citet, citep, Citet etc.
1489 if (compare_no_case(cmdName, "cite", 4) == 0) {
1490 inset = new InsetCitation(inscmd);
1491 } else if (cmdName == "bibitem") {
1492 lex.printError("Wrong place for bibitem");
1493 inset = new InsetBibKey(inscmd);
1494 } else if (cmdName == "BibTeX") {
1495 inset = new InsetBibtex(inscmd);
1496 } else if (cmdName == "index") {
1497 inset = new InsetIndex(inscmd);
1498 } else if (cmdName == "include") {
1499 inset = new InsetInclude(inscmd, *this);
1500 } else if (cmdName == "label") {
1501 inset = new InsetLabel(inscmd);
1502 } else if (cmdName == "url"
1503 || cmdName == "htmlurl") {
1504 inset = new InsetUrl(inscmd);
1505 } else if (cmdName == "ref"
1506 || cmdName == "pageref"
1507 || cmdName == "vref"
1508 || cmdName == "vpageref"
1509 || cmdName == "prettyref") {
1510 if (!inscmd.getOptions().empty()
1511 || !inscmd.getContents().empty()) {
1512 inset = new InsetRef(inscmd, *this);
1514 } else if (cmdName == "tableofcontents") {
1515 inset = new InsetTOC(inscmd);
1516 } else if (cmdName == "listofalgorithms") {
1517 inset = new InsetFloatList("algorithm");
1518 } else if (cmdName == "listoffigures") {
1519 inset = new InsetFloatList("figure");
1520 } else if (cmdName == "listoftables") {
1521 inset = new InsetFloatList("table");
1522 } else if (cmdName == "printindex") {
1523 inset = new InsetPrintIndex(inscmd);
1524 } else if (cmdName == "lyxparent") {
1525 inset = new InsetParent(inscmd, *this);
1528 bool alreadyread = false;
1529 if (tmptok == "Quotes") {
1530 inset = new InsetQuotes;
1531 } else if (tmptok == "External") {
1532 inset = new InsetExternal;
1533 } else if (tmptok == "FormulaMacro") {
1534 inset = new InsetFormulaMacro;
1535 } else if (tmptok == "Formula") {
1536 inset = new InsetFormula;
1537 } else if (tmptok == "Figure") { // Backward compatibility
1538 // inset = new InsetFig(100, 100, *this);
1539 inset = new InsetGraphics;
1540 } else if (tmptok == "Graphics") {
1541 inset = new InsetGraphics;
1542 } else if (tmptok == "Info") {// backwards compatibility
1543 inset = new InsetNote(this,
1544 lex.getLongString("\\end_inset"),
1547 } else if (tmptok == "Note") {
1548 inset = new InsetNote(params);
1549 } else if (tmptok == "Include") {
1550 InsetCommandParams p("Include");
1551 inset = new InsetInclude(p, *this);
1552 } else if (tmptok == "ERT") {
1553 inset = new InsetERT(params);
1554 } else if (tmptok == "Tabular") {
1555 inset = new InsetTabular(*this);
1556 } else if (tmptok == "Text") {
1557 inset = new InsetText(params);
1558 } else if (tmptok == "Foot") {
1559 inset = new InsetFoot(params);
1560 } else if (tmptok == "Marginal") {
1561 inset = new InsetMarginal(params);
1562 } else if (tmptok == "Minipage") {
1563 inset = new InsetMinipage(params);
1564 } else if (tmptok == "Float") {
1566 string tmptok = lex.getString();
1567 inset = new InsetFloat(params, tmptok);
1569 } else if (tmptok == "List") {
1570 inset = new InsetList;
1571 } else if (tmptok == "Theorem") {
1572 inset = new InsetList;
1574 } else if (tmptok == "Caption") {
1575 inset = new InsetCaption(params);
1576 } else if (tmptok == "FloatList") {
1577 inset = new InsetFloatList;
1580 if (inset && !alreadyread) inset->read(this, lex);
1584 par->insertInset(pos, inset, font);
1590 bool Buffer::readFile(LyXLex & lex, Paragraph * par)
1594 string const token(lex.getString());
1595 if (token == "\\lyxformat") { // the first token _must_ be...
1597 string tmp_format = lex.getString();
1598 //lyxerr << "LyX Format: `" << tmp_format << "'" << endl;
1599 // if present remove ".," from string.
1600 string::size_type dot = tmp_format.find_first_of(".,");
1601 //lyxerr << " dot found at " << dot << endl;
1602 if (dot != string::npos)
1603 tmp_format.erase(dot, 1);
1604 file_format = strToInt(tmp_format);
1605 if (file_format == LYX_FORMAT) {
1607 } else if (file_format > LYX_FORMAT) {
1609 Alert::alert(_("Warning!"),
1610 _("LyX file format is newer that what"),
1611 _("is supported in this LyX version. Expect some problems."));
1613 } else if (file_format < LYX_FORMAT) {
1615 if (file_format < 200) {
1616 Alert::alert(_("ERROR!"),
1617 _("Old LyX file format found. "
1618 "Use LyX 0.10.x to read this!"));
1622 bool the_end = readLyXformat2(lex, par);
1623 params.setPaperStuff();
1624 // the_end was added in 213
1625 if (file_format < 213)
1629 Alert::alert(_("Warning!"),
1630 _("Reading of document is not complete"),
1631 _("Maybe the document is truncated"));
1634 } else { // "\\lyxformat" not found
1635 Alert::alert(_("ERROR!"), _("Not a LyX file!"));
1638 Alert::alert(_("ERROR!"), _("Unable to read file!"));
1643 // Should probably be moved to somewhere else: BufferView? LyXView?
1644 bool Buffer::save() const
1646 // We don't need autosaves in the immediate future. (Asger)
1647 resetAutosaveTimers();
1651 if (lyxrc.make_backup) {
1652 s = fileName() + '~';
1653 if (!lyxrc.backupdir_path.empty())
1654 s = AddName(lyxrc.backupdir_path,
1655 subst(os::slashify_path(s),'/','!'));
1657 // Rename is the wrong way of making a backup,
1658 // this is the correct way.
1659 /* truss cp fil fil2:
1660 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
1661 stat("LyXVC.lyx", 0xEFFFF688) = 0
1662 open("LyXVC.lyx", O_RDONLY) = 3
1663 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
1664 fstat(4, 0xEFFFF508) = 0
1665 fstat(3, 0xEFFFF508) = 0
1666 read(3, " # T h i s f i l e w".., 8192) = 5579
1667 write(4, " # T h i s f i l e w".., 5579) = 5579
1668 read(3, 0xEFFFD4A0, 8192) = 0
1671 chmod("LyXVC3.lyx", 0100644) = 0
1672 lseek(0, 0, SEEK_CUR) = 46440
1676 // Should probably have some more error checking here.
1677 // Should be cleaned up in 0.13, at least a bit.
1678 // Doing it this way, also makes the inodes stay the same.
1679 // This is still not a very good solution, in particular we
1680 // might loose the owner of the backup.
1681 FileInfo finfo(fileName());
1682 if (finfo.exist()) {
1683 mode_t fmode = finfo.getMode();
1684 struct utimbuf times = {
1685 finfo.getAccessTime(),
1686 finfo.getModificationTime() };
1688 ifstream ifs(fileName().c_str());
1689 ofstream ofs(s.c_str(), ios::out|ios::trunc);
1694 ::chmod(s.c_str(), fmode);
1696 if (::utime(s.c_str(), ×)) {
1697 lyxerr << "utime error." << endl;
1700 lyxerr << "LyX was not able to make "
1701 "backup copy. Beware." << endl;
1706 if (writeFile(fileName(), false)) {
1708 removeAutosaveFile(fileName());
1710 // Saving failed, so backup is not backup
1711 if (lyxrc.make_backup) {
1712 lyx::rename(s, fileName());
1720 // Returns false if unsuccesful
1721 bool Buffer::writeFile(string const & fname, bool flag) const
1723 // if flag is false writeFile will not create any GUI
1724 // warnings, only cerr.
1725 // Needed for autosave in background or panic save (Matthias 120496)
1727 if (read_only && (fname == fileName())) {
1728 // Here we should come with a question if we should
1729 // perform the write anyway.
1731 lyxerr << _("Error! Document is read-only: ")
1734 Alert::alert(_("Error! Document is read-only: "),
1739 FileInfo finfo(fname);
1740 if (finfo.exist() && !finfo.writable()) {
1741 // Here we should come with a question if we should
1742 // try to do the save anyway. (i.e. do a chmod first)
1744 lyxerr << _("Error! Cannot write file: ")
1747 Alert::err_alert(_("Error! Cannot write file: "),
1752 ofstream ofs(fname.c_str());
1755 lyxerr << _("Error! Cannot open file: ")
1758 Alert::err_alert(_("Error! Cannot open file: "),
1764 // Use the standard "C" locale for file output.
1765 ofs.imbue(std::locale::classic());
1768 // The top of the file should not be written by params.
1770 // write out a comment in the top of the file
1771 ofs << '#' << lyx_docversion
1772 << " created this file. For more info see http://www.lyx.org/\n"
1773 << "\\lyxformat " << LYX_FORMAT << "\n";
1775 // now write out the buffer paramters.
1776 params.writeFile(ofs);
1778 Paragraph::depth_type depth = 0;
1780 // this will write out all the paragraphs
1781 // using recursive descent.
1782 paragraph->writeFile(this, ofs, params, depth);
1784 // Write marker that shows file is complete
1785 ofs << "\n\\the_end" << endl;
1789 // how to check if close went ok?
1790 // Following is an attempt... (BE 20001011)
1792 // good() returns false if any error occured, including some
1793 // formatting error.
1794 // bad() returns true if something bad happened in the buffer,
1795 // which should include file system full errors.
1802 lyxerr << "Buffer::writeFile: BAD ERROR!" << endl;
1804 lyxerr << "Buffer::writeFile: NOT SO BAD ERROR!"
1816 pair<int, string> const addDepth(int depth, int ldepth)
1820 d += (ldepth - depth) * 2;
1821 return make_pair(d, string(d, ' '));
1827 string const Buffer::asciiParagraph(Paragraph const * par,
1828 unsigned int linelen,
1829 bool noparbreak) const
1831 ostringstream buffer;
1832 Paragraph::depth_type depth = 0;
1834 Paragraph::depth_type ltype_depth = 0;
1835 bool ref_printed = false;
1836 // if (!par->previous()) {
1838 // begins or ends a deeper area ?
1839 if (depth != par->params().depth()) {
1840 if (par->params().depth() > depth) {
1841 while (par->params().depth() > depth) {
1845 while (par->params().depth() < depth) {
1851 depth = par->params().depth();
1854 // First write the layout
1855 string const & tmp = par->layout();
1856 if (compare_no_case(tmp, "itemize") == 0) {
1858 ltype_depth = depth + 1;
1859 } else if (compare_no_case(tmp, "enumerate") == 0) {
1861 ltype_depth = depth + 1;
1862 } else if (contains(lowercase(tmp), "ection")) {
1864 ltype_depth = depth + 1;
1865 } else if (contains(lowercase(tmp), "aragraph")) {
1867 ltype_depth = depth + 1;
1868 } else if (compare_no_case(tmp, "description") == 0) {
1870 ltype_depth = depth + 1;
1871 } else if (compare_no_case(tmp, "abstract") == 0) {
1874 } else if (compare_no_case(tmp, "bibliography") == 0) {
1882 /* maybe some vertical spaces */
1884 /* the labelwidthstring used in lists */
1888 /* some pagebreaks? */
1892 /* what about the alignment */
1894 // lyxerr << "Should this ever happen?" << endl;
1897 // linelen <= 0 is special and means we don't have pargraph breaks
1899 string::size_type currlinelen = 0;
1905 buffer << string(depth * 2, ' ');
1906 currlinelen += depth * 2;
1909 // we should probably change to the paragraph language in the
1910 // gettext here (if possible) so that strings are outputted in
1911 // the correct language! (20012712 Jug)
1915 case 4: // (Sub)Paragraph
1916 case 5: // Description
1920 buffer << _("Abstract") << "\n\n";
1923 string const abst = _("Abstract: ");
1925 currlinelen += abst.length();
1928 case 7: // Bibliography
1931 buffer << _("References") << "\n\n";
1934 string const refs = _("References: ");
1936 currlinelen += refs.length();
1944 string const parlab = par->params().labelString();
1945 buffer << parlab << " ";
1946 currlinelen += parlab.length() + 1;
1954 pair<int, string> p = addDepth(depth, ltype_depth);
1956 currlinelen += p.first;
1959 // this is to change the linebreak to do it by word a bit more
1960 // intelligent hopefully! (only in the case where we have a
1961 // max linelenght!) (Jug)
1965 for (pos_type i = 0; i < par->size(); ++i) {
1966 char c = par->getUChar(params, i);
1968 case Paragraph::META_INSET:
1970 Inset const * inset = par->getInset(i);
1974 currlinelen += word.length();
1977 if (inset->ascii(this, buffer, linelen)) {
1978 // to be sure it breaks paragraph
1979 currlinelen += linelen;
1985 case Paragraph::META_NEWLINE:
1987 buffer << word << "\n";
1990 pair<int, string> p = addDepth(depth,
1993 currlinelen = p.first;
1997 case Paragraph::META_HFILL:
1998 buffer << word << "\t";
1999 currlinelen += word.length() + 1;
2006 currlinelen + word.length() > linelen - 10) {
2008 pair<int, string> p =
2009 addDepth(depth, ltype_depth);
2011 currlinelen = p.first;
2014 buffer << word << ' ';
2015 currlinelen += word.length() + 1;
2022 lyxerr[Debug::INFO] <<
2023 "writeAsciiFile: NULL char in structure." << endl;
2025 if ((linelen > 0) &&
2026 (currlinelen + word.length()) > linelen)
2030 pair<int, string> p =
2031 addDepth(depth, ltype_depth);
2033 currlinelen = p.first;
2040 return buffer.str().c_str();
2044 void Buffer::writeFileAscii(string const & fname, int linelen)
2046 ofstream ofs(fname.c_str());
2048 Alert::err_alert(_("Error: Cannot write file:"), fname);
2051 writeFileAscii(ofs, linelen);
2055 void Buffer::writeFileAscii(ostream & ofs, int linelen)
2057 Paragraph * par = paragraph;
2059 ofs << asciiParagraph(par, linelen, par->previous() == 0);
2069 void Buffer::makeLaTeXFile(string const & fname,
2070 string const & original_path,
2071 bool nice, bool only_body)
2073 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
2075 ofstream ofs(fname.c_str());
2077 Alert::err_alert(_("Error: Cannot open file: "), fname);
2081 niceFile = nice; // this will be used by Insetincludes.
2083 tex_code_break_column = lyxrc.ascii_linelen;
2085 // validate the buffer.
2086 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
2087 LaTeXFeatures features(params);
2089 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
2092 // The starting paragraph of the coming rows is the
2093 // first paragraph of the document. (Asger)
2094 texrow.start(paragraph, 0);
2096 if (!only_body && nice) {
2097 ofs << "%% " << lyx_docversion << " created this file. "
2098 "For more info, see http://www.lyx.org/.\n"
2099 "%% Do not edit unless you really know what "
2104 lyxerr[Debug::INFO] << "lyx header finished" << endl;
2105 // There are a few differences between nice LaTeX and usual files:
2106 // usual is \batchmode and has a
2107 // special input@path to allow the including of figures
2108 // with either \input or \includegraphics (what figinsets do).
2109 // batchmode is not set if there is a tex_code_break_column.
2110 // In this case somebody is interested in the generated LaTeX,
2111 // so this is OK. input@path is set when the actual parameter
2112 // original_path is set. This is done for usual tex-file, but not
2113 // for nice-latex-file. (Matthias 250696)
2116 // code for usual, NOT nice-latex-file
2117 ofs << "\\batchmode\n"; // changed
2118 // from \nonstopmode
2121 if (!original_path.empty()) {
2122 string inputpath = os::external_path(original_path);
2123 subst(inputpath, "~", "\\string~");
2124 ofs << "\\makeatletter\n"
2125 << "\\def\\input@path{{"
2126 << inputpath << "/}}\n"
2127 << "\\makeatother\n";
2133 ofs << "\\documentclass";
2135 LyXTextClass const & tclass = textclasslist[params.textclass];
2137 ostringstream options; // the document class options.
2139 if (tokenPos(tclass.opt_fontsize(),
2140 '|', params.fontsize) >= 0) {
2141 // only write if existing in list (and not default)
2142 options << params.fontsize << "pt,";
2146 if (!params.use_geometry &&
2147 (params.paperpackage == BufferParams::PACKAGE_NONE)) {
2148 switch (params.papersize) {
2149 case BufferParams::PAPER_A4PAPER:
2150 options << "a4paper,";
2152 case BufferParams::PAPER_USLETTER:
2153 options << "letterpaper,";
2155 case BufferParams::PAPER_A5PAPER:
2156 options << "a5paper,";
2158 case BufferParams::PAPER_B5PAPER:
2159 options << "b5paper,";
2161 case BufferParams::PAPER_EXECUTIVEPAPER:
2162 options << "executivepaper,";
2164 case BufferParams::PAPER_LEGALPAPER:
2165 options << "legalpaper,";
2171 if (params.sides != tclass.sides()) {
2172 switch (params.sides) {
2173 case LyXTextClass::OneSide:
2174 options << "oneside,";
2176 case LyXTextClass::TwoSides:
2177 options << "twoside,";
2183 if (params.columns != tclass.columns()) {
2184 if (params.columns == 2)
2185 options << "twocolumn,";
2187 options << "onecolumn,";
2190 if (!params.use_geometry
2191 && params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
2192 options << "landscape,";
2194 // language should be a parameter to \documentclass
2196 ostringstream language_options;
2197 if (params.language->babel() == "hebrew"
2198 && default_language->babel() != "hebrew")
2199 // This seems necessary
2200 features.useLanguage(default_language);
2202 if (lyxrc.language_use_babel ||
2203 params.language->lang() != lyxrc.default_language ||
2204 features.hasLanguages()) {
2206 language_options << features.getLanguages();
2207 language_options << params.language->babel();
2208 if (lyxrc.language_global_options)
2209 options << language_options.str() << ',';
2212 // the user-defined options
2213 if (!params.options.empty()) {
2214 options << params.options << ',';
2217 string strOptions(options.str().c_str());
2218 if (!strOptions.empty()) {
2219 strOptions = strip(strOptions, ',');
2220 ofs << '[' << strOptions << ']';
2223 ofs << '{' << tclass.latexname() << "}\n";
2225 // end of \documentclass defs
2227 // font selection must be done before loading fontenc.sty
2228 // The ae package is not needed when using OT1 font encoding.
2229 if (params.fonts != "default" &&
2230 (params.fonts != "ae" || lyxrc.fontenc != "default")) {
2231 ofs << "\\usepackage{" << params.fonts << "}\n";
2233 if (params.fonts == "ae") {
2234 ofs << "\\usepackage{aecompl}\n";
2238 // this one is not per buffer
2239 if (lyxrc.fontenc != "default") {
2240 ofs << "\\usepackage[" << lyxrc.fontenc
2245 if (params.inputenc == "auto") {
2246 string const doc_encoding =
2247 params.language->encoding()->LatexName();
2249 // Create a list with all the input encodings used
2251 set<string> encodings = features.getEncodingSet(doc_encoding);
2253 ofs << "\\usepackage[";
2254 std::copy(encodings.begin(), encodings.end(),
2255 std::ostream_iterator<string>(ofs, ","));
2256 ofs << doc_encoding << "]{inputenc}\n";
2258 } else if (params.inputenc != "default") {
2259 ofs << "\\usepackage[" << params.inputenc
2264 // At the very beginning the text parameters.
2265 if (params.paperpackage != BufferParams::PACKAGE_NONE) {
2266 switch (params.paperpackage) {
2267 case BufferParams::PACKAGE_A4:
2268 ofs << "\\usepackage{a4}\n";
2271 case BufferParams::PACKAGE_A4WIDE:
2272 ofs << "\\usepackage{a4wide}\n";
2275 case BufferParams::PACKAGE_WIDEMARGINSA4:
2276 ofs << "\\usepackage[widemargins]{a4}\n";
2281 if (params.use_geometry) {
2282 ofs << "\\usepackage{geometry}\n";
2284 ofs << "\\geometry{verbose";
2285 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
2286 ofs << ",landscape";
2287 switch (params.papersize2) {
2288 case BufferParams::VM_PAPER_CUSTOM:
2289 if (!params.paperwidth.empty())
2290 ofs << ",paperwidth="
2291 << params.paperwidth;
2292 if (!params.paperheight.empty())
2293 ofs << ",paperheight="
2294 << params.paperheight;
2296 case BufferParams::VM_PAPER_USLETTER:
2297 ofs << ",letterpaper";
2299 case BufferParams::VM_PAPER_USLEGAL:
2300 ofs << ",legalpaper";
2302 case BufferParams::VM_PAPER_USEXECUTIVE:
2303 ofs << ",executivepaper";
2305 case BufferParams::VM_PAPER_A3:
2308 case BufferParams::VM_PAPER_A4:
2311 case BufferParams::VM_PAPER_A5:
2314 case BufferParams::VM_PAPER_B3:
2317 case BufferParams::VM_PAPER_B4:
2320 case BufferParams::VM_PAPER_B5:
2324 // default papersize ie BufferParams::VM_PAPER_DEFAULT
2325 switch (lyxrc.default_papersize) {
2326 case BufferParams::PAPER_DEFAULT: // keep compiler happy
2327 case BufferParams::PAPER_USLETTER:
2328 ofs << ",letterpaper";
2330 case BufferParams::PAPER_LEGALPAPER:
2331 ofs << ",legalpaper";
2333 case BufferParams::PAPER_EXECUTIVEPAPER:
2334 ofs << ",executivepaper";
2336 case BufferParams::PAPER_A3PAPER:
2339 case BufferParams::PAPER_A4PAPER:
2342 case BufferParams::PAPER_A5PAPER:
2345 case BufferParams::PAPER_B5PAPER:
2350 if (!params.topmargin.empty())
2351 ofs << ",tmargin=" << params.topmargin;
2352 if (!params.bottommargin.empty())
2353 ofs << ",bmargin=" << params.bottommargin;
2354 if (!params.leftmargin.empty())
2355 ofs << ",lmargin=" << params.leftmargin;
2356 if (!params.rightmargin.empty())
2357 ofs << ",rmargin=" << params.rightmargin;
2358 if (!params.headheight.empty())
2359 ofs << ",headheight=" << params.headheight;
2360 if (!params.headsep.empty())
2361 ofs << ",headsep=" << params.headsep;
2362 if (!params.footskip.empty())
2363 ofs << ",footskip=" << params.footskip;
2368 if (tokenPos(tclass.opt_pagestyle(),
2369 '|', params.pagestyle) >= 0) {
2370 if (params.pagestyle == "fancy") {
2371 ofs << "\\usepackage{fancyhdr}\n";
2374 ofs << "\\pagestyle{" << params.pagestyle << "}\n";
2378 if (params.secnumdepth != tclass.secnumdepth()) {
2379 ofs << "\\setcounter{secnumdepth}{"
2380 << params.secnumdepth
2384 if (params.tocdepth != tclass.tocdepth()) {
2385 ofs << "\\setcounter{tocdepth}{"
2391 if (params.paragraph_separation) {
2392 switch (params.defskip.kind()) {
2393 case VSpace::SMALLSKIP:
2394 ofs << "\\setlength\\parskip{\\smallskipamount}\n";
2396 case VSpace::MEDSKIP:
2397 ofs << "\\setlength\\parskip{\\medskipamount}\n";
2399 case VSpace::BIGSKIP:
2400 ofs << "\\setlength\\parskip{\\bigskipamount}\n";
2402 case VSpace::LENGTH:
2403 ofs << "\\setlength\\parskip{"
2404 << params.defskip.length().asLatexString()
2407 default: // should never happen // Then delete it.
2408 ofs << "\\setlength\\parskip{\\medskipamount}\n";
2413 ofs << "\\setlength\\parindent{0pt}\n";
2417 // Now insert the LyX specific LaTeX commands...
2419 // The optional packages;
2420 string preamble(features.getPackages());
2422 // this might be useful...
2423 preamble += "\n\\makeatletter\n";
2425 // Some macros LyX will need
2426 string tmppreamble(features.getMacros());
2428 if (!tmppreamble.empty()) {
2429 preamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2430 "LyX specific LaTeX commands.\n"
2431 + tmppreamble + '\n';
2434 // the text class specific preamble
2435 tmppreamble = features.getTClassPreamble();
2436 if (!tmppreamble.empty()) {
2437 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2438 "Textclass specific LaTeX commands.\n"
2439 + tmppreamble + '\n';
2442 /* the user-defined preamble */
2443 if (!params.preamble.empty()) {
2444 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2445 "User specified LaTeX commands.\n"
2446 + params.preamble + '\n';
2449 preamble += "\\makeatother\n";
2451 // Itemize bullet settings need to be last in case the user
2452 // defines their own bullets that use a package included
2453 // in the user-defined preamble -- ARRae
2454 // Actually it has to be done much later than that
2455 // since some packages like frenchb make modifications
2456 // at \begin{document} time -- JMarc
2458 for (int i = 0; i < 4; ++i) {
2459 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
2460 if (bullets_def.empty())
2461 bullets_def="\\AtBeginDocument{\n";
2462 bullets_def += " \\renewcommand{\\labelitemi";
2464 // `i' is one less than the item to modify
2471 bullets_def += "ii";
2477 bullets_def += "}{" +
2478 params.user_defined_bullets[i].getText()
2483 if (!bullets_def.empty())
2484 preamble += bullets_def + "}\n\n";
2487 int(lyx::count(preamble.begin(), preamble.end(), '\n'));
2488 for (int j = 0; j != nlines; ++j) {
2494 // We try to load babel late, in case it interferes
2495 // with other packages.
2497 string tmp = lyxrc.language_package;
2498 if (!lyxrc.language_global_options
2499 && tmp == "\\usepackage{babel}")
2500 tmp = string("\\usepackage[") +
2501 language_options.str().c_str() +
2508 ofs << "\\begin{document}\n";
2511 lyxerr[Debug::INFO] << "preamble finished, now the body." << endl;
2513 if (!lyxrc.language_auto_begin) {
2514 ofs << subst(lyxrc.language_command_begin, "$$lang",
2515 params.language->babel())
2520 latexParagraphs(ofs, paragraph, 0, texrow);
2522 // add this just in case after all the paragraphs
2526 if (!lyxrc.language_auto_end) {
2527 ofs << subst(lyxrc.language_command_end, "$$lang",
2528 params.language->babel())
2534 ofs << "\\end{document}\n";
2537 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
2539 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
2543 // Just to be sure. (Asger)
2546 // tex_code_break_column's value is used to decide
2547 // if we are in batchmode or not (within mathed_write()
2548 // in math_write.C) so we must set it to a non-zero
2549 // value when we leave otherwise we save incorrect .lyx files.
2550 tex_code_break_column = lyxrc.ascii_linelen;
2554 lyxerr << "File was not closed properly." << endl;
2557 lyxerr[Debug::INFO] << "Finished making latex file." << endl;
2558 lyxerr[Debug::INFO] << "Row count was " << texrow.rows()-1 << "." << endl;
2560 // we want this to be true outside previews (for insetexternal)
2566 // LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
2568 void Buffer::latexParagraphs(ostream & ofs, Paragraph * par,
2569 Paragraph * endpar, TexRow & texrow) const
2571 bool was_title = false;
2572 bool already_title = false;
2575 while (par != endpar) {
2576 Inset * in = par->inInset();
2577 // well we have to check if we are in an inset with unlimited
2578 // lenght (all in one row) if that is true then we don't allow
2579 // any special options in the paragraph and also we don't allow
2580 // any environment other then "Standard" to be valid!
2581 if ((in == 0) || !in->forceDefaultParagraphs(in)) {
2582 LyXLayout const & layout =
2583 textclasslist[params.textclass][par->layout()];
2585 if (layout.intitle) {
2586 if (already_title) {
2587 lyxerr <<"Error in latexParagraphs: You"
2588 " should not mix title layouts"
2589 " with normal ones." << endl;
2592 } else if (was_title && !already_title) {
2593 ofs << "\\maketitle\n";
2595 already_title = true;
2599 if (layout.isEnvironment() ||
2600 !par->params().leftIndent().zero())
2602 par = par->TeXEnvironment(this, params, ofs, texrow);
2604 par = par->TeXOnePar(this, params, ofs, texrow, false);
2607 par = par->TeXOnePar(this, params, ofs, texrow, false);
2610 // It might be that we only have a title in this document
2611 if (was_title && !already_title) {
2612 ofs << "\\maketitle\n";
2618 bool Buffer::isLatex() const
2620 return textclasslist[params.textclass].outputType() == LATEX;
2624 bool Buffer::isLinuxDoc() const
2626 return textclasslist[params.textclass].outputType() == LINUXDOC;
2630 bool Buffer::isLiterate() const
2632 return textclasslist[params.textclass].outputType() == LITERATE;
2636 bool Buffer::isDocBook() const
2638 return textclasslist[params.textclass].outputType() == DOCBOOK;
2642 bool Buffer::isSGML() const
2644 LyXTextClass const & tclass = textclasslist[params.textclass];
2646 return tclass.outputType() == LINUXDOC ||
2647 tclass.outputType() == DOCBOOK;
2651 void Buffer::sgmlOpenTag(ostream & os, Paragraph::depth_type,
2652 string const & latexname) const
2654 if (!latexname.empty() && latexname != "!-- --")
2655 //os << "<!-- " << depth << " -->" << "<" << latexname << ">";
2656 os << "<" << latexname << ">";
2660 void Buffer::sgmlCloseTag(ostream & os, Paragraph::depth_type,
2661 string const & latexname) const
2663 if (!latexname.empty() && latexname != "!-- --")
2664 //os << "<!-- " << depth << " -->" << "</" << latexname << ">\n";
2665 os << "</" << latexname << ">";
2669 void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
2671 ofstream ofs(fname.c_str());
2674 Alert::alert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2678 niceFile = nice; // this will be used by included files.
2680 LaTeXFeatures features(params);
2686 LyXTextClass const & tclass = textclasslist[params.textclass];
2688 string top_element = tclass.latexname();
2691 ofs << "<!doctype linuxdoc system";
2693 string preamble = params.preamble;
2694 const string name = nice ? ChangeExtension(filename_, ".sgml")
2696 preamble += features.getIncludedFiles(name);
2697 preamble += features.getLyXSGMLEntities();
2699 if (!preamble.empty()) {
2700 ofs << " [ " << preamble << " ]";
2704 if (params.options.empty())
2705 sgmlOpenTag(ofs, 0, top_element);
2707 string top = top_element;
2709 top += params.options;
2710 sgmlOpenTag(ofs, 0, top);
2714 ofs << "<!-- " << lyx_docversion
2715 << " created this file. For more info see http://www.lyx.org/"
2718 Paragraph::depth_type depth = 0; // paragraph depth
2719 Paragraph * par = paragraph;
2721 vector<string> environment_stack(5);
2724 LyXLayout const & style = tclass[par->layout()];
2726 // treat <toc> as a special case for compatibility with old code
2727 if (par->isInset(0)) {
2728 Inset * inset = par->getInset(0);
2729 Inset::Code lyx_code = inset->lyxCode();
2730 if (lyx_code == Inset::TOC_CODE) {
2731 string const temp = "toc";
2732 sgmlOpenTag(ofs, depth, temp);
2739 // environment tag closing
2740 for (; depth > par->params().depth(); --depth) {
2741 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2742 environment_stack[depth].erase();
2745 // write opening SGML tags
2746 switch (style.latextype) {
2747 case LATEX_PARAGRAPH:
2748 if (depth == par->params().depth()
2749 && !environment_stack[depth].empty()) {
2750 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2751 environment_stack[depth].erase();
2757 sgmlOpenTag(ofs, depth, style.latexname());
2763 _("Error : Wrong depth for"
2764 " LatexType Command.\n"));
2766 if (!environment_stack[depth].empty()) {
2767 sgmlCloseTag(ofs, depth,
2768 environment_stack[depth]);
2772 environment_stack[depth].erase();
2773 sgmlOpenTag(ofs, depth, style.latexname());
2776 case LATEX_ENVIRONMENT:
2777 case LATEX_ITEM_ENVIRONMENT:
2778 if (depth == par->params().depth()
2779 && environment_stack[depth] != style.latexname()) {
2780 sgmlCloseTag(ofs, depth,
2781 environment_stack[depth]);
2782 environment_stack[depth].erase();
2784 if (depth < par->params().depth()) {
2785 depth = par->params().depth();
2786 environment_stack[depth].erase();
2788 if (environment_stack[depth] != style.latexname()) {
2790 sgmlOpenTag(ofs, depth, "p");
2792 sgmlOpenTag(ofs, depth, style.latexname());
2794 if (environment_stack.size() == depth + 1)
2795 environment_stack.push_back("!-- --");
2796 environment_stack[depth] = style.latexname();
2799 if (style.latexparam() == "CDATA")
2802 if (style.latextype == LATEX_ENVIRONMENT) break;
2804 if (style.labeltype == LABEL_MANUAL)
2809 sgmlOpenTag(ofs, depth + 1, item_name);
2812 sgmlOpenTag(ofs, depth, style.latexname());
2816 simpleLinuxDocOnePar(ofs, par, depth);
2821 // write closing SGML tags
2822 switch (style.latextype) {
2825 case LATEX_ENVIRONMENT:
2826 case LATEX_ITEM_ENVIRONMENT:
2827 if (style.latexparam() == "CDATA")
2831 sgmlCloseTag(ofs, depth, style.latexname());
2837 for (int i=depth; i >= 0; --i)
2838 sgmlCloseTag(ofs, depth, environment_stack[i]);
2842 sgmlCloseTag(ofs, 0, top_element);
2846 // How to check for successful close
2848 // we want this to be true outside previews (for insetexternal)
2853 // checks, if newcol chars should be put into this line
2854 // writes newline, if necessary.
2857 void sgmlLineBreak(ostream & os, string::size_type & colcount,
2858 string::size_type newcol)
2861 if (colcount > lyxrc.ascii_linelen) {
2863 colcount = newcol; // assume write after this call
2878 string tag_name(PAR_TAG const & pt) {
2880 case NONE: return "!-- --";
2881 case TT: return "tt";
2882 case SF: return "sf";
2883 case BF: return "bf";
2884 case IT: return "it";
2885 case SL: return "sl";
2886 case EM: return "em";
2893 void operator|=(PAR_TAG & p1, PAR_TAG const & p2)
2895 p1 = static_cast<PAR_TAG>(p1 | p2);
2900 void reset(PAR_TAG & p1, PAR_TAG const & p2)
2902 p1 = static_cast<PAR_TAG>(p1 & ~p2);
2908 // Handle internal paragraph parsing -- layout already processed.
2909 void Buffer::simpleLinuxDocOnePar(ostream & os,
2911 Paragraph::depth_type /*depth*/)
2913 LyXLayout const & style =
2914 textclasslist[params.textclass][par->layout()];
2915 string::size_type char_line_count = 5; // Heuristic choice ;-)
2917 // gets paragraph main font
2920 if (style.labeltype == LABEL_MANUAL) {
2921 font_old = style.labelfont;
2924 font_old = style.font;
2928 LyXFont::FONT_FAMILY family_type = LyXFont::ROMAN_FAMILY;
2929 LyXFont::FONT_SERIES series_type = LyXFont::MEDIUM_SERIES;
2930 LyXFont::FONT_SHAPE shape_type = LyXFont::UP_SHAPE;
2933 stack<PAR_TAG> tag_state;
2934 // parsing main loop
2935 for (pos_type i = 0; i < par->size(); ++i) {
2937 PAR_TAG tag_close = NONE;
2938 list < PAR_TAG > tag_open;
2940 LyXFont const font = par->getFont(params, i);
2942 if (font_old.family() != font.family()) {
2943 switch (family_type) {
2944 case LyXFont::SANS_FAMILY:
2947 case LyXFont::TYPEWRITER_FAMILY:
2954 family_type = font.family();
2956 switch (family_type) {
2957 case LyXFont::SANS_FAMILY:
2958 tag_open.push_back(SF);
2960 case LyXFont::TYPEWRITER_FAMILY:
2961 tag_open.push_back(TT);
2968 if (font_old.series() != font.series()) {
2969 switch (series_type) {
2970 case LyXFont::BOLD_SERIES:
2977 series_type = font.series();
2979 switch (series_type) {
2980 case LyXFont::BOLD_SERIES:
2981 tag_open.push_back(BF);
2989 if (font_old.shape() != font.shape()) {
2990 switch (shape_type) {
2991 case LyXFont::ITALIC_SHAPE:
2994 case LyXFont::SLANTED_SHAPE:
3001 shape_type = font.shape();
3003 switch (shape_type) {
3004 case LyXFont::ITALIC_SHAPE:
3005 tag_open.push_back(IT);
3007 case LyXFont::SLANTED_SHAPE:
3008 tag_open.push_back(SL);
3015 if (font_old.emph() != font.emph()) {
3016 if (font.emph() == LyXFont::ON) {
3017 tag_open.push_back(EM);
3026 list < PAR_TAG > temp;
3027 while (!tag_state.empty() && tag_close) {
3028 PAR_TAG k = tag_state.top();
3030 os << "</" << tag_name(k) << ">";
3037 for(list< PAR_TAG >::const_iterator j = temp.begin();
3038 j != temp.end(); ++j) {
3040 os << "<" << tag_name(*j) << ">";
3043 for(list< PAR_TAG >::const_iterator j = tag_open.begin();
3044 j != tag_open.end(); ++j) {
3046 os << "<" << tag_name(*j) << ">";
3049 char c = par->getChar(i);
3051 if (c == Paragraph::META_INSET) {
3052 Inset * inset = par->getInset(i);
3053 inset->linuxdoc(this, os);
3058 if (style.latexparam() == "CDATA") {
3059 // "TeX"-Mode on == > SGML-Mode on.
3065 if (par->sgmlConvertChar(c, sgml_string)
3066 && !style.free_spacing && !par->isFreeSpacing())
3068 // in freespacing mode, spaces are
3069 // non-breaking characters
3070 if (desc_on) {// if char is ' ' then...
3073 sgmlLineBreak(os, char_line_count, 6);
3077 sgmlLineBreak(os, char_line_count, 1);
3082 char_line_count += sgml_string.length();
3088 while (!tag_state.empty()) {
3089 os << "</" << tag_name(tag_state.top()) << ">";
3093 // resets description flag correctly
3095 // <tag> not closed...
3096 sgmlLineBreak(os, char_line_count, 6);
3102 // Print an error message.
3103 void Buffer::sgmlError(Paragraph * /*par*/, int /*pos*/,
3104 string const & /*message*/) const
3106 #warning This is wrong we cannot insert an inset like this!!!
3107 // I guess this was Jose' so I explain you more or less why this
3108 // is wrong. This way you insert something in the paragraph and
3109 // don't tell it to LyXText (row rebreaking and undo handling!!!)
3110 // I deactivate this code, have a look at BufferView::insertErrors
3111 // how you should do this correctly! (Jug 20020315)
3113 // insert an error marker in text
3114 InsetError * new_inset = new InsetError(message);
3115 par->insertInset(pos, new_inset, LyXFont(LyXFont::ALL_INHERIT,
3121 void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
3123 ofstream ofs(fname.c_str());
3125 Alert::alert(_("LYX_ERROR:"), _("Cannot write file"), fname);
3129 Paragraph * par = paragraph;
3131 niceFile = nice; // this will be used by Insetincludes.
3133 LaTeXFeatures features(params);
3138 LyXTextClass const & tclass = textclasslist[params.textclass];
3139 string top_element = tclass.latexname();
3142 ofs << "<!DOCTYPE " << top_element
3143 << " PUBLIC \"-//OASIS//DTD DocBook V4.1//EN\"";
3145 string preamble = params.preamble;
3146 const string name = nice ? ChangeExtension(filename_, ".sgml")
3148 preamble += features.getIncludedFiles(name);
3149 preamble += features.getLyXSGMLEntities();
3151 if (!preamble.empty()) {
3152 ofs << "\n [ " << preamble << " ]";
3157 string top = top_element;
3159 top += params.language->code();
3162 if (!params.options.empty()) {
3164 top += params.options;
3166 sgmlOpenTag(ofs, 0, top);
3168 ofs << "<!-- DocBook file was created by " << lyx_docversion
3169 << "\n See http://www.lyx.org/ for more information -->\n";
3171 vector<string> environment_stack(10);
3172 vector<string> environment_inner(10);
3173 vector<string> command_stack(10);
3175 bool command_flag = false;
3176 Paragraph::depth_type command_depth = 0;
3177 Paragraph::depth_type command_base = 0;
3178 Paragraph::depth_type cmd_depth = 0;
3179 Paragraph::depth_type depth = 0; // paragraph depth
3182 string command_name;
3188 int desc_on = 0; // description mode
3190 LyXLayout const & style = tclass[par->layout()];
3192 // environment tag closing
3193 for (; depth > par->params().depth(); --depth) {
3194 if (environment_inner[depth] != "!-- --") {
3195 item_name = "listitem";
3196 sgmlCloseTag(ofs, command_depth + depth,
3198 if (environment_inner[depth] == "varlistentry")
3199 sgmlCloseTag(ofs, depth+command_depth,
3200 environment_inner[depth]);
3202 sgmlCloseTag(ofs, depth + command_depth,
3203 environment_stack[depth]);
3204 environment_stack[depth].erase();
3205 environment_inner[depth].erase();
3208 if (depth == par->params().depth()
3209 && environment_stack[depth] != style.latexname()
3210 && !environment_stack[depth].empty()) {
3211 if (environment_inner[depth] != "!-- --") {
3212 item_name= "listitem";
3213 sgmlCloseTag(ofs, command_depth+depth,
3215 if (environment_inner[depth] == "varlistentry")
3217 depth + command_depth,
3218 environment_inner[depth]);
3221 sgmlCloseTag(ofs, depth + command_depth,
3222 environment_stack[depth]);
3224 environment_stack[depth].erase();
3225 environment_inner[depth].erase();
3228 // Write opening SGML tags.
3229 switch (style.latextype) {
3230 case LATEX_PARAGRAPH:
3231 sgmlOpenTag(ofs, depth + command_depth,
3238 _("Error : Wrong depth for "
3239 "LatexType Command.\n"));
3241 command_name = style.latexname();
3243 sgmlparam = style.latexparam();
3244 c_params = split(sgmlparam, c_depth,'|');
3246 cmd_depth = lyx::atoi(c_depth);
3249 if (cmd_depth < command_base) {
3250 for (Paragraph::depth_type j = command_depth;
3251 j >= command_base; --j) {
3252 sgmlCloseTag(ofs, j, command_stack[j]);
3255 command_depth = command_base = cmd_depth;
3256 } else if (cmd_depth <= command_depth) {
3257 for (int j = command_depth;
3258 j >= int(cmd_depth); --j) {
3259 sgmlCloseTag(ofs, j, command_stack[j]);
3262 command_depth = cmd_depth;
3264 command_depth = cmd_depth;
3266 command_depth = command_base = cmd_depth;
3267 command_flag = true;
3269 if (command_stack.size() == command_depth + 1)
3270 command_stack.push_back(string());
3271 command_stack[command_depth] = command_name;
3273 // treat label as a special case for
3274 // more WYSIWYM handling.
3275 // This is a hack while paragraphs can't have
3276 // attributes, like id in this case.
3277 if (par->isInset(0)) {
3278 Inset * inset = par->getInset(0);
3279 Inset::Code lyx_code = inset->lyxCode();
3280 if (lyx_code == Inset::LABEL_CODE) {
3281 command_name += " id=\"";
3282 command_name += (static_cast<InsetCommand *>(inset))->getContents();
3283 command_name += "\"";
3288 sgmlOpenTag(ofs, depth + command_depth, command_name);
3289 if (c_params.empty())
3290 item_name = "title";
3292 item_name = c_params;
3293 sgmlOpenTag(ofs, depth + 1 + command_depth, item_name);
3296 case LATEX_ENVIRONMENT:
3297 case LATEX_ITEM_ENVIRONMENT:
3298 if (depth < par->params().depth()) {
3299 depth = par->params().depth();
3300 environment_stack[depth].erase();
3303 if (environment_stack[depth] != style.latexname()) {
3304 if (environment_stack.size() == depth + 1) {
3305 environment_stack.push_back("!-- --");
3306 environment_inner.push_back("!-- --");
3308 environment_stack[depth] = style.latexname();
3309 environment_inner[depth] = "!-- --";
3310 sgmlOpenTag(ofs, depth + command_depth,
3311 environment_stack[depth]);
3313 if (environment_inner[depth] != "!-- --") {
3314 item_name= "listitem";
3316 command_depth + depth,
3318 if (environment_inner[depth] == "varlistentry")
3320 depth + command_depth,
3321 environment_inner[depth]);
3325 if (style.latextype == LATEX_ENVIRONMENT) {
3326 if (!style.latexparam().empty()) {
3327 if (style.latexparam() == "CDATA")
3330 sgmlOpenTag(ofs, depth + command_depth,
3331 style.latexparam());
3336 desc_on = (style.labeltype == LABEL_MANUAL);
3339 environment_inner[depth]= "varlistentry";
3341 environment_inner[depth]= "listitem";
3343 sgmlOpenTag(ofs, depth + 1 + command_depth,
3344 environment_inner[depth]);
3348 sgmlOpenTag(ofs, depth + 1 + command_depth,
3352 sgmlOpenTag(ofs, depth + 1 + command_depth,
3357 sgmlOpenTag(ofs, depth + command_depth,
3362 simpleDocBookOnePar(ofs, par, desc_on, depth+1+command_depth);
3366 // write closing SGML tags
3367 switch (style.latextype) {
3369 if (c_params.empty())
3373 sgmlCloseTag(ofs, depth + command_depth, end_tag);
3375 case LATEX_ENVIRONMENT:
3376 if (!style.latexparam().empty()) {
3377 if (style.latexparam() == "CDATA")
3380 sgmlCloseTag(ofs, depth + command_depth,
3381 style.latexparam());
3384 case LATEX_ITEM_ENVIRONMENT:
3385 if (desc_on == 1) break;
3387 sgmlCloseTag(ofs, depth + 1 + command_depth, end_tag);
3389 case LATEX_PARAGRAPH:
3390 sgmlCloseTag(ofs, depth + command_depth, style.latexname());
3393 sgmlCloseTag(ofs, depth + command_depth, style.latexname());
3399 for (int d = depth; d >= 0; --d) {
3400 if (!environment_stack[depth].empty()) {
3401 if (environment_inner[depth] != "!-- --") {
3402 item_name = "listitem";
3403 sgmlCloseTag(ofs, command_depth + depth,
3405 if (environment_inner[depth] == "varlistentry")
3406 sgmlCloseTag(ofs, depth + command_depth,
3407 environment_inner[depth]);
3410 sgmlCloseTag(ofs, depth + command_depth,
3411 environment_stack[depth]);
3415 for (int j = command_depth; j >= 0 ; --j)
3416 if (!command_stack[j].empty()) {
3417 sgmlCloseTag(ofs, j, command_stack[j]);
3422 sgmlCloseTag(ofs, 0, top_element);
3425 // How to check for successful close
3427 // we want this to be true outside previews (for insetexternal)
3432 void Buffer::simpleDocBookOnePar(ostream & os,
3433 Paragraph * par, int & desc_on,
3434 Paragraph::depth_type depth) const
3436 bool emph_flag = false;
3438 LyXLayout const & style =
3439 textclasslist[params.textclass][par->layout()];
3441 LyXFont font_old = style.labeltype == LABEL_MANUAL ? style.labelfont : style.font;
3443 int char_line_count = depth;
3444 //if (!style.free_spacing)
3445 // os << string(depth,' ');
3447 // parsing main loop
3448 for (pos_type i = 0; i < par->size(); ++i) {
3449 LyXFont font = par->getFont(params, i);
3451 // handle <emphasis> tag
3452 if (font_old.emph() != font.emph()) {
3453 if (font.emph() == LyXFont::ON) {
3454 if(style.latexparam() == "CDATA")
3457 if(style.latexparam() == "CDATA")
3461 if(style.latexparam() == "CDATA")
3463 os << "</emphasis>";
3464 if(style.latexparam() == "CDATA")
3471 if (par->isInset(i)) {
3472 Inset * inset = par->getInset(i);
3473 // don't print the inset in position 0 if desc_on == 3 (label)
3474 if ( i || desc_on != 3) {
3475 if(style.latexparam() == "CDATA")
3477 inset->docbook(this, os);
3478 if(style.latexparam() == "CDATA")
3482 char c = par->getChar(i);
3484 par->sgmlConvertChar(c, sgml_string);
3486 if (style.pass_thru) {
3488 } else if (style.free_spacing || par->isFreeSpacing() || c != ' ') {
3490 } else if (desc_on ==1) {
3492 os << "\n</term><listitem><para>";
3502 if(style.latexparam() == "CDATA")
3504 os << "</emphasis>";
3505 if(style.latexparam() == "CDATA")
3509 // resets description flag correctly
3511 // <term> not closed...
3512 os << "</term>\n<listitem><para> </para>";
3514 if (style.free_spacing) os << '\n';
3518 // This should be enabled when the Chktex class is implemented. (Asger)
3519 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
3520 // Other flags: -wall -v0 -x
3521 int Buffer::runChktex()
3523 if (!users->text) return 0;
3525 users->owner()->prohibitInput();
3527 // get LaTeX-Filename
3528 string const name = getLatexName();
3529 string path = filePath();
3531 string const org_path = path;
3532 if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
3536 Path p(path); // path to LaTeX file
3537 users->owner()->message(_("Running chktex..."));
3539 // Remove all error insets
3540 bool const removedErrorInsets = users->removeAutoInsets();
3542 // Generate the LaTeX file if neccessary
3543 makeLaTeXFile(name, org_path, false);
3546 Chktex chktex(lyxrc.chktex_command, name, filePath());
3547 int res = chktex.run(terr); // run chktex
3550 Alert::alert(_("chktex did not work!"),
3551 _("Could not run with file:"), name);
3552 } else if (res > 0) {
3553 // Insert all errors as errors boxes
3554 users->insertErrors(terr);
3557 // if we removed error insets before we ran chktex or if we inserted
3558 // error insets after we ran chktex, this must be run:
3559 if (removedErrorInsets || res) {
3563 users->owner()->allowInput();
3569 void Buffer::validate(LaTeXFeatures & features) const
3571 Paragraph * par = paragraph;
3572 LyXTextClass const & tclass = textclasslist[params.textclass];
3574 // AMS Style is at document level
3575 if (params.use_amsmath || tclass.provides(LyXTextClass::amsmath))
3576 features.require("amsmath");
3579 // We don't use "lyxerr.debug" because of speed. (Asger)
3580 if (lyxerr.debugging(Debug::LATEX))
3581 lyxerr << "Paragraph: " << par << endl;
3583 // Now just follow the list of paragraphs and run
3584 // validate on each of them.
3585 par->validate(features);
3587 // and then the next paragraph
3591 // the bullet shapes are buffer level not paragraph level
3592 // so they are tested here
3593 for (int i = 0; i < 4; ++i) {
3594 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
3595 int const font = params.user_defined_bullets[i].getFont();
3597 int const c = params
3598 .user_defined_bullets[i]
3605 features.require("latexsym");
3607 } else if (font == 1) {
3608 features.require("amssymb");
3609 } else if ((font >= 2 && font <= 5)) {
3610 features.require("pifont");
3615 if (lyxerr.debugging(Debug::LATEX)) {
3616 features.showStruct();
3621 // This function should be in Buffer because it's a buffer's property (ale)
3622 string const Buffer::getIncludeonlyList(char delim)
3625 for (inset_iterator it = inset_iterator_begin();
3626 it != inset_iterator_end(); ++it) {
3627 if ((*it)->lyxCode() == Inset::INCLUDE_CODE) {
3628 InsetInclude * insetinc =
3629 static_cast<InsetInclude *>(*it);
3630 if (insetinc->isIncludeOnly()) {
3633 lst += insetinc->getRelFileBaseName();
3637 lyxerr[Debug::INFO] << "Includeonly(" << lst << ')' << endl;
3642 vector<string> const Buffer::getLabelList()
3644 /// if this is a child document and the parent is already loaded
3645 /// Use the parent's list instead [ale990407]
3646 if (!params.parentname.empty()
3647 && bufferlist.exists(params.parentname)) {
3648 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3650 return tmp->getLabelList();
3653 vector<string> label_list;
3654 for (inset_iterator it = inset_iterator_begin();
3655 it != inset_iterator_end(); ++it) {
3656 vector<string> const l = (*it)->getLabelList();
3657 label_list.insert(label_list.end(), l.begin(), l.end());
3663 Buffer::Lists const Buffer::getLists() const
3666 Paragraph * par = paragraph;
3668 LyXTextClass const & textclass = textclasslist[params.textclass];
3669 bool found = textclass.hasLayout("Caption");
3670 string const layout("Caption");
3673 char const labeltype = textclass[par->layout()].labeltype;
3675 if (labeltype >= LABEL_COUNTER_CHAPTER
3676 && labeltype <= LABEL_COUNTER_CHAPTER + params.tocdepth) {
3677 // insert this into the table of contents
3678 SingleList & item = l["TOC"];
3681 textclass.maxcounter());
3682 item.push_back(TocItem(par, depth, par->asString(this, true)));
3684 // For each paragrph, traverse its insets and look for
3688 Paragraph::inset_iterator it =
3689 par->inset_iterator_begin();
3690 Paragraph::inset_iterator end =
3691 par->inset_iterator_end();
3693 for (; it != end; ++it) {
3694 if ((*it)->lyxCode() == Inset::FLOAT_CODE) {
3696 static_cast<InsetFloat*>(*it);
3698 string const type = il->type();
3700 // Now find the caption in the float...
3701 // We now tranverse the paragraphs of
3703 Paragraph * tmp = il->inset.paragraph();
3705 if (tmp->layout() == layout) {
3706 SingleList & item = l[type];
3708 tostr(item.size()+1) + ". " + tmp->asString(this, false);
3709 item.push_back(TocItem(tmp, 0 , str));
3716 lyxerr << "Caption not found" << endl;
3725 // This is also a buffer property (ale)
3726 vector<pair<string, string> > const Buffer::getBibkeyList() const
3728 typedef pair<string, string> StringPair;
3729 /// if this is a child document and the parent is already loaded
3730 /// Use the parent's list instead [ale990412]
3731 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3732 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
3734 return tmp->getBibkeyList();
3737 vector<StringPair> keys;
3738 Paragraph * par = paragraph;
3741 string const key = par->bibkey->getContents();
3742 string const opt = par->bibkey->getOptions();
3743 string const ref = par->asString(this, false);
3744 string const info = opt + "TheBibliographyRef" + ref;
3746 keys.push_back(StringPair(key, info));
3751 // Might be either using bibtex or a child has bibliography
3753 for (inset_iterator it = inset_const_iterator_begin();
3754 it != inset_const_iterator_end(); ++it) {
3755 // Search for Bibtex or Include inset
3756 if ((*it)->lyxCode() == Inset::BIBTEX_CODE) {
3757 vector<StringPair> tmp =
3758 static_cast<InsetBibtex*>(*it)->getKeys(this);
3759 keys.insert(keys.end(), tmp.begin(), tmp.end());
3760 } else if ((*it)->lyxCode() == Inset::INCLUDE_CODE) {
3761 vector<StringPair> const tmp =
3762 static_cast<InsetInclude*>(*it)->getKeys();
3763 keys.insert(keys.end(), tmp.begin(), tmp.end());
3772 bool Buffer::isDepClean(string const & name) const
3774 DEPCLEAN * item = dep_clean;
3775 while (item && item->master != name)
3777 if (!item) return true;
3782 void Buffer::markDepClean(string const & name)
3785 dep_clean = new DEPCLEAN;
3786 dep_clean->clean = true;
3787 dep_clean->master = name;
3788 dep_clean->next = 0;
3790 DEPCLEAN * item = dep_clean;
3791 while (item && item->master != name)
3796 item = new DEPCLEAN;
3798 item->master = name;
3805 bool Buffer::dispatch(string const & command)
3807 // Split command string into command and argument
3809 string line = frontStrip(command);
3810 string const arg = strip(frontStrip(split(line, cmd, ' ')));
3812 return dispatch(lyxaction.LookupFunc(cmd), arg);
3816 bool Buffer::dispatch(int action, string const & argument)
3818 bool dispatched = true;
3821 Exporter::Export(this, argument, false);
3831 void Buffer::resizeInsets(BufferView * bv)
3833 /// then remove all LyXText in text-insets
3834 Paragraph * par = paragraph;
3835 for (; par; par = par->next()) {
3836 par->resizeInsetsLyXText(bv);
3841 void Buffer::redraw()
3848 void Buffer::changeLanguage(Language const * from, Language const * to)
3851 ParIterator end = par_iterator_end();
3852 for (ParIterator it = par_iterator_begin(); it != end; ++it)
3853 (*it)->changeLanguage(params, from, to);
3857 bool Buffer::isMultiLingual()
3859 ParIterator end = par_iterator_end();
3860 for (ParIterator it = par_iterator_begin(); it != end; ++it)
3861 if ((*it)->isMultiLingual(params))
3868 Buffer::inset_iterator::inset_iterator(Paragraph * paragraph, pos_type pos)
3871 it = par->InsetIterator(pos);
3872 if (it == par->inset_iterator_end()) {
3879 void Buffer::inset_iterator::setParagraph()
3882 it = par->inset_iterator_begin();
3883 if (it != par->inset_iterator_end())
3888 // We maintain an invariant that whenever par = 0 then it = 0
3892 Inset * Buffer::getInsetFromID(int id_arg) const
3894 for (inset_iterator it = inset_const_iterator_begin();
3895 it != inset_const_iterator_end(); ++it)
3897 if ((*it)->id() == id_arg)
3899 Inset * in = (*it)->getInsetFromID(id_arg);
3907 Paragraph * Buffer::getParFromID(int id) const
3909 if (id < 0) return 0;
3910 Paragraph * par = paragraph;
3912 if (par->id() == id) {
3915 Paragraph * tmp = par->getParFromID(id);
3925 ParIterator Buffer::par_iterator_begin()
3927 return ParIterator(paragraph);
3931 ParIterator Buffer::par_iterator_end()
3933 return ParIterator();