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"
35 #include "LaTeXFeatures.h"
42 #include "converter.h"
43 #include "BufferView.h"
44 #include "ParagraphParameters.h"
45 #include "iterators.h"
46 #include "lyxtextclasslist.h"
48 #include "paragraph_funcs.h"
50 #include "frontends/LyXView.h"
52 #include "mathed/formulamacro.h"
53 #include "mathed/formula.h"
55 #include "insets/inset.h"
56 #include "insets/inseterror.h"
57 #include "insets/insetlabel.h"
58 #include "insets/insetref.h"
59 #include "insets/inseturl.h"
60 #include "insets/insetnote.h"
61 #include "insets/insetquotes.h"
62 #include "insets/insetlatexaccent.h"
63 #include "insets/insetbib.h"
64 #include "insets/insetcite.h"
65 #include "insets/insetexternal.h"
66 #include "insets/insetindex.h"
67 #include "insets/insetinclude.h"
68 #include "insets/insettoc.h"
69 #include "insets/insetparent.h"
70 #include "insets/insetspecialchar.h"
71 #include "insets/insettext.h"
72 #include "insets/insetert.h"
73 #include "insets/insetgraphics.h"
74 #include "insets/insetfoot.h"
75 #include "insets/insetmarginal.h"
76 #include "insets/insetminipage.h"
77 #include "insets/insetfloat.h"
78 #include "insets/insettabular.h"
80 #include "insets/insettheorem.h"
81 #include "insets/insetlist.h"
83 #include "insets/insetcaption.h"
84 #include "insets/insetfloatlist.h"
86 #include "frontends/Dialogs.h"
87 #include "frontends/Alert.h"
89 #include "graphics/Previews.h"
91 #include "support/textutils.h"
92 #include "support/filetools.h"
93 #include "support/path.h"
94 #include "support/os.h"
95 #include "support/lyxlib.h"
96 #include "support/FileInfo.h"
97 #include "support/lyxmanip.h"
98 #include "support/lyxalgo.h" // for lyx::count
100 #include <boost/bind.hpp>
101 #include <boost/tuple/tuple.hpp>
113 #include <sys/types.h>
120 #ifndef CXX_GLOBAL_CSTD
132 using std::make_pair;
142 using lyx::textclass_type;
144 // all these externs should eventually be removed.
145 extern BufferList bufferlist;
149 const int LYX_FORMAT = 220;
153 Buffer::Buffer(string const & file, bool ronly)
154 : niceFile(true), lyx_clean(true), bak_clean(true),
155 unnamed(false), dep_clean(0), read_only(ronly),
156 filename_(file), users(0), ctrs(new Counters)
158 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
160 filepath_ = OnlyPath(file);
164 // read_only = ronly;
168 if (read_only || lyxrc.use_tempdir) {
169 tmppath = CreateBufferTmpDir();
178 lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
179 // here the buffer should take care that it is
180 // saved properly, before it goes into the void.
182 // make sure that views using this buffer
187 if (!tmppath.empty()) {
188 DestroyBufferTmpDir(tmppath);
193 // Remove any previewed LaTeX snippets assocoated with this buffer.
194 grfx::Previews::get().removeLoader(this);
198 string const Buffer::getLatexName(bool no_path) const
200 string const name = ChangeExtension(MakeLatexName(fileName()), ".tex");
202 return OnlyFilename(name);
208 pair<Buffer::LogType, string> const Buffer::getLogName(void) const
210 string const filename = getLatexName(false);
212 if (filename.empty())
213 return make_pair(Buffer::latexlog, string());
215 string path = OnlyPath(filename);
217 if (lyxrc.use_tempdir || !IsDirWriteable(path))
220 string const fname = AddName(path,
221 OnlyFilename(ChangeExtension(filename,
224 AddName(path, OnlyFilename(
225 ChangeExtension(filename,
226 formats.extension("literate") + ".out")));
228 // If no Latex log or Build log is newer, show Build log
230 FileInfo const f_fi(fname);
231 FileInfo const b_fi(bname);
234 (!f_fi.exist() || f_fi.getModificationTime() < b_fi.getModificationTime())) {
235 lyxerr[Debug::FILES] << "Log name calculated as : " << bname << endl;
236 return make_pair(Buffer::buildlog, bname);
238 lyxerr[Debug::FILES] << "Log name calculated as : " << fname << endl;
239 return make_pair(Buffer::latexlog, fname);
243 void Buffer::setReadonly(bool flag)
245 if (read_only != flag) {
248 users->owner()->getDialogs().updateBufferDependent(false);
253 /// Update window titles of all users
254 // Should work on a list
255 void Buffer::updateTitles() const
258 users->owner()->updateWindowTitle();
262 /// Reset autosave timer of all users
263 // Should work on a list
264 void Buffer::resetAutosaveTimers() const
267 users->owner()->resetAutosaveTimer();
271 void Buffer::setFileName(string const & newfile)
273 filename_ = MakeAbsPath(newfile);
274 filepath_ = OnlyPath(filename_);
275 setReadonly(IsFileWriteable(filename_) == 0);
280 // We'll remove this later. (Lgb)
283 string last_inset_read;
285 #ifndef NO_COMPABILITY
288 ErtComp() : active(false), fromlayout(false), in_tabular(false) {
297 std::stack<ErtComp> ert_stack;
302 #warning And _why_ is this here? (Lgb)
310 // candidate for move to BufferView
311 // (at least some parts in the beginning of the func)
314 // changed to be public and have one parameter
315 // if par = 0 normal behavior
316 // else insert behavior
317 // Returns false if "\the_end" is not read for formats >= 2.13. (Asger)
318 bool Buffer::readLyXformat2(LyXLex & lex, Paragraph * par)
322 #ifndef NO_COMPABILITY
323 ert_comp.contents.erase();
324 ert_comp.active = false;
325 ert_comp.fromlayout = false;
326 ert_comp.in_tabular = false;
329 Paragraph::depth_type depth = 0;
330 bool the_end_read = false;
332 Paragraph * first_par = 0;
333 LyXFont font(LyXFont::ALL_INHERIT, params.language);
336 if (file_format < 216 && params.language->lang() == "hebrew")
337 font.setLanguage(default_language);
342 par->layout(params.getLyXTextClass().defaultLayout());
344 // We are inserting into an existing document
345 users->text->breakParagraph(users);
346 first_par = users->text->ownerParagraph();
349 // We don't want to adopt the parameters from the
350 // document we insert, so we skip until the text begins:
353 string const pretoken = lex.getString();
354 if (pretoken == "\\layout") {
355 lex.pushToken(pretoken);
363 string const token = lex.getString();
365 if (token.empty()) continue;
367 lyxerr[Debug::PARSER] << "Handling token: `"
368 << token << "'" << endl;
371 parseSingleLyXformat2Token(lex, par, first_par,
379 paragraphs.set(first_par);
381 if (unknown_layouts > 0) {
382 string s = _("Couldn't set the layout for ");
383 if (unknown_layouts == 1) {
384 s += _("one paragraph");
386 s += tostr(unknown_layouts);
387 s += _(" paragraphs");
389 Alert::alert(_("Textclass Loading Error!"), s,
390 _("When reading " + fileName()));
393 if (unknown_tokens > 0) {
394 string s = _("Encountered ");
395 if (unknown_tokens == 1) {
396 s += _("one unknown token");
398 s += tostr(unknown_tokens);
399 s += _(" unknown tokens");
401 Alert::alert(_("Textclass Loading Error!"), s,
402 _("When reading " + fileName()));
409 #ifndef NO_COMPABILITY
411 Inset * Buffer::isErtInset(Paragraph * par, int pos) const
414 if ((par->getChar(pos) == Paragraph::META_INSET) &&
415 (inset = par->getInset(pos)) &&
416 (inset->lyxCode() == Inset::ERT_CODE))
423 void Buffer::insertErtContents(Paragraph * par, int & pos, bool set_inactive)
425 if (ert_comp.contents.find_first_not_of(' ') != string::npos) {
426 // we only skip completely empty ERT (only spaces) otherwise
427 // we have to insert it as is.
428 string str(ert_comp.contents);
429 lyxerr[Debug::INSETS] << "ERT contents:\n'"
430 << str << "'" << endl;
431 // check if we have already an ert inset a position earlier
432 // if this is the case then we should insert the contents
433 // inside the other ertinset as it is stupid to have various
436 if ((pos > 0) && (inset=isErtInset(par, pos-1))) {
437 // get the last paragraph from the inset before
438 Paragraph * last = inset->firstParagraph();
441 // create the new paragraph after the last one
442 Paragraph * par = new Paragraph(last);
443 par->layout(params.getLyXTextClass().defaultLayoutName());
444 par->setInsetOwner(last->inInset());
446 LyXFont font(LyXFont::ALL_INHERIT, params.language);
447 string::const_iterator cit = str.begin();
448 string::const_iterator end = str.end();
450 for (; cit != end; ++cit) {
451 par->insertChar(pos++, *cit, font);
455 new InsetERT(params, params.language, str, true);
456 par->insertInset(pos++, inset, ert_comp.font);
459 ert_comp.contents.erase();
460 ert_comp.fromlayout = false;
462 ert_comp.active = false;
469 Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
470 Paragraph *& first_par,
471 string const & token, int & pos,
472 Paragraph::depth_type & depth,
476 bool the_end_read = false;
477 #ifndef NO_COMPABILITY
478 #ifndef NO_PEXTRA_REALLY
479 // This is super temporary but is needed to get the compability
480 // mode for minipages work correctly together with new tabulars.
481 static int call_depth;
483 bool checkminipage = false;
484 static Paragraph * minipar = 0;
485 static Paragraph * parBeforeMinipage;
489 // The order of the tags tested may seem unnatural, but this
490 // has been done in order to reduce the number of string
491 // comparisons needed to recognize a given token. This leads
492 // on large documents like UserGuide to a reduction of a
494 if (token[0] != '\\') {
495 #ifndef NO_COMPABILITY
496 if (ert_comp.active) {
497 ert_comp.contents += token;
500 for (string::const_iterator cit = token.begin();
501 cit != token.end(); ++cit) {
502 par->insertChar(pos, (*cit), font);
505 #ifndef NO_COMPABILITY
508 } else if (token == "\\layout") {
509 #ifndef NO_COMPABILITY
510 bool old_fromlayout = ert_comp.fromlayout;
511 bool create_new_par = true;
512 ert_comp.in_tabular = false;
514 if (!par->size() && par->previous() &&
515 (par->previous()->size() == 1) &&
516 isErtInset(par->previous(), par->previous()->size()-1))
518 int p = par->previous()->size();
519 insertErtContents(par->previous(), p);
520 create_new_par = false;
522 insertErtContents(par, pos);
525 // reset the font as we start a new layout and if the font is
526 // not ALL_INHERIT,document_language then it will be set to the
527 // right values after this tag (Jug 20020420)
528 font = LyXFont(LyXFont::ALL_INHERIT, params.language);
531 if (file_format < 216 && params.language->lang() == "hebrew")
532 font.setLanguage(default_language);
536 string layoutname = lex.getString();
538 LyXTextClass const & tclass = params.getLyXTextClass();
540 if (layoutname.empty()) {
541 layoutname = tclass.defaultLayoutName();
543 #ifndef NO_COMPABILITY
544 if (compare_ascii_no_case(layoutname, "latex") == 0) {
545 ert_comp.active = true;
546 ert_comp.fromlayout = true;
547 ert_comp.font = font;
549 create_new_par = false;
552 bool hasLayout = tclass.hasLayout(layoutname);
554 lyxerr << "Layout '" << layoutname << "' does not"
555 << " exist in textclass '" << tclass.name()
557 lyxerr << "Trying to use default layout instead."
559 layoutname = tclass.defaultLayoutName();
563 // The is the compability reading of layout caption.
564 // It can be removed in LyX version 1.3.0. (Lgb)
565 if (compare_ascii_no_case(layoutname, "caption") == 0) {
566 // We expect that the par we are now working on is
567 // really inside a InsetText inside a InsetFloat.
568 // We also know that captions can only be
569 // one paragraph. (Lgb)
571 // We should now read until the next "\layout"
573 // This is probably not good enough, what if the
574 // caption is the last par in the document (Lgb)
575 istream & ist = lex.getStream();
581 if (prefixIs(line, "\\layout")) {
585 if (prefixIs(line, "\\begin_inset"))
587 if (prefixIs(line, "\\end_inset")) {
598 // Now we should have the whole layout in ss
599 // we should now be able to give this to the
601 ss << "\\end_inset\n";
603 // This seems like a bug in stringstream.
604 // We really should be able to use ss
606 istringstream is(ss.str());
608 tmplex.setStream(is);
609 Inset * inset = new InsetCaption;
610 inset->Read(this, tmplex);
611 par->InsertInset(pos, inset, font);
615 #ifndef NO_COMPABILITY
616 if (create_new_par) {
621 par = new Paragraph(par);
622 par->layout(params.getLyXTextClass().defaultLayout());
625 par->layout(params.getLyXTextClass()[layoutname]);
626 // Test whether the layout is obsolete.
627 LyXLayout_ptr const & layout = par->layout();
628 if (!layout->obsoleted_by().empty())
629 par->layout(params.getLyXTextClass()[layout->obsoleted_by()]);
630 par->params().depth(depth);
631 #ifndef NO_COMPABILITY
633 // we duplicate code here because it's easier to remove
634 // the code then of NO_COMPATIBILITY
635 par->layout(layoutname);
636 // Test whether the layout is obsolete.
637 LyXLayout_ptr const & layout =
638 params.getLyXTextClass()[par->layout()];
639 if (!layout->obsoleted_by().empty())
640 par->layout(layout->obsoleted_by());
641 par->params().depth(depth);
648 } else if (token == "\\end_inset") {
649 lyxerr << "Solitary \\end_inset. Missing \\begin_inset?.\n"
650 << "Last inset read was: " << last_inset_read
652 // Simply ignore this. The insets do not have
654 // But insets should read it, it is a part of
655 // the inset isn't it? Lgb.
656 } else if (token == "\\begin_inset") {
657 #ifndef NO_COMPABILITY
658 insertErtContents(par, pos, false);
659 ert_stack.push(ert_comp);
660 ert_comp = ErtComp();
662 readInset(lex, par, pos, font);
663 #ifndef NO_COMPABILITY
664 ert_comp = ert_stack.top();
666 insertErtContents(par, pos);
668 } else if (token == "\\family") {
670 font.setLyXFamily(lex.getString());
671 } else if (token == "\\series") {
673 font.setLyXSeries(lex.getString());
674 } else if (token == "\\shape") {
676 font.setLyXShape(lex.getString());
677 } else if (token == "\\size") {
679 font.setLyXSize(lex.getString());
680 #ifndef NO_COMPABILITY
681 } else if (token == "\\latex") {
683 string const tok = lex.getString();
684 if (tok == "no_latex") {
686 insertErtContents(par, pos);
687 } else if (tok == "latex") {
688 ert_comp.active = true;
689 ert_comp.font = font;
690 } else if (tok == "default") {
692 insertErtContents(par, pos);
694 lex.printError("Unknown LaTeX font flag "
698 } else if (token == "\\lang") {
700 string const tok = lex.getString();
701 Language const * lang = languages.getLanguage(tok);
703 font.setLanguage(lang);
705 font.setLanguage(params.language);
706 lex.printError("Unknown language `$$Token'");
708 } else if (token == "\\numeric") {
710 font.setNumber(font.setLyXMisc(lex.getString()));
711 } else if (token == "\\emph") {
713 font.setEmph(font.setLyXMisc(lex.getString()));
714 } else if (token == "\\bar") {
716 string const tok = lex.getString();
717 // This is dirty, but gone with LyX3. (Asger)
719 font.setUnderbar(LyXFont::ON);
720 else if (tok == "no")
721 font.setUnderbar(LyXFont::OFF);
722 else if (tok == "default")
723 font.setUnderbar(LyXFont::INHERIT);
725 lex.printError("Unknown bar font flag "
727 } else if (token == "\\noun") {
729 font.setNoun(font.setLyXMisc(lex.getString()));
730 } else if (token == "\\color") {
732 font.setLyXColor(lex.getString());
733 } else if (token == "\\SpecialChar") {
734 LyXLayout_ptr const & layout = par->layout();
736 // Insets don't make sense in a free-spacing context! ---Kayvan
737 if (layout->free_spacing || par->isFreeSpacing()) {
740 string next_token = lex.getString();
741 if (next_token == "\\-") {
742 par->insertChar(pos, '-', font);
743 } else if (next_token == "\\protected_separator"
744 || next_token == "~") {
745 par->insertChar(pos, ' ', font);
747 lex.printError("Token `$$Token' "
749 "paragraph layout!");
754 Inset * inset = new InsetSpecialChar;
755 inset->read(this, lex);
756 par->insertInset(pos, inset, font);
759 } else if (token == "\\i") {
760 Inset * inset = new InsetLatexAccent;
761 inset->read(this, lex);
762 par->insertInset(pos, inset, font);
764 } else if (token == "\\backslash") {
765 #ifndef NO_COMPABILITY
766 if (ert_comp.active) {
767 ert_comp.contents += "\\";
770 par->insertChar(pos, '\\', font);
772 #ifndef NO_COMPABILITY
775 #ifndef NO_COMPABILITY
776 } else if (token == "\\begin_float") {
777 insertErtContents(par, pos);
778 //insertErtContents(par, pos, false);
779 //ert_stack.push(ert_comp);
780 //ert_comp = ErtComp();
782 // This is the compability reader. It can be removed in
783 // LyX version 1.3.0. (Lgb)
785 string const tmptok = lex.getString();
786 //lyxerr << "old float: " << tmptok << endl;
789 stringstream old_float;
791 if (tmptok == "footnote") {
792 inset = new InsetFoot(params);
793 old_float << "collapsed true\n";
794 } else if (tmptok == "margin") {
795 inset = new InsetMarginal(params);
796 old_float << "collapsed true\n";
797 } else if (tmptok == "fig") {
798 inset = new InsetFloat(params, "figure");
799 old_float << "wide false\n"
800 << "collapsed false\n";
801 } else if (tmptok == "tab") {
802 inset = new InsetFloat(params, "table");
803 old_float << "wide false\n"
804 << "collapsed false\n";
805 } else if (tmptok == "alg") {
806 inset = new InsetFloat(params, "algorithm");
807 old_float << "wide false\n"
808 << "collapsed false\n";
809 } else if (tmptok == "wide-fig") {
810 inset = new InsetFloat(params, "figure");
811 //InsetFloat * tmp = new InsetFloat("figure");
814 old_float << "wide true\n"
815 << "collapsed false\n";
816 } else if (tmptok == "wide-tab") {
817 inset = new InsetFloat(params, "table");
818 //InsetFloat * tmp = new InsetFloat("table");
821 old_float << "wide true\n"
822 << "collapsed false\n";
826 #ifndef NO_PEXTRA_REALLY
829 return false; // no end read yet
832 // Here we need to check for \end_deeper and handle that
833 // before we do the footnote parsing.
834 // This _is_ a hack! (Lgb)
837 string const tmp = lex.getString();
838 if (tmp == "\\end_deeper") {
839 //lyxerr << "\\end_deeper caught!" << endl;
841 lex.printError("\\end_deeper: "
842 "depth is already null");
847 old_float << tmp << ' ';
852 old_float << lex.getLongString("\\end_float")
853 << "\n\\end_inset\n";
854 //lyxerr << "Float Body:\n" << old_float.str() << endl;
855 // That this does not work seems like a bug
856 // in stringstream. (Lgb)
857 istringstream istr(old_float.str());
859 nylex.setStream(istr);
860 inset->read(this, nylex);
861 par->insertInset(pos, inset, font);
863 insertErtContents(par, pos);
865 // we have to reset the font as in the old format after a float
866 // the font was automatically reset!
867 font = LyXFont(LyXFont::ALL_INHERIT, params.language);
869 } else if (token == "\\begin_deeper") {
871 } else if (token == "\\end_deeper") {
873 lex.printError("\\end_deeper: "
874 "depth is already null");
878 } else if (token == "\\begin_preamble") {
879 params.readPreamble(lex);
880 } else if (token == "\\textclass") {
882 pair<bool, textclass_type> pp =
883 textclasslist.NumberOfClass(lex.getString());
885 params.textclass = pp.second;
887 Alert::alert(string(_("Textclass error")),
888 string(_("The document uses an unknown textclass \"")) +
889 lex.getString() + string("\"."),
890 string(_("LyX will not be able to produce output correctly.")));
891 params.textclass = 0;
893 if (!params.getLyXTextClass().load()) {
894 // if the textclass wasn't loaded properly
895 // we need to either substitute another
896 // or stop loading the file.
897 // I can substitute but I don't see how I can
898 // stop loading... ideas?? ARRae980418
899 Alert::alert(_("Textclass Loading Error!"),
900 string(_("Can't load textclass ")) +
901 params.getLyXTextClass().name(),
902 _("-- substituting default"));
903 params.textclass = 0;
905 } else if (token == "\\options") {
907 params.options = lex.getString();
908 } else if (token == "\\language") {
909 params.readLanguage(lex);
910 } else if (token == "\\fontencoding") {
912 } else if (token == "\\inputencoding") {
914 params.inputenc = lex.getString();
915 } else if (token == "\\graphics") {
916 params.readGraphicsDriver(lex);
917 } else if (token == "\\fontscheme") {
919 params.fonts = lex.getString();
920 } else if (token == "\\noindent") {
921 par->params().noindent(true);
922 } else if (token == "\\leftindent") {
924 LyXLength value(lex.getString());
925 par->params().leftIndent(value);
926 } else if (token == "\\fill_top") {
927 par->params().spaceTop(VSpace(VSpace::VFILL));
928 } else if (token == "\\fill_bottom") {
929 par->params().spaceBottom(VSpace(VSpace::VFILL));
930 } else if (token == "\\line_top") {
931 par->params().lineTop(true);
932 } else if (token == "\\line_bottom") {
933 par->params().lineBottom(true);
934 } else if (token == "\\pagebreak_top") {
935 par->params().pagebreakTop(true);
936 } else if (token == "\\pagebreak_bottom") {
937 par->params().pagebreakBottom(true);
938 } else if (token == "\\start_of_appendix") {
939 par->params().startOfAppendix(true);
940 } else if (token == "\\paragraph_separation") {
941 int tmpret = lex.findToken(string_paragraph_separation);
944 params.paragraph_separation =
945 static_cast<BufferParams::PARSEP>(tmpret);
946 } else if (token == "\\defskip") {
948 params.defskip = VSpace(lex.getString());
949 #ifndef NO_COMPABILITY
950 } else if (token == "\\epsfig") { // obsolete
951 // Indeed it is obsolete, but we HAVE to be backwards
952 // compatible until 0.14, because otherwise all figures
953 // in existing documents are irretrivably lost. (Asger)
954 params.readGraphicsDriver(lex);
956 } else if (token == "\\quotes_language") {
957 int tmpret = lex.findToken(string_quotes_language);
960 InsetQuotes::quote_language tmpl =
961 InsetQuotes::EnglishQ;
964 tmpl = InsetQuotes::EnglishQ;
967 tmpl = InsetQuotes::SwedishQ;
970 tmpl = InsetQuotes::GermanQ;
973 tmpl = InsetQuotes::PolishQ;
976 tmpl = InsetQuotes::FrenchQ;
979 tmpl = InsetQuotes::DanishQ;
982 params.quotes_language = tmpl;
983 } else if (token == "\\quotes_times") {
985 switch (lex.getInteger()) {
987 params.quotes_times = InsetQuotes::SingleQ;
990 params.quotes_times = InsetQuotes::DoubleQ;
993 } else if (token == "\\papersize") {
994 int tmpret = lex.findToken(string_papersize);
998 params.papersize2 = tmpret;
999 } else if (token == "\\paperpackage") {
1000 int tmpret = lex.findToken(string_paperpackages);
1003 params.paperpackage = BufferParams::PACKAGE_NONE;
1005 params.paperpackage = tmpret;
1006 } else if (token == "\\use_geometry") {
1008 params.use_geometry = lex.getInteger();
1009 } else if (token == "\\use_amsmath") {
1011 params.use_amsmath = lex.getInteger();
1012 } else if (token == "\\use_natbib") {
1014 params.use_natbib = lex.getInteger();
1015 } else if (token == "\\use_numerical_citations") {
1017 params.use_numerical_citations = lex.getInteger();
1018 } else if (token == "\\paperorientation") {
1019 int tmpret = lex.findToken(string_orientation);
1022 params.orientation =
1023 static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
1024 } else if (token == "\\paperwidth") {
1026 params.paperwidth = lex.getString();
1027 } else if (token == "\\paperheight") {
1029 params.paperheight = lex.getString();
1030 } else if (token == "\\leftmargin") {
1032 params.leftmargin = lex.getString();
1033 } else if (token == "\\topmargin") {
1035 params.topmargin = lex.getString();
1036 } else if (token == "\\rightmargin") {
1038 params.rightmargin = lex.getString();
1039 } else if (token == "\\bottommargin") {
1041 params.bottommargin = lex.getString();
1042 } else if (token == "\\headheight") {
1044 params.headheight = lex.getString();
1045 } else if (token == "\\headsep") {
1047 params.headsep = lex.getString();
1048 } else if (token == "\\footskip") {
1050 params.footskip = lex.getString();
1051 } else if (token == "\\paperfontsize") {
1053 params.fontsize = rtrim(lex.getString());
1054 } else if (token == "\\papercolumns") {
1056 params.columns = lex.getInteger();
1057 } else if (token == "\\papersides") {
1059 switch (lex.getInteger()) {
1061 case 1: params.sides = LyXTextClass::OneSide; break;
1062 case 2: params.sides = LyXTextClass::TwoSides; break;
1064 } else if (token == "\\paperpagestyle") {
1066 params.pagestyle = rtrim(lex.getString());
1067 } else if (token == "\\bullet") {
1069 int const index = lex.getInteger();
1071 int temp_int = lex.getInteger();
1072 params.user_defined_bullets[index].setFont(temp_int);
1073 params.temp_bullets[index].setFont(temp_int);
1075 temp_int = lex.getInteger();
1076 params.user_defined_bullets[index].setCharacter(temp_int);
1077 params.temp_bullets[index].setCharacter(temp_int);
1079 temp_int = lex.getInteger();
1080 params.user_defined_bullets[index].setSize(temp_int);
1081 params.temp_bullets[index].setSize(temp_int);
1083 string const temp_str = lex.getString();
1084 if (temp_str != "\\end_bullet") {
1085 // this element isn't really necessary for
1086 // parsing but is easier for humans
1087 // to understand bullets. Put it back and
1088 // set a debug message?
1089 lex.printError("\\end_bullet expected, got" + temp_str);
1090 //how can I put it back?
1092 } else if (token == "\\bulletLaTeX") {
1093 // The bullet class should be able to read this.
1095 int const index = lex.getInteger();
1097 string temp_str = lex.getString();
1099 while (temp_str != "\\end_bullet") {
1100 // this loop structure is needed when user
1101 // enters an empty string since the first
1102 // thing returned will be the \\end_bullet
1104 // if the LaTeX entry has spaces. Each element
1105 // therefore needs to be read in turn
1106 sum_str += temp_str;
1108 temp_str = lex.getString();
1111 params.user_defined_bullets[index].setText(sum_str);
1112 params.temp_bullets[index].setText(sum_str);
1113 } else if (token == "\\secnumdepth") {
1115 params.secnumdepth = lex.getInteger();
1116 } else if (token == "\\tocdepth") {
1118 params.tocdepth = lex.getInteger();
1119 } else if (token == "\\spacing") {
1121 string const tmp = rtrim(lex.getString());
1122 Spacing::Space tmp_space = Spacing::Default;
1123 float tmp_val = 0.0;
1124 if (tmp == "single") {
1125 tmp_space = Spacing::Single;
1126 } else if (tmp == "onehalf") {
1127 tmp_space = Spacing::Onehalf;
1128 } else if (tmp == "double") {
1129 tmp_space = Spacing::Double;
1130 } else if (tmp == "other") {
1132 tmp_space = Spacing::Other;
1133 tmp_val = lex.getFloat();
1135 lex.printError("Unknown spacing token: '$$Token'");
1137 // Small hack so that files written with klyx will be
1138 // parsed correctly.
1140 par->params().spacing(Spacing(tmp_space, tmp_val));
1142 params.spacing.set(tmp_space, tmp_val);
1144 } else if (token == "\\paragraph_spacing") {
1146 string const tmp = rtrim(lex.getString());
1147 if (tmp == "single") {
1148 par->params().spacing(Spacing(Spacing::Single));
1149 } else if (tmp == "onehalf") {
1150 par->params().spacing(Spacing(Spacing::Onehalf));
1151 } else if (tmp == "double") {
1152 par->params().spacing(Spacing(Spacing::Double));
1153 } else if (tmp == "other") {
1155 par->params().spacing(Spacing(Spacing::Other,
1158 lex.printError("Unknown spacing token: '$$Token'");
1160 } else if (token == "\\float_placement") {
1162 params.float_placement = lex.getString();
1163 } else if (token == "\\align") {
1164 int tmpret = lex.findToken(string_align);
1165 if (tmpret == -1) ++tmpret;
1166 int const tmpret2 = int(pow(2.0, tmpret));
1167 par->params().align(LyXAlignment(tmpret2));
1168 } else if (token == "\\added_space_top") {
1170 VSpace value = VSpace(lex.getString());
1171 // only add the length when value > 0 or
1173 if ((value.length().len().value() != 0) ||
1175 (value.kind() != VSpace::LENGTH))
1176 par->params().spaceTop(value);
1177 } else if (token == "\\added_space_bottom") {
1179 VSpace value = VSpace(lex.getString());
1180 // only add the length when value > 0 or
1182 if ((value.length().len().value() != 0) ||
1184 (value.kind() != VSpace::LENGTH))
1185 par->params().spaceBottom(value);
1186 #ifndef NO_COMPABILITY
1187 #ifndef NO_PEXTRA_REALLY
1188 } else if (token == "\\pextra_type") {
1190 par->params().pextraType(lex.getInteger());
1191 } else if (token == "\\pextra_width") {
1193 par->params().pextraWidth(lex.getString());
1194 } else if (token == "\\pextra_widthp") {
1196 par->params().pextraWidthp(lex.getString());
1197 } else if (token == "\\pextra_alignment") {
1199 par->params().pextraAlignment(lex.getInteger());
1200 } else if (token == "\\pextra_hfill") {
1202 par->params().pextraHfill(lex.getInteger());
1203 } else if (token == "\\pextra_start_minipage") {
1205 par->params().pextraStartMinipage(lex.getInteger());
1208 } else if (token == "\\labelwidthstring") {
1210 par->params().labelWidthString(lex.getString());
1211 // do not delete this token, it is still needed!
1212 } else if (token == "\\newline") {
1213 #ifndef NO_COMPABILITY
1214 if (!ert_comp.in_tabular && ert_comp.active) {
1215 ert_comp.contents += char(Paragraph::META_NEWLINE);
1217 // Since we cannot know it this is only a regular
1218 // newline or a tabular cell delimter we have to
1219 // handle the ERT here.
1220 insertErtContents(par, pos, false);
1222 par->insertChar(pos, Paragraph::META_NEWLINE, font);
1226 par->insertChar(pos, Paragraph::META_NEWLINE, font);
1229 } else if (token == "\\LyXTable") {
1230 #ifndef NO_COMPABILITY
1231 ert_comp.in_tabular = true;
1233 Inset * inset = new InsetTabular(*this);
1234 inset->read(this, lex);
1235 par->insertInset(pos, inset, font);
1237 } else if (token == "\\hfill") {
1238 par->insertChar(pos, Paragraph::META_HFILL, font);
1240 } else if (token == "\\protected_separator") { // obsolete
1241 // This is a backward compability thingie. (Lgb)
1242 // Remove it later some time...introduced with fileformat
1244 LyXLayout_ptr const & layout = par->layout();
1246 if (layout->free_spacing || par->isFreeSpacing()) {
1247 par->insertChar(pos, ' ', font);
1249 Inset * inset = new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
1250 par->insertInset(pos, inset, font);
1253 } else if (token == "\\bibitem") { // ale970302
1255 InsetCommandParams p("bibitem", "dummy");
1256 par->bibkey = new InsetBibKey(p);
1258 par->bibkey->read(this, lex);
1259 } else if (token == "\\the_end") {
1260 #ifndef NO_COMPABILITY
1261 // If we still have some ert active here we have to insert
1262 // it so we don't loose it. (Lgb)
1263 insertErtContents(par, pos);
1265 the_end_read = true;
1266 #ifndef NO_COMPABILITY
1267 #ifndef NO_PEXTRA_REALLY
1270 minipar = parBeforeMinipage = 0;
1274 #ifndef NO_COMPABILITY
1275 if (ert_comp.active) {
1276 ert_comp.contents += token;
1279 // This should be insurance for the future: (Asger)
1282 string const s = _("Unknown token: ") + token
1283 + " " + lex.text() + "\n";
1284 // we can do this here this way because we're actually reading
1285 // the buffer and don't care about LyXText right now.
1286 InsetError * new_inset = new InsetError(s);
1287 par->insertInset(pos, new_inset, LyXFont(LyXFont::ALL_INHERIT,
1290 #ifndef NO_COMPABILITY
1295 #ifndef NO_COMPABILITY
1296 #ifndef NO_PEXTRA_REALLY
1297 // I wonder if we could use this blanket fix for all the
1298 // checkminipage cases...
1299 // don't forget about ert paragraphs and compatibility read for'em
1300 if (par && (par->size() || !ert_comp.contents.empty())) {
1301 // It is possible that this will check to often,
1302 // but that should not be an correctness issue.
1303 // Only a speed issue.
1304 checkminipage = true;
1307 // now check if we have a minipage paragraph as at this
1308 // point we already read all the necessary data!
1309 // this cannot be done in layout because there we did
1310 // not read yet the paragraph PEXTRA-params (Jug)
1312 // BEGIN pextra_minipage compability
1313 // This should be removed in 1.3.x (Lgb)
1314 // I don't think we should remove this so fast (Jug)
1316 // This compability code is not perfect. In a couple
1317 // of rand cases it fails. When the minipage par is
1318 // the first par in the document, and when there are
1319 // none or only one regular paragraphs after the
1320 // minipage. Currently I am not investing any effort
1321 // in fixing those cases.
1323 // lyxerr << "Call depth: " << call_depth << endl;
1324 // lyxerr << "Checkminipage: " << checkminipage << endl;
1326 if (checkminipage && (call_depth == 1)) {
1327 checkminipage = false;
1328 if (minipar && (minipar != par) &&
1329 (par->params().pextraType() == Paragraph::PEXTRA_MINIPAGE)) {
1330 lyxerr << "minipages in a row" << endl;
1331 if (par->params().pextraStartMinipage()) {
1332 lyxerr << "start new minipage" << endl;
1333 // minipages in a row
1334 par->previous()->next(0);
1337 Paragraph * tmp = minipar;
1339 tmp->params().pextraType(0);
1340 tmp->params().pextraWidth(string());
1341 tmp->params().pextraWidthp(string());
1342 tmp->params().pextraAlignment(0);
1343 tmp->params().pextraHfill(false);
1344 tmp->params().pextraStartMinipage(false);
1347 // create a new paragraph to insert the
1348 // minipages in the following case
1349 if (par->params().pextraStartMinipage() &&
1350 !par->params().pextraHfill()) {
1351 Paragraph * p = new Paragraph;
1352 p->layout(params.getLyXTextClass().defaultLayoutName());
1354 p->previous(parBeforeMinipage);
1355 parBeforeMinipage->next(p);
1357 p->params().depth(parBeforeMinipage->params().depth());
1358 parBeforeMinipage = p;
1360 InsetMinipage * mini = new InsetMinipage(params);
1361 mini->pos(static_cast<InsetMinipage::Position>(par->params().pextraAlignment()));
1362 mini->pageWidth(LyXLength(par->params().pextraWidth()));
1363 if (!par->params().pextraWidthp().empty()) {
1364 lyxerr << "WP:" << mini->pageWidth().asString() << endl;
1365 mini->pageWidth(LyXLength((par->params().pextraWidthp())+"col%"));
1367 Paragraph * op = mini->firstParagraph();
1368 mini->inset.paragraph(par);
1370 // and free the old ones!
1373 Paragraph * pp = op->next();
1377 // Insert the minipage last in the
1378 // previous paragraph.
1379 if (par->params().pextraHfill()) {
1380 parBeforeMinipage->insertChar
1381 (parBeforeMinipage->size(),
1382 Paragraph::META_HFILL, font);
1384 parBeforeMinipage->insertInset
1385 (parBeforeMinipage->size(), mini, font);
1389 lyxerr << "new minipage par" << endl;
1390 //nothing to do just continue reading
1393 } else if (minipar && (minipar != par)) {
1394 lyxerr << "last minipage par read" << endl;
1395 // The last paragraph read was not part of a
1396 // minipage but the par linked list is...
1397 // So we need to remove the last par from the
1399 if (par->previous())
1400 par->previous()->next(0);
1401 par->previous(parBeforeMinipage);
1402 parBeforeMinipage->next(par);
1403 Paragraph * tmp = minipar;
1405 tmp->params().pextraType(0);
1406 tmp->params().pextraWidth(string());
1407 tmp->params().pextraWidthp(string());
1408 tmp->params().pextraAlignment(0);
1409 tmp->params().pextraHfill(false);
1410 tmp->params().pextraStartMinipage(false);
1413 depth = parBeforeMinipage->params().depth();
1414 // and set this depth on the par as it has not been set already
1415 par->params().depth(depth);
1416 minipar = parBeforeMinipage = 0;
1417 } else if (!minipar &&
1418 (par->params().pextraType() == Paragraph::PEXTRA_MINIPAGE)) {
1419 // par is the first paragraph in a minipage
1420 lyxerr << "begin minipage" << endl;
1421 // To minimize problems for
1422 // the users we will insert
1423 // the first minipage in
1424 // a sequence of minipages
1425 // in its own paragraph.
1426 Paragraph * p = new Paragraph;
1427 p->layout(params.getLyXTextClass().defaultLayoutName());
1428 p->previous(par->previous());
1430 p->params().depth(depth);
1431 par->params().depth(0);
1433 if (par->previous())
1434 par->previous()->next(p);
1436 parBeforeMinipage = p;
1438 if (!first_par || (first_par == par))
1441 InsetMinipage * mini = new InsetMinipage(params);
1442 mini->pos(static_cast<InsetMinipage::Position>(minipar->params().pextraAlignment()));
1443 mini->pageWidth(LyXLength(minipar->params().pextraWidth()));
1444 if (!par->params().pextraWidthp().empty()) {
1445 lyxerr << "WP:" << mini->pageWidth().asString() << endl;
1446 mini->pageWidth(LyXLength((par->params().pextraWidthp())+"col%"));
1449 Paragraph * op = mini->firstParagraph();
1450 mini->inset.paragraph(minipar);
1452 // and free the old ones!
1455 Paragraph * pp = op->next();
1460 // Insert the minipage last in the
1461 // previous paragraph.
1462 if (minipar->params().pextraHfill()) {
1463 parBeforeMinipage->insertChar
1464 (parBeforeMinipage->size(),
1465 Paragraph::META_HFILL, font);
1467 parBeforeMinipage->insertInset
1468 (parBeforeMinipage->size(), mini, font);
1469 } else if (par->params().pextraType() == Paragraph::PEXTRA_INDENT) {
1470 par->params().leftIndent(LyXLength(par->params().pextraWidth()));
1471 if (!par->params().pextraWidthp().empty()) {
1472 par->params().leftIndent(LyXLength((par->params().pextraWidthp())+"col%"));
1476 // End of pextra_minipage compability
1480 return the_end_read;
1483 // needed to insert the selection
1484 void Buffer::insertStringAsLines(Paragraph *& par, pos_type & pos,
1485 LyXFont const & fn,string const & str) const
1487 LyXLayout_ptr const & layout = par->layout();
1491 par->checkInsertChar(font);
1492 // insert the string, don't insert doublespace
1493 bool space_inserted = true;
1494 bool autobreakrows = !par->inInset() ||
1495 static_cast<InsetText *>(par->inInset())->getAutoBreakRows();
1496 for(string::const_iterator cit = str.begin();
1497 cit != str.end(); ++cit) {
1499 if (autobreakrows && (!par->empty() || layout->keepempty)) {
1500 breakParagraph(params, par, pos,
1501 layout->isEnvironment());
1504 space_inserted = true;
1508 // do not insert consecutive spaces if !free_spacing
1509 } else if ((*cit == ' ' || *cit == '\t') &&
1510 space_inserted && !layout->free_spacing &&
1511 !par->isFreeSpacing())
1514 } else if (*cit == '\t') {
1515 if (!layout->free_spacing && !par->isFreeSpacing()) {
1516 // tabs are like spaces here
1517 par->insertChar(pos, ' ', font);
1519 space_inserted = true;
1521 const pos_type nb = 8 - pos % 8;
1522 for (pos_type a = 0; a < nb ; ++a) {
1523 par->insertChar(pos, ' ', font);
1526 space_inserted = true;
1528 } else if (!IsPrintable(*cit)) {
1529 // Ignore unprintables
1532 // just insert the character
1533 par->insertChar(pos, *cit, font);
1535 space_inserted = (*cit == ' ');
1542 void Buffer::readInset(LyXLex & lex, Paragraph *& par,
1543 int & pos, LyXFont & font)
1545 // consistency check
1546 if (lex.getString() != "\\begin_inset") {
1547 lyxerr << "Buffer::readInset: Consistency check failed."
1554 string const tmptok = lex.getString();
1555 last_inset_read = tmptok;
1557 // test the different insets
1558 if (tmptok == "LatexCommand") {
1559 InsetCommandParams inscmd;
1562 string const cmdName = inscmd.getCmdName();
1564 // This strange command allows LyX to recognize "natbib" style
1565 // citations: citet, citep, Citet etc.
1566 if (compare_ascii_no_case(cmdName.substr(0,4), "cite") == 0) {
1567 inset = new InsetCitation(inscmd);
1568 } else if (cmdName == "bibitem") {
1569 lex.printError("Wrong place for bibitem");
1570 inset = new InsetBibKey(inscmd);
1571 } else if (cmdName == "BibTeX") {
1572 inset = new InsetBibtex(inscmd);
1573 } else if (cmdName == "index") {
1574 inset = new InsetIndex(inscmd);
1575 } else if (cmdName == "include") {
1576 inset = new InsetInclude(inscmd, *this);
1577 } else if (cmdName == "label") {
1578 inset = new InsetLabel(inscmd);
1579 } else if (cmdName == "url"
1580 || cmdName == "htmlurl") {
1581 inset = new InsetUrl(inscmd);
1582 } else if (cmdName == "ref"
1583 || cmdName == "pageref"
1584 || cmdName == "vref"
1585 || cmdName == "vpageref"
1586 || cmdName == "prettyref") {
1587 if (!inscmd.getOptions().empty()
1588 || !inscmd.getContents().empty()) {
1589 inset = new InsetRef(inscmd, *this);
1591 } else if (cmdName == "tableofcontents") {
1592 inset = new InsetTOC(inscmd);
1593 } else if (cmdName == "listofalgorithms") {
1594 inset = new InsetFloatList("algorithm");
1595 } else if (cmdName == "listoffigures") {
1596 inset = new InsetFloatList("figure");
1597 } else if (cmdName == "listoftables") {
1598 inset = new InsetFloatList("table");
1599 } else if (cmdName == "printindex") {
1600 inset = new InsetPrintIndex(inscmd);
1601 } else if (cmdName == "lyxparent") {
1602 inset = new InsetParent(inscmd, *this);
1605 bool alreadyread = false;
1606 if (tmptok == "Quotes") {
1607 inset = new InsetQuotes;
1608 } else if (tmptok == "External") {
1609 inset = new InsetExternal;
1610 } else if (tmptok == "FormulaMacro") {
1611 inset = new InsetFormulaMacro;
1612 } else if (tmptok == "Formula") {
1613 inset = new InsetFormula;
1614 } else if (tmptok == "Figure") { // Backward compatibility
1615 // inset = new InsetFig(100, 100, *this);
1616 inset = new InsetGraphics;
1617 } else if (tmptok == "Graphics") {
1618 inset = new InsetGraphics;
1619 } else if (tmptok == "Info") {// backwards compatibility
1620 inset = new InsetNote(this,
1621 lex.getLongString("\\end_inset"),
1624 } else if (tmptok == "Note") {
1625 inset = new InsetNote(params);
1626 } else if (tmptok == "Include") {
1627 InsetCommandParams p("Include");
1628 inset = new InsetInclude(p, *this);
1629 } else if (tmptok == "ERT") {
1630 inset = new InsetERT(params);
1631 } else if (tmptok == "Tabular") {
1632 inset = new InsetTabular(*this);
1633 } else if (tmptok == "Text") {
1634 inset = new InsetText(params);
1635 } else if (tmptok == "Foot") {
1636 inset = new InsetFoot(params);
1637 } else if (tmptok == "Marginal") {
1638 inset = new InsetMarginal(params);
1639 } else if (tmptok == "Minipage") {
1640 inset = new InsetMinipage(params);
1641 } else if (tmptok == "Float") {
1643 string tmptok = lex.getString();
1644 inset = new InsetFloat(params, tmptok);
1646 } else if (tmptok == "List") {
1647 inset = new InsetList;
1648 } else if (tmptok == "Theorem") {
1649 inset = new InsetList;
1651 } else if (tmptok == "Caption") {
1652 inset = new InsetCaption(params);
1653 } else if (tmptok == "FloatList") {
1654 inset = new InsetFloatList;
1657 if (inset && !alreadyread) inset->read(this, lex);
1661 par->insertInset(pos, inset, font);
1667 bool Buffer::readFile(LyXLex & lex, Paragraph * par)
1671 string const token(lex.getString());
1672 if (token == "\\lyxformat") { // the first token _must_ be...
1674 string tmp_format = lex.getString();
1675 //lyxerr << "LyX Format: `" << tmp_format << "'" << endl;
1676 // if present remove ".," from string.
1677 string::size_type dot = tmp_format.find_first_of(".,");
1678 //lyxerr << " dot found at " << dot << endl;
1679 if (dot != string::npos)
1680 tmp_format.erase(dot, 1);
1681 file_format = strToInt(tmp_format);
1682 if (file_format == LYX_FORMAT) {
1684 } else if (file_format > LYX_FORMAT) {
1686 Alert::alert(_("Warning!"),
1687 _("LyX file format is newer that what"),
1688 _("is supported in this LyX version. Expect some problems."));
1690 } else if (file_format < LYX_FORMAT) {
1692 if (file_format < 200) {
1693 Alert::alert(_("ERROR!"),
1694 _("Old LyX file format found. "
1695 "Use LyX 0.10.x to read this!"));
1697 } else if (file_format < 220) {
1698 string const command = "lyx2lyx "
1699 + QuoteName(filename_);
1700 cmd_ret const ret = RunCommand(command);
1702 Alert::alert(_("ERROR!"),
1703 _("An error occured while "
1704 "running the conversion script."));
1707 istringstream is(ret.second);
1708 LyXLex tmplex(0, 0);
1709 tmplex.setStream(is);
1710 return readFile(tmplex);
1713 bool the_end = readLyXformat2(lex, par);
1714 params.setPaperStuff();
1717 // the_end was added in 213
1718 if (file_format < 213)
1723 Alert::alert(_("Warning!"),
1724 _("Reading of document is not complete"),
1725 _("Maybe the document is truncated"));
1728 } else { // "\\lyxformat" not found
1729 Alert::alert(_("ERROR!"), _("Not a LyX file!"));
1732 Alert::alert(_("ERROR!"), _("Unable to read file!"));
1737 // Should probably be moved to somewhere else: BufferView? LyXView?
1738 bool Buffer::save() const
1740 // We don't need autosaves in the immediate future. (Asger)
1741 resetAutosaveTimers();
1745 if (lyxrc.make_backup) {
1746 s = fileName() + '~';
1747 if (!lyxrc.backupdir_path.empty())
1748 s = AddName(lyxrc.backupdir_path,
1749 subst(os::slashify_path(s),'/','!'));
1751 // Rename is the wrong way of making a backup,
1752 // this is the correct way.
1753 /* truss cp fil fil2:
1754 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
1755 stat("LyXVC.lyx", 0xEFFFF688) = 0
1756 open("LyXVC.lyx", O_RDONLY) = 3
1757 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
1758 fstat(4, 0xEFFFF508) = 0
1759 fstat(3, 0xEFFFF508) = 0
1760 read(3, " # T h i s f i l e w".., 8192) = 5579
1761 write(4, " # T h i s f i l e w".., 5579) = 5579
1762 read(3, 0xEFFFD4A0, 8192) = 0
1765 chmod("LyXVC3.lyx", 0100644) = 0
1766 lseek(0, 0, SEEK_CUR) = 46440
1770 // Should probably have some more error checking here.
1771 // Doing it this way, also makes the inodes stay the same.
1772 // This is still not a very good solution, in particular we
1773 // might loose the owner of the backup.
1774 FileInfo finfo(fileName());
1775 if (finfo.exist()) {
1776 mode_t fmode = finfo.getMode();
1777 struct utimbuf times = {
1778 finfo.getAccessTime(),
1779 finfo.getModificationTime() };
1781 ifstream ifs(fileName().c_str());
1782 ofstream ofs(s.c_str(), ios::out|ios::trunc);
1787 ::chmod(s.c_str(), fmode);
1789 if (::utime(s.c_str(), ×)) {
1790 lyxerr << "utime error." << endl;
1793 lyxerr << "LyX was not able to make "
1794 "backup copy. Beware." << endl;
1799 if (writeFile(fileName())) {
1801 removeAutosaveFile(fileName());
1803 // Saving failed, so backup is not backup
1804 if (lyxrc.make_backup) {
1805 lyx::rename(s, fileName());
1813 bool Buffer::writeFile(string const & fname) const
1815 if (read_only && (fname == fileName())) {
1819 FileInfo finfo(fname);
1820 if (finfo.exist() && !finfo.writable()) {
1824 ofstream ofs(fname.c_str());
1830 // Use the standard "C" locale for file output.
1831 ofs.imbue(std::locale::classic());
1834 // The top of the file should not be written by params.
1836 // write out a comment in the top of the file
1837 ofs << '#' << lyx_docversion
1838 << " created this file. For more info see http://www.lyx.org/\n"
1839 << "\\lyxformat " << LYX_FORMAT << "\n";
1841 // now write out the buffer paramters.
1842 params.writeFile(ofs);
1844 Paragraph::depth_type depth = 0;
1846 // this will write out all the paragraphs
1847 // using recursive descent.
1848 ParagraphList::iterator pit = paragraphs.begin();
1849 ParagraphList::iterator pend = paragraphs.end();
1850 for (; pit != pend; ++pit)
1851 pit->write(this, ofs, params, depth);
1853 // Write marker that shows file is complete
1854 ofs << "\n\\the_end" << endl;
1858 // how to check if close went ok?
1859 // Following is an attempt... (BE 20001011)
1861 // good() returns false if any error occured, including some
1862 // formatting error.
1863 // bad() returns true if something bad happened in the buffer,
1864 // which should include file system full errors.
1871 lyxerr << "Buffer::writeFile: BAD ERROR!" << endl;
1873 lyxerr << "Buffer::writeFile: NOT SO BAD ERROR!"
1885 pair<int, string> const addDepth(int depth, int ldepth)
1889 d += (ldepth - depth) * 2;
1890 return make_pair(d, string(d, ' '));
1896 string const Buffer::asciiParagraph(Paragraph const & par,
1897 unsigned int linelen,
1898 bool noparbreak) const
1900 ostringstream buffer;
1901 Paragraph::depth_type depth = 0;
1903 Paragraph::depth_type ltype_depth = 0;
1904 bool ref_printed = false;
1905 // if (!par->previous()) {
1907 // begins or ends a deeper area ?
1908 if (depth != par->params().depth()) {
1909 if (par->params().depth() > depth) {
1910 while (par->params().depth() > depth) {
1914 while (par->params().depth() < depth) {
1920 depth = par.params().depth();
1923 // First write the layout
1924 string const & tmp = par.layout()->name();
1925 if (compare_no_case(tmp, "itemize") == 0) {
1927 ltype_depth = depth + 1;
1928 } else if (compare_ascii_no_case(tmp, "enumerate") == 0) {
1930 ltype_depth = depth + 1;
1931 } else if (contains(ascii_lowercase(tmp), "ection")) {
1933 ltype_depth = depth + 1;
1934 } else if (contains(ascii_lowercase(tmp), "aragraph")) {
1936 ltype_depth = depth + 1;
1937 } else if (compare_ascii_no_case(tmp, "description") == 0) {
1939 ltype_depth = depth + 1;
1940 } else if (compare_ascii_no_case(tmp, "abstract") == 0) {
1943 } else if (compare_ascii_no_case(tmp, "bibliography") == 0) {
1951 /* maybe some vertical spaces */
1953 /* the labelwidthstring used in lists */
1957 /* some pagebreaks? */
1961 /* what about the alignment */
1963 // lyxerr << "Should this ever happen?" << endl;
1966 // linelen <= 0 is special and means we don't have paragraph breaks
1968 string::size_type currlinelen = 0;
1974 buffer << string(depth * 2, ' ');
1975 currlinelen += depth * 2;
1978 // we should probably change to the paragraph language in the
1979 // gettext here (if possible) so that strings are outputted in
1980 // the correct language! (20012712 Jug)
1984 case 4: // (Sub)Paragraph
1985 case 5: // Description
1989 buffer << _("Abstract") << "\n\n";
1992 string const abst = _("Abstract: ");
1994 currlinelen += abst.length();
1997 case 7: // Bibliography
2000 buffer << _("References") << "\n\n";
2003 string const refs = _("References: ");
2005 currlinelen += refs.length();
2013 string const parlab = par.params().labelString();
2014 buffer << parlab << " ";
2015 currlinelen += parlab.length() + 1;
2023 pair<int, string> p = addDepth(depth, ltype_depth);
2025 currlinelen += p.first;
2028 // this is to change the linebreak to do it by word a bit more
2029 // intelligent hopefully! (only in the case where we have a
2030 // max linelenght!) (Jug)
2034 for (pos_type i = 0; i < par.size(); ++i) {
2035 char c = par.getUChar(params, i);
2037 case Paragraph::META_INSET:
2039 Inset const * inset = par.getInset(i);
2043 currlinelen += word.length();
2046 if (inset->ascii(this, buffer, linelen)) {
2047 // to be sure it breaks paragraph
2048 currlinelen += linelen;
2054 case Paragraph::META_NEWLINE:
2056 buffer << word << "\n";
2059 pair<int, string> p = addDepth(depth,
2062 currlinelen = p.first;
2066 case Paragraph::META_HFILL:
2067 buffer << word << "\t";
2068 currlinelen += word.length() + 1;
2075 currlinelen + word.length() > linelen - 10) {
2077 pair<int, string> p =
2078 addDepth(depth, ltype_depth);
2080 currlinelen = p.first;
2083 buffer << word << ' ';
2084 currlinelen += word.length() + 1;
2091 lyxerr[Debug::INFO] <<
2092 "writeAsciiFile: NULL char in structure." << endl;
2094 if ((linelen > 0) &&
2095 (currlinelen + word.length()) > linelen)
2099 pair<int, string> p =
2100 addDepth(depth, ltype_depth);
2102 currlinelen = p.first;
2109 return buffer.str().c_str();
2113 void Buffer::writeFileAscii(string const & fname, int linelen)
2115 ofstream ofs(fname.c_str());
2117 Alert::err_alert(_("Error: Cannot write file:"), fname);
2120 writeFileAscii(ofs, linelen);
2124 void Buffer::writeFileAscii(ostream & os, int linelen)
2126 ParagraphList::iterator beg = paragraphs.begin();
2127 ParagraphList::iterator end = paragraphs.end();
2128 ParagraphList::iterator it = beg;
2129 for (; it != end; ++it) {
2130 os << asciiParagraph(*it, linelen, it == beg);
2139 void Buffer::makeLaTeXFile(string const & fname,
2140 string const & original_path,
2141 bool nice, bool only_body, bool only_preamble)
2143 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
2145 ofstream ofs(fname.c_str());
2147 Alert::err_alert(_("Error: Cannot open file: "), fname);
2151 makeLaTeXFile(ofs, original_path, nice, only_body, only_preamble);
2155 lyxerr << "File was not closed properly." << endl;
2160 void Buffer::makeLaTeXFile(ostream & os,
2161 string const & original_path,
2162 bool nice, bool only_body, bool only_preamble)
2164 niceFile = nice; // this will be used by Insetincludes.
2166 // validate the buffer.
2167 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
2168 LaTeXFeatures features(params);
2170 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
2173 // The starting paragraph of the coming rows is the
2174 // first paragraph of the document. (Asger)
2175 texrow.start(&*(paragraphs.begin()), 0);
2177 if (!only_body && nice) {
2178 os << "%% " << lyx_docversion << " created this file. "
2179 "For more info, see http://www.lyx.org/.\n"
2180 "%% Do not edit unless you really know what "
2185 lyxerr[Debug::INFO] << "lyx header finished" << endl;
2186 // There are a few differences between nice LaTeX and usual files:
2187 // usual is \batchmode and has a
2188 // special input@path to allow the including of figures
2189 // with either \input or \includegraphics (what figinsets do).
2190 // input@path is set when the actual parameter
2191 // original_path is set. This is done for usual tex-file, but not
2192 // for nice-latex-file. (Matthias 250696)
2195 // code for usual, NOT nice-latex-file
2196 os << "\\batchmode\n"; // changed
2197 // from \nonstopmode
2200 if (!original_path.empty()) {
2201 string inputpath = os::external_path(original_path);
2202 subst(inputpath, "~", "\\string~");
2203 os << "\\makeatletter\n"
2204 << "\\def\\input@path{{"
2205 << inputpath << "/}}\n"
2206 << "\\makeatother\n";
2212 os << "\\documentclass";
2214 LyXTextClass const & tclass = params.getLyXTextClass();
2216 ostringstream options; // the document class options.
2218 if (tokenPos(tclass.opt_fontsize(),
2219 '|', params.fontsize) >= 0) {
2220 // only write if existing in list (and not default)
2221 options << params.fontsize << "pt,";
2225 if (!params.use_geometry &&
2226 (params.paperpackage == BufferParams::PACKAGE_NONE)) {
2227 switch (params.papersize) {
2228 case BufferParams::PAPER_A4PAPER:
2229 options << "a4paper,";
2231 case BufferParams::PAPER_USLETTER:
2232 options << "letterpaper,";
2234 case BufferParams::PAPER_A5PAPER:
2235 options << "a5paper,";
2237 case BufferParams::PAPER_B5PAPER:
2238 options << "b5paper,";
2240 case BufferParams::PAPER_EXECUTIVEPAPER:
2241 options << "executivepaper,";
2243 case BufferParams::PAPER_LEGALPAPER:
2244 options << "legalpaper,";
2250 if (params.sides != tclass.sides()) {
2251 switch (params.sides) {
2252 case LyXTextClass::OneSide:
2253 options << "oneside,";
2255 case LyXTextClass::TwoSides:
2256 options << "twoside,";
2262 if (params.columns != tclass.columns()) {
2263 if (params.columns == 2)
2264 options << "twocolumn,";
2266 options << "onecolumn,";
2269 if (!params.use_geometry
2270 && params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
2271 options << "landscape,";
2273 // language should be a parameter to \documentclass
2275 ostringstream language_options;
2276 if (params.language->babel() == "hebrew"
2277 && default_language->babel() != "hebrew")
2278 // This seems necessary
2279 features.useLanguage(default_language);
2281 if (lyxrc.language_use_babel ||
2282 params.language->lang() != lyxrc.default_language ||
2283 features.hasLanguages()) {
2285 language_options << features.getLanguages();
2286 language_options << params.language->babel();
2287 if (lyxrc.language_global_options)
2288 options << language_options.str() << ',';
2291 // the user-defined options
2292 if (!params.options.empty()) {
2293 options << params.options << ',';
2296 string strOptions(options.str().c_str());
2297 if (!strOptions.empty()) {
2298 strOptions = rtrim(strOptions, ",");
2299 os << '[' << strOptions << ']';
2302 os << '{' << tclass.latexname() << "}\n";
2304 // end of \documentclass defs
2306 // font selection must be done before loading fontenc.sty
2307 // The ae package is not needed when using OT1 font encoding.
2308 if (params.fonts != "default" &&
2309 (params.fonts != "ae" || lyxrc.fontenc != "default")) {
2310 os << "\\usepackage{" << params.fonts << "}\n";
2312 if (params.fonts == "ae") {
2313 os << "\\usepackage{aecompl}\n";
2317 // this one is not per buffer
2318 if (lyxrc.fontenc != "default") {
2319 os << "\\usepackage[" << lyxrc.fontenc
2324 if (params.inputenc == "auto") {
2325 string const doc_encoding =
2326 params.language->encoding()->LatexName();
2328 // Create a list with all the input encodings used
2330 set<string> encodings = features.getEncodingSet(doc_encoding);
2332 os << "\\usepackage[";
2333 std::copy(encodings.begin(), encodings.end(),
2334 std::ostream_iterator<string>(os, ","));
2335 os << doc_encoding << "]{inputenc}\n";
2337 } else if (params.inputenc != "default") {
2338 os << "\\usepackage[" << params.inputenc
2343 // At the very beginning the text parameters.
2344 if (params.paperpackage != BufferParams::PACKAGE_NONE) {
2345 switch (params.paperpackage) {
2346 case BufferParams::PACKAGE_A4:
2347 os << "\\usepackage{a4}\n";
2350 case BufferParams::PACKAGE_A4WIDE:
2351 os << "\\usepackage{a4wide}\n";
2354 case BufferParams::PACKAGE_WIDEMARGINSA4:
2355 os << "\\usepackage[widemargins]{a4}\n";
2360 if (params.use_geometry) {
2361 os << "\\usepackage{geometry}\n";
2363 os << "\\geometry{verbose";
2364 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
2366 switch (params.papersize2) {
2367 case BufferParams::VM_PAPER_CUSTOM:
2368 if (!params.paperwidth.empty())
2369 os << ",paperwidth="
2370 << params.paperwidth;
2371 if (!params.paperheight.empty())
2372 os << ",paperheight="
2373 << params.paperheight;
2375 case BufferParams::VM_PAPER_USLETTER:
2376 os << ",letterpaper";
2378 case BufferParams::VM_PAPER_USLEGAL:
2379 os << ",legalpaper";
2381 case BufferParams::VM_PAPER_USEXECUTIVE:
2382 os << ",executivepaper";
2384 case BufferParams::VM_PAPER_A3:
2387 case BufferParams::VM_PAPER_A4:
2390 case BufferParams::VM_PAPER_A5:
2393 case BufferParams::VM_PAPER_B3:
2396 case BufferParams::VM_PAPER_B4:
2399 case BufferParams::VM_PAPER_B5:
2403 // default papersize ie BufferParams::VM_PAPER_DEFAULT
2404 switch (lyxrc.default_papersize) {
2405 case BufferParams::PAPER_DEFAULT: // keep compiler happy
2406 case BufferParams::PAPER_USLETTER:
2407 os << ",letterpaper";
2409 case BufferParams::PAPER_LEGALPAPER:
2410 os << ",legalpaper";
2412 case BufferParams::PAPER_EXECUTIVEPAPER:
2413 os << ",executivepaper";
2415 case BufferParams::PAPER_A3PAPER:
2418 case BufferParams::PAPER_A4PAPER:
2421 case BufferParams::PAPER_A5PAPER:
2424 case BufferParams::PAPER_B5PAPER:
2429 if (!params.topmargin.empty())
2430 os << ",tmargin=" << params.topmargin;
2431 if (!params.bottommargin.empty())
2432 os << ",bmargin=" << params.bottommargin;
2433 if (!params.leftmargin.empty())
2434 os << ",lmargin=" << params.leftmargin;
2435 if (!params.rightmargin.empty())
2436 os << ",rmargin=" << params.rightmargin;
2437 if (!params.headheight.empty())
2438 os << ",headheight=" << params.headheight;
2439 if (!params.headsep.empty())
2440 os << ",headsep=" << params.headsep;
2441 if (!params.footskip.empty())
2442 os << ",footskip=" << params.footskip;
2447 if (tokenPos(tclass.opt_pagestyle(),
2448 '|', params.pagestyle) >= 0) {
2449 if (params.pagestyle == "fancy") {
2450 os << "\\usepackage{fancyhdr}\n";
2453 os << "\\pagestyle{" << params.pagestyle << "}\n";
2457 if (params.secnumdepth != tclass.secnumdepth()) {
2458 os << "\\setcounter{secnumdepth}{"
2459 << params.secnumdepth
2463 if (params.tocdepth != tclass.tocdepth()) {
2464 os << "\\setcounter{tocdepth}{"
2470 if (params.paragraph_separation) {
2471 switch (params.defskip.kind()) {
2472 case VSpace::SMALLSKIP:
2473 os << "\\setlength\\parskip{\\smallskipamount}\n";
2475 case VSpace::MEDSKIP:
2476 os << "\\setlength\\parskip{\\medskipamount}\n";
2478 case VSpace::BIGSKIP:
2479 os << "\\setlength\\parskip{\\bigskipamount}\n";
2481 case VSpace::LENGTH:
2482 os << "\\setlength\\parskip{"
2483 << params.defskip.length().asLatexString()
2486 default: // should never happen // Then delete it.
2487 os << "\\setlength\\parskip{\\medskipamount}\n";
2492 os << "\\setlength\\parindent{0pt}\n";
2496 // Now insert the LyX specific LaTeX commands...
2498 // The optional packages;
2499 string preamble(features.getPackages());
2501 // this might be useful...
2502 preamble += "\n\\makeatletter\n";
2504 // Some macros LyX will need
2505 string tmppreamble(features.getMacros());
2507 if (!tmppreamble.empty()) {
2508 preamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2509 "LyX specific LaTeX commands.\n"
2510 + tmppreamble + '\n';
2513 // the text class specific preamble
2514 tmppreamble = features.getTClassPreamble();
2515 if (!tmppreamble.empty()) {
2516 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2517 "Textclass specific LaTeX commands.\n"
2518 + tmppreamble + '\n';
2521 /* the user-defined preamble */
2522 if (!params.preamble.empty()) {
2523 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2524 "User specified LaTeX commands.\n"
2525 + params.preamble + '\n';
2528 // Itemize bullet settings need to be last in case the user
2529 // defines their own bullets that use a package included
2530 // in the user-defined preamble -- ARRae
2531 // Actually it has to be done much later than that
2532 // since some packages like frenchb make modifications
2533 // at \begin{document} time -- JMarc
2535 for (int i = 0; i < 4; ++i) {
2536 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
2537 if (bullets_def.empty())
2538 bullets_def="\\AtBeginDocument{\n";
2539 bullets_def += " \\renewcommand{\\labelitemi";
2541 // `i' is one less than the item to modify
2548 bullets_def += "ii";
2554 bullets_def += "}{" +
2555 params.user_defined_bullets[i].getText()
2560 if (!bullets_def.empty())
2561 preamble += bullets_def + "}\n\n";
2564 int(lyx::count(preamble.begin(), preamble.end(), '\n'));
2565 for (int j = 0; j != nlines; ++j) {
2569 // We try to load babel late, in case it interferes
2570 // with other packages.
2572 string tmp = lyxrc.language_package;
2573 if (!lyxrc.language_global_options
2574 && tmp == "\\usepackage{babel}")
2575 tmp = string("\\usepackage[") +
2576 language_options.str().c_str() +
2578 preamble += tmp + "\n";
2579 preamble += features.getBabelOptions();
2582 preamble += "\\makeatother\n";
2590 os << "\\begin{document}\n";
2593 lyxerr[Debug::INFO] << "preamble finished, now the body." << endl;
2595 if (!lyxrc.language_auto_begin) {
2596 os << subst(lyxrc.language_command_begin, "$$lang",
2597 params.language->babel())
2602 latexParagraphs(os, &*(paragraphs.begin()), 0, texrow);
2604 // add this just in case after all the paragraphs
2608 if (!lyxrc.language_auto_end) {
2609 os << subst(lyxrc.language_command_end, "$$lang",
2610 params.language->babel())
2616 os << "\\end{document}\n";
2619 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
2621 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
2625 // Just to be sure. (Asger)
2628 lyxerr[Debug::INFO] << "Finished making latex file." << endl;
2629 lyxerr[Debug::INFO] << "Row count was " << texrow.rows()-1 << "." << endl;
2631 // we want this to be true outside previews (for insetexternal)
2637 // LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
2639 void Buffer::latexParagraphs(ostream & ofs, Paragraph * par,
2640 Paragraph * endpar, TexRow & texrow,
2641 bool moving_arg) const
2643 bool was_title = false;
2644 bool already_title = false;
2647 while (par != endpar) {
2648 Inset * in = par->inInset();
2649 // well we have to check if we are in an inset with unlimited
2650 // length (all in one row) if that is true then we don't allow
2651 // any special options in the paragraph and also we don't allow
2652 // any environment other then "Standard" to be valid!
2653 if ((in == 0) || !in->forceDefaultParagraphs(in)) {
2654 LyXLayout_ptr const & layout = par->layout();
2656 if (layout->intitle) {
2657 if (already_title) {
2658 lyxerr <<"Error in latexParagraphs: You"
2659 " should not mix title layouts"
2660 " with normal ones." << endl;
2663 } else if (was_title && !already_title) {
2664 ofs << "\\maketitle\n";
2666 already_title = true;
2670 if (layout->isEnvironment() ||
2671 !par->params().leftIndent().zero())
2673 par = par->TeXEnvironment(this, params, ofs, texrow);
2675 par = par->TeXOnePar(this, params, ofs, texrow, moving_arg);
2678 par = par->TeXOnePar(this, params, ofs, texrow, moving_arg);
2681 // It might be that we only have a title in this document
2682 if (was_title && !already_title) {
2683 ofs << "\\maketitle\n";
2689 bool Buffer::isLatex() const
2691 return params.getLyXTextClass().outputType() == LATEX;
2695 bool Buffer::isLinuxDoc() const
2697 return params.getLyXTextClass().outputType() == LINUXDOC;
2701 bool Buffer::isLiterate() const
2703 return params.getLyXTextClass().outputType() == LITERATE;
2707 bool Buffer::isDocBook() const
2709 return params.getLyXTextClass().outputType() == DOCBOOK;
2713 bool Buffer::isSGML() const
2715 LyXTextClass const & tclass = params.getLyXTextClass();
2717 return tclass.outputType() == LINUXDOC ||
2718 tclass.outputType() == DOCBOOK;
2722 int Buffer::sgmlOpenTag(ostream & os, Paragraph::depth_type depth, bool mixcont,
2723 string const & latexname) const
2725 if (!latexname.empty() && latexname != "!-- --") {
2727 os << string(" ",depth);
2728 os << "<" << latexname << ">";
2738 int Buffer::sgmlCloseTag(ostream & os, Paragraph::depth_type depth, bool mixcont,
2739 string const & latexname) const
2741 if (!latexname.empty() && latexname != "!-- --") {
2743 os << endl << string(" ",depth);
2744 os << "</" << latexname << ">";
2754 void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
2756 ofstream ofs(fname.c_str());
2759 Alert::alert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2763 niceFile = nice; // this will be used by included files.
2765 LaTeXFeatures features(params);
2771 LyXTextClass const & tclass = params.getLyXTextClass();
2773 string top_element = tclass.latexname();
2776 ofs << "<!doctype linuxdoc system";
2778 string preamble = params.preamble;
2779 const string name = nice ? ChangeExtension(filename_, ".sgml")
2781 preamble += features.getIncludedFiles(name);
2782 preamble += features.getLyXSGMLEntities();
2784 if (!preamble.empty()) {
2785 ofs << " [ " << preamble << " ]";
2789 if (params.options.empty())
2790 sgmlOpenTag(ofs, 0, false, top_element);
2792 string top = top_element;
2794 top += params.options;
2795 sgmlOpenTag(ofs, 0, false, top);
2799 ofs << "<!-- " << lyx_docversion
2800 << " created this file. For more info see http://www.lyx.org/"
2803 Paragraph::depth_type depth = 0; // paragraph depth
2804 Paragraph * par = &*(paragraphs.begin());
2806 vector<string> environment_stack(5);
2809 LyXLayout_ptr const & style = par->layout();
2810 // treat <toc> as a special case for compatibility with old code
2811 if (par->isInset(0)) {
2812 Inset * inset = par->getInset(0);
2813 Inset::Code lyx_code = inset->lyxCode();
2814 if (lyx_code == Inset::TOC_CODE) {
2815 string const temp = "toc";
2816 sgmlOpenTag(ofs, depth, false, temp);
2823 // environment tag closing
2824 for (; depth > par->params().depth(); --depth) {
2825 sgmlCloseTag(ofs, depth, false, environment_stack[depth]);
2826 environment_stack[depth].erase();
2829 // write opening SGML tags
2830 switch (style->latextype) {
2831 case LATEX_PARAGRAPH:
2832 if (depth == par->params().depth()
2833 && !environment_stack[depth].empty()) {
2834 sgmlCloseTag(ofs, depth, false, environment_stack[depth]);
2835 environment_stack[depth].erase();
2841 sgmlOpenTag(ofs, depth, false, style->latexname());
2847 _("Error : Wrong depth for"
2848 " LatexType Command.\n"));
2850 if (!environment_stack[depth].empty()) {
2851 sgmlCloseTag(ofs, depth, false, environment_stack[depth]);
2855 environment_stack[depth].erase();
2856 sgmlOpenTag(ofs, depth, false, style->latexname());
2859 case LATEX_ENVIRONMENT:
2860 case LATEX_ITEM_ENVIRONMENT:
2862 string const & latexname = style->latexname();
2864 if (depth == par->params().depth()
2865 && environment_stack[depth] != latexname) {
2866 sgmlCloseTag(ofs, depth, false,
2867 environment_stack[depth]);
2868 environment_stack[depth].erase();
2870 if (depth < par->params().depth()) {
2871 depth = par->params().depth();
2872 environment_stack[depth].erase();
2874 if (environment_stack[depth] != latexname) {
2876 sgmlOpenTag(ofs, depth, false, "p");
2878 sgmlOpenTag(ofs, depth, false, latexname);
2880 if (environment_stack.size() == depth + 1)
2881 environment_stack.push_back("!-- --");
2882 environment_stack[depth] = latexname;
2885 if (style->latexparam() == "CDATA")
2888 if (style->latextype == LATEX_ENVIRONMENT) break;
2890 if (style->labeltype == LABEL_MANUAL)
2895 sgmlOpenTag(ofs, depth + 1, false, item_name);
2900 sgmlOpenTag(ofs, depth, false, style->latexname());
2904 simpleLinuxDocOnePar(ofs, par, depth);
2909 // write closing SGML tags
2910 switch (style->latextype) {
2913 case LATEX_ENVIRONMENT:
2914 case LATEX_ITEM_ENVIRONMENT:
2915 if (style->latexparam() == "CDATA")
2919 sgmlCloseTag(ofs, depth, false, style->latexname());
2925 for (int i = depth; i >= 0; --i)
2926 sgmlCloseTag(ofs, depth, false, environment_stack[i]);
2930 sgmlCloseTag(ofs, 0, false, top_element);
2934 // How to check for successful close
2936 // we want this to be true outside previews (for insetexternal)
2941 // checks, if newcol chars should be put into this line
2942 // writes newline, if necessary.
2945 void sgmlLineBreak(ostream & os, string::size_type & colcount,
2946 string::size_type newcol)
2949 if (colcount > lyxrc.ascii_linelen) {
2951 colcount = newcol; // assume write after this call
2966 string tag_name(PAR_TAG const & pt) {
2968 case NONE: return "!-- --";
2969 case TT: return "tt";
2970 case SF: return "sf";
2971 case BF: return "bf";
2972 case IT: return "it";
2973 case SL: return "sl";
2974 case EM: return "em";
2981 void operator|=(PAR_TAG & p1, PAR_TAG const & p2)
2983 p1 = static_cast<PAR_TAG>(p1 | p2);
2988 void reset(PAR_TAG & p1, PAR_TAG const & p2)
2990 p1 = static_cast<PAR_TAG>(p1 & ~p2);
2996 // Handle internal paragraph parsing -- layout already processed.
2997 void Buffer::simpleLinuxDocOnePar(ostream & os,
2999 Paragraph::depth_type /*depth*/)
3001 LyXLayout_ptr const & style = par->layout();
3003 string::size_type char_line_count = 5; // Heuristic choice ;-)
3005 // gets paragraph main font
3008 if (style->labeltype == LABEL_MANUAL) {
3009 font_old = style->labelfont;
3012 font_old = style->font;
3016 LyXFont::FONT_FAMILY family_type = LyXFont::ROMAN_FAMILY;
3017 LyXFont::FONT_SERIES series_type = LyXFont::MEDIUM_SERIES;
3018 LyXFont::FONT_SHAPE shape_type = LyXFont::UP_SHAPE;
3021 stack<PAR_TAG> tag_state;
3022 // parsing main loop
3023 for (pos_type i = 0; i < par->size(); ++i) {
3025 PAR_TAG tag_close = NONE;
3026 list < PAR_TAG > tag_open;
3028 LyXFont const font = par->getFont(params, i);
3030 if (font_old.family() != font.family()) {
3031 switch (family_type) {
3032 case LyXFont::SANS_FAMILY:
3035 case LyXFont::TYPEWRITER_FAMILY:
3042 family_type = font.family();
3044 switch (family_type) {
3045 case LyXFont::SANS_FAMILY:
3046 tag_open.push_back(SF);
3048 case LyXFont::TYPEWRITER_FAMILY:
3049 tag_open.push_back(TT);
3056 if (font_old.series() != font.series()) {
3057 switch (series_type) {
3058 case LyXFont::BOLD_SERIES:
3065 series_type = font.series();
3067 switch (series_type) {
3068 case LyXFont::BOLD_SERIES:
3069 tag_open.push_back(BF);
3077 if (font_old.shape() != font.shape()) {
3078 switch (shape_type) {
3079 case LyXFont::ITALIC_SHAPE:
3082 case LyXFont::SLANTED_SHAPE:
3089 shape_type = font.shape();
3091 switch (shape_type) {
3092 case LyXFont::ITALIC_SHAPE:
3093 tag_open.push_back(IT);
3095 case LyXFont::SLANTED_SHAPE:
3096 tag_open.push_back(SL);
3103 if (font_old.emph() != font.emph()) {
3104 if (font.emph() == LyXFont::ON) {
3105 tag_open.push_back(EM);
3114 list < PAR_TAG > temp;
3115 while (!tag_state.empty() && tag_close) {
3116 PAR_TAG k = tag_state.top();
3118 os << "</" << tag_name(k) << ">";
3125 for(list< PAR_TAG >::const_iterator j = temp.begin();
3126 j != temp.end(); ++j) {
3128 os << "<" << tag_name(*j) << ">";
3131 for(list< PAR_TAG >::const_iterator j = tag_open.begin();
3132 j != tag_open.end(); ++j) {
3134 os << "<" << tag_name(*j) << ">";
3137 char c = par->getChar(i);
3139 if (c == Paragraph::META_INSET) {
3140 Inset * inset = par->getInset(i);
3141 inset->linuxdoc(this, os);
3146 if (style->latexparam() == "CDATA") {
3147 // "TeX"-Mode on == > SGML-Mode on.
3154 boost::tie(ws, str) = sgml::escapeChar(c);
3155 if (ws && !style->free_spacing && !par->isFreeSpacing()) {
3156 // in freespacing mode, spaces are
3157 // non-breaking characters
3158 if (desc_on) {// if char is ' ' then...
3161 sgmlLineBreak(os, char_line_count, 6);
3165 sgmlLineBreak(os, char_line_count, 1);
3170 char_line_count += str.length();
3176 while (!tag_state.empty()) {
3177 os << "</" << tag_name(tag_state.top()) << ">";
3181 // resets description flag correctly
3183 // <tag> not closed...
3184 sgmlLineBreak(os, char_line_count, 6);
3190 // Print an error message.
3191 void Buffer::sgmlError(Paragraph * /*par*/, int /*pos*/,
3192 string const & /*message*/) const
3194 #ifdef WITH_WARNINGS
3195 #warning This is wrong we cannot insert an inset like this!!!
3196 // I guess this was Jose' so I explain you more or less why this
3197 // is wrong. This way you insert something in the paragraph and
3198 // don't tell it to LyXText (row rebreaking and undo handling!!!)
3199 // I deactivate this code, have a look at BufferView::insertErrors
3200 // how you should do this correctly! (Jug 20020315)
3203 // insert an error marker in text
3204 InsetError * new_inset = new InsetError(message);
3205 par->insertInset(pos, new_inset, LyXFont(LyXFont::ALL_INHERIT,
3211 void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
3213 ofstream ofs(fname.c_str());
3215 Alert::alert(_("LYX_ERROR:"), _("Cannot write file"), fname);
3219 Paragraph * par = &*(paragraphs.begin());
3221 niceFile = nice; // this will be used by Insetincludes.
3223 LaTeXFeatures features(params);
3228 LyXTextClass const & tclass = params.getLyXTextClass();
3229 string top_element = tclass.latexname();
3232 ofs << "<!DOCTYPE " << top_element
3233 << " PUBLIC \"-//OASIS//DTD DocBook V4.1//EN\"";
3235 string preamble = params.preamble;
3236 const string name = nice ? ChangeExtension(filename_, ".sgml")
3238 preamble += features.getIncludedFiles(name);
3239 preamble += features.getLyXSGMLEntities();
3241 if (!preamble.empty()) {
3242 ofs << "\n [ " << preamble << " ]";
3247 string top = top_element;
3249 top += params.language->code();
3252 if (!params.options.empty()) {
3254 top += params.options;
3256 sgmlOpenTag(ofs, 0, false, top);
3258 ofs << "<!-- DocBook file was created by " << lyx_docversion
3259 << "\n See http://www.lyx.org/ for more information -->\n";
3261 vector<string> environment_stack(10);
3262 vector<string> environment_inner(10);
3263 vector<string> command_stack(10);
3265 bool command_flag = false;
3266 Paragraph::depth_type command_depth = 0;
3267 Paragraph::depth_type command_base = 0;
3268 Paragraph::depth_type cmd_depth = 0;
3269 Paragraph::depth_type depth = 0; // paragraph depth
3272 string command_name;
3278 int desc_on = 0; // description mode
3280 LyXLayout_ptr const & style = par->layout();
3282 // environment tag closing
3283 for (; depth > par->params().depth(); --depth) {
3284 if (environment_inner[depth] != "!-- --") {
3285 item_name = "listitem";
3286 sgmlCloseTag(ofs, command_depth + depth, false, item_name);
3287 if (environment_inner[depth] == "varlistentry")
3288 sgmlCloseTag(ofs, depth+command_depth, false, environment_inner[depth]);
3290 sgmlCloseTag(ofs, depth + command_depth, false, environment_stack[depth]);
3291 environment_stack[depth].erase();
3292 environment_inner[depth].erase();
3295 if (depth == par->params().depth()
3296 && environment_stack[depth] != style->latexname()
3297 && !environment_stack[depth].empty()) {
3298 if (environment_inner[depth] != "!-- --") {
3299 item_name= "listitem";
3300 sgmlCloseTag(ofs, command_depth+depth, false, item_name);
3301 if (environment_inner[depth] == "varlistentry")
3302 sgmlCloseTag(ofs, depth + command_depth, false, environment_inner[depth]);
3305 sgmlCloseTag(ofs, depth + command_depth, false, environment_stack[depth]);
3307 environment_stack[depth].erase();
3308 environment_inner[depth].erase();
3311 // Write opening SGML tags.
3312 switch (style->latextype) {
3313 case LATEX_PARAGRAPH:
3314 sgmlOpenTag(ofs, depth + command_depth,
3315 false, style->latexname());
3321 _("Error : Wrong depth for "
3322 "LatexType Command.\n"));
3324 command_name = style->latexname();
3326 sgmlparam = style->latexparam();
3327 c_params = split(sgmlparam, c_depth,'|');
3329 cmd_depth = lyx::atoi(c_depth);
3332 if (cmd_depth < command_base) {
3333 for (Paragraph::depth_type j = command_depth;
3334 j >= command_base; --j) {
3335 sgmlCloseTag(ofs, j, false, command_stack[j]);
3338 command_depth = command_base = cmd_depth;
3339 } else if (cmd_depth <= command_depth) {
3340 for (int j = command_depth;
3341 j >= int(cmd_depth); --j) {
3342 sgmlCloseTag(ofs, j, false, command_stack[j]);
3345 command_depth = cmd_depth;
3347 command_depth = cmd_depth;
3349 command_depth = command_base = cmd_depth;
3350 command_flag = true;
3352 if (command_stack.size() == command_depth + 1)
3353 command_stack.push_back(string());
3354 command_stack[command_depth] = command_name;
3356 // treat label as a special case for
3357 // more WYSIWYM handling.
3358 // This is a hack while paragraphs can't have
3359 // attributes, like id in this case.
3360 if (par->isInset(0)) {
3361 Inset * inset = par->getInset(0);
3362 Inset::Code lyx_code = inset->lyxCode();
3363 if (lyx_code == Inset::LABEL_CODE) {
3364 command_name += " id=\"";
3365 command_name += (static_cast<InsetCommand *>(inset))->getContents();
3366 command_name += "\"";
3371 sgmlOpenTag(ofs, depth + command_depth, false, command_name);
3373 item_name = c_params.empty()?"title":c_params;
3374 sgmlOpenTag(ofs, depth + 1 + command_depth, false, item_name);
3377 case LATEX_ENVIRONMENT:
3378 case LATEX_ITEM_ENVIRONMENT:
3379 if (depth < par->params().depth()) {
3380 depth = par->params().depth();
3381 environment_stack[depth].erase();
3384 if (environment_stack[depth] != style->latexname()) {
3385 if (environment_stack.size() == depth + 1) {
3386 environment_stack.push_back("!-- --");
3387 environment_inner.push_back("!-- --");
3389 environment_stack[depth] = style->latexname();
3390 environment_inner[depth] = "!-- --";
3391 sgmlOpenTag(ofs, depth + command_depth, false, environment_stack[depth]);
3393 if (environment_inner[depth] != "!-- --") {
3394 item_name= "listitem";
3395 sgmlCloseTag(ofs, command_depth + depth, false, item_name);
3396 if (environment_inner[depth] == "varlistentry")
3397 sgmlCloseTag(ofs, depth + command_depth, false, environment_inner[depth]);
3401 if (style->latextype == LATEX_ENVIRONMENT) {
3402 if (!style->latexparam().empty()) {
3403 if (style->latexparam() == "CDATA")
3406 sgmlOpenTag(ofs, depth + command_depth, false, style->latexparam());
3411 desc_on = (style->labeltype == LABEL_MANUAL);
3413 environment_inner[depth] = desc_on ? "varlistentry" : "listitem";
3414 sgmlOpenTag(ofs, depth + 1 + command_depth,
3415 false, environment_inner[depth]);
3417 item_name = desc_on ? "term" : "para";
3418 sgmlOpenTag(ofs, depth + 1 + command_depth,
3422 sgmlOpenTag(ofs, depth + command_depth,
3423 false, style->latexname());
3427 simpleDocBookOnePar(ofs, par, desc_on,
3428 depth + 1 + command_depth);
3432 // write closing SGML tags
3433 switch (style->latextype) {
3435 end_tag = c_params.empty() ? "title" : c_params;
3436 sgmlCloseTag(ofs, depth + command_depth,
3439 case LATEX_ENVIRONMENT:
3440 if (!style->latexparam().empty()) {
3441 if (style->latexparam() == "CDATA")
3444 sgmlCloseTag(ofs, depth + command_depth, false, style->latexparam());
3447 case LATEX_ITEM_ENVIRONMENT:
3448 if (desc_on == 1) break;
3450 sgmlCloseTag(ofs, depth + 1 + command_depth, false, end_tag);
3452 case LATEX_PARAGRAPH:
3453 sgmlCloseTag(ofs, depth + command_depth, false, style->latexname());
3456 sgmlCloseTag(ofs, depth + command_depth, false, style->latexname());
3462 for (int d = depth; d >= 0; --d) {
3463 if (!environment_stack[depth].empty()) {
3464 if (environment_inner[depth] != "!-- --") {
3465 item_name = "listitem";
3466 sgmlCloseTag(ofs, command_depth + depth, false, item_name);
3467 if (environment_inner[depth] == "varlistentry")
3468 sgmlCloseTag(ofs, depth + command_depth, false, environment_inner[depth]);
3471 sgmlCloseTag(ofs, depth + command_depth, false, environment_stack[depth]);
3475 for (int j = command_depth; j >= 0 ; --j)
3476 if (!command_stack[j].empty()) {
3477 sgmlCloseTag(ofs, j, false, command_stack[j]);
3482 sgmlCloseTag(ofs, 0, false, top_element);
3485 // How to check for successful close
3487 // we want this to be true outside previews (for insetexternal)
3492 void Buffer::simpleDocBookOnePar(ostream & os,
3493 Paragraph * par, int & desc_on,
3494 Paragraph::depth_type depth) const
3496 bool emph_flag = false;
3498 LyXLayout_ptr const & style = par->layout();
3500 LyXFont font_old = (style->labeltype == LABEL_MANUAL ? style->labelfont : style->font);
3502 int char_line_count = depth;
3503 //if (!style.free_spacing)
3504 // os << string(depth,' ');
3506 // parsing main loop
3507 for (pos_type i = 0; i < par->size(); ++i) {
3508 LyXFont font = par->getFont(params, i);
3510 // handle <emphasis> tag
3511 if (font_old.emph() != font.emph()) {
3512 if (font.emph() == LyXFont::ON) {
3513 if (style->latexparam() == "CDATA")
3516 if (style->latexparam() == "CDATA")
3520 if (style->latexparam() == "CDATA")
3522 os << "</emphasis>";
3523 if (style->latexparam() == "CDATA")
3530 if (par->isInset(i)) {
3531 Inset * inset = par->getInset(i);
3532 // don't print the inset in position 0 if desc_on == 3 (label)
3533 if (i || desc_on != 3) {
3534 if (style->latexparam() == "CDATA")
3536 inset->docbook(this, os, false);
3537 if (style->latexparam() == "CDATA")
3541 char c = par->getChar(i);
3544 boost::tie(ws, str) = sgml::escapeChar(c);
3546 if (style->pass_thru) {
3548 } else if (style->free_spacing || par->isFreeSpacing() || c != ' ') {
3550 } else if (desc_on ==1) {
3552 os << "\n</term><listitem><para>";
3562 if (style->latexparam() == "CDATA")
3564 os << "</emphasis>";
3565 if (style->latexparam() == "CDATA")
3569 // resets description flag correctly
3571 // <term> not closed...
3572 os << "</term>\n<listitem><para> </para>";
3574 if (style->free_spacing)
3579 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
3580 // Other flags: -wall -v0 -x
3581 int Buffer::runChktex()
3583 if (!users->text) return 0;
3585 users->owner()->prohibitInput();
3587 // get LaTeX-Filename
3588 string const name = getLatexName();
3589 string path = filePath();
3591 string const org_path = path;
3592 if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
3596 Path p(path); // path to LaTeX file
3597 users->owner()->message(_("Running chktex..."));
3599 // Remove all error insets
3600 bool const removedErrorInsets = users->removeAutoInsets();
3602 // Generate the LaTeX file if neccessary
3603 makeLaTeXFile(name, org_path, false);
3606 Chktex chktex(lyxrc.chktex_command, name, filePath());
3607 int res = chktex.run(terr); // run chktex
3610 Alert::alert(_("chktex did not work!"),
3611 _("Could not run with file:"), name);
3612 } else if (res > 0) {
3613 // Insert all errors as errors boxes
3614 users->insertErrors(terr);
3617 // if we removed error insets before we ran chktex or if we inserted
3618 // error insets after we ran chktex, this must be run:
3619 if (removedErrorInsets || res) {
3620 #warning repaint needed here, or do you mean update() ?
3624 users->owner()->allowInput();
3630 void Buffer::validate(LaTeXFeatures & features) const
3632 LyXTextClass const & tclass = params.getLyXTextClass();
3634 // AMS Style is at document level
3635 if (params.use_amsmath || tclass.provides(LyXTextClass::amsmath))
3636 features.require("amsmath");
3638 for_each(paragraphs.begin(), paragraphs.end(),
3639 boost::bind(&Paragraph::validate, _1, boost::ref(features)));
3641 // the bullet shapes are buffer level not paragraph level
3642 // so they are tested here
3643 for (int i = 0; i < 4; ++i) {
3644 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
3645 int const font = params.user_defined_bullets[i].getFont();
3647 int const c = params
3648 .user_defined_bullets[i]
3655 features.require("latexsym");
3657 } else if (font == 1) {
3658 features.require("amssymb");
3659 } else if ((font >= 2 && font <= 5)) {
3660 features.require("pifont");
3665 if (lyxerr.debugging(Debug::LATEX)) {
3666 features.showStruct();
3671 // This function should be in Buffer because it's a buffer's property (ale)
3672 string const Buffer::getIncludeonlyList(char delim)
3675 for (inset_iterator it = inset_iterator_begin();
3676 it != inset_iterator_end(); ++it) {
3677 if (it->lyxCode() == Inset::INCLUDE_CODE) {
3678 InsetInclude & inc = static_cast<InsetInclude &>(*it);
3679 if (inc.isIncludeOnly()) {
3682 lst += inc.getRelFileBaseName();
3686 lyxerr[Debug::INFO] << "Includeonly(" << lst << ')' << endl;
3691 vector<string> const Buffer::getLabelList() const
3693 /// if this is a child document and the parent is already loaded
3694 /// Use the parent's list instead [ale990407]
3695 if (!params.parentname.empty()
3696 && bufferlist.exists(params.parentname)) {
3697 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
3699 return tmp->getLabelList();
3702 vector<string> label_list;
3703 for (inset_iterator it = inset_const_iterator_begin();
3704 it != inset_const_iterator_end(); ++it) {
3705 vector<string> const l = it->getLabelList();
3706 label_list.insert(label_list.end(), l.begin(), l.end());
3712 // This is also a buffer property (ale)
3713 vector<pair<string, string> > const Buffer::getBibkeyList() const
3715 typedef pair<string, string> StringPair;
3716 /// if this is a child document and the parent is already loaded
3717 /// Use the parent's list instead [ale990412]
3718 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3719 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
3721 return tmp->getBibkeyList();
3724 vector<StringPair> keys;
3725 ParagraphList::iterator pit = paragraphs.begin();
3726 ParagraphList::iterator pend = paragraphs.end();
3727 for (; pit != pend; ++pit) {
3729 string const key = pit->bibkey->getContents();
3730 string const opt = pit->bibkey->getOptions();
3731 string const ref = pit->asString(this, false);
3732 string const info = opt + "TheBibliographyRef" + ref;
3734 keys.push_back(StringPair(key, info));
3738 // Might be either using bibtex or a child has bibliography
3740 for (inset_iterator it = inset_const_iterator_begin();
3741 it != inset_const_iterator_end(); ++it) {
3742 // Search for Bibtex or Include inset
3743 if (it->lyxCode() == Inset::BIBTEX_CODE) {
3744 vector<StringPair> tmp =
3745 static_cast<InsetBibtex &>(*it).getKeys(this);
3746 keys.insert(keys.end(), tmp.begin(), tmp.end());
3747 } else if (it->lyxCode() == Inset::INCLUDE_CODE) {
3748 vector<StringPair> const tmp =
3749 static_cast<InsetInclude &>(*it).getKeys();
3750 keys.insert(keys.end(), tmp.begin(), tmp.end());
3759 bool Buffer::isDepClean(string const & name) const
3761 DEPCLEAN * item = dep_clean;
3762 while (item && item->master != name)
3764 if (!item) return true;
3769 void Buffer::markDepClean(string const & name)
3772 dep_clean = new DEPCLEAN;
3773 dep_clean->clean = true;
3774 dep_clean->master = name;
3775 dep_clean->next = 0;
3777 DEPCLEAN * item = dep_clean;
3778 while (item && item->master != name)
3783 item = new DEPCLEAN;
3785 item->master = name;
3792 bool Buffer::dispatch(string const & command, bool * result)
3794 // Split command string into command and argument
3796 string line = ltrim(command);
3797 string const arg = trim(split(line, cmd, ' '));
3799 return dispatch(lyxaction.LookupFunc(cmd), arg, result);
3803 bool Buffer::dispatch(int action, string const & argument, bool * result)
3805 bool dispatched = true;
3809 bool const tmp = Exporter::Export(this, argument, false);
3822 void Buffer::resizeInsets(BufferView * bv)
3824 /// then remove all LyXText in text-insets
3825 for_each(paragraphs.begin(), paragraphs.end(),
3826 boost::bind(&Paragraph::resizeInsetsLyXText, _1, bv));
3830 void Buffer::redraw()
3832 #warning repaint needed here, or do you mean update() ?
3838 void Buffer::changeLanguage(Language const * from, Language const * to)
3841 ParIterator end = par_iterator_end();
3842 for (ParIterator it = par_iterator_begin(); it != end; ++it)
3843 (*it)->changeLanguage(params, from, to);
3847 bool Buffer::isMultiLingual()
3849 ParIterator end = par_iterator_end();
3850 for (ParIterator it = par_iterator_begin(); it != end; ++it)
3851 if ((*it)->isMultiLingual(params))
3858 Counters & Buffer::counters() const
3864 void Buffer::inset_iterator::setParagraph()
3866 while (pit != pend) {
3867 it = pit->insetlist.begin();
3868 if (it != pit->insetlist.end())
3875 Inset * Buffer::getInsetFromID(int id_arg) const
3877 for (inset_iterator it = inset_const_iterator_begin();
3878 it != inset_const_iterator_end(); ++it)
3880 if (it->id() == id_arg)
3882 Inset * in = it->getInsetFromID(id_arg);
3890 Paragraph * Buffer::getParFromID(int id) const
3895 ParagraphList::iterator it = paragraphs.begin();
3896 ParagraphList::iterator end = paragraphs.end();
3897 for (; it != end; ++it) {
3898 if (it->id() == id) {
3901 Paragraph * tmp = it->getParFromID(id);
3910 ParIterator Buffer::par_iterator_begin()
3912 return ParIterator(&*(paragraphs.begin()));
3916 ParIterator Buffer::par_iterator_end()
3918 return ParIterator();
3922 void Buffer::addUser(BufferView * u)
3928 void Buffer::delUser(BufferView *)
3934 Language const * Buffer::getLanguage() const
3936 return params.language;
3940 bool Buffer::isClean() const
3946 bool Buffer::isBakClean() const
3952 void Buffer::markClean() const
3958 // if the .lyx file has been saved, we don't need an
3964 void Buffer::markBakClean()
3970 void Buffer::setUnnamed(bool flag)
3976 bool Buffer::isUnnamed()
3982 void Buffer::markDirty()
3989 DEPCLEAN * tmp = dep_clean;
3997 string const & Buffer::fileName() const
4003 string const & Buffer::filePath() const
4009 bool Buffer::isReadonly() const
4015 BufferView * Buffer::getUser() const
4021 void Buffer::setParentName(string const & name)
4023 params.parentname = name;
4027 Buffer::inset_iterator::inset_iterator()
4032 Buffer::inset_iterator::inset_iterator(base_type p, base_type e)
4039 Buffer::inset_iterator & Buffer::inset_iterator::operator++()
4043 if (it == pit->insetlist.end()) {
4052 Buffer::inset_iterator Buffer::inset_iterator::operator++(int)
4054 inset_iterator tmp = *this;
4060 Buffer::inset_iterator::reference Buffer::inset_iterator::operator*()
4062 return *it.getInset();
4066 Buffer::inset_iterator::pointer Buffer::inset_iterator::operator->()
4068 return it.getInset();
4072 Paragraph * Buffer::inset_iterator::getPar()
4078 lyx::pos_type Buffer::inset_iterator::getPos() const
4084 bool operator==(Buffer::inset_iterator const & iter1,
4085 Buffer::inset_iterator const & iter2)
4087 return iter1.pit == iter2.pit
4088 && (iter1.pit == iter1.pend || iter1.it == iter2.it);
4092 bool operator!=(Buffer::inset_iterator const & iter1,
4093 Buffer::inset_iterator const & iter2)
4095 return !(iter1 == iter2);