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 * ======================================================
26 #include <sys/types.h>
35 #include <boost/tuple/tuple.hpp>
38 #pragma implementation
42 #include "bufferlist.h"
44 #include "lyx_gui_misc.h"
45 #include "LyXAction.h"
48 #include "tex-strings.h"
50 #include "bufferview_funcs.h"
53 #include "mathed/formulamacro.h"
54 #include "mathed/formula.h"
55 #include "insets/inset.h"
56 #include "insets/inseterror.h"
57 #include "insets/insetlabel.h"
58 #include "insets/insetref.h"
59 #include "insets/inseturl.h"
60 #include "insets/insetnote.h"
61 #include "insets/insetquotes.h"
62 #include "insets/insetlatexaccent.h"
63 #include "insets/insetbib.h"
64 #include "insets/insetcite.h"
65 #include "insets/insetexternal.h"
66 #include "insets/insetindex.h"
67 #include "insets/insetinclude.h"
68 #include "insets/insettoc.h"
69 #include "insets/insetparent.h"
70 #include "insets/insetspecialchar.h"
71 #include "insets/figinset.h"
72 #include "insets/insettext.h"
73 #include "insets/insetert.h"
74 #include "insets/insetgraphics.h"
75 #include "insets/insetfoot.h"
76 #include "insets/insetmarginal.h"
77 #include "insets/insetminipage.h"
78 #include "insets/insetfloat.h"
79 #include "insets/insettabular.h"
81 #include "insets/insettheorem.h"
82 #include "insets/insetlist.h"
84 #include "insets/insetcaption.h"
85 #include "insets/insetfloatlist.h"
86 #include "support/textutils.h"
87 #include "support/filetools.h"
88 #include "support/path.h"
89 #include "support/os.h"
94 #include "LaTeXFeatures.h"
95 #include "support/syscall.h"
96 #include "support/lyxlib.h"
97 #include "support/FileInfo.h"
98 #include "support/lyxmanip.h"
101 #include "language.h"
102 #include "lyx_gui_misc.h" // WarnReadonly()
103 #include "frontends/Dialogs.h"
104 #include "encoding.h"
105 #include "exporter.h"
106 #include "Lsstream.h"
107 #include "converter.h"
108 #include "BufferView.h"
109 #include "ParagraphParameters.h"
110 #include "iterators.h"
120 using std::make_pair;
128 // all these externs should eventually be removed.
129 extern BufferList bufferlist;
131 extern LyXAction lyxaction;
135 const int LYX_FORMAT = 220;
139 extern int tex_code_break_column;
142 Buffer::Buffer(string const & file, bool ronly)
144 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
146 filepath = OnlyPath(file);
155 if (read_only || (lyxrc.use_tempdir)) {
156 tmppath = CreateBufferTmpDir();
157 } else tmppath.erase();
163 lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
164 // here the buffer should take care that it is
165 // saved properly, before it goes into the void.
167 // make sure that views using this buffer
172 if (!tmppath.empty()) {
173 DestroyBufferTmpDir(tmppath);
176 Paragraph * par = paragraph;
179 tmppar = par->next();
187 string const Buffer::getLatexName(bool no_path) const
189 string name = ChangeExtension(MakeLatexName(filename), ".tex");
191 return OnlyFilename(name);
197 pair<Buffer::LogType, string> const Buffer::getLogName(void) const
199 string const filename = getLatexName(false);
201 if (filename.empty())
202 return make_pair(Buffer::latexlog, string());
204 string path = OnlyPath(filename);
206 if (lyxrc.use_tempdir || !IsDirWriteable(path))
209 string const fname = AddName(path,
210 OnlyFilename(ChangeExtension(filename,
213 AddName(path, OnlyFilename(
214 ChangeExtension(filename,
215 formats.extension("literate") + ".out")));
217 // If no Latex log or Build log is newer, show Build log
219 FileInfo const f_fi(fname);
220 FileInfo const b_fi(bname);
223 (!f_fi.exist() || f_fi.getModificationTime() < b_fi.getModificationTime())) {
224 lyxerr[Debug::FILES] << "Log name calculated as : " << bname << endl;
225 return make_pair(Buffer::buildlog, bname);
227 lyxerr[Debug::FILES] << "Log name calculated as : " << fname << endl;
228 return make_pair(Buffer::latexlog, fname);
232 void Buffer::setReadonly(bool flag)
234 if (read_only != flag) {
237 users->owner()->getDialogs()->updateBufferDependent(false);
240 WarnReadonly(filename);
245 bool Buffer::saveParamsAsDefaults() // const
247 string const fname = AddName(AddPath(user_lyxdir, "templates/"),
249 Buffer defaults = Buffer(fname);
251 // Use the current buffer's parameters as default
252 defaults.params = params;
254 // add an empty paragraph. Is this enough?
255 defaults.paragraph = new Paragraph;
257 return defaults.writeFile(defaults.filename, false);
261 /// Update window titles of all users
262 // Should work on a list
263 void Buffer::updateTitles() const
265 if (users) users->owner()->updateWindowTitle();
269 /// Reset autosave timer of all users
270 // Should work on a list
271 void Buffer::resetAutosaveTimers() const
273 if (users) users->owner()->resetAutosaveTimer();
277 void Buffer::setFileName(string const & newfile)
279 filename = MakeAbsPath(newfile);
280 filepath = OnlyPath(filename);
281 setReadonly(IsFileWriteable(filename) == 0);
286 // We'll remove this later. (Lgb)
289 string last_inset_read;
291 #ifndef NO_COMPABILITY
294 ErtComp() : active(false), in_tabular(false) {
301 std::stack<ErtComp> ert_stack;
305 #warning And _why_ is this here? (Lgb)
311 // candidate for move to BufferView
312 // (at least some parts in the beginning of the func)
315 // changed to be public and have one parameter
316 // if par = 0 normal behavior
317 // else insert behavior
318 // Returns false if "\the_end" is not read for formats >= 2.13. (Asger)
319 bool Buffer::readLyXformat2(LyXLex & lex, Paragraph * par)
322 #ifndef NO_COMPABILITY
323 ert_comp.contents.erase();
324 ert_comp.active = 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);
333 if (file_format < 216 && params.language->lang() == "hebrew")
334 font.setLanguage(default_language);
339 // We are inserting into an existing document
340 users->text->breakParagraph(users);
341 first_par = users->text->firstParagraph();
344 // We don't want to adopt the parameters from the
345 // document we insert, so we skip until the text begins:
348 string const pretoken = lex.getString();
349 if (pretoken == "\\layout") {
350 lex.pushToken(pretoken);
358 string const token = lex.getString();
360 if (token.empty()) continue;
362 lyxerr[Debug::PARSER] << "Handling token: `"
363 << token << "'" << endl;
366 parseSingleLyXformat2Token(lex, par, first_par,
374 paragraph = first_par;
376 if (unknown_layouts > 0) {
377 string s = _("Couldn't set the layout for ");
378 if (unknown_layouts == 1) {
379 s += _("one paragraph");
381 s += tostr(unknown_layouts);
382 s += _(" paragraphs");
384 WriteAlert(_("Textclass Loading Error!"), s,
385 _("When reading " + fileName()));
392 #ifndef NO_COMPABILITY
393 void Buffer::insertErtContents(Paragraph * par, int & pos,
394 LyXFont const & font, bool set_inactive)
396 if (!ert_comp.contents.empty()) {
397 lyxerr[Debug::INSETS] << "ERT contents:\n"
398 << ert_comp.contents << endl;
399 Inset * inset = new InsetERT(ert_comp.contents, true);
400 par->insertInset(pos++, inset, font);
401 ert_comp.contents.erase();
404 ert_comp.active = false;
411 Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
412 Paragraph *& first_par,
413 string const & token, int & pos,
414 Paragraph::depth_type & depth,
418 bool the_end_read = false;
419 #ifndef NO_COMPABILITY
420 #ifndef NO_PEXTRA_REALLY
421 // This is super temporary but is needed to get the compability
422 // mode for minipages work correctly together with new tabulars.
423 static int call_depth;
425 bool checkminipage = false;
426 static Paragraph * minipar;
427 static Paragraph * parBeforeMinipage;
430 if (token[0] != '\\') {
431 #ifndef NO_COMPABILITY
432 if (ert_comp.active) {
433 ert_comp.contents += token;
436 for (string::const_iterator cit = token.begin();
437 cit != token.end(); ++cit) {
438 par->insertChar(pos, (*cit), font);
441 #ifndef NO_COMPABILITY
444 } else if (token == "\\i") {
445 Inset * inset = new InsetLatexAccent;
446 inset->read(this, lex);
447 par->insertInset(pos, inset, font);
449 } else if (token == "\\layout") {
450 #ifndef NO_COMPABILITY
451 ert_comp.in_tabular = false;
453 insertErtContents(par, pos, font);
456 string const layoutname = lex.getString();
457 pair<bool, LyXTextClass::LayoutList::size_type> pp
458 = textclasslist.NumberOfLayout(params.textclass,
461 #ifndef NO_COMPABILITY
462 if (compare_no_case(layoutname, "latex") == 0) {
463 ert_comp.active = true;
467 // The is the compability reading of layout caption.
468 // It can be removed in LyX version 1.3.0. (Lgb)
469 if (compare_no_case(layoutname, "caption") == 0) {
470 // We expect that the par we are now working on is
471 // really inside a InsetText inside a InsetFloat.
472 // We also know that captions can only be
473 // one paragraph. (Lgb)
475 // We should now read until the next "\layout"
477 // This is probably not good enough, what if the
478 // caption is the last par in the document (Lgb)
479 istream & ist = lex.getStream();
485 if (prefixIs(line, "\\layout")) {
489 if (prefixIs(line, "\\begin_inset"))
491 if (prefixIs(line, "\\end_inset")) {
502 // Now we should have the whole layout in ss
503 // we should now be able to give this to the
505 ss << "\\end_inset\n";
507 // This seems like a bug in stringstream.
508 // We really should be able to use ss
510 istringstream is(ss.str());
512 tmplex.setStream(is);
513 Inset * inset = new InsetCaption;
514 inset->Read(this, tmplex);
515 par->InsertInset(pos, inset, font);
522 par = new Paragraph(par);
526 par->layout = pp.second;
527 #ifndef NO_COMPABILITY
528 } else if (ert_comp.active) {
533 // use default layout "Standard" (0)
536 string const s = _("Layout had to be changed from\n")
537 + layoutname + _(" to ")
538 + textclasslist.NameOfLayout(params.textclass, par->layout);
539 InsetError * new_inset = new InsetError(s);
540 par->insertInset(0, new_inset);
542 // Test whether the layout is obsolete.
543 LyXLayout const & layout =
544 textclasslist.Style(params.textclass,
546 if (!layout.obsoleted_by().empty())
547 par->layout = textclasslist
548 .NumberOfLayout(params.textclass,
549 layout.obsoleted_by())
551 par->params().depth(depth);
552 font = LyXFont(LyXFont::ALL_INHERIT, params.language);
553 if (file_format < 216
554 && params.language->lang() == "hebrew")
555 font.setLanguage(default_language);
560 #ifndef NO_COMPABILITY
561 } else if (token == "\\begin_float") {
562 insertErtContents(par, pos, font);
563 //insertErtContents(par, pos, font, false);
564 //ert_stack.push(ert_comp);
565 //ert_comp = ErtComp();
567 // This is the compability reader. It can be removed in
568 // LyX version 1.3.0. (Lgb)
570 string const tmptok = lex.getString();
571 //lyxerr << "old float: " << tmptok << endl;
574 stringstream old_float;
576 if (tmptok == "footnote") {
577 inset = new InsetFoot;
578 old_float << "collapsed true\n";
579 } else if (tmptok == "margin") {
580 inset = new InsetMarginal;
581 old_float << "collapsed true\n";
582 } else if (tmptok == "fig") {
583 inset = new InsetFloat("figure");
584 old_float << "placement htbp\n"
586 << "collapsed false\n";
587 } else if (tmptok == "tab") {
588 inset = new InsetFloat("table");
589 old_float << "placement htbp\n"
591 << "collapsed false\n";
592 } else if (tmptok == "alg") {
593 inset = new InsetFloat("algorithm");
594 old_float << "placement htbp\n"
596 << "collapsed false\n";
597 } else if (tmptok == "wide-fig") {
598 inset = new InsetFloat("figure");
599 //InsetFloat * tmp = new InsetFloat("figure");
602 old_float << "placement htbp\n"
604 << "collapsed false\n";
605 } else if (tmptok == "wide-tab") {
606 inset = new InsetFloat("table");
607 //InsetFloat * tmp = new InsetFloat("table");
610 old_float << "placement htbp\n"
612 << "collapsed false\n";
616 #ifndef NO_PEXTRA_REALLY
619 return false; // no end read yet
622 // Here we need to check for \end_deeper and handle that
623 // before we do the footnote parsing.
624 // This _is_ a hack! (Lgb)
627 string const tmp = lex.getString();
628 if (tmp == "\\end_deeper") {
629 //lyxerr << "\\end_deeper caught!" << endl;
631 lex.printError("\\end_deeper: "
632 "depth is already null");
637 old_float << tmp << ' ';
642 old_float << lex.getLongString("\\end_float")
643 << "\n\\end_inset\n";
644 //lyxerr << "Float Body:\n" << old_float.str() << endl;
645 // That this does not work seems like a bug
646 // in stringstream. (Lgb)
647 istringstream istr(old_float.str());
649 nylex.setStream(istr);
650 inset->read(this, nylex);
651 par->insertInset(pos, inset, font);
653 insertErtContents(par, pos, font);
655 } else if (token == "\\begin_deeper") {
657 } else if (token == "\\end_deeper") {
659 lex.printError("\\end_deeper: "
660 "depth is already null");
664 } else if (token == "\\begin_preamble") {
665 params.readPreamble(lex);
666 } else if (token == "\\textclass") {
668 pair<bool, LyXTextClassList::size_type> pp =
669 textclasslist.NumberOfClass(lex.getString());
671 params.textclass = pp.second;
673 WriteAlert(string(_("Textclass error")),
674 string(_("The document uses an unknown textclass \"")) +
675 lex.getString() + string("\"."),
676 string(_("LyX will not be able to produce output correctly.")));
677 params.textclass = 0;
679 if (!textclasslist.Load(params.textclass)) {
680 // if the textclass wasn't loaded properly
681 // we need to either substitute another
682 // or stop loading the file.
683 // I can substitute but I don't see how I can
684 // stop loading... ideas?? ARRae980418
685 WriteAlert(_("Textclass Loading Error!"),
686 string(_("Can't load textclass ")) +
687 textclasslist.NameOfClass(params.textclass),
688 _("-- substituting default"));
689 params.textclass = 0;
691 } else if (token == "\\options") {
693 params.options = lex.getString();
694 } else if (token == "\\language") {
695 params.readLanguage(lex);
696 } else if (token == "\\fontencoding") {
698 } else if (token == "\\inputencoding") {
700 params.inputenc = lex.getString();
701 } else if (token == "\\graphics") {
702 params.readGraphicsDriver(lex);
703 } else if (token == "\\fontscheme") {
705 params.fonts = lex.getString();
706 } else if (token == "\\noindent") {
707 par->params().noindent(true);
708 } else if (token == "\\fill_top") {
709 par->params().spaceTop(VSpace(VSpace::VFILL));
710 } else if (token == "\\fill_bottom") {
711 par->params().spaceBottom(VSpace(VSpace::VFILL));
712 } else if (token == "\\line_top") {
713 par->params().lineTop(true);
714 } else if (token == "\\line_bottom") {
715 par->params().lineBottom(true);
716 } else if (token == "\\pagebreak_top") {
717 par->params().pagebreakTop(true);
718 } else if (token == "\\pagebreak_bottom") {
719 par->params().pagebreakBottom(true);
720 } else if (token == "\\start_of_appendix") {
721 par->params().startOfAppendix(true);
722 } else if (token == "\\paragraph_separation") {
723 int tmpret = lex.findToken(string_paragraph_separation);
724 if (tmpret == -1) ++tmpret;
725 if (tmpret != LYX_LAYOUT_DEFAULT)
726 params.paragraph_separation =
727 static_cast<BufferParams::PARSEP>(tmpret);
728 } else if (token == "\\defskip") {
730 params.defskip = VSpace(lex.getString());
731 } else if (token == "\\epsfig") { // obsolete
732 // Indeed it is obsolete, but we HAVE to be backwards
733 // compatible until 0.14, because otherwise all figures
734 // in existing documents are irretrivably lost. (Asger)
735 params.readGraphicsDriver(lex);
736 } else if (token == "\\quotes_language") {
737 int tmpret = lex.findToken(string_quotes_language);
738 if (tmpret == -1) ++tmpret;
739 if (tmpret != LYX_LAYOUT_DEFAULT) {
740 InsetQuotes::quote_language tmpl =
741 InsetQuotes::EnglishQ;
744 tmpl = InsetQuotes::EnglishQ;
747 tmpl = InsetQuotes::SwedishQ;
750 tmpl = InsetQuotes::GermanQ;
753 tmpl = InsetQuotes::PolishQ;
756 tmpl = InsetQuotes::FrenchQ;
759 tmpl = InsetQuotes::DanishQ;
762 params.quotes_language = tmpl;
764 } else if (token == "\\quotes_times") {
766 switch (lex.getInteger()) {
768 params.quotes_times = InsetQuotes::SingleQ;
771 params.quotes_times = InsetQuotes::DoubleQ;
774 } else if (token == "\\papersize") {
775 int tmpret = lex.findToken(string_papersize);
779 params.papersize2 = tmpret;
780 } else if (token == "\\paperpackage") {
781 int tmpret = lex.findToken(string_paperpackages);
784 params.paperpackage = BufferParams::PACKAGE_NONE;
786 params.paperpackage = tmpret;
787 } else if (token == "\\use_geometry") {
789 params.use_geometry = lex.getInteger();
790 } else if (token == "\\use_amsmath") {
792 params.use_amsmath = lex.getInteger();
793 } else if (token == "\\use_natbib") {
795 params.use_natbib = lex.getInteger();
796 } else if (token == "\\use_numerical_citations") {
798 params.use_numerical_citations = lex.getInteger();
799 } else if (token == "\\paperorientation") {
800 int tmpret = lex.findToken(string_orientation);
801 if (tmpret == -1) ++tmpret;
802 if (tmpret != LYX_LAYOUT_DEFAULT)
803 params.orientation = static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
804 } else if (token == "\\paperwidth") {
806 params.paperwidth = lex.getString();
807 } else if (token == "\\paperheight") {
809 params.paperheight = lex.getString();
810 } else if (token == "\\leftmargin") {
812 params.leftmargin = lex.getString();
813 } else if (token == "\\topmargin") {
815 params.topmargin = lex.getString();
816 } else if (token == "\\rightmargin") {
818 params.rightmargin = lex.getString();
819 } else if (token == "\\bottommargin") {
821 params.bottommargin = lex.getString();
822 } else if (token == "\\headheight") {
824 params.headheight = lex.getString();
825 } else if (token == "\\headsep") {
827 params.headsep = lex.getString();
828 } else if (token == "\\footskip") {
830 params.footskip = lex.getString();
831 } else if (token == "\\paperfontsize") {
833 params.fontsize = strip(lex.getString());
834 } else if (token == "\\papercolumns") {
836 params.columns = lex.getInteger();
837 } else if (token == "\\papersides") {
839 switch (lex.getInteger()) {
841 case 1: params.sides = LyXTextClass::OneSide; break;
842 case 2: params.sides = LyXTextClass::TwoSides; break;
844 } else if (token == "\\paperpagestyle") {
846 params.pagestyle = strip(lex.getString());
847 } else if (token == "\\bullet") {
849 int const index = lex.getInteger();
851 int temp_int = lex.getInteger();
852 params.user_defined_bullets[index].setFont(temp_int);
853 params.temp_bullets[index].setFont(temp_int);
855 temp_int = lex.getInteger();
856 params.user_defined_bullets[index].setCharacter(temp_int);
857 params.temp_bullets[index].setCharacter(temp_int);
859 temp_int = lex.getInteger();
860 params.user_defined_bullets[index].setSize(temp_int);
861 params.temp_bullets[index].setSize(temp_int);
863 string const temp_str = lex.getString();
864 if (temp_str != "\\end_bullet") {
865 // this element isn't really necessary for
866 // parsing but is easier for humans
867 // to understand bullets. Put it back and
868 // set a debug message?
869 lex.printError("\\end_bullet expected, got" + temp_str);
870 //how can I put it back?
872 } else if (token == "\\bulletLaTeX") {
874 int const index = lex.getInteger();
876 string temp_str = lex.getString();
878 while (temp_str != "\\end_bullet") {
879 // this loop structure is needed when user
880 // enters an empty string since the first
881 // thing returned will be the \\end_bullet
883 // if the LaTeX entry has spaces. Each element
884 // therefore needs to be read in turn
887 temp_str = lex.getString();
889 params.user_defined_bullets[index].setText(sum_str);
890 params.temp_bullets[index].setText(sum_str);
891 } else if (token == "\\secnumdepth") {
893 params.secnumdepth = lex.getInteger();
894 } else if (token == "\\tocdepth") {
896 params.tocdepth = lex.getInteger();
897 } else if (token == "\\spacing") {
899 string const tmp = strip(lex.getString());
900 Spacing::Space tmp_space = Spacing::Default;
902 if (tmp == "single") {
903 tmp_space = Spacing::Single;
904 } else if (tmp == "onehalf") {
905 tmp_space = Spacing::Onehalf;
906 } else if (tmp == "double") {
907 tmp_space = Spacing::Double;
908 } else if (tmp == "other") {
910 tmp_space = Spacing::Other;
911 tmp_val = lex.getFloat();
913 lex.printError("Unknown spacing token: '$$Token'");
915 // Small hack so that files written with klyx will be
918 par->params().spacing(Spacing(tmp_space, tmp_val));
920 params.spacing.set(tmp_space, tmp_val);
922 } else if (token == "\\paragraph_spacing") {
924 string const tmp = strip(lex.getString());
925 if (tmp == "single") {
926 par->params().spacing(Spacing(Spacing::Single));
927 } else if (tmp == "onehalf") {
928 par->params().spacing(Spacing(Spacing::Onehalf));
929 } else if (tmp == "double") {
930 par->params().spacing(Spacing(Spacing::Double));
931 } else if (tmp == "other") {
933 par->params().spacing(Spacing(Spacing::Other,
936 lex.printError("Unknown spacing token: '$$Token'");
938 } else if (token == "\\float_placement") {
940 params.float_placement = lex.getString();
941 } else if (token == "\\family") {
943 font.setLyXFamily(lex.getString());
944 } else if (token == "\\series") {
946 font.setLyXSeries(lex.getString());
947 } else if (token == "\\shape") {
949 font.setLyXShape(lex.getString());
950 } else if (token == "\\size") {
952 font.setLyXSize(lex.getString());
953 #ifndef NO_COMPABILITY
954 } else if (token == "\\latex") {
956 string const tok = lex.getString();
957 if (tok == "no_latex") {
959 insertErtContents(par, pos, font);
960 } else if (tok == "latex") {
961 ert_comp.active = true;
962 } else if (tok == "default") {
964 insertErtContents(par, pos, font);
966 lex.printError("Unknown LaTeX font flag "
970 } else if (token == "\\lang") {
972 string const tok = lex.getString();
973 Language const * lang = languages.getLanguage(tok);
975 font.setLanguage(lang);
977 font.setLanguage(params.language);
978 lex.printError("Unknown language `$$Token'");
980 } else if (token == "\\numeric") {
982 font.setNumber(font.setLyXMisc(lex.getString()));
983 } else if (token == "\\emph") {
985 font.setEmph(font.setLyXMisc(lex.getString()));
986 } else if (token == "\\bar") {
988 string const tok = lex.getString();
989 // This is dirty, but gone with LyX3. (Asger)
991 font.setUnderbar(LyXFont::ON);
992 else if (tok == "no")
993 font.setUnderbar(LyXFont::OFF);
994 else if (tok == "default")
995 font.setUnderbar(LyXFont::INHERIT);
997 lex.printError("Unknown bar font flag "
999 } else if (token == "\\noun") {
1001 font.setNoun(font.setLyXMisc(lex.getString()));
1002 } else if (token == "\\color") {
1004 font.setLyXColor(lex.getString());
1005 } else if (token == "\\align") {
1006 int tmpret = lex.findToken(string_align);
1007 if (tmpret == -1) ++tmpret;
1008 if (tmpret != LYX_LAYOUT_DEFAULT) { // tmpret != 99 ???
1009 int const tmpret2 = int(pow(2.0, tmpret));
1010 //lyxerr << "Tmpret2 = " << tmpret2 << endl;
1011 par->params().align(LyXAlignment(tmpret2));
1013 } else if (token == "\\added_space_top") {
1015 par->params().spaceTop(VSpace(lex.getString()));
1016 } else if (token == "\\added_space_bottom") {
1018 par->params().spaceBottom(VSpace(lex.getString()));
1019 #ifndef NO_COMPABILITY
1020 #ifndef NO_PEXTRA_REALLY
1021 } else if (token == "\\pextra_type") {
1023 par->params().pextraType(lex.getInteger());
1024 } else if (token == "\\pextra_width") {
1026 par->params().pextraWidth(lex.getString());
1027 } else if (token == "\\pextra_widthp") {
1029 par->params().pextraWidthp(lex.getString());
1030 } else if (token == "\\pextra_alignment") {
1032 par->params().pextraAlignment(lex.getInteger());
1033 } else if (token == "\\pextra_hfill") {
1035 par->params().pextraHfill(lex.getInteger());
1036 } else if (token == "\\pextra_start_minipage") {
1038 par->params().pextraStartMinipage(lex.getInteger());
1041 } else if (token == "\\labelwidthstring") {
1043 par->params().labelWidthString(lex.getString());
1044 // do not delete this token, it is still needed!
1045 } else if (token == "\\end_inset") {
1046 lyxerr << "Solitary \\end_inset. Missing \\begin_inset?.\n"
1047 << "Last inset read was: " << last_inset_read
1049 // Simply ignore this. The insets do not have
1051 // But insets should read it, it is a part of
1052 // the inset isn't it? Lgb.
1053 } else if (token == "\\begin_inset") {
1054 #ifndef NO_COMPABILITY
1055 insertErtContents(par, pos, font, false);
1056 ert_stack.push(ert_comp);
1057 ert_comp = ErtComp();
1059 readInset(lex, par, pos, font);
1060 #ifndef NO_COMPABILITY
1061 ert_comp = ert_stack.top();
1063 insertErtContents(par, pos, font);
1065 } else if (token == "\\SpecialChar") {
1066 LyXLayout const & layout =
1067 textclasslist.Style(params.textclass,
1070 // Insets don't make sense in a free-spacing context! ---Kayvan
1071 if (layout.free_spacing) {
1074 string next_token = lex.getString();
1075 if (next_token == "\\-") {
1076 par->insertChar(pos, '-', font);
1077 } else if (next_token == "\\protected_separator"
1078 || next_token == "~") {
1079 par->insertChar(pos, ' ', font);
1081 lex.printError("Token `$$Token' "
1083 "paragraph layout!");
1088 Inset * inset = new InsetSpecialChar;
1089 inset->read(this, lex);
1090 par->insertInset(pos, inset, font);
1093 } else if (token == "\\newline") {
1094 #ifndef NO_COMPABILITY
1095 if (!ert_comp.in_tabular && ert_comp.active) {
1096 ert_comp.contents += char(Paragraph::META_NEWLINE);
1098 // Since we cannot know it this is only a regular
1099 // newline or a tabular cell delimter we have to
1100 // handle the ERT here.
1101 insertErtContents(par, pos, font, false);
1103 par->insertChar(pos, Paragraph::META_NEWLINE, font);
1107 par->insertChar(pos, Paragraph::META_NEWLINE, font);
1110 } else if (token == "\\LyXTable") {
1111 #ifndef NO_COMPABILITY
1112 ert_comp.in_tabular = true;
1114 Inset * inset = new InsetTabular(*this);
1115 inset->read(this, lex);
1116 par->insertInset(pos, inset, font);
1118 } else if (token == "\\hfill") {
1119 par->insertChar(pos, Paragraph::META_HFILL, font);
1121 } else if (token == "\\protected_separator") { // obsolete
1122 // This is a backward compability thingie. (Lgb)
1123 // Remove it later some time...introduced with fileformat
1125 LyXLayout const & layout =
1126 textclasslist.Style(params.textclass,
1129 if (layout.free_spacing) {
1130 par->insertChar(pos, ' ', font);
1132 Inset * inset = new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
1133 par->insertInset(pos, inset, font);
1136 } else if (token == "\\bibitem") { // ale970302
1138 InsetCommandParams p("bibitem", "dummy");
1139 par->bibkey = new InsetBibKey(p);
1141 par->bibkey->read(this, lex);
1142 } else if (token == "\\backslash") {
1143 #ifndef NO_COMPABILITY
1144 if (ert_comp.active) {
1145 ert_comp.contents += "\\";
1148 par->insertChar(pos, '\\', font);
1150 #ifndef NO_COMPABILITY
1153 } else if (token == "\\the_end") {
1154 #ifndef NO_COMPABILITY
1155 // If we still have some ert active here we have to insert
1156 // it so we don't loose it. (Lgb)
1157 insertErtContents(par, pos, font);
1159 the_end_read = true;
1160 #ifndef NO_COMPABILITY
1161 #ifndef NO_PEXTRA_REALLY
1162 minipar = parBeforeMinipage = 0;
1166 #ifndef NO_COMPABILITY
1167 if (ert_comp.active) {
1168 ert_comp.contents += token;
1171 // This should be insurance for the future: (Asger)
1172 lex.printError("Unknown token `$$Token'. "
1173 "Inserting as text.");
1174 string::const_iterator cit = token.begin();
1175 string::const_iterator end = token.end();
1176 for (; cit != end; ++cit) {
1177 par->insertChar(pos, (*cit), font);
1180 #ifndef NO_COMPABILITY
1185 #ifndef NO_COMPABILITY
1186 #ifndef NO_PEXTRA_REALLY
1187 // I wonder if we could use this blanket fix for all the
1188 // checkminipage cases...
1189 if (par && par->size()) {
1190 // It is possible that this will check to often,
1191 // but that should not be an correctness issue.
1192 // Only a speed issue.
1193 checkminipage = true;
1196 // now check if we have a minipage paragraph as at this
1197 // point we already read all the necessary data!
1198 // this cannot be done in layout because there we did
1199 // not read yet the paragraph PEXTRA-params (Jug)
1201 // BEGIN pextra_minipage compability
1202 // This should be removed in 1.3.x (Lgb)
1204 // This compability code is not perfect. In a couple
1205 // of rand cases it fails. When the minipage par is
1206 // the first par in the document, and when there are
1207 // none or only one regular paragraphs after the
1208 // minipage. Currently I am not investing any effort
1209 // in fixing those cases.
1211 //lyxerr << "Call depth: " << call_depth << endl;
1212 if (checkminipage && (call_depth == 1)) {
1213 checkminipage = false;
1214 if (minipar && (minipar != par) &&
1215 (par->params().pextraType()==Paragraph::PEXTRA_MINIPAGE))
1217 lyxerr << "minipages in a row" << endl;
1218 if (par->params().pextraStartMinipage()) {
1219 lyxerr << "start new minipage" << endl;
1220 // minipages in a row
1221 par->previous()->next(0);
1224 Paragraph * tmp = minipar;
1226 tmp->params().pextraType(0);
1227 tmp->params().pextraWidth(string());
1228 tmp->params().pextraWidthp(string());
1229 tmp->params().pextraAlignment(0);
1230 tmp->params().pextraHfill(false);
1231 tmp->params().pextraStartMinipage(false);
1234 // create a new paragraph to insert the
1235 // minipages in the following case
1236 if (par->params().pextraStartMinipage() &&
1237 !par->params().pextraHfill())
1239 Paragraph * p = new Paragraph;
1241 p->previous(parBeforeMinipage);
1242 parBeforeMinipage->next(p);
1244 p->params().depth(parBeforeMinipage->params().depth());
1245 parBeforeMinipage = p;
1247 InsetMinipage * mini = new InsetMinipage;
1248 mini->pos(static_cast<InsetMinipage::Position>(par->params().pextraAlignment()));
1249 mini->width(par->params().pextraWidth());
1250 if (!par->params().pextraWidthp().empty()) {
1251 lyxerr << "WP:" << mini->width() << endl;
1252 mini->width(tostr(par->params().pextraWidthp())+"%");
1254 mini->inset.paragraph(par);
1255 // Insert the minipage last in the
1256 // previous paragraph.
1257 if (par->params().pextraHfill()) {
1258 parBeforeMinipage->insertChar
1259 (parBeforeMinipage->size(), Paragraph::META_HFILL);
1261 parBeforeMinipage->insertInset
1262 (parBeforeMinipage->size(), mini);
1266 lyxerr << "new minipage par" << endl;
1267 //nothing to do just continue reading
1270 } else if (minipar && (minipar != par)) {
1271 lyxerr << "last minipage par read" << endl;
1272 // The last paragraph read was not part of a
1273 // minipage but the par linked list is...
1274 // So we need to remove the last par from the
1276 if (par->previous())
1277 par->previous()->next(0);
1278 par->previous(parBeforeMinipage);
1279 parBeforeMinipage->next(par);
1280 Paragraph * tmp = minipar;
1282 tmp->params().pextraType(0);
1283 tmp->params().pextraWidth(string());
1284 tmp->params().pextraWidthp(string());
1285 tmp->params().pextraAlignment(0);
1286 tmp->params().pextraHfill(false);
1287 tmp->params().pextraStartMinipage(false);
1290 depth = parBeforeMinipage->params().depth();
1291 minipar = parBeforeMinipage = 0;
1292 } else if (!minipar &&
1293 (par->params().pextraType() == Paragraph::PEXTRA_MINIPAGE))
1295 // par is the first paragraph in a minipage
1296 lyxerr << "begin minipage" << endl;
1297 // To minimize problems for
1298 // the users we will insert
1299 // the first minipage in
1300 // a sequence of minipages
1301 // in its own paragraph.
1302 Paragraph * p = new Paragraph;
1304 p->previous(par->previous());
1306 p->params().depth(depth);
1307 par->params().depth(0);
1309 if (par->previous())
1310 par->previous()->next(p);
1312 parBeforeMinipage = p;
1314 if (!first_par || (first_par == par))
1317 InsetMinipage * mini = new InsetMinipage;
1318 mini->pos(static_cast<InsetMinipage::Position>(minipar->params().pextraAlignment()));
1319 mini->width(minipar->params().pextraWidth());
1320 if (!par->params().pextraWidthp().empty()) {
1321 lyxerr << "WP:" << mini->width() << endl;
1322 mini->width(tostr(par->params().pextraWidthp())+"%");
1324 mini->inset.paragraph(minipar);
1326 // Insert the minipage last in the
1327 // previous paragraph.
1328 if (minipar->params().pextraHfill()) {
1329 parBeforeMinipage->insertChar
1330 (parBeforeMinipage->size(),Paragraph::META_HFILL);
1332 parBeforeMinipage->insertInset
1333 (parBeforeMinipage->size(), mini);
1336 // End of pextra_minipage compability
1340 return the_end_read;
1343 // needed to insert the selection
1344 void Buffer::insertStringAsLines(Paragraph *& par, Paragraph::size_type & pos,
1345 LyXFont const & font,
1346 string const & str) const
1348 LyXLayout const & layout = textclasslist.Style(params.textclass,
1350 // insert the string, don't insert doublespace
1351 bool space_inserted = true;
1352 for(string::const_iterator cit = str.begin();
1353 cit != str.end(); ++cit) {
1355 if (par->size() || layout.keepempty) {
1356 par->breakParagraph(params, pos,
1357 layout.isEnvironment());
1360 space_inserted = true;
1364 // do not insert consecutive spaces if !free_spacing
1365 } else if ((*cit == ' ' || *cit == '\t')
1366 && space_inserted && !layout.free_spacing) {
1368 } else if (*cit == '\t') {
1369 if (!layout.free_spacing) {
1370 // tabs are like spaces here
1371 par->insertChar(pos, ' ', font);
1373 space_inserted = true;
1375 const Paragraph::value_type nb = 8 - pos % 8;
1376 for (Paragraph::size_type a = 0;
1378 par->insertChar(pos, ' ', font);
1381 space_inserted = true;
1383 } else if (!IsPrintable(*cit)) {
1384 // Ignore unprintables
1387 // just insert the character
1388 par->insertChar(pos, *cit, font);
1390 space_inserted = (*cit == ' ');
1397 void Buffer::readInset(LyXLex & lex, Paragraph *& par,
1398 int & pos, LyXFont & font)
1400 // consistency check
1401 if (lex.getString() != "\\begin_inset") {
1402 lyxerr << "Buffer::readInset: Consistency check failed."
1409 string const tmptok = lex.getString();
1410 last_inset_read = tmptok;
1412 // test the different insets
1413 if (tmptok == "LatexCommand") {
1414 InsetCommandParams inscmd;
1417 string const cmdName = inscmd.getCmdName();
1419 // This strange command allows LyX to recognize "natbib" style
1420 // citations: citet, citep, Citet etc.
1421 if (compare_no_case(cmdName, "cite", 4) == 0) {
1422 inset = new InsetCitation(inscmd);
1423 } else if (cmdName == "bibitem") {
1424 lex.printError("Wrong place for bibitem");
1425 inset = new InsetBibKey(inscmd);
1426 } else if (cmdName == "BibTeX") {
1427 inset = new InsetBibtex(inscmd);
1428 } else if (cmdName == "index") {
1429 inset = new InsetIndex(inscmd);
1430 } else if (cmdName == "include") {
1431 inset = new InsetInclude(inscmd, *this);
1432 } else if (cmdName == "label") {
1433 inset = new InsetLabel(inscmd);
1434 } else if (cmdName == "url"
1435 || cmdName == "htmlurl") {
1436 inset = new InsetUrl(inscmd);
1437 } else if (cmdName == "ref"
1438 || cmdName == "pageref"
1439 || cmdName == "vref"
1440 || cmdName == "vpageref"
1441 || cmdName == "prettyref") {
1442 if (!inscmd.getOptions().empty()
1443 || !inscmd.getContents().empty()) {
1444 inset = new InsetRef(inscmd, *this);
1446 } else if (cmdName == "tableofcontents") {
1447 inset = new InsetTOC(inscmd);
1448 } else if (cmdName == "listofalgorithms") {
1449 inset = new InsetFloatList("algorithm");
1450 } else if (cmdName == "listoffigures") {
1451 inset = new InsetFloatList("figure");
1452 } else if (cmdName == "listoftables") {
1453 inset = new InsetFloatList("table");
1454 } else if (cmdName == "printindex") {
1455 inset = new InsetPrintIndex(inscmd);
1456 } else if (cmdName == "lyxparent") {
1457 inset = new InsetParent(inscmd, *this);
1460 bool alreadyread = false;
1461 if (tmptok == "Quotes") {
1462 inset = new InsetQuotes;
1463 } else if (tmptok == "External") {
1464 inset = new InsetExternal;
1465 } else if (tmptok == "FormulaMacro") {
1466 inset = new InsetFormulaMacro;
1467 } else if (tmptok == "Formula") {
1468 inset = new InsetFormula;
1469 } else if (tmptok == "Figure") { // Backward compatibility
1470 inset = new InsetFig(100, 100, *this);
1471 //inset = new InsetGraphics;
1472 } else if (tmptok == "Graphics") {
1473 inset = new InsetGraphics;
1474 } else if (tmptok == "Info") {// backwards compatibility
1475 inset = new InsetNote(this,
1476 lex.getLongString("\\end_inset"),
1479 } else if (tmptok == "Note") {
1480 inset = new InsetNote;
1481 } else if (tmptok == "Include") {
1482 InsetCommandParams p( "Include" );
1483 inset = new InsetInclude(p, *this);
1484 } else if (tmptok == "ERT") {
1485 inset = new InsetERT;
1486 } else if (tmptok == "Tabular") {
1487 inset = new InsetTabular(*this);
1488 } else if (tmptok == "Text") {
1489 inset = new InsetText;
1490 } else if (tmptok == "Foot") {
1491 inset = new InsetFoot;
1492 } else if (tmptok == "Marginal") {
1493 inset = new InsetMarginal;
1494 } else if (tmptok == "Minipage") {
1495 inset = new InsetMinipage;
1496 } else if (tmptok == "Float") {
1498 string tmptok = lex.getString();
1499 inset = new InsetFloat(tmptok);
1501 } else if (tmptok == "List") {
1502 inset = new InsetList;
1503 } else if (tmptok == "Theorem") {
1504 inset = new InsetList;
1506 } else if (tmptok == "Caption") {
1507 inset = new InsetCaption;
1508 } else if (tmptok == "FloatList") {
1509 inset = new InsetFloatList;
1512 if (inset && !alreadyread) inset->read(this, lex);
1516 par->insertInset(pos, inset, font);
1522 bool Buffer::readFile(LyXLex & lex, Paragraph * par)
1526 string const token(lex.getString());
1527 if (token == "\\lyxformat") { // the first token _must_ be...
1529 string tmp_format = lex.getString();
1530 //lyxerr << "LyX Format: `" << tmp_format << "'" << endl;
1531 // if present remove ".," from string.
1532 string::size_type dot = tmp_format.find_first_of(".,");
1533 //lyxerr << " dot found at " << dot << endl;
1534 if (dot != string::npos)
1535 tmp_format.erase(dot, 1);
1536 file_format = strToInt(tmp_format);
1537 if (file_format == LYX_FORMAT) {
1539 } else if (file_format > LYX_FORMAT) {
1541 WriteAlert(_("Warning!"),
1542 _("LyX file format is newer that what"),
1543 _("is supported in this LyX version. Expect some problems."));
1545 } else if (file_format < LYX_FORMAT) {
1547 if (file_format < 200) {
1548 WriteAlert(_("ERROR!"),
1549 _("Old LyX file format found. "
1550 "Use LyX 0.10.x to read this!"));
1554 bool the_end = readLyXformat2(lex, par);
1556 // the_end was added in 213
1557 if (file_format < 213)
1561 WriteAlert(_("Warning!"),
1562 _("Reading of document is not complete"),
1563 _("Maybe the document is truncated"));
1565 } else { // "\\lyxformat" not found
1566 WriteAlert(_("ERROR!"), _("Not a LyX file!"));
1569 WriteAlert(_("ERROR!"), _("Unable to read file!"));
1574 // Should probably be moved to somewhere else: BufferView? LyXView?
1575 bool Buffer::save() const
1577 // We don't need autosaves in the immediate future. (Asger)
1578 resetAutosaveTimers();
1582 if (lyxrc.make_backup) {
1583 s = fileName() + '~';
1584 if (!lyxrc.backupdir_path.empty())
1585 s = AddName(lyxrc.backupdir_path,
1586 subst(os::slashify_path(s),'/','!'));
1588 // Rename is the wrong way of making a backup,
1589 // this is the correct way.
1590 /* truss cp fil fil2:
1591 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
1592 stat("LyXVC.lyx", 0xEFFFF688) = 0
1593 open("LyXVC.lyx", O_RDONLY) = 3
1594 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
1595 fstat(4, 0xEFFFF508) = 0
1596 fstat(3, 0xEFFFF508) = 0
1597 read(3, " # T h i s f i l e w".., 8192) = 5579
1598 write(4, " # T h i s f i l e w".., 5579) = 5579
1599 read(3, 0xEFFFD4A0, 8192) = 0
1602 chmod("LyXVC3.lyx", 0100644) = 0
1603 lseek(0, 0, SEEK_CUR) = 46440
1607 // Should probably have some more error checking here.
1608 // Should be cleaned up in 0.13, at least a bit.
1609 // Doing it this way, also makes the inodes stay the same.
1610 // This is still not a very good solution, in particular we
1611 // might loose the owner of the backup.
1612 FileInfo finfo(fileName());
1613 if (finfo.exist()) {
1614 mode_t fmode = finfo.getMode();
1615 struct utimbuf times = {
1616 finfo.getAccessTime(),
1617 finfo.getModificationTime() };
1619 ifstream ifs(fileName().c_str());
1620 ofstream ofs(s.c_str(), ios::out|ios::trunc);
1625 ::chmod(s.c_str(), fmode);
1627 if (::utime(s.c_str(), ×)) {
1628 lyxerr << "utime error." << endl;
1631 lyxerr << "LyX was not able to make "
1632 "backup copy. Beware." << endl;
1637 if (writeFile(fileName(), false)) {
1639 removeAutosaveFile(fileName());
1641 // Saving failed, so backup is not backup
1642 if (lyxrc.make_backup) {
1643 lyx::rename(s, fileName());
1651 // Returns false if unsuccesful
1652 bool Buffer::writeFile(string const & fname, bool flag) const
1654 // if flag is false writeFile will not create any GUI
1655 // warnings, only cerr.
1656 // Needed for autosave in background or panic save (Matthias 120496)
1658 if (read_only && (fname == filename)) {
1659 // Here we should come with a question if we should
1660 // perform the write anyway.
1662 lyxerr << _("Error! Document is read-only: ")
1665 WriteAlert(_("Error! Document is read-only: "),
1670 FileInfo finfo(fname);
1671 if (finfo.exist() && !finfo.writable()) {
1672 // Here we should come with a question if we should
1673 // try to do the save anyway. (i.e. do a chmod first)
1675 lyxerr << _("Error! Cannot write file: ")
1678 WriteFSAlert(_("Error! Cannot write file: "),
1683 ofstream ofs(fname.c_str());
1686 lyxerr << _("Error! Cannot open file: ")
1689 WriteFSAlert(_("Error! Cannot open file: "),
1695 // Use the standard "C" locale for file output.
1696 ofs.imbue(std::locale::classic());
1699 // The top of the file should not be written by params.
1701 // write out a comment in the top of the file
1702 ofs << '#' << LYX_DOCVERSION
1703 << " created this file. For more info see http://www.lyx.org/\n"
1704 << "\\lyxformat " << LYX_FORMAT << "\n";
1706 // now write out the buffer paramters.
1707 params.writeFile(ofs);
1709 Paragraph::depth_type depth = 0;
1711 // this will write out all the paragraphs
1712 // using recursive descent.
1713 paragraph->writeFile(this, ofs, params, depth);
1715 // Write marker that shows file is complete
1716 ofs << "\n\\the_end" << endl;
1720 // how to check if close went ok?
1721 // Following is an attempt... (BE 20001011)
1723 // good() returns false if any error occured, including some
1724 // formatting error.
1725 // bad() returns true if something bad happened in the buffer,
1726 // which should include file system full errors.
1733 lyxerr << "Buffer::writeFile: BAD ERROR!" << endl;
1735 lyxerr << "Buffer::writeFile: NOT SO BAD ERROR!"
1745 string const Buffer::asciiParagraph(Paragraph const * par,
1746 unsigned int linelen) const
1748 ostringstream buffer;
1749 Paragraph::depth_type depth = 0;
1751 Paragraph::depth_type ltype_depth = 0;
1752 unsigned int currlinelen = 0;
1753 bool ref_printed = false;
1757 if (!par->previous()) {
1758 // begins or ends a deeper area ?
1759 if (depth != par->params().depth()) {
1760 if (par->params().depth() > depth) {
1761 while (par->params().depth() > depth) {
1765 while (par->params().depth() < depth) {
1771 // First write the layout
1772 string const tmp = textclasslist.NameOfLayout(params.textclass, par->layout);
1773 if (tmp == "Itemize") {
1775 ltype_depth = depth + 1;
1776 } else if (tmp == "Enumerate") {
1778 ltype_depth = depth + 1;
1779 } else if (contains(tmp, "ection")) {
1781 ltype_depth = depth + 1;
1782 } else if (contains(tmp, "aragraph")) {
1784 ltype_depth = depth + 1;
1785 } else if (tmp == "Description") {
1787 ltype_depth = depth + 1;
1788 } else if (tmp == "Abstract") {
1791 } else if (tmp == "Bibliography") {
1799 /* maybe some vertical spaces */
1801 /* the labelwidthstring used in lists */
1805 /* some pagebreaks? */
1809 /* what about the alignment */
1811 lyxerr << "Should this ever happen?" << endl;
1814 for (Paragraph::size_type i = 0; i < par->size(); ++i) {
1815 if (!i && !noparbreak) {
1818 for (Paragraph::depth_type j = 0; j < depth; ++j)
1820 currlinelen = depth * 2;
1823 case 4: // (Sub)Paragraph
1824 case 5: // Description
1828 buffer << "Abstract\n\n";
1830 buffer << "Abstract: ";
1832 case 7: // Bibliography
1835 buffer << "References\n\n";
1837 buffer << "References: ";
1842 buffer << par->params().labelString() << " ";
1845 if (ltype_depth > depth) {
1846 for (Paragraph::depth_type j = ltype_depth - 1;
1849 currlinelen += (ltype_depth-depth)*2;
1853 char c = par->getUChar(params, i);
1857 case Paragraph::META_INSET:
1859 Inset const * inset = par->getInset(i);
1861 if (!inset->ascii(this, buffer)) {
1864 rsplit(buffer.str().c_str(),
1866 currlinelen += s.length();
1868 // to be sure it breaks paragraph
1869 currlinelen += linelen;
1875 case Paragraph::META_NEWLINE:
1878 for (Paragraph::depth_type j = 0;
1882 currlinelen = depth * 2;
1883 if (ltype_depth > depth) {
1884 for (Paragraph::depth_type j = ltype_depth;
1887 currlinelen += (ltype_depth - depth) * 2;
1891 case Paragraph::META_HFILL:
1900 if ((linelen > 0) && (currlinelen > (linelen - 10)) &&
1901 (c == ' ') && ((i + 2) < par->size()))
1904 for (Paragraph::depth_type j = 0;
1907 currlinelen = depth * 2;
1908 if (ltype_depth > depth) {
1909 for (Paragraph::depth_type j = ltype_depth;
1912 currlinelen += (ltype_depth-depth)*2;
1914 } else if (c != '\0')
1917 lyxerr[Debug::INFO] << "writeAsciiFile: NULL char in structure." << endl;
1922 return buffer.str().c_str();
1926 void Buffer::writeFileAscii(string const & fname, int linelen)
1928 ofstream ofs(fname.c_str());
1930 WriteFSAlert(_("Error: Cannot write file:"), fname);
1933 writeFileAscii(ofs, linelen);
1937 void Buffer::writeFileAscii(ostream & ofs, int linelen)
1939 Paragraph * par = paragraph;
1941 ofs << asciiParagraph(par, linelen);
1949 void Buffer::makeLaTeXFile(string const & fname,
1950 string const & original_path,
1951 bool nice, bool only_body)
1953 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
1955 niceFile = nice; // this will be used by Insetincludes.
1957 tex_code_break_column = lyxrc.ascii_linelen;
1959 LyXTextClass const & tclass =
1960 textclasslist.TextClass(params.textclass);
1962 ofstream ofs(fname.c_str());
1964 WriteFSAlert(_("Error: Cannot open file: "), fname);
1968 // validate the buffer.
1969 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
1970 LaTeXFeatures features(params, tclass.numLayouts());
1972 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
1975 // The starting paragraph of the coming rows is the
1976 // first paragraph of the document. (Asger)
1977 texrow.start(paragraph, 0);
1979 if (!only_body && nice) {
1980 ofs << "%% " LYX_DOCVERSION " created this file. "
1981 "For more info, see http://www.lyx.org/.\n"
1982 "%% Do not edit unless you really know what "
1987 lyxerr[Debug::INFO] << "lyx header finished" << endl;
1988 // There are a few differences between nice LaTeX and usual files:
1989 // usual is \batchmode and has a
1990 // special input@path to allow the including of figures
1991 // with either \input or \includegraphics (what figinsets do).
1992 // batchmode is not set if there is a tex_code_break_column.
1993 // In this case somebody is interested in the generated LaTeX,
1994 // so this is OK. input@path is set when the actual parameter
1995 // original_path is set. This is done for usual tex-file, but not
1996 // for nice-latex-file. (Matthias 250696)
1999 // code for usual, NOT nice-latex-file
2000 ofs << "\\batchmode\n"; // changed
2001 // from \nonstopmode
2004 if (!original_path.empty()) {
2005 ofs << "\\makeatletter\n"
2006 << "\\def\\input@path{{"
2007 << os::external_path(original_path) << "/}}\n"
2008 << "\\makeatother\n";
2014 ofs << "\\documentclass";
2016 ostringstream options; // the document class options.
2018 if (tokenPos(tclass.opt_fontsize(),
2019 '|', params.fontsize) >= 0) {
2020 // only write if existing in list (and not default)
2021 options << params.fontsize << "pt,";
2025 if (!params.use_geometry &&
2026 (params.paperpackage == BufferParams::PACKAGE_NONE)) {
2027 switch (params.papersize) {
2028 case BufferParams::PAPER_A4PAPER:
2029 options << "a4paper,";
2031 case BufferParams::PAPER_USLETTER:
2032 options << "letterpaper,";
2034 case BufferParams::PAPER_A5PAPER:
2035 options << "a5paper,";
2037 case BufferParams::PAPER_B5PAPER:
2038 options << "b5paper,";
2040 case BufferParams::PAPER_EXECUTIVEPAPER:
2041 options << "executivepaper,";
2043 case BufferParams::PAPER_LEGALPAPER:
2044 options << "legalpaper,";
2050 if (params.sides != tclass.sides()) {
2051 switch (params.sides) {
2052 case LyXTextClass::OneSide:
2053 options << "oneside,";
2055 case LyXTextClass::TwoSides:
2056 options << "twoside,";
2062 if (params.columns != tclass.columns()) {
2063 if (params.columns == 2)
2064 options << "twocolumn,";
2066 options << "onecolumn,";
2069 if (!params.use_geometry
2070 && params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
2071 options << "landscape,";
2073 // language should be a parameter to \documentclass
2075 ostringstream language_options;
2076 if (params.language->babel() == "hebrew"
2077 && default_language->babel() != "hebrew")
2078 // This seems necessary
2079 features.UsedLanguages.insert(default_language);
2081 if (lyxrc.language_use_babel ||
2082 params.language->lang() != lyxrc.default_language ||
2083 !features.UsedLanguages.empty()) {
2085 for (LaTeXFeatures::LanguageList::const_iterator cit =
2086 features.UsedLanguages.begin();
2087 cit != features.UsedLanguages.end(); ++cit)
2088 language_options << (*cit)->babel() << ',';
2089 language_options << params.language->babel();
2090 if (lyxrc.language_global_options)
2091 options << language_options.str() << ',';
2094 // the user-defined options
2095 if (!params.options.empty()) {
2096 options << params.options << ',';
2099 string strOptions(options.str().c_str());
2100 if (!strOptions.empty()){
2101 strOptions = strip(strOptions, ',');
2102 ofs << '[' << strOptions << ']';
2106 << textclasslist.LatexnameOfClass(params.textclass)
2109 // end of \documentclass defs
2111 // font selection must be done before loading fontenc.sty
2112 // The ae package is not needed when using OT1 font encoding.
2113 if (params.fonts != "default" &&
2114 (params.fonts != "ae" || lyxrc.fontenc != "default")) {
2115 ofs << "\\usepackage{" << params.fonts << "}\n";
2117 if (params.fonts == "ae") {
2118 ofs << "\\usepackage{aecompl}\n";
2122 // this one is not per buffer
2123 if (lyxrc.fontenc != "default") {
2124 ofs << "\\usepackage[" << lyxrc.fontenc
2129 if (params.inputenc == "auto") {
2130 string const doc_encoding =
2131 params.language->encoding()->LatexName();
2133 // Create a list with all the input encodings used
2135 set<string> encodings;
2136 for (LaTeXFeatures::LanguageList::const_iterator it =
2137 features.UsedLanguages.begin();
2138 it != features.UsedLanguages.end(); ++it)
2139 if ((*it)->encoding()->LatexName() != doc_encoding)
2140 encodings.insert((*it)->encoding()->LatexName());
2142 ofs << "\\usepackage[";
2143 std::copy(encodings.begin(), encodings.end(),
2144 std::ostream_iterator<string>(ofs, ","));
2145 ofs << doc_encoding << "]{inputenc}\n";
2147 } else if (params.inputenc != "default") {
2148 ofs << "\\usepackage[" << params.inputenc
2153 // At the very beginning the text parameters.
2154 if (params.paperpackage != BufferParams::PACKAGE_NONE) {
2155 switch (params.paperpackage) {
2156 case BufferParams::PACKAGE_A4:
2157 ofs << "\\usepackage{a4}\n";
2160 case BufferParams::PACKAGE_A4WIDE:
2161 ofs << "\\usepackage{a4wide}\n";
2164 case BufferParams::PACKAGE_WIDEMARGINSA4:
2165 ofs << "\\usepackage[widemargins]{a4}\n";
2170 if (params.use_geometry) {
2171 ofs << "\\usepackage{geometry}\n";
2173 ofs << "\\geometry{verbose";
2174 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
2175 ofs << ",landscape";
2176 switch (params.papersize2) {
2177 case BufferParams::VM_PAPER_CUSTOM:
2178 if (!params.paperwidth.empty())
2179 ofs << ",paperwidth="
2180 << params.paperwidth;
2181 if (!params.paperheight.empty())
2182 ofs << ",paperheight="
2183 << params.paperheight;
2185 case BufferParams::VM_PAPER_USLETTER:
2186 ofs << ",letterpaper";
2188 case BufferParams::VM_PAPER_USLEGAL:
2189 ofs << ",legalpaper";
2191 case BufferParams::VM_PAPER_USEXECUTIVE:
2192 ofs << ",executivepaper";
2194 case BufferParams::VM_PAPER_A3:
2197 case BufferParams::VM_PAPER_A4:
2200 case BufferParams::VM_PAPER_A5:
2203 case BufferParams::VM_PAPER_B3:
2206 case BufferParams::VM_PAPER_B4:
2209 case BufferParams::VM_PAPER_B5:
2213 // default papersize ie BufferParams::VM_PAPER_DEFAULT
2214 switch (lyxrc.default_papersize) {
2215 case BufferParams::PAPER_DEFAULT: // keep compiler happy
2216 case BufferParams::PAPER_USLETTER:
2217 ofs << ",letterpaper";
2219 case BufferParams::PAPER_LEGALPAPER:
2220 ofs << ",legalpaper";
2222 case BufferParams::PAPER_EXECUTIVEPAPER:
2223 ofs << ",executivepaper";
2225 case BufferParams::PAPER_A3PAPER:
2228 case BufferParams::PAPER_A4PAPER:
2231 case BufferParams::PAPER_A5PAPER:
2234 case BufferParams::PAPER_B5PAPER:
2239 if (!params.topmargin.empty())
2240 ofs << ",tmargin=" << params.topmargin;
2241 if (!params.bottommargin.empty())
2242 ofs << ",bmargin=" << params.bottommargin;
2243 if (!params.leftmargin.empty())
2244 ofs << ",lmargin=" << params.leftmargin;
2245 if (!params.rightmargin.empty())
2246 ofs << ",rmargin=" << params.rightmargin;
2247 if (!params.headheight.empty())
2248 ofs << ",headheight=" << params.headheight;
2249 if (!params.headsep.empty())
2250 ofs << ",headsep=" << params.headsep;
2251 if (!params.footskip.empty())
2252 ofs << ",footskip=" << params.footskip;
2256 if (features.amsstyle
2257 && !tclass.provides(LyXTextClass::amsmath)) {
2258 ofs << "\\usepackage{amsmath}\n";
2262 if (tokenPos(tclass.opt_pagestyle(),
2263 '|', params.pagestyle) >= 0) {
2264 if (params.pagestyle == "fancy") {
2265 ofs << "\\usepackage{fancyhdr}\n";
2268 ofs << "\\pagestyle{" << params.pagestyle << "}\n";
2272 // We try to load babel late, in case it interferes
2273 // with other packages.
2275 string tmp = lyxrc.language_package;
2276 if (!lyxrc.language_global_options
2277 && tmp == "\\usepackage{babel}")
2278 tmp = string("\\usepackage[") +
2279 language_options.str().c_str() +
2285 if (params.secnumdepth != tclass.secnumdepth()) {
2286 ofs << "\\setcounter{secnumdepth}{"
2287 << params.secnumdepth
2291 if (params.tocdepth != tclass.tocdepth()) {
2292 ofs << "\\setcounter{tocdepth}{"
2298 if (params.paragraph_separation) {
2299 switch (params.defskip.kind()) {
2300 case VSpace::SMALLSKIP:
2301 ofs << "\\setlength\\parskip{\\smallskipamount}\n";
2303 case VSpace::MEDSKIP:
2304 ofs << "\\setlength\\parskip{\\medskipamount}\n";
2306 case VSpace::BIGSKIP:
2307 ofs << "\\setlength\\parskip{\\bigskipamount}\n";
2309 case VSpace::LENGTH:
2310 ofs << "\\setlength\\parskip{"
2311 << params.defskip.length().asLatexString()
2314 default: // should never happen // Then delete it.
2315 ofs << "\\setlength\\parskip{\\medskipamount}\n";
2320 ofs << "\\setlength\\parindent{0pt}\n";
2324 // Now insert the LyX specific LaTeX commands...
2326 // The optional packages;
2327 string preamble(features.getPackages());
2329 // this might be useful...
2330 preamble += "\n\\makeatletter\n";
2332 // Some macros LyX will need
2333 string tmppreamble(features.getMacros());
2335 if (!tmppreamble.empty()) {
2336 preamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2337 "LyX specific LaTeX commands.\n"
2338 + tmppreamble + '\n';
2341 // the text class specific preamble
2342 tmppreamble = features.getTClassPreamble();
2343 if (!tmppreamble.empty()) {
2344 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2345 "Textclass specific LaTeX commands.\n"
2346 + tmppreamble + '\n';
2349 /* the user-defined preamble */
2350 if (!params.preamble.empty()) {
2351 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2352 "User specified LaTeX commands.\n"
2353 + params.preamble + '\n';
2356 preamble += "\\makeatother\n";
2358 // Itemize bullet settings need to be last in case the user
2359 // defines their own bullets that use a package included
2360 // in the user-defined preamble -- ARRae
2361 // Actually it has to be done much later than that
2362 // since some packages like frenchb make modifications
2363 // at \begin{document} time -- JMarc
2365 for (int i = 0; i < 4; ++i) {
2366 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
2367 if (bullets_def.empty())
2368 bullets_def="\\AtBeginDocument{\n";
2369 bullets_def += " \\renewcommand{\\labelitemi";
2371 // `i' is one less than the item to modify
2378 bullets_def += "ii";
2384 bullets_def += "}{" +
2385 params.user_defined_bullets[i].getText()
2390 if (!bullets_def.empty())
2391 preamble += bullets_def + "}\n\n";
2393 for (int j = countChar(preamble, '\n'); j-- ;) {
2400 ofs << "\\begin{document}\n";
2403 lyxerr[Debug::INFO] << "preamble finished, now the body." << endl;
2405 if (!lyxrc.language_auto_begin) {
2406 ofs << subst(lyxrc.language_command_begin, "$$lang",
2407 params.language->babel())
2412 latexParagraphs(ofs, paragraph, 0, texrow);
2414 // add this just in case after all the paragraphs
2418 if (!lyxrc.language_auto_end) {
2419 ofs << subst(lyxrc.language_command_end, "$$lang",
2420 params.language->babel())
2426 ofs << "\\end{document}\n";
2429 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
2431 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
2435 // Just to be sure. (Asger)
2438 // tex_code_break_column's value is used to decide
2439 // if we are in batchmode or not (within mathed_write()
2440 // in math_write.C) so we must set it to a non-zero
2441 // value when we leave otherwise we save incorrect .lyx files.
2442 tex_code_break_column = lyxrc.ascii_linelen;
2446 lyxerr << "File was not closed properly." << endl;
2449 lyxerr[Debug::INFO] << "Finished making latex file." << endl;
2454 // LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
2456 void Buffer::latexParagraphs(ostream & ofs, Paragraph * par,
2457 Paragraph * endpar, TexRow & texrow) const
2459 bool was_title = false;
2460 bool already_title = false;
2463 while (par != endpar) {
2464 LyXLayout const & layout =
2465 textclasslist.Style(params.textclass,
2468 if (layout.intitle) {
2469 if (already_title) {
2470 lyxerr <<"Error in latexParagraphs: You"
2471 " should not mix title layouts"
2472 " with normal ones." << endl;
2475 } else if (was_title && !already_title) {
2476 ofs << "\\maketitle\n";
2478 already_title = true;
2482 if (layout.isEnvironment()) {
2483 par = par->TeXEnvironment(this, params, ofs, texrow);
2485 par = par->TeXOnePar(this, params, ofs, texrow, false);
2488 // It might be that we only have a title in this document
2489 if (was_title && !already_title) {
2490 ofs << "\\maketitle\n";
2496 bool Buffer::isLatex() const
2498 return textclasslist.TextClass(params.textclass).outputType() == LATEX;
2502 bool Buffer::isLinuxDoc() const
2504 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC;
2508 bool Buffer::isLiterate() const
2510 return textclasslist.TextClass(params.textclass).outputType() == LITERATE;
2514 bool Buffer::isDocBook() const
2516 return textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2520 bool Buffer::isSGML() const
2522 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC ||
2523 textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2527 void Buffer::sgmlOpenTag(ostream & os, Paragraph::depth_type depth,
2528 string const & latexname) const
2530 if (!latexname.empty() && latexname != "!-- --")
2531 os << "<!-- " << depth << " -->" << "<" << latexname << ">";
2532 //os << string(depth, ' ') << "<" << latexname << ">\n";
2536 void Buffer::sgmlCloseTag(ostream & os, Paragraph::depth_type depth,
2537 string const & latexname) const
2539 if (!latexname.empty() && latexname != "!-- --")
2540 os << "<!-- " << depth << " -->" << "</" << latexname << ">\n";
2541 //os << string(depth, ' ') << "</" << latexname << ">\n";
2545 void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
2547 ofstream ofs(fname.c_str());
2550 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2554 niceFile = nice; // this will be used by included files.
2556 LyXTextClass const & tclass =
2557 textclasslist.TextClass(params.textclass);
2559 LaTeXFeatures features(params, tclass.numLayouts());
2564 string top_element = textclasslist.LatexnameOfClass(params.textclass);
2567 string sgml_includedfiles=features.getIncludedFiles(fname);
2569 if (params.preamble.empty() && sgml_includedfiles.empty()) {
2570 ofs << "<!doctype linuxdoc system>\n\n";
2572 ofs << "<!doctype linuxdoc system [ "
2573 << params.preamble << sgml_includedfiles << " \n]>\n\n";
2576 if (params.options.empty())
2577 sgmlOpenTag(ofs, 0, top_element);
2579 string top = top_element;
2581 top += params.options;
2582 sgmlOpenTag(ofs, 0, top);
2586 ofs << "<!-- " << LYX_DOCVERSION
2587 << " created this file. For more info see http://www.lyx.org/"
2590 Paragraph::depth_type depth = 0; // paragraph depth
2591 Paragraph * par = paragraph;
2593 vector<string> environment_stack(5);
2596 LyXLayout const & style =
2597 textclasslist.Style(params.textclass,
2600 // treat <toc> as a special case for compatibility with old code
2601 if (par->getChar(0) == Paragraph::META_INSET) {
2602 Inset * inset = par->getInset(0);
2603 Inset::Code lyx_code = inset->lyxCode();
2604 if (lyx_code == Inset::TOC_CODE){
2605 string const temp = "toc";
2606 sgmlOpenTag(ofs, depth, temp);
2613 // environment tag closing
2614 for (; depth > par->params().depth(); --depth) {
2615 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2616 environment_stack[depth].erase();
2619 // write opening SGML tags
2620 switch (style.latextype) {
2621 case LATEX_PARAGRAPH:
2622 if (depth == par->params().depth()
2623 && !environment_stack[depth].empty()) {
2624 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2625 environment_stack[depth].erase();
2631 sgmlOpenTag(ofs, depth, style.latexname());
2636 linuxDocError(par, 0,
2637 _("Error : Wrong depth for"
2638 " LatexType Command.\n"));
2640 if (!environment_stack[depth].empty()){
2641 sgmlCloseTag(ofs, depth,
2642 environment_stack[depth]);
2646 environment_stack[depth].erase();
2647 sgmlOpenTag(ofs, depth, style.latexname());
2650 case LATEX_ENVIRONMENT:
2651 case LATEX_ITEM_ENVIRONMENT:
2652 if (depth == par->params().depth()
2653 && environment_stack[depth] != style.latexname()) {
2654 sgmlCloseTag(ofs, depth,
2655 environment_stack[depth]);
2656 environment_stack[depth].erase();
2658 if (depth < par->params().depth()) {
2659 depth = par->params().depth();
2660 environment_stack[depth].erase();
2662 if (environment_stack[depth] != style.latexname()) {
2664 sgmlOpenTag(ofs, depth, "p");
2666 sgmlOpenTag(ofs, depth, style.latexname());
2668 if (environment_stack.size() == depth + 1)
2669 environment_stack.push_back("!-- --");
2670 environment_stack[depth] = style.latexname();
2673 if (style.latexparam() == "CDATA")
2676 if (style.latextype == LATEX_ENVIRONMENT) break;
2678 if (style.labeltype == LABEL_MANUAL)
2683 sgmlOpenTag(ofs, depth + 1, item_name);
2686 sgmlOpenTag(ofs, depth, style.latexname());
2690 simpleLinuxDocOnePar(ofs, par, depth);
2695 // write closing SGML tags
2696 switch (style.latextype) {
2699 case LATEX_ENVIRONMENT:
2700 case LATEX_ITEM_ENVIRONMENT:
2701 if (style.latexparam() == "CDATA")
2705 sgmlCloseTag(ofs, depth, style.latexname());
2711 for (int i=depth; i >= 0; --i)
2712 sgmlCloseTag(ofs, depth, environment_stack[i]);
2716 sgmlCloseTag(ofs, 0, top_element);
2720 // How to check for successful close
2724 void Buffer::docBookHandleCaption(ostream & os, string & inner_tag,
2725 Paragraph::depth_type depth, int desc_on,
2728 Paragraph * tpar = par;
2730 && (tpar->layout != textclasslist.NumberOfLayout(params.textclass,
2732 tpar = tpar->next();
2735 tpar->layout == textclasslist.NumberOfLayout(params.textclass,
2736 "Caption").second) {
2737 sgmlOpenTag(os, depth + 1, inner_tag);
2739 simpleDocBookOnePar(os, extra_par, tpar,
2740 desc_on, depth + 2);
2741 sgmlCloseTag(os, depth+1, inner_tag);
2742 if (!extra_par.empty())
2748 // checks, if newcol chars should be put into this line
2749 // writes newline, if necessary.
2752 void linux_doc_line_break(ostream & os, string::size_type & colcount,
2753 string::size_type newcol)
2756 if (colcount > lyxrc.ascii_linelen) {
2758 colcount = newcol; // assume write after this call
2773 string tag_name(PAR_TAG const & pt) {
2775 case NONE: return "!-- --";
2776 case TT: return "tt";
2777 case SF: return "sf";
2778 case BF: return "bf";
2779 case IT: return "it";
2780 case SL: return "sl";
2781 case EM: return "em";
2788 void operator|=(PAR_TAG & p1, PAR_TAG const & p2)
2790 p1 = static_cast<PAR_TAG>(p1 | p2);
2795 void reset(PAR_TAG & p1, PAR_TAG const & p2)
2797 p1 = static_cast<PAR_TAG>( p1 & ~p2);
2805 // Handle internal paragraph parsing -- layout already processed.
2806 void Buffer::simpleLinuxDocOnePar(ostream & os,
2808 Paragraph::depth_type /*depth*/)
2810 LyXLayout const & style = textclasslist.Style(params.textclass,
2812 string::size_type char_line_count = 5; // Heuristic choice ;-)
2814 // gets paragraph main font
2817 if (style.labeltype == LABEL_MANUAL) {
2818 font_old = style.labelfont;
2821 font_old = style.font;
2825 LyXFont::FONT_FAMILY family_type = LyXFont::ROMAN_FAMILY;
2826 LyXFont::FONT_SERIES series_type = LyXFont::MEDIUM_SERIES;
2827 LyXFont::FONT_SHAPE shape_type = LyXFont::UP_SHAPE;
2830 stack<PAR_TAG> tag_state;
2831 // parsing main loop
2832 for (Paragraph::size_type i = 0; i < par->size(); ++i) {
2834 PAR_TAG tag_close = NONE;
2835 list < PAR_TAG > tag_open;
2837 LyXFont const font = par->getFont(params, i);
2839 if (font_old.family() != font.family()) {
2840 switch (family_type) {
2841 case LyXFont::SANS_FAMILY:
2844 case LyXFont::TYPEWRITER_FAMILY:
2851 family_type = font.family();
2853 switch (family_type) {
2854 case LyXFont::SANS_FAMILY:
2855 tag_open.push_back(SF);
2857 case LyXFont::TYPEWRITER_FAMILY:
2858 tag_open.push_back(TT);
2865 if (font_old.series() != font.series()) {
2866 switch (series_type) {
2867 case LyXFont::BOLD_SERIES:
2874 series_type = font.series();
2876 switch (series_type) {
2877 case LyXFont::BOLD_SERIES:
2878 tag_open.push_back(BF);
2886 if (font_old.shape() != font.shape()) {
2887 switch (shape_type) {
2888 case LyXFont::ITALIC_SHAPE:
2891 case LyXFont::SLANTED_SHAPE:
2898 shape_type = font.shape();
2900 switch (shape_type) {
2901 case LyXFont::ITALIC_SHAPE:
2902 tag_open.push_back(IT);
2904 case LyXFont::SLANTED_SHAPE:
2905 tag_open.push_back(SL);
2912 if (font_old.emph() != font.emph()) {
2913 if (font.emph() == LyXFont::ON) {
2914 tag_open.push_back(EM);
2923 list < PAR_TAG > temp;
2924 while(!tag_state.empty() && tag_close ) {
2925 PAR_TAG k = tag_state.top();
2927 os << "</" << tag_name(k) << ">";
2934 for(list< PAR_TAG >::const_iterator j = temp.begin();
2935 j != temp.end(); ++j) {
2937 os << "<" << tag_name(*j) << ">";
2940 for(list< PAR_TAG >::const_iterator j = tag_open.begin();
2941 j != tag_open.end(); ++j) {
2943 os << "<" << tag_name(*j) << ">";
2946 char c = par->getChar(i);
2948 if (c == Paragraph::META_INSET) {
2949 Inset * inset = par->getInset(i);
2950 inset->linuxdoc(this, os);
2955 if (style.latexparam() == "CDATA") {
2956 // "TeX"-Mode on == > SGML-Mode on.
2962 if (par->linuxDocConvertChar(c, sgml_string)
2963 && !style.free_spacing) {
2964 // in freespacing mode, spaces are
2965 // non-breaking characters
2966 if (desc_on) {// if char is ' ' then...
2969 linux_doc_line_break(os, char_line_count, 6);
2973 linux_doc_line_break(os, char_line_count, 1);
2978 char_line_count += sgml_string.length();
2984 while (!tag_state.empty()) {
2985 os << "</" << tag_name(tag_state.top()) << ">";
2989 // resets description flag correctly
2991 // <tag> not closed...
2992 linux_doc_line_break(os, char_line_count, 6);
2998 // Print an error message.
2999 void Buffer::linuxDocError(Paragraph * par, int pos,
3000 string const & message)
3002 // insert an error marker in text
3003 InsetError * new_inset = new InsetError(message);
3004 par->insertInset(pos, new_inset);
3008 void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
3010 ofstream ofs(fname.c_str());
3012 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
3016 Paragraph * par = paragraph;
3018 niceFile = nice; // this will be used by Insetincludes.
3020 LyXTextClass const & tclass =
3021 textclasslist.TextClass(params.textclass);
3023 LaTeXFeatures features(params, tclass.numLayouts());
3028 string top_element = textclasslist.LatexnameOfClass(params.textclass);
3031 string sgml_includedfiles = features.getIncludedFiles(fname);
3033 ofs << "<!doctype " << top_element
3034 << " public \"-//OASIS//DTD DocBook V3.1//EN\"";
3036 if (params.preamble.empty() && sgml_includedfiles.empty())
3039 ofs << "\n [ " << params.preamble
3040 << sgml_includedfiles << " \n]>\n\n";
3043 string top = top_element;
3045 top += params.language->code();
3048 if (!params.options.empty()) {
3050 top += params.options;
3052 sgmlOpenTag(ofs, 0, top);
3054 ofs << "<!-- DocBook file was created by " << LYX_DOCVERSION
3055 << "\n See http://www.lyx.org/ for more information -->\n";
3057 vector<string> environment_stack(10);
3058 vector<string> environment_inner(10);
3059 vector<string> command_stack(10);
3061 bool command_flag = false;
3062 Paragraph::depth_type command_depth = 0;
3063 Paragraph::depth_type command_base = 0;
3064 Paragraph::depth_type cmd_depth = 0;
3065 Paragraph::depth_type depth = 0; // paragraph depth
3068 string command_name;
3074 int desc_on = 0; // description mode
3076 LyXLayout const & style =
3077 textclasslist.Style(params.textclass,
3080 // environment tag closing
3081 for (; depth > par->params().depth(); --depth) {
3082 if (environment_inner[depth] != "!-- --") {
3083 item_name = "listitem";
3084 sgmlCloseTag(ofs, command_depth + depth,
3086 if (environment_inner[depth] == "varlistentry")
3087 sgmlCloseTag(ofs, depth+command_depth,
3088 environment_inner[depth]);
3090 sgmlCloseTag(ofs, depth + command_depth,
3091 environment_stack[depth]);
3092 environment_stack[depth].erase();
3093 environment_inner[depth].erase();
3096 if (depth == par->params().depth()
3097 && environment_stack[depth] != style.latexname()
3098 && !environment_stack[depth].empty()) {
3099 if (environment_inner[depth] != "!-- --") {
3100 item_name= "listitem";
3101 sgmlCloseTag(ofs, command_depth+depth,
3103 if (environment_inner[depth] == "varlistentry")
3105 depth + command_depth,
3106 environment_inner[depth]);
3109 sgmlCloseTag(ofs, depth + command_depth,
3110 environment_stack[depth]);
3112 environment_stack[depth].erase();
3113 environment_inner[depth].erase();
3116 // Write opening SGML tags.
3117 switch (style.latextype) {
3118 case LATEX_PARAGRAPH:
3119 sgmlOpenTag(ofs, depth + command_depth,
3125 linuxDocError(par, 0,
3126 _("Error : Wrong depth for "
3127 "LatexType Command.\n"));
3129 command_name = style.latexname();
3131 sgmlparam = style.latexparam();
3132 c_params = split(sgmlparam, c_depth,'|');
3134 cmd_depth = lyx::atoi(c_depth);
3137 if (cmd_depth < command_base) {
3138 for (Paragraph::depth_type j = command_depth; j >= command_base; --j)
3139 sgmlCloseTag(ofs, j, command_stack[j]);
3140 command_depth = command_base = cmd_depth;
3141 } else if (cmd_depth <= command_depth) {
3142 for (int j = command_depth; j >= int(cmd_depth); --j)
3143 sgmlCloseTag(ofs, j, command_stack[j]);
3144 command_depth = cmd_depth;
3146 command_depth = cmd_depth;
3148 command_depth = command_base = cmd_depth;
3149 command_flag = true;
3151 if (command_stack.size() == command_depth + 1)
3152 command_stack.push_back(string());
3153 command_stack[command_depth] = command_name;
3155 // treat label as a special case for
3156 // more WYSIWYM handling.
3157 if (par->getChar(0) == Paragraph::META_INSET) {
3158 Inset * inset = par->getInset(0);
3159 Inset::Code lyx_code = inset->lyxCode();
3160 if (lyx_code == Inset::LABEL_CODE){
3161 command_name += " id=\"";
3162 command_name += (static_cast<InsetCommand *>(inset))->getContents();
3163 command_name += "\"";
3168 sgmlOpenTag(ofs, depth + command_depth, command_name);
3169 if (c_params.empty())
3170 item_name = "title";
3172 item_name = c_params;
3173 sgmlOpenTag(ofs, depth + 1 + command_depth, item_name);
3176 case LATEX_ENVIRONMENT:
3177 case LATEX_ITEM_ENVIRONMENT:
3178 if (depth < par->params().depth()) {
3179 depth = par->params().depth();
3180 environment_stack[depth].erase();
3183 if (environment_stack[depth] != style.latexname()) {
3184 if(environment_stack.size() == depth + 1) {
3185 environment_stack.push_back("!-- --");
3186 environment_inner.push_back("!-- --");
3188 environment_stack[depth] = style.latexname();
3189 environment_inner[depth] = "!-- --";
3190 sgmlOpenTag(ofs, depth + command_depth,
3191 environment_stack[depth]);
3193 if (environment_inner[depth] != "!-- --") {
3194 item_name= "listitem";
3196 command_depth + depth,
3198 if (environment_inner[depth] == "varlistentry")
3200 depth + command_depth,
3201 environment_inner[depth]);
3205 if (style.latextype == LATEX_ENVIRONMENT) {
3206 if (!style.latexparam().empty()) {
3207 if(style.latexparam() == "CDATA")
3210 sgmlOpenTag(ofs, depth + command_depth,
3211 style.latexparam());
3216 desc_on = (style.labeltype == LABEL_MANUAL);
3219 environment_inner[depth]= "varlistentry";
3221 environment_inner[depth]= "listitem";
3223 sgmlOpenTag(ofs, depth + 1 + command_depth,
3224 environment_inner[depth]);
3228 sgmlOpenTag(ofs, depth + 1 + command_depth,
3232 sgmlOpenTag(ofs, depth + 1 + command_depth,
3237 sgmlOpenTag(ofs, depth + command_depth,
3243 simpleDocBookOnePar(ofs, extra_par, par, desc_on,
3244 depth + 1 + command_depth);
3248 // write closing SGML tags
3249 switch (style.latextype) {
3251 if (c_params.empty())
3255 sgmlCloseTag(ofs, depth + command_depth, end_tag);
3257 case LATEX_ENVIRONMENT:
3258 if (!style.latexparam().empty()) {
3259 if(style.latexparam() == "CDATA")
3262 sgmlCloseTag(ofs, depth + command_depth,
3263 style.latexparam());
3266 case LATEX_ITEM_ENVIRONMENT:
3267 if (desc_on == 1) break;
3269 sgmlCloseTag(ofs, depth + 1 + command_depth, end_tag);
3271 case LATEX_PARAGRAPH:
3272 sgmlCloseTag(ofs, depth + command_depth, style.latexname());
3275 sgmlCloseTag(ofs, depth + command_depth, style.latexname());
3281 for (int d = depth; d >= 0; --d) {
3282 if (!environment_stack[depth].empty()) {
3283 if (environment_inner[depth] != "!-- --") {
3284 item_name = "listitem";
3285 sgmlCloseTag(ofs, command_depth + depth,
3287 if (environment_inner[depth] == "varlistentry")
3288 sgmlCloseTag(ofs, depth + command_depth,
3289 environment_inner[depth]);
3292 sgmlCloseTag(ofs, depth + command_depth,
3293 environment_stack[depth]);
3297 for (int j = command_depth; j >= 0 ; --j)
3298 if (!command_stack[j].empty())
3299 sgmlCloseTag(ofs, j, command_stack[j]);
3302 sgmlCloseTag(ofs, 0, top_element);
3305 // How to check for successful close
3309 void Buffer::simpleDocBookOnePar(ostream & os, string & extra,
3310 Paragraph * par, int & desc_on,
3311 Paragraph::depth_type depth) const
3313 bool emph_flag = false;
3315 LyXLayout const & style = textclasslist.Style(params.textclass,
3318 LyXFont font_old = style.labeltype == LABEL_MANUAL ? style.labelfont : style.font;
3320 int char_line_count = depth;
3321 //if (!style.free_spacing)
3322 // os << string(depth,' ');
3324 // parsing main loop
3325 for (Paragraph::size_type i = 0;
3326 i < par->size(); ++i) {
3327 LyXFont font = par->getFont(params, i);
3329 // handle <emphasis> tag
3330 if (font_old.emph() != font.emph()) {
3331 if (font.emph() == LyXFont::ON) {
3335 os << "</emphasis>";
3340 char c = par->getChar(i);
3342 if (c == Paragraph::META_INSET) {
3343 Inset * inset = par->getInset(i);
3345 inset->docBook(this, ost);
3346 string tmp_out = ost.str().c_str();
3349 // This code needs some explanation:
3350 // Two insets are treated specially
3351 // label if it is the first element in a command paragraph
3353 // graphics inside tables or figure floats can't go on
3354 // title (the equivalente in latex for this case is caption
3355 // and title should come first
3358 if (desc_on!= 3 || i!= 0) {
3359 if (!tmp_out.empty() && tmp_out[0] == '@') {
3361 extra += frontStrip(tmp_out, '@');
3363 os << frontStrip(tmp_out, '@');
3370 if (par->linuxDocConvertChar(c, sgml_string)
3371 && !style.free_spacing) { // in freespacing
3373 // non-breaking characters
3377 os << "\n</term><listitem><para>";
3390 os << "</emphasis>";
3393 // resets description flag correctly
3395 // <term> not closed...
3398 if(style.free_spacing) os << '\n';
3402 // This should be enabled when the Chktex class is implemented. (Asger)
3403 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
3404 // Other flags: -wall -v0 -x
3405 int Buffer::runChktex()
3407 if (!users->text) return 0;
3409 users->owner()->prohibitInput();
3411 // get LaTeX-Filename
3412 string const name = getLatexName();
3413 string path = OnlyPath(filename);
3415 string const org_path = path;
3416 if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
3420 Path p(path); // path to LaTeX file
3421 users->owner()->message(_("Running chktex..."));
3423 // Remove all error insets
3424 bool const removedErrorInsets = users->removeAutoInsets();
3426 // Generate the LaTeX file if neccessary
3427 makeLaTeXFile(name, org_path, false);
3430 Chktex chktex(lyxrc.chktex_command, name, filepath);
3431 int res = chktex.run(terr); // run chktex
3434 WriteAlert(_("chktex did not work!"),
3435 _("Could not run with file:"), name);
3436 } else if (res > 0) {
3437 // Insert all errors as errors boxes
3438 users->insertErrors(terr);
3441 // if we removed error insets before we ran chktex or if we inserted
3442 // error insets after we ran chktex, this must be run:
3443 if (removedErrorInsets || res){
3447 users->owner()->allowInput();
3453 void Buffer::validate(LaTeXFeatures & features) const
3455 Paragraph * par = paragraph;
3456 LyXTextClass const & tclass =
3457 textclasslist.TextClass(params.textclass);
3459 // AMS Style is at document level
3460 features.amsstyle = (params.use_amsmath ||
3461 tclass.provides(LyXTextClass::amsmath));
3464 // We don't use "lyxerr.debug" because of speed. (Asger)
3465 if (lyxerr.debugging(Debug::LATEX))
3466 lyxerr << "Paragraph: " << par << endl;
3468 // Now just follow the list of paragraphs and run
3469 // validate on each of them.
3470 par->validate(features);
3472 // and then the next paragraph
3476 // the bullet shapes are buffer level not paragraph level
3477 // so they are tested here
3478 for (int i = 0; i < 4; ++i) {
3479 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
3480 int const font = params.user_defined_bullets[i].getFont();
3482 int const c = params
3483 .user_defined_bullets[i]
3490 features.latexsym = true;
3492 } else if (font == 1) {
3493 features.amssymb = true;
3494 } else if ((font >= 2 && font <= 5)) {
3495 features.pifont = true;
3500 if (lyxerr.debugging(Debug::LATEX)) {
3501 features.showStruct();
3506 void Buffer::setPaperStuff()
3508 params.papersize = BufferParams::PAPER_DEFAULT;
3509 char const c1 = params.paperpackage;
3510 if (c1 == BufferParams::PACKAGE_NONE) {
3511 char const c2 = params.papersize2;
3512 if (c2 == BufferParams::VM_PAPER_USLETTER)
3513 params.papersize = BufferParams::PAPER_USLETTER;
3514 else if (c2 == BufferParams::VM_PAPER_USLEGAL)
3515 params.papersize = BufferParams::PAPER_LEGALPAPER;
3516 else if (c2 == BufferParams::VM_PAPER_USEXECUTIVE)
3517 params.papersize = BufferParams::PAPER_EXECUTIVEPAPER;
3518 else if (c2 == BufferParams::VM_PAPER_A3)
3519 params.papersize = BufferParams::PAPER_A3PAPER;
3520 else if (c2 == BufferParams::VM_PAPER_A4)
3521 params.papersize = BufferParams::PAPER_A4PAPER;
3522 else if (c2 == BufferParams::VM_PAPER_A5)
3523 params.papersize = BufferParams::PAPER_A5PAPER;
3524 else if ((c2 == BufferParams::VM_PAPER_B3) || (c2 == BufferParams::VM_PAPER_B4) ||
3525 (c2 == BufferParams::VM_PAPER_B5))
3526 params.papersize = BufferParams::PAPER_B5PAPER;
3527 } else if ((c1 == BufferParams::PACKAGE_A4) || (c1 == BufferParams::PACKAGE_A4WIDE) ||
3528 (c1 == BufferParams::PACKAGE_WIDEMARGINSA4))
3529 params.papersize = BufferParams::PAPER_A4PAPER;
3533 // This function should be in Buffer because it's a buffer's property (ale)
3534 string const Buffer::getIncludeonlyList(char delim)
3537 for (inset_iterator it = inset_iterator_begin();
3538 it != inset_iterator_end(); ++it) {
3539 if ((*it)->lyxCode() == Inset::INCLUDE_CODE) {
3540 InsetInclude * insetinc =
3541 static_cast<InsetInclude *>(*it);
3542 if (insetinc->isIncludeOnly()) {
3545 lst += insetinc->getRelFileBaseName();
3549 lyxerr[Debug::INFO] << "Includeonly(" << lst << ')' << endl;
3554 vector<string> const Buffer::getLabelList()
3556 /// if this is a child document and the parent is already loaded
3557 /// Use the parent's list instead [ale990407]
3558 if (!params.parentname.empty()
3559 && bufferlist.exists(params.parentname)) {
3560 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3562 return tmp->getLabelList();
3565 vector<string> label_list;
3566 for (inset_iterator it = inset_iterator_begin();
3567 it != inset_iterator_end(); ++it) {
3568 vector<string> const l = (*it)->getLabelList();
3569 label_list.insert(label_list.end(), l.begin(), l.end());
3575 Buffer::Lists const Buffer::getLists() const
3578 Paragraph * par = paragraph;
3580 LyXTextClassList::size_type cap;
3581 boost::tie(found, cap) = textclasslist
3582 .NumberOfLayout(params.textclass, "Caption");
3585 char const labeltype =
3586 textclasslist.Style(params.textclass,
3587 par->getLayout()).labeltype;
3589 if (labeltype >= LABEL_COUNTER_CHAPTER
3590 && labeltype <= LABEL_COUNTER_CHAPTER + params.tocdepth) {
3591 // insert this into the table of contents
3592 SingleList & item = l["TOC"];
3595 textclasslist.TextClass(params.textclass).maxcounter());
3596 item.push_back(TocItem(par, depth, par->asString(this, true)));
3598 // For each paragrph, traverse its insets and look for
3602 Paragraph::inset_iterator it =
3603 par->inset_iterator_begin();
3604 Paragraph::inset_iterator end =
3605 par->inset_iterator_end();
3607 for (; it != end; ++it) {
3608 if ((*it)->lyxCode() == Inset::FLOAT_CODE) {
3610 static_cast<InsetFloat*>(*it);
3612 string const type = il->type();
3614 // Now find the caption in the float...
3615 // We now tranverse the paragraphs of
3617 Paragraph * tmp = il->inset.paragraph();
3619 if (tmp->layout == cap) {
3620 SingleList & item = l[type];
3622 tostr(item.size()+1) + ". " + tmp->asString(this, false);
3623 item.push_back(TocItem(tmp, 0 , str));
3630 lyxerr << "caption not found" << endl;
3639 // This is also a buffer property (ale)
3640 vector<pair<string, string> > const Buffer::getBibkeyList()
3642 /// if this is a child document and the parent is already loaded
3643 /// Use the parent's list instead [ale990412]
3644 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3645 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3647 return tmp->getBibkeyList();
3650 vector<pair<string, string> > keys;
3651 Paragraph * par = paragraph;
3654 keys.push_back(pair<string, string>(par->bibkey->getContents(),
3655 par->asString(this, false)));
3659 // Might be either using bibtex or a child has bibliography
3661 for (inset_iterator it = inset_iterator_begin();
3662 it != inset_iterator_end(); ++it) {
3663 // Search for Bibtex or Include inset
3664 if ((*it)->lyxCode() == Inset::BIBTEX_CODE) {
3665 vector<pair<string,string> > tmp =
3666 static_cast<InsetBibtex*>(*it)->getKeys(this);
3667 keys.insert(keys.end(), tmp.begin(), tmp.end());
3668 } else if ((*it)->lyxCode() == Inset::INCLUDE_CODE) {
3669 vector<pair<string,string> > const tmp =
3670 static_cast<InsetInclude*>(*it)->getKeys();
3671 keys.insert(keys.end(), tmp.begin(), tmp.end());
3680 bool Buffer::isDepClean(string const & name) const
3682 DEPCLEAN * item = dep_clean;
3683 while (item && item->master != name)
3685 if (!item) return true;
3690 void Buffer::markDepClean(string const & name)
3693 dep_clean = new DEPCLEAN;
3694 dep_clean->clean = true;
3695 dep_clean->master = name;
3696 dep_clean->next = 0;
3698 DEPCLEAN * item = dep_clean;
3699 while (item && item->master != name)
3704 item = new DEPCLEAN;
3706 item->master = name;
3713 bool Buffer::dispatch(string const & command)
3715 // Split command string into command and argument
3717 string line = frontStrip(command);
3718 string const arg = strip(frontStrip(split(line, cmd, ' ')));
3720 return dispatch(lyxaction.LookupFunc(cmd), arg);
3724 bool Buffer::dispatch(int action, string const & argument)
3726 bool dispatched = true;
3729 Exporter::Export(this, argument, false);
3739 void Buffer::resizeInsets(BufferView * bv)
3741 /// then remove all LyXText in text-insets
3742 Paragraph * par = paragraph;
3743 for (; par; par = par->next()) {
3744 par->resizeInsetsLyXText(bv);
3749 void Buffer::redraw()
3756 void Buffer::changeLanguage(Language const * from, Language const * to)
3759 ParIterator end = par_iterator_end();
3760 for (ParIterator it = par_iterator_begin(); it != end; ++it)
3761 (*it)->changeLanguage(params, from, to);
3765 bool Buffer::isMultiLingual()
3767 ParIterator end = par_iterator_end();
3768 for (ParIterator it = par_iterator_begin(); it != end; ++it)
3769 if ((*it)->isMultiLingual(params))
3776 Buffer::inset_iterator::inset_iterator(Paragraph * paragraph,
3777 Paragraph::size_type pos)
3780 it = par->InsetIterator(pos);
3781 if (it == par->inset_iterator_end()) {
3788 void Buffer::inset_iterator::setParagraph()
3791 it = par->inset_iterator_begin();
3792 if (it != par->inset_iterator_end())
3797 // We maintain an invariant that whenever par = 0 then it = 0
3801 Inset * Buffer::getInsetFromID(int id_arg) const
3803 for (inset_iterator it = inset_const_iterator_begin();
3804 it != inset_const_iterator_end(); ++it)
3806 if ((*it)->id() == id_arg)
3808 Inset * in = (*it)->getInsetFromID(id_arg);
3816 Paragraph * Buffer::getParFromID(int id) const
3818 if (id < 0) return 0;
3819 Paragraph * par = paragraph;
3821 if (par->id() == id) {
3824 Paragraph * tmp = par->getParFromID(id);
3834 ParIterator Buffer::par_iterator_begin()
3836 return ParIterator(paragraph);
3840 ParIterator Buffer::par_iterator_end()
3842 return ParIterator();