1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2000 The LyX Team.
9 * This file is Copyright 1996-1999
12 * ======================================================
26 #include <sys/types.h>
36 #pragma implementation "buffer.h"
40 #include "bufferlist.h"
42 #include "lyx_gui_misc.h"
43 #include "LyXAction.h"
46 #include "tex-strings.h"
48 #include "bufferview_funcs.h"
49 #include "minibuffer.h"
52 #include "mathed/formulamacro.h"
53 #include "insets/lyxinset.h"
54 #include "insets/inseterror.h"
55 #include "insets/insetlabel.h"
56 #include "insets/insetref.h"
57 #include "insets/inseturl.h"
58 #include "insets/insetinfo.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/insetlist.h"
78 #include "insets/insettabular.h"
79 #include "insets/insettheorem.h"
80 #include "insets/insetcaption.h"
81 #include "support/filetools.h"
82 #include "support/path.h"
87 #include "LaTeXFeatures.h"
88 #include "support/syscall.h"
89 #include "support/lyxlib.h"
90 #include "support/FileInfo.h"
91 #include "support/lyxmanip.h"
95 #include "lyx_gui_misc.h" // WarnReadonly()
96 #include "frontends/Dialogs.h"
100 #include "converter.h"
102 using std::stringstream;
111 using std::make_pair;
119 // all these externs should eventually be removed.
120 extern BufferList bufferlist;
122 extern LyXAction lyxaction;
126 const int LYX_FORMAT = 218;
130 extern int tex_code_break_column;
133 Buffer::Buffer(string const & file, bool ronly)
135 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
137 filepath = OnlyPath(file);
146 if (read_only || (lyxrc.use_tempdir)) {
147 tmppath = CreateBufferTmpDir();
148 } else tmppath.erase();
154 lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
155 // here the buffer should take care that it is
156 // saved properly, before it goes into the void.
158 // make sure that views using this buffer
163 if (!tmppath.empty()) {
164 DestroyBufferTmpDir(tmppath);
167 LyXParagraph * par = paragraph;
168 LyXParagraph * tmppar;
177 tmppar = par->next();
186 string const Buffer::getLatexName(bool no_path) const
189 return OnlyFilename(ChangeExtension(MakeLatexName(filename),
192 return ChangeExtension(MakeLatexName(filename),
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) < 1))
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 LyXParagraph;
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 // candidate for move to BufferView
287 // (at least some parts in the beginning of the func)
290 // changed to be public and have one parameter
291 // if par = 0 normal behavior
292 // else insert behavior
293 // Returns false if "\the_end" is not read for formats >= 2.13. (Asger)
294 bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par)
297 char depth = 0; // signed or unsigned?
299 LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
300 LyXParagraph::footnote_kind footnotekind = LyXParagraph::FOOTNOTE;
302 bool the_end_read = false;
304 LyXParagraph * return_par = 0;
305 LyXFont font(LyXFont::ALL_INHERIT, params.language);
306 if (file_format < 216 && params.language->lang() == "hebrew")
307 font.setLanguage(default_language);
308 // If we are inserting, we cheat and get a token in advance
309 bool has_token = false;
313 par = new LyXParagraph;
315 users->text->BreakParagraph(users);
316 return_par = users->text->FirstParagraph();
319 // We don't want to adopt the parameters from the
320 // document we insert, so we skip until the text begins:
323 pretoken = lex.GetString();
324 if (pretoken == "\\layout") {
336 pretoken = lex.GetString();
339 if (pretoken.empty()) continue;
342 parseSingleLyXformat2Token(lex, par, return_par,
343 pretoken, pos, depth,
355 paragraph = return_par;
361 // We'll remove this later. (Lgb)
364 string last_inset_read;
370 Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
371 LyXParagraph *& return_par,
372 string const & token, int & pos,
373 char & depth, LyXFont & font
375 , LyXParagraph::footnote_flag & footnoteflag,
376 LyXParagraph::footnote_kind & footnotekind
380 bool the_end_read = false;
381 #ifndef NO_PEXTRA_REALLY
383 // This is super temporary but is needed to get the compability
384 // mode for minipages work correctly together with new tabulars.
385 static int call_depth = 0;
388 bool checkminipage = false;
389 static LyXParagraph * minipar = 0;
390 static LyXParagraph * parBeforeMinipage = 0;
393 if (token[0] != '\\') {
394 for (string::const_iterator cit = token.begin();
395 cit != token.end(); ++cit)
397 par->InsertChar(pos, (*cit), font);
400 checkminipage = true;
401 } else if (token == "\\i") {
402 Inset * inset = new InsetLatexAccent;
403 inset->Read(this, lex);
404 par->InsertInset(pos, inset, font);
406 } else if (token == "\\layout") {
412 par = new LyXParagraph(par);
416 string const layoutname = lex.GetString();
417 pair<bool, LyXTextClass::LayoutList::size_type> pp
418 = textclasslist.NumberOfLayout(params.textclass,
421 par->layout = pp.second;
422 } else { // layout not found
423 // use default layout "Standard" (0)
426 // Test whether the layout is obsolete.
427 LyXLayout const & layout =
428 textclasslist.Style(params.textclass,
430 if (!layout.obsoleted_by().empty())
432 textclasslist.NumberOfLayout(params.textclass,
433 layout.obsoleted_by()).second;
434 par->footnoteflag = footnoteflag;
435 par->footnotekind = footnotekind;
436 par->params.depth(depth);
437 font = LyXFont(LyXFont::ALL_INHERIT, params.language);
438 if (file_format < 216 && params.language->lang() == "hebrew")
439 font.setLanguage(default_language);
442 string const layoutname = lex.GetString();
443 pair<bool, LyXTextClass::LayoutList::size_type> pp
444 = textclasslist.NumberOfLayout(params.textclass,
448 // The is the compability reading of layout caption.
449 // It can be removed in LyX version 1.3.0. (Lgb)
450 if (compare_no_case(layoutname, "caption") == 0) {
451 // We expect that the par we are now working on is
452 // really inside a InsetText inside a InsetFloat.
453 // We also know that captions can only be
454 // one paragraph. (Lgb)
456 // We should now read until the next "\layout"
458 // This is probably not good enough, what if the
459 // caption is the last par in the document (Lgb)
460 istream & ist = lex.getStream();
466 if (prefixIs(line, "\\layout")) {
470 if (prefixIs(line, "\\begin_inset"))
472 if (prefixIs(line, "\\end_inset")) {
483 // Now we should have the whole layout in ss
484 // we should now be able to give this to the
486 ss << "\\end_inset\n";
488 // This seems like a bug in stringstream.
489 // We really should be able to use ss
491 istringstream is(ss.str());
493 tmplex.setStream(is);
494 Inset * inset = new InsetCaption;
495 inset->Read(this, tmplex);
496 par->InsertInset(pos, inset, font);
504 par = new LyXParagraph(par);
508 par->layout = pp.second;
511 // use default layout "Standard" (0)
514 // Test whether the layout is obsolete.
515 LyXLayout const & layout =
516 textclasslist.Style(params.textclass,
518 if (!layout.obsoleted_by().empty())
519 par->layout = textclasslist
520 .NumberOfLayout(params.textclass,
521 layout.obsoleted_by())
523 par->params.depth(depth);
524 font = LyXFont(LyXFont::ALL_INHERIT, params.language);
525 if (file_format < 216
526 && params.language->lang() == "hebrew")
527 font.setLanguage(default_language);
533 } else if (token == "\\end_float") {
538 par = new LyXParagraph(par);
540 footnotekind = LyXParagraph::FOOTNOTE;
541 footnoteflag = LyXParagraph::NO_FOOTNOTE;
544 par->layout = LYX_DUMMY_LAYOUT;
545 font = LyXFont(LyXFont::ALL_INHERIT, params.language);
546 if (file_format < 216 && params.language->lang() == "hebrew")
547 font.setLanguage(default_language);
548 } else if (token == "\\begin_float") {
549 int tmpret = lex.FindToken(string_footnotekinds);
550 if (tmpret == -1) ++tmpret;
551 if (tmpret != LYX_LAYOUT_DEFAULT)
552 footnotekind = static_cast<LyXParagraph::footnote_kind>(tmpret); // bad
553 if (footnotekind == LyXParagraph::FOOTNOTE
554 || footnotekind == LyXParagraph::MARGIN)
555 footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
557 footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
559 } else if (token == "\\begin_float") {
560 // This is the compability reader. It can be removed in
561 // LyX version 1.3.0. (Lgb)
563 string const tmptok = lex.GetString();
564 //lyxerr << "old float: " << tmptok << endl;
567 stringstream old_float;
569 if (tmptok == "footnote") {
570 inset = new InsetFoot;
571 } else if (tmptok == "margin") {
572 inset = new InsetMarginal;
573 } else if (tmptok == "fig") {
574 inset = new InsetFloat("figure");
575 old_float << "placement htbp\n";
576 } else if (tmptok == "tab") {
577 inset = new InsetFloat("table");
578 old_float << "placement htbp\n";
579 } else if (tmptok == "alg") {
580 inset = new InsetFloat("algorithm");
581 old_float << "placement htbp\n";
582 } else if (tmptok == "wide-fig") {
583 InsetFloat * tmp = new InsetFloat("figure");
586 old_float << "placement htbp\n";
587 } else if (tmptok == "wide-tab") {
588 InsetFloat * tmp = new InsetFloat("table");
591 old_float << "placement htbp\n";
596 return false; // no end read yet
599 old_float << "collapsed true\n";
601 // Here we need to check for \end_deeper and handle that
602 // before we do the footnote parsing.
603 // This _is_ a hack! (Lgb)
606 string const tmp = lex.GetString();
607 if (tmp == "\\end_deeper") {
608 //lyxerr << "\\end_deeper caught!" << endl;
610 lex.printError("\\end_deeper: "
611 "depth is already null");
616 old_float << tmp << ' ';
621 old_float << lex.getLongString("\\end_float")
622 << "\n\\end_inset\n";
623 //lyxerr << "Float Body:\n" << old_float.str() << endl;
624 // That this does not work seems like a bug
625 // in stringstream. (Lgb)
626 istringstream istr(old_float.str());
628 nylex.setStream(istr);
629 inset->Read(this, nylex);
630 par->InsertInset(pos, inset, font);
633 } else if (token == "\\begin_deeper") {
635 } else if (token == "\\end_deeper") {
637 lex.printError("\\end_deeper: "
638 "depth is already null");
642 } else if (token == "\\begin_preamble") {
643 params.readPreamble(lex);
644 } else if (token == "\\textclass") {
646 pair<bool, LyXTextClassList::size_type> pp =
647 textclasslist.NumberOfClass(lex.GetString());
649 params.textclass = pp.second;
651 WriteAlert(string(_("Textclass error")),
652 string(_("The document uses an unknown textclass \"")) +
653 lex.GetString() + string("\"."),
654 string(_("LyX will not be able to produce output correctly.")));
655 params.textclass = 0;
657 if (!textclasslist.Load(params.textclass)) {
658 // if the textclass wasn't loaded properly
659 // we need to either substitute another
660 // or stop loading the file.
661 // I can substitute but I don't see how I can
662 // stop loading... ideas?? ARRae980418
663 WriteAlert(_("Textclass Loading Error!"),
664 string(_("Can't load textclass ")) +
665 textclasslist.NameOfClass(params.textclass),
666 _("-- substituting default"));
667 params.textclass = 0;
669 } else if (token == "\\options") {
671 params.options = lex.GetString();
672 } else if (token == "\\language") {
673 params.readLanguage(lex);
674 } else if (token == "\\fontencoding") {
676 } else if (token == "\\inputencoding") {
678 params.inputenc = lex.GetString();
679 } else if (token == "\\graphics") {
680 params.readGraphicsDriver(lex);
681 } else if (token == "\\fontscheme") {
683 params.fonts = lex.GetString();
684 } else if (token == "\\noindent") {
685 par->params.noindent(true);
686 } else if (token == "\\fill_top") {
687 par->params.spaceTop(VSpace(VSpace::VFILL));
688 } else if (token == "\\fill_bottom") {
689 par->params.spaceBottom(VSpace(VSpace::VFILL));
690 } else if (token == "\\line_top") {
691 par->params.lineTop(true);
692 } else if (token == "\\line_bottom") {
693 par->params.lineBottom(true);
694 } else if (token == "\\pagebreak_top") {
695 par->params.pagebreakTop(true);
696 } else if (token == "\\pagebreak_bottom") {
697 par->params.pagebreakBottom(true);
698 } else if (token == "\\start_of_appendix") {
699 par->params.startOfAppendix(true);
700 } else if (token == "\\paragraph_separation") {
701 int tmpret = lex.FindToken(string_paragraph_separation);
702 if (tmpret == -1) ++tmpret;
703 if (tmpret != LYX_LAYOUT_DEFAULT)
704 params.paragraph_separation =
705 static_cast<BufferParams::PARSEP>(tmpret);
706 } else if (token == "\\defskip") {
708 params.defskip = VSpace(lex.GetString());
709 } else if (token == "\\epsfig") { // obsolete
710 // Indeed it is obsolete, but we HAVE to be backwards
711 // compatible until 0.14, because otherwise all figures
712 // in existing documents are irretrivably lost. (Asger)
713 params.readGraphicsDriver(lex);
714 } else if (token == "\\quotes_language") {
715 int tmpret = lex.FindToken(string_quotes_language);
716 if (tmpret == -1) ++tmpret;
717 if (tmpret != LYX_LAYOUT_DEFAULT) {
718 InsetQuotes::quote_language tmpl =
719 InsetQuotes::EnglishQ;
722 tmpl = InsetQuotes::EnglishQ;
725 tmpl = InsetQuotes::SwedishQ;
728 tmpl = InsetQuotes::GermanQ;
731 tmpl = InsetQuotes::PolishQ;
734 tmpl = InsetQuotes::FrenchQ;
737 tmpl = InsetQuotes::DanishQ;
740 params.quotes_language = tmpl;
742 } else if (token == "\\quotes_times") {
744 switch (lex.GetInteger()) {
746 params.quotes_times = InsetQuotes::SingleQ;
749 params.quotes_times = InsetQuotes::DoubleQ;
752 } else if (token == "\\papersize") {
753 int tmpret = lex.FindToken(string_papersize);
757 params.papersize2 = tmpret;
758 } else if (token == "\\paperpackage") {
759 int tmpret = lex.FindToken(string_paperpackages);
762 params.paperpackage = BufferParams::PACKAGE_NONE;
764 params.paperpackage = tmpret;
765 } else if (token == "\\use_geometry") {
767 params.use_geometry = lex.GetInteger();
768 } else if (token == "\\use_amsmath") {
770 params.use_amsmath = lex.GetInteger();
771 } else if (token == "\\paperorientation") {
772 int tmpret = lex.FindToken(string_orientation);
773 if (tmpret == -1) ++tmpret;
774 if (tmpret != LYX_LAYOUT_DEFAULT)
775 params.orientation = static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
776 } else if (token == "\\paperwidth") {
778 params.paperwidth = lex.GetString();
779 } else if (token == "\\paperheight") {
781 params.paperheight = lex.GetString();
782 } else if (token == "\\leftmargin") {
784 params.leftmargin = lex.GetString();
785 } else if (token == "\\topmargin") {
787 params.topmargin = lex.GetString();
788 } else if (token == "\\rightmargin") {
790 params.rightmargin = lex.GetString();
791 } else if (token == "\\bottommargin") {
793 params.bottommargin = lex.GetString();
794 } else if (token == "\\headheight") {
796 params.headheight = lex.GetString();
797 } else if (token == "\\headsep") {
799 params.headsep = lex.GetString();
800 } else if (token == "\\footskip") {
802 params.footskip = lex.GetString();
803 } else if (token == "\\paperfontsize") {
805 params.fontsize = strip(lex.GetString());
806 } else if (token == "\\papercolumns") {
808 params.columns = lex.GetInteger();
809 } else if (token == "\\papersides") {
811 switch (lex.GetInteger()) {
813 case 1: params.sides = LyXTextClass::OneSide; break;
814 case 2: params.sides = LyXTextClass::TwoSides; break;
816 } else if (token == "\\paperpagestyle") {
818 params.pagestyle = strip(lex.GetString());
819 } else if (token == "\\bullet") {
821 int const index = lex.GetInteger();
823 int temp_int = lex.GetInteger();
824 params.user_defined_bullets[index].setFont(temp_int);
825 params.temp_bullets[index].setFont(temp_int);
827 temp_int = lex.GetInteger();
828 params.user_defined_bullets[index].setCharacter(temp_int);
829 params.temp_bullets[index].setCharacter(temp_int);
831 temp_int = lex.GetInteger();
832 params.user_defined_bullets[index].setSize(temp_int);
833 params.temp_bullets[index].setSize(temp_int);
835 string const temp_str = lex.GetString();
836 if (temp_str != "\\end_bullet") {
837 // this element isn't really necessary for
838 // parsing but is easier for humans
839 // to understand bullets. Put it back and
840 // set a debug message?
841 lex.printError("\\end_bullet expected, got" + temp_str);
842 //how can I put it back?
844 } else if (token == "\\bulletLaTeX") {
846 int const index = lex.GetInteger();
848 string temp_str = lex.GetString();
850 while (temp_str != "\\end_bullet") {
851 // this loop structure is needed when user
852 // enters an empty string since the first
853 // thing returned will be the \\end_bullet
855 // if the LaTeX entry has spaces. Each element
856 // therefore needs to be read in turn
859 temp_str = lex.GetString();
861 params.user_defined_bullets[index].setText(sum_str);
862 params.temp_bullets[index].setText(sum_str);
863 } else if (token == "\\secnumdepth") {
865 params.secnumdepth = lex.GetInteger();
866 } else if (token == "\\tocdepth") {
868 params.tocdepth = lex.GetInteger();
869 } else if (token == "\\spacing") {
871 string const tmp = strip(lex.GetString());
872 Spacing::Space tmp_space = Spacing::Default;
874 if (tmp == "single") {
875 tmp_space = Spacing::Single;
876 } else if (tmp == "onehalf") {
877 tmp_space = Spacing::Onehalf;
878 } else if (tmp == "double") {
879 tmp_space = Spacing::Double;
880 } else if (tmp == "other") {
882 tmp_space = Spacing::Other;
883 tmp_val = lex.GetFloat();
885 lex.printError("Unknown spacing token: '$$Token'");
887 // Small hack so that files written with klyx will be
890 par->params.spacing(Spacing(tmp_space, tmp_val));
892 params.spacing.set(tmp_space, tmp_val);
894 } else if (token == "\\paragraph_spacing") {
896 string const tmp = strip(lex.GetString());
897 if (tmp == "single") {
898 par->params.spacing(Spacing(Spacing::Single));
899 } else if (tmp == "onehalf") {
900 par->params.spacing(Spacing(Spacing::Onehalf));
901 } else if (tmp == "double") {
902 par->params.spacing(Spacing(Spacing::Double));
903 } else if (tmp == "other") {
905 par->params.spacing(Spacing(Spacing::Other,
908 lex.printError("Unknown spacing token: '$$Token'");
910 } else if (token == "\\float_placement") {
912 params.float_placement = lex.GetString();
913 } else if (token == "\\family") {
915 font.setLyXFamily(lex.GetString());
916 } else if (token == "\\series") {
918 font.setLyXSeries(lex.GetString());
919 } else if (token == "\\shape") {
921 font.setLyXShape(lex.GetString());
922 } else if (token == "\\size") {
924 font.setLyXSize(lex.GetString());
925 } else if (token == "\\latex") {
927 string const tok = lex.GetString();
928 // This is dirty, but gone with LyX3. (Asger)
929 if (tok == "no_latex")
930 font.setLatex(LyXFont::OFF);
931 else if (tok == "latex")
932 font.setLatex(LyXFont::ON);
933 else if (tok == "default")
934 font.setLatex(LyXFont::INHERIT);
936 lex.printError("Unknown LaTeX font flag "
938 } else if (token == "\\lang") {
940 string const tok = lex.GetString();
941 Language const * lang = languages.getLanguage(tok);
943 font.setLanguage(lang);
945 font.setLanguage(params.language);
946 lex.printError("Unknown language `$$Token'");
948 } else if (token == "\\numeric") {
950 font.setNumber(font.setLyXMisc(lex.GetString()));
951 } else if (token == "\\emph") {
953 font.setEmph(font.setLyXMisc(lex.GetString()));
954 } else if (token == "\\bar") {
956 string const tok = lex.GetString();
957 // This is dirty, but gone with LyX3. (Asger)
959 font.setUnderbar(LyXFont::ON);
960 else if (tok == "no")
961 font.setUnderbar(LyXFont::OFF);
962 else if (tok == "default")
963 font.setUnderbar(LyXFont::INHERIT);
965 lex.printError("Unknown bar font flag "
967 } else if (token == "\\noun") {
969 font.setNoun(font.setLyXMisc(lex.GetString()));
970 } else if (token == "\\color") {
972 font.setLyXColor(lex.GetString());
973 } else if (token == "\\align") {
974 int tmpret = lex.FindToken(string_align);
975 if (tmpret == -1) ++tmpret;
976 if (tmpret != LYX_LAYOUT_DEFAULT) { // tmpret != 99 ???
977 int const tmpret2 = int(pow(2.0, tmpret));
978 //lyxerr << "Tmpret2 = " << tmpret2 << endl;
979 par->params.align(LyXAlignment(tmpret2));
981 } else if (token == "\\added_space_top") {
983 par->params.spaceTop(VSpace(lex.GetString()));
984 } else if (token == "\\added_space_bottom") {
986 par->params.spaceBottom(VSpace(lex.GetString()));
987 #ifndef NO_PEXTRA_REALLY
988 } else if (token == "\\pextra_type") {
990 par->params.pextraType(lex.GetInteger());
991 } else if (token == "\\pextra_width") {
993 par->params.pextraWidth(lex.GetString());
994 } else if (token == "\\pextra_widthp") {
996 par->params.pextraWidthp(lex.GetString());
997 } else if (token == "\\pextra_alignment") {
999 par->params.pextraAlignment(lex.GetInteger());
1000 } else if (token == "\\pextra_hfill") {
1002 par->params.pextraHfill(lex.GetInteger());
1003 } else if (token == "\\pextra_start_minipage") {
1005 par->params.pextraStartMinipage(lex.GetInteger());
1007 } else if (token == "\\labelwidthstring") {
1009 par->params.labelWidthString(lex.GetString());
1010 // do not delete this token, it is still needed!
1011 } else if (token == "\\end_inset") {
1012 lyxerr << "Solitary \\end_inset. Missing \\begin_inset?.\n"
1013 << "Last inset read was: " << last_inset_read
1015 // Simply ignore this. The insets do not have
1017 // But insets should read it, it is a part of
1018 // the inset isn't it? Lgb.
1019 } else if (token == "\\begin_inset") {
1020 readInset(lex, par, pos, font);
1021 } else if (token == "\\SpecialChar") {
1022 LyXLayout const & layout =
1023 textclasslist.Style(params.textclass,
1026 // Insets don't make sense in a free-spacing context! ---Kayvan
1027 if (layout.free_spacing) {
1030 string next_token = lex.GetString();
1031 if (next_token == "\\-") {
1032 par->InsertChar(pos, '-', font);
1033 } else if (next_token == "\\protected_separator"
1034 || next_token == "~") {
1035 par->InsertChar(pos, ' ', font);
1037 lex.printError("Token `$$Token' "
1039 "paragraph layout!");
1044 Inset * inset = new InsetSpecialChar;
1045 inset->Read(this, lex);
1046 par->InsertInset(pos, inset, font);
1049 } else if (token == "\\newline") {
1050 par->InsertChar(pos, LyXParagraph::META_NEWLINE, font);
1052 } else if (token == "\\LyXTable") {
1053 Inset * inset = new InsetTabular(*this);
1054 inset->Read(this, lex);
1055 par->InsertInset(pos, inset, font);
1057 // because of OLD_TABULAR_READ where tabulars have been
1059 checkminipage = true;
1060 } else if (token == "\\hfill") {
1061 par->InsertChar(pos, LyXParagraph::META_HFILL, font);
1063 } else if (token == "\\protected_separator") { // obsolete
1064 // This is a backward compability thingie. (Lgb)
1065 // Remove it later some time...introduced with fileformat
1067 LyXLayout const & layout =
1068 textclasslist.Style(params.textclass,
1071 if (layout.free_spacing) {
1072 par->InsertChar(pos, ' ', font);
1074 Inset * inset = new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
1075 par->InsertInset(pos, inset, font);
1078 } else if (token == "\\bibitem") { // ale970302
1080 InsetCommandParams p("bibitem", "dummy");
1081 par->bibkey = new InsetBibKey(p);
1083 par->bibkey->Read(this, lex);
1084 } else if (token == "\\backslash") {
1085 par->InsertChar(pos, '\\', font);
1087 } else if (token == "\\the_end") {
1088 the_end_read = true;
1089 minipar = parBeforeMinipage = 0;
1091 // This should be insurance for the future: (Asger)
1092 lex.printError("Unknown token `$$Token'. "
1093 "Inserting as text.");
1094 string::const_iterator cit = token.begin();
1095 string::const_iterator end = token.end();
1096 for (; cit != end; ++cit) {
1097 par->InsertChar(pos, (*cit), font);
1101 #ifndef NO_PEXTRA_REALLY
1102 // now check if we have a minipage paragraph as at this
1103 // point we already read all the necessary data!
1104 // this cannot be done in layout because there we did
1105 // not read yet the paragraph PEXTRA-params (Jug)
1107 // BEGIN pextra_minipage compability
1108 // This should be removed in 1.3.x (Lgb)
1110 // This compability code is not perfect. In a couple
1111 // of rand cases it fails. When the minipage par is
1112 // the first par in the document, and when there are
1113 // none or only one regular paragraphs after the
1114 // minipage. Currently I am not investing any effort
1115 // in fixing those cases.
1117 //lyxerr << "Call depth: " << call_depth << endl;
1118 if (checkminipage && (call_depth == 1)) {
1119 checkminipage = false;
1120 if (minipar && (minipar != par) &&
1121 (par->params.pextraType()==LyXParagraph::PEXTRA_MINIPAGE))
1123 lyxerr << "minipages in a row" << endl;
1124 if (par->params.pextraStartMinipage()) {
1125 lyxerr << "start new minipage" << endl;
1126 // minipages in a row
1127 par->previous()->next(0);
1130 LyXParagraph * tmp = minipar;
1132 tmp->params.pextraType(0);
1133 tmp->params.pextraWidth(string());
1134 tmp->params.pextraWidthp(string());
1135 tmp->params.pextraAlignment(0);
1136 tmp->params.pextraHfill(false);
1137 tmp->params.pextraStartMinipage(false);
1140 // create a new paragraph to insert the
1141 // minipages in the following case
1142 if (par->params.pextraStartMinipage() &&
1143 !par->params.pextraHfill())
1145 LyXParagraph * p = new LyXParagraph;
1147 p->previous(parBeforeMinipage);
1148 parBeforeMinipage->next(p);
1150 p->params.depth(parBeforeMinipage->params.depth());
1151 parBeforeMinipage = p;
1153 InsetMinipage * mini = new InsetMinipage;
1154 mini->pos(static_cast<InsetMinipage::Position>(par->params.pextraAlignment()));
1155 mini->width(par->params.pextraWidth());
1156 if (!par->params.pextraWidthp().empty()) {
1157 lyxerr << "WP:" << mini->width() << endl;
1158 mini->width(tostr(par->params.pextraWidthp())+"%");
1160 mini->inset.par = par;
1161 // Insert the minipage last in the
1162 // previous paragraph.
1163 if (par->params.pextraHfill()) {
1164 parBeforeMinipage->InsertChar
1165 (parBeforeMinipage->size(), LyXParagraph::META_HFILL);
1167 parBeforeMinipage->InsertInset
1168 (parBeforeMinipage->size(), mini);
1172 lyxerr << "new minipage par" << endl;
1173 //nothing to do just continue reading
1176 } else if (minipar && (minipar != par)) {
1177 lyxerr << "last minipage par read" << endl;
1178 // The last paragraph read was not part of a
1179 // minipage but the par linked list is...
1180 // So we need to remove the last par from the
1182 if (par->previous())
1183 par->previous()->next(0);
1184 par->previous(parBeforeMinipage);
1185 parBeforeMinipage->next(par);
1186 LyXParagraph * tmp = minipar;
1188 tmp->params.pextraType(0);
1189 tmp->params.pextraWidth(string());
1190 tmp->params.pextraWidthp(string());
1191 tmp->params.pextraAlignment(0);
1192 tmp->params.pextraHfill(false);
1193 tmp->params.pextraStartMinipage(false);
1196 depth = parBeforeMinipage->params.depth();
1197 minipar = parBeforeMinipage = 0;
1198 } else if (!minipar &&
1199 (par->params.pextraType() == LyXParagraph::PEXTRA_MINIPAGE))
1201 // par is the first paragraph in a minipage
1202 lyxerr << "begin minipage" << endl;
1203 // To minimize problems for
1204 // the users we will insert
1205 // the first minipage in
1206 // a sequence of minipages
1207 // in its own paragraph.
1208 LyXParagraph * p = new LyXParagraph;
1210 p->previous(par->previous());
1212 p->params.depth(depth);
1213 par->params.depth(0);
1215 if (par->previous())
1216 par->previous()->next(p);
1218 parBeforeMinipage = p;
1220 if (!return_par || (return_par == par))
1223 InsetMinipage * mini = new InsetMinipage;
1224 mini->pos(static_cast<InsetMinipage::Position>(minipar->params.pextraAlignment()));
1225 mini->width(minipar->params.pextraWidth());
1226 if (!par->params.pextraWidthp().empty()) {
1227 lyxerr << "WP:" << mini->width() << endl;
1228 mini->width(tostr(par->params.pextraWidthp())+"%");
1230 mini->inset.par = minipar;
1232 // Insert the minipage last in the
1233 // previous paragraph.
1234 if (minipar->params.pextraHfill()) {
1235 parBeforeMinipage->InsertChar
1236 (parBeforeMinipage->size(),LyXParagraph::META_HFILL);
1238 parBeforeMinipage->InsertInset
1239 (parBeforeMinipage->size(), mini);
1242 // End of pextra_minipage compability
1245 return the_end_read;
1249 void Buffer::readInset(LyXLex & lex, LyXParagraph *& par,
1250 int & pos, LyXFont & font)
1252 // consistency check
1253 if (lex.GetString() != "\\begin_inset") {
1254 lyxerr << "Buffer::readInset: Consistency check failed."
1261 string const tmptok = lex.GetString();
1262 last_inset_read = tmptok;
1264 // test the different insets
1265 if (tmptok == "LatexCommand") {
1266 InsetCommandParams inscmd;
1269 if (inscmd.getCmdName() == "cite") {
1270 inset = new InsetCitation(inscmd);
1271 } else if (inscmd.getCmdName() == "bibitem") {
1272 lex.printError("Wrong place for bibitem");
1273 inset = new InsetBibKey(inscmd);
1274 } else if (inscmd.getCmdName() == "BibTeX") {
1275 inset = new InsetBibtex(inscmd);
1276 } else if (inscmd.getCmdName() == "index") {
1277 inset = new InsetIndex(inscmd);
1278 } else if (inscmd.getCmdName() == "include") {
1279 inset = new InsetInclude(inscmd, *this);
1280 } else if (inscmd.getCmdName() == "label") {
1281 inset = new InsetLabel(inscmd);
1282 } else if (inscmd.getCmdName() == "url"
1283 || inscmd.getCmdName() == "htmlurl") {
1284 inset = new InsetUrl(inscmd);
1285 } else if (inscmd.getCmdName() == "ref"
1286 || inscmd.getCmdName() == "pageref"
1287 || inscmd.getCmdName() == "vref"
1288 || inscmd.getCmdName() == "vpageref"
1289 || inscmd.getCmdName() == "prettyref") {
1290 if (!inscmd.getOptions().empty()
1291 || !inscmd.getContents().empty()) {
1292 inset = new InsetRef(inscmd, *this);
1294 } else if (inscmd.getCmdName() == "tableofcontents"
1295 || inscmd.getCmdName() == "listofalgorithms"
1296 || inscmd.getCmdName() == "listoffigures"
1297 || inscmd.getCmdName() == "listoftables") {
1298 inset = new InsetTOC(inscmd);
1299 } else if (inscmd.getCmdName() == "printindex") {
1300 inset = new InsetPrintIndex(inscmd);
1301 } else if (inscmd.getCmdName() == "lyxparent") {
1302 inset = new InsetParent(inscmd, *this);
1305 if (tmptok == "Quotes") {
1306 inset = new InsetQuotes;
1307 } else if (tmptok == "External") {
1308 inset = new InsetExternal;
1309 } else if (tmptok == "FormulaMacro") {
1310 inset = new InsetFormulaMacro;
1311 } else if (tmptok == "Formula") {
1312 inset = new InsetFormula;
1313 } else if (tmptok == "Figure") {
1314 inset = new InsetFig(100, 100, *this);
1315 } else if (tmptok == "Info") {
1316 inset = new InsetInfo;
1317 } else if (tmptok == "Include") {
1318 InsetCommandParams p( "Include" );
1319 inset = new InsetInclude(p, *this);
1320 } else if (tmptok == "ERT") {
1321 inset = new InsetERT;
1322 } else if (tmptok == "Tabular") {
1323 inset = new InsetTabular(*this);
1324 } else if (tmptok == "Text") {
1325 inset = new InsetText;
1326 } else if (tmptok == "Foot") {
1327 inset = new InsetFoot;
1328 } else if (tmptok == "Marginal") {
1329 inset = new InsetMarginal;
1330 } else if (tmptok == "Minipage") {
1331 inset = new InsetMinipage;
1332 } else if (tmptok == "Float") {
1334 string tmptok = lex.GetString();
1335 inset = new InsetFloat(tmptok);
1336 } else if (tmptok == "List") {
1337 inset = new InsetList;
1338 } else if (tmptok == "Theorem") {
1339 inset = new InsetList;
1340 } else if (tmptok == "Caption") {
1341 inset = new InsetCaption;
1342 } else if (tmptok == "GRAPHICS") {
1343 inset = new InsetGraphics;
1346 if (inset) inset->Read(this, lex);
1350 par->InsertInset(pos, inset, font);
1356 bool Buffer::readFile(LyXLex & lex, LyXParagraph * par)
1360 string const token(lex.GetString());
1361 if (token == "\\lyxformat") { // the first token _must_ be...
1363 string tmp_format = lex.GetString();
1364 //lyxerr << "LyX Format: `" << tmp_format << "'" << endl;
1365 // if present remove ".," from string.
1366 string::size_type dot = tmp_format.find_first_of(".,");
1367 //lyxerr << " dot found at " << dot << endl;
1368 if (dot != string::npos)
1369 tmp_format.erase(dot, 1);
1370 file_format = strToInt(tmp_format);
1371 if (file_format == LYX_FORMAT) {
1373 } else if (file_format > LYX_FORMAT) {
1375 WriteAlert(_("Warning!"),
1376 _("LyX file format is newer that what"),
1377 _("is supported in this LyX version. Expect some problems."));
1379 } else if (file_format < LYX_FORMAT) {
1381 if (file_format < 200) {
1382 WriteAlert(_("ERROR!"),
1383 _("Old LyX file format found. "
1384 "Use LyX 0.10.x to read this!"));
1388 bool the_end = readLyXformat2(lex, par);
1390 // the_end was added in 213
1391 if (file_format < 213)
1395 WriteAlert(_("Warning!"),
1396 _("Reading of document is not complete"),
1397 _("Maybe the document is truncated"));
1399 } else { // "\\lyxformat" not found
1400 WriteAlert(_("ERROR!"), _("Not a LyX file!"));
1403 WriteAlert(_("ERROR!"), _("Unable to read file!"));
1409 // Should probably be moved to somewhere else: BufferView? LyXView?
1410 bool Buffer::save() const
1412 // We don't need autosaves in the immediate future. (Asger)
1413 resetAutosaveTimers();
1417 if (lyxrc.make_backup) {
1418 s = fileName() + '~';
1419 if (!lyxrc.backupdir_path.empty())
1420 s = AddName(lyxrc.backupdir_path,
1421 subst(CleanupPath(s),'/','!'));
1423 // Rename is the wrong way of making a backup,
1424 // this is the correct way.
1425 /* truss cp fil fil2:
1426 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
1427 stat("LyXVC.lyx", 0xEFFFF688) = 0
1428 open("LyXVC.lyx", O_RDONLY) = 3
1429 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
1430 fstat(4, 0xEFFFF508) = 0
1431 fstat(3, 0xEFFFF508) = 0
1432 read(3, " # T h i s f i l e w".., 8192) = 5579
1433 write(4, " # T h i s f i l e w".., 5579) = 5579
1434 read(3, 0xEFFFD4A0, 8192) = 0
1437 chmod("LyXVC3.lyx", 0100644) = 0
1438 lseek(0, 0, SEEK_CUR) = 46440
1442 // Should proabaly have some more error checking here.
1443 // Should be cleaned up in 0.13, at least a bit.
1444 // Doing it this way, also makes the inodes stay the same.
1445 // This is still not a very good solution, in particular we
1446 // might loose the owner of the backup.
1447 FileInfo finfo(fileName());
1448 if (finfo.exist()) {
1449 mode_t fmode = finfo.getMode();
1450 struct utimbuf times = {
1451 finfo.getAccessTime(),
1452 finfo.getModificationTime() };
1454 ifstream ifs(fileName().c_str());
1455 ofstream ofs(s.c_str(), ios::out|ios::trunc);
1460 ::chmod(s.c_str(), fmode);
1462 if (::utime(s.c_str(), ×)) {
1463 lyxerr << "utime error." << endl;
1466 lyxerr << "LyX was not able to make "
1467 "backupcopy. Beware." << endl;
1472 if (writeFile(fileName(), false)) {
1474 removeAutosaveFile(fileName());
1476 // Saving failed, so backup is not backup
1477 if (lyxrc.make_backup) {
1478 lyx::rename(s, fileName());
1486 // Returns false if unsuccesful
1487 bool Buffer::writeFile(string const & fname, bool flag) const
1489 // if flag is false writeFile will not create any GUI
1490 // warnings, only cerr.
1491 // Needed for autosave in background or panic save (Matthias 120496)
1493 if (read_only && (fname == filename)) {
1494 // Here we should come with a question if we should
1495 // perform the write anyway.
1497 lyxerr << _("Error! Document is read-only: ")
1500 WriteAlert(_("Error! Document is read-only: "),
1505 FileInfo finfo(fname);
1506 if (finfo.exist() && !finfo.writable()) {
1507 // Here we should come with a question if we should
1508 // try to do the save anyway. (i.e. do a chmod first)
1510 lyxerr << _("Error! Cannot write file: ")
1513 WriteFSAlert(_("Error! Cannot write file: "),
1518 ofstream ofs(fname.c_str());
1521 lyxerr << _("Error! Cannot open file: ")
1524 WriteFSAlert(_("Error! Cannot open file: "),
1530 // Use the standard "C" locale for file output.
1531 ofs.imbue(std::locale::classic());
1534 // The top of the file should not be written by params.
1536 // write out a comment in the top of the file
1537 ofs << '#' << LYX_DOCVERSION
1538 << " created this file. For more info see http://www.lyx.org/\n"
1539 << "\\lyxformat " << LYX_FORMAT << "\n";
1541 // now write out the buffer paramters.
1542 params.writeFile(ofs);
1544 char footnoteflag = 0;
1547 // this will write out all the paragraphs
1548 // using recursive descent.
1549 paragraph->writeFile(this, ofs, params, footnoteflag, depth);
1551 // Write marker that shows file is complete
1552 ofs << "\n\\the_end" << endl;
1556 // how to check if close went ok?
1557 // Following is an attempt... (BE 20001011)
1559 // good() returns false if any error occured, including some
1560 // formatting error.
1561 // bad() returns true if something bad happened in the buffer,
1562 // which should include file system full errors.
1569 lyxerr << "Buffer::writeFile: BAD ERROR!" << endl;
1571 lyxerr << "Buffer::writeFile: NOT SO BAD ERROR!"
1581 string const Buffer::asciiParagraph(LyXParagraph const * par,
1582 unsigned int linelen) const
1584 ostringstream buffer;
1587 Inset const * inset;
1590 LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
1594 int ltype_depth = 0;
1595 unsigned int currlinelen = 0;
1596 bool ref_printed = false;
1601 if (par->footnoteflag != LyXParagraph::NO_FOOTNOTE ||
1603 || par->previous()->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
1604 /* begins a footnote environment ? */
1605 if (footnoteflag != par->footnoteflag) {
1606 footnoteflag = par->footnoteflag;
1608 size_t const j = strlen(string_footnotekinds[par->footnotekind]) + 4;
1609 if ((linelen > 0) &&
1610 ((currlinelen + j) > linelen)) {
1615 << string_footnotekinds[par->footnotekind]
1621 if (!par->previous()) {
1623 /* begins or ends a deeper area ?*/
1624 if (depth != par->params.depth()) {
1625 if (par->params.depth() > depth) {
1626 while (par->params.depth() > depth) {
1630 while (par->params.depth() < depth) {
1636 /* First write the layout */
1637 string const tmp = textclasslist.NameOfLayout(params.textclass, par->layout);
1638 if (tmp == "Itemize") {
1640 ltype_depth = depth + 1;
1641 } else if (tmp == "Enumerate") {
1643 ltype_depth = depth + 1;
1644 } else if (strstr(tmp.c_str(), "ection")) {
1646 ltype_depth = depth + 1;
1647 } else if (strstr(tmp.c_str(), "aragraph")) {
1649 ltype_depth = depth + 1;
1650 } else if (tmp == "Description") {
1652 ltype_depth = depth + 1;
1653 } else if (tmp == "Abstract") {
1656 } else if (tmp == "Bibliography") {
1664 /* maybe some vertical spaces */
1666 /* the labelwidthstring used in lists */
1670 /* some pagebreaks? */
1674 /* what about the alignment */
1677 /* dummy layout, that means a footnote ended */
1678 footnoteflag = LyXParagraph::NO_FOOTNOTE;
1682 lyxerr << "Should this ever happen?" << endl;
1686 font1 = LyXFont(LyXFont::ALL_INHERIT, params.language);
1687 for (LyXParagraph::size_type i = 0; i < par->size(); ++i) {
1695 for (char j = 0; j < depth; ++j)
1697 currlinelen = depth * 2;
1699 case 0: /* Standard */
1700 case 4: /* (Sub)Paragraph */
1701 case 5: /* Description */
1703 case 6: /* Abstract */
1705 buffer << "Abstract\n\n";
1707 buffer << "Abstract: ";
1709 case 7: /* Bibliography */
1712 buffer << "References\n\n";
1714 buffer << "References: ";
1719 buffer << par->params.labelString() << " ";
1722 if (ltype_depth > depth) {
1723 for (char j = ltype_depth - 1; j > depth; --j)
1725 currlinelen += (ltype_depth-depth)*2;
1728 font2 = par->GetFontSettings(params, i);
1729 if (font1.latex() != font2.latex()) {
1730 if (font2.latex() == LyXFont::OFF)
1737 c = par->GetUChar(params, i);
1741 case LyXParagraph::META_INSET:
1742 if ((inset = par->GetInset(i))) {
1743 if (!inset->Ascii(this, buffer)) {
1745 string s = rsplit(buffer.str().c_str(),
1747 currlinelen += s.length();
1749 // to be sure it breaks paragraph
1750 currlinelen += linelen;
1754 case LyXParagraph::META_NEWLINE:
1757 for (char j = 0; j < depth; ++j)
1760 currlinelen = depth * 2;
1761 if (ltype_depth > depth) {
1762 for (char j = ltype_depth;
1765 currlinelen += (ltype_depth - depth) * 2;
1768 case LyXParagraph::META_HFILL:
1775 if ((linelen > 0) && (currlinelen > (linelen - 10)) &&
1776 (c == ' ') && ((i + 2) < par->size()))
1779 for (char j = 0; j < depth; ++j)
1781 currlinelen = depth * 2;
1782 if (ltype_depth > depth) {
1783 for (char j = ltype_depth;
1786 currlinelen += (ltype_depth-depth)*2;
1788 } else if (c != '\0')
1791 lyxerr.debug() << "writeAsciiFile: NULL char in structure." << endl;
1796 return buffer.str().c_str();
1800 void Buffer::writeFileAscii(string const & fname, int linelen)
1802 ofstream ofs(fname.c_str());
1804 WriteFSAlert(_("Error: Cannot write file:"), fname);
1807 writeFileAscii(ofs, linelen);
1811 void Buffer::writeFileAscii(ostream & ofs, int linelen)
1813 LyXParagraph * par = paragraph;
1815 ofs << asciiParagraph(par, linelen);
1823 void Buffer::makeLaTeXFile(string const & fname,
1824 string const & original_path,
1825 bool nice, bool only_body)
1827 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
1829 niceFile = nice; // this will be used by Insetincludes.
1831 tex_code_break_column = lyxrc.ascii_linelen;
1833 LyXTextClass const & tclass =
1834 textclasslist.TextClass(params.textclass);
1836 ofstream ofs(fname.c_str());
1838 WriteFSAlert(_("Error: Cannot open file: "), fname);
1842 // validate the buffer.
1843 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
1844 LaTeXFeatures features(params, tclass.numLayouts());
1846 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
1849 // The starting paragraph of the coming rows is the
1850 // first paragraph of the document. (Asger)
1851 texrow.start(paragraph, 0);
1853 if (!only_body && nice) {
1854 ofs << "%% " LYX_DOCVERSION " created this file. "
1855 "For more info, see http://www.lyx.org/.\n"
1856 "%% Do not edit unless you really know what "
1861 lyxerr.debug() << "lyx header finished" << endl;
1862 // There are a few differences between nice LaTeX and usual files:
1863 // usual is \batchmode and has a
1864 // special input@path to allow the including of figures
1865 // with either \input or \includegraphics (what figinsets do).
1866 // batchmode is not set if there is a tex_code_break_column.
1867 // In this case somebody is interested in the generated LaTeX,
1868 // so this is OK. input@path is set when the actual parameter
1869 // original_path is set. This is done for usual tex-file, but not
1870 // for nice-latex-file. (Matthias 250696)
1873 // code for usual, NOT nice-latex-file
1874 ofs << "\\batchmode\n"; // changed
1875 // from \nonstopmode
1878 if (!original_path.empty()) {
1879 ofs << "\\makeatletter\n"
1880 << "\\def\\input@path{{"
1881 << original_path << "/}}\n"
1882 << "\\makeatother\n";
1888 ofs << "\\documentclass";
1890 string options; // the document class options.
1892 if (tokenPos(tclass.opt_fontsize(),
1893 '|', params.fontsize) >= 0) {
1894 // only write if existing in list (and not default)
1895 options += params.fontsize;
1900 if (!params.use_geometry &&
1901 (params.paperpackage == BufferParams::PACKAGE_NONE)) {
1902 switch (params.papersize) {
1903 case BufferParams::PAPER_A4PAPER:
1904 options += "a4paper,";
1906 case BufferParams::PAPER_USLETTER:
1907 options += "letterpaper,";
1909 case BufferParams::PAPER_A5PAPER:
1910 options += "a5paper,";
1912 case BufferParams::PAPER_B5PAPER:
1913 options += "b5paper,";
1915 case BufferParams::PAPER_EXECUTIVEPAPER:
1916 options += "executivepaper,";
1918 case BufferParams::PAPER_LEGALPAPER:
1919 options += "legalpaper,";
1925 if (params.sides != tclass.sides()) {
1926 switch (params.sides) {
1927 case LyXTextClass::OneSide:
1928 options += "oneside,";
1930 case LyXTextClass::TwoSides:
1931 options += "twoside,";
1938 if (params.columns != tclass.columns()) {
1939 if (params.columns == 2)
1940 options += "twocolumn,";
1942 options += "onecolumn,";
1945 if (!params.use_geometry
1946 && params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1947 options += "landscape,";
1949 // language should be a parameter to \documentclass
1951 string language_options;
1952 if (params.language->babel() == "hebrew"
1953 && default_language->babel() != "hebrew")
1954 // This seems necessary
1955 features.UsedLanguages.insert(default_language);
1957 if (lyxrc.language_use_babel ||
1958 params.language->lang() != lyxrc.default_language ||
1959 !features.UsedLanguages.empty()) {
1961 for (LaTeXFeatures::LanguageList::const_iterator cit =
1962 features.UsedLanguages.begin();
1963 cit != features.UsedLanguages.end(); ++cit)
1964 language_options += (*cit)->babel() + ',';
1965 language_options += params.language->babel();
1966 if (lyxrc.language_global_options)
1967 options += language_options + ',';
1970 // the user-defined options
1971 if (!params.options.empty()) {
1972 options += params.options + ',';
1975 if (!options.empty()){
1976 options = strip(options, ',');
1977 ofs << '[' << options << ']';
1981 << textclasslist.LatexnameOfClass(params.textclass)
1984 // end of \documentclass defs
1986 // font selection must be done before loading fontenc.sty
1987 // The ae package is not needed when using OT1 font encoding.
1988 if (params.fonts != "default" &&
1989 (params.fonts != "ae" || lyxrc.fontenc != "default")) {
1990 ofs << "\\usepackage{" << params.fonts << "}\n";
1992 if (params.fonts == "ae") {
1993 ofs << "\\usepackage{aecompl}\n";
1997 // this one is not per buffer
1998 if (lyxrc.fontenc != "default") {
1999 ofs << "\\usepackage[" << lyxrc.fontenc
2004 if (params.inputenc == "auto") {
2005 string const doc_encoding =
2006 params.language->encoding()->LatexName();
2008 // Create a list with all the input encodings used
2010 set<string> encodings;
2011 for (LaTeXFeatures::LanguageList::const_iterator it =
2012 features.UsedLanguages.begin();
2013 it != features.UsedLanguages.end(); ++it)
2014 if ((*it)->encoding()->LatexName() != doc_encoding)
2015 encodings.insert((*it)->encoding()->LatexName());
2017 ofs << "\\usepackage[";
2018 std::copy(encodings.begin(), encodings.end(),
2019 std::ostream_iterator<string>(ofs, ","));
2020 ofs << doc_encoding << "]{inputenc}\n";
2022 } else if (params.inputenc != "default") {
2023 ofs << "\\usepackage[" << params.inputenc
2028 // At the very beginning the text parameters.
2029 if (params.paperpackage != BufferParams::PACKAGE_NONE) {
2030 switch (params.paperpackage) {
2031 case BufferParams::PACKAGE_A4:
2032 ofs << "\\usepackage{a4}\n";
2035 case BufferParams::PACKAGE_A4WIDE:
2036 ofs << "\\usepackage{a4wide}\n";
2039 case BufferParams::PACKAGE_WIDEMARGINSA4:
2040 ofs << "\\usepackage[widemargins]{a4}\n";
2045 if (params.use_geometry) {
2046 ofs << "\\usepackage{geometry}\n";
2048 ofs << "\\geometry{verbose";
2049 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
2050 ofs << ",landscape";
2051 switch (params.papersize2) {
2052 case BufferParams::VM_PAPER_CUSTOM:
2053 if (!params.paperwidth.empty())
2054 ofs << ",paperwidth="
2055 << params.paperwidth;
2056 if (!params.paperheight.empty())
2057 ofs << ",paperheight="
2058 << params.paperheight;
2060 case BufferParams::VM_PAPER_USLETTER:
2061 ofs << ",letterpaper";
2063 case BufferParams::VM_PAPER_USLEGAL:
2064 ofs << ",legalpaper";
2066 case BufferParams::VM_PAPER_USEXECUTIVE:
2067 ofs << ",executivepaper";
2069 case BufferParams::VM_PAPER_A3:
2072 case BufferParams::VM_PAPER_A4:
2075 case BufferParams::VM_PAPER_A5:
2078 case BufferParams::VM_PAPER_B3:
2081 case BufferParams::VM_PAPER_B4:
2084 case BufferParams::VM_PAPER_B5:
2088 // default papersize ie BufferParams::VM_PAPER_DEFAULT
2089 switch (lyxrc.default_papersize) {
2090 case BufferParams::PAPER_DEFAULT: // keep compiler happy
2091 case BufferParams::PAPER_USLETTER:
2092 ofs << ",letterpaper";
2094 case BufferParams::PAPER_LEGALPAPER:
2095 ofs << ",legalpaper";
2097 case BufferParams::PAPER_EXECUTIVEPAPER:
2098 ofs << ",executivepaper";
2100 case BufferParams::PAPER_A3PAPER:
2103 case BufferParams::PAPER_A4PAPER:
2106 case BufferParams::PAPER_A5PAPER:
2109 case BufferParams::PAPER_B5PAPER:
2114 if (!params.topmargin.empty())
2115 ofs << ",tmargin=" << params.topmargin;
2116 if (!params.bottommargin.empty())
2117 ofs << ",bmargin=" << params.bottommargin;
2118 if (!params.leftmargin.empty())
2119 ofs << ",lmargin=" << params.leftmargin;
2120 if (!params.rightmargin.empty())
2121 ofs << ",rmargin=" << params.rightmargin;
2122 if (!params.headheight.empty())
2123 ofs << ",headheight=" << params.headheight;
2124 if (!params.headsep.empty())
2125 ofs << ",headsep=" << params.headsep;
2126 if (!params.footskip.empty())
2127 ofs << ",footskip=" << params.footskip;
2131 if (features.amsstyle
2132 && !tclass.provides(LyXTextClass::amsmath)) {
2133 ofs << "\\usepackage{amsmath}\n";
2137 if (tokenPos(tclass.opt_pagestyle(),
2138 '|', params.pagestyle) >= 0) {
2139 if (params.pagestyle == "fancy") {
2140 ofs << "\\usepackage{fancyhdr}\n";
2143 ofs << "\\pagestyle{" << params.pagestyle << "}\n";
2147 // We try to load babel late, in case it interferes
2148 // with other packages.
2150 string tmp = lyxrc.language_package;
2151 if (!lyxrc.language_global_options
2152 && tmp == "\\usepackage{babel}")
2153 tmp = "\\usepackage[" +
2154 language_options + "]{babel}";
2159 if (params.secnumdepth != tclass.secnumdepth()) {
2160 ofs << "\\setcounter{secnumdepth}{"
2161 << params.secnumdepth
2165 if (params.tocdepth != tclass.tocdepth()) {
2166 ofs << "\\setcounter{tocdepth}{"
2172 if (params.paragraph_separation) {
2173 switch (params.defskip.kind()) {
2174 case VSpace::SMALLSKIP:
2175 ofs << "\\setlength\\parskip{\\smallskipamount}\n";
2177 case VSpace::MEDSKIP:
2178 ofs << "\\setlength\\parskip{\\medskipamount}\n";
2180 case VSpace::BIGSKIP:
2181 ofs << "\\setlength\\parskip{\\bigskipamount}\n";
2183 case VSpace::LENGTH:
2184 ofs << "\\setlength\\parskip{"
2185 << params.defskip.length().asLatexString()
2188 default: // should never happen // Then delete it.
2189 ofs << "\\setlength\\parskip{\\medskipamount}\n";
2194 ofs << "\\setlength\\parindent{0pt}\n";
2198 // Now insert the LyX specific LaTeX commands...
2200 // The optional packages;
2201 string preamble(features.getPackages());
2203 // this might be useful...
2204 preamble += "\n\\makeatletter\n";
2206 // Some macros LyX will need
2207 string tmppreamble(features.getMacros());
2209 if (!tmppreamble.empty()) {
2210 preamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2211 "LyX specific LaTeX commands.\n"
2212 + tmppreamble + '\n';
2215 // the text class specific preamble
2216 tmppreamble = features.getTClassPreamble();
2217 if (!tmppreamble.empty()) {
2218 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2219 "Textclass specific LaTeX commands.\n"
2220 + tmppreamble + '\n';
2223 /* the user-defined preamble */
2224 if (!params.preamble.empty()) {
2225 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2226 "User specified LaTeX commands.\n"
2227 + params.preamble + '\n';
2230 preamble += "\\makeatother\n";
2232 // Itemize bullet settings need to be last in case the user
2233 // defines their own bullets that use a package included
2234 // in the user-defined preamble -- ARRae
2235 // Actually it has to be done much later than that
2236 // since some packages like frenchb make modifications
2237 // at \begin{document} time -- JMarc
2239 for (int i = 0; i < 4; ++i) {
2240 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
2241 if (bullets_def.empty())
2242 bullets_def="\\AtBeginDocument{\n";
2243 bullets_def += " \\renewcommand{\\labelitemi";
2245 // `i' is one less than the item to modify
2252 bullets_def += "ii";
2258 bullets_def += "}{" +
2259 params.user_defined_bullets[i].getText()
2264 if (!bullets_def.empty())
2265 preamble += bullets_def + "}\n\n";
2267 for (int j = countChar(preamble, '\n'); j-- ;) {
2274 ofs << "\\begin{document}\n";
2277 lyxerr.debug() << "preamble finished, now the body." << endl;
2279 if (!lyxrc.language_auto_begin) {
2280 ofs << subst(lyxrc.language_command_begin, "$$lang",
2281 params.language->babel())
2286 latexParagraphs(ofs, paragraph, 0, texrow);
2288 // add this just in case after all the paragraphs
2292 if (!lyxrc.language_auto_end) {
2293 ofs << subst(lyxrc.language_command_end, "$$lang",
2294 params.language->babel())
2300 ofs << "\\end{document}\n";
2303 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
2305 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
2309 // Just to be sure. (Asger)
2312 // tex_code_break_column's value is used to decide
2313 // if we are in batchmode or not (within mathed_write()
2314 // in math_write.C) so we must set it to a non-zero
2315 // value when we leave otherwise we save incorrect .lyx files.
2316 tex_code_break_column = lyxrc.ascii_linelen;
2320 lyxerr << "File was not closed properly." << endl;
2323 lyxerr.debug() << "Finished making latex file." << endl;
2328 // LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
2330 void Buffer::latexParagraphs(ostream & ofs, LyXParagraph * par,
2331 LyXParagraph * endpar, TexRow & texrow) const
2333 bool was_title = false;
2334 bool already_title = false;
2335 std::ostringstream ftnote;
2340 while (par != endpar) {
2343 lyxerr[Debug::LATEX] << "Error in latexParagraphs."
2346 LyXLayout const & layout =
2347 textclasslist.Style(params.textclass,
2350 if (layout.intitle) {
2351 if (already_title) {
2352 lyxerr <<"Error in latexParagraphs: You"
2353 " should not mix title layouts"
2354 " with normal ones." << endl;
2357 } else if (was_title && !already_title) {
2358 ofs << "\\maketitle\n";
2360 already_title = true;
2363 // We are at depth 0 so we can just use
2364 // ordinary \footnote{} generation
2365 // flag this with ftcount
2367 if (layout.isEnvironment()
2369 || par->params.pextraType() != LyXParagraph::PEXTRA_NONE
2372 par = par->TeXEnvironment(this, params, ofs, texrow
2374 ,ftnote, ft_texrow, ftcount
2378 par = par->TeXOnePar(this, params, ofs, texrow, false
2381 ftnote, ft_texrow, ftcount
2386 // Write out what we've generated...
2389 ofs << "\\addtocounter{footnote}{-"
2393 ofs << ftnote.str();
2394 texrow += ft_texrow;
2396 // The extra .c_str() is needed when we use
2397 // lyxstring instead of the STL string class.
2398 ftnote.str(string().c_str());
2403 // It might be that we only have a title in this document
2404 if (was_title && !already_title) {
2405 ofs << "\\maketitle\n";
2411 bool Buffer::isLatex() const
2413 return textclasslist.TextClass(params.textclass).outputType() == LATEX;
2417 bool Buffer::isLinuxDoc() const
2419 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC;
2423 bool Buffer::isLiterate() const
2425 return textclasslist.TextClass(params.textclass).outputType() == LITERATE;
2429 bool Buffer::isDocBook() const
2431 return textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2435 bool Buffer::isSGML() const
2437 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC ||
2438 textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2442 void Buffer::sgmlOpenTag(ostream & os, int depth,
2443 string const & latexname) const
2445 if (!latexname.empty() && latexname != "!-- --")
2446 os << string(depth, ' ') << "<" << latexname << ">\n";
2450 void Buffer::sgmlCloseTag(ostream & os, int depth,
2451 string const & latexname) const
2453 if (!latexname.empty() && latexname != "!-- --")
2454 os << string(depth, ' ') << "</" << latexname << ">\n";
2458 void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
2460 ofstream ofs(fname.c_str());
2463 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2467 niceFile = nice; // this will be used by included files.
2469 LyXTextClass const & tclass =
2470 textclasslist.TextClass(params.textclass);
2472 LaTeXFeatures features(params, tclass.numLayouts());
2477 string top_element = textclasslist.LatexnameOfClass(params.textclass);
2480 string sgml_includedfiles=features.getIncludedFiles(fname);
2482 if (params.preamble.empty() && sgml_includedfiles.empty()) {
2483 ofs << "<!doctype linuxdoc system>\n\n";
2485 ofs << "<!doctype linuxdoc system [ "
2486 << params.preamble << sgml_includedfiles << " \n]>\n\n";
2489 if (params.options.empty())
2490 sgmlOpenTag(ofs, 0, top_element);
2492 string top = top_element;
2494 top += params.options;
2495 sgmlOpenTag(ofs, 0, top);
2499 ofs << "<!-- " << LYX_DOCVERSION
2500 << " created this file. For more info see http://www.lyx.org/"
2503 int depth = 0; // paragraph depth
2504 LyXParagraph * par = paragraph;
2506 vector<string> environment_stack(5);
2509 LyXLayout const & style =
2510 textclasslist.Style(params.textclass,
2513 // treat <toc> as a special case for compatibility with old code
2514 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2515 Inset * inset = par->GetInset(0);
2516 Inset::Code lyx_code = inset->LyxCode();
2517 if (lyx_code == Inset::TOC_CODE){
2518 string const temp = "toc";
2519 sgmlOpenTag(ofs, depth, temp);
2523 linuxDocHandleFootnote(ofs, par, depth);
2531 // environment tag closing
2532 for (; depth > par->params.depth(); --depth) {
2533 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2534 environment_stack[depth].erase();
2537 // write opening SGML tags
2538 switch (style.latextype) {
2539 case LATEX_PARAGRAPH:
2540 if (depth == par->params.depth()
2541 && !environment_stack[depth].empty()) {
2542 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2543 environment_stack[depth].erase();
2549 sgmlOpenTag(ofs, depth, style.latexname());
2554 LinuxDocError(par, 0,
2555 _("Error : Wrong depth for"
2556 " LatexType Command.\n"));
2558 if (!environment_stack[depth].empty()){
2559 sgmlCloseTag(ofs, depth,
2560 environment_stack[depth]);
2564 environment_stack[depth].erase();
2565 sgmlOpenTag(ofs, depth, style.latexname());
2568 case LATEX_ENVIRONMENT:
2569 case LATEX_ITEM_ENVIRONMENT:
2570 if (depth == par->params.depth()
2571 && environment_stack[depth] != style.latexname()) {
2572 sgmlCloseTag(ofs, depth,
2573 environment_stack[depth]);
2574 environment_stack[depth].erase();
2576 if (depth < par->params.depth()) {
2577 depth = par->params.depth();
2578 environment_stack[depth].erase();
2580 if (environment_stack[depth] != style.latexname()) {
2582 sgmlOpenTag(ofs, depth, "p");
2584 sgmlOpenTag(ofs, depth, style.latexname());
2586 if (environment_stack.size() == depth + 1)
2587 environment_stack.push_back("!-- --");
2588 environment_stack[depth] = style.latexname();
2591 if (style.latexparam() == "CDATA")
2594 if (style.latextype == LATEX_ENVIRONMENT) break;
2596 if (style.labeltype == LABEL_MANUAL)
2601 sgmlOpenTag(ofs, depth + 1, item_name);
2604 sgmlOpenTag(ofs, depth, style.latexname());
2610 SimpleLinuxDocOnePar(ofs, par, depth);
2613 linuxDocHandleFootnote(ofs, par, depth);
2615 while(par && par->IsDummy());
2617 SimpleLinuxDocOnePar(ofs, par, depth);
2623 // write closing SGML tags
2624 switch (style.latextype) {
2627 case LATEX_ENVIRONMENT:
2628 case LATEX_ITEM_ENVIRONMENT:
2629 if (style.latexparam() == "CDATA")
2633 sgmlCloseTag(ofs, depth, style.latexname());
2639 for (int i=depth; i >= 0; --i)
2640 sgmlCloseTag(ofs, depth, environment_stack[i]);
2644 sgmlCloseTag(ofs, 0, top_element);
2648 // How to check for successful close
2653 void Buffer::linuxDocHandleFootnote(ostream & os, LyXParagraph * & par,
2656 string const tag = "footnote";
2658 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2659 sgmlOpenTag(os, depth + 1, tag);
2660 SimpleLinuxDocOnePar(os, par, 0, depth + 1);
2661 sgmlCloseTag(os, depth + 1, tag);
2668 void Buffer::DocBookHandleCaption(ostream & os, string & inner_tag,
2669 int depth, int desc_on,
2670 LyXParagraph * & par)
2672 LyXParagraph * tpar = par;
2675 && (tpar->footnoteflag != LyXParagraph::NO_FOOTNOTE)
2676 && (tpar->layout != textclasslist.NumberOfLayout(params.textclass,
2681 && (tpar->layout != textclasslist.NumberOfLayout(params.textclass,
2683 tpar = tpar->next();
2686 tpar->layout == textclasslist.NumberOfLayout(params.textclass,
2687 "Caption").second) {
2688 sgmlOpenTag(os, depth + 1, inner_tag);
2690 SimpleDocBookOnePar(os, extra_par, tpar,
2691 desc_on, depth + 2);
2692 sgmlCloseTag(os, depth+1, inner_tag);
2693 if (!extra_par.empty())
2700 void Buffer::DocBookHandleFootnote(ostream & os, LyXParagraph * & par,
2703 string tag, inner_tag;
2704 string tmp_par, extra_par;
2705 bool inner_span = false;
2708 // Someone should give this enum a proper name (Lgb)
2716 SOME_ENUM last = NO_ONE;
2717 SOME_ENUM present = FOOTNOTE_LIKE;
2719 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2720 if (last == present) {
2722 if (!tmp_par.empty()) {
2725 sgmlCloseTag(os, depth + 1, inner_tag);
2726 sgmlOpenTag(os, depth + 1, inner_tag);
2733 if (!inner_tag.empty()) sgmlCloseTag(os, depth + 1,
2735 if (!extra_par.empty()) os << extra_par;
2736 if (!tag.empty()) sgmlCloseTag(os, depth, tag);
2739 switch (par->footnotekind) {
2740 case LyXParagraph::FOOTNOTE:
2741 case LyXParagraph::ALGORITHM:
2744 present = FOOTNOTE_LIKE;
2747 case LyXParagraph::MARGIN:
2750 present = MARGIN_LIKE;
2753 case LyXParagraph::FIG:
2754 case LyXParagraph::WIDE_FIG:
2756 inner_tag = "title";
2760 case LyXParagraph::TAB:
2761 case LyXParagraph::WIDE_TAB:
2763 inner_tag = "title";
2768 sgmlOpenTag(os, depth, tag);
2769 if ((present == TAB_LIKE) || (present == FIG_LIKE)) {
2770 DocBookHandleCaption(os, inner_tag, depth,
2774 sgmlOpenTag(os, depth + 1, inner_tag);
2777 // ignore all caption here, we processed them above!!!
2778 if (par->layout != textclasslist
2779 .NumberOfLayout(params.textclass,
2780 "Caption").second) {
2781 std::ostringstream ost;
2782 SimpleDocBookOnePar(ost, extra_par, par,
2783 desc_on, depth + 2);
2784 tmp_par += ost.str().c_str();
2786 tmp_par = frontStrip(strip(tmp_par));
2792 if (!inner_tag.empty()) sgmlCloseTag(os, depth + 1, inner_tag);
2793 if (!extra_par.empty()) os << extra_par;
2794 if (!tag.empty()) sgmlCloseTag(os, depth, tag);
2799 // checks, if newcol chars should be put into this line
2800 // writes newline, if necessary.
2803 void linux_doc_line_break(ostream & os, string::size_type & colcount,
2804 string::size_type newcol)
2807 if (colcount > lyxrc.ascii_linelen) {
2809 colcount = newcol; // assume write after this call
2824 string tag_name(PAR_TAG const & pt) {
2826 case NONE: return "!-- --";
2827 case TT: return "tt";
2828 case SF: return "sf";
2829 case BF: return "bf";
2830 case IT: return "it";
2831 case SL: return "sl";
2832 case EM: return "em";
2839 void operator|=(PAR_TAG & p1, PAR_TAG const & p2)
2841 p1 = static_cast<PAR_TAG>(p1 | p2);
2846 void reset(PAR_TAG & p1, PAR_TAG const & p2)
2848 p1 = static_cast<PAR_TAG>( p1 & ~p2);
2856 // Handle internal paragraph parsing -- layout already processed.
2857 void Buffer::SimpleLinuxDocOnePar(ostream & os,
2858 LyXParagraph * par, int /*depth*/)
2860 LyXLayout const & style = textclasslist.Style(params.textclass,
2862 string::size_type char_line_count = 5; // Heuristic choice ;-)
2864 // gets paragraph main font
2867 if (style.labeltype == LABEL_MANUAL) {
2868 font_old = style.labelfont;
2871 font_old = style.font;
2875 LyXFont::FONT_FAMILY family_type = LyXFont::ROMAN_FAMILY;
2876 LyXFont::FONT_SERIES series_type = LyXFont::MEDIUM_SERIES;
2877 LyXFont::FONT_SHAPE shape_type = LyXFont::UP_SHAPE;
2880 stack < PAR_TAG > tag_state;
2881 // parsing main loop
2882 for (LyXParagraph::size_type i = 0; i < par->size(); ++i) {
2884 PAR_TAG tag_close = NONE;
2885 list < PAR_TAG > tag_open;
2887 LyXFont const font = par->getFont(params, i);
2889 if (font_old.family() != font.family()) {
2890 switch (family_type) {
2891 case LyXFont::SANS_FAMILY:
2894 case LyXFont::TYPEWRITER_FAMILY:
2901 family_type = font.family();
2903 switch (family_type) {
2904 case LyXFont::SANS_FAMILY:
2905 tag_open.push_back(SF);
2907 case LyXFont::TYPEWRITER_FAMILY:
2908 tag_open.push_back(TT);
2915 if (font_old.series() != font.series()) {
2916 switch (series_type) {
2917 case LyXFont::BOLD_SERIES:
2924 series_type = font.series();
2926 switch (series_type) {
2927 case LyXFont::BOLD_SERIES:
2928 tag_open.push_back(BF);
2936 if (font_old.shape() != font.shape()) {
2937 switch (shape_type) {
2938 case LyXFont::ITALIC_SHAPE:
2941 case LyXFont::SLANTED_SHAPE:
2948 shape_type = font.shape();
2950 switch (shape_type) {
2951 case LyXFont::ITALIC_SHAPE:
2952 tag_open.push_back(IT);
2954 case LyXFont::SLANTED_SHAPE:
2955 tag_open.push_back(SL);
2962 if (font_old.emph() != font.emph()) {
2963 if (font.emph() == LyXFont::ON) {
2964 tag_open.push_back(EM);
2973 list < PAR_TAG > temp;
2974 while(!tag_state.empty() && tag_close ) {
2975 PAR_TAG k = tag_state.top();
2977 os << "</" << tag_name(k) << ">";
2984 for(list< PAR_TAG >::const_iterator j = temp.begin();
2985 j != temp.end(); ++j) {
2987 os << "<" << tag_name(*j) << ">";
2990 for(list< PAR_TAG >::const_iterator j = tag_open.begin();
2991 j != tag_open.end(); ++j) {
2993 os << "<" << tag_name(*j) << ">";
2996 char c = par->GetChar(i);
2998 if (c == LyXParagraph::META_INSET) {
2999 Inset * inset = par->GetInset(i);
3000 inset->Linuxdoc(this, os);
3005 if (font.latex() == LyXFont::ON || style.latexparam() == "CDATA") {
3006 // "TeX"-Mode on == > SGML-Mode on.
3012 if (par->linuxDocConvertChar(c, sgml_string)
3013 && !style.free_spacing) {
3014 // in freespacing mode, spaces are
3015 // non-breaking characters
3016 if (desc_on) {// if char is ' ' then...
3019 linux_doc_line_break(os, char_line_count, 6);
3023 linux_doc_line_break(os, char_line_count, 1);
3028 char_line_count += sgml_string.length();
3034 while (!tag_state.empty()) {
3035 os << "</" << tag_name(tag_state.top()) << ">";
3039 // resets description flag correctly
3041 // <tag> not closed...
3042 linux_doc_line_break(os, char_line_count, 6);
3048 // Print an error message.
3049 void Buffer::LinuxDocError(LyXParagraph * par, int pos,
3050 string const & message)
3052 // insert an error marker in text
3053 InsetError * new_inset = new InsetError(message);
3054 par->InsertInset(pos, new_inset);
3058 void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
3060 ofstream ofs(fname.c_str());
3062 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
3066 LyXParagraph * par = paragraph;
3068 niceFile = nice; // this will be used by Insetincludes.
3070 LyXTextClass const & tclass =
3071 textclasslist.TextClass(params.textclass);
3073 LaTeXFeatures features(params, tclass.numLayouts());
3078 string top_element = textclasslist.LatexnameOfClass(params.textclass);
3081 string sgml_includedfiles = features.getIncludedFiles(fname);
3083 ofs << "<!doctype " << top_element
3084 << " public \"-//OASIS//DTD DocBook V3.1//EN\"";
3086 if (params.preamble.empty() && sgml_includedfiles.empty())
3089 ofs << "\n [ " << params.preamble
3090 << sgml_includedfiles << " \n]>\n\n";
3093 string top = top_element;
3095 top += params.language->code();
3098 if (!params.options.empty()) {
3100 top += params.options;
3102 sgmlOpenTag(ofs, 0, top);
3104 ofs << "<!-- DocBook file was created by " << LYX_DOCVERSION
3105 << "\n See http://www.lyx.org/ for more information -->\n";
3107 vector<string> environment_stack(10);
3108 vector<string> environment_inner(10);
3109 vector<string> command_stack(10);
3111 bool command_flag = false;
3112 int command_depth = 0;
3113 int command_base = 0;
3115 int depth = 0; // paragraph depth
3118 string command_name;
3124 int desc_on = 0; // description mode
3126 LyXLayout const & style =
3127 textclasslist.Style(params.textclass,
3130 // environment tag closing
3131 for (; depth > par->params.depth(); --depth) {
3132 if (environment_inner[depth] != "!-- --") {
3133 item_name = "listitem";
3134 sgmlCloseTag(ofs, command_depth + depth,
3136 if (environment_inner[depth] == "varlistentry")
3137 sgmlCloseTag(ofs, depth+command_depth,
3138 environment_inner[depth]);
3140 sgmlCloseTag(ofs, depth + command_depth,
3141 environment_stack[depth]);
3142 environment_stack[depth].erase();
3143 environment_inner[depth].erase();
3146 if (depth == par->params.depth()
3147 && environment_stack[depth] != style.latexname()
3148 && !environment_stack[depth].empty()) {
3149 if (environment_inner[depth] != "!-- --") {
3150 item_name= "listitem";
3151 sgmlCloseTag(ofs, command_depth+depth,
3153 if (environment_inner[depth] == "varlistentry")
3155 depth + command_depth,
3156 environment_inner[depth]);
3159 sgmlCloseTag(ofs, depth + command_depth,
3160 environment_stack[depth]);
3162 environment_stack[depth].erase();
3163 environment_inner[depth].erase();
3166 // Write opening SGML tags.
3167 switch (style.latextype) {
3168 case LATEX_PARAGRAPH:
3169 sgmlOpenTag(ofs, depth + command_depth,
3175 LinuxDocError(par, 0,
3176 _("Error : Wrong depth for "
3177 "LatexType Command.\n"));
3179 command_name = style.latexname();
3181 sgmlparam = style.latexparam();
3182 c_params = split(sgmlparam, c_depth,'|');
3184 cmd_depth = lyx::atoi(c_depth);
3187 if (cmd_depth < command_base) {
3188 for (int j = command_depth; j >= command_base; --j)
3189 sgmlCloseTag(ofs, j, command_stack[j]);
3190 command_depth = command_base = cmd_depth;
3191 } else if (cmd_depth <= command_depth) {
3192 for (int j = command_depth; j >= cmd_depth; --j)
3193 sgmlCloseTag(ofs, j, command_stack[j]);
3194 command_depth = cmd_depth;
3196 command_depth = cmd_depth;
3198 command_depth = command_base = cmd_depth;
3199 command_flag = true;
3201 if (command_stack.size() == command_depth + 1)
3202 command_stack.push_back("");
3203 command_stack[command_depth] = command_name;
3205 // treat label as a special case for
3206 // more WYSIWYM handling.
3207 if (par->GetChar(0) == LyXParagraph::META_INSET) {
3208 Inset * inset = par->GetInset(0);
3209 Inset::Code lyx_code = inset->LyxCode();
3210 if (lyx_code == Inset::LABEL_CODE){
3211 command_name += " id=\"";
3212 command_name += (static_cast<InsetCommand *>(inset))->getContents();
3213 command_name += "\"";
3218 sgmlOpenTag(ofs, depth + command_depth, command_name);
3219 if (c_params.empty())
3220 item_name = "title";
3222 item_name = c_params;
3223 sgmlOpenTag(ofs, depth + 1 + command_depth, item_name);
3226 case LATEX_ENVIRONMENT:
3227 case LATEX_ITEM_ENVIRONMENT:
3228 if (depth < par->params.depth()) {
3229 depth = par->params.depth();
3230 environment_stack[depth].erase();
3233 if (environment_stack[depth] != style.latexname()) {
3234 if(environment_stack.size() == depth + 1) {
3235 environment_stack.push_back("!-- --");
3236 environment_inner.push_back("!-- --");
3238 environment_stack[depth] = style.latexname();
3239 environment_inner[depth] = "!-- --";
3240 sgmlOpenTag(ofs, depth + command_depth,
3241 environment_stack[depth]);
3243 if (environment_inner[depth] != "!-- --") {
3244 item_name= "listitem";
3246 command_depth + depth,
3248 if (environment_inner[depth] == "varlistentry")
3250 depth + command_depth,
3251 environment_inner[depth]);
3255 if (style.latextype == LATEX_ENVIRONMENT) {
3256 if (!style.latexparam().empty()) {
3257 if(style.latexparam() == "CDATA")
3260 sgmlOpenTag(ofs, depth + command_depth,
3261 style.latexparam());
3266 desc_on = (style.labeltype == LABEL_MANUAL);
3269 environment_inner[depth]= "varlistentry";
3271 environment_inner[depth]= "listitem";
3273 sgmlOpenTag(ofs, depth + 1 + command_depth,
3274 environment_inner[depth]);
3278 sgmlOpenTag(ofs, depth + 1 + command_depth,
3282 sgmlOpenTag(ofs, depth + 1 + command_depth,
3287 sgmlOpenTag(ofs, depth + command_depth,
3295 SimpleDocBookOnePar(ofs, extra_par, par, desc_on,
3296 depth + 1 + command_depth);
3298 DocBookHandleFootnote(ofs, par,
3299 depth + 1 + command_depth);
3300 } while(par && par->IsDummy());
3303 SimpleDocBookOnePar(ofs, extra_par, par, desc_on,
3304 depth + 1 + command_depth);
3308 // write closing SGML tags
3309 switch (style.latextype) {
3311 if (c_params.empty())
3315 sgmlCloseTag(ofs, depth + command_depth, end_tag);
3317 case LATEX_ENVIRONMENT:
3318 if (!style.latexparam().empty()) {
3319 if(style.latexparam() == "CDATA")
3322 sgmlCloseTag(ofs, depth + command_depth,
3323 style.latexparam());
3326 case LATEX_ITEM_ENVIRONMENT:
3327 if (desc_on == 1) break;
3329 sgmlCloseTag(ofs, depth + 1 + command_depth, end_tag);
3331 case LATEX_PARAGRAPH:
3332 sgmlCloseTag(ofs, depth + command_depth, style.latexname());
3335 sgmlCloseTag(ofs, depth + command_depth, style.latexname());
3341 for (; depth >= 0; --depth) {
3342 if (!environment_stack[depth].empty()) {
3343 if (environment_inner[depth] != "!-- --") {
3344 item_name = "listitem";
3345 sgmlCloseTag(ofs, command_depth + depth,
3347 if (environment_inner[depth] == "varlistentry")
3348 sgmlCloseTag(ofs, depth + command_depth,
3349 environment_inner[depth]);
3352 sgmlCloseTag(ofs, depth + command_depth,
3353 environment_stack[depth]);
3357 for (int j = command_depth; j >= command_base; --j)
3358 if (!command_stack[j].empty())
3359 sgmlCloseTag(ofs, j, command_stack[j]);
3362 sgmlCloseTag(ofs, 0, top_element);
3365 // How to check for successful close
3369 void Buffer::SimpleDocBookOnePar(ostream & os, string & extra,
3370 LyXParagraph * par, int & desc_on,
3373 bool emph_flag = false;
3375 LyXLayout const & style = textclasslist.Style(params.textclass,
3378 LyXFont font_old = style.labeltype == LABEL_MANUAL ? style.labelfont : style.font;
3380 int char_line_count = depth;
3381 if (!style.free_spacing)
3382 os << string(depth,' ');
3384 // parsing main loop
3385 for (LyXParagraph::size_type i = 0;
3386 i < par->size(); ++i) {
3387 LyXFont font = par->getFont(params, i);
3389 // handle <emphasis> tag
3390 if (font_old.emph() != font.emph()) {
3391 if (font.emph() == LyXFont::ON) {
3395 os << "</emphasis>";
3400 char c = par->GetChar(i);
3402 if (c == LyXParagraph::META_INSET) {
3403 Inset * inset = par->GetInset(i);
3404 std::ostringstream ost;
3405 inset->DocBook(this, ost);
3406 string tmp_out = ost.str().c_str();
3409 // This code needs some explanation:
3410 // Two insets are treated specially
3411 // label if it is the first element in a command paragraph
3413 // graphics inside tables or figure floats can't go on
3414 // title (the equivalente in latex for this case is caption
3415 // and title should come first
3418 if (desc_on!= 3 || i!= 0) {
3419 if (!tmp_out.empty() && tmp_out[0] == '@') {
3421 extra += frontStrip(tmp_out, '@');
3423 os << frontStrip(tmp_out, '@');
3428 } else if (font.latex() == LyXFont::ON) {
3429 // "TeX"-Mode on ==> SGML-Mode on.
3435 if (par->linuxDocConvertChar(c, sgml_string)
3436 && !style.free_spacing) { // in freespacing
3438 // non-breaking characters
3442 os << "\n</term><listitem><para>";
3455 os << "</emphasis>";
3458 // resets description flag correctly
3460 // <term> not closed...
3467 // This should be enabled when the Chktex class is implemented. (Asger)
3468 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
3469 // Other flags: -wall -v0 -x
3470 int Buffer::runChktex()
3472 if (!users->text) return 0;
3474 ProhibitInput(users);
3476 // get LaTeX-Filename
3477 string const name = getLatexName();
3478 string path = OnlyPath(filename);
3480 string const org_path = path;
3481 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3485 Path p(path); // path to LaTeX file
3486 users->owner()->getMiniBuffer()->Set(_("Running chktex..."));
3488 // Remove all error insets
3489 bool const removedErrorInsets = users->removeAutoInsets();
3491 // Generate the LaTeX file if neccessary
3492 makeLaTeXFile(name, org_path, false);
3495 Chktex chktex(lyxrc.chktex_command, name, filepath);
3496 int res = chktex.run(terr); // run chktex
3499 WriteAlert(_("chktex did not work!"),
3500 _("Could not run with file:"), name);
3501 } else if (res > 0) {
3502 // Insert all errors as errors boxes
3503 users->insertErrors(terr);
3506 // if we removed error insets before we ran chktex or if we inserted
3507 // error insets after we ran chktex, this must be run:
3508 if (removedErrorInsets || res){
3510 users->fitCursor(users->text);
3518 void Buffer::validate(LaTeXFeatures & features) const
3520 LyXParagraph * par = paragraph;
3521 LyXTextClass const & tclass =
3522 textclasslist.TextClass(params.textclass);
3524 // AMS Style is at document level
3526 features.amsstyle = (params.use_amsmath ||
3527 tclass.provides(LyXTextClass::amsmath));
3530 // We don't use "lyxerr.debug" because of speed. (Asger)
3531 if (lyxerr.debugging(Debug::LATEX))
3532 lyxerr << "Paragraph: " << par << endl;
3534 // Now just follow the list of paragraphs and run
3535 // validate on each of them.
3536 par->validate(features);
3538 // and then the next paragraph
3546 // the bullet shapes are buffer level not paragraph level
3547 // so they are tested here
3548 for (int i = 0; i < 4; ++i) {
3549 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
3550 int const font = params.user_defined_bullets[i].getFont();
3552 int const c = params
3553 .user_defined_bullets[i]
3560 features.latexsym = true;
3562 } else if (font == 1) {
3563 features.amssymb = true;
3564 } else if ((font >= 2 && font <= 5)) {
3565 features.pifont = true;
3570 if (lyxerr.debugging(Debug::LATEX)) {
3571 features.showStruct();
3576 void Buffer::setPaperStuff()
3578 params.papersize = BufferParams::PAPER_DEFAULT;
3579 char const c1 = params.paperpackage;
3580 if (c1 == BufferParams::PACKAGE_NONE) {
3581 char const c2 = params.papersize2;
3582 if (c2 == BufferParams::VM_PAPER_USLETTER)
3583 params.papersize = BufferParams::PAPER_USLETTER;
3584 else if (c2 == BufferParams::VM_PAPER_USLEGAL)
3585 params.papersize = BufferParams::PAPER_LEGALPAPER;
3586 else if (c2 == BufferParams::VM_PAPER_USEXECUTIVE)
3587 params.papersize = BufferParams::PAPER_EXECUTIVEPAPER;
3588 else if (c2 == BufferParams::VM_PAPER_A3)
3589 params.papersize = BufferParams::PAPER_A3PAPER;
3590 else if (c2 == BufferParams::VM_PAPER_A4)
3591 params.papersize = BufferParams::PAPER_A4PAPER;
3592 else if (c2 == BufferParams::VM_PAPER_A5)
3593 params.papersize = BufferParams::PAPER_A5PAPER;
3594 else if ((c2 == BufferParams::VM_PAPER_B3) || (c2 == BufferParams::VM_PAPER_B4) ||
3595 (c2 == BufferParams::VM_PAPER_B5))
3596 params.papersize = BufferParams::PAPER_B5PAPER;
3597 } else if ((c1 == BufferParams::PACKAGE_A4) || (c1 == BufferParams::PACKAGE_A4WIDE) ||
3598 (c1 == BufferParams::PACKAGE_WIDEMARGINSA4))
3599 params.papersize = BufferParams::PAPER_A4PAPER;
3603 // This function should be in Buffer because it's a buffer's property (ale)
3604 string const Buffer::getIncludeonlyList(char delim)
3607 for (inset_iterator it = inset_iterator_begin();
3608 it != inset_iterator_end(); ++it) {
3609 if ((*it)->LyxCode() == Inset::INCLUDE_CODE) {
3610 InsetInclude * insetinc =
3611 static_cast<InsetInclude *>(*it);
3612 if (insetinc->isIncludeOnly()) {
3615 lst += insetinc->getRelFileBaseName();
3619 lyxerr.debug() << "Includeonly(" << lst << ')' << endl;
3624 vector<string> const Buffer::getLabelList()
3626 /// if this is a child document and the parent is already loaded
3627 /// Use the parent's list instead [ale990407]
3628 if (!params.parentname.empty()
3629 && bufferlist.exists(params.parentname)) {
3630 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3632 return tmp->getLabelList();
3635 vector<string> label_list;
3636 for (inset_iterator it = inset_iterator_begin();
3637 it != inset_iterator_end(); ++it) {
3638 vector<string> const l = (*it)->getLabelList();
3639 label_list.insert(label_list.end(), l.begin(), l.end());
3645 Buffer::Lists const Buffer::getLists() const
3648 LyXParagraph * par = paragraph;
3651 LyXTextClassList::size_type cap;
3652 boost::tie(found, cap) = textclasslist
3653 .NumberOfLayout(params.textclass, "Caption");
3658 if (par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
3659 if (textclasslist.Style(params.textclass,
3660 par->GetLayout()).labeltype
3661 == LABEL_SENSITIVE) {
3663 switch (par->footnotekind) {
3664 case LyXParagraph::FIG:
3665 case LyXParagraph::WIDE_FIG:
3668 case LyXParagraph::TAB:
3669 case LyXParagraph::WIDE_TAB:
3672 case LyXParagraph::ALGORITHM:
3675 case LyXParagraph::FOOTNOTE:
3676 case LyXParagraph::MARGIN:
3679 if (!type.empty()) {
3680 SingleList & item = l[type];
3682 tostr(item.size()+1) + ". " + par->String(this, false);
3683 item.push_back(TocItem(par, 0, str));
3686 } else if (!par->IsDummy()) {
3688 char const labeltype =
3689 textclasslist.Style(params.textclass,
3690 par->GetLayout()).labeltype;
3692 if (labeltype >= LABEL_COUNTER_CHAPTER
3693 && labeltype <= LABEL_COUNTER_CHAPTER + params.tocdepth) {
3694 // insert this into the table of contents
3695 SingleList & item = l["TOC"];
3698 textclasslist.TextClass(params.textclass).maxcounter());
3699 item.push_back(TocItem(par, depth, par->String(this, true)));
3702 // For each paragrph, traverse its insets and look for
3706 LyXParagraph::inset_iterator it =
3707 par->inset_iterator_begin();
3708 LyXParagraph::inset_iterator end =
3709 par->inset_iterator_end();
3711 for (; it != end; ++it) {
3712 if ((*it)->LyxCode() == Inset::FLOAT_CODE) {
3714 static_cast<InsetFloat*>(*it);
3716 string const type = il->type();
3718 // Now find the caption in the float...
3719 // We now tranverse the paragraphs of
3721 LyXParagraph * tmp = il->inset.par;
3723 if (tmp->layout == cap) {
3724 SingleList & item = l[type];
3726 tostr(item.size()+1) + ". " + tmp->String(this, false);
3727 item.push_back(TocItem(tmp, 0 , str));
3734 lyxerr << "caption not found" << endl;
3749 // This is also a buffer property (ale)
3750 vector<pair<string, string> > const Buffer::getBibkeyList()
3752 /// if this is a child document and the parent is already loaded
3753 /// Use the parent's list instead [ale990412]
3754 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3755 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3757 return tmp->getBibkeyList();
3760 vector<pair<string, string> > keys;
3761 LyXParagraph * par = paragraph;
3764 keys.push_back(pair<string, string>(par->bibkey->getContents(),
3765 par->String(this, false)));
3773 // Might be either using bibtex or a child has bibliography
3775 for (inset_iterator it = inset_iterator_begin();
3776 it != inset_iterator_end(); ++it) {
3777 // Search for Bibtex or Include inset
3778 if ((*it)->LyxCode() == Inset::BIBTEX_CODE) {
3779 vector<pair<string,string> > tmp =
3780 static_cast<InsetBibtex*>(*it)->getKeys(this);
3781 keys.insert(keys.end(), tmp.begin(), tmp.end());
3782 } else if ((*it)->LyxCode() == Inset::INCLUDE_CODE) {
3783 vector<pair<string,string> > const tmp =
3784 static_cast<InsetInclude*>(*it)->getKeys();
3785 keys.insert(keys.end(), tmp.begin(), tmp.end());
3794 bool Buffer::isDepClean(string const & name) const
3796 DEPCLEAN * item = dep_clean;
3797 while (item && item->master != name)
3799 if (!item) return true;
3804 void Buffer::markDepClean(string const & name)
3807 dep_clean = new DEPCLEAN;
3808 dep_clean->clean = true;
3809 dep_clean->master = name;
3810 dep_clean->next = 0;
3812 DEPCLEAN * item = dep_clean;
3813 while (item && item->master != name)
3818 item = new DEPCLEAN;
3820 item->master = name;
3827 bool Buffer::Dispatch(string const & command)
3829 // Split command string into command and argument
3831 string line = frontStrip(command);
3832 string const arg = strip(frontStrip(split(line, cmd, ' ')));
3834 return Dispatch(lyxaction.LookupFunc(cmd), arg);
3838 bool Buffer::Dispatch(int action, string const & argument)
3840 bool dispatched = true;
3843 Exporter::Export(this, argument, false);
3853 void Buffer::resize()
3855 /// resize the BufferViews!
3861 void Buffer::resizeInsets(BufferView * bv)
3863 /// then remove all LyXText in text-insets
3864 LyXParagraph * par = paragraph;
3866 for (; par; par = par->next_) {
3867 par->resizeInsetsLyXText(bv);
3870 for (; par; par = par->next()) {
3871 par->resizeInsetsLyXText(bv);
3877 void Buffer::ChangeLanguage(Language const * from, Language const * to)
3880 LyXParagraph * par = paragraph;
3882 par->ChangeLanguage(params, from, to);
3892 bool Buffer::isMultiLingual()
3894 LyXParagraph * par = paragraph;
3896 if (par->isMultiLingual(params))
3908 Buffer::inset_iterator::inset_iterator(LyXParagraph * paragraph,
3909 LyXParagraph::size_type pos)
3912 it = par->InsetIterator(pos);
3913 if (it == par->inset_iterator_end()) {
3924 void Buffer::inset_iterator::SetParagraph()
3927 it = par->inset_iterator_begin();
3928 if (it != par->inset_iterator_end())
3937 // We maintain an invariant that whenever par = 0 then it = 0