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>
35 #pragma implementation "buffer.h"
39 #include "bufferlist.h"
41 #include "lyx_gui_misc.h"
42 #include "LyXAction.h"
45 #include "tex-strings.h"
48 #include "minibuffer.h"
51 #include "mathed/formulamacro.h"
52 #include "insets/lyxinset.h"
53 #include "insets/inseterror.h"
54 #include "insets/insetlabel.h"
55 #include "insets/insetref.h"
56 #include "insets/inseturl.h"
57 #include "insets/insetinfo.h"
58 #include "insets/insetquotes.h"
59 #include "insets/insetlatexaccent.h"
60 #include "insets/insetbib.h"
61 #include "insets/insetindex.h"
62 #include "insets/insetinclude.h"
63 #include "insets/insettoc.h"
64 #include "insets/insetlof.h"
65 #include "insets/insetlot.h"
66 #include "insets/insetloa.h"
67 #include "insets/insetparent.h"
68 #include "insets/insetspecialchar.h"
69 #include "insets/figinset.h"
70 #include "insets/insettext.h"
71 //#include "insets/insetnumber.h"
72 #include "insets/insetert.h"
73 #include "insets/insetgraphics.h"
74 #include "insets/insetfoot.h"
75 #include "support/filetools.h"
76 #include "support/path.h"
82 #include "LaTeXFeatures.h"
83 #include "support/syscall.h"
84 #include "support/lyxlib.h"
85 #include "support/FileInfo.h"
99 // Uncomment this line to enable a workaround for the weird behaviour
100 // of the cursor between a displayed inset and last character
101 // at the upper line. (Alejandro 20.9.96)
102 // #define BREAK_BEFORE_INSET
104 /* Lars, when changing this file sometime in the future to a list,
105 * please check out the figinsets-sideeffects described at the
106 * beginning of figinset.C Matthias (04.07.1996)
110 // all these externs should eventually be removed.
111 extern BufferList bufferlist;
113 extern void MenuExport(Buffer *, string const &);
114 extern LyXAction lyxaction;
117 static const float LYX_FORMAT = 2.16;
119 extern int tex_code_break_column;
121 extern void FreeUpdateTimer();
124 Buffer::Buffer(string const & file, bool ronly)
126 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
128 filepath = OnlyPath(file);
132 dvi_clean_orgd = false; // Heinrich Bauer, 23/03/98
133 dvi_clean_tmpd = false; // Heinrich Bauer, 23/03/98
138 if (read_only || (lyxrc.use_tempdir)) {
139 tmppath = CreateBufferTmpDir();
140 } else tmppath.clear();
146 lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
147 // here the buffer should take care that it is
148 // saved properly, before it goes into the void.
150 // make sure that views using this buffer
155 if (!tmppath.empty()) {
156 DestroyBufferTmpDir(tmppath);
159 LyXParagraph * par = paragraph;
160 LyXParagraph * tmppar;
170 string Buffer::getLatexName(bool no_path /* = true */) const
172 return ChangeExtension(MakeLatexName(filename),
177 void Buffer::setReadonly(bool flag /* = true */)
179 if (read_only != flag) {
182 updateAllVisibleBufferRelatedPopups();
185 WarnReadonly(filename);
190 bool Buffer::saveParamsAsDefaults()
192 string fname = AddName(AddPath(user_lyxdir, "templates/"),
194 Buffer defaults = Buffer(fname);
196 // Use the current buffer's parameters as default
197 defaults.params = params;
199 // add an empty paragraph. Is this enough?
200 defaults.paragraph = new LyXParagraph;
202 return defaults.writeFile(defaults.filename, false);
206 /// Update window titles of all users
207 // Should work on a list
208 void Buffer::updateTitles() const
210 if (users) users->owner()->updateWindowTitle();
214 /// Reset autosave timer of all users
215 // Should work on a list
216 void Buffer::resetAutosaveTimers() const
218 if (users) users->owner()->resetAutosaveTimer();
222 void Buffer::fileName(string const & newfile)
224 filename = MakeAbsPath(newfile);
225 filepath = OnlyPath(filename);
226 setReadonly(IsFileWriteable(filename) == 0);
231 // candidate for move to BufferView
232 // (at least some parts in the beginning of the func)
235 // changed to be public and have one parameter
236 // if par = 0 normal behavior
237 // else insert behavior
238 // Returns false if "\the_end" is not read for formats >= 2.13. (Asger)
239 #define USE_PARSE_FUNCTION 1
240 bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par)
244 char depth = 0; // signed or unsigned?
245 LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
246 LyXParagraph::footnote_kind footnotekind = LyXParagraph::FOOTNOTE;
247 bool the_end_read = false;
249 LyXParagraph * return_par = 0;
250 LyXFont font(LyXFont::ALL_INHERIT,params.language_info);
251 if (format < 2.16 && params.language == "hebrew")
252 font.setLanguage(default_language);
254 // If we are inserting, we cheat and get a token in advance
255 bool has_token = false;
259 par = new LyXParagraph;
261 users->text->BreakParagraph();
262 return_par = users->text->FirstParagraph();
265 // We don't want to adopt the parameters from the
266 // document we insert, so we skip until the text begins:
269 pretoken = lex.GetString();
270 if (pretoken == "\\layout") {
282 pretoken = lex.GetString();
285 // Profiling show this should give a lot: (Asger)
286 string const token = pretoken;
290 the_end_read = parseSingleLyXformat2Token(lex, par, return_par,
299 paragraph = return_par;
305 bool Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
306 LyXParagraph *& return_par,
307 string const & token, int & pos,
308 char & depth, LyXFont & font,
309 LyXParagraph::footnote_flag & footnoteflag,
310 LyXParagraph::footnote_kind & footnotekind)
315 bool the_end_read = false;
317 if (token[0] != '\\') {
318 int n = token.length();
319 for (int i = 0; i < n; ++i) {
320 par->InsertChar(pos, token[i]);
321 par->SetFont(pos, font);
324 } else if (token == "\\i") {
325 inset = new InsetLatexAccent;
327 par->InsertChar(pos, LyXParagraph::META_INSET);
328 par->InsertInset(pos, inset);
329 par->SetFont(pos, font);
331 } else if (token == "\\layout") {
336 par = new LyXParagraph(par);
340 string layoutname = lex.GetString();
341 pair<bool, LyXTextClass::LayoutList::size_type> pp
342 = textclasslist.NumberOfLayout(params.textclass,
345 par->layout = pp.second;
346 } else { // layout not found
347 // use default layout "Standard" (0)
350 // Test whether the layout is obsolete.
351 LyXLayout const & layout =
352 textclasslist.Style(params.textclass,
354 if (!layout.obsoleted_by().empty())
356 textclasslist.NumberOfLayout(params.textclass,
357 layout.obsoleted_by()).second;
358 par->footnoteflag = footnoteflag;
359 par->footnotekind = footnotekind;
361 font = LyXFont(LyXFont::ALL_INHERIT,params.language_info);
362 if (format < 2.16 && params.language == "hebrew")
363 font.setLanguage(default_language);
364 } else if (token == "\\end_float") {
369 par = new LyXParagraph(par);
371 footnotekind = LyXParagraph::FOOTNOTE;
372 footnoteflag = LyXParagraph::NO_FOOTNOTE;
375 par->layout = LYX_DUMMY_LAYOUT;
376 font = LyXFont(LyXFont::ALL_INHERIT, params.language_info);
377 if (format < 2.16 && params.language == "hebrew")
378 font.setLanguage(default_language);
379 } else if (token == "\\begin_float") {
380 tmpret = lex.FindToken(string_footnotekinds);
381 if (tmpret == -1) ++tmpret;
382 if (tmpret != LYX_LAYOUT_DEFAULT)
383 footnotekind = static_cast<LyXParagraph::footnote_kind>(tmpret); // bad
384 if (footnotekind == LyXParagraph::FOOTNOTE
385 || footnotekind == LyXParagraph::MARGIN)
386 footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
388 footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
389 } else if (token == "\\begin_deeper") {
391 } else if (token == "\\end_deeper") {
393 lex.printError("\\end_deeper: "
394 "depth is already null");
398 } else if (token == "\\begin_preamble") {
399 params.readPreamble(lex);
400 } else if (token == "\\textclass") {
402 pair<bool, LyXTextClassList::size_type> pp =
403 textclasslist.NumberOfClass(lex.GetString());
405 params.textclass = pp.second;
407 lex.printError("Unknown textclass `$$Token'");
408 params.textclass = 0;
410 if (!textclasslist.Load(params.textclass)) {
411 // if the textclass wasn't loaded properly
412 // we need to either substitute another
413 // or stop loading the file.
414 // I can substitute but I don't see how I can
415 // stop loading... ideas?? ARRae980418
416 WriteAlert(_("Textclass Loading Error!"),
417 string(_("Can't load textclass ")) +
418 textclasslist.NameOfClass(params.textclass),
419 _("-- substituting default"));
420 params.textclass = 0;
422 } else if (token == "\\options") {
424 params.options = lex.GetString();
425 } else if (token == "\\language") {
426 params.readLanguage(lex);
427 } else if (token == "\\fontencoding") {
429 } else if (token == "\\inputencoding") {
431 params.inputenc = lex.GetString();
432 } else if (token == "\\graphics") {
433 params.readGraphicsDriver(lex);
434 } else if (token == "\\fontscheme") {
436 params.fonts = lex.GetString();
437 } else if (token == "\\noindent") {
438 par->noindent = true;
439 } else if (token == "\\fill_top") {
440 par->added_space_top = VSpace(VSpace::VFILL);
441 } else if (token == "\\fill_bottom") {
442 par->added_space_bottom = VSpace(VSpace::VFILL);
443 } else if (token == "\\line_top") {
444 par->line_top = true;
445 } else if (token == "\\line_bottom") {
446 par->line_bottom = true;
447 } else if (token == "\\pagebreak_top") {
448 par->pagebreak_top = true;
449 } else if (token == "\\pagebreak_bottom") {
450 par->pagebreak_bottom = true;
451 } else if (token == "\\start_of_appendix") {
452 par->start_of_appendix = true;
453 } else if (token == "\\paragraph_separation") {
454 tmpret = lex.FindToken(string_paragraph_separation);
455 if (tmpret == -1) ++tmpret;
456 if (tmpret != LYX_LAYOUT_DEFAULT)
457 params.paragraph_separation =
458 static_cast<BufferParams::PARSEP>(tmpret);
459 } else if (token == "\\defskip") {
461 params.defskip = VSpace(lex.GetString());
463 } else if (token == "\\no_isolatin1") { // obsolete
465 } else if (token == "\\no_babel") { // obsolete
467 } else if (token == "\\no_epsfig") { // obsolete
470 } else if (token == "\\epsfig") { // obsolete
471 // Indeed it is obsolete, but we HAVE to be backwards
472 // compatible until 0.14, because otherwise all figures
473 // in existing documents are irretrivably lost. (Asger)
474 params.readGraphicsDriver(lex);
475 } else if (token == "\\quotes_language") {
476 tmpret = lex.FindToken(string_quotes_language);
477 if (tmpret == -1) ++tmpret;
478 if (tmpret != LYX_LAYOUT_DEFAULT) {
479 InsetQuotes::quote_language tmpl =
480 InsetQuotes::EnglishQ;
483 tmpl = InsetQuotes::EnglishQ;
486 tmpl = InsetQuotes::SwedishQ;
489 tmpl = InsetQuotes::GermanQ;
492 tmpl = InsetQuotes::PolishQ;
495 tmpl = InsetQuotes::FrenchQ;
498 tmpl = InsetQuotes::DanishQ;
501 params.quotes_language = tmpl;
503 } else if (token == "\\quotes_times") {
505 switch(lex.GetInteger()) {
507 params.quotes_times = InsetQuotes::SingleQ;
510 params.quotes_times = InsetQuotes::DoubleQ;
513 } else if (token == "\\papersize") {
514 tmpret = lex.FindToken(string_papersize);
518 params.papersize2 = tmpret;
519 } else if (token == "\\paperpackage") {
520 tmpret = lex.FindToken(string_paperpackages);
523 params.paperpackage = BufferParams::PACKAGE_NONE;
525 params.paperpackage = tmpret;
526 } else if (token == "\\use_geometry") {
528 params.use_geometry = lex.GetInteger();
529 } else if (token == "\\use_amsmath") {
531 params.use_amsmath = lex.GetInteger();
532 } else if (token == "\\paperorientation") {
533 tmpret = lex.FindToken(string_orientation);
534 if (tmpret == -1) ++tmpret;
535 if (tmpret != LYX_LAYOUT_DEFAULT)
536 params.orientation = static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
537 } else if (token == "\\paperwidth") {
539 params.paperwidth = lex.GetString();
540 } else if (token == "\\paperheight") {
542 params.paperheight = lex.GetString();
543 } else if (token == "\\leftmargin") {
545 params.leftmargin = lex.GetString();
546 } else if (token == "\\topmargin") {
548 params.topmargin = lex.GetString();
549 } else if (token == "\\rightmargin") {
551 params.rightmargin = lex.GetString();
552 } else if (token == "\\bottommargin") {
554 params.bottommargin = lex.GetString();
555 } else if (token == "\\headheight") {
557 params.headheight = lex.GetString();
558 } else if (token == "\\headsep") {
560 params.headsep = lex.GetString();
561 } else if (token == "\\footskip") {
563 params.footskip = lex.GetString();
564 } else if (token == "\\paperfontsize") {
566 params.fontsize = strip(lex.GetString());
567 } else if (token == "\\papercolumns") {
569 params.columns = lex.GetInteger();
570 } else if (token == "\\papersides") {
572 switch(lex.GetInteger()) {
574 case 1: params.sides = LyXTextClass::OneSide; break;
575 case 2: params.sides = LyXTextClass::TwoSides; break;
577 } else if (token == "\\paperpagestyle") {
579 params.pagestyle = strip(lex.GetString());
580 } else if (token == "\\bullet") {
582 int index = lex.GetInteger();
584 int temp_int = lex.GetInteger();
585 params.user_defined_bullets[index].setFont(temp_int);
586 params.temp_bullets[index].setFont(temp_int);
588 temp_int = lex.GetInteger();
589 params.user_defined_bullets[index].setCharacter(temp_int);
590 params.temp_bullets[index].setCharacter(temp_int);
592 temp_int = lex.GetInteger();
593 params.user_defined_bullets[index].setSize(temp_int);
594 params.temp_bullets[index].setSize(temp_int);
596 string temp_str = lex.GetString();
597 if (temp_str != "\\end_bullet") {
598 // this element isn't really necessary for
599 // parsing but is easier for humans
600 // to understand bullets. Put it back and
601 // set a debug message?
602 lex.printError("\\end_bullet expected, got" + temp_str);
603 //how can I put it back?
605 } else if (token == "\\bulletLaTeX") {
607 int index = lex.GetInteger();
609 string temp_str = lex.GetString(), sum_str;
610 while (temp_str != "\\end_bullet") {
611 // this loop structure is needed when user
612 // enters an empty string since the first
613 // thing returned will be the \\end_bullet
615 // if the LaTeX entry has spaces. Each element
616 // therefore needs to be read in turn
619 temp_str = lex.GetString();
621 params.user_defined_bullets[index].setText(sum_str);
622 params.temp_bullets[index].setText(sum_str);
623 } else if (token == "\\secnumdepth") {
625 params.secnumdepth = lex.GetInteger();
626 } else if (token == "\\tocdepth") {
628 params.tocdepth = lex.GetInteger();
629 } else if (token == "\\baselinestretch") { // obsolete
630 lex.nextToken(); // should not be used directly
632 // Will probably keep a kind of support just for
634 params.spacing.set(Spacing::Other, lex.GetFloat());
635 } else if (token == "\\spacing") {
637 string tmp = strip(lex.GetString());
638 if (tmp == "single") {
639 params.spacing.set(Spacing::Single);
640 } else if (tmp == "onehalf") {
641 params.spacing.set(Spacing::Onehalf);
642 } else if (tmp == "double") {
643 params.spacing.set(Spacing::Double);
644 } else if (tmp == "other") {
646 params.spacing.set(Spacing::Other,
649 lex.printError("Unknown spacing token: '$$Token'");
651 } else if (token == "\\paragraph_spacing") {
653 string tmp = strip(lex.GetString());
654 if (tmp == "single") {
655 par->spacing.set(Spacing::Single);
656 } else if (tmp == "onehalf") {
657 par->spacing.set(Spacing::Onehalf);
658 } else if (tmp == "double") {
659 par->spacing.set(Spacing::Double);
660 } else if (tmp == "other") {
662 par->spacing.set(Spacing::Other,
665 lex.printError("Unknown spacing token: '$$Token'");
667 } else if (token == "\\float_placement") {
669 params.float_placement = lex.GetString();
670 } else if (token == "\\cursor") { // obsolete
671 // 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 == "\\direction") { // obsolete
710 lex.printError("Command \\direction is obsolete");
712 string tok = lex.GetString();
714 font.setLanguage(&languages["hebrew"]);
715 else if (tok == "default")
716 if (params.language == "hebrew")
717 font.setLanguage(default_language);
719 font.setLanguage(params.language_info);
721 lex.printError("Unknown direction `$$Token'");
722 } else if (token == "\\emph") {
724 font.setEmph(font.setLyXMisc(lex.GetString()));
725 } else if (token == "\\bar") {
727 string tok = lex.GetString();
728 // This is dirty, but gone with LyX3. (Asger)
730 font.setUnderbar(LyXFont::ON);
731 else if (tok == "no")
732 font.setUnderbar(LyXFont::OFF);
733 else if (tok == "default")
734 font.setUnderbar(LyXFont::INHERIT);
736 lex.printError("Unknown bar font flag "
738 } else if (token == "\\noun") {
740 font.setNoun(font.setLyXMisc(lex.GetString()));
741 } else if (token == "\\color") {
743 font.setLyXColor(lex.GetString());
744 } else if (token == "\\align") {
745 tmpret = lex.FindToken(string_align);
746 if (tmpret == -1) ++tmpret;
747 if (tmpret != LYX_LAYOUT_DEFAULT) { // tmpret != 99 ???
749 for (; tmpret > 0; --tmpret)
750 tmpret2 = tmpret2 * 2;
751 par->align = LyXAlignment(tmpret2);
753 } else if (token == "\\added_space_top") {
755 par->added_space_top = VSpace(lex.GetString());
756 } else if (token == "\\added_space_bottom") {
758 par->added_space_bottom = VSpace(lex.GetString());
759 } else if (token == "\\pextra_type") {
761 par->pextra_type = lex.GetInteger();
762 } else if (token == "\\pextra_width") {
764 par->pextra_width = lex.GetString();
765 } else if (token == "\\pextra_widthp") {
767 par->pextra_widthp = lex.GetString();
768 } else if (token == "\\pextra_alignment") {
770 par->pextra_alignment = lex.GetInteger();
771 } else if (token == "\\pextra_hfill") {
773 par->pextra_hfill = lex.GetInteger();
774 } else if (token == "\\pextra_start_minipage") {
776 par->pextra_start_minipage = lex.GetInteger();
777 } else if (token == "\\labelwidthstring") {
779 par->labelwidthstring = lex.GetString();
780 /* do not delete this token, it is still needed! */
781 } else if (token == "\\end_inset") {
782 /* simple ignore this. The insets do not have
784 // but insets should read it, it is a part of
785 //the inset isn't it? Lgb.
786 } else if (token == "\\begin_inset") {
788 tmptok = lex.GetString();
789 /* test the different insets */
790 if (tmptok == "Quotes") {
791 inset = new InsetQuotes;
793 par->InsertChar(pos, LyXParagraph::META_INSET);
794 par->InsertInset(pos, inset);
795 par->SetFont(pos, font);
797 } else if (tmptok == "\\i") {
798 inset = new InsetLatexAccent;
800 par->InsertChar(pos, LyXParagraph::META_INSET);
801 par->InsertInset(pos, inset);
802 par->SetFont(pos, font);
804 } else if (tmptok == "FormulaMacro") {
805 inset = new InsetFormulaMacro;
807 par->InsertChar(pos, LyXParagraph::META_INSET);
808 par->InsertInset(pos, inset);
809 par->SetFont(pos, font);
811 } else if (tmptok == "Formula") {
812 inset = new InsetFormula;
814 par->InsertChar(pos, LyXParagraph::META_INSET);
815 par->InsertInset(pos, inset);
816 par->SetFont(pos, font);
818 } else if (tmptok == "Figure") {
819 inset = new InsetFig(100, 100, this);
821 par->InsertChar(pos, LyXParagraph::META_INSET);
822 par->InsertInset(pos, inset);
823 par->SetFont(pos, font);
825 } else if (tmptok == "Info") {
826 inset = new InsetInfo;
828 par->InsertChar(pos, LyXParagraph::META_INSET);
829 par->InsertInset(pos, inset);
830 par->SetFont(pos, font);
832 } else if (tmptok == "Include") {
833 inset = new InsetInclude(string(), this);
835 par->InsertChar(pos, LyXParagraph::META_INSET);
836 par->InsertInset(pos, inset);
837 par->SetFont(pos, font);
839 } else if (tmptok == "ERT") {
840 inset = new InsetERT(this);
842 par->InsertChar(pos, LyXParagraph::META_INSET);
843 par->InsertInset(pos, inset);
844 par->SetFont(pos, font);
846 } else if (tmptok == "Text") {
847 inset = new InsetText(this);
849 par->InsertChar(pos, LyXParagraph::META_INSET);
850 par->InsertInset(pos, inset);
851 par->SetFont(pos, font);
854 } else if (tmptok == "Number") {
855 inset = new InsetNumber(this);
857 par->InsertChar(pos, LyXParagraph::META_INSET);
858 par->InsertInset(pos, inset);
859 par->SetFont(pos, font);
862 } else if (tmptok == "Foot") {
863 inset = new InsetFoot(this);
865 par->InsertChar(pos, LyXParagraph::META_INSET);
866 par->InsertInset(pos, inset);
867 par->SetFont(pos, font);
869 } else if (tmptok == "GRAPHICS") {
870 inset = new InsetGraphics;
872 par->InsertChar(pos, LyXParagraph::META_INSET);
873 par->InsertInset(pos, inset);
874 par->SetFont(pos, font);
875 } else if (tmptok == "LatexCommand") {
878 if (inscmd.getCmdName() == "cite") {
879 inset = new InsetCitation(inscmd.getContents(), inscmd.getOptions());
880 } else if (inscmd.getCmdName() == "bibitem") {
881 lex.printError("Wrong place for bibitem");
882 inset = inscmd.Clone();
883 } else if (inscmd.getCmdName() == "BibTeX") {
884 inset = new InsetBibtex(inscmd.getContents(), inscmd.getOptions(), this);
885 } else if (inscmd.getCmdName() == "index") {
886 inset = new InsetIndex(inscmd.getContents());
887 } else if (inscmd.getCmdName() == "include") {
888 inset = new InsetInclude(inscmd.getContents(), this);
889 } else if (inscmd.getCmdName() == "label") {
890 inset = new InsetLabel(inscmd.getCommand());
891 } else if (inscmd.getCmdName() == "url"
892 || inscmd.getCmdName() == "htmlurl") {
893 inset = new InsetUrl(inscmd.getCommand());
894 } else if (inscmd.getCmdName() == "ref"
895 || inscmd.getCmdName() == "pageref") {
896 if (!inscmd.getOptions().empty() || !inscmd.getContents().empty()) {
897 inset = new InsetRef(inscmd, this);
899 #warning Check if this else clause is still needed. (Lgb)
901 // This condition comes from a
902 // temporary solution to the latexdel
903 // ref inset that was transformed to
904 // an empty ref inset plus the body
905 // surronded by latexdel insets
907 string cont, opt, tmptmptok, cmdname;
909 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
914 tmptmptok = lex.GetString();
915 if(tmptmptok[0] == '\\') {
916 if( tmptmptok == "\\backslash")
926 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
931 tmptmptok = lex.GetString();
932 if(tmptmptok[0] == '\\') {
933 if( tmptmptok == "\\backslash")
943 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
949 cmdname = "\\" + inscmd.getCmdName();
950 cmdname += "[" + cont + "]";
951 cmdname += "{" + opt + "}";
952 inset = new InsetRef(cmdname, this);
955 } else if (inscmd.getCmdName() == "tableofcontents") {
956 inset = new InsetTOC(this);
957 } else if (inscmd.getCmdName() == "listoffigures") {
958 inset = new InsetLOF(this);
959 } else if (inscmd.getCmdName() == "listofalgorithms") {
960 inset = new InsetLOA(this);
961 } else if (inscmd.getCmdName() == "listoftables") {
962 inset = new InsetLOT(this);
963 } else if (inscmd.getCmdName() == "printindex") {
964 inset = new InsetPrintIndex(this);
965 } else if (inscmd.getCmdName() == "lyxparent") {
966 inset = new InsetParent(inscmd.getContents(), this);
970 par->InsertChar(pos, LyXParagraph::META_INSET);
971 par->InsertInset(pos, inset);
972 par->SetFont(pos, font);
976 } else if (token == "\\InsetQuotes") {
977 inset = new InsetQuotes;
979 par->InsertChar(pos, LyXParagraph::META_INSET);
980 par->InsertInset(pos, inset);
981 par->SetFont(pos, font);
983 } else if (token == "\\InsetFormula") {
984 inset = new InsetFormula;
986 par->InsertChar(pos, LyXParagraph::META_INSET);
987 par->InsertInset(pos, inset);
988 par->SetFont(pos, font);
990 } else if (token == "\\SpecialChar") {
991 LyXLayout const & layout =
992 textclasslist.Style(params.textclass,
995 // Insets don't make sense in a free-spacing context! ---Kayvan
996 if (layout.free_spacing)
1001 next_token = lex.GetString();
1002 if (next_token == "\\-") {
1003 par->InsertChar(pos, '-');
1004 par->SetFont(pos, font);
1005 } else if (next_token == "\\protected_separator") {
1006 par->InsertChar(pos, ' ');
1007 par->SetFont(pos, font);
1009 lex.printError("Token `$$Token' "
1011 "paragraph layout!");
1018 inset = new InsetSpecialChar;
1020 par->InsertChar(pos, LyXParagraph::META_INSET);
1021 par->InsertInset(pos, inset);
1022 par->SetFont(pos, font);
1025 } else if (token == "\\Figure") {
1026 inset = new InsetFig(100, 100, this);
1028 par->InsertChar(pos, LyXParagraph::META_INSET);
1029 par->InsertInset(pos, inset);
1030 par->SetFont(pos, font);
1032 } else if (token == "\\newline") { // soon obsolete
1034 par->InsertChar(pos, LyXParagraph::META_NEWLINE);
1035 par->SetFont(pos, font);
1037 inset = new InsetSpecialChar(InsetSpecialChar::NEWLINE);
1038 par->InsertChar(pos, LyXParagraph::META_INSET);
1039 par->InsertInset(pos, inset);
1040 par->SetFont(pos, font);
1043 } else if (token == "\\LyXTable") {
1044 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
1051 LyXLayout const & layout =
1052 textclasslist.Style(params.textclass,
1055 if (layout.free_spacing) {
1056 par->InsertChar(pos, ' ');
1057 par->SetFont(pos, font);
1059 inset = new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
1060 par->InsertChar(pos, LyXParagraph::META_INSET);
1061 par->InsertInset(pos, inset);
1062 par->SetFont(pos, font);
1065 par->InsertChar(pos, LyXParagraph::META_PROTECTED_SEPARATOR);
1066 par->SetFont(pos, font);
1069 } else if (token == "\\bibitem") { // ale970302
1071 par->bibkey = new InsetBibKey;
1072 par->bibkey->Read(lex);
1073 }else if (token == "\\backslash") {
1074 par->InsertChar(pos, '\\');
1075 par->SetFont(pos, font);
1077 }else if (token == "\\the_end") {
1078 the_end_read = true;
1080 // This should be insurance for the future: (Asger)
1081 lex.printError("Unknown token `$$Token'. "
1082 "Inserting as text.");
1083 int n = token.length();
1084 for (int i = 0; i < n; ++i) {
1085 par->InsertChar(pos, token[i]);
1086 par->SetFont(pos, font);
1090 return the_end_read;
1093 bool Buffer::readFile(LyXLex & lex, LyXParagraph * par)
1099 token = lex.GetString();
1100 if (token == "\\lyxformat") { // the first token _must_ be...
1102 format = lex.GetFloat();
1104 if (LYX_FORMAT - format > 0.05) {
1105 printf(_("Warning: need lyxformat %.2f but found %.2f\n"),
1106 LYX_FORMAT, format);
1108 if (format - LYX_FORMAT > 0.05) {
1109 printf(_("ERROR: need lyxformat %.2f but found %.2f\n"),
1110 LYX_FORMAT, format);
1112 bool the_end = readLyXformat2(lex, par);
1113 // Formats >= 2.13 support "\the_end" marker
1120 WriteAlert(_("Warning!"),
1121 _("Reading of document is not complete"),
1122 _("Maybe the document is truncated"));
1123 // We simulate a safe reading anyways to allow
1124 // users to take the chance... (Asger)
1128 WriteAlert(_("ERROR!"),
1129 _("Old LyX file format found. "
1130 "Use LyX 0.10.x to read this!"));
1134 } else { // "\\lyxformat" not found
1135 WriteAlert(_("ERROR!"), _("Not a LyX file!"));
1138 WriteAlert(_("ERROR!"), _("Unable to read file!"));
1144 // Should probably be moved to somewhere else: BufferView? LyXView?
1145 bool Buffer::save() const
1147 // We don't need autosaves in the immediate future. (Asger)
1148 resetAutosaveTimers();
1152 if (lyxrc.make_backup) {
1153 s = fileName() + '~';
1154 if (!lyxrc.backupdir_path.empty())
1155 s = AddName(lyxrc.backupdir_path,
1156 subst(CleanupPath(s),'/','!'));
1158 // Rename is the wrong way of making a backup,
1159 // this is the correct way.
1160 /* truss cp fil fil2:
1161 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
1162 stat("LyXVC.lyx", 0xEFFFF688) = 0
1163 open("LyXVC.lyx", O_RDONLY) = 3
1164 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
1165 fstat(4, 0xEFFFF508) = 0
1166 fstat(3, 0xEFFFF508) = 0
1167 read(3, " # T h i s f i l e w".., 8192) = 5579
1168 write(4, " # T h i s f i l e w".., 5579) = 5579
1169 read(3, 0xEFFFD4A0, 8192) = 0
1172 chmod("LyXVC3.lyx", 0100644) = 0
1173 lseek(0, 0, SEEK_CUR) = 46440
1177 // Should proabaly have some more error checking here.
1178 // Should be cleaned up in 0.13, at least a bit.
1179 // Doing it this way, also makes the inodes stay the same.
1180 // This is still not a very good solution, in particular we
1181 // might loose the owner of the backup.
1182 FileInfo finfo(fileName());
1183 if (finfo.exist()) {
1184 mode_t fmode = finfo.getMode();
1185 struct utimbuf times = {
1186 finfo.getAccessTime(),
1187 finfo.getModificationTime() };
1189 ifstream ifs(fileName().c_str());
1190 ofstream ofs(s.c_str(), ios::out|ios::trunc);
1195 ::chmod(s.c_str(), fmode);
1197 if (::utime(s.c_str(), ×)) {
1198 lyxerr << "utime error." << endl;
1201 lyxerr << "LyX was not able to make "
1202 "backupcopy. Beware." << endl;
1207 if (writeFile(fileName(), false)) {
1210 // now delete the autosavefile
1211 string a = OnlyPath(fileName());
1213 a += OnlyFilename(fileName());
1215 FileInfo fileinfo(a);
1216 if (fileinfo.exist()) {
1217 if (::remove(a.c_str()) != 0) {
1218 WriteFSAlert(_("Could not delete "
1219 "auto-save file!"), a);
1223 // Saving failed, so backup is not backup
1224 if (lyxrc.make_backup) {
1225 ::rename(s.c_str(), fileName().c_str());
1233 // Returns false if unsuccesful
1234 bool Buffer::writeFile(string const & fname, bool flag) const
1236 // if flag is false writeFile will not create any GUI
1237 // warnings, only cerr.
1238 // Needed for autosave in background or panic save (Matthias 120496)
1240 if (read_only && (fname == filename)) {
1241 // Here we should come with a question if we should
1242 // perform the write anyway.
1244 lyxerr << _("Error! Document is read-only: ")
1247 WriteAlert(_("Error! Document is read-only: "),
1252 FileInfo finfo(fname);
1253 if (finfo.exist() && !finfo.writable()) {
1254 // Here we should come with a question if we should
1255 // try to do the save anyway. (i.e. do a chmod first)
1257 lyxerr << _("Error! Cannot write file: ")
1260 WriteFSAlert(_("Error! Cannot write file: "),
1265 ofstream ofs(fname.c_str());
1268 lyxerr << _("Error! Cannot open file: ")
1271 WriteFSAlert(_("Error! Cannot open file: "),
1275 // The top of the file should not be written by params.
1277 // write out a comment in the top of the file
1278 ofs << '#' << LYX_DOCVERSION
1279 << " created this file. For more info see http://www.lyx.org/\n";
1280 ofs.setf(ios::showpoint|ios::fixed);
1282 ofs << "\\lyxformat " << setw(4) << LYX_FORMAT << "\n";
1284 // now write out the buffer paramters.
1285 params.writeFile(ofs);
1287 char footnoteflag = 0;
1290 // this will write out all the paragraphs
1291 // using recursive descent.
1292 paragraph->writeFile(ofs, params, footnoteflag, depth);
1294 // Write marker that shows file is complete
1295 ofs << "\n\\the_end" << endl;
1297 // how to check if close went ok?
1302 void Buffer::writeFileAscii(string const & fname, int linelen)
1304 LyXFont font1, font2;
1306 char c, footnoteflag = 0, depth = 0;
1308 LyXParagraph::size_type i;
1309 int j, h, ltype = 0, ltype_depth = 0,
1310 * clen = 0, actcell = 0, actpos = 0, cell = 0, cells = 0,
1313 bool ref_printed = false;
1315 ofstream ofs(fname.c_str());
1317 WriteFSAlert(_("Error: Cannot write file:"), fname);
1321 string fname1 = TmpFileName();
1322 LyXParagraph * par = paragraph;
1326 if (par->footnoteflag != LyXParagraph::NO_FOOTNOTE ||
1328 par->previous->footnoteflag == LyXParagraph::NO_FOOTNOTE){
1330 /* begins a footnote environment ? */
1331 if (footnoteflag != par->footnoteflag) {
1332 footnoteflag = par->footnoteflag;
1334 j = strlen(string_footnotekinds[par->footnotekind])+4;
1335 if (currlinelen + j > linelen)
1338 << string_footnotekinds[par->footnotekind] << "] ";
1343 /* begins or ends a deeper area ?*/
1344 if (depth != par->depth) {
1345 if (par->depth > depth) {
1346 while (par->depth > depth) {
1351 while (par->depth < depth) {
1357 /* First write the layout */
1358 tmp = textclasslist.NameOfLayout(params.textclass, par->layout);
1359 if (tmp == "Itemize") {
1361 ltype_depth = depth+1;
1362 } else if (tmp == "Enumerate") {
1364 ltype_depth = depth+1;
1365 } else if (strstr(tmp.c_str(), "ection")) {
1367 ltype_depth = depth+1;
1368 } else if (strstr(tmp.c_str(), "aragraph")) {
1370 ltype_depth = depth+1;
1371 } else if (tmp == "Description") {
1373 ltype_depth = depth+1;
1374 } else if (tmp == "Abstract") {
1377 } else if (tmp == "Bibliography") {
1385 /* maybe some vertical spaces */
1387 /* the labelwidthstring used in lists */
1391 /* some pagebreaks? */
1395 /* what about the alignment */
1398 /* dummy layout, that means a footnote ended */
1399 footnoteflag = LyXParagraph::NO_FOOTNOTE;
1404 LyXLayout const & layout =
1405 textclasslist.Style(params.textclass,
1407 bool free_spc = layout.free_spacing;
1409 /* It might be a table */
1412 if (!lyxrc.ascii_roff_command.empty() &&
1413 lyxrc.ascii_roff_command != "none") {
1414 RoffAsciiTable(ofs, par);
1421 cells = par->table->columns;
1422 clen = new int [cells];
1423 memset(clen, 0, sizeof(int) * cells);
1425 for (i = 0, j = 0, h = 1; i < par->size(); ++i, ++h) {
1426 c = par->GetChar(i);
1427 if (c == LyXParagraph::META_INSET) {
1428 if ((inset = par->GetInset(i))) {
1431 std::ostringstream ost;
1432 inset->Latex(ost, -1, free_spc);
1433 h += ost.str().length();
1436 inset->Latex(ost, -1, free_spc);
1438 char * tmp = ost.str();
1444 ofstream fs(fname1.c_str());
1446 WriteFSAlert(_("Error: Cannot open temporary file:"), fname1);
1449 inset->Latex(fs, -1, free_spc);
1450 h += fs.tellp() - 1;
1451 ::remove(fname1.c_str());
1454 } else if (c == LyXParagraph::META_NEWLINE) {
1458 j = (++j) % par->table->NumberOfCellsInRow(actcell);
1466 font1 = LyXFont(LyXFont::ALL_INHERIT,params.language_info);
1468 for (i = 0, actpos = 1; i < par->size(); ++i, ++actpos) {
1469 if (!i && !footnoteflag && !noparbreak){
1471 for(j = 0; j < depth; ++j)
1473 currlinelen = depth * 2;
1475 case 0: /* Standard */
1476 case 4: /* (Sub)Paragraph */
1477 case 5: /* Description */
1479 case 6: /* Abstract */
1480 ofs << "Abstract\n\n";
1482 case 7: /* Bibliography */
1484 ofs << "References\n\n";
1489 ofs << par->labelstring << " ";
1492 if (ltype_depth > depth) {
1493 for(j = ltype_depth - 1; j > depth; --j)
1495 currlinelen += (ltype_depth-depth)*2;
1498 for(j = 0; j < cells; ++j) {
1500 for(h = 0; h < (clen[j] + 1);
1505 for(j = 0; j < depth; ++j)
1507 currlinelen = depth * 2;
1508 if (ltype_depth > depth) {
1509 for(j = ltype_depth;
1512 currlinelen += (ltype_depth-depth)*2;
1517 font2 = par->GetFontSettings(i);
1518 if (font1.latex() != font2.latex()) {
1519 if (font2.latex() == LyXFont::OFF)
1527 c = par->GetChar(i);
1531 case LyXParagraph::META_INSET:
1532 if ((inset = par->GetInset(i))) {
1534 inset->Latex(ofs, -1, free_spc);
1535 currlinelen += (ofs.tellp() - fpos);
1536 actpos += (ofs.tellp() - fpos) - 1;
1539 case LyXParagraph::META_NEWLINE:
1541 if (par->table->NumberOfCellsInRow(actcell) <= cell) {
1542 for(j = actpos; j < clen[cell - 1]; ++j)
1545 for(j = 0; j < depth; ++j)
1547 currlinelen = depth*2;
1548 if (ltype_depth > depth) {
1549 for(j = ltype_depth; j > depth; --j)
1551 currlinelen += (ltype_depth-depth) * 2;
1553 for(j = 0; j < cells; ++j) {
1555 for(h = 0; h < (clen[j] + 1); ++h)
1559 for(j = 0; j < depth; ++j)
1561 currlinelen = depth * 2;
1562 if (ltype_depth > depth) {
1563 for(j = ltype_depth;
1566 currlinelen += (ltype_depth-depth)*2;
1572 j < clen[cell - 1]; ++j)
1578 currlinelen = actpos = 0;
1581 for(j = 0; j < depth; ++j)
1583 currlinelen = depth * 2;
1584 if (ltype_depth > depth) {
1585 for(j = ltype_depth;
1588 currlinelen += (ltype_depth - depth) * 2;
1592 case LyXParagraph::META_HFILL:
1596 case LyXParagraph::META_PROTECTED_SEPARATOR:
1604 if (currlinelen > linelen - 10
1605 && c == ' ' && i + 2 < par->size()) {
1607 for(j = 0; j < depth; ++j)
1609 currlinelen = depth * 2;
1610 if (ltype_depth > depth) {
1611 for(j = ltype_depth;
1614 currlinelen += (ltype_depth-depth)*2;
1616 } else if (c != '\0')
1619 lyxerr.debug() << "writeAsciiFile: NULL char in structure." << endl;
1625 for(j = actpos; j < clen[cell - 1]; ++j)
1628 for(j = 0; j < depth; ++j)
1630 currlinelen = depth * 2;
1631 if (ltype_depth > depth) {
1632 for(j = ltype_depth; j > depth; --j)
1634 currlinelen += (ltype_depth - depth) * 2;
1636 for(j = 0; j < cells; ++j) {
1638 for(h = 0; h < (clen[j] + 1); ++h)
1651 void Buffer::makeLaTeXFile(string const & fname,
1652 string const & original_path,
1653 bool nice, bool only_body)
1655 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
1657 niceFile = nice; // this will be used by Insetincludes.
1659 tex_code_break_column = lyxrc.ascii_linelen;
1661 LyXTextClass const & tclass =
1662 textclasslist.TextClass(params.textclass);
1664 ofstream ofs(fname.c_str());
1666 WriteFSAlert(_("Error: Cannot open file: "), fname);
1670 // validate the buffer.
1671 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
1672 LaTeXFeatures features(params, tclass.numLayouts());
1674 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
1677 // The starting paragraph of the coming rows is the
1678 // first paragraph of the document. (Asger)
1679 texrow.start(paragraph, 0);
1681 if (!only_body && nice) {
1682 ofs << "%% " LYX_DOCVERSION " created this file. "
1683 "For more info, see http://www.lyx.org/.\n"
1684 "%% Do not edit unless you really know what "
1689 lyxerr.debug() << "lyx header finished" << endl;
1690 // There are a few differences between nice LaTeX and usual files:
1691 // usual is \batchmode and has a
1692 // special input@path to allow the including of figures
1693 // with either \input or \includegraphics (what figinsets do).
1694 // batchmode is not set if there is a tex_code_break_column.
1695 // In this case somebody is interested in the generated LaTeX,
1696 // so this is OK. input@path is set when the actual parameter
1697 // original_path is set. This is done for usual tex-file, but not
1698 // for nice-latex-file. (Matthias 250696)
1701 // code for usual, NOT nice-latex-file
1702 ofs << "\\batchmode\n"; // changed
1703 // from \nonstopmode
1706 if (!original_path.empty()) {
1707 ofs << "\\makeatletter\n"
1708 << "\\def\\input@path{{"
1709 << original_path << "/}}\n"
1710 << "\\makeatother\n";
1716 ofs << "\\documentclass";
1718 string options; // the document class options.
1720 if (tokenPos(tclass.opt_fontsize(), '|', params.fontsize) >= 0) {
1721 // only write if existing in list (and not default)
1722 options += params.fontsize;
1727 if (!params.use_geometry &&
1728 (params.paperpackage == BufferParams::PACKAGE_NONE)) {
1729 switch (params.papersize) {
1730 case BufferParams::PAPER_A4PAPER:
1731 options += "a4paper,";
1733 case BufferParams::PAPER_USLETTER:
1734 options += "letterpaper,";
1736 case BufferParams::PAPER_A5PAPER:
1737 options += "a5paper,";
1739 case BufferParams::PAPER_B5PAPER:
1740 options += "b5paper,";
1742 case BufferParams::PAPER_EXECUTIVEPAPER:
1743 options += "executivepaper,";
1745 case BufferParams::PAPER_LEGALPAPER:
1746 options += "legalpaper,";
1752 if (params.sides != tclass.sides()) {
1753 switch (params.sides) {
1754 case LyXTextClass::OneSide:
1755 options += "oneside,";
1757 case LyXTextClass::TwoSides:
1758 options += "twoside,";
1765 if (params.columns != tclass.columns()) {
1766 if (params.columns == 2)
1767 options += "twocolumn,";
1769 options += "onecolumn,";
1772 if (!params.use_geometry
1773 && params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1774 options += "landscape,";
1776 // language should be a parameter to \documentclass
1777 bool use_babel = false;
1778 if (params.language != "default" ||
1779 !features.UsedLanguages.empty() ) {
1781 for (LaTeXFeatures::LanguageList::const_iterator cit =
1782 features.UsedLanguages.begin();
1783 cit != features.UsedLanguages.end(); ++cit) {
1784 options += (*cit)->lang + ",";
1786 if (default_language != params.language_info)
1787 options += default_language ->lang + ',';
1788 options += params.language_info->lang + ',';
1791 // the user-defined options
1792 if (!params.options.empty()) {
1793 options += params.options + ',';
1796 if (!options.empty()){
1797 options = strip(options, ',');
1798 ofs << '[' << options << ']';
1802 << textclasslist.LatexnameOfClass(params.textclass)
1805 // end of \documentclass defs
1807 // font selection must be done before loading fontenc.sty
1808 if (params.fonts != "default") {
1809 ofs << "\\usepackage{" << params.fonts << "}\n";
1812 // this one is not per buffer
1813 if (lyxrc.fontenc != "default") {
1814 ofs << "\\usepackage[" << lyxrc.fontenc
1818 if (params.inputenc != "default") {
1819 ofs << "\\usepackage[" << params.inputenc
1824 /* at the very beginning the text parameters */
1825 if (params.paperpackage != BufferParams::PACKAGE_NONE) {
1826 switch (params.paperpackage) {
1827 case BufferParams::PACKAGE_A4:
1828 ofs << "\\usepackage{a4}\n";
1831 case BufferParams::PACKAGE_A4WIDE:
1832 ofs << "\\usepackage{a4wide}\n";
1835 case BufferParams::PACKAGE_WIDEMARGINSA4:
1836 ofs << "\\usepackage[widemargins]{a4}\n";
1841 if (params.use_geometry) {
1842 ofs << "\\usepackage{geometry}\n";
1844 ofs << "\\geometry{verbose";
1845 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1846 ofs << ",landscape";
1847 switch (params.papersize2) {
1848 case BufferParams::VM_PAPER_CUSTOM:
1849 if (!params.paperwidth.empty())
1850 ofs << ",paperwidth="
1851 << params.paperwidth;
1852 if (!params.paperheight.empty())
1853 ofs << ",paperheight="
1854 << params.paperheight;
1856 case BufferParams::VM_PAPER_USLETTER:
1857 ofs << ",letterpaper";
1859 case BufferParams::VM_PAPER_USLEGAL:
1860 ofs << ",legalpaper";
1862 case BufferParams::VM_PAPER_USEXECUTIVE:
1863 ofs << ",executivepaper";
1865 case BufferParams::VM_PAPER_A3:
1868 case BufferParams::VM_PAPER_A4:
1871 case BufferParams::VM_PAPER_A5:
1874 case BufferParams::VM_PAPER_B3:
1877 case BufferParams::VM_PAPER_B4:
1880 case BufferParams::VM_PAPER_B5:
1884 // default papersize ie BufferParams::VM_PAPER_DEFAULT
1885 switch (lyxrc.default_papersize) {
1886 case BufferParams::PAPER_DEFAULT: // keep compiler happy
1887 case BufferParams::PAPER_USLETTER:
1888 ofs << ",letterpaper";
1890 case BufferParams::PAPER_LEGALPAPER:
1891 ofs << ",legalpaper";
1893 case BufferParams::PAPER_EXECUTIVEPAPER:
1894 ofs << ",executivepaper";
1896 case BufferParams::PAPER_A3PAPER:
1899 case BufferParams::PAPER_A4PAPER:
1902 case BufferParams::PAPER_A5PAPER:
1905 case BufferParams::PAPER_B5PAPER:
1910 if (!params.topmargin.empty())
1911 ofs << ",tmargin=" << params.topmargin;
1912 if (!params.bottommargin.empty())
1913 ofs << ",bmargin=" << params.bottommargin;
1914 if (!params.leftmargin.empty())
1915 ofs << ",lmargin=" << params.leftmargin;
1916 if (!params.rightmargin.empty())
1917 ofs << ",rmargin=" << params.rightmargin;
1918 if (!params.headheight.empty())
1919 ofs << ",headheight=" << params.headheight;
1920 if (!params.headsep.empty())
1921 ofs << ",headsep=" << params.headsep;
1922 if (!params.footskip.empty())
1923 ofs << ",footskip=" << params.footskip;
1927 if (params.use_amsmath
1928 && !prefixIs(textclasslist.LatexnameOfClass(params.textclass), "ams")) {
1929 ofs << "\\usepackage{amsmath}\n";
1933 if (tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle) >= 0) {
1934 if (params.pagestyle == "fancy") {
1935 ofs << "\\usepackage{fancyhdr}\n";
1938 ofs << "\\pagestyle{" << params.pagestyle << "}\n";
1942 // We try to load babel late, in case it interferes
1943 // with other packages.
1945 ofs << lyxrc.language_package << endl;
1949 if (params.secnumdepth != tclass.secnumdepth()) {
1950 ofs << "\\setcounter{secnumdepth}{"
1951 << params.secnumdepth
1955 if (params.tocdepth != tclass.tocdepth()) {
1956 ofs << "\\setcounter{tocdepth}{"
1962 if (params.paragraph_separation) {
1963 switch (params.defskip.kind()) {
1964 case VSpace::SMALLSKIP:
1965 ofs << "\\setlength\\parskip{\\smallskipamount}\n";
1967 case VSpace::MEDSKIP:
1968 ofs << "\\setlength\\parskip{\\medskipamount}\n";
1970 case VSpace::BIGSKIP:
1971 ofs << "\\setlength\\parskip{\\bigskipamount}\n";
1973 case VSpace::LENGTH:
1974 ofs << "\\setlength\\parskip{"
1975 << params.defskip.length().asLatexString()
1978 default: // should never happen // Then delete it.
1979 ofs << "\\setlength\\parskip{\\medskipamount}\n";
1984 ofs << "\\setlength\\parindent{0pt}\n";
1988 // Now insert the LyX specific LaTeX commands...
1989 string preamble, tmppreamble;
1991 // The optional packages;
1992 preamble = features.getPackages();
1994 // this might be useful...
1995 preamble += "\n\\makeatletter\n\n";
1997 // Some macros LyX will need
1998 tmppreamble = features.getMacros();
2000 if (!tmppreamble.empty()) {
2001 preamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2002 "LyX specific LaTeX commands.\n"
2003 + tmppreamble + '\n';
2006 // the text class specific preamble
2007 tmppreamble = features.getTClassPreamble();
2008 if (!tmppreamble.empty()) {
2009 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2010 "Textclass specific LaTeX commands.\n"
2011 + tmppreamble + '\n';
2014 /* the user-defined preamble */
2015 if (!params.preamble.empty()) {
2016 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2017 "User specified LaTeX commands.\n"
2018 + params.preamble + '\n';
2021 preamble += "\\makeatother\n\n";
2023 // Itemize bullet settings need to be last in case the user
2024 // defines their own bullets that use a package included
2025 // in the user-defined preamble -- ARRae
2026 // Actually it has to be done much later than that
2027 // since some packages like frenchb make modifications
2028 // at \begin{document} time -- JMarc
2030 for (int i = 0; i < 4; ++i) {
2031 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
2032 if (bullets_def.empty())
2033 bullets_def="\\AtBeginDocument{\n";
2034 bullets_def += " \\renewcommand{\\labelitemi";
2036 // `i' is one less than the item to modify
2043 bullets_def += "ii";
2049 bullets_def += "}{" +
2050 params.user_defined_bullets[i].getText()
2055 if (!bullets_def.empty())
2056 preamble += bullets_def + "}\n\n";
2058 for (int j = countChar(preamble, '\n'); j-- ;) {
2065 ofs << "\\begin{document}\n\n";
2069 lyxerr.debug() << "preamble finished, now the body." << endl;
2070 if (!lyxrc.language_auto_begin && params.language != "default") {
2071 ofs << subst(lyxrc.language_command_begin, "$$lang",
2077 bool was_title = false;
2078 bool already_title = false;
2080 std::ostringstream ftnote;
2082 char * tmpholder = 0;
2087 LyXParagraph * par = paragraph;
2091 #ifndef HAVE_SSTREAM
2094 ftnote << tmpholder;
2095 delete [] tmpholder;
2100 lyxerr[Debug::LATEX] << "Error in MakeLateXFile."
2102 LyXLayout const & layout =
2103 textclasslist.Style(params.textclass,
2106 if (layout.intitle) {
2107 if (already_title) {
2108 lyxerr <<"Error in MakeLatexFile: You"
2109 " should not mix title layouts"
2110 " with normal ones." << endl;
2113 } else if (was_title && !already_title) {
2114 ofs << "\\maketitle\n";
2116 already_title = true;
2119 // We are at depth 0 so we can just use
2120 // ordinary \footnote{} generation
2121 // flag this with ftcount
2123 if (layout.isEnvironment()
2124 || par->pextra_type != LyXParagraph::PEXTRA_NONE) {
2125 par = par->TeXEnvironment(ofs, texrow,
2126 ftnote, ft_texrow, ftcount);
2128 par = par->TeXOnePar(ofs, texrow,
2129 ftnote, ft_texrow, ftcount);
2132 // Write out what we've generated...
2135 ofs << "\\addtocounter{footnote}{-"
2139 ofs << ftnote.str();
2140 texrow += ft_texrow;
2142 // The extra .c_str() is needed when we use
2143 // lyxstring instead of the STL string class.
2144 ftnote.str(string().c_str());
2146 delete [] ftnote.str();
2151 #ifndef HAVE_SSTREAM
2153 // I hate strstreams
2154 tmpholder = ftnote.str();
2158 #ifndef HAVE_SSTREAM
2159 delete [] tmpholder;
2161 // It might be that we only have a title in this document
2162 if (was_title && !already_title) {
2163 ofs << "\\maketitle\n";
2167 if (!lyxrc.language_auto_end && params.language != "default") {
2168 ofs << subst(lyxrc.language_command_end, "$$lang",
2175 ofs << "\\end{document}\n";
2178 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
2180 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
2184 // Just to be sure. (Asger)
2187 // tex_code_break_column's value is used to decide
2188 // if we are in batchmode or not (within mathed_write()
2189 // in math_write.C) so we must set it to a non-zero
2190 // value when we leave otherwise we save incorrect .lyx files.
2191 tex_code_break_column = lyxrc.ascii_linelen;
2195 lyxerr << "File was not closed properly." << endl;
2198 lyxerr.debug() << "Finished making latex file." << endl;
2202 bool Buffer::isLatex() const
2204 return textclasslist.TextClass(params.textclass).outputType() == LATEX;
2208 bool Buffer::isLinuxDoc() const
2210 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC;
2214 bool Buffer::isLiterate() const
2216 return textclasslist.TextClass(params.textclass).outputType() == LITERATE;
2220 bool Buffer::isDocBook() const
2222 return textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2226 bool Buffer::isSGML() const
2228 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC ||
2229 textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2233 void Buffer::sgmlOpenTag(ostream & os, int depth,
2234 string const & latexname) const
2236 os << string(depth, ' ') << "<" << latexname << ">\n";
2240 void Buffer::sgmlCloseTag(ostream & os, int depth,
2241 string const & latexname) const
2243 os << string(depth, ' ') << "</" << latexname << ">\n";
2247 void Buffer::makeLinuxDocFile(string const & fname, int column)
2249 LyXParagraph * par = paragraph;
2251 string top_element = textclasslist.LatexnameOfClass(params.textclass);
2252 string environment_stack[10];
2255 int depth = 0; /* paragraph depth */
2257 ofstream ofs(fname.c_str());
2260 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2264 tex_code_break_column = column;
2267 if (params.preamble.empty()) {
2268 ofs << "<!doctype linuxdoc system>\n\n";
2271 ofs << "<!doctype linuxdoc system \n [ "
2272 << params.preamble << " \n]>\n\n";
2275 ofs << "<!-- " << LYX_DOCVERSION
2276 << " created this file. For more info see http://www.lyx.org/"
2279 if(params.options.empty())
2280 sgmlOpenTag(ofs, 0, top_element);
2282 string top = top_element;
2284 top += params.options;
2285 sgmlOpenTag(ofs, 0, top);
2289 int desc_on = 0; /* description mode*/
2290 LyXLayout const & style =
2291 textclasslist.Style(users->buffer()->params.textclass,
2293 par->AutoDeleteInsets();
2295 /* treat <toc> as a special case for compatibility with old code */
2296 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2297 Inset * inset = par->GetInset(0);
2298 char lyx_code = inset->LyxCode();
2299 if (lyx_code == Inset::TOC_CODE){
2300 string temp = "toc";
2301 sgmlOpenTag(ofs, depth, temp);
2304 linuxDocHandleFootnote(ofs, par, depth);
2309 // environment tag closing
2310 for( ; depth > par->depth; --depth) {
2311 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2312 environment_stack[depth].clear();
2315 // write opening SGML tags
2316 switch(style.latextype) {
2317 case LATEX_PARAGRAPH:
2318 if(depth == par->depth
2319 && !environment_stack[depth].empty()) {
2320 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2321 environment_stack[depth].clear();
2327 sgmlOpenTag(ofs, depth, style.latexname());
2332 LinuxDocError(par, 0, _("Error : Wrong depth for LatexType Command.\n"));
2334 if (!environment_stack[depth].empty()){
2335 sgmlCloseTag(ofs, depth,
2336 environment_stack[depth]);
2340 environment_stack[depth].clear();
2341 sgmlOpenTag(ofs, depth, style.latexname());
2344 case LATEX_ENVIRONMENT:
2345 case LATEX_ITEM_ENVIRONMENT:
2346 if(depth == par->depth
2347 && environment_stack[depth] != style.latexname()
2348 && !environment_stack[depth].empty()) {
2350 sgmlCloseTag(ofs, depth,
2351 environment_stack[depth]);
2352 environment_stack[depth].clear();
2354 if (depth < par->depth) {
2356 environment_stack[depth].clear();
2358 if (environment_stack[depth] != style.latexname()) {
2361 sgmlOpenTag(ofs, depth, temp);
2363 environment_stack[depth] = style.latexname();
2364 sgmlOpenTag(ofs, depth, environment_stack[depth]);
2366 if(style.latextype == LATEX_ENVIRONMENT) break;
2368 desc_on = (style.labeltype == LABEL_MANUAL);
2375 sgmlOpenTag(ofs, depth + 1, item_name);
2378 sgmlOpenTag(ofs, depth, style.latexname());
2383 SimpleLinuxDocOnePar(ofs, par, desc_on, depth);
2386 linuxDocHandleFootnote(ofs, par, depth);
2388 while(par && par->IsDummy());
2391 /* write closing SGML tags */
2392 switch(style.latextype) {
2394 case LATEX_ENVIRONMENT:
2395 case LATEX_ITEM_ENVIRONMENT:
2398 sgmlCloseTag(ofs, depth, style.latexname());
2403 /* Close open tags */
2404 for(; depth > 0; --depth)
2405 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2407 if(!environment_stack[depth].empty())
2408 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2411 sgmlCloseTag(ofs, 0, top_element);
2414 // How to check for successful close
2418 void Buffer::linuxDocHandleFootnote(ostream & os, LyXParagraph * & par,
2421 string tag = "footnote";
2423 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2424 sgmlOpenTag(os, depth + 1, tag);
2425 SimpleLinuxDocOnePar(os, par, 0, depth + 1);
2426 sgmlCloseTag(os, depth + 1, tag);
2432 void Buffer::DocBookHandleCaption(ostream & os, string & inner_tag,
2433 int const depth, int desc_on,
2434 LyXParagraph * & par)
2436 LyXParagraph * tpar = par;
2437 while (tpar && (tpar->footnoteflag != LyXParagraph::NO_FOOTNOTE) &&
2438 (tpar->layout != textclasslist.NumberOfLayout(params.textclass,
2442 tpar->layout == textclasslist.NumberOfLayout(params.textclass,
2443 "Caption").second) {
2444 sgmlOpenTag(os, depth + 1, inner_tag);
2446 SimpleDocBookOnePar(os, extra_par, tpar,
2447 desc_on, depth + 2);
2448 sgmlCloseTag(os, depth+1, inner_tag);
2449 if(!extra_par.empty())
2455 void Buffer::DocBookHandleFootnote(ostream & os, LyXParagraph * & par,
2458 string tag, inner_tag;
2459 string tmp_par, extra_par;
2460 bool inner_span = false;
2463 // Someone should give this enum a proper name (Lgb)
2471 SOME_ENUM last = NO_ONE;
2472 SOME_ENUM present = FOOTNOTE_LIKE;
2474 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2475 if(last == present) {
2477 if(!tmp_par.empty()) {
2480 sgmlCloseTag(os, depth + 1, inner_tag);
2481 sgmlOpenTag(os, depth + 1, inner_tag);
2488 if(!inner_tag.empty()) sgmlCloseTag(os, depth + 1,
2490 if(!extra_par.empty()) os << extra_par;
2491 if(!tag.empty()) sgmlCloseTag(os, depth, tag);
2494 switch (par->footnotekind) {
2495 case LyXParagraph::FOOTNOTE:
2496 case LyXParagraph::ALGORITHM:
2499 present = FOOTNOTE_LIKE;
2502 case LyXParagraph::MARGIN:
2505 present = MARGIN_LIKE;
2508 case LyXParagraph::FIG:
2509 case LyXParagraph::WIDE_FIG:
2511 inner_tag = "title";
2515 case LyXParagraph::TAB:
2516 case LyXParagraph::WIDE_TAB:
2518 inner_tag = "title";
2523 sgmlOpenTag(os, depth, tag);
2524 if ((present == TAB_LIKE) || (present == FIG_LIKE)) {
2525 DocBookHandleCaption(os, inner_tag, depth,
2529 sgmlOpenTag(os, depth + 1, inner_tag);
2532 // ignore all caption here, we processed them above!!!
2533 if (par->layout != textclasslist
2534 .NumberOfLayout(params.textclass,
2535 "Caption").second) {
2537 std::ostringstream ost;
2541 SimpleDocBookOnePar(ost, extra_par, par,
2542 desc_on, depth + 2);
2544 tmp_par += ost.str().c_str();
2547 char * ctmp = ost.str();
2552 tmp_par = frontStrip(strip(tmp_par));
2558 if(!inner_tag.empty()) sgmlCloseTag(os, depth + 1, inner_tag);
2559 if(!extra_par.empty()) os << extra_par;
2560 if(!tag.empty()) sgmlCloseTag(os, depth, tag);
2564 /* push a tag in a style stack */
2565 void Buffer::push_tag(ostream & os, char const * tag,
2566 int & pos, char stack[5][3])
2568 /* pop all previous tags */
2569 for (int j = pos; j >= 0; --j)
2570 os << "</" << stack[j] << ">";
2573 sprintf(stack[++pos], "%s", tag);
2576 for (int i = 0; i <= pos; ++i)
2577 os << "<" << stack[i] << ">";
2581 void Buffer::pop_tag(ostream & os, char const * tag,
2582 int & pos, char stack[5][3])
2586 // pop all tags till specified one
2587 for (j = pos; (j >= 0) && (strcmp(stack[j], tag)); --j)
2588 os << "</" << stack[j] << ">";
2591 os << "</" << tag << ">";
2593 // push all tags, but the specified one
2594 for (j = j + 1; j <= pos; ++j) {
2595 os << "<" << stack[j] << ">";
2596 strcpy(stack[j-1], stack[j]);
2602 /* handle internal paragraph parsing -- layout already processed */
2604 // checks, if newcol chars should be put into this line
2605 // writes newline, if necessary.
2607 void linux_doc_line_break(ostream & os, unsigned int & colcount,
2608 const unsigned int newcol)
2611 if (colcount > lyxrc.ascii_linelen) {
2613 colcount = newcol; // assume write after this call
2618 void Buffer::SimpleLinuxDocOnePar(ostream & os, LyXParagraph * par,
2619 int desc_on, int const /*depth*/)
2621 LyXFont font1, font2;
2624 LyXParagraph::size_type main_body;
2626 LyXLayout const & style = textclasslist.Style(params.textclass,
2629 char family_type = 0; // family font flag
2630 bool is_bold = false; // series font flag
2631 char shape_type = 0; // shape font flag
2632 bool is_em = false; // emphasis (italic) font flag
2634 int stack_num = -1; // style stack position
2635 char stack[5][3]; // style stack
2636 unsigned int char_line_count = 5; // Heuristic choice ;-)
2638 if (style.labeltype != LABEL_MANUAL)
2641 main_body = par->BeginningOfMainBody();
2643 /* gets paragraph main font */
2645 font1 = style.labelfont;
2650 /* parsing main loop */
2651 for (LyXParagraph::size_type i = 0;
2652 i < par->size(); ++i) {
2654 /* handle quote tag */
2655 if (i == main_body && !par->IsDummy()) {
2660 font2 = par->getFont(i);
2662 if (font1.family() != font2.family()) {
2663 switch(family_type) {
2665 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2666 push_tag(os, "tt", stack_num, stack);
2669 else if (font2.family() == LyXFont::SANS_FAMILY) {
2670 push_tag(os, "sf", stack_num, stack);
2675 pop_tag(os, "tt", stack_num, stack);
2676 if (font2.family() == LyXFont::SANS_FAMILY) {
2677 push_tag(os, "sf", stack_num, stack);
2685 pop_tag(os, "sf", stack_num, stack);
2686 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2687 push_tag(os, "tt", stack_num, stack);
2696 /* handle bold face */
2697 if (font1.series() != font2.series()) {
2698 if (font2.series() == LyXFont::BOLD_SERIES) {
2699 push_tag(os, "bf", stack_num, stack);
2703 pop_tag(os, "bf", stack_num, stack);
2708 /* handle italic and slanted fonts */
2709 if (font1.shape() != font2.shape()) {
2710 switch(shape_type) {
2712 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2713 push_tag(os, "it", stack_num, stack);
2716 else if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2717 push_tag(os, "sl", stack_num, stack);
2722 pop_tag(os, "it", stack_num, stack);
2723 if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2724 push_tag(os, "sl", stack_num, stack);
2732 pop_tag(os, "sl", stack_num, stack);
2733 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2734 push_tag(os, "it", stack_num, stack);
2742 /* handle <em> tag */
2743 if (font1.emph() != font2.emph()) {
2744 if (font2.emph() == LyXFont::ON) {
2745 push_tag(os, "em", stack_num, stack);
2748 pop_tag(os, "em", stack_num, stack);
2753 c = par->GetChar(i);
2755 if (font2.latex() == LyXFont::ON) {
2756 // "TeX"-Mode on == > SGML-Mode on.
2758 os << c; // see LaTeX-Generation...
2760 } else if (c == LyXParagraph::META_INSET) {
2761 inset = par->GetInset(i);
2762 inset->Linuxdoc(os);
2765 if (par->linuxDocConvertChar(c, sgml_string)
2766 && !style.free_spacing) { // in freespacing
2768 // non-breaking characters
2772 linux_doc_line_break(os, char_line_count, 6);
2777 linux_doc_line_break(os, char_line_count, 1);
2783 char_line_count += sgml_string.length();
2789 /* needed if there is an optional argument but no contents */
2790 if (main_body > 0 && main_body == par->size()) {
2794 /* pop all defined Styles */
2795 for (j = stack_num; j >= 0; --j) {
2796 linux_doc_line_break(os,
2798 3 + strlen(stack[j]));
2799 os << "</" << stack[j] << ">";
2802 /* resets description flag correctly */
2805 /* <tag> not closed... */
2806 linux_doc_line_break(os, char_line_count, 6);
2810 /* fprintf(file, "</p>");*/
2816 /* print an error message */
2817 void Buffer::LinuxDocError(LyXParagraph * par, int pos,
2818 char const * message)
2820 InsetError * new_inset;
2822 /* insert an error marker in text */
2823 new_inset = new InsetError(message);
2824 par->InsertChar(pos, LyXParagraph::META_INSET);
2825 par->InsertInset(pos, new_inset);
2828 // This constant defines the maximum number of
2829 // environment layouts that can be nesteded.
2830 // The same applies for command layouts.
2831 // These values should be more than enough.
2832 // José Matos (1999/07/22)
2834 enum { MAX_NEST_LEVEL = 25};
2836 void Buffer::makeDocBookFile(string const & fname, int column)
2838 LyXParagraph * par = paragraph;
2840 string top_element= textclasslist.LatexnameOfClass(params.textclass);
2841 string environment_stack[MAX_NEST_LEVEL];
2842 string environment_inner[MAX_NEST_LEVEL];
2843 string command_stack[MAX_NEST_LEVEL];
2844 bool command_flag= false;
2845 int command_depth= 0, command_base= 0, cmd_depth= 0;
2847 string item_name, command_name;
2848 string c_depth, c_params, tmps;
2850 int depth= 0; /* paragraph depth */
2852 tex_code_break_column = column;
2854 ofstream ofs(fname.c_str());
2856 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2862 ofs << "<!doctype " << top_element
2863 << " public \"-//OASIS//DTD DocBook V3.1//EN\"";
2865 if (params.preamble.empty())
2868 ofs << "\n [ " << params.preamble << " \n]>\n\n";
2870 ofs << "<!-- DocBook file was created by " << LYX_DOCVERSION
2871 << "\n See http://www.lyx.org/ for more information -->\n";
2873 if(params.options.empty())
2874 sgmlOpenTag(ofs, 0, top_element);
2876 string top = top_element;
2878 top += params.options;
2879 sgmlOpenTag(ofs, 0, top);
2883 int desc_on = 0; /* description mode*/
2884 LyXLayout const & style =
2885 textclasslist.Style(users->buffer()->params.textclass,
2887 par->AutoDeleteInsets();
2889 /* environment tag closing */
2890 for( ; depth > par->depth; --depth) {
2891 if(environment_inner[depth] != "!-- --") {
2892 item_name= "listitem";
2893 sgmlCloseTag(ofs, command_depth + depth,
2895 if( environment_inner[depth] == "varlistentry")
2896 sgmlCloseTag(ofs, depth+command_depth,
2897 environment_inner[depth]);
2899 sgmlCloseTag(ofs, depth + command_depth,
2900 environment_stack[depth]);
2901 environment_stack[depth].clear();
2902 environment_inner[depth].clear();
2905 if(depth == par->depth
2906 && environment_stack[depth] != style.latexname()
2907 && !environment_stack[depth].empty()) {
2908 if(environment_inner[depth] != "!-- --") {
2909 item_name= "listitem";
2910 sgmlCloseTag(ofs, command_depth+depth,
2912 if( environment_inner[depth] == "varlistentry")
2914 depth + command_depth,
2915 environment_inner[depth]);
2918 sgmlCloseTag(ofs, depth + command_depth,
2919 environment_stack[depth]);
2921 environment_stack[depth].clear();
2922 environment_inner[depth].clear();
2925 // Write opening SGML tags.
2926 switch(style.latextype) {
2927 case LATEX_PARAGRAPH:
2928 if(style.latexname() != "dummy")
2929 sgmlOpenTag(ofs, depth+command_depth,
2935 LinuxDocError(par, 0,
2936 _("Error : Wrong depth for "
2937 "LatexType Command.\n"));
2939 command_name = style.latexname();
2941 tmps = style.latexparam();
2942 c_params = split(tmps, c_depth,'|');
2944 cmd_depth= atoi(c_depth.c_str());
2947 if(cmd_depth<command_base) {
2948 for(int j = command_depth;
2949 j >= command_base; --j)
2950 if(!command_stack[j].empty())
2951 sgmlCloseTag(ofs, j, command_stack[j]);
2952 command_depth= command_base= cmd_depth;
2954 else if(cmd_depth <= command_depth) {
2955 for(int j = command_depth;
2956 j >= cmd_depth; --j)
2958 if(!command_stack[j].empty())
2959 sgmlCloseTag(ofs, j, command_stack[j]);
2960 command_depth= cmd_depth;
2963 command_depth= cmd_depth;
2966 command_depth = command_base = cmd_depth;
2967 command_flag = true;
2969 command_stack[command_depth]= command_name;
2971 // treat label as a special case for
2972 // more WYSIWYM handling.
2973 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2974 Inset * inset = par->GetInset(0);
2975 char lyx_code = inset->LyxCode();
2976 if (lyx_code == Inset::LABEL_CODE){
2977 command_name += " id=\"";
2978 command_name += (static_cast<InsetCommand *>(inset))->getContents();
2979 command_name += "\"";
2984 sgmlOpenTag(ofs, depth+command_depth, command_name);
2985 item_name = "title";
2986 sgmlOpenTag(ofs, depth + 1 + command_depth, item_name);
2989 case LATEX_ENVIRONMENT:
2990 case LATEX_ITEM_ENVIRONMENT:
2991 if (depth < par->depth) {
2993 environment_stack[depth].clear();
2996 if (environment_stack[depth] != style.latexname()) {
2997 environment_stack[depth] = style.latexname();
2998 environment_inner[depth] = "!-- --";
2999 sgmlOpenTag(ofs, depth + command_depth,
3000 environment_stack[depth]);
3002 if(environment_inner[depth] != "!-- --") {
3003 item_name= "listitem";
3005 command_depth + depth,
3007 if (environment_inner[depth] == "varlistentry")
3009 depth + command_depth,
3010 environment_inner[depth]);
3014 if(style.latextype == LATEX_ENVIRONMENT) {
3015 if(!style.latexparam().empty())
3016 sgmlOpenTag(ofs, depth + command_depth,
3017 style.latexparam());
3021 desc_on = (style.labeltype == LABEL_MANUAL);
3024 environment_inner[depth]= "varlistentry";
3026 environment_inner[depth]= "listitem";
3028 sgmlOpenTag(ofs, depth + 1 + command_depth,
3029 environment_inner[depth]);
3033 sgmlOpenTag(ofs, depth + 1 + command_depth,
3038 sgmlOpenTag(ofs, depth + 1 + command_depth,
3043 sgmlOpenTag(ofs, depth + command_depth,
3050 SimpleDocBookOnePar(ofs, extra_par, par, desc_on,
3051 depth + 1 + command_depth);
3053 DocBookHandleFootnote(ofs, par,
3054 depth + 1 + command_depth);
3056 while(par && par->IsDummy());
3059 /* write closing SGML tags */
3060 switch(style.latextype) {
3063 sgmlCloseTag(ofs, depth + command_depth, end_tag);
3065 case LATEX_ENVIRONMENT:
3066 if(!style.latexparam().empty())
3067 sgmlCloseTag(ofs, depth + command_depth,
3068 style.latexparam());
3070 case LATEX_ITEM_ENVIRONMENT:
3071 if(desc_on == 1) break;
3073 sgmlCloseTag(ofs, depth + 1 + command_depth, end_tag);
3075 case LATEX_PARAGRAPH:
3076 if(style.latexname() != "dummy")
3077 sgmlCloseTag(ofs, depth + command_depth,
3081 sgmlCloseTag(ofs, depth + command_depth,
3088 for(; depth >= 0; --depth) {
3089 if(!environment_stack[depth].empty()) {
3090 if(environment_inner[depth] != "!-- --") {
3091 item_name= "listitem";
3092 sgmlCloseTag(ofs, command_depth + depth,
3094 if( environment_inner[depth] == "varlistentry")
3095 sgmlCloseTag(ofs, depth + command_depth,
3096 environment_inner[depth]);
3099 sgmlCloseTag(ofs, depth + command_depth,
3100 environment_stack[depth]);
3104 for(int j = command_depth; j >= command_base; --j)
3105 if(!command_stack[j].empty())
3106 sgmlCloseTag(ofs, j, command_stack[j]);
3109 sgmlCloseTag(ofs, 0, top_element);
3112 // How to check for successful close
3116 void Buffer::SimpleDocBookOnePar(ostream & os, string & extra,
3117 LyXParagraph * par, int & desc_on,
3121 par->SimpleDocBookOneTablePar(os, extra, desc_on, depth);
3125 bool emph_flag = false;
3127 LyXLayout const & style = textclasslist.Style(params.textclass,
3130 LyXParagraph::size_type main_body;
3131 if (style.labeltype != LABEL_MANUAL)
3134 main_body = par->BeginningOfMainBody();
3136 // gets paragraph main font
3137 //if (main_body > 0)
3138 // font1 = style.labelfont;
3140 // font1 = style.font;
3141 LyXFont font1 = main_body > 0 ? style.labelfont : style.font;
3143 int char_line_count = depth;
3144 if(!style.free_spacing)
3145 for (int j = 0; j < depth; ++j)
3148 // parsing main loop
3149 for (LyXParagraph::size_type i = 0;
3150 i < par->size(); ++i) {
3151 LyXFont font2 = par->getFont(i);
3153 // handle <emphasis> tag
3154 if (font1.emph() != font2.emph() && i) {
3155 if (font2.emph() == LyXFont::ON) {
3159 os << "</emphasis>";
3164 char c = par->GetChar(i);
3166 if (c == LyXParagraph::META_INSET) {
3167 Inset * inset = par->GetInset(i);
3169 std::ostringstream ost;
3170 inset->DocBook(ost);
3171 string tmp_out = ost.str().c_str();
3174 inset->DocBook(ost);
3176 char * ctmp = ost.str();
3177 string tmp_out(ctmp);
3181 // This code needs some explanation:
3182 // Two insets are treated specially
3183 // label if it is the first element in a command paragraph
3185 // graphics inside tables or figure floats can't go on
3186 // title (the equivalente in latex for this case is caption
3187 // and title should come first
3190 if(desc_on!= 3 || i!= 0) {
3191 if(!tmp_out.empty() && tmp_out[0] == '@') {
3193 extra += frontStrip(tmp_out, '@');
3195 os << frontStrip(tmp_out, '@');
3200 } else if (font2.latex() == LyXFont::ON) {
3201 // "TeX"-Mode on ==> SGML-Mode on.
3208 if (par->linuxDocConvertChar(c, sgml_string)
3209 && !style.free_spacing) { // in freespacing
3211 // non-breaking characters
3215 os << "\n</term><listitem><para>";
3229 /* needed if there is an optional argument but no contents */
3230 if (main_body > 0 && main_body == par->size()) {
3234 os << "</emphasis>";
3237 /* resets description flag correctly */
3240 /* <term> not closed... */
3248 int Buffer::runLaTeX()
3250 if (!users->text) return 0;
3252 ProhibitInput(users);
3254 // get LaTeX-Filename
3255 string name = getLatexName();
3257 string path = OnlyPath(filename);
3259 string org_path = path;
3260 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3264 Path p(path); // path to LaTeX file
3265 users->owner()->getMiniBuffer()->Set(_("Running LaTeX..."));
3267 // Remove all error insets
3268 bool a = users->removeAutoInsets();
3270 // Always generate the LaTeX file
3271 makeLaTeXFile(name, org_path, false);
3274 // do the LaTex run(s)
3276 string latex_command = lyxrc.pdf_mode ?
3277 lyxrc.pdflatex_command : lyxrc.latex_command;
3278 LaTeX latex(latex_command, name, filepath);
3279 int res = latex.run(terr,
3280 users->owner()->getMiniBuffer()); // running latex
3282 // check return value from latex.run().
3283 if ((res & LaTeX::NO_LOGFILE)) {
3284 WriteAlert(_("LaTeX did not work!"),
3285 _("Missing log file:"), name);
3286 } else if ((res & LaTeX::ERRORS)) {
3287 users->owner()->getMiniBuffer()->Set(_("Done"));
3288 // Insert all errors as errors boxes
3289 users->insertErrors(terr);
3291 // Dvi should also be kept dirty if the latex run
3292 // ends up with errors. However it should be possible
3293 // to view a dirty dvi too.
3295 //no errors or any other things to think about so:
3296 users->owner()->getMiniBuffer()->Set(_("Done"));
3300 // if we removed error insets before we ran LaTeX or if we inserted
3301 // error insets after we ran LaTeX this must be run:
3302 if (a || (res & LaTeX::ERRORS)){
3305 users->updateScrollbar();
3309 return latex.getNumErrors();
3313 int Buffer::runLiterate()
3315 if (!users->text) return 0;
3317 ProhibitInput(users);
3319 // get LaTeX-Filename
3320 string name = getLatexName();
3321 // get Literate-Filename
3322 string lit_name = ChangeExtension (getLatexName(),
3323 lyxrc.literate_extension, true);
3325 string path = OnlyPath(filename);
3327 string org_path = path;
3328 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3332 Path p(path); // path to Literate file
3333 users->owner()->getMiniBuffer()->Set(_("Running Literate..."));
3335 // Remove all error insets
3336 bool a = users->removeAutoInsets();
3338 // generate the Literate file if necessary
3339 if (!isDviClean() || a) {
3340 makeLaTeXFile(lit_name, org_path, false);
3344 string latex_command = lyxrc.pdf_mode ?
3345 lyxrc.pdflatex_command : lyxrc.latex_command;
3346 Literate literate(latex_command, name, filepath,
3348 lyxrc.literate_command, lyxrc.literate_error_filter,
3349 lyxrc.build_command, lyxrc.build_error_filter);
3351 int res = literate.weave(terr, users->owner()->getMiniBuffer());
3353 // check return value from literate.weave().
3354 if ((res & Literate::NO_LOGFILE)) {
3355 WriteAlert(_("Literate command did not work!"),
3356 _("Missing log file:"), name);
3357 } else if ((res & Literate::ERRORS)) {
3358 users->owner()->getMiniBuffer()->Set(_("Done"));
3359 // Insert all errors as errors boxes
3360 users->insertErrors(terr);
3362 // Dvi should also be kept dirty if the latex run
3363 // ends up with errors. However it should be possible
3364 // to view a dirty dvi too.
3366 //no errors or any other things to think about so:
3367 users->owner()->getMiniBuffer()->Set(_("Done"));
3371 // if we removed error insets before we ran LaTeX or if we inserted
3372 // error insets after we ran LaTeX this must be run:
3373 if (a || (res & Literate::ERRORS)){
3376 users->updateScrollbar();
3380 return literate.getNumErrors();
3384 int Buffer::buildProgram()
3386 if (!users->text) return 0;
3388 ProhibitInput(users);
3390 // get LaTeX-Filename
3391 string name = getLatexName();
3392 // get Literate-Filename
3393 string lit_name = ChangeExtension(getLatexName(),
3394 lyxrc.literate_extension, true);
3396 string path = OnlyPath(filename);
3398 string org_path = path;
3399 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3403 Path p(path); // path to Literate file
3404 users->owner()->getMiniBuffer()->Set(_("Building Program..."));
3406 // Remove all error insets
3407 bool a = users->removeAutoInsets();
3409 // generate the LaTeX file if necessary
3410 if (!isNwClean() || a) {
3411 makeLaTeXFile(lit_name, org_path, false);
3415 string latex_command = lyxrc.pdf_mode ?
3416 lyxrc.pdflatex_command : lyxrc.latex_command;
3417 Literate literate(latex_command, name, filepath,
3419 lyxrc.literate_command, lyxrc.literate_error_filter,
3420 lyxrc.build_command, lyxrc.build_error_filter);
3422 int res = literate.build(terr, users->owner()->getMiniBuffer());
3424 // check return value from literate.build().
3425 if ((res & Literate::NO_LOGFILE)) {
3426 WriteAlert(_("Build did not work!"),
3427 _("Missing log file:"), name);
3428 } else if ((res & Literate::ERRORS)) {
3429 users->owner()->getMiniBuffer()->Set(_("Done"));
3430 // Insert all errors as errors boxes
3431 users->insertErrors(terr);
3433 // Literate files should also be kept dirty if the literate
3434 // command run ends up with errors.
3436 //no errors or any other things to think about so:
3437 users->owner()->getMiniBuffer()->Set(_("Done"));
3441 // if we removed error insets before we ran Literate/Build or if we inserted
3442 // error insets after we ran Literate/Build this must be run:
3443 if (a || (res & Literate::ERRORS)){
3446 users->updateScrollbar();
3450 return literate.getNumErrors();
3454 // This should be enabled when the Chktex class is implemented. (Asger)
3455 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
3456 // Other flags: -wall -v0 -x
3457 int Buffer::runChktex()
3459 if (!users->text) return 0;
3461 ProhibitInput(users);
3463 // get LaTeX-Filename
3464 string name = getLatexName();
3465 string path = OnlyPath(filename);
3467 string org_path = path;
3468 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3472 Path p(path); // path to LaTeX file
3473 users->owner()->getMiniBuffer()->Set(_("Running chktex..."));
3475 // Remove all error insets
3476 bool a = users->removeAutoInsets();
3478 // Generate the LaTeX file if neccessary
3479 if (!isDviClean() || a) {
3480 makeLaTeXFile(name, org_path, false);
3485 Chktex chktex(lyxrc.chktex_command, name, filepath);
3486 int res = chktex.run(terr); // run chktex
3489 WriteAlert(_("chktex did not work!"),
3490 _("Could not run with file:"), name);
3491 } else if (res > 0) {
3492 // Insert all errors as errors boxes
3493 users->insertErrors(terr);
3496 // if we removed error insets before we ran chktex or if we inserted
3497 // error insets after we ran chktex, this must be run:
3501 users->updateScrollbar();
3510 void Buffer::RoffAsciiTable(ostream & os, LyXParagraph * par)
3512 LyXFont font1(LyXFont::ALL_INHERIT,params.language_info);
3515 LyXParagraph::size_type i;
3519 string fname1 = TmpFileName(string(), "RAT1");
3520 string fname2 = TmpFileName(string(), "RAT2");
3522 ofstream ofs(fname1.c_str());
3524 WriteAlert(_("LYX_ERROR:"),
3525 _("Cannot open temporary file:"), fname1);
3528 par->table->RoffEndOfCell(ofs, -1);
3529 for (i = 0; i < par->size(); ++i) {
3530 c = par->GetChar(i);
3531 if (par->table->IsContRow(cell)) {
3532 if (c == LyXParagraph::META_NEWLINE)
3536 font2 = par->GetFontSettings(i);
3537 if (font1.latex() != font2.latex()) {
3538 if (font2.latex() != LyXFont::OFF)
3542 case LyXParagraph::META_INSET:
3543 if ((inset = par->GetInset(i))) {
3546 stringstresm ss(ios::in | ios::out);
3547 inset->Latex(ss, -1);
3559 inset->Latex(ss, -1);
3572 fstream fs(fname2.c_str(), ios::in|ios::out);
3574 WriteAlert(_("LYX_ERROR:"),
3575 _("Cannot open temporary file:"), fname2);
3577 remove(fname1.c_str());
3580 inset->Latex(fs, -1);
3594 case LyXParagraph::META_NEWLINE:
3595 if (par->table->CellHasContRow(cell)>= 0)
3596 par->RoffContTableRows(ofs, i+1, cell);
3597 par->table->RoffEndOfCell(ofs, cell);
3600 case LyXParagraph::META_HFILL:
3603 case LyXParagraph::META_PROTECTED_SEPARATOR:
3614 << "RoffAsciiTable:"
3615 " NULL char in structure." << endl;
3619 par->table->RoffEndOfCell(ofs, cell);
3621 string cmd = lyxrc.ascii_roff_command + " >" + fname2;
3622 cmd = subst(cmd, "$$FName", fname1);
3623 Systemcalls one(Systemcalls::System, cmd);
3624 if (!(lyxerr.debugging(Debug::ROFF))) {
3625 remove(fname1.c_str());
3627 ifstream ifs(fname2.c_str());
3629 WriteFSAlert(_("Error! Can't open temporary file:"), fname2);
3632 // now output the produced file
3636 WriteAlert(_("Error!"),
3637 _("Error executing *roff command on table"));
3638 // overread leading blank lines
3639 while(!ifs && (c == '\n'))
3642 for(j = 0; j < par->depth; ++j)
3644 while(!ifs && (c != '\n')) {
3649 // overread trailing blank lines
3650 while(!ifs && (c == '\n'))
3654 remove(fname2.c_str());
3659 /// changed Heinrich Bauer, 23/03/98
3660 bool Buffer::isDviClean() const
3662 if (lyxrc.use_tempdir)
3663 return dvi_clean_tmpd;
3665 return dvi_clean_orgd;
3669 /// changed Heinrich Bauer, 23/03/98
3670 void Buffer::markDviClean()
3672 if (lyxrc.use_tempdir)
3673 dvi_clean_tmpd = true;
3675 dvi_clean_orgd = true;
3679 /// changed Heinrich Bauer, 23/03/98
3680 void Buffer::markDviDirty()
3682 if (lyxrc.use_tempdir)
3683 dvi_clean_tmpd = false;
3685 dvi_clean_orgd = false;
3689 void Buffer::validate(LaTeXFeatures & features) const
3691 LyXParagraph * par = paragraph;
3692 LyXTextClass const & tclass =
3693 textclasslist.TextClass(params.textclass);
3695 // AMS Style is at document level
3697 features.amsstyle = (params.use_amsmath ||
3698 tclass.provides(LyXTextClass::amsmath));
3701 // We don't use "lyxerr.debug" because of speed. (Asger)
3702 if (lyxerr.debugging(Debug::LATEX))
3703 lyxerr << "Paragraph: " << par << endl;
3705 // Now just follow the list of paragraphs and run
3706 // validate on each of them.
3707 par->validate(features);
3709 // and then the next paragraph
3713 // the bullet shapes are buffer level not paragraph level
3714 // so they are tested here
3715 for (int i = 0; i < 4; ++i) {
3716 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
3717 int font = params.user_defined_bullets[i].getFont();
3720 .user_defined_bullets[i]
3727 features.latexsym = true;
3731 features.amssymb = true;
3733 else if ((font >= 2 && font <= 5)) {
3734 features.pifont = true;
3739 if (lyxerr.debugging(Debug::LATEX)) {
3740 features.showStruct();
3745 void Buffer::setPaperStuff()
3747 params.papersize = BufferParams::PAPER_DEFAULT;
3748 char c1 = params.paperpackage;
3749 if (c1 == BufferParams::PACKAGE_NONE) {
3750 char c2 = params.papersize2;
3751 if (c2 == BufferParams::VM_PAPER_USLETTER)
3752 params.papersize = BufferParams::PAPER_USLETTER;
3753 else if (c2 == BufferParams::VM_PAPER_USLEGAL)
3754 params.papersize = BufferParams::PAPER_LEGALPAPER;
3755 else if (c2 == BufferParams::VM_PAPER_USEXECUTIVE)
3756 params.papersize = BufferParams::PAPER_EXECUTIVEPAPER;
3757 else if (c2 == BufferParams::VM_PAPER_A3)
3758 params.papersize = BufferParams::PAPER_A3PAPER;
3759 else if (c2 == BufferParams::VM_PAPER_A4)
3760 params.papersize = BufferParams::PAPER_A4PAPER;
3761 else if (c2 == BufferParams::VM_PAPER_A5)
3762 params.papersize = BufferParams::PAPER_A5PAPER;
3763 else if ((c2 == BufferParams::VM_PAPER_B3) || (c2 == BufferParams::VM_PAPER_B4) ||
3764 (c2 == BufferParams::VM_PAPER_B5))
3765 params.papersize = BufferParams::PAPER_B5PAPER;
3766 } else if ((c1 == BufferParams::PACKAGE_A4) || (c1 == BufferParams::PACKAGE_A4WIDE) ||
3767 (c1 == BufferParams::PACKAGE_WIDEMARGINSA4))
3768 params.papersize = BufferParams::PAPER_A4PAPER;
3772 // This function should be in Buffer because it's a buffer's property (ale)
3773 string Buffer::getIncludeonlyList(char delim)
3776 LyXParagraph * par = paragraph;
3777 LyXParagraph::size_type pos;
3781 while ((inset = par->ReturnNextInsetPointer(pos))){
3782 if (inset->LyxCode() == Inset::INCLUDE_CODE) {
3783 InsetInclude * insetinc =
3784 static_cast<InsetInclude*>(inset);
3785 if (insetinc->isInclude()
3786 && insetinc->isNoLoad()) {
3789 lst += ChangeExtension(insetinc->getContents(), string(), true);
3796 lyxerr.debug() << "Includeonly(" << lst << ')' << endl;
3801 // This is also a buffer property (ale)
3802 string Buffer::getReferenceList(char delim)
3804 /// if this is a child document and the parent is already loaded
3805 /// Use the parent's list instead [ale990407]
3806 if (!params.parentname.empty()
3807 && bufferlist.exists(params.parentname)) {
3808 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3810 return tmp->getReferenceList(delim);
3813 LyXParagraph * par = paragraph;
3814 LyXParagraph::size_type pos;
3819 while ((inset = par->ReturnNextInsetPointer(pos))){
3820 for (int i = 0; i < inset->GetNumberOfLabels(); ++i) {
3823 lst += inset->getLabel(i);
3829 lyxerr.debug() << "References(" << lst << ")" << endl;
3834 // This is also a buffer property (ale)
3835 string Buffer::getBibkeyList(char delim)
3837 /// if this is a child document and the parent is already loaded
3838 /// Use the parent's list instead [ale990412]
3839 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3840 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3842 return tmp->getBibkeyList(delim);
3846 LyXParagraph * par = paragraph;
3849 if (!bibkeys.empty())
3851 bibkeys += par->bibkey->getContents();
3856 // Might be either using bibtex or a child has bibliography
3857 if (bibkeys.empty()) {
3861 LyXParagraph::size_type pos = -1;
3863 // Search for Bibtex or Include inset
3864 while ((inset = par->ReturnNextInsetPointer(pos))) {
3865 if (inset-> LyxCode() == Inset::BIBTEX_CODE) {
3866 if (!bibkeys.empty())
3868 bibkeys += static_cast<InsetBibtex*>(inset)->getKeys(delim);
3869 } else if (inset-> LyxCode() == Inset::INCLUDE_CODE) {
3870 string bk = static_cast<InsetInclude*>(inset)->getKeys(delim);
3872 if (!bibkeys.empty())
3883 lyxerr.debug() << "Bibkeys(" << bibkeys << ")" << endl;
3888 bool Buffer::isDepClean(string const & name) const
3890 DEPCLEAN * item = dep_clean;
3891 while (item && item->master != name)
3893 if (!item) return true;
3898 void Buffer::markDepClean(string const & name)
3901 dep_clean = new DEPCLEAN;
3902 dep_clean->clean = true;
3903 dep_clean->master = name;
3904 dep_clean->next = 0;
3906 DEPCLEAN* item = dep_clean;
3907 while (item && item->master != name)
3912 item = new DEPCLEAN;
3914 item->master = name;
3921 void Buffer::Dispatch(string const & command)
3923 // Split command string into command and argument
3924 string cmd, line = frontStrip(command);
3925 string arg = strip(frontStrip(split(line, cmd, ' ')));
3927 Dispatch(lyxaction.LookupFunc(cmd.c_str()), arg.c_str());
3931 void Buffer::Dispatch(int action, string const & argument)
3935 MenuExport(this, argument);
3939 lyxerr << "A truly unknown func!" << endl;
3945 void Buffer::ChangeLanguage(Language const * from, Language const * to)
3948 LyXParagraph * par = paragraph;
3950 par->ChangeLanguage(from,to);
3955 bool Buffer::isMultiLingual()
3958 LyXParagraph * par = paragraph;
3960 if (par->isMultiLingual())