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/insetert.h"
73 #include "insets/insetgraphics.h"
74 #include "insets/insetfoot.h"
75 #include "support/filetools.h"
76 #include "support/path.h"
82 #include "LaTeXFeatures.h"
83 #include "support/syscall.h"
84 #include "support/lyxlib.h"
85 #include "support/FileInfo.h"
99 // Uncomment this line to enable a workaround for the weird behaviour
100 // of the cursor between a displayed inset and last character
101 // at the upper line. (Alejandro 20.9.96)
102 // #define BREAK_BEFORE_INSET
104 /* Lars, when changing this file sometime in the future to a list,
105 * please check out the figinsets-sideeffects described at the
106 * beginning of figinset.C Matthias (04.07.1996)
110 // all these externs should eventually be removed.
111 extern BufferList bufferlist;
113 extern void MenuExport(Buffer *, string const &);
114 extern LyXAction lyxaction;
117 static const float LYX_FORMAT = 2.16;
119 extern int tex_code_break_column;
122 Buffer::Buffer(string const & file, bool ronly)
124 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
126 filepath = OnlyPath(file);
130 dvi_clean_orgd = false; // Heinrich Bauer, 23/03/98
131 dvi_clean_tmpd = false; // Heinrich Bauer, 23/03/98
136 if (read_only || (lyxrc.use_tempdir)) {
137 tmppath = CreateBufferTmpDir();
138 } else tmppath.clear();
144 lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
145 // here the buffer should take care that it is
146 // saved properly, before it goes into the void.
148 // make sure that views using this buffer
153 if (!tmppath.empty()) {
154 DestroyBufferTmpDir(tmppath);
157 LyXParagraph * par = paragraph;
158 LyXParagraph * tmppar;
168 string Buffer::getLatexName(bool no_path /* = true */) const
170 return ChangeExtension(MakeLatexName(filename),
175 void Buffer::setReadonly(bool flag /* = true */)
177 if (read_only != flag) {
180 updateAllVisibleBufferRelatedPopups();
183 WarnReadonly(filename);
188 bool Buffer::saveParamsAsDefaults()
190 string fname = AddName(AddPath(user_lyxdir, "templates/"),
192 Buffer defaults = Buffer(fname);
194 // Use the current buffer's parameters as default
195 defaults.params = params;
197 // add an empty paragraph. Is this enough?
198 defaults.paragraph = new LyXParagraph;
200 return defaults.writeFile(defaults.filename, false);
204 /// Update window titles of all users
205 // Should work on a list
206 void Buffer::updateTitles() const
208 if (users) users->owner()->updateWindowTitle();
212 /// Reset autosave timer of all users
213 // Should work on a list
214 void Buffer::resetAutosaveTimers() const
216 if (users) users->owner()->resetAutosaveTimer();
220 void Buffer::fileName(string const & newfile)
222 filename = MakeAbsPath(newfile);
223 filepath = OnlyPath(filename);
224 setReadonly(IsFileWriteable(filename) == 0);
229 // candidate for move to BufferView
230 // (at least some parts in the beginning of the func)
233 // changed to be public and have one parameter
234 // if par = 0 normal behavior
235 // else insert behavior
236 // Returns false if "\the_end" is not read for formats >= 2.13. (Asger)
237 #define USE_PARSE_FUNCTION 1
238 bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par)
242 char depth = 0; // signed or unsigned?
243 LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
244 LyXParagraph::footnote_kind footnotekind = LyXParagraph::FOOTNOTE;
245 bool the_end_read = false;
247 LyXParagraph * return_par = 0;
248 LyXFont font(LyXFont::ALL_INHERIT,params.language_info);
249 if (format < 2.16 && params.language == "hebrew")
250 font.setLanguage(default_language);
252 // If we are inserting, we cheat and get a token in advance
253 bool has_token = false;
257 par = new LyXParagraph;
259 users->text->BreakParagraph();
260 return_par = users->text->FirstParagraph();
263 // We don't want to adopt the parameters from the
264 // document we insert, so we skip until the text begins:
267 pretoken = lex.GetString();
268 if (pretoken == "\\layout") {
280 pretoken = lex.GetString();
283 // Profiling show this should give a lot: (Asger)
284 string const token = pretoken;
288 the_end_read = parseSingleLyXformat2Token(lex, par, return_par,
297 paragraph = return_par;
304 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)
312 bool the_end_read = false;
314 if (token[0] != '\\') {
315 for (string::const_iterator cit = token.begin();
316 cit != token.end(); ++cit) {
317 par->InsertChar(pos, (*cit));
318 par->SetFont(pos, font);
321 } else if (token == "\\i") {
322 Inset * inset = new InsetLatexAccent;
324 par->InsertChar(pos, LyXParagraph::META_INSET);
325 par->InsertInset(pos, inset);
326 par->SetFont(pos, font);
328 } else if (token == "\\layout") {
333 par = new LyXParagraph(par);
337 string layoutname = lex.GetString();
338 pair<bool, LyXTextClass::LayoutList::size_type> pp
339 = textclasslist.NumberOfLayout(params.textclass,
342 par->layout = pp.second;
343 } else { // layout not found
344 // use default layout "Standard" (0)
347 // Test whether the layout is obsolete.
348 LyXLayout const & layout =
349 textclasslist.Style(params.textclass,
351 if (!layout.obsoleted_by().empty())
353 textclasslist.NumberOfLayout(params.textclass,
354 layout.obsoleted_by()).second;
355 par->footnoteflag = footnoteflag;
356 par->footnotekind = footnotekind;
358 font = LyXFont(LyXFont::ALL_INHERIT,params.language_info);
359 if (format < 2.16 && params.language == "hebrew")
360 font.setLanguage(default_language);
361 } else if (token == "\\end_float") {
366 par = new LyXParagraph(par);
368 footnotekind = LyXParagraph::FOOTNOTE;
369 footnoteflag = LyXParagraph::NO_FOOTNOTE;
372 par->layout = LYX_DUMMY_LAYOUT;
373 font = LyXFont(LyXFont::ALL_INHERIT, params.language_info);
374 if (format < 2.16 && params.language == "hebrew")
375 font.setLanguage(default_language);
376 } else if (token == "\\begin_float") {
377 tmpret = lex.FindToken(string_footnotekinds);
378 if (tmpret == -1) ++tmpret;
379 if (tmpret != LYX_LAYOUT_DEFAULT)
380 footnotekind = static_cast<LyXParagraph::footnote_kind>(tmpret); // bad
381 if (footnotekind == LyXParagraph::FOOTNOTE
382 || footnotekind == LyXParagraph::MARGIN)
383 footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
385 footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
386 } else if (token == "\\begin_deeper") {
388 } else if (token == "\\end_deeper") {
390 lex.printError("\\end_deeper: "
391 "depth is already null");
395 } else if (token == "\\begin_preamble") {
396 params.readPreamble(lex);
397 } else if (token == "\\textclass") {
399 pair<bool, LyXTextClassList::size_type> pp =
400 textclasslist.NumberOfClass(lex.GetString());
402 params.textclass = pp.second;
404 lex.printError("Unknown textclass `$$Token'");
405 params.textclass = 0;
407 if (!textclasslist.Load(params.textclass)) {
408 // if the textclass wasn't loaded properly
409 // we need to either substitute another
410 // or stop loading the file.
411 // I can substitute but I don't see how I can
412 // stop loading... ideas?? ARRae980418
413 WriteAlert(_("Textclass Loading Error!"),
414 string(_("Can't load textclass ")) +
415 textclasslist.NameOfClass(params.textclass),
416 _("-- substituting default"));
417 params.textclass = 0;
419 } else if (token == "\\options") {
421 params.options = lex.GetString();
422 } else if (token == "\\language") {
423 params.readLanguage(lex);
424 } else if (token == "\\fontencoding") {
426 } else if (token == "\\inputencoding") {
428 params.inputenc = lex.GetString();
429 } else if (token == "\\graphics") {
430 params.readGraphicsDriver(lex);
431 } else if (token == "\\fontscheme") {
433 params.fonts = lex.GetString();
434 } else if (token == "\\noindent") {
435 par->noindent = true;
436 } else if (token == "\\fill_top") {
437 par->added_space_top = VSpace(VSpace::VFILL);
438 } else if (token == "\\fill_bottom") {
439 par->added_space_bottom = VSpace(VSpace::VFILL);
440 } else if (token == "\\line_top") {
441 par->line_top = true;
442 } else if (token == "\\line_bottom") {
443 par->line_bottom = true;
444 } else if (token == "\\pagebreak_top") {
445 par->pagebreak_top = true;
446 } else if (token == "\\pagebreak_bottom") {
447 par->pagebreak_bottom = true;
448 } else if (token == "\\start_of_appendix") {
449 par->start_of_appendix = true;
450 } else if (token == "\\paragraph_separation") {
451 tmpret = lex.FindToken(string_paragraph_separation);
452 if (tmpret == -1) ++tmpret;
453 if (tmpret != LYX_LAYOUT_DEFAULT)
454 params.paragraph_separation =
455 static_cast<BufferParams::PARSEP>(tmpret);
456 } else if (token == "\\defskip") {
458 params.defskip = VSpace(lex.GetString());
459 } else if (token == "\\epsfig") { // obsolete
460 // Indeed it is obsolete, but we HAVE to be backwards
461 // compatible until 0.14, because otherwise all figures
462 // in existing documents are irretrivably lost. (Asger)
463 params.readGraphicsDriver(lex);
464 } else if (token == "\\quotes_language") {
465 tmpret = lex.FindToken(string_quotes_language);
466 if (tmpret == -1) ++tmpret;
467 if (tmpret != LYX_LAYOUT_DEFAULT) {
468 InsetQuotes::quote_language tmpl =
469 InsetQuotes::EnglishQ;
472 tmpl = InsetQuotes::EnglishQ;
475 tmpl = InsetQuotes::SwedishQ;
478 tmpl = InsetQuotes::GermanQ;
481 tmpl = InsetQuotes::PolishQ;
484 tmpl = InsetQuotes::FrenchQ;
487 tmpl = InsetQuotes::DanishQ;
490 params.quotes_language = tmpl;
492 } else if (token == "\\quotes_times") {
494 switch(lex.GetInteger()) {
496 params.quotes_times = InsetQuotes::SingleQ;
499 params.quotes_times = InsetQuotes::DoubleQ;
502 } else if (token == "\\papersize") {
503 tmpret = lex.FindToken(string_papersize);
507 params.papersize2 = tmpret;
508 } else if (token == "\\paperpackage") {
509 tmpret = lex.FindToken(string_paperpackages);
512 params.paperpackage = BufferParams::PACKAGE_NONE;
514 params.paperpackage = tmpret;
515 } else if (token == "\\use_geometry") {
517 params.use_geometry = lex.GetInteger();
518 } else if (token == "\\use_amsmath") {
520 params.use_amsmath = lex.GetInteger();
521 } else if (token == "\\paperorientation") {
522 tmpret = lex.FindToken(string_orientation);
523 if (tmpret == -1) ++tmpret;
524 if (tmpret != LYX_LAYOUT_DEFAULT)
525 params.orientation = static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
526 } else if (token == "\\paperwidth") {
528 params.paperwidth = lex.GetString();
529 } else if (token == "\\paperheight") {
531 params.paperheight = lex.GetString();
532 } else if (token == "\\leftmargin") {
534 params.leftmargin = lex.GetString();
535 } else if (token == "\\topmargin") {
537 params.topmargin = lex.GetString();
538 } else if (token == "\\rightmargin") {
540 params.rightmargin = lex.GetString();
541 } else if (token == "\\bottommargin") {
543 params.bottommargin = lex.GetString();
544 } else if (token == "\\headheight") {
546 params.headheight = lex.GetString();
547 } else if (token == "\\headsep") {
549 params.headsep = lex.GetString();
550 } else if (token == "\\footskip") {
552 params.footskip = lex.GetString();
553 } else if (token == "\\paperfontsize") {
555 params.fontsize = strip(lex.GetString());
556 } else if (token == "\\papercolumns") {
558 params.columns = lex.GetInteger();
559 } else if (token == "\\papersides") {
561 switch(lex.GetInteger()) {
563 case 1: params.sides = LyXTextClass::OneSide; break;
564 case 2: params.sides = LyXTextClass::TwoSides; break;
566 } else if (token == "\\paperpagestyle") {
568 params.pagestyle = strip(lex.GetString());
569 } else if (token == "\\bullet") {
571 int index = lex.GetInteger();
573 int temp_int = lex.GetInteger();
574 params.user_defined_bullets[index].setFont(temp_int);
575 params.temp_bullets[index].setFont(temp_int);
577 temp_int = lex.GetInteger();
578 params.user_defined_bullets[index].setCharacter(temp_int);
579 params.temp_bullets[index].setCharacter(temp_int);
581 temp_int = lex.GetInteger();
582 params.user_defined_bullets[index].setSize(temp_int);
583 params.temp_bullets[index].setSize(temp_int);
585 string temp_str = lex.GetString();
586 if (temp_str != "\\end_bullet") {
587 // this element isn't really necessary for
588 // parsing but is easier for humans
589 // to understand bullets. Put it back and
590 // set a debug message?
591 lex.printError("\\end_bullet expected, got" + temp_str);
592 //how can I put it back?
594 } else if (token == "\\bulletLaTeX") {
596 int index = lex.GetInteger();
598 string temp_str = lex.GetString(), sum_str;
599 while (temp_str != "\\end_bullet") {
600 // this loop structure is needed when user
601 // enters an empty string since the first
602 // thing returned will be the \\end_bullet
604 // if the LaTeX entry has spaces. Each element
605 // therefore needs to be read in turn
608 temp_str = lex.GetString();
610 params.user_defined_bullets[index].setText(sum_str);
611 params.temp_bullets[index].setText(sum_str);
612 } else if (token == "\\secnumdepth") {
614 params.secnumdepth = lex.GetInteger();
615 } else if (token == "\\tocdepth") {
617 params.tocdepth = lex.GetInteger();
619 } else if (token == "\\baselinestretch") { // obsolete
620 lex.nextToken(); // should not be used directly
622 // Will probably keep a kind of support just for
624 params.spacing.set(Spacing::Other, lex.GetFloat());
626 } else if (token == "\\spacing") {
628 string tmp = strip(lex.GetString());
629 Spacing::Space tmp_space = Spacing::Default;
630 if (tmp == "single") {
631 params.spacing.set(Spacing::Single);
632 } else if (tmp == "onehalf") {
633 params.spacing.set(Spacing::Onehalf);
634 } else if (tmp == "double") {
635 params.spacing.set(Spacing::Double);
636 } else if (tmp == "other") {
638 params.spacing.set(Spacing::Other,
641 lex.printError("Unknown spacing token: '$$Token'");
643 // Small hack so that files written with klyx will be
646 par->spacing.set(tmp_space);
648 params.spacing.set(tmp_space);
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();
670 } else if (token == "\\cursor") { // obsolete
671 // this is obsolete, so we just skip it.
674 } else if (token == "\\family") {
676 font.setLyXFamily(lex.GetString());
677 } else if (token == "\\series") {
679 font.setLyXSeries(lex.GetString());
680 } else if (token == "\\shape") {
682 font.setLyXShape(lex.GetString());
683 } else if (token == "\\size") {
685 font.setLyXSize(lex.GetString());
686 } else if (token == "\\latex") {
688 string tok = lex.GetString();
689 // This is dirty, but gone with LyX3. (Asger)
690 if (tok == "no_latex")
691 font.setLatex(LyXFont::OFF);
692 else if (tok == "latex")
693 font.setLatex(LyXFont::ON);
694 else if (tok == "default")
695 font.setLatex(LyXFont::INHERIT);
697 lex.printError("Unknown LaTeX font flag "
699 } else if (token == "\\lang") {
701 string tok = lex.GetString();
702 Languages::iterator lit = languages.find(tok);
703 if (lit != languages.end()) {
704 font.setLanguage(&(*lit).second);
706 font.setLanguage(params.language_info);
707 lex.printError("Unknown language `$$Token'");
710 } else if (token == "\\direction") { // obsolete
712 lex.printError("Command \\direction is obsolete");
714 string tok = lex.GetString();
716 font.setLanguage(&languages["hebrew"]);
717 else if (tok == "default")
718 if (params.language == "hebrew")
719 font.setLanguage(default_language);
721 font.setLanguage(params.language_info);
723 lex.printError("Unknown direction `$$Token'");
725 } else if (token == "\\emph") {
727 font.setEmph(font.setLyXMisc(lex.GetString()));
728 } else if (token == "\\bar") {
730 string tok = lex.GetString();
731 // This is dirty, but gone with LyX3. (Asger)
733 font.setUnderbar(LyXFont::ON);
734 else if (tok == "no")
735 font.setUnderbar(LyXFont::OFF);
736 else if (tok == "default")
737 font.setUnderbar(LyXFont::INHERIT);
739 lex.printError("Unknown bar font flag "
741 } else if (token == "\\noun") {
743 font.setNoun(font.setLyXMisc(lex.GetString()));
744 } else if (token == "\\color") {
746 font.setLyXColor(lex.GetString());
747 } else if (token == "\\align") {
748 tmpret = lex.FindToken(string_align);
749 if (tmpret == -1) ++tmpret;
750 if (tmpret != LYX_LAYOUT_DEFAULT) { // tmpret != 99 ???
752 for (; tmpret > 0; --tmpret)
753 tmpret2 = tmpret2 * 2;
754 par->align = LyXAlignment(tmpret2);
756 } else if (token == "\\added_space_top") {
758 par->added_space_top = VSpace(lex.GetString());
759 } else if (token == "\\added_space_bottom") {
761 par->added_space_bottom = VSpace(lex.GetString());
762 } else if (token == "\\pextra_type") {
764 par->pextra_type = lex.GetInteger();
765 } else if (token == "\\pextra_width") {
767 par->pextra_width = lex.GetString();
768 } else if (token == "\\pextra_widthp") {
770 par->pextra_widthp = lex.GetString();
771 } else if (token == "\\pextra_alignment") {
773 par->pextra_alignment = lex.GetInteger();
774 } else if (token == "\\pextra_hfill") {
776 par->pextra_hfill = lex.GetInteger();
777 } else if (token == "\\pextra_start_minipage") {
779 par->pextra_start_minipage = lex.GetInteger();
780 } else if (token == "\\labelwidthstring") {
782 par->labelwidthstring = lex.GetString();
783 /* do not delete this token, it is still needed! */
784 } else if (token == "\\end_inset") {
785 /* simple ignore this. The insets do not have
787 // but insets should read it, it is a part of
788 //the inset isn't it? Lgb.
789 } else if (token == "\\begin_inset") {
791 string tmptok = lex.GetString();
792 /* test the different insets */
793 if (tmptok == "Quotes") {
794 Inset * inset = new InsetQuotes;
796 par->InsertChar(pos, LyXParagraph::META_INSET);
797 par->InsertInset(pos, inset);
798 par->SetFont(pos, font);
800 } else if (tmptok == "\\i") {
801 Inset * inset = new InsetLatexAccent;
803 par->InsertChar(pos, LyXParagraph::META_INSET);
804 par->InsertInset(pos, inset);
805 par->SetFont(pos, font);
807 } else if (tmptok == "FormulaMacro") {
808 Inset * inset = new InsetFormulaMacro;
810 par->InsertChar(pos, LyXParagraph::META_INSET);
811 par->InsertInset(pos, inset);
812 par->SetFont(pos, font);
814 } else if (tmptok == "Formula") {
815 Inset * inset = new InsetFormula;
817 par->InsertChar(pos, LyXParagraph::META_INSET);
818 par->InsertInset(pos, inset);
819 par->SetFont(pos, font);
821 } else if (tmptok == "Figure") {
822 Inset * inset = new InsetFig(100, 100, this);
824 par->InsertChar(pos, LyXParagraph::META_INSET);
825 par->InsertInset(pos, inset);
826 par->SetFont(pos, font);
828 } else if (tmptok == "Info") {
829 Inset * inset = new InsetInfo;
831 par->InsertChar(pos, LyXParagraph::META_INSET);
832 par->InsertInset(pos, inset);
833 par->SetFont(pos, font);
835 } else if (tmptok == "Include") {
836 Inset * inset = new InsetInclude(string(), this);
838 par->InsertChar(pos, LyXParagraph::META_INSET);
839 par->InsertInset(pos, inset);
840 par->SetFont(pos, font);
842 } else if (tmptok == "ERT") {
843 Inset * inset = new InsetERT(this);
845 par->InsertChar(pos, LyXParagraph::META_INSET);
846 par->InsertInset(pos, inset);
847 par->SetFont(pos, font);
849 } else if (tmptok == "Text") {
850 Inset * inset = new InsetText(this);
852 par->InsertChar(pos, LyXParagraph::META_INSET);
853 par->InsertInset(pos, inset);
854 par->SetFont(pos, font);
856 } else if (tmptok == "Foot") {
857 Inset * inset = new InsetFoot(this);
859 par->InsertChar(pos, LyXParagraph::META_INSET);
860 par->InsertInset(pos, inset);
861 par->SetFont(pos, font);
863 } else if (tmptok == "GRAPHICS") {
864 Inset * inset = new InsetGraphics;
866 par->InsertChar(pos, LyXParagraph::META_INSET);
867 par->InsertInset(pos, inset);
868 par->SetFont(pos, font);
869 } else if (tmptok == "LatexCommand") {
873 if (inscmd.getCmdName() == "cite") {
874 inset = new InsetCitation(inscmd.getContents(), inscmd.getOptions());
875 } else if (inscmd.getCmdName() == "bibitem") {
876 lex.printError("Wrong place for bibitem");
877 inset = inscmd.Clone();
878 } else if (inscmd.getCmdName() == "BibTeX") {
879 inset = new InsetBibtex(inscmd.getContents(), inscmd.getOptions(), this);
880 } else if (inscmd.getCmdName() == "index") {
881 inset = new InsetIndex(inscmd.getContents());
882 } else if (inscmd.getCmdName() == "include") {
883 inset = new InsetInclude(inscmd.getContents(), this);
884 } else if (inscmd.getCmdName() == "label") {
885 inset = new InsetLabel(inscmd.getCommand());
886 } else if (inscmd.getCmdName() == "url"
887 || inscmd.getCmdName() == "htmlurl") {
888 inset = new InsetUrl(inscmd.getCommand());
889 } else if (inscmd.getCmdName() == "ref"
890 || inscmd.getCmdName() == "pageref") {
891 if (!inscmd.getOptions().empty() || !inscmd.getContents().empty()) {
892 inset = new InsetRef(inscmd, this);
894 #warning Check if this else clause is still needed. (Lgb)
896 // This condition comes from a
897 // temporary solution to the latexdel
898 // ref inset that was transformed to
899 // an empty ref inset plus the body
900 // surronded by latexdel insets
902 string cont, opt, tmptmptok, cmdname;
904 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
909 tmptmptok = lex.GetString();
910 if(tmptmptok[0] == '\\') {
911 if( tmptmptok == "\\backslash")
921 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
926 tmptmptok = lex.GetString();
927 if(tmptmptok[0] == '\\') {
928 if( tmptmptok == "\\backslash")
938 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
944 cmdname = "\\" + inscmd.getCmdName();
945 cmdname += "[" + cont + "]";
946 cmdname += "{" + opt + "}";
947 inset = new InsetRef(cmdname, this);
950 } else if (inscmd.getCmdName() == "tableofcontents") {
951 inset = new InsetTOC(this);
952 } else if (inscmd.getCmdName() == "listoffigures") {
953 inset = new InsetLOF(this);
954 } else if (inscmd.getCmdName() == "listofalgorithms") {
955 inset = new InsetLOA(this);
956 } else if (inscmd.getCmdName() == "listoftables") {
957 inset = new InsetLOT(this);
958 } else if (inscmd.getCmdName() == "printindex") {
959 inset = new InsetPrintIndex(this);
960 } else if (inscmd.getCmdName() == "lyxparent") {
961 inset = new InsetParent(inscmd.getContents(), this);
965 par->InsertChar(pos, LyXParagraph::META_INSET);
966 par->InsertInset(pos, inset);
967 par->SetFont(pos, font);
971 } else if (token == "\\InsetQuotes") {
972 lyxerr << "InsetQuotes" << endl;
973 Inset * inset = new InsetQuotes;
975 par->InsertChar(pos, LyXParagraph::META_INSET);
976 par->InsertInset(pos, inset);
977 par->SetFont(pos, font);
979 } else if (token == "\\InsetFormula") {
980 lyxerr << "InsetFormula" << endl;
981 Inset * inset = new InsetFormula;
983 par->InsertChar(pos, LyXParagraph::META_INSET);
984 par->InsertInset(pos, inset);
985 par->SetFont(pos, font);
987 } else if (token == "\\SpecialChar") {
988 LyXLayout const & layout =
989 textclasslist.Style(params.textclass,
992 // Insets don't make sense in a free-spacing context! ---Kayvan
993 if (layout.free_spacing) {
997 next_token = lex.GetString();
998 if (next_token == "\\-") {
999 par->InsertChar(pos, '-');
1000 par->SetFont(pos, font);
1001 } else if (next_token == "\\protected_separator") {
1002 par->InsertChar(pos, ' ');
1003 par->SetFont(pos, font);
1005 lex.printError("Token `$$Token' "
1007 "paragraph layout!");
1012 Inset * inset = new InsetSpecialChar;
1014 par->InsertChar(pos, LyXParagraph::META_INSET);
1015 par->InsertInset(pos, inset);
1016 par->SetFont(pos, font);
1019 } else if (token == "\\Figure") {
1020 lyxerr << "Figure" << endl;
1021 Inset * inset = new InsetFig(100, 100, this);
1023 par->InsertChar(pos, LyXParagraph::META_INSET);
1024 par->InsertInset(pos, inset);
1025 par->SetFont(pos, font);
1027 } else if (token == "\\newline") {
1028 par->InsertChar(pos, LyXParagraph::META_NEWLINE);
1029 par->SetFont(pos, font);
1031 } else if (token == "\\LyXTable") {
1032 par->table = new LyXTable(lex);
1033 } else if (token == "\\hfill") {
1034 par->InsertChar(pos, LyXParagraph::META_HFILL);
1035 par->SetFont(pos, font);
1037 } else if (token == "\\protected_separator") { // obsolete
1038 LyXLayout const & layout =
1039 textclasslist.Style(params.textclass,
1042 if (layout.free_spacing) {
1043 par->InsertChar(pos, ' ');
1044 par->SetFont(pos, font);
1046 Inset * inset = new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
1047 par->InsertChar(pos, LyXParagraph::META_INSET);
1048 par->InsertInset(pos, inset);
1049 par->SetFont(pos, font);
1052 } else if (token == "\\bibitem") { // ale970302
1054 par->bibkey = new InsetBibKey;
1055 par->bibkey->Read(lex);
1056 }else if (token == "\\backslash") {
1057 par->InsertChar(pos, '\\');
1058 par->SetFont(pos, font);
1060 }else if (token == "\\the_end") {
1061 the_end_read = true;
1063 // This should be insurance for the future: (Asger)
1064 lex.printError("Unknown token `$$Token'. "
1065 "Inserting as text.");
1066 for(string::const_iterator cit = token.begin();
1067 cit != token.end(); ++cit) {
1068 par->InsertChar(pos, (*cit));
1069 par->SetFont(pos, font);
1073 return the_end_read;
1076 bool Buffer::readFile(LyXLex & lex, LyXParagraph * par)
1082 token = lex.GetString();
1083 if (token == "\\lyxformat") { // the first token _must_ be...
1085 format = lex.GetFloat();
1087 if (LYX_FORMAT - format > 0.05) {
1088 printf(_("Warning: need lyxformat %.2f but found %.2f\n"),
1089 LYX_FORMAT, format);
1091 if (format - LYX_FORMAT > 0.05) {
1092 printf(_("ERROR: need lyxformat %.2f but found %.2f\n"),
1093 LYX_FORMAT, format);
1095 bool the_end = readLyXformat2(lex, par);
1096 // Formats >= 2.13 support "\the_end" marker
1103 WriteAlert(_("Warning!"),
1104 _("Reading of document is not complete"),
1105 _("Maybe the document is truncated"));
1106 // We simulate a safe reading anyways to allow
1107 // users to take the chance... (Asger)
1111 WriteAlert(_("ERROR!"),
1112 _("Old LyX file format found. "
1113 "Use LyX 0.10.x to read this!"));
1117 } else { // "\\lyxformat" not found
1118 WriteAlert(_("ERROR!"), _("Not a LyX file!"));
1121 WriteAlert(_("ERROR!"), _("Unable to read file!"));
1127 // Should probably be moved to somewhere else: BufferView? LyXView?
1128 bool Buffer::save() const
1130 // We don't need autosaves in the immediate future. (Asger)
1131 resetAutosaveTimers();
1135 if (lyxrc.make_backup) {
1136 s = fileName() + '~';
1137 if (!lyxrc.backupdir_path.empty())
1138 s = AddName(lyxrc.backupdir_path,
1139 subst(CleanupPath(s),'/','!'));
1141 // Rename is the wrong way of making a backup,
1142 // this is the correct way.
1143 /* truss cp fil fil2:
1144 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
1145 stat("LyXVC.lyx", 0xEFFFF688) = 0
1146 open("LyXVC.lyx", O_RDONLY) = 3
1147 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
1148 fstat(4, 0xEFFFF508) = 0
1149 fstat(3, 0xEFFFF508) = 0
1150 read(3, " # T h i s f i l e w".., 8192) = 5579
1151 write(4, " # T h i s f i l e w".., 5579) = 5579
1152 read(3, 0xEFFFD4A0, 8192) = 0
1155 chmod("LyXVC3.lyx", 0100644) = 0
1156 lseek(0, 0, SEEK_CUR) = 46440
1160 // Should proabaly have some more error checking here.
1161 // Should be cleaned up in 0.13, at least a bit.
1162 // Doing it this way, also makes the inodes stay the same.
1163 // This is still not a very good solution, in particular we
1164 // might loose the owner of the backup.
1165 FileInfo finfo(fileName());
1166 if (finfo.exist()) {
1167 mode_t fmode = finfo.getMode();
1168 struct utimbuf times = {
1169 finfo.getAccessTime(),
1170 finfo.getModificationTime() };
1172 ifstream ifs(fileName().c_str());
1173 ofstream ofs(s.c_str(), ios::out|ios::trunc);
1178 ::chmod(s.c_str(), fmode);
1180 if (::utime(s.c_str(), ×)) {
1181 lyxerr << "utime error." << endl;
1184 lyxerr << "LyX was not able to make "
1185 "backupcopy. Beware." << endl;
1190 if (writeFile(fileName(), false)) {
1193 // now delete the autosavefile
1194 string a = OnlyPath(fileName());
1196 a += OnlyFilename(fileName());
1198 FileInfo fileinfo(a);
1199 if (fileinfo.exist()) {
1200 if (::remove(a.c_str()) != 0) {
1201 WriteFSAlert(_("Could not delete "
1202 "auto-save file!"), a);
1206 // Saving failed, so backup is not backup
1207 if (lyxrc.make_backup) {
1208 ::rename(s.c_str(), fileName().c_str());
1216 // Returns false if unsuccesful
1217 bool Buffer::writeFile(string const & fname, bool flag) const
1219 // if flag is false writeFile will not create any GUI
1220 // warnings, only cerr.
1221 // Needed for autosave in background or panic save (Matthias 120496)
1223 if (read_only && (fname == filename)) {
1224 // Here we should come with a question if we should
1225 // perform the write anyway.
1227 lyxerr << _("Error! Document is read-only: ")
1230 WriteAlert(_("Error! Document is read-only: "),
1235 FileInfo finfo(fname);
1236 if (finfo.exist() && !finfo.writable()) {
1237 // Here we should come with a question if we should
1238 // try to do the save anyway. (i.e. do a chmod first)
1240 lyxerr << _("Error! Cannot write file: ")
1243 WriteFSAlert(_("Error! Cannot write file: "),
1248 ofstream ofs(fname.c_str());
1251 lyxerr << _("Error! Cannot open file: ")
1254 WriteFSAlert(_("Error! Cannot open file: "),
1258 // The top of the file should not be written by params.
1260 // write out a comment in the top of the file
1261 ofs << '#' << LYX_DOCVERSION
1262 << " created this file. For more info see http://www.lyx.org/\n";
1263 ofs.setf(ios::showpoint|ios::fixed);
1265 ofs << "\\lyxformat " << setw(4) << LYX_FORMAT << "\n";
1267 // now write out the buffer paramters.
1268 params.writeFile(ofs);
1270 char footnoteflag = 0;
1273 // this will write out all the paragraphs
1274 // using recursive descent.
1275 paragraph->writeFile(ofs, params, footnoteflag, depth);
1277 // Write marker that shows file is complete
1278 ofs << "\n\\the_end" << endl;
1280 // how to check if close went ok?
1285 void Buffer::writeFileAscii(string const & fname, int linelen)
1287 LyXFont font1, font2;
1289 char c, footnoteflag = 0, depth = 0;
1291 LyXParagraph::size_type i;
1292 int j, h, ltype = 0, ltype_depth = 0,
1293 * clen = 0, actcell = 0, actpos = 0, cell = 0, cells = 0,
1296 bool ref_printed = false;
1298 ofstream ofs(fname.c_str());
1300 WriteFSAlert(_("Error: Cannot write file:"), fname);
1304 string fname1 = TmpFileName();
1305 LyXParagraph * par = paragraph;
1309 if (par->footnoteflag != LyXParagraph::NO_FOOTNOTE ||
1311 par->previous->footnoteflag == LyXParagraph::NO_FOOTNOTE){
1313 /* begins a footnote environment ? */
1314 if (footnoteflag != par->footnoteflag) {
1315 footnoteflag = par->footnoteflag;
1317 j = strlen(string_footnotekinds[par->footnotekind])+4;
1318 if (currlinelen + j > linelen)
1321 << string_footnotekinds[par->footnotekind] << "] ";
1326 /* begins or ends a deeper area ?*/
1327 if (depth != par->depth) {
1328 if (par->depth > depth) {
1329 while (par->depth > depth) {
1334 while (par->depth < depth) {
1340 /* First write the layout */
1341 tmp = textclasslist.NameOfLayout(params.textclass, par->layout);
1342 if (tmp == "Itemize") {
1344 ltype_depth = depth+1;
1345 } else if (tmp == "Enumerate") {
1347 ltype_depth = depth+1;
1348 } else if (strstr(tmp.c_str(), "ection")) {
1350 ltype_depth = depth+1;
1351 } else if (strstr(tmp.c_str(), "aragraph")) {
1353 ltype_depth = depth+1;
1354 } else if (tmp == "Description") {
1356 ltype_depth = depth+1;
1357 } else if (tmp == "Abstract") {
1360 } else if (tmp == "Bibliography") {
1368 /* maybe some vertical spaces */
1370 /* the labelwidthstring used in lists */
1374 /* some pagebreaks? */
1378 /* what about the alignment */
1381 /* dummy layout, that means a footnote ended */
1382 footnoteflag = LyXParagraph::NO_FOOTNOTE;
1387 LyXLayout const & layout =
1388 textclasslist.Style(params.textclass,
1390 //bool free_spc = layout.free_spacing; //unused
1392 /* It might be a table */
1395 if (!lyxrc.ascii_roff_command.empty() &&
1396 lyxrc.ascii_roff_command != "none") {
1397 RoffAsciiTable(ofs, par);
1404 cells = par->table->columns;
1405 clen = new int [cells];
1406 memset(clen, 0, sizeof(int) * cells);
1408 for (i = 0, j = 0, h = 1; i < par->size(); ++i, ++h) {
1409 c = par->GetChar(i);
1410 if (c == LyXParagraph::META_INSET) {
1411 if ((inset = par->GetInset(i))) {
1413 std::ostringstream ost;
1415 h += ost.str().length();
1420 char * tmp = ost.str();
1426 } else if (c == LyXParagraph::META_NEWLINE) {
1430 j = (++j) % par->table->NumberOfCellsInRow(actcell);
1438 font1 = LyXFont(LyXFont::ALL_INHERIT,params.language_info);
1440 for (i = 0, actpos = 1; i < par->size(); ++i, ++actpos) {
1441 if (!i && !footnoteflag && !noparbreak){
1443 for(j = 0; j < depth; ++j)
1445 currlinelen = depth * 2;
1447 case 0: /* Standard */
1448 case 4: /* (Sub)Paragraph */
1449 case 5: /* Description */
1451 case 6: /* Abstract */
1452 ofs << "Abstract\n\n";
1454 case 7: /* Bibliography */
1456 ofs << "References\n\n";
1461 ofs << par->labelstring << " ";
1464 if (ltype_depth > depth) {
1465 for(j = ltype_depth - 1; j > depth; --j)
1467 currlinelen += (ltype_depth-depth)*2;
1470 for(j = 0; j < cells; ++j) {
1472 for(h = 0; h < (clen[j] + 1);
1477 for(j = 0; j < depth; ++j)
1479 currlinelen = depth * 2;
1480 if (ltype_depth > depth) {
1481 for(j = ltype_depth;
1484 currlinelen += (ltype_depth-depth)*2;
1489 font2 = par->GetFontSettings(i);
1490 if (font1.latex() != font2.latex()) {
1491 if (font2.latex() == LyXFont::OFF)
1499 c = par->GetChar(i);
1503 case LyXParagraph::META_INSET:
1504 if ((inset = par->GetInset(i))) {
1507 currlinelen += (ofs.tellp() - fpos);
1508 actpos += (ofs.tellp() - fpos) - 1;
1511 case LyXParagraph::META_NEWLINE:
1513 if (par->table->NumberOfCellsInRow(actcell) <= cell) {
1514 for(j = actpos; j < clen[cell - 1]; ++j)
1517 for(j = 0; j < depth; ++j)
1519 currlinelen = depth*2;
1520 if (ltype_depth > depth) {
1521 for(j = ltype_depth; j > depth; --j)
1523 currlinelen += (ltype_depth-depth) * 2;
1525 for(j = 0; j < cells; ++j) {
1527 for(h = 0; h < (clen[j] + 1); ++h)
1531 for(j = 0; j < depth; ++j)
1533 currlinelen = depth * 2;
1534 if (ltype_depth > depth) {
1535 for(j = ltype_depth;
1538 currlinelen += (ltype_depth-depth)*2;
1544 j < clen[cell - 1]; ++j)
1550 currlinelen = actpos = 0;
1553 for(j = 0; j < depth; ++j)
1555 currlinelen = depth * 2;
1556 if (ltype_depth > depth) {
1557 for(j = ltype_depth;
1560 currlinelen += (ltype_depth - depth) * 2;
1564 case LyXParagraph::META_HFILL:
1571 if (currlinelen > linelen - 10
1572 && c == ' ' && i + 2 < par->size()) {
1574 for(j = 0; j < depth; ++j)
1576 currlinelen = depth * 2;
1577 if (ltype_depth > depth) {
1578 for(j = ltype_depth;
1581 currlinelen += (ltype_depth-depth)*2;
1583 } else if (c != '\0')
1586 lyxerr.debug() << "writeAsciiFile: NULL char in structure." << endl;
1592 for(j = actpos; j < clen[cell - 1]; ++j)
1595 for(j = 0; j < depth; ++j)
1597 currlinelen = depth * 2;
1598 if (ltype_depth > depth) {
1599 for(j = ltype_depth; j > depth; --j)
1601 currlinelen += (ltype_depth - depth) * 2;
1603 for(j = 0; j < cells; ++j) {
1605 for(h = 0; h < (clen[j] + 1); ++h)
1618 void Buffer::makeLaTeXFile(string const & fname,
1619 string const & original_path,
1620 bool nice, bool only_body)
1622 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
1624 niceFile = nice; // this will be used by Insetincludes.
1626 tex_code_break_column = lyxrc.ascii_linelen;
1628 LyXTextClass const & tclass =
1629 textclasslist.TextClass(params.textclass);
1631 ofstream ofs(fname.c_str());
1633 WriteFSAlert(_("Error: Cannot open file: "), fname);
1637 // validate the buffer.
1638 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
1639 LaTeXFeatures features(params, tclass.numLayouts());
1641 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
1644 // The starting paragraph of the coming rows is the
1645 // first paragraph of the document. (Asger)
1646 texrow.start(paragraph, 0);
1648 if (!only_body && nice) {
1649 ofs << "%% " LYX_DOCVERSION " created this file. "
1650 "For more info, see http://www.lyx.org/.\n"
1651 "%% Do not edit unless you really know what "
1656 lyxerr.debug() << "lyx header finished" << endl;
1657 // There are a few differences between nice LaTeX and usual files:
1658 // usual is \batchmode and has a
1659 // special input@path to allow the including of figures
1660 // with either \input or \includegraphics (what figinsets do).
1661 // batchmode is not set if there is a tex_code_break_column.
1662 // In this case somebody is interested in the generated LaTeX,
1663 // so this is OK. input@path is set when the actual parameter
1664 // original_path is set. This is done for usual tex-file, but not
1665 // for nice-latex-file. (Matthias 250696)
1668 // code for usual, NOT nice-latex-file
1669 ofs << "\\batchmode\n"; // changed
1670 // from \nonstopmode
1673 if (!original_path.empty()) {
1674 ofs << "\\makeatletter\n"
1675 << "\\def\\input@path{{"
1676 << original_path << "/}}\n"
1677 << "\\makeatother\n";
1683 ofs << "\\documentclass";
1685 string options; // the document class options.
1687 if (tokenPos(tclass.opt_fontsize(), '|', params.fontsize) >= 0) {
1688 // only write if existing in list (and not default)
1689 options += params.fontsize;
1694 if (!params.use_geometry &&
1695 (params.paperpackage == BufferParams::PACKAGE_NONE)) {
1696 switch (params.papersize) {
1697 case BufferParams::PAPER_A4PAPER:
1698 options += "a4paper,";
1700 case BufferParams::PAPER_USLETTER:
1701 options += "letterpaper,";
1703 case BufferParams::PAPER_A5PAPER:
1704 options += "a5paper,";
1706 case BufferParams::PAPER_B5PAPER:
1707 options += "b5paper,";
1709 case BufferParams::PAPER_EXECUTIVEPAPER:
1710 options += "executivepaper,";
1712 case BufferParams::PAPER_LEGALPAPER:
1713 options += "legalpaper,";
1719 if (params.sides != tclass.sides()) {
1720 switch (params.sides) {
1721 case LyXTextClass::OneSide:
1722 options += "oneside,";
1724 case LyXTextClass::TwoSides:
1725 options += "twoside,";
1732 if (params.columns != tclass.columns()) {
1733 if (params.columns == 2)
1734 options += "twocolumn,";
1736 options += "onecolumn,";
1739 if (!params.use_geometry
1740 && params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1741 options += "landscape,";
1743 // language should be a parameter to \documentclass
1744 bool use_babel = false;
1745 if (params.language != "default" ||
1746 !features.UsedLanguages.empty() ) {
1748 for (LaTeXFeatures::LanguageList::const_iterator cit =
1749 features.UsedLanguages.begin();
1750 cit != features.UsedLanguages.end(); ++cit) {
1751 options += (*cit)->lang + ",";
1753 if (default_language != params.language_info)
1754 options += default_language ->lang + ',';
1755 options += params.language_info->lang + ',';
1758 // the user-defined options
1759 if (!params.options.empty()) {
1760 options += params.options + ',';
1763 if (!options.empty()){
1764 options = strip(options, ',');
1765 ofs << '[' << options << ']';
1769 << textclasslist.LatexnameOfClass(params.textclass)
1772 // end of \documentclass defs
1774 // font selection must be done before loading fontenc.sty
1775 if (params.fonts != "default") {
1776 ofs << "\\usepackage{" << params.fonts << "}\n";
1779 // this one is not per buffer
1780 if (lyxrc.fontenc != "default") {
1781 ofs << "\\usepackage[" << lyxrc.fontenc
1785 if (params.inputenc != "default") {
1786 ofs << "\\usepackage[" << params.inputenc
1791 /* at the very beginning the text parameters */
1792 if (params.paperpackage != BufferParams::PACKAGE_NONE) {
1793 switch (params.paperpackage) {
1794 case BufferParams::PACKAGE_A4:
1795 ofs << "\\usepackage{a4}\n";
1798 case BufferParams::PACKAGE_A4WIDE:
1799 ofs << "\\usepackage{a4wide}\n";
1802 case BufferParams::PACKAGE_WIDEMARGINSA4:
1803 ofs << "\\usepackage[widemargins]{a4}\n";
1808 if (params.use_geometry) {
1809 ofs << "\\usepackage{geometry}\n";
1811 ofs << "\\geometry{verbose";
1812 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1813 ofs << ",landscape";
1814 switch (params.papersize2) {
1815 case BufferParams::VM_PAPER_CUSTOM:
1816 if (!params.paperwidth.empty())
1817 ofs << ",paperwidth="
1818 << params.paperwidth;
1819 if (!params.paperheight.empty())
1820 ofs << ",paperheight="
1821 << params.paperheight;
1823 case BufferParams::VM_PAPER_USLETTER:
1824 ofs << ",letterpaper";
1826 case BufferParams::VM_PAPER_USLEGAL:
1827 ofs << ",legalpaper";
1829 case BufferParams::VM_PAPER_USEXECUTIVE:
1830 ofs << ",executivepaper";
1832 case BufferParams::VM_PAPER_A3:
1835 case BufferParams::VM_PAPER_A4:
1838 case BufferParams::VM_PAPER_A5:
1841 case BufferParams::VM_PAPER_B3:
1844 case BufferParams::VM_PAPER_B4:
1847 case BufferParams::VM_PAPER_B5:
1851 // default papersize ie BufferParams::VM_PAPER_DEFAULT
1852 switch (lyxrc.default_papersize) {
1853 case BufferParams::PAPER_DEFAULT: // keep compiler happy
1854 case BufferParams::PAPER_USLETTER:
1855 ofs << ",letterpaper";
1857 case BufferParams::PAPER_LEGALPAPER:
1858 ofs << ",legalpaper";
1860 case BufferParams::PAPER_EXECUTIVEPAPER:
1861 ofs << ",executivepaper";
1863 case BufferParams::PAPER_A3PAPER:
1866 case BufferParams::PAPER_A4PAPER:
1869 case BufferParams::PAPER_A5PAPER:
1872 case BufferParams::PAPER_B5PAPER:
1877 if (!params.topmargin.empty())
1878 ofs << ",tmargin=" << params.topmargin;
1879 if (!params.bottommargin.empty())
1880 ofs << ",bmargin=" << params.bottommargin;
1881 if (!params.leftmargin.empty())
1882 ofs << ",lmargin=" << params.leftmargin;
1883 if (!params.rightmargin.empty())
1884 ofs << ",rmargin=" << params.rightmargin;
1885 if (!params.headheight.empty())
1886 ofs << ",headheight=" << params.headheight;
1887 if (!params.headsep.empty())
1888 ofs << ",headsep=" << params.headsep;
1889 if (!params.footskip.empty())
1890 ofs << ",footskip=" << params.footskip;
1894 if (params.use_amsmath
1895 && !prefixIs(textclasslist.LatexnameOfClass(params.textclass), "ams")) {
1896 ofs << "\\usepackage{amsmath}\n";
1900 if (tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle) >= 0) {
1901 if (params.pagestyle == "fancy") {
1902 ofs << "\\usepackage{fancyhdr}\n";
1905 ofs << "\\pagestyle{" << params.pagestyle << "}\n";
1909 // We try to load babel late, in case it interferes
1910 // with other packages.
1912 ofs << lyxrc.language_package << endl;
1916 if (params.secnumdepth != tclass.secnumdepth()) {
1917 ofs << "\\setcounter{secnumdepth}{"
1918 << params.secnumdepth
1922 if (params.tocdepth != tclass.tocdepth()) {
1923 ofs << "\\setcounter{tocdepth}{"
1929 if (params.paragraph_separation) {
1930 switch (params.defskip.kind()) {
1931 case VSpace::SMALLSKIP:
1932 ofs << "\\setlength\\parskip{\\smallskipamount}\n";
1934 case VSpace::MEDSKIP:
1935 ofs << "\\setlength\\parskip{\\medskipamount}\n";
1937 case VSpace::BIGSKIP:
1938 ofs << "\\setlength\\parskip{\\bigskipamount}\n";
1940 case VSpace::LENGTH:
1941 ofs << "\\setlength\\parskip{"
1942 << params.defskip.length().asLatexString()
1945 default: // should never happen // Then delete it.
1946 ofs << "\\setlength\\parskip{\\medskipamount}\n";
1951 ofs << "\\setlength\\parindent{0pt}\n";
1955 // Now insert the LyX specific LaTeX commands...
1956 string preamble, tmppreamble;
1958 // The optional packages;
1959 preamble = features.getPackages();
1961 // this might be useful...
1962 preamble += "\n\\makeatletter\n\n";
1964 // Some macros LyX will need
1965 tmppreamble = features.getMacros();
1967 if (!tmppreamble.empty()) {
1968 preamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1969 "LyX specific LaTeX commands.\n"
1970 + tmppreamble + '\n';
1973 // the text class specific preamble
1974 tmppreamble = features.getTClassPreamble();
1975 if (!tmppreamble.empty()) {
1976 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1977 "Textclass specific LaTeX commands.\n"
1978 + tmppreamble + '\n';
1981 /* the user-defined preamble */
1982 if (!params.preamble.empty()) {
1983 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1984 "User specified LaTeX commands.\n"
1985 + params.preamble + '\n';
1988 preamble += "\\makeatother\n\n";
1990 // Itemize bullet settings need to be last in case the user
1991 // defines their own bullets that use a package included
1992 // in the user-defined preamble -- ARRae
1993 // Actually it has to be done much later than that
1994 // since some packages like frenchb make modifications
1995 // at \begin{document} time -- JMarc
1997 for (int i = 0; i < 4; ++i) {
1998 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
1999 if (bullets_def.empty())
2000 bullets_def="\\AtBeginDocument{\n";
2001 bullets_def += " \\renewcommand{\\labelitemi";
2003 // `i' is one less than the item to modify
2010 bullets_def += "ii";
2016 bullets_def += "}{" +
2017 params.user_defined_bullets[i].getText()
2022 if (!bullets_def.empty())
2023 preamble += bullets_def + "}\n\n";
2025 for (int j = countChar(preamble, '\n'); j-- ;) {
2032 ofs << "\\begin{document}\n\n";
2036 lyxerr.debug() << "preamble finished, now the body." << endl;
2037 if (!lyxrc.language_auto_begin && params.language != "default") {
2038 ofs << subst(lyxrc.language_command_begin, "$$lang",
2044 bool was_title = false;
2045 bool already_title = false;
2047 std::ostringstream ftnote;
2049 char * tmpholder = 0;
2054 LyXParagraph * par = paragraph;
2058 #ifndef HAVE_SSTREAM
2061 ftnote << tmpholder;
2062 delete [] tmpholder;
2067 lyxerr[Debug::LATEX] << "Error in MakeLateXFile."
2069 LyXLayout const & layout =
2070 textclasslist.Style(params.textclass,
2073 if (layout.intitle) {
2074 if (already_title) {
2075 lyxerr <<"Error in MakeLatexFile: You"
2076 " should not mix title layouts"
2077 " with normal ones." << endl;
2080 } else if (was_title && !already_title) {
2081 ofs << "\\maketitle\n";
2083 already_title = true;
2086 // We are at depth 0 so we can just use
2087 // ordinary \footnote{} generation
2088 // flag this with ftcount
2090 if (layout.isEnvironment()
2091 || par->pextra_type != LyXParagraph::PEXTRA_NONE) {
2092 par = par->TeXEnvironment(ofs, texrow,
2093 ftnote, ft_texrow, ftcount);
2095 par = par->TeXOnePar(ofs, texrow,
2096 ftnote, ft_texrow, ftcount);
2099 // Write out what we've generated...
2102 ofs << "\\addtocounter{footnote}{-"
2106 ofs << ftnote.str();
2107 texrow += ft_texrow;
2109 // The extra .c_str() is needed when we use
2110 // lyxstring instead of the STL string class.
2111 ftnote.str(string().c_str());
2113 delete [] ftnote.str();
2118 #ifndef HAVE_SSTREAM
2120 // I hate strstreams
2121 tmpholder = ftnote.str();
2125 #ifndef HAVE_SSTREAM
2126 delete [] tmpholder;
2128 // It might be that we only have a title in this document
2129 if (was_title && !already_title) {
2130 ofs << "\\maketitle\n";
2134 if (!lyxrc.language_auto_end && params.language != "default") {
2135 ofs << subst(lyxrc.language_command_end, "$$lang",
2142 ofs << "\\end{document}\n";
2145 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
2147 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
2151 // Just to be sure. (Asger)
2154 // tex_code_break_column's value is used to decide
2155 // if we are in batchmode or not (within mathed_write()
2156 // in math_write.C) so we must set it to a non-zero
2157 // value when we leave otherwise we save incorrect .lyx files.
2158 tex_code_break_column = lyxrc.ascii_linelen;
2162 lyxerr << "File was not closed properly." << endl;
2165 lyxerr.debug() << "Finished making latex file." << endl;
2169 bool Buffer::isLatex() const
2171 return textclasslist.TextClass(params.textclass).outputType() == LATEX;
2175 bool Buffer::isLinuxDoc() const
2177 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC;
2181 bool Buffer::isLiterate() const
2183 return textclasslist.TextClass(params.textclass).outputType() == LITERATE;
2187 bool Buffer::isDocBook() const
2189 return textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2193 bool Buffer::isSGML() const
2195 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC ||
2196 textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2200 void Buffer::sgmlOpenTag(ostream & os, int depth,
2201 string const & latexname) const
2203 os << string(depth, ' ') << "<" << latexname << ">\n";
2207 void Buffer::sgmlCloseTag(ostream & os, int depth,
2208 string const & latexname) const
2210 os << string(depth, ' ') << "</" << latexname << ">\n";
2214 void Buffer::makeLinuxDocFile(string const & fname, int column)
2216 LyXParagraph * par = paragraph;
2218 string top_element = textclasslist.LatexnameOfClass(params.textclass);
2219 string environment_stack[10];
2222 int depth = 0; /* paragraph depth */
2224 ofstream ofs(fname.c_str());
2227 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2231 tex_code_break_column = column;
2234 if (params.preamble.empty()) {
2235 ofs << "<!doctype linuxdoc system>\n\n";
2238 ofs << "<!doctype linuxdoc system \n [ "
2239 << params.preamble << " \n]>\n\n";
2242 ofs << "<!-- " << LYX_DOCVERSION
2243 << " created this file. For more info see http://www.lyx.org/"
2246 if(params.options.empty())
2247 sgmlOpenTag(ofs, 0, top_element);
2249 string top = top_element;
2251 top += params.options;
2252 sgmlOpenTag(ofs, 0, top);
2256 int desc_on = 0; /* description mode*/
2257 LyXLayout const & style =
2258 textclasslist.Style(users->buffer()->params.textclass,
2260 par->AutoDeleteInsets();
2262 /* treat <toc> as a special case for compatibility with old code */
2263 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2264 Inset * inset = par->GetInset(0);
2265 char lyx_code = inset->LyxCode();
2266 if (lyx_code == Inset::TOC_CODE){
2267 string temp = "toc";
2268 sgmlOpenTag(ofs, depth, temp);
2271 linuxDocHandleFootnote(ofs, par, depth);
2276 // environment tag closing
2277 for( ; depth > par->depth; --depth) {
2278 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2279 environment_stack[depth].clear();
2282 // write opening SGML tags
2283 switch(style.latextype) {
2284 case LATEX_PARAGRAPH:
2285 if(depth == par->depth
2286 && !environment_stack[depth].empty()) {
2287 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2288 environment_stack[depth].clear();
2294 sgmlOpenTag(ofs, depth, style.latexname());
2299 LinuxDocError(par, 0, _("Error : Wrong depth for LatexType Command.\n"));
2301 if (!environment_stack[depth].empty()){
2302 sgmlCloseTag(ofs, depth,
2303 environment_stack[depth]);
2307 environment_stack[depth].clear();
2308 sgmlOpenTag(ofs, depth, style.latexname());
2311 case LATEX_ENVIRONMENT:
2312 case LATEX_ITEM_ENVIRONMENT:
2313 if(depth == par->depth
2314 && environment_stack[depth] != style.latexname()
2315 && !environment_stack[depth].empty()) {
2317 sgmlCloseTag(ofs, depth,
2318 environment_stack[depth]);
2319 environment_stack[depth].clear();
2321 if (depth < par->depth) {
2323 environment_stack[depth].clear();
2325 if (environment_stack[depth] != style.latexname()) {
2328 sgmlOpenTag(ofs, depth, temp);
2330 environment_stack[depth] = style.latexname();
2331 sgmlOpenTag(ofs, depth, environment_stack[depth]);
2333 if(style.latextype == LATEX_ENVIRONMENT) break;
2335 desc_on = (style.labeltype == LABEL_MANUAL);
2342 sgmlOpenTag(ofs, depth + 1, item_name);
2345 sgmlOpenTag(ofs, depth, style.latexname());
2350 SimpleLinuxDocOnePar(ofs, par, desc_on, depth);
2353 linuxDocHandleFootnote(ofs, par, depth);
2355 while(par && par->IsDummy());
2358 /* write closing SGML tags */
2359 switch(style.latextype) {
2361 case LATEX_ENVIRONMENT:
2362 case LATEX_ITEM_ENVIRONMENT:
2365 sgmlCloseTag(ofs, depth, style.latexname());
2370 /* Close open tags */
2371 for(; depth > 0; --depth)
2372 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2374 if(!environment_stack[depth].empty())
2375 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2378 sgmlCloseTag(ofs, 0, top_element);
2381 // How to check for successful close
2385 void Buffer::linuxDocHandleFootnote(ostream & os, LyXParagraph * & par,
2388 string tag = "footnote";
2390 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2391 sgmlOpenTag(os, depth + 1, tag);
2392 SimpleLinuxDocOnePar(os, par, 0, depth + 1);
2393 sgmlCloseTag(os, depth + 1, tag);
2399 void Buffer::DocBookHandleCaption(ostream & os, string & inner_tag,
2400 int const depth, int desc_on,
2401 LyXParagraph * & par)
2403 LyXParagraph * tpar = par;
2404 while (tpar && (tpar->footnoteflag != LyXParagraph::NO_FOOTNOTE) &&
2405 (tpar->layout != textclasslist.NumberOfLayout(params.textclass,
2409 tpar->layout == textclasslist.NumberOfLayout(params.textclass,
2410 "Caption").second) {
2411 sgmlOpenTag(os, depth + 1, inner_tag);
2413 SimpleDocBookOnePar(os, extra_par, tpar,
2414 desc_on, depth + 2);
2415 sgmlCloseTag(os, depth+1, inner_tag);
2416 if(!extra_par.empty())
2422 void Buffer::DocBookHandleFootnote(ostream & os, LyXParagraph * & par,
2425 string tag, inner_tag;
2426 string tmp_par, extra_par;
2427 bool inner_span = false;
2430 // Someone should give this enum a proper name (Lgb)
2438 SOME_ENUM last = NO_ONE;
2439 SOME_ENUM present = FOOTNOTE_LIKE;
2441 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2442 if(last == present) {
2444 if(!tmp_par.empty()) {
2447 sgmlCloseTag(os, depth + 1, inner_tag);
2448 sgmlOpenTag(os, depth + 1, inner_tag);
2455 if(!inner_tag.empty()) sgmlCloseTag(os, depth + 1,
2457 if(!extra_par.empty()) os << extra_par;
2458 if(!tag.empty()) sgmlCloseTag(os, depth, tag);
2461 switch (par->footnotekind) {
2462 case LyXParagraph::FOOTNOTE:
2463 case LyXParagraph::ALGORITHM:
2466 present = FOOTNOTE_LIKE;
2469 case LyXParagraph::MARGIN:
2472 present = MARGIN_LIKE;
2475 case LyXParagraph::FIG:
2476 case LyXParagraph::WIDE_FIG:
2478 inner_tag = "title";
2482 case LyXParagraph::TAB:
2483 case LyXParagraph::WIDE_TAB:
2485 inner_tag = "title";
2490 sgmlOpenTag(os, depth, tag);
2491 if ((present == TAB_LIKE) || (present == FIG_LIKE)) {
2492 DocBookHandleCaption(os, inner_tag, depth,
2496 sgmlOpenTag(os, depth + 1, inner_tag);
2499 // ignore all caption here, we processed them above!!!
2500 if (par->layout != textclasslist
2501 .NumberOfLayout(params.textclass,
2502 "Caption").second) {
2504 std::ostringstream ost;
2508 SimpleDocBookOnePar(ost, extra_par, par,
2509 desc_on, depth + 2);
2511 tmp_par += ost.str().c_str();
2514 char * ctmp = ost.str();
2519 tmp_par = frontStrip(strip(tmp_par));
2525 if(!inner_tag.empty()) sgmlCloseTag(os, depth + 1, inner_tag);
2526 if(!extra_par.empty()) os << extra_par;
2527 if(!tag.empty()) sgmlCloseTag(os, depth, tag);
2531 /* push a tag in a style stack */
2532 void Buffer::push_tag(ostream & os, char const * tag,
2533 int & pos, char stack[5][3])
2535 /* pop all previous tags */
2536 for (int j = pos; j >= 0; --j)
2537 os << "</" << stack[j] << ">";
2540 sprintf(stack[++pos], "%s", tag);
2543 for (int i = 0; i <= pos; ++i)
2544 os << "<" << stack[i] << ">";
2548 void Buffer::pop_tag(ostream & os, char const * tag,
2549 int & pos, char stack[5][3])
2553 // pop all tags till specified one
2554 for (j = pos; (j >= 0) && (strcmp(stack[j], tag)); --j)
2555 os << "</" << stack[j] << ">";
2558 os << "</" << tag << ">";
2560 // push all tags, but the specified one
2561 for (j = j + 1; j <= pos; ++j) {
2562 os << "<" << stack[j] << ">";
2563 strcpy(stack[j-1], stack[j]);
2569 /* handle internal paragraph parsing -- layout already processed */
2571 // checks, if newcol chars should be put into this line
2572 // writes newline, if necessary.
2574 void linux_doc_line_break(ostream & os, unsigned int & colcount,
2575 const unsigned int newcol)
2578 if (colcount > lyxrc.ascii_linelen) {
2580 colcount = newcol; // assume write after this call
2585 void Buffer::SimpleLinuxDocOnePar(ostream & os, LyXParagraph * par,
2586 int desc_on, int const /*depth*/)
2588 LyXFont font1, font2;
2591 LyXParagraph::size_type main_body;
2593 LyXLayout const & style = textclasslist.Style(params.textclass,
2596 char family_type = 0; // family font flag
2597 bool is_bold = false; // series font flag
2598 char shape_type = 0; // shape font flag
2599 bool is_em = false; // emphasis (italic) font flag
2601 int stack_num = -1; // style stack position
2602 char stack[5][3]; // style stack
2603 unsigned int char_line_count = 5; // Heuristic choice ;-)
2605 if (style.labeltype != LABEL_MANUAL)
2608 main_body = par->BeginningOfMainBody();
2610 /* gets paragraph main font */
2612 font1 = style.labelfont;
2617 /* parsing main loop */
2618 for (LyXParagraph::size_type i = 0;
2619 i < par->size(); ++i) {
2621 /* handle quote tag */
2622 if (i == main_body && !par->IsDummy()) {
2627 font2 = par->getFont(i);
2629 if (font1.family() != font2.family()) {
2630 switch(family_type) {
2632 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2633 push_tag(os, "tt", stack_num, stack);
2636 else if (font2.family() == LyXFont::SANS_FAMILY) {
2637 push_tag(os, "sf", stack_num, stack);
2642 pop_tag(os, "tt", stack_num, stack);
2643 if (font2.family() == LyXFont::SANS_FAMILY) {
2644 push_tag(os, "sf", stack_num, stack);
2652 pop_tag(os, "sf", stack_num, stack);
2653 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2654 push_tag(os, "tt", stack_num, stack);
2663 /* handle bold face */
2664 if (font1.series() != font2.series()) {
2665 if (font2.series() == LyXFont::BOLD_SERIES) {
2666 push_tag(os, "bf", stack_num, stack);
2670 pop_tag(os, "bf", stack_num, stack);
2675 /* handle italic and slanted fonts */
2676 if (font1.shape() != font2.shape()) {
2677 switch(shape_type) {
2679 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2680 push_tag(os, "it", stack_num, stack);
2683 else if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2684 push_tag(os, "sl", stack_num, stack);
2689 pop_tag(os, "it", stack_num, stack);
2690 if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2691 push_tag(os, "sl", stack_num, stack);
2699 pop_tag(os, "sl", stack_num, stack);
2700 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2701 push_tag(os, "it", stack_num, stack);
2709 /* handle <em> tag */
2710 if (font1.emph() != font2.emph()) {
2711 if (font2.emph() == LyXFont::ON) {
2712 push_tag(os, "em", stack_num, stack);
2715 pop_tag(os, "em", stack_num, stack);
2720 c = par->GetChar(i);
2722 if (font2.latex() == LyXFont::ON) {
2723 // "TeX"-Mode on == > SGML-Mode on.
2725 os << c; // see LaTeX-Generation...
2727 } else if (c == LyXParagraph::META_INSET) {
2728 inset = par->GetInset(i);
2729 inset->Linuxdoc(os);
2732 if (par->linuxDocConvertChar(c, sgml_string)
2733 && !style.free_spacing) { // in freespacing
2735 // non-breaking characters
2739 linux_doc_line_break(os, char_line_count, 6);
2744 linux_doc_line_break(os, char_line_count, 1);
2750 char_line_count += sgml_string.length();
2756 /* needed if there is an optional argument but no contents */
2757 if (main_body > 0 && main_body == par->size()) {
2761 /* pop all defined Styles */
2762 for (j = stack_num; j >= 0; --j) {
2763 linux_doc_line_break(os,
2765 3 + strlen(stack[j]));
2766 os << "</" << stack[j] << ">";
2769 /* resets description flag correctly */
2772 /* <tag> not closed... */
2773 linux_doc_line_break(os, char_line_count, 6);
2777 /* fprintf(file, "</p>");*/
2783 /* print an error message */
2784 void Buffer::LinuxDocError(LyXParagraph * par, int pos,
2785 char const * message)
2787 InsetError * new_inset;
2789 /* insert an error marker in text */
2790 new_inset = new InsetError(message);
2791 par->InsertChar(pos, LyXParagraph::META_INSET);
2792 par->InsertInset(pos, new_inset);
2795 // This constant defines the maximum number of
2796 // environment layouts that can be nesteded.
2797 // The same applies for command layouts.
2798 // These values should be more than enough.
2799 // José Matos (1999/07/22)
2801 enum { MAX_NEST_LEVEL = 25};
2803 void Buffer::makeDocBookFile(string const & fname, int column)
2805 LyXParagraph * par = paragraph;
2807 string top_element= textclasslist.LatexnameOfClass(params.textclass);
2808 string environment_stack[MAX_NEST_LEVEL];
2809 string environment_inner[MAX_NEST_LEVEL];
2810 string command_stack[MAX_NEST_LEVEL];
2811 bool command_flag= false;
2812 int command_depth= 0, command_base= 0, cmd_depth= 0;
2814 string item_name, command_name;
2815 string c_depth, c_params, tmps;
2817 int depth= 0; /* paragraph depth */
2819 tex_code_break_column = column;
2821 ofstream ofs(fname.c_str());
2823 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2829 ofs << "<!doctype " << top_element
2830 << " public \"-//OASIS//DTD DocBook V3.1//EN\"";
2832 if (params.preamble.empty())
2835 ofs << "\n [ " << params.preamble << " \n]>\n\n";
2837 ofs << "<!-- DocBook file was created by " << LYX_DOCVERSION
2838 << "\n See http://www.lyx.org/ for more information -->\n";
2840 if(params.options.empty())
2841 sgmlOpenTag(ofs, 0, top_element);
2843 string top = top_element;
2845 top += params.options;
2846 sgmlOpenTag(ofs, 0, top);
2850 int desc_on = 0; /* description mode*/
2851 LyXLayout const & style =
2852 textclasslist.Style(users->buffer()->params.textclass,
2854 par->AutoDeleteInsets();
2856 /* environment tag closing */
2857 for( ; depth > par->depth; --depth) {
2858 if(environment_inner[depth] != "!-- --") {
2859 item_name= "listitem";
2860 sgmlCloseTag(ofs, command_depth + depth,
2862 if( environment_inner[depth] == "varlistentry")
2863 sgmlCloseTag(ofs, depth+command_depth,
2864 environment_inner[depth]);
2866 sgmlCloseTag(ofs, depth + command_depth,
2867 environment_stack[depth]);
2868 environment_stack[depth].clear();
2869 environment_inner[depth].clear();
2872 if(depth == par->depth
2873 && environment_stack[depth] != style.latexname()
2874 && !environment_stack[depth].empty()) {
2875 if(environment_inner[depth] != "!-- --") {
2876 item_name= "listitem";
2877 sgmlCloseTag(ofs, command_depth+depth,
2879 if( environment_inner[depth] == "varlistentry")
2881 depth + command_depth,
2882 environment_inner[depth]);
2885 sgmlCloseTag(ofs, depth + command_depth,
2886 environment_stack[depth]);
2888 environment_stack[depth].clear();
2889 environment_inner[depth].clear();
2892 // Write opening SGML tags.
2893 switch(style.latextype) {
2894 case LATEX_PARAGRAPH:
2895 if(style.latexname() != "dummy")
2896 sgmlOpenTag(ofs, depth+command_depth,
2902 LinuxDocError(par, 0,
2903 _("Error : Wrong depth for "
2904 "LatexType Command.\n"));
2906 command_name = style.latexname();
2908 tmps = style.latexparam();
2909 c_params = split(tmps, c_depth,'|');
2911 cmd_depth= atoi(c_depth.c_str());
2914 if(cmd_depth<command_base) {
2915 for(int j = command_depth;
2916 j >= command_base; --j)
2917 if(!command_stack[j].empty())
2918 sgmlCloseTag(ofs, j, command_stack[j]);
2919 command_depth= command_base= cmd_depth;
2921 else if(cmd_depth <= command_depth) {
2922 for(int j = command_depth;
2923 j >= cmd_depth; --j)
2925 if(!command_stack[j].empty())
2926 sgmlCloseTag(ofs, j, command_stack[j]);
2927 command_depth= cmd_depth;
2930 command_depth= cmd_depth;
2933 command_depth = command_base = cmd_depth;
2934 command_flag = true;
2936 command_stack[command_depth]= command_name;
2938 // treat label as a special case for
2939 // more WYSIWYM handling.
2940 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2941 Inset * inset = par->GetInset(0);
2942 char lyx_code = inset->LyxCode();
2943 if (lyx_code == Inset::LABEL_CODE){
2944 command_name += " id=\"";
2945 command_name += (static_cast<InsetCommand *>(inset))->getContents();
2946 command_name += "\"";
2951 sgmlOpenTag(ofs, depth+command_depth, command_name);
2952 item_name = "title";
2953 sgmlOpenTag(ofs, depth + 1 + command_depth, item_name);
2956 case LATEX_ENVIRONMENT:
2957 case LATEX_ITEM_ENVIRONMENT:
2958 if (depth < par->depth) {
2960 environment_stack[depth].clear();
2963 if (environment_stack[depth] != style.latexname()) {
2964 environment_stack[depth] = style.latexname();
2965 environment_inner[depth] = "!-- --";
2966 sgmlOpenTag(ofs, depth + command_depth,
2967 environment_stack[depth]);
2969 if(environment_inner[depth] != "!-- --") {
2970 item_name= "listitem";
2972 command_depth + depth,
2974 if (environment_inner[depth] == "varlistentry")
2976 depth + command_depth,
2977 environment_inner[depth]);
2981 if(style.latextype == LATEX_ENVIRONMENT) {
2982 if(!style.latexparam().empty())
2983 sgmlOpenTag(ofs, depth + command_depth,
2984 style.latexparam());
2988 desc_on = (style.labeltype == LABEL_MANUAL);
2991 environment_inner[depth]= "varlistentry";
2993 environment_inner[depth]= "listitem";
2995 sgmlOpenTag(ofs, depth + 1 + command_depth,
2996 environment_inner[depth]);
3000 sgmlOpenTag(ofs, depth + 1 + command_depth,
3005 sgmlOpenTag(ofs, depth + 1 + command_depth,
3010 sgmlOpenTag(ofs, depth + command_depth,
3017 SimpleDocBookOnePar(ofs, extra_par, par, desc_on,
3018 depth + 1 + command_depth);
3020 DocBookHandleFootnote(ofs, par,
3021 depth + 1 + command_depth);
3023 while(par && par->IsDummy());
3026 /* write closing SGML tags */
3027 switch(style.latextype) {
3030 sgmlCloseTag(ofs, depth + command_depth, end_tag);
3032 case LATEX_ENVIRONMENT:
3033 if(!style.latexparam().empty())
3034 sgmlCloseTag(ofs, depth + command_depth,
3035 style.latexparam());
3037 case LATEX_ITEM_ENVIRONMENT:
3038 if(desc_on == 1) break;
3040 sgmlCloseTag(ofs, depth + 1 + command_depth, end_tag);
3042 case LATEX_PARAGRAPH:
3043 if(style.latexname() != "dummy")
3044 sgmlCloseTag(ofs, depth + command_depth,
3048 sgmlCloseTag(ofs, depth + command_depth,
3055 for(; depth >= 0; --depth) {
3056 if(!environment_stack[depth].empty()) {
3057 if(environment_inner[depth] != "!-- --") {
3058 item_name= "listitem";
3059 sgmlCloseTag(ofs, command_depth + depth,
3061 if( environment_inner[depth] == "varlistentry")
3062 sgmlCloseTag(ofs, depth + command_depth,
3063 environment_inner[depth]);
3066 sgmlCloseTag(ofs, depth + command_depth,
3067 environment_stack[depth]);
3071 for(int j = command_depth; j >= command_base; --j)
3072 if(!command_stack[j].empty())
3073 sgmlCloseTag(ofs, j, command_stack[j]);
3076 sgmlCloseTag(ofs, 0, top_element);
3079 // How to check for successful close
3083 void Buffer::SimpleDocBookOnePar(ostream & os, string & extra,
3084 LyXParagraph * par, int & desc_on,
3088 par->SimpleDocBookOneTablePar(os, extra, desc_on, depth);
3092 bool emph_flag = false;
3094 LyXLayout const & style = textclasslist.Style(params.textclass,
3097 LyXParagraph::size_type main_body;
3098 if (style.labeltype != LABEL_MANUAL)
3101 main_body = par->BeginningOfMainBody();
3103 // gets paragraph main font
3104 //if (main_body > 0)
3105 // font1 = style.labelfont;
3107 // font1 = style.font;
3108 LyXFont font1 = main_body > 0 ? style.labelfont : style.font;
3110 int char_line_count = depth;
3111 if(!style.free_spacing)
3112 for (int j = 0; j < depth; ++j)
3115 // parsing main loop
3116 for (LyXParagraph::size_type i = 0;
3117 i < par->size(); ++i) {
3118 LyXFont font2 = par->getFont(i);
3120 // handle <emphasis> tag
3121 if (font1.emph() != font2.emph() && i) {
3122 if (font2.emph() == LyXFont::ON) {
3126 os << "</emphasis>";
3131 char c = par->GetChar(i);
3133 if (c == LyXParagraph::META_INSET) {
3134 Inset * inset = par->GetInset(i);
3136 std::ostringstream ost;
3137 inset->DocBook(ost);
3138 string tmp_out = ost.str().c_str();
3141 inset->DocBook(ost);
3143 char * ctmp = ost.str();
3144 string tmp_out(ctmp);
3148 // This code needs some explanation:
3149 // Two insets are treated specially
3150 // label if it is the first element in a command paragraph
3152 // graphics inside tables or figure floats can't go on
3153 // title (the equivalente in latex for this case is caption
3154 // and title should come first
3157 if(desc_on!= 3 || i!= 0) {
3158 if(!tmp_out.empty() && tmp_out[0] == '@') {
3160 extra += frontStrip(tmp_out, '@');
3162 os << frontStrip(tmp_out, '@');
3167 } else if (font2.latex() == LyXFont::ON) {
3168 // "TeX"-Mode on ==> SGML-Mode on.
3175 if (par->linuxDocConvertChar(c, sgml_string)
3176 && !style.free_spacing) { // in freespacing
3178 // non-breaking characters
3182 os << "\n</term><listitem><para>";
3196 /* needed if there is an optional argument but no contents */
3197 if (main_body > 0 && main_body == par->size()) {
3201 os << "</emphasis>";
3204 /* resets description flag correctly */
3207 /* <term> not closed... */
3215 int Buffer::runLaTeX()
3217 if (!users->text) return 0;
3219 ProhibitInput(users);
3221 // get LaTeX-Filename
3222 string name = getLatexName();
3224 string path = OnlyPath(filename);
3226 string org_path = path;
3227 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3231 Path p(path); // path to LaTeX file
3232 users->owner()->getMiniBuffer()->Set(_("Running LaTeX..."));
3234 // Remove all error insets
3235 bool a = users->removeAutoInsets();
3237 // Always generate the LaTeX file
3238 makeLaTeXFile(name, org_path, false);
3241 // do the LaTex run(s)
3243 string latex_command = lyxrc.pdf_mode ?
3244 lyxrc.pdflatex_command : lyxrc.latex_command;
3245 LaTeX latex(latex_command, name, filepath);
3246 int res = latex.run(terr,
3247 users->owner()->getMiniBuffer()); // running latex
3249 // check return value from latex.run().
3250 if ((res & LaTeX::NO_LOGFILE)) {
3251 WriteAlert(_("LaTeX did not work!"),
3252 _("Missing log file:"), name);
3253 } else if ((res & LaTeX::ERRORS)) {
3254 users->owner()->getMiniBuffer()->Set(_("Done"));
3255 // Insert all errors as errors boxes
3256 users->insertErrors(terr);
3258 // Dvi should also be kept dirty if the latex run
3259 // ends up with errors. However it should be possible
3260 // to view a dirty dvi too.
3262 //no errors or any other things to think about so:
3263 users->owner()->getMiniBuffer()->Set(_("Done"));
3267 // if we removed error insets before we ran LaTeX or if we inserted
3268 // error insets after we ran LaTeX this must be run:
3269 if (a || (res & LaTeX::ERRORS)){
3272 users->updateScrollbar();
3276 return latex.getNumErrors();
3280 int Buffer::runLiterate()
3282 if (!users->text) return 0;
3284 ProhibitInput(users);
3286 // get LaTeX-Filename
3287 string name = getLatexName();
3288 // get Literate-Filename
3289 string lit_name = ChangeExtension (getLatexName(),
3290 lyxrc.literate_extension, true);
3292 string path = OnlyPath(filename);
3294 string org_path = path;
3295 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3299 Path p(path); // path to Literate file
3300 users->owner()->getMiniBuffer()->Set(_("Running Literate..."));
3302 // Remove all error insets
3303 bool a = users->removeAutoInsets();
3305 // generate the Literate file if necessary
3306 if (!isDviClean() || a) {
3307 makeLaTeXFile(lit_name, org_path, false);
3311 string latex_command = lyxrc.pdf_mode ?
3312 lyxrc.pdflatex_command : lyxrc.latex_command;
3313 Literate literate(latex_command, name, filepath,
3315 lyxrc.literate_command, lyxrc.literate_error_filter,
3316 lyxrc.build_command, lyxrc.build_error_filter);
3318 int res = literate.weave(terr, users->owner()->getMiniBuffer());
3320 // check return value from literate.weave().
3321 if ((res & Literate::NO_LOGFILE)) {
3322 WriteAlert(_("Literate command did not work!"),
3323 _("Missing log file:"), name);
3324 } else if ((res & Literate::ERRORS)) {
3325 users->owner()->getMiniBuffer()->Set(_("Done"));
3326 // Insert all errors as errors boxes
3327 users->insertErrors(terr);
3329 // Dvi should also be kept dirty if the latex run
3330 // ends up with errors. However it should be possible
3331 // to view a dirty dvi too.
3333 //no errors or any other things to think about so:
3334 users->owner()->getMiniBuffer()->Set(_("Done"));
3338 // if we removed error insets before we ran LaTeX or if we inserted
3339 // error insets after we ran LaTeX this must be run:
3340 if (a || (res & Literate::ERRORS)){
3343 users->updateScrollbar();
3347 return literate.getNumErrors();
3351 int Buffer::buildProgram()
3353 if (!users->text) return 0;
3355 ProhibitInput(users);
3357 // get LaTeX-Filename
3358 string name = getLatexName();
3359 // get Literate-Filename
3360 string lit_name = ChangeExtension(getLatexName(),
3361 lyxrc.literate_extension, true);
3363 string path = OnlyPath(filename);
3365 string org_path = path;
3366 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3370 Path p(path); // path to Literate file
3371 users->owner()->getMiniBuffer()->Set(_("Building Program..."));
3373 // Remove all error insets
3374 bool a = users->removeAutoInsets();
3376 // generate the LaTeX file if necessary
3377 if (!isNwClean() || a) {
3378 makeLaTeXFile(lit_name, org_path, false);
3382 string latex_command = lyxrc.pdf_mode ?
3383 lyxrc.pdflatex_command : lyxrc.latex_command;
3384 Literate literate(latex_command, name, filepath,
3386 lyxrc.literate_command, lyxrc.literate_error_filter,
3387 lyxrc.build_command, lyxrc.build_error_filter);
3389 int res = literate.build(terr, users->owner()->getMiniBuffer());
3391 // check return value from literate.build().
3392 if ((res & Literate::NO_LOGFILE)) {
3393 WriteAlert(_("Build did not work!"),
3394 _("Missing log file:"), name);
3395 } else if ((res & Literate::ERRORS)) {
3396 users->owner()->getMiniBuffer()->Set(_("Done"));
3397 // Insert all errors as errors boxes
3398 users->insertErrors(terr);
3400 // Literate files should also be kept dirty if the literate
3401 // command run ends up with errors.
3403 //no errors or any other things to think about so:
3404 users->owner()->getMiniBuffer()->Set(_("Done"));
3408 // if we removed error insets before we ran Literate/Build or if we inserted
3409 // error insets after we ran Literate/Build this must be run:
3410 if (a || (res & Literate::ERRORS)){
3413 users->updateScrollbar();
3417 return literate.getNumErrors();
3421 // This should be enabled when the Chktex class is implemented. (Asger)
3422 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
3423 // Other flags: -wall -v0 -x
3424 int Buffer::runChktex()
3426 if (!users->text) return 0;
3428 ProhibitInput(users);
3430 // get LaTeX-Filename
3431 string name = getLatexName();
3432 string path = OnlyPath(filename);
3434 string org_path = path;
3435 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3439 Path p(path); // path to LaTeX file
3440 users->owner()->getMiniBuffer()->Set(_("Running chktex..."));
3442 // Remove all error insets
3443 bool a = users->removeAutoInsets();
3445 // Generate the LaTeX file if neccessary
3446 if (!isDviClean() || a) {
3447 makeLaTeXFile(name, org_path, false);
3452 Chktex chktex(lyxrc.chktex_command, name, filepath);
3453 int res = chktex.run(terr); // run chktex
3456 WriteAlert(_("chktex did not work!"),
3457 _("Could not run with file:"), name);
3458 } else if (res > 0) {
3459 // Insert all errors as errors boxes
3460 users->insertErrors(terr);
3463 // if we removed error insets before we ran chktex or if we inserted
3464 // error insets after we ran chktex, this must be run:
3468 users->updateScrollbar();
3477 void Buffer::RoffAsciiTable(ostream & os, LyXParagraph * par)
3479 LyXFont font1(LyXFont::ALL_INHERIT,params.language_info);
3482 LyXParagraph::size_type i;
3486 string fname1 = TmpFileName(string(), "RAT1");
3487 string fname2 = TmpFileName(string(), "RAT2");
3489 ofstream ofs(fname1.c_str());
3491 WriteAlert(_("LYX_ERROR:"),
3492 _("Cannot open temporary file:"), fname1);
3495 par->table->RoffEndOfCell(ofs, -1);
3496 for (i = 0; i < par->size(); ++i) {
3497 c = par->GetChar(i);
3498 if (par->table->IsContRow(cell)) {
3499 if (c == LyXParagraph::META_NEWLINE)
3503 font2 = par->GetFontSettings(i);
3504 if (font1.latex() != font2.latex()) {
3505 if (font2.latex() != LyXFont::OFF)
3509 case LyXParagraph::META_INSET:
3510 if ((inset = par->GetInset(i))) {
3512 stringstresm ss(ios::in | ios::out);
3539 case LyXParagraph::META_NEWLINE:
3540 if (par->table->CellHasContRow(cell)>= 0)
3541 par->RoffContTableRows(ofs, i+1, cell);
3542 par->table->RoffEndOfCell(ofs, cell);
3545 case LyXParagraph::META_HFILL:
3555 << "RoffAsciiTable:"
3556 " NULL char in structure." << endl;
3560 par->table->RoffEndOfCell(ofs, cell);
3562 string cmd = lyxrc.ascii_roff_command + " >" + fname2;
3563 cmd = subst(cmd, "$$FName", fname1);
3564 Systemcalls one(Systemcalls::System, cmd);
3565 if (!(lyxerr.debugging(Debug::ROFF))) {
3566 remove(fname1.c_str());
3568 ifstream ifs(fname2.c_str());
3570 WriteFSAlert(_("Error! Can't open temporary file:"), fname2);
3573 // now output the produced file
3577 WriteAlert(_("Error!"),
3578 _("Error executing *roff command on table"));
3579 // overread leading blank lines
3580 while(!ifs && (c == '\n'))
3583 for(j = 0; j < par->depth; ++j)
3585 while(!ifs && (c != '\n')) {
3590 // overread trailing blank lines
3591 while(!ifs && (c == '\n'))
3595 remove(fname2.c_str());
3600 /// changed Heinrich Bauer, 23/03/98
3601 bool Buffer::isDviClean() const
3603 if (lyxrc.use_tempdir)
3604 return dvi_clean_tmpd;
3606 return dvi_clean_orgd;
3610 /// changed Heinrich Bauer, 23/03/98
3611 void Buffer::markDviClean()
3613 if (lyxrc.use_tempdir)
3614 dvi_clean_tmpd = true;
3616 dvi_clean_orgd = true;
3620 /// changed Heinrich Bauer, 23/03/98
3621 void Buffer::markDviDirty()
3623 if (lyxrc.use_tempdir)
3624 dvi_clean_tmpd = false;
3626 dvi_clean_orgd = false;
3630 void Buffer::validate(LaTeXFeatures & features) const
3632 LyXParagraph * par = paragraph;
3633 LyXTextClass const & tclass =
3634 textclasslist.TextClass(params.textclass);
3636 // AMS Style is at document level
3638 features.amsstyle = (params.use_amsmath ||
3639 tclass.provides(LyXTextClass::amsmath));
3642 // We don't use "lyxerr.debug" because of speed. (Asger)
3643 if (lyxerr.debugging(Debug::LATEX))
3644 lyxerr << "Paragraph: " << par << endl;
3646 // Now just follow the list of paragraphs and run
3647 // validate on each of them.
3648 par->validate(features);
3650 // and then the next paragraph
3654 // the bullet shapes are buffer level not paragraph level
3655 // so they are tested here
3656 for (int i = 0; i < 4; ++i) {
3657 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
3658 int font = params.user_defined_bullets[i].getFont();
3661 .user_defined_bullets[i]
3668 features.latexsym = true;
3672 features.amssymb = true;
3674 else if ((font >= 2 && font <= 5)) {
3675 features.pifont = true;
3680 if (lyxerr.debugging(Debug::LATEX)) {
3681 features.showStruct();
3686 void Buffer::setPaperStuff()
3688 params.papersize = BufferParams::PAPER_DEFAULT;
3689 char c1 = params.paperpackage;
3690 if (c1 == BufferParams::PACKAGE_NONE) {
3691 char c2 = params.papersize2;
3692 if (c2 == BufferParams::VM_PAPER_USLETTER)
3693 params.papersize = BufferParams::PAPER_USLETTER;
3694 else if (c2 == BufferParams::VM_PAPER_USLEGAL)
3695 params.papersize = BufferParams::PAPER_LEGALPAPER;
3696 else if (c2 == BufferParams::VM_PAPER_USEXECUTIVE)
3697 params.papersize = BufferParams::PAPER_EXECUTIVEPAPER;
3698 else if (c2 == BufferParams::VM_PAPER_A3)
3699 params.papersize = BufferParams::PAPER_A3PAPER;
3700 else if (c2 == BufferParams::VM_PAPER_A4)
3701 params.papersize = BufferParams::PAPER_A4PAPER;
3702 else if (c2 == BufferParams::VM_PAPER_A5)
3703 params.papersize = BufferParams::PAPER_A5PAPER;
3704 else if ((c2 == BufferParams::VM_PAPER_B3) || (c2 == BufferParams::VM_PAPER_B4) ||
3705 (c2 == BufferParams::VM_PAPER_B5))
3706 params.papersize = BufferParams::PAPER_B5PAPER;
3707 } else if ((c1 == BufferParams::PACKAGE_A4) || (c1 == BufferParams::PACKAGE_A4WIDE) ||
3708 (c1 == BufferParams::PACKAGE_WIDEMARGINSA4))
3709 params.papersize = BufferParams::PAPER_A4PAPER;
3713 // This function should be in Buffer because it's a buffer's property (ale)
3714 string Buffer::getIncludeonlyList(char delim)
3717 LyXParagraph * par = paragraph;
3718 LyXParagraph::size_type pos;
3722 while ((inset = par->ReturnNextInsetPointer(pos))){
3723 if (inset->LyxCode() == Inset::INCLUDE_CODE) {
3724 InsetInclude * insetinc =
3725 static_cast<InsetInclude*>(inset);
3726 if (insetinc->isInclude()
3727 && insetinc->isNoLoad()) {
3730 lst += ChangeExtension(insetinc->getContents(), string(), true);
3737 lyxerr.debug() << "Includeonly(" << lst << ')' << endl;
3742 // This is also a buffer property (ale)
3743 string Buffer::getReferenceList(char delim)
3745 /// if this is a child document and the parent is already loaded
3746 /// Use the parent's list instead [ale990407]
3747 if (!params.parentname.empty()
3748 && bufferlist.exists(params.parentname)) {
3749 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3751 return tmp->getReferenceList(delim);
3754 LyXParagraph * par = paragraph;
3755 LyXParagraph::size_type pos;
3760 while ((inset = par->ReturnNextInsetPointer(pos))){
3761 for (int i = 0; i < inset->GetNumberOfLabels(); ++i) {
3764 lst += inset->getLabel(i);
3770 lyxerr.debug() << "References(" << lst << ")" << endl;
3775 // This is also a buffer property (ale)
3776 string Buffer::getBibkeyList(char delim)
3778 /// if this is a child document and the parent is already loaded
3779 /// Use the parent's list instead [ale990412]
3780 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3781 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3783 return tmp->getBibkeyList(delim);
3787 LyXParagraph * par = paragraph;
3790 if (!bibkeys.empty())
3792 bibkeys += par->bibkey->getContents();
3797 // Might be either using bibtex or a child has bibliography
3798 if (bibkeys.empty()) {
3802 LyXParagraph::size_type pos = -1;
3804 // Search for Bibtex or Include inset
3805 while ((inset = par->ReturnNextInsetPointer(pos))) {
3806 if (inset-> LyxCode() == Inset::BIBTEX_CODE) {
3807 if (!bibkeys.empty())
3809 bibkeys += static_cast<InsetBibtex*>(inset)->getKeys(delim);
3810 } else if (inset-> LyxCode() == Inset::INCLUDE_CODE) {
3811 string bk = static_cast<InsetInclude*>(inset)->getKeys(delim);
3813 if (!bibkeys.empty())
3824 lyxerr.debug() << "Bibkeys(" << bibkeys << ")" << endl;
3829 bool Buffer::isDepClean(string const & name) const
3831 DEPCLEAN * item = dep_clean;
3832 while (item && item->master != name)
3834 if (!item) return true;
3839 void Buffer::markDepClean(string const & name)
3842 dep_clean = new DEPCLEAN;
3843 dep_clean->clean = true;
3844 dep_clean->master = name;
3845 dep_clean->next = 0;
3847 DEPCLEAN* item = dep_clean;
3848 while (item && item->master != name)
3853 item = new DEPCLEAN;
3855 item->master = name;
3862 void Buffer::Dispatch(string const & command)
3864 // Split command string into command and argument
3865 string cmd, line = frontStrip(command);
3866 string arg = strip(frontStrip(split(line, cmd, ' ')));
3868 Dispatch(lyxaction.LookupFunc(cmd.c_str()), arg.c_str());
3872 void Buffer::Dispatch(int action, string const & argument)
3876 MenuExport(this, argument);
3880 lyxerr << "A truly unknown func!" << endl;
3886 void Buffer::ChangeLanguage(Language const * from, Language const * to)
3889 LyXParagraph * par = paragraph;
3891 par->ChangeLanguage(from,to);
3896 bool Buffer::isMultiLingual()
3899 LyXParagraph * par = paragraph;
3901 if (par->isMultiLingual())