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 par->table = new LyXTable(lex);
1029 } else if (token == "\\hfill") {
1030 par->InsertChar(pos, LyXParagraph::META_HFILL);
1031 par->SetFont(pos, font);
1033 } else if (token == "\\protected_separator") { // obsolete
1034 // This is a backward compability thingie. (Lgb)
1035 // Remove it later some time...introduced with fileformat
1037 LyXLayout const & layout =
1038 textclasslist.Style(params.textclass,
1041 if (layout.free_spacing) {
1042 par->InsertChar(pos, ' ');
1043 par->SetFont(pos, font);
1045 Inset * inset = new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
1046 par->InsertChar(pos, LyXParagraph::META_INSET);
1047 par->InsertInset(pos, inset);
1048 par->SetFont(pos, font);
1051 } else if (token == "\\bibitem") { // ale970302
1053 par->bibkey = new InsetBibKey;
1054 par->bibkey->Read(lex);
1055 }else if (token == "\\backslash") {
1056 par->InsertChar(pos, '\\');
1057 par->SetFont(pos, font);
1059 }else if (token == "\\the_end") {
1060 the_end_read = true;
1062 // This should be insurance for the future: (Asger)
1063 lex.printError("Unknown token `$$Token'. "
1064 "Inserting as text.");
1065 for(string::const_iterator cit = token.begin();
1066 cit != token.end(); ++cit) {
1067 par->InsertChar(pos, (*cit));
1068 par->SetFont(pos, font);
1072 return the_end_read;
1075 bool Buffer::readFile(LyXLex & lex, LyXParagraph * par)
1081 token = lex.GetString();
1082 if (token == "\\lyxformat") { // the first token _must_ be...
1084 format = lex.GetFloat();
1086 if (LYX_FORMAT - format > 0.05) {
1087 printf(_("Warning: need lyxformat %.2f but found %.2f\n"),
1088 LYX_FORMAT, format);
1090 if (format - LYX_FORMAT > 0.05) {
1091 printf(_("ERROR: need lyxformat %.2f but found %.2f\n"),
1092 LYX_FORMAT, format);
1094 bool the_end = readLyXformat2(lex, par);
1095 // Formats >= 2.13 support "\the_end" marker
1102 WriteAlert(_("Warning!"),
1103 _("Reading of document is not complete"),
1104 _("Maybe the document is truncated"));
1105 // We simulate a safe reading anyways to allow
1106 // users to take the chance... (Asger)
1110 WriteAlert(_("ERROR!"),
1111 _("Old LyX file format found. "
1112 "Use LyX 0.10.x to read this!"));
1116 } else { // "\\lyxformat" not found
1117 WriteAlert(_("ERROR!"), _("Not a LyX file!"));
1120 WriteAlert(_("ERROR!"), _("Unable to read file!"));
1126 // Should probably be moved to somewhere else: BufferView? LyXView?
1127 bool Buffer::save() const
1129 // We don't need autosaves in the immediate future. (Asger)
1130 resetAutosaveTimers();
1134 if (lyxrc.make_backup) {
1135 s = fileName() + '~';
1136 if (!lyxrc.backupdir_path.empty())
1137 s = AddName(lyxrc.backupdir_path,
1138 subst(CleanupPath(s),'/','!'));
1140 // Rename is the wrong way of making a backup,
1141 // this is the correct way.
1142 /* truss cp fil fil2:
1143 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
1144 stat("LyXVC.lyx", 0xEFFFF688) = 0
1145 open("LyXVC.lyx", O_RDONLY) = 3
1146 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
1147 fstat(4, 0xEFFFF508) = 0
1148 fstat(3, 0xEFFFF508) = 0
1149 read(3, " # T h i s f i l e w".., 8192) = 5579
1150 write(4, " # T h i s f i l e w".., 5579) = 5579
1151 read(3, 0xEFFFD4A0, 8192) = 0
1154 chmod("LyXVC3.lyx", 0100644) = 0
1155 lseek(0, 0, SEEK_CUR) = 46440
1159 // Should proabaly have some more error checking here.
1160 // Should be cleaned up in 0.13, at least a bit.
1161 // Doing it this way, also makes the inodes stay the same.
1162 // This is still not a very good solution, in particular we
1163 // might loose the owner of the backup.
1164 FileInfo finfo(fileName());
1165 if (finfo.exist()) {
1166 mode_t fmode = finfo.getMode();
1167 struct utimbuf times = {
1168 finfo.getAccessTime(),
1169 finfo.getModificationTime() };
1171 ifstream ifs(fileName().c_str());
1172 ofstream ofs(s.c_str(), ios::out|ios::trunc);
1177 ::chmod(s.c_str(), fmode);
1179 if (::utime(s.c_str(), ×)) {
1180 lyxerr << "utime error." << endl;
1183 lyxerr << "LyX was not able to make "
1184 "backupcopy. Beware." << endl;
1189 if (writeFile(fileName(), false)) {
1192 // now delete the autosavefile
1193 string a = OnlyPath(fileName());
1195 a += OnlyFilename(fileName());
1197 FileInfo fileinfo(a);
1198 if (fileinfo.exist()) {
1199 if (::remove(a.c_str()) != 0) {
1200 WriteFSAlert(_("Could not delete "
1201 "auto-save file!"), a);
1205 // Saving failed, so backup is not backup
1206 if (lyxrc.make_backup) {
1207 ::rename(s.c_str(), fileName().c_str());
1215 // Returns false if unsuccesful
1216 bool Buffer::writeFile(string const & fname, bool flag) const
1218 // if flag is false writeFile will not create any GUI
1219 // warnings, only cerr.
1220 // Needed for autosave in background or panic save (Matthias 120496)
1222 if (read_only && (fname == filename)) {
1223 // Here we should come with a question if we should
1224 // perform the write anyway.
1226 lyxerr << _("Error! Document is read-only: ")
1229 WriteAlert(_("Error! Document is read-only: "),
1234 FileInfo finfo(fname);
1235 if (finfo.exist() && !finfo.writable()) {
1236 // Here we should come with a question if we should
1237 // try to do the save anyway. (i.e. do a chmod first)
1239 lyxerr << _("Error! Cannot write file: ")
1242 WriteFSAlert(_("Error! Cannot write file: "),
1247 ofstream ofs(fname.c_str());
1250 lyxerr << _("Error! Cannot open file: ")
1253 WriteFSAlert(_("Error! Cannot open file: "),
1257 // The top of the file should not be written by params.
1259 // write out a comment in the top of the file
1260 ofs << '#' << LYX_DOCVERSION
1261 << " created this file. For more info see http://www.lyx.org/\n";
1262 ofs.setf(ios::showpoint|ios::fixed);
1264 ofs << "\\lyxformat " << setw(4) << LYX_FORMAT << "\n";
1266 // now write out the buffer paramters.
1267 params.writeFile(ofs);
1269 char footnoteflag = 0;
1272 // this will write out all the paragraphs
1273 // using recursive descent.
1274 paragraph->writeFile(ofs, params, footnoteflag, depth);
1276 // Write marker that shows file is complete
1277 ofs << "\n\\the_end" << endl;
1279 // how to check if close went ok?
1284 void Buffer::writeFileAscii(string const & fname, int linelen)
1286 LyXFont font1, font2;
1288 char c, footnoteflag = 0, depth = 0;
1290 LyXParagraph::size_type i;
1291 int j, h, ltype = 0, ltype_depth = 0,
1292 * clen = 0, actcell = 0, actpos = 0, cell = 0, cells = 0,
1295 bool ref_printed = false;
1297 ofstream ofs(fname.c_str());
1299 WriteFSAlert(_("Error: Cannot write file:"), fname);
1303 string fname1 = TmpFileName();
1304 LyXParagraph * par = paragraph;
1308 if (par->footnoteflag != LyXParagraph::NO_FOOTNOTE ||
1310 par->previous->footnoteflag == LyXParagraph::NO_FOOTNOTE){
1312 /* begins a footnote environment ? */
1313 if (footnoteflag != par->footnoteflag) {
1314 footnoteflag = par->footnoteflag;
1316 j = strlen(string_footnotekinds[par->footnotekind])+4;
1317 if (currlinelen + j > linelen)
1320 << string_footnotekinds[par->footnotekind] << "] ";
1325 /* begins or ends a deeper area ?*/
1326 if (depth != par->depth) {
1327 if (par->depth > depth) {
1328 while (par->depth > depth) {
1333 while (par->depth < depth) {
1339 /* First write the layout */
1340 tmp = textclasslist.NameOfLayout(params.textclass, par->layout);
1341 if (tmp == "Itemize") {
1343 ltype_depth = depth+1;
1344 } else if (tmp == "Enumerate") {
1346 ltype_depth = depth+1;
1347 } else if (strstr(tmp.c_str(), "ection")) {
1349 ltype_depth = depth+1;
1350 } else if (strstr(tmp.c_str(), "aragraph")) {
1352 ltype_depth = depth+1;
1353 } else if (tmp == "Description") {
1355 ltype_depth = depth+1;
1356 } else if (tmp == "Abstract") {
1359 } else if (tmp == "Bibliography") {
1367 /* maybe some vertical spaces */
1369 /* the labelwidthstring used in lists */
1373 /* some pagebreaks? */
1377 /* what about the alignment */
1379 /* dummy layout, that means a footnote ended */
1380 footnoteflag = LyXParagraph::NO_FOOTNOTE;
1385 //LyXLayout const & layout =
1386 // textclasslist.Style(params.textclass,
1387 // par->GetLayout()); // unused
1388 //bool free_spc = layout.free_spacing; //unused
1390 /* It might be a table */
1393 if (!lyxrc.ascii_roff_command.empty() &&
1394 lyxrc.ascii_roff_command != "none") {
1395 RoffAsciiTable(ofs, par);
1402 cells = par->table->columns;
1403 clen = new int [cells];
1404 memset(clen, 0, sizeof(int) * cells);
1406 for (i = 0, j = 0, h = 1; i < par->size(); ++i, ++h) {
1407 c = par->GetChar(i);
1408 if (c == LyXParagraph::META_INSET) {
1409 if ((inset = par->GetInset(i))) {
1411 std::ostringstream ost;
1413 h += ost.str().length();
1418 char * tmp = ost.str();
1424 } else if (c == LyXParagraph::META_NEWLINE) {
1428 j = (++j) % par->table->NumberOfCellsInRow(actcell);
1436 font1 = LyXFont(LyXFont::ALL_INHERIT, params.language_info);
1438 for (i = 0, actpos = 1; i < par->size(); ++i, ++actpos) {
1439 if (!i && !footnoteflag && !noparbreak){
1441 for(j = 0; j < depth; ++j)
1443 currlinelen = depth * 2;
1445 case 0: /* Standard */
1446 case 4: /* (Sub)Paragraph */
1447 case 5: /* Description */
1449 case 6: /* Abstract */
1450 ofs << "Abstract\n\n";
1452 case 7: /* Bibliography */
1454 ofs << "References\n\n";
1459 ofs << par->labelstring << " ";
1462 if (ltype_depth > depth) {
1463 for(j = ltype_depth - 1; j > depth; --j)
1465 currlinelen += (ltype_depth-depth)*2;
1468 for(j = 0; j < cells; ++j) {
1470 for(h = 0; h < (clen[j] + 1);
1475 for(j = 0; j < depth; ++j)
1477 currlinelen = depth * 2;
1478 if (ltype_depth > depth) {
1479 for(j = ltype_depth;
1482 currlinelen += (ltype_depth-depth)*2;
1487 font2 = par->GetFontSettings(i);
1488 if (font1.latex() != font2.latex()) {
1489 if (font2.latex() == LyXFont::OFF)
1496 c = par->GetChar(i);
1500 case LyXParagraph::META_INSET:
1501 if ((inset = par->GetInset(i))) {
1504 currlinelen += (ofs.tellp() - fpos);
1505 actpos += (ofs.tellp() - fpos) - 1;
1508 case LyXParagraph::META_NEWLINE:
1510 if (par->table->NumberOfCellsInRow(actcell) <= cell) {
1511 for(j = actpos; j < clen[cell - 1]; ++j)
1514 for(j = 0; j < depth; ++j)
1516 currlinelen = depth*2;
1517 if (ltype_depth > depth) {
1518 for(j = ltype_depth; j > depth; --j)
1520 currlinelen += (ltype_depth-depth) * 2;
1522 for(j = 0; j < cells; ++j) {
1524 for(h = 0; h < (clen[j] + 1); ++h)
1528 for(j = 0; j < depth; ++j)
1530 currlinelen = depth * 2;
1531 if (ltype_depth > depth) {
1532 for(j = ltype_depth;
1535 currlinelen += (ltype_depth-depth)*2;
1541 j < clen[cell - 1]; ++j)
1547 currlinelen = actpos = 0;
1550 for(j = 0; j < depth; ++j)
1552 currlinelen = depth * 2;
1553 if (ltype_depth > depth) {
1554 for(j = ltype_depth;
1557 currlinelen += (ltype_depth - depth) * 2;
1561 case LyXParagraph::META_HFILL:
1568 if (currlinelen > linelen - 10
1569 && c == ' ' && i + 2 < par->size()) {
1571 for(j = 0; j < depth; ++j)
1573 currlinelen = depth * 2;
1574 if (ltype_depth > depth) {
1575 for(j = ltype_depth;
1578 currlinelen += (ltype_depth-depth)*2;
1580 } else if (c != '\0')
1583 lyxerr.debug() << "writeAsciiFile: NULL char in structure." << endl;
1589 for(j = actpos; j < clen[cell - 1]; ++j)
1592 for(j = 0; j < depth; ++j)
1594 currlinelen = depth * 2;
1595 if (ltype_depth > depth) {
1596 for(j = ltype_depth; j > depth; --j)
1598 currlinelen += (ltype_depth - depth) * 2;
1600 for(j = 0; j < cells; ++j) {
1602 for(h = 0; h < (clen[j] + 1); ++h)
1615 void Buffer::makeLaTeXFile(string const & fname,
1616 string const & original_path,
1617 bool nice, bool only_body)
1619 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
1621 niceFile = nice; // this will be used by Insetincludes.
1623 tex_code_break_column = lyxrc.ascii_linelen;
1625 LyXTextClass const & tclass =
1626 textclasslist.TextClass(params.textclass);
1628 ofstream ofs(fname.c_str());
1630 WriteFSAlert(_("Error: Cannot open file: "), fname);
1634 // validate the buffer.
1635 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
1636 LaTeXFeatures features(params, tclass.numLayouts());
1638 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
1641 // The starting paragraph of the coming rows is the
1642 // first paragraph of the document. (Asger)
1643 texrow.start(paragraph, 0);
1645 if (!only_body && nice) {
1646 ofs << "%% " LYX_DOCVERSION " created this file. "
1647 "For more info, see http://www.lyx.org/.\n"
1648 "%% Do not edit unless you really know what "
1653 lyxerr.debug() << "lyx header finished" << endl;
1654 // There are a few differences between nice LaTeX and usual files:
1655 // usual is \batchmode and has a
1656 // special input@path to allow the including of figures
1657 // with either \input or \includegraphics (what figinsets do).
1658 // batchmode is not set if there is a tex_code_break_column.
1659 // In this case somebody is interested in the generated LaTeX,
1660 // so this is OK. input@path is set when the actual parameter
1661 // original_path is set. This is done for usual tex-file, but not
1662 // for nice-latex-file. (Matthias 250696)
1665 // code for usual, NOT nice-latex-file
1666 ofs << "\\batchmode\n"; // changed
1667 // from \nonstopmode
1670 if (!original_path.empty()) {
1671 ofs << "\\makeatletter\n"
1672 << "\\def\\input@path{{"
1673 << original_path << "/}}\n"
1674 << "\\makeatother\n";
1680 ofs << "\\documentclass";
1682 string options; // the document class options.
1684 if (tokenPos(tclass.opt_fontsize(), '|', params.fontsize) >= 0) {
1685 // only write if existing in list (and not default)
1686 options += params.fontsize;
1691 if (!params.use_geometry &&
1692 (params.paperpackage == BufferParams::PACKAGE_NONE)) {
1693 switch (params.papersize) {
1694 case BufferParams::PAPER_A4PAPER:
1695 options += "a4paper,";
1697 case BufferParams::PAPER_USLETTER:
1698 options += "letterpaper,";
1700 case BufferParams::PAPER_A5PAPER:
1701 options += "a5paper,";
1703 case BufferParams::PAPER_B5PAPER:
1704 options += "b5paper,";
1706 case BufferParams::PAPER_EXECUTIVEPAPER:
1707 options += "executivepaper,";
1709 case BufferParams::PAPER_LEGALPAPER:
1710 options += "legalpaper,";
1716 if (params.sides != tclass.sides()) {
1717 switch (params.sides) {
1718 case LyXTextClass::OneSide:
1719 options += "oneside,";
1721 case LyXTextClass::TwoSides:
1722 options += "twoside,";
1729 if (params.columns != tclass.columns()) {
1730 if (params.columns == 2)
1731 options += "twocolumn,";
1733 options += "onecolumn,";
1736 if (!params.use_geometry
1737 && params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1738 options += "landscape,";
1740 // language should be a parameter to \documentclass
1741 bool use_babel = false;
1742 if (params.language_info->RightToLeft) // This seems necessary
1743 features.UsedLanguages.insert(default_language);
1744 if (params.language != "default" ||
1745 !features.UsedLanguages.empty() ) {
1747 for (LaTeXFeatures::LanguageList::const_iterator cit =
1748 features.UsedLanguages.begin();
1749 cit != features.UsedLanguages.end(); ++cit)
1750 options += (*cit)->lang + ",";
1751 options += params.language_info->lang + ',';
1754 // the user-defined options
1755 if (!params.options.empty()) {
1756 options += params.options + ',';
1759 if (!options.empty()){
1760 options = strip(options, ',');
1761 ofs << '[' << options << ']';
1765 << textclasslist.LatexnameOfClass(params.textclass)
1768 // end of \documentclass defs
1770 // font selection must be done before loading fontenc.sty
1771 if (params.fonts != "default") {
1772 ofs << "\\usepackage{" << params.fonts << "}\n";
1775 // this one is not per buffer
1776 if (lyxrc.fontenc != "default") {
1777 ofs << "\\usepackage[" << lyxrc.fontenc
1781 if (params.inputenc != "default") {
1782 ofs << "\\usepackage[" << params.inputenc
1787 // At the very beginning the text parameters.
1788 if (params.paperpackage != BufferParams::PACKAGE_NONE) {
1789 switch (params.paperpackage) {
1790 case BufferParams::PACKAGE_A4:
1791 ofs << "\\usepackage{a4}\n";
1794 case BufferParams::PACKAGE_A4WIDE:
1795 ofs << "\\usepackage{a4wide}\n";
1798 case BufferParams::PACKAGE_WIDEMARGINSA4:
1799 ofs << "\\usepackage[widemargins]{a4}\n";
1804 if (params.use_geometry) {
1805 ofs << "\\usepackage{geometry}\n";
1807 ofs << "\\geometry{verbose";
1808 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1809 ofs << ",landscape";
1810 switch (params.papersize2) {
1811 case BufferParams::VM_PAPER_CUSTOM:
1812 if (!params.paperwidth.empty())
1813 ofs << ",paperwidth="
1814 << params.paperwidth;
1815 if (!params.paperheight.empty())
1816 ofs << ",paperheight="
1817 << params.paperheight;
1819 case BufferParams::VM_PAPER_USLETTER:
1820 ofs << ",letterpaper";
1822 case BufferParams::VM_PAPER_USLEGAL:
1823 ofs << ",legalpaper";
1825 case BufferParams::VM_PAPER_USEXECUTIVE:
1826 ofs << ",executivepaper";
1828 case BufferParams::VM_PAPER_A3:
1831 case BufferParams::VM_PAPER_A4:
1834 case BufferParams::VM_PAPER_A5:
1837 case BufferParams::VM_PAPER_B3:
1840 case BufferParams::VM_PAPER_B4:
1843 case BufferParams::VM_PAPER_B5:
1847 // default papersize ie BufferParams::VM_PAPER_DEFAULT
1848 switch (lyxrc.default_papersize) {
1849 case BufferParams::PAPER_DEFAULT: // keep compiler happy
1850 case BufferParams::PAPER_USLETTER:
1851 ofs << ",letterpaper";
1853 case BufferParams::PAPER_LEGALPAPER:
1854 ofs << ",legalpaper";
1856 case BufferParams::PAPER_EXECUTIVEPAPER:
1857 ofs << ",executivepaper";
1859 case BufferParams::PAPER_A3PAPER:
1862 case BufferParams::PAPER_A4PAPER:
1865 case BufferParams::PAPER_A5PAPER:
1868 case BufferParams::PAPER_B5PAPER:
1873 if (!params.topmargin.empty())
1874 ofs << ",tmargin=" << params.topmargin;
1875 if (!params.bottommargin.empty())
1876 ofs << ",bmargin=" << params.bottommargin;
1877 if (!params.leftmargin.empty())
1878 ofs << ",lmargin=" << params.leftmargin;
1879 if (!params.rightmargin.empty())
1880 ofs << ",rmargin=" << params.rightmargin;
1881 if (!params.headheight.empty())
1882 ofs << ",headheight=" << params.headheight;
1883 if (!params.headsep.empty())
1884 ofs << ",headsep=" << params.headsep;
1885 if (!params.footskip.empty())
1886 ofs << ",footskip=" << params.footskip;
1890 if (params.use_amsmath
1891 && !tclass.provides(LyXTextClass::amsmath)) {
1892 ofs << "\\usepackage{amsmath}\n";
1896 if (tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle) >= 0) {
1897 if (params.pagestyle == "fancy") {
1898 ofs << "\\usepackage{fancyhdr}\n";
1901 ofs << "\\pagestyle{" << params.pagestyle << "}\n";
1905 // We try to load babel late, in case it interferes
1906 // with other packages.
1908 ofs << lyxrc.language_package << endl;
1912 if (params.secnumdepth != tclass.secnumdepth()) {
1913 ofs << "\\setcounter{secnumdepth}{"
1914 << params.secnumdepth
1918 if (params.tocdepth != tclass.tocdepth()) {
1919 ofs << "\\setcounter{tocdepth}{"
1925 if (params.paragraph_separation) {
1926 switch (params.defskip.kind()) {
1927 case VSpace::SMALLSKIP:
1928 ofs << "\\setlength\\parskip{\\smallskipamount}\n";
1930 case VSpace::MEDSKIP:
1931 ofs << "\\setlength\\parskip{\\medskipamount}\n";
1933 case VSpace::BIGSKIP:
1934 ofs << "\\setlength\\parskip{\\bigskipamount}\n";
1936 case VSpace::LENGTH:
1937 ofs << "\\setlength\\parskip{"
1938 << params.defskip.length().asLatexString()
1941 default: // should never happen // Then delete it.
1942 ofs << "\\setlength\\parskip{\\medskipamount}\n";
1947 ofs << "\\setlength\\parindent{0pt}\n";
1951 // Now insert the LyX specific LaTeX commands...
1952 string preamble, tmppreamble;
1954 // The optional packages;
1955 preamble = features.getPackages();
1957 // this might be useful...
1958 preamble += "\n\\makeatletter\n\n";
1960 // Some macros LyX will need
1961 tmppreamble = features.getMacros();
1963 if (!tmppreamble.empty()) {
1964 preamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1965 "LyX specific LaTeX commands.\n"
1966 + tmppreamble + '\n';
1969 // the text class specific preamble
1970 tmppreamble = features.getTClassPreamble();
1971 if (!tmppreamble.empty()) {
1972 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1973 "Textclass specific LaTeX commands.\n"
1974 + tmppreamble + '\n';
1977 /* the user-defined preamble */
1978 if (!params.preamble.empty()) {
1979 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1980 "User specified LaTeX commands.\n"
1981 + params.preamble + '\n';
1984 preamble += "\\makeatother\n\n";
1986 // Itemize bullet settings need to be last in case the user
1987 // defines their own bullets that use a package included
1988 // in the user-defined preamble -- ARRae
1989 // Actually it has to be done much later than that
1990 // since some packages like frenchb make modifications
1991 // at \begin{document} time -- JMarc
1993 for (int i = 0; i < 4; ++i) {
1994 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
1995 if (bullets_def.empty())
1996 bullets_def="\\AtBeginDocument{\n";
1997 bullets_def += " \\renewcommand{\\labelitemi";
1999 // `i' is one less than the item to modify
2006 bullets_def += "ii";
2012 bullets_def += "}{" +
2013 params.user_defined_bullets[i].getText()
2018 if (!bullets_def.empty())
2019 preamble += bullets_def + "}\n\n";
2021 for (int j = countChar(preamble, '\n'); j-- ;) {
2028 ofs << "\\begin{document}\n\n";
2032 lyxerr.debug() << "preamble finished, now the body." << endl;
2033 if (!lyxrc.language_auto_begin && params.language != "default") {
2034 ofs << subst(lyxrc.language_command_begin, "$$lang",
2040 latexParagraphs(ofs, paragraph, 0, texrow);
2042 // add this just in case after all the paragraphs
2046 if (!lyxrc.language_auto_end && params.language != "default") {
2047 ofs << subst(lyxrc.language_command_end, "$$lang",
2054 ofs << "\\end{document}\n";
2057 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
2059 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
2063 // Just to be sure. (Asger)
2066 // tex_code_break_column's value is used to decide
2067 // if we are in batchmode or not (within mathed_write()
2068 // in math_write.C) so we must set it to a non-zero
2069 // value when we leave otherwise we save incorrect .lyx files.
2070 tex_code_break_column = lyxrc.ascii_linelen;
2074 lyxerr << "File was not closed properly." << endl;
2077 lyxerr.debug() << "Finished making latex file." << endl;
2081 // LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
2083 void Buffer::latexParagraphs(ostream & ofs, LyXParagraph *par,
2084 LyXParagraph *endpar, TexRow & texrow)
2086 bool was_title = false;
2087 bool already_title = false;
2089 std::ostringstream ftnote;
2091 char * tmpholder = 0;
2097 while (par != endpar) {
2098 #ifndef HAVE_SSTREAM
2101 ftnote << tmpholder;
2102 delete [] tmpholder;
2107 lyxerr[Debug::LATEX] << "Error in latexParagraphs."
2109 LyXLayout const & layout =
2110 textclasslist.Style(params.textclass,
2113 if (layout.intitle) {
2114 if (already_title) {
2115 lyxerr <<"Error in latexParagraphs: You"
2116 " should not mix title layouts"
2117 " with normal ones." << endl;
2120 } else if (was_title && !already_title) {
2121 ofs << "\\maketitle\n";
2123 already_title = true;
2126 // We are at depth 0 so we can just use
2127 // ordinary \footnote{} generation
2128 // flag this with ftcount
2130 if (layout.isEnvironment()
2131 || par->pextra_type != LyXParagraph::PEXTRA_NONE) {
2132 par = par->TeXEnvironment(ofs, texrow,
2133 ftnote, ft_texrow, ftcount);
2135 par = par->TeXOnePar(ofs, texrow, false,
2136 ftnote, ft_texrow, ftcount);
2139 // Write out what we've generated...
2142 ofs << "\\addtocounter{footnote}{-"
2146 ofs << ftnote.str();
2147 texrow += ft_texrow;
2149 // The extra .c_str() is needed when we use
2150 // lyxstring instead of the STL string class.
2151 ftnote.str(string().c_str());
2153 delete [] ftnote.str();
2158 #ifndef HAVE_SSTREAM
2160 // I hate strstreams
2161 tmpholder = ftnote.str();
2165 #ifndef HAVE_SSTREAM
2166 delete [] tmpholder;
2168 // It might be that we only have a title in this document
2169 if (was_title && !already_title) {
2170 ofs << "\\maketitle\n";
2175 bool Buffer::isLatex() const
2177 return textclasslist.TextClass(params.textclass).outputType() == LATEX;
2181 bool Buffer::isLinuxDoc() const
2183 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC;
2187 bool Buffer::isLiterate() const
2189 return textclasslist.TextClass(params.textclass).outputType() == LITERATE;
2193 bool Buffer::isDocBook() const
2195 return textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2199 bool Buffer::isSGML() const
2201 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC ||
2202 textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2206 void Buffer::sgmlOpenTag(ostream & os, int depth,
2207 string const & latexname) const
2209 os << string(depth, ' ') << "<" << latexname << ">\n";
2213 void Buffer::sgmlCloseTag(ostream & os, int depth,
2214 string const & latexname) const
2216 os << string(depth, ' ') << "</" << latexname << ">\n";
2220 void Buffer::makeLinuxDocFile(string const & fname, int column)
2222 LyXParagraph * par = paragraph;
2224 string top_element = textclasslist.LatexnameOfClass(params.textclass);
2225 string environment_stack[10];
2228 int depth = 0; // paragraph depth
2230 ofstream ofs(fname.c_str());
2233 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2237 tex_code_break_column = column;
2240 if (params.preamble.empty()) {
2241 ofs << "<!doctype linuxdoc system>\n\n";
2244 ofs << "<!doctype linuxdoc system \n [ "
2245 << params.preamble << " \n]>\n\n";
2248 ofs << "<!-- " << LYX_DOCVERSION
2249 << " created this file. For more info see http://www.lyx.org/"
2252 if(params.options.empty())
2253 sgmlOpenTag(ofs, 0, top_element);
2255 string top = top_element;
2257 top += params.options;
2258 sgmlOpenTag(ofs, 0, top);
2262 int desc_on = 0; // description mode
2263 LyXLayout const & style =
2264 textclasslist.Style(users->buffer()->params.textclass,
2266 par->AutoDeleteInsets();
2268 // treat <toc> as a special case for compatibility with old code
2269 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2270 Inset * inset = par->GetInset(0);
2271 char lyx_code = inset->LyxCode();
2272 if (lyx_code == Inset::TOC_CODE){
2273 string temp = "toc";
2274 sgmlOpenTag(ofs, depth, temp);
2277 linuxDocHandleFootnote(ofs, par, depth);
2282 // environment tag closing
2283 for( ; depth > par->depth; --depth) {
2284 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2285 environment_stack[depth].erase();
2288 // write opening SGML tags
2289 switch(style.latextype) {
2290 case LATEX_PARAGRAPH:
2291 if(depth == par->depth
2292 && !environment_stack[depth].empty()) {
2293 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2294 environment_stack[depth].erase();
2300 sgmlOpenTag(ofs, depth, style.latexname());
2305 LinuxDocError(par, 0,
2306 _("Error : Wrong depth for"
2307 " LatexType Command.\n"));
2309 if (!environment_stack[depth].empty()){
2310 sgmlCloseTag(ofs, depth,
2311 environment_stack[depth]);
2315 environment_stack[depth].erase();
2316 sgmlOpenTag(ofs, depth, style.latexname());
2319 case LATEX_ENVIRONMENT:
2320 case LATEX_ITEM_ENVIRONMENT:
2321 if(depth == par->depth
2322 && environment_stack[depth] != style.latexname()
2323 && !environment_stack[depth].empty()) {
2325 sgmlCloseTag(ofs, depth,
2326 environment_stack[depth]);
2327 environment_stack[depth].erase();
2329 if (depth < par->depth) {
2331 environment_stack[depth].erase();
2333 if (environment_stack[depth] != style.latexname()) {
2336 sgmlOpenTag(ofs, depth, temp);
2338 environment_stack[depth] = style.latexname();
2339 sgmlOpenTag(ofs, depth,
2340 environment_stack[depth]);
2342 if(style.latextype == LATEX_ENVIRONMENT) break;
2344 desc_on = (style.labeltype == LABEL_MANUAL);
2351 sgmlOpenTag(ofs, depth + 1, item_name);
2354 sgmlOpenTag(ofs, depth, style.latexname());
2359 SimpleLinuxDocOnePar(ofs, par, desc_on, depth);
2362 linuxDocHandleFootnote(ofs, par, depth);
2364 while(par && par->IsDummy());
2367 // write closing SGML tags
2368 switch(style.latextype) {
2370 case LATEX_ENVIRONMENT:
2371 case LATEX_ITEM_ENVIRONMENT:
2374 sgmlCloseTag(ofs, depth, style.latexname());
2380 for(; depth > 0; --depth)
2381 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2383 if(!environment_stack[depth].empty())
2384 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2387 sgmlCloseTag(ofs, 0, top_element);
2390 // How to check for successful close
2394 void Buffer::linuxDocHandleFootnote(ostream & os, LyXParagraph * & par,
2397 string tag = "footnote";
2399 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2400 sgmlOpenTag(os, depth + 1, tag);
2401 SimpleLinuxDocOnePar(os, par, 0, depth + 1);
2402 sgmlCloseTag(os, depth + 1, tag);
2408 void Buffer::DocBookHandleCaption(ostream & os, string & inner_tag,
2409 int const depth, int desc_on,
2410 LyXParagraph * & par)
2412 LyXParagraph * tpar = par;
2413 while (tpar && (tpar->footnoteflag != LyXParagraph::NO_FOOTNOTE) &&
2414 (tpar->layout != textclasslist.NumberOfLayout(params.textclass,
2418 tpar->layout == textclasslist.NumberOfLayout(params.textclass,
2419 "Caption").second) {
2420 sgmlOpenTag(os, depth + 1, inner_tag);
2422 SimpleDocBookOnePar(os, extra_par, tpar,
2423 desc_on, depth + 2);
2424 sgmlCloseTag(os, depth+1, inner_tag);
2425 if(!extra_par.empty())
2431 void Buffer::DocBookHandleFootnote(ostream & os, LyXParagraph * & par,
2434 string tag, inner_tag;
2435 string tmp_par, extra_par;
2436 bool inner_span = false;
2439 // Someone should give this enum a proper name (Lgb)
2447 SOME_ENUM last = NO_ONE;
2448 SOME_ENUM present = FOOTNOTE_LIKE;
2450 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2451 if(last == present) {
2453 if(!tmp_par.empty()) {
2456 sgmlCloseTag(os, depth + 1, inner_tag);
2457 sgmlOpenTag(os, depth + 1, inner_tag);
2464 if(!inner_tag.empty()) sgmlCloseTag(os, depth + 1,
2466 if(!extra_par.empty()) os << extra_par;
2467 if(!tag.empty()) sgmlCloseTag(os, depth, tag);
2470 switch (par->footnotekind) {
2471 case LyXParagraph::FOOTNOTE:
2472 case LyXParagraph::ALGORITHM:
2475 present = FOOTNOTE_LIKE;
2478 case LyXParagraph::MARGIN:
2481 present = MARGIN_LIKE;
2484 case LyXParagraph::FIG:
2485 case LyXParagraph::WIDE_FIG:
2487 inner_tag = "title";
2491 case LyXParagraph::TAB:
2492 case LyXParagraph::WIDE_TAB:
2494 inner_tag = "title";
2499 sgmlOpenTag(os, depth, tag);
2500 if ((present == TAB_LIKE) || (present == FIG_LIKE)) {
2501 DocBookHandleCaption(os, inner_tag, depth,
2505 sgmlOpenTag(os, depth + 1, inner_tag);
2508 // ignore all caption here, we processed them above!!!
2509 if (par->layout != textclasslist
2510 .NumberOfLayout(params.textclass,
2511 "Caption").second) {
2513 std::ostringstream ost;
2517 SimpleDocBookOnePar(ost, extra_par, par,
2518 desc_on, depth + 2);
2520 tmp_par += ost.str().c_str();
2523 char * ctmp = ost.str();
2528 tmp_par = frontStrip(strip(tmp_par));
2534 if(!inner_tag.empty()) sgmlCloseTag(os, depth + 1, inner_tag);
2535 if(!extra_par.empty()) os << extra_par;
2536 if(!tag.empty()) sgmlCloseTag(os, depth, tag);
2540 // push a tag in a style stack
2541 void Buffer::push_tag(ostream & os, char const * tag,
2542 int & pos, char stack[5][3])
2544 // pop all previous tags
2545 for (int j = pos; j >= 0; --j)
2546 os << "</" << stack[j] << ">";
2549 sprintf(stack[++pos], "%s", tag);
2552 for (int i = 0; i <= pos; ++i)
2553 os << "<" << stack[i] << ">";
2557 void Buffer::pop_tag(ostream & os, char const * tag,
2558 int & pos, char stack[5][3])
2562 // pop all tags till specified one
2563 for (j = pos; (j >= 0) && (strcmp(stack[j], tag)); --j)
2564 os << "</" << stack[j] << ">";
2567 os << "</" << tag << ">";
2569 // push all tags, but the specified one
2570 for (j = j + 1; j <= pos; ++j) {
2571 os << "<" << stack[j] << ">";
2572 strcpy(stack[j-1], stack[j]);
2578 // Handle internal paragraph parsing -- layout already processed.
2580 // checks, if newcol chars should be put into this line
2581 // writes newline, if necessary.
2583 void linux_doc_line_break(ostream & os, unsigned int & colcount,
2584 const unsigned int newcol)
2587 if (colcount > lyxrc.ascii_linelen) {
2589 colcount = newcol; // assume write after this call
2594 void Buffer::SimpleLinuxDocOnePar(ostream & os, LyXParagraph * par,
2595 int desc_on, int const /*depth*/)
2597 LyXFont font1, font2;
2600 LyXParagraph::size_type main_body;
2602 LyXLayout const & style = textclasslist.Style(params.textclass,
2605 char family_type = 0; // family font flag
2606 bool is_bold = false; // series font flag
2607 char shape_type = 0; // shape font flag
2608 bool is_em = false; // emphasis (italic) font flag
2610 int stack_num = -1; // style stack position
2611 // Can this be rewritten to use a std::stack, please. (Lgb)
2612 char stack[5][3]; // style stack
2613 unsigned int char_line_count = 5; // Heuristic choice ;-)
2615 if (style.labeltype != LABEL_MANUAL)
2618 main_body = par->BeginningOfMainBody();
2620 // gets paragraph main font
2622 font1 = style.labelfont;
2627 // parsing main loop
2628 for (LyXParagraph::size_type i = 0;
2629 i < par->size(); ++i) {
2632 if (i == main_body && !par->IsDummy()) {
2637 font2 = par->getFont(i);
2639 if (font1.family() != font2.family()) {
2640 switch(family_type) {
2642 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2643 push_tag(os, "tt", stack_num, stack);
2646 else if (font2.family() == LyXFont::SANS_FAMILY) {
2647 push_tag(os, "sf", stack_num, stack);
2652 pop_tag(os, "tt", stack_num, stack);
2653 if (font2.family() == LyXFont::SANS_FAMILY) {
2654 push_tag(os, "sf", stack_num, stack);
2662 pop_tag(os, "sf", stack_num, stack);
2663 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2664 push_tag(os, "tt", stack_num, stack);
2674 if (font1.series() != font2.series()) {
2675 if (font2.series() == LyXFont::BOLD_SERIES) {
2676 push_tag(os, "bf", stack_num, stack);
2680 pop_tag(os, "bf", stack_num, stack);
2685 // handle italic and slanted fonts
2686 if (font1.shape() != font2.shape()) {
2687 switch(shape_type) {
2689 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2690 push_tag(os, "it", stack_num, stack);
2693 else if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2694 push_tag(os, "sl", stack_num, stack);
2699 pop_tag(os, "it", stack_num, stack);
2700 if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2701 push_tag(os, "sl", stack_num, stack);
2709 pop_tag(os, "sl", stack_num, stack);
2710 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2711 push_tag(os, "it", stack_num, stack);
2720 if (font1.emph() != font2.emph()) {
2721 if (font2.emph() == LyXFont::ON) {
2722 push_tag(os, "em", stack_num, stack);
2725 pop_tag(os, "em", stack_num, stack);
2730 c = par->GetChar(i);
2732 if (font2.latex() == LyXFont::ON) {
2733 // "TeX"-Mode on == > SGML-Mode on.
2735 os << c; // see LaTeX-Generation...
2737 } else if (c == LyXParagraph::META_INSET) {
2738 inset = par->GetInset(i);
2739 inset->Linuxdoc(os);
2742 if (par->linuxDocConvertChar(c, sgml_string)
2743 && !style.free_spacing) { // in freespacing
2745 // non-breaking characters
2749 linux_doc_line_break(os, char_line_count, 6);
2754 linux_doc_line_break(os, char_line_count, 1);
2760 char_line_count += sgml_string.length();
2766 // needed if there is an optional argument but no contents
2767 if (main_body > 0 && main_body == par->size()) {
2771 // pop all defined Styles
2772 for (j = stack_num; j >= 0; --j) {
2773 linux_doc_line_break(os,
2775 3 + strlen(stack[j]));
2776 os << "</" << stack[j] << ">";
2779 // resets description flag correctly
2782 // <tag> not closed...
2783 linux_doc_line_break(os, char_line_count, 6);
2787 // fprintf(file, "</p>");
2793 // Print an error message.
2794 void Buffer::LinuxDocError(LyXParagraph * par, int pos,
2795 char const * message)
2797 InsetError * new_inset;
2799 // insert an error marker in text
2800 new_inset = new InsetError(message);
2801 par->InsertChar(pos, LyXParagraph::META_INSET);
2802 par->InsertInset(pos, new_inset);
2805 // This constant defines the maximum number of
2806 // environment layouts that can be nesteded.
2807 // The same applies for command layouts.
2808 // These values should be more than enough.
2809 // José Matos (1999/07/22)
2811 enum { MAX_NEST_LEVEL = 25};
2813 void Buffer::makeDocBookFile(string const & fname, int column)
2815 LyXParagraph * par = paragraph;
2817 string top_element= textclasslist.LatexnameOfClass(params.textclass);
2818 // Please use a real stack.
2819 string environment_stack[MAX_NEST_LEVEL];
2820 string environment_inner[MAX_NEST_LEVEL];
2821 // Please use a real stack.
2822 string command_stack[MAX_NEST_LEVEL];
2823 bool command_flag= false;
2824 int command_depth= 0, command_base= 0, cmd_depth= 0;
2826 string item_name, command_name;
2827 string c_depth, c_params, tmps;
2829 int depth = 0; // paragraph depth
2831 tex_code_break_column = column;
2833 ofstream ofs(fname.c_str());
2835 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2841 ofs << "<!doctype " << top_element
2842 << " public \"-//OASIS//DTD DocBook V3.1//EN\"";
2844 if (params.preamble.empty())
2847 ofs << "\n [ " << params.preamble << " \n]>\n\n";
2849 ofs << "<!-- DocBook file was created by " << LYX_DOCVERSION
2850 << "\n See http://www.lyx.org/ for more information -->\n";
2852 if(params.options.empty())
2853 sgmlOpenTag(ofs, 0, top_element);
2855 string top = top_element;
2857 top += params.options;
2858 sgmlOpenTag(ofs, 0, top);
2862 int desc_on = 0; // description mode
2863 LyXLayout const & style =
2864 textclasslist.Style(users->buffer()->params.textclass,
2866 par->AutoDeleteInsets();
2868 // environment tag closing
2869 for( ; depth > par->depth; --depth) {
2870 if(environment_inner[depth] != "!-- --") {
2871 item_name= "listitem";
2872 sgmlCloseTag(ofs, command_depth + depth,
2874 if( environment_inner[depth] == "varlistentry")
2875 sgmlCloseTag(ofs, depth+command_depth,
2876 environment_inner[depth]);
2878 sgmlCloseTag(ofs, depth + command_depth,
2879 environment_stack[depth]);
2880 environment_stack[depth].erase();
2881 environment_inner[depth].erase();
2884 if(depth == par->depth
2885 && environment_stack[depth] != style.latexname()
2886 && !environment_stack[depth].empty()) {
2887 if(environment_inner[depth] != "!-- --") {
2888 item_name= "listitem";
2889 sgmlCloseTag(ofs, command_depth+depth,
2891 if( environment_inner[depth] == "varlistentry")
2893 depth + command_depth,
2894 environment_inner[depth]);
2897 sgmlCloseTag(ofs, depth + command_depth,
2898 environment_stack[depth]);
2900 environment_stack[depth].erase();
2901 environment_inner[depth].erase();
2904 // Write opening SGML tags.
2905 switch(style.latextype) {
2906 case LATEX_PARAGRAPH:
2907 if(style.latexname() != "dummy")
2908 sgmlOpenTag(ofs, depth+command_depth,
2914 LinuxDocError(par, 0,
2915 _("Error : Wrong depth for "
2916 "LatexType Command.\n"));
2918 command_name = style.latexname();
2920 tmps = style.latexparam();
2921 c_params = split(tmps, c_depth,'|');
2923 cmd_depth= atoi(c_depth.c_str());
2926 if(cmd_depth<command_base) {
2927 for(int j = command_depth;
2928 j >= command_base; --j)
2929 if(!command_stack[j].empty())
2930 sgmlCloseTag(ofs, j, command_stack[j]);
2931 command_depth= command_base= cmd_depth;
2933 else if(cmd_depth <= command_depth) {
2934 for(int j = command_depth;
2935 j >= cmd_depth; --j)
2937 if(!command_stack[j].empty())
2938 sgmlCloseTag(ofs, j, command_stack[j]);
2939 command_depth= cmd_depth;
2942 command_depth= cmd_depth;
2945 command_depth = command_base = cmd_depth;
2946 command_flag = true;
2948 command_stack[command_depth]= command_name;
2950 // treat label as a special case for
2951 // more WYSIWYM handling.
2952 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2953 Inset * inset = par->GetInset(0);
2954 char lyx_code = inset->LyxCode();
2955 if (lyx_code == Inset::LABEL_CODE){
2956 command_name += " id=\"";
2957 command_name += (static_cast<InsetCommand *>(inset))->getContents();
2958 command_name += "\"";
2963 sgmlOpenTag(ofs, depth+command_depth, command_name);
2964 item_name = "title";
2965 sgmlOpenTag(ofs, depth + 1 + command_depth, item_name);
2968 case LATEX_ENVIRONMENT:
2969 case LATEX_ITEM_ENVIRONMENT:
2970 if (depth < par->depth) {
2972 environment_stack[depth].erase();
2975 if (environment_stack[depth] != style.latexname()) {
2976 environment_stack[depth] = style.latexname();
2977 environment_inner[depth] = "!-- --";
2978 sgmlOpenTag(ofs, depth + command_depth,
2979 environment_stack[depth]);
2981 if(environment_inner[depth] != "!-- --") {
2982 item_name= "listitem";
2984 command_depth + depth,
2986 if (environment_inner[depth] == "varlistentry")
2988 depth + command_depth,
2989 environment_inner[depth]);
2993 if(style.latextype == LATEX_ENVIRONMENT) {
2994 if(!style.latexparam().empty())
2995 sgmlOpenTag(ofs, depth + command_depth,
2996 style.latexparam());
3000 desc_on = (style.labeltype == LABEL_MANUAL);
3003 environment_inner[depth]= "varlistentry";
3005 environment_inner[depth]= "listitem";
3007 sgmlOpenTag(ofs, depth + 1 + command_depth,
3008 environment_inner[depth]);
3012 sgmlOpenTag(ofs, depth + 1 + command_depth,
3017 sgmlOpenTag(ofs, depth + 1 + command_depth,
3022 sgmlOpenTag(ofs, depth + command_depth,
3029 SimpleDocBookOnePar(ofs, extra_par, par, desc_on,
3030 depth + 1 + command_depth);
3032 DocBookHandleFootnote(ofs, par,
3033 depth + 1 + command_depth);
3035 while(par && par->IsDummy());
3038 // write closing SGML tags
3039 switch(style.latextype) {
3042 sgmlCloseTag(ofs, depth + command_depth, end_tag);
3044 case LATEX_ENVIRONMENT:
3045 if(!style.latexparam().empty())
3046 sgmlCloseTag(ofs, depth + command_depth,
3047 style.latexparam());
3049 case LATEX_ITEM_ENVIRONMENT:
3050 if(desc_on == 1) break;
3052 sgmlCloseTag(ofs, depth + 1 + command_depth, end_tag);
3054 case LATEX_PARAGRAPH:
3055 if(style.latexname() != "dummy")
3056 sgmlCloseTag(ofs, depth + command_depth,
3060 sgmlCloseTag(ofs, depth + command_depth,
3067 for(; depth >= 0; --depth) {
3068 if(!environment_stack[depth].empty()) {
3069 if(environment_inner[depth] != "!-- --") {
3070 item_name= "listitem";
3071 sgmlCloseTag(ofs, command_depth + depth,
3073 if( environment_inner[depth] == "varlistentry")
3074 sgmlCloseTag(ofs, depth + command_depth,
3075 environment_inner[depth]);
3078 sgmlCloseTag(ofs, depth + command_depth,
3079 environment_stack[depth]);
3083 for(int j = command_depth; j >= command_base; --j)
3084 if(!command_stack[j].empty())
3085 sgmlCloseTag(ofs, j, command_stack[j]);
3088 sgmlCloseTag(ofs, 0, top_element);
3091 // How to check for successful close
3095 void Buffer::SimpleDocBookOnePar(ostream & os, string & extra,
3096 LyXParagraph * par, int & desc_on,
3100 par->SimpleDocBookOneTablePar(os, extra, desc_on, depth);
3104 bool emph_flag = false;
3106 LyXLayout const & style = textclasslist.Style(params.textclass,
3109 LyXParagraph::size_type main_body;
3110 if (style.labeltype != LABEL_MANUAL)
3113 main_body = par->BeginningOfMainBody();
3115 // gets paragraph main font
3116 LyXFont font1 = main_body > 0 ? style.labelfont : style.font;
3118 int char_line_count = depth;
3119 if(!style.free_spacing)
3120 for (int j = 0; j < depth; ++j)
3123 // parsing main loop
3124 for (LyXParagraph::size_type i = 0;
3125 i < par->size(); ++i) {
3126 LyXFont font2 = par->getFont(i);
3128 // handle <emphasis> tag
3129 if (font1.emph() != font2.emph() && i) {
3130 if (font2.emph() == LyXFont::ON) {
3134 os << "</emphasis>";
3139 char c = par->GetChar(i);
3141 if (c == LyXParagraph::META_INSET) {
3142 Inset * inset = par->GetInset(i);
3144 std::ostringstream ost;
3145 inset->DocBook(ost);
3146 string tmp_out = ost.str().c_str();
3149 inset->DocBook(ost);
3151 char * ctmp = ost.str();
3152 string tmp_out(ctmp);
3156 // This code needs some explanation:
3157 // Two insets are treated specially
3158 // label if it is the first element in a command paragraph
3160 // graphics inside tables or figure floats can't go on
3161 // title (the equivalente in latex for this case is caption
3162 // and title should come first
3165 if(desc_on!= 3 || i!= 0) {
3166 if(!tmp_out.empty() && tmp_out[0] == '@') {
3168 extra += frontStrip(tmp_out, '@');
3170 os << frontStrip(tmp_out, '@');
3175 } else if (font2.latex() == LyXFont::ON) {
3176 // "TeX"-Mode on ==> SGML-Mode on.
3182 if (par->linuxDocConvertChar(c, sgml_string)
3183 && !style.free_spacing) { // in freespacing
3185 // non-breaking characters
3189 os << "\n</term><listitem><para>";
3201 // needed if there is an optional argument but no contents
3202 if (main_body > 0 && main_body == par->size()) {
3206 os << "</emphasis>";
3209 // resets description flag correctly
3212 // <term> not closed...
3220 int Buffer::runLaTeX()
3222 if (!users->text) return 0;
3224 ProhibitInput(users);
3226 // get LaTeX-Filename
3227 string name = getLatexName();
3229 string path = OnlyPath(filename);
3231 string org_path = path;
3232 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3236 Path p(path); // path to LaTeX file
3237 users->owner()->getMiniBuffer()->Set(_("Running LaTeX..."));
3239 // Remove all error insets
3240 bool a = users->removeAutoInsets();
3242 // Always generate the LaTeX file
3243 makeLaTeXFile(name, org_path, false);
3246 // do the LaTex run(s)
3248 string latex_command = lyxrc.pdf_mode ?
3249 lyxrc.pdflatex_command : lyxrc.latex_command;
3250 LaTeX latex(latex_command, name, filepath);
3251 int res = latex.run(terr,
3252 users->owner()->getMiniBuffer()); // running latex
3254 // check return value from latex.run().
3255 if ((res & LaTeX::NO_LOGFILE)) {
3256 WriteAlert(_("LaTeX did not work!"),
3257 _("Missing log file:"), name);
3258 } else if ((res & LaTeX::ERRORS)) {
3259 users->owner()->getMiniBuffer()->Set(_("Done"));
3260 // Insert all errors as errors boxes
3261 users->insertErrors(terr);
3263 // Dvi should also be kept dirty if the latex run
3264 // ends up with errors. However it should be possible
3265 // to view a dirty dvi too.
3267 //no errors or any other things to think about so:
3268 users->owner()->getMiniBuffer()->Set(_("Done"));
3272 // if we removed error insets before we ran LaTeX or if we inserted
3273 // error insets after we ran LaTeX this must be run:
3274 if (a || (res & LaTeX::ERRORS)){
3277 //users->updateScrollbar();
3281 return latex.getNumErrors();
3285 int Buffer::runLiterate()
3287 if (!users->text) return 0;
3289 ProhibitInput(users);
3291 // get LaTeX-Filename
3292 string name = getLatexName();
3293 // get Literate-Filename
3294 string lit_name = OnlyFilename(ChangeExtension (getLatexName(),
3295 lyxrc.literate_extension));
3297 string path = OnlyPath(filename);
3299 string org_path = path;
3300 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3304 Path p(path); // path to Literate file
3305 users->owner()->getMiniBuffer()->Set(_("Running Literate..."));
3307 // Remove all error insets
3308 bool a = users->removeAutoInsets();
3310 // generate the Literate file if necessary
3311 if (!isDviClean() || a) {
3312 makeLaTeXFile(lit_name, org_path, false);
3316 string latex_command = lyxrc.pdf_mode ?
3317 lyxrc.pdflatex_command : lyxrc.latex_command;
3318 Literate literate(latex_command, name, filepath,
3320 lyxrc.literate_command, lyxrc.literate_error_filter,
3321 lyxrc.build_command, lyxrc.build_error_filter);
3323 int res = literate.weave(terr, users->owner()->getMiniBuffer());
3325 // check return value from literate.weave().
3326 if ((res & Literate::NO_LOGFILE)) {
3327 WriteAlert(_("Literate command did not work!"),
3328 _("Missing log file:"), name);
3329 } else if ((res & Literate::ERRORS)) {
3330 users->owner()->getMiniBuffer()->Set(_("Done"));
3331 // Insert all errors as errors boxes
3332 users->insertErrors(terr);
3334 // Dvi should also be kept dirty if the latex run
3335 // ends up with errors. However it should be possible
3336 // to view a dirty dvi too.
3338 //no errors or any other things to think about so:
3339 users->owner()->getMiniBuffer()->Set(_("Done"));
3343 // if we removed error insets before we ran LaTeX or if we inserted
3344 // error insets after we ran LaTeX this must be run:
3345 if (a || (res & Literate::ERRORS)){
3348 //users->updateScrollbar();
3352 return literate.getNumErrors();
3356 int Buffer::buildProgram()
3358 if (!users->text) return 0;
3360 ProhibitInput(users);
3362 // get LaTeX-Filename
3363 string name = getLatexName();
3364 // get Literate-Filename
3365 string lit_name = OnlyFilename(ChangeExtension(getLatexName(),
3366 lyxrc.literate_extension));
3368 string path = OnlyPath(filename);
3370 string org_path = path;
3371 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3375 Path p(path); // path to Literate file
3376 users->owner()->getMiniBuffer()->Set(_("Building Program..."));
3378 // Remove all error insets
3379 bool a = users->removeAutoInsets();
3381 // generate the LaTeX file if necessary
3382 if (!isNwClean() || a) {
3383 makeLaTeXFile(lit_name, org_path, false);
3387 string latex_command = lyxrc.pdf_mode ?
3388 lyxrc.pdflatex_command : lyxrc.latex_command;
3389 Literate literate(latex_command, name, filepath,
3391 lyxrc.literate_command, lyxrc.literate_error_filter,
3392 lyxrc.build_command, lyxrc.build_error_filter);
3394 int res = literate.build(terr, users->owner()->getMiniBuffer());
3396 // check return value from literate.build().
3397 if ((res & Literate::NO_LOGFILE)) {
3398 WriteAlert(_("Build did not work!"),
3399 _("Missing log file:"), name);
3400 } else if ((res & Literate::ERRORS)) {
3401 users->owner()->getMiniBuffer()->Set(_("Done"));
3402 // Insert all errors as errors boxes
3403 users->insertErrors(terr);
3405 // Literate files should also be kept dirty if the literate
3406 // command run ends up with errors.
3408 //no errors or any other things to think about so:
3409 users->owner()->getMiniBuffer()->Set(_("Done"));
3413 // if we removed error insets before we ran Literate/Build or
3414 // if we inserted error insets after we ran Literate/Build this
3416 if (a || (res & Literate::ERRORS)){
3419 //users->updateScrollbar();
3423 return literate.getNumErrors();
3427 // This should be enabled when the Chktex class is implemented. (Asger)
3428 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
3429 // Other flags: -wall -v0 -x
3430 int Buffer::runChktex()
3432 if (!users->text) return 0;
3434 ProhibitInput(users);
3436 // get LaTeX-Filename
3437 string name = getLatexName();
3438 string path = OnlyPath(filename);
3440 string org_path = path;
3441 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3445 Path p(path); // path to LaTeX file
3446 users->owner()->getMiniBuffer()->Set(_("Running chktex..."));
3448 // Remove all error insets
3449 bool a = users->removeAutoInsets();
3451 // Generate the LaTeX file if neccessary
3452 if (!isDviClean() || a) {
3453 makeLaTeXFile(name, org_path, false);
3458 Chktex chktex(lyxrc.chktex_command, name, filepath);
3459 int res = chktex.run(terr); // run chktex
3462 WriteAlert(_("chktex did not work!"),
3463 _("Could not run with file:"), name);
3464 } else if (res > 0) {
3465 // Insert all errors as errors boxes
3466 users->insertErrors(terr);
3469 // if we removed error insets before we ran chktex or if we inserted
3470 // error insets after we ran chktex, this must be run:
3474 //users->updateScrollbar();
3483 void Buffer::RoffAsciiTable(ostream & os, LyXParagraph * par)
3485 LyXFont font1(LyXFont::ALL_INHERIT,params.language_info);
3488 LyXParagraph::size_type i;
3492 string fname1 = TmpFileName(string(), "RAT1");
3493 string fname2 = TmpFileName(string(), "RAT2");
3495 ofstream ofs(fname1.c_str());
3497 WriteAlert(_("LYX_ERROR:"),
3498 _("Cannot open temporary file:"), fname1);
3501 par->table->RoffEndOfCell(ofs, -1);
3502 for (i = 0; i < par->size(); ++i) {
3503 c = par->GetChar(i);
3504 if (par->table->IsContRow(cell)) {
3505 if (c == LyXParagraph::META_NEWLINE)
3509 font2 = par->GetFontSettings(i);
3510 if (font1.latex() != font2.latex()) {
3511 if (font2.latex() != LyXFont::OFF)
3515 case LyXParagraph::META_INSET:
3516 if ((inset = par->GetInset(i))) {
3518 stringstresm ss(ios::in | ios::out);
3545 case LyXParagraph::META_NEWLINE:
3546 if (par->table->CellHasContRow(cell)>= 0)
3547 par->RoffContTableRows(ofs, i+1, cell);
3548 par->table->RoffEndOfCell(ofs, cell);
3551 case LyXParagraph::META_HFILL:
3561 << "RoffAsciiTable:"
3562 " NULL char in structure." << endl;
3566 par->table->RoffEndOfCell(ofs, cell);
3568 string cmd = lyxrc.ascii_roff_command + " >" + fname2;
3569 cmd = subst(cmd, "$$FName", fname1);
3570 Systemcalls one(Systemcalls::System, cmd);
3571 if (!(lyxerr.debugging(Debug::ROFF))) {
3572 remove(fname1.c_str());
3574 ifstream ifs(fname2.c_str());
3576 WriteFSAlert(_("Error! Can't open temporary file:"), fname2);
3579 // now output the produced file
3583 WriteAlert(_("Error!"),
3584 _("Error executing *roff command on table"));
3585 // overread leading blank lines
3586 while(!ifs && (c == '\n'))
3589 for(j = 0; j < par->depth; ++j)
3591 while(!ifs && (c != '\n')) {
3596 // overread trailing blank lines
3597 while(!ifs && (c == '\n'))
3601 remove(fname2.c_str());
3606 /// changed Heinrich Bauer, 23/03/98
3607 bool Buffer::isDviClean() const
3609 if (lyxrc.use_tempdir)
3610 return dvi_clean_tmpd;
3612 return dvi_clean_orgd;
3616 /// changed Heinrich Bauer, 23/03/98
3617 void Buffer::markDviClean()
3619 if (lyxrc.use_tempdir)
3620 dvi_clean_tmpd = true;
3622 dvi_clean_orgd = true;
3626 /// changed Heinrich Bauer, 23/03/98
3627 void Buffer::markDviDirty()
3629 if (lyxrc.use_tempdir)
3630 dvi_clean_tmpd = false;
3632 dvi_clean_orgd = false;
3636 void Buffer::validate(LaTeXFeatures & features) const
3638 LyXParagraph * par = paragraph;
3639 LyXTextClass const & tclass =
3640 textclasslist.TextClass(params.textclass);
3642 // AMS Style is at document level
3644 features.amsstyle = (params.use_amsmath ||
3645 tclass.provides(LyXTextClass::amsmath));
3648 // We don't use "lyxerr.debug" because of speed. (Asger)
3649 if (lyxerr.debugging(Debug::LATEX))
3650 lyxerr << "Paragraph: " << par << endl;
3652 // Now just follow the list of paragraphs and run
3653 // validate on each of them.
3654 par->validate(features);
3656 // and then the next paragraph
3660 // the bullet shapes are buffer level not paragraph level
3661 // so they are tested here
3662 for (int i = 0; i < 4; ++i) {
3663 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
3664 int font = params.user_defined_bullets[i].getFont();
3667 .user_defined_bullets[i]
3674 features.latexsym = true;
3678 features.amssymb = true;
3680 else if ((font >= 2 && font <= 5)) {
3681 features.pifont = true;
3686 if (lyxerr.debugging(Debug::LATEX)) {
3687 features.showStruct();
3692 void Buffer::setPaperStuff()
3694 params.papersize = BufferParams::PAPER_DEFAULT;
3695 char c1 = params.paperpackage;
3696 if (c1 == BufferParams::PACKAGE_NONE) {
3697 char c2 = params.papersize2;
3698 if (c2 == BufferParams::VM_PAPER_USLETTER)
3699 params.papersize = BufferParams::PAPER_USLETTER;
3700 else if (c2 == BufferParams::VM_PAPER_USLEGAL)
3701 params.papersize = BufferParams::PAPER_LEGALPAPER;
3702 else if (c2 == BufferParams::VM_PAPER_USEXECUTIVE)
3703 params.papersize = BufferParams::PAPER_EXECUTIVEPAPER;
3704 else if (c2 == BufferParams::VM_PAPER_A3)
3705 params.papersize = BufferParams::PAPER_A3PAPER;
3706 else if (c2 == BufferParams::VM_PAPER_A4)
3707 params.papersize = BufferParams::PAPER_A4PAPER;
3708 else if (c2 == BufferParams::VM_PAPER_A5)
3709 params.papersize = BufferParams::PAPER_A5PAPER;
3710 else if ((c2 == BufferParams::VM_PAPER_B3) || (c2 == BufferParams::VM_PAPER_B4) ||
3711 (c2 == BufferParams::VM_PAPER_B5))
3712 params.papersize = BufferParams::PAPER_B5PAPER;
3713 } else if ((c1 == BufferParams::PACKAGE_A4) || (c1 == BufferParams::PACKAGE_A4WIDE) ||
3714 (c1 == BufferParams::PACKAGE_WIDEMARGINSA4))
3715 params.papersize = BufferParams::PAPER_A4PAPER;
3719 // This function should be in Buffer because it's a buffer's property (ale)
3720 string Buffer::getIncludeonlyList(char delim)
3723 LyXParagraph * par = paragraph;
3724 LyXParagraph::size_type pos;
3728 while ((inset = par->ReturnNextInsetPointer(pos))){
3729 if (inset->LyxCode() == Inset::INCLUDE_CODE) {
3730 InsetInclude * insetinc =
3731 static_cast<InsetInclude*>(inset);
3732 if (insetinc->isInclude()
3733 && insetinc->isNoLoad()) {
3736 lst += OnlyFilename(ChangeExtension(insetinc->getContents(), string()));
3743 lyxerr.debug() << "Includeonly(" << lst << ')' << endl;
3748 // This is also a buffer property (ale)
3749 string Buffer::getReferenceList(char delim)
3751 /// if this is a child document and the parent is already loaded
3752 /// Use the parent's list instead [ale990407]
3753 if (!params.parentname.empty()
3754 && bufferlist.exists(params.parentname)) {
3755 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3757 return tmp->getReferenceList(delim);
3760 LyXParagraph * par = paragraph;
3761 LyXParagraph::size_type pos;
3766 while ((inset = par->ReturnNextInsetPointer(pos))){
3767 for (int i = 0; i < inset->GetNumberOfLabels(); ++i) {
3770 lst += inset->getLabel(i);
3776 lyxerr.debug() << "References(" << lst << ")" << endl;
3781 // This is also a buffer property (ale)
3782 string Buffer::getBibkeyList(char delim)
3784 /// if this is a child document and the parent is already loaded
3785 /// Use the parent's list instead [ale990412]
3786 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3787 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3789 return tmp->getBibkeyList(delim);
3793 LyXParagraph * par = paragraph;
3796 if (!bibkeys.empty())
3798 bibkeys += par->bibkey->getContents();
3803 // Might be either using bibtex or a child has bibliography
3804 if (bibkeys.empty()) {
3808 LyXParagraph::size_type pos = -1;
3810 // Search for Bibtex or Include inset
3811 while ((inset = par->ReturnNextInsetPointer(pos))) {
3812 if (inset-> LyxCode() == Inset::BIBTEX_CODE) {
3813 if (!bibkeys.empty())
3815 bibkeys += static_cast<InsetBibtex*>(inset)->getKeys(delim);
3816 } else if (inset-> LyxCode() == Inset::INCLUDE_CODE) {
3817 string bk = static_cast<InsetInclude*>(inset)->getKeys(delim);
3819 if (!bibkeys.empty())
3830 lyxerr.debug() << "Bibkeys(" << bibkeys << ")" << endl;
3835 bool Buffer::isDepClean(string const & name) const
3837 DEPCLEAN * item = dep_clean;
3838 while (item && item->master != name)
3840 if (!item) return true;
3845 void Buffer::markDepClean(string const & name)
3848 dep_clean = new DEPCLEAN;
3849 dep_clean->clean = true;
3850 dep_clean->master = name;
3851 dep_clean->next = 0;
3853 DEPCLEAN* item = dep_clean;
3854 while (item && item->master != name)
3859 item = new DEPCLEAN;
3861 item->master = name;
3868 bool Buffer::Dispatch(string const & command)
3870 // Split command string into command and argument
3871 string cmd, line = frontStrip(command);
3872 string arg = strip(frontStrip(split(line, cmd, ' ')));
3874 return Dispatch(lyxaction.LookupFunc(cmd.c_str()), arg.c_str());
3878 bool Buffer::Dispatch(int action, string const & argument)
3880 bool dispatched = true;
3883 MenuExport(this, argument);
3893 void Buffer::ChangeLanguage(Language const * from, Language const * to)
3896 LyXParagraph * par = paragraph;
3898 par->ChangeLanguage(from, to);
3904 bool Buffer::isMultiLingual()
3907 LyXParagraph * par = paragraph;
3909 if (par->isMultiLingual())