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>
28 #pragma implementation "buffer.h"
32 #include "bufferlist.h"
34 #include "lyx_gui_misc.h"
35 #include "LyXAction.h"
38 #include "tex-strings.h"
40 #include "bufferview_funcs.h"
41 #include "minibuffer.h"
44 #include "mathed/formulamacro.h"
45 #include "insets/lyxinset.h"
46 #include "insets/inseterror.h"
47 #include "insets/insetlabel.h"
48 #include "insets/insetref.h"
49 #include "insets/inseturl.h"
50 #include "insets/insetinfo.h"
51 #include "insets/insetquotes.h"
52 #include "insets/insetlatexaccent.h"
53 #include "insets/insetbib.h"
54 #include "insets/insetcite.h"
55 #include "insets/insetexternal.h"
56 #include "insets/insetindex.h"
57 #include "insets/insetinclude.h"
58 #include "insets/insettoc.h"
59 #include "insets/insetparent.h"
60 #include "insets/insetspecialchar.h"
61 #include "insets/figinset.h"
62 #include "insets/insettext.h"
63 #include "insets/insetert.h"
64 #include "insets/insetgraphics.h"
65 #include "insets/insetfoot.h"
66 #include "insets/insetmarginal.h"
67 #include "insets/insetminipage.h"
68 #include "insets/insetfloat.h"
69 #include "insets/insetlist.h"
70 #include "insets/insettabular.h"
71 #include "insets/insettheorem.h"
72 #include "insets/insetcaption.h"
73 #include "support/filetools.h"
74 #include "support/path.h"
80 #include "LaTeXFeatures.h"
81 #include "support/syscall.h"
82 #include "support/lyxlib.h"
83 #include "support/FileInfo.h"
87 #include "lyx_gui_misc.h" // WarnReadonly()
88 #include "frontends/Dialogs.h"
103 using std::istringstream;
106 // all these externs should eventually be removed.
107 extern BufferList bufferlist;
109 extern void MenuExport(Buffer *, string const &);
110 extern LyXAction lyxaction;
113 static const float LYX_FORMAT = 2.17;
115 extern int tex_code_break_column;
118 Buffer::Buffer(string const & file, bool ronly)
120 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
122 filepath = OnlyPath(file);
131 if (read_only || (lyxrc.use_tempdir)) {
132 tmppath = CreateBufferTmpDir();
133 } else tmppath.erase();
139 lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
140 // here the buffer should take care that it is
141 // saved properly, before it goes into the void.
143 // make sure that views using this buffer
148 if (!tmppath.empty()) {
149 DestroyBufferTmpDir(tmppath);
152 LyXParagraph * par = paragraph;
153 LyXParagraph * tmppar;
163 string Buffer::getLatexName(bool no_path) const
166 return OnlyFilename(ChangeExtension(MakeLatexName(filename),
169 return ChangeExtension(MakeLatexName(filename),
174 void Buffer::setReadonly(bool flag)
176 if (read_only != flag) {
179 users->owner()->getDialogs()->updateBufferDependent();
182 WarnReadonly(filename);
187 bool Buffer::saveParamsAsDefaults()
189 string fname = AddName(AddPath(user_lyxdir, "templates/"),
191 Buffer defaults = Buffer(fname);
193 // Use the current buffer's parameters as default
194 defaults.params = params;
196 // add an empty paragraph. Is this enough?
197 defaults.paragraph = new LyXParagraph;
199 return defaults.writeFile(defaults.filename, false);
203 /// Update window titles of all users
204 // Should work on a list
205 void Buffer::updateTitles() const
207 if (users) users->owner()->updateWindowTitle();
211 /// Reset autosave timer of all users
212 // Should work on a list
213 void Buffer::resetAutosaveTimers() const
215 if (users) users->owner()->resetAutosaveTimer();
219 void Buffer::fileName(string const & newfile)
221 filename = MakeAbsPath(newfile);
222 filepath = OnlyPath(filename);
223 setReadonly(IsFileWriteable(filename) == 0);
228 // candidate for move to BufferView
229 // (at least some parts in the beginning of the func)
232 // changed to be public and have one parameter
233 // if par = 0 normal behavior
234 // else insert behavior
235 // Returns false if "\the_end" is not read for formats >= 2.13. (Asger)
236 bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par)
240 char depth = 0; // signed or unsigned?
242 LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
243 LyXParagraph::footnote_kind footnotekind = LyXParagraph::FOOTNOTE;
245 bool the_end_read = false;
247 LyXParagraph * return_par = 0;
248 LyXFont font(LyXFont::ALL_INHERIT, params.language_info);
249 if (format < 2.16 && params.language == "hebrew")
250 font.setLanguage(default_language);
252 // If we are inserting, we cheat and get a token in advance
253 bool has_token = false;
257 par = new LyXParagraph;
259 users->text->BreakParagraph(users);
260 return_par = users->text->FirstParagraph();
263 // We don't want to adopt the parameters from the
264 // document we insert, so we skip until the text begins:
267 pretoken = lex.GetString();
268 if (pretoken == "\\layout") {
280 pretoken = lex.GetString();
283 // Profiling show this should give a lot: (Asger)
284 string const token = pretoken;
288 the_end_read = parseSingleLyXformat2Token(lex, par, return_par,
301 paragraph = return_par;
307 // We'll remove this later. (Lgb)
308 static string last_inset_read;
312 Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
313 LyXParagraph *& return_par,
314 string const & token, int & pos,
315 char & depth, LyXFont & font
317 , LyXParagraph::footnote_flag & footnoteflag,
318 LyXParagraph::footnote_kind & footnotekind
322 bool the_end_read = false;
324 if (token[0] != '\\') {
325 for (string::const_iterator cit = token.begin();
326 cit != token.end(); ++cit) {
327 par->InsertChar(pos, (*cit), font);
330 } else if (token == "\\i") {
331 Inset * inset = new InsetLatexAccent;
332 inset->Read(this, lex);
333 par->InsertInset(pos, inset, font);
335 } else if (token == "\\layout") {
340 par = new LyXParagraph(par);
344 string layoutname = lex.GetString();
345 pair<bool, LyXTextClass::LayoutList::size_type> pp
346 = textclasslist.NumberOfLayout(params.textclass,
349 par->layout = pp.second;
350 } else { // layout not found
351 // use default layout "Standard" (0)
354 // Test whether the layout is obsolete.
355 LyXLayout const & layout =
356 textclasslist.Style(params.textclass,
358 if (!layout.obsoleted_by().empty())
360 textclasslist.NumberOfLayout(params.textclass,
361 layout.obsoleted_by()).second;
363 par->footnoteflag = footnoteflag;
364 par->footnotekind = footnotekind;
367 font = LyXFont(LyXFont::ALL_INHERIT, params.language_info);
368 if (format < 2.16 && params.language == "hebrew")
369 font.setLanguage(default_language);
371 } else if (token == "\\end_float") {
376 par = new LyXParagraph(par);
378 footnotekind = LyXParagraph::FOOTNOTE;
379 footnoteflag = LyXParagraph::NO_FOOTNOTE;
382 par->layout = LYX_DUMMY_LAYOUT;
383 font = LyXFont(LyXFont::ALL_INHERIT, params.language_info);
384 if (format < 2.16 && params.language == "hebrew")
385 font.setLanguage(default_language);
386 } else if (token == "\\begin_float") {
387 int tmpret = lex.FindToken(string_footnotekinds);
388 if (tmpret == -1) ++tmpret;
389 if (tmpret != LYX_LAYOUT_DEFAULT)
390 footnotekind = static_cast<LyXParagraph::footnote_kind>(tmpret); // bad
391 if (footnotekind == LyXParagraph::FOOTNOTE
392 || footnotekind == LyXParagraph::MARGIN)
393 footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
395 footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
397 } else if (token == "\\begin_float") {
398 // This is the compability reader, unfinished but tested.
401 string tmptok = lex.GetString();
402 //lyxerr << "old float: " << tmptok << endl;
407 if (tmptok == "footnote") {
408 inset = new InsetFoot;
409 } else if (tmptok == "margin") {
410 inset = new InsetMarginal;
411 } else if (tmptok == "fig") {
412 inset = new InsetFloat("figure");
413 old_float += "placement htbp\n";
414 } else if (tmptok == "tab") {
415 inset = new InsetFloat("table");
416 old_float += "placement htbp\n";
417 } else if (tmptok == "alg") {
418 inset = new InsetFloat("algorithm");
419 old_float += "placement htbp\n";
420 } else if (tmptok == "wide-fig") {
421 InsetFloat * tmp = new InsetFloat("figure");
424 old_float += "placement htbp\n";
425 } else if (tmptok == "wide-tab") {
426 InsetFloat * tmp = new InsetFloat("table");
429 old_float += "placement htbp\n";
432 if (!inset) return false; // no end read yet
434 old_float += "collapsed true\n";
436 // Here we need to check for \end_deeper and handle that
437 // before we do the footnote parsing.
438 // This _is_ a hack! (Lgb)
441 string tmp = lex.GetString();
442 if (tmp == "\\end_deeper") {
443 lyxerr << "\\end_deeper caught!" << endl;
445 lex.printError("\\end_deeper: "
446 "depth is already null");
457 old_float += lex.getLongString("\\end_float");
458 old_float += "\n\\end_inset\n";
459 //lyxerr << "float body: " << old_float << endl;
462 istringstream istr(old_float);
464 istrstream istr(old_float.c_str());
468 nylex.setStream(istr);
470 inset->Read(this, nylex);
471 par->InsertInset(pos, inset, font);
474 } else if (token == "\\begin_deeper") {
476 } else if (token == "\\end_deeper") {
478 lex.printError("\\end_deeper: "
479 "depth is already null");
483 } else if (token == "\\begin_preamble") {
484 params.readPreamble(lex);
485 } else if (token == "\\textclass") {
487 pair<bool, LyXTextClassList::size_type> pp =
488 textclasslist.NumberOfClass(lex.GetString());
490 params.textclass = pp.second;
492 lex.printError("Unknown textclass `$$Token'");
493 params.textclass = 0;
495 if (!textclasslist.Load(params.textclass)) {
496 // if the textclass wasn't loaded properly
497 // we need to either substitute another
498 // or stop loading the file.
499 // I can substitute but I don't see how I can
500 // stop loading... ideas?? ARRae980418
501 WriteAlert(_("Textclass Loading Error!"),
502 string(_("Can't load textclass ")) +
503 textclasslist.NameOfClass(params.textclass),
504 _("-- substituting default"));
505 params.textclass = 0;
507 } else if (token == "\\options") {
509 params.options = lex.GetString();
510 } else if (token == "\\language") {
511 params.readLanguage(lex);
512 } else if (token == "\\fontencoding") {
514 } else if (token == "\\inputencoding") {
516 params.inputenc = lex.GetString();
517 } else if (token == "\\graphics") {
518 params.readGraphicsDriver(lex);
519 } else if (token == "\\fontscheme") {
521 params.fonts = lex.GetString();
522 } else if (token == "\\noindent") {
523 par->noindent = true;
524 } else if (token == "\\fill_top") {
525 par->added_space_top = VSpace(VSpace::VFILL);
526 } else if (token == "\\fill_bottom") {
527 par->added_space_bottom = VSpace(VSpace::VFILL);
528 } else if (token == "\\line_top") {
529 par->line_top = true;
530 } else if (token == "\\line_bottom") {
531 par->line_bottom = true;
532 } else if (token == "\\pagebreak_top") {
533 par->pagebreak_top = true;
534 } else if (token == "\\pagebreak_bottom") {
535 par->pagebreak_bottom = true;
536 } else if (token == "\\start_of_appendix") {
537 par->start_of_appendix = true;
538 } else if (token == "\\paragraph_separation") {
539 int tmpret = lex.FindToken(string_paragraph_separation);
540 if (tmpret == -1) ++tmpret;
541 if (tmpret != LYX_LAYOUT_DEFAULT)
542 params.paragraph_separation =
543 static_cast<BufferParams::PARSEP>(tmpret);
544 } else if (token == "\\defskip") {
546 params.defskip = VSpace(lex.GetString());
547 } else if (token == "\\epsfig") { // obsolete
548 // Indeed it is obsolete, but we HAVE to be backwards
549 // compatible until 0.14, because otherwise all figures
550 // in existing documents are irretrivably lost. (Asger)
551 params.readGraphicsDriver(lex);
552 } else if (token == "\\quotes_language") {
553 int tmpret = lex.FindToken(string_quotes_language);
554 if (tmpret == -1) ++tmpret;
555 if (tmpret != LYX_LAYOUT_DEFAULT) {
556 InsetQuotes::quote_language tmpl =
557 InsetQuotes::EnglishQ;
560 tmpl = InsetQuotes::EnglishQ;
563 tmpl = InsetQuotes::SwedishQ;
566 tmpl = InsetQuotes::GermanQ;
569 tmpl = InsetQuotes::PolishQ;
572 tmpl = InsetQuotes::FrenchQ;
575 tmpl = InsetQuotes::DanishQ;
578 params.quotes_language = tmpl;
580 } else if (token == "\\quotes_times") {
582 switch(lex.GetInteger()) {
584 params.quotes_times = InsetQuotes::SingleQ;
587 params.quotes_times = InsetQuotes::DoubleQ;
590 } else if (token == "\\papersize") {
591 int tmpret = lex.FindToken(string_papersize);
595 params.papersize2 = tmpret;
596 } else if (token == "\\paperpackage") {
597 int tmpret = lex.FindToken(string_paperpackages);
600 params.paperpackage = BufferParams::PACKAGE_NONE;
602 params.paperpackage = tmpret;
603 } else if (token == "\\use_geometry") {
605 params.use_geometry = lex.GetInteger();
606 } else if (token == "\\use_amsmath") {
608 params.use_amsmath = lex.GetInteger();
609 } else if (token == "\\paperorientation") {
610 int tmpret = lex.FindToken(string_orientation);
611 if (tmpret == -1) ++tmpret;
612 if (tmpret != LYX_LAYOUT_DEFAULT)
613 params.orientation = static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
614 } else if (token == "\\paperwidth") {
616 params.paperwidth = lex.GetString();
617 } else if (token == "\\paperheight") {
619 params.paperheight = lex.GetString();
620 } else if (token == "\\leftmargin") {
622 params.leftmargin = lex.GetString();
623 } else if (token == "\\topmargin") {
625 params.topmargin = lex.GetString();
626 } else if (token == "\\rightmargin") {
628 params.rightmargin = lex.GetString();
629 } else if (token == "\\bottommargin") {
631 params.bottommargin = lex.GetString();
632 } else if (token == "\\headheight") {
634 params.headheight = lex.GetString();
635 } else if (token == "\\headsep") {
637 params.headsep = lex.GetString();
638 } else if (token == "\\footskip") {
640 params.footskip = lex.GetString();
641 } else if (token == "\\paperfontsize") {
643 params.fontsize = strip(lex.GetString());
644 } else if (token == "\\papercolumns") {
646 params.columns = lex.GetInteger();
647 } else if (token == "\\papersides") {
649 switch(lex.GetInteger()) {
651 case 1: params.sides = LyXTextClass::OneSide; break;
652 case 2: params.sides = LyXTextClass::TwoSides; break;
654 } else if (token == "\\paperpagestyle") {
656 params.pagestyle = strip(lex.GetString());
657 } else if (token == "\\bullet") {
659 int index = lex.GetInteger();
661 int temp_int = lex.GetInteger();
662 params.user_defined_bullets[index].setFont(temp_int);
663 params.temp_bullets[index].setFont(temp_int);
665 temp_int = lex.GetInteger();
666 params.user_defined_bullets[index].setCharacter(temp_int);
667 params.temp_bullets[index].setCharacter(temp_int);
669 temp_int = lex.GetInteger();
670 params.user_defined_bullets[index].setSize(temp_int);
671 params.temp_bullets[index].setSize(temp_int);
673 string temp_str = lex.GetString();
674 if (temp_str != "\\end_bullet") {
675 // this element isn't really necessary for
676 // parsing but is easier for humans
677 // to understand bullets. Put it back and
678 // set a debug message?
679 lex.printError("\\end_bullet expected, got" + temp_str);
680 //how can I put it back?
682 } else if (token == "\\bulletLaTeX") {
684 int index = lex.GetInteger();
686 string temp_str = lex.GetString(), sum_str;
687 while (temp_str != "\\end_bullet") {
688 // this loop structure is needed when user
689 // enters an empty string since the first
690 // thing returned will be the \\end_bullet
692 // if the LaTeX entry has spaces. Each element
693 // therefore needs to be read in turn
696 temp_str = lex.GetString();
698 params.user_defined_bullets[index].setText(sum_str);
699 params.temp_bullets[index].setText(sum_str);
700 } else if (token == "\\secnumdepth") {
702 params.secnumdepth = lex.GetInteger();
703 } else if (token == "\\tocdepth") {
705 params.tocdepth = lex.GetInteger();
706 } else if (token == "\\spacing") {
708 string tmp = strip(lex.GetString());
709 Spacing::Space tmp_space = Spacing::Default;
711 if (tmp == "single") {
712 tmp_space = Spacing::Single;
713 } else if (tmp == "onehalf") {
714 tmp_space = Spacing::Onehalf;
715 } else if (tmp == "double") {
716 tmp_space = Spacing::Double;
717 } else if (tmp == "other") {
719 tmp_space = Spacing::Other;
720 tmp_val = lex.GetFloat();
722 lex.printError("Unknown spacing token: '$$Token'");
724 // Small hack so that files written with klyx will be
727 par->spacing.set(tmp_space, tmp_val);
729 params.spacing.set(tmp_space, tmp_val);
731 } else if (token == "\\paragraph_spacing") {
733 string tmp = strip(lex.GetString());
734 if (tmp == "single") {
735 par->spacing.set(Spacing::Single);
736 } else if (tmp == "onehalf") {
737 par->spacing.set(Spacing::Onehalf);
738 } else if (tmp == "double") {
739 par->spacing.set(Spacing::Double);
740 } else if (tmp == "other") {
742 par->spacing.set(Spacing::Other,
745 lex.printError("Unknown spacing token: '$$Token'");
747 } else if (token == "\\float_placement") {
749 params.float_placement = lex.GetString();
750 } else if (token == "\\family") {
752 font.setLyXFamily(lex.GetString());
753 } else if (token == "\\series") {
755 font.setLyXSeries(lex.GetString());
756 } else if (token == "\\shape") {
758 font.setLyXShape(lex.GetString());
759 } else if (token == "\\size") {
761 font.setLyXSize(lex.GetString());
762 } else if (token == "\\latex") {
764 string tok = lex.GetString();
765 // This is dirty, but gone with LyX3. (Asger)
766 if (tok == "no_latex")
767 font.setLatex(LyXFont::OFF);
768 else if (tok == "latex")
769 font.setLatex(LyXFont::ON);
770 else if (tok == "default")
771 font.setLatex(LyXFont::INHERIT);
773 lex.printError("Unknown LaTeX font flag "
775 } else if (token == "\\lang") {
777 string tok = lex.GetString();
778 Languages::iterator lit = languages.find(tok);
779 if (lit != languages.end()) {
780 font.setLanguage(&(*lit).second);
782 font.setLanguage(params.language_info);
783 lex.printError("Unknown language `$$Token'");
785 } else if (token == "\\emph") {
787 font.setEmph(font.setLyXMisc(lex.GetString()));
788 } else if (token == "\\bar") {
790 string tok = lex.GetString();
791 // This is dirty, but gone with LyX3. (Asger)
793 font.setUnderbar(LyXFont::ON);
794 else if (tok == "no")
795 font.setUnderbar(LyXFont::OFF);
796 else if (tok == "default")
797 font.setUnderbar(LyXFont::INHERIT);
799 lex.printError("Unknown bar font flag "
801 } else if (token == "\\noun") {
803 font.setNoun(font.setLyXMisc(lex.GetString()));
804 } else if (token == "\\color") {
806 font.setLyXColor(lex.GetString());
807 } else if (token == "\\align") {
808 int tmpret = lex.FindToken(string_align);
809 if (tmpret == -1) ++tmpret;
810 if (tmpret != LYX_LAYOUT_DEFAULT) { // tmpret != 99 ???
812 for (; tmpret > 0; --tmpret)
813 tmpret2 = tmpret2 * 2;
814 par->align = LyXAlignment(tmpret2);
816 } else if (token == "\\added_space_top") {
818 par->added_space_top = VSpace(lex.GetString());
819 } else if (token == "\\added_space_bottom") {
821 par->added_space_bottom = VSpace(lex.GetString());
822 } else if (token == "\\pextra_type") {
824 par->pextra_type = lex.GetInteger();
825 } else if (token == "\\pextra_width") {
827 par->pextra_width = lex.GetString();
828 } else if (token == "\\pextra_widthp") {
830 par->pextra_widthp = lex.GetString();
831 } else if (token == "\\pextra_alignment") {
833 par->pextra_alignment = lex.GetInteger();
834 } else if (token == "\\pextra_hfill") {
836 par->pextra_hfill = lex.GetInteger();
837 } else if (token == "\\pextra_start_minipage") {
839 par->pextra_start_minipage = lex.GetInteger();
840 } else if (token == "\\labelwidthstring") {
842 par->labelwidthstring = lex.GetString();
843 // do not delete this token, it is still needed!
844 } else if (token == "\\end_inset") {
845 lyxerr << "Solitary \\end_inset. Missing \\begin_inset?.\n"
846 << "Last inset read was: " << last_inset_read
848 // Simply ignore this. The insets do not have
850 // But insets should read it, it is a part of
851 // the inset isn't it? Lgb.
852 } else if (token == "\\begin_inset") {
853 readInset(lex, par, pos, font);
854 } else if (token == "\\SpecialChar") {
855 LyXLayout const & layout =
856 textclasslist.Style(params.textclass,
859 // Insets don't make sense in a free-spacing context! ---Kayvan
860 if (layout.free_spacing) {
863 string next_token = lex.GetString();
864 if (next_token == "\\-") {
865 par->InsertChar(pos, '-', font);
866 } else if (next_token == "\\protected_separator"
867 || next_token == "~") {
868 par->InsertChar(pos, ' ', font);
870 lex.printError("Token `$$Token' "
872 "paragraph layout!");
877 Inset * inset = new InsetSpecialChar;
878 inset->Read(this, lex);
879 par->InsertInset(pos, inset, font);
882 } else if (token == "\\newline") {
883 par->InsertChar(pos, LyXParagraph::META_NEWLINE, font);
885 } else if (token == "\\LyXTable") {
887 Inset * inset = new InsetTabular(this);
888 inset->Read(this, lex);
889 par->InsertInset(pos, inset, font);
892 par->table = new LyXTable(lex);
894 } else if (token == "\\hfill") {
895 par->InsertChar(pos, LyXParagraph::META_HFILL, font);
897 } else if (token == "\\protected_separator") { // obsolete
898 // This is a backward compability thingie. (Lgb)
899 // Remove it later some time...introduced with fileformat
901 LyXLayout const & layout =
902 textclasslist.Style(params.textclass,
905 if (layout.free_spacing) {
906 par->InsertChar(pos, ' ', font);
908 Inset * inset = new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
909 par->InsertInset(pos, inset, font);
912 } else if (token == "\\bibitem") { // ale970302
914 InsetCommandParams p( "bibitem" );
915 par->bibkey = new InsetBibKey(p);
917 par->bibkey->Read(this, lex);
918 } else if (token == "\\backslash") {
919 par->InsertChar(pos, '\\', font);
921 } else if (token == "\\the_end") {
924 // This should be insurance for the future: (Asger)
925 lex.printError("Unknown token `$$Token'. "
926 "Inserting as text.");
927 string::const_iterator cit = token.begin();
928 string::const_iterator end = token.end();
929 for(; cit != end; ++cit) {
930 par->InsertChar(pos, (*cit), font);
938 void Buffer::readInset(LyXLex & lex, LyXParagraph *& par,
939 int & pos, LyXFont & font)
942 if (lex.GetString() != "\\begin_inset") {
943 lyxerr << "Buffer::readInset: Consistency check failed."
948 string tmptok = lex.GetString();
949 last_inset_read = tmptok;
950 // test the different insets
951 if (tmptok == "Quotes") {
952 Inset * inset = new InsetQuotes;
953 inset->Read(this, lex);
954 par->InsertInset(pos, inset, font);
956 } else if (tmptok == "External") {
957 Inset * inset = new InsetExternal;
958 inset->Read(this, lex);
959 par->InsertInset(pos, inset, font);
961 } else if (tmptok == "FormulaMacro") {
962 Inset * inset = new InsetFormulaMacro;
963 inset->Read(this, lex);
964 par->InsertInset(pos, inset, font);
966 } else if (tmptok == "Formula") {
967 Inset * inset = new InsetFormula;
968 inset->Read(this, lex);
969 par->InsertInset(pos, inset, font);
971 } else if (tmptok == "Figure") {
972 Inset * inset = new InsetFig(100, 100, this);
973 inset->Read(this, lex);
974 par->InsertInset(pos, inset, font);
976 } else if (tmptok == "Info") {
977 Inset * inset = new InsetInfo;
978 inset->Read(this, lex);
979 par->InsertInset(pos, inset, font);
981 } else if (tmptok == "Include") {
982 InsetCommandParams p( "Include" );
983 Inset * inset = new InsetInclude(p, this);
984 inset->Read(this, lex);
985 par->InsertInset(pos, inset, font);
987 } else if (tmptok == "ERT") {
988 Inset * inset = new InsetERT;
989 inset->Read(this, lex);
990 par->InsertInset(pos, inset, font);
992 } else if (tmptok == "Tabular") {
993 Inset * inset = new InsetTabular(this);
994 inset->Read(this, lex);
995 par->InsertInset(pos, inset, font);
997 } else if (tmptok == "Text") {
998 Inset * inset = new InsetText;
999 inset->Read(this, lex);
1000 par->InsertInset(pos, inset, font);
1002 } else if (tmptok == "Foot") {
1003 Inset * inset = new InsetFoot;
1004 inset->Read(this, lex);
1005 par->InsertInset(pos, inset, font);
1007 } else if (tmptok == "Marginal") {
1008 Inset * inset = new InsetMarginal;
1009 inset->Read(this, lex);
1010 par->InsertInset(pos, inset, font);
1012 } else if (tmptok == "Minipage") {
1013 Inset * inset = new InsetMinipage;
1014 inset->Read(this, lex);
1015 par->InsertInset(pos, inset, font);
1017 } else if (tmptok == "Float") {
1019 string tmptok = lex.GetString();
1020 Inset * inset = new InsetFloat(tmptok);
1021 inset->Read(this, lex);
1022 par->InsertInset(pos, inset, font);
1024 } else if (tmptok == "List") {
1025 Inset * inset = new InsetList;
1026 inset->Read(this, lex);
1027 par->InsertInset(pos, inset, font);
1029 } else if (tmptok == "Theorem") {
1030 Inset * inset = new InsetList;
1031 inset->Read(this, lex);
1032 par->InsertInset(pos, inset, font);
1034 } else if (tmptok == "Caption") {
1035 Inset * inset = new InsetCaption;
1036 inset->Read(this, lex);
1037 par->InsertInset(pos, inset, font);
1039 } else if (tmptok == "GRAPHICS") {
1040 Inset * inset = new InsetGraphics;
1041 inset->Read(this, lex);
1042 par->InsertInset(pos, inset, font);
1044 } else if (tmptok == "LatexCommand") {
1045 InsetCommandParams inscmd;
1048 if (inscmd.getCmdName() == "cite") {
1049 inset = new InsetCitation(inscmd);
1050 } else if (inscmd.getCmdName() == "bibitem") {
1051 lex.printError("Wrong place for bibitem");
1052 inset = new InsetBibKey(inscmd);
1053 } else if (inscmd.getCmdName() == "BibTeX") {
1054 inset = new InsetBibtex(inscmd, this);
1055 } else if (inscmd.getCmdName() == "index") {
1056 inset = new InsetIndex(inscmd);
1057 } else if (inscmd.getCmdName() == "include") {
1058 inset = new InsetInclude(inscmd, this);
1059 } else if (inscmd.getCmdName() == "label") {
1060 inset = new InsetLabel(inscmd);
1061 } else if (inscmd.getCmdName() == "url"
1062 || inscmd.getCmdName() == "htmlurl") {
1063 inset = new InsetUrl(inscmd);
1064 } else if (inscmd.getCmdName() == "ref"
1065 || inscmd.getCmdName() == "pageref"
1066 || inscmd.getCmdName() == "vref"
1067 || inscmd.getCmdName() == "vpageref"
1068 || inscmd.getCmdName() == "prettyref") {
1069 if (!inscmd.getOptions().empty()
1070 || !inscmd.getContents().empty()) {
1071 inset = new InsetRef(inscmd);
1073 } else if (inscmd.getCmdName() == "tableofcontents"
1074 || inscmd.getCmdName() == "listofalgorithms"
1075 || inscmd.getCmdName() == "listoffigures"
1076 || inscmd.getCmdName() == "listoftables") {
1077 inset = new InsetTOC(inscmd);
1078 } else if (inscmd.getCmdName() == "printindex") {
1079 inset = new InsetPrintIndex(inscmd);
1080 } else if (inscmd.getCmdName() == "lyxparent") {
1081 inset = new InsetParent(inscmd, this);
1085 par->InsertInset(pos, inset, font);
1092 bool Buffer::readFile(LyXLex & lex, LyXParagraph * par)
1096 string token(lex.GetString());
1097 if (token == "\\lyxformat") { // the first token _must_ be...
1099 format = lex.GetFloat();
1101 if (LYX_FORMAT - format > 0.05) {
1103 printf(_("Warning: need lyxformat %.2f but found %.2f\n"),
1104 LYX_FORMAT, format);
1106 if (format - LYX_FORMAT > 0.05) {
1107 printf(_("ERROR: need lyxformat %.2f but found %.2f\n"),
1108 LYX_FORMAT, format);
1110 bool the_end = readLyXformat2(lex, par);
1111 // Formats >= 2.13 support "\the_end" marker
1118 WriteAlert(_("Warning!"),
1119 _("Reading of document is not complete"),
1120 _("Maybe the document is truncated"));
1121 // We simulate a safe reading anyways to allow
1122 // users to take the chance... (Asger)
1126 WriteAlert(_("ERROR!"),
1127 _("Old LyX file format found. "
1128 "Use LyX 0.10.x to read this!"));
1132 } else { // "\\lyxformat" not found
1133 WriteAlert(_("ERROR!"), _("Not a LyX file!"));
1136 WriteAlert(_("ERROR!"), _("Unable to read file!"));
1142 // Should probably be moved to somewhere else: BufferView? LyXView?
1143 bool Buffer::save() const
1145 // We don't need autosaves in the immediate future. (Asger)
1146 resetAutosaveTimers();
1150 if (lyxrc.make_backup) {
1151 s = fileName() + '~';
1152 if (!lyxrc.backupdir_path.empty())
1153 s = AddName(lyxrc.backupdir_path,
1154 subst(CleanupPath(s),'/','!'));
1156 // Rename is the wrong way of making a backup,
1157 // this is the correct way.
1158 /* truss cp fil fil2:
1159 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
1160 stat("LyXVC.lyx", 0xEFFFF688) = 0
1161 open("LyXVC.lyx", O_RDONLY) = 3
1162 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
1163 fstat(4, 0xEFFFF508) = 0
1164 fstat(3, 0xEFFFF508) = 0
1165 read(3, " # T h i s f i l e w".., 8192) = 5579
1166 write(4, " # T h i s f i l e w".., 5579) = 5579
1167 read(3, 0xEFFFD4A0, 8192) = 0
1170 chmod("LyXVC3.lyx", 0100644) = 0
1171 lseek(0, 0, SEEK_CUR) = 46440
1175 // Should proabaly have some more error checking here.
1176 // Should be cleaned up in 0.13, at least a bit.
1177 // Doing it this way, also makes the inodes stay the same.
1178 // This is still not a very good solution, in particular we
1179 // might loose the owner of the backup.
1180 FileInfo finfo(fileName());
1181 if (finfo.exist()) {
1182 mode_t fmode = finfo.getMode();
1183 struct utimbuf times = {
1184 finfo.getAccessTime(),
1185 finfo.getModificationTime() };
1187 ifstream ifs(fileName().c_str());
1188 ofstream ofs(s.c_str(), ios::out|ios::trunc);
1193 ::chmod(s.c_str(), fmode);
1195 if (::utime(s.c_str(), ×)) {
1196 lyxerr << "utime error." << endl;
1199 lyxerr << "LyX was not able to make "
1200 "backupcopy. Beware." << endl;
1205 if (writeFile(fileName(), false)) {
1207 removeAutosaveFile(fileName());
1209 // Saving failed, so backup is not backup
1210 if (lyxrc.make_backup) {
1211 ::rename(s.c_str(), fileName().c_str());
1219 // Returns false if unsuccesful
1220 bool Buffer::writeFile(string const & fname, bool flag) const
1222 // if flag is false writeFile will not create any GUI
1223 // warnings, only cerr.
1224 // Needed for autosave in background or panic save (Matthias 120496)
1226 if (read_only && (fname == filename)) {
1227 // Here we should come with a question if we should
1228 // perform the write anyway.
1230 lyxerr << _("Error! Document is read-only: ")
1233 WriteAlert(_("Error! Document is read-only: "),
1238 FileInfo finfo(fname);
1239 if (finfo.exist() && !finfo.writable()) {
1240 // Here we should come with a question if we should
1241 // try to do the save anyway. (i.e. do a chmod first)
1243 lyxerr << _("Error! Cannot write file: ")
1246 WriteFSAlert(_("Error! Cannot write file: "),
1251 ofstream ofs(fname.c_str());
1254 lyxerr << _("Error! Cannot open file: ")
1257 WriteFSAlert(_("Error! Cannot open file: "),
1261 // The top of the file should not be written by params.
1263 // write out a comment in the top of the file
1264 ofs << '#' << LYX_DOCVERSION
1265 << " created this file. For more info see http://www.lyx.org/\n";
1266 ofs.setf(ios::showpoint|ios::fixed);
1268 ofs << "\\lyxformat " << setw(4) << LYX_FORMAT << "\n";
1270 // now write out the buffer paramters.
1271 params.writeFile(ofs);
1273 char footnoteflag = 0;
1276 // this will write out all the paragraphs
1277 // using recursive descent.
1278 paragraph->writeFile(this, ofs, params, footnoteflag, depth);
1280 // Write marker that shows file is complete
1281 ofs << "\n\\the_end" << endl;
1283 // how to check if close went ok?
1288 void Buffer::writeFileAscii(string const & fname, int linelen)
1290 LyXFont font1, font2;
1292 char c, footnoteflag = 0, depth = 0;
1294 LyXParagraph::size_type i;
1297 int ltype_depth = 0;
1306 int currlinelen = 0;
1308 bool ref_printed = false;
1310 ofstream ofs(fname.c_str());
1312 WriteFSAlert(_("Error: Cannot write file:"), fname);
1316 string fname1 = TmpFileName();
1317 LyXParagraph * par = paragraph;
1323 par->footnoteflag != LyXParagraph::NO_FOOTNOTE ||
1327 || par->previous->footnoteflag == LyXParagraph::NO_FOOTNOTE
1332 /* begins a footnote environment ? */
1333 if (footnoteflag != par->footnoteflag) {
1334 footnoteflag = par->footnoteflag;
1336 j = strlen(string_footnotekinds[par->footnotekind])+4;
1337 if (currlinelen + j > linelen)
1340 << string_footnotekinds[par->footnotekind] << "] ";
1346 /* begins or ends a deeper area ?*/
1347 if (depth != par->depth) {
1348 if (par->depth > depth) {
1349 while (par->depth > depth) {
1354 while (par->depth < depth) {
1360 /* First write the layout */
1361 tmp = textclasslist.NameOfLayout(params.textclass, par->layout);
1362 if (tmp == "Itemize") {
1364 ltype_depth = depth+1;
1365 } else if (tmp == "Enumerate") {
1367 ltype_depth = depth+1;
1368 } else if (strstr(tmp.c_str(), "ection")) {
1370 ltype_depth = depth+1;
1371 } else if (strstr(tmp.c_str(), "aragraph")) {
1373 ltype_depth = depth+1;
1374 } else if (tmp == "Description") {
1376 ltype_depth = depth+1;
1377 } else if (tmp == "Abstract") {
1380 } else if (tmp == "Bibliography") {
1388 /* maybe some vertical spaces */
1390 /* the labelwidthstring used in lists */
1394 /* some pagebreaks? */
1398 /* what about the alignment */
1401 /* dummy layout, that means a footnote ended */
1402 footnoteflag = LyXParagraph::NO_FOOTNOTE;
1406 lyxerr << "Should this ever happen?" << endl;
1410 //LyXLayout const & layout =
1411 // textclasslist.Style(params.textclass,
1412 // par->GetLayout()); // unused
1413 //bool free_spc = layout.free_spacing; //unused
1416 /* It might be a table */
1420 cells = par->table->columns;
1421 clen = new int [cells];
1422 memset(clen, 0, sizeof(int) * cells);
1424 for (i = 0, j = 0, h = 1; i < par->size(); ++i, ++h) {
1425 c = par->GetChar(i);
1426 if (c == LyXParagraph::META_INSET) {
1427 if ((inset = par->GetInset(i))) {
1429 std::ostringstream ost;
1430 inset->Ascii(this, ost);
1431 h += ost.str().length();
1434 inset->Ascii(this, ost);
1436 char * tmp = ost.str();
1442 } else if (c == LyXParagraph::META_NEWLINE) {
1446 j = (++j) % par->table->NumberOfCellsInRow(actcell);
1454 font1 = LyXFont(LyXFont::ALL_INHERIT, params.language_info);
1456 for (i = 0, actpos = 1; i < par->size(); ++i, ++actpos) {
1457 if (!i && !footnoteflag && !noparbreak){
1459 for(j = 0; j < depth; ++j)
1461 currlinelen = depth * 2;
1463 case 0: /* Standard */
1464 case 4: /* (Sub)Paragraph */
1465 case 5: /* Description */
1467 case 6: /* Abstract */
1468 ofs << "Abstract\n\n";
1470 case 7: /* Bibliography */
1472 ofs << "References\n\n";
1477 ofs << par->labelstring << " ";
1480 if (ltype_depth > depth) {
1481 for(j = ltype_depth - 1; j > depth; --j)
1483 currlinelen += (ltype_depth-depth)*2;
1487 for(j = 0; j < cells; ++j) {
1489 for(h = 0; h < (clen[j] + 1);
1494 for(j = 0; j < depth; ++j)
1496 currlinelen = depth * 2;
1497 if (ltype_depth > depth) {
1498 for(j = ltype_depth;
1501 currlinelen += (ltype_depth-depth)*2;
1507 font2 = par->GetFontSettings(params, i);
1508 if (font1.latex() != font2.latex()) {
1509 if (font2.latex() == LyXFont::OFF)
1516 c = par->GetChar(i);
1520 case LyXParagraph::META_INSET:
1521 if ((inset = par->GetInset(i))) {
1523 inset->Ascii(this, ofs);
1524 currlinelen += (ofs.tellp() - fpos);
1525 actpos += (ofs.tellp() - fpos) - 1;
1528 case LyXParagraph::META_NEWLINE:
1531 if (par->table->NumberOfCellsInRow(actcell) <= cell) {
1532 for(j = actpos; j < clen[cell - 1]; ++j)
1535 for(j = 0; j < depth; ++j)
1537 currlinelen = depth*2;
1538 if (ltype_depth > depth) {
1539 for(j = ltype_depth; j > depth; --j)
1541 currlinelen += (ltype_depth-depth) * 2;
1543 for(j = 0; j < cells; ++j) {
1545 for(h = 0; h < (clen[j] + 1); ++h)
1549 for(j = 0; j < depth; ++j)
1551 currlinelen = depth * 2;
1552 if (ltype_depth > depth) {
1553 for(j = ltype_depth;
1556 currlinelen += (ltype_depth-depth)*2;
1562 j < clen[cell - 1]; ++j)
1568 currlinelen = actpos = 0;
1572 for(j = 0; j < depth; ++j)
1574 currlinelen = depth * 2;
1575 if (ltype_depth > depth) {
1576 for(j = ltype_depth;
1579 currlinelen += (ltype_depth - depth) * 2;
1585 case LyXParagraph::META_HFILL:
1592 if (currlinelen > linelen - 10
1593 && c == ' ' && i + 2 < par->size()) {
1595 for(j = 0; j < depth; ++j)
1597 currlinelen = depth * 2;
1598 if (ltype_depth > depth) {
1599 for(j = ltype_depth;
1602 currlinelen += (ltype_depth-depth)*2;
1604 } else if (c != '\0')
1607 lyxerr.debug() << "writeAsciiFile: NULL char in structure." << endl;
1614 for(j = actpos; j < clen[cell - 1]; ++j)
1617 for(j = 0; j < depth; ++j)
1619 currlinelen = depth * 2;
1620 if (ltype_depth > depth) {
1621 for(j = ltype_depth; j > depth; --j)
1623 currlinelen += (ltype_depth - depth) * 2;
1625 for(j = 0; j < cells; ++j) {
1627 for(h = 0; h < (clen[j] + 1); ++h)
1641 void Buffer::makeLaTeXFile(string const & fname,
1642 string const & original_path,
1643 bool nice, bool only_body)
1645 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
1647 niceFile = nice; // this will be used by Insetincludes.
1649 tex_code_break_column = lyxrc.ascii_linelen;
1651 LyXTextClass const & tclass =
1652 textclasslist.TextClass(params.textclass);
1654 ofstream ofs(fname.c_str());
1656 WriteFSAlert(_("Error: Cannot open file: "), fname);
1660 // validate the buffer.
1661 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
1662 LaTeXFeatures features(params, tclass.numLayouts());
1664 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
1667 // The starting paragraph of the coming rows is the
1668 // first paragraph of the document. (Asger)
1669 texrow.start(paragraph, 0);
1671 if (!only_body && nice) {
1672 ofs << "%% " LYX_DOCVERSION " created this file. "
1673 "For more info, see http://www.lyx.org/.\n"
1674 "%% Do not edit unless you really know what "
1679 lyxerr.debug() << "lyx header finished" << endl;
1680 // There are a few differences between nice LaTeX and usual files:
1681 // usual is \batchmode and has a
1682 // special input@path to allow the including of figures
1683 // with either \input or \includegraphics (what figinsets do).
1684 // batchmode is not set if there is a tex_code_break_column.
1685 // In this case somebody is interested in the generated LaTeX,
1686 // so this is OK. input@path is set when the actual parameter
1687 // original_path is set. This is done for usual tex-file, but not
1688 // for nice-latex-file. (Matthias 250696)
1691 // code for usual, NOT nice-latex-file
1692 ofs << "\\batchmode\n"; // changed
1693 // from \nonstopmode
1696 if (!original_path.empty()) {
1697 ofs << "\\makeatletter\n"
1698 << "\\def\\input@path{{"
1699 << original_path << "/}}\n"
1700 << "\\makeatother\n";
1706 ofs << "\\documentclass";
1708 string options; // the document class options.
1710 if (tokenPos(tclass.opt_fontsize(),
1711 '|', params.fontsize) >= 0) {
1712 // only write if existing in list (and not default)
1713 options += params.fontsize;
1718 if (!params.use_geometry &&
1719 (params.paperpackage == BufferParams::PACKAGE_NONE)) {
1720 switch (params.papersize) {
1721 case BufferParams::PAPER_A4PAPER:
1722 options += "a4paper,";
1724 case BufferParams::PAPER_USLETTER:
1725 options += "letterpaper,";
1727 case BufferParams::PAPER_A5PAPER:
1728 options += "a5paper,";
1730 case BufferParams::PAPER_B5PAPER:
1731 options += "b5paper,";
1733 case BufferParams::PAPER_EXECUTIVEPAPER:
1734 options += "executivepaper,";
1736 case BufferParams::PAPER_LEGALPAPER:
1737 options += "legalpaper,";
1743 if (params.sides != tclass.sides()) {
1744 switch (params.sides) {
1745 case LyXTextClass::OneSide:
1746 options += "oneside,";
1748 case LyXTextClass::TwoSides:
1749 options += "twoside,";
1756 if (params.columns != tclass.columns()) {
1757 if (params.columns == 2)
1758 options += "twocolumn,";
1760 options += "onecolumn,";
1763 if (!params.use_geometry
1764 && params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1765 options += "landscape,";
1767 // language should be a parameter to \documentclass
1768 bool use_babel = false;
1769 if (params.language_info->lang() == "hebrew") // This seems necessary
1770 features.UsedLanguages.insert(default_language);
1771 if (params.language != "default" ||
1772 !features.UsedLanguages.empty() ) {
1774 for (LaTeXFeatures::LanguageList::const_iterator cit =
1775 features.UsedLanguages.begin();
1776 cit != features.UsedLanguages.end(); ++cit)
1777 options += (*cit)->lang() + ",";
1778 options += params.language_info->lang() + ',';
1781 // the user-defined options
1782 if (!params.options.empty()) {
1783 options += params.options + ',';
1786 if (!options.empty()){
1787 options = strip(options, ',');
1788 ofs << '[' << options << ']';
1792 << textclasslist.LatexnameOfClass(params.textclass)
1795 // end of \documentclass defs
1797 // font selection must be done before loading fontenc.sty
1798 if (params.fonts != "default") {
1799 ofs << "\\usepackage{" << params.fonts << "}\n";
1802 // this one is not per buffer
1803 if (lyxrc.fontenc != "default") {
1804 ofs << "\\usepackage[" << lyxrc.fontenc
1809 if (params.inputenc == "auto") {
1810 string doc_encoding =
1811 params.language_info->encoding()->LatexName();
1813 // Create a list with all the input encodings used
1815 set<string> encodings;
1816 for (LaTeXFeatures::LanguageList::const_iterator it =
1817 features.UsedLanguages.begin();
1818 it != features.UsedLanguages.end(); ++it)
1819 if ((*it)->encoding()->LatexName() != doc_encoding)
1820 encodings.insert((*it)->encoding()->LatexName());
1822 ofs << "\\usepackage[";
1823 for (set<string>::const_iterator it = encodings.begin();
1824 it != encodings.end(); ++it)
1826 ofs << doc_encoding << "]{inputenc}\n";
1828 } else if (params.inputenc != "default") {
1829 ofs << "\\usepackage[" << params.inputenc
1834 // At the very beginning the text parameters.
1835 if (params.paperpackage != BufferParams::PACKAGE_NONE) {
1836 switch (params.paperpackage) {
1837 case BufferParams::PACKAGE_A4:
1838 ofs << "\\usepackage{a4}\n";
1841 case BufferParams::PACKAGE_A4WIDE:
1842 ofs << "\\usepackage{a4wide}\n";
1845 case BufferParams::PACKAGE_WIDEMARGINSA4:
1846 ofs << "\\usepackage[widemargins]{a4}\n";
1851 if (params.use_geometry) {
1852 ofs << "\\usepackage{geometry}\n";
1854 ofs << "\\geometry{verbose";
1855 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1856 ofs << ",landscape";
1857 switch (params.papersize2) {
1858 case BufferParams::VM_PAPER_CUSTOM:
1859 if (!params.paperwidth.empty())
1860 ofs << ",paperwidth="
1861 << params.paperwidth;
1862 if (!params.paperheight.empty())
1863 ofs << ",paperheight="
1864 << params.paperheight;
1866 case BufferParams::VM_PAPER_USLETTER:
1867 ofs << ",letterpaper";
1869 case BufferParams::VM_PAPER_USLEGAL:
1870 ofs << ",legalpaper";
1872 case BufferParams::VM_PAPER_USEXECUTIVE:
1873 ofs << ",executivepaper";
1875 case BufferParams::VM_PAPER_A3:
1878 case BufferParams::VM_PAPER_A4:
1881 case BufferParams::VM_PAPER_A5:
1884 case BufferParams::VM_PAPER_B3:
1887 case BufferParams::VM_PAPER_B4:
1890 case BufferParams::VM_PAPER_B5:
1894 // default papersize ie BufferParams::VM_PAPER_DEFAULT
1895 switch (lyxrc.default_papersize) {
1896 case BufferParams::PAPER_DEFAULT: // keep compiler happy
1897 case BufferParams::PAPER_USLETTER:
1898 ofs << ",letterpaper";
1900 case BufferParams::PAPER_LEGALPAPER:
1901 ofs << ",legalpaper";
1903 case BufferParams::PAPER_EXECUTIVEPAPER:
1904 ofs << ",executivepaper";
1906 case BufferParams::PAPER_A3PAPER:
1909 case BufferParams::PAPER_A4PAPER:
1912 case BufferParams::PAPER_A5PAPER:
1915 case BufferParams::PAPER_B5PAPER:
1920 if (!params.topmargin.empty())
1921 ofs << ",tmargin=" << params.topmargin;
1922 if (!params.bottommargin.empty())
1923 ofs << ",bmargin=" << params.bottommargin;
1924 if (!params.leftmargin.empty())
1925 ofs << ",lmargin=" << params.leftmargin;
1926 if (!params.rightmargin.empty())
1927 ofs << ",rmargin=" << params.rightmargin;
1928 if (!params.headheight.empty())
1929 ofs << ",headheight=" << params.headheight;
1930 if (!params.headsep.empty())
1931 ofs << ",headsep=" << params.headsep;
1932 if (!params.footskip.empty())
1933 ofs << ",footskip=" << params.footskip;
1937 if (params.use_amsmath
1938 && !tclass.provides(LyXTextClass::amsmath)) {
1939 ofs << "\\usepackage{amsmath}\n";
1943 if (tokenPos(tclass.opt_pagestyle(),
1944 '|', params.pagestyle) >= 0) {
1945 if (params.pagestyle == "fancy") {
1946 ofs << "\\usepackage{fancyhdr}\n";
1949 ofs << "\\pagestyle{" << params.pagestyle << "}\n";
1953 // We try to load babel late, in case it interferes
1954 // with other packages.
1956 ofs << lyxrc.language_package << endl;
1960 if (params.secnumdepth != tclass.secnumdepth()) {
1961 ofs << "\\setcounter{secnumdepth}{"
1962 << params.secnumdepth
1966 if (params.tocdepth != tclass.tocdepth()) {
1967 ofs << "\\setcounter{tocdepth}{"
1973 if (params.paragraph_separation) {
1974 switch (params.defskip.kind()) {
1975 case VSpace::SMALLSKIP:
1976 ofs << "\\setlength\\parskip{\\smallskipamount}\n";
1978 case VSpace::MEDSKIP:
1979 ofs << "\\setlength\\parskip{\\medskipamount}\n";
1981 case VSpace::BIGSKIP:
1982 ofs << "\\setlength\\parskip{\\bigskipamount}\n";
1984 case VSpace::LENGTH:
1985 ofs << "\\setlength\\parskip{"
1986 << params.defskip.length().asLatexString()
1989 default: // should never happen // Then delete it.
1990 ofs << "\\setlength\\parskip{\\medskipamount}\n";
1995 ofs << "\\setlength\\parindent{0pt}\n";
1999 // Now insert the LyX specific LaTeX commands...
2001 // The optional packages;
2002 string preamble(features.getPackages());
2004 // this might be useful...
2005 preamble += "\n\\makeatletter\n";
2007 // Some macros LyX will need
2008 string tmppreamble(features.getMacros());
2010 if (!tmppreamble.empty()) {
2011 preamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2012 "LyX specific LaTeX commands.\n"
2013 + tmppreamble + '\n';
2016 // the text class specific preamble
2017 tmppreamble = features.getTClassPreamble();
2018 if (!tmppreamble.empty()) {
2019 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2020 "Textclass specific LaTeX commands.\n"
2021 + tmppreamble + '\n';
2024 /* the user-defined preamble */
2025 if (!params.preamble.empty()) {
2026 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2027 "User specified LaTeX commands.\n"
2028 + params.preamble + '\n';
2031 preamble += "\\makeatother\n";
2033 // Itemize bullet settings need to be last in case the user
2034 // defines their own bullets that use a package included
2035 // in the user-defined preamble -- ARRae
2036 // Actually it has to be done much later than that
2037 // since some packages like frenchb make modifications
2038 // at \begin{document} time -- JMarc
2040 for (int i = 0; i < 4; ++i) {
2041 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
2042 if (bullets_def.empty())
2043 bullets_def="\\AtBeginDocument{\n";
2044 bullets_def += " \\renewcommand{\\labelitemi";
2046 // `i' is one less than the item to modify
2053 bullets_def += "ii";
2059 bullets_def += "}{" +
2060 params.user_defined_bullets[i].getText()
2065 if (!bullets_def.empty())
2066 preamble += bullets_def + "}\n\n";
2068 for (int j = countChar(preamble, '\n'); j-- ;) {
2075 ofs << "\\begin{document}\n";
2078 lyxerr.debug() << "preamble finished, now the body." << endl;
2079 if (!lyxrc.language_auto_begin && params.language != "default") {
2080 ofs << subst(lyxrc.language_command_begin, "$$lang",
2086 latexParagraphs(ofs, paragraph, 0, texrow);
2088 // add this just in case after all the paragraphs
2092 if (!lyxrc.language_auto_end && params.language != "default") {
2093 ofs << subst(lyxrc.language_command_end, "$$lang",
2100 ofs << "\\end{document}\n";
2103 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
2105 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
2109 // Just to be sure. (Asger)
2112 // tex_code_break_column's value is used to decide
2113 // if we are in batchmode or not (within mathed_write()
2114 // in math_write.C) so we must set it to a non-zero
2115 // value when we leave otherwise we save incorrect .lyx files.
2116 tex_code_break_column = lyxrc.ascii_linelen;
2120 lyxerr << "File was not closed properly." << endl;
2123 lyxerr.debug() << "Finished making latex file." << endl;
2128 // LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
2130 void Buffer::latexParagraphs(ostream & ofs, LyXParagraph * par,
2131 LyXParagraph * endpar, TexRow & texrow) const
2133 bool was_title = false;
2134 bool already_title = false;
2136 std::ostringstream ftnote;
2138 char * tmpholder = 0;
2144 while (par != endpar) {
2145 #ifndef HAVE_SSTREAM
2148 ftnote << tmpholder;
2149 delete [] tmpholder;
2155 lyxerr[Debug::LATEX] << "Error in latexParagraphs."
2158 LyXLayout const & layout =
2159 textclasslist.Style(params.textclass,
2162 if (layout.intitle) {
2163 if (already_title) {
2164 lyxerr <<"Error in latexParagraphs: You"
2165 " should not mix title layouts"
2166 " with normal ones." << endl;
2169 } else if (was_title && !already_title) {
2170 ofs << "\\maketitle\n";
2172 already_title = true;
2175 // We are at depth 0 so we can just use
2176 // ordinary \footnote{} generation
2177 // flag this with ftcount
2179 if (layout.isEnvironment()
2180 || par->pextra_type != LyXParagraph::PEXTRA_NONE) {
2181 par = par->TeXEnvironment(this, params, ofs, texrow
2183 ,ftnote, ft_texrow, ftcount
2187 par = par->TeXOnePar(this, params, ofs, texrow, false
2190 ftnote, ft_texrow, ftcount
2195 // Write out what we've generated...
2198 ofs << "\\addtocounter{footnote}{-"
2202 ofs << ftnote.str();
2203 texrow += ft_texrow;
2205 // The extra .c_str() is needed when we use
2206 // lyxstring instead of the STL string class.
2207 ftnote.str(string().c_str());
2209 delete [] ftnote.str();
2214 #ifndef HAVE_SSTREAM
2216 // I hate strstreams
2217 tmpholder = ftnote.str();
2221 #ifndef HAVE_SSTREAM
2222 delete [] tmpholder;
2224 // It might be that we only have a title in this document
2225 if (was_title && !already_title) {
2226 ofs << "\\maketitle\n";
2232 bool Buffer::isLatex() const
2234 return textclasslist.TextClass(params.textclass).outputType() == LATEX;
2238 bool Buffer::isLinuxDoc() const
2240 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC;
2244 bool Buffer::isLiterate() const
2246 return textclasslist.TextClass(params.textclass).outputType() == LITERATE;
2250 bool Buffer::isDocBook() const
2252 return textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2256 bool Buffer::isSGML() const
2258 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC ||
2259 textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2263 void Buffer::sgmlOpenTag(ostream & os, int depth,
2264 string const & latexname) const
2266 os << string(depth, ' ') << "<" << latexname << ">\n";
2270 void Buffer::sgmlCloseTag(ostream & os, int depth,
2271 string const & latexname) const
2273 os << string(depth, ' ') << "</" << latexname << ">\n";
2277 void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
2279 LyXParagraph * par = paragraph;
2281 niceFile = nice; // this will be used by Insetincludes.
2283 string top_element = textclasslist.LatexnameOfClass(params.textclass);
2284 string environment_stack[10];
2287 int depth = 0; // paragraph depth
2289 ofstream ofs(fname.c_str());
2292 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2296 LyXTextClass const & tclass =
2297 textclasslist.TextClass(params.textclass);
2299 LaTeXFeatures features(params, tclass.numLayouts());
2303 tex_code_break_column = lyxrc.ascii_linelen;
2305 //tex_code_break_column = 0;
2310 string sgml_includedfiles=features.getIncludedFiles();
2312 if (params.preamble.empty() && sgml_includedfiles.empty()) {
2313 ofs << "<!doctype linuxdoc system>\n\n";
2315 ofs << "<!doctype linuxdoc system [ "
2316 << params.preamble << sgml_includedfiles << " \n]>\n\n";
2319 if(params.options.empty())
2320 sgmlOpenTag(ofs, 0, top_element);
2322 string top = top_element;
2324 top += params.options;
2325 sgmlOpenTag(ofs, 0, top);
2329 ofs << "<!-- " << LYX_DOCVERSION
2330 << " created this file. For more info see http://www.lyx.org/"
2334 int desc_on = 0; // description mode
2335 LyXLayout const & style =
2336 textclasslist.Style(params.textclass,
2339 // treat <toc> as a special case for compatibility with old code
2340 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2341 Inset * inset = par->GetInset(0);
2342 Inset::Code lyx_code = inset->LyxCode();
2343 if (lyx_code == Inset::TOC_CODE){
2344 string temp = "toc";
2345 sgmlOpenTag(ofs, depth, temp);
2349 linuxDocHandleFootnote(ofs, par, depth);
2355 // environment tag closing
2356 for( ; depth > par->depth; --depth) {
2357 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2358 environment_stack[depth].erase();
2361 // write opening SGML tags
2362 switch(style.latextype) {
2363 case LATEX_PARAGRAPH:
2364 if(depth == par->depth
2365 && !environment_stack[depth].empty()) {
2366 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2367 environment_stack[depth].erase();
2373 sgmlOpenTag(ofs, depth, style.latexname());
2378 LinuxDocError(par, 0,
2379 _("Error : Wrong depth for"
2380 " LatexType Command.\n"));
2382 if (!environment_stack[depth].empty()){
2383 sgmlCloseTag(ofs, depth,
2384 environment_stack[depth]);
2388 environment_stack[depth].erase();
2389 sgmlOpenTag(ofs, depth, style.latexname());
2392 case LATEX_ENVIRONMENT:
2393 case LATEX_ITEM_ENVIRONMENT:
2394 if(depth == par->depth
2395 && environment_stack[depth] != style.latexname()
2396 && !environment_stack[depth].empty()) {
2398 sgmlCloseTag(ofs, depth,
2399 environment_stack[depth]);
2400 environment_stack[depth].erase();
2402 if (depth < par->depth) {
2404 environment_stack[depth].erase();
2406 if (environment_stack[depth] != style.latexname()) {
2409 sgmlOpenTag(ofs, depth, temp);
2411 environment_stack[depth] = style.latexname();
2412 sgmlOpenTag(ofs, depth,
2413 environment_stack[depth]);
2415 if(style.latextype == LATEX_ENVIRONMENT) break;
2417 desc_on = (style.labeltype == LABEL_MANUAL);
2424 sgmlOpenTag(ofs, depth + 1, item_name);
2427 sgmlOpenTag(ofs, depth, style.latexname());
2434 SimpleLinuxDocOnePar(ofs, par, desc_on, depth);
2438 linuxDocHandleFootnote(ofs, par, depth);
2440 while(par && par->IsDummy());
2444 // write closing SGML tags
2445 switch(style.latextype) {
2447 case LATEX_ENVIRONMENT:
2448 case LATEX_ITEM_ENVIRONMENT:
2451 sgmlCloseTag(ofs, depth, style.latexname());
2457 for(; depth > 0; --depth)
2458 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2460 if(!environment_stack[depth].empty())
2461 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2465 sgmlCloseTag(ofs, 0, top_element);
2469 // How to check for successful close
2474 void Buffer::linuxDocHandleFootnote(ostream & os, LyXParagraph * & par,
2477 string tag = "footnote";
2479 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2480 sgmlOpenTag(os, depth + 1, tag);
2481 SimpleLinuxDocOnePar(os, par, 0, depth + 1);
2482 sgmlCloseTag(os, depth + 1, tag);
2489 void Buffer::DocBookHandleCaption(ostream & os, string & inner_tag,
2490 int const depth, int desc_on,
2491 LyXParagraph * & par)
2493 LyXParagraph * tpar = par;
2496 && (tpar->footnoteflag != LyXParagraph::NO_FOOTNOTE)
2498 && (tpar->layout != textclasslist.NumberOfLayout(params.textclass,
2502 tpar->layout == textclasslist.NumberOfLayout(params.textclass,
2503 "Caption").second) {
2504 sgmlOpenTag(os, depth + 1, inner_tag);
2506 SimpleDocBookOnePar(os, extra_par, tpar,
2507 desc_on, depth + 2);
2508 sgmlCloseTag(os, depth+1, inner_tag);
2509 if(!extra_par.empty())
2516 void Buffer::DocBookHandleFootnote(ostream & os, LyXParagraph * & par,
2519 string tag, inner_tag;
2520 string tmp_par, extra_par;
2521 bool inner_span = false;
2524 // Someone should give this enum a proper name (Lgb)
2532 SOME_ENUM last = NO_ONE;
2533 SOME_ENUM present = FOOTNOTE_LIKE;
2535 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2536 if(last == present) {
2538 if(!tmp_par.empty()) {
2541 sgmlCloseTag(os, depth + 1, inner_tag);
2542 sgmlOpenTag(os, depth + 1, inner_tag);
2549 if(!inner_tag.empty()) sgmlCloseTag(os, depth + 1,
2551 if(!extra_par.empty()) os << extra_par;
2552 if(!tag.empty()) sgmlCloseTag(os, depth, tag);
2555 switch (par->footnotekind) {
2556 case LyXParagraph::FOOTNOTE:
2557 case LyXParagraph::ALGORITHM:
2560 present = FOOTNOTE_LIKE;
2563 case LyXParagraph::MARGIN:
2566 present = MARGIN_LIKE;
2569 case LyXParagraph::FIG:
2570 case LyXParagraph::WIDE_FIG:
2572 inner_tag = "title";
2576 case LyXParagraph::TAB:
2577 case LyXParagraph::WIDE_TAB:
2579 inner_tag = "title";
2584 sgmlOpenTag(os, depth, tag);
2585 if ((present == TAB_LIKE) || (present == FIG_LIKE)) {
2586 DocBookHandleCaption(os, inner_tag, depth,
2590 sgmlOpenTag(os, depth + 1, inner_tag);
2593 // ignore all caption here, we processed them above!!!
2594 if (par->layout != textclasslist
2595 .NumberOfLayout(params.textclass,
2596 "Caption").second) {
2598 std::ostringstream ost;
2602 SimpleDocBookOnePar(ost, extra_par, par,
2603 desc_on, depth + 2);
2605 tmp_par += ost.str().c_str();
2608 char * ctmp = ost.str();
2613 tmp_par = frontStrip(strip(tmp_par));
2619 if(!inner_tag.empty()) sgmlCloseTag(os, depth + 1, inner_tag);
2620 if(!extra_par.empty()) os << extra_par;
2621 if(!tag.empty()) sgmlCloseTag(os, depth, tag);
2626 // push a tag in a style stack
2627 void Buffer::push_tag(ostream & os, char const * tag,
2628 int & pos, char stack[5][3])
2630 // pop all previous tags
2631 for (int j = pos; j >= 0; --j)
2632 os << "</" << stack[j] << ">";
2635 sprintf(stack[++pos], "%s", tag);
2638 for (int i = 0; i <= pos; ++i)
2639 os << "<" << stack[i] << ">";
2643 void Buffer::pop_tag(ostream & os, char const * tag,
2644 int & pos, char stack[5][3])
2648 // pop all tags till specified one
2649 for (j = pos; (j >= 0) && (strcmp(stack[j], tag)); --j)
2650 os << "</" << stack[j] << ">";
2653 os << "</" << tag << ">";
2655 // push all tags, but the specified one
2656 for (j = j + 1; j <= pos; ++j) {
2657 os << "<" << stack[j] << ">";
2658 strcpy(stack[j-1], stack[j]);
2664 // Handle internal paragraph parsing -- layout already processed.
2666 // checks, if newcol chars should be put into this line
2667 // writes newline, if necessary.
2669 void linux_doc_line_break(ostream & os, unsigned int & colcount,
2670 const unsigned int newcol)
2673 if (colcount > lyxrc.ascii_linelen) {
2675 colcount = newcol; // assume write after this call
2680 void Buffer::SimpleLinuxDocOnePar(ostream & os, LyXParagraph * par,
2681 int desc_on, int const /*depth*/)
2683 LyXFont font1, font2;
2686 LyXParagraph::size_type main_body;
2688 LyXLayout const & style = textclasslist.Style(params.textclass,
2691 char family_type = 0; // family font flag
2692 bool is_bold = false; // series font flag
2693 char shape_type = 0; // shape font flag
2694 bool is_em = false; // emphasis (italic) font flag
2696 int stack_num = -1; // style stack position
2697 // Can this be rewritten to use a std::stack, please. (Lgb)
2698 char stack[5][3]; // style stack
2699 unsigned int char_line_count = 5; // Heuristic choice ;-)
2701 if (style.labeltype != LABEL_MANUAL)
2704 main_body = par->BeginningOfMainBody();
2706 // gets paragraph main font
2708 font1 = style.labelfont;
2713 // parsing main loop
2714 for (LyXParagraph::size_type i = 0;
2715 i < par->size(); ++i) {
2727 font2 = par->getFont(params, i);
2729 if (font1.family() != font2.family()) {
2730 switch(family_type) {
2732 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2733 push_tag(os, "tt", stack_num, stack);
2736 else if (font2.family() == LyXFont::SANS_FAMILY) {
2737 push_tag(os, "sf", stack_num, stack);
2742 pop_tag(os, "tt", stack_num, stack);
2743 if (font2.family() == LyXFont::SANS_FAMILY) {
2744 push_tag(os, "sf", stack_num, stack);
2751 pop_tag(os, "sf", stack_num, stack);
2752 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2753 push_tag(os, "tt", stack_num, stack);
2762 if (font1.series() != font2.series()) {
2763 if (font2.series() == LyXFont::BOLD_SERIES) {
2764 push_tag(os, "bf", stack_num, stack);
2766 } else if (is_bold) {
2767 pop_tag(os, "bf", stack_num, stack);
2772 // handle italic and slanted fonts
2773 if (font1.shape() != font2.shape()) {
2774 switch(shape_type) {
2776 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2777 push_tag(os, "it", stack_num, stack);
2779 } else if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2780 push_tag(os, "sl", stack_num, stack);
2785 pop_tag(os, "it", stack_num, stack);
2786 if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2787 push_tag(os, "sl", stack_num, stack);
2794 pop_tag(os, "sl", stack_num, stack);
2795 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2796 push_tag(os, "it", stack_num, stack);
2804 if (font1.emph() != font2.emph()) {
2805 if (font2.emph() == LyXFont::ON) {
2806 push_tag(os, "em", stack_num, stack);
2809 pop_tag(os, "em", stack_num, stack);
2814 c = par->GetChar(i);
2816 if (c == LyXParagraph::META_INSET) {
2817 inset = par->GetInset(i);
2818 inset->Linuxdoc(this, os);
2821 if (font2.latex() == LyXFont::ON) {
2822 // "TeX"-Mode on == > SGML-Mode on.
2824 os << c; // see LaTeX-Generation...
2828 if (par->linuxDocConvertChar(c, sgml_string)
2829 && !style.free_spacing) { // in freespacing
2831 // non-breaking characters
2835 linux_doc_line_break(os, char_line_count, 6);
2839 linux_doc_line_break(os, char_line_count, 1);
2844 char_line_count += sgml_string.length();
2850 // needed if there is an optional argument but no contents
2851 if (main_body > 0 && main_body == par->size()) {
2855 // pop all defined Styles
2856 for (j = stack_num; j >= 0; --j) {
2857 linux_doc_line_break(os,
2859 3 + strlen(stack[j]));
2860 os << "</" << stack[j] << ">";
2863 // resets description flag correctly
2866 // <tag> not closed...
2867 linux_doc_line_break(os, char_line_count, 6);
2871 // fprintf(file, "</p>");
2877 // Print an error message.
2878 void Buffer::LinuxDocError(LyXParagraph * par, int pos,
2879 char const * message)
2881 // insert an error marker in text
2882 InsetError * new_inset = new InsetError(message);
2883 par->InsertInset(pos, new_inset);
2886 // This constant defines the maximum number of
2887 // environment layouts that can be nesteded.
2888 // The same applies for command layouts.
2889 // These values should be more than enough.
2890 // José Matos (1999/07/22)
2892 enum { MAX_NEST_LEVEL = 25};
2894 void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
2896 LyXParagraph * par = paragraph;
2898 niceFile = nice; // this will be used by Insetincludes.
2900 string top_element= textclasslist.LatexnameOfClass(params.textclass);
2901 // Please use a real stack.
2902 string environment_stack[MAX_NEST_LEVEL];
2903 string environment_inner[MAX_NEST_LEVEL];
2904 // Please use a real stack.
2905 string command_stack[MAX_NEST_LEVEL];
2906 bool command_flag= false;
2907 int command_depth= 0, command_base= 0, cmd_depth= 0;
2909 string item_name, command_name;
2910 string c_depth, c_params, tmps;
2912 int depth = 0; // paragraph depth
2913 LyXTextClass const & tclass =
2914 textclasslist.TextClass(params.textclass);
2916 LaTeXFeatures features(params, tclass.numLayouts());
2920 tex_code_break_column = lyxrc.ascii_linelen;
2922 //tex_code_break_column = 0;
2924 ofstream ofs(fname.c_str());
2926 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2933 string sgml_includedfiles=features.getIncludedFiles();
2935 ofs << "<!doctype " << top_element
2936 << " public \"-//OASIS//DTD DocBook V3.1//EN\"";
2938 if (params.preamble.empty() && sgml_includedfiles.empty())
2941 ofs << "\n [ " << params.preamble
2942 << sgml_includedfiles << " \n]>\n\n";
2944 if(params.options.empty())
2945 sgmlOpenTag(ofs, 0, top_element);
2947 string top = top_element;
2949 top += params.options;
2950 sgmlOpenTag(ofs, 0, top);
2954 ofs << "<!-- DocBook file was created by " << LYX_DOCVERSION
2955 << "\n See http://www.lyx.org/ for more information -->\n";
2958 int desc_on = 0; // description mode
2959 LyXLayout const & style =
2960 textclasslist.Style(params.textclass,
2963 // environment tag closing
2964 for( ; depth > par->depth; --depth) {
2965 if(environment_inner[depth] != "!-- --") {
2966 item_name= "listitem";
2967 sgmlCloseTag(ofs, command_depth + depth,
2969 if( environment_inner[depth] == "varlistentry")
2970 sgmlCloseTag(ofs, depth+command_depth,
2971 environment_inner[depth]);
2973 sgmlCloseTag(ofs, depth + command_depth,
2974 environment_stack[depth]);
2975 environment_stack[depth].erase();
2976 environment_inner[depth].erase();
2979 if(depth == par->depth
2980 && environment_stack[depth] != style.latexname()
2981 && !environment_stack[depth].empty()) {
2982 if(environment_inner[depth] != "!-- --") {
2983 item_name= "listitem";
2984 sgmlCloseTag(ofs, command_depth+depth,
2986 if( environment_inner[depth] == "varlistentry")
2988 depth + command_depth,
2989 environment_inner[depth]);
2992 sgmlCloseTag(ofs, depth + command_depth,
2993 environment_stack[depth]);
2995 environment_stack[depth].erase();
2996 environment_inner[depth].erase();
2999 // Write opening SGML tags.
3000 switch(style.latextype) {
3001 case LATEX_PARAGRAPH:
3002 if(style.latexname() != "dummy")
3003 sgmlOpenTag(ofs, depth+command_depth,
3009 LinuxDocError(par, 0,
3010 _("Error : Wrong depth for "
3011 "LatexType Command.\n"));
3013 command_name = style.latexname();
3015 tmps = style.latexparam();
3016 c_params = split(tmps, c_depth,'|');
3018 cmd_depth= atoi(c_depth.c_str());
3021 if(cmd_depth<command_base) {
3022 for(int j = command_depth;
3023 j >= command_base; --j)
3024 if(!command_stack[j].empty())
3025 sgmlCloseTag(ofs, j, command_stack[j]);
3026 command_depth= command_base= cmd_depth;
3027 } else if(cmd_depth <= command_depth) {
3028 for(int j = command_depth;
3029 j >= cmd_depth; --j)
3031 if(!command_stack[j].empty())
3032 sgmlCloseTag(ofs, j, command_stack[j]);
3033 command_depth= cmd_depth;
3035 command_depth= cmd_depth;
3037 command_depth = command_base = cmd_depth;
3038 command_flag = true;
3040 command_stack[command_depth]= command_name;
3042 // treat label as a special case for
3043 // more WYSIWYM handling.
3044 if (par->GetChar(0) == LyXParagraph::META_INSET) {
3045 Inset * inset = par->GetInset(0);
3046 Inset::Code lyx_code = inset->LyxCode();
3047 if (lyx_code == Inset::LABEL_CODE){
3048 command_name += " id=\"";
3049 command_name += (static_cast<InsetCommand *>(inset))->getContents();
3050 command_name += "\"";
3055 sgmlOpenTag(ofs, depth + command_depth, command_name);
3056 item_name = "title";
3057 sgmlOpenTag(ofs, depth + 1 + command_depth, item_name);
3060 case LATEX_ENVIRONMENT:
3061 case LATEX_ITEM_ENVIRONMENT:
3062 if (depth < par->depth) {
3064 environment_stack[depth].erase();
3067 if (environment_stack[depth] != style.latexname()) {
3068 environment_stack[depth] = style.latexname();
3069 environment_inner[depth] = "!-- --";
3070 sgmlOpenTag(ofs, depth + command_depth,
3071 environment_stack[depth]);
3073 if(environment_inner[depth] != "!-- --") {
3074 item_name= "listitem";
3076 command_depth + depth,
3078 if (environment_inner[depth] == "varlistentry")
3080 depth + command_depth,
3081 environment_inner[depth]);
3085 if(style.latextype == LATEX_ENVIRONMENT) {
3086 if(!style.latexparam().empty())
3087 sgmlOpenTag(ofs, depth + command_depth,
3088 style.latexparam());
3092 desc_on = (style.labeltype == LABEL_MANUAL);
3095 environment_inner[depth]= "varlistentry";
3097 environment_inner[depth]= "listitem";
3099 sgmlOpenTag(ofs, depth + 1 + command_depth,
3100 environment_inner[depth]);
3104 sgmlOpenTag(ofs, depth + 1 + command_depth,
3108 sgmlOpenTag(ofs, depth + 1 + command_depth,
3113 sgmlOpenTag(ofs, depth + command_depth,
3122 SimpleDocBookOnePar(ofs, extra_par, par, desc_on,
3123 depth + 1 + command_depth);
3126 DocBookHandleFootnote(ofs, par,
3127 depth + 1 + command_depth);
3129 while(par && par->IsDummy());
3132 // write closing SGML tags
3133 switch(style.latextype) {
3136 sgmlCloseTag(ofs, depth + command_depth, end_tag);
3138 case LATEX_ENVIRONMENT:
3139 if(!style.latexparam().empty())
3140 sgmlCloseTag(ofs, depth + command_depth,
3141 style.latexparam());
3143 case LATEX_ITEM_ENVIRONMENT:
3144 if(desc_on == 1) break;
3146 sgmlCloseTag(ofs, depth + 1 + command_depth, end_tag);
3148 case LATEX_PARAGRAPH:
3149 if(style.latexname() != "dummy")
3150 sgmlCloseTag(ofs, depth + command_depth,
3154 sgmlCloseTag(ofs, depth + command_depth,
3161 for(; depth >= 0; --depth) {
3162 if(!environment_stack[depth].empty()) {
3163 if(environment_inner[depth] != "!-- --") {
3164 item_name= "listitem";
3165 sgmlCloseTag(ofs, command_depth + depth,
3167 if( environment_inner[depth] == "varlistentry")
3168 sgmlCloseTag(ofs, depth + command_depth,
3169 environment_inner[depth]);
3172 sgmlCloseTag(ofs, depth + command_depth,
3173 environment_stack[depth]);
3177 for(int j = command_depth; j >= command_base; --j)
3178 if(!command_stack[j].empty())
3179 sgmlCloseTag(ofs, j, command_stack[j]);
3183 sgmlCloseTag(ofs, 0, top_element);
3187 // How to check for successful close
3191 void Buffer::SimpleDocBookOnePar(ostream & os, string & extra,
3192 LyXParagraph * par, int & desc_on,
3197 par->SimpleDocBookOneTablePar(this,
3198 os, extra, desc_on, depth);
3203 bool emph_flag = false;
3205 LyXLayout const & style = textclasslist.Style(params.textclass,
3208 LyXParagraph::size_type main_body;
3209 if (style.labeltype != LABEL_MANUAL)
3212 main_body = par->BeginningOfMainBody();
3214 // gets paragraph main font
3215 LyXFont font1 = main_body > 0 ? style.labelfont : style.font;
3217 int char_line_count = depth;
3218 if(!style.free_spacing)
3219 for (int j = 0; j < depth; ++j)
3222 // parsing main loop
3223 for (LyXParagraph::size_type i = 0;
3224 i < par->size(); ++i) {
3225 LyXFont font2 = par->getFont(params, i);
3227 // handle <emphasis> tag
3228 if (font1.emph() != font2.emph() && i) {
3229 if (font2.emph() == LyXFont::ON) {
3233 os << "</emphasis>";
3238 char c = par->GetChar(i);
3240 if (c == LyXParagraph::META_INSET) {
3241 Inset * inset = par->GetInset(i);
3243 std::ostringstream ost;
3244 inset->DocBook(this, ost);
3245 string tmp_out = ost.str().c_str();
3248 inset->DocBook(this, ost);
3250 char * ctmp = ost.str();
3251 string tmp_out(ctmp);
3255 // This code needs some explanation:
3256 // Two insets are treated specially
3257 // label if it is the first element in a command paragraph
3259 // graphics inside tables or figure floats can't go on
3260 // title (the equivalente in latex for this case is caption
3261 // and title should come first
3264 if(desc_on!= 3 || i!= 0) {
3265 if(!tmp_out.empty() && tmp_out[0] == '@') {
3267 extra += frontStrip(tmp_out, '@');
3269 os << frontStrip(tmp_out, '@');
3274 } else if (font2.latex() == LyXFont::ON) {
3275 // "TeX"-Mode on ==> SGML-Mode on.
3281 if (par->linuxDocConvertChar(c, sgml_string)
3282 && !style.free_spacing) { // in freespacing
3284 // non-breaking characters
3288 os << "\n</term><listitem><para>";
3300 // needed if there is an optional argument but no contents
3301 if (main_body > 0 && main_body == par->size()) {
3305 os << "</emphasis>";
3308 // resets description flag correctly
3311 // <term> not closed...
3319 int Buffer::runLaTeX()
3321 if (!users->text) return 0;
3323 ProhibitInput(users);
3325 // get LaTeX-Filename
3326 string name = getLatexName();
3328 string path = OnlyPath(filename);
3330 string org_path = path;
3331 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3335 Path p(path); // path to LaTeX file
3336 users->owner()->getMiniBuffer()->Set(_("Running LaTeX..."));
3338 // Remove all error insets
3339 bool a = users->removeAutoInsets();
3341 // Always generate the LaTeX file
3342 makeLaTeXFile(name, org_path, false);
3344 // do the LaTex run(s)
3346 string latex_command = lyxrc.pdf_mode ?
3347 lyxrc.pdflatex_command : lyxrc.latex_command;
3348 LaTeX latex(latex_command, name, filepath);
3349 int res = latex.run(terr,
3350 users->owner()->getMiniBuffer()); // running latex
3352 // check return value from latex.run().
3353 if ((res & LaTeX::NO_LOGFILE)) {
3354 WriteAlert(_("LaTeX did not work!"),
3355 _("Missing log file:"), name);
3356 } else if ((res & LaTeX::ERRORS)) {
3357 users->owner()->getMiniBuffer()->Set(_("Done"));
3358 // Insert all errors as errors boxes
3359 users->insertErrors(terr);
3361 // Dvi should also be kept dirty if the latex run
3362 // ends up with errors. However it should be possible
3363 // to view a dirty dvi too.
3365 //no errors or any other things to think about so:
3366 users->owner()->getMiniBuffer()->Set(_("Done"));
3369 // if we removed error insets before we ran LaTeX or if we inserted
3370 // error insets after we ran LaTeX this must be run:
3371 if (a || (res & LaTeX::ERRORS)){
3374 //users->updateScrollbar();
3378 return latex.getNumErrors();
3382 int Buffer::runLiterate()
3384 if (!users->text) return 0;
3386 ProhibitInput(users);
3388 // get LaTeX-Filename
3389 string name = getLatexName();
3390 // get Literate-Filename
3391 string lit_name = OnlyFilename(ChangeExtension (getLatexName(),
3392 lyxrc.literate_extension));
3394 string path = OnlyPath(filename);
3396 string org_path = path;
3397 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3401 Path p(path); // path to Literate file
3402 users->owner()->getMiniBuffer()->Set(_("Running Literate..."));
3404 // Remove all error insets
3405 bool removedErrorInsets = users->removeAutoInsets();
3407 // generate the Literate file if necessary
3408 makeLaTeXFile(lit_name, org_path, false);
3410 string latex_command = lyxrc.pdf_mode ?
3411 lyxrc.pdflatex_command : lyxrc.latex_command;
3412 Literate literate(latex_command, name, filepath,
3414 lyxrc.literate_command, lyxrc.literate_error_filter,
3415 lyxrc.build_command, lyxrc.build_error_filter);
3417 int res = literate.weave(terr, users->owner()->getMiniBuffer());
3419 // check return value from literate.weave().
3420 if ((res & Literate::NO_LOGFILE)) {
3421 WriteAlert(_("Literate command did not work!"),
3422 _("Missing log file:"), name);
3423 } else if ((res & Literate::ERRORS)) {
3424 users->owner()->getMiniBuffer()->Set(_("Done"));
3425 // Insert all errors as errors boxes
3426 users->insertErrors(terr);
3428 // Dvi should also be kept dirty if the latex run
3429 // ends up with errors. However it should be possible
3430 // to view a dirty dvi too.
3432 //no errors or any other things to think about so:
3433 users->owner()->getMiniBuffer()->Set(_("Done"));
3436 // if we removed error insets before we ran LaTeX or if we inserted
3437 // error insets after we ran LaTeX this must be run:
3438 if (removedErrorInsets || (res & Literate::ERRORS)){
3441 //users->updateScrollbar();
3445 return literate.getNumErrors();
3449 int Buffer::buildProgram()
3451 if (!users->text) return 0;
3453 ProhibitInput(users);
3455 // get LaTeX-Filename
3456 string name = getLatexName();
3457 // get Literate-Filename
3458 string lit_name = OnlyFilename(ChangeExtension(getLatexName(),
3459 lyxrc.literate_extension));
3461 string path = OnlyPath(filename);
3463 string org_path = path;
3464 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3468 Path p(path); // path to Literate file
3469 users->owner()->getMiniBuffer()->Set(_("Building Program..."));
3471 // Remove all error insets
3472 bool removedErrorInsets = users->removeAutoInsets();
3474 // generate the LaTeX file if necessary
3475 if (!isNwClean() || removedErrorInsets) {
3476 makeLaTeXFile(lit_name, org_path, false);
3480 string latex_command = lyxrc.pdf_mode ?
3481 lyxrc.pdflatex_command : lyxrc.latex_command;
3482 Literate literate(latex_command, name, filepath,
3484 lyxrc.literate_command, lyxrc.literate_error_filter,
3485 lyxrc.build_command, lyxrc.build_error_filter);
3487 int res = literate.build(terr, users->owner()->getMiniBuffer());
3489 // check return value from literate.build().
3490 if ((res & Literate::NO_LOGFILE)) {
3491 WriteAlert(_("Build did not work!"),
3492 _("Missing log file:"), name);
3493 } else if ((res & Literate::ERRORS)) {
3494 users->owner()->getMiniBuffer()->Set(_("Done"));
3495 // Insert all errors as errors boxes
3496 users->insertErrors(terr);
3498 // Literate files should also be kept dirty if the literate
3499 // command run ends up with errors.
3501 //no errors or any other things to think about so:
3502 users->owner()->getMiniBuffer()->Set(_("Done"));
3506 // if we removed error insets before we ran Literate/Build or
3507 // if we inserted error insets after we ran Literate/Build this
3509 if (removedErrorInsets || (res & Literate::ERRORS)){
3512 //users->updateScrollbar();
3516 return literate.getNumErrors();
3520 // This should be enabled when the Chktex class is implemented. (Asger)
3521 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
3522 // Other flags: -wall -v0 -x
3523 int Buffer::runChktex()
3525 if (!users->text) return 0;
3527 ProhibitInput(users);
3529 // get LaTeX-Filename
3530 string name = getLatexName();
3531 string path = OnlyPath(filename);
3533 string org_path = path;
3534 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3538 Path p(path); // path to LaTeX file
3539 users->owner()->getMiniBuffer()->Set(_("Running chktex..."));
3541 // Remove all error insets
3542 bool removedErrorInsets = users->removeAutoInsets();
3544 // Generate the LaTeX file if neccessary
3545 makeLaTeXFile(name, org_path, false);
3548 Chktex chktex(lyxrc.chktex_command, name, filepath);
3549 int res = chktex.run(terr); // run chktex
3552 WriteAlert(_("chktex did not work!"),
3553 _("Could not run with file:"), name);
3554 } else if (res > 0) {
3555 // Insert all errors as errors boxes
3556 users->insertErrors(terr);
3559 // if we removed error insets before we ran chktex or if we inserted
3560 // error insets after we ran chktex, this must be run:
3561 if (removedErrorInsets || res){
3564 //users->updateScrollbar();
3572 void Buffer::validate(LaTeXFeatures & features) const
3574 LyXParagraph * par = paragraph;
3575 LyXTextClass const & tclass =
3576 textclasslist.TextClass(params.textclass);
3578 // AMS Style is at document level
3580 features.amsstyle = (params.use_amsmath ||
3581 tclass.provides(LyXTextClass::amsmath));
3584 // We don't use "lyxerr.debug" because of speed. (Asger)
3585 if (lyxerr.debugging(Debug::LATEX))
3586 lyxerr << "Paragraph: " << par << endl;
3588 // Now just follow the list of paragraphs and run
3589 // validate on each of them.
3590 par->validate(features);
3592 // and then the next paragraph
3596 // the bullet shapes are buffer level not paragraph level
3597 // so they are tested here
3598 for (int i = 0; i < 4; ++i) {
3599 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
3600 int font = params.user_defined_bullets[i].getFont();
3603 .user_defined_bullets[i]
3610 features.latexsym = true;
3614 features.amssymb = true;
3616 else if ((font >= 2 && font <= 5)) {
3617 features.pifont = true;
3622 if (lyxerr.debugging(Debug::LATEX)) {
3623 features.showStruct();
3628 void Buffer::setPaperStuff()
3630 params.papersize = BufferParams::PAPER_DEFAULT;
3631 char c1 = params.paperpackage;
3632 if (c1 == BufferParams::PACKAGE_NONE) {
3633 char c2 = params.papersize2;
3634 if (c2 == BufferParams::VM_PAPER_USLETTER)
3635 params.papersize = BufferParams::PAPER_USLETTER;
3636 else if (c2 == BufferParams::VM_PAPER_USLEGAL)
3637 params.papersize = BufferParams::PAPER_LEGALPAPER;
3638 else if (c2 == BufferParams::VM_PAPER_USEXECUTIVE)
3639 params.papersize = BufferParams::PAPER_EXECUTIVEPAPER;
3640 else if (c2 == BufferParams::VM_PAPER_A3)
3641 params.papersize = BufferParams::PAPER_A3PAPER;
3642 else if (c2 == BufferParams::VM_PAPER_A4)
3643 params.papersize = BufferParams::PAPER_A4PAPER;
3644 else if (c2 == BufferParams::VM_PAPER_A5)
3645 params.papersize = BufferParams::PAPER_A5PAPER;
3646 else if ((c2 == BufferParams::VM_PAPER_B3) || (c2 == BufferParams::VM_PAPER_B4) ||
3647 (c2 == BufferParams::VM_PAPER_B5))
3648 params.papersize = BufferParams::PAPER_B5PAPER;
3649 } else if ((c1 == BufferParams::PACKAGE_A4) || (c1 == BufferParams::PACKAGE_A4WIDE) ||
3650 (c1 == BufferParams::PACKAGE_WIDEMARGINSA4))
3651 params.papersize = BufferParams::PAPER_A4PAPER;
3655 // This function should be in Buffer because it's a buffer's property (ale)
3656 string Buffer::getIncludeonlyList(char delim)
3659 for (inset_iterator it = inset_iterator_begin();
3660 it != inset_iterator_end(); ++it) {
3661 if ((*it)->LyxCode() == Inset::INCLUDE_CODE) {
3662 InsetInclude * insetinc =
3663 static_cast<InsetInclude *>(*it);
3664 if (insetinc->isInclude()
3665 && insetinc->isNoLoad()) {
3668 lst += OnlyFilename(ChangeExtension(insetinc->getContents(), string()));
3672 lyxerr.debug() << "Includeonly(" << lst << ')' << endl;
3677 vector<string> Buffer::getLabelList()
3679 /// if this is a child document and the parent is already loaded
3680 /// Use the parent's list instead [ale990407]
3681 if (!params.parentname.empty()
3682 && bufferlist.exists(params.parentname)) {
3683 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3685 return tmp->getLabelList();
3688 vector<string> label_list;
3689 for (inset_iterator it = inset_iterator_begin();
3690 it != inset_iterator_end(); ++it) {
3691 vector<string> l = (*it)->getLabelList();
3692 label_list.insert(label_list.end(), l.begin(), l.end());
3698 vector<vector<Buffer::TocItem> > Buffer::getTocList()
3700 vector<vector<TocItem> > l(4);
3701 LyXParagraph * par = paragraph;
3704 if (par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
3705 if (textclasslist.Style(params.textclass,
3706 par->GetLayout()).labeltype
3707 == LABEL_SENSITIVE) {
3711 tmp.str = par->String(this, false);
3712 switch (par->footnotekind) {
3713 case LyXParagraph::FIG:
3714 case LyXParagraph::WIDE_FIG:
3715 l[TOC_LOF].push_back(tmp);
3717 case LyXParagraph::TAB:
3718 case LyXParagraph::WIDE_TAB:
3719 l[TOC_LOT].push_back(tmp);
3721 case LyXParagraph::ALGORITHM:
3722 l[TOC_LOA].push_back(tmp);
3724 case LyXParagraph::FOOTNOTE:
3725 case LyXParagraph::MARGIN:
3729 } else if (!par->IsDummy()) {
3731 char labeltype = textclasslist.Style(params.textclass,
3732 par->GetLayout()).labeltype;
3734 if (labeltype >= LABEL_COUNTER_CHAPTER
3735 && labeltype <= LABEL_COUNTER_CHAPTER + params.tocdepth) {
3736 // insert this into the table of contents
3741 textclasslist.TextClass(params.textclass).maxcounter());
3742 tmp.str = par->String(this, true);
3743 l[TOC_TOC].push_back(tmp);
3753 // This is also a buffer property (ale)
3754 vector<pair<string,string> > Buffer::getBibkeyList()
3756 /// if this is a child document and the parent is already loaded
3757 /// Use the parent's list instead [ale990412]
3758 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3759 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3761 return tmp->getBibkeyList();
3764 vector<pair<string, string> > keys;
3765 LyXParagraph * par = paragraph;
3768 keys.push_back(pair<string, string>(par->bibkey->getContents(),
3769 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();
3781 keys.insert(keys.end(), tmp.begin(), tmp.end());
3782 } else if ((*it)->LyxCode() == Inset::INCLUDE_CODE) {
3783 vector<pair<string,string> > 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
3830 string cmd, line = frontStrip(command);
3831 string arg = strip(frontStrip(split(line, cmd, ' ')));
3833 return Dispatch(lyxaction.LookupFunc(cmd.c_str()), arg.c_str());
3837 bool Buffer::Dispatch(int action, string const & argument)
3839 bool dispatched = true;
3842 MenuExport(this, argument);
3852 void Buffer::resize()
3854 /// resize the BufferViews!
3860 void Buffer::resizeInsets(BufferView * bv)
3862 /// then remove all LyXText in text-insets
3863 LyXParagraph * par = paragraph;
3864 for(;par;par = par->next) {
3865 par->resizeInsetsLyXText(bv);
3869 void Buffer::ChangeLanguage(Language const * from, Language const * to)
3872 LyXParagraph * par = paragraph;
3874 par->ChangeLanguage(params, from, to);
3880 bool Buffer::isMultiLingual()
3883 LyXParagraph * par = paragraph;
3885 if (par->isMultiLingual(params))
3893 Buffer::inset_iterator::inset_iterator(LyXParagraph * paragraph,
3894 LyXParagraph::size_type pos)
3896 it = par->InsetIterator(pos);
3897 if (it == par->inset_iterator_end()) {
3904 void Buffer::inset_iterator::SetParagraph() {
3906 it = par->inset_iterator_begin();
3907 if (it != par->inset_iterator_end())
3912 // We maintain an invariant that whenever par = 0 then it = 0