1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2001 The LyX Team.
9 * This file is Copyright 1996-2001
12 * ======================================================
18 #pragma implementation
22 #include "bufferlist.h"
24 #include "LyXAction.h"
27 #include "tex-strings.h"
29 #include "bufferview_funcs.h"
34 #include "frontends/LyXView.h"
36 #include "LaTeXFeatures.h"
43 #include "converter.h"
44 #include "BufferView.h"
45 #include "ParagraphParameters.h"
46 #include "iterators.h"
47 #include "lyxtextclasslist.h"
49 #include "mathed/formulamacro.h"
50 #include "mathed/formula.h"
52 #include "insets/inset.h"
53 #include "insets/inseterror.h"
54 #include "insets/insetlabel.h"
55 #include "insets/insetref.h"
56 #include "insets/inseturl.h"
57 #include "insets/insetnote.h"
58 #include "insets/insetquotes.h"
59 #include "insets/insetlatexaccent.h"
60 #include "insets/insetbib.h"
61 #include "insets/insetcite.h"
62 #include "insets/insetexternal.h"
63 #include "insets/insetindex.h"
64 #include "insets/insetinclude.h"
65 #include "insets/insettoc.h"
66 #include "insets/insetparent.h"
67 #include "insets/insetspecialchar.h"
68 #include "insets/insettext.h"
69 #include "insets/insetert.h"
70 #include "insets/insetgraphics.h"
71 #include "insets/insetfoot.h"
72 #include "insets/insetmarginal.h"
73 #include "insets/insetminipage.h"
74 #include "insets/insetfloat.h"
75 #include "insets/insettabular.h"
77 #include "insets/insettheorem.h"
78 #include "insets/insetlist.h"
80 #include "insets/insetcaption.h"
81 #include "insets/insetfloatlist.h"
83 #include "frontends/Dialogs.h"
84 #include "frontends/Alert.h"
86 #include "support/textutils.h"
87 #include "support/filetools.h"
88 #include "support/path.h"
89 #include "support/os.h"
90 #include "support/lyxlib.h"
91 #include "support/FileInfo.h"
92 #include "support/lyxmanip.h"
93 #include "support/lyxalgo.h" // for lyx::count
105 #include <sys/types.h>
113 #ifndef CXX_GLOBAL_CSTD
125 using std::make_pair;
134 using lyx::textclass_type;
136 // all these externs should eventually be removed.
137 extern BufferList bufferlist;
139 extern LyXAction lyxaction;
143 const int LYX_FORMAT = 220;
147 extern int tex_code_break_column;
150 Buffer::Buffer(string const & file, bool ronly)
151 : paragraph(0), niceFile(true), lyx_clean(true), bak_clean(true),
152 unnamed(false), dep_clean(0), read_only(ronly),
153 filename_(file), users(0)
155 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
157 filepath_ = OnlyPath(file);
162 // read_only = ronly;
166 if (read_only || lyxrc.use_tempdir) {
167 tmppath = CreateBufferTmpDir();
176 lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
177 // here the buffer should take care that it is
178 // saved properly, before it goes into the void.
180 // make sure that views using this buffer
185 if (!tmppath.empty()) {
186 DestroyBufferTmpDir(tmppath);
189 Paragraph * par = paragraph;
192 tmppar = par->next();
200 string const Buffer::getLatexName(bool no_path) const
202 string const name = ChangeExtension(MakeLatexName(fileName()), ".tex");
204 return OnlyFilename(name);
210 pair<Buffer::LogType, string> const Buffer::getLogName(void) const
212 string const filename = getLatexName(false);
214 if (filename.empty())
215 return make_pair(Buffer::latexlog, string());
217 string path = OnlyPath(filename);
219 if (lyxrc.use_tempdir || !IsDirWriteable(path))
222 string const fname = AddName(path,
223 OnlyFilename(ChangeExtension(filename,
226 AddName(path, OnlyFilename(
227 ChangeExtension(filename,
228 formats.extension("literate") + ".out")));
230 // If no Latex log or Build log is newer, show Build log
232 FileInfo const f_fi(fname);
233 FileInfo const b_fi(bname);
236 (!f_fi.exist() || f_fi.getModificationTime() < b_fi.getModificationTime())) {
237 lyxerr[Debug::FILES] << "Log name calculated as : " << bname << endl;
238 return make_pair(Buffer::buildlog, bname);
240 lyxerr[Debug::FILES] << "Log name calculated as : " << fname << endl;
241 return make_pair(Buffer::latexlog, fname);
245 void Buffer::setReadonly(bool flag)
247 if (read_only != flag) {
250 users->owner()->getDialogs()->updateBufferDependent(false);
255 /// Update window titles of all users
256 // Should work on a list
257 void Buffer::updateTitles() const
260 users->owner()->updateWindowTitle();
264 /// Reset autosave timer of all users
265 // Should work on a list
266 void Buffer::resetAutosaveTimers() const
269 users->owner()->resetAutosaveTimer();
273 void Buffer::setFileName(string const & newfile)
275 filename_ = MakeAbsPath(newfile);
276 filepath_ = OnlyPath(filename_);
277 setReadonly(IsFileWriteable(filename_) == 0);
282 // We'll remove this later. (Lgb)
285 string last_inset_read;
287 #ifndef NO_COMPABILITY
290 ErtComp() : active(false), fromlayout(false), in_tabular(false) {
299 std::stack<ErtComp> ert_stack;
304 #warning And _why_ is this here? (Lgb)
312 // candidate for move to BufferView
313 // (at least some parts in the beginning of the func)
316 // changed to be public and have one parameter
317 // if par = 0 normal behavior
318 // else insert behavior
319 // Returns false if "\the_end" is not read for formats >= 2.13. (Asger)
320 bool Buffer::readLyXformat2(LyXLex & lex, Paragraph * par)
324 #ifndef NO_COMPABILITY
325 ert_comp.contents.erase();
326 ert_comp.active = false;
327 ert_comp.fromlayout = false;
328 ert_comp.in_tabular = false;
331 Paragraph::depth_type depth = 0;
332 bool the_end_read = false;
334 Paragraph * first_par = 0;
335 LyXFont font(LyXFont::ALL_INHERIT, params.language);
338 if (file_format < 216 && params.language->lang() == "hebrew")
339 font.setLanguage(default_language);
344 par->layout(textclasslist[params.textclass].defaultLayoutName());
346 // We are inserting into an existing document
347 users->text->breakParagraph(users);
348 first_par = users->text->ownerParagraph();
351 // We don't want to adopt the parameters from the
352 // document we insert, so we skip until the text begins:
355 string const pretoken = lex.getString();
356 if (pretoken == "\\layout") {
357 lex.pushToken(pretoken);
365 string const token = lex.getString();
367 if (token.empty()) continue;
369 lyxerr[Debug::PARSER] << "Handling token: `"
370 << token << "'" << endl;
373 parseSingleLyXformat2Token(lex, par, first_par,
381 paragraph = first_par;
383 if (unknown_layouts > 0) {
384 string s = _("Couldn't set the layout for ");
385 if (unknown_layouts == 1) {
386 s += _("one paragraph");
388 s += tostr(unknown_layouts);
389 s += _(" paragraphs");
391 Alert::alert(_("Textclass Loading Error!"), s,
392 _("When reading " + fileName()));
395 if (unknown_tokens > 0) {
396 string s = _("Encountered ");
397 if (unknown_tokens == 1) {
398 s += _("one unknown token");
400 s += tostr(unknown_tokens);
401 s += _(" unknown tokens");
403 Alert::alert(_("Textclass Loading Error!"), s,
404 _("When reading " + fileName()));
411 #ifndef NO_COMPABILITY
413 Inset * Buffer::isErtInset(Paragraph * par, int pos) const
416 if ((par->getChar(pos) == Paragraph::META_INSET) &&
417 (inset = par->getInset(pos)) &&
418 (inset->lyxCode() == Inset::ERT_CODE))
425 void Buffer::insertErtContents(Paragraph * par, int & pos, bool set_inactive)
427 if (ert_comp.contents.find_first_not_of(' ') != string::npos) {
428 // we only skip completely empty ERT (only spaces) otherwise
429 // we have to insert it as is.
430 string str(ert_comp.contents);
431 lyxerr[Debug::INSETS] << "ERT contents:\n'"
432 << str << "'" << endl;
433 // check if we have already an ert inset a position earlier
434 // if this is the case then we should insert the contents
435 // inside the other ertinset as it is stupid to have various
438 if ((pos > 0) && (inset=isErtInset(par, pos-1))) {
439 // get the last paragraph from the inset before
440 Paragraph * last = inset->firstParagraph();
443 // create the new paragraph after the last one
444 Paragraph * par = new Paragraph(last);
445 par->layout(textclasslist[params.textclass].defaultLayoutName());
446 par->setInsetOwner(last->inInset());
448 LyXFont font(LyXFont::ALL_INHERIT, params.language);
449 string::const_iterator cit = str.begin();
450 string::const_iterator end = str.end();
452 for (; cit != end; ++cit) {
453 par->insertChar(pos++, *cit, font);
457 new InsetERT(params, params.language, str, true);
458 par->insertInset(pos++, inset, ert_comp.font);
461 ert_comp.contents.erase();
462 ert_comp.fromlayout = false;
464 ert_comp.active = false;
471 Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
472 Paragraph *& first_par,
473 string const & token, int & pos,
474 Paragraph::depth_type & depth,
478 bool the_end_read = false;
479 #ifndef NO_COMPABILITY
480 #ifndef NO_PEXTRA_REALLY
481 // This is super temporary but is needed to get the compability
482 // mode for minipages work correctly together with new tabulars.
483 static int call_depth;
485 bool checkminipage = false;
486 static Paragraph * minipar = 0;
487 static Paragraph * parBeforeMinipage;
491 // The order of the tags tested may seem unnatural, but this
492 // has been done in order to reduce the number of string
493 // comparisons needed to recognize a given token. This leads
494 // on large documents like UserGuide to a reduction of a
496 if (token[0] != '\\') {
497 #ifndef NO_COMPABILITY
498 if (ert_comp.active) {
499 ert_comp.contents += token;
502 for (string::const_iterator cit = token.begin();
503 cit != token.end(); ++cit) {
504 par->insertChar(pos, (*cit), font);
507 #ifndef NO_COMPABILITY
510 } else if (token == "\\layout") {
511 #ifndef NO_COMPABILITY
512 bool old_fromlayout = ert_comp.fromlayout;
513 bool create_new_par = true;
514 ert_comp.in_tabular = false;
516 if (!par->size() && par->previous() &&
517 (par->previous()->size() == 1) &&
518 isErtInset(par->previous(), par->previous()->size()-1))
520 int p = par->previous()->size();
521 insertErtContents(par->previous(), p);
522 create_new_par = false;
524 insertErtContents(par, pos);
527 // reset the font as we start a new layout and if the font is
528 // not ALL_INHERIT,document_language then it will be set to the
529 // right values after this tag (Jug 20020420)
530 font = LyXFont(LyXFont::ALL_INHERIT, params.language);
533 if (file_format < 216 && params.language->lang() == "hebrew")
534 font.setLanguage(default_language);
538 string layoutname = lex.getString();
540 LyXTextClass const & tclass = textclasslist[params.textclass];
542 if (layoutname.empty()) {
543 layoutname = tclass.defaultLayoutName();
545 #ifndef NO_COMPABILITY
546 if (compare_no_case(layoutname, "latex") == 0) {
547 ert_comp.active = true;
548 ert_comp.fromlayout = true;
549 ert_comp.font = font;
551 create_new_par = false;
554 bool hasLayout = tclass.hasLayout(layoutname);
556 lyxerr << "Layout '" << layoutname << "' does not"
557 << " exist in textclass '" << tclass.name()
559 lyxerr << "Trying to use default layout instead."
561 layoutname = tclass.defaultLayoutName();
565 // The is the compability reading of layout caption.
566 // It can be removed in LyX version 1.3.0. (Lgb)
567 if (compare_no_case(layoutname, "caption") == 0) {
568 // We expect that the par we are now working on is
569 // really inside a InsetText inside a InsetFloat.
570 // We also know that captions can only be
571 // one paragraph. (Lgb)
573 // We should now read until the next "\layout"
575 // This is probably not good enough, what if the
576 // caption is the last par in the document (Lgb)
577 istream & ist = lex.getStream();
583 if (prefixIs(line, "\\layout")) {
587 if (prefixIs(line, "\\begin_inset"))
589 if (prefixIs(line, "\\end_inset")) {
600 // Now we should have the whole layout in ss
601 // we should now be able to give this to the
603 ss << "\\end_inset\n";
605 // This seems like a bug in stringstream.
606 // We really should be able to use ss
608 istringstream is(ss.str());
610 tmplex.setStream(is);
611 Inset * inset = new InsetCaption;
612 inset->Read(this, tmplex);
613 par->InsertInset(pos, inset, font);
617 #ifndef NO_COMPABILITY
618 if (create_new_par) {
623 par = new Paragraph(par);
624 par->layout(textclasslist[params.textclass].defaultLayoutName());
627 par->layout(layoutname);
628 // Test whether the layout is obsolete.
629 LyXLayout const & layout =
630 textclasslist[params.textclass][par->layout()];
631 if (!layout.obsoleted_by().empty())
632 par->layout(layout.obsoleted_by());
633 par->params().depth(depth);
634 #ifndef NO_COMPABILITY
636 // we duplicate code here because it's easier to remove
637 // the code then of NO_COMPATIBILITY
638 par->layout(layoutname);
639 // Test whether the layout is obsolete.
640 LyXLayout const & layout =
641 textclasslist[params.textclass][par->layout()];
642 if (!layout.obsoleted_by().empty())
643 par->layout(layout.obsoleted_by());
644 par->params().depth(depth);
651 } else if (token == "\\end_inset") {
652 lyxerr << "Solitary \\end_inset. Missing \\begin_inset?.\n"
653 << "Last inset read was: " << last_inset_read
655 // Simply ignore this. The insets do not have
657 // But insets should read it, it is a part of
658 // the inset isn't it? Lgb.
659 } else if (token == "\\begin_inset") {
660 #ifndef NO_COMPABILITY
661 insertErtContents(par, pos, false);
662 ert_stack.push(ert_comp);
663 ert_comp = ErtComp();
665 readInset(lex, par, pos, font);
666 #ifndef NO_COMPABILITY
667 ert_comp = ert_stack.top();
669 insertErtContents(par, pos);
671 } else if (token == "\\family") {
673 font.setLyXFamily(lex.getString());
674 } else if (token == "\\series") {
676 font.setLyXSeries(lex.getString());
677 } else if (token == "\\shape") {
679 font.setLyXShape(lex.getString());
680 } else if (token == "\\size") {
682 font.setLyXSize(lex.getString());
683 #ifndef NO_COMPABILITY
684 } else if (token == "\\latex") {
686 string const tok = lex.getString();
687 if (tok == "no_latex") {
689 insertErtContents(par, pos);
690 } else if (tok == "latex") {
691 ert_comp.active = true;
692 ert_comp.font = font;
693 } else if (tok == "default") {
695 insertErtContents(par, pos);
697 lex.printError("Unknown LaTeX font flag "
701 } else if (token == "\\lang") {
703 string const tok = lex.getString();
704 Language const * lang = languages.getLanguage(tok);
706 font.setLanguage(lang);
708 font.setLanguage(params.language);
709 lex.printError("Unknown language `$$Token'");
711 } else if (token == "\\numeric") {
713 font.setNumber(font.setLyXMisc(lex.getString()));
714 } else if (token == "\\emph") {
716 font.setEmph(font.setLyXMisc(lex.getString()));
717 } else if (token == "\\bar") {
719 string const tok = lex.getString();
720 // This is dirty, but gone with LyX3. (Asger)
722 font.setUnderbar(LyXFont::ON);
723 else if (tok == "no")
724 font.setUnderbar(LyXFont::OFF);
725 else if (tok == "default")
726 font.setUnderbar(LyXFont::INHERIT);
728 lex.printError("Unknown bar font flag "
730 } else if (token == "\\noun") {
732 font.setNoun(font.setLyXMisc(lex.getString()));
733 } else if (token == "\\color") {
735 font.setLyXColor(lex.getString());
736 } else if (token == "\\SpecialChar") {
737 LyXLayout const & layout =
738 textclasslist[params.textclass][par->layout()];
740 // Insets don't make sense in a free-spacing context! ---Kayvan
741 if (layout.free_spacing || par->isFreeSpacing()) {
744 string next_token = lex.getString();
745 if (next_token == "\\-") {
746 par->insertChar(pos, '-', font);
747 } else if (next_token == "\\protected_separator"
748 || next_token == "~") {
749 par->insertChar(pos, ' ', font);
751 lex.printError("Token `$$Token' "
753 "paragraph layout!");
758 Inset * inset = new InsetSpecialChar;
759 inset->read(this, lex);
760 par->insertInset(pos, inset, font);
763 } else if (token == "\\i") {
764 Inset * inset = new InsetLatexAccent;
765 inset->read(this, lex);
766 par->insertInset(pos, inset, font);
768 } else if (token == "\\backslash") {
769 #ifndef NO_COMPABILITY
770 if (ert_comp.active) {
771 ert_comp.contents += "\\";
774 par->insertChar(pos, '\\', font);
776 #ifndef NO_COMPABILITY
779 #ifndef NO_COMPABILITY
780 } else if (token == "\\begin_float") {
781 insertErtContents(par, pos);
782 //insertErtContents(par, pos, false);
783 //ert_stack.push(ert_comp);
784 //ert_comp = ErtComp();
786 // This is the compability reader. It can be removed in
787 // LyX version 1.3.0. (Lgb)
789 string const tmptok = lex.getString();
790 //lyxerr << "old float: " << tmptok << endl;
793 stringstream old_float;
795 if (tmptok == "footnote") {
796 inset = new InsetFoot(params);
797 old_float << "collapsed true\n";
798 } else if (tmptok == "margin") {
799 inset = new InsetMarginal(params);
800 old_float << "collapsed true\n";
801 } else if (tmptok == "fig") {
802 inset = new InsetFloat(params, "figure");
803 old_float << "placement htbp\n"
805 << "collapsed false\n";
806 } else if (tmptok == "tab") {
807 inset = new InsetFloat(params, "table");
808 old_float << "placement htbp\n"
810 << "collapsed false\n";
811 } else if (tmptok == "alg") {
812 inset = new InsetFloat(params, "algorithm");
813 old_float << "placement htbp\n"
815 << "collapsed false\n";
816 } else if (tmptok == "wide-fig") {
817 inset = new InsetFloat(params, "figure");
818 //InsetFloat * tmp = new InsetFloat("figure");
821 old_float << "placement htbp\n"
823 << "collapsed false\n";
824 } else if (tmptok == "wide-tab") {
825 inset = new InsetFloat(params, "table");
826 //InsetFloat * tmp = new InsetFloat("table");
829 old_float << "placement htbp\n"
831 << "collapsed false\n";
835 #ifndef NO_PEXTRA_REALLY
838 return false; // no end read yet
841 // Here we need to check for \end_deeper and handle that
842 // before we do the footnote parsing.
843 // This _is_ a hack! (Lgb)
846 string const tmp = lex.getString();
847 if (tmp == "\\end_deeper") {
848 //lyxerr << "\\end_deeper caught!" << endl;
850 lex.printError("\\end_deeper: "
851 "depth is already null");
856 old_float << tmp << ' ';
861 old_float << lex.getLongString("\\end_float")
862 << "\n\\end_inset\n";
863 //lyxerr << "Float Body:\n" << old_float.str() << endl;
864 // That this does not work seems like a bug
865 // in stringstream. (Lgb)
866 istringstream istr(old_float.str());
868 nylex.setStream(istr);
869 inset->read(this, nylex);
870 par->insertInset(pos, inset, font);
872 insertErtContents(par, pos);
874 // we have to reset the font as in the old format after a float
875 // the font was automatically reset!
876 font = LyXFont(LyXFont::ALL_INHERIT, params.language);
878 } else if (token == "\\begin_deeper") {
880 } else if (token == "\\end_deeper") {
882 lex.printError("\\end_deeper: "
883 "depth is already null");
887 } else if (token == "\\begin_preamble") {
888 params.readPreamble(lex);
889 } else if (token == "\\textclass") {
891 pair<bool, textclass_type> pp =
892 textclasslist.NumberOfClass(lex.getString());
894 params.textclass = pp.second;
896 Alert::alert(string(_("Textclass error")),
897 string(_("The document uses an unknown textclass \"")) +
898 lex.getString() + string("\"."),
899 string(_("LyX will not be able to produce output correctly.")));
900 params.textclass = 0;
902 if (!textclasslist[params.textclass].load()) {
903 // if the textclass wasn't loaded properly
904 // we need to either substitute another
905 // or stop loading the file.
906 // I can substitute but I don't see how I can
907 // stop loading... ideas?? ARRae980418
908 Alert::alert(_("Textclass Loading Error!"),
909 string(_("Can't load textclass ")) +
910 textclasslist[params.textclass].name(),
911 _("-- substituting default"));
912 params.textclass = 0;
914 } else if (token == "\\options") {
916 params.options = lex.getString();
917 } else if (token == "\\language") {
918 params.readLanguage(lex);
919 } else if (token == "\\fontencoding") {
921 } else if (token == "\\inputencoding") {
923 params.inputenc = lex.getString();
924 } else if (token == "\\graphics") {
925 params.readGraphicsDriver(lex);
926 } else if (token == "\\fontscheme") {
928 params.fonts = lex.getString();
929 } else if (token == "\\noindent") {
930 par->params().noindent(true);
931 } else if (token == "\\leftindent") {
933 LyXLength value(lex.getString());
934 par->params().leftIndent(value);
935 } else if (token == "\\fill_top") {
936 par->params().spaceTop(VSpace(VSpace::VFILL));
937 } else if (token == "\\fill_bottom") {
938 par->params().spaceBottom(VSpace(VSpace::VFILL));
939 } else if (token == "\\line_top") {
940 par->params().lineTop(true);
941 } else if (token == "\\line_bottom") {
942 par->params().lineBottom(true);
943 } else if (token == "\\pagebreak_top") {
944 par->params().pagebreakTop(true);
945 } else if (token == "\\pagebreak_bottom") {
946 par->params().pagebreakBottom(true);
947 } else if (token == "\\start_of_appendix") {
948 par->params().startOfAppendix(true);
949 } else if (token == "\\paragraph_separation") {
950 int tmpret = lex.findToken(string_paragraph_separation);
953 if (tmpret != LYX_LAYOUT_DEFAULT)
954 params.paragraph_separation =
955 static_cast<BufferParams::PARSEP>(tmpret);
956 } else if (token == "\\defskip") {
958 params.defskip = VSpace(lex.getString());
959 #ifndef NO_COMPABILITY
960 } else if (token == "\\epsfig") { // obsolete
961 // Indeed it is obsolete, but we HAVE to be backwards
962 // compatible until 0.14, because otherwise all figures
963 // in existing documents are irretrivably lost. (Asger)
964 params.readGraphicsDriver(lex);
966 } else if (token == "\\quotes_language") {
967 int tmpret = lex.findToken(string_quotes_language);
970 if (tmpret != LYX_LAYOUT_DEFAULT) {
971 InsetQuotes::quote_language tmpl =
972 InsetQuotes::EnglishQ;
975 tmpl = InsetQuotes::EnglishQ;
978 tmpl = InsetQuotes::SwedishQ;
981 tmpl = InsetQuotes::GermanQ;
984 tmpl = InsetQuotes::PolishQ;
987 tmpl = InsetQuotes::FrenchQ;
990 tmpl = InsetQuotes::DanishQ;
993 params.quotes_language = tmpl;
995 } else if (token == "\\quotes_times") {
997 switch (lex.getInteger()) {
999 params.quotes_times = InsetQuotes::SingleQ;
1002 params.quotes_times = InsetQuotes::DoubleQ;
1005 } else if (token == "\\papersize") {
1006 int tmpret = lex.findToken(string_papersize);
1010 params.papersize2 = tmpret;
1011 } else if (token == "\\paperpackage") {
1012 int tmpret = lex.findToken(string_paperpackages);
1015 params.paperpackage = BufferParams::PACKAGE_NONE;
1017 params.paperpackage = tmpret;
1018 } else if (token == "\\use_geometry") {
1020 params.use_geometry = lex.getInteger();
1021 } else if (token == "\\use_amsmath") {
1023 params.use_amsmath = lex.getInteger();
1024 } else if (token == "\\use_natbib") {
1026 params.use_natbib = lex.getInteger();
1027 } else if (token == "\\use_numerical_citations") {
1029 params.use_numerical_citations = lex.getInteger();
1030 } else if (token == "\\paperorientation") {
1031 int tmpret = lex.findToken(string_orientation);
1034 if (tmpret != LYX_LAYOUT_DEFAULT)
1035 params.orientation = static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
1036 } else if (token == "\\paperwidth") {
1038 params.paperwidth = lex.getString();
1039 } else if (token == "\\paperheight") {
1041 params.paperheight = lex.getString();
1042 } else if (token == "\\leftmargin") {
1044 params.leftmargin = lex.getString();
1045 } else if (token == "\\topmargin") {
1047 params.topmargin = lex.getString();
1048 } else if (token == "\\rightmargin") {
1050 params.rightmargin = lex.getString();
1051 } else if (token == "\\bottommargin") {
1053 params.bottommargin = lex.getString();
1054 } else if (token == "\\headheight") {
1056 params.headheight = lex.getString();
1057 } else if (token == "\\headsep") {
1059 params.headsep = lex.getString();
1060 } else if (token == "\\footskip") {
1062 params.footskip = lex.getString();
1063 } else if (token == "\\paperfontsize") {
1065 params.fontsize = strip(lex.getString());
1066 } else if (token == "\\papercolumns") {
1068 params.columns = lex.getInteger();
1069 } else if (token == "\\papersides") {
1071 switch (lex.getInteger()) {
1073 case 1: params.sides = LyXTextClass::OneSide; break;
1074 case 2: params.sides = LyXTextClass::TwoSides; break;
1076 } else if (token == "\\paperpagestyle") {
1078 params.pagestyle = strip(lex.getString());
1079 } else if (token == "\\bullet") {
1081 int const index = lex.getInteger();
1083 int temp_int = lex.getInteger();
1084 params.user_defined_bullets[index].setFont(temp_int);
1085 params.temp_bullets[index].setFont(temp_int);
1087 temp_int = lex.getInteger();
1088 params.user_defined_bullets[index].setCharacter(temp_int);
1089 params.temp_bullets[index].setCharacter(temp_int);
1091 temp_int = lex.getInteger();
1092 params.user_defined_bullets[index].setSize(temp_int);
1093 params.temp_bullets[index].setSize(temp_int);
1095 string const temp_str = lex.getString();
1096 if (temp_str != "\\end_bullet") {
1097 // this element isn't really necessary for
1098 // parsing but is easier for humans
1099 // to understand bullets. Put it back and
1100 // set a debug message?
1101 lex.printError("\\end_bullet expected, got" + temp_str);
1102 //how can I put it back?
1104 } else if (token == "\\bulletLaTeX") {
1105 // The bullet class should be able to read this.
1107 int const index = lex.getInteger();
1109 string temp_str = lex.getString();
1111 while (temp_str != "\\end_bullet") {
1112 // this loop structure is needed when user
1113 // enters an empty string since the first
1114 // thing returned will be the \\end_bullet
1116 // if the LaTeX entry has spaces. Each element
1117 // therefore needs to be read in turn
1118 sum_str += temp_str;
1120 temp_str = lex.getString();
1123 params.user_defined_bullets[index].setText(sum_str);
1124 params.temp_bullets[index].setText(sum_str);
1125 } else if (token == "\\secnumdepth") {
1127 params.secnumdepth = lex.getInteger();
1128 } else if (token == "\\tocdepth") {
1130 params.tocdepth = lex.getInteger();
1131 } else if (token == "\\spacing") {
1133 string const tmp = strip(lex.getString());
1134 Spacing::Space tmp_space = Spacing::Default;
1135 float tmp_val = 0.0;
1136 if (tmp == "single") {
1137 tmp_space = Spacing::Single;
1138 } else if (tmp == "onehalf") {
1139 tmp_space = Spacing::Onehalf;
1140 } else if (tmp == "double") {
1141 tmp_space = Spacing::Double;
1142 } else if (tmp == "other") {
1144 tmp_space = Spacing::Other;
1145 tmp_val = lex.getFloat();
1147 lex.printError("Unknown spacing token: '$$Token'");
1149 // Small hack so that files written with klyx will be
1150 // parsed correctly.
1152 par->params().spacing(Spacing(tmp_space, tmp_val));
1154 params.spacing.set(tmp_space, tmp_val);
1156 } else if (token == "\\paragraph_spacing") {
1158 string const tmp = strip(lex.getString());
1159 if (tmp == "single") {
1160 par->params().spacing(Spacing(Spacing::Single));
1161 } else if (tmp == "onehalf") {
1162 par->params().spacing(Spacing(Spacing::Onehalf));
1163 } else if (tmp == "double") {
1164 par->params().spacing(Spacing(Spacing::Double));
1165 } else if (tmp == "other") {
1167 par->params().spacing(Spacing(Spacing::Other,
1170 lex.printError("Unknown spacing token: '$$Token'");
1172 } else if (token == "\\float_placement") {
1174 params.float_placement = lex.getString();
1175 } else if (token == "\\align") {
1176 int tmpret = lex.findToken(string_align);
1177 if (tmpret == -1) ++tmpret;
1178 if (tmpret != LYX_LAYOUT_DEFAULT) { // tmpret != 99 ???
1179 int const tmpret2 = int(pow(2.0, tmpret));
1180 //lyxerr << "Tmpret2 = " << tmpret2 << endl;
1181 par->params().align(LyXAlignment(tmpret2));
1183 } else if (token == "\\added_space_top") {
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().spaceTop(value);
1192 } else if (token == "\\added_space_bottom") {
1194 VSpace value = VSpace(lex.getString());
1195 // only add the length when value > 0 or
1197 if ((value.length().len().value() != 0) ||
1199 (value.kind() != VSpace::LENGTH))
1200 par->params().spaceBottom(value);
1201 #ifndef NO_COMPABILITY
1202 #ifndef NO_PEXTRA_REALLY
1203 } else if (token == "\\pextra_type") {
1205 par->params().pextraType(lex.getInteger());
1206 } else if (token == "\\pextra_width") {
1208 par->params().pextraWidth(lex.getString());
1209 } else if (token == "\\pextra_widthp") {
1211 par->params().pextraWidthp(lex.getString());
1212 } else if (token == "\\pextra_alignment") {
1214 par->params().pextraAlignment(lex.getInteger());
1215 } else if (token == "\\pextra_hfill") {
1217 par->params().pextraHfill(lex.getInteger());
1218 } else if (token == "\\pextra_start_minipage") {
1220 par->params().pextraStartMinipage(lex.getInteger());
1223 } else if (token == "\\labelwidthstring") {
1225 par->params().labelWidthString(lex.getString());
1226 // do not delete this token, it is still needed!
1227 } else if (token == "\\newline") {
1228 #ifndef NO_COMPABILITY
1229 if (!ert_comp.in_tabular && ert_comp.active) {
1230 ert_comp.contents += char(Paragraph::META_NEWLINE);
1232 // Since we cannot know it this is only a regular
1233 // newline or a tabular cell delimter we have to
1234 // handle the ERT here.
1235 insertErtContents(par, pos, false);
1237 par->insertChar(pos, Paragraph::META_NEWLINE, font);
1241 par->insertChar(pos, Paragraph::META_NEWLINE, font);
1244 } else if (token == "\\LyXTable") {
1245 #ifndef NO_COMPABILITY
1246 ert_comp.in_tabular = true;
1248 Inset * inset = new InsetTabular(*this);
1249 inset->read(this, lex);
1250 par->insertInset(pos, inset, font);
1252 } else if (token == "\\hfill") {
1253 par->insertChar(pos, Paragraph::META_HFILL, font);
1255 } else if (token == "\\protected_separator") { // obsolete
1256 // This is a backward compability thingie. (Lgb)
1257 // Remove it later some time...introduced with fileformat
1259 LyXLayout const & layout =
1260 textclasslist[params.textclass][par->layout()];
1262 if (layout.free_spacing || par->isFreeSpacing()) {
1263 par->insertChar(pos, ' ', font);
1265 Inset * inset = new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
1266 par->insertInset(pos, inset, font);
1269 } else if (token == "\\bibitem") { // ale970302
1271 InsetCommandParams p("bibitem", "dummy");
1272 par->bibkey = new InsetBibKey(p);
1274 par->bibkey->read(this, lex);
1275 } else if (token == "\\the_end") {
1276 #ifndef NO_COMPABILITY
1277 // If we still have some ert active here we have to insert
1278 // it so we don't loose it. (Lgb)
1279 insertErtContents(par, pos);
1281 the_end_read = true;
1282 #ifndef NO_COMPABILITY
1283 #ifndef NO_PEXTRA_REALLY
1286 minipar = parBeforeMinipage = 0;
1290 #ifndef NO_COMPABILITY
1291 if (ert_comp.active) {
1292 ert_comp.contents += token;
1295 // This should be insurance for the future: (Asger)
1298 string const s = _("Unknown token: ") + token
1299 + " " + lex.text() + "\n";
1300 // we can do this here this way because we're actually reading
1301 // the buffer and don't care about LyXText right now.
1302 InsetError * new_inset = new InsetError(s);
1303 par->insertInset(pos, new_inset, LyXFont(LyXFont::ALL_INHERIT,
1306 #ifndef NO_COMPABILITY
1311 #ifndef NO_COMPABILITY
1312 #ifndef NO_PEXTRA_REALLY
1313 // I wonder if we could use this blanket fix for all the
1314 // checkminipage cases...
1315 // don't forget about ert paragraphs and compatibility read for'em
1316 if (par && (par->size() || !ert_comp.contents.empty())) {
1317 // It is possible that this will check to often,
1318 // but that should not be an correctness issue.
1319 // Only a speed issue.
1320 checkminipage = true;
1323 // now check if we have a minipage paragraph as at this
1324 // point we already read all the necessary data!
1325 // this cannot be done in layout because there we did
1326 // not read yet the paragraph PEXTRA-params (Jug)
1328 // BEGIN pextra_minipage compability
1329 // This should be removed in 1.3.x (Lgb)
1330 // I don't think we should remove this so fast (Jug)
1332 // This compability code is not perfect. In a couple
1333 // of rand cases it fails. When the minipage par is
1334 // the first par in the document, and when there are
1335 // none or only one regular paragraphs after the
1336 // minipage. Currently I am not investing any effort
1337 // in fixing those cases.
1339 // lyxerr << "Call depth: " << call_depth << endl;
1340 // lyxerr << "Checkminipage: " << checkminipage << endl;
1342 if (checkminipage && (call_depth == 1)) {
1343 checkminipage = false;
1344 if (minipar && (minipar != par) &&
1345 (par->params().pextraType() == Paragraph::PEXTRA_MINIPAGE)) {
1346 lyxerr << "minipages in a row" << endl;
1347 if (par->params().pextraStartMinipage()) {
1348 lyxerr << "start new minipage" << endl;
1349 // minipages in a row
1350 par->previous()->next(0);
1353 Paragraph * tmp = minipar;
1355 tmp->params().pextraType(0);
1356 tmp->params().pextraWidth(string());
1357 tmp->params().pextraWidthp(string());
1358 tmp->params().pextraAlignment(0);
1359 tmp->params().pextraHfill(false);
1360 tmp->params().pextraStartMinipage(false);
1363 // create a new paragraph to insert the
1364 // minipages in the following case
1365 if (par->params().pextraStartMinipage() &&
1366 !par->params().pextraHfill()) {
1367 Paragraph * p = new Paragraph;
1368 p->layout(textclasslist[params.textclass].defaultLayoutName());
1370 p->previous(parBeforeMinipage);
1371 parBeforeMinipage->next(p);
1373 p->params().depth(parBeforeMinipage->params().depth());
1374 parBeforeMinipage = p;
1376 InsetMinipage * mini = new InsetMinipage(params);
1377 mini->pos(static_cast<InsetMinipage::Position>(par->params().pextraAlignment()));
1378 mini->pageWidth(LyXLength(par->params().pextraWidth()));
1379 if (!par->params().pextraWidthp().empty()) {
1380 lyxerr << "WP:" << mini->pageWidth().asString() << endl;
1381 mini->pageWidth(LyXLength((par->params().pextraWidthp())+"col%"));
1383 Paragraph * op = mini->firstParagraph();
1384 mini->inset.paragraph(par);
1386 // and free the old ones!
1389 Paragraph * pp = op->next();
1393 // Insert the minipage last in the
1394 // previous paragraph.
1395 if (par->params().pextraHfill()) {
1396 parBeforeMinipage->insertChar
1397 (parBeforeMinipage->size(),
1398 Paragraph::META_HFILL, font);
1400 parBeforeMinipage->insertInset
1401 (parBeforeMinipage->size(), mini, font);
1405 lyxerr << "new minipage par" << endl;
1406 //nothing to do just continue reading
1409 } else if (minipar && (minipar != par)) {
1410 lyxerr << "last minipage par read" << endl;
1411 // The last paragraph read was not part of a
1412 // minipage but the par linked list is...
1413 // So we need to remove the last par from the
1415 if (par->previous())
1416 par->previous()->next(0);
1417 par->previous(parBeforeMinipage);
1418 parBeforeMinipage->next(par);
1419 Paragraph * tmp = minipar;
1421 tmp->params().pextraType(0);
1422 tmp->params().pextraWidth(string());
1423 tmp->params().pextraWidthp(string());
1424 tmp->params().pextraAlignment(0);
1425 tmp->params().pextraHfill(false);
1426 tmp->params().pextraStartMinipage(false);
1429 depth = parBeforeMinipage->params().depth();
1430 // and set this depth on the par as it has not been set already
1431 par->params().depth(depth);
1432 minipar = parBeforeMinipage = 0;
1433 } else if (!minipar &&
1434 (par->params().pextraType() == Paragraph::PEXTRA_MINIPAGE)) {
1435 // par is the first paragraph in a minipage
1436 lyxerr << "begin minipage" << endl;
1437 // To minimize problems for
1438 // the users we will insert
1439 // the first minipage in
1440 // a sequence of minipages
1441 // in its own paragraph.
1442 Paragraph * p = new Paragraph;
1443 p->layout(textclasslist[params.textclass].defaultLayoutName());
1444 p->previous(par->previous());
1446 p->params().depth(depth);
1447 par->params().depth(0);
1449 if (par->previous())
1450 par->previous()->next(p);
1452 parBeforeMinipage = p;
1454 if (!first_par || (first_par == par))
1457 InsetMinipage * mini = new InsetMinipage(params);
1458 mini->pos(static_cast<InsetMinipage::Position>(minipar->params().pextraAlignment()));
1459 mini->pageWidth(LyXLength(minipar->params().pextraWidth()));
1460 if (!par->params().pextraWidthp().empty()) {
1461 lyxerr << "WP:" << mini->pageWidth().asString() << endl;
1462 mini->pageWidth(LyXLength((par->params().pextraWidthp())+"col%"));
1465 Paragraph * op = mini->firstParagraph();
1466 mini->inset.paragraph(minipar);
1468 // and free the old ones!
1471 Paragraph * pp = op->next();
1476 // Insert the minipage last in the
1477 // previous paragraph.
1478 if (minipar->params().pextraHfill()) {
1479 parBeforeMinipage->insertChar
1480 (parBeforeMinipage->size(),
1481 Paragraph::META_HFILL, font);
1483 parBeforeMinipage->insertInset
1484 (parBeforeMinipage->size(), mini, font);
1485 } else if (par->params().pextraType() == Paragraph::PEXTRA_INDENT) {
1486 par->params().leftIndent(LyXLength(par->params().pextraWidth()));
1487 if (!par->params().pextraWidthp().empty()) {
1488 par->params().leftIndent(LyXLength((par->params().pextraWidthp())+"col%"));
1492 // End of pextra_minipage compability
1496 return the_end_read;
1499 // needed to insert the selection
1500 void Buffer::insertStringAsLines(Paragraph *& par, pos_type & pos,
1501 LyXFont const & fn,string const & str) const
1503 LyXLayout const & layout =
1504 textclasslist[params.textclass][par->layout()];
1507 par->checkInsertChar(font);
1508 // insert the string, don't insert doublespace
1509 bool space_inserted = true;
1510 bool autobreakrows = !par->inInset() ||
1511 static_cast<InsetText *>(par->inInset())->getAutoBreakRows();
1512 for(string::const_iterator cit = str.begin();
1513 cit != str.end(); ++cit) {
1515 if (autobreakrows && (par->size() || layout.keepempty)) {
1516 par->breakParagraph(params, pos,
1517 layout.isEnvironment());
1520 space_inserted = true;
1524 // do not insert consecutive spaces if !free_spacing
1525 } else if ((*cit == ' ' || *cit == '\t') &&
1526 space_inserted && !layout.free_spacing &&
1527 !par->isFreeSpacing())
1530 } else if (*cit == '\t') {
1531 if (!layout.free_spacing && !par->isFreeSpacing()) {
1532 // tabs are like spaces here
1533 par->insertChar(pos, ' ', font);
1535 space_inserted = true;
1537 const pos_type nb = 8 - pos % 8;
1538 for (pos_type a = 0; a < nb ; ++a) {
1539 par->insertChar(pos, ' ', font);
1542 space_inserted = true;
1544 } else if (!IsPrintable(*cit)) {
1545 // Ignore unprintables
1548 // just insert the character
1549 par->insertChar(pos, *cit, font);
1551 space_inserted = (*cit == ' ');
1558 void Buffer::readInset(LyXLex & lex, Paragraph *& par,
1559 int & pos, LyXFont & font)
1561 // consistency check
1562 if (lex.getString() != "\\begin_inset") {
1563 lyxerr << "Buffer::readInset: Consistency check failed."
1570 string const tmptok = lex.getString();
1571 last_inset_read = tmptok;
1573 // test the different insets
1574 if (tmptok == "LatexCommand") {
1575 InsetCommandParams inscmd;
1578 string const cmdName = inscmd.getCmdName();
1580 // This strange command allows LyX to recognize "natbib" style
1581 // citations: citet, citep, Citet etc.
1582 if (compare_no_case(cmdName, "cite", 4) == 0) {
1583 inset = new InsetCitation(inscmd);
1584 } else if (cmdName == "bibitem") {
1585 lex.printError("Wrong place for bibitem");
1586 inset = new InsetBibKey(inscmd);
1587 } else if (cmdName == "BibTeX") {
1588 inset = new InsetBibtex(inscmd);
1589 } else if (cmdName == "index") {
1590 inset = new InsetIndex(inscmd);
1591 } else if (cmdName == "include") {
1592 inset = new InsetInclude(inscmd, *this);
1593 } else if (cmdName == "label") {
1594 inset = new InsetLabel(inscmd);
1595 } else if (cmdName == "url"
1596 || cmdName == "htmlurl") {
1597 inset = new InsetUrl(inscmd);
1598 } else if (cmdName == "ref"
1599 || cmdName == "pageref"
1600 || cmdName == "vref"
1601 || cmdName == "vpageref"
1602 || cmdName == "prettyref") {
1603 if (!inscmd.getOptions().empty()
1604 || !inscmd.getContents().empty()) {
1605 inset = new InsetRef(inscmd, *this);
1607 } else if (cmdName == "tableofcontents") {
1608 inset = new InsetTOC(inscmd);
1609 } else if (cmdName == "listofalgorithms") {
1610 inset = new InsetFloatList("algorithm");
1611 } else if (cmdName == "listoffigures") {
1612 inset = new InsetFloatList("figure");
1613 } else if (cmdName == "listoftables") {
1614 inset = new InsetFloatList("table");
1615 } else if (cmdName == "printindex") {
1616 inset = new InsetPrintIndex(inscmd);
1617 } else if (cmdName == "lyxparent") {
1618 inset = new InsetParent(inscmd, *this);
1621 bool alreadyread = false;
1622 if (tmptok == "Quotes") {
1623 inset = new InsetQuotes;
1624 } else if (tmptok == "External") {
1625 inset = new InsetExternal;
1626 } else if (tmptok == "FormulaMacro") {
1627 inset = new InsetFormulaMacro;
1628 } else if (tmptok == "Formula") {
1629 inset = new InsetFormula;
1630 } else if (tmptok == "Figure") { // Backward compatibility
1631 // inset = new InsetFig(100, 100, *this);
1632 inset = new InsetGraphics;
1633 } else if (tmptok == "Graphics") {
1634 inset = new InsetGraphics;
1635 } else if (tmptok == "Info") {// backwards compatibility
1636 inset = new InsetNote(this,
1637 lex.getLongString("\\end_inset"),
1640 } else if (tmptok == "Note") {
1641 inset = new InsetNote(params);
1642 } else if (tmptok == "Include") {
1643 InsetCommandParams p("Include");
1644 inset = new InsetInclude(p, *this);
1645 } else if (tmptok == "ERT") {
1646 inset = new InsetERT(params);
1647 } else if (tmptok == "Tabular") {
1648 inset = new InsetTabular(*this);
1649 } else if (tmptok == "Text") {
1650 inset = new InsetText(params);
1651 } else if (tmptok == "Foot") {
1652 inset = new InsetFoot(params);
1653 } else if (tmptok == "Marginal") {
1654 inset = new InsetMarginal(params);
1655 } else if (tmptok == "Minipage") {
1656 inset = new InsetMinipage(params);
1657 } else if (tmptok == "Float") {
1659 string tmptok = lex.getString();
1660 inset = new InsetFloat(params, tmptok);
1662 } else if (tmptok == "List") {
1663 inset = new InsetList;
1664 } else if (tmptok == "Theorem") {
1665 inset = new InsetList;
1667 } else if (tmptok == "Caption") {
1668 inset = new InsetCaption(params);
1669 } else if (tmptok == "FloatList") {
1670 inset = new InsetFloatList;
1673 if (inset && !alreadyread) inset->read(this, lex);
1677 par->insertInset(pos, inset, font);
1683 bool Buffer::readFile(LyXLex & lex, Paragraph * par)
1687 string const token(lex.getString());
1688 if (token == "\\lyxformat") { // the first token _must_ be...
1690 string tmp_format = lex.getString();
1691 //lyxerr << "LyX Format: `" << tmp_format << "'" << endl;
1692 // if present remove ".," from string.
1693 string::size_type dot = tmp_format.find_first_of(".,");
1694 //lyxerr << " dot found at " << dot << endl;
1695 if (dot != string::npos)
1696 tmp_format.erase(dot, 1);
1697 file_format = strToInt(tmp_format);
1698 if (file_format == LYX_FORMAT) {
1700 } else if (file_format > LYX_FORMAT) {
1702 Alert::alert(_("Warning!"),
1703 _("LyX file format is newer that what"),
1704 _("is supported in this LyX version. Expect some problems."));
1706 } else if (file_format < LYX_FORMAT) {
1708 if (file_format < 200) {
1709 Alert::alert(_("ERROR!"),
1710 _("Old LyX file format found. "
1711 "Use LyX 0.10.x to read this!"));
1713 } else if (file_format < 220) {
1714 Alert::alert(_("ERROR!"),
1715 _("Old LyX file format found. "
1716 "Use LyX 1.2.x to read this!"));
1720 bool the_end = readLyXformat2(lex, par);
1721 params.setPaperStuff();
1724 // the_end was added in 213
1725 if (file_format < 213)
1730 Alert::alert(_("Warning!"),
1731 _("Reading of document is not complete"),
1732 _("Maybe the document is truncated"));
1735 } else { // "\\lyxformat" not found
1736 Alert::alert(_("ERROR!"), _("Not a LyX file!"));
1739 Alert::alert(_("ERROR!"), _("Unable to read file!"));
1744 // Should probably be moved to somewhere else: BufferView? LyXView?
1745 bool Buffer::save() const
1747 // We don't need autosaves in the immediate future. (Asger)
1748 resetAutosaveTimers();
1752 if (lyxrc.make_backup) {
1753 s = fileName() + '~';
1754 if (!lyxrc.backupdir_path.empty())
1755 s = AddName(lyxrc.backupdir_path,
1756 subst(os::slashify_path(s),'/','!'));
1758 // Rename is the wrong way of making a backup,
1759 // this is the correct way.
1760 /* truss cp fil fil2:
1761 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
1762 stat("LyXVC.lyx", 0xEFFFF688) = 0
1763 open("LyXVC.lyx", O_RDONLY) = 3
1764 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
1765 fstat(4, 0xEFFFF508) = 0
1766 fstat(3, 0xEFFFF508) = 0
1767 read(3, " # T h i s f i l e w".., 8192) = 5579
1768 write(4, " # T h i s f i l e w".., 5579) = 5579
1769 read(3, 0xEFFFD4A0, 8192) = 0
1772 chmod("LyXVC3.lyx", 0100644) = 0
1773 lseek(0, 0, SEEK_CUR) = 46440
1777 // Should probably have some more error checking here.
1778 // Doing it this way, also makes the inodes stay the same.
1779 // This is still not a very good solution, in particular we
1780 // might loose the owner of the backup.
1781 FileInfo finfo(fileName());
1782 if (finfo.exist()) {
1783 mode_t fmode = finfo.getMode();
1784 struct utimbuf times = {
1785 finfo.getAccessTime(),
1786 finfo.getModificationTime() };
1788 ifstream ifs(fileName().c_str());
1789 ofstream ofs(s.c_str(), ios::out|ios::trunc);
1794 ::chmod(s.c_str(), fmode);
1796 if (::utime(s.c_str(), ×)) {
1797 lyxerr << "utime error." << endl;
1800 lyxerr << "LyX was not able to make "
1801 "backup copy. Beware." << endl;
1806 if (writeFile(fileName(), false)) {
1808 removeAutosaveFile(fileName());
1810 // Saving failed, so backup is not backup
1811 if (lyxrc.make_backup) {
1812 lyx::rename(s, fileName());
1820 // Returns false if unsuccesful
1821 bool Buffer::writeFile(string const & fname, bool flag) const
1823 // if flag is false writeFile will not create any GUI
1824 // warnings, only cerr.
1825 // Needed for autosave in background or panic save (Matthias 120496)
1827 if (read_only && (fname == fileName())) {
1828 // Here we should come with a question if we should
1829 // perform the write anyway.
1831 lyxerr << _("Error! Document is read-only: ")
1834 Alert::alert(_("Error! Document is read-only: "),
1839 FileInfo finfo(fname);
1840 if (finfo.exist() && !finfo.writable()) {
1841 // Here we should come with a question if we should
1842 // try to do the save anyway. (i.e. do a chmod first)
1844 lyxerr << _("Error! Cannot write file: ")
1847 Alert::err_alert(_("Error! Cannot write file: "),
1852 ofstream ofs(fname.c_str());
1855 lyxerr << _("Error! Cannot open file: ")
1858 Alert::err_alert(_("Error! Cannot open file: "),
1864 // Use the standard "C" locale for file output.
1865 ofs.imbue(std::locale::classic());
1868 // The top of the file should not be written by params.
1870 // write out a comment in the top of the file
1871 ofs << '#' << lyx_docversion
1872 << " created this file. For more info see http://www.lyx.org/\n"
1873 << "\\lyxformat " << LYX_FORMAT << "\n";
1875 // now write out the buffer paramters.
1876 params.writeFile(ofs);
1878 Paragraph::depth_type depth = 0;
1880 // this will write out all the paragraphs
1881 // using recursive descent.
1882 paragraph->writeFile(this, ofs, params, depth);
1884 // Write marker that shows file is complete
1885 ofs << "\n\\the_end" << endl;
1889 // how to check if close went ok?
1890 // Following is an attempt... (BE 20001011)
1892 // good() returns false if any error occured, including some
1893 // formatting error.
1894 // bad() returns true if something bad happened in the buffer,
1895 // which should include file system full errors.
1902 lyxerr << "Buffer::writeFile: BAD ERROR!" << endl;
1904 lyxerr << "Buffer::writeFile: NOT SO BAD ERROR!"
1916 pair<int, string> const addDepth(int depth, int ldepth)
1920 d += (ldepth - depth) * 2;
1921 return make_pair(d, string(d, ' '));
1927 string const Buffer::asciiParagraph(Paragraph const * par,
1928 unsigned int linelen,
1929 bool noparbreak) const
1931 ostringstream buffer;
1932 Paragraph::depth_type depth = 0;
1934 Paragraph::depth_type ltype_depth = 0;
1935 bool ref_printed = false;
1936 // if (!par->previous()) {
1938 // begins or ends a deeper area ?
1939 if (depth != par->params().depth()) {
1940 if (par->params().depth() > depth) {
1941 while (par->params().depth() > depth) {
1945 while (par->params().depth() < depth) {
1951 depth = par->params().depth();
1954 // First write the layout
1955 string const & tmp = par->layout();
1956 if (compare_no_case(tmp, "itemize") == 0) {
1958 ltype_depth = depth + 1;
1959 } else if (compare_no_case(tmp, "enumerate") == 0) {
1961 ltype_depth = depth + 1;
1962 } else if (contains(lowercase(tmp), "ection")) {
1964 ltype_depth = depth + 1;
1965 } else if (contains(lowercase(tmp), "aragraph")) {
1967 ltype_depth = depth + 1;
1968 } else if (compare_no_case(tmp, "description") == 0) {
1970 ltype_depth = depth + 1;
1971 } else if (compare_no_case(tmp, "abstract") == 0) {
1974 } else if (compare_no_case(tmp, "bibliography") == 0) {
1982 /* maybe some vertical spaces */
1984 /* the labelwidthstring used in lists */
1988 /* some pagebreaks? */
1992 /* what about the alignment */
1994 // lyxerr << "Should this ever happen?" << endl;
1997 // linelen <= 0 is special and means we don't have pargraph breaks
1999 string::size_type currlinelen = 0;
2005 buffer << string(depth * 2, ' ');
2006 currlinelen += depth * 2;
2009 // we should probably change to the paragraph language in the
2010 // gettext here (if possible) so that strings are outputted in
2011 // the correct language! (20012712 Jug)
2015 case 4: // (Sub)Paragraph
2016 case 5: // Description
2020 buffer << _("Abstract") << "\n\n";
2023 string const abst = _("Abstract: ");
2025 currlinelen += abst.length();
2028 case 7: // Bibliography
2031 buffer << _("References") << "\n\n";
2034 string const refs = _("References: ");
2036 currlinelen += refs.length();
2044 string const parlab = par->params().labelString();
2045 buffer << parlab << " ";
2046 currlinelen += parlab.length() + 1;
2054 pair<int, string> p = addDepth(depth, ltype_depth);
2056 currlinelen += p.first;
2059 // this is to change the linebreak to do it by word a bit more
2060 // intelligent hopefully! (only in the case where we have a
2061 // max linelenght!) (Jug)
2065 for (pos_type i = 0; i < par->size(); ++i) {
2066 char c = par->getUChar(params, i);
2068 case Paragraph::META_INSET:
2070 Inset const * inset = par->getInset(i);
2074 currlinelen += word.length();
2077 if (inset->ascii(this, buffer, linelen)) {
2078 // to be sure it breaks paragraph
2079 currlinelen += linelen;
2085 case Paragraph::META_NEWLINE:
2087 buffer << word << "\n";
2090 pair<int, string> p = addDepth(depth,
2093 currlinelen = p.first;
2097 case Paragraph::META_HFILL:
2098 buffer << word << "\t";
2099 currlinelen += word.length() + 1;
2106 currlinelen + word.length() > linelen - 10) {
2108 pair<int, string> p =
2109 addDepth(depth, ltype_depth);
2111 currlinelen = p.first;
2114 buffer << word << ' ';
2115 currlinelen += word.length() + 1;
2122 lyxerr[Debug::INFO] <<
2123 "writeAsciiFile: NULL char in structure." << endl;
2125 if ((linelen > 0) &&
2126 (currlinelen + word.length()) > linelen)
2130 pair<int, string> p =
2131 addDepth(depth, ltype_depth);
2133 currlinelen = p.first;
2140 return buffer.str().c_str();
2144 void Buffer::writeFileAscii(string const & fname, int linelen)
2146 ofstream ofs(fname.c_str());
2148 Alert::err_alert(_("Error: Cannot write file:"), fname);
2151 writeFileAscii(ofs, linelen);
2155 void Buffer::writeFileAscii(ostream & ofs, int linelen)
2157 Paragraph * par = paragraph;
2159 ofs << asciiParagraph(par, linelen, par->previous() == 0);
2169 void Buffer::makeLaTeXFile(string const & fname,
2170 string const & original_path,
2171 bool nice, bool only_body)
2173 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
2175 ofstream ofs(fname.c_str());
2177 Alert::err_alert(_("Error: Cannot open file: "), fname);
2181 niceFile = nice; // this will be used by Insetincludes.
2183 tex_code_break_column = lyxrc.ascii_linelen;
2185 // validate the buffer.
2186 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
2187 LaTeXFeatures features(params);
2189 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
2192 // The starting paragraph of the coming rows is the
2193 // first paragraph of the document. (Asger)
2194 texrow.start(paragraph, 0);
2196 if (!only_body && nice) {
2197 ofs << "%% " << lyx_docversion << " created this file. "
2198 "For more info, see http://www.lyx.org/.\n"
2199 "%% Do not edit unless you really know what "
2204 lyxerr[Debug::INFO] << "lyx header finished" << endl;
2205 // There are a few differences between nice LaTeX and usual files:
2206 // usual is \batchmode and has a
2207 // special input@path to allow the including of figures
2208 // with either \input or \includegraphics (what figinsets do).
2209 // batchmode is not set if there is a tex_code_break_column.
2210 // In this case somebody is interested in the generated LaTeX,
2211 // so this is OK. input@path is set when the actual parameter
2212 // original_path is set. This is done for usual tex-file, but not
2213 // for nice-latex-file. (Matthias 250696)
2216 // code for usual, NOT nice-latex-file
2217 ofs << "\\batchmode\n"; // changed
2218 // from \nonstopmode
2221 if (!original_path.empty()) {
2222 string inputpath = os::external_path(original_path);
2223 subst(inputpath, "~", "\\string~");
2224 ofs << "\\makeatletter\n"
2225 << "\\def\\input@path{{"
2226 << inputpath << "/}}\n"
2227 << "\\makeatother\n";
2233 ofs << "\\documentclass";
2235 LyXTextClass const & tclass = textclasslist[params.textclass];
2237 ostringstream options; // the document class options.
2239 if (tokenPos(tclass.opt_fontsize(),
2240 '|', params.fontsize) >= 0) {
2241 // only write if existing in list (and not default)
2242 options << params.fontsize << "pt,";
2246 if (!params.use_geometry &&
2247 (params.paperpackage == BufferParams::PACKAGE_NONE)) {
2248 switch (params.papersize) {
2249 case BufferParams::PAPER_A4PAPER:
2250 options << "a4paper,";
2252 case BufferParams::PAPER_USLETTER:
2253 options << "letterpaper,";
2255 case BufferParams::PAPER_A5PAPER:
2256 options << "a5paper,";
2258 case BufferParams::PAPER_B5PAPER:
2259 options << "b5paper,";
2261 case BufferParams::PAPER_EXECUTIVEPAPER:
2262 options << "executivepaper,";
2264 case BufferParams::PAPER_LEGALPAPER:
2265 options << "legalpaper,";
2271 if (params.sides != tclass.sides()) {
2272 switch (params.sides) {
2273 case LyXTextClass::OneSide:
2274 options << "oneside,";
2276 case LyXTextClass::TwoSides:
2277 options << "twoside,";
2283 if (params.columns != tclass.columns()) {
2284 if (params.columns == 2)
2285 options << "twocolumn,";
2287 options << "onecolumn,";
2290 if (!params.use_geometry
2291 && params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
2292 options << "landscape,";
2294 // language should be a parameter to \documentclass
2296 ostringstream language_options;
2297 if (params.language->babel() == "hebrew"
2298 && default_language->babel() != "hebrew")
2299 // This seems necessary
2300 features.useLanguage(default_language);
2302 if (lyxrc.language_use_babel ||
2303 params.language->lang() != lyxrc.default_language ||
2304 features.hasLanguages()) {
2306 language_options << features.getLanguages();
2307 language_options << params.language->babel();
2308 if (lyxrc.language_global_options)
2309 options << language_options.str() << ',';
2312 // the user-defined options
2313 if (!params.options.empty()) {
2314 options << params.options << ',';
2317 string strOptions(options.str().c_str());
2318 if (!strOptions.empty()) {
2319 strOptions = strip(strOptions, ',');
2320 ofs << '[' << strOptions << ']';
2323 ofs << '{' << tclass.latexname() << "}\n";
2325 // end of \documentclass defs
2327 // font selection must be done before loading fontenc.sty
2328 // The ae package is not needed when using OT1 font encoding.
2329 if (params.fonts != "default" &&
2330 (params.fonts != "ae" || lyxrc.fontenc != "default")) {
2331 ofs << "\\usepackage{" << params.fonts << "}\n";
2333 if (params.fonts == "ae") {
2334 ofs << "\\usepackage{aecompl}\n";
2338 // this one is not per buffer
2339 if (lyxrc.fontenc != "default") {
2340 ofs << "\\usepackage[" << lyxrc.fontenc
2345 if (params.inputenc == "auto") {
2346 string const doc_encoding =
2347 params.language->encoding()->LatexName();
2349 // Create a list with all the input encodings used
2351 set<string> encodings = features.getEncodingSet(doc_encoding);
2353 ofs << "\\usepackage[";
2354 std::copy(encodings.begin(), encodings.end(),
2355 std::ostream_iterator<string>(ofs, ","));
2356 ofs << doc_encoding << "]{inputenc}\n";
2358 } else if (params.inputenc != "default") {
2359 ofs << "\\usepackage[" << params.inputenc
2364 // At the very beginning the text parameters.
2365 if (params.paperpackage != BufferParams::PACKAGE_NONE) {
2366 switch (params.paperpackage) {
2367 case BufferParams::PACKAGE_A4:
2368 ofs << "\\usepackage{a4}\n";
2371 case BufferParams::PACKAGE_A4WIDE:
2372 ofs << "\\usepackage{a4wide}\n";
2375 case BufferParams::PACKAGE_WIDEMARGINSA4:
2376 ofs << "\\usepackage[widemargins]{a4}\n";
2381 if (params.use_geometry) {
2382 ofs << "\\usepackage{geometry}\n";
2384 ofs << "\\geometry{verbose";
2385 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
2386 ofs << ",landscape";
2387 switch (params.papersize2) {
2388 case BufferParams::VM_PAPER_CUSTOM:
2389 if (!params.paperwidth.empty())
2390 ofs << ",paperwidth="
2391 << params.paperwidth;
2392 if (!params.paperheight.empty())
2393 ofs << ",paperheight="
2394 << params.paperheight;
2396 case BufferParams::VM_PAPER_USLETTER:
2397 ofs << ",letterpaper";
2399 case BufferParams::VM_PAPER_USLEGAL:
2400 ofs << ",legalpaper";
2402 case BufferParams::VM_PAPER_USEXECUTIVE:
2403 ofs << ",executivepaper";
2405 case BufferParams::VM_PAPER_A3:
2408 case BufferParams::VM_PAPER_A4:
2411 case BufferParams::VM_PAPER_A5:
2414 case BufferParams::VM_PAPER_B3:
2417 case BufferParams::VM_PAPER_B4:
2420 case BufferParams::VM_PAPER_B5:
2424 // default papersize ie BufferParams::VM_PAPER_DEFAULT
2425 switch (lyxrc.default_papersize) {
2426 case BufferParams::PAPER_DEFAULT: // keep compiler happy
2427 case BufferParams::PAPER_USLETTER:
2428 ofs << ",letterpaper";
2430 case BufferParams::PAPER_LEGALPAPER:
2431 ofs << ",legalpaper";
2433 case BufferParams::PAPER_EXECUTIVEPAPER:
2434 ofs << ",executivepaper";
2436 case BufferParams::PAPER_A3PAPER:
2439 case BufferParams::PAPER_A4PAPER:
2442 case BufferParams::PAPER_A5PAPER:
2445 case BufferParams::PAPER_B5PAPER:
2450 if (!params.topmargin.empty())
2451 ofs << ",tmargin=" << params.topmargin;
2452 if (!params.bottommargin.empty())
2453 ofs << ",bmargin=" << params.bottommargin;
2454 if (!params.leftmargin.empty())
2455 ofs << ",lmargin=" << params.leftmargin;
2456 if (!params.rightmargin.empty())
2457 ofs << ",rmargin=" << params.rightmargin;
2458 if (!params.headheight.empty())
2459 ofs << ",headheight=" << params.headheight;
2460 if (!params.headsep.empty())
2461 ofs << ",headsep=" << params.headsep;
2462 if (!params.footskip.empty())
2463 ofs << ",footskip=" << params.footskip;
2468 if (tokenPos(tclass.opt_pagestyle(),
2469 '|', params.pagestyle) >= 0) {
2470 if (params.pagestyle == "fancy") {
2471 ofs << "\\usepackage{fancyhdr}\n";
2474 ofs << "\\pagestyle{" << params.pagestyle << "}\n";
2478 if (params.secnumdepth != tclass.secnumdepth()) {
2479 ofs << "\\setcounter{secnumdepth}{"
2480 << params.secnumdepth
2484 if (params.tocdepth != tclass.tocdepth()) {
2485 ofs << "\\setcounter{tocdepth}{"
2491 if (params.paragraph_separation) {
2492 switch (params.defskip.kind()) {
2493 case VSpace::SMALLSKIP:
2494 ofs << "\\setlength\\parskip{\\smallskipamount}\n";
2496 case VSpace::MEDSKIP:
2497 ofs << "\\setlength\\parskip{\\medskipamount}\n";
2499 case VSpace::BIGSKIP:
2500 ofs << "\\setlength\\parskip{\\bigskipamount}\n";
2502 case VSpace::LENGTH:
2503 ofs << "\\setlength\\parskip{"
2504 << params.defskip.length().asLatexString()
2507 default: // should never happen // Then delete it.
2508 ofs << "\\setlength\\parskip{\\medskipamount}\n";
2513 ofs << "\\setlength\\parindent{0pt}\n";
2517 // Now insert the LyX specific LaTeX commands...
2519 // The optional packages;
2520 string preamble(features.getPackages());
2522 // this might be useful...
2523 preamble += "\n\\makeatletter\n";
2525 // Some macros LyX will need
2526 string tmppreamble(features.getMacros());
2528 if (!tmppreamble.empty()) {
2529 preamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2530 "LyX specific LaTeX commands.\n"
2531 + tmppreamble + '\n';
2534 // the text class specific preamble
2535 tmppreamble = features.getTClassPreamble();
2536 if (!tmppreamble.empty()) {
2537 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2538 "Textclass specific LaTeX commands.\n"
2539 + tmppreamble + '\n';
2542 /* the user-defined preamble */
2543 if (!params.preamble.empty()) {
2544 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2545 "User specified LaTeX commands.\n"
2546 + params.preamble + '\n';
2549 // Itemize bullet settings need to be last in case the user
2550 // defines their own bullets that use a package included
2551 // in the user-defined preamble -- ARRae
2552 // Actually it has to be done much later than that
2553 // since some packages like frenchb make modifications
2554 // at \begin{document} time -- JMarc
2556 for (int i = 0; i < 4; ++i) {
2557 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
2558 if (bullets_def.empty())
2559 bullets_def="\\AtBeginDocument{\n";
2560 bullets_def += " \\renewcommand{\\labelitemi";
2562 // `i' is one less than the item to modify
2569 bullets_def += "ii";
2575 bullets_def += "}{" +
2576 params.user_defined_bullets[i].getText()
2581 if (!bullets_def.empty())
2582 preamble += bullets_def + "}\n\n";
2585 int(lyx::count(preamble.begin(), preamble.end(), '\n'));
2586 for (int j = 0; j != nlines; ++j) {
2590 // We try to load babel late, in case it interferes
2591 // with other packages.
2593 string tmp = lyxrc.language_package;
2594 if (!lyxrc.language_global_options
2595 && tmp == "\\usepackage{babel}")
2596 tmp = string("\\usepackage[") +
2597 language_options.str().c_str() +
2599 preamble += tmp + "\n";
2600 preamble += features.getBabelOptions();
2603 preamble += "\\makeatother\n";
2608 ofs << "\\begin{document}\n";
2611 lyxerr[Debug::INFO] << "preamble finished, now the body." << endl;
2613 if (!lyxrc.language_auto_begin) {
2614 ofs << subst(lyxrc.language_command_begin, "$$lang",
2615 params.language->babel())
2620 latexParagraphs(ofs, paragraph, 0, texrow);
2622 // add this just in case after all the paragraphs
2626 if (!lyxrc.language_auto_end) {
2627 ofs << subst(lyxrc.language_command_end, "$$lang",
2628 params.language->babel())
2634 ofs << "\\end{document}\n";
2637 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
2639 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
2643 // Just to be sure. (Asger)
2646 // tex_code_break_column's value is used to decide
2647 // if we are in batchmode or not (within mathed_write()
2648 // in math_write.C) so we must set it to a non-zero
2649 // value when we leave otherwise we save incorrect .lyx files.
2650 tex_code_break_column = lyxrc.ascii_linelen;
2654 lyxerr << "File was not closed properly." << endl;
2657 lyxerr[Debug::INFO] << "Finished making latex file." << endl;
2658 lyxerr[Debug::INFO] << "Row count was " << texrow.rows()-1 << "." << endl;
2660 // we want this to be true outside previews (for insetexternal)
2666 // LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
2668 void Buffer::latexParagraphs(ostream & ofs, Paragraph * par,
2669 Paragraph * endpar, TexRow & texrow,
2670 bool moving_arg) const
2672 bool was_title = false;
2673 bool already_title = false;
2676 while (par != endpar) {
2677 Inset * in = par->inInset();
2678 // well we have to check if we are in an inset with unlimited
2679 // lenght (all in one row) if that is true then we don't allow
2680 // any special options in the paragraph and also we don't allow
2681 // any environment other then "Standard" to be valid!
2682 if ((in == 0) || !in->forceDefaultParagraphs(in)) {
2683 LyXLayout const & layout =
2684 textclasslist[params.textclass][par->layout()];
2686 if (layout.intitle) {
2687 if (already_title) {
2688 lyxerr <<"Error in latexParagraphs: You"
2689 " should not mix title layouts"
2690 " with normal ones." << endl;
2693 } else if (was_title && !already_title) {
2694 ofs << "\\maketitle\n";
2696 already_title = true;
2700 if (layout.isEnvironment() ||
2701 !par->params().leftIndent().zero())
2703 par = par->TeXEnvironment(this, params, ofs, texrow);
2705 par = par->TeXOnePar(this, params, ofs, texrow, moving_arg);
2708 par = par->TeXOnePar(this, params, ofs, texrow, moving_arg);
2711 // It might be that we only have a title in this document
2712 if (was_title && !already_title) {
2713 ofs << "\\maketitle\n";
2719 bool Buffer::isLatex() const
2721 return textclasslist[params.textclass].outputType() == LATEX;
2725 bool Buffer::isLinuxDoc() const
2727 return textclasslist[params.textclass].outputType() == LINUXDOC;
2731 bool Buffer::isLiterate() const
2733 return textclasslist[params.textclass].outputType() == LITERATE;
2737 bool Buffer::isDocBook() const
2739 return textclasslist[params.textclass].outputType() == DOCBOOK;
2743 bool Buffer::isSGML() const
2745 LyXTextClass const & tclass = textclasslist[params.textclass];
2747 return tclass.outputType() == LINUXDOC ||
2748 tclass.outputType() == DOCBOOK;
2752 int Buffer::sgmlOpenTag(ostream & os, Paragraph::depth_type depth, bool mixcont,
2753 string const & latexname) const
2755 if (!latexname.empty() && latexname != "!-- --") {
2757 os << string(" ",depth);
2758 os << "<" << latexname << ">";
2768 int Buffer::sgmlCloseTag(ostream & os, Paragraph::depth_type depth, bool mixcont,
2769 string const & latexname) const
2771 if (!latexname.empty() && latexname != "!-- --") {
2773 os << endl << string(" ",depth);
2774 os << "</" << latexname << ">";
2784 void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
2786 ofstream ofs(fname.c_str());
2789 Alert::alert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2793 niceFile = nice; // this will be used by included files.
2795 LaTeXFeatures features(params);
2801 LyXTextClass const & tclass = textclasslist[params.textclass];
2803 string top_element = tclass.latexname();
2806 ofs << "<!doctype linuxdoc system";
2808 string preamble = params.preamble;
2809 const string name = nice ? ChangeExtension(filename_, ".sgml")
2811 preamble += features.getIncludedFiles(name);
2812 preamble += features.getLyXSGMLEntities();
2814 if (!preamble.empty()) {
2815 ofs << " [ " << preamble << " ]";
2819 if (params.options.empty())
2820 sgmlOpenTag(ofs, 0, false, top_element);
2822 string top = top_element;
2824 top += params.options;
2825 sgmlOpenTag(ofs, 0, false, top);
2829 ofs << "<!-- " << lyx_docversion
2830 << " created this file. For more info see http://www.lyx.org/"
2833 Paragraph::depth_type depth = 0; // paragraph depth
2834 Paragraph * par = paragraph;
2836 vector<string> environment_stack(5);
2839 LyXLayout const & style = tclass[par->layout()];
2841 // treat <toc> as a special case for compatibility with old code
2842 if (par->isInset(0)) {
2843 Inset * inset = par->getInset(0);
2844 Inset::Code lyx_code = inset->lyxCode();
2845 if (lyx_code == Inset::TOC_CODE) {
2846 string const temp = "toc";
2847 sgmlOpenTag(ofs, depth, false, temp);
2854 // environment tag closing
2855 for (; depth > par->params().depth(); --depth) {
2856 sgmlCloseTag(ofs, depth, false, environment_stack[depth]);
2857 environment_stack[depth].erase();
2860 // write opening SGML tags
2861 switch (style.latextype) {
2862 case LATEX_PARAGRAPH:
2863 if (depth == par->params().depth()
2864 && !environment_stack[depth].empty()) {
2865 sgmlCloseTag(ofs, depth, false, environment_stack[depth]);
2866 environment_stack[depth].erase();
2872 sgmlOpenTag(ofs, depth, false, style.latexname());
2878 _("Error : Wrong depth for"
2879 " LatexType Command.\n"));
2881 if (!environment_stack[depth].empty()) {
2882 sgmlCloseTag(ofs, depth, false, environment_stack[depth]);
2886 environment_stack[depth].erase();
2887 sgmlOpenTag(ofs, depth, false, style.latexname());
2890 case LATEX_ENVIRONMENT:
2891 case LATEX_ITEM_ENVIRONMENT:
2892 if (depth == par->params().depth()
2893 && environment_stack[depth] != style.latexname()) {
2894 sgmlCloseTag(ofs, depth, false, environment_stack[depth]);
2895 environment_stack[depth].erase();
2897 if (depth < par->params().depth()) {
2898 depth = par->params().depth();
2899 environment_stack[depth].erase();
2901 if (environment_stack[depth] != style.latexname()) {
2903 sgmlOpenTag(ofs, depth, false, "p");
2905 sgmlOpenTag(ofs, depth, false, style.latexname());
2907 if (environment_stack.size() == depth + 1)
2908 environment_stack.push_back("!-- --");
2909 environment_stack[depth] = style.latexname();
2912 if (style.latexparam() == "CDATA")
2915 if (style.latextype == LATEX_ENVIRONMENT) break;
2917 if (style.labeltype == LABEL_MANUAL)
2922 sgmlOpenTag(ofs, depth + 1, false, item_name);
2925 sgmlOpenTag(ofs, depth, false, style.latexname());
2929 simpleLinuxDocOnePar(ofs, par, depth);
2934 // write closing SGML tags
2935 switch (style.latextype) {
2938 case LATEX_ENVIRONMENT:
2939 case LATEX_ITEM_ENVIRONMENT:
2940 if (style.latexparam() == "CDATA")
2944 sgmlCloseTag(ofs, depth, false, style.latexname());
2950 for (int i=depth; i >= 0; --i)
2951 sgmlCloseTag(ofs, depth, false, environment_stack[i]);
2955 sgmlCloseTag(ofs, 0, false, top_element);
2959 // How to check for successful close
2961 // we want this to be true outside previews (for insetexternal)
2966 // checks, if newcol chars should be put into this line
2967 // writes newline, if necessary.
2970 void sgmlLineBreak(ostream & os, string::size_type & colcount,
2971 string::size_type newcol)
2974 if (colcount > lyxrc.ascii_linelen) {
2976 colcount = newcol; // assume write after this call
2991 string tag_name(PAR_TAG const & pt) {
2993 case NONE: return "!-- --";
2994 case TT: return "tt";
2995 case SF: return "sf";
2996 case BF: return "bf";
2997 case IT: return "it";
2998 case SL: return "sl";
2999 case EM: return "em";
3006 void operator|=(PAR_TAG & p1, PAR_TAG const & p2)
3008 p1 = static_cast<PAR_TAG>(p1 | p2);
3013 void reset(PAR_TAG & p1, PAR_TAG const & p2)
3015 p1 = static_cast<PAR_TAG>(p1 & ~p2);
3021 // Handle internal paragraph parsing -- layout already processed.
3022 void Buffer::simpleLinuxDocOnePar(ostream & os,
3024 Paragraph::depth_type /*depth*/)
3026 LyXLayout const & style =
3027 textclasslist[params.textclass][par->layout()];
3028 string::size_type char_line_count = 5; // Heuristic choice ;-)
3030 // gets paragraph main font
3033 if (style.labeltype == LABEL_MANUAL) {
3034 font_old = style.labelfont;
3037 font_old = style.font;
3041 LyXFont::FONT_FAMILY family_type = LyXFont::ROMAN_FAMILY;
3042 LyXFont::FONT_SERIES series_type = LyXFont::MEDIUM_SERIES;
3043 LyXFont::FONT_SHAPE shape_type = LyXFont::UP_SHAPE;
3046 stack<PAR_TAG> tag_state;
3047 // parsing main loop
3048 for (pos_type i = 0; i < par->size(); ++i) {
3050 PAR_TAG tag_close = NONE;
3051 list < PAR_TAG > tag_open;
3053 LyXFont const font = par->getFont(params, i);
3055 if (font_old.family() != font.family()) {
3056 switch (family_type) {
3057 case LyXFont::SANS_FAMILY:
3060 case LyXFont::TYPEWRITER_FAMILY:
3067 family_type = font.family();
3069 switch (family_type) {
3070 case LyXFont::SANS_FAMILY:
3071 tag_open.push_back(SF);
3073 case LyXFont::TYPEWRITER_FAMILY:
3074 tag_open.push_back(TT);
3081 if (font_old.series() != font.series()) {
3082 switch (series_type) {
3083 case LyXFont::BOLD_SERIES:
3090 series_type = font.series();
3092 switch (series_type) {
3093 case LyXFont::BOLD_SERIES:
3094 tag_open.push_back(BF);
3102 if (font_old.shape() != font.shape()) {
3103 switch (shape_type) {
3104 case LyXFont::ITALIC_SHAPE:
3107 case LyXFont::SLANTED_SHAPE:
3114 shape_type = font.shape();
3116 switch (shape_type) {
3117 case LyXFont::ITALIC_SHAPE:
3118 tag_open.push_back(IT);
3120 case LyXFont::SLANTED_SHAPE:
3121 tag_open.push_back(SL);
3128 if (font_old.emph() != font.emph()) {
3129 if (font.emph() == LyXFont::ON) {
3130 tag_open.push_back(EM);
3139 list < PAR_TAG > temp;
3140 while (!tag_state.empty() && tag_close) {
3141 PAR_TAG k = tag_state.top();
3143 os << "</" << tag_name(k) << ">";
3150 for(list< PAR_TAG >::const_iterator j = temp.begin();
3151 j != temp.end(); ++j) {
3153 os << "<" << tag_name(*j) << ">";
3156 for(list< PAR_TAG >::const_iterator j = tag_open.begin();
3157 j != tag_open.end(); ++j) {
3159 os << "<" << tag_name(*j) << ">";
3162 char c = par->getChar(i);
3164 if (c == Paragraph::META_INSET) {
3165 Inset * inset = par->getInset(i);
3166 inset->linuxdoc(this, os);
3171 if (style.latexparam() == "CDATA") {
3172 // "TeX"-Mode on == > SGML-Mode on.
3178 if (par->sgmlConvertChar(c, sgml_string)
3179 && !style.free_spacing && !par->isFreeSpacing())
3181 // in freespacing mode, spaces are
3182 // non-breaking characters
3183 if (desc_on) {// if char is ' ' then...
3186 sgmlLineBreak(os, char_line_count, 6);
3190 sgmlLineBreak(os, char_line_count, 1);
3195 char_line_count += sgml_string.length();
3201 while (!tag_state.empty()) {
3202 os << "</" << tag_name(tag_state.top()) << ">";
3206 // resets description flag correctly
3208 // <tag> not closed...
3209 sgmlLineBreak(os, char_line_count, 6);
3215 // Print an error message.
3216 void Buffer::sgmlError(Paragraph * /*par*/, int /*pos*/,
3217 string const & /*message*/) const
3219 #ifdef WITH_WARNINGS
3220 #warning This is wrong we cannot insert an inset like this!!!
3221 // I guess this was Jose' so I explain you more or less why this
3222 // is wrong. This way you insert something in the paragraph and
3223 // don't tell it to LyXText (row rebreaking and undo handling!!!)
3224 // I deactivate this code, have a look at BufferView::insertErrors
3225 // how you should do this correctly! (Jug 20020315)
3228 // insert an error marker in text
3229 InsetError * new_inset = new InsetError(message);
3230 par->insertInset(pos, new_inset, LyXFont(LyXFont::ALL_INHERIT,
3236 void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
3238 ofstream ofs(fname.c_str());
3240 Alert::alert(_("LYX_ERROR:"), _("Cannot write file"), fname);
3244 Paragraph * par = paragraph;
3246 niceFile = nice; // this will be used by Insetincludes.
3248 LaTeXFeatures features(params);
3253 LyXTextClass const & tclass = textclasslist[params.textclass];
3254 string top_element = tclass.latexname();
3257 ofs << "<!DOCTYPE " << top_element
3258 << " PUBLIC \"-//OASIS//DTD DocBook V4.1//EN\"";
3260 string preamble = params.preamble;
3261 const string name = nice ? ChangeExtension(filename_, ".sgml")
3263 preamble += features.getIncludedFiles(name);
3264 preamble += features.getLyXSGMLEntities();
3266 if (!preamble.empty()) {
3267 ofs << "\n [ " << preamble << " ]";
3272 string top = top_element;
3274 top += params.language->code();
3277 if (!params.options.empty()) {
3279 top += params.options;
3281 sgmlOpenTag(ofs, 0, false, top);
3283 ofs << "<!-- DocBook file was created by " << lyx_docversion
3284 << "\n See http://www.lyx.org/ for more information -->\n";
3286 vector<string> environment_stack(10);
3287 vector<string> environment_inner(10);
3288 vector<string> command_stack(10);
3290 bool command_flag = false;
3291 Paragraph::depth_type command_depth = 0;
3292 Paragraph::depth_type command_base = 0;
3293 Paragraph::depth_type cmd_depth = 0;
3294 Paragraph::depth_type depth = 0; // paragraph depth
3297 string command_name;
3303 int desc_on = 0; // description mode
3305 LyXLayout const & style = tclass[par->layout()];
3307 // environment tag closing
3308 for (; depth > par->params().depth(); --depth) {
3309 if (environment_inner[depth] != "!-- --") {
3310 item_name = "listitem";
3311 sgmlCloseTag(ofs, command_depth + depth, false, item_name);
3312 if (environment_inner[depth] == "varlistentry")
3313 sgmlCloseTag(ofs, depth+command_depth, false, environment_inner[depth]);
3315 sgmlCloseTag(ofs, depth + command_depth, false, environment_stack[depth]);
3316 environment_stack[depth].erase();
3317 environment_inner[depth].erase();
3320 if (depth == par->params().depth()
3321 && environment_stack[depth] != style.latexname()
3322 && !environment_stack[depth].empty()) {
3323 if (environment_inner[depth] != "!-- --") {
3324 item_name= "listitem";
3325 sgmlCloseTag(ofs, command_depth+depth, false, item_name);
3326 if (environment_inner[depth] == "varlistentry")
3327 sgmlCloseTag(ofs, depth + command_depth, false, environment_inner[depth]);
3330 sgmlCloseTag(ofs, depth + command_depth, false, environment_stack[depth]);
3332 environment_stack[depth].erase();
3333 environment_inner[depth].erase();
3336 // Write opening SGML tags.
3337 switch (style.latextype) {
3338 case LATEX_PARAGRAPH:
3339 sgmlOpenTag(ofs, depth + command_depth, false, style.latexname());
3345 _("Error : Wrong depth for "
3346 "LatexType Command.\n"));
3348 command_name = style.latexname();
3350 sgmlparam = style.latexparam();
3351 c_params = split(sgmlparam, c_depth,'|');
3353 cmd_depth = lyx::atoi(c_depth);
3356 if (cmd_depth < command_base) {
3357 for (Paragraph::depth_type j = command_depth;
3358 j >= command_base; --j) {
3359 sgmlCloseTag(ofs, j, false, command_stack[j]);
3362 command_depth = command_base = cmd_depth;
3363 } else if (cmd_depth <= command_depth) {
3364 for (int j = command_depth;
3365 j >= int(cmd_depth); --j) {
3366 sgmlCloseTag(ofs, j, false, command_stack[j]);
3369 command_depth = cmd_depth;
3371 command_depth = cmd_depth;
3373 command_depth = command_base = cmd_depth;
3374 command_flag = true;
3376 if (command_stack.size() == command_depth + 1)
3377 command_stack.push_back(string());
3378 command_stack[command_depth] = command_name;
3380 // treat label as a special case for
3381 // more WYSIWYM handling.
3382 // This is a hack while paragraphs can't have
3383 // attributes, like id in this case.
3384 if (par->isInset(0)) {
3385 Inset * inset = par->getInset(0);
3386 Inset::Code lyx_code = inset->lyxCode();
3387 if (lyx_code == Inset::LABEL_CODE) {
3388 command_name += " id=\"";
3389 command_name += (static_cast<InsetCommand *>(inset))->getContents();
3390 command_name += "\"";
3395 sgmlOpenTag(ofs, depth + command_depth, false, command_name);
3397 item_name = c_params.empty()?"title":c_params;
3398 sgmlOpenTag(ofs, depth + 1 + command_depth, false, item_name);
3401 case LATEX_ENVIRONMENT:
3402 case LATEX_ITEM_ENVIRONMENT:
3403 if (depth < par->params().depth()) {
3404 depth = par->params().depth();
3405 environment_stack[depth].erase();
3408 if (environment_stack[depth] != style.latexname()) {
3409 if (environment_stack.size() == depth + 1) {
3410 environment_stack.push_back("!-- --");
3411 environment_inner.push_back("!-- --");
3413 environment_stack[depth] = style.latexname();
3414 environment_inner[depth] = "!-- --";
3415 sgmlOpenTag(ofs, depth + command_depth, false, environment_stack[depth]);
3417 if (environment_inner[depth] != "!-- --") {
3418 item_name= "listitem";
3419 sgmlCloseTag(ofs, command_depth + depth, false, item_name);
3420 if (environment_inner[depth] == "varlistentry")
3421 sgmlCloseTag(ofs, depth + command_depth, false, environment_inner[depth]);
3425 if (style.latextype == LATEX_ENVIRONMENT) {
3426 if (!style.latexparam().empty()) {
3427 if (style.latexparam() == "CDATA")
3430 sgmlOpenTag(ofs, depth + command_depth, false, style.latexparam());
3435 desc_on = (style.labeltype == LABEL_MANUAL);
3437 environment_inner[depth] = desc_on?"varlistentry": "listitem";
3438 sgmlOpenTag(ofs, depth + 1 + command_depth, false, environment_inner[depth]);
3440 item_name = desc_on? "term": "para";
3441 sgmlOpenTag(ofs, depth + 1 + command_depth, false, item_name);
3444 sgmlOpenTag(ofs, depth + command_depth, false, style.latexname());
3448 simpleDocBookOnePar(ofs, par, desc_on, depth+1+command_depth);
3452 // write closing SGML tags
3453 switch (style.latextype) {
3455 end_tag = c_params.empty()?"title":c_params;
3456 sgmlCloseTag(ofs, depth + command_depth, false, end_tag);
3458 case LATEX_ENVIRONMENT:
3459 if (!style.latexparam().empty()) {
3460 if (style.latexparam() == "CDATA")
3463 sgmlCloseTag(ofs, depth + command_depth, false, style.latexparam());
3466 case LATEX_ITEM_ENVIRONMENT:
3467 if (desc_on == 1) break;
3469 sgmlCloseTag(ofs, depth + 1 + command_depth, false, end_tag);
3471 case LATEX_PARAGRAPH:
3472 sgmlCloseTag(ofs, depth + command_depth, false, style.latexname());
3475 sgmlCloseTag(ofs, depth + command_depth, false, style.latexname());
3481 for (int d = depth; d >= 0; --d) {
3482 if (!environment_stack[depth].empty()) {
3483 if (environment_inner[depth] != "!-- --") {
3484 item_name = "listitem";
3485 sgmlCloseTag(ofs, command_depth + depth, false, item_name);
3486 if (environment_inner[depth] == "varlistentry")
3487 sgmlCloseTag(ofs, depth + command_depth, false, environment_inner[depth]);
3490 sgmlCloseTag(ofs, depth + command_depth, false, environment_stack[depth]);
3494 for (int j = command_depth; j >= 0 ; --j)
3495 if (!command_stack[j].empty()) {
3496 sgmlCloseTag(ofs, j, false, command_stack[j]);
3501 sgmlCloseTag(ofs, 0, false, top_element);
3504 // How to check for successful close
3506 // we want this to be true outside previews (for insetexternal)
3511 void Buffer::simpleDocBookOnePar(ostream & os,
3512 Paragraph * par, int & desc_on,
3513 Paragraph::depth_type depth) const
3515 bool emph_flag = false;
3517 LyXLayout const & style = textclasslist[params.textclass][par->layout()];
3519 LyXFont font_old = style.labeltype == LABEL_MANUAL ? style.labelfont : style.font;
3521 int char_line_count = depth;
3522 //if (!style.free_spacing)
3523 // os << string(depth,' ');
3525 // parsing main loop
3526 for (pos_type i = 0; i < par->size(); ++i) {
3527 LyXFont font = par->getFont(params, i);
3529 // handle <emphasis> tag
3530 if (font_old.emph() != font.emph()) {
3531 if (font.emph() == LyXFont::ON) {
3532 if(style.latexparam() == "CDATA")
3535 if(style.latexparam() == "CDATA")
3539 if(style.latexparam() == "CDATA")
3541 os << "</emphasis>";
3542 if(style.latexparam() == "CDATA")
3549 if (par->isInset(i)) {
3550 Inset * inset = par->getInset(i);
3551 // don't print the inset in position 0 if desc_on == 3 (label)
3552 if ( i || desc_on != 3) {
3553 if(style.latexparam() == "CDATA")
3555 inset->docbook(this, os, false);
3556 if(style.latexparam() == "CDATA")
3560 char c = par->getChar(i);
3562 par->sgmlConvertChar(c, sgml_string);
3564 if (style.pass_thru) {
3566 } else if (style.free_spacing || par->isFreeSpacing() || c != ' ') {
3568 } else if (desc_on ==1) {
3570 os << "\n</term><listitem><para>";
3580 if(style.latexparam() == "CDATA")
3582 os << "</emphasis>";
3583 if(style.latexparam() == "CDATA")
3587 // resets description flag correctly
3589 // <term> not closed...
3590 os << "</term>\n<listitem><para> </para>";
3592 if (style.free_spacing) os << '\n';
3596 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
3597 // Other flags: -wall -v0 -x
3598 int Buffer::runChktex()
3600 if (!users->text) return 0;
3602 users->owner()->prohibitInput();
3604 // get LaTeX-Filename
3605 string const name = getLatexName();
3606 string path = filePath();
3608 string const org_path = path;
3609 if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
3613 Path p(path); // path to LaTeX file
3614 users->owner()->message(_("Running chktex..."));
3616 // Remove all error insets
3617 bool const removedErrorInsets = users->removeAutoInsets();
3619 // Generate the LaTeX file if neccessary
3620 makeLaTeXFile(name, org_path, false);
3623 Chktex chktex(lyxrc.chktex_command, name, filePath());
3624 int res = chktex.run(terr); // run chktex
3627 Alert::alert(_("chktex did not work!"),
3628 _("Could not run with file:"), name);
3629 } else if (res > 0) {
3630 // Insert all errors as errors boxes
3631 users->insertErrors(terr);
3634 // if we removed error insets before we ran chktex or if we inserted
3635 // error insets after we ran chktex, this must be run:
3636 if (removedErrorInsets || res) {
3640 users->owner()->allowInput();
3646 void Buffer::validate(LaTeXFeatures & features) const
3648 Paragraph * par = paragraph;
3649 LyXTextClass const & tclass = textclasslist[params.textclass];
3651 // AMS Style is at document level
3652 if (params.use_amsmath || tclass.provides(LyXTextClass::amsmath))
3653 features.require("amsmath");
3656 // We don't use "lyxerr.debug" because of speed. (Asger)
3657 if (lyxerr.debugging(Debug::LATEX))
3658 lyxerr << "Paragraph: " << par << endl;
3660 // Now just follow the list of paragraphs and run
3661 // validate on each of them.
3662 par->validate(features);
3664 // and then the next paragraph
3668 // the bullet shapes are buffer level not paragraph level
3669 // so they are tested here
3670 for (int i = 0; i < 4; ++i) {
3671 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
3672 int const font = params.user_defined_bullets[i].getFont();
3674 int const c = params
3675 .user_defined_bullets[i]
3682 features.require("latexsym");
3684 } else if (font == 1) {
3685 features.require("amssymb");
3686 } else if ((font >= 2 && font <= 5)) {
3687 features.require("pifont");
3692 if (lyxerr.debugging(Debug::LATEX)) {
3693 features.showStruct();
3698 // This function should be in Buffer because it's a buffer's property (ale)
3699 string const Buffer::getIncludeonlyList(char delim)
3702 for (inset_iterator it = inset_iterator_begin();
3703 it != inset_iterator_end(); ++it) {
3704 if ((*it)->lyxCode() == Inset::INCLUDE_CODE) {
3705 InsetInclude * insetinc =
3706 static_cast<InsetInclude *>(*it);
3707 if (insetinc->isIncludeOnly()) {
3710 lst += insetinc->getRelFileBaseName();
3714 lyxerr[Debug::INFO] << "Includeonly(" << lst << ')' << endl;
3719 vector<string> const Buffer::getLabelList()
3721 /// if this is a child document and the parent is already loaded
3722 /// Use the parent's list instead [ale990407]
3723 if (!params.parentname.empty()
3724 && bufferlist.exists(params.parentname)) {
3725 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3727 return tmp->getLabelList();
3730 vector<string> label_list;
3731 for (inset_iterator it = inset_iterator_begin();
3732 it != inset_iterator_end(); ++it) {
3733 vector<string> const l = (*it)->getLabelList();
3734 label_list.insert(label_list.end(), l.begin(), l.end());
3740 Buffer::Lists const Buffer::getLists() const
3743 Paragraph * par = paragraph;
3745 LyXTextClass const & textclass = textclasslist[params.textclass];
3746 bool found = textclass.hasLayout("Caption");
3747 string const layout("Caption");
3750 char const labeltype = textclass[par->layout()].labeltype;
3752 if (labeltype >= LABEL_COUNTER_CHAPTER
3753 && labeltype <= LABEL_COUNTER_CHAPTER + params.tocdepth) {
3754 // insert this into the table of contents
3755 SingleList & item = l["TOC"];
3758 textclass.maxcounter());
3759 item.push_back(TocItem(par, depth, par->asString(this, true)));
3761 // For each paragrph, traverse its insets and look for
3765 Paragraph::inset_iterator it =
3766 par->inset_iterator_begin();
3767 Paragraph::inset_iterator end =
3768 par->inset_iterator_end();
3770 for (; it != end; ++it) {
3771 if ((*it)->lyxCode() == Inset::FLOAT_CODE) {
3773 static_cast<InsetFloat*>(*it);
3775 string const type = il->type();
3777 // Now find the caption in the float...
3778 // We now tranverse the paragraphs of
3780 Paragraph * tmp = il->inset.paragraph();
3782 if (tmp->layout() == layout) {
3783 SingleList & item = l[type];
3785 tostr(item.size()+1) + ". " + tmp->asString(this, false);
3786 item.push_back(TocItem(tmp, 0 , str));
3793 lyxerr << "Caption not found" << endl;
3802 // This is also a buffer property (ale)
3803 vector<pair<string, string> > const Buffer::getBibkeyList() const
3805 typedef pair<string, string> StringPair;
3806 /// if this is a child document and the parent is already loaded
3807 /// Use the parent's list instead [ale990412]
3808 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3809 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
3811 return tmp->getBibkeyList();
3814 vector<StringPair> keys;
3815 Paragraph * par = paragraph;
3818 string const key = par->bibkey->getContents();
3819 string const opt = par->bibkey->getOptions();
3820 string const ref = par->asString(this, false);
3821 string const info = opt + "TheBibliographyRef" + ref;
3823 keys.push_back(StringPair(key, info));
3828 // Might be either using bibtex or a child has bibliography
3830 for (inset_iterator it = inset_const_iterator_begin();
3831 it != inset_const_iterator_end(); ++it) {
3832 // Search for Bibtex or Include inset
3833 if ((*it)->lyxCode() == Inset::BIBTEX_CODE) {
3834 vector<StringPair> tmp =
3835 static_cast<InsetBibtex*>(*it)->getKeys(this);
3836 keys.insert(keys.end(), tmp.begin(), tmp.end());
3837 } else if ((*it)->lyxCode() == Inset::INCLUDE_CODE) {
3838 vector<StringPair> const tmp =
3839 static_cast<InsetInclude*>(*it)->getKeys();
3840 keys.insert(keys.end(), tmp.begin(), tmp.end());
3849 bool Buffer::isDepClean(string const & name) const
3851 DEPCLEAN * item = dep_clean;
3852 while (item && item->master != name)
3854 if (!item) return true;
3859 void Buffer::markDepClean(string const & name)
3862 dep_clean = new DEPCLEAN;
3863 dep_clean->clean = true;
3864 dep_clean->master = name;
3865 dep_clean->next = 0;
3867 DEPCLEAN * item = dep_clean;
3868 while (item && item->master != name)
3873 item = new DEPCLEAN;
3875 item->master = name;
3882 bool Buffer::dispatch(string const & command, bool * result)
3884 // Split command string into command and argument
3886 string line = frontStrip(command);
3887 string const arg = strip(frontStrip(split(line, cmd, ' ')));
3889 return dispatch(lyxaction.LookupFunc(cmd), arg, result);
3893 bool Buffer::dispatch(int action, string const & argument, bool * result)
3895 bool dispatched = true;
3899 bool const tmp = Exporter::Export(this, argument, false);
3912 void Buffer::resizeInsets(BufferView * bv)
3914 /// then remove all LyXText in text-insets
3915 Paragraph * par = paragraph;
3916 for (; par; par = par->next()) {
3917 par->resizeInsetsLyXText(bv);
3922 void Buffer::redraw()
3929 void Buffer::changeLanguage(Language const * from, Language const * to)
3932 ParIterator end = par_iterator_end();
3933 for (ParIterator it = par_iterator_begin(); it != end; ++it)
3934 (*it)->changeLanguage(params, from, to);
3938 bool Buffer::isMultiLingual()
3940 ParIterator end = par_iterator_end();
3941 for (ParIterator it = par_iterator_begin(); it != end; ++it)
3942 if ((*it)->isMultiLingual(params))
3949 Buffer::inset_iterator::inset_iterator(Paragraph * paragraph, pos_type pos)
3952 it = par->InsetIterator(pos);
3953 if (it == par->inset_iterator_end()) {
3960 void Buffer::inset_iterator::setParagraph()
3963 it = par->inset_iterator_begin();
3964 if (it != par->inset_iterator_end())
3969 // We maintain an invariant that whenever par = 0 then it = 0
3973 Inset * Buffer::getInsetFromID(int id_arg) const
3975 for (inset_iterator it = inset_const_iterator_begin();
3976 it != inset_const_iterator_end(); ++it)
3978 if ((*it)->id() == id_arg)
3980 Inset * in = (*it)->getInsetFromID(id_arg);
3988 Paragraph * Buffer::getParFromID(int id) const
3990 if (id < 0) return 0;
3991 Paragraph * par = paragraph;
3993 if (par->id() == id) {
3996 Paragraph * tmp = par->getParFromID(id);
4006 ParIterator Buffer::par_iterator_begin()
4008 return ParIterator(paragraph);
4012 ParIterator Buffer::par_iterator_end()
4014 return ParIterator();