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/insetmarginal.h"
70 #include "insets/insetminipage.h"
71 #include "insets/insetfloat.h"
72 #include "insets/insetlist.h"
73 #include "insets/insettabular.h"
74 #include "insets/insettheorem.h"
75 #include "insets/insetcaption.h"
76 #include "support/filetools.h"
77 #include "support/path.h"
83 #include "LaTeXFeatures.h"
84 #include "support/syscall.h"
85 #include "support/lyxlib.h"
86 #include "support/FileInfo.h"
90 #include "lyx_gui_misc.h" // WarnReadonly()
91 #include "frontends/Dialogs.h"
106 using std::istringstream;
109 // all these externs should eventually be removed.
110 extern BufferList bufferlist;
112 extern void MenuExport(Buffer *, string const &);
113 extern LyXAction lyxaction;
116 static const float LYX_FORMAT = 2.16;
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);
133 if (read_only || (lyxrc.use_tempdir)) {
134 tmppath = CreateBufferTmpDir();
135 } else tmppath.erase();
141 lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
142 // here the buffer should take care that it is
143 // saved properly, before it goes into the void.
145 // make sure that views using this buffer
150 if (!tmppath.empty()) {
151 DestroyBufferTmpDir(tmppath);
154 LyXParagraph * par = paragraph;
155 LyXParagraph * tmppar;
165 string Buffer::getLatexName(bool no_path) const
168 return OnlyFilename(ChangeExtension(MakeLatexName(filename),
171 return ChangeExtension(MakeLatexName(filename),
176 void Buffer::setReadonly(bool flag)
178 if (read_only != flag) {
181 users->owner()->getDialogs()->updateBufferDependent();
184 WarnReadonly(filename);
189 bool Buffer::saveParamsAsDefaults()
191 string fname = AddName(AddPath(user_lyxdir, "templates/"),
193 Buffer defaults = Buffer(fname);
195 // Use the current buffer's parameters as default
196 defaults.params = params;
198 // add an empty paragraph. Is this enough?
199 defaults.paragraph = new LyXParagraph;
201 return defaults.writeFile(defaults.filename, false);
205 /// Update window titles of all users
206 // Should work on a list
207 void Buffer::updateTitles() const
209 if (users) users->owner()->updateWindowTitle();
213 /// Reset autosave timer of all users
214 // Should work on a list
215 void Buffer::resetAutosaveTimers() const
217 if (users) users->owner()->resetAutosaveTimer();
221 void Buffer::fileName(string const & newfile)
223 filename = MakeAbsPath(newfile);
224 filepath = OnlyPath(filename);
225 setReadonly(IsFileWriteable(filename) == 0);
230 // candidate for move to BufferView
231 // (at least some parts in the beginning of the func)
234 // changed to be public and have one parameter
235 // if par = 0 normal behavior
236 // else insert behavior
237 // Returns false if "\the_end" is not read for formats >= 2.13. (Asger)
238 #define USE_PARSE_FUNCTION 1
239 //#define USE_TABULAR_INSETS 1
240 bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par)
244 char depth = 0; // signed or unsigned?
246 LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
247 LyXParagraph::footnote_kind footnotekind = LyXParagraph::FOOTNOTE;
249 bool the_end_read = false;
251 LyXParagraph * return_par = 0;
252 LyXFont font(LyXFont::ALL_INHERIT, params.language_info);
253 if (format < 2.16 && params.language == "hebrew")
254 font.setLanguage(default_language);
256 // If we are inserting, we cheat and get a token in advance
257 bool has_token = false;
261 par = new LyXParagraph;
263 users->text->BreakParagraph(users);
264 return_par = users->text->FirstParagraph();
267 // We don't want to adopt the parameters from the
268 // document we insert, so we skip until the text begins:
271 pretoken = lex.GetString();
272 if (pretoken == "\\layout") {
284 pretoken = lex.GetString();
287 // Profiling show this should give a lot: (Asger)
288 string const token = pretoken;
292 the_end_read = parseSingleLyXformat2Token(lex, par, return_par,
305 paragraph = return_par;
312 Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
313 LyXParagraph *& return_par,
314 string const & token, int & pos,
315 char & depth, LyXFont & font
317 , LyXParagraph::footnote_flag & footnoteflag,
318 LyXParagraph::footnote_kind & footnotekind
322 bool the_end_read = false;
323 // We'll remove this later. (Lgb)
324 static string last_inset_read;
326 if (token[0] != '\\') {
327 for (string::const_iterator cit = token.begin();
328 cit != token.end(); ++cit) {
329 par->InsertChar(pos, (*cit), font);
332 } else if (token == "\\i") {
333 Inset * inset = new InsetLatexAccent;
334 inset->Read(this, lex);
335 par->InsertInset(pos, inset, font);
337 } else if (token == "\\layout") {
342 par = new LyXParagraph(par);
346 string layoutname = lex.GetString();
347 pair<bool, LyXTextClass::LayoutList::size_type> pp
348 = textclasslist.NumberOfLayout(params.textclass,
351 par->layout = pp.second;
352 } else { // layout not found
353 // use default layout "Standard" (0)
356 // Test whether the layout is obsolete.
357 LyXLayout const & layout =
358 textclasslist.Style(params.textclass,
360 if (!layout.obsoleted_by().empty())
362 textclasslist.NumberOfLayout(params.textclass,
363 layout.obsoleted_by()).second;
365 par->footnoteflag = footnoteflag;
366 par->footnotekind = footnotekind;
369 font = LyXFont(LyXFont::ALL_INHERIT, params.language_info);
370 if (format < 2.16 && params.language == "hebrew")
371 font.setLanguage(default_language);
373 } else if (token == "\\end_float") {
378 par = new LyXParagraph(par);
380 footnotekind = LyXParagraph::FOOTNOTE;
381 footnoteflag = LyXParagraph::NO_FOOTNOTE;
384 par->layout = LYX_DUMMY_LAYOUT;
385 font = LyXFont(LyXFont::ALL_INHERIT, params.language_info);
386 if (format < 2.16 && params.language == "hebrew")
387 font.setLanguage(default_language);
388 } else if (token == "\\begin_float") {
389 int tmpret = lex.FindToken(string_footnotekinds);
390 if (tmpret == -1) ++tmpret;
391 if (tmpret != LYX_LAYOUT_DEFAULT)
392 footnotekind = static_cast<LyXParagraph::footnote_kind>(tmpret); // bad
393 if (footnotekind == LyXParagraph::FOOTNOTE
394 || footnotekind == LyXParagraph::MARGIN)
395 footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
397 footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
399 } else if (token == "\\begin_float") {
400 // This is the compability reader, unfinished but tested.
403 string tmptok = lex.GetString();
404 //lyxerr << "old float: " << tmptok << endl;
409 if (tmptok == "footnote") {
410 inset = new InsetFoot;
411 } else if (tmptok == "margin") {
412 inset = new InsetMarginal;
413 } else if (tmptok == "fig") {
414 inset = new InsetFloat("figure");
415 old_float += "placement htbp\n";
416 } else if (tmptok == "tab") {
417 inset = new InsetFloat("table");
418 old_float += "placement htbp\n";
419 } else if (tmptok == "alg") {
420 inset = new InsetFloat("algorithm");
421 old_float += "placement htbp\n";
422 } else if (tmptok == "wide-fig") {
423 InsetFloat * tmp = new InsetFloat("figure");
426 old_float += "placement htbp\n";
427 } else if (tmptok == "wide-tab") {
428 InsetFloat * tmp = new InsetFloat("table");
431 old_float += "placement htbp\n";
434 if (!inset) return false; // no end read yet
436 old_float += "collapsed true\n";
438 // Here we need to check for \end_deeper and handle that
439 // before we do the footnote parsing.
440 // This _is_ a hack! (Lgb)
443 string tmp = lex.GetString();
444 if (tmp == "\\end_deeper") {
445 lyxerr << "\\end_deeper caught!" << endl;
447 lex.printError("\\end_deeper: "
448 "depth is already null");
459 old_float += lex.getLongString("\\end_float");
460 old_float += "\n\\end_inset\n";
461 //lyxerr << "float body: " << old_float << endl;
464 istringstream istr(old_float.c_str());
466 istrstream istr(old_float.c_str());
470 nylex.setStream(istr);
472 inset->Read(this, nylex);
473 par->InsertInset(pos, inset, font);
476 } else if (token == "\\begin_deeper") {
478 } else if (token == "\\end_deeper") {
480 lex.printError("\\end_deeper: "
481 "depth is already null");
485 } else if (token == "\\begin_preamble") {
486 params.readPreamble(lex);
487 } else if (token == "\\textclass") {
489 pair<bool, LyXTextClassList::size_type> pp =
490 textclasslist.NumberOfClass(lex.GetString());
492 params.textclass = pp.second;
494 lex.printError("Unknown textclass `$$Token'");
495 params.textclass = 0;
497 if (!textclasslist.Load(params.textclass)) {
498 // if the textclass wasn't loaded properly
499 // we need to either substitute another
500 // or stop loading the file.
501 // I can substitute but I don't see how I can
502 // stop loading... ideas?? ARRae980418
503 WriteAlert(_("Textclass Loading Error!"),
504 string(_("Can't load textclass ")) +
505 textclasslist.NameOfClass(params.textclass),
506 _("-- substituting default"));
507 params.textclass = 0;
509 } else if (token == "\\options") {
511 params.options = lex.GetString();
512 } else if (token == "\\language") {
513 params.readLanguage(lex);
514 } else if (token == "\\fontencoding") {
516 } else if (token == "\\inputencoding") {
518 params.inputenc = lex.GetString();
519 } else if (token == "\\graphics") {
520 params.readGraphicsDriver(lex);
521 } else if (token == "\\fontscheme") {
523 params.fonts = lex.GetString();
524 } else if (token == "\\noindent") {
525 par->noindent = true;
526 } else if (token == "\\fill_top") {
527 par->added_space_top = VSpace(VSpace::VFILL);
528 } else if (token == "\\fill_bottom") {
529 par->added_space_bottom = VSpace(VSpace::VFILL);
530 } else if (token == "\\line_top") {
531 par->line_top = true;
532 } else if (token == "\\line_bottom") {
533 par->line_bottom = true;
534 } else if (token == "\\pagebreak_top") {
535 par->pagebreak_top = true;
536 } else if (token == "\\pagebreak_bottom") {
537 par->pagebreak_bottom = true;
538 } else if (token == "\\start_of_appendix") {
539 par->start_of_appendix = true;
540 } else if (token == "\\paragraph_separation") {
541 int tmpret = lex.FindToken(string_paragraph_separation);
542 if (tmpret == -1) ++tmpret;
543 if (tmpret != LYX_LAYOUT_DEFAULT)
544 params.paragraph_separation =
545 static_cast<BufferParams::PARSEP>(tmpret);
546 } else if (token == "\\defskip") {
548 params.defskip = VSpace(lex.GetString());
549 } else if (token == "\\epsfig") { // obsolete
550 // Indeed it is obsolete, but we HAVE to be backwards
551 // compatible until 0.14, because otherwise all figures
552 // in existing documents are irretrivably lost. (Asger)
553 params.readGraphicsDriver(lex);
554 } else if (token == "\\quotes_language") {
555 int tmpret = lex.FindToken(string_quotes_language);
556 if (tmpret == -1) ++tmpret;
557 if (tmpret != LYX_LAYOUT_DEFAULT) {
558 InsetQuotes::quote_language tmpl =
559 InsetQuotes::EnglishQ;
562 tmpl = InsetQuotes::EnglishQ;
565 tmpl = InsetQuotes::SwedishQ;
568 tmpl = InsetQuotes::GermanQ;
571 tmpl = InsetQuotes::PolishQ;
574 tmpl = InsetQuotes::FrenchQ;
577 tmpl = InsetQuotes::DanishQ;
580 params.quotes_language = tmpl;
582 } else if (token == "\\quotes_times") {
584 switch(lex.GetInteger()) {
586 params.quotes_times = InsetQuotes::SingleQ;
589 params.quotes_times = InsetQuotes::DoubleQ;
592 } else if (token == "\\papersize") {
593 int tmpret = lex.FindToken(string_papersize);
597 params.papersize2 = tmpret;
598 } else if (token == "\\paperpackage") {
599 int tmpret = lex.FindToken(string_paperpackages);
602 params.paperpackage = BufferParams::PACKAGE_NONE;
604 params.paperpackage = tmpret;
605 } else if (token == "\\use_geometry") {
607 params.use_geometry = lex.GetInteger();
608 } else if (token == "\\use_amsmath") {
610 params.use_amsmath = lex.GetInteger();
611 } else if (token == "\\paperorientation") {
612 int tmpret = lex.FindToken(string_orientation);
613 if (tmpret == -1) ++tmpret;
614 if (tmpret != LYX_LAYOUT_DEFAULT)
615 params.orientation = static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
616 } else if (token == "\\paperwidth") {
618 params.paperwidth = lex.GetString();
619 } else if (token == "\\paperheight") {
621 params.paperheight = lex.GetString();
622 } else if (token == "\\leftmargin") {
624 params.leftmargin = lex.GetString();
625 } else if (token == "\\topmargin") {
627 params.topmargin = lex.GetString();
628 } else if (token == "\\rightmargin") {
630 params.rightmargin = lex.GetString();
631 } else if (token == "\\bottommargin") {
633 params.bottommargin = lex.GetString();
634 } else if (token == "\\headheight") {
636 params.headheight = lex.GetString();
637 } else if (token == "\\headsep") {
639 params.headsep = lex.GetString();
640 } else if (token == "\\footskip") {
642 params.footskip = lex.GetString();
643 } else if (token == "\\paperfontsize") {
645 params.fontsize = strip(lex.GetString());
646 } else if (token == "\\papercolumns") {
648 params.columns = lex.GetInteger();
649 } else if (token == "\\papersides") {
651 switch(lex.GetInteger()) {
653 case 1: params.sides = LyXTextClass::OneSide; break;
654 case 2: params.sides = LyXTextClass::TwoSides; break;
656 } else if (token == "\\paperpagestyle") {
658 params.pagestyle = strip(lex.GetString());
659 } else if (token == "\\bullet") {
661 int index = lex.GetInteger();
663 int temp_int = lex.GetInteger();
664 params.user_defined_bullets[index].setFont(temp_int);
665 params.temp_bullets[index].setFont(temp_int);
667 temp_int = lex.GetInteger();
668 params.user_defined_bullets[index].setCharacter(temp_int);
669 params.temp_bullets[index].setCharacter(temp_int);
671 temp_int = lex.GetInteger();
672 params.user_defined_bullets[index].setSize(temp_int);
673 params.temp_bullets[index].setSize(temp_int);
675 string temp_str = lex.GetString();
676 if (temp_str != "\\end_bullet") {
677 // this element isn't really necessary for
678 // parsing but is easier for humans
679 // to understand bullets. Put it back and
680 // set a debug message?
681 lex.printError("\\end_bullet expected, got" + temp_str);
682 //how can I put it back?
684 } else if (token == "\\bulletLaTeX") {
686 int index = lex.GetInteger();
688 string temp_str = lex.GetString(), sum_str;
689 while (temp_str != "\\end_bullet") {
690 // this loop structure is needed when user
691 // enters an empty string since the first
692 // thing returned will be the \\end_bullet
694 // if the LaTeX entry has spaces. Each element
695 // therefore needs to be read in turn
698 temp_str = lex.GetString();
700 params.user_defined_bullets[index].setText(sum_str);
701 params.temp_bullets[index].setText(sum_str);
702 } else if (token == "\\secnumdepth") {
704 params.secnumdepth = lex.GetInteger();
705 } else if (token == "\\tocdepth") {
707 params.tocdepth = lex.GetInteger();
708 } else if (token == "\\spacing") {
710 string tmp = strip(lex.GetString());
711 Spacing::Space tmp_space = Spacing::Default;
713 if (tmp == "single") {
714 tmp_space = Spacing::Single;
715 } else if (tmp == "onehalf") {
716 tmp_space = Spacing::Onehalf;
717 } else if (tmp == "double") {
718 tmp_space = Spacing::Double;
719 } else if (tmp == "other") {
721 tmp_space = Spacing::Other;
722 tmp_val = lex.GetFloat();
724 lex.printError("Unknown spacing token: '$$Token'");
726 // Small hack so that files written with klyx will be
729 par->spacing.set(tmp_space, tmp_val);
731 params.spacing.set(tmp_space, tmp_val);
733 } else if (token == "\\paragraph_spacing") {
735 string tmp = strip(lex.GetString());
736 if (tmp == "single") {
737 par->spacing.set(Spacing::Single);
738 } else if (tmp == "onehalf") {
739 par->spacing.set(Spacing::Onehalf);
740 } else if (tmp == "double") {
741 par->spacing.set(Spacing::Double);
742 } else if (tmp == "other") {
744 par->spacing.set(Spacing::Other,
747 lex.printError("Unknown spacing token: '$$Token'");
749 } else if (token == "\\float_placement") {
751 params.float_placement = lex.GetString();
752 } else if (token == "\\family") {
754 font.setLyXFamily(lex.GetString());
755 } else if (token == "\\series") {
757 font.setLyXSeries(lex.GetString());
758 } else if (token == "\\shape") {
760 font.setLyXShape(lex.GetString());
761 } else if (token == "\\size") {
763 font.setLyXSize(lex.GetString());
764 } else if (token == "\\latex") {
766 string tok = lex.GetString();
767 // This is dirty, but gone with LyX3. (Asger)
768 if (tok == "no_latex")
769 font.setLatex(LyXFont::OFF);
770 else if (tok == "latex")
771 font.setLatex(LyXFont::ON);
772 else if (tok == "default")
773 font.setLatex(LyXFont::INHERIT);
775 lex.printError("Unknown LaTeX font flag "
777 } else if (token == "\\lang") {
779 string tok = lex.GetString();
780 Languages::iterator lit = languages.find(tok);
781 if (lit != languages.end()) {
782 font.setLanguage(&(*lit).second);
784 font.setLanguage(params.language_info);
785 lex.printError("Unknown language `$$Token'");
787 } else if (token == "\\emph") {
789 font.setEmph(font.setLyXMisc(lex.GetString()));
790 } else if (token == "\\bar") {
792 string tok = lex.GetString();
793 // This is dirty, but gone with LyX3. (Asger)
795 font.setUnderbar(LyXFont::ON);
796 else if (tok == "no")
797 font.setUnderbar(LyXFont::OFF);
798 else if (tok == "default")
799 font.setUnderbar(LyXFont::INHERIT);
801 lex.printError("Unknown bar font flag "
803 } else if (token == "\\noun") {
805 font.setNoun(font.setLyXMisc(lex.GetString()));
806 } else if (token == "\\color") {
808 font.setLyXColor(lex.GetString());
809 } else if (token == "\\align") {
810 int tmpret = lex.FindToken(string_align);
811 if (tmpret == -1) ++tmpret;
812 if (tmpret != LYX_LAYOUT_DEFAULT) { // tmpret != 99 ???
814 for (; tmpret > 0; --tmpret)
815 tmpret2 = tmpret2 * 2;
816 par->align = LyXAlignment(tmpret2);
818 } else if (token == "\\added_space_top") {
820 par->added_space_top = VSpace(lex.GetString());
821 } else if (token == "\\added_space_bottom") {
823 par->added_space_bottom = VSpace(lex.GetString());
824 } else if (token == "\\pextra_type") {
826 par->pextra_type = lex.GetInteger();
827 } else if (token == "\\pextra_width") {
829 par->pextra_width = lex.GetString();
830 } else if (token == "\\pextra_widthp") {
832 par->pextra_widthp = lex.GetString();
833 } else if (token == "\\pextra_alignment") {
835 par->pextra_alignment = lex.GetInteger();
836 } else if (token == "\\pextra_hfill") {
838 par->pextra_hfill = lex.GetInteger();
839 } else if (token == "\\pextra_start_minipage") {
841 par->pextra_start_minipage = lex.GetInteger();
842 } else if (token == "\\labelwidthstring") {
844 par->labelwidthstring = lex.GetString();
845 // do not delete this token, it is still needed!
846 } else if (token == "\\end_inset") {
847 lyxerr << "Solitary \\end_inset. Missing \\begin_inset?.\n"
848 << "Last inset read was: " << last_inset_read
850 // Simply ignore this. The insets do not have
852 // But insets should read it, it is a part of
853 // the inset isn't it? Lgb.
854 } else if (token == "\\begin_inset") {
855 // Should be moved out into its own function/method. (Lgb)
857 string tmptok = lex.GetString();
858 last_inset_read = tmptok;
859 // test the different insets
860 if (tmptok == "Quotes") {
861 Inset * inset = new InsetQuotes;
862 inset->Read(this, lex);
863 par->InsertInset(pos, inset, font);
865 } else if (tmptok == "External") {
866 Inset * inset = new InsetExternal;
867 inset->Read(this, lex);
868 par->InsertInset(pos, inset, font);
870 } else if (tmptok == "FormulaMacro") {
871 Inset * inset = new InsetFormulaMacro;
872 inset->Read(this, lex);
873 par->InsertInset(pos, inset, font);
875 } else if (tmptok == "Formula") {
876 Inset * inset = new InsetFormula;
877 inset->Read(this, lex);
878 par->InsertInset(pos, inset, font);
880 } else if (tmptok == "Figure") {
881 Inset * inset = new InsetFig(100, 100, this);
882 inset->Read(this, lex);
883 par->InsertInset(pos, inset, font);
885 } else if (tmptok == "Info") {
886 Inset * inset = new InsetInfo;
887 inset->Read(this, lex);
888 par->InsertInset(pos, inset, font);
890 } else if (tmptok == "Include") {
891 Inset * inset = new InsetInclude(string(), this);
892 inset->Read(this, lex);
893 par->InsertInset(pos, inset, font);
895 } else if (tmptok == "ERT") {
896 Inset * inset = new InsetERT;
897 inset->Read(this, lex);
898 par->InsertInset(pos, inset, font);
900 } else if (tmptok == "Tabular") {
901 Inset * inset = new InsetTabular(this);
902 inset->Read(this, lex);
903 par->InsertInset(pos, inset, font);
905 } else if (tmptok == "Text") {
906 Inset * inset = new InsetText;
907 inset->Read(this, lex);
908 par->InsertInset(pos, inset, font);
910 } else if (tmptok == "Foot") {
911 Inset * inset = new InsetFoot;
912 inset->Read(this, lex);
913 par->InsertInset(pos, inset, font);
915 } else if (tmptok == "Marginal") {
916 Inset * inset = new InsetMarginal;
917 inset->Read(this, lex);
918 par->InsertInset(pos, inset, font);
920 } else if (tmptok == "Minipage") {
921 Inset * inset = new InsetMinipage;
922 inset->Read(this, lex);
923 par->InsertInset(pos, inset, font);
925 } else if (tmptok == "Float") {
927 string tmptok = lex.GetString();
928 Inset * inset = new InsetFloat(tmptok);
929 inset->Read(this, lex);
930 par->InsertInset(pos, inset, font);
932 } else if (tmptok == "List") {
933 Inset * inset = new InsetList;
934 inset->Read(this, lex);
935 par->InsertInset(pos, inset, font);
937 } else if (tmptok == "Theorem") {
938 Inset * inset = new InsetList;
939 inset->Read(this, lex);
940 par->InsertInset(pos, inset, font);
942 } else if (tmptok == "Caption") {
943 Inset * inset = new InsetCaption;
944 inset->Read(this, lex);
945 par->InsertInset(pos, inset, font);
947 } else if (tmptok == "GRAPHICS") {
948 Inset * inset = new InsetGraphics;
949 //inset->Read(this, lex);
950 par->InsertInset(pos, inset, font);
951 } else if (tmptok == "LatexCommand") {
953 inscmd.Read(this, lex);
955 if (inscmd.getCmdName() == "cite") {
956 inset = new InsetCitation(inscmd.getContents(), inscmd.getOptions());
957 } else if (inscmd.getCmdName() == "bibitem") {
958 lex.printError("Wrong place for bibitem");
959 inset = inscmd.Clone();
960 } else if (inscmd.getCmdName() == "BibTeX") {
961 inset = new InsetBibtex(inscmd.getContents(), inscmd.getOptions(), this);
962 } else if (inscmd.getCmdName() == "index") {
963 inset = new InsetIndex(inscmd.getContents());
964 } else if (inscmd.getCmdName() == "include") {
965 inset = new InsetInclude(inscmd.getContents(), this);
966 } else if (inscmd.getCmdName() == "label") {
967 inset = new InsetLabel(inscmd.getCommand());
968 } else if (inscmd.getCmdName() == "url"
969 || inscmd.getCmdName() == "htmlurl") {
970 inset = new InsetUrl(inscmd.getCommand());
971 } else if (inscmd.getCmdName() == "ref"
972 || inscmd.getCmdName() == "pageref"
973 || inscmd.getCmdName() == "vref"
974 || inscmd.getCmdName() == "vpageref"
975 || inscmd.getCmdName() == "prettyref") {
976 if (!inscmd.getOptions().empty() || !inscmd.getContents().empty()) {
977 inset = new InsetRef(inscmd, this);
979 } else if (inscmd.getCmdName() == "tableofcontents") {
980 inset = new InsetTOC(this);
981 } else if (inscmd.getCmdName() == "listoffigures") {
982 inset = new InsetLOF(this);
983 } else if (inscmd.getCmdName() == "listofalgorithms") {
984 inset = new InsetLOA(this);
985 } else if (inscmd.getCmdName() == "listoftables") {
986 inset = new InsetLOT(this);
987 } else if (inscmd.getCmdName() == "printindex") {
988 inset = new InsetPrintIndex(this);
989 } else if (inscmd.getCmdName() == "lyxparent") {
990 inset = new InsetParent(inscmd.getContents(), this);
994 par->InsertInset(pos, inset, font);
998 } else if (token == "\\SpecialChar") {
999 LyXLayout const & layout =
1000 textclasslist.Style(params.textclass,
1003 // Insets don't make sense in a free-spacing context! ---Kayvan
1004 if (layout.free_spacing) {
1007 string next_token = lex.GetString();
1008 if (next_token == "\\-") {
1009 par->InsertChar(pos, '-', font);
1010 } else if (next_token == "\\protected_separator"
1011 || next_token == "~") {
1012 par->InsertChar(pos, ' ', font);
1014 lex.printError("Token `$$Token' "
1016 "paragraph layout!");
1021 Inset * inset = new InsetSpecialChar;
1022 inset->Read(this, lex);
1023 par->InsertInset(pos, inset, font);
1026 } else if (token == "\\newline") {
1027 par->InsertChar(pos, LyXParagraph::META_NEWLINE, font);
1029 } else if (token == "\\LyXTable") {
1030 #ifdef USE_TABULAR_INSETS
1031 Inset * inset = new InsetTabular(this);
1032 inset->Read(this, lex);
1033 par->InsertInset(pos, inset, font);
1036 par->table = new LyXTable(lex);
1038 } else if (token == "\\hfill") {
1039 par->InsertChar(pos, LyXParagraph::META_HFILL, font);
1041 } else if (token == "\\protected_separator") { // obsolete
1042 // This is a backward compability thingie. (Lgb)
1043 // Remove it later some time...introduced with fileformat
1045 LyXLayout const & layout =
1046 textclasslist.Style(params.textclass,
1049 if (layout.free_spacing) {
1050 par->InsertChar(pos, ' ', font);
1052 Inset * inset = new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
1053 par->InsertInset(pos, inset, font);
1056 } else if (token == "\\bibitem") { // ale970302
1058 par->bibkey = new InsetBibKey;
1059 par->bibkey->Read(this, lex);
1060 }else if (token == "\\backslash") {
1061 par->InsertChar(pos, '\\', font);
1063 }else if (token == "\\the_end") {
1064 the_end_read = true;
1066 // This should be insurance for the future: (Asger)
1067 lex.printError("Unknown token `$$Token'. "
1068 "Inserting as text.");
1069 for(string::const_iterator cit = token.begin();
1070 cit != token.end(); ++cit) {
1071 par->InsertChar(pos, (*cit), font);
1075 return the_end_read;
1078 bool Buffer::readFile(LyXLex & lex, LyXParagraph * par)
1084 token = lex.GetString();
1085 if (token == "\\lyxformat") { // the first token _must_ be...
1087 format = lex.GetFloat();
1089 if (LYX_FORMAT - format > 0.05) {
1090 printf(_("Warning: need lyxformat %.2f but found %.2f\n"),
1091 LYX_FORMAT, format);
1093 if (format - LYX_FORMAT > 0.05) {
1094 printf(_("ERROR: need lyxformat %.2f but found %.2f\n"),
1095 LYX_FORMAT, format);
1097 bool the_end = readLyXformat2(lex, par);
1098 // Formats >= 2.13 support "\the_end" marker
1105 WriteAlert(_("Warning!"),
1106 _("Reading of document is not complete"),
1107 _("Maybe the document is truncated"));
1108 // We simulate a safe reading anyways to allow
1109 // users to take the chance... (Asger)
1113 WriteAlert(_("ERROR!"),
1114 _("Old LyX file format found. "
1115 "Use LyX 0.10.x to read this!"));
1119 } else { // "\\lyxformat" not found
1120 WriteAlert(_("ERROR!"), _("Not a LyX file!"));
1123 WriteAlert(_("ERROR!"), _("Unable to read file!"));
1129 // Should probably be moved to somewhere else: BufferView? LyXView?
1130 bool Buffer::save() const
1132 // We don't need autosaves in the immediate future. (Asger)
1133 resetAutosaveTimers();
1137 if (lyxrc.make_backup) {
1138 s = fileName() + '~';
1139 if (!lyxrc.backupdir_path.empty())
1140 s = AddName(lyxrc.backupdir_path,
1141 subst(CleanupPath(s),'/','!'));
1143 // Rename is the wrong way of making a backup,
1144 // this is the correct way.
1145 /* truss cp fil fil2:
1146 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
1147 stat("LyXVC.lyx", 0xEFFFF688) = 0
1148 open("LyXVC.lyx", O_RDONLY) = 3
1149 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
1150 fstat(4, 0xEFFFF508) = 0
1151 fstat(3, 0xEFFFF508) = 0
1152 read(3, " # T h i s f i l e w".., 8192) = 5579
1153 write(4, " # T h i s f i l e w".., 5579) = 5579
1154 read(3, 0xEFFFD4A0, 8192) = 0
1157 chmod("LyXVC3.lyx", 0100644) = 0
1158 lseek(0, 0, SEEK_CUR) = 46440
1162 // Should proabaly have some more error checking here.
1163 // Should be cleaned up in 0.13, at least a bit.
1164 // Doing it this way, also makes the inodes stay the same.
1165 // This is still not a very good solution, in particular we
1166 // might loose the owner of the backup.
1167 FileInfo finfo(fileName());
1168 if (finfo.exist()) {
1169 mode_t fmode = finfo.getMode();
1170 struct utimbuf times = {
1171 finfo.getAccessTime(),
1172 finfo.getModificationTime() };
1174 ifstream ifs(fileName().c_str());
1175 ofstream ofs(s.c_str(), ios::out|ios::trunc);
1180 ::chmod(s.c_str(), fmode);
1182 if (::utime(s.c_str(), ×)) {
1183 lyxerr << "utime error." << endl;
1186 lyxerr << "LyX was not able to make "
1187 "backupcopy. Beware." << endl;
1192 if (writeFile(fileName(), false)) {
1195 // now delete the autosavefile
1196 string a = OnlyPath(fileName());
1198 a += OnlyFilename(fileName());
1200 FileInfo fileinfo(a);
1201 if (fileinfo.exist()) {
1202 if (::remove(a.c_str()) != 0) {
1203 WriteFSAlert(_("Could not delete "
1204 "auto-save file!"), a);
1208 // Saving failed, so backup is not backup
1209 if (lyxrc.make_backup) {
1210 ::rename(s.c_str(), fileName().c_str());
1218 // Returns false if unsuccesful
1219 bool Buffer::writeFile(string const & fname, bool flag) const
1221 // if flag is false writeFile will not create any GUI
1222 // warnings, only cerr.
1223 // Needed for autosave in background or panic save (Matthias 120496)
1225 if (read_only && (fname == filename)) {
1226 // Here we should come with a question if we should
1227 // perform the write anyway.
1229 lyxerr << _("Error! Document is read-only: ")
1232 WriteAlert(_("Error! Document is read-only: "),
1237 FileInfo finfo(fname);
1238 if (finfo.exist() && !finfo.writable()) {
1239 // Here we should come with a question if we should
1240 // try to do the save anyway. (i.e. do a chmod first)
1242 lyxerr << _("Error! Cannot write file: ")
1245 WriteFSAlert(_("Error! Cannot write file: "),
1250 ofstream ofs(fname.c_str());
1253 lyxerr << _("Error! Cannot open file: ")
1256 WriteFSAlert(_("Error! Cannot open file: "),
1260 // The top of the file should not be written by params.
1262 // write out a comment in the top of the file
1263 ofs << '#' << LYX_DOCVERSION
1264 << " created this file. For more info see http://www.lyx.org/\n";
1265 ofs.setf(ios::showpoint|ios::fixed);
1267 ofs << "\\lyxformat " << setw(4) << LYX_FORMAT << "\n";
1269 // now write out the buffer paramters.
1270 params.writeFile(ofs);
1272 char footnoteflag = 0;
1275 // this will write out all the paragraphs
1276 // using recursive descent.
1277 paragraph->writeFile(this, ofs, params, footnoteflag, depth);
1279 // Write marker that shows file is complete
1280 ofs << "\n\\the_end" << endl;
1282 // how to check if close went ok?
1287 void Buffer::writeFileAscii(string const & fname, int linelen)
1289 LyXFont font1, font2;
1291 char c, footnoteflag = 0, depth = 0;
1293 LyXParagraph::size_type i;
1294 int j, h, ltype = 0, ltype_depth = 0,
1295 * clen = 0, actcell = 0, actpos = 0, cell = 0, cells = 0,
1298 bool ref_printed = false;
1300 ofstream ofs(fname.c_str());
1302 WriteFSAlert(_("Error: Cannot write file:"), fname);
1306 string fname1 = TmpFileName();
1307 LyXParagraph * par = paragraph;
1313 par->footnoteflag != LyXParagraph::NO_FOOTNOTE ||
1317 || par->previous->footnoteflag == LyXParagraph::NO_FOOTNOTE
1322 /* begins a footnote environment ? */
1323 if (footnoteflag != par->footnoteflag) {
1324 footnoteflag = par->footnoteflag;
1326 j = strlen(string_footnotekinds[par->footnotekind])+4;
1327 if (currlinelen + j > linelen)
1330 << string_footnotekinds[par->footnotekind] << "] ";
1336 /* begins or ends a deeper area ?*/
1337 if (depth != par->depth) {
1338 if (par->depth > depth) {
1339 while (par->depth > depth) {
1344 while (par->depth < depth) {
1350 /* First write the layout */
1351 tmp = textclasslist.NameOfLayout(params.textclass, par->layout);
1352 if (tmp == "Itemize") {
1354 ltype_depth = depth+1;
1355 } else if (tmp == "Enumerate") {
1357 ltype_depth = depth+1;
1358 } else if (strstr(tmp.c_str(), "ection")) {
1360 ltype_depth = depth+1;
1361 } else if (strstr(tmp.c_str(), "aragraph")) {
1363 ltype_depth = depth+1;
1364 } else if (tmp == "Description") {
1366 ltype_depth = depth+1;
1367 } else if (tmp == "Abstract") {
1370 } else if (tmp == "Bibliography") {
1378 /* maybe some vertical spaces */
1380 /* the labelwidthstring used in lists */
1384 /* some pagebreaks? */
1388 /* what about the alignment */
1391 /* dummy layout, that means a footnote ended */
1392 footnoteflag = LyXParagraph::NO_FOOTNOTE;
1396 lyxerr << "Should this ever happen?" << endl;
1400 //LyXLayout const & layout =
1401 // textclasslist.Style(params.textclass,
1402 // par->GetLayout()); // unused
1403 //bool free_spc = layout.free_spacing; //unused
1406 /* It might be a table */
1410 cells = par->table->columns;
1411 clen = new int [cells];
1412 memset(clen, 0, sizeof(int) * cells);
1414 for (i = 0, j = 0, h = 1; i < par->size(); ++i, ++h) {
1415 c = par->GetChar(i);
1416 if (c == LyXParagraph::META_INSET) {
1417 if ((inset = par->GetInset(i))) {
1419 std::ostringstream ost;
1420 inset->Ascii(this, ost);
1421 h += ost.str().length();
1424 inset->Ascii(this, ost);
1426 char * tmp = ost.str();
1432 } else if (c == LyXParagraph::META_NEWLINE) {
1436 j = (++j) % par->table->NumberOfCellsInRow(actcell);
1444 font1 = LyXFont(LyXFont::ALL_INHERIT, params.language_info);
1446 for (i = 0, actpos = 1; i < par->size(); ++i, ++actpos) {
1447 if (!i && !footnoteflag && !noparbreak){
1449 for(j = 0; j < depth; ++j)
1451 currlinelen = depth * 2;
1453 case 0: /* Standard */
1454 case 4: /* (Sub)Paragraph */
1455 case 5: /* Description */
1457 case 6: /* Abstract */
1458 ofs << "Abstract\n\n";
1460 case 7: /* Bibliography */
1462 ofs << "References\n\n";
1467 ofs << par->labelstring << " ";
1470 if (ltype_depth > depth) {
1471 for(j = ltype_depth - 1; j > depth; --j)
1473 currlinelen += (ltype_depth-depth)*2;
1477 for(j = 0; j < cells; ++j) {
1479 for(h = 0; h < (clen[j] + 1);
1484 for(j = 0; j < depth; ++j)
1486 currlinelen = depth * 2;
1487 if (ltype_depth > depth) {
1488 for(j = ltype_depth;
1491 currlinelen += (ltype_depth-depth)*2;
1497 font2 = par->GetFontSettings(params, i);
1498 if (font1.latex() != font2.latex()) {
1499 if (font2.latex() == LyXFont::OFF)
1506 c = par->GetChar(i);
1510 case LyXParagraph::META_INSET:
1511 if ((inset = par->GetInset(i))) {
1513 inset->Ascii(this, ofs);
1514 currlinelen += (ofs.tellp() - fpos);
1515 actpos += (ofs.tellp() - fpos) - 1;
1518 case LyXParagraph::META_NEWLINE:
1521 if (par->table->NumberOfCellsInRow(actcell) <= cell) {
1522 for(j = actpos; j < clen[cell - 1]; ++j)
1525 for(j = 0; j < depth; ++j)
1527 currlinelen = depth*2;
1528 if (ltype_depth > depth) {
1529 for(j = ltype_depth; j > depth; --j)
1531 currlinelen += (ltype_depth-depth) * 2;
1533 for(j = 0; j < cells; ++j) {
1535 for(h = 0; h < (clen[j] + 1); ++h)
1539 for(j = 0; j < depth; ++j)
1541 currlinelen = depth * 2;
1542 if (ltype_depth > depth) {
1543 for(j = ltype_depth;
1546 currlinelen += (ltype_depth-depth)*2;
1552 j < clen[cell - 1]; ++j)
1558 currlinelen = actpos = 0;
1562 for(j = 0; j < depth; ++j)
1564 currlinelen = depth * 2;
1565 if (ltype_depth > depth) {
1566 for(j = ltype_depth;
1569 currlinelen += (ltype_depth - depth) * 2;
1575 case LyXParagraph::META_HFILL:
1582 if (currlinelen > linelen - 10
1583 && c == ' ' && i + 2 < par->size()) {
1585 for(j = 0; j < depth; ++j)
1587 currlinelen = depth * 2;
1588 if (ltype_depth > depth) {
1589 for(j = ltype_depth;
1592 currlinelen += (ltype_depth-depth)*2;
1594 } else if (c != '\0')
1597 lyxerr.debug() << "writeAsciiFile: NULL char in structure." << endl;
1604 for(j = actpos; j < clen[cell - 1]; ++j)
1607 for(j = 0; j < depth; ++j)
1609 currlinelen = depth * 2;
1610 if (ltype_depth > depth) {
1611 for(j = ltype_depth; j > depth; --j)
1613 currlinelen += (ltype_depth - depth) * 2;
1615 for(j = 0; j < cells; ++j) {
1617 for(h = 0; h < (clen[j] + 1); ++h)
1631 void Buffer::makeLaTeXFile(string const & fname,
1632 string const & original_path,
1633 bool nice, bool only_body)
1635 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
1637 niceFile = nice; // this will be used by Insetincludes.
1639 tex_code_break_column = lyxrc.ascii_linelen;
1641 LyXTextClass const & tclass =
1642 textclasslist.TextClass(params.textclass);
1644 ofstream ofs(fname.c_str());
1646 WriteFSAlert(_("Error: Cannot open file: "), fname);
1650 // validate the buffer.
1651 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
1652 LaTeXFeatures features(params, tclass.numLayouts());
1654 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
1657 // The starting paragraph of the coming rows is the
1658 // first paragraph of the document. (Asger)
1659 texrow.start(paragraph, 0);
1661 if (!only_body && nice) {
1662 ofs << "%% " LYX_DOCVERSION " created this file. "
1663 "For more info, see http://www.lyx.org/.\n"
1664 "%% Do not edit unless you really know what "
1669 lyxerr.debug() << "lyx header finished" << endl;
1670 // There are a few differences between nice LaTeX and usual files:
1671 // usual is \batchmode and has a
1672 // special input@path to allow the including of figures
1673 // with either \input or \includegraphics (what figinsets do).
1674 // batchmode is not set if there is a tex_code_break_column.
1675 // In this case somebody is interested in the generated LaTeX,
1676 // so this is OK. input@path is set when the actual parameter
1677 // original_path is set. This is done for usual tex-file, but not
1678 // for nice-latex-file. (Matthias 250696)
1681 // code for usual, NOT nice-latex-file
1682 ofs << "\\batchmode\n"; // changed
1683 // from \nonstopmode
1686 if (!original_path.empty()) {
1687 ofs << "\\makeatletter\n"
1688 << "\\def\\input@path{{"
1689 << original_path << "/}}\n"
1690 << "\\makeatother\n";
1696 ofs << "\\documentclass";
1698 string options; // the document class options.
1700 if (tokenPos(tclass.opt_fontsize(),
1701 '|', params.fontsize) >= 0) {
1702 // only write if existing in list (and not default)
1703 options += params.fontsize;
1708 if (!params.use_geometry &&
1709 (params.paperpackage == BufferParams::PACKAGE_NONE)) {
1710 switch (params.papersize) {
1711 case BufferParams::PAPER_A4PAPER:
1712 options += "a4paper,";
1714 case BufferParams::PAPER_USLETTER:
1715 options += "letterpaper,";
1717 case BufferParams::PAPER_A5PAPER:
1718 options += "a5paper,";
1720 case BufferParams::PAPER_B5PAPER:
1721 options += "b5paper,";
1723 case BufferParams::PAPER_EXECUTIVEPAPER:
1724 options += "executivepaper,";
1726 case BufferParams::PAPER_LEGALPAPER:
1727 options += "legalpaper,";
1733 if (params.sides != tclass.sides()) {
1734 switch (params.sides) {
1735 case LyXTextClass::OneSide:
1736 options += "oneside,";
1738 case LyXTextClass::TwoSides:
1739 options += "twoside,";
1746 if (params.columns != tclass.columns()) {
1747 if (params.columns == 2)
1748 options += "twocolumn,";
1750 options += "onecolumn,";
1753 if (!params.use_geometry
1754 && params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1755 options += "landscape,";
1757 // language should be a parameter to \documentclass
1758 bool use_babel = false;
1759 if (params.language_info->lang() == "hebrew") // This seems necessary
1760 features.UsedLanguages.insert(default_language);
1761 if (params.language != "default" ||
1762 !features.UsedLanguages.empty() ) {
1764 for (LaTeXFeatures::LanguageList::const_iterator cit =
1765 features.UsedLanguages.begin();
1766 cit != features.UsedLanguages.end(); ++cit)
1767 options += (*cit)->lang() + ",";
1768 options += params.language_info->lang() + ',';
1771 // the user-defined options
1772 if (!params.options.empty()) {
1773 options += params.options + ',';
1776 if (!options.empty()){
1777 options = strip(options, ',');
1778 ofs << '[' << options << ']';
1782 << textclasslist.LatexnameOfClass(params.textclass)
1785 // end of \documentclass defs
1787 // font selection must be done before loading fontenc.sty
1788 if (params.fonts != "default") {
1789 ofs << "\\usepackage{" << params.fonts << "}\n";
1792 // this one is not per buffer
1793 if (lyxrc.fontenc != "default") {
1794 ofs << "\\usepackage[" << lyxrc.fontenc
1799 if (params.inputenc == "auto") {
1800 string doc_encoding =
1801 params.language_info->encoding()->LatexName();
1803 // Create a list with all the input encodings used
1805 set<string> encodings;
1806 for (LaTeXFeatures::LanguageList::const_iterator it =
1807 features.UsedLanguages.begin();
1808 it != features.UsedLanguages.end(); ++it)
1809 if ((*it)->encoding()->LatexName() != doc_encoding)
1810 encodings.insert((*it)->encoding()->LatexName());
1812 ofs << "\\usepackage[";
1813 for (set<string>::const_iterator it = encodings.begin();
1814 it != encodings.end(); ++it)
1816 ofs << doc_encoding << "]{inputenc}\n";
1818 } else if (params.inputenc != "default") {
1819 ofs << "\\usepackage[" << params.inputenc
1824 // At the very beginning the text parameters.
1825 if (params.paperpackage != BufferParams::PACKAGE_NONE) {
1826 switch (params.paperpackage) {
1827 case BufferParams::PACKAGE_A4:
1828 ofs << "\\usepackage{a4}\n";
1831 case BufferParams::PACKAGE_A4WIDE:
1832 ofs << "\\usepackage{a4wide}\n";
1835 case BufferParams::PACKAGE_WIDEMARGINSA4:
1836 ofs << "\\usepackage[widemargins]{a4}\n";
1841 if (params.use_geometry) {
1842 ofs << "\\usepackage{geometry}\n";
1844 ofs << "\\geometry{verbose";
1845 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1846 ofs << ",landscape";
1847 switch (params.papersize2) {
1848 case BufferParams::VM_PAPER_CUSTOM:
1849 if (!params.paperwidth.empty())
1850 ofs << ",paperwidth="
1851 << params.paperwidth;
1852 if (!params.paperheight.empty())
1853 ofs << ",paperheight="
1854 << params.paperheight;
1856 case BufferParams::VM_PAPER_USLETTER:
1857 ofs << ",letterpaper";
1859 case BufferParams::VM_PAPER_USLEGAL:
1860 ofs << ",legalpaper";
1862 case BufferParams::VM_PAPER_USEXECUTIVE:
1863 ofs << ",executivepaper";
1865 case BufferParams::VM_PAPER_A3:
1868 case BufferParams::VM_PAPER_A4:
1871 case BufferParams::VM_PAPER_A5:
1874 case BufferParams::VM_PAPER_B3:
1877 case BufferParams::VM_PAPER_B4:
1880 case BufferParams::VM_PAPER_B5:
1884 // default papersize ie BufferParams::VM_PAPER_DEFAULT
1885 switch (lyxrc.default_papersize) {
1886 case BufferParams::PAPER_DEFAULT: // keep compiler happy
1887 case BufferParams::PAPER_USLETTER:
1888 ofs << ",letterpaper";
1890 case BufferParams::PAPER_LEGALPAPER:
1891 ofs << ",legalpaper";
1893 case BufferParams::PAPER_EXECUTIVEPAPER:
1894 ofs << ",executivepaper";
1896 case BufferParams::PAPER_A3PAPER:
1899 case BufferParams::PAPER_A4PAPER:
1902 case BufferParams::PAPER_A5PAPER:
1905 case BufferParams::PAPER_B5PAPER:
1910 if (!params.topmargin.empty())
1911 ofs << ",tmargin=" << params.topmargin;
1912 if (!params.bottommargin.empty())
1913 ofs << ",bmargin=" << params.bottommargin;
1914 if (!params.leftmargin.empty())
1915 ofs << ",lmargin=" << params.leftmargin;
1916 if (!params.rightmargin.empty())
1917 ofs << ",rmargin=" << params.rightmargin;
1918 if (!params.headheight.empty())
1919 ofs << ",headheight=" << params.headheight;
1920 if (!params.headsep.empty())
1921 ofs << ",headsep=" << params.headsep;
1922 if (!params.footskip.empty())
1923 ofs << ",footskip=" << params.footskip;
1927 if (params.use_amsmath
1928 && !tclass.provides(LyXTextClass::amsmath)) {
1929 ofs << "\\usepackage{amsmath}\n";
1933 if (tokenPos(tclass.opt_pagestyle(),
1934 '|', params.pagestyle) >= 0) {
1935 if (params.pagestyle == "fancy") {
1936 ofs << "\\usepackage{fancyhdr}\n";
1939 ofs << "\\pagestyle{" << params.pagestyle << "}\n";
1943 // We try to load babel late, in case it interferes
1944 // with other packages.
1946 ofs << lyxrc.language_package << endl;
1950 if (params.secnumdepth != tclass.secnumdepth()) {
1951 ofs << "\\setcounter{secnumdepth}{"
1952 << params.secnumdepth
1956 if (params.tocdepth != tclass.tocdepth()) {
1957 ofs << "\\setcounter{tocdepth}{"
1963 if (params.paragraph_separation) {
1964 switch (params.defskip.kind()) {
1965 case VSpace::SMALLSKIP:
1966 ofs << "\\setlength\\parskip{\\smallskipamount}\n";
1968 case VSpace::MEDSKIP:
1969 ofs << "\\setlength\\parskip{\\medskipamount}\n";
1971 case VSpace::BIGSKIP:
1972 ofs << "\\setlength\\parskip{\\bigskipamount}\n";
1974 case VSpace::LENGTH:
1975 ofs << "\\setlength\\parskip{"
1976 << params.defskip.length().asLatexString()
1979 default: // should never happen // Then delete it.
1980 ofs << "\\setlength\\parskip{\\medskipamount}\n";
1985 ofs << "\\setlength\\parindent{0pt}\n";
1989 // Now insert the LyX specific LaTeX commands...
1991 // The optional packages;
1992 string preamble(features.getPackages());
1994 // this might be useful...
1995 preamble += "\n\\makeatletter\n";
1997 // Some macros LyX will need
1998 string tmppreamble(features.getMacros());
2000 if (!tmppreamble.empty()) {
2001 preamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2002 "LyX specific LaTeX commands.\n"
2003 + tmppreamble + '\n';
2006 // the text class specific preamble
2007 tmppreamble = features.getTClassPreamble();
2008 if (!tmppreamble.empty()) {
2009 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2010 "Textclass specific LaTeX commands.\n"
2011 + tmppreamble + '\n';
2014 /* the user-defined preamble */
2015 if (!params.preamble.empty()) {
2016 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2017 "User specified LaTeX commands.\n"
2018 + params.preamble + '\n';
2021 preamble += "\\makeatother\n";
2023 // Itemize bullet settings need to be last in case the user
2024 // defines their own bullets that use a package included
2025 // in the user-defined preamble -- ARRae
2026 // Actually it has to be done much later than that
2027 // since some packages like frenchb make modifications
2028 // at \begin{document} time -- JMarc
2030 for (int i = 0; i < 4; ++i) {
2031 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
2032 if (bullets_def.empty())
2033 bullets_def="\\AtBeginDocument{\n";
2034 bullets_def += " \\renewcommand{\\labelitemi";
2036 // `i' is one less than the item to modify
2043 bullets_def += "ii";
2049 bullets_def += "}{" +
2050 params.user_defined_bullets[i].getText()
2055 if (!bullets_def.empty())
2056 preamble += bullets_def + "}\n\n";
2058 for (int j = countChar(preamble, '\n'); j-- ;) {
2065 ofs << "\\begin{document}\n";
2068 lyxerr.debug() << "preamble finished, now the body." << endl;
2069 if (!lyxrc.language_auto_begin && params.language != "default") {
2070 ofs << subst(lyxrc.language_command_begin, "$$lang",
2076 latexParagraphs(ofs, paragraph, 0, texrow);
2078 // add this just in case after all the paragraphs
2082 if (!lyxrc.language_auto_end && params.language != "default") {
2083 ofs << subst(lyxrc.language_command_end, "$$lang",
2090 ofs << "\\end{document}\n";
2093 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
2095 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
2099 // Just to be sure. (Asger)
2102 // tex_code_break_column's value is used to decide
2103 // if we are in batchmode or not (within mathed_write()
2104 // in math_write.C) so we must set it to a non-zero
2105 // value when we leave otherwise we save incorrect .lyx files.
2106 tex_code_break_column = lyxrc.ascii_linelen;
2110 lyxerr << "File was not closed properly." << endl;
2113 lyxerr.debug() << "Finished making latex file." << endl;
2118 // LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
2120 void Buffer::latexParagraphs(ostream & ofs, LyXParagraph * par,
2121 LyXParagraph * endpar, TexRow & texrow) const
2123 bool was_title = false;
2124 bool already_title = false;
2126 std::ostringstream ftnote;
2128 char * tmpholder = 0;
2134 while (par != endpar) {
2135 #ifndef HAVE_SSTREAM
2138 ftnote << tmpholder;
2139 delete [] tmpholder;
2145 lyxerr[Debug::LATEX] << "Error in latexParagraphs."
2148 LyXLayout const & layout =
2149 textclasslist.Style(params.textclass,
2152 if (layout.intitle) {
2153 if (already_title) {
2154 lyxerr <<"Error in latexParagraphs: You"
2155 " should not mix title layouts"
2156 " with normal ones." << endl;
2159 } else if (was_title && !already_title) {
2160 ofs << "\\maketitle\n";
2162 already_title = true;
2165 // We are at depth 0 so we can just use
2166 // ordinary \footnote{} generation
2167 // flag this with ftcount
2169 if (layout.isEnvironment()
2170 || par->pextra_type != LyXParagraph::PEXTRA_NONE) {
2171 par = par->TeXEnvironment(this, params, ofs, texrow,
2172 ftnote, ft_texrow, ftcount);
2174 par = par->TeXOnePar(this, params, ofs, texrow, false
2177 ftnote, ft_texrow, ftcount
2182 // Write out what we've generated...
2185 ofs << "\\addtocounter{footnote}{-"
2189 ofs << ftnote.str();
2190 texrow += ft_texrow;
2192 // The extra .c_str() is needed when we use
2193 // lyxstring instead of the STL string class.
2194 ftnote.str(string().c_str());
2196 delete [] ftnote.str();
2201 #ifndef HAVE_SSTREAM
2203 // I hate strstreams
2204 tmpholder = ftnote.str();
2208 #ifndef HAVE_SSTREAM
2209 delete [] tmpholder;
2211 // It might be that we only have a title in this document
2212 if (was_title && !already_title) {
2213 ofs << "\\maketitle\n";
2219 bool Buffer::isLatex() const
2221 return textclasslist.TextClass(params.textclass).outputType() == LATEX;
2225 bool Buffer::isLinuxDoc() const
2227 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC;
2231 bool Buffer::isLiterate() const
2233 return textclasslist.TextClass(params.textclass).outputType() == LITERATE;
2237 bool Buffer::isDocBook() const
2239 return textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2243 bool Buffer::isSGML() const
2245 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC ||
2246 textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2250 void Buffer::sgmlOpenTag(ostream & os, int depth,
2251 string const & latexname) const
2253 os << string(depth, ' ') << "<" << latexname << ">\n";
2257 void Buffer::sgmlCloseTag(ostream & os, int depth,
2258 string const & latexname) const
2260 os << string(depth, ' ') << "</" << latexname << ">\n";
2264 void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
2266 LyXParagraph * par = paragraph;
2268 niceFile = nice; // this will be used by Insetincludes.
2270 string top_element = textclasslist.LatexnameOfClass(params.textclass);
2271 string environment_stack[10];
2274 int depth = 0; // paragraph depth
2276 ofstream ofs(fname.c_str());
2279 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2283 LyXTextClass const & tclass =
2284 textclasslist.TextClass(params.textclass);
2286 LaTeXFeatures features(params, tclass.numLayouts());
2290 tex_code_break_column = lyxrc.ascii_linelen;
2292 //tex_code_break_column = 0;
2297 string sgml_includedfiles=features.getIncludedFiles();
2299 if (params.preamble.empty() && sgml_includedfiles.empty()) {
2300 ofs << "<!doctype linuxdoc system>\n\n";
2302 ofs << "<!doctype linuxdoc system [ "
2303 << params.preamble << sgml_includedfiles << " \n]>\n\n";
2306 if(params.options.empty())
2307 sgmlOpenTag(ofs, 0, top_element);
2309 string top = top_element;
2311 top += params.options;
2312 sgmlOpenTag(ofs, 0, top);
2316 ofs << "<!-- " << LYX_DOCVERSION
2317 << " created this file. For more info see http://www.lyx.org/"
2321 int desc_on = 0; // description mode
2322 LyXLayout const & style =
2323 textclasslist.Style(params.textclass,
2326 // treat <toc> as a special case for compatibility with old code
2327 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2328 Inset * inset = par->GetInset(0);
2329 Inset::Code lyx_code = inset->LyxCode();
2330 if (lyx_code == Inset::TOC_CODE){
2331 string temp = "toc";
2332 sgmlOpenTag(ofs, depth, temp);
2336 linuxDocHandleFootnote(ofs, par, depth);
2342 // environment tag closing
2343 for( ; depth > par->depth; --depth) {
2344 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2345 environment_stack[depth].erase();
2348 // write opening SGML tags
2349 switch(style.latextype) {
2350 case LATEX_PARAGRAPH:
2351 if(depth == par->depth
2352 && !environment_stack[depth].empty()) {
2353 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2354 environment_stack[depth].erase();
2360 sgmlOpenTag(ofs, depth, style.latexname());
2365 LinuxDocError(par, 0,
2366 _("Error : Wrong depth for"
2367 " LatexType Command.\n"));
2369 if (!environment_stack[depth].empty()){
2370 sgmlCloseTag(ofs, depth,
2371 environment_stack[depth]);
2375 environment_stack[depth].erase();
2376 sgmlOpenTag(ofs, depth, style.latexname());
2379 case LATEX_ENVIRONMENT:
2380 case LATEX_ITEM_ENVIRONMENT:
2381 if(depth == par->depth
2382 && environment_stack[depth] != style.latexname()
2383 && !environment_stack[depth].empty()) {
2385 sgmlCloseTag(ofs, depth,
2386 environment_stack[depth]);
2387 environment_stack[depth].erase();
2389 if (depth < par->depth) {
2391 environment_stack[depth].erase();
2393 if (environment_stack[depth] != style.latexname()) {
2396 sgmlOpenTag(ofs, depth, temp);
2398 environment_stack[depth] = style.latexname();
2399 sgmlOpenTag(ofs, depth,
2400 environment_stack[depth]);
2402 if(style.latextype == LATEX_ENVIRONMENT) break;
2404 desc_on = (style.labeltype == LABEL_MANUAL);
2411 sgmlOpenTag(ofs, depth + 1, item_name);
2414 sgmlOpenTag(ofs, depth, style.latexname());
2421 SimpleLinuxDocOnePar(ofs, par, desc_on, depth);
2425 linuxDocHandleFootnote(ofs, par, depth);
2427 while(par && par->IsDummy());
2431 // write closing SGML tags
2432 switch(style.latextype) {
2434 case LATEX_ENVIRONMENT:
2435 case LATEX_ITEM_ENVIRONMENT:
2438 sgmlCloseTag(ofs, depth, style.latexname());
2444 for(; depth > 0; --depth)
2445 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2447 if(!environment_stack[depth].empty())
2448 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2452 sgmlCloseTag(ofs, 0, top_element);
2456 // How to check for successful close
2461 void Buffer::linuxDocHandleFootnote(ostream & os, LyXParagraph * & par,
2464 string tag = "footnote";
2466 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2467 sgmlOpenTag(os, depth + 1, tag);
2468 SimpleLinuxDocOnePar(os, par, 0, depth + 1);
2469 sgmlCloseTag(os, depth + 1, tag);
2476 void Buffer::DocBookHandleCaption(ostream & os, string & inner_tag,
2477 int const depth, int desc_on,
2478 LyXParagraph * & par)
2480 LyXParagraph * tpar = par;
2483 && (tpar->footnoteflag != LyXParagraph::NO_FOOTNOTE)
2485 && (tpar->layout != textclasslist.NumberOfLayout(params.textclass,
2489 tpar->layout == textclasslist.NumberOfLayout(params.textclass,
2490 "Caption").second) {
2491 sgmlOpenTag(os, depth + 1, inner_tag);
2493 SimpleDocBookOnePar(os, extra_par, tpar,
2494 desc_on, depth + 2);
2495 sgmlCloseTag(os, depth+1, inner_tag);
2496 if(!extra_par.empty())
2503 void Buffer::DocBookHandleFootnote(ostream & os, LyXParagraph * & par,
2506 string tag, inner_tag;
2507 string tmp_par, extra_par;
2508 bool inner_span = false;
2511 // Someone should give this enum a proper name (Lgb)
2519 SOME_ENUM last = NO_ONE;
2520 SOME_ENUM present = FOOTNOTE_LIKE;
2522 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2523 if(last == present) {
2525 if(!tmp_par.empty()) {
2528 sgmlCloseTag(os, depth + 1, inner_tag);
2529 sgmlOpenTag(os, depth + 1, inner_tag);
2536 if(!inner_tag.empty()) sgmlCloseTag(os, depth + 1,
2538 if(!extra_par.empty()) os << extra_par;
2539 if(!tag.empty()) sgmlCloseTag(os, depth, tag);
2542 switch (par->footnotekind) {
2543 case LyXParagraph::FOOTNOTE:
2544 case LyXParagraph::ALGORITHM:
2547 present = FOOTNOTE_LIKE;
2550 case LyXParagraph::MARGIN:
2553 present = MARGIN_LIKE;
2556 case LyXParagraph::FIG:
2557 case LyXParagraph::WIDE_FIG:
2559 inner_tag = "title";
2563 case LyXParagraph::TAB:
2564 case LyXParagraph::WIDE_TAB:
2566 inner_tag = "title";
2571 sgmlOpenTag(os, depth, tag);
2572 if ((present == TAB_LIKE) || (present == FIG_LIKE)) {
2573 DocBookHandleCaption(os, inner_tag, depth,
2577 sgmlOpenTag(os, depth + 1, inner_tag);
2580 // ignore all caption here, we processed them above!!!
2581 if (par->layout != textclasslist
2582 .NumberOfLayout(params.textclass,
2583 "Caption").second) {
2585 std::ostringstream ost;
2589 SimpleDocBookOnePar(ost, extra_par, par,
2590 desc_on, depth + 2);
2592 tmp_par += ost.str().c_str();
2595 char * ctmp = ost.str();
2600 tmp_par = frontStrip(strip(tmp_par));
2606 if(!inner_tag.empty()) sgmlCloseTag(os, depth + 1, inner_tag);
2607 if(!extra_par.empty()) os << extra_par;
2608 if(!tag.empty()) sgmlCloseTag(os, depth, tag);
2613 // push a tag in a style stack
2614 void Buffer::push_tag(ostream & os, char const * tag,
2615 int & pos, char stack[5][3])
2617 // pop all previous tags
2618 for (int j = pos; j >= 0; --j)
2619 os << "</" << stack[j] << ">";
2622 sprintf(stack[++pos], "%s", tag);
2625 for (int i = 0; i <= pos; ++i)
2626 os << "<" << stack[i] << ">";
2630 void Buffer::pop_tag(ostream & os, char const * tag,
2631 int & pos, char stack[5][3])
2635 // pop all tags till specified one
2636 for (j = pos; (j >= 0) && (strcmp(stack[j], tag)); --j)
2637 os << "</" << stack[j] << ">";
2640 os << "</" << tag << ">";
2642 // push all tags, but the specified one
2643 for (j = j + 1; j <= pos; ++j) {
2644 os << "<" << stack[j] << ">";
2645 strcpy(stack[j-1], stack[j]);
2651 // Handle internal paragraph parsing -- layout already processed.
2653 // checks, if newcol chars should be put into this line
2654 // writes newline, if necessary.
2656 void linux_doc_line_break(ostream & os, unsigned int & colcount,
2657 const unsigned int newcol)
2660 if (colcount > lyxrc.ascii_linelen) {
2662 colcount = newcol; // assume write after this call
2667 void Buffer::SimpleLinuxDocOnePar(ostream & os, LyXParagraph * par,
2668 int desc_on, int const /*depth*/)
2670 LyXFont font1, font2;
2673 LyXParagraph::size_type main_body;
2675 LyXLayout const & style = textclasslist.Style(params.textclass,
2678 char family_type = 0; // family font flag
2679 bool is_bold = false; // series font flag
2680 char shape_type = 0; // shape font flag
2681 bool is_em = false; // emphasis (italic) font flag
2683 int stack_num = -1; // style stack position
2684 // Can this be rewritten to use a std::stack, please. (Lgb)
2685 char stack[5][3]; // style stack
2686 unsigned int char_line_count = 5; // Heuristic choice ;-)
2688 if (style.labeltype != LABEL_MANUAL)
2691 main_body = par->BeginningOfMainBody();
2693 // gets paragraph main font
2695 font1 = style.labelfont;
2700 // parsing main loop
2701 for (LyXParagraph::size_type i = 0;
2702 i < par->size(); ++i) {
2714 font2 = par->getFont(params, i);
2716 if (font1.family() != font2.family()) {
2717 switch(family_type) {
2719 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2720 push_tag(os, "tt", stack_num, stack);
2723 else if (font2.family() == LyXFont::SANS_FAMILY) {
2724 push_tag(os, "sf", stack_num, stack);
2729 pop_tag(os, "tt", stack_num, stack);
2730 if (font2.family() == LyXFont::SANS_FAMILY) {
2731 push_tag(os, "sf", stack_num, stack);
2738 pop_tag(os, "sf", stack_num, stack);
2739 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2740 push_tag(os, "tt", stack_num, stack);
2749 if (font1.series() != font2.series()) {
2750 if (font2.series() == LyXFont::BOLD_SERIES) {
2751 push_tag(os, "bf", stack_num, stack);
2753 } else if (is_bold) {
2754 pop_tag(os, "bf", stack_num, stack);
2759 // handle italic and slanted fonts
2760 if (font1.shape() != font2.shape()) {
2761 switch(shape_type) {
2763 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2764 push_tag(os, "it", stack_num, stack);
2766 } else if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2767 push_tag(os, "sl", stack_num, stack);
2772 pop_tag(os, "it", stack_num, stack);
2773 if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2774 push_tag(os, "sl", stack_num, stack);
2781 pop_tag(os, "sl", stack_num, stack);
2782 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2783 push_tag(os, "it", stack_num, stack);
2791 if (font1.emph() != font2.emph()) {
2792 if (font2.emph() == LyXFont::ON) {
2793 push_tag(os, "em", stack_num, stack);
2796 pop_tag(os, "em", stack_num, stack);
2801 c = par->GetChar(i);
2803 if (c == LyXParagraph::META_INSET) {
2804 inset = par->GetInset(i);
2805 inset->Linuxdoc(this, os);
2808 if (font2.latex() == LyXFont::ON) {
2809 // "TeX"-Mode on == > SGML-Mode on.
2811 os << c; // see LaTeX-Generation...
2815 if (par->linuxDocConvertChar(c, sgml_string)
2816 && !style.free_spacing) { // in freespacing
2818 // non-breaking characters
2822 linux_doc_line_break(os, char_line_count, 6);
2826 linux_doc_line_break(os, char_line_count, 1);
2831 char_line_count += sgml_string.length();
2837 // needed if there is an optional argument but no contents
2838 if (main_body > 0 && main_body == par->size()) {
2842 // pop all defined Styles
2843 for (j = stack_num; j >= 0; --j) {
2844 linux_doc_line_break(os,
2846 3 + strlen(stack[j]));
2847 os << "</" << stack[j] << ">";
2850 // resets description flag correctly
2853 // <tag> not closed...
2854 linux_doc_line_break(os, char_line_count, 6);
2858 // fprintf(file, "</p>");
2864 // Print an error message.
2865 void Buffer::LinuxDocError(LyXParagraph * par, int pos,
2866 char const * message)
2868 // insert an error marker in text
2869 InsetError * new_inset = new InsetError(message);
2870 par->InsertInset(pos, new_inset);
2873 // This constant defines the maximum number of
2874 // environment layouts that can be nesteded.
2875 // The same applies for command layouts.
2876 // These values should be more than enough.
2877 // José Matos (1999/07/22)
2879 enum { MAX_NEST_LEVEL = 25};
2881 void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
2883 LyXParagraph * par = paragraph;
2885 niceFile = nice; // this will be used by Insetincludes.
2887 string top_element= textclasslist.LatexnameOfClass(params.textclass);
2888 // Please use a real stack.
2889 string environment_stack[MAX_NEST_LEVEL];
2890 string environment_inner[MAX_NEST_LEVEL];
2891 // Please use a real stack.
2892 string command_stack[MAX_NEST_LEVEL];
2893 bool command_flag= false;
2894 int command_depth= 0, command_base= 0, cmd_depth= 0;
2896 string item_name, command_name;
2897 string c_depth, c_params, tmps;
2899 int depth = 0; // paragraph depth
2900 LyXTextClass const & tclass =
2901 textclasslist.TextClass(params.textclass);
2903 LaTeXFeatures features(params, tclass.numLayouts());
2907 tex_code_break_column = lyxrc.ascii_linelen;
2909 //tex_code_break_column = 0;
2911 ofstream ofs(fname.c_str());
2913 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2920 string sgml_includedfiles=features.getIncludedFiles();
2922 ofs << "<!doctype " << top_element
2923 << " public \"-//OASIS//DTD DocBook V3.1//EN\"";
2925 if (params.preamble.empty() && sgml_includedfiles.empty())
2928 ofs << "\n [ " << params.preamble
2929 << sgml_includedfiles << " \n]>\n\n";
2931 if(params.options.empty())
2932 sgmlOpenTag(ofs, 0, top_element);
2934 string top = top_element;
2936 top += params.options;
2937 sgmlOpenTag(ofs, 0, top);
2941 ofs << "<!-- DocBook file was created by " << LYX_DOCVERSION
2942 << "\n See http://www.lyx.org/ for more information -->\n";
2945 int desc_on = 0; // description mode
2946 LyXLayout const & style =
2947 textclasslist.Style(params.textclass,
2950 // environment tag closing
2951 for( ; depth > par->depth; --depth) {
2952 if(environment_inner[depth] != "!-- --") {
2953 item_name= "listitem";
2954 sgmlCloseTag(ofs, command_depth + depth,
2956 if( environment_inner[depth] == "varlistentry")
2957 sgmlCloseTag(ofs, depth+command_depth,
2958 environment_inner[depth]);
2960 sgmlCloseTag(ofs, depth + command_depth,
2961 environment_stack[depth]);
2962 environment_stack[depth].erase();
2963 environment_inner[depth].erase();
2966 if(depth == par->depth
2967 && environment_stack[depth] != style.latexname()
2968 && !environment_stack[depth].empty()) {
2969 if(environment_inner[depth] != "!-- --") {
2970 item_name= "listitem";
2971 sgmlCloseTag(ofs, command_depth+depth,
2973 if( environment_inner[depth] == "varlistentry")
2975 depth + command_depth,
2976 environment_inner[depth]);
2979 sgmlCloseTag(ofs, depth + command_depth,
2980 environment_stack[depth]);
2982 environment_stack[depth].erase();
2983 environment_inner[depth].erase();
2986 // Write opening SGML tags.
2987 switch(style.latextype) {
2988 case LATEX_PARAGRAPH:
2989 if(style.latexname() != "dummy")
2990 sgmlOpenTag(ofs, depth+command_depth,
2996 LinuxDocError(par, 0,
2997 _("Error : Wrong depth for "
2998 "LatexType Command.\n"));
3000 command_name = style.latexname();
3002 tmps = style.latexparam();
3003 c_params = split(tmps, c_depth,'|');
3005 cmd_depth= atoi(c_depth.c_str());
3008 if(cmd_depth<command_base) {
3009 for(int j = command_depth;
3010 j >= command_base; --j)
3011 if(!command_stack[j].empty())
3012 sgmlCloseTag(ofs, j, command_stack[j]);
3013 command_depth= command_base= cmd_depth;
3014 } else if(cmd_depth <= command_depth) {
3015 for(int j = command_depth;
3016 j >= cmd_depth; --j)
3018 if(!command_stack[j].empty())
3019 sgmlCloseTag(ofs, j, command_stack[j]);
3020 command_depth= cmd_depth;
3022 command_depth= cmd_depth;
3024 command_depth = command_base = cmd_depth;
3025 command_flag = true;
3027 command_stack[command_depth]= command_name;
3029 // treat label as a special case for
3030 // more WYSIWYM handling.
3031 if (par->GetChar(0) == LyXParagraph::META_INSET) {
3032 Inset * inset = par->GetInset(0);
3033 Inset::Code lyx_code = inset->LyxCode();
3034 if (lyx_code == Inset::LABEL_CODE){
3035 command_name += " id=\"";
3036 command_name += (static_cast<InsetCommand *>(inset))->getContents();
3037 command_name += "\"";
3042 sgmlOpenTag(ofs, depth + command_depth, command_name);
3043 item_name = "title";
3044 sgmlOpenTag(ofs, depth + 1 + command_depth, item_name);
3047 case LATEX_ENVIRONMENT:
3048 case LATEX_ITEM_ENVIRONMENT:
3049 if (depth < par->depth) {
3051 environment_stack[depth].erase();
3054 if (environment_stack[depth] != style.latexname()) {
3055 environment_stack[depth] = style.latexname();
3056 environment_inner[depth] = "!-- --";
3057 sgmlOpenTag(ofs, depth + command_depth,
3058 environment_stack[depth]);
3060 if(environment_inner[depth] != "!-- --") {
3061 item_name= "listitem";
3063 command_depth + depth,
3065 if (environment_inner[depth] == "varlistentry")
3067 depth + command_depth,
3068 environment_inner[depth]);
3072 if(style.latextype == LATEX_ENVIRONMENT) {
3073 if(!style.latexparam().empty())
3074 sgmlOpenTag(ofs, depth + command_depth,
3075 style.latexparam());
3079 desc_on = (style.labeltype == LABEL_MANUAL);
3082 environment_inner[depth]= "varlistentry";
3084 environment_inner[depth]= "listitem";
3086 sgmlOpenTag(ofs, depth + 1 + command_depth,
3087 environment_inner[depth]);
3091 sgmlOpenTag(ofs, depth + 1 + command_depth,
3095 sgmlOpenTag(ofs, depth + 1 + command_depth,
3100 sgmlOpenTag(ofs, depth + command_depth,
3109 SimpleDocBookOnePar(ofs, extra_par, par, desc_on,
3110 depth + 1 + command_depth);
3113 DocBookHandleFootnote(ofs, par,
3114 depth + 1 + command_depth);
3116 while(par && par->IsDummy());
3119 // write closing SGML tags
3120 switch(style.latextype) {
3123 sgmlCloseTag(ofs, depth + command_depth, end_tag);
3125 case LATEX_ENVIRONMENT:
3126 if(!style.latexparam().empty())
3127 sgmlCloseTag(ofs, depth + command_depth,
3128 style.latexparam());
3130 case LATEX_ITEM_ENVIRONMENT:
3131 if(desc_on == 1) break;
3133 sgmlCloseTag(ofs, depth + 1 + command_depth, end_tag);
3135 case LATEX_PARAGRAPH:
3136 if(style.latexname() != "dummy")
3137 sgmlCloseTag(ofs, depth + command_depth,
3141 sgmlCloseTag(ofs, depth + command_depth,
3148 for(; depth >= 0; --depth) {
3149 if(!environment_stack[depth].empty()) {
3150 if(environment_inner[depth] != "!-- --") {
3151 item_name= "listitem";
3152 sgmlCloseTag(ofs, command_depth + depth,
3154 if( environment_inner[depth] == "varlistentry")
3155 sgmlCloseTag(ofs, depth + command_depth,
3156 environment_inner[depth]);
3159 sgmlCloseTag(ofs, depth + command_depth,
3160 environment_stack[depth]);
3164 for(int j = command_depth; j >= command_base; --j)
3165 if(!command_stack[j].empty())
3166 sgmlCloseTag(ofs, j, command_stack[j]);
3170 sgmlCloseTag(ofs, 0, top_element);
3174 // How to check for successful close
3178 void Buffer::SimpleDocBookOnePar(ostream & os, string & extra,
3179 LyXParagraph * par, int & desc_on,
3184 par->SimpleDocBookOneTablePar(this,
3185 os, extra, desc_on, depth);
3190 bool emph_flag = false;
3192 LyXLayout const & style = textclasslist.Style(params.textclass,
3195 LyXParagraph::size_type main_body;
3196 if (style.labeltype != LABEL_MANUAL)
3199 main_body = par->BeginningOfMainBody();
3201 // gets paragraph main font
3202 LyXFont font1 = main_body > 0 ? style.labelfont : style.font;
3204 int char_line_count = depth;
3205 if(!style.free_spacing)
3206 for (int j = 0; j < depth; ++j)
3209 // parsing main loop
3210 for (LyXParagraph::size_type i = 0;
3211 i < par->size(); ++i) {
3212 LyXFont font2 = par->getFont(params, i);
3214 // handle <emphasis> tag
3215 if (font1.emph() != font2.emph() && i) {
3216 if (font2.emph() == LyXFont::ON) {
3220 os << "</emphasis>";
3225 char c = par->GetChar(i);
3227 if (c == LyXParagraph::META_INSET) {
3228 Inset * inset = par->GetInset(i);
3230 std::ostringstream ost;
3231 inset->DocBook(this, ost);
3232 string tmp_out = ost.str().c_str();
3235 inset->DocBook(this, ost);
3237 char * ctmp = ost.str();
3238 string tmp_out(ctmp);
3242 // This code needs some explanation:
3243 // Two insets are treated specially
3244 // label if it is the first element in a command paragraph
3246 // graphics inside tables or figure floats can't go on
3247 // title (the equivalente in latex for this case is caption
3248 // and title should come first
3251 if(desc_on!= 3 || i!= 0) {
3252 if(!tmp_out.empty() && tmp_out[0] == '@') {
3254 extra += frontStrip(tmp_out, '@');
3256 os << frontStrip(tmp_out, '@');
3261 } else if (font2.latex() == LyXFont::ON) {
3262 // "TeX"-Mode on ==> SGML-Mode on.
3268 if (par->linuxDocConvertChar(c, sgml_string)
3269 && !style.free_spacing) { // in freespacing
3271 // non-breaking characters
3275 os << "\n</term><listitem><para>";
3287 // needed if there is an optional argument but no contents
3288 if (main_body > 0 && main_body == par->size()) {
3292 os << "</emphasis>";
3295 // resets description flag correctly
3298 // <term> not closed...
3306 int Buffer::runLaTeX()
3308 if (!users->text) return 0;
3310 ProhibitInput(users);
3312 // get LaTeX-Filename
3313 string name = getLatexName();
3315 string path = OnlyPath(filename);
3317 string org_path = path;
3318 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3322 Path p(path); // path to LaTeX file
3323 users->owner()->getMiniBuffer()->Set(_("Running LaTeX..."));
3325 // Remove all error insets
3326 bool a = users->removeAutoInsets();
3328 // Always generate the LaTeX file
3329 makeLaTeXFile(name, org_path, false);
3331 // do the LaTex run(s)
3333 string latex_command = lyxrc.pdf_mode ?
3334 lyxrc.pdflatex_command : lyxrc.latex_command;
3335 LaTeX latex(latex_command, name, filepath);
3336 int res = latex.run(terr,
3337 users->owner()->getMiniBuffer()); // running latex
3339 // check return value from latex.run().
3340 if ((res & LaTeX::NO_LOGFILE)) {
3341 WriteAlert(_("LaTeX did not work!"),
3342 _("Missing log file:"), name);
3343 } else if ((res & LaTeX::ERRORS)) {
3344 users->owner()->getMiniBuffer()->Set(_("Done"));
3345 // Insert all errors as errors boxes
3346 users->insertErrors(terr);
3348 // Dvi should also be kept dirty if the latex run
3349 // ends up with errors. However it should be possible
3350 // to view a dirty dvi too.
3352 //no errors or any other things to think about so:
3353 users->owner()->getMiniBuffer()->Set(_("Done"));
3356 // if we removed error insets before we ran LaTeX or if we inserted
3357 // error insets after we ran LaTeX this must be run:
3358 if (a || (res & LaTeX::ERRORS)){
3361 //users->updateScrollbar();
3365 return latex.getNumErrors();
3369 int Buffer::runLiterate()
3371 if (!users->text) return 0;
3373 ProhibitInput(users);
3375 // get LaTeX-Filename
3376 string name = getLatexName();
3377 // get Literate-Filename
3378 string lit_name = OnlyFilename(ChangeExtension (getLatexName(),
3379 lyxrc.literate_extension));
3381 string path = OnlyPath(filename);
3383 string org_path = path;
3384 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3388 Path p(path); // path to Literate file
3389 users->owner()->getMiniBuffer()->Set(_("Running Literate..."));
3391 // Remove all error insets
3392 bool a = users->removeAutoInsets();
3394 // generate the Literate file if necessary
3395 makeLaTeXFile(lit_name, org_path, false);
3397 string latex_command = lyxrc.pdf_mode ?
3398 lyxrc.pdflatex_command : lyxrc.latex_command;
3399 Literate literate(latex_command, name, filepath,
3401 lyxrc.literate_command, lyxrc.literate_error_filter,
3402 lyxrc.build_command, lyxrc.build_error_filter);
3404 int res = literate.weave(terr, users->owner()->getMiniBuffer());
3406 // check return value from literate.weave().
3407 if ((res & Literate::NO_LOGFILE)) {
3408 WriteAlert(_("Literate command did not work!"),
3409 _("Missing log file:"), name);
3410 } else if ((res & Literate::ERRORS)) {
3411 users->owner()->getMiniBuffer()->Set(_("Done"));
3412 // Insert all errors as errors boxes
3413 users->insertErrors(terr);
3415 // Dvi should also be kept dirty if the latex run
3416 // ends up with errors. However it should be possible
3417 // to view a dirty dvi too.
3419 //no errors or any other things to think about so:
3420 users->owner()->getMiniBuffer()->Set(_("Done"));
3423 // if we removed error insets before we ran LaTeX or if we inserted
3424 // error insets after we ran LaTeX this must be run:
3425 if (a || (res & Literate::ERRORS)){
3428 //users->updateScrollbar();
3432 return literate.getNumErrors();
3436 int Buffer::buildProgram()
3438 if (!users->text) return 0;
3440 ProhibitInput(users);
3442 // get LaTeX-Filename
3443 string name = getLatexName();
3444 // get Literate-Filename
3445 string lit_name = OnlyFilename(ChangeExtension(getLatexName(),
3446 lyxrc.literate_extension));
3448 string path = OnlyPath(filename);
3450 string org_path = path;
3451 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3455 Path p(path); // path to Literate file
3456 users->owner()->getMiniBuffer()->Set(_("Building Program..."));
3458 // Remove all error insets
3459 bool a = users->removeAutoInsets();
3461 // generate the LaTeX file if necessary
3462 if (!isNwClean() || a) {
3463 makeLaTeXFile(lit_name, org_path, false);
3467 string latex_command = lyxrc.pdf_mode ?
3468 lyxrc.pdflatex_command : lyxrc.latex_command;
3469 Literate literate(latex_command, name, filepath,
3471 lyxrc.literate_command, lyxrc.literate_error_filter,
3472 lyxrc.build_command, lyxrc.build_error_filter);
3474 int res = literate.build(terr, users->owner()->getMiniBuffer());
3476 // check return value from literate.build().
3477 if ((res & Literate::NO_LOGFILE)) {
3478 WriteAlert(_("Build did not work!"),
3479 _("Missing log file:"), name);
3480 } else if ((res & Literate::ERRORS)) {
3481 users->owner()->getMiniBuffer()->Set(_("Done"));
3482 // Insert all errors as errors boxes
3483 users->insertErrors(terr);
3485 // Literate files should also be kept dirty if the literate
3486 // command run ends up with errors.
3488 //no errors or any other things to think about so:
3489 users->owner()->getMiniBuffer()->Set(_("Done"));
3493 // if we removed error insets before we ran Literate/Build or
3494 // if we inserted error insets after we ran Literate/Build this
3496 if (a || (res & Literate::ERRORS)){
3499 //users->updateScrollbar();
3503 return literate.getNumErrors();
3507 // This should be enabled when the Chktex class is implemented. (Asger)
3508 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
3509 // Other flags: -wall -v0 -x
3510 int Buffer::runChktex()
3512 if (!users->text) return 0;
3514 ProhibitInput(users);
3516 // get LaTeX-Filename
3517 string name = getLatexName();
3518 string path = OnlyPath(filename);
3520 string org_path = path;
3521 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3525 Path p(path); // path to LaTeX file
3526 users->owner()->getMiniBuffer()->Set(_("Running chktex..."));
3528 // Remove all error insets
3529 bool removedErrorInsets = users->removeAutoInsets();
3531 // Generate the LaTeX file if neccessary
3532 makeLaTeXFile(name, org_path, false);
3535 Chktex chktex(lyxrc.chktex_command, name, filepath);
3536 int res = chktex.run(terr); // run chktex
3539 WriteAlert(_("chktex did not work!"),
3540 _("Could not run with file:"), name);
3541 } else if (res > 0) {
3542 // Insert all errors as errors boxes
3543 users->insertErrors(terr);
3546 // if we removed error insets before we ran chktex or if we inserted
3547 // error insets after we ran chktex, this must be run:
3548 if (removedErrorInsets || res){
3551 //users->updateScrollbar();
3559 void Buffer::validate(LaTeXFeatures & features) const
3561 LyXParagraph * par = paragraph;
3562 LyXTextClass const & tclass =
3563 textclasslist.TextClass(params.textclass);
3565 // AMS Style is at document level
3567 features.amsstyle = (params.use_amsmath ||
3568 tclass.provides(LyXTextClass::amsmath));
3571 // We don't use "lyxerr.debug" because of speed. (Asger)
3572 if (lyxerr.debugging(Debug::LATEX))
3573 lyxerr << "Paragraph: " << par << endl;
3575 // Now just follow the list of paragraphs and run
3576 // validate on each of them.
3577 par->validate(features);
3579 // and then the next paragraph
3583 // the bullet shapes are buffer level not paragraph level
3584 // so they are tested here
3585 for (int i = 0; i < 4; ++i) {
3586 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
3587 int font = params.user_defined_bullets[i].getFont();
3590 .user_defined_bullets[i]
3597 features.latexsym = true;
3601 features.amssymb = true;
3603 else if ((font >= 2 && font <= 5)) {
3604 features.pifont = true;
3609 if (lyxerr.debugging(Debug::LATEX)) {
3610 features.showStruct();
3615 void Buffer::setPaperStuff()
3617 params.papersize = BufferParams::PAPER_DEFAULT;
3618 char c1 = params.paperpackage;
3619 if (c1 == BufferParams::PACKAGE_NONE) {
3620 char c2 = params.papersize2;
3621 if (c2 == BufferParams::VM_PAPER_USLETTER)
3622 params.papersize = BufferParams::PAPER_USLETTER;
3623 else if (c2 == BufferParams::VM_PAPER_USLEGAL)
3624 params.papersize = BufferParams::PAPER_LEGALPAPER;
3625 else if (c2 == BufferParams::VM_PAPER_USEXECUTIVE)
3626 params.papersize = BufferParams::PAPER_EXECUTIVEPAPER;
3627 else if (c2 == BufferParams::VM_PAPER_A3)
3628 params.papersize = BufferParams::PAPER_A3PAPER;
3629 else if (c2 == BufferParams::VM_PAPER_A4)
3630 params.papersize = BufferParams::PAPER_A4PAPER;
3631 else if (c2 == BufferParams::VM_PAPER_A5)
3632 params.papersize = BufferParams::PAPER_A5PAPER;
3633 else if ((c2 == BufferParams::VM_PAPER_B3) || (c2 == BufferParams::VM_PAPER_B4) ||
3634 (c2 == BufferParams::VM_PAPER_B5))
3635 params.papersize = BufferParams::PAPER_B5PAPER;
3636 } else if ((c1 == BufferParams::PACKAGE_A4) || (c1 == BufferParams::PACKAGE_A4WIDE) ||
3637 (c1 == BufferParams::PACKAGE_WIDEMARGINSA4))
3638 params.papersize = BufferParams::PAPER_A4PAPER;
3642 // This function should be in Buffer because it's a buffer's property (ale)
3643 string Buffer::getIncludeonlyList(char delim)
3646 for (inset_iterator it = inset_iterator_begin();
3647 it != inset_iterator_end(); ++it) {
3648 if ((*it)->LyxCode() == Inset::INCLUDE_CODE) {
3649 InsetInclude * insetinc =
3650 static_cast<InsetInclude *>(*it);
3651 if (insetinc->isInclude()
3652 && insetinc->isNoLoad()) {
3655 lst += OnlyFilename(ChangeExtension(insetinc->getContents(), string()));
3659 lyxerr.debug() << "Includeonly(" << lst << ')' << endl;
3664 vector<string> Buffer::getLabelList()
3666 /// if this is a child document and the parent is already loaded
3667 /// Use the parent's list instead [ale990407]
3668 if (!params.parentname.empty()
3669 && bufferlist.exists(params.parentname)) {
3670 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3672 return tmp->getLabelList();
3675 vector<string> label_list;
3676 for (inset_iterator it = inset_iterator_begin();
3677 it != inset_iterator_end(); ++it) {
3678 vector<string> l = (*it)->getLabelList();
3679 label_list.insert(label_list.end(), l.begin(), l.end());
3685 vector<vector<Buffer::TocItem> > Buffer::getTocList()
3687 vector<vector<TocItem> > l(4);
3688 LyXParagraph * par = paragraph;
3691 if (par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
3692 if (textclasslist.Style(params.textclass,
3693 par->GetLayout()).labeltype
3694 == LABEL_SENSITIVE) {
3698 tmp.str = par->String(this, false);
3699 switch (par->footnotekind) {
3700 case LyXParagraph::FIG:
3701 case LyXParagraph::WIDE_FIG:
3702 l[TOC_LOF].push_back(tmp);
3704 case LyXParagraph::TAB:
3705 case LyXParagraph::WIDE_TAB:
3706 l[TOC_LOT].push_back(tmp);
3708 case LyXParagraph::ALGORITHM:
3709 l[TOC_LOA].push_back(tmp);
3711 case LyXParagraph::FOOTNOTE:
3712 case LyXParagraph::MARGIN:
3716 } else if (!par->IsDummy()) {
3718 char labeltype = textclasslist.Style(params.textclass,
3719 par->GetLayout()).labeltype;
3721 if (labeltype >= LABEL_COUNTER_CHAPTER
3722 && labeltype <= LABEL_COUNTER_CHAPTER + params.tocdepth) {
3723 // insert this into the table of contents
3728 textclasslist.TextClass(params.textclass).maxcounter());
3729 tmp.str = par->String(this, true);
3730 l[TOC_TOC].push_back(tmp);
3740 // This is also a buffer property (ale)
3741 vector<pair<string,string> > Buffer::getBibkeyList()
3743 /// if this is a child document and the parent is already loaded
3744 /// Use the parent's list instead [ale990412]
3745 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3746 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3748 return tmp->getBibkeyList();
3751 vector<pair<string, string> > keys;
3752 LyXParagraph * par = paragraph;
3755 keys.push_back(pair<string, string>(par->bibkey->getContents(),
3756 par->String(this, false)));
3760 // Might be either using bibtex or a child has bibliography
3762 for (inset_iterator it = inset_iterator_begin();
3763 it != inset_iterator_end(); ++it) {
3764 // Search for Bibtex or Include inset
3765 if ((*it)->LyxCode() == Inset::BIBTEX_CODE) {
3766 vector<pair<string,string> > tmp =
3767 static_cast<InsetBibtex*>(*it)->getKeys();
3768 keys.insert(keys.end(), tmp.begin(), tmp.end());
3769 } else if ((*it)->LyxCode() == Inset::INCLUDE_CODE) {
3770 vector<pair<string,string> > tmp =
3771 static_cast<InsetInclude*>(*it)->getKeys();
3772 keys.insert(keys.end(), tmp.begin(), tmp.end());
3781 bool Buffer::isDepClean(string const & name) const
3783 DEPCLEAN * item = dep_clean;
3784 while (item && item->master != name)
3786 if (!item) return true;
3791 void Buffer::markDepClean(string const & name)
3794 dep_clean = new DEPCLEAN;
3795 dep_clean->clean = true;
3796 dep_clean->master = name;
3797 dep_clean->next = 0;
3799 DEPCLEAN* item = dep_clean;
3800 while (item && item->master != name)
3805 item = new DEPCLEAN;
3807 item->master = name;
3814 bool Buffer::Dispatch(string const & command)
3816 // Split command string into command and argument
3817 string cmd, line = frontStrip(command);
3818 string arg = strip(frontStrip(split(line, cmd, ' ')));
3820 return Dispatch(lyxaction.LookupFunc(cmd.c_str()), arg.c_str());
3824 bool Buffer::Dispatch(int action, string const & argument)
3826 bool dispatched = true;
3829 MenuExport(this, argument);
3839 void Buffer::resize()
3841 /// resize the BufferViews!
3847 void Buffer::resizeInsets(BufferView * bv)
3849 /// then remove all LyXText in text-insets
3850 LyXParagraph * par = paragraph;
3851 for(;par;par = par->next) {
3852 par->resizeInsetsLyXText(bv);
3856 void Buffer::ChangeLanguage(Language const * from, Language const * to)
3859 LyXParagraph * par = paragraph;
3861 par->ChangeLanguage(params, from, to);
3867 bool Buffer::isMultiLingual()
3870 LyXParagraph * par = paragraph;
3872 if (par->isMultiLingual(params))
3880 Buffer::inset_iterator::inset_iterator(LyXParagraph * paragraph,
3881 LyXParagraph::size_type pos)
3883 it = par->InsetIterator(pos);
3884 if (it == par->inset_iterator_end()) {
3891 void Buffer::inset_iterator::SetParagraph() {
3893 it = par->inset_iterator_begin();
3894 if (it != par->inset_iterator_end())
3899 // We maintain an invariant that whenever par = 0 then it = 0