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"
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>
110 #include <boost/tuple/tuple.hpp>
116 #ifndef CXX_GLOBAL_CSTD
128 using std::make_pair;
137 using lyx::textclass_type;
139 // all these externs should eventually be removed.
140 extern BufferList bufferlist;
144 const int LYX_FORMAT = 220;
148 Buffer::Buffer(string const & file, bool ronly)
149 : niceFile(true), lyx_clean(true), bak_clean(true),
150 unnamed(false), dep_clean(0), read_only(ronly),
151 filename_(file), users(0)
153 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
155 filepath_ = OnlyPath(file);
159 // read_only = ronly;
163 if (read_only || lyxrc.use_tempdir) {
164 tmppath = CreateBufferTmpDir();
173 lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
174 // here the buffer should take care that it is
175 // saved properly, before it goes into the void.
177 // make sure that views using this buffer
182 if (!tmppath.empty()) {
183 DestroyBufferTmpDir(tmppath);
188 // Remove any previewed LaTeX snippets assocoated with this buffer.
189 grfx::Previews::get().removeLoader(this);
193 string const Buffer::getLatexName(bool no_path) const
195 string const name = ChangeExtension(MakeLatexName(fileName()), ".tex");
197 return OnlyFilename(name);
203 pair<Buffer::LogType, string> const Buffer::getLogName(void) const
205 string const filename = getLatexName(false);
207 if (filename.empty())
208 return make_pair(Buffer::latexlog, string());
210 string path = OnlyPath(filename);
212 if (lyxrc.use_tempdir || !IsDirWriteable(path))
215 string const fname = AddName(path,
216 OnlyFilename(ChangeExtension(filename,
219 AddName(path, OnlyFilename(
220 ChangeExtension(filename,
221 formats.extension("literate") + ".out")));
223 // If no Latex log or Build log is newer, show Build log
225 FileInfo const f_fi(fname);
226 FileInfo const b_fi(bname);
229 (!f_fi.exist() || f_fi.getModificationTime() < b_fi.getModificationTime())) {
230 lyxerr[Debug::FILES] << "Log name calculated as : " << bname << endl;
231 return make_pair(Buffer::buildlog, bname);
233 lyxerr[Debug::FILES] << "Log name calculated as : " << fname << endl;
234 return make_pair(Buffer::latexlog, fname);
238 void Buffer::setReadonly(bool flag)
240 if (read_only != flag) {
243 users->owner()->getDialogs()->updateBufferDependent(false);
248 /// Update window titles of all users
249 // Should work on a list
250 void Buffer::updateTitles() const
253 users->owner()->updateWindowTitle();
257 /// Reset autosave timer of all users
258 // Should work on a list
259 void Buffer::resetAutosaveTimers() const
262 users->owner()->resetAutosaveTimer();
266 void Buffer::setFileName(string const & newfile)
268 filename_ = MakeAbsPath(newfile);
269 filepath_ = OnlyPath(filename_);
270 setReadonly(IsFileWriteable(filename_) == 0);
275 // We'll remove this later. (Lgb)
278 string last_inset_read;
280 #ifndef NO_COMPABILITY
283 ErtComp() : active(false), fromlayout(false), in_tabular(false) {
292 std::stack<ErtComp> ert_stack;
297 #warning And _why_ is this here? (Lgb)
305 // candidate for move to BufferView
306 // (at least some parts in the beginning of the func)
309 // changed to be public and have one parameter
310 // if par = 0 normal behavior
311 // else insert behavior
312 // Returns false if "\the_end" is not read for formats >= 2.13. (Asger)
313 bool Buffer::readLyXformat2(LyXLex & lex, Paragraph * par)
317 #ifndef NO_COMPABILITY
318 ert_comp.contents.erase();
319 ert_comp.active = false;
320 ert_comp.fromlayout = false;
321 ert_comp.in_tabular = false;
324 Paragraph::depth_type depth = 0;
325 bool the_end_read = false;
327 Paragraph * first_par = 0;
328 LyXFont font(LyXFont::ALL_INHERIT, params.language);
331 if (file_format < 216 && params.language->lang() == "hebrew")
332 font.setLanguage(default_language);
337 par->layout(params.getLyXTextClass().defaultLayout());
339 // We are inserting into an existing document
340 users->text->breakParagraph(users);
341 first_par = users->text->ownerParagraph();
344 // We don't want to adopt the parameters from the
345 // document we insert, so we skip until the text begins:
348 string const pretoken = lex.getString();
349 if (pretoken == "\\layout") {
350 lex.pushToken(pretoken);
358 string const token = lex.getString();
360 if (token.empty()) continue;
362 lyxerr[Debug::PARSER] << "Handling token: `"
363 << token << "'" << endl;
366 parseSingleLyXformat2Token(lex, par, first_par,
374 paragraphs.set(first_par);
376 if (unknown_layouts > 0) {
377 string s = _("Couldn't set the layout for ");
378 if (unknown_layouts == 1) {
379 s += _("one paragraph");
381 s += tostr(unknown_layouts);
382 s += _(" paragraphs");
384 Alert::alert(_("Textclass Loading Error!"), s,
385 _("When reading " + fileName()));
388 if (unknown_tokens > 0) {
389 string s = _("Encountered ");
390 if (unknown_tokens == 1) {
391 s += _("one unknown token");
393 s += tostr(unknown_tokens);
394 s += _(" unknown tokens");
396 Alert::alert(_("Textclass Loading Error!"), s,
397 _("When reading " + fileName()));
404 #ifndef NO_COMPABILITY
406 Inset * Buffer::isErtInset(Paragraph * par, int pos) const
409 if ((par->getChar(pos) == Paragraph::META_INSET) &&
410 (inset = par->getInset(pos)) &&
411 (inset->lyxCode() == Inset::ERT_CODE))
418 void Buffer::insertErtContents(Paragraph * par, int & pos, bool set_inactive)
420 if (ert_comp.contents.find_first_not_of(' ') != string::npos) {
421 // we only skip completely empty ERT (only spaces) otherwise
422 // we have to insert it as is.
423 string str(ert_comp.contents);
424 lyxerr[Debug::INSETS] << "ERT contents:\n'"
425 << str << "'" << endl;
426 // check if we have already an ert inset a position earlier
427 // if this is the case then we should insert the contents
428 // inside the other ertinset as it is stupid to have various
431 if ((pos > 0) && (inset=isErtInset(par, pos-1))) {
432 // get the last paragraph from the inset before
433 Paragraph * last = inset->firstParagraph();
436 // create the new paragraph after the last one
437 Paragraph * par = new Paragraph(last);
438 par->layout(params.getLyXTextClass().defaultLayoutName());
439 par->setInsetOwner(last->inInset());
441 LyXFont font(LyXFont::ALL_INHERIT, params.language);
442 string::const_iterator cit = str.begin();
443 string::const_iterator end = str.end();
445 for (; cit != end; ++cit) {
446 par->insertChar(pos++, *cit, font);
450 new InsetERT(params, params.language, str, true);
451 par->insertInset(pos++, inset, ert_comp.font);
454 ert_comp.contents.erase();
455 ert_comp.fromlayout = false;
457 ert_comp.active = false;
464 Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
465 Paragraph *& first_par,
466 string const & token, int & pos,
467 Paragraph::depth_type & depth,
471 bool the_end_read = false;
472 #ifndef NO_COMPABILITY
473 #ifndef NO_PEXTRA_REALLY
474 // This is super temporary but is needed to get the compability
475 // mode for minipages work correctly together with new tabulars.
476 static int call_depth;
478 bool checkminipage = false;
479 static Paragraph * minipar = 0;
480 static Paragraph * parBeforeMinipage;
484 // The order of the tags tested may seem unnatural, but this
485 // has been done in order to reduce the number of string
486 // comparisons needed to recognize a given token. This leads
487 // on large documents like UserGuide to a reduction of a
489 if (token[0] != '\\') {
490 #ifndef NO_COMPABILITY
491 if (ert_comp.active) {
492 ert_comp.contents += token;
495 for (string::const_iterator cit = token.begin();
496 cit != token.end(); ++cit) {
497 par->insertChar(pos, (*cit), font);
500 #ifndef NO_COMPABILITY
503 } else if (token == "\\layout") {
504 #ifndef NO_COMPABILITY
505 bool old_fromlayout = ert_comp.fromlayout;
506 bool create_new_par = true;
507 ert_comp.in_tabular = false;
509 if (!par->size() && par->previous() &&
510 (par->previous()->size() == 1) &&
511 isErtInset(par->previous(), par->previous()->size()-1))
513 int p = par->previous()->size();
514 insertErtContents(par->previous(), p);
515 create_new_par = false;
517 insertErtContents(par, pos);
520 // reset the font as we start a new layout and if the font is
521 // not ALL_INHERIT,document_language then it will be set to the
522 // right values after this tag (Jug 20020420)
523 font = LyXFont(LyXFont::ALL_INHERIT, params.language);
526 if (file_format < 216 && params.language->lang() == "hebrew")
527 font.setLanguage(default_language);
531 string layoutname = lex.getString();
533 LyXTextClass const & tclass = params.getLyXTextClass();
535 if (layoutname.empty()) {
536 layoutname = tclass.defaultLayoutName();
538 #ifndef NO_COMPABILITY
539 if (compare_ascii_no_case(layoutname, "latex") == 0) {
540 ert_comp.active = true;
541 ert_comp.fromlayout = true;
542 ert_comp.font = font;
544 create_new_par = false;
547 bool hasLayout = tclass.hasLayout(layoutname);
549 lyxerr << "Layout '" << layoutname << "' does not"
550 << " exist in textclass '" << tclass.name()
552 lyxerr << "Trying to use default layout instead."
554 layoutname = tclass.defaultLayoutName();
558 // The is the compability reading of layout caption.
559 // It can be removed in LyX version 1.3.0. (Lgb)
560 if (compare_ascii_no_case(layoutname, "caption") == 0) {
561 // We expect that the par we are now working on is
562 // really inside a InsetText inside a InsetFloat.
563 // We also know that captions can only be
564 // one paragraph. (Lgb)
566 // We should now read until the next "\layout"
568 // This is probably not good enough, what if the
569 // caption is the last par in the document (Lgb)
570 istream & ist = lex.getStream();
576 if (prefixIs(line, "\\layout")) {
580 if (prefixIs(line, "\\begin_inset"))
582 if (prefixIs(line, "\\end_inset")) {
593 // Now we should have the whole layout in ss
594 // we should now be able to give this to the
596 ss << "\\end_inset\n";
598 // This seems like a bug in stringstream.
599 // We really should be able to use ss
601 istringstream is(ss.str());
603 tmplex.setStream(is);
604 Inset * inset = new InsetCaption;
605 inset->Read(this, tmplex);
606 par->InsertInset(pos, inset, font);
610 #ifndef NO_COMPABILITY
611 if (create_new_par) {
616 par = new Paragraph(par);
617 par->layout(params.getLyXTextClass().defaultLayout());
620 par->layout(params.getLyXTextClass()[layoutname]);
621 // Test whether the layout is obsolete.
622 LyXLayout_ptr const & layout = par->layout();
623 if (!layout->obsoleted_by().empty())
624 par->layout(params.getLyXTextClass()[layout->obsoleted_by()]);
625 par->params().depth(depth);
626 #ifndef NO_COMPABILITY
628 // we duplicate code here because it's easier to remove
629 // the code then of NO_COMPATIBILITY
630 par->layout(layoutname);
631 // Test whether the layout is obsolete.
632 LyXLayout_ptr const & layout =
633 params.getLyXTextClass()[par->layout()];
634 if (!layout->obsoleted_by().empty())
635 par->layout(layout->obsoleted_by());
636 par->params().depth(depth);
643 } else if (token == "\\end_inset") {
644 lyxerr << "Solitary \\end_inset. Missing \\begin_inset?.\n"
645 << "Last inset read was: " << last_inset_read
647 // Simply ignore this. The insets do not have
649 // But insets should read it, it is a part of
650 // the inset isn't it? Lgb.
651 } else if (token == "\\begin_inset") {
652 #ifndef NO_COMPABILITY
653 insertErtContents(par, pos, false);
654 ert_stack.push(ert_comp);
655 ert_comp = ErtComp();
657 readInset(lex, par, pos, font);
658 #ifndef NO_COMPABILITY
659 ert_comp = ert_stack.top();
661 insertErtContents(par, pos);
663 } else if (token == "\\family") {
665 font.setLyXFamily(lex.getString());
666 } else if (token == "\\series") {
668 font.setLyXSeries(lex.getString());
669 } else if (token == "\\shape") {
671 font.setLyXShape(lex.getString());
672 } else if (token == "\\size") {
674 font.setLyXSize(lex.getString());
675 #ifndef NO_COMPABILITY
676 } else if (token == "\\latex") {
678 string const tok = lex.getString();
679 if (tok == "no_latex") {
681 insertErtContents(par, pos);
682 } else if (tok == "latex") {
683 ert_comp.active = true;
684 ert_comp.font = font;
685 } else if (tok == "default") {
687 insertErtContents(par, pos);
689 lex.printError("Unknown LaTeX font flag "
693 } else if (token == "\\lang") {
695 string const tok = lex.getString();
696 Language const * lang = languages.getLanguage(tok);
698 font.setLanguage(lang);
700 font.setLanguage(params.language);
701 lex.printError("Unknown language `$$Token'");
703 } else if (token == "\\numeric") {
705 font.setNumber(font.setLyXMisc(lex.getString()));
706 } else if (token == "\\emph") {
708 font.setEmph(font.setLyXMisc(lex.getString()));
709 } else if (token == "\\bar") {
711 string const tok = lex.getString();
712 // This is dirty, but gone with LyX3. (Asger)
714 font.setUnderbar(LyXFont::ON);
715 else if (tok == "no")
716 font.setUnderbar(LyXFont::OFF);
717 else if (tok == "default")
718 font.setUnderbar(LyXFont::INHERIT);
720 lex.printError("Unknown bar font flag "
722 } else if (token == "\\noun") {
724 font.setNoun(font.setLyXMisc(lex.getString()));
725 } else if (token == "\\color") {
727 font.setLyXColor(lex.getString());
728 } else if (token == "\\SpecialChar") {
729 LyXLayout_ptr const & layout = par->layout();
731 // Insets don't make sense in a free-spacing context! ---Kayvan
732 if (layout->free_spacing || par->isFreeSpacing()) {
735 string next_token = lex.getString();
736 if (next_token == "\\-") {
737 par->insertChar(pos, '-', font);
738 } else if (next_token == "\\protected_separator"
739 || next_token == "~") {
740 par->insertChar(pos, ' ', font);
742 lex.printError("Token `$$Token' "
744 "paragraph layout!");
749 Inset * inset = new InsetSpecialChar;
750 inset->read(this, lex);
751 par->insertInset(pos, inset, font);
754 } else if (token == "\\i") {
755 Inset * inset = new InsetLatexAccent;
756 inset->read(this, lex);
757 par->insertInset(pos, inset, font);
759 } else if (token == "\\backslash") {
760 #ifndef NO_COMPABILITY
761 if (ert_comp.active) {
762 ert_comp.contents += "\\";
765 par->insertChar(pos, '\\', font);
767 #ifndef NO_COMPABILITY
770 #ifndef NO_COMPABILITY
771 } else if (token == "\\begin_float") {
772 insertErtContents(par, pos);
773 //insertErtContents(par, pos, false);
774 //ert_stack.push(ert_comp);
775 //ert_comp = ErtComp();
777 // This is the compability reader. It can be removed in
778 // LyX version 1.3.0. (Lgb)
780 string const tmptok = lex.getString();
781 //lyxerr << "old float: " << tmptok << endl;
784 stringstream old_float;
786 if (tmptok == "footnote") {
787 inset = new InsetFoot(params);
788 old_float << "collapsed true\n";
789 } else if (tmptok == "margin") {
790 inset = new InsetMarginal(params);
791 old_float << "collapsed true\n";
792 } else if (tmptok == "fig") {
793 inset = new InsetFloat(params, "figure");
794 old_float << "wide false\n"
795 << "collapsed false\n";
796 } else if (tmptok == "tab") {
797 inset = new InsetFloat(params, "table");
798 old_float << "wide false\n"
799 << "collapsed false\n";
800 } else if (tmptok == "alg") {
801 inset = new InsetFloat(params, "algorithm");
802 old_float << "wide false\n"
803 << "collapsed false\n";
804 } else if (tmptok == "wide-fig") {
805 inset = new InsetFloat(params, "figure");
806 //InsetFloat * tmp = new InsetFloat("figure");
809 old_float << "wide true\n"
810 << "collapsed false\n";
811 } else if (tmptok == "wide-tab") {
812 inset = new InsetFloat(params, "table");
813 //InsetFloat * tmp = new InsetFloat("table");
816 old_float << "wide true\n"
817 << "collapsed false\n";
821 #ifndef NO_PEXTRA_REALLY
824 return false; // no end read yet
827 // Here we need to check for \end_deeper and handle that
828 // before we do the footnote parsing.
829 // This _is_ a hack! (Lgb)
832 string const tmp = lex.getString();
833 if (tmp == "\\end_deeper") {
834 //lyxerr << "\\end_deeper caught!" << endl;
836 lex.printError("\\end_deeper: "
837 "depth is already null");
842 old_float << tmp << ' ';
847 old_float << lex.getLongString("\\end_float")
848 << "\n\\end_inset\n";
849 //lyxerr << "Float Body:\n" << old_float.str() << endl;
850 // That this does not work seems like a bug
851 // in stringstream. (Lgb)
852 istringstream istr(old_float.str());
854 nylex.setStream(istr);
855 inset->read(this, nylex);
856 par->insertInset(pos, inset, font);
858 insertErtContents(par, pos);
860 // we have to reset the font as in the old format after a float
861 // the font was automatically reset!
862 font = LyXFont(LyXFont::ALL_INHERIT, params.language);
864 } else if (token == "\\begin_deeper") {
866 } else if (token == "\\end_deeper") {
868 lex.printError("\\end_deeper: "
869 "depth is already null");
873 } else if (token == "\\begin_preamble") {
874 params.readPreamble(lex);
875 } else if (token == "\\textclass") {
877 pair<bool, textclass_type> pp =
878 textclasslist.NumberOfClass(lex.getString());
880 params.textclass = pp.second;
882 Alert::alert(string(_("Textclass error")),
883 string(_("The document uses an unknown textclass \"")) +
884 lex.getString() + string("\"."),
885 string(_("LyX will not be able to produce output correctly.")));
886 params.textclass = 0;
888 if (!params.getLyXTextClass().load()) {
889 // if the textclass wasn't loaded properly
890 // we need to either substitute another
891 // or stop loading the file.
892 // I can substitute but I don't see how I can
893 // stop loading... ideas?? ARRae980418
894 Alert::alert(_("Textclass Loading Error!"),
895 string(_("Can't load textclass ")) +
896 params.getLyXTextClass().name(),
897 _("-- substituting default"));
898 params.textclass = 0;
900 } else if (token == "\\options") {
902 params.options = lex.getString();
903 } else if (token == "\\language") {
904 params.readLanguage(lex);
905 } else if (token == "\\fontencoding") {
907 } else if (token == "\\inputencoding") {
909 params.inputenc = lex.getString();
910 } else if (token == "\\graphics") {
911 params.readGraphicsDriver(lex);
912 } else if (token == "\\fontscheme") {
914 params.fonts = lex.getString();
915 } else if (token == "\\noindent") {
916 par->params().noindent(true);
917 } else if (token == "\\leftindent") {
919 LyXLength value(lex.getString());
920 par->params().leftIndent(value);
921 } else if (token == "\\fill_top") {
922 par->params().spaceTop(VSpace(VSpace::VFILL));
923 } else if (token == "\\fill_bottom") {
924 par->params().spaceBottom(VSpace(VSpace::VFILL));
925 } else if (token == "\\line_top") {
926 par->params().lineTop(true);
927 } else if (token == "\\line_bottom") {
928 par->params().lineBottom(true);
929 } else if (token == "\\pagebreak_top") {
930 par->params().pagebreakTop(true);
931 } else if (token == "\\pagebreak_bottom") {
932 par->params().pagebreakBottom(true);
933 } else if (token == "\\start_of_appendix") {
934 par->params().startOfAppendix(true);
935 } else if (token == "\\paragraph_separation") {
936 int tmpret = lex.findToken(string_paragraph_separation);
939 params.paragraph_separation =
940 static_cast<BufferParams::PARSEP>(tmpret);
941 } else if (token == "\\defskip") {
943 params.defskip = VSpace(lex.getString());
944 #ifndef NO_COMPABILITY
945 } else if (token == "\\epsfig") { // obsolete
946 // Indeed it is obsolete, but we HAVE to be backwards
947 // compatible until 0.14, because otherwise all figures
948 // in existing documents are irretrivably lost. (Asger)
949 params.readGraphicsDriver(lex);
951 } else if (token == "\\quotes_language") {
952 int tmpret = lex.findToken(string_quotes_language);
955 InsetQuotes::quote_language tmpl =
956 InsetQuotes::EnglishQ;
959 tmpl = InsetQuotes::EnglishQ;
962 tmpl = InsetQuotes::SwedishQ;
965 tmpl = InsetQuotes::GermanQ;
968 tmpl = InsetQuotes::PolishQ;
971 tmpl = InsetQuotes::FrenchQ;
974 tmpl = InsetQuotes::DanishQ;
977 params.quotes_language = tmpl;
978 } else if (token == "\\quotes_times") {
980 switch (lex.getInteger()) {
982 params.quotes_times = InsetQuotes::SingleQ;
985 params.quotes_times = InsetQuotes::DoubleQ;
988 } else if (token == "\\papersize") {
989 int tmpret = lex.findToken(string_papersize);
993 params.papersize2 = tmpret;
994 } else if (token == "\\paperpackage") {
995 int tmpret = lex.findToken(string_paperpackages);
998 params.paperpackage = BufferParams::PACKAGE_NONE;
1000 params.paperpackage = tmpret;
1001 } else if (token == "\\use_geometry") {
1003 params.use_geometry = lex.getInteger();
1004 } else if (token == "\\use_amsmath") {
1006 params.use_amsmath = lex.getInteger();
1007 } else if (token == "\\use_natbib") {
1009 params.use_natbib = lex.getInteger();
1010 } else if (token == "\\use_numerical_citations") {
1012 params.use_numerical_citations = lex.getInteger();
1013 } else if (token == "\\paperorientation") {
1014 int tmpret = lex.findToken(string_orientation);
1017 params.orientation =
1018 static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
1019 } else if (token == "\\paperwidth") {
1021 params.paperwidth = lex.getString();
1022 } else if (token == "\\paperheight") {
1024 params.paperheight = lex.getString();
1025 } else if (token == "\\leftmargin") {
1027 params.leftmargin = lex.getString();
1028 } else if (token == "\\topmargin") {
1030 params.topmargin = lex.getString();
1031 } else if (token == "\\rightmargin") {
1033 params.rightmargin = lex.getString();
1034 } else if (token == "\\bottommargin") {
1036 params.bottommargin = lex.getString();
1037 } else if (token == "\\headheight") {
1039 params.headheight = lex.getString();
1040 } else if (token == "\\headsep") {
1042 params.headsep = lex.getString();
1043 } else if (token == "\\footskip") {
1045 params.footskip = lex.getString();
1046 } else if (token == "\\paperfontsize") {
1048 params.fontsize = rtrim(lex.getString());
1049 } else if (token == "\\papercolumns") {
1051 params.columns = lex.getInteger();
1052 } else if (token == "\\papersides") {
1054 switch (lex.getInteger()) {
1056 case 1: params.sides = LyXTextClass::OneSide; break;
1057 case 2: params.sides = LyXTextClass::TwoSides; break;
1059 } else if (token == "\\paperpagestyle") {
1061 params.pagestyle = rtrim(lex.getString());
1062 } else if (token == "\\bullet") {
1064 int const index = lex.getInteger();
1066 int temp_int = lex.getInteger();
1067 params.user_defined_bullets[index].setFont(temp_int);
1068 params.temp_bullets[index].setFont(temp_int);
1070 temp_int = lex.getInteger();
1071 params.user_defined_bullets[index].setCharacter(temp_int);
1072 params.temp_bullets[index].setCharacter(temp_int);
1074 temp_int = lex.getInteger();
1075 params.user_defined_bullets[index].setSize(temp_int);
1076 params.temp_bullets[index].setSize(temp_int);
1078 string const temp_str = lex.getString();
1079 if (temp_str != "\\end_bullet") {
1080 // this element isn't really necessary for
1081 // parsing but is easier for humans
1082 // to understand bullets. Put it back and
1083 // set a debug message?
1084 lex.printError("\\end_bullet expected, got" + temp_str);
1085 //how can I put it back?
1087 } else if (token == "\\bulletLaTeX") {
1088 // The bullet class should be able to read this.
1090 int const index = lex.getInteger();
1092 string temp_str = lex.getString();
1094 while (temp_str != "\\end_bullet") {
1095 // this loop structure is needed when user
1096 // enters an empty string since the first
1097 // thing returned will be the \\end_bullet
1099 // if the LaTeX entry has spaces. Each element
1100 // therefore needs to be read in turn
1101 sum_str += temp_str;
1103 temp_str = lex.getString();
1106 params.user_defined_bullets[index].setText(sum_str);
1107 params.temp_bullets[index].setText(sum_str);
1108 } else if (token == "\\secnumdepth") {
1110 params.secnumdepth = lex.getInteger();
1111 } else if (token == "\\tocdepth") {
1113 params.tocdepth = lex.getInteger();
1114 } else if (token == "\\spacing") {
1116 string const tmp = rtrim(lex.getString());
1117 Spacing::Space tmp_space = Spacing::Default;
1118 float tmp_val = 0.0;
1119 if (tmp == "single") {
1120 tmp_space = Spacing::Single;
1121 } else if (tmp == "onehalf") {
1122 tmp_space = Spacing::Onehalf;
1123 } else if (tmp == "double") {
1124 tmp_space = Spacing::Double;
1125 } else if (tmp == "other") {
1127 tmp_space = Spacing::Other;
1128 tmp_val = lex.getFloat();
1130 lex.printError("Unknown spacing token: '$$Token'");
1132 // Small hack so that files written with klyx will be
1133 // parsed correctly.
1135 par->params().spacing(Spacing(tmp_space, tmp_val));
1137 params.spacing.set(tmp_space, tmp_val);
1139 } else if (token == "\\paragraph_spacing") {
1141 string const tmp = rtrim(lex.getString());
1142 if (tmp == "single") {
1143 par->params().spacing(Spacing(Spacing::Single));
1144 } else if (tmp == "onehalf") {
1145 par->params().spacing(Spacing(Spacing::Onehalf));
1146 } else if (tmp == "double") {
1147 par->params().spacing(Spacing(Spacing::Double));
1148 } else if (tmp == "other") {
1150 par->params().spacing(Spacing(Spacing::Other,
1153 lex.printError("Unknown spacing token: '$$Token'");
1155 } else if (token == "\\float_placement") {
1157 params.float_placement = lex.getString();
1158 } else if (token == "\\align") {
1159 int tmpret = lex.findToken(string_align);
1160 if (tmpret == -1) ++tmpret;
1161 int const tmpret2 = int(pow(2.0, tmpret));
1162 par->params().align(LyXAlignment(tmpret2));
1163 } else if (token == "\\added_space_top") {
1165 VSpace value = VSpace(lex.getString());
1166 // only add the length when value > 0 or
1168 if ((value.length().len().value() != 0) ||
1170 (value.kind() != VSpace::LENGTH))
1171 par->params().spaceTop(value);
1172 } else if (token == "\\added_space_bottom") {
1174 VSpace value = VSpace(lex.getString());
1175 // only add the length when value > 0 or
1177 if ((value.length().len().value() != 0) ||
1179 (value.kind() != VSpace::LENGTH))
1180 par->params().spaceBottom(value);
1181 #ifndef NO_COMPABILITY
1182 #ifndef NO_PEXTRA_REALLY
1183 } else if (token == "\\pextra_type") {
1185 par->params().pextraType(lex.getInteger());
1186 } else if (token == "\\pextra_width") {
1188 par->params().pextraWidth(lex.getString());
1189 } else if (token == "\\pextra_widthp") {
1191 par->params().pextraWidthp(lex.getString());
1192 } else if (token == "\\pextra_alignment") {
1194 par->params().pextraAlignment(lex.getInteger());
1195 } else if (token == "\\pextra_hfill") {
1197 par->params().pextraHfill(lex.getInteger());
1198 } else if (token == "\\pextra_start_minipage") {
1200 par->params().pextraStartMinipage(lex.getInteger());
1203 } else if (token == "\\labelwidthstring") {
1205 par->params().labelWidthString(lex.getString());
1206 // do not delete this token, it is still needed!
1207 } else if (token == "\\newline") {
1208 #ifndef NO_COMPABILITY
1209 if (!ert_comp.in_tabular && ert_comp.active) {
1210 ert_comp.contents += char(Paragraph::META_NEWLINE);
1212 // Since we cannot know it this is only a regular
1213 // newline or a tabular cell delimter we have to
1214 // handle the ERT here.
1215 insertErtContents(par, pos, false);
1217 par->insertChar(pos, Paragraph::META_NEWLINE, font);
1221 par->insertChar(pos, Paragraph::META_NEWLINE, font);
1224 } else if (token == "\\LyXTable") {
1225 #ifndef NO_COMPABILITY
1226 ert_comp.in_tabular = true;
1228 Inset * inset = new InsetTabular(*this);
1229 inset->read(this, lex);
1230 par->insertInset(pos, inset, font);
1232 } else if (token == "\\hfill") {
1233 par->insertChar(pos, Paragraph::META_HFILL, font);
1235 } else if (token == "\\protected_separator") { // obsolete
1236 // This is a backward compability thingie. (Lgb)
1237 // Remove it later some time...introduced with fileformat
1239 LyXLayout_ptr const & layout = par->layout();
1241 if (layout->free_spacing || par->isFreeSpacing()) {
1242 par->insertChar(pos, ' ', font);
1244 Inset * inset = new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
1245 par->insertInset(pos, inset, font);
1248 } else if (token == "\\bibitem") { // ale970302
1250 InsetCommandParams p("bibitem", "dummy");
1251 par->bibkey = new InsetBibKey(p);
1253 par->bibkey->read(this, lex);
1254 } else if (token == "\\the_end") {
1255 #ifndef NO_COMPABILITY
1256 // If we still have some ert active here we have to insert
1257 // it so we don't loose it. (Lgb)
1258 insertErtContents(par, pos);
1260 the_end_read = true;
1261 #ifndef NO_COMPABILITY
1262 #ifndef NO_PEXTRA_REALLY
1265 minipar = parBeforeMinipage = 0;
1269 #ifndef NO_COMPABILITY
1270 if (ert_comp.active) {
1271 ert_comp.contents += token;
1274 // This should be insurance for the future: (Asger)
1277 string const s = _("Unknown token: ") + token
1278 + " " + lex.text() + "\n";
1279 // we can do this here this way because we're actually reading
1280 // the buffer and don't care about LyXText right now.
1281 InsetError * new_inset = new InsetError(s);
1282 par->insertInset(pos, new_inset, LyXFont(LyXFont::ALL_INHERIT,
1285 #ifndef NO_COMPABILITY
1290 #ifndef NO_COMPABILITY
1291 #ifndef NO_PEXTRA_REALLY
1292 // I wonder if we could use this blanket fix for all the
1293 // checkminipage cases...
1294 // don't forget about ert paragraphs and compatibility read for'em
1295 if (par && (par->size() || !ert_comp.contents.empty())) {
1296 // It is possible that this will check to often,
1297 // but that should not be an correctness issue.
1298 // Only a speed issue.
1299 checkminipage = true;
1302 // now check if we have a minipage paragraph as at this
1303 // point we already read all the necessary data!
1304 // this cannot be done in layout because there we did
1305 // not read yet the paragraph PEXTRA-params (Jug)
1307 // BEGIN pextra_minipage compability
1308 // This should be removed in 1.3.x (Lgb)
1309 // I don't think we should remove this so fast (Jug)
1311 // This compability code is not perfect. In a couple
1312 // of rand cases it fails. When the minipage par is
1313 // the first par in the document, and when there are
1314 // none or only one regular paragraphs after the
1315 // minipage. Currently I am not investing any effort
1316 // in fixing those cases.
1318 // lyxerr << "Call depth: " << call_depth << endl;
1319 // lyxerr << "Checkminipage: " << checkminipage << endl;
1321 if (checkminipage && (call_depth == 1)) {
1322 checkminipage = false;
1323 if (minipar && (minipar != par) &&
1324 (par->params().pextraType() == Paragraph::PEXTRA_MINIPAGE)) {
1325 lyxerr << "minipages in a row" << endl;
1326 if (par->params().pextraStartMinipage()) {
1327 lyxerr << "start new minipage" << endl;
1328 // minipages in a row
1329 par->previous()->next(0);
1332 Paragraph * tmp = minipar;
1334 tmp->params().pextraType(0);
1335 tmp->params().pextraWidth(string());
1336 tmp->params().pextraWidthp(string());
1337 tmp->params().pextraAlignment(0);
1338 tmp->params().pextraHfill(false);
1339 tmp->params().pextraStartMinipage(false);
1342 // create a new paragraph to insert the
1343 // minipages in the following case
1344 if (par->params().pextraStartMinipage() &&
1345 !par->params().pextraHfill()) {
1346 Paragraph * p = new Paragraph;
1347 p->layout(params.getLyXTextClass().defaultLayoutName());
1349 p->previous(parBeforeMinipage);
1350 parBeforeMinipage->next(p);
1352 p->params().depth(parBeforeMinipage->params().depth());
1353 parBeforeMinipage = p;
1355 InsetMinipage * mini = new InsetMinipage(params);
1356 mini->pos(static_cast<InsetMinipage::Position>(par->params().pextraAlignment()));
1357 mini->pageWidth(LyXLength(par->params().pextraWidth()));
1358 if (!par->params().pextraWidthp().empty()) {
1359 lyxerr << "WP:" << mini->pageWidth().asString() << endl;
1360 mini->pageWidth(LyXLength((par->params().pextraWidthp())+"col%"));
1362 Paragraph * op = mini->firstParagraph();
1363 mini->inset.paragraph(par);
1365 // and free the old ones!
1368 Paragraph * pp = op->next();
1372 // Insert the minipage last in the
1373 // previous paragraph.
1374 if (par->params().pextraHfill()) {
1375 parBeforeMinipage->insertChar
1376 (parBeforeMinipage->size(),
1377 Paragraph::META_HFILL, font);
1379 parBeforeMinipage->insertInset
1380 (parBeforeMinipage->size(), mini, font);
1384 lyxerr << "new minipage par" << endl;
1385 //nothing to do just continue reading
1388 } else if (minipar && (minipar != par)) {
1389 lyxerr << "last minipage par read" << endl;
1390 // The last paragraph read was not part of a
1391 // minipage but the par linked list is...
1392 // So we need to remove the last par from the
1394 if (par->previous())
1395 par->previous()->next(0);
1396 par->previous(parBeforeMinipage);
1397 parBeforeMinipage->next(par);
1398 Paragraph * tmp = minipar;
1400 tmp->params().pextraType(0);
1401 tmp->params().pextraWidth(string());
1402 tmp->params().pextraWidthp(string());
1403 tmp->params().pextraAlignment(0);
1404 tmp->params().pextraHfill(false);
1405 tmp->params().pextraStartMinipage(false);
1408 depth = parBeforeMinipage->params().depth();
1409 // and set this depth on the par as it has not been set already
1410 par->params().depth(depth);
1411 minipar = parBeforeMinipage = 0;
1412 } else if (!minipar &&
1413 (par->params().pextraType() == Paragraph::PEXTRA_MINIPAGE)) {
1414 // par is the first paragraph in a minipage
1415 lyxerr << "begin minipage" << endl;
1416 // To minimize problems for
1417 // the users we will insert
1418 // the first minipage in
1419 // a sequence of minipages
1420 // in its own paragraph.
1421 Paragraph * p = new Paragraph;
1422 p->layout(params.getLyXTextClass().defaultLayoutName());
1423 p->previous(par->previous());
1425 p->params().depth(depth);
1426 par->params().depth(0);
1428 if (par->previous())
1429 par->previous()->next(p);
1431 parBeforeMinipage = p;
1433 if (!first_par || (first_par == par))
1436 InsetMinipage * mini = new InsetMinipage(params);
1437 mini->pos(static_cast<InsetMinipage::Position>(minipar->params().pextraAlignment()));
1438 mini->pageWidth(LyXLength(minipar->params().pextraWidth()));
1439 if (!par->params().pextraWidthp().empty()) {
1440 lyxerr << "WP:" << mini->pageWidth().asString() << endl;
1441 mini->pageWidth(LyXLength((par->params().pextraWidthp())+"col%"));
1444 Paragraph * op = mini->firstParagraph();
1445 mini->inset.paragraph(minipar);
1447 // and free the old ones!
1450 Paragraph * pp = op->next();
1455 // Insert the minipage last in the
1456 // previous paragraph.
1457 if (minipar->params().pextraHfill()) {
1458 parBeforeMinipage->insertChar
1459 (parBeforeMinipage->size(),
1460 Paragraph::META_HFILL, font);
1462 parBeforeMinipage->insertInset
1463 (parBeforeMinipage->size(), mini, font);
1464 } else if (par->params().pextraType() == Paragraph::PEXTRA_INDENT) {
1465 par->params().leftIndent(LyXLength(par->params().pextraWidth()));
1466 if (!par->params().pextraWidthp().empty()) {
1467 par->params().leftIndent(LyXLength((par->params().pextraWidthp())+"col%"));
1471 // End of pextra_minipage compability
1475 return the_end_read;
1478 // needed to insert the selection
1479 void Buffer::insertStringAsLines(Paragraph *& par, pos_type & pos,
1480 LyXFont const & fn,string const & str) const
1482 LyXLayout_ptr const & layout = par->layout();
1486 par->checkInsertChar(font);
1487 // insert the string, don't insert doublespace
1488 bool space_inserted = true;
1489 bool autobreakrows = !par->inInset() ||
1490 static_cast<InsetText *>(par->inInset())->getAutoBreakRows();
1491 for(string::const_iterator cit = str.begin();
1492 cit != str.end(); ++cit) {
1494 if (autobreakrows && (!par->empty() || layout->keepempty)) {
1495 par->breakParagraph(params, pos,
1496 layout->isEnvironment());
1499 space_inserted = true;
1503 // do not insert consecutive spaces if !free_spacing
1504 } else if ((*cit == ' ' || *cit == '\t') &&
1505 space_inserted && !layout->free_spacing &&
1506 !par->isFreeSpacing())
1509 } else if (*cit == '\t') {
1510 if (!layout->free_spacing && !par->isFreeSpacing()) {
1511 // tabs are like spaces here
1512 par->insertChar(pos, ' ', font);
1514 space_inserted = true;
1516 const pos_type nb = 8 - pos % 8;
1517 for (pos_type a = 0; a < nb ; ++a) {
1518 par->insertChar(pos, ' ', font);
1521 space_inserted = true;
1523 } else if (!IsPrintable(*cit)) {
1524 // Ignore unprintables
1527 // just insert the character
1528 par->insertChar(pos, *cit, font);
1530 space_inserted = (*cit == ' ');
1537 void Buffer::readInset(LyXLex & lex, Paragraph *& par,
1538 int & pos, LyXFont & font)
1540 // consistency check
1541 if (lex.getString() != "\\begin_inset") {
1542 lyxerr << "Buffer::readInset: Consistency check failed."
1549 string const tmptok = lex.getString();
1550 last_inset_read = tmptok;
1552 // test the different insets
1553 if (tmptok == "LatexCommand") {
1554 InsetCommandParams inscmd;
1557 string const cmdName = inscmd.getCmdName();
1559 // This strange command allows LyX to recognize "natbib" style
1560 // citations: citet, citep, Citet etc.
1561 if (compare_ascii_no_case(cmdName.substr(0,4), "cite") == 0) {
1562 inset = new InsetCitation(inscmd);
1563 } else if (cmdName == "bibitem") {
1564 lex.printError("Wrong place for bibitem");
1565 inset = new InsetBibKey(inscmd);
1566 } else if (cmdName == "BibTeX") {
1567 inset = new InsetBibtex(inscmd);
1568 } else if (cmdName == "index") {
1569 inset = new InsetIndex(inscmd);
1570 } else if (cmdName == "include") {
1571 inset = new InsetInclude(inscmd, *this);
1572 } else if (cmdName == "label") {
1573 inset = new InsetLabel(inscmd);
1574 } else if (cmdName == "url"
1575 || cmdName == "htmlurl") {
1576 inset = new InsetUrl(inscmd);
1577 } else if (cmdName == "ref"
1578 || cmdName == "pageref"
1579 || cmdName == "vref"
1580 || cmdName == "vpageref"
1581 || cmdName == "prettyref") {
1582 if (!inscmd.getOptions().empty()
1583 || !inscmd.getContents().empty()) {
1584 inset = new InsetRef(inscmd, *this);
1586 } else if (cmdName == "tableofcontents") {
1587 inset = new InsetTOC(inscmd);
1588 } else if (cmdName == "listofalgorithms") {
1589 inset = new InsetFloatList("algorithm");
1590 } else if (cmdName == "listoffigures") {
1591 inset = new InsetFloatList("figure");
1592 } else if (cmdName == "listoftables") {
1593 inset = new InsetFloatList("table");
1594 } else if (cmdName == "printindex") {
1595 inset = new InsetPrintIndex(inscmd);
1596 } else if (cmdName == "lyxparent") {
1597 inset = new InsetParent(inscmd, *this);
1600 bool alreadyread = false;
1601 if (tmptok == "Quotes") {
1602 inset = new InsetQuotes;
1603 } else if (tmptok == "External") {
1604 inset = new InsetExternal;
1605 } else if (tmptok == "FormulaMacro") {
1606 inset = new InsetFormulaMacro;
1607 } else if (tmptok == "Formula") {
1608 inset = new InsetFormula;
1609 } else if (tmptok == "Figure") { // Backward compatibility
1610 // inset = new InsetFig(100, 100, *this);
1611 inset = new InsetGraphics;
1612 } else if (tmptok == "Graphics") {
1613 inset = new InsetGraphics;
1614 } else if (tmptok == "Info") {// backwards compatibility
1615 inset = new InsetNote(this,
1616 lex.getLongString("\\end_inset"),
1619 } else if (tmptok == "Note") {
1620 inset = new InsetNote(params);
1621 } else if (tmptok == "Include") {
1622 InsetCommandParams p("Include");
1623 inset = new InsetInclude(p, *this);
1624 } else if (tmptok == "ERT") {
1625 inset = new InsetERT(params);
1626 } else if (tmptok == "Tabular") {
1627 inset = new InsetTabular(*this);
1628 } else if (tmptok == "Text") {
1629 inset = new InsetText(params);
1630 } else if (tmptok == "Foot") {
1631 inset = new InsetFoot(params);
1632 } else if (tmptok == "Marginal") {
1633 inset = new InsetMarginal(params);
1634 } else if (tmptok == "Minipage") {
1635 inset = new InsetMinipage(params);
1636 } else if (tmptok == "Float") {
1638 string tmptok = lex.getString();
1639 inset = new InsetFloat(params, tmptok);
1641 } else if (tmptok == "List") {
1642 inset = new InsetList;
1643 } else if (tmptok == "Theorem") {
1644 inset = new InsetList;
1646 } else if (tmptok == "Caption") {
1647 inset = new InsetCaption(params);
1648 } else if (tmptok == "FloatList") {
1649 inset = new InsetFloatList;
1652 if (inset && !alreadyread) inset->read(this, lex);
1656 par->insertInset(pos, inset, font);
1662 bool Buffer::readFile(LyXLex & lex, Paragraph * par)
1666 string const token(lex.getString());
1667 if (token == "\\lyxformat") { // the first token _must_ be...
1669 string tmp_format = lex.getString();
1670 //lyxerr << "LyX Format: `" << tmp_format << "'" << endl;
1671 // if present remove ".," from string.
1672 string::size_type dot = tmp_format.find_first_of(".,");
1673 //lyxerr << " dot found at " << dot << endl;
1674 if (dot != string::npos)
1675 tmp_format.erase(dot, 1);
1676 file_format = strToInt(tmp_format);
1677 if (file_format == LYX_FORMAT) {
1679 } else if (file_format > LYX_FORMAT) {
1681 Alert::alert(_("Warning!"),
1682 _("LyX file format is newer that what"),
1683 _("is supported in this LyX version. Expect some problems."));
1685 } else if (file_format < LYX_FORMAT) {
1687 if (file_format < 200) {
1688 Alert::alert(_("ERROR!"),
1689 _("Old LyX file format found. "
1690 "Use LyX 0.10.x to read this!"));
1692 } else if (file_format < 220) {
1693 string const command = "lyx2lyx "
1694 + QuoteName(filename_);
1695 cmd_ret const ret = RunCommand(command);
1697 Alert::alert(_("ERROR!"),
1698 _("An error occured while "
1699 "running the conversion script."));
1702 istringstream is(ret.second);
1703 LyXLex tmplex(0, 0);
1704 tmplex.setStream(is);
1705 return readFile(tmplex);
1708 bool the_end = readLyXformat2(lex, par);
1709 params.setPaperStuff();
1712 // the_end was added in 213
1713 if (file_format < 213)
1718 Alert::alert(_("Warning!"),
1719 _("Reading of document is not complete"),
1720 _("Maybe the document is truncated"));
1723 } else { // "\\lyxformat" not found
1724 Alert::alert(_("ERROR!"), _("Not a LyX file!"));
1727 Alert::alert(_("ERROR!"), _("Unable to read file!"));
1732 // Should probably be moved to somewhere else: BufferView? LyXView?
1733 bool Buffer::save() const
1735 // We don't need autosaves in the immediate future. (Asger)
1736 resetAutosaveTimers();
1740 if (lyxrc.make_backup) {
1741 s = fileName() + '~';
1742 if (!lyxrc.backupdir_path.empty())
1743 s = AddName(lyxrc.backupdir_path,
1744 subst(os::slashify_path(s),'/','!'));
1746 // Rename is the wrong way of making a backup,
1747 // this is the correct way.
1748 /* truss cp fil fil2:
1749 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
1750 stat("LyXVC.lyx", 0xEFFFF688) = 0
1751 open("LyXVC.lyx", O_RDONLY) = 3
1752 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
1753 fstat(4, 0xEFFFF508) = 0
1754 fstat(3, 0xEFFFF508) = 0
1755 read(3, " # T h i s f i l e w".., 8192) = 5579
1756 write(4, " # T h i s f i l e w".., 5579) = 5579
1757 read(3, 0xEFFFD4A0, 8192) = 0
1760 chmod("LyXVC3.lyx", 0100644) = 0
1761 lseek(0, 0, SEEK_CUR) = 46440
1765 // Should probably have some more error checking here.
1766 // Doing it this way, also makes the inodes stay the same.
1767 // This is still not a very good solution, in particular we
1768 // might loose the owner of the backup.
1769 FileInfo finfo(fileName());
1770 if (finfo.exist()) {
1771 mode_t fmode = finfo.getMode();
1772 struct utimbuf times = {
1773 finfo.getAccessTime(),
1774 finfo.getModificationTime() };
1776 ifstream ifs(fileName().c_str());
1777 ofstream ofs(s.c_str(), ios::out|ios::trunc);
1782 ::chmod(s.c_str(), fmode);
1784 if (::utime(s.c_str(), ×)) {
1785 lyxerr << "utime error." << endl;
1788 lyxerr << "LyX was not able to make "
1789 "backup copy. Beware." << endl;
1794 if (writeFile(fileName())) {
1796 removeAutosaveFile(fileName());
1798 // Saving failed, so backup is not backup
1799 if (lyxrc.make_backup) {
1800 lyx::rename(s, fileName());
1808 bool Buffer::writeFile(string const & fname) const
1810 if (read_only && (fname == fileName())) {
1814 FileInfo finfo(fname);
1815 if (finfo.exist() && !finfo.writable()) {
1819 ofstream ofs(fname.c_str());
1825 // Use the standard "C" locale for file output.
1826 ofs.imbue(std::locale::classic());
1829 // The top of the file should not be written by params.
1831 // write out a comment in the top of the file
1832 ofs << '#' << lyx_docversion
1833 << " created this file. For more info see http://www.lyx.org/\n"
1834 << "\\lyxformat " << LYX_FORMAT << "\n";
1836 // now write out the buffer paramters.
1837 params.writeFile(ofs);
1839 Paragraph::depth_type depth = 0;
1841 // this will write out all the paragraphs
1842 // using recursive descent.
1843 paragraphs.begin()->writeFile(this, ofs, params, depth);
1845 // Write marker that shows file is complete
1846 ofs << "\n\\the_end" << endl;
1850 // how to check if close went ok?
1851 // Following is an attempt... (BE 20001011)
1853 // good() returns false if any error occured, including some
1854 // formatting error.
1855 // bad() returns true if something bad happened in the buffer,
1856 // which should include file system full errors.
1863 lyxerr << "Buffer::writeFile: BAD ERROR!" << endl;
1865 lyxerr << "Buffer::writeFile: NOT SO BAD ERROR!"
1877 pair<int, string> const addDepth(int depth, int ldepth)
1881 d += (ldepth - depth) * 2;
1882 return make_pair(d, string(d, ' '));
1888 string const Buffer::asciiParagraph(Paragraph const * par,
1889 unsigned int linelen,
1890 bool noparbreak) const
1892 ostringstream buffer;
1893 Paragraph::depth_type depth = 0;
1895 Paragraph::depth_type ltype_depth = 0;
1896 bool ref_printed = false;
1897 // if (!par->previous()) {
1899 // begins or ends a deeper area ?
1900 if (depth != par->params().depth()) {
1901 if (par->params().depth() > depth) {
1902 while (par->params().depth() > depth) {
1906 while (par->params().depth() < depth) {
1912 depth = par->params().depth();
1915 // First write the layout
1916 string const & tmp = par->layout()->name();
1917 if (compare_no_case(tmp, "itemize") == 0) {
1919 ltype_depth = depth + 1;
1920 } else if (compare_ascii_no_case(tmp, "enumerate") == 0) {
1922 ltype_depth = depth + 1;
1923 } else if (contains(ascii_lowercase(tmp), "ection")) {
1925 ltype_depth = depth + 1;
1926 } else if (contains(ascii_lowercase(tmp), "aragraph")) {
1928 ltype_depth = depth + 1;
1929 } else if (compare_ascii_no_case(tmp, "description") == 0) {
1931 ltype_depth = depth + 1;
1932 } else if (compare_ascii_no_case(tmp, "abstract") == 0) {
1935 } else if (compare_ascii_no_case(tmp, "bibliography") == 0) {
1943 /* maybe some vertical spaces */
1945 /* the labelwidthstring used in lists */
1949 /* some pagebreaks? */
1953 /* what about the alignment */
1955 // lyxerr << "Should this ever happen?" << endl;
1958 // linelen <= 0 is special and means we don't have pargraph breaks
1960 string::size_type currlinelen = 0;
1966 buffer << string(depth * 2, ' ');
1967 currlinelen += depth * 2;
1970 // we should probably change to the paragraph language in the
1971 // gettext here (if possible) so that strings are outputted in
1972 // the correct language! (20012712 Jug)
1976 case 4: // (Sub)Paragraph
1977 case 5: // Description
1981 buffer << _("Abstract") << "\n\n";
1984 string const abst = _("Abstract: ");
1986 currlinelen += abst.length();
1989 case 7: // Bibliography
1992 buffer << _("References") << "\n\n";
1995 string const refs = _("References: ");
1997 currlinelen += refs.length();
2005 string const parlab = par->params().labelString();
2006 buffer << parlab << " ";
2007 currlinelen += parlab.length() + 1;
2015 pair<int, string> p = addDepth(depth, ltype_depth);
2017 currlinelen += p.first;
2020 // this is to change the linebreak to do it by word a bit more
2021 // intelligent hopefully! (only in the case where we have a
2022 // max linelenght!) (Jug)
2026 for (pos_type i = 0; i < par->size(); ++i) {
2027 char c = par->getUChar(params, i);
2029 case Paragraph::META_INSET:
2031 Inset const * inset = par->getInset(i);
2035 currlinelen += word.length();
2038 if (inset->ascii(this, buffer, linelen)) {
2039 // to be sure it breaks paragraph
2040 currlinelen += linelen;
2046 case Paragraph::META_NEWLINE:
2048 buffer << word << "\n";
2051 pair<int, string> p = addDepth(depth,
2054 currlinelen = p.first;
2058 case Paragraph::META_HFILL:
2059 buffer << word << "\t";
2060 currlinelen += word.length() + 1;
2067 currlinelen + word.length() > linelen - 10) {
2069 pair<int, string> p =
2070 addDepth(depth, ltype_depth);
2072 currlinelen = p.first;
2075 buffer << word << ' ';
2076 currlinelen += word.length() + 1;
2083 lyxerr[Debug::INFO] <<
2084 "writeAsciiFile: NULL char in structure." << endl;
2086 if ((linelen > 0) &&
2087 (currlinelen + word.length()) > linelen)
2091 pair<int, string> p =
2092 addDepth(depth, ltype_depth);
2094 currlinelen = p.first;
2101 return buffer.str().c_str();
2105 void Buffer::writeFileAscii(string const & fname, int linelen)
2107 ofstream ofs(fname.c_str());
2109 Alert::err_alert(_("Error: Cannot write file:"), fname);
2112 writeFileAscii(ofs, linelen);
2116 void Buffer::writeFileAscii(ostream & ofs, int linelen)
2118 Paragraph * par = &*(paragraphs.begin());
2120 ofs << asciiParagraph(par, linelen, par->previous() == 0);
2130 void Buffer::makeLaTeXFile(string const & fname,
2131 string const & original_path,
2132 bool nice, bool only_body, bool only_preamble)
2134 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
2136 ofstream ofs(fname.c_str());
2138 Alert::err_alert(_("Error: Cannot open file: "), fname);
2142 makeLaTeXFile(ofs, original_path, nice, only_body, only_preamble);
2146 lyxerr << "File was not closed properly." << endl;
2151 void Buffer::makeLaTeXFile(ostream & os,
2152 string const & original_path,
2153 bool nice, bool only_body, bool only_preamble)
2155 niceFile = nice; // this will be used by Insetincludes.
2157 // validate the buffer.
2158 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
2159 LaTeXFeatures features(params);
2161 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
2164 // The starting paragraph of the coming rows is the
2165 // first paragraph of the document. (Asger)
2166 texrow.start(&*(paragraphs.begin()), 0);
2168 if (!only_body && nice) {
2169 os << "%% " << lyx_docversion << " created this file. "
2170 "For more info, see http://www.lyx.org/.\n"
2171 "%% Do not edit unless you really know what "
2176 lyxerr[Debug::INFO] << "lyx header finished" << endl;
2177 // There are a few differences between nice LaTeX and usual files:
2178 // usual is \batchmode and has a
2179 // special input@path to allow the including of figures
2180 // with either \input or \includegraphics (what figinsets do).
2181 // input@path is set when the actual parameter
2182 // original_path is set. This is done for usual tex-file, but not
2183 // for nice-latex-file. (Matthias 250696)
2186 // code for usual, NOT nice-latex-file
2187 os << "\\batchmode\n"; // changed
2188 // from \nonstopmode
2191 if (!original_path.empty()) {
2192 string inputpath = os::external_path(original_path);
2193 subst(inputpath, "~", "\\string~");
2194 os << "\\makeatletter\n"
2195 << "\\def\\input@path{{"
2196 << inputpath << "/}}\n"
2197 << "\\makeatother\n";
2203 os << "\\documentclass";
2205 LyXTextClass const & tclass = params.getLyXTextClass();
2207 ostringstream options; // the document class options.
2209 if (tokenPos(tclass.opt_fontsize(),
2210 '|', params.fontsize) >= 0) {
2211 // only write if existing in list (and not default)
2212 options << params.fontsize << "pt,";
2216 if (!params.use_geometry &&
2217 (params.paperpackage == BufferParams::PACKAGE_NONE)) {
2218 switch (params.papersize) {
2219 case BufferParams::PAPER_A4PAPER:
2220 options << "a4paper,";
2222 case BufferParams::PAPER_USLETTER:
2223 options << "letterpaper,";
2225 case BufferParams::PAPER_A5PAPER:
2226 options << "a5paper,";
2228 case BufferParams::PAPER_B5PAPER:
2229 options << "b5paper,";
2231 case BufferParams::PAPER_EXECUTIVEPAPER:
2232 options << "executivepaper,";
2234 case BufferParams::PAPER_LEGALPAPER:
2235 options << "legalpaper,";
2241 if (params.sides != tclass.sides()) {
2242 switch (params.sides) {
2243 case LyXTextClass::OneSide:
2244 options << "oneside,";
2246 case LyXTextClass::TwoSides:
2247 options << "twoside,";
2253 if (params.columns != tclass.columns()) {
2254 if (params.columns == 2)
2255 options << "twocolumn,";
2257 options << "onecolumn,";
2260 if (!params.use_geometry
2261 && params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
2262 options << "landscape,";
2264 // language should be a parameter to \documentclass
2266 ostringstream language_options;
2267 if (params.language->babel() == "hebrew"
2268 && default_language->babel() != "hebrew")
2269 // This seems necessary
2270 features.useLanguage(default_language);
2272 if (lyxrc.language_use_babel ||
2273 params.language->lang() != lyxrc.default_language ||
2274 features.hasLanguages()) {
2276 language_options << features.getLanguages();
2277 language_options << params.language->babel();
2278 if (lyxrc.language_global_options)
2279 options << language_options.str() << ',';
2282 // the user-defined options
2283 if (!params.options.empty()) {
2284 options << params.options << ',';
2287 string strOptions(options.str().c_str());
2288 if (!strOptions.empty()) {
2289 strOptions = rtrim(strOptions, ",");
2290 os << '[' << strOptions << ']';
2293 os << '{' << tclass.latexname() << "}\n";
2295 // end of \documentclass defs
2297 // font selection must be done before loading fontenc.sty
2298 // The ae package is not needed when using OT1 font encoding.
2299 if (params.fonts != "default" &&
2300 (params.fonts != "ae" || lyxrc.fontenc != "default")) {
2301 os << "\\usepackage{" << params.fonts << "}\n";
2303 if (params.fonts == "ae") {
2304 os << "\\usepackage{aecompl}\n";
2308 // this one is not per buffer
2309 if (lyxrc.fontenc != "default") {
2310 os << "\\usepackage[" << lyxrc.fontenc
2315 if (params.inputenc == "auto") {
2316 string const doc_encoding =
2317 params.language->encoding()->LatexName();
2319 // Create a list with all the input encodings used
2321 set<string> encodings = features.getEncodingSet(doc_encoding);
2323 os << "\\usepackage[";
2324 std::copy(encodings.begin(), encodings.end(),
2325 std::ostream_iterator<string>(os, ","));
2326 os << doc_encoding << "]{inputenc}\n";
2328 } else if (params.inputenc != "default") {
2329 os << "\\usepackage[" << params.inputenc
2334 // At the very beginning the text parameters.
2335 if (params.paperpackage != BufferParams::PACKAGE_NONE) {
2336 switch (params.paperpackage) {
2337 case BufferParams::PACKAGE_A4:
2338 os << "\\usepackage{a4}\n";
2341 case BufferParams::PACKAGE_A4WIDE:
2342 os << "\\usepackage{a4wide}\n";
2345 case BufferParams::PACKAGE_WIDEMARGINSA4:
2346 os << "\\usepackage[widemargins]{a4}\n";
2351 if (params.use_geometry) {
2352 os << "\\usepackage{geometry}\n";
2354 os << "\\geometry{verbose";
2355 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
2357 switch (params.papersize2) {
2358 case BufferParams::VM_PAPER_CUSTOM:
2359 if (!params.paperwidth.empty())
2360 os << ",paperwidth="
2361 << params.paperwidth;
2362 if (!params.paperheight.empty())
2363 os << ",paperheight="
2364 << params.paperheight;
2366 case BufferParams::VM_PAPER_USLETTER:
2367 os << ",letterpaper";
2369 case BufferParams::VM_PAPER_USLEGAL:
2370 os << ",legalpaper";
2372 case BufferParams::VM_PAPER_USEXECUTIVE:
2373 os << ",executivepaper";
2375 case BufferParams::VM_PAPER_A3:
2378 case BufferParams::VM_PAPER_A4:
2381 case BufferParams::VM_PAPER_A5:
2384 case BufferParams::VM_PAPER_B3:
2387 case BufferParams::VM_PAPER_B4:
2390 case BufferParams::VM_PAPER_B5:
2394 // default papersize ie BufferParams::VM_PAPER_DEFAULT
2395 switch (lyxrc.default_papersize) {
2396 case BufferParams::PAPER_DEFAULT: // keep compiler happy
2397 case BufferParams::PAPER_USLETTER:
2398 os << ",letterpaper";
2400 case BufferParams::PAPER_LEGALPAPER:
2401 os << ",legalpaper";
2403 case BufferParams::PAPER_EXECUTIVEPAPER:
2404 os << ",executivepaper";
2406 case BufferParams::PAPER_A3PAPER:
2409 case BufferParams::PAPER_A4PAPER:
2412 case BufferParams::PAPER_A5PAPER:
2415 case BufferParams::PAPER_B5PAPER:
2420 if (!params.topmargin.empty())
2421 os << ",tmargin=" << params.topmargin;
2422 if (!params.bottommargin.empty())
2423 os << ",bmargin=" << params.bottommargin;
2424 if (!params.leftmargin.empty())
2425 os << ",lmargin=" << params.leftmargin;
2426 if (!params.rightmargin.empty())
2427 os << ",rmargin=" << params.rightmargin;
2428 if (!params.headheight.empty())
2429 os << ",headheight=" << params.headheight;
2430 if (!params.headsep.empty())
2431 os << ",headsep=" << params.headsep;
2432 if (!params.footskip.empty())
2433 os << ",footskip=" << params.footskip;
2438 if (tokenPos(tclass.opt_pagestyle(),
2439 '|', params.pagestyle) >= 0) {
2440 if (params.pagestyle == "fancy") {
2441 os << "\\usepackage{fancyhdr}\n";
2444 os << "\\pagestyle{" << params.pagestyle << "}\n";
2448 if (params.secnumdepth != tclass.secnumdepth()) {
2449 os << "\\setcounter{secnumdepth}{"
2450 << params.secnumdepth
2454 if (params.tocdepth != tclass.tocdepth()) {
2455 os << "\\setcounter{tocdepth}{"
2461 if (params.paragraph_separation) {
2462 switch (params.defskip.kind()) {
2463 case VSpace::SMALLSKIP:
2464 os << "\\setlength\\parskip{\\smallskipamount}\n";
2466 case VSpace::MEDSKIP:
2467 os << "\\setlength\\parskip{\\medskipamount}\n";
2469 case VSpace::BIGSKIP:
2470 os << "\\setlength\\parskip{\\bigskipamount}\n";
2472 case VSpace::LENGTH:
2473 os << "\\setlength\\parskip{"
2474 << params.defskip.length().asLatexString()
2477 default: // should never happen // Then delete it.
2478 os << "\\setlength\\parskip{\\medskipamount}\n";
2483 os << "\\setlength\\parindent{0pt}\n";
2487 // Now insert the LyX specific LaTeX commands...
2489 // The optional packages;
2490 string preamble(features.getPackages());
2492 // this might be useful...
2493 preamble += "\n\\makeatletter\n";
2495 // Some macros LyX will need
2496 string tmppreamble(features.getMacros());
2498 if (!tmppreamble.empty()) {
2499 preamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2500 "LyX specific LaTeX commands.\n"
2501 + tmppreamble + '\n';
2504 // the text class specific preamble
2505 tmppreamble = features.getTClassPreamble();
2506 if (!tmppreamble.empty()) {
2507 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2508 "Textclass specific LaTeX commands.\n"
2509 + tmppreamble + '\n';
2512 /* the user-defined preamble */
2513 if (!params.preamble.empty()) {
2514 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2515 "User specified LaTeX commands.\n"
2516 + params.preamble + '\n';
2519 // Itemize bullet settings need to be last in case the user
2520 // defines their own bullets that use a package included
2521 // in the user-defined preamble -- ARRae
2522 // Actually it has to be done much later than that
2523 // since some packages like frenchb make modifications
2524 // at \begin{document} time -- JMarc
2526 for (int i = 0; i < 4; ++i) {
2527 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
2528 if (bullets_def.empty())
2529 bullets_def="\\AtBeginDocument{\n";
2530 bullets_def += " \\renewcommand{\\labelitemi";
2532 // `i' is one less than the item to modify
2539 bullets_def += "ii";
2545 bullets_def += "}{" +
2546 params.user_defined_bullets[i].getText()
2551 if (!bullets_def.empty())
2552 preamble += bullets_def + "}\n\n";
2555 int(lyx::count(preamble.begin(), preamble.end(), '\n'));
2556 for (int j = 0; j != nlines; ++j) {
2560 // We try to load babel late, in case it interferes
2561 // with other packages.
2563 string tmp = lyxrc.language_package;
2564 if (!lyxrc.language_global_options
2565 && tmp == "\\usepackage{babel}")
2566 tmp = string("\\usepackage[") +
2567 language_options.str().c_str() +
2569 preamble += tmp + "\n";
2570 preamble += features.getBabelOptions();
2573 preamble += "\\makeatother\n";
2581 os << "\\begin{document}\n";
2584 lyxerr[Debug::INFO] << "preamble finished, now the body." << endl;
2586 if (!lyxrc.language_auto_begin) {
2587 os << subst(lyxrc.language_command_begin, "$$lang",
2588 params.language->babel())
2593 latexParagraphs(os, &*(paragraphs.begin()), 0, texrow);
2595 // add this just in case after all the paragraphs
2599 if (!lyxrc.language_auto_end) {
2600 os << subst(lyxrc.language_command_end, "$$lang",
2601 params.language->babel())
2607 os << "\\end{document}\n";
2610 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
2612 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
2616 // Just to be sure. (Asger)
2619 lyxerr[Debug::INFO] << "Finished making latex file." << endl;
2620 lyxerr[Debug::INFO] << "Row count was " << texrow.rows()-1 << "." << endl;
2622 // we want this to be true outside previews (for insetexternal)
2628 // LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
2630 void Buffer::latexParagraphs(ostream & ofs, Paragraph * par,
2631 Paragraph * endpar, TexRow & texrow,
2632 bool moving_arg) const
2634 bool was_title = false;
2635 bool already_title = false;
2638 while (par != endpar) {
2639 Inset * in = par->inInset();
2640 // well we have to check if we are in an inset with unlimited
2641 // lenght (all in one row) if that is true then we don't allow
2642 // any special options in the paragraph and also we don't allow
2643 // any environment other then "Standard" to be valid!
2644 if ((in == 0) || !in->forceDefaultParagraphs(in)) {
2645 LyXLayout_ptr const & layout = par->layout();
2647 if (layout->intitle) {
2648 if (already_title) {
2649 lyxerr <<"Error in latexParagraphs: You"
2650 " should not mix title layouts"
2651 " with normal ones." << endl;
2654 } else if (was_title && !already_title) {
2655 ofs << "\\maketitle\n";
2657 already_title = true;
2661 if (layout->isEnvironment() ||
2662 !par->params().leftIndent().zero())
2664 par = par->TeXEnvironment(this, params, ofs, texrow);
2666 par = par->TeXOnePar(this, params, ofs, texrow, moving_arg);
2669 par = par->TeXOnePar(this, params, ofs, texrow, moving_arg);
2672 // It might be that we only have a title in this document
2673 if (was_title && !already_title) {
2674 ofs << "\\maketitle\n";
2680 bool Buffer::isLatex() const
2682 return params.getLyXTextClass().outputType() == LATEX;
2686 bool Buffer::isLinuxDoc() const
2688 return params.getLyXTextClass().outputType() == LINUXDOC;
2692 bool Buffer::isLiterate() const
2694 return params.getLyXTextClass().outputType() == LITERATE;
2698 bool Buffer::isDocBook() const
2700 return params.getLyXTextClass().outputType() == DOCBOOK;
2704 bool Buffer::isSGML() const
2706 LyXTextClass const & tclass = params.getLyXTextClass();
2708 return tclass.outputType() == LINUXDOC ||
2709 tclass.outputType() == DOCBOOK;
2713 int Buffer::sgmlOpenTag(ostream & os, Paragraph::depth_type depth, bool mixcont,
2714 string const & latexname) const
2716 if (!latexname.empty() && latexname != "!-- --") {
2718 os << string(" ",depth);
2719 os << "<" << latexname << ">";
2729 int Buffer::sgmlCloseTag(ostream & os, Paragraph::depth_type depth, bool mixcont,
2730 string const & latexname) const
2732 if (!latexname.empty() && latexname != "!-- --") {
2734 os << endl << string(" ",depth);
2735 os << "</" << latexname << ">";
2745 void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
2747 ofstream ofs(fname.c_str());
2750 Alert::alert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2754 niceFile = nice; // this will be used by included files.
2756 LaTeXFeatures features(params);
2762 LyXTextClass const & tclass = params.getLyXTextClass();
2764 string top_element = tclass.latexname();
2767 ofs << "<!doctype linuxdoc system";
2769 string preamble = params.preamble;
2770 const string name = nice ? ChangeExtension(filename_, ".sgml")
2772 preamble += features.getIncludedFiles(name);
2773 preamble += features.getLyXSGMLEntities();
2775 if (!preamble.empty()) {
2776 ofs << " [ " << preamble << " ]";
2780 if (params.options.empty())
2781 sgmlOpenTag(ofs, 0, false, top_element);
2783 string top = top_element;
2785 top += params.options;
2786 sgmlOpenTag(ofs, 0, false, top);
2790 ofs << "<!-- " << lyx_docversion
2791 << " created this file. For more info see http://www.lyx.org/"
2794 Paragraph::depth_type depth = 0; // paragraph depth
2795 Paragraph * par = &*(paragraphs.begin());
2797 vector<string> environment_stack(5);
2800 LyXLayout_ptr const & style = par->layout();
2801 // treat <toc> as a special case for compatibility with old code
2802 if (par->isInset(0)) {
2803 Inset * inset = par->getInset(0);
2804 Inset::Code lyx_code = inset->lyxCode();
2805 if (lyx_code == Inset::TOC_CODE) {
2806 string const temp = "toc";
2807 sgmlOpenTag(ofs, depth, false, temp);
2814 // environment tag closing
2815 for (; depth > par->params().depth(); --depth) {
2816 sgmlCloseTag(ofs, depth, false, environment_stack[depth]);
2817 environment_stack[depth].erase();
2820 // write opening SGML tags
2821 switch (style->latextype) {
2822 case LATEX_PARAGRAPH:
2823 if (depth == par->params().depth()
2824 && !environment_stack[depth].empty()) {
2825 sgmlCloseTag(ofs, depth, false, environment_stack[depth]);
2826 environment_stack[depth].erase();
2832 sgmlOpenTag(ofs, depth, false, style->latexname());
2838 _("Error : Wrong depth for"
2839 " LatexType Command.\n"));
2841 if (!environment_stack[depth].empty()) {
2842 sgmlCloseTag(ofs, depth, false, environment_stack[depth]);
2846 environment_stack[depth].erase();
2847 sgmlOpenTag(ofs, depth, false, style->latexname());
2850 case LATEX_ENVIRONMENT:
2851 case LATEX_ITEM_ENVIRONMENT:
2853 string const & latexname = style->latexname();
2855 if (depth == par->params().depth()
2856 && environment_stack[depth] != latexname) {
2857 sgmlCloseTag(ofs, depth, false,
2858 environment_stack[depth]);
2859 environment_stack[depth].erase();
2861 if (depth < par->params().depth()) {
2862 depth = par->params().depth();
2863 environment_stack[depth].erase();
2865 if (environment_stack[depth] != latexname) {
2867 sgmlOpenTag(ofs, depth, false, "p");
2869 sgmlOpenTag(ofs, depth, false, latexname);
2871 if (environment_stack.size() == depth + 1)
2872 environment_stack.push_back("!-- --");
2873 environment_stack[depth] = latexname;
2876 if (style->latexparam() == "CDATA")
2879 if (style->latextype == LATEX_ENVIRONMENT) break;
2881 if (style->labeltype == LABEL_MANUAL)
2886 sgmlOpenTag(ofs, depth + 1, false, item_name);
2891 sgmlOpenTag(ofs, depth, false, style->latexname());
2895 simpleLinuxDocOnePar(ofs, par, depth);
2900 // write closing SGML tags
2901 switch (style->latextype) {
2904 case LATEX_ENVIRONMENT:
2905 case LATEX_ITEM_ENVIRONMENT:
2906 if (style->latexparam() == "CDATA")
2910 sgmlCloseTag(ofs, depth, false, style->latexname());
2916 for (int i = depth; i >= 0; --i)
2917 sgmlCloseTag(ofs, depth, false, environment_stack[i]);
2921 sgmlCloseTag(ofs, 0, false, top_element);
2925 // How to check for successful close
2927 // we want this to be true outside previews (for insetexternal)
2932 // checks, if newcol chars should be put into this line
2933 // writes newline, if necessary.
2936 void sgmlLineBreak(ostream & os, string::size_type & colcount,
2937 string::size_type newcol)
2940 if (colcount > lyxrc.ascii_linelen) {
2942 colcount = newcol; // assume write after this call
2957 string tag_name(PAR_TAG const & pt) {
2959 case NONE: return "!-- --";
2960 case TT: return "tt";
2961 case SF: return "sf";
2962 case BF: return "bf";
2963 case IT: return "it";
2964 case SL: return "sl";
2965 case EM: return "em";
2972 void operator|=(PAR_TAG & p1, PAR_TAG const & p2)
2974 p1 = static_cast<PAR_TAG>(p1 | p2);
2979 void reset(PAR_TAG & p1, PAR_TAG const & p2)
2981 p1 = static_cast<PAR_TAG>(p1 & ~p2);
2987 // Handle internal paragraph parsing -- layout already processed.
2988 void Buffer::simpleLinuxDocOnePar(ostream & os,
2990 Paragraph::depth_type /*depth*/)
2992 LyXLayout_ptr const & style = par->layout();
2994 string::size_type char_line_count = 5; // Heuristic choice ;-)
2996 // gets paragraph main font
2999 if (style->labeltype == LABEL_MANUAL) {
3000 font_old = style->labelfont;
3003 font_old = style->font;
3007 LyXFont::FONT_FAMILY family_type = LyXFont::ROMAN_FAMILY;
3008 LyXFont::FONT_SERIES series_type = LyXFont::MEDIUM_SERIES;
3009 LyXFont::FONT_SHAPE shape_type = LyXFont::UP_SHAPE;
3012 stack<PAR_TAG> tag_state;
3013 // parsing main loop
3014 for (pos_type i = 0; i < par->size(); ++i) {
3016 PAR_TAG tag_close = NONE;
3017 list < PAR_TAG > tag_open;
3019 LyXFont const font = par->getFont(params, i);
3021 if (font_old.family() != font.family()) {
3022 switch (family_type) {
3023 case LyXFont::SANS_FAMILY:
3026 case LyXFont::TYPEWRITER_FAMILY:
3033 family_type = font.family();
3035 switch (family_type) {
3036 case LyXFont::SANS_FAMILY:
3037 tag_open.push_back(SF);
3039 case LyXFont::TYPEWRITER_FAMILY:
3040 tag_open.push_back(TT);
3047 if (font_old.series() != font.series()) {
3048 switch (series_type) {
3049 case LyXFont::BOLD_SERIES:
3056 series_type = font.series();
3058 switch (series_type) {
3059 case LyXFont::BOLD_SERIES:
3060 tag_open.push_back(BF);
3068 if (font_old.shape() != font.shape()) {
3069 switch (shape_type) {
3070 case LyXFont::ITALIC_SHAPE:
3073 case LyXFont::SLANTED_SHAPE:
3080 shape_type = font.shape();
3082 switch (shape_type) {
3083 case LyXFont::ITALIC_SHAPE:
3084 tag_open.push_back(IT);
3086 case LyXFont::SLANTED_SHAPE:
3087 tag_open.push_back(SL);
3094 if (font_old.emph() != font.emph()) {
3095 if (font.emph() == LyXFont::ON) {
3096 tag_open.push_back(EM);
3105 list < PAR_TAG > temp;
3106 while (!tag_state.empty() && tag_close) {
3107 PAR_TAG k = tag_state.top();
3109 os << "</" << tag_name(k) << ">";
3116 for(list< PAR_TAG >::const_iterator j = temp.begin();
3117 j != temp.end(); ++j) {
3119 os << "<" << tag_name(*j) << ">";
3122 for(list< PAR_TAG >::const_iterator j = tag_open.begin();
3123 j != tag_open.end(); ++j) {
3125 os << "<" << tag_name(*j) << ">";
3128 char c = par->getChar(i);
3130 if (c == Paragraph::META_INSET) {
3131 Inset * inset = par->getInset(i);
3132 inset->linuxdoc(this, os);
3137 if (style->latexparam() == "CDATA") {
3138 // "TeX"-Mode on == > SGML-Mode on.
3145 boost::tie(ws, str) = sgml::escapeChar(c);
3146 if (ws && !style->free_spacing && !par->isFreeSpacing()) {
3147 // in freespacing mode, spaces are
3148 // non-breaking characters
3149 if (desc_on) {// if char is ' ' then...
3152 sgmlLineBreak(os, char_line_count, 6);
3156 sgmlLineBreak(os, char_line_count, 1);
3161 char_line_count += str.length();
3167 while (!tag_state.empty()) {
3168 os << "</" << tag_name(tag_state.top()) << ">";
3172 // resets description flag correctly
3174 // <tag> not closed...
3175 sgmlLineBreak(os, char_line_count, 6);
3181 // Print an error message.
3182 void Buffer::sgmlError(Paragraph * /*par*/, int /*pos*/,
3183 string const & /*message*/) const
3185 #ifdef WITH_WARNINGS
3186 #warning This is wrong we cannot insert an inset like this!!!
3187 // I guess this was Jose' so I explain you more or less why this
3188 // is wrong. This way you insert something in the paragraph and
3189 // don't tell it to LyXText (row rebreaking and undo handling!!!)
3190 // I deactivate this code, have a look at BufferView::insertErrors
3191 // how you should do this correctly! (Jug 20020315)
3194 // insert an error marker in text
3195 InsetError * new_inset = new InsetError(message);
3196 par->insertInset(pos, new_inset, LyXFont(LyXFont::ALL_INHERIT,
3202 void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
3204 ofstream ofs(fname.c_str());
3206 Alert::alert(_("LYX_ERROR:"), _("Cannot write file"), fname);
3210 Paragraph * par = &*(paragraphs.begin());
3212 niceFile = nice; // this will be used by Insetincludes.
3214 LaTeXFeatures features(params);
3219 LyXTextClass const & tclass = params.getLyXTextClass();
3220 string top_element = tclass.latexname();
3223 ofs << "<!DOCTYPE " << top_element
3224 << " PUBLIC \"-//OASIS//DTD DocBook V4.1//EN\"";
3226 string preamble = params.preamble;
3227 const string name = nice ? ChangeExtension(filename_, ".sgml")
3229 preamble += features.getIncludedFiles(name);
3230 preamble += features.getLyXSGMLEntities();
3232 if (!preamble.empty()) {
3233 ofs << "\n [ " << preamble << " ]";
3238 string top = top_element;
3240 top += params.language->code();
3243 if (!params.options.empty()) {
3245 top += params.options;
3247 sgmlOpenTag(ofs, 0, false, top);
3249 ofs << "<!-- DocBook file was created by " << lyx_docversion
3250 << "\n See http://www.lyx.org/ for more information -->\n";
3252 vector<string> environment_stack(10);
3253 vector<string> environment_inner(10);
3254 vector<string> command_stack(10);
3256 bool command_flag = false;
3257 Paragraph::depth_type command_depth = 0;
3258 Paragraph::depth_type command_base = 0;
3259 Paragraph::depth_type cmd_depth = 0;
3260 Paragraph::depth_type depth = 0; // paragraph depth
3263 string command_name;
3269 int desc_on = 0; // description mode
3271 LyXLayout_ptr const & style = par->layout();
3273 // environment tag closing
3274 for (; depth > par->params().depth(); --depth) {
3275 if (environment_inner[depth] != "!-- --") {
3276 item_name = "listitem";
3277 sgmlCloseTag(ofs, command_depth + depth, false, item_name);
3278 if (environment_inner[depth] == "varlistentry")
3279 sgmlCloseTag(ofs, depth+command_depth, false, environment_inner[depth]);
3281 sgmlCloseTag(ofs, depth + command_depth, false, environment_stack[depth]);
3282 environment_stack[depth].erase();
3283 environment_inner[depth].erase();
3286 if (depth == par->params().depth()
3287 && environment_stack[depth] != style->latexname()
3288 && !environment_stack[depth].empty()) {
3289 if (environment_inner[depth] != "!-- --") {
3290 item_name= "listitem";
3291 sgmlCloseTag(ofs, command_depth+depth, false, item_name);
3292 if (environment_inner[depth] == "varlistentry")
3293 sgmlCloseTag(ofs, depth + command_depth, false, environment_inner[depth]);
3296 sgmlCloseTag(ofs, depth + command_depth, false, environment_stack[depth]);
3298 environment_stack[depth].erase();
3299 environment_inner[depth].erase();
3302 // Write opening SGML tags.
3303 switch (style->latextype) {
3304 case LATEX_PARAGRAPH:
3305 sgmlOpenTag(ofs, depth + command_depth,
3306 false, style->latexname());
3312 _("Error : Wrong depth for "
3313 "LatexType Command.\n"));
3315 command_name = style->latexname();
3317 sgmlparam = style->latexparam();
3318 c_params = split(sgmlparam, c_depth,'|');
3320 cmd_depth = lyx::atoi(c_depth);
3323 if (cmd_depth < command_base) {
3324 for (Paragraph::depth_type j = command_depth;
3325 j >= command_base; --j) {
3326 sgmlCloseTag(ofs, j, false, command_stack[j]);
3329 command_depth = command_base = cmd_depth;
3330 } else if (cmd_depth <= command_depth) {
3331 for (int j = command_depth;
3332 j >= int(cmd_depth); --j) {
3333 sgmlCloseTag(ofs, j, false, command_stack[j]);
3336 command_depth = cmd_depth;
3338 command_depth = cmd_depth;
3340 command_depth = command_base = cmd_depth;
3341 command_flag = true;
3343 if (command_stack.size() == command_depth + 1)
3344 command_stack.push_back(string());
3345 command_stack[command_depth] = command_name;
3347 // treat label as a special case for
3348 // more WYSIWYM handling.
3349 // This is a hack while paragraphs can't have
3350 // attributes, like id in this case.
3351 if (par->isInset(0)) {
3352 Inset * inset = par->getInset(0);
3353 Inset::Code lyx_code = inset->lyxCode();
3354 if (lyx_code == Inset::LABEL_CODE) {
3355 command_name += " id=\"";
3356 command_name += (static_cast<InsetCommand *>(inset))->getContents();
3357 command_name += "\"";
3362 sgmlOpenTag(ofs, depth + command_depth, false, command_name);
3364 item_name = c_params.empty()?"title":c_params;
3365 sgmlOpenTag(ofs, depth + 1 + command_depth, false, item_name);
3368 case LATEX_ENVIRONMENT:
3369 case LATEX_ITEM_ENVIRONMENT:
3370 if (depth < par->params().depth()) {
3371 depth = par->params().depth();
3372 environment_stack[depth].erase();
3375 if (environment_stack[depth] != style->latexname()) {
3376 if (environment_stack.size() == depth + 1) {
3377 environment_stack.push_back("!-- --");
3378 environment_inner.push_back("!-- --");
3380 environment_stack[depth] = style->latexname();
3381 environment_inner[depth] = "!-- --";
3382 sgmlOpenTag(ofs, depth + command_depth, false, environment_stack[depth]);
3384 if (environment_inner[depth] != "!-- --") {
3385 item_name= "listitem";
3386 sgmlCloseTag(ofs, command_depth + depth, false, item_name);
3387 if (environment_inner[depth] == "varlistentry")
3388 sgmlCloseTag(ofs, depth + command_depth, false, environment_inner[depth]);
3392 if (style->latextype == LATEX_ENVIRONMENT) {
3393 if (!style->latexparam().empty()) {
3394 if (style->latexparam() == "CDATA")
3397 sgmlOpenTag(ofs, depth + command_depth, false, style->latexparam());
3402 desc_on = (style->labeltype == LABEL_MANUAL);
3404 environment_inner[depth] = desc_on ? "varlistentry" : "listitem";
3405 sgmlOpenTag(ofs, depth + 1 + command_depth,
3406 false, environment_inner[depth]);
3408 item_name = desc_on ? "term" : "para";
3409 sgmlOpenTag(ofs, depth + 1 + command_depth,
3413 sgmlOpenTag(ofs, depth + command_depth,
3414 false, style->latexname());
3418 simpleDocBookOnePar(ofs, par, desc_on,
3419 depth + 1 + command_depth);
3423 // write closing SGML tags
3424 switch (style->latextype) {
3426 end_tag = c_params.empty() ? "title" : c_params;
3427 sgmlCloseTag(ofs, depth + command_depth,
3430 case LATEX_ENVIRONMENT:
3431 if (!style->latexparam().empty()) {
3432 if (style->latexparam() == "CDATA")
3435 sgmlCloseTag(ofs, depth + command_depth, false, style->latexparam());
3438 case LATEX_ITEM_ENVIRONMENT:
3439 if (desc_on == 1) break;
3441 sgmlCloseTag(ofs, depth + 1 + command_depth, false, end_tag);
3443 case LATEX_PARAGRAPH:
3444 sgmlCloseTag(ofs, depth + command_depth, false, style->latexname());
3447 sgmlCloseTag(ofs, depth + command_depth, false, style->latexname());
3453 for (int d = depth; d >= 0; --d) {
3454 if (!environment_stack[depth].empty()) {
3455 if (environment_inner[depth] != "!-- --") {
3456 item_name = "listitem";
3457 sgmlCloseTag(ofs, command_depth + depth, false, item_name);
3458 if (environment_inner[depth] == "varlistentry")
3459 sgmlCloseTag(ofs, depth + command_depth, false, environment_inner[depth]);
3462 sgmlCloseTag(ofs, depth + command_depth, false, environment_stack[depth]);
3466 for (int j = command_depth; j >= 0 ; --j)
3467 if (!command_stack[j].empty()) {
3468 sgmlCloseTag(ofs, j, false, command_stack[j]);
3473 sgmlCloseTag(ofs, 0, false, top_element);
3476 // How to check for successful close
3478 // we want this to be true outside previews (for insetexternal)
3483 void Buffer::simpleDocBookOnePar(ostream & os,
3484 Paragraph * par, int & desc_on,
3485 Paragraph::depth_type depth) const
3487 bool emph_flag = false;
3489 LyXLayout_ptr const & style = par->layout();
3491 LyXFont font_old = (style->labeltype == LABEL_MANUAL ? style->labelfont : style->font);
3493 int char_line_count = depth;
3494 //if (!style.free_spacing)
3495 // os << string(depth,' ');
3497 // parsing main loop
3498 for (pos_type i = 0; i < par->size(); ++i) {
3499 LyXFont font = par->getFont(params, i);
3501 // handle <emphasis> tag
3502 if (font_old.emph() != font.emph()) {
3503 if (font.emph() == LyXFont::ON) {
3504 if (style->latexparam() == "CDATA")
3507 if (style->latexparam() == "CDATA")
3511 if (style->latexparam() == "CDATA")
3513 os << "</emphasis>";
3514 if (style->latexparam() == "CDATA")
3521 if (par->isInset(i)) {
3522 Inset * inset = par->getInset(i);
3523 // don't print the inset in position 0 if desc_on == 3 (label)
3524 if (i || desc_on != 3) {
3525 if (style->latexparam() == "CDATA")
3527 inset->docbook(this, os, false);
3528 if (style->latexparam() == "CDATA")
3532 char c = par->getChar(i);
3535 boost::tie(ws, str) = sgml::escapeChar(c);
3537 if (style->pass_thru) {
3539 } else if (style->free_spacing || par->isFreeSpacing() || c != ' ') {
3541 } else if (desc_on ==1) {
3543 os << "\n</term><listitem><para>";
3553 if (style->latexparam() == "CDATA")
3555 os << "</emphasis>";
3556 if (style->latexparam() == "CDATA")
3560 // resets description flag correctly
3562 // <term> not closed...
3563 os << "</term>\n<listitem><para> </para>";
3565 if (style->free_spacing)
3570 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
3571 // Other flags: -wall -v0 -x
3572 int Buffer::runChktex()
3574 if (!users->text) return 0;
3576 users->owner()->prohibitInput();
3578 // get LaTeX-Filename
3579 string const name = getLatexName();
3580 string path = filePath();
3582 string const org_path = path;
3583 if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
3587 Path p(path); // path to LaTeX file
3588 users->owner()->message(_("Running chktex..."));
3590 // Remove all error insets
3591 bool const removedErrorInsets = users->removeAutoInsets();
3593 // Generate the LaTeX file if neccessary
3594 makeLaTeXFile(name, org_path, false);
3597 Chktex chktex(lyxrc.chktex_command, name, filePath());
3598 int res = chktex.run(terr); // run chktex
3601 Alert::alert(_("chktex did not work!"),
3602 _("Could not run with file:"), name);
3603 } else if (res > 0) {
3604 // Insert all errors as errors boxes
3605 users->insertErrors(terr);
3608 // if we removed error insets before we ran chktex or if we inserted
3609 // error insets after we ran chktex, this must be run:
3610 if (removedErrorInsets || res) {
3611 #warning repaint needed here, or do you mean update() ?
3615 users->owner()->allowInput();
3621 void Buffer::validate(LaTeXFeatures & features) const
3623 Paragraph * par = &*(paragraphs.begin());
3624 LyXTextClass const & tclass = params.getLyXTextClass();
3626 // AMS Style is at document level
3627 if (params.use_amsmath || tclass.provides(LyXTextClass::amsmath))
3628 features.require("amsmath");
3631 // We don't use "lyxerr.debug" because of speed. (Asger)
3632 if (lyxerr.debugging(Debug::LATEX))
3633 lyxerr << "Paragraph: " << par << endl;
3635 // Now just follow the list of paragraphs and run
3636 // validate on each of them.
3637 par->validate(features);
3639 // and then the next paragraph
3643 // the bullet shapes are buffer level not paragraph level
3644 // so they are tested here
3645 for (int i = 0; i < 4; ++i) {
3646 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
3647 int const font = params.user_defined_bullets[i].getFont();
3649 int const c = params
3650 .user_defined_bullets[i]
3657 features.require("latexsym");
3659 } else if (font == 1) {
3660 features.require("amssymb");
3661 } else if ((font >= 2 && font <= 5)) {
3662 features.require("pifont");
3667 if (lyxerr.debugging(Debug::LATEX)) {
3668 features.showStruct();
3673 // This function should be in Buffer because it's a buffer's property (ale)
3674 string const Buffer::getIncludeonlyList(char delim)
3677 for (inset_iterator it = inset_iterator_begin();
3678 it != inset_iterator_end(); ++it) {
3679 if ((*it)->lyxCode() == Inset::INCLUDE_CODE) {
3680 InsetInclude * insetinc =
3681 static_cast<InsetInclude *>(*it);
3682 if (insetinc->isIncludeOnly()) {
3685 lst += insetinc->getRelFileBaseName();
3689 lyxerr[Debug::INFO] << "Includeonly(" << lst << ')' << endl;
3694 vector<string> const Buffer::getLabelList()
3696 /// if this is a child document and the parent is already loaded
3697 /// Use the parent's list instead [ale990407]
3698 if (!params.parentname.empty()
3699 && bufferlist.exists(params.parentname)) {
3700 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3702 return tmp->getLabelList();
3705 vector<string> label_list;
3706 for (inset_iterator it = inset_iterator_begin();
3707 it != inset_iterator_end(); ++it) {
3708 vector<string> const l = (*it)->getLabelList();
3709 label_list.insert(label_list.end(), l.begin(), l.end());
3715 // This is also a buffer property (ale)
3716 vector<pair<string, string> > const Buffer::getBibkeyList() const
3718 typedef pair<string, string> StringPair;
3719 /// if this is a child document and the parent is already loaded
3720 /// Use the parent's list instead [ale990412]
3721 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3722 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
3724 return tmp->getBibkeyList();
3727 vector<StringPair> keys;
3728 Paragraph * par = &*(paragraphs.begin());
3731 string const key = par->bibkey->getContents();
3732 string const opt = par->bibkey->getOptions();
3733 string const ref = par->asString(this, false);
3734 string const info = opt + "TheBibliographyRef" + ref;
3736 keys.push_back(StringPair(key, info));
3741 // Might be either using bibtex or a child has bibliography
3743 for (inset_iterator it = inset_const_iterator_begin();
3744 it != inset_const_iterator_end(); ++it) {
3745 // Search for Bibtex or Include inset
3746 if ((*it)->lyxCode() == Inset::BIBTEX_CODE) {
3747 vector<StringPair> tmp =
3748 static_cast<InsetBibtex*>(*it)->getKeys(this);
3749 keys.insert(keys.end(), tmp.begin(), tmp.end());
3750 } else if ((*it)->lyxCode() == Inset::INCLUDE_CODE) {
3751 vector<StringPair> const tmp =
3752 static_cast<InsetInclude*>(*it)->getKeys();
3753 keys.insert(keys.end(), tmp.begin(), tmp.end());
3762 bool Buffer::isDepClean(string const & name) const
3764 DEPCLEAN * item = dep_clean;
3765 while (item && item->master != name)
3767 if (!item) return true;
3772 void Buffer::markDepClean(string const & name)
3775 dep_clean = new DEPCLEAN;
3776 dep_clean->clean = true;
3777 dep_clean->master = name;
3778 dep_clean->next = 0;
3780 DEPCLEAN * item = dep_clean;
3781 while (item && item->master != name)
3786 item = new DEPCLEAN;
3788 item->master = name;
3795 bool Buffer::dispatch(string const & command, bool * result)
3797 // Split command string into command and argument
3799 string line = ltrim(command);
3800 string const arg = trim(split(line, cmd, ' '));
3802 return dispatch(lyxaction.LookupFunc(cmd), arg, result);
3806 bool Buffer::dispatch(int action, string const & argument, bool * result)
3808 bool dispatched = true;
3812 bool const tmp = Exporter::Export(this, argument, false);
3825 void Buffer::resizeInsets(BufferView * bv)
3827 /// then remove all LyXText in text-insets
3828 Paragraph * par = &*(paragraphs.begin());
3829 for (; par; par = par->next()) {
3830 par->resizeInsetsLyXText(bv);
3835 void Buffer::redraw()
3837 #warning repaint needed here, or do you mean update() ?
3843 void Buffer::changeLanguage(Language const * from, Language const * to)
3846 ParIterator end = par_iterator_end();
3847 for (ParIterator it = par_iterator_begin(); it != end; ++it)
3848 (*it)->changeLanguage(params, from, to);
3852 bool Buffer::isMultiLingual()
3854 ParIterator end = par_iterator_end();
3855 for (ParIterator it = par_iterator_begin(); it != end; ++it)
3856 if ((*it)->isMultiLingual(params))
3863 Buffer::inset_iterator::inset_iterator(Paragraph * paragraph, pos_type pos)
3866 it = par->insetlist.insetIterator(pos);
3867 if (it == par->insetlist.end()) {
3874 void Buffer::inset_iterator::setParagraph()
3877 it = par->insetlist.begin();
3878 if (it != par->insetlist.end())
3883 // We maintain an invariant that whenever par = 0 then it = 0
3887 Inset * Buffer::getInsetFromID(int id_arg) const
3889 for (inset_iterator it = inset_const_iterator_begin();
3890 it != inset_const_iterator_end(); ++it)
3892 if ((*it)->id() == id_arg)
3894 Inset * in = (*it)->getInsetFromID(id_arg);
3902 Paragraph * Buffer::getParFromID(int id) const
3904 if (id < 0) return 0;
3905 Paragraph * par = &*(paragraphs.begin());
3907 if (par->id() == id) {
3910 Paragraph * tmp = par->getParFromID(id);
3920 ParIterator Buffer::par_iterator_begin()
3922 return ParIterator(&*(paragraphs.begin()));
3926 ParIterator Buffer::par_iterator_end()
3928 return ParIterator();