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"
104 using std::istringstream;
107 // all these externs should eventually be removed.
108 extern BufferList bufferlist;
111 extern void MenuExport(Buffer *, string const &);
113 extern LyXAction lyxaction;
116 static const float LYX_FORMAT = 2.17;
118 extern int tex_code_break_column;
121 Buffer::Buffer(string const & file, bool ronly)
123 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
125 filepath = OnlyPath(file);
134 if (read_only || (lyxrc.use_tempdir)) {
135 tmppath = CreateBufferTmpDir();
136 } else tmppath.erase();
142 lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
143 // here the buffer should take care that it is
144 // saved properly, before it goes into the void.
146 // make sure that views using this buffer
151 if (!tmppath.empty()) {
152 DestroyBufferTmpDir(tmppath);
155 LyXParagraph * par = paragraph;
156 LyXParagraph * tmppar;
166 string Buffer::getLatexName(bool no_path) const
169 return OnlyFilename(ChangeExtension(MakeLatexName(filename),
172 return ChangeExtension(MakeLatexName(filename),
177 void Buffer::setReadonly(bool flag)
179 if (read_only != flag) {
182 users->owner()->getDialogs()->updateBufferDependent();
185 WarnReadonly(filename);
190 bool Buffer::saveParamsAsDefaults()
192 string fname = AddName(AddPath(user_lyxdir, "templates/"),
194 Buffer defaults = Buffer(fname);
196 // Use the current buffer's parameters as default
197 defaults.params = params;
199 // add an empty paragraph. Is this enough?
200 defaults.paragraph = new LyXParagraph;
202 return defaults.writeFile(defaults.filename, false);
206 /// Update window titles of all users
207 // Should work on a list
208 void Buffer::updateTitles() const
210 if (users) users->owner()->updateWindowTitle();
214 /// Reset autosave timer of all users
215 // Should work on a list
216 void Buffer::resetAutosaveTimers() const
218 if (users) users->owner()->resetAutosaveTimer();
222 void Buffer::fileName(string const & newfile)
224 filename = MakeAbsPath(newfile);
225 filepath = OnlyPath(filename);
226 setReadonly(IsFileWriteable(filename) == 0);
231 // candidate for move to BufferView
232 // (at least some parts in the beginning of the func)
235 // changed to be public and have one parameter
236 // if par = 0 normal behavior
237 // else insert behavior
238 // Returns false if "\the_end" is not read for formats >= 2.13. (Asger)
239 bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par)
243 char depth = 0; // signed or unsigned?
245 LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
246 LyXParagraph::footnote_kind footnotekind = LyXParagraph::FOOTNOTE;
248 bool the_end_read = false;
250 LyXParagraph * return_par = 0;
251 LyXFont font(LyXFont::ALL_INHERIT, params.language_info);
252 if (format < 2.16 && params.language == "hebrew")
253 font.setLanguage(default_language);
255 // If we are inserting, we cheat and get a token in advance
256 bool has_token = false;
260 par = new LyXParagraph;
262 users->text->BreakParagraph(users);
263 return_par = users->text->FirstParagraph();
266 // We don't want to adopt the parameters from the
267 // document we insert, so we skip until the text begins:
270 pretoken = lex.GetString();
271 if (pretoken == "\\layout") {
283 pretoken = lex.GetString();
286 // Profiling show this should give a lot: (Asger)
287 string const token = pretoken;
291 the_end_read = parseSingleLyXformat2Token(lex, par, return_par,
304 paragraph = return_par;
310 // We'll remove this later. (Lgb)
311 static string last_inset_read;
315 Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
316 LyXParagraph *& return_par,
317 string const & token, int & pos,
318 char & depth, LyXFont & font
320 , LyXParagraph::footnote_flag & footnoteflag,
321 LyXParagraph::footnote_kind & footnotekind
325 bool the_end_read = false;
327 if (token[0] != '\\') {
328 for (string::const_iterator cit = token.begin();
329 cit != token.end(); ++cit) {
330 par->InsertChar(pos, (*cit), font);
333 } else if (token == "\\i") {
334 Inset * inset = new InsetLatexAccent;
335 inset->Read(this, lex);
336 par->InsertInset(pos, inset, font);
338 } else if (token == "\\layout") {
343 par = new LyXParagraph(par);
347 string layoutname = lex.GetString();
348 pair<bool, LyXTextClass::LayoutList::size_type> pp
349 = textclasslist.NumberOfLayout(params.textclass,
352 par->layout = pp.second;
353 } else { // layout not found
354 // use default layout "Standard" (0)
357 // Test whether the layout is obsolete.
358 LyXLayout const & layout =
359 textclasslist.Style(params.textclass,
361 if (!layout.obsoleted_by().empty())
363 textclasslist.NumberOfLayout(params.textclass,
364 layout.obsoleted_by()).second;
366 par->footnoteflag = footnoteflag;
367 par->footnotekind = footnotekind;
370 font = LyXFont(LyXFont::ALL_INHERIT, params.language_info);
371 if (format < 2.16 && params.language == "hebrew")
372 font.setLanguage(default_language);
374 } else if (token == "\\end_float") {
379 par = new LyXParagraph(par);
381 footnotekind = LyXParagraph::FOOTNOTE;
382 footnoteflag = LyXParagraph::NO_FOOTNOTE;
385 par->layout = LYX_DUMMY_LAYOUT;
386 font = LyXFont(LyXFont::ALL_INHERIT, params.language_info);
387 if (format < 2.16 && params.language == "hebrew")
388 font.setLanguage(default_language);
389 } else if (token == "\\begin_float") {
390 int tmpret = lex.FindToken(string_footnotekinds);
391 if (tmpret == -1) ++tmpret;
392 if (tmpret != LYX_LAYOUT_DEFAULT)
393 footnotekind = static_cast<LyXParagraph::footnote_kind>(tmpret); // bad
394 if (footnotekind == LyXParagraph::FOOTNOTE
395 || footnotekind == LyXParagraph::MARGIN)
396 footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
398 footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
400 } else if (token == "\\begin_float") {
401 // This is the compability reader, unfinished but tested.
404 string tmptok = lex.GetString();
405 //lyxerr << "old float: " << tmptok << endl;
410 if (tmptok == "footnote") {
411 inset = new InsetFoot;
412 } else if (tmptok == "margin") {
413 inset = new InsetMarginal;
414 } else if (tmptok == "fig") {
415 inset = new InsetFloat("figure");
416 old_float += "placement htbp\n";
417 } else if (tmptok == "tab") {
418 inset = new InsetFloat("table");
419 old_float += "placement htbp\n";
420 } else if (tmptok == "alg") {
421 inset = new InsetFloat("algorithm");
422 old_float += "placement htbp\n";
423 } else if (tmptok == "wide-fig") {
424 InsetFloat * tmp = new InsetFloat("figure");
427 old_float += "placement htbp\n";
428 } else if (tmptok == "wide-tab") {
429 InsetFloat * tmp = new InsetFloat("table");
432 old_float += "placement htbp\n";
435 if (!inset) return false; // no end read yet
437 old_float += "collapsed true\n";
439 // Here we need to check for \end_deeper and handle that
440 // before we do the footnote parsing.
441 // This _is_ a hack! (Lgb)
444 string tmp = lex.GetString();
445 if (tmp == "\\end_deeper") {
446 lyxerr << "\\end_deeper caught!" << endl;
448 lex.printError("\\end_deeper: "
449 "depth is already null");
460 old_float += lex.getLongString("\\end_float");
461 old_float += "\n\\end_inset\n";
462 //lyxerr << "float body: " << old_float << endl;
465 istringstream istr(old_float);
467 istrstream istr(old_float.c_str());
471 nylex.setStream(istr);
473 inset->Read(this, nylex);
474 par->InsertInset(pos, inset, font);
477 } else if (token == "\\begin_deeper") {
479 } else if (token == "\\end_deeper") {
481 lex.printError("\\end_deeper: "
482 "depth is already null");
486 } else if (token == "\\begin_preamble") {
487 params.readPreamble(lex);
488 } else if (token == "\\textclass") {
490 pair<bool, LyXTextClassList::size_type> pp =
491 textclasslist.NumberOfClass(lex.GetString());
493 params.textclass = pp.second;
495 lex.printError("Unknown textclass `$$Token'");
496 params.textclass = 0;
498 if (!textclasslist.Load(params.textclass)) {
499 // if the textclass wasn't loaded properly
500 // we need to either substitute another
501 // or stop loading the file.
502 // I can substitute but I don't see how I can
503 // stop loading... ideas?? ARRae980418
504 WriteAlert(_("Textclass Loading Error!"),
505 string(_("Can't load textclass ")) +
506 textclasslist.NameOfClass(params.textclass),
507 _("-- substituting default"));
508 params.textclass = 0;
510 } else if (token == "\\options") {
512 params.options = lex.GetString();
513 } else if (token == "\\language") {
514 params.readLanguage(lex);
515 } else if (token == "\\fontencoding") {
517 } else if (token == "\\inputencoding") {
519 params.inputenc = lex.GetString();
520 } else if (token == "\\graphics") {
521 params.readGraphicsDriver(lex);
522 } else if (token == "\\fontscheme") {
524 params.fonts = lex.GetString();
525 } else if (token == "\\noindent") {
526 par->noindent = true;
527 } else if (token == "\\fill_top") {
528 par->added_space_top = VSpace(VSpace::VFILL);
529 } else if (token == "\\fill_bottom") {
530 par->added_space_bottom = VSpace(VSpace::VFILL);
531 } else if (token == "\\line_top") {
532 par->line_top = true;
533 } else if (token == "\\line_bottom") {
534 par->line_bottom = true;
535 } else if (token == "\\pagebreak_top") {
536 par->pagebreak_top = true;
537 } else if (token == "\\pagebreak_bottom") {
538 par->pagebreak_bottom = true;
539 } else if (token == "\\start_of_appendix") {
540 par->start_of_appendix = true;
541 } else if (token == "\\paragraph_separation") {
542 int tmpret = lex.FindToken(string_paragraph_separation);
543 if (tmpret == -1) ++tmpret;
544 if (tmpret != LYX_LAYOUT_DEFAULT)
545 params.paragraph_separation =
546 static_cast<BufferParams::PARSEP>(tmpret);
547 } else if (token == "\\defskip") {
549 params.defskip = VSpace(lex.GetString());
550 } else if (token == "\\epsfig") { // obsolete
551 // Indeed it is obsolete, but we HAVE to be backwards
552 // compatible until 0.14, because otherwise all figures
553 // in existing documents are irretrivably lost. (Asger)
554 params.readGraphicsDriver(lex);
555 } else if (token == "\\quotes_language") {
556 int tmpret = lex.FindToken(string_quotes_language);
557 if (tmpret == -1) ++tmpret;
558 if (tmpret != LYX_LAYOUT_DEFAULT) {
559 InsetQuotes::quote_language tmpl =
560 InsetQuotes::EnglishQ;
563 tmpl = InsetQuotes::EnglishQ;
566 tmpl = InsetQuotes::SwedishQ;
569 tmpl = InsetQuotes::GermanQ;
572 tmpl = InsetQuotes::PolishQ;
575 tmpl = InsetQuotes::FrenchQ;
578 tmpl = InsetQuotes::DanishQ;
581 params.quotes_language = tmpl;
583 } else if (token == "\\quotes_times") {
585 switch(lex.GetInteger()) {
587 params.quotes_times = InsetQuotes::SingleQ;
590 params.quotes_times = InsetQuotes::DoubleQ;
593 } else if (token == "\\papersize") {
594 int tmpret = lex.FindToken(string_papersize);
598 params.papersize2 = tmpret;
599 } else if (token == "\\paperpackage") {
600 int tmpret = lex.FindToken(string_paperpackages);
603 params.paperpackage = BufferParams::PACKAGE_NONE;
605 params.paperpackage = tmpret;
606 } else if (token == "\\use_geometry") {
608 params.use_geometry = lex.GetInteger();
609 } else if (token == "\\use_amsmath") {
611 params.use_amsmath = lex.GetInteger();
612 } else if (token == "\\paperorientation") {
613 int tmpret = lex.FindToken(string_orientation);
614 if (tmpret == -1) ++tmpret;
615 if (tmpret != LYX_LAYOUT_DEFAULT)
616 params.orientation = static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
617 } else if (token == "\\paperwidth") {
619 params.paperwidth = lex.GetString();
620 } else if (token == "\\paperheight") {
622 params.paperheight = lex.GetString();
623 } else if (token == "\\leftmargin") {
625 params.leftmargin = lex.GetString();
626 } else if (token == "\\topmargin") {
628 params.topmargin = lex.GetString();
629 } else if (token == "\\rightmargin") {
631 params.rightmargin = lex.GetString();
632 } else if (token == "\\bottommargin") {
634 params.bottommargin = lex.GetString();
635 } else if (token == "\\headheight") {
637 params.headheight = lex.GetString();
638 } else if (token == "\\headsep") {
640 params.headsep = lex.GetString();
641 } else if (token == "\\footskip") {
643 params.footskip = lex.GetString();
644 } else if (token == "\\paperfontsize") {
646 params.fontsize = strip(lex.GetString());
647 } else if (token == "\\papercolumns") {
649 params.columns = lex.GetInteger();
650 } else if (token == "\\papersides") {
652 switch(lex.GetInteger()) {
654 case 1: params.sides = LyXTextClass::OneSide; break;
655 case 2: params.sides = LyXTextClass::TwoSides; break;
657 } else if (token == "\\paperpagestyle") {
659 params.pagestyle = strip(lex.GetString());
660 } else if (token == "\\bullet") {
662 int index = lex.GetInteger();
664 int temp_int = lex.GetInteger();
665 params.user_defined_bullets[index].setFont(temp_int);
666 params.temp_bullets[index].setFont(temp_int);
668 temp_int = lex.GetInteger();
669 params.user_defined_bullets[index].setCharacter(temp_int);
670 params.temp_bullets[index].setCharacter(temp_int);
672 temp_int = lex.GetInteger();
673 params.user_defined_bullets[index].setSize(temp_int);
674 params.temp_bullets[index].setSize(temp_int);
676 string temp_str = lex.GetString();
677 if (temp_str != "\\end_bullet") {
678 // this element isn't really necessary for
679 // parsing but is easier for humans
680 // to understand bullets. Put it back and
681 // set a debug message?
682 lex.printError("\\end_bullet expected, got" + temp_str);
683 //how can I put it back?
685 } else if (token == "\\bulletLaTeX") {
687 int index = lex.GetInteger();
689 string temp_str = lex.GetString(), sum_str;
690 while (temp_str != "\\end_bullet") {
691 // this loop structure is needed when user
692 // enters an empty string since the first
693 // thing returned will be the \\end_bullet
695 // if the LaTeX entry has spaces. Each element
696 // therefore needs to be read in turn
699 temp_str = lex.GetString();
701 params.user_defined_bullets[index].setText(sum_str);
702 params.temp_bullets[index].setText(sum_str);
703 } else if (token == "\\secnumdepth") {
705 params.secnumdepth = lex.GetInteger();
706 } else if (token == "\\tocdepth") {
708 params.tocdepth = lex.GetInteger();
709 } else if (token == "\\spacing") {
711 string tmp = strip(lex.GetString());
712 Spacing::Space tmp_space = Spacing::Default;
714 if (tmp == "single") {
715 tmp_space = Spacing::Single;
716 } else if (tmp == "onehalf") {
717 tmp_space = Spacing::Onehalf;
718 } else if (tmp == "double") {
719 tmp_space = Spacing::Double;
720 } else if (tmp == "other") {
722 tmp_space = Spacing::Other;
723 tmp_val = lex.GetFloat();
725 lex.printError("Unknown spacing token: '$$Token'");
727 // Small hack so that files written with klyx will be
730 par->spacing.set(tmp_space, tmp_val);
732 params.spacing.set(tmp_space, tmp_val);
734 } else if (token == "\\paragraph_spacing") {
736 string tmp = strip(lex.GetString());
737 if (tmp == "single") {
738 par->spacing.set(Spacing::Single);
739 } else if (tmp == "onehalf") {
740 par->spacing.set(Spacing::Onehalf);
741 } else if (tmp == "double") {
742 par->spacing.set(Spacing::Double);
743 } else if (tmp == "other") {
745 par->spacing.set(Spacing::Other,
748 lex.printError("Unknown spacing token: '$$Token'");
750 } else if (token == "\\float_placement") {
752 params.float_placement = lex.GetString();
753 } else if (token == "\\family") {
755 font.setLyXFamily(lex.GetString());
756 } else if (token == "\\series") {
758 font.setLyXSeries(lex.GetString());
759 } else if (token == "\\shape") {
761 font.setLyXShape(lex.GetString());
762 } else if (token == "\\size") {
764 font.setLyXSize(lex.GetString());
765 } else if (token == "\\latex") {
767 string tok = lex.GetString();
768 // This is dirty, but gone with LyX3. (Asger)
769 if (tok == "no_latex")
770 font.setLatex(LyXFont::OFF);
771 else if (tok == "latex")
772 font.setLatex(LyXFont::ON);
773 else if (tok == "default")
774 font.setLatex(LyXFont::INHERIT);
776 lex.printError("Unknown LaTeX font flag "
778 } else if (token == "\\lang") {
780 string tok = lex.GetString();
781 Languages::iterator lit = languages.find(tok);
782 if (lit != languages.end()) {
783 font.setLanguage(&(*lit).second);
785 font.setLanguage(params.language_info);
786 lex.printError("Unknown language `$$Token'");
788 } else if (token == "\\emph") {
790 font.setEmph(font.setLyXMisc(lex.GetString()));
791 } else if (token == "\\bar") {
793 string tok = lex.GetString();
794 // This is dirty, but gone with LyX3. (Asger)
796 font.setUnderbar(LyXFont::ON);
797 else if (tok == "no")
798 font.setUnderbar(LyXFont::OFF);
799 else if (tok == "default")
800 font.setUnderbar(LyXFont::INHERIT);
802 lex.printError("Unknown bar font flag "
804 } else if (token == "\\noun") {
806 font.setNoun(font.setLyXMisc(lex.GetString()));
807 } else if (token == "\\color") {
809 font.setLyXColor(lex.GetString());
810 } else if (token == "\\align") {
811 int tmpret = lex.FindToken(string_align);
812 if (tmpret == -1) ++tmpret;
813 if (tmpret != LYX_LAYOUT_DEFAULT) { // tmpret != 99 ???
815 for (; tmpret > 0; --tmpret)
816 tmpret2 = tmpret2 * 2;
817 par->align = LyXAlignment(tmpret2);
819 } else if (token == "\\added_space_top") {
821 par->added_space_top = VSpace(lex.GetString());
822 } else if (token == "\\added_space_bottom") {
824 par->added_space_bottom = VSpace(lex.GetString());
825 } else if (token == "\\pextra_type") {
827 par->pextra_type = lex.GetInteger();
828 } else if (token == "\\pextra_width") {
830 par->pextra_width = lex.GetString();
831 } else if (token == "\\pextra_widthp") {
833 par->pextra_widthp = lex.GetString();
834 } else if (token == "\\pextra_alignment") {
836 par->pextra_alignment = lex.GetInteger();
837 } else if (token == "\\pextra_hfill") {
839 par->pextra_hfill = lex.GetInteger();
840 } else if (token == "\\pextra_start_minipage") {
842 par->pextra_start_minipage = lex.GetInteger();
843 } else if (token == "\\labelwidthstring") {
845 par->labelwidthstring = lex.GetString();
846 // do not delete this token, it is still needed!
847 } else if (token == "\\end_inset") {
848 lyxerr << "Solitary \\end_inset. Missing \\begin_inset?.\n"
849 << "Last inset read was: " << last_inset_read
851 // Simply ignore this. The insets do not have
853 // But insets should read it, it is a part of
854 // the inset isn't it? Lgb.
855 } else if (token == "\\begin_inset") {
856 readInset(lex, par, pos, font);
857 } else if (token == "\\SpecialChar") {
858 LyXLayout const & layout =
859 textclasslist.Style(params.textclass,
862 // Insets don't make sense in a free-spacing context! ---Kayvan
863 if (layout.free_spacing) {
866 string next_token = lex.GetString();
867 if (next_token == "\\-") {
868 par->InsertChar(pos, '-', font);
869 } else if (next_token == "\\protected_separator"
870 || next_token == "~") {
871 par->InsertChar(pos, ' ', font);
873 lex.printError("Token `$$Token' "
875 "paragraph layout!");
880 Inset * inset = new InsetSpecialChar;
881 inset->Read(this, lex);
882 par->InsertInset(pos, inset, font);
885 } else if (token == "\\newline") {
886 par->InsertChar(pos, LyXParagraph::META_NEWLINE, font);
888 } else if (token == "\\LyXTable") {
890 Inset * inset = new InsetTabular(this);
891 inset->Read(this, lex);
892 par->InsertInset(pos, inset, font);
895 par->table = new LyXTable(lex);
897 } else if (token == "\\hfill") {
898 par->InsertChar(pos, LyXParagraph::META_HFILL, font);
900 } else if (token == "\\protected_separator") { // obsolete
901 // This is a backward compability thingie. (Lgb)
902 // Remove it later some time...introduced with fileformat
904 LyXLayout const & layout =
905 textclasslist.Style(params.textclass,
908 if (layout.free_spacing) {
909 par->InsertChar(pos, ' ', font);
911 Inset * inset = new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
912 par->InsertInset(pos, inset, font);
915 } else if (token == "\\bibitem") { // ale970302
917 InsetCommandParams p( "bibitem" );
918 par->bibkey = new InsetBibKey(p);
920 par->bibkey->Read(this, lex);
921 } else if (token == "\\backslash") {
922 par->InsertChar(pos, '\\', font);
924 } else if (token == "\\the_end") {
927 // This should be insurance for the future: (Asger)
928 lex.printError("Unknown token `$$Token'. "
929 "Inserting as text.");
930 string::const_iterator cit = token.begin();
931 string::const_iterator end = token.end();
932 for(; cit != end; ++cit) {
933 par->InsertChar(pos, (*cit), font);
941 void Buffer::readInset(LyXLex & lex, LyXParagraph *& par,
942 int & pos, LyXFont & font)
945 if (lex.GetString() != "\\begin_inset") {
946 lyxerr << "Buffer::readInset: Consistency check failed."
951 string tmptok = lex.GetString();
952 last_inset_read = tmptok;
953 // test the different insets
954 if (tmptok == "Quotes") {
955 Inset * inset = new InsetQuotes;
956 inset->Read(this, lex);
957 par->InsertInset(pos, inset, font);
959 } else if (tmptok == "External") {
960 Inset * inset = new InsetExternal;
961 inset->Read(this, lex);
962 par->InsertInset(pos, inset, font);
964 } else if (tmptok == "FormulaMacro") {
965 Inset * inset = new InsetFormulaMacro;
966 inset->Read(this, lex);
967 par->InsertInset(pos, inset, font);
969 } else if (tmptok == "Formula") {
970 Inset * inset = new InsetFormula;
971 inset->Read(this, lex);
972 par->InsertInset(pos, inset, font);
974 } else if (tmptok == "Figure") {
975 Inset * inset = new InsetFig(100, 100, this);
976 inset->Read(this, lex);
977 par->InsertInset(pos, inset, font);
979 } else if (tmptok == "Info") {
980 Inset * inset = new InsetInfo;
981 inset->Read(this, lex);
982 par->InsertInset(pos, inset, font);
984 } else if (tmptok == "Include") {
985 InsetCommandParams p( "Include" );
986 Inset * inset = new InsetInclude(p, this);
987 inset->Read(this, lex);
988 par->InsertInset(pos, inset, font);
990 } else if (tmptok == "ERT") {
991 Inset * inset = new InsetERT;
992 inset->Read(this, lex);
993 par->InsertInset(pos, inset, font);
995 } else if (tmptok == "Tabular") {
996 Inset * inset = new InsetTabular(this);
997 inset->Read(this, lex);
998 par->InsertInset(pos, inset, font);
1000 } else if (tmptok == "Text") {
1001 Inset * inset = new InsetText;
1002 inset->Read(this, lex);
1003 par->InsertInset(pos, inset, font);
1005 } else if (tmptok == "Foot") {
1006 Inset * inset = new InsetFoot;
1007 inset->Read(this, lex);
1008 par->InsertInset(pos, inset, font);
1010 } else if (tmptok == "Marginal") {
1011 Inset * inset = new InsetMarginal;
1012 inset->Read(this, lex);
1013 par->InsertInset(pos, inset, font);
1015 } else if (tmptok == "Minipage") {
1016 Inset * inset = new InsetMinipage;
1017 inset->Read(this, lex);
1018 par->InsertInset(pos, inset, font);
1020 } else if (tmptok == "Float") {
1022 string tmptok = lex.GetString();
1023 Inset * inset = new InsetFloat(tmptok);
1024 inset->Read(this, lex);
1025 par->InsertInset(pos, inset, font);
1027 } else if (tmptok == "List") {
1028 Inset * inset = new InsetList;
1029 inset->Read(this, lex);
1030 par->InsertInset(pos, inset, font);
1032 } else if (tmptok == "Theorem") {
1033 Inset * inset = new InsetList;
1034 inset->Read(this, lex);
1035 par->InsertInset(pos, inset, font);
1037 } else if (tmptok == "Caption") {
1038 Inset * inset = new InsetCaption;
1039 inset->Read(this, lex);
1040 par->InsertInset(pos, inset, font);
1042 } else if (tmptok == "GRAPHICS") {
1043 Inset * inset = new InsetGraphics;
1044 inset->Read(this, lex);
1045 par->InsertInset(pos, inset, font);
1047 } else if (tmptok == "LatexCommand") {
1048 InsetCommandParams inscmd;
1051 if (inscmd.getCmdName() == "cite") {
1052 inset = new InsetCitation(inscmd);
1053 } else if (inscmd.getCmdName() == "bibitem") {
1054 lex.printError("Wrong place for bibitem");
1055 inset = new InsetBibKey(inscmd);
1056 } else if (inscmd.getCmdName() == "BibTeX") {
1057 inset = new InsetBibtex(inscmd, this);
1058 } else if (inscmd.getCmdName() == "index") {
1059 inset = new InsetIndex(inscmd);
1060 } else if (inscmd.getCmdName() == "include") {
1061 inset = new InsetInclude(inscmd, this);
1062 } else if (inscmd.getCmdName() == "label") {
1063 inset = new InsetLabel(inscmd);
1064 } else if (inscmd.getCmdName() == "url"
1065 || inscmd.getCmdName() == "htmlurl") {
1066 inset = new InsetUrl(inscmd);
1067 } else if (inscmd.getCmdName() == "ref"
1068 || inscmd.getCmdName() == "pageref"
1069 || inscmd.getCmdName() == "vref"
1070 || inscmd.getCmdName() == "vpageref"
1071 || inscmd.getCmdName() == "prettyref") {
1072 if (!inscmd.getOptions().empty()
1073 || !inscmd.getContents().empty()) {
1074 inset = new InsetRef(inscmd);
1076 } else if (inscmd.getCmdName() == "tableofcontents"
1077 || inscmd.getCmdName() == "listofalgorithms"
1078 || inscmd.getCmdName() == "listoffigures"
1079 || inscmd.getCmdName() == "listoftables") {
1080 inset = new InsetTOC(inscmd);
1081 } else if (inscmd.getCmdName() == "printindex") {
1082 inset = new InsetPrintIndex(inscmd);
1083 } else if (inscmd.getCmdName() == "lyxparent") {
1084 inset = new InsetParent(inscmd, this);
1088 par->InsertInset(pos, inset, font);
1095 bool Buffer::readFile(LyXLex & lex, LyXParagraph * par)
1099 string token(lex.GetString());
1100 if (token == "\\lyxformat") { // the first token _must_ be...
1102 format = lex.GetFloat();
1104 if (LYX_FORMAT - format > 0.05) {
1106 printf(_("Warning: need lyxformat %.2f but found %.2f\n"),
1107 LYX_FORMAT, format);
1109 if (format - LYX_FORMAT > 0.05) {
1110 printf(_("ERROR: need lyxformat %.2f but found %.2f\n"),
1111 LYX_FORMAT, format);
1113 bool the_end = readLyXformat2(lex, par);
1114 // Formats >= 2.13 support "\the_end" marker
1121 WriteAlert(_("Warning!"),
1122 _("Reading of document is not complete"),
1123 _("Maybe the document is truncated"));
1124 // We simulate a safe reading anyways to allow
1125 // users to take the chance... (Asger)
1129 WriteAlert(_("ERROR!"),
1130 _("Old LyX file format found. "
1131 "Use LyX 0.10.x to read this!"));
1135 } else { // "\\lyxformat" not found
1136 WriteAlert(_("ERROR!"), _("Not a LyX file!"));
1139 WriteAlert(_("ERROR!"), _("Unable to read file!"));
1145 // Should probably be moved to somewhere else: BufferView? LyXView?
1146 bool Buffer::save() const
1148 // We don't need autosaves in the immediate future. (Asger)
1149 resetAutosaveTimers();
1153 if (lyxrc.make_backup) {
1154 s = fileName() + '~';
1155 if (!lyxrc.backupdir_path.empty())
1156 s = AddName(lyxrc.backupdir_path,
1157 subst(CleanupPath(s),'/','!'));
1159 // Rename is the wrong way of making a backup,
1160 // this is the correct way.
1161 /* truss cp fil fil2:
1162 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
1163 stat("LyXVC.lyx", 0xEFFFF688) = 0
1164 open("LyXVC.lyx", O_RDONLY) = 3
1165 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
1166 fstat(4, 0xEFFFF508) = 0
1167 fstat(3, 0xEFFFF508) = 0
1168 read(3, " # T h i s f i l e w".., 8192) = 5579
1169 write(4, " # T h i s f i l e w".., 5579) = 5579
1170 read(3, 0xEFFFD4A0, 8192) = 0
1173 chmod("LyXVC3.lyx", 0100644) = 0
1174 lseek(0, 0, SEEK_CUR) = 46440
1178 // Should proabaly have some more error checking here.
1179 // Should be cleaned up in 0.13, at least a bit.
1180 // Doing it this way, also makes the inodes stay the same.
1181 // This is still not a very good solution, in particular we
1182 // might loose the owner of the backup.
1183 FileInfo finfo(fileName());
1184 if (finfo.exist()) {
1185 mode_t fmode = finfo.getMode();
1186 struct utimbuf times = {
1187 finfo.getAccessTime(),
1188 finfo.getModificationTime() };
1190 ifstream ifs(fileName().c_str());
1191 ofstream ofs(s.c_str(), ios::out|ios::trunc);
1196 ::chmod(s.c_str(), fmode);
1198 if (::utime(s.c_str(), ×)) {
1199 lyxerr << "utime error." << endl;
1202 lyxerr << "LyX was not able to make "
1203 "backupcopy. Beware." << endl;
1208 if (writeFile(fileName(), false)) {
1210 removeAutosaveFile(fileName());
1212 // Saving failed, so backup is not backup
1213 if (lyxrc.make_backup) {
1214 ::rename(s.c_str(), fileName().c_str());
1222 // Returns false if unsuccesful
1223 bool Buffer::writeFile(string const & fname, bool flag) const
1225 // if flag is false writeFile will not create any GUI
1226 // warnings, only cerr.
1227 // Needed for autosave in background or panic save (Matthias 120496)
1229 if (read_only && (fname == filename)) {
1230 // Here we should come with a question if we should
1231 // perform the write anyway.
1233 lyxerr << _("Error! Document is read-only: ")
1236 WriteAlert(_("Error! Document is read-only: "),
1241 FileInfo finfo(fname);
1242 if (finfo.exist() && !finfo.writable()) {
1243 // Here we should come with a question if we should
1244 // try to do the save anyway. (i.e. do a chmod first)
1246 lyxerr << _("Error! Cannot write file: ")
1249 WriteFSAlert(_("Error! Cannot write file: "),
1254 ofstream ofs(fname.c_str());
1257 lyxerr << _("Error! Cannot open file: ")
1260 WriteFSAlert(_("Error! Cannot open file: "),
1264 // The top of the file should not be written by params.
1266 // write out a comment in the top of the file
1267 ofs << '#' << LYX_DOCVERSION
1268 << " created this file. For more info see http://www.lyx.org/\n";
1269 ofs.setf(ios::showpoint|ios::fixed);
1271 ofs << "\\lyxformat " << setw(4) << LYX_FORMAT << "\n";
1273 // now write out the buffer paramters.
1274 params.writeFile(ofs);
1276 char footnoteflag = 0;
1279 // this will write out all the paragraphs
1280 // using recursive descent.
1281 paragraph->writeFile(this, ofs, params, footnoteflag, depth);
1283 // Write marker that shows file is complete
1284 ofs << "\n\\the_end" << endl;
1286 // how to check if close went ok?
1291 void Buffer::writeFileAscii(string const & fname, int linelen)
1293 LyXFont font1, font2;
1295 char c, footnoteflag = 0, depth = 0;
1297 LyXParagraph::size_type i;
1300 int ltype_depth = 0;
1309 int currlinelen = 0;
1311 bool ref_printed = false;
1313 ofstream ofs(fname.c_str());
1315 WriteFSAlert(_("Error: Cannot write file:"), fname);
1319 string fname1 = TmpFileName();
1320 LyXParagraph * par = paragraph;
1326 par->footnoteflag != LyXParagraph::NO_FOOTNOTE ||
1330 || par->previous->footnoteflag == LyXParagraph::NO_FOOTNOTE
1335 /* begins a footnote environment ? */
1336 if (footnoteflag != par->footnoteflag) {
1337 footnoteflag = par->footnoteflag;
1339 j = strlen(string_footnotekinds[par->footnotekind])+4;
1340 if (currlinelen + j > linelen)
1343 << string_footnotekinds[par->footnotekind] << "] ";
1349 /* begins or ends a deeper area ?*/
1350 if (depth != par->depth) {
1351 if (par->depth > depth) {
1352 while (par->depth > depth) {
1357 while (par->depth < depth) {
1363 /* First write the layout */
1364 tmp = textclasslist.NameOfLayout(params.textclass, par->layout);
1365 if (tmp == "Itemize") {
1367 ltype_depth = depth+1;
1368 } else if (tmp == "Enumerate") {
1370 ltype_depth = depth+1;
1371 } else if (strstr(tmp.c_str(), "ection")) {
1373 ltype_depth = depth+1;
1374 } else if (strstr(tmp.c_str(), "aragraph")) {
1376 ltype_depth = depth+1;
1377 } else if (tmp == "Description") {
1379 ltype_depth = depth+1;
1380 } else if (tmp == "Abstract") {
1383 } else if (tmp == "Bibliography") {
1391 /* maybe some vertical spaces */
1393 /* the labelwidthstring used in lists */
1397 /* some pagebreaks? */
1401 /* what about the alignment */
1404 /* dummy layout, that means a footnote ended */
1405 footnoteflag = LyXParagraph::NO_FOOTNOTE;
1409 lyxerr << "Should this ever happen?" << endl;
1413 //LyXLayout const & layout =
1414 // textclasslist.Style(params.textclass,
1415 // par->GetLayout()); // unused
1416 //bool free_spc = layout.free_spacing; //unused
1419 /* It might be a table */
1423 cells = par->table->columns;
1424 clen = new int [cells];
1425 memset(clen, 0, sizeof(int) * cells);
1427 for (i = 0, j = 0, h = 1; i < par->size(); ++i, ++h) {
1428 c = par->GetChar(i);
1429 if (c == LyXParagraph::META_INSET) {
1430 if ((inset = par->GetInset(i))) {
1432 std::ostringstream ost;
1433 inset->Ascii(this, ost);
1434 h += ost.str().length();
1437 inset->Ascii(this, ost);
1439 char * tmp = ost.str();
1445 } else if (c == LyXParagraph::META_NEWLINE) {
1449 j = (++j) % par->table->NumberOfCellsInRow(actcell);
1457 font1 = LyXFont(LyXFont::ALL_INHERIT, params.language_info);
1459 for (i = 0, actpos = 1; i < par->size(); ++i, ++actpos) {
1460 if (!i && !footnoteflag && !noparbreak){
1462 for(j = 0; j < depth; ++j)
1464 currlinelen = depth * 2;
1466 case 0: /* Standard */
1467 case 4: /* (Sub)Paragraph */
1468 case 5: /* Description */
1470 case 6: /* Abstract */
1471 ofs << "Abstract\n\n";
1473 case 7: /* Bibliography */
1475 ofs << "References\n\n";
1480 ofs << par->labelstring << " ";
1483 if (ltype_depth > depth) {
1484 for(j = ltype_depth - 1; j > depth; --j)
1486 currlinelen += (ltype_depth-depth)*2;
1490 for(j = 0; j < cells; ++j) {
1492 for(h = 0; h < (clen[j] + 1);
1497 for(j = 0; j < depth; ++j)
1499 currlinelen = depth * 2;
1500 if (ltype_depth > depth) {
1501 for(j = ltype_depth;
1504 currlinelen += (ltype_depth-depth)*2;
1510 font2 = par->GetFontSettings(params, i);
1511 if (font1.latex() != font2.latex()) {
1512 if (font2.latex() == LyXFont::OFF)
1519 c = par->GetChar(i);
1523 case LyXParagraph::META_INSET:
1524 if ((inset = par->GetInset(i))) {
1526 inset->Ascii(this, ofs);
1527 currlinelen += (ofs.tellp() - fpos);
1528 actpos += (ofs.tellp() - fpos) - 1;
1531 case LyXParagraph::META_NEWLINE:
1534 if (par->table->NumberOfCellsInRow(actcell) <= cell) {
1535 for(j = actpos; j < clen[cell - 1]; ++j)
1538 for(j = 0; j < depth; ++j)
1540 currlinelen = depth*2;
1541 if (ltype_depth > depth) {
1542 for(j = ltype_depth; j > depth; --j)
1544 currlinelen += (ltype_depth-depth) * 2;
1546 for(j = 0; j < cells; ++j) {
1548 for(h = 0; h < (clen[j] + 1); ++h)
1552 for(j = 0; j < depth; ++j)
1554 currlinelen = depth * 2;
1555 if (ltype_depth > depth) {
1556 for(j = ltype_depth;
1559 currlinelen += (ltype_depth-depth)*2;
1565 j < clen[cell - 1]; ++j)
1571 currlinelen = actpos = 0;
1575 for(j = 0; j < depth; ++j)
1577 currlinelen = depth * 2;
1578 if (ltype_depth > depth) {
1579 for(j = ltype_depth;
1582 currlinelen += (ltype_depth - depth) * 2;
1588 case LyXParagraph::META_HFILL:
1595 if (currlinelen > linelen - 10
1596 && c == ' ' && i + 2 < par->size()) {
1598 for(j = 0; j < depth; ++j)
1600 currlinelen = depth * 2;
1601 if (ltype_depth > depth) {
1602 for(j = ltype_depth;
1605 currlinelen += (ltype_depth-depth)*2;
1607 } else if (c != '\0')
1610 lyxerr.debug() << "writeAsciiFile: NULL char in structure." << endl;
1617 for(j = actpos; j < clen[cell - 1]; ++j)
1620 for(j = 0; j < depth; ++j)
1622 currlinelen = depth * 2;
1623 if (ltype_depth > depth) {
1624 for(j = ltype_depth; j > depth; --j)
1626 currlinelen += (ltype_depth - depth) * 2;
1628 for(j = 0; j < cells; ++j) {
1630 for(h = 0; h < (clen[j] + 1); ++h)
1644 void Buffer::makeLaTeXFile(string const & fname,
1645 string const & original_path,
1646 bool nice, bool only_body)
1648 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
1650 niceFile = nice; // this will be used by Insetincludes.
1652 tex_code_break_column = lyxrc.ascii_linelen;
1654 LyXTextClass const & tclass =
1655 textclasslist.TextClass(params.textclass);
1657 ofstream ofs(fname.c_str());
1659 WriteFSAlert(_("Error: Cannot open file: "), fname);
1663 // validate the buffer.
1664 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
1665 LaTeXFeatures features(params, tclass.numLayouts());
1667 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
1670 // The starting paragraph of the coming rows is the
1671 // first paragraph of the document. (Asger)
1672 texrow.start(paragraph, 0);
1674 if (!only_body && nice) {
1675 ofs << "%% " LYX_DOCVERSION " created this file. "
1676 "For more info, see http://www.lyx.org/.\n"
1677 "%% Do not edit unless you really know what "
1682 lyxerr.debug() << "lyx header finished" << endl;
1683 // There are a few differences between nice LaTeX and usual files:
1684 // usual is \batchmode and has a
1685 // special input@path to allow the including of figures
1686 // with either \input or \includegraphics (what figinsets do).
1687 // batchmode is not set if there is a tex_code_break_column.
1688 // In this case somebody is interested in the generated LaTeX,
1689 // so this is OK. input@path is set when the actual parameter
1690 // original_path is set. This is done for usual tex-file, but not
1691 // for nice-latex-file. (Matthias 250696)
1694 // code for usual, NOT nice-latex-file
1695 ofs << "\\batchmode\n"; // changed
1696 // from \nonstopmode
1699 if (!original_path.empty()) {
1700 ofs << "\\makeatletter\n"
1701 << "\\def\\input@path{{"
1702 << original_path << "/}}\n"
1703 << "\\makeatother\n";
1709 ofs << "\\documentclass";
1711 string options; // the document class options.
1713 if (tokenPos(tclass.opt_fontsize(),
1714 '|', params.fontsize) >= 0) {
1715 // only write if existing in list (and not default)
1716 options += params.fontsize;
1721 if (!params.use_geometry &&
1722 (params.paperpackage == BufferParams::PACKAGE_NONE)) {
1723 switch (params.papersize) {
1724 case BufferParams::PAPER_A4PAPER:
1725 options += "a4paper,";
1727 case BufferParams::PAPER_USLETTER:
1728 options += "letterpaper,";
1730 case BufferParams::PAPER_A5PAPER:
1731 options += "a5paper,";
1733 case BufferParams::PAPER_B5PAPER:
1734 options += "b5paper,";
1736 case BufferParams::PAPER_EXECUTIVEPAPER:
1737 options += "executivepaper,";
1739 case BufferParams::PAPER_LEGALPAPER:
1740 options += "legalpaper,";
1746 if (params.sides != tclass.sides()) {
1747 switch (params.sides) {
1748 case LyXTextClass::OneSide:
1749 options += "oneside,";
1751 case LyXTextClass::TwoSides:
1752 options += "twoside,";
1759 if (params.columns != tclass.columns()) {
1760 if (params.columns == 2)
1761 options += "twocolumn,";
1763 options += "onecolumn,";
1766 if (!params.use_geometry
1767 && params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1768 options += "landscape,";
1770 // language should be a parameter to \documentclass
1771 bool use_babel = false;
1772 if (params.language_info->lang() == "hebrew") // This seems necessary
1773 features.UsedLanguages.insert(default_language);
1774 if (params.language != "default" ||
1775 !features.UsedLanguages.empty() ) {
1777 for (LaTeXFeatures::LanguageList::const_iterator cit =
1778 features.UsedLanguages.begin();
1779 cit != features.UsedLanguages.end(); ++cit)
1780 options += (*cit)->lang() + ",";
1781 options += params.language_info->lang() + ',';
1784 // the user-defined options
1785 if (!params.options.empty()) {
1786 options += params.options + ',';
1789 if (!options.empty()){
1790 options = strip(options, ',');
1791 ofs << '[' << options << ']';
1795 << textclasslist.LatexnameOfClass(params.textclass)
1798 // end of \documentclass defs
1800 // font selection must be done before loading fontenc.sty
1801 if (params.fonts != "default") {
1802 ofs << "\\usepackage{" << params.fonts << "}\n";
1805 // this one is not per buffer
1806 if (lyxrc.fontenc != "default") {
1807 ofs << "\\usepackage[" << lyxrc.fontenc
1812 if (params.inputenc == "auto") {
1813 string doc_encoding =
1814 params.language_info->encoding()->LatexName();
1816 // Create a list with all the input encodings used
1818 set<string> encodings;
1819 for (LaTeXFeatures::LanguageList::const_iterator it =
1820 features.UsedLanguages.begin();
1821 it != features.UsedLanguages.end(); ++it)
1822 if ((*it)->encoding()->LatexName() != doc_encoding)
1823 encodings.insert((*it)->encoding()->LatexName());
1825 ofs << "\\usepackage[";
1826 for (set<string>::const_iterator it = encodings.begin();
1827 it != encodings.end(); ++it)
1829 ofs << doc_encoding << "]{inputenc}\n";
1831 } else if (params.inputenc != "default") {
1832 ofs << "\\usepackage[" << params.inputenc
1837 // At the very beginning the text parameters.
1838 if (params.paperpackage != BufferParams::PACKAGE_NONE) {
1839 switch (params.paperpackage) {
1840 case BufferParams::PACKAGE_A4:
1841 ofs << "\\usepackage{a4}\n";
1844 case BufferParams::PACKAGE_A4WIDE:
1845 ofs << "\\usepackage{a4wide}\n";
1848 case BufferParams::PACKAGE_WIDEMARGINSA4:
1849 ofs << "\\usepackage[widemargins]{a4}\n";
1854 if (params.use_geometry) {
1855 ofs << "\\usepackage{geometry}\n";
1857 ofs << "\\geometry{verbose";
1858 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1859 ofs << ",landscape";
1860 switch (params.papersize2) {
1861 case BufferParams::VM_PAPER_CUSTOM:
1862 if (!params.paperwidth.empty())
1863 ofs << ",paperwidth="
1864 << params.paperwidth;
1865 if (!params.paperheight.empty())
1866 ofs << ",paperheight="
1867 << params.paperheight;
1869 case BufferParams::VM_PAPER_USLETTER:
1870 ofs << ",letterpaper";
1872 case BufferParams::VM_PAPER_USLEGAL:
1873 ofs << ",legalpaper";
1875 case BufferParams::VM_PAPER_USEXECUTIVE:
1876 ofs << ",executivepaper";
1878 case BufferParams::VM_PAPER_A3:
1881 case BufferParams::VM_PAPER_A4:
1884 case BufferParams::VM_PAPER_A5:
1887 case BufferParams::VM_PAPER_B3:
1890 case BufferParams::VM_PAPER_B4:
1893 case BufferParams::VM_PAPER_B5:
1897 // default papersize ie BufferParams::VM_PAPER_DEFAULT
1898 switch (lyxrc.default_papersize) {
1899 case BufferParams::PAPER_DEFAULT: // keep compiler happy
1900 case BufferParams::PAPER_USLETTER:
1901 ofs << ",letterpaper";
1903 case BufferParams::PAPER_LEGALPAPER:
1904 ofs << ",legalpaper";
1906 case BufferParams::PAPER_EXECUTIVEPAPER:
1907 ofs << ",executivepaper";
1909 case BufferParams::PAPER_A3PAPER:
1912 case BufferParams::PAPER_A4PAPER:
1915 case BufferParams::PAPER_A5PAPER:
1918 case BufferParams::PAPER_B5PAPER:
1923 if (!params.topmargin.empty())
1924 ofs << ",tmargin=" << params.topmargin;
1925 if (!params.bottommargin.empty())
1926 ofs << ",bmargin=" << params.bottommargin;
1927 if (!params.leftmargin.empty())
1928 ofs << ",lmargin=" << params.leftmargin;
1929 if (!params.rightmargin.empty())
1930 ofs << ",rmargin=" << params.rightmargin;
1931 if (!params.headheight.empty())
1932 ofs << ",headheight=" << params.headheight;
1933 if (!params.headsep.empty())
1934 ofs << ",headsep=" << params.headsep;
1935 if (!params.footskip.empty())
1936 ofs << ",footskip=" << params.footskip;
1940 if (params.use_amsmath
1941 && !tclass.provides(LyXTextClass::amsmath)) {
1942 ofs << "\\usepackage{amsmath}\n";
1946 if (tokenPos(tclass.opt_pagestyle(),
1947 '|', params.pagestyle) >= 0) {
1948 if (params.pagestyle == "fancy") {
1949 ofs << "\\usepackage{fancyhdr}\n";
1952 ofs << "\\pagestyle{" << params.pagestyle << "}\n";
1956 // We try to load babel late, in case it interferes
1957 // with other packages.
1959 ofs << lyxrc.language_package << endl;
1963 if (params.secnumdepth != tclass.secnumdepth()) {
1964 ofs << "\\setcounter{secnumdepth}{"
1965 << params.secnumdepth
1969 if (params.tocdepth != tclass.tocdepth()) {
1970 ofs << "\\setcounter{tocdepth}{"
1976 if (params.paragraph_separation) {
1977 switch (params.defskip.kind()) {
1978 case VSpace::SMALLSKIP:
1979 ofs << "\\setlength\\parskip{\\smallskipamount}\n";
1981 case VSpace::MEDSKIP:
1982 ofs << "\\setlength\\parskip{\\medskipamount}\n";
1984 case VSpace::BIGSKIP:
1985 ofs << "\\setlength\\parskip{\\bigskipamount}\n";
1987 case VSpace::LENGTH:
1988 ofs << "\\setlength\\parskip{"
1989 << params.defskip.length().asLatexString()
1992 default: // should never happen // Then delete it.
1993 ofs << "\\setlength\\parskip{\\medskipamount}\n";
1998 ofs << "\\setlength\\parindent{0pt}\n";
2002 // Now insert the LyX specific LaTeX commands...
2004 // The optional packages;
2005 string preamble(features.getPackages());
2007 // this might be useful...
2008 preamble += "\n\\makeatletter\n";
2010 // Some macros LyX will need
2011 string tmppreamble(features.getMacros());
2013 if (!tmppreamble.empty()) {
2014 preamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2015 "LyX specific LaTeX commands.\n"
2016 + tmppreamble + '\n';
2019 // the text class specific preamble
2020 tmppreamble = features.getTClassPreamble();
2021 if (!tmppreamble.empty()) {
2022 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2023 "Textclass specific LaTeX commands.\n"
2024 + tmppreamble + '\n';
2027 /* the user-defined preamble */
2028 if (!params.preamble.empty()) {
2029 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2030 "User specified LaTeX commands.\n"
2031 + params.preamble + '\n';
2034 preamble += "\\makeatother\n";
2036 // Itemize bullet settings need to be last in case the user
2037 // defines their own bullets that use a package included
2038 // in the user-defined preamble -- ARRae
2039 // Actually it has to be done much later than that
2040 // since some packages like frenchb make modifications
2041 // at \begin{document} time -- JMarc
2043 for (int i = 0; i < 4; ++i) {
2044 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
2045 if (bullets_def.empty())
2046 bullets_def="\\AtBeginDocument{\n";
2047 bullets_def += " \\renewcommand{\\labelitemi";
2049 // `i' is one less than the item to modify
2056 bullets_def += "ii";
2062 bullets_def += "}{" +
2063 params.user_defined_bullets[i].getText()
2068 if (!bullets_def.empty())
2069 preamble += bullets_def + "}\n\n";
2071 for (int j = countChar(preamble, '\n'); j-- ;) {
2078 ofs << "\\begin{document}\n";
2081 lyxerr.debug() << "preamble finished, now the body." << endl;
2082 if (!lyxrc.language_auto_begin && params.language != "default") {
2083 ofs << subst(lyxrc.language_command_begin, "$$lang",
2089 latexParagraphs(ofs, paragraph, 0, texrow);
2091 // add this just in case after all the paragraphs
2095 if (!lyxrc.language_auto_end && params.language != "default") {
2096 ofs << subst(lyxrc.language_command_end, "$$lang",
2103 ofs << "\\end{document}\n";
2106 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
2108 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
2112 // Just to be sure. (Asger)
2115 // tex_code_break_column's value is used to decide
2116 // if we are in batchmode or not (within mathed_write()
2117 // in math_write.C) so we must set it to a non-zero
2118 // value when we leave otherwise we save incorrect .lyx files.
2119 tex_code_break_column = lyxrc.ascii_linelen;
2123 lyxerr << "File was not closed properly." << endl;
2126 lyxerr.debug() << "Finished making latex file." << endl;
2131 // LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
2133 void Buffer::latexParagraphs(ostream & ofs, LyXParagraph * par,
2134 LyXParagraph * endpar, TexRow & texrow) const
2136 bool was_title = false;
2137 bool already_title = false;
2139 std::ostringstream ftnote;
2141 char * tmpholder = 0;
2147 while (par != endpar) {
2148 #ifndef HAVE_SSTREAM
2151 ftnote << tmpholder;
2152 delete [] tmpholder;
2158 lyxerr[Debug::LATEX] << "Error in latexParagraphs."
2161 LyXLayout const & layout =
2162 textclasslist.Style(params.textclass,
2165 if (layout.intitle) {
2166 if (already_title) {
2167 lyxerr <<"Error in latexParagraphs: You"
2168 " should not mix title layouts"
2169 " with normal ones." << endl;
2172 } else if (was_title && !already_title) {
2173 ofs << "\\maketitle\n";
2175 already_title = true;
2178 // We are at depth 0 so we can just use
2179 // ordinary \footnote{} generation
2180 // flag this with ftcount
2182 if (layout.isEnvironment()
2183 || par->pextra_type != LyXParagraph::PEXTRA_NONE) {
2184 par = par->TeXEnvironment(this, params, ofs, texrow
2186 ,ftnote, ft_texrow, ftcount
2190 par = par->TeXOnePar(this, params, ofs, texrow, false
2193 ftnote, ft_texrow, ftcount
2198 // Write out what we've generated...
2201 ofs << "\\addtocounter{footnote}{-"
2205 ofs << ftnote.str();
2206 texrow += ft_texrow;
2208 // The extra .c_str() is needed when we use
2209 // lyxstring instead of the STL string class.
2210 ftnote.str(string().c_str());
2212 delete [] ftnote.str();
2217 #ifndef HAVE_SSTREAM
2219 // I hate strstreams
2220 tmpholder = ftnote.str();
2224 #ifndef HAVE_SSTREAM
2225 delete [] tmpholder;
2227 // It might be that we only have a title in this document
2228 if (was_title && !already_title) {
2229 ofs << "\\maketitle\n";
2235 bool Buffer::isLatex() const
2237 return textclasslist.TextClass(params.textclass).outputType() == LATEX;
2241 bool Buffer::isLinuxDoc() const
2243 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC;
2247 bool Buffer::isLiterate() const
2249 return textclasslist.TextClass(params.textclass).outputType() == LITERATE;
2253 bool Buffer::isDocBook() const
2255 return textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2259 bool Buffer::isSGML() const
2261 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC ||
2262 textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2266 void Buffer::sgmlOpenTag(ostream & os, int depth,
2267 string const & latexname) const
2269 os << string(depth, ' ') << "<" << latexname << ">\n";
2273 void Buffer::sgmlCloseTag(ostream & os, int depth,
2274 string const & latexname) const
2276 os << string(depth, ' ') << "</" << latexname << ">\n";
2280 void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
2282 LyXParagraph * par = paragraph;
2284 niceFile = nice; // this will be used by Insetincludes.
2286 string top_element = textclasslist.LatexnameOfClass(params.textclass);
2287 string environment_stack[10];
2290 int depth = 0; // paragraph depth
2292 ofstream ofs(fname.c_str());
2295 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2299 LyXTextClass const & tclass =
2300 textclasslist.TextClass(params.textclass);
2302 LaTeXFeatures features(params, tclass.numLayouts());
2306 tex_code_break_column = lyxrc.ascii_linelen;
2308 //tex_code_break_column = 0;
2313 string sgml_includedfiles=features.getIncludedFiles();
2315 if (params.preamble.empty() && sgml_includedfiles.empty()) {
2316 ofs << "<!doctype linuxdoc system>\n\n";
2318 ofs << "<!doctype linuxdoc system [ "
2319 << params.preamble << sgml_includedfiles << " \n]>\n\n";
2322 if(params.options.empty())
2323 sgmlOpenTag(ofs, 0, top_element);
2325 string top = top_element;
2327 top += params.options;
2328 sgmlOpenTag(ofs, 0, top);
2332 ofs << "<!-- " << LYX_DOCVERSION
2333 << " created this file. For more info see http://www.lyx.org/"
2337 int desc_on = 0; // description mode
2338 LyXLayout const & style =
2339 textclasslist.Style(params.textclass,
2342 // treat <toc> as a special case for compatibility with old code
2343 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2344 Inset * inset = par->GetInset(0);
2345 Inset::Code lyx_code = inset->LyxCode();
2346 if (lyx_code == Inset::TOC_CODE){
2347 string temp = "toc";
2348 sgmlOpenTag(ofs, depth, temp);
2352 linuxDocHandleFootnote(ofs, par, depth);
2358 // environment tag closing
2359 for( ; depth > par->depth; --depth) {
2360 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2361 environment_stack[depth].erase();
2364 // write opening SGML tags
2365 switch(style.latextype) {
2366 case LATEX_PARAGRAPH:
2367 if(depth == par->depth
2368 && !environment_stack[depth].empty()) {
2369 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2370 environment_stack[depth].erase();
2376 sgmlOpenTag(ofs, depth, style.latexname());
2381 LinuxDocError(par, 0,
2382 _("Error : Wrong depth for"
2383 " LatexType Command.\n"));
2385 if (!environment_stack[depth].empty()){
2386 sgmlCloseTag(ofs, depth,
2387 environment_stack[depth]);
2391 environment_stack[depth].erase();
2392 sgmlOpenTag(ofs, depth, style.latexname());
2395 case LATEX_ENVIRONMENT:
2396 case LATEX_ITEM_ENVIRONMENT:
2397 if(depth == par->depth
2398 && environment_stack[depth] != style.latexname()
2399 && !environment_stack[depth].empty()) {
2401 sgmlCloseTag(ofs, depth,
2402 environment_stack[depth]);
2403 environment_stack[depth].erase();
2405 if (depth < par->depth) {
2407 environment_stack[depth].erase();
2409 if (environment_stack[depth] != style.latexname()) {
2412 sgmlOpenTag(ofs, depth, temp);
2414 environment_stack[depth] = style.latexname();
2415 sgmlOpenTag(ofs, depth,
2416 environment_stack[depth]);
2418 if(style.latextype == LATEX_ENVIRONMENT) break;
2420 desc_on = (style.labeltype == LABEL_MANUAL);
2427 sgmlOpenTag(ofs, depth + 1, item_name);
2430 sgmlOpenTag(ofs, depth, style.latexname());
2437 SimpleLinuxDocOnePar(ofs, par, desc_on, depth);
2441 linuxDocHandleFootnote(ofs, par, depth);
2443 while(par && par->IsDummy());
2447 // write closing SGML tags
2448 switch(style.latextype) {
2450 case LATEX_ENVIRONMENT:
2451 case LATEX_ITEM_ENVIRONMENT:
2454 sgmlCloseTag(ofs, depth, style.latexname());
2460 for(; depth > 0; --depth)
2461 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2463 if(!environment_stack[depth].empty())
2464 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2468 sgmlCloseTag(ofs, 0, top_element);
2472 // How to check for successful close
2477 void Buffer::linuxDocHandleFootnote(ostream & os, LyXParagraph * & par,
2480 string tag = "footnote";
2482 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2483 sgmlOpenTag(os, depth + 1, tag);
2484 SimpleLinuxDocOnePar(os, par, 0, depth + 1);
2485 sgmlCloseTag(os, depth + 1, tag);
2492 void Buffer::DocBookHandleCaption(ostream & os, string & inner_tag,
2493 int const depth, int desc_on,
2494 LyXParagraph * & par)
2496 LyXParagraph * tpar = par;
2499 && (tpar->footnoteflag != LyXParagraph::NO_FOOTNOTE)
2501 && (tpar->layout != textclasslist.NumberOfLayout(params.textclass,
2505 tpar->layout == textclasslist.NumberOfLayout(params.textclass,
2506 "Caption").second) {
2507 sgmlOpenTag(os, depth + 1, inner_tag);
2509 SimpleDocBookOnePar(os, extra_par, tpar,
2510 desc_on, depth + 2);
2511 sgmlCloseTag(os, depth+1, inner_tag);
2512 if(!extra_par.empty())
2519 void Buffer::DocBookHandleFootnote(ostream & os, LyXParagraph * & par,
2522 string tag, inner_tag;
2523 string tmp_par, extra_par;
2524 bool inner_span = false;
2527 // Someone should give this enum a proper name (Lgb)
2535 SOME_ENUM last = NO_ONE;
2536 SOME_ENUM present = FOOTNOTE_LIKE;
2538 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2539 if(last == present) {
2541 if(!tmp_par.empty()) {
2544 sgmlCloseTag(os, depth + 1, inner_tag);
2545 sgmlOpenTag(os, depth + 1, inner_tag);
2552 if(!inner_tag.empty()) sgmlCloseTag(os, depth + 1,
2554 if(!extra_par.empty()) os << extra_par;
2555 if(!tag.empty()) sgmlCloseTag(os, depth, tag);
2558 switch (par->footnotekind) {
2559 case LyXParagraph::FOOTNOTE:
2560 case LyXParagraph::ALGORITHM:
2563 present = FOOTNOTE_LIKE;
2566 case LyXParagraph::MARGIN:
2569 present = MARGIN_LIKE;
2572 case LyXParagraph::FIG:
2573 case LyXParagraph::WIDE_FIG:
2575 inner_tag = "title";
2579 case LyXParagraph::TAB:
2580 case LyXParagraph::WIDE_TAB:
2582 inner_tag = "title";
2587 sgmlOpenTag(os, depth, tag);
2588 if ((present == TAB_LIKE) || (present == FIG_LIKE)) {
2589 DocBookHandleCaption(os, inner_tag, depth,
2593 sgmlOpenTag(os, depth + 1, inner_tag);
2596 // ignore all caption here, we processed them above!!!
2597 if (par->layout != textclasslist
2598 .NumberOfLayout(params.textclass,
2599 "Caption").second) {
2601 std::ostringstream ost;
2605 SimpleDocBookOnePar(ost, extra_par, par,
2606 desc_on, depth + 2);
2608 tmp_par += ost.str().c_str();
2611 char * ctmp = ost.str();
2616 tmp_par = frontStrip(strip(tmp_par));
2622 if(!inner_tag.empty()) sgmlCloseTag(os, depth + 1, inner_tag);
2623 if(!extra_par.empty()) os << extra_par;
2624 if(!tag.empty()) sgmlCloseTag(os, depth, tag);
2629 // push a tag in a style stack
2630 void Buffer::push_tag(ostream & os, char const * tag,
2631 int & pos, char stack[5][3])
2633 // pop all previous tags
2634 for (int j = pos; j >= 0; --j)
2635 os << "</" << stack[j] << ">";
2638 sprintf(stack[++pos], "%s", tag);
2641 for (int i = 0; i <= pos; ++i)
2642 os << "<" << stack[i] << ">";
2646 void Buffer::pop_tag(ostream & os, char const * tag,
2647 int & pos, char stack[5][3])
2651 // pop all tags till specified one
2652 for (j = pos; (j >= 0) && (strcmp(stack[j], tag)); --j)
2653 os << "</" << stack[j] << ">";
2656 os << "</" << tag << ">";
2658 // push all tags, but the specified one
2659 for (j = j + 1; j <= pos; ++j) {
2660 os << "<" << stack[j] << ">";
2661 strcpy(stack[j-1], stack[j]);
2667 // Handle internal paragraph parsing -- layout already processed.
2669 // checks, if newcol chars should be put into this line
2670 // writes newline, if necessary.
2672 void linux_doc_line_break(ostream & os, unsigned int & colcount,
2673 const unsigned int newcol)
2676 if (colcount > lyxrc.ascii_linelen) {
2678 colcount = newcol; // assume write after this call
2683 void Buffer::SimpleLinuxDocOnePar(ostream & os, LyXParagraph * par,
2684 int desc_on, int const /*depth*/)
2686 LyXFont font1, font2;
2689 LyXParagraph::size_type main_body;
2691 LyXLayout const & style = textclasslist.Style(params.textclass,
2694 char family_type = 0; // family font flag
2695 bool is_bold = false; // series font flag
2696 char shape_type = 0; // shape font flag
2697 bool is_em = false; // emphasis (italic) font flag
2699 int stack_num = -1; // style stack position
2700 // Can this be rewritten to use a std::stack, please. (Lgb)
2701 char stack[5][3]; // style stack
2702 unsigned int char_line_count = 5; // Heuristic choice ;-)
2704 if (style.labeltype != LABEL_MANUAL)
2707 main_body = par->BeginningOfMainBody();
2709 // gets paragraph main font
2711 font1 = style.labelfont;
2716 // parsing main loop
2717 for (LyXParagraph::size_type i = 0;
2718 i < par->size(); ++i) {
2730 font2 = par->getFont(params, i);
2732 if (font1.family() != font2.family()) {
2733 switch(family_type) {
2735 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2736 push_tag(os, "tt", stack_num, stack);
2739 else if (font2.family() == LyXFont::SANS_FAMILY) {
2740 push_tag(os, "sf", stack_num, stack);
2745 pop_tag(os, "tt", stack_num, stack);
2746 if (font2.family() == LyXFont::SANS_FAMILY) {
2747 push_tag(os, "sf", stack_num, stack);
2754 pop_tag(os, "sf", stack_num, stack);
2755 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2756 push_tag(os, "tt", stack_num, stack);
2765 if (font1.series() != font2.series()) {
2766 if (font2.series() == LyXFont::BOLD_SERIES) {
2767 push_tag(os, "bf", stack_num, stack);
2769 } else if (is_bold) {
2770 pop_tag(os, "bf", stack_num, stack);
2775 // handle italic and slanted fonts
2776 if (font1.shape() != font2.shape()) {
2777 switch(shape_type) {
2779 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2780 push_tag(os, "it", stack_num, stack);
2782 } else if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2783 push_tag(os, "sl", stack_num, stack);
2788 pop_tag(os, "it", stack_num, stack);
2789 if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2790 push_tag(os, "sl", stack_num, stack);
2797 pop_tag(os, "sl", stack_num, stack);
2798 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2799 push_tag(os, "it", stack_num, stack);
2807 if (font1.emph() != font2.emph()) {
2808 if (font2.emph() == LyXFont::ON) {
2809 push_tag(os, "em", stack_num, stack);
2812 pop_tag(os, "em", stack_num, stack);
2817 c = par->GetChar(i);
2819 if (c == LyXParagraph::META_INSET) {
2820 inset = par->GetInset(i);
2821 inset->Linuxdoc(this, os);
2824 if (font2.latex() == LyXFont::ON) {
2825 // "TeX"-Mode on == > SGML-Mode on.
2827 os << c; // see LaTeX-Generation...
2831 if (par->linuxDocConvertChar(c, sgml_string)
2832 && !style.free_spacing) { // in freespacing
2834 // non-breaking characters
2838 linux_doc_line_break(os, char_line_count, 6);
2842 linux_doc_line_break(os, char_line_count, 1);
2847 char_line_count += sgml_string.length();
2853 // needed if there is an optional argument but no contents
2854 if (main_body > 0 && main_body == par->size()) {
2858 // pop all defined Styles
2859 for (j = stack_num; j >= 0; --j) {
2860 linux_doc_line_break(os,
2862 3 + strlen(stack[j]));
2863 os << "</" << stack[j] << ">";
2866 // resets description flag correctly
2869 // <tag> not closed...
2870 linux_doc_line_break(os, char_line_count, 6);
2874 // fprintf(file, "</p>");
2880 // Print an error message.
2881 void Buffer::LinuxDocError(LyXParagraph * par, int pos,
2882 char const * message)
2884 // insert an error marker in text
2885 InsetError * new_inset = new InsetError(message);
2886 par->InsertInset(pos, new_inset);
2889 // This constant defines the maximum number of
2890 // environment layouts that can be nesteded.
2891 // The same applies for command layouts.
2892 // These values should be more than enough.
2893 // José Matos (1999/07/22)
2895 enum { MAX_NEST_LEVEL = 25};
2897 void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
2899 LyXParagraph * par = paragraph;
2901 niceFile = nice; // this will be used by Insetincludes.
2903 string top_element= textclasslist.LatexnameOfClass(params.textclass);
2904 // Please use a real stack.
2905 string environment_stack[MAX_NEST_LEVEL];
2906 string environment_inner[MAX_NEST_LEVEL];
2907 // Please use a real stack.
2908 string command_stack[MAX_NEST_LEVEL];
2909 bool command_flag= false;
2910 int command_depth= 0, command_base= 0, cmd_depth= 0;
2912 string item_name, command_name;
2913 string c_depth, c_params, tmps;
2915 int depth = 0; // paragraph depth
2916 LyXTextClass const & tclass =
2917 textclasslist.TextClass(params.textclass);
2919 LaTeXFeatures features(params, tclass.numLayouts());
2923 tex_code_break_column = lyxrc.ascii_linelen;
2925 //tex_code_break_column = 0;
2927 ofstream ofs(fname.c_str());
2929 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2936 string sgml_includedfiles=features.getIncludedFiles();
2938 ofs << "<!doctype " << top_element
2939 << " public \"-//OASIS//DTD DocBook V3.1//EN\"";
2941 if (params.preamble.empty() && sgml_includedfiles.empty())
2944 ofs << "\n [ " << params.preamble
2945 << sgml_includedfiles << " \n]>\n\n";
2947 if(params.options.empty())
2948 sgmlOpenTag(ofs, 0, top_element);
2950 string top = top_element;
2952 top += params.options;
2953 sgmlOpenTag(ofs, 0, top);
2957 ofs << "<!-- DocBook file was created by " << LYX_DOCVERSION
2958 << "\n See http://www.lyx.org/ for more information -->\n";
2961 int desc_on = 0; // description mode
2962 LyXLayout const & style =
2963 textclasslist.Style(params.textclass,
2966 // environment tag closing
2967 for( ; depth > par->depth; --depth) {
2968 if(environment_inner[depth] != "!-- --") {
2969 item_name= "listitem";
2970 sgmlCloseTag(ofs, command_depth + depth,
2972 if( environment_inner[depth] == "varlistentry")
2973 sgmlCloseTag(ofs, depth+command_depth,
2974 environment_inner[depth]);
2976 sgmlCloseTag(ofs, depth + command_depth,
2977 environment_stack[depth]);
2978 environment_stack[depth].erase();
2979 environment_inner[depth].erase();
2982 if(depth == par->depth
2983 && environment_stack[depth] != style.latexname()
2984 && !environment_stack[depth].empty()) {
2985 if(environment_inner[depth] != "!-- --") {
2986 item_name= "listitem";
2987 sgmlCloseTag(ofs, command_depth+depth,
2989 if( environment_inner[depth] == "varlistentry")
2991 depth + command_depth,
2992 environment_inner[depth]);
2995 sgmlCloseTag(ofs, depth + command_depth,
2996 environment_stack[depth]);
2998 environment_stack[depth].erase();
2999 environment_inner[depth].erase();
3002 // Write opening SGML tags.
3003 switch(style.latextype) {
3004 case LATEX_PARAGRAPH:
3005 if(style.latexname() != "dummy")
3006 sgmlOpenTag(ofs, depth+command_depth,
3012 LinuxDocError(par, 0,
3013 _("Error : Wrong depth for "
3014 "LatexType Command.\n"));
3016 command_name = style.latexname();
3018 tmps = style.latexparam();
3019 c_params = split(tmps, c_depth,'|');
3021 cmd_depth= atoi(c_depth.c_str());
3024 if(cmd_depth<command_base) {
3025 for(int j = command_depth;
3026 j >= command_base; --j)
3027 if(!command_stack[j].empty())
3028 sgmlCloseTag(ofs, j, command_stack[j]);
3029 command_depth= command_base= cmd_depth;
3030 } else if(cmd_depth <= command_depth) {
3031 for(int j = command_depth;
3032 j >= cmd_depth; --j)
3034 if(!command_stack[j].empty())
3035 sgmlCloseTag(ofs, j, command_stack[j]);
3036 command_depth= cmd_depth;
3038 command_depth= cmd_depth;
3040 command_depth = command_base = cmd_depth;
3041 command_flag = true;
3043 command_stack[command_depth]= command_name;
3045 // treat label as a special case for
3046 // more WYSIWYM handling.
3047 if (par->GetChar(0) == LyXParagraph::META_INSET) {
3048 Inset * inset = par->GetInset(0);
3049 Inset::Code lyx_code = inset->LyxCode();
3050 if (lyx_code == Inset::LABEL_CODE){
3051 command_name += " id=\"";
3052 command_name += (static_cast<InsetCommand *>(inset))->getContents();
3053 command_name += "\"";
3058 sgmlOpenTag(ofs, depth + command_depth, command_name);
3059 item_name = "title";
3060 sgmlOpenTag(ofs, depth + 1 + command_depth, item_name);
3063 case LATEX_ENVIRONMENT:
3064 case LATEX_ITEM_ENVIRONMENT:
3065 if (depth < par->depth) {
3067 environment_stack[depth].erase();
3070 if (environment_stack[depth] != style.latexname()) {
3071 environment_stack[depth] = style.latexname();
3072 environment_inner[depth] = "!-- --";
3073 sgmlOpenTag(ofs, depth + command_depth,
3074 environment_stack[depth]);
3076 if(environment_inner[depth] != "!-- --") {
3077 item_name= "listitem";
3079 command_depth + depth,
3081 if (environment_inner[depth] == "varlistentry")
3083 depth + command_depth,
3084 environment_inner[depth]);
3088 if(style.latextype == LATEX_ENVIRONMENT) {
3089 if(!style.latexparam().empty())
3090 sgmlOpenTag(ofs, depth + command_depth,
3091 style.latexparam());
3095 desc_on = (style.labeltype == LABEL_MANUAL);
3098 environment_inner[depth]= "varlistentry";
3100 environment_inner[depth]= "listitem";
3102 sgmlOpenTag(ofs, depth + 1 + command_depth,
3103 environment_inner[depth]);
3107 sgmlOpenTag(ofs, depth + 1 + command_depth,
3111 sgmlOpenTag(ofs, depth + 1 + command_depth,
3116 sgmlOpenTag(ofs, depth + command_depth,
3125 SimpleDocBookOnePar(ofs, extra_par, par, desc_on,
3126 depth + 1 + command_depth);
3129 DocBookHandleFootnote(ofs, par,
3130 depth + 1 + command_depth);
3132 while(par && par->IsDummy());
3135 // write closing SGML tags
3136 switch(style.latextype) {
3139 sgmlCloseTag(ofs, depth + command_depth, end_tag);
3141 case LATEX_ENVIRONMENT:
3142 if(!style.latexparam().empty())
3143 sgmlCloseTag(ofs, depth + command_depth,
3144 style.latexparam());
3146 case LATEX_ITEM_ENVIRONMENT:
3147 if(desc_on == 1) break;
3149 sgmlCloseTag(ofs, depth + 1 + command_depth, end_tag);
3151 case LATEX_PARAGRAPH:
3152 if(style.latexname() != "dummy")
3153 sgmlCloseTag(ofs, depth + command_depth,
3157 sgmlCloseTag(ofs, depth + command_depth,
3164 for(; depth >= 0; --depth) {
3165 if(!environment_stack[depth].empty()) {
3166 if(environment_inner[depth] != "!-- --") {
3167 item_name= "listitem";
3168 sgmlCloseTag(ofs, command_depth + depth,
3170 if( environment_inner[depth] == "varlistentry")
3171 sgmlCloseTag(ofs, depth + command_depth,
3172 environment_inner[depth]);
3175 sgmlCloseTag(ofs, depth + command_depth,
3176 environment_stack[depth]);
3180 for(int j = command_depth; j >= command_base; --j)
3181 if(!command_stack[j].empty())
3182 sgmlCloseTag(ofs, j, command_stack[j]);
3186 sgmlCloseTag(ofs, 0, top_element);
3190 // How to check for successful close
3194 void Buffer::SimpleDocBookOnePar(ostream & os, string & extra,
3195 LyXParagraph * par, int & desc_on,
3200 par->SimpleDocBookOneTablePar(this,
3201 os, extra, desc_on, depth);
3206 bool emph_flag = false;
3208 LyXLayout const & style = textclasslist.Style(params.textclass,
3211 LyXParagraph::size_type main_body;
3212 if (style.labeltype != LABEL_MANUAL)
3215 main_body = par->BeginningOfMainBody();
3217 // gets paragraph main font
3218 LyXFont font1 = main_body > 0 ? style.labelfont : style.font;
3220 int char_line_count = depth;
3221 if(!style.free_spacing)
3222 for (int j = 0; j < depth; ++j)
3225 // parsing main loop
3226 for (LyXParagraph::size_type i = 0;
3227 i < par->size(); ++i) {
3228 LyXFont font2 = par->getFont(params, i);
3230 // handle <emphasis> tag
3231 if (font1.emph() != font2.emph() && i) {
3232 if (font2.emph() == LyXFont::ON) {
3236 os << "</emphasis>";
3241 char c = par->GetChar(i);
3243 if (c == LyXParagraph::META_INSET) {
3244 Inset * inset = par->GetInset(i);
3246 std::ostringstream ost;
3247 inset->DocBook(this, ost);
3248 string tmp_out = ost.str().c_str();
3251 inset->DocBook(this, ost);
3253 char * ctmp = ost.str();
3254 string tmp_out(ctmp);
3258 // This code needs some explanation:
3259 // Two insets are treated specially
3260 // label if it is the first element in a command paragraph
3262 // graphics inside tables or figure floats can't go on
3263 // title (the equivalente in latex for this case is caption
3264 // and title should come first
3267 if(desc_on!= 3 || i!= 0) {
3268 if(!tmp_out.empty() && tmp_out[0] == '@') {
3270 extra += frontStrip(tmp_out, '@');
3272 os << frontStrip(tmp_out, '@');
3277 } else if (font2.latex() == LyXFont::ON) {
3278 // "TeX"-Mode on ==> SGML-Mode on.
3284 if (par->linuxDocConvertChar(c, sgml_string)
3285 && !style.free_spacing) { // in freespacing
3287 // non-breaking characters
3291 os << "\n</term><listitem><para>";
3303 // needed if there is an optional argument but no contents
3304 if (main_body > 0 && main_body == par->size()) {
3308 os << "</emphasis>";
3311 // resets description flag correctly
3314 // <term> not closed...
3322 int Buffer::runLaTeX()
3326 if (!users->text) return 0;
3328 ProhibitInput(users);
3330 // get LaTeX-Filename
3331 string name = getLatexName();
3333 string path = OnlyPath(filename);
3335 string org_path = path;
3336 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3340 Path p(path); // path to LaTeX file
3341 users->owner()->getMiniBuffer()->Set(_("Running LaTeX..."));
3343 // Remove all error insets
3344 bool a = users->removeAutoInsets();
3346 // Always generate the LaTeX file
3347 makeLaTeXFile(name, org_path, false);
3349 // do the LaTex run(s)
3351 string latex_command = lyxrc.pdf_mode ?
3352 lyxrc.pdflatex_command : lyxrc.latex_command;
3353 LaTeX latex(latex_command, name, filepath);
3354 int res = latex.run(terr,
3355 users->owner()->getMiniBuffer()); // running latex
3357 // check return value from latex.run().
3358 if ((res & LaTeX::NO_LOGFILE)) {
3359 WriteAlert(_("LaTeX did not work!"),
3360 _("Missing log file:"), name);
3361 } else if ((res & LaTeX::ERRORS)) {
3362 users->owner()->getMiniBuffer()->Set(_("Done"));
3363 // Insert all errors as errors boxes
3364 users->insertErrors(terr);
3366 // Dvi should also be kept dirty if the latex run
3367 // ends up with errors. However it should be possible
3368 // to view a dirty dvi too.
3370 //no errors or any other things to think about so:
3371 users->owner()->getMiniBuffer()->Set(_("Done"));
3374 // if we removed error insets before we ran LaTeX or if we inserted
3375 // error insets after we ran LaTeX this must be run:
3376 if (a || (res & LaTeX::ERRORS)){
3379 //users->updateScrollbar();
3383 return latex.getNumErrors();
3390 int Buffer::runLiterate()
3392 if (!users->text) return 0;
3394 ProhibitInput(users);
3396 // get LaTeX-Filename
3397 string name = getLatexName();
3398 // get Literate-Filename
3399 string lit_name = OnlyFilename(ChangeExtension (getLatexName(),
3400 lyxrc.literate_extension));
3402 string path = OnlyPath(filename);
3404 string org_path = path;
3405 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3409 Path p(path); // path to Literate file
3410 users->owner()->getMiniBuffer()->Set(_("Running Literate..."));
3412 // Remove all error insets
3413 bool removedErrorInsets = users->removeAutoInsets();
3415 // generate the Literate file if necessary
3416 makeLaTeXFile(lit_name, org_path, false);
3418 string latex_command = lyxrc.pdf_mode ?
3419 lyxrc.pdflatex_command : lyxrc.latex_command;
3420 Literate literate(latex_command, name, filepath,
3422 lyxrc.literate_command, lyxrc.literate_error_filter,
3423 lyxrc.build_command, lyxrc.build_error_filter);
3425 int res = literate.weave(terr, users->owner()->getMiniBuffer());
3427 // check return value from literate.weave().
3428 if ((res & Literate::NO_LOGFILE)) {
3429 WriteAlert(_("Literate command did not work!"),
3430 _("Missing log file:"), name);
3431 } else if ((res & Literate::ERRORS)) {
3432 users->owner()->getMiniBuffer()->Set(_("Done"));
3433 // Insert all errors as errors boxes
3434 users->insertErrors(terr);
3436 // Dvi should also be kept dirty if the latex run
3437 // ends up with errors. However it should be possible
3438 // to view a dirty dvi too.
3440 //no errors or any other things to think about so:
3441 users->owner()->getMiniBuffer()->Set(_("Done"));
3444 // if we removed error insets before we ran LaTeX or if we inserted
3445 // error insets after we ran LaTeX this must be run:
3446 if (removedErrorInsets || (res & Literate::ERRORS)){
3449 //users->updateScrollbar();
3453 return literate.getNumErrors();
3457 int Buffer::buildProgram()
3459 if (!users->text) return 0;
3461 ProhibitInput(users);
3463 // get LaTeX-Filename
3464 string name = getLatexName();
3465 // get Literate-Filename
3466 string lit_name = OnlyFilename(ChangeExtension(getLatexName(),
3467 lyxrc.literate_extension));
3469 string path = OnlyPath(filename);
3471 string org_path = path;
3472 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3476 Path p(path); // path to Literate file
3477 users->owner()->getMiniBuffer()->Set(_("Building Program..."));
3479 // Remove all error insets
3480 bool removedErrorInsets = users->removeAutoInsets();
3482 // generate the LaTeX file if necessary
3483 if (!isNwClean() || removedErrorInsets) {
3484 makeLaTeXFile(lit_name, org_path, false);
3488 string latex_command = lyxrc.pdf_mode ?
3489 lyxrc.pdflatex_command : lyxrc.latex_command;
3490 Literate literate(latex_command, name, filepath,
3492 lyxrc.literate_command, lyxrc.literate_error_filter,
3493 lyxrc.build_command, lyxrc.build_error_filter);
3495 int res = literate.build(terr, users->owner()->getMiniBuffer());
3497 // check return value from literate.build().
3498 if ((res & Literate::NO_LOGFILE)) {
3499 WriteAlert(_("Build did not work!"),
3500 _("Missing log file:"), name);
3501 } else if ((res & Literate::ERRORS)) {
3502 users->owner()->getMiniBuffer()->Set(_("Done"));
3503 // Insert all errors as errors boxes
3504 users->insertErrors(terr);
3506 // Literate files should also be kept dirty if the literate
3507 // command run ends up with errors.
3509 //no errors or any other things to think about so:
3510 users->owner()->getMiniBuffer()->Set(_("Done"));
3514 // if we removed error insets before we ran Literate/Build or
3515 // if we inserted error insets after we ran Literate/Build this
3517 if (removedErrorInsets || (res & Literate::ERRORS)){
3520 //users->updateScrollbar();
3524 return literate.getNumErrors();
3528 // This should be enabled when the Chktex class is implemented. (Asger)
3529 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
3530 // Other flags: -wall -v0 -x
3531 int Buffer::runChktex()
3533 if (!users->text) return 0;
3535 ProhibitInput(users);
3537 // get LaTeX-Filename
3538 string name = getLatexName();
3539 string path = OnlyPath(filename);
3541 string org_path = path;
3542 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3546 Path p(path); // path to LaTeX file
3547 users->owner()->getMiniBuffer()->Set(_("Running chktex..."));
3549 // Remove all error insets
3550 bool removedErrorInsets = users->removeAutoInsets();
3552 // Generate the LaTeX file if neccessary
3553 makeLaTeXFile(name, org_path, false);
3556 Chktex chktex(lyxrc.chktex_command, name, filepath);
3557 int res = chktex.run(terr); // run chktex
3560 WriteAlert(_("chktex did not work!"),
3561 _("Could not run with file:"), name);
3562 } else if (res > 0) {
3563 // Insert all errors as errors boxes
3564 users->insertErrors(terr);
3567 // if we removed error insets before we ran chktex or if we inserted
3568 // error insets after we ran chktex, this must be run:
3569 if (removedErrorInsets || res){
3572 //users->updateScrollbar();
3580 void Buffer::validate(LaTeXFeatures & features) const
3582 LyXParagraph * par = paragraph;
3583 LyXTextClass const & tclass =
3584 textclasslist.TextClass(params.textclass);
3586 // AMS Style is at document level
3588 features.amsstyle = (params.use_amsmath ||
3589 tclass.provides(LyXTextClass::amsmath));
3592 // We don't use "lyxerr.debug" because of speed. (Asger)
3593 if (lyxerr.debugging(Debug::LATEX))
3594 lyxerr << "Paragraph: " << par << endl;
3596 // Now just follow the list of paragraphs and run
3597 // validate on each of them.
3598 par->validate(features);
3600 // and then the next paragraph
3604 // the bullet shapes are buffer level not paragraph level
3605 // so they are tested here
3606 for (int i = 0; i < 4; ++i) {
3607 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
3608 int font = params.user_defined_bullets[i].getFont();
3611 .user_defined_bullets[i]
3618 features.latexsym = true;
3622 features.amssymb = true;
3624 else if ((font >= 2 && font <= 5)) {
3625 features.pifont = true;
3630 if (lyxerr.debugging(Debug::LATEX)) {
3631 features.showStruct();
3636 void Buffer::setPaperStuff()
3638 params.papersize = BufferParams::PAPER_DEFAULT;
3639 char c1 = params.paperpackage;
3640 if (c1 == BufferParams::PACKAGE_NONE) {
3641 char c2 = params.papersize2;
3642 if (c2 == BufferParams::VM_PAPER_USLETTER)
3643 params.papersize = BufferParams::PAPER_USLETTER;
3644 else if (c2 == BufferParams::VM_PAPER_USLEGAL)
3645 params.papersize = BufferParams::PAPER_LEGALPAPER;
3646 else if (c2 == BufferParams::VM_PAPER_USEXECUTIVE)
3647 params.papersize = BufferParams::PAPER_EXECUTIVEPAPER;
3648 else if (c2 == BufferParams::VM_PAPER_A3)
3649 params.papersize = BufferParams::PAPER_A3PAPER;
3650 else if (c2 == BufferParams::VM_PAPER_A4)
3651 params.papersize = BufferParams::PAPER_A4PAPER;
3652 else if (c2 == BufferParams::VM_PAPER_A5)
3653 params.papersize = BufferParams::PAPER_A5PAPER;
3654 else if ((c2 == BufferParams::VM_PAPER_B3) || (c2 == BufferParams::VM_PAPER_B4) ||
3655 (c2 == BufferParams::VM_PAPER_B5))
3656 params.papersize = BufferParams::PAPER_B5PAPER;
3657 } else if ((c1 == BufferParams::PACKAGE_A4) || (c1 == BufferParams::PACKAGE_A4WIDE) ||
3658 (c1 == BufferParams::PACKAGE_WIDEMARGINSA4))
3659 params.papersize = BufferParams::PAPER_A4PAPER;
3663 // This function should be in Buffer because it's a buffer's property (ale)
3664 string Buffer::getIncludeonlyList(char delim)
3667 for (inset_iterator it = inset_iterator_begin();
3668 it != inset_iterator_end(); ++it) {
3669 if ((*it)->LyxCode() == Inset::INCLUDE_CODE) {
3670 InsetInclude * insetinc =
3671 static_cast<InsetInclude *>(*it);
3672 if (insetinc->isInclude()
3673 && insetinc->isNoLoad()) {
3676 lst += OnlyFilename(ChangeExtension(insetinc->getContents(), string()));
3680 lyxerr.debug() << "Includeonly(" << lst << ')' << endl;
3685 vector<string> Buffer::getLabelList()
3687 /// if this is a child document and the parent is already loaded
3688 /// Use the parent's list instead [ale990407]
3689 if (!params.parentname.empty()
3690 && bufferlist.exists(params.parentname)) {
3691 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3693 return tmp->getLabelList();
3696 vector<string> label_list;
3697 for (inset_iterator it = inset_iterator_begin();
3698 it != inset_iterator_end(); ++it) {
3699 vector<string> l = (*it)->getLabelList();
3700 label_list.insert(label_list.end(), l.begin(), l.end());
3706 vector<vector<Buffer::TocItem> > Buffer::getTocList()
3708 vector<vector<TocItem> > l(4);
3709 LyXParagraph * par = paragraph;
3712 if (par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
3713 if (textclasslist.Style(params.textclass,
3714 par->GetLayout()).labeltype
3715 == LABEL_SENSITIVE) {
3719 tmp.str = par->String(this, false);
3720 switch (par->footnotekind) {
3721 case LyXParagraph::FIG:
3722 case LyXParagraph::WIDE_FIG:
3723 l[TOC_LOF].push_back(tmp);
3725 case LyXParagraph::TAB:
3726 case LyXParagraph::WIDE_TAB:
3727 l[TOC_LOT].push_back(tmp);
3729 case LyXParagraph::ALGORITHM:
3730 l[TOC_LOA].push_back(tmp);
3732 case LyXParagraph::FOOTNOTE:
3733 case LyXParagraph::MARGIN:
3737 } else if (!par->IsDummy()) {
3739 char labeltype = textclasslist.Style(params.textclass,
3740 par->GetLayout()).labeltype;
3742 if (labeltype >= LABEL_COUNTER_CHAPTER
3743 && labeltype <= LABEL_COUNTER_CHAPTER + params.tocdepth) {
3744 // insert this into the table of contents
3749 textclasslist.TextClass(params.textclass).maxcounter());
3750 tmp.str = par->String(this, true);
3751 l[TOC_TOC].push_back(tmp);
3761 // This is also a buffer property (ale)
3762 vector<pair<string,string> > Buffer::getBibkeyList()
3764 /// if this is a child document and the parent is already loaded
3765 /// Use the parent's list instead [ale990412]
3766 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3767 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3769 return tmp->getBibkeyList();
3772 vector<pair<string, string> > keys;
3773 LyXParagraph * par = paragraph;
3776 keys.push_back(pair<string, string>(par->bibkey->getContents(),
3777 par->String(this, false)));
3781 // Might be either using bibtex or a child has bibliography
3783 for (inset_iterator it = inset_iterator_begin();
3784 it != inset_iterator_end(); ++it) {
3785 // Search for Bibtex or Include inset
3786 if ((*it)->LyxCode() == Inset::BIBTEX_CODE) {
3787 vector<pair<string,string> > tmp =
3788 static_cast<InsetBibtex*>(*it)->getKeys();
3789 keys.insert(keys.end(), tmp.begin(), tmp.end());
3790 } else if ((*it)->LyxCode() == Inset::INCLUDE_CODE) {
3791 vector<pair<string,string> > tmp =
3792 static_cast<InsetInclude*>(*it)->getKeys();
3793 keys.insert(keys.end(), tmp.begin(), tmp.end());
3802 bool Buffer::isDepClean(string const & name) const
3804 DEPCLEAN * item = dep_clean;
3805 while (item && item->master != name)
3807 if (!item) return true;
3812 void Buffer::markDepClean(string const & name)
3815 dep_clean = new DEPCLEAN;
3816 dep_clean->clean = true;
3817 dep_clean->master = name;
3818 dep_clean->next = 0;
3820 DEPCLEAN* item = dep_clean;
3821 while (item && item->master != name)
3826 item = new DEPCLEAN;
3828 item->master = name;
3835 bool Buffer::Dispatch(string const & command)
3837 // Split command string into command and argument
3838 string cmd, line = frontStrip(command);
3839 string arg = strip(frontStrip(split(line, cmd, ' ')));
3841 return Dispatch(lyxaction.LookupFunc(cmd.c_str()), arg.c_str());
3845 bool Buffer::Dispatch(int action, string const & argument)
3847 bool dispatched = true;
3851 Exporter::Export(this, argument, false);
3853 MenuExport(this, argument);
3864 void Buffer::resize()
3866 /// resize the BufferViews!
3872 void Buffer::resizeInsets(BufferView * bv)
3874 /// then remove all LyXText in text-insets
3875 LyXParagraph * par = paragraph;
3876 for(;par;par = par->next) {
3877 par->resizeInsetsLyXText(bv);
3881 void Buffer::ChangeLanguage(Language const * from, Language const * to)
3884 LyXParagraph * par = paragraph;
3886 par->ChangeLanguage(params, from, to);
3892 bool Buffer::isMultiLingual()
3895 LyXParagraph * par = paragraph;
3897 if (par->isMultiLingual(params))
3905 Buffer::inset_iterator::inset_iterator(LyXParagraph * paragraph,
3906 LyXParagraph::size_type pos)
3908 it = par->InsetIterator(pos);
3909 if (it == par->inset_iterator_end()) {
3916 void Buffer::inset_iterator::SetParagraph() {
3918 it = par->inset_iterator_begin();
3919 if (it != par->inset_iterator_end())
3924 // We maintain an invariant that whenever par = 0 then it = 0