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, true, free_spc);
1432 h += ost.str().length();
1435 inset->Latex(ost, true, 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, true, 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, true, 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:
1598 if (currlinelen > linelen - 10
1599 && c == ' ' && i + 2 < par->size()) {
1601 for(j = 0; j < depth; ++j)
1603 currlinelen = depth * 2;
1604 if (ltype_depth > depth) {
1605 for(j = ltype_depth;
1608 currlinelen += (ltype_depth-depth)*2;
1610 } else if (c != '\0')
1613 lyxerr.debug() << "writeAsciiFile: NULL char in structure." << endl;
1619 for(j = actpos; j < clen[cell - 1]; ++j)
1622 for(j = 0; j < depth; ++j)
1624 currlinelen = depth * 2;
1625 if (ltype_depth > depth) {
1626 for(j = ltype_depth; j > depth; --j)
1628 currlinelen += (ltype_depth - depth) * 2;
1630 for(j = 0; j < cells; ++j) {
1632 for(h = 0; h < (clen[j] + 1); ++h)
1645 void Buffer::makeLaTeXFile(string const & fname,
1646 string const & original_path,
1647 bool nice, bool only_body)
1649 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
1651 niceFile = nice; // this will be used by Insetincludes.
1653 tex_code_break_column = lyxrc.ascii_linelen;
1655 LyXTextClass const & tclass =
1656 textclasslist.TextClass(params.textclass);
1658 ofstream ofs(fname.c_str());
1660 WriteFSAlert(_("Error: Cannot open file: "), fname);
1664 // validate the buffer.
1665 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
1666 LaTeXFeatures features(params, tclass.numLayouts());
1668 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
1671 // The starting paragraph of the coming rows is the
1672 // first paragraph of the document. (Asger)
1673 texrow.start(paragraph, 0);
1675 if (!only_body && nice) {
1676 ofs << "%% " LYX_DOCVERSION " created this file. "
1677 "For more info, see http://www.lyx.org/.\n"
1678 "%% Do not edit unless you really know what "
1683 lyxerr.debug() << "lyx header finished" << endl;
1684 // There are a few differences between nice LaTeX and usual files:
1685 // usual is \batchmode and has a
1686 // special input@path to allow the including of figures
1687 // with either \input or \includegraphics (what figinsets do).
1688 // batchmode is not set if there is a tex_code_break_column.
1689 // In this case somebody is interested in the generated LaTeX,
1690 // so this is OK. input@path is set when the actual parameter
1691 // original_path is set. This is done for usual tex-file, but not
1692 // for nice-latex-file. (Matthias 250696)
1695 // code for usual, NOT nice-latex-file
1696 ofs << "\\batchmode\n"; // changed
1697 // from \nonstopmode
1700 if (!original_path.empty()) {
1701 ofs << "\\makeatletter\n"
1702 << "\\def\\input@path{{"
1703 << original_path << "/}}\n"
1704 << "\\makeatother\n";
1710 ofs << "\\documentclass";
1712 string options; // the document class options.
1714 if (tokenPos(tclass.opt_fontsize(), '|', params.fontsize) >= 0) {
1715 // only write if existing in list (and not default)
1716 options += params.fontsize;
1721 if (!params.use_geometry &&
1722 (params.paperpackage == BufferParams::PACKAGE_NONE)) {
1723 switch (params.papersize) {
1724 case BufferParams::PAPER_A4PAPER:
1725 options += "a4paper,";
1727 case BufferParams::PAPER_USLETTER:
1728 options += "letterpaper,";
1730 case BufferParams::PAPER_A5PAPER:
1731 options += "a5paper,";
1733 case BufferParams::PAPER_B5PAPER:
1734 options += "b5paper,";
1736 case BufferParams::PAPER_EXECUTIVEPAPER:
1737 options += "executivepaper,";
1739 case BufferParams::PAPER_LEGALPAPER:
1740 options += "legalpaper,";
1746 if (params.sides != tclass.sides()) {
1747 switch (params.sides) {
1748 case LyXTextClass::OneSide:
1749 options += "oneside,";
1751 case LyXTextClass::TwoSides:
1752 options += "twoside,";
1759 if (params.columns != tclass.columns()) {
1760 if (params.columns == 2)
1761 options += "twocolumn,";
1763 options += "onecolumn,";
1766 if (!params.use_geometry
1767 && params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1768 options += "landscape,";
1770 // language should be a parameter to \documentclass
1771 bool use_babel = false;
1772 if (params.language != "default" ||
1773 !features.UsedLanguages.empty() ) {
1775 for (LaTeXFeatures::LanguageList::const_iterator cit =
1776 features.UsedLanguages.begin();
1777 cit != features.UsedLanguages.end(); ++cit) {
1778 options += (*cit)->lang + ",";
1780 if (default_language != params.language_info)
1781 options += default_language ->lang + ',';
1782 options += params.language_info->lang + ',';
1785 // the user-defined options
1786 if (!params.options.empty()) {
1787 options += params.options + ',';
1790 if (!options.empty()){
1791 options = strip(options, ',');
1792 ofs << '[' << options << ']';
1796 << textclasslist.LatexnameOfClass(params.textclass)
1799 // end of \documentclass defs
1801 // font selection must be done before loading fontenc.sty
1802 if (params.fonts != "default") {
1803 ofs << "\\usepackage{" << params.fonts << "}\n";
1806 // this one is not per buffer
1807 if (lyxrc.fontenc != "default") {
1808 ofs << "\\usepackage[" << lyxrc.fontenc
1812 if (params.inputenc != "default") {
1813 ofs << "\\usepackage[" << params.inputenc
1818 /* at the very beginning the text parameters */
1819 if (params.paperpackage != BufferParams::PACKAGE_NONE) {
1820 switch (params.paperpackage) {
1821 case BufferParams::PACKAGE_A4:
1822 ofs << "\\usepackage{a4}\n";
1825 case BufferParams::PACKAGE_A4WIDE:
1826 ofs << "\\usepackage{a4wide}\n";
1829 case BufferParams::PACKAGE_WIDEMARGINSA4:
1830 ofs << "\\usepackage[widemargins]{a4}\n";
1835 if (params.use_geometry) {
1836 ofs << "\\usepackage{geometry}\n";
1838 ofs << "\\geometry{verbose";
1839 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1840 ofs << ",landscape";
1841 switch (params.papersize2) {
1842 case BufferParams::VM_PAPER_CUSTOM:
1843 if (!params.paperwidth.empty())
1844 ofs << ",paperwidth="
1845 << params.paperwidth;
1846 if (!params.paperheight.empty())
1847 ofs << ",paperheight="
1848 << params.paperheight;
1850 case BufferParams::VM_PAPER_USLETTER:
1851 ofs << ",letterpaper";
1853 case BufferParams::VM_PAPER_USLEGAL:
1854 ofs << ",legalpaper";
1856 case BufferParams::VM_PAPER_USEXECUTIVE:
1857 ofs << ",executivepaper";
1859 case BufferParams::VM_PAPER_A3:
1862 case BufferParams::VM_PAPER_A4:
1865 case BufferParams::VM_PAPER_A5:
1868 case BufferParams::VM_PAPER_B3:
1871 case BufferParams::VM_PAPER_B4:
1874 case BufferParams::VM_PAPER_B5:
1878 // default papersize ie BufferParams::VM_PAPER_DEFAULT
1879 switch (lyxrc.default_papersize) {
1880 case BufferParams::PAPER_DEFAULT: // keep compiler happy
1881 case BufferParams::PAPER_USLETTER:
1882 ofs << ",letterpaper";
1884 case BufferParams::PAPER_LEGALPAPER:
1885 ofs << ",legalpaper";
1887 case BufferParams::PAPER_EXECUTIVEPAPER:
1888 ofs << ",executivepaper";
1890 case BufferParams::PAPER_A3PAPER:
1893 case BufferParams::PAPER_A4PAPER:
1896 case BufferParams::PAPER_A5PAPER:
1899 case BufferParams::PAPER_B5PAPER:
1904 if (!params.topmargin.empty())
1905 ofs << ",tmargin=" << params.topmargin;
1906 if (!params.bottommargin.empty())
1907 ofs << ",bmargin=" << params.bottommargin;
1908 if (!params.leftmargin.empty())
1909 ofs << ",lmargin=" << params.leftmargin;
1910 if (!params.rightmargin.empty())
1911 ofs << ",rmargin=" << params.rightmargin;
1912 if (!params.headheight.empty())
1913 ofs << ",headheight=" << params.headheight;
1914 if (!params.headsep.empty())
1915 ofs << ",headsep=" << params.headsep;
1916 if (!params.footskip.empty())
1917 ofs << ",footskip=" << params.footskip;
1921 if (params.use_amsmath
1922 && !prefixIs(textclasslist.LatexnameOfClass(params.textclass), "ams")) {
1923 ofs << "\\usepackage{amsmath}\n";
1927 if (tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle) >= 0) {
1928 if (params.pagestyle == "fancy") {
1929 ofs << "\\usepackage{fancyhdr}\n";
1932 ofs << "\\pagestyle{" << params.pagestyle << "}\n";
1936 // We try to load babel late, in case it interferes
1937 // with other packages.
1939 ofs << lyxrc.language_package << endl;
1943 if (params.secnumdepth != tclass.secnumdepth()) {
1944 ofs << "\\setcounter{secnumdepth}{"
1945 << params.secnumdepth
1949 if (params.tocdepth != tclass.tocdepth()) {
1950 ofs << "\\setcounter{tocdepth}{"
1956 if (params.paragraph_separation) {
1957 switch (params.defskip.kind()) {
1958 case VSpace::SMALLSKIP:
1959 ofs << "\\setlength\\parskip{\\smallskipamount}\n";
1961 case VSpace::MEDSKIP:
1962 ofs << "\\setlength\\parskip{\\medskipamount}\n";
1964 case VSpace::BIGSKIP:
1965 ofs << "\\setlength\\parskip{\\bigskipamount}\n";
1967 case VSpace::LENGTH:
1968 ofs << "\\setlength\\parskip{"
1969 << params.defskip.length().asLatexString()
1972 default: // should never happen // Then delete it.
1973 ofs << "\\setlength\\parskip{\\medskipamount}\n";
1978 ofs << "\\setlength\\parindent{0pt}\n";
1982 // Now insert the LyX specific LaTeX commands...
1983 string preamble, tmppreamble;
1985 // The optional packages;
1986 preamble = features.getPackages();
1988 // this might be useful...
1989 preamble += "\n\\makeatletter\n\n";
1991 // Some macros LyX will need
1992 tmppreamble = features.getMacros();
1994 if (!tmppreamble.empty()) {
1995 preamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1996 "LyX specific LaTeX commands.\n"
1997 + tmppreamble + '\n';
2000 // the text class specific preamble
2001 tmppreamble = features.getTClassPreamble();
2002 if (!tmppreamble.empty()) {
2003 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2004 "Textclass specific LaTeX commands.\n"
2005 + tmppreamble + '\n';
2008 /* the user-defined preamble */
2009 if (!params.preamble.empty()) {
2010 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2011 "User specified LaTeX commands.\n"
2012 + params.preamble + '\n';
2015 preamble += "\\makeatother\n\n";
2017 // Itemize bullet settings need to be last in case the user
2018 // defines their own bullets that use a package included
2019 // in the user-defined preamble -- ARRae
2020 // Actually it has to be done much later than that
2021 // since some packages like frenchb make modifications
2022 // at \begin{document} time -- JMarc
2024 for (int i = 0; i < 4; ++i) {
2025 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
2026 if (bullets_def.empty())
2027 bullets_def="\\AtBeginDocument{\n";
2028 bullets_def += " \\renewcommand{\\labelitemi";
2030 // `i' is one less than the item to modify
2037 bullets_def += "ii";
2043 bullets_def += "}{" +
2044 params.user_defined_bullets[i].getText()
2049 if (!bullets_def.empty())
2050 preamble += bullets_def + "}\n\n";
2052 for (int j = countChar(preamble, '\n'); j-- ;) {
2059 ofs << "\\begin{document}\n\n";
2063 lyxerr.debug() << "preamble finished, now the body." << endl;
2064 if (!lyxrc.language_auto_begin && params.language != "default") {
2065 ofs << subst(lyxrc.language_command_begin, "$$lang",
2071 bool was_title = false;
2072 bool already_title = false;
2074 std::ostringstream ftnote;
2076 char * tmpholder = 0;
2081 LyXParagraph * par = paragraph;
2085 #ifndef HAVE_SSTREAM
2088 ftnote << tmpholder;
2089 delete [] tmpholder;
2094 lyxerr[Debug::LATEX] << "Error in MakeLateXFile."
2096 LyXLayout const & layout =
2097 textclasslist.Style(params.textclass,
2100 if (layout.intitle) {
2101 if (already_title) {
2102 lyxerr <<"Error in MakeLatexFile: You"
2103 " should not mix title layouts"
2104 " with normal ones." << endl;
2107 } else if (was_title && !already_title) {
2108 ofs << "\\maketitle\n";
2110 already_title = true;
2113 // We are at depth 0 so we can just use
2114 // ordinary \footnote{} generation
2115 // flag this with ftcount
2117 if (layout.isEnvironment()
2118 || par->pextra_type != LyXParagraph::PEXTRA_NONE) {
2119 par = par->TeXEnvironment(ofs, texrow,
2120 ftnote, ft_texrow, ftcount);
2122 par = par->TeXOnePar(ofs, texrow,
2123 ftnote, ft_texrow, ftcount);
2126 // Write out what we've generated...
2129 ofs << "\\addtocounter{footnote}{-"
2133 ofs << ftnote.str();
2134 texrow += ft_texrow;
2136 // The extra .c_str() is needed when we use
2137 // lyxstring instead of the STL string class.
2138 ftnote.str(string().c_str());
2140 delete [] ftnote.str();
2145 #ifndef HAVE_SSTREAM
2147 // I hate strstreams
2148 tmpholder = ftnote.str();
2152 #ifndef HAVE_SSTREAM
2153 delete [] tmpholder;
2155 // It might be that we only have a title in this document
2156 if (was_title && !already_title) {
2157 ofs << "\\maketitle\n";
2161 if (!lyxrc.language_auto_end && params.language != "default") {
2162 ofs << subst(lyxrc.language_command_end, "$$lang",
2169 ofs << "\\end{document}\n";
2172 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
2174 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
2178 // Just to be sure. (Asger)
2181 // tex_code_break_column's value is used to decide
2182 // if we are in batchmode or not (within mathed_write()
2183 // in math_write.C) so we must set it to a non-zero
2184 // value when we leave otherwise we save incorrect .lyx files.
2185 tex_code_break_column = lyxrc.ascii_linelen;
2189 lyxerr << "File was not closed properly." << endl;
2192 lyxerr.debug() << "Finished making latex file." << endl;
2196 bool Buffer::isLatex() const
2198 return textclasslist.TextClass(params.textclass).outputType() == LATEX;
2202 bool Buffer::isLinuxDoc() const
2204 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC;
2208 bool Buffer::isLiterate() const
2210 return textclasslist.TextClass(params.textclass).outputType() == LITERATE;
2214 bool Buffer::isDocBook() const
2216 return textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2220 bool Buffer::isSGML() const
2222 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC ||
2223 textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2227 void Buffer::sgmlOpenTag(ostream & os, int depth,
2228 string const & latexname) const
2230 os << string(depth, ' ') << "<" << latexname << ">\n";
2234 void Buffer::sgmlCloseTag(ostream & os, int depth,
2235 string const & latexname) const
2237 os << string(depth, ' ') << "</" << latexname << ">\n";
2241 void Buffer::makeLinuxDocFile(string const & fname, int column)
2243 LyXParagraph * par = paragraph;
2245 string top_element = textclasslist.LatexnameOfClass(params.textclass);
2246 string environment_stack[10];
2249 int depth = 0; /* paragraph depth */
2251 ofstream ofs(fname.c_str());
2254 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2258 tex_code_break_column = column;
2261 if (params.preamble.empty()) {
2262 ofs << "<!doctype linuxdoc system>\n\n";
2265 ofs << "<!doctype linuxdoc system \n [ "
2266 << params.preamble << " \n]>\n\n";
2269 ofs << "<!-- " << LYX_DOCVERSION
2270 << " created this file. For more info see http://www.lyx.org/"
2273 if(params.options.empty())
2274 sgmlOpenTag(ofs, 0, top_element);
2276 string top = top_element;
2278 top += params.options;
2279 sgmlOpenTag(ofs, 0, top);
2283 int desc_on = 0; /* description mode*/
2284 LyXLayout const & style =
2285 textclasslist.Style(users->buffer()->params.textclass,
2287 par->AutoDeleteInsets();
2289 /* treat <toc> as a special case for compatibility with old code */
2290 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2291 Inset * inset = par->GetInset(0);
2292 char lyx_code = inset->LyxCode();
2293 if (lyx_code == Inset::TOC_CODE){
2294 string temp = "toc";
2295 sgmlOpenTag(ofs, depth, temp);
2298 linuxDocHandleFootnote(ofs, par, depth);
2303 // environment tag closing
2304 for( ; depth > par->depth; --depth) {
2305 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2306 environment_stack[depth].clear();
2309 // write opening SGML tags
2310 switch(style.latextype) {
2311 case LATEX_PARAGRAPH:
2312 if(depth == par->depth
2313 && !environment_stack[depth].empty()) {
2314 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2315 environment_stack[depth].clear();
2321 sgmlOpenTag(ofs, depth, style.latexname());
2326 LinuxDocError(par, 0, _("Error : Wrong depth for LatexType Command.\n"));
2328 if (!environment_stack[depth].empty()){
2329 sgmlCloseTag(ofs, depth,
2330 environment_stack[depth]);
2334 environment_stack[depth].clear();
2335 sgmlOpenTag(ofs, depth, style.latexname());
2338 case LATEX_ENVIRONMENT:
2339 case LATEX_ITEM_ENVIRONMENT:
2340 if(depth == par->depth
2341 && environment_stack[depth] != style.latexname()
2342 && !environment_stack[depth].empty()) {
2344 sgmlCloseTag(ofs, depth,
2345 environment_stack[depth]);
2346 environment_stack[depth].clear();
2348 if (depth < par->depth) {
2350 environment_stack[depth].clear();
2352 if (environment_stack[depth] != style.latexname()) {
2355 sgmlOpenTag(ofs, depth, temp);
2357 environment_stack[depth] = style.latexname();
2358 sgmlOpenTag(ofs, depth, environment_stack[depth]);
2360 if(style.latextype == LATEX_ENVIRONMENT) break;
2362 desc_on = (style.labeltype == LABEL_MANUAL);
2369 sgmlOpenTag(ofs, depth + 1, item_name);
2372 sgmlOpenTag(ofs, depth, style.latexname());
2377 SimpleLinuxDocOnePar(ofs, par, desc_on, depth);
2380 linuxDocHandleFootnote(ofs, par, depth);
2382 while(par && par->IsDummy());
2385 /* write closing SGML tags */
2386 switch(style.latextype) {
2388 case LATEX_ENVIRONMENT:
2389 case LATEX_ITEM_ENVIRONMENT:
2392 sgmlCloseTag(ofs, depth, style.latexname());
2397 /* Close open tags */
2398 for(; depth > 0; --depth)
2399 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2401 if(!environment_stack[depth].empty())
2402 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2405 sgmlCloseTag(ofs, 0, top_element);
2408 // How to check for successful close
2412 void Buffer::linuxDocHandleFootnote(ostream & os, LyXParagraph * & par,
2415 string tag = "footnote";
2417 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2418 sgmlOpenTag(os, depth + 1, tag);
2419 SimpleLinuxDocOnePar(os, par, 0, depth + 1);
2420 sgmlCloseTag(os, depth + 1, tag);
2426 void Buffer::DocBookHandleCaption(ostream & os, string & inner_tag,
2427 int const depth, int desc_on,
2428 LyXParagraph * & par)
2430 LyXParagraph * tpar = par;
2431 while (tpar && (tpar->footnoteflag != LyXParagraph::NO_FOOTNOTE) &&
2432 (tpar->layout != textclasslist.NumberOfLayout(params.textclass,
2436 tpar->layout == textclasslist.NumberOfLayout(params.textclass,
2437 "Caption").second) {
2438 sgmlOpenTag(os, depth + 1, inner_tag);
2440 SimpleDocBookOnePar(os, extra_par, tpar,
2441 desc_on, depth + 2);
2442 sgmlCloseTag(os, depth+1, inner_tag);
2443 if(!extra_par.empty())
2449 void Buffer::DocBookHandleFootnote(ostream & os, LyXParagraph * & par,
2452 string tag, inner_tag;
2453 string tmp_par, extra_par;
2454 bool inner_span = false;
2457 // Someone should give this enum a proper name (Lgb)
2465 SOME_ENUM last = NO_ONE;
2466 SOME_ENUM present = FOOTNOTE_LIKE;
2468 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2469 if(last == present) {
2471 if(!tmp_par.empty()) {
2474 sgmlCloseTag(os, depth + 1, inner_tag);
2475 sgmlOpenTag(os, depth + 1, inner_tag);
2482 if(!inner_tag.empty()) sgmlCloseTag(os, depth + 1,
2484 if(!extra_par.empty()) os << extra_par;
2485 if(!tag.empty()) sgmlCloseTag(os, depth, tag);
2488 switch (par->footnotekind) {
2489 case LyXParagraph::FOOTNOTE:
2490 case LyXParagraph::ALGORITHM:
2493 present = FOOTNOTE_LIKE;
2496 case LyXParagraph::MARGIN:
2499 present = MARGIN_LIKE;
2502 case LyXParagraph::FIG:
2503 case LyXParagraph::WIDE_FIG:
2505 inner_tag = "title";
2509 case LyXParagraph::TAB:
2510 case LyXParagraph::WIDE_TAB:
2512 inner_tag = "title";
2517 sgmlOpenTag(os, depth, tag);
2518 if ((present == TAB_LIKE) || (present == FIG_LIKE)) {
2519 DocBookHandleCaption(os, inner_tag, depth,
2523 sgmlOpenTag(os, depth + 1, inner_tag);
2526 // ignore all caption here, we processed them above!!!
2527 if (par->layout != textclasslist
2528 .NumberOfLayout(params.textclass,
2529 "Caption").second) {
2531 std::ostringstream ost;
2535 SimpleDocBookOnePar(ost, extra_par, par,
2536 desc_on, depth + 2);
2538 tmp_par += ost.str().c_str();
2541 char * ctmp = ost.str();
2546 tmp_par = frontStrip(strip(tmp_par));
2552 if(!inner_tag.empty()) sgmlCloseTag(os, depth + 1, inner_tag);
2553 if(!extra_par.empty()) os << extra_par;
2554 if(!tag.empty()) sgmlCloseTag(os, depth, tag);
2558 /* push a tag in a style stack */
2559 void Buffer::push_tag(ostream & os, char const * tag,
2560 int & pos, char stack[5][3])
2562 /* pop all previous tags */
2563 for (int j = pos; j >= 0; --j)
2564 os << "</" << stack[j] << ">";
2567 sprintf(stack[++pos], "%s", tag);
2570 for (int i = 0; i <= pos; ++i)
2571 os << "<" << stack[i] << ">";
2575 void Buffer::pop_tag(ostream & os, char const * tag,
2576 int & pos, char stack[5][3])
2580 // pop all tags till specified one
2581 for (j = pos; (j >= 0) && (strcmp(stack[j], tag)); --j)
2582 os << "</" << stack[j] << ">";
2585 os << "</" << tag << ">";
2587 // push all tags, but the specified one
2588 for (j = j + 1; j <= pos; ++j) {
2589 os << "<" << stack[j] << ">";
2590 strcpy(stack[j-1], stack[j]);
2596 /* handle internal paragraph parsing -- layout already processed */
2598 // checks, if newcol chars should be put into this line
2599 // writes newline, if necessary.
2601 void linux_doc_line_break(ostream & os, unsigned int & colcount,
2602 const unsigned int newcol)
2605 if (colcount > lyxrc.ascii_linelen) {
2607 colcount = newcol; // assume write after this call
2612 void Buffer::SimpleLinuxDocOnePar(ostream & os, LyXParagraph * par,
2613 int desc_on, int const /*depth*/)
2615 LyXFont font1, font2;
2618 LyXParagraph::size_type main_body;
2620 LyXLayout const & style = textclasslist.Style(params.textclass,
2623 char family_type = 0; // family font flag
2624 bool is_bold = false; // series font flag
2625 char shape_type = 0; // shape font flag
2626 bool is_em = false; // emphasis (italic) font flag
2628 int stack_num = -1; // style stack position
2629 char stack[5][3]; // style stack
2630 unsigned int char_line_count = 5; // Heuristic choice ;-)
2632 if (style.labeltype != LABEL_MANUAL)
2635 main_body = par->BeginningOfMainBody();
2637 /* gets paragraph main font */
2639 font1 = style.labelfont;
2644 /* parsing main loop */
2645 for (LyXParagraph::size_type i = 0;
2646 i < par->size(); ++i) {
2648 /* handle quote tag */
2649 if (i == main_body && !par->IsDummy()) {
2654 font2 = par->getFont(i);
2656 if (font1.family() != font2.family()) {
2657 switch(family_type) {
2659 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2660 push_tag(os, "tt", stack_num, stack);
2663 else if (font2.family() == LyXFont::SANS_FAMILY) {
2664 push_tag(os, "sf", stack_num, stack);
2669 pop_tag(os, "tt", stack_num, stack);
2670 if (font2.family() == LyXFont::SANS_FAMILY) {
2671 push_tag(os, "sf", stack_num, stack);
2679 pop_tag(os, "sf", stack_num, stack);
2680 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2681 push_tag(os, "tt", stack_num, stack);
2690 /* handle bold face */
2691 if (font1.series() != font2.series()) {
2692 if (font2.series() == LyXFont::BOLD_SERIES) {
2693 push_tag(os, "bf", stack_num, stack);
2697 pop_tag(os, "bf", stack_num, stack);
2702 /* handle italic and slanted fonts */
2703 if (font1.shape() != font2.shape()) {
2704 switch(shape_type) {
2706 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2707 push_tag(os, "it", stack_num, stack);
2710 else if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2711 push_tag(os, "sl", stack_num, stack);
2716 pop_tag(os, "it", stack_num, stack);
2717 if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2718 push_tag(os, "sl", stack_num, stack);
2726 pop_tag(os, "sl", stack_num, stack);
2727 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2728 push_tag(os, "it", stack_num, stack);
2736 /* handle <em> tag */
2737 if (font1.emph() != font2.emph()) {
2738 if (font2.emph() == LyXFont::ON) {
2739 push_tag(os, "em", stack_num, stack);
2742 pop_tag(os, "em", stack_num, stack);
2747 c = par->GetChar(i);
2749 if (font2.latex() == LyXFont::ON) {
2750 // "TeX"-Mode on == > SGML-Mode on.
2752 os << c; // see LaTeX-Generation...
2754 } else if (c == LyXParagraph::META_INSET) {
2755 inset = par->GetInset(i);
2756 inset->Linuxdoc(os);
2759 if (par->linuxDocConvertChar(c, sgml_string)
2760 && !style.free_spacing) { // in freespacing
2762 // non-breaking characters
2766 linux_doc_line_break(os, char_line_count, 6);
2771 linux_doc_line_break(os, char_line_count, 1);
2777 char_line_count += sgml_string.length();
2783 /* needed if there is an optional argument but no contents */
2784 if (main_body > 0 && main_body == par->size()) {
2788 /* pop all defined Styles */
2789 for (j = stack_num; j >= 0; --j) {
2790 linux_doc_line_break(os,
2792 3 + strlen(stack[j]));
2793 os << "</" << stack[j] << ">";
2796 /* resets description flag correctly */
2799 /* <tag> not closed... */
2800 linux_doc_line_break(os, char_line_count, 6);
2804 /* fprintf(file, "</p>");*/
2810 /* print an error message */
2811 void Buffer::LinuxDocError(LyXParagraph * par, int pos,
2812 char const * message)
2814 InsetError * new_inset;
2816 /* insert an error marker in text */
2817 new_inset = new InsetError(message);
2818 par->InsertChar(pos, LyXParagraph::META_INSET);
2819 par->InsertInset(pos, new_inset);
2822 // This constant defines the maximum number of
2823 // environment layouts that can be nesteded.
2824 // The same applies for command layouts.
2825 // These values should be more than enough.
2826 // José Matos (1999/07/22)
2828 enum { MAX_NEST_LEVEL = 25};
2830 void Buffer::makeDocBookFile(string const & fname, int column)
2832 LyXParagraph * par = paragraph;
2834 string top_element= textclasslist.LatexnameOfClass(params.textclass);
2835 string environment_stack[MAX_NEST_LEVEL];
2836 string environment_inner[MAX_NEST_LEVEL];
2837 string command_stack[MAX_NEST_LEVEL];
2838 bool command_flag= false;
2839 int command_depth= 0, command_base= 0, cmd_depth= 0;
2841 string item_name, command_name;
2842 string c_depth, c_params, tmps;
2844 int depth= 0; /* paragraph depth */
2846 tex_code_break_column = column;
2848 ofstream ofs(fname.c_str());
2850 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2856 ofs << "<!doctype " << top_element
2857 << " public \"-//OASIS//DTD DocBook V3.1//EN\"";
2859 if (params.preamble.empty())
2862 ofs << "\n [ " << params.preamble << " \n]>\n\n";
2864 ofs << "<!-- DocBook file was created by " << LYX_DOCVERSION
2865 << "\n See http://www.lyx.org/ for more information -->\n";
2867 if(params.options.empty())
2868 sgmlOpenTag(ofs, 0, top_element);
2870 string top = top_element;
2872 top += params.options;
2873 sgmlOpenTag(ofs, 0, top);
2877 int desc_on = 0; /* description mode*/
2878 LyXLayout const & style =
2879 textclasslist.Style(users->buffer()->params.textclass,
2881 par->AutoDeleteInsets();
2883 /* environment tag closing */
2884 for( ; depth > par->depth; --depth) {
2885 if(environment_inner[depth] != "!-- --") {
2886 item_name= "listitem";
2887 sgmlCloseTag(ofs, command_depth + depth,
2889 if( environment_inner[depth] == "varlistentry")
2890 sgmlCloseTag(ofs, depth+command_depth,
2891 environment_inner[depth]);
2893 sgmlCloseTag(ofs, depth + command_depth,
2894 environment_stack[depth]);
2895 environment_stack[depth].clear();
2896 environment_inner[depth].clear();
2899 if(depth == par->depth
2900 && environment_stack[depth] != style.latexname()
2901 && !environment_stack[depth].empty()) {
2902 if(environment_inner[depth] != "!-- --") {
2903 item_name= "listitem";
2904 sgmlCloseTag(ofs, command_depth+depth,
2906 if( environment_inner[depth] == "varlistentry")
2908 depth + command_depth,
2909 environment_inner[depth]);
2912 sgmlCloseTag(ofs, depth + command_depth,
2913 environment_stack[depth]);
2915 environment_stack[depth].clear();
2916 environment_inner[depth].clear();
2919 // Write opening SGML tags.
2920 switch(style.latextype) {
2921 case LATEX_PARAGRAPH:
2922 if(style.latexname() != "dummy")
2923 sgmlOpenTag(ofs, depth+command_depth,
2929 LinuxDocError(par, 0,
2930 _("Error : Wrong depth for "
2931 "LatexType Command.\n"));
2933 command_name = style.latexname();
2935 tmps = style.latexparam();
2936 c_params = split(tmps, c_depth,'|');
2938 cmd_depth= atoi(c_depth.c_str());
2941 if(cmd_depth<command_base) {
2942 for(int j = command_depth;
2943 j >= command_base; --j)
2944 if(!command_stack[j].empty())
2945 sgmlCloseTag(ofs, j, command_stack[j]);
2946 command_depth= command_base= cmd_depth;
2948 else if(cmd_depth <= command_depth) {
2949 for(int j = command_depth;
2950 j >= cmd_depth; --j)
2952 if(!command_stack[j].empty())
2953 sgmlCloseTag(ofs, j, command_stack[j]);
2954 command_depth= cmd_depth;
2957 command_depth= cmd_depth;
2960 command_depth = command_base = cmd_depth;
2961 command_flag = true;
2963 command_stack[command_depth]= command_name;
2965 // treat label as a special case for
2966 // more WYSIWYM handling.
2967 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2968 Inset * inset = par->GetInset(0);
2969 char lyx_code = inset->LyxCode();
2970 if (lyx_code == Inset::LABEL_CODE){
2971 command_name += " id=\"";
2972 command_name += (static_cast<InsetCommand *>(inset))->getContents();
2973 command_name += "\"";
2978 sgmlOpenTag(ofs, depth+command_depth, command_name);
2979 item_name = "title";
2980 sgmlOpenTag(ofs, depth + 1 + command_depth, item_name);
2983 case LATEX_ENVIRONMENT:
2984 case LATEX_ITEM_ENVIRONMENT:
2985 if (depth < par->depth) {
2987 environment_stack[depth].clear();
2990 if (environment_stack[depth] != style.latexname()) {
2991 environment_stack[depth] = style.latexname();
2992 environment_inner[depth] = "!-- --";
2993 sgmlOpenTag(ofs, depth + command_depth,
2994 environment_stack[depth]);
2996 if(environment_inner[depth] != "!-- --") {
2997 item_name= "listitem";
2999 command_depth + depth,
3001 if (environment_inner[depth] == "varlistentry")
3003 depth + command_depth,
3004 environment_inner[depth]);
3008 if(style.latextype == LATEX_ENVIRONMENT) {
3009 if(!style.latexparam().empty())
3010 sgmlOpenTag(ofs, depth + command_depth,
3011 style.latexparam());
3015 desc_on = (style.labeltype == LABEL_MANUAL);
3018 environment_inner[depth]= "varlistentry";
3020 environment_inner[depth]= "listitem";
3022 sgmlOpenTag(ofs, depth + 1 + command_depth,
3023 environment_inner[depth]);
3027 sgmlOpenTag(ofs, depth + 1 + command_depth,
3032 sgmlOpenTag(ofs, depth + 1 + command_depth,
3037 sgmlOpenTag(ofs, depth + command_depth,
3044 SimpleDocBookOnePar(ofs, extra_par, par, desc_on,
3045 depth + 1 + command_depth);
3047 DocBookHandleFootnote(ofs, par,
3048 depth + 1 + command_depth);
3050 while(par && par->IsDummy());
3053 /* write closing SGML tags */
3054 switch(style.latextype) {
3057 sgmlCloseTag(ofs, depth + command_depth, end_tag);
3059 case LATEX_ENVIRONMENT:
3060 if(!style.latexparam().empty())
3061 sgmlCloseTag(ofs, depth + command_depth,
3062 style.latexparam());
3064 case LATEX_ITEM_ENVIRONMENT:
3065 if(desc_on == 1) break;
3067 sgmlCloseTag(ofs, depth + 1 + command_depth, end_tag);
3069 case LATEX_PARAGRAPH:
3070 if(style.latexname() != "dummy")
3071 sgmlCloseTag(ofs, depth + command_depth,
3075 sgmlCloseTag(ofs, depth + command_depth,
3082 for(; depth >= 0; --depth) {
3083 if(!environment_stack[depth].empty()) {
3084 if(environment_inner[depth] != "!-- --") {
3085 item_name= "listitem";
3086 sgmlCloseTag(ofs, command_depth + depth,
3088 if( environment_inner[depth] == "varlistentry")
3089 sgmlCloseTag(ofs, depth + command_depth,
3090 environment_inner[depth]);
3093 sgmlCloseTag(ofs, depth + command_depth,
3094 environment_stack[depth]);
3098 for(int j = command_depth; j >= command_base; --j)
3099 if(!command_stack[j].empty())
3100 sgmlCloseTag(ofs, j, command_stack[j]);
3103 sgmlCloseTag(ofs, 0, top_element);
3106 // How to check for successful close
3110 void Buffer::SimpleDocBookOnePar(ostream & os, string & extra,
3111 LyXParagraph * par, int & desc_on,
3115 par->SimpleDocBookOneTablePar(os, extra, desc_on, depth);
3119 bool emph_flag = false;
3121 LyXLayout const & style = textclasslist.Style(params.textclass,
3124 LyXParagraph::size_type main_body;
3125 if (style.labeltype != LABEL_MANUAL)
3128 main_body = par->BeginningOfMainBody();
3130 // gets paragraph main font
3131 //if (main_body > 0)
3132 // font1 = style.labelfont;
3134 // font1 = style.font;
3135 LyXFont font1 = main_body > 0 ? style.labelfont : style.font;
3137 int char_line_count = depth;
3138 if(!style.free_spacing)
3139 for (int j = 0; j < depth; ++j)
3142 // parsing main loop
3143 for (LyXParagraph::size_type i = 0;
3144 i < par->size(); ++i) {
3145 LyXFont font2 = par->getFont(i);
3147 // handle <emphasis> tag
3148 if (font1.emph() != font2.emph() && i) {
3149 if (font2.emph() == LyXFont::ON) {
3153 os << "</emphasis>";
3158 char c = par->GetChar(i);
3160 if (c == LyXParagraph::META_INSET) {
3161 Inset * inset = par->GetInset(i);
3163 std::ostringstream ost;
3164 inset->DocBook(ost);
3165 string tmp_out = ost.str().c_str();
3168 inset->DocBook(ost);
3170 char * ctmp = ost.str();
3171 string tmp_out(ctmp);
3175 // This code needs some explanation:
3176 // Two insets are treated specially
3177 // label if it is the first element in a command paragraph
3179 // graphics inside tables or figure floats can't go on
3180 // title (the equivalente in latex for this case is caption
3181 // and title should come first
3184 if(desc_on!= 3 || i!= 0) {
3185 if(!tmp_out.empty() && tmp_out[0] == '@') {
3187 extra += frontStrip(tmp_out, '@');
3189 os << frontStrip(tmp_out, '@');
3194 } else if (font2.latex() == LyXFont::ON) {
3195 // "TeX"-Mode on ==> SGML-Mode on.
3202 if (par->linuxDocConvertChar(c, sgml_string)
3203 && !style.free_spacing) { // in freespacing
3205 // non-breaking characters
3209 os << "\n</term><listitem><para>";
3223 /* needed if there is an optional argument but no contents */
3224 if (main_body > 0 && main_body == par->size()) {
3228 os << "</emphasis>";
3231 /* resets description flag correctly */
3234 /* <term> not closed... */
3242 int Buffer::runLaTeX()
3244 if (!users->text) return 0;
3246 ProhibitInput(users);
3248 // get LaTeX-Filename
3249 string name = getLatexName();
3251 string path = OnlyPath(filename);
3253 string org_path = path;
3254 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3258 Path p(path); // path to LaTeX file
3259 users->owner()->getMiniBuffer()->Set(_("Running LaTeX..."));
3261 // Remove all error insets
3262 bool a = users->removeAutoInsets();
3264 // Always generate the LaTeX file
3265 makeLaTeXFile(name, org_path, false);
3268 // do the LaTex run(s)
3270 string latex_command = lyxrc.pdf_mode ?
3271 lyxrc.pdflatex_command : lyxrc.latex_command;
3272 LaTeX latex(latex_command, name, filepath);
3273 int res = latex.run(terr,
3274 users->owner()->getMiniBuffer()); // running latex
3276 // check return value from latex.run().
3277 if ((res & LaTeX::NO_LOGFILE)) {
3278 WriteAlert(_("LaTeX did not work!"),
3279 _("Missing log file:"), name);
3280 } else if ((res & LaTeX::ERRORS)) {
3281 users->owner()->getMiniBuffer()->Set(_("Done"));
3282 // Insert all errors as errors boxes
3283 users->insertErrors(terr);
3285 // Dvi should also be kept dirty if the latex run
3286 // ends up with errors. However it should be possible
3287 // to view a dirty dvi too.
3289 //no errors or any other things to think about so:
3290 users->owner()->getMiniBuffer()->Set(_("Done"));
3294 // if we removed error insets before we ran LaTeX or if we inserted
3295 // error insets after we ran LaTeX this must be run:
3296 if (a || (res & LaTeX::ERRORS)){
3299 users->updateScrollbar();
3303 return latex.getNumErrors();
3307 int Buffer::runLiterate()
3309 if (!users->text) return 0;
3311 ProhibitInput(users);
3313 // get LaTeX-Filename
3314 string name = getLatexName();
3315 // get Literate-Filename
3316 string lit_name = ChangeExtension (getLatexName(),
3317 lyxrc.literate_extension, true);
3319 string path = OnlyPath(filename);
3321 string org_path = path;
3322 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3326 Path p(path); // path to Literate file
3327 users->owner()->getMiniBuffer()->Set(_("Running Literate..."));
3329 // Remove all error insets
3330 bool a = users->removeAutoInsets();
3332 // generate the Literate file if necessary
3333 if (!isDviClean() || a) {
3334 makeLaTeXFile(lit_name, org_path, false);
3338 string latex_command = lyxrc.pdf_mode ?
3339 lyxrc.pdflatex_command : lyxrc.latex_command;
3340 Literate literate(latex_command, name, filepath,
3342 lyxrc.literate_command, lyxrc.literate_error_filter,
3343 lyxrc.build_command, lyxrc.build_error_filter);
3345 int res = literate.weave(terr, users->owner()->getMiniBuffer());
3347 // check return value from literate.weave().
3348 if ((res & Literate::NO_LOGFILE)) {
3349 WriteAlert(_("Literate command did not work!"),
3350 _("Missing log file:"), name);
3351 } else if ((res & Literate::ERRORS)) {
3352 users->owner()->getMiniBuffer()->Set(_("Done"));
3353 // Insert all errors as errors boxes
3354 users->insertErrors(terr);
3356 // Dvi should also be kept dirty if the latex run
3357 // ends up with errors. However it should be possible
3358 // to view a dirty dvi too.
3360 //no errors or any other things to think about so:
3361 users->owner()->getMiniBuffer()->Set(_("Done"));
3365 // if we removed error insets before we ran LaTeX or if we inserted
3366 // error insets after we ran LaTeX this must be run:
3367 if (a || (res & Literate::ERRORS)){
3370 users->updateScrollbar();
3374 return literate.getNumErrors();
3378 int Buffer::buildProgram()
3380 if (!users->text) return 0;
3382 ProhibitInput(users);
3384 // get LaTeX-Filename
3385 string name = getLatexName();
3386 // get Literate-Filename
3387 string lit_name = ChangeExtension(getLatexName(),
3388 lyxrc.literate_extension, true);
3390 string path = OnlyPath(filename);
3392 string org_path = path;
3393 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3397 Path p(path); // path to Literate file
3398 users->owner()->getMiniBuffer()->Set(_("Building Program..."));
3400 // Remove all error insets
3401 bool a = users->removeAutoInsets();
3403 // generate the LaTeX file if necessary
3404 if (!isNwClean() || a) {
3405 makeLaTeXFile(lit_name, org_path, false);
3409 string latex_command = lyxrc.pdf_mode ?
3410 lyxrc.pdflatex_command : lyxrc.latex_command;
3411 Literate literate(latex_command, name, filepath,
3413 lyxrc.literate_command, lyxrc.literate_error_filter,
3414 lyxrc.build_command, lyxrc.build_error_filter);
3416 int res = literate.build(terr, users->owner()->getMiniBuffer());
3418 // check return value from literate.build().
3419 if ((res & Literate::NO_LOGFILE)) {
3420 WriteAlert(_("Build did not work!"),
3421 _("Missing log file:"), name);
3422 } else if ((res & Literate::ERRORS)) {
3423 users->owner()->getMiniBuffer()->Set(_("Done"));
3424 // Insert all errors as errors boxes
3425 users->insertErrors(terr);
3427 // Literate files should also be kept dirty if the literate
3428 // command run ends up with errors.
3430 //no errors or any other things to think about so:
3431 users->owner()->getMiniBuffer()->Set(_("Done"));
3435 // if we removed error insets before we ran Literate/Build or if we inserted
3436 // error insets after we ran Literate/Build this must be run:
3437 if (a || (res & Literate::ERRORS)){
3440 users->updateScrollbar();
3444 return literate.getNumErrors();
3448 // This should be enabled when the Chktex class is implemented. (Asger)
3449 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
3450 // Other flags: -wall -v0 -x
3451 int Buffer::runChktex()
3453 if (!users->text) return 0;
3455 ProhibitInput(users);
3457 // get LaTeX-Filename
3458 string name = getLatexName();
3459 string path = OnlyPath(filename);
3461 string org_path = path;
3462 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3466 Path p(path); // path to LaTeX file
3467 users->owner()->getMiniBuffer()->Set(_("Running chktex..."));
3469 // Remove all error insets
3470 bool a = users->removeAutoInsets();
3472 // Generate the LaTeX file if neccessary
3473 if (!isDviClean() || a) {
3474 makeLaTeXFile(name, org_path, false);
3479 Chktex chktex(lyxrc.chktex_command, name, filepath);
3480 int res = chktex.run(terr); // run chktex
3483 WriteAlert(_("chktex did not work!"),
3484 _("Could not run with file:"), name);
3485 } else if (res > 0) {
3486 // Insert all errors as errors boxes
3487 users->insertErrors(terr);
3490 // if we removed error insets before we ran chktex or if we inserted
3491 // error insets after we ran chktex, this must be run:
3495 users->updateScrollbar();
3504 void Buffer::RoffAsciiTable(ostream & os, LyXParagraph * par)
3506 LyXFont font1(LyXFont::ALL_INHERIT,params.language_info);
3509 LyXParagraph::size_type i;
3513 string fname1 = TmpFileName(string(), "RAT1");
3514 string fname2 = TmpFileName(string(), "RAT2");
3516 ofstream ofs(fname1.c_str());
3518 WriteAlert(_("LYX_ERROR:"),
3519 _("Cannot open temporary file:"), fname1);
3522 par->table->RoffEndOfCell(ofs, -1);
3523 for (i = 0; i < par->size(); ++i) {
3524 c = par->GetChar(i);
3525 if (par->table->IsContRow(cell)) {
3526 if (c == LyXParagraph::META_NEWLINE)
3530 font2 = par->GetFontSettings(i);
3531 if (font1.latex() != font2.latex()) {
3532 if (font2.latex() != LyXFont::OFF)
3536 case LyXParagraph::META_INSET:
3537 if ((inset = par->GetInset(i))) {
3540 stringstresm ss(ios::in | ios::out);
3541 inset->Latex(ss, true);
3553 inset->Latex(ss, true);
3566 fstream fs(fname2.c_str(), ios::in|ios::out);
3568 WriteAlert(_("LYX_ERROR:"),
3569 _("Cannot open temporary file:"), fname2);
3571 remove(fname1.c_str());
3574 inset->Latex(fs, true);
3588 case LyXParagraph::META_NEWLINE:
3589 if (par->table->CellHasContRow(cell)>= 0)
3590 par->RoffContTableRows(ofs, i+1, cell);
3591 par->table->RoffEndOfCell(ofs, cell);
3594 case LyXParagraph::META_HFILL:
3604 << "RoffAsciiTable:"
3605 " NULL char in structure." << endl;
3609 par->table->RoffEndOfCell(ofs, cell);
3611 string cmd = lyxrc.ascii_roff_command + " >" + fname2;
3612 cmd = subst(cmd, "$$FName", fname1);
3613 Systemcalls one(Systemcalls::System, cmd);
3614 if (!(lyxerr.debugging(Debug::ROFF))) {
3615 remove(fname1.c_str());
3617 ifstream ifs(fname2.c_str());
3619 WriteFSAlert(_("Error! Can't open temporary file:"), fname2);
3622 // now output the produced file
3626 WriteAlert(_("Error!"),
3627 _("Error executing *roff command on table"));
3628 // overread leading blank lines
3629 while(!ifs && (c == '\n'))
3632 for(j = 0; j < par->depth; ++j)
3634 while(!ifs && (c != '\n')) {
3639 // overread trailing blank lines
3640 while(!ifs && (c == '\n'))
3644 remove(fname2.c_str());
3649 /// changed Heinrich Bauer, 23/03/98
3650 bool Buffer::isDviClean() const
3652 if (lyxrc.use_tempdir)
3653 return dvi_clean_tmpd;
3655 return dvi_clean_orgd;
3659 /// changed Heinrich Bauer, 23/03/98
3660 void Buffer::markDviClean()
3662 if (lyxrc.use_tempdir)
3663 dvi_clean_tmpd = true;
3665 dvi_clean_orgd = true;
3669 /// changed Heinrich Bauer, 23/03/98
3670 void Buffer::markDviDirty()
3672 if (lyxrc.use_tempdir)
3673 dvi_clean_tmpd = false;
3675 dvi_clean_orgd = false;
3679 void Buffer::validate(LaTeXFeatures & features) const
3681 LyXParagraph * par = paragraph;
3682 LyXTextClass const & tclass =
3683 textclasslist.TextClass(params.textclass);
3685 // AMS Style is at document level
3687 features.amsstyle = (params.use_amsmath ||
3688 tclass.provides(LyXTextClass::amsmath));
3691 // We don't use "lyxerr.debug" because of speed. (Asger)
3692 if (lyxerr.debugging(Debug::LATEX))
3693 lyxerr << "Paragraph: " << par << endl;
3695 // Now just follow the list of paragraphs and run
3696 // validate on each of them.
3697 par->validate(features);
3699 // and then the next paragraph
3703 // the bullet shapes are buffer level not paragraph level
3704 // so they are tested here
3705 for (int i = 0; i < 4; ++i) {
3706 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
3707 int font = params.user_defined_bullets[i].getFont();
3710 .user_defined_bullets[i]
3717 features.latexsym = true;
3721 features.amssymb = true;
3723 else if ((font >= 2 && font <= 5)) {
3724 features.pifont = true;
3729 if (lyxerr.debugging(Debug::LATEX)) {
3730 features.showStruct();
3735 void Buffer::setPaperStuff()
3737 params.papersize = BufferParams::PAPER_DEFAULT;
3738 char c1 = params.paperpackage;
3739 if (c1 == BufferParams::PACKAGE_NONE) {
3740 char c2 = params.papersize2;
3741 if (c2 == BufferParams::VM_PAPER_USLETTER)
3742 params.papersize = BufferParams::PAPER_USLETTER;
3743 else if (c2 == BufferParams::VM_PAPER_USLEGAL)
3744 params.papersize = BufferParams::PAPER_LEGALPAPER;
3745 else if (c2 == BufferParams::VM_PAPER_USEXECUTIVE)
3746 params.papersize = BufferParams::PAPER_EXECUTIVEPAPER;
3747 else if (c2 == BufferParams::VM_PAPER_A3)
3748 params.papersize = BufferParams::PAPER_A3PAPER;
3749 else if (c2 == BufferParams::VM_PAPER_A4)
3750 params.papersize = BufferParams::PAPER_A4PAPER;
3751 else if (c2 == BufferParams::VM_PAPER_A5)
3752 params.papersize = BufferParams::PAPER_A5PAPER;
3753 else if ((c2 == BufferParams::VM_PAPER_B3) || (c2 == BufferParams::VM_PAPER_B4) ||
3754 (c2 == BufferParams::VM_PAPER_B5))
3755 params.papersize = BufferParams::PAPER_B5PAPER;
3756 } else if ((c1 == BufferParams::PACKAGE_A4) || (c1 == BufferParams::PACKAGE_A4WIDE) ||
3757 (c1 == BufferParams::PACKAGE_WIDEMARGINSA4))
3758 params.papersize = BufferParams::PAPER_A4PAPER;
3762 // This function should be in Buffer because it's a buffer's property (ale)
3763 string Buffer::getIncludeonlyList(char delim)
3766 LyXParagraph * par = paragraph;
3767 LyXParagraph::size_type pos;
3771 while ((inset = par->ReturnNextInsetPointer(pos))){
3772 if (inset->LyxCode() == Inset::INCLUDE_CODE) {
3773 InsetInclude * insetinc =
3774 static_cast<InsetInclude*>(inset);
3775 if (insetinc->isInclude()
3776 && insetinc->isNoLoad()) {
3779 lst += ChangeExtension(insetinc->getContents(), string(), true);
3786 lyxerr.debug() << "Includeonly(" << lst << ')' << endl;
3791 // This is also a buffer property (ale)
3792 string Buffer::getReferenceList(char delim)
3794 /// if this is a child document and the parent is already loaded
3795 /// Use the parent's list instead [ale990407]
3796 if (!params.parentname.empty()
3797 && bufferlist.exists(params.parentname)) {
3798 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3800 return tmp->getReferenceList(delim);
3803 LyXParagraph * par = paragraph;
3804 LyXParagraph::size_type pos;
3809 while ((inset = par->ReturnNextInsetPointer(pos))){
3810 for (int i = 0; i < inset->GetNumberOfLabels(); ++i) {
3813 lst += inset->getLabel(i);
3819 lyxerr.debug() << "References(" << lst << ")" << endl;
3824 // This is also a buffer property (ale)
3825 string Buffer::getBibkeyList(char delim)
3827 /// if this is a child document and the parent is already loaded
3828 /// Use the parent's list instead [ale990412]
3829 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3830 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3832 return tmp->getBibkeyList(delim);
3836 LyXParagraph * par = paragraph;
3839 if (!bibkeys.empty())
3841 bibkeys += par->bibkey->getContents();
3846 // Might be either using bibtex or a child has bibliography
3847 if (bibkeys.empty()) {
3851 LyXParagraph::size_type pos = -1;
3853 // Search for Bibtex or Include inset
3854 while ((inset = par->ReturnNextInsetPointer(pos))) {
3855 if (inset-> LyxCode() == Inset::BIBTEX_CODE) {
3856 if (!bibkeys.empty())
3858 bibkeys += static_cast<InsetBibtex*>(inset)->getKeys(delim);
3859 } else if (inset-> LyxCode() == Inset::INCLUDE_CODE) {
3860 string bk = static_cast<InsetInclude*>(inset)->getKeys(delim);
3862 if (!bibkeys.empty())
3873 lyxerr.debug() << "Bibkeys(" << bibkeys << ")" << endl;
3878 bool Buffer::isDepClean(string const & name) const
3880 DEPCLEAN * item = dep_clean;
3881 while (item && item->master != name)
3883 if (!item) return true;
3888 void Buffer::markDepClean(string const & name)
3891 dep_clean = new DEPCLEAN;
3892 dep_clean->clean = true;
3893 dep_clean->master = name;
3894 dep_clean->next = 0;
3896 DEPCLEAN* item = dep_clean;
3897 while (item && item->master != name)
3902 item = new DEPCLEAN;
3904 item->master = name;
3911 void Buffer::Dispatch(string const & command)
3913 // Split command string into command and argument
3914 string cmd, line = frontStrip(command);
3915 string arg = strip(frontStrip(split(line, cmd, ' ')));
3917 Dispatch(lyxaction.LookupFunc(cmd.c_str()), arg.c_str());
3921 void Buffer::Dispatch(int action, string const & argument)
3925 MenuExport(this, argument);
3929 lyxerr << "A truly unknown func!" << endl;
3935 void Buffer::ChangeLanguage(Language const * from, Language const * to)
3938 LyXParagraph * par = paragraph;
3940 par->ChangeLanguage(from,to);
3945 bool Buffer::isMultiLingual()
3948 LyXParagraph * par = paragraph;
3950 if (par->isMultiLingual())