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"
23 #include "LyXAction.h"
26 #include "tex-strings.h"
28 #include "bufferview_funcs.h"
33 #include "frontends/LyXView.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 "mathed/formulamacro.h"
49 #include "mathed/formula.h"
51 #include "insets/inset.h"
52 #include "insets/inseterror.h"
53 #include "insets/insetlabel.h"
54 #include "insets/insetref.h"
55 #include "insets/inseturl.h"
56 #include "insets/insetnote.h"
57 #include "insets/insetquotes.h"
58 #include "insets/insetlatexaccent.h"
59 #include "insets/insetbib.h"
60 #include "insets/insetcite.h"
61 #include "insets/insetexternal.h"
62 #include "insets/insetindex.h"
63 #include "insets/insetinclude.h"
64 #include "insets/insettoc.h"
65 #include "insets/insetparent.h"
66 #include "insets/insetspecialchar.h"
67 #include "insets/insettext.h"
68 #include "insets/insetert.h"
69 #include "insets/insetgraphics.h"
70 #include "insets/insetfoot.h"
71 #include "insets/insetmarginal.h"
72 #include "insets/insetminipage.h"
73 #include "insets/insetfloat.h"
74 #include "insets/insettabular.h"
76 #include "insets/insettheorem.h"
77 #include "insets/insetlist.h"
79 #include "insets/insetcaption.h"
80 #include "insets/insetfloatlist.h"
82 #include "frontends/Dialogs.h"
83 #include "frontends/Alert.h"
85 #include "graphics/Previews.h"
87 #include "support/textutils.h"
88 #include "support/filetools.h"
89 #include "support/path.h"
90 #include "support/os.h"
91 #include "support/lyxlib.h"
92 #include "support/FileInfo.h"
93 #include "support/lyxmanip.h"
94 #include "support/lyxalgo.h" // for lyx::count
106 #include <sys/types.h>
114 #ifndef CXX_GLOBAL_CSTD
126 using std::make_pair;
135 using lyx::textclass_type;
137 // all these externs should eventually be removed.
138 extern BufferList bufferlist;
140 extern LyXAction lyxaction;
144 const int LYX_FORMAT = 220;
148 extern int tex_code_break_column;
151 Buffer::Buffer(string const & file, bool ronly)
152 : paragraph(0), niceFile(true), lyx_clean(true), bak_clean(true),
153 unnamed(false), dep_clean(0), read_only(ronly),
154 filename_(file), users(0)
156 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
158 filepath_ = OnlyPath(file);
163 // read_only = ronly;
167 if (read_only || lyxrc.use_tempdir) {
168 tmppath = CreateBufferTmpDir();
177 lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
178 // here the buffer should take care that it is
179 // saved properly, before it goes into the void.
181 // make sure that views using this buffer
186 if (!tmppath.empty()) {
187 DestroyBufferTmpDir(tmppath);
190 Paragraph * par = paragraph;
193 tmppar = par->next();
199 // Remove any previewed LaTeX snippets assocoated with this buffer.
200 grfx::Previews::get().removeLoader(this);
204 string const Buffer::getLatexName(bool no_path) const
206 string const name = ChangeExtension(MakeLatexName(fileName()), ".tex");
208 return OnlyFilename(name);
214 pair<Buffer::LogType, string> const Buffer::getLogName(void) const
216 string const filename = getLatexName(false);
218 if (filename.empty())
219 return make_pair(Buffer::latexlog, string());
221 string path = OnlyPath(filename);
223 if (lyxrc.use_tempdir || !IsDirWriteable(path))
226 string const fname = AddName(path,
227 OnlyFilename(ChangeExtension(filename,
230 AddName(path, OnlyFilename(
231 ChangeExtension(filename,
232 formats.extension("literate") + ".out")));
234 // If no Latex log or Build log is newer, show Build log
236 FileInfo const f_fi(fname);
237 FileInfo const b_fi(bname);
240 (!f_fi.exist() || f_fi.getModificationTime() < b_fi.getModificationTime())) {
241 lyxerr[Debug::FILES] << "Log name calculated as : " << bname << endl;
242 return make_pair(Buffer::buildlog, bname);
244 lyxerr[Debug::FILES] << "Log name calculated as : " << fname << endl;
245 return make_pair(Buffer::latexlog, fname);
249 void Buffer::setReadonly(bool flag)
251 if (read_only != flag) {
254 users->owner()->getDialogs()->updateBufferDependent(false);
259 /// Update window titles of all users
260 // Should work on a list
261 void Buffer::updateTitles() const
264 users->owner()->updateWindowTitle();
268 /// Reset autosave timer of all users
269 // Should work on a list
270 void Buffer::resetAutosaveTimers() const
273 users->owner()->resetAutosaveTimer();
277 void Buffer::setFileName(string const & newfile)
279 filename_ = MakeAbsPath(newfile);
280 filepath_ = OnlyPath(filename_);
281 setReadonly(IsFileWriteable(filename_) == 0);
286 // We'll remove this later. (Lgb)
289 string last_inset_read;
291 #ifndef NO_COMPABILITY
294 ErtComp() : active(false), fromlayout(false), in_tabular(false) {
303 std::stack<ErtComp> ert_stack;
308 #warning And _why_ is this here? (Lgb)
316 // candidate for move to BufferView
317 // (at least some parts in the beginning of the func)
320 // changed to be public and have one parameter
321 // if par = 0 normal behavior
322 // else insert behavior
323 // Returns false if "\the_end" is not read for formats >= 2.13. (Asger)
324 bool Buffer::readLyXformat2(LyXLex & lex, Paragraph * par)
328 #ifndef NO_COMPABILITY
329 ert_comp.contents.erase();
330 ert_comp.active = false;
331 ert_comp.fromlayout = false;
332 ert_comp.in_tabular = false;
335 Paragraph::depth_type depth = 0;
336 bool the_end_read = false;
338 Paragraph * first_par = 0;
339 LyXFont font(LyXFont::ALL_INHERIT, params.language);
342 if (file_format < 216 && params.language->lang() == "hebrew")
343 font.setLanguage(default_language);
348 par->layout(params.getLyXTextClass().defaultLayout());
350 // We are inserting into an existing document
351 users->text->breakParagraph(users);
352 first_par = users->text->ownerParagraph();
355 // We don't want to adopt the parameters from the
356 // document we insert, so we skip until the text begins:
359 string const pretoken = lex.getString();
360 if (pretoken == "\\layout") {
361 lex.pushToken(pretoken);
369 string const token = lex.getString();
371 if (token.empty()) continue;
373 lyxerr[Debug::PARSER] << "Handling token: `"
374 << token << "'" << endl;
377 parseSingleLyXformat2Token(lex, par, first_par,
385 paragraph = first_par;
387 if (unknown_layouts > 0) {
388 string s = _("Couldn't set the layout for ");
389 if (unknown_layouts == 1) {
390 s += _("one paragraph");
392 s += tostr(unknown_layouts);
393 s += _(" paragraphs");
395 Alert::alert(_("Textclass Loading Error!"), s,
396 _("When reading " + fileName()));
399 if (unknown_tokens > 0) {
400 string s = _("Encountered ");
401 if (unknown_tokens == 1) {
402 s += _("one unknown token");
404 s += tostr(unknown_tokens);
405 s += _(" unknown tokens");
407 Alert::alert(_("Textclass Loading Error!"), s,
408 _("When reading " + fileName()));
415 #ifndef NO_COMPABILITY
417 Inset * Buffer::isErtInset(Paragraph * par, int pos) const
420 if ((par->getChar(pos) == Paragraph::META_INSET) &&
421 (inset = par->getInset(pos)) &&
422 (inset->lyxCode() == Inset::ERT_CODE))
429 void Buffer::insertErtContents(Paragraph * par, int & pos, bool set_inactive)
431 if (ert_comp.contents.find_first_not_of(' ') != string::npos) {
432 // we only skip completely empty ERT (only spaces) otherwise
433 // we have to insert it as is.
434 string str(ert_comp.contents);
435 lyxerr[Debug::INSETS] << "ERT contents:\n'"
436 << str << "'" << endl;
437 // check if we have already an ert inset a position earlier
438 // if this is the case then we should insert the contents
439 // inside the other ertinset as it is stupid to have various
442 if ((pos > 0) && (inset=isErtInset(par, pos-1))) {
443 // get the last paragraph from the inset before
444 Paragraph * last = inset->firstParagraph();
447 // create the new paragraph after the last one
448 Paragraph * par = new Paragraph(last);
449 par->layout(params.getLyXTextClass().defaultLayoutName());
450 par->setInsetOwner(last->inInset());
452 LyXFont font(LyXFont::ALL_INHERIT, params.language);
453 string::const_iterator cit = str.begin();
454 string::const_iterator end = str.end();
456 for (; cit != end; ++cit) {
457 par->insertChar(pos++, *cit, font);
461 new InsetERT(params, params.language, str, true);
462 par->insertInset(pos++, inset, ert_comp.font);
465 ert_comp.contents.erase();
466 ert_comp.fromlayout = false;
468 ert_comp.active = false;
475 Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
476 Paragraph *& first_par,
477 string const & token, int & pos,
478 Paragraph::depth_type & depth,
482 bool the_end_read = false;
483 #ifndef NO_COMPABILITY
484 #ifndef NO_PEXTRA_REALLY
485 // This is super temporary but is needed to get the compability
486 // mode for minipages work correctly together with new tabulars.
487 static int call_depth;
489 bool checkminipage = false;
490 static Paragraph * minipar = 0;
491 static Paragraph * parBeforeMinipage;
495 // The order of the tags tested may seem unnatural, but this
496 // has been done in order to reduce the number of string
497 // comparisons needed to recognize a given token. This leads
498 // on large documents like UserGuide to a reduction of a
500 if (token[0] != '\\') {
501 #ifndef NO_COMPABILITY
502 if (ert_comp.active) {
503 ert_comp.contents += token;
506 for (string::const_iterator cit = token.begin();
507 cit != token.end(); ++cit) {
508 par->insertChar(pos, (*cit), font);
511 #ifndef NO_COMPABILITY
514 } else if (token == "\\layout") {
515 #ifndef NO_COMPABILITY
516 bool old_fromlayout = ert_comp.fromlayout;
517 bool create_new_par = true;
518 ert_comp.in_tabular = false;
520 if (!par->size() && par->previous() &&
521 (par->previous()->size() == 1) &&
522 isErtInset(par->previous(), par->previous()->size()-1))
524 int p = par->previous()->size();
525 insertErtContents(par->previous(), p);
526 create_new_par = false;
528 insertErtContents(par, pos);
531 // reset the font as we start a new layout and if the font is
532 // not ALL_INHERIT,document_language then it will be set to the
533 // right values after this tag (Jug 20020420)
534 font = LyXFont(LyXFont::ALL_INHERIT, params.language);
537 if (file_format < 216 && params.language->lang() == "hebrew")
538 font.setLanguage(default_language);
542 string layoutname = lex.getString();
544 LyXTextClass const & tclass = params.getLyXTextClass();
546 if (layoutname.empty()) {
547 layoutname = tclass.defaultLayoutName();
549 #ifndef NO_COMPABILITY
550 if (compare_ascii_no_case(layoutname, "latex") == 0) {
551 ert_comp.active = true;
552 ert_comp.fromlayout = true;
553 ert_comp.font = font;
555 create_new_par = false;
558 bool hasLayout = tclass.hasLayout(layoutname);
560 lyxerr << "Layout '" << layoutname << "' does not"
561 << " exist in textclass '" << tclass.name()
563 lyxerr << "Trying to use default layout instead."
565 layoutname = tclass.defaultLayoutName();
569 // The is the compability reading of layout caption.
570 // It can be removed in LyX version 1.3.0. (Lgb)
571 if (compare_ascii_no_case(layoutname, "caption") == 0) {
572 // We expect that the par we are now working on is
573 // really inside a InsetText inside a InsetFloat.
574 // We also know that captions can only be
575 // one paragraph. (Lgb)
577 // We should now read until the next "\layout"
579 // This is probably not good enough, what if the
580 // caption is the last par in the document (Lgb)
581 istream & ist = lex.getStream();
587 if (prefixIs(line, "\\layout")) {
591 if (prefixIs(line, "\\begin_inset"))
593 if (prefixIs(line, "\\end_inset")) {
604 // Now we should have the whole layout in ss
605 // we should now be able to give this to the
607 ss << "\\end_inset\n";
609 // This seems like a bug in stringstream.
610 // We really should be able to use ss
612 istringstream is(ss.str());
614 tmplex.setStream(is);
615 Inset * inset = new InsetCaption;
616 inset->Read(this, tmplex);
617 par->InsertInset(pos, inset, font);
621 #ifndef NO_COMPABILITY
622 if (create_new_par) {
627 par = new Paragraph(par);
628 par->layout(params.getLyXTextClass().defaultLayout());
631 par->layout(params.getLyXTextClass()[layoutname]);
632 // Test whether the layout is obsolete.
633 LyXLayout_ptr const & layout = par->layout();
634 if (!layout->obsoleted_by().empty())
635 par->layout(params.getLyXTextClass()[layout->obsoleted_by()]);
636 par->params().depth(depth);
637 #ifndef NO_COMPABILITY
639 // we duplicate code here because it's easier to remove
640 // the code then of NO_COMPATIBILITY
641 par->layout(layoutname);
642 // Test whether the layout is obsolete.
643 LyXLayout_ptr const & layout =
644 params.getLyXTextClass()[par->layout()];
645 if (!layout->obsoleted_by().empty())
646 par->layout(layout->obsoleted_by());
647 par->params().depth(depth);
654 } else if (token == "\\end_inset") {
655 lyxerr << "Solitary \\end_inset. Missing \\begin_inset?.\n"
656 << "Last inset read was: " << last_inset_read
658 // Simply ignore this. The insets do not have
660 // But insets should read it, it is a part of
661 // the inset isn't it? Lgb.
662 } else if (token == "\\begin_inset") {
663 #ifndef NO_COMPABILITY
664 insertErtContents(par, pos, false);
665 ert_stack.push(ert_comp);
666 ert_comp = ErtComp();
668 readInset(lex, par, pos, font);
669 #ifndef NO_COMPABILITY
670 ert_comp = ert_stack.top();
672 insertErtContents(par, pos);
674 } else if (token == "\\family") {
676 font.setLyXFamily(lex.getString());
677 } else if (token == "\\series") {
679 font.setLyXSeries(lex.getString());
680 } else if (token == "\\shape") {
682 font.setLyXShape(lex.getString());
683 } else if (token == "\\size") {
685 font.setLyXSize(lex.getString());
686 #ifndef NO_COMPABILITY
687 } else if (token == "\\latex") {
689 string const tok = lex.getString();
690 if (tok == "no_latex") {
692 insertErtContents(par, pos);
693 } else if (tok == "latex") {
694 ert_comp.active = true;
695 ert_comp.font = font;
696 } else if (tok == "default") {
698 insertErtContents(par, pos);
700 lex.printError("Unknown LaTeX font flag "
704 } else if (token == "\\lang") {
706 string const tok = lex.getString();
707 Language const * lang = languages.getLanguage(tok);
709 font.setLanguage(lang);
711 font.setLanguage(params.language);
712 lex.printError("Unknown language `$$Token'");
714 } else if (token == "\\numeric") {
716 font.setNumber(font.setLyXMisc(lex.getString()));
717 } else if (token == "\\emph") {
719 font.setEmph(font.setLyXMisc(lex.getString()));
720 } else if (token == "\\bar") {
722 string const tok = lex.getString();
723 // This is dirty, but gone with LyX3. (Asger)
725 font.setUnderbar(LyXFont::ON);
726 else if (tok == "no")
727 font.setUnderbar(LyXFont::OFF);
728 else if (tok == "default")
729 font.setUnderbar(LyXFont::INHERIT);
731 lex.printError("Unknown bar font flag "
733 } else if (token == "\\noun") {
735 font.setNoun(font.setLyXMisc(lex.getString()));
736 } else if (token == "\\color") {
738 font.setLyXColor(lex.getString());
739 } else if (token == "\\SpecialChar") {
740 LyXLayout_ptr const & layout = par->layout();
742 // Insets don't make sense in a free-spacing context! ---Kayvan
743 if (layout->free_spacing || par->isFreeSpacing()) {
746 string next_token = lex.getString();
747 if (next_token == "\\-") {
748 par->insertChar(pos, '-', font);
749 } else if (next_token == "\\protected_separator"
750 || next_token == "~") {
751 par->insertChar(pos, ' ', font);
753 lex.printError("Token `$$Token' "
755 "paragraph layout!");
760 Inset * inset = new InsetSpecialChar;
761 inset->read(this, lex);
762 par->insertInset(pos, inset, font);
765 } else if (token == "\\i") {
766 Inset * inset = new InsetLatexAccent;
767 inset->read(this, lex);
768 par->insertInset(pos, inset, font);
770 } else if (token == "\\backslash") {
771 #ifndef NO_COMPABILITY
772 if (ert_comp.active) {
773 ert_comp.contents += "\\";
776 par->insertChar(pos, '\\', font);
778 #ifndef NO_COMPABILITY
781 #ifndef NO_COMPABILITY
782 } else if (token == "\\begin_float") {
783 insertErtContents(par, pos);
784 //insertErtContents(par, pos, false);
785 //ert_stack.push(ert_comp);
786 //ert_comp = ErtComp();
788 // This is the compability reader. It can be removed in
789 // LyX version 1.3.0. (Lgb)
791 string const tmptok = lex.getString();
792 //lyxerr << "old float: " << tmptok << endl;
795 stringstream old_float;
797 if (tmptok == "footnote") {
798 inset = new InsetFoot(params);
799 old_float << "collapsed true\n";
800 } else if (tmptok == "margin") {
801 inset = new InsetMarginal(params);
802 old_float << "collapsed true\n";
803 } else if (tmptok == "fig") {
804 inset = new InsetFloat(params, "figure");
805 old_float << "wide false\n"
806 << "collapsed false\n";
807 } else if (tmptok == "tab") {
808 inset = new InsetFloat(params, "table");
809 old_float << "wide false\n"
810 << "collapsed false\n";
811 } else if (tmptok == "alg") {
812 inset = new InsetFloat(params, "algorithm");
813 old_float << "wide false\n"
814 << "collapsed false\n";
815 } else if (tmptok == "wide-fig") {
816 inset = new InsetFloat(params, "figure");
817 //InsetFloat * tmp = new InsetFloat("figure");
820 old_float << "wide true\n"
821 << "collapsed false\n";
822 } else if (tmptok == "wide-tab") {
823 inset = new InsetFloat(params, "table");
824 //InsetFloat * tmp = new InsetFloat("table");
827 old_float << "wide true\n"
828 << "collapsed false\n";
832 #ifndef NO_PEXTRA_REALLY
835 return false; // no end read yet
838 // Here we need to check for \end_deeper and handle that
839 // before we do the footnote parsing.
840 // This _is_ a hack! (Lgb)
843 string const tmp = lex.getString();
844 if (tmp == "\\end_deeper") {
845 //lyxerr << "\\end_deeper caught!" << endl;
847 lex.printError("\\end_deeper: "
848 "depth is already null");
853 old_float << tmp << ' ';
858 old_float << lex.getLongString("\\end_float")
859 << "\n\\end_inset\n";
860 //lyxerr << "Float Body:\n" << old_float.str() << endl;
861 // That this does not work seems like a bug
862 // in stringstream. (Lgb)
863 istringstream istr(old_float.str());
865 nylex.setStream(istr);
866 inset->read(this, nylex);
867 par->insertInset(pos, inset, font);
869 insertErtContents(par, pos);
871 // we have to reset the font as in the old format after a float
872 // the font was automatically reset!
873 font = LyXFont(LyXFont::ALL_INHERIT, params.language);
875 } else if (token == "\\begin_deeper") {
877 } else if (token == "\\end_deeper") {
879 lex.printError("\\end_deeper: "
880 "depth is already null");
884 } else if (token == "\\begin_preamble") {
885 params.readPreamble(lex);
886 } else if (token == "\\textclass") {
888 pair<bool, textclass_type> pp =
889 textclasslist.NumberOfClass(lex.getString());
891 params.textclass = pp.second;
893 Alert::alert(string(_("Textclass error")),
894 string(_("The document uses an unknown textclass \"")) +
895 lex.getString() + string("\"."),
896 string(_("LyX will not be able to produce output correctly.")));
897 params.textclass = 0;
899 if (!params.getLyXTextClass().load()) {
900 // if the textclass wasn't loaded properly
901 // we need to either substitute another
902 // or stop loading the file.
903 // I can substitute but I don't see how I can
904 // stop loading... ideas?? ARRae980418
905 Alert::alert(_("Textclass Loading Error!"),
906 string(_("Can't load textclass ")) +
907 params.getLyXTextClass().name(),
908 _("-- substituting default"));
909 params.textclass = 0;
911 } else if (token == "\\options") {
913 params.options = lex.getString();
914 } else if (token == "\\language") {
915 params.readLanguage(lex);
916 } else if (token == "\\fontencoding") {
918 } else if (token == "\\inputencoding") {
920 params.inputenc = lex.getString();
921 } else if (token == "\\graphics") {
922 params.readGraphicsDriver(lex);
923 } else if (token == "\\fontscheme") {
925 params.fonts = lex.getString();
926 } else if (token == "\\noindent") {
927 par->params().noindent(true);
928 } else if (token == "\\leftindent") {
930 LyXLength value(lex.getString());
931 par->params().leftIndent(value);
932 } else if (token == "\\fill_top") {
933 par->params().spaceTop(VSpace(VSpace::VFILL));
934 } else if (token == "\\fill_bottom") {
935 par->params().spaceBottom(VSpace(VSpace::VFILL));
936 } else if (token == "\\line_top") {
937 par->params().lineTop(true);
938 } else if (token == "\\line_bottom") {
939 par->params().lineBottom(true);
940 } else if (token == "\\pagebreak_top") {
941 par->params().pagebreakTop(true);
942 } else if (token == "\\pagebreak_bottom") {
943 par->params().pagebreakBottom(true);
944 } else if (token == "\\start_of_appendix") {
945 par->params().startOfAppendix(true);
946 } else if (token == "\\paragraph_separation") {
947 int tmpret = lex.findToken(string_paragraph_separation);
950 params.paragraph_separation =
951 static_cast<BufferParams::PARSEP>(tmpret);
952 } else if (token == "\\defskip") {
954 params.defskip = VSpace(lex.getString());
955 #ifndef NO_COMPABILITY
956 } else if (token == "\\epsfig") { // obsolete
957 // Indeed it is obsolete, but we HAVE to be backwards
958 // compatible until 0.14, because otherwise all figures
959 // in existing documents are irretrivably lost. (Asger)
960 params.readGraphicsDriver(lex);
962 } else if (token == "\\quotes_language") {
963 int tmpret = lex.findToken(string_quotes_language);
966 InsetQuotes::quote_language tmpl =
967 InsetQuotes::EnglishQ;
970 tmpl = InsetQuotes::EnglishQ;
973 tmpl = InsetQuotes::SwedishQ;
976 tmpl = InsetQuotes::GermanQ;
979 tmpl = InsetQuotes::PolishQ;
982 tmpl = InsetQuotes::FrenchQ;
985 tmpl = InsetQuotes::DanishQ;
988 params.quotes_language = tmpl;
989 } else if (token == "\\quotes_times") {
991 switch (lex.getInteger()) {
993 params.quotes_times = InsetQuotes::SingleQ;
996 params.quotes_times = InsetQuotes::DoubleQ;
999 } else if (token == "\\papersize") {
1000 int tmpret = lex.findToken(string_papersize);
1004 params.papersize2 = tmpret;
1005 } else if (token == "\\paperpackage") {
1006 int tmpret = lex.findToken(string_paperpackages);
1009 params.paperpackage = BufferParams::PACKAGE_NONE;
1011 params.paperpackage = tmpret;
1012 } else if (token == "\\use_geometry") {
1014 params.use_geometry = lex.getInteger();
1015 } else if (token == "\\use_amsmath") {
1017 params.use_amsmath = lex.getInteger();
1018 } else if (token == "\\use_natbib") {
1020 params.use_natbib = lex.getInteger();
1021 } else if (token == "\\use_numerical_citations") {
1023 params.use_numerical_citations = lex.getInteger();
1024 } else if (token == "\\paperorientation") {
1025 int tmpret = lex.findToken(string_orientation);
1028 params.orientation =
1029 static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
1030 } else if (token == "\\paperwidth") {
1032 params.paperwidth = lex.getString();
1033 } else if (token == "\\paperheight") {
1035 params.paperheight = lex.getString();
1036 } else if (token == "\\leftmargin") {
1038 params.leftmargin = lex.getString();
1039 } else if (token == "\\topmargin") {
1041 params.topmargin = lex.getString();
1042 } else if (token == "\\rightmargin") {
1044 params.rightmargin = lex.getString();
1045 } else if (token == "\\bottommargin") {
1047 params.bottommargin = lex.getString();
1048 } else if (token == "\\headheight") {
1050 params.headheight = lex.getString();
1051 } else if (token == "\\headsep") {
1053 params.headsep = lex.getString();
1054 } else if (token == "\\footskip") {
1056 params.footskip = lex.getString();
1057 } else if (token == "\\paperfontsize") {
1059 params.fontsize = rtrim(lex.getString());
1060 } else if (token == "\\papercolumns") {
1062 params.columns = lex.getInteger();
1063 } else if (token == "\\papersides") {
1065 switch (lex.getInteger()) {
1067 case 1: params.sides = LyXTextClass::OneSide; break;
1068 case 2: params.sides = LyXTextClass::TwoSides; break;
1070 } else if (token == "\\paperpagestyle") {
1072 params.pagestyle = rtrim(lex.getString());
1073 } else if (token == "\\bullet") {
1075 int const index = lex.getInteger();
1077 int temp_int = lex.getInteger();
1078 params.user_defined_bullets[index].setFont(temp_int);
1079 params.temp_bullets[index].setFont(temp_int);
1081 temp_int = lex.getInteger();
1082 params.user_defined_bullets[index].setCharacter(temp_int);
1083 params.temp_bullets[index].setCharacter(temp_int);
1085 temp_int = lex.getInteger();
1086 params.user_defined_bullets[index].setSize(temp_int);
1087 params.temp_bullets[index].setSize(temp_int);
1089 string const temp_str = lex.getString();
1090 if (temp_str != "\\end_bullet") {
1091 // this element isn't really necessary for
1092 // parsing but is easier for humans
1093 // to understand bullets. Put it back and
1094 // set a debug message?
1095 lex.printError("\\end_bullet expected, got" + temp_str);
1096 //how can I put it back?
1098 } else if (token == "\\bulletLaTeX") {
1099 // The bullet class should be able to read this.
1101 int const index = lex.getInteger();
1103 string temp_str = lex.getString();
1105 while (temp_str != "\\end_bullet") {
1106 // this loop structure is needed when user
1107 // enters an empty string since the first
1108 // thing returned will be the \\end_bullet
1110 // if the LaTeX entry has spaces. Each element
1111 // therefore needs to be read in turn
1112 sum_str += temp_str;
1114 temp_str = lex.getString();
1117 params.user_defined_bullets[index].setText(sum_str);
1118 params.temp_bullets[index].setText(sum_str);
1119 } else if (token == "\\secnumdepth") {
1121 params.secnumdepth = lex.getInteger();
1122 } else if (token == "\\tocdepth") {
1124 params.tocdepth = lex.getInteger();
1125 } else if (token == "\\spacing") {
1127 string const tmp = rtrim(lex.getString());
1128 Spacing::Space tmp_space = Spacing::Default;
1129 float tmp_val = 0.0;
1130 if (tmp == "single") {
1131 tmp_space = Spacing::Single;
1132 } else if (tmp == "onehalf") {
1133 tmp_space = Spacing::Onehalf;
1134 } else if (tmp == "double") {
1135 tmp_space = Spacing::Double;
1136 } else if (tmp == "other") {
1138 tmp_space = Spacing::Other;
1139 tmp_val = lex.getFloat();
1141 lex.printError("Unknown spacing token: '$$Token'");
1143 // Small hack so that files written with klyx will be
1144 // parsed correctly.
1146 par->params().spacing(Spacing(tmp_space, tmp_val));
1148 params.spacing.set(tmp_space, tmp_val);
1150 } else if (token == "\\paragraph_spacing") {
1152 string const tmp = rtrim(lex.getString());
1153 if (tmp == "single") {
1154 par->params().spacing(Spacing(Spacing::Single));
1155 } else if (tmp == "onehalf") {
1156 par->params().spacing(Spacing(Spacing::Onehalf));
1157 } else if (tmp == "double") {
1158 par->params().spacing(Spacing(Spacing::Double));
1159 } else if (tmp == "other") {
1161 par->params().spacing(Spacing(Spacing::Other,
1164 lex.printError("Unknown spacing token: '$$Token'");
1166 } else if (token == "\\float_placement") {
1168 params.float_placement = lex.getString();
1169 } else if (token == "\\align") {
1170 int tmpret = lex.findToken(string_align);
1171 if (tmpret == -1) ++tmpret;
1172 int const tmpret2 = int(pow(2.0, tmpret));
1173 par->params().align(LyXAlignment(tmpret2));
1174 } else if (token == "\\added_space_top") {
1176 VSpace value = VSpace(lex.getString());
1177 // only add the length when value > 0 or
1179 if ((value.length().len().value() != 0) ||
1181 (value.kind() != VSpace::LENGTH))
1182 par->params().spaceTop(value);
1183 } else if (token == "\\added_space_bottom") {
1185 VSpace value = VSpace(lex.getString());
1186 // only add the length when value > 0 or
1188 if ((value.length().len().value() != 0) ||
1190 (value.kind() != VSpace::LENGTH))
1191 par->params().spaceBottom(value);
1192 #ifndef NO_COMPABILITY
1193 #ifndef NO_PEXTRA_REALLY
1194 } else if (token == "\\pextra_type") {
1196 par->params().pextraType(lex.getInteger());
1197 } else if (token == "\\pextra_width") {
1199 par->params().pextraWidth(lex.getString());
1200 } else if (token == "\\pextra_widthp") {
1202 par->params().pextraWidthp(lex.getString());
1203 } else if (token == "\\pextra_alignment") {
1205 par->params().pextraAlignment(lex.getInteger());
1206 } else if (token == "\\pextra_hfill") {
1208 par->params().pextraHfill(lex.getInteger());
1209 } else if (token == "\\pextra_start_minipage") {
1211 par->params().pextraStartMinipage(lex.getInteger());
1214 } else if (token == "\\labelwidthstring") {
1216 par->params().labelWidthString(lex.getString());
1217 // do not delete this token, it is still needed!
1218 } else if (token == "\\newline") {
1219 #ifndef NO_COMPABILITY
1220 if (!ert_comp.in_tabular && ert_comp.active) {
1221 ert_comp.contents += char(Paragraph::META_NEWLINE);
1223 // Since we cannot know it this is only a regular
1224 // newline or a tabular cell delimter we have to
1225 // handle the ERT here.
1226 insertErtContents(par, pos, false);
1228 par->insertChar(pos, Paragraph::META_NEWLINE, font);
1232 par->insertChar(pos, Paragraph::META_NEWLINE, font);
1235 } else if (token == "\\LyXTable") {
1236 #ifndef NO_COMPABILITY
1237 ert_comp.in_tabular = true;
1239 Inset * inset = new InsetTabular(*this);
1240 inset->read(this, lex);
1241 par->insertInset(pos, inset, font);
1243 } else if (token == "\\hfill") {
1244 par->insertChar(pos, Paragraph::META_HFILL, font);
1246 } else if (token == "\\protected_separator") { // obsolete
1247 // This is a backward compability thingie. (Lgb)
1248 // Remove it later some time...introduced with fileformat
1250 LyXLayout_ptr const & layout = par->layout();
1252 if (layout->free_spacing || par->isFreeSpacing()) {
1253 par->insertChar(pos, ' ', font);
1255 Inset * inset = new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
1256 par->insertInset(pos, inset, font);
1259 } else if (token == "\\bibitem") { // ale970302
1261 InsetCommandParams p("bibitem", "dummy");
1262 par->bibkey = new InsetBibKey(p);
1264 par->bibkey->read(this, lex);
1265 } else if (token == "\\the_end") {
1266 #ifndef NO_COMPABILITY
1267 // If we still have some ert active here we have to insert
1268 // it so we don't loose it. (Lgb)
1269 insertErtContents(par, pos);
1271 the_end_read = true;
1272 #ifndef NO_COMPABILITY
1273 #ifndef NO_PEXTRA_REALLY
1276 minipar = parBeforeMinipage = 0;
1280 #ifndef NO_COMPABILITY
1281 if (ert_comp.active) {
1282 ert_comp.contents += token;
1285 // This should be insurance for the future: (Asger)
1288 string const s = _("Unknown token: ") + token
1289 + " " + lex.text() + "\n";
1290 // we can do this here this way because we're actually reading
1291 // the buffer and don't care about LyXText right now.
1292 InsetError * new_inset = new InsetError(s);
1293 par->insertInset(pos, new_inset, LyXFont(LyXFont::ALL_INHERIT,
1296 #ifndef NO_COMPABILITY
1301 #ifndef NO_COMPABILITY
1302 #ifndef NO_PEXTRA_REALLY
1303 // I wonder if we could use this blanket fix for all the
1304 // checkminipage cases...
1305 // don't forget about ert paragraphs and compatibility read for'em
1306 if (par && (par->size() || !ert_comp.contents.empty())) {
1307 // It is possible that this will check to often,
1308 // but that should not be an correctness issue.
1309 // Only a speed issue.
1310 checkminipage = true;
1313 // now check if we have a minipage paragraph as at this
1314 // point we already read all the necessary data!
1315 // this cannot be done in layout because there we did
1316 // not read yet the paragraph PEXTRA-params (Jug)
1318 // BEGIN pextra_minipage compability
1319 // This should be removed in 1.3.x (Lgb)
1320 // I don't think we should remove this so fast (Jug)
1322 // This compability code is not perfect. In a couple
1323 // of rand cases it fails. When the minipage par is
1324 // the first par in the document, and when there are
1325 // none or only one regular paragraphs after the
1326 // minipage. Currently I am not investing any effort
1327 // in fixing those cases.
1329 // lyxerr << "Call depth: " << call_depth << endl;
1330 // lyxerr << "Checkminipage: " << checkminipage << endl;
1332 if (checkminipage && (call_depth == 1)) {
1333 checkminipage = false;
1334 if (minipar && (minipar != par) &&
1335 (par->params().pextraType() == Paragraph::PEXTRA_MINIPAGE)) {
1336 lyxerr << "minipages in a row" << endl;
1337 if (par->params().pextraStartMinipage()) {
1338 lyxerr << "start new minipage" << endl;
1339 // minipages in a row
1340 par->previous()->next(0);
1343 Paragraph * tmp = minipar;
1345 tmp->params().pextraType(0);
1346 tmp->params().pextraWidth(string());
1347 tmp->params().pextraWidthp(string());
1348 tmp->params().pextraAlignment(0);
1349 tmp->params().pextraHfill(false);
1350 tmp->params().pextraStartMinipage(false);
1353 // create a new paragraph to insert the
1354 // minipages in the following case
1355 if (par->params().pextraStartMinipage() &&
1356 !par->params().pextraHfill()) {
1357 Paragraph * p = new Paragraph;
1358 p->layout(params.getLyXTextClass().defaultLayoutName());
1360 p->previous(parBeforeMinipage);
1361 parBeforeMinipage->next(p);
1363 p->params().depth(parBeforeMinipage->params().depth());
1364 parBeforeMinipage = p;
1366 InsetMinipage * mini = new InsetMinipage(params);
1367 mini->pos(static_cast<InsetMinipage::Position>(par->params().pextraAlignment()));
1368 mini->pageWidth(LyXLength(par->params().pextraWidth()));
1369 if (!par->params().pextraWidthp().empty()) {
1370 lyxerr << "WP:" << mini->pageWidth().asString() << endl;
1371 mini->pageWidth(LyXLength((par->params().pextraWidthp())+"col%"));
1373 Paragraph * op = mini->firstParagraph();
1374 mini->inset.paragraph(par);
1376 // and free the old ones!
1379 Paragraph * pp = op->next();
1383 // Insert the minipage last in the
1384 // previous paragraph.
1385 if (par->params().pextraHfill()) {
1386 parBeforeMinipage->insertChar
1387 (parBeforeMinipage->size(),
1388 Paragraph::META_HFILL, font);
1390 parBeforeMinipage->insertInset
1391 (parBeforeMinipage->size(), mini, font);
1395 lyxerr << "new minipage par" << endl;
1396 //nothing to do just continue reading
1399 } else if (minipar && (minipar != par)) {
1400 lyxerr << "last minipage par read" << endl;
1401 // The last paragraph read was not part of a
1402 // minipage but the par linked list is...
1403 // So we need to remove the last par from the
1405 if (par->previous())
1406 par->previous()->next(0);
1407 par->previous(parBeforeMinipage);
1408 parBeforeMinipage->next(par);
1409 Paragraph * tmp = minipar;
1411 tmp->params().pextraType(0);
1412 tmp->params().pextraWidth(string());
1413 tmp->params().pextraWidthp(string());
1414 tmp->params().pextraAlignment(0);
1415 tmp->params().pextraHfill(false);
1416 tmp->params().pextraStartMinipage(false);
1419 depth = parBeforeMinipage->params().depth();
1420 // and set this depth on the par as it has not been set already
1421 par->params().depth(depth);
1422 minipar = parBeforeMinipage = 0;
1423 } else if (!minipar &&
1424 (par->params().pextraType() == Paragraph::PEXTRA_MINIPAGE)) {
1425 // par is the first paragraph in a minipage
1426 lyxerr << "begin minipage" << endl;
1427 // To minimize problems for
1428 // the users we will insert
1429 // the first minipage in
1430 // a sequence of minipages
1431 // in its own paragraph.
1432 Paragraph * p = new Paragraph;
1433 p->layout(params.getLyXTextClass().defaultLayoutName());
1434 p->previous(par->previous());
1436 p->params().depth(depth);
1437 par->params().depth(0);
1439 if (par->previous())
1440 par->previous()->next(p);
1442 parBeforeMinipage = p;
1444 if (!first_par || (first_par == par))
1447 InsetMinipage * mini = new InsetMinipage(params);
1448 mini->pos(static_cast<InsetMinipage::Position>(minipar->params().pextraAlignment()));
1449 mini->pageWidth(LyXLength(minipar->params().pextraWidth()));
1450 if (!par->params().pextraWidthp().empty()) {
1451 lyxerr << "WP:" << mini->pageWidth().asString() << endl;
1452 mini->pageWidth(LyXLength((par->params().pextraWidthp())+"col%"));
1455 Paragraph * op = mini->firstParagraph();
1456 mini->inset.paragraph(minipar);
1458 // and free the old ones!
1461 Paragraph * pp = op->next();
1466 // Insert the minipage last in the
1467 // previous paragraph.
1468 if (minipar->params().pextraHfill()) {
1469 parBeforeMinipage->insertChar
1470 (parBeforeMinipage->size(),
1471 Paragraph::META_HFILL, font);
1473 parBeforeMinipage->insertInset
1474 (parBeforeMinipage->size(), mini, font);
1475 } else if (par->params().pextraType() == Paragraph::PEXTRA_INDENT) {
1476 par->params().leftIndent(LyXLength(par->params().pextraWidth()));
1477 if (!par->params().pextraWidthp().empty()) {
1478 par->params().leftIndent(LyXLength((par->params().pextraWidthp())+"col%"));
1482 // End of pextra_minipage compability
1486 return the_end_read;
1489 // needed to insert the selection
1490 void Buffer::insertStringAsLines(Paragraph *& par, pos_type & pos,
1491 LyXFont const & fn,string const & str) const
1493 LyXLayout_ptr const & layout = par->layout();
1497 par->checkInsertChar(font);
1498 // insert the string, don't insert doublespace
1499 bool space_inserted = true;
1500 bool autobreakrows = !par->inInset() ||
1501 static_cast<InsetText *>(par->inInset())->getAutoBreakRows();
1502 for(string::const_iterator cit = str.begin();
1503 cit != str.end(); ++cit) {
1505 if (autobreakrows && (par->size() || layout->keepempty)) {
1506 par->breakParagraph(params, pos,
1507 layout->isEnvironment());
1510 space_inserted = true;
1514 // do not insert consecutive spaces if !free_spacing
1515 } else if ((*cit == ' ' || *cit == '\t') &&
1516 space_inserted && !layout->free_spacing &&
1517 !par->isFreeSpacing())
1520 } else if (*cit == '\t') {
1521 if (!layout->free_spacing && !par->isFreeSpacing()) {
1522 // tabs are like spaces here
1523 par->insertChar(pos, ' ', font);
1525 space_inserted = true;
1527 const pos_type nb = 8 - pos % 8;
1528 for (pos_type a = 0; a < nb ; ++a) {
1529 par->insertChar(pos, ' ', font);
1532 space_inserted = true;
1534 } else if (!IsPrintable(*cit)) {
1535 // Ignore unprintables
1538 // just insert the character
1539 par->insertChar(pos, *cit, font);
1541 space_inserted = (*cit == ' ');
1548 void Buffer::readInset(LyXLex & lex, Paragraph *& par,
1549 int & pos, LyXFont & font)
1551 // consistency check
1552 if (lex.getString() != "\\begin_inset") {
1553 lyxerr << "Buffer::readInset: Consistency check failed."
1560 string const tmptok = lex.getString();
1561 last_inset_read = tmptok;
1563 // test the different insets
1564 if (tmptok == "LatexCommand") {
1565 InsetCommandParams inscmd;
1568 string const cmdName = inscmd.getCmdName();
1570 // This strange command allows LyX to recognize "natbib" style
1571 // citations: citet, citep, Citet etc.
1572 if (compare_ascii_no_case(cmdName.substr(0,4), "cite") == 0) {
1573 inset = new InsetCitation(inscmd);
1574 } else if (cmdName == "bibitem") {
1575 lex.printError("Wrong place for bibitem");
1576 inset = new InsetBibKey(inscmd);
1577 } else if (cmdName == "BibTeX") {
1578 inset = new InsetBibtex(inscmd);
1579 } else if (cmdName == "index") {
1580 inset = new InsetIndex(inscmd);
1581 } else if (cmdName == "include") {
1582 inset = new InsetInclude(inscmd, *this);
1583 } else if (cmdName == "label") {
1584 inset = new InsetLabel(inscmd);
1585 } else if (cmdName == "url"
1586 || cmdName == "htmlurl") {
1587 inset = new InsetUrl(inscmd);
1588 } else if (cmdName == "ref"
1589 || cmdName == "pageref"
1590 || cmdName == "vref"
1591 || cmdName == "vpageref"
1592 || cmdName == "prettyref") {
1593 if (!inscmd.getOptions().empty()
1594 || !inscmd.getContents().empty()) {
1595 inset = new InsetRef(inscmd, *this);
1597 } else if (cmdName == "tableofcontents") {
1598 inset = new InsetTOC(inscmd);
1599 } else if (cmdName == "listofalgorithms") {
1600 inset = new InsetFloatList("algorithm");
1601 } else if (cmdName == "listoffigures") {
1602 inset = new InsetFloatList("figure");
1603 } else if (cmdName == "listoftables") {
1604 inset = new InsetFloatList("table");
1605 } else if (cmdName == "printindex") {
1606 inset = new InsetPrintIndex(inscmd);
1607 } else if (cmdName == "lyxparent") {
1608 inset = new InsetParent(inscmd, *this);
1611 bool alreadyread = false;
1612 if (tmptok == "Quotes") {
1613 inset = new InsetQuotes;
1614 } else if (tmptok == "External") {
1615 inset = new InsetExternal;
1616 } else if (tmptok == "FormulaMacro") {
1617 inset = new InsetFormulaMacro;
1618 } else if (tmptok == "Formula") {
1619 inset = new InsetFormula;
1620 } else if (tmptok == "Figure") { // Backward compatibility
1621 // inset = new InsetFig(100, 100, *this);
1622 inset = new InsetGraphics;
1623 } else if (tmptok == "Graphics") {
1624 inset = new InsetGraphics;
1625 } else if (tmptok == "Info") {// backwards compatibility
1626 inset = new InsetNote(this,
1627 lex.getLongString("\\end_inset"),
1630 } else if (tmptok == "Note") {
1631 inset = new InsetNote(params);
1632 } else if (tmptok == "Include") {
1633 InsetCommandParams p("Include");
1634 inset = new InsetInclude(p, *this);
1635 } else if (tmptok == "ERT") {
1636 inset = new InsetERT(params);
1637 } else if (tmptok == "Tabular") {
1638 inset = new InsetTabular(*this);
1639 } else if (tmptok == "Text") {
1640 inset = new InsetText(params);
1641 } else if (tmptok == "Foot") {
1642 inset = new InsetFoot(params);
1643 } else if (tmptok == "Marginal") {
1644 inset = new InsetMarginal(params);
1645 } else if (tmptok == "Minipage") {
1646 inset = new InsetMinipage(params);
1647 } else if (tmptok == "Float") {
1649 string tmptok = lex.getString();
1650 inset = new InsetFloat(params, tmptok);
1652 } else if (tmptok == "List") {
1653 inset = new InsetList;
1654 } else if (tmptok == "Theorem") {
1655 inset = new InsetList;
1657 } else if (tmptok == "Caption") {
1658 inset = new InsetCaption(params);
1659 } else if (tmptok == "FloatList") {
1660 inset = new InsetFloatList;
1663 if (inset && !alreadyread) inset->read(this, lex);
1667 par->insertInset(pos, inset, font);
1673 bool Buffer::readFile(LyXLex & lex, Paragraph * par)
1677 string const token(lex.getString());
1678 if (token == "\\lyxformat") { // the first token _must_ be...
1680 string tmp_format = lex.getString();
1681 //lyxerr << "LyX Format: `" << tmp_format << "'" << endl;
1682 // if present remove ".," from string.
1683 string::size_type dot = tmp_format.find_first_of(".,");
1684 //lyxerr << " dot found at " << dot << endl;
1685 if (dot != string::npos)
1686 tmp_format.erase(dot, 1);
1687 file_format = strToInt(tmp_format);
1688 if (file_format == LYX_FORMAT) {
1690 } else if (file_format > LYX_FORMAT) {
1692 Alert::alert(_("Warning!"),
1693 _("LyX file format is newer that what"),
1694 _("is supported in this LyX version. Expect some problems."));
1696 } else if (file_format < LYX_FORMAT) {
1698 if (file_format < 200) {
1699 Alert::alert(_("ERROR!"),
1700 _("Old LyX file format found. "
1701 "Use LyX 0.10.x to read this!"));
1703 } else if (file_format < 220) {
1704 string const command = "lyx2lyx "
1705 + QuoteName(filename_);
1706 cmd_ret const ret = RunCommand(command);
1708 Alert::alert(_("ERROR!"),
1709 _("An error occured while "
1710 "running the conversion script."));
1713 istringstream is(ret.second);
1714 LyXLex tmplex(0, 0);
1715 tmplex.setStream(is);
1716 return readFile(tmplex);
1719 bool the_end = readLyXformat2(lex, par);
1720 params.setPaperStuff();
1723 // the_end was added in 213
1724 if (file_format < 213)
1729 Alert::alert(_("Warning!"),
1730 _("Reading of document is not complete"),
1731 _("Maybe the document is truncated"));
1734 } else { // "\\lyxformat" not found
1735 Alert::alert(_("ERROR!"), _("Not a LyX file!"));
1738 Alert::alert(_("ERROR!"), _("Unable to read file!"));
1743 // Should probably be moved to somewhere else: BufferView? LyXView?
1744 bool Buffer::save() const
1746 // We don't need autosaves in the immediate future. (Asger)
1747 resetAutosaveTimers();
1751 if (lyxrc.make_backup) {
1752 s = fileName() + '~';
1753 if (!lyxrc.backupdir_path.empty())
1754 s = AddName(lyxrc.backupdir_path,
1755 subst(os::slashify_path(s),'/','!'));
1757 // Rename is the wrong way of making a backup,
1758 // this is the correct way.
1759 /* truss cp fil fil2:
1760 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
1761 stat("LyXVC.lyx", 0xEFFFF688) = 0
1762 open("LyXVC.lyx", O_RDONLY) = 3
1763 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
1764 fstat(4, 0xEFFFF508) = 0
1765 fstat(3, 0xEFFFF508) = 0
1766 read(3, " # T h i s f i l e w".., 8192) = 5579
1767 write(4, " # T h i s f i l e w".., 5579) = 5579
1768 read(3, 0xEFFFD4A0, 8192) = 0
1771 chmod("LyXVC3.lyx", 0100644) = 0
1772 lseek(0, 0, SEEK_CUR) = 46440
1776 // Should probably have some more error checking here.
1777 // Doing it this way, also makes the inodes stay the same.
1778 // This is still not a very good solution, in particular we
1779 // might loose the owner of the backup.
1780 FileInfo finfo(fileName());
1781 if (finfo.exist()) {
1782 mode_t fmode = finfo.getMode();
1783 struct utimbuf times = {
1784 finfo.getAccessTime(),
1785 finfo.getModificationTime() };
1787 ifstream ifs(fileName().c_str());
1788 ofstream ofs(s.c_str(), ios::out|ios::trunc);
1793 ::chmod(s.c_str(), fmode);
1795 if (::utime(s.c_str(), ×)) {
1796 lyxerr << "utime error." << endl;
1799 lyxerr << "LyX was not able to make "
1800 "backup copy. Beware." << endl;
1805 if (writeFile(fileName())) {
1807 removeAutosaveFile(fileName());
1809 // Saving failed, so backup is not backup
1810 if (lyxrc.make_backup) {
1811 lyx::rename(s, fileName());
1819 bool Buffer::writeFile(string const & fname) const
1821 if (read_only && (fname == fileName())) {
1825 FileInfo finfo(fname);
1826 if (finfo.exist() && !finfo.writable()) {
1830 ofstream ofs(fname.c_str());
1836 // Use the standard "C" locale for file output.
1837 ofs.imbue(std::locale::classic());
1840 // The top of the file should not be written by params.
1842 // write out a comment in the top of the file
1843 ofs << '#' << lyx_docversion
1844 << " created this file. For more info see http://www.lyx.org/\n"
1845 << "\\lyxformat " << LYX_FORMAT << "\n";
1847 // now write out the buffer paramters.
1848 params.writeFile(ofs);
1850 Paragraph::depth_type depth = 0;
1852 // this will write out all the paragraphs
1853 // using recursive descent.
1854 paragraph->writeFile(this, ofs, params, depth);
1856 // Write marker that shows file is complete
1857 ofs << "\n\\the_end" << endl;
1861 // how to check if close went ok?
1862 // Following is an attempt... (BE 20001011)
1864 // good() returns false if any error occured, including some
1865 // formatting error.
1866 // bad() returns true if something bad happened in the buffer,
1867 // which should include file system full errors.
1874 lyxerr << "Buffer::writeFile: BAD ERROR!" << endl;
1876 lyxerr << "Buffer::writeFile: NOT SO BAD ERROR!"
1888 pair<int, string> const addDepth(int depth, int ldepth)
1892 d += (ldepth - depth) * 2;
1893 return make_pair(d, string(d, ' '));
1899 string const Buffer::asciiParagraph(Paragraph const * par,
1900 unsigned int linelen,
1901 bool noparbreak) const
1903 ostringstream buffer;
1904 Paragraph::depth_type depth = 0;
1906 Paragraph::depth_type ltype_depth = 0;
1907 bool ref_printed = false;
1908 // if (!par->previous()) {
1910 // begins or ends a deeper area ?
1911 if (depth != par->params().depth()) {
1912 if (par->params().depth() > depth) {
1913 while (par->params().depth() > depth) {
1917 while (par->params().depth() < depth) {
1923 depth = par->params().depth();
1926 // First write the layout
1927 string const & tmp = par->layout()->name();
1928 if (compare_no_case(tmp, "itemize") == 0) {
1930 ltype_depth = depth + 1;
1931 } else if (compare_ascii_no_case(tmp, "enumerate") == 0) {
1933 ltype_depth = depth + 1;
1934 } else if (contains(ascii_lowercase(tmp), "ection")) {
1936 ltype_depth = depth + 1;
1937 } else if (contains(ascii_lowercase(tmp), "aragraph")) {
1939 ltype_depth = depth + 1;
1940 } else if (compare_ascii_no_case(tmp, "description") == 0) {
1942 ltype_depth = depth + 1;
1943 } else if (compare_ascii_no_case(tmp, "abstract") == 0) {
1946 } else if (compare_ascii_no_case(tmp, "bibliography") == 0) {
1954 /* maybe some vertical spaces */
1956 /* the labelwidthstring used in lists */
1960 /* some pagebreaks? */
1964 /* what about the alignment */
1966 // lyxerr << "Should this ever happen?" << endl;
1969 // linelen <= 0 is special and means we don't have pargraph breaks
1971 string::size_type currlinelen = 0;
1977 buffer << string(depth * 2, ' ');
1978 currlinelen += depth * 2;
1981 // we should probably change to the paragraph language in the
1982 // gettext here (if possible) so that strings are outputted in
1983 // the correct language! (20012712 Jug)
1987 case 4: // (Sub)Paragraph
1988 case 5: // Description
1992 buffer << _("Abstract") << "\n\n";
1995 string const abst = _("Abstract: ");
1997 currlinelen += abst.length();
2000 case 7: // Bibliography
2003 buffer << _("References") << "\n\n";
2006 string const refs = _("References: ");
2008 currlinelen += refs.length();
2016 string const parlab = par->params().labelString();
2017 buffer << parlab << " ";
2018 currlinelen += parlab.length() + 1;
2026 pair<int, string> p = addDepth(depth, ltype_depth);
2028 currlinelen += p.first;
2031 // this is to change the linebreak to do it by word a bit more
2032 // intelligent hopefully! (only in the case where we have a
2033 // max linelenght!) (Jug)
2037 for (pos_type i = 0; i < par->size(); ++i) {
2038 char c = par->getUChar(params, i);
2040 case Paragraph::META_INSET:
2042 Inset const * inset = par->getInset(i);
2046 currlinelen += word.length();
2049 if (inset->ascii(this, buffer, linelen)) {
2050 // to be sure it breaks paragraph
2051 currlinelen += linelen;
2057 case Paragraph::META_NEWLINE:
2059 buffer << word << "\n";
2062 pair<int, string> p = addDepth(depth,
2065 currlinelen = p.first;
2069 case Paragraph::META_HFILL:
2070 buffer << word << "\t";
2071 currlinelen += word.length() + 1;
2078 currlinelen + word.length() > linelen - 10) {
2080 pair<int, string> p =
2081 addDepth(depth, ltype_depth);
2083 currlinelen = p.first;
2086 buffer << word << ' ';
2087 currlinelen += word.length() + 1;
2094 lyxerr[Debug::INFO] <<
2095 "writeAsciiFile: NULL char in structure." << endl;
2097 if ((linelen > 0) &&
2098 (currlinelen + word.length()) > linelen)
2102 pair<int, string> p =
2103 addDepth(depth, ltype_depth);
2105 currlinelen = p.first;
2112 return buffer.str().c_str();
2116 void Buffer::writeFileAscii(string const & fname, int linelen)
2118 ofstream ofs(fname.c_str());
2120 Alert::err_alert(_("Error: Cannot write file:"), fname);
2123 writeFileAscii(ofs, linelen);
2127 void Buffer::writeFileAscii(ostream & ofs, int linelen)
2129 Paragraph * par = paragraph;
2131 ofs << asciiParagraph(par, linelen, par->previous() == 0);
2141 void Buffer::makeLaTeXFile(string const & fname,
2142 string const & original_path,
2143 bool nice, bool only_body, bool only_preamble)
2145 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
2147 ofstream ofs(fname.c_str());
2149 Alert::err_alert(_("Error: Cannot open file: "), fname);
2153 makeLaTeXFile(ofs, original_path, nice, only_body, only_preamble);
2157 lyxerr << "File was not closed properly." << endl;
2162 void Buffer::makeLaTeXFile(ostream & os,
2163 string const & original_path,
2164 bool nice, bool only_body, bool only_preamble)
2166 niceFile = nice; // this will be used by Insetincludes.
2168 tex_code_break_column = lyxrc.ascii_linelen;
2170 // validate the buffer.
2171 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
2172 LaTeXFeatures features(params);
2174 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
2177 // The starting paragraph of the coming rows is the
2178 // first paragraph of the document. (Asger)
2179 texrow.start(paragraph, 0);
2181 if (!only_body && nice) {
2182 os << "%% " << lyx_docversion << " created this file. "
2183 "For more info, see http://www.lyx.org/.\n"
2184 "%% Do not edit unless you really know what "
2189 lyxerr[Debug::INFO] << "lyx header finished" << endl;
2190 // There are a few differences between nice LaTeX and usual files:
2191 // usual is \batchmode and has a
2192 // special input@path to allow the including of figures
2193 // with either \input or \includegraphics (what figinsets do).
2194 // batchmode is not set if there is a tex_code_break_column.
2195 // In this case somebody is interested in the generated LaTeX,
2196 // so this is OK. input@path is set when the actual parameter
2197 // original_path is set. This is done for usual tex-file, but not
2198 // for nice-latex-file. (Matthias 250696)
2201 // code for usual, NOT nice-latex-file
2202 os << "\\batchmode\n"; // changed
2203 // from \nonstopmode
2206 if (!original_path.empty()) {
2207 string inputpath = os::external_path(original_path);
2208 subst(inputpath, "~", "\\string~");
2209 os << "\\makeatletter\n"
2210 << "\\def\\input@path{{"
2211 << inputpath << "/}}\n"
2212 << "\\makeatother\n";
2218 os << "\\documentclass";
2220 LyXTextClass const & tclass = params.getLyXTextClass();
2222 ostringstream options; // the document class options.
2224 if (tokenPos(tclass.opt_fontsize(),
2225 '|', params.fontsize) >= 0) {
2226 // only write if existing in list (and not default)
2227 options << params.fontsize << "pt,";
2231 if (!params.use_geometry &&
2232 (params.paperpackage == BufferParams::PACKAGE_NONE)) {
2233 switch (params.papersize) {
2234 case BufferParams::PAPER_A4PAPER:
2235 options << "a4paper,";
2237 case BufferParams::PAPER_USLETTER:
2238 options << "letterpaper,";
2240 case BufferParams::PAPER_A5PAPER:
2241 options << "a5paper,";
2243 case BufferParams::PAPER_B5PAPER:
2244 options << "b5paper,";
2246 case BufferParams::PAPER_EXECUTIVEPAPER:
2247 options << "executivepaper,";
2249 case BufferParams::PAPER_LEGALPAPER:
2250 options << "legalpaper,";
2256 if (params.sides != tclass.sides()) {
2257 switch (params.sides) {
2258 case LyXTextClass::OneSide:
2259 options << "oneside,";
2261 case LyXTextClass::TwoSides:
2262 options << "twoside,";
2268 if (params.columns != tclass.columns()) {
2269 if (params.columns == 2)
2270 options << "twocolumn,";
2272 options << "onecolumn,";
2275 if (!params.use_geometry
2276 && params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
2277 options << "landscape,";
2279 // language should be a parameter to \documentclass
2281 ostringstream language_options;
2282 if (params.language->babel() == "hebrew"
2283 && default_language->babel() != "hebrew")
2284 // This seems necessary
2285 features.useLanguage(default_language);
2287 if (lyxrc.language_use_babel ||
2288 params.language->lang() != lyxrc.default_language ||
2289 features.hasLanguages()) {
2291 language_options << features.getLanguages();
2292 language_options << params.language->babel();
2293 if (lyxrc.language_global_options)
2294 options << language_options.str() << ',';
2297 // the user-defined options
2298 if (!params.options.empty()) {
2299 options << params.options << ',';
2302 string strOptions(options.str().c_str());
2303 if (!strOptions.empty()) {
2304 strOptions = rtrim(strOptions, ",");
2305 os << '[' << strOptions << ']';
2308 os << '{' << tclass.latexname() << "}\n";
2310 // end of \documentclass defs
2312 // font selection must be done before loading fontenc.sty
2313 // The ae package is not needed when using OT1 font encoding.
2314 if (params.fonts != "default" &&
2315 (params.fonts != "ae" || lyxrc.fontenc != "default")) {
2316 os << "\\usepackage{" << params.fonts << "}\n";
2318 if (params.fonts == "ae") {
2319 os << "\\usepackage{aecompl}\n";
2323 // this one is not per buffer
2324 if (lyxrc.fontenc != "default") {
2325 os << "\\usepackage[" << lyxrc.fontenc
2330 if (params.inputenc == "auto") {
2331 string const doc_encoding =
2332 params.language->encoding()->LatexName();
2334 // Create a list with all the input encodings used
2336 set<string> encodings = features.getEncodingSet(doc_encoding);
2338 os << "\\usepackage[";
2339 std::copy(encodings.begin(), encodings.end(),
2340 std::ostream_iterator<string>(os, ","));
2341 os << doc_encoding << "]{inputenc}\n";
2343 } else if (params.inputenc != "default") {
2344 os << "\\usepackage[" << params.inputenc
2349 // At the very beginning the text parameters.
2350 if (params.paperpackage != BufferParams::PACKAGE_NONE) {
2351 switch (params.paperpackage) {
2352 case BufferParams::PACKAGE_A4:
2353 os << "\\usepackage{a4}\n";
2356 case BufferParams::PACKAGE_A4WIDE:
2357 os << "\\usepackage{a4wide}\n";
2360 case BufferParams::PACKAGE_WIDEMARGINSA4:
2361 os << "\\usepackage[widemargins]{a4}\n";
2366 if (params.use_geometry) {
2367 os << "\\usepackage{geometry}\n";
2369 os << "\\geometry{verbose";
2370 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
2372 switch (params.papersize2) {
2373 case BufferParams::VM_PAPER_CUSTOM:
2374 if (!params.paperwidth.empty())
2375 os << ",paperwidth="
2376 << params.paperwidth;
2377 if (!params.paperheight.empty())
2378 os << ",paperheight="
2379 << params.paperheight;
2381 case BufferParams::VM_PAPER_USLETTER:
2382 os << ",letterpaper";
2384 case BufferParams::VM_PAPER_USLEGAL:
2385 os << ",legalpaper";
2387 case BufferParams::VM_PAPER_USEXECUTIVE:
2388 os << ",executivepaper";
2390 case BufferParams::VM_PAPER_A3:
2393 case BufferParams::VM_PAPER_A4:
2396 case BufferParams::VM_PAPER_A5:
2399 case BufferParams::VM_PAPER_B3:
2402 case BufferParams::VM_PAPER_B4:
2405 case BufferParams::VM_PAPER_B5:
2409 // default papersize ie BufferParams::VM_PAPER_DEFAULT
2410 switch (lyxrc.default_papersize) {
2411 case BufferParams::PAPER_DEFAULT: // keep compiler happy
2412 case BufferParams::PAPER_USLETTER:
2413 os << ",letterpaper";
2415 case BufferParams::PAPER_LEGALPAPER:
2416 os << ",legalpaper";
2418 case BufferParams::PAPER_EXECUTIVEPAPER:
2419 os << ",executivepaper";
2421 case BufferParams::PAPER_A3PAPER:
2424 case BufferParams::PAPER_A4PAPER:
2427 case BufferParams::PAPER_A5PAPER:
2430 case BufferParams::PAPER_B5PAPER:
2435 if (!params.topmargin.empty())
2436 os << ",tmargin=" << params.topmargin;
2437 if (!params.bottommargin.empty())
2438 os << ",bmargin=" << params.bottommargin;
2439 if (!params.leftmargin.empty())
2440 os << ",lmargin=" << params.leftmargin;
2441 if (!params.rightmargin.empty())
2442 os << ",rmargin=" << params.rightmargin;
2443 if (!params.headheight.empty())
2444 os << ",headheight=" << params.headheight;
2445 if (!params.headsep.empty())
2446 os << ",headsep=" << params.headsep;
2447 if (!params.footskip.empty())
2448 os << ",footskip=" << params.footskip;
2453 if (tokenPos(tclass.opt_pagestyle(),
2454 '|', params.pagestyle) >= 0) {
2455 if (params.pagestyle == "fancy") {
2456 os << "\\usepackage{fancyhdr}\n";
2459 os << "\\pagestyle{" << params.pagestyle << "}\n";
2463 if (params.secnumdepth != tclass.secnumdepth()) {
2464 os << "\\setcounter{secnumdepth}{"
2465 << params.secnumdepth
2469 if (params.tocdepth != tclass.tocdepth()) {
2470 os << "\\setcounter{tocdepth}{"
2476 if (params.paragraph_separation) {
2477 switch (params.defskip.kind()) {
2478 case VSpace::SMALLSKIP:
2479 os << "\\setlength\\parskip{\\smallskipamount}\n";
2481 case VSpace::MEDSKIP:
2482 os << "\\setlength\\parskip{\\medskipamount}\n";
2484 case VSpace::BIGSKIP:
2485 os << "\\setlength\\parskip{\\bigskipamount}\n";
2487 case VSpace::LENGTH:
2488 os << "\\setlength\\parskip{"
2489 << params.defskip.length().asLatexString()
2492 default: // should never happen // Then delete it.
2493 os << "\\setlength\\parskip{\\medskipamount}\n";
2498 os << "\\setlength\\parindent{0pt}\n";
2502 // Now insert the LyX specific LaTeX commands...
2504 // The optional packages;
2505 string preamble(features.getPackages());
2507 // this might be useful...
2508 preamble += "\n\\makeatletter\n";
2510 // Some macros LyX will need
2511 string tmppreamble(features.getMacros());
2513 if (!tmppreamble.empty()) {
2514 preamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2515 "LyX specific LaTeX commands.\n"
2516 + tmppreamble + '\n';
2519 // the text class specific preamble
2520 tmppreamble = features.getTClassPreamble();
2521 if (!tmppreamble.empty()) {
2522 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2523 "Textclass specific LaTeX commands.\n"
2524 + tmppreamble + '\n';
2527 /* the user-defined preamble */
2528 if (!params.preamble.empty()) {
2529 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2530 "User specified LaTeX commands.\n"
2531 + params.preamble + '\n';
2534 // Itemize bullet settings need to be last in case the user
2535 // defines their own bullets that use a package included
2536 // in the user-defined preamble -- ARRae
2537 // Actually it has to be done much later than that
2538 // since some packages like frenchb make modifications
2539 // at \begin{document} time -- JMarc
2541 for (int i = 0; i < 4; ++i) {
2542 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
2543 if (bullets_def.empty())
2544 bullets_def="\\AtBeginDocument{\n";
2545 bullets_def += " \\renewcommand{\\labelitemi";
2547 // `i' is one less than the item to modify
2554 bullets_def += "ii";
2560 bullets_def += "}{" +
2561 params.user_defined_bullets[i].getText()
2566 if (!bullets_def.empty())
2567 preamble += bullets_def + "}\n\n";
2570 int(lyx::count(preamble.begin(), preamble.end(), '\n'));
2571 for (int j = 0; j != nlines; ++j) {
2575 // We try to load babel late, in case it interferes
2576 // with other packages.
2578 string tmp = lyxrc.language_package;
2579 if (!lyxrc.language_global_options
2580 && tmp == "\\usepackage{babel}")
2581 tmp = string("\\usepackage[") +
2582 language_options.str().c_str() +
2584 preamble += tmp + "\n";
2585 preamble += features.getBabelOptions();
2588 preamble += "\\makeatother\n";
2596 os << "\\begin{document}\n";
2599 lyxerr[Debug::INFO] << "preamble finished, now the body." << endl;
2601 if (!lyxrc.language_auto_begin) {
2602 os << subst(lyxrc.language_command_begin, "$$lang",
2603 params.language->babel())
2608 latexParagraphs(os, paragraph, 0, texrow);
2610 // add this just in case after all the paragraphs
2614 if (!lyxrc.language_auto_end) {
2615 os << subst(lyxrc.language_command_end, "$$lang",
2616 params.language->babel())
2622 os << "\\end{document}\n";
2625 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
2627 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
2631 // Just to be sure. (Asger)
2634 // tex_code_break_column's value is used to decide
2635 // if we are in batchmode or not (within mathed_write()
2636 // in math_write.C) so we must set it to a non-zero
2637 // value when we leave otherwise we save incorrect .lyx files.
2638 tex_code_break_column = lyxrc.ascii_linelen;
2640 lyxerr[Debug::INFO] << "Finished making latex file." << endl;
2641 lyxerr[Debug::INFO] << "Row count was " << texrow.rows()-1 << "." << endl;
2643 // we want this to be true outside previews (for insetexternal)
2649 // LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
2651 void Buffer::latexParagraphs(ostream & ofs, Paragraph * par,
2652 Paragraph * endpar, TexRow & texrow,
2653 bool moving_arg) const
2655 bool was_title = false;
2656 bool already_title = false;
2659 while (par != endpar) {
2660 Inset * in = par->inInset();
2661 // well we have to check if we are in an inset with unlimited
2662 // lenght (all in one row) if that is true then we don't allow
2663 // any special options in the paragraph and also we don't allow
2664 // any environment other then "Standard" to be valid!
2665 if ((in == 0) || !in->forceDefaultParagraphs(in)) {
2666 LyXLayout_ptr const & layout = par->layout();
2668 if (layout->intitle) {
2669 if (already_title) {
2670 lyxerr <<"Error in latexParagraphs: You"
2671 " should not mix title layouts"
2672 " with normal ones." << endl;
2675 } else if (was_title && !already_title) {
2676 ofs << "\\maketitle\n";
2678 already_title = true;
2682 if (layout->isEnvironment() ||
2683 !par->params().leftIndent().zero())
2685 par = par->TeXEnvironment(this, params, ofs, texrow);
2687 par = par->TeXOnePar(this, params, ofs, texrow, moving_arg);
2690 par = par->TeXOnePar(this, params, ofs, texrow, moving_arg);
2693 // It might be that we only have a title in this document
2694 if (was_title && !already_title) {
2695 ofs << "\\maketitle\n";
2701 bool Buffer::isLatex() const
2703 return params.getLyXTextClass().outputType() == LATEX;
2707 bool Buffer::isLinuxDoc() const
2709 return params.getLyXTextClass().outputType() == LINUXDOC;
2713 bool Buffer::isLiterate() const
2715 return params.getLyXTextClass().outputType() == LITERATE;
2719 bool Buffer::isDocBook() const
2721 return params.getLyXTextClass().outputType() == DOCBOOK;
2725 bool Buffer::isSGML() const
2727 LyXTextClass const & tclass = params.getLyXTextClass();
2729 return tclass.outputType() == LINUXDOC ||
2730 tclass.outputType() == DOCBOOK;
2734 int Buffer::sgmlOpenTag(ostream & os, Paragraph::depth_type depth, bool mixcont,
2735 string const & latexname) const
2737 if (!latexname.empty() && latexname != "!-- --") {
2739 os << string(" ",depth);
2740 os << "<" << latexname << ">";
2750 int Buffer::sgmlCloseTag(ostream & os, Paragraph::depth_type depth, bool mixcont,
2751 string const & latexname) const
2753 if (!latexname.empty() && latexname != "!-- --") {
2755 os << endl << string(" ",depth);
2756 os << "</" << latexname << ">";
2766 void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
2768 ofstream ofs(fname.c_str());
2771 Alert::alert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2775 niceFile = nice; // this will be used by included files.
2777 LaTeXFeatures features(params);
2783 LyXTextClass const & tclass = params.getLyXTextClass();
2785 string top_element = tclass.latexname();
2788 ofs << "<!doctype linuxdoc system";
2790 string preamble = params.preamble;
2791 const string name = nice ? ChangeExtension(filename_, ".sgml")
2793 preamble += features.getIncludedFiles(name);
2794 preamble += features.getLyXSGMLEntities();
2796 if (!preamble.empty()) {
2797 ofs << " [ " << preamble << " ]";
2801 if (params.options.empty())
2802 sgmlOpenTag(ofs, 0, false, top_element);
2804 string top = top_element;
2806 top += params.options;
2807 sgmlOpenTag(ofs, 0, false, top);
2811 ofs << "<!-- " << lyx_docversion
2812 << " created this file. For more info see http://www.lyx.org/"
2815 Paragraph::depth_type depth = 0; // paragraph depth
2816 Paragraph * par = paragraph;
2818 vector<string> environment_stack(5);
2821 LyXLayout_ptr const & style = par->layout();
2822 // treat <toc> as a special case for compatibility with old code
2823 if (par->isInset(0)) {
2824 Inset * inset = par->getInset(0);
2825 Inset::Code lyx_code = inset->lyxCode();
2826 if (lyx_code == Inset::TOC_CODE) {
2827 string const temp = "toc";
2828 sgmlOpenTag(ofs, depth, false, temp);
2835 // environment tag closing
2836 for (; depth > par->params().depth(); --depth) {
2837 sgmlCloseTag(ofs, depth, false, environment_stack[depth]);
2838 environment_stack[depth].erase();
2841 // write opening SGML tags
2842 switch (style->latextype) {
2843 case LATEX_PARAGRAPH:
2844 if (depth == par->params().depth()
2845 && !environment_stack[depth].empty()) {
2846 sgmlCloseTag(ofs, depth, false, environment_stack[depth]);
2847 environment_stack[depth].erase();
2853 sgmlOpenTag(ofs, depth, false, style->latexname());
2859 _("Error : Wrong depth for"
2860 " LatexType Command.\n"));
2862 if (!environment_stack[depth].empty()) {
2863 sgmlCloseTag(ofs, depth, false, environment_stack[depth]);
2867 environment_stack[depth].erase();
2868 sgmlOpenTag(ofs, depth, false, style->latexname());
2871 case LATEX_ENVIRONMENT:
2872 case LATEX_ITEM_ENVIRONMENT:
2874 string const & latexname = style->latexname();
2876 if (depth == par->params().depth()
2877 && environment_stack[depth] != latexname) {
2878 sgmlCloseTag(ofs, depth, false,
2879 environment_stack[depth]);
2880 environment_stack[depth].erase();
2882 if (depth < par->params().depth()) {
2883 depth = par->params().depth();
2884 environment_stack[depth].erase();
2886 if (environment_stack[depth] != latexname) {
2888 sgmlOpenTag(ofs, depth, false, "p");
2890 sgmlOpenTag(ofs, depth, false, latexname);
2892 if (environment_stack.size() == depth + 1)
2893 environment_stack.push_back("!-- --");
2894 environment_stack[depth] = latexname;
2897 if (style->latexparam() == "CDATA")
2900 if (style->latextype == LATEX_ENVIRONMENT) break;
2902 if (style->labeltype == LABEL_MANUAL)
2907 sgmlOpenTag(ofs, depth + 1, false, item_name);
2912 sgmlOpenTag(ofs, depth, false, style->latexname());
2916 simpleLinuxDocOnePar(ofs, par, depth);
2921 // write closing SGML tags
2922 switch (style->latextype) {
2925 case LATEX_ENVIRONMENT:
2926 case LATEX_ITEM_ENVIRONMENT:
2927 if (style->latexparam() == "CDATA")
2931 sgmlCloseTag(ofs, depth, false, style->latexname());
2937 for (int i = depth; i >= 0; --i)
2938 sgmlCloseTag(ofs, depth, false, environment_stack[i]);
2942 sgmlCloseTag(ofs, 0, false, top_element);
2946 // How to check for successful close
2948 // we want this to be true outside previews (for insetexternal)
2953 // checks, if newcol chars should be put into this line
2954 // writes newline, if necessary.
2957 void sgmlLineBreak(ostream & os, string::size_type & colcount,
2958 string::size_type newcol)
2961 if (colcount > lyxrc.ascii_linelen) {
2963 colcount = newcol; // assume write after this call
2978 string tag_name(PAR_TAG const & pt) {
2980 case NONE: return "!-- --";
2981 case TT: return "tt";
2982 case SF: return "sf";
2983 case BF: return "bf";
2984 case IT: return "it";
2985 case SL: return "sl";
2986 case EM: return "em";
2993 void operator|=(PAR_TAG & p1, PAR_TAG const & p2)
2995 p1 = static_cast<PAR_TAG>(p1 | p2);
3000 void reset(PAR_TAG & p1, PAR_TAG const & p2)
3002 p1 = static_cast<PAR_TAG>(p1 & ~p2);
3008 // Handle internal paragraph parsing -- layout already processed.
3009 void Buffer::simpleLinuxDocOnePar(ostream & os,
3011 Paragraph::depth_type /*depth*/)
3013 LyXLayout_ptr const & style = par->layout();
3015 string::size_type char_line_count = 5; // Heuristic choice ;-)
3017 // gets paragraph main font
3020 if (style->labeltype == LABEL_MANUAL) {
3021 font_old = style->labelfont;
3024 font_old = style->font;
3028 LyXFont::FONT_FAMILY family_type = LyXFont::ROMAN_FAMILY;
3029 LyXFont::FONT_SERIES series_type = LyXFont::MEDIUM_SERIES;
3030 LyXFont::FONT_SHAPE shape_type = LyXFont::UP_SHAPE;
3033 stack<PAR_TAG> tag_state;
3034 // parsing main loop
3035 for (pos_type i = 0; i < par->size(); ++i) {
3037 PAR_TAG tag_close = NONE;
3038 list < PAR_TAG > tag_open;
3040 LyXFont const font = par->getFont(params, i);
3042 if (font_old.family() != font.family()) {
3043 switch (family_type) {
3044 case LyXFont::SANS_FAMILY:
3047 case LyXFont::TYPEWRITER_FAMILY:
3054 family_type = font.family();
3056 switch (family_type) {
3057 case LyXFont::SANS_FAMILY:
3058 tag_open.push_back(SF);
3060 case LyXFont::TYPEWRITER_FAMILY:
3061 tag_open.push_back(TT);
3068 if (font_old.series() != font.series()) {
3069 switch (series_type) {
3070 case LyXFont::BOLD_SERIES:
3077 series_type = font.series();
3079 switch (series_type) {
3080 case LyXFont::BOLD_SERIES:
3081 tag_open.push_back(BF);
3089 if (font_old.shape() != font.shape()) {
3090 switch (shape_type) {
3091 case LyXFont::ITALIC_SHAPE:
3094 case LyXFont::SLANTED_SHAPE:
3101 shape_type = font.shape();
3103 switch (shape_type) {
3104 case LyXFont::ITALIC_SHAPE:
3105 tag_open.push_back(IT);
3107 case LyXFont::SLANTED_SHAPE:
3108 tag_open.push_back(SL);
3115 if (font_old.emph() != font.emph()) {
3116 if (font.emph() == LyXFont::ON) {
3117 tag_open.push_back(EM);
3126 list < PAR_TAG > temp;
3127 while (!tag_state.empty() && tag_close) {
3128 PAR_TAG k = tag_state.top();
3130 os << "</" << tag_name(k) << ">";
3137 for(list< PAR_TAG >::const_iterator j = temp.begin();
3138 j != temp.end(); ++j) {
3140 os << "<" << tag_name(*j) << ">";
3143 for(list< PAR_TAG >::const_iterator j = tag_open.begin();
3144 j != tag_open.end(); ++j) {
3146 os << "<" << tag_name(*j) << ">";
3149 char c = par->getChar(i);
3151 if (c == Paragraph::META_INSET) {
3152 Inset * inset = par->getInset(i);
3153 inset->linuxdoc(this, os);
3158 if (style->latexparam() == "CDATA") {
3159 // "TeX"-Mode on == > SGML-Mode on.
3165 if (par->sgmlConvertChar(c, sgml_string)
3166 && !style->free_spacing && !par->isFreeSpacing())
3168 // in freespacing mode, spaces are
3169 // non-breaking characters
3170 if (desc_on) {// if char is ' ' then...
3173 sgmlLineBreak(os, char_line_count, 6);
3177 sgmlLineBreak(os, char_line_count, 1);
3182 char_line_count += sgml_string.length();
3188 while (!tag_state.empty()) {
3189 os << "</" << tag_name(tag_state.top()) << ">";
3193 // resets description flag correctly
3195 // <tag> not closed...
3196 sgmlLineBreak(os, char_line_count, 6);
3202 // Print an error message.
3203 void Buffer::sgmlError(Paragraph * /*par*/, int /*pos*/,
3204 string const & /*message*/) const
3206 #ifdef WITH_WARNINGS
3207 #warning This is wrong we cannot insert an inset like this!!!
3208 // I guess this was Jose' so I explain you more or less why this
3209 // is wrong. This way you insert something in the paragraph and
3210 // don't tell it to LyXText (row rebreaking and undo handling!!!)
3211 // I deactivate this code, have a look at BufferView::insertErrors
3212 // how you should do this correctly! (Jug 20020315)
3215 // insert an error marker in text
3216 InsetError * new_inset = new InsetError(message);
3217 par->insertInset(pos, new_inset, LyXFont(LyXFont::ALL_INHERIT,
3223 void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
3225 ofstream ofs(fname.c_str());
3227 Alert::alert(_("LYX_ERROR:"), _("Cannot write file"), fname);
3231 Paragraph * par = paragraph;
3233 niceFile = nice; // this will be used by Insetincludes.
3235 LaTeXFeatures features(params);
3240 LyXTextClass const & tclass = params.getLyXTextClass();
3241 string top_element = tclass.latexname();
3244 ofs << "<!DOCTYPE " << top_element
3245 << " PUBLIC \"-//OASIS//DTD DocBook V4.1//EN\"";
3247 string preamble = params.preamble;
3248 const string name = nice ? ChangeExtension(filename_, ".sgml")
3250 preamble += features.getIncludedFiles(name);
3251 preamble += features.getLyXSGMLEntities();
3253 if (!preamble.empty()) {
3254 ofs << "\n [ " << preamble << " ]";
3259 string top = top_element;
3261 top += params.language->code();
3264 if (!params.options.empty()) {
3266 top += params.options;
3268 sgmlOpenTag(ofs, 0, false, top);
3270 ofs << "<!-- DocBook file was created by " << lyx_docversion
3271 << "\n See http://www.lyx.org/ for more information -->\n";
3273 vector<string> environment_stack(10);
3274 vector<string> environment_inner(10);
3275 vector<string> command_stack(10);
3277 bool command_flag = false;
3278 Paragraph::depth_type command_depth = 0;
3279 Paragraph::depth_type command_base = 0;
3280 Paragraph::depth_type cmd_depth = 0;
3281 Paragraph::depth_type depth = 0; // paragraph depth
3284 string command_name;
3290 int desc_on = 0; // description mode
3292 LyXLayout_ptr const & style = par->layout();
3294 // environment tag closing
3295 for (; depth > par->params().depth(); --depth) {
3296 if (environment_inner[depth] != "!-- --") {
3297 item_name = "listitem";
3298 sgmlCloseTag(ofs, command_depth + depth, false, item_name);
3299 if (environment_inner[depth] == "varlistentry")
3300 sgmlCloseTag(ofs, depth+command_depth, false, environment_inner[depth]);
3302 sgmlCloseTag(ofs, depth + command_depth, false, environment_stack[depth]);
3303 environment_stack[depth].erase();
3304 environment_inner[depth].erase();
3307 if (depth == par->params().depth()
3308 && environment_stack[depth] != style->latexname()
3309 && !environment_stack[depth].empty()) {
3310 if (environment_inner[depth] != "!-- --") {
3311 item_name= "listitem";
3312 sgmlCloseTag(ofs, command_depth+depth, false, item_name);
3313 if (environment_inner[depth] == "varlistentry")
3314 sgmlCloseTag(ofs, depth + command_depth, false, environment_inner[depth]);
3317 sgmlCloseTag(ofs, depth + command_depth, false, environment_stack[depth]);
3319 environment_stack[depth].erase();
3320 environment_inner[depth].erase();
3323 // Write opening SGML tags.
3324 switch (style->latextype) {
3325 case LATEX_PARAGRAPH:
3326 sgmlOpenTag(ofs, depth + command_depth,
3327 false, style->latexname());
3333 _("Error : Wrong depth for "
3334 "LatexType Command.\n"));
3336 command_name = style->latexname();
3338 sgmlparam = style->latexparam();
3339 c_params = split(sgmlparam, c_depth,'|');
3341 cmd_depth = lyx::atoi(c_depth);
3344 if (cmd_depth < command_base) {
3345 for (Paragraph::depth_type j = command_depth;
3346 j >= command_base; --j) {
3347 sgmlCloseTag(ofs, j, false, command_stack[j]);
3350 command_depth = command_base = cmd_depth;
3351 } else if (cmd_depth <= command_depth) {
3352 for (int j = command_depth;
3353 j >= int(cmd_depth); --j) {
3354 sgmlCloseTag(ofs, j, false, command_stack[j]);
3357 command_depth = cmd_depth;
3359 command_depth = cmd_depth;
3361 command_depth = command_base = cmd_depth;
3362 command_flag = true;
3364 if (command_stack.size() == command_depth + 1)
3365 command_stack.push_back(string());
3366 command_stack[command_depth] = command_name;
3368 // treat label as a special case for
3369 // more WYSIWYM handling.
3370 // This is a hack while paragraphs can't have
3371 // attributes, like id in this case.
3372 if (par->isInset(0)) {
3373 Inset * inset = par->getInset(0);
3374 Inset::Code lyx_code = inset->lyxCode();
3375 if (lyx_code == Inset::LABEL_CODE) {
3376 command_name += " id=\"";
3377 command_name += (static_cast<InsetCommand *>(inset))->getContents();
3378 command_name += "\"";
3383 sgmlOpenTag(ofs, depth + command_depth, false, command_name);
3385 item_name = c_params.empty()?"title":c_params;
3386 sgmlOpenTag(ofs, depth + 1 + command_depth, false, item_name);
3389 case LATEX_ENVIRONMENT:
3390 case LATEX_ITEM_ENVIRONMENT:
3391 if (depth < par->params().depth()) {
3392 depth = par->params().depth();
3393 environment_stack[depth].erase();
3396 if (environment_stack[depth] != style->latexname()) {
3397 if (environment_stack.size() == depth + 1) {
3398 environment_stack.push_back("!-- --");
3399 environment_inner.push_back("!-- --");
3401 environment_stack[depth] = style->latexname();
3402 environment_inner[depth] = "!-- --";
3403 sgmlOpenTag(ofs, depth + command_depth, false, environment_stack[depth]);
3405 if (environment_inner[depth] != "!-- --") {
3406 item_name= "listitem";
3407 sgmlCloseTag(ofs, command_depth + depth, false, item_name);
3408 if (environment_inner[depth] == "varlistentry")
3409 sgmlCloseTag(ofs, depth + command_depth, false, environment_inner[depth]);
3413 if (style->latextype == LATEX_ENVIRONMENT) {
3414 if (!style->latexparam().empty()) {
3415 if (style->latexparam() == "CDATA")
3418 sgmlOpenTag(ofs, depth + command_depth, false, style->latexparam());
3423 desc_on = (style->labeltype == LABEL_MANUAL);
3425 environment_inner[depth] = desc_on ? "varlistentry" : "listitem";
3426 sgmlOpenTag(ofs, depth + 1 + command_depth,
3427 false, environment_inner[depth]);
3429 item_name = desc_on ? "term" : "para";
3430 sgmlOpenTag(ofs, depth + 1 + command_depth,
3434 sgmlOpenTag(ofs, depth + command_depth,
3435 false, style->latexname());
3439 simpleDocBookOnePar(ofs, par, desc_on,
3440 depth + 1 + command_depth);
3444 // write closing SGML tags
3445 switch (style->latextype) {
3447 end_tag = c_params.empty() ? "title" : c_params;
3448 sgmlCloseTag(ofs, depth + command_depth,
3451 case LATEX_ENVIRONMENT:
3452 if (!style->latexparam().empty()) {
3453 if (style->latexparam() == "CDATA")
3456 sgmlCloseTag(ofs, depth + command_depth, false, style->latexparam());
3459 case LATEX_ITEM_ENVIRONMENT:
3460 if (desc_on == 1) break;
3462 sgmlCloseTag(ofs, depth + 1 + command_depth, false, end_tag);
3464 case LATEX_PARAGRAPH:
3465 sgmlCloseTag(ofs, depth + command_depth, false, style->latexname());
3468 sgmlCloseTag(ofs, depth + command_depth, false, style->latexname());
3474 for (int d = depth; d >= 0; --d) {
3475 if (!environment_stack[depth].empty()) {
3476 if (environment_inner[depth] != "!-- --") {
3477 item_name = "listitem";
3478 sgmlCloseTag(ofs, command_depth + depth, false, item_name);
3479 if (environment_inner[depth] == "varlistentry")
3480 sgmlCloseTag(ofs, depth + command_depth, false, environment_inner[depth]);
3483 sgmlCloseTag(ofs, depth + command_depth, false, environment_stack[depth]);
3487 for (int j = command_depth; j >= 0 ; --j)
3488 if (!command_stack[j].empty()) {
3489 sgmlCloseTag(ofs, j, false, command_stack[j]);
3494 sgmlCloseTag(ofs, 0, false, top_element);
3497 // How to check for successful close
3499 // we want this to be true outside previews (for insetexternal)
3504 void Buffer::simpleDocBookOnePar(ostream & os,
3505 Paragraph * par, int & desc_on,
3506 Paragraph::depth_type depth) const
3508 bool emph_flag = false;
3510 LyXLayout_ptr const & style = par->layout();
3512 LyXFont font_old = (style->labeltype == LABEL_MANUAL ? style->labelfont : style->font);
3514 int char_line_count = depth;
3515 //if (!style.free_spacing)
3516 // os << string(depth,' ');
3518 // parsing main loop
3519 for (pos_type i = 0; i < par->size(); ++i) {
3520 LyXFont font = par->getFont(params, i);
3522 // handle <emphasis> tag
3523 if (font_old.emph() != font.emph()) {
3524 if (font.emph() == LyXFont::ON) {
3525 if (style->latexparam() == "CDATA")
3528 if (style->latexparam() == "CDATA")
3532 if (style->latexparam() == "CDATA")
3534 os << "</emphasis>";
3535 if (style->latexparam() == "CDATA")
3542 if (par->isInset(i)) {
3543 Inset * inset = par->getInset(i);
3544 // don't print the inset in position 0 if desc_on == 3 (label)
3545 if (i || desc_on != 3) {
3546 if (style->latexparam() == "CDATA")
3548 inset->docbook(this, os, false);
3549 if (style->latexparam() == "CDATA")
3553 char c = par->getChar(i);
3555 par->sgmlConvertChar(c, sgml_string);
3557 if (style->pass_thru) {
3559 } else if (style->free_spacing || par->isFreeSpacing() || c != ' ') {
3561 } else if (desc_on ==1) {
3563 os << "\n</term><listitem><para>";
3573 if (style->latexparam() == "CDATA")
3575 os << "</emphasis>";
3576 if (style->latexparam() == "CDATA")
3580 // resets description flag correctly
3582 // <term> not closed...
3583 os << "</term>\n<listitem><para> </para>";
3585 if (style->free_spacing)
3590 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
3591 // Other flags: -wall -v0 -x
3592 int Buffer::runChktex()
3594 if (!users->text) return 0;
3596 users->owner()->prohibitInput();
3598 // get LaTeX-Filename
3599 string const name = getLatexName();
3600 string path = filePath();
3602 string const org_path = path;
3603 if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
3607 Path p(path); // path to LaTeX file
3608 users->owner()->message(_("Running chktex..."));
3610 // Remove all error insets
3611 bool const removedErrorInsets = users->removeAutoInsets();
3613 // Generate the LaTeX file if neccessary
3614 makeLaTeXFile(name, org_path, false);
3617 Chktex chktex(lyxrc.chktex_command, name, filePath());
3618 int res = chktex.run(terr); // run chktex
3621 Alert::alert(_("chktex did not work!"),
3622 _("Could not run with file:"), name);
3623 } else if (res > 0) {
3624 // Insert all errors as errors boxes
3625 users->insertErrors(terr);
3628 // if we removed error insets before we ran chktex or if we inserted
3629 // error insets after we ran chktex, this must be run:
3630 if (removedErrorInsets || res) {
3631 #warning repaint needed here, or do you mean update() ?
3635 users->owner()->allowInput();
3641 void Buffer::validate(LaTeXFeatures & features) const
3643 Paragraph * par = paragraph;
3644 LyXTextClass const & tclass = params.getLyXTextClass();
3646 // AMS Style is at document level
3647 if (params.use_amsmath || tclass.provides(LyXTextClass::amsmath))
3648 features.require("amsmath");
3651 // We don't use "lyxerr.debug" because of speed. (Asger)
3652 if (lyxerr.debugging(Debug::LATEX))
3653 lyxerr << "Paragraph: " << par << endl;
3655 // Now just follow the list of paragraphs and run
3656 // validate on each of them.
3657 par->validate(features);
3659 // and then the next paragraph
3663 // the bullet shapes are buffer level not paragraph level
3664 // so they are tested here
3665 for (int i = 0; i < 4; ++i) {
3666 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
3667 int const font = params.user_defined_bullets[i].getFont();
3669 int const c = params
3670 .user_defined_bullets[i]
3677 features.require("latexsym");
3679 } else if (font == 1) {
3680 features.require("amssymb");
3681 } else if ((font >= 2 && font <= 5)) {
3682 features.require("pifont");
3687 if (lyxerr.debugging(Debug::LATEX)) {
3688 features.showStruct();
3693 // This function should be in Buffer because it's a buffer's property (ale)
3694 string const Buffer::getIncludeonlyList(char delim)
3697 for (inset_iterator it = inset_iterator_begin();
3698 it != inset_iterator_end(); ++it) {
3699 if ((*it)->lyxCode() == Inset::INCLUDE_CODE) {
3700 InsetInclude * insetinc =
3701 static_cast<InsetInclude *>(*it);
3702 if (insetinc->isIncludeOnly()) {
3705 lst += insetinc->getRelFileBaseName();
3709 lyxerr[Debug::INFO] << "Includeonly(" << lst << ')' << endl;
3714 vector<string> const Buffer::getLabelList()
3716 /// if this is a child document and the parent is already loaded
3717 /// Use the parent's list instead [ale990407]
3718 if (!params.parentname.empty()
3719 && bufferlist.exists(params.parentname)) {
3720 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3722 return tmp->getLabelList();
3725 vector<string> label_list;
3726 for (inset_iterator it = inset_iterator_begin();
3727 it != inset_iterator_end(); ++it) {
3728 vector<string> const l = (*it)->getLabelList();
3729 label_list.insert(label_list.end(), l.begin(), l.end());
3735 // This is also a buffer property (ale)
3736 vector<pair<string, string> > const Buffer::getBibkeyList() const
3738 typedef pair<string, string> StringPair;
3739 /// if this is a child document and the parent is already loaded
3740 /// Use the parent's list instead [ale990412]
3741 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3742 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
3744 return tmp->getBibkeyList();
3747 vector<StringPair> keys;
3748 Paragraph * par = paragraph;
3751 string const key = par->bibkey->getContents();
3752 string const opt = par->bibkey->getOptions();
3753 string const ref = par->asString(this, false);
3754 string const info = opt + "TheBibliographyRef" + ref;
3756 keys.push_back(StringPair(key, info));
3761 // Might be either using bibtex or a child has bibliography
3763 for (inset_iterator it = inset_const_iterator_begin();
3764 it != inset_const_iterator_end(); ++it) {
3765 // Search for Bibtex or Include inset
3766 if ((*it)->lyxCode() == Inset::BIBTEX_CODE) {
3767 vector<StringPair> tmp =
3768 static_cast<InsetBibtex*>(*it)->getKeys(this);
3769 keys.insert(keys.end(), tmp.begin(), tmp.end());
3770 } else if ((*it)->lyxCode() == Inset::INCLUDE_CODE) {
3771 vector<StringPair> const tmp =
3772 static_cast<InsetInclude*>(*it)->getKeys();
3773 keys.insert(keys.end(), tmp.begin(), tmp.end());
3782 bool Buffer::isDepClean(string const & name) const
3784 DEPCLEAN * item = dep_clean;
3785 while (item && item->master != name)
3787 if (!item) return true;
3792 void Buffer::markDepClean(string const & name)
3795 dep_clean = new DEPCLEAN;
3796 dep_clean->clean = true;
3797 dep_clean->master = name;
3798 dep_clean->next = 0;
3800 DEPCLEAN * item = dep_clean;
3801 while (item && item->master != name)
3806 item = new DEPCLEAN;
3808 item->master = name;
3815 bool Buffer::dispatch(string const & command, bool * result)
3817 // Split command string into command and argument
3819 string line = ltrim(command);
3820 string const arg = trim(split(line, cmd, ' '));
3822 return dispatch(lyxaction.LookupFunc(cmd), arg, result);
3826 bool Buffer::dispatch(int action, string const & argument, bool * result)
3828 bool dispatched = true;
3832 bool const tmp = Exporter::Export(this, argument, false);
3845 void Buffer::resizeInsets(BufferView * bv)
3847 /// then remove all LyXText in text-insets
3848 Paragraph * par = paragraph;
3849 for (; par; par = par->next()) {
3850 par->resizeInsetsLyXText(bv);
3855 void Buffer::redraw()
3857 #warning repaint needed here, or do you mean update() ?
3863 void Buffer::changeLanguage(Language const * from, Language const * to)
3866 ParIterator end = par_iterator_end();
3867 for (ParIterator it = par_iterator_begin(); it != end; ++it)
3868 (*it)->changeLanguage(params, from, to);
3872 bool Buffer::isMultiLingual()
3874 ParIterator end = par_iterator_end();
3875 for (ParIterator it = par_iterator_begin(); it != end; ++it)
3876 if ((*it)->isMultiLingual(params))
3883 Buffer::inset_iterator::inset_iterator(Paragraph * paragraph, pos_type pos)
3886 it = par->InsetIterator(pos);
3887 if (it == par->inset_iterator_end()) {
3894 void Buffer::inset_iterator::setParagraph()
3897 it = par->inset_iterator_begin();
3898 if (it != par->inset_iterator_end())
3903 // We maintain an invariant that whenever par = 0 then it = 0
3907 Inset * Buffer::getInsetFromID(int id_arg) const
3909 for (inset_iterator it = inset_const_iterator_begin();
3910 it != inset_const_iterator_end(); ++it)
3912 if ((*it)->id() == id_arg)
3914 Inset * in = (*it)->getInsetFromID(id_arg);
3922 Paragraph * Buffer::getParFromID(int id) const
3924 if (id < 0) return 0;
3925 Paragraph * par = paragraph;
3927 if (par->id() == id) {
3930 Paragraph * tmp = par->getParFromID(id);
3940 ParIterator Buffer::par_iterator_begin()
3942 return ParIterator(paragraph);
3946 ParIterator Buffer::par_iterator_end()
3948 return ParIterator();