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/insetcite.h"
64 #include "insets/insetindex.h"
65 #include "insets/insetinclude.h"
66 #include "insets/insettoc.h"
67 #include "insets/insetlof.h"
68 #include "insets/insetlot.h"
69 #include "insets/insetloa.h"
70 #include "insets/insetparent.h"
71 #include "insets/insetspecialchar.h"
72 #include "insets/figinset.h"
73 #include "insets/insettext.h"
74 #include "insets/insetert.h"
75 #include "insets/insetgraphics.h"
76 #include "insets/insetfoot.h"
77 #include "insets/insettabular.h"
78 #include "support/filetools.h"
79 #include "support/path.h"
85 #include "LaTeXFeatures.h"
86 #include "support/syscall.h"
87 #include "support/lyxlib.h"
88 #include "support/FileInfo.h"
104 // all these externs should eventually be removed.
105 extern BufferList bufferlist;
107 extern void MenuExport(Buffer *, string const &);
108 extern LyXAction lyxaction;
111 static const float LYX_FORMAT = 2.16;
113 extern int tex_code_break_column;
116 Buffer::Buffer(string const & file, bool ronly)
118 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
120 filepath = OnlyPath(file);
124 dvi_clean_orgd = false; // Heinrich Bauer, 23/03/98
125 dvi_clean_tmpd = false; // Heinrich Bauer, 23/03/98
130 if (read_only || (lyxrc.use_tempdir)) {
131 tmppath = CreateBufferTmpDir();
132 } else tmppath.erase();
138 lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
139 // here the buffer should take care that it is
140 // saved properly, before it goes into the void.
142 // make sure that views using this buffer
147 if (!tmppath.empty()) {
148 DestroyBufferTmpDir(tmppath);
151 LyXParagraph * par = paragraph;
152 LyXParagraph * tmppar;
162 string Buffer::getLatexName(bool no_path) const
165 return OnlyFilename(ChangeExtension(MakeLatexName(filename),
168 return ChangeExtension(MakeLatexName(filename),
173 void Buffer::setReadonly(bool flag)
175 if (read_only != flag) {
178 updateAllVisibleBufferRelatedPopups();
181 WarnReadonly(filename);
186 bool Buffer::saveParamsAsDefaults()
188 string fname = AddName(AddPath(user_lyxdir, "templates/"),
190 Buffer defaults = Buffer(fname);
192 // Use the current buffer's parameters as default
193 defaults.params = params;
195 // add an empty paragraph. Is this enough?
196 defaults.paragraph = new LyXParagraph;
198 return defaults.writeFile(defaults.filename, false);
202 /// Update window titles of all users
203 // Should work on a list
204 void Buffer::updateTitles() const
206 if (users) users->owner()->updateWindowTitle();
210 /// Reset autosave timer of all users
211 // Should work on a list
212 void Buffer::resetAutosaveTimers() const
214 if (users) users->owner()->resetAutosaveTimer();
218 void Buffer::fileName(string const & newfile)
220 filename = MakeAbsPath(newfile);
221 filepath = OnlyPath(filename);
222 setReadonly(IsFileWriteable(filename) == 0);
227 // candidate for move to BufferView
228 // (at least some parts in the beginning of the func)
231 // changed to be public and have one parameter
232 // if par = 0 normal behavior
233 // else insert behavior
234 // Returns false if "\the_end" is not read for formats >= 2.13. (Asger)
235 #define USE_PARSE_FUNCTION 1
236 //#define USE_TABULAR_INSETS 1
237 bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par)
241 char depth = 0; // signed or unsigned?
242 LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
243 LyXParagraph::footnote_kind footnotekind = LyXParagraph::FOOTNOTE;
244 bool the_end_read = false;
246 LyXParagraph * return_par = 0;
247 LyXFont font(LyXFont::ALL_INHERIT, params.language_info);
248 if (format < 2.16 && params.language == "hebrew")
249 font.setLanguage(default_language);
251 // If we are inserting, we cheat and get a token in advance
252 bool has_token = false;
256 par = new LyXParagraph;
258 users->text->BreakParagraph();
259 return_par = users->text->FirstParagraph();
262 // We don't want to adopt the parameters from the
263 // document we insert, so we skip until the text begins:
266 pretoken = lex.GetString();
267 if (pretoken == "\\layout") {
279 pretoken = lex.GetString();
282 // Profiling show this should give a lot: (Asger)
283 string const token = pretoken;
287 the_end_read = parseSingleLyXformat2Token(lex, par, return_par,
296 paragraph = return_par;
303 Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
304 LyXParagraph *& return_par,
305 string const & token, int & pos,
306 char & depth, LyXFont & font,
307 LyXParagraph::footnote_flag & footnoteflag,
308 LyXParagraph::footnote_kind & footnotekind)
310 bool the_end_read = false;
312 if (token[0] != '\\') {
313 for (string::const_iterator cit = token.begin();
314 cit != token.end(); ++cit) {
315 par->InsertChar(pos, (*cit));
316 par->SetFont(pos, font);
319 } else if (token == "\\i") {
320 Inset * inset = new InsetLatexAccent;
322 par->InsertChar(pos, LyXParagraph::META_INSET);
323 par->InsertInset(pos, inset);
324 par->SetFont(pos, font);
326 } else if (token == "\\layout") {
331 par = new LyXParagraph(par);
335 string layoutname = lex.GetString();
336 pair<bool, LyXTextClass::LayoutList::size_type> pp
337 = textclasslist.NumberOfLayout(params.textclass,
340 par->layout = pp.second;
341 } else { // layout not found
342 // use default layout "Standard" (0)
345 // Test whether the layout is obsolete.
346 LyXLayout const & layout =
347 textclasslist.Style(params.textclass,
349 if (!layout.obsoleted_by().empty())
351 textclasslist.NumberOfLayout(params.textclass,
352 layout.obsoleted_by()).second;
353 par->footnoteflag = footnoteflag;
354 par->footnotekind = footnotekind;
356 font = LyXFont(LyXFont::ALL_INHERIT, params.language_info);
357 if (format < 2.16 && params.language == "hebrew")
358 font.setLanguage(default_language);
359 } else if (token == "\\end_float") {
364 par = new LyXParagraph(par);
366 footnotekind = LyXParagraph::FOOTNOTE;
367 footnoteflag = LyXParagraph::NO_FOOTNOTE;
370 par->layout = LYX_DUMMY_LAYOUT;
371 font = LyXFont(LyXFont::ALL_INHERIT, params.language_info);
372 if (format < 2.16 && params.language == "hebrew")
373 font.setLanguage(default_language);
374 } else if (token == "\\begin_float") {
375 int tmpret = lex.FindToken(string_footnotekinds);
376 if (tmpret == -1) ++tmpret;
377 if (tmpret != LYX_LAYOUT_DEFAULT)
378 footnotekind = static_cast<LyXParagraph::footnote_kind>(tmpret); // bad
379 if (footnotekind == LyXParagraph::FOOTNOTE
380 || footnotekind == LyXParagraph::MARGIN)
381 footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
383 footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
384 } else if (token == "\\begin_deeper") {
386 } else if (token == "\\end_deeper") {
388 lex.printError("\\end_deeper: "
389 "depth is already null");
393 } else if (token == "\\begin_preamble") {
394 params.readPreamble(lex);
395 } else if (token == "\\textclass") {
397 pair<bool, LyXTextClassList::size_type> pp =
398 textclasslist.NumberOfClass(lex.GetString());
400 params.textclass = pp.second;
402 lex.printError("Unknown textclass `$$Token'");
403 params.textclass = 0;
405 if (!textclasslist.Load(params.textclass)) {
406 // if the textclass wasn't loaded properly
407 // we need to either substitute another
408 // or stop loading the file.
409 // I can substitute but I don't see how I can
410 // stop loading... ideas?? ARRae980418
411 WriteAlert(_("Textclass Loading Error!"),
412 string(_("Can't load textclass ")) +
413 textclasslist.NameOfClass(params.textclass),
414 _("-- substituting default"));
415 params.textclass = 0;
417 } else if (token == "\\options") {
419 params.options = lex.GetString();
420 } else if (token == "\\language") {
421 params.readLanguage(lex);
422 } else if (token == "\\fontencoding") {
424 } else if (token == "\\inputencoding") {
426 params.inputenc = lex.GetString();
427 } else if (token == "\\graphics") {
428 params.readGraphicsDriver(lex);
429 } else if (token == "\\fontscheme") {
431 params.fonts = lex.GetString();
432 } else if (token == "\\noindent") {
433 par->noindent = true;
434 } else if (token == "\\fill_top") {
435 par->added_space_top = VSpace(VSpace::VFILL);
436 } else if (token == "\\fill_bottom") {
437 par->added_space_bottom = VSpace(VSpace::VFILL);
438 } else if (token == "\\line_top") {
439 par->line_top = true;
440 } else if (token == "\\line_bottom") {
441 par->line_bottom = true;
442 } else if (token == "\\pagebreak_top") {
443 par->pagebreak_top = true;
444 } else if (token == "\\pagebreak_bottom") {
445 par->pagebreak_bottom = true;
446 } else if (token == "\\start_of_appendix") {
447 par->start_of_appendix = true;
448 } else if (token == "\\paragraph_separation") {
449 int tmpret = lex.FindToken(string_paragraph_separation);
450 if (tmpret == -1) ++tmpret;
451 if (tmpret != LYX_LAYOUT_DEFAULT)
452 params.paragraph_separation =
453 static_cast<BufferParams::PARSEP>(tmpret);
454 } else if (token == "\\defskip") {
456 params.defskip = VSpace(lex.GetString());
457 } else if (token == "\\epsfig") { // obsolete
458 // Indeed it is obsolete, but we HAVE to be backwards
459 // compatible until 0.14, because otherwise all figures
460 // in existing documents are irretrivably lost. (Asger)
461 params.readGraphicsDriver(lex);
462 } else if (token == "\\quotes_language") {
463 int tmpret = lex.FindToken(string_quotes_language);
464 if (tmpret == -1) ++tmpret;
465 if (tmpret != LYX_LAYOUT_DEFAULT) {
466 InsetQuotes::quote_language tmpl =
467 InsetQuotes::EnglishQ;
470 tmpl = InsetQuotes::EnglishQ;
473 tmpl = InsetQuotes::SwedishQ;
476 tmpl = InsetQuotes::GermanQ;
479 tmpl = InsetQuotes::PolishQ;
482 tmpl = InsetQuotes::FrenchQ;
485 tmpl = InsetQuotes::DanishQ;
488 params.quotes_language = tmpl;
490 } else if (token == "\\quotes_times") {
492 switch(lex.GetInteger()) {
494 params.quotes_times = InsetQuotes::SingleQ;
497 params.quotes_times = InsetQuotes::DoubleQ;
500 } else if (token == "\\papersize") {
501 int tmpret = lex.FindToken(string_papersize);
505 params.papersize2 = tmpret;
506 } else if (token == "\\paperpackage") {
507 int tmpret = lex.FindToken(string_paperpackages);
510 params.paperpackage = BufferParams::PACKAGE_NONE;
512 params.paperpackage = tmpret;
513 } else if (token == "\\use_geometry") {
515 params.use_geometry = lex.GetInteger();
516 } else if (token == "\\use_amsmath") {
518 params.use_amsmath = lex.GetInteger();
519 } else if (token == "\\paperorientation") {
520 int tmpret = lex.FindToken(string_orientation);
521 if (tmpret == -1) ++tmpret;
522 if (tmpret != LYX_LAYOUT_DEFAULT)
523 params.orientation = static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
524 } else if (token == "\\paperwidth") {
526 params.paperwidth = lex.GetString();
527 } else if (token == "\\paperheight") {
529 params.paperheight = lex.GetString();
530 } else if (token == "\\leftmargin") {
532 params.leftmargin = lex.GetString();
533 } else if (token == "\\topmargin") {
535 params.topmargin = lex.GetString();
536 } else if (token == "\\rightmargin") {
538 params.rightmargin = lex.GetString();
539 } else if (token == "\\bottommargin") {
541 params.bottommargin = lex.GetString();
542 } else if (token == "\\headheight") {
544 params.headheight = lex.GetString();
545 } else if (token == "\\headsep") {
547 params.headsep = lex.GetString();
548 } else if (token == "\\footskip") {
550 params.footskip = lex.GetString();
551 } else if (token == "\\paperfontsize") {
553 params.fontsize = strip(lex.GetString());
554 } else if (token == "\\papercolumns") {
556 params.columns = lex.GetInteger();
557 } else if (token == "\\papersides") {
559 switch(lex.GetInteger()) {
561 case 1: params.sides = LyXTextClass::OneSide; break;
562 case 2: params.sides = LyXTextClass::TwoSides; break;
564 } else if (token == "\\paperpagestyle") {
566 params.pagestyle = strip(lex.GetString());
567 } else if (token == "\\bullet") {
569 int index = lex.GetInteger();
571 int temp_int = lex.GetInteger();
572 params.user_defined_bullets[index].setFont(temp_int);
573 params.temp_bullets[index].setFont(temp_int);
575 temp_int = lex.GetInteger();
576 params.user_defined_bullets[index].setCharacter(temp_int);
577 params.temp_bullets[index].setCharacter(temp_int);
579 temp_int = lex.GetInteger();
580 params.user_defined_bullets[index].setSize(temp_int);
581 params.temp_bullets[index].setSize(temp_int);
583 string temp_str = lex.GetString();
584 if (temp_str != "\\end_bullet") {
585 // this element isn't really necessary for
586 // parsing but is easier for humans
587 // to understand bullets. Put it back and
588 // set a debug message?
589 lex.printError("\\end_bullet expected, got" + temp_str);
590 //how can I put it back?
592 } else if (token == "\\bulletLaTeX") {
594 int index = lex.GetInteger();
596 string temp_str = lex.GetString(), sum_str;
597 while (temp_str != "\\end_bullet") {
598 // this loop structure is needed when user
599 // enters an empty string since the first
600 // thing returned will be the \\end_bullet
602 // if the LaTeX entry has spaces. Each element
603 // therefore needs to be read in turn
606 temp_str = lex.GetString();
608 params.user_defined_bullets[index].setText(sum_str);
609 params.temp_bullets[index].setText(sum_str);
610 } else if (token == "\\secnumdepth") {
612 params.secnumdepth = lex.GetInteger();
613 } else if (token == "\\tocdepth") {
615 params.tocdepth = lex.GetInteger();
617 } else if (token == "\\baselinestretch") { // obsolete
618 lex.nextToken(); // should not be used directly
620 // Will probably keep a kind of support just for
622 params.spacing.set(Spacing::Other, lex.GetFloat());
624 } else if (token == "\\spacing") {
626 string tmp = strip(lex.GetString());
627 Spacing::Space tmp_space = Spacing::Default;
629 if (tmp == "single") {
630 tmp_space = Spacing::Single;
631 } else if (tmp == "onehalf") {
632 tmp_space = Spacing::Onehalf;
633 } else if (tmp == "double") {
634 tmp_space = Spacing::Double;
635 } else if (tmp == "other") {
637 tmp_space = Spacing::Other;
638 tmp_val = lex.GetFloat();
640 lex.printError("Unknown spacing token: '$$Token'");
642 // Small hack so that files written with klyx will be
645 par->spacing.set(tmp_space, tmp_val);
647 params.spacing.set(tmp_space, tmp_val);
649 } else if (token == "\\paragraph_spacing") {
651 string tmp = strip(lex.GetString());
652 if (tmp == "single") {
653 par->spacing.set(Spacing::Single);
654 } else if (tmp == "onehalf") {
655 par->spacing.set(Spacing::Onehalf);
656 } else if (tmp == "double") {
657 par->spacing.set(Spacing::Double);
658 } else if (tmp == "other") {
660 par->spacing.set(Spacing::Other,
663 lex.printError("Unknown spacing token: '$$Token'");
665 } else if (token == "\\float_placement") {
667 params.float_placement = lex.GetString();
669 } else if (token == "\\cursor") { // obsolete
670 // this is obsolete, so we just skip it.
673 } else if (token == "\\family") {
675 font.setLyXFamily(lex.GetString());
676 } else if (token == "\\series") {
678 font.setLyXSeries(lex.GetString());
679 } else if (token == "\\shape") {
681 font.setLyXShape(lex.GetString());
682 } else if (token == "\\size") {
684 font.setLyXSize(lex.GetString());
685 } else if (token == "\\latex") {
687 string tok = lex.GetString();
688 // This is dirty, but gone with LyX3. (Asger)
689 if (tok == "no_latex")
690 font.setLatex(LyXFont::OFF);
691 else if (tok == "latex")
692 font.setLatex(LyXFont::ON);
693 else if (tok == "default")
694 font.setLatex(LyXFont::INHERIT);
696 lex.printError("Unknown LaTeX font flag "
698 } else if (token == "\\lang") {
700 string tok = lex.GetString();
701 Languages::iterator lit = languages.find(tok);
702 if (lit != languages.end()) {
703 font.setLanguage(&(*lit).second);
705 font.setLanguage(params.language_info);
706 lex.printError("Unknown language `$$Token'");
708 } else if (token == "\\emph") {
710 font.setEmph(font.setLyXMisc(lex.GetString()));
711 } else if (token == "\\bar") {
713 string tok = lex.GetString();
714 // This is dirty, but gone with LyX3. (Asger)
716 font.setUnderbar(LyXFont::ON);
717 else if (tok == "no")
718 font.setUnderbar(LyXFont::OFF);
719 else if (tok == "default")
720 font.setUnderbar(LyXFont::INHERIT);
722 lex.printError("Unknown bar font flag "
724 } else if (token == "\\noun") {
726 font.setNoun(font.setLyXMisc(lex.GetString()));
727 } else if (token == "\\color") {
729 font.setLyXColor(lex.GetString());
730 } else if (token == "\\align") {
731 int tmpret = lex.FindToken(string_align);
732 if (tmpret == -1) ++tmpret;
733 if (tmpret != LYX_LAYOUT_DEFAULT) { // tmpret != 99 ???
735 for (; tmpret > 0; --tmpret)
736 tmpret2 = tmpret2 * 2;
737 par->align = LyXAlignment(tmpret2);
739 } else if (token == "\\added_space_top") {
741 par->added_space_top = VSpace(lex.GetString());
742 } else if (token == "\\added_space_bottom") {
744 par->added_space_bottom = VSpace(lex.GetString());
745 } else if (token == "\\pextra_type") {
747 par->pextra_type = lex.GetInteger();
748 } else if (token == "\\pextra_width") {
750 par->pextra_width = lex.GetString();
751 } else if (token == "\\pextra_widthp") {
753 par->pextra_widthp = lex.GetString();
754 } else if (token == "\\pextra_alignment") {
756 par->pextra_alignment = lex.GetInteger();
757 } else if (token == "\\pextra_hfill") {
759 par->pextra_hfill = lex.GetInteger();
760 } else if (token == "\\pextra_start_minipage") {
762 par->pextra_start_minipage = lex.GetInteger();
763 } else if (token == "\\labelwidthstring") {
765 par->labelwidthstring = lex.GetString();
766 // do not delete this token, it is still needed!
767 } else if (token == "\\end_inset") {
768 // Simply ignore this. The insets do not have
770 // But insets should read it, it is a part of
771 // the inset isn't it? Lgb.
772 } else if (token == "\\begin_inset") {
773 // Should be moved out into its own function/method. (Lgb)
775 string tmptok = lex.GetString();
776 // test the different insets
777 if (tmptok == "Quotes") {
778 Inset * inset = new InsetQuotes;
780 par->InsertChar(pos, LyXParagraph::META_INSET);
781 par->InsertInset(pos, inset);
782 par->SetFont(pos, font);
785 } else if (tmptok == "\\i") {
786 Inset * inset = new InsetLatexAccent;
788 par->InsertChar(pos, LyXParagraph::META_INSET);
789 par->InsertInset(pos, inset);
790 par->SetFont(pos, font);
793 } else if (tmptok == "FormulaMacro") {
794 Inset * inset = new InsetFormulaMacro;
796 par->InsertChar(pos, LyXParagraph::META_INSET);
797 par->InsertInset(pos, inset);
798 par->SetFont(pos, font);
800 } else if (tmptok == "Formula") {
801 Inset * inset = new InsetFormula;
803 par->InsertChar(pos, LyXParagraph::META_INSET);
804 par->InsertInset(pos, inset);
805 par->SetFont(pos, font);
807 } else if (tmptok == "Figure") {
808 Inset * inset = new InsetFig(100, 100, this);
810 par->InsertChar(pos, LyXParagraph::META_INSET);
811 par->InsertInset(pos, inset);
812 par->SetFont(pos, font);
814 } else if (tmptok == "Info") {
815 Inset * inset = new InsetInfo;
817 par->InsertChar(pos, LyXParagraph::META_INSET);
818 par->InsertInset(pos, inset);
819 par->SetFont(pos, font);
821 } else if (tmptok == "Include") {
822 Inset * inset = new InsetInclude(string(), this);
824 par->InsertChar(pos, LyXParagraph::META_INSET);
825 par->InsertInset(pos, inset);
826 par->SetFont(pos, font);
828 } else if (tmptok == "ERT") {
829 Inset * inset = new InsetERT(this);
831 par->InsertChar(pos, LyXParagraph::META_INSET);
832 par->InsertInset(pos, inset);
833 par->SetFont(pos, font);
835 } else if (tmptok == "Tabular") {
836 Inset * inset = new InsetTabular(this);
838 par->InsertChar(pos, LyXParagraph::META_INSET);
839 par->InsertInset(pos, inset);
840 par->SetFont(pos, font);
842 } else if (tmptok == "Text") {
843 Inset * inset = new InsetText(this);
845 par->InsertChar(pos, LyXParagraph::META_INSET);
846 par->InsertInset(pos, inset);
847 par->SetFont(pos, font);
849 } else if (tmptok == "Foot") {
850 Inset * inset = new InsetFoot(this);
852 par->InsertChar(pos, LyXParagraph::META_INSET);
853 par->InsertInset(pos, inset);
854 par->SetFont(pos, font);
856 } else if (tmptok == "GRAPHICS") {
857 Inset * inset = new InsetGraphics;
859 par->InsertChar(pos, LyXParagraph::META_INSET);
860 par->InsertInset(pos, inset);
861 par->SetFont(pos, font);
862 } else if (tmptok == "LatexCommand") {
866 if (inscmd.getCmdName() == "cite") {
867 inset = new InsetCitation(inscmd.getContents(), inscmd.getOptions());
868 } else if (inscmd.getCmdName() == "bibitem") {
869 lex.printError("Wrong place for bibitem");
870 inset = inscmd.Clone();
871 } else if (inscmd.getCmdName() == "BibTeX") {
872 inset = new InsetBibtex(inscmd.getContents(), inscmd.getOptions(), this);
873 } else if (inscmd.getCmdName() == "index") {
874 inset = new InsetIndex(inscmd.getContents());
875 } else if (inscmd.getCmdName() == "include") {
876 inset = new InsetInclude(inscmd.getContents(), this);
877 } else if (inscmd.getCmdName() == "label") {
878 inset = new InsetLabel(inscmd.getCommand());
879 } else if (inscmd.getCmdName() == "url"
880 || inscmd.getCmdName() == "htmlurl") {
881 inset = new InsetUrl(inscmd.getCommand());
882 } else if (inscmd.getCmdName() == "ref"
883 || inscmd.getCmdName() == "pageref"
884 || inscmd.getCmdName() == "vref"
885 || inscmd.getCmdName() == "vpageref"
886 || inscmd.getCmdName() == "prettyref") {
887 if (!inscmd.getOptions().empty() || !inscmd.getContents().empty()) {
888 inset = new InsetRef(inscmd, this);
890 // CHECK if this else clause
891 //is still needed. (Lgb)
893 // This condition comes from a
894 // temporary solution to the latexdel
895 // ref inset that was transformed to
896 // an empty ref inset plus the body
897 // surronded by latexdel insets
899 string cont, opt, tmptmptok, cmdname;
901 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
906 tmptmptok = lex.GetString();
907 if(tmptmptok[0] == '\\') {
908 if( tmptmptok == "\\backslash")
918 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
923 tmptmptok = lex.GetString();
924 if(tmptmptok[0] == '\\') {
925 if( tmptmptok == "\\backslash")
935 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
941 cmdname = "\\" + inscmd.getCmdName();
942 cmdname += "[" + cont + "]";
943 cmdname += "{" + opt + "}";
944 inset = new InsetRef(cmdname, this);
947 } else if (inscmd.getCmdName() == "tableofcontents") {
948 inset = new InsetTOC(this);
949 } else if (inscmd.getCmdName() == "listoffigures") {
950 inset = new InsetLOF(this);
951 } else if (inscmd.getCmdName() == "listofalgorithms") {
952 inset = new InsetLOA(this);
953 } else if (inscmd.getCmdName() == "listoftables") {
954 inset = new InsetLOT(this);
955 } else if (inscmd.getCmdName() == "printindex") {
956 inset = new InsetPrintIndex(this);
957 } else if (inscmd.getCmdName() == "lyxparent") {
958 inset = new InsetParent(inscmd.getContents(), this);
962 par->InsertChar(pos, LyXParagraph::META_INSET);
963 par->InsertInset(pos, inset);
964 par->SetFont(pos, font);
969 } else if (token == "\\InsetQuotes") {
970 lyxerr << "InsetQuotes" << endl;
971 Inset * inset = new InsetQuotes;
973 par->InsertChar(pos, LyXParagraph::META_INSET);
974 par->InsertInset(pos, inset);
975 par->SetFont(pos, font);
979 } else if (token == "\\InsetFormula") {
980 lyxerr << "InsetFormula" << endl;
981 Inset * inset = new InsetFormula;
983 par->InsertChar(pos, LyXParagraph::META_INSET);
984 par->InsertInset(pos, inset);
985 par->SetFont(pos, font);
988 } else if (token == "\\SpecialChar") {
989 LyXLayout const & layout =
990 textclasslist.Style(params.textclass,
993 // Insets don't make sense in a free-spacing context! ---Kayvan
994 if (layout.free_spacing) {
998 next_token = lex.GetString();
999 if (next_token == "\\-") {
1000 par->InsertChar(pos, '-');
1001 par->SetFont(pos, font);
1002 } else if (next_token == "\\protected_separator"
1003 || next_token == "~") {
1004 par->InsertChar(pos, ' ');
1005 par->SetFont(pos, font);
1007 lex.printError("Token `$$Token' "
1009 "paragraph layout!");
1014 Inset * inset = new InsetSpecialChar;
1016 par->InsertChar(pos, LyXParagraph::META_INSET);
1017 par->InsertInset(pos, inset);
1018 par->SetFont(pos, font);
1022 } else if (token == "\\Figure") {
1023 lyxerr << "Figure" << endl;
1024 Inset * inset = new InsetFig(100, 100, this);
1026 par->InsertChar(pos, LyXParagraph::META_INSET);
1027 par->InsertInset(pos, inset);
1028 par->SetFont(pos, font);
1031 } else if (token == "\\newline") {
1032 par->InsertChar(pos, LyXParagraph::META_NEWLINE);
1033 par->SetFont(pos, font);
1035 } else if (token == "\\LyXTable") {
1036 #ifdef USE_TABULAR_INSETS
1037 Inset * inset = new InsetTabular(this);
1039 par->InsertChar(pos, LyXParagraph::META_INSET);
1040 par->InsertInset(pos, inset);
1041 par->SetFont(pos, font);
1044 par->table = new LyXTable(lex);
1046 } else if (token == "\\hfill") {
1047 par->InsertChar(pos, LyXParagraph::META_HFILL);
1048 par->SetFont(pos, font);
1050 } else if (token == "\\protected_separator") { // obsolete
1051 // This is a backward compability thingie. (Lgb)
1052 // Remove it later some time...introduced with fileformat
1054 LyXLayout const & layout =
1055 textclasslist.Style(params.textclass,
1058 if (layout.free_spacing) {
1059 par->InsertChar(pos, ' ');
1060 par->SetFont(pos, font);
1062 Inset * inset = new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
1063 par->InsertChar(pos, LyXParagraph::META_INSET);
1064 par->InsertInset(pos, inset);
1065 par->SetFont(pos, font);
1068 } else if (token == "\\bibitem") { // ale970302
1070 par->bibkey = new InsetBibKey;
1071 par->bibkey->Read(lex);
1072 }else if (token == "\\backslash") {
1073 par->InsertChar(pos, '\\');
1074 par->SetFont(pos, font);
1076 }else if (token == "\\the_end") {
1077 the_end_read = true;
1079 // This should be insurance for the future: (Asger)
1080 lex.printError("Unknown token `$$Token'. "
1081 "Inserting as text.");
1082 for(string::const_iterator cit = token.begin();
1083 cit != token.end(); ++cit) {
1084 par->InsertChar(pos, (*cit));
1085 par->SetFont(pos, font);
1089 return the_end_read;
1092 bool Buffer::readFile(LyXLex & lex, LyXParagraph * par)
1098 token = lex.GetString();
1099 if (token == "\\lyxformat") { // the first token _must_ be...
1101 format = lex.GetFloat();
1103 if (LYX_FORMAT - format > 0.05) {
1104 printf(_("Warning: need lyxformat %.2f but found %.2f\n"),
1105 LYX_FORMAT, format);
1107 if (format - LYX_FORMAT > 0.05) {
1108 printf(_("ERROR: need lyxformat %.2f but found %.2f\n"),
1109 LYX_FORMAT, format);
1111 bool the_end = readLyXformat2(lex, par);
1112 // Formats >= 2.13 support "\the_end" marker
1119 WriteAlert(_("Warning!"),
1120 _("Reading of document is not complete"),
1121 _("Maybe the document is truncated"));
1122 // We simulate a safe reading anyways to allow
1123 // users to take the chance... (Asger)
1127 WriteAlert(_("ERROR!"),
1128 _("Old LyX file format found. "
1129 "Use LyX 0.10.x to read this!"));
1133 } else { // "\\lyxformat" not found
1134 WriteAlert(_("ERROR!"), _("Not a LyX file!"));
1137 WriteAlert(_("ERROR!"), _("Unable to read file!"));
1143 // Should probably be moved to somewhere else: BufferView? LyXView?
1144 bool Buffer::save() const
1146 // We don't need autosaves in the immediate future. (Asger)
1147 resetAutosaveTimers();
1151 if (lyxrc.make_backup) {
1152 s = fileName() + '~';
1153 if (!lyxrc.backupdir_path.empty())
1154 s = AddName(lyxrc.backupdir_path,
1155 subst(CleanupPath(s),'/','!'));
1157 // Rename is the wrong way of making a backup,
1158 // this is the correct way.
1159 /* truss cp fil fil2:
1160 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
1161 stat("LyXVC.lyx", 0xEFFFF688) = 0
1162 open("LyXVC.lyx", O_RDONLY) = 3
1163 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
1164 fstat(4, 0xEFFFF508) = 0
1165 fstat(3, 0xEFFFF508) = 0
1166 read(3, " # T h i s f i l e w".., 8192) = 5579
1167 write(4, " # T h i s f i l e w".., 5579) = 5579
1168 read(3, 0xEFFFD4A0, 8192) = 0
1171 chmod("LyXVC3.lyx", 0100644) = 0
1172 lseek(0, 0, SEEK_CUR) = 46440
1176 // Should proabaly have some more error checking here.
1177 // Should be cleaned up in 0.13, at least a bit.
1178 // Doing it this way, also makes the inodes stay the same.
1179 // This is still not a very good solution, in particular we
1180 // might loose the owner of the backup.
1181 FileInfo finfo(fileName());
1182 if (finfo.exist()) {
1183 mode_t fmode = finfo.getMode();
1184 struct utimbuf times = {
1185 finfo.getAccessTime(),
1186 finfo.getModificationTime() };
1188 ifstream ifs(fileName().c_str());
1189 ofstream ofs(s.c_str(), ios::out|ios::trunc);
1194 ::chmod(s.c_str(), fmode);
1196 if (::utime(s.c_str(), ×)) {
1197 lyxerr << "utime error." << endl;
1200 lyxerr << "LyX was not able to make "
1201 "backupcopy. Beware." << endl;
1206 if (writeFile(fileName(), false)) {
1209 // now delete the autosavefile
1210 string a = OnlyPath(fileName());
1212 a += OnlyFilename(fileName());
1214 FileInfo fileinfo(a);
1215 if (fileinfo.exist()) {
1216 if (::remove(a.c_str()) != 0) {
1217 WriteFSAlert(_("Could not delete "
1218 "auto-save file!"), a);
1222 // Saving failed, so backup is not backup
1223 if (lyxrc.make_backup) {
1224 ::rename(s.c_str(), fileName().c_str());
1232 // Returns false if unsuccesful
1233 bool Buffer::writeFile(string const & fname, bool flag) const
1235 // if flag is false writeFile will not create any GUI
1236 // warnings, only cerr.
1237 // Needed for autosave in background or panic save (Matthias 120496)
1239 if (read_only && (fname == filename)) {
1240 // Here we should come with a question if we should
1241 // perform the write anyway.
1243 lyxerr << _("Error! Document is read-only: ")
1246 WriteAlert(_("Error! Document is read-only: "),
1251 FileInfo finfo(fname);
1252 if (finfo.exist() && !finfo.writable()) {
1253 // Here we should come with a question if we should
1254 // try to do the save anyway. (i.e. do a chmod first)
1256 lyxerr << _("Error! Cannot write file: ")
1259 WriteFSAlert(_("Error! Cannot write file: "),
1264 ofstream ofs(fname.c_str());
1267 lyxerr << _("Error! Cannot open file: ")
1270 WriteFSAlert(_("Error! Cannot open file: "),
1274 // The top of the file should not be written by params.
1276 // write out a comment in the top of the file
1277 ofs << '#' << LYX_DOCVERSION
1278 << " created this file. For more info see http://www.lyx.org/\n";
1279 ofs.setf(ios::showpoint|ios::fixed);
1281 ofs << "\\lyxformat " << setw(4) << LYX_FORMAT << "\n";
1283 // now write out the buffer paramters.
1284 params.writeFile(ofs);
1286 char footnoteflag = 0;
1289 // this will write out all the paragraphs
1290 // using recursive descent.
1291 paragraph->writeFile(ofs, params, footnoteflag, depth);
1293 // Write marker that shows file is complete
1294 ofs << "\n\\the_end" << endl;
1296 // how to check if close went ok?
1301 void Buffer::writeFileAscii(string const & fname, int linelen)
1303 LyXFont font1, font2;
1305 char c, footnoteflag = 0, depth = 0;
1307 LyXParagraph::size_type i;
1308 int j, h, ltype = 0, ltype_depth = 0,
1309 * clen = 0, actcell = 0, actpos = 0, cell = 0, cells = 0,
1312 bool ref_printed = false;
1314 ofstream ofs(fname.c_str());
1316 WriteFSAlert(_("Error: Cannot write file:"), fname);
1320 string fname1 = TmpFileName();
1321 LyXParagraph * par = paragraph;
1325 if (par->footnoteflag != LyXParagraph::NO_FOOTNOTE ||
1327 par->previous->footnoteflag == LyXParagraph::NO_FOOTNOTE){
1329 /* begins a footnote environment ? */
1330 if (footnoteflag != par->footnoteflag) {
1331 footnoteflag = par->footnoteflag;
1333 j = strlen(string_footnotekinds[par->footnotekind])+4;
1334 if (currlinelen + j > linelen)
1337 << string_footnotekinds[par->footnotekind] << "] ";
1342 /* begins or ends a deeper area ?*/
1343 if (depth != par->depth) {
1344 if (par->depth > depth) {
1345 while (par->depth > depth) {
1350 while (par->depth < depth) {
1356 /* First write the layout */
1357 tmp = textclasslist.NameOfLayout(params.textclass, par->layout);
1358 if (tmp == "Itemize") {
1360 ltype_depth = depth+1;
1361 } else if (tmp == "Enumerate") {
1363 ltype_depth = depth+1;
1364 } else if (strstr(tmp.c_str(), "ection")) {
1366 ltype_depth = depth+1;
1367 } else if (strstr(tmp.c_str(), "aragraph")) {
1369 ltype_depth = depth+1;
1370 } else if (tmp == "Description") {
1372 ltype_depth = depth+1;
1373 } else if (tmp == "Abstract") {
1376 } else if (tmp == "Bibliography") {
1384 /* maybe some vertical spaces */
1386 /* the labelwidthstring used in lists */
1390 /* some pagebreaks? */
1394 /* what about the alignment */
1396 /* dummy layout, that means a footnote ended */
1397 footnoteflag = LyXParagraph::NO_FOOTNOTE;
1402 //LyXLayout const & layout =
1403 // textclasslist.Style(params.textclass,
1404 // par->GetLayout()); // unused
1405 //bool free_spc = layout.free_spacing; //unused
1407 /* It might be a table */
1410 if (!lyxrc.ascii_roff_command.empty() &&
1411 lyxrc.ascii_roff_command != "none") {
1412 RoffAsciiTable(ofs, par);
1419 cells = par->table->columns;
1420 clen = new int [cells];
1421 memset(clen, 0, sizeof(int) * cells);
1423 for (i = 0, j = 0, h = 1; i < par->size(); ++i, ++h) {
1424 c = par->GetChar(i);
1425 if (c == LyXParagraph::META_INSET) {
1426 if ((inset = par->GetInset(i))) {
1428 std::ostringstream ost;
1430 h += ost.str().length();
1435 char * tmp = ost.str();
1441 } else if (c == LyXParagraph::META_NEWLINE) {
1445 j = (++j) % par->table->NumberOfCellsInRow(actcell);
1453 font1 = LyXFont(LyXFont::ALL_INHERIT, params.language_info);
1455 for (i = 0, actpos = 1; i < par->size(); ++i, ++actpos) {
1456 if (!i && !footnoteflag && !noparbreak){
1458 for(j = 0; j < depth; ++j)
1460 currlinelen = depth * 2;
1462 case 0: /* Standard */
1463 case 4: /* (Sub)Paragraph */
1464 case 5: /* Description */
1466 case 6: /* Abstract */
1467 ofs << "Abstract\n\n";
1469 case 7: /* Bibliography */
1471 ofs << "References\n\n";
1476 ofs << par->labelstring << " ";
1479 if (ltype_depth > depth) {
1480 for(j = ltype_depth - 1; j > depth; --j)
1482 currlinelen += (ltype_depth-depth)*2;
1485 for(j = 0; j < cells; ++j) {
1487 for(h = 0; h < (clen[j] + 1);
1492 for(j = 0; j < depth; ++j)
1494 currlinelen = depth * 2;
1495 if (ltype_depth > depth) {
1496 for(j = ltype_depth;
1499 currlinelen += (ltype_depth-depth)*2;
1504 font2 = par->GetFontSettings(i);
1505 if (font1.latex() != font2.latex()) {
1506 if (font2.latex() == LyXFont::OFF)
1513 c = par->GetChar(i);
1517 case LyXParagraph::META_INSET:
1518 if ((inset = par->GetInset(i))) {
1521 currlinelen += (ofs.tellp() - fpos);
1522 actpos += (ofs.tellp() - fpos) - 1;
1525 case LyXParagraph::META_NEWLINE:
1527 if (par->table->NumberOfCellsInRow(actcell) <= cell) {
1528 for(j = actpos; j < clen[cell - 1]; ++j)
1531 for(j = 0; j < depth; ++j)
1533 currlinelen = depth*2;
1534 if (ltype_depth > depth) {
1535 for(j = ltype_depth; j > depth; --j)
1537 currlinelen += (ltype_depth-depth) * 2;
1539 for(j = 0; j < cells; ++j) {
1541 for(h = 0; h < (clen[j] + 1); ++h)
1545 for(j = 0; j < depth; ++j)
1547 currlinelen = depth * 2;
1548 if (ltype_depth > depth) {
1549 for(j = ltype_depth;
1552 currlinelen += (ltype_depth-depth)*2;
1558 j < clen[cell - 1]; ++j)
1564 currlinelen = actpos = 0;
1567 for(j = 0; j < depth; ++j)
1569 currlinelen = depth * 2;
1570 if (ltype_depth > depth) {
1571 for(j = ltype_depth;
1574 currlinelen += (ltype_depth - depth) * 2;
1578 case LyXParagraph::META_HFILL:
1585 if (currlinelen > linelen - 10
1586 && c == ' ' && i + 2 < par->size()) {
1588 for(j = 0; j < depth; ++j)
1590 currlinelen = depth * 2;
1591 if (ltype_depth > depth) {
1592 for(j = ltype_depth;
1595 currlinelen += (ltype_depth-depth)*2;
1597 } else if (c != '\0')
1600 lyxerr.debug() << "writeAsciiFile: NULL char in structure." << endl;
1606 for(j = actpos; j < clen[cell - 1]; ++j)
1609 for(j = 0; j < depth; ++j)
1611 currlinelen = depth * 2;
1612 if (ltype_depth > depth) {
1613 for(j = ltype_depth; j > depth; --j)
1615 currlinelen += (ltype_depth - depth) * 2;
1617 for(j = 0; j < cells; ++j) {
1619 for(h = 0; h < (clen[j] + 1); ++h)
1632 void Buffer::makeLaTeXFile(string const & fname,
1633 string const & original_path,
1634 bool nice, bool only_body)
1636 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
1638 niceFile = nice; // this will be used by Insetincludes.
1640 tex_code_break_column = lyxrc.ascii_linelen;
1642 LyXTextClass const & tclass =
1643 textclasslist.TextClass(params.textclass);
1645 ofstream ofs(fname.c_str());
1647 WriteFSAlert(_("Error: Cannot open file: "), fname);
1651 // validate the buffer.
1652 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
1653 LaTeXFeatures features(params, tclass.numLayouts());
1655 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
1658 // The starting paragraph of the coming rows is the
1659 // first paragraph of the document. (Asger)
1660 texrow.start(paragraph, 0);
1662 if (!only_body && nice) {
1663 ofs << "%% " LYX_DOCVERSION " created this file. "
1664 "For more info, see http://www.lyx.org/.\n"
1665 "%% Do not edit unless you really know what "
1670 lyxerr.debug() << "lyx header finished" << endl;
1671 // There are a few differences between nice LaTeX and usual files:
1672 // usual is \batchmode and has a
1673 // special input@path to allow the including of figures
1674 // with either \input or \includegraphics (what figinsets do).
1675 // batchmode is not set if there is a tex_code_break_column.
1676 // In this case somebody is interested in the generated LaTeX,
1677 // so this is OK. input@path is set when the actual parameter
1678 // original_path is set. This is done for usual tex-file, but not
1679 // for nice-latex-file. (Matthias 250696)
1682 // code for usual, NOT nice-latex-file
1683 ofs << "\\batchmode\n"; // changed
1684 // from \nonstopmode
1687 if (!original_path.empty()) {
1688 ofs << "\\makeatletter\n"
1689 << "\\def\\input@path{{"
1690 << original_path << "/}}\n"
1691 << "\\makeatother\n";
1697 ofs << "\\documentclass";
1699 string options; // the document class options.
1701 if (tokenPos(tclass.opt_fontsize(), '|', params.fontsize) >= 0) {
1702 // only write if existing in list (and not default)
1703 options += params.fontsize;
1708 if (!params.use_geometry &&
1709 (params.paperpackage == BufferParams::PACKAGE_NONE)) {
1710 switch (params.papersize) {
1711 case BufferParams::PAPER_A4PAPER:
1712 options += "a4paper,";
1714 case BufferParams::PAPER_USLETTER:
1715 options += "letterpaper,";
1717 case BufferParams::PAPER_A5PAPER:
1718 options += "a5paper,";
1720 case BufferParams::PAPER_B5PAPER:
1721 options += "b5paper,";
1723 case BufferParams::PAPER_EXECUTIVEPAPER:
1724 options += "executivepaper,";
1726 case BufferParams::PAPER_LEGALPAPER:
1727 options += "legalpaper,";
1733 if (params.sides != tclass.sides()) {
1734 switch (params.sides) {
1735 case LyXTextClass::OneSide:
1736 options += "oneside,";
1738 case LyXTextClass::TwoSides:
1739 options += "twoside,";
1746 if (params.columns != tclass.columns()) {
1747 if (params.columns == 2)
1748 options += "twocolumn,";
1750 options += "onecolumn,";
1753 if (!params.use_geometry
1754 && params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1755 options += "landscape,";
1757 // language should be a parameter to \documentclass
1758 bool use_babel = false;
1759 if (params.language_info->RightToLeft) // This seems necessary
1760 features.UsedLanguages.insert(default_language);
1761 if (params.language != "default" ||
1762 !features.UsedLanguages.empty() ) {
1764 for (LaTeXFeatures::LanguageList::const_iterator cit =
1765 features.UsedLanguages.begin();
1766 cit != features.UsedLanguages.end(); ++cit)
1767 options += (*cit)->lang + ",";
1768 options += params.language_info->lang + ',';
1771 // the user-defined options
1772 if (!params.options.empty()) {
1773 options += params.options + ',';
1776 if (!options.empty()){
1777 options = strip(options, ',');
1778 ofs << '[' << options << ']';
1782 << textclasslist.LatexnameOfClass(params.textclass)
1785 // end of \documentclass defs
1787 // font selection must be done before loading fontenc.sty
1788 if (params.fonts != "default") {
1789 ofs << "\\usepackage{" << params.fonts << "}\n";
1792 // this one is not per buffer
1793 if (lyxrc.fontenc != "default") {
1794 ofs << "\\usepackage[" << lyxrc.fontenc
1798 if (params.inputenc != "default") {
1799 ofs << "\\usepackage[" << params.inputenc
1804 // At the very beginning the text parameters.
1805 if (params.paperpackage != BufferParams::PACKAGE_NONE) {
1806 switch (params.paperpackage) {
1807 case BufferParams::PACKAGE_A4:
1808 ofs << "\\usepackage{a4}\n";
1811 case BufferParams::PACKAGE_A4WIDE:
1812 ofs << "\\usepackage{a4wide}\n";
1815 case BufferParams::PACKAGE_WIDEMARGINSA4:
1816 ofs << "\\usepackage[widemargins]{a4}\n";
1821 if (params.use_geometry) {
1822 ofs << "\\usepackage{geometry}\n";
1824 ofs << "\\geometry{verbose";
1825 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1826 ofs << ",landscape";
1827 switch (params.papersize2) {
1828 case BufferParams::VM_PAPER_CUSTOM:
1829 if (!params.paperwidth.empty())
1830 ofs << ",paperwidth="
1831 << params.paperwidth;
1832 if (!params.paperheight.empty())
1833 ofs << ",paperheight="
1834 << params.paperheight;
1836 case BufferParams::VM_PAPER_USLETTER:
1837 ofs << ",letterpaper";
1839 case BufferParams::VM_PAPER_USLEGAL:
1840 ofs << ",legalpaper";
1842 case BufferParams::VM_PAPER_USEXECUTIVE:
1843 ofs << ",executivepaper";
1845 case BufferParams::VM_PAPER_A3:
1848 case BufferParams::VM_PAPER_A4:
1851 case BufferParams::VM_PAPER_A5:
1854 case BufferParams::VM_PAPER_B3:
1857 case BufferParams::VM_PAPER_B4:
1860 case BufferParams::VM_PAPER_B5:
1864 // default papersize ie BufferParams::VM_PAPER_DEFAULT
1865 switch (lyxrc.default_papersize) {
1866 case BufferParams::PAPER_DEFAULT: // keep compiler happy
1867 case BufferParams::PAPER_USLETTER:
1868 ofs << ",letterpaper";
1870 case BufferParams::PAPER_LEGALPAPER:
1871 ofs << ",legalpaper";
1873 case BufferParams::PAPER_EXECUTIVEPAPER:
1874 ofs << ",executivepaper";
1876 case BufferParams::PAPER_A3PAPER:
1879 case BufferParams::PAPER_A4PAPER:
1882 case BufferParams::PAPER_A5PAPER:
1885 case BufferParams::PAPER_B5PAPER:
1890 if (!params.topmargin.empty())
1891 ofs << ",tmargin=" << params.topmargin;
1892 if (!params.bottommargin.empty())
1893 ofs << ",bmargin=" << params.bottommargin;
1894 if (!params.leftmargin.empty())
1895 ofs << ",lmargin=" << params.leftmargin;
1896 if (!params.rightmargin.empty())
1897 ofs << ",rmargin=" << params.rightmargin;
1898 if (!params.headheight.empty())
1899 ofs << ",headheight=" << params.headheight;
1900 if (!params.headsep.empty())
1901 ofs << ",headsep=" << params.headsep;
1902 if (!params.footskip.empty())
1903 ofs << ",footskip=" << params.footskip;
1907 if (params.use_amsmath
1908 && !tclass.provides(LyXTextClass::amsmath)) {
1909 ofs << "\\usepackage{amsmath}\n";
1913 if (tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle) >= 0) {
1914 if (params.pagestyle == "fancy") {
1915 ofs << "\\usepackage{fancyhdr}\n";
1918 ofs << "\\pagestyle{" << params.pagestyle << "}\n";
1922 // We try to load babel late, in case it interferes
1923 // with other packages.
1925 ofs << lyxrc.language_package << endl;
1929 if (params.secnumdepth != tclass.secnumdepth()) {
1930 ofs << "\\setcounter{secnumdepth}{"
1931 << params.secnumdepth
1935 if (params.tocdepth != tclass.tocdepth()) {
1936 ofs << "\\setcounter{tocdepth}{"
1942 if (params.paragraph_separation) {
1943 switch (params.defskip.kind()) {
1944 case VSpace::SMALLSKIP:
1945 ofs << "\\setlength\\parskip{\\smallskipamount}\n";
1947 case VSpace::MEDSKIP:
1948 ofs << "\\setlength\\parskip{\\medskipamount}\n";
1950 case VSpace::BIGSKIP:
1951 ofs << "\\setlength\\parskip{\\bigskipamount}\n";
1953 case VSpace::LENGTH:
1954 ofs << "\\setlength\\parskip{"
1955 << params.defskip.length().asLatexString()
1958 default: // should never happen // Then delete it.
1959 ofs << "\\setlength\\parskip{\\medskipamount}\n";
1964 ofs << "\\setlength\\parindent{0pt}\n";
1968 // Now insert the LyX specific LaTeX commands...
1969 string preamble, tmppreamble;
1971 // The optional packages;
1972 preamble = features.getPackages();
1974 // this might be useful...
1975 preamble += "\n\\makeatletter\n\n";
1977 // Some macros LyX will need
1978 tmppreamble = features.getMacros();
1980 if (!tmppreamble.empty()) {
1981 preamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1982 "LyX specific LaTeX commands.\n"
1983 + tmppreamble + '\n';
1986 // the text class specific preamble
1987 tmppreamble = features.getTClassPreamble();
1988 if (!tmppreamble.empty()) {
1989 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1990 "Textclass specific LaTeX commands.\n"
1991 + tmppreamble + '\n';
1994 /* the user-defined preamble */
1995 if (!params.preamble.empty()) {
1996 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1997 "User specified LaTeX commands.\n"
1998 + params.preamble + '\n';
2001 preamble += "\\makeatother\n\n";
2003 // Itemize bullet settings need to be last in case the user
2004 // defines their own bullets that use a package included
2005 // in the user-defined preamble -- ARRae
2006 // Actually it has to be done much later than that
2007 // since some packages like frenchb make modifications
2008 // at \begin{document} time -- JMarc
2010 for (int i = 0; i < 4; ++i) {
2011 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
2012 if (bullets_def.empty())
2013 bullets_def="\\AtBeginDocument{\n";
2014 bullets_def += " \\renewcommand{\\labelitemi";
2016 // `i' is one less than the item to modify
2023 bullets_def += "ii";
2029 bullets_def += "}{" +
2030 params.user_defined_bullets[i].getText()
2035 if (!bullets_def.empty())
2036 preamble += bullets_def + "}\n\n";
2038 for (int j = countChar(preamble, '\n'); j-- ;) {
2045 ofs << "\\begin{document}\n\n";
2049 lyxerr.debug() << "preamble finished, now the body." << endl;
2050 if (!lyxrc.language_auto_begin && params.language != "default") {
2051 ofs << subst(lyxrc.language_command_begin, "$$lang",
2057 latexParagraphs(ofs, paragraph, 0, texrow);
2059 // add this just in case after all the paragraphs
2063 if (!lyxrc.language_auto_end && params.language != "default") {
2064 ofs << subst(lyxrc.language_command_end, "$$lang",
2071 ofs << "\\end{document}\n";
2074 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
2076 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
2080 // Just to be sure. (Asger)
2083 // tex_code_break_column's value is used to decide
2084 // if we are in batchmode or not (within mathed_write()
2085 // in math_write.C) so we must set it to a non-zero
2086 // value when we leave otherwise we save incorrect .lyx files.
2087 tex_code_break_column = lyxrc.ascii_linelen;
2091 lyxerr << "File was not closed properly." << endl;
2094 lyxerr.debug() << "Finished making latex file." << endl;
2098 // LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
2100 void Buffer::latexParagraphs(ostream & ofs, LyXParagraph *par,
2101 LyXParagraph *endpar, TexRow & texrow)
2103 bool was_title = false;
2104 bool already_title = false;
2106 std::ostringstream ftnote;
2108 char * tmpholder = 0;
2114 while (par != endpar) {
2115 #ifndef HAVE_SSTREAM
2118 ftnote << tmpholder;
2119 delete [] tmpholder;
2124 lyxerr[Debug::LATEX] << "Error in latexParagraphs."
2126 LyXLayout const & layout =
2127 textclasslist.Style(params.textclass,
2130 if (layout.intitle) {
2131 if (already_title) {
2132 lyxerr <<"Error in latexParagraphs: You"
2133 " should not mix title layouts"
2134 " with normal ones." << endl;
2137 } else if (was_title && !already_title) {
2138 ofs << "\\maketitle\n";
2140 already_title = true;
2143 // We are at depth 0 so we can just use
2144 // ordinary \footnote{} generation
2145 // flag this with ftcount
2147 if (layout.isEnvironment()
2148 || par->pextra_type != LyXParagraph::PEXTRA_NONE) {
2149 par = par->TeXEnvironment(ofs, texrow,
2150 ftnote, ft_texrow, ftcount);
2152 par = par->TeXOnePar(ofs, texrow, false,
2153 ftnote, ft_texrow, ftcount);
2156 // Write out what we've generated...
2159 ofs << "\\addtocounter{footnote}{-"
2163 ofs << ftnote.str();
2164 texrow += ft_texrow;
2166 // The extra .c_str() is needed when we use
2167 // lyxstring instead of the STL string class.
2168 ftnote.str(string().c_str());
2170 delete [] ftnote.str();
2175 #ifndef HAVE_SSTREAM
2177 // I hate strstreams
2178 tmpholder = ftnote.str();
2182 #ifndef HAVE_SSTREAM
2183 delete [] tmpholder;
2185 // It might be that we only have a title in this document
2186 if (was_title && !already_title) {
2187 ofs << "\\maketitle\n";
2192 bool Buffer::isLatex() const
2194 return textclasslist.TextClass(params.textclass).outputType() == LATEX;
2198 bool Buffer::isLinuxDoc() const
2200 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC;
2204 bool Buffer::isLiterate() const
2206 return textclasslist.TextClass(params.textclass).outputType() == LITERATE;
2210 bool Buffer::isDocBook() const
2212 return textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2216 bool Buffer::isSGML() const
2218 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC ||
2219 textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2223 void Buffer::sgmlOpenTag(ostream & os, int depth,
2224 string const & latexname) const
2226 os << string(depth, ' ') << "<" << latexname << ">\n";
2230 void Buffer::sgmlCloseTag(ostream & os, int depth,
2231 string const & latexname) const
2233 os << string(depth, ' ') << "</" << latexname << ">\n";
2237 void Buffer::makeLinuxDocFile(string const & fname, int column)
2239 LyXParagraph * par = paragraph;
2241 string top_element = textclasslist.LatexnameOfClass(params.textclass);
2242 string environment_stack[10];
2245 int depth = 0; // paragraph depth
2247 ofstream ofs(fname.c_str());
2250 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2254 tex_code_break_column = column;
2257 if (params.preamble.empty()) {
2258 ofs << "<!doctype linuxdoc system>\n\n";
2261 ofs << "<!doctype linuxdoc system \n [ "
2262 << params.preamble << " \n]>\n\n";
2265 ofs << "<!-- " << LYX_DOCVERSION
2266 << " created this file. For more info see http://www.lyx.org/"
2269 if(params.options.empty())
2270 sgmlOpenTag(ofs, 0, top_element);
2272 string top = top_element;
2274 top += params.options;
2275 sgmlOpenTag(ofs, 0, top);
2279 int desc_on = 0; // description mode
2280 LyXLayout const & style =
2281 textclasslist.Style(users->buffer()->params.textclass,
2283 #ifdef WITH_WARNINGS
2284 #warning please check if this call is really needed!!!
2286 // par->AutoDeleteInsets();
2288 // treat <toc> as a special case for compatibility with old code
2289 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2290 Inset * inset = par->GetInset(0);
2291 Inset::Code lyx_code = inset->LyxCode();
2292 if (lyx_code == Inset::TOC_CODE){
2293 string temp = "toc";
2294 sgmlOpenTag(ofs, depth, temp);
2297 linuxDocHandleFootnote(ofs, par, depth);
2302 // environment tag closing
2303 for( ; depth > par->depth; --depth) {
2304 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2305 environment_stack[depth].erase();
2308 // write opening SGML tags
2309 switch(style.latextype) {
2310 case LATEX_PARAGRAPH:
2311 if(depth == par->depth
2312 && !environment_stack[depth].empty()) {
2313 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2314 environment_stack[depth].erase();
2320 sgmlOpenTag(ofs, depth, style.latexname());
2325 LinuxDocError(par, 0,
2326 _("Error : Wrong depth for"
2327 " LatexType Command.\n"));
2329 if (!environment_stack[depth].empty()){
2330 sgmlCloseTag(ofs, depth,
2331 environment_stack[depth]);
2335 environment_stack[depth].erase();
2336 sgmlOpenTag(ofs, depth, style.latexname());
2339 case LATEX_ENVIRONMENT:
2340 case LATEX_ITEM_ENVIRONMENT:
2341 if(depth == par->depth
2342 && environment_stack[depth] != style.latexname()
2343 && !environment_stack[depth].empty()) {
2345 sgmlCloseTag(ofs, depth,
2346 environment_stack[depth]);
2347 environment_stack[depth].erase();
2349 if (depth < par->depth) {
2351 environment_stack[depth].erase();
2353 if (environment_stack[depth] != style.latexname()) {
2356 sgmlOpenTag(ofs, depth, temp);
2358 environment_stack[depth] = style.latexname();
2359 sgmlOpenTag(ofs, depth,
2360 environment_stack[depth]);
2362 if(style.latextype == LATEX_ENVIRONMENT) break;
2364 desc_on = (style.labeltype == LABEL_MANUAL);
2371 sgmlOpenTag(ofs, depth + 1, item_name);
2374 sgmlOpenTag(ofs, depth, style.latexname());
2379 SimpleLinuxDocOnePar(ofs, par, desc_on, depth);
2382 linuxDocHandleFootnote(ofs, par, depth);
2384 while(par && par->IsDummy());
2387 // write closing SGML tags
2388 switch(style.latextype) {
2390 case LATEX_ENVIRONMENT:
2391 case LATEX_ITEM_ENVIRONMENT:
2394 sgmlCloseTag(ofs, depth, style.latexname());
2400 for(; depth > 0; --depth)
2401 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2403 if(!environment_stack[depth].empty())
2404 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2407 sgmlCloseTag(ofs, 0, top_element);
2410 // How to check for successful close
2414 void Buffer::linuxDocHandleFootnote(ostream & os, LyXParagraph * & par,
2417 string tag = "footnote";
2419 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2420 sgmlOpenTag(os, depth + 1, tag);
2421 SimpleLinuxDocOnePar(os, par, 0, depth + 1);
2422 sgmlCloseTag(os, depth + 1, tag);
2428 void Buffer::DocBookHandleCaption(ostream & os, string & inner_tag,
2429 int const depth, int desc_on,
2430 LyXParagraph * & par)
2432 LyXParagraph * tpar = par;
2433 while (tpar && (tpar->footnoteflag != LyXParagraph::NO_FOOTNOTE) &&
2434 (tpar->layout != textclasslist.NumberOfLayout(params.textclass,
2438 tpar->layout == textclasslist.NumberOfLayout(params.textclass,
2439 "Caption").second) {
2440 sgmlOpenTag(os, depth + 1, inner_tag);
2442 SimpleDocBookOnePar(os, extra_par, tpar,
2443 desc_on, depth + 2);
2444 sgmlCloseTag(os, depth+1, inner_tag);
2445 if(!extra_par.empty())
2451 void Buffer::DocBookHandleFootnote(ostream & os, LyXParagraph * & par,
2454 string tag, inner_tag;
2455 string tmp_par, extra_par;
2456 bool inner_span = false;
2459 // Someone should give this enum a proper name (Lgb)
2467 SOME_ENUM last = NO_ONE;
2468 SOME_ENUM present = FOOTNOTE_LIKE;
2470 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2471 if(last == present) {
2473 if(!tmp_par.empty()) {
2476 sgmlCloseTag(os, depth + 1, inner_tag);
2477 sgmlOpenTag(os, depth + 1, inner_tag);
2484 if(!inner_tag.empty()) sgmlCloseTag(os, depth + 1,
2486 if(!extra_par.empty()) os << extra_par;
2487 if(!tag.empty()) sgmlCloseTag(os, depth, tag);
2490 switch (par->footnotekind) {
2491 case LyXParagraph::FOOTNOTE:
2492 case LyXParagraph::ALGORITHM:
2495 present = FOOTNOTE_LIKE;
2498 case LyXParagraph::MARGIN:
2501 present = MARGIN_LIKE;
2504 case LyXParagraph::FIG:
2505 case LyXParagraph::WIDE_FIG:
2507 inner_tag = "title";
2511 case LyXParagraph::TAB:
2512 case LyXParagraph::WIDE_TAB:
2514 inner_tag = "title";
2519 sgmlOpenTag(os, depth, tag);
2520 if ((present == TAB_LIKE) || (present == FIG_LIKE)) {
2521 DocBookHandleCaption(os, inner_tag, depth,
2525 sgmlOpenTag(os, depth + 1, inner_tag);
2528 // ignore all caption here, we processed them above!!!
2529 if (par->layout != textclasslist
2530 .NumberOfLayout(params.textclass,
2531 "Caption").second) {
2533 std::ostringstream ost;
2537 SimpleDocBookOnePar(ost, extra_par, par,
2538 desc_on, depth + 2);
2540 tmp_par += ost.str().c_str();
2543 char * ctmp = ost.str();
2548 tmp_par = frontStrip(strip(tmp_par));
2554 if(!inner_tag.empty()) sgmlCloseTag(os, depth + 1, inner_tag);
2555 if(!extra_par.empty()) os << extra_par;
2556 if(!tag.empty()) sgmlCloseTag(os, depth, tag);
2560 // push a tag in a style stack
2561 void Buffer::push_tag(ostream & os, char const * tag,
2562 int & pos, char stack[5][3])
2564 // pop all previous tags
2565 for (int j = pos; j >= 0; --j)
2566 os << "</" << stack[j] << ">";
2569 sprintf(stack[++pos], "%s", tag);
2572 for (int i = 0; i <= pos; ++i)
2573 os << "<" << stack[i] << ">";
2577 void Buffer::pop_tag(ostream & os, char const * tag,
2578 int & pos, char stack[5][3])
2582 // pop all tags till specified one
2583 for (j = pos; (j >= 0) && (strcmp(stack[j], tag)); --j)
2584 os << "</" << stack[j] << ">";
2587 os << "</" << tag << ">";
2589 // push all tags, but the specified one
2590 for (j = j + 1; j <= pos; ++j) {
2591 os << "<" << stack[j] << ">";
2592 strcpy(stack[j-1], stack[j]);
2598 // Handle internal paragraph parsing -- layout already processed.
2600 // checks, if newcol chars should be put into this line
2601 // writes newline, if necessary.
2603 void linux_doc_line_break(ostream & os, unsigned int & colcount,
2604 const unsigned int newcol)
2607 if (colcount > lyxrc.ascii_linelen) {
2609 colcount = newcol; // assume write after this call
2614 void Buffer::SimpleLinuxDocOnePar(ostream & os, LyXParagraph * par,
2615 int desc_on, int const /*depth*/)
2617 LyXFont font1, font2;
2620 LyXParagraph::size_type main_body;
2622 LyXLayout const & style = textclasslist.Style(params.textclass,
2625 char family_type = 0; // family font flag
2626 bool is_bold = false; // series font flag
2627 char shape_type = 0; // shape font flag
2628 bool is_em = false; // emphasis (italic) font flag
2630 int stack_num = -1; // style stack position
2631 // Can this be rewritten to use a std::stack, please. (Lgb)
2632 char stack[5][3]; // style stack
2633 unsigned int char_line_count = 5; // Heuristic choice ;-)
2635 if (style.labeltype != LABEL_MANUAL)
2638 main_body = par->BeginningOfMainBody();
2640 // gets paragraph main font
2642 font1 = style.labelfont;
2647 // parsing main loop
2648 for (LyXParagraph::size_type i = 0;
2649 i < par->size(); ++i) {
2652 if (i == main_body && !par->IsDummy()) {
2657 font2 = par->getFont(i);
2659 if (font1.family() != font2.family()) {
2660 switch(family_type) {
2662 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2663 push_tag(os, "tt", stack_num, stack);
2666 else if (font2.family() == LyXFont::SANS_FAMILY) {
2667 push_tag(os, "sf", stack_num, stack);
2672 pop_tag(os, "tt", stack_num, stack);
2673 if (font2.family() == LyXFont::SANS_FAMILY) {
2674 push_tag(os, "sf", stack_num, stack);
2682 pop_tag(os, "sf", stack_num, stack);
2683 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2684 push_tag(os, "tt", stack_num, stack);
2694 if (font1.series() != font2.series()) {
2695 if (font2.series() == LyXFont::BOLD_SERIES) {
2696 push_tag(os, "bf", stack_num, stack);
2700 pop_tag(os, "bf", stack_num, stack);
2705 // handle italic and slanted fonts
2706 if (font1.shape() != font2.shape()) {
2707 switch(shape_type) {
2709 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2710 push_tag(os, "it", stack_num, stack);
2713 else if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2714 push_tag(os, "sl", stack_num, stack);
2719 pop_tag(os, "it", stack_num, stack);
2720 if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2721 push_tag(os, "sl", stack_num, stack);
2729 pop_tag(os, "sl", stack_num, stack);
2730 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2731 push_tag(os, "it", stack_num, stack);
2740 if (font1.emph() != font2.emph()) {
2741 if (font2.emph() == LyXFont::ON) {
2742 push_tag(os, "em", stack_num, stack);
2745 pop_tag(os, "em", stack_num, stack);
2750 c = par->GetChar(i);
2752 if (font2.latex() == LyXFont::ON) {
2753 // "TeX"-Mode on == > SGML-Mode on.
2755 os << c; // see LaTeX-Generation...
2757 } else if (c == LyXParagraph::META_INSET) {
2758 inset = par->GetInset(i);
2759 inset->Linuxdoc(os);
2762 if (par->linuxDocConvertChar(c, sgml_string)
2763 && !style.free_spacing) { // in freespacing
2765 // non-breaking characters
2769 linux_doc_line_break(os, char_line_count, 6);
2774 linux_doc_line_break(os, char_line_count, 1);
2780 char_line_count += sgml_string.length();
2786 // needed if there is an optional argument but no contents
2787 if (main_body > 0 && main_body == par->size()) {
2791 // pop all defined Styles
2792 for (j = stack_num; j >= 0; --j) {
2793 linux_doc_line_break(os,
2795 3 + strlen(stack[j]));
2796 os << "</" << stack[j] << ">";
2799 // resets description flag correctly
2802 // <tag> not closed...
2803 linux_doc_line_break(os, char_line_count, 6);
2807 // fprintf(file, "</p>");
2813 // Print an error message.
2814 void Buffer::LinuxDocError(LyXParagraph * par, int pos,
2815 char const * message)
2817 InsetError * new_inset;
2819 // insert an error marker in text
2820 new_inset = new InsetError(message);
2821 par->InsertChar(pos, LyXParagraph::META_INSET);
2822 par->InsertInset(pos, new_inset);
2825 // This constant defines the maximum number of
2826 // environment layouts that can be nesteded.
2827 // The same applies for command layouts.
2828 // These values should be more than enough.
2829 // José Matos (1999/07/22)
2831 enum { MAX_NEST_LEVEL = 25};
2833 void Buffer::makeDocBookFile(string const & fname, int column)
2835 LyXParagraph * par = paragraph;
2837 string top_element= textclasslist.LatexnameOfClass(params.textclass);
2838 // Please use a real stack.
2839 string environment_stack[MAX_NEST_LEVEL];
2840 string environment_inner[MAX_NEST_LEVEL];
2841 // Please use a real stack.
2842 string command_stack[MAX_NEST_LEVEL];
2843 bool command_flag= false;
2844 int command_depth= 0, command_base= 0, cmd_depth= 0;
2846 string item_name, command_name;
2847 string c_depth, c_params, tmps;
2849 int depth = 0; // paragraph depth
2851 tex_code_break_column = column;
2853 ofstream ofs(fname.c_str());
2855 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2861 ofs << "<!doctype " << top_element
2862 << " public \"-//OASIS//DTD DocBook V3.1//EN\"";
2864 if (params.preamble.empty())
2867 ofs << "\n [ " << params.preamble << " \n]>\n\n";
2869 ofs << "<!-- DocBook file was created by " << LYX_DOCVERSION
2870 << "\n See http://www.lyx.org/ for more information -->\n";
2872 if(params.options.empty())
2873 sgmlOpenTag(ofs, 0, top_element);
2875 string top = top_element;
2877 top += params.options;
2878 sgmlOpenTag(ofs, 0, top);
2882 int desc_on = 0; // description mode
2883 LyXLayout const & style =
2884 textclasslist.Style(users->buffer()->params.textclass,
2886 #ifdef WITH_WARNINGS
2887 #warning please check if this call is really needed!!!
2889 // par->AutoDeleteInsets();
2891 // environment tag closing
2892 for( ; depth > par->depth; --depth) {
2893 if(environment_inner[depth] != "!-- --") {
2894 item_name= "listitem";
2895 sgmlCloseTag(ofs, command_depth + depth,
2897 if( environment_inner[depth] == "varlistentry")
2898 sgmlCloseTag(ofs, depth+command_depth,
2899 environment_inner[depth]);
2901 sgmlCloseTag(ofs, depth + command_depth,
2902 environment_stack[depth]);
2903 environment_stack[depth].erase();
2904 environment_inner[depth].erase();
2907 if(depth == par->depth
2908 && environment_stack[depth] != style.latexname()
2909 && !environment_stack[depth].empty()) {
2910 if(environment_inner[depth] != "!-- --") {
2911 item_name= "listitem";
2912 sgmlCloseTag(ofs, command_depth+depth,
2914 if( environment_inner[depth] == "varlistentry")
2916 depth + command_depth,
2917 environment_inner[depth]);
2920 sgmlCloseTag(ofs, depth + command_depth,
2921 environment_stack[depth]);
2923 environment_stack[depth].erase();
2924 environment_inner[depth].erase();
2927 // Write opening SGML tags.
2928 switch(style.latextype) {
2929 case LATEX_PARAGRAPH:
2930 if(style.latexname() != "dummy")
2931 sgmlOpenTag(ofs, depth+command_depth,
2937 LinuxDocError(par, 0,
2938 _("Error : Wrong depth for "
2939 "LatexType Command.\n"));
2941 command_name = style.latexname();
2943 tmps = style.latexparam();
2944 c_params = split(tmps, c_depth,'|');
2946 cmd_depth= atoi(c_depth.c_str());
2949 if(cmd_depth<command_base) {
2950 for(int j = command_depth;
2951 j >= command_base; --j)
2952 if(!command_stack[j].empty())
2953 sgmlCloseTag(ofs, j, command_stack[j]);
2954 command_depth= command_base= cmd_depth;
2956 else if(cmd_depth <= command_depth) {
2957 for(int j = command_depth;
2958 j >= cmd_depth; --j)
2960 if(!command_stack[j].empty())
2961 sgmlCloseTag(ofs, j, command_stack[j]);
2962 command_depth= cmd_depth;
2965 command_depth= cmd_depth;
2968 command_depth = command_base = cmd_depth;
2969 command_flag = true;
2971 command_stack[command_depth]= command_name;
2973 // treat label as a special case for
2974 // more WYSIWYM handling.
2975 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2976 Inset * inset = par->GetInset(0);
2977 Inset::Code lyx_code = inset->LyxCode();
2978 if (lyx_code == Inset::LABEL_CODE){
2979 command_name += " id=\"";
2980 command_name += (static_cast<InsetCommand *>(inset))->getContents();
2981 command_name += "\"";
2986 sgmlOpenTag(ofs, depth + command_depth, command_name);
2987 item_name = "title";
2988 sgmlOpenTag(ofs, depth + 1 + command_depth, item_name);
2991 case LATEX_ENVIRONMENT:
2992 case LATEX_ITEM_ENVIRONMENT:
2993 if (depth < par->depth) {
2995 environment_stack[depth].erase();
2998 if (environment_stack[depth] != style.latexname()) {
2999 environment_stack[depth] = style.latexname();
3000 environment_inner[depth] = "!-- --";
3001 sgmlOpenTag(ofs, depth + command_depth,
3002 environment_stack[depth]);
3004 if(environment_inner[depth] != "!-- --") {
3005 item_name= "listitem";
3007 command_depth + depth,
3009 if (environment_inner[depth] == "varlistentry")
3011 depth + command_depth,
3012 environment_inner[depth]);
3016 if(style.latextype == LATEX_ENVIRONMENT) {
3017 if(!style.latexparam().empty())
3018 sgmlOpenTag(ofs, depth + command_depth,
3019 style.latexparam());
3023 desc_on = (style.labeltype == LABEL_MANUAL);
3026 environment_inner[depth]= "varlistentry";
3028 environment_inner[depth]= "listitem";
3030 sgmlOpenTag(ofs, depth + 1 + command_depth,
3031 environment_inner[depth]);
3035 sgmlOpenTag(ofs, depth + 1 + command_depth,
3040 sgmlOpenTag(ofs, depth + 1 + command_depth,
3045 sgmlOpenTag(ofs, depth + command_depth,
3052 SimpleDocBookOnePar(ofs, extra_par, par, desc_on,
3053 depth + 1 + command_depth);
3055 DocBookHandleFootnote(ofs, par,
3056 depth + 1 + command_depth);
3058 while(par && par->IsDummy());
3061 // write closing SGML tags
3062 switch(style.latextype) {
3065 sgmlCloseTag(ofs, depth + command_depth, end_tag);
3067 case LATEX_ENVIRONMENT:
3068 if(!style.latexparam().empty())
3069 sgmlCloseTag(ofs, depth + command_depth,
3070 style.latexparam());
3072 case LATEX_ITEM_ENVIRONMENT:
3073 if(desc_on == 1) break;
3075 sgmlCloseTag(ofs, depth + 1 + command_depth, end_tag);
3077 case LATEX_PARAGRAPH:
3078 if(style.latexname() != "dummy")
3079 sgmlCloseTag(ofs, depth + command_depth,
3083 sgmlCloseTag(ofs, depth + command_depth,
3090 for(; depth >= 0; --depth) {
3091 if(!environment_stack[depth].empty()) {
3092 if(environment_inner[depth] != "!-- --") {
3093 item_name= "listitem";
3094 sgmlCloseTag(ofs, command_depth + depth,
3096 if( environment_inner[depth] == "varlistentry")
3097 sgmlCloseTag(ofs, depth + command_depth,
3098 environment_inner[depth]);
3101 sgmlCloseTag(ofs, depth + command_depth,
3102 environment_stack[depth]);
3106 for(int j = command_depth; j >= command_base; --j)
3107 if(!command_stack[j].empty())
3108 sgmlCloseTag(ofs, j, command_stack[j]);
3111 sgmlCloseTag(ofs, 0, top_element);
3114 // How to check for successful close
3118 void Buffer::SimpleDocBookOnePar(ostream & os, string & extra,
3119 LyXParagraph * par, int & desc_on,
3123 par->SimpleDocBookOneTablePar(os, extra, desc_on, depth);
3127 bool emph_flag = false;
3129 LyXLayout const & style = textclasslist.Style(params.textclass,
3132 LyXParagraph::size_type main_body;
3133 if (style.labeltype != LABEL_MANUAL)
3136 main_body = par->BeginningOfMainBody();
3138 // gets paragraph main font
3139 LyXFont font1 = main_body > 0 ? style.labelfont : style.font;
3141 int char_line_count = depth;
3142 if(!style.free_spacing)
3143 for (int j = 0; j < depth; ++j)
3146 // parsing main loop
3147 for (LyXParagraph::size_type i = 0;
3148 i < par->size(); ++i) {
3149 LyXFont font2 = par->getFont(i);
3151 // handle <emphasis> tag
3152 if (font1.emph() != font2.emph() && i) {
3153 if (font2.emph() == LyXFont::ON) {
3157 os << "</emphasis>";
3162 char c = par->GetChar(i);
3164 if (c == LyXParagraph::META_INSET) {
3165 Inset * inset = par->GetInset(i);
3167 std::ostringstream ost;
3168 inset->DocBook(ost);
3169 string tmp_out = ost.str().c_str();
3172 inset->DocBook(ost);
3174 char * ctmp = ost.str();
3175 string tmp_out(ctmp);
3179 // This code needs some explanation:
3180 // Two insets are treated specially
3181 // label if it is the first element in a command paragraph
3183 // graphics inside tables or figure floats can't go on
3184 // title (the equivalente in latex for this case is caption
3185 // and title should come first
3188 if(desc_on!= 3 || i!= 0) {
3189 if(!tmp_out.empty() && tmp_out[0] == '@') {
3191 extra += frontStrip(tmp_out, '@');
3193 os << frontStrip(tmp_out, '@');
3198 } else if (font2.latex() == LyXFont::ON) {
3199 // "TeX"-Mode on ==> SGML-Mode on.
3205 if (par->linuxDocConvertChar(c, sgml_string)
3206 && !style.free_spacing) { // in freespacing
3208 // non-breaking characters
3212 os << "\n</term><listitem><para>";
3224 // needed if there is an optional argument but no contents
3225 if (main_body > 0 && main_body == par->size()) {
3229 os << "</emphasis>";
3232 // resets description flag correctly
3235 // <term> not closed...
3243 int Buffer::runLaTeX()
3245 if (!users->text) return 0;
3247 ProhibitInput(users);
3249 // get LaTeX-Filename
3250 string name = getLatexName();
3252 string path = OnlyPath(filename);
3254 string org_path = path;
3255 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3259 Path p(path); // path to LaTeX file
3260 users->owner()->getMiniBuffer()->Set(_("Running LaTeX..."));
3262 // Remove all error insets
3263 bool a = users->removeAutoInsets();
3265 // Always generate the LaTeX file
3266 makeLaTeXFile(name, org_path, false);
3269 // do the LaTex run(s)
3271 string latex_command = lyxrc.pdf_mode ?
3272 lyxrc.pdflatex_command : lyxrc.latex_command;
3273 LaTeX latex(latex_command, name, filepath);
3274 int res = latex.run(terr,
3275 users->owner()->getMiniBuffer()); // running latex
3277 // check return value from latex.run().
3278 if ((res & LaTeX::NO_LOGFILE)) {
3279 WriteAlert(_("LaTeX did not work!"),
3280 _("Missing log file:"), name);
3281 } else if ((res & LaTeX::ERRORS)) {
3282 users->owner()->getMiniBuffer()->Set(_("Done"));
3283 // Insert all errors as errors boxes
3284 users->insertErrors(terr);
3286 // Dvi should also be kept dirty if the latex run
3287 // ends up with errors. However it should be possible
3288 // to view a dirty dvi too.
3290 //no errors or any other things to think about so:
3291 users->owner()->getMiniBuffer()->Set(_("Done"));
3295 // if we removed error insets before we ran LaTeX or if we inserted
3296 // error insets after we ran LaTeX this must be run:
3297 if (a || (res & LaTeX::ERRORS)){
3300 //users->updateScrollbar();
3304 return latex.getNumErrors();
3308 int Buffer::runLiterate()
3310 if (!users->text) return 0;
3312 ProhibitInput(users);
3314 // get LaTeX-Filename
3315 string name = getLatexName();
3316 // get Literate-Filename
3317 string lit_name = OnlyFilename(ChangeExtension (getLatexName(),
3318 lyxrc.literate_extension));
3320 string path = OnlyPath(filename);
3322 string org_path = path;
3323 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3327 Path p(path); // path to Literate file
3328 users->owner()->getMiniBuffer()->Set(_("Running Literate..."));
3330 // Remove all error insets
3331 bool a = users->removeAutoInsets();
3333 // generate the Literate file if necessary
3334 if (!isDviClean() || a) {
3335 makeLaTeXFile(lit_name, org_path, false);
3339 string latex_command = lyxrc.pdf_mode ?
3340 lyxrc.pdflatex_command : lyxrc.latex_command;
3341 Literate literate(latex_command, name, filepath,
3343 lyxrc.literate_command, lyxrc.literate_error_filter,
3344 lyxrc.build_command, lyxrc.build_error_filter);
3346 int res = literate.weave(terr, users->owner()->getMiniBuffer());
3348 // check return value from literate.weave().
3349 if ((res & Literate::NO_LOGFILE)) {
3350 WriteAlert(_("Literate command did not work!"),
3351 _("Missing log file:"), name);
3352 } else if ((res & Literate::ERRORS)) {
3353 users->owner()->getMiniBuffer()->Set(_("Done"));
3354 // Insert all errors as errors boxes
3355 users->insertErrors(terr);
3357 // Dvi should also be kept dirty if the latex run
3358 // ends up with errors. However it should be possible
3359 // to view a dirty dvi too.
3361 //no errors or any other things to think about so:
3362 users->owner()->getMiniBuffer()->Set(_("Done"));
3366 // if we removed error insets before we ran LaTeX or if we inserted
3367 // error insets after we ran LaTeX this must be run:
3368 if (a || (res & Literate::ERRORS)){
3371 //users->updateScrollbar();
3375 return literate.getNumErrors();
3379 int Buffer::buildProgram()
3381 if (!users->text) return 0;
3383 ProhibitInput(users);
3385 // get LaTeX-Filename
3386 string name = getLatexName();
3387 // get Literate-Filename
3388 string lit_name = OnlyFilename(ChangeExtension(getLatexName(),
3389 lyxrc.literate_extension));
3391 string path = OnlyPath(filename);
3393 string org_path = path;
3394 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3398 Path p(path); // path to Literate file
3399 users->owner()->getMiniBuffer()->Set(_("Building Program..."));
3401 // Remove all error insets
3402 bool a = users->removeAutoInsets();
3404 // generate the LaTeX file if necessary
3405 if (!isNwClean() || a) {
3406 makeLaTeXFile(lit_name, org_path, false);
3410 string latex_command = lyxrc.pdf_mode ?
3411 lyxrc.pdflatex_command : lyxrc.latex_command;
3412 Literate literate(latex_command, name, filepath,
3414 lyxrc.literate_command, lyxrc.literate_error_filter,
3415 lyxrc.build_command, lyxrc.build_error_filter);
3417 int res = literate.build(terr, users->owner()->getMiniBuffer());
3419 // check return value from literate.build().
3420 if ((res & Literate::NO_LOGFILE)) {
3421 WriteAlert(_("Build did not work!"),
3422 _("Missing log file:"), name);
3423 } else if ((res & Literate::ERRORS)) {
3424 users->owner()->getMiniBuffer()->Set(_("Done"));
3425 // Insert all errors as errors boxes
3426 users->insertErrors(terr);
3428 // Literate files should also be kept dirty if the literate
3429 // command run ends up with errors.
3431 //no errors or any other things to think about so:
3432 users->owner()->getMiniBuffer()->Set(_("Done"));
3436 // if we removed error insets before we ran Literate/Build or
3437 // if we inserted error insets after we ran Literate/Build this
3439 if (a || (res & Literate::ERRORS)){
3442 //users->updateScrollbar();
3446 return literate.getNumErrors();
3450 // This should be enabled when the Chktex class is implemented. (Asger)
3451 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
3452 // Other flags: -wall -v0 -x
3453 int Buffer::runChktex()
3455 if (!users->text) return 0;
3457 ProhibitInput(users);
3459 // get LaTeX-Filename
3460 string name = getLatexName();
3461 string path = OnlyPath(filename);
3463 string org_path = path;
3464 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3468 Path p(path); // path to LaTeX file
3469 users->owner()->getMiniBuffer()->Set(_("Running chktex..."));
3471 // Remove all error insets
3472 bool a = users->removeAutoInsets();
3474 // Generate the LaTeX file if neccessary
3475 if (!isDviClean() || a) {
3476 makeLaTeXFile(name, org_path, false);
3481 Chktex chktex(lyxrc.chktex_command, name, filepath);
3482 int res = chktex.run(terr); // run chktex
3485 WriteAlert(_("chktex did not work!"),
3486 _("Could not run with file:"), name);
3487 } else if (res > 0) {
3488 // Insert all errors as errors boxes
3489 users->insertErrors(terr);
3492 // if we removed error insets before we ran chktex or if we inserted
3493 // error insets after we ran chktex, this must be run:
3497 //users->updateScrollbar();
3506 void Buffer::RoffAsciiTable(ostream & os, LyXParagraph * par)
3508 LyXFont font1(LyXFont::ALL_INHERIT,params.language_info);
3511 LyXParagraph::size_type i;
3515 string fname1 = TmpFileName(string(), "RAT1");
3516 string fname2 = TmpFileName(string(), "RAT2");
3518 ofstream ofs(fname1.c_str());
3520 WriteAlert(_("LYX_ERROR:"),
3521 _("Cannot open temporary file:"), fname1);
3524 par->table->RoffEndOfCell(ofs, -1);
3525 for (i = 0; i < par->size(); ++i) {
3526 c = par->GetChar(i);
3527 if (par->table->IsContRow(cell)) {
3528 if (c == LyXParagraph::META_NEWLINE)
3532 font2 = par->GetFontSettings(i);
3533 if (font1.latex() != font2.latex()) {
3534 if (font2.latex() != LyXFont::OFF)
3538 case LyXParagraph::META_INSET:
3539 if ((inset = par->GetInset(i))) {
3541 stringstresm ss(ios::in | ios::out);
3568 case LyXParagraph::META_NEWLINE:
3569 if (par->table->CellHasContRow(cell)>= 0)
3570 par->RoffContTableRows(ofs, i+1, cell);
3571 par->table->RoffEndOfCell(ofs, cell);
3574 case LyXParagraph::META_HFILL:
3584 << "RoffAsciiTable:"
3585 " NULL char in structure." << endl;
3589 par->table->RoffEndOfCell(ofs, cell);
3591 string cmd = lyxrc.ascii_roff_command + " >" + fname2;
3592 cmd = subst(cmd, "$$FName", fname1);
3593 Systemcalls one(Systemcalls::System, cmd);
3594 if (!(lyxerr.debugging(Debug::ROFF))) {
3595 remove(fname1.c_str());
3597 ifstream ifs(fname2.c_str());
3599 WriteFSAlert(_("Error! Can't open temporary file:"), fname2);
3602 // now output the produced file
3606 WriteAlert(_("Error!"),
3607 _("Error executing *roff command on table"));
3608 // overread leading blank lines
3609 while(!ifs && (c == '\n'))
3612 for(j = 0; j < par->depth; ++j)
3614 while(!ifs && (c != '\n')) {
3619 // overread trailing blank lines
3620 while(!ifs && (c == '\n'))
3624 remove(fname2.c_str());
3629 /// changed Heinrich Bauer, 23/03/98
3630 bool Buffer::isDviClean() const
3632 if (lyxrc.use_tempdir)
3633 return dvi_clean_tmpd;
3635 return dvi_clean_orgd;
3639 /// changed Heinrich Bauer, 23/03/98
3640 void Buffer::markDviClean()
3642 if (lyxrc.use_tempdir)
3643 dvi_clean_tmpd = true;
3645 dvi_clean_orgd = true;
3649 /// changed Heinrich Bauer, 23/03/98
3650 void Buffer::markDviDirty()
3652 if (lyxrc.use_tempdir)
3653 dvi_clean_tmpd = false;
3655 dvi_clean_orgd = false;
3659 void Buffer::validate(LaTeXFeatures & features) const
3661 LyXParagraph * par = paragraph;
3662 LyXTextClass const & tclass =
3663 textclasslist.TextClass(params.textclass);
3665 // AMS Style is at document level
3667 features.amsstyle = (params.use_amsmath ||
3668 tclass.provides(LyXTextClass::amsmath));
3671 // We don't use "lyxerr.debug" because of speed. (Asger)
3672 if (lyxerr.debugging(Debug::LATEX))
3673 lyxerr << "Paragraph: " << par << endl;
3675 // Now just follow the list of paragraphs and run
3676 // validate on each of them.
3677 par->validate(features);
3679 // and then the next paragraph
3683 // the bullet shapes are buffer level not paragraph level
3684 // so they are tested here
3685 for (int i = 0; i < 4; ++i) {
3686 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
3687 int font = params.user_defined_bullets[i].getFont();
3690 .user_defined_bullets[i]
3697 features.latexsym = true;
3701 features.amssymb = true;
3703 else if ((font >= 2 && font <= 5)) {
3704 features.pifont = true;
3709 if (lyxerr.debugging(Debug::LATEX)) {
3710 features.showStruct();
3715 void Buffer::setPaperStuff()
3717 params.papersize = BufferParams::PAPER_DEFAULT;
3718 char c1 = params.paperpackage;
3719 if (c1 == BufferParams::PACKAGE_NONE) {
3720 char c2 = params.papersize2;
3721 if (c2 == BufferParams::VM_PAPER_USLETTER)
3722 params.papersize = BufferParams::PAPER_USLETTER;
3723 else if (c2 == BufferParams::VM_PAPER_USLEGAL)
3724 params.papersize = BufferParams::PAPER_LEGALPAPER;
3725 else if (c2 == BufferParams::VM_PAPER_USEXECUTIVE)
3726 params.papersize = BufferParams::PAPER_EXECUTIVEPAPER;
3727 else if (c2 == BufferParams::VM_PAPER_A3)
3728 params.papersize = BufferParams::PAPER_A3PAPER;
3729 else if (c2 == BufferParams::VM_PAPER_A4)
3730 params.papersize = BufferParams::PAPER_A4PAPER;
3731 else if (c2 == BufferParams::VM_PAPER_A5)
3732 params.papersize = BufferParams::PAPER_A5PAPER;
3733 else if ((c2 == BufferParams::VM_PAPER_B3) || (c2 == BufferParams::VM_PAPER_B4) ||
3734 (c2 == BufferParams::VM_PAPER_B5))
3735 params.papersize = BufferParams::PAPER_B5PAPER;
3736 } else if ((c1 == BufferParams::PACKAGE_A4) || (c1 == BufferParams::PACKAGE_A4WIDE) ||
3737 (c1 == BufferParams::PACKAGE_WIDEMARGINSA4))
3738 params.papersize = BufferParams::PAPER_A4PAPER;
3742 // This function should be in Buffer because it's a buffer's property (ale)
3743 string Buffer::getIncludeonlyList(char delim)
3746 for (inset_iterator it = inset_iterator_begin();
3747 it != inset_iterator_end(); ++it) {
3748 if ((*it)->LyxCode() == Inset::INCLUDE_CODE) {
3749 InsetInclude * insetinc =
3750 static_cast<InsetInclude *>(*it);
3751 if (insetinc->isInclude()
3752 && insetinc->isNoLoad()) {
3755 lst += OnlyFilename(ChangeExtension(insetinc->getContents(), string()));
3759 lyxerr.debug() << "Includeonly(" << lst << ')' << endl;
3764 vector<string> Buffer::getLabelList()
3766 /// if this is a child document and the parent is already loaded
3767 /// Use the parent's list instead [ale990407]
3768 if (!params.parentname.empty()
3769 && bufferlist.exists(params.parentname)) {
3770 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3772 return tmp->getLabelList();
3775 vector<string> label_list;
3776 for (inset_iterator it = inset_iterator_begin();
3777 it != inset_iterator_end(); ++it) {
3778 vector<string> l = (*it)->getLabelList();
3779 label_list.insert(label_list.end(), l.begin(), l.end());
3785 vector<vector<Buffer::TocItem> > Buffer::getTocList()
3787 vector<vector<TocItem> > l(4);
3788 LyXParagraph * par = paragraph;
3790 if (par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
3791 if (textclasslist.Style(params.textclass,
3792 par->GetLayout()).labeltype
3793 == LABEL_SENSITIVE) {
3797 tmp.str = par->String(false);
3798 switch (par->footnotekind) {
3799 case LyXParagraph::FIG:
3800 case LyXParagraph::WIDE_FIG:
3801 l[TOC_LOF].push_back(tmp);
3803 case LyXParagraph::TAB:
3804 case LyXParagraph::WIDE_TAB:
3805 l[TOC_LOT].push_back(tmp);
3807 case LyXParagraph::ALGORITHM:
3808 l[TOC_LOA].push_back(tmp);
3810 case LyXParagraph::FOOTNOTE:
3811 case LyXParagraph::MARGIN:
3815 } else if (!par->IsDummy()) {
3816 char labeltype = textclasslist.Style(params.textclass,
3817 par->GetLayout()).labeltype;
3819 if (labeltype >= LABEL_COUNTER_CHAPTER
3820 && labeltype <= LABEL_COUNTER_CHAPTER + params.tocdepth) {
3821 // insert this into the table of contents
3826 textclasslist.TextClass(params.textclass).maxcounter());
3827 tmp.str = par->String(true);
3828 l[TOC_TOC].push_back(tmp);
3836 // This is also a buffer property (ale)
3837 vector<pair<string,string> > Buffer::getBibkeyList()
3839 /// if this is a child document and the parent is already loaded
3840 /// Use the parent's list instead [ale990412]
3841 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3842 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3844 return tmp->getBibkeyList();
3847 vector<pair<string,string> > keys;
3848 LyXParagraph * par = paragraph;
3851 keys.push_back(pair<string,string>(par->bibkey->getContents(),
3852 par->String(false)));
3856 // Might be either using bibtex or a child has bibliography
3858 for (inset_iterator it = inset_iterator_begin();
3859 it != inset_iterator_end(); ++it) {
3860 // Search for Bibtex or Include inset
3861 if ((*it)->LyxCode() == Inset::BIBTEX_CODE) {
3862 vector<pair<string,string> > tmp =
3863 static_cast<InsetBibtex*>(*it)->getKeys();
3864 keys.insert(keys.end(), tmp.begin(), tmp.end());
3865 } else if ((*it)->LyxCode() == Inset::INCLUDE_CODE) {
3866 vector<pair<string,string> > tmp =
3867 static_cast<InsetInclude*>(*it)->getKeys();
3868 keys.insert(keys.end(), tmp.begin(), tmp.end());
3877 bool Buffer::isDepClean(string const & name) const
3879 DEPCLEAN * item = dep_clean;
3880 while (item && item->master != name)
3882 if (!item) return true;
3887 void Buffer::markDepClean(string const & name)
3890 dep_clean = new DEPCLEAN;
3891 dep_clean->clean = true;
3892 dep_clean->master = name;
3893 dep_clean->next = 0;
3895 DEPCLEAN* item = dep_clean;
3896 while (item && item->master != name)
3901 item = new DEPCLEAN;
3903 item->master = name;
3910 bool Buffer::Dispatch(string const & command)
3912 // Split command string into command and argument
3913 string cmd, line = frontStrip(command);
3914 string arg = strip(frontStrip(split(line, cmd, ' ')));
3916 return Dispatch(lyxaction.LookupFunc(cmd.c_str()), arg.c_str());
3920 bool Buffer::Dispatch(int action, string const & argument)
3922 bool dispatched = true;
3925 MenuExport(this, argument);
3935 void Buffer::ChangeLanguage(Language const * from, Language const * to)
3938 LyXParagraph * par = paragraph;
3940 par->ChangeLanguage(from, to);
3946 bool Buffer::isMultiLingual()
3949 LyXParagraph * par = paragraph;
3951 if (par->isMultiLingual())
3959 Buffer::inset_iterator::inset_iterator(LyXParagraph * paragraph,
3960 LyXParagraph::size_type pos)
3962 it = par->InsetIterator(pos);
3963 if (it == par->inset_iterator_end()) {
3970 void Buffer::inset_iterator::SetParagraph() {
3972 it = par->inset_iterator_begin();
3973 if (it != par->inset_iterator_end())
3978 // We maintain an invariant that whenever par = 0 then it = 0