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 "support/filetools.h"
76 #include "support/path.h"
82 #include "LaTeXFeatures.h"
83 #include "support/syscall.h"
84 #include "support/lyxlib.h"
85 #include "support/FileInfo.h"
89 #include "lyx_gui_misc.h" // WarnReadonly()
90 #include "frontends/Dialogs.h"
105 // all these externs should eventually be removed.
106 extern BufferList bufferlist;
108 extern void MenuExport(Buffer *, string const &);
109 extern LyXAction lyxaction;
112 static const float LYX_FORMAT = 2.16;
114 extern int tex_code_break_column;
117 Buffer::Buffer(string const & file, bool ronly)
119 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
121 filepath = OnlyPath(file);
129 if (read_only || (lyxrc.use_tempdir)) {
130 tmppath = CreateBufferTmpDir();
131 } else tmppath.erase();
137 lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
138 // here the buffer should take care that it is
139 // saved properly, before it goes into the void.
141 // make sure that views using this buffer
146 if (!tmppath.empty()) {
147 DestroyBufferTmpDir(tmppath);
150 LyXParagraph * par = paragraph;
151 LyXParagraph * tmppar;
161 string Buffer::getLatexName(bool no_path) const
164 return OnlyFilename(ChangeExtension(MakeLatexName(filename),
167 return ChangeExtension(MakeLatexName(filename),
172 void Buffer::setReadonly(bool flag)
174 if (read_only != flag) {
177 users->owner()->getDialogs()->updateBufferDependent();
180 WarnReadonly(filename);
185 bool Buffer::saveParamsAsDefaults()
187 string fname = AddName(AddPath(user_lyxdir, "templates/"),
189 Buffer defaults = Buffer(fname);
191 // Use the current buffer's parameters as default
192 defaults.params = params;
194 // add an empty paragraph. Is this enough?
195 defaults.paragraph = new LyXParagraph;
197 return defaults.writeFile(defaults.filename, false);
201 /// Update window titles of all users
202 // Should work on a list
203 void Buffer::updateTitles() const
205 if (users) users->owner()->updateWindowTitle();
209 /// Reset autosave timer of all users
210 // Should work on a list
211 void Buffer::resetAutosaveTimers() const
213 if (users) users->owner()->resetAutosaveTimer();
217 void Buffer::fileName(string const & newfile)
219 filename = MakeAbsPath(newfile);
220 filepath = OnlyPath(filename);
221 setReadonly(IsFileWriteable(filename) == 0);
226 // candidate for move to BufferView
227 // (at least some parts in the beginning of the func)
230 // changed to be public and have one parameter
231 // if par = 0 normal behavior
232 // else insert behavior
233 // Returns false if "\the_end" is not read for formats >= 2.13. (Asger)
234 #define USE_PARSE_FUNCTION 1
235 //#define USE_TABULAR_INSETS 1
236 bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par)
240 char depth = 0; // signed or unsigned?
241 LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
242 LyXParagraph::footnote_kind footnotekind = LyXParagraph::FOOTNOTE;
243 bool the_end_read = false;
245 LyXParagraph * return_par = 0;
246 LyXFont font(LyXFont::ALL_INHERIT, params.language_info);
247 if (format < 2.16 && params.language == "hebrew")
248 font.setLanguage(default_language);
250 // If we are inserting, we cheat and get a token in advance
251 bool has_token = false;
255 par = new LyXParagraph;
257 users->text->BreakParagraph(users);
258 return_par = users->text->FirstParagraph();
261 // We don't want to adopt the parameters from the
262 // document we insert, so we skip until the text begins:
265 pretoken = lex.GetString();
266 if (pretoken == "\\layout") {
278 pretoken = lex.GetString();
281 // Profiling show this should give a lot: (Asger)
282 string const token = pretoken;
286 the_end_read = parseSingleLyXformat2Token(lex, par, return_par,
295 paragraph = return_par;
302 Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
303 LyXParagraph *& return_par,
304 string const & token, int & pos,
305 char & depth, LyXFont & font,
306 LyXParagraph::footnote_flag & footnoteflag,
307 LyXParagraph::footnote_kind & footnotekind)
309 bool the_end_read = false;
310 // We'll remove this later. (Lgb)
311 static string last_inset_read;
313 if (token[0] != '\\') {
314 for (string::const_iterator cit = token.begin();
315 cit != token.end(); ++cit) {
316 par->InsertChar(pos, (*cit), font);
319 } else if (token == "\\i") {
320 Inset * inset = new InsetLatexAccent;
321 inset->Read(this, lex);
322 par->InsertInset(pos, inset, font);
324 } else if (token == "\\layout") {
329 par = new LyXParagraph(par);
333 string layoutname = lex.GetString();
334 pair<bool, LyXTextClass::LayoutList::size_type> pp
335 = textclasslist.NumberOfLayout(params.textclass,
338 par->layout = pp.second;
339 } else { // layout not found
340 // use default layout "Standard" (0)
343 // Test whether the layout is obsolete.
344 LyXLayout const & layout =
345 textclasslist.Style(params.textclass,
347 if (!layout.obsoleted_by().empty())
349 textclasslist.NumberOfLayout(params.textclass,
350 layout.obsoleted_by()).second;
351 par->footnoteflag = footnoteflag;
352 par->footnotekind = footnotekind;
354 font = LyXFont(LyXFont::ALL_INHERIT, params.language_info);
355 if (format < 2.16 && params.language == "hebrew")
356 font.setLanguage(default_language);
358 } else if (token == "\\end_float") {
363 par = new LyXParagraph(par);
365 footnotekind = LyXParagraph::FOOTNOTE;
366 footnoteflag = LyXParagraph::NO_FOOTNOTE;
369 par->layout = LYX_DUMMY_LAYOUT;
370 font = LyXFont(LyXFont::ALL_INHERIT, params.language_info);
371 if (format < 2.16 && params.language == "hebrew")
372 font.setLanguage(default_language);
373 } else if (token == "\\begin_float") {
374 int tmpret = lex.FindToken(string_footnotekinds);
375 if (tmpret == -1) ++tmpret;
376 if (tmpret != LYX_LAYOUT_DEFAULT)
377 footnotekind = static_cast<LyXParagraph::footnote_kind>(tmpret); // bad
378 if (footnotekind == LyXParagraph::FOOTNOTE
379 || footnotekind == LyXParagraph::MARGIN)
380 footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
382 footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
384 } else if (token == "\\begin_float") {
385 // This is the compability reader, unfinished but tested.
388 string tmptok = lex.GetString();
389 //lyxerr << "old float: " << tmptok << endl;
393 if (tmptok == "footnote") {
394 inset = new InsetFoot;
395 } else if (tmptok == "margin") {
396 inset = new InsetMarginal;
397 } else if (tmptok == "fig") {
398 inset = new InsetFloat("figure");
399 //inset = new InsetFigure;
400 } else if (tmptok == "tab") {
401 inset = new InsetFloat("table");
402 //inset = new InsetTable;
403 } else if (tmptok == "alg") {
404 inset = new InsetFloat("algorithm");
405 //inset = new InsetAlgorithm;
406 } else if (tmptok == "wide-fig") {
407 InsetFloat * tmp = new InsetFloat("figure");
410 //inset = new InsetFigure(true);
411 } else if (tmptok == "wide-tab") {
412 InsetFloat * tmp = new InsetFloat("table");
415 //inset = new InsetTable(true);
418 if (!inset) return false; // no end read yet
420 string old_float = "\ncollapsed true\n";
421 old_float += lex.getLongString("\\end_float");
422 old_float += "\n\\end_inset\n";
423 lyxerr << "float body: " << old_float << endl;
425 istrstream istr(old_float.c_str());
427 nylex.setStream(istr);
429 inset->Read(this, nylex);
430 par->InsertInset(pos, inset, font);
433 } else if (token == "\\begin_deeper") {
435 } else if (token == "\\end_deeper") {
437 lex.printError("\\end_deeper: "
438 "depth is already null");
442 } else if (token == "\\begin_preamble") {
443 params.readPreamble(lex);
444 } else if (token == "\\textclass") {
446 pair<bool, LyXTextClassList::size_type> pp =
447 textclasslist.NumberOfClass(lex.GetString());
449 params.textclass = pp.second;
451 lex.printError("Unknown textclass `$$Token'");
452 params.textclass = 0;
454 if (!textclasslist.Load(params.textclass)) {
455 // if the textclass wasn't loaded properly
456 // we need to either substitute another
457 // or stop loading the file.
458 // I can substitute but I don't see how I can
459 // stop loading... ideas?? ARRae980418
460 WriteAlert(_("Textclass Loading Error!"),
461 string(_("Can't load textclass ")) +
462 textclasslist.NameOfClass(params.textclass),
463 _("-- substituting default"));
464 params.textclass = 0;
466 } else if (token == "\\options") {
468 params.options = lex.GetString();
469 } else if (token == "\\language") {
470 params.readLanguage(lex);
471 } else if (token == "\\fontencoding") {
473 } else if (token == "\\inputencoding") {
475 params.inputenc = lex.GetString();
476 } else if (token == "\\graphics") {
477 params.readGraphicsDriver(lex);
478 } else if (token == "\\fontscheme") {
480 params.fonts = lex.GetString();
481 } else if (token == "\\noindent") {
482 par->noindent = true;
483 } else if (token == "\\fill_top") {
484 par->added_space_top = VSpace(VSpace::VFILL);
485 } else if (token == "\\fill_bottom") {
486 par->added_space_bottom = VSpace(VSpace::VFILL);
487 } else if (token == "\\line_top") {
488 par->line_top = true;
489 } else if (token == "\\line_bottom") {
490 par->line_bottom = true;
491 } else if (token == "\\pagebreak_top") {
492 par->pagebreak_top = true;
493 } else if (token == "\\pagebreak_bottom") {
494 par->pagebreak_bottom = true;
495 } else if (token == "\\start_of_appendix") {
496 par->start_of_appendix = true;
497 } else if (token == "\\paragraph_separation") {
498 int tmpret = lex.FindToken(string_paragraph_separation);
499 if (tmpret == -1) ++tmpret;
500 if (tmpret != LYX_LAYOUT_DEFAULT)
501 params.paragraph_separation =
502 static_cast<BufferParams::PARSEP>(tmpret);
503 } else if (token == "\\defskip") {
505 params.defskip = VSpace(lex.GetString());
506 } else if (token == "\\epsfig") { // obsolete
507 // Indeed it is obsolete, but we HAVE to be backwards
508 // compatible until 0.14, because otherwise all figures
509 // in existing documents are irretrivably lost. (Asger)
510 params.readGraphicsDriver(lex);
511 } else if (token == "\\quotes_language") {
512 int tmpret = lex.FindToken(string_quotes_language);
513 if (tmpret == -1) ++tmpret;
514 if (tmpret != LYX_LAYOUT_DEFAULT) {
515 InsetQuotes::quote_language tmpl =
516 InsetQuotes::EnglishQ;
519 tmpl = InsetQuotes::EnglishQ;
522 tmpl = InsetQuotes::SwedishQ;
525 tmpl = InsetQuotes::GermanQ;
528 tmpl = InsetQuotes::PolishQ;
531 tmpl = InsetQuotes::FrenchQ;
534 tmpl = InsetQuotes::DanishQ;
537 params.quotes_language = tmpl;
539 } else if (token == "\\quotes_times") {
541 switch(lex.GetInteger()) {
543 params.quotes_times = InsetQuotes::SingleQ;
546 params.quotes_times = InsetQuotes::DoubleQ;
549 } else if (token == "\\papersize") {
550 int tmpret = lex.FindToken(string_papersize);
554 params.papersize2 = tmpret;
555 } else if (token == "\\paperpackage") {
556 int tmpret = lex.FindToken(string_paperpackages);
559 params.paperpackage = BufferParams::PACKAGE_NONE;
561 params.paperpackage = tmpret;
562 } else if (token == "\\use_geometry") {
564 params.use_geometry = lex.GetInteger();
565 } else if (token == "\\use_amsmath") {
567 params.use_amsmath = lex.GetInteger();
568 } else if (token == "\\paperorientation") {
569 int tmpret = lex.FindToken(string_orientation);
570 if (tmpret == -1) ++tmpret;
571 if (tmpret != LYX_LAYOUT_DEFAULT)
572 params.orientation = static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
573 } else if (token == "\\paperwidth") {
575 params.paperwidth = lex.GetString();
576 } else if (token == "\\paperheight") {
578 params.paperheight = lex.GetString();
579 } else if (token == "\\leftmargin") {
581 params.leftmargin = lex.GetString();
582 } else if (token == "\\topmargin") {
584 params.topmargin = lex.GetString();
585 } else if (token == "\\rightmargin") {
587 params.rightmargin = lex.GetString();
588 } else if (token == "\\bottommargin") {
590 params.bottommargin = lex.GetString();
591 } else if (token == "\\headheight") {
593 params.headheight = lex.GetString();
594 } else if (token == "\\headsep") {
596 params.headsep = lex.GetString();
597 } else if (token == "\\footskip") {
599 params.footskip = lex.GetString();
600 } else if (token == "\\paperfontsize") {
602 params.fontsize = strip(lex.GetString());
603 } else if (token == "\\papercolumns") {
605 params.columns = lex.GetInteger();
606 } else if (token == "\\papersides") {
608 switch(lex.GetInteger()) {
610 case 1: params.sides = LyXTextClass::OneSide; break;
611 case 2: params.sides = LyXTextClass::TwoSides; break;
613 } else if (token == "\\paperpagestyle") {
615 params.pagestyle = strip(lex.GetString());
616 } else if (token == "\\bullet") {
618 int index = lex.GetInteger();
620 int temp_int = lex.GetInteger();
621 params.user_defined_bullets[index].setFont(temp_int);
622 params.temp_bullets[index].setFont(temp_int);
624 temp_int = lex.GetInteger();
625 params.user_defined_bullets[index].setCharacter(temp_int);
626 params.temp_bullets[index].setCharacter(temp_int);
628 temp_int = lex.GetInteger();
629 params.user_defined_bullets[index].setSize(temp_int);
630 params.temp_bullets[index].setSize(temp_int);
632 string temp_str = lex.GetString();
633 if (temp_str != "\\end_bullet") {
634 // this element isn't really necessary for
635 // parsing but is easier for humans
636 // to understand bullets. Put it back and
637 // set a debug message?
638 lex.printError("\\end_bullet expected, got" + temp_str);
639 //how can I put it back?
641 } else if (token == "\\bulletLaTeX") {
643 int index = lex.GetInteger();
645 string temp_str = lex.GetString(), sum_str;
646 while (temp_str != "\\end_bullet") {
647 // this loop structure is needed when user
648 // enters an empty string since the first
649 // thing returned will be the \\end_bullet
651 // if the LaTeX entry has spaces. Each element
652 // therefore needs to be read in turn
655 temp_str = lex.GetString();
657 params.user_defined_bullets[index].setText(sum_str);
658 params.temp_bullets[index].setText(sum_str);
659 } else if (token == "\\secnumdepth") {
661 params.secnumdepth = lex.GetInteger();
662 } else if (token == "\\tocdepth") {
664 params.tocdepth = lex.GetInteger();
665 } else if (token == "\\spacing") {
667 string tmp = strip(lex.GetString());
668 Spacing::Space tmp_space = Spacing::Default;
670 if (tmp == "single") {
671 tmp_space = Spacing::Single;
672 } else if (tmp == "onehalf") {
673 tmp_space = Spacing::Onehalf;
674 } else if (tmp == "double") {
675 tmp_space = Spacing::Double;
676 } else if (tmp == "other") {
678 tmp_space = Spacing::Other;
679 tmp_val = lex.GetFloat();
681 lex.printError("Unknown spacing token: '$$Token'");
683 // Small hack so that files written with klyx will be
686 par->spacing.set(tmp_space, tmp_val);
688 params.spacing.set(tmp_space, tmp_val);
690 } else if (token == "\\paragraph_spacing") {
692 string tmp = strip(lex.GetString());
693 if (tmp == "single") {
694 par->spacing.set(Spacing::Single);
695 } else if (tmp == "onehalf") {
696 par->spacing.set(Spacing::Onehalf);
697 } else if (tmp == "double") {
698 par->spacing.set(Spacing::Double);
699 } else if (tmp == "other") {
701 par->spacing.set(Spacing::Other,
704 lex.printError("Unknown spacing token: '$$Token'");
706 } else if (token == "\\float_placement") {
708 params.float_placement = lex.GetString();
709 } else if (token == "\\family") {
711 font.setLyXFamily(lex.GetString());
712 } else if (token == "\\series") {
714 font.setLyXSeries(lex.GetString());
715 } else if (token == "\\shape") {
717 font.setLyXShape(lex.GetString());
718 } else if (token == "\\size") {
720 font.setLyXSize(lex.GetString());
721 } else if (token == "\\latex") {
723 string tok = lex.GetString();
724 // This is dirty, but gone with LyX3. (Asger)
725 if (tok == "no_latex")
726 font.setLatex(LyXFont::OFF);
727 else if (tok == "latex")
728 font.setLatex(LyXFont::ON);
729 else if (tok == "default")
730 font.setLatex(LyXFont::INHERIT);
732 lex.printError("Unknown LaTeX font flag "
734 } else if (token == "\\lang") {
736 string tok = lex.GetString();
737 Languages::iterator lit = languages.find(tok);
738 if (lit != languages.end()) {
739 font.setLanguage(&(*lit).second);
741 font.setLanguage(params.language_info);
742 lex.printError("Unknown language `$$Token'");
744 } else if (token == "\\emph") {
746 font.setEmph(font.setLyXMisc(lex.GetString()));
747 } else if (token == "\\bar") {
749 string tok = lex.GetString();
750 // This is dirty, but gone with LyX3. (Asger)
752 font.setUnderbar(LyXFont::ON);
753 else if (tok == "no")
754 font.setUnderbar(LyXFont::OFF);
755 else if (tok == "default")
756 font.setUnderbar(LyXFont::INHERIT);
758 lex.printError("Unknown bar font flag "
760 } else if (token == "\\noun") {
762 font.setNoun(font.setLyXMisc(lex.GetString()));
763 } else if (token == "\\color") {
765 font.setLyXColor(lex.GetString());
766 } else if (token == "\\align") {
767 int tmpret = lex.FindToken(string_align);
768 if (tmpret == -1) ++tmpret;
769 if (tmpret != LYX_LAYOUT_DEFAULT) { // tmpret != 99 ???
771 for (; tmpret > 0; --tmpret)
772 tmpret2 = tmpret2 * 2;
773 par->align = LyXAlignment(tmpret2);
775 } else if (token == "\\added_space_top") {
777 par->added_space_top = VSpace(lex.GetString());
778 } else if (token == "\\added_space_bottom") {
780 par->added_space_bottom = VSpace(lex.GetString());
781 } else if (token == "\\pextra_type") {
783 par->pextra_type = lex.GetInteger();
784 } else if (token == "\\pextra_width") {
786 par->pextra_width = lex.GetString();
787 } else if (token == "\\pextra_widthp") {
789 par->pextra_widthp = lex.GetString();
790 } else if (token == "\\pextra_alignment") {
792 par->pextra_alignment = lex.GetInteger();
793 } else if (token == "\\pextra_hfill") {
795 par->pextra_hfill = lex.GetInteger();
796 } else if (token == "\\pextra_start_minipage") {
798 par->pextra_start_minipage = lex.GetInteger();
799 } else if (token == "\\labelwidthstring") {
801 par->labelwidthstring = lex.GetString();
802 // do not delete this token, it is still needed!
803 } else if (token == "\\end_inset") {
804 lyxerr << "Solitary \\end_inset. Missing \\begin_inset?.\n"
805 << "Last inset read was: " << last_inset_read
807 // Simply ignore this. The insets do not have
809 // But insets should read it, it is a part of
810 // the inset isn't it? Lgb.
811 } else if (token == "\\begin_inset") {
812 // Should be moved out into its own function/method. (Lgb)
814 string tmptok = lex.GetString();
815 last_inset_read = tmptok;
816 // test the different insets
817 if (tmptok == "Quotes") {
818 Inset * inset = new InsetQuotes;
819 inset->Read(this, lex);
820 par->InsertInset(pos, inset, font);
822 } else if (tmptok == "External") {
823 Inset * inset = new InsetExternal;
824 inset->Read(this, lex);
825 par->InsertInset(pos, inset, font);
827 } else if (tmptok == "FormulaMacro") {
828 Inset * inset = new InsetFormulaMacro;
829 inset->Read(this, lex);
830 par->InsertInset(pos, inset, font);
832 } else if (tmptok == "Formula") {
833 Inset * inset = new InsetFormula;
834 inset->Read(this, lex);
835 par->InsertInset(pos, inset, font);
837 } else if (tmptok == "Figure") {
838 Inset * inset = new InsetFig(100, 100, this);
839 inset->Read(this, lex);
840 par->InsertInset(pos, inset, font);
842 } else if (tmptok == "Info") {
843 Inset * inset = new InsetInfo;
844 inset->Read(this, lex);
845 par->InsertInset(pos, inset, font);
847 } else if (tmptok == "Include") {
848 Inset * inset = new InsetInclude(string(), this);
849 inset->Read(this, lex);
850 par->InsertInset(pos, inset, font);
852 } else if (tmptok == "ERT") {
853 Inset * inset = new InsetERT;
854 inset->Read(this, lex);
855 par->InsertInset(pos, inset, font);
857 } else if (tmptok == "Tabular") {
858 Inset * inset = new InsetTabular(this);
859 inset->Read(this, lex);
860 par->InsertInset(pos, inset, font);
862 } else if (tmptok == "Text") {
863 Inset * inset = new InsetText;
864 inset->Read(this, lex);
865 par->InsertInset(pos, inset, font);
867 } else if (tmptok == "Foot") {
868 Inset * inset = new InsetFoot;
869 inset->Read(this, lex);
870 par->InsertInset(pos, inset, font);
872 } else if (tmptok == "Marginal") {
873 Inset * inset = new InsetMarginal;
874 inset->Read(this, lex);
875 par->InsertInset(pos, inset, font);
877 } else if (tmptok == "Minipage") {
878 Inset * inset = new InsetMinipage;
879 inset->Read(this, lex);
880 par->InsertInset(pos, inset, font);
882 } else if (tmptok == "Float") {
884 string tmptok = lex.GetString();
885 Inset * inset = new InsetFloat(tmptok);
886 inset->Read(this, lex);
887 par->InsertInset(pos, inset, font);
889 } else if (tmptok == "List") {
890 Inset * inset = new InsetList;
891 inset->Read(this, lex);
892 par->InsertInset(pos, inset, font);
894 } else if (tmptok == "Theorem") {
895 Inset * inset = new InsetList;
896 inset->Read(this, lex);
897 par->InsertInset(pos, inset, font);
899 } else if (tmptok == "GRAPHICS") {
900 Inset * inset = new InsetGraphics;
901 //inset->Read(this, lex);
902 par->InsertInset(pos, inset, font);
903 } else if (tmptok == "LatexCommand") {
905 inscmd.Read(this, lex);
907 if (inscmd.getCmdName() == "cite") {
908 inset = new InsetCitation(inscmd.getContents(), inscmd.getOptions());
909 } else if (inscmd.getCmdName() == "bibitem") {
910 lex.printError("Wrong place for bibitem");
911 inset = inscmd.Clone();
912 } else if (inscmd.getCmdName() == "BibTeX") {
913 inset = new InsetBibtex(inscmd.getContents(), inscmd.getOptions(), this);
914 } else if (inscmd.getCmdName() == "index") {
915 inset = new InsetIndex(inscmd.getContents());
916 } else if (inscmd.getCmdName() == "include") {
917 inset = new InsetInclude(inscmd.getContents(), this);
918 } else if (inscmd.getCmdName() == "label") {
919 inset = new InsetLabel(inscmd.getCommand());
920 } else if (inscmd.getCmdName() == "url"
921 || inscmd.getCmdName() == "htmlurl") {
922 inset = new InsetUrl(inscmd.getCommand());
923 } else if (inscmd.getCmdName() == "ref"
924 || inscmd.getCmdName() == "pageref"
925 || inscmd.getCmdName() == "vref"
926 || inscmd.getCmdName() == "vpageref"
927 || inscmd.getCmdName() == "prettyref") {
928 if (!inscmd.getOptions().empty() || !inscmd.getContents().empty()) {
929 inset = new InsetRef(inscmd, this);
931 } else if (inscmd.getCmdName() == "tableofcontents") {
932 inset = new InsetTOC(this);
933 } else if (inscmd.getCmdName() == "listoffigures") {
934 inset = new InsetLOF(this);
935 } else if (inscmd.getCmdName() == "listofalgorithms") {
936 inset = new InsetLOA(this);
937 } else if (inscmd.getCmdName() == "listoftables") {
938 inset = new InsetLOT(this);
939 } else if (inscmd.getCmdName() == "printindex") {
940 inset = new InsetPrintIndex(this);
941 } else if (inscmd.getCmdName() == "lyxparent") {
942 inset = new InsetParent(inscmd.getContents(), this);
946 par->InsertInset(pos, inset, font);
950 } else if (token == "\\SpecialChar") {
951 LyXLayout const & layout =
952 textclasslist.Style(params.textclass,
955 // Insets don't make sense in a free-spacing context! ---Kayvan
956 if (layout.free_spacing) {
959 string next_token = lex.GetString();
960 if (next_token == "\\-") {
961 par->InsertChar(pos, '-', font);
962 } else if (next_token == "\\protected_separator"
963 || next_token == "~") {
964 par->InsertChar(pos, ' ', font);
966 lex.printError("Token `$$Token' "
968 "paragraph layout!");
973 Inset * inset = new InsetSpecialChar;
974 inset->Read(this, lex);
975 par->InsertInset(pos, inset, font);
978 } else if (token == "\\newline") {
979 par->InsertChar(pos, LyXParagraph::META_NEWLINE, font);
981 } else if (token == "\\LyXTable") {
982 #ifdef USE_TABULAR_INSETS
983 Inset * inset = new InsetTabular(this);
984 inset->Read(this, lex);
985 par->InsertInset(pos, inset, font);
988 par->table = new LyXTable(lex);
990 } else if (token == "\\hfill") {
991 par->InsertChar(pos, LyXParagraph::META_HFILL, font);
993 } else if (token == "\\protected_separator") { // obsolete
994 // This is a backward compability thingie. (Lgb)
995 // Remove it later some time...introduced with fileformat
997 LyXLayout const & layout =
998 textclasslist.Style(params.textclass,
1001 if (layout.free_spacing) {
1002 par->InsertChar(pos, ' ', font);
1004 Inset * inset = new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
1005 par->InsertInset(pos, inset, font);
1008 } else if (token == "\\bibitem") { // ale970302
1010 par->bibkey = new InsetBibKey;
1011 par->bibkey->Read(this, lex);
1012 }else if (token == "\\backslash") {
1013 par->InsertChar(pos, '\\', font);
1015 }else if (token == "\\the_end") {
1016 the_end_read = true;
1018 // This should be insurance for the future: (Asger)
1019 lex.printError("Unknown token `$$Token'. "
1020 "Inserting as text.");
1021 for(string::const_iterator cit = token.begin();
1022 cit != token.end(); ++cit) {
1023 par->InsertChar(pos, (*cit), font);
1027 return the_end_read;
1030 bool Buffer::readFile(LyXLex & lex, LyXParagraph * par)
1036 token = lex.GetString();
1037 if (token == "\\lyxformat") { // the first token _must_ be...
1039 format = lex.GetFloat();
1041 if (LYX_FORMAT - format > 0.05) {
1042 printf(_("Warning: need lyxformat %.2f but found %.2f\n"),
1043 LYX_FORMAT, format);
1045 if (format - LYX_FORMAT > 0.05) {
1046 printf(_("ERROR: need lyxformat %.2f but found %.2f\n"),
1047 LYX_FORMAT, format);
1049 bool the_end = readLyXformat2(lex, par);
1050 // Formats >= 2.13 support "\the_end" marker
1057 WriteAlert(_("Warning!"),
1058 _("Reading of document is not complete"),
1059 _("Maybe the document is truncated"));
1060 // We simulate a safe reading anyways to allow
1061 // users to take the chance... (Asger)
1065 WriteAlert(_("ERROR!"),
1066 _("Old LyX file format found. "
1067 "Use LyX 0.10.x to read this!"));
1071 } else { // "\\lyxformat" not found
1072 WriteAlert(_("ERROR!"), _("Not a LyX file!"));
1075 WriteAlert(_("ERROR!"), _("Unable to read file!"));
1081 // Should probably be moved to somewhere else: BufferView? LyXView?
1082 bool Buffer::save() const
1084 // We don't need autosaves in the immediate future. (Asger)
1085 resetAutosaveTimers();
1089 if (lyxrc.make_backup) {
1090 s = fileName() + '~';
1091 if (!lyxrc.backupdir_path.empty())
1092 s = AddName(lyxrc.backupdir_path,
1093 subst(CleanupPath(s),'/','!'));
1095 // Rename is the wrong way of making a backup,
1096 // this is the correct way.
1097 /* truss cp fil fil2:
1098 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
1099 stat("LyXVC.lyx", 0xEFFFF688) = 0
1100 open("LyXVC.lyx", O_RDONLY) = 3
1101 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
1102 fstat(4, 0xEFFFF508) = 0
1103 fstat(3, 0xEFFFF508) = 0
1104 read(3, " # T h i s f i l e w".., 8192) = 5579
1105 write(4, " # T h i s f i l e w".., 5579) = 5579
1106 read(3, 0xEFFFD4A0, 8192) = 0
1109 chmod("LyXVC3.lyx", 0100644) = 0
1110 lseek(0, 0, SEEK_CUR) = 46440
1114 // Should proabaly have some more error checking here.
1115 // Should be cleaned up in 0.13, at least a bit.
1116 // Doing it this way, also makes the inodes stay the same.
1117 // This is still not a very good solution, in particular we
1118 // might loose the owner of the backup.
1119 FileInfo finfo(fileName());
1120 if (finfo.exist()) {
1121 mode_t fmode = finfo.getMode();
1122 struct utimbuf times = {
1123 finfo.getAccessTime(),
1124 finfo.getModificationTime() };
1126 ifstream ifs(fileName().c_str());
1127 ofstream ofs(s.c_str(), ios::out|ios::trunc);
1132 ::chmod(s.c_str(), fmode);
1134 if (::utime(s.c_str(), ×)) {
1135 lyxerr << "utime error." << endl;
1138 lyxerr << "LyX was not able to make "
1139 "backupcopy. Beware." << endl;
1144 if (writeFile(fileName(), false)) {
1147 // now delete the autosavefile
1148 string a = OnlyPath(fileName());
1150 a += OnlyFilename(fileName());
1152 FileInfo fileinfo(a);
1153 if (fileinfo.exist()) {
1154 if (::remove(a.c_str()) != 0) {
1155 WriteFSAlert(_("Could not delete "
1156 "auto-save file!"), a);
1160 // Saving failed, so backup is not backup
1161 if (lyxrc.make_backup) {
1162 ::rename(s.c_str(), fileName().c_str());
1170 // Returns false if unsuccesful
1171 bool Buffer::writeFile(string const & fname, bool flag) const
1173 // if flag is false writeFile will not create any GUI
1174 // warnings, only cerr.
1175 // Needed for autosave in background or panic save (Matthias 120496)
1177 if (read_only && (fname == filename)) {
1178 // Here we should come with a question if we should
1179 // perform the write anyway.
1181 lyxerr << _("Error! Document is read-only: ")
1184 WriteAlert(_("Error! Document is read-only: "),
1189 FileInfo finfo(fname);
1190 if (finfo.exist() && !finfo.writable()) {
1191 // Here we should come with a question if we should
1192 // try to do the save anyway. (i.e. do a chmod first)
1194 lyxerr << _("Error! Cannot write file: ")
1197 WriteFSAlert(_("Error! Cannot write file: "),
1202 ofstream ofs(fname.c_str());
1205 lyxerr << _("Error! Cannot open file: ")
1208 WriteFSAlert(_("Error! Cannot open file: "),
1212 // The top of the file should not be written by params.
1214 // write out a comment in the top of the file
1215 ofs << '#' << LYX_DOCVERSION
1216 << " created this file. For more info see http://www.lyx.org/\n";
1217 ofs.setf(ios::showpoint|ios::fixed);
1219 ofs << "\\lyxformat " << setw(4) << LYX_FORMAT << "\n";
1221 // now write out the buffer paramters.
1222 params.writeFile(ofs);
1224 char footnoteflag = 0;
1227 // this will write out all the paragraphs
1228 // using recursive descent.
1229 paragraph->writeFile(this, ofs, params, footnoteflag, depth);
1231 // Write marker that shows file is complete
1232 ofs << "\n\\the_end" << endl;
1234 // how to check if close went ok?
1239 void Buffer::writeFileAscii(string const & fname, int linelen)
1241 LyXFont font1, font2;
1243 char c, footnoteflag = 0, depth = 0;
1245 LyXParagraph::size_type i;
1246 int j, h, ltype = 0, ltype_depth = 0,
1247 * clen = 0, actcell = 0, actpos = 0, cell = 0, cells = 0,
1250 bool ref_printed = false;
1252 ofstream ofs(fname.c_str());
1254 WriteFSAlert(_("Error: Cannot write file:"), fname);
1258 string fname1 = TmpFileName();
1259 LyXParagraph * par = paragraph;
1263 if (par->footnoteflag != LyXParagraph::NO_FOOTNOTE ||
1265 par->previous->footnoteflag == LyXParagraph::NO_FOOTNOTE){
1267 /* begins a footnote environment ? */
1268 if (footnoteflag != par->footnoteflag) {
1269 footnoteflag = par->footnoteflag;
1271 j = strlen(string_footnotekinds[par->footnotekind])+4;
1272 if (currlinelen + j > linelen)
1275 << string_footnotekinds[par->footnotekind] << "] ";
1280 /* begins or ends a deeper area ?*/
1281 if (depth != par->depth) {
1282 if (par->depth > depth) {
1283 while (par->depth > depth) {
1288 while (par->depth < depth) {
1294 /* First write the layout */
1295 tmp = textclasslist.NameOfLayout(params.textclass, par->layout);
1296 if (tmp == "Itemize") {
1298 ltype_depth = depth+1;
1299 } else if (tmp == "Enumerate") {
1301 ltype_depth = depth+1;
1302 } else if (strstr(tmp.c_str(), "ection")) {
1304 ltype_depth = depth+1;
1305 } else if (strstr(tmp.c_str(), "aragraph")) {
1307 ltype_depth = depth+1;
1308 } else if (tmp == "Description") {
1310 ltype_depth = depth+1;
1311 } else if (tmp == "Abstract") {
1314 } else if (tmp == "Bibliography") {
1322 /* maybe some vertical spaces */
1324 /* the labelwidthstring used in lists */
1328 /* some pagebreaks? */
1332 /* what about the alignment */
1334 /* dummy layout, that means a footnote ended */
1335 footnoteflag = LyXParagraph::NO_FOOTNOTE;
1340 //LyXLayout const & layout =
1341 // textclasslist.Style(params.textclass,
1342 // par->GetLayout()); // unused
1343 //bool free_spc = layout.free_spacing; //unused
1346 /* It might be a table */
1350 cells = par->table->columns;
1351 clen = new int [cells];
1352 memset(clen, 0, sizeof(int) * cells);
1354 for (i = 0, j = 0, h = 1; i < par->size(); ++i, ++h) {
1355 c = par->GetChar(i);
1356 if (c == LyXParagraph::META_INSET) {
1357 if ((inset = par->GetInset(i))) {
1359 std::ostringstream ost;
1360 inset->Ascii(this, ost);
1361 h += ost.str().length();
1364 inset->Ascii(this, ost);
1366 char * tmp = ost.str();
1372 } else if (c == LyXParagraph::META_NEWLINE) {
1376 j = (++j) % par->table->NumberOfCellsInRow(actcell);
1384 font1 = LyXFont(LyXFont::ALL_INHERIT, params.language_info);
1386 for (i = 0, actpos = 1; i < par->size(); ++i, ++actpos) {
1387 if (!i && !footnoteflag && !noparbreak){
1389 for(j = 0; j < depth; ++j)
1391 currlinelen = depth * 2;
1393 case 0: /* Standard */
1394 case 4: /* (Sub)Paragraph */
1395 case 5: /* Description */
1397 case 6: /* Abstract */
1398 ofs << "Abstract\n\n";
1400 case 7: /* Bibliography */
1402 ofs << "References\n\n";
1407 ofs << par->labelstring << " ";
1410 if (ltype_depth > depth) {
1411 for(j = ltype_depth - 1; j > depth; --j)
1413 currlinelen += (ltype_depth-depth)*2;
1417 for(j = 0; j < cells; ++j) {
1419 for(h = 0; h < (clen[j] + 1);
1424 for(j = 0; j < depth; ++j)
1426 currlinelen = depth * 2;
1427 if (ltype_depth > depth) {
1428 for(j = ltype_depth;
1431 currlinelen += (ltype_depth-depth)*2;
1437 font2 = par->GetFontSettings(params, i);
1438 if (font1.latex() != font2.latex()) {
1439 if (font2.latex() == LyXFont::OFF)
1446 c = par->GetChar(i);
1450 case LyXParagraph::META_INSET:
1451 if ((inset = par->GetInset(i))) {
1453 inset->Ascii(this, ofs);
1454 currlinelen += (ofs.tellp() - fpos);
1455 actpos += (ofs.tellp() - fpos) - 1;
1458 case LyXParagraph::META_NEWLINE:
1461 if (par->table->NumberOfCellsInRow(actcell) <= cell) {
1462 for(j = actpos; j < clen[cell - 1]; ++j)
1465 for(j = 0; j < depth; ++j)
1467 currlinelen = depth*2;
1468 if (ltype_depth > depth) {
1469 for(j = ltype_depth; j > depth; --j)
1471 currlinelen += (ltype_depth-depth) * 2;
1473 for(j = 0; j < cells; ++j) {
1475 for(h = 0; h < (clen[j] + 1); ++h)
1479 for(j = 0; j < depth; ++j)
1481 currlinelen = depth * 2;
1482 if (ltype_depth > depth) {
1483 for(j = ltype_depth;
1486 currlinelen += (ltype_depth-depth)*2;
1492 j < clen[cell - 1]; ++j)
1498 currlinelen = actpos = 0;
1502 for(j = 0; j < depth; ++j)
1504 currlinelen = depth * 2;
1505 if (ltype_depth > depth) {
1506 for(j = ltype_depth;
1509 currlinelen += (ltype_depth - depth) * 2;
1515 case LyXParagraph::META_HFILL:
1522 if (currlinelen > linelen - 10
1523 && c == ' ' && i + 2 < par->size()) {
1525 for(j = 0; j < depth; ++j)
1527 currlinelen = depth * 2;
1528 if (ltype_depth > depth) {
1529 for(j = ltype_depth;
1532 currlinelen += (ltype_depth-depth)*2;
1534 } else if (c != '\0')
1537 lyxerr.debug() << "writeAsciiFile: NULL char in structure." << endl;
1544 for(j = actpos; j < clen[cell - 1]; ++j)
1547 for(j = 0; j < depth; ++j)
1549 currlinelen = depth * 2;
1550 if (ltype_depth > depth) {
1551 for(j = ltype_depth; j > depth; --j)
1553 currlinelen += (ltype_depth - depth) * 2;
1555 for(j = 0; j < cells; ++j) {
1557 for(h = 0; h < (clen[j] + 1); ++h)
1571 void Buffer::makeLaTeXFile(string const & fname,
1572 string const & original_path,
1573 bool nice, bool only_body)
1575 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
1577 niceFile = nice; // this will be used by Insetincludes.
1579 tex_code_break_column = lyxrc.ascii_linelen;
1581 LyXTextClass const & tclass =
1582 textclasslist.TextClass(params.textclass);
1584 ofstream ofs(fname.c_str());
1586 WriteFSAlert(_("Error: Cannot open file: "), fname);
1590 // validate the buffer.
1591 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
1592 LaTeXFeatures features(params, tclass.numLayouts());
1594 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
1597 // The starting paragraph of the coming rows is the
1598 // first paragraph of the document. (Asger)
1599 texrow.start(paragraph, 0);
1601 if (!only_body && nice) {
1602 ofs << "%% " LYX_DOCVERSION " created this file. "
1603 "For more info, see http://www.lyx.org/.\n"
1604 "%% Do not edit unless you really know what "
1609 lyxerr.debug() << "lyx header finished" << endl;
1610 // There are a few differences between nice LaTeX and usual files:
1611 // usual is \batchmode and has a
1612 // special input@path to allow the including of figures
1613 // with either \input or \includegraphics (what figinsets do).
1614 // batchmode is not set if there is a tex_code_break_column.
1615 // In this case somebody is interested in the generated LaTeX,
1616 // so this is OK. input@path is set when the actual parameter
1617 // original_path is set. This is done for usual tex-file, but not
1618 // for nice-latex-file. (Matthias 250696)
1621 // code for usual, NOT nice-latex-file
1622 ofs << "\\batchmode\n"; // changed
1623 // from \nonstopmode
1626 if (!original_path.empty()) {
1627 ofs << "\\makeatletter\n"
1628 << "\\def\\input@path{{"
1629 << original_path << "/}}\n"
1630 << "\\makeatother\n";
1636 ofs << "\\documentclass";
1638 string options; // the document class options.
1640 if (tokenPos(tclass.opt_fontsize(),
1641 '|', params.fontsize) >= 0) {
1642 // only write if existing in list (and not default)
1643 options += params.fontsize;
1648 if (!params.use_geometry &&
1649 (params.paperpackage == BufferParams::PACKAGE_NONE)) {
1650 switch (params.papersize) {
1651 case BufferParams::PAPER_A4PAPER:
1652 options += "a4paper,";
1654 case BufferParams::PAPER_USLETTER:
1655 options += "letterpaper,";
1657 case BufferParams::PAPER_A5PAPER:
1658 options += "a5paper,";
1660 case BufferParams::PAPER_B5PAPER:
1661 options += "b5paper,";
1663 case BufferParams::PAPER_EXECUTIVEPAPER:
1664 options += "executivepaper,";
1666 case BufferParams::PAPER_LEGALPAPER:
1667 options += "legalpaper,";
1673 if (params.sides != tclass.sides()) {
1674 switch (params.sides) {
1675 case LyXTextClass::OneSide:
1676 options += "oneside,";
1678 case LyXTextClass::TwoSides:
1679 options += "twoside,";
1686 if (params.columns != tclass.columns()) {
1687 if (params.columns == 2)
1688 options += "twocolumn,";
1690 options += "onecolumn,";
1693 if (!params.use_geometry
1694 && params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1695 options += "landscape,";
1697 // language should be a parameter to \documentclass
1698 bool use_babel = false;
1699 if (params.language_info->lang() == "hebrew") // This seems necessary
1700 features.UsedLanguages.insert(default_language);
1701 if (params.language != "default" ||
1702 !features.UsedLanguages.empty() ) {
1704 for (LaTeXFeatures::LanguageList::const_iterator cit =
1705 features.UsedLanguages.begin();
1706 cit != features.UsedLanguages.end(); ++cit)
1707 options += (*cit)->lang() + ",";
1708 options += params.language_info->lang() + ',';
1711 // the user-defined options
1712 if (!params.options.empty()) {
1713 options += params.options + ',';
1716 if (!options.empty()){
1717 options = strip(options, ',');
1718 ofs << '[' << options << ']';
1722 << textclasslist.LatexnameOfClass(params.textclass)
1725 // end of \documentclass defs
1727 // font selection must be done before loading fontenc.sty
1728 if (params.fonts != "default") {
1729 ofs << "\\usepackage{" << params.fonts << "}\n";
1732 // this one is not per buffer
1733 if (lyxrc.fontenc != "default") {
1734 ofs << "\\usepackage[" << lyxrc.fontenc
1739 if (params.inputenc == "auto") {
1740 string doc_encoding =
1741 params.language_info->encoding()->LatexName();
1743 // Create a list with all the input encodings used
1745 set<string> encodings;
1746 for (LaTeXFeatures::LanguageList::const_iterator it =
1747 features.UsedLanguages.begin();
1748 it != features.UsedLanguages.end(); ++it)
1749 if ((*it)->encoding()->LatexName() != doc_encoding)
1750 encodings.insert((*it)->encoding()->LatexName());
1752 ofs << "\\usepackage[";
1753 for (set<string>::const_iterator it = encodings.begin();
1754 it != encodings.end(); ++it)
1756 ofs << doc_encoding << "]{inputenc}\n";
1758 } else if (params.inputenc != "default") {
1759 ofs << "\\usepackage[" << params.inputenc
1764 // At the very beginning the text parameters.
1765 if (params.paperpackage != BufferParams::PACKAGE_NONE) {
1766 switch (params.paperpackage) {
1767 case BufferParams::PACKAGE_A4:
1768 ofs << "\\usepackage{a4}\n";
1771 case BufferParams::PACKAGE_A4WIDE:
1772 ofs << "\\usepackage{a4wide}\n";
1775 case BufferParams::PACKAGE_WIDEMARGINSA4:
1776 ofs << "\\usepackage[widemargins]{a4}\n";
1781 if (params.use_geometry) {
1782 ofs << "\\usepackage{geometry}\n";
1784 ofs << "\\geometry{verbose";
1785 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1786 ofs << ",landscape";
1787 switch (params.papersize2) {
1788 case BufferParams::VM_PAPER_CUSTOM:
1789 if (!params.paperwidth.empty())
1790 ofs << ",paperwidth="
1791 << params.paperwidth;
1792 if (!params.paperheight.empty())
1793 ofs << ",paperheight="
1794 << params.paperheight;
1796 case BufferParams::VM_PAPER_USLETTER:
1797 ofs << ",letterpaper";
1799 case BufferParams::VM_PAPER_USLEGAL:
1800 ofs << ",legalpaper";
1802 case BufferParams::VM_PAPER_USEXECUTIVE:
1803 ofs << ",executivepaper";
1805 case BufferParams::VM_PAPER_A3:
1808 case BufferParams::VM_PAPER_A4:
1811 case BufferParams::VM_PAPER_A5:
1814 case BufferParams::VM_PAPER_B3:
1817 case BufferParams::VM_PAPER_B4:
1820 case BufferParams::VM_PAPER_B5:
1824 // default papersize ie BufferParams::VM_PAPER_DEFAULT
1825 switch (lyxrc.default_papersize) {
1826 case BufferParams::PAPER_DEFAULT: // keep compiler happy
1827 case BufferParams::PAPER_USLETTER:
1828 ofs << ",letterpaper";
1830 case BufferParams::PAPER_LEGALPAPER:
1831 ofs << ",legalpaper";
1833 case BufferParams::PAPER_EXECUTIVEPAPER:
1834 ofs << ",executivepaper";
1836 case BufferParams::PAPER_A3PAPER:
1839 case BufferParams::PAPER_A4PAPER:
1842 case BufferParams::PAPER_A5PAPER:
1845 case BufferParams::PAPER_B5PAPER:
1850 if (!params.topmargin.empty())
1851 ofs << ",tmargin=" << params.topmargin;
1852 if (!params.bottommargin.empty())
1853 ofs << ",bmargin=" << params.bottommargin;
1854 if (!params.leftmargin.empty())
1855 ofs << ",lmargin=" << params.leftmargin;
1856 if (!params.rightmargin.empty())
1857 ofs << ",rmargin=" << params.rightmargin;
1858 if (!params.headheight.empty())
1859 ofs << ",headheight=" << params.headheight;
1860 if (!params.headsep.empty())
1861 ofs << ",headsep=" << params.headsep;
1862 if (!params.footskip.empty())
1863 ofs << ",footskip=" << params.footskip;
1867 if (params.use_amsmath
1868 && !tclass.provides(LyXTextClass::amsmath)) {
1869 ofs << "\\usepackage{amsmath}\n";
1873 if (tokenPos(tclass.opt_pagestyle(),
1874 '|', params.pagestyle) >= 0) {
1875 if (params.pagestyle == "fancy") {
1876 ofs << "\\usepackage{fancyhdr}\n";
1879 ofs << "\\pagestyle{" << params.pagestyle << "}\n";
1883 // We try to load babel late, in case it interferes
1884 // with other packages.
1886 ofs << lyxrc.language_package << endl;
1890 if (params.secnumdepth != tclass.secnumdepth()) {
1891 ofs << "\\setcounter{secnumdepth}{"
1892 << params.secnumdepth
1896 if (params.tocdepth != tclass.tocdepth()) {
1897 ofs << "\\setcounter{tocdepth}{"
1903 if (params.paragraph_separation) {
1904 switch (params.defskip.kind()) {
1905 case VSpace::SMALLSKIP:
1906 ofs << "\\setlength\\parskip{\\smallskipamount}\n";
1908 case VSpace::MEDSKIP:
1909 ofs << "\\setlength\\parskip{\\medskipamount}\n";
1911 case VSpace::BIGSKIP:
1912 ofs << "\\setlength\\parskip{\\bigskipamount}\n";
1914 case VSpace::LENGTH:
1915 ofs << "\\setlength\\parskip{"
1916 << params.defskip.length().asLatexString()
1919 default: // should never happen // Then delete it.
1920 ofs << "\\setlength\\parskip{\\medskipamount}\n";
1925 ofs << "\\setlength\\parindent{0pt}\n";
1929 // Now insert the LyX specific LaTeX commands...
1931 // The optional packages;
1932 string preamble(features.getPackages());
1934 // this might be useful...
1935 preamble += "\n\\makeatletter\n";
1937 // Some macros LyX will need
1938 string tmppreamble(features.getMacros());
1940 if (!tmppreamble.empty()) {
1941 preamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1942 "LyX specific LaTeX commands.\n"
1943 + tmppreamble + '\n';
1946 // the text class specific preamble
1947 tmppreamble = features.getTClassPreamble();
1948 if (!tmppreamble.empty()) {
1949 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1950 "Textclass specific LaTeX commands.\n"
1951 + tmppreamble + '\n';
1954 /* the user-defined preamble */
1955 if (!params.preamble.empty()) {
1956 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1957 "User specified LaTeX commands.\n"
1958 + params.preamble + '\n';
1961 preamble += "\\makeatother\n";
1963 // Itemize bullet settings need to be last in case the user
1964 // defines their own bullets that use a package included
1965 // in the user-defined preamble -- ARRae
1966 // Actually it has to be done much later than that
1967 // since some packages like frenchb make modifications
1968 // at \begin{document} time -- JMarc
1970 for (int i = 0; i < 4; ++i) {
1971 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
1972 if (bullets_def.empty())
1973 bullets_def="\\AtBeginDocument{\n";
1974 bullets_def += " \\renewcommand{\\labelitemi";
1976 // `i' is one less than the item to modify
1983 bullets_def += "ii";
1989 bullets_def += "}{" +
1990 params.user_defined_bullets[i].getText()
1995 if (!bullets_def.empty())
1996 preamble += bullets_def + "}\n\n";
1998 for (int j = countChar(preamble, '\n'); j-- ;) {
2005 ofs << "\\begin{document}\n";
2008 lyxerr.debug() << "preamble finished, now the body." << endl;
2009 if (!lyxrc.language_auto_begin && params.language != "default") {
2010 ofs << subst(lyxrc.language_command_begin, "$$lang",
2016 latexParagraphs(ofs, paragraph, 0, texrow);
2018 // add this just in case after all the paragraphs
2022 if (!lyxrc.language_auto_end && params.language != "default") {
2023 ofs << subst(lyxrc.language_command_end, "$$lang",
2030 ofs << "\\end{document}\n";
2033 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
2035 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
2039 // Just to be sure. (Asger)
2042 // tex_code_break_column's value is used to decide
2043 // if we are in batchmode or not (within mathed_write()
2044 // in math_write.C) so we must set it to a non-zero
2045 // value when we leave otherwise we save incorrect .lyx files.
2046 tex_code_break_column = lyxrc.ascii_linelen;
2050 lyxerr << "File was not closed properly." << endl;
2053 lyxerr.debug() << "Finished making latex file." << endl;
2058 // LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
2060 void Buffer::latexParagraphs(ostream & ofs, LyXParagraph * par,
2061 LyXParagraph * endpar, TexRow & texrow) const
2063 bool was_title = false;
2064 bool already_title = false;
2066 std::ostringstream ftnote;
2068 char * tmpholder = 0;
2074 while (par != endpar) {
2075 #ifndef HAVE_SSTREAM
2078 ftnote << tmpholder;
2079 delete [] tmpholder;
2084 lyxerr[Debug::LATEX] << "Error in latexParagraphs."
2086 LyXLayout const & layout =
2087 textclasslist.Style(params.textclass,
2090 if (layout.intitle) {
2091 if (already_title) {
2092 lyxerr <<"Error in latexParagraphs: You"
2093 " should not mix title layouts"
2094 " with normal ones." << endl;
2097 } else if (was_title && !already_title) {
2098 ofs << "\\maketitle\n";
2100 already_title = true;
2103 // We are at depth 0 so we can just use
2104 // ordinary \footnote{} generation
2105 // flag this with ftcount
2107 if (layout.isEnvironment()
2108 || par->pextra_type != LyXParagraph::PEXTRA_NONE) {
2109 par = par->TeXEnvironment(this, params, ofs, texrow,
2110 ftnote, ft_texrow, ftcount);
2112 par = par->TeXOnePar(this, params, ofs, texrow, false,
2113 ftnote, ft_texrow, ftcount);
2116 // Write out what we've generated...
2119 ofs << "\\addtocounter{footnote}{-"
2123 ofs << ftnote.str();
2124 texrow += ft_texrow;
2126 // The extra .c_str() is needed when we use
2127 // lyxstring instead of the STL string class.
2128 ftnote.str(string().c_str());
2130 delete [] ftnote.str();
2135 #ifndef HAVE_SSTREAM
2137 // I hate strstreams
2138 tmpholder = ftnote.str();
2142 #ifndef HAVE_SSTREAM
2143 delete [] tmpholder;
2145 // It might be that we only have a title in this document
2146 if (was_title && !already_title) {
2147 ofs << "\\maketitle\n";
2153 bool Buffer::isLatex() const
2155 return textclasslist.TextClass(params.textclass).outputType() == LATEX;
2159 bool Buffer::isLinuxDoc() const
2161 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC;
2165 bool Buffer::isLiterate() const
2167 return textclasslist.TextClass(params.textclass).outputType() == LITERATE;
2171 bool Buffer::isDocBook() const
2173 return textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2177 bool Buffer::isSGML() const
2179 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC ||
2180 textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2184 void Buffer::sgmlOpenTag(ostream & os, int depth,
2185 string const & latexname) const
2187 os << string(depth, ' ') << "<" << latexname << ">\n";
2191 void Buffer::sgmlCloseTag(ostream & os, int depth,
2192 string const & latexname) const
2194 os << string(depth, ' ') << "</" << latexname << ">\n";
2198 void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
2200 LyXParagraph * par = paragraph;
2202 niceFile = nice; // this will be used by Insetincludes.
2204 string top_element = textclasslist.LatexnameOfClass(params.textclass);
2205 string environment_stack[10];
2208 int depth = 0; // paragraph depth
2210 ofstream ofs(fname.c_str());
2213 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2217 LyXTextClass const & tclass =
2218 textclasslist.TextClass(params.textclass);
2220 LaTeXFeatures features(params, tclass.numLayouts());
2224 tex_code_break_column = lyxrc.ascii_linelen;
2226 //tex_code_break_column = 0;
2231 string sgml_includedfiles=features.getIncludedFiles();
2233 if (params.preamble.empty() && sgml_includedfiles.empty()) {
2234 ofs << "<!doctype linuxdoc system>\n\n";
2236 ofs << "<!doctype linuxdoc system [ "
2237 << params.preamble << sgml_includedfiles << " \n]>\n\n";
2240 if(params.options.empty())
2241 sgmlOpenTag(ofs, 0, top_element);
2243 string top = top_element;
2245 top += params.options;
2246 sgmlOpenTag(ofs, 0, top);
2250 ofs << "<!-- " << LYX_DOCVERSION
2251 << " created this file. For more info see http://www.lyx.org/"
2255 int desc_on = 0; // description mode
2256 LyXLayout const & style =
2257 textclasslist.Style(params.textclass,
2260 // treat <toc> as a special case for compatibility with old code
2261 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2262 Inset * inset = par->GetInset(0);
2263 Inset::Code lyx_code = inset->LyxCode();
2264 if (lyx_code == Inset::TOC_CODE){
2265 string temp = "toc";
2266 sgmlOpenTag(ofs, depth, temp);
2269 linuxDocHandleFootnote(ofs, par, depth);
2274 // environment tag closing
2275 for( ; depth > par->depth; --depth) {
2276 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2277 environment_stack[depth].erase();
2280 // write opening SGML tags
2281 switch(style.latextype) {
2282 case LATEX_PARAGRAPH:
2283 if(depth == par->depth
2284 && !environment_stack[depth].empty()) {
2285 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2286 environment_stack[depth].erase();
2292 sgmlOpenTag(ofs, depth, style.latexname());
2297 LinuxDocError(par, 0,
2298 _("Error : Wrong depth for"
2299 " LatexType Command.\n"));
2301 if (!environment_stack[depth].empty()){
2302 sgmlCloseTag(ofs, depth,
2303 environment_stack[depth]);
2307 environment_stack[depth].erase();
2308 sgmlOpenTag(ofs, depth, style.latexname());
2311 case LATEX_ENVIRONMENT:
2312 case LATEX_ITEM_ENVIRONMENT:
2313 if(depth == par->depth
2314 && environment_stack[depth] != style.latexname()
2315 && !environment_stack[depth].empty()) {
2317 sgmlCloseTag(ofs, depth,
2318 environment_stack[depth]);
2319 environment_stack[depth].erase();
2321 if (depth < par->depth) {
2323 environment_stack[depth].erase();
2325 if (environment_stack[depth] != style.latexname()) {
2328 sgmlOpenTag(ofs, depth, temp);
2330 environment_stack[depth] = style.latexname();
2331 sgmlOpenTag(ofs, depth,
2332 environment_stack[depth]);
2334 if(style.latextype == LATEX_ENVIRONMENT) break;
2336 desc_on = (style.labeltype == LABEL_MANUAL);
2343 sgmlOpenTag(ofs, depth + 1, item_name);
2346 sgmlOpenTag(ofs, depth, style.latexname());
2351 SimpleLinuxDocOnePar(ofs, par, desc_on, depth);
2354 linuxDocHandleFootnote(ofs, par, depth);
2356 while(par && par->IsDummy());
2359 // write closing SGML tags
2360 switch(style.latextype) {
2362 case LATEX_ENVIRONMENT:
2363 case LATEX_ITEM_ENVIRONMENT:
2366 sgmlCloseTag(ofs, depth, style.latexname());
2372 for(; depth > 0; --depth)
2373 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2375 if(!environment_stack[depth].empty())
2376 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2380 sgmlCloseTag(ofs, 0, top_element);
2384 // How to check for successful close
2388 void Buffer::linuxDocHandleFootnote(ostream & os, LyXParagraph * & par,
2391 string tag = "footnote";
2393 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2394 sgmlOpenTag(os, depth + 1, tag);
2395 SimpleLinuxDocOnePar(os, par, 0, depth + 1);
2396 sgmlCloseTag(os, depth + 1, tag);
2402 void Buffer::DocBookHandleCaption(ostream & os, string & inner_tag,
2403 int const depth, int desc_on,
2404 LyXParagraph * & par)
2406 LyXParagraph * tpar = par;
2407 while (tpar && (tpar->footnoteflag != LyXParagraph::NO_FOOTNOTE) &&
2408 (tpar->layout != textclasslist.NumberOfLayout(params.textclass,
2412 tpar->layout == textclasslist.NumberOfLayout(params.textclass,
2413 "Caption").second) {
2414 sgmlOpenTag(os, depth + 1, inner_tag);
2416 SimpleDocBookOnePar(os, extra_par, tpar,
2417 desc_on, depth + 2);
2418 sgmlCloseTag(os, depth+1, inner_tag);
2419 if(!extra_par.empty())
2425 void Buffer::DocBookHandleFootnote(ostream & os, LyXParagraph * & par,
2428 string tag, inner_tag;
2429 string tmp_par, extra_par;
2430 bool inner_span = false;
2433 // Someone should give this enum a proper name (Lgb)
2441 SOME_ENUM last = NO_ONE;
2442 SOME_ENUM present = FOOTNOTE_LIKE;
2444 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2445 if(last == present) {
2447 if(!tmp_par.empty()) {
2450 sgmlCloseTag(os, depth + 1, inner_tag);
2451 sgmlOpenTag(os, depth + 1, inner_tag);
2458 if(!inner_tag.empty()) sgmlCloseTag(os, depth + 1,
2460 if(!extra_par.empty()) os << extra_par;
2461 if(!tag.empty()) sgmlCloseTag(os, depth, tag);
2464 switch (par->footnotekind) {
2465 case LyXParagraph::FOOTNOTE:
2466 case LyXParagraph::ALGORITHM:
2469 present = FOOTNOTE_LIKE;
2472 case LyXParagraph::MARGIN:
2475 present = MARGIN_LIKE;
2478 case LyXParagraph::FIG:
2479 case LyXParagraph::WIDE_FIG:
2481 inner_tag = "title";
2485 case LyXParagraph::TAB:
2486 case LyXParagraph::WIDE_TAB:
2488 inner_tag = "title";
2493 sgmlOpenTag(os, depth, tag);
2494 if ((present == TAB_LIKE) || (present == FIG_LIKE)) {
2495 DocBookHandleCaption(os, inner_tag, depth,
2499 sgmlOpenTag(os, depth + 1, inner_tag);
2502 // ignore all caption here, we processed them above!!!
2503 if (par->layout != textclasslist
2504 .NumberOfLayout(params.textclass,
2505 "Caption").second) {
2507 std::ostringstream ost;
2511 SimpleDocBookOnePar(ost, extra_par, par,
2512 desc_on, depth + 2);
2514 tmp_par += ost.str().c_str();
2517 char * ctmp = ost.str();
2522 tmp_par = frontStrip(strip(tmp_par));
2528 if(!inner_tag.empty()) sgmlCloseTag(os, depth + 1, inner_tag);
2529 if(!extra_par.empty()) os << extra_par;
2530 if(!tag.empty()) sgmlCloseTag(os, depth, tag);
2534 // push a tag in a style stack
2535 void Buffer::push_tag(ostream & os, char const * tag,
2536 int & pos, char stack[5][3])
2538 // pop all previous tags
2539 for (int j = pos; j >= 0; --j)
2540 os << "</" << stack[j] << ">";
2543 sprintf(stack[++pos], "%s", tag);
2546 for (int i = 0; i <= pos; ++i)
2547 os << "<" << stack[i] << ">";
2551 void Buffer::pop_tag(ostream & os, char const * tag,
2552 int & pos, char stack[5][3])
2556 // pop all tags till specified one
2557 for (j = pos; (j >= 0) && (strcmp(stack[j], tag)); --j)
2558 os << "</" << stack[j] << ">";
2561 os << "</" << tag << ">";
2563 // push all tags, but the specified one
2564 for (j = j + 1; j <= pos; ++j) {
2565 os << "<" << stack[j] << ">";
2566 strcpy(stack[j-1], stack[j]);
2572 // Handle internal paragraph parsing -- layout already processed.
2574 // checks, if newcol chars should be put into this line
2575 // writes newline, if necessary.
2577 void linux_doc_line_break(ostream & os, unsigned int & colcount,
2578 const unsigned int newcol)
2581 if (colcount > lyxrc.ascii_linelen) {
2583 colcount = newcol; // assume write after this call
2588 void Buffer::SimpleLinuxDocOnePar(ostream & os, LyXParagraph * par,
2589 int desc_on, int const /*depth*/)
2591 LyXFont font1, font2;
2594 LyXParagraph::size_type main_body;
2596 LyXLayout const & style = textclasslist.Style(params.textclass,
2599 char family_type = 0; // family font flag
2600 bool is_bold = false; // series font flag
2601 char shape_type = 0; // shape font flag
2602 bool is_em = false; // emphasis (italic) font flag
2604 int stack_num = -1; // style stack position
2605 // Can this be rewritten to use a std::stack, please. (Lgb)
2606 char stack[5][3]; // style stack
2607 unsigned int char_line_count = 5; // Heuristic choice ;-)
2609 if (style.labeltype != LABEL_MANUAL)
2612 main_body = par->BeginningOfMainBody();
2614 // gets paragraph main font
2616 font1 = style.labelfont;
2621 // parsing main loop
2622 for (LyXParagraph::size_type i = 0;
2623 i < par->size(); ++i) {
2626 if (i == main_body && !par->IsDummy()) {
2631 font2 = par->getFont(params, i);
2633 if (font1.family() != font2.family()) {
2634 switch(family_type) {
2636 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2637 push_tag(os, "tt", stack_num, stack);
2640 else if (font2.family() == LyXFont::SANS_FAMILY) {
2641 push_tag(os, "sf", stack_num, stack);
2646 pop_tag(os, "tt", stack_num, stack);
2647 if (font2.family() == LyXFont::SANS_FAMILY) {
2648 push_tag(os, "sf", stack_num, stack);
2655 pop_tag(os, "sf", stack_num, stack);
2656 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2657 push_tag(os, "tt", stack_num, stack);
2666 if (font1.series() != font2.series()) {
2667 if (font2.series() == LyXFont::BOLD_SERIES) {
2668 push_tag(os, "bf", stack_num, stack);
2670 } else if (is_bold) {
2671 pop_tag(os, "bf", stack_num, stack);
2676 // handle italic and slanted fonts
2677 if (font1.shape() != font2.shape()) {
2678 switch(shape_type) {
2680 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2681 push_tag(os, "it", stack_num, stack);
2683 } else if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2684 push_tag(os, "sl", stack_num, stack);
2689 pop_tag(os, "it", stack_num, stack);
2690 if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2691 push_tag(os, "sl", stack_num, stack);
2698 pop_tag(os, "sl", stack_num, stack);
2699 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2700 push_tag(os, "it", stack_num, stack);
2708 if (font1.emph() != font2.emph()) {
2709 if (font2.emph() == LyXFont::ON) {
2710 push_tag(os, "em", stack_num, stack);
2713 pop_tag(os, "em", stack_num, stack);
2718 c = par->GetChar(i);
2720 if (c == LyXParagraph::META_INSET) {
2721 inset = par->GetInset(i);
2722 inset->Linuxdoc(this, os);
2725 if (font2.latex() == LyXFont::ON) {
2726 // "TeX"-Mode on == > SGML-Mode on.
2728 os << c; // see LaTeX-Generation...
2732 if (par->linuxDocConvertChar(c, sgml_string)
2733 && !style.free_spacing) { // in freespacing
2735 // non-breaking characters
2739 linux_doc_line_break(os, char_line_count, 6);
2743 linux_doc_line_break(os, char_line_count, 1);
2748 char_line_count += sgml_string.length();
2754 // needed if there is an optional argument but no contents
2755 if (main_body > 0 && main_body == par->size()) {
2759 // pop all defined Styles
2760 for (j = stack_num; j >= 0; --j) {
2761 linux_doc_line_break(os,
2763 3 + strlen(stack[j]));
2764 os << "</" << stack[j] << ">";
2767 // resets description flag correctly
2770 // <tag> not closed...
2771 linux_doc_line_break(os, char_line_count, 6);
2775 // fprintf(file, "</p>");
2781 // Print an error message.
2782 void Buffer::LinuxDocError(LyXParagraph * par, int pos,
2783 char const * message)
2785 // insert an error marker in text
2786 InsetError * new_inset = new InsetError(message);
2787 par->InsertInset(pos, new_inset);
2790 // This constant defines the maximum number of
2791 // environment layouts that can be nesteded.
2792 // The same applies for command layouts.
2793 // These values should be more than enough.
2794 // José Matos (1999/07/22)
2796 enum { MAX_NEST_LEVEL = 25};
2798 void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
2800 LyXParagraph * par = paragraph;
2802 niceFile = nice; // this will be used by Insetincludes.
2804 string top_element= textclasslist.LatexnameOfClass(params.textclass);
2805 // Please use a real stack.
2806 string environment_stack[MAX_NEST_LEVEL];
2807 string environment_inner[MAX_NEST_LEVEL];
2808 // Please use a real stack.
2809 string command_stack[MAX_NEST_LEVEL];
2810 bool command_flag= false;
2811 int command_depth= 0, command_base= 0, cmd_depth= 0;
2813 string item_name, command_name;
2814 string c_depth, c_params, tmps;
2816 int depth = 0; // paragraph depth
2817 LyXTextClass const & tclass =
2818 textclasslist.TextClass(params.textclass);
2820 LaTeXFeatures features(params, tclass.numLayouts());
2824 tex_code_break_column = lyxrc.ascii_linelen;
2826 //tex_code_break_column = 0;
2828 ofstream ofs(fname.c_str());
2830 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2837 string sgml_includedfiles=features.getIncludedFiles();
2839 ofs << "<!doctype " << top_element
2840 << " public \"-//OASIS//DTD DocBook V3.1//EN\"";
2842 if (params.preamble.empty() && sgml_includedfiles.empty())
2845 ofs << "\n [ " << params.preamble
2846 << sgml_includedfiles << " \n]>\n\n";
2848 if(params.options.empty())
2849 sgmlOpenTag(ofs, 0, top_element);
2851 string top = top_element;
2853 top += params.options;
2854 sgmlOpenTag(ofs, 0, top);
2858 ofs << "<!-- DocBook file was created by " << LYX_DOCVERSION
2859 << "\n See http://www.lyx.org/ for more information -->\n";
2862 int desc_on = 0; // description mode
2863 LyXLayout const & style =
2864 textclasslist.Style(params.textclass,
2867 // environment tag closing
2868 for( ; depth > par->depth; --depth) {
2869 if(environment_inner[depth] != "!-- --") {
2870 item_name= "listitem";
2871 sgmlCloseTag(ofs, command_depth + depth,
2873 if( environment_inner[depth] == "varlistentry")
2874 sgmlCloseTag(ofs, depth+command_depth,
2875 environment_inner[depth]);
2877 sgmlCloseTag(ofs, depth + command_depth,
2878 environment_stack[depth]);
2879 environment_stack[depth].erase();
2880 environment_inner[depth].erase();
2883 if(depth == par->depth
2884 && environment_stack[depth] != style.latexname()
2885 && !environment_stack[depth].empty()) {
2886 if(environment_inner[depth] != "!-- --") {
2887 item_name= "listitem";
2888 sgmlCloseTag(ofs, command_depth+depth,
2890 if( environment_inner[depth] == "varlistentry")
2892 depth + command_depth,
2893 environment_inner[depth]);
2896 sgmlCloseTag(ofs, depth + command_depth,
2897 environment_stack[depth]);
2899 environment_stack[depth].erase();
2900 environment_inner[depth].erase();
2903 // Write opening SGML tags.
2904 switch(style.latextype) {
2905 case LATEX_PARAGRAPH:
2906 if(style.latexname() != "dummy")
2907 sgmlOpenTag(ofs, depth+command_depth,
2913 LinuxDocError(par, 0,
2914 _("Error : Wrong depth for "
2915 "LatexType Command.\n"));
2917 command_name = style.latexname();
2919 tmps = style.latexparam();
2920 c_params = split(tmps, c_depth,'|');
2922 cmd_depth= atoi(c_depth.c_str());
2925 if(cmd_depth<command_base) {
2926 for(int j = command_depth;
2927 j >= command_base; --j)
2928 if(!command_stack[j].empty())
2929 sgmlCloseTag(ofs, j, command_stack[j]);
2930 command_depth= command_base= cmd_depth;
2931 } else if(cmd_depth <= command_depth) {
2932 for(int j = command_depth;
2933 j >= cmd_depth; --j)
2935 if(!command_stack[j].empty())
2936 sgmlCloseTag(ofs, j, command_stack[j]);
2937 command_depth= cmd_depth;
2939 command_depth= cmd_depth;
2941 command_depth = command_base = cmd_depth;
2942 command_flag = true;
2944 command_stack[command_depth]= command_name;
2946 // treat label as a special case for
2947 // more WYSIWYM handling.
2948 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2949 Inset * inset = par->GetInset(0);
2950 Inset::Code lyx_code = inset->LyxCode();
2951 if (lyx_code == Inset::LABEL_CODE){
2952 command_name += " id=\"";
2953 command_name += (static_cast<InsetCommand *>(inset))->getContents();
2954 command_name += "\"";
2959 sgmlOpenTag(ofs, depth + command_depth, command_name);
2960 item_name = "title";
2961 sgmlOpenTag(ofs, depth + 1 + command_depth, item_name);
2964 case LATEX_ENVIRONMENT:
2965 case LATEX_ITEM_ENVIRONMENT:
2966 if (depth < par->depth) {
2968 environment_stack[depth].erase();
2971 if (environment_stack[depth] != style.latexname()) {
2972 environment_stack[depth] = style.latexname();
2973 environment_inner[depth] = "!-- --";
2974 sgmlOpenTag(ofs, depth + command_depth,
2975 environment_stack[depth]);
2977 if(environment_inner[depth] != "!-- --") {
2978 item_name= "listitem";
2980 command_depth + depth,
2982 if (environment_inner[depth] == "varlistentry")
2984 depth + command_depth,
2985 environment_inner[depth]);
2989 if(style.latextype == LATEX_ENVIRONMENT) {
2990 if(!style.latexparam().empty())
2991 sgmlOpenTag(ofs, depth + command_depth,
2992 style.latexparam());
2996 desc_on = (style.labeltype == LABEL_MANUAL);
2999 environment_inner[depth]= "varlistentry";
3001 environment_inner[depth]= "listitem";
3003 sgmlOpenTag(ofs, depth + 1 + command_depth,
3004 environment_inner[depth]);
3008 sgmlOpenTag(ofs, depth + 1 + command_depth,
3012 sgmlOpenTag(ofs, depth + 1 + command_depth,
3017 sgmlOpenTag(ofs, depth + command_depth,
3024 SimpleDocBookOnePar(ofs, extra_par, par, desc_on,
3025 depth + 1 + command_depth);
3027 DocBookHandleFootnote(ofs, par,
3028 depth + 1 + command_depth);
3030 while(par && par->IsDummy());
3033 // write closing SGML tags
3034 switch(style.latextype) {
3037 sgmlCloseTag(ofs, depth + command_depth, end_tag);
3039 case LATEX_ENVIRONMENT:
3040 if(!style.latexparam().empty())
3041 sgmlCloseTag(ofs, depth + command_depth,
3042 style.latexparam());
3044 case LATEX_ITEM_ENVIRONMENT:
3045 if(desc_on == 1) break;
3047 sgmlCloseTag(ofs, depth + 1 + command_depth, end_tag);
3049 case LATEX_PARAGRAPH:
3050 if(style.latexname() != "dummy")
3051 sgmlCloseTag(ofs, depth + command_depth,
3055 sgmlCloseTag(ofs, depth + command_depth,
3062 for(; depth >= 0; --depth) {
3063 if(!environment_stack[depth].empty()) {
3064 if(environment_inner[depth] != "!-- --") {
3065 item_name= "listitem";
3066 sgmlCloseTag(ofs, command_depth + depth,
3068 if( environment_inner[depth] == "varlistentry")
3069 sgmlCloseTag(ofs, depth + command_depth,
3070 environment_inner[depth]);
3073 sgmlCloseTag(ofs, depth + command_depth,
3074 environment_stack[depth]);
3078 for(int j = command_depth; j >= command_base; --j)
3079 if(!command_stack[j].empty())
3080 sgmlCloseTag(ofs, j, command_stack[j]);
3084 sgmlCloseTag(ofs, 0, top_element);
3088 // How to check for successful close
3092 void Buffer::SimpleDocBookOnePar(ostream & os, string & extra,
3093 LyXParagraph * par, int & desc_on,
3098 par->SimpleDocBookOneTablePar(this,
3099 os, extra, desc_on, depth);
3104 bool emph_flag = false;
3106 LyXLayout const & style = textclasslist.Style(params.textclass,
3109 LyXParagraph::size_type main_body;
3110 if (style.labeltype != LABEL_MANUAL)
3113 main_body = par->BeginningOfMainBody();
3115 // gets paragraph main font
3116 LyXFont font1 = main_body > 0 ? style.labelfont : style.font;
3118 int char_line_count = depth;
3119 if(!style.free_spacing)
3120 for (int j = 0; j < depth; ++j)
3123 // parsing main loop
3124 for (LyXParagraph::size_type i = 0;
3125 i < par->size(); ++i) {
3126 LyXFont font2 = par->getFont(params, i);
3128 // handle <emphasis> tag
3129 if (font1.emph() != font2.emph() && i) {
3130 if (font2.emph() == LyXFont::ON) {
3134 os << "</emphasis>";
3139 char c = par->GetChar(i);
3141 if (c == LyXParagraph::META_INSET) {
3142 Inset * inset = par->GetInset(i);
3144 std::ostringstream ost;
3145 inset->DocBook(this, ost);
3146 string tmp_out = ost.str().c_str();
3149 inset->DocBook(this, ost);
3151 char * ctmp = ost.str();
3152 string tmp_out(ctmp);
3156 // This code needs some explanation:
3157 // Two insets are treated specially
3158 // label if it is the first element in a command paragraph
3160 // graphics inside tables or figure floats can't go on
3161 // title (the equivalente in latex for this case is caption
3162 // and title should come first
3165 if(desc_on!= 3 || i!= 0) {
3166 if(!tmp_out.empty() && tmp_out[0] == '@') {
3168 extra += frontStrip(tmp_out, '@');
3170 os << frontStrip(tmp_out, '@');
3175 } else if (font2.latex() == LyXFont::ON) {
3176 // "TeX"-Mode on ==> SGML-Mode on.
3182 if (par->linuxDocConvertChar(c, sgml_string)
3183 && !style.free_spacing) { // in freespacing
3185 // non-breaking characters
3189 os << "\n</term><listitem><para>";
3201 // needed if there is an optional argument but no contents
3202 if (main_body > 0 && main_body == par->size()) {
3206 os << "</emphasis>";
3209 // resets description flag correctly
3212 // <term> not closed...
3220 int Buffer::runLaTeX()
3222 if (!users->text) return 0;
3224 ProhibitInput(users);
3226 // get LaTeX-Filename
3227 string name = getLatexName();
3229 string path = OnlyPath(filename);
3231 string org_path = path;
3232 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3236 Path p(path); // path to LaTeX file
3237 users->owner()->getMiniBuffer()->Set(_("Running LaTeX..."));
3239 // Remove all error insets
3240 bool a = users->removeAutoInsets();
3242 // Always generate the LaTeX file
3243 makeLaTeXFile(name, org_path, false);
3245 // do the LaTex run(s)
3247 string latex_command = lyxrc.pdf_mode ?
3248 lyxrc.pdflatex_command : lyxrc.latex_command;
3249 LaTeX latex(latex_command, name, filepath);
3250 int res = latex.run(terr,
3251 users->owner()->getMiniBuffer()); // running latex
3253 // check return value from latex.run().
3254 if ((res & LaTeX::NO_LOGFILE)) {
3255 WriteAlert(_("LaTeX did not work!"),
3256 _("Missing log file:"), name);
3257 } else if ((res & LaTeX::ERRORS)) {
3258 users->owner()->getMiniBuffer()->Set(_("Done"));
3259 // Insert all errors as errors boxes
3260 users->insertErrors(terr);
3262 // Dvi should also be kept dirty if the latex run
3263 // ends up with errors. However it should be possible
3264 // to view a dirty dvi too.
3266 //no errors or any other things to think about so:
3267 users->owner()->getMiniBuffer()->Set(_("Done"));
3270 // if we removed error insets before we ran LaTeX or if we inserted
3271 // error insets after we ran LaTeX this must be run:
3272 if (a || (res & LaTeX::ERRORS)){
3275 //users->updateScrollbar();
3279 return latex.getNumErrors();
3283 int Buffer::runLiterate()
3285 if (!users->text) return 0;
3287 ProhibitInput(users);
3289 // get LaTeX-Filename
3290 string name = getLatexName();
3291 // get Literate-Filename
3292 string lit_name = OnlyFilename(ChangeExtension (getLatexName(),
3293 lyxrc.literate_extension));
3295 string path = OnlyPath(filename);
3297 string org_path = path;
3298 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3302 Path p(path); // path to Literate file
3303 users->owner()->getMiniBuffer()->Set(_("Running Literate..."));
3305 // Remove all error insets
3306 bool a = users->removeAutoInsets();
3308 // generate the Literate file if necessary
3309 makeLaTeXFile(lit_name, org_path, false);
3311 string latex_command = lyxrc.pdf_mode ?
3312 lyxrc.pdflatex_command : lyxrc.latex_command;
3313 Literate literate(latex_command, name, filepath,
3315 lyxrc.literate_command, lyxrc.literate_error_filter,
3316 lyxrc.build_command, lyxrc.build_error_filter);
3318 int res = literate.weave(terr, users->owner()->getMiniBuffer());
3320 // check return value from literate.weave().
3321 if ((res & Literate::NO_LOGFILE)) {
3322 WriteAlert(_("Literate command did not work!"),
3323 _("Missing log file:"), name);
3324 } else if ((res & Literate::ERRORS)) {
3325 users->owner()->getMiniBuffer()->Set(_("Done"));
3326 // Insert all errors as errors boxes
3327 users->insertErrors(terr);
3329 // Dvi should also be kept dirty if the latex run
3330 // ends up with errors. However it should be possible
3331 // to view a dirty dvi too.
3333 //no errors or any other things to think about so:
3334 users->owner()->getMiniBuffer()->Set(_("Done"));
3337 // if we removed error insets before we ran LaTeX or if we inserted
3338 // error insets after we ran LaTeX this must be run:
3339 if (a || (res & Literate::ERRORS)){
3342 //users->updateScrollbar();
3346 return literate.getNumErrors();
3350 int Buffer::buildProgram()
3352 if (!users->text) return 0;
3354 ProhibitInput(users);
3356 // get LaTeX-Filename
3357 string name = getLatexName();
3358 // get Literate-Filename
3359 string lit_name = OnlyFilename(ChangeExtension(getLatexName(),
3360 lyxrc.literate_extension));
3362 string path = OnlyPath(filename);
3364 string org_path = path;
3365 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3369 Path p(path); // path to Literate file
3370 users->owner()->getMiniBuffer()->Set(_("Building Program..."));
3372 // Remove all error insets
3373 bool a = users->removeAutoInsets();
3375 // generate the LaTeX file if necessary
3376 if (!isNwClean() || a) {
3377 makeLaTeXFile(lit_name, org_path, false);
3381 string latex_command = lyxrc.pdf_mode ?
3382 lyxrc.pdflatex_command : lyxrc.latex_command;
3383 Literate literate(latex_command, name, filepath,
3385 lyxrc.literate_command, lyxrc.literate_error_filter,
3386 lyxrc.build_command, lyxrc.build_error_filter);
3388 int res = literate.build(terr, users->owner()->getMiniBuffer());
3390 // check return value from literate.build().
3391 if ((res & Literate::NO_LOGFILE)) {
3392 WriteAlert(_("Build did not work!"),
3393 _("Missing log file:"), name);
3394 } else if ((res & Literate::ERRORS)) {
3395 users->owner()->getMiniBuffer()->Set(_("Done"));
3396 // Insert all errors as errors boxes
3397 users->insertErrors(terr);
3399 // Literate files should also be kept dirty if the literate
3400 // command run ends up with errors.
3402 //no errors or any other things to think about so:
3403 users->owner()->getMiniBuffer()->Set(_("Done"));
3407 // if we removed error insets before we ran Literate/Build or
3408 // if we inserted error insets after we ran Literate/Build this
3410 if (a || (res & Literate::ERRORS)){
3413 //users->updateScrollbar();
3417 return literate.getNumErrors();
3421 // This should be enabled when the Chktex class is implemented. (Asger)
3422 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
3423 // Other flags: -wall -v0 -x
3424 int Buffer::runChktex()
3426 if (!users->text) return 0;
3428 ProhibitInput(users);
3430 // get LaTeX-Filename
3431 string name = getLatexName();
3432 string path = OnlyPath(filename);
3434 string org_path = path;
3435 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3439 Path p(path); // path to LaTeX file
3440 users->owner()->getMiniBuffer()->Set(_("Running chktex..."));
3442 // Remove all error insets
3443 bool removedErrorInsets = users->removeAutoInsets();
3445 // Generate the LaTeX file if neccessary
3446 makeLaTeXFile(name, org_path, false);
3449 Chktex chktex(lyxrc.chktex_command, name, filepath);
3450 int res = chktex.run(terr); // run chktex
3453 WriteAlert(_("chktex did not work!"),
3454 _("Could not run with file:"), name);
3455 } else if (res > 0) {
3456 // Insert all errors as errors boxes
3457 users->insertErrors(terr);
3460 // if we removed error insets before we ran chktex or if we inserted
3461 // error insets after we ran chktex, this must be run:
3462 if (removedErrorInsets || res){
3465 //users->updateScrollbar();
3473 void Buffer::validate(LaTeXFeatures & features) const
3475 LyXParagraph * par = paragraph;
3476 LyXTextClass const & tclass =
3477 textclasslist.TextClass(params.textclass);
3479 // AMS Style is at document level
3481 features.amsstyle = (params.use_amsmath ||
3482 tclass.provides(LyXTextClass::amsmath));
3485 // We don't use "lyxerr.debug" because of speed. (Asger)
3486 if (lyxerr.debugging(Debug::LATEX))
3487 lyxerr << "Paragraph: " << par << endl;
3489 // Now just follow the list of paragraphs and run
3490 // validate on each of them.
3491 par->validate(features);
3493 // and then the next paragraph
3497 // the bullet shapes are buffer level not paragraph level
3498 // so they are tested here
3499 for (int i = 0; i < 4; ++i) {
3500 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
3501 int font = params.user_defined_bullets[i].getFont();
3504 .user_defined_bullets[i]
3511 features.latexsym = true;
3515 features.amssymb = true;
3517 else if ((font >= 2 && font <= 5)) {
3518 features.pifont = true;
3523 if (lyxerr.debugging(Debug::LATEX)) {
3524 features.showStruct();
3529 void Buffer::setPaperStuff()
3531 params.papersize = BufferParams::PAPER_DEFAULT;
3532 char c1 = params.paperpackage;
3533 if (c1 == BufferParams::PACKAGE_NONE) {
3534 char c2 = params.papersize2;
3535 if (c2 == BufferParams::VM_PAPER_USLETTER)
3536 params.papersize = BufferParams::PAPER_USLETTER;
3537 else if (c2 == BufferParams::VM_PAPER_USLEGAL)
3538 params.papersize = BufferParams::PAPER_LEGALPAPER;
3539 else if (c2 == BufferParams::VM_PAPER_USEXECUTIVE)
3540 params.papersize = BufferParams::PAPER_EXECUTIVEPAPER;
3541 else if (c2 == BufferParams::VM_PAPER_A3)
3542 params.papersize = BufferParams::PAPER_A3PAPER;
3543 else if (c2 == BufferParams::VM_PAPER_A4)
3544 params.papersize = BufferParams::PAPER_A4PAPER;
3545 else if (c2 == BufferParams::VM_PAPER_A5)
3546 params.papersize = BufferParams::PAPER_A5PAPER;
3547 else if ((c2 == BufferParams::VM_PAPER_B3) || (c2 == BufferParams::VM_PAPER_B4) ||
3548 (c2 == BufferParams::VM_PAPER_B5))
3549 params.papersize = BufferParams::PAPER_B5PAPER;
3550 } else if ((c1 == BufferParams::PACKAGE_A4) || (c1 == BufferParams::PACKAGE_A4WIDE) ||
3551 (c1 == BufferParams::PACKAGE_WIDEMARGINSA4))
3552 params.papersize = BufferParams::PAPER_A4PAPER;
3556 // This function should be in Buffer because it's a buffer's property (ale)
3557 string Buffer::getIncludeonlyList(char delim)
3560 for (inset_iterator it = inset_iterator_begin();
3561 it != inset_iterator_end(); ++it) {
3562 if ((*it)->LyxCode() == Inset::INCLUDE_CODE) {
3563 InsetInclude * insetinc =
3564 static_cast<InsetInclude *>(*it);
3565 if (insetinc->isInclude()
3566 && insetinc->isNoLoad()) {
3569 lst += OnlyFilename(ChangeExtension(insetinc->getContents(), string()));
3573 lyxerr.debug() << "Includeonly(" << lst << ')' << endl;
3578 vector<string> Buffer::getLabelList()
3580 /// if this is a child document and the parent is already loaded
3581 /// Use the parent's list instead [ale990407]
3582 if (!params.parentname.empty()
3583 && bufferlist.exists(params.parentname)) {
3584 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3586 return tmp->getLabelList();
3589 vector<string> label_list;
3590 for (inset_iterator it = inset_iterator_begin();
3591 it != inset_iterator_end(); ++it) {
3592 vector<string> l = (*it)->getLabelList();
3593 label_list.insert(label_list.end(), l.begin(), l.end());
3599 vector<vector<Buffer::TocItem> > Buffer::getTocList()
3601 vector<vector<TocItem> > l(4);
3602 LyXParagraph * par = paragraph;
3604 if (par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
3605 if (textclasslist.Style(params.textclass,
3606 par->GetLayout()).labeltype
3607 == LABEL_SENSITIVE) {
3611 tmp.str = par->String(this, false);
3612 switch (par->footnotekind) {
3613 case LyXParagraph::FIG:
3614 case LyXParagraph::WIDE_FIG:
3615 l[TOC_LOF].push_back(tmp);
3617 case LyXParagraph::TAB:
3618 case LyXParagraph::WIDE_TAB:
3619 l[TOC_LOT].push_back(tmp);
3621 case LyXParagraph::ALGORITHM:
3622 l[TOC_LOA].push_back(tmp);
3624 case LyXParagraph::FOOTNOTE:
3625 case LyXParagraph::MARGIN:
3629 } else if (!par->IsDummy()) {
3630 char labeltype = textclasslist.Style(params.textclass,
3631 par->GetLayout()).labeltype;
3633 if (labeltype >= LABEL_COUNTER_CHAPTER
3634 && labeltype <= LABEL_COUNTER_CHAPTER + params.tocdepth) {
3635 // insert this into the table of contents
3640 textclasslist.TextClass(params.textclass).maxcounter());
3641 tmp.str = par->String(this, true);
3642 l[TOC_TOC].push_back(tmp);
3650 // This is also a buffer property (ale)
3651 vector<pair<string,string> > Buffer::getBibkeyList()
3653 /// if this is a child document and the parent is already loaded
3654 /// Use the parent's list instead [ale990412]
3655 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3656 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3658 return tmp->getBibkeyList();
3661 vector<pair<string, string> > keys;
3662 LyXParagraph * par = paragraph;
3665 keys.push_back(pair<string,string>(par->bibkey->getContents(),
3666 par->String(this, false)));
3670 // Might be either using bibtex or a child has bibliography
3672 for (inset_iterator it = inset_iterator_begin();
3673 it != inset_iterator_end(); ++it) {
3674 // Search for Bibtex or Include inset
3675 if ((*it)->LyxCode() == Inset::BIBTEX_CODE) {
3676 vector<pair<string,string> > tmp =
3677 static_cast<InsetBibtex*>(*it)->getKeys();
3678 keys.insert(keys.end(), tmp.begin(), tmp.end());
3679 } else if ((*it)->LyxCode() == Inset::INCLUDE_CODE) {
3680 vector<pair<string,string> > tmp =
3681 static_cast<InsetInclude*>(*it)->getKeys();
3682 keys.insert(keys.end(), tmp.begin(), tmp.end());
3691 bool Buffer::isDepClean(string const & name) const
3693 DEPCLEAN * item = dep_clean;
3694 while (item && item->master != name)
3696 if (!item) return true;
3701 void Buffer::markDepClean(string const & name)
3704 dep_clean = new DEPCLEAN;
3705 dep_clean->clean = true;
3706 dep_clean->master = name;
3707 dep_clean->next = 0;
3709 DEPCLEAN* item = dep_clean;
3710 while (item && item->master != name)
3715 item = new DEPCLEAN;
3717 item->master = name;
3724 bool Buffer::Dispatch(string const & command)
3726 // Split command string into command and argument
3727 string cmd, line = frontStrip(command);
3728 string arg = strip(frontStrip(split(line, cmd, ' ')));
3730 return Dispatch(lyxaction.LookupFunc(cmd.c_str()), arg.c_str());
3734 bool Buffer::Dispatch(int action, string const & argument)
3736 bool dispatched = true;
3739 MenuExport(this, argument);
3749 void Buffer::resize()
3751 /// resize the BufferViews!
3757 void Buffer::resizeInsets(BufferView * bv)
3759 /// then remove all LyXText in text-insets
3760 LyXParagraph * par = paragraph;
3761 for(;par;par = par->next) {
3762 par->resizeInsetsLyXText(bv);
3766 void Buffer::ChangeLanguage(Language const * from, Language const * to)
3769 LyXParagraph * par = paragraph;
3771 par->ChangeLanguage(params, from, to);
3777 bool Buffer::isMultiLingual()
3780 LyXParagraph * par = paragraph;
3782 if (par->isMultiLingual(params))
3790 Buffer::inset_iterator::inset_iterator(LyXParagraph * paragraph,
3791 LyXParagraph::size_type pos)
3793 it = par->InsetIterator(pos);
3794 if (it == par->inset_iterator_end()) {
3801 void Buffer::inset_iterator::SetParagraph() {
3803 it = par->inset_iterator_begin();
3804 if (it != par->inset_iterator_end())
3809 // We maintain an invariant that whenever par = 0 then it = 0