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"
47 #include "bufferview_funcs.h"
48 #include "minibuffer.h"
51 #include "mathed/formulamacro.h"
52 #include "insets/lyxinset.h"
53 #include "insets/inseterror.h"
54 #include "insets/insetlabel.h"
55 #include "insets/insetref.h"
56 #include "insets/inseturl.h"
57 #include "insets/insetinfo.h"
58 #include "insets/insetquotes.h"
59 #include "insets/insetlatexaccent.h"
60 #include "insets/insetbib.h"
61 #include "insets/insetindex.h"
62 #include "insets/insetinclude.h"
63 #include "insets/insettoc.h"
64 #include "insets/insetlof.h"
65 #include "insets/insetlot.h"
66 #include "insets/insetloa.h"
67 #include "insets/insetparent.h"
68 #include "insets/insetspecialchar.h"
69 #include "insets/figinset.h"
70 #include "insets/insettext.h"
71 #include "insets/insetert.h"
72 #include "insets/insetgraphics.h"
73 #include "insets/insetfoot.h"
74 #include "insets/insettabular.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"
100 // all these externs should eventually be removed.
101 extern BufferList bufferlist;
103 extern void MenuExport(Buffer *, string const &);
104 extern LyXAction lyxaction;
107 static const float LYX_FORMAT = 2.16;
109 extern int tex_code_break_column;
112 Buffer::Buffer(string const & file, bool ronly)
114 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
116 filepath = OnlyPath(file);
120 dvi_clean_orgd = false; // Heinrich Bauer, 23/03/98
121 dvi_clean_tmpd = false; // Heinrich Bauer, 23/03/98
126 if (read_only || (lyxrc.use_tempdir)) {
127 tmppath = CreateBufferTmpDir();
128 } else tmppath.erase();
134 lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
135 // here the buffer should take care that it is
136 // saved properly, before it goes into the void.
138 // make sure that views using this buffer
143 if (!tmppath.empty()) {
144 DestroyBufferTmpDir(tmppath);
147 LyXParagraph * par = paragraph;
148 LyXParagraph * tmppar;
158 string Buffer::getLatexName(bool no_path) const
161 return OnlyFilename(ChangeExtension(MakeLatexName(filename),
164 return ChangeExtension(MakeLatexName(filename),
169 void Buffer::setReadonly(bool flag)
171 if (read_only != flag) {
174 updateAllVisibleBufferRelatedPopups();
177 WarnReadonly(filename);
182 bool Buffer::saveParamsAsDefaults()
184 string fname = AddName(AddPath(user_lyxdir, "templates/"),
186 Buffer defaults = Buffer(fname);
188 // Use the current buffer's parameters as default
189 defaults.params = params;
191 // add an empty paragraph. Is this enough?
192 defaults.paragraph = new LyXParagraph;
194 return defaults.writeFile(defaults.filename, false);
198 /// Update window titles of all users
199 // Should work on a list
200 void Buffer::updateTitles() const
202 if (users) users->owner()->updateWindowTitle();
206 /// Reset autosave timer of all users
207 // Should work on a list
208 void Buffer::resetAutosaveTimers() const
210 if (users) users->owner()->resetAutosaveTimer();
214 void Buffer::fileName(string const & newfile)
216 filename = MakeAbsPath(newfile);
217 filepath = OnlyPath(filename);
218 setReadonly(IsFileWriteable(filename) == 0);
223 // candidate for move to BufferView
224 // (at least some parts in the beginning of the func)
227 // changed to be public and have one parameter
228 // if par = 0 normal behavior
229 // else insert behavior
230 // Returns false if "\the_end" is not read for formats >= 2.13. (Asger)
231 #define USE_PARSE_FUNCTION 1
232 bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par)
236 char depth = 0; // signed or unsigned?
237 LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
238 LyXParagraph::footnote_kind footnotekind = LyXParagraph::FOOTNOTE;
239 bool the_end_read = false;
241 LyXParagraph * return_par = 0;
242 LyXFont font(LyXFont::ALL_INHERIT, params.language_info);
243 if (format < 2.16 && params.language == "hebrew")
244 font.setLanguage(default_language);
246 // If we are inserting, we cheat and get a token in advance
247 bool has_token = false;
251 par = new LyXParagraph;
253 users->text->BreakParagraph();
254 return_par = users->text->FirstParagraph();
257 // We don't want to adopt the parameters from the
258 // document we insert, so we skip until the text begins:
261 pretoken = lex.GetString();
262 if (pretoken == "\\layout") {
274 pretoken = lex.GetString();
277 // Profiling show this should give a lot: (Asger)
278 string const token = pretoken;
282 the_end_read = parseSingleLyXformat2Token(lex, par, return_par,
291 paragraph = return_par;
298 Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
299 LyXParagraph *& return_par,
300 string const & token, int & pos,
301 char & depth, LyXFont & font,
302 LyXParagraph::footnote_flag & footnoteflag,
303 LyXParagraph::footnote_kind & footnotekind)
305 bool the_end_read = false;
307 if (token[0] != '\\') {
308 for (string::const_iterator cit = token.begin();
309 cit != token.end(); ++cit) {
310 par->InsertChar(pos, (*cit));
311 par->SetFont(pos, font);
314 } else if (token == "\\i") {
315 Inset * inset = new InsetLatexAccent;
317 par->InsertChar(pos, LyXParagraph::META_INSET);
318 par->InsertInset(pos, inset);
319 par->SetFont(pos, font);
321 } else if (token == "\\layout") {
326 par = new LyXParagraph(par);
330 string layoutname = lex.GetString();
331 pair<bool, LyXTextClass::LayoutList::size_type> pp
332 = textclasslist.NumberOfLayout(params.textclass,
335 par->layout = pp.second;
336 } else { // layout not found
337 // use default layout "Standard" (0)
340 // Test whether the layout is obsolete.
341 LyXLayout const & layout =
342 textclasslist.Style(params.textclass,
344 if (!layout.obsoleted_by().empty())
346 textclasslist.NumberOfLayout(params.textclass,
347 layout.obsoleted_by()).second;
348 par->footnoteflag = footnoteflag;
349 par->footnotekind = footnotekind;
351 font = LyXFont(LyXFont::ALL_INHERIT, params.language_info);
352 if (format < 2.16 && params.language == "hebrew")
353 font.setLanguage(default_language);
354 } else if (token == "\\end_float") {
359 par = new LyXParagraph(par);
361 footnotekind = LyXParagraph::FOOTNOTE;
362 footnoteflag = LyXParagraph::NO_FOOTNOTE;
365 par->layout = LYX_DUMMY_LAYOUT;
366 font = LyXFont(LyXFont::ALL_INHERIT, params.language_info);
367 if (format < 2.16 && params.language == "hebrew")
368 font.setLanguage(default_language);
369 } else if (token == "\\begin_float") {
370 int tmpret = lex.FindToken(string_footnotekinds);
371 if (tmpret == -1) ++tmpret;
372 if (tmpret != LYX_LAYOUT_DEFAULT)
373 footnotekind = static_cast<LyXParagraph::footnote_kind>(tmpret); // bad
374 if (footnotekind == LyXParagraph::FOOTNOTE
375 || footnotekind == LyXParagraph::MARGIN)
376 footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
378 footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
379 } else if (token == "\\begin_deeper") {
381 } else if (token == "\\end_deeper") {
383 lex.printError("\\end_deeper: "
384 "depth is already null");
388 } else if (token == "\\begin_preamble") {
389 params.readPreamble(lex);
390 } else if (token == "\\textclass") {
392 pair<bool, LyXTextClassList::size_type> pp =
393 textclasslist.NumberOfClass(lex.GetString());
395 params.textclass = pp.second;
397 lex.printError("Unknown textclass `$$Token'");
398 params.textclass = 0;
400 if (!textclasslist.Load(params.textclass)) {
401 // if the textclass wasn't loaded properly
402 // we need to either substitute another
403 // or stop loading the file.
404 // I can substitute but I don't see how I can
405 // stop loading... ideas?? ARRae980418
406 WriteAlert(_("Textclass Loading Error!"),
407 string(_("Can't load textclass ")) +
408 textclasslist.NameOfClass(params.textclass),
409 _("-- substituting default"));
410 params.textclass = 0;
412 } else if (token == "\\options") {
414 params.options = lex.GetString();
415 } else if (token == "\\language") {
416 params.readLanguage(lex);
417 } else if (token == "\\fontencoding") {
419 } else if (token == "\\inputencoding") {
421 params.inputenc = lex.GetString();
422 } else if (token == "\\graphics") {
423 params.readGraphicsDriver(lex);
424 } else if (token == "\\fontscheme") {
426 params.fonts = lex.GetString();
427 } else if (token == "\\noindent") {
428 par->noindent = true;
429 } else if (token == "\\fill_top") {
430 par->added_space_top = VSpace(VSpace::VFILL);
431 } else if (token == "\\fill_bottom") {
432 par->added_space_bottom = VSpace(VSpace::VFILL);
433 } else if (token == "\\line_top") {
434 par->line_top = true;
435 } else if (token == "\\line_bottom") {
436 par->line_bottom = true;
437 } else if (token == "\\pagebreak_top") {
438 par->pagebreak_top = true;
439 } else if (token == "\\pagebreak_bottom") {
440 par->pagebreak_bottom = true;
441 } else if (token == "\\start_of_appendix") {
442 par->start_of_appendix = true;
443 } else if (token == "\\paragraph_separation") {
444 int tmpret = lex.FindToken(string_paragraph_separation);
445 if (tmpret == -1) ++tmpret;
446 if (tmpret != LYX_LAYOUT_DEFAULT)
447 params.paragraph_separation =
448 static_cast<BufferParams::PARSEP>(tmpret);
449 } else if (token == "\\defskip") {
451 params.defskip = VSpace(lex.GetString());
452 } else if (token == "\\epsfig") { // obsolete
453 // Indeed it is obsolete, but we HAVE to be backwards
454 // compatible until 0.14, because otherwise all figures
455 // in existing documents are irretrivably lost. (Asger)
456 params.readGraphicsDriver(lex);
457 } else if (token == "\\quotes_language") {
458 int tmpret = lex.FindToken(string_quotes_language);
459 if (tmpret == -1) ++tmpret;
460 if (tmpret != LYX_LAYOUT_DEFAULT) {
461 InsetQuotes::quote_language tmpl =
462 InsetQuotes::EnglishQ;
465 tmpl = InsetQuotes::EnglishQ;
468 tmpl = InsetQuotes::SwedishQ;
471 tmpl = InsetQuotes::GermanQ;
474 tmpl = InsetQuotes::PolishQ;
477 tmpl = InsetQuotes::FrenchQ;
480 tmpl = InsetQuotes::DanishQ;
483 params.quotes_language = tmpl;
485 } else if (token == "\\quotes_times") {
487 switch(lex.GetInteger()) {
489 params.quotes_times = InsetQuotes::SingleQ;
492 params.quotes_times = InsetQuotes::DoubleQ;
495 } else if (token == "\\papersize") {
496 int tmpret = lex.FindToken(string_papersize);
500 params.papersize2 = tmpret;
501 } else if (token == "\\paperpackage") {
502 int tmpret = lex.FindToken(string_paperpackages);
505 params.paperpackage = BufferParams::PACKAGE_NONE;
507 params.paperpackage = tmpret;
508 } else if (token == "\\use_geometry") {
510 params.use_geometry = lex.GetInteger();
511 } else if (token == "\\use_amsmath") {
513 params.use_amsmath = lex.GetInteger();
514 } else if (token == "\\paperorientation") {
515 int tmpret = lex.FindToken(string_orientation);
516 if (tmpret == -1) ++tmpret;
517 if (tmpret != LYX_LAYOUT_DEFAULT)
518 params.orientation = static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
519 } else if (token == "\\paperwidth") {
521 params.paperwidth = lex.GetString();
522 } else if (token == "\\paperheight") {
524 params.paperheight = lex.GetString();
525 } else if (token == "\\leftmargin") {
527 params.leftmargin = lex.GetString();
528 } else if (token == "\\topmargin") {
530 params.topmargin = lex.GetString();
531 } else if (token == "\\rightmargin") {
533 params.rightmargin = lex.GetString();
534 } else if (token == "\\bottommargin") {
536 params.bottommargin = lex.GetString();
537 } else if (token == "\\headheight") {
539 params.headheight = lex.GetString();
540 } else if (token == "\\headsep") {
542 params.headsep = lex.GetString();
543 } else if (token == "\\footskip") {
545 params.footskip = lex.GetString();
546 } else if (token == "\\paperfontsize") {
548 params.fontsize = strip(lex.GetString());
549 } else if (token == "\\papercolumns") {
551 params.columns = lex.GetInteger();
552 } else if (token == "\\papersides") {
554 switch(lex.GetInteger()) {
556 case 1: params.sides = LyXTextClass::OneSide; break;
557 case 2: params.sides = LyXTextClass::TwoSides; break;
559 } else if (token == "\\paperpagestyle") {
561 params.pagestyle = strip(lex.GetString());
562 } else if (token == "\\bullet") {
564 int index = lex.GetInteger();
566 int temp_int = lex.GetInteger();
567 params.user_defined_bullets[index].setFont(temp_int);
568 params.temp_bullets[index].setFont(temp_int);
570 temp_int = lex.GetInteger();
571 params.user_defined_bullets[index].setCharacter(temp_int);
572 params.temp_bullets[index].setCharacter(temp_int);
574 temp_int = lex.GetInteger();
575 params.user_defined_bullets[index].setSize(temp_int);
576 params.temp_bullets[index].setSize(temp_int);
578 string temp_str = lex.GetString();
579 if (temp_str != "\\end_bullet") {
580 // this element isn't really necessary for
581 // parsing but is easier for humans
582 // to understand bullets. Put it back and
583 // set a debug message?
584 lex.printError("\\end_bullet expected, got" + temp_str);
585 //how can I put it back?
587 } else if (token == "\\bulletLaTeX") {
589 int index = lex.GetInteger();
591 string temp_str = lex.GetString(), sum_str;
592 while (temp_str != "\\end_bullet") {
593 // this loop structure is needed when user
594 // enters an empty string since the first
595 // thing returned will be the \\end_bullet
597 // if the LaTeX entry has spaces. Each element
598 // therefore needs to be read in turn
601 temp_str = lex.GetString();
603 params.user_defined_bullets[index].setText(sum_str);
604 params.temp_bullets[index].setText(sum_str);
605 } else if (token == "\\secnumdepth") {
607 params.secnumdepth = lex.GetInteger();
608 } else if (token == "\\tocdepth") {
610 params.tocdepth = lex.GetInteger();
612 } else if (token == "\\baselinestretch") { // obsolete
613 lex.nextToken(); // should not be used directly
615 // Will probably keep a kind of support just for
617 params.spacing.set(Spacing::Other, lex.GetFloat());
619 } else if (token == "\\spacing") {
621 string tmp = strip(lex.GetString());
622 Spacing::Space tmp_space = Spacing::Default;
624 if (tmp == "single") {
625 tmp_space = Spacing::Single;
626 } else if (tmp == "onehalf") {
627 tmp_space = Spacing::Onehalf;
628 } else if (tmp == "double") {
629 tmp_space = Spacing::Double;
630 } else if (tmp == "other") {
632 tmp_space = Spacing::Other;
633 tmp_val = lex.GetFloat();
635 lex.printError("Unknown spacing token: '$$Token'");
637 // Small hack so that files written with klyx will be
640 par->spacing.set(tmp_space, tmp_val);
642 params.spacing.set(tmp_space, tmp_val);
644 } else if (token == "\\paragraph_spacing") {
646 string tmp = strip(lex.GetString());
647 if (tmp == "single") {
648 par->spacing.set(Spacing::Single);
649 } else if (tmp == "onehalf") {
650 par->spacing.set(Spacing::Onehalf);
651 } else if (tmp == "double") {
652 par->spacing.set(Spacing::Double);
653 } else if (tmp == "other") {
655 par->spacing.set(Spacing::Other,
658 lex.printError("Unknown spacing token: '$$Token'");
660 } else if (token == "\\float_placement") {
662 params.float_placement = lex.GetString();
664 } else if (token == "\\cursor") { // obsolete
665 // this is obsolete, so we just skip it.
668 } else if (token == "\\family") {
670 font.setLyXFamily(lex.GetString());
671 } else if (token == "\\series") {
673 font.setLyXSeries(lex.GetString());
674 } else if (token == "\\shape") {
676 font.setLyXShape(lex.GetString());
677 } else if (token == "\\size") {
679 font.setLyXSize(lex.GetString());
680 } else if (token == "\\latex") {
682 string tok = lex.GetString();
683 // This is dirty, but gone with LyX3. (Asger)
684 if (tok == "no_latex")
685 font.setLatex(LyXFont::OFF);
686 else if (tok == "latex")
687 font.setLatex(LyXFont::ON);
688 else if (tok == "default")
689 font.setLatex(LyXFont::INHERIT);
691 lex.printError("Unknown LaTeX font flag "
693 } else if (token == "\\lang") {
695 string tok = lex.GetString();
696 Languages::iterator lit = languages.find(tok);
697 if (lit != languages.end()) {
698 font.setLanguage(&(*lit).second);
700 font.setLanguage(params.language_info);
701 lex.printError("Unknown language `$$Token'");
703 } else if (token == "\\emph") {
705 font.setEmph(font.setLyXMisc(lex.GetString()));
706 } else if (token == "\\bar") {
708 string tok = lex.GetString();
709 // This is dirty, but gone with LyX3. (Asger)
711 font.setUnderbar(LyXFont::ON);
712 else if (tok == "no")
713 font.setUnderbar(LyXFont::OFF);
714 else if (tok == "default")
715 font.setUnderbar(LyXFont::INHERIT);
717 lex.printError("Unknown bar font flag "
719 } else if (token == "\\noun") {
721 font.setNoun(font.setLyXMisc(lex.GetString()));
722 } else if (token == "\\color") {
724 font.setLyXColor(lex.GetString());
725 } else if (token == "\\align") {
726 int tmpret = lex.FindToken(string_align);
727 if (tmpret == -1) ++tmpret;
728 if (tmpret != LYX_LAYOUT_DEFAULT) { // tmpret != 99 ???
730 for (; tmpret > 0; --tmpret)
731 tmpret2 = tmpret2 * 2;
732 par->align = LyXAlignment(tmpret2);
734 } else if (token == "\\added_space_top") {
736 par->added_space_top = VSpace(lex.GetString());
737 } else if (token == "\\added_space_bottom") {
739 par->added_space_bottom = VSpace(lex.GetString());
740 } else if (token == "\\pextra_type") {
742 par->pextra_type = lex.GetInteger();
743 } else if (token == "\\pextra_width") {
745 par->pextra_width = lex.GetString();
746 } else if (token == "\\pextra_widthp") {
748 par->pextra_widthp = lex.GetString();
749 } else if (token == "\\pextra_alignment") {
751 par->pextra_alignment = lex.GetInteger();
752 } else if (token == "\\pextra_hfill") {
754 par->pextra_hfill = lex.GetInteger();
755 } else if (token == "\\pextra_start_minipage") {
757 par->pextra_start_minipage = lex.GetInteger();
758 } else if (token == "\\labelwidthstring") {
760 par->labelwidthstring = lex.GetString();
761 // do not delete this token, it is still needed!
762 } else if (token == "\\end_inset") {
763 // Simply ignore this. The insets do not have
765 // But insets should read it, it is a part of
766 // the inset isn't it? Lgb.
767 } else if (token == "\\begin_inset") {
768 // Should be moved out into its own function/method. (Lgb)
770 string tmptok = lex.GetString();
771 // test the different insets
772 if (tmptok == "Quotes") {
773 Inset * inset = new InsetQuotes;
775 par->InsertChar(pos, LyXParagraph::META_INSET);
776 par->InsertInset(pos, inset);
777 par->SetFont(pos, font);
780 } else if (tmptok == "\\i") {
781 Inset * inset = new InsetLatexAccent;
783 par->InsertChar(pos, LyXParagraph::META_INSET);
784 par->InsertInset(pos, inset);
785 par->SetFont(pos, font);
788 } else if (tmptok == "FormulaMacro") {
789 Inset * inset = new InsetFormulaMacro;
791 par->InsertChar(pos, LyXParagraph::META_INSET);
792 par->InsertInset(pos, inset);
793 par->SetFont(pos, font);
795 } else if (tmptok == "Formula") {
796 Inset * inset = new InsetFormula;
798 par->InsertChar(pos, LyXParagraph::META_INSET);
799 par->InsertInset(pos, inset);
800 par->SetFont(pos, font);
802 } else if (tmptok == "Figure") {
803 Inset * inset = new InsetFig(100, 100, this);
805 par->InsertChar(pos, LyXParagraph::META_INSET);
806 par->InsertInset(pos, inset);
807 par->SetFont(pos, font);
809 } else if (tmptok == "Info") {
810 Inset * inset = new InsetInfo;
812 par->InsertChar(pos, LyXParagraph::META_INSET);
813 par->InsertInset(pos, inset);
814 par->SetFont(pos, font);
816 } else if (tmptok == "Include") {
817 Inset * inset = new InsetInclude(string(), this);
819 par->InsertChar(pos, LyXParagraph::META_INSET);
820 par->InsertInset(pos, inset);
821 par->SetFont(pos, font);
823 } else if (tmptok == "ERT") {
824 Inset * inset = new InsetERT(this);
826 par->InsertChar(pos, LyXParagraph::META_INSET);
827 par->InsertInset(pos, inset);
828 par->SetFont(pos, font);
830 } else if (tmptok == "Tabular") {
831 Inset * inset = new InsetTabular(this);
833 par->InsertChar(pos, LyXParagraph::META_INSET);
834 par->InsertInset(pos, inset);
835 par->SetFont(pos, font);
837 } else if (tmptok == "Text") {
838 Inset * inset = new InsetText(this);
840 par->InsertChar(pos, LyXParagraph::META_INSET);
841 par->InsertInset(pos, inset);
842 par->SetFont(pos, font);
844 } else if (tmptok == "Foot") {
845 Inset * inset = new InsetFoot(this);
847 par->InsertChar(pos, LyXParagraph::META_INSET);
848 par->InsertInset(pos, inset);
849 par->SetFont(pos, font);
851 } else if (tmptok == "GRAPHICS") {
852 Inset * inset = new InsetGraphics;
854 par->InsertChar(pos, LyXParagraph::META_INSET);
855 par->InsertInset(pos, inset);
856 par->SetFont(pos, font);
857 } else if (tmptok == "LatexCommand") {
861 if (inscmd.getCmdName() == "cite") {
862 inset = new InsetCitation(inscmd.getContents(), inscmd.getOptions());
863 } else if (inscmd.getCmdName() == "bibitem") {
864 lex.printError("Wrong place for bibitem");
865 inset = inscmd.Clone();
866 } else if (inscmd.getCmdName() == "BibTeX") {
867 inset = new InsetBibtex(inscmd.getContents(), inscmd.getOptions(), this);
868 } else if (inscmd.getCmdName() == "index") {
869 inset = new InsetIndex(inscmd.getContents());
870 } else if (inscmd.getCmdName() == "include") {
871 inset = new InsetInclude(inscmd.getContents(), this);
872 } else if (inscmd.getCmdName() == "label") {
873 inset = new InsetLabel(inscmd.getCommand());
874 } else if (inscmd.getCmdName() == "url"
875 || inscmd.getCmdName() == "htmlurl") {
876 inset = new InsetUrl(inscmd.getCommand());
877 } else if (inscmd.getCmdName() == "ref"
878 || inscmd.getCmdName() == "pageref") {
879 if (!inscmd.getOptions().empty() || !inscmd.getContents().empty()) {
880 inset = new InsetRef(inscmd, this);
882 // CHECK if this else clause
883 //is still needed. (Lgb)
885 // This condition comes from a
886 // temporary solution to the latexdel
887 // ref inset that was transformed to
888 // an empty ref inset plus the body
889 // surronded by latexdel insets
891 string cont, opt, tmptmptok, cmdname;
893 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
898 tmptmptok = lex.GetString();
899 if(tmptmptok[0] == '\\') {
900 if( tmptmptok == "\\backslash")
910 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
915 tmptmptok = lex.GetString();
916 if(tmptmptok[0] == '\\') {
917 if( tmptmptok == "\\backslash")
927 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
933 cmdname = "\\" + inscmd.getCmdName();
934 cmdname += "[" + cont + "]";
935 cmdname += "{" + opt + "}";
936 inset = new InsetRef(cmdname, this);
939 } else if (inscmd.getCmdName() == "tableofcontents") {
940 inset = new InsetTOC(this);
941 } else if (inscmd.getCmdName() == "listoffigures") {
942 inset = new InsetLOF(this);
943 } else if (inscmd.getCmdName() == "listofalgorithms") {
944 inset = new InsetLOA(this);
945 } else if (inscmd.getCmdName() == "listoftables") {
946 inset = new InsetLOT(this);
947 } else if (inscmd.getCmdName() == "printindex") {
948 inset = new InsetPrintIndex(this);
949 } else if (inscmd.getCmdName() == "lyxparent") {
950 inset = new InsetParent(inscmd.getContents(), this);
954 par->InsertChar(pos, LyXParagraph::META_INSET);
955 par->InsertInset(pos, inset);
956 par->SetFont(pos, font);
961 } else if (token == "\\InsetQuotes") {
962 lyxerr << "InsetQuotes" << endl;
963 Inset * inset = new InsetQuotes;
965 par->InsertChar(pos, LyXParagraph::META_INSET);
966 par->InsertInset(pos, inset);
967 par->SetFont(pos, font);
971 } else if (token == "\\InsetFormula") {
972 lyxerr << "InsetFormula" << endl;
973 Inset * inset = new InsetFormula;
975 par->InsertChar(pos, LyXParagraph::META_INSET);
976 par->InsertInset(pos, inset);
977 par->SetFont(pos, font);
980 } else if (token == "\\SpecialChar") {
981 LyXLayout const & layout =
982 textclasslist.Style(params.textclass,
985 // Insets don't make sense in a free-spacing context! ---Kayvan
986 if (layout.free_spacing) {
990 next_token = lex.GetString();
991 if (next_token == "\\-") {
992 par->InsertChar(pos, '-');
993 par->SetFont(pos, font);
994 } else if (next_token == "\\protected_separator"
995 || next_token == "~") {
996 par->InsertChar(pos, ' ');
997 par->SetFont(pos, font);
999 lex.printError("Token `$$Token' "
1001 "paragraph layout!");
1006 Inset * inset = new InsetSpecialChar;
1008 par->InsertChar(pos, LyXParagraph::META_INSET);
1009 par->InsertInset(pos, inset);
1010 par->SetFont(pos, font);
1014 } else if (token == "\\Figure") {
1015 lyxerr << "Figure" << endl;
1016 Inset * inset = new InsetFig(100, 100, this);
1018 par->InsertChar(pos, LyXParagraph::META_INSET);
1019 par->InsertInset(pos, inset);
1020 par->SetFont(pos, font);
1023 } else if (token == "\\newline") {
1024 par->InsertChar(pos, LyXParagraph::META_NEWLINE);
1025 par->SetFont(pos, font);
1027 } else if (token == "\\LyXTable") {
1028 #ifdef USE_TABULAR_INSETS
1029 Inset * inset = new InsetTabular(this);
1031 par->InsertChar(pos, LyXParagraph::META_INSET);
1032 par->InsertInset(pos, inset);
1033 par->SetFont(pos, font);
1036 par->table = new LyXTable(lex);
1038 } else if (token == "\\hfill") {
1039 par->InsertChar(pos, LyXParagraph::META_HFILL);
1040 par->SetFont(pos, font);
1042 } else if (token == "\\protected_separator") { // obsolete
1043 // This is a backward compability thingie. (Lgb)
1044 // Remove it later some time...introduced with fileformat
1046 LyXLayout const & layout =
1047 textclasslist.Style(params.textclass,
1050 if (layout.free_spacing) {
1051 par->InsertChar(pos, ' ');
1052 par->SetFont(pos, font);
1054 Inset * inset = new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
1055 par->InsertChar(pos, LyXParagraph::META_INSET);
1056 par->InsertInset(pos, inset);
1057 par->SetFont(pos, font);
1060 } else if (token == "\\bibitem") { // ale970302
1062 par->bibkey = new InsetBibKey;
1063 par->bibkey->Read(lex);
1064 }else if (token == "\\backslash") {
1065 par->InsertChar(pos, '\\');
1066 par->SetFont(pos, font);
1068 }else if (token == "\\the_end") {
1069 the_end_read = true;
1071 // This should be insurance for the future: (Asger)
1072 lex.printError("Unknown token `$$Token'. "
1073 "Inserting as text.");
1074 for(string::const_iterator cit = token.begin();
1075 cit != token.end(); ++cit) {
1076 par->InsertChar(pos, (*cit));
1077 par->SetFont(pos, font);
1081 return the_end_read;
1084 bool Buffer::readFile(LyXLex & lex, LyXParagraph * par)
1090 token = lex.GetString();
1091 if (token == "\\lyxformat") { // the first token _must_ be...
1093 format = lex.GetFloat();
1095 if (LYX_FORMAT - format > 0.05) {
1096 printf(_("Warning: need lyxformat %.2f but found %.2f\n"),
1097 LYX_FORMAT, format);
1099 if (format - LYX_FORMAT > 0.05) {
1100 printf(_("ERROR: need lyxformat %.2f but found %.2f\n"),
1101 LYX_FORMAT, format);
1103 bool the_end = readLyXformat2(lex, par);
1104 // Formats >= 2.13 support "\the_end" marker
1111 WriteAlert(_("Warning!"),
1112 _("Reading of document is not complete"),
1113 _("Maybe the document is truncated"));
1114 // We simulate a safe reading anyways to allow
1115 // users to take the chance... (Asger)
1119 WriteAlert(_("ERROR!"),
1120 _("Old LyX file format found. "
1121 "Use LyX 0.10.x to read this!"));
1125 } else { // "\\lyxformat" not found
1126 WriteAlert(_("ERROR!"), _("Not a LyX file!"));
1129 WriteAlert(_("ERROR!"), _("Unable to read file!"));
1135 // Should probably be moved to somewhere else: BufferView? LyXView?
1136 bool Buffer::save() const
1138 // We don't need autosaves in the immediate future. (Asger)
1139 resetAutosaveTimers();
1143 if (lyxrc.make_backup) {
1144 s = fileName() + '~';
1145 if (!lyxrc.backupdir_path.empty())
1146 s = AddName(lyxrc.backupdir_path,
1147 subst(CleanupPath(s),'/','!'));
1149 // Rename is the wrong way of making a backup,
1150 // this is the correct way.
1151 /* truss cp fil fil2:
1152 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
1153 stat("LyXVC.lyx", 0xEFFFF688) = 0
1154 open("LyXVC.lyx", O_RDONLY) = 3
1155 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
1156 fstat(4, 0xEFFFF508) = 0
1157 fstat(3, 0xEFFFF508) = 0
1158 read(3, " # T h i s f i l e w".., 8192) = 5579
1159 write(4, " # T h i s f i l e w".., 5579) = 5579
1160 read(3, 0xEFFFD4A0, 8192) = 0
1163 chmod("LyXVC3.lyx", 0100644) = 0
1164 lseek(0, 0, SEEK_CUR) = 46440
1168 // Should proabaly have some more error checking here.
1169 // Should be cleaned up in 0.13, at least a bit.
1170 // Doing it this way, also makes the inodes stay the same.
1171 // This is still not a very good solution, in particular we
1172 // might loose the owner of the backup.
1173 FileInfo finfo(fileName());
1174 if (finfo.exist()) {
1175 mode_t fmode = finfo.getMode();
1176 struct utimbuf times = {
1177 finfo.getAccessTime(),
1178 finfo.getModificationTime() };
1180 ifstream ifs(fileName().c_str());
1181 ofstream ofs(s.c_str(), ios::out|ios::trunc);
1186 ::chmod(s.c_str(), fmode);
1188 if (::utime(s.c_str(), ×)) {
1189 lyxerr << "utime error." << endl;
1192 lyxerr << "LyX was not able to make "
1193 "backupcopy. Beware." << endl;
1198 if (writeFile(fileName(), false)) {
1201 // now delete the autosavefile
1202 string a = OnlyPath(fileName());
1204 a += OnlyFilename(fileName());
1206 FileInfo fileinfo(a);
1207 if (fileinfo.exist()) {
1208 if (::remove(a.c_str()) != 0) {
1209 WriteFSAlert(_("Could not delete "
1210 "auto-save file!"), a);
1214 // Saving failed, so backup is not backup
1215 if (lyxrc.make_backup) {
1216 ::rename(s.c_str(), fileName().c_str());
1224 // Returns false if unsuccesful
1225 bool Buffer::writeFile(string const & fname, bool flag) const
1227 // if flag is false writeFile will not create any GUI
1228 // warnings, only cerr.
1229 // Needed for autosave in background or panic save (Matthias 120496)
1231 if (read_only && (fname == filename)) {
1232 // Here we should come with a question if we should
1233 // perform the write anyway.
1235 lyxerr << _("Error! Document is read-only: ")
1238 WriteAlert(_("Error! Document is read-only: "),
1243 FileInfo finfo(fname);
1244 if (finfo.exist() && !finfo.writable()) {
1245 // Here we should come with a question if we should
1246 // try to do the save anyway. (i.e. do a chmod first)
1248 lyxerr << _("Error! Cannot write file: ")
1251 WriteFSAlert(_("Error! Cannot write file: "),
1256 ofstream ofs(fname.c_str());
1259 lyxerr << _("Error! Cannot open file: ")
1262 WriteFSAlert(_("Error! Cannot open file: "),
1266 // The top of the file should not be written by params.
1268 // write out a comment in the top of the file
1269 ofs << '#' << LYX_DOCVERSION
1270 << " created this file. For more info see http://www.lyx.org/\n";
1271 ofs.setf(ios::showpoint|ios::fixed);
1273 ofs << "\\lyxformat " << setw(4) << LYX_FORMAT << "\n";
1275 // now write out the buffer paramters.
1276 params.writeFile(ofs);
1278 char footnoteflag = 0;
1281 // this will write out all the paragraphs
1282 // using recursive descent.
1283 paragraph->writeFile(ofs, params, footnoteflag, depth);
1285 // Write marker that shows file is complete
1286 ofs << "\n\\the_end" << endl;
1288 // how to check if close went ok?
1293 void Buffer::writeFileAscii(string const & fname, int linelen)
1295 LyXFont font1, font2;
1297 char c, footnoteflag = 0, depth = 0;
1299 LyXParagraph::size_type i;
1300 int j, h, ltype = 0, ltype_depth = 0,
1301 * clen = 0, actcell = 0, actpos = 0, cell = 0, cells = 0,
1304 bool ref_printed = false;
1306 ofstream ofs(fname.c_str());
1308 WriteFSAlert(_("Error: Cannot write file:"), fname);
1312 string fname1 = TmpFileName();
1313 LyXParagraph * par = paragraph;
1317 if (par->footnoteflag != LyXParagraph::NO_FOOTNOTE ||
1319 par->previous->footnoteflag == LyXParagraph::NO_FOOTNOTE){
1321 /* begins a footnote environment ? */
1322 if (footnoteflag != par->footnoteflag) {
1323 footnoteflag = par->footnoteflag;
1325 j = strlen(string_footnotekinds[par->footnotekind])+4;
1326 if (currlinelen + j > linelen)
1329 << string_footnotekinds[par->footnotekind] << "] ";
1334 /* begins or ends a deeper area ?*/
1335 if (depth != par->depth) {
1336 if (par->depth > depth) {
1337 while (par->depth > depth) {
1342 while (par->depth < depth) {
1348 /* First write the layout */
1349 tmp = textclasslist.NameOfLayout(params.textclass, par->layout);
1350 if (tmp == "Itemize") {
1352 ltype_depth = depth+1;
1353 } else if (tmp == "Enumerate") {
1355 ltype_depth = depth+1;
1356 } else if (strstr(tmp.c_str(), "ection")) {
1358 ltype_depth = depth+1;
1359 } else if (strstr(tmp.c_str(), "aragraph")) {
1361 ltype_depth = depth+1;
1362 } else if (tmp == "Description") {
1364 ltype_depth = depth+1;
1365 } else if (tmp == "Abstract") {
1368 } else if (tmp == "Bibliography") {
1376 /* maybe some vertical spaces */
1378 /* the labelwidthstring used in lists */
1382 /* some pagebreaks? */
1386 /* what about the alignment */
1388 /* dummy layout, that means a footnote ended */
1389 footnoteflag = LyXParagraph::NO_FOOTNOTE;
1394 //LyXLayout const & layout =
1395 // textclasslist.Style(params.textclass,
1396 // par->GetLayout()); // unused
1397 //bool free_spc = layout.free_spacing; //unused
1399 /* It might be a table */
1402 if (!lyxrc.ascii_roff_command.empty() &&
1403 lyxrc.ascii_roff_command != "none") {
1404 RoffAsciiTable(ofs, par);
1411 cells = par->table->columns;
1412 clen = new int [cells];
1413 memset(clen, 0, sizeof(int) * cells);
1415 for (i = 0, j = 0, h = 1; i < par->size(); ++i, ++h) {
1416 c = par->GetChar(i);
1417 if (c == LyXParagraph::META_INSET) {
1418 if ((inset = par->GetInset(i))) {
1420 std::ostringstream ost;
1422 h += ost.str().length();
1427 char * tmp = ost.str();
1433 } else if (c == LyXParagraph::META_NEWLINE) {
1437 j = (++j) % par->table->NumberOfCellsInRow(actcell);
1445 font1 = LyXFont(LyXFont::ALL_INHERIT, params.language_info);
1447 for (i = 0, actpos = 1; i < par->size(); ++i, ++actpos) {
1448 if (!i && !footnoteflag && !noparbreak){
1450 for(j = 0; j < depth; ++j)
1452 currlinelen = depth * 2;
1454 case 0: /* Standard */
1455 case 4: /* (Sub)Paragraph */
1456 case 5: /* Description */
1458 case 6: /* Abstract */
1459 ofs << "Abstract\n\n";
1461 case 7: /* Bibliography */
1463 ofs << "References\n\n";
1468 ofs << par->labelstring << " ";
1471 if (ltype_depth > depth) {
1472 for(j = ltype_depth - 1; j > depth; --j)
1474 currlinelen += (ltype_depth-depth)*2;
1477 for(j = 0; j < cells; ++j) {
1479 for(h = 0; h < (clen[j] + 1);
1484 for(j = 0; j < depth; ++j)
1486 currlinelen = depth * 2;
1487 if (ltype_depth > depth) {
1488 for(j = ltype_depth;
1491 currlinelen += (ltype_depth-depth)*2;
1496 font2 = par->GetFontSettings(i);
1497 if (font1.latex() != font2.latex()) {
1498 if (font2.latex() == LyXFont::OFF)
1505 c = par->GetChar(i);
1509 case LyXParagraph::META_INSET:
1510 if ((inset = par->GetInset(i))) {
1513 currlinelen += (ofs.tellp() - fpos);
1514 actpos += (ofs.tellp() - fpos) - 1;
1517 case LyXParagraph::META_NEWLINE:
1519 if (par->table->NumberOfCellsInRow(actcell) <= cell) {
1520 for(j = actpos; j < clen[cell - 1]; ++j)
1523 for(j = 0; j < depth; ++j)
1525 currlinelen = depth*2;
1526 if (ltype_depth > depth) {
1527 for(j = ltype_depth; j > depth; --j)
1529 currlinelen += (ltype_depth-depth) * 2;
1531 for(j = 0; j < cells; ++j) {
1533 for(h = 0; h < (clen[j] + 1); ++h)
1537 for(j = 0; j < depth; ++j)
1539 currlinelen = depth * 2;
1540 if (ltype_depth > depth) {
1541 for(j = ltype_depth;
1544 currlinelen += (ltype_depth-depth)*2;
1550 j < clen[cell - 1]; ++j)
1556 currlinelen = actpos = 0;
1559 for(j = 0; j < depth; ++j)
1561 currlinelen = depth * 2;
1562 if (ltype_depth > depth) {
1563 for(j = ltype_depth;
1566 currlinelen += (ltype_depth - depth) * 2;
1570 case LyXParagraph::META_HFILL:
1577 if (currlinelen > linelen - 10
1578 && c == ' ' && i + 2 < par->size()) {
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;
1589 } else if (c != '\0')
1592 lyxerr.debug() << "writeAsciiFile: NULL char in structure." << endl;
1598 for(j = actpos; j < clen[cell - 1]; ++j)
1601 for(j = 0; j < depth; ++j)
1603 currlinelen = depth * 2;
1604 if (ltype_depth > depth) {
1605 for(j = ltype_depth; j > depth; --j)
1607 currlinelen += (ltype_depth - depth) * 2;
1609 for(j = 0; j < cells; ++j) {
1611 for(h = 0; h < (clen[j] + 1); ++h)
1624 void Buffer::makeLaTeXFile(string const & fname,
1625 string const & original_path,
1626 bool nice, bool only_body)
1628 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
1630 niceFile = nice; // this will be used by Insetincludes.
1632 tex_code_break_column = lyxrc.ascii_linelen;
1634 LyXTextClass const & tclass =
1635 textclasslist.TextClass(params.textclass);
1637 ofstream ofs(fname.c_str());
1639 WriteFSAlert(_("Error: Cannot open file: "), fname);
1643 // validate the buffer.
1644 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
1645 LaTeXFeatures features(params, tclass.numLayouts());
1647 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
1650 // The starting paragraph of the coming rows is the
1651 // first paragraph of the document. (Asger)
1652 texrow.start(paragraph, 0);
1654 if (!only_body && nice) {
1655 ofs << "%% " LYX_DOCVERSION " created this file. "
1656 "For more info, see http://www.lyx.org/.\n"
1657 "%% Do not edit unless you really know what "
1662 lyxerr.debug() << "lyx header finished" << endl;
1663 // There are a few differences between nice LaTeX and usual files:
1664 // usual is \batchmode and has a
1665 // special input@path to allow the including of figures
1666 // with either \input or \includegraphics (what figinsets do).
1667 // batchmode is not set if there is a tex_code_break_column.
1668 // In this case somebody is interested in the generated LaTeX,
1669 // so this is OK. input@path is set when the actual parameter
1670 // original_path is set. This is done for usual tex-file, but not
1671 // for nice-latex-file. (Matthias 250696)
1674 // code for usual, NOT nice-latex-file
1675 ofs << "\\batchmode\n"; // changed
1676 // from \nonstopmode
1679 if (!original_path.empty()) {
1680 ofs << "\\makeatletter\n"
1681 << "\\def\\input@path{{"
1682 << original_path << "/}}\n"
1683 << "\\makeatother\n";
1689 ofs << "\\documentclass";
1691 string options; // the document class options.
1693 if (tokenPos(tclass.opt_fontsize(), '|', params.fontsize) >= 0) {
1694 // only write if existing in list (and not default)
1695 options += params.fontsize;
1700 if (!params.use_geometry &&
1701 (params.paperpackage == BufferParams::PACKAGE_NONE)) {
1702 switch (params.papersize) {
1703 case BufferParams::PAPER_A4PAPER:
1704 options += "a4paper,";
1706 case BufferParams::PAPER_USLETTER:
1707 options += "letterpaper,";
1709 case BufferParams::PAPER_A5PAPER:
1710 options += "a5paper,";
1712 case BufferParams::PAPER_B5PAPER:
1713 options += "b5paper,";
1715 case BufferParams::PAPER_EXECUTIVEPAPER:
1716 options += "executivepaper,";
1718 case BufferParams::PAPER_LEGALPAPER:
1719 options += "legalpaper,";
1725 if (params.sides != tclass.sides()) {
1726 switch (params.sides) {
1727 case LyXTextClass::OneSide:
1728 options += "oneside,";
1730 case LyXTextClass::TwoSides:
1731 options += "twoside,";
1738 if (params.columns != tclass.columns()) {
1739 if (params.columns == 2)
1740 options += "twocolumn,";
1742 options += "onecolumn,";
1745 if (!params.use_geometry
1746 && params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1747 options += "landscape,";
1749 // language should be a parameter to \documentclass
1750 bool use_babel = false;
1751 if (params.language_info->RightToLeft) // This seems necessary
1752 features.UsedLanguages.insert(default_language);
1753 if (params.language != "default" ||
1754 !features.UsedLanguages.empty() ) {
1756 for (LaTeXFeatures::LanguageList::const_iterator cit =
1757 features.UsedLanguages.begin();
1758 cit != features.UsedLanguages.end(); ++cit)
1759 options += (*cit)->lang + ",";
1760 options += params.language_info->lang + ',';
1763 // the user-defined options
1764 if (!params.options.empty()) {
1765 options += params.options + ',';
1768 if (!options.empty()){
1769 options = strip(options, ',');
1770 ofs << '[' << options << ']';
1774 << textclasslist.LatexnameOfClass(params.textclass)
1777 // end of \documentclass defs
1779 // font selection must be done before loading fontenc.sty
1780 if (params.fonts != "default") {
1781 ofs << "\\usepackage{" << params.fonts << "}\n";
1784 // this one is not per buffer
1785 if (lyxrc.fontenc != "default") {
1786 ofs << "\\usepackage[" << lyxrc.fontenc
1790 if (params.inputenc != "default") {
1791 ofs << "\\usepackage[" << params.inputenc
1796 // At the very beginning the text parameters.
1797 if (params.paperpackage != BufferParams::PACKAGE_NONE) {
1798 switch (params.paperpackage) {
1799 case BufferParams::PACKAGE_A4:
1800 ofs << "\\usepackage{a4}\n";
1803 case BufferParams::PACKAGE_A4WIDE:
1804 ofs << "\\usepackage{a4wide}\n";
1807 case BufferParams::PACKAGE_WIDEMARGINSA4:
1808 ofs << "\\usepackage[widemargins]{a4}\n";
1813 if (params.use_geometry) {
1814 ofs << "\\usepackage{geometry}\n";
1816 ofs << "\\geometry{verbose";
1817 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1818 ofs << ",landscape";
1819 switch (params.papersize2) {
1820 case BufferParams::VM_PAPER_CUSTOM:
1821 if (!params.paperwidth.empty())
1822 ofs << ",paperwidth="
1823 << params.paperwidth;
1824 if (!params.paperheight.empty())
1825 ofs << ",paperheight="
1826 << params.paperheight;
1828 case BufferParams::VM_PAPER_USLETTER:
1829 ofs << ",letterpaper";
1831 case BufferParams::VM_PAPER_USLEGAL:
1832 ofs << ",legalpaper";
1834 case BufferParams::VM_PAPER_USEXECUTIVE:
1835 ofs << ",executivepaper";
1837 case BufferParams::VM_PAPER_A3:
1840 case BufferParams::VM_PAPER_A4:
1843 case BufferParams::VM_PAPER_A5:
1846 case BufferParams::VM_PAPER_B3:
1849 case BufferParams::VM_PAPER_B4:
1852 case BufferParams::VM_PAPER_B5:
1856 // default papersize ie BufferParams::VM_PAPER_DEFAULT
1857 switch (lyxrc.default_papersize) {
1858 case BufferParams::PAPER_DEFAULT: // keep compiler happy
1859 case BufferParams::PAPER_USLETTER:
1860 ofs << ",letterpaper";
1862 case BufferParams::PAPER_LEGALPAPER:
1863 ofs << ",legalpaper";
1865 case BufferParams::PAPER_EXECUTIVEPAPER:
1866 ofs << ",executivepaper";
1868 case BufferParams::PAPER_A3PAPER:
1871 case BufferParams::PAPER_A4PAPER:
1874 case BufferParams::PAPER_A5PAPER:
1877 case BufferParams::PAPER_B5PAPER:
1882 if (!params.topmargin.empty())
1883 ofs << ",tmargin=" << params.topmargin;
1884 if (!params.bottommargin.empty())
1885 ofs << ",bmargin=" << params.bottommargin;
1886 if (!params.leftmargin.empty())
1887 ofs << ",lmargin=" << params.leftmargin;
1888 if (!params.rightmargin.empty())
1889 ofs << ",rmargin=" << params.rightmargin;
1890 if (!params.headheight.empty())
1891 ofs << ",headheight=" << params.headheight;
1892 if (!params.headsep.empty())
1893 ofs << ",headsep=" << params.headsep;
1894 if (!params.footskip.empty())
1895 ofs << ",footskip=" << params.footskip;
1899 if (params.use_amsmath
1900 && !tclass.provides(LyXTextClass::amsmath)) {
1901 ofs << "\\usepackage{amsmath}\n";
1905 if (tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle) >= 0) {
1906 if (params.pagestyle == "fancy") {
1907 ofs << "\\usepackage{fancyhdr}\n";
1910 ofs << "\\pagestyle{" << params.pagestyle << "}\n";
1914 // We try to load babel late, in case it interferes
1915 // with other packages.
1917 ofs << lyxrc.language_package << endl;
1921 if (params.secnumdepth != tclass.secnumdepth()) {
1922 ofs << "\\setcounter{secnumdepth}{"
1923 << params.secnumdepth
1927 if (params.tocdepth != tclass.tocdepth()) {
1928 ofs << "\\setcounter{tocdepth}{"
1934 if (params.paragraph_separation) {
1935 switch (params.defskip.kind()) {
1936 case VSpace::SMALLSKIP:
1937 ofs << "\\setlength\\parskip{\\smallskipamount}\n";
1939 case VSpace::MEDSKIP:
1940 ofs << "\\setlength\\parskip{\\medskipamount}\n";
1942 case VSpace::BIGSKIP:
1943 ofs << "\\setlength\\parskip{\\bigskipamount}\n";
1945 case VSpace::LENGTH:
1946 ofs << "\\setlength\\parskip{"
1947 << params.defskip.length().asLatexString()
1950 default: // should never happen // Then delete it.
1951 ofs << "\\setlength\\parskip{\\medskipamount}\n";
1956 ofs << "\\setlength\\parindent{0pt}\n";
1960 // Now insert the LyX specific LaTeX commands...
1961 string preamble, tmppreamble;
1963 // The optional packages;
1964 preamble = features.getPackages();
1966 // this might be useful...
1967 preamble += "\n\\makeatletter\n\n";
1969 // Some macros LyX will need
1970 tmppreamble = features.getMacros();
1972 if (!tmppreamble.empty()) {
1973 preamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1974 "LyX specific LaTeX commands.\n"
1975 + tmppreamble + '\n';
1978 // the text class specific preamble
1979 tmppreamble = features.getTClassPreamble();
1980 if (!tmppreamble.empty()) {
1981 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1982 "Textclass specific LaTeX commands.\n"
1983 + tmppreamble + '\n';
1986 /* the user-defined preamble */
1987 if (!params.preamble.empty()) {
1988 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1989 "User specified LaTeX commands.\n"
1990 + params.preamble + '\n';
1993 preamble += "\\makeatother\n\n";
1995 // Itemize bullet settings need to be last in case the user
1996 // defines their own bullets that use a package included
1997 // in the user-defined preamble -- ARRae
1998 // Actually it has to be done much later than that
1999 // since some packages like frenchb make modifications
2000 // at \begin{document} time -- JMarc
2002 for (int i = 0; i < 4; ++i) {
2003 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
2004 if (bullets_def.empty())
2005 bullets_def="\\AtBeginDocument{\n";
2006 bullets_def += " \\renewcommand{\\labelitemi";
2008 // `i' is one less than the item to modify
2015 bullets_def += "ii";
2021 bullets_def += "}{" +
2022 params.user_defined_bullets[i].getText()
2027 if (!bullets_def.empty())
2028 preamble += bullets_def + "}\n\n";
2030 for (int j = countChar(preamble, '\n'); j-- ;) {
2037 ofs << "\\begin{document}\n\n";
2041 lyxerr.debug() << "preamble finished, now the body." << endl;
2042 if (!lyxrc.language_auto_begin && params.language != "default") {
2043 ofs << subst(lyxrc.language_command_begin, "$$lang",
2049 latexParagraphs(ofs, paragraph, 0, texrow);
2051 // add this just in case after all the paragraphs
2055 if (!lyxrc.language_auto_end && params.language != "default") {
2056 ofs << subst(lyxrc.language_command_end, "$$lang",
2063 ofs << "\\end{document}\n";
2066 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
2068 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
2072 // Just to be sure. (Asger)
2075 // tex_code_break_column's value is used to decide
2076 // if we are in batchmode or not (within mathed_write()
2077 // in math_write.C) so we must set it to a non-zero
2078 // value when we leave otherwise we save incorrect .lyx files.
2079 tex_code_break_column = lyxrc.ascii_linelen;
2083 lyxerr << "File was not closed properly." << endl;
2086 lyxerr.debug() << "Finished making latex file." << endl;
2090 // LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
2092 void Buffer::latexParagraphs(ostream & ofs, LyXParagraph *par,
2093 LyXParagraph *endpar, TexRow & texrow)
2095 bool was_title = false;
2096 bool already_title = false;
2098 std::ostringstream ftnote;
2100 char * tmpholder = 0;
2106 while (par != endpar) {
2107 #ifndef HAVE_SSTREAM
2110 ftnote << tmpholder;
2111 delete [] tmpholder;
2116 lyxerr[Debug::LATEX] << "Error in latexParagraphs."
2118 LyXLayout const & layout =
2119 textclasslist.Style(params.textclass,
2122 if (layout.intitle) {
2123 if (already_title) {
2124 lyxerr <<"Error in latexParagraphs: You"
2125 " should not mix title layouts"
2126 " with normal ones." << endl;
2129 } else if (was_title && !already_title) {
2130 ofs << "\\maketitle\n";
2132 already_title = true;
2135 // We are at depth 0 so we can just use
2136 // ordinary \footnote{} generation
2137 // flag this with ftcount
2139 if (layout.isEnvironment()
2140 || par->pextra_type != LyXParagraph::PEXTRA_NONE) {
2141 par = par->TeXEnvironment(ofs, texrow,
2142 ftnote, ft_texrow, ftcount);
2144 par = par->TeXOnePar(ofs, texrow, false,
2145 ftnote, ft_texrow, ftcount);
2148 // Write out what we've generated...
2151 ofs << "\\addtocounter{footnote}{-"
2155 ofs << ftnote.str();
2156 texrow += ft_texrow;
2158 // The extra .c_str() is needed when we use
2159 // lyxstring instead of the STL string class.
2160 ftnote.str(string().c_str());
2162 delete [] ftnote.str();
2167 #ifndef HAVE_SSTREAM
2169 // I hate strstreams
2170 tmpholder = ftnote.str();
2174 #ifndef HAVE_SSTREAM
2175 delete [] tmpholder;
2177 // It might be that we only have a title in this document
2178 if (was_title && !already_title) {
2179 ofs << "\\maketitle\n";
2184 bool Buffer::isLatex() const
2186 return textclasslist.TextClass(params.textclass).outputType() == LATEX;
2190 bool Buffer::isLinuxDoc() const
2192 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC;
2196 bool Buffer::isLiterate() const
2198 return textclasslist.TextClass(params.textclass).outputType() == LITERATE;
2202 bool Buffer::isDocBook() const
2204 return textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2208 bool Buffer::isSGML() const
2210 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC ||
2211 textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2215 void Buffer::sgmlOpenTag(ostream & os, int depth,
2216 string const & latexname) const
2218 os << string(depth, ' ') << "<" << latexname << ">\n";
2222 void Buffer::sgmlCloseTag(ostream & os, int depth,
2223 string const & latexname) const
2225 os << string(depth, ' ') << "</" << latexname << ">\n";
2229 void Buffer::makeLinuxDocFile(string const & fname, int column)
2231 LyXParagraph * par = paragraph;
2233 string top_element = textclasslist.LatexnameOfClass(params.textclass);
2234 string environment_stack[10];
2237 int depth = 0; // paragraph depth
2239 ofstream ofs(fname.c_str());
2242 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2246 tex_code_break_column = column;
2249 if (params.preamble.empty()) {
2250 ofs << "<!doctype linuxdoc system>\n\n";
2253 ofs << "<!doctype linuxdoc system \n [ "
2254 << params.preamble << " \n]>\n\n";
2257 ofs << "<!-- " << LYX_DOCVERSION
2258 << " created this file. For more info see http://www.lyx.org/"
2261 if(params.options.empty())
2262 sgmlOpenTag(ofs, 0, top_element);
2264 string top = top_element;
2266 top += params.options;
2267 sgmlOpenTag(ofs, 0, top);
2271 int desc_on = 0; // description mode
2272 LyXLayout const & style =
2273 textclasslist.Style(users->buffer()->params.textclass,
2275 #warning please check if this call is really needed!!!
2276 // par->AutoDeleteInsets();
2278 // treat <toc> as a special case for compatibility with old code
2279 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2280 Inset * inset = par->GetInset(0);
2281 char lyx_code = inset->LyxCode();
2282 if (lyx_code == Inset::TOC_CODE){
2283 string temp = "toc";
2284 sgmlOpenTag(ofs, depth, temp);
2287 linuxDocHandleFootnote(ofs, par, depth);
2292 // environment tag closing
2293 for( ; depth > par->depth; --depth) {
2294 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2295 environment_stack[depth].erase();
2298 // write opening SGML tags
2299 switch(style.latextype) {
2300 case LATEX_PARAGRAPH:
2301 if(depth == par->depth
2302 && !environment_stack[depth].empty()) {
2303 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2304 environment_stack[depth].erase();
2310 sgmlOpenTag(ofs, depth, style.latexname());
2315 LinuxDocError(par, 0,
2316 _("Error : Wrong depth for"
2317 " LatexType Command.\n"));
2319 if (!environment_stack[depth].empty()){
2320 sgmlCloseTag(ofs, depth,
2321 environment_stack[depth]);
2325 environment_stack[depth].erase();
2326 sgmlOpenTag(ofs, depth, style.latexname());
2329 case LATEX_ENVIRONMENT:
2330 case LATEX_ITEM_ENVIRONMENT:
2331 if(depth == par->depth
2332 && environment_stack[depth] != style.latexname()
2333 && !environment_stack[depth].empty()) {
2335 sgmlCloseTag(ofs, depth,
2336 environment_stack[depth]);
2337 environment_stack[depth].erase();
2339 if (depth < par->depth) {
2341 environment_stack[depth].erase();
2343 if (environment_stack[depth] != style.latexname()) {
2346 sgmlOpenTag(ofs, depth, temp);
2348 environment_stack[depth] = style.latexname();
2349 sgmlOpenTag(ofs, depth,
2350 environment_stack[depth]);
2352 if(style.latextype == LATEX_ENVIRONMENT) break;
2354 desc_on = (style.labeltype == LABEL_MANUAL);
2361 sgmlOpenTag(ofs, depth + 1, item_name);
2364 sgmlOpenTag(ofs, depth, style.latexname());
2369 SimpleLinuxDocOnePar(ofs, par, desc_on, depth);
2372 linuxDocHandleFootnote(ofs, par, depth);
2374 while(par && par->IsDummy());
2377 // write closing SGML tags
2378 switch(style.latextype) {
2380 case LATEX_ENVIRONMENT:
2381 case LATEX_ITEM_ENVIRONMENT:
2384 sgmlCloseTag(ofs, depth, style.latexname());
2390 for(; depth > 0; --depth)
2391 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2393 if(!environment_stack[depth].empty())
2394 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2397 sgmlCloseTag(ofs, 0, top_element);
2400 // How to check for successful close
2404 void Buffer::linuxDocHandleFootnote(ostream & os, LyXParagraph * & par,
2407 string tag = "footnote";
2409 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2410 sgmlOpenTag(os, depth + 1, tag);
2411 SimpleLinuxDocOnePar(os, par, 0, depth + 1);
2412 sgmlCloseTag(os, depth + 1, tag);
2418 void Buffer::DocBookHandleCaption(ostream & os, string & inner_tag,
2419 int const depth, int desc_on,
2420 LyXParagraph * & par)
2422 LyXParagraph * tpar = par;
2423 while (tpar && (tpar->footnoteflag != LyXParagraph::NO_FOOTNOTE) &&
2424 (tpar->layout != textclasslist.NumberOfLayout(params.textclass,
2428 tpar->layout == textclasslist.NumberOfLayout(params.textclass,
2429 "Caption").second) {
2430 sgmlOpenTag(os, depth + 1, inner_tag);
2432 SimpleDocBookOnePar(os, extra_par, tpar,
2433 desc_on, depth + 2);
2434 sgmlCloseTag(os, depth+1, inner_tag);
2435 if(!extra_par.empty())
2441 void Buffer::DocBookHandleFootnote(ostream & os, LyXParagraph * & par,
2444 string tag, inner_tag;
2445 string tmp_par, extra_par;
2446 bool inner_span = false;
2449 // Someone should give this enum a proper name (Lgb)
2457 SOME_ENUM last = NO_ONE;
2458 SOME_ENUM present = FOOTNOTE_LIKE;
2460 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2461 if(last == present) {
2463 if(!tmp_par.empty()) {
2466 sgmlCloseTag(os, depth + 1, inner_tag);
2467 sgmlOpenTag(os, depth + 1, inner_tag);
2474 if(!inner_tag.empty()) sgmlCloseTag(os, depth + 1,
2476 if(!extra_par.empty()) os << extra_par;
2477 if(!tag.empty()) sgmlCloseTag(os, depth, tag);
2480 switch (par->footnotekind) {
2481 case LyXParagraph::FOOTNOTE:
2482 case LyXParagraph::ALGORITHM:
2485 present = FOOTNOTE_LIKE;
2488 case LyXParagraph::MARGIN:
2491 present = MARGIN_LIKE;
2494 case LyXParagraph::FIG:
2495 case LyXParagraph::WIDE_FIG:
2497 inner_tag = "title";
2501 case LyXParagraph::TAB:
2502 case LyXParagraph::WIDE_TAB:
2504 inner_tag = "title";
2509 sgmlOpenTag(os, depth, tag);
2510 if ((present == TAB_LIKE) || (present == FIG_LIKE)) {
2511 DocBookHandleCaption(os, inner_tag, depth,
2515 sgmlOpenTag(os, depth + 1, inner_tag);
2518 // ignore all caption here, we processed them above!!!
2519 if (par->layout != textclasslist
2520 .NumberOfLayout(params.textclass,
2521 "Caption").second) {
2523 std::ostringstream ost;
2527 SimpleDocBookOnePar(ost, extra_par, par,
2528 desc_on, depth + 2);
2530 tmp_par += ost.str().c_str();
2533 char * ctmp = ost.str();
2538 tmp_par = frontStrip(strip(tmp_par));
2544 if(!inner_tag.empty()) sgmlCloseTag(os, depth + 1, inner_tag);
2545 if(!extra_par.empty()) os << extra_par;
2546 if(!tag.empty()) sgmlCloseTag(os, depth, tag);
2550 // push a tag in a style stack
2551 void Buffer::push_tag(ostream & os, char const * tag,
2552 int & pos, char stack[5][3])
2554 // pop all previous tags
2555 for (int j = pos; j >= 0; --j)
2556 os << "</" << stack[j] << ">";
2559 sprintf(stack[++pos], "%s", tag);
2562 for (int i = 0; i <= pos; ++i)
2563 os << "<" << stack[i] << ">";
2567 void Buffer::pop_tag(ostream & os, char const * tag,
2568 int & pos, char stack[5][3])
2572 // pop all tags till specified one
2573 for (j = pos; (j >= 0) && (strcmp(stack[j], tag)); --j)
2574 os << "</" << stack[j] << ">";
2577 os << "</" << tag << ">";
2579 // push all tags, but the specified one
2580 for (j = j + 1; j <= pos; ++j) {
2581 os << "<" << stack[j] << ">";
2582 strcpy(stack[j-1], stack[j]);
2588 // Handle internal paragraph parsing -- layout already processed.
2590 // checks, if newcol chars should be put into this line
2591 // writes newline, if necessary.
2593 void linux_doc_line_break(ostream & os, unsigned int & colcount,
2594 const unsigned int newcol)
2597 if (colcount > lyxrc.ascii_linelen) {
2599 colcount = newcol; // assume write after this call
2604 void Buffer::SimpleLinuxDocOnePar(ostream & os, LyXParagraph * par,
2605 int desc_on, int const /*depth*/)
2607 LyXFont font1, font2;
2610 LyXParagraph::size_type main_body;
2612 LyXLayout const & style = textclasslist.Style(params.textclass,
2615 char family_type = 0; // family font flag
2616 bool is_bold = false; // series font flag
2617 char shape_type = 0; // shape font flag
2618 bool is_em = false; // emphasis (italic) font flag
2620 int stack_num = -1; // style stack position
2621 // Can this be rewritten to use a std::stack, please. (Lgb)
2622 char stack[5][3]; // style stack
2623 unsigned int char_line_count = 5; // Heuristic choice ;-)
2625 if (style.labeltype != LABEL_MANUAL)
2628 main_body = par->BeginningOfMainBody();
2630 // gets paragraph main font
2632 font1 = style.labelfont;
2637 // parsing main loop
2638 for (LyXParagraph::size_type i = 0;
2639 i < par->size(); ++i) {
2642 if (i == main_body && !par->IsDummy()) {
2647 font2 = par->getFont(i);
2649 if (font1.family() != font2.family()) {
2650 switch(family_type) {
2652 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2653 push_tag(os, "tt", stack_num, stack);
2656 else if (font2.family() == LyXFont::SANS_FAMILY) {
2657 push_tag(os, "sf", stack_num, stack);
2662 pop_tag(os, "tt", stack_num, stack);
2663 if (font2.family() == LyXFont::SANS_FAMILY) {
2664 push_tag(os, "sf", stack_num, stack);
2672 pop_tag(os, "sf", stack_num, stack);
2673 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2674 push_tag(os, "tt", stack_num, stack);
2684 if (font1.series() != font2.series()) {
2685 if (font2.series() == LyXFont::BOLD_SERIES) {
2686 push_tag(os, "bf", stack_num, stack);
2690 pop_tag(os, "bf", stack_num, stack);
2695 // handle italic and slanted fonts
2696 if (font1.shape() != font2.shape()) {
2697 switch(shape_type) {
2699 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2700 push_tag(os, "it", stack_num, stack);
2703 else if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2704 push_tag(os, "sl", stack_num, stack);
2709 pop_tag(os, "it", stack_num, stack);
2710 if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2711 push_tag(os, "sl", stack_num, stack);
2719 pop_tag(os, "sl", stack_num, stack);
2720 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2721 push_tag(os, "it", stack_num, stack);
2730 if (font1.emph() != font2.emph()) {
2731 if (font2.emph() == LyXFont::ON) {
2732 push_tag(os, "em", stack_num, stack);
2735 pop_tag(os, "em", stack_num, stack);
2740 c = par->GetChar(i);
2742 if (font2.latex() == LyXFont::ON) {
2743 // "TeX"-Mode on == > SGML-Mode on.
2745 os << c; // see LaTeX-Generation...
2747 } else if (c == LyXParagraph::META_INSET) {
2748 inset = par->GetInset(i);
2749 inset->Linuxdoc(os);
2752 if (par->linuxDocConvertChar(c, sgml_string)
2753 && !style.free_spacing) { // in freespacing
2755 // non-breaking characters
2759 linux_doc_line_break(os, char_line_count, 6);
2764 linux_doc_line_break(os, char_line_count, 1);
2770 char_line_count += sgml_string.length();
2776 // needed if there is an optional argument but no contents
2777 if (main_body > 0 && main_body == par->size()) {
2781 // pop all defined Styles
2782 for (j = stack_num; j >= 0; --j) {
2783 linux_doc_line_break(os,
2785 3 + strlen(stack[j]));
2786 os << "</" << stack[j] << ">";
2789 // resets description flag correctly
2792 // <tag> not closed...
2793 linux_doc_line_break(os, char_line_count, 6);
2797 // fprintf(file, "</p>");
2803 // Print an error message.
2804 void Buffer::LinuxDocError(LyXParagraph * par, int pos,
2805 char const * message)
2807 InsetError * new_inset;
2809 // insert an error marker in text
2810 new_inset = new InsetError(message);
2811 par->InsertChar(pos, LyXParagraph::META_INSET);
2812 par->InsertInset(pos, new_inset);
2815 // This constant defines the maximum number of
2816 // environment layouts that can be nesteded.
2817 // The same applies for command layouts.
2818 // These values should be more than enough.
2819 // José Matos (1999/07/22)
2821 enum { MAX_NEST_LEVEL = 25};
2823 void Buffer::makeDocBookFile(string const & fname, int column)
2825 LyXParagraph * par = paragraph;
2827 string top_element= textclasslist.LatexnameOfClass(params.textclass);
2828 // Please use a real stack.
2829 string environment_stack[MAX_NEST_LEVEL];
2830 string environment_inner[MAX_NEST_LEVEL];
2831 // Please use a real stack.
2832 string command_stack[MAX_NEST_LEVEL];
2833 bool command_flag= false;
2834 int command_depth= 0, command_base= 0, cmd_depth= 0;
2836 string item_name, command_name;
2837 string c_depth, c_params, tmps;
2839 int depth = 0; // paragraph depth
2841 tex_code_break_column = column;
2843 ofstream ofs(fname.c_str());
2845 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2851 ofs << "<!doctype " << top_element
2852 << " public \"-//OASIS//DTD DocBook V3.1//EN\"";
2854 if (params.preamble.empty())
2857 ofs << "\n [ " << params.preamble << " \n]>\n\n";
2859 ofs << "<!-- DocBook file was created by " << LYX_DOCVERSION
2860 << "\n See http://www.lyx.org/ for more information -->\n";
2862 if(params.options.empty())
2863 sgmlOpenTag(ofs, 0, top_element);
2865 string top = top_element;
2867 top += params.options;
2868 sgmlOpenTag(ofs, 0, top);
2872 int desc_on = 0; // description mode
2873 LyXLayout const & style =
2874 textclasslist.Style(users->buffer()->params.textclass,
2876 #warning please check if this call is really needed!!!
2877 // par->AutoDeleteInsets();
2879 // environment tag closing
2880 for( ; depth > par->depth; --depth) {
2881 if(environment_inner[depth] != "!-- --") {
2882 item_name= "listitem";
2883 sgmlCloseTag(ofs, command_depth + depth,
2885 if( environment_inner[depth] == "varlistentry")
2886 sgmlCloseTag(ofs, depth+command_depth,
2887 environment_inner[depth]);
2889 sgmlCloseTag(ofs, depth + command_depth,
2890 environment_stack[depth]);
2891 environment_stack[depth].erase();
2892 environment_inner[depth].erase();
2895 if(depth == par->depth
2896 && environment_stack[depth] != style.latexname()
2897 && !environment_stack[depth].empty()) {
2898 if(environment_inner[depth] != "!-- --") {
2899 item_name= "listitem";
2900 sgmlCloseTag(ofs, command_depth+depth,
2902 if( environment_inner[depth] == "varlistentry")
2904 depth + command_depth,
2905 environment_inner[depth]);
2908 sgmlCloseTag(ofs, depth + command_depth,
2909 environment_stack[depth]);
2911 environment_stack[depth].erase();
2912 environment_inner[depth].erase();
2915 // Write opening SGML tags.
2916 switch(style.latextype) {
2917 case LATEX_PARAGRAPH:
2918 if(style.latexname() != "dummy")
2919 sgmlOpenTag(ofs, depth+command_depth,
2925 LinuxDocError(par, 0,
2926 _("Error : Wrong depth for "
2927 "LatexType Command.\n"));
2929 command_name = style.latexname();
2931 tmps = style.latexparam();
2932 c_params = split(tmps, c_depth,'|');
2934 cmd_depth= atoi(c_depth.c_str());
2937 if(cmd_depth<command_base) {
2938 for(int j = command_depth;
2939 j >= command_base; --j)
2940 if(!command_stack[j].empty())
2941 sgmlCloseTag(ofs, j, command_stack[j]);
2942 command_depth= command_base= cmd_depth;
2944 else if(cmd_depth <= command_depth) {
2945 for(int j = command_depth;
2946 j >= cmd_depth; --j)
2948 if(!command_stack[j].empty())
2949 sgmlCloseTag(ofs, j, command_stack[j]);
2950 command_depth= cmd_depth;
2953 command_depth= cmd_depth;
2956 command_depth = command_base = cmd_depth;
2957 command_flag = true;
2959 command_stack[command_depth]= command_name;
2961 // treat label as a special case for
2962 // more WYSIWYM handling.
2963 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2964 Inset * inset = par->GetInset(0);
2965 char lyx_code = inset->LyxCode();
2966 if (lyx_code == Inset::LABEL_CODE){
2967 command_name += " id=\"";
2968 command_name += (static_cast<InsetCommand *>(inset))->getContents();
2969 command_name += "\"";
2974 sgmlOpenTag(ofs, depth+command_depth, command_name);
2975 item_name = "title";
2976 sgmlOpenTag(ofs, depth + 1 + command_depth, item_name);
2979 case LATEX_ENVIRONMENT:
2980 case LATEX_ITEM_ENVIRONMENT:
2981 if (depth < par->depth) {
2983 environment_stack[depth].erase();
2986 if (environment_stack[depth] != style.latexname()) {
2987 environment_stack[depth] = style.latexname();
2988 environment_inner[depth] = "!-- --";
2989 sgmlOpenTag(ofs, depth + command_depth,
2990 environment_stack[depth]);
2992 if(environment_inner[depth] != "!-- --") {
2993 item_name= "listitem";
2995 command_depth + depth,
2997 if (environment_inner[depth] == "varlistentry")
2999 depth + command_depth,
3000 environment_inner[depth]);
3004 if(style.latextype == LATEX_ENVIRONMENT) {
3005 if(!style.latexparam().empty())
3006 sgmlOpenTag(ofs, depth + command_depth,
3007 style.latexparam());
3011 desc_on = (style.labeltype == LABEL_MANUAL);
3014 environment_inner[depth]= "varlistentry";
3016 environment_inner[depth]= "listitem";
3018 sgmlOpenTag(ofs, depth + 1 + command_depth,
3019 environment_inner[depth]);
3023 sgmlOpenTag(ofs, depth + 1 + command_depth,
3028 sgmlOpenTag(ofs, depth + 1 + command_depth,
3033 sgmlOpenTag(ofs, depth + command_depth,
3040 SimpleDocBookOnePar(ofs, extra_par, par, desc_on,
3041 depth + 1 + command_depth);
3043 DocBookHandleFootnote(ofs, par,
3044 depth + 1 + command_depth);
3046 while(par && par->IsDummy());
3049 // write closing SGML tags
3050 switch(style.latextype) {
3053 sgmlCloseTag(ofs, depth + command_depth, end_tag);
3055 case LATEX_ENVIRONMENT:
3056 if(!style.latexparam().empty())
3057 sgmlCloseTag(ofs, depth + command_depth,
3058 style.latexparam());
3060 case LATEX_ITEM_ENVIRONMENT:
3061 if(desc_on == 1) break;
3063 sgmlCloseTag(ofs, depth + 1 + command_depth, end_tag);
3065 case LATEX_PARAGRAPH:
3066 if(style.latexname() != "dummy")
3067 sgmlCloseTag(ofs, depth + command_depth,
3071 sgmlCloseTag(ofs, depth + command_depth,
3078 for(; depth >= 0; --depth) {
3079 if(!environment_stack[depth].empty()) {
3080 if(environment_inner[depth] != "!-- --") {
3081 item_name= "listitem";
3082 sgmlCloseTag(ofs, command_depth + depth,
3084 if( environment_inner[depth] == "varlistentry")
3085 sgmlCloseTag(ofs, depth + command_depth,
3086 environment_inner[depth]);
3089 sgmlCloseTag(ofs, depth + command_depth,
3090 environment_stack[depth]);
3094 for(int j = command_depth; j >= command_base; --j)
3095 if(!command_stack[j].empty())
3096 sgmlCloseTag(ofs, j, command_stack[j]);
3099 sgmlCloseTag(ofs, 0, top_element);
3102 // How to check for successful close
3106 void Buffer::SimpleDocBookOnePar(ostream & os, string & extra,
3107 LyXParagraph * par, int & desc_on,
3111 par->SimpleDocBookOneTablePar(os, extra, desc_on, depth);
3115 bool emph_flag = false;
3117 LyXLayout const & style = textclasslist.Style(params.textclass,
3120 LyXParagraph::size_type main_body;
3121 if (style.labeltype != LABEL_MANUAL)
3124 main_body = par->BeginningOfMainBody();
3126 // gets paragraph main font
3127 LyXFont font1 = main_body > 0 ? style.labelfont : style.font;
3129 int char_line_count = depth;
3130 if(!style.free_spacing)
3131 for (int j = 0; j < depth; ++j)
3134 // parsing main loop
3135 for (LyXParagraph::size_type i = 0;
3136 i < par->size(); ++i) {
3137 LyXFont font2 = par->getFont(i);
3139 // handle <emphasis> tag
3140 if (font1.emph() != font2.emph() && i) {
3141 if (font2.emph() == LyXFont::ON) {
3145 os << "</emphasis>";
3150 char c = par->GetChar(i);
3152 if (c == LyXParagraph::META_INSET) {
3153 Inset * inset = par->GetInset(i);
3155 std::ostringstream ost;
3156 inset->DocBook(ost);
3157 string tmp_out = ost.str().c_str();
3160 inset->DocBook(ost);
3162 char * ctmp = ost.str();
3163 string tmp_out(ctmp);
3167 // This code needs some explanation:
3168 // Two insets are treated specially
3169 // label if it is the first element in a command paragraph
3171 // graphics inside tables or figure floats can't go on
3172 // title (the equivalente in latex for this case is caption
3173 // and title should come first
3176 if(desc_on!= 3 || i!= 0) {
3177 if(!tmp_out.empty() && tmp_out[0] == '@') {
3179 extra += frontStrip(tmp_out, '@');
3181 os << frontStrip(tmp_out, '@');
3186 } else if (font2.latex() == LyXFont::ON) {
3187 // "TeX"-Mode on ==> SGML-Mode on.
3193 if (par->linuxDocConvertChar(c, sgml_string)
3194 && !style.free_spacing) { // in freespacing
3196 // non-breaking characters
3200 os << "\n</term><listitem><para>";
3212 // needed if there is an optional argument but no contents
3213 if (main_body > 0 && main_body == par->size()) {
3217 os << "</emphasis>";
3220 // resets description flag correctly
3223 // <term> not closed...
3231 int Buffer::runLaTeX()
3233 if (!users->text) return 0;
3235 ProhibitInput(users);
3237 // get LaTeX-Filename
3238 string name = getLatexName();
3240 string path = OnlyPath(filename);
3242 string org_path = path;
3243 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3247 Path p(path); // path to LaTeX file
3248 users->owner()->getMiniBuffer()->Set(_("Running LaTeX..."));
3250 // Remove all error insets
3251 bool a = users->removeAutoInsets();
3253 // Always generate the LaTeX file
3254 makeLaTeXFile(name, org_path, false);
3257 // do the LaTex run(s)
3259 string latex_command = lyxrc.pdf_mode ?
3260 lyxrc.pdflatex_command : lyxrc.latex_command;
3261 LaTeX latex(latex_command, name, filepath);
3262 int res = latex.run(terr,
3263 users->owner()->getMiniBuffer()); // running latex
3265 // check return value from latex.run().
3266 if ((res & LaTeX::NO_LOGFILE)) {
3267 WriteAlert(_("LaTeX did not work!"),
3268 _("Missing log file:"), name);
3269 } else if ((res & LaTeX::ERRORS)) {
3270 users->owner()->getMiniBuffer()->Set(_("Done"));
3271 // Insert all errors as errors boxes
3272 users->insertErrors(terr);
3274 // Dvi should also be kept dirty if the latex run
3275 // ends up with errors. However it should be possible
3276 // to view a dirty dvi too.
3278 //no errors or any other things to think about so:
3279 users->owner()->getMiniBuffer()->Set(_("Done"));
3283 // if we removed error insets before we ran LaTeX or if we inserted
3284 // error insets after we ran LaTeX this must be run:
3285 if (a || (res & LaTeX::ERRORS)){
3288 //users->updateScrollbar();
3292 return latex.getNumErrors();
3296 int Buffer::runLiterate()
3298 if (!users->text) return 0;
3300 ProhibitInput(users);
3302 // get LaTeX-Filename
3303 string name = getLatexName();
3304 // get Literate-Filename
3305 string lit_name = OnlyFilename(ChangeExtension (getLatexName(),
3306 lyxrc.literate_extension));
3308 string path = OnlyPath(filename);
3310 string org_path = path;
3311 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3315 Path p(path); // path to Literate file
3316 users->owner()->getMiniBuffer()->Set(_("Running Literate..."));
3318 // Remove all error insets
3319 bool a = users->removeAutoInsets();
3321 // generate the Literate file if necessary
3322 if (!isDviClean() || a) {
3323 makeLaTeXFile(lit_name, org_path, false);
3327 string latex_command = lyxrc.pdf_mode ?
3328 lyxrc.pdflatex_command : lyxrc.latex_command;
3329 Literate literate(latex_command, name, filepath,
3331 lyxrc.literate_command, lyxrc.literate_error_filter,
3332 lyxrc.build_command, lyxrc.build_error_filter);
3334 int res = literate.weave(terr, users->owner()->getMiniBuffer());
3336 // check return value from literate.weave().
3337 if ((res & Literate::NO_LOGFILE)) {
3338 WriteAlert(_("Literate command did not work!"),
3339 _("Missing log file:"), name);
3340 } else if ((res & Literate::ERRORS)) {
3341 users->owner()->getMiniBuffer()->Set(_("Done"));
3342 // Insert all errors as errors boxes
3343 users->insertErrors(terr);
3345 // Dvi should also be kept dirty if the latex run
3346 // ends up with errors. However it should be possible
3347 // to view a dirty dvi too.
3349 //no errors or any other things to think about so:
3350 users->owner()->getMiniBuffer()->Set(_("Done"));
3354 // if we removed error insets before we ran LaTeX or if we inserted
3355 // error insets after we ran LaTeX this must be run:
3356 if (a || (res & Literate::ERRORS)){
3359 //users->updateScrollbar();
3363 return literate.getNumErrors();
3367 int Buffer::buildProgram()
3369 if (!users->text) return 0;
3371 ProhibitInput(users);
3373 // get LaTeX-Filename
3374 string name = getLatexName();
3375 // get Literate-Filename
3376 string lit_name = OnlyFilename(ChangeExtension(getLatexName(),
3377 lyxrc.literate_extension));
3379 string path = OnlyPath(filename);
3381 string org_path = path;
3382 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3386 Path p(path); // path to Literate file
3387 users->owner()->getMiniBuffer()->Set(_("Building Program..."));
3389 // Remove all error insets
3390 bool a = users->removeAutoInsets();
3392 // generate the LaTeX file if necessary
3393 if (!isNwClean() || a) {
3394 makeLaTeXFile(lit_name, org_path, false);
3398 string latex_command = lyxrc.pdf_mode ?
3399 lyxrc.pdflatex_command : lyxrc.latex_command;
3400 Literate literate(latex_command, name, filepath,
3402 lyxrc.literate_command, lyxrc.literate_error_filter,
3403 lyxrc.build_command, lyxrc.build_error_filter);
3405 int res = literate.build(terr, users->owner()->getMiniBuffer());
3407 // check return value from literate.build().
3408 if ((res & Literate::NO_LOGFILE)) {
3409 WriteAlert(_("Build did not work!"),
3410 _("Missing log file:"), name);
3411 } else if ((res & Literate::ERRORS)) {
3412 users->owner()->getMiniBuffer()->Set(_("Done"));
3413 // Insert all errors as errors boxes
3414 users->insertErrors(terr);
3416 // Literate files should also be kept dirty if the literate
3417 // command run ends up with errors.
3419 //no errors or any other things to think about so:
3420 users->owner()->getMiniBuffer()->Set(_("Done"));
3424 // if we removed error insets before we ran Literate/Build or
3425 // if we inserted error insets after we ran Literate/Build this
3427 if (a || (res & Literate::ERRORS)){
3430 //users->updateScrollbar();
3434 return literate.getNumErrors();
3438 // This should be enabled when the Chktex class is implemented. (Asger)
3439 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
3440 // Other flags: -wall -v0 -x
3441 int Buffer::runChktex()
3443 if (!users->text) return 0;
3445 ProhibitInput(users);
3447 // get LaTeX-Filename
3448 string name = getLatexName();
3449 string path = OnlyPath(filename);
3451 string org_path = path;
3452 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3456 Path p(path); // path to LaTeX file
3457 users->owner()->getMiniBuffer()->Set(_("Running chktex..."));
3459 // Remove all error insets
3460 bool a = users->removeAutoInsets();
3462 // Generate the LaTeX file if neccessary
3463 if (!isDviClean() || a) {
3464 makeLaTeXFile(name, org_path, false);
3469 Chktex chktex(lyxrc.chktex_command, name, filepath);
3470 int res = chktex.run(terr); // run chktex
3473 WriteAlert(_("chktex did not work!"),
3474 _("Could not run with file:"), name);
3475 } else if (res > 0) {
3476 // Insert all errors as errors boxes
3477 users->insertErrors(terr);
3480 // if we removed error insets before we ran chktex or if we inserted
3481 // error insets after we ran chktex, this must be run:
3485 //users->updateScrollbar();
3494 void Buffer::RoffAsciiTable(ostream & os, LyXParagraph * par)
3496 LyXFont font1(LyXFont::ALL_INHERIT,params.language_info);
3499 LyXParagraph::size_type i;
3503 string fname1 = TmpFileName(string(), "RAT1");
3504 string fname2 = TmpFileName(string(), "RAT2");
3506 ofstream ofs(fname1.c_str());
3508 WriteAlert(_("LYX_ERROR:"),
3509 _("Cannot open temporary file:"), fname1);
3512 par->table->RoffEndOfCell(ofs, -1);
3513 for (i = 0; i < par->size(); ++i) {
3514 c = par->GetChar(i);
3515 if (par->table->IsContRow(cell)) {
3516 if (c == LyXParagraph::META_NEWLINE)
3520 font2 = par->GetFontSettings(i);
3521 if (font1.latex() != font2.latex()) {
3522 if (font2.latex() != LyXFont::OFF)
3526 case LyXParagraph::META_INSET:
3527 if ((inset = par->GetInset(i))) {
3529 stringstresm ss(ios::in | ios::out);
3556 case LyXParagraph::META_NEWLINE:
3557 if (par->table->CellHasContRow(cell)>= 0)
3558 par->RoffContTableRows(ofs, i+1, cell);
3559 par->table->RoffEndOfCell(ofs, cell);
3562 case LyXParagraph::META_HFILL:
3572 << "RoffAsciiTable:"
3573 " NULL char in structure." << endl;
3577 par->table->RoffEndOfCell(ofs, cell);
3579 string cmd = lyxrc.ascii_roff_command + " >" + fname2;
3580 cmd = subst(cmd, "$$FName", fname1);
3581 Systemcalls one(Systemcalls::System, cmd);
3582 if (!(lyxerr.debugging(Debug::ROFF))) {
3583 remove(fname1.c_str());
3585 ifstream ifs(fname2.c_str());
3587 WriteFSAlert(_("Error! Can't open temporary file:"), fname2);
3590 // now output the produced file
3594 WriteAlert(_("Error!"),
3595 _("Error executing *roff command on table"));
3596 // overread leading blank lines
3597 while(!ifs && (c == '\n'))
3600 for(j = 0; j < par->depth; ++j)
3602 while(!ifs && (c != '\n')) {
3607 // overread trailing blank lines
3608 while(!ifs && (c == '\n'))
3612 remove(fname2.c_str());
3617 /// changed Heinrich Bauer, 23/03/98
3618 bool Buffer::isDviClean() const
3620 if (lyxrc.use_tempdir)
3621 return dvi_clean_tmpd;
3623 return dvi_clean_orgd;
3627 /// changed Heinrich Bauer, 23/03/98
3628 void Buffer::markDviClean()
3630 if (lyxrc.use_tempdir)
3631 dvi_clean_tmpd = true;
3633 dvi_clean_orgd = true;
3637 /// changed Heinrich Bauer, 23/03/98
3638 void Buffer::markDviDirty()
3640 if (lyxrc.use_tempdir)
3641 dvi_clean_tmpd = false;
3643 dvi_clean_orgd = false;
3647 void Buffer::validate(LaTeXFeatures & features) const
3649 LyXParagraph * par = paragraph;
3650 LyXTextClass const & tclass =
3651 textclasslist.TextClass(params.textclass);
3653 // AMS Style is at document level
3655 features.amsstyle = (params.use_amsmath ||
3656 tclass.provides(LyXTextClass::amsmath));
3659 // We don't use "lyxerr.debug" because of speed. (Asger)
3660 if (lyxerr.debugging(Debug::LATEX))
3661 lyxerr << "Paragraph: " << par << endl;
3663 // Now just follow the list of paragraphs and run
3664 // validate on each of them.
3665 par->validate(features);
3667 // and then the next paragraph
3671 // the bullet shapes are buffer level not paragraph level
3672 // so they are tested here
3673 for (int i = 0; i < 4; ++i) {
3674 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
3675 int font = params.user_defined_bullets[i].getFont();
3678 .user_defined_bullets[i]
3685 features.latexsym = true;
3689 features.amssymb = true;
3691 else if ((font >= 2 && font <= 5)) {
3692 features.pifont = true;
3697 if (lyxerr.debugging(Debug::LATEX)) {
3698 features.showStruct();
3703 void Buffer::setPaperStuff()
3705 params.papersize = BufferParams::PAPER_DEFAULT;
3706 char c1 = params.paperpackage;
3707 if (c1 == BufferParams::PACKAGE_NONE) {
3708 char c2 = params.papersize2;
3709 if (c2 == BufferParams::VM_PAPER_USLETTER)
3710 params.papersize = BufferParams::PAPER_USLETTER;
3711 else if (c2 == BufferParams::VM_PAPER_USLEGAL)
3712 params.papersize = BufferParams::PAPER_LEGALPAPER;
3713 else if (c2 == BufferParams::VM_PAPER_USEXECUTIVE)
3714 params.papersize = BufferParams::PAPER_EXECUTIVEPAPER;
3715 else if (c2 == BufferParams::VM_PAPER_A3)
3716 params.papersize = BufferParams::PAPER_A3PAPER;
3717 else if (c2 == BufferParams::VM_PAPER_A4)
3718 params.papersize = BufferParams::PAPER_A4PAPER;
3719 else if (c2 == BufferParams::VM_PAPER_A5)
3720 params.papersize = BufferParams::PAPER_A5PAPER;
3721 else if ((c2 == BufferParams::VM_PAPER_B3) || (c2 == BufferParams::VM_PAPER_B4) ||
3722 (c2 == BufferParams::VM_PAPER_B5))
3723 params.papersize = BufferParams::PAPER_B5PAPER;
3724 } else if ((c1 == BufferParams::PACKAGE_A4) || (c1 == BufferParams::PACKAGE_A4WIDE) ||
3725 (c1 == BufferParams::PACKAGE_WIDEMARGINSA4))
3726 params.papersize = BufferParams::PAPER_A4PAPER;
3730 // This function should be in Buffer because it's a buffer's property (ale)
3731 string Buffer::getIncludeonlyList(char delim)
3734 LyXParagraph * par = paragraph;
3735 LyXParagraph::size_type pos;
3739 while ((inset = par->ReturnNextInsetPointer(pos))){
3740 if (inset->LyxCode() == Inset::INCLUDE_CODE) {
3741 InsetInclude * insetinc =
3742 static_cast<InsetInclude*>(inset);
3743 if (insetinc->isInclude()
3744 && insetinc->isNoLoad()) {
3747 lst += OnlyFilename(ChangeExtension(insetinc->getContents(), string()));
3754 lyxerr.debug() << "Includeonly(" << lst << ')' << endl;
3759 // This is also a buffer property (ale)
3760 string Buffer::getReferenceList(char delim)
3762 /// if this is a child document and the parent is already loaded
3763 /// Use the parent's list instead [ale990407]
3764 if (!params.parentname.empty()
3765 && bufferlist.exists(params.parentname)) {
3766 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3768 return tmp->getReferenceList(delim);
3771 LyXParagraph * par = paragraph;
3772 LyXParagraph::size_type pos;
3777 while ((inset = par->ReturnNextInsetPointer(pos))){
3778 for (int i = 0; i < inset->GetNumberOfLabels(); ++i) {
3781 lst += inset->getLabel(i);
3787 lyxerr.debug() << "References(" << lst << ")" << endl;
3792 // This is also a buffer property (ale)
3793 string Buffer::getBibkeyList(char delim)
3795 /// if this is a child document and the parent is already loaded
3796 /// Use the parent's list instead [ale990412]
3797 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3798 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3800 return tmp->getBibkeyList(delim);
3804 LyXParagraph * par = paragraph;
3807 if (!bibkeys.empty())
3809 bibkeys += par->bibkey->getContents();
3814 // Might be either using bibtex or a child has bibliography
3815 if (bibkeys.empty()) {
3819 LyXParagraph::size_type pos = -1;
3821 // Search for Bibtex or Include inset
3822 while ((inset = par->ReturnNextInsetPointer(pos))) {
3823 if (inset-> LyxCode() == Inset::BIBTEX_CODE) {
3824 if (!bibkeys.empty())
3826 bibkeys += static_cast<InsetBibtex*>(inset)->getKeys(delim);
3827 } else if (inset-> LyxCode() == Inset::INCLUDE_CODE) {
3828 string bk = static_cast<InsetInclude*>(inset)->getKeys(delim);
3830 if (!bibkeys.empty())
3841 lyxerr.debug() << "Bibkeys(" << bibkeys << ")" << endl;
3846 bool Buffer::isDepClean(string const & name) const
3848 DEPCLEAN * item = dep_clean;
3849 while (item && item->master != name)
3851 if (!item) return true;
3856 void Buffer::markDepClean(string const & name)
3859 dep_clean = new DEPCLEAN;
3860 dep_clean->clean = true;
3861 dep_clean->master = name;
3862 dep_clean->next = 0;
3864 DEPCLEAN* item = dep_clean;
3865 while (item && item->master != name)
3870 item = new DEPCLEAN;
3872 item->master = name;
3879 bool Buffer::Dispatch(string const & command)
3881 // Split command string into command and argument
3882 string cmd, line = frontStrip(command);
3883 string arg = strip(frontStrip(split(line, cmd, ' ')));
3885 return Dispatch(lyxaction.LookupFunc(cmd.c_str()), arg.c_str());
3889 bool Buffer::Dispatch(int action, string const & argument)
3891 bool dispatched = true;
3894 MenuExport(this, argument);
3904 void Buffer::ChangeLanguage(Language const * from, Language const * to)
3907 LyXParagraph * par = paragraph;
3909 par->ChangeLanguage(from, to);
3915 bool Buffer::isMultiLingual()
3918 LyXParagraph * par = paragraph;
3920 if (par->isMultiLingual())