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 * ======================================================
22 #include <sys/types.h>
32 #pragma implementation "buffer.h"
36 #include "bufferlist.h"
38 #include "lyx_gui_misc.h"
39 #include "LyXAction.h"
42 #include "tex-strings.h"
44 #include "bufferview_funcs.h"
45 #include "minibuffer.h"
48 #include "mathed/formulamacro.h"
49 #include "insets/lyxinset.h"
50 #include "insets/inseterror.h"
51 #include "insets/insetlabel.h"
52 #include "insets/insetref.h"
53 #include "insets/inseturl.h"
54 #include "insets/insetinfo.h"
55 #include "insets/insetquotes.h"
56 #include "insets/insetlatexaccent.h"
57 #include "insets/insetbib.h"
58 #include "insets/insetcite.h"
59 #include "insets/insetexternal.h"
60 #include "insets/insetindex.h"
61 #include "insets/insetinclude.h"
62 #include "insets/insettoc.h"
63 #include "insets/insetparent.h"
64 #include "insets/insetspecialchar.h"
65 #include "insets/figinset.h"
66 #include "insets/insettext.h"
67 #include "insets/insetert.h"
68 #include "insets/insetgraphics.h"
69 #include "insets/insetfoot.h"
70 #include "insets/insetmarginal.h"
71 #include "insets/insetminipage.h"
72 #include "insets/insetfloat.h"
73 #include "insets/insetlist.h"
74 #include "insets/insettabular.h"
75 #include "insets/insettheorem.h"
76 #include "insets/insetcaption.h"
77 #include "support/filetools.h"
78 #include "support/path.h"
84 #include "LaTeXFeatures.h"
85 #include "support/syscall.h"
86 #include "support/lyxlib.h"
87 #include "support/FileInfo.h"
91 #include "lyx_gui_misc.h" // WarnReadonly()
92 #include "frontends/Dialogs.h"
107 //#ifdef HAVE_SSTREAM
108 using std::istringstream;
111 // all these externs should eventually be removed.
112 extern BufferList bufferlist;
115 extern void MenuExport(Buffer *, string const &);
117 extern LyXAction lyxaction;
120 static const float LYX_FORMAT = 2.17;
122 extern int tex_code_break_column;
125 Buffer::Buffer(string const & file, bool ronly)
127 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
129 filepath = OnlyPath(file);
138 if (read_only || (lyxrc.use_tempdir)) {
139 tmppath = CreateBufferTmpDir();
140 } else tmppath.erase();
146 lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
147 // here the buffer should take care that it is
148 // saved properly, before it goes into the void.
150 // make sure that views using this buffer
155 if (!tmppath.empty()) {
156 DestroyBufferTmpDir(tmppath);
159 LyXParagraph * par = paragraph;
160 LyXParagraph * tmppar;
170 string const Buffer::getLatexName(bool no_path) const
173 return OnlyFilename(ChangeExtension(MakeLatexName(filename),
176 return ChangeExtension(MakeLatexName(filename),
181 void Buffer::setReadonly(bool flag)
183 if (read_only != flag) {
186 users->owner()->getDialogs()->updateBufferDependent();
189 WarnReadonly(filename);
194 bool Buffer::saveParamsAsDefaults()
196 string fname = AddName(AddPath(user_lyxdir, "templates/"),
198 Buffer defaults = Buffer(fname);
200 // Use the current buffer's parameters as default
201 defaults.params = params;
203 // add an empty paragraph. Is this enough?
204 defaults.paragraph = new LyXParagraph;
206 return defaults.writeFile(defaults.filename, false);
210 /// Update window titles of all users
211 // Should work on a list
212 void Buffer::updateTitles() const
214 if (users) users->owner()->updateWindowTitle();
218 /// Reset autosave timer of all users
219 // Should work on a list
220 void Buffer::resetAutosaveTimers() const
222 if (users) users->owner()->resetAutosaveTimer();
226 void Buffer::fileName(string const & newfile)
228 filename = MakeAbsPath(newfile);
229 filepath = OnlyPath(filename);
230 setReadonly(IsFileWriteable(filename) == 0);
235 // candidate for move to BufferView
236 // (at least some parts in the beginning of the func)
239 // changed to be public and have one parameter
240 // if par = 0 normal behavior
241 // else insert behavior
242 // Returns false if "\the_end" is not read for formats >= 2.13. (Asger)
243 bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par)
247 char depth = 0; // signed or unsigned?
249 LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
250 LyXParagraph::footnote_kind footnotekind = LyXParagraph::FOOTNOTE;
252 bool the_end_read = false;
254 LyXParagraph * return_par = 0;
255 LyXFont font(LyXFont::ALL_INHERIT, params.language_info);
256 if (format < 2.16 && params.language == "hebrew")
257 font.setLanguage(default_language);
259 // If we are inserting, we cheat and get a token in advance
260 bool has_token = false;
264 par = new LyXParagraph;
266 users->text->BreakParagraph(users);
267 return_par = users->text->FirstParagraph();
270 // We don't want to adopt the parameters from the
271 // document we insert, so we skip until the text begins:
274 pretoken = lex.GetString();
275 if (pretoken == "\\layout") {
287 pretoken = lex.GetString();
290 // Profiling show this should give a lot: (Asger)
291 string const token = pretoken;
295 the_end_read = parseSingleLyXformat2Token(lex, par, return_par,
308 paragraph = return_par;
314 // We'll remove this later. (Lgb)
315 static string last_inset_read;
319 Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
320 LyXParagraph *& return_par,
321 string const & token, int & pos,
322 char & depth, LyXFont & font
324 , LyXParagraph::footnote_flag & footnoteflag,
325 LyXParagraph::footnote_kind & footnotekind
329 bool the_end_read = false;
331 if (token[0] != '\\') {
332 for (string::const_iterator cit = token.begin();
333 cit != token.end(); ++cit) {
334 par->InsertChar(pos, (*cit), font);
337 } else if (token == "\\i") {
338 Inset * inset = new InsetLatexAccent;
339 inset->Read(this, lex);
340 par->InsertInset(pos, inset, font);
342 } else if (token == "\\layout") {
347 par = new LyXParagraph(par);
351 string layoutname = lex.GetString();
352 pair<bool, LyXTextClass::LayoutList::size_type> pp
353 = textclasslist.NumberOfLayout(params.textclass,
356 par->layout = pp.second;
357 } else { // layout not found
358 // use default layout "Standard" (0)
361 // Test whether the layout is obsolete.
362 LyXLayout const & layout =
363 textclasslist.Style(params.textclass,
365 if (!layout.obsoleted_by().empty())
367 textclasslist.NumberOfLayout(params.textclass,
368 layout.obsoleted_by()).second;
370 par->footnoteflag = footnoteflag;
371 par->footnotekind = footnotekind;
374 font = LyXFont(LyXFont::ALL_INHERIT, params.language_info);
375 if (format < 2.16 && params.language == "hebrew")
376 font.setLanguage(default_language);
378 } else if (token == "\\end_float") {
383 par = new LyXParagraph(par);
385 footnotekind = LyXParagraph::FOOTNOTE;
386 footnoteflag = LyXParagraph::NO_FOOTNOTE;
389 par->layout = LYX_DUMMY_LAYOUT;
390 font = LyXFont(LyXFont::ALL_INHERIT, params.language_info);
391 if (format < 2.16 && params.language == "hebrew")
392 font.setLanguage(default_language);
393 } else if (token == "\\begin_float") {
394 int tmpret = lex.FindToken(string_footnotekinds);
395 if (tmpret == -1) ++tmpret;
396 if (tmpret != LYX_LAYOUT_DEFAULT)
397 footnotekind = static_cast<LyXParagraph::footnote_kind>(tmpret); // bad
398 if (footnotekind == LyXParagraph::FOOTNOTE
399 || footnotekind == LyXParagraph::MARGIN)
400 footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
402 footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
404 } else if (token == "\\begin_float") {
405 // This is the compability reader, unfinished but tested.
408 string tmptok = lex.GetString();
409 //lyxerr << "old float: " << tmptok << endl;
414 if (tmptok == "footnote") {
415 inset = new InsetFoot;
416 } else if (tmptok == "margin") {
417 inset = new InsetMarginal;
418 } else if (tmptok == "fig") {
419 inset = new InsetFloat("figure");
420 old_float += "placement htbp\n";
421 } else if (tmptok == "tab") {
422 inset = new InsetFloat("table");
423 old_float += "placement htbp\n";
424 } else if (tmptok == "alg") {
425 inset = new InsetFloat("algorithm");
426 old_float += "placement htbp\n";
427 } else if (tmptok == "wide-fig") {
428 InsetFloat * tmp = new InsetFloat("figure");
431 old_float += "placement htbp\n";
432 } else if (tmptok == "wide-tab") {
433 InsetFloat * tmp = new InsetFloat("table");
436 old_float += "placement htbp\n";
439 if (!inset) return false; // no end read yet
441 old_float += "collapsed true\n";
443 // Here we need to check for \end_deeper and handle that
444 // before we do the footnote parsing.
445 // This _is_ a hack! (Lgb)
448 string tmp = lex.GetString();
449 if (tmp == "\\end_deeper") {
450 lyxerr << "\\end_deeper caught!" << endl;
452 lex.printError("\\end_deeper: "
453 "depth is already null");
464 old_float += lex.getLongString("\\end_float");
465 old_float += "\n\\end_inset\n";
466 //lyxerr << "float body: " << old_float << endl;
468 //#ifdef HAVE_SSTREAM
469 istringstream istr(old_float);
471 // istrstream istr(old_float.c_str());
475 nylex.setStream(istr);
477 inset->Read(this, nylex);
478 par->InsertInset(pos, inset, font);
481 } else if (token == "\\begin_deeper") {
483 } else if (token == "\\end_deeper") {
485 lex.printError("\\end_deeper: "
486 "depth is already null");
490 } else if (token == "\\begin_preamble") {
491 params.readPreamble(lex);
492 } else if (token == "\\textclass") {
494 pair<bool, LyXTextClassList::size_type> pp =
495 textclasslist.NumberOfClass(lex.GetString());
497 params.textclass = pp.second;
499 lex.printError("Unknown textclass `$$Token'");
500 params.textclass = 0;
502 if (!textclasslist.Load(params.textclass)) {
503 // if the textclass wasn't loaded properly
504 // we need to either substitute another
505 // or stop loading the file.
506 // I can substitute but I don't see how I can
507 // stop loading... ideas?? ARRae980418
508 WriteAlert(_("Textclass Loading Error!"),
509 string(_("Can't load textclass ")) +
510 textclasslist.NameOfClass(params.textclass),
511 _("-- substituting default"));
512 params.textclass = 0;
514 } else if (token == "\\options") {
516 params.options = lex.GetString();
517 } else if (token == "\\language") {
518 params.readLanguage(lex);
519 } else if (token == "\\fontencoding") {
521 } else if (token == "\\inputencoding") {
523 params.inputenc = lex.GetString();
524 } else if (token == "\\graphics") {
525 params.readGraphicsDriver(lex);
526 } else if (token == "\\fontscheme") {
528 params.fonts = lex.GetString();
529 } else if (token == "\\noindent") {
530 par->noindent = true;
531 } else if (token == "\\fill_top") {
532 par->added_space_top = VSpace(VSpace::VFILL);
533 } else if (token == "\\fill_bottom") {
534 par->added_space_bottom = VSpace(VSpace::VFILL);
535 } else if (token == "\\line_top") {
536 par->line_top = true;
537 } else if (token == "\\line_bottom") {
538 par->line_bottom = true;
539 } else if (token == "\\pagebreak_top") {
540 par->pagebreak_top = true;
541 } else if (token == "\\pagebreak_bottom") {
542 par->pagebreak_bottom = true;
543 } else if (token == "\\start_of_appendix") {
544 par->start_of_appendix = true;
545 } else if (token == "\\paragraph_separation") {
546 int tmpret = lex.FindToken(string_paragraph_separation);
547 if (tmpret == -1) ++tmpret;
548 if (tmpret != LYX_LAYOUT_DEFAULT)
549 params.paragraph_separation =
550 static_cast<BufferParams::PARSEP>(tmpret);
551 } else if (token == "\\defskip") {
553 params.defskip = VSpace(lex.GetString());
554 } else if (token == "\\epsfig") { // obsolete
555 // Indeed it is obsolete, but we HAVE to be backwards
556 // compatible until 0.14, because otherwise all figures
557 // in existing documents are irretrivably lost. (Asger)
558 params.readGraphicsDriver(lex);
559 } else if (token == "\\quotes_language") {
560 int tmpret = lex.FindToken(string_quotes_language);
561 if (tmpret == -1) ++tmpret;
562 if (tmpret != LYX_LAYOUT_DEFAULT) {
563 InsetQuotes::quote_language tmpl =
564 InsetQuotes::EnglishQ;
567 tmpl = InsetQuotes::EnglishQ;
570 tmpl = InsetQuotes::SwedishQ;
573 tmpl = InsetQuotes::GermanQ;
576 tmpl = InsetQuotes::PolishQ;
579 tmpl = InsetQuotes::FrenchQ;
582 tmpl = InsetQuotes::DanishQ;
585 params.quotes_language = tmpl;
587 } else if (token == "\\quotes_times") {
589 switch(lex.GetInteger()) {
591 params.quotes_times = InsetQuotes::SingleQ;
594 params.quotes_times = InsetQuotes::DoubleQ;
597 } else if (token == "\\papersize") {
598 int tmpret = lex.FindToken(string_papersize);
602 params.papersize2 = tmpret;
603 } else if (token == "\\paperpackage") {
604 int tmpret = lex.FindToken(string_paperpackages);
607 params.paperpackage = BufferParams::PACKAGE_NONE;
609 params.paperpackage = tmpret;
610 } else if (token == "\\use_geometry") {
612 params.use_geometry = lex.GetInteger();
613 } else if (token == "\\use_amsmath") {
615 params.use_amsmath = lex.GetInteger();
616 } else if (token == "\\paperorientation") {
617 int tmpret = lex.FindToken(string_orientation);
618 if (tmpret == -1) ++tmpret;
619 if (tmpret != LYX_LAYOUT_DEFAULT)
620 params.orientation = static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
621 } else if (token == "\\paperwidth") {
623 params.paperwidth = lex.GetString();
624 } else if (token == "\\paperheight") {
626 params.paperheight = lex.GetString();
627 } else if (token == "\\leftmargin") {
629 params.leftmargin = lex.GetString();
630 } else if (token == "\\topmargin") {
632 params.topmargin = lex.GetString();
633 } else if (token == "\\rightmargin") {
635 params.rightmargin = lex.GetString();
636 } else if (token == "\\bottommargin") {
638 params.bottommargin = lex.GetString();
639 } else if (token == "\\headheight") {
641 params.headheight = lex.GetString();
642 } else if (token == "\\headsep") {
644 params.headsep = lex.GetString();
645 } else if (token == "\\footskip") {
647 params.footskip = lex.GetString();
648 } else if (token == "\\paperfontsize") {
650 params.fontsize = strip(lex.GetString());
651 } else if (token == "\\papercolumns") {
653 params.columns = lex.GetInteger();
654 } else if (token == "\\papersides") {
656 switch(lex.GetInteger()) {
658 case 1: params.sides = LyXTextClass::OneSide; break;
659 case 2: params.sides = LyXTextClass::TwoSides; break;
661 } else if (token == "\\paperpagestyle") {
663 params.pagestyle = strip(lex.GetString());
664 } else if (token == "\\bullet") {
666 int index = lex.GetInteger();
668 int temp_int = lex.GetInteger();
669 params.user_defined_bullets[index].setFont(temp_int);
670 params.temp_bullets[index].setFont(temp_int);
672 temp_int = lex.GetInteger();
673 params.user_defined_bullets[index].setCharacter(temp_int);
674 params.temp_bullets[index].setCharacter(temp_int);
676 temp_int = lex.GetInteger();
677 params.user_defined_bullets[index].setSize(temp_int);
678 params.temp_bullets[index].setSize(temp_int);
680 string temp_str = lex.GetString();
681 if (temp_str != "\\end_bullet") {
682 // this element isn't really necessary for
683 // parsing but is easier for humans
684 // to understand bullets. Put it back and
685 // set a debug message?
686 lex.printError("\\end_bullet expected, got" + temp_str);
687 //how can I put it back?
689 } else if (token == "\\bulletLaTeX") {
691 int index = lex.GetInteger();
693 string temp_str = lex.GetString(), sum_str;
694 while (temp_str != "\\end_bullet") {
695 // this loop structure is needed when user
696 // enters an empty string since the first
697 // thing returned will be the \\end_bullet
699 // if the LaTeX entry has spaces. Each element
700 // therefore needs to be read in turn
703 temp_str = lex.GetString();
705 params.user_defined_bullets[index].setText(sum_str);
706 params.temp_bullets[index].setText(sum_str);
707 } else if (token == "\\secnumdepth") {
709 params.secnumdepth = lex.GetInteger();
710 } else if (token == "\\tocdepth") {
712 params.tocdepth = lex.GetInteger();
713 } else if (token == "\\spacing") {
715 string tmp = strip(lex.GetString());
716 Spacing::Space tmp_space = Spacing::Default;
718 if (tmp == "single") {
719 tmp_space = Spacing::Single;
720 } else if (tmp == "onehalf") {
721 tmp_space = Spacing::Onehalf;
722 } else if (tmp == "double") {
723 tmp_space = Spacing::Double;
724 } else if (tmp == "other") {
726 tmp_space = Spacing::Other;
727 tmp_val = lex.GetFloat();
729 lex.printError("Unknown spacing token: '$$Token'");
731 // Small hack so that files written with klyx will be
734 par->spacing.set(tmp_space, tmp_val);
736 params.spacing.set(tmp_space, tmp_val);
738 } else if (token == "\\paragraph_spacing") {
740 string tmp = strip(lex.GetString());
741 if (tmp == "single") {
742 par->spacing.set(Spacing::Single);
743 } else if (tmp == "onehalf") {
744 par->spacing.set(Spacing::Onehalf);
745 } else if (tmp == "double") {
746 par->spacing.set(Spacing::Double);
747 } else if (tmp == "other") {
749 par->spacing.set(Spacing::Other,
752 lex.printError("Unknown spacing token: '$$Token'");
754 } else if (token == "\\float_placement") {
756 params.float_placement = lex.GetString();
757 } else if (token == "\\family") {
759 font.setLyXFamily(lex.GetString());
760 } else if (token == "\\series") {
762 font.setLyXSeries(lex.GetString());
763 } else if (token == "\\shape") {
765 font.setLyXShape(lex.GetString());
766 } else if (token == "\\size") {
768 font.setLyXSize(lex.GetString());
769 } else if (token == "\\latex") {
771 string tok = lex.GetString();
772 // This is dirty, but gone with LyX3. (Asger)
773 if (tok == "no_latex")
774 font.setLatex(LyXFont::OFF);
775 else if (tok == "latex")
776 font.setLatex(LyXFont::ON);
777 else if (tok == "default")
778 font.setLatex(LyXFont::INHERIT);
780 lex.printError("Unknown LaTeX font flag "
782 } else if (token == "\\lang") {
784 string tok = lex.GetString();
785 Languages::iterator lit = languages.find(tok);
786 if (lit != languages.end()) {
787 font.setLanguage(&(*lit).second);
789 font.setLanguage(params.language_info);
790 lex.printError("Unknown language `$$Token'");
792 } else if (token == "\\emph") {
794 font.setEmph(font.setLyXMisc(lex.GetString()));
795 } else if (token == "\\bar") {
797 string tok = lex.GetString();
798 // This is dirty, but gone with LyX3. (Asger)
800 font.setUnderbar(LyXFont::ON);
801 else if (tok == "no")
802 font.setUnderbar(LyXFont::OFF);
803 else if (tok == "default")
804 font.setUnderbar(LyXFont::INHERIT);
806 lex.printError("Unknown bar font flag "
808 } else if (token == "\\noun") {
810 font.setNoun(font.setLyXMisc(lex.GetString()));
811 } else if (token == "\\color") {
813 font.setLyXColor(lex.GetString());
814 } else if (token == "\\align") {
815 int tmpret = lex.FindToken(string_align);
816 if (tmpret == -1) ++tmpret;
817 if (tmpret != LYX_LAYOUT_DEFAULT) { // tmpret != 99 ???
819 for (; tmpret > 0; --tmpret)
820 tmpret2 = tmpret2 * 2;
821 par->align = LyXAlignment(tmpret2);
823 } else if (token == "\\added_space_top") {
825 par->added_space_top = VSpace(lex.GetString());
826 } else if (token == "\\added_space_bottom") {
828 par->added_space_bottom = VSpace(lex.GetString());
829 } else if (token == "\\pextra_type") {
831 par->pextra_type = lex.GetInteger();
832 } else if (token == "\\pextra_width") {
834 par->pextra_width = lex.GetString();
835 } else if (token == "\\pextra_widthp") {
837 par->pextra_widthp = lex.GetString();
838 } else if (token == "\\pextra_alignment") {
840 par->pextra_alignment = lex.GetInteger();
841 } else if (token == "\\pextra_hfill") {
843 par->pextra_hfill = lex.GetInteger();
844 } else if (token == "\\pextra_start_minipage") {
846 par->pextra_start_minipage = lex.GetInteger();
847 } else if (token == "\\labelwidthstring") {
849 par->labelwidthstring = lex.GetString();
850 // do not delete this token, it is still needed!
851 } else if (token == "\\end_inset") {
852 lyxerr << "Solitary \\end_inset. Missing \\begin_inset?.\n"
853 << "Last inset read was: " << last_inset_read
855 // Simply ignore this. The insets do not have
857 // But insets should read it, it is a part of
858 // the inset isn't it? Lgb.
859 } else if (token == "\\begin_inset") {
860 readInset(lex, par, pos, font);
861 } else if (token == "\\SpecialChar") {
862 LyXLayout const & layout =
863 textclasslist.Style(params.textclass,
866 // Insets don't make sense in a free-spacing context! ---Kayvan
867 if (layout.free_spacing) {
870 string next_token = lex.GetString();
871 if (next_token == "\\-") {
872 par->InsertChar(pos, '-', font);
873 } else if (next_token == "\\protected_separator"
874 || next_token == "~") {
875 par->InsertChar(pos, ' ', font);
877 lex.printError("Token `$$Token' "
879 "paragraph layout!");
884 Inset * inset = new InsetSpecialChar;
885 inset->Read(this, lex);
886 par->InsertInset(pos, inset, font);
889 } else if (token == "\\newline") {
890 par->InsertChar(pos, LyXParagraph::META_NEWLINE, font);
892 } else if (token == "\\LyXTable") {
894 Inset * inset = new InsetTabular(this);
895 inset->Read(this, lex);
896 par->InsertInset(pos, inset, font);
899 par->table = new LyXTable(lex);
901 } else if (token == "\\hfill") {
902 par->InsertChar(pos, LyXParagraph::META_HFILL, font);
904 } else if (token == "\\protected_separator") { // obsolete
905 // This is a backward compability thingie. (Lgb)
906 // Remove it later some time...introduced with fileformat
908 LyXLayout const & layout =
909 textclasslist.Style(params.textclass,
912 if (layout.free_spacing) {
913 par->InsertChar(pos, ' ', font);
915 Inset * inset = new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
916 par->InsertInset(pos, inset, font);
919 } else if (token == "\\bibitem") { // ale970302
921 InsetCommandParams p( "bibitem" );
922 par->bibkey = new InsetBibKey(p);
924 par->bibkey->Read(this, lex);
925 } else if (token == "\\backslash") {
926 par->InsertChar(pos, '\\', font);
928 } else if (token == "\\the_end") {
931 // This should be insurance for the future: (Asger)
932 lex.printError("Unknown token `$$Token'. "
933 "Inserting as text.");
934 string::const_iterator cit = token.begin();
935 string::const_iterator end = token.end();
936 for(; cit != end; ++cit) {
937 par->InsertChar(pos, (*cit), font);
945 void Buffer::readInset(LyXLex & lex, LyXParagraph *& par,
946 int & pos, LyXFont & font)
949 if (lex.GetString() != "\\begin_inset") {
950 lyxerr << "Buffer::readInset: Consistency check failed."
955 string tmptok = lex.GetString();
956 last_inset_read = tmptok;
957 // test the different insets
958 if (tmptok == "Quotes") {
959 Inset * inset = new InsetQuotes;
960 inset->Read(this, lex);
961 par->InsertInset(pos, inset, font);
963 } else if (tmptok == "External") {
964 Inset * inset = new InsetExternal;
965 inset->Read(this, lex);
966 par->InsertInset(pos, inset, font);
968 } else if (tmptok == "FormulaMacro") {
969 Inset * inset = new InsetFormulaMacro;
970 inset->Read(this, lex);
971 par->InsertInset(pos, inset, font);
973 } else if (tmptok == "Formula") {
974 Inset * inset = new InsetFormula;
975 inset->Read(this, lex);
976 par->InsertInset(pos, inset, font);
978 } else if (tmptok == "Figure") {
979 Inset * inset = new InsetFig(100, 100, this);
980 inset->Read(this, lex);
981 par->InsertInset(pos, inset, font);
983 } else if (tmptok == "Info") {
984 Inset * inset = new InsetInfo;
985 inset->Read(this, lex);
986 par->InsertInset(pos, inset, font);
988 } else if (tmptok == "Include") {
989 InsetCommandParams p( "Include" );
990 Inset * inset = new InsetInclude(p, this);
991 inset->Read(this, lex);
992 par->InsertInset(pos, inset, font);
994 } else if (tmptok == "ERT") {
995 Inset * inset = new InsetERT;
996 inset->Read(this, lex);
997 par->InsertInset(pos, inset, font);
999 } else if (tmptok == "Tabular") {
1000 Inset * inset = new InsetTabular(this);
1001 inset->Read(this, lex);
1002 par->InsertInset(pos, inset, font);
1004 } else if (tmptok == "Text") {
1005 Inset * inset = new InsetText;
1006 inset->Read(this, lex);
1007 par->InsertInset(pos, inset, font);
1009 } else if (tmptok == "Foot") {
1010 Inset * inset = new InsetFoot;
1011 inset->Read(this, lex);
1012 par->InsertInset(pos, inset, font);
1014 } else if (tmptok == "Marginal") {
1015 Inset * inset = new InsetMarginal;
1016 inset->Read(this, lex);
1017 par->InsertInset(pos, inset, font);
1019 } else if (tmptok == "Minipage") {
1020 Inset * inset = new InsetMinipage;
1021 inset->Read(this, lex);
1022 par->InsertInset(pos, inset, font);
1024 } else if (tmptok == "Float") {
1026 string tmptok = lex.GetString();
1027 Inset * inset = new InsetFloat(tmptok);
1028 inset->Read(this, lex);
1029 par->InsertInset(pos, inset, font);
1031 } else if (tmptok == "List") {
1032 Inset * inset = new InsetList;
1033 inset->Read(this, lex);
1034 par->InsertInset(pos, inset, font);
1036 } else if (tmptok == "Theorem") {
1037 Inset * inset = new InsetList;
1038 inset->Read(this, lex);
1039 par->InsertInset(pos, inset, font);
1041 } else if (tmptok == "Caption") {
1042 Inset * inset = new InsetCaption;
1043 inset->Read(this, lex);
1044 par->InsertInset(pos, inset, font);
1046 } else if (tmptok == "GRAPHICS") {
1047 Inset * inset = new InsetGraphics;
1048 inset->Read(this, lex);
1049 par->InsertInset(pos, inset, font);
1051 } else if (tmptok == "LatexCommand") {
1052 InsetCommandParams inscmd;
1055 if (inscmd.getCmdName() == "cite") {
1056 inset = new InsetCitation(inscmd);
1057 } else if (inscmd.getCmdName() == "bibitem") {
1058 lex.printError("Wrong place for bibitem");
1059 inset = new InsetBibKey(inscmd);
1060 } else if (inscmd.getCmdName() == "BibTeX") {
1061 inset = new InsetBibtex(inscmd, this);
1062 } else if (inscmd.getCmdName() == "index") {
1063 inset = new InsetIndex(inscmd);
1064 } else if (inscmd.getCmdName() == "include") {
1065 inset = new InsetInclude(inscmd, this);
1066 } else if (inscmd.getCmdName() == "label") {
1067 inset = new InsetLabel(inscmd);
1068 } else if (inscmd.getCmdName() == "url"
1069 || inscmd.getCmdName() == "htmlurl") {
1070 inset = new InsetUrl(inscmd);
1071 } else if (inscmd.getCmdName() == "ref"
1072 || inscmd.getCmdName() == "pageref"
1073 || inscmd.getCmdName() == "vref"
1074 || inscmd.getCmdName() == "vpageref"
1075 || inscmd.getCmdName() == "prettyref") {
1076 if (!inscmd.getOptions().empty()
1077 || !inscmd.getContents().empty()) {
1078 inset = new InsetRef(inscmd);
1080 } else if (inscmd.getCmdName() == "tableofcontents"
1081 || inscmd.getCmdName() == "listofalgorithms"
1082 || inscmd.getCmdName() == "listoffigures"
1083 || inscmd.getCmdName() == "listoftables") {
1084 inset = new InsetTOC(inscmd);
1085 } else if (inscmd.getCmdName() == "printindex") {
1086 inset = new InsetPrintIndex(inscmd);
1087 } else if (inscmd.getCmdName() == "lyxparent") {
1088 inset = new InsetParent(inscmd, this);
1092 par->InsertInset(pos, inset, font);
1099 bool Buffer::readFile(LyXLex & lex, LyXParagraph * par)
1103 string token(lex.GetString());
1104 if (token == "\\lyxformat") { // the first token _must_ be...
1106 format = lex.GetFloat();
1108 if (LYX_FORMAT - format > 0.05) {
1110 printf(_("Warning: need lyxformat %.2f but found %.2f\n"),
1111 LYX_FORMAT, format);
1113 if (format - LYX_FORMAT > 0.05) {
1114 printf(_("ERROR: need lyxformat %.2f but found %.2f\n"),
1115 LYX_FORMAT, format);
1117 bool the_end = readLyXformat2(lex, par);
1118 // Formats >= 2.13 support "\the_end" marker
1125 WriteAlert(_("Warning!"),
1126 _("Reading of document is not complete"),
1127 _("Maybe the document is truncated"));
1128 // We simulate a safe reading anyways to allow
1129 // users to take the chance... (Asger)
1133 WriteAlert(_("ERROR!"),
1134 _("Old LyX file format found. "
1135 "Use LyX 0.10.x to read this!"));
1139 } else { // "\\lyxformat" not found
1140 WriteAlert(_("ERROR!"), _("Not a LyX file!"));
1143 WriteAlert(_("ERROR!"), _("Unable to read file!"));
1149 // Should probably be moved to somewhere else: BufferView? LyXView?
1150 bool Buffer::save() const
1152 // We don't need autosaves in the immediate future. (Asger)
1153 resetAutosaveTimers();
1157 if (lyxrc.make_backup) {
1158 s = fileName() + '~';
1159 if (!lyxrc.backupdir_path.empty())
1160 s = AddName(lyxrc.backupdir_path,
1161 subst(CleanupPath(s),'/','!'));
1163 // Rename is the wrong way of making a backup,
1164 // this is the correct way.
1165 /* truss cp fil fil2:
1166 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
1167 stat("LyXVC.lyx", 0xEFFFF688) = 0
1168 open("LyXVC.lyx", O_RDONLY) = 3
1169 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
1170 fstat(4, 0xEFFFF508) = 0
1171 fstat(3, 0xEFFFF508) = 0
1172 read(3, " # T h i s f i l e w".., 8192) = 5579
1173 write(4, " # T h i s f i l e w".., 5579) = 5579
1174 read(3, 0xEFFFD4A0, 8192) = 0
1177 chmod("LyXVC3.lyx", 0100644) = 0
1178 lseek(0, 0, SEEK_CUR) = 46440
1182 // Should proabaly have some more error checking here.
1183 // Should be cleaned up in 0.13, at least a bit.
1184 // Doing it this way, also makes the inodes stay the same.
1185 // This is still not a very good solution, in particular we
1186 // might loose the owner of the backup.
1187 FileInfo finfo(fileName());
1188 if (finfo.exist()) {
1189 mode_t fmode = finfo.getMode();
1190 struct utimbuf times = {
1191 finfo.getAccessTime(),
1192 finfo.getModificationTime() };
1194 ifstream ifs(fileName().c_str());
1195 ofstream ofs(s.c_str(), ios::out|ios::trunc);
1200 ::chmod(s.c_str(), fmode);
1202 if (::utime(s.c_str(), ×)) {
1203 lyxerr << "utime error." << endl;
1206 lyxerr << "LyX was not able to make "
1207 "backupcopy. Beware." << endl;
1212 if (writeFile(fileName(), false)) {
1214 removeAutosaveFile(fileName());
1216 // Saving failed, so backup is not backup
1217 if (lyxrc.make_backup) {
1218 ::rename(s.c_str(), fileName().c_str());
1226 // Returns false if unsuccesful
1227 bool Buffer::writeFile(string const & fname, bool flag) const
1229 // if flag is false writeFile will not create any GUI
1230 // warnings, only cerr.
1231 // Needed for autosave in background or panic save (Matthias 120496)
1233 if (read_only && (fname == filename)) {
1234 // Here we should come with a question if we should
1235 // perform the write anyway.
1237 lyxerr << _("Error! Document is read-only: ")
1240 WriteAlert(_("Error! Document is read-only: "),
1245 FileInfo finfo(fname);
1246 if (finfo.exist() && !finfo.writable()) {
1247 // Here we should come with a question if we should
1248 // try to do the save anyway. (i.e. do a chmod first)
1250 lyxerr << _("Error! Cannot write file: ")
1253 WriteFSAlert(_("Error! Cannot write file: "),
1258 ofstream ofs(fname.c_str());
1261 lyxerr << _("Error! Cannot open file: ")
1264 WriteFSAlert(_("Error! Cannot open file: "),
1270 // Use the standard "C" locale for file output.
1271 ofs.imbue(std::locale::classic());
1274 // The top of the file should not be written by params.
1276 // write out a comment in the top of the file
1277 ofs << '#' << LYX_DOCVERSION
1278 << " created this file. For more info see http://www.lyx.org/\n";
1279 ofs.setf(ios::showpoint|ios::fixed);
1282 char dummy_format[512];
1283 sprintf(dummy_format, "%.2f", LYX_FORMAT);
1284 ofs << "\\lyxformat " << dummy_format << "\n";
1286 ofs << "\\lyxformat " << setw(4) << LYX_FORMAT << "\n";
1288 // now write out the buffer paramters.
1289 params.writeFile(ofs);
1291 char footnoteflag = 0;
1294 // this will write out all the paragraphs
1295 // using recursive descent.
1296 paragraph->writeFile(this, ofs, params, footnoteflag, depth);
1298 // Write marker that shows file is complete
1299 ofs << "\n\\the_end" << endl;
1301 // how to check if close went ok?
1306 void Buffer::writeFileAscii(string const & fname, int linelen)
1308 LyXFont font1, font2;
1310 char c, footnoteflag = 0, depth = 0;
1312 LyXParagraph::size_type i;
1315 int ltype_depth = 0;
1324 int currlinelen = 0;
1326 bool ref_printed = false;
1328 ofstream ofs(fname.c_str());
1330 WriteFSAlert(_("Error: Cannot write file:"), fname);
1334 string fname1 = TmpFileName();
1335 LyXParagraph * par = paragraph;
1341 par->footnoteflag != LyXParagraph::NO_FOOTNOTE ||
1345 || par->previous->footnoteflag == LyXParagraph::NO_FOOTNOTE
1350 /* begins a footnote environment ? */
1351 if (footnoteflag != par->footnoteflag) {
1352 footnoteflag = par->footnoteflag;
1354 j = strlen(string_footnotekinds[par->footnotekind])+4;
1355 if (currlinelen + j > linelen)
1358 << string_footnotekinds[par->footnotekind] << "] ";
1364 /* begins or ends a deeper area ?*/
1365 if (depth != par->depth) {
1366 if (par->depth > depth) {
1367 while (par->depth > depth) {
1372 while (par->depth < depth) {
1378 /* First write the layout */
1379 tmp = textclasslist.NameOfLayout(params.textclass, par->layout);
1380 if (tmp == "Itemize") {
1382 ltype_depth = depth+1;
1383 } else if (tmp == "Enumerate") {
1385 ltype_depth = depth+1;
1386 } else if (strstr(tmp.c_str(), "ection")) {
1388 ltype_depth = depth+1;
1389 } else if (strstr(tmp.c_str(), "aragraph")) {
1391 ltype_depth = depth+1;
1392 } else if (tmp == "Description") {
1394 ltype_depth = depth+1;
1395 } else if (tmp == "Abstract") {
1398 } else if (tmp == "Bibliography") {
1406 /* maybe some vertical spaces */
1408 /* the labelwidthstring used in lists */
1412 /* some pagebreaks? */
1416 /* what about the alignment */
1419 /* dummy layout, that means a footnote ended */
1420 footnoteflag = LyXParagraph::NO_FOOTNOTE;
1424 lyxerr << "Should this ever happen?" << endl;
1428 //LyXLayout const & layout =
1429 // textclasslist.Style(params.textclass,
1430 // par->GetLayout()); // unused
1431 //bool free_spc = layout.free_spacing; //unused
1434 /* It might be a table */
1438 cells = par->table->columns;
1439 clen = new int [cells];
1440 memset(clen, 0, sizeof(int) * cells);
1442 for (i = 0, j = 0, h = 1; i < par->size(); ++i, ++h) {
1443 c = par->GetChar(i);
1444 if (c == LyXParagraph::META_INSET) {
1445 if ((inset = par->GetInset(i))) {
1446 //#ifdef HAVE_SSTREAM
1447 std::ostringstream ost;
1448 inset->Ascii(this, ost);
1449 h += ost.str().length();
1452 // inset->Ascii(this, ost);
1454 // char * tmp = ost.str();
1455 // string tstr(tmp);
1456 // h += tstr.length();
1460 } else if (c == LyXParagraph::META_NEWLINE) {
1464 j = (++j) % par->table->NumberOfCellsInRow(actcell);
1472 font1 = LyXFont(LyXFont::ALL_INHERIT, params.language_info);
1474 for (i = 0, actpos = 1; i < par->size(); ++i, ++actpos) {
1475 if (!i && !footnoteflag && !noparbreak){
1477 for(j = 0; j < depth; ++j)
1479 currlinelen = depth * 2;
1481 case 0: /* Standard */
1482 case 4: /* (Sub)Paragraph */
1483 case 5: /* Description */
1485 case 6: /* Abstract */
1486 ofs << "Abstract\n\n";
1488 case 7: /* Bibliography */
1490 ofs << "References\n\n";
1495 ofs << par->labelstring << " ";
1498 if (ltype_depth > depth) {
1499 for(j = ltype_depth - 1; j > depth; --j)
1501 currlinelen += (ltype_depth-depth)*2;
1505 for(j = 0; j < cells; ++j) {
1507 for(h = 0; h < (clen[j] + 1);
1512 for(j = 0; j < depth; ++j)
1514 currlinelen = depth * 2;
1515 if (ltype_depth > depth) {
1516 for(j = ltype_depth;
1519 currlinelen += (ltype_depth-depth)*2;
1525 font2 = par->GetFontSettings(params, i);
1526 if (font1.latex() != font2.latex()) {
1527 if (font2.latex() == LyXFont::OFF)
1534 c = par->GetChar(i);
1538 case LyXParagraph::META_INSET:
1539 if ((inset = par->GetInset(i))) {
1541 inset->Ascii(this, ofs);
1542 currlinelen += (ofs.tellp() - fpos);
1543 actpos += (ofs.tellp() - fpos) - 1;
1546 case LyXParagraph::META_NEWLINE:
1549 if (par->table->NumberOfCellsInRow(actcell) <= cell) {
1550 for(j = actpos; j < clen[cell - 1]; ++j)
1553 for(j = 0; j < depth; ++j)
1555 currlinelen = depth*2;
1556 if (ltype_depth > depth) {
1557 for(j = ltype_depth; j > depth; --j)
1559 currlinelen += (ltype_depth-depth) * 2;
1561 for(j = 0; j < cells; ++j) {
1563 for(h = 0; h < (clen[j] + 1); ++h)
1567 for(j = 0; j < depth; ++j)
1569 currlinelen = depth * 2;
1570 if (ltype_depth > depth) {
1571 for(j = ltype_depth;
1574 currlinelen += (ltype_depth-depth)*2;
1580 j < clen[cell - 1]; ++j)
1586 currlinelen = actpos = 0;
1590 for(j = 0; j < depth; ++j)
1592 currlinelen = depth * 2;
1593 if (ltype_depth > depth) {
1594 for(j = ltype_depth;
1597 currlinelen += (ltype_depth - depth) * 2;
1603 case LyXParagraph::META_HFILL:
1610 if (currlinelen > linelen - 10
1611 && c == ' ' && i + 2 < par->size()) {
1613 for(j = 0; j < depth; ++j)
1615 currlinelen = depth * 2;
1616 if (ltype_depth > depth) {
1617 for(j = ltype_depth;
1620 currlinelen += (ltype_depth-depth)*2;
1622 } else if (c != '\0')
1625 lyxerr.debug() << "writeAsciiFile: NULL char in structure." << endl;
1632 for(j = actpos; j < clen[cell - 1]; ++j)
1635 for(j = 0; j < depth; ++j)
1637 currlinelen = depth * 2;
1638 if (ltype_depth > depth) {
1639 for(j = ltype_depth; j > depth; --j)
1641 currlinelen += (ltype_depth - depth) * 2;
1643 for(j = 0; j < cells; ++j) {
1645 for(h = 0; h < (clen[j] + 1); ++h)
1659 void Buffer::makeLaTeXFile(string const & fname,
1660 string const & original_path,
1661 bool nice, bool only_body)
1663 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
1665 niceFile = nice; // this will be used by Insetincludes.
1667 tex_code_break_column = lyxrc.ascii_linelen;
1669 LyXTextClass const & tclass =
1670 textclasslist.TextClass(params.textclass);
1672 ofstream ofs(fname.c_str());
1674 WriteFSAlert(_("Error: Cannot open file: "), fname);
1678 // validate the buffer.
1679 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
1680 LaTeXFeatures features(params, tclass.numLayouts());
1682 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
1685 // The starting paragraph of the coming rows is the
1686 // first paragraph of the document. (Asger)
1687 texrow.start(paragraph, 0);
1689 if (!only_body && nice) {
1690 ofs << "%% " LYX_DOCVERSION " created this file. "
1691 "For more info, see http://www.lyx.org/.\n"
1692 "%% Do not edit unless you really know what "
1697 lyxerr.debug() << "lyx header finished" << endl;
1698 // There are a few differences between nice LaTeX and usual files:
1699 // usual is \batchmode and has a
1700 // special input@path to allow the including of figures
1701 // with either \input or \includegraphics (what figinsets do).
1702 // batchmode is not set if there is a tex_code_break_column.
1703 // In this case somebody is interested in the generated LaTeX,
1704 // so this is OK. input@path is set when the actual parameter
1705 // original_path is set. This is done for usual tex-file, but not
1706 // for nice-latex-file. (Matthias 250696)
1709 // code for usual, NOT nice-latex-file
1710 ofs << "\\batchmode\n"; // changed
1711 // from \nonstopmode
1714 if (!original_path.empty()) {
1715 ofs << "\\makeatletter\n"
1716 << "\\def\\input@path{{"
1717 << original_path << "/}}\n"
1718 << "\\makeatother\n";
1724 ofs << "\\documentclass";
1726 string options; // the document class options.
1728 if (tokenPos(tclass.opt_fontsize(),
1729 '|', params.fontsize) >= 0) {
1730 // only write if existing in list (and not default)
1731 options += params.fontsize;
1736 if (!params.use_geometry &&
1737 (params.paperpackage == BufferParams::PACKAGE_NONE)) {
1738 switch (params.papersize) {
1739 case BufferParams::PAPER_A4PAPER:
1740 options += "a4paper,";
1742 case BufferParams::PAPER_USLETTER:
1743 options += "letterpaper,";
1745 case BufferParams::PAPER_A5PAPER:
1746 options += "a5paper,";
1748 case BufferParams::PAPER_B5PAPER:
1749 options += "b5paper,";
1751 case BufferParams::PAPER_EXECUTIVEPAPER:
1752 options += "executivepaper,";
1754 case BufferParams::PAPER_LEGALPAPER:
1755 options += "legalpaper,";
1761 if (params.sides != tclass.sides()) {
1762 switch (params.sides) {
1763 case LyXTextClass::OneSide:
1764 options += "oneside,";
1766 case LyXTextClass::TwoSides:
1767 options += "twoside,";
1774 if (params.columns != tclass.columns()) {
1775 if (params.columns == 2)
1776 options += "twocolumn,";
1778 options += "onecolumn,";
1781 if (!params.use_geometry
1782 && params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1783 options += "landscape,";
1785 // language should be a parameter to \documentclass
1786 bool use_babel = false;
1787 if (params.language_info->lang() == "hebrew") // This seems necessary
1788 features.UsedLanguages.insert(default_language);
1789 if (params.language != "default" ||
1790 !features.UsedLanguages.empty() ) {
1792 for (LaTeXFeatures::LanguageList::const_iterator cit =
1793 features.UsedLanguages.begin();
1794 cit != features.UsedLanguages.end(); ++cit)
1795 options += (*cit)->lang() + ",";
1796 options += params.language_info->lang() + ',';
1799 // the user-defined options
1800 if (!params.options.empty()) {
1801 options += params.options + ',';
1804 if (!options.empty()){
1805 options = strip(options, ',');
1806 ofs << '[' << options << ']';
1810 << textclasslist.LatexnameOfClass(params.textclass)
1813 // end of \documentclass defs
1815 // font selection must be done before loading fontenc.sty
1816 if (params.fonts != "default") {
1817 ofs << "\\usepackage{" << params.fonts << "}\n";
1820 // this one is not per buffer
1821 if (lyxrc.fontenc != "default") {
1822 ofs << "\\usepackage[" << lyxrc.fontenc
1827 if (params.inputenc == "auto") {
1828 string doc_encoding =
1829 params.language_info->encoding()->LatexName();
1831 // Create a list with all the input encodings used
1833 set<string> encodings;
1834 for (LaTeXFeatures::LanguageList::const_iterator it =
1835 features.UsedLanguages.begin();
1836 it != features.UsedLanguages.end(); ++it)
1837 if ((*it)->encoding()->LatexName() != doc_encoding)
1838 encodings.insert((*it)->encoding()->LatexName());
1840 ofs << "\\usepackage[";
1841 for (set<string>::const_iterator it = encodings.begin();
1842 it != encodings.end(); ++it)
1844 ofs << doc_encoding << "]{inputenc}\n";
1846 } else if (params.inputenc != "default") {
1847 ofs << "\\usepackage[" << params.inputenc
1852 // At the very beginning the text parameters.
1853 if (params.paperpackage != BufferParams::PACKAGE_NONE) {
1854 switch (params.paperpackage) {
1855 case BufferParams::PACKAGE_A4:
1856 ofs << "\\usepackage{a4}\n";
1859 case BufferParams::PACKAGE_A4WIDE:
1860 ofs << "\\usepackage{a4wide}\n";
1863 case BufferParams::PACKAGE_WIDEMARGINSA4:
1864 ofs << "\\usepackage[widemargins]{a4}\n";
1869 if (params.use_geometry) {
1870 ofs << "\\usepackage{geometry}\n";
1872 ofs << "\\geometry{verbose";
1873 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1874 ofs << ",landscape";
1875 switch (params.papersize2) {
1876 case BufferParams::VM_PAPER_CUSTOM:
1877 if (!params.paperwidth.empty())
1878 ofs << ",paperwidth="
1879 << params.paperwidth;
1880 if (!params.paperheight.empty())
1881 ofs << ",paperheight="
1882 << params.paperheight;
1884 case BufferParams::VM_PAPER_USLETTER:
1885 ofs << ",letterpaper";
1887 case BufferParams::VM_PAPER_USLEGAL:
1888 ofs << ",legalpaper";
1890 case BufferParams::VM_PAPER_USEXECUTIVE:
1891 ofs << ",executivepaper";
1893 case BufferParams::VM_PAPER_A3:
1896 case BufferParams::VM_PAPER_A4:
1899 case BufferParams::VM_PAPER_A5:
1902 case BufferParams::VM_PAPER_B3:
1905 case BufferParams::VM_PAPER_B4:
1908 case BufferParams::VM_PAPER_B5:
1912 // default papersize ie BufferParams::VM_PAPER_DEFAULT
1913 switch (lyxrc.default_papersize) {
1914 case BufferParams::PAPER_DEFAULT: // keep compiler happy
1915 case BufferParams::PAPER_USLETTER:
1916 ofs << ",letterpaper";
1918 case BufferParams::PAPER_LEGALPAPER:
1919 ofs << ",legalpaper";
1921 case BufferParams::PAPER_EXECUTIVEPAPER:
1922 ofs << ",executivepaper";
1924 case BufferParams::PAPER_A3PAPER:
1927 case BufferParams::PAPER_A4PAPER:
1930 case BufferParams::PAPER_A5PAPER:
1933 case BufferParams::PAPER_B5PAPER:
1938 if (!params.topmargin.empty())
1939 ofs << ",tmargin=" << params.topmargin;
1940 if (!params.bottommargin.empty())
1941 ofs << ",bmargin=" << params.bottommargin;
1942 if (!params.leftmargin.empty())
1943 ofs << ",lmargin=" << params.leftmargin;
1944 if (!params.rightmargin.empty())
1945 ofs << ",rmargin=" << params.rightmargin;
1946 if (!params.headheight.empty())
1947 ofs << ",headheight=" << params.headheight;
1948 if (!params.headsep.empty())
1949 ofs << ",headsep=" << params.headsep;
1950 if (!params.footskip.empty())
1951 ofs << ",footskip=" << params.footskip;
1955 if (params.use_amsmath
1956 && !tclass.provides(LyXTextClass::amsmath)) {
1957 ofs << "\\usepackage{amsmath}\n";
1961 if (tokenPos(tclass.opt_pagestyle(),
1962 '|', params.pagestyle) >= 0) {
1963 if (params.pagestyle == "fancy") {
1964 ofs << "\\usepackage{fancyhdr}\n";
1967 ofs << "\\pagestyle{" << params.pagestyle << "}\n";
1971 // We try to load babel late, in case it interferes
1972 // with other packages.
1974 ofs << lyxrc.language_package << endl;
1978 if (params.secnumdepth != tclass.secnumdepth()) {
1979 ofs << "\\setcounter{secnumdepth}{"
1980 << params.secnumdepth
1984 if (params.tocdepth != tclass.tocdepth()) {
1985 ofs << "\\setcounter{tocdepth}{"
1991 if (params.paragraph_separation) {
1992 switch (params.defskip.kind()) {
1993 case VSpace::SMALLSKIP:
1994 ofs << "\\setlength\\parskip{\\smallskipamount}\n";
1996 case VSpace::MEDSKIP:
1997 ofs << "\\setlength\\parskip{\\medskipamount}\n";
1999 case VSpace::BIGSKIP:
2000 ofs << "\\setlength\\parskip{\\bigskipamount}\n";
2002 case VSpace::LENGTH:
2003 ofs << "\\setlength\\parskip{"
2004 << params.defskip.length().asLatexString()
2007 default: // should never happen // Then delete it.
2008 ofs << "\\setlength\\parskip{\\medskipamount}\n";
2013 ofs << "\\setlength\\parindent{0pt}\n";
2017 // Now insert the LyX specific LaTeX commands...
2019 // The optional packages;
2020 string preamble(features.getPackages());
2022 // this might be useful...
2023 preamble += "\n\\makeatletter\n";
2025 // Some macros LyX will need
2026 string tmppreamble(features.getMacros());
2028 if (!tmppreamble.empty()) {
2029 preamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2030 "LyX specific LaTeX commands.\n"
2031 + tmppreamble + '\n';
2034 // the text class specific preamble
2035 tmppreamble = features.getTClassPreamble();
2036 if (!tmppreamble.empty()) {
2037 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2038 "Textclass specific LaTeX commands.\n"
2039 + tmppreamble + '\n';
2042 /* the user-defined preamble */
2043 if (!params.preamble.empty()) {
2044 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2045 "User specified LaTeX commands.\n"
2046 + params.preamble + '\n';
2049 preamble += "\\makeatother\n";
2051 // Itemize bullet settings need to be last in case the user
2052 // defines their own bullets that use a package included
2053 // in the user-defined preamble -- ARRae
2054 // Actually it has to be done much later than that
2055 // since some packages like frenchb make modifications
2056 // at \begin{document} time -- JMarc
2058 for (int i = 0; i < 4; ++i) {
2059 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
2060 if (bullets_def.empty())
2061 bullets_def="\\AtBeginDocument{\n";
2062 bullets_def += " \\renewcommand{\\labelitemi";
2064 // `i' is one less than the item to modify
2071 bullets_def += "ii";
2077 bullets_def += "}{" +
2078 params.user_defined_bullets[i].getText()
2083 if (!bullets_def.empty())
2084 preamble += bullets_def + "}\n\n";
2086 for (int j = countChar(preamble, '\n'); j-- ;) {
2093 ofs << "\\begin{document}\n";
2096 lyxerr.debug() << "preamble finished, now the body." << endl;
2097 if (!lyxrc.language_auto_begin && params.language != "default") {
2098 ofs << subst(lyxrc.language_command_begin, "$$lang",
2104 latexParagraphs(ofs, paragraph, 0, texrow);
2106 // add this just in case after all the paragraphs
2110 if (!lyxrc.language_auto_end && params.language != "default") {
2111 ofs << subst(lyxrc.language_command_end, "$$lang",
2118 ofs << "\\end{document}\n";
2121 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
2123 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
2127 // Just to be sure. (Asger)
2130 // tex_code_break_column's value is used to decide
2131 // if we are in batchmode or not (within mathed_write()
2132 // in math_write.C) so we must set it to a non-zero
2133 // value when we leave otherwise we save incorrect .lyx files.
2134 tex_code_break_column = lyxrc.ascii_linelen;
2138 lyxerr << "File was not closed properly." << endl;
2141 lyxerr.debug() << "Finished making latex file." << endl;
2146 // LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
2148 void Buffer::latexParagraphs(ostream & ofs, LyXParagraph * par,
2149 LyXParagraph * endpar, TexRow & texrow) const
2151 bool was_title = false;
2152 bool already_title = false;
2153 //#ifdef HAVE_SSTREAM
2154 std::ostringstream ftnote;
2156 // char * tmpholder = 0;
2162 while (par != endpar) {
2163 //#ifndef HAVE_SSTREAM
2164 // ostrstream ftnote;
2166 // ftnote << tmpholder;
2167 // delete [] tmpholder;
2173 lyxerr[Debug::LATEX] << "Error in latexParagraphs."
2176 LyXLayout const & layout =
2177 textclasslist.Style(params.textclass,
2180 if (layout.intitle) {
2181 if (already_title) {
2182 lyxerr <<"Error in latexParagraphs: You"
2183 " should not mix title layouts"
2184 " with normal ones." << endl;
2187 } else if (was_title && !already_title) {
2188 ofs << "\\maketitle\n";
2190 already_title = true;
2193 // We are at depth 0 so we can just use
2194 // ordinary \footnote{} generation
2195 // flag this with ftcount
2197 if (layout.isEnvironment()
2198 || par->pextra_type != LyXParagraph::PEXTRA_NONE) {
2199 par = par->TeXEnvironment(this, params, ofs, texrow
2201 ,ftnote, ft_texrow, ftcount
2205 par = par->TeXOnePar(this, params, ofs, texrow, false
2208 ftnote, ft_texrow, ftcount
2213 // Write out what we've generated...
2216 ofs << "\\addtocounter{footnote}{-"
2220 ofs << ftnote.str();
2221 texrow += ft_texrow;
2222 //#ifdef HAVE_SSTREAM
2223 // The extra .c_str() is needed when we use
2224 // lyxstring instead of the STL string class.
2225 ftnote.str(string().c_str());
2227 // delete [] ftnote.str();
2232 //#ifndef HAVE_SSTREAM
2234 // // I hate strstreams
2235 // tmpholder = ftnote.str();
2239 //#ifndef HAVE_SSTREAM
2240 // delete [] tmpholder;
2242 // It might be that we only have a title in this document
2243 if (was_title && !already_title) {
2244 ofs << "\\maketitle\n";
2250 bool Buffer::isLatex() const
2252 return textclasslist.TextClass(params.textclass).outputType() == LATEX;
2256 bool Buffer::isLinuxDoc() const
2258 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC;
2262 bool Buffer::isLiterate() const
2264 return textclasslist.TextClass(params.textclass).outputType() == LITERATE;
2268 bool Buffer::isDocBook() const
2270 return textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2274 bool Buffer::isSGML() const
2276 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC ||
2277 textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2281 void Buffer::sgmlOpenTag(ostream & os, int depth,
2282 string const & latexname) const
2284 os << string(depth, ' ') << "<" << latexname << ">\n";
2288 void Buffer::sgmlCloseTag(ostream & os, int depth,
2289 string const & latexname) const
2291 os << string(depth, ' ') << "</" << latexname << ">\n";
2295 void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
2297 LyXParagraph * par = paragraph;
2299 niceFile = nice; // this will be used by Insetincludes.
2301 string top_element = textclasslist.LatexnameOfClass(params.textclass);
2302 string environment_stack[10];
2305 int depth = 0; // paragraph depth
2307 ofstream ofs(fname.c_str());
2310 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2314 LyXTextClass const & tclass =
2315 textclasslist.TextClass(params.textclass);
2317 LaTeXFeatures features(params, tclass.numLayouts());
2321 tex_code_break_column = lyxrc.ascii_linelen;
2323 //tex_code_break_column = 0;
2328 string sgml_includedfiles=features.getIncludedFiles();
2330 if (params.preamble.empty() && sgml_includedfiles.empty()) {
2331 ofs << "<!doctype linuxdoc system>\n\n";
2333 ofs << "<!doctype linuxdoc system [ "
2334 << params.preamble << sgml_includedfiles << " \n]>\n\n";
2337 if(params.options.empty())
2338 sgmlOpenTag(ofs, 0, top_element);
2340 string top = top_element;
2342 top += params.options;
2343 sgmlOpenTag(ofs, 0, top);
2347 ofs << "<!-- " << LYX_DOCVERSION
2348 << " created this file. For more info see http://www.lyx.org/"
2352 int desc_on = 0; // description mode
2353 LyXLayout const & style =
2354 textclasslist.Style(params.textclass,
2357 // treat <toc> as a special case for compatibility with old code
2358 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2359 Inset * inset = par->GetInset(0);
2360 Inset::Code lyx_code = inset->LyxCode();
2361 if (lyx_code == Inset::TOC_CODE){
2362 string temp = "toc";
2363 sgmlOpenTag(ofs, depth, temp);
2367 linuxDocHandleFootnote(ofs, par, depth);
2373 // environment tag closing
2374 for( ; depth > par->depth; --depth) {
2375 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2376 environment_stack[depth].erase();
2379 // write opening SGML tags
2380 switch(style.latextype) {
2381 case LATEX_PARAGRAPH:
2382 if(depth == par->depth
2383 && !environment_stack[depth].empty()) {
2384 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2385 environment_stack[depth].erase();
2391 sgmlOpenTag(ofs, depth, style.latexname());
2396 LinuxDocError(par, 0,
2397 _("Error : Wrong depth for"
2398 " LatexType Command.\n"));
2400 if (!environment_stack[depth].empty()){
2401 sgmlCloseTag(ofs, depth,
2402 environment_stack[depth]);
2406 environment_stack[depth].erase();
2407 sgmlOpenTag(ofs, depth, style.latexname());
2410 case LATEX_ENVIRONMENT:
2411 case LATEX_ITEM_ENVIRONMENT:
2412 if(depth == par->depth
2413 && environment_stack[depth] != style.latexname()
2414 && !environment_stack[depth].empty()) {
2416 sgmlCloseTag(ofs, depth,
2417 environment_stack[depth]);
2418 environment_stack[depth].erase();
2420 if (depth < par->depth) {
2422 environment_stack[depth].erase();
2424 if (environment_stack[depth] != style.latexname()) {
2427 sgmlOpenTag(ofs, depth, temp);
2429 environment_stack[depth] = style.latexname();
2430 sgmlOpenTag(ofs, depth,
2431 environment_stack[depth]);
2433 if(style.latextype == LATEX_ENVIRONMENT) break;
2435 desc_on = (style.labeltype == LABEL_MANUAL);
2442 sgmlOpenTag(ofs, depth + 1, item_name);
2445 sgmlOpenTag(ofs, depth, style.latexname());
2452 SimpleLinuxDocOnePar(ofs, par, desc_on, depth);
2456 linuxDocHandleFootnote(ofs, par, depth);
2458 while(par && par->IsDummy());
2462 // write closing SGML tags
2463 switch(style.latextype) {
2465 case LATEX_ENVIRONMENT:
2466 case LATEX_ITEM_ENVIRONMENT:
2469 sgmlCloseTag(ofs, depth, style.latexname());
2475 for(; depth > 0; --depth)
2476 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2478 if(!environment_stack[depth].empty())
2479 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2483 sgmlCloseTag(ofs, 0, top_element);
2487 // How to check for successful close
2492 void Buffer::linuxDocHandleFootnote(ostream & os, LyXParagraph * & par,
2495 string tag = "footnote";
2497 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2498 sgmlOpenTag(os, depth + 1, tag);
2499 SimpleLinuxDocOnePar(os, par, 0, depth + 1);
2500 sgmlCloseTag(os, depth + 1, tag);
2507 void Buffer::DocBookHandleCaption(ostream & os, string & inner_tag,
2508 int const depth, int desc_on,
2509 LyXParagraph * & par)
2511 LyXParagraph * tpar = par;
2514 && (tpar->footnoteflag != LyXParagraph::NO_FOOTNOTE)
2516 && (tpar->layout != textclasslist.NumberOfLayout(params.textclass,
2520 tpar->layout == textclasslist.NumberOfLayout(params.textclass,
2521 "Caption").second) {
2522 sgmlOpenTag(os, depth + 1, inner_tag);
2524 SimpleDocBookOnePar(os, extra_par, tpar,
2525 desc_on, depth + 2);
2526 sgmlCloseTag(os, depth+1, inner_tag);
2527 if(!extra_par.empty())
2534 void Buffer::DocBookHandleFootnote(ostream & os, LyXParagraph * & par,
2537 string tag, inner_tag;
2538 string tmp_par, extra_par;
2539 bool inner_span = false;
2542 // Someone should give this enum a proper name (Lgb)
2550 SOME_ENUM last = NO_ONE;
2551 SOME_ENUM present = FOOTNOTE_LIKE;
2553 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2554 if(last == present) {
2556 if(!tmp_par.empty()) {
2559 sgmlCloseTag(os, depth + 1, inner_tag);
2560 sgmlOpenTag(os, depth + 1, inner_tag);
2567 if(!inner_tag.empty()) sgmlCloseTag(os, depth + 1,
2569 if(!extra_par.empty()) os << extra_par;
2570 if(!tag.empty()) sgmlCloseTag(os, depth, tag);
2573 switch (par->footnotekind) {
2574 case LyXParagraph::FOOTNOTE:
2575 case LyXParagraph::ALGORITHM:
2578 present = FOOTNOTE_LIKE;
2581 case LyXParagraph::MARGIN:
2584 present = MARGIN_LIKE;
2587 case LyXParagraph::FIG:
2588 case LyXParagraph::WIDE_FIG:
2590 inner_tag = "title";
2594 case LyXParagraph::TAB:
2595 case LyXParagraph::WIDE_TAB:
2597 inner_tag = "title";
2602 sgmlOpenTag(os, depth, tag);
2603 if ((present == TAB_LIKE) || (present == FIG_LIKE)) {
2604 DocBookHandleCaption(os, inner_tag, depth,
2608 sgmlOpenTag(os, depth + 1, inner_tag);
2611 // ignore all caption here, we processed them above!!!
2612 if (par->layout != textclasslist
2613 .NumberOfLayout(params.textclass,
2614 "Caption").second) {
2615 //#ifdef HAVE_SSTREAM
2616 std::ostringstream ost;
2620 SimpleDocBookOnePar(ost, extra_par, par,
2621 desc_on, depth + 2);
2622 //#ifdef HAVE_SSTREAM
2623 tmp_par += ost.str().c_str();
2626 // char * ctmp = ost.str();
2631 tmp_par = frontStrip(strip(tmp_par));
2637 if(!inner_tag.empty()) sgmlCloseTag(os, depth + 1, inner_tag);
2638 if(!extra_par.empty()) os << extra_par;
2639 if(!tag.empty()) sgmlCloseTag(os, depth, tag);
2644 // push a tag in a style stack
2645 void Buffer::push_tag(ostream & os, string const & tag,
2646 int & pos, char stack[5][3])
2648 #warning Use a real stack! (Lgb)
2649 // pop all previous tags
2650 for (int j = pos; j >= 0; --j)
2651 os << "</" << stack[j] << ">";
2654 sprintf(stack[++pos], "%s", tag.c_str());
2657 for (int i = 0; i <= pos; ++i)
2658 os << "<" << stack[i] << ">";
2662 void Buffer::pop_tag(ostream & os, string const & tag,
2663 int & pos, char stack[5][3])
2665 #ifdef WITH_WARNINGS
2666 #warning Use a real stack! (Lgb)
2668 // Please, Lars, do not remove the global variable. I already
2669 // had to reintroduce it twice! (JMarc)
2672 // pop all tags till specified one
2673 for (j = pos; (j >= 0) && (strcmp(stack[j], tag.c_str())); --j)
2674 os << "</" << stack[j] << ">";
2677 os << "</" << tag << ">";
2679 // push all tags, but the specified one
2680 for (j = j + 1; j <= pos; ++j) {
2681 os << "<" << stack[j] << ">";
2682 strcpy(stack[j-1], stack[j]);
2688 // Handle internal paragraph parsing -- layout already processed.
2690 // checks, if newcol chars should be put into this line
2691 // writes newline, if necessary.
2693 void linux_doc_line_break(ostream & os, unsigned int & colcount,
2694 const unsigned int newcol)
2697 if (colcount > lyxrc.ascii_linelen) {
2699 colcount = newcol; // assume write after this call
2704 void Buffer::SimpleLinuxDocOnePar(ostream & os, LyXParagraph * par,
2705 int desc_on, int const /*depth*/)
2707 LyXFont font1, font2;
2710 LyXParagraph::size_type main_body;
2712 LyXLayout const & style = textclasslist.Style(params.textclass,
2715 char family_type = 0; // family font flag
2716 bool is_bold = false; // series font flag
2717 char shape_type = 0; // shape font flag
2718 bool is_em = false; // emphasis (italic) font flag
2720 int stack_num = -1; // style stack position
2721 // Can this be rewritten to use a std::stack, please. (Lgb)
2722 char stack[5][3]; // style stack
2723 unsigned int char_line_count = 5; // Heuristic choice ;-)
2725 if (style.labeltype != LABEL_MANUAL)
2728 main_body = par->BeginningOfMainBody();
2730 // gets paragraph main font
2732 font1 = style.labelfont;
2737 // parsing main loop
2738 for (LyXParagraph::size_type i = 0;
2739 i < par->size(); ++i) {
2751 font2 = par->getFont(params, i);
2753 if (font1.family() != font2.family()) {
2754 switch(family_type) {
2756 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2757 push_tag(os, "tt", stack_num, stack);
2760 else if (font2.family() == LyXFont::SANS_FAMILY) {
2761 push_tag(os, "sf", stack_num, stack);
2766 pop_tag(os, "tt", stack_num, stack);
2767 if (font2.family() == LyXFont::SANS_FAMILY) {
2768 push_tag(os, "sf", stack_num, stack);
2775 pop_tag(os, "sf", stack_num, stack);
2776 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2777 push_tag(os, "tt", stack_num, stack);
2786 if (font1.series() != font2.series()) {
2787 if (font2.series() == LyXFont::BOLD_SERIES) {
2788 push_tag(os, "bf", stack_num, stack);
2790 } else if (is_bold) {
2791 pop_tag(os, "bf", stack_num, stack);
2796 // handle italic and slanted fonts
2797 if (font1.shape() != font2.shape()) {
2798 switch(shape_type) {
2800 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2801 push_tag(os, "it", stack_num, stack);
2803 } else if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2804 push_tag(os, "sl", stack_num, stack);
2809 pop_tag(os, "it", stack_num, stack);
2810 if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2811 push_tag(os, "sl", stack_num, stack);
2818 pop_tag(os, "sl", stack_num, stack);
2819 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2820 push_tag(os, "it", stack_num, stack);
2828 if (font1.emph() != font2.emph()) {
2829 if (font2.emph() == LyXFont::ON) {
2830 push_tag(os, "em", stack_num, stack);
2833 pop_tag(os, "em", stack_num, stack);
2838 c = par->GetChar(i);
2840 if (c == LyXParagraph::META_INSET) {
2841 inset = par->GetInset(i);
2842 inset->Linuxdoc(this, os);
2845 if (font2.latex() == LyXFont::ON) {
2846 // "TeX"-Mode on == > SGML-Mode on.
2848 os << c; // see LaTeX-Generation...
2852 if (par->linuxDocConvertChar(c, sgml_string)
2853 && !style.free_spacing) { // in freespacing
2855 // non-breaking characters
2859 linux_doc_line_break(os, char_line_count, 6);
2863 linux_doc_line_break(os, char_line_count, 1);
2868 char_line_count += sgml_string.length();
2874 // needed if there is an optional argument but no contents
2875 if (main_body > 0 && main_body == par->size()) {
2879 // pop all defined Styles
2880 for (j = stack_num; j >= 0; --j) {
2881 linux_doc_line_break(os,
2883 3 + strlen(stack[j]));
2884 os << "</" << stack[j] << ">";
2887 // resets description flag correctly
2890 // <tag> not closed...
2891 linux_doc_line_break(os, char_line_count, 6);
2895 // fprintf(file, "</p>");
2901 // Print an error message.
2902 void Buffer::LinuxDocError(LyXParagraph * par, int pos,
2903 string const & message)
2905 // insert an error marker in text
2906 InsetError * new_inset = new InsetError(message);
2907 par->InsertInset(pos, new_inset);
2910 // This constant defines the maximum number of
2911 // environment layouts that can be nesteded.
2912 // The same applies for command layouts.
2913 // These values should be more than enough.
2914 // José Matos (1999/07/22)
2916 enum { MAX_NEST_LEVEL = 25};
2918 void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
2920 LyXParagraph * par = paragraph;
2922 niceFile = nice; // this will be used by Insetincludes.
2924 string top_element= textclasslist.LatexnameOfClass(params.textclass);
2925 // Please use a real stack.
2926 string environment_stack[MAX_NEST_LEVEL];
2927 string environment_inner[MAX_NEST_LEVEL];
2928 // Please use a real stack.
2929 string command_stack[MAX_NEST_LEVEL];
2930 bool command_flag= false;
2931 int command_depth= 0, command_base= 0, cmd_depth= 0;
2933 string item_name, command_name;
2934 string c_depth, c_params, tmps;
2936 int depth = 0; // paragraph depth
2937 LyXTextClass const & tclass =
2938 textclasslist.TextClass(params.textclass);
2940 LaTeXFeatures features(params, tclass.numLayouts());
2944 tex_code_break_column = lyxrc.ascii_linelen;
2946 //tex_code_break_column = 0;
2948 ofstream ofs(fname.c_str());
2950 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2957 string sgml_includedfiles=features.getIncludedFiles();
2959 ofs << "<!doctype " << top_element
2960 << " public \"-//OASIS//DTD DocBook V3.1//EN\"";
2962 if (params.preamble.empty() && sgml_includedfiles.empty())
2965 ofs << "\n [ " << params.preamble
2966 << sgml_includedfiles << " \n]>\n\n";
2968 if(params.options.empty())
2969 sgmlOpenTag(ofs, 0, top_element);
2971 string top = top_element;
2973 top += params.options;
2974 sgmlOpenTag(ofs, 0, top);
2978 ofs << "<!-- DocBook file was created by " << LYX_DOCVERSION
2979 << "\n See http://www.lyx.org/ for more information -->\n";
2982 int desc_on = 0; // description mode
2983 LyXLayout const & style =
2984 textclasslist.Style(params.textclass,
2987 // environment tag closing
2988 for( ; depth > par->depth; --depth) {
2989 if(environment_inner[depth] != "!-- --") {
2990 item_name= "listitem";
2991 sgmlCloseTag(ofs, command_depth + depth,
2993 if( environment_inner[depth] == "varlistentry")
2994 sgmlCloseTag(ofs, depth+command_depth,
2995 environment_inner[depth]);
2997 sgmlCloseTag(ofs, depth + command_depth,
2998 environment_stack[depth]);
2999 environment_stack[depth].erase();
3000 environment_inner[depth].erase();
3003 if(depth == par->depth
3004 && environment_stack[depth] != style.latexname()
3005 && !environment_stack[depth].empty()) {
3006 if(environment_inner[depth] != "!-- --") {
3007 item_name= "listitem";
3008 sgmlCloseTag(ofs, command_depth+depth,
3010 if( environment_inner[depth] == "varlistentry")
3012 depth + command_depth,
3013 environment_inner[depth]);
3016 sgmlCloseTag(ofs, depth + command_depth,
3017 environment_stack[depth]);
3019 environment_stack[depth].erase();
3020 environment_inner[depth].erase();
3023 // Write opening SGML tags.
3024 switch(style.latextype) {
3025 case LATEX_PARAGRAPH:
3026 if(style.latexname() != "dummy")
3027 sgmlOpenTag(ofs, depth+command_depth,
3033 LinuxDocError(par, 0,
3034 _("Error : Wrong depth for "
3035 "LatexType Command.\n"));
3037 command_name = style.latexname();
3039 tmps = style.latexparam();
3040 c_params = split(tmps, c_depth,'|');
3042 cmd_depth= atoi(c_depth.c_str());
3045 if(cmd_depth<command_base) {
3046 for(int j = command_depth;
3047 j >= command_base; --j)
3048 if(!command_stack[j].empty())
3049 sgmlCloseTag(ofs, j, command_stack[j]);
3050 command_depth= command_base= cmd_depth;
3051 } else if(cmd_depth <= command_depth) {
3052 for(int j = command_depth;
3053 j >= cmd_depth; --j)
3055 if(!command_stack[j].empty())
3056 sgmlCloseTag(ofs, j, command_stack[j]);
3057 command_depth= cmd_depth;
3059 command_depth= cmd_depth;
3061 command_depth = command_base = cmd_depth;
3062 command_flag = true;
3064 command_stack[command_depth]= command_name;
3066 // treat label as a special case for
3067 // more WYSIWYM handling.
3068 if (par->GetChar(0) == LyXParagraph::META_INSET) {
3069 Inset * inset = par->GetInset(0);
3070 Inset::Code lyx_code = inset->LyxCode();
3071 if (lyx_code == Inset::LABEL_CODE){
3072 command_name += " id=\"";
3073 command_name += (static_cast<InsetCommand *>(inset))->getContents();
3074 command_name += "\"";
3079 sgmlOpenTag(ofs, depth + command_depth, command_name);
3080 item_name = "title";
3081 sgmlOpenTag(ofs, depth + 1 + command_depth, item_name);
3084 case LATEX_ENVIRONMENT:
3085 case LATEX_ITEM_ENVIRONMENT:
3086 if (depth < par->depth) {
3088 environment_stack[depth].erase();
3091 if (environment_stack[depth] != style.latexname()) {
3092 environment_stack[depth] = style.latexname();
3093 environment_inner[depth] = "!-- --";
3094 sgmlOpenTag(ofs, depth + command_depth,
3095 environment_stack[depth]);
3097 if(environment_inner[depth] != "!-- --") {
3098 item_name= "listitem";
3100 command_depth + depth,
3102 if (environment_inner[depth] == "varlistentry")
3104 depth + command_depth,
3105 environment_inner[depth]);
3109 if(style.latextype == LATEX_ENVIRONMENT) {
3110 if(!style.latexparam().empty())
3111 sgmlOpenTag(ofs, depth + command_depth,
3112 style.latexparam());
3116 desc_on = (style.labeltype == LABEL_MANUAL);
3119 environment_inner[depth]= "varlistentry";
3121 environment_inner[depth]= "listitem";
3123 sgmlOpenTag(ofs, depth + 1 + command_depth,
3124 environment_inner[depth]);
3128 sgmlOpenTag(ofs, depth + 1 + command_depth,
3132 sgmlOpenTag(ofs, depth + 1 + command_depth,
3137 sgmlOpenTag(ofs, depth + command_depth,
3146 SimpleDocBookOnePar(ofs, extra_par, par, desc_on,
3147 depth + 1 + command_depth);
3150 DocBookHandleFootnote(ofs, par,
3151 depth + 1 + command_depth);
3153 while(par && par->IsDummy());
3156 // write closing SGML tags
3157 switch(style.latextype) {
3160 sgmlCloseTag(ofs, depth + command_depth, end_tag);
3162 case LATEX_ENVIRONMENT:
3163 if(!style.latexparam().empty())
3164 sgmlCloseTag(ofs, depth + command_depth,
3165 style.latexparam());
3167 case LATEX_ITEM_ENVIRONMENT:
3168 if(desc_on == 1) break;
3170 sgmlCloseTag(ofs, depth + 1 + command_depth, end_tag);
3172 case LATEX_PARAGRAPH:
3173 if(style.latexname() != "dummy")
3174 sgmlCloseTag(ofs, depth + command_depth,
3178 sgmlCloseTag(ofs, depth + command_depth,
3185 for(; depth >= 0; --depth) {
3186 if(!environment_stack[depth].empty()) {
3187 if(environment_inner[depth] != "!-- --") {
3188 item_name= "listitem";
3189 sgmlCloseTag(ofs, command_depth + depth,
3191 if( environment_inner[depth] == "varlistentry")
3192 sgmlCloseTag(ofs, depth + command_depth,
3193 environment_inner[depth]);
3196 sgmlCloseTag(ofs, depth + command_depth,
3197 environment_stack[depth]);
3201 for(int j = command_depth; j >= command_base; --j)
3202 if(!command_stack[j].empty())
3203 sgmlCloseTag(ofs, j, command_stack[j]);
3207 sgmlCloseTag(ofs, 0, top_element);
3211 // How to check for successful close
3215 void Buffer::SimpleDocBookOnePar(ostream & os, string & extra,
3216 LyXParagraph * par, int & desc_on,
3221 par->SimpleDocBookOneTablePar(this,
3222 os, extra, desc_on, depth);
3227 bool emph_flag = false;
3229 LyXLayout const & style = textclasslist.Style(params.textclass,
3232 LyXParagraph::size_type main_body;
3233 if (style.labeltype != LABEL_MANUAL)
3236 main_body = par->BeginningOfMainBody();
3238 // gets paragraph main font
3239 LyXFont font1 = main_body > 0 ? style.labelfont : style.font;
3241 int char_line_count = depth;
3242 if(!style.free_spacing)
3243 for (int j = 0; j < depth; ++j)
3246 // parsing main loop
3247 for (LyXParagraph::size_type i = 0;
3248 i < par->size(); ++i) {
3249 LyXFont font2 = par->getFont(params, i);
3251 // handle <emphasis> tag
3252 if (font1.emph() != font2.emph() && i) {
3253 if (font2.emph() == LyXFont::ON) {
3257 os << "</emphasis>";
3262 char c = par->GetChar(i);
3264 if (c == LyXParagraph::META_INSET) {
3265 Inset * inset = par->GetInset(i);
3266 //#ifdef HAVE_SSTREAM
3267 std::ostringstream ost;
3268 inset->DocBook(this, ost);
3269 string tmp_out = ost.str().c_str();
3272 // inset->DocBook(this, ost);
3274 // char * ctmp = ost.str();
3275 // string tmp_out(ctmp);
3279 // This code needs some explanation:
3280 // Two insets are treated specially
3281 // label if it is the first element in a command paragraph
3283 // graphics inside tables or figure floats can't go on
3284 // title (the equivalente in latex for this case is caption
3285 // and title should come first
3288 if(desc_on!= 3 || i!= 0) {
3289 if(!tmp_out.empty() && tmp_out[0] == '@') {
3291 extra += frontStrip(tmp_out, '@');
3293 os << frontStrip(tmp_out, '@');
3298 } else if (font2.latex() == LyXFont::ON) {
3299 // "TeX"-Mode on ==> SGML-Mode on.
3305 if (par->linuxDocConvertChar(c, sgml_string)
3306 && !style.free_spacing) { // in freespacing
3308 // non-breaking characters
3312 os << "\n</term><listitem><para>";
3324 // needed if there is an optional argument but no contents
3325 if (main_body > 0 && main_body == par->size()) {
3329 os << "</emphasis>";
3332 // resets description flag correctly
3335 // <term> not closed...
3343 int Buffer::runLaTeX()
3347 if (!users->text) return 0;
3349 ProhibitInput(users);
3351 // get LaTeX-Filename
3352 string name = getLatexName();
3354 string path = OnlyPath(filename);
3356 string org_path = path;
3357 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3361 Path p(path); // path to LaTeX file
3362 users->owner()->getMiniBuffer()->Set(_("Running LaTeX..."));
3364 // Remove all error insets
3365 bool a = users->removeAutoInsets();
3367 // Always generate the LaTeX file
3368 makeLaTeXFile(name, org_path, false);
3370 // do the LaTex run(s)
3372 string latex_command = lyxrc.pdf_mode ?
3373 lyxrc.pdflatex_command : lyxrc.latex_command;
3374 LaTeX latex(latex_command, name, filepath);
3375 int res = latex.run(terr,
3376 users->owner()->getMiniBuffer()); // running latex
3378 // check return value from latex.run().
3379 if ((res & LaTeX::NO_LOGFILE)) {
3380 WriteAlert(_("LaTeX did not work!"),
3381 _("Missing log file:"), name);
3382 } else if ((res & LaTeX::ERRORS)) {
3383 users->owner()->getMiniBuffer()->Set(_("Done"));
3384 // Insert all errors as errors boxes
3385 users->insertErrors(terr);
3387 // Dvi should also be kept dirty if the latex run
3388 // ends up with errors. However it should be possible
3389 // to view a dirty dvi too.
3391 //no errors or any other things to think about so:
3392 users->owner()->getMiniBuffer()->Set(_("Done"));
3395 // if we removed error insets before we ran LaTeX or if we inserted
3396 // error insets after we ran LaTeX this must be run:
3397 if (a || (res & LaTeX::ERRORS)){
3400 //users->updateScrollbar();
3404 return latex.getNumErrors();
3411 int Buffer::runLiterate()
3413 if (!users->text) return 0;
3415 ProhibitInput(users);
3417 // get LaTeX-Filename
3418 string name = getLatexName();
3419 // get Literate-Filename
3420 string lit_name = OnlyFilename(ChangeExtension (getLatexName(),
3421 lyxrc.literate_extension));
3423 string path = OnlyPath(filename);
3425 string org_path = path;
3426 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3430 Path p(path); // path to Literate file
3431 users->owner()->getMiniBuffer()->Set(_("Running Literate..."));
3433 // Remove all error insets
3434 bool removedErrorInsets = users->removeAutoInsets();
3436 // generate the Literate file if necessary
3437 makeLaTeXFile(lit_name, org_path, false);
3439 string latex_command = lyxrc.pdf_mode ?
3440 lyxrc.pdflatex_command : lyxrc.latex_command;
3441 Literate literate(latex_command, name, filepath,
3443 lyxrc.literate_command, lyxrc.literate_error_filter,
3444 lyxrc.build_command, lyxrc.build_error_filter);
3446 int res = literate.weave(terr, users->owner()->getMiniBuffer());
3448 // check return value from literate.weave().
3449 if ((res & Literate::NO_LOGFILE)) {
3450 WriteAlert(_("Literate command did not work!"),
3451 _("Missing log file:"), name);
3452 } else if ((res & Literate::ERRORS)) {
3453 users->owner()->getMiniBuffer()->Set(_("Done"));
3454 // Insert all errors as errors boxes
3455 users->insertErrors(terr);
3457 // Dvi should also be kept dirty if the latex run
3458 // ends up with errors. However it should be possible
3459 // to view a dirty dvi too.
3461 //no errors or any other things to think about so:
3462 users->owner()->getMiniBuffer()->Set(_("Done"));
3465 // if we removed error insets before we ran LaTeX or if we inserted
3466 // error insets after we ran LaTeX this must be run:
3467 if (removedErrorInsets || (res & Literate::ERRORS)){
3470 //users->updateScrollbar();
3474 return literate.getNumErrors();
3478 int Buffer::buildProgram()
3480 if (!users->text) return 0;
3482 ProhibitInput(users);
3484 // get LaTeX-Filename
3485 string name = getLatexName();
3486 // get Literate-Filename
3487 string lit_name = OnlyFilename(ChangeExtension(getLatexName(),
3488 lyxrc.literate_extension));
3490 string path = OnlyPath(filename);
3492 string org_path = path;
3493 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3497 Path p(path); // path to Literate file
3498 users->owner()->getMiniBuffer()->Set(_("Building Program..."));
3500 // Remove all error insets
3501 bool removedErrorInsets = users->removeAutoInsets();
3503 // generate the LaTeX file if necessary
3504 if (!isNwClean() || removedErrorInsets) {
3505 makeLaTeXFile(lit_name, org_path, false);
3509 string latex_command = lyxrc.pdf_mode ?
3510 lyxrc.pdflatex_command : lyxrc.latex_command;
3511 Literate literate(latex_command, name, filepath,
3513 lyxrc.literate_command, lyxrc.literate_error_filter,
3514 lyxrc.build_command, lyxrc.build_error_filter);
3516 int res = literate.build(terr, users->owner()->getMiniBuffer());
3518 // check return value from literate.build().
3519 if ((res & Literate::NO_LOGFILE)) {
3520 WriteAlert(_("Build did not work!"),
3521 _("Missing log file:"), name);
3522 } else if ((res & Literate::ERRORS)) {
3523 users->owner()->getMiniBuffer()->Set(_("Done"));
3524 // Insert all errors as errors boxes
3525 users->insertErrors(terr);
3527 // Literate files should also be kept dirty if the literate
3528 // command run ends up with errors.
3530 //no errors or any other things to think about so:
3531 users->owner()->getMiniBuffer()->Set(_("Done"));
3535 // if we removed error insets before we ran Literate/Build or
3536 // if we inserted error insets after we ran Literate/Build this
3538 if (removedErrorInsets || (res & Literate::ERRORS)){
3541 //users->updateScrollbar();
3545 return literate.getNumErrors();
3549 // This should be enabled when the Chktex class is implemented. (Asger)
3550 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
3551 // Other flags: -wall -v0 -x
3552 int Buffer::runChktex()
3554 if (!users->text) return 0;
3556 ProhibitInput(users);
3558 // get LaTeX-Filename
3559 string name = getLatexName();
3560 string path = OnlyPath(filename);
3562 string org_path = path;
3563 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3567 Path p(path); // path to LaTeX file
3568 users->owner()->getMiniBuffer()->Set(_("Running chktex..."));
3570 // Remove all error insets
3571 bool removedErrorInsets = users->removeAutoInsets();
3573 // Generate the LaTeX file if neccessary
3574 makeLaTeXFile(name, org_path, false);
3577 Chktex chktex(lyxrc.chktex_command, name, filepath);
3578 int res = chktex.run(terr); // run chktex
3581 WriteAlert(_("chktex did not work!"),
3582 _("Could not run with file:"), name);
3583 } else if (res > 0) {
3584 // Insert all errors as errors boxes
3585 users->insertErrors(terr);
3588 // if we removed error insets before we ran chktex or if we inserted
3589 // error insets after we ran chktex, this must be run:
3590 if (removedErrorInsets || res){
3593 //users->updateScrollbar();
3601 void Buffer::validate(LaTeXFeatures & features) const
3603 LyXParagraph * par = paragraph;
3604 LyXTextClass const & tclass =
3605 textclasslist.TextClass(params.textclass);
3607 // AMS Style is at document level
3609 features.amsstyle = (params.use_amsmath ||
3610 tclass.provides(LyXTextClass::amsmath));
3613 // We don't use "lyxerr.debug" because of speed. (Asger)
3614 if (lyxerr.debugging(Debug::LATEX))
3615 lyxerr << "Paragraph: " << par << endl;
3617 // Now just follow the list of paragraphs and run
3618 // validate on each of them.
3619 par->validate(features);
3621 // and then the next paragraph
3625 // the bullet shapes are buffer level not paragraph level
3626 // so they are tested here
3627 for (int i = 0; i < 4; ++i) {
3628 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
3629 int font = params.user_defined_bullets[i].getFont();
3632 .user_defined_bullets[i]
3639 features.latexsym = true;
3643 features.amssymb = true;
3645 else if ((font >= 2 && font <= 5)) {
3646 features.pifont = true;
3651 if (lyxerr.debugging(Debug::LATEX)) {
3652 features.showStruct();
3657 void Buffer::setPaperStuff()
3659 params.papersize = BufferParams::PAPER_DEFAULT;
3660 char c1 = params.paperpackage;
3661 if (c1 == BufferParams::PACKAGE_NONE) {
3662 char c2 = params.papersize2;
3663 if (c2 == BufferParams::VM_PAPER_USLETTER)
3664 params.papersize = BufferParams::PAPER_USLETTER;
3665 else if (c2 == BufferParams::VM_PAPER_USLEGAL)
3666 params.papersize = BufferParams::PAPER_LEGALPAPER;
3667 else if (c2 == BufferParams::VM_PAPER_USEXECUTIVE)
3668 params.papersize = BufferParams::PAPER_EXECUTIVEPAPER;
3669 else if (c2 == BufferParams::VM_PAPER_A3)
3670 params.papersize = BufferParams::PAPER_A3PAPER;
3671 else if (c2 == BufferParams::VM_PAPER_A4)
3672 params.papersize = BufferParams::PAPER_A4PAPER;
3673 else if (c2 == BufferParams::VM_PAPER_A5)
3674 params.papersize = BufferParams::PAPER_A5PAPER;
3675 else if ((c2 == BufferParams::VM_PAPER_B3) || (c2 == BufferParams::VM_PAPER_B4) ||
3676 (c2 == BufferParams::VM_PAPER_B5))
3677 params.papersize = BufferParams::PAPER_B5PAPER;
3678 } else if ((c1 == BufferParams::PACKAGE_A4) || (c1 == BufferParams::PACKAGE_A4WIDE) ||
3679 (c1 == BufferParams::PACKAGE_WIDEMARGINSA4))
3680 params.papersize = BufferParams::PAPER_A4PAPER;
3684 // This function should be in Buffer because it's a buffer's property (ale)
3685 string const Buffer::getIncludeonlyList(char delim)
3688 for (inset_iterator it = inset_iterator_begin();
3689 it != inset_iterator_end(); ++it) {
3690 if ((*it)->LyxCode() == Inset::INCLUDE_CODE) {
3691 InsetInclude * insetinc =
3692 static_cast<InsetInclude *>(*it);
3693 if (insetinc->isInclude()
3694 && insetinc->isNoLoad()) {
3697 lst += OnlyFilename(ChangeExtension(insetinc->getContents(), string()));
3701 lyxerr.debug() << "Includeonly(" << lst << ')' << endl;
3706 vector<string> const Buffer::getLabelList()
3708 /// if this is a child document and the parent is already loaded
3709 /// Use the parent's list instead [ale990407]
3710 if (!params.parentname.empty()
3711 && bufferlist.exists(params.parentname)) {
3712 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3714 return tmp->getLabelList();
3717 vector<string> label_list;
3718 for (inset_iterator it = inset_iterator_begin();
3719 it != inset_iterator_end(); ++it) {
3720 vector<string> l = (*it)->getLabelList();
3721 label_list.insert(label_list.end(), l.begin(), l.end());
3727 vector<vector<Buffer::TocItem> > const Buffer::getTocList()
3729 vector<vector<TocItem> > l(4);
3730 LyXParagraph * par = paragraph;
3733 if (par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
3734 if (textclasslist.Style(params.textclass,
3735 par->GetLayout()).labeltype
3736 == LABEL_SENSITIVE) {
3740 tmp.str = par->String(this, false);
3741 switch (par->footnotekind) {
3742 case LyXParagraph::FIG:
3743 case LyXParagraph::WIDE_FIG:
3744 l[TOC_LOF].push_back(tmp);
3746 case LyXParagraph::TAB:
3747 case LyXParagraph::WIDE_TAB:
3748 l[TOC_LOT].push_back(tmp);
3750 case LyXParagraph::ALGORITHM:
3751 l[TOC_LOA].push_back(tmp);
3753 case LyXParagraph::FOOTNOTE:
3754 case LyXParagraph::MARGIN:
3758 } else if (!par->IsDummy()) {
3760 char labeltype = textclasslist.Style(params.textclass,
3761 par->GetLayout()).labeltype;
3763 if (labeltype >= LABEL_COUNTER_CHAPTER
3764 && labeltype <= LABEL_COUNTER_CHAPTER + params.tocdepth) {
3765 // insert this into the table of contents
3770 textclasslist.TextClass(params.textclass).maxcounter());
3771 tmp.str = par->String(this, true);
3772 l[TOC_TOC].push_back(tmp);
3783 // This is also a buffer property (ale)
3784 vector<pair<string,string> > const Buffer::getBibkeyList()
3786 /// if this is a child document and the parent is already loaded
3787 /// Use the parent's list instead [ale990412]
3788 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3789 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3791 return tmp->getBibkeyList();
3794 vector<pair<string, string> > keys;
3795 LyXParagraph * par = paragraph;
3798 keys.push_back(pair<string, string>(par->bibkey->getContents(),
3799 par->String(this, false)));
3803 // Might be either using bibtex or a child has bibliography
3805 for (inset_iterator it = inset_iterator_begin();
3806 it != inset_iterator_end(); ++it) {
3807 // Search for Bibtex or Include inset
3808 if ((*it)->LyxCode() == Inset::BIBTEX_CODE) {
3809 vector<pair<string,string> > tmp =
3810 static_cast<InsetBibtex*>(*it)->getKeys();
3811 keys.insert(keys.end(), tmp.begin(), tmp.end());
3812 } else if ((*it)->LyxCode() == Inset::INCLUDE_CODE) {
3813 vector<pair<string,string> > tmp =
3814 static_cast<InsetInclude*>(*it)->getKeys();
3815 keys.insert(keys.end(), tmp.begin(), tmp.end());
3824 bool Buffer::isDepClean(string const & name) const
3826 DEPCLEAN * item = dep_clean;
3827 while (item && item->master != name)
3829 if (!item) return true;
3834 void Buffer::markDepClean(string const & name)
3837 dep_clean = new DEPCLEAN;
3838 dep_clean->clean = true;
3839 dep_clean->master = name;
3840 dep_clean->next = 0;
3842 DEPCLEAN* item = dep_clean;
3843 while (item && item->master != name)
3848 item = new DEPCLEAN;
3850 item->master = name;
3857 bool Buffer::Dispatch(string const & command)
3859 // Split command string into command and argument
3860 string cmd, line = frontStrip(command);
3861 string arg = strip(frontStrip(split(line, cmd, ' ')));
3863 return Dispatch(lyxaction.LookupFunc(cmd.c_str()), arg.c_str());
3867 bool Buffer::Dispatch(int action, string const & argument)
3869 bool dispatched = true;
3873 Exporter::Export(this, argument, false);
3875 MenuExport(this, argument);
3886 void Buffer::resize()
3888 /// resize the BufferViews!
3894 void Buffer::resizeInsets(BufferView * bv)
3896 /// then remove all LyXText in text-insets
3897 LyXParagraph * par = paragraph;
3898 for(;par;par = par->next) {
3899 par->resizeInsetsLyXText(bv);
3903 void Buffer::ChangeLanguage(Language const * from, Language const * to)
3906 LyXParagraph * par = paragraph;
3908 par->ChangeLanguage(params, from, to);
3914 bool Buffer::isMultiLingual()
3917 LyXParagraph * par = paragraph;
3919 if (par->isMultiLingual(params))
3927 Buffer::inset_iterator::inset_iterator(LyXParagraph * paragraph,
3928 LyXParagraph::size_type pos)
3930 it = par->InsetIterator(pos);
3931 if (it == par->inset_iterator_end()) {
3938 void Buffer::inset_iterator::SetParagraph() {
3940 it = par->inset_iterator_begin();
3941 if (it != par->inset_iterator_end())
3946 // We maintain an invariant that whenever par = 0 then it = 0