1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2000 The LyX Team.
9 * This file is Copyright 1996-1999
12 * ======================================================
17 // 23/03/98 Heinrich Bauer (heinrich.bauer@t-mobil.de)
18 // Spots marked "changed Heinrich Bauer, 23/03/98" modified due to the
19 // following bug: dvi file export did not work after printing (or previewing)
20 // and vice versa as long as the same file was concerned. This happened
21 // every time the LyX-file was left unchanged between the two actions mentioned
31 #include <sys/types.h>
35 #pragma implementation "buffer.h"
39 #include "bufferlist.h"
41 #include "lyx_gui_misc.h"
42 #include "LyXAction.h"
45 #include "tex-strings.h"
48 #include "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/insetnumber.h"
72 #include "insets/insetert.h"
73 #include "insets/insetgraphics.h"
74 #include "insets/insetfoot.h"
75 #include "support/filetools.h"
76 #include "support/path.h"
82 #include "LaTeXFeatures.h"
83 #include "support/syscall.h"
84 #include "support/lyxlib.h"
85 #include "support/FileInfo.h"
99 // Uncomment this line to enable a workaround for the weird behaviour
100 // of the cursor between a displayed inset and last character
101 // at the upper line. (Alejandro 20.9.96)
102 // #define BREAK_BEFORE_INSET
104 /* Lars, when changing this file sometime in the future to a list,
105 * please check out the figinsets-sideeffects described at the
106 * beginning of figinset.C Matthias (04.07.1996)
110 // all these externs should eventually be removed.
111 extern BufferList bufferlist;
113 extern void MenuExport(Buffer *, string const &);
114 extern LyXAction lyxaction;
117 static const float LYX_FORMAT = 2.16;
119 extern int tex_code_break_column;
121 extern void FreeUpdateTimer();
124 Buffer::Buffer(string const & file, bool ronly)
126 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
128 filepath = OnlyPath(file);
132 dvi_clean_orgd = false; // Heinrich Bauer, 23/03/98
133 dvi_clean_tmpd = false; // Heinrich Bauer, 23/03/98
138 if (read_only || (lyxrc.use_tempdir)) {
139 tmppath = CreateBufferTmpDir();
140 } else tmppath.clear();
146 lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
147 // here the buffer should take care that it is
148 // saved properly, before it goes into the void.
150 // make sure that views using this buffer
155 if (!tmppath.empty()) {
156 DestroyBufferTmpDir(tmppath);
159 LyXParagraph * par = paragraph;
160 LyXParagraph * tmppar;
170 bool Buffer::saveParamsAsDefaults()
172 string fname = AddName(AddPath(user_lyxdir, "templates/"),
174 Buffer defaults = Buffer(fname);
176 // Use the current buffer's parameters as default
177 defaults.params = params;
179 // add an empty paragraph. Is this enough?
180 defaults.paragraph = new LyXParagraph;
182 return defaults.writeFile(defaults.filename, false);
186 /// Update window titles of all users
187 // Should work on a list
188 void Buffer::updateTitles() const
190 if (users) users->owner()->updateWindowTitle();
194 /// Reset autosave timer of all users
195 // Should work on a list
196 void Buffer::resetAutosaveTimers() const
198 if (users) users->owner()->resetAutosaveTimer();
202 void Buffer::fileName(string const & newfile)
204 filename = MakeAbsPath(newfile);
205 filepath = OnlyPath(filename);
206 setReadonly(IsFileWriteable(filename) == 0);
211 // candidate for move to BufferView
212 // (at least some parts in the beginning of the func)
215 // changed to be public and have one parameter
216 // if par = 0 normal behavior
217 // else insert behavior
218 // Returns false if "\the_end" is not read for formats >= 2.13. (Asger)
219 #define USE_PARSE_FUNCTION 1
220 bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par)
224 char depth = 0; // signed or unsigned?
225 LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
226 LyXParagraph::footnote_kind footnotekind = LyXParagraph::FOOTNOTE;
227 bool the_end_read = false;
229 LyXParagraph * return_par = 0;
230 LyXFont font(LyXFont::ALL_INHERIT,params.language_info);
231 if (format < 2.16 && params.language == "hebrew")
232 font.setLanguage(default_language);
234 // If we are inserting, we cheat and get a token in advance
235 bool has_token = false;
239 par = new LyXParagraph;
241 users->text->BreakParagraph();
242 return_par = users->text->FirstParagraph();
245 // We don't want to adopt the parameters from the
246 // document we insert, so we skip until the text begins:
249 pretoken = lex.GetString();
250 if (pretoken == "\\layout") {
262 pretoken = lex.GetString();
265 // Profiling show this should give a lot: (Asger)
266 string const token = pretoken;
270 the_end_read = parseSingleLyXformat2Token(lex, par, return_par,
279 paragraph = return_par;
285 bool Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
286 LyXParagraph *& return_par,
287 const string & token, int & pos,
288 char & depth, LyXFont & font,
289 LyXParagraph::footnote_flag & footnoteflag,
290 LyXParagraph::footnote_kind & footnotekind)
295 bool the_end_read = false;
297 if (token[0] != '\\') {
298 int n = token.length();
299 for (int i = 0; i < n; ++i) {
300 par->InsertChar(pos, token[i]);
301 par->SetFont(pos, font);
304 } else if (token == "\\i") {
305 inset = new InsetLatexAccent;
307 par->InsertChar(pos, LyXParagraph::META_INSET);
308 par->InsertInset(pos, inset);
309 par->SetFont(pos, font);
311 } else if (token == "\\layout") {
316 par = new LyXParagraph(par);
320 string layoutname = lex.GetString();
321 pair<bool, LyXTextClass::LayoutList::size_type> pp
322 = textclasslist.NumberOfLayout(params.textclass,
325 par->layout = pp.second;
326 } else { // layout not found
327 // use default layout "Standard" (0)
330 // Test whether the layout is obsolete.
331 LyXLayout const & layout =
332 textclasslist.Style(params.textclass,
334 if (!layout.obsoleted_by().empty())
336 textclasslist.NumberOfLayout(params.textclass,
337 layout.obsoleted_by()).second;
338 par->footnoteflag = footnoteflag;
339 par->footnotekind = footnotekind;
341 font = LyXFont(LyXFont::ALL_INHERIT,params.language_info);
342 if (format < 2.16 && params.language == "hebrew")
343 font.setLanguage(default_language);
344 } else if (token == "\\end_float") {
349 par = new LyXParagraph(par);
351 footnotekind = LyXParagraph::FOOTNOTE;
352 footnoteflag = LyXParagraph::NO_FOOTNOTE;
355 par->layout = LYX_DUMMY_LAYOUT;
356 font = LyXFont(LyXFont::ALL_INHERIT,params.language_info);
357 if (format < 2.16 && params.language == "hebrew")
358 font.setLanguage(default_language);
359 } else if (token == "\\begin_float") {
360 tmpret = lex.FindToken(string_footnotekinds);
361 if (tmpret == -1) ++tmpret;
362 if (tmpret != LYX_LAYOUT_DEFAULT)
363 footnotekind = static_cast<LyXParagraph::footnote_kind>(tmpret); // bad
364 if (footnotekind == LyXParagraph::FOOTNOTE
365 || footnotekind == LyXParagraph::MARGIN)
366 footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
368 footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
369 } else if (token == "\\begin_deeper") {
371 } else if (token == "\\end_deeper") {
373 lex.printError("\\end_deeper: "
374 "depth is already null");
378 } else if (token == "\\begin_preamble") {
379 params.readPreamble(lex);
380 } else if (token == "\\textclass") {
382 pair<bool, LyXTextClassList::size_type> pp =
383 textclasslist.NumberOfClass(lex.GetString());
385 params.textclass = pp.second;
387 lex.printError("Unknown textclass `$$Token'");
388 params.textclass = 0;
390 if (!textclasslist.Load(params.textclass)) {
391 // if the textclass wasn't loaded properly
392 // we need to either substitute another
393 // or stop loading the file.
394 // I can substitute but I don't see how I can
395 // stop loading... ideas?? ARRae980418
396 WriteAlert(_("Textclass Loading Error!"),
397 string(_("Can't load textclass ")) +
398 textclasslist.NameOfClass(params.textclass),
399 _("-- substituting default"));
400 params.textclass = 0;
402 } else if (token == "\\options") {
404 params.options = lex.GetString();
405 } else if (token == "\\language") {
406 params.readLanguage(lex);
407 } else if (token == "\\fontencoding") {
409 } else if (token == "\\inputencoding") {
411 params.inputenc = lex.GetString();
412 } else if (token == "\\graphics") {
413 params.readGraphicsDriver(lex);
414 } else if (token == "\\fontscheme") {
416 params.fonts = lex.GetString();
417 } else if (token == "\\noindent") {
418 par->noindent = true;
419 } else if (token == "\\fill_top") {
420 par->added_space_top = VSpace(VSpace::VFILL);
421 } else if (token == "\\fill_bottom") {
422 par->added_space_bottom = VSpace(VSpace::VFILL);
423 } else if (token == "\\line_top") {
424 par->line_top = true;
425 } else if (token == "\\line_bottom") {
426 par->line_bottom = true;
427 } else if (token == "\\pagebreak_top") {
428 par->pagebreak_top = true;
429 } else if (token == "\\pagebreak_bottom") {
430 par->pagebreak_bottom = true;
431 } else if (token == "\\start_of_appendix") {
432 par->start_of_appendix = true;
433 } else if (token == "\\paragraph_separation") {
434 tmpret = lex.FindToken(string_paragraph_separation);
435 if (tmpret == -1) ++tmpret;
436 if (tmpret != LYX_LAYOUT_DEFAULT)
437 params.paragraph_separation =
438 static_cast<BufferParams::PARSEP>(tmpret);
439 } else if (token == "\\defskip") {
441 params.defskip = VSpace(lex.GetString());
443 } else if (token == "\\no_isolatin1") { // obsolete
445 } else if (token == "\\no_babel") { // obsolete
447 } else if (token == "\\no_epsfig") { // obsolete
450 } else if (token == "\\epsfig") { // obsolete
451 // Indeed it is obsolete, but we HAVE to be backwards
452 // compatible until 0.14, because otherwise all figures
453 // in existing documents are irretrivably lost. (Asger)
454 params.readGraphicsDriver(lex);
455 } else if (token == "\\quotes_language") {
456 tmpret = lex.FindToken(string_quotes_language);
457 if (tmpret == -1) ++tmpret;
458 if (tmpret != LYX_LAYOUT_DEFAULT) {
459 InsetQuotes::quote_language tmpl =
460 InsetQuotes::EnglishQ;
463 tmpl = InsetQuotes::EnglishQ;
466 tmpl = InsetQuotes::SwedishQ;
469 tmpl = InsetQuotes::GermanQ;
472 tmpl = InsetQuotes::PolishQ;
475 tmpl = InsetQuotes::FrenchQ;
478 tmpl = InsetQuotes::DanishQ;
481 params.quotes_language = tmpl;
483 } else if (token == "\\quotes_times") {
485 switch(lex.GetInteger()) {
487 params.quotes_times = InsetQuotes::SingleQ;
490 params.quotes_times = InsetQuotes::DoubleQ;
493 } else if (token == "\\papersize") {
494 tmpret = lex.FindToken(string_papersize);
498 params.papersize2 = tmpret;
499 } else if (token == "\\paperpackage") {
500 tmpret = lex.FindToken(string_paperpackages);
503 params.paperpackage = BufferParams::PACKAGE_NONE;
505 params.paperpackage = tmpret;
506 } else if (token == "\\use_geometry") {
508 params.use_geometry = lex.GetInteger();
509 } else if (token == "\\use_amsmath") {
511 params.use_amsmath = lex.GetInteger();
512 } else if (token == "\\paperorientation") {
513 tmpret = lex.FindToken(string_orientation);
514 if (tmpret == -1) ++tmpret;
515 if (tmpret != LYX_LAYOUT_DEFAULT)
516 params.orientation = static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
517 } else if (token == "\\paperwidth") {
519 params.paperwidth = lex.GetString();
520 } else if (token == "\\paperheight") {
522 params.paperheight = lex.GetString();
523 } else if (token == "\\leftmargin") {
525 params.leftmargin = lex.GetString();
526 } else if (token == "\\topmargin") {
528 params.topmargin = lex.GetString();
529 } else if (token == "\\rightmargin") {
531 params.rightmargin = lex.GetString();
532 } else if (token == "\\bottommargin") {
534 params.bottommargin = lex.GetString();
535 } else if (token == "\\headheight") {
537 params.headheight = lex.GetString();
538 } else if (token == "\\headsep") {
540 params.headsep = lex.GetString();
541 } else if (token == "\\footskip") {
543 params.footskip = lex.GetString();
544 } else if (token == "\\paperfontsize") {
546 params.fontsize = strip(lex.GetString());
547 } else if (token == "\\papercolumns") {
549 params.columns = lex.GetInteger();
550 } else if (token == "\\papersides") {
552 switch(lex.GetInteger()) {
554 case 1: params.sides = LyXTextClass::OneSide; break;
555 case 2: params.sides = LyXTextClass::TwoSides; break;
557 } else if (token == "\\paperpagestyle") {
559 params.pagestyle = strip(lex.GetString());
560 } else if (token == "\\bullet") {
562 int index = lex.GetInteger();
564 int temp_int = lex.GetInteger();
565 params.user_defined_bullets[index].setFont(temp_int);
566 params.temp_bullets[index].setFont(temp_int);
568 temp_int = lex.GetInteger();
569 params.user_defined_bullets[index].setCharacter(temp_int);
570 params.temp_bullets[index].setCharacter(temp_int);
572 temp_int = lex.GetInteger();
573 params.user_defined_bullets[index].setSize(temp_int);
574 params.temp_bullets[index].setSize(temp_int);
576 string temp_str = lex.GetString();
577 if (temp_str != "\\end_bullet") {
578 // this element isn't really necessary for
579 // parsing but is easier for humans
580 // to understand bullets. Put it back and
581 // set a debug message?
582 lex.printError("\\end_bullet expected, got" + temp_str);
583 //how can I put it back?
585 } else if (token == "\\bulletLaTeX") {
587 int index = lex.GetInteger();
589 string temp_str = lex.GetString(), sum_str;
590 while (temp_str != "\\end_bullet") {
591 // this loop structure is needed when user
592 // enters an empty string since the first
593 // thing returned will be the \\end_bullet
595 // if the LaTeX entry has spaces. Each element
596 // therefore needs to be read in turn
599 temp_str = lex.GetString();
601 params.user_defined_bullets[index].setText(sum_str);
602 params.temp_bullets[index].setText(sum_str);
603 } else if (token == "\\secnumdepth") {
605 params.secnumdepth = lex.GetInteger();
606 } else if (token == "\\tocdepth") {
608 params.tocdepth = lex.GetInteger();
609 } else if (token == "\\baselinestretch") { // obsolete
610 lex.nextToken(); // should not be used directly
612 // Will probably keep a kind of support just for
614 params.spacing.set(Spacing::Other, lex.GetFloat());
615 } else if (token == "\\spacing") {
617 string tmp = strip(lex.GetString());
618 if (tmp == "single") {
619 params.spacing.set(Spacing::Single);
620 } else if (tmp == "onehalf") {
621 params.spacing.set(Spacing::Onehalf);
622 } else if (tmp == "double") {
623 params.spacing.set(Spacing::Double);
624 } else if (tmp == "other") {
626 params.spacing.set(Spacing::Other,
629 lex.printError("Unknown spacing token: '$$Token'");
631 } else if (token == "\\float_placement") {
633 params.float_placement = lex.GetString();
634 } else if (token == "\\cursor") { // obsolete
635 // this is obsolete, so we just skip it.
637 } else if (token == "\\family") {
639 font.setLyXFamily(lex.GetString());
640 } else if (token == "\\series") {
642 font.setLyXSeries(lex.GetString());
643 } else if (token == "\\shape") {
645 font.setLyXShape(lex.GetString());
646 } else if (token == "\\size") {
648 font.setLyXSize(lex.GetString());
649 } else if (token == "\\latex") {
651 string tok = lex.GetString();
652 // This is dirty, but gone with LyX3. (Asger)
653 if (tok == "no_latex")
654 font.setLatex(LyXFont::OFF);
655 else if (tok == "latex")
656 font.setLatex(LyXFont::ON);
657 else if (tok == "default")
658 font.setLatex(LyXFont::INHERIT);
660 lex.printError("Unknown LaTeX font flag "
662 } else if (token == "\\lang") {
664 string tok = lex.GetString();
665 Languages::iterator lit = languages.find(tok);
666 if (lit != languages.end()) {
667 font.setLanguage(&(*lit).second);
669 font.setLanguage(params.language_info);
670 lex.printError("Unknown language `$$Token'");
672 } else if (token == "\\direction") { // obsolete
674 lex.printError("Command \\direction is obsolete");
676 string tok = lex.GetString();
678 font.setLanguage(&languages["hebrew"]);
679 else if (tok == "default")
680 if (params.language == "hebrew")
681 font.setLanguage(default_language);
683 font.setLanguage(params.language_info);
685 lex.printError("Unknown direction `$$Token'");
686 } else if (token == "\\emph") {
688 font.setEmph(font.setLyXMisc(lex.GetString()));
689 } else if (token == "\\bar") {
691 string tok = lex.GetString();
692 // This is dirty, but gone with LyX3. (Asger)
694 font.setUnderbar(LyXFont::ON);
695 else if (tok == "no")
696 font.setUnderbar(LyXFont::OFF);
697 else if (tok == "default")
698 font.setUnderbar(LyXFont::INHERIT);
700 lex.printError("Unknown bar font flag "
702 } else if (token == "\\noun") {
704 font.setNoun(font.setLyXMisc(lex.GetString()));
705 } else if (token == "\\color") {
707 font.setLyXColor(lex.GetString());
708 } else if (token == "\\align") {
709 tmpret = lex.FindToken(string_align);
710 if (tmpret == -1) ++tmpret;
711 if (tmpret != LYX_LAYOUT_DEFAULT) { // tmpret != 99 ???
713 for (; tmpret > 0; --tmpret)
714 tmpret2 = tmpret2 * 2;
715 par->align = LyXAlignment(tmpret2);
717 } else if (token == "\\added_space_top") {
719 par->added_space_top = lex.GetString();
720 } else if (token == "\\added_space_bottom") {
722 par->added_space_bottom = lex.GetString();
723 } else if (token == "\\pextra_type") {
725 par->pextra_type = lex.GetInteger();
726 } else if (token == "\\pextra_width") {
728 par->pextra_width = lex.GetString();
729 } else if (token == "\\pextra_widthp") {
731 par->pextra_widthp = lex.GetString();
732 } else if (token == "\\pextra_alignment") {
734 par->pextra_alignment = lex.GetInteger();
735 } else if (token == "\\pextra_hfill") {
737 par->pextra_hfill = lex.GetInteger();
738 } else if (token == "\\pextra_start_minipage") {
740 par->pextra_start_minipage = lex.GetInteger();
741 } else if (token == "\\labelwidthstring") {
743 par->labelwidthstring = lex.GetString();
744 /* do not delete this token, it is still needed! */
745 } else if (token == "\\end_inset") {
746 /* simple ignore this. The insets do not have
748 // but insets should read it, it is a part of
749 //the inset isn't it? Lgb.
750 } else if (token == "\\begin_inset") {
752 tmptok = lex.GetString();
753 /* test the different insets */
754 if (tmptok == "Quotes") {
755 inset = new InsetQuotes;
757 par->InsertChar(pos, LyXParagraph::META_INSET);
758 par->InsertInset(pos, inset);
759 par->SetFont(pos, font);
761 } else if (tmptok == "\\i") {
762 inset = new InsetLatexAccent;
764 par->InsertChar(pos, LyXParagraph::META_INSET);
765 par->InsertInset(pos, inset);
766 par->SetFont(pos, font);
768 } else if (tmptok == "FormulaMacro") {
769 inset = new InsetFormulaMacro;
771 par->InsertChar(pos, LyXParagraph::META_INSET);
772 par->InsertInset(pos, inset);
773 par->SetFont(pos, font);
775 } else if (tmptok == "Formula") {
776 inset = new InsetFormula;
778 par->InsertChar(pos, LyXParagraph::META_INSET);
779 par->InsertInset(pos, inset);
780 par->SetFont(pos, font);
782 } else if (tmptok == "Figure") {
783 inset = new InsetFig(100, 100, this);
785 par->InsertChar(pos, LyXParagraph::META_INSET);
786 par->InsertInset(pos, inset);
787 par->SetFont(pos, font);
789 } else if (tmptok == "Info") {
790 inset = new InsetInfo;
792 par->InsertChar(pos, LyXParagraph::META_INSET);
793 par->InsertInset(pos, inset);
794 par->SetFont(pos, font);
796 } else if (tmptok == "Include") {
797 inset = new InsetInclude(string(), this);
799 par->InsertChar(pos, LyXParagraph::META_INSET);
800 par->InsertInset(pos, inset);
801 par->SetFont(pos, font);
803 } else if (tmptok == "ERT") {
804 inset = new InsetERT(this);
806 par->InsertChar(pos, LyXParagraph::META_INSET);
807 par->InsertInset(pos, inset);
808 par->SetFont(pos, font);
810 } else if (tmptok == "Text") {
811 inset = new InsetText(this);
813 par->InsertChar(pos, LyXParagraph::META_INSET);
814 par->InsertInset(pos, inset);
815 par->SetFont(pos, font);
818 } else if (tmptok == "Number") {
819 inset = new InsetNumber(this);
821 par->InsertChar(pos, LyXParagraph::META_INSET);
822 par->InsertInset(pos, inset);
823 par->SetFont(pos, font);
826 } else if (tmptok == "Foot") {
827 inset = new InsetFoot(this);
829 par->InsertChar(pos, LyXParagraph::META_INSET);
830 par->InsertInset(pos, inset);
831 par->SetFont(pos, font);
833 } else if (tmptok == "GRAPHICS") {
834 inset = new InsetGraphics;
836 par->InsertChar(pos, LyXParagraph::META_INSET);
837 par->InsertInset(pos, inset);
838 par->SetFont(pos, font);
839 } else if (tmptok == "LatexCommand") {
842 if (inscmd.getCmdName() == "cite") {
843 inset = new InsetCitation(inscmd.getContents(), inscmd.getOptions());
844 } else if (inscmd.getCmdName() == "bibitem") {
845 lex.printError("Wrong place for bibitem");
846 inset = inscmd.Clone();
847 } else if (inscmd.getCmdName() == "BibTeX") {
848 inset = new InsetBibtex(inscmd.getContents(), inscmd.getOptions(), this);
849 } else if (inscmd.getCmdName() == "index") {
850 inset = new InsetIndex(inscmd.getContents());
851 } else if (inscmd.getCmdName() == "include") {
852 inset = new InsetInclude(inscmd.getContents(), this);
853 } else if (inscmd.getCmdName() == "label") {
854 inset = new InsetLabel(inscmd.getCommand());
855 } else if (inscmd.getCmdName() == "url"
856 || inscmd.getCmdName() == "htmlurl") {
857 inset = new InsetUrl(inscmd.getCommand());
858 } else if (inscmd.getCmdName() == "ref"
859 || inscmd.getCmdName() == "pageref") {
860 if (!inscmd.getOptions().empty() || !inscmd.getContents().empty()) {
861 inset = new InsetRef(inscmd, this);
863 #warning Check if this else clause is still needed. (Lgb)
865 // This condition comes from a
866 // temporary solution to the latexdel
867 // ref inset that was transformed to
868 // an empty ref inset plus the body
869 // surronded by latexdel insets
871 string cont, opt, tmptmptok, cmdname;
873 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
878 tmptmptok = lex.GetString();
879 if(tmptmptok[0] == '\\') {
880 if( tmptmptok == "\\backslash")
890 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
895 tmptmptok = lex.GetString();
896 if(tmptmptok[0] == '\\') {
897 if( tmptmptok == "\\backslash")
907 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
913 cmdname = "\\" + inscmd.getCmdName();
914 cmdname += "[" + cont + "]";
915 cmdname += "{" + opt + "}";
916 inset = new InsetRef(cmdname, this);
919 } else if (inscmd.getCmdName() == "tableofcontents") {
920 inset = new InsetTOC(this);
921 } else if (inscmd.getCmdName() == "listoffigures") {
922 inset = new InsetLOF(this);
923 } else if (inscmd.getCmdName() == "listofalgorithms") {
924 inset = new InsetLOA(this);
925 } else if (inscmd.getCmdName() == "listoftables") {
926 inset = new InsetLOT(this);
927 } else if (inscmd.getCmdName() == "printindex") {
928 inset = new InsetPrintIndex(this);
929 } else if (inscmd.getCmdName() == "lyxparent") {
930 inset = new InsetParent(inscmd.getContents(), this);
934 par->InsertChar(pos, LyXParagraph::META_INSET);
935 par->InsertInset(pos, inset);
936 par->SetFont(pos, font);
940 } else if (token == "\\InsetQuotes") {
941 inset = new InsetQuotes;
943 par->InsertChar(pos, LyXParagraph::META_INSET);
944 par->InsertInset(pos, inset);
945 par->SetFont(pos, font);
947 } else if (token == "\\InsetFormula") {
948 inset = new InsetFormula;
950 par->InsertChar(pos, LyXParagraph::META_INSET);
951 par->InsertInset(pos, inset);
952 par->SetFont(pos, font);
954 } else if (token == "\\SpecialChar") {
955 LyXLayout const & layout =
956 textclasslist.Style(params.textclass,
959 // Insets don't make sense in a free-spacing context! ---Kayvan
960 if (layout.free_spacing)
965 next_token = lex.GetString();
966 if (next_token == "\\-") {
967 par->InsertChar(pos, '-');
968 par->SetFont(pos, font);
969 } else if (next_token == "\\protected_separator") {
970 par->InsertChar(pos, ' ');
971 par->SetFont(pos, font);
973 lex.printError("Token `$$Token' "
975 "paragraph layout!");
982 inset = new InsetSpecialChar;
984 par->InsertChar(pos, LyXParagraph::META_INSET);
985 par->InsertInset(pos, inset);
986 par->SetFont(pos, font);
989 } else if (token == "\\Figure") {
990 inset = new InsetFig(100, 100, this);
992 par->InsertChar(pos, LyXParagraph::META_INSET);
993 par->InsertInset(pos, inset);
994 par->SetFont(pos, font);
996 } else if (token == "\\newline") { // soon obsolete
998 par->InsertChar(pos, LyXParagraph::META_NEWLINE);
999 par->SetFont(pos, font);
1001 inset = new InsetSpecialChar(InsetSpecialChar::NEWLINE);
1002 par->InsertChar(pos, LyXParagraph::META_INSET);
1003 par->InsertInset(pos, inset);
1004 par->SetFont(pos, font);
1007 } else if (token == "\\LyXTable") {
1008 par->table = new LyXTable(lex);
1009 } else if (token == "\\hfill") {
1010 par->InsertChar(pos, LyXParagraph::META_HFILL);
1011 par->SetFont(pos, font);
1013 } else if (token == "\\protected_separator") { // obsolete
1015 LyXLayout const & layout =
1016 textclasslist.Style(params.textclass,
1019 if (layout.free_spacing) {
1020 par->InsertChar(pos, ' ');
1021 par->SetFont(pos, font);
1023 inset = new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
1024 par->InsertChar(pos, LyXParagraph::META_INSET);
1025 par->InsertInset(pos, inset);
1026 par->SetFont(pos, font);
1029 par->InsertChar(pos, LyXParagraph::META_PROTECTED_SEPARATOR);
1030 par->SetFont(pos, font);
1033 } else if (token == "\\bibitem") { // ale970302
1035 par->bibkey = new InsetBibKey;
1036 par->bibkey->Read(lex);
1037 }else if (token == "\\backslash") {
1038 par->InsertChar(pos, '\\');
1039 par->SetFont(pos, font);
1041 }else if (token == "\\the_end") {
1042 the_end_read = true;
1044 // This should be insurance for the future: (Asger)
1045 lex.printError("Unknown token `$$Token'. "
1046 "Inserting as text.");
1047 int n = token.length();
1048 for (int i = 0; i < n; ++i) {
1049 par->InsertChar(pos, token[i]);
1050 par->SetFont(pos, font);
1054 return the_end_read;
1057 bool Buffer::readFile(LyXLex & lex, LyXParagraph * par)
1063 token = lex.GetString();
1064 if (token == "\\lyxformat") { // the first token _must_ be...
1066 format = lex.GetFloat();
1068 if (LYX_FORMAT - format > 0.05) {
1069 printf(_("Warning: need lyxformat %.2f but found %.2f\n"),
1070 LYX_FORMAT, format);
1072 if (format - LYX_FORMAT > 0.05) {
1073 printf(_("ERROR: need lyxformat %.2f but found %.2f\n"),
1074 LYX_FORMAT, format);
1076 bool the_end = readLyXformat2(lex, par);
1077 // Formats >= 2.13 support "\the_end" marker
1084 WriteAlert(_("Warning!"),
1085 _("Reading of document is not complete"),
1086 _("Maybe the document is truncated"));
1087 // We simulate a safe reading anyways to allow
1088 // users to take the chance... (Asger)
1092 WriteAlert(_("ERROR!"),
1093 _("Old LyX file format found. "
1094 "Use LyX 0.10.x to read this!"));
1098 } else { // "\\lyxformat" not found
1099 WriteAlert(_("ERROR!"), _("Not a LyX file!"));
1102 WriteAlert(_("ERROR!"), _("Unable to read file!"));
1108 // Should probably be moved to somewhere else: BufferView? LyXView?
1109 bool Buffer::save() const
1111 // We don't need autosaves in the immediate future. (Asger)
1112 resetAutosaveTimers();
1116 if (lyxrc.make_backup) {
1117 s = fileName() + '~';
1118 if (!lyxrc.backupdir_path.empty())
1119 s = AddName(lyxrc.backupdir_path,
1120 subst(CleanupPath(s),'/','!'));
1122 // Rename is the wrong way of making a backup,
1123 // this is the correct way.
1124 /* truss cp fil fil2:
1125 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
1126 stat("LyXVC.lyx", 0xEFFFF688) = 0
1127 open("LyXVC.lyx", O_RDONLY) = 3
1128 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
1129 fstat(4, 0xEFFFF508) = 0
1130 fstat(3, 0xEFFFF508) = 0
1131 read(3, " # T h i s f i l e w".., 8192) = 5579
1132 write(4, " # T h i s f i l e w".., 5579) = 5579
1133 read(3, 0xEFFFD4A0, 8192) = 0
1136 chmod("LyXVC3.lyx", 0100644) = 0
1137 lseek(0, 0, SEEK_CUR) = 46440
1141 // Should proabaly have some more error checking here.
1142 // Should be cleaned up in 0.13, at least a bit.
1143 // Doing it this way, also makes the inodes stay the same.
1144 // This is still not a very good solution, in particular we
1145 // might loose the owner of the backup.
1146 FileInfo finfo(fileName());
1147 if (finfo.exist()) {
1148 mode_t fmode = finfo.getMode();
1149 struct utimbuf times = {
1150 finfo.getAccessTime(),
1151 finfo.getModificationTime() };
1153 ifstream ifs(fileName().c_str());
1154 ofstream ofs(s.c_str(), ios::out|ios::trunc);
1159 ::chmod(s.c_str(), fmode);
1161 if (::utime(s.c_str(), ×)) {
1162 lyxerr << "utime error." << endl;
1165 lyxerr << "LyX was not able to make "
1166 "backupcopy. Beware." << endl;
1171 if (writeFile(fileName(), false)) {
1174 // now delete the autosavefile
1175 string a = OnlyPath(fileName());
1177 a += OnlyFilename(fileName());
1179 FileInfo fileinfo(a);
1180 if (fileinfo.exist()) {
1181 if (::remove(a.c_str()) != 0) {
1182 WriteFSAlert(_("Could not delete "
1183 "auto-save file!"), a);
1187 // Saving failed, so backup is not backup
1188 if (lyxrc.make_backup) {
1189 ::rename(s.c_str(), fileName().c_str());
1197 // Returns false if unsuccesful
1198 bool Buffer::writeFile(string const & fname, bool flag) const
1200 // if flag is false writeFile will not create any GUI
1201 // warnings, only cerr.
1202 // Needed for autosave in background or panic save (Matthias 120496)
1204 if (read_only && (fname == filename)) {
1205 // Here we should come with a question if we should
1206 // perform the write anyway.
1208 lyxerr << _("Error! Document is read-only: ")
1211 WriteAlert(_("Error! Document is read-only: "),
1216 FileInfo finfo(fname);
1217 if (finfo.exist() && !finfo.writable()) {
1218 // Here we should come with a question if we should
1219 // try to do the save anyway. (i.e. do a chmod first)
1221 lyxerr << _("Error! Cannot write file: ")
1224 WriteFSAlert(_("Error! Cannot write file: "),
1229 ofstream ofs(fname.c_str());
1232 lyxerr << _("Error! Cannot open file: ")
1235 WriteFSAlert(_("Error! Cannot open file: "),
1239 // The top of the file should not be written by params.
1241 // write out a comment in the top of the file
1242 ofs << '#' << LYX_DOCVERSION
1243 << " created this file. For more info see http://www.lyx.org/\n";
1244 ofs.setf(ios::showpoint|ios::fixed);
1246 ofs << "\\lyxformat " << setw(4) << LYX_FORMAT << "\n";
1248 // now write out the buffer paramters.
1249 params.writeFile(ofs);
1251 char footnoteflag = 0;
1254 // this will write out all the paragraphs
1255 // using recursive descent.
1256 paragraph->writeFile(ofs, params, footnoteflag, depth);
1258 // Write marker that shows file is complete
1259 ofs << "\n\\the_end" << endl;
1261 // how to check if close went ok?
1266 void Buffer::writeFileAscii(string const & fname, int linelen)
1268 LyXFont font1, font2;
1270 char c, footnoteflag = 0, depth = 0;
1272 LyXParagraph::size_type i;
1273 int j, h, ltype = 0, ltype_depth = 0,
1274 * clen = 0, actcell = 0, actpos = 0, cell = 0, cells = 0,
1277 bool ref_printed = false;
1279 ofstream ofs(fname.c_str());
1281 WriteFSAlert(_("Error: Cannot write file:"), fname);
1285 string fname1 = TmpFileName();
1286 LyXParagraph * par = paragraph;
1290 if (par->footnoteflag != LyXParagraph::NO_FOOTNOTE ||
1292 par->previous->footnoteflag == LyXParagraph::NO_FOOTNOTE){
1294 /* begins a footnote environment ? */
1295 if (footnoteflag != par->footnoteflag) {
1296 footnoteflag = par->footnoteflag;
1298 j = strlen(string_footnotekinds[par->footnotekind])+4;
1299 if (currlinelen + j > linelen)
1302 << string_footnotekinds[par->footnotekind] << "] ";
1307 /* begins or ends a deeper area ?*/
1308 if (depth != par->depth) {
1309 if (par->depth > depth) {
1310 while (par->depth > depth) {
1315 while (par->depth < depth) {
1321 /* First write the layout */
1322 tmp = textclasslist.NameOfLayout(params.textclass, par->layout);
1323 if (tmp == "Itemize") {
1325 ltype_depth = depth+1;
1326 } else if (tmp == "Enumerate") {
1328 ltype_depth = depth+1;
1329 } else if (strstr(tmp.c_str(), "ection")) {
1331 ltype_depth = depth+1;
1332 } else if (strstr(tmp.c_str(), "aragraph")) {
1334 ltype_depth = depth+1;
1335 } else if (tmp == "Description") {
1337 ltype_depth = depth+1;
1338 } else if (tmp == "Abstract") {
1341 } else if (tmp == "Bibliography") {
1349 /* maybe some vertical spaces */
1351 /* the labelwidthstring used in lists */
1355 /* some pagebreaks? */
1359 /* what about the alignment */
1362 /* dummy layout, that means a footnote ended */
1363 footnoteflag = LyXParagraph::NO_FOOTNOTE;
1368 LyXLayout const & layout =
1369 textclasslist.Style(params.textclass,
1371 bool free_spc = layout.free_spacing;
1373 /* It might be a table */
1376 if (!lyxrc.ascii_roff_command.empty() &&
1377 lyxrc.ascii_roff_command != "none") {
1378 RoffAsciiTable(ofs, par);
1385 cells = par->table->columns;
1386 clen = new int [cells];
1387 memset(clen, 0, sizeof(int) * cells);
1389 for (i = 0, j = 0, h = 1; i < par->size(); ++i, ++h) {
1390 c = par->GetChar(i);
1391 if (c == LyXParagraph::META_INSET) {
1392 if ((inset = par->GetInset(i))) {
1395 std::ostringstream ost;
1396 inset->Latex(ost, -1, free_spc);
1397 h += ost.str().length();
1400 inset->Latex(ost, -1, free_spc);
1402 char * tmp = ost.str();
1408 ofstream fs(fname1.c_str());
1410 WriteFSAlert(_("Error: Cannot open temporary file:"), fname1);
1413 inset->Latex(fs, -1, free_spc);
1414 h += fs.tellp() - 1;
1415 ::remove(fname1.c_str());
1418 } else if (c == LyXParagraph::META_NEWLINE) {
1422 j = (++j) % par->table->NumberOfCellsInRow(actcell);
1430 font1 = LyXFont(LyXFont::ALL_INHERIT,params.language_info);
1432 for (i = 0, actpos = 1; i < par->size(); ++i, ++actpos) {
1433 if (!i && !footnoteflag && !noparbreak){
1435 for(j = 0; j < depth; ++j)
1437 currlinelen = depth * 2;
1439 case 0: /* Standard */
1440 case 4: /* (Sub)Paragraph */
1441 case 5: /* Description */
1443 case 6: /* Abstract */
1444 ofs << "Abstract\n\n";
1446 case 7: /* Bibliography */
1448 ofs << "References\n\n";
1453 ofs << par->labelstring << " ";
1456 if (ltype_depth > depth) {
1457 for(j = ltype_depth - 1; j > depth; --j)
1459 currlinelen += (ltype_depth-depth)*2;
1462 for(j = 0; j < cells; ++j) {
1464 for(h = 0; h < (clen[j] + 1);
1469 for(j = 0; j < depth; ++j)
1471 currlinelen = depth * 2;
1472 if (ltype_depth > depth) {
1473 for(j = ltype_depth;
1476 currlinelen += (ltype_depth-depth)*2;
1481 font2 = par->GetFontSettings(i);
1482 if (font1.latex() != font2.latex()) {
1483 if (font2.latex() == LyXFont::OFF)
1491 c = par->GetChar(i);
1495 case LyXParagraph::META_INSET:
1496 if ((inset = par->GetInset(i))) {
1498 inset->Latex(ofs, -1, free_spc);
1499 currlinelen += (ofs.tellp() - fpos);
1500 actpos += (ofs.tellp() - fpos) - 1;
1503 case LyXParagraph::META_NEWLINE:
1505 if (par->table->NumberOfCellsInRow(actcell) <= cell) {
1506 for(j = actpos; j < clen[cell - 1]; ++j)
1509 for(j = 0; j < depth; ++j)
1511 currlinelen = depth*2;
1512 if (ltype_depth > depth) {
1513 for(j = ltype_depth; j > depth; --j)
1515 currlinelen += (ltype_depth-depth) * 2;
1517 for(j = 0; j < cells; ++j) {
1519 for(h = 0; h < (clen[j] + 1); ++h)
1523 for(j = 0; j < depth; ++j)
1525 currlinelen = depth * 2;
1526 if (ltype_depth > depth) {
1527 for(j = ltype_depth;
1530 currlinelen += (ltype_depth-depth)*2;
1536 j < clen[cell - 1]; ++j)
1542 currlinelen = actpos = 0;
1545 for(j = 0; j < depth; ++j)
1547 currlinelen = depth * 2;
1548 if (ltype_depth > depth) {
1549 for(j = ltype_depth;
1552 currlinelen += (ltype_depth - depth) * 2;
1556 case LyXParagraph::META_HFILL:
1560 case LyXParagraph::META_PROTECTED_SEPARATOR:
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(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 != "default" ||
1743 !features.UsedLanguages.empty() ) {
1745 for (LaTeXFeatures::LanguageList::const_iterator cit =
1746 features.UsedLanguages.begin();
1747 cit != features.UsedLanguages.end(); ++cit) {
1748 options += (*cit)->lang + ",";
1750 if (default_language != params.language_info)
1751 options += default_language ->lang + ',';
1752 options += params.language_info->lang + ',';
1755 // the user-defined options
1756 if (!params.options.empty()) {
1757 options += params.options + ',';
1760 if (!options.empty()){
1761 options = strip(options, ',');
1762 ofs << '[' << options << ']';
1766 << textclasslist.LatexnameOfClass(params.textclass)
1769 // end of \documentclass defs
1771 // font selection must be done before loading fontenc.sty
1772 if (params.fonts != "default") {
1773 ofs << "\\usepackage{" << params.fonts << "}\n";
1776 // this one is not per buffer
1777 if (lyxrc.fontenc != "default") {
1778 ofs << "\\usepackage[" << lyxrc.fontenc
1782 if (params.inputenc != "default") {
1783 ofs << "\\usepackage[" << params.inputenc
1788 /* at the very beginning the text parameters */
1789 if (params.paperpackage != BufferParams::PACKAGE_NONE) {
1790 switch (params.paperpackage) {
1791 case BufferParams::PACKAGE_A4:
1792 ofs << "\\usepackage{a4}\n";
1795 case BufferParams::PACKAGE_A4WIDE:
1796 ofs << "\\usepackage{a4wide}\n";
1799 case BufferParams::PACKAGE_WIDEMARGINSA4:
1800 ofs << "\\usepackage[widemargins]{a4}\n";
1805 if (params.use_geometry) {
1806 ofs << "\\usepackage{geometry}\n";
1808 ofs << "\\geometry{verbose";
1809 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1810 ofs << ",landscape";
1811 switch (params.papersize2) {
1812 case BufferParams::VM_PAPER_CUSTOM:
1813 if (!params.paperwidth.empty())
1814 ofs << ",paperwidth="
1815 << params.paperwidth;
1816 if (!params.paperheight.empty())
1817 ofs << ",paperheight="
1818 << params.paperheight;
1820 case BufferParams::VM_PAPER_USLETTER:
1821 ofs << ",letterpaper";
1823 case BufferParams::VM_PAPER_USLEGAL:
1824 ofs << ",legalpaper";
1826 case BufferParams::VM_PAPER_USEXECUTIVE:
1827 ofs << ",executivepaper";
1829 case BufferParams::VM_PAPER_A3:
1832 case BufferParams::VM_PAPER_A4:
1835 case BufferParams::VM_PAPER_A5:
1838 case BufferParams::VM_PAPER_B3:
1841 case BufferParams::VM_PAPER_B4:
1844 case BufferParams::VM_PAPER_B5:
1848 // default papersize ie BufferParams::VM_PAPER_DEFAULT
1849 switch (lyxrc.default_papersize) {
1850 case BufferParams::PAPER_DEFAULT: // keep compiler happy
1851 case BufferParams::PAPER_USLETTER:
1852 ofs << ",letterpaper";
1854 case BufferParams::PAPER_LEGALPAPER:
1855 ofs << ",legalpaper";
1857 case BufferParams::PAPER_EXECUTIVEPAPER:
1858 ofs << ",executivepaper";
1860 case BufferParams::PAPER_A3PAPER:
1863 case BufferParams::PAPER_A4PAPER:
1866 case BufferParams::PAPER_A5PAPER:
1869 case BufferParams::PAPER_B5PAPER:
1874 if (!params.topmargin.empty())
1875 ofs << ",tmargin=" << params.topmargin;
1876 if (!params.bottommargin.empty())
1877 ofs << ",bmargin=" << params.bottommargin;
1878 if (!params.leftmargin.empty())
1879 ofs << ",lmargin=" << params.leftmargin;
1880 if (!params.rightmargin.empty())
1881 ofs << ",rmargin=" << params.rightmargin;
1882 if (!params.headheight.empty())
1883 ofs << ",headheight=" << params.headheight;
1884 if (!params.headsep.empty())
1885 ofs << ",headsep=" << params.headsep;
1886 if (!params.footskip.empty())
1887 ofs << ",footskip=" << params.footskip;
1891 if (params.use_amsmath
1892 && !prefixIs(textclasslist.LatexnameOfClass(params.textclass), "ams")) {
1893 ofs << "\\usepackage{amsmath}\n";
1897 if (tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle) >= 0) {
1898 if (params.pagestyle == "fancy") {
1899 ofs << "\\usepackage{fancyhdr}\n";
1902 ofs << "\\pagestyle{" << params.pagestyle << "}\n";
1906 // We try to load babel late, in case it interferes
1907 // with other packages.
1909 ofs << lyxrc.language_package << endl;
1913 if (params.secnumdepth != tclass.secnumdepth()) {
1914 ofs << "\\setcounter{secnumdepth}{"
1915 << params.secnumdepth
1919 if (params.tocdepth != tclass.tocdepth()) {
1920 ofs << "\\setcounter{tocdepth}{"
1926 if (params.paragraph_separation) {
1927 switch (params.defskip.kind()) {
1928 case VSpace::SMALLSKIP:
1929 ofs << "\\setlength\\parskip{\\smallskipamount}\n";
1931 case VSpace::MEDSKIP:
1932 ofs << "\\setlength\\parskip{\\medskipamount}\n";
1934 case VSpace::BIGSKIP:
1935 ofs << "\\setlength\\parskip{\\bigskipamount}\n";
1937 case VSpace::LENGTH:
1938 ofs << "\\setlength\\parskip{"
1939 << params.defskip.length().asLatexString()
1942 default: // should never happen // Then delete it.
1943 ofs << "\\setlength\\parskip{\\medskipamount}\n";
1948 ofs << "\\setlength\\parindent{0pt}\n";
1952 // Now insert the LyX specific LaTeX commands...
1953 string preamble, tmppreamble;
1955 // The optional packages;
1956 preamble = features.getPackages(params);
1958 // this might be useful...
1959 preamble += "\n\\makeatletter\n\n";
1961 // Some macros LyX will need
1962 tmppreamble = features.getMacros(params);
1964 if (!tmppreamble.empty()) {
1965 preamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1966 "LyX specific LaTeX commands.\n"
1967 + tmppreamble + '\n';
1970 // the text class specific preamble
1971 tmppreamble = features.getTClassPreamble(params);
1972 if (!tmppreamble.empty()) {
1973 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1974 "Textclass specific LaTeX commands.\n"
1975 + tmppreamble + '\n';
1978 /* the user-defined preamble */
1979 if (!params.preamble.empty()) {
1980 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1981 "User specified LaTeX commands.\n"
1982 + params.preamble + '\n';
1985 preamble += "\\makeatother\n\n";
1987 // Itemize bullet settings need to be last in case the user
1988 // defines their own bullets that use a package included
1989 // in the user-defined preamble -- ARRae
1990 // Actually it has to be done much later than that
1991 // since some packages like frenchb make modifications
1992 // at \begin{document} time -- JMarc
1994 for (int i = 0; i < 4; ++i) {
1995 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
1996 if (bullets_def.empty())
1997 bullets_def="\\AtBeginDocument{\n";
1998 bullets_def += " \\renewcommand{\\labelitemi";
2000 // `i' is one less than the item to modify
2007 bullets_def += "ii";
2013 bullets_def += "}{" +
2014 params.user_defined_bullets[i].getText()
2019 if (!bullets_def.empty())
2020 preamble += bullets_def + "}\n\n";
2022 for (int j = countChar(preamble, '\n'); j-- ;) {
2029 ofs << "\\begin{document}\n\n";
2033 lyxerr.debug() << "preamble finished, now the body." << endl;
2034 if (!lyxrc.language_auto_begin && params.language != "default") {
2035 ofs << subst(lyxrc.language_command_begin, "$$lang",
2041 bool was_title = false;
2042 bool already_title = false;
2044 std::ostringstream ftnote;
2046 char * tmpholder = 0;
2051 LyXParagraph * par = paragraph;
2055 #ifndef HAVE_SSTREAM
2058 ftnote << tmpholder;
2059 delete [] tmpholder;
2064 lyxerr[Debug::LATEX] << "Error in MakeLateXFile."
2066 LyXLayout const & layout =
2067 textclasslist.Style(params.textclass,
2070 if (layout.intitle) {
2071 if (already_title) {
2072 lyxerr <<"Error in MakeLatexFile: You"
2073 " should not mix title layouts"
2074 " with normal ones." << endl;
2077 } else if (was_title && !already_title) {
2078 ofs << "\\maketitle\n";
2080 already_title = true;
2083 // We are at depth 0 so we can just use
2084 // ordinary \footnote{} generation
2085 // flag this with ftcount
2087 if (layout.isEnvironment()
2088 || par->pextra_type != LyXParagraph::PEXTRA_NONE) {
2089 par = par->TeXEnvironment(ofs, texrow,
2090 ftnote, ft_texrow, ftcount);
2092 par = par->TeXOnePar(ofs, texrow,
2093 ftnote, ft_texrow, ftcount);
2096 // Write out what we've generated...
2099 ofs << "\\addtocounter{footnote}{-"
2103 ofs << ftnote.str();
2104 texrow += ft_texrow;
2106 // The extra .c_str() is needed when we use
2107 // lyxstring instead of the STL string class.
2108 ftnote.str(string().c_str());
2110 delete [] ftnote.str();
2115 #ifndef HAVE_SSTREAM
2117 // I hate strstreams
2118 tmpholder = ftnote.str();
2122 #ifndef HAVE_SSTREAM
2123 delete [] tmpholder;
2125 // It might be that we only have a title in this document
2126 if (was_title && !already_title) {
2127 ofs << "\\maketitle\n";
2131 if (!lyxrc.language_auto_end && params.language != "default") {
2132 ofs << subst(lyxrc.language_command_end, "$$lang",
2139 ofs << "\\end{document}\n";
2142 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
2144 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
2148 // Just to be sure. (Asger)
2151 // tex_code_break_column's value is used to decide
2152 // if we are in batchmode or not (within mathed_write()
2153 // in math_write.C) so we must set it to a non-zero
2154 // value when we leave otherwise we save incorrect .lyx files.
2155 tex_code_break_column = lyxrc.ascii_linelen;
2159 lyxerr << "File was not closed properly." << endl;
2162 lyxerr.debug() << "Finished making latex file." << endl;
2166 bool Buffer::isLatex() const
2168 return textclasslist.TextClass(params.textclass).outputType() == LATEX;
2172 bool Buffer::isLinuxDoc() const
2174 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC;
2178 bool Buffer::isLiterate() const
2180 return textclasslist.TextClass(params.textclass).outputType() == LITERATE;
2184 bool Buffer::isDocBook() const
2186 return textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2190 bool Buffer::isSGML() const
2192 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC ||
2193 textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2197 void Buffer::sgmlOpenTag(ostream & os, int depth,
2198 string const & latexname) const
2200 os << string(depth, ' ') << "<" << latexname << ">\n";
2204 void Buffer::sgmlCloseTag(ostream & os, int depth,
2205 string const & latexname) const
2207 os << string(depth, ' ') << "</" << latexname << ">\n";
2211 void Buffer::makeLinuxDocFile(string const & fname, int column)
2213 LyXParagraph * par = paragraph;
2215 string top_element = textclasslist.LatexnameOfClass(params.textclass);
2216 string environment_stack[10];
2219 int depth = 0; /* paragraph depth */
2221 ofstream ofs(fname.c_str());
2224 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2228 tex_code_break_column = column;
2231 if (params.preamble.empty()) {
2232 ofs << "<!doctype linuxdoc system>\n\n";
2235 ofs << "<!doctype linuxdoc system \n [ "
2236 << params.preamble << " \n]>\n\n";
2239 ofs << "<!-- " << LYX_DOCVERSION
2240 << " created this file. For more info see http://www.lyx.org/"
2243 if(params.options.empty())
2244 sgmlOpenTag(ofs, 0, top_element);
2246 string top = top_element;
2248 top += params.options;
2249 sgmlOpenTag(ofs, 0, top);
2253 int desc_on = 0; /* description mode*/
2254 LyXLayout const & style =
2255 textclasslist.Style(users->buffer()->params.textclass,
2257 par->AutoDeleteInsets();
2259 /* treat <toc> as a special case for compatibility with old code */
2260 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2261 Inset * inset = par->GetInset(0);
2262 char lyx_code = inset->LyxCode();
2263 if (lyx_code == Inset::TOC_CODE){
2264 string temp = "toc";
2265 sgmlOpenTag(ofs, depth, temp);
2268 linuxDocHandleFootnote(ofs, par, depth);
2273 // environment tag closing
2274 for( ; depth > par->depth; --depth) {
2275 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2276 environment_stack[depth].clear();
2279 // write opening SGML tags
2280 switch(style.latextype) {
2281 case LATEX_PARAGRAPH:
2282 if(depth == par->depth
2283 && !environment_stack[depth].empty()) {
2284 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2285 environment_stack[depth].clear();
2291 sgmlOpenTag(ofs, depth, style.latexname());
2296 LinuxDocError(par, 0, _("Error : Wrong depth for LatexType Command.\n"));
2298 if (!environment_stack[depth].empty()){
2299 sgmlCloseTag(ofs, depth,
2300 environment_stack[depth]);
2304 environment_stack[depth].clear();
2305 sgmlOpenTag(ofs, depth, style.latexname());
2308 case LATEX_ENVIRONMENT:
2309 case LATEX_ITEM_ENVIRONMENT:
2310 if(depth == par->depth
2311 && environment_stack[depth] != style.latexname()
2312 && !environment_stack[depth].empty()) {
2314 sgmlCloseTag(ofs, depth,
2315 environment_stack[depth]);
2316 environment_stack[depth].clear();
2318 if (depth < par->depth) {
2320 environment_stack[depth].clear();
2322 if (environment_stack[depth] != style.latexname()) {
2325 sgmlOpenTag(ofs, depth, temp);
2327 environment_stack[depth] = style.latexname();
2328 sgmlOpenTag(ofs, depth, environment_stack[depth]);
2330 if(style.latextype == LATEX_ENVIRONMENT) break;
2332 desc_on = (style.labeltype == LABEL_MANUAL);
2339 sgmlOpenTag(ofs, depth + 1, item_name);
2342 sgmlOpenTag(ofs, depth, style.latexname());
2347 SimpleLinuxDocOnePar(ofs, par, desc_on, depth);
2350 linuxDocHandleFootnote(ofs, par, depth);
2352 while(par && par->IsDummy());
2355 /* write closing SGML tags */
2356 switch(style.latextype) {
2358 case LATEX_ENVIRONMENT:
2359 case LATEX_ITEM_ENVIRONMENT:
2362 sgmlCloseTag(ofs, depth, style.latexname());
2367 /* Close open tags */
2368 for(; depth > 0; --depth)
2369 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2371 if(!environment_stack[depth].empty())
2372 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2375 sgmlCloseTag(ofs, 0, top_element);
2378 // How to check for successful close
2382 void Buffer::linuxDocHandleFootnote(ostream & os, LyXParagraph * & par,
2385 string tag = "footnote";
2387 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2388 sgmlOpenTag(os, depth + 1, tag);
2389 SimpleLinuxDocOnePar(os, par, 0, depth + 1);
2390 sgmlCloseTag(os, depth + 1, tag);
2396 void Buffer::DocBookHandleCaption(ostream & os, string & inner_tag,
2397 int const depth, int desc_on,
2398 LyXParagraph * & par)
2400 LyXParagraph * tpar = par;
2401 while (tpar && (tpar->footnoteflag != LyXParagraph::NO_FOOTNOTE) &&
2402 (tpar->layout != textclasslist.NumberOfLayout(params.textclass,
2406 tpar->layout == textclasslist.NumberOfLayout(params.textclass,
2407 "Caption").second) {
2408 sgmlOpenTag(os, depth + 1, inner_tag);
2410 SimpleDocBookOnePar(os, extra_par, tpar,
2411 desc_on, depth + 2);
2412 sgmlCloseTag(os, depth+1, inner_tag);
2413 if(!extra_par.empty())
2419 void Buffer::DocBookHandleFootnote(ostream & os, LyXParagraph * & par,
2422 string tag, inner_tag;
2423 string tmp_par, extra_par;
2424 bool inner_span = false;
2427 // Someone should give this enum a proper name (Lgb)
2435 SOME_ENUM last = NO_ONE;
2436 SOME_ENUM present = FOOTNOTE_LIKE;
2438 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2439 if(last == present) {
2441 if(!tmp_par.empty()) {
2444 sgmlCloseTag(os, depth + 1, inner_tag);
2445 sgmlOpenTag(os, depth + 1, inner_tag);
2452 if(!inner_tag.empty()) sgmlCloseTag(os, depth + 1,
2454 if(!extra_par.empty()) os << extra_par;
2455 if(!tag.empty()) sgmlCloseTag(os, depth, tag);
2458 switch (par->footnotekind) {
2459 case LyXParagraph::FOOTNOTE:
2460 case LyXParagraph::ALGORITHM:
2463 present = FOOTNOTE_LIKE;
2466 case LyXParagraph::MARGIN:
2469 present = MARGIN_LIKE;
2472 case LyXParagraph::FIG:
2473 case LyXParagraph::WIDE_FIG:
2475 inner_tag = "title";
2479 case LyXParagraph::TAB:
2480 case LyXParagraph::WIDE_TAB:
2482 inner_tag = "title";
2487 sgmlOpenTag(os, depth, tag);
2488 if ((present == TAB_LIKE) || (present == FIG_LIKE)) {
2489 DocBookHandleCaption(os, inner_tag, depth,
2493 sgmlOpenTag(os, depth + 1, inner_tag);
2496 // ignore all caption here, we processed them above!!!
2497 if (par->layout != textclasslist
2498 .NumberOfLayout(params.textclass,
2499 "Caption").second) {
2501 std::ostringstream ost;
2505 SimpleDocBookOnePar(ost, extra_par, par,
2506 desc_on, depth + 2);
2508 tmp_par += ost.str().c_str();
2511 char * ctmp = ost.str();
2516 tmp_par = frontStrip(strip(tmp_par));
2522 if(!inner_tag.empty()) sgmlCloseTag(os, depth + 1, inner_tag);
2523 if(!extra_par.empty()) os << extra_par;
2524 if(!tag.empty()) sgmlCloseTag(os, depth, tag);
2528 /* push a tag in a style stack */
2529 void Buffer::push_tag(ostream & os, char const * tag,
2530 int & pos, char stack[5][3])
2532 /* pop all previous tags */
2533 for (int j = pos; j >= 0; --j)
2534 os << "</" << stack[j] << ">";
2537 sprintf(stack[++pos], "%s", tag);
2540 for (int i = 0; i <= pos; ++i)
2541 os << "<" << stack[i] << ">";
2545 void Buffer::pop_tag(ostream & os, char const * tag,
2546 int & pos, char stack[5][3])
2550 // pop all tags till specified one
2551 for (j = pos; (j >= 0) && (strcmp(stack[j], tag)); --j)
2552 os << "</" << stack[j] << ">";
2555 os << "</" << tag << ">";
2557 // push all tags, but the specified one
2558 for (j = j + 1; j <= pos; ++j) {
2559 os << "<" << stack[j] << ">";
2560 strcpy(stack[j-1], stack[j]);
2566 /* handle internal paragraph parsing -- layout already processed */
2568 // checks, if newcol chars should be put into this line
2569 // writes newline, if necessary.
2571 void linux_doc_line_break(ostream & os, unsigned int & colcount,
2572 const unsigned int newcol)
2575 if (colcount > lyxrc.ascii_linelen) {
2577 colcount = newcol; // assume write after this call
2582 void Buffer::SimpleLinuxDocOnePar(ostream & os, LyXParagraph * par,
2583 int desc_on, int const /*depth*/)
2585 LyXFont font1, font2;
2588 LyXParagraph::size_type main_body;
2590 LyXLayout const & style = textclasslist.Style(params.textclass,
2593 char family_type = 0; // family font flag
2594 bool is_bold = false; // series font flag
2595 char shape_type = 0; // shape font flag
2596 bool is_em = false; // emphasis (italic) font flag
2598 int stack_num = -1; // style stack position
2599 char stack[5][3]; // style stack
2600 unsigned int char_line_count = 5; // Heuristic choice ;-)
2602 if (style.labeltype != LABEL_MANUAL)
2605 main_body = par->BeginningOfMainBody();
2607 /* gets paragraph main font */
2609 font1 = style.labelfont;
2614 /* parsing main loop */
2615 for (LyXParagraph::size_type i = 0;
2616 i < par->size(); ++i) {
2618 /* handle quote tag */
2619 if (i == main_body && !par->IsDummy()) {
2624 font2 = par->getFont(i);
2626 if (font1.family() != font2.family()) {
2627 switch(family_type) {
2629 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2630 push_tag(os, "tt", stack_num, stack);
2633 else if (font2.family() == LyXFont::SANS_FAMILY) {
2634 push_tag(os, "sf", stack_num, stack);
2639 pop_tag(os, "tt", stack_num, stack);
2640 if (font2.family() == LyXFont::SANS_FAMILY) {
2641 push_tag(os, "sf", stack_num, stack);
2649 pop_tag(os, "sf", stack_num, stack);
2650 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2651 push_tag(os, "tt", stack_num, stack);
2660 /* handle bold face */
2661 if (font1.series() != font2.series()) {
2662 if (font2.series() == LyXFont::BOLD_SERIES) {
2663 push_tag(os, "bf", stack_num, stack);
2667 pop_tag(os, "bf", stack_num, stack);
2672 /* handle italic and slanted fonts */
2673 if (font1.shape() != font2.shape()) {
2674 switch(shape_type) {
2676 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2677 push_tag(os, "it", stack_num, stack);
2680 else if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2681 push_tag(os, "sl", stack_num, stack);
2686 pop_tag(os, "it", stack_num, stack);
2687 if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2688 push_tag(os, "sl", stack_num, stack);
2696 pop_tag(os, "sl", stack_num, stack);
2697 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2698 push_tag(os, "it", stack_num, stack);
2706 /* handle <em> tag */
2707 if (font1.emph() != font2.emph()) {
2708 if (font2.emph() == LyXFont::ON) {
2709 push_tag(os, "em", stack_num, stack);
2712 pop_tag(os, "em", stack_num, stack);
2717 c = par->GetChar(i);
2719 if (font2.latex() == LyXFont::ON) {
2720 // "TeX"-Mode on == > SGML-Mode on.
2722 os << c; // see LaTeX-Generation...
2724 } else if (c == LyXParagraph::META_INSET) {
2725 inset = par->GetInset(i);
2726 inset->Linuxdoc(os);
2729 if (par->linuxDocConvertChar(c, sgml_string)
2730 && !style.free_spacing) { // in freespacing
2732 // non-breaking characters
2736 linux_doc_line_break(os, char_line_count, 6);
2741 linux_doc_line_break(os, char_line_count, 1);
2747 char_line_count += sgml_string.length();
2753 /* needed if there is an optional argument but no contents */
2754 if (main_body > 0 && main_body == par->size()) {
2758 /* pop all defined Styles */
2759 for (j = stack_num; j >= 0; --j) {
2760 linux_doc_line_break(os,
2762 3 + strlen(stack[j]));
2763 os << "</" << stack[j] << ">";
2766 /* resets description flag correctly */
2769 /* <tag> not closed... */
2770 linux_doc_line_break(os, char_line_count, 6);
2774 /* fprintf(file, "</p>");*/
2780 /* print an error message */
2781 void Buffer::LinuxDocError(LyXParagraph * par, int pos,
2782 char const * message)
2784 InsetError * new_inset;
2786 /* insert an error marker in text */
2787 new_inset = new InsetError(message);
2788 par->InsertChar(pos, LyXParagraph::META_INSET);
2789 par->InsertInset(pos, new_inset);
2792 // This constant defines the maximum number of
2793 // environment layouts that can be nesteded.
2794 // The same applies for command layouts.
2795 // These values should be more than enough.
2796 // José Matos (1999/07/22)
2798 enum { MAX_NEST_LEVEL = 25};
2800 void Buffer::makeDocBookFile(string const & fname, int column)
2802 LyXParagraph * par = paragraph;
2804 string top_element= textclasslist.LatexnameOfClass(params.textclass);
2805 string environment_stack[MAX_NEST_LEVEL];
2806 string environment_inner[MAX_NEST_LEVEL];
2807 string command_stack[MAX_NEST_LEVEL];
2808 bool command_flag= false;
2809 int command_depth= 0, command_base= 0, cmd_depth= 0;
2811 string item_name, command_name;
2812 string c_depth, c_params, tmps;
2814 int depth= 0; /* paragraph depth */
2816 tex_code_break_column = column;
2818 ofstream ofs(fname.c_str());
2820 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2826 ofs << "<!doctype " << top_element
2827 << " public \"-//OASIS//DTD DocBook V3.1//EN\"";
2829 if (params.preamble.empty())
2832 ofs << "\n [ " << params.preamble << " \n]>\n\n";
2834 ofs << "<!-- DocBook file was created by " << LYX_DOCVERSION
2835 << "\n See http://www.lyx.org/ for more information -->\n";
2837 if(params.options.empty())
2838 sgmlOpenTag(ofs, 0, top_element);
2840 string top = top_element;
2842 top += params.options;
2843 sgmlOpenTag(ofs, 0, top);
2847 int desc_on = 0; /* description mode*/
2848 LyXLayout const & style =
2849 textclasslist.Style(users->buffer()->params.textclass,
2851 par->AutoDeleteInsets();
2853 /* environment tag closing */
2854 for( ; depth > par->depth; --depth) {
2855 if(environment_inner[depth] != "!-- --") {
2856 item_name= "listitem";
2857 sgmlCloseTag(ofs, command_depth + depth,
2859 if( environment_inner[depth] == "varlistentry")
2860 sgmlCloseTag(ofs, depth+command_depth,
2861 environment_inner[depth]);
2863 sgmlCloseTag(ofs, depth + command_depth,
2864 environment_stack[depth]);
2865 environment_stack[depth].clear();
2866 environment_inner[depth].clear();
2869 if(depth == par->depth
2870 && environment_stack[depth] != style.latexname()
2871 && !environment_stack[depth].empty()) {
2872 if(environment_inner[depth] != "!-- --") {
2873 item_name= "listitem";
2874 sgmlCloseTag(ofs, command_depth+depth,
2876 if( environment_inner[depth] == "varlistentry")
2878 depth + command_depth,
2879 environment_inner[depth]);
2882 sgmlCloseTag(ofs, depth + command_depth,
2883 environment_stack[depth]);
2885 environment_stack[depth].clear();
2886 environment_inner[depth].clear();
2889 // Write opening SGML tags.
2890 switch(style.latextype) {
2891 case LATEX_PARAGRAPH:
2892 if(style.latexname() != "dummy")
2893 sgmlOpenTag(ofs, depth+command_depth,
2899 LinuxDocError(par, 0,
2900 _("Error : Wrong depth for "
2901 "LatexType Command.\n"));
2903 command_name = style.latexname();
2905 tmps = style.latexparam();
2906 c_params = split(tmps, c_depth,'|');
2908 cmd_depth= atoi(c_depth.c_str());
2911 if(cmd_depth<command_base) {
2912 for(int j = command_depth;
2913 j >= command_base; --j)
2914 if(!command_stack[j].empty())
2915 sgmlCloseTag(ofs, j, command_stack[j]);
2916 command_depth= command_base= cmd_depth;
2918 else if(cmd_depth <= command_depth) {
2919 for(int j = command_depth;
2920 j >= cmd_depth; --j)
2922 if(!command_stack[j].empty())
2923 sgmlCloseTag(ofs, j, command_stack[j]);
2924 command_depth= cmd_depth;
2927 command_depth= cmd_depth;
2930 command_depth = command_base = cmd_depth;
2931 command_flag = true;
2933 command_stack[command_depth]= command_name;
2935 // treat label as a special case for
2936 // more WYSIWYM handling.
2937 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2938 Inset * inset = par->GetInset(0);
2939 char lyx_code = inset->LyxCode();
2940 if (lyx_code == Inset::LABEL_CODE){
2941 command_name += " id=\"";
2942 command_name += (static_cast<InsetCommand *>(inset))->getContents();
2943 command_name += "\"";
2948 sgmlOpenTag(ofs, depth+command_depth, command_name);
2949 item_name = "title";
2950 sgmlOpenTag(ofs, depth + 1 + command_depth, item_name);
2953 case LATEX_ENVIRONMENT:
2954 case LATEX_ITEM_ENVIRONMENT:
2955 if (depth < par->depth) {
2957 environment_stack[depth].clear();
2960 if (environment_stack[depth] != style.latexname()) {
2961 environment_stack[depth] = style.latexname();
2962 environment_inner[depth] = "!-- --";
2963 sgmlOpenTag(ofs, depth + command_depth,
2964 environment_stack[depth]);
2966 if(environment_inner[depth] != "!-- --") {
2967 item_name= "listitem";
2969 command_depth + depth,
2971 if (environment_inner[depth] == "varlistentry")
2973 depth + command_depth,
2974 environment_inner[depth]);
2978 if(style.latextype == LATEX_ENVIRONMENT) {
2979 if(!style.latexparam().empty())
2980 sgmlOpenTag(ofs, depth + command_depth,
2981 style.latexparam());
2985 desc_on = (style.labeltype == LABEL_MANUAL);
2988 environment_inner[depth]= "varlistentry";
2990 environment_inner[depth]= "listitem";
2992 sgmlOpenTag(ofs, depth + 1 + command_depth,
2993 environment_inner[depth]);
2997 sgmlOpenTag(ofs, depth + 1 + command_depth,
3002 sgmlOpenTag(ofs, depth + 1 + command_depth,
3007 sgmlOpenTag(ofs, depth + command_depth,
3014 SimpleDocBookOnePar(ofs, extra_par, par, desc_on,
3015 depth + 1 + command_depth);
3017 DocBookHandleFootnote(ofs, par,
3018 depth + 1 + command_depth);
3020 while(par && par->IsDummy());
3023 /* write closing SGML tags */
3024 switch(style.latextype) {
3027 sgmlCloseTag(ofs, depth + command_depth, end_tag);
3029 case LATEX_ENVIRONMENT:
3030 if(!style.latexparam().empty())
3031 sgmlCloseTag(ofs, depth + command_depth,
3032 style.latexparam());
3034 case LATEX_ITEM_ENVIRONMENT:
3035 if(desc_on == 1) break;
3037 sgmlCloseTag(ofs, depth + 1 + command_depth, end_tag);
3039 case LATEX_PARAGRAPH:
3040 if(style.latexname() != "dummy")
3041 sgmlCloseTag(ofs, depth + command_depth,
3045 sgmlCloseTag(ofs, depth + command_depth,
3052 for(; depth >= 0; --depth) {
3053 if(!environment_stack[depth].empty()) {
3054 if(environment_inner[depth] != "!-- --") {
3055 item_name= "listitem";
3056 sgmlCloseTag(ofs, command_depth + depth,
3058 if( environment_inner[depth] == "varlistentry")
3059 sgmlCloseTag(ofs, depth + command_depth,
3060 environment_inner[depth]);
3063 sgmlCloseTag(ofs, depth + command_depth,
3064 environment_stack[depth]);
3068 for(int j = command_depth; j >= command_base; --j)
3069 if(!command_stack[j].empty())
3070 sgmlCloseTag(ofs, j, command_stack[j]);
3073 sgmlCloseTag(ofs, 0, top_element);
3076 // How to check for successful close
3080 void Buffer::SimpleDocBookOnePar(ostream & os, string & extra,
3081 LyXParagraph * par, int & desc_on,
3085 par->SimpleDocBookOneTablePar(os, extra, desc_on, depth);
3089 bool emph_flag = false;
3091 LyXLayout const & style = textclasslist.Style(params.textclass,
3094 LyXParagraph::size_type main_body;
3095 if (style.labeltype != LABEL_MANUAL)
3098 main_body = par->BeginningOfMainBody();
3100 // gets paragraph main font
3101 //if (main_body > 0)
3102 // font1 = style.labelfont;
3104 // font1 = style.font;
3105 LyXFont font1 = main_body > 0 ? style.labelfont : style.font;
3107 int char_line_count = depth;
3108 if(!style.free_spacing)
3109 for (int j = 0; j < depth; ++j)
3112 // parsing main loop
3113 for (LyXParagraph::size_type i = 0;
3114 i < par->size(); ++i) {
3115 LyXFont font2 = par->getFont(i);
3117 // handle <emphasis> tag
3118 if (font1.emph() != font2.emph() && i) {
3119 if (font2.emph() == LyXFont::ON) {
3123 os << "</emphasis>";
3128 char c = par->GetChar(i);
3130 if (c == LyXParagraph::META_INSET) {
3131 Inset * inset = par->GetInset(i);
3133 std::ostringstream ost;
3134 inset->DocBook(ost);
3135 string tmp_out = ost.str().c_str();
3138 inset->DocBook(ost);
3140 char * ctmp = ost.str();
3141 string tmp_out(ctmp);
3145 // This code needs some explanation:
3146 // Two insets are treated specially
3147 // label if it is the first element in a command paragraph
3149 // graphics inside tables or figure floats can't go on
3150 // title (the equivalente in latex for this case is caption
3151 // and title should come first
3154 if(desc_on!= 3 || i!= 0) {
3155 if(!tmp_out.empty() && tmp_out[0] == '@') {
3157 extra += frontStrip(tmp_out, '@');
3159 os << frontStrip(tmp_out, '@');
3164 } else if (font2.latex() == LyXFont::ON) {
3165 // "TeX"-Mode on ==> SGML-Mode on.
3172 if (par->linuxDocConvertChar(c, sgml_string)
3173 && !style.free_spacing) { // in freespacing
3175 // non-breaking characters
3179 os << "\n</term><listitem><para>";
3193 /* needed if there is an optional argument but no contents */
3194 if (main_body > 0 && main_body == par->size()) {
3198 os << "</emphasis>";
3201 /* resets description flag correctly */
3204 /* <term> not closed... */
3212 int Buffer::runLaTeX()
3214 if (!users->text) return 0;
3218 // get LaTeX-Filename
3219 string name = getLatexName();
3221 string path = OnlyPath(filename);
3223 string org_path = path;
3224 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3228 Path p(path); // path to LaTeX file
3229 users->owner()->getMiniBuffer()->Set(_("Running LaTeX..."));
3231 // Remove all error insets
3232 bool a = users->removeAutoInsets();
3234 // Always generate the LaTeX file
3235 makeLaTeXFile(name, org_path, false);
3238 // do the LaTex run(s)
3240 string latex_command = lyxrc.pdf_mode ?
3241 lyxrc.pdflatex_command : lyxrc.latex_command;
3242 LaTeX latex(latex_command, name, filepath);
3243 int res = latex.run(terr,
3244 users->owner()->getMiniBuffer()); // running latex
3246 // check return value from latex.run().
3247 if ((res & LaTeX::NO_LOGFILE)) {
3248 WriteAlert(_("LaTeX did not work!"),
3249 _("Missing log file:"), name);
3250 } else if ((res & LaTeX::ERRORS)) {
3251 users->owner()->getMiniBuffer()->Set(_("Done"));
3252 // Insert all errors as errors boxes
3253 users->insertErrors(terr);
3255 // Dvi should also be kept dirty if the latex run
3256 // ends up with errors. However it should be possible
3257 // to view a dirty dvi too.
3259 //no errors or any other things to think about so:
3260 users->owner()->getMiniBuffer()->Set(_("Done"));
3264 // if we removed error insets before we ran LaTeX or if we inserted
3265 // error insets after we ran LaTeX this must be run:
3266 if (a || (res & LaTeX::ERRORS)){
3269 users->updateScrollbar();
3273 return latex.getNumErrors();
3277 int Buffer::runLiterate()
3279 if (!users->text) return 0;
3283 // get LaTeX-Filename
3284 string name = getLatexName();
3285 // get Literate-Filename
3286 string lit_name = ChangeExtension (getLatexName(),
3287 lyxrc.literate_extension, true);
3289 string path = OnlyPath(filename);
3291 string org_path = path;
3292 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3296 Path p(path); // path to Literate file
3297 users->owner()->getMiniBuffer()->Set(_("Running Literate..."));
3299 // Remove all error insets
3300 bool a = users->removeAutoInsets();
3302 // generate the Literate file if necessary
3303 if (!isDviClean() || a) {
3304 makeLaTeXFile(lit_name, org_path, false);
3308 string latex_command = lyxrc.pdf_mode ?
3309 lyxrc.pdflatex_command : lyxrc.latex_command;
3310 Literate literate(latex_command, name, filepath,
3312 lyxrc.literate_command, lyxrc.literate_error_filter,
3313 lyxrc.build_command, lyxrc.build_error_filter);
3315 int res = literate.weave(terr, users->owner()->getMiniBuffer());
3317 // check return value from literate.weave().
3318 if ((res & Literate::NO_LOGFILE)) {
3319 WriteAlert(_("Literate command did not work!"),
3320 _("Missing log file:"), name);
3321 } else if ((res & Literate::ERRORS)) {
3322 users->owner()->getMiniBuffer()->Set(_("Done"));
3323 // Insert all errors as errors boxes
3324 users->insertErrors(terr);
3326 // Dvi should also be kept dirty if the latex run
3327 // ends up with errors. However it should be possible
3328 // to view a dirty dvi too.
3330 //no errors or any other things to think about so:
3331 users->owner()->getMiniBuffer()->Set(_("Done"));
3335 // if we removed error insets before we ran LaTeX or if we inserted
3336 // error insets after we ran LaTeX this must be run:
3337 if (a || (res & Literate::ERRORS)){
3340 users->updateScrollbar();
3344 return literate.getNumErrors();
3348 int Buffer::buildProgram()
3350 if (!users->text) return 0;
3354 // get LaTeX-Filename
3355 string name = getLatexName();
3356 // get Literate-Filename
3357 string lit_name = ChangeExtension(getLatexName(),
3358 lyxrc.literate_extension, true);
3360 string path = OnlyPath(filename);
3362 string org_path = path;
3363 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3367 Path p(path); // path to Literate file
3368 users->owner()->getMiniBuffer()->Set(_("Building Program..."));
3370 // Remove all error insets
3371 bool a = users->removeAutoInsets();
3373 // generate the LaTeX file if necessary
3374 if (!isNwClean() || a) {
3375 makeLaTeXFile(lit_name, org_path, false);
3379 string latex_command = lyxrc.pdf_mode ?
3380 lyxrc.pdflatex_command : lyxrc.latex_command;
3381 Literate literate(latex_command, name, filepath,
3383 lyxrc.literate_command, lyxrc.literate_error_filter,
3384 lyxrc.build_command, lyxrc.build_error_filter);
3386 int res = literate.build(terr, users->owner()->getMiniBuffer());
3388 // check return value from literate.build().
3389 if ((res & Literate::NO_LOGFILE)) {
3390 WriteAlert(_("Build did not work!"),
3391 _("Missing log file:"), name);
3392 } else if ((res & Literate::ERRORS)) {
3393 users->owner()->getMiniBuffer()->Set(_("Done"));
3394 // Insert all errors as errors boxes
3395 users->insertErrors(terr);
3397 // Literate files should also be kept dirty if the literate
3398 // command run ends up with errors.
3400 //no errors or any other things to think about so:
3401 users->owner()->getMiniBuffer()->Set(_("Done"));
3405 // if we removed error insets before we ran Literate/Build or if we inserted
3406 // error insets after we ran Literate/Build this must be run:
3407 if (a || (res & Literate::ERRORS)){
3410 users->updateScrollbar();
3414 return literate.getNumErrors();
3418 // This should be enabled when the Chktex class is implemented. (Asger)
3419 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
3420 // Other flags: -wall -v0 -x
3421 int Buffer::runChktex()
3423 if (!users->text) return 0;
3427 // get LaTeX-Filename
3428 string name = getLatexName();
3429 string path = OnlyPath(filename);
3431 string org_path = path;
3432 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3436 Path p(path); // path to LaTeX file
3437 users->owner()->getMiniBuffer()->Set(_("Running chktex..."));
3439 // Remove all error insets
3440 bool a = users->removeAutoInsets();
3442 // Generate the LaTeX file if neccessary
3443 if (!isDviClean() || a) {
3444 makeLaTeXFile(name, org_path, false);
3449 Chktex chktex(lyxrc.chktex_command, name, filepath);
3450 int res = chktex.run(terr); // run chktex
3453 WriteAlert(_("chktex did not work!"),
3454 _("Could not run with file:"), name);
3455 } else if (res > 0) {
3456 // Insert all errors as errors boxes
3457 users->insertErrors(terr);
3460 // if we removed error insets before we ran chktex or if we inserted
3461 // error insets after we ran chktex, this must be run:
3465 users->updateScrollbar();
3474 void Buffer::RoffAsciiTable(ostream & os, LyXParagraph * par)
3476 LyXFont font1(LyXFont::ALL_INHERIT,params.language_info);
3479 LyXParagraph::size_type i;
3483 string fname1 = TmpFileName(string(), "RAT1");
3484 string fname2 = TmpFileName(string(), "RAT2");
3486 ofstream ofs(fname1.c_str());
3488 WriteAlert(_("LYX_ERROR:"),
3489 _("Cannot open temporary file:"), fname1);
3492 par->table->RoffEndOfCell(ofs, -1);
3493 for (i = 0; i < par->size(); ++i) {
3494 c = par->GetChar(i);
3495 if (par->table->IsContRow(cell)) {
3496 if (c == LyXParagraph::META_NEWLINE)
3500 font2 = par->GetFontSettings(i);
3501 if (font1.latex() != font2.latex()) {
3502 if (font2.latex() != LyXFont::OFF)
3506 case LyXParagraph::META_INSET:
3507 if ((inset = par->GetInset(i))) {
3510 stringstresm ss(ios::in | ios::out);
3511 inset->Latex(ss, -1);
3523 inset->Latex(ss, -1);
3536 fstream fs(fname2.c_str(), ios::in|ios::out);
3538 WriteAlert(_("LYX_ERROR:"),
3539 _("Cannot open temporary file:"), fname2);
3541 remove(fname1.c_str());
3544 inset->Latex(fs, -1);
3558 case LyXParagraph::META_NEWLINE:
3559 if (par->table->CellHasContRow(cell)>= 0)
3560 par->RoffContTableRows(ofs, i+1, cell);
3561 par->table->RoffEndOfCell(ofs, cell);
3564 case LyXParagraph::META_HFILL:
3567 case LyXParagraph::META_PROTECTED_SEPARATOR:
3578 << "RoffAsciiTable:"
3579 " NULL char in structure." << endl;
3583 par->table->RoffEndOfCell(ofs, cell);
3585 string cmd = lyxrc.ascii_roff_command + " >" + fname2;
3586 cmd = subst(cmd, "$$FName", fname1);
3587 Systemcalls one(Systemcalls::System, cmd);
3588 if (!(lyxerr.debugging(Debug::ROFF))) {
3589 remove(fname1.c_str());
3591 ifstream ifs(fname2.c_str());
3593 WriteFSAlert(_("Error! Can't open temporary file:"), fname2);
3596 // now output the produced file
3600 WriteAlert(_("Error!"),
3601 _("Error executing *roff command on table"));
3602 // overread leading blank lines
3603 while(!ifs && (c == '\n'))
3606 for(j = 0; j < par->depth; ++j)
3608 while(!ifs && (c != '\n')) {
3613 // overread trailing blank lines
3614 while(!ifs && (c == '\n'))
3618 remove(fname2.c_str());
3623 /// changed Heinrich Bauer, 23/03/98
3624 bool Buffer::isDviClean() const
3626 if (lyxrc.use_tempdir)
3627 return dvi_clean_tmpd;
3629 return dvi_clean_orgd;
3633 /// changed Heinrich Bauer, 23/03/98
3634 void Buffer::markDviClean()
3636 if (lyxrc.use_tempdir)
3637 dvi_clean_tmpd = true;
3639 dvi_clean_orgd = true;
3643 /// changed Heinrich Bauer, 23/03/98
3644 void Buffer::markDviDirty()
3646 if (lyxrc.use_tempdir)
3647 dvi_clean_tmpd = false;
3649 dvi_clean_orgd = false;
3653 void Buffer::validate(LaTeXFeatures & features) const
3655 LyXParagraph * par = paragraph;
3656 LyXTextClass const & tclass =
3657 textclasslist.TextClass(params.textclass);
3659 // AMS Style is at document level
3661 features.amsstyle = (params.use_amsmath ||
3662 tclass.provides(LyXTextClass::amsmath));
3665 // We don't use "lyxerr.debug" because of speed. (Asger)
3666 if (lyxerr.debugging(Debug::LATEX))
3667 lyxerr << "Paragraph: " << par << endl;
3669 // Now just follow the list of paragraphs and run
3670 // validate on each of them.
3671 par->validate(features);
3673 // and then the next paragraph
3677 // the bullet shapes are buffer level not paragraph level
3678 // so they are tested here
3679 for (int i = 0; i < 4; ++i) {
3680 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
3681 int font = params.user_defined_bullets[i].getFont();
3684 .user_defined_bullets[i]
3691 features.latexsym = true;
3695 features.amssymb = true;
3697 else if ((font >= 2 && font <= 5)) {
3698 features.pifont = true;
3703 if (lyxerr.debugging(Debug::LATEX)) {
3704 features.showStruct(params);
3709 void Buffer::setPaperStuff()
3711 params.papersize = BufferParams::PAPER_DEFAULT;
3712 char c1 = params.paperpackage;
3713 if (c1 == BufferParams::PACKAGE_NONE) {
3714 char c2 = params.papersize2;
3715 if (c2 == BufferParams::VM_PAPER_USLETTER)
3716 params.papersize = BufferParams::PAPER_USLETTER;
3717 else if (c2 == BufferParams::VM_PAPER_USLEGAL)
3718 params.papersize = BufferParams::PAPER_LEGALPAPER;
3719 else if (c2 == BufferParams::VM_PAPER_USEXECUTIVE)
3720 params.papersize = BufferParams::PAPER_EXECUTIVEPAPER;
3721 else if (c2 == BufferParams::VM_PAPER_A3)
3722 params.papersize = BufferParams::PAPER_A3PAPER;
3723 else if (c2 == BufferParams::VM_PAPER_A4)
3724 params.papersize = BufferParams::PAPER_A4PAPER;
3725 else if (c2 == BufferParams::VM_PAPER_A5)
3726 params.papersize = BufferParams::PAPER_A5PAPER;
3727 else if ((c2 == BufferParams::VM_PAPER_B3) || (c2 == BufferParams::VM_PAPER_B4) ||
3728 (c2 == BufferParams::VM_PAPER_B5))
3729 params.papersize = BufferParams::PAPER_B5PAPER;
3730 } else if ((c1 == BufferParams::PACKAGE_A4) || (c1 == BufferParams::PACKAGE_A4WIDE) ||
3731 (c1 == BufferParams::PACKAGE_WIDEMARGINSA4))
3732 params.papersize = BufferParams::PAPER_A4PAPER;
3736 // This function should be in Buffer because it's a buffer's property (ale)
3737 string Buffer::getIncludeonlyList(char delim)
3740 LyXParagraph * par = paragraph;
3741 LyXParagraph::size_type pos;
3745 while ((inset = par->ReturnNextInsetPointer(pos))){
3746 if (inset->LyxCode() == Inset::INCLUDE_CODE) {
3747 InsetInclude * insetinc =
3748 static_cast<InsetInclude*>(inset);
3749 if (insetinc->isInclude()
3750 && insetinc->isNoLoad()) {
3753 lst += ChangeExtension(insetinc->getContents(), string(), true);
3760 lyxerr.debug() << "Includeonly(" << lst << ')' << endl;
3765 // This is also a buffer property (ale)
3766 string Buffer::getReferenceList(char delim)
3768 /// if this is a child document and the parent is already loaded
3769 /// Use the parent's list instead [ale990407]
3770 if (!params.parentname.empty()
3771 && bufferlist.exists(params.parentname)) {
3772 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3774 return tmp->getReferenceList(delim);
3777 LyXParagraph * par = paragraph;
3778 LyXParagraph::size_type pos;
3783 while ((inset = par->ReturnNextInsetPointer(pos))){
3784 for (int i = 0; i < inset->GetNumberOfLabels(); ++i) {
3787 lst += inset->getLabel(i);
3793 lyxerr.debug() << "References(" << lst << ")" << endl;
3798 // This is also a buffer property (ale)
3799 string Buffer::getBibkeyList(char delim)
3801 /// if this is a child document and the parent is already loaded
3802 /// Use the parent's list instead [ale990412]
3803 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3804 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3806 return tmp->getBibkeyList(delim);
3810 LyXParagraph * par = paragraph;
3813 if (!bibkeys.empty())
3815 bibkeys += par->bibkey->getContents();
3820 // Might be either using bibtex or a child has bibliography
3821 if (bibkeys.empty()) {
3825 LyXParagraph::size_type pos = -1;
3827 // Search for Bibtex or Include inset
3828 while ((inset = par->ReturnNextInsetPointer(pos))) {
3829 if (inset-> LyxCode() == Inset::BIBTEX_CODE) {
3830 if (!bibkeys.empty())
3832 bibkeys += static_cast<InsetBibtex*>(inset)->getKeys(delim);
3833 } else if (inset-> LyxCode() == Inset::INCLUDE_CODE) {
3834 string bk = static_cast<InsetInclude*>(inset)->getKeys(delim);
3836 if (!bibkeys.empty())
3847 lyxerr.debug() << "Bibkeys(" << bibkeys << ")" << endl;
3852 bool Buffer::isDepClean(string const & name) const
3854 DEPCLEAN * item = dep_clean;
3855 while (item && item->master != name)
3857 if (!item) return true;
3862 void Buffer::markDepClean(string const & name)
3865 dep_clean = new DEPCLEAN;
3866 dep_clean->clean = true;
3867 dep_clean->master = name;
3868 dep_clean->next = 0;
3870 DEPCLEAN* item = dep_clean;
3871 while (item && item->master != name)
3876 item = new DEPCLEAN;
3878 item->master = name;
3885 void Buffer::Dispatch(string const & command)
3887 // Split command string into command and argument
3888 string cmd, line = frontStrip(command);
3889 string arg = strip(frontStrip(split(line, cmd, ' ')));
3891 Dispatch(lyxaction.LookupFunc(cmd.c_str()), arg.c_str());
3895 void Buffer::Dispatch(int action, string const & argument)
3899 MenuExport(this, argument);
3903 lyxerr << "A truly unknown func!" << endl;