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 "bufferview_funcs.h"
49 #include "minibuffer.h"
52 #include "mathed/formulamacro.h"
53 #include "insets/lyxinset.h"
54 #include "insets/inseterror.h"
55 #include "insets/insetlabel.h"
56 #include "insets/insetref.h"
57 #include "insets/inseturl.h"
58 #include "insets/insetinfo.h"
59 #include "insets/insetquotes.h"
60 #include "insets/insetlatexaccent.h"
61 #include "insets/insetbib.h"
62 #include "insets/insetindex.h"
63 #include "insets/insetinclude.h"
64 #include "insets/insettoc.h"
65 #include "insets/insetlof.h"
66 #include "insets/insetlot.h"
67 #include "insets/insetloa.h"
68 #include "insets/insetparent.h"
69 #include "insets/insetspecialchar.h"
70 #include "insets/figinset.h"
71 #include "insets/insettext.h"
72 //#include "insets/insetnumber.h"
73 #include "insets/insetert.h"
74 #include "insets/insetgraphics.h"
75 #include "insets/insetfoot.h"
76 #include "support/filetools.h"
77 #include "support/path.h"
83 #include "LaTeXFeatures.h"
84 #include "support/syscall.h"
85 #include "support/lyxlib.h"
86 #include "support/FileInfo.h"
100 // Uncomment this line to enable a workaround for the weird behaviour
101 // of the cursor between a displayed inset and last character
102 // at the upper line. (Alejandro 20.9.96)
103 // #define BREAK_BEFORE_INSET
105 /* Lars, when changing this file sometime in the future to a list,
106 * please check out the figinsets-sideeffects described at the
107 * beginning of figinset.C Matthias (04.07.1996)
111 // all these externs should eventually be removed.
112 extern BufferList bufferlist;
114 extern void MenuExport(Buffer *, string const &);
115 extern LyXAction lyxaction;
118 static const float LYX_FORMAT = 2.16;
120 extern int tex_code_break_column;
123 Buffer::Buffer(string const & file, bool ronly)
125 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
127 filepath = OnlyPath(file);
131 dvi_clean_orgd = false; // Heinrich Bauer, 23/03/98
132 dvi_clean_tmpd = false; // Heinrich Bauer, 23/03/98
137 if (read_only || (lyxrc.use_tempdir)) {
138 tmppath = CreateBufferTmpDir();
139 } else tmppath.clear();
145 lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
146 // here the buffer should take care that it is
147 // saved properly, before it goes into the void.
149 // make sure that views using this buffer
154 if (!tmppath.empty()) {
155 DestroyBufferTmpDir(tmppath);
158 LyXParagraph * par = paragraph;
159 LyXParagraph * tmppar;
169 string Buffer::getLatexName(bool no_path /* = true */) const
171 return ChangeExtension(MakeLatexName(filename),
176 void Buffer::setReadonly(bool flag /* = true */)
178 if (read_only != flag) {
181 updateAllVisibleBufferRelatedPopups();
184 WarnReadonly(filename);
189 bool Buffer::saveParamsAsDefaults()
191 string fname = AddName(AddPath(user_lyxdir, "templates/"),
193 Buffer defaults = Buffer(fname);
195 // Use the current buffer's parameters as default
196 defaults.params = params;
198 // add an empty paragraph. Is this enough?
199 defaults.paragraph = new LyXParagraph;
201 return defaults.writeFile(defaults.filename, false);
205 /// Update window titles of all users
206 // Should work on a list
207 void Buffer::updateTitles() const
209 if (users) users->owner()->updateWindowTitle();
213 /// Reset autosave timer of all users
214 // Should work on a list
215 void Buffer::resetAutosaveTimers() const
217 if (users) users->owner()->resetAutosaveTimer();
221 void Buffer::fileName(string const & newfile)
223 filename = MakeAbsPath(newfile);
224 filepath = OnlyPath(filename);
225 setReadonly(IsFileWriteable(filename) == 0);
230 // candidate for move to BufferView
231 // (at least some parts in the beginning of the func)
234 // changed to be public and have one parameter
235 // if par = 0 normal behavior
236 // else insert behavior
237 // Returns false if "\the_end" is not read for formats >= 2.13. (Asger)
238 #define USE_PARSE_FUNCTION 1
239 bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par)
243 char depth = 0; // signed or unsigned?
244 LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
245 LyXParagraph::footnote_kind footnotekind = LyXParagraph::FOOTNOTE;
246 bool the_end_read = false;
248 LyXParagraph * return_par = 0;
249 LyXFont font(LyXFont::ALL_INHERIT,params.language_info);
250 if (format < 2.16 && params.language == "hebrew")
251 font.setLanguage(default_language);
253 // If we are inserting, we cheat and get a token in advance
254 bool has_token = false;
258 par = new LyXParagraph;
260 users->text->BreakParagraph();
261 return_par = users->text->FirstParagraph();
264 // We don't want to adopt the parameters from the
265 // document we insert, so we skip until the text begins:
268 pretoken = lex.GetString();
269 if (pretoken == "\\layout") {
281 pretoken = lex.GetString();
284 // Profiling show this should give a lot: (Asger)
285 string const token = pretoken;
289 the_end_read = parseSingleLyXformat2Token(lex, par, return_par,
298 paragraph = return_par;
304 bool Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
305 LyXParagraph *& return_par,
306 string const & token, int & pos,
307 char & depth, LyXFont & font,
308 LyXParagraph::footnote_flag & footnoteflag,
309 LyXParagraph::footnote_kind & footnotekind)
314 bool the_end_read = false;
316 if (token[0] != '\\') {
317 int n = token.length();
318 for (int i = 0; i < n; ++i) {
319 par->InsertChar(pos, token[i]);
320 par->SetFont(pos, font);
323 } else if (token == "\\i") {
324 inset = new InsetLatexAccent;
326 par->InsertChar(pos, LyXParagraph::META_INSET);
327 par->InsertInset(pos, inset);
328 par->SetFont(pos, font);
330 } else if (token == "\\layout") {
335 par = new LyXParagraph(par);
339 string layoutname = lex.GetString();
340 pair<bool, LyXTextClass::LayoutList::size_type> pp
341 = textclasslist.NumberOfLayout(params.textclass,
344 par->layout = pp.second;
345 } else { // layout not found
346 // use default layout "Standard" (0)
349 // Test whether the layout is obsolete.
350 LyXLayout const & layout =
351 textclasslist.Style(params.textclass,
353 if (!layout.obsoleted_by().empty())
355 textclasslist.NumberOfLayout(params.textclass,
356 layout.obsoleted_by()).second;
357 par->footnoteflag = footnoteflag;
358 par->footnotekind = footnotekind;
360 font = LyXFont(LyXFont::ALL_INHERIT,params.language_info);
361 if (format < 2.16 && params.language == "hebrew")
362 font.setLanguage(default_language);
363 } else if (token == "\\end_float") {
368 par = new LyXParagraph(par);
370 footnotekind = LyXParagraph::FOOTNOTE;
371 footnoteflag = LyXParagraph::NO_FOOTNOTE;
374 par->layout = LYX_DUMMY_LAYOUT;
375 font = LyXFont(LyXFont::ALL_INHERIT, params.language_info);
376 if (format < 2.16 && params.language == "hebrew")
377 font.setLanguage(default_language);
378 } else if (token == "\\begin_float") {
379 tmpret = lex.FindToken(string_footnotekinds);
380 if (tmpret == -1) ++tmpret;
381 if (tmpret != LYX_LAYOUT_DEFAULT)
382 footnotekind = static_cast<LyXParagraph::footnote_kind>(tmpret); // bad
383 if (footnotekind == LyXParagraph::FOOTNOTE
384 || footnotekind == LyXParagraph::MARGIN)
385 footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
387 footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
388 } else if (token == "\\begin_deeper") {
390 } else if (token == "\\end_deeper") {
392 lex.printError("\\end_deeper: "
393 "depth is already null");
397 } else if (token == "\\begin_preamble") {
398 params.readPreamble(lex);
399 } else if (token == "\\textclass") {
401 pair<bool, LyXTextClassList::size_type> pp =
402 textclasslist.NumberOfClass(lex.GetString());
404 params.textclass = pp.second;
406 lex.printError("Unknown textclass `$$Token'");
407 params.textclass = 0;
409 if (!textclasslist.Load(params.textclass)) {
410 // if the textclass wasn't loaded properly
411 // we need to either substitute another
412 // or stop loading the file.
413 // I can substitute but I don't see how I can
414 // stop loading... ideas?? ARRae980418
415 WriteAlert(_("Textclass Loading Error!"),
416 string(_("Can't load textclass ")) +
417 textclasslist.NameOfClass(params.textclass),
418 _("-- substituting default"));
419 params.textclass = 0;
421 } else if (token == "\\options") {
423 params.options = lex.GetString();
424 } else if (token == "\\language") {
425 params.readLanguage(lex);
426 } else if (token == "\\fontencoding") {
428 } else if (token == "\\inputencoding") {
430 params.inputenc = lex.GetString();
431 } else if (token == "\\graphics") {
432 params.readGraphicsDriver(lex);
433 } else if (token == "\\fontscheme") {
435 params.fonts = lex.GetString();
436 } else if (token == "\\noindent") {
437 par->noindent = true;
438 } else if (token == "\\fill_top") {
439 par->added_space_top = VSpace(VSpace::VFILL);
440 } else if (token == "\\fill_bottom") {
441 par->added_space_bottom = VSpace(VSpace::VFILL);
442 } else if (token == "\\line_top") {
443 par->line_top = true;
444 } else if (token == "\\line_bottom") {
445 par->line_bottom = true;
446 } else if (token == "\\pagebreak_top") {
447 par->pagebreak_top = true;
448 } else if (token == "\\pagebreak_bottom") {
449 par->pagebreak_bottom = true;
450 } else if (token == "\\start_of_appendix") {
451 par->start_of_appendix = true;
452 } else if (token == "\\paragraph_separation") {
453 tmpret = lex.FindToken(string_paragraph_separation);
454 if (tmpret == -1) ++tmpret;
455 if (tmpret != LYX_LAYOUT_DEFAULT)
456 params.paragraph_separation =
457 static_cast<BufferParams::PARSEP>(tmpret);
458 } else if (token == "\\defskip") {
460 params.defskip = VSpace(lex.GetString());
462 } else if (token == "\\no_isolatin1") { // obsolete
464 } else if (token == "\\no_babel") { // obsolete
466 } else if (token == "\\no_epsfig") { // obsolete
469 } else if (token == "\\epsfig") { // obsolete
470 // Indeed it is obsolete, but we HAVE to be backwards
471 // compatible until 0.14, because otherwise all figures
472 // in existing documents are irretrivably lost. (Asger)
473 params.readGraphicsDriver(lex);
474 } else if (token == "\\quotes_language") {
475 tmpret = lex.FindToken(string_quotes_language);
476 if (tmpret == -1) ++tmpret;
477 if (tmpret != LYX_LAYOUT_DEFAULT) {
478 InsetQuotes::quote_language tmpl =
479 InsetQuotes::EnglishQ;
482 tmpl = InsetQuotes::EnglishQ;
485 tmpl = InsetQuotes::SwedishQ;
488 tmpl = InsetQuotes::GermanQ;
491 tmpl = InsetQuotes::PolishQ;
494 tmpl = InsetQuotes::FrenchQ;
497 tmpl = InsetQuotes::DanishQ;
500 params.quotes_language = tmpl;
502 } else if (token == "\\quotes_times") {
504 switch(lex.GetInteger()) {
506 params.quotes_times = InsetQuotes::SingleQ;
509 params.quotes_times = InsetQuotes::DoubleQ;
512 } else if (token == "\\papersize") {
513 tmpret = lex.FindToken(string_papersize);
517 params.papersize2 = tmpret;
518 } else if (token == "\\paperpackage") {
519 tmpret = lex.FindToken(string_paperpackages);
522 params.paperpackage = BufferParams::PACKAGE_NONE;
524 params.paperpackage = tmpret;
525 } else if (token == "\\use_geometry") {
527 params.use_geometry = lex.GetInteger();
528 } else if (token == "\\use_amsmath") {
530 params.use_amsmath = lex.GetInteger();
531 } else if (token == "\\paperorientation") {
532 tmpret = lex.FindToken(string_orientation);
533 if (tmpret == -1) ++tmpret;
534 if (tmpret != LYX_LAYOUT_DEFAULT)
535 params.orientation = static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
536 } else if (token == "\\paperwidth") {
538 params.paperwidth = lex.GetString();
539 } else if (token == "\\paperheight") {
541 params.paperheight = lex.GetString();
542 } else if (token == "\\leftmargin") {
544 params.leftmargin = lex.GetString();
545 } else if (token == "\\topmargin") {
547 params.topmargin = lex.GetString();
548 } else if (token == "\\rightmargin") {
550 params.rightmargin = lex.GetString();
551 } else if (token == "\\bottommargin") {
553 params.bottommargin = lex.GetString();
554 } else if (token == "\\headheight") {
556 params.headheight = lex.GetString();
557 } else if (token == "\\headsep") {
559 params.headsep = lex.GetString();
560 } else if (token == "\\footskip") {
562 params.footskip = lex.GetString();
563 } else if (token == "\\paperfontsize") {
565 params.fontsize = strip(lex.GetString());
566 } else if (token == "\\papercolumns") {
568 params.columns = lex.GetInteger();
569 } else if (token == "\\papersides") {
571 switch(lex.GetInteger()) {
573 case 1: params.sides = LyXTextClass::OneSide; break;
574 case 2: params.sides = LyXTextClass::TwoSides; break;
576 } else if (token == "\\paperpagestyle") {
578 params.pagestyle = strip(lex.GetString());
579 } else if (token == "\\bullet") {
581 int index = lex.GetInteger();
583 int temp_int = lex.GetInteger();
584 params.user_defined_bullets[index].setFont(temp_int);
585 params.temp_bullets[index].setFont(temp_int);
587 temp_int = lex.GetInteger();
588 params.user_defined_bullets[index].setCharacter(temp_int);
589 params.temp_bullets[index].setCharacter(temp_int);
591 temp_int = lex.GetInteger();
592 params.user_defined_bullets[index].setSize(temp_int);
593 params.temp_bullets[index].setSize(temp_int);
595 string temp_str = lex.GetString();
596 if (temp_str != "\\end_bullet") {
597 // this element isn't really necessary for
598 // parsing but is easier for humans
599 // to understand bullets. Put it back and
600 // set a debug message?
601 lex.printError("\\end_bullet expected, got" + temp_str);
602 //how can I put it back?
604 } else if (token == "\\bulletLaTeX") {
606 int index = lex.GetInteger();
608 string temp_str = lex.GetString(), sum_str;
609 while (temp_str != "\\end_bullet") {
610 // this loop structure is needed when user
611 // enters an empty string since the first
612 // thing returned will be the \\end_bullet
614 // if the LaTeX entry has spaces. Each element
615 // therefore needs to be read in turn
618 temp_str = lex.GetString();
620 params.user_defined_bullets[index].setText(sum_str);
621 params.temp_bullets[index].setText(sum_str);
622 } else if (token == "\\secnumdepth") {
624 params.secnumdepth = lex.GetInteger();
625 } else if (token == "\\tocdepth") {
627 params.tocdepth = lex.GetInteger();
628 } else if (token == "\\baselinestretch") { // obsolete
629 lex.nextToken(); // should not be used directly
631 // Will probably keep a kind of support just for
633 params.spacing.set(Spacing::Other, lex.GetFloat());
634 } else if (token == "\\spacing") {
636 string tmp = strip(lex.GetString());
637 if (tmp == "single") {
638 params.spacing.set(Spacing::Single);
639 } else if (tmp == "onehalf") {
640 params.spacing.set(Spacing::Onehalf);
641 } else if (tmp == "double") {
642 params.spacing.set(Spacing::Double);
643 } else if (tmp == "other") {
645 params.spacing.set(Spacing::Other,
648 lex.printError("Unknown spacing token: '$$Token'");
650 } else if (token == "\\paragraph_spacing") {
652 string tmp = strip(lex.GetString());
653 if (tmp == "single") {
654 par->spacing.set(Spacing::Single);
655 } else if (tmp == "onehalf") {
656 par->spacing.set(Spacing::Onehalf);
657 } else if (tmp == "double") {
658 par->spacing.set(Spacing::Double);
659 } else if (tmp == "other") {
661 par->spacing.set(Spacing::Other,
664 lex.printError("Unknown spacing token: '$$Token'");
666 } else if (token == "\\float_placement") {
668 params.float_placement = lex.GetString();
669 } else if (token == "\\cursor") { // obsolete
670 // this is obsolete, so we just skip it.
672 } else if (token == "\\family") {
674 font.setLyXFamily(lex.GetString());
675 } else if (token == "\\series") {
677 font.setLyXSeries(lex.GetString());
678 } else if (token == "\\shape") {
680 font.setLyXShape(lex.GetString());
681 } else if (token == "\\size") {
683 font.setLyXSize(lex.GetString());
684 } else if (token == "\\latex") {
686 string tok = lex.GetString();
687 // This is dirty, but gone with LyX3. (Asger)
688 if (tok == "no_latex")
689 font.setLatex(LyXFont::OFF);
690 else if (tok == "latex")
691 font.setLatex(LyXFont::ON);
692 else if (tok == "default")
693 font.setLatex(LyXFont::INHERIT);
695 lex.printError("Unknown LaTeX font flag "
697 } else if (token == "\\lang") {
699 string tok = lex.GetString();
700 Languages::iterator lit = languages.find(tok);
701 if (lit != languages.end()) {
702 font.setLanguage(&(*lit).second);
704 font.setLanguage(params.language_info);
705 lex.printError("Unknown language `$$Token'");
707 } else if (token == "\\direction") { // obsolete
709 lex.printError("Command \\direction is obsolete");
711 string tok = lex.GetString();
713 font.setLanguage(&languages["hebrew"]);
714 else if (tok == "default")
715 if (params.language == "hebrew")
716 font.setLanguage(default_language);
718 font.setLanguage(params.language_info);
720 lex.printError("Unknown direction `$$Token'");
721 } else if (token == "\\emph") {
723 font.setEmph(font.setLyXMisc(lex.GetString()));
724 } else if (token == "\\bar") {
726 string tok = lex.GetString();
727 // This is dirty, but gone with LyX3. (Asger)
729 font.setUnderbar(LyXFont::ON);
730 else if (tok == "no")
731 font.setUnderbar(LyXFont::OFF);
732 else if (tok == "default")
733 font.setUnderbar(LyXFont::INHERIT);
735 lex.printError("Unknown bar font flag "
737 } else if (token == "\\noun") {
739 font.setNoun(font.setLyXMisc(lex.GetString()));
740 } else if (token == "\\color") {
742 font.setLyXColor(lex.GetString());
743 } else if (token == "\\align") {
744 tmpret = lex.FindToken(string_align);
745 if (tmpret == -1) ++tmpret;
746 if (tmpret != LYX_LAYOUT_DEFAULT) { // tmpret != 99 ???
748 for (; tmpret > 0; --tmpret)
749 tmpret2 = tmpret2 * 2;
750 par->align = LyXAlignment(tmpret2);
752 } else if (token == "\\added_space_top") {
754 par->added_space_top = VSpace(lex.GetString());
755 } else if (token == "\\added_space_bottom") {
757 par->added_space_bottom = VSpace(lex.GetString());
758 } else if (token == "\\pextra_type") {
760 par->pextra_type = lex.GetInteger();
761 } else if (token == "\\pextra_width") {
763 par->pextra_width = lex.GetString();
764 } else if (token == "\\pextra_widthp") {
766 par->pextra_widthp = lex.GetString();
767 } else if (token == "\\pextra_alignment") {
769 par->pextra_alignment = lex.GetInteger();
770 } else if (token == "\\pextra_hfill") {
772 par->pextra_hfill = lex.GetInteger();
773 } else if (token == "\\pextra_start_minipage") {
775 par->pextra_start_minipage = lex.GetInteger();
776 } else if (token == "\\labelwidthstring") {
778 par->labelwidthstring = lex.GetString();
779 /* do not delete this token, it is still needed! */
780 } else if (token == "\\end_inset") {
781 /* simple ignore this. The insets do not have
783 // but insets should read it, it is a part of
784 //the inset isn't it? Lgb.
785 } else if (token == "\\begin_inset") {
787 tmptok = lex.GetString();
788 /* test the different insets */
789 if (tmptok == "Quotes") {
790 inset = new InsetQuotes;
792 par->InsertChar(pos, LyXParagraph::META_INSET);
793 par->InsertInset(pos, inset);
794 par->SetFont(pos, font);
796 } else if (tmptok == "\\i") {
797 inset = new InsetLatexAccent;
799 par->InsertChar(pos, LyXParagraph::META_INSET);
800 par->InsertInset(pos, inset);
801 par->SetFont(pos, font);
803 } else if (tmptok == "FormulaMacro") {
804 inset = new InsetFormulaMacro;
806 par->InsertChar(pos, LyXParagraph::META_INSET);
807 par->InsertInset(pos, inset);
808 par->SetFont(pos, font);
810 } else if (tmptok == "Formula") {
811 inset = new InsetFormula;
813 par->InsertChar(pos, LyXParagraph::META_INSET);
814 par->InsertInset(pos, inset);
815 par->SetFont(pos, font);
817 } else if (tmptok == "Figure") {
818 inset = new InsetFig(100, 100, this);
820 par->InsertChar(pos, LyXParagraph::META_INSET);
821 par->InsertInset(pos, inset);
822 par->SetFont(pos, font);
824 } else if (tmptok == "Info") {
825 inset = new InsetInfo;
827 par->InsertChar(pos, LyXParagraph::META_INSET);
828 par->InsertInset(pos, inset);
829 par->SetFont(pos, font);
831 } else if (tmptok == "Include") {
832 inset = new InsetInclude(string(), this);
834 par->InsertChar(pos, LyXParagraph::META_INSET);
835 par->InsertInset(pos, inset);
836 par->SetFont(pos, font);
838 } else if (tmptok == "ERT") {
839 inset = new InsetERT(this);
841 par->InsertChar(pos, LyXParagraph::META_INSET);
842 par->InsertInset(pos, inset);
843 par->SetFont(pos, font);
845 } else if (tmptok == "Text") {
846 inset = new InsetText(this);
848 par->InsertChar(pos, LyXParagraph::META_INSET);
849 par->InsertInset(pos, inset);
850 par->SetFont(pos, font);
853 } else if (tmptok == "Number") {
854 inset = new InsetNumber(this);
856 par->InsertChar(pos, LyXParagraph::META_INSET);
857 par->InsertInset(pos, inset);
858 par->SetFont(pos, font);
861 } else if (tmptok == "Foot") {
862 inset = new InsetFoot(this);
864 par->InsertChar(pos, LyXParagraph::META_INSET);
865 par->InsertInset(pos, inset);
866 par->SetFont(pos, font);
868 } else if (tmptok == "GRAPHICS") {
869 inset = new InsetGraphics;
871 par->InsertChar(pos, LyXParagraph::META_INSET);
872 par->InsertInset(pos, inset);
873 par->SetFont(pos, font);
874 } else if (tmptok == "LatexCommand") {
877 if (inscmd.getCmdName() == "cite") {
878 inset = new InsetCitation(inscmd.getContents(), inscmd.getOptions());
879 } else if (inscmd.getCmdName() == "bibitem") {
880 lex.printError("Wrong place for bibitem");
881 inset = inscmd.Clone();
882 } else if (inscmd.getCmdName() == "BibTeX") {
883 inset = new InsetBibtex(inscmd.getContents(), inscmd.getOptions(), this);
884 } else if (inscmd.getCmdName() == "index") {
885 inset = new InsetIndex(inscmd.getContents());
886 } else if (inscmd.getCmdName() == "include") {
887 inset = new InsetInclude(inscmd.getContents(), this);
888 } else if (inscmd.getCmdName() == "label") {
889 inset = new InsetLabel(inscmd.getCommand());
890 } else if (inscmd.getCmdName() == "url"
891 || inscmd.getCmdName() == "htmlurl") {
892 inset = new InsetUrl(inscmd.getCommand());
893 } else if (inscmd.getCmdName() == "ref"
894 || inscmd.getCmdName() == "pageref") {
895 if (!inscmd.getOptions().empty() || !inscmd.getContents().empty()) {
896 inset = new InsetRef(inscmd, this);
898 #warning Check if this else clause is still needed. (Lgb)
900 // This condition comes from a
901 // temporary solution to the latexdel
902 // ref inset that was transformed to
903 // an empty ref inset plus the body
904 // surronded by latexdel insets
906 string cont, opt, tmptmptok, cmdname;
908 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
913 tmptmptok = lex.GetString();
914 if(tmptmptok[0] == '\\') {
915 if( tmptmptok == "\\backslash")
925 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
930 tmptmptok = lex.GetString();
931 if(tmptmptok[0] == '\\') {
932 if( tmptmptok == "\\backslash")
942 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
948 cmdname = "\\" + inscmd.getCmdName();
949 cmdname += "[" + cont + "]";
950 cmdname += "{" + opt + "}";
951 inset = new InsetRef(cmdname, this);
954 } else if (inscmd.getCmdName() == "tableofcontents") {
955 inset = new InsetTOC(this);
956 } else if (inscmd.getCmdName() == "listoffigures") {
957 inset = new InsetLOF(this);
958 } else if (inscmd.getCmdName() == "listofalgorithms") {
959 inset = new InsetLOA(this);
960 } else if (inscmd.getCmdName() == "listoftables") {
961 inset = new InsetLOT(this);
962 } else if (inscmd.getCmdName() == "printindex") {
963 inset = new InsetPrintIndex(this);
964 } else if (inscmd.getCmdName() == "lyxparent") {
965 inset = new InsetParent(inscmd.getContents(), this);
969 par->InsertChar(pos, LyXParagraph::META_INSET);
970 par->InsertInset(pos, inset);
971 par->SetFont(pos, font);
975 } else if (token == "\\InsetQuotes") {
976 inset = new InsetQuotes;
978 par->InsertChar(pos, LyXParagraph::META_INSET);
979 par->InsertInset(pos, inset);
980 par->SetFont(pos, font);
982 } else if (token == "\\InsetFormula") {
983 inset = new InsetFormula;
985 par->InsertChar(pos, LyXParagraph::META_INSET);
986 par->InsertInset(pos, inset);
987 par->SetFont(pos, font);
989 } else if (token == "\\SpecialChar") {
990 LyXLayout const & layout =
991 textclasslist.Style(params.textclass,
994 // Insets don't make sense in a free-spacing context! ---Kayvan
995 if (layout.free_spacing)
1000 next_token = lex.GetString();
1001 if (next_token == "\\-") {
1002 par->InsertChar(pos, '-');
1003 par->SetFont(pos, font);
1004 } else if (next_token == "\\protected_separator") {
1005 par->InsertChar(pos, ' ');
1006 par->SetFont(pos, font);
1008 lex.printError("Token `$$Token' "
1010 "paragraph layout!");
1017 inset = new InsetSpecialChar;
1019 par->InsertChar(pos, LyXParagraph::META_INSET);
1020 par->InsertInset(pos, inset);
1021 par->SetFont(pos, font);
1024 } else if (token == "\\Figure") {
1025 inset = new InsetFig(100, 100, this);
1027 par->InsertChar(pos, LyXParagraph::META_INSET);
1028 par->InsertInset(pos, inset);
1029 par->SetFont(pos, font);
1031 } else if (token == "\\newline") { // soon obsolete
1033 par->InsertChar(pos, LyXParagraph::META_NEWLINE);
1034 par->SetFont(pos, font);
1036 inset = new InsetSpecialChar(InsetSpecialChar::NEWLINE);
1037 par->InsertChar(pos, LyXParagraph::META_INSET);
1038 par->InsertInset(pos, inset);
1039 par->SetFont(pos, font);
1042 } else if (token == "\\LyXTable") {
1043 par->table = new LyXTable(lex);
1044 } else if (token == "\\hfill") {
1045 par->InsertChar(pos, LyXParagraph::META_HFILL);
1046 par->SetFont(pos, font);
1048 } else if (token == "\\protected_separator") { // obsolete
1050 LyXLayout const & layout =
1051 textclasslist.Style(params.textclass,
1054 if (layout.free_spacing) {
1055 par->InsertChar(pos, ' ');
1056 par->SetFont(pos, font);
1058 inset = new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
1059 par->InsertChar(pos, LyXParagraph::META_INSET);
1060 par->InsertInset(pos, inset);
1061 par->SetFont(pos, font);
1064 par->InsertChar(pos, LyXParagraph::META_PROTECTED_SEPARATOR);
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 int n = token.length();
1083 for (int i = 0; i < n; ++i) {
1084 par->InsertChar(pos, token[i]);
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 */
1397 /* dummy layout, that means a footnote ended */
1398 footnoteflag = LyXParagraph::NO_FOOTNOTE;
1403 LyXLayout const & layout =
1404 textclasslist.Style(params.textclass,
1406 bool free_spc = layout.free_spacing;
1408 /* It might be a table */
1411 if (!lyxrc.ascii_roff_command.empty() &&
1412 lyxrc.ascii_roff_command != "none") {
1413 RoffAsciiTable(ofs, par);
1420 cells = par->table->columns;
1421 clen = new int [cells];
1422 memset(clen, 0, sizeof(int) * cells);
1424 for (i = 0, j = 0, h = 1; i < par->size(); ++i, ++h) {
1425 c = par->GetChar(i);
1426 if (c == LyXParagraph::META_INSET) {
1427 if ((inset = par->GetInset(i))) {
1430 std::ostringstream ost;
1431 inset->Latex(ost, -1, free_spc);
1432 h += ost.str().length();
1435 inset->Latex(ost, -1, free_spc);
1437 char * tmp = ost.str();
1443 ofstream fs(fname1.c_str());
1445 WriteFSAlert(_("Error: Cannot open temporary file:"), fname1);
1448 inset->Latex(fs, -1, free_spc);
1449 h += fs.tellp() - 1;
1450 ::remove(fname1.c_str());
1453 } else if (c == LyXParagraph::META_NEWLINE) {
1457 j = (++j) % par->table->NumberOfCellsInRow(actcell);
1465 font1 = LyXFont(LyXFont::ALL_INHERIT,params.language_info);
1467 for (i = 0, actpos = 1; i < par->size(); ++i, ++actpos) {
1468 if (!i && !footnoteflag && !noparbreak){
1470 for(j = 0; j < depth; ++j)
1472 currlinelen = depth * 2;
1474 case 0: /* Standard */
1475 case 4: /* (Sub)Paragraph */
1476 case 5: /* Description */
1478 case 6: /* Abstract */
1479 ofs << "Abstract\n\n";
1481 case 7: /* Bibliography */
1483 ofs << "References\n\n";
1488 ofs << par->labelstring << " ";
1491 if (ltype_depth > depth) {
1492 for(j = ltype_depth - 1; j > depth; --j)
1494 currlinelen += (ltype_depth-depth)*2;
1497 for(j = 0; j < cells; ++j) {
1499 for(h = 0; h < (clen[j] + 1);
1504 for(j = 0; j < depth; ++j)
1506 currlinelen = depth * 2;
1507 if (ltype_depth > depth) {
1508 for(j = ltype_depth;
1511 currlinelen += (ltype_depth-depth)*2;
1516 font2 = par->GetFontSettings(i);
1517 if (font1.latex() != font2.latex()) {
1518 if (font2.latex() == LyXFont::OFF)
1526 c = par->GetChar(i);
1530 case LyXParagraph::META_INSET:
1531 if ((inset = par->GetInset(i))) {
1533 inset->Latex(ofs, -1, free_spc);
1534 currlinelen += (ofs.tellp() - fpos);
1535 actpos += (ofs.tellp() - fpos) - 1;
1538 case LyXParagraph::META_NEWLINE:
1540 if (par->table->NumberOfCellsInRow(actcell) <= cell) {
1541 for(j = actpos; j < clen[cell - 1]; ++j)
1544 for(j = 0; j < depth; ++j)
1546 currlinelen = depth*2;
1547 if (ltype_depth > depth) {
1548 for(j = ltype_depth; j > depth; --j)
1550 currlinelen += (ltype_depth-depth) * 2;
1552 for(j = 0; j < cells; ++j) {
1554 for(h = 0; h < (clen[j] + 1); ++h)
1558 for(j = 0; j < depth; ++j)
1560 currlinelen = depth * 2;
1561 if (ltype_depth > depth) {
1562 for(j = ltype_depth;
1565 currlinelen += (ltype_depth-depth)*2;
1571 j < clen[cell - 1]; ++j)
1577 currlinelen = actpos = 0;
1580 for(j = 0; j < depth; ++j)
1582 currlinelen = depth * 2;
1583 if (ltype_depth > depth) {
1584 for(j = ltype_depth;
1587 currlinelen += (ltype_depth - depth) * 2;
1591 case LyXParagraph::META_HFILL:
1595 case LyXParagraph::META_PROTECTED_SEPARATOR:
1603 if (currlinelen > linelen - 10
1604 && c == ' ' && i + 2 < par->size()) {
1606 for(j = 0; j < depth; ++j)
1608 currlinelen = depth * 2;
1609 if (ltype_depth > depth) {
1610 for(j = ltype_depth;
1613 currlinelen += (ltype_depth-depth)*2;
1615 } else if (c != '\0')
1618 lyxerr.debug() << "writeAsciiFile: NULL char in structure." << endl;
1624 for(j = actpos; j < clen[cell - 1]; ++j)
1627 for(j = 0; j < depth; ++j)
1629 currlinelen = depth * 2;
1630 if (ltype_depth > depth) {
1631 for(j = ltype_depth; j > depth; --j)
1633 currlinelen += (ltype_depth - depth) * 2;
1635 for(j = 0; j < cells; ++j) {
1637 for(h = 0; h < (clen[j] + 1); ++h)
1650 void Buffer::makeLaTeXFile(string const & fname,
1651 string const & original_path,
1652 bool nice, bool only_body)
1654 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
1656 niceFile = nice; // this will be used by Insetincludes.
1658 tex_code_break_column = lyxrc.ascii_linelen;
1660 LyXTextClass const & tclass =
1661 textclasslist.TextClass(params.textclass);
1663 ofstream ofs(fname.c_str());
1665 WriteFSAlert(_("Error: Cannot open file: "), fname);
1669 // validate the buffer.
1670 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
1671 LaTeXFeatures features(params, tclass.numLayouts());
1673 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
1676 // The starting paragraph of the coming rows is the
1677 // first paragraph of the document. (Asger)
1678 texrow.start(paragraph, 0);
1680 if (!only_body && nice) {
1681 ofs << "%% " LYX_DOCVERSION " created this file. "
1682 "For more info, see http://www.lyx.org/.\n"
1683 "%% Do not edit unless you really know what "
1688 lyxerr.debug() << "lyx header finished" << endl;
1689 // There are a few differences between nice LaTeX and usual files:
1690 // usual is \batchmode and has a
1691 // special input@path to allow the including of figures
1692 // with either \input or \includegraphics (what figinsets do).
1693 // batchmode is not set if there is a tex_code_break_column.
1694 // In this case somebody is interested in the generated LaTeX,
1695 // so this is OK. input@path is set when the actual parameter
1696 // original_path is set. This is done for usual tex-file, but not
1697 // for nice-latex-file. (Matthias 250696)
1700 // code for usual, NOT nice-latex-file
1701 ofs << "\\batchmode\n"; // changed
1702 // from \nonstopmode
1705 if (!original_path.empty()) {
1706 ofs << "\\makeatletter\n"
1707 << "\\def\\input@path{{"
1708 << original_path << "/}}\n"
1709 << "\\makeatother\n";
1715 ofs << "\\documentclass";
1717 string options; // the document class options.
1719 if (tokenPos(tclass.opt_fontsize(), '|', params.fontsize) >= 0) {
1720 // only write if existing in list (and not default)
1721 options += params.fontsize;
1726 if (!params.use_geometry &&
1727 (params.paperpackage == BufferParams::PACKAGE_NONE)) {
1728 switch (params.papersize) {
1729 case BufferParams::PAPER_A4PAPER:
1730 options += "a4paper,";
1732 case BufferParams::PAPER_USLETTER:
1733 options += "letterpaper,";
1735 case BufferParams::PAPER_A5PAPER:
1736 options += "a5paper,";
1738 case BufferParams::PAPER_B5PAPER:
1739 options += "b5paper,";
1741 case BufferParams::PAPER_EXECUTIVEPAPER:
1742 options += "executivepaper,";
1744 case BufferParams::PAPER_LEGALPAPER:
1745 options += "legalpaper,";
1751 if (params.sides != tclass.sides()) {
1752 switch (params.sides) {
1753 case LyXTextClass::OneSide:
1754 options += "oneside,";
1756 case LyXTextClass::TwoSides:
1757 options += "twoside,";
1764 if (params.columns != tclass.columns()) {
1765 if (params.columns == 2)
1766 options += "twocolumn,";
1768 options += "onecolumn,";
1771 if (!params.use_geometry
1772 && params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1773 options += "landscape,";
1775 // language should be a parameter to \documentclass
1776 bool use_babel = false;
1777 if (params.language != "default" ||
1778 !features.UsedLanguages.empty() ) {
1780 for (LaTeXFeatures::LanguageList::const_iterator cit =
1781 features.UsedLanguages.begin();
1782 cit != features.UsedLanguages.end(); ++cit) {
1783 options += (*cit)->lang + ",";
1785 if (default_language != params.language_info)
1786 options += default_language ->lang + ',';
1787 options += params.language_info->lang + ',';
1790 // the user-defined options
1791 if (!params.options.empty()) {
1792 options += params.options + ',';
1795 if (!options.empty()){
1796 options = strip(options, ',');
1797 ofs << '[' << options << ']';
1801 << textclasslist.LatexnameOfClass(params.textclass)
1804 // end of \documentclass defs
1806 // font selection must be done before loading fontenc.sty
1807 if (params.fonts != "default") {
1808 ofs << "\\usepackage{" << params.fonts << "}\n";
1811 // this one is not per buffer
1812 if (lyxrc.fontenc != "default") {
1813 ofs << "\\usepackage[" << lyxrc.fontenc
1817 if (params.inputenc != "default") {
1818 ofs << "\\usepackage[" << params.inputenc
1823 /* at the very beginning the text parameters */
1824 if (params.paperpackage != BufferParams::PACKAGE_NONE) {
1825 switch (params.paperpackage) {
1826 case BufferParams::PACKAGE_A4:
1827 ofs << "\\usepackage{a4}\n";
1830 case BufferParams::PACKAGE_A4WIDE:
1831 ofs << "\\usepackage{a4wide}\n";
1834 case BufferParams::PACKAGE_WIDEMARGINSA4:
1835 ofs << "\\usepackage[widemargins]{a4}\n";
1840 if (params.use_geometry) {
1841 ofs << "\\usepackage{geometry}\n";
1843 ofs << "\\geometry{verbose";
1844 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1845 ofs << ",landscape";
1846 switch (params.papersize2) {
1847 case BufferParams::VM_PAPER_CUSTOM:
1848 if (!params.paperwidth.empty())
1849 ofs << ",paperwidth="
1850 << params.paperwidth;
1851 if (!params.paperheight.empty())
1852 ofs << ",paperheight="
1853 << params.paperheight;
1855 case BufferParams::VM_PAPER_USLETTER:
1856 ofs << ",letterpaper";
1858 case BufferParams::VM_PAPER_USLEGAL:
1859 ofs << ",legalpaper";
1861 case BufferParams::VM_PAPER_USEXECUTIVE:
1862 ofs << ",executivepaper";
1864 case BufferParams::VM_PAPER_A3:
1867 case BufferParams::VM_PAPER_A4:
1870 case BufferParams::VM_PAPER_A5:
1873 case BufferParams::VM_PAPER_B3:
1876 case BufferParams::VM_PAPER_B4:
1879 case BufferParams::VM_PAPER_B5:
1883 // default papersize ie BufferParams::VM_PAPER_DEFAULT
1884 switch (lyxrc.default_papersize) {
1885 case BufferParams::PAPER_DEFAULT: // keep compiler happy
1886 case BufferParams::PAPER_USLETTER:
1887 ofs << ",letterpaper";
1889 case BufferParams::PAPER_LEGALPAPER:
1890 ofs << ",legalpaper";
1892 case BufferParams::PAPER_EXECUTIVEPAPER:
1893 ofs << ",executivepaper";
1895 case BufferParams::PAPER_A3PAPER:
1898 case BufferParams::PAPER_A4PAPER:
1901 case BufferParams::PAPER_A5PAPER:
1904 case BufferParams::PAPER_B5PAPER:
1909 if (!params.topmargin.empty())
1910 ofs << ",tmargin=" << params.topmargin;
1911 if (!params.bottommargin.empty())
1912 ofs << ",bmargin=" << params.bottommargin;
1913 if (!params.leftmargin.empty())
1914 ofs << ",lmargin=" << params.leftmargin;
1915 if (!params.rightmargin.empty())
1916 ofs << ",rmargin=" << params.rightmargin;
1917 if (!params.headheight.empty())
1918 ofs << ",headheight=" << params.headheight;
1919 if (!params.headsep.empty())
1920 ofs << ",headsep=" << params.headsep;
1921 if (!params.footskip.empty())
1922 ofs << ",footskip=" << params.footskip;
1926 if (params.use_amsmath
1927 && !prefixIs(textclasslist.LatexnameOfClass(params.textclass), "ams")) {
1928 ofs << "\\usepackage{amsmath}\n";
1932 if (tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle) >= 0) {
1933 if (params.pagestyle == "fancy") {
1934 ofs << "\\usepackage{fancyhdr}\n";
1937 ofs << "\\pagestyle{" << params.pagestyle << "}\n";
1941 // We try to load babel late, in case it interferes
1942 // with other packages.
1944 ofs << lyxrc.language_package << endl;
1948 if (params.secnumdepth != tclass.secnumdepth()) {
1949 ofs << "\\setcounter{secnumdepth}{"
1950 << params.secnumdepth
1954 if (params.tocdepth != tclass.tocdepth()) {
1955 ofs << "\\setcounter{tocdepth}{"
1961 if (params.paragraph_separation) {
1962 switch (params.defskip.kind()) {
1963 case VSpace::SMALLSKIP:
1964 ofs << "\\setlength\\parskip{\\smallskipamount}\n";
1966 case VSpace::MEDSKIP:
1967 ofs << "\\setlength\\parskip{\\medskipamount}\n";
1969 case VSpace::BIGSKIP:
1970 ofs << "\\setlength\\parskip{\\bigskipamount}\n";
1972 case VSpace::LENGTH:
1973 ofs << "\\setlength\\parskip{"
1974 << params.defskip.length().asLatexString()
1977 default: // should never happen // Then delete it.
1978 ofs << "\\setlength\\parskip{\\medskipamount}\n";
1983 ofs << "\\setlength\\parindent{0pt}\n";
1987 // Now insert the LyX specific LaTeX commands...
1988 string preamble, tmppreamble;
1990 // The optional packages;
1991 preamble = features.getPackages();
1993 // this might be useful...
1994 preamble += "\n\\makeatletter\n\n";
1996 // Some macros LyX will need
1997 tmppreamble = features.getMacros();
1999 if (!tmppreamble.empty()) {
2000 preamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2001 "LyX specific LaTeX commands.\n"
2002 + tmppreamble + '\n';
2005 // the text class specific preamble
2006 tmppreamble = features.getTClassPreamble();
2007 if (!tmppreamble.empty()) {
2008 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2009 "Textclass specific LaTeX commands.\n"
2010 + tmppreamble + '\n';
2013 /* the user-defined preamble */
2014 if (!params.preamble.empty()) {
2015 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2016 "User specified LaTeX commands.\n"
2017 + params.preamble + '\n';
2020 preamble += "\\makeatother\n\n";
2022 // Itemize bullet settings need to be last in case the user
2023 // defines their own bullets that use a package included
2024 // in the user-defined preamble -- ARRae
2025 // Actually it has to be done much later than that
2026 // since some packages like frenchb make modifications
2027 // at \begin{document} time -- JMarc
2029 for (int i = 0; i < 4; ++i) {
2030 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
2031 if (bullets_def.empty())
2032 bullets_def="\\AtBeginDocument{\n";
2033 bullets_def += " \\renewcommand{\\labelitemi";
2035 // `i' is one less than the item to modify
2042 bullets_def += "ii";
2048 bullets_def += "}{" +
2049 params.user_defined_bullets[i].getText()
2054 if (!bullets_def.empty())
2055 preamble += bullets_def + "}\n\n";
2057 for (int j = countChar(preamble, '\n'); j-- ;) {
2064 ofs << "\\begin{document}\n\n";
2068 lyxerr.debug() << "preamble finished, now the body." << endl;
2069 if (!lyxrc.language_auto_begin && params.language != "default") {
2070 ofs << subst(lyxrc.language_command_begin, "$$lang",
2076 bool was_title = false;
2077 bool already_title = false;
2079 std::ostringstream ftnote;
2081 char * tmpholder = 0;
2086 LyXParagraph * par = paragraph;
2090 #ifndef HAVE_SSTREAM
2093 ftnote << tmpholder;
2094 delete [] tmpholder;
2099 lyxerr[Debug::LATEX] << "Error in MakeLateXFile."
2101 LyXLayout const & layout =
2102 textclasslist.Style(params.textclass,
2105 if (layout.intitle) {
2106 if (already_title) {
2107 lyxerr <<"Error in MakeLatexFile: You"
2108 " should not mix title layouts"
2109 " with normal ones." << endl;
2112 } else if (was_title && !already_title) {
2113 ofs << "\\maketitle\n";
2115 already_title = true;
2118 // We are at depth 0 so we can just use
2119 // ordinary \footnote{} generation
2120 // flag this with ftcount
2122 if (layout.isEnvironment()
2123 || par->pextra_type != LyXParagraph::PEXTRA_NONE) {
2124 par = par->TeXEnvironment(ofs, texrow,
2125 ftnote, ft_texrow, ftcount);
2127 par = par->TeXOnePar(ofs, texrow,
2128 ftnote, ft_texrow, ftcount);
2131 // Write out what we've generated...
2134 ofs << "\\addtocounter{footnote}{-"
2138 ofs << ftnote.str();
2139 texrow += ft_texrow;
2141 // The extra .c_str() is needed when we use
2142 // lyxstring instead of the STL string class.
2143 ftnote.str(string().c_str());
2145 delete [] ftnote.str();
2150 #ifndef HAVE_SSTREAM
2152 // I hate strstreams
2153 tmpholder = ftnote.str();
2157 #ifndef HAVE_SSTREAM
2158 delete [] tmpholder;
2160 // It might be that we only have a title in this document
2161 if (was_title && !already_title) {
2162 ofs << "\\maketitle\n";
2166 if (!lyxrc.language_auto_end && params.language != "default") {
2167 ofs << subst(lyxrc.language_command_end, "$$lang",
2174 ofs << "\\end{document}\n";
2177 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
2179 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
2183 // Just to be sure. (Asger)
2186 // tex_code_break_column's value is used to decide
2187 // if we are in batchmode or not (within mathed_write()
2188 // in math_write.C) so we must set it to a non-zero
2189 // value when we leave otherwise we save incorrect .lyx files.
2190 tex_code_break_column = lyxrc.ascii_linelen;
2194 lyxerr << "File was not closed properly." << endl;
2197 lyxerr.debug() << "Finished making latex file." << endl;
2201 bool Buffer::isLatex() const
2203 return textclasslist.TextClass(params.textclass).outputType() == LATEX;
2207 bool Buffer::isLinuxDoc() const
2209 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC;
2213 bool Buffer::isLiterate() const
2215 return textclasslist.TextClass(params.textclass).outputType() == LITERATE;
2219 bool Buffer::isDocBook() const
2221 return textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2225 bool Buffer::isSGML() const
2227 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC ||
2228 textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2232 void Buffer::sgmlOpenTag(ostream & os, int depth,
2233 string const & latexname) const
2235 os << string(depth, ' ') << "<" << latexname << ">\n";
2239 void Buffer::sgmlCloseTag(ostream & os, int depth,
2240 string const & latexname) const
2242 os << string(depth, ' ') << "</" << latexname << ">\n";
2246 void Buffer::makeLinuxDocFile(string const & fname, int column)
2248 LyXParagraph * par = paragraph;
2250 string top_element = textclasslist.LatexnameOfClass(params.textclass);
2251 string environment_stack[10];
2254 int depth = 0; /* paragraph depth */
2256 ofstream ofs(fname.c_str());
2259 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2263 tex_code_break_column = column;
2266 if (params.preamble.empty()) {
2267 ofs << "<!doctype linuxdoc system>\n\n";
2270 ofs << "<!doctype linuxdoc system \n [ "
2271 << params.preamble << " \n]>\n\n";
2274 ofs << "<!-- " << LYX_DOCVERSION
2275 << " created this file. For more info see http://www.lyx.org/"
2278 if(params.options.empty())
2279 sgmlOpenTag(ofs, 0, top_element);
2281 string top = top_element;
2283 top += params.options;
2284 sgmlOpenTag(ofs, 0, top);
2288 int desc_on = 0; /* description mode*/
2289 LyXLayout const & style =
2290 textclasslist.Style(users->buffer()->params.textclass,
2292 par->AutoDeleteInsets();
2294 /* treat <toc> as a special case for compatibility with old code */
2295 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2296 Inset * inset = par->GetInset(0);
2297 char lyx_code = inset->LyxCode();
2298 if (lyx_code == Inset::TOC_CODE){
2299 string temp = "toc";
2300 sgmlOpenTag(ofs, depth, temp);
2303 linuxDocHandleFootnote(ofs, par, depth);
2308 // environment tag closing
2309 for( ; depth > par->depth; --depth) {
2310 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2311 environment_stack[depth].clear();
2314 // write opening SGML tags
2315 switch(style.latextype) {
2316 case LATEX_PARAGRAPH:
2317 if(depth == par->depth
2318 && !environment_stack[depth].empty()) {
2319 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2320 environment_stack[depth].clear();
2326 sgmlOpenTag(ofs, depth, style.latexname());
2331 LinuxDocError(par, 0, _("Error : Wrong depth for LatexType Command.\n"));
2333 if (!environment_stack[depth].empty()){
2334 sgmlCloseTag(ofs, depth,
2335 environment_stack[depth]);
2339 environment_stack[depth].clear();
2340 sgmlOpenTag(ofs, depth, style.latexname());
2343 case LATEX_ENVIRONMENT:
2344 case LATEX_ITEM_ENVIRONMENT:
2345 if(depth == par->depth
2346 && environment_stack[depth] != style.latexname()
2347 && !environment_stack[depth].empty()) {
2349 sgmlCloseTag(ofs, depth,
2350 environment_stack[depth]);
2351 environment_stack[depth].clear();
2353 if (depth < par->depth) {
2355 environment_stack[depth].clear();
2357 if (environment_stack[depth] != style.latexname()) {
2360 sgmlOpenTag(ofs, depth, temp);
2362 environment_stack[depth] = style.latexname();
2363 sgmlOpenTag(ofs, depth, environment_stack[depth]);
2365 if(style.latextype == LATEX_ENVIRONMENT) break;
2367 desc_on = (style.labeltype == LABEL_MANUAL);
2374 sgmlOpenTag(ofs, depth + 1, item_name);
2377 sgmlOpenTag(ofs, depth, style.latexname());
2382 SimpleLinuxDocOnePar(ofs, par, desc_on, depth);
2385 linuxDocHandleFootnote(ofs, par, depth);
2387 while(par && par->IsDummy());
2390 /* write closing SGML tags */
2391 switch(style.latextype) {
2393 case LATEX_ENVIRONMENT:
2394 case LATEX_ITEM_ENVIRONMENT:
2397 sgmlCloseTag(ofs, depth, style.latexname());
2402 /* Close open tags */
2403 for(; depth > 0; --depth)
2404 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2406 if(!environment_stack[depth].empty())
2407 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2410 sgmlCloseTag(ofs, 0, top_element);
2413 // How to check for successful close
2417 void Buffer::linuxDocHandleFootnote(ostream & os, LyXParagraph * & par,
2420 string tag = "footnote";
2422 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2423 sgmlOpenTag(os, depth + 1, tag);
2424 SimpleLinuxDocOnePar(os, par, 0, depth + 1);
2425 sgmlCloseTag(os, depth + 1, tag);
2431 void Buffer::DocBookHandleCaption(ostream & os, string & inner_tag,
2432 int const depth, int desc_on,
2433 LyXParagraph * & par)
2435 LyXParagraph * tpar = par;
2436 while (tpar && (tpar->footnoteflag != LyXParagraph::NO_FOOTNOTE) &&
2437 (tpar->layout != textclasslist.NumberOfLayout(params.textclass,
2441 tpar->layout == textclasslist.NumberOfLayout(params.textclass,
2442 "Caption").second) {
2443 sgmlOpenTag(os, depth + 1, inner_tag);
2445 SimpleDocBookOnePar(os, extra_par, tpar,
2446 desc_on, depth + 2);
2447 sgmlCloseTag(os, depth+1, inner_tag);
2448 if(!extra_par.empty())
2454 void Buffer::DocBookHandleFootnote(ostream & os, LyXParagraph * & par,
2457 string tag, inner_tag;
2458 string tmp_par, extra_par;
2459 bool inner_span = false;
2462 // Someone should give this enum a proper name (Lgb)
2470 SOME_ENUM last = NO_ONE;
2471 SOME_ENUM present = FOOTNOTE_LIKE;
2473 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2474 if(last == present) {
2476 if(!tmp_par.empty()) {
2479 sgmlCloseTag(os, depth + 1, inner_tag);
2480 sgmlOpenTag(os, depth + 1, inner_tag);
2487 if(!inner_tag.empty()) sgmlCloseTag(os, depth + 1,
2489 if(!extra_par.empty()) os << extra_par;
2490 if(!tag.empty()) sgmlCloseTag(os, depth, tag);
2493 switch (par->footnotekind) {
2494 case LyXParagraph::FOOTNOTE:
2495 case LyXParagraph::ALGORITHM:
2498 present = FOOTNOTE_LIKE;
2501 case LyXParagraph::MARGIN:
2504 present = MARGIN_LIKE;
2507 case LyXParagraph::FIG:
2508 case LyXParagraph::WIDE_FIG:
2510 inner_tag = "title";
2514 case LyXParagraph::TAB:
2515 case LyXParagraph::WIDE_TAB:
2517 inner_tag = "title";
2522 sgmlOpenTag(os, depth, tag);
2523 if ((present == TAB_LIKE) || (present == FIG_LIKE)) {
2524 DocBookHandleCaption(os, inner_tag, depth,
2528 sgmlOpenTag(os, depth + 1, inner_tag);
2531 // ignore all caption here, we processed them above!!!
2532 if (par->layout != textclasslist
2533 .NumberOfLayout(params.textclass,
2534 "Caption").second) {
2536 std::ostringstream ost;
2540 SimpleDocBookOnePar(ost, extra_par, par,
2541 desc_on, depth + 2);
2543 tmp_par += ost.str().c_str();
2546 char * ctmp = ost.str();
2551 tmp_par = frontStrip(strip(tmp_par));
2557 if(!inner_tag.empty()) sgmlCloseTag(os, depth + 1, inner_tag);
2558 if(!extra_par.empty()) os << extra_par;
2559 if(!tag.empty()) sgmlCloseTag(os, depth, tag);
2563 /* push a tag in a style stack */
2564 void Buffer::push_tag(ostream & os, char const * tag,
2565 int & pos, char stack[5][3])
2567 /* pop all previous tags */
2568 for (int j = pos; j >= 0; --j)
2569 os << "</" << stack[j] << ">";
2572 sprintf(stack[++pos], "%s", tag);
2575 for (int i = 0; i <= pos; ++i)
2576 os << "<" << stack[i] << ">";
2580 void Buffer::pop_tag(ostream & os, char const * tag,
2581 int & pos, char stack[5][3])
2585 // pop all tags till specified one
2586 for (j = pos; (j >= 0) && (strcmp(stack[j], tag)); --j)
2587 os << "</" << stack[j] << ">";
2590 os << "</" << tag << ">";
2592 // push all tags, but the specified one
2593 for (j = j + 1; j <= pos; ++j) {
2594 os << "<" << stack[j] << ">";
2595 strcpy(stack[j-1], stack[j]);
2601 /* handle internal paragraph parsing -- layout already processed */
2603 // checks, if newcol chars should be put into this line
2604 // writes newline, if necessary.
2606 void linux_doc_line_break(ostream & os, unsigned int & colcount,
2607 const unsigned int newcol)
2610 if (colcount > lyxrc.ascii_linelen) {
2612 colcount = newcol; // assume write after this call
2617 void Buffer::SimpleLinuxDocOnePar(ostream & os, LyXParagraph * par,
2618 int desc_on, int const /*depth*/)
2620 LyXFont font1, font2;
2623 LyXParagraph::size_type main_body;
2625 LyXLayout const & style = textclasslist.Style(params.textclass,
2628 char family_type = 0; // family font flag
2629 bool is_bold = false; // series font flag
2630 char shape_type = 0; // shape font flag
2631 bool is_em = false; // emphasis (italic) font flag
2633 int stack_num = -1; // style stack position
2634 char stack[5][3]; // style stack
2635 unsigned int char_line_count = 5; // Heuristic choice ;-)
2637 if (style.labeltype != LABEL_MANUAL)
2640 main_body = par->BeginningOfMainBody();
2642 /* gets paragraph main font */
2644 font1 = style.labelfont;
2649 /* parsing main loop */
2650 for (LyXParagraph::size_type i = 0;
2651 i < par->size(); ++i) {
2653 /* handle quote tag */
2654 if (i == main_body && !par->IsDummy()) {
2659 font2 = par->getFont(i);
2661 if (font1.family() != font2.family()) {
2662 switch(family_type) {
2664 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2665 push_tag(os, "tt", stack_num, stack);
2668 else if (font2.family() == LyXFont::SANS_FAMILY) {
2669 push_tag(os, "sf", stack_num, stack);
2674 pop_tag(os, "tt", stack_num, stack);
2675 if (font2.family() == LyXFont::SANS_FAMILY) {
2676 push_tag(os, "sf", stack_num, stack);
2684 pop_tag(os, "sf", stack_num, stack);
2685 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2686 push_tag(os, "tt", stack_num, stack);
2695 /* handle bold face */
2696 if (font1.series() != font2.series()) {
2697 if (font2.series() == LyXFont::BOLD_SERIES) {
2698 push_tag(os, "bf", stack_num, stack);
2702 pop_tag(os, "bf", stack_num, stack);
2707 /* handle italic and slanted fonts */
2708 if (font1.shape() != font2.shape()) {
2709 switch(shape_type) {
2711 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2712 push_tag(os, "it", stack_num, stack);
2715 else if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2716 push_tag(os, "sl", stack_num, stack);
2721 pop_tag(os, "it", stack_num, stack);
2722 if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2723 push_tag(os, "sl", stack_num, stack);
2731 pop_tag(os, "sl", stack_num, stack);
2732 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2733 push_tag(os, "it", stack_num, stack);
2741 /* handle <em> tag */
2742 if (font1.emph() != font2.emph()) {
2743 if (font2.emph() == LyXFont::ON) {
2744 push_tag(os, "em", stack_num, stack);
2747 pop_tag(os, "em", stack_num, stack);
2752 c = par->GetChar(i);
2754 if (font2.latex() == LyXFont::ON) {
2755 // "TeX"-Mode on == > SGML-Mode on.
2757 os << c; // see LaTeX-Generation...
2759 } else if (c == LyXParagraph::META_INSET) {
2760 inset = par->GetInset(i);
2761 inset->Linuxdoc(os);
2764 if (par->linuxDocConvertChar(c, sgml_string)
2765 && !style.free_spacing) { // in freespacing
2767 // non-breaking characters
2771 linux_doc_line_break(os, char_line_count, 6);
2776 linux_doc_line_break(os, char_line_count, 1);
2782 char_line_count += sgml_string.length();
2788 /* needed if there is an optional argument but no contents */
2789 if (main_body > 0 && main_body == par->size()) {
2793 /* pop all defined Styles */
2794 for (j = stack_num; j >= 0; --j) {
2795 linux_doc_line_break(os,
2797 3 + strlen(stack[j]));
2798 os << "</" << stack[j] << ">";
2801 /* resets description flag correctly */
2804 /* <tag> not closed... */
2805 linux_doc_line_break(os, char_line_count, 6);
2809 /* fprintf(file, "</p>");*/
2815 /* print an error message */
2816 void Buffer::LinuxDocError(LyXParagraph * par, int pos,
2817 char const * message)
2819 InsetError * new_inset;
2821 /* insert an error marker in text */
2822 new_inset = new InsetError(message);
2823 par->InsertChar(pos, LyXParagraph::META_INSET);
2824 par->InsertInset(pos, new_inset);
2827 // This constant defines the maximum number of
2828 // environment layouts that can be nesteded.
2829 // The same applies for command layouts.
2830 // These values should be more than enough.
2831 // José Matos (1999/07/22)
2833 enum { MAX_NEST_LEVEL = 25};
2835 void Buffer::makeDocBookFile(string const & fname, int column)
2837 LyXParagraph * par = paragraph;
2839 string top_element= textclasslist.LatexnameOfClass(params.textclass);
2840 string environment_stack[MAX_NEST_LEVEL];
2841 string environment_inner[MAX_NEST_LEVEL];
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 par->AutoDeleteInsets();
2888 /* environment tag closing */
2889 for( ; depth > par->depth; --depth) {
2890 if(environment_inner[depth] != "!-- --") {
2891 item_name= "listitem";
2892 sgmlCloseTag(ofs, command_depth + depth,
2894 if( environment_inner[depth] == "varlistentry")
2895 sgmlCloseTag(ofs, depth+command_depth,
2896 environment_inner[depth]);
2898 sgmlCloseTag(ofs, depth + command_depth,
2899 environment_stack[depth]);
2900 environment_stack[depth].clear();
2901 environment_inner[depth].clear();
2904 if(depth == par->depth
2905 && environment_stack[depth] != style.latexname()
2906 && !environment_stack[depth].empty()) {
2907 if(environment_inner[depth] != "!-- --") {
2908 item_name= "listitem";
2909 sgmlCloseTag(ofs, command_depth+depth,
2911 if( environment_inner[depth] == "varlistentry")
2913 depth + command_depth,
2914 environment_inner[depth]);
2917 sgmlCloseTag(ofs, depth + command_depth,
2918 environment_stack[depth]);
2920 environment_stack[depth].clear();
2921 environment_inner[depth].clear();
2924 // Write opening SGML tags.
2925 switch(style.latextype) {
2926 case LATEX_PARAGRAPH:
2927 if(style.latexname() != "dummy")
2928 sgmlOpenTag(ofs, depth+command_depth,
2934 LinuxDocError(par, 0,
2935 _("Error : Wrong depth for "
2936 "LatexType Command.\n"));
2938 command_name = style.latexname();
2940 tmps = style.latexparam();
2941 c_params = split(tmps, c_depth,'|');
2943 cmd_depth= atoi(c_depth.c_str());
2946 if(cmd_depth<command_base) {
2947 for(int j = command_depth;
2948 j >= command_base; --j)
2949 if(!command_stack[j].empty())
2950 sgmlCloseTag(ofs, j, command_stack[j]);
2951 command_depth= command_base= cmd_depth;
2953 else if(cmd_depth <= command_depth) {
2954 for(int j = command_depth;
2955 j >= cmd_depth; --j)
2957 if(!command_stack[j].empty())
2958 sgmlCloseTag(ofs, j, command_stack[j]);
2959 command_depth= cmd_depth;
2962 command_depth= cmd_depth;
2965 command_depth = command_base = cmd_depth;
2966 command_flag = true;
2968 command_stack[command_depth]= command_name;
2970 // treat label as a special case for
2971 // more WYSIWYM handling.
2972 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2973 Inset * inset = par->GetInset(0);
2974 char lyx_code = inset->LyxCode();
2975 if (lyx_code == Inset::LABEL_CODE){
2976 command_name += " id=\"";
2977 command_name += (static_cast<InsetCommand *>(inset))->getContents();
2978 command_name += "\"";
2983 sgmlOpenTag(ofs, depth+command_depth, command_name);
2984 item_name = "title";
2985 sgmlOpenTag(ofs, depth + 1 + command_depth, item_name);
2988 case LATEX_ENVIRONMENT:
2989 case LATEX_ITEM_ENVIRONMENT:
2990 if (depth < par->depth) {
2992 environment_stack[depth].clear();
2995 if (environment_stack[depth] != style.latexname()) {
2996 environment_stack[depth] = style.latexname();
2997 environment_inner[depth] = "!-- --";
2998 sgmlOpenTag(ofs, depth + command_depth,
2999 environment_stack[depth]);
3001 if(environment_inner[depth] != "!-- --") {
3002 item_name= "listitem";
3004 command_depth + depth,
3006 if (environment_inner[depth] == "varlistentry")
3008 depth + command_depth,
3009 environment_inner[depth]);
3013 if(style.latextype == LATEX_ENVIRONMENT) {
3014 if(!style.latexparam().empty())
3015 sgmlOpenTag(ofs, depth + command_depth,
3016 style.latexparam());
3020 desc_on = (style.labeltype == LABEL_MANUAL);
3023 environment_inner[depth]= "varlistentry";
3025 environment_inner[depth]= "listitem";
3027 sgmlOpenTag(ofs, depth + 1 + command_depth,
3028 environment_inner[depth]);
3032 sgmlOpenTag(ofs, depth + 1 + command_depth,
3037 sgmlOpenTag(ofs, depth + 1 + command_depth,
3042 sgmlOpenTag(ofs, depth + command_depth,
3049 SimpleDocBookOnePar(ofs, extra_par, par, desc_on,
3050 depth + 1 + command_depth);
3052 DocBookHandleFootnote(ofs, par,
3053 depth + 1 + command_depth);
3055 while(par && par->IsDummy());
3058 /* write closing SGML tags */
3059 switch(style.latextype) {
3062 sgmlCloseTag(ofs, depth + command_depth, end_tag);
3064 case LATEX_ENVIRONMENT:
3065 if(!style.latexparam().empty())
3066 sgmlCloseTag(ofs, depth + command_depth,
3067 style.latexparam());
3069 case LATEX_ITEM_ENVIRONMENT:
3070 if(desc_on == 1) break;
3072 sgmlCloseTag(ofs, depth + 1 + command_depth, end_tag);
3074 case LATEX_PARAGRAPH:
3075 if(style.latexname() != "dummy")
3076 sgmlCloseTag(ofs, depth + command_depth,
3080 sgmlCloseTag(ofs, depth + command_depth,
3087 for(; depth >= 0; --depth) {
3088 if(!environment_stack[depth].empty()) {
3089 if(environment_inner[depth] != "!-- --") {
3090 item_name= "listitem";
3091 sgmlCloseTag(ofs, command_depth + depth,
3093 if( environment_inner[depth] == "varlistentry")
3094 sgmlCloseTag(ofs, depth + command_depth,
3095 environment_inner[depth]);
3098 sgmlCloseTag(ofs, depth + command_depth,
3099 environment_stack[depth]);
3103 for(int j = command_depth; j >= command_base; --j)
3104 if(!command_stack[j].empty())
3105 sgmlCloseTag(ofs, j, command_stack[j]);
3108 sgmlCloseTag(ofs, 0, top_element);
3111 // How to check for successful close
3115 void Buffer::SimpleDocBookOnePar(ostream & os, string & extra,
3116 LyXParagraph * par, int & desc_on,
3120 par->SimpleDocBookOneTablePar(os, extra, desc_on, depth);
3124 bool emph_flag = false;
3126 LyXLayout const & style = textclasslist.Style(params.textclass,
3129 LyXParagraph::size_type main_body;
3130 if (style.labeltype != LABEL_MANUAL)
3133 main_body = par->BeginningOfMainBody();
3135 // gets paragraph main font
3136 //if (main_body > 0)
3137 // font1 = style.labelfont;
3139 // font1 = style.font;
3140 LyXFont font1 = main_body > 0 ? style.labelfont : style.font;
3142 int char_line_count = depth;
3143 if(!style.free_spacing)
3144 for (int j = 0; j < depth; ++j)
3147 // parsing main loop
3148 for (LyXParagraph::size_type i = 0;
3149 i < par->size(); ++i) {
3150 LyXFont font2 = par->getFont(i);
3152 // handle <emphasis> tag
3153 if (font1.emph() != font2.emph() && i) {
3154 if (font2.emph() == LyXFont::ON) {
3158 os << "</emphasis>";
3163 char c = par->GetChar(i);
3165 if (c == LyXParagraph::META_INSET) {
3166 Inset * inset = par->GetInset(i);
3168 std::ostringstream ost;
3169 inset->DocBook(ost);
3170 string tmp_out = ost.str().c_str();
3173 inset->DocBook(ost);
3175 char * ctmp = ost.str();
3176 string tmp_out(ctmp);
3180 // This code needs some explanation:
3181 // Two insets are treated specially
3182 // label if it is the first element in a command paragraph
3184 // graphics inside tables or figure floats can't go on
3185 // title (the equivalente in latex for this case is caption
3186 // and title should come first
3189 if(desc_on!= 3 || i!= 0) {
3190 if(!tmp_out.empty() && tmp_out[0] == '@') {
3192 extra += frontStrip(tmp_out, '@');
3194 os << frontStrip(tmp_out, '@');
3199 } else if (font2.latex() == LyXFont::ON) {
3200 // "TeX"-Mode on ==> SGML-Mode on.
3207 if (par->linuxDocConvertChar(c, sgml_string)
3208 && !style.free_spacing) { // in freespacing
3210 // non-breaking characters
3214 os << "\n</term><listitem><para>";
3228 /* needed if there is an optional argument but no contents */
3229 if (main_body > 0 && main_body == par->size()) {
3233 os << "</emphasis>";
3236 /* resets description flag correctly */
3239 /* <term> not closed... */
3247 int Buffer::runLaTeX()
3249 if (!users->text) return 0;
3251 ProhibitInput(users);
3253 // get LaTeX-Filename
3254 string name = getLatexName();
3256 string path = OnlyPath(filename);
3258 string org_path = path;
3259 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3263 Path p(path); // path to LaTeX file
3264 users->owner()->getMiniBuffer()->Set(_("Running LaTeX..."));
3266 // Remove all error insets
3267 bool a = users->removeAutoInsets();
3269 // Always generate the LaTeX file
3270 makeLaTeXFile(name, org_path, false);
3273 // do the LaTex run(s)
3275 string latex_command = lyxrc.pdf_mode ?
3276 lyxrc.pdflatex_command : lyxrc.latex_command;
3277 LaTeX latex(latex_command, name, filepath);
3278 int res = latex.run(terr,
3279 users->owner()->getMiniBuffer()); // running latex
3281 // check return value from latex.run().
3282 if ((res & LaTeX::NO_LOGFILE)) {
3283 WriteAlert(_("LaTeX did not work!"),
3284 _("Missing log file:"), name);
3285 } else if ((res & LaTeX::ERRORS)) {
3286 users->owner()->getMiniBuffer()->Set(_("Done"));
3287 // Insert all errors as errors boxes
3288 users->insertErrors(terr);
3290 // Dvi should also be kept dirty if the latex run
3291 // ends up with errors. However it should be possible
3292 // to view a dirty dvi too.
3294 //no errors or any other things to think about so:
3295 users->owner()->getMiniBuffer()->Set(_("Done"));
3299 // if we removed error insets before we ran LaTeX or if we inserted
3300 // error insets after we ran LaTeX this must be run:
3301 if (a || (res & LaTeX::ERRORS)){
3304 users->updateScrollbar();
3308 return latex.getNumErrors();
3312 int Buffer::runLiterate()
3314 if (!users->text) return 0;
3316 ProhibitInput(users);
3318 // get LaTeX-Filename
3319 string name = getLatexName();
3320 // get Literate-Filename
3321 string lit_name = ChangeExtension (getLatexName(),
3322 lyxrc.literate_extension, true);
3324 string path = OnlyPath(filename);
3326 string org_path = path;
3327 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3331 Path p(path); // path to Literate file
3332 users->owner()->getMiniBuffer()->Set(_("Running Literate..."));
3334 // Remove all error insets
3335 bool a = users->removeAutoInsets();
3337 // generate the Literate file if necessary
3338 if (!isDviClean() || a) {
3339 makeLaTeXFile(lit_name, org_path, false);
3343 string latex_command = lyxrc.pdf_mode ?
3344 lyxrc.pdflatex_command : lyxrc.latex_command;
3345 Literate literate(latex_command, name, filepath,
3347 lyxrc.literate_command, lyxrc.literate_error_filter,
3348 lyxrc.build_command, lyxrc.build_error_filter);
3350 int res = literate.weave(terr, users->owner()->getMiniBuffer());
3352 // check return value from literate.weave().
3353 if ((res & Literate::NO_LOGFILE)) {
3354 WriteAlert(_("Literate command did not work!"),
3355 _("Missing log file:"), name);
3356 } else if ((res & Literate::ERRORS)) {
3357 users->owner()->getMiniBuffer()->Set(_("Done"));
3358 // Insert all errors as errors boxes
3359 users->insertErrors(terr);
3361 // Dvi should also be kept dirty if the latex run
3362 // ends up with errors. However it should be possible
3363 // to view a dirty dvi too.
3365 //no errors or any other things to think about so:
3366 users->owner()->getMiniBuffer()->Set(_("Done"));
3370 // if we removed error insets before we ran LaTeX or if we inserted
3371 // error insets after we ran LaTeX this must be run:
3372 if (a || (res & Literate::ERRORS)){
3375 users->updateScrollbar();
3379 return literate.getNumErrors();
3383 int Buffer::buildProgram()
3385 if (!users->text) return 0;
3387 ProhibitInput(users);
3389 // get LaTeX-Filename
3390 string name = getLatexName();
3391 // get Literate-Filename
3392 string lit_name = ChangeExtension(getLatexName(),
3393 lyxrc.literate_extension, true);
3395 string path = OnlyPath(filename);
3397 string org_path = path;
3398 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3402 Path p(path); // path to Literate file
3403 users->owner()->getMiniBuffer()->Set(_("Building Program..."));
3405 // Remove all error insets
3406 bool a = users->removeAutoInsets();
3408 // generate the LaTeX file if necessary
3409 if (!isNwClean() || a) {
3410 makeLaTeXFile(lit_name, org_path, false);
3414 string latex_command = lyxrc.pdf_mode ?
3415 lyxrc.pdflatex_command : lyxrc.latex_command;
3416 Literate literate(latex_command, name, filepath,
3418 lyxrc.literate_command, lyxrc.literate_error_filter,
3419 lyxrc.build_command, lyxrc.build_error_filter);
3421 int res = literate.build(terr, users->owner()->getMiniBuffer());
3423 // check return value from literate.build().
3424 if ((res & Literate::NO_LOGFILE)) {
3425 WriteAlert(_("Build did not work!"),
3426 _("Missing log file:"), name);
3427 } else if ((res & Literate::ERRORS)) {
3428 users->owner()->getMiniBuffer()->Set(_("Done"));
3429 // Insert all errors as errors boxes
3430 users->insertErrors(terr);
3432 // Literate files should also be kept dirty if the literate
3433 // command run ends up with errors.
3435 //no errors or any other things to think about so:
3436 users->owner()->getMiniBuffer()->Set(_("Done"));
3440 // if we removed error insets before we ran Literate/Build or if we inserted
3441 // error insets after we ran Literate/Build this must be run:
3442 if (a || (res & Literate::ERRORS)){
3445 users->updateScrollbar();
3449 return literate.getNumErrors();
3453 // This should be enabled when the Chktex class is implemented. (Asger)
3454 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
3455 // Other flags: -wall -v0 -x
3456 int Buffer::runChktex()
3458 if (!users->text) return 0;
3460 ProhibitInput(users);
3462 // get LaTeX-Filename
3463 string name = getLatexName();
3464 string path = OnlyPath(filename);
3466 string org_path = path;
3467 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3471 Path p(path); // path to LaTeX file
3472 users->owner()->getMiniBuffer()->Set(_("Running chktex..."));
3474 // Remove all error insets
3475 bool a = users->removeAutoInsets();
3477 // Generate the LaTeX file if neccessary
3478 if (!isDviClean() || a) {
3479 makeLaTeXFile(name, org_path, false);
3484 Chktex chktex(lyxrc.chktex_command, name, filepath);
3485 int res = chktex.run(terr); // run chktex
3488 WriteAlert(_("chktex did not work!"),
3489 _("Could not run with file:"), name);
3490 } else if (res > 0) {
3491 // Insert all errors as errors boxes
3492 users->insertErrors(terr);
3495 // if we removed error insets before we ran chktex or if we inserted
3496 // error insets after we ran chktex, this must be run:
3500 users->updateScrollbar();
3509 void Buffer::RoffAsciiTable(ostream & os, LyXParagraph * par)
3511 LyXFont font1(LyXFont::ALL_INHERIT,params.language_info);
3514 LyXParagraph::size_type i;
3518 string fname1 = TmpFileName(string(), "RAT1");
3519 string fname2 = TmpFileName(string(), "RAT2");
3521 ofstream ofs(fname1.c_str());
3523 WriteAlert(_("LYX_ERROR:"),
3524 _("Cannot open temporary file:"), fname1);
3527 par->table->RoffEndOfCell(ofs, -1);
3528 for (i = 0; i < par->size(); ++i) {
3529 c = par->GetChar(i);
3530 if (par->table->IsContRow(cell)) {
3531 if (c == LyXParagraph::META_NEWLINE)
3535 font2 = par->GetFontSettings(i);
3536 if (font1.latex() != font2.latex()) {
3537 if (font2.latex() != LyXFont::OFF)
3541 case LyXParagraph::META_INSET:
3542 if ((inset = par->GetInset(i))) {
3545 stringstresm ss(ios::in | ios::out);
3546 inset->Latex(ss, -1);
3558 inset->Latex(ss, -1);
3571 fstream fs(fname2.c_str(), ios::in|ios::out);
3573 WriteAlert(_("LYX_ERROR:"),
3574 _("Cannot open temporary file:"), fname2);
3576 remove(fname1.c_str());
3579 inset->Latex(fs, -1);
3593 case LyXParagraph::META_NEWLINE:
3594 if (par->table->CellHasContRow(cell)>= 0)
3595 par->RoffContTableRows(ofs, i+1, cell);
3596 par->table->RoffEndOfCell(ofs, cell);
3599 case LyXParagraph::META_HFILL:
3602 case LyXParagraph::META_PROTECTED_SEPARATOR:
3613 << "RoffAsciiTable:"
3614 " NULL char in structure." << endl;
3618 par->table->RoffEndOfCell(ofs, cell);
3620 string cmd = lyxrc.ascii_roff_command + " >" + fname2;
3621 cmd = subst(cmd, "$$FName", fname1);
3622 Systemcalls one(Systemcalls::System, cmd);
3623 if (!(lyxerr.debugging(Debug::ROFF))) {
3624 remove(fname1.c_str());
3626 ifstream ifs(fname2.c_str());
3628 WriteFSAlert(_("Error! Can't open temporary file:"), fname2);
3631 // now output the produced file
3635 WriteAlert(_("Error!"),
3636 _("Error executing *roff command on table"));
3637 // overread leading blank lines
3638 while(!ifs && (c == '\n'))
3641 for(j = 0; j < par->depth; ++j)
3643 while(!ifs && (c != '\n')) {
3648 // overread trailing blank lines
3649 while(!ifs && (c == '\n'))
3653 remove(fname2.c_str());
3658 /// changed Heinrich Bauer, 23/03/98
3659 bool Buffer::isDviClean() const
3661 if (lyxrc.use_tempdir)
3662 return dvi_clean_tmpd;
3664 return dvi_clean_orgd;
3668 /// changed Heinrich Bauer, 23/03/98
3669 void Buffer::markDviClean()
3671 if (lyxrc.use_tempdir)
3672 dvi_clean_tmpd = true;
3674 dvi_clean_orgd = true;
3678 /// changed Heinrich Bauer, 23/03/98
3679 void Buffer::markDviDirty()
3681 if (lyxrc.use_tempdir)
3682 dvi_clean_tmpd = false;
3684 dvi_clean_orgd = false;
3688 void Buffer::validate(LaTeXFeatures & features) const
3690 LyXParagraph * par = paragraph;
3691 LyXTextClass const & tclass =
3692 textclasslist.TextClass(params.textclass);
3694 // AMS Style is at document level
3696 features.amsstyle = (params.use_amsmath ||
3697 tclass.provides(LyXTextClass::amsmath));
3700 // We don't use "lyxerr.debug" because of speed. (Asger)
3701 if (lyxerr.debugging(Debug::LATEX))
3702 lyxerr << "Paragraph: " << par << endl;
3704 // Now just follow the list of paragraphs and run
3705 // validate on each of them.
3706 par->validate(features);
3708 // and then the next paragraph
3712 // the bullet shapes are buffer level not paragraph level
3713 // so they are tested here
3714 for (int i = 0; i < 4; ++i) {
3715 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
3716 int font = params.user_defined_bullets[i].getFont();
3719 .user_defined_bullets[i]
3726 features.latexsym = true;
3730 features.amssymb = true;
3732 else if ((font >= 2 && font <= 5)) {
3733 features.pifont = true;
3738 if (lyxerr.debugging(Debug::LATEX)) {
3739 features.showStruct();
3744 void Buffer::setPaperStuff()
3746 params.papersize = BufferParams::PAPER_DEFAULT;
3747 char c1 = params.paperpackage;
3748 if (c1 == BufferParams::PACKAGE_NONE) {
3749 char c2 = params.papersize2;
3750 if (c2 == BufferParams::VM_PAPER_USLETTER)
3751 params.papersize = BufferParams::PAPER_USLETTER;
3752 else if (c2 == BufferParams::VM_PAPER_USLEGAL)
3753 params.papersize = BufferParams::PAPER_LEGALPAPER;
3754 else if (c2 == BufferParams::VM_PAPER_USEXECUTIVE)
3755 params.papersize = BufferParams::PAPER_EXECUTIVEPAPER;
3756 else if (c2 == BufferParams::VM_PAPER_A3)
3757 params.papersize = BufferParams::PAPER_A3PAPER;
3758 else if (c2 == BufferParams::VM_PAPER_A4)
3759 params.papersize = BufferParams::PAPER_A4PAPER;
3760 else if (c2 == BufferParams::VM_PAPER_A5)
3761 params.papersize = BufferParams::PAPER_A5PAPER;
3762 else if ((c2 == BufferParams::VM_PAPER_B3) || (c2 == BufferParams::VM_PAPER_B4) ||
3763 (c2 == BufferParams::VM_PAPER_B5))
3764 params.papersize = BufferParams::PAPER_B5PAPER;
3765 } else if ((c1 == BufferParams::PACKAGE_A4) || (c1 == BufferParams::PACKAGE_A4WIDE) ||
3766 (c1 == BufferParams::PACKAGE_WIDEMARGINSA4))
3767 params.papersize = BufferParams::PAPER_A4PAPER;
3771 // This function should be in Buffer because it's a buffer's property (ale)
3772 string Buffer::getIncludeonlyList(char delim)
3775 LyXParagraph * par = paragraph;
3776 LyXParagraph::size_type pos;
3780 while ((inset = par->ReturnNextInsetPointer(pos))){
3781 if (inset->LyxCode() == Inset::INCLUDE_CODE) {
3782 InsetInclude * insetinc =
3783 static_cast<InsetInclude*>(inset);
3784 if (insetinc->isInclude()
3785 && insetinc->isNoLoad()) {
3788 lst += ChangeExtension(insetinc->getContents(), string(), true);
3795 lyxerr.debug() << "Includeonly(" << lst << ')' << endl;
3800 // This is also a buffer property (ale)
3801 string Buffer::getReferenceList(char delim)
3803 /// if this is a child document and the parent is already loaded
3804 /// Use the parent's list instead [ale990407]
3805 if (!params.parentname.empty()
3806 && bufferlist.exists(params.parentname)) {
3807 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3809 return tmp->getReferenceList(delim);
3812 LyXParagraph * par = paragraph;
3813 LyXParagraph::size_type pos;
3818 while ((inset = par->ReturnNextInsetPointer(pos))){
3819 for (int i = 0; i < inset->GetNumberOfLabels(); ++i) {
3822 lst += inset->getLabel(i);
3828 lyxerr.debug() << "References(" << lst << ")" << endl;
3833 // This is also a buffer property (ale)
3834 string Buffer::getBibkeyList(char delim)
3836 /// if this is a child document and the parent is already loaded
3837 /// Use the parent's list instead [ale990412]
3838 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3839 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3841 return tmp->getBibkeyList(delim);
3845 LyXParagraph * par = paragraph;
3848 if (!bibkeys.empty())
3850 bibkeys += par->bibkey->getContents();
3855 // Might be either using bibtex or a child has bibliography
3856 if (bibkeys.empty()) {
3860 LyXParagraph::size_type pos = -1;
3862 // Search for Bibtex or Include inset
3863 while ((inset = par->ReturnNextInsetPointer(pos))) {
3864 if (inset-> LyxCode() == Inset::BIBTEX_CODE) {
3865 if (!bibkeys.empty())
3867 bibkeys += static_cast<InsetBibtex*>(inset)->getKeys(delim);
3868 } else if (inset-> LyxCode() == Inset::INCLUDE_CODE) {
3869 string bk = static_cast<InsetInclude*>(inset)->getKeys(delim);
3871 if (!bibkeys.empty())
3882 lyxerr.debug() << "Bibkeys(" << bibkeys << ")" << endl;
3887 bool Buffer::isDepClean(string const & name) const
3889 DEPCLEAN * item = dep_clean;
3890 while (item && item->master != name)
3892 if (!item) return true;
3897 void Buffer::markDepClean(string const & name)
3900 dep_clean = new DEPCLEAN;
3901 dep_clean->clean = true;
3902 dep_clean->master = name;
3903 dep_clean->next = 0;
3905 DEPCLEAN* item = dep_clean;
3906 while (item && item->master != name)
3911 item = new DEPCLEAN;
3913 item->master = name;
3920 void Buffer::Dispatch(string const & command)
3922 // Split command string into command and argument
3923 string cmd, line = frontStrip(command);
3924 string arg = strip(frontStrip(split(line, cmd, ' ')));
3926 Dispatch(lyxaction.LookupFunc(cmd.c_str()), arg.c_str());
3930 void Buffer::Dispatch(int action, string const & argument)
3934 MenuExport(this, argument);
3938 lyxerr << "A truly unknown func!" << endl;
3944 void Buffer::ChangeLanguage(Language const * from, Language const * to)
3947 LyXParagraph * par = paragraph;
3949 par->ChangeLanguage(from,to);
3954 bool Buffer::isMultiLingual()
3957 LyXParagraph * par = paragraph;
3959 if (par->isMultiLingual())