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>
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;
488 // The order of the tags tested may seem unnatural, but this
489 // has been done in order to reduce the number of string
490 // comparisons needed to recognize a given token. This leads
491 // on large documents like UserGuide to a reduction of a
493 if (token[0] != '\\') {
494 #ifndef NO_COMPABILITY
495 if (ert_comp.active) {
496 ert_comp.contents += token;
499 for (string::const_iterator cit = token.begin();
500 cit != token.end(); ++cit) {
501 par->insertChar(pos, (*cit), font);
504 #ifndef NO_COMPABILITY
507 } else if (token == "\\layout") {
508 #ifndef NO_COMPABILITY
509 bool old_fromlayout = ert_comp.fromlayout;
510 bool create_new_par = true;
511 ert_comp.in_tabular = false;
513 if (!par->size() && par->previous() &&
514 (par->previous()->size() == 1) &&
515 isErtInset(par->previous(), par->previous()->size()-1))
517 int p = par->previous()->size();
518 insertErtContents(par->previous(), p);
519 create_new_par = false;
521 insertErtContents(par, pos);
524 // reset the font as we start a new layout and if the font is
525 // not ALL_INHERIT,document_language then it will be set to the
526 // right values after this tag (Jug 20020420)
527 font = LyXFont(LyXFont::ALL_INHERIT, params.language);
530 if (file_format < 216 && params.language->lang() == "hebrew")
531 font.setLanguage(default_language);
535 string layoutname = lex.getString();
537 LyXTextClass const & tclass = textclasslist[params.textclass];
539 if (layoutname.empty()) {
540 layoutname = tclass.defaultLayoutName();
542 #ifndef NO_COMPABILITY
543 if (compare_no_case(layoutname, "latex") == 0) {
544 ert_comp.active = true;
545 ert_comp.fromlayout = true;
546 ert_comp.font = font;
548 create_new_par = false;
551 bool hasLayout = tclass.hasLayout(layoutname);
553 lyxerr << "Layout '" << layoutname << "' does not"
554 << " exist in textclass '" << tclass.name()
556 lyxerr << "Trying to use default layout instead."
558 layoutname = tclass.defaultLayoutName();
562 // The is the compability reading of layout caption.
563 // It can be removed in LyX version 1.3.0. (Lgb)
564 if (compare_no_case(layoutname, "caption") == 0) {
565 // We expect that the par we are now working on is
566 // really inside a InsetText inside a InsetFloat.
567 // We also know that captions can only be
568 // one paragraph. (Lgb)
570 // We should now read until the next "\layout"
572 // This is probably not good enough, what if the
573 // caption is the last par in the document (Lgb)
574 istream & ist = lex.getStream();
580 if (prefixIs(line, "\\layout")) {
584 if (prefixIs(line, "\\begin_inset"))
586 if (prefixIs(line, "\\end_inset")) {
597 // Now we should have the whole layout in ss
598 // we should now be able to give this to the
600 ss << "\\end_inset\n";
602 // This seems like a bug in stringstream.
603 // We really should be able to use ss
605 istringstream is(ss.str());
607 tmplex.setStream(is);
608 Inset * inset = new InsetCaption;
609 inset->Read(this, tmplex);
610 par->InsertInset(pos, inset, font);
614 #ifndef NO_COMPABILITY
615 if (create_new_par) {
620 par = new Paragraph(par);
621 par->layout(textclasslist[params.textclass].defaultLayoutName());
624 par->layout(layoutname);
625 // Test whether the layout is obsolete.
626 LyXLayout const & layout =
627 textclasslist[params.textclass][par->layout()];
628 if (!layout.obsoleted_by().empty())
629 par->layout(layout.obsoleted_by());
630 par->params().depth(depth);
631 #ifndef NO_COMPABILITY
633 // we duplicate code here because it's easier to remove
634 // the code then of NO_COMPATIBILITY
635 par->layout(layoutname);
636 // Test whether the layout is obsolete.
637 LyXLayout const & layout =
638 textclasslist[params.textclass][par->layout()];
639 if (!layout.obsoleted_by().empty())
640 par->layout(layout.obsoleted_by());
641 par->params().depth(depth);
648 } else if (token == "\\end_inset") {
649 lyxerr << "Solitary \\end_inset. Missing \\begin_inset?.\n"
650 << "Last inset read was: " << last_inset_read
652 // Simply ignore this. The insets do not have
654 // But insets should read it, it is a part of
655 // the inset isn't it? Lgb.
656 } else if (token == "\\begin_inset") {
657 #ifndef NO_COMPABILITY
658 insertErtContents(par, pos, false);
659 ert_stack.push(ert_comp);
660 ert_comp = ErtComp();
662 readInset(lex, par, pos, font);
663 #ifndef NO_COMPABILITY
664 ert_comp = ert_stack.top();
666 insertErtContents(par, pos);
668 } else if (token == "\\family") {
670 font.setLyXFamily(lex.getString());
671 } else if (token == "\\series") {
673 font.setLyXSeries(lex.getString());
674 } else if (token == "\\shape") {
676 font.setLyXShape(lex.getString());
677 } else if (token == "\\size") {
679 font.setLyXSize(lex.getString());
680 #ifndef NO_COMPABILITY
681 } else if (token == "\\latex") {
683 string const tok = lex.getString();
684 if (tok == "no_latex") {
686 insertErtContents(par, pos);
687 } else if (tok == "latex") {
688 ert_comp.active = true;
689 ert_comp.font = font;
690 } else if (tok == "default") {
692 insertErtContents(par, pos);
694 lex.printError("Unknown LaTeX font flag "
698 } else if (token == "\\lang") {
700 string const tok = lex.getString();
701 Language const * lang = languages.getLanguage(tok);
703 font.setLanguage(lang);
705 font.setLanguage(params.language);
706 lex.printError("Unknown language `$$Token'");
708 } else if (token == "\\numeric") {
710 font.setNumber(font.setLyXMisc(lex.getString()));
711 } else if (token == "\\emph") {
713 font.setEmph(font.setLyXMisc(lex.getString()));
714 } else if (token == "\\bar") {
716 string const tok = lex.getString();
717 // This is dirty, but gone with LyX3. (Asger)
719 font.setUnderbar(LyXFont::ON);
720 else if (tok == "no")
721 font.setUnderbar(LyXFont::OFF);
722 else if (tok == "default")
723 font.setUnderbar(LyXFont::INHERIT);
725 lex.printError("Unknown bar font flag "
727 } else if (token == "\\noun") {
729 font.setNoun(font.setLyXMisc(lex.getString()));
730 } else if (token == "\\color") {
732 font.setLyXColor(lex.getString());
733 } else if (token == "\\SpecialChar") {
734 LyXLayout const & layout =
735 textclasslist[params.textclass][par->layout()];
737 // Insets don't make sense in a free-spacing context! ---Kayvan
738 if (layout.free_spacing || par->isFreeSpacing()) {
741 string next_token = lex.getString();
742 if (next_token == "\\-") {
743 par->insertChar(pos, '-', font);
744 } else if (next_token == "\\protected_separator"
745 || next_token == "~") {
746 par->insertChar(pos, ' ', font);
748 lex.printError("Token `$$Token' "
750 "paragraph layout!");
755 Inset * inset = new InsetSpecialChar;
756 inset->read(this, lex);
757 par->insertInset(pos, inset, font);
760 } else if (token == "\\i") {
761 Inset * inset = new InsetLatexAccent;
762 inset->read(this, lex);
763 par->insertInset(pos, inset, font);
765 } else if (token == "\\backslash") {
766 #ifndef NO_COMPABILITY
767 if (ert_comp.active) {
768 ert_comp.contents += "\\";
771 par->insertChar(pos, '\\', font);
773 #ifndef NO_COMPABILITY
776 #ifndef NO_COMPABILITY
777 } else if (token == "\\begin_float") {
778 insertErtContents(par, pos);
779 //insertErtContents(par, pos, false);
780 //ert_stack.push(ert_comp);
781 //ert_comp = ErtComp();
783 // This is the compability reader. It can be removed in
784 // LyX version 1.3.0. (Lgb)
786 string const tmptok = lex.getString();
787 //lyxerr << "old float: " << tmptok << endl;
790 stringstream old_float;
792 if (tmptok == "footnote") {
793 inset = new InsetFoot(params);
794 old_float << "collapsed true\n";
795 } else if (tmptok == "margin") {
796 inset = new InsetMarginal(params);
797 old_float << "collapsed true\n";
798 } else if (tmptok == "fig") {
799 inset = new InsetFloat(params, "figure");
800 old_float << "placement htbp\n"
802 << "collapsed false\n";
803 } else if (tmptok == "tab") {
804 inset = new InsetFloat(params, "table");
805 old_float << "placement htbp\n"
807 << "collapsed false\n";
808 } else if (tmptok == "alg") {
809 inset = new InsetFloat(params, "algorithm");
810 old_float << "placement htbp\n"
812 << "collapsed false\n";
813 } else if (tmptok == "wide-fig") {
814 inset = new InsetFloat(params, "figure");
815 //InsetFloat * tmp = new InsetFloat("figure");
818 old_float << "placement htbp\n"
820 << "collapsed false\n";
821 } else if (tmptok == "wide-tab") {
822 inset = new InsetFloat(params, "table");
823 //InsetFloat * tmp = new InsetFloat("table");
826 old_float << "placement htbp\n"
828 << "collapsed false\n";
832 #ifndef NO_PEXTRA_REALLY
835 return false; // no end read yet
838 // Here we need to check for \end_deeper and handle that
839 // before we do the footnote parsing.
840 // This _is_ a hack! (Lgb)
843 string const tmp = lex.getString();
844 if (tmp == "\\end_deeper") {
845 //lyxerr << "\\end_deeper caught!" << endl;
847 lex.printError("\\end_deeper: "
848 "depth is already null");
853 old_float << tmp << ' ';
858 old_float << lex.getLongString("\\end_float")
859 << "\n\\end_inset\n";
860 //lyxerr << "Float Body:\n" << old_float.str() << endl;
861 // That this does not work seems like a bug
862 // in stringstream. (Lgb)
863 istringstream istr(old_float.str());
865 nylex.setStream(istr);
866 inset->read(this, nylex);
867 par->insertInset(pos, inset, font);
869 insertErtContents(par, pos);
871 // we have to reset the font as in the old format after a float
872 // the font was automatically reset!
873 font = LyXFont(LyXFont::ALL_INHERIT, params.language);
875 } else if (token == "\\begin_deeper") {
877 } else if (token == "\\end_deeper") {
879 lex.printError("\\end_deeper: "
880 "depth is already null");
884 } else if (token == "\\begin_preamble") {
885 params.readPreamble(lex);
886 } else if (token == "\\textclass") {
888 pair<bool, textclass_type> pp =
889 textclasslist.NumberOfClass(lex.getString());
891 params.textclass = pp.second;
893 Alert::alert(string(_("Textclass error")),
894 string(_("The document uses an unknown textclass \"")) +
895 lex.getString() + string("\"."),
896 string(_("LyX will not be able to produce output correctly.")));
897 params.textclass = 0;
899 if (!textclasslist[params.textclass].load()) {
900 // if the textclass wasn't loaded properly
901 // we need to either substitute another
902 // or stop loading the file.
903 // I can substitute but I don't see how I can
904 // stop loading... ideas?? ARRae980418
905 Alert::alert(_("Textclass Loading Error!"),
906 string(_("Can't load textclass ")) +
907 textclasslist[params.textclass].name(),
908 _("-- substituting default"));
909 params.textclass = 0;
911 } else if (token == "\\options") {
913 params.options = lex.getString();
914 } else if (token == "\\language") {
915 params.readLanguage(lex);
916 } else if (token == "\\fontencoding") {
918 } else if (token == "\\inputencoding") {
920 params.inputenc = lex.getString();
921 } else if (token == "\\graphics") {
922 params.readGraphicsDriver(lex);
923 } else if (token == "\\fontscheme") {
925 params.fonts = lex.getString();
926 } else if (token == "\\noindent") {
927 par->params().noindent(true);
928 } else if (token == "\\leftindent") {
930 LyXLength value(lex.getString());
931 par->params().leftIndent(value);
932 } else if (token == "\\fill_top") {
933 par->params().spaceTop(VSpace(VSpace::VFILL));
934 } else if (token == "\\fill_bottom") {
935 par->params().spaceBottom(VSpace(VSpace::VFILL));
936 } else if (token == "\\line_top") {
937 par->params().lineTop(true);
938 } else if (token == "\\line_bottom") {
939 par->params().lineBottom(true);
940 } else if (token == "\\pagebreak_top") {
941 par->params().pagebreakTop(true);
942 } else if (token == "\\pagebreak_bottom") {
943 par->params().pagebreakBottom(true);
944 } else if (token == "\\start_of_appendix") {
945 par->params().startOfAppendix(true);
946 } else if (token == "\\paragraph_separation") {
947 int tmpret = lex.findToken(string_paragraph_separation);
950 if (tmpret != LYX_LAYOUT_DEFAULT)
951 params.paragraph_separation =
952 static_cast<BufferParams::PARSEP>(tmpret);
953 } else if (token == "\\defskip") {
955 params.defskip = VSpace(lex.getString());
956 #ifndef NO_COMPABILITY
957 } else if (token == "\\epsfig") { // obsolete
958 // Indeed it is obsolete, but we HAVE to be backwards
959 // compatible until 0.14, because otherwise all figures
960 // in existing documents are irretrivably lost. (Asger)
961 params.readGraphicsDriver(lex);
963 } else if (token == "\\quotes_language") {
964 int tmpret = lex.findToken(string_quotes_language);
967 if (tmpret != LYX_LAYOUT_DEFAULT) {
968 InsetQuotes::quote_language tmpl =
969 InsetQuotes::EnglishQ;
972 tmpl = InsetQuotes::EnglishQ;
975 tmpl = InsetQuotes::SwedishQ;
978 tmpl = InsetQuotes::GermanQ;
981 tmpl = InsetQuotes::PolishQ;
984 tmpl = InsetQuotes::FrenchQ;
987 tmpl = InsetQuotes::DanishQ;
990 params.quotes_language = tmpl;
992 } else if (token == "\\quotes_times") {
994 switch (lex.getInteger()) {
996 params.quotes_times = InsetQuotes::SingleQ;
999 params.quotes_times = InsetQuotes::DoubleQ;
1002 } else if (token == "\\papersize") {
1003 int tmpret = lex.findToken(string_papersize);
1007 params.papersize2 = tmpret;
1008 } else if (token == "\\paperpackage") {
1009 int tmpret = lex.findToken(string_paperpackages);
1012 params.paperpackage = BufferParams::PACKAGE_NONE;
1014 params.paperpackage = tmpret;
1015 } else if (token == "\\use_geometry") {
1017 params.use_geometry = lex.getInteger();
1018 } else if (token == "\\use_amsmath") {
1020 params.use_amsmath = lex.getInteger();
1021 } else if (token == "\\use_natbib") {
1023 params.use_natbib = lex.getInteger();
1024 } else if (token == "\\use_numerical_citations") {
1026 params.use_numerical_citations = lex.getInteger();
1027 } else if (token == "\\paperorientation") {
1028 int tmpret = lex.findToken(string_orientation);
1031 if (tmpret != LYX_LAYOUT_DEFAULT)
1032 params.orientation = static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
1033 } else if (token == "\\paperwidth") {
1035 params.paperwidth = lex.getString();
1036 } else if (token == "\\paperheight") {
1038 params.paperheight = lex.getString();
1039 } else if (token == "\\leftmargin") {
1041 params.leftmargin = lex.getString();
1042 } else if (token == "\\topmargin") {
1044 params.topmargin = lex.getString();
1045 } else if (token == "\\rightmargin") {
1047 params.rightmargin = lex.getString();
1048 } else if (token == "\\bottommargin") {
1050 params.bottommargin = lex.getString();
1051 } else if (token == "\\headheight") {
1053 params.headheight = lex.getString();
1054 } else if (token == "\\headsep") {
1056 params.headsep = lex.getString();
1057 } else if (token == "\\footskip") {
1059 params.footskip = lex.getString();
1060 } else if (token == "\\paperfontsize") {
1062 params.fontsize = strip(lex.getString());
1063 } else if (token == "\\papercolumns") {
1065 params.columns = lex.getInteger();
1066 } else if (token == "\\papersides") {
1068 switch (lex.getInteger()) {
1070 case 1: params.sides = LyXTextClass::OneSide; break;
1071 case 2: params.sides = LyXTextClass::TwoSides; break;
1073 } else if (token == "\\paperpagestyle") {
1075 params.pagestyle = strip(lex.getString());
1076 } else if (token == "\\bullet") {
1078 int const index = lex.getInteger();
1080 int temp_int = lex.getInteger();
1081 params.user_defined_bullets[index].setFont(temp_int);
1082 params.temp_bullets[index].setFont(temp_int);
1084 temp_int = lex.getInteger();
1085 params.user_defined_bullets[index].setCharacter(temp_int);
1086 params.temp_bullets[index].setCharacter(temp_int);
1088 temp_int = lex.getInteger();
1089 params.user_defined_bullets[index].setSize(temp_int);
1090 params.temp_bullets[index].setSize(temp_int);
1092 string const temp_str = lex.getString();
1093 if (temp_str != "\\end_bullet") {
1094 // this element isn't really necessary for
1095 // parsing but is easier for humans
1096 // to understand bullets. Put it back and
1097 // set a debug message?
1098 lex.printError("\\end_bullet expected, got" + temp_str);
1099 //how can I put it back?
1101 } else if (token == "\\bulletLaTeX") {
1102 // The bullet class should be able to read this.
1104 int const index = lex.getInteger();
1106 string temp_str = lex.getString();
1108 while (temp_str != "\\end_bullet") {
1109 // this loop structure is needed when user
1110 // enters an empty string since the first
1111 // thing returned will be the \\end_bullet
1113 // if the LaTeX entry has spaces. Each element
1114 // therefore needs to be read in turn
1115 sum_str += temp_str;
1117 temp_str = lex.getString();
1120 params.user_defined_bullets[index].setText(sum_str);
1121 params.temp_bullets[index].setText(sum_str);
1122 } else if (token == "\\secnumdepth") {
1124 params.secnumdepth = lex.getInteger();
1125 } else if (token == "\\tocdepth") {
1127 params.tocdepth = lex.getInteger();
1128 } else if (token == "\\spacing") {
1130 string const tmp = strip(lex.getString());
1131 Spacing::Space tmp_space = Spacing::Default;
1132 float tmp_val = 0.0;
1133 if (tmp == "single") {
1134 tmp_space = Spacing::Single;
1135 } else if (tmp == "onehalf") {
1136 tmp_space = Spacing::Onehalf;
1137 } else if (tmp == "double") {
1138 tmp_space = Spacing::Double;
1139 } else if (tmp == "other") {
1141 tmp_space = Spacing::Other;
1142 tmp_val = lex.getFloat();
1144 lex.printError("Unknown spacing token: '$$Token'");
1146 // Small hack so that files written with klyx will be
1147 // parsed correctly.
1149 par->params().spacing(Spacing(tmp_space, tmp_val));
1151 params.spacing.set(tmp_space, tmp_val);
1153 } else if (token == "\\paragraph_spacing") {
1155 string const tmp = strip(lex.getString());
1156 if (tmp == "single") {
1157 par->params().spacing(Spacing(Spacing::Single));
1158 } else if (tmp == "onehalf") {
1159 par->params().spacing(Spacing(Spacing::Onehalf));
1160 } else if (tmp == "double") {
1161 par->params().spacing(Spacing(Spacing::Double));
1162 } else if (tmp == "other") {
1164 par->params().spacing(Spacing(Spacing::Other,
1167 lex.printError("Unknown spacing token: '$$Token'");
1169 } else if (token == "\\float_placement") {
1171 params.float_placement = lex.getString();
1172 } else if (token == "\\align") {
1173 int tmpret = lex.findToken(string_align);
1174 if (tmpret == -1) ++tmpret;
1175 if (tmpret != LYX_LAYOUT_DEFAULT) { // tmpret != 99 ???
1176 int const tmpret2 = int(pow(2.0, tmpret));
1177 //lyxerr << "Tmpret2 = " << tmpret2 << endl;
1178 par->params().align(LyXAlignment(tmpret2));
1180 } else if (token == "\\added_space_top") {
1182 VSpace value = VSpace(lex.getString());
1183 // only add the length when value > 0 or
1185 if ((value.length().len().value() != 0) ||
1187 (value.kind() != VSpace::LENGTH))
1188 par->params().spaceTop(value);
1189 } else if (token == "\\added_space_bottom") {
1191 VSpace value = VSpace(lex.getString());
1192 // only add the length when value > 0 or
1194 if ((value.length().len().value() != 0) ||
1196 (value.kind() != VSpace::LENGTH))
1197 par->params().spaceBottom(value);
1198 #ifndef NO_COMPABILITY
1199 #ifndef NO_PEXTRA_REALLY
1200 } else if (token == "\\pextra_type") {
1202 par->params().pextraType(lex.getInteger());
1203 } else if (token == "\\pextra_width") {
1205 par->params().pextraWidth(lex.getString());
1206 } else if (token == "\\pextra_widthp") {
1208 par->params().pextraWidthp(lex.getString());
1209 } else if (token == "\\pextra_alignment") {
1211 par->params().pextraAlignment(lex.getInteger());
1212 } else if (token == "\\pextra_hfill") {
1214 par->params().pextraHfill(lex.getInteger());
1215 } else if (token == "\\pextra_start_minipage") {
1217 par->params().pextraStartMinipage(lex.getInteger());
1220 } else if (token == "\\labelwidthstring") {
1222 par->params().labelWidthString(lex.getString());
1223 // do not delete this token, it is still needed!
1224 } else if (token == "\\newline") {
1225 #ifndef NO_COMPABILITY
1226 if (!ert_comp.in_tabular && ert_comp.active) {
1227 ert_comp.contents += char(Paragraph::META_NEWLINE);
1229 // Since we cannot know it this is only a regular
1230 // newline or a tabular cell delimter we have to
1231 // handle the ERT here.
1232 insertErtContents(par, pos, false);
1234 par->insertChar(pos, Paragraph::META_NEWLINE, font);
1238 par->insertChar(pos, Paragraph::META_NEWLINE, font);
1241 } else if (token == "\\LyXTable") {
1242 #ifndef NO_COMPABILITY
1243 ert_comp.in_tabular = true;
1245 Inset * inset = new InsetTabular(*this);
1246 inset->read(this, lex);
1247 par->insertInset(pos, inset, font);
1249 } else if (token == "\\hfill") {
1250 par->insertChar(pos, Paragraph::META_HFILL, font);
1252 } else if (token == "\\protected_separator") { // obsolete
1253 // This is a backward compability thingie. (Lgb)
1254 // Remove it later some time...introduced with fileformat
1256 LyXLayout const & layout =
1257 textclasslist[params.textclass][par->layout()];
1259 if (layout.free_spacing || par->isFreeSpacing()) {
1260 par->insertChar(pos, ' ', font);
1262 Inset * inset = new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
1263 par->insertInset(pos, inset, font);
1266 } else if (token == "\\bibitem") { // ale970302
1268 InsetCommandParams p("bibitem", "dummy");
1269 par->bibkey = new InsetBibKey(p);
1271 par->bibkey->read(this, lex);
1272 } else if (token == "\\the_end") {
1273 #ifndef NO_COMPABILITY
1274 // If we still have some ert active here we have to insert
1275 // it so we don't loose it. (Lgb)
1276 insertErtContents(par, pos);
1278 the_end_read = true;
1279 #ifndef NO_COMPABILITY
1280 #ifndef NO_PEXTRA_REALLY
1283 minipar = parBeforeMinipage = 0;
1287 #ifndef NO_COMPABILITY
1288 if (ert_comp.active) {
1289 ert_comp.contents += token;
1292 // This should be insurance for the future: (Asger)
1295 string const s = _("Unknown token: ") + token
1296 + " " + lex.text() + "\n";
1297 // we can do this here this way because we're actually reading
1298 // the buffer and don't care about LyXText right now.
1299 InsetError * new_inset = new InsetError(s);
1300 par->insertInset(pos, new_inset, LyXFont(LyXFont::ALL_INHERIT,
1303 #ifndef NO_COMPABILITY
1308 #ifndef NO_COMPABILITY
1309 #ifndef NO_PEXTRA_REALLY
1310 // I wonder if we could use this blanket fix for all the
1311 // checkminipage cases...
1312 // don't forget about ert paragraphs and compatibility read for'em
1313 if (par && (par->size() || !ert_comp.contents.empty())) {
1314 // It is possible that this will check to often,
1315 // but that should not be an correctness issue.
1316 // Only a speed issue.
1317 checkminipage = true;
1320 // now check if we have a minipage paragraph as at this
1321 // point we already read all the necessary data!
1322 // this cannot be done in layout because there we did
1323 // not read yet the paragraph PEXTRA-params (Jug)
1325 // BEGIN pextra_minipage compability
1326 // This should be removed in 1.3.x (Lgb)
1327 // I don't think we should remove this so fast (Jug)
1329 // This compability code is not perfect. In a couple
1330 // of rand cases it fails. When the minipage par is
1331 // the first par in the document, and when there are
1332 // none or only one regular paragraphs after the
1333 // minipage. Currently I am not investing any effort
1334 // in fixing those cases.
1336 // lyxerr << "Call depth: " << call_depth << endl;
1337 // lyxerr << "Checkminipage: " << checkminipage << endl;
1339 if (checkminipage && (call_depth == 1)) {
1340 checkminipage = false;
1341 if (minipar && (minipar != par) &&
1342 (par->params().pextraType() == Paragraph::PEXTRA_MINIPAGE)) {
1343 lyxerr << "minipages in a row" << endl;
1344 if (par->params().pextraStartMinipage()) {
1345 lyxerr << "start new minipage" << endl;
1346 // minipages in a row
1347 par->previous()->next(0);
1350 Paragraph * tmp = minipar;
1352 tmp->params().pextraType(0);
1353 tmp->params().pextraWidth(string());
1354 tmp->params().pextraWidthp(string());
1355 tmp->params().pextraAlignment(0);
1356 tmp->params().pextraHfill(false);
1357 tmp->params().pextraStartMinipage(false);
1360 // create a new paragraph to insert the
1361 // minipages in the following case
1362 if (par->params().pextraStartMinipage() &&
1363 !par->params().pextraHfill()) {
1364 Paragraph * p = new Paragraph;
1365 p->layout(textclasslist[params.textclass].defaultLayoutName());
1367 p->previous(parBeforeMinipage);
1368 parBeforeMinipage->next(p);
1370 p->params().depth(parBeforeMinipage->params().depth());
1371 parBeforeMinipage = p;
1373 InsetMinipage * mini = new InsetMinipage(params);
1374 mini->pos(static_cast<InsetMinipage::Position>(par->params().pextraAlignment()));
1375 mini->pageWidth(LyXLength(par->params().pextraWidth()));
1376 if (!par->params().pextraWidthp().empty()) {
1377 lyxerr << "WP:" << mini->pageWidth().asString() << endl;
1378 mini->pageWidth(LyXLength((par->params().pextraWidthp())+"col%"));
1380 Paragraph * op = mini->firstParagraph();
1381 mini->inset.paragraph(par);
1383 // and free the old ones!
1386 Paragraph * pp = op->next();
1390 // Insert the minipage last in the
1391 // previous paragraph.
1392 if (par->params().pextraHfill()) {
1393 parBeforeMinipage->insertChar
1394 (parBeforeMinipage->size(),
1395 Paragraph::META_HFILL, font);
1397 parBeforeMinipage->insertInset
1398 (parBeforeMinipage->size(), mini, font);
1402 lyxerr << "new minipage par" << endl;
1403 //nothing to do just continue reading
1406 } else if (minipar && (minipar != par)) {
1407 lyxerr << "last minipage par read" << endl;
1408 // The last paragraph read was not part of a
1409 // minipage but the par linked list is...
1410 // So we need to remove the last par from the
1412 if (par->previous())
1413 par->previous()->next(0);
1414 par->previous(parBeforeMinipage);
1415 parBeforeMinipage->next(par);
1416 Paragraph * tmp = minipar;
1418 tmp->params().pextraType(0);
1419 tmp->params().pextraWidth(string());
1420 tmp->params().pextraWidthp(string());
1421 tmp->params().pextraAlignment(0);
1422 tmp->params().pextraHfill(false);
1423 tmp->params().pextraStartMinipage(false);
1426 depth = parBeforeMinipage->params().depth();
1427 // and set this depth on the par as it has not been set already
1428 par->params().depth(depth);
1429 minipar = parBeforeMinipage = 0;
1430 } else if (!minipar &&
1431 (par->params().pextraType() == Paragraph::PEXTRA_MINIPAGE)) {
1432 // par is the first paragraph in a minipage
1433 lyxerr << "begin minipage" << endl;
1434 // To minimize problems for
1435 // the users we will insert
1436 // the first minipage in
1437 // a sequence of minipages
1438 // in its own paragraph.
1439 Paragraph * p = new Paragraph;
1440 p->layout(textclasslist[params.textclass].defaultLayoutName());
1441 p->previous(par->previous());
1443 p->params().depth(depth);
1444 par->params().depth(0);
1446 if (par->previous())
1447 par->previous()->next(p);
1449 parBeforeMinipage = p;
1451 if (!first_par || (first_par == par))
1454 InsetMinipage * mini = new InsetMinipage(params);
1455 mini->pos(static_cast<InsetMinipage::Position>(minipar->params().pextraAlignment()));
1456 mini->pageWidth(LyXLength(minipar->params().pextraWidth()));
1457 if (!par->params().pextraWidthp().empty()) {
1458 lyxerr << "WP:" << mini->pageWidth().asString() << endl;
1459 mini->pageWidth(LyXLength((par->params().pextraWidthp())+"col%"));
1462 Paragraph * op = mini->firstParagraph();
1463 mini->inset.paragraph(minipar);
1465 // and free the old ones!
1468 Paragraph * pp = op->next();
1473 // Insert the minipage last in the
1474 // previous paragraph.
1475 if (minipar->params().pextraHfill()) {
1476 parBeforeMinipage->insertChar
1477 (parBeforeMinipage->size(),
1478 Paragraph::META_HFILL, font);
1480 parBeforeMinipage->insertInset
1481 (parBeforeMinipage->size(), mini, font);
1482 } else if (par->params().pextraType() == Paragraph::PEXTRA_INDENT) {
1483 par->params().leftIndent(LyXLength(par->params().pextraWidth()));
1484 if (!par->params().pextraWidthp().empty()) {
1485 par->params().leftIndent(LyXLength((par->params().pextraWidthp())+"col%"));
1489 // End of pextra_minipage compability
1493 return the_end_read;
1496 // needed to insert the selection
1497 void Buffer::insertStringAsLines(Paragraph *& par, pos_type & pos,
1498 LyXFont const & fn,string const & str) const
1500 LyXLayout const & layout =
1501 textclasslist[params.textclass][par->layout()];
1504 par->checkInsertChar(font);
1505 // insert the string, don't insert doublespace
1506 bool space_inserted = true;
1507 bool autobreakrows = !par->inInset() ||
1508 static_cast<InsetText *>(par->inInset())->getAutoBreakRows();
1509 for(string::const_iterator cit = str.begin();
1510 cit != str.end(); ++cit) {
1512 if (autobreakrows && (par->size() || layout.keepempty)) {
1513 par->breakParagraph(params, pos,
1514 layout.isEnvironment());
1517 space_inserted = true;
1521 // do not insert consecutive spaces if !free_spacing
1522 } else if ((*cit == ' ' || *cit == '\t') &&
1523 space_inserted && !layout.free_spacing &&
1524 !par->isFreeSpacing())
1527 } else if (*cit == '\t') {
1528 if (!layout.free_spacing && !par->isFreeSpacing()) {
1529 // tabs are like spaces here
1530 par->insertChar(pos, ' ', font);
1532 space_inserted = true;
1534 const pos_type nb = 8 - pos % 8;
1535 for (pos_type a = 0; a < nb ; ++a) {
1536 par->insertChar(pos, ' ', font);
1539 space_inserted = true;
1541 } else if (!IsPrintable(*cit)) {
1542 // Ignore unprintables
1545 // just insert the character
1546 par->insertChar(pos, *cit, font);
1548 space_inserted = (*cit == ' ');
1555 void Buffer::readInset(LyXLex & lex, Paragraph *& par,
1556 int & pos, LyXFont & font)
1558 // consistency check
1559 if (lex.getString() != "\\begin_inset") {
1560 lyxerr << "Buffer::readInset: Consistency check failed."
1567 string const tmptok = lex.getString();
1568 last_inset_read = tmptok;
1570 // test the different insets
1571 if (tmptok == "LatexCommand") {
1572 InsetCommandParams inscmd;
1575 string const cmdName = inscmd.getCmdName();
1577 // This strange command allows LyX to recognize "natbib" style
1578 // citations: citet, citep, Citet etc.
1579 if (compare_no_case(cmdName, "cite", 4) == 0) {
1580 inset = new InsetCitation(inscmd);
1581 } else if (cmdName == "bibitem") {
1582 lex.printError("Wrong place for bibitem");
1583 inset = new InsetBibKey(inscmd);
1584 } else if (cmdName == "BibTeX") {
1585 inset = new InsetBibtex(inscmd);
1586 } else if (cmdName == "index") {
1587 inset = new InsetIndex(inscmd);
1588 } else if (cmdName == "include") {
1589 inset = new InsetInclude(inscmd, *this);
1590 } else if (cmdName == "label") {
1591 inset = new InsetLabel(inscmd);
1592 } else if (cmdName == "url"
1593 || cmdName == "htmlurl") {
1594 inset = new InsetUrl(inscmd);
1595 } else if (cmdName == "ref"
1596 || cmdName == "pageref"
1597 || cmdName == "vref"
1598 || cmdName == "vpageref"
1599 || cmdName == "prettyref") {
1600 if (!inscmd.getOptions().empty()
1601 || !inscmd.getContents().empty()) {
1602 inset = new InsetRef(inscmd, *this);
1604 } else if (cmdName == "tableofcontents") {
1605 inset = new InsetTOC(inscmd);
1606 } else if (cmdName == "listofalgorithms") {
1607 inset = new InsetFloatList("algorithm");
1608 } else if (cmdName == "listoffigures") {
1609 inset = new InsetFloatList("figure");
1610 } else if (cmdName == "listoftables") {
1611 inset = new InsetFloatList("table");
1612 } else if (cmdName == "printindex") {
1613 inset = new InsetPrintIndex(inscmd);
1614 } else if (cmdName == "lyxparent") {
1615 inset = new InsetParent(inscmd, *this);
1618 bool alreadyread = false;
1619 if (tmptok == "Quotes") {
1620 inset = new InsetQuotes;
1621 } else if (tmptok == "External") {
1622 inset = new InsetExternal;
1623 } else if (tmptok == "FormulaMacro") {
1624 inset = new InsetFormulaMacro;
1625 } else if (tmptok == "Formula") {
1626 inset = new InsetFormula;
1627 } else if (tmptok == "Figure") { // Backward compatibility
1628 // inset = new InsetFig(100, 100, *this);
1629 inset = new InsetGraphics;
1630 } else if (tmptok == "Graphics") {
1631 inset = new InsetGraphics;
1632 } else if (tmptok == "Info") {// backwards compatibility
1633 inset = new InsetNote(this,
1634 lex.getLongString("\\end_inset"),
1637 } else if (tmptok == "Note") {
1638 inset = new InsetNote(params);
1639 } else if (tmptok == "Include") {
1640 InsetCommandParams p("Include");
1641 inset = new InsetInclude(p, *this);
1642 } else if (tmptok == "ERT") {
1643 inset = new InsetERT(params);
1644 } else if (tmptok == "Tabular") {
1645 inset = new InsetTabular(*this);
1646 } else if (tmptok == "Text") {
1647 inset = new InsetText(params);
1648 } else if (tmptok == "Foot") {
1649 inset = new InsetFoot(params);
1650 } else if (tmptok == "Marginal") {
1651 inset = new InsetMarginal(params);
1652 } else if (tmptok == "Minipage") {
1653 inset = new InsetMinipage(params);
1654 } else if (tmptok == "Float") {
1656 string tmptok = lex.getString();
1657 inset = new InsetFloat(params, tmptok);
1659 } else if (tmptok == "List") {
1660 inset = new InsetList;
1661 } else if (tmptok == "Theorem") {
1662 inset = new InsetList;
1664 } else if (tmptok == "Caption") {
1665 inset = new InsetCaption(params);
1666 } else if (tmptok == "FloatList") {
1667 inset = new InsetFloatList;
1670 if (inset && !alreadyread) inset->read(this, lex);
1674 par->insertInset(pos, inset, font);
1680 bool Buffer::readFile(LyXLex & lex, Paragraph * par)
1684 string const token(lex.getString());
1685 if (token == "\\lyxformat") { // the first token _must_ be...
1687 string tmp_format = lex.getString();
1688 //lyxerr << "LyX Format: `" << tmp_format << "'" << endl;
1689 // if present remove ".," from string.
1690 string::size_type dot = tmp_format.find_first_of(".,");
1691 //lyxerr << " dot found at " << dot << endl;
1692 if (dot != string::npos)
1693 tmp_format.erase(dot, 1);
1694 file_format = strToInt(tmp_format);
1695 if (file_format == LYX_FORMAT) {
1697 } else if (file_format > LYX_FORMAT) {
1699 Alert::alert(_("Warning!"),
1700 _("LyX file format is newer that what"),
1701 _("is supported in this LyX version. Expect some problems."));
1703 } else if (file_format < LYX_FORMAT) {
1705 if (file_format < 200) {
1706 Alert::alert(_("ERROR!"),
1707 _("Old LyX file format found. "
1708 "Use LyX 0.10.x to read this!"));
1710 } else if (file_format < 220) {
1711 Alert::alert(_("ERROR!"),
1712 _("Old LyX file format found. "
1713 "User LyX 1.2.x to read this!"));
1717 bool the_end = readLyXformat2(lex, par);
1718 params.setPaperStuff();
1721 // the_end was added in 213
1722 if (file_format < 213)
1727 Alert::alert(_("Warning!"),
1728 _("Reading of document is not complete"),
1729 _("Maybe the document is truncated"));
1732 } else { // "\\lyxformat" not found
1733 Alert::alert(_("ERROR!"), _("Not a LyX file!"));
1736 Alert::alert(_("ERROR!"), _("Unable to read file!"));
1741 // Should probably be moved to somewhere else: BufferView? LyXView?
1742 bool Buffer::save() const
1744 // We don't need autosaves in the immediate future. (Asger)
1745 resetAutosaveTimers();
1749 if (lyxrc.make_backup) {
1750 s = fileName() + '~';
1751 if (!lyxrc.backupdir_path.empty())
1752 s = AddName(lyxrc.backupdir_path,
1753 subst(os::slashify_path(s),'/','!'));
1755 // Rename is the wrong way of making a backup,
1756 // this is the correct way.
1757 /* truss cp fil fil2:
1758 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
1759 stat("LyXVC.lyx", 0xEFFFF688) = 0
1760 open("LyXVC.lyx", O_RDONLY) = 3
1761 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
1762 fstat(4, 0xEFFFF508) = 0
1763 fstat(3, 0xEFFFF508) = 0
1764 read(3, " # T h i s f i l e w".., 8192) = 5579
1765 write(4, " # T h i s f i l e w".., 5579) = 5579
1766 read(3, 0xEFFFD4A0, 8192) = 0
1769 chmod("LyXVC3.lyx", 0100644) = 0
1770 lseek(0, 0, SEEK_CUR) = 46440
1774 // Should probably have some more error checking here.
1775 // Doing it this way, also makes the inodes stay the same.
1776 // This is still not a very good solution, in particular we
1777 // might loose the owner of the backup.
1778 FileInfo finfo(fileName());
1779 if (finfo.exist()) {
1780 mode_t fmode = finfo.getMode();
1781 struct utimbuf times = {
1782 finfo.getAccessTime(),
1783 finfo.getModificationTime() };
1785 ifstream ifs(fileName().c_str());
1786 ofstream ofs(s.c_str(), ios::out|ios::trunc);
1791 ::chmod(s.c_str(), fmode);
1793 if (::utime(s.c_str(), ×)) {
1794 lyxerr << "utime error." << endl;
1797 lyxerr << "LyX was not able to make "
1798 "backup copy. Beware." << endl;
1803 if (writeFile(fileName(), false)) {
1805 removeAutosaveFile(fileName());
1807 // Saving failed, so backup is not backup
1808 if (lyxrc.make_backup) {
1809 lyx::rename(s, fileName());
1817 // Returns false if unsuccesful
1818 bool Buffer::writeFile(string const & fname, bool flag) const
1820 // if flag is false writeFile will not create any GUI
1821 // warnings, only cerr.
1822 // Needed for autosave in background or panic save (Matthias 120496)
1824 if (read_only && (fname == fileName())) {
1825 // Here we should come with a question if we should
1826 // perform the write anyway.
1828 lyxerr << _("Error! Document is read-only: ")
1831 Alert::alert(_("Error! Document is read-only: "),
1836 FileInfo finfo(fname);
1837 if (finfo.exist() && !finfo.writable()) {
1838 // Here we should come with a question if we should
1839 // try to do the save anyway. (i.e. do a chmod first)
1841 lyxerr << _("Error! Cannot write file: ")
1844 Alert::err_alert(_("Error! Cannot write file: "),
1849 ofstream ofs(fname.c_str());
1852 lyxerr << _("Error! Cannot open file: ")
1855 Alert::err_alert(_("Error! Cannot open file: "),
1861 // Use the standard "C" locale for file output.
1862 ofs.imbue(std::locale::classic());
1865 // The top of the file should not be written by params.
1867 // write out a comment in the top of the file
1868 ofs << '#' << lyx_docversion
1869 << " created this file. For more info see http://www.lyx.org/\n"
1870 << "\\lyxformat " << LYX_FORMAT << "\n";
1872 // now write out the buffer paramters.
1873 params.writeFile(ofs);
1875 Paragraph::depth_type depth = 0;
1877 // this will write out all the paragraphs
1878 // using recursive descent.
1879 paragraph->writeFile(this, ofs, params, depth);
1881 // Write marker that shows file is complete
1882 ofs << "\n\\the_end" << endl;
1886 // how to check if close went ok?
1887 // Following is an attempt... (BE 20001011)
1889 // good() returns false if any error occured, including some
1890 // formatting error.
1891 // bad() returns true if something bad happened in the buffer,
1892 // which should include file system full errors.
1899 lyxerr << "Buffer::writeFile: BAD ERROR!" << endl;
1901 lyxerr << "Buffer::writeFile: NOT SO BAD ERROR!"
1913 pair<int, string> const addDepth(int depth, int ldepth)
1917 d += (ldepth - depth) * 2;
1918 return make_pair(d, string(d, ' '));
1924 string const Buffer::asciiParagraph(Paragraph const * par,
1925 unsigned int linelen,
1926 bool noparbreak) const
1928 ostringstream buffer;
1929 Paragraph::depth_type depth = 0;
1931 Paragraph::depth_type ltype_depth = 0;
1932 bool ref_printed = false;
1933 // if (!par->previous()) {
1935 // begins or ends a deeper area ?
1936 if (depth != par->params().depth()) {
1937 if (par->params().depth() > depth) {
1938 while (par->params().depth() > depth) {
1942 while (par->params().depth() < depth) {
1948 depth = par->params().depth();
1951 // First write the layout
1952 string const & tmp = par->layout();
1953 if (compare_no_case(tmp, "itemize") == 0) {
1955 ltype_depth = depth + 1;
1956 } else if (compare_no_case(tmp, "enumerate") == 0) {
1958 ltype_depth = depth + 1;
1959 } else if (contains(lowercase(tmp), "ection")) {
1961 ltype_depth = depth + 1;
1962 } else if (contains(lowercase(tmp), "aragraph")) {
1964 ltype_depth = depth + 1;
1965 } else if (compare_no_case(tmp, "description") == 0) {
1967 ltype_depth = depth + 1;
1968 } else if (compare_no_case(tmp, "abstract") == 0) {
1971 } else if (compare_no_case(tmp, "bibliography") == 0) {
1979 /* maybe some vertical spaces */
1981 /* the labelwidthstring used in lists */
1985 /* some pagebreaks? */
1989 /* what about the alignment */
1991 // lyxerr << "Should this ever happen?" << endl;
1994 // linelen <= 0 is special and means we don't have pargraph breaks
1996 string::size_type currlinelen = 0;
2002 buffer << string(depth * 2, ' ');
2003 currlinelen += depth * 2;
2006 // we should probably change to the paragraph language in the
2007 // gettext here (if possible) so that strings are outputted in
2008 // the correct language! (20012712 Jug)
2012 case 4: // (Sub)Paragraph
2013 case 5: // Description
2017 buffer << _("Abstract") << "\n\n";
2020 string const abst = _("Abstract: ");
2022 currlinelen += abst.length();
2025 case 7: // Bibliography
2028 buffer << _("References") << "\n\n";
2031 string const refs = _("References: ");
2033 currlinelen += refs.length();
2041 string const parlab = par->params().labelString();
2042 buffer << parlab << " ";
2043 currlinelen += parlab.length() + 1;
2051 pair<int, string> p = addDepth(depth, ltype_depth);
2053 currlinelen += p.first;
2056 // this is to change the linebreak to do it by word a bit more
2057 // intelligent hopefully! (only in the case where we have a
2058 // max linelenght!) (Jug)
2062 for (pos_type i = 0; i < par->size(); ++i) {
2063 char c = par->getUChar(params, i);
2065 case Paragraph::META_INSET:
2067 Inset const * inset = par->getInset(i);
2071 currlinelen += word.length();
2074 if (inset->ascii(this, buffer, linelen)) {
2075 // to be sure it breaks paragraph
2076 currlinelen += linelen;
2082 case Paragraph::META_NEWLINE:
2084 buffer << word << "\n";
2087 pair<int, string> p = addDepth(depth,
2090 currlinelen = p.first;
2094 case Paragraph::META_HFILL:
2095 buffer << word << "\t";
2096 currlinelen += word.length() + 1;
2103 currlinelen + word.length() > linelen - 10) {
2105 pair<int, string> p =
2106 addDepth(depth, ltype_depth);
2108 currlinelen = p.first;
2111 buffer << word << ' ';
2112 currlinelen += word.length() + 1;
2119 lyxerr[Debug::INFO] <<
2120 "writeAsciiFile: NULL char in structure." << endl;
2122 if ((linelen > 0) &&
2123 (currlinelen + word.length()) > linelen)
2127 pair<int, string> p =
2128 addDepth(depth, ltype_depth);
2130 currlinelen = p.first;
2137 return buffer.str().c_str();
2141 void Buffer::writeFileAscii(string const & fname, int linelen)
2143 ofstream ofs(fname.c_str());
2145 Alert::err_alert(_("Error: Cannot write file:"), fname);
2148 writeFileAscii(ofs, linelen);
2152 void Buffer::writeFileAscii(ostream & ofs, int linelen)
2154 Paragraph * par = paragraph;
2156 ofs << asciiParagraph(par, linelen, par->previous() == 0);
2166 void Buffer::makeLaTeXFile(string const & fname,
2167 string const & original_path,
2168 bool nice, bool only_body)
2170 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
2172 ofstream ofs(fname.c_str());
2174 Alert::err_alert(_("Error: Cannot open file: "), fname);
2178 niceFile = nice; // this will be used by Insetincludes.
2180 tex_code_break_column = lyxrc.ascii_linelen;
2182 // validate the buffer.
2183 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
2184 LaTeXFeatures features(params);
2186 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
2189 // The starting paragraph of the coming rows is the
2190 // first paragraph of the document. (Asger)
2191 texrow.start(paragraph, 0);
2193 if (!only_body && nice) {
2194 ofs << "%% " << lyx_docversion << " created this file. "
2195 "For more info, see http://www.lyx.org/.\n"
2196 "%% Do not edit unless you really know what "
2201 lyxerr[Debug::INFO] << "lyx header finished" << endl;
2202 // There are a few differences between nice LaTeX and usual files:
2203 // usual is \batchmode and has a
2204 // special input@path to allow the including of figures
2205 // with either \input or \includegraphics (what figinsets do).
2206 // batchmode is not set if there is a tex_code_break_column.
2207 // In this case somebody is interested in the generated LaTeX,
2208 // so this is OK. input@path is set when the actual parameter
2209 // original_path is set. This is done for usual tex-file, but not
2210 // for nice-latex-file. (Matthias 250696)
2213 // code for usual, NOT nice-latex-file
2214 ofs << "\\batchmode\n"; // changed
2215 // from \nonstopmode
2218 if (!original_path.empty()) {
2219 string inputpath = os::external_path(original_path);
2220 subst(inputpath, "~", "\\string~");
2221 ofs << "\\makeatletter\n"
2222 << "\\def\\input@path{{"
2223 << inputpath << "/}}\n"
2224 << "\\makeatother\n";
2230 ofs << "\\documentclass";
2232 LyXTextClass const & tclass = textclasslist[params.textclass];
2234 ostringstream options; // the document class options.
2236 if (tokenPos(tclass.opt_fontsize(),
2237 '|', params.fontsize) >= 0) {
2238 // only write if existing in list (and not default)
2239 options << params.fontsize << "pt,";
2243 if (!params.use_geometry &&
2244 (params.paperpackage == BufferParams::PACKAGE_NONE)) {
2245 switch (params.papersize) {
2246 case BufferParams::PAPER_A4PAPER:
2247 options << "a4paper,";
2249 case BufferParams::PAPER_USLETTER:
2250 options << "letterpaper,";
2252 case BufferParams::PAPER_A5PAPER:
2253 options << "a5paper,";
2255 case BufferParams::PAPER_B5PAPER:
2256 options << "b5paper,";
2258 case BufferParams::PAPER_EXECUTIVEPAPER:
2259 options << "executivepaper,";
2261 case BufferParams::PAPER_LEGALPAPER:
2262 options << "legalpaper,";
2268 if (params.sides != tclass.sides()) {
2269 switch (params.sides) {
2270 case LyXTextClass::OneSide:
2271 options << "oneside,";
2273 case LyXTextClass::TwoSides:
2274 options << "twoside,";
2280 if (params.columns != tclass.columns()) {
2281 if (params.columns == 2)
2282 options << "twocolumn,";
2284 options << "onecolumn,";
2287 if (!params.use_geometry
2288 && params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
2289 options << "landscape,";
2291 // language should be a parameter to \documentclass
2293 ostringstream language_options;
2294 if (params.language->babel() == "hebrew"
2295 && default_language->babel() != "hebrew")
2296 // This seems necessary
2297 features.useLanguage(default_language);
2299 if (lyxrc.language_use_babel ||
2300 params.language->lang() != lyxrc.default_language ||
2301 features.hasLanguages()) {
2303 language_options << features.getLanguages();
2304 language_options << params.language->babel();
2305 if (lyxrc.language_global_options)
2306 options << language_options.str() << ',';
2309 // the user-defined options
2310 if (!params.options.empty()) {
2311 options << params.options << ',';
2314 string strOptions(options.str().c_str());
2315 if (!strOptions.empty()) {
2316 strOptions = strip(strOptions, ',');
2317 ofs << '[' << strOptions << ']';
2320 ofs << '{' << tclass.latexname() << "}\n";
2322 // end of \documentclass defs
2324 // font selection must be done before loading fontenc.sty
2325 // The ae package is not needed when using OT1 font encoding.
2326 if (params.fonts != "default" &&
2327 (params.fonts != "ae" || lyxrc.fontenc != "default")) {
2328 ofs << "\\usepackage{" << params.fonts << "}\n";
2330 if (params.fonts == "ae") {
2331 ofs << "\\usepackage{aecompl}\n";
2335 // this one is not per buffer
2336 if (lyxrc.fontenc != "default") {
2337 ofs << "\\usepackage[" << lyxrc.fontenc
2342 if (params.inputenc == "auto") {
2343 string const doc_encoding =
2344 params.language->encoding()->LatexName();
2346 // Create a list with all the input encodings used
2348 set<string> encodings = features.getEncodingSet(doc_encoding);
2350 ofs << "\\usepackage[";
2351 std::copy(encodings.begin(), encodings.end(),
2352 std::ostream_iterator<string>(ofs, ","));
2353 ofs << doc_encoding << "]{inputenc}\n";
2355 } else if (params.inputenc != "default") {
2356 ofs << "\\usepackage[" << params.inputenc
2361 // At the very beginning the text parameters.
2362 if (params.paperpackage != BufferParams::PACKAGE_NONE) {
2363 switch (params.paperpackage) {
2364 case BufferParams::PACKAGE_A4:
2365 ofs << "\\usepackage{a4}\n";
2368 case BufferParams::PACKAGE_A4WIDE:
2369 ofs << "\\usepackage{a4wide}\n";
2372 case BufferParams::PACKAGE_WIDEMARGINSA4:
2373 ofs << "\\usepackage[widemargins]{a4}\n";
2378 if (params.use_geometry) {
2379 ofs << "\\usepackage{geometry}\n";
2381 ofs << "\\geometry{verbose";
2382 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
2383 ofs << ",landscape";
2384 switch (params.papersize2) {
2385 case BufferParams::VM_PAPER_CUSTOM:
2386 if (!params.paperwidth.empty())
2387 ofs << ",paperwidth="
2388 << params.paperwidth;
2389 if (!params.paperheight.empty())
2390 ofs << ",paperheight="
2391 << params.paperheight;
2393 case BufferParams::VM_PAPER_USLETTER:
2394 ofs << ",letterpaper";
2396 case BufferParams::VM_PAPER_USLEGAL:
2397 ofs << ",legalpaper";
2399 case BufferParams::VM_PAPER_USEXECUTIVE:
2400 ofs << ",executivepaper";
2402 case BufferParams::VM_PAPER_A3:
2405 case BufferParams::VM_PAPER_A4:
2408 case BufferParams::VM_PAPER_A5:
2411 case BufferParams::VM_PAPER_B3:
2414 case BufferParams::VM_PAPER_B4:
2417 case BufferParams::VM_PAPER_B5:
2421 // default papersize ie BufferParams::VM_PAPER_DEFAULT
2422 switch (lyxrc.default_papersize) {
2423 case BufferParams::PAPER_DEFAULT: // keep compiler happy
2424 case BufferParams::PAPER_USLETTER:
2425 ofs << ",letterpaper";
2427 case BufferParams::PAPER_LEGALPAPER:
2428 ofs << ",legalpaper";
2430 case BufferParams::PAPER_EXECUTIVEPAPER:
2431 ofs << ",executivepaper";
2433 case BufferParams::PAPER_A3PAPER:
2436 case BufferParams::PAPER_A4PAPER:
2439 case BufferParams::PAPER_A5PAPER:
2442 case BufferParams::PAPER_B5PAPER:
2447 if (!params.topmargin.empty())
2448 ofs << ",tmargin=" << params.topmargin;
2449 if (!params.bottommargin.empty())
2450 ofs << ",bmargin=" << params.bottommargin;
2451 if (!params.leftmargin.empty())
2452 ofs << ",lmargin=" << params.leftmargin;
2453 if (!params.rightmargin.empty())
2454 ofs << ",rmargin=" << params.rightmargin;
2455 if (!params.headheight.empty())
2456 ofs << ",headheight=" << params.headheight;
2457 if (!params.headsep.empty())
2458 ofs << ",headsep=" << params.headsep;
2459 if (!params.footskip.empty())
2460 ofs << ",footskip=" << params.footskip;
2465 if (tokenPos(tclass.opt_pagestyle(),
2466 '|', params.pagestyle) >= 0) {
2467 if (params.pagestyle == "fancy") {
2468 ofs << "\\usepackage{fancyhdr}\n";
2471 ofs << "\\pagestyle{" << params.pagestyle << "}\n";
2475 if (params.secnumdepth != tclass.secnumdepth()) {
2476 ofs << "\\setcounter{secnumdepth}{"
2477 << params.secnumdepth
2481 if (params.tocdepth != tclass.tocdepth()) {
2482 ofs << "\\setcounter{tocdepth}{"
2488 if (params.paragraph_separation) {
2489 switch (params.defskip.kind()) {
2490 case VSpace::SMALLSKIP:
2491 ofs << "\\setlength\\parskip{\\smallskipamount}\n";
2493 case VSpace::MEDSKIP:
2494 ofs << "\\setlength\\parskip{\\medskipamount}\n";
2496 case VSpace::BIGSKIP:
2497 ofs << "\\setlength\\parskip{\\bigskipamount}\n";
2499 case VSpace::LENGTH:
2500 ofs << "\\setlength\\parskip{"
2501 << params.defskip.length().asLatexString()
2504 default: // should never happen // Then delete it.
2505 ofs << "\\setlength\\parskip{\\medskipamount}\n";
2510 ofs << "\\setlength\\parindent{0pt}\n";
2514 // Now insert the LyX specific LaTeX commands...
2516 // The optional packages;
2517 string preamble(features.getPackages());
2519 // this might be useful...
2520 preamble += "\n\\makeatletter\n";
2522 // Some macros LyX will need
2523 string tmppreamble(features.getMacros());
2525 if (!tmppreamble.empty()) {
2526 preamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2527 "LyX specific LaTeX commands.\n"
2528 + tmppreamble + '\n';
2531 // the text class specific preamble
2532 tmppreamble = features.getTClassPreamble();
2533 if (!tmppreamble.empty()) {
2534 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2535 "Textclass specific LaTeX commands.\n"
2536 + tmppreamble + '\n';
2539 /* the user-defined preamble */
2540 if (!params.preamble.empty()) {
2541 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2542 "User specified LaTeX commands.\n"
2543 + params.preamble + '\n';
2546 // Itemize bullet settings need to be last in case the user
2547 // defines their own bullets that use a package included
2548 // in the user-defined preamble -- ARRae
2549 // Actually it has to be done much later than that
2550 // since some packages like frenchb make modifications
2551 // at \begin{document} time -- JMarc
2553 for (int i = 0; i < 4; ++i) {
2554 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
2555 if (bullets_def.empty())
2556 bullets_def="\\AtBeginDocument{\n";
2557 bullets_def += " \\renewcommand{\\labelitemi";
2559 // `i' is one less than the item to modify
2566 bullets_def += "ii";
2572 bullets_def += "}{" +
2573 params.user_defined_bullets[i].getText()
2578 if (!bullets_def.empty())
2579 preamble += bullets_def + "}\n\n";
2582 int(lyx::count(preamble.begin(), preamble.end(), '\n'));
2583 for (int j = 0; j != nlines; ++j) {
2587 // We try to load babel late, in case it interferes
2588 // with other packages.
2590 string tmp = lyxrc.language_package;
2591 if (!lyxrc.language_global_options
2592 && tmp == "\\usepackage{babel}")
2593 tmp = string("\\usepackage[") +
2594 language_options.str().c_str() +
2596 preamble += tmp + "\n";
2597 preamble += features.getBabelOptions();
2600 preamble += "\\makeatother\n";
2605 ofs << "\\begin{document}\n";
2608 lyxerr[Debug::INFO] << "preamble finished, now the body." << endl;
2610 if (!lyxrc.language_auto_begin) {
2611 ofs << subst(lyxrc.language_command_begin, "$$lang",
2612 params.language->babel())
2617 latexParagraphs(ofs, paragraph, 0, texrow);
2619 // add this just in case after all the paragraphs
2623 if (!lyxrc.language_auto_end) {
2624 ofs << subst(lyxrc.language_command_end, "$$lang",
2625 params.language->babel())
2631 ofs << "\\end{document}\n";
2634 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
2636 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
2640 // Just to be sure. (Asger)
2643 // tex_code_break_column's value is used to decide
2644 // if we are in batchmode or not (within mathed_write()
2645 // in math_write.C) so we must set it to a non-zero
2646 // value when we leave otherwise we save incorrect .lyx files.
2647 tex_code_break_column = lyxrc.ascii_linelen;
2651 lyxerr << "File was not closed properly." << endl;
2654 lyxerr[Debug::INFO] << "Finished making latex file." << endl;
2655 lyxerr[Debug::INFO] << "Row count was " << texrow.rows()-1 << "." << endl;
2657 // we want this to be true outside previews (for insetexternal)
2663 // LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
2665 void Buffer::latexParagraphs(ostream & ofs, Paragraph * par,
2666 Paragraph * endpar, TexRow & texrow,
2667 bool moving_arg) const
2669 bool was_title = false;
2670 bool already_title = false;
2673 while (par != endpar) {
2674 Inset * in = par->inInset();
2675 // well we have to check if we are in an inset with unlimited
2676 // lenght (all in one row) if that is true then we don't allow
2677 // any special options in the paragraph and also we don't allow
2678 // any environment other then "Standard" to be valid!
2679 if ((in == 0) || !in->forceDefaultParagraphs(in)) {
2680 LyXLayout const & layout =
2681 textclasslist[params.textclass][par->layout()];
2683 if (layout.intitle) {
2684 if (already_title) {
2685 lyxerr <<"Error in latexParagraphs: You"
2686 " should not mix title layouts"
2687 " with normal ones." << endl;
2690 } else if (was_title && !already_title) {
2691 ofs << "\\maketitle\n";
2693 already_title = true;
2697 if (layout.isEnvironment() ||
2698 !par->params().leftIndent().zero())
2700 par = par->TeXEnvironment(this, params, ofs, texrow);
2702 par = par->TeXOnePar(this, params, ofs, texrow, moving_arg);
2705 par = par->TeXOnePar(this, params, ofs, texrow, moving_arg);
2708 // It might be that we only have a title in this document
2709 if (was_title && !already_title) {
2710 ofs << "\\maketitle\n";
2716 bool Buffer::isLatex() const
2718 return textclasslist[params.textclass].outputType() == LATEX;
2722 bool Buffer::isLinuxDoc() const
2724 return textclasslist[params.textclass].outputType() == LINUXDOC;
2728 bool Buffer::isLiterate() const
2730 return textclasslist[params.textclass].outputType() == LITERATE;
2734 bool Buffer::isDocBook() const
2736 return textclasslist[params.textclass].outputType() == DOCBOOK;
2740 bool Buffer::isSGML() const
2742 LyXTextClass const & tclass = textclasslist[params.textclass];
2744 return tclass.outputType() == LINUXDOC ||
2745 tclass.outputType() == DOCBOOK;
2749 void Buffer::sgmlOpenTag(ostream & os, Paragraph::depth_type,
2750 string const & latexname) const
2752 if (!latexname.empty() && latexname != "!-- --")
2753 //os << "<!-- " << depth << " -->" << "<" << latexname << ">";
2754 os << "<" << latexname << ">";
2758 void Buffer::sgmlCloseTag(ostream & os, Paragraph::depth_type,
2759 string const & latexname) const
2761 if (!latexname.empty() && latexname != "!-- --")
2762 //os << "<!-- " << depth << " -->" << "</" << latexname << ">\n";
2763 os << "</" << latexname << ">";
2767 void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
2769 ofstream ofs(fname.c_str());
2772 Alert::alert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2776 niceFile = nice; // this will be used by included files.
2778 LaTeXFeatures features(params);
2784 LyXTextClass const & tclass = textclasslist[params.textclass];
2786 string top_element = tclass.latexname();
2789 ofs << "<!doctype linuxdoc system";
2791 string preamble = params.preamble;
2792 const string name = nice ? ChangeExtension(filename_, ".sgml")
2794 preamble += features.getIncludedFiles(name);
2795 preamble += features.getLyXSGMLEntities();
2797 if (!preamble.empty()) {
2798 ofs << " [ " << preamble << " ]";
2802 if (params.options.empty())
2803 sgmlOpenTag(ofs, 0, top_element);
2805 string top = top_element;
2807 top += params.options;
2808 sgmlOpenTag(ofs, 0, top);
2812 ofs << "<!-- " << lyx_docversion
2813 << " created this file. For more info see http://www.lyx.org/"
2816 Paragraph::depth_type depth = 0; // paragraph depth
2817 Paragraph * par = paragraph;
2819 vector<string> environment_stack(5);
2822 LyXLayout const & style = tclass[par->layout()];
2824 // treat <toc> as a special case for compatibility with old code
2825 if (par->isInset(0)) {
2826 Inset * inset = par->getInset(0);
2827 Inset::Code lyx_code = inset->lyxCode();
2828 if (lyx_code == Inset::TOC_CODE) {
2829 string const temp = "toc";
2830 sgmlOpenTag(ofs, depth, temp);
2837 // environment tag closing
2838 for (; depth > par->params().depth(); --depth) {
2839 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2840 environment_stack[depth].erase();
2843 // write opening SGML tags
2844 switch (style.latextype) {
2845 case LATEX_PARAGRAPH:
2846 if (depth == par->params().depth()
2847 && !environment_stack[depth].empty()) {
2848 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2849 environment_stack[depth].erase();
2855 sgmlOpenTag(ofs, depth, style.latexname());
2861 _("Error : Wrong depth for"
2862 " LatexType Command.\n"));
2864 if (!environment_stack[depth].empty()) {
2865 sgmlCloseTag(ofs, depth,
2866 environment_stack[depth]);
2870 environment_stack[depth].erase();
2871 sgmlOpenTag(ofs, depth, style.latexname());
2874 case LATEX_ENVIRONMENT:
2875 case LATEX_ITEM_ENVIRONMENT:
2876 if (depth == par->params().depth()
2877 && environment_stack[depth] != style.latexname()) {
2878 sgmlCloseTag(ofs, depth,
2879 environment_stack[depth]);
2880 environment_stack[depth].erase();
2882 if (depth < par->params().depth()) {
2883 depth = par->params().depth();
2884 environment_stack[depth].erase();
2886 if (environment_stack[depth] != style.latexname()) {
2888 sgmlOpenTag(ofs, depth, "p");
2890 sgmlOpenTag(ofs, depth, style.latexname());
2892 if (environment_stack.size() == depth + 1)
2893 environment_stack.push_back("!-- --");
2894 environment_stack[depth] = style.latexname();
2897 if (style.latexparam() == "CDATA")
2900 if (style.latextype == LATEX_ENVIRONMENT) break;
2902 if (style.labeltype == LABEL_MANUAL)
2907 sgmlOpenTag(ofs, depth + 1, item_name);
2910 sgmlOpenTag(ofs, depth, style.latexname());
2914 simpleLinuxDocOnePar(ofs, par, depth);
2919 // write closing SGML tags
2920 switch (style.latextype) {
2923 case LATEX_ENVIRONMENT:
2924 case LATEX_ITEM_ENVIRONMENT:
2925 if (style.latexparam() == "CDATA")
2929 sgmlCloseTag(ofs, depth, style.latexname());
2935 for (int i=depth; i >= 0; --i)
2936 sgmlCloseTag(ofs, depth, environment_stack[i]);
2940 sgmlCloseTag(ofs, 0, top_element);
2944 // How to check for successful close
2946 // we want this to be true outside previews (for insetexternal)
2951 // checks, if newcol chars should be put into this line
2952 // writes newline, if necessary.
2955 void sgmlLineBreak(ostream & os, string::size_type & colcount,
2956 string::size_type newcol)
2959 if (colcount > lyxrc.ascii_linelen) {
2961 colcount = newcol; // assume write after this call
2976 string tag_name(PAR_TAG const & pt) {
2978 case NONE: return "!-- --";
2979 case TT: return "tt";
2980 case SF: return "sf";
2981 case BF: return "bf";
2982 case IT: return "it";
2983 case SL: return "sl";
2984 case EM: return "em";
2991 void operator|=(PAR_TAG & p1, PAR_TAG const & p2)
2993 p1 = static_cast<PAR_TAG>(p1 | p2);
2998 void reset(PAR_TAG & p1, PAR_TAG const & p2)
3000 p1 = static_cast<PAR_TAG>(p1 & ~p2);
3006 // Handle internal paragraph parsing -- layout already processed.
3007 void Buffer::simpleLinuxDocOnePar(ostream & os,
3009 Paragraph::depth_type /*depth*/)
3011 LyXLayout const & style =
3012 textclasslist[params.textclass][par->layout()];
3013 string::size_type char_line_count = 5; // Heuristic choice ;-)
3015 // gets paragraph main font
3018 if (style.labeltype == LABEL_MANUAL) {
3019 font_old = style.labelfont;
3022 font_old = style.font;
3026 LyXFont::FONT_FAMILY family_type = LyXFont::ROMAN_FAMILY;
3027 LyXFont::FONT_SERIES series_type = LyXFont::MEDIUM_SERIES;
3028 LyXFont::FONT_SHAPE shape_type = LyXFont::UP_SHAPE;
3031 stack<PAR_TAG> tag_state;
3032 // parsing main loop
3033 for (pos_type i = 0; i < par->size(); ++i) {
3035 PAR_TAG tag_close = NONE;
3036 list < PAR_TAG > tag_open;
3038 LyXFont const font = par->getFont(params, i);
3040 if (font_old.family() != font.family()) {
3041 switch (family_type) {
3042 case LyXFont::SANS_FAMILY:
3045 case LyXFont::TYPEWRITER_FAMILY:
3052 family_type = font.family();
3054 switch (family_type) {
3055 case LyXFont::SANS_FAMILY:
3056 tag_open.push_back(SF);
3058 case LyXFont::TYPEWRITER_FAMILY:
3059 tag_open.push_back(TT);
3066 if (font_old.series() != font.series()) {
3067 switch (series_type) {
3068 case LyXFont::BOLD_SERIES:
3075 series_type = font.series();
3077 switch (series_type) {
3078 case LyXFont::BOLD_SERIES:
3079 tag_open.push_back(BF);
3087 if (font_old.shape() != font.shape()) {
3088 switch (shape_type) {
3089 case LyXFont::ITALIC_SHAPE:
3092 case LyXFont::SLANTED_SHAPE:
3099 shape_type = font.shape();
3101 switch (shape_type) {
3102 case LyXFont::ITALIC_SHAPE:
3103 tag_open.push_back(IT);
3105 case LyXFont::SLANTED_SHAPE:
3106 tag_open.push_back(SL);
3113 if (font_old.emph() != font.emph()) {
3114 if (font.emph() == LyXFont::ON) {
3115 tag_open.push_back(EM);
3124 list < PAR_TAG > temp;
3125 while (!tag_state.empty() && tag_close) {
3126 PAR_TAG k = tag_state.top();
3128 os << "</" << tag_name(k) << ">";
3135 for(list< PAR_TAG >::const_iterator j = temp.begin();
3136 j != temp.end(); ++j) {
3138 os << "<" << tag_name(*j) << ">";
3141 for(list< PAR_TAG >::const_iterator j = tag_open.begin();
3142 j != tag_open.end(); ++j) {
3144 os << "<" << tag_name(*j) << ">";
3147 char c = par->getChar(i);
3149 if (c == Paragraph::META_INSET) {
3150 Inset * inset = par->getInset(i);
3151 inset->linuxdoc(this, os);
3156 if (style.latexparam() == "CDATA") {
3157 // "TeX"-Mode on == > SGML-Mode on.
3163 if (par->sgmlConvertChar(c, sgml_string)
3164 && !style.free_spacing && !par->isFreeSpacing())
3166 // in freespacing mode, spaces are
3167 // non-breaking characters
3168 if (desc_on) {// if char is ' ' then...
3171 sgmlLineBreak(os, char_line_count, 6);
3175 sgmlLineBreak(os, char_line_count, 1);
3180 char_line_count += sgml_string.length();
3186 while (!tag_state.empty()) {
3187 os << "</" << tag_name(tag_state.top()) << ">";
3191 // resets description flag correctly
3193 // <tag> not closed...
3194 sgmlLineBreak(os, char_line_count, 6);
3200 // Print an error message.
3201 void Buffer::sgmlError(Paragraph * /*par*/, int /*pos*/,
3202 string const & /*message*/) const
3204 #ifdef WITH_WARNINGS
3205 #warning This is wrong we cannot insert an inset like this!!!
3206 // I guess this was Jose' so I explain you more or less why this
3207 // is wrong. This way you insert something in the paragraph and
3208 // don't tell it to LyXText (row rebreaking and undo handling!!!)
3209 // I deactivate this code, have a look at BufferView::insertErrors
3210 // how you should do this correctly! (Jug 20020315)
3213 // insert an error marker in text
3214 InsetError * new_inset = new InsetError(message);
3215 par->insertInset(pos, new_inset, LyXFont(LyXFont::ALL_INHERIT,
3221 void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
3223 ofstream ofs(fname.c_str());
3225 Alert::alert(_("LYX_ERROR:"), _("Cannot write file"), fname);
3229 Paragraph * par = paragraph;
3231 niceFile = nice; // this will be used by Insetincludes.
3233 LaTeXFeatures features(params);
3238 LyXTextClass const & tclass = textclasslist[params.textclass];
3239 string top_element = tclass.latexname();
3242 ofs << "<!DOCTYPE " << top_element
3243 << " PUBLIC \"-//OASIS//DTD DocBook V4.1//EN\"";
3245 string preamble = params.preamble;
3246 const string name = nice ? ChangeExtension(filename_, ".sgml")
3248 preamble += features.getIncludedFiles(name);
3249 preamble += features.getLyXSGMLEntities();
3251 if (!preamble.empty()) {
3252 ofs << "\n [ " << preamble << " ]";
3257 string top = top_element;
3259 top += params.language->code();
3262 if (!params.options.empty()) {
3264 top += params.options;
3266 sgmlOpenTag(ofs, 0, top);
3268 ofs << "<!-- DocBook file was created by " << lyx_docversion
3269 << "\n See http://www.lyx.org/ for more information -->\n";
3271 vector<string> environment_stack(10);
3272 vector<string> environment_inner(10);
3273 vector<string> command_stack(10);
3275 bool command_flag = false;
3276 Paragraph::depth_type command_depth = 0;
3277 Paragraph::depth_type command_base = 0;
3278 Paragraph::depth_type cmd_depth = 0;
3279 Paragraph::depth_type depth = 0; // paragraph depth
3282 string command_name;
3288 int desc_on = 0; // description mode
3290 LyXLayout const & style = tclass[par->layout()];
3292 // environment tag closing
3293 for (; depth > par->params().depth(); --depth) {
3294 if (environment_inner[depth] != "!-- --") {
3295 item_name = "listitem";
3296 sgmlCloseTag(ofs, command_depth + depth,
3298 if (environment_inner[depth] == "varlistentry")
3299 sgmlCloseTag(ofs, depth+command_depth,
3300 environment_inner[depth]);
3302 sgmlCloseTag(ofs, depth + command_depth,
3303 environment_stack[depth]);
3304 environment_stack[depth].erase();
3305 environment_inner[depth].erase();
3308 if (depth == par->params().depth()
3309 && environment_stack[depth] != style.latexname()
3310 && !environment_stack[depth].empty()) {
3311 if (environment_inner[depth] != "!-- --") {
3312 item_name= "listitem";
3313 sgmlCloseTag(ofs, command_depth+depth,
3315 if (environment_inner[depth] == "varlistentry")
3317 depth + command_depth,
3318 environment_inner[depth]);
3321 sgmlCloseTag(ofs, depth + command_depth,
3322 environment_stack[depth]);
3324 environment_stack[depth].erase();
3325 environment_inner[depth].erase();
3328 // Write opening SGML tags.
3329 switch (style.latextype) {
3330 case LATEX_PARAGRAPH:
3331 sgmlOpenTag(ofs, depth + command_depth,
3338 _("Error : Wrong depth for "
3339 "LatexType Command.\n"));
3341 command_name = style.latexname();
3343 sgmlparam = style.latexparam();
3344 c_params = split(sgmlparam, c_depth,'|');
3346 cmd_depth = lyx::atoi(c_depth);
3349 if (cmd_depth < command_base) {
3350 for (Paragraph::depth_type j = command_depth;
3351 j >= command_base; --j) {
3352 sgmlCloseTag(ofs, j, command_stack[j]);
3355 command_depth = command_base = cmd_depth;
3356 } else if (cmd_depth <= command_depth) {
3357 for (int j = command_depth;
3358 j >= int(cmd_depth); --j) {
3359 sgmlCloseTag(ofs, j, command_stack[j]);
3362 command_depth = cmd_depth;
3364 command_depth = cmd_depth;
3366 command_depth = command_base = cmd_depth;
3367 command_flag = true;
3369 if (command_stack.size() == command_depth + 1)
3370 command_stack.push_back(string());
3371 command_stack[command_depth] = command_name;
3373 // treat label as a special case for
3374 // more WYSIWYM handling.
3375 // This is a hack while paragraphs can't have
3376 // attributes, like id in this case.
3377 if (par->isInset(0)) {
3378 Inset * inset = par->getInset(0);
3379 Inset::Code lyx_code = inset->lyxCode();
3380 if (lyx_code == Inset::LABEL_CODE) {
3381 command_name += " id=\"";
3382 command_name += (static_cast<InsetCommand *>(inset))->getContents();
3383 command_name += "\"";
3388 sgmlOpenTag(ofs, depth + command_depth, command_name);
3389 if (c_params.empty())
3390 item_name = "title";
3392 item_name = c_params;
3393 sgmlOpenTag(ofs, depth + 1 + command_depth, item_name);
3396 case LATEX_ENVIRONMENT:
3397 case LATEX_ITEM_ENVIRONMENT:
3398 if (depth < par->params().depth()) {
3399 depth = par->params().depth();
3400 environment_stack[depth].erase();
3403 if (environment_stack[depth] != style.latexname()) {
3404 if (environment_stack.size() == depth + 1) {
3405 environment_stack.push_back("!-- --");
3406 environment_inner.push_back("!-- --");
3408 environment_stack[depth] = style.latexname();
3409 environment_inner[depth] = "!-- --";
3410 sgmlOpenTag(ofs, depth + command_depth,
3411 environment_stack[depth]);
3413 if (environment_inner[depth] != "!-- --") {
3414 item_name= "listitem";
3416 command_depth + depth,
3418 if (environment_inner[depth] == "varlistentry")
3420 depth + command_depth,
3421 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,
3431 style.latexparam());
3436 desc_on = (style.labeltype == LABEL_MANUAL);
3439 environment_inner[depth]= "varlistentry";
3441 environment_inner[depth]= "listitem";
3443 sgmlOpenTag(ofs, depth + 1 + command_depth,
3444 environment_inner[depth]);
3448 sgmlOpenTag(ofs, depth + 1 + command_depth,
3452 sgmlOpenTag(ofs, depth + 1 + command_depth,
3457 sgmlOpenTag(ofs, depth + command_depth,
3462 simpleDocBookOnePar(ofs, par, desc_on, depth+1+command_depth);
3466 // write closing SGML tags
3467 switch (style.latextype) {
3469 if (c_params.empty())
3473 sgmlCloseTag(ofs, depth + command_depth, end_tag);
3475 case LATEX_ENVIRONMENT:
3476 if (!style.latexparam().empty()) {
3477 if (style.latexparam() == "CDATA")
3480 sgmlCloseTag(ofs, depth + command_depth,
3481 style.latexparam());
3484 case LATEX_ITEM_ENVIRONMENT:
3485 if (desc_on == 1) break;
3487 sgmlCloseTag(ofs, depth + 1 + command_depth, end_tag);
3489 case LATEX_PARAGRAPH:
3490 sgmlCloseTag(ofs, depth + command_depth, style.latexname());
3493 sgmlCloseTag(ofs, depth + command_depth, style.latexname());
3499 for (int d = depth; d >= 0; --d) {
3500 if (!environment_stack[depth].empty()) {
3501 if (environment_inner[depth] != "!-- --") {
3502 item_name = "listitem";
3503 sgmlCloseTag(ofs, command_depth + depth,
3505 if (environment_inner[depth] == "varlistentry")
3506 sgmlCloseTag(ofs, depth + command_depth,
3507 environment_inner[depth]);
3510 sgmlCloseTag(ofs, depth + command_depth,
3511 environment_stack[depth]);
3515 for (int j = command_depth; j >= 0 ; --j)
3516 if (!command_stack[j].empty()) {
3517 sgmlCloseTag(ofs, j, command_stack[j]);
3522 sgmlCloseTag(ofs, 0, top_element);
3525 // How to check for successful close
3527 // we want this to be true outside previews (for insetexternal)
3532 void Buffer::simpleDocBookOnePar(ostream & os,
3533 Paragraph * par, int & desc_on,
3534 Paragraph::depth_type depth) const
3536 bool emph_flag = false;
3538 LyXLayout const & style =
3539 textclasslist[params.textclass][par->layout()];
3541 LyXFont font_old = style.labeltype == LABEL_MANUAL ? style.labelfont : style.font;
3543 int char_line_count = depth;
3544 //if (!style.free_spacing)
3545 // os << string(depth,' ');
3547 // parsing main loop
3548 for (pos_type i = 0; i < par->size(); ++i) {
3549 LyXFont font = par->getFont(params, i);
3551 // handle <emphasis> tag
3552 if (font_old.emph() != font.emph()) {
3553 if (font.emph() == LyXFont::ON) {
3554 if(style.latexparam() == "CDATA")
3557 if(style.latexparam() == "CDATA")
3561 if(style.latexparam() == "CDATA")
3563 os << "</emphasis>";
3564 if(style.latexparam() == "CDATA")
3571 if (par->isInset(i)) {
3572 Inset * inset = par->getInset(i);
3573 // don't print the inset in position 0 if desc_on == 3 (label)
3574 if ( i || desc_on != 3) {
3575 if(style.latexparam() == "CDATA")
3577 inset->docbook(this, os);
3578 if(style.latexparam() == "CDATA")
3582 char c = par->getChar(i);
3584 par->sgmlConvertChar(c, sgml_string);
3586 if (style.pass_thru) {
3588 } else if (style.free_spacing || par->isFreeSpacing() || c != ' ') {
3590 } else if (desc_on ==1) {
3592 os << "\n</term><listitem><para>";
3602 if(style.latexparam() == "CDATA")
3604 os << "</emphasis>";
3605 if(style.latexparam() == "CDATA")
3609 // resets description flag correctly
3611 // <term> not closed...
3612 os << "</term>\n<listitem><para> </para>";
3614 if (style.free_spacing) os << '\n';
3618 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
3619 // Other flags: -wall -v0 -x
3620 int Buffer::runChktex()
3622 if (!users->text) return 0;
3624 users->owner()->prohibitInput();
3626 // get LaTeX-Filename
3627 string const name = getLatexName();
3628 string path = filePath();
3630 string const org_path = path;
3631 if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
3635 Path p(path); // path to LaTeX file
3636 users->owner()->message(_("Running chktex..."));
3638 // Remove all error insets
3639 bool const removedErrorInsets = users->removeAutoInsets();
3641 // Generate the LaTeX file if neccessary
3642 makeLaTeXFile(name, org_path, false);
3645 Chktex chktex(lyxrc.chktex_command, name, filePath());
3646 int res = chktex.run(terr); // run chktex
3649 Alert::alert(_("chktex did not work!"),
3650 _("Could not run with file:"), name);
3651 } else if (res > 0) {
3652 // Insert all errors as errors boxes
3653 users->insertErrors(terr);
3656 // if we removed error insets before we ran chktex or if we inserted
3657 // error insets after we ran chktex, this must be run:
3658 if (removedErrorInsets || res) {
3662 users->owner()->allowInput();
3668 void Buffer::validate(LaTeXFeatures & features) const
3670 Paragraph * par = paragraph;
3671 LyXTextClass const & tclass = textclasslist[params.textclass];
3673 // AMS Style is at document level
3674 if (params.use_amsmath || tclass.provides(LyXTextClass::amsmath))
3675 features.require("amsmath");
3678 // We don't use "lyxerr.debug" because of speed. (Asger)
3679 if (lyxerr.debugging(Debug::LATEX))
3680 lyxerr << "Paragraph: " << par << endl;
3682 // Now just follow the list of paragraphs and run
3683 // validate on each of them.
3684 par->validate(features);
3686 // and then the next paragraph
3690 // the bullet shapes are buffer level not paragraph level
3691 // so they are tested here
3692 for (int i = 0; i < 4; ++i) {
3693 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
3694 int const font = params.user_defined_bullets[i].getFont();
3696 int const c = params
3697 .user_defined_bullets[i]
3704 features.require("latexsym");
3706 } else if (font == 1) {
3707 features.require("amssymb");
3708 } else if ((font >= 2 && font <= 5)) {
3709 features.require("pifont");
3714 if (lyxerr.debugging(Debug::LATEX)) {
3715 features.showStruct();
3720 // This function should be in Buffer because it's a buffer's property (ale)
3721 string const Buffer::getIncludeonlyList(char delim)
3724 for (inset_iterator it = inset_iterator_begin();
3725 it != inset_iterator_end(); ++it) {
3726 if ((*it)->lyxCode() == Inset::INCLUDE_CODE) {
3727 InsetInclude * insetinc =
3728 static_cast<InsetInclude *>(*it);
3729 if (insetinc->isIncludeOnly()) {
3732 lst += insetinc->getRelFileBaseName();
3736 lyxerr[Debug::INFO] << "Includeonly(" << lst << ')' << endl;
3741 vector<string> const Buffer::getLabelList()
3743 /// if this is a child document and the parent is already loaded
3744 /// Use the parent's list instead [ale990407]
3745 if (!params.parentname.empty()
3746 && bufferlist.exists(params.parentname)) {
3747 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3749 return tmp->getLabelList();
3752 vector<string> label_list;
3753 for (inset_iterator it = inset_iterator_begin();
3754 it != inset_iterator_end(); ++it) {
3755 vector<string> const l = (*it)->getLabelList();
3756 label_list.insert(label_list.end(), l.begin(), l.end());
3762 Buffer::Lists const Buffer::getLists() const
3765 Paragraph * par = paragraph;
3767 LyXTextClass const & textclass = textclasslist[params.textclass];
3768 bool found = textclass.hasLayout("Caption");
3769 string const layout("Caption");
3772 char const labeltype = textclass[par->layout()].labeltype;
3774 if (labeltype >= LABEL_COUNTER_CHAPTER
3775 && labeltype <= LABEL_COUNTER_CHAPTER + params.tocdepth) {
3776 // insert this into the table of contents
3777 SingleList & item = l["TOC"];
3780 textclass.maxcounter());
3781 item.push_back(TocItem(par, depth, par->asString(this, true)));
3783 // For each paragrph, traverse its insets and look for
3787 Paragraph::inset_iterator it =
3788 par->inset_iterator_begin();
3789 Paragraph::inset_iterator end =
3790 par->inset_iterator_end();
3792 for (; it != end; ++it) {
3793 if ((*it)->lyxCode() == Inset::FLOAT_CODE) {
3795 static_cast<InsetFloat*>(*it);
3797 string const type = il->type();
3799 // Now find the caption in the float...
3800 // We now tranverse the paragraphs of
3802 Paragraph * tmp = il->inset.paragraph();
3804 if (tmp->layout() == layout) {
3805 SingleList & item = l[type];
3807 tostr(item.size()+1) + ". " + tmp->asString(this, false);
3808 item.push_back(TocItem(tmp, 0 , str));
3815 lyxerr << "Caption not found" << endl;
3824 // This is also a buffer property (ale)
3825 vector<pair<string, string> > const Buffer::getBibkeyList() const
3827 typedef pair<string, string> StringPair;
3828 /// if this is a child document and the parent is already loaded
3829 /// Use the parent's list instead [ale990412]
3830 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3831 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
3833 return tmp->getBibkeyList();
3836 vector<StringPair> keys;
3837 Paragraph * par = paragraph;
3840 string const key = par->bibkey->getContents();
3841 string const opt = par->bibkey->getOptions();
3842 string const ref = par->asString(this, false);
3843 string const info = opt + "TheBibliographyRef" + ref;
3845 keys.push_back(StringPair(key, info));
3850 // Might be either using bibtex or a child has bibliography
3852 for (inset_iterator it = inset_const_iterator_begin();
3853 it != inset_const_iterator_end(); ++it) {
3854 // Search for Bibtex or Include inset
3855 if ((*it)->lyxCode() == Inset::BIBTEX_CODE) {
3856 vector<StringPair> tmp =
3857 static_cast<InsetBibtex*>(*it)->getKeys(this);
3858 keys.insert(keys.end(), tmp.begin(), tmp.end());
3859 } else if ((*it)->lyxCode() == Inset::INCLUDE_CODE) {
3860 vector<StringPair> const tmp =
3861 static_cast<InsetInclude*>(*it)->getKeys();
3862 keys.insert(keys.end(), tmp.begin(), tmp.end());
3871 bool Buffer::isDepClean(string const & name) const
3873 DEPCLEAN * item = dep_clean;
3874 while (item && item->master != name)
3876 if (!item) return true;
3881 void Buffer::markDepClean(string const & name)
3884 dep_clean = new DEPCLEAN;
3885 dep_clean->clean = true;
3886 dep_clean->master = name;
3887 dep_clean->next = 0;
3889 DEPCLEAN * item = dep_clean;
3890 while (item && item->master != name)
3895 item = new DEPCLEAN;
3897 item->master = name;
3904 bool Buffer::dispatch(string const & command, bool * result)
3906 // Split command string into command and argument
3908 string line = frontStrip(command);
3909 string const arg = strip(frontStrip(split(line, cmd, ' ')));
3911 return dispatch(lyxaction.LookupFunc(cmd), arg, result);
3915 bool Buffer::dispatch(int action, string const & argument, bool * result)
3917 bool dispatched = true;
3921 bool const tmp = Exporter::Export(this, argument, false);
3934 void Buffer::resizeInsets(BufferView * bv)
3936 /// then remove all LyXText in text-insets
3937 Paragraph * par = paragraph;
3938 for (; par; par = par->next()) {
3939 par->resizeInsetsLyXText(bv);
3944 void Buffer::redraw()
3951 void Buffer::changeLanguage(Language const * from, Language const * to)
3954 ParIterator end = par_iterator_end();
3955 for (ParIterator it = par_iterator_begin(); it != end; ++it)
3956 (*it)->changeLanguage(params, from, to);
3960 bool Buffer::isMultiLingual()
3962 ParIterator end = par_iterator_end();
3963 for (ParIterator it = par_iterator_begin(); it != end; ++it)
3964 if ((*it)->isMultiLingual(params))
3971 Buffer::inset_iterator::inset_iterator(Paragraph * paragraph, pos_type pos)
3974 it = par->InsetIterator(pos);
3975 if (it == par->inset_iterator_end()) {
3982 void Buffer::inset_iterator::setParagraph()
3985 it = par->inset_iterator_begin();
3986 if (it != par->inset_iterator_end())
3991 // We maintain an invariant that whenever par = 0 then it = 0
3995 Inset * Buffer::getInsetFromID(int id_arg) const
3997 for (inset_iterator it = inset_const_iterator_begin();
3998 it != inset_const_iterator_end(); ++it)
4000 if ((*it)->id() == id_arg)
4002 Inset * in = (*it)->getInsetFromID(id_arg);
4010 Paragraph * Buffer::getParFromID(int id) const
4012 if (id < 0) return 0;
4013 Paragraph * par = paragraph;
4015 if (par->id() == id) {
4018 Paragraph * tmp = par->getParFromID(id);
4028 ParIterator Buffer::par_iterator_begin()
4030 return ParIterator(paragraph);
4034 ParIterator Buffer::par_iterator_end()
4036 return ParIterator();