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"
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>
122 using std::make_pair;
131 using lyx::textclass_type;
133 // all these externs should eventually be removed.
134 extern BufferList bufferlist;
136 extern LyXAction lyxaction;
140 const int LYX_FORMAT = 220;
144 extern int tex_code_break_column;
147 Buffer::Buffer(string const & file, bool ronly)
148 : paragraph(0), niceFile(true), lyx_clean(true), bak_clean(true),
149 unnamed(false), dep_clean(0), read_only(ronly),
150 filename_(file), users(0)
152 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
154 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);
186 Paragraph * par = paragraph;
189 tmppar = par->next();
197 string const Buffer::getLatexName(bool no_path) const
199 string const name = ChangeExtension(MakeLatexName(fileName()), ".tex");
201 return OnlyFilename(name);
207 pair<Buffer::LogType, string> const Buffer::getLogName(void) const
209 string const filename = getLatexName(false);
211 if (filename.empty())
212 return make_pair(Buffer::latexlog, string());
214 string path = OnlyPath(filename);
216 if (lyxrc.use_tempdir || !IsDirWriteable(path))
219 string const fname = AddName(path,
220 OnlyFilename(ChangeExtension(filename,
223 AddName(path, OnlyFilename(
224 ChangeExtension(filename,
225 formats.extension("literate") + ".out")));
227 // If no Latex log or Build log is newer, show Build log
229 FileInfo const f_fi(fname);
230 FileInfo const b_fi(bname);
233 (!f_fi.exist() || f_fi.getModificationTime() < b_fi.getModificationTime())) {
234 lyxerr[Debug::FILES] << "Log name calculated as : " << bname << endl;
235 return make_pair(Buffer::buildlog, bname);
237 lyxerr[Debug::FILES] << "Log name calculated as : " << fname << endl;
238 return make_pair(Buffer::latexlog, fname);
242 void Buffer::setReadonly(bool flag)
244 if (read_only != flag) {
247 users->owner()->getDialogs()->updateBufferDependent(false);
252 /// Update window titles of all users
253 // Should work on a list
254 void Buffer::updateTitles() const
257 users->owner()->updateWindowTitle();
261 /// Reset autosave timer of all users
262 // Should work on a list
263 void Buffer::resetAutosaveTimers() const
266 users->owner()->resetAutosaveTimer();
270 void Buffer::setFileName(string const & newfile)
272 filename_ = MakeAbsPath(newfile);
273 filepath_ = OnlyPath(filename_);
274 setReadonly(IsFileWriteable(filename_) == 0);
279 // We'll remove this later. (Lgb)
282 string last_inset_read;
284 #ifndef NO_COMPABILITY
287 ErtComp() : active(false), fromlayout(false), in_tabular(false) {
296 std::stack<ErtComp> ert_stack;
301 #warning And _why_ is this here? (Lgb)
309 // candidate for move to BufferView
310 // (at least some parts in the beginning of the func)
313 // changed to be public and have one parameter
314 // if par = 0 normal behavior
315 // else insert behavior
316 // Returns false if "\the_end" is not read for formats >= 2.13. (Asger)
317 bool Buffer::readLyXformat2(LyXLex & lex, Paragraph * par)
321 #ifndef NO_COMPABILITY
322 ert_comp.contents.erase();
323 ert_comp.active = false;
324 ert_comp.fromlayout = false;
325 ert_comp.in_tabular = false;
328 Paragraph::depth_type depth = 0;
329 bool the_end_read = false;
331 Paragraph * first_par = 0;
332 LyXFont font(LyXFont::ALL_INHERIT, params.language);
335 if (file_format < 216 && params.language->lang() == "hebrew")
336 font.setLanguage(default_language);
341 par->layout(textclasslist[params.textclass].defaultLayoutName());
343 // We are inserting into an existing document
344 users->text->breakParagraph(users);
345 first_par = users->text->ownerParagraph();
348 // We don't want to adopt the parameters from the
349 // document we insert, so we skip until the text begins:
352 string const pretoken = lex.getString();
353 if (pretoken == "\\layout") {
354 lex.pushToken(pretoken);
362 string const token = lex.getString();
364 if (token.empty()) continue;
366 lyxerr[Debug::PARSER] << "Handling token: `"
367 << token << "'" << endl;
370 parseSingleLyXformat2Token(lex, par, first_par,
378 paragraph = first_par;
380 if (unknown_layouts > 0) {
381 string s = _("Couldn't set the layout for ");
382 if (unknown_layouts == 1) {
383 s += _("one paragraph");
385 s += tostr(unknown_layouts);
386 s += _(" paragraphs");
388 Alert::alert(_("Textclass Loading Error!"), s,
389 _("When reading " + fileName()));
392 if (unknown_tokens > 0) {
393 string s = _("Encountered ");
394 if (unknown_tokens == 1) {
395 s += _("one unknown token");
397 s += tostr(unknown_tokens);
398 s += _(" unknown tokens");
400 Alert::alert(_("Textclass Loading Error!"), s,
401 _("When reading " + fileName()));
408 #ifndef NO_COMPABILITY
410 Inset * Buffer::isErtInset(Paragraph * par, int pos) const
413 if ((par->getChar(pos) == Paragraph::META_INSET) &&
414 (inset = par->getInset(pos)) &&
415 (inset->lyxCode() == Inset::ERT_CODE))
422 void Buffer::insertErtContents(Paragraph * par, int & pos, bool set_inactive)
424 if (ert_comp.contents.find_first_not_of(' ') != string::npos) {
425 // we only skip completely empty ERT (only spaces) otherwise
426 // we have to insert it as is.
427 string str(ert_comp.contents);
428 lyxerr[Debug::INSETS] << "ERT contents:\n'"
429 << str << "'" << endl;
430 // check if we have already an ert inset a position earlier
431 // if this is the case then we should insert the contents
432 // inside the other ertinset as it is stupid to have various
435 if ((pos > 0) && (inset=isErtInset(par, pos-1))) {
436 // get the last paragraph from the inset before
437 Paragraph * last = inset->firstParagraph();
440 // create the new paragraph after the last one
441 Paragraph * par = new Paragraph(last);
442 par->layout(textclasslist[params.textclass].defaultLayoutName());
443 par->setInsetOwner(last->inInset());
445 LyXFont font(LyXFont::ALL_INHERIT, params.language);
446 string::const_iterator cit = str.begin();
447 string::const_iterator end = str.end();
449 for (; cit != end; ++cit) {
450 par->insertChar(pos++, *cit, font);
454 new InsetERT(params, params.language, str, true);
455 par->insertInset(pos++, inset, ert_comp.font);
458 ert_comp.contents.erase();
459 ert_comp.fromlayout = false;
461 ert_comp.active = false;
468 Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
469 Paragraph *& first_par,
470 string const & token, int & pos,
471 Paragraph::depth_type & depth,
475 bool the_end_read = false;
476 #ifndef NO_COMPABILITY
477 #ifndef NO_PEXTRA_REALLY
478 // This is super temporary but is needed to get the compability
479 // mode for minipages work correctly together with new tabulars.
480 static int call_depth;
482 bool checkminipage = false;
483 static Paragraph * minipar = 0;
484 static Paragraph * parBeforeMinipage;
487 if (token[0] != '\\') {
488 #ifndef NO_COMPABILITY
489 if (ert_comp.active) {
490 ert_comp.contents += token;
493 for (string::const_iterator cit = token.begin();
494 cit != token.end(); ++cit) {
495 par->insertChar(pos, (*cit), font);
498 #ifndef NO_COMPABILITY
501 } else if (token == "\\i") {
502 Inset * inset = new InsetLatexAccent;
503 inset->read(this, lex);
504 par->insertInset(pos, inset, font);
506 } else if (token == "\\layout") {
507 #ifndef NO_COMPABILITY
508 bool old_fromlayout = ert_comp.fromlayout;
509 bool create_new_par = true;
510 ert_comp.in_tabular = false;
512 if (!par->size() && par->previous() &&
513 (par->previous()->size() == 1) &&
514 isErtInset(par->previous(), par->previous()->size()-1))
516 int p = par->previous()->size();
517 insertErtContents(par->previous(), p);
518 create_new_par = false;
520 insertErtContents(par, pos);
523 // reset the font as we start a new layout and if the font is
524 // not ALL_INHERIT,document_language then it will be set to the
525 // right values after this tag (Jug 20020420)
526 font = LyXFont(LyXFont::ALL_INHERIT, params.language);
529 if (file_format < 216 && params.language->lang() == "hebrew")
530 font.setLanguage(default_language);
534 string layoutname = lex.getString();
536 LyXTextClass const & tclass = textclasslist[params.textclass];
538 if (layoutname.empty()) {
539 layoutname = tclass.defaultLayoutName();
541 #ifndef NO_COMPABILITY
542 if (compare_no_case(layoutname, "latex") == 0) {
543 ert_comp.active = true;
544 ert_comp.fromlayout = true;
545 ert_comp.font = font;
547 create_new_par = false;
550 bool hasLayout = tclass.hasLayout(layoutname);
552 lyxerr << "Layout '" << layoutname << "' does not"
553 << " exist in textclass '" << tclass.name()
555 lyxerr << "Trying to use default layout instead."
557 layoutname = tclass.defaultLayoutName();
561 // The is the compability reading of layout caption.
562 // It can be removed in LyX version 1.3.0. (Lgb)
563 if (compare_no_case(layoutname, "caption") == 0) {
564 // We expect that the par we are now working on is
565 // really inside a InsetText inside a InsetFloat.
566 // We also know that captions can only be
567 // one paragraph. (Lgb)
569 // We should now read until the next "\layout"
571 // This is probably not good enough, what if the
572 // caption is the last par in the document (Lgb)
573 istream & ist = lex.getStream();
579 if (prefixIs(line, "\\layout")) {
583 if (prefixIs(line, "\\begin_inset"))
585 if (prefixIs(line, "\\end_inset")) {
596 // Now we should have the whole layout in ss
597 // we should now be able to give this to the
599 ss << "\\end_inset\n";
601 // This seems like a bug in stringstream.
602 // We really should be able to use ss
604 istringstream is(ss.str());
606 tmplex.setStream(is);
607 Inset * inset = new InsetCaption;
608 inset->Read(this, tmplex);
609 par->InsertInset(pos, inset, font);
613 #ifndef NO_COMPABILITY
614 if (create_new_par) {
619 par = new Paragraph(par);
620 par->layout(textclasslist[params.textclass].defaultLayoutName());
623 par->layout(layoutname);
624 // Test whether the layout is obsolete.
625 LyXLayout const & layout =
626 textclasslist[params.textclass][par->layout()];
627 if (!layout.obsoleted_by().empty())
628 par->layout(layout.obsoleted_by());
629 par->params().depth(depth);
630 #ifndef NO_COMPABILITY
632 // we duplicate code here because it's easier to remove
633 // the code then of NO_COMPATIBILITY
634 par->layout(layoutname);
635 // Test whether the layout is obsolete.
636 LyXLayout const & layout =
637 textclasslist[params.textclass][par->layout()];
638 if (!layout.obsoleted_by().empty())
639 par->layout(layout.obsoleted_by());
640 par->params().depth(depth);
647 #ifndef NO_COMPABILITY
648 } else if (token == "\\begin_float") {
649 insertErtContents(par, pos);
650 //insertErtContents(par, pos, false);
651 //ert_stack.push(ert_comp);
652 //ert_comp = ErtComp();
654 // This is the compability reader. It can be removed in
655 // LyX version 1.3.0. (Lgb)
657 string const tmptok = lex.getString();
658 //lyxerr << "old float: " << tmptok << endl;
661 stringstream old_float;
663 if (tmptok == "footnote") {
664 inset = new InsetFoot(params);
665 old_float << "collapsed true\n";
666 } else if (tmptok == "margin") {
667 inset = new InsetMarginal(params);
668 old_float << "collapsed true\n";
669 } else if (tmptok == "fig") {
670 inset = new InsetFloat(params, "figure");
671 old_float << "placement htbp\n"
673 << "collapsed false\n";
674 } else if (tmptok == "tab") {
675 inset = new InsetFloat(params, "table");
676 old_float << "placement htbp\n"
678 << "collapsed false\n";
679 } else if (tmptok == "alg") {
680 inset = new InsetFloat(params, "algorithm");
681 old_float << "placement htbp\n"
683 << "collapsed false\n";
684 } else if (tmptok == "wide-fig") {
685 inset = new InsetFloat(params, "figure");
686 //InsetFloat * tmp = new InsetFloat("figure");
689 old_float << "placement htbp\n"
691 << "collapsed false\n";
692 } else if (tmptok == "wide-tab") {
693 inset = new InsetFloat(params, "table");
694 //InsetFloat * tmp = new InsetFloat("table");
697 old_float << "placement htbp\n"
699 << "collapsed false\n";
703 #ifndef NO_PEXTRA_REALLY
706 return false; // no end read yet
709 // Here we need to check for \end_deeper and handle that
710 // before we do the footnote parsing.
711 // This _is_ a hack! (Lgb)
714 string const tmp = lex.getString();
715 if (tmp == "\\end_deeper") {
716 //lyxerr << "\\end_deeper caught!" << endl;
718 lex.printError("\\end_deeper: "
719 "depth is already null");
724 old_float << tmp << ' ';
729 old_float << lex.getLongString("\\end_float")
730 << "\n\\end_inset\n";
731 //lyxerr << "Float Body:\n" << old_float.str() << endl;
732 // That this does not work seems like a bug
733 // in stringstream. (Lgb)
734 istringstream istr(old_float.str());
736 nylex.setStream(istr);
737 inset->read(this, nylex);
739 par->insertInset(pos, inset, font);
741 insertErtContents(par, pos);
743 // we have to reset the font as in the old format after a float
744 // the font was automatically reset!
745 font = LyXFont(LyXFont::ALL_INHERIT, params.language);
747 } else if (token == "\\begin_deeper") {
749 } else if (token == "\\end_deeper") {
751 lex.printError("\\end_deeper: "
752 "depth is already null");
756 } else if (token == "\\begin_preamble") {
757 params.readPreamble(lex);
758 } else if (token == "\\textclass") {
760 pair<bool, textclass_type> pp =
761 textclasslist.NumberOfClass(lex.getString());
763 params.textclass = pp.second;
765 Alert::alert(string(_("Textclass error")),
766 string(_("The document uses an unknown textclass \"")) +
767 lex.getString() + string("\"."),
768 string(_("LyX will not be able to produce output correctly.")));
769 params.textclass = 0;
771 if (!textclasslist[params.textclass].load()) {
772 // if the textclass wasn't loaded properly
773 // we need to either substitute another
774 // or stop loading the file.
775 // I can substitute but I don't see how I can
776 // stop loading... ideas?? ARRae980418
777 Alert::alert(_("Textclass Loading Error!"),
778 string(_("Can't load textclass ")) +
779 textclasslist[params.textclass].name(),
780 _("-- substituting default"));
781 params.textclass = 0;
783 } else if (token == "\\options") {
785 params.options = lex.getString();
786 } else if (token == "\\language") {
787 params.readLanguage(lex);
788 } else if (token == "\\fontencoding") {
790 } else if (token == "\\inputencoding") {
792 params.inputenc = lex.getString();
793 } else if (token == "\\graphics") {
794 params.readGraphicsDriver(lex);
795 } else if (token == "\\fontscheme") {
797 params.fonts = lex.getString();
798 } else if (token == "\\noindent") {
799 par->params().noindent(true);
800 } else if (token == "\\leftindent") {
802 LyXLength value(lex.getString());
803 par->params().leftIndent(value);
804 } else if (token == "\\fill_top") {
805 par->params().spaceTop(VSpace(VSpace::VFILL));
806 } else if (token == "\\fill_bottom") {
807 par->params().spaceBottom(VSpace(VSpace::VFILL));
808 } else if (token == "\\line_top") {
809 par->params().lineTop(true);
810 } else if (token == "\\line_bottom") {
811 par->params().lineBottom(true);
812 } else if (token == "\\pagebreak_top") {
813 par->params().pagebreakTop(true);
814 } else if (token == "\\pagebreak_bottom") {
815 par->params().pagebreakBottom(true);
816 } else if (token == "\\start_of_appendix") {
817 par->params().startOfAppendix(true);
818 } else if (token == "\\paragraph_separation") {
819 int tmpret = lex.findToken(string_paragraph_separation);
822 if (tmpret != LYX_LAYOUT_DEFAULT)
823 params.paragraph_separation =
824 static_cast<BufferParams::PARSEP>(tmpret);
825 } else if (token == "\\defskip") {
827 params.defskip = VSpace(lex.getString());
828 #ifndef NO_COMPABILITY
829 } else if (token == "\\epsfig") { // obsolete
830 // Indeed it is obsolete, but we HAVE to be backwards
831 // compatible until 0.14, because otherwise all figures
832 // in existing documents are irretrivably lost. (Asger)
833 params.readGraphicsDriver(lex);
835 } else if (token == "\\quotes_language") {
836 int tmpret = lex.findToken(string_quotes_language);
839 if (tmpret != LYX_LAYOUT_DEFAULT) {
840 InsetQuotes::quote_language tmpl =
841 InsetQuotes::EnglishQ;
844 tmpl = InsetQuotes::EnglishQ;
847 tmpl = InsetQuotes::SwedishQ;
850 tmpl = InsetQuotes::GermanQ;
853 tmpl = InsetQuotes::PolishQ;
856 tmpl = InsetQuotes::FrenchQ;
859 tmpl = InsetQuotes::DanishQ;
862 params.quotes_language = tmpl;
864 } else if (token == "\\quotes_times") {
866 switch (lex.getInteger()) {
868 params.quotes_times = InsetQuotes::SingleQ;
871 params.quotes_times = InsetQuotes::DoubleQ;
874 } else if (token == "\\papersize") {
875 int tmpret = lex.findToken(string_papersize);
879 params.papersize2 = tmpret;
880 } else if (token == "\\paperpackage") {
881 int tmpret = lex.findToken(string_paperpackages);
884 params.paperpackage = BufferParams::PACKAGE_NONE;
886 params.paperpackage = tmpret;
887 } else if (token == "\\use_geometry") {
889 params.use_geometry = lex.getInteger();
890 } else if (token == "\\use_amsmath") {
892 params.use_amsmath = lex.getInteger();
893 } else if (token == "\\use_natbib") {
895 params.use_natbib = lex.getInteger();
896 } else if (token == "\\use_numerical_citations") {
898 params.use_numerical_citations = lex.getInteger();
899 } else if (token == "\\paperorientation") {
900 int tmpret = lex.findToken(string_orientation);
903 if (tmpret != LYX_LAYOUT_DEFAULT)
904 params.orientation = static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
905 } else if (token == "\\paperwidth") {
907 params.paperwidth = lex.getString();
908 } else if (token == "\\paperheight") {
910 params.paperheight = lex.getString();
911 } else if (token == "\\leftmargin") {
913 params.leftmargin = lex.getString();
914 } else if (token == "\\topmargin") {
916 params.topmargin = lex.getString();
917 } else if (token == "\\rightmargin") {
919 params.rightmargin = lex.getString();
920 } else if (token == "\\bottommargin") {
922 params.bottommargin = lex.getString();
923 } else if (token == "\\headheight") {
925 params.headheight = lex.getString();
926 } else if (token == "\\headsep") {
928 params.headsep = lex.getString();
929 } else if (token == "\\footskip") {
931 params.footskip = lex.getString();
932 } else if (token == "\\paperfontsize") {
934 params.fontsize = strip(lex.getString());
935 } else if (token == "\\papercolumns") {
937 params.columns = lex.getInteger();
938 } else if (token == "\\papersides") {
940 switch (lex.getInteger()) {
942 case 1: params.sides = LyXTextClass::OneSide; break;
943 case 2: params.sides = LyXTextClass::TwoSides; break;
945 } else if (token == "\\paperpagestyle") {
947 params.pagestyle = strip(lex.getString());
948 } else if (token == "\\bullet") {
950 int const index = lex.getInteger();
952 int temp_int = lex.getInteger();
953 params.user_defined_bullets[index].setFont(temp_int);
954 params.temp_bullets[index].setFont(temp_int);
956 temp_int = lex.getInteger();
957 params.user_defined_bullets[index].setCharacter(temp_int);
958 params.temp_bullets[index].setCharacter(temp_int);
960 temp_int = lex.getInteger();
961 params.user_defined_bullets[index].setSize(temp_int);
962 params.temp_bullets[index].setSize(temp_int);
964 string const temp_str = lex.getString();
965 if (temp_str != "\\end_bullet") {
966 // this element isn't really necessary for
967 // parsing but is easier for humans
968 // to understand bullets. Put it back and
969 // set a debug message?
970 lex.printError("\\end_bullet expected, got" + temp_str);
971 //how can I put it back?
973 } else if (token == "\\bulletLaTeX") {
974 // The bullet class should be able to read this.
976 int const index = lex.getInteger();
978 string temp_str = lex.getString();
980 while (temp_str != "\\end_bullet") {
981 // this loop structure is needed when user
982 // enters an empty string since the first
983 // thing returned will be the \\end_bullet
985 // if the LaTeX entry has spaces. Each element
986 // therefore needs to be read in turn
989 temp_str = lex.getString();
992 params.user_defined_bullets[index].setText(sum_str);
993 params.temp_bullets[index].setText(sum_str);
994 } else if (token == "\\secnumdepth") {
996 params.secnumdepth = lex.getInteger();
997 } else if (token == "\\tocdepth") {
999 params.tocdepth = lex.getInteger();
1000 } else if (token == "\\spacing") {
1002 string const tmp = strip(lex.getString());
1003 Spacing::Space tmp_space = Spacing::Default;
1004 float tmp_val = 0.0;
1005 if (tmp == "single") {
1006 tmp_space = Spacing::Single;
1007 } else if (tmp == "onehalf") {
1008 tmp_space = Spacing::Onehalf;
1009 } else if (tmp == "double") {
1010 tmp_space = Spacing::Double;
1011 } else if (tmp == "other") {
1013 tmp_space = Spacing::Other;
1014 tmp_val = lex.getFloat();
1016 lex.printError("Unknown spacing token: '$$Token'");
1018 // Small hack so that files written with klyx will be
1019 // parsed correctly.
1021 par->params().spacing(Spacing(tmp_space, tmp_val));
1023 params.spacing.set(tmp_space, tmp_val);
1025 } else if (token == "\\paragraph_spacing") {
1027 string const tmp = strip(lex.getString());
1028 if (tmp == "single") {
1029 par->params().spacing(Spacing(Spacing::Single));
1030 } else if (tmp == "onehalf") {
1031 par->params().spacing(Spacing(Spacing::Onehalf));
1032 } else if (tmp == "double") {
1033 par->params().spacing(Spacing(Spacing::Double));
1034 } else if (tmp == "other") {
1036 par->params().spacing(Spacing(Spacing::Other,
1039 lex.printError("Unknown spacing token: '$$Token'");
1041 } else if (token == "\\float_placement") {
1043 params.float_placement = lex.getString();
1044 } else if (token == "\\family") {
1046 font.setLyXFamily(lex.getString());
1047 } else if (token == "\\series") {
1049 font.setLyXSeries(lex.getString());
1050 } else if (token == "\\shape") {
1052 font.setLyXShape(lex.getString());
1053 } else if (token == "\\size") {
1055 font.setLyXSize(lex.getString());
1056 #ifndef NO_COMPABILITY
1057 } else if (token == "\\latex") {
1059 string const tok = lex.getString();
1060 if (tok == "no_latex") {
1062 insertErtContents(par, pos);
1063 } else if (tok == "latex") {
1064 ert_comp.active = true;
1065 ert_comp.font = font;
1066 } else if (tok == "default") {
1068 insertErtContents(par, pos);
1070 lex.printError("Unknown LaTeX font flag "
1074 } else if (token == "\\lang") {
1076 string const tok = lex.getString();
1077 Language const * lang = languages.getLanguage(tok);
1079 font.setLanguage(lang);
1081 font.setLanguage(params.language);
1082 lex.printError("Unknown language `$$Token'");
1084 #ifndef NO_COMPABILITY
1085 // if the contents is still empty we're just behind the
1086 // latex font change and so this inset should also be
1087 // inserted with that language tag!
1088 if (ert_comp.active && ert_comp.contents.empty()) {
1089 ert_comp.font.setLanguage(font.language());
1092 } else if (token == "\\numeric") {
1094 font.setNumber(font.setLyXMisc(lex.getString()));
1095 } else if (token == "\\emph") {
1097 font.setEmph(font.setLyXMisc(lex.getString()));
1098 } else if (token == "\\bar") {
1100 string const tok = lex.getString();
1101 // This is dirty, but gone with LyX3. (Asger)
1103 font.setUnderbar(LyXFont::ON);
1104 else if (tok == "no")
1105 font.setUnderbar(LyXFont::OFF);
1106 else if (tok == "default")
1107 font.setUnderbar(LyXFont::INHERIT);
1109 lex.printError("Unknown bar font flag "
1111 } else if (token == "\\noun") {
1113 font.setNoun(font.setLyXMisc(lex.getString()));
1114 } else if (token == "\\color") {
1116 font.setLyXColor(lex.getString());
1117 } else if (token == "\\align") {
1118 int tmpret = lex.findToken(string_align);
1119 if (tmpret == -1) ++tmpret;
1120 if (tmpret != LYX_LAYOUT_DEFAULT) { // tmpret != 99 ???
1121 int const tmpret2 = int(pow(2.0, tmpret));
1122 //lyxerr << "Tmpret2 = " << tmpret2 << endl;
1123 par->params().align(LyXAlignment(tmpret2));
1125 } else if (token == "\\added_space_top") {
1127 VSpace value = VSpace(lex.getString());
1128 if ((value.length().len().value() != 0) ||
1129 (value.kind() != VSpace::LENGTH))
1130 par->params().spaceTop(value);
1131 } else if (token == "\\added_space_bottom") {
1133 VSpace value = VSpace(lex.getString());
1134 if ((value.length().len().value() != 0) ||
1135 (value.kind() != VSpace::LENGTH))
1136 par->params().spaceBottom(value);
1137 #ifndef NO_COMPABILITY
1138 #ifndef NO_PEXTRA_REALLY
1139 } else if (token == "\\pextra_type") {
1141 par->params().pextraType(lex.getInteger());
1142 } else if (token == "\\pextra_width") {
1144 par->params().pextraWidth(lex.getString());
1145 } else if (token == "\\pextra_widthp") {
1147 par->params().pextraWidthp(lex.getString());
1148 } else if (token == "\\pextra_alignment") {
1150 par->params().pextraAlignment(lex.getInteger());
1151 } else if (token == "\\pextra_hfill") {
1153 par->params().pextraHfill(lex.getInteger());
1154 } else if (token == "\\pextra_start_minipage") {
1156 par->params().pextraStartMinipage(lex.getInteger());
1159 } else if (token == "\\labelwidthstring") {
1161 par->params().labelWidthString(lex.getString());
1162 // do not delete this token, it is still needed!
1163 } else if (token == "\\end_inset") {
1164 lyxerr << "Solitary \\end_inset. Missing \\begin_inset?.\n"
1165 << "Last inset read was: " << last_inset_read
1167 // Simply ignore this. The insets do not have
1169 // But insets should read it, it is a part of
1170 // the inset isn't it? Lgb.
1171 } else if (token == "\\begin_inset") {
1172 #ifndef NO_COMPABILITY
1173 insertErtContents(par, pos, false);
1174 ert_stack.push(ert_comp);
1175 ert_comp = ErtComp();
1177 readInset(lex, par, pos, font);
1178 #ifndef NO_COMPABILITY
1179 ert_comp = ert_stack.top();
1182 } else if (token == "\\SpecialChar") {
1183 LyXLayout const & layout =
1184 textclasslist[params.textclass][par->layout()];
1186 // Insets don't make sense in a free-spacing context! ---Kayvan
1187 if (layout.free_spacing || par->isFreeSpacing()) {
1190 string next_token = lex.getString();
1191 if (next_token == "\\-") {
1192 par->insertChar(pos, '-', font);
1193 } else if (next_token == "\\protected_separator"
1194 || next_token == "~") {
1195 par->insertChar(pos, ' ', font);
1197 lex.printError("Token `$$Token' "
1199 "paragraph layout!");
1204 Inset * inset = new InsetSpecialChar;
1205 inset->read(this, lex);
1206 par->insertInset(pos, inset, font);
1209 } else if (token == "\\newline") {
1210 #ifndef NO_COMPABILITY
1211 if (!ert_comp.in_tabular && ert_comp.active) {
1212 ert_comp.contents += char(Paragraph::META_NEWLINE);
1214 // Since we cannot know it this is only a regular
1215 // newline or a tabular cell delimter we have to
1216 // handle the ERT here.
1217 insertErtContents(par, pos, false);
1219 par->insertChar(pos, Paragraph::META_NEWLINE, font);
1223 par->insertChar(pos, Paragraph::META_NEWLINE, font);
1226 } else if (token == "\\LyXTable") {
1227 #ifndef NO_COMPABILITY
1228 ert_comp.in_tabular = true;
1230 Inset * inset = new InsetTabular(*this);
1231 inset->read(this, lex);
1232 par->insertInset(pos, inset, font);
1234 } else if (token == "\\hfill") {
1235 par->insertChar(pos, Paragraph::META_HFILL, font);
1237 } else if (token == "\\protected_separator") { // obsolete
1238 // This is a backward compability thingie. (Lgb)
1239 // Remove it later some time...introduced with fileformat
1241 LyXLayout const & layout =
1242 textclasslist[params.textclass][par->layout()];
1244 if (layout.free_spacing || par->isFreeSpacing()) {
1245 par->insertChar(pos, ' ', font);
1247 Inset * inset = new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
1248 par->insertInset(pos, inset, font);
1251 } else if (token == "\\bibitem") { // ale970302
1253 InsetCommandParams p("bibitem", "dummy");
1254 par->bibkey = new InsetBibKey(p);
1256 par->bibkey->read(this, lex);
1257 } else if (token == "\\backslash") {
1258 #ifndef NO_COMPABILITY
1259 if (ert_comp.active) {
1260 ert_comp.contents += "\\";
1263 par->insertChar(pos, '\\', font);
1265 #ifndef NO_COMPABILITY
1268 } else if (token == "\\the_end") {
1269 #ifndef NO_COMPABILITY
1270 // If we still have some ert active here we have to insert
1271 // it so we don't loose it. (Lgb)
1272 insertErtContents(par, pos);
1274 the_end_read = true;
1275 #ifndef NO_COMPABILITY
1276 #ifndef NO_PEXTRA_REALLY
1279 minipar = parBeforeMinipage = 0;
1283 #ifndef NO_COMPABILITY
1284 if (ert_comp.active) {
1285 ert_comp.contents += token;
1288 // This should be insurance for the future: (Asger)
1291 string const s = _("Unknown token: ") + token
1292 + " " + lex.text() + "\n";
1293 // we can do this here this way because we're actually reading
1294 // the buffer and don't care about LyXText right now.
1295 InsetError * new_inset = new InsetError(s);
1296 par->insertInset(pos, new_inset, LyXFont(LyXFont::ALL_INHERIT,
1299 #ifndef NO_COMPABILITY
1304 #ifndef NO_COMPABILITY
1305 #ifndef NO_PEXTRA_REALLY
1306 // I wonder if we could use this blanket fix for all the
1307 // checkminipage cases...
1308 // don't forget about ert paragraphs and compatibility read for'em
1309 if (par && (par->size() || !ert_comp.contents.empty())) {
1310 // It is possible that this will check to often,
1311 // but that should not be an correctness issue.
1312 // Only a speed issue.
1313 checkminipage = true;
1316 // now check if we have a minipage paragraph as at this
1317 // point we already read all the necessary data!
1318 // this cannot be done in layout because there we did
1319 // not read yet the paragraph PEXTRA-params (Jug)
1321 // BEGIN pextra_minipage compability
1322 // This should be removed in 1.3.x (Lgb)
1323 // I don't think we should remove this so fast (Jug)
1325 // This compability code is not perfect. In a couple
1326 // of rand cases it fails. When the minipage par is
1327 // the first par in the document, and when there are
1328 // none or only one regular paragraphs after the
1329 // minipage. Currently I am not investing any effort
1330 // in fixing those cases.
1332 // lyxerr << "Call depth: " << call_depth << endl;
1333 // lyxerr << "Checkminipage: " << checkminipage << endl;
1335 if (checkminipage && (call_depth == 1)) {
1336 checkminipage = false;
1337 if (minipar && (minipar != par) &&
1338 (par->params().pextraType() == Paragraph::PEXTRA_MINIPAGE)) {
1339 lyxerr << "minipages in a row" << endl;
1340 if (par->params().pextraStartMinipage()) {
1341 lyxerr << "start new minipage" << endl;
1342 // minipages in a row
1343 par->previous()->next(0);
1346 Paragraph * tmp = minipar;
1348 tmp->params().pextraType(0);
1349 tmp->params().pextraWidth(string());
1350 tmp->params().pextraWidthp(string());
1351 tmp->params().pextraAlignment(0);
1352 tmp->params().pextraHfill(false);
1353 tmp->params().pextraStartMinipage(false);
1356 // create a new paragraph to insert the
1357 // minipages in the following case
1358 if (par->params().pextraStartMinipage() &&
1359 !par->params().pextraHfill()) {
1360 Paragraph * p = new Paragraph;
1361 p->layout(textclasslist[params.textclass].defaultLayoutName());
1363 p->previous(parBeforeMinipage);
1364 parBeforeMinipage->next(p);
1366 p->params().depth(parBeforeMinipage->params().depth());
1367 parBeforeMinipage = p;
1369 InsetMinipage * mini = new InsetMinipage(params);
1370 mini->pos(static_cast<InsetMinipage::Position>(par->params().pextraAlignment()));
1371 mini->pageWidth(LyXLength(par->params().pextraWidth()));
1372 if (!par->params().pextraWidthp().empty()) {
1373 lyxerr << "WP:" << mini->pageWidth().asString() << endl;
1374 mini->pageWidth(LyXLength((par->params().pextraWidthp())+"col%"));
1376 Paragraph * op = mini->firstParagraph();
1377 mini->inset.paragraph(par);
1379 // and free the old ones!
1382 Paragraph * pp = op->next();
1386 // Insert the minipage last in the
1387 // previous paragraph.
1388 if (par->params().pextraHfill()) {
1389 parBeforeMinipage->insertChar
1390 (parBeforeMinipage->size(),
1391 Paragraph::META_HFILL, font);
1393 parBeforeMinipage->insertInset
1394 (parBeforeMinipage->size(), mini, font);
1398 lyxerr << "new minipage par" << endl;
1399 //nothing to do just continue reading
1402 } else if (minipar && (minipar != par)) {
1403 lyxerr << "last minipage par read" << endl;
1404 // The last paragraph read was not part of a
1405 // minipage but the par linked list is...
1406 // So we need to remove the last par from the
1408 if (par->previous())
1409 par->previous()->next(0);
1410 par->previous(parBeforeMinipage);
1411 parBeforeMinipage->next(par);
1412 Paragraph * tmp = minipar;
1414 tmp->params().pextraType(0);
1415 tmp->params().pextraWidth(string());
1416 tmp->params().pextraWidthp(string());
1417 tmp->params().pextraAlignment(0);
1418 tmp->params().pextraHfill(false);
1419 tmp->params().pextraStartMinipage(false);
1422 depth = parBeforeMinipage->params().depth();
1423 // and set this depth on the par as it has not been set already
1424 par->params().depth(depth);
1425 minipar = parBeforeMinipage = 0;
1426 } else if (!minipar &&
1427 (par->params().pextraType() == Paragraph::PEXTRA_MINIPAGE)) {
1428 // par is the first paragraph in a minipage
1429 lyxerr << "begin minipage" << endl;
1430 // To minimize problems for
1431 // the users we will insert
1432 // the first minipage in
1433 // a sequence of minipages
1434 // in its own paragraph.
1435 Paragraph * p = new Paragraph;
1436 p->layout(textclasslist[params.textclass].defaultLayoutName());
1437 p->previous(par->previous());
1439 p->params().depth(depth);
1440 par->params().depth(0);
1442 if (par->previous())
1443 par->previous()->next(p);
1445 parBeforeMinipage = p;
1447 if (!first_par || (first_par == par))
1450 InsetMinipage * mini = new InsetMinipage(params);
1451 mini->pos(static_cast<InsetMinipage::Position>(minipar->params().pextraAlignment()));
1452 mini->pageWidth(LyXLength(minipar->params().pextraWidth()));
1453 if (!par->params().pextraWidthp().empty()) {
1454 lyxerr << "WP:" << mini->pageWidth().asString() << endl;
1455 mini->pageWidth(LyXLength((par->params().pextraWidthp())+"col%"));
1458 Paragraph * op = mini->firstParagraph();
1459 mini->inset.paragraph(minipar);
1461 // and free the old ones!
1464 Paragraph * pp = op->next();
1469 // Insert the minipage last in the
1470 // previous paragraph.
1471 if (minipar->params().pextraHfill()) {
1472 parBeforeMinipage->insertChar
1473 (parBeforeMinipage->size(),
1474 Paragraph::META_HFILL, font);
1476 parBeforeMinipage->insertInset
1477 (parBeforeMinipage->size(), mini, font);
1478 } else if (par->params().pextraType() == Paragraph::PEXTRA_INDENT) {
1479 par->params().leftIndent(LyXLength(par->params().pextraWidth()));
1480 if (!par->params().pextraWidthp().empty()) {
1481 par->params().leftIndent(LyXLength((par->params().pextraWidthp())+"col%"));
1485 // End of pextra_minipage compability
1489 return the_end_read;
1492 // needed to insert the selection
1493 void Buffer::insertStringAsLines(Paragraph *& par, pos_type & pos,
1494 LyXFont const & fn,string const & str) const
1496 LyXLayout const & layout =
1497 textclasslist[params.textclass][par->layout()];
1500 par->checkInsertChar(font);
1501 // insert the string, don't insert doublespace
1502 bool space_inserted = true;
1503 bool autobreakrows = !par->inInset() ||
1504 static_cast<InsetText *>(par->inInset())->getAutoBreakRows();
1505 for(string::const_iterator cit = str.begin();
1506 cit != str.end(); ++cit) {
1508 if (autobreakrows && (par->size() || layout.keepempty)) {
1509 par->breakParagraph(params, pos,
1510 layout.isEnvironment());
1513 space_inserted = true;
1517 // do not insert consecutive spaces if !free_spacing
1518 } else if ((*cit == ' ' || *cit == '\t') &&
1519 space_inserted && !layout.free_spacing &&
1520 !par->isFreeSpacing())
1523 } else if (*cit == '\t') {
1524 if (!layout.free_spacing && !par->isFreeSpacing()) {
1525 // tabs are like spaces here
1526 par->insertChar(pos, ' ', font);
1528 space_inserted = true;
1530 const pos_type nb = 8 - pos % 8;
1531 for (pos_type a = 0; a < nb ; ++a) {
1532 par->insertChar(pos, ' ', font);
1535 space_inserted = true;
1537 } else if (!IsPrintable(*cit)) {
1538 // Ignore unprintables
1541 // just insert the character
1542 par->insertChar(pos, *cit, font);
1544 space_inserted = (*cit == ' ');
1551 void Buffer::readInset(LyXLex & lex, Paragraph *& par,
1552 int & pos, LyXFont & font)
1554 // consistency check
1555 if (lex.getString() != "\\begin_inset") {
1556 lyxerr << "Buffer::readInset: Consistency check failed."
1563 string const tmptok = lex.getString();
1564 last_inset_read = tmptok;
1566 // test the different insets
1567 if (tmptok == "LatexCommand") {
1568 InsetCommandParams inscmd;
1571 string const cmdName = inscmd.getCmdName();
1573 // This strange command allows LyX to recognize "natbib" style
1574 // citations: citet, citep, Citet etc.
1575 if (compare_no_case(cmdName, "cite", 4) == 0) {
1576 inset = new InsetCitation(inscmd);
1577 } else if (cmdName == "bibitem") {
1578 lex.printError("Wrong place for bibitem");
1579 inset = new InsetBibKey(inscmd);
1580 } else if (cmdName == "BibTeX") {
1581 inset = new InsetBibtex(inscmd);
1582 } else if (cmdName == "index") {
1583 inset = new InsetIndex(inscmd);
1584 } else if (cmdName == "include") {
1585 inset = new InsetInclude(inscmd, *this);
1586 } else if (cmdName == "label") {
1587 inset = new InsetLabel(inscmd);
1588 } else if (cmdName == "url"
1589 || cmdName == "htmlurl") {
1590 inset = new InsetUrl(inscmd);
1591 } else if (cmdName == "ref"
1592 || cmdName == "pageref"
1593 || cmdName == "vref"
1594 || cmdName == "vpageref"
1595 || cmdName == "prettyref") {
1596 if (!inscmd.getOptions().empty()
1597 || !inscmd.getContents().empty()) {
1598 inset = new InsetRef(inscmd, *this);
1600 } else if (cmdName == "tableofcontents") {
1601 inset = new InsetTOC(inscmd);
1602 } else if (cmdName == "listofalgorithms") {
1603 inset = new InsetFloatList("algorithm");
1604 } else if (cmdName == "listoffigures") {
1605 inset = new InsetFloatList("figure");
1606 } else if (cmdName == "listoftables") {
1607 inset = new InsetFloatList("table");
1608 } else if (cmdName == "printindex") {
1609 inset = new InsetPrintIndex(inscmd);
1610 } else if (cmdName == "lyxparent") {
1611 inset = new InsetParent(inscmd, *this);
1614 bool alreadyread = false;
1615 if (tmptok == "Quotes") {
1616 inset = new InsetQuotes;
1617 } else if (tmptok == "External") {
1618 inset = new InsetExternal;
1619 } else if (tmptok == "FormulaMacro") {
1620 inset = new InsetFormulaMacro;
1621 } else if (tmptok == "Formula") {
1622 inset = new InsetFormula;
1623 } else if (tmptok == "Figure") { // Backward compatibility
1624 // inset = new InsetFig(100, 100, *this);
1625 inset = new InsetGraphics;
1626 } else if (tmptok == "Graphics") {
1627 inset = new InsetGraphics;
1628 } else if (tmptok == "Info") {// backwards compatibility
1629 inset = new InsetNote(this,
1630 lex.getLongString("\\end_inset"),
1633 } else if (tmptok == "Note") {
1634 inset = new InsetNote(params);
1635 } else if (tmptok == "Include") {
1636 InsetCommandParams p("Include");
1637 inset = new InsetInclude(p, *this);
1638 } else if (tmptok == "ERT") {
1639 inset = new InsetERT(params);
1640 } else if (tmptok == "Tabular") {
1641 inset = new InsetTabular(*this);
1642 } else if (tmptok == "Text") {
1643 inset = new InsetText(params);
1644 } else if (tmptok == "Foot") {
1645 inset = new InsetFoot(params);
1646 } else if (tmptok == "Marginal") {
1647 inset = new InsetMarginal(params);
1648 } else if (tmptok == "Minipage") {
1649 inset = new InsetMinipage(params);
1650 } else if (tmptok == "Float") {
1652 string tmptok = lex.getString();
1653 inset = new InsetFloat(params, tmptok);
1655 } else if (tmptok == "List") {
1656 inset = new InsetList;
1657 } else if (tmptok == "Theorem") {
1658 inset = new InsetList;
1660 } else if (tmptok == "Caption") {
1661 inset = new InsetCaption(params);
1662 } else if (tmptok == "FloatList") {
1663 inset = new InsetFloatList;
1666 if (inset && !alreadyread) inset->read(this, lex);
1670 par->insertInset(pos, inset, font);
1676 bool Buffer::readFile(LyXLex & lex, Paragraph * par)
1680 string const token(lex.getString());
1681 if (token == "\\lyxformat") { // the first token _must_ be...
1683 string tmp_format = lex.getString();
1684 //lyxerr << "LyX Format: `" << tmp_format << "'" << endl;
1685 // if present remove ".," from string.
1686 string::size_type dot = tmp_format.find_first_of(".,");
1687 //lyxerr << " dot found at " << dot << endl;
1688 if (dot != string::npos)
1689 tmp_format.erase(dot, 1);
1690 file_format = strToInt(tmp_format);
1691 if (file_format == LYX_FORMAT) {
1693 } else if (file_format > LYX_FORMAT) {
1695 Alert::alert(_("Warning!"),
1696 _("LyX file format is newer that what"),
1697 _("is supported in this LyX version. Expect some problems."));
1699 } else if (file_format < LYX_FORMAT) {
1701 if (file_format < 200) {
1702 Alert::alert(_("ERROR!"),
1703 _("Old LyX file format found. "
1704 "Use LyX 0.10.x to read this!"));
1706 } else if (file_format < 220) {
1707 Alert::alert(_("ERROR!"),
1708 _("Old LyX file format found. "
1709 "User LyX 1.2.x to read this!"));
1713 bool the_end = readLyXformat2(lex, par);
1714 params.setPaperStuff();
1717 // the_end was added in 213
1718 if (file_format < 213)
1723 Alert::alert(_("Warning!"),
1724 _("Reading of document is not complete"),
1725 _("Maybe the document is truncated"));
1728 } else { // "\\lyxformat" not found
1729 Alert::alert(_("ERROR!"), _("Not a LyX file!"));
1732 Alert::alert(_("ERROR!"), _("Unable to read file!"));
1737 // Should probably be moved to somewhere else: BufferView? LyXView?
1738 bool Buffer::save() const
1740 // We don't need autosaves in the immediate future. (Asger)
1741 resetAutosaveTimers();
1745 if (lyxrc.make_backup) {
1746 s = fileName() + '~';
1747 if (!lyxrc.backupdir_path.empty())
1748 s = AddName(lyxrc.backupdir_path,
1749 subst(os::slashify_path(s),'/','!'));
1751 // Rename is the wrong way of making a backup,
1752 // this is the correct way.
1753 /* truss cp fil fil2:
1754 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
1755 stat("LyXVC.lyx", 0xEFFFF688) = 0
1756 open("LyXVC.lyx", O_RDONLY) = 3
1757 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
1758 fstat(4, 0xEFFFF508) = 0
1759 fstat(3, 0xEFFFF508) = 0
1760 read(3, " # T h i s f i l e w".., 8192) = 5579
1761 write(4, " # T h i s f i l e w".., 5579) = 5579
1762 read(3, 0xEFFFD4A0, 8192) = 0
1765 chmod("LyXVC3.lyx", 0100644) = 0
1766 lseek(0, 0, SEEK_CUR) = 46440
1770 // Should probably have some more error checking here.
1771 // Should be cleaned up in 0.13, at least a bit.
1772 // Doing it this way, also makes the inodes stay the same.
1773 // This is still not a very good solution, in particular we
1774 // might loose the owner of the backup.
1775 FileInfo finfo(fileName());
1776 if (finfo.exist()) {
1777 mode_t fmode = finfo.getMode();
1778 struct utimbuf times = {
1779 finfo.getAccessTime(),
1780 finfo.getModificationTime() };
1782 ifstream ifs(fileName().c_str());
1783 ofstream ofs(s.c_str(), ios::out|ios::trunc);
1788 ::chmod(s.c_str(), fmode);
1790 if (::utime(s.c_str(), ×)) {
1791 lyxerr << "utime error." << endl;
1794 lyxerr << "LyX was not able to make "
1795 "backup copy. Beware." << endl;
1800 if (writeFile(fileName(), false)) {
1802 removeAutosaveFile(fileName());
1804 // Saving failed, so backup is not backup
1805 if (lyxrc.make_backup) {
1806 lyx::rename(s, fileName());
1814 // Returns false if unsuccesful
1815 bool Buffer::writeFile(string const & fname, bool flag) const
1817 // if flag is false writeFile will not create any GUI
1818 // warnings, only cerr.
1819 // Needed for autosave in background or panic save (Matthias 120496)
1821 if (read_only && (fname == fileName())) {
1822 // Here we should come with a question if we should
1823 // perform the write anyway.
1825 lyxerr << _("Error! Document is read-only: ")
1828 Alert::alert(_("Error! Document is read-only: "),
1833 FileInfo finfo(fname);
1834 if (finfo.exist() && !finfo.writable()) {
1835 // Here we should come with a question if we should
1836 // try to do the save anyway. (i.e. do a chmod first)
1838 lyxerr << _("Error! Cannot write file: ")
1841 Alert::err_alert(_("Error! Cannot write file: "),
1846 ofstream ofs(fname.c_str());
1849 lyxerr << _("Error! Cannot open file: ")
1852 Alert::err_alert(_("Error! Cannot open file: "),
1858 // Use the standard "C" locale for file output.
1859 ofs.imbue(std::locale::classic());
1862 // The top of the file should not be written by params.
1864 // write out a comment in the top of the file
1865 ofs << '#' << lyx_docversion
1866 << " created this file. For more info see http://www.lyx.org/\n"
1867 << "\\lyxformat " << LYX_FORMAT << "\n";
1869 // now write out the buffer paramters.
1870 params.writeFile(ofs);
1872 Paragraph::depth_type depth = 0;
1874 // this will write out all the paragraphs
1875 // using recursive descent.
1876 paragraph->writeFile(this, ofs, params, depth);
1878 // Write marker that shows file is complete
1879 ofs << "\n\\the_end" << endl;
1883 // how to check if close went ok?
1884 // Following is an attempt... (BE 20001011)
1886 // good() returns false if any error occured, including some
1887 // formatting error.
1888 // bad() returns true if something bad happened in the buffer,
1889 // which should include file system full errors.
1896 lyxerr << "Buffer::writeFile: BAD ERROR!" << endl;
1898 lyxerr << "Buffer::writeFile: NOT SO BAD ERROR!"
1910 pair<int, string> const addDepth(int depth, int ldepth)
1914 d += (ldepth - depth) * 2;
1915 return make_pair(d, string(d, ' '));
1921 string const Buffer::asciiParagraph(Paragraph const * par,
1922 unsigned int linelen,
1923 bool noparbreak) const
1925 ostringstream buffer;
1926 Paragraph::depth_type depth = 0;
1928 Paragraph::depth_type ltype_depth = 0;
1929 bool ref_printed = false;
1930 // if (!par->previous()) {
1932 // begins or ends a deeper area ?
1933 if (depth != par->params().depth()) {
1934 if (par->params().depth() > depth) {
1935 while (par->params().depth() > depth) {
1939 while (par->params().depth() < depth) {
1945 depth = par->params().depth();
1948 // First write the layout
1949 string const & tmp = par->layout();
1950 if (compare_no_case(tmp, "itemize") == 0) {
1952 ltype_depth = depth + 1;
1953 } else if (compare_no_case(tmp, "enumerate") == 0) {
1955 ltype_depth = depth + 1;
1956 } else if (contains(lowercase(tmp), "ection")) {
1958 ltype_depth = depth + 1;
1959 } else if (contains(lowercase(tmp), "aragraph")) {
1961 ltype_depth = depth + 1;
1962 } else if (compare_no_case(tmp, "description") == 0) {
1964 ltype_depth = depth + 1;
1965 } else if (compare_no_case(tmp, "abstract") == 0) {
1968 } else if (compare_no_case(tmp, "bibliography") == 0) {
1976 /* maybe some vertical spaces */
1978 /* the labelwidthstring used in lists */
1982 /* some pagebreaks? */
1986 /* what about the alignment */
1988 // lyxerr << "Should this ever happen?" << endl;
1991 // linelen <= 0 is special and means we don't have pargraph breaks
1993 string::size_type currlinelen = 0;
1999 buffer << string(depth * 2, ' ');
2000 currlinelen += depth * 2;
2003 // we should probably change to the paragraph language in the
2004 // gettext here (if possible) so that strings are outputted in
2005 // the correct language! (20012712 Jug)
2009 case 4: // (Sub)Paragraph
2010 case 5: // Description
2014 buffer << _("Abstract") << "\n\n";
2017 string const abst = _("Abstract: ");
2019 currlinelen += abst.length();
2022 case 7: // Bibliography
2025 buffer << _("References") << "\n\n";
2028 string const refs = _("References: ");
2030 currlinelen += refs.length();
2038 string const parlab = par->params().labelString();
2039 buffer << parlab << " ";
2040 currlinelen += parlab.length() + 1;
2048 pair<int, string> p = addDepth(depth, ltype_depth);
2050 currlinelen += p.first;
2053 // this is to change the linebreak to do it by word a bit more
2054 // intelligent hopefully! (only in the case where we have a
2055 // max linelenght!) (Jug)
2059 for (pos_type i = 0; i < par->size(); ++i) {
2060 char c = par->getUChar(params, i);
2062 case Paragraph::META_INSET:
2064 Inset const * inset = par->getInset(i);
2068 currlinelen += word.length();
2071 if (inset->ascii(this, buffer, linelen)) {
2072 // to be sure it breaks paragraph
2073 currlinelen += linelen;
2079 case Paragraph::META_NEWLINE:
2081 buffer << word << "\n";
2084 pair<int, string> p = addDepth(depth,
2087 currlinelen = p.first;
2091 case Paragraph::META_HFILL:
2092 buffer << word << "\t";
2093 currlinelen += word.length() + 1;
2100 currlinelen + word.length() > linelen - 10) {
2102 pair<int, string> p =
2103 addDepth(depth, ltype_depth);
2105 currlinelen = p.first;
2108 buffer << word << ' ';
2109 currlinelen += word.length() + 1;
2116 lyxerr[Debug::INFO] <<
2117 "writeAsciiFile: NULL char in structure." << endl;
2119 if ((linelen > 0) &&
2120 (currlinelen + word.length()) > linelen)
2124 pair<int, string> p =
2125 addDepth(depth, ltype_depth);
2127 currlinelen = p.first;
2134 return buffer.str().c_str();
2138 void Buffer::writeFileAscii(string const & fname, int linelen)
2140 ofstream ofs(fname.c_str());
2142 Alert::err_alert(_("Error: Cannot write file:"), fname);
2145 writeFileAscii(ofs, linelen);
2149 void Buffer::writeFileAscii(ostream & ofs, int linelen)
2151 Paragraph * par = paragraph;
2153 ofs << asciiParagraph(par, linelen, par->previous() == 0);
2163 void Buffer::makeLaTeXFile(string const & fname,
2164 string const & original_path,
2165 bool nice, bool only_body)
2167 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
2169 ofstream ofs(fname.c_str());
2171 Alert::err_alert(_("Error: Cannot open file: "), fname);
2175 niceFile = nice; // this will be used by Insetincludes.
2177 tex_code_break_column = lyxrc.ascii_linelen;
2179 // validate the buffer.
2180 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
2181 LaTeXFeatures features(params);
2183 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
2186 // The starting paragraph of the coming rows is the
2187 // first paragraph of the document. (Asger)
2188 texrow.start(paragraph, 0);
2190 if (!only_body && nice) {
2191 ofs << "%% " << lyx_docversion << " created this file. "
2192 "For more info, see http://www.lyx.org/.\n"
2193 "%% Do not edit unless you really know what "
2198 lyxerr[Debug::INFO] << "lyx header finished" << endl;
2199 // There are a few differences between nice LaTeX and usual files:
2200 // usual is \batchmode and has a
2201 // special input@path to allow the including of figures
2202 // with either \input or \includegraphics (what figinsets do).
2203 // batchmode is not set if there is a tex_code_break_column.
2204 // In this case somebody is interested in the generated LaTeX,
2205 // so this is OK. input@path is set when the actual parameter
2206 // original_path is set. This is done for usual tex-file, but not
2207 // for nice-latex-file. (Matthias 250696)
2210 // code for usual, NOT nice-latex-file
2211 ofs << "\\batchmode\n"; // changed
2212 // from \nonstopmode
2215 if (!original_path.empty()) {
2216 string inputpath = os::external_path(original_path);
2217 subst(inputpath, "~", "\\string~");
2218 ofs << "\\makeatletter\n"
2219 << "\\def\\input@path{{"
2220 << inputpath << "/}}\n"
2221 << "\\makeatother\n";
2227 ofs << "\\documentclass";
2229 LyXTextClass const & tclass = textclasslist[params.textclass];
2231 ostringstream options; // the document class options.
2233 if (tokenPos(tclass.opt_fontsize(),
2234 '|', params.fontsize) >= 0) {
2235 // only write if existing in list (and not default)
2236 options << params.fontsize << "pt,";
2240 if (!params.use_geometry &&
2241 (params.paperpackage == BufferParams::PACKAGE_NONE)) {
2242 switch (params.papersize) {
2243 case BufferParams::PAPER_A4PAPER:
2244 options << "a4paper,";
2246 case BufferParams::PAPER_USLETTER:
2247 options << "letterpaper,";
2249 case BufferParams::PAPER_A5PAPER:
2250 options << "a5paper,";
2252 case BufferParams::PAPER_B5PAPER:
2253 options << "b5paper,";
2255 case BufferParams::PAPER_EXECUTIVEPAPER:
2256 options << "executivepaper,";
2258 case BufferParams::PAPER_LEGALPAPER:
2259 options << "legalpaper,";
2265 if (params.sides != tclass.sides()) {
2266 switch (params.sides) {
2267 case LyXTextClass::OneSide:
2268 options << "oneside,";
2270 case LyXTextClass::TwoSides:
2271 options << "twoside,";
2277 if (params.columns != tclass.columns()) {
2278 if (params.columns == 2)
2279 options << "twocolumn,";
2281 options << "onecolumn,";
2284 if (!params.use_geometry
2285 && params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
2286 options << "landscape,";
2288 // language should be a parameter to \documentclass
2290 ostringstream language_options;
2291 if (params.language->babel() == "hebrew"
2292 && default_language->babel() != "hebrew")
2293 // This seems necessary
2294 features.useLanguage(default_language);
2296 if (lyxrc.language_use_babel ||
2297 params.language->lang() != lyxrc.default_language ||
2298 features.hasLanguages()) {
2300 language_options << features.getLanguages();
2301 language_options << params.language->babel();
2302 if (lyxrc.language_global_options)
2303 options << language_options.str() << ',';
2306 // the user-defined options
2307 if (!params.options.empty()) {
2308 options << params.options << ',';
2311 string strOptions(options.str().c_str());
2312 if (!strOptions.empty()) {
2313 strOptions = strip(strOptions, ',');
2314 ofs << '[' << strOptions << ']';
2317 ofs << '{' << tclass.latexname() << "}\n";
2319 // end of \documentclass defs
2321 // font selection must be done before loading fontenc.sty
2322 // The ae package is not needed when using OT1 font encoding.
2323 if (params.fonts != "default" &&
2324 (params.fonts != "ae" || lyxrc.fontenc != "default")) {
2325 ofs << "\\usepackage{" << params.fonts << "}\n";
2327 if (params.fonts == "ae") {
2328 ofs << "\\usepackage{aecompl}\n";
2332 // this one is not per buffer
2333 if (lyxrc.fontenc != "default") {
2334 ofs << "\\usepackage[" << lyxrc.fontenc
2339 if (params.inputenc == "auto") {
2340 string const doc_encoding =
2341 params.language->encoding()->LatexName();
2343 // Create a list with all the input encodings used
2345 set<string> encodings = features.getEncodingSet(doc_encoding);
2347 ofs << "\\usepackage[";
2348 std::copy(encodings.begin(), encodings.end(),
2349 std::ostream_iterator<string>(ofs, ","));
2350 ofs << doc_encoding << "]{inputenc}\n";
2352 } else if (params.inputenc != "default") {
2353 ofs << "\\usepackage[" << params.inputenc
2358 // At the very beginning the text parameters.
2359 if (params.paperpackage != BufferParams::PACKAGE_NONE) {
2360 switch (params.paperpackage) {
2361 case BufferParams::PACKAGE_A4:
2362 ofs << "\\usepackage{a4}\n";
2365 case BufferParams::PACKAGE_A4WIDE:
2366 ofs << "\\usepackage{a4wide}\n";
2369 case BufferParams::PACKAGE_WIDEMARGINSA4:
2370 ofs << "\\usepackage[widemargins]{a4}\n";
2375 if (params.use_geometry) {
2376 ofs << "\\usepackage{geometry}\n";
2378 ofs << "\\geometry{verbose";
2379 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
2380 ofs << ",landscape";
2381 switch (params.papersize2) {
2382 case BufferParams::VM_PAPER_CUSTOM:
2383 if (!params.paperwidth.empty())
2384 ofs << ",paperwidth="
2385 << params.paperwidth;
2386 if (!params.paperheight.empty())
2387 ofs << ",paperheight="
2388 << params.paperheight;
2390 case BufferParams::VM_PAPER_USLETTER:
2391 ofs << ",letterpaper";
2393 case BufferParams::VM_PAPER_USLEGAL:
2394 ofs << ",legalpaper";
2396 case BufferParams::VM_PAPER_USEXECUTIVE:
2397 ofs << ",executivepaper";
2399 case BufferParams::VM_PAPER_A3:
2402 case BufferParams::VM_PAPER_A4:
2405 case BufferParams::VM_PAPER_A5:
2408 case BufferParams::VM_PAPER_B3:
2411 case BufferParams::VM_PAPER_B4:
2414 case BufferParams::VM_PAPER_B5:
2418 // default papersize ie BufferParams::VM_PAPER_DEFAULT
2419 switch (lyxrc.default_papersize) {
2420 case BufferParams::PAPER_DEFAULT: // keep compiler happy
2421 case BufferParams::PAPER_USLETTER:
2422 ofs << ",letterpaper";
2424 case BufferParams::PAPER_LEGALPAPER:
2425 ofs << ",legalpaper";
2427 case BufferParams::PAPER_EXECUTIVEPAPER:
2428 ofs << ",executivepaper";
2430 case BufferParams::PAPER_A3PAPER:
2433 case BufferParams::PAPER_A4PAPER:
2436 case BufferParams::PAPER_A5PAPER:
2439 case BufferParams::PAPER_B5PAPER:
2444 if (!params.topmargin.empty())
2445 ofs << ",tmargin=" << params.topmargin;
2446 if (!params.bottommargin.empty())
2447 ofs << ",bmargin=" << params.bottommargin;
2448 if (!params.leftmargin.empty())
2449 ofs << ",lmargin=" << params.leftmargin;
2450 if (!params.rightmargin.empty())
2451 ofs << ",rmargin=" << params.rightmargin;
2452 if (!params.headheight.empty())
2453 ofs << ",headheight=" << params.headheight;
2454 if (!params.headsep.empty())
2455 ofs << ",headsep=" << params.headsep;
2456 if (!params.footskip.empty())
2457 ofs << ",footskip=" << params.footskip;
2462 if (tokenPos(tclass.opt_pagestyle(),
2463 '|', params.pagestyle) >= 0) {
2464 if (params.pagestyle == "fancy") {
2465 ofs << "\\usepackage{fancyhdr}\n";
2468 ofs << "\\pagestyle{" << params.pagestyle << "}\n";
2472 if (params.secnumdepth != tclass.secnumdepth()) {
2473 ofs << "\\setcounter{secnumdepth}{"
2474 << params.secnumdepth
2478 if (params.tocdepth != tclass.tocdepth()) {
2479 ofs << "\\setcounter{tocdepth}{"
2485 if (params.paragraph_separation) {
2486 switch (params.defskip.kind()) {
2487 case VSpace::SMALLSKIP:
2488 ofs << "\\setlength\\parskip{\\smallskipamount}\n";
2490 case VSpace::MEDSKIP:
2491 ofs << "\\setlength\\parskip{\\medskipamount}\n";
2493 case VSpace::BIGSKIP:
2494 ofs << "\\setlength\\parskip{\\bigskipamount}\n";
2496 case VSpace::LENGTH:
2497 ofs << "\\setlength\\parskip{"
2498 << params.defskip.length().asLatexString()
2501 default: // should never happen // Then delete it.
2502 ofs << "\\setlength\\parskip{\\medskipamount}\n";
2507 ofs << "\\setlength\\parindent{0pt}\n";
2511 // Now insert the LyX specific LaTeX commands...
2513 // The optional packages;
2514 string preamble(features.getPackages());
2516 // this might be useful...
2517 preamble += "\n\\makeatletter\n";
2519 // Some macros LyX will need
2520 string tmppreamble(features.getMacros());
2522 if (!tmppreamble.empty()) {
2523 preamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2524 "LyX specific LaTeX commands.\n"
2525 + tmppreamble + '\n';
2528 // the text class specific preamble
2529 tmppreamble = features.getTClassPreamble();
2530 if (!tmppreamble.empty()) {
2531 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2532 "Textclass specific LaTeX commands.\n"
2533 + tmppreamble + '\n';
2536 /* the user-defined preamble */
2537 if (!params.preamble.empty()) {
2538 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2539 "User specified LaTeX commands.\n"
2540 + params.preamble + '\n';
2543 // Itemize bullet settings need to be last in case the user
2544 // defines their own bullets that use a package included
2545 // in the user-defined preamble -- ARRae
2546 // Actually it has to be done much later than that
2547 // since some packages like frenchb make modifications
2548 // at \begin{document} time -- JMarc
2550 for (int i = 0; i < 4; ++i) {
2551 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
2552 if (bullets_def.empty())
2553 bullets_def="\\AtBeginDocument{\n";
2554 bullets_def += " \\renewcommand{\\labelitemi";
2556 // `i' is one less than the item to modify
2563 bullets_def += "ii";
2569 bullets_def += "}{" +
2570 params.user_defined_bullets[i].getText()
2575 if (!bullets_def.empty())
2576 preamble += bullets_def + "}\n\n";
2579 int(lyx::count(preamble.begin(), preamble.end(), '\n'));
2580 for (int j = 0; j != nlines; ++j) {
2584 // We try to load babel late, in case it interferes
2585 // with other packages.
2587 string tmp = lyxrc.language_package;
2588 if (!lyxrc.language_global_options
2589 && tmp == "\\usepackage{babel}")
2590 tmp = string("\\usepackage[") +
2591 language_options.str().c_str() +
2593 preamble += tmp + "\n";
2594 preamble += features.getBabelOptions();
2597 preamble += "\\makeatother\n";
2602 ofs << "\\begin{document}\n";
2605 lyxerr[Debug::INFO] << "preamble finished, now the body." << endl;
2607 if (!lyxrc.language_auto_begin) {
2608 ofs << subst(lyxrc.language_command_begin, "$$lang",
2609 params.language->babel())
2614 latexParagraphs(ofs, paragraph, 0, texrow);
2616 // add this just in case after all the paragraphs
2620 if (!lyxrc.language_auto_end) {
2621 ofs << subst(lyxrc.language_command_end, "$$lang",
2622 params.language->babel())
2628 ofs << "\\end{document}\n";
2631 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
2633 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
2637 // Just to be sure. (Asger)
2640 // tex_code_break_column's value is used to decide
2641 // if we are in batchmode or not (within mathed_write()
2642 // in math_write.C) so we must set it to a non-zero
2643 // value when we leave otherwise we save incorrect .lyx files.
2644 tex_code_break_column = lyxrc.ascii_linelen;
2648 lyxerr << "File was not closed properly." << endl;
2651 lyxerr[Debug::INFO] << "Finished making latex file." << endl;
2652 lyxerr[Debug::INFO] << "Row count was " << texrow.rows()-1 << "." << endl;
2654 // we want this to be true outside previews (for insetexternal)
2660 // LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
2662 void Buffer::latexParagraphs(ostream & ofs, Paragraph * par,
2663 Paragraph * endpar, TexRow & texrow,
2664 bool moving_arg) const
2666 bool was_title = false;
2667 bool already_title = false;
2670 while (par != endpar) {
2671 Inset * in = par->inInset();
2672 // well we have to check if we are in an inset with unlimited
2673 // lenght (all in one row) if that is true then we don't allow
2674 // any special options in the paragraph and also we don't allow
2675 // any environment other then "Standard" to be valid!
2676 if ((in == 0) || !in->forceDefaultParagraphs(in)) {
2677 LyXLayout const & layout =
2678 textclasslist[params.textclass][par->layout()];
2680 if (layout.intitle) {
2681 if (already_title) {
2682 lyxerr <<"Error in latexParagraphs: You"
2683 " should not mix title layouts"
2684 " with normal ones." << endl;
2687 } else if (was_title && !already_title) {
2688 ofs << "\\maketitle\n";
2690 already_title = true;
2694 if (layout.isEnvironment() ||
2695 !par->params().leftIndent().zero())
2697 par = par->TeXEnvironment(this, params, ofs, texrow);
2699 par = par->TeXOnePar(this, params, ofs, texrow, moving_arg);
2702 par = par->TeXOnePar(this, params, ofs, texrow, moving_arg);
2705 // It might be that we only have a title in this document
2706 if (was_title && !already_title) {
2707 ofs << "\\maketitle\n";
2713 bool Buffer::isLatex() const
2715 return textclasslist[params.textclass].outputType() == LATEX;
2719 bool Buffer::isLinuxDoc() const
2721 return textclasslist[params.textclass].outputType() == LINUXDOC;
2725 bool Buffer::isLiterate() const
2727 return textclasslist[params.textclass].outputType() == LITERATE;
2731 bool Buffer::isDocBook() const
2733 return textclasslist[params.textclass].outputType() == DOCBOOK;
2737 bool Buffer::isSGML() const
2739 LyXTextClass const & tclass = textclasslist[params.textclass];
2741 return tclass.outputType() == LINUXDOC ||
2742 tclass.outputType() == DOCBOOK;
2746 void Buffer::sgmlOpenTag(ostream & os, Paragraph::depth_type,
2747 string const & latexname) const
2749 if (!latexname.empty() && latexname != "!-- --")
2750 //os << "<!-- " << depth << " -->" << "<" << latexname << ">";
2751 os << "<" << latexname << ">";
2755 void Buffer::sgmlCloseTag(ostream & os, Paragraph::depth_type,
2756 string const & latexname) const
2758 if (!latexname.empty() && latexname != "!-- --")
2759 //os << "<!-- " << depth << " -->" << "</" << latexname << ">\n";
2760 os << "</" << latexname << ">";
2764 void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
2766 ofstream ofs(fname.c_str());
2769 Alert::alert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2773 niceFile = nice; // this will be used by included files.
2775 LaTeXFeatures features(params);
2781 LyXTextClass const & tclass = textclasslist[params.textclass];
2783 string top_element = tclass.latexname();
2786 ofs << "<!doctype linuxdoc system";
2788 string preamble = params.preamble;
2789 const string name = nice ? ChangeExtension(filename_, ".sgml")
2791 preamble += features.getIncludedFiles(name);
2792 preamble += features.getLyXSGMLEntities();
2794 if (!preamble.empty()) {
2795 ofs << " [ " << preamble << " ]";
2799 if (params.options.empty())
2800 sgmlOpenTag(ofs, 0, top_element);
2802 string top = top_element;
2804 top += params.options;
2805 sgmlOpenTag(ofs, 0, top);
2809 ofs << "<!-- " << lyx_docversion
2810 << " created this file. For more info see http://www.lyx.org/"
2813 Paragraph::depth_type depth = 0; // paragraph depth
2814 Paragraph * par = paragraph;
2816 vector<string> environment_stack(5);
2819 LyXLayout const & style = tclass[par->layout()];
2821 // treat <toc> as a special case for compatibility with old code
2822 if (par->isInset(0)) {
2823 Inset * inset = par->getInset(0);
2824 Inset::Code lyx_code = inset->lyxCode();
2825 if (lyx_code == Inset::TOC_CODE) {
2826 string const temp = "toc";
2827 sgmlOpenTag(ofs, depth, temp);
2834 // environment tag closing
2835 for (; depth > par->params().depth(); --depth) {
2836 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2837 environment_stack[depth].erase();
2840 // write opening SGML tags
2841 switch (style.latextype) {
2842 case LATEX_PARAGRAPH:
2843 if (depth == par->params().depth()
2844 && !environment_stack[depth].empty()) {
2845 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2846 environment_stack[depth].erase();
2852 sgmlOpenTag(ofs, depth, style.latexname());
2858 _("Error : Wrong depth for"
2859 " LatexType Command.\n"));
2861 if (!environment_stack[depth].empty()) {
2862 sgmlCloseTag(ofs, depth,
2863 environment_stack[depth]);
2867 environment_stack[depth].erase();
2868 sgmlOpenTag(ofs, depth, style.latexname());
2871 case LATEX_ENVIRONMENT:
2872 case LATEX_ITEM_ENVIRONMENT:
2873 if (depth == par->params().depth()
2874 && environment_stack[depth] != style.latexname()) {
2875 sgmlCloseTag(ofs, depth,
2876 environment_stack[depth]);
2877 environment_stack[depth].erase();
2879 if (depth < par->params().depth()) {
2880 depth = par->params().depth();
2881 environment_stack[depth].erase();
2883 if (environment_stack[depth] != style.latexname()) {
2885 sgmlOpenTag(ofs, depth, "p");
2887 sgmlOpenTag(ofs, depth, style.latexname());
2889 if (environment_stack.size() == depth + 1)
2890 environment_stack.push_back("!-- --");
2891 environment_stack[depth] = style.latexname();
2894 if (style.latexparam() == "CDATA")
2897 if (style.latextype == LATEX_ENVIRONMENT) break;
2899 if (style.labeltype == LABEL_MANUAL)
2904 sgmlOpenTag(ofs, depth + 1, item_name);
2907 sgmlOpenTag(ofs, depth, style.latexname());
2911 simpleLinuxDocOnePar(ofs, par, depth);
2916 // write closing SGML tags
2917 switch (style.latextype) {
2920 case LATEX_ENVIRONMENT:
2921 case LATEX_ITEM_ENVIRONMENT:
2922 if (style.latexparam() == "CDATA")
2926 sgmlCloseTag(ofs, depth, style.latexname());
2932 for (int i=depth; i >= 0; --i)
2933 sgmlCloseTag(ofs, depth, environment_stack[i]);
2937 sgmlCloseTag(ofs, 0, top_element);
2941 // How to check for successful close
2943 // we want this to be true outside previews (for insetexternal)
2948 // checks, if newcol chars should be put into this line
2949 // writes newline, if necessary.
2952 void sgmlLineBreak(ostream & os, string::size_type & colcount,
2953 string::size_type newcol)
2956 if (colcount > lyxrc.ascii_linelen) {
2958 colcount = newcol; // assume write after this call
2973 string tag_name(PAR_TAG const & pt) {
2975 case NONE: return "!-- --";
2976 case TT: return "tt";
2977 case SF: return "sf";
2978 case BF: return "bf";
2979 case IT: return "it";
2980 case SL: return "sl";
2981 case EM: return "em";
2988 void operator|=(PAR_TAG & p1, PAR_TAG const & p2)
2990 p1 = static_cast<PAR_TAG>(p1 | p2);
2995 void reset(PAR_TAG & p1, PAR_TAG const & p2)
2997 p1 = static_cast<PAR_TAG>(p1 & ~p2);
3003 // Handle internal paragraph parsing -- layout already processed.
3004 void Buffer::simpleLinuxDocOnePar(ostream & os,
3006 Paragraph::depth_type /*depth*/)
3008 LyXLayout const & style =
3009 textclasslist[params.textclass][par->layout()];
3010 string::size_type char_line_count = 5; // Heuristic choice ;-)
3012 // gets paragraph main font
3015 if (style.labeltype == LABEL_MANUAL) {
3016 font_old = style.labelfont;
3019 font_old = style.font;
3023 LyXFont::FONT_FAMILY family_type = LyXFont::ROMAN_FAMILY;
3024 LyXFont::FONT_SERIES series_type = LyXFont::MEDIUM_SERIES;
3025 LyXFont::FONT_SHAPE shape_type = LyXFont::UP_SHAPE;
3028 stack<PAR_TAG> tag_state;
3029 // parsing main loop
3030 for (pos_type i = 0; i < par->size(); ++i) {
3032 PAR_TAG tag_close = NONE;
3033 list < PAR_TAG > tag_open;
3035 LyXFont const font = par->getFont(params, i);
3037 if (font_old.family() != font.family()) {
3038 switch (family_type) {
3039 case LyXFont::SANS_FAMILY:
3042 case LyXFont::TYPEWRITER_FAMILY:
3049 family_type = font.family();
3051 switch (family_type) {
3052 case LyXFont::SANS_FAMILY:
3053 tag_open.push_back(SF);
3055 case LyXFont::TYPEWRITER_FAMILY:
3056 tag_open.push_back(TT);
3063 if (font_old.series() != font.series()) {
3064 switch (series_type) {
3065 case LyXFont::BOLD_SERIES:
3072 series_type = font.series();
3074 switch (series_type) {
3075 case LyXFont::BOLD_SERIES:
3076 tag_open.push_back(BF);
3084 if (font_old.shape() != font.shape()) {
3085 switch (shape_type) {
3086 case LyXFont::ITALIC_SHAPE:
3089 case LyXFont::SLANTED_SHAPE:
3096 shape_type = font.shape();
3098 switch (shape_type) {
3099 case LyXFont::ITALIC_SHAPE:
3100 tag_open.push_back(IT);
3102 case LyXFont::SLANTED_SHAPE:
3103 tag_open.push_back(SL);
3110 if (font_old.emph() != font.emph()) {
3111 if (font.emph() == LyXFont::ON) {
3112 tag_open.push_back(EM);
3121 list < PAR_TAG > temp;
3122 while (!tag_state.empty() && tag_close) {
3123 PAR_TAG k = tag_state.top();
3125 os << "</" << tag_name(k) << ">";
3132 for(list< PAR_TAG >::const_iterator j = temp.begin();
3133 j != temp.end(); ++j) {
3135 os << "<" << tag_name(*j) << ">";
3138 for(list< PAR_TAG >::const_iterator j = tag_open.begin();
3139 j != tag_open.end(); ++j) {
3141 os << "<" << tag_name(*j) << ">";
3144 char c = par->getChar(i);
3146 if (c == Paragraph::META_INSET) {
3147 Inset * inset = par->getInset(i);
3148 inset->linuxdoc(this, os);
3153 if (style.latexparam() == "CDATA") {
3154 // "TeX"-Mode on == > SGML-Mode on.
3160 if (par->sgmlConvertChar(c, sgml_string)
3161 && !style.free_spacing && !par->isFreeSpacing())
3163 // in freespacing mode, spaces are
3164 // non-breaking characters
3165 if (desc_on) {// if char is ' ' then...
3168 sgmlLineBreak(os, char_line_count, 6);
3172 sgmlLineBreak(os, char_line_count, 1);
3177 char_line_count += sgml_string.length();
3183 while (!tag_state.empty()) {
3184 os << "</" << tag_name(tag_state.top()) << ">";
3188 // resets description flag correctly
3190 // <tag> not closed...
3191 sgmlLineBreak(os, char_line_count, 6);
3197 // Print an error message.
3198 void Buffer::sgmlError(Paragraph * /*par*/, int /*pos*/,
3199 string const & /*message*/) const
3201 #warning This is wrong we cannot insert an inset like this!!!
3202 // I guess this was Jose' so I explain you more or less why this
3203 // is wrong. This way you insert something in the paragraph and
3204 // don't tell it to LyXText (row rebreaking and undo handling!!!)
3205 // I deactivate this code, have a look at BufferView::insertErrors
3206 // how you should do this correctly! (Jug 20020315)
3208 // insert an error marker in text
3209 InsetError * new_inset = new InsetError(message);
3210 par->insertInset(pos, new_inset, LyXFont(LyXFont::ALL_INHERIT,
3216 void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
3218 ofstream ofs(fname.c_str());
3220 Alert::alert(_("LYX_ERROR:"), _("Cannot write file"), fname);
3224 Paragraph * par = paragraph;
3226 niceFile = nice; // this will be used by Insetincludes.
3228 LaTeXFeatures features(params);
3233 LyXTextClass const & tclass = textclasslist[params.textclass];
3234 string top_element = tclass.latexname();
3237 ofs << "<!DOCTYPE " << top_element
3238 << " PUBLIC \"-//OASIS//DTD DocBook V4.1//EN\"";
3240 string preamble = params.preamble;
3241 const string name = nice ? ChangeExtension(filename_, ".sgml")
3243 preamble += features.getIncludedFiles(name);
3244 preamble += features.getLyXSGMLEntities();
3246 if (!preamble.empty()) {
3247 ofs << "\n [ " << preamble << " ]";
3252 string top = top_element;
3254 top += params.language->code();
3257 if (!params.options.empty()) {
3259 top += params.options;
3261 sgmlOpenTag(ofs, 0, top);
3263 ofs << "<!-- DocBook file was created by " << lyx_docversion
3264 << "\n See http://www.lyx.org/ for more information -->\n";
3266 vector<string> environment_stack(10);
3267 vector<string> environment_inner(10);
3268 vector<string> command_stack(10);
3270 bool command_flag = false;
3271 Paragraph::depth_type command_depth = 0;
3272 Paragraph::depth_type command_base = 0;
3273 Paragraph::depth_type cmd_depth = 0;
3274 Paragraph::depth_type depth = 0; // paragraph depth
3277 string command_name;
3283 int desc_on = 0; // description mode
3285 LyXLayout const & style = tclass[par->layout()];
3287 // environment tag closing
3288 for (; depth > par->params().depth(); --depth) {
3289 if (environment_inner[depth] != "!-- --") {
3290 item_name = "listitem";
3291 sgmlCloseTag(ofs, command_depth + depth,
3293 if (environment_inner[depth] == "varlistentry")
3294 sgmlCloseTag(ofs, depth+command_depth,
3295 environment_inner[depth]);
3297 sgmlCloseTag(ofs, depth + command_depth,
3298 environment_stack[depth]);
3299 environment_stack[depth].erase();
3300 environment_inner[depth].erase();
3303 if (depth == par->params().depth()
3304 && environment_stack[depth] != style.latexname()
3305 && !environment_stack[depth].empty()) {
3306 if (environment_inner[depth] != "!-- --") {
3307 item_name= "listitem";
3308 sgmlCloseTag(ofs, command_depth+depth,
3310 if (environment_inner[depth] == "varlistentry")
3312 depth + command_depth,
3313 environment_inner[depth]);
3316 sgmlCloseTag(ofs, depth + command_depth,
3317 environment_stack[depth]);
3319 environment_stack[depth].erase();
3320 environment_inner[depth].erase();
3323 // Write opening SGML tags.
3324 switch (style.latextype) {
3325 case LATEX_PARAGRAPH:
3326 sgmlOpenTag(ofs, depth + command_depth,
3333 _("Error : Wrong depth for "
3334 "LatexType Command.\n"));
3336 command_name = style.latexname();
3338 sgmlparam = style.latexparam();
3339 c_params = split(sgmlparam, c_depth,'|');
3341 cmd_depth = lyx::atoi(c_depth);
3344 if (cmd_depth < command_base) {
3345 for (Paragraph::depth_type j = command_depth;
3346 j >= command_base; --j) {
3347 sgmlCloseTag(ofs, j, command_stack[j]);
3350 command_depth = command_base = cmd_depth;
3351 } else if (cmd_depth <= command_depth) {
3352 for (int j = command_depth;
3353 j >= int(cmd_depth); --j) {
3354 sgmlCloseTag(ofs, j, command_stack[j]);
3357 command_depth = cmd_depth;
3359 command_depth = cmd_depth;
3361 command_depth = command_base = cmd_depth;
3362 command_flag = true;
3364 if (command_stack.size() == command_depth + 1)
3365 command_stack.push_back(string());
3366 command_stack[command_depth] = command_name;
3368 // treat label as a special case for
3369 // more WYSIWYM handling.
3370 // This is a hack while paragraphs can't have
3371 // attributes, like id in this case.
3372 if (par->isInset(0)) {
3373 Inset * inset = par->getInset(0);
3374 Inset::Code lyx_code = inset->lyxCode();
3375 if (lyx_code == Inset::LABEL_CODE) {
3376 command_name += " id=\"";
3377 command_name += (static_cast<InsetCommand *>(inset))->getContents();
3378 command_name += "\"";
3383 sgmlOpenTag(ofs, depth + command_depth, command_name);
3384 if (c_params.empty())
3385 item_name = "title";
3387 item_name = c_params;
3388 sgmlOpenTag(ofs, depth + 1 + command_depth, item_name);
3391 case LATEX_ENVIRONMENT:
3392 case LATEX_ITEM_ENVIRONMENT:
3393 if (depth < par->params().depth()) {
3394 depth = par->params().depth();
3395 environment_stack[depth].erase();
3398 if (environment_stack[depth] != style.latexname()) {
3399 if (environment_stack.size() == depth + 1) {
3400 environment_stack.push_back("!-- --");
3401 environment_inner.push_back("!-- --");
3403 environment_stack[depth] = style.latexname();
3404 environment_inner[depth] = "!-- --";
3405 sgmlOpenTag(ofs, depth + command_depth,
3406 environment_stack[depth]);
3408 if (environment_inner[depth] != "!-- --") {
3409 item_name= "listitem";
3411 command_depth + depth,
3413 if (environment_inner[depth] == "varlistentry")
3415 depth + command_depth,
3416 environment_inner[depth]);
3420 if (style.latextype == LATEX_ENVIRONMENT) {
3421 if (!style.latexparam().empty()) {
3422 if (style.latexparam() == "CDATA")
3425 sgmlOpenTag(ofs, depth + command_depth,
3426 style.latexparam());
3431 desc_on = (style.labeltype == LABEL_MANUAL);
3434 environment_inner[depth]= "varlistentry";
3436 environment_inner[depth]= "listitem";
3438 sgmlOpenTag(ofs, depth + 1 + command_depth,
3439 environment_inner[depth]);
3443 sgmlOpenTag(ofs, depth + 1 + command_depth,
3447 sgmlOpenTag(ofs, depth + 1 + command_depth,
3452 sgmlOpenTag(ofs, depth + command_depth,
3457 simpleDocBookOnePar(ofs, par, desc_on, depth+1+command_depth);
3461 // write closing SGML tags
3462 switch (style.latextype) {
3464 if (c_params.empty())
3468 sgmlCloseTag(ofs, depth + command_depth, end_tag);
3470 case LATEX_ENVIRONMENT:
3471 if (!style.latexparam().empty()) {
3472 if (style.latexparam() == "CDATA")
3475 sgmlCloseTag(ofs, depth + command_depth,
3476 style.latexparam());
3479 case LATEX_ITEM_ENVIRONMENT:
3480 if (desc_on == 1) break;
3482 sgmlCloseTag(ofs, depth + 1 + command_depth, end_tag);
3484 case LATEX_PARAGRAPH:
3485 sgmlCloseTag(ofs, depth + command_depth, style.latexname());
3488 sgmlCloseTag(ofs, depth + command_depth, style.latexname());
3494 for (int d = depth; d >= 0; --d) {
3495 if (!environment_stack[depth].empty()) {
3496 if (environment_inner[depth] != "!-- --") {
3497 item_name = "listitem";
3498 sgmlCloseTag(ofs, command_depth + depth,
3500 if (environment_inner[depth] == "varlistentry")
3501 sgmlCloseTag(ofs, depth + command_depth,
3502 environment_inner[depth]);
3505 sgmlCloseTag(ofs, depth + command_depth,
3506 environment_stack[depth]);
3510 for (int j = command_depth; j >= 0 ; --j)
3511 if (!command_stack[j].empty()) {
3512 sgmlCloseTag(ofs, j, command_stack[j]);
3517 sgmlCloseTag(ofs, 0, top_element);
3520 // How to check for successful close
3522 // we want this to be true outside previews (for insetexternal)
3527 void Buffer::simpleDocBookOnePar(ostream & os,
3528 Paragraph * par, int & desc_on,
3529 Paragraph::depth_type depth) const
3531 bool emph_flag = false;
3533 LyXLayout const & style =
3534 textclasslist[params.textclass][par->layout()];
3536 LyXFont font_old = style.labeltype == LABEL_MANUAL ? style.labelfont : style.font;
3538 int char_line_count = depth;
3539 //if (!style.free_spacing)
3540 // os << string(depth,' ');
3542 // parsing main loop
3543 for (pos_type i = 0; i < par->size(); ++i) {
3544 LyXFont font = par->getFont(params, i);
3546 // handle <emphasis> tag
3547 if (font_old.emph() != font.emph()) {
3548 if (font.emph() == LyXFont::ON) {
3549 if(style.latexparam() == "CDATA")
3552 if(style.latexparam() == "CDATA")
3556 if(style.latexparam() == "CDATA")
3558 os << "</emphasis>";
3559 if(style.latexparam() == "CDATA")
3566 if (par->isInset(i)) {
3567 Inset * inset = par->getInset(i);
3568 // don't print the inset in position 0 if desc_on == 3 (label)
3569 if ( i || desc_on != 3) {
3570 if(style.latexparam() == "CDATA")
3572 inset->docbook(this, os);
3573 if(style.latexparam() == "CDATA")
3577 char c = par->getChar(i);
3579 par->sgmlConvertChar(c, sgml_string);
3581 if (style.pass_thru) {
3583 } else if (style.free_spacing || par->isFreeSpacing() || c != ' ') {
3585 } else if (desc_on ==1) {
3587 os << "\n</term><listitem><para>";
3597 if(style.latexparam() == "CDATA")
3599 os << "</emphasis>";
3600 if(style.latexparam() == "CDATA")
3604 // resets description flag correctly
3606 // <term> not closed...
3607 os << "</term>\n<listitem><para> </para>";
3609 if (style.free_spacing) os << '\n';
3613 // This should be enabled when the Chktex class is implemented. (Asger)
3614 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
3615 // Other flags: -wall -v0 -x
3616 int Buffer::runChktex()
3618 if (!users->text) return 0;
3620 users->owner()->prohibitInput();
3622 // get LaTeX-Filename
3623 string const name = getLatexName();
3624 string path = filePath();
3626 string const org_path = path;
3627 if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
3631 Path p(path); // path to LaTeX file
3632 users->owner()->message(_("Running chktex..."));
3634 // Remove all error insets
3635 bool const removedErrorInsets = users->removeAutoInsets();
3637 // Generate the LaTeX file if neccessary
3638 makeLaTeXFile(name, org_path, false);
3641 Chktex chktex(lyxrc.chktex_command, name, filePath());
3642 int res = chktex.run(terr); // run chktex
3645 Alert::alert(_("chktex did not work!"),
3646 _("Could not run with file:"), name);
3647 } else if (res > 0) {
3648 // Insert all errors as errors boxes
3649 users->insertErrors(terr);
3652 // if we removed error insets before we ran chktex or if we inserted
3653 // error insets after we ran chktex, this must be run:
3654 if (removedErrorInsets || res) {
3658 users->owner()->allowInput();
3664 void Buffer::validate(LaTeXFeatures & features) const
3666 Paragraph * par = paragraph;
3667 LyXTextClass const & tclass = textclasslist[params.textclass];
3669 // AMS Style is at document level
3670 if (params.use_amsmath || tclass.provides(LyXTextClass::amsmath))
3671 features.require("amsmath");
3674 // We don't use "lyxerr.debug" because of speed. (Asger)
3675 if (lyxerr.debugging(Debug::LATEX))
3676 lyxerr << "Paragraph: " << par << endl;
3678 // Now just follow the list of paragraphs and run
3679 // validate on each of them.
3680 par->validate(features);
3682 // and then the next paragraph
3686 // the bullet shapes are buffer level not paragraph level
3687 // so they are tested here
3688 for (int i = 0; i < 4; ++i) {
3689 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
3690 int const font = params.user_defined_bullets[i].getFont();
3692 int const c = params
3693 .user_defined_bullets[i]
3700 features.require("latexsym");
3702 } else if (font == 1) {
3703 features.require("amssymb");
3704 } else if ((font >= 2 && font <= 5)) {
3705 features.require("pifont");
3710 if (lyxerr.debugging(Debug::LATEX)) {
3711 features.showStruct();
3716 // This function should be in Buffer because it's a buffer's property (ale)
3717 string const Buffer::getIncludeonlyList(char delim)
3720 for (inset_iterator it = inset_iterator_begin();
3721 it != inset_iterator_end(); ++it) {
3722 if ((*it)->lyxCode() == Inset::INCLUDE_CODE) {
3723 InsetInclude * insetinc =
3724 static_cast<InsetInclude *>(*it);
3725 if (insetinc->isIncludeOnly()) {
3728 lst += insetinc->getRelFileBaseName();
3732 lyxerr[Debug::INFO] << "Includeonly(" << lst << ')' << endl;
3737 vector<string> const Buffer::getLabelList()
3739 /// if this is a child document and the parent is already loaded
3740 /// Use the parent's list instead [ale990407]
3741 if (!params.parentname.empty()
3742 && bufferlist.exists(params.parentname)) {
3743 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3745 return tmp->getLabelList();
3748 vector<string> label_list;
3749 for (inset_iterator it = inset_iterator_begin();
3750 it != inset_iterator_end(); ++it) {
3751 vector<string> const l = (*it)->getLabelList();
3752 label_list.insert(label_list.end(), l.begin(), l.end());
3758 Buffer::Lists const Buffer::getLists() const
3761 Paragraph * par = paragraph;
3763 LyXTextClass const & textclass = textclasslist[params.textclass];
3764 bool found = textclass.hasLayout("Caption");
3765 string const layout("Caption");
3768 char const labeltype = textclass[par->layout()].labeltype;
3770 if (labeltype >= LABEL_COUNTER_CHAPTER
3771 && labeltype <= LABEL_COUNTER_CHAPTER + params.tocdepth) {
3772 // insert this into the table of contents
3773 SingleList & item = l["TOC"];
3776 textclass.maxcounter());
3777 item.push_back(TocItem(par, depth, par->asString(this, true)));
3779 // For each paragrph, traverse its insets and look for
3783 Paragraph::inset_iterator it =
3784 par->inset_iterator_begin();
3785 Paragraph::inset_iterator end =
3786 par->inset_iterator_end();
3788 for (; it != end; ++it) {
3789 if ((*it)->lyxCode() == Inset::FLOAT_CODE) {
3791 static_cast<InsetFloat*>(*it);
3793 string const type = il->type();
3795 // Now find the caption in the float...
3796 // We now tranverse the paragraphs of
3798 Paragraph * tmp = il->inset.paragraph();
3800 if (tmp->layout() == layout) {
3801 SingleList & item = l[type];
3803 tostr(item.size()+1) + ". " + tmp->asString(this, false);
3804 item.push_back(TocItem(tmp, 0 , str));
3811 lyxerr << "Caption not found" << endl;
3820 // This is also a buffer property (ale)
3821 vector<pair<string, string> > const Buffer::getBibkeyList() const
3823 typedef pair<string, string> StringPair;
3824 /// if this is a child document and the parent is already loaded
3825 /// Use the parent's list instead [ale990412]
3826 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3827 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
3829 return tmp->getBibkeyList();
3832 vector<StringPair> keys;
3833 Paragraph * par = paragraph;
3836 string const key = par->bibkey->getContents();
3837 string const opt = par->bibkey->getOptions();
3838 string const ref = par->asString(this, false);
3839 string const info = opt + "TheBibliographyRef" + ref;
3841 keys.push_back(StringPair(key, info));
3846 // Might be either using bibtex or a child has bibliography
3848 for (inset_iterator it = inset_const_iterator_begin();
3849 it != inset_const_iterator_end(); ++it) {
3850 // Search for Bibtex or Include inset
3851 if ((*it)->lyxCode() == Inset::BIBTEX_CODE) {
3852 vector<StringPair> tmp =
3853 static_cast<InsetBibtex*>(*it)->getKeys(this);
3854 keys.insert(keys.end(), tmp.begin(), tmp.end());
3855 } else if ((*it)->lyxCode() == Inset::INCLUDE_CODE) {
3856 vector<StringPair> const tmp =
3857 static_cast<InsetInclude*>(*it)->getKeys();
3858 keys.insert(keys.end(), tmp.begin(), tmp.end());
3867 bool Buffer::isDepClean(string const & name) const
3869 DEPCLEAN * item = dep_clean;
3870 while (item && item->master != name)
3872 if (!item) return true;
3877 void Buffer::markDepClean(string const & name)
3880 dep_clean = new DEPCLEAN;
3881 dep_clean->clean = true;
3882 dep_clean->master = name;
3883 dep_clean->next = 0;
3885 DEPCLEAN * item = dep_clean;
3886 while (item && item->master != name)
3891 item = new DEPCLEAN;
3893 item->master = name;
3900 bool Buffer::dispatch(string const & command)
3902 // Split command string into command and argument
3904 string line = frontStrip(command);
3905 string const arg = strip(frontStrip(split(line, cmd, ' ')));
3907 return dispatch(lyxaction.LookupFunc(cmd), arg);
3911 bool Buffer::dispatch(int action, string const & argument)
3913 bool dispatched = true;
3916 Exporter::Export(this, argument, false);
3926 void Buffer::resizeInsets(BufferView * bv)
3928 /// then remove all LyXText in text-insets
3929 Paragraph * par = paragraph;
3930 for (; par; par = par->next()) {
3931 par->resizeInsetsLyXText(bv);
3936 void Buffer::redraw()
3943 void Buffer::changeLanguage(Language const * from, Language const * to)
3946 ParIterator end = par_iterator_end();
3947 for (ParIterator it = par_iterator_begin(); it != end; ++it)
3948 (*it)->changeLanguage(params, from, to);
3952 bool Buffer::isMultiLingual()
3954 ParIterator end = par_iterator_end();
3955 for (ParIterator it = par_iterator_begin(); it != end; ++it)
3956 if ((*it)->isMultiLingual(params))
3963 Buffer::inset_iterator::inset_iterator(Paragraph * paragraph, pos_type pos)
3966 it = par->InsetIterator(pos);
3967 if (it == par->inset_iterator_end()) {
3974 void Buffer::inset_iterator::setParagraph()
3977 it = par->inset_iterator_begin();
3978 if (it != par->inset_iterator_end())
3983 // We maintain an invariant that whenever par = 0 then it = 0
3987 Inset * Buffer::getInsetFromID(int id_arg) const
3989 for (inset_iterator it = inset_const_iterator_begin();
3990 it != inset_const_iterator_end(); ++it)
3992 if ((*it)->id() == id_arg)
3994 Inset * in = (*it)->getInsetFromID(id_arg);
4002 Paragraph * Buffer::getParFromID(int id) const
4004 if (id < 0) return 0;
4005 Paragraph * par = paragraph;
4007 if (par->id() == id) {
4010 Paragraph * tmp = par->getParFromID(id);
4020 ParIterator Buffer::par_iterator_begin()
4022 return ParIterator(paragraph);
4026 ParIterator Buffer::par_iterator_end()
4028 return ParIterator();