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>
36 #pragma implementation
40 #include "bufferlist.h"
42 #include "lyx_gui_misc.h"
43 #include "LyXAction.h"
46 #include "tex-strings.h"
48 #include "bufferview_funcs.h"
51 #include "mathed/formulamacro.h"
52 #include "mathed/formula.h"
53 #include "insets/inset.h"
54 #include "insets/inseterror.h"
55 #include "insets/insetlabel.h"
56 #include "insets/insetref.h"
57 #include "insets/inseturl.h"
58 #include "insets/insetnote.h"
59 #include "insets/insetquotes.h"
60 #include "insets/insetlatexaccent.h"
61 #include "insets/insetbib.h"
62 #include "insets/insetcite.h"
63 #include "insets/insetexternal.h"
64 #include "insets/insetindex.h"
65 #include "insets/insetinclude.h"
66 #include "insets/insettoc.h"
67 #include "insets/insetparent.h"
68 #include "insets/insetspecialchar.h"
69 #include "insets/figinset.h"
70 #include "insets/insettext.h"
71 #include "insets/insetert.h"
72 #include "insets/insetgraphics.h"
73 #include "insets/insetfoot.h"
74 #include "insets/insetmarginal.h"
75 #include "insets/insetminipage.h"
76 #include "insets/insetfloat.h"
77 #include "insets/insettabular.h"
79 #include "insets/insettheorem.h"
80 #include "insets/insetlist.h"
82 #include "insets/insetcaption.h"
83 #include "insets/insetfloatlist.h"
84 #include "support/textutils.h"
85 #include "support/filetools.h"
86 #include "support/path.h"
87 #include "support/os.h"
92 #include "LaTeXFeatures.h"
93 #include "support/syscall.h"
94 #include "support/lyxlib.h"
95 #include "support/FileInfo.h"
96 #include "support/lyxmanip.h"
100 #include "lyx_gui_misc.h" // WarnReadonly()
101 #include "frontends/Dialogs.h"
102 #include "encoding.h"
103 #include "exporter.h"
104 #include "Lsstream.h"
105 #include "converter.h"
106 #include "BufferView.h"
107 #include "ParagraphParameters.h"
108 #include "iterators.h"
118 using std::make_pair;
126 // all these externs should eventually be removed.
127 extern BufferList bufferlist;
129 extern LyXAction lyxaction;
133 const int LYX_FORMAT = 220;
137 extern int tex_code_break_column;
140 Buffer::Buffer(string const & file, bool ronly)
142 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
144 filepath = OnlyPath(file);
153 if (read_only || (lyxrc.use_tempdir)) {
154 tmppath = CreateBufferTmpDir();
155 } else tmppath.erase();
161 lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
162 // here the buffer should take care that it is
163 // saved properly, before it goes into the void.
165 // make sure that views using this buffer
170 if (!tmppath.empty()) {
171 DestroyBufferTmpDir(tmppath);
174 Paragraph * par = paragraph;
177 tmppar = par->next();
185 string const Buffer::getLatexName(bool no_path) const
187 string name = ChangeExtension(MakeLatexName(filename), ".tex");
189 return OnlyFilename(name);
195 pair<Buffer::LogType, string> const Buffer::getLogName(void) const
197 string const filename = getLatexName(false);
199 if (filename.empty())
200 return make_pair(Buffer::latexlog, string());
202 string path = OnlyPath(filename);
204 if (lyxrc.use_tempdir || !IsDirWriteable(path))
207 string const fname = AddName(path,
208 OnlyFilename(ChangeExtension(filename,
211 AddName(path, OnlyFilename(
212 ChangeExtension(filename,
213 formats.extension("literate") + ".out")));
215 // If no Latex log or Build log is newer, show Build log
217 FileInfo const f_fi(fname);
218 FileInfo const b_fi(bname);
221 (!f_fi.exist() || f_fi.getModificationTime() < b_fi.getModificationTime())) {
222 lyxerr[Debug::FILES] << "Log name calculated as : " << bname << endl;
223 return make_pair(Buffer::buildlog, bname);
225 lyxerr[Debug::FILES] << "Log name calculated as : " << fname << endl;
226 return make_pair(Buffer::latexlog, fname);
230 void Buffer::setReadonly(bool flag)
232 if (read_only != flag) {
235 users->owner()->getDialogs()->updateBufferDependent(false);
238 WarnReadonly(filename);
243 bool Buffer::saveParamsAsDefaults() // const
245 string const fname = AddName(AddPath(user_lyxdir, "templates/"),
247 Buffer defaults = Buffer(fname);
249 // Use the current buffer's parameters as default
250 defaults.params = params;
252 // add an empty paragraph. Is this enough?
253 defaults.paragraph = new Paragraph;
255 return defaults.writeFile(defaults.filename, false);
259 /// Update window titles of all users
260 // Should work on a list
261 void Buffer::updateTitles() const
263 if (users) users->owner()->updateWindowTitle();
267 /// Reset autosave timer of all users
268 // Should work on a list
269 void Buffer::resetAutosaveTimers() const
271 if (users) users->owner()->resetAutosaveTimer();
275 void Buffer::setFileName(string const & newfile)
277 filename = MakeAbsPath(newfile);
278 filepath = OnlyPath(filename);
279 setReadonly(IsFileWriteable(filename) == 0);
284 // We'll remove this later. (Lgb)
287 string last_inset_read;
289 #ifndef NO_COMPABILITY
292 ErtComp() : active(false), in_tabular(false) {
299 std::stack<ErtComp> ert_stack;
303 #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)
320 #ifndef NO_COMPABILITY
321 ert_comp.contents.erase();
322 ert_comp.active = false;
323 ert_comp.in_tabular = false;
326 Paragraph::depth_type depth = 0;
327 bool the_end_read = false;
329 Paragraph * first_par = 0;
330 LyXFont font(LyXFont::ALL_INHERIT, params.language);
331 if (file_format < 216 && params.language->lang() == "hebrew")
332 font.setLanguage(default_language);
337 // We are inserting into an existing document
338 users->text->breakParagraph(users);
339 first_par = users->text->firstParagraph();
342 // We don't want to adopt the parameters from the
343 // document we insert, so we skip until the text begins:
346 string const pretoken = lex.getString();
347 if (pretoken == "\\layout") {
348 lex.pushToken(pretoken);
356 string const token = lex.getString();
358 if (token.empty()) continue;
360 lyxerr[Debug::PARSER] << "Handling token: `"
361 << token << "'" << endl;
364 parseSingleLyXformat2Token(lex, par, first_par,
372 paragraph = first_par;
374 if (unknown_layouts > 0) {
375 string s = _("Couldn't set the layout for ");
376 if (unknown_layouts == 1) {
377 s += _("one paragraph");
379 s += tostr(unknown_layouts);
380 s += _(" paragraphs");
382 WriteAlert(_("Textclass Loading Error!"), s,
383 _("When reading " + fileName()));
390 #ifndef NO_COMPABILITY
391 void Buffer::insertErtContents(Paragraph * par, int & pos,
392 LyXFont const & font, bool set_inactive)
394 if (!ert_comp.contents.empty()) {
395 lyxerr[Debug::INSETS] << "ERT contents:\n"
396 << ert_comp.contents << endl;
397 Inset * inset = new InsetERT(ert_comp.contents, true);
398 par->insertInset(pos++, inset, font);
399 ert_comp.contents.erase();
402 ert_comp.active = false;
409 Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
410 Paragraph *& first_par,
411 string const & token, int & pos,
412 Paragraph::depth_type & depth,
416 bool the_end_read = false;
417 #ifndef NO_COMPABILITY
418 #ifndef NO_PEXTRA_REALLY
419 // This is super temporary but is needed to get the compability
420 // mode for minipages work correctly together with new tabulars.
421 static int call_depth;
423 bool checkminipage = false;
424 static Paragraph * minipar;
425 static Paragraph * parBeforeMinipage;
428 if (token[0] != '\\') {
429 #ifndef NO_COMPABILITY
430 if (ert_comp.active) {
431 ert_comp.contents += token;
434 for (string::const_iterator cit = token.begin();
435 cit != token.end(); ++cit) {
436 par->insertChar(pos, (*cit), font);
439 #ifndef NO_COMPABILITY
442 } else if (token == "\\i") {
443 Inset * inset = new InsetLatexAccent;
444 inset->read(this, lex);
445 par->insertInset(pos, inset, font);
447 } else if (token == "\\layout") {
448 #ifndef NO_COMPABILITY
449 ert_comp.in_tabular = false;
451 insertErtContents(par, pos, font);
454 string const layoutname = lex.getString();
455 pair<bool, LyXTextClass::LayoutList::size_type> pp
456 = textclasslist.NumberOfLayout(params.textclass,
459 #ifndef NO_COMPABILITY
460 if (compare_no_case(layoutname, "latex") == 0) {
461 ert_comp.active = true;
465 // The is the compability reading of layout caption.
466 // It can be removed in LyX version 1.3.0. (Lgb)
467 if (compare_no_case(layoutname, "caption") == 0) {
468 // We expect that the par we are now working on is
469 // really inside a InsetText inside a InsetFloat.
470 // We also know that captions can only be
471 // one paragraph. (Lgb)
473 // We should now read until the next "\layout"
475 // This is probably not good enough, what if the
476 // caption is the last par in the document (Lgb)
477 istream & ist = lex.getStream();
483 if (prefixIs(line, "\\layout")) {
487 if (prefixIs(line, "\\begin_inset"))
489 if (prefixIs(line, "\\end_inset")) {
500 // Now we should have the whole layout in ss
501 // we should now be able to give this to the
503 ss << "\\end_inset\n";
505 // This seems like a bug in stringstream.
506 // We really should be able to use ss
508 istringstream is(ss.str());
510 tmplex.setStream(is);
511 Inset * inset = new InsetCaption;
512 inset->Read(this, tmplex);
513 par->InsertInset(pos, inset, font);
520 par = new Paragraph(par);
524 par->layout = pp.second;
525 #ifndef NO_COMPABILITY
526 } else if (ert_comp.active) {
531 // use default layout "Standard" (0)
534 string const s = _("Layout had to be changed from\n")
535 + layoutname + _(" to ")
536 + textclasslist.NameOfLayout(params.textclass, par->layout);
537 InsetError * new_inset = new InsetError(s);
538 par->insertInset(0, new_inset);
540 // Test whether the layout is obsolete.
541 LyXLayout const & layout =
542 textclasslist.Style(params.textclass,
544 if (!layout.obsoleted_by().empty())
545 par->layout = textclasslist
546 .NumberOfLayout(params.textclass,
547 layout.obsoleted_by())
549 par->params().depth(depth);
550 font = LyXFont(LyXFont::ALL_INHERIT, params.language);
551 if (file_format < 216
552 && params.language->lang() == "hebrew")
553 font.setLanguage(default_language);
558 #ifndef NO_COMPABILITY
559 } else if (token == "\\begin_float") {
560 insertErtContents(par, pos, font);
561 //insertErtContents(par, pos, font, false);
562 //ert_stack.push(ert_comp);
563 //ert_comp = ErtComp();
565 // This is the compability reader. It can be removed in
566 // LyX version 1.3.0. (Lgb)
568 string const tmptok = lex.getString();
569 //lyxerr << "old float: " << tmptok << endl;
572 stringstream old_float;
574 if (tmptok == "footnote") {
575 inset = new InsetFoot;
576 old_float << "collapsed true\n";
577 } else if (tmptok == "margin") {
578 inset = new InsetMarginal;
579 old_float << "collapsed true\n";
580 } else if (tmptok == "fig") {
581 inset = new InsetFloat("figure");
582 old_float << "placement htbp\n"
584 << "collapsed false\n";
585 } else if (tmptok == "tab") {
586 inset = new InsetFloat("table");
587 old_float << "placement htbp\n"
589 << "collapsed false\n";
590 } else if (tmptok == "alg") {
591 inset = new InsetFloat("algorithm");
592 old_float << "placement htbp\n"
594 << "collapsed false\n";
595 } else if (tmptok == "wide-fig") {
596 inset = new InsetFloat("figure");
597 //InsetFloat * tmp = new InsetFloat("figure");
600 old_float << "placement htbp\n"
602 << "collapsed false\n";
603 } else if (tmptok == "wide-tab") {
604 inset = new InsetFloat("table");
605 //InsetFloat * tmp = new InsetFloat("table");
608 old_float << "placement htbp\n"
610 << "collapsed false\n";
614 #ifndef NO_PEXTRA_REALLY
617 return false; // no end read yet
620 // Here we need to check for \end_deeper and handle that
621 // before we do the footnote parsing.
622 // This _is_ a hack! (Lgb)
625 string const tmp = lex.getString();
626 if (tmp == "\\end_deeper") {
627 //lyxerr << "\\end_deeper caught!" << endl;
629 lex.printError("\\end_deeper: "
630 "depth is already null");
635 old_float << tmp << ' ';
640 old_float << lex.getLongString("\\end_float")
641 << "\n\\end_inset\n";
642 //lyxerr << "Float Body:\n" << old_float.str() << endl;
643 // That this does not work seems like a bug
644 // in stringstream. (Lgb)
645 istringstream istr(old_float.str());
647 nylex.setStream(istr);
648 inset->read(this, nylex);
649 par->insertInset(pos, inset, font);
651 insertErtContents(par, pos, font);
653 } else if (token == "\\begin_deeper") {
655 } else if (token == "\\end_deeper") {
657 lex.printError("\\end_deeper: "
658 "depth is already null");
662 } else if (token == "\\begin_preamble") {
663 params.readPreamble(lex);
664 } else if (token == "\\textclass") {
666 pair<bool, LyXTextClassList::size_type> pp =
667 textclasslist.NumberOfClass(lex.getString());
669 params.textclass = pp.second;
671 WriteAlert(string(_("Textclass error")),
672 string(_("The document uses an unknown textclass \"")) +
673 lex.getString() + string("\"."),
674 string(_("LyX will not be able to produce output correctly.")));
675 params.textclass = 0;
677 if (!textclasslist.Load(params.textclass)) {
678 // if the textclass wasn't loaded properly
679 // we need to either substitute another
680 // or stop loading the file.
681 // I can substitute but I don't see how I can
682 // stop loading... ideas?? ARRae980418
683 WriteAlert(_("Textclass Loading Error!"),
684 string(_("Can't load textclass ")) +
685 textclasslist.NameOfClass(params.textclass),
686 _("-- substituting default"));
687 params.textclass = 0;
689 } else if (token == "\\options") {
691 params.options = lex.getString();
692 } else if (token == "\\language") {
693 params.readLanguage(lex);
694 } else if (token == "\\fontencoding") {
696 } else if (token == "\\inputencoding") {
698 params.inputenc = lex.getString();
699 } else if (token == "\\graphics") {
700 params.readGraphicsDriver(lex);
701 } else if (token == "\\fontscheme") {
703 params.fonts = lex.getString();
704 } else if (token == "\\noindent") {
705 par->params().noindent(true);
706 } else if (token == "\\fill_top") {
707 par->params().spaceTop(VSpace(VSpace::VFILL));
708 } else if (token == "\\fill_bottom") {
709 par->params().spaceBottom(VSpace(VSpace::VFILL));
710 } else if (token == "\\line_top") {
711 par->params().lineTop(true);
712 } else if (token == "\\line_bottom") {
713 par->params().lineBottom(true);
714 } else if (token == "\\pagebreak_top") {
715 par->params().pagebreakTop(true);
716 } else if (token == "\\pagebreak_bottom") {
717 par->params().pagebreakBottom(true);
718 } else if (token == "\\start_of_appendix") {
719 par->params().startOfAppendix(true);
720 } else if (token == "\\paragraph_separation") {
721 int tmpret = lex.findToken(string_paragraph_separation);
722 if (tmpret == -1) ++tmpret;
723 if (tmpret != LYX_LAYOUT_DEFAULT)
724 params.paragraph_separation =
725 static_cast<BufferParams::PARSEP>(tmpret);
726 } else if (token == "\\defskip") {
728 params.defskip = VSpace(lex.getString());
729 } else if (token == "\\epsfig") { // obsolete
730 // Indeed it is obsolete, but we HAVE to be backwards
731 // compatible until 0.14, because otherwise all figures
732 // in existing documents are irretrivably lost. (Asger)
733 params.readGraphicsDriver(lex);
734 } else if (token == "\\quotes_language") {
735 int tmpret = lex.findToken(string_quotes_language);
736 if (tmpret == -1) ++tmpret;
737 if (tmpret != LYX_LAYOUT_DEFAULT) {
738 InsetQuotes::quote_language tmpl =
739 InsetQuotes::EnglishQ;
742 tmpl = InsetQuotes::EnglishQ;
745 tmpl = InsetQuotes::SwedishQ;
748 tmpl = InsetQuotes::GermanQ;
751 tmpl = InsetQuotes::PolishQ;
754 tmpl = InsetQuotes::FrenchQ;
757 tmpl = InsetQuotes::DanishQ;
760 params.quotes_language = tmpl;
762 } else if (token == "\\quotes_times") {
764 switch (lex.getInteger()) {
766 params.quotes_times = InsetQuotes::SingleQ;
769 params.quotes_times = InsetQuotes::DoubleQ;
772 } else if (token == "\\papersize") {
773 int tmpret = lex.findToken(string_papersize);
777 params.papersize2 = tmpret;
778 } else if (token == "\\paperpackage") {
779 int tmpret = lex.findToken(string_paperpackages);
782 params.paperpackage = BufferParams::PACKAGE_NONE;
784 params.paperpackage = tmpret;
785 } else if (token == "\\use_geometry") {
787 params.use_geometry = lex.getInteger();
788 } else if (token == "\\use_amsmath") {
790 params.use_amsmath = lex.getInteger();
791 } else if (token == "\\use_natbib") {
793 params.use_natbib = lex.getInteger();
794 } else if (token == "\\use_numerical_citations") {
796 params.use_numerical_citations = lex.getInteger();
797 } else if (token == "\\paperorientation") {
798 int tmpret = lex.findToken(string_orientation);
799 if (tmpret == -1) ++tmpret;
800 if (tmpret != LYX_LAYOUT_DEFAULT)
801 params.orientation = static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
802 } else if (token == "\\paperwidth") {
804 params.paperwidth = lex.getString();
805 } else if (token == "\\paperheight") {
807 params.paperheight = lex.getString();
808 } else if (token == "\\leftmargin") {
810 params.leftmargin = lex.getString();
811 } else if (token == "\\topmargin") {
813 params.topmargin = lex.getString();
814 } else if (token == "\\rightmargin") {
816 params.rightmargin = lex.getString();
817 } else if (token == "\\bottommargin") {
819 params.bottommargin = lex.getString();
820 } else if (token == "\\headheight") {
822 params.headheight = lex.getString();
823 } else if (token == "\\headsep") {
825 params.headsep = lex.getString();
826 } else if (token == "\\footskip") {
828 params.footskip = lex.getString();
829 } else if (token == "\\paperfontsize") {
831 params.fontsize = strip(lex.getString());
832 } else if (token == "\\papercolumns") {
834 params.columns = lex.getInteger();
835 } else if (token == "\\papersides") {
837 switch (lex.getInteger()) {
839 case 1: params.sides = LyXTextClass::OneSide; break;
840 case 2: params.sides = LyXTextClass::TwoSides; break;
842 } else if (token == "\\paperpagestyle") {
844 params.pagestyle = strip(lex.getString());
845 } else if (token == "\\bullet") {
847 int const index = lex.getInteger();
849 int temp_int = lex.getInteger();
850 params.user_defined_bullets[index].setFont(temp_int);
851 params.temp_bullets[index].setFont(temp_int);
853 temp_int = lex.getInteger();
854 params.user_defined_bullets[index].setCharacter(temp_int);
855 params.temp_bullets[index].setCharacter(temp_int);
857 temp_int = lex.getInteger();
858 params.user_defined_bullets[index].setSize(temp_int);
859 params.temp_bullets[index].setSize(temp_int);
861 string const temp_str = lex.getString();
862 if (temp_str != "\\end_bullet") {
863 // this element isn't really necessary for
864 // parsing but is easier for humans
865 // to understand bullets. Put it back and
866 // set a debug message?
867 lex.printError("\\end_bullet expected, got" + temp_str);
868 //how can I put it back?
870 } else if (token == "\\bulletLaTeX") {
872 int const index = lex.getInteger();
874 string temp_str = lex.getString();
876 while (temp_str != "\\end_bullet") {
877 // this loop structure is needed when user
878 // enters an empty string since the first
879 // thing returned will be the \\end_bullet
881 // if the LaTeX entry has spaces. Each element
882 // therefore needs to be read in turn
885 temp_str = lex.getString();
887 params.user_defined_bullets[index].setText(sum_str);
888 params.temp_bullets[index].setText(sum_str);
889 } else if (token == "\\secnumdepth") {
891 params.secnumdepth = lex.getInteger();
892 } else if (token == "\\tocdepth") {
894 params.tocdepth = lex.getInteger();
895 } else if (token == "\\spacing") {
897 string const tmp = strip(lex.getString());
898 Spacing::Space tmp_space = Spacing::Default;
900 if (tmp == "single") {
901 tmp_space = Spacing::Single;
902 } else if (tmp == "onehalf") {
903 tmp_space = Spacing::Onehalf;
904 } else if (tmp == "double") {
905 tmp_space = Spacing::Double;
906 } else if (tmp == "other") {
908 tmp_space = Spacing::Other;
909 tmp_val = lex.getFloat();
911 lex.printError("Unknown spacing token: '$$Token'");
913 // Small hack so that files written with klyx will be
916 par->params().spacing(Spacing(tmp_space, tmp_val));
918 params.spacing.set(tmp_space, tmp_val);
920 } else if (token == "\\paragraph_spacing") {
922 string const tmp = strip(lex.getString());
923 if (tmp == "single") {
924 par->params().spacing(Spacing(Spacing::Single));
925 } else if (tmp == "onehalf") {
926 par->params().spacing(Spacing(Spacing::Onehalf));
927 } else if (tmp == "double") {
928 par->params().spacing(Spacing(Spacing::Double));
929 } else if (tmp == "other") {
931 par->params().spacing(Spacing(Spacing::Other,
934 lex.printError("Unknown spacing token: '$$Token'");
936 } else if (token == "\\float_placement") {
938 params.float_placement = lex.getString();
939 } else if (token == "\\family") {
941 font.setLyXFamily(lex.getString());
942 } else if (token == "\\series") {
944 font.setLyXSeries(lex.getString());
945 } else if (token == "\\shape") {
947 font.setLyXShape(lex.getString());
948 } else if (token == "\\size") {
950 font.setLyXSize(lex.getString());
951 #ifndef NO_COMPABILITY
952 } else if (token == "\\latex") {
954 string const tok = lex.getString();
955 if (tok == "no_latex") {
957 insertErtContents(par, pos, font);
958 } else if (tok == "latex") {
959 ert_comp.active = true;
960 } else if (tok == "default") {
962 insertErtContents(par, pos, font);
964 lex.printError("Unknown LaTeX font flag "
968 } else if (token == "\\lang") {
970 string const tok = lex.getString();
971 Language const * lang = languages.getLanguage(tok);
973 font.setLanguage(lang);
975 font.setLanguage(params.language);
976 lex.printError("Unknown language `$$Token'");
978 } else if (token == "\\numeric") {
980 font.setNumber(font.setLyXMisc(lex.getString()));
981 } else if (token == "\\emph") {
983 font.setEmph(font.setLyXMisc(lex.getString()));
984 } else if (token == "\\bar") {
986 string const tok = lex.getString();
987 // This is dirty, but gone with LyX3. (Asger)
989 font.setUnderbar(LyXFont::ON);
990 else if (tok == "no")
991 font.setUnderbar(LyXFont::OFF);
992 else if (tok == "default")
993 font.setUnderbar(LyXFont::INHERIT);
995 lex.printError("Unknown bar font flag "
997 } else if (token == "\\noun") {
999 font.setNoun(font.setLyXMisc(lex.getString()));
1000 } else if (token == "\\color") {
1002 font.setLyXColor(lex.getString());
1003 } else if (token == "\\align") {
1004 int tmpret = lex.findToken(string_align);
1005 if (tmpret == -1) ++tmpret;
1006 if (tmpret != LYX_LAYOUT_DEFAULT) { // tmpret != 99 ???
1007 int const tmpret2 = int(pow(2.0, tmpret));
1008 //lyxerr << "Tmpret2 = " << tmpret2 << endl;
1009 par->params().align(LyXAlignment(tmpret2));
1011 } else if (token == "\\added_space_top") {
1013 par->params().spaceTop(VSpace(lex.getString()));
1014 } else if (token == "\\added_space_bottom") {
1016 par->params().spaceBottom(VSpace(lex.getString()));
1017 #ifndef NO_COMPABILITY
1018 #ifndef NO_PEXTRA_REALLY
1019 } else if (token == "\\pextra_type") {
1021 par->params().pextraType(lex.getInteger());
1022 } else if (token == "\\pextra_width") {
1024 par->params().pextraWidth(lex.getString());
1025 } else if (token == "\\pextra_widthp") {
1027 par->params().pextraWidthp(lex.getString());
1028 } else if (token == "\\pextra_alignment") {
1030 par->params().pextraAlignment(lex.getInteger());
1031 } else if (token == "\\pextra_hfill") {
1033 par->params().pextraHfill(lex.getInteger());
1034 } else if (token == "\\pextra_start_minipage") {
1036 par->params().pextraStartMinipage(lex.getInteger());
1039 } else if (token == "\\labelwidthstring") {
1041 par->params().labelWidthString(lex.getString());
1042 // do not delete this token, it is still needed!
1043 } else if (token == "\\end_inset") {
1044 lyxerr << "Solitary \\end_inset. Missing \\begin_inset?.\n"
1045 << "Last inset read was: " << last_inset_read
1047 // Simply ignore this. The insets do not have
1049 // But insets should read it, it is a part of
1050 // the inset isn't it? Lgb.
1051 } else if (token == "\\begin_inset") {
1052 #ifndef NO_COMPABILITY
1053 insertErtContents(par, pos, font, false);
1054 ert_stack.push(ert_comp);
1055 ert_comp = ErtComp();
1057 readInset(lex, par, pos, font);
1058 #ifndef NO_COMPABILITY
1059 ert_comp = ert_stack.top();
1061 insertErtContents(par, pos, font);
1063 } else if (token == "\\SpecialChar") {
1064 LyXLayout const & layout =
1065 textclasslist.Style(params.textclass,
1068 // Insets don't make sense in a free-spacing context! ---Kayvan
1069 if (layout.free_spacing) {
1072 string next_token = lex.getString();
1073 if (next_token == "\\-") {
1074 par->insertChar(pos, '-', font);
1075 } else if (next_token == "\\protected_separator"
1076 || next_token == "~") {
1077 par->insertChar(pos, ' ', font);
1079 lex.printError("Token `$$Token' "
1081 "paragraph layout!");
1086 Inset * inset = new InsetSpecialChar;
1087 inset->read(this, lex);
1088 par->insertInset(pos, inset, font);
1091 } else if (token == "\\newline") {
1092 #ifndef NO_COMPABILITY
1093 if (!ert_comp.in_tabular && ert_comp.active) {
1094 ert_comp.contents += char(Paragraph::META_NEWLINE);
1096 // Since we cannot know it this is only a regular
1097 // newline or a tabular cell delimter we have to
1098 // handle the ERT here.
1099 insertErtContents(par, pos, font, false);
1101 par->insertChar(pos, Paragraph::META_NEWLINE, font);
1105 par->insertChar(pos, Paragraph::META_NEWLINE, font);
1108 } else if (token == "\\LyXTable") {
1109 #ifndef NO_COMPABILITY
1110 ert_comp.in_tabular = true;
1112 Inset * inset = new InsetTabular(*this);
1113 inset->read(this, lex);
1114 par->insertInset(pos, inset, font);
1116 } else if (token == "\\hfill") {
1117 par->insertChar(pos, Paragraph::META_HFILL, font);
1119 } else if (token == "\\protected_separator") { // obsolete
1120 // This is a backward compability thingie. (Lgb)
1121 // Remove it later some time...introduced with fileformat
1123 LyXLayout const & layout =
1124 textclasslist.Style(params.textclass,
1127 if (layout.free_spacing) {
1128 par->insertChar(pos, ' ', font);
1130 Inset * inset = new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
1131 par->insertInset(pos, inset, font);
1134 } else if (token == "\\bibitem") { // ale970302
1136 InsetCommandParams p("bibitem", "dummy");
1137 par->bibkey = new InsetBibKey(p);
1139 par->bibkey->read(this, lex);
1140 } else if (token == "\\backslash") {
1141 #ifndef NO_COMPABILITY
1142 if (ert_comp.active) {
1143 ert_comp.contents += "\\";
1146 par->insertChar(pos, '\\', font);
1148 #ifndef NO_COMPABILITY
1151 } else if (token == "\\the_end") {
1152 #ifndef NO_COMPABILITY
1153 // If we still have some ert active here we have to insert
1154 // it so we don't loose it. (Lgb)
1155 insertErtContents(par, pos, font);
1157 the_end_read = true;
1158 #ifndef NO_COMPABILITY
1159 #ifndef NO_PEXTRA_REALLY
1160 minipar = parBeforeMinipage = 0;
1164 #ifndef NO_COMPABILITY
1165 if (ert_comp.active) {
1166 ert_comp.contents += token;
1169 // This should be insurance for the future: (Asger)
1170 lex.printError("Unknown token `$$Token'. "
1171 "Inserting as text.");
1172 string::const_iterator cit = token.begin();
1173 string::const_iterator end = token.end();
1174 for (; cit != end; ++cit) {
1175 par->insertChar(pos, (*cit), font);
1178 #ifndef NO_COMPABILITY
1183 #ifndef NO_COMPABILITY
1184 #ifndef NO_PEXTRA_REALLY
1185 // I wonder if we could use this blanket fix for all the
1186 // checkminipage cases...
1187 if (par && par->size()) {
1188 // It is possible that this will check to often,
1189 // but that should not be an correctness issue.
1190 // Only a speed issue.
1191 checkminipage = true;
1194 // now check if we have a minipage paragraph as at this
1195 // point we already read all the necessary data!
1196 // this cannot be done in layout because there we did
1197 // not read yet the paragraph PEXTRA-params (Jug)
1199 // BEGIN pextra_minipage compability
1200 // This should be removed in 1.3.x (Lgb)
1202 // This compability code is not perfect. In a couple
1203 // of rand cases it fails. When the minipage par is
1204 // the first par in the document, and when there are
1205 // none or only one regular paragraphs after the
1206 // minipage. Currently I am not investing any effort
1207 // in fixing those cases.
1209 //lyxerr << "Call depth: " << call_depth << endl;
1210 if (checkminipage && (call_depth == 1)) {
1211 checkminipage = false;
1212 if (minipar && (minipar != par) &&
1213 (par->params().pextraType()==Paragraph::PEXTRA_MINIPAGE))
1215 lyxerr << "minipages in a row" << endl;
1216 if (par->params().pextraStartMinipage()) {
1217 lyxerr << "start new minipage" << endl;
1218 // minipages in a row
1219 par->previous()->next(0);
1222 Paragraph * tmp = minipar;
1224 tmp->params().pextraType(0);
1225 tmp->params().pextraWidth(string());
1226 tmp->params().pextraWidthp(string());
1227 tmp->params().pextraAlignment(0);
1228 tmp->params().pextraHfill(false);
1229 tmp->params().pextraStartMinipage(false);
1232 // create a new paragraph to insert the
1233 // minipages in the following case
1234 if (par->params().pextraStartMinipage() &&
1235 !par->params().pextraHfill())
1237 Paragraph * p = new Paragraph;
1239 p->previous(parBeforeMinipage);
1240 parBeforeMinipage->next(p);
1242 p->params().depth(parBeforeMinipage->params().depth());
1243 parBeforeMinipage = p;
1245 InsetMinipage * mini = new InsetMinipage;
1246 mini->pos(static_cast<InsetMinipage::Position>(par->params().pextraAlignment()));
1247 mini->width(par->params().pextraWidth());
1248 if (!par->params().pextraWidthp().empty()) {
1249 lyxerr << "WP:" << mini->width() << endl;
1250 mini->width(tostr(par->params().pextraWidthp())+"%");
1252 mini->inset.paragraph(par);
1253 // Insert the minipage last in the
1254 // previous paragraph.
1255 if (par->params().pextraHfill()) {
1256 parBeforeMinipage->insertChar
1257 (parBeforeMinipage->size(), Paragraph::META_HFILL);
1259 parBeforeMinipage->insertInset
1260 (parBeforeMinipage->size(), mini);
1264 lyxerr << "new minipage par" << endl;
1265 //nothing to do just continue reading
1268 } else if (minipar && (minipar != par)) {
1269 lyxerr << "last minipage par read" << endl;
1270 // The last paragraph read was not part of a
1271 // minipage but the par linked list is...
1272 // So we need to remove the last par from the
1274 if (par->previous())
1275 par->previous()->next(0);
1276 par->previous(parBeforeMinipage);
1277 parBeforeMinipage->next(par);
1278 Paragraph * tmp = minipar;
1280 tmp->params().pextraType(0);
1281 tmp->params().pextraWidth(string());
1282 tmp->params().pextraWidthp(string());
1283 tmp->params().pextraAlignment(0);
1284 tmp->params().pextraHfill(false);
1285 tmp->params().pextraStartMinipage(false);
1288 depth = parBeforeMinipage->params().depth();
1289 minipar = parBeforeMinipage = 0;
1290 } else if (!minipar &&
1291 (par->params().pextraType() == Paragraph::PEXTRA_MINIPAGE))
1293 // par is the first paragraph in a minipage
1294 lyxerr << "begin minipage" << endl;
1295 // To minimize problems for
1296 // the users we will insert
1297 // the first minipage in
1298 // a sequence of minipages
1299 // in its own paragraph.
1300 Paragraph * p = new Paragraph;
1302 p->previous(par->previous());
1304 p->params().depth(depth);
1305 par->params().depth(0);
1307 if (par->previous())
1308 par->previous()->next(p);
1310 parBeforeMinipage = p;
1312 if (!first_par || (first_par == par))
1315 InsetMinipage * mini = new InsetMinipage;
1316 mini->pos(static_cast<InsetMinipage::Position>(minipar->params().pextraAlignment()));
1317 mini->width(minipar->params().pextraWidth());
1318 if (!par->params().pextraWidthp().empty()) {
1319 lyxerr << "WP:" << mini->width() << endl;
1320 mini->width(tostr(par->params().pextraWidthp())+"%");
1322 mini->inset.paragraph(minipar);
1324 // Insert the minipage last in the
1325 // previous paragraph.
1326 if (minipar->params().pextraHfill()) {
1327 parBeforeMinipage->insertChar
1328 (parBeforeMinipage->size(),Paragraph::META_HFILL);
1330 parBeforeMinipage->insertInset
1331 (parBeforeMinipage->size(), mini);
1334 // End of pextra_minipage compability
1338 return the_end_read;
1341 // needed to insert the selection
1342 void Buffer::insertStringAsLines(Paragraph *& par, Paragraph::size_type & pos,
1343 LyXFont const & fn,string const & str) const
1345 LyXLayout const & layout = textclasslist.Style(params.textclass,
1349 (void)par->checkInsertChar(font);
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)
1369 } else if (*cit == '\t') {
1370 if (!layout.free_spacing) {
1371 // tabs are like spaces here
1372 par->insertChar(pos, ' ', font);
1374 space_inserted = true;
1376 const Paragraph::size_type nb = 8 - pos % 8;
1377 for (Paragraph::size_type a = 0;
1379 par->insertChar(pos, ' ', font);
1382 space_inserted = true;
1384 } else if (!IsPrintable(*cit)) {
1385 // Ignore unprintables
1388 // just insert the character
1389 par->insertChar(pos, *cit, font);
1391 space_inserted = (*cit == ' ');
1398 void Buffer::readInset(LyXLex & lex, Paragraph *& par,
1399 int & pos, LyXFont & font)
1401 // consistency check
1402 if (lex.getString() != "\\begin_inset") {
1403 lyxerr << "Buffer::readInset: Consistency check failed."
1410 string const tmptok = lex.getString();
1411 last_inset_read = tmptok;
1413 // test the different insets
1414 if (tmptok == "LatexCommand") {
1415 InsetCommandParams inscmd;
1418 string const cmdName = inscmd.getCmdName();
1420 // This strange command allows LyX to recognize "natbib" style
1421 // citations: citet, citep, Citet etc.
1422 if (compare_no_case(cmdName, "cite", 4) == 0) {
1423 inset = new InsetCitation(inscmd);
1424 } else if (cmdName == "bibitem") {
1425 lex.printError("Wrong place for bibitem");
1426 inset = new InsetBibKey(inscmd);
1427 } else if (cmdName == "BibTeX") {
1428 inset = new InsetBibtex(inscmd);
1429 } else if (cmdName == "index") {
1430 inset = new InsetIndex(inscmd);
1431 } else if (cmdName == "include") {
1432 inset = new InsetInclude(inscmd, *this);
1433 } else if (cmdName == "label") {
1434 inset = new InsetLabel(inscmd);
1435 } else if (cmdName == "url"
1436 || cmdName == "htmlurl") {
1437 inset = new InsetUrl(inscmd);
1438 } else if (cmdName == "ref"
1439 || cmdName == "pageref"
1440 || cmdName == "vref"
1441 || cmdName == "vpageref"
1442 || cmdName == "prettyref") {
1443 if (!inscmd.getOptions().empty()
1444 || !inscmd.getContents().empty()) {
1445 inset = new InsetRef(inscmd, *this);
1447 } else if (cmdName == "tableofcontents") {
1448 inset = new InsetTOC(inscmd);
1449 } else if (cmdName == "listofalgorithms") {
1450 inset = new InsetFloatList("algorithm");
1451 } else if (cmdName == "listoffigures") {
1452 inset = new InsetFloatList("figure");
1453 } else if (cmdName == "listoftables") {
1454 inset = new InsetFloatList("table");
1455 } else if (cmdName == "printindex") {
1456 inset = new InsetPrintIndex(inscmd);
1457 } else if (cmdName == "lyxparent") {
1458 inset = new InsetParent(inscmd, *this);
1461 bool alreadyread = false;
1462 if (tmptok == "Quotes") {
1463 inset = new InsetQuotes;
1464 } else if (tmptok == "External") {
1465 inset = new InsetExternal;
1466 } else if (tmptok == "FormulaMacro") {
1467 inset = new InsetFormulaMacro;
1468 } else if (tmptok == "Formula") {
1469 inset = new InsetFormula;
1470 } else if (tmptok == "Figure") { // Backward compatibility
1471 inset = new InsetFig(100, 100, *this);
1472 //inset = new InsetGraphics;
1473 } else if (tmptok == "Graphics") {
1474 inset = new InsetGraphics;
1475 } else if (tmptok == "Info") {// backwards compatibility
1476 inset = new InsetNote(this,
1477 lex.getLongString("\\end_inset"),
1480 } else if (tmptok == "Note") {
1481 inset = new InsetNote;
1482 } else if (tmptok == "Include") {
1483 InsetCommandParams p( "Include" );
1484 inset = new InsetInclude(p, *this);
1485 } else if (tmptok == "ERT") {
1486 inset = new InsetERT;
1487 } else if (tmptok == "Tabular") {
1488 inset = new InsetTabular(*this);
1489 } else if (tmptok == "Text") {
1490 inset = new InsetText;
1491 } else if (tmptok == "Foot") {
1492 inset = new InsetFoot;
1493 } else if (tmptok == "Marginal") {
1494 inset = new InsetMarginal;
1495 } else if (tmptok == "Minipage") {
1496 inset = new InsetMinipage;
1497 } else if (tmptok == "Float") {
1499 string tmptok = lex.getString();
1500 inset = new InsetFloat(tmptok);
1502 } else if (tmptok == "List") {
1503 inset = new InsetList;
1504 } else if (tmptok == "Theorem") {
1505 inset = new InsetList;
1507 } else if (tmptok == "Caption") {
1508 inset = new InsetCaption;
1509 } else if (tmptok == "FloatList") {
1510 inset = new InsetFloatList;
1513 if (inset && !alreadyread) inset->read(this, lex);
1517 par->insertInset(pos, inset, font);
1523 bool Buffer::readFile(LyXLex & lex, Paragraph * par)
1527 string const token(lex.getString());
1528 if (token == "\\lyxformat") { // the first token _must_ be...
1530 string tmp_format = lex.getString();
1531 //lyxerr << "LyX Format: `" << tmp_format << "'" << endl;
1532 // if present remove ".," from string.
1533 string::size_type dot = tmp_format.find_first_of(".,");
1534 //lyxerr << " dot found at " << dot << endl;
1535 if (dot != string::npos)
1536 tmp_format.erase(dot, 1);
1537 file_format = strToInt(tmp_format);
1538 if (file_format == LYX_FORMAT) {
1540 } else if (file_format > LYX_FORMAT) {
1542 WriteAlert(_("Warning!"),
1543 _("LyX file format is newer that what"),
1544 _("is supported in this LyX version. Expect some problems."));
1546 } else if (file_format < LYX_FORMAT) {
1548 if (file_format < 200) {
1549 WriteAlert(_("ERROR!"),
1550 _("Old LyX file format found. "
1551 "Use LyX 0.10.x to read this!"));
1555 bool the_end = readLyXformat2(lex, par);
1557 // the_end was added in 213
1558 if (file_format < 213)
1562 WriteAlert(_("Warning!"),
1563 _("Reading of document is not complete"),
1564 _("Maybe the document is truncated"));
1566 } else { // "\\lyxformat" not found
1567 WriteAlert(_("ERROR!"), _("Not a LyX file!"));
1570 WriteAlert(_("ERROR!"), _("Unable to read file!"));
1575 // Should probably be moved to somewhere else: BufferView? LyXView?
1576 bool Buffer::save() const
1578 // We don't need autosaves in the immediate future. (Asger)
1579 resetAutosaveTimers();
1583 if (lyxrc.make_backup) {
1584 s = fileName() + '~';
1585 if (!lyxrc.backupdir_path.empty())
1586 s = AddName(lyxrc.backupdir_path,
1587 subst(os::slashify_path(s),'/','!'));
1589 // Rename is the wrong way of making a backup,
1590 // this is the correct way.
1591 /* truss cp fil fil2:
1592 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
1593 stat("LyXVC.lyx", 0xEFFFF688) = 0
1594 open("LyXVC.lyx", O_RDONLY) = 3
1595 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
1596 fstat(4, 0xEFFFF508) = 0
1597 fstat(3, 0xEFFFF508) = 0
1598 read(3, " # T h i s f i l e w".., 8192) = 5579
1599 write(4, " # T h i s f i l e w".., 5579) = 5579
1600 read(3, 0xEFFFD4A0, 8192) = 0
1603 chmod("LyXVC3.lyx", 0100644) = 0
1604 lseek(0, 0, SEEK_CUR) = 46440
1608 // Should probably have some more error checking here.
1609 // Should be cleaned up in 0.13, at least a bit.
1610 // Doing it this way, also makes the inodes stay the same.
1611 // This is still not a very good solution, in particular we
1612 // might loose the owner of the backup.
1613 FileInfo finfo(fileName());
1614 if (finfo.exist()) {
1615 mode_t fmode = finfo.getMode();
1616 struct utimbuf times = {
1617 finfo.getAccessTime(),
1618 finfo.getModificationTime() };
1620 ifstream ifs(fileName().c_str());
1621 ofstream ofs(s.c_str(), ios::out|ios::trunc);
1626 ::chmod(s.c_str(), fmode);
1628 if (::utime(s.c_str(), ×)) {
1629 lyxerr << "utime error." << endl;
1632 lyxerr << "LyX was not able to make "
1633 "backup copy. Beware." << endl;
1638 if (writeFile(fileName(), false)) {
1640 removeAutosaveFile(fileName());
1642 // Saving failed, so backup is not backup
1643 if (lyxrc.make_backup) {
1644 lyx::rename(s, fileName());
1652 // Returns false if unsuccesful
1653 bool Buffer::writeFile(string const & fname, bool flag) const
1655 // if flag is false writeFile will not create any GUI
1656 // warnings, only cerr.
1657 // Needed for autosave in background or panic save (Matthias 120496)
1659 if (read_only && (fname == filename)) {
1660 // Here we should come with a question if we should
1661 // perform the write anyway.
1663 lyxerr << _("Error! Document is read-only: ")
1666 WriteAlert(_("Error! Document is read-only: "),
1671 FileInfo finfo(fname);
1672 if (finfo.exist() && !finfo.writable()) {
1673 // Here we should come with a question if we should
1674 // try to do the save anyway. (i.e. do a chmod first)
1676 lyxerr << _("Error! Cannot write file: ")
1679 WriteFSAlert(_("Error! Cannot write file: "),
1684 ofstream ofs(fname.c_str());
1687 lyxerr << _("Error! Cannot open file: ")
1690 WriteFSAlert(_("Error! Cannot open file: "),
1696 // Use the standard "C" locale for file output.
1697 ofs.imbue(std::locale::classic());
1700 // The top of the file should not be written by params.
1702 // write out a comment in the top of the file
1703 ofs << '#' << lyx_docversion
1704 << " created this file. For more info see http://www.lyx.org/\n"
1705 << "\\lyxformat " << LYX_FORMAT << "\n";
1707 // now write out the buffer paramters.
1708 params.writeFile(ofs);
1710 Paragraph::depth_type depth = 0;
1712 // this will write out all the paragraphs
1713 // using recursive descent.
1714 paragraph->writeFile(this, ofs, params, depth);
1716 // Write marker that shows file is complete
1717 ofs << "\n\\the_end" << endl;
1721 // how to check if close went ok?
1722 // Following is an attempt... (BE 20001011)
1724 // good() returns false if any error occured, including some
1725 // formatting error.
1726 // bad() returns true if something bad happened in the buffer,
1727 // which should include file system full errors.
1734 lyxerr << "Buffer::writeFile: BAD ERROR!" << endl;
1736 lyxerr << "Buffer::writeFile: NOT SO BAD ERROR!"
1746 string const Buffer::asciiParagraph(Paragraph const * par,
1747 unsigned int linelen) const
1749 ostringstream buffer;
1750 Paragraph::depth_type depth = 0;
1752 Paragraph::depth_type ltype_depth = 0;
1753 string::size_type currlinelen = 0;
1754 bool ref_printed = false;
1758 if (!par->previous()) {
1759 // begins or ends a deeper area ?
1760 if (depth != par->params().depth()) {
1761 if (par->params().depth() > depth) {
1762 while (par->params().depth() > depth) {
1766 while (par->params().depth() < depth) {
1772 // First write the layout
1773 string const tmp = textclasslist.NameOfLayout(params.textclass, par->layout);
1774 if (tmp == "Itemize") {
1776 ltype_depth = depth + 1;
1777 } else if (tmp == "Enumerate") {
1779 ltype_depth = depth + 1;
1780 } else if (contains(tmp, "ection")) {
1782 ltype_depth = depth + 1;
1783 } else if (contains(tmp, "aragraph")) {
1785 ltype_depth = depth + 1;
1786 } else if (tmp == "Description") {
1788 ltype_depth = depth + 1;
1789 } else if (tmp == "Abstract") {
1792 } else if (tmp == "Bibliography") {
1800 /* maybe some vertical spaces */
1802 /* the labelwidthstring used in lists */
1806 /* some pagebreaks? */
1810 /* what about the alignment */
1812 lyxerr << "Should this ever happen?" << endl;
1815 for (Paragraph::size_type i = 0; i < par->size(); ++i) {
1816 if (!i && !noparbreak) {
1819 for (Paragraph::depth_type j = 0; j < depth; ++j)
1821 currlinelen = depth * 2;
1824 case 4: // (Sub)Paragraph
1825 case 5: // Description
1829 buffer << "Abstract\n\n";
1831 buffer << "Abstract: ";
1833 case 7: // Bibliography
1836 buffer << "References\n\n";
1838 buffer << "References: ";
1843 buffer << par->params().labelString() << " ";
1846 if (ltype_depth > depth) {
1847 for (Paragraph::depth_type j = ltype_depth - 1;
1850 currlinelen += (ltype_depth-depth)*2;
1854 char c = par->getUChar(params, i);
1858 case Paragraph::META_INSET:
1860 Inset const * inset = par->getInset(i);
1862 if (!inset->ascii(this, buffer)) {
1865 rsplit(buffer.str().c_str(),
1867 currlinelen += s.length();
1869 // to be sure it breaks paragraph
1870 currlinelen += linelen;
1876 case Paragraph::META_NEWLINE:
1879 for (Paragraph::depth_type j = 0;
1883 currlinelen = depth * 2;
1884 if (ltype_depth > depth) {
1885 for (Paragraph::depth_type j = ltype_depth;
1888 currlinelen += (ltype_depth - depth) * 2;
1892 case Paragraph::META_HFILL:
1897 if ((linelen > 0) && (currlinelen > (linelen - 10)) &&
1898 (c == ' ') && ((i + 2) < par->size()))
1901 for (Paragraph::depth_type j = 0;
1904 currlinelen = depth * 2;
1905 if (ltype_depth > depth) {
1906 for (Paragraph::depth_type j = ltype_depth;
1909 currlinelen += (ltype_depth-depth)*2;
1911 } else if (c != '\0') {
1915 lyxerr[Debug::INFO] << "writeAsciiFile: NULL char in structure." << endl;
1919 return buffer.str().c_str();
1923 void Buffer::writeFileAscii(string const & fname, int linelen)
1925 ofstream ofs(fname.c_str());
1927 WriteFSAlert(_("Error: Cannot write file:"), fname);
1930 writeFileAscii(ofs, linelen);
1934 void Buffer::writeFileAscii(ostream & ofs, int linelen)
1936 Paragraph * par = paragraph;
1938 ofs << asciiParagraph(par, linelen);
1946 void Buffer::makeLaTeXFile(string const & fname,
1947 string const & original_path,
1948 bool nice, bool only_body)
1950 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
1952 niceFile = nice; // this will be used by Insetincludes.
1954 tex_code_break_column = lyxrc.ascii_linelen;
1956 LyXTextClass const & tclass =
1957 textclasslist.TextClass(params.textclass);
1959 ofstream ofs(fname.c_str());
1961 WriteFSAlert(_("Error: Cannot open file: "), fname);
1965 // validate the buffer.
1966 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
1967 LaTeXFeatures features(params, tclass.numLayouts());
1969 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
1972 // The starting paragraph of the coming rows is the
1973 // first paragraph of the document. (Asger)
1974 texrow.start(paragraph, 0);
1976 if (!only_body && nice) {
1977 ofs << "%% " << lyx_docversion << " created this file. "
1978 "For more info, see http://www.lyx.org/.\n"
1979 "%% Do not edit unless you really know what "
1984 lyxerr[Debug::INFO] << "lyx header finished" << endl;
1985 // There are a few differences between nice LaTeX and usual files:
1986 // usual is \batchmode and has a
1987 // special input@path to allow the including of figures
1988 // with either \input or \includegraphics (what figinsets do).
1989 // batchmode is not set if there is a tex_code_break_column.
1990 // In this case somebody is interested in the generated LaTeX,
1991 // so this is OK. input@path is set when the actual parameter
1992 // original_path is set. This is done for usual tex-file, but not
1993 // for nice-latex-file. (Matthias 250696)
1996 // code for usual, NOT nice-latex-file
1997 ofs << "\\batchmode\n"; // changed
1998 // from \nonstopmode
2001 if (!original_path.empty()) {
2002 ofs << "\\makeatletter\n"
2003 << "\\def\\input@path{{"
2004 << os::external_path(original_path) << "/}}\n"
2005 << "\\makeatother\n";
2011 ofs << "\\documentclass";
2013 ostringstream options; // the document class options.
2015 if (tokenPos(tclass.opt_fontsize(),
2016 '|', params.fontsize) >= 0) {
2017 // only write if existing in list (and not default)
2018 options << params.fontsize << "pt,";
2022 if (!params.use_geometry &&
2023 (params.paperpackage == BufferParams::PACKAGE_NONE)) {
2024 switch (params.papersize) {
2025 case BufferParams::PAPER_A4PAPER:
2026 options << "a4paper,";
2028 case BufferParams::PAPER_USLETTER:
2029 options << "letterpaper,";
2031 case BufferParams::PAPER_A5PAPER:
2032 options << "a5paper,";
2034 case BufferParams::PAPER_B5PAPER:
2035 options << "b5paper,";
2037 case BufferParams::PAPER_EXECUTIVEPAPER:
2038 options << "executivepaper,";
2040 case BufferParams::PAPER_LEGALPAPER:
2041 options << "legalpaper,";
2047 if (params.sides != tclass.sides()) {
2048 switch (params.sides) {
2049 case LyXTextClass::OneSide:
2050 options << "oneside,";
2052 case LyXTextClass::TwoSides:
2053 options << "twoside,";
2059 if (params.columns != tclass.columns()) {
2060 if (params.columns == 2)
2061 options << "twocolumn,";
2063 options << "onecolumn,";
2066 if (!params.use_geometry
2067 && params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
2068 options << "landscape,";
2070 // language should be a parameter to \documentclass
2072 ostringstream language_options;
2073 if (params.language->babel() == "hebrew"
2074 && default_language->babel() != "hebrew")
2075 // This seems necessary
2076 features.UsedLanguages.insert(default_language);
2078 if (lyxrc.language_use_babel ||
2079 params.language->lang() != lyxrc.default_language ||
2080 !features.UsedLanguages.empty()) {
2082 for (LaTeXFeatures::LanguageList::const_iterator cit =
2083 features.UsedLanguages.begin();
2084 cit != features.UsedLanguages.end(); ++cit)
2085 language_options << (*cit)->babel() << ',';
2086 language_options << params.language->babel();
2087 if (lyxrc.language_global_options)
2088 options << language_options.str() << ',';
2091 // the user-defined options
2092 if (!params.options.empty()) {
2093 options << params.options << ',';
2096 string strOptions(options.str().c_str());
2097 if (!strOptions.empty()){
2098 strOptions = strip(strOptions, ',');
2099 ofs << '[' << strOptions << ']';
2103 << textclasslist.LatexnameOfClass(params.textclass)
2106 // end of \documentclass defs
2108 // font selection must be done before loading fontenc.sty
2109 // The ae package is not needed when using OT1 font encoding.
2110 if (params.fonts != "default" &&
2111 (params.fonts != "ae" || lyxrc.fontenc != "default")) {
2112 ofs << "\\usepackage{" << params.fonts << "}\n";
2114 if (params.fonts == "ae") {
2115 ofs << "\\usepackage{aecompl}\n";
2119 // this one is not per buffer
2120 if (lyxrc.fontenc != "default") {
2121 ofs << "\\usepackage[" << lyxrc.fontenc
2126 if (params.inputenc == "auto") {
2127 string const doc_encoding =
2128 params.language->encoding()->LatexName();
2130 // Create a list with all the input encodings used
2132 set<string> encodings;
2133 for (LaTeXFeatures::LanguageList::const_iterator it =
2134 features.UsedLanguages.begin();
2135 it != features.UsedLanguages.end(); ++it)
2136 if ((*it)->encoding()->LatexName() != doc_encoding)
2137 encodings.insert((*it)->encoding()->LatexName());
2139 ofs << "\\usepackage[";
2140 std::copy(encodings.begin(), encodings.end(),
2141 std::ostream_iterator<string>(ofs, ","));
2142 ofs << doc_encoding << "]{inputenc}\n";
2144 } else if (params.inputenc != "default") {
2145 ofs << "\\usepackage[" << params.inputenc
2150 // At the very beginning the text parameters.
2151 if (params.paperpackage != BufferParams::PACKAGE_NONE) {
2152 switch (params.paperpackage) {
2153 case BufferParams::PACKAGE_A4:
2154 ofs << "\\usepackage{a4}\n";
2157 case BufferParams::PACKAGE_A4WIDE:
2158 ofs << "\\usepackage{a4wide}\n";
2161 case BufferParams::PACKAGE_WIDEMARGINSA4:
2162 ofs << "\\usepackage[widemargins]{a4}\n";
2167 if (params.use_geometry) {
2168 ofs << "\\usepackage{geometry}\n";
2170 ofs << "\\geometry{verbose";
2171 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
2172 ofs << ",landscape";
2173 switch (params.papersize2) {
2174 case BufferParams::VM_PAPER_CUSTOM:
2175 if (!params.paperwidth.empty())
2176 ofs << ",paperwidth="
2177 << params.paperwidth;
2178 if (!params.paperheight.empty())
2179 ofs << ",paperheight="
2180 << params.paperheight;
2182 case BufferParams::VM_PAPER_USLETTER:
2183 ofs << ",letterpaper";
2185 case BufferParams::VM_PAPER_USLEGAL:
2186 ofs << ",legalpaper";
2188 case BufferParams::VM_PAPER_USEXECUTIVE:
2189 ofs << ",executivepaper";
2191 case BufferParams::VM_PAPER_A3:
2194 case BufferParams::VM_PAPER_A4:
2197 case BufferParams::VM_PAPER_A5:
2200 case BufferParams::VM_PAPER_B3:
2203 case BufferParams::VM_PAPER_B4:
2206 case BufferParams::VM_PAPER_B5:
2210 // default papersize ie BufferParams::VM_PAPER_DEFAULT
2211 switch (lyxrc.default_papersize) {
2212 case BufferParams::PAPER_DEFAULT: // keep compiler happy
2213 case BufferParams::PAPER_USLETTER:
2214 ofs << ",letterpaper";
2216 case BufferParams::PAPER_LEGALPAPER:
2217 ofs << ",legalpaper";
2219 case BufferParams::PAPER_EXECUTIVEPAPER:
2220 ofs << ",executivepaper";
2222 case BufferParams::PAPER_A3PAPER:
2225 case BufferParams::PAPER_A4PAPER:
2228 case BufferParams::PAPER_A5PAPER:
2231 case BufferParams::PAPER_B5PAPER:
2236 if (!params.topmargin.empty())
2237 ofs << ",tmargin=" << params.topmargin;
2238 if (!params.bottommargin.empty())
2239 ofs << ",bmargin=" << params.bottommargin;
2240 if (!params.leftmargin.empty())
2241 ofs << ",lmargin=" << params.leftmargin;
2242 if (!params.rightmargin.empty())
2243 ofs << ",rmargin=" << params.rightmargin;
2244 if (!params.headheight.empty())
2245 ofs << ",headheight=" << params.headheight;
2246 if (!params.headsep.empty())
2247 ofs << ",headsep=" << params.headsep;
2248 if (!params.footskip.empty())
2249 ofs << ",footskip=" << params.footskip;
2253 if (features.amsstyle
2254 && !tclass.provides(LyXTextClass::amsmath)) {
2255 ofs << "\\usepackage{amsmath}\n";
2259 if (tokenPos(tclass.opt_pagestyle(),
2260 '|', params.pagestyle) >= 0) {
2261 if (params.pagestyle == "fancy") {
2262 ofs << "\\usepackage{fancyhdr}\n";
2265 ofs << "\\pagestyle{" << params.pagestyle << "}\n";
2269 if (params.secnumdepth != tclass.secnumdepth()) {
2270 ofs << "\\setcounter{secnumdepth}{"
2271 << params.secnumdepth
2275 if (params.tocdepth != tclass.tocdepth()) {
2276 ofs << "\\setcounter{tocdepth}{"
2282 if (params.paragraph_separation) {
2283 switch (params.defskip.kind()) {
2284 case VSpace::SMALLSKIP:
2285 ofs << "\\setlength\\parskip{\\smallskipamount}\n";
2287 case VSpace::MEDSKIP:
2288 ofs << "\\setlength\\parskip{\\medskipamount}\n";
2290 case VSpace::BIGSKIP:
2291 ofs << "\\setlength\\parskip{\\bigskipamount}\n";
2293 case VSpace::LENGTH:
2294 ofs << "\\setlength\\parskip{"
2295 << params.defskip.length().asLatexString()
2298 default: // should never happen // Then delete it.
2299 ofs << "\\setlength\\parskip{\\medskipamount}\n";
2304 ofs << "\\setlength\\parindent{0pt}\n";
2308 // Now insert the LyX specific LaTeX commands...
2310 // The optional packages;
2311 string preamble(features.getPackages());
2313 // this might be useful...
2314 preamble += "\n\\makeatletter\n";
2316 // Some macros LyX will need
2317 string tmppreamble(features.getMacros());
2319 if (!tmppreamble.empty()) {
2320 preamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2321 "LyX specific LaTeX commands.\n"
2322 + tmppreamble + '\n';
2325 // the text class specific preamble
2326 tmppreamble = features.getTClassPreamble();
2327 if (!tmppreamble.empty()) {
2328 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2329 "Textclass specific LaTeX commands.\n"
2330 + tmppreamble + '\n';
2333 /* the user-defined preamble */
2334 if (!params.preamble.empty()) {
2335 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2336 "User specified LaTeX commands.\n"
2337 + params.preamble + '\n';
2340 preamble += "\\makeatother\n";
2342 // Itemize bullet settings need to be last in case the user
2343 // defines their own bullets that use a package included
2344 // in the user-defined preamble -- ARRae
2345 // Actually it has to be done much later than that
2346 // since some packages like frenchb make modifications
2347 // at \begin{document} time -- JMarc
2349 for (int i = 0; i < 4; ++i) {
2350 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
2351 if (bullets_def.empty())
2352 bullets_def="\\AtBeginDocument{\n";
2353 bullets_def += " \\renewcommand{\\labelitemi";
2355 // `i' is one less than the item to modify
2362 bullets_def += "ii";
2368 bullets_def += "}{" +
2369 params.user_defined_bullets[i].getText()
2374 if (!bullets_def.empty())
2375 preamble += bullets_def + "}\n\n";
2377 for (int j = countChar(preamble, '\n'); j-- ;) {
2383 // We try to load babel late, in case it interferes
2384 // with other packages.
2386 string tmp = lyxrc.language_package;
2387 if (!lyxrc.language_global_options
2388 && tmp == "\\usepackage{babel}")
2389 tmp = string("\\usepackage[") +
2390 language_options.str().c_str() +
2397 ofs << "\\begin{document}\n";
2400 lyxerr[Debug::INFO] << "preamble finished, now the body." << endl;
2402 if (!lyxrc.language_auto_begin) {
2403 ofs << subst(lyxrc.language_command_begin, "$$lang",
2404 params.language->babel())
2409 latexParagraphs(ofs, paragraph, 0, texrow);
2411 // add this just in case after all the paragraphs
2415 if (!lyxrc.language_auto_end) {
2416 ofs << subst(lyxrc.language_command_end, "$$lang",
2417 params.language->babel())
2423 ofs << "\\end{document}\n";
2426 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
2428 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
2432 // Just to be sure. (Asger)
2435 // tex_code_break_column's value is used to decide
2436 // if we are in batchmode or not (within mathed_write()
2437 // in math_write.C) so we must set it to a non-zero
2438 // value when we leave otherwise we save incorrect .lyx files.
2439 tex_code_break_column = lyxrc.ascii_linelen;
2443 lyxerr << "File was not closed properly." << endl;
2446 lyxerr[Debug::INFO] << "Finished making latex file." << endl;
2451 // LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
2453 void Buffer::latexParagraphs(ostream & ofs, Paragraph * par,
2454 Paragraph * endpar, TexRow & texrow) const
2456 bool was_title = false;
2457 bool already_title = false;
2460 while (par != endpar) {
2461 LyXLayout const & layout =
2462 textclasslist.Style(params.textclass,
2465 if (layout.intitle) {
2466 if (already_title) {
2467 lyxerr <<"Error in latexParagraphs: You"
2468 " should not mix title layouts"
2469 " with normal ones." << endl;
2472 } else if (was_title && !already_title) {
2473 ofs << "\\maketitle\n";
2475 already_title = true;
2479 if (layout.isEnvironment()) {
2480 par = par->TeXEnvironment(this, params, ofs, texrow);
2482 par = par->TeXOnePar(this, params, ofs, texrow, false);
2485 // It might be that we only have a title in this document
2486 if (was_title && !already_title) {
2487 ofs << "\\maketitle\n";
2493 bool Buffer::isLatex() const
2495 return textclasslist.TextClass(params.textclass).outputType() == LATEX;
2499 bool Buffer::isLinuxDoc() const
2501 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC;
2505 bool Buffer::isLiterate() const
2507 return textclasslist.TextClass(params.textclass).outputType() == LITERATE;
2511 bool Buffer::isDocBook() const
2513 return textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2517 bool Buffer::isSGML() const
2519 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC ||
2520 textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2524 void Buffer::sgmlOpenTag(ostream & os, Paragraph::depth_type depth,
2525 string const & latexname) const
2527 if (!latexname.empty() && latexname != "!-- --")
2528 os << "<!-- " << depth << " -->" << "<" << latexname << ">";
2529 //os << string(depth, ' ') << "<" << latexname << ">\n";
2533 void Buffer::sgmlCloseTag(ostream & os, Paragraph::depth_type depth,
2534 string const & latexname) const
2536 if (!latexname.empty() && latexname != "!-- --")
2537 os << "<!-- " << depth << " -->" << "</" << latexname << ">\n";
2538 //os << string(depth, ' ') << "</" << latexname << ">\n";
2542 void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
2544 ofstream ofs(fname.c_str());
2547 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2551 niceFile = nice; // this will be used by included files.
2553 LyXTextClass const & tclass =
2554 textclasslist.TextClass(params.textclass);
2556 LaTeXFeatures features(params, tclass.numLayouts());
2561 string top_element = textclasslist.LatexnameOfClass(params.textclass);
2564 string sgml_includedfiles=features.getIncludedFiles(fname);
2566 if (params.preamble.empty() && sgml_includedfiles.empty()) {
2567 ofs << "<!doctype linuxdoc system>\n\n";
2569 ofs << "<!doctype linuxdoc system [ "
2570 << params.preamble << sgml_includedfiles << " \n]>\n\n";
2573 if (params.options.empty())
2574 sgmlOpenTag(ofs, 0, top_element);
2576 string top = top_element;
2578 top += params.options;
2579 sgmlOpenTag(ofs, 0, top);
2583 ofs << "<!-- " << lyx_docversion
2584 << " created this file. For more info see http://www.lyx.org/"
2587 Paragraph::depth_type depth = 0; // paragraph depth
2588 Paragraph * par = paragraph;
2590 vector<string> environment_stack(5);
2593 LyXLayout const & style =
2594 textclasslist.Style(params.textclass,
2597 // treat <toc> as a special case for compatibility with old code
2598 if (par->getChar(0) == Paragraph::META_INSET) {
2599 Inset * inset = par->getInset(0);
2600 Inset::Code lyx_code = inset->lyxCode();
2601 if (lyx_code == Inset::TOC_CODE){
2602 string const temp = "toc";
2603 sgmlOpenTag(ofs, depth, temp);
2610 // environment tag closing
2611 for (; depth > par->params().depth(); --depth) {
2612 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2613 environment_stack[depth].erase();
2616 // write opening SGML tags
2617 switch (style.latextype) {
2618 case LATEX_PARAGRAPH:
2619 if (depth == par->params().depth()
2620 && !environment_stack[depth].empty()) {
2621 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2622 environment_stack[depth].erase();
2628 sgmlOpenTag(ofs, depth, style.latexname());
2633 linuxDocError(par, 0,
2634 _("Error : Wrong depth for"
2635 " LatexType Command.\n"));
2637 if (!environment_stack[depth].empty()){
2638 sgmlCloseTag(ofs, depth,
2639 environment_stack[depth]);
2643 environment_stack[depth].erase();
2644 sgmlOpenTag(ofs, depth, style.latexname());
2647 case LATEX_ENVIRONMENT:
2648 case LATEX_ITEM_ENVIRONMENT:
2649 if (depth == par->params().depth()
2650 && environment_stack[depth] != style.latexname()) {
2651 sgmlCloseTag(ofs, depth,
2652 environment_stack[depth]);
2653 environment_stack[depth].erase();
2655 if (depth < par->params().depth()) {
2656 depth = par->params().depth();
2657 environment_stack[depth].erase();
2659 if (environment_stack[depth] != style.latexname()) {
2661 sgmlOpenTag(ofs, depth, "p");
2663 sgmlOpenTag(ofs, depth, style.latexname());
2665 if (environment_stack.size() == depth + 1)
2666 environment_stack.push_back("!-- --");
2667 environment_stack[depth] = style.latexname();
2670 if (style.latexparam() == "CDATA")
2673 if (style.latextype == LATEX_ENVIRONMENT) break;
2675 if (style.labeltype == LABEL_MANUAL)
2680 sgmlOpenTag(ofs, depth + 1, item_name);
2683 sgmlOpenTag(ofs, depth, style.latexname());
2687 simpleLinuxDocOnePar(ofs, par, depth);
2692 // write closing SGML tags
2693 switch (style.latextype) {
2696 case LATEX_ENVIRONMENT:
2697 case LATEX_ITEM_ENVIRONMENT:
2698 if (style.latexparam() == "CDATA")
2702 sgmlCloseTag(ofs, depth, style.latexname());
2708 for (int i=depth; i >= 0; --i)
2709 sgmlCloseTag(ofs, depth, environment_stack[i]);
2713 sgmlCloseTag(ofs, 0, top_element);
2717 // How to check for successful close
2721 void Buffer::docbookHandleCaption(ostream & os, string & inner_tag,
2722 Paragraph::depth_type depth, int desc_on,
2725 Paragraph * tpar = par;
2727 && (tpar->layout != textclasslist.NumberOfLayout(params.textclass,
2729 tpar = tpar->next();
2732 tpar->layout == textclasslist.NumberOfLayout(params.textclass,
2733 "Caption").second) {
2734 sgmlOpenTag(os, depth + 1, inner_tag);
2736 simpleDocBookOnePar(os, extra_par, tpar,
2737 desc_on, depth + 2);
2738 sgmlCloseTag(os, depth+1, inner_tag);
2739 if (!extra_par.empty())
2745 // checks, if newcol chars should be put into this line
2746 // writes newline, if necessary.
2749 void linux_doc_line_break(ostream & os, string::size_type & colcount,
2750 string::size_type newcol)
2753 if (colcount > lyxrc.ascii_linelen) {
2755 colcount = newcol; // assume write after this call
2770 string tag_name(PAR_TAG const & pt) {
2772 case NONE: return "!-- --";
2773 case TT: return "tt";
2774 case SF: return "sf";
2775 case BF: return "bf";
2776 case IT: return "it";
2777 case SL: return "sl";
2778 case EM: return "em";
2785 void operator|=(PAR_TAG & p1, PAR_TAG const & p2)
2787 p1 = static_cast<PAR_TAG>(p1 | p2);
2792 void reset(PAR_TAG & p1, PAR_TAG const & p2)
2794 p1 = static_cast<PAR_TAG>( p1 & ~p2);
2802 // Handle internal paragraph parsing -- layout already processed.
2803 void Buffer::simpleLinuxDocOnePar(ostream & os,
2805 Paragraph::depth_type /*depth*/)
2807 LyXLayout const & style = textclasslist.Style(params.textclass,
2809 string::size_type char_line_count = 5; // Heuristic choice ;-)
2811 // gets paragraph main font
2814 if (style.labeltype == LABEL_MANUAL) {
2815 font_old = style.labelfont;
2818 font_old = style.font;
2822 LyXFont::FONT_FAMILY family_type = LyXFont::ROMAN_FAMILY;
2823 LyXFont::FONT_SERIES series_type = LyXFont::MEDIUM_SERIES;
2824 LyXFont::FONT_SHAPE shape_type = LyXFont::UP_SHAPE;
2827 stack<PAR_TAG> tag_state;
2828 // parsing main loop
2829 for (Paragraph::size_type i = 0; i < par->size(); ++i) {
2831 PAR_TAG tag_close = NONE;
2832 list < PAR_TAG > tag_open;
2834 LyXFont const font = par->getFont(params, i);
2836 if (font_old.family() != font.family()) {
2837 switch (family_type) {
2838 case LyXFont::SANS_FAMILY:
2841 case LyXFont::TYPEWRITER_FAMILY:
2848 family_type = font.family();
2850 switch (family_type) {
2851 case LyXFont::SANS_FAMILY:
2852 tag_open.push_back(SF);
2854 case LyXFont::TYPEWRITER_FAMILY:
2855 tag_open.push_back(TT);
2862 if (font_old.series() != font.series()) {
2863 switch (series_type) {
2864 case LyXFont::BOLD_SERIES:
2871 series_type = font.series();
2873 switch (series_type) {
2874 case LyXFont::BOLD_SERIES:
2875 tag_open.push_back(BF);
2883 if (font_old.shape() != font.shape()) {
2884 switch (shape_type) {
2885 case LyXFont::ITALIC_SHAPE:
2888 case LyXFont::SLANTED_SHAPE:
2895 shape_type = font.shape();
2897 switch (shape_type) {
2898 case LyXFont::ITALIC_SHAPE:
2899 tag_open.push_back(IT);
2901 case LyXFont::SLANTED_SHAPE:
2902 tag_open.push_back(SL);
2909 if (font_old.emph() != font.emph()) {
2910 if (font.emph() == LyXFont::ON) {
2911 tag_open.push_back(EM);
2920 list < PAR_TAG > temp;
2921 while(!tag_state.empty() && tag_close ) {
2922 PAR_TAG k = tag_state.top();
2924 os << "</" << tag_name(k) << ">";
2931 for(list< PAR_TAG >::const_iterator j = temp.begin();
2932 j != temp.end(); ++j) {
2934 os << "<" << tag_name(*j) << ">";
2937 for(list< PAR_TAG >::const_iterator j = tag_open.begin();
2938 j != tag_open.end(); ++j) {
2940 os << "<" << tag_name(*j) << ">";
2943 char c = par->getChar(i);
2945 if (c == Paragraph::META_INSET) {
2946 Inset * inset = par->getInset(i);
2947 inset->linuxdoc(this, os);
2952 if (style.latexparam() == "CDATA") {
2953 // "TeX"-Mode on == > SGML-Mode on.
2959 if (par->linuxDocConvertChar(c, sgml_string)
2960 && !style.free_spacing) {
2961 // in freespacing mode, spaces are
2962 // non-breaking characters
2963 if (desc_on) {// if char is ' ' then...
2966 linux_doc_line_break(os, char_line_count, 6);
2970 linux_doc_line_break(os, char_line_count, 1);
2975 char_line_count += sgml_string.length();
2981 while (!tag_state.empty()) {
2982 os << "</" << tag_name(tag_state.top()) << ">";
2986 // resets description flag correctly
2988 // <tag> not closed...
2989 linux_doc_line_break(os, char_line_count, 6);
2995 // Print an error message.
2996 void Buffer::linuxDocError(Paragraph * par, int pos,
2997 string const & message)
2999 // insert an error marker in text
3000 InsetError * new_inset = new InsetError(message);
3001 par->insertInset(pos, new_inset);
3005 void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
3007 ofstream ofs(fname.c_str());
3009 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
3013 Paragraph * par = paragraph;
3015 niceFile = nice; // this will be used by Insetincludes.
3017 LyXTextClass const & tclass =
3018 textclasslist.TextClass(params.textclass);
3020 LaTeXFeatures features(params, tclass.numLayouts());
3025 string top_element = textclasslist.LatexnameOfClass(params.textclass);
3028 string sgml_includedfiles = features.getIncludedFiles(fname);
3030 ofs << "<!doctype " << top_element
3031 << " public \"-//OASIS//DTD DocBook V3.1//EN\"";
3033 if (params.preamble.empty() && sgml_includedfiles.empty())
3036 ofs << "\n [ " << params.preamble
3037 << sgml_includedfiles << " \n]>\n\n";
3040 string top = top_element;
3042 top += params.language->code();
3045 if (!params.options.empty()) {
3047 top += params.options;
3049 sgmlOpenTag(ofs, 0, top);
3051 ofs << "<!-- DocBook file was created by " << lyx_docversion
3052 << "\n See http://www.lyx.org/ for more information -->\n";
3054 vector<string> environment_stack(10);
3055 vector<string> environment_inner(10);
3056 vector<string> command_stack(10);
3058 bool command_flag = false;
3059 Paragraph::depth_type command_depth = 0;
3060 Paragraph::depth_type command_base = 0;
3061 Paragraph::depth_type cmd_depth = 0;
3062 Paragraph::depth_type depth = 0; // paragraph depth
3065 string command_name;
3071 int desc_on = 0; // description mode
3073 LyXLayout const & style =
3074 textclasslist.Style(params.textclass,
3077 // environment tag closing
3078 for (; depth > par->params().depth(); --depth) {
3079 if (environment_inner[depth] != "!-- --") {
3080 item_name = "listitem";
3081 sgmlCloseTag(ofs, command_depth + depth,
3083 if (environment_inner[depth] == "varlistentry")
3084 sgmlCloseTag(ofs, depth+command_depth,
3085 environment_inner[depth]);
3087 sgmlCloseTag(ofs, depth + command_depth,
3088 environment_stack[depth]);
3089 environment_stack[depth].erase();
3090 environment_inner[depth].erase();
3093 if (depth == par->params().depth()
3094 && environment_stack[depth] != style.latexname()
3095 && !environment_stack[depth].empty()) {
3096 if (environment_inner[depth] != "!-- --") {
3097 item_name= "listitem";
3098 sgmlCloseTag(ofs, command_depth+depth,
3100 if (environment_inner[depth] == "varlistentry")
3102 depth + command_depth,
3103 environment_inner[depth]);
3106 sgmlCloseTag(ofs, depth + command_depth,
3107 environment_stack[depth]);
3109 environment_stack[depth].erase();
3110 environment_inner[depth].erase();
3113 // Write opening SGML tags.
3114 switch (style.latextype) {
3115 case LATEX_PARAGRAPH:
3116 sgmlOpenTag(ofs, depth + command_depth,
3122 linuxDocError(par, 0,
3123 _("Error : Wrong depth for "
3124 "LatexType Command.\n"));
3126 command_name = style.latexname();
3128 sgmlparam = style.latexparam();
3129 c_params = split(sgmlparam, c_depth,'|');
3131 cmd_depth = lyx::atoi(c_depth);
3134 if (cmd_depth < command_base) {
3135 for (Paragraph::depth_type j = command_depth; j >= command_base; --j)
3136 sgmlCloseTag(ofs, j, command_stack[j]);
3137 command_depth = command_base = cmd_depth;
3138 } else if (cmd_depth <= command_depth) {
3139 for (int j = command_depth; j >= int(cmd_depth); --j)
3140 sgmlCloseTag(ofs, j, command_stack[j]);
3141 command_depth = cmd_depth;
3143 command_depth = cmd_depth;
3145 command_depth = command_base = cmd_depth;
3146 command_flag = true;
3148 if (command_stack.size() == command_depth + 1)
3149 command_stack.push_back(string());
3150 command_stack[command_depth] = command_name;
3152 // treat label as a special case for
3153 // more WYSIWYM handling.
3154 if (par->getChar(0) == Paragraph::META_INSET) {
3155 Inset * inset = par->getInset(0);
3156 Inset::Code lyx_code = inset->lyxCode();
3157 if (lyx_code == Inset::LABEL_CODE){
3158 command_name += " id=\"";
3159 command_name += (static_cast<InsetCommand *>(inset))->getContents();
3160 command_name += "\"";
3165 sgmlOpenTag(ofs, depth + command_depth, command_name);
3166 if (c_params.empty())
3167 item_name = "title";
3169 item_name = c_params;
3170 sgmlOpenTag(ofs, depth + 1 + command_depth, item_name);
3173 case LATEX_ENVIRONMENT:
3174 case LATEX_ITEM_ENVIRONMENT:
3175 if (depth < par->params().depth()) {
3176 depth = par->params().depth();
3177 environment_stack[depth].erase();
3180 if (environment_stack[depth] != style.latexname()) {
3181 if(environment_stack.size() == depth + 1) {
3182 environment_stack.push_back("!-- --");
3183 environment_inner.push_back("!-- --");
3185 environment_stack[depth] = style.latexname();
3186 environment_inner[depth] = "!-- --";
3187 sgmlOpenTag(ofs, depth + command_depth,
3188 environment_stack[depth]);
3190 if (environment_inner[depth] != "!-- --") {
3191 item_name= "listitem";
3193 command_depth + depth,
3195 if (environment_inner[depth] == "varlistentry")
3197 depth + command_depth,
3198 environment_inner[depth]);
3202 if (style.latextype == LATEX_ENVIRONMENT) {
3203 if (!style.latexparam().empty()) {
3204 if(style.latexparam() == "CDATA")
3207 sgmlOpenTag(ofs, depth + command_depth,
3208 style.latexparam());
3213 desc_on = (style.labeltype == LABEL_MANUAL);
3216 environment_inner[depth]= "varlistentry";
3218 environment_inner[depth]= "listitem";
3220 sgmlOpenTag(ofs, depth + 1 + command_depth,
3221 environment_inner[depth]);
3225 sgmlOpenTag(ofs, depth + 1 + command_depth,
3229 sgmlOpenTag(ofs, depth + 1 + command_depth,
3234 sgmlOpenTag(ofs, depth + command_depth,
3240 simpleDocBookOnePar(ofs, extra_par, par, desc_on,
3241 depth + 1 + command_depth);
3245 // write closing SGML tags
3246 switch (style.latextype) {
3248 if (c_params.empty())
3252 sgmlCloseTag(ofs, depth + command_depth, end_tag);
3254 case LATEX_ENVIRONMENT:
3255 if (!style.latexparam().empty()) {
3256 if(style.latexparam() == "CDATA")
3259 sgmlCloseTag(ofs, depth + command_depth,
3260 style.latexparam());
3263 case LATEX_ITEM_ENVIRONMENT:
3264 if (desc_on == 1) break;
3266 sgmlCloseTag(ofs, depth + 1 + command_depth, end_tag);
3268 case LATEX_PARAGRAPH:
3269 sgmlCloseTag(ofs, depth + command_depth, style.latexname());
3272 sgmlCloseTag(ofs, depth + command_depth, style.latexname());
3278 for (int d = depth; d >= 0; --d) {
3279 if (!environment_stack[depth].empty()) {
3280 if (environment_inner[depth] != "!-- --") {
3281 item_name = "listitem";
3282 sgmlCloseTag(ofs, command_depth + depth,
3284 if (environment_inner[depth] == "varlistentry")
3285 sgmlCloseTag(ofs, depth + command_depth,
3286 environment_inner[depth]);
3289 sgmlCloseTag(ofs, depth + command_depth,
3290 environment_stack[depth]);
3294 for (int j = command_depth; j >= 0 ; --j)
3295 if (!command_stack[j].empty())
3296 sgmlCloseTag(ofs, j, command_stack[j]);
3299 sgmlCloseTag(ofs, 0, top_element);
3302 // How to check for successful close
3306 void Buffer::simpleDocBookOnePar(ostream & os, string & extra,
3307 Paragraph * par, int & desc_on,
3308 Paragraph::depth_type depth) const
3310 bool emph_flag = false;
3312 LyXLayout const & style = textclasslist.Style(params.textclass,
3315 LyXFont font_old = style.labeltype == LABEL_MANUAL ? style.labelfont : style.font;
3317 int char_line_count = depth;
3318 //if (!style.free_spacing)
3319 // os << string(depth,' ');
3321 // parsing main loop
3322 for (Paragraph::size_type i = 0;
3323 i < par->size(); ++i) {
3324 LyXFont font = par->getFont(params, i);
3326 // handle <emphasis> tag
3327 if (font_old.emph() != font.emph()) {
3328 if (font.emph() == LyXFont::ON) {
3332 os << "</emphasis>";
3337 char c = par->getChar(i);
3339 if (c == Paragraph::META_INSET) {
3340 Inset * inset = par->getInset(i);
3342 inset->docbook(this, ost);
3343 string tmp_out = ost.str().c_str();
3346 // This code needs some explanation:
3347 // Two insets are treated specially
3348 // label if it is the first element in a command paragraph
3350 // graphics inside tables or figure floats can't go on
3351 // title (the equivalente in latex for this case is caption
3352 // and title should come first
3355 if (desc_on!= 3 || i!= 0) {
3356 if (!tmp_out.empty() && tmp_out[0] == '@') {
3358 extra += frontStrip(tmp_out, '@');
3360 os << frontStrip(tmp_out, '@');
3367 par->linuxDocConvertChar(c, sgml_string);
3369 if (style.pass_thru) {
3371 } else if(style.free_spacing || c != ' ') {
3373 } else if (desc_on ==1) {
3375 os << "\n</term><listitem><para>";
3385 os << "</emphasis>";
3388 // resets description flag correctly
3390 // <term> not closed...
3393 if(style.free_spacing) os << '\n';
3397 // This should be enabled when the Chktex class is implemented. (Asger)
3398 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
3399 // Other flags: -wall -v0 -x
3400 int Buffer::runChktex()
3402 if (!users->text) return 0;
3404 users->owner()->prohibitInput();
3406 // get LaTeX-Filename
3407 string const name = getLatexName();
3408 string path = OnlyPath(filename);
3410 string const org_path = path;
3411 if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
3415 Path p(path); // path to LaTeX file
3416 users->owner()->message(_("Running chktex..."));
3418 // Remove all error insets
3419 bool const removedErrorInsets = users->removeAutoInsets();
3421 // Generate the LaTeX file if neccessary
3422 makeLaTeXFile(name, org_path, false);
3425 Chktex chktex(lyxrc.chktex_command, name, filepath);
3426 int res = chktex.run(terr); // run chktex
3429 WriteAlert(_("chktex did not work!"),
3430 _("Could not run with file:"), name);
3431 } else if (res > 0) {
3432 // Insert all errors as errors boxes
3433 users->insertErrors(terr);
3436 // if we removed error insets before we ran chktex or if we inserted
3437 // error insets after we ran chktex, this must be run:
3438 if (removedErrorInsets || res){
3442 users->owner()->allowInput();
3448 void Buffer::validate(LaTeXFeatures & features) const
3450 Paragraph * par = paragraph;
3451 LyXTextClass const & tclass =
3452 textclasslist.TextClass(params.textclass);
3454 // AMS Style is at document level
3455 features.amsstyle = (params.use_amsmath ||
3456 tclass.provides(LyXTextClass::amsmath));
3459 // We don't use "lyxerr.debug" because of speed. (Asger)
3460 if (lyxerr.debugging(Debug::LATEX))
3461 lyxerr << "Paragraph: " << par << endl;
3463 // Now just follow the list of paragraphs and run
3464 // validate on each of them.
3465 par->validate(features);
3467 // and then the next paragraph
3471 // the bullet shapes are buffer level not paragraph level
3472 // so they are tested here
3473 for (int i = 0; i < 4; ++i) {
3474 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
3475 int const font = params.user_defined_bullets[i].getFont();
3477 int const c = params
3478 .user_defined_bullets[i]
3485 features.latexsym = true;
3487 } else if (font == 1) {
3488 features.amssymb = true;
3489 } else if ((font >= 2 && font <= 5)) {
3490 features.pifont = true;
3495 if (lyxerr.debugging(Debug::LATEX)) {
3496 features.showStruct();
3501 void Buffer::setPaperStuff()
3503 params.papersize = BufferParams::PAPER_DEFAULT;
3504 char const c1 = params.paperpackage;
3505 if (c1 == BufferParams::PACKAGE_NONE) {
3506 char const c2 = params.papersize2;
3507 if (c2 == BufferParams::VM_PAPER_USLETTER)
3508 params.papersize = BufferParams::PAPER_USLETTER;
3509 else if (c2 == BufferParams::VM_PAPER_USLEGAL)
3510 params.papersize = BufferParams::PAPER_LEGALPAPER;
3511 else if (c2 == BufferParams::VM_PAPER_USEXECUTIVE)
3512 params.papersize = BufferParams::PAPER_EXECUTIVEPAPER;
3513 else if (c2 == BufferParams::VM_PAPER_A3)
3514 params.papersize = BufferParams::PAPER_A3PAPER;
3515 else if (c2 == BufferParams::VM_PAPER_A4)
3516 params.papersize = BufferParams::PAPER_A4PAPER;
3517 else if (c2 == BufferParams::VM_PAPER_A5)
3518 params.papersize = BufferParams::PAPER_A5PAPER;
3519 else if ((c2 == BufferParams::VM_PAPER_B3) || (c2 == BufferParams::VM_PAPER_B4) ||
3520 (c2 == BufferParams::VM_PAPER_B5))
3521 params.papersize = BufferParams::PAPER_B5PAPER;
3522 } else if ((c1 == BufferParams::PACKAGE_A4) || (c1 == BufferParams::PACKAGE_A4WIDE) ||
3523 (c1 == BufferParams::PACKAGE_WIDEMARGINSA4))
3524 params.papersize = BufferParams::PAPER_A4PAPER;
3528 // This function should be in Buffer because it's a buffer's property (ale)
3529 string const Buffer::getIncludeonlyList(char delim)
3532 for (inset_iterator it = inset_iterator_begin();
3533 it != inset_iterator_end(); ++it) {
3534 if ((*it)->lyxCode() == Inset::INCLUDE_CODE) {
3535 InsetInclude * insetinc =
3536 static_cast<InsetInclude *>(*it);
3537 if (insetinc->isIncludeOnly()) {
3540 lst += insetinc->getRelFileBaseName();
3544 lyxerr[Debug::INFO] << "Includeonly(" << lst << ')' << endl;
3549 vector<string> const Buffer::getLabelList()
3551 /// if this is a child document and the parent is already loaded
3552 /// Use the parent's list instead [ale990407]
3553 if (!params.parentname.empty()
3554 && bufferlist.exists(params.parentname)) {
3555 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3557 return tmp->getLabelList();
3560 vector<string> label_list;
3561 for (inset_iterator it = inset_iterator_begin();
3562 it != inset_iterator_end(); ++it) {
3563 vector<string> const l = (*it)->getLabelList();
3564 label_list.insert(label_list.end(), l.begin(), l.end());
3570 Buffer::Lists const Buffer::getLists() const
3573 Paragraph * par = paragraph;
3576 std::pair<bool, LyXTextClassList::size_type> const tmp =
3577 textclasslist.NumberOfLayout(params.textclass, "Caption");
3578 bool const found = tmp.first;
3579 LyXTextClassList::size_type const cap = tmp.second;
3582 // This is the prefered way to to this, but boost::tie can break
3585 LyXTextClassList::size_type cap;
3586 boost::tie(found, cap) = textclasslist
3587 .NumberOfLayout(params.textclass, "Caption");
3591 char const labeltype =
3592 textclasslist.Style(params.textclass,
3593 par->getLayout()).labeltype;
3595 if (labeltype >= LABEL_COUNTER_CHAPTER
3596 && labeltype <= LABEL_COUNTER_CHAPTER + params.tocdepth) {
3597 // insert this into the table of contents
3598 SingleList & item = l["TOC"];
3601 textclasslist.TextClass(params.textclass).maxcounter());
3602 item.push_back(TocItem(par, depth, par->asString(this, true)));
3604 // For each paragrph, traverse its insets and look for
3608 Paragraph::inset_iterator it =
3609 par->inset_iterator_begin();
3610 Paragraph::inset_iterator end =
3611 par->inset_iterator_end();
3613 for (; it != end; ++it) {
3614 if ((*it)->lyxCode() == Inset::FLOAT_CODE) {
3616 static_cast<InsetFloat*>(*it);
3618 string const type = il->type();
3620 // Now find the caption in the float...
3621 // We now tranverse the paragraphs of
3623 Paragraph * tmp = il->inset.paragraph();
3625 if (tmp->layout == cap) {
3626 SingleList & item = l[type];
3628 tostr(item.size()+1) + ". " + tmp->asString(this, false);
3629 item.push_back(TocItem(tmp, 0 , str));
3636 lyxerr << "caption not found" << endl;
3645 // This is also a buffer property (ale)
3646 vector<pair<string, string> > const Buffer::getBibkeyList()
3648 /// if this is a child document and the parent is already loaded
3649 /// Use the parent's list instead [ale990412]
3650 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3651 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3653 return tmp->getBibkeyList();
3656 vector<pair<string, string> > keys;
3657 Paragraph * par = paragraph;
3660 keys.push_back(pair<string, string>(par->bibkey->getContents(),
3661 par->asString(this, false)));
3665 // Might be either using bibtex or a child has bibliography
3667 for (inset_iterator it = inset_iterator_begin();
3668 it != inset_iterator_end(); ++it) {
3669 // Search for Bibtex or Include inset
3670 if ((*it)->lyxCode() == Inset::BIBTEX_CODE) {
3671 vector<pair<string,string> > tmp =
3672 static_cast<InsetBibtex*>(*it)->getKeys(this);
3673 keys.insert(keys.end(), tmp.begin(), tmp.end());
3674 } else if ((*it)->lyxCode() == Inset::INCLUDE_CODE) {
3675 vector<pair<string,string> > const tmp =
3676 static_cast<InsetInclude*>(*it)->getKeys();
3677 keys.insert(keys.end(), tmp.begin(), tmp.end());
3686 bool Buffer::isDepClean(string const & name) const
3688 DEPCLEAN * item = dep_clean;
3689 while (item && item->master != name)
3691 if (!item) return true;
3696 void Buffer::markDepClean(string const & name)
3699 dep_clean = new DEPCLEAN;
3700 dep_clean->clean = true;
3701 dep_clean->master = name;
3702 dep_clean->next = 0;
3704 DEPCLEAN * item = dep_clean;
3705 while (item && item->master != name)
3710 item = new DEPCLEAN;
3712 item->master = name;
3719 bool Buffer::dispatch(string const & command)
3721 // Split command string into command and argument
3723 string line = frontStrip(command);
3724 string const arg = strip(frontStrip(split(line, cmd, ' ')));
3726 return dispatch(lyxaction.LookupFunc(cmd), arg);
3730 bool Buffer::dispatch(int action, string const & argument)
3732 bool dispatched = true;
3735 Exporter::Export(this, argument, false);
3745 void Buffer::resizeInsets(BufferView * bv)
3747 /// then remove all LyXText in text-insets
3748 Paragraph * par = paragraph;
3749 for (; par; par = par->next()) {
3750 par->resizeInsetsLyXText(bv);
3755 void Buffer::redraw()
3762 void Buffer::changeLanguage(Language const * from, Language const * to)
3765 ParIterator end = par_iterator_end();
3766 for (ParIterator it = par_iterator_begin(); it != end; ++it)
3767 (*it)->changeLanguage(params, from, to);
3771 bool Buffer::isMultiLingual()
3773 ParIterator end = par_iterator_end();
3774 for (ParIterator it = par_iterator_begin(); it != end; ++it)
3775 if ((*it)->isMultiLingual(params))
3782 Buffer::inset_iterator::inset_iterator(Paragraph * paragraph,
3783 Paragraph::size_type pos)
3786 it = par->InsetIterator(pos);
3787 if (it == par->inset_iterator_end()) {
3794 void Buffer::inset_iterator::setParagraph()
3797 it = par->inset_iterator_begin();
3798 if (it != par->inset_iterator_end())
3803 // We maintain an invariant that whenever par = 0 then it = 0
3807 Inset * Buffer::getInsetFromID(int id_arg) const
3809 for (inset_iterator it = inset_const_iterator_begin();
3810 it != inset_const_iterator_end(); ++it)
3812 if ((*it)->id() == id_arg)
3814 Inset * in = (*it)->getInsetFromID(id_arg);
3822 Paragraph * Buffer::getParFromID(int id) const
3824 if (id < 0) return 0;
3825 Paragraph * par = paragraph;
3827 if (par->id() == id) {
3830 Paragraph * tmp = par->getParFromID(id);
3840 ParIterator Buffer::par_iterator_begin()
3842 return ParIterator(paragraph);
3846 ParIterator Buffer::par_iterator_end()
3848 return ParIterator();