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/insetlof.h"
60 #include "insets/insetlot.h"
61 #include "insets/insetloa.h"
62 #include "insets/insetparent.h"
63 #include "insets/insetspecialchar.h"
64 #include "insets/figinset.h"
65 #include "insets/insettext.h"
66 #include "insets/insetert.h"
67 #include "insets/insetgraphics.h"
68 #include "insets/insetfoot.h"
69 #include "insets/insettabular.h"
70 #include "support/filetools.h"
71 #include "support/path.h"
77 #include "LaTeXFeatures.h"
78 #include "support/syscall.h"
79 #include "support/lyxlib.h"
80 #include "support/FileInfo.h"
84 #include "lyx_gui_misc.h" // WarnReadonly()
85 #include "frontends/Dialogs.h"
98 // all these externs should eventually be removed.
99 extern BufferList bufferlist;
101 extern void MenuExport(Buffer *, string const &);
102 extern LyXAction lyxaction;
105 static const float LYX_FORMAT = 2.16;
107 extern int tex_code_break_column;
110 Buffer::Buffer(string const & file, bool ronly)
112 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
114 filepath = OnlyPath(file);
122 if (read_only || (lyxrc.use_tempdir)) {
123 tmppath = CreateBufferTmpDir();
124 } else tmppath.erase();
130 lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
131 // here the buffer should take care that it is
132 // saved properly, before it goes into the void.
134 // make sure that views using this buffer
139 if (!tmppath.empty()) {
140 DestroyBufferTmpDir(tmppath);
143 LyXParagraph * par = paragraph;
144 LyXParagraph * tmppar;
154 string Buffer::getLatexName(bool no_path) const
157 return OnlyFilename(ChangeExtension(MakeLatexName(filename),
160 return ChangeExtension(MakeLatexName(filename),
165 void Buffer::setReadonly(bool flag)
167 if (read_only != flag) {
170 users->owner()->getDialogs()->updateBufferDependent();
173 WarnReadonly(filename);
178 bool Buffer::saveParamsAsDefaults()
180 string fname = AddName(AddPath(user_lyxdir, "templates/"),
182 Buffer defaults = Buffer(fname);
184 // Use the current buffer's parameters as default
185 defaults.params = params;
187 // add an empty paragraph. Is this enough?
188 defaults.paragraph = new LyXParagraph;
190 return defaults.writeFile(defaults.filename, false);
194 /// Update window titles of all users
195 // Should work on a list
196 void Buffer::updateTitles() const
198 if (users) users->owner()->updateWindowTitle();
202 /// Reset autosave timer of all users
203 // Should work on a list
204 void Buffer::resetAutosaveTimers() const
206 if (users) users->owner()->resetAutosaveTimer();
210 void Buffer::fileName(string const & newfile)
212 filename = MakeAbsPath(newfile);
213 filepath = OnlyPath(filename);
214 setReadonly(IsFileWriteable(filename) == 0);
219 // candidate for move to BufferView
220 // (at least some parts in the beginning of the func)
223 // changed to be public and have one parameter
224 // if par = 0 normal behavior
225 // else insert behavior
226 // Returns false if "\the_end" is not read for formats >= 2.13. (Asger)
227 #define USE_PARSE_FUNCTION 1
228 //#define USE_TABULAR_INSETS 1
229 bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par)
233 char depth = 0; // signed or unsigned?
234 LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
235 LyXParagraph::footnote_kind footnotekind = LyXParagraph::FOOTNOTE;
236 bool the_end_read = false;
238 LyXParagraph * return_par = 0;
239 LyXFont font(LyXFont::ALL_INHERIT, params.language_info);
240 if (format < 2.16 && params.language == "hebrew")
241 font.setLanguage(default_language);
243 // If we are inserting, we cheat and get a token in advance
244 bool has_token = false;
248 par = new LyXParagraph;
250 users->text->BreakParagraph(users);
251 return_par = users->text->FirstParagraph();
254 // We don't want to adopt the parameters from the
255 // document we insert, so we skip until the text begins:
258 pretoken = lex.GetString();
259 if (pretoken == "\\layout") {
271 pretoken = lex.GetString();
274 // Profiling show this should give a lot: (Asger)
275 string const token = pretoken;
279 the_end_read = parseSingleLyXformat2Token(lex, par, return_par,
288 paragraph = return_par;
295 Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
296 LyXParagraph *& return_par,
297 string const & token, int & pos,
298 char & depth, LyXFont & font,
299 LyXParagraph::footnote_flag & footnoteflag,
300 LyXParagraph::footnote_kind & footnotekind)
302 bool the_end_read = false;
304 if (token[0] != '\\') {
305 for (string::const_iterator cit = token.begin();
306 cit != token.end(); ++cit) {
307 par->InsertChar(pos, (*cit));
308 par->SetFont(pos, font);
311 } else if (token == "\\i") {
312 Inset * inset = new InsetLatexAccent;
313 inset->Read(this, lex);
314 par->InsertChar(pos, LyXParagraph::META_INSET);
315 par->InsertInset(pos, inset);
316 par->SetFont(pos, font);
318 } else if (token == "\\layout") {
323 par = new LyXParagraph(par);
327 string layoutname = lex.GetString();
328 pair<bool, LyXTextClass::LayoutList::size_type> pp
329 = textclasslist.NumberOfLayout(params.textclass,
332 par->layout = pp.second;
333 } else { // layout not found
334 // use default layout "Standard" (0)
337 // Test whether the layout is obsolete.
338 LyXLayout const & layout =
339 textclasslist.Style(params.textclass,
341 if (!layout.obsoleted_by().empty())
343 textclasslist.NumberOfLayout(params.textclass,
344 layout.obsoleted_by()).second;
345 par->footnoteflag = footnoteflag;
346 par->footnotekind = footnotekind;
348 font = LyXFont(LyXFont::ALL_INHERIT, params.language_info);
349 if (format < 2.16 && params.language == "hebrew")
350 font.setLanguage(default_language);
351 } else if (token == "\\end_float") {
356 par = new LyXParagraph(par);
358 footnotekind = LyXParagraph::FOOTNOTE;
359 footnoteflag = LyXParagraph::NO_FOOTNOTE;
362 par->layout = LYX_DUMMY_LAYOUT;
363 font = LyXFont(LyXFont::ALL_INHERIT, params.language_info);
364 if (format < 2.16 && params.language == "hebrew")
365 font.setLanguage(default_language);
366 } else if (token == "\\begin_float") {
367 int tmpret = lex.FindToken(string_footnotekinds);
368 if (tmpret == -1) ++tmpret;
369 if (tmpret != LYX_LAYOUT_DEFAULT)
370 footnotekind = static_cast<LyXParagraph::footnote_kind>(tmpret); // bad
371 if (footnotekind == LyXParagraph::FOOTNOTE
372 || footnotekind == LyXParagraph::MARGIN)
373 footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
375 footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
376 } else if (token == "\\begin_deeper") {
378 } else if (token == "\\end_deeper") {
380 lex.printError("\\end_deeper: "
381 "depth is already null");
385 } else if (token == "\\begin_preamble") {
386 params.readPreamble(lex);
387 } else if (token == "\\textclass") {
389 pair<bool, LyXTextClassList::size_type> pp =
390 textclasslist.NumberOfClass(lex.GetString());
392 params.textclass = pp.second;
394 lex.printError("Unknown textclass `$$Token'");
395 params.textclass = 0;
397 if (!textclasslist.Load(params.textclass)) {
398 // if the textclass wasn't loaded properly
399 // we need to either substitute another
400 // or stop loading the file.
401 // I can substitute but I don't see how I can
402 // stop loading... ideas?? ARRae980418
403 WriteAlert(_("Textclass Loading Error!"),
404 string(_("Can't load textclass ")) +
405 textclasslist.NameOfClass(params.textclass),
406 _("-- substituting default"));
407 params.textclass = 0;
409 } else if (token == "\\options") {
411 params.options = lex.GetString();
412 } else if (token == "\\language") {
413 params.readLanguage(lex);
414 } else if (token == "\\fontencoding") {
416 } else if (token == "\\inputencoding") {
418 params.inputenc = lex.GetString();
419 } else if (token == "\\graphics") {
420 params.readGraphicsDriver(lex);
421 } else if (token == "\\fontscheme") {
423 params.fonts = lex.GetString();
424 } else if (token == "\\noindent") {
425 par->noindent = true;
426 } else if (token == "\\fill_top") {
427 par->added_space_top = VSpace(VSpace::VFILL);
428 } else if (token == "\\fill_bottom") {
429 par->added_space_bottom = VSpace(VSpace::VFILL);
430 } else if (token == "\\line_top") {
431 par->line_top = true;
432 } else if (token == "\\line_bottom") {
433 par->line_bottom = true;
434 } else if (token == "\\pagebreak_top") {
435 par->pagebreak_top = true;
436 } else if (token == "\\pagebreak_bottom") {
437 par->pagebreak_bottom = true;
438 } else if (token == "\\start_of_appendix") {
439 par->start_of_appendix = true;
440 } else if (token == "\\paragraph_separation") {
441 int tmpret = lex.FindToken(string_paragraph_separation);
442 if (tmpret == -1) ++tmpret;
443 if (tmpret != LYX_LAYOUT_DEFAULT)
444 params.paragraph_separation =
445 static_cast<BufferParams::PARSEP>(tmpret);
446 } else if (token == "\\defskip") {
448 params.defskip = VSpace(lex.GetString());
449 } else if (token == "\\epsfig") { // obsolete
450 // Indeed it is obsolete, but we HAVE to be backwards
451 // compatible until 0.14, because otherwise all figures
452 // in existing documents are irretrivably lost. (Asger)
453 params.readGraphicsDriver(lex);
454 } else if (token == "\\quotes_language") {
455 int tmpret = lex.FindToken(string_quotes_language);
456 if (tmpret == -1) ++tmpret;
457 if (tmpret != LYX_LAYOUT_DEFAULT) {
458 InsetQuotes::quote_language tmpl =
459 InsetQuotes::EnglishQ;
462 tmpl = InsetQuotes::EnglishQ;
465 tmpl = InsetQuotes::SwedishQ;
468 tmpl = InsetQuotes::GermanQ;
471 tmpl = InsetQuotes::PolishQ;
474 tmpl = InsetQuotes::FrenchQ;
477 tmpl = InsetQuotes::DanishQ;
480 params.quotes_language = tmpl;
482 } else if (token == "\\quotes_times") {
484 switch(lex.GetInteger()) {
486 params.quotes_times = InsetQuotes::SingleQ;
489 params.quotes_times = InsetQuotes::DoubleQ;
492 } else if (token == "\\papersize") {
493 int tmpret = lex.FindToken(string_papersize);
497 params.papersize2 = tmpret;
498 } else if (token == "\\paperpackage") {
499 int tmpret = lex.FindToken(string_paperpackages);
502 params.paperpackage = BufferParams::PACKAGE_NONE;
504 params.paperpackage = tmpret;
505 } else if (token == "\\use_geometry") {
507 params.use_geometry = lex.GetInteger();
508 } else if (token == "\\use_amsmath") {
510 params.use_amsmath = lex.GetInteger();
511 } else if (token == "\\paperorientation") {
512 int tmpret = lex.FindToken(string_orientation);
513 if (tmpret == -1) ++tmpret;
514 if (tmpret != LYX_LAYOUT_DEFAULT)
515 params.orientation = static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
516 } else if (token == "\\paperwidth") {
518 params.paperwidth = lex.GetString();
519 } else if (token == "\\paperheight") {
521 params.paperheight = lex.GetString();
522 } else if (token == "\\leftmargin") {
524 params.leftmargin = lex.GetString();
525 } else if (token == "\\topmargin") {
527 params.topmargin = lex.GetString();
528 } else if (token == "\\rightmargin") {
530 params.rightmargin = lex.GetString();
531 } else if (token == "\\bottommargin") {
533 params.bottommargin = lex.GetString();
534 } else if (token == "\\headheight") {
536 params.headheight = lex.GetString();
537 } else if (token == "\\headsep") {
539 params.headsep = lex.GetString();
540 } else if (token == "\\footskip") {
542 params.footskip = lex.GetString();
543 } else if (token == "\\paperfontsize") {
545 params.fontsize = strip(lex.GetString());
546 } else if (token == "\\papercolumns") {
548 params.columns = lex.GetInteger();
549 } else if (token == "\\papersides") {
551 switch(lex.GetInteger()) {
553 case 1: params.sides = LyXTextClass::OneSide; break;
554 case 2: params.sides = LyXTextClass::TwoSides; break;
556 } else if (token == "\\paperpagestyle") {
558 params.pagestyle = strip(lex.GetString());
559 } else if (token == "\\bullet") {
561 int index = lex.GetInteger();
563 int temp_int = lex.GetInteger();
564 params.user_defined_bullets[index].setFont(temp_int);
565 params.temp_bullets[index].setFont(temp_int);
567 temp_int = lex.GetInteger();
568 params.user_defined_bullets[index].setCharacter(temp_int);
569 params.temp_bullets[index].setCharacter(temp_int);
571 temp_int = lex.GetInteger();
572 params.user_defined_bullets[index].setSize(temp_int);
573 params.temp_bullets[index].setSize(temp_int);
575 string temp_str = lex.GetString();
576 if (temp_str != "\\end_bullet") {
577 // this element isn't really necessary for
578 // parsing but is easier for humans
579 // to understand bullets. Put it back and
580 // set a debug message?
581 lex.printError("\\end_bullet expected, got" + temp_str);
582 //how can I put it back?
584 } else if (token == "\\bulletLaTeX") {
586 int index = lex.GetInteger();
588 string temp_str = lex.GetString(), sum_str;
589 while (temp_str != "\\end_bullet") {
590 // this loop structure is needed when user
591 // enters an empty string since the first
592 // thing returned will be the \\end_bullet
594 // if the LaTeX entry has spaces. Each element
595 // therefore needs to be read in turn
598 temp_str = lex.GetString();
600 params.user_defined_bullets[index].setText(sum_str);
601 params.temp_bullets[index].setText(sum_str);
602 } else if (token == "\\secnumdepth") {
604 params.secnumdepth = lex.GetInteger();
605 } else if (token == "\\tocdepth") {
607 params.tocdepth = lex.GetInteger();
608 } else if (token == "\\spacing") {
610 string tmp = strip(lex.GetString());
611 Spacing::Space tmp_space = Spacing::Default;
613 if (tmp == "single") {
614 tmp_space = Spacing::Single;
615 } else if (tmp == "onehalf") {
616 tmp_space = Spacing::Onehalf;
617 } else if (tmp == "double") {
618 tmp_space = Spacing::Double;
619 } else if (tmp == "other") {
621 tmp_space = Spacing::Other;
622 tmp_val = lex.GetFloat();
624 lex.printError("Unknown spacing token: '$$Token'");
626 // Small hack so that files written with klyx will be
629 par->spacing.set(tmp_space, tmp_val);
631 params.spacing.set(tmp_space, tmp_val);
633 } else if (token == "\\paragraph_spacing") {
635 string tmp = strip(lex.GetString());
636 if (tmp == "single") {
637 par->spacing.set(Spacing::Single);
638 } else if (tmp == "onehalf") {
639 par->spacing.set(Spacing::Onehalf);
640 } else if (tmp == "double") {
641 par->spacing.set(Spacing::Double);
642 } else if (tmp == "other") {
644 par->spacing.set(Spacing::Other,
647 lex.printError("Unknown spacing token: '$$Token'");
649 } else if (token == "\\float_placement") {
651 params.float_placement = lex.GetString();
653 } else if (token == "\\cursor") { // obsolete
654 // this is obsolete, so we just skip it.
657 } else if (token == "\\family") {
659 font.setLyXFamily(lex.GetString());
660 } else if (token == "\\series") {
662 font.setLyXSeries(lex.GetString());
663 } else if (token == "\\shape") {
665 font.setLyXShape(lex.GetString());
666 } else if (token == "\\size") {
668 font.setLyXSize(lex.GetString());
669 } else if (token == "\\latex") {
671 string tok = lex.GetString();
672 // This is dirty, but gone with LyX3. (Asger)
673 if (tok == "no_latex")
674 font.setLatex(LyXFont::OFF);
675 else if (tok == "latex")
676 font.setLatex(LyXFont::ON);
677 else if (tok == "default")
678 font.setLatex(LyXFont::INHERIT);
680 lex.printError("Unknown LaTeX font flag "
682 } else if (token == "\\lang") {
684 string tok = lex.GetString();
685 Languages::iterator lit = languages.find(tok);
686 if (lit != languages.end()) {
687 font.setLanguage(&(*lit).second);
689 font.setLanguage(params.language_info);
690 lex.printError("Unknown language `$$Token'");
692 } else if (token == "\\emph") {
694 font.setEmph(font.setLyXMisc(lex.GetString()));
695 } else if (token == "\\bar") {
697 string tok = lex.GetString();
698 // This is dirty, but gone with LyX3. (Asger)
700 font.setUnderbar(LyXFont::ON);
701 else if (tok == "no")
702 font.setUnderbar(LyXFont::OFF);
703 else if (tok == "default")
704 font.setUnderbar(LyXFont::INHERIT);
706 lex.printError("Unknown bar font flag "
708 } else if (token == "\\noun") {
710 font.setNoun(font.setLyXMisc(lex.GetString()));
711 } else if (token == "\\color") {
713 font.setLyXColor(lex.GetString());
714 } else if (token == "\\align") {
715 int tmpret = lex.FindToken(string_align);
716 if (tmpret == -1) ++tmpret;
717 if (tmpret != LYX_LAYOUT_DEFAULT) { // tmpret != 99 ???
719 for (; tmpret > 0; --tmpret)
720 tmpret2 = tmpret2 * 2;
721 par->align = LyXAlignment(tmpret2);
723 } else if (token == "\\added_space_top") {
725 par->added_space_top = VSpace(lex.GetString());
726 } else if (token == "\\added_space_bottom") {
728 par->added_space_bottom = VSpace(lex.GetString());
729 } else if (token == "\\pextra_type") {
731 par->pextra_type = lex.GetInteger();
732 } else if (token == "\\pextra_width") {
734 par->pextra_width = lex.GetString();
735 } else if (token == "\\pextra_widthp") {
737 par->pextra_widthp = lex.GetString();
738 } else if (token == "\\pextra_alignment") {
740 par->pextra_alignment = lex.GetInteger();
741 } else if (token == "\\pextra_hfill") {
743 par->pextra_hfill = lex.GetInteger();
744 } else if (token == "\\pextra_start_minipage") {
746 par->pextra_start_minipage = lex.GetInteger();
747 } else if (token == "\\labelwidthstring") {
749 par->labelwidthstring = lex.GetString();
750 // do not delete this token, it is still needed!
751 } else if (token == "\\end_inset") {
752 // Simply ignore this. The insets do not have
754 // But insets should read it, it is a part of
755 // the inset isn't it? Lgb.
756 } else if (token == "\\begin_inset") {
757 // Should be moved out into its own function/method. (Lgb)
759 string tmptok = lex.GetString();
760 // test the different insets
761 if (tmptok == "Quotes") {
762 Inset * inset = new InsetQuotes;
763 inset->Read(this, lex);
764 par->InsertChar(pos, LyXParagraph::META_INSET);
765 par->InsertInset(pos, inset);
766 par->SetFont(pos, font);
769 } else if (tmptok == "\\i") {
770 Inset * inset = new InsetLatexAccent;
771 inset->Read(this, lex);
772 par->InsertChar(pos, LyXParagraph::META_INSET);
773 par->InsertInset(pos, inset);
774 par->SetFont(pos, font);
777 } else if (tmptok == "External") {
778 Inset * inset = new InsetExternal;
779 inset->Read(this, lex);
780 par->InsertChar(pos, LyXParagraph::META_INSET);
781 par->InsertInset(pos, inset);
782 par->SetFont(pos, font);
784 } else if (tmptok == "FormulaMacro") {
785 Inset * inset = new InsetFormulaMacro;
786 inset->Read(this, lex);
787 par->InsertChar(pos, LyXParagraph::META_INSET);
788 par->InsertInset(pos, inset);
789 par->SetFont(pos, font);
791 } else if (tmptok == "Formula") {
792 Inset * inset = new InsetFormula;
793 inset->Read(this, lex);
794 par->InsertChar(pos, LyXParagraph::META_INSET);
795 par->InsertInset(pos, inset);
796 par->SetFont(pos, font);
798 } else if (tmptok == "Figure") {
799 Inset * inset = new InsetFig(100, 100, this);
800 inset->Read(this, lex);
801 par->InsertChar(pos, LyXParagraph::META_INSET);
802 par->InsertInset(pos, inset);
803 par->SetFont(pos, font);
805 } else if (tmptok == "Info") {
806 Inset * inset = new InsetInfo;
807 inset->Read(this, lex);
808 par->InsertChar(pos, LyXParagraph::META_INSET);
809 par->InsertInset(pos, inset);
810 par->SetFont(pos, font);
812 } else if (tmptok == "Include") {
813 Inset * inset = new InsetInclude(string(), this);
814 inset->Read(this, lex);
815 par->InsertChar(pos, LyXParagraph::META_INSET);
816 par->InsertInset(pos, inset);
817 par->SetFont(pos, font);
819 } else if (tmptok == "ERT") {
820 Inset * inset = new InsetERT();
821 inset->Read(this, lex);
822 par->InsertChar(pos, LyXParagraph::META_INSET);
823 par->InsertInset(pos, inset);
824 par->SetFont(pos, font);
826 } else if (tmptok == "Tabular") {
827 Inset * inset = new InsetTabular(this);
828 inset->Read(this, lex);
829 par->InsertChar(pos, LyXParagraph::META_INSET);
830 par->InsertInset(pos, inset);
831 par->SetFont(pos, font);
833 } else if (tmptok == "Text") {
834 Inset * inset = new InsetText();
835 inset->Read(this, lex);
836 par->InsertChar(pos, LyXParagraph::META_INSET);
837 par->InsertInset(pos, inset);
838 par->SetFont(pos, font);
840 } else if (tmptok == "Foot") {
841 Inset * inset = new InsetFoot();
842 inset->Read(this, lex);
843 par->InsertChar(pos, LyXParagraph::META_INSET);
844 par->InsertInset(pos, inset);
845 par->SetFont(pos, font);
847 } else if (tmptok == "GRAPHICS") {
848 Inset * inset = new InsetGraphics;
849 //inset->Read(this, lex);
850 par->InsertChar(pos, LyXParagraph::META_INSET);
851 par->InsertInset(pos, inset);
852 par->SetFont(pos, font);
853 } else if (tmptok == "LatexCommand") {
855 inscmd.Read(this, lex);
857 if (inscmd.getCmdName() == "cite") {
858 inset = new InsetCitation(inscmd.getContents(), inscmd.getOptions());
859 } else if (inscmd.getCmdName() == "bibitem") {
860 lex.printError("Wrong place for bibitem");
861 inset = inscmd.Clone();
862 } else if (inscmd.getCmdName() == "BibTeX") {
863 inset = new InsetBibtex(inscmd.getContents(), inscmd.getOptions(), this);
864 } else if (inscmd.getCmdName() == "index") {
865 inset = new InsetIndex(inscmd.getContents());
866 } else if (inscmd.getCmdName() == "include") {
867 inset = new InsetInclude(inscmd.getContents(), this);
868 } else if (inscmd.getCmdName() == "label") {
869 inset = new InsetLabel(inscmd.getCommand());
870 } else if (inscmd.getCmdName() == "url"
871 || inscmd.getCmdName() == "htmlurl") {
872 inset = new InsetUrl(inscmd.getCommand());
873 } else if (inscmd.getCmdName() == "ref"
874 || inscmd.getCmdName() == "pageref"
875 || inscmd.getCmdName() == "vref"
876 || inscmd.getCmdName() == "vpageref"
877 || inscmd.getCmdName() == "prettyref") {
878 if (!inscmd.getOptions().empty() || !inscmd.getContents().empty()) {
879 inset = new InsetRef(inscmd, this);
881 } else if (inscmd.getCmdName() == "tableofcontents") {
882 inset = new InsetTOC(this);
883 } else if (inscmd.getCmdName() == "listoffigures") {
884 inset = new InsetLOF(this);
885 } else if (inscmd.getCmdName() == "listofalgorithms") {
886 inset = new InsetLOA(this);
887 } else if (inscmd.getCmdName() == "listoftables") {
888 inset = new InsetLOT(this);
889 } else if (inscmd.getCmdName() == "printindex") {
890 inset = new InsetPrintIndex(this);
891 } else if (inscmd.getCmdName() == "lyxparent") {
892 inset = new InsetParent(inscmd.getContents(), this);
896 par->InsertChar(pos, LyXParagraph::META_INSET);
897 par->InsertInset(pos, inset);
898 par->SetFont(pos, font);
902 } else if (token == "\\SpecialChar") {
903 LyXLayout const & layout =
904 textclasslist.Style(params.textclass,
907 // Insets don't make sense in a free-spacing context! ---Kayvan
908 if (layout.free_spacing) {
912 next_token = lex.GetString();
913 if (next_token == "\\-") {
914 par->InsertChar(pos, '-');
915 par->SetFont(pos, font);
916 } else if (next_token == "\\protected_separator"
917 || next_token == "~") {
918 par->InsertChar(pos, ' ');
919 par->SetFont(pos, font);
921 lex.printError("Token `$$Token' "
923 "paragraph layout!");
928 Inset * inset = new InsetSpecialChar;
929 inset->Read(this, lex);
930 par->InsertChar(pos, LyXParagraph::META_INSET);
931 par->InsertInset(pos, inset);
932 par->SetFont(pos, font);
935 } else if (token == "\\newline") {
936 par->InsertChar(pos, LyXParagraph::META_NEWLINE);
937 par->SetFont(pos, font);
939 } else if (token == "\\LyXTable") {
940 #ifdef USE_TABULAR_INSETS
941 Inset * inset = new InsetTabular(this);
942 inset->Read(this, lex);
943 par->InsertChar(pos, LyXParagraph::META_INSET);
944 par->InsertInset(pos, inset);
945 par->SetFont(pos, font);
948 par->table = new LyXTable(lex);
950 } else if (token == "\\hfill") {
951 par->InsertChar(pos, LyXParagraph::META_HFILL);
952 par->SetFont(pos, font);
954 } else if (token == "\\protected_separator") { // obsolete
955 // This is a backward compability thingie. (Lgb)
956 // Remove it later some time...introduced with fileformat
958 LyXLayout const & layout =
959 textclasslist.Style(params.textclass,
962 if (layout.free_spacing) {
963 par->InsertChar(pos, ' ');
964 par->SetFont(pos, font);
966 Inset * inset = new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
967 par->InsertChar(pos, LyXParagraph::META_INSET);
968 par->InsertInset(pos, inset);
969 par->SetFont(pos, font);
972 } else if (token == "\\bibitem") { // ale970302
974 par->bibkey = new InsetBibKey;
975 par->bibkey->Read(this, lex);
976 }else if (token == "\\backslash") {
977 par->InsertChar(pos, '\\');
978 par->SetFont(pos, font);
980 }else if (token == "\\the_end") {
983 // This should be insurance for the future: (Asger)
984 lex.printError("Unknown token `$$Token'. "
985 "Inserting as text.");
986 for(string::const_iterator cit = token.begin();
987 cit != token.end(); ++cit) {
988 par->InsertChar(pos, (*cit));
989 par->SetFont(pos, font);
996 bool Buffer::readFile(LyXLex & lex, LyXParagraph * par)
1002 token = lex.GetString();
1003 if (token == "\\lyxformat") { // the first token _must_ be...
1005 format = lex.GetFloat();
1007 if (LYX_FORMAT - format > 0.05) {
1008 printf(_("Warning: need lyxformat %.2f but found %.2f\n"),
1009 LYX_FORMAT, format);
1011 if (format - LYX_FORMAT > 0.05) {
1012 printf(_("ERROR: need lyxformat %.2f but found %.2f\n"),
1013 LYX_FORMAT, format);
1015 bool the_end = readLyXformat2(lex, par);
1016 // Formats >= 2.13 support "\the_end" marker
1023 WriteAlert(_("Warning!"),
1024 _("Reading of document is not complete"),
1025 _("Maybe the document is truncated"));
1026 // We simulate a safe reading anyways to allow
1027 // users to take the chance... (Asger)
1031 WriteAlert(_("ERROR!"),
1032 _("Old LyX file format found. "
1033 "Use LyX 0.10.x to read this!"));
1037 } else { // "\\lyxformat" not found
1038 WriteAlert(_("ERROR!"), _("Not a LyX file!"));
1041 WriteAlert(_("ERROR!"), _("Unable to read file!"));
1047 // Should probably be moved to somewhere else: BufferView? LyXView?
1048 bool Buffer::save() const
1050 // We don't need autosaves in the immediate future. (Asger)
1051 resetAutosaveTimers();
1055 if (lyxrc.make_backup) {
1056 s = fileName() + '~';
1057 if (!lyxrc.backupdir_path.empty())
1058 s = AddName(lyxrc.backupdir_path,
1059 subst(CleanupPath(s),'/','!'));
1061 // Rename is the wrong way of making a backup,
1062 // this is the correct way.
1063 /* truss cp fil fil2:
1064 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
1065 stat("LyXVC.lyx", 0xEFFFF688) = 0
1066 open("LyXVC.lyx", O_RDONLY) = 3
1067 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
1068 fstat(4, 0xEFFFF508) = 0
1069 fstat(3, 0xEFFFF508) = 0
1070 read(3, " # T h i s f i l e w".., 8192) = 5579
1071 write(4, " # T h i s f i l e w".., 5579) = 5579
1072 read(3, 0xEFFFD4A0, 8192) = 0
1075 chmod("LyXVC3.lyx", 0100644) = 0
1076 lseek(0, 0, SEEK_CUR) = 46440
1080 // Should proabaly have some more error checking here.
1081 // Should be cleaned up in 0.13, at least a bit.
1082 // Doing it this way, also makes the inodes stay the same.
1083 // This is still not a very good solution, in particular we
1084 // might loose the owner of the backup.
1085 FileInfo finfo(fileName());
1086 if (finfo.exist()) {
1087 mode_t fmode = finfo.getMode();
1088 struct utimbuf times = {
1089 finfo.getAccessTime(),
1090 finfo.getModificationTime() };
1092 ifstream ifs(fileName().c_str());
1093 ofstream ofs(s.c_str(), ios::out|ios::trunc);
1098 ::chmod(s.c_str(), fmode);
1100 if (::utime(s.c_str(), ×)) {
1101 lyxerr << "utime error." << endl;
1104 lyxerr << "LyX was not able to make "
1105 "backupcopy. Beware." << endl;
1110 if (writeFile(fileName(), false)) {
1113 // now delete the autosavefile
1114 string a = OnlyPath(fileName());
1116 a += OnlyFilename(fileName());
1118 FileInfo fileinfo(a);
1119 if (fileinfo.exist()) {
1120 if (::remove(a.c_str()) != 0) {
1121 WriteFSAlert(_("Could not delete "
1122 "auto-save file!"), a);
1126 // Saving failed, so backup is not backup
1127 if (lyxrc.make_backup) {
1128 ::rename(s.c_str(), fileName().c_str());
1136 // Returns false if unsuccesful
1137 bool Buffer::writeFile(string const & fname, bool flag) const
1139 // if flag is false writeFile will not create any GUI
1140 // warnings, only cerr.
1141 // Needed for autosave in background or panic save (Matthias 120496)
1143 if (read_only && (fname == filename)) {
1144 // Here we should come with a question if we should
1145 // perform the write anyway.
1147 lyxerr << _("Error! Document is read-only: ")
1150 WriteAlert(_("Error! Document is read-only: "),
1155 FileInfo finfo(fname);
1156 if (finfo.exist() && !finfo.writable()) {
1157 // Here we should come with a question if we should
1158 // try to do the save anyway. (i.e. do a chmod first)
1160 lyxerr << _("Error! Cannot write file: ")
1163 WriteFSAlert(_("Error! Cannot write file: "),
1168 ofstream ofs(fname.c_str());
1171 lyxerr << _("Error! Cannot open file: ")
1174 WriteFSAlert(_("Error! Cannot open file: "),
1178 // The top of the file should not be written by params.
1180 // write out a comment in the top of the file
1181 ofs << '#' << LYX_DOCVERSION
1182 << " created this file. For more info see http://www.lyx.org/\n";
1183 ofs.setf(ios::showpoint|ios::fixed);
1185 ofs << "\\lyxformat " << setw(4) << LYX_FORMAT << "\n";
1187 // now write out the buffer paramters.
1188 params.writeFile(ofs);
1190 char footnoteflag = 0;
1193 // this will write out all the paragraphs
1194 // using recursive descent.
1195 paragraph->writeFile(this, ofs, params, footnoteflag, depth);
1197 // Write marker that shows file is complete
1198 ofs << "\n\\the_end" << endl;
1200 // how to check if close went ok?
1205 void Buffer::writeFileAscii(string const & fname, int linelen)
1207 LyXFont font1, font2;
1209 char c, footnoteflag = 0, depth = 0;
1211 LyXParagraph::size_type i;
1212 int j, h, ltype = 0, ltype_depth = 0,
1213 * clen = 0, actcell = 0, actpos = 0, cell = 0, cells = 0,
1216 bool ref_printed = false;
1218 ofstream ofs(fname.c_str());
1220 WriteFSAlert(_("Error: Cannot write file:"), fname);
1224 string fname1 = TmpFileName();
1225 LyXParagraph * par = paragraph;
1229 if (par->footnoteflag != LyXParagraph::NO_FOOTNOTE ||
1231 par->previous->footnoteflag == LyXParagraph::NO_FOOTNOTE){
1233 /* begins a footnote environment ? */
1234 if (footnoteflag != par->footnoteflag) {
1235 footnoteflag = par->footnoteflag;
1237 j = strlen(string_footnotekinds[par->footnotekind])+4;
1238 if (currlinelen + j > linelen)
1241 << string_footnotekinds[par->footnotekind] << "] ";
1246 /* begins or ends a deeper area ?*/
1247 if (depth != par->depth) {
1248 if (par->depth > depth) {
1249 while (par->depth > depth) {
1254 while (par->depth < depth) {
1260 /* First write the layout */
1261 tmp = textclasslist.NameOfLayout(params.textclass, par->layout);
1262 if (tmp == "Itemize") {
1264 ltype_depth = depth+1;
1265 } else if (tmp == "Enumerate") {
1267 ltype_depth = depth+1;
1268 } else if (strstr(tmp.c_str(), "ection")) {
1270 ltype_depth = depth+1;
1271 } else if (strstr(tmp.c_str(), "aragraph")) {
1273 ltype_depth = depth+1;
1274 } else if (tmp == "Description") {
1276 ltype_depth = depth+1;
1277 } else if (tmp == "Abstract") {
1280 } else if (tmp == "Bibliography") {
1288 /* maybe some vertical spaces */
1290 /* the labelwidthstring used in lists */
1294 /* some pagebreaks? */
1298 /* what about the alignment */
1300 /* dummy layout, that means a footnote ended */
1301 footnoteflag = LyXParagraph::NO_FOOTNOTE;
1306 //LyXLayout const & layout =
1307 // textclasslist.Style(params.textclass,
1308 // par->GetLayout()); // unused
1309 //bool free_spc = layout.free_spacing; //unused
1312 /* It might be a table */
1315 if (!lyxrc.ascii_roff_command.empty() &&
1316 lyxrc.ascii_roff_command != "none") {
1317 RoffAsciiTable(ofs, par);
1324 cells = par->table->columns;
1325 clen = new int [cells];
1326 memset(clen, 0, sizeof(int) * cells);
1328 for (i = 0, j = 0, h = 1; i < par->size(); ++i, ++h) {
1329 c = par->GetChar(i);
1330 if (c == LyXParagraph::META_INSET) {
1331 if ((inset = par->GetInset(i))) {
1333 std::ostringstream ost;
1334 inset->Ascii(this, ost);
1335 h += ost.str().length();
1338 inset->Ascii(this, ost);
1340 char * tmp = ost.str();
1346 } else if (c == LyXParagraph::META_NEWLINE) {
1350 j = (++j) % par->table->NumberOfCellsInRow(actcell);
1358 font1 = LyXFont(LyXFont::ALL_INHERIT, params.language_info);
1360 for (i = 0, actpos = 1; i < par->size(); ++i, ++actpos) {
1361 if (!i && !footnoteflag && !noparbreak){
1363 for(j = 0; j < depth; ++j)
1365 currlinelen = depth * 2;
1367 case 0: /* Standard */
1368 case 4: /* (Sub)Paragraph */
1369 case 5: /* Description */
1371 case 6: /* Abstract */
1372 ofs << "Abstract\n\n";
1374 case 7: /* Bibliography */
1376 ofs << "References\n\n";
1381 ofs << par->labelstring << " ";
1384 if (ltype_depth > depth) {
1385 for(j = ltype_depth - 1; j > depth; --j)
1387 currlinelen += (ltype_depth-depth)*2;
1391 for(j = 0; j < cells; ++j) {
1393 for(h = 0; h < (clen[j] + 1);
1398 for(j = 0; j < depth; ++j)
1400 currlinelen = depth * 2;
1401 if (ltype_depth > depth) {
1402 for(j = ltype_depth;
1405 currlinelen += (ltype_depth-depth)*2;
1411 font2 = par->GetFontSettings(params, i);
1412 if (font1.latex() != font2.latex()) {
1413 if (font2.latex() == LyXFont::OFF)
1420 c = par->GetChar(i);
1424 case LyXParagraph::META_INSET:
1425 if ((inset = par->GetInset(i))) {
1427 inset->Ascii(this, ofs);
1428 currlinelen += (ofs.tellp() - fpos);
1429 actpos += (ofs.tellp() - fpos) - 1;
1432 case LyXParagraph::META_NEWLINE:
1435 if (par->table->NumberOfCellsInRow(actcell) <= cell) {
1436 for(j = actpos; j < clen[cell - 1]; ++j)
1439 for(j = 0; j < depth; ++j)
1441 currlinelen = depth*2;
1442 if (ltype_depth > depth) {
1443 for(j = ltype_depth; j > depth; --j)
1445 currlinelen += (ltype_depth-depth) * 2;
1447 for(j = 0; j < cells; ++j) {
1449 for(h = 0; h < (clen[j] + 1); ++h)
1453 for(j = 0; j < depth; ++j)
1455 currlinelen = depth * 2;
1456 if (ltype_depth > depth) {
1457 for(j = ltype_depth;
1460 currlinelen += (ltype_depth-depth)*2;
1466 j < clen[cell - 1]; ++j)
1472 currlinelen = actpos = 0;
1476 for(j = 0; j < depth; ++j)
1478 currlinelen = depth * 2;
1479 if (ltype_depth > depth) {
1480 for(j = ltype_depth;
1483 currlinelen += (ltype_depth - depth) * 2;
1489 case LyXParagraph::META_HFILL:
1496 if (currlinelen > linelen - 10
1497 && c == ' ' && i + 2 < par->size()) {
1499 for(j = 0; j < depth; ++j)
1501 currlinelen = depth * 2;
1502 if (ltype_depth > depth) {
1503 for(j = ltype_depth;
1506 currlinelen += (ltype_depth-depth)*2;
1508 } else if (c != '\0')
1511 lyxerr.debug() << "writeAsciiFile: NULL char in structure." << endl;
1518 for(j = actpos; j < clen[cell - 1]; ++j)
1521 for(j = 0; j < depth; ++j)
1523 currlinelen = depth * 2;
1524 if (ltype_depth > depth) {
1525 for(j = ltype_depth; j > depth; --j)
1527 currlinelen += (ltype_depth - depth) * 2;
1529 for(j = 0; j < cells; ++j) {
1531 for(h = 0; h < (clen[j] + 1); ++h)
1545 void Buffer::makeLaTeXFile(string const & fname,
1546 string const & original_path,
1547 bool nice, bool only_body)
1549 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
1551 niceFile = nice; // this will be used by Insetincludes.
1553 tex_code_break_column = lyxrc.ascii_linelen;
1555 LyXTextClass const & tclass =
1556 textclasslist.TextClass(params.textclass);
1558 ofstream ofs(fname.c_str());
1560 WriteFSAlert(_("Error: Cannot open file: "), fname);
1564 // validate the buffer.
1565 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
1566 LaTeXFeatures features(params, tclass.numLayouts());
1568 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
1571 // The starting paragraph of the coming rows is the
1572 // first paragraph of the document. (Asger)
1573 texrow.start(paragraph, 0);
1575 if (!only_body && nice) {
1576 ofs << "%% " LYX_DOCVERSION " created this file. "
1577 "For more info, see http://www.lyx.org/.\n"
1578 "%% Do not edit unless you really know what "
1583 lyxerr.debug() << "lyx header finished" << endl;
1584 // There are a few differences between nice LaTeX and usual files:
1585 // usual is \batchmode and has a
1586 // special input@path to allow the including of figures
1587 // with either \input or \includegraphics (what figinsets do).
1588 // batchmode is not set if there is a tex_code_break_column.
1589 // In this case somebody is interested in the generated LaTeX,
1590 // so this is OK. input@path is set when the actual parameter
1591 // original_path is set. This is done for usual tex-file, but not
1592 // for nice-latex-file. (Matthias 250696)
1595 // code for usual, NOT nice-latex-file
1596 ofs << "\\batchmode\n"; // changed
1597 // from \nonstopmode
1600 if (!original_path.empty()) {
1601 ofs << "\\makeatletter\n"
1602 << "\\def\\input@path{{"
1603 << original_path << "/}}\n"
1604 << "\\makeatother\n";
1610 ofs << "\\documentclass";
1612 string options; // the document class options.
1614 if (tokenPos(tclass.opt_fontsize(), '|', params.fontsize) >= 0) {
1615 // only write if existing in list (and not default)
1616 options += params.fontsize;
1621 if (!params.use_geometry &&
1622 (params.paperpackage == BufferParams::PACKAGE_NONE)) {
1623 switch (params.papersize) {
1624 case BufferParams::PAPER_A4PAPER:
1625 options += "a4paper,";
1627 case BufferParams::PAPER_USLETTER:
1628 options += "letterpaper,";
1630 case BufferParams::PAPER_A5PAPER:
1631 options += "a5paper,";
1633 case BufferParams::PAPER_B5PAPER:
1634 options += "b5paper,";
1636 case BufferParams::PAPER_EXECUTIVEPAPER:
1637 options += "executivepaper,";
1639 case BufferParams::PAPER_LEGALPAPER:
1640 options += "legalpaper,";
1646 if (params.sides != tclass.sides()) {
1647 switch (params.sides) {
1648 case LyXTextClass::OneSide:
1649 options += "oneside,";
1651 case LyXTextClass::TwoSides:
1652 options += "twoside,";
1659 if (params.columns != tclass.columns()) {
1660 if (params.columns == 2)
1661 options += "twocolumn,";
1663 options += "onecolumn,";
1666 if (!params.use_geometry
1667 && params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1668 options += "landscape,";
1670 // language should be a parameter to \documentclass
1671 bool use_babel = false;
1672 if (params.language_info->RightToLeft()) // This seems necessary
1673 features.UsedLanguages.insert(default_language);
1674 if (params.language != "default" ||
1675 !features.UsedLanguages.empty() ) {
1677 for (LaTeXFeatures::LanguageList::const_iterator cit =
1678 features.UsedLanguages.begin();
1679 cit != features.UsedLanguages.end(); ++cit)
1680 options += (*cit)->lang() + ",";
1681 options += params.language_info->lang() + ',';
1684 // the user-defined options
1685 if (!params.options.empty()) {
1686 options += params.options + ',';
1689 if (!options.empty()){
1690 options = strip(options, ',');
1691 ofs << '[' << options << ']';
1695 << textclasslist.LatexnameOfClass(params.textclass)
1698 // end of \documentclass defs
1700 // font selection must be done before loading fontenc.sty
1701 if (params.fonts != "default") {
1702 ofs << "\\usepackage{" << params.fonts << "}\n";
1705 // this one is not per buffer
1706 if (lyxrc.fontenc != "default") {
1707 ofs << "\\usepackage[" << lyxrc.fontenc
1711 if (params.inputenc != "default") {
1712 ofs << "\\usepackage[" << params.inputenc
1717 // At the very beginning the text parameters.
1718 if (params.paperpackage != BufferParams::PACKAGE_NONE) {
1719 switch (params.paperpackage) {
1720 case BufferParams::PACKAGE_A4:
1721 ofs << "\\usepackage{a4}\n";
1724 case BufferParams::PACKAGE_A4WIDE:
1725 ofs << "\\usepackage{a4wide}\n";
1728 case BufferParams::PACKAGE_WIDEMARGINSA4:
1729 ofs << "\\usepackage[widemargins]{a4}\n";
1734 if (params.use_geometry) {
1735 ofs << "\\usepackage{geometry}\n";
1737 ofs << "\\geometry{verbose";
1738 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1739 ofs << ",landscape";
1740 switch (params.papersize2) {
1741 case BufferParams::VM_PAPER_CUSTOM:
1742 if (!params.paperwidth.empty())
1743 ofs << ",paperwidth="
1744 << params.paperwidth;
1745 if (!params.paperheight.empty())
1746 ofs << ",paperheight="
1747 << params.paperheight;
1749 case BufferParams::VM_PAPER_USLETTER:
1750 ofs << ",letterpaper";
1752 case BufferParams::VM_PAPER_USLEGAL:
1753 ofs << ",legalpaper";
1755 case BufferParams::VM_PAPER_USEXECUTIVE:
1756 ofs << ",executivepaper";
1758 case BufferParams::VM_PAPER_A3:
1761 case BufferParams::VM_PAPER_A4:
1764 case BufferParams::VM_PAPER_A5:
1767 case BufferParams::VM_PAPER_B3:
1770 case BufferParams::VM_PAPER_B4:
1773 case BufferParams::VM_PAPER_B5:
1777 // default papersize ie BufferParams::VM_PAPER_DEFAULT
1778 switch (lyxrc.default_papersize) {
1779 case BufferParams::PAPER_DEFAULT: // keep compiler happy
1780 case BufferParams::PAPER_USLETTER:
1781 ofs << ",letterpaper";
1783 case BufferParams::PAPER_LEGALPAPER:
1784 ofs << ",legalpaper";
1786 case BufferParams::PAPER_EXECUTIVEPAPER:
1787 ofs << ",executivepaper";
1789 case BufferParams::PAPER_A3PAPER:
1792 case BufferParams::PAPER_A4PAPER:
1795 case BufferParams::PAPER_A5PAPER:
1798 case BufferParams::PAPER_B5PAPER:
1803 if (!params.topmargin.empty())
1804 ofs << ",tmargin=" << params.topmargin;
1805 if (!params.bottommargin.empty())
1806 ofs << ",bmargin=" << params.bottommargin;
1807 if (!params.leftmargin.empty())
1808 ofs << ",lmargin=" << params.leftmargin;
1809 if (!params.rightmargin.empty())
1810 ofs << ",rmargin=" << params.rightmargin;
1811 if (!params.headheight.empty())
1812 ofs << ",headheight=" << params.headheight;
1813 if (!params.headsep.empty())
1814 ofs << ",headsep=" << params.headsep;
1815 if (!params.footskip.empty())
1816 ofs << ",footskip=" << params.footskip;
1820 if (params.use_amsmath
1821 && !tclass.provides(LyXTextClass::amsmath)) {
1822 ofs << "\\usepackage{amsmath}\n";
1826 if (tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle) >= 0) {
1827 if (params.pagestyle == "fancy") {
1828 ofs << "\\usepackage{fancyhdr}\n";
1831 ofs << "\\pagestyle{" << params.pagestyle << "}\n";
1835 // We try to load babel late, in case it interferes
1836 // with other packages.
1838 ofs << lyxrc.language_package << endl;
1842 if (params.secnumdepth != tclass.secnumdepth()) {
1843 ofs << "\\setcounter{secnumdepth}{"
1844 << params.secnumdepth
1848 if (params.tocdepth != tclass.tocdepth()) {
1849 ofs << "\\setcounter{tocdepth}{"
1855 if (params.paragraph_separation) {
1856 switch (params.defskip.kind()) {
1857 case VSpace::SMALLSKIP:
1858 ofs << "\\setlength\\parskip{\\smallskipamount}\n";
1860 case VSpace::MEDSKIP:
1861 ofs << "\\setlength\\parskip{\\medskipamount}\n";
1863 case VSpace::BIGSKIP:
1864 ofs << "\\setlength\\parskip{\\bigskipamount}\n";
1866 case VSpace::LENGTH:
1867 ofs << "\\setlength\\parskip{"
1868 << params.defskip.length().asLatexString()
1871 default: // should never happen // Then delete it.
1872 ofs << "\\setlength\\parskip{\\medskipamount}\n";
1877 ofs << "\\setlength\\parindent{0pt}\n";
1881 // Now insert the LyX specific LaTeX commands...
1882 string preamble, tmppreamble;
1884 // The optional packages;
1885 preamble = features.getPackages();
1887 // this might be useful...
1888 preamble += "\n\\makeatletter\n\n";
1890 // Some macros LyX will need
1891 tmppreamble = features.getMacros();
1893 if (!tmppreamble.empty()) {
1894 preamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1895 "LyX specific LaTeX commands.\n"
1896 + tmppreamble + '\n';
1899 // the text class specific preamble
1900 tmppreamble = features.getTClassPreamble();
1901 if (!tmppreamble.empty()) {
1902 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1903 "Textclass specific LaTeX commands.\n"
1904 + tmppreamble + '\n';
1907 /* the user-defined preamble */
1908 if (!params.preamble.empty()) {
1909 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1910 "User specified LaTeX commands.\n"
1911 + params.preamble + '\n';
1914 preamble += "\\makeatother\n\n";
1916 // Itemize bullet settings need to be last in case the user
1917 // defines their own bullets that use a package included
1918 // in the user-defined preamble -- ARRae
1919 // Actually it has to be done much later than that
1920 // since some packages like frenchb make modifications
1921 // at \begin{document} time -- JMarc
1923 for (int i = 0; i < 4; ++i) {
1924 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
1925 if (bullets_def.empty())
1926 bullets_def="\\AtBeginDocument{\n";
1927 bullets_def += " \\renewcommand{\\labelitemi";
1929 // `i' is one less than the item to modify
1936 bullets_def += "ii";
1942 bullets_def += "}{" +
1943 params.user_defined_bullets[i].getText()
1948 if (!bullets_def.empty())
1949 preamble += bullets_def + "}\n\n";
1951 for (int j = countChar(preamble, '\n'); j-- ;) {
1958 ofs << "\\begin{document}\n\n";
1962 lyxerr.debug() << "preamble finished, now the body." << endl;
1963 if (!lyxrc.language_auto_begin && params.language != "default") {
1964 ofs << subst(lyxrc.language_command_begin, "$$lang",
1970 latexParagraphs(ofs, paragraph, 0, texrow);
1972 // add this just in case after all the paragraphs
1976 if (!lyxrc.language_auto_end && params.language != "default") {
1977 ofs << subst(lyxrc.language_command_end, "$$lang",
1984 ofs << "\\end{document}\n";
1987 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
1989 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
1993 // Just to be sure. (Asger)
1996 // tex_code_break_column's value is used to decide
1997 // if we are in batchmode or not (within mathed_write()
1998 // in math_write.C) so we must set it to a non-zero
1999 // value when we leave otherwise we save incorrect .lyx files.
2000 tex_code_break_column = lyxrc.ascii_linelen;
2004 lyxerr << "File was not closed properly." << endl;
2007 lyxerr.debug() << "Finished making latex file." << endl;
2011 // LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
2013 void Buffer::latexParagraphs(ostream & ofs, LyXParagraph *par,
2014 LyXParagraph *endpar, TexRow & texrow) const
2016 bool was_title = false;
2017 bool already_title = false;
2019 std::ostringstream ftnote;
2021 char * tmpholder = 0;
2027 while (par != endpar) {
2028 #ifndef HAVE_SSTREAM
2031 ftnote << tmpholder;
2032 delete [] tmpholder;
2037 lyxerr[Debug::LATEX] << "Error in latexParagraphs."
2039 LyXLayout const & layout =
2040 textclasslist.Style(params.textclass,
2043 if (layout.intitle) {
2044 if (already_title) {
2045 lyxerr <<"Error in latexParagraphs: You"
2046 " should not mix title layouts"
2047 " with normal ones." << endl;
2050 } else if (was_title && !already_title) {
2051 ofs << "\\maketitle\n";
2053 already_title = true;
2056 // We are at depth 0 so we can just use
2057 // ordinary \footnote{} generation
2058 // flag this with ftcount
2060 if (layout.isEnvironment()
2061 || par->pextra_type != LyXParagraph::PEXTRA_NONE) {
2062 par = par->TeXEnvironment(this, params, ofs, texrow,
2063 ftnote, ft_texrow, ftcount);
2065 par = par->TeXOnePar(this, params, ofs, texrow, false,
2066 ftnote, ft_texrow, ftcount);
2069 // Write out what we've generated...
2072 ofs << "\\addtocounter{footnote}{-"
2076 ofs << ftnote.str();
2077 texrow += ft_texrow;
2079 // The extra .c_str() is needed when we use
2080 // lyxstring instead of the STL string class.
2081 ftnote.str(string().c_str());
2083 delete [] ftnote.str();
2088 #ifndef HAVE_SSTREAM
2090 // I hate strstreams
2091 tmpholder = ftnote.str();
2095 #ifndef HAVE_SSTREAM
2096 delete [] tmpholder;
2098 // It might be that we only have a title in this document
2099 if (was_title && !already_title) {
2100 ofs << "\\maketitle\n";
2105 bool Buffer::isLatex() const
2107 return textclasslist.TextClass(params.textclass).outputType() == LATEX;
2111 bool Buffer::isLinuxDoc() const
2113 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC;
2117 bool Buffer::isLiterate() const
2119 return textclasslist.TextClass(params.textclass).outputType() == LITERATE;
2123 bool Buffer::isDocBook() const
2125 return textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2129 bool Buffer::isSGML() const
2131 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC ||
2132 textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2136 void Buffer::sgmlOpenTag(ostream & os, int depth,
2137 string const & latexname) const
2139 os << string(depth, ' ') << "<" << latexname << ">\n";
2143 void Buffer::sgmlCloseTag(ostream & os, int depth,
2144 string const & latexname) const
2146 os << string(depth, ' ') << "</" << latexname << ">\n";
2150 void Buffer::makeLinuxDocFile(string const & fname, int column)
2152 LyXParagraph * par = paragraph;
2154 string top_element = textclasslist.LatexnameOfClass(params.textclass);
2155 string environment_stack[10];
2158 int depth = 0; // paragraph depth
2160 ofstream ofs(fname.c_str());
2163 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2167 tex_code_break_column = column;
2170 if (params.preamble.empty()) {
2171 ofs << "<!doctype linuxdoc system>\n\n";
2174 ofs << "<!doctype linuxdoc system \n [ "
2175 << params.preamble << " \n]>\n\n";
2178 ofs << "<!-- " << LYX_DOCVERSION
2179 << " created this file. For more info see http://www.lyx.org/"
2182 if(params.options.empty())
2183 sgmlOpenTag(ofs, 0, top_element);
2185 string top = top_element;
2187 top += params.options;
2188 sgmlOpenTag(ofs, 0, top);
2192 int desc_on = 0; // description mode
2193 LyXLayout const & style =
2194 textclasslist.Style(users->buffer()->params.textclass,
2197 // treat <toc> as a special case for compatibility with old code
2198 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2199 Inset * inset = par->GetInset(0);
2200 Inset::Code lyx_code = inset->LyxCode();
2201 if (lyx_code == Inset::TOC_CODE){
2202 string temp = "toc";
2203 sgmlOpenTag(ofs, depth, temp);
2206 linuxDocHandleFootnote(ofs, par, depth);
2211 // environment tag closing
2212 for( ; depth > par->depth; --depth) {
2213 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2214 environment_stack[depth].erase();
2217 // write opening SGML tags
2218 switch(style.latextype) {
2219 case LATEX_PARAGRAPH:
2220 if(depth == par->depth
2221 && !environment_stack[depth].empty()) {
2222 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2223 environment_stack[depth].erase();
2229 sgmlOpenTag(ofs, depth, style.latexname());
2234 LinuxDocError(par, 0,
2235 _("Error : Wrong depth for"
2236 " LatexType Command.\n"));
2238 if (!environment_stack[depth].empty()){
2239 sgmlCloseTag(ofs, depth,
2240 environment_stack[depth]);
2244 environment_stack[depth].erase();
2245 sgmlOpenTag(ofs, depth, style.latexname());
2248 case LATEX_ENVIRONMENT:
2249 case LATEX_ITEM_ENVIRONMENT:
2250 if(depth == par->depth
2251 && environment_stack[depth] != style.latexname()
2252 && !environment_stack[depth].empty()) {
2254 sgmlCloseTag(ofs, depth,
2255 environment_stack[depth]);
2256 environment_stack[depth].erase();
2258 if (depth < par->depth) {
2260 environment_stack[depth].erase();
2262 if (environment_stack[depth] != style.latexname()) {
2265 sgmlOpenTag(ofs, depth, temp);
2267 environment_stack[depth] = style.latexname();
2268 sgmlOpenTag(ofs, depth,
2269 environment_stack[depth]);
2271 if(style.latextype == LATEX_ENVIRONMENT) break;
2273 desc_on = (style.labeltype == LABEL_MANUAL);
2280 sgmlOpenTag(ofs, depth + 1, item_name);
2283 sgmlOpenTag(ofs, depth, style.latexname());
2288 SimpleLinuxDocOnePar(ofs, par, desc_on, depth);
2291 linuxDocHandleFootnote(ofs, par, depth);
2293 while(par && par->IsDummy());
2296 // write closing SGML tags
2297 switch(style.latextype) {
2299 case LATEX_ENVIRONMENT:
2300 case LATEX_ITEM_ENVIRONMENT:
2303 sgmlCloseTag(ofs, depth, style.latexname());
2309 for(; depth > 0; --depth)
2310 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2312 if(!environment_stack[depth].empty())
2313 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2316 sgmlCloseTag(ofs, 0, top_element);
2319 // How to check for successful close
2323 void Buffer::linuxDocHandleFootnote(ostream & os, LyXParagraph * & par,
2326 string tag = "footnote";
2328 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2329 sgmlOpenTag(os, depth + 1, tag);
2330 SimpleLinuxDocOnePar(os, par, 0, depth + 1);
2331 sgmlCloseTag(os, depth + 1, tag);
2337 void Buffer::DocBookHandleCaption(ostream & os, string & inner_tag,
2338 int const depth, int desc_on,
2339 LyXParagraph * & par)
2341 LyXParagraph * tpar = par;
2342 while (tpar && (tpar->footnoteflag != LyXParagraph::NO_FOOTNOTE) &&
2343 (tpar->layout != textclasslist.NumberOfLayout(params.textclass,
2347 tpar->layout == textclasslist.NumberOfLayout(params.textclass,
2348 "Caption").second) {
2349 sgmlOpenTag(os, depth + 1, inner_tag);
2351 SimpleDocBookOnePar(os, extra_par, tpar,
2352 desc_on, depth + 2);
2353 sgmlCloseTag(os, depth+1, inner_tag);
2354 if(!extra_par.empty())
2360 void Buffer::DocBookHandleFootnote(ostream & os, LyXParagraph * & par,
2363 string tag, inner_tag;
2364 string tmp_par, extra_par;
2365 bool inner_span = false;
2368 // Someone should give this enum a proper name (Lgb)
2376 SOME_ENUM last = NO_ONE;
2377 SOME_ENUM present = FOOTNOTE_LIKE;
2379 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2380 if(last == present) {
2382 if(!tmp_par.empty()) {
2385 sgmlCloseTag(os, depth + 1, inner_tag);
2386 sgmlOpenTag(os, depth + 1, inner_tag);
2393 if(!inner_tag.empty()) sgmlCloseTag(os, depth + 1,
2395 if(!extra_par.empty()) os << extra_par;
2396 if(!tag.empty()) sgmlCloseTag(os, depth, tag);
2399 switch (par->footnotekind) {
2400 case LyXParagraph::FOOTNOTE:
2401 case LyXParagraph::ALGORITHM:
2404 present = FOOTNOTE_LIKE;
2407 case LyXParagraph::MARGIN:
2410 present = MARGIN_LIKE;
2413 case LyXParagraph::FIG:
2414 case LyXParagraph::WIDE_FIG:
2416 inner_tag = "title";
2420 case LyXParagraph::TAB:
2421 case LyXParagraph::WIDE_TAB:
2423 inner_tag = "title";
2428 sgmlOpenTag(os, depth, tag);
2429 if ((present == TAB_LIKE) || (present == FIG_LIKE)) {
2430 DocBookHandleCaption(os, inner_tag, depth,
2434 sgmlOpenTag(os, depth + 1, inner_tag);
2437 // ignore all caption here, we processed them above!!!
2438 if (par->layout != textclasslist
2439 .NumberOfLayout(params.textclass,
2440 "Caption").second) {
2442 std::ostringstream ost;
2446 SimpleDocBookOnePar(ost, extra_par, par,
2447 desc_on, depth + 2);
2449 tmp_par += ost.str().c_str();
2452 char * ctmp = ost.str();
2457 tmp_par = frontStrip(strip(tmp_par));
2463 if(!inner_tag.empty()) sgmlCloseTag(os, depth + 1, inner_tag);
2464 if(!extra_par.empty()) os << extra_par;
2465 if(!tag.empty()) sgmlCloseTag(os, depth, tag);
2469 // push a tag in a style stack
2470 void Buffer::push_tag(ostream & os, char const * tag,
2471 int & pos, char stack[5][3])
2473 // pop all previous tags
2474 for (int j = pos; j >= 0; --j)
2475 os << "</" << stack[j] << ">";
2478 sprintf(stack[++pos], "%s", tag);
2481 for (int i = 0; i <= pos; ++i)
2482 os << "<" << stack[i] << ">";
2486 void Buffer::pop_tag(ostream & os, char const * tag,
2487 int & pos, char stack[5][3])
2491 // pop all tags till specified one
2492 for (j = pos; (j >= 0) && (strcmp(stack[j], tag)); --j)
2493 os << "</" << stack[j] << ">";
2496 os << "</" << tag << ">";
2498 // push all tags, but the specified one
2499 for (j = j + 1; j <= pos; ++j) {
2500 os << "<" << stack[j] << ">";
2501 strcpy(stack[j-1], stack[j]);
2507 // Handle internal paragraph parsing -- layout already processed.
2509 // checks, if newcol chars should be put into this line
2510 // writes newline, if necessary.
2512 void linux_doc_line_break(ostream & os, unsigned int & colcount,
2513 const unsigned int newcol)
2516 if (colcount > lyxrc.ascii_linelen) {
2518 colcount = newcol; // assume write after this call
2523 void Buffer::SimpleLinuxDocOnePar(ostream & os, LyXParagraph * par,
2524 int desc_on, int const /*depth*/)
2526 LyXFont font1, font2;
2529 LyXParagraph::size_type main_body;
2531 LyXLayout const & style = textclasslist.Style(params.textclass,
2534 char family_type = 0; // family font flag
2535 bool is_bold = false; // series font flag
2536 char shape_type = 0; // shape font flag
2537 bool is_em = false; // emphasis (italic) font flag
2539 int stack_num = -1; // style stack position
2540 // Can this be rewritten to use a std::stack, please. (Lgb)
2541 char stack[5][3]; // style stack
2542 unsigned int char_line_count = 5; // Heuristic choice ;-)
2544 if (style.labeltype != LABEL_MANUAL)
2547 main_body = par->BeginningOfMainBody();
2549 // gets paragraph main font
2551 font1 = style.labelfont;
2556 // parsing main loop
2557 for (LyXParagraph::size_type i = 0;
2558 i < par->size(); ++i) {
2561 if (i == main_body && !par->IsDummy()) {
2566 font2 = par->getFont(params, i);
2568 if (font1.family() != font2.family()) {
2569 switch(family_type) {
2571 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2572 push_tag(os, "tt", stack_num, stack);
2575 else if (font2.family() == LyXFont::SANS_FAMILY) {
2576 push_tag(os, "sf", stack_num, stack);
2581 pop_tag(os, "tt", stack_num, stack);
2582 if (font2.family() == LyXFont::SANS_FAMILY) {
2583 push_tag(os, "sf", stack_num, stack);
2591 pop_tag(os, "sf", stack_num, stack);
2592 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2593 push_tag(os, "tt", stack_num, stack);
2603 if (font1.series() != font2.series()) {
2604 if (font2.series() == LyXFont::BOLD_SERIES) {
2605 push_tag(os, "bf", stack_num, stack);
2609 pop_tag(os, "bf", stack_num, stack);
2614 // handle italic and slanted fonts
2615 if (font1.shape() != font2.shape()) {
2616 switch(shape_type) {
2618 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2619 push_tag(os, "it", stack_num, stack);
2622 else if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2623 push_tag(os, "sl", stack_num, stack);
2628 pop_tag(os, "it", stack_num, stack);
2629 if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2630 push_tag(os, "sl", stack_num, stack);
2638 pop_tag(os, "sl", stack_num, stack);
2639 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2640 push_tag(os, "it", stack_num, stack);
2649 if (font1.emph() != font2.emph()) {
2650 if (font2.emph() == LyXFont::ON) {
2651 push_tag(os, "em", stack_num, stack);
2654 pop_tag(os, "em", stack_num, stack);
2659 c = par->GetChar(i);
2661 if (font2.latex() == LyXFont::ON) {
2662 // "TeX"-Mode on == > SGML-Mode on.
2664 os << c; // see LaTeX-Generation...
2666 } else if (c == LyXParagraph::META_INSET) {
2667 inset = par->GetInset(i);
2668 inset->Linuxdoc(this, os);
2671 if (par->linuxDocConvertChar(c, sgml_string)
2672 && !style.free_spacing) { // in freespacing
2674 // non-breaking characters
2678 linux_doc_line_break(os, char_line_count, 6);
2683 linux_doc_line_break(os, char_line_count, 1);
2689 char_line_count += sgml_string.length();
2695 // needed if there is an optional argument but no contents
2696 if (main_body > 0 && main_body == par->size()) {
2700 // pop all defined Styles
2701 for (j = stack_num; j >= 0; --j) {
2702 linux_doc_line_break(os,
2704 3 + strlen(stack[j]));
2705 os << "</" << stack[j] << ">";
2708 // resets description flag correctly
2711 // <tag> not closed...
2712 linux_doc_line_break(os, char_line_count, 6);
2716 // fprintf(file, "</p>");
2722 // Print an error message.
2723 void Buffer::LinuxDocError(LyXParagraph * par, int pos,
2724 char const * message)
2726 InsetError * new_inset;
2728 // insert an error marker in text
2729 new_inset = new InsetError(message);
2730 par->InsertChar(pos, LyXParagraph::META_INSET);
2731 par->InsertInset(pos, new_inset);
2734 // This constant defines the maximum number of
2735 // environment layouts that can be nesteded.
2736 // The same applies for command layouts.
2737 // These values should be more than enough.
2738 // José Matos (1999/07/22)
2740 enum { MAX_NEST_LEVEL = 25};
2742 void Buffer::makeDocBookFile(string const & fname, int column)
2744 LyXParagraph * par = paragraph;
2746 string top_element= textclasslist.LatexnameOfClass(params.textclass);
2747 // Please use a real stack.
2748 string environment_stack[MAX_NEST_LEVEL];
2749 string environment_inner[MAX_NEST_LEVEL];
2750 // Please use a real stack.
2751 string command_stack[MAX_NEST_LEVEL];
2752 bool command_flag= false;
2753 int command_depth= 0, command_base= 0, cmd_depth= 0;
2755 string item_name, command_name;
2756 string c_depth, c_params, tmps;
2758 int depth = 0; // paragraph depth
2760 tex_code_break_column = column;
2762 ofstream ofs(fname.c_str());
2764 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2770 ofs << "<!doctype " << top_element
2771 << " public \"-//OASIS//DTD DocBook V3.1//EN\"";
2773 if (params.preamble.empty())
2776 ofs << "\n [ " << params.preamble << " \n]>\n\n";
2778 ofs << "<!-- DocBook file was created by " << LYX_DOCVERSION
2779 << "\n See http://www.lyx.org/ for more information -->\n";
2781 if(params.options.empty())
2782 sgmlOpenTag(ofs, 0, top_element);
2784 string top = top_element;
2786 top += params.options;
2787 sgmlOpenTag(ofs, 0, top);
2791 int desc_on = 0; // description mode
2792 LyXLayout const & style =
2793 textclasslist.Style(users->buffer()->params.textclass,
2796 // environment tag closing
2797 for( ; depth > par->depth; --depth) {
2798 if(environment_inner[depth] != "!-- --") {
2799 item_name= "listitem";
2800 sgmlCloseTag(ofs, command_depth + depth,
2802 if( environment_inner[depth] == "varlistentry")
2803 sgmlCloseTag(ofs, depth+command_depth,
2804 environment_inner[depth]);
2806 sgmlCloseTag(ofs, depth + command_depth,
2807 environment_stack[depth]);
2808 environment_stack[depth].erase();
2809 environment_inner[depth].erase();
2812 if(depth == par->depth
2813 && environment_stack[depth] != style.latexname()
2814 && !environment_stack[depth].empty()) {
2815 if(environment_inner[depth] != "!-- --") {
2816 item_name= "listitem";
2817 sgmlCloseTag(ofs, command_depth+depth,
2819 if( environment_inner[depth] == "varlistentry")
2821 depth + command_depth,
2822 environment_inner[depth]);
2825 sgmlCloseTag(ofs, depth + command_depth,
2826 environment_stack[depth]);
2828 environment_stack[depth].erase();
2829 environment_inner[depth].erase();
2832 // Write opening SGML tags.
2833 switch(style.latextype) {
2834 case LATEX_PARAGRAPH:
2835 if(style.latexname() != "dummy")
2836 sgmlOpenTag(ofs, depth+command_depth,
2842 LinuxDocError(par, 0,
2843 _("Error : Wrong depth for "
2844 "LatexType Command.\n"));
2846 command_name = style.latexname();
2848 tmps = style.latexparam();
2849 c_params = split(tmps, c_depth,'|');
2851 cmd_depth= atoi(c_depth.c_str());
2854 if(cmd_depth<command_base) {
2855 for(int j = command_depth;
2856 j >= command_base; --j)
2857 if(!command_stack[j].empty())
2858 sgmlCloseTag(ofs, j, command_stack[j]);
2859 command_depth= command_base= cmd_depth;
2861 else if(cmd_depth <= command_depth) {
2862 for(int j = command_depth;
2863 j >= cmd_depth; --j)
2865 if(!command_stack[j].empty())
2866 sgmlCloseTag(ofs, j, command_stack[j]);
2867 command_depth= cmd_depth;
2870 command_depth= cmd_depth;
2873 command_depth = command_base = cmd_depth;
2874 command_flag = true;
2876 command_stack[command_depth]= command_name;
2878 // treat label as a special case for
2879 // more WYSIWYM handling.
2880 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2881 Inset * inset = par->GetInset(0);
2882 Inset::Code lyx_code = inset->LyxCode();
2883 if (lyx_code == Inset::LABEL_CODE){
2884 command_name += " id=\"";
2885 command_name += (static_cast<InsetCommand *>(inset))->getContents();
2886 command_name += "\"";
2891 sgmlOpenTag(ofs, depth + command_depth, command_name);
2892 item_name = "title";
2893 sgmlOpenTag(ofs, depth + 1 + command_depth, item_name);
2896 case LATEX_ENVIRONMENT:
2897 case LATEX_ITEM_ENVIRONMENT:
2898 if (depth < par->depth) {
2900 environment_stack[depth].erase();
2903 if (environment_stack[depth] != style.latexname()) {
2904 environment_stack[depth] = style.latexname();
2905 environment_inner[depth] = "!-- --";
2906 sgmlOpenTag(ofs, depth + command_depth,
2907 environment_stack[depth]);
2909 if(environment_inner[depth] != "!-- --") {
2910 item_name= "listitem";
2912 command_depth + depth,
2914 if (environment_inner[depth] == "varlistentry")
2916 depth + command_depth,
2917 environment_inner[depth]);
2921 if(style.latextype == LATEX_ENVIRONMENT) {
2922 if(!style.latexparam().empty())
2923 sgmlOpenTag(ofs, depth + command_depth,
2924 style.latexparam());
2928 desc_on = (style.labeltype == LABEL_MANUAL);
2931 environment_inner[depth]= "varlistentry";
2933 environment_inner[depth]= "listitem";
2935 sgmlOpenTag(ofs, depth + 1 + command_depth,
2936 environment_inner[depth]);
2940 sgmlOpenTag(ofs, depth + 1 + command_depth,
2945 sgmlOpenTag(ofs, depth + 1 + command_depth,
2950 sgmlOpenTag(ofs, depth + command_depth,
2957 SimpleDocBookOnePar(ofs, extra_par, par, desc_on,
2958 depth + 1 + command_depth);
2960 DocBookHandleFootnote(ofs, par,
2961 depth + 1 + command_depth);
2963 while(par && par->IsDummy());
2966 // write closing SGML tags
2967 switch(style.latextype) {
2970 sgmlCloseTag(ofs, depth + command_depth, end_tag);
2972 case LATEX_ENVIRONMENT:
2973 if(!style.latexparam().empty())
2974 sgmlCloseTag(ofs, depth + command_depth,
2975 style.latexparam());
2977 case LATEX_ITEM_ENVIRONMENT:
2978 if(desc_on == 1) break;
2980 sgmlCloseTag(ofs, depth + 1 + command_depth, end_tag);
2982 case LATEX_PARAGRAPH:
2983 if(style.latexname() != "dummy")
2984 sgmlCloseTag(ofs, depth + command_depth,
2988 sgmlCloseTag(ofs, depth + command_depth,
2995 for(; depth >= 0; --depth) {
2996 if(!environment_stack[depth].empty()) {
2997 if(environment_inner[depth] != "!-- --") {
2998 item_name= "listitem";
2999 sgmlCloseTag(ofs, command_depth + depth,
3001 if( environment_inner[depth] == "varlistentry")
3002 sgmlCloseTag(ofs, depth + command_depth,
3003 environment_inner[depth]);
3006 sgmlCloseTag(ofs, depth + command_depth,
3007 environment_stack[depth]);
3011 for(int j = command_depth; j >= command_base; --j)
3012 if(!command_stack[j].empty())
3013 sgmlCloseTag(ofs, j, command_stack[j]);
3016 sgmlCloseTag(ofs, 0, top_element);
3019 // How to check for successful close
3023 void Buffer::SimpleDocBookOnePar(ostream & os, string & extra,
3024 LyXParagraph * par, int & desc_on,
3029 par->SimpleDocBookOneTablePar(this,
3030 os, extra, desc_on, depth);
3035 bool emph_flag = false;
3037 LyXLayout const & style = textclasslist.Style(params.textclass,
3040 LyXParagraph::size_type main_body;
3041 if (style.labeltype != LABEL_MANUAL)
3044 main_body = par->BeginningOfMainBody();
3046 // gets paragraph main font
3047 LyXFont font1 = main_body > 0 ? style.labelfont : style.font;
3049 int char_line_count = depth;
3050 if(!style.free_spacing)
3051 for (int j = 0; j < depth; ++j)
3054 // parsing main loop
3055 for (LyXParagraph::size_type i = 0;
3056 i < par->size(); ++i) {
3057 LyXFont font2 = par->getFont(params, i);
3059 // handle <emphasis> tag
3060 if (font1.emph() != font2.emph() && i) {
3061 if (font2.emph() == LyXFont::ON) {
3065 os << "</emphasis>";
3070 char c = par->GetChar(i);
3072 if (c == LyXParagraph::META_INSET) {
3073 Inset * inset = par->GetInset(i);
3075 std::ostringstream ost;
3076 inset->DocBook(this, ost);
3077 string tmp_out = ost.str().c_str();
3080 inset->DocBook(this, ost);
3082 char * ctmp = ost.str();
3083 string tmp_out(ctmp);
3087 // This code needs some explanation:
3088 // Two insets are treated specially
3089 // label if it is the first element in a command paragraph
3091 // graphics inside tables or figure floats can't go on
3092 // title (the equivalente in latex for this case is caption
3093 // and title should come first
3096 if(desc_on!= 3 || i!= 0) {
3097 if(!tmp_out.empty() && tmp_out[0] == '@') {
3099 extra += frontStrip(tmp_out, '@');
3101 os << frontStrip(tmp_out, '@');
3106 } else if (font2.latex() == LyXFont::ON) {
3107 // "TeX"-Mode on ==> SGML-Mode on.
3113 if (par->linuxDocConvertChar(c, sgml_string)
3114 && !style.free_spacing) { // in freespacing
3116 // non-breaking characters
3120 os << "\n</term><listitem><para>";
3132 // needed if there is an optional argument but no contents
3133 if (main_body > 0 && main_body == par->size()) {
3137 os << "</emphasis>";
3140 // resets description flag correctly
3143 // <term> not closed...
3151 int Buffer::runLaTeX()
3153 if (!users->text) return 0;
3155 ProhibitInput(users);
3157 // get LaTeX-Filename
3158 string name = getLatexName();
3160 string path = OnlyPath(filename);
3162 string org_path = path;
3163 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3167 Path p(path); // path to LaTeX file
3168 users->owner()->getMiniBuffer()->Set(_("Running LaTeX..."));
3170 // Remove all error insets
3171 bool a = users->removeAutoInsets();
3173 // Always generate the LaTeX file
3174 makeLaTeXFile(name, org_path, false);
3176 // do the LaTex run(s)
3178 string latex_command = lyxrc.pdf_mode ?
3179 lyxrc.pdflatex_command : lyxrc.latex_command;
3180 LaTeX latex(latex_command, name, filepath);
3181 int res = latex.run(terr,
3182 users->owner()->getMiniBuffer()); // running latex
3184 // check return value from latex.run().
3185 if ((res & LaTeX::NO_LOGFILE)) {
3186 WriteAlert(_("LaTeX did not work!"),
3187 _("Missing log file:"), name);
3188 } else if ((res & LaTeX::ERRORS)) {
3189 users->owner()->getMiniBuffer()->Set(_("Done"));
3190 // Insert all errors as errors boxes
3191 users->insertErrors(terr);
3193 // Dvi should also be kept dirty if the latex run
3194 // ends up with errors. However it should be possible
3195 // to view a dirty dvi too.
3197 //no errors or any other things to think about so:
3198 users->owner()->getMiniBuffer()->Set(_("Done"));
3201 // if we removed error insets before we ran LaTeX or if we inserted
3202 // error insets after we ran LaTeX this must be run:
3203 if (a || (res & LaTeX::ERRORS)){
3206 //users->updateScrollbar();
3210 return latex.getNumErrors();
3214 int Buffer::runLiterate()
3216 if (!users->text) return 0;
3218 ProhibitInput(users);
3220 // get LaTeX-Filename
3221 string name = getLatexName();
3222 // get Literate-Filename
3223 string lit_name = OnlyFilename(ChangeExtension (getLatexName(),
3224 lyxrc.literate_extension));
3226 string path = OnlyPath(filename);
3228 string org_path = path;
3229 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3233 Path p(path); // path to Literate file
3234 users->owner()->getMiniBuffer()->Set(_("Running Literate..."));
3236 // Remove all error insets
3237 bool a = users->removeAutoInsets();
3239 // generate the Literate file if necessary
3240 makeLaTeXFile(lit_name, org_path, false);
3242 string latex_command = lyxrc.pdf_mode ?
3243 lyxrc.pdflatex_command : lyxrc.latex_command;
3244 Literate literate(latex_command, name, filepath,
3246 lyxrc.literate_command, lyxrc.literate_error_filter,
3247 lyxrc.build_command, lyxrc.build_error_filter);
3249 int res = literate.weave(terr, users->owner()->getMiniBuffer());
3251 // check return value from literate.weave().
3252 if ((res & Literate::NO_LOGFILE)) {
3253 WriteAlert(_("Literate command did not work!"),
3254 _("Missing log file:"), name);
3255 } else if ((res & Literate::ERRORS)) {
3256 users->owner()->getMiniBuffer()->Set(_("Done"));
3257 // Insert all errors as errors boxes
3258 users->insertErrors(terr);
3260 // Dvi should also be kept dirty if the latex run
3261 // ends up with errors. However it should be possible
3262 // to view a dirty dvi too.
3264 //no errors or any other things to think about so:
3265 users->owner()->getMiniBuffer()->Set(_("Done"));
3268 // if we removed error insets before we ran LaTeX or if we inserted
3269 // error insets after we ran LaTeX this must be run:
3270 if (a || (res & Literate::ERRORS)){
3273 //users->updateScrollbar();
3277 return literate.getNumErrors();
3281 int Buffer::buildProgram()
3283 if (!users->text) return 0;
3285 ProhibitInput(users);
3287 // get LaTeX-Filename
3288 string name = getLatexName();
3289 // get Literate-Filename
3290 string lit_name = OnlyFilename(ChangeExtension(getLatexName(),
3291 lyxrc.literate_extension));
3293 string path = OnlyPath(filename);
3295 string org_path = path;
3296 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3300 Path p(path); // path to Literate file
3301 users->owner()->getMiniBuffer()->Set(_("Building Program..."));
3303 // Remove all error insets
3304 bool a = users->removeAutoInsets();
3306 // generate the LaTeX file if necessary
3307 if (!isNwClean() || a) {
3308 makeLaTeXFile(lit_name, org_path, false);
3312 string latex_command = lyxrc.pdf_mode ?
3313 lyxrc.pdflatex_command : lyxrc.latex_command;
3314 Literate literate(latex_command, name, filepath,
3316 lyxrc.literate_command, lyxrc.literate_error_filter,
3317 lyxrc.build_command, lyxrc.build_error_filter);
3319 int res = literate.build(terr, users->owner()->getMiniBuffer());
3321 // check return value from literate.build().
3322 if ((res & Literate::NO_LOGFILE)) {
3323 WriteAlert(_("Build did not work!"),
3324 _("Missing log file:"), name);
3325 } else if ((res & Literate::ERRORS)) {
3326 users->owner()->getMiniBuffer()->Set(_("Done"));
3327 // Insert all errors as errors boxes
3328 users->insertErrors(terr);
3330 // Literate files should also be kept dirty if the literate
3331 // command run ends up with errors.
3333 //no errors or any other things to think about so:
3334 users->owner()->getMiniBuffer()->Set(_("Done"));
3338 // if we removed error insets before we ran Literate/Build or
3339 // if we inserted error insets after we ran Literate/Build this
3341 if (a || (res & Literate::ERRORS)){
3344 //users->updateScrollbar();
3348 return literate.getNumErrors();
3352 // This should be enabled when the Chktex class is implemented. (Asger)
3353 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
3354 // Other flags: -wall -v0 -x
3355 int Buffer::runChktex()
3357 if (!users->text) return 0;
3359 ProhibitInput(users);
3361 // get LaTeX-Filename
3362 string name = getLatexName();
3363 string path = OnlyPath(filename);
3365 string org_path = path;
3366 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3370 Path p(path); // path to LaTeX file
3371 users->owner()->getMiniBuffer()->Set(_("Running chktex..."));
3373 // Remove all error insets
3374 bool removedErrorInsets = users->removeAutoInsets();
3376 // Generate the LaTeX file if neccessary
3377 makeLaTeXFile(name, org_path, false);
3380 Chktex chktex(lyxrc.chktex_command, name, filepath);
3381 int res = chktex.run(terr); // run chktex
3384 WriteAlert(_("chktex did not work!"),
3385 _("Could not run with file:"), name);
3386 } else if (res > 0) {
3387 // Insert all errors as errors boxes
3388 users->insertErrors(terr);
3391 // if we removed error insets before we ran chktex or if we inserted
3392 // error insets after we ran chktex, this must be run:
3393 if (removedErrorInsets || res){
3396 //users->updateScrollbar();
3405 void Buffer::RoffAsciiTable(ostream & os, LyXParagraph * par)
3407 LyXFont font1(LyXFont::ALL_INHERIT,params.language_info);
3410 LyXParagraph::size_type i;
3414 string fname1 = TmpFileName(string(), "RAT1");
3415 string fname2 = TmpFileName(string(), "RAT2");
3417 ofstream ofs(fname1.c_str());
3419 WriteAlert(_("LYX_ERROR:"),
3420 _("Cannot open temporary file:"), fname1);
3423 par->table->RoffEndOfCell(ofs, -1);
3424 for (i = 0; i < par->size(); ++i) {
3425 c = par->GetChar(i);
3426 if (par->table->IsContRow(cell)) {
3427 if (c == LyXParagraph::META_NEWLINE)
3431 font2 = par->GetFontSettings(i);
3432 if (font1.latex() != font2.latex()) {
3433 if (font2.latex() != LyXFont::OFF)
3437 case LyXParagraph::META_INSET:
3438 if ((inset = par->GetInset(i))) {
3440 stringstresm ss(ios::in | ios::out);
3441 inset->Ascii(this, ss);
3453 inset->Ascii(this, ss);
3467 case LyXParagraph::META_NEWLINE:
3468 if (par->table->CellHasContRow(cell)>= 0)
3469 par->RoffContTableRows(ofs, i+1, cell);
3470 par->table->RoffEndOfCell(ofs, cell);
3473 case LyXParagraph::META_HFILL:
3483 << "RoffAsciiTable:"
3484 " NULL char in structure." << endl;
3488 par->table->RoffEndOfCell(ofs, cell);
3490 string cmd = lyxrc.ascii_roff_command + " >" + fname2;
3491 cmd = subst(cmd, "$$FName", fname1);
3492 Systemcalls one(Systemcalls::System, cmd);
3493 if (!(lyxerr.debugging(Debug::ROFF))) {
3494 remove(fname1.c_str());
3496 ifstream ifs(fname2.c_str());
3498 WriteFSAlert(_("Error! Can't open temporary file:"), fname2);
3501 // now output the produced file
3505 WriteAlert(_("Error!"),
3506 _("Error executing *roff command on table"));
3507 // overread leading blank lines
3508 while(!ifs && (c == '\n'))
3511 for(j = 0; j < par->depth; ++j)
3513 while(!ifs && (c != '\n')) {
3518 // overread trailing blank lines
3519 while(!ifs && (c == '\n'))
3523 remove(fname2.c_str());
3528 void Buffer::validate(LaTeXFeatures & features) const
3530 LyXParagraph * par = paragraph;
3531 LyXTextClass const & tclass =
3532 textclasslist.TextClass(params.textclass);
3534 // AMS Style is at document level
3536 features.amsstyle = (params.use_amsmath ||
3537 tclass.provides(LyXTextClass::amsmath));
3540 // We don't use "lyxerr.debug" because of speed. (Asger)
3541 if (lyxerr.debugging(Debug::LATEX))
3542 lyxerr << "Paragraph: " << par << endl;
3544 // Now just follow the list of paragraphs and run
3545 // validate on each of them.
3546 par->validate(features);
3548 // and then the next paragraph
3552 // the bullet shapes are buffer level not paragraph level
3553 // so they are tested here
3554 for (int i = 0; i < 4; ++i) {
3555 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
3556 int font = params.user_defined_bullets[i].getFont();
3559 .user_defined_bullets[i]
3566 features.latexsym = true;
3570 features.amssymb = true;
3572 else if ((font >= 2 && font <= 5)) {
3573 features.pifont = true;
3578 if (lyxerr.debugging(Debug::LATEX)) {
3579 features.showStruct();
3584 void Buffer::setPaperStuff()
3586 params.papersize = BufferParams::PAPER_DEFAULT;
3587 char c1 = params.paperpackage;
3588 if (c1 == BufferParams::PACKAGE_NONE) {
3589 char c2 = params.papersize2;
3590 if (c2 == BufferParams::VM_PAPER_USLETTER)
3591 params.papersize = BufferParams::PAPER_USLETTER;
3592 else if (c2 == BufferParams::VM_PAPER_USLEGAL)
3593 params.papersize = BufferParams::PAPER_LEGALPAPER;
3594 else if (c2 == BufferParams::VM_PAPER_USEXECUTIVE)
3595 params.papersize = BufferParams::PAPER_EXECUTIVEPAPER;
3596 else if (c2 == BufferParams::VM_PAPER_A3)
3597 params.papersize = BufferParams::PAPER_A3PAPER;
3598 else if (c2 == BufferParams::VM_PAPER_A4)
3599 params.papersize = BufferParams::PAPER_A4PAPER;
3600 else if (c2 == BufferParams::VM_PAPER_A5)
3601 params.papersize = BufferParams::PAPER_A5PAPER;
3602 else if ((c2 == BufferParams::VM_PAPER_B3) || (c2 == BufferParams::VM_PAPER_B4) ||
3603 (c2 == BufferParams::VM_PAPER_B5))
3604 params.papersize = BufferParams::PAPER_B5PAPER;
3605 } else if ((c1 == BufferParams::PACKAGE_A4) || (c1 == BufferParams::PACKAGE_A4WIDE) ||
3606 (c1 == BufferParams::PACKAGE_WIDEMARGINSA4))
3607 params.papersize = BufferParams::PAPER_A4PAPER;
3611 // This function should be in Buffer because it's a buffer's property (ale)
3612 string Buffer::getIncludeonlyList(char delim)
3615 for (inset_iterator it = inset_iterator_begin();
3616 it != inset_iterator_end(); ++it) {
3617 if ((*it)->LyxCode() == Inset::INCLUDE_CODE) {
3618 InsetInclude * insetinc =
3619 static_cast<InsetInclude *>(*it);
3620 if (insetinc->isInclude()
3621 && insetinc->isNoLoad()) {
3624 lst += OnlyFilename(ChangeExtension(insetinc->getContents(), string()));
3628 lyxerr.debug() << "Includeonly(" << lst << ')' << endl;
3633 vector<string> Buffer::getLabelList()
3635 /// if this is a child document and the parent is already loaded
3636 /// Use the parent's list instead [ale990407]
3637 if (!params.parentname.empty()
3638 && bufferlist.exists(params.parentname)) {
3639 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3641 return tmp->getLabelList();
3644 vector<string> label_list;
3645 for (inset_iterator it = inset_iterator_begin();
3646 it != inset_iterator_end(); ++it) {
3647 vector<string> l = (*it)->getLabelList();
3648 label_list.insert(label_list.end(), l.begin(), l.end());
3654 vector<vector<Buffer::TocItem> > Buffer::getTocList()
3656 vector<vector<TocItem> > l(4);
3657 LyXParagraph * par = paragraph;
3659 if (par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
3660 if (textclasslist.Style(params.textclass,
3661 par->GetLayout()).labeltype
3662 == LABEL_SENSITIVE) {
3666 tmp.str = par->String(this, false);
3667 switch (par->footnotekind) {
3668 case LyXParagraph::FIG:
3669 case LyXParagraph::WIDE_FIG:
3670 l[TOC_LOF].push_back(tmp);
3672 case LyXParagraph::TAB:
3673 case LyXParagraph::WIDE_TAB:
3674 l[TOC_LOT].push_back(tmp);
3676 case LyXParagraph::ALGORITHM:
3677 l[TOC_LOA].push_back(tmp);
3679 case LyXParagraph::FOOTNOTE:
3680 case LyXParagraph::MARGIN:
3684 } else if (!par->IsDummy()) {
3685 char labeltype = textclasslist.Style(params.textclass,
3686 par->GetLayout()).labeltype;
3688 if (labeltype >= LABEL_COUNTER_CHAPTER
3689 && labeltype <= LABEL_COUNTER_CHAPTER + params.tocdepth) {
3690 // insert this into the table of contents
3695 textclasslist.TextClass(params.textclass).maxcounter());
3696 tmp.str = par->String(this, true);
3697 l[TOC_TOC].push_back(tmp);
3705 // This is also a buffer property (ale)
3706 vector<pair<string,string> > Buffer::getBibkeyList()
3708 /// if this is a child document and the parent is already loaded
3709 /// Use the parent's list instead [ale990412]
3710 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3711 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3713 return tmp->getBibkeyList();
3716 vector<pair<string, string> > keys;
3717 LyXParagraph * par = paragraph;
3720 keys.push_back(pair<string,string>(par->bibkey->getContents(),
3721 par->String(this, false)));
3725 // Might be either using bibtex or a child has bibliography
3727 for (inset_iterator it = inset_iterator_begin();
3728 it != inset_iterator_end(); ++it) {
3729 // Search for Bibtex or Include inset
3730 if ((*it)->LyxCode() == Inset::BIBTEX_CODE) {
3731 vector<pair<string,string> > tmp =
3732 static_cast<InsetBibtex*>(*it)->getKeys();
3733 keys.insert(keys.end(), tmp.begin(), tmp.end());
3734 } else if ((*it)->LyxCode() == Inset::INCLUDE_CODE) {
3735 vector<pair<string,string> > tmp =
3736 static_cast<InsetInclude*>(*it)->getKeys();
3737 keys.insert(keys.end(), tmp.begin(), tmp.end());
3746 bool Buffer::isDepClean(string const & name) const
3748 DEPCLEAN * item = dep_clean;
3749 while (item && item->master != name)
3751 if (!item) return true;
3756 void Buffer::markDepClean(string const & name)
3759 dep_clean = new DEPCLEAN;
3760 dep_clean->clean = true;
3761 dep_clean->master = name;
3762 dep_clean->next = 0;
3764 DEPCLEAN* item = dep_clean;
3765 while (item && item->master != name)
3770 item = new DEPCLEAN;
3772 item->master = name;
3779 bool Buffer::Dispatch(string const & command)
3781 // Split command string into command and argument
3782 string cmd, line = frontStrip(command);
3783 string arg = strip(frontStrip(split(line, cmd, ' ')));
3785 return Dispatch(lyxaction.LookupFunc(cmd.c_str()), arg.c_str());
3789 bool Buffer::Dispatch(int action, string const & argument)
3791 bool dispatched = true;
3794 MenuExport(this, argument);
3804 void Buffer::resize()
3806 /// first resize the BufferViews!
3810 /// then remove all LyXText in text-insets
3811 LyXParagraph * par = paragraph;
3812 for(;par;par = par->next) {
3813 par->deleteInsetsLyXText(users);
3818 void Buffer::ChangeLanguage(Language const * from, Language const * to)
3821 LyXParagraph * par = paragraph;
3823 par->ChangeLanguage(params, from, to);
3829 bool Buffer::isMultiLingual()
3832 LyXParagraph * par = paragraph;
3834 if (par->isMultiLingual(params))
3842 Buffer::inset_iterator::inset_iterator(LyXParagraph * paragraph,
3843 LyXParagraph::size_type pos)
3845 it = par->InsetIterator(pos);
3846 if (it == par->inset_iterator_end()) {
3853 void Buffer::inset_iterator::SetParagraph() {
3855 it = par->inset_iterator_begin();
3856 if (it != par->inset_iterator_end())
3861 // We maintain an invariant that whenever par = 0 then it = 0