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"
34 #include "frontends/LyXView.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 "graphics/Previews.h"
88 #include "support/textutils.h"
89 #include "support/filetools.h"
90 #include "support/path.h"
91 #include "support/os.h"
92 #include "support/lyxlib.h"
93 #include "support/FileInfo.h"
94 #include "support/lyxmanip.h"
95 #include "support/lyxalgo.h" // for lyx::count
107 #include <sys/types.h>
115 #ifndef CXX_GLOBAL_CSTD
127 using std::make_pair;
136 using lyx::textclass_type;
138 // all these externs should eventually be removed.
139 extern BufferList bufferlist;
141 extern LyXAction lyxaction;
145 const int LYX_FORMAT = 220;
149 extern int tex_code_break_column;
152 Buffer::Buffer(string const & file, bool ronly)
153 : paragraph(0), niceFile(true), lyx_clean(true), bak_clean(true),
154 unnamed(false), dep_clean(0), read_only(ronly),
155 filename_(file), users(0)
157 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
159 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);
191 Paragraph * par = paragraph;
194 tmppar = par->next();
200 // Remove any previewed LaTeX snippets assocoated with this buffer.
201 grfx::Previews::get().removeLoader(this);
205 string const Buffer::getLatexName(bool no_path) const
207 string const name = ChangeExtension(MakeLatexName(fileName()), ".tex");
209 return OnlyFilename(name);
215 pair<Buffer::LogType, string> const Buffer::getLogName(void) const
217 string const filename = getLatexName(false);
219 if (filename.empty())
220 return make_pair(Buffer::latexlog, string());
222 string path = OnlyPath(filename);
224 if (lyxrc.use_tempdir || !IsDirWriteable(path))
227 string const fname = AddName(path,
228 OnlyFilename(ChangeExtension(filename,
231 AddName(path, OnlyFilename(
232 ChangeExtension(filename,
233 formats.extension("literate") + ".out")));
235 // If no Latex log or Build log is newer, show Build log
237 FileInfo const f_fi(fname);
238 FileInfo const b_fi(bname);
241 (!f_fi.exist() || f_fi.getModificationTime() < b_fi.getModificationTime())) {
242 lyxerr[Debug::FILES] << "Log name calculated as : " << bname << endl;
243 return make_pair(Buffer::buildlog, bname);
245 lyxerr[Debug::FILES] << "Log name calculated as : " << fname << endl;
246 return make_pair(Buffer::latexlog, fname);
250 void Buffer::setReadonly(bool flag)
252 if (read_only != flag) {
255 users->owner()->getDialogs()->updateBufferDependent(false);
260 /// Update window titles of all users
261 // Should work on a list
262 void Buffer::updateTitles() const
265 users->owner()->updateWindowTitle();
269 /// Reset autosave timer of all users
270 // Should work on a list
271 void Buffer::resetAutosaveTimers() const
274 users->owner()->resetAutosaveTimer();
278 void Buffer::setFileName(string const & newfile)
280 filename_ = MakeAbsPath(newfile);
281 filepath_ = OnlyPath(filename_);
282 setReadonly(IsFileWriteable(filename_) == 0);
287 // We'll remove this later. (Lgb)
290 string last_inset_read;
292 #ifndef NO_COMPABILITY
295 ErtComp() : active(false), fromlayout(false), in_tabular(false) {
304 std::stack<ErtComp> ert_stack;
309 #warning And _why_ is this here? (Lgb)
317 // candidate for move to BufferView
318 // (at least some parts in the beginning of the func)
321 // changed to be public and have one parameter
322 // if par = 0 normal behavior
323 // else insert behavior
324 // Returns false if "\the_end" is not read for formats >= 2.13. (Asger)
325 bool Buffer::readLyXformat2(LyXLex & lex, Paragraph * par)
329 #ifndef NO_COMPABILITY
330 ert_comp.contents.erase();
331 ert_comp.active = false;
332 ert_comp.fromlayout = false;
333 ert_comp.in_tabular = false;
336 Paragraph::depth_type depth = 0;
337 bool the_end_read = false;
339 Paragraph * first_par = 0;
340 LyXFont font(LyXFont::ALL_INHERIT, params.language);
343 if (file_format < 216 && params.language->lang() == "hebrew")
344 font.setLanguage(default_language);
349 par->layout(params.getLyXTextClass().defaultLayout());
351 // We are inserting into an existing document
352 users->text->breakParagraph(users);
353 first_par = users->text->ownerParagraph();
356 // We don't want to adopt the parameters from the
357 // document we insert, so we skip until the text begins:
360 string const pretoken = lex.getString();
361 if (pretoken == "\\layout") {
362 lex.pushToken(pretoken);
370 string const token = lex.getString();
372 if (token.empty()) continue;
374 lyxerr[Debug::PARSER] << "Handling token: `"
375 << token << "'" << endl;
378 parseSingleLyXformat2Token(lex, par, first_par,
386 paragraph = first_par;
388 if (unknown_layouts > 0) {
389 string s = _("Couldn't set the layout for ");
390 if (unknown_layouts == 1) {
391 s += _("one paragraph");
393 s += tostr(unknown_layouts);
394 s += _(" paragraphs");
396 Alert::alert(_("Textclass Loading Error!"), s,
397 _("When reading " + fileName()));
400 if (unknown_tokens > 0) {
401 string s = _("Encountered ");
402 if (unknown_tokens == 1) {
403 s += _("one unknown token");
405 s += tostr(unknown_tokens);
406 s += _(" unknown tokens");
408 Alert::alert(_("Textclass Loading Error!"), s,
409 _("When reading " + fileName()));
416 #ifndef NO_COMPABILITY
418 Inset * Buffer::isErtInset(Paragraph * par, int pos) const
421 if ((par->getChar(pos) == Paragraph::META_INSET) &&
422 (inset = par->getInset(pos)) &&
423 (inset->lyxCode() == Inset::ERT_CODE))
430 void Buffer::insertErtContents(Paragraph * par, int & pos, bool set_inactive)
432 if (ert_comp.contents.find_first_not_of(' ') != string::npos) {
433 // we only skip completely empty ERT (only spaces) otherwise
434 // we have to insert it as is.
435 string str(ert_comp.contents);
436 lyxerr[Debug::INSETS] << "ERT contents:\n'"
437 << str << "'" << endl;
438 // check if we have already an ert inset a position earlier
439 // if this is the case then we should insert the contents
440 // inside the other ertinset as it is stupid to have various
443 if ((pos > 0) && (inset=isErtInset(par, pos-1))) {
444 // get the last paragraph from the inset before
445 Paragraph * last = inset->firstParagraph();
448 // create the new paragraph after the last one
449 Paragraph * par = new Paragraph(last);
450 par->layout(params.getLyXTextClass().defaultLayoutName());
451 par->setInsetOwner(last->inInset());
453 LyXFont font(LyXFont::ALL_INHERIT, params.language);
454 string::const_iterator cit = str.begin();
455 string::const_iterator end = str.end();
457 for (; cit != end; ++cit) {
458 par->insertChar(pos++, *cit, font);
462 new InsetERT(params, params.language, str, true);
463 par->insertInset(pos++, inset, ert_comp.font);
466 ert_comp.contents.erase();
467 ert_comp.fromlayout = false;
469 ert_comp.active = false;
476 Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
477 Paragraph *& first_par,
478 string const & token, int & pos,
479 Paragraph::depth_type & depth,
483 bool the_end_read = false;
484 #ifndef NO_COMPABILITY
485 #ifndef NO_PEXTRA_REALLY
486 // This is super temporary but is needed to get the compability
487 // mode for minipages work correctly together with new tabulars.
488 static int call_depth;
490 bool checkminipage = false;
491 static Paragraph * minipar = 0;
492 static Paragraph * parBeforeMinipage;
496 // The order of the tags tested may seem unnatural, but this
497 // has been done in order to reduce the number of string
498 // comparisons needed to recognize a given token. This leads
499 // on large documents like UserGuide to a reduction of a
501 if (token[0] != '\\') {
502 #ifndef NO_COMPABILITY
503 if (ert_comp.active) {
504 ert_comp.contents += token;
507 for (string::const_iterator cit = token.begin();
508 cit != token.end(); ++cit) {
509 par->insertChar(pos, (*cit), font);
512 #ifndef NO_COMPABILITY
515 } else if (token == "\\layout") {
516 #ifndef NO_COMPABILITY
517 bool old_fromlayout = ert_comp.fromlayout;
518 bool create_new_par = true;
519 ert_comp.in_tabular = false;
521 if (!par->size() && par->previous() &&
522 (par->previous()->size() == 1) &&
523 isErtInset(par->previous(), par->previous()->size()-1))
525 int p = par->previous()->size();
526 insertErtContents(par->previous(), p);
527 create_new_par = false;
529 insertErtContents(par, pos);
532 // reset the font as we start a new layout and if the font is
533 // not ALL_INHERIT,document_language then it will be set to the
534 // right values after this tag (Jug 20020420)
535 font = LyXFont(LyXFont::ALL_INHERIT, params.language);
538 if (file_format < 216 && params.language->lang() == "hebrew")
539 font.setLanguage(default_language);
543 string layoutname = lex.getString();
545 LyXTextClass const & tclass = params.getLyXTextClass();
547 if (layoutname.empty()) {
548 layoutname = tclass.defaultLayoutName();
550 #ifndef NO_COMPABILITY
551 if (compare_ascii_no_case(layoutname, "latex") == 0) {
552 ert_comp.active = true;
553 ert_comp.fromlayout = true;
554 ert_comp.font = font;
556 create_new_par = false;
559 bool hasLayout = tclass.hasLayout(layoutname);
561 lyxerr << "Layout '" << layoutname << "' does not"
562 << " exist in textclass '" << tclass.name()
564 lyxerr << "Trying to use default layout instead."
566 layoutname = tclass.defaultLayoutName();
570 // The is the compability reading of layout caption.
571 // It can be removed in LyX version 1.3.0. (Lgb)
572 if (compare_ascii_no_case(layoutname, "caption") == 0) {
573 // We expect that the par we are now working on is
574 // really inside a InsetText inside a InsetFloat.
575 // We also know that captions can only be
576 // one paragraph. (Lgb)
578 // We should now read until the next "\layout"
580 // This is probably not good enough, what if the
581 // caption is the last par in the document (Lgb)
582 istream & ist = lex.getStream();
588 if (prefixIs(line, "\\layout")) {
592 if (prefixIs(line, "\\begin_inset"))
594 if (prefixIs(line, "\\end_inset")) {
605 // Now we should have the whole layout in ss
606 // we should now be able to give this to the
608 ss << "\\end_inset\n";
610 // This seems like a bug in stringstream.
611 // We really should be able to use ss
613 istringstream is(ss.str());
615 tmplex.setStream(is);
616 Inset * inset = new InsetCaption;
617 inset->Read(this, tmplex);
618 par->InsertInset(pos, inset, font);
622 #ifndef NO_COMPABILITY
623 if (create_new_par) {
628 par = new Paragraph(par);
629 par->layout(params.getLyXTextClass().defaultLayout());
632 par->layout(params.getLyXTextClass()[layoutname]);
633 // Test whether the layout is obsolete.
634 LyXLayout_ptr const & layout = par->layout();
635 if (!layout->obsoleted_by().empty())
636 par->layout(params.getLyXTextClass()[layout->obsoleted_by()]);
637 par->params().depth(depth);
638 #ifndef NO_COMPABILITY
640 // we duplicate code here because it's easier to remove
641 // the code then of NO_COMPATIBILITY
642 par->layout(layoutname);
643 // Test whether the layout is obsolete.
644 LyXLayout_ptr const & layout =
645 params.getLyXTextClass()[par->layout()];
646 if (!layout->obsoleted_by().empty())
647 par->layout(layout->obsoleted_by());
648 par->params().depth(depth);
655 } else if (token == "\\end_inset") {
656 lyxerr << "Solitary \\end_inset. Missing \\begin_inset?.\n"
657 << "Last inset read was: " << last_inset_read
659 // Simply ignore this. The insets do not have
661 // But insets should read it, it is a part of
662 // the inset isn't it? Lgb.
663 } else if (token == "\\begin_inset") {
664 #ifndef NO_COMPABILITY
665 insertErtContents(par, pos, false);
666 ert_stack.push(ert_comp);
667 ert_comp = ErtComp();
669 readInset(lex, par, pos, font);
670 #ifndef NO_COMPABILITY
671 ert_comp = ert_stack.top();
673 insertErtContents(par, pos);
675 } else if (token == "\\family") {
677 font.setLyXFamily(lex.getString());
678 } else if (token == "\\series") {
680 font.setLyXSeries(lex.getString());
681 } else if (token == "\\shape") {
683 font.setLyXShape(lex.getString());
684 } else if (token == "\\size") {
686 font.setLyXSize(lex.getString());
687 #ifndef NO_COMPABILITY
688 } else if (token == "\\latex") {
690 string const tok = lex.getString();
691 if (tok == "no_latex") {
693 insertErtContents(par, pos);
694 } else if (tok == "latex") {
695 ert_comp.active = true;
696 ert_comp.font = font;
697 } else if (tok == "default") {
699 insertErtContents(par, pos);
701 lex.printError("Unknown LaTeX font flag "
705 } else if (token == "\\lang") {
707 string const tok = lex.getString();
708 Language const * lang = languages.getLanguage(tok);
710 font.setLanguage(lang);
712 font.setLanguage(params.language);
713 lex.printError("Unknown language `$$Token'");
715 } else if (token == "\\numeric") {
717 font.setNumber(font.setLyXMisc(lex.getString()));
718 } else if (token == "\\emph") {
720 font.setEmph(font.setLyXMisc(lex.getString()));
721 } else if (token == "\\bar") {
723 string const tok = lex.getString();
724 // This is dirty, but gone with LyX3. (Asger)
726 font.setUnderbar(LyXFont::ON);
727 else if (tok == "no")
728 font.setUnderbar(LyXFont::OFF);
729 else if (tok == "default")
730 font.setUnderbar(LyXFont::INHERIT);
732 lex.printError("Unknown bar font flag "
734 } else if (token == "\\noun") {
736 font.setNoun(font.setLyXMisc(lex.getString()));
737 } else if (token == "\\color") {
739 font.setLyXColor(lex.getString());
740 } else if (token == "\\SpecialChar") {
741 LyXLayout_ptr const & layout = par->layout();
743 // Insets don't make sense in a free-spacing context! ---Kayvan
744 if (layout->free_spacing || par->isFreeSpacing()) {
747 string next_token = lex.getString();
748 if (next_token == "\\-") {
749 par->insertChar(pos, '-', font);
750 } else if (next_token == "\\protected_separator"
751 || next_token == "~") {
752 par->insertChar(pos, ' ', font);
754 lex.printError("Token `$$Token' "
756 "paragraph layout!");
761 Inset * inset = new InsetSpecialChar;
762 inset->read(this, lex);
763 par->insertInset(pos, inset, font);
766 } else if (token == "\\i") {
767 Inset * inset = new InsetLatexAccent;
768 inset->read(this, lex);
769 par->insertInset(pos, inset, font);
771 } else if (token == "\\backslash") {
772 #ifndef NO_COMPABILITY
773 if (ert_comp.active) {
774 ert_comp.contents += "\\";
777 par->insertChar(pos, '\\', font);
779 #ifndef NO_COMPABILITY
782 #ifndef NO_COMPABILITY
783 } else if (token == "\\begin_float") {
784 insertErtContents(par, pos);
785 //insertErtContents(par, pos, false);
786 //ert_stack.push(ert_comp);
787 //ert_comp = ErtComp();
789 // This is the compability reader. It can be removed in
790 // LyX version 1.3.0. (Lgb)
792 string const tmptok = lex.getString();
793 //lyxerr << "old float: " << tmptok << endl;
796 stringstream old_float;
798 if (tmptok == "footnote") {
799 inset = new InsetFoot(params);
800 old_float << "collapsed true\n";
801 } else if (tmptok == "margin") {
802 inset = new InsetMarginal(params);
803 old_float << "collapsed true\n";
804 } else if (tmptok == "fig") {
805 inset = new InsetFloat(params, "figure");
806 old_float << "wide false\n"
807 << "collapsed false\n";
808 } else if (tmptok == "tab") {
809 inset = new InsetFloat(params, "table");
810 old_float << "wide false\n"
811 << "collapsed false\n";
812 } else if (tmptok == "alg") {
813 inset = new InsetFloat(params, "algorithm");
814 old_float << "wide false\n"
815 << "collapsed false\n";
816 } else if (tmptok == "wide-fig") {
817 inset = new InsetFloat(params, "figure");
818 //InsetFloat * tmp = new InsetFloat("figure");
821 old_float << "wide true\n"
822 << "collapsed false\n";
823 } else if (tmptok == "wide-tab") {
824 inset = new InsetFloat(params, "table");
825 //InsetFloat * tmp = new InsetFloat("table");
828 old_float << "wide true\n"
829 << "collapsed false\n";
833 #ifndef NO_PEXTRA_REALLY
836 return false; // no end read yet
839 // Here we need to check for \end_deeper and handle that
840 // before we do the footnote parsing.
841 // This _is_ a hack! (Lgb)
844 string const tmp = lex.getString();
845 if (tmp == "\\end_deeper") {
846 //lyxerr << "\\end_deeper caught!" << endl;
848 lex.printError("\\end_deeper: "
849 "depth is already null");
854 old_float << tmp << ' ';
859 old_float << lex.getLongString("\\end_float")
860 << "\n\\end_inset\n";
861 //lyxerr << "Float Body:\n" << old_float.str() << endl;
862 // That this does not work seems like a bug
863 // in stringstream. (Lgb)
864 istringstream istr(old_float.str());
866 nylex.setStream(istr);
867 inset->read(this, nylex);
868 par->insertInset(pos, inset, font);
870 insertErtContents(par, pos);
872 // we have to reset the font as in the old format after a float
873 // the font was automatically reset!
874 font = LyXFont(LyXFont::ALL_INHERIT, params.language);
876 } else if (token == "\\begin_deeper") {
878 } else if (token == "\\end_deeper") {
880 lex.printError("\\end_deeper: "
881 "depth is already null");
885 } else if (token == "\\begin_preamble") {
886 params.readPreamble(lex);
887 } else if (token == "\\textclass") {
889 pair<bool, textclass_type> pp =
890 textclasslist.NumberOfClass(lex.getString());
892 params.textclass = pp.second;
894 Alert::alert(string(_("Textclass error")),
895 string(_("The document uses an unknown textclass \"")) +
896 lex.getString() + string("\"."),
897 string(_("LyX will not be able to produce output correctly.")));
898 params.textclass = 0;
900 if (!params.getLyXTextClass().load()) {
901 // if the textclass wasn't loaded properly
902 // we need to either substitute another
903 // or stop loading the file.
904 // I can substitute but I don't see how I can
905 // stop loading... ideas?? ARRae980418
906 Alert::alert(_("Textclass Loading Error!"),
907 string(_("Can't load textclass ")) +
908 params.getLyXTextClass().name(),
909 _("-- substituting default"));
910 params.textclass = 0;
912 } else if (token == "\\options") {
914 params.options = lex.getString();
915 } else if (token == "\\language") {
916 params.readLanguage(lex);
917 } else if (token == "\\fontencoding") {
919 } else if (token == "\\inputencoding") {
921 params.inputenc = lex.getString();
922 } else if (token == "\\graphics") {
923 params.readGraphicsDriver(lex);
924 } else if (token == "\\fontscheme") {
926 params.fonts = lex.getString();
927 } else if (token == "\\noindent") {
928 par->params().noindent(true);
929 } else if (token == "\\leftindent") {
931 LyXLength value(lex.getString());
932 par->params().leftIndent(value);
933 } else if (token == "\\fill_top") {
934 par->params().spaceTop(VSpace(VSpace::VFILL));
935 } else if (token == "\\fill_bottom") {
936 par->params().spaceBottom(VSpace(VSpace::VFILL));
937 } else if (token == "\\line_top") {
938 par->params().lineTop(true);
939 } else if (token == "\\line_bottom") {
940 par->params().lineBottom(true);
941 } else if (token == "\\pagebreak_top") {
942 par->params().pagebreakTop(true);
943 } else if (token == "\\pagebreak_bottom") {
944 par->params().pagebreakBottom(true);
945 } else if (token == "\\start_of_appendix") {
946 par->params().startOfAppendix(true);
947 } else if (token == "\\paragraph_separation") {
948 int tmpret = lex.findToken(string_paragraph_separation);
951 if (tmpret != LYX_LAYOUT_DEFAULT)
952 params.paragraph_separation =
953 static_cast<BufferParams::PARSEP>(tmpret);
954 } else if (token == "\\defskip") {
956 params.defskip = VSpace(lex.getString());
957 #ifndef NO_COMPABILITY
958 } else if (token == "\\epsfig") { // obsolete
959 // Indeed it is obsolete, but we HAVE to be backwards
960 // compatible until 0.14, because otherwise all figures
961 // in existing documents are irretrivably lost. (Asger)
962 params.readGraphicsDriver(lex);
964 } else if (token == "\\quotes_language") {
965 int tmpret = lex.findToken(string_quotes_language);
968 if (tmpret != LYX_LAYOUT_DEFAULT) {
969 InsetQuotes::quote_language tmpl =
970 InsetQuotes::EnglishQ;
973 tmpl = InsetQuotes::EnglishQ;
976 tmpl = InsetQuotes::SwedishQ;
979 tmpl = InsetQuotes::GermanQ;
982 tmpl = InsetQuotes::PolishQ;
985 tmpl = InsetQuotes::FrenchQ;
988 tmpl = InsetQuotes::DanishQ;
991 params.quotes_language = tmpl;
993 } else if (token == "\\quotes_times") {
995 switch (lex.getInteger()) {
997 params.quotes_times = InsetQuotes::SingleQ;
1000 params.quotes_times = InsetQuotes::DoubleQ;
1003 } else if (token == "\\papersize") {
1004 int tmpret = lex.findToken(string_papersize);
1008 params.papersize2 = tmpret;
1009 } else if (token == "\\paperpackage") {
1010 int tmpret = lex.findToken(string_paperpackages);
1013 params.paperpackage = BufferParams::PACKAGE_NONE;
1015 params.paperpackage = tmpret;
1016 } else if (token == "\\use_geometry") {
1018 params.use_geometry = lex.getInteger();
1019 } else if (token == "\\use_amsmath") {
1021 params.use_amsmath = lex.getInteger();
1022 } else if (token == "\\use_natbib") {
1024 params.use_natbib = lex.getInteger();
1025 } else if (token == "\\use_numerical_citations") {
1027 params.use_numerical_citations = lex.getInteger();
1028 } else if (token == "\\paperorientation") {
1029 int tmpret = lex.findToken(string_orientation);
1032 if (tmpret != LYX_LAYOUT_DEFAULT)
1033 params.orientation = static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
1034 } else if (token == "\\paperwidth") {
1036 params.paperwidth = lex.getString();
1037 } else if (token == "\\paperheight") {
1039 params.paperheight = lex.getString();
1040 } else if (token == "\\leftmargin") {
1042 params.leftmargin = lex.getString();
1043 } else if (token == "\\topmargin") {
1045 params.topmargin = lex.getString();
1046 } else if (token == "\\rightmargin") {
1048 params.rightmargin = lex.getString();
1049 } else if (token == "\\bottommargin") {
1051 params.bottommargin = lex.getString();
1052 } else if (token == "\\headheight") {
1054 params.headheight = lex.getString();
1055 } else if (token == "\\headsep") {
1057 params.headsep = lex.getString();
1058 } else if (token == "\\footskip") {
1060 params.footskip = lex.getString();
1061 } else if (token == "\\paperfontsize") {
1063 params.fontsize = rtrim(lex.getString());
1064 } else if (token == "\\papercolumns") {
1066 params.columns = lex.getInteger();
1067 } else if (token == "\\papersides") {
1069 switch (lex.getInteger()) {
1071 case 1: params.sides = LyXTextClass::OneSide; break;
1072 case 2: params.sides = LyXTextClass::TwoSides; break;
1074 } else if (token == "\\paperpagestyle") {
1076 params.pagestyle = rtrim(lex.getString());
1077 } else if (token == "\\bullet") {
1079 int const index = lex.getInteger();
1081 int temp_int = lex.getInteger();
1082 params.user_defined_bullets[index].setFont(temp_int);
1083 params.temp_bullets[index].setFont(temp_int);
1085 temp_int = lex.getInteger();
1086 params.user_defined_bullets[index].setCharacter(temp_int);
1087 params.temp_bullets[index].setCharacter(temp_int);
1089 temp_int = lex.getInteger();
1090 params.user_defined_bullets[index].setSize(temp_int);
1091 params.temp_bullets[index].setSize(temp_int);
1093 string const temp_str = lex.getString();
1094 if (temp_str != "\\end_bullet") {
1095 // this element isn't really necessary for
1096 // parsing but is easier for humans
1097 // to understand bullets. Put it back and
1098 // set a debug message?
1099 lex.printError("\\end_bullet expected, got" + temp_str);
1100 //how can I put it back?
1102 } else if (token == "\\bulletLaTeX") {
1103 // The bullet class should be able to read this.
1105 int const index = lex.getInteger();
1107 string temp_str = lex.getString();
1109 while (temp_str != "\\end_bullet") {
1110 // this loop structure is needed when user
1111 // enters an empty string since the first
1112 // thing returned will be the \\end_bullet
1114 // if the LaTeX entry has spaces. Each element
1115 // therefore needs to be read in turn
1116 sum_str += temp_str;
1118 temp_str = lex.getString();
1121 params.user_defined_bullets[index].setText(sum_str);
1122 params.temp_bullets[index].setText(sum_str);
1123 } else if (token == "\\secnumdepth") {
1125 params.secnumdepth = lex.getInteger();
1126 } else if (token == "\\tocdepth") {
1128 params.tocdepth = lex.getInteger();
1129 } else if (token == "\\spacing") {
1131 string const tmp = rtrim(lex.getString());
1132 Spacing::Space tmp_space = Spacing::Default;
1133 float tmp_val = 0.0;
1134 if (tmp == "single") {
1135 tmp_space = Spacing::Single;
1136 } else if (tmp == "onehalf") {
1137 tmp_space = Spacing::Onehalf;
1138 } else if (tmp == "double") {
1139 tmp_space = Spacing::Double;
1140 } else if (tmp == "other") {
1142 tmp_space = Spacing::Other;
1143 tmp_val = lex.getFloat();
1145 lex.printError("Unknown spacing token: '$$Token'");
1147 // Small hack so that files written with klyx will be
1148 // parsed correctly.
1150 par->params().spacing(Spacing(tmp_space, tmp_val));
1152 params.spacing.set(tmp_space, tmp_val);
1154 } else if (token == "\\paragraph_spacing") {
1156 string const tmp = rtrim(lex.getString());
1157 if (tmp == "single") {
1158 par->params().spacing(Spacing(Spacing::Single));
1159 } else if (tmp == "onehalf") {
1160 par->params().spacing(Spacing(Spacing::Onehalf));
1161 } else if (tmp == "double") {
1162 par->params().spacing(Spacing(Spacing::Double));
1163 } else if (tmp == "other") {
1165 par->params().spacing(Spacing(Spacing::Other,
1168 lex.printError("Unknown spacing token: '$$Token'");
1170 } else if (token == "\\float_placement") {
1172 params.float_placement = lex.getString();
1173 } else if (token == "\\align") {
1174 int tmpret = lex.findToken(string_align);
1175 if (tmpret == -1) ++tmpret;
1176 if (tmpret != LYX_LAYOUT_DEFAULT) { // tmpret != 99 ???
1177 int const tmpret2 = int(pow(2.0, tmpret));
1178 //lyxerr << "Tmpret2 = " << tmpret2 << endl;
1179 par->params().align(LyXAlignment(tmpret2));
1181 } else if (token == "\\added_space_top") {
1183 VSpace value = VSpace(lex.getString());
1184 // only add the length when value > 0 or
1186 if ((value.length().len().value() != 0) ||
1188 (value.kind() != VSpace::LENGTH))
1189 par->params().spaceTop(value);
1190 } else if (token == "\\added_space_bottom") {
1192 VSpace value = VSpace(lex.getString());
1193 // only add the length when value > 0 or
1195 if ((value.length().len().value() != 0) ||
1197 (value.kind() != VSpace::LENGTH))
1198 par->params().spaceBottom(value);
1199 #ifndef NO_COMPABILITY
1200 #ifndef NO_PEXTRA_REALLY
1201 } else if (token == "\\pextra_type") {
1203 par->params().pextraType(lex.getInteger());
1204 } else if (token == "\\pextra_width") {
1206 par->params().pextraWidth(lex.getString());
1207 } else if (token == "\\pextra_widthp") {
1209 par->params().pextraWidthp(lex.getString());
1210 } else if (token == "\\pextra_alignment") {
1212 par->params().pextraAlignment(lex.getInteger());
1213 } else if (token == "\\pextra_hfill") {
1215 par->params().pextraHfill(lex.getInteger());
1216 } else if (token == "\\pextra_start_minipage") {
1218 par->params().pextraStartMinipage(lex.getInteger());
1221 } else if (token == "\\labelwidthstring") {
1223 par->params().labelWidthString(lex.getString());
1224 // do not delete this token, it is still needed!
1225 } else if (token == "\\newline") {
1226 #ifndef NO_COMPABILITY
1227 if (!ert_comp.in_tabular && ert_comp.active) {
1228 ert_comp.contents += char(Paragraph::META_NEWLINE);
1230 // Since we cannot know it this is only a regular
1231 // newline or a tabular cell delimter we have to
1232 // handle the ERT here.
1233 insertErtContents(par, pos, false);
1235 par->insertChar(pos, Paragraph::META_NEWLINE, font);
1239 par->insertChar(pos, Paragraph::META_NEWLINE, font);
1242 } else if (token == "\\LyXTable") {
1243 #ifndef NO_COMPABILITY
1244 ert_comp.in_tabular = true;
1246 Inset * inset = new InsetTabular(*this);
1247 inset->read(this, lex);
1248 par->insertInset(pos, inset, font);
1250 } else if (token == "\\hfill") {
1251 par->insertChar(pos, Paragraph::META_HFILL, font);
1253 } else if (token == "\\protected_separator") { // obsolete
1254 // This is a backward compability thingie. (Lgb)
1255 // Remove it later some time...introduced with fileformat
1257 LyXLayout_ptr const & layout = par->layout();
1259 if (layout->free_spacing || par->isFreeSpacing()) {
1260 par->insertChar(pos, ' ', font);
1262 Inset * inset = new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
1263 par->insertInset(pos, inset, font);
1266 } else if (token == "\\bibitem") { // ale970302
1268 InsetCommandParams p("bibitem", "dummy");
1269 par->bibkey = new InsetBibKey(p);
1271 par->bibkey->read(this, lex);
1272 } else if (token == "\\the_end") {
1273 #ifndef NO_COMPABILITY
1274 // If we still have some ert active here we have to insert
1275 // it so we don't loose it. (Lgb)
1276 insertErtContents(par, pos);
1278 the_end_read = true;
1279 #ifndef NO_COMPABILITY
1280 #ifndef NO_PEXTRA_REALLY
1283 minipar = parBeforeMinipage = 0;
1287 #ifndef NO_COMPABILITY
1288 if (ert_comp.active) {
1289 ert_comp.contents += token;
1292 // This should be insurance for the future: (Asger)
1295 string const s = _("Unknown token: ") + token
1296 + " " + lex.text() + "\n";
1297 // we can do this here this way because we're actually reading
1298 // the buffer and don't care about LyXText right now.
1299 InsetError * new_inset = new InsetError(s);
1300 par->insertInset(pos, new_inset, LyXFont(LyXFont::ALL_INHERIT,
1303 #ifndef NO_COMPABILITY
1308 #ifndef NO_COMPABILITY
1309 #ifndef NO_PEXTRA_REALLY
1310 // I wonder if we could use this blanket fix for all the
1311 // checkminipage cases...
1312 // don't forget about ert paragraphs and compatibility read for'em
1313 if (par && (par->size() || !ert_comp.contents.empty())) {
1314 // It is possible that this will check to often,
1315 // but that should not be an correctness issue.
1316 // Only a speed issue.
1317 checkminipage = true;
1320 // now check if we have a minipage paragraph as at this
1321 // point we already read all the necessary data!
1322 // this cannot be done in layout because there we did
1323 // not read yet the paragraph PEXTRA-params (Jug)
1325 // BEGIN pextra_minipage compability
1326 // This should be removed in 1.3.x (Lgb)
1327 // I don't think we should remove this so fast (Jug)
1329 // This compability code is not perfect. In a couple
1330 // of rand cases it fails. When the minipage par is
1331 // the first par in the document, and when there are
1332 // none or only one regular paragraphs after the
1333 // minipage. Currently I am not investing any effort
1334 // in fixing those cases.
1336 // lyxerr << "Call depth: " << call_depth << endl;
1337 // lyxerr << "Checkminipage: " << checkminipage << endl;
1339 if (checkminipage && (call_depth == 1)) {
1340 checkminipage = false;
1341 if (minipar && (minipar != par) &&
1342 (par->params().pextraType() == Paragraph::PEXTRA_MINIPAGE)) {
1343 lyxerr << "minipages in a row" << endl;
1344 if (par->params().pextraStartMinipage()) {
1345 lyxerr << "start new minipage" << endl;
1346 // minipages in a row
1347 par->previous()->next(0);
1350 Paragraph * tmp = minipar;
1352 tmp->params().pextraType(0);
1353 tmp->params().pextraWidth(string());
1354 tmp->params().pextraWidthp(string());
1355 tmp->params().pextraAlignment(0);
1356 tmp->params().pextraHfill(false);
1357 tmp->params().pextraStartMinipage(false);
1360 // create a new paragraph to insert the
1361 // minipages in the following case
1362 if (par->params().pextraStartMinipage() &&
1363 !par->params().pextraHfill()) {
1364 Paragraph * p = new Paragraph;
1365 p->layout(params.getLyXTextClass().defaultLayoutName());
1367 p->previous(parBeforeMinipage);
1368 parBeforeMinipage->next(p);
1370 p->params().depth(parBeforeMinipage->params().depth());
1371 parBeforeMinipage = p;
1373 InsetMinipage * mini = new InsetMinipage(params);
1374 mini->pos(static_cast<InsetMinipage::Position>(par->params().pextraAlignment()));
1375 mini->pageWidth(LyXLength(par->params().pextraWidth()));
1376 if (!par->params().pextraWidthp().empty()) {
1377 lyxerr << "WP:" << mini->pageWidth().asString() << endl;
1378 mini->pageWidth(LyXLength((par->params().pextraWidthp())+"col%"));
1380 Paragraph * op = mini->firstParagraph();
1381 mini->inset.paragraph(par);
1383 // and free the old ones!
1386 Paragraph * pp = op->next();
1390 // Insert the minipage last in the
1391 // previous paragraph.
1392 if (par->params().pextraHfill()) {
1393 parBeforeMinipage->insertChar
1394 (parBeforeMinipage->size(),
1395 Paragraph::META_HFILL, font);
1397 parBeforeMinipage->insertInset
1398 (parBeforeMinipage->size(), mini, font);
1402 lyxerr << "new minipage par" << endl;
1403 //nothing to do just continue reading
1406 } else if (minipar && (minipar != par)) {
1407 lyxerr << "last minipage par read" << endl;
1408 // The last paragraph read was not part of a
1409 // minipage but the par linked list is...
1410 // So we need to remove the last par from the
1412 if (par->previous())
1413 par->previous()->next(0);
1414 par->previous(parBeforeMinipage);
1415 parBeforeMinipage->next(par);
1416 Paragraph * tmp = minipar;
1418 tmp->params().pextraType(0);
1419 tmp->params().pextraWidth(string());
1420 tmp->params().pextraWidthp(string());
1421 tmp->params().pextraAlignment(0);
1422 tmp->params().pextraHfill(false);
1423 tmp->params().pextraStartMinipage(false);
1426 depth = parBeforeMinipage->params().depth();
1427 // and set this depth on the par as it has not been set already
1428 par->params().depth(depth);
1429 minipar = parBeforeMinipage = 0;
1430 } else if (!minipar &&
1431 (par->params().pextraType() == Paragraph::PEXTRA_MINIPAGE)) {
1432 // par is the first paragraph in a minipage
1433 lyxerr << "begin minipage" << endl;
1434 // To minimize problems for
1435 // the users we will insert
1436 // the first minipage in
1437 // a sequence of minipages
1438 // in its own paragraph.
1439 Paragraph * p = new Paragraph;
1440 p->layout(params.getLyXTextClass().defaultLayoutName());
1441 p->previous(par->previous());
1443 p->params().depth(depth);
1444 par->params().depth(0);
1446 if (par->previous())
1447 par->previous()->next(p);
1449 parBeforeMinipage = p;
1451 if (!first_par || (first_par == par))
1454 InsetMinipage * mini = new InsetMinipage(params);
1455 mini->pos(static_cast<InsetMinipage::Position>(minipar->params().pextraAlignment()));
1456 mini->pageWidth(LyXLength(minipar->params().pextraWidth()));
1457 if (!par->params().pextraWidthp().empty()) {
1458 lyxerr << "WP:" << mini->pageWidth().asString() << endl;
1459 mini->pageWidth(LyXLength((par->params().pextraWidthp())+"col%"));
1462 Paragraph * op = mini->firstParagraph();
1463 mini->inset.paragraph(minipar);
1465 // and free the old ones!
1468 Paragraph * pp = op->next();
1473 // Insert the minipage last in the
1474 // previous paragraph.
1475 if (minipar->params().pextraHfill()) {
1476 parBeforeMinipage->insertChar
1477 (parBeforeMinipage->size(),
1478 Paragraph::META_HFILL, font);
1480 parBeforeMinipage->insertInset
1481 (parBeforeMinipage->size(), mini, font);
1482 } else if (par->params().pextraType() == Paragraph::PEXTRA_INDENT) {
1483 par->params().leftIndent(LyXLength(par->params().pextraWidth()));
1484 if (!par->params().pextraWidthp().empty()) {
1485 par->params().leftIndent(LyXLength((par->params().pextraWidthp())+"col%"));
1489 // End of pextra_minipage compability
1493 return the_end_read;
1496 // needed to insert the selection
1497 void Buffer::insertStringAsLines(Paragraph *& par, pos_type & pos,
1498 LyXFont const & fn,string const & str) const
1500 LyXLayout_ptr const & layout = par->layout();
1504 par->checkInsertChar(font);
1505 // insert the string, don't insert doublespace
1506 bool space_inserted = true;
1507 bool autobreakrows = !par->inInset() ||
1508 static_cast<InsetText *>(par->inInset())->getAutoBreakRows();
1509 for(string::const_iterator cit = str.begin();
1510 cit != str.end(); ++cit) {
1512 if (autobreakrows && (par->size() || layout->keepempty)) {
1513 par->breakParagraph(params, pos,
1514 layout->isEnvironment());
1517 space_inserted = true;
1521 // do not insert consecutive spaces if !free_spacing
1522 } else if ((*cit == ' ' || *cit == '\t') &&
1523 space_inserted && !layout->free_spacing &&
1524 !par->isFreeSpacing())
1527 } else if (*cit == '\t') {
1528 if (!layout->free_spacing && !par->isFreeSpacing()) {
1529 // tabs are like spaces here
1530 par->insertChar(pos, ' ', font);
1532 space_inserted = true;
1534 const pos_type nb = 8 - pos % 8;
1535 for (pos_type a = 0; a < nb ; ++a) {
1536 par->insertChar(pos, ' ', font);
1539 space_inserted = true;
1541 } else if (!IsPrintable(*cit)) {
1542 // Ignore unprintables
1545 // just insert the character
1546 par->insertChar(pos, *cit, font);
1548 space_inserted = (*cit == ' ');
1555 void Buffer::readInset(LyXLex & lex, Paragraph *& par,
1556 int & pos, LyXFont & font)
1558 // consistency check
1559 if (lex.getString() != "\\begin_inset") {
1560 lyxerr << "Buffer::readInset: Consistency check failed."
1567 string const tmptok = lex.getString();
1568 last_inset_read = tmptok;
1570 // test the different insets
1571 if (tmptok == "LatexCommand") {
1572 InsetCommandParams inscmd;
1575 string const cmdName = inscmd.getCmdName();
1577 // This strange command allows LyX to recognize "natbib" style
1578 // citations: citet, citep, Citet etc.
1579 if (compare_ascii_no_case(cmdName.substr(0,4), "cite") == 0) {
1580 inset = new InsetCitation(inscmd);
1581 } else if (cmdName == "bibitem") {
1582 lex.printError("Wrong place for bibitem");
1583 inset = new InsetBibKey(inscmd);
1584 } else if (cmdName == "BibTeX") {
1585 inset = new InsetBibtex(inscmd);
1586 } else if (cmdName == "index") {
1587 inset = new InsetIndex(inscmd);
1588 } else if (cmdName == "include") {
1589 inset = new InsetInclude(inscmd, *this);
1590 } else if (cmdName == "label") {
1591 inset = new InsetLabel(inscmd);
1592 } else if (cmdName == "url"
1593 || cmdName == "htmlurl") {
1594 inset = new InsetUrl(inscmd);
1595 } else if (cmdName == "ref"
1596 || cmdName == "pageref"
1597 || cmdName == "vref"
1598 || cmdName == "vpageref"
1599 || cmdName == "prettyref") {
1600 if (!inscmd.getOptions().empty()
1601 || !inscmd.getContents().empty()) {
1602 inset = new InsetRef(inscmd, *this);
1604 } else if (cmdName == "tableofcontents") {
1605 inset = new InsetTOC(inscmd);
1606 } else if (cmdName == "listofalgorithms") {
1607 inset = new InsetFloatList("algorithm");
1608 } else if (cmdName == "listoffigures") {
1609 inset = new InsetFloatList("figure");
1610 } else if (cmdName == "listoftables") {
1611 inset = new InsetFloatList("table");
1612 } else if (cmdName == "printindex") {
1613 inset = new InsetPrintIndex(inscmd);
1614 } else if (cmdName == "lyxparent") {
1615 inset = new InsetParent(inscmd, *this);
1618 bool alreadyread = false;
1619 if (tmptok == "Quotes") {
1620 inset = new InsetQuotes;
1621 } else if (tmptok == "External") {
1622 inset = new InsetExternal;
1623 } else if (tmptok == "FormulaMacro") {
1624 inset = new InsetFormulaMacro;
1625 } else if (tmptok == "Formula") {
1626 inset = new InsetFormula;
1627 } else if (tmptok == "Figure") { // Backward compatibility
1628 // inset = new InsetFig(100, 100, *this);
1629 inset = new InsetGraphics;
1630 } else if (tmptok == "Graphics") {
1631 inset = new InsetGraphics;
1632 } else if (tmptok == "Info") {// backwards compatibility
1633 inset = new InsetNote(this,
1634 lex.getLongString("\\end_inset"),
1637 } else if (tmptok == "Note") {
1638 inset = new InsetNote(params);
1639 } else if (tmptok == "Include") {
1640 InsetCommandParams p("Include");
1641 inset = new InsetInclude(p, *this);
1642 } else if (tmptok == "ERT") {
1643 inset = new InsetERT(params);
1644 } else if (tmptok == "Tabular") {
1645 inset = new InsetTabular(*this);
1646 } else if (tmptok == "Text") {
1647 inset = new InsetText(params);
1648 } else if (tmptok == "Foot") {
1649 inset = new InsetFoot(params);
1650 } else if (tmptok == "Marginal") {
1651 inset = new InsetMarginal(params);
1652 } else if (tmptok == "Minipage") {
1653 inset = new InsetMinipage(params);
1654 } else if (tmptok == "Float") {
1656 string tmptok = lex.getString();
1657 inset = new InsetFloat(params, tmptok);
1659 } else if (tmptok == "List") {
1660 inset = new InsetList;
1661 } else if (tmptok == "Theorem") {
1662 inset = new InsetList;
1664 } else if (tmptok == "Caption") {
1665 inset = new InsetCaption(params);
1666 } else if (tmptok == "FloatList") {
1667 inset = new InsetFloatList;
1670 if (inset && !alreadyread) inset->read(this, lex);
1674 par->insertInset(pos, inset, font);
1680 bool Buffer::readFile(LyXLex & lex, Paragraph * par)
1684 string const token(lex.getString());
1685 if (token == "\\lyxformat") { // the first token _must_ be...
1687 string tmp_format = lex.getString();
1688 //lyxerr << "LyX Format: `" << tmp_format << "'" << endl;
1689 // if present remove ".," from string.
1690 string::size_type dot = tmp_format.find_first_of(".,");
1691 //lyxerr << " dot found at " << dot << endl;
1692 if (dot != string::npos)
1693 tmp_format.erase(dot, 1);
1694 file_format = strToInt(tmp_format);
1695 if (file_format == LYX_FORMAT) {
1697 } else if (file_format > LYX_FORMAT) {
1699 Alert::alert(_("Warning!"),
1700 _("LyX file format is newer that what"),
1701 _("is supported in this LyX version. Expect some problems."));
1703 } else if (file_format < LYX_FORMAT) {
1705 if (file_format < 200) {
1706 Alert::alert(_("ERROR!"),
1707 _("Old LyX file format found. "
1708 "Use LyX 0.10.x to read this!"));
1710 } else if (file_format < 220) {
1711 string const command = "lyx2lyx "
1712 + QuoteName(filename_);
1713 cmd_ret const ret = RunCommand(command);
1715 Alert::alert(_("ERROR!"),
1716 _("An error occured while "
1717 "running the conversion script."));
1720 istringstream is(ret.second);
1721 LyXLex tmplex(0, 0);
1722 tmplex.setStream(is);
1723 return readFile(tmplex);
1726 bool the_end = readLyXformat2(lex, par);
1727 params.setPaperStuff();
1730 // the_end was added in 213
1731 if (file_format < 213)
1736 Alert::alert(_("Warning!"),
1737 _("Reading of document is not complete"),
1738 _("Maybe the document is truncated"));
1741 } else { // "\\lyxformat" not found
1742 Alert::alert(_("ERROR!"), _("Not a LyX file!"));
1745 Alert::alert(_("ERROR!"), _("Unable to read file!"));
1750 // Should probably be moved to somewhere else: BufferView? LyXView?
1751 bool Buffer::save() const
1753 // We don't need autosaves in the immediate future. (Asger)
1754 resetAutosaveTimers();
1758 if (lyxrc.make_backup) {
1759 s = fileName() + '~';
1760 if (!lyxrc.backupdir_path.empty())
1761 s = AddName(lyxrc.backupdir_path,
1762 subst(os::slashify_path(s),'/','!'));
1764 // Rename is the wrong way of making a backup,
1765 // this is the correct way.
1766 /* truss cp fil fil2:
1767 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
1768 stat("LyXVC.lyx", 0xEFFFF688) = 0
1769 open("LyXVC.lyx", O_RDONLY) = 3
1770 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
1771 fstat(4, 0xEFFFF508) = 0
1772 fstat(3, 0xEFFFF508) = 0
1773 read(3, " # T h i s f i l e w".., 8192) = 5579
1774 write(4, " # T h i s f i l e w".., 5579) = 5579
1775 read(3, 0xEFFFD4A0, 8192) = 0
1778 chmod("LyXVC3.lyx", 0100644) = 0
1779 lseek(0, 0, SEEK_CUR) = 46440
1783 // Should probably have some more error checking here.
1784 // Doing it this way, also makes the inodes stay the same.
1785 // This is still not a very good solution, in particular we
1786 // might loose the owner of the backup.
1787 FileInfo finfo(fileName());
1788 if (finfo.exist()) {
1789 mode_t fmode = finfo.getMode();
1790 struct utimbuf times = {
1791 finfo.getAccessTime(),
1792 finfo.getModificationTime() };
1794 ifstream ifs(fileName().c_str());
1795 ofstream ofs(s.c_str(), ios::out|ios::trunc);
1800 ::chmod(s.c_str(), fmode);
1802 if (::utime(s.c_str(), ×)) {
1803 lyxerr << "utime error." << endl;
1806 lyxerr << "LyX was not able to make "
1807 "backup copy. Beware." << endl;
1812 if (writeFile(fileName())) {
1814 removeAutosaveFile(fileName());
1816 // Saving failed, so backup is not backup
1817 if (lyxrc.make_backup) {
1818 lyx::rename(s, fileName());
1826 bool Buffer::writeFile(string const & fname) const
1828 if (read_only && (fname == fileName())) {
1832 FileInfo finfo(fname);
1833 if (finfo.exist() && !finfo.writable()) {
1837 ofstream ofs(fname.c_str());
1843 // Use the standard "C" locale for file output.
1844 ofs.imbue(std::locale::classic());
1847 // The top of the file should not be written by params.
1849 // write out a comment in the top of the file
1850 ofs << '#' << lyx_docversion
1851 << " created this file. For more info see http://www.lyx.org/\n"
1852 << "\\lyxformat " << LYX_FORMAT << "\n";
1854 // now write out the buffer paramters.
1855 params.writeFile(ofs);
1857 Paragraph::depth_type depth = 0;
1859 // this will write out all the paragraphs
1860 // using recursive descent.
1861 paragraph->writeFile(this, ofs, params, depth);
1863 // Write marker that shows file is complete
1864 ofs << "\n\\the_end" << endl;
1868 // how to check if close went ok?
1869 // Following is an attempt... (BE 20001011)
1871 // good() returns false if any error occured, including some
1872 // formatting error.
1873 // bad() returns true if something bad happened in the buffer,
1874 // which should include file system full errors.
1881 lyxerr << "Buffer::writeFile: BAD ERROR!" << endl;
1883 lyxerr << "Buffer::writeFile: NOT SO BAD ERROR!"
1895 pair<int, string> const addDepth(int depth, int ldepth)
1899 d += (ldepth - depth) * 2;
1900 return make_pair(d, string(d, ' '));
1906 string const Buffer::asciiParagraph(Paragraph const * par,
1907 unsigned int linelen,
1908 bool noparbreak) const
1910 ostringstream buffer;
1911 Paragraph::depth_type depth = 0;
1913 Paragraph::depth_type ltype_depth = 0;
1914 bool ref_printed = false;
1915 // if (!par->previous()) {
1917 // begins or ends a deeper area ?
1918 if (depth != par->params().depth()) {
1919 if (par->params().depth() > depth) {
1920 while (par->params().depth() > depth) {
1924 while (par->params().depth() < depth) {
1930 depth = par->params().depth();
1933 // First write the layout
1934 string const & tmp = par->layout()->name();
1935 if (compare_no_case(tmp, "itemize") == 0) {
1937 ltype_depth = depth + 1;
1938 } else if (compare_ascii_no_case(tmp, "enumerate") == 0) {
1940 ltype_depth = depth + 1;
1941 } else if (contains(ascii_lowercase(tmp), "ection")) {
1943 ltype_depth = depth + 1;
1944 } else if (contains(ascii_lowercase(tmp), "aragraph")) {
1946 ltype_depth = depth + 1;
1947 } else if (compare_ascii_no_case(tmp, "description") == 0) {
1949 ltype_depth = depth + 1;
1950 } else if (compare_ascii_no_case(tmp, "abstract") == 0) {
1953 } else if (compare_ascii_no_case(tmp, "bibliography") == 0) {
1961 /* maybe some vertical spaces */
1963 /* the labelwidthstring used in lists */
1967 /* some pagebreaks? */
1971 /* what about the alignment */
1973 // lyxerr << "Should this ever happen?" << endl;
1976 // linelen <= 0 is special and means we don't have pargraph breaks
1978 string::size_type currlinelen = 0;
1984 buffer << string(depth * 2, ' ');
1985 currlinelen += depth * 2;
1988 // we should probably change to the paragraph language in the
1989 // gettext here (if possible) so that strings are outputted in
1990 // the correct language! (20012712 Jug)
1994 case 4: // (Sub)Paragraph
1995 case 5: // Description
1999 buffer << _("Abstract") << "\n\n";
2002 string const abst = _("Abstract: ");
2004 currlinelen += abst.length();
2007 case 7: // Bibliography
2010 buffer << _("References") << "\n\n";
2013 string const refs = _("References: ");
2015 currlinelen += refs.length();
2023 string const parlab = par->params().labelString();
2024 buffer << parlab << " ";
2025 currlinelen += parlab.length() + 1;
2033 pair<int, string> p = addDepth(depth, ltype_depth);
2035 currlinelen += p.first;
2038 // this is to change the linebreak to do it by word a bit more
2039 // intelligent hopefully! (only in the case where we have a
2040 // max linelenght!) (Jug)
2044 for (pos_type i = 0; i < par->size(); ++i) {
2045 char c = par->getUChar(params, i);
2047 case Paragraph::META_INSET:
2049 Inset const * inset = par->getInset(i);
2053 currlinelen += word.length();
2056 if (inset->ascii(this, buffer, linelen)) {
2057 // to be sure it breaks paragraph
2058 currlinelen += linelen;
2064 case Paragraph::META_NEWLINE:
2066 buffer << word << "\n";
2069 pair<int, string> p = addDepth(depth,
2072 currlinelen = p.first;
2076 case Paragraph::META_HFILL:
2077 buffer << word << "\t";
2078 currlinelen += word.length() + 1;
2085 currlinelen + word.length() > linelen - 10) {
2087 pair<int, string> p =
2088 addDepth(depth, ltype_depth);
2090 currlinelen = p.first;
2093 buffer << word << ' ';
2094 currlinelen += word.length() + 1;
2101 lyxerr[Debug::INFO] <<
2102 "writeAsciiFile: NULL char in structure." << endl;
2104 if ((linelen > 0) &&
2105 (currlinelen + word.length()) > linelen)
2109 pair<int, string> p =
2110 addDepth(depth, ltype_depth);
2112 currlinelen = p.first;
2119 return buffer.str().c_str();
2123 void Buffer::writeFileAscii(string const & fname, int linelen)
2125 ofstream ofs(fname.c_str());
2127 Alert::err_alert(_("Error: Cannot write file:"), fname);
2130 writeFileAscii(ofs, linelen);
2134 void Buffer::writeFileAscii(ostream & ofs, int linelen)
2136 Paragraph * par = paragraph;
2138 ofs << asciiParagraph(par, linelen, par->previous() == 0);
2148 void Buffer::makeLaTeXFile(string const & fname,
2149 string const & original_path,
2150 bool nice, bool only_body, bool only_preamble)
2152 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
2154 ofstream ofs(fname.c_str());
2156 Alert::err_alert(_("Error: Cannot open file: "), fname);
2160 makeLaTeXFile(ofs, original_path, nice, only_body, only_preamble);
2164 lyxerr << "File was not closed properly." << endl;
2169 void Buffer::makeLaTeXFile(ostream & os,
2170 string const & original_path,
2171 bool nice, bool only_body, bool only_preamble)
2173 niceFile = nice; // this will be used by Insetincludes.
2175 tex_code_break_column = lyxrc.ascii_linelen;
2177 // validate the buffer.
2178 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
2179 LaTeXFeatures features(params);
2181 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
2184 // The starting paragraph of the coming rows is the
2185 // first paragraph of the document. (Asger)
2186 texrow.start(paragraph, 0);
2188 if (!only_body && nice) {
2189 os << "%% " << lyx_docversion << " created this file. "
2190 "For more info, see http://www.lyx.org/.\n"
2191 "%% Do not edit unless you really know what "
2196 lyxerr[Debug::INFO] << "lyx header finished" << endl;
2197 // There are a few differences between nice LaTeX and usual files:
2198 // usual is \batchmode and has a
2199 // special input@path to allow the including of figures
2200 // with either \input or \includegraphics (what figinsets do).
2201 // batchmode is not set if there is a tex_code_break_column.
2202 // In this case somebody is interested in the generated LaTeX,
2203 // so this is OK. input@path is set when the actual parameter
2204 // original_path is set. This is done for usual tex-file, but not
2205 // for nice-latex-file. (Matthias 250696)
2208 // code for usual, NOT nice-latex-file
2209 os << "\\batchmode\n"; // changed
2210 // from \nonstopmode
2213 if (!original_path.empty()) {
2214 string inputpath = os::external_path(original_path);
2215 subst(inputpath, "~", "\\string~");
2216 os << "\\makeatletter\n"
2217 << "\\def\\input@path{{"
2218 << inputpath << "/}}\n"
2219 << "\\makeatother\n";
2225 os << "\\documentclass";
2227 LyXTextClass const & tclass = params.getLyXTextClass();
2229 ostringstream options; // the document class options.
2231 if (tokenPos(tclass.opt_fontsize(),
2232 '|', params.fontsize) >= 0) {
2233 // only write if existing in list (and not default)
2234 options << params.fontsize << "pt,";
2238 if (!params.use_geometry &&
2239 (params.paperpackage == BufferParams::PACKAGE_NONE)) {
2240 switch (params.papersize) {
2241 case BufferParams::PAPER_A4PAPER:
2242 options << "a4paper,";
2244 case BufferParams::PAPER_USLETTER:
2245 options << "letterpaper,";
2247 case BufferParams::PAPER_A5PAPER:
2248 options << "a5paper,";
2250 case BufferParams::PAPER_B5PAPER:
2251 options << "b5paper,";
2253 case BufferParams::PAPER_EXECUTIVEPAPER:
2254 options << "executivepaper,";
2256 case BufferParams::PAPER_LEGALPAPER:
2257 options << "legalpaper,";
2263 if (params.sides != tclass.sides()) {
2264 switch (params.sides) {
2265 case LyXTextClass::OneSide:
2266 options << "oneside,";
2268 case LyXTextClass::TwoSides:
2269 options << "twoside,";
2275 if (params.columns != tclass.columns()) {
2276 if (params.columns == 2)
2277 options << "twocolumn,";
2279 options << "onecolumn,";
2282 if (!params.use_geometry
2283 && params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
2284 options << "landscape,";
2286 // language should be a parameter to \documentclass
2288 ostringstream language_options;
2289 if (params.language->babel() == "hebrew"
2290 && default_language->babel() != "hebrew")
2291 // This seems necessary
2292 features.useLanguage(default_language);
2294 if (lyxrc.language_use_babel ||
2295 params.language->lang() != lyxrc.default_language ||
2296 features.hasLanguages()) {
2298 language_options << features.getLanguages();
2299 language_options << params.language->babel();
2300 if (lyxrc.language_global_options)
2301 options << language_options.str() << ',';
2304 // the user-defined options
2305 if (!params.options.empty()) {
2306 options << params.options << ',';
2309 string strOptions(options.str().c_str());
2310 if (!strOptions.empty()) {
2311 strOptions = rtrim(strOptions, ",");
2312 os << '[' << strOptions << ']';
2315 os << '{' << tclass.latexname() << "}\n";
2317 // end of \documentclass defs
2319 // font selection must be done before loading fontenc.sty
2320 // The ae package is not needed when using OT1 font encoding.
2321 if (params.fonts != "default" &&
2322 (params.fonts != "ae" || lyxrc.fontenc != "default")) {
2323 os << "\\usepackage{" << params.fonts << "}\n";
2325 if (params.fonts == "ae") {
2326 os << "\\usepackage{aecompl}\n";
2330 // this one is not per buffer
2331 if (lyxrc.fontenc != "default") {
2332 os << "\\usepackage[" << lyxrc.fontenc
2337 if (params.inputenc == "auto") {
2338 string const doc_encoding =
2339 params.language->encoding()->LatexName();
2341 // Create a list with all the input encodings used
2343 set<string> encodings = features.getEncodingSet(doc_encoding);
2345 os << "\\usepackage[";
2346 std::copy(encodings.begin(), encodings.end(),
2347 std::ostream_iterator<string>(os, ","));
2348 os << doc_encoding << "]{inputenc}\n";
2350 } else if (params.inputenc != "default") {
2351 os << "\\usepackage[" << params.inputenc
2356 // At the very beginning the text parameters.
2357 if (params.paperpackage != BufferParams::PACKAGE_NONE) {
2358 switch (params.paperpackage) {
2359 case BufferParams::PACKAGE_A4:
2360 os << "\\usepackage{a4}\n";
2363 case BufferParams::PACKAGE_A4WIDE:
2364 os << "\\usepackage{a4wide}\n";
2367 case BufferParams::PACKAGE_WIDEMARGINSA4:
2368 os << "\\usepackage[widemargins]{a4}\n";
2373 if (params.use_geometry) {
2374 os << "\\usepackage{geometry}\n";
2376 os << "\\geometry{verbose";
2377 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
2379 switch (params.papersize2) {
2380 case BufferParams::VM_PAPER_CUSTOM:
2381 if (!params.paperwidth.empty())
2382 os << ",paperwidth="
2383 << params.paperwidth;
2384 if (!params.paperheight.empty())
2385 os << ",paperheight="
2386 << params.paperheight;
2388 case BufferParams::VM_PAPER_USLETTER:
2389 os << ",letterpaper";
2391 case BufferParams::VM_PAPER_USLEGAL:
2392 os << ",legalpaper";
2394 case BufferParams::VM_PAPER_USEXECUTIVE:
2395 os << ",executivepaper";
2397 case BufferParams::VM_PAPER_A3:
2400 case BufferParams::VM_PAPER_A4:
2403 case BufferParams::VM_PAPER_A5:
2406 case BufferParams::VM_PAPER_B3:
2409 case BufferParams::VM_PAPER_B4:
2412 case BufferParams::VM_PAPER_B5:
2416 // default papersize ie BufferParams::VM_PAPER_DEFAULT
2417 switch (lyxrc.default_papersize) {
2418 case BufferParams::PAPER_DEFAULT: // keep compiler happy
2419 case BufferParams::PAPER_USLETTER:
2420 os << ",letterpaper";
2422 case BufferParams::PAPER_LEGALPAPER:
2423 os << ",legalpaper";
2425 case BufferParams::PAPER_EXECUTIVEPAPER:
2426 os << ",executivepaper";
2428 case BufferParams::PAPER_A3PAPER:
2431 case BufferParams::PAPER_A4PAPER:
2434 case BufferParams::PAPER_A5PAPER:
2437 case BufferParams::PAPER_B5PAPER:
2442 if (!params.topmargin.empty())
2443 os << ",tmargin=" << params.topmargin;
2444 if (!params.bottommargin.empty())
2445 os << ",bmargin=" << params.bottommargin;
2446 if (!params.leftmargin.empty())
2447 os << ",lmargin=" << params.leftmargin;
2448 if (!params.rightmargin.empty())
2449 os << ",rmargin=" << params.rightmargin;
2450 if (!params.headheight.empty())
2451 os << ",headheight=" << params.headheight;
2452 if (!params.headsep.empty())
2453 os << ",headsep=" << params.headsep;
2454 if (!params.footskip.empty())
2455 os << ",footskip=" << params.footskip;
2460 if (tokenPos(tclass.opt_pagestyle(),
2461 '|', params.pagestyle) >= 0) {
2462 if (params.pagestyle == "fancy") {
2463 os << "\\usepackage{fancyhdr}\n";
2466 os << "\\pagestyle{" << params.pagestyle << "}\n";
2470 if (params.secnumdepth != tclass.secnumdepth()) {
2471 os << "\\setcounter{secnumdepth}{"
2472 << params.secnumdepth
2476 if (params.tocdepth != tclass.tocdepth()) {
2477 os << "\\setcounter{tocdepth}{"
2483 if (params.paragraph_separation) {
2484 switch (params.defskip.kind()) {
2485 case VSpace::SMALLSKIP:
2486 os << "\\setlength\\parskip{\\smallskipamount}\n";
2488 case VSpace::MEDSKIP:
2489 os << "\\setlength\\parskip{\\medskipamount}\n";
2491 case VSpace::BIGSKIP:
2492 os << "\\setlength\\parskip{\\bigskipamount}\n";
2494 case VSpace::LENGTH:
2495 os << "\\setlength\\parskip{"
2496 << params.defskip.length().asLatexString()
2499 default: // should never happen // Then delete it.
2500 os << "\\setlength\\parskip{\\medskipamount}\n";
2505 os << "\\setlength\\parindent{0pt}\n";
2509 // Now insert the LyX specific LaTeX commands...
2511 // The optional packages;
2512 string preamble(features.getPackages());
2514 // this might be useful...
2515 preamble += "\n\\makeatletter\n";
2517 // Some macros LyX will need
2518 string tmppreamble(features.getMacros());
2520 if (!tmppreamble.empty()) {
2521 preamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2522 "LyX specific LaTeX commands.\n"
2523 + tmppreamble + '\n';
2526 // the text class specific preamble
2527 tmppreamble = features.getTClassPreamble();
2528 if (!tmppreamble.empty()) {
2529 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2530 "Textclass specific LaTeX commands.\n"
2531 + tmppreamble + '\n';
2534 /* the user-defined preamble */
2535 if (!params.preamble.empty()) {
2536 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2537 "User specified LaTeX commands.\n"
2538 + params.preamble + '\n';
2541 // Itemize bullet settings need to be last in case the user
2542 // defines their own bullets that use a package included
2543 // in the user-defined preamble -- ARRae
2544 // Actually it has to be done much later than that
2545 // since some packages like frenchb make modifications
2546 // at \begin{document} time -- JMarc
2548 for (int i = 0; i < 4; ++i) {
2549 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
2550 if (bullets_def.empty())
2551 bullets_def="\\AtBeginDocument{\n";
2552 bullets_def += " \\renewcommand{\\labelitemi";
2554 // `i' is one less than the item to modify
2561 bullets_def += "ii";
2567 bullets_def += "}{" +
2568 params.user_defined_bullets[i].getText()
2573 if (!bullets_def.empty())
2574 preamble += bullets_def + "}\n\n";
2577 int(lyx::count(preamble.begin(), preamble.end(), '\n'));
2578 for (int j = 0; j != nlines; ++j) {
2582 // We try to load babel late, in case it interferes
2583 // with other packages.
2585 string tmp = lyxrc.language_package;
2586 if (!lyxrc.language_global_options
2587 && tmp == "\\usepackage{babel}")
2588 tmp = string("\\usepackage[") +
2589 language_options.str().c_str() +
2591 preamble += tmp + "\n";
2592 preamble += features.getBabelOptions();
2595 preamble += "\\makeatother\n";
2603 os << "\\begin{document}\n";
2606 lyxerr[Debug::INFO] << "preamble finished, now the body." << endl;
2608 if (!lyxrc.language_auto_begin) {
2609 os << subst(lyxrc.language_command_begin, "$$lang",
2610 params.language->babel())
2615 latexParagraphs(os, paragraph, 0, texrow);
2617 // add this just in case after all the paragraphs
2621 if (!lyxrc.language_auto_end) {
2622 os << subst(lyxrc.language_command_end, "$$lang",
2623 params.language->babel())
2629 os << "\\end{document}\n";
2632 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
2634 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
2638 // Just to be sure. (Asger)
2641 // tex_code_break_column's value is used to decide
2642 // if we are in batchmode or not (within mathed_write()
2643 // in math_write.C) so we must set it to a non-zero
2644 // value when we leave otherwise we save incorrect .lyx files.
2645 tex_code_break_column = lyxrc.ascii_linelen;
2647 lyxerr[Debug::INFO] << "Finished making latex file." << endl;
2648 lyxerr[Debug::INFO] << "Row count was " << texrow.rows()-1 << "." << endl;
2650 // we want this to be true outside previews (for insetexternal)
2656 // LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
2658 void Buffer::latexParagraphs(ostream & ofs, Paragraph * par,
2659 Paragraph * endpar, TexRow & texrow,
2660 bool moving_arg) const
2662 bool was_title = false;
2663 bool already_title = false;
2666 while (par != endpar) {
2667 Inset * in = par->inInset();
2668 // well we have to check if we are in an inset with unlimited
2669 // lenght (all in one row) if that is true then we don't allow
2670 // any special options in the paragraph and also we don't allow
2671 // any environment other then "Standard" to be valid!
2672 if ((in == 0) || !in->forceDefaultParagraphs(in)) {
2673 LyXLayout_ptr const & layout = par->layout();
2675 if (layout->intitle) {
2676 if (already_title) {
2677 lyxerr <<"Error in latexParagraphs: You"
2678 " should not mix title layouts"
2679 " with normal ones." << endl;
2682 } else if (was_title && !already_title) {
2683 ofs << "\\maketitle\n";
2685 already_title = true;
2689 if (layout->isEnvironment() ||
2690 !par->params().leftIndent().zero())
2692 par = par->TeXEnvironment(this, params, ofs, texrow);
2694 par = par->TeXOnePar(this, params, ofs, texrow, moving_arg);
2697 par = par->TeXOnePar(this, params, ofs, texrow, moving_arg);
2700 // It might be that we only have a title in this document
2701 if (was_title && !already_title) {
2702 ofs << "\\maketitle\n";
2708 bool Buffer::isLatex() const
2710 return params.getLyXTextClass().outputType() == LATEX;
2714 bool Buffer::isLinuxDoc() const
2716 return params.getLyXTextClass().outputType() == LINUXDOC;
2720 bool Buffer::isLiterate() const
2722 return params.getLyXTextClass().outputType() == LITERATE;
2726 bool Buffer::isDocBook() const
2728 return params.getLyXTextClass().outputType() == DOCBOOK;
2732 bool Buffer::isSGML() const
2734 LyXTextClass const & tclass = params.getLyXTextClass();
2736 return tclass.outputType() == LINUXDOC ||
2737 tclass.outputType() == DOCBOOK;
2741 int Buffer::sgmlOpenTag(ostream & os, Paragraph::depth_type depth, bool mixcont,
2742 string const & latexname) const
2744 if (!latexname.empty() && latexname != "!-- --") {
2746 os << string(" ",depth);
2747 os << "<" << latexname << ">";
2757 int Buffer::sgmlCloseTag(ostream & os, Paragraph::depth_type depth, bool mixcont,
2758 string const & latexname) const
2760 if (!latexname.empty() && latexname != "!-- --") {
2762 os << endl << string(" ",depth);
2763 os << "</" << latexname << ">";
2773 void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
2775 ofstream ofs(fname.c_str());
2778 Alert::alert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2782 niceFile = nice; // this will be used by included files.
2784 LaTeXFeatures features(params);
2790 LyXTextClass const & tclass = params.getLyXTextClass();
2792 string top_element = tclass.latexname();
2795 ofs << "<!doctype linuxdoc system";
2797 string preamble = params.preamble;
2798 const string name = nice ? ChangeExtension(filename_, ".sgml")
2800 preamble += features.getIncludedFiles(name);
2801 preamble += features.getLyXSGMLEntities();
2803 if (!preamble.empty()) {
2804 ofs << " [ " << preamble << " ]";
2808 if (params.options.empty())
2809 sgmlOpenTag(ofs, 0, false, top_element);
2811 string top = top_element;
2813 top += params.options;
2814 sgmlOpenTag(ofs, 0, false, top);
2818 ofs << "<!-- " << lyx_docversion
2819 << " created this file. For more info see http://www.lyx.org/"
2822 Paragraph::depth_type depth = 0; // paragraph depth
2823 Paragraph * par = paragraph;
2825 vector<string> environment_stack(5);
2828 LyXLayout_ptr const & style = par->layout();
2829 // treat <toc> as a special case for compatibility with old code
2830 if (par->isInset(0)) {
2831 Inset * inset = par->getInset(0);
2832 Inset::Code lyx_code = inset->lyxCode();
2833 if (lyx_code == Inset::TOC_CODE) {
2834 string const temp = "toc";
2835 sgmlOpenTag(ofs, depth, false, temp);
2842 // environment tag closing
2843 for (; depth > par->params().depth(); --depth) {
2844 sgmlCloseTag(ofs, depth, false, environment_stack[depth]);
2845 environment_stack[depth].erase();
2848 // write opening SGML tags
2849 switch (style->latextype) {
2850 case LATEX_PARAGRAPH:
2851 if (depth == par->params().depth()
2852 && !environment_stack[depth].empty()) {
2853 sgmlCloseTag(ofs, depth, false, environment_stack[depth]);
2854 environment_stack[depth].erase();
2860 sgmlOpenTag(ofs, depth, false, style->latexname());
2866 _("Error : Wrong depth for"
2867 " LatexType Command.\n"));
2869 if (!environment_stack[depth].empty()) {
2870 sgmlCloseTag(ofs, depth, false, environment_stack[depth]);
2874 environment_stack[depth].erase();
2875 sgmlOpenTag(ofs, depth, false, style->latexname());
2878 case LATEX_ENVIRONMENT:
2879 case LATEX_ITEM_ENVIRONMENT:
2881 string const & latexname = style->latexname();
2883 if (depth == par->params().depth()
2884 && environment_stack[depth] != latexname) {
2885 sgmlCloseTag(ofs, depth, false,
2886 environment_stack[depth]);
2887 environment_stack[depth].erase();
2889 if (depth < par->params().depth()) {
2890 depth = par->params().depth();
2891 environment_stack[depth].erase();
2893 if (environment_stack[depth] != latexname) {
2895 sgmlOpenTag(ofs, depth, false, "p");
2897 sgmlOpenTag(ofs, depth, false, latexname);
2899 if (environment_stack.size() == depth + 1)
2900 environment_stack.push_back("!-- --");
2901 environment_stack[depth] = latexname;
2904 if (style->latexparam() == "CDATA")
2907 if (style->latextype == LATEX_ENVIRONMENT) break;
2909 if (style->labeltype == LABEL_MANUAL)
2914 sgmlOpenTag(ofs, depth + 1, false, item_name);
2919 sgmlOpenTag(ofs, depth, false, style->latexname());
2923 simpleLinuxDocOnePar(ofs, par, depth);
2928 // write closing SGML tags
2929 switch (style->latextype) {
2932 case LATEX_ENVIRONMENT:
2933 case LATEX_ITEM_ENVIRONMENT:
2934 if (style->latexparam() == "CDATA")
2938 sgmlCloseTag(ofs, depth, false, style->latexname());
2944 for (int i = depth; i >= 0; --i)
2945 sgmlCloseTag(ofs, depth, false, environment_stack[i]);
2949 sgmlCloseTag(ofs, 0, false, top_element);
2953 // How to check for successful close
2955 // we want this to be true outside previews (for insetexternal)
2960 // checks, if newcol chars should be put into this line
2961 // writes newline, if necessary.
2964 void sgmlLineBreak(ostream & os, string::size_type & colcount,
2965 string::size_type newcol)
2968 if (colcount > lyxrc.ascii_linelen) {
2970 colcount = newcol; // assume write after this call
2985 string tag_name(PAR_TAG const & pt) {
2987 case NONE: return "!-- --";
2988 case TT: return "tt";
2989 case SF: return "sf";
2990 case BF: return "bf";
2991 case IT: return "it";
2992 case SL: return "sl";
2993 case EM: return "em";
3000 void operator|=(PAR_TAG & p1, PAR_TAG const & p2)
3002 p1 = static_cast<PAR_TAG>(p1 | p2);
3007 void reset(PAR_TAG & p1, PAR_TAG const & p2)
3009 p1 = static_cast<PAR_TAG>(p1 & ~p2);
3015 // Handle internal paragraph parsing -- layout already processed.
3016 void Buffer::simpleLinuxDocOnePar(ostream & os,
3018 Paragraph::depth_type /*depth*/)
3020 LyXLayout_ptr const & style = par->layout();
3022 string::size_type char_line_count = 5; // Heuristic choice ;-)
3024 // gets paragraph main font
3027 if (style->labeltype == LABEL_MANUAL) {
3028 font_old = style->labelfont;
3031 font_old = style->font;
3035 LyXFont::FONT_FAMILY family_type = LyXFont::ROMAN_FAMILY;
3036 LyXFont::FONT_SERIES series_type = LyXFont::MEDIUM_SERIES;
3037 LyXFont::FONT_SHAPE shape_type = LyXFont::UP_SHAPE;
3040 stack<PAR_TAG> tag_state;
3041 // parsing main loop
3042 for (pos_type i = 0; i < par->size(); ++i) {
3044 PAR_TAG tag_close = NONE;
3045 list < PAR_TAG > tag_open;
3047 LyXFont const font = par->getFont(params, i);
3049 if (font_old.family() != font.family()) {
3050 switch (family_type) {
3051 case LyXFont::SANS_FAMILY:
3054 case LyXFont::TYPEWRITER_FAMILY:
3061 family_type = font.family();
3063 switch (family_type) {
3064 case LyXFont::SANS_FAMILY:
3065 tag_open.push_back(SF);
3067 case LyXFont::TYPEWRITER_FAMILY:
3068 tag_open.push_back(TT);
3075 if (font_old.series() != font.series()) {
3076 switch (series_type) {
3077 case LyXFont::BOLD_SERIES:
3084 series_type = font.series();
3086 switch (series_type) {
3087 case LyXFont::BOLD_SERIES:
3088 tag_open.push_back(BF);
3096 if (font_old.shape() != font.shape()) {
3097 switch (shape_type) {
3098 case LyXFont::ITALIC_SHAPE:
3101 case LyXFont::SLANTED_SHAPE:
3108 shape_type = font.shape();
3110 switch (shape_type) {
3111 case LyXFont::ITALIC_SHAPE:
3112 tag_open.push_back(IT);
3114 case LyXFont::SLANTED_SHAPE:
3115 tag_open.push_back(SL);
3122 if (font_old.emph() != font.emph()) {
3123 if (font.emph() == LyXFont::ON) {
3124 tag_open.push_back(EM);
3133 list < PAR_TAG > temp;
3134 while (!tag_state.empty() && tag_close) {
3135 PAR_TAG k = tag_state.top();
3137 os << "</" << tag_name(k) << ">";
3144 for(list< PAR_TAG >::const_iterator j = temp.begin();
3145 j != temp.end(); ++j) {
3147 os << "<" << tag_name(*j) << ">";
3150 for(list< PAR_TAG >::const_iterator j = tag_open.begin();
3151 j != tag_open.end(); ++j) {
3153 os << "<" << tag_name(*j) << ">";
3156 char c = par->getChar(i);
3158 if (c == Paragraph::META_INSET) {
3159 Inset * inset = par->getInset(i);
3160 inset->linuxdoc(this, os);
3165 if (style->latexparam() == "CDATA") {
3166 // "TeX"-Mode on == > SGML-Mode on.
3172 if (par->sgmlConvertChar(c, sgml_string)
3173 && !style->free_spacing && !par->isFreeSpacing())
3175 // in freespacing mode, spaces are
3176 // non-breaking characters
3177 if (desc_on) {// if char is ' ' then...
3180 sgmlLineBreak(os, char_line_count, 6);
3184 sgmlLineBreak(os, char_line_count, 1);
3189 char_line_count += sgml_string.length();
3195 while (!tag_state.empty()) {
3196 os << "</" << tag_name(tag_state.top()) << ">";
3200 // resets description flag correctly
3202 // <tag> not closed...
3203 sgmlLineBreak(os, char_line_count, 6);
3209 // Print an error message.
3210 void Buffer::sgmlError(Paragraph * /*par*/, int /*pos*/,
3211 string const & /*message*/) const
3213 #ifdef WITH_WARNINGS
3214 #warning This is wrong we cannot insert an inset like this!!!
3215 // I guess this was Jose' so I explain you more or less why this
3216 // is wrong. This way you insert something in the paragraph and
3217 // don't tell it to LyXText (row rebreaking and undo handling!!!)
3218 // I deactivate this code, have a look at BufferView::insertErrors
3219 // how you should do this correctly! (Jug 20020315)
3222 // insert an error marker in text
3223 InsetError * new_inset = new InsetError(message);
3224 par->insertInset(pos, new_inset, LyXFont(LyXFont::ALL_INHERIT,
3230 void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
3232 ofstream ofs(fname.c_str());
3234 Alert::alert(_("LYX_ERROR:"), _("Cannot write file"), fname);
3238 Paragraph * par = paragraph;
3240 niceFile = nice; // this will be used by Insetincludes.
3242 LaTeXFeatures features(params);
3247 LyXTextClass const & tclass = params.getLyXTextClass();
3248 string top_element = tclass.latexname();
3251 ofs << "<!DOCTYPE " << top_element
3252 << " PUBLIC \"-//OASIS//DTD DocBook V4.1//EN\"";
3254 string preamble = params.preamble;
3255 const string name = nice ? ChangeExtension(filename_, ".sgml")
3257 preamble += features.getIncludedFiles(name);
3258 preamble += features.getLyXSGMLEntities();
3260 if (!preamble.empty()) {
3261 ofs << "\n [ " << preamble << " ]";
3266 string top = top_element;
3268 top += params.language->code();
3271 if (!params.options.empty()) {
3273 top += params.options;
3275 sgmlOpenTag(ofs, 0, false, top);
3277 ofs << "<!-- DocBook file was created by " << lyx_docversion
3278 << "\n See http://www.lyx.org/ for more information -->\n";
3280 vector<string> environment_stack(10);
3281 vector<string> environment_inner(10);
3282 vector<string> command_stack(10);
3284 bool command_flag = false;
3285 Paragraph::depth_type command_depth = 0;
3286 Paragraph::depth_type command_base = 0;
3287 Paragraph::depth_type cmd_depth = 0;
3288 Paragraph::depth_type depth = 0; // paragraph depth
3291 string command_name;
3297 int desc_on = 0; // description mode
3299 LyXLayout_ptr const & style = par->layout();
3301 // environment tag closing
3302 for (; depth > par->params().depth(); --depth) {
3303 if (environment_inner[depth] != "!-- --") {
3304 item_name = "listitem";
3305 sgmlCloseTag(ofs, command_depth + depth, false, item_name);
3306 if (environment_inner[depth] == "varlistentry")
3307 sgmlCloseTag(ofs, depth+command_depth, false, environment_inner[depth]);
3309 sgmlCloseTag(ofs, depth + command_depth, false, environment_stack[depth]);
3310 environment_stack[depth].erase();
3311 environment_inner[depth].erase();
3314 if (depth == par->params().depth()
3315 && environment_stack[depth] != style->latexname()
3316 && !environment_stack[depth].empty()) {
3317 if (environment_inner[depth] != "!-- --") {
3318 item_name= "listitem";
3319 sgmlCloseTag(ofs, command_depth+depth, false, item_name);
3320 if (environment_inner[depth] == "varlistentry")
3321 sgmlCloseTag(ofs, depth + command_depth, false, environment_inner[depth]);
3324 sgmlCloseTag(ofs, depth + command_depth, false, environment_stack[depth]);
3326 environment_stack[depth].erase();
3327 environment_inner[depth].erase();
3330 // Write opening SGML tags.
3331 switch (style->latextype) {
3332 case LATEX_PARAGRAPH:
3333 sgmlOpenTag(ofs, depth + command_depth,
3334 false, style->latexname());
3340 _("Error : Wrong depth for "
3341 "LatexType Command.\n"));
3343 command_name = style->latexname();
3345 sgmlparam = style->latexparam();
3346 c_params = split(sgmlparam, c_depth,'|');
3348 cmd_depth = lyx::atoi(c_depth);
3351 if (cmd_depth < command_base) {
3352 for (Paragraph::depth_type j = command_depth;
3353 j >= command_base; --j) {
3354 sgmlCloseTag(ofs, j, false, command_stack[j]);
3357 command_depth = command_base = cmd_depth;
3358 } else if (cmd_depth <= command_depth) {
3359 for (int j = command_depth;
3360 j >= int(cmd_depth); --j) {
3361 sgmlCloseTag(ofs, j, false, command_stack[j]);
3364 command_depth = cmd_depth;
3366 command_depth = cmd_depth;
3368 command_depth = command_base = cmd_depth;
3369 command_flag = true;
3371 if (command_stack.size() == command_depth + 1)
3372 command_stack.push_back(string());
3373 command_stack[command_depth] = command_name;
3375 // treat label as a special case for
3376 // more WYSIWYM handling.
3377 // This is a hack while paragraphs can't have
3378 // attributes, like id in this case.
3379 if (par->isInset(0)) {
3380 Inset * inset = par->getInset(0);
3381 Inset::Code lyx_code = inset->lyxCode();
3382 if (lyx_code == Inset::LABEL_CODE) {
3383 command_name += " id=\"";
3384 command_name += (static_cast<InsetCommand *>(inset))->getContents();
3385 command_name += "\"";
3390 sgmlOpenTag(ofs, depth + command_depth, false, command_name);
3392 item_name = c_params.empty()?"title":c_params;
3393 sgmlOpenTag(ofs, depth + 1 + command_depth, false, item_name);
3396 case LATEX_ENVIRONMENT:
3397 case LATEX_ITEM_ENVIRONMENT:
3398 if (depth < par->params().depth()) {
3399 depth = par->params().depth();
3400 environment_stack[depth].erase();
3403 if (environment_stack[depth] != style->latexname()) {
3404 if (environment_stack.size() == depth + 1) {
3405 environment_stack.push_back("!-- --");
3406 environment_inner.push_back("!-- --");
3408 environment_stack[depth] = style->latexname();
3409 environment_inner[depth] = "!-- --";
3410 sgmlOpenTag(ofs, depth + command_depth, false, environment_stack[depth]);
3412 if (environment_inner[depth] != "!-- --") {
3413 item_name= "listitem";
3414 sgmlCloseTag(ofs, command_depth + depth, false, item_name);
3415 if (environment_inner[depth] == "varlistentry")
3416 sgmlCloseTag(ofs, depth + command_depth, false, environment_inner[depth]);
3420 if (style->latextype == LATEX_ENVIRONMENT) {
3421 if (!style->latexparam().empty()) {
3422 if (style->latexparam() == "CDATA")
3425 sgmlOpenTag(ofs, depth + command_depth, false, style->latexparam());
3430 desc_on = (style->labeltype == LABEL_MANUAL);
3432 environment_inner[depth] = desc_on ? "varlistentry" : "listitem";
3433 sgmlOpenTag(ofs, depth + 1 + command_depth,
3434 false, environment_inner[depth]);
3436 item_name = desc_on ? "term" : "para";
3437 sgmlOpenTag(ofs, depth + 1 + command_depth,
3441 sgmlOpenTag(ofs, depth + command_depth,
3442 false, style->latexname());
3446 simpleDocBookOnePar(ofs, par, desc_on,
3447 depth + 1 + command_depth);
3451 // write closing SGML tags
3452 switch (style->latextype) {
3454 end_tag = c_params.empty() ? "title" : c_params;
3455 sgmlCloseTag(ofs, depth + command_depth,
3458 case LATEX_ENVIRONMENT:
3459 if (!style->latexparam().empty()) {
3460 if (style->latexparam() == "CDATA")
3463 sgmlCloseTag(ofs, depth + command_depth, false, style->latexparam());
3466 case LATEX_ITEM_ENVIRONMENT:
3467 if (desc_on == 1) break;
3469 sgmlCloseTag(ofs, depth + 1 + command_depth, false, end_tag);
3471 case LATEX_PARAGRAPH:
3472 sgmlCloseTag(ofs, depth + command_depth, false, style->latexname());
3475 sgmlCloseTag(ofs, depth + command_depth, false, style->latexname());
3481 for (int d = depth; d >= 0; --d) {
3482 if (!environment_stack[depth].empty()) {
3483 if (environment_inner[depth] != "!-- --") {
3484 item_name = "listitem";
3485 sgmlCloseTag(ofs, command_depth + depth, false, item_name);
3486 if (environment_inner[depth] == "varlistentry")
3487 sgmlCloseTag(ofs, depth + command_depth, false, environment_inner[depth]);
3490 sgmlCloseTag(ofs, depth + command_depth, false, environment_stack[depth]);
3494 for (int j = command_depth; j >= 0 ; --j)
3495 if (!command_stack[j].empty()) {
3496 sgmlCloseTag(ofs, j, false, command_stack[j]);
3501 sgmlCloseTag(ofs, 0, false, top_element);
3504 // How to check for successful close
3506 // we want this to be true outside previews (for insetexternal)
3511 void Buffer::simpleDocBookOnePar(ostream & os,
3512 Paragraph * par, int & desc_on,
3513 Paragraph::depth_type depth) const
3515 bool emph_flag = false;
3517 LyXLayout_ptr const & style = par->layout();
3519 LyXFont font_old = (style->labeltype == LABEL_MANUAL ? style->labelfont : style->font);
3521 int char_line_count = depth;
3522 //if (!style.free_spacing)
3523 // os << string(depth,' ');
3525 // parsing main loop
3526 for (pos_type i = 0; i < par->size(); ++i) {
3527 LyXFont font = par->getFont(params, i);
3529 // handle <emphasis> tag
3530 if (font_old.emph() != font.emph()) {
3531 if (font.emph() == LyXFont::ON) {
3532 if (style->latexparam() == "CDATA")
3535 if (style->latexparam() == "CDATA")
3539 if (style->latexparam() == "CDATA")
3541 os << "</emphasis>";
3542 if (style->latexparam() == "CDATA")
3549 if (par->isInset(i)) {
3550 Inset * inset = par->getInset(i);
3551 // don't print the inset in position 0 if desc_on == 3 (label)
3552 if (i || desc_on != 3) {
3553 if (style->latexparam() == "CDATA")
3555 inset->docbook(this, os, false);
3556 if (style->latexparam() == "CDATA")
3560 char c = par->getChar(i);
3562 par->sgmlConvertChar(c, sgml_string);
3564 if (style->pass_thru) {
3566 } else if (style->free_spacing || par->isFreeSpacing() || c != ' ') {
3568 } else if (desc_on ==1) {
3570 os << "\n</term><listitem><para>";
3580 if (style->latexparam() == "CDATA")
3582 os << "</emphasis>";
3583 if (style->latexparam() == "CDATA")
3587 // resets description flag correctly
3589 // <term> not closed...
3590 os << "</term>\n<listitem><para> </para>";
3592 if (style->free_spacing)
3597 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
3598 // Other flags: -wall -v0 -x
3599 int Buffer::runChktex()
3601 if (!users->text) return 0;
3603 users->owner()->prohibitInput();
3605 // get LaTeX-Filename
3606 string const name = getLatexName();
3607 string path = filePath();
3609 string const org_path = path;
3610 if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
3614 Path p(path); // path to LaTeX file
3615 users->owner()->message(_("Running chktex..."));
3617 // Remove all error insets
3618 bool const removedErrorInsets = users->removeAutoInsets();
3620 // Generate the LaTeX file if neccessary
3621 makeLaTeXFile(name, org_path, false);
3624 Chktex chktex(lyxrc.chktex_command, name, filePath());
3625 int res = chktex.run(terr); // run chktex
3628 Alert::alert(_("chktex did not work!"),
3629 _("Could not run with file:"), name);
3630 } else if (res > 0) {
3631 // Insert all errors as errors boxes
3632 users->insertErrors(terr);
3635 // if we removed error insets before we ran chktex or if we inserted
3636 // error insets after we ran chktex, this must be run:
3637 if (removedErrorInsets || res) {
3638 #warning repaint needed here, or do you mean update() ?
3642 users->owner()->allowInput();
3648 void Buffer::validate(LaTeXFeatures & features) const
3650 Paragraph * par = paragraph;
3651 LyXTextClass const & tclass = params.getLyXTextClass();
3653 // AMS Style is at document level
3654 if (params.use_amsmath || tclass.provides(LyXTextClass::amsmath))
3655 features.require("amsmath");
3658 // We don't use "lyxerr.debug" because of speed. (Asger)
3659 if (lyxerr.debugging(Debug::LATEX))
3660 lyxerr << "Paragraph: " << par << endl;
3662 // Now just follow the list of paragraphs and run
3663 // validate on each of them.
3664 par->validate(features);
3666 // and then the next paragraph
3670 // the bullet shapes are buffer level not paragraph level
3671 // so they are tested here
3672 for (int i = 0; i < 4; ++i) {
3673 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
3674 int const font = params.user_defined_bullets[i].getFont();
3676 int const c = params
3677 .user_defined_bullets[i]
3684 features.require("latexsym");
3686 } else if (font == 1) {
3687 features.require("amssymb");
3688 } else if ((font >= 2 && font <= 5)) {
3689 features.require("pifont");
3694 if (lyxerr.debugging(Debug::LATEX)) {
3695 features.showStruct();
3700 // This function should be in Buffer because it's a buffer's property (ale)
3701 string const Buffer::getIncludeonlyList(char delim)
3704 for (inset_iterator it = inset_iterator_begin();
3705 it != inset_iterator_end(); ++it) {
3706 if ((*it)->lyxCode() == Inset::INCLUDE_CODE) {
3707 InsetInclude * insetinc =
3708 static_cast<InsetInclude *>(*it);
3709 if (insetinc->isIncludeOnly()) {
3712 lst += insetinc->getRelFileBaseName();
3716 lyxerr[Debug::INFO] << "Includeonly(" << lst << ')' << endl;
3721 vector<string> const Buffer::getLabelList()
3723 /// if this is a child document and the parent is already loaded
3724 /// Use the parent's list instead [ale990407]
3725 if (!params.parentname.empty()
3726 && bufferlist.exists(params.parentname)) {
3727 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3729 return tmp->getLabelList();
3732 vector<string> label_list;
3733 for (inset_iterator it = inset_iterator_begin();
3734 it != inset_iterator_end(); ++it) {
3735 vector<string> const l = (*it)->getLabelList();
3736 label_list.insert(label_list.end(), l.begin(), l.end());
3742 // This is also a buffer property (ale)
3743 vector<pair<string, string> > const Buffer::getBibkeyList() const
3745 typedef pair<string, string> StringPair;
3746 /// if this is a child document and the parent is already loaded
3747 /// Use the parent's list instead [ale990412]
3748 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3749 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
3751 return tmp->getBibkeyList();
3754 vector<StringPair> keys;
3755 Paragraph * par = paragraph;
3758 string const key = par->bibkey->getContents();
3759 string const opt = par->bibkey->getOptions();
3760 string const ref = par->asString(this, false);
3761 string const info = opt + "TheBibliographyRef" + ref;
3763 keys.push_back(StringPair(key, info));
3768 // Might be either using bibtex or a child has bibliography
3770 for (inset_iterator it = inset_const_iterator_begin();
3771 it != inset_const_iterator_end(); ++it) {
3772 // Search for Bibtex or Include inset
3773 if ((*it)->lyxCode() == Inset::BIBTEX_CODE) {
3774 vector<StringPair> tmp =
3775 static_cast<InsetBibtex*>(*it)->getKeys(this);
3776 keys.insert(keys.end(), tmp.begin(), tmp.end());
3777 } else if ((*it)->lyxCode() == Inset::INCLUDE_CODE) {
3778 vector<StringPair> const tmp =
3779 static_cast<InsetInclude*>(*it)->getKeys();
3780 keys.insert(keys.end(), tmp.begin(), tmp.end());
3789 bool Buffer::isDepClean(string const & name) const
3791 DEPCLEAN * item = dep_clean;
3792 while (item && item->master != name)
3794 if (!item) return true;
3799 void Buffer::markDepClean(string const & name)
3802 dep_clean = new DEPCLEAN;
3803 dep_clean->clean = true;
3804 dep_clean->master = name;
3805 dep_clean->next = 0;
3807 DEPCLEAN * item = dep_clean;
3808 while (item && item->master != name)
3813 item = new DEPCLEAN;
3815 item->master = name;
3822 bool Buffer::dispatch(string const & command, bool * result)
3824 // Split command string into command and argument
3826 string line = ltrim(command);
3827 string const arg = trim(split(line, cmd, ' '));
3829 return dispatch(lyxaction.LookupFunc(cmd), arg, result);
3833 bool Buffer::dispatch(int action, string const & argument, bool * result)
3835 bool dispatched = true;
3839 bool const tmp = Exporter::Export(this, argument, false);
3852 void Buffer::resizeInsets(BufferView * bv)
3854 /// then remove all LyXText in text-insets
3855 Paragraph * par = paragraph;
3856 for (; par; par = par->next()) {
3857 par->resizeInsetsLyXText(bv);
3862 void Buffer::redraw()
3864 #warning repaint needed here, or do you mean update() ?
3870 void Buffer::changeLanguage(Language const * from, Language const * to)
3873 ParIterator end = par_iterator_end();
3874 for (ParIterator it = par_iterator_begin(); it != end; ++it)
3875 (*it)->changeLanguage(params, from, to);
3879 bool Buffer::isMultiLingual()
3881 ParIterator end = par_iterator_end();
3882 for (ParIterator it = par_iterator_begin(); it != end; ++it)
3883 if ((*it)->isMultiLingual(params))
3890 Buffer::inset_iterator::inset_iterator(Paragraph * paragraph, pos_type pos)
3893 it = par->InsetIterator(pos);
3894 if (it == par->inset_iterator_end()) {
3901 void Buffer::inset_iterator::setParagraph()
3904 it = par->inset_iterator_begin();
3905 if (it != par->inset_iterator_end())
3910 // We maintain an invariant that whenever par = 0 then it = 0
3914 Inset * Buffer::getInsetFromID(int id_arg) const
3916 for (inset_iterator it = inset_const_iterator_begin();
3917 it != inset_const_iterator_end(); ++it)
3919 if ((*it)->id() == id_arg)
3921 Inset * in = (*it)->getInsetFromID(id_arg);
3929 Paragraph * Buffer::getParFromID(int id) const
3931 if (id < 0) return 0;
3932 Paragraph * par = paragraph;
3934 if (par->id() == id) {
3937 Paragraph * tmp = par->getParFromID(id);
3947 ParIterator Buffer::par_iterator_begin()
3949 return ParIterator(paragraph);
3953 ParIterator Buffer::par_iterator_end()
3955 return ParIterator();