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 bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par)
242 char depth = 0; // signed or unsigned?
244 LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
245 LyXParagraph::footnote_kind footnotekind = LyXParagraph::FOOTNOTE;
247 bool the_end_read = false;
249 LyXParagraph * return_par = 0;
250 LyXFont font(LyXFont::ALL_INHERIT, params.language_info);
251 if (format < 2.16 && params.language == "hebrew")
252 font.setLanguage(default_language);
254 // If we are inserting, we cheat and get a token in advance
255 bool has_token = false;
259 par = new LyXParagraph;
261 users->text->BreakParagraph(users);
262 return_par = users->text->FirstParagraph();
265 // We don't want to adopt the parameters from the
266 // document we insert, so we skip until the text begins:
269 pretoken = lex.GetString();
270 if (pretoken == "\\layout") {
282 pretoken = lex.GetString();
285 // Profiling show this should give a lot: (Asger)
286 string const token = pretoken;
290 the_end_read = parseSingleLyXformat2Token(lex, par, return_par,
303 paragraph = return_par;
310 Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
311 LyXParagraph *& return_par,
312 string const & token, int & pos,
313 char & depth, LyXFont & font
315 , LyXParagraph::footnote_flag & footnoteflag,
316 LyXParagraph::footnote_kind & footnotekind
320 bool the_end_read = false;
321 // We'll remove this later. (Lgb)
322 static string last_inset_read;
324 if (token[0] != '\\') {
325 for (string::const_iterator cit = token.begin();
326 cit != token.end(); ++cit) {
327 par->InsertChar(pos, (*cit), font);
330 } else if (token == "\\i") {
331 Inset * inset = new InsetLatexAccent;
332 inset->Read(this, lex);
333 par->InsertInset(pos, inset, font);
335 } else if (token == "\\layout") {
340 par = new LyXParagraph(par);
344 string layoutname = lex.GetString();
345 pair<bool, LyXTextClass::LayoutList::size_type> pp
346 = textclasslist.NumberOfLayout(params.textclass,
349 par->layout = pp.second;
350 } else { // layout not found
351 // use default layout "Standard" (0)
354 // Test whether the layout is obsolete.
355 LyXLayout const & layout =
356 textclasslist.Style(params.textclass,
358 if (!layout.obsoleted_by().empty())
360 textclasslist.NumberOfLayout(params.textclass,
361 layout.obsoleted_by()).second;
363 par->footnoteflag = footnoteflag;
364 par->footnotekind = footnotekind;
367 font = LyXFont(LyXFont::ALL_INHERIT, params.language_info);
368 if (format < 2.16 && params.language == "hebrew")
369 font.setLanguage(default_language);
371 } else if (token == "\\end_float") {
376 par = new LyXParagraph(par);
378 footnotekind = LyXParagraph::FOOTNOTE;
379 footnoteflag = LyXParagraph::NO_FOOTNOTE;
382 par->layout = LYX_DUMMY_LAYOUT;
383 font = LyXFont(LyXFont::ALL_INHERIT, params.language_info);
384 if (format < 2.16 && params.language == "hebrew")
385 font.setLanguage(default_language);
386 } else if (token == "\\begin_float") {
387 int tmpret = lex.FindToken(string_footnotekinds);
388 if (tmpret == -1) ++tmpret;
389 if (tmpret != LYX_LAYOUT_DEFAULT)
390 footnotekind = static_cast<LyXParagraph::footnote_kind>(tmpret); // bad
391 if (footnotekind == LyXParagraph::FOOTNOTE
392 || footnotekind == LyXParagraph::MARGIN)
393 footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
395 footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
397 } else if (token == "\\begin_float") {
398 // This is the compability reader, unfinished but tested.
401 string tmptok = lex.GetString();
402 //lyxerr << "old float: " << tmptok << endl;
407 if (tmptok == "footnote") {
408 inset = new InsetFoot;
409 } else if (tmptok == "margin") {
410 inset = new InsetMarginal;
411 } else if (tmptok == "fig") {
412 inset = new InsetFloat("figure");
413 old_float += "placement htbp\n";
414 } else if (tmptok == "tab") {
415 inset = new InsetFloat("table");
416 old_float += "placement htbp\n";
417 } else if (tmptok == "alg") {
418 inset = new InsetFloat("algorithm");
419 old_float += "placement htbp\n";
420 } else if (tmptok == "wide-fig") {
421 InsetFloat * tmp = new InsetFloat("figure");
424 old_float += "placement htbp\n";
425 } else if (tmptok == "wide-tab") {
426 InsetFloat * tmp = new InsetFloat("table");
429 old_float += "placement htbp\n";
432 if (!inset) return false; // no end read yet
434 old_float += "collapsed true\n";
436 // Here we need to check for \end_deeper and handle that
437 // before we do the footnote parsing.
438 // This _is_ a hack! (Lgb)
441 string tmp = lex.GetString();
442 if (tmp == "\\end_deeper") {
443 lyxerr << "\\end_deeper caught!" << endl;
445 lex.printError("\\end_deeper: "
446 "depth is already null");
457 old_float += lex.getLongString("\\end_float");
458 old_float += "\n\\end_inset\n";
459 //lyxerr << "float body: " << old_float << endl;
462 istringstream istr(old_float.c_str());
464 istrstream istr(old_float.c_str());
468 nylex.setStream(istr);
470 inset->Read(this, nylex);
471 par->InsertInset(pos, inset, font);
474 } else if (token == "\\begin_deeper") {
476 } else if (token == "\\end_deeper") {
478 lex.printError("\\end_deeper: "
479 "depth is already null");
483 } else if (token == "\\begin_preamble") {
484 params.readPreamble(lex);
485 } else if (token == "\\textclass") {
487 pair<bool, LyXTextClassList::size_type> pp =
488 textclasslist.NumberOfClass(lex.GetString());
490 params.textclass = pp.second;
492 lex.printError("Unknown textclass `$$Token'");
493 params.textclass = 0;
495 if (!textclasslist.Load(params.textclass)) {
496 // if the textclass wasn't loaded properly
497 // we need to either substitute another
498 // or stop loading the file.
499 // I can substitute but I don't see how I can
500 // stop loading... ideas?? ARRae980418
501 WriteAlert(_("Textclass Loading Error!"),
502 string(_("Can't load textclass ")) +
503 textclasslist.NameOfClass(params.textclass),
504 _("-- substituting default"));
505 params.textclass = 0;
507 } else if (token == "\\options") {
509 params.options = lex.GetString();
510 } else if (token == "\\language") {
511 params.readLanguage(lex);
512 } else if (token == "\\fontencoding") {
514 } else if (token == "\\inputencoding") {
516 params.inputenc = lex.GetString();
517 } else if (token == "\\graphics") {
518 params.readGraphicsDriver(lex);
519 } else if (token == "\\fontscheme") {
521 params.fonts = lex.GetString();
522 } else if (token == "\\noindent") {
523 par->noindent = true;
524 } else if (token == "\\fill_top") {
525 par->added_space_top = VSpace(VSpace::VFILL);
526 } else if (token == "\\fill_bottom") {
527 par->added_space_bottom = VSpace(VSpace::VFILL);
528 } else if (token == "\\line_top") {
529 par->line_top = true;
530 } else if (token == "\\line_bottom") {
531 par->line_bottom = true;
532 } else if (token == "\\pagebreak_top") {
533 par->pagebreak_top = true;
534 } else if (token == "\\pagebreak_bottom") {
535 par->pagebreak_bottom = true;
536 } else if (token == "\\start_of_appendix") {
537 par->start_of_appendix = true;
538 } else if (token == "\\paragraph_separation") {
539 int tmpret = lex.FindToken(string_paragraph_separation);
540 if (tmpret == -1) ++tmpret;
541 if (tmpret != LYX_LAYOUT_DEFAULT)
542 params.paragraph_separation =
543 static_cast<BufferParams::PARSEP>(tmpret);
544 } else if (token == "\\defskip") {
546 params.defskip = VSpace(lex.GetString());
547 } else if (token == "\\epsfig") { // obsolete
548 // Indeed it is obsolete, but we HAVE to be backwards
549 // compatible until 0.14, because otherwise all figures
550 // in existing documents are irretrivably lost. (Asger)
551 params.readGraphicsDriver(lex);
552 } else if (token == "\\quotes_language") {
553 int tmpret = lex.FindToken(string_quotes_language);
554 if (tmpret == -1) ++tmpret;
555 if (tmpret != LYX_LAYOUT_DEFAULT) {
556 InsetQuotes::quote_language tmpl =
557 InsetQuotes::EnglishQ;
560 tmpl = InsetQuotes::EnglishQ;
563 tmpl = InsetQuotes::SwedishQ;
566 tmpl = InsetQuotes::GermanQ;
569 tmpl = InsetQuotes::PolishQ;
572 tmpl = InsetQuotes::FrenchQ;
575 tmpl = InsetQuotes::DanishQ;
578 params.quotes_language = tmpl;
580 } else if (token == "\\quotes_times") {
582 switch(lex.GetInteger()) {
584 params.quotes_times = InsetQuotes::SingleQ;
587 params.quotes_times = InsetQuotes::DoubleQ;
590 } else if (token == "\\papersize") {
591 int tmpret = lex.FindToken(string_papersize);
595 params.papersize2 = tmpret;
596 } else if (token == "\\paperpackage") {
597 int tmpret = lex.FindToken(string_paperpackages);
600 params.paperpackage = BufferParams::PACKAGE_NONE;
602 params.paperpackage = tmpret;
603 } else if (token == "\\use_geometry") {
605 params.use_geometry = lex.GetInteger();
606 } else if (token == "\\use_amsmath") {
608 params.use_amsmath = lex.GetInteger();
609 } else if (token == "\\paperorientation") {
610 int tmpret = lex.FindToken(string_orientation);
611 if (tmpret == -1) ++tmpret;
612 if (tmpret != LYX_LAYOUT_DEFAULT)
613 params.orientation = static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
614 } else if (token == "\\paperwidth") {
616 params.paperwidth = lex.GetString();
617 } else if (token == "\\paperheight") {
619 params.paperheight = lex.GetString();
620 } else if (token == "\\leftmargin") {
622 params.leftmargin = lex.GetString();
623 } else if (token == "\\topmargin") {
625 params.topmargin = lex.GetString();
626 } else if (token == "\\rightmargin") {
628 params.rightmargin = lex.GetString();
629 } else if (token == "\\bottommargin") {
631 params.bottommargin = lex.GetString();
632 } else if (token == "\\headheight") {
634 params.headheight = lex.GetString();
635 } else if (token == "\\headsep") {
637 params.headsep = lex.GetString();
638 } else if (token == "\\footskip") {
640 params.footskip = lex.GetString();
641 } else if (token == "\\paperfontsize") {
643 params.fontsize = strip(lex.GetString());
644 } else if (token == "\\papercolumns") {
646 params.columns = lex.GetInteger();
647 } else if (token == "\\papersides") {
649 switch(lex.GetInteger()) {
651 case 1: params.sides = LyXTextClass::OneSide; break;
652 case 2: params.sides = LyXTextClass::TwoSides; break;
654 } else if (token == "\\paperpagestyle") {
656 params.pagestyle = strip(lex.GetString());
657 } else if (token == "\\bullet") {
659 int index = lex.GetInteger();
661 int temp_int = lex.GetInteger();
662 params.user_defined_bullets[index].setFont(temp_int);
663 params.temp_bullets[index].setFont(temp_int);
665 temp_int = lex.GetInteger();
666 params.user_defined_bullets[index].setCharacter(temp_int);
667 params.temp_bullets[index].setCharacter(temp_int);
669 temp_int = lex.GetInteger();
670 params.user_defined_bullets[index].setSize(temp_int);
671 params.temp_bullets[index].setSize(temp_int);
673 string temp_str = lex.GetString();
674 if (temp_str != "\\end_bullet") {
675 // this element isn't really necessary for
676 // parsing but is easier for humans
677 // to understand bullets. Put it back and
678 // set a debug message?
679 lex.printError("\\end_bullet expected, got" + temp_str);
680 //how can I put it back?
682 } else if (token == "\\bulletLaTeX") {
684 int index = lex.GetInteger();
686 string temp_str = lex.GetString(), sum_str;
687 while (temp_str != "\\end_bullet") {
688 // this loop structure is needed when user
689 // enters an empty string since the first
690 // thing returned will be the \\end_bullet
692 // if the LaTeX entry has spaces. Each element
693 // therefore needs to be read in turn
696 temp_str = lex.GetString();
698 params.user_defined_bullets[index].setText(sum_str);
699 params.temp_bullets[index].setText(sum_str);
700 } else if (token == "\\secnumdepth") {
702 params.secnumdepth = lex.GetInteger();
703 } else if (token == "\\tocdepth") {
705 params.tocdepth = lex.GetInteger();
706 } else if (token == "\\spacing") {
708 string tmp = strip(lex.GetString());
709 Spacing::Space tmp_space = Spacing::Default;
711 if (tmp == "single") {
712 tmp_space = Spacing::Single;
713 } else if (tmp == "onehalf") {
714 tmp_space = Spacing::Onehalf;
715 } else if (tmp == "double") {
716 tmp_space = Spacing::Double;
717 } else if (tmp == "other") {
719 tmp_space = Spacing::Other;
720 tmp_val = lex.GetFloat();
722 lex.printError("Unknown spacing token: '$$Token'");
724 // Small hack so that files written with klyx will be
727 par->spacing.set(tmp_space, tmp_val);
729 params.spacing.set(tmp_space, tmp_val);
731 } else if (token == "\\paragraph_spacing") {
733 string tmp = strip(lex.GetString());
734 if (tmp == "single") {
735 par->spacing.set(Spacing::Single);
736 } else if (tmp == "onehalf") {
737 par->spacing.set(Spacing::Onehalf);
738 } else if (tmp == "double") {
739 par->spacing.set(Spacing::Double);
740 } else if (tmp == "other") {
742 par->spacing.set(Spacing::Other,
745 lex.printError("Unknown spacing token: '$$Token'");
747 } else if (token == "\\float_placement") {
749 params.float_placement = lex.GetString();
750 } else if (token == "\\family") {
752 font.setLyXFamily(lex.GetString());
753 } else if (token == "\\series") {
755 font.setLyXSeries(lex.GetString());
756 } else if (token == "\\shape") {
758 font.setLyXShape(lex.GetString());
759 } else if (token == "\\size") {
761 font.setLyXSize(lex.GetString());
762 } else if (token == "\\latex") {
764 string tok = lex.GetString();
765 // This is dirty, but gone with LyX3. (Asger)
766 if (tok == "no_latex")
767 font.setLatex(LyXFont::OFF);
768 else if (tok == "latex")
769 font.setLatex(LyXFont::ON);
770 else if (tok == "default")
771 font.setLatex(LyXFont::INHERIT);
773 lex.printError("Unknown LaTeX font flag "
775 } else if (token == "\\lang") {
777 string tok = lex.GetString();
778 Languages::iterator lit = languages.find(tok);
779 if (lit != languages.end()) {
780 font.setLanguage(&(*lit).second);
782 font.setLanguage(params.language_info);
783 lex.printError("Unknown language `$$Token'");
785 } else if (token == "\\emph") {
787 font.setEmph(font.setLyXMisc(lex.GetString()));
788 } else if (token == "\\bar") {
790 string tok = lex.GetString();
791 // This is dirty, but gone with LyX3. (Asger)
793 font.setUnderbar(LyXFont::ON);
794 else if (tok == "no")
795 font.setUnderbar(LyXFont::OFF);
796 else if (tok == "default")
797 font.setUnderbar(LyXFont::INHERIT);
799 lex.printError("Unknown bar font flag "
801 } else if (token == "\\noun") {
803 font.setNoun(font.setLyXMisc(lex.GetString()));
804 } else if (token == "\\color") {
806 font.setLyXColor(lex.GetString());
807 } else if (token == "\\align") {
808 int tmpret = lex.FindToken(string_align);
809 if (tmpret == -1) ++tmpret;
810 if (tmpret != LYX_LAYOUT_DEFAULT) { // tmpret != 99 ???
812 for (; tmpret > 0; --tmpret)
813 tmpret2 = tmpret2 * 2;
814 par->align = LyXAlignment(tmpret2);
816 } else if (token == "\\added_space_top") {
818 par->added_space_top = VSpace(lex.GetString());
819 } else if (token == "\\added_space_bottom") {
821 par->added_space_bottom = VSpace(lex.GetString());
822 } else if (token == "\\pextra_type") {
824 par->pextra_type = lex.GetInteger();
825 } else if (token == "\\pextra_width") {
827 par->pextra_width = lex.GetString();
828 } else if (token == "\\pextra_widthp") {
830 par->pextra_widthp = lex.GetString();
831 } else if (token == "\\pextra_alignment") {
833 par->pextra_alignment = lex.GetInteger();
834 } else if (token == "\\pextra_hfill") {
836 par->pextra_hfill = lex.GetInteger();
837 } else if (token == "\\pextra_start_minipage") {
839 par->pextra_start_minipage = lex.GetInteger();
840 } else if (token == "\\labelwidthstring") {
842 par->labelwidthstring = lex.GetString();
843 // do not delete this token, it is still needed!
844 } else if (token == "\\end_inset") {
845 lyxerr << "Solitary \\end_inset. Missing \\begin_inset?.\n"
846 << "Last inset read was: " << last_inset_read
848 // Simply ignore this. The insets do not have
850 // But insets should read it, it is a part of
851 // the inset isn't it? Lgb.
852 } else if (token == "\\begin_inset") {
853 // Should be moved out into its own function/method. (Lgb)
855 string tmptok = lex.GetString();
856 last_inset_read = tmptok;
857 // test the different insets
858 if (tmptok == "Quotes") {
859 Inset * inset = new InsetQuotes;
860 inset->Read(this, lex);
861 par->InsertInset(pos, inset, font);
863 } else if (tmptok == "External") {
864 Inset * inset = new InsetExternal;
865 inset->Read(this, lex);
866 par->InsertInset(pos, inset, font);
868 } else if (tmptok == "FormulaMacro") {
869 Inset * inset = new InsetFormulaMacro;
870 inset->Read(this, lex);
871 par->InsertInset(pos, inset, font);
873 } else if (tmptok == "Formula") {
874 Inset * inset = new InsetFormula;
875 inset->Read(this, lex);
876 par->InsertInset(pos, inset, font);
878 } else if (tmptok == "Figure") {
879 Inset * inset = new InsetFig(100, 100, this);
880 inset->Read(this, lex);
881 par->InsertInset(pos, inset, font);
883 } else if (tmptok == "Info") {
884 Inset * inset = new InsetInfo;
885 inset->Read(this, lex);
886 par->InsertInset(pos, inset, font);
888 } else if (tmptok == "Include") {
889 Inset * inset = new InsetInclude(string(), this);
890 inset->Read(this, lex);
891 par->InsertInset(pos, inset, font);
893 } else if (tmptok == "ERT") {
894 Inset * inset = new InsetERT;
895 inset->Read(this, lex);
896 par->InsertInset(pos, inset, font);
898 } else if (tmptok == "Tabular") {
899 Inset * inset = new InsetTabular(this);
900 inset->Read(this, lex);
901 par->InsertInset(pos, inset, font);
903 } else if (tmptok == "Text") {
904 Inset * inset = new InsetText;
905 inset->Read(this, lex);
906 par->InsertInset(pos, inset, font);
908 } else if (tmptok == "Foot") {
909 Inset * inset = new InsetFoot;
910 inset->Read(this, lex);
911 par->InsertInset(pos, inset, font);
913 } else if (tmptok == "Marginal") {
914 Inset * inset = new InsetMarginal;
915 inset->Read(this, lex);
916 par->InsertInset(pos, inset, font);
918 } else if (tmptok == "Minipage") {
919 Inset * inset = new InsetMinipage;
920 inset->Read(this, lex);
921 par->InsertInset(pos, inset, font);
923 } else if (tmptok == "Float") {
925 string tmptok = lex.GetString();
926 Inset * inset = new InsetFloat(tmptok);
927 inset->Read(this, lex);
928 par->InsertInset(pos, inset, font);
930 } else if (tmptok == "List") {
931 Inset * inset = new InsetList;
932 inset->Read(this, lex);
933 par->InsertInset(pos, inset, font);
935 } else if (tmptok == "Theorem") {
936 Inset * inset = new InsetList;
937 inset->Read(this, lex);
938 par->InsertInset(pos, inset, font);
940 } else if (tmptok == "Caption") {
941 Inset * inset = new InsetCaption;
942 inset->Read(this, lex);
943 par->InsertInset(pos, inset, font);
945 } else if (tmptok == "GRAPHICS") {
946 Inset * inset = new InsetGraphics;
947 //inset->Read(this, lex);
948 par->InsertInset(pos, inset, font);
949 } else if (tmptok == "LatexCommand") {
951 inscmd.Read(this, lex);
953 if (inscmd.getCmdName() == "cite") {
954 inset = new InsetCitation(inscmd.getContents(), inscmd.getOptions());
955 } else if (inscmd.getCmdName() == "bibitem") {
956 lex.printError("Wrong place for bibitem");
957 inset = inscmd.Clone();
958 } else if (inscmd.getCmdName() == "BibTeX") {
959 inset = new InsetBibtex(inscmd.getContents(), inscmd.getOptions(), this);
960 } else if (inscmd.getCmdName() == "index") {
961 inset = new InsetIndex(inscmd.getContents());
962 } else if (inscmd.getCmdName() == "include") {
963 inset = new InsetInclude(inscmd.getContents(), this);
964 } else if (inscmd.getCmdName() == "label") {
965 inset = new InsetLabel(inscmd.getCommand());
966 } else if (inscmd.getCmdName() == "url"
967 || inscmd.getCmdName() == "htmlurl") {
968 inset = new InsetUrl(inscmd.getCommand());
969 } else if (inscmd.getCmdName() == "ref"
970 || inscmd.getCmdName() == "pageref"
971 || inscmd.getCmdName() == "vref"
972 || inscmd.getCmdName() == "vpageref"
973 || inscmd.getCmdName() == "prettyref") {
974 if (!inscmd.getOptions().empty() || !inscmd.getContents().empty()) {
975 inset = new InsetRef(inscmd, this);
977 } else if (inscmd.getCmdName() == "tableofcontents") {
978 inset = new InsetTOC(this);
979 } else if (inscmd.getCmdName() == "listoffigures") {
980 inset = new InsetLOF(this);
981 } else if (inscmd.getCmdName() == "listofalgorithms") {
982 inset = new InsetLOA(this);
983 } else if (inscmd.getCmdName() == "listoftables") {
984 inset = new InsetLOT(this);
985 } else if (inscmd.getCmdName() == "printindex") {
986 inset = new InsetPrintIndex(this);
987 } else if (inscmd.getCmdName() == "lyxparent") {
988 inset = new InsetParent(inscmd.getContents(), this);
992 par->InsertInset(pos, inset, font);
996 } else if (token == "\\SpecialChar") {
997 LyXLayout const & layout =
998 textclasslist.Style(params.textclass,
1001 // Insets don't make sense in a free-spacing context! ---Kayvan
1002 if (layout.free_spacing) {
1005 string next_token = lex.GetString();
1006 if (next_token == "\\-") {
1007 par->InsertChar(pos, '-', font);
1008 } else if (next_token == "\\protected_separator"
1009 || next_token == "~") {
1010 par->InsertChar(pos, ' ', font);
1012 lex.printError("Token `$$Token' "
1014 "paragraph layout!");
1019 Inset * inset = new InsetSpecialChar;
1020 inset->Read(this, lex);
1021 par->InsertInset(pos, inset, font);
1024 } else if (token == "\\newline") {
1025 par->InsertChar(pos, LyXParagraph::META_NEWLINE, font);
1027 } else if (token == "\\LyXTable") {
1029 Inset * inset = new InsetTabular(this);
1030 inset->Read(this, lex);
1031 par->InsertInset(pos, inset, font);
1034 par->table = new LyXTable(lex);
1036 } else if (token == "\\hfill") {
1037 par->InsertChar(pos, LyXParagraph::META_HFILL, font);
1039 } else if (token == "\\protected_separator") { // obsolete
1040 // This is a backward compability thingie. (Lgb)
1041 // Remove it later some time...introduced with fileformat
1043 LyXLayout const & layout =
1044 textclasslist.Style(params.textclass,
1047 if (layout.free_spacing) {
1048 par->InsertChar(pos, ' ', font);
1050 Inset * inset = new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
1051 par->InsertInset(pos, inset, font);
1054 } else if (token == "\\bibitem") { // ale970302
1056 par->bibkey = new InsetBibKey;
1057 par->bibkey->Read(this, lex);
1058 }else if (token == "\\backslash") {
1059 par->InsertChar(pos, '\\', font);
1061 }else if (token == "\\the_end") {
1062 the_end_read = true;
1064 // This should be insurance for the future: (Asger)
1065 lex.printError("Unknown token `$$Token'. "
1066 "Inserting as text.");
1067 for(string::const_iterator cit = token.begin();
1068 cit != token.end(); ++cit) {
1069 par->InsertChar(pos, (*cit), font);
1073 return the_end_read;
1076 bool Buffer::readFile(LyXLex & lex, LyXParagraph * par)
1082 token = lex.GetString();
1083 if (token == "\\lyxformat") { // the first token _must_ be...
1085 format = lex.GetFloat();
1087 if (LYX_FORMAT - format > 0.05) {
1088 printf(_("Warning: need lyxformat %.2f but found %.2f\n"),
1089 LYX_FORMAT, format);
1091 if (format - LYX_FORMAT > 0.05) {
1092 printf(_("ERROR: need lyxformat %.2f but found %.2f\n"),
1093 LYX_FORMAT, format);
1095 bool the_end = readLyXformat2(lex, par);
1096 // Formats >= 2.13 support "\the_end" marker
1103 WriteAlert(_("Warning!"),
1104 _("Reading of document is not complete"),
1105 _("Maybe the document is truncated"));
1106 // We simulate a safe reading anyways to allow
1107 // users to take the chance... (Asger)
1111 WriteAlert(_("ERROR!"),
1112 _("Old LyX file format found. "
1113 "Use LyX 0.10.x to read this!"));
1117 } else { // "\\lyxformat" not found
1118 WriteAlert(_("ERROR!"), _("Not a LyX file!"));
1121 WriteAlert(_("ERROR!"), _("Unable to read file!"));
1127 // Should probably be moved to somewhere else: BufferView? LyXView?
1128 bool Buffer::save() const
1130 // We don't need autosaves in the immediate future. (Asger)
1131 resetAutosaveTimers();
1135 if (lyxrc.make_backup) {
1136 s = fileName() + '~';
1137 if (!lyxrc.backupdir_path.empty())
1138 s = AddName(lyxrc.backupdir_path,
1139 subst(CleanupPath(s),'/','!'));
1141 // Rename is the wrong way of making a backup,
1142 // this is the correct way.
1143 /* truss cp fil fil2:
1144 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
1145 stat("LyXVC.lyx", 0xEFFFF688) = 0
1146 open("LyXVC.lyx", O_RDONLY) = 3
1147 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
1148 fstat(4, 0xEFFFF508) = 0
1149 fstat(3, 0xEFFFF508) = 0
1150 read(3, " # T h i s f i l e w".., 8192) = 5579
1151 write(4, " # T h i s f i l e w".., 5579) = 5579
1152 read(3, 0xEFFFD4A0, 8192) = 0
1155 chmod("LyXVC3.lyx", 0100644) = 0
1156 lseek(0, 0, SEEK_CUR) = 46440
1160 // Should proabaly have some more error checking here.
1161 // Should be cleaned up in 0.13, at least a bit.
1162 // Doing it this way, also makes the inodes stay the same.
1163 // This is still not a very good solution, in particular we
1164 // might loose the owner of the backup.
1165 FileInfo finfo(fileName());
1166 if (finfo.exist()) {
1167 mode_t fmode = finfo.getMode();
1168 struct utimbuf times = {
1169 finfo.getAccessTime(),
1170 finfo.getModificationTime() };
1172 ifstream ifs(fileName().c_str());
1173 ofstream ofs(s.c_str(), ios::out|ios::trunc);
1178 ::chmod(s.c_str(), fmode);
1180 if (::utime(s.c_str(), ×)) {
1181 lyxerr << "utime error." << endl;
1184 lyxerr << "LyX was not able to make "
1185 "backupcopy. Beware." << endl;
1190 if (writeFile(fileName(), false)) {
1193 // now delete the autosavefile
1194 string a = OnlyPath(fileName());
1196 a += OnlyFilename(fileName());
1198 FileInfo fileinfo(a);
1199 if (fileinfo.exist()) {
1200 if (::remove(a.c_str()) != 0) {
1201 WriteFSAlert(_("Could not delete "
1202 "auto-save file!"), a);
1206 // Saving failed, so backup is not backup
1207 if (lyxrc.make_backup) {
1208 ::rename(s.c_str(), fileName().c_str());
1216 // Returns false if unsuccesful
1217 bool Buffer::writeFile(string const & fname, bool flag) const
1219 // if flag is false writeFile will not create any GUI
1220 // warnings, only cerr.
1221 // Needed for autosave in background or panic save (Matthias 120496)
1223 if (read_only && (fname == filename)) {
1224 // Here we should come with a question if we should
1225 // perform the write anyway.
1227 lyxerr << _("Error! Document is read-only: ")
1230 WriteAlert(_("Error! Document is read-only: "),
1235 FileInfo finfo(fname);
1236 if (finfo.exist() && !finfo.writable()) {
1237 // Here we should come with a question if we should
1238 // try to do the save anyway. (i.e. do a chmod first)
1240 lyxerr << _("Error! Cannot write file: ")
1243 WriteFSAlert(_("Error! Cannot write file: "),
1248 ofstream ofs(fname.c_str());
1251 lyxerr << _("Error! Cannot open file: ")
1254 WriteFSAlert(_("Error! Cannot open file: "),
1258 // The top of the file should not be written by params.
1260 // write out a comment in the top of the file
1261 ofs << '#' << LYX_DOCVERSION
1262 << " created this file. For more info see http://www.lyx.org/\n";
1263 ofs.setf(ios::showpoint|ios::fixed);
1265 ofs << "\\lyxformat " << setw(4) << LYX_FORMAT << "\n";
1267 // now write out the buffer paramters.
1268 params.writeFile(ofs);
1270 char footnoteflag = 0;
1273 // this will write out all the paragraphs
1274 // using recursive descent.
1275 paragraph->writeFile(this, ofs, params, footnoteflag, depth);
1277 // Write marker that shows file is complete
1278 ofs << "\n\\the_end" << endl;
1280 // how to check if close went ok?
1285 void Buffer::writeFileAscii(string const & fname, int linelen)
1287 LyXFont font1, font2;
1289 char c, footnoteflag = 0, depth = 0;
1291 LyXParagraph::size_type i;
1294 int ltype_depth = 0;
1303 int currlinelen = 0;
1305 bool ref_printed = false;
1307 ofstream ofs(fname.c_str());
1309 WriteFSAlert(_("Error: Cannot write file:"), fname);
1313 string fname1 = TmpFileName();
1314 LyXParagraph * par = paragraph;
1320 par->footnoteflag != LyXParagraph::NO_FOOTNOTE ||
1324 || par->previous->footnoteflag == LyXParagraph::NO_FOOTNOTE
1329 /* begins a footnote environment ? */
1330 if (footnoteflag != par->footnoteflag) {
1331 footnoteflag = par->footnoteflag;
1333 j = strlen(string_footnotekinds[par->footnotekind])+4;
1334 if (currlinelen + j > linelen)
1337 << string_footnotekinds[par->footnotekind] << "] ";
1343 /* begins or ends a deeper area ?*/
1344 if (depth != par->depth) {
1345 if (par->depth > depth) {
1346 while (par->depth > depth) {
1351 while (par->depth < depth) {
1357 /* First write the layout */
1358 tmp = textclasslist.NameOfLayout(params.textclass, par->layout);
1359 if (tmp == "Itemize") {
1361 ltype_depth = depth+1;
1362 } else if (tmp == "Enumerate") {
1364 ltype_depth = depth+1;
1365 } else if (strstr(tmp.c_str(), "ection")) {
1367 ltype_depth = depth+1;
1368 } else if (strstr(tmp.c_str(), "aragraph")) {
1370 ltype_depth = depth+1;
1371 } else if (tmp == "Description") {
1373 ltype_depth = depth+1;
1374 } else if (tmp == "Abstract") {
1377 } else if (tmp == "Bibliography") {
1385 /* maybe some vertical spaces */
1387 /* the labelwidthstring used in lists */
1391 /* some pagebreaks? */
1395 /* what about the alignment */
1398 /* dummy layout, that means a footnote ended */
1399 footnoteflag = LyXParagraph::NO_FOOTNOTE;
1403 lyxerr << "Should this ever happen?" << endl;
1407 //LyXLayout const & layout =
1408 // textclasslist.Style(params.textclass,
1409 // par->GetLayout()); // unused
1410 //bool free_spc = layout.free_spacing; //unused
1413 /* It might be a table */
1417 cells = par->table->columns;
1418 clen = new int [cells];
1419 memset(clen, 0, sizeof(int) * cells);
1421 for (i = 0, j = 0, h = 1; i < par->size(); ++i, ++h) {
1422 c = par->GetChar(i);
1423 if (c == LyXParagraph::META_INSET) {
1424 if ((inset = par->GetInset(i))) {
1426 std::ostringstream ost;
1427 inset->Ascii(this, ost);
1428 h += ost.str().length();
1431 inset->Ascii(this, ost);
1433 char * tmp = ost.str();
1439 } else if (c == LyXParagraph::META_NEWLINE) {
1443 j = (++j) % par->table->NumberOfCellsInRow(actcell);
1451 font1 = LyXFont(LyXFont::ALL_INHERIT, params.language_info);
1453 for (i = 0, actpos = 1; i < par->size(); ++i, ++actpos) {
1454 if (!i && !footnoteflag && !noparbreak){
1456 for(j = 0; j < depth; ++j)
1458 currlinelen = depth * 2;
1460 case 0: /* Standard */
1461 case 4: /* (Sub)Paragraph */
1462 case 5: /* Description */
1464 case 6: /* Abstract */
1465 ofs << "Abstract\n\n";
1467 case 7: /* Bibliography */
1469 ofs << "References\n\n";
1474 ofs << par->labelstring << " ";
1477 if (ltype_depth > depth) {
1478 for(j = ltype_depth - 1; j > depth; --j)
1480 currlinelen += (ltype_depth-depth)*2;
1484 for(j = 0; j < cells; ++j) {
1486 for(h = 0; h < (clen[j] + 1);
1491 for(j = 0; j < depth; ++j)
1493 currlinelen = depth * 2;
1494 if (ltype_depth > depth) {
1495 for(j = ltype_depth;
1498 currlinelen += (ltype_depth-depth)*2;
1504 font2 = par->GetFontSettings(params, i);
1505 if (font1.latex() != font2.latex()) {
1506 if (font2.latex() == LyXFont::OFF)
1513 c = par->GetChar(i);
1517 case LyXParagraph::META_INSET:
1518 if ((inset = par->GetInset(i))) {
1520 inset->Ascii(this, ofs);
1521 currlinelen += (ofs.tellp() - fpos);
1522 actpos += (ofs.tellp() - fpos) - 1;
1525 case LyXParagraph::META_NEWLINE:
1528 if (par->table->NumberOfCellsInRow(actcell) <= cell) {
1529 for(j = actpos; j < clen[cell - 1]; ++j)
1532 for(j = 0; j < depth; ++j)
1534 currlinelen = depth*2;
1535 if (ltype_depth > depth) {
1536 for(j = ltype_depth; j > depth; --j)
1538 currlinelen += (ltype_depth-depth) * 2;
1540 for(j = 0; j < cells; ++j) {
1542 for(h = 0; h < (clen[j] + 1); ++h)
1546 for(j = 0; j < depth; ++j)
1548 currlinelen = depth * 2;
1549 if (ltype_depth > depth) {
1550 for(j = ltype_depth;
1553 currlinelen += (ltype_depth-depth)*2;
1559 j < clen[cell - 1]; ++j)
1565 currlinelen = actpos = 0;
1569 for(j = 0; j < depth; ++j)
1571 currlinelen = depth * 2;
1572 if (ltype_depth > depth) {
1573 for(j = ltype_depth;
1576 currlinelen += (ltype_depth - depth) * 2;
1582 case LyXParagraph::META_HFILL:
1589 if (currlinelen > linelen - 10
1590 && c == ' ' && i + 2 < par->size()) {
1592 for(j = 0; j < depth; ++j)
1594 currlinelen = depth * 2;
1595 if (ltype_depth > depth) {
1596 for(j = ltype_depth;
1599 currlinelen += (ltype_depth-depth)*2;
1601 } else if (c != '\0')
1604 lyxerr.debug() << "writeAsciiFile: NULL char in structure." << endl;
1611 for(j = actpos; j < clen[cell - 1]; ++j)
1614 for(j = 0; j < depth; ++j)
1616 currlinelen = depth * 2;
1617 if (ltype_depth > depth) {
1618 for(j = ltype_depth; j > depth; --j)
1620 currlinelen += (ltype_depth - depth) * 2;
1622 for(j = 0; j < cells; ++j) {
1624 for(h = 0; h < (clen[j] + 1); ++h)
1638 void Buffer::makeLaTeXFile(string const & fname,
1639 string const & original_path,
1640 bool nice, bool only_body)
1642 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
1644 niceFile = nice; // this will be used by Insetincludes.
1646 tex_code_break_column = lyxrc.ascii_linelen;
1648 LyXTextClass const & tclass =
1649 textclasslist.TextClass(params.textclass);
1651 ofstream ofs(fname.c_str());
1653 WriteFSAlert(_("Error: Cannot open file: "), fname);
1657 // validate the buffer.
1658 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
1659 LaTeXFeatures features(params, tclass.numLayouts());
1661 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
1664 // The starting paragraph of the coming rows is the
1665 // first paragraph of the document. (Asger)
1666 texrow.start(paragraph, 0);
1668 if (!only_body && nice) {
1669 ofs << "%% " LYX_DOCVERSION " created this file. "
1670 "For more info, see http://www.lyx.org/.\n"
1671 "%% Do not edit unless you really know what "
1676 lyxerr.debug() << "lyx header finished" << endl;
1677 // There are a few differences between nice LaTeX and usual files:
1678 // usual is \batchmode and has a
1679 // special input@path to allow the including of figures
1680 // with either \input or \includegraphics (what figinsets do).
1681 // batchmode is not set if there is a tex_code_break_column.
1682 // In this case somebody is interested in the generated LaTeX,
1683 // so this is OK. input@path is set when the actual parameter
1684 // original_path is set. This is done for usual tex-file, but not
1685 // for nice-latex-file. (Matthias 250696)
1688 // code for usual, NOT nice-latex-file
1689 ofs << "\\batchmode\n"; // changed
1690 // from \nonstopmode
1693 if (!original_path.empty()) {
1694 ofs << "\\makeatletter\n"
1695 << "\\def\\input@path{{"
1696 << original_path << "/}}\n"
1697 << "\\makeatother\n";
1703 ofs << "\\documentclass";
1705 string options; // the document class options.
1707 if (tokenPos(tclass.opt_fontsize(),
1708 '|', params.fontsize) >= 0) {
1709 // only write if existing in list (and not default)
1710 options += params.fontsize;
1715 if (!params.use_geometry &&
1716 (params.paperpackage == BufferParams::PACKAGE_NONE)) {
1717 switch (params.papersize) {
1718 case BufferParams::PAPER_A4PAPER:
1719 options += "a4paper,";
1721 case BufferParams::PAPER_USLETTER:
1722 options += "letterpaper,";
1724 case BufferParams::PAPER_A5PAPER:
1725 options += "a5paper,";
1727 case BufferParams::PAPER_B5PAPER:
1728 options += "b5paper,";
1730 case BufferParams::PAPER_EXECUTIVEPAPER:
1731 options += "executivepaper,";
1733 case BufferParams::PAPER_LEGALPAPER:
1734 options += "legalpaper,";
1740 if (params.sides != tclass.sides()) {
1741 switch (params.sides) {
1742 case LyXTextClass::OneSide:
1743 options += "oneside,";
1745 case LyXTextClass::TwoSides:
1746 options += "twoside,";
1753 if (params.columns != tclass.columns()) {
1754 if (params.columns == 2)
1755 options += "twocolumn,";
1757 options += "onecolumn,";
1760 if (!params.use_geometry
1761 && params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1762 options += "landscape,";
1764 // language should be a parameter to \documentclass
1765 bool use_babel = false;
1766 if (params.language_info->lang() == "hebrew") // This seems necessary
1767 features.UsedLanguages.insert(default_language);
1768 if (params.language != "default" ||
1769 !features.UsedLanguages.empty() ) {
1771 for (LaTeXFeatures::LanguageList::const_iterator cit =
1772 features.UsedLanguages.begin();
1773 cit != features.UsedLanguages.end(); ++cit)
1774 options += (*cit)->lang() + ",";
1775 options += params.language_info->lang() + ',';
1778 // the user-defined options
1779 if (!params.options.empty()) {
1780 options += params.options + ',';
1783 if (!options.empty()){
1784 options = strip(options, ',');
1785 ofs << '[' << options << ']';
1789 << textclasslist.LatexnameOfClass(params.textclass)
1792 // end of \documentclass defs
1794 // font selection must be done before loading fontenc.sty
1795 if (params.fonts != "default") {
1796 ofs << "\\usepackage{" << params.fonts << "}\n";
1799 // this one is not per buffer
1800 if (lyxrc.fontenc != "default") {
1801 ofs << "\\usepackage[" << lyxrc.fontenc
1806 if (params.inputenc == "auto") {
1807 string doc_encoding =
1808 params.language_info->encoding()->LatexName();
1810 // Create a list with all the input encodings used
1812 set<string> encodings;
1813 for (LaTeXFeatures::LanguageList::const_iterator it =
1814 features.UsedLanguages.begin();
1815 it != features.UsedLanguages.end(); ++it)
1816 if ((*it)->encoding()->LatexName() != doc_encoding)
1817 encodings.insert((*it)->encoding()->LatexName());
1819 ofs << "\\usepackage[";
1820 for (set<string>::const_iterator it = encodings.begin();
1821 it != encodings.end(); ++it)
1823 ofs << doc_encoding << "]{inputenc}\n";
1825 } else if (params.inputenc != "default") {
1826 ofs << "\\usepackage[" << params.inputenc
1831 // At the very beginning the text parameters.
1832 if (params.paperpackage != BufferParams::PACKAGE_NONE) {
1833 switch (params.paperpackage) {
1834 case BufferParams::PACKAGE_A4:
1835 ofs << "\\usepackage{a4}\n";
1838 case BufferParams::PACKAGE_A4WIDE:
1839 ofs << "\\usepackage{a4wide}\n";
1842 case BufferParams::PACKAGE_WIDEMARGINSA4:
1843 ofs << "\\usepackage[widemargins]{a4}\n";
1848 if (params.use_geometry) {
1849 ofs << "\\usepackage{geometry}\n";
1851 ofs << "\\geometry{verbose";
1852 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1853 ofs << ",landscape";
1854 switch (params.papersize2) {
1855 case BufferParams::VM_PAPER_CUSTOM:
1856 if (!params.paperwidth.empty())
1857 ofs << ",paperwidth="
1858 << params.paperwidth;
1859 if (!params.paperheight.empty())
1860 ofs << ",paperheight="
1861 << params.paperheight;
1863 case BufferParams::VM_PAPER_USLETTER:
1864 ofs << ",letterpaper";
1866 case BufferParams::VM_PAPER_USLEGAL:
1867 ofs << ",legalpaper";
1869 case BufferParams::VM_PAPER_USEXECUTIVE:
1870 ofs << ",executivepaper";
1872 case BufferParams::VM_PAPER_A3:
1875 case BufferParams::VM_PAPER_A4:
1878 case BufferParams::VM_PAPER_A5:
1881 case BufferParams::VM_PAPER_B3:
1884 case BufferParams::VM_PAPER_B4:
1887 case BufferParams::VM_PAPER_B5:
1891 // default papersize ie BufferParams::VM_PAPER_DEFAULT
1892 switch (lyxrc.default_papersize) {
1893 case BufferParams::PAPER_DEFAULT: // keep compiler happy
1894 case BufferParams::PAPER_USLETTER:
1895 ofs << ",letterpaper";
1897 case BufferParams::PAPER_LEGALPAPER:
1898 ofs << ",legalpaper";
1900 case BufferParams::PAPER_EXECUTIVEPAPER:
1901 ofs << ",executivepaper";
1903 case BufferParams::PAPER_A3PAPER:
1906 case BufferParams::PAPER_A4PAPER:
1909 case BufferParams::PAPER_A5PAPER:
1912 case BufferParams::PAPER_B5PAPER:
1917 if (!params.topmargin.empty())
1918 ofs << ",tmargin=" << params.topmargin;
1919 if (!params.bottommargin.empty())
1920 ofs << ",bmargin=" << params.bottommargin;
1921 if (!params.leftmargin.empty())
1922 ofs << ",lmargin=" << params.leftmargin;
1923 if (!params.rightmargin.empty())
1924 ofs << ",rmargin=" << params.rightmargin;
1925 if (!params.headheight.empty())
1926 ofs << ",headheight=" << params.headheight;
1927 if (!params.headsep.empty())
1928 ofs << ",headsep=" << params.headsep;
1929 if (!params.footskip.empty())
1930 ofs << ",footskip=" << params.footskip;
1934 if (params.use_amsmath
1935 && !tclass.provides(LyXTextClass::amsmath)) {
1936 ofs << "\\usepackage{amsmath}\n";
1940 if (tokenPos(tclass.opt_pagestyle(),
1941 '|', params.pagestyle) >= 0) {
1942 if (params.pagestyle == "fancy") {
1943 ofs << "\\usepackage{fancyhdr}\n";
1946 ofs << "\\pagestyle{" << params.pagestyle << "}\n";
1950 // We try to load babel late, in case it interferes
1951 // with other packages.
1953 ofs << lyxrc.language_package << endl;
1957 if (params.secnumdepth != tclass.secnumdepth()) {
1958 ofs << "\\setcounter{secnumdepth}{"
1959 << params.secnumdepth
1963 if (params.tocdepth != tclass.tocdepth()) {
1964 ofs << "\\setcounter{tocdepth}{"
1970 if (params.paragraph_separation) {
1971 switch (params.defskip.kind()) {
1972 case VSpace::SMALLSKIP:
1973 ofs << "\\setlength\\parskip{\\smallskipamount}\n";
1975 case VSpace::MEDSKIP:
1976 ofs << "\\setlength\\parskip{\\medskipamount}\n";
1978 case VSpace::BIGSKIP:
1979 ofs << "\\setlength\\parskip{\\bigskipamount}\n";
1981 case VSpace::LENGTH:
1982 ofs << "\\setlength\\parskip{"
1983 << params.defskip.length().asLatexString()
1986 default: // should never happen // Then delete it.
1987 ofs << "\\setlength\\parskip{\\medskipamount}\n";
1992 ofs << "\\setlength\\parindent{0pt}\n";
1996 // Now insert the LyX specific LaTeX commands...
1998 // The optional packages;
1999 string preamble(features.getPackages());
2001 // this might be useful...
2002 preamble += "\n\\makeatletter\n";
2004 // Some macros LyX will need
2005 string tmppreamble(features.getMacros());
2007 if (!tmppreamble.empty()) {
2008 preamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2009 "LyX specific LaTeX commands.\n"
2010 + tmppreamble + '\n';
2013 // the text class specific preamble
2014 tmppreamble = features.getTClassPreamble();
2015 if (!tmppreamble.empty()) {
2016 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2017 "Textclass specific LaTeX commands.\n"
2018 + tmppreamble + '\n';
2021 /* the user-defined preamble */
2022 if (!params.preamble.empty()) {
2023 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2024 "User specified LaTeX commands.\n"
2025 + params.preamble + '\n';
2028 preamble += "\\makeatother\n";
2030 // Itemize bullet settings need to be last in case the user
2031 // defines their own bullets that use a package included
2032 // in the user-defined preamble -- ARRae
2033 // Actually it has to be done much later than that
2034 // since some packages like frenchb make modifications
2035 // at \begin{document} time -- JMarc
2037 for (int i = 0; i < 4; ++i) {
2038 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
2039 if (bullets_def.empty())
2040 bullets_def="\\AtBeginDocument{\n";
2041 bullets_def += " \\renewcommand{\\labelitemi";
2043 // `i' is one less than the item to modify
2050 bullets_def += "ii";
2056 bullets_def += "}{" +
2057 params.user_defined_bullets[i].getText()
2062 if (!bullets_def.empty())
2063 preamble += bullets_def + "}\n\n";
2065 for (int j = countChar(preamble, '\n'); j-- ;) {
2072 ofs << "\\begin{document}\n";
2075 lyxerr.debug() << "preamble finished, now the body." << endl;
2076 if (!lyxrc.language_auto_begin && params.language != "default") {
2077 ofs << subst(lyxrc.language_command_begin, "$$lang",
2083 latexParagraphs(ofs, paragraph, 0, texrow);
2085 // add this just in case after all the paragraphs
2089 if (!lyxrc.language_auto_end && params.language != "default") {
2090 ofs << subst(lyxrc.language_command_end, "$$lang",
2097 ofs << "\\end{document}\n";
2100 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
2102 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
2106 // Just to be sure. (Asger)
2109 // tex_code_break_column's value is used to decide
2110 // if we are in batchmode or not (within mathed_write()
2111 // in math_write.C) so we must set it to a non-zero
2112 // value when we leave otherwise we save incorrect .lyx files.
2113 tex_code_break_column = lyxrc.ascii_linelen;
2117 lyxerr << "File was not closed properly." << endl;
2120 lyxerr.debug() << "Finished making latex file." << endl;
2125 // LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
2127 void Buffer::latexParagraphs(ostream & ofs, LyXParagraph * par,
2128 LyXParagraph * endpar, TexRow & texrow) const
2130 bool was_title = false;
2131 bool already_title = false;
2133 std::ostringstream ftnote;
2135 char * tmpholder = 0;
2141 while (par != endpar) {
2142 #ifndef HAVE_SSTREAM
2145 ftnote << tmpholder;
2146 delete [] tmpholder;
2152 lyxerr[Debug::LATEX] << "Error in latexParagraphs."
2155 LyXLayout const & layout =
2156 textclasslist.Style(params.textclass,
2159 if (layout.intitle) {
2160 if (already_title) {
2161 lyxerr <<"Error in latexParagraphs: You"
2162 " should not mix title layouts"
2163 " with normal ones." << endl;
2166 } else if (was_title && !already_title) {
2167 ofs << "\\maketitle\n";
2169 already_title = true;
2172 // We are at depth 0 so we can just use
2173 // ordinary \footnote{} generation
2174 // flag this with ftcount
2176 if (layout.isEnvironment()
2177 || par->pextra_type != LyXParagraph::PEXTRA_NONE) {
2178 par = par->TeXEnvironment(this, params, ofs, texrow,
2179 ftnote, ft_texrow, ftcount);
2181 par = par->TeXOnePar(this, params, ofs, texrow, false
2184 ftnote, ft_texrow, ftcount
2189 // Write out what we've generated...
2192 ofs << "\\addtocounter{footnote}{-"
2196 ofs << ftnote.str();
2197 texrow += ft_texrow;
2199 // The extra .c_str() is needed when we use
2200 // lyxstring instead of the STL string class.
2201 ftnote.str(string().c_str());
2203 delete [] ftnote.str();
2208 #ifndef HAVE_SSTREAM
2210 // I hate strstreams
2211 tmpholder = ftnote.str();
2215 #ifndef HAVE_SSTREAM
2216 delete [] tmpholder;
2218 // It might be that we only have a title in this document
2219 if (was_title && !already_title) {
2220 ofs << "\\maketitle\n";
2226 bool Buffer::isLatex() const
2228 return textclasslist.TextClass(params.textclass).outputType() == LATEX;
2232 bool Buffer::isLinuxDoc() const
2234 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC;
2238 bool Buffer::isLiterate() const
2240 return textclasslist.TextClass(params.textclass).outputType() == LITERATE;
2244 bool Buffer::isDocBook() const
2246 return textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2250 bool Buffer::isSGML() const
2252 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC ||
2253 textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2257 void Buffer::sgmlOpenTag(ostream & os, int depth,
2258 string const & latexname) const
2260 os << string(depth, ' ') << "<" << latexname << ">\n";
2264 void Buffer::sgmlCloseTag(ostream & os, int depth,
2265 string const & latexname) const
2267 os << string(depth, ' ') << "</" << latexname << ">\n";
2271 void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
2273 LyXParagraph * par = paragraph;
2275 niceFile = nice; // this will be used by Insetincludes.
2277 string top_element = textclasslist.LatexnameOfClass(params.textclass);
2278 string environment_stack[10];
2281 int depth = 0; // paragraph depth
2283 ofstream ofs(fname.c_str());
2286 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2290 LyXTextClass const & tclass =
2291 textclasslist.TextClass(params.textclass);
2293 LaTeXFeatures features(params, tclass.numLayouts());
2297 tex_code_break_column = lyxrc.ascii_linelen;
2299 //tex_code_break_column = 0;
2304 string sgml_includedfiles=features.getIncludedFiles();
2306 if (params.preamble.empty() && sgml_includedfiles.empty()) {
2307 ofs << "<!doctype linuxdoc system>\n\n";
2309 ofs << "<!doctype linuxdoc system [ "
2310 << params.preamble << sgml_includedfiles << " \n]>\n\n";
2313 if(params.options.empty())
2314 sgmlOpenTag(ofs, 0, top_element);
2316 string top = top_element;
2318 top += params.options;
2319 sgmlOpenTag(ofs, 0, top);
2323 ofs << "<!-- " << LYX_DOCVERSION
2324 << " created this file. For more info see http://www.lyx.org/"
2328 int desc_on = 0; // description mode
2329 LyXLayout const & style =
2330 textclasslist.Style(params.textclass,
2333 // treat <toc> as a special case for compatibility with old code
2334 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2335 Inset * inset = par->GetInset(0);
2336 Inset::Code lyx_code = inset->LyxCode();
2337 if (lyx_code == Inset::TOC_CODE){
2338 string temp = "toc";
2339 sgmlOpenTag(ofs, depth, temp);
2343 linuxDocHandleFootnote(ofs, par, depth);
2349 // environment tag closing
2350 for( ; depth > par->depth; --depth) {
2351 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2352 environment_stack[depth].erase();
2355 // write opening SGML tags
2356 switch(style.latextype) {
2357 case LATEX_PARAGRAPH:
2358 if(depth == par->depth
2359 && !environment_stack[depth].empty()) {
2360 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2361 environment_stack[depth].erase();
2367 sgmlOpenTag(ofs, depth, style.latexname());
2372 LinuxDocError(par, 0,
2373 _("Error : Wrong depth for"
2374 " LatexType Command.\n"));
2376 if (!environment_stack[depth].empty()){
2377 sgmlCloseTag(ofs, depth,
2378 environment_stack[depth]);
2382 environment_stack[depth].erase();
2383 sgmlOpenTag(ofs, depth, style.latexname());
2386 case LATEX_ENVIRONMENT:
2387 case LATEX_ITEM_ENVIRONMENT:
2388 if(depth == par->depth
2389 && environment_stack[depth] != style.latexname()
2390 && !environment_stack[depth].empty()) {
2392 sgmlCloseTag(ofs, depth,
2393 environment_stack[depth]);
2394 environment_stack[depth].erase();
2396 if (depth < par->depth) {
2398 environment_stack[depth].erase();
2400 if (environment_stack[depth] != style.latexname()) {
2403 sgmlOpenTag(ofs, depth, temp);
2405 environment_stack[depth] = style.latexname();
2406 sgmlOpenTag(ofs, depth,
2407 environment_stack[depth]);
2409 if(style.latextype == LATEX_ENVIRONMENT) break;
2411 desc_on = (style.labeltype == LABEL_MANUAL);
2418 sgmlOpenTag(ofs, depth + 1, item_name);
2421 sgmlOpenTag(ofs, depth, style.latexname());
2428 SimpleLinuxDocOnePar(ofs, par, desc_on, depth);
2432 linuxDocHandleFootnote(ofs, par, depth);
2434 while(par && par->IsDummy());
2438 // write closing SGML tags
2439 switch(style.latextype) {
2441 case LATEX_ENVIRONMENT:
2442 case LATEX_ITEM_ENVIRONMENT:
2445 sgmlCloseTag(ofs, depth, style.latexname());
2451 for(; depth > 0; --depth)
2452 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2454 if(!environment_stack[depth].empty())
2455 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2459 sgmlCloseTag(ofs, 0, top_element);
2463 // How to check for successful close
2468 void Buffer::linuxDocHandleFootnote(ostream & os, LyXParagraph * & par,
2471 string tag = "footnote";
2473 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2474 sgmlOpenTag(os, depth + 1, tag);
2475 SimpleLinuxDocOnePar(os, par, 0, depth + 1);
2476 sgmlCloseTag(os, depth + 1, tag);
2483 void Buffer::DocBookHandleCaption(ostream & os, string & inner_tag,
2484 int const depth, int desc_on,
2485 LyXParagraph * & par)
2487 LyXParagraph * tpar = par;
2490 && (tpar->footnoteflag != LyXParagraph::NO_FOOTNOTE)
2492 && (tpar->layout != textclasslist.NumberOfLayout(params.textclass,
2496 tpar->layout == textclasslist.NumberOfLayout(params.textclass,
2497 "Caption").second) {
2498 sgmlOpenTag(os, depth + 1, inner_tag);
2500 SimpleDocBookOnePar(os, extra_par, tpar,
2501 desc_on, depth + 2);
2502 sgmlCloseTag(os, depth+1, inner_tag);
2503 if(!extra_par.empty())
2510 void Buffer::DocBookHandleFootnote(ostream & os, LyXParagraph * & par,
2513 string tag, inner_tag;
2514 string tmp_par, extra_par;
2515 bool inner_span = false;
2518 // Someone should give this enum a proper name (Lgb)
2526 SOME_ENUM last = NO_ONE;
2527 SOME_ENUM present = FOOTNOTE_LIKE;
2529 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2530 if(last == present) {
2532 if(!tmp_par.empty()) {
2535 sgmlCloseTag(os, depth + 1, inner_tag);
2536 sgmlOpenTag(os, depth + 1, inner_tag);
2543 if(!inner_tag.empty()) sgmlCloseTag(os, depth + 1,
2545 if(!extra_par.empty()) os << extra_par;
2546 if(!tag.empty()) sgmlCloseTag(os, depth, tag);
2549 switch (par->footnotekind) {
2550 case LyXParagraph::FOOTNOTE:
2551 case LyXParagraph::ALGORITHM:
2554 present = FOOTNOTE_LIKE;
2557 case LyXParagraph::MARGIN:
2560 present = MARGIN_LIKE;
2563 case LyXParagraph::FIG:
2564 case LyXParagraph::WIDE_FIG:
2566 inner_tag = "title";
2570 case LyXParagraph::TAB:
2571 case LyXParagraph::WIDE_TAB:
2573 inner_tag = "title";
2578 sgmlOpenTag(os, depth, tag);
2579 if ((present == TAB_LIKE) || (present == FIG_LIKE)) {
2580 DocBookHandleCaption(os, inner_tag, depth,
2584 sgmlOpenTag(os, depth + 1, inner_tag);
2587 // ignore all caption here, we processed them above!!!
2588 if (par->layout != textclasslist
2589 .NumberOfLayout(params.textclass,
2590 "Caption").second) {
2592 std::ostringstream ost;
2596 SimpleDocBookOnePar(ost, extra_par, par,
2597 desc_on, depth + 2);
2599 tmp_par += ost.str().c_str();
2602 char * ctmp = ost.str();
2607 tmp_par = frontStrip(strip(tmp_par));
2613 if(!inner_tag.empty()) sgmlCloseTag(os, depth + 1, inner_tag);
2614 if(!extra_par.empty()) os << extra_par;
2615 if(!tag.empty()) sgmlCloseTag(os, depth, tag);
2620 // push a tag in a style stack
2621 void Buffer::push_tag(ostream & os, char const * tag,
2622 int & pos, char stack[5][3])
2624 // pop all previous tags
2625 for (int j = pos; j >= 0; --j)
2626 os << "</" << stack[j] << ">";
2629 sprintf(stack[++pos], "%s", tag);
2632 for (int i = 0; i <= pos; ++i)
2633 os << "<" << stack[i] << ">";
2637 void Buffer::pop_tag(ostream & os, char const * tag,
2638 int & pos, char stack[5][3])
2642 // pop all tags till specified one
2643 for (j = pos; (j >= 0) && (strcmp(stack[j], tag)); --j)
2644 os << "</" << stack[j] << ">";
2647 os << "</" << tag << ">";
2649 // push all tags, but the specified one
2650 for (j = j + 1; j <= pos; ++j) {
2651 os << "<" << stack[j] << ">";
2652 strcpy(stack[j-1], stack[j]);
2658 // Handle internal paragraph parsing -- layout already processed.
2660 // checks, if newcol chars should be put into this line
2661 // writes newline, if necessary.
2663 void linux_doc_line_break(ostream & os, unsigned int & colcount,
2664 const unsigned int newcol)
2667 if (colcount > lyxrc.ascii_linelen) {
2669 colcount = newcol; // assume write after this call
2674 void Buffer::SimpleLinuxDocOnePar(ostream & os, LyXParagraph * par,
2675 int desc_on, int const /*depth*/)
2677 LyXFont font1, font2;
2680 LyXParagraph::size_type main_body;
2682 LyXLayout const & style = textclasslist.Style(params.textclass,
2685 char family_type = 0; // family font flag
2686 bool is_bold = false; // series font flag
2687 char shape_type = 0; // shape font flag
2688 bool is_em = false; // emphasis (italic) font flag
2690 int stack_num = -1; // style stack position
2691 // Can this be rewritten to use a std::stack, please. (Lgb)
2692 char stack[5][3]; // style stack
2693 unsigned int char_line_count = 5; // Heuristic choice ;-)
2695 if (style.labeltype != LABEL_MANUAL)
2698 main_body = par->BeginningOfMainBody();
2700 // gets paragraph main font
2702 font1 = style.labelfont;
2707 // parsing main loop
2708 for (LyXParagraph::size_type i = 0;
2709 i < par->size(); ++i) {
2721 font2 = par->getFont(params, i);
2723 if (font1.family() != font2.family()) {
2724 switch(family_type) {
2726 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2727 push_tag(os, "tt", stack_num, stack);
2730 else if (font2.family() == LyXFont::SANS_FAMILY) {
2731 push_tag(os, "sf", stack_num, stack);
2736 pop_tag(os, "tt", stack_num, stack);
2737 if (font2.family() == LyXFont::SANS_FAMILY) {
2738 push_tag(os, "sf", stack_num, stack);
2745 pop_tag(os, "sf", stack_num, stack);
2746 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2747 push_tag(os, "tt", stack_num, stack);
2756 if (font1.series() != font2.series()) {
2757 if (font2.series() == LyXFont::BOLD_SERIES) {
2758 push_tag(os, "bf", stack_num, stack);
2760 } else if (is_bold) {
2761 pop_tag(os, "bf", stack_num, stack);
2766 // handle italic and slanted fonts
2767 if (font1.shape() != font2.shape()) {
2768 switch(shape_type) {
2770 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2771 push_tag(os, "it", stack_num, stack);
2773 } else if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2774 push_tag(os, "sl", stack_num, stack);
2779 pop_tag(os, "it", stack_num, stack);
2780 if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2781 push_tag(os, "sl", stack_num, stack);
2788 pop_tag(os, "sl", stack_num, stack);
2789 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2790 push_tag(os, "it", stack_num, stack);
2798 if (font1.emph() != font2.emph()) {
2799 if (font2.emph() == LyXFont::ON) {
2800 push_tag(os, "em", stack_num, stack);
2803 pop_tag(os, "em", stack_num, stack);
2808 c = par->GetChar(i);
2810 if (c == LyXParagraph::META_INSET) {
2811 inset = par->GetInset(i);
2812 inset->Linuxdoc(this, os);
2815 if (font2.latex() == LyXFont::ON) {
2816 // "TeX"-Mode on == > SGML-Mode on.
2818 os << c; // see LaTeX-Generation...
2822 if (par->linuxDocConvertChar(c, sgml_string)
2823 && !style.free_spacing) { // in freespacing
2825 // non-breaking characters
2829 linux_doc_line_break(os, char_line_count, 6);
2833 linux_doc_line_break(os, char_line_count, 1);
2838 char_line_count += sgml_string.length();
2844 // needed if there is an optional argument but no contents
2845 if (main_body > 0 && main_body == par->size()) {
2849 // pop all defined Styles
2850 for (j = stack_num; j >= 0; --j) {
2851 linux_doc_line_break(os,
2853 3 + strlen(stack[j]));
2854 os << "</" << stack[j] << ">";
2857 // resets description flag correctly
2860 // <tag> not closed...
2861 linux_doc_line_break(os, char_line_count, 6);
2865 // fprintf(file, "</p>");
2871 // Print an error message.
2872 void Buffer::LinuxDocError(LyXParagraph * par, int pos,
2873 char const * message)
2875 // insert an error marker in text
2876 InsetError * new_inset = new InsetError(message);
2877 par->InsertInset(pos, new_inset);
2880 // This constant defines the maximum number of
2881 // environment layouts that can be nesteded.
2882 // The same applies for command layouts.
2883 // These values should be more than enough.
2884 // José Matos (1999/07/22)
2886 enum { MAX_NEST_LEVEL = 25};
2888 void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
2890 LyXParagraph * par = paragraph;
2892 niceFile = nice; // this will be used by Insetincludes.
2894 string top_element= textclasslist.LatexnameOfClass(params.textclass);
2895 // Please use a real stack.
2896 string environment_stack[MAX_NEST_LEVEL];
2897 string environment_inner[MAX_NEST_LEVEL];
2898 // Please use a real stack.
2899 string command_stack[MAX_NEST_LEVEL];
2900 bool command_flag= false;
2901 int command_depth= 0, command_base= 0, cmd_depth= 0;
2903 string item_name, command_name;
2904 string c_depth, c_params, tmps;
2906 int depth = 0; // paragraph depth
2907 LyXTextClass const & tclass =
2908 textclasslist.TextClass(params.textclass);
2910 LaTeXFeatures features(params, tclass.numLayouts());
2914 tex_code_break_column = lyxrc.ascii_linelen;
2916 //tex_code_break_column = 0;
2918 ofstream ofs(fname.c_str());
2920 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2927 string sgml_includedfiles=features.getIncludedFiles();
2929 ofs << "<!doctype " << top_element
2930 << " public \"-//OASIS//DTD DocBook V3.1//EN\"";
2932 if (params.preamble.empty() && sgml_includedfiles.empty())
2935 ofs << "\n [ " << params.preamble
2936 << sgml_includedfiles << " \n]>\n\n";
2938 if(params.options.empty())
2939 sgmlOpenTag(ofs, 0, top_element);
2941 string top = top_element;
2943 top += params.options;
2944 sgmlOpenTag(ofs, 0, top);
2948 ofs << "<!-- DocBook file was created by " << LYX_DOCVERSION
2949 << "\n See http://www.lyx.org/ for more information -->\n";
2952 int desc_on = 0; // description mode
2953 LyXLayout const & style =
2954 textclasslist.Style(params.textclass,
2957 // environment tag closing
2958 for( ; depth > par->depth; --depth) {
2959 if(environment_inner[depth] != "!-- --") {
2960 item_name= "listitem";
2961 sgmlCloseTag(ofs, command_depth + depth,
2963 if( environment_inner[depth] == "varlistentry")
2964 sgmlCloseTag(ofs, depth+command_depth,
2965 environment_inner[depth]);
2967 sgmlCloseTag(ofs, depth + command_depth,
2968 environment_stack[depth]);
2969 environment_stack[depth].erase();
2970 environment_inner[depth].erase();
2973 if(depth == par->depth
2974 && environment_stack[depth] != style.latexname()
2975 && !environment_stack[depth].empty()) {
2976 if(environment_inner[depth] != "!-- --") {
2977 item_name= "listitem";
2978 sgmlCloseTag(ofs, command_depth+depth,
2980 if( environment_inner[depth] == "varlistentry")
2982 depth + command_depth,
2983 environment_inner[depth]);
2986 sgmlCloseTag(ofs, depth + command_depth,
2987 environment_stack[depth]);
2989 environment_stack[depth].erase();
2990 environment_inner[depth].erase();
2993 // Write opening SGML tags.
2994 switch(style.latextype) {
2995 case LATEX_PARAGRAPH:
2996 if(style.latexname() != "dummy")
2997 sgmlOpenTag(ofs, depth+command_depth,
3003 LinuxDocError(par, 0,
3004 _("Error : Wrong depth for "
3005 "LatexType Command.\n"));
3007 command_name = style.latexname();
3009 tmps = style.latexparam();
3010 c_params = split(tmps, c_depth,'|');
3012 cmd_depth= atoi(c_depth.c_str());
3015 if(cmd_depth<command_base) {
3016 for(int j = command_depth;
3017 j >= command_base; --j)
3018 if(!command_stack[j].empty())
3019 sgmlCloseTag(ofs, j, command_stack[j]);
3020 command_depth= command_base= cmd_depth;
3021 } else if(cmd_depth <= command_depth) {
3022 for(int j = command_depth;
3023 j >= cmd_depth; --j)
3025 if(!command_stack[j].empty())
3026 sgmlCloseTag(ofs, j, command_stack[j]);
3027 command_depth= cmd_depth;
3029 command_depth= cmd_depth;
3031 command_depth = command_base = cmd_depth;
3032 command_flag = true;
3034 command_stack[command_depth]= command_name;
3036 // treat label as a special case for
3037 // more WYSIWYM handling.
3038 if (par->GetChar(0) == LyXParagraph::META_INSET) {
3039 Inset * inset = par->GetInset(0);
3040 Inset::Code lyx_code = inset->LyxCode();
3041 if (lyx_code == Inset::LABEL_CODE){
3042 command_name += " id=\"";
3043 command_name += (static_cast<InsetCommand *>(inset))->getContents();
3044 command_name += "\"";
3049 sgmlOpenTag(ofs, depth + command_depth, command_name);
3050 item_name = "title";
3051 sgmlOpenTag(ofs, depth + 1 + command_depth, item_name);
3054 case LATEX_ENVIRONMENT:
3055 case LATEX_ITEM_ENVIRONMENT:
3056 if (depth < par->depth) {
3058 environment_stack[depth].erase();
3061 if (environment_stack[depth] != style.latexname()) {
3062 environment_stack[depth] = style.latexname();
3063 environment_inner[depth] = "!-- --";
3064 sgmlOpenTag(ofs, depth + command_depth,
3065 environment_stack[depth]);
3067 if(environment_inner[depth] != "!-- --") {
3068 item_name= "listitem";
3070 command_depth + depth,
3072 if (environment_inner[depth] == "varlistentry")
3074 depth + command_depth,
3075 environment_inner[depth]);
3079 if(style.latextype == LATEX_ENVIRONMENT) {
3080 if(!style.latexparam().empty())
3081 sgmlOpenTag(ofs, depth + command_depth,
3082 style.latexparam());
3086 desc_on = (style.labeltype == LABEL_MANUAL);
3089 environment_inner[depth]= "varlistentry";
3091 environment_inner[depth]= "listitem";
3093 sgmlOpenTag(ofs, depth + 1 + command_depth,
3094 environment_inner[depth]);
3098 sgmlOpenTag(ofs, depth + 1 + command_depth,
3102 sgmlOpenTag(ofs, depth + 1 + command_depth,
3107 sgmlOpenTag(ofs, depth + command_depth,
3116 SimpleDocBookOnePar(ofs, extra_par, par, desc_on,
3117 depth + 1 + command_depth);
3120 DocBookHandleFootnote(ofs, par,
3121 depth + 1 + command_depth);
3123 while(par && par->IsDummy());
3126 // write closing SGML tags
3127 switch(style.latextype) {
3130 sgmlCloseTag(ofs, depth + command_depth, end_tag);
3132 case LATEX_ENVIRONMENT:
3133 if(!style.latexparam().empty())
3134 sgmlCloseTag(ofs, depth + command_depth,
3135 style.latexparam());
3137 case LATEX_ITEM_ENVIRONMENT:
3138 if(desc_on == 1) break;
3140 sgmlCloseTag(ofs, depth + 1 + command_depth, end_tag);
3142 case LATEX_PARAGRAPH:
3143 if(style.latexname() != "dummy")
3144 sgmlCloseTag(ofs, depth + command_depth,
3148 sgmlCloseTag(ofs, depth + command_depth,
3155 for(; depth >= 0; --depth) {
3156 if(!environment_stack[depth].empty()) {
3157 if(environment_inner[depth] != "!-- --") {
3158 item_name= "listitem";
3159 sgmlCloseTag(ofs, command_depth + depth,
3161 if( environment_inner[depth] == "varlistentry")
3162 sgmlCloseTag(ofs, depth + command_depth,
3163 environment_inner[depth]);
3166 sgmlCloseTag(ofs, depth + command_depth,
3167 environment_stack[depth]);
3171 for(int j = command_depth; j >= command_base; --j)
3172 if(!command_stack[j].empty())
3173 sgmlCloseTag(ofs, j, command_stack[j]);
3177 sgmlCloseTag(ofs, 0, top_element);
3181 // How to check for successful close
3185 void Buffer::SimpleDocBookOnePar(ostream & os, string & extra,
3186 LyXParagraph * par, int & desc_on,
3191 par->SimpleDocBookOneTablePar(this,
3192 os, extra, desc_on, depth);
3197 bool emph_flag = false;
3199 LyXLayout const & style = textclasslist.Style(params.textclass,
3202 LyXParagraph::size_type main_body;
3203 if (style.labeltype != LABEL_MANUAL)
3206 main_body = par->BeginningOfMainBody();
3208 // gets paragraph main font
3209 LyXFont font1 = main_body > 0 ? style.labelfont : style.font;
3211 int char_line_count = depth;
3212 if(!style.free_spacing)
3213 for (int j = 0; j < depth; ++j)
3216 // parsing main loop
3217 for (LyXParagraph::size_type i = 0;
3218 i < par->size(); ++i) {
3219 LyXFont font2 = par->getFont(params, i);
3221 // handle <emphasis> tag
3222 if (font1.emph() != font2.emph() && i) {
3223 if (font2.emph() == LyXFont::ON) {
3227 os << "</emphasis>";
3232 char c = par->GetChar(i);
3234 if (c == LyXParagraph::META_INSET) {
3235 Inset * inset = par->GetInset(i);
3237 std::ostringstream ost;
3238 inset->DocBook(this, ost);
3239 string tmp_out = ost.str().c_str();
3242 inset->DocBook(this, ost);
3244 char * ctmp = ost.str();
3245 string tmp_out(ctmp);
3249 // This code needs some explanation:
3250 // Two insets are treated specially
3251 // label if it is the first element in a command paragraph
3253 // graphics inside tables or figure floats can't go on
3254 // title (the equivalente in latex for this case is caption
3255 // and title should come first
3258 if(desc_on!= 3 || i!= 0) {
3259 if(!tmp_out.empty() && tmp_out[0] == '@') {
3261 extra += frontStrip(tmp_out, '@');
3263 os << frontStrip(tmp_out, '@');
3268 } else if (font2.latex() == LyXFont::ON) {
3269 // "TeX"-Mode on ==> SGML-Mode on.
3275 if (par->linuxDocConvertChar(c, sgml_string)
3276 && !style.free_spacing) { // in freespacing
3278 // non-breaking characters
3282 os << "\n</term><listitem><para>";
3294 // needed if there is an optional argument but no contents
3295 if (main_body > 0 && main_body == par->size()) {
3299 os << "</emphasis>";
3302 // resets description flag correctly
3305 // <term> not closed...
3313 int Buffer::runLaTeX()
3315 if (!users->text) return 0;
3317 ProhibitInput(users);
3319 // get LaTeX-Filename
3320 string name = getLatexName();
3322 string path = OnlyPath(filename);
3324 string org_path = path;
3325 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3329 Path p(path); // path to LaTeX file
3330 users->owner()->getMiniBuffer()->Set(_("Running LaTeX..."));
3332 // Remove all error insets
3333 bool a = users->removeAutoInsets();
3335 // Always generate the LaTeX file
3336 makeLaTeXFile(name, org_path, false);
3338 // do the LaTex run(s)
3340 string latex_command = lyxrc.pdf_mode ?
3341 lyxrc.pdflatex_command : lyxrc.latex_command;
3342 LaTeX latex(latex_command, name, filepath);
3343 int res = latex.run(terr,
3344 users->owner()->getMiniBuffer()); // running latex
3346 // check return value from latex.run().
3347 if ((res & LaTeX::NO_LOGFILE)) {
3348 WriteAlert(_("LaTeX did not work!"),
3349 _("Missing log file:"), name);
3350 } else if ((res & LaTeX::ERRORS)) {
3351 users->owner()->getMiniBuffer()->Set(_("Done"));
3352 // Insert all errors as errors boxes
3353 users->insertErrors(terr);
3355 // Dvi should also be kept dirty if the latex run
3356 // ends up with errors. However it should be possible
3357 // to view a dirty dvi too.
3359 //no errors or any other things to think about so:
3360 users->owner()->getMiniBuffer()->Set(_("Done"));
3363 // if we removed error insets before we ran LaTeX or if we inserted
3364 // error insets after we ran LaTeX this must be run:
3365 if (a || (res & LaTeX::ERRORS)){
3368 //users->updateScrollbar();
3372 return latex.getNumErrors();
3376 int Buffer::runLiterate()
3378 if (!users->text) return 0;
3380 ProhibitInput(users);
3382 // get LaTeX-Filename
3383 string name = getLatexName();
3384 // get Literate-Filename
3385 string lit_name = OnlyFilename(ChangeExtension (getLatexName(),
3386 lyxrc.literate_extension));
3388 string path = OnlyPath(filename);
3390 string org_path = path;
3391 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3395 Path p(path); // path to Literate file
3396 users->owner()->getMiniBuffer()->Set(_("Running Literate..."));
3398 // Remove all error insets
3399 bool a = users->removeAutoInsets();
3401 // generate the Literate file if necessary
3402 makeLaTeXFile(lit_name, org_path, false);
3404 string latex_command = lyxrc.pdf_mode ?
3405 lyxrc.pdflatex_command : lyxrc.latex_command;
3406 Literate literate(latex_command, name, filepath,
3408 lyxrc.literate_command, lyxrc.literate_error_filter,
3409 lyxrc.build_command, lyxrc.build_error_filter);
3411 int res = literate.weave(terr, users->owner()->getMiniBuffer());
3413 // check return value from literate.weave().
3414 if ((res & Literate::NO_LOGFILE)) {
3415 WriteAlert(_("Literate command did not work!"),
3416 _("Missing log file:"), name);
3417 } else if ((res & Literate::ERRORS)) {
3418 users->owner()->getMiniBuffer()->Set(_("Done"));
3419 // Insert all errors as errors boxes
3420 users->insertErrors(terr);
3422 // Dvi should also be kept dirty if the latex run
3423 // ends up with errors. However it should be possible
3424 // to view a dirty dvi too.
3426 //no errors or any other things to think about so:
3427 users->owner()->getMiniBuffer()->Set(_("Done"));
3430 // if we removed error insets before we ran LaTeX or if we inserted
3431 // error insets after we ran LaTeX this must be run:
3432 if (a || (res & Literate::ERRORS)){
3435 //users->updateScrollbar();
3439 return literate.getNumErrors();
3443 int Buffer::buildProgram()
3445 if (!users->text) return 0;
3447 ProhibitInput(users);
3449 // get LaTeX-Filename
3450 string name = getLatexName();
3451 // get Literate-Filename
3452 string lit_name = OnlyFilename(ChangeExtension(getLatexName(),
3453 lyxrc.literate_extension));
3455 string path = OnlyPath(filename);
3457 string org_path = path;
3458 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3462 Path p(path); // path to Literate file
3463 users->owner()->getMiniBuffer()->Set(_("Building Program..."));
3465 // Remove all error insets
3466 bool a = users->removeAutoInsets();
3468 // generate the LaTeX file if necessary
3469 if (!isNwClean() || a) {
3470 makeLaTeXFile(lit_name, org_path, false);
3474 string latex_command = lyxrc.pdf_mode ?
3475 lyxrc.pdflatex_command : lyxrc.latex_command;
3476 Literate literate(latex_command, name, filepath,
3478 lyxrc.literate_command, lyxrc.literate_error_filter,
3479 lyxrc.build_command, lyxrc.build_error_filter);
3481 int res = literate.build(terr, users->owner()->getMiniBuffer());
3483 // check return value from literate.build().
3484 if ((res & Literate::NO_LOGFILE)) {
3485 WriteAlert(_("Build did not work!"),
3486 _("Missing log file:"), name);
3487 } else if ((res & Literate::ERRORS)) {
3488 users->owner()->getMiniBuffer()->Set(_("Done"));
3489 // Insert all errors as errors boxes
3490 users->insertErrors(terr);
3492 // Literate files should also be kept dirty if the literate
3493 // command run ends up with errors.
3495 //no errors or any other things to think about so:
3496 users->owner()->getMiniBuffer()->Set(_("Done"));
3500 // if we removed error insets before we ran Literate/Build or
3501 // if we inserted error insets after we ran Literate/Build this
3503 if (a || (res & Literate::ERRORS)){
3506 //users->updateScrollbar();
3510 return literate.getNumErrors();
3514 // This should be enabled when the Chktex class is implemented. (Asger)
3515 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
3516 // Other flags: -wall -v0 -x
3517 int Buffer::runChktex()
3519 if (!users->text) return 0;
3521 ProhibitInput(users);
3523 // get LaTeX-Filename
3524 string name = getLatexName();
3525 string path = OnlyPath(filename);
3527 string org_path = path;
3528 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3532 Path p(path); // path to LaTeX file
3533 users->owner()->getMiniBuffer()->Set(_("Running chktex..."));
3535 // Remove all error insets
3536 bool removedErrorInsets = users->removeAutoInsets();
3538 // Generate the LaTeX file if neccessary
3539 makeLaTeXFile(name, org_path, false);
3542 Chktex chktex(lyxrc.chktex_command, name, filepath);
3543 int res = chktex.run(terr); // run chktex
3546 WriteAlert(_("chktex did not work!"),
3547 _("Could not run with file:"), name);
3548 } else if (res > 0) {
3549 // Insert all errors as errors boxes
3550 users->insertErrors(terr);
3553 // if we removed error insets before we ran chktex or if we inserted
3554 // error insets after we ran chktex, this must be run:
3555 if (removedErrorInsets || res){
3558 //users->updateScrollbar();
3566 void Buffer::validate(LaTeXFeatures & features) const
3568 LyXParagraph * par = paragraph;
3569 LyXTextClass const & tclass =
3570 textclasslist.TextClass(params.textclass);
3572 // AMS Style is at document level
3574 features.amsstyle = (params.use_amsmath ||
3575 tclass.provides(LyXTextClass::amsmath));
3578 // We don't use "lyxerr.debug" because of speed. (Asger)
3579 if (lyxerr.debugging(Debug::LATEX))
3580 lyxerr << "Paragraph: " << par << endl;
3582 // Now just follow the list of paragraphs and run
3583 // validate on each of them.
3584 par->validate(features);
3586 // and then the next paragraph
3590 // the bullet shapes are buffer level not paragraph level
3591 // so they are tested here
3592 for (int i = 0; i < 4; ++i) {
3593 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
3594 int font = params.user_defined_bullets[i].getFont();
3597 .user_defined_bullets[i]
3604 features.latexsym = true;
3608 features.amssymb = true;
3610 else if ((font >= 2 && font <= 5)) {
3611 features.pifont = true;
3616 if (lyxerr.debugging(Debug::LATEX)) {
3617 features.showStruct();
3622 void Buffer::setPaperStuff()
3624 params.papersize = BufferParams::PAPER_DEFAULT;
3625 char c1 = params.paperpackage;
3626 if (c1 == BufferParams::PACKAGE_NONE) {
3627 char c2 = params.papersize2;
3628 if (c2 == BufferParams::VM_PAPER_USLETTER)
3629 params.papersize = BufferParams::PAPER_USLETTER;
3630 else if (c2 == BufferParams::VM_PAPER_USLEGAL)
3631 params.papersize = BufferParams::PAPER_LEGALPAPER;
3632 else if (c2 == BufferParams::VM_PAPER_USEXECUTIVE)
3633 params.papersize = BufferParams::PAPER_EXECUTIVEPAPER;
3634 else if (c2 == BufferParams::VM_PAPER_A3)
3635 params.papersize = BufferParams::PAPER_A3PAPER;
3636 else if (c2 == BufferParams::VM_PAPER_A4)
3637 params.papersize = BufferParams::PAPER_A4PAPER;
3638 else if (c2 == BufferParams::VM_PAPER_A5)
3639 params.papersize = BufferParams::PAPER_A5PAPER;
3640 else if ((c2 == BufferParams::VM_PAPER_B3) || (c2 == BufferParams::VM_PAPER_B4) ||
3641 (c2 == BufferParams::VM_PAPER_B5))
3642 params.papersize = BufferParams::PAPER_B5PAPER;
3643 } else if ((c1 == BufferParams::PACKAGE_A4) || (c1 == BufferParams::PACKAGE_A4WIDE) ||
3644 (c1 == BufferParams::PACKAGE_WIDEMARGINSA4))
3645 params.papersize = BufferParams::PAPER_A4PAPER;
3649 // This function should be in Buffer because it's a buffer's property (ale)
3650 string Buffer::getIncludeonlyList(char delim)
3653 for (inset_iterator it = inset_iterator_begin();
3654 it != inset_iterator_end(); ++it) {
3655 if ((*it)->LyxCode() == Inset::INCLUDE_CODE) {
3656 InsetInclude * insetinc =
3657 static_cast<InsetInclude *>(*it);
3658 if (insetinc->isInclude()
3659 && insetinc->isNoLoad()) {
3662 lst += OnlyFilename(ChangeExtension(insetinc->getContents(), string()));
3666 lyxerr.debug() << "Includeonly(" << lst << ')' << endl;
3671 vector<string> Buffer::getLabelList()
3673 /// if this is a child document and the parent is already loaded
3674 /// Use the parent's list instead [ale990407]
3675 if (!params.parentname.empty()
3676 && bufferlist.exists(params.parentname)) {
3677 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3679 return tmp->getLabelList();
3682 vector<string> label_list;
3683 for (inset_iterator it = inset_iterator_begin();
3684 it != inset_iterator_end(); ++it) {
3685 vector<string> l = (*it)->getLabelList();
3686 label_list.insert(label_list.end(), l.begin(), l.end());
3692 vector<vector<Buffer::TocItem> > Buffer::getTocList()
3694 vector<vector<TocItem> > l(4);
3695 LyXParagraph * par = paragraph;
3698 if (par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
3699 if (textclasslist.Style(params.textclass,
3700 par->GetLayout()).labeltype
3701 == LABEL_SENSITIVE) {
3705 tmp.str = par->String(this, false);
3706 switch (par->footnotekind) {
3707 case LyXParagraph::FIG:
3708 case LyXParagraph::WIDE_FIG:
3709 l[TOC_LOF].push_back(tmp);
3711 case LyXParagraph::TAB:
3712 case LyXParagraph::WIDE_TAB:
3713 l[TOC_LOT].push_back(tmp);
3715 case LyXParagraph::ALGORITHM:
3716 l[TOC_LOA].push_back(tmp);
3718 case LyXParagraph::FOOTNOTE:
3719 case LyXParagraph::MARGIN:
3723 } else if (!par->IsDummy()) {
3725 char labeltype = textclasslist.Style(params.textclass,
3726 par->GetLayout()).labeltype;
3728 if (labeltype >= LABEL_COUNTER_CHAPTER
3729 && labeltype <= LABEL_COUNTER_CHAPTER + params.tocdepth) {
3730 // insert this into the table of contents
3735 textclasslist.TextClass(params.textclass).maxcounter());
3736 tmp.str = par->String(this, true);
3737 l[TOC_TOC].push_back(tmp);
3747 // This is also a buffer property (ale)
3748 vector<pair<string,string> > Buffer::getBibkeyList()
3750 /// if this is a child document and the parent is already loaded
3751 /// Use the parent's list instead [ale990412]
3752 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3753 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3755 return tmp->getBibkeyList();
3758 vector<pair<string, string> > keys;
3759 LyXParagraph * par = paragraph;
3762 keys.push_back(pair<string, string>(par->bibkey->getContents(),
3763 par->String(this, false)));
3767 // Might be either using bibtex or a child has bibliography
3769 for (inset_iterator it = inset_iterator_begin();
3770 it != inset_iterator_end(); ++it) {
3771 // Search for Bibtex or Include inset
3772 if ((*it)->LyxCode() == Inset::BIBTEX_CODE) {
3773 vector<pair<string,string> > tmp =
3774 static_cast<InsetBibtex*>(*it)->getKeys();
3775 keys.insert(keys.end(), tmp.begin(), tmp.end());
3776 } else if ((*it)->LyxCode() == Inset::INCLUDE_CODE) {
3777 vector<pair<string,string> > tmp =
3778 static_cast<InsetInclude*>(*it)->getKeys();
3779 keys.insert(keys.end(), tmp.begin(), tmp.end());
3788 bool Buffer::isDepClean(string const & name) const
3790 DEPCLEAN * item = dep_clean;
3791 while (item && item->master != name)
3793 if (!item) return true;
3798 void Buffer::markDepClean(string const & name)
3801 dep_clean = new DEPCLEAN;
3802 dep_clean->clean = true;
3803 dep_clean->master = name;
3804 dep_clean->next = 0;
3806 DEPCLEAN* item = dep_clean;
3807 while (item && item->master != name)
3812 item = new DEPCLEAN;
3814 item->master = name;
3821 bool Buffer::Dispatch(string const & command)
3823 // Split command string into command and argument
3824 string cmd, line = frontStrip(command);
3825 string arg = strip(frontStrip(split(line, cmd, ' ')));
3827 return Dispatch(lyxaction.LookupFunc(cmd.c_str()), arg.c_str());
3831 bool Buffer::Dispatch(int action, string const & argument)
3833 bool dispatched = true;
3836 MenuExport(this, argument);
3846 void Buffer::resize()
3848 /// resize the BufferViews!
3854 void Buffer::resizeInsets(BufferView * bv)
3856 /// then remove all LyXText in text-insets
3857 LyXParagraph * par = paragraph;
3858 for(;par;par = par->next) {
3859 par->resizeInsetsLyXText(bv);
3863 void Buffer::ChangeLanguage(Language const * from, Language const * to)
3866 LyXParagraph * par = paragraph;
3868 par->ChangeLanguage(params, from, to);
3874 bool Buffer::isMultiLingual()
3877 LyXParagraph * par = paragraph;
3879 if (par->isMultiLingual(params))
3887 Buffer::inset_iterator::inset_iterator(LyXParagraph * paragraph,
3888 LyXParagraph::size_type pos)
3890 it = par->InsetIterator(pos);
3891 if (it == par->inset_iterator_end()) {
3898 void Buffer::inset_iterator::SetParagraph() {
3900 it = par->inset_iterator_begin();
3901 if (it != par->inset_iterator_end())
3906 // We maintain an invariant that whenever par = 0 then it = 0