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 * ======================================================
17 // 23/03/98 Heinrich Bauer (heinrich.bauer@t-mobil.de)
18 // Spots marked "changed Heinrich Bauer, 23/03/98" modified due to the
19 // following bug: dvi file export did not work after printing (or previewing)
20 // and vice versa as long as the same file was concerned. This happened
21 // every time the LyX-file was left unchanged between the two actions mentioned
31 #include <sys/types.h>
37 #pragma implementation "buffer.h"
41 #include "bufferlist.h"
43 #include "lyx_gui_misc.h"
44 #include "LyXAction.h"
47 #include "tex-strings.h"
49 #include "bufferview_funcs.h"
50 #include "minibuffer.h"
53 #include "mathed/formulamacro.h"
54 #include "insets/lyxinset.h"
55 #include "insets/inseterror.h"
56 #include "insets/insetlabel.h"
57 #include "insets/insetref.h"
58 #include "insets/inseturl.h"
59 #include "insets/insetinfo.h"
60 #include "insets/insetquotes.h"
61 #include "insets/insetlatexaccent.h"
62 #include "insets/insetbib.h"
63 #include "insets/insetindex.h"
64 #include "insets/insetinclude.h"
65 #include "insets/insettoc.h"
66 #include "insets/insetlof.h"
67 #include "insets/insetlot.h"
68 #include "insets/insetloa.h"
69 #include "insets/insetparent.h"
70 #include "insets/insetspecialchar.h"
71 #include "insets/figinset.h"
72 #include "insets/insettext.h"
73 #include "insets/insetert.h"
74 #include "insets/insetgraphics.h"
75 #include "insets/insetfoot.h"
76 #include "insets/insettabular.h"
77 #include "support/filetools.h"
78 #include "support/path.h"
84 #include "LaTeXFeatures.h"
85 #include "support/syscall.h"
86 #include "support/lyxlib.h"
87 #include "support/FileInfo.h"
103 // all these externs should eventually be removed.
104 extern BufferList bufferlist;
106 extern void MenuExport(Buffer *, string const &);
107 extern LyXAction lyxaction;
110 static const float LYX_FORMAT = 2.16;
112 extern int tex_code_break_column;
115 Buffer::Buffer(string const & file, bool ronly)
117 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
119 filepath = OnlyPath(file);
123 dvi_clean_orgd = false; // Heinrich Bauer, 23/03/98
124 dvi_clean_tmpd = false; // Heinrich Bauer, 23/03/98
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 updateAllVisibleBufferRelatedPopups();
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();
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;
311 if (token[0] != '\\') {
312 for (string::const_iterator cit = token.begin();
313 cit != token.end(); ++cit) {
314 par->InsertChar(pos, (*cit));
315 par->SetFont(pos, font);
318 } else if (token == "\\i") {
319 Inset * inset = new InsetLatexAccent;
321 par->InsertChar(pos, LyXParagraph::META_INSET);
322 par->InsertInset(pos, inset);
323 par->SetFont(pos, font);
325 } else if (token == "\\layout") {
330 par = new LyXParagraph(par);
334 string layoutname = lex.GetString();
335 pair<bool, LyXTextClass::LayoutList::size_type> pp
336 = textclasslist.NumberOfLayout(params.textclass,
339 par->layout = pp.second;
340 } else { // layout not found
341 // use default layout "Standard" (0)
344 // Test whether the layout is obsolete.
345 LyXLayout const & layout =
346 textclasslist.Style(params.textclass,
348 if (!layout.obsoleted_by().empty())
350 textclasslist.NumberOfLayout(params.textclass,
351 layout.obsoleted_by()).second;
352 par->footnoteflag = footnoteflag;
353 par->footnotekind = footnotekind;
355 font = LyXFont(LyXFont::ALL_INHERIT, params.language_info);
356 if (format < 2.16 && params.language == "hebrew")
357 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;
383 } else if (token == "\\begin_deeper") {
385 } else if (token == "\\end_deeper") {
387 lex.printError("\\end_deeper: "
388 "depth is already null");
392 } else if (token == "\\begin_preamble") {
393 params.readPreamble(lex);
394 } else if (token == "\\textclass") {
396 pair<bool, LyXTextClassList::size_type> pp =
397 textclasslist.NumberOfClass(lex.GetString());
399 params.textclass = pp.second;
401 lex.printError("Unknown textclass `$$Token'");
402 params.textclass = 0;
404 if (!textclasslist.Load(params.textclass)) {
405 // if the textclass wasn't loaded properly
406 // we need to either substitute another
407 // or stop loading the file.
408 // I can substitute but I don't see how I can
409 // stop loading... ideas?? ARRae980418
410 WriteAlert(_("Textclass Loading Error!"),
411 string(_("Can't load textclass ")) +
412 textclasslist.NameOfClass(params.textclass),
413 _("-- substituting default"));
414 params.textclass = 0;
416 } else if (token == "\\options") {
418 params.options = lex.GetString();
419 } else if (token == "\\language") {
420 params.readLanguage(lex);
421 } else if (token == "\\fontencoding") {
423 } else if (token == "\\inputencoding") {
425 params.inputenc = lex.GetString();
426 } else if (token == "\\graphics") {
427 params.readGraphicsDriver(lex);
428 } else if (token == "\\fontscheme") {
430 params.fonts = lex.GetString();
431 } else if (token == "\\noindent") {
432 par->noindent = true;
433 } else if (token == "\\fill_top") {
434 par->added_space_top = VSpace(VSpace::VFILL);
435 } else if (token == "\\fill_bottom") {
436 par->added_space_bottom = VSpace(VSpace::VFILL);
437 } else if (token == "\\line_top") {
438 par->line_top = true;
439 } else if (token == "\\line_bottom") {
440 par->line_bottom = true;
441 } else if (token == "\\pagebreak_top") {
442 par->pagebreak_top = true;
443 } else if (token == "\\pagebreak_bottom") {
444 par->pagebreak_bottom = true;
445 } else if (token == "\\start_of_appendix") {
446 par->start_of_appendix = true;
447 } else if (token == "\\paragraph_separation") {
448 int tmpret = lex.FindToken(string_paragraph_separation);
449 if (tmpret == -1) ++tmpret;
450 if (tmpret != LYX_LAYOUT_DEFAULT)
451 params.paragraph_separation =
452 static_cast<BufferParams::PARSEP>(tmpret);
453 } else if (token == "\\defskip") {
455 params.defskip = VSpace(lex.GetString());
456 } else if (token == "\\epsfig") { // obsolete
457 // Indeed it is obsolete, but we HAVE to be backwards
458 // compatible until 0.14, because otherwise all figures
459 // in existing documents are irretrivably lost. (Asger)
460 params.readGraphicsDriver(lex);
461 } else if (token == "\\quotes_language") {
462 int tmpret = lex.FindToken(string_quotes_language);
463 if (tmpret == -1) ++tmpret;
464 if (tmpret != LYX_LAYOUT_DEFAULT) {
465 InsetQuotes::quote_language tmpl =
466 InsetQuotes::EnglishQ;
469 tmpl = InsetQuotes::EnglishQ;
472 tmpl = InsetQuotes::SwedishQ;
475 tmpl = InsetQuotes::GermanQ;
478 tmpl = InsetQuotes::PolishQ;
481 tmpl = InsetQuotes::FrenchQ;
484 tmpl = InsetQuotes::DanishQ;
487 params.quotes_language = tmpl;
489 } else if (token == "\\quotes_times") {
491 switch(lex.GetInteger()) {
493 params.quotes_times = InsetQuotes::SingleQ;
496 params.quotes_times = InsetQuotes::DoubleQ;
499 } else if (token == "\\papersize") {
500 int tmpret = lex.FindToken(string_papersize);
504 params.papersize2 = tmpret;
505 } else if (token == "\\paperpackage") {
506 int tmpret = lex.FindToken(string_paperpackages);
509 params.paperpackage = BufferParams::PACKAGE_NONE;
511 params.paperpackage = tmpret;
512 } else if (token == "\\use_geometry") {
514 params.use_geometry = lex.GetInteger();
515 } else if (token == "\\use_amsmath") {
517 params.use_amsmath = lex.GetInteger();
518 } else if (token == "\\paperorientation") {
519 int tmpret = lex.FindToken(string_orientation);
520 if (tmpret == -1) ++tmpret;
521 if (tmpret != LYX_LAYOUT_DEFAULT)
522 params.orientation = static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
523 } else if (token == "\\paperwidth") {
525 params.paperwidth = lex.GetString();
526 } else if (token == "\\paperheight") {
528 params.paperheight = lex.GetString();
529 } else if (token == "\\leftmargin") {
531 params.leftmargin = lex.GetString();
532 } else if (token == "\\topmargin") {
534 params.topmargin = lex.GetString();
535 } else if (token == "\\rightmargin") {
537 params.rightmargin = lex.GetString();
538 } else if (token == "\\bottommargin") {
540 params.bottommargin = lex.GetString();
541 } else if (token == "\\headheight") {
543 params.headheight = lex.GetString();
544 } else if (token == "\\headsep") {
546 params.headsep = lex.GetString();
547 } else if (token == "\\footskip") {
549 params.footskip = lex.GetString();
550 } else if (token == "\\paperfontsize") {
552 params.fontsize = strip(lex.GetString());
553 } else if (token == "\\papercolumns") {
555 params.columns = lex.GetInteger();
556 } else if (token == "\\papersides") {
558 switch(lex.GetInteger()) {
560 case 1: params.sides = LyXTextClass::OneSide; break;
561 case 2: params.sides = LyXTextClass::TwoSides; break;
563 } else if (token == "\\paperpagestyle") {
565 params.pagestyle = strip(lex.GetString());
566 } else if (token == "\\bullet") {
568 int index = lex.GetInteger();
570 int temp_int = lex.GetInteger();
571 params.user_defined_bullets[index].setFont(temp_int);
572 params.temp_bullets[index].setFont(temp_int);
574 temp_int = lex.GetInteger();
575 params.user_defined_bullets[index].setCharacter(temp_int);
576 params.temp_bullets[index].setCharacter(temp_int);
578 temp_int = lex.GetInteger();
579 params.user_defined_bullets[index].setSize(temp_int);
580 params.temp_bullets[index].setSize(temp_int);
582 string temp_str = lex.GetString();
583 if (temp_str != "\\end_bullet") {
584 // this element isn't really necessary for
585 // parsing but is easier for humans
586 // to understand bullets. Put it back and
587 // set a debug message?
588 lex.printError("\\end_bullet expected, got" + temp_str);
589 //how can I put it back?
591 } else if (token == "\\bulletLaTeX") {
593 int index = lex.GetInteger();
595 string temp_str = lex.GetString(), sum_str;
596 while (temp_str != "\\end_bullet") {
597 // this loop structure is needed when user
598 // enters an empty string since the first
599 // thing returned will be the \\end_bullet
601 // if the LaTeX entry has spaces. Each element
602 // therefore needs to be read in turn
605 temp_str = lex.GetString();
607 params.user_defined_bullets[index].setText(sum_str);
608 params.temp_bullets[index].setText(sum_str);
609 } else if (token == "\\secnumdepth") {
611 params.secnumdepth = lex.GetInteger();
612 } else if (token == "\\tocdepth") {
614 params.tocdepth = lex.GetInteger();
616 } else if (token == "\\baselinestretch") { // obsolete
617 lex.nextToken(); // should not be used directly
619 // Will probably keep a kind of support just for
621 params.spacing.set(Spacing::Other, lex.GetFloat());
623 } else if (token == "\\spacing") {
625 string tmp = strip(lex.GetString());
626 Spacing::Space tmp_space = Spacing::Default;
628 if (tmp == "single") {
629 tmp_space = Spacing::Single;
630 } else if (tmp == "onehalf") {
631 tmp_space = Spacing::Onehalf;
632 } else if (tmp == "double") {
633 tmp_space = Spacing::Double;
634 } else if (tmp == "other") {
636 tmp_space = Spacing::Other;
637 tmp_val = lex.GetFloat();
639 lex.printError("Unknown spacing token: '$$Token'");
641 // Small hack so that files written with klyx will be
644 par->spacing.set(tmp_space, tmp_val);
646 params.spacing.set(tmp_space, tmp_val);
648 } else if (token == "\\paragraph_spacing") {
650 string tmp = strip(lex.GetString());
651 if (tmp == "single") {
652 par->spacing.set(Spacing::Single);
653 } else if (tmp == "onehalf") {
654 par->spacing.set(Spacing::Onehalf);
655 } else if (tmp == "double") {
656 par->spacing.set(Spacing::Double);
657 } else if (tmp == "other") {
659 par->spacing.set(Spacing::Other,
662 lex.printError("Unknown spacing token: '$$Token'");
664 } else if (token == "\\float_placement") {
666 params.float_placement = lex.GetString();
668 } else if (token == "\\cursor") { // obsolete
669 // this is obsolete, so we just skip it.
672 } else if (token == "\\family") {
674 font.setLyXFamily(lex.GetString());
675 } else if (token == "\\series") {
677 font.setLyXSeries(lex.GetString());
678 } else if (token == "\\shape") {
680 font.setLyXShape(lex.GetString());
681 } else if (token == "\\size") {
683 font.setLyXSize(lex.GetString());
684 } else if (token == "\\latex") {
686 string tok = lex.GetString();
687 // This is dirty, but gone with LyX3. (Asger)
688 if (tok == "no_latex")
689 font.setLatex(LyXFont::OFF);
690 else if (tok == "latex")
691 font.setLatex(LyXFont::ON);
692 else if (tok == "default")
693 font.setLatex(LyXFont::INHERIT);
695 lex.printError("Unknown LaTeX font flag "
697 } else if (token == "\\lang") {
699 string tok = lex.GetString();
700 Languages::iterator lit = languages.find(tok);
701 if (lit != languages.end()) {
702 font.setLanguage(&(*lit).second);
704 font.setLanguage(params.language_info);
705 lex.printError("Unknown language `$$Token'");
707 } else if (token == "\\emph") {
709 font.setEmph(font.setLyXMisc(lex.GetString()));
710 } else if (token == "\\bar") {
712 string tok = lex.GetString();
713 // This is dirty, but gone with LyX3. (Asger)
715 font.setUnderbar(LyXFont::ON);
716 else if (tok == "no")
717 font.setUnderbar(LyXFont::OFF);
718 else if (tok == "default")
719 font.setUnderbar(LyXFont::INHERIT);
721 lex.printError("Unknown bar font flag "
723 } else if (token == "\\noun") {
725 font.setNoun(font.setLyXMisc(lex.GetString()));
726 } else if (token == "\\color") {
728 font.setLyXColor(lex.GetString());
729 } else if (token == "\\align") {
730 int tmpret = lex.FindToken(string_align);
731 if (tmpret == -1) ++tmpret;
732 if (tmpret != LYX_LAYOUT_DEFAULT) { // tmpret != 99 ???
734 for (; tmpret > 0; --tmpret)
735 tmpret2 = tmpret2 * 2;
736 par->align = LyXAlignment(tmpret2);
738 } else if (token == "\\added_space_top") {
740 par->added_space_top = VSpace(lex.GetString());
741 } else if (token == "\\added_space_bottom") {
743 par->added_space_bottom = VSpace(lex.GetString());
744 } else if (token == "\\pextra_type") {
746 par->pextra_type = lex.GetInteger();
747 } else if (token == "\\pextra_width") {
749 par->pextra_width = lex.GetString();
750 } else if (token == "\\pextra_widthp") {
752 par->pextra_widthp = lex.GetString();
753 } else if (token == "\\pextra_alignment") {
755 par->pextra_alignment = lex.GetInteger();
756 } else if (token == "\\pextra_hfill") {
758 par->pextra_hfill = lex.GetInteger();
759 } else if (token == "\\pextra_start_minipage") {
761 par->pextra_start_minipage = lex.GetInteger();
762 } else if (token == "\\labelwidthstring") {
764 par->labelwidthstring = lex.GetString();
765 // do not delete this token, it is still needed!
766 } else if (token == "\\end_inset") {
767 // Simply ignore this. The insets do not have
769 // But insets should read it, it is a part of
770 // the inset isn't it? Lgb.
771 } else if (token == "\\begin_inset") {
772 // Should be moved out into its own function/method. (Lgb)
774 string tmptok = lex.GetString();
775 // test the different insets
776 if (tmptok == "Quotes") {
777 Inset * inset = new InsetQuotes;
779 par->InsertChar(pos, LyXParagraph::META_INSET);
780 par->InsertInset(pos, inset);
781 par->SetFont(pos, font);
784 } else if (tmptok == "\\i") {
785 Inset * inset = new InsetLatexAccent;
787 par->InsertChar(pos, LyXParagraph::META_INSET);
788 par->InsertInset(pos, inset);
789 par->SetFont(pos, font);
792 } else if (tmptok == "FormulaMacro") {
793 Inset * inset = new InsetFormulaMacro;
795 par->InsertChar(pos, LyXParagraph::META_INSET);
796 par->InsertInset(pos, inset);
797 par->SetFont(pos, font);
799 } else if (tmptok == "Formula") {
800 Inset * inset = new InsetFormula;
802 par->InsertChar(pos, LyXParagraph::META_INSET);
803 par->InsertInset(pos, inset);
804 par->SetFont(pos, font);
806 } else if (tmptok == "Figure") {
807 Inset * inset = new InsetFig(100, 100, this);
809 par->InsertChar(pos, LyXParagraph::META_INSET);
810 par->InsertInset(pos, inset);
811 par->SetFont(pos, font);
813 } else if (tmptok == "Info") {
814 Inset * inset = new InsetInfo;
816 par->InsertChar(pos, LyXParagraph::META_INSET);
817 par->InsertInset(pos, inset);
818 par->SetFont(pos, font);
820 } else if (tmptok == "Include") {
821 Inset * inset = new InsetInclude(string(), this);
823 par->InsertChar(pos, LyXParagraph::META_INSET);
824 par->InsertInset(pos, inset);
825 par->SetFont(pos, font);
827 } else if (tmptok == "ERT") {
828 Inset * inset = new InsetERT(this);
830 par->InsertChar(pos, LyXParagraph::META_INSET);
831 par->InsertInset(pos, inset);
832 par->SetFont(pos, font);
834 } else if (tmptok == "Tabular") {
835 Inset * inset = new InsetTabular(this);
837 par->InsertChar(pos, LyXParagraph::META_INSET);
838 par->InsertInset(pos, inset);
839 par->SetFont(pos, font);
841 } else if (tmptok == "Text") {
842 Inset * inset = new InsetText(this);
844 par->InsertChar(pos, LyXParagraph::META_INSET);
845 par->InsertInset(pos, inset);
846 par->SetFont(pos, font);
848 } else if (tmptok == "Foot") {
849 Inset * inset = new InsetFoot(this);
851 par->InsertChar(pos, LyXParagraph::META_INSET);
852 par->InsertInset(pos, inset);
853 par->SetFont(pos, font);
855 } else if (tmptok == "GRAPHICS") {
856 Inset * inset = new InsetGraphics;
858 par->InsertChar(pos, LyXParagraph::META_INSET);
859 par->InsertInset(pos, inset);
860 par->SetFont(pos, font);
861 } else if (tmptok == "LatexCommand") {
865 if (inscmd.getCmdName() == "cite") {
866 inset = new InsetCitation(inscmd.getContents(), inscmd.getOptions());
867 } else if (inscmd.getCmdName() == "bibitem") {
868 lex.printError("Wrong place for bibitem");
869 inset = inscmd.Clone();
870 } else if (inscmd.getCmdName() == "BibTeX") {
871 inset = new InsetBibtex(inscmd.getContents(), inscmd.getOptions(), this);
872 } else if (inscmd.getCmdName() == "index") {
873 inset = new InsetIndex(inscmd.getContents());
874 } else if (inscmd.getCmdName() == "include") {
875 inset = new InsetInclude(inscmd.getContents(), this);
876 } else if (inscmd.getCmdName() == "label") {
877 inset = new InsetLabel(inscmd.getCommand());
878 } else if (inscmd.getCmdName() == "url"
879 || inscmd.getCmdName() == "htmlurl") {
880 inset = new InsetUrl(inscmd.getCommand());
881 } else if (inscmd.getCmdName() == "ref"
882 || inscmd.getCmdName() == "pageref"
883 || inscmd.getCmdName() == "vref"
884 || inscmd.getCmdName() == "vpageref"
885 || inscmd.getCmdName() == "prettyref") {
886 if (!inscmd.getOptions().empty() || !inscmd.getContents().empty()) {
887 inset = new InsetRef(inscmd, this);
889 // CHECK if this else clause
890 //is still needed. (Lgb)
892 // This condition comes from a
893 // temporary solution to the latexdel
894 // ref inset that was transformed to
895 // an empty ref inset plus the body
896 // surronded by latexdel insets
898 string cont, opt, tmptmptok, cmdname;
900 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
905 tmptmptok = lex.GetString();
906 if(tmptmptok[0] == '\\') {
907 if( tmptmptok == "\\backslash")
917 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
922 tmptmptok = lex.GetString();
923 if(tmptmptok[0] == '\\') {
924 if( tmptmptok == "\\backslash")
934 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
940 cmdname = "\\" + inscmd.getCmdName();
941 cmdname += "[" + cont + "]";
942 cmdname += "{" + opt + "}";
943 inset = new InsetRef(cmdname, this);
946 } else if (inscmd.getCmdName() == "tableofcontents") {
947 inset = new InsetTOC(this);
948 } else if (inscmd.getCmdName() == "listoffigures") {
949 inset = new InsetLOF(this);
950 } else if (inscmd.getCmdName() == "listofalgorithms") {
951 inset = new InsetLOA(this);
952 } else if (inscmd.getCmdName() == "listoftables") {
953 inset = new InsetLOT(this);
954 } else if (inscmd.getCmdName() == "printindex") {
955 inset = new InsetPrintIndex(this);
956 } else if (inscmd.getCmdName() == "lyxparent") {
957 inset = new InsetParent(inscmd.getContents(), this);
961 par->InsertChar(pos, LyXParagraph::META_INSET);
962 par->InsertInset(pos, inset);
963 par->SetFont(pos, font);
968 } else if (token == "\\InsetQuotes") {
969 lyxerr << "InsetQuotes" << endl;
970 Inset * inset = new InsetQuotes;
972 par->InsertChar(pos, LyXParagraph::META_INSET);
973 par->InsertInset(pos, inset);
974 par->SetFont(pos, font);
978 } else if (token == "\\InsetFormula") {
979 lyxerr << "InsetFormula" << endl;
980 Inset * inset = new InsetFormula;
982 par->InsertChar(pos, LyXParagraph::META_INSET);
983 par->InsertInset(pos, inset);
984 par->SetFont(pos, font);
987 } else if (token == "\\SpecialChar") {
988 LyXLayout const & layout =
989 textclasslist.Style(params.textclass,
992 // Insets don't make sense in a free-spacing context! ---Kayvan
993 if (layout.free_spacing) {
997 next_token = lex.GetString();
998 if (next_token == "\\-") {
999 par->InsertChar(pos, '-');
1000 par->SetFont(pos, font);
1001 } else if (next_token == "\\protected_separator"
1002 || next_token == "~") {
1003 par->InsertChar(pos, ' ');
1004 par->SetFont(pos, font);
1006 lex.printError("Token `$$Token' "
1008 "paragraph layout!");
1013 Inset * inset = new InsetSpecialChar;
1015 par->InsertChar(pos, LyXParagraph::META_INSET);
1016 par->InsertInset(pos, inset);
1017 par->SetFont(pos, font);
1021 } else if (token == "\\Figure") {
1022 lyxerr << "Figure" << endl;
1023 Inset * inset = new InsetFig(100, 100, this);
1025 par->InsertChar(pos, LyXParagraph::META_INSET);
1026 par->InsertInset(pos, inset);
1027 par->SetFont(pos, font);
1030 } else if (token == "\\newline") {
1031 par->InsertChar(pos, LyXParagraph::META_NEWLINE);
1032 par->SetFont(pos, font);
1034 } else if (token == "\\LyXTable") {
1035 #ifdef USE_TABULAR_INSETS
1036 Inset * inset = new InsetTabular(this);
1038 par->InsertChar(pos, LyXParagraph::META_INSET);
1039 par->InsertInset(pos, inset);
1040 par->SetFont(pos, font);
1043 par->table = new LyXTable(lex);
1045 } else if (token == "\\hfill") {
1046 par->InsertChar(pos, LyXParagraph::META_HFILL);
1047 par->SetFont(pos, font);
1049 } else if (token == "\\protected_separator") { // obsolete
1050 // This is a backward compability thingie. (Lgb)
1051 // Remove it later some time...introduced with fileformat
1053 LyXLayout const & layout =
1054 textclasslist.Style(params.textclass,
1057 if (layout.free_spacing) {
1058 par->InsertChar(pos, ' ');
1059 par->SetFont(pos, font);
1061 Inset * inset = new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
1062 par->InsertChar(pos, LyXParagraph::META_INSET);
1063 par->InsertInset(pos, inset);
1064 par->SetFont(pos, font);
1067 } else if (token == "\\bibitem") { // ale970302
1069 par->bibkey = new InsetBibKey;
1070 par->bibkey->Read(lex);
1071 }else if (token == "\\backslash") {
1072 par->InsertChar(pos, '\\');
1073 par->SetFont(pos, font);
1075 }else if (token == "\\the_end") {
1076 the_end_read = true;
1078 // This should be insurance for the future: (Asger)
1079 lex.printError("Unknown token `$$Token'. "
1080 "Inserting as text.");
1081 for(string::const_iterator cit = token.begin();
1082 cit != token.end(); ++cit) {
1083 par->InsertChar(pos, (*cit));
1084 par->SetFont(pos, font);
1088 return the_end_read;
1091 bool Buffer::readFile(LyXLex & lex, LyXParagraph * par)
1097 token = lex.GetString();
1098 if (token == "\\lyxformat") { // the first token _must_ be...
1100 format = lex.GetFloat();
1102 if (LYX_FORMAT - format > 0.05) {
1103 printf(_("Warning: need lyxformat %.2f but found %.2f\n"),
1104 LYX_FORMAT, format);
1106 if (format - LYX_FORMAT > 0.05) {
1107 printf(_("ERROR: need lyxformat %.2f but found %.2f\n"),
1108 LYX_FORMAT, format);
1110 bool the_end = readLyXformat2(lex, par);
1111 // Formats >= 2.13 support "\the_end" marker
1118 WriteAlert(_("Warning!"),
1119 _("Reading of document is not complete"),
1120 _("Maybe the document is truncated"));
1121 // We simulate a safe reading anyways to allow
1122 // users to take the chance... (Asger)
1126 WriteAlert(_("ERROR!"),
1127 _("Old LyX file format found. "
1128 "Use LyX 0.10.x to read this!"));
1132 } else { // "\\lyxformat" not found
1133 WriteAlert(_("ERROR!"), _("Not a LyX file!"));
1136 WriteAlert(_("ERROR!"), _("Unable to read file!"));
1142 // Should probably be moved to somewhere else: BufferView? LyXView?
1143 bool Buffer::save() const
1145 // We don't need autosaves in the immediate future. (Asger)
1146 resetAutosaveTimers();
1150 if (lyxrc.make_backup) {
1151 s = fileName() + '~';
1152 if (!lyxrc.backupdir_path.empty())
1153 s = AddName(lyxrc.backupdir_path,
1154 subst(CleanupPath(s),'/','!'));
1156 // Rename is the wrong way of making a backup,
1157 // this is the correct way.
1158 /* truss cp fil fil2:
1159 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
1160 stat("LyXVC.lyx", 0xEFFFF688) = 0
1161 open("LyXVC.lyx", O_RDONLY) = 3
1162 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
1163 fstat(4, 0xEFFFF508) = 0
1164 fstat(3, 0xEFFFF508) = 0
1165 read(3, " # T h i s f i l e w".., 8192) = 5579
1166 write(4, " # T h i s f i l e w".., 5579) = 5579
1167 read(3, 0xEFFFD4A0, 8192) = 0
1170 chmod("LyXVC3.lyx", 0100644) = 0
1171 lseek(0, 0, SEEK_CUR) = 46440
1175 // Should proabaly have some more error checking here.
1176 // Should be cleaned up in 0.13, at least a bit.
1177 // Doing it this way, also makes the inodes stay the same.
1178 // This is still not a very good solution, in particular we
1179 // might loose the owner of the backup.
1180 FileInfo finfo(fileName());
1181 if (finfo.exist()) {
1182 mode_t fmode = finfo.getMode();
1183 struct utimbuf times = {
1184 finfo.getAccessTime(),
1185 finfo.getModificationTime() };
1187 ifstream ifs(fileName().c_str());
1188 ofstream ofs(s.c_str(), ios::out|ios::trunc);
1193 ::chmod(s.c_str(), fmode);
1195 if (::utime(s.c_str(), ×)) {
1196 lyxerr << "utime error." << endl;
1199 lyxerr << "LyX was not able to make "
1200 "backupcopy. Beware." << endl;
1205 if (writeFile(fileName(), false)) {
1208 // now delete the autosavefile
1209 string a = OnlyPath(fileName());
1211 a += OnlyFilename(fileName());
1213 FileInfo fileinfo(a);
1214 if (fileinfo.exist()) {
1215 if (::remove(a.c_str()) != 0) {
1216 WriteFSAlert(_("Could not delete "
1217 "auto-save file!"), a);
1221 // Saving failed, so backup is not backup
1222 if (lyxrc.make_backup) {
1223 ::rename(s.c_str(), fileName().c_str());
1231 // Returns false if unsuccesful
1232 bool Buffer::writeFile(string const & fname, bool flag) const
1234 // if flag is false writeFile will not create any GUI
1235 // warnings, only cerr.
1236 // Needed for autosave in background or panic save (Matthias 120496)
1238 if (read_only && (fname == filename)) {
1239 // Here we should come with a question if we should
1240 // perform the write anyway.
1242 lyxerr << _("Error! Document is read-only: ")
1245 WriteAlert(_("Error! Document is read-only: "),
1250 FileInfo finfo(fname);
1251 if (finfo.exist() && !finfo.writable()) {
1252 // Here we should come with a question if we should
1253 // try to do the save anyway. (i.e. do a chmod first)
1255 lyxerr << _("Error! Cannot write file: ")
1258 WriteFSAlert(_("Error! Cannot write file: "),
1263 ofstream ofs(fname.c_str());
1266 lyxerr << _("Error! Cannot open file: ")
1269 WriteFSAlert(_("Error! Cannot open file: "),
1273 // The top of the file should not be written by params.
1275 // write out a comment in the top of the file
1276 ofs << '#' << LYX_DOCVERSION
1277 << " created this file. For more info see http://www.lyx.org/\n";
1278 ofs.setf(ios::showpoint|ios::fixed);
1280 ofs << "\\lyxformat " << setw(4) << LYX_FORMAT << "\n";
1282 // now write out the buffer paramters.
1283 params.writeFile(ofs);
1285 char footnoteflag = 0;
1288 // this will write out all the paragraphs
1289 // using recursive descent.
1290 paragraph->writeFile(ofs, params, footnoteflag, depth);
1292 // Write marker that shows file is complete
1293 ofs << "\n\\the_end" << endl;
1295 // how to check if close went ok?
1300 void Buffer::writeFileAscii(string const & fname, int linelen)
1302 LyXFont font1, font2;
1304 char c, footnoteflag = 0, depth = 0;
1306 LyXParagraph::size_type i;
1307 int j, h, ltype = 0, ltype_depth = 0,
1308 * clen = 0, actcell = 0, actpos = 0, cell = 0, cells = 0,
1311 bool ref_printed = false;
1313 ofstream ofs(fname.c_str());
1315 WriteFSAlert(_("Error: Cannot write file:"), fname);
1319 string fname1 = TmpFileName();
1320 LyXParagraph * par = paragraph;
1324 if (par->footnoteflag != LyXParagraph::NO_FOOTNOTE ||
1326 par->previous->footnoteflag == LyXParagraph::NO_FOOTNOTE){
1328 /* begins a footnote environment ? */
1329 if (footnoteflag != par->footnoteflag) {
1330 footnoteflag = par->footnoteflag;
1332 j = strlen(string_footnotekinds[par->footnotekind])+4;
1333 if (currlinelen + j > linelen)
1336 << string_footnotekinds[par->footnotekind] << "] ";
1341 /* begins or ends a deeper area ?*/
1342 if (depth != par->depth) {
1343 if (par->depth > depth) {
1344 while (par->depth > depth) {
1349 while (par->depth < depth) {
1355 /* First write the layout */
1356 tmp = textclasslist.NameOfLayout(params.textclass, par->layout);
1357 if (tmp == "Itemize") {
1359 ltype_depth = depth+1;
1360 } else if (tmp == "Enumerate") {
1362 ltype_depth = depth+1;
1363 } else if (strstr(tmp.c_str(), "ection")) {
1365 ltype_depth = depth+1;
1366 } else if (strstr(tmp.c_str(), "aragraph")) {
1368 ltype_depth = depth+1;
1369 } else if (tmp == "Description") {
1371 ltype_depth = depth+1;
1372 } else if (tmp == "Abstract") {
1375 } else if (tmp == "Bibliography") {
1383 /* maybe some vertical spaces */
1385 /* the labelwidthstring used in lists */
1389 /* some pagebreaks? */
1393 /* what about the alignment */
1395 /* dummy layout, that means a footnote ended */
1396 footnoteflag = LyXParagraph::NO_FOOTNOTE;
1401 //LyXLayout const & layout =
1402 // textclasslist.Style(params.textclass,
1403 // par->GetLayout()); // unused
1404 //bool free_spc = layout.free_spacing; //unused
1406 /* It might be a table */
1409 if (!lyxrc.ascii_roff_command.empty() &&
1410 lyxrc.ascii_roff_command != "none") {
1411 RoffAsciiTable(ofs, par);
1418 cells = par->table->columns;
1419 clen = new int [cells];
1420 memset(clen, 0, sizeof(int) * cells);
1422 for (i = 0, j = 0, h = 1; i < par->size(); ++i, ++h) {
1423 c = par->GetChar(i);
1424 if (c == LyXParagraph::META_INSET) {
1425 if ((inset = par->GetInset(i))) {
1427 std::ostringstream ost;
1429 h += ost.str().length();
1434 char * tmp = ost.str();
1440 } else if (c == LyXParagraph::META_NEWLINE) {
1444 j = (++j) % par->table->NumberOfCellsInRow(actcell);
1452 font1 = LyXFont(LyXFont::ALL_INHERIT, params.language_info);
1454 for (i = 0, actpos = 1; i < par->size(); ++i, ++actpos) {
1455 if (!i && !footnoteflag && !noparbreak){
1457 for(j = 0; j < depth; ++j)
1459 currlinelen = depth * 2;
1461 case 0: /* Standard */
1462 case 4: /* (Sub)Paragraph */
1463 case 5: /* Description */
1465 case 6: /* Abstract */
1466 ofs << "Abstract\n\n";
1468 case 7: /* Bibliography */
1470 ofs << "References\n\n";
1475 ofs << par->labelstring << " ";
1478 if (ltype_depth > depth) {
1479 for(j = ltype_depth - 1; j > depth; --j)
1481 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;
1503 font2 = par->GetFontSettings(i);
1504 if (font1.latex() != font2.latex()) {
1505 if (font2.latex() == LyXFont::OFF)
1512 c = par->GetChar(i);
1516 case LyXParagraph::META_INSET:
1517 if ((inset = par->GetInset(i))) {
1520 currlinelen += (ofs.tellp() - fpos);
1521 actpos += (ofs.tellp() - fpos) - 1;
1524 case LyXParagraph::META_NEWLINE:
1526 if (par->table->NumberOfCellsInRow(actcell) <= cell) {
1527 for(j = actpos; j < clen[cell - 1]; ++j)
1530 for(j = 0; j < depth; ++j)
1532 currlinelen = depth*2;
1533 if (ltype_depth > depth) {
1534 for(j = ltype_depth; j > depth; --j)
1536 currlinelen += (ltype_depth-depth) * 2;
1538 for(j = 0; j < cells; ++j) {
1540 for(h = 0; h < (clen[j] + 1); ++h)
1544 for(j = 0; j < depth; ++j)
1546 currlinelen = depth * 2;
1547 if (ltype_depth > depth) {
1548 for(j = ltype_depth;
1551 currlinelen += (ltype_depth-depth)*2;
1557 j < clen[cell - 1]; ++j)
1563 currlinelen = actpos = 0;
1566 for(j = 0; j < depth; ++j)
1568 currlinelen = depth * 2;
1569 if (ltype_depth > depth) {
1570 for(j = ltype_depth;
1573 currlinelen += (ltype_depth - depth) * 2;
1577 case LyXParagraph::META_HFILL:
1584 if (currlinelen > linelen - 10
1585 && c == ' ' && i + 2 < par->size()) {
1587 for(j = 0; j < depth; ++j)
1589 currlinelen = depth * 2;
1590 if (ltype_depth > depth) {
1591 for(j = ltype_depth;
1594 currlinelen += (ltype_depth-depth)*2;
1596 } else if (c != '\0')
1599 lyxerr.debug() << "writeAsciiFile: NULL char in structure." << endl;
1605 for(j = actpos; j < clen[cell - 1]; ++j)
1608 for(j = 0; j < depth; ++j)
1610 currlinelen = depth * 2;
1611 if (ltype_depth > depth) {
1612 for(j = ltype_depth; j > depth; --j)
1614 currlinelen += (ltype_depth - depth) * 2;
1616 for(j = 0; j < cells; ++j) {
1618 for(h = 0; h < (clen[j] + 1); ++h)
1631 void Buffer::makeLaTeXFile(string const & fname,
1632 string const & original_path,
1633 bool nice, bool only_body)
1635 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
1637 niceFile = nice; // this will be used by Insetincludes.
1639 tex_code_break_column = lyxrc.ascii_linelen;
1641 LyXTextClass const & tclass =
1642 textclasslist.TextClass(params.textclass);
1644 ofstream ofs(fname.c_str());
1646 WriteFSAlert(_("Error: Cannot open file: "), fname);
1650 // validate the buffer.
1651 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
1652 LaTeXFeatures features(params, tclass.numLayouts());
1654 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
1657 // The starting paragraph of the coming rows is the
1658 // first paragraph of the document. (Asger)
1659 texrow.start(paragraph, 0);
1661 if (!only_body && nice) {
1662 ofs << "%% " LYX_DOCVERSION " created this file. "
1663 "For more info, see http://www.lyx.org/.\n"
1664 "%% Do not edit unless you really know what "
1669 lyxerr.debug() << "lyx header finished" << endl;
1670 // There are a few differences between nice LaTeX and usual files:
1671 // usual is \batchmode and has a
1672 // special input@path to allow the including of figures
1673 // with either \input or \includegraphics (what figinsets do).
1674 // batchmode is not set if there is a tex_code_break_column.
1675 // In this case somebody is interested in the generated LaTeX,
1676 // so this is OK. input@path is set when the actual parameter
1677 // original_path is set. This is done for usual tex-file, but not
1678 // for nice-latex-file. (Matthias 250696)
1681 // code for usual, NOT nice-latex-file
1682 ofs << "\\batchmode\n"; // changed
1683 // from \nonstopmode
1686 if (!original_path.empty()) {
1687 ofs << "\\makeatletter\n"
1688 << "\\def\\input@path{{"
1689 << original_path << "/}}\n"
1690 << "\\makeatother\n";
1696 ofs << "\\documentclass";
1698 string options; // the document class options.
1700 if (tokenPos(tclass.opt_fontsize(), '|', params.fontsize) >= 0) {
1701 // only write if existing in list (and not default)
1702 options += params.fontsize;
1707 if (!params.use_geometry &&
1708 (params.paperpackage == BufferParams::PACKAGE_NONE)) {
1709 switch (params.papersize) {
1710 case BufferParams::PAPER_A4PAPER:
1711 options += "a4paper,";
1713 case BufferParams::PAPER_USLETTER:
1714 options += "letterpaper,";
1716 case BufferParams::PAPER_A5PAPER:
1717 options += "a5paper,";
1719 case BufferParams::PAPER_B5PAPER:
1720 options += "b5paper,";
1722 case BufferParams::PAPER_EXECUTIVEPAPER:
1723 options += "executivepaper,";
1725 case BufferParams::PAPER_LEGALPAPER:
1726 options += "legalpaper,";
1732 if (params.sides != tclass.sides()) {
1733 switch (params.sides) {
1734 case LyXTextClass::OneSide:
1735 options += "oneside,";
1737 case LyXTextClass::TwoSides:
1738 options += "twoside,";
1745 if (params.columns != tclass.columns()) {
1746 if (params.columns == 2)
1747 options += "twocolumn,";
1749 options += "onecolumn,";
1752 if (!params.use_geometry
1753 && params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1754 options += "landscape,";
1756 // language should be a parameter to \documentclass
1757 bool use_babel = false;
1758 if (params.language_info->RightToLeft) // This seems necessary
1759 features.UsedLanguages.insert(default_language);
1760 if (params.language != "default" ||
1761 !features.UsedLanguages.empty() ) {
1763 for (LaTeXFeatures::LanguageList::const_iterator cit =
1764 features.UsedLanguages.begin();
1765 cit != features.UsedLanguages.end(); ++cit)
1766 options += (*cit)->lang + ",";
1767 options += params.language_info->lang + ',';
1770 // the user-defined options
1771 if (!params.options.empty()) {
1772 options += params.options + ',';
1775 if (!options.empty()){
1776 options = strip(options, ',');
1777 ofs << '[' << options << ']';
1781 << textclasslist.LatexnameOfClass(params.textclass)
1784 // end of \documentclass defs
1786 // font selection must be done before loading fontenc.sty
1787 if (params.fonts != "default") {
1788 ofs << "\\usepackage{" << params.fonts << "}\n";
1791 // this one is not per buffer
1792 if (lyxrc.fontenc != "default") {
1793 ofs << "\\usepackage[" << lyxrc.fontenc
1797 if (params.inputenc != "default") {
1798 ofs << "\\usepackage[" << params.inputenc
1803 // At the very beginning the text parameters.
1804 if (params.paperpackage != BufferParams::PACKAGE_NONE) {
1805 switch (params.paperpackage) {
1806 case BufferParams::PACKAGE_A4:
1807 ofs << "\\usepackage{a4}\n";
1810 case BufferParams::PACKAGE_A4WIDE:
1811 ofs << "\\usepackage{a4wide}\n";
1814 case BufferParams::PACKAGE_WIDEMARGINSA4:
1815 ofs << "\\usepackage[widemargins]{a4}\n";
1820 if (params.use_geometry) {
1821 ofs << "\\usepackage{geometry}\n";
1823 ofs << "\\geometry{verbose";
1824 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1825 ofs << ",landscape";
1826 switch (params.papersize2) {
1827 case BufferParams::VM_PAPER_CUSTOM:
1828 if (!params.paperwidth.empty())
1829 ofs << ",paperwidth="
1830 << params.paperwidth;
1831 if (!params.paperheight.empty())
1832 ofs << ",paperheight="
1833 << params.paperheight;
1835 case BufferParams::VM_PAPER_USLETTER:
1836 ofs << ",letterpaper";
1838 case BufferParams::VM_PAPER_USLEGAL:
1839 ofs << ",legalpaper";
1841 case BufferParams::VM_PAPER_USEXECUTIVE:
1842 ofs << ",executivepaper";
1844 case BufferParams::VM_PAPER_A3:
1847 case BufferParams::VM_PAPER_A4:
1850 case BufferParams::VM_PAPER_A5:
1853 case BufferParams::VM_PAPER_B3:
1856 case BufferParams::VM_PAPER_B4:
1859 case BufferParams::VM_PAPER_B5:
1863 // default papersize ie BufferParams::VM_PAPER_DEFAULT
1864 switch (lyxrc.default_papersize) {
1865 case BufferParams::PAPER_DEFAULT: // keep compiler happy
1866 case BufferParams::PAPER_USLETTER:
1867 ofs << ",letterpaper";
1869 case BufferParams::PAPER_LEGALPAPER:
1870 ofs << ",legalpaper";
1872 case BufferParams::PAPER_EXECUTIVEPAPER:
1873 ofs << ",executivepaper";
1875 case BufferParams::PAPER_A3PAPER:
1878 case BufferParams::PAPER_A4PAPER:
1881 case BufferParams::PAPER_A5PAPER:
1884 case BufferParams::PAPER_B5PAPER:
1889 if (!params.topmargin.empty())
1890 ofs << ",tmargin=" << params.topmargin;
1891 if (!params.bottommargin.empty())
1892 ofs << ",bmargin=" << params.bottommargin;
1893 if (!params.leftmargin.empty())
1894 ofs << ",lmargin=" << params.leftmargin;
1895 if (!params.rightmargin.empty())
1896 ofs << ",rmargin=" << params.rightmargin;
1897 if (!params.headheight.empty())
1898 ofs << ",headheight=" << params.headheight;
1899 if (!params.headsep.empty())
1900 ofs << ",headsep=" << params.headsep;
1901 if (!params.footskip.empty())
1902 ofs << ",footskip=" << params.footskip;
1906 if (params.use_amsmath
1907 && !tclass.provides(LyXTextClass::amsmath)) {
1908 ofs << "\\usepackage{amsmath}\n";
1912 if (tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle) >= 0) {
1913 if (params.pagestyle == "fancy") {
1914 ofs << "\\usepackage{fancyhdr}\n";
1917 ofs << "\\pagestyle{" << params.pagestyle << "}\n";
1921 // We try to load babel late, in case it interferes
1922 // with other packages.
1924 ofs << lyxrc.language_package << endl;
1928 if (params.secnumdepth != tclass.secnumdepth()) {
1929 ofs << "\\setcounter{secnumdepth}{"
1930 << params.secnumdepth
1934 if (params.tocdepth != tclass.tocdepth()) {
1935 ofs << "\\setcounter{tocdepth}{"
1941 if (params.paragraph_separation) {
1942 switch (params.defskip.kind()) {
1943 case VSpace::SMALLSKIP:
1944 ofs << "\\setlength\\parskip{\\smallskipamount}\n";
1946 case VSpace::MEDSKIP:
1947 ofs << "\\setlength\\parskip{\\medskipamount}\n";
1949 case VSpace::BIGSKIP:
1950 ofs << "\\setlength\\parskip{\\bigskipamount}\n";
1952 case VSpace::LENGTH:
1953 ofs << "\\setlength\\parskip{"
1954 << params.defskip.length().asLatexString()
1957 default: // should never happen // Then delete it.
1958 ofs << "\\setlength\\parskip{\\medskipamount}\n";
1963 ofs << "\\setlength\\parindent{0pt}\n";
1967 // Now insert the LyX specific LaTeX commands...
1968 string preamble, tmppreamble;
1970 // The optional packages;
1971 preamble = features.getPackages();
1973 // this might be useful...
1974 preamble += "\n\\makeatletter\n\n";
1976 // Some macros LyX will need
1977 tmppreamble = features.getMacros();
1979 if (!tmppreamble.empty()) {
1980 preamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1981 "LyX specific LaTeX commands.\n"
1982 + tmppreamble + '\n';
1985 // the text class specific preamble
1986 tmppreamble = features.getTClassPreamble();
1987 if (!tmppreamble.empty()) {
1988 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1989 "Textclass specific LaTeX commands.\n"
1990 + tmppreamble + '\n';
1993 /* the user-defined preamble */
1994 if (!params.preamble.empty()) {
1995 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1996 "User specified LaTeX commands.\n"
1997 + params.preamble + '\n';
2000 preamble += "\\makeatother\n\n";
2002 // Itemize bullet settings need to be last in case the user
2003 // defines their own bullets that use a package included
2004 // in the user-defined preamble -- ARRae
2005 // Actually it has to be done much later than that
2006 // since some packages like frenchb make modifications
2007 // at \begin{document} time -- JMarc
2009 for (int i = 0; i < 4; ++i) {
2010 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
2011 if (bullets_def.empty())
2012 bullets_def="\\AtBeginDocument{\n";
2013 bullets_def += " \\renewcommand{\\labelitemi";
2015 // `i' is one less than the item to modify
2022 bullets_def += "ii";
2028 bullets_def += "}{" +
2029 params.user_defined_bullets[i].getText()
2034 if (!bullets_def.empty())
2035 preamble += bullets_def + "}\n\n";
2037 for (int j = countChar(preamble, '\n'); j-- ;) {
2044 ofs << "\\begin{document}\n\n";
2048 lyxerr.debug() << "preamble finished, now the body." << endl;
2049 if (!lyxrc.language_auto_begin && params.language != "default") {
2050 ofs << subst(lyxrc.language_command_begin, "$$lang",
2056 latexParagraphs(ofs, paragraph, 0, texrow);
2058 // add this just in case after all the paragraphs
2062 if (!lyxrc.language_auto_end && params.language != "default") {
2063 ofs << subst(lyxrc.language_command_end, "$$lang",
2070 ofs << "\\end{document}\n";
2073 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
2075 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
2079 // Just to be sure. (Asger)
2082 // tex_code_break_column's value is used to decide
2083 // if we are in batchmode or not (within mathed_write()
2084 // in math_write.C) so we must set it to a non-zero
2085 // value when we leave otherwise we save incorrect .lyx files.
2086 tex_code_break_column = lyxrc.ascii_linelen;
2090 lyxerr << "File was not closed properly." << endl;
2093 lyxerr.debug() << "Finished making latex file." << endl;
2097 // LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
2099 void Buffer::latexParagraphs(ostream & ofs, LyXParagraph *par,
2100 LyXParagraph *endpar, TexRow & texrow)
2102 bool was_title = false;
2103 bool already_title = false;
2105 std::ostringstream ftnote;
2107 char * tmpholder = 0;
2113 while (par != endpar) {
2114 #ifndef HAVE_SSTREAM
2117 ftnote << tmpholder;
2118 delete [] tmpholder;
2123 lyxerr[Debug::LATEX] << "Error in latexParagraphs."
2125 LyXLayout const & layout =
2126 textclasslist.Style(params.textclass,
2129 if (layout.intitle) {
2130 if (already_title) {
2131 lyxerr <<"Error in latexParagraphs: You"
2132 " should not mix title layouts"
2133 " with normal ones." << endl;
2136 } else if (was_title && !already_title) {
2137 ofs << "\\maketitle\n";
2139 already_title = true;
2142 // We are at depth 0 so we can just use
2143 // ordinary \footnote{} generation
2144 // flag this with ftcount
2146 if (layout.isEnvironment()
2147 || par->pextra_type != LyXParagraph::PEXTRA_NONE) {
2148 par = par->TeXEnvironment(ofs, texrow,
2149 ftnote, ft_texrow, ftcount);
2151 par = par->TeXOnePar(ofs, texrow, false,
2152 ftnote, ft_texrow, ftcount);
2155 // Write out what we've generated...
2158 ofs << "\\addtocounter{footnote}{-"
2162 ofs << ftnote.str();
2163 texrow += ft_texrow;
2165 // The extra .c_str() is needed when we use
2166 // lyxstring instead of the STL string class.
2167 ftnote.str(string().c_str());
2169 delete [] ftnote.str();
2174 #ifndef HAVE_SSTREAM
2176 // I hate strstreams
2177 tmpholder = ftnote.str();
2181 #ifndef HAVE_SSTREAM
2182 delete [] tmpholder;
2184 // It might be that we only have a title in this document
2185 if (was_title && !already_title) {
2186 ofs << "\\maketitle\n";
2191 bool Buffer::isLatex() const
2193 return textclasslist.TextClass(params.textclass).outputType() == LATEX;
2197 bool Buffer::isLinuxDoc() const
2199 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC;
2203 bool Buffer::isLiterate() const
2205 return textclasslist.TextClass(params.textclass).outputType() == LITERATE;
2209 bool Buffer::isDocBook() const
2211 return textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2215 bool Buffer::isSGML() const
2217 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC ||
2218 textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2222 void Buffer::sgmlOpenTag(ostream & os, int depth,
2223 string const & latexname) const
2225 os << string(depth, ' ') << "<" << latexname << ">\n";
2229 void Buffer::sgmlCloseTag(ostream & os, int depth,
2230 string const & latexname) const
2232 os << string(depth, ' ') << "</" << latexname << ">\n";
2236 void Buffer::makeLinuxDocFile(string const & fname, int column)
2238 LyXParagraph * par = paragraph;
2240 string top_element = textclasslist.LatexnameOfClass(params.textclass);
2241 string environment_stack[10];
2244 int depth = 0; // paragraph depth
2246 ofstream ofs(fname.c_str());
2249 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2253 tex_code_break_column = column;
2256 if (params.preamble.empty()) {
2257 ofs << "<!doctype linuxdoc system>\n\n";
2260 ofs << "<!doctype linuxdoc system \n [ "
2261 << params.preamble << " \n]>\n\n";
2264 ofs << "<!-- " << LYX_DOCVERSION
2265 << " created this file. For more info see http://www.lyx.org/"
2268 if(params.options.empty())
2269 sgmlOpenTag(ofs, 0, top_element);
2271 string top = top_element;
2273 top += params.options;
2274 sgmlOpenTag(ofs, 0, top);
2278 int desc_on = 0; // description mode
2279 LyXLayout const & style =
2280 textclasslist.Style(users->buffer()->params.textclass,
2282 #ifdef WITH_WARNINGS
2283 #warning please check if this call is really needed!!!
2285 // par->AutoDeleteInsets();
2287 // treat <toc> as a special case for compatibility with old code
2288 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2289 Inset * inset = par->GetInset(0);
2290 Inset::Code lyx_code = inset->LyxCode();
2291 if (lyx_code == Inset::TOC_CODE){
2292 string temp = "toc";
2293 sgmlOpenTag(ofs, depth, temp);
2296 linuxDocHandleFootnote(ofs, par, depth);
2301 // environment tag closing
2302 for( ; depth > par->depth; --depth) {
2303 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2304 environment_stack[depth].erase();
2307 // write opening SGML tags
2308 switch(style.latextype) {
2309 case LATEX_PARAGRAPH:
2310 if(depth == par->depth
2311 && !environment_stack[depth].empty()) {
2312 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2313 environment_stack[depth].erase();
2319 sgmlOpenTag(ofs, depth, style.latexname());
2324 LinuxDocError(par, 0,
2325 _("Error : Wrong depth for"
2326 " LatexType Command.\n"));
2328 if (!environment_stack[depth].empty()){
2329 sgmlCloseTag(ofs, depth,
2330 environment_stack[depth]);
2334 environment_stack[depth].erase();
2335 sgmlOpenTag(ofs, depth, style.latexname());
2338 case LATEX_ENVIRONMENT:
2339 case LATEX_ITEM_ENVIRONMENT:
2340 if(depth == par->depth
2341 && environment_stack[depth] != style.latexname()
2342 && !environment_stack[depth].empty()) {
2344 sgmlCloseTag(ofs, depth,
2345 environment_stack[depth]);
2346 environment_stack[depth].erase();
2348 if (depth < par->depth) {
2350 environment_stack[depth].erase();
2352 if (environment_stack[depth] != style.latexname()) {
2355 sgmlOpenTag(ofs, depth, temp);
2357 environment_stack[depth] = style.latexname();
2358 sgmlOpenTag(ofs, depth,
2359 environment_stack[depth]);
2361 if(style.latextype == LATEX_ENVIRONMENT) break;
2363 desc_on = (style.labeltype == LABEL_MANUAL);
2370 sgmlOpenTag(ofs, depth + 1, item_name);
2373 sgmlOpenTag(ofs, depth, style.latexname());
2378 SimpleLinuxDocOnePar(ofs, par, desc_on, depth);
2381 linuxDocHandleFootnote(ofs, par, depth);
2383 while(par && par->IsDummy());
2386 // write closing SGML tags
2387 switch(style.latextype) {
2389 case LATEX_ENVIRONMENT:
2390 case LATEX_ITEM_ENVIRONMENT:
2393 sgmlCloseTag(ofs, depth, style.latexname());
2399 for(; depth > 0; --depth)
2400 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2402 if(!environment_stack[depth].empty())
2403 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2406 sgmlCloseTag(ofs, 0, top_element);
2409 // How to check for successful close
2413 void Buffer::linuxDocHandleFootnote(ostream & os, LyXParagraph * & par,
2416 string tag = "footnote";
2418 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2419 sgmlOpenTag(os, depth + 1, tag);
2420 SimpleLinuxDocOnePar(os, par, 0, depth + 1);
2421 sgmlCloseTag(os, depth + 1, tag);
2427 void Buffer::DocBookHandleCaption(ostream & os, string & inner_tag,
2428 int const depth, int desc_on,
2429 LyXParagraph * & par)
2431 LyXParagraph * tpar = par;
2432 while (tpar && (tpar->footnoteflag != LyXParagraph::NO_FOOTNOTE) &&
2433 (tpar->layout != textclasslist.NumberOfLayout(params.textclass,
2437 tpar->layout == textclasslist.NumberOfLayout(params.textclass,
2438 "Caption").second) {
2439 sgmlOpenTag(os, depth + 1, inner_tag);
2441 SimpleDocBookOnePar(os, extra_par, tpar,
2442 desc_on, depth + 2);
2443 sgmlCloseTag(os, depth+1, inner_tag);
2444 if(!extra_par.empty())
2450 void Buffer::DocBookHandleFootnote(ostream & os, LyXParagraph * & par,
2453 string tag, inner_tag;
2454 string tmp_par, extra_par;
2455 bool inner_span = false;
2458 // Someone should give this enum a proper name (Lgb)
2466 SOME_ENUM last = NO_ONE;
2467 SOME_ENUM present = FOOTNOTE_LIKE;
2469 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2470 if(last == present) {
2472 if(!tmp_par.empty()) {
2475 sgmlCloseTag(os, depth + 1, inner_tag);
2476 sgmlOpenTag(os, depth + 1, inner_tag);
2483 if(!inner_tag.empty()) sgmlCloseTag(os, depth + 1,
2485 if(!extra_par.empty()) os << extra_par;
2486 if(!tag.empty()) sgmlCloseTag(os, depth, tag);
2489 switch (par->footnotekind) {
2490 case LyXParagraph::FOOTNOTE:
2491 case LyXParagraph::ALGORITHM:
2494 present = FOOTNOTE_LIKE;
2497 case LyXParagraph::MARGIN:
2500 present = MARGIN_LIKE;
2503 case LyXParagraph::FIG:
2504 case LyXParagraph::WIDE_FIG:
2506 inner_tag = "title";
2510 case LyXParagraph::TAB:
2511 case LyXParagraph::WIDE_TAB:
2513 inner_tag = "title";
2518 sgmlOpenTag(os, depth, tag);
2519 if ((present == TAB_LIKE) || (present == FIG_LIKE)) {
2520 DocBookHandleCaption(os, inner_tag, depth,
2524 sgmlOpenTag(os, depth + 1, inner_tag);
2527 // ignore all caption here, we processed them above!!!
2528 if (par->layout != textclasslist
2529 .NumberOfLayout(params.textclass,
2530 "Caption").second) {
2532 std::ostringstream ost;
2536 SimpleDocBookOnePar(ost, extra_par, par,
2537 desc_on, depth + 2);
2539 tmp_par += ost.str().c_str();
2542 char * ctmp = ost.str();
2547 tmp_par = frontStrip(strip(tmp_par));
2553 if(!inner_tag.empty()) sgmlCloseTag(os, depth + 1, inner_tag);
2554 if(!extra_par.empty()) os << extra_par;
2555 if(!tag.empty()) sgmlCloseTag(os, depth, tag);
2559 // push a tag in a style stack
2560 void Buffer::push_tag(ostream & os, char const * tag,
2561 int & pos, char stack[5][3])
2563 // pop all previous tags
2564 for (int j = pos; j >= 0; --j)
2565 os << "</" << stack[j] << ">";
2568 sprintf(stack[++pos], "%s", tag);
2571 for (int i = 0; i <= pos; ++i)
2572 os << "<" << stack[i] << ">";
2576 void Buffer::pop_tag(ostream & os, char const * tag,
2577 int & pos, char stack[5][3])
2581 // pop all tags till specified one
2582 for (j = pos; (j >= 0) && (strcmp(stack[j], tag)); --j)
2583 os << "</" << stack[j] << ">";
2586 os << "</" << tag << ">";
2588 // push all tags, but the specified one
2589 for (j = j + 1; j <= pos; ++j) {
2590 os << "<" << stack[j] << ">";
2591 strcpy(stack[j-1], stack[j]);
2597 // Handle internal paragraph parsing -- layout already processed.
2599 // checks, if newcol chars should be put into this line
2600 // writes newline, if necessary.
2602 void linux_doc_line_break(ostream & os, unsigned int & colcount,
2603 const unsigned int newcol)
2606 if (colcount > lyxrc.ascii_linelen) {
2608 colcount = newcol; // assume write after this call
2613 void Buffer::SimpleLinuxDocOnePar(ostream & os, LyXParagraph * par,
2614 int desc_on, int const /*depth*/)
2616 LyXFont font1, font2;
2619 LyXParagraph::size_type main_body;
2621 LyXLayout const & style = textclasslist.Style(params.textclass,
2624 char family_type = 0; // family font flag
2625 bool is_bold = false; // series font flag
2626 char shape_type = 0; // shape font flag
2627 bool is_em = false; // emphasis (italic) font flag
2629 int stack_num = -1; // style stack position
2630 // Can this be rewritten to use a std::stack, please. (Lgb)
2631 char stack[5][3]; // style stack
2632 unsigned int char_line_count = 5; // Heuristic choice ;-)
2634 if (style.labeltype != LABEL_MANUAL)
2637 main_body = par->BeginningOfMainBody();
2639 // gets paragraph main font
2641 font1 = style.labelfont;
2646 // parsing main loop
2647 for (LyXParagraph::size_type i = 0;
2648 i < par->size(); ++i) {
2651 if (i == main_body && !par->IsDummy()) {
2656 font2 = par->getFont(i);
2658 if (font1.family() != font2.family()) {
2659 switch(family_type) {
2661 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2662 push_tag(os, "tt", stack_num, stack);
2665 else if (font2.family() == LyXFont::SANS_FAMILY) {
2666 push_tag(os, "sf", stack_num, stack);
2671 pop_tag(os, "tt", stack_num, stack);
2672 if (font2.family() == LyXFont::SANS_FAMILY) {
2673 push_tag(os, "sf", stack_num, stack);
2681 pop_tag(os, "sf", stack_num, stack);
2682 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2683 push_tag(os, "tt", stack_num, stack);
2693 if (font1.series() != font2.series()) {
2694 if (font2.series() == LyXFont::BOLD_SERIES) {
2695 push_tag(os, "bf", stack_num, stack);
2699 pop_tag(os, "bf", stack_num, stack);
2704 // handle italic and slanted fonts
2705 if (font1.shape() != font2.shape()) {
2706 switch(shape_type) {
2708 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2709 push_tag(os, "it", stack_num, stack);
2712 else if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2713 push_tag(os, "sl", stack_num, stack);
2718 pop_tag(os, "it", stack_num, stack);
2719 if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2720 push_tag(os, "sl", stack_num, stack);
2728 pop_tag(os, "sl", stack_num, stack);
2729 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2730 push_tag(os, "it", stack_num, stack);
2739 if (font1.emph() != font2.emph()) {
2740 if (font2.emph() == LyXFont::ON) {
2741 push_tag(os, "em", stack_num, stack);
2744 pop_tag(os, "em", stack_num, stack);
2749 c = par->GetChar(i);
2751 if (font2.latex() == LyXFont::ON) {
2752 // "TeX"-Mode on == > SGML-Mode on.
2754 os << c; // see LaTeX-Generation...
2756 } else if (c == LyXParagraph::META_INSET) {
2757 inset = par->GetInset(i);
2758 inset->Linuxdoc(os);
2761 if (par->linuxDocConvertChar(c, sgml_string)
2762 && !style.free_spacing) { // in freespacing
2764 // non-breaking characters
2768 linux_doc_line_break(os, char_line_count, 6);
2773 linux_doc_line_break(os, char_line_count, 1);
2779 char_line_count += sgml_string.length();
2785 // needed if there is an optional argument but no contents
2786 if (main_body > 0 && main_body == par->size()) {
2790 // pop all defined Styles
2791 for (j = stack_num; j >= 0; --j) {
2792 linux_doc_line_break(os,
2794 3 + strlen(stack[j]));
2795 os << "</" << stack[j] << ">";
2798 // resets description flag correctly
2801 // <tag> not closed...
2802 linux_doc_line_break(os, char_line_count, 6);
2806 // fprintf(file, "</p>");
2812 // Print an error message.
2813 void Buffer::LinuxDocError(LyXParagraph * par, int pos,
2814 char const * message)
2816 InsetError * new_inset;
2818 // insert an error marker in text
2819 new_inset = new InsetError(message);
2820 par->InsertChar(pos, LyXParagraph::META_INSET);
2821 par->InsertInset(pos, new_inset);
2824 // This constant defines the maximum number of
2825 // environment layouts that can be nesteded.
2826 // The same applies for command layouts.
2827 // These values should be more than enough.
2828 // José Matos (1999/07/22)
2830 enum { MAX_NEST_LEVEL = 25};
2832 void Buffer::makeDocBookFile(string const & fname, int column)
2834 LyXParagraph * par = paragraph;
2836 string top_element= textclasslist.LatexnameOfClass(params.textclass);
2837 // Please use a real stack.
2838 string environment_stack[MAX_NEST_LEVEL];
2839 string environment_inner[MAX_NEST_LEVEL];
2840 // Please use a real stack.
2841 string command_stack[MAX_NEST_LEVEL];
2842 bool command_flag= false;
2843 int command_depth= 0, command_base= 0, cmd_depth= 0;
2845 string item_name, command_name;
2846 string c_depth, c_params, tmps;
2848 int depth = 0; // paragraph depth
2850 tex_code_break_column = column;
2852 ofstream ofs(fname.c_str());
2854 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2860 ofs << "<!doctype " << top_element
2861 << " public \"-//OASIS//DTD DocBook V3.1//EN\"";
2863 if (params.preamble.empty())
2866 ofs << "\n [ " << params.preamble << " \n]>\n\n";
2868 ofs << "<!-- DocBook file was created by " << LYX_DOCVERSION
2869 << "\n See http://www.lyx.org/ for more information -->\n";
2871 if(params.options.empty())
2872 sgmlOpenTag(ofs, 0, top_element);
2874 string top = top_element;
2876 top += params.options;
2877 sgmlOpenTag(ofs, 0, top);
2881 int desc_on = 0; // description mode
2882 LyXLayout const & style =
2883 textclasslist.Style(users->buffer()->params.textclass,
2885 #ifdef WITH_WARNINGS
2886 #warning please check if this call is really needed!!!
2888 // par->AutoDeleteInsets();
2890 // environment tag closing
2891 for( ; depth > par->depth; --depth) {
2892 if(environment_inner[depth] != "!-- --") {
2893 item_name= "listitem";
2894 sgmlCloseTag(ofs, command_depth + depth,
2896 if( environment_inner[depth] == "varlistentry")
2897 sgmlCloseTag(ofs, depth+command_depth,
2898 environment_inner[depth]);
2900 sgmlCloseTag(ofs, depth + command_depth,
2901 environment_stack[depth]);
2902 environment_stack[depth].erase();
2903 environment_inner[depth].erase();
2906 if(depth == par->depth
2907 && environment_stack[depth] != style.latexname()
2908 && !environment_stack[depth].empty()) {
2909 if(environment_inner[depth] != "!-- --") {
2910 item_name= "listitem";
2911 sgmlCloseTag(ofs, command_depth+depth,
2913 if( environment_inner[depth] == "varlistentry")
2915 depth + command_depth,
2916 environment_inner[depth]);
2919 sgmlCloseTag(ofs, depth + command_depth,
2920 environment_stack[depth]);
2922 environment_stack[depth].erase();
2923 environment_inner[depth].erase();
2926 // Write opening SGML tags.
2927 switch(style.latextype) {
2928 case LATEX_PARAGRAPH:
2929 if(style.latexname() != "dummy")
2930 sgmlOpenTag(ofs, depth+command_depth,
2936 LinuxDocError(par, 0,
2937 _("Error : Wrong depth for "
2938 "LatexType Command.\n"));
2940 command_name = style.latexname();
2942 tmps = style.latexparam();
2943 c_params = split(tmps, c_depth,'|');
2945 cmd_depth= atoi(c_depth.c_str());
2948 if(cmd_depth<command_base) {
2949 for(int j = command_depth;
2950 j >= command_base; --j)
2951 if(!command_stack[j].empty())
2952 sgmlCloseTag(ofs, j, command_stack[j]);
2953 command_depth= command_base= cmd_depth;
2955 else if(cmd_depth <= command_depth) {
2956 for(int j = command_depth;
2957 j >= cmd_depth; --j)
2959 if(!command_stack[j].empty())
2960 sgmlCloseTag(ofs, j, command_stack[j]);
2961 command_depth= cmd_depth;
2964 command_depth= cmd_depth;
2967 command_depth = command_base = cmd_depth;
2968 command_flag = true;
2970 command_stack[command_depth]= command_name;
2972 // treat label as a special case for
2973 // more WYSIWYM handling.
2974 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2975 Inset * inset = par->GetInset(0);
2976 Inset::Code lyx_code = inset->LyxCode();
2977 if (lyx_code == Inset::LABEL_CODE){
2978 command_name += " id=\"";
2979 command_name += (static_cast<InsetCommand *>(inset))->getContents();
2980 command_name += "\"";
2985 sgmlOpenTag(ofs, depth + command_depth, command_name);
2986 item_name = "title";
2987 sgmlOpenTag(ofs, depth + 1 + command_depth, item_name);
2990 case LATEX_ENVIRONMENT:
2991 case LATEX_ITEM_ENVIRONMENT:
2992 if (depth < par->depth) {
2994 environment_stack[depth].erase();
2997 if (environment_stack[depth] != style.latexname()) {
2998 environment_stack[depth] = style.latexname();
2999 environment_inner[depth] = "!-- --";
3000 sgmlOpenTag(ofs, depth + command_depth,
3001 environment_stack[depth]);
3003 if(environment_inner[depth] != "!-- --") {
3004 item_name= "listitem";
3006 command_depth + depth,
3008 if (environment_inner[depth] == "varlistentry")
3010 depth + command_depth,
3011 environment_inner[depth]);
3015 if(style.latextype == LATEX_ENVIRONMENT) {
3016 if(!style.latexparam().empty())
3017 sgmlOpenTag(ofs, depth + command_depth,
3018 style.latexparam());
3022 desc_on = (style.labeltype == LABEL_MANUAL);
3025 environment_inner[depth]= "varlistentry";
3027 environment_inner[depth]= "listitem";
3029 sgmlOpenTag(ofs, depth + 1 + command_depth,
3030 environment_inner[depth]);
3034 sgmlOpenTag(ofs, depth + 1 + command_depth,
3039 sgmlOpenTag(ofs, depth + 1 + command_depth,
3044 sgmlOpenTag(ofs, depth + command_depth,
3051 SimpleDocBookOnePar(ofs, extra_par, par, desc_on,
3052 depth + 1 + command_depth);
3054 DocBookHandleFootnote(ofs, par,
3055 depth + 1 + command_depth);
3057 while(par && par->IsDummy());
3060 // write closing SGML tags
3061 switch(style.latextype) {
3064 sgmlCloseTag(ofs, depth + command_depth, end_tag);
3066 case LATEX_ENVIRONMENT:
3067 if(!style.latexparam().empty())
3068 sgmlCloseTag(ofs, depth + command_depth,
3069 style.latexparam());
3071 case LATEX_ITEM_ENVIRONMENT:
3072 if(desc_on == 1) break;
3074 sgmlCloseTag(ofs, depth + 1 + command_depth, end_tag);
3076 case LATEX_PARAGRAPH:
3077 if(style.latexname() != "dummy")
3078 sgmlCloseTag(ofs, depth + command_depth,
3082 sgmlCloseTag(ofs, depth + command_depth,
3089 for(; depth >= 0; --depth) {
3090 if(!environment_stack[depth].empty()) {
3091 if(environment_inner[depth] != "!-- --") {
3092 item_name= "listitem";
3093 sgmlCloseTag(ofs, command_depth + depth,
3095 if( environment_inner[depth] == "varlistentry")
3096 sgmlCloseTag(ofs, depth + command_depth,
3097 environment_inner[depth]);
3100 sgmlCloseTag(ofs, depth + command_depth,
3101 environment_stack[depth]);
3105 for(int j = command_depth; j >= command_base; --j)
3106 if(!command_stack[j].empty())
3107 sgmlCloseTag(ofs, j, command_stack[j]);
3110 sgmlCloseTag(ofs, 0, top_element);
3113 // How to check for successful close
3117 void Buffer::SimpleDocBookOnePar(ostream & os, string & extra,
3118 LyXParagraph * par, int & desc_on,
3122 par->SimpleDocBookOneTablePar(os, extra, desc_on, depth);
3126 bool emph_flag = false;
3128 LyXLayout const & style = textclasslist.Style(params.textclass,
3131 LyXParagraph::size_type main_body;
3132 if (style.labeltype != LABEL_MANUAL)
3135 main_body = par->BeginningOfMainBody();
3137 // gets paragraph main font
3138 LyXFont font1 = main_body > 0 ? style.labelfont : style.font;
3140 int char_line_count = depth;
3141 if(!style.free_spacing)
3142 for (int j = 0; j < depth; ++j)
3145 // parsing main loop
3146 for (LyXParagraph::size_type i = 0;
3147 i < par->size(); ++i) {
3148 LyXFont font2 = par->getFont(i);
3150 // handle <emphasis> tag
3151 if (font1.emph() != font2.emph() && i) {
3152 if (font2.emph() == LyXFont::ON) {
3156 os << "</emphasis>";
3161 char c = par->GetChar(i);
3163 if (c == LyXParagraph::META_INSET) {
3164 Inset * inset = par->GetInset(i);
3166 std::ostringstream ost;
3167 inset->DocBook(ost);
3168 string tmp_out = ost.str().c_str();
3171 inset->DocBook(ost);
3173 char * ctmp = ost.str();
3174 string tmp_out(ctmp);
3178 // This code needs some explanation:
3179 // Two insets are treated specially
3180 // label if it is the first element in a command paragraph
3182 // graphics inside tables or figure floats can't go on
3183 // title (the equivalente in latex for this case is caption
3184 // and title should come first
3187 if(desc_on!= 3 || i!= 0) {
3188 if(!tmp_out.empty() && tmp_out[0] == '@') {
3190 extra += frontStrip(tmp_out, '@');
3192 os << frontStrip(tmp_out, '@');
3197 } else if (font2.latex() == LyXFont::ON) {
3198 // "TeX"-Mode on ==> SGML-Mode on.
3204 if (par->linuxDocConvertChar(c, sgml_string)
3205 && !style.free_spacing) { // in freespacing
3207 // non-breaking characters
3211 os << "\n</term><listitem><para>";
3223 // needed if there is an optional argument but no contents
3224 if (main_body > 0 && main_body == par->size()) {
3228 os << "</emphasis>";
3231 // resets description flag correctly
3234 // <term> not closed...
3242 int Buffer::runLaTeX()
3244 if (!users->text) return 0;
3246 ProhibitInput(users);
3248 // get LaTeX-Filename
3249 string name = getLatexName();
3251 string path = OnlyPath(filename);
3253 string org_path = path;
3254 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3258 Path p(path); // path to LaTeX file
3259 users->owner()->getMiniBuffer()->Set(_("Running LaTeX..."));
3261 // Remove all error insets
3262 bool a = users->removeAutoInsets();
3264 // Always generate the LaTeX file
3265 makeLaTeXFile(name, org_path, false);
3268 // do the LaTex run(s)
3270 string latex_command = lyxrc.pdf_mode ?
3271 lyxrc.pdflatex_command : lyxrc.latex_command;
3272 LaTeX latex(latex_command, name, filepath);
3273 int res = latex.run(terr,
3274 users->owner()->getMiniBuffer()); // running latex
3276 // check return value from latex.run().
3277 if ((res & LaTeX::NO_LOGFILE)) {
3278 WriteAlert(_("LaTeX did not work!"),
3279 _("Missing log file:"), name);
3280 } else if ((res & LaTeX::ERRORS)) {
3281 users->owner()->getMiniBuffer()->Set(_("Done"));
3282 // Insert all errors as errors boxes
3283 users->insertErrors(terr);
3285 // Dvi should also be kept dirty if the latex run
3286 // ends up with errors. However it should be possible
3287 // to view a dirty dvi too.
3289 //no errors or any other things to think about so:
3290 users->owner()->getMiniBuffer()->Set(_("Done"));
3294 // if we removed error insets before we ran LaTeX or if we inserted
3295 // error insets after we ran LaTeX this must be run:
3296 if (a || (res & LaTeX::ERRORS)){
3299 //users->updateScrollbar();
3303 return latex.getNumErrors();
3307 int Buffer::runLiterate()
3309 if (!users->text) return 0;
3311 ProhibitInput(users);
3313 // get LaTeX-Filename
3314 string name = getLatexName();
3315 // get Literate-Filename
3316 string lit_name = OnlyFilename(ChangeExtension (getLatexName(),
3317 lyxrc.literate_extension));
3319 string path = OnlyPath(filename);
3321 string org_path = path;
3322 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3326 Path p(path); // path to Literate file
3327 users->owner()->getMiniBuffer()->Set(_("Running Literate..."));
3329 // Remove all error insets
3330 bool a = users->removeAutoInsets();
3332 // generate the Literate file if necessary
3333 if (!isDviClean() || a) {
3334 makeLaTeXFile(lit_name, org_path, false);
3338 string latex_command = lyxrc.pdf_mode ?
3339 lyxrc.pdflatex_command : lyxrc.latex_command;
3340 Literate literate(latex_command, name, filepath,
3342 lyxrc.literate_command, lyxrc.literate_error_filter,
3343 lyxrc.build_command, lyxrc.build_error_filter);
3345 int res = literate.weave(terr, users->owner()->getMiniBuffer());
3347 // check return value from literate.weave().
3348 if ((res & Literate::NO_LOGFILE)) {
3349 WriteAlert(_("Literate command did not work!"),
3350 _("Missing log file:"), name);
3351 } else if ((res & Literate::ERRORS)) {
3352 users->owner()->getMiniBuffer()->Set(_("Done"));
3353 // Insert all errors as errors boxes
3354 users->insertErrors(terr);
3356 // Dvi should also be kept dirty if the latex run
3357 // ends up with errors. However it should be possible
3358 // to view a dirty dvi too.
3360 //no errors or any other things to think about so:
3361 users->owner()->getMiniBuffer()->Set(_("Done"));
3365 // if we removed error insets before we ran LaTeX or if we inserted
3366 // error insets after we ran LaTeX this must be run:
3367 if (a || (res & Literate::ERRORS)){
3370 //users->updateScrollbar();
3374 return literate.getNumErrors();
3378 int Buffer::buildProgram()
3380 if (!users->text) return 0;
3382 ProhibitInput(users);
3384 // get LaTeX-Filename
3385 string name = getLatexName();
3386 // get Literate-Filename
3387 string lit_name = OnlyFilename(ChangeExtension(getLatexName(),
3388 lyxrc.literate_extension));
3390 string path = OnlyPath(filename);
3392 string org_path = path;
3393 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3397 Path p(path); // path to Literate file
3398 users->owner()->getMiniBuffer()->Set(_("Building Program..."));
3400 // Remove all error insets
3401 bool a = users->removeAutoInsets();
3403 // generate the LaTeX file if necessary
3404 if (!isNwClean() || a) {
3405 makeLaTeXFile(lit_name, org_path, false);
3409 string latex_command = lyxrc.pdf_mode ?
3410 lyxrc.pdflatex_command : lyxrc.latex_command;
3411 Literate literate(latex_command, name, filepath,
3413 lyxrc.literate_command, lyxrc.literate_error_filter,
3414 lyxrc.build_command, lyxrc.build_error_filter);
3416 int res = literate.build(terr, users->owner()->getMiniBuffer());
3418 // check return value from literate.build().
3419 if ((res & Literate::NO_LOGFILE)) {
3420 WriteAlert(_("Build did not work!"),
3421 _("Missing log file:"), name);
3422 } else if ((res & Literate::ERRORS)) {
3423 users->owner()->getMiniBuffer()->Set(_("Done"));
3424 // Insert all errors as errors boxes
3425 users->insertErrors(terr);
3427 // Literate files should also be kept dirty if the literate
3428 // command run ends up with errors.
3430 //no errors or any other things to think about so:
3431 users->owner()->getMiniBuffer()->Set(_("Done"));
3435 // if we removed error insets before we ran Literate/Build or
3436 // if we inserted error insets after we ran Literate/Build this
3438 if (a || (res & Literate::ERRORS)){
3441 //users->updateScrollbar();
3445 return literate.getNumErrors();
3449 // This should be enabled when the Chktex class is implemented. (Asger)
3450 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
3451 // Other flags: -wall -v0 -x
3452 int Buffer::runChktex()
3454 if (!users->text) return 0;
3456 ProhibitInput(users);
3458 // get LaTeX-Filename
3459 string name = getLatexName();
3460 string path = OnlyPath(filename);
3462 string org_path = path;
3463 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3467 Path p(path); // path to LaTeX file
3468 users->owner()->getMiniBuffer()->Set(_("Running chktex..."));
3470 // Remove all error insets
3471 bool a = users->removeAutoInsets();
3473 // Generate the LaTeX file if neccessary
3474 if (!isDviClean() || a) {
3475 makeLaTeXFile(name, org_path, false);
3480 Chktex chktex(lyxrc.chktex_command, name, filepath);
3481 int res = chktex.run(terr); // run chktex
3484 WriteAlert(_("chktex did not work!"),
3485 _("Could not run with file:"), name);
3486 } else if (res > 0) {
3487 // Insert all errors as errors boxes
3488 users->insertErrors(terr);
3491 // if we removed error insets before we ran chktex or if we inserted
3492 // error insets after we ran chktex, this must be run:
3496 //users->updateScrollbar();
3505 void Buffer::RoffAsciiTable(ostream & os, LyXParagraph * par)
3507 LyXFont font1(LyXFont::ALL_INHERIT,params.language_info);
3510 LyXParagraph::size_type i;
3514 string fname1 = TmpFileName(string(), "RAT1");
3515 string fname2 = TmpFileName(string(), "RAT2");
3517 ofstream ofs(fname1.c_str());
3519 WriteAlert(_("LYX_ERROR:"),
3520 _("Cannot open temporary file:"), fname1);
3523 par->table->RoffEndOfCell(ofs, -1);
3524 for (i = 0; i < par->size(); ++i) {
3525 c = par->GetChar(i);
3526 if (par->table->IsContRow(cell)) {
3527 if (c == LyXParagraph::META_NEWLINE)
3531 font2 = par->GetFontSettings(i);
3532 if (font1.latex() != font2.latex()) {
3533 if (font2.latex() != LyXFont::OFF)
3537 case LyXParagraph::META_INSET:
3538 if ((inset = par->GetInset(i))) {
3540 stringstresm ss(ios::in | ios::out);
3567 case LyXParagraph::META_NEWLINE:
3568 if (par->table->CellHasContRow(cell)>= 0)
3569 par->RoffContTableRows(ofs, i+1, cell);
3570 par->table->RoffEndOfCell(ofs, cell);
3573 case LyXParagraph::META_HFILL:
3583 << "RoffAsciiTable:"
3584 " NULL char in structure." << endl;
3588 par->table->RoffEndOfCell(ofs, cell);
3590 string cmd = lyxrc.ascii_roff_command + " >" + fname2;
3591 cmd = subst(cmd, "$$FName", fname1);
3592 Systemcalls one(Systemcalls::System, cmd);
3593 if (!(lyxerr.debugging(Debug::ROFF))) {
3594 remove(fname1.c_str());
3596 ifstream ifs(fname2.c_str());
3598 WriteFSAlert(_("Error! Can't open temporary file:"), fname2);
3601 // now output the produced file
3605 WriteAlert(_("Error!"),
3606 _("Error executing *roff command on table"));
3607 // overread leading blank lines
3608 while(!ifs && (c == '\n'))
3611 for(j = 0; j < par->depth; ++j)
3613 while(!ifs && (c != '\n')) {
3618 // overread trailing blank lines
3619 while(!ifs && (c == '\n'))
3623 remove(fname2.c_str());
3628 /// changed Heinrich Bauer, 23/03/98
3629 bool Buffer::isDviClean() const
3631 if (lyxrc.use_tempdir)
3632 return dvi_clean_tmpd;
3634 return dvi_clean_orgd;
3638 /// changed Heinrich Bauer, 23/03/98
3639 void Buffer::markDviClean()
3641 if (lyxrc.use_tempdir)
3642 dvi_clean_tmpd = true;
3644 dvi_clean_orgd = true;
3648 /// changed Heinrich Bauer, 23/03/98
3649 void Buffer::markDviDirty()
3651 if (lyxrc.use_tempdir)
3652 dvi_clean_tmpd = false;
3654 dvi_clean_orgd = false;
3658 void Buffer::validate(LaTeXFeatures & features) const
3660 LyXParagraph * par = paragraph;
3661 LyXTextClass const & tclass =
3662 textclasslist.TextClass(params.textclass);
3664 // AMS Style is at document level
3666 features.amsstyle = (params.use_amsmath ||
3667 tclass.provides(LyXTextClass::amsmath));
3670 // We don't use "lyxerr.debug" because of speed. (Asger)
3671 if (lyxerr.debugging(Debug::LATEX))
3672 lyxerr << "Paragraph: " << par << endl;
3674 // Now just follow the list of paragraphs and run
3675 // validate on each of them.
3676 par->validate(features);
3678 // and then the next paragraph
3682 // the bullet shapes are buffer level not paragraph level
3683 // so they are tested here
3684 for (int i = 0; i < 4; ++i) {
3685 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
3686 int font = params.user_defined_bullets[i].getFont();
3689 .user_defined_bullets[i]
3696 features.latexsym = true;
3700 features.amssymb = true;
3702 else if ((font >= 2 && font <= 5)) {
3703 features.pifont = true;
3708 if (lyxerr.debugging(Debug::LATEX)) {
3709 features.showStruct();
3714 void Buffer::setPaperStuff()
3716 params.papersize = BufferParams::PAPER_DEFAULT;
3717 char c1 = params.paperpackage;
3718 if (c1 == BufferParams::PACKAGE_NONE) {
3719 char c2 = params.papersize2;
3720 if (c2 == BufferParams::VM_PAPER_USLETTER)
3721 params.papersize = BufferParams::PAPER_USLETTER;
3722 else if (c2 == BufferParams::VM_PAPER_USLEGAL)
3723 params.papersize = BufferParams::PAPER_LEGALPAPER;
3724 else if (c2 == BufferParams::VM_PAPER_USEXECUTIVE)
3725 params.papersize = BufferParams::PAPER_EXECUTIVEPAPER;
3726 else if (c2 == BufferParams::VM_PAPER_A3)
3727 params.papersize = BufferParams::PAPER_A3PAPER;
3728 else if (c2 == BufferParams::VM_PAPER_A4)
3729 params.papersize = BufferParams::PAPER_A4PAPER;
3730 else if (c2 == BufferParams::VM_PAPER_A5)
3731 params.papersize = BufferParams::PAPER_A5PAPER;
3732 else if ((c2 == BufferParams::VM_PAPER_B3) || (c2 == BufferParams::VM_PAPER_B4) ||
3733 (c2 == BufferParams::VM_PAPER_B5))
3734 params.papersize = BufferParams::PAPER_B5PAPER;
3735 } else if ((c1 == BufferParams::PACKAGE_A4) || (c1 == BufferParams::PACKAGE_A4WIDE) ||
3736 (c1 == BufferParams::PACKAGE_WIDEMARGINSA4))
3737 params.papersize = BufferParams::PAPER_A4PAPER;
3741 // This function should be in Buffer because it's a buffer's property (ale)
3742 string Buffer::getIncludeonlyList(char delim)
3745 for (inset_iterator it = inset_iterator_begin();
3746 it != inset_iterator_end(); ++it) {
3747 if ((*it)->LyxCode() == Inset::INCLUDE_CODE) {
3748 InsetInclude * insetinc =
3749 static_cast<InsetInclude *>(*it);
3750 if (insetinc->isInclude()
3751 && insetinc->isNoLoad()) {
3754 lst += OnlyFilename(ChangeExtension(insetinc->getContents(), string()));
3758 lyxerr.debug() << "Includeonly(" << lst << ')' << endl;
3763 vector<string> Buffer::getLabelList()
3765 /// if this is a child document and the parent is already loaded
3766 /// Use the parent's list instead [ale990407]
3767 if (!params.parentname.empty()
3768 && bufferlist.exists(params.parentname)) {
3769 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3771 return tmp->getLabelList();
3774 vector<string> label_list;
3775 for (inset_iterator it = inset_iterator_begin();
3776 it != inset_iterator_end(); ++it) {
3777 vector<string> l = (*it)->getLabelList();
3778 label_list.insert(label_list.end(), l.begin(), l.end());
3784 vector<vector<Buffer::TocItem> > Buffer::getTocList()
3786 vector<vector<TocItem> > l(4);
3787 LyXParagraph * par = paragraph;
3789 if (par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
3790 if (textclasslist.Style(params.textclass,
3791 par->GetLayout()).labeltype
3792 == LABEL_SENSITIVE) {
3796 tmp.str = par->String(false);
3797 switch (par->footnotekind) {
3798 case LyXParagraph::FIG:
3799 case LyXParagraph::WIDE_FIG:
3800 l[TOC_LOF].push_back(tmp);
3802 case LyXParagraph::TAB:
3803 case LyXParagraph::WIDE_TAB:
3804 l[TOC_LOT].push_back(tmp);
3806 case LyXParagraph::ALGORITHM:
3807 l[TOC_LOA].push_back(tmp);
3809 case LyXParagraph::FOOTNOTE:
3810 case LyXParagraph::MARGIN:
3814 } else if (!par->IsDummy()) {
3815 char labeltype = textclasslist.Style(params.textclass,
3816 par->GetLayout()).labeltype;
3818 if (labeltype >= LABEL_COUNTER_CHAPTER
3819 && labeltype <= LABEL_COUNTER_CHAPTER + params.tocdepth) {
3820 // insert this into the table of contents
3825 textclasslist.TextClass(params.textclass).maxcounter());
3826 tmp.str = par->String(true);
3827 l[TOC_TOC].push_back(tmp);
3835 // This is also a buffer property (ale)
3836 string Buffer::getBibkeyList(char delim)
3838 /// if this is a child document and the parent is already loaded
3839 /// Use the parent's list instead [ale990412]
3840 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3841 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3843 return tmp->getBibkeyList(delim);
3847 LyXParagraph * par = paragraph;
3850 if (!bibkeys.empty())
3852 bibkeys += par->bibkey->getContents();
3857 // Might be either using bibtex or a child has bibliography
3858 if (bibkeys.empty()) {
3859 for (inset_iterator it = inset_iterator_begin();
3860 it != inset_iterator_end(); ++it) {
3861 // Search for Bibtex or Include inset
3862 if ((*it)->LyxCode() == Inset::BIBTEX_CODE) {
3863 if (!bibkeys.empty())
3865 bibkeys += static_cast<InsetBibtex *>(*it)->getKeys(delim);
3866 } else if ((*it)->LyxCode() == Inset::INCLUDE_CODE) {
3867 string bk(static_cast<InsetInclude *>(*it)->getKeys(delim));
3869 if (!bibkeys.empty())
3877 lyxerr.debug() << "Bibkeys(" << bibkeys << ")" << endl;
3882 bool Buffer::isDepClean(string const & name) const
3884 DEPCLEAN * item = dep_clean;
3885 while (item && item->master != name)
3887 if (!item) return true;
3892 void Buffer::markDepClean(string const & name)
3895 dep_clean = new DEPCLEAN;
3896 dep_clean->clean = true;
3897 dep_clean->master = name;
3898 dep_clean->next = 0;
3900 DEPCLEAN* item = dep_clean;
3901 while (item && item->master != name)
3906 item = new DEPCLEAN;
3908 item->master = name;
3915 bool Buffer::Dispatch(string const & command)
3917 // Split command string into command and argument
3918 string cmd, line = frontStrip(command);
3919 string arg = strip(frontStrip(split(line, cmd, ' ')));
3921 return Dispatch(lyxaction.LookupFunc(cmd.c_str()), arg.c_str());
3925 bool Buffer::Dispatch(int action, string const & argument)
3927 bool dispatched = true;
3930 MenuExport(this, argument);
3940 void Buffer::ChangeLanguage(Language const * from, Language const * to)
3943 LyXParagraph * par = paragraph;
3945 par->ChangeLanguage(from, to);
3951 bool Buffer::isMultiLingual()
3954 LyXParagraph * par = paragraph;
3956 if (par->isMultiLingual())
3964 Buffer::inset_iterator::inset_iterator(LyXParagraph * paragraph,
3965 LyXParagraph::size_type pos)
3967 it = par->InsetIterator(pos);
3968 if (it == par->inset_iterator_end()) {
3975 void Buffer::inset_iterator::SetParagraph() {
3977 it = par->inset_iterator_begin();
3978 if (it != par->inset_iterator_end())
3983 // We maintain an invariant that whenever par = 0 then it = 0