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
37 #include <sys/types.h>
41 #pragma implementation "buffer.h"
45 #include "bufferlist.h"
47 #include "lyx_gui_misc.h"
48 #include "LyXAction.h"
51 #include "tex-strings.h"
54 #include "minibuffer.h"
57 #include "mathed/formulamacro.h"
58 #include "insets/lyxinset.h"
59 #include "insets/inseterror.h"
60 #include "insets/insetlabel.h"
61 #include "insets/insetref.h"
62 #include "insets/inseturl.h"
63 #include "insets/insetinfo.h"
64 #include "insets/insetquotes.h"
65 #include "insets/insetlatexaccent.h"
66 #include "insets/insetbib.h"
67 #include "insets/insetindex.h"
68 #include "insets/insetinclude.h"
69 #include "insets/insettoc.h"
70 #include "insets/insetlof.h"
71 #include "insets/insetlot.h"
72 #include "insets/insetloa.h"
73 #include "insets/insetparent.h"
74 #include "insets/insetspecialchar.h"
75 #include "insets/figinset.h"
76 #include "insets/insettext.h"
77 #include "insets/insetert.h"
78 #include "insets/insetgraphics.h"
79 #include "insets/insetfoot.h"
80 #include "support/filetools.h"
81 #include "support/path.h"
87 #include "LaTeXFeatures.h"
88 #include "support/syscall.h"
89 #include "support/lyxlib.h"
90 #include "support/FileInfo.h"
97 // Uncomment this line to enable a workaround for the weird behaviour
98 // of the cursor between a displayed inset and last character
99 // at the upper line. (Alejandro 20.9.96)
100 // #define BREAK_BEFORE_INSET
102 /* Lars, when changing this file sometime in the future to a list,
103 * please check out the figinsets-sideeffects described at the
104 * beginning of figinset.C Matthias (04.07.1996)
108 // all these externs should eventually be removed.
109 extern BufferList bufferlist;
111 extern void MenuExport(Buffer *, string const &);
112 extern LyXAction lyxaction;
115 static const float LYX_FORMAT = 2.16;
117 extern int tex_code_break_column;
119 extern void FreeUpdateTimer();
122 Buffer::Buffer(string const & file, bool ronly)
124 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
126 filepath = OnlyPath(file);
130 dvi_clean_orgd = false; // Heinrich Bauer, 23/03/98
131 dvi_clean_tmpd = false; // Heinrich Bauer, 23/03/98
136 if (read_only || (lyxrc.use_tempdir)) {
137 tmppath = CreateBufferTmpDir();
138 } else tmppath.clear();
144 lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
145 // here the buffer should take care that it is
146 // saved properly, before it goes into the void.
148 // make sure that views using this buffer
153 if (!tmppath.empty()) {
154 DestroyBufferTmpDir(tmppath);
157 LyXParagraph * par = paragraph;
158 LyXParagraph * tmppar;
168 bool Buffer::saveParamsAsDefaults()
170 string fname = AddName(AddPath(user_lyxdir, "templates/"),
172 Buffer defaults = Buffer(fname);
174 // Use the current buffer's parameters as default
175 defaults.params = params;
177 // add an empty paragraph. Is this enough?
178 defaults.paragraph = new LyXParagraph;
180 return defaults.writeFile(defaults.filename, false);
184 /// Update window titles of all users
185 // Should work on a list
186 void Buffer::updateTitles() const
188 if (users) users->owner()->updateWindowTitle();
192 /// Reset autosave timer of all users
193 // Should work on a list
194 void Buffer::resetAutosaveTimers() const
196 if (users) users->owner()->resetAutosaveTimer();
200 void Buffer::fileName(string const & newfile)
202 filename = MakeAbsPath(newfile);
203 filepath = OnlyPath(filename);
204 setReadonly(IsFileWriteable(filename) == 0);
209 // candidate for move to BufferView
210 // (at least some parts in the beginning of the func)
213 // changed to be public and have one parameter
214 // if par = 0 normal behavior
215 // else insert behavior
216 // Returns false if "\the_end" is not read for formats >= 2.13. (Asger)
217 #define USE_PARSE_FUNCTION 1
218 bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par)
222 char depth = 0; // signed or unsigned?
223 LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
224 LyXParagraph::footnote_kind footnotekind = LyXParagraph::FOOTNOTE;
225 bool the_end_read = false;
227 LyXParagraph * return_par = 0;
228 LyXFont font(LyXFont::ALL_INHERIT,params.language_info);
229 if (format < 2.16 && params.language == "hebrew")
230 font.setLanguage(default_language);
232 // If we are inserting, we cheat and get a token in advance
233 bool has_token = false;
237 par = new LyXParagraph;
239 users->text->BreakParagraph();
240 return_par = users->text->FirstParagraph();
243 // We don't want to adopt the parameters from the
244 // document we insert, so we skip until the text begins:
247 pretoken = lex.GetString();
248 if (pretoken == "\\layout") {
260 pretoken = lex.GetString();
263 // Profiling show this should give a lot: (Asger)
264 string const token = pretoken;
268 the_end_read = parseSingleLyXformat2Token(lex, par, return_par,
277 paragraph = return_par;
283 bool Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
284 LyXParagraph *& return_par,
285 const string & token, int & pos,
286 char & depth, LyXFont & font,
287 LyXParagraph::footnote_flag & footnoteflag,
288 LyXParagraph::footnote_kind & footnotekind)
293 bool the_end_read = false;
295 if (token[0] != '\\') {
296 int n = token.length();
297 for (int i = 0; i < n; ++i) {
298 par->InsertChar(pos, token[i]);
299 par->SetFont(pos, font);
302 } else if (token == "\\i") {
303 inset = new InsetLatexAccent;
305 par->InsertChar(pos, LyXParagraph::META_INSET);
306 par->InsertInset(pos, inset);
307 par->SetFont(pos, font);
309 } else if (token == "\\layout") {
314 par = new LyXParagraph(par);
318 string layoutname = lex.GetString();
319 pair<bool, LyXTextClass::LayoutList::size_type> pp
320 = textclasslist.NumberOfLayout(params.textclass,
323 par->layout = pp.second;
324 } else { // layout not found
325 // use default layout "Standard" (0)
328 // Test whether the layout is obsolete.
329 LyXLayout const & layout =
330 textclasslist.Style(params.textclass,
332 if (!layout.obsoleted_by().empty())
334 textclasslist.NumberOfLayout(params.textclass,
335 layout.obsoleted_by()).second;
336 par->footnoteflag = footnoteflag;
337 par->footnotekind = footnotekind;
339 font = LyXFont(LyXFont::ALL_INHERIT,params.language_info);
340 if (format < 2.16 && params.language == "hebrew")
341 font.setLanguage(default_language);
342 } else if (token == "\\end_float") {
347 par = new LyXParagraph(par);
349 footnotekind = LyXParagraph::FOOTNOTE;
350 footnoteflag = LyXParagraph::NO_FOOTNOTE;
353 par->layout = LYX_DUMMY_LAYOUT;
354 font = LyXFont(LyXFont::ALL_INHERIT,params.language_info);
355 if (format < 2.16 && params.language == "hebrew")
356 font.setLanguage(default_language);
357 } else if (token == "\\begin_float") {
358 tmpret = lex.FindToken(string_footnotekinds);
359 if (tmpret == -1) ++tmpret;
360 if (tmpret != LYX_LAYOUT_DEFAULT)
361 footnotekind = static_cast<LyXParagraph::footnote_kind>(tmpret); // bad
362 if (footnotekind == LyXParagraph::FOOTNOTE
363 || footnotekind == LyXParagraph::MARGIN)
364 footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
366 footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
367 } else if (token == "\\begin_deeper") {
369 } else if (token == "\\end_deeper") {
371 lex.printError("\\end_deeper: "
372 "depth is already null");
376 } else if (token == "\\begin_preamble") {
377 params.readPreamble(lex);
378 } else if (token == "\\textclass") {
380 pair<bool, LyXTextClassList::size_type> pp =
381 textclasslist.NumberOfClass(lex.GetString());
383 params.textclass = pp.second;
385 lex.printError("Unknown textclass `$$Token'");
386 params.textclass = 0;
388 if (!textclasslist.Load(params.textclass)) {
389 // if the textclass wasn't loaded properly
390 // we need to either substitute another
391 // or stop loading the file.
392 // I can substitute but I don't see how I can
393 // stop loading... ideas?? ARRae980418
394 WriteAlert(_("Textclass Loading Error!"),
395 string(_("Can't load textclass ")) +
396 textclasslist.NameOfClass(params.textclass),
397 _("-- substituting default"));
398 params.textclass = 0;
400 } else if (token == "\\options") {
402 params.options = lex.GetString();
403 } else if (token == "\\language") {
404 params.readLanguage(lex);
405 } else if (token == "\\fontencoding") {
407 } else if (token == "\\inputencoding") {
409 params.inputenc = lex.GetString();
410 } else if (token == "\\graphics") {
411 params.readGraphicsDriver(lex);
412 } else if (token == "\\fontscheme") {
414 params.fonts = lex.GetString();
415 } else if (token == "\\noindent") {
416 par->noindent = true;
417 } else if (token == "\\fill_top") {
418 par->added_space_top = VSpace(VSpace::VFILL);
419 } else if (token == "\\fill_bottom") {
420 par->added_space_bottom = VSpace(VSpace::VFILL);
421 } else if (token == "\\line_top") {
422 par->line_top = true;
423 } else if (token == "\\line_bottom") {
424 par->line_bottom = true;
425 } else if (token == "\\pagebreak_top") {
426 par->pagebreak_top = true;
427 } else if (token == "\\pagebreak_bottom") {
428 par->pagebreak_bottom = true;
429 } else if (token == "\\start_of_appendix") {
430 par->start_of_appendix = true;
431 } else if (token == "\\paragraph_separation") {
432 tmpret = lex.FindToken(string_paragraph_separation);
433 if (tmpret == -1) ++tmpret;
434 if (tmpret != LYX_LAYOUT_DEFAULT)
435 params.paragraph_separation =
436 static_cast<BufferParams::PARSEP>(tmpret);
437 } else if (token == "\\defskip") {
439 params.defskip = VSpace(lex.GetString());
441 } else if (token == "\\no_isolatin1") { // obsolete
443 } else if (token == "\\no_babel") { // obsolete
445 } else if (token == "\\no_epsfig") { // obsolete
448 } else if (token == "\\epsfig") { // obsolete
449 // Indeed it is obsolete, but we HAVE to be backwards
450 // compatible until 0.14, because otherwise all figures
451 // in existing documents are irretrivably lost. (Asger)
452 params.readGraphicsDriver(lex);
453 } else if (token == "\\quotes_language") {
454 tmpret = lex.FindToken(string_quotes_language);
455 if (tmpret == -1) ++tmpret;
456 if (tmpret != LYX_LAYOUT_DEFAULT) {
457 InsetQuotes::quote_language tmpl =
458 InsetQuotes::EnglishQ;
461 tmpl = InsetQuotes::EnglishQ;
464 tmpl = InsetQuotes::SwedishQ;
467 tmpl = InsetQuotes::GermanQ;
470 tmpl = InsetQuotes::PolishQ;
473 tmpl = InsetQuotes::FrenchQ;
476 tmpl = InsetQuotes::DanishQ;
479 params.quotes_language = tmpl;
481 } else if (token == "\\quotes_times") {
483 switch(lex.GetInteger()) {
485 params.quotes_times = InsetQuotes::SingleQ;
488 params.quotes_times = InsetQuotes::DoubleQ;
491 } else if (token == "\\papersize") {
492 tmpret = lex.FindToken(string_papersize);
496 params.papersize2 = tmpret;
497 } else if (token == "\\paperpackage") {
498 tmpret = lex.FindToken(string_paperpackages);
501 params.paperpackage = BufferParams::PACKAGE_NONE;
503 params.paperpackage = tmpret;
504 } else if (token == "\\use_geometry") {
506 params.use_geometry = lex.GetInteger();
507 } else if (token == "\\use_amsmath") {
509 params.use_amsmath = lex.GetInteger();
510 } else if (token == "\\paperorientation") {
511 tmpret = lex.FindToken(string_orientation);
512 if (tmpret == -1) ++tmpret;
513 if (tmpret != LYX_LAYOUT_DEFAULT)
514 params.orientation = static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
515 } else if (token == "\\paperwidth") {
517 params.paperwidth = lex.GetString();
518 } else if (token == "\\paperheight") {
520 params.paperheight = lex.GetString();
521 } else if (token == "\\leftmargin") {
523 params.leftmargin = lex.GetString();
524 } else if (token == "\\topmargin") {
526 params.topmargin = lex.GetString();
527 } else if (token == "\\rightmargin") {
529 params.rightmargin = lex.GetString();
530 } else if (token == "\\bottommargin") {
532 params.bottommargin = lex.GetString();
533 } else if (token == "\\headheight") {
535 params.headheight = lex.GetString();
536 } else if (token == "\\headsep") {
538 params.headsep = lex.GetString();
539 } else if (token == "\\footskip") {
541 params.footskip = lex.GetString();
542 } else if (token == "\\paperfontsize") {
544 params.fontsize = strip(lex.GetString());
545 } else if (token == "\\papercolumns") {
547 params.columns = lex.GetInteger();
548 } else if (token == "\\papersides") {
550 switch(lex.GetInteger()) {
552 case 1: params.sides = LyXTextClass::OneSide; break;
553 case 2: params.sides = LyXTextClass::TwoSides; break;
555 } else if (token == "\\paperpagestyle") {
557 params.pagestyle = strip(lex.GetString());
558 } else if (token == "\\bullet") {
560 int index = lex.GetInteger();
562 int temp_int = lex.GetInteger();
563 params.user_defined_bullets[index].setFont(temp_int);
564 params.temp_bullets[index].setFont(temp_int);
566 temp_int = lex.GetInteger();
567 params.user_defined_bullets[index].setCharacter(temp_int);
568 params.temp_bullets[index].setCharacter(temp_int);
570 temp_int = lex.GetInteger();
571 params.user_defined_bullets[index].setSize(temp_int);
572 params.temp_bullets[index].setSize(temp_int);
574 string temp_str = lex.GetString();
575 if (temp_str != "\\end_bullet") {
576 // this element isn't really necessary for
577 // parsing but is easier for humans
578 // to understand bullets. Put it back and
579 // set a debug message?
580 lex.printError("\\end_bullet expected, got" + temp_str);
581 //how can I put it back?
583 } else if (token == "\\bulletLaTeX") {
585 int index = lex.GetInteger();
587 string temp_str = lex.GetString(), sum_str;
588 while (temp_str != "\\end_bullet") {
589 // this loop structure is needed when user
590 // enters an empty string since the first
591 // thing returned will be the \\end_bullet
593 // if the LaTeX entry has spaces. Each element
594 // therefore needs to be read in turn
597 temp_str = lex.GetString();
599 params.user_defined_bullets[index].setText(sum_str);
600 params.temp_bullets[index].setText(sum_str);
601 } else if (token == "\\secnumdepth") {
603 params.secnumdepth = lex.GetInteger();
604 } else if (token == "\\tocdepth") {
606 params.tocdepth = lex.GetInteger();
607 } else if (token == "\\baselinestretch") { // obsolete
608 lex.nextToken(); // should not be used directly
610 // Will probably keep a kind of support just for
612 params.spacing.set(Spacing::Other, lex.GetFloat());
613 } else if (token == "\\spacing") {
615 string tmp = strip(lex.GetString());
616 if (tmp == "single") {
617 params.spacing.set(Spacing::Single);
618 } else if (tmp == "onehalf") {
619 params.spacing.set(Spacing::Onehalf);
620 } else if (tmp == "double") {
621 params.spacing.set(Spacing::Double);
622 } else if (tmp == "other") {
624 params.spacing.set(Spacing::Other,
627 lex.printError("Unknown spacing token: '$$Token'");
629 } else if (token == "\\float_placement") {
631 params.float_placement = lex.GetString();
632 } else if (token == "\\cursor") { // obsolete
633 // this is obsolete, so we just skip it.
635 } else if (token == "\\family") {
637 font.setLyXFamily(lex.GetString());
638 } else if (token == "\\series") {
640 font.setLyXSeries(lex.GetString());
641 } else if (token == "\\shape") {
643 font.setLyXShape(lex.GetString());
644 } else if (token == "\\size") {
646 font.setLyXSize(lex.GetString());
647 } else if (token == "\\latex") {
649 string tok = lex.GetString();
650 // This is dirty, but gone with LyX3. (Asger)
651 if (tok == "no_latex")
652 font.setLatex(LyXFont::OFF);
653 else if (tok == "latex")
654 font.setLatex(LyXFont::ON);
655 else if (tok == "default")
656 font.setLatex(LyXFont::INHERIT);
658 lex.printError("Unknown LaTeX font flag "
660 } else if (token == "\\lang") {
662 string tok = lex.GetString();
663 Languages::iterator lit = languages.find(tok);
664 if (lit != languages.end()) {
665 font.setLanguage(&(*lit).second);
667 font.setLanguage(params.language_info);
668 lex.printError("Unknown language `$$Token'");
670 } else if (token == "\\direction") { // obsolete
672 lex.printError("Command \\direction is obsolete");
674 string tok = lex.GetString();
676 font.setLanguage(&languages["hebrew"]);
677 else if (tok == "default")
678 if (params.language == "hebrew")
679 font.setLanguage(default_language);
681 font.setLanguage(params.language_info);
683 lex.printError("Unknown direction `$$Token'");
684 } else if (token == "\\emph") {
686 font.setEmph(font.setLyXMisc(lex.GetString()));
687 } else if (token == "\\bar") {
689 string tok = lex.GetString();
690 // This is dirty, but gone with LyX3. (Asger)
692 font.setUnderbar(LyXFont::ON);
693 else if (tok == "no")
694 font.setUnderbar(LyXFont::OFF);
695 else if (tok == "default")
696 font.setUnderbar(LyXFont::INHERIT);
698 lex.printError("Unknown bar font flag "
700 } else if (token == "\\noun") {
702 font.setNoun(font.setLyXMisc(lex.GetString()));
703 } else if (token == "\\color") {
705 font.setLyXColor(lex.GetString());
706 } else if (token == "\\align") {
707 tmpret = lex.FindToken(string_align);
708 if (tmpret == -1) ++tmpret;
709 if (tmpret != LYX_LAYOUT_DEFAULT) { // tmpret != 99 ???
711 for (; tmpret > 0; --tmpret)
712 tmpret2 = tmpret2 * 2;
713 par->align = LyXAlignment(tmpret2);
715 } else if (token == "\\added_space_top") {
717 par->added_space_top = lex.GetString();
718 } else if (token == "\\added_space_bottom") {
720 par->added_space_bottom = lex.GetString();
721 } else if (token == "\\pextra_type") {
723 par->pextra_type = lex.GetInteger();
724 } else if (token == "\\pextra_width") {
726 par->pextra_width = lex.GetString();
727 } else if (token == "\\pextra_widthp") {
729 par->pextra_widthp = lex.GetString();
730 } else if (token == "\\pextra_alignment") {
732 par->pextra_alignment = lex.GetInteger();
733 } else if (token == "\\pextra_hfill") {
735 par->pextra_hfill = lex.GetInteger();
736 } else if (token == "\\pextra_start_minipage") {
738 par->pextra_start_minipage = lex.GetInteger();
739 } else if (token == "\\labelwidthstring") {
741 par->labelwidthstring = lex.GetString();
742 /* do not delete this token, it is still needed! */
743 } else if (token == "\\end_inset") {
744 /* simple ignore this. The insets do not have
746 // but insets should read it, it is a part of
747 //the inset isn't it? Lgb.
748 } else if (token == "\\begin_inset") {
750 tmptok = lex.GetString();
751 /* test the different insets */
752 if (tmptok == "Quotes") {
753 inset = new InsetQuotes;
755 par->InsertChar(pos, LyXParagraph::META_INSET);
756 par->InsertInset(pos, inset);
757 par->SetFont(pos, font);
759 } else if (tmptok == "\\i") {
760 inset = new InsetLatexAccent;
762 par->InsertChar(pos, LyXParagraph::META_INSET);
763 par->InsertInset(pos, inset);
764 par->SetFont(pos, font);
766 } else if (tmptok == "FormulaMacro") {
767 inset = new InsetFormulaMacro;
769 par->InsertChar(pos, LyXParagraph::META_INSET);
770 par->InsertInset(pos, inset);
771 par->SetFont(pos, font);
773 } else if (tmptok == "Formula") {
774 inset = new InsetFormula;
776 par->InsertChar(pos, LyXParagraph::META_INSET);
777 par->InsertInset(pos, inset);
778 par->SetFont(pos, font);
780 } else if (tmptok == "Figure") {
781 inset = new InsetFig(100, 100, this);
783 par->InsertChar(pos, LyXParagraph::META_INSET);
784 par->InsertInset(pos, inset);
785 par->SetFont(pos, font);
787 } else if (tmptok == "Info") {
788 inset = new InsetInfo;
790 par->InsertChar(pos, LyXParagraph::META_INSET);
791 par->InsertInset(pos, inset);
792 par->SetFont(pos, font);
794 } else if (tmptok == "Include") {
795 inset = new InsetInclude(string(), this);
797 par->InsertChar(pos, LyXParagraph::META_INSET);
798 par->InsertInset(pos, inset);
799 par->SetFont(pos, font);
801 } else if (tmptok == "ERT") {
802 inset = new InsetERT(this);
804 par->InsertChar(pos, LyXParagraph::META_INSET);
805 par->InsertInset(pos, inset);
806 par->SetFont(pos, font);
808 } else if (tmptok == "Text") {
809 inset = new InsetText(this);
811 par->InsertChar(pos, LyXParagraph::META_INSET);
812 par->InsertInset(pos, inset);
813 par->SetFont(pos, font);
815 } else if (tmptok == "Foot") {
816 inset = new InsetFoot(this);
818 par->InsertChar(pos, LyXParagraph::META_INSET);
819 par->InsertInset(pos, inset);
820 par->SetFont(pos, font);
822 } else if (tmptok == "GRAPHICS") {
823 inset = new InsetGraphics;
825 par->InsertChar(pos, LyXParagraph::META_INSET);
826 par->InsertInset(pos, inset);
827 par->SetFont(pos, font);
828 } else if (tmptok == "LatexCommand") {
831 if (inscmd.getCmdName() == "cite") {
832 inset = new InsetCitation(inscmd.getContents(), inscmd.getOptions());
833 } else if (inscmd.getCmdName() == "bibitem") {
834 lex.printError("Wrong place for bibitem");
835 inset = inscmd.Clone();
836 } else if (inscmd.getCmdName() == "BibTeX") {
837 inset = new InsetBibtex(inscmd.getContents(), inscmd.getOptions(), this);
838 } else if (inscmd.getCmdName() == "index") {
839 inset = new InsetIndex(inscmd.getContents());
840 } else if (inscmd.getCmdName() == "include") {
841 inset = new InsetInclude(inscmd.getContents(), this);
842 } else if (inscmd.getCmdName() == "label") {
843 inset = new InsetLabel(inscmd.getCommand());
844 } else if (inscmd.getCmdName() == "url"
845 || inscmd.getCmdName() == "htmlurl") {
846 inset = new InsetUrl(inscmd.getCommand());
847 } else if (inscmd.getCmdName() == "ref"
848 || inscmd.getCmdName() == "pageref") {
849 if (!inscmd.getOptions().empty() || !inscmd.getContents().empty()) {
850 inset = new InsetRef(inscmd, this);
852 #warning Verify that this else clause is still needed. (Lgb)
854 // This condition comes from a
855 // temporary solution to the latexdel
856 // ref inset that was transformed to
857 // an empty ref inset plus the body
858 // surronded by latexdel insets
860 string cont, opt, tmptmptok, cmdname;
862 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
867 tmptmptok = lex.GetString();
868 if(tmptmptok[0] == '\\') {
869 if( tmptmptok == "\\backslash")
879 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
884 tmptmptok = lex.GetString();
885 if(tmptmptok[0] == '\\') {
886 if( tmptmptok == "\\backslash")
896 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
902 cmdname = "\\" + inscmd.getCmdName();
903 cmdname += "[" + cont + "]";
904 cmdname += "{" + opt + "}";
905 inset = new InsetRef(cmdname, this);
908 } else if (inscmd.getCmdName() == "tableofcontents") {
909 inset = new InsetTOC(this);
910 } else if (inscmd.getCmdName() == "listoffigures") {
911 inset = new InsetLOF(this);
912 } else if (inscmd.getCmdName() == "listofalgorithms") {
913 inset = new InsetLOA(this);
914 } else if (inscmd.getCmdName() == "listoftables") {
915 inset = new InsetLOT(this);
916 } else if (inscmd.getCmdName() == "printindex") {
917 inset = new InsetPrintIndex(this);
918 } else if (inscmd.getCmdName() == "lyxparent") {
919 inset = new InsetParent(inscmd.getContents(), this);
923 par->InsertChar(pos, LyXParagraph::META_INSET);
924 par->InsertInset(pos, inset);
925 par->SetFont(pos, font);
929 } else if (token == "\\InsetQuotes") {
930 inset = new InsetQuotes;
932 par->InsertChar(pos, LyXParagraph::META_INSET);
933 par->InsertInset(pos, inset);
934 par->SetFont(pos, font);
936 } else if (token == "\\InsetFormula") {
937 inset = new InsetFormula;
939 par->InsertChar(pos, LyXParagraph::META_INSET);
940 par->InsertInset(pos, inset);
941 par->SetFont(pos, font);
943 } else if (token == "\\SpecialChar") {
944 LyXLayout const & layout =
945 textclasslist.Style(params.textclass,
948 // Insets don't make sense in a free-spacing context! ---Kayvan
949 if (layout.free_spacing)
954 next_token = lex.GetString();
955 if (next_token == "\\-") {
956 par->InsertChar(pos, '-');
957 par->SetFont(pos, font);
958 } else if (next_token == "\\protected_separator") {
959 par->InsertChar(pos, ' ');
960 par->SetFont(pos, font);
962 lex.printError("Token `$$Token' "
964 "paragraph layout!");
971 inset = new InsetSpecialChar;
973 par->InsertChar(pos, LyXParagraph::META_INSET);
974 par->InsertInset(pos, inset);
975 par->SetFont(pos, font);
978 } else if (token == "\\Figure") {
979 inset = new InsetFig(100, 100, this);
981 par->InsertChar(pos, LyXParagraph::META_INSET);
982 par->InsertInset(pos, inset);
983 par->SetFont(pos, font);
985 } else if (token == "\\newline") { // soon obsolete
987 par->InsertChar(pos, LyXParagraph::META_NEWLINE);
988 par->SetFont(pos, font);
990 inset = new InsetSpecialChar(InsetSpecialChar::NEWLINE);
991 par->InsertChar(pos, LyXParagraph::META_INSET);
992 par->InsertInset(pos, inset);
993 par->SetFont(pos, font);
996 } else if (token == "\\LyXTable") {
997 par->table = new LyXTable(lex);
998 } else if (token == "\\hfill") {
999 par->InsertChar(pos, LyXParagraph::META_HFILL);
1000 par->SetFont(pos, font);
1002 } else if (token == "\\protected_separator") { // obsolete
1004 LyXLayout const & layout =
1005 textclasslist.Style(params.textclass,
1008 if (layout.free_spacing) {
1009 par->InsertChar(pos, ' ');
1010 par->SetFont(pos, font);
1012 inset = new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
1013 par->InsertChar(pos, LyXParagraph::META_INSET);
1014 par->InsertInset(pos, inset);
1015 par->SetFont(pos, font);
1018 par->InsertChar(pos, LyXParagraph::META_PROTECTED_SEPARATOR);
1019 par->SetFont(pos, font);
1022 } else if (token == "\\bibitem") { // ale970302
1024 par->bibkey = new InsetBibKey;
1025 par->bibkey->Read(lex);
1026 }else if (token == "\\backslash") {
1027 par->InsertChar(pos, '\\');
1028 par->SetFont(pos, font);
1030 }else if (token == "\\the_end") {
1031 the_end_read = true;
1033 // This should be insurance for the future: (Asger)
1034 lex.printError("Unknown token `$$Token'. "
1035 "Inserting as text.");
1036 int n = token.length();
1037 for (int i = 0; i < n; ++i) {
1038 par->InsertChar(pos, token[i]);
1039 par->SetFont(pos, font);
1043 return the_end_read;
1046 bool Buffer::readFile(LyXLex & lex, LyXParagraph * par)
1052 token = lex.GetString();
1053 if (token == "\\lyxformat") { // the first token _must_ be...
1055 format = lex.GetFloat();
1057 if (LYX_FORMAT - format > 0.05) {
1058 printf(_("Warning: need lyxformat %.2f but found %.2f\n"),
1059 LYX_FORMAT, format);
1061 if (format - LYX_FORMAT > 0.05) {
1062 printf(_("ERROR: need lyxformat %.2f but found %.2f\n"),
1063 LYX_FORMAT, format);
1065 bool the_end = readLyXformat2(lex, par);
1066 // Formats >= 2.13 support "\the_end" marker
1073 WriteAlert(_("Warning!"),
1074 _("Reading of document is not complete"),
1075 _("Maybe the document is truncated"));
1076 // We simulate a safe reading anyways to allow
1077 // users to take the chance... (Asger)
1081 WriteAlert(_("ERROR!"),
1082 _("Old LyX file format found. "
1083 "Use LyX 0.10.x to read this!"));
1087 } else { // "\\lyxformat" not found
1088 WriteAlert(_("ERROR!"), _("Not a LyX file!"));
1091 WriteAlert(_("ERROR!"), _("Unable to read file!"));
1097 // Should probably be moved to somewhere else: BufferView? LyXView?
1098 bool Buffer::save() const
1100 // We don't need autosaves in the immediate future. (Asger)
1101 resetAutosaveTimers();
1105 if (lyxrc.make_backup) {
1106 s = fileName() + '~';
1107 if (!lyxrc.backupdir_path.empty())
1108 s = AddName(lyxrc.backupdir_path,
1109 subst(CleanupPath(s),'/','!'));
1111 // Rename is the wrong way of making a backup,
1112 // this is the correct way.
1113 /* truss cp fil fil2:
1114 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
1115 stat("LyXVC.lyx", 0xEFFFF688) = 0
1116 open("LyXVC.lyx", O_RDONLY) = 3
1117 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
1118 fstat(4, 0xEFFFF508) = 0
1119 fstat(3, 0xEFFFF508) = 0
1120 read(3, " # T h i s f i l e w".., 8192) = 5579
1121 write(4, " # T h i s f i l e w".., 5579) = 5579
1122 read(3, 0xEFFFD4A0, 8192) = 0
1125 chmod("LyXVC3.lyx", 0100644) = 0
1126 lseek(0, 0, SEEK_CUR) = 46440
1130 // Should proabaly have some more error checking here.
1131 // Should be cleaned up in 0.13, at least a bit.
1132 // Doing it this way, also makes the inodes stay the same.
1133 // This is still not a very good solution, in particular we
1134 // might loose the owner of the backup.
1135 FileInfo finfo(fileName());
1136 if (finfo.exist()) {
1137 mode_t fmode = finfo.getMode();
1138 struct utimbuf times = {
1139 finfo.getAccessTime(),
1140 finfo.getModificationTime() };
1142 ifstream ifs(fileName().c_str());
1143 ofstream ofs(s.c_str(), ios::out|ios::trunc);
1148 ::chmod(s.c_str(), fmode);
1150 if (::utime(s.c_str(), ×)) {
1151 lyxerr << "utime error." << endl;
1154 lyxerr << "LyX was not able to make "
1155 "backupcopy. Beware." << endl;
1160 if (writeFile(fileName(), false)) {
1163 // now delete the autosavefile
1164 string a = OnlyPath(fileName());
1166 a += OnlyFilename(fileName());
1168 FileInfo fileinfo(a);
1169 if (fileinfo.exist()) {
1170 if (::remove(a.c_str()) != 0) {
1171 WriteFSAlert(_("Could not delete "
1172 "auto-save file!"), a);
1176 // Saving failed, so backup is not backup
1177 if (lyxrc.make_backup) {
1178 ::rename(s.c_str(), fileName().c_str());
1186 // Returns false if unsuccesful
1187 bool Buffer::writeFile(string const & fname, bool flag) const
1189 // if flag is false writeFile will not create any GUI
1190 // warnings, only cerr.
1191 // Needed for autosave in background or panic save (Matthias 120496)
1193 if (read_only && (fname == filename)) {
1194 // Here we should come with a question if we should
1195 // perform the write anyway.
1197 lyxerr << _("Error! Document is read-only: ")
1200 WriteAlert(_("Error! Document is read-only: "),
1205 FileInfo finfo(fname);
1206 if (finfo.exist() && !finfo.writable()) {
1207 // Here we should come with a question if we should
1208 // try to do the save anyway. (i.e. do a chmod first)
1210 lyxerr << _("Error! Cannot write file: ")
1213 WriteFSAlert(_("Error! Cannot write file: "),
1218 ofstream ofs(fname.c_str());
1221 lyxerr << _("Error! Cannot open file: ")
1224 WriteFSAlert(_("Error! Cannot open file: "),
1228 // The top of the file should not be written by params.
1230 // write out a comment in the top of the file
1231 ofs << '#' << LYX_DOCVERSION
1232 << " created this file. For more info see http://www.lyx.org/\n";
1233 ofs.setf(ios::showpoint|ios::fixed);
1235 ofs << "\\lyxformat " << setw(4) << LYX_FORMAT << "\n";
1237 // now write out the buffer paramters.
1238 params.writeFile(ofs);
1240 char footnoteflag = 0;
1243 // this will write out all the paragraphs
1244 // using recursive descent.
1245 paragraph->writeFile(ofs, params, footnoteflag, depth);
1247 // Write marker that shows file is complete
1248 ofs << "\n\\the_end" << endl;
1250 // how to check if close went ok?
1255 void Buffer::writeFileAscii(string const & fname, int linelen)
1257 LyXFont font1, font2;
1259 char c, footnoteflag = 0, depth = 0;
1261 LyXParagraph::size_type i;
1262 int j, h, ltype = 0, ltype_depth = 0,
1263 * clen = 0, actcell = 0, actpos = 0, cell = 0, cells = 0,
1266 bool ref_printed = false;
1268 ofstream ofs(fname.c_str());
1270 WriteFSAlert(_("Error: Cannot write file:"), fname);
1274 string fname1 = TmpFileName();
1275 LyXParagraph * par = paragraph;
1279 if (par->footnoteflag != LyXParagraph::NO_FOOTNOTE ||
1281 par->previous->footnoteflag == LyXParagraph::NO_FOOTNOTE){
1283 /* begins a footnote environment ? */
1284 if (footnoteflag != par->footnoteflag) {
1285 footnoteflag = par->footnoteflag;
1287 j = strlen(string_footnotekinds[par->footnotekind])+4;
1288 if (currlinelen + j > linelen)
1291 << string_footnotekinds[par->footnotekind] << "] ";
1296 /* begins or ends a deeper area ?*/
1297 if (depth != par->depth) {
1298 if (par->depth > depth) {
1299 while (par->depth > depth) {
1304 while (par->depth < depth) {
1310 /* First write the layout */
1311 tmp = textclasslist.NameOfLayout(params.textclass, par->layout);
1312 if (tmp == "Itemize") {
1314 ltype_depth = depth+1;
1315 } else if (tmp == "Enumerate") {
1317 ltype_depth = depth+1;
1318 } else if (strstr(tmp.c_str(), "ection")) {
1320 ltype_depth = depth+1;
1321 } else if (strstr(tmp.c_str(), "aragraph")) {
1323 ltype_depth = depth+1;
1324 } else if (tmp == "Description") {
1326 ltype_depth = depth+1;
1327 } else if (tmp == "Abstract") {
1330 } else if (tmp == "Bibliography") {
1338 /* maybe some vertical spaces */
1340 /* the labelwidthstring used in lists */
1344 /* some pagebreaks? */
1348 /* what about the alignment */
1351 /* dummy layout, that means a footnote ended */
1352 footnoteflag = LyXParagraph::NO_FOOTNOTE;
1357 LyXLayout const & layout =
1358 textclasslist.Style(params.textclass,
1360 bool free_spc = layout.free_spacing;
1362 /* It might be a table */
1365 if (!lyxrc.ascii_roff_command.empty() &&
1366 lyxrc.ascii_roff_command != "none") {
1367 RoffAsciiTable(ofs, par);
1374 cells = par->table->columns;
1375 clen = new int [cells];
1376 memset(clen, 0, sizeof(int) * cells);
1378 for (i = 0, j = 0, h = 1; i < par->size(); ++i, ++h) {
1379 c = par->GetChar(i);
1380 if (c == LyXParagraph::META_INSET) {
1381 if ((inset = par->GetInset(i))) {
1385 inset->Latex(ost, -1, free_spc);
1386 h += ost.str().length();
1389 inset->Latex(ost, -1, free_spc);
1391 char * tmp = ost.str();
1397 ofstream fs(fname1.c_str());
1399 WriteFSAlert(_("Error: Cannot open temporary file:"), fname1);
1402 inset->Latex(fs, -1, free_spc);
1403 h += fs.tellp() - 1;
1404 ::remove(fname1.c_str());
1407 } else if (c == LyXParagraph::META_NEWLINE) {
1411 j = (++j) % par->table->NumberOfCellsInRow(actcell);
1419 font1 = LyXFont(LyXFont::ALL_INHERIT,params.language_info);
1421 for (i = 0, actpos = 1; i < par->size(); ++i, ++actpos) {
1422 if (!i && !footnoteflag && !noparbreak){
1424 for(j = 0; j < depth; ++j)
1426 currlinelen = depth * 2;
1428 case 0: /* Standard */
1429 case 4: /* (Sub)Paragraph */
1430 case 5: /* Description */
1432 case 6: /* Abstract */
1433 ofs << "Abstract\n\n";
1435 case 7: /* Bibliography */
1437 ofs << "References\n\n";
1442 ofs << par->labelstring << " ";
1445 if (ltype_depth > depth) {
1446 for(j = ltype_depth - 1; j > depth; --j)
1448 currlinelen += (ltype_depth-depth)*2;
1451 for(j = 0; j < cells; ++j) {
1453 for(h = 0; h < (clen[j] + 1);
1458 for(j = 0; j < depth; ++j)
1460 currlinelen = depth * 2;
1461 if (ltype_depth > depth) {
1462 for(j = ltype_depth;
1465 currlinelen += (ltype_depth-depth)*2;
1470 font2 = par->GetFontSettings(i);
1471 if (font1.latex() != font2.latex()) {
1472 if (font2.latex() == LyXFont::OFF)
1480 c = par->GetChar(i);
1484 case LyXParagraph::META_INSET:
1485 if ((inset = par->GetInset(i))) {
1487 inset->Latex(ofs, -1, free_spc);
1488 currlinelen += (ofs.tellp() - fpos);
1489 actpos += (ofs.tellp() - fpos) - 1;
1492 case LyXParagraph::META_NEWLINE:
1494 if (par->table->NumberOfCellsInRow(actcell) <= cell) {
1495 for(j = actpos; j < clen[cell - 1]; ++j)
1498 for(j = 0; j < depth; ++j)
1500 currlinelen = depth*2;
1501 if (ltype_depth > depth) {
1502 for(j = ltype_depth; j > depth; --j)
1504 currlinelen += (ltype_depth-depth) * 2;
1506 for(j = 0; j < cells; ++j) {
1508 for(h = 0; h < (clen[j] + 1); ++h)
1512 for(j = 0; j < depth; ++j)
1514 currlinelen = depth * 2;
1515 if (ltype_depth > depth) {
1516 for(j = ltype_depth;
1519 currlinelen += (ltype_depth-depth)*2;
1525 j < clen[cell - 1]; ++j)
1531 currlinelen = actpos = 0;
1534 for(j = 0; j < depth; ++j)
1536 currlinelen = depth * 2;
1537 if (ltype_depth > depth) {
1538 for(j = ltype_depth;
1541 currlinelen += (ltype_depth - depth) * 2;
1545 case LyXParagraph::META_HFILL:
1549 case LyXParagraph::META_PROTECTED_SEPARATOR:
1557 if (currlinelen > linelen - 10
1558 && c == ' ' && i + 2 < par->size()) {
1560 for(j = 0; j < depth; ++j)
1562 currlinelen = depth * 2;
1563 if (ltype_depth > depth) {
1564 for(j = ltype_depth;
1567 currlinelen += (ltype_depth-depth)*2;
1569 } else if (c != '\0')
1572 lyxerr.debug() << "writeAsciiFile: NULL char in structure." << endl;
1578 for(j = actpos; j < clen[cell - 1]; ++j)
1581 for(j = 0; j < depth; ++j)
1583 currlinelen = depth * 2;
1584 if (ltype_depth > depth) {
1585 for(j = ltype_depth; j > depth; --j)
1587 currlinelen += (ltype_depth - depth) * 2;
1589 for(j = 0; j < cells; ++j) {
1591 for(h = 0; h < (clen[j] + 1); ++h)
1604 void Buffer::makeLaTeXFile(string const & fname,
1605 string const & original_path,
1606 bool nice, bool only_body)
1608 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
1610 niceFile = nice; // this will be used by Insetincludes.
1612 tex_code_break_column = lyxrc.ascii_linelen;
1614 LyXTextClass const & tclass =
1615 textclasslist.TextClass(params.textclass);
1617 ofstream ofs(fname.c_str());
1619 WriteFSAlert(_("Error: Cannot open file: "), fname);
1623 // validate the buffer.
1624 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
1625 LaTeXFeatures features(tclass.numLayouts());
1627 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
1630 // The starting paragraph of the coming rows is the
1631 // first paragraph of the document. (Asger)
1632 texrow.start(paragraph, 0);
1634 if (!only_body && nice) {
1635 ofs << "%% " LYX_DOCVERSION " created this file. "
1636 "For more info, see http://www.lyx.org/.\n"
1637 "%% Do not edit unless you really know what "
1642 lyxerr.debug() << "lyx header finished" << endl;
1643 // There are a few differences between nice LaTeX and usual files:
1644 // usual is \batchmode and has a
1645 // special input@path to allow the including of figures
1646 // with either \input or \includegraphics (what figinsets do).
1647 // batchmode is not set if there is a tex_code_break_column.
1648 // In this case somebody is interested in the generated LaTeX,
1649 // so this is OK. input@path is set when the actual parameter
1650 // original_path is set. This is done for usual tex-file, but not
1651 // for nice-latex-file. (Matthias 250696)
1654 // code for usual, NOT nice-latex-file
1655 ofs << "\\batchmode\n"; // changed
1656 // from \nonstopmode
1659 if (!original_path.empty()) {
1660 ofs << "\\makeatletter\n"
1661 << "\\def\\input@path{{"
1662 << original_path << "/}}\n"
1663 << "\\makeatother\n";
1669 ofs << "\\documentclass";
1671 string options; // the document class options.
1673 if (tokenPos(tclass.opt_fontsize(), '|', params.fontsize) >= 0) {
1674 // only write if existing in list (and not default)
1675 options += params.fontsize;
1680 if (!params.use_geometry &&
1681 (params.paperpackage == BufferParams::PACKAGE_NONE)) {
1682 switch (params.papersize) {
1683 case BufferParams::PAPER_A4PAPER:
1684 options += "a4paper,";
1686 case BufferParams::PAPER_USLETTER:
1687 options += "letterpaper,";
1689 case BufferParams::PAPER_A5PAPER:
1690 options += "a5paper,";
1692 case BufferParams::PAPER_B5PAPER:
1693 options += "b5paper,";
1695 case BufferParams::PAPER_EXECUTIVEPAPER:
1696 options += "executivepaper,";
1698 case BufferParams::PAPER_LEGALPAPER:
1699 options += "legalpaper,";
1705 if (params.sides != tclass.sides()) {
1706 switch (params.sides) {
1707 case LyXTextClass::OneSide:
1708 options += "oneside,";
1710 case LyXTextClass::TwoSides:
1711 options += "twoside,";
1718 if (params.columns != tclass.columns()) {
1719 if (params.columns == 2)
1720 options += "twocolumn,";
1722 options += "onecolumn,";
1725 if (!params.use_geometry
1726 && params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1727 options += "landscape,";
1729 // language should be a parameter to \documentclass
1730 bool use_babel = false;
1731 if (params.language != "default" ||
1732 !features.UsedLanguages.empty() ) {
1734 for (LaTeXFeatures::LanguageList::const_iterator cit =
1735 features.UsedLanguages.begin();
1736 cit != features.UsedLanguages.end(); ++cit) {
1737 options += (*cit)->lang + ",";
1739 if (default_language != params.language_info)
1740 options += default_language ->lang + ',';
1741 options += params.language_info->lang + ',';
1744 // the user-defined options
1745 if (!params.options.empty()) {
1746 options += params.options + ',';
1749 if (!options.empty()){
1750 options = strip(options, ',');
1751 ofs << '[' << options << ']';
1755 << textclasslist.LatexnameOfClass(params.textclass)
1758 // end of \documentclass defs
1760 // font selection must be done before loading fontenc.sty
1761 if (params.fonts != "default") {
1762 ofs << "\\usepackage{" << params.fonts << "}\n";
1765 // this one is not per buffer
1766 if (lyxrc.fontenc != "default") {
1767 ofs << "\\usepackage[" << lyxrc.fontenc
1771 if (params.inputenc != "default") {
1772 ofs << "\\usepackage[" << params.inputenc
1777 /* at the very beginning the text parameters */
1778 if (params.paperpackage != BufferParams::PACKAGE_NONE) {
1779 switch (params.paperpackage) {
1780 case BufferParams::PACKAGE_A4:
1781 ofs << "\\usepackage{a4}\n";
1784 case BufferParams::PACKAGE_A4WIDE:
1785 ofs << "\\usepackage{a4wide}\n";
1788 case BufferParams::PACKAGE_WIDEMARGINSA4:
1789 ofs << "\\usepackage[widemargins]{a4}\n";
1794 if (params.use_geometry) {
1795 ofs << "\\usepackage{geometry}\n";
1797 ofs << "\\geometry{verbose";
1798 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1799 ofs << ",landscape";
1800 switch (params.papersize2) {
1801 case BufferParams::VM_PAPER_CUSTOM:
1802 if (!params.paperwidth.empty())
1803 ofs << ",paperwidth="
1804 << params.paperwidth;
1805 if (!params.paperheight.empty())
1806 ofs << ",paperheight="
1807 << params.paperheight;
1809 case BufferParams::VM_PAPER_USLETTER:
1810 ofs << ",letterpaper";
1812 case BufferParams::VM_PAPER_USLEGAL:
1813 ofs << ",legalpaper";
1815 case BufferParams::VM_PAPER_USEXECUTIVE:
1816 ofs << ",executivepaper";
1818 case BufferParams::VM_PAPER_A3:
1821 case BufferParams::VM_PAPER_A4:
1824 case BufferParams::VM_PAPER_A5:
1827 case BufferParams::VM_PAPER_B3:
1830 case BufferParams::VM_PAPER_B4:
1833 case BufferParams::VM_PAPER_B5:
1837 // default papersize ie BufferParams::VM_PAPER_DEFAULT
1838 switch (lyxrc.default_papersize) {
1839 case BufferParams::PAPER_DEFAULT: // keep compiler happy
1840 case BufferParams::PAPER_USLETTER:
1841 ofs << ",letterpaper";
1843 case BufferParams::PAPER_LEGALPAPER:
1844 ofs << ",legalpaper";
1846 case BufferParams::PAPER_EXECUTIVEPAPER:
1847 ofs << ",executivepaper";
1849 case BufferParams::PAPER_A3PAPER:
1852 case BufferParams::PAPER_A4PAPER:
1855 case BufferParams::PAPER_A5PAPER:
1858 case BufferParams::PAPER_B5PAPER:
1863 if (!params.topmargin.empty())
1864 ofs << ",tmargin=" << params.topmargin;
1865 if (!params.bottommargin.empty())
1866 ofs << ",bmargin=" << params.bottommargin;
1867 if (!params.leftmargin.empty())
1868 ofs << ",lmargin=" << params.leftmargin;
1869 if (!params.rightmargin.empty())
1870 ofs << ",rmargin=" << params.rightmargin;
1871 if (!params.headheight.empty())
1872 ofs << ",headheight=" << params.headheight;
1873 if (!params.headsep.empty())
1874 ofs << ",headsep=" << params.headsep;
1875 if (!params.footskip.empty())
1876 ofs << ",footskip=" << params.footskip;
1880 if (params.use_amsmath
1881 && !prefixIs(textclasslist.LatexnameOfClass(params.textclass), "ams")) {
1882 ofs << "\\usepackage{amsmath}\n";
1886 if (tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle) >= 0) {
1887 if (params.pagestyle == "fancy") {
1888 ofs << "\\usepackage{fancyhdr}\n";
1891 ofs << "\\pagestyle{" << params.pagestyle << "}\n";
1895 // We try to load babel late, in case it interferes
1896 // with other packages.
1898 ofs << lyxrc.language_package << endl;
1902 if (params.secnumdepth != tclass.secnumdepth()) {
1903 ofs << "\\setcounter{secnumdepth}{"
1904 << params.secnumdepth
1908 if (params.tocdepth != tclass.tocdepth()) {
1909 ofs << "\\setcounter{tocdepth}{"
1915 if (params.paragraph_separation) {
1916 switch (params.defskip.kind()) {
1917 case VSpace::SMALLSKIP:
1918 ofs << "\\setlength\\parskip{\\smallskipamount}\n";
1920 case VSpace::MEDSKIP:
1921 ofs << "\\setlength\\parskip{\\medskipamount}\n";
1923 case VSpace::BIGSKIP:
1924 ofs << "\\setlength\\parskip{\\bigskipamount}\n";
1926 case VSpace::LENGTH:
1927 ofs << "\\setlength\\parskip{"
1928 << params.defskip.length().asLatexString()
1931 default: // should never happen // Then delete it.
1932 ofs << "\\setlength\\parskip{\\medskipamount}\n";
1937 ofs << "\\setlength\\parindent{0pt}\n";
1941 // Now insert the LyX specific LaTeX commands...
1942 string preamble, tmppreamble;
1944 // The optional packages;
1945 preamble = features.getPackages(params);
1947 // this might be useful...
1948 preamble += "\n\\makeatletter\n\n";
1950 // Some macros LyX will need
1951 tmppreamble = features.getMacros(params);
1953 if (!tmppreamble.empty()) {
1954 preamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1955 "LyX specific LaTeX commands.\n"
1956 + tmppreamble + '\n';
1959 // the text class specific preamble
1960 tmppreamble = features.getTClassPreamble(params);
1961 if (!tmppreamble.empty()) {
1962 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1963 "Textclass specific LaTeX commands.\n"
1964 + tmppreamble + '\n';
1967 /* the user-defined preamble */
1968 if (!params.preamble.empty()) {
1969 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1970 "User specified LaTeX commands.\n"
1971 + params.preamble + '\n';
1974 preamble += "\\makeatother\n\n";
1976 // Itemize bullet settings need to be last in case the user
1977 // defines their own bullets that use a package included
1978 // in the user-defined preamble -- ARRae
1979 // Actually it has to be done much later than that
1980 // since some packages like frenchb make modifications
1981 // at \begin{document} time -- JMarc
1983 for (int i = 0; i < 4; ++i) {
1984 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
1985 if (bullets_def.empty())
1986 bullets_def="\\AtBeginDocument{\n";
1987 bullets_def += " \\renewcommand{\\labelitemi";
1989 // `i' is one less than the item to modify
1996 bullets_def += "ii";
2002 bullets_def += "}{" +
2003 params.user_defined_bullets[i].getText()
2008 if (!bullets_def.empty())
2009 preamble += bullets_def + "}\n\n";
2011 for (int j = countChar(preamble, '\n'); j-- ;) {
2018 ofs << "\\begin{document}\n\n";
2022 lyxerr.debug() << "preamble finished, now the body." << endl;
2023 if (!lyxrc.language_auto_begin && params.language != "default") {
2024 ofs << subst(lyxrc.language_command_begin, "$$lang",
2030 bool was_title = false;
2031 bool already_title = false;
2033 ostringstream ftnote;
2035 char * tmpholder = 0;
2040 LyXParagraph * par = paragraph;
2044 #ifndef HAVE_SSTREAM
2047 ftnote << tmpholder;
2048 delete [] tmpholder;
2053 lyxerr[Debug::LATEX] << "Error in MakeLateXFile."
2055 LyXLayout const & layout =
2056 textclasslist.Style(params.textclass,
2059 if (layout.intitle) {
2060 if (already_title) {
2061 lyxerr <<"Error in MakeLatexFile: You"
2062 " should not mix title layouts"
2063 " with normal ones." << endl;
2066 } else if (was_title && !already_title) {
2067 ofs << "\\maketitle\n";
2069 already_title = true;
2072 // We are at depth 0 so we can just use
2073 // ordinary \footnote{} generation
2074 // flag this with ftcount
2076 if (layout.isEnvironment()
2077 || par->pextra_type != LyXParagraph::PEXTRA_NONE) {
2078 par = par->TeXEnvironment(ofs, texrow,
2079 ftnote, ft_texrow, ftcount);
2081 par = par->TeXOnePar(ofs, texrow,
2082 ftnote, ft_texrow, ftcount);
2085 // Write out what we've generated...
2088 ofs << "\\addtocounter{footnote}{-"
2092 ofs << ftnote.str();
2093 texrow += ft_texrow;
2095 // The extra .c_str() is needed when we use
2096 // lyxstring instead of the STL string class.
2097 ftnote.str(string().c_str());
2099 delete [] ftnote.str();
2104 #ifndef HAVE_SSTREAM
2106 // I hate strstreams
2107 tmpholder = ftnote.str();
2111 #ifndef HAVE_SSTREAM
2112 delete [] tmpholder;
2114 // It might be that we only have a title in this document
2115 if (was_title && !already_title) {
2116 ofs << "\\maketitle\n";
2120 if (!lyxrc.language_auto_end && params.language != "default") {
2121 ofs << subst(lyxrc.language_command_end, "$$lang",
2128 ofs << "\\end{document}\n";
2131 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
2133 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
2137 // Just to be sure. (Asger)
2140 // tex_code_break_column's value is used to decide
2141 // if we are in batchmode or not (within mathed_write()
2142 // in math_write.C) so we must set it to a non-zero
2143 // value when we leave otherwise we save incorrect .lyx files.
2144 tex_code_break_column = lyxrc.ascii_linelen;
2148 lyxerr << "File was not closed properly." << endl;
2151 lyxerr.debug() << "Finished making latex file." << endl;
2155 bool Buffer::isLatex() const
2157 return textclasslist.TextClass(params.textclass).outputType() == LATEX;
2161 bool Buffer::isLinuxDoc() const
2163 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC;
2167 bool Buffer::isLiterate() const
2169 return textclasslist.TextClass(params.textclass).outputType() == LITERATE;
2173 bool Buffer::isDocBook() const
2175 return textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2179 bool Buffer::isSGML() const
2181 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC ||
2182 textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2186 void Buffer::sgmlOpenTag(ostream & os, int depth,
2187 string const & latexname) const
2189 os << string(depth, ' ') << "<" << latexname << ">\n";
2193 void Buffer::sgmlCloseTag(ostream & os, int depth,
2194 string const & latexname) const
2196 os << string(depth, ' ') << "</" << latexname << ">\n";
2200 void Buffer::makeLinuxDocFile(string const & fname, int column)
2202 LyXParagraph * par = paragraph;
2204 string top_element = textclasslist.LatexnameOfClass(params.textclass);
2205 string environment_stack[10];
2208 int depth = 0; /* paragraph depth */
2210 ofstream ofs(fname.c_str());
2213 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2217 tex_code_break_column = column;
2220 if (params.preamble.empty()) {
2221 ofs << "<!doctype linuxdoc system>\n\n";
2224 ofs << "<!doctype linuxdoc system \n [ "
2225 << params.preamble << " \n]>\n\n";
2228 ofs << "<!-- " << LYX_DOCVERSION
2229 << " created this file. For more info see http://www.lyx.org/"
2232 if(params.options.empty())
2233 sgmlOpenTag(ofs, 0, top_element);
2235 string top = top_element;
2237 top += params.options;
2238 sgmlOpenTag(ofs, 0, top);
2242 int desc_on = 0; /* description mode*/
2243 LyXLayout const & style =
2244 textclasslist.Style(users->buffer()->params.textclass,
2246 par->AutoDeleteInsets();
2248 /* treat <toc> as a special case for compatibility with old code */
2249 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2250 Inset * inset = par->GetInset(0);
2251 char lyx_code = inset->LyxCode();
2252 if (lyx_code == Inset::TOC_CODE){
2253 string temp = "toc";
2254 sgmlOpenTag(ofs, depth, temp);
2257 linuxDocHandleFootnote(ofs, par, depth);
2262 // environment tag closing
2263 for( ; depth > par->depth; --depth) {
2264 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2265 environment_stack[depth].clear();
2268 // write opening SGML tags
2269 switch(style.latextype) {
2270 case LATEX_PARAGRAPH:
2271 if(depth == par->depth
2272 && !environment_stack[depth].empty()) {
2273 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2274 environment_stack[depth].clear();
2280 sgmlOpenTag(ofs, depth, style.latexname());
2285 LinuxDocError(par, 0, _("Error : Wrong depth for LatexType Command.\n"));
2287 if (!environment_stack[depth].empty()){
2288 sgmlCloseTag(ofs, depth,
2289 environment_stack[depth]);
2293 environment_stack[depth].clear();
2294 sgmlOpenTag(ofs, depth, style.latexname());
2297 case LATEX_ENVIRONMENT:
2298 case LATEX_ITEM_ENVIRONMENT:
2299 if(depth == par->depth
2300 && environment_stack[depth] != style.latexname()
2301 && !environment_stack[depth].empty()) {
2303 sgmlCloseTag(ofs, depth,
2304 environment_stack[depth]);
2305 environment_stack[depth].clear();
2307 if (depth < par->depth) {
2309 environment_stack[depth].clear();
2311 if (environment_stack[depth] != style.latexname()) {
2314 sgmlOpenTag(ofs, depth, temp);
2316 environment_stack[depth] = style.latexname();
2317 sgmlOpenTag(ofs, depth, environment_stack[depth]);
2319 if(style.latextype == LATEX_ENVIRONMENT) break;
2321 desc_on = (style.labeltype == LABEL_MANUAL);
2328 sgmlOpenTag(ofs, depth + 1, item_name);
2331 sgmlOpenTag(ofs, depth, style.latexname());
2336 SimpleLinuxDocOnePar(ofs, par, desc_on, depth);
2339 linuxDocHandleFootnote(ofs, par, depth);
2341 while(par && par->IsDummy());
2344 /* write closing SGML tags */
2345 switch(style.latextype) {
2347 case LATEX_ENVIRONMENT:
2348 case LATEX_ITEM_ENVIRONMENT:
2351 sgmlCloseTag(ofs, depth, style.latexname());
2356 /* Close open tags */
2357 for(; depth > 0; --depth)
2358 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2360 if(!environment_stack[depth].empty())
2361 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2364 sgmlCloseTag(ofs, 0, top_element);
2367 // How to check for successful close
2371 void Buffer::linuxDocHandleFootnote(ostream & os, LyXParagraph * & par,
2374 string tag = "footnote";
2376 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2377 sgmlOpenTag(os, depth + 1, tag);
2378 SimpleLinuxDocOnePar(os, par, 0, depth + 1);
2379 sgmlCloseTag(os, depth + 1, tag);
2385 void Buffer::DocBookHandleCaption(ostream & os, string & inner_tag,
2386 int const depth, int desc_on,
2387 LyXParagraph * & par)
2389 LyXParagraph * tpar = par;
2390 while (tpar && (tpar->footnoteflag != LyXParagraph::NO_FOOTNOTE) &&
2391 (tpar->layout != textclasslist.NumberOfLayout(params.textclass,
2395 tpar->layout == textclasslist.NumberOfLayout(params.textclass,
2396 "Caption").second) {
2397 sgmlOpenTag(os, depth + 1, inner_tag);
2399 SimpleDocBookOnePar(os, extra_par, tpar,
2400 desc_on, depth + 2);
2401 sgmlCloseTag(os, depth+1, inner_tag);
2402 if(!extra_par.empty())
2408 void Buffer::DocBookHandleFootnote(ostream & os, LyXParagraph * & par,
2411 string tag, inner_tag;
2412 string tmp_par, extra_par;
2413 bool inner_span = false;
2416 // Someone should give this enum a proper name (Lgb)
2424 SOME_ENUM last = NO_ONE;
2425 SOME_ENUM present = FOOTNOTE_LIKE;
2427 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2428 if(last == present) {
2430 if(!tmp_par.empty()) {
2433 sgmlCloseTag(os, depth + 1, inner_tag);
2434 sgmlOpenTag(os, depth + 1, inner_tag);
2441 if(!inner_tag.empty()) sgmlCloseTag(os, depth + 1,
2443 if(!extra_par.empty()) os << extra_par;
2444 if(!tag.empty()) sgmlCloseTag(os, depth, tag);
2447 switch (par->footnotekind) {
2448 case LyXParagraph::FOOTNOTE:
2449 case LyXParagraph::ALGORITHM:
2452 present = FOOTNOTE_LIKE;
2455 case LyXParagraph::MARGIN:
2458 present = MARGIN_LIKE;
2461 case LyXParagraph::FIG:
2462 case LyXParagraph::WIDE_FIG:
2464 inner_tag = "title";
2468 case LyXParagraph::TAB:
2469 case LyXParagraph::WIDE_TAB:
2471 inner_tag = "title";
2476 sgmlOpenTag(os, depth, tag);
2477 if ((present == TAB_LIKE) || (present == FIG_LIKE)) {
2478 DocBookHandleCaption(os, inner_tag, depth,
2482 sgmlOpenTag(os, depth + 1, inner_tag);
2485 // ignore all caption here, we processed them above!!!
2486 if (par->layout != textclasslist
2487 .NumberOfLayout(params.textclass,
2488 "Caption").second) {
2494 SimpleDocBookOnePar(ost, extra_par, par,
2495 desc_on, depth + 2);
2497 tmp_par += ost.str().c_str();
2500 char * ctmp = ost.str();
2505 tmp_par = frontStrip(strip(tmp_par));
2511 if(!inner_tag.empty()) sgmlCloseTag(os, depth + 1, inner_tag);
2512 if(!extra_par.empty()) os << extra_par;
2513 if(!tag.empty()) sgmlCloseTag(os, depth, tag);
2517 /* push a tag in a style stack */
2518 void Buffer::push_tag(ostream & os, char const * tag,
2519 int & pos, char stack[5][3])
2521 /* pop all previous tags */
2522 for (int j = pos; j >= 0; --j)
2523 os << "</" << stack[j] << ">";
2526 sprintf(stack[++pos], "%s", tag);
2529 for (int i = 0; i <= pos; ++i)
2530 os << "<" << stack[i] << ">";
2534 void Buffer::pop_tag(ostream & os, char const * tag,
2535 int & pos, char stack[5][3])
2539 // pop all tags till specified one
2540 for (j = pos; (j >= 0) && (strcmp(stack[j], tag)); --j)
2541 os << "</" << stack[j] << ">";
2544 os << "</" << tag << ">";
2546 // push all tags, but the specified one
2547 for (j = j + 1; j <= pos; ++j) {
2548 os << "<" << stack[j] << ">";
2549 strcpy(stack[j-1], stack[j]);
2555 /* handle internal paragraph parsing -- layout already processed */
2557 // checks, if newcol chars should be put into this line
2558 // writes newline, if necessary.
2560 void linux_doc_line_break(ostream & os, unsigned int & colcount,
2561 const unsigned int newcol)
2564 if (colcount > lyxrc.ascii_linelen) {
2566 colcount = newcol; // assume write after this call
2571 void Buffer::SimpleLinuxDocOnePar(ostream & os, LyXParagraph * par,
2572 int desc_on, int const /*depth*/)
2574 LyXFont font1, font2;
2577 LyXParagraph::size_type main_body;
2579 LyXLayout const & style = textclasslist.Style(params.textclass,
2582 char family_type = 0; // family font flag
2583 bool is_bold = false; // series font flag
2584 char shape_type = 0; // shape font flag
2585 bool is_em = false; // emphasis (italic) font flag
2587 int stack_num = -1; // style stack position
2588 char stack[5][3]; // style stack
2589 unsigned int char_line_count = 5; // Heuristic choice ;-)
2591 if (style.labeltype != LABEL_MANUAL)
2594 main_body = par->BeginningOfMainBody();
2596 /* gets paragraph main font */
2598 font1 = style.labelfont;
2603 /* parsing main loop */
2604 for (LyXParagraph::size_type i = 0;
2605 i < par->size(); ++i) {
2607 /* handle quote tag */
2608 if (i == main_body && !par->IsDummy()) {
2613 font2 = par->getFont(i);
2615 if (font1.family() != font2.family()) {
2616 switch(family_type) {
2618 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2619 push_tag(os, "tt", stack_num, stack);
2622 else if (font2.family() == LyXFont::SANS_FAMILY) {
2623 push_tag(os, "sf", stack_num, stack);
2628 pop_tag(os, "tt", stack_num, stack);
2629 if (font2.family() == LyXFont::SANS_FAMILY) {
2630 push_tag(os, "sf", stack_num, stack);
2638 pop_tag(os, "sf", stack_num, stack);
2639 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2640 push_tag(os, "tt", stack_num, stack);
2649 /* handle bold face */
2650 if (font1.series() != font2.series()) {
2651 if (font2.series() == LyXFont::BOLD_SERIES) {
2652 push_tag(os, "bf", stack_num, stack);
2656 pop_tag(os, "bf", stack_num, stack);
2661 /* handle italic and slanted fonts */
2662 if (font1.shape() != font2.shape()) {
2663 switch(shape_type) {
2665 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2666 push_tag(os, "it", stack_num, stack);
2669 else if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2670 push_tag(os, "sl", stack_num, stack);
2675 pop_tag(os, "it", stack_num, stack);
2676 if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2677 push_tag(os, "sl", stack_num, stack);
2685 pop_tag(os, "sl", stack_num, stack);
2686 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2687 push_tag(os, "it", stack_num, stack);
2695 /* handle <em> tag */
2696 if (font1.emph() != font2.emph()) {
2697 if (font2.emph() == LyXFont::ON) {
2698 push_tag(os, "em", stack_num, stack);
2701 pop_tag(os, "em", stack_num, stack);
2706 c = par->GetChar(i);
2708 if (font2.latex() == LyXFont::ON) {
2709 // "TeX"-Mode on == > SGML-Mode on.
2711 os << c; // see LaTeX-Generation...
2713 } else if (c == LyXParagraph::META_INSET) {
2714 inset = par->GetInset(i);
2715 inset->Linuxdoc(os);
2718 if (par->linuxDocConvertChar(c, sgml_string)
2719 && !style.free_spacing) { // in freespacing
2721 // non-breaking characters
2725 linux_doc_line_break(os, char_line_count, 6);
2730 linux_doc_line_break(os, char_line_count, 1);
2736 char_line_count += sgml_string.length();
2742 /* needed if there is an optional argument but no contents */
2743 if (main_body > 0 && main_body == par->size()) {
2747 /* pop all defined Styles */
2748 for (j = stack_num; j >= 0; --j) {
2749 linux_doc_line_break(os,
2751 3 + strlen(stack[j]));
2752 os << "</" << stack[j] << ">";
2755 /* resets description flag correctly */
2758 /* <tag> not closed... */
2759 linux_doc_line_break(os, char_line_count, 6);
2763 /* fprintf(file, "</p>");*/
2769 /* print an error message */
2770 void Buffer::LinuxDocError(LyXParagraph * par, int pos,
2771 char const * message)
2773 InsetError * new_inset;
2775 /* insert an error marker in text */
2776 new_inset = new InsetError(message);
2777 par->InsertChar(pos, LyXParagraph::META_INSET);
2778 par->InsertInset(pos, new_inset);
2781 // This constant defines the maximum number of
2782 // environment layouts that can be nesteded.
2783 // The same applies for command layouts.
2784 // These values should be more than enough.
2785 // José Matos (1999/07/22)
2787 enum { MAX_NEST_LEVEL = 25};
2789 void Buffer::makeDocBookFile(string const & fname, int column)
2791 LyXParagraph * par = paragraph;
2793 string top_element= textclasslist.LatexnameOfClass(params.textclass);
2794 string environment_stack[MAX_NEST_LEVEL];
2795 string environment_inner[MAX_NEST_LEVEL];
2796 string command_stack[MAX_NEST_LEVEL];
2797 bool command_flag= false;
2798 int command_depth= 0, command_base= 0, cmd_depth= 0;
2800 string item_name, command_name;
2801 string c_depth, c_params, tmps;
2803 int depth= 0; /* paragraph depth */
2805 tex_code_break_column = column;
2807 ofstream ofs(fname.c_str());
2809 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2815 ofs << "<!doctype " << top_element
2816 << " public \"-//OASIS//DTD DocBook V3.1//EN\"";
2818 if (params.preamble.empty())
2821 ofs << "\n [ " << params.preamble << " \n]>\n\n";
2823 ofs << "<!-- DocBook file was created by " << LYX_DOCVERSION
2824 << "\n See http://www.lyx.org/ for more information -->\n";
2826 if(params.options.empty())
2827 sgmlOpenTag(ofs, 0, top_element);
2829 string top = top_element;
2831 top += params.options;
2832 sgmlOpenTag(ofs, 0, top);
2836 int desc_on = 0; /* description mode*/
2837 LyXLayout const & style =
2838 textclasslist.Style(users->buffer()->params.textclass,
2840 par->AutoDeleteInsets();
2842 /* environment tag closing */
2843 for( ; depth > par->depth; --depth) {
2844 if(environment_inner[depth] != "!-- --") {
2845 item_name= "listitem";
2846 sgmlCloseTag(ofs, command_depth + depth,
2848 if( environment_inner[depth] == "varlistentry")
2849 sgmlCloseTag(ofs, depth+command_depth,
2850 environment_inner[depth]);
2852 sgmlCloseTag(ofs, depth + command_depth,
2853 environment_stack[depth]);
2854 environment_stack[depth].clear();
2855 environment_inner[depth].clear();
2858 if(depth == par->depth
2859 && environment_stack[depth] != style.latexname()
2860 && !environment_stack[depth].empty()) {
2861 if(environment_inner[depth] != "!-- --") {
2862 item_name= "listitem";
2863 sgmlCloseTag(ofs, command_depth+depth,
2865 if( environment_inner[depth] == "varlistentry")
2867 depth + command_depth,
2868 environment_inner[depth]);
2871 sgmlCloseTag(ofs, depth + command_depth,
2872 environment_stack[depth]);
2874 environment_stack[depth].clear();
2875 environment_inner[depth].clear();
2878 // Write opening SGML tags.
2879 switch(style.latextype) {
2880 case LATEX_PARAGRAPH:
2881 if(style.latexname() != "dummy")
2882 sgmlOpenTag(ofs, depth+command_depth,
2888 LinuxDocError(par, 0,
2889 _("Error : Wrong depth for "
2890 "LatexType Command.\n"));
2892 command_name = style.latexname();
2894 tmps = style.latexparam();
2895 c_params = split(tmps, c_depth,'|');
2897 cmd_depth= atoi(c_depth.c_str());
2900 if(cmd_depth<command_base) {
2901 for(int j = command_depth;
2902 j >= command_base; --j)
2903 if(!command_stack[j].empty())
2904 sgmlCloseTag(ofs, j, command_stack[j]);
2905 command_depth= command_base= cmd_depth;
2907 else if(cmd_depth <= command_depth) {
2908 for(int j = command_depth;
2909 j >= cmd_depth; --j)
2911 if(!command_stack[j].empty())
2912 sgmlCloseTag(ofs, j, command_stack[j]);
2913 command_depth= cmd_depth;
2916 command_depth= cmd_depth;
2919 command_depth = command_base = cmd_depth;
2920 command_flag = true;
2922 command_stack[command_depth]= command_name;
2924 // treat label as a special case for
2925 // more WYSIWYM handling.
2926 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2927 Inset * inset = par->GetInset(0);
2928 char lyx_code = inset->LyxCode();
2929 if (lyx_code == Inset::LABEL_CODE){
2930 command_name += " id=\"";
2931 command_name += (static_cast<InsetCommand *>(inset))->getContents();
2932 command_name += "\"";
2937 sgmlOpenTag(ofs, depth+command_depth, command_name);
2938 item_name = "title";
2939 sgmlOpenTag(ofs, depth + 1 + command_depth, item_name);
2942 case LATEX_ENVIRONMENT:
2943 case LATEX_ITEM_ENVIRONMENT:
2944 if (depth < par->depth) {
2946 environment_stack[depth].clear();
2949 if (environment_stack[depth] != style.latexname()) {
2950 environment_stack[depth] = style.latexname();
2951 environment_inner[depth] = "!-- --";
2952 sgmlOpenTag(ofs, depth + command_depth,
2953 environment_stack[depth]);
2955 if(environment_inner[depth] != "!-- --") {
2956 item_name= "listitem";
2958 command_depth + depth,
2960 if (environment_inner[depth] == "varlistentry")
2962 depth + command_depth,
2963 environment_inner[depth]);
2967 if(style.latextype == LATEX_ENVIRONMENT) {
2968 if(!style.latexparam().empty())
2969 sgmlOpenTag(ofs, depth + command_depth,
2970 style.latexparam());
2974 desc_on = (style.labeltype == LABEL_MANUAL);
2977 environment_inner[depth]= "varlistentry";
2979 environment_inner[depth]= "listitem";
2981 sgmlOpenTag(ofs, depth + 1 + command_depth,
2982 environment_inner[depth]);
2986 sgmlOpenTag(ofs, depth + 1 + command_depth,
2991 sgmlOpenTag(ofs, depth + 1 + command_depth,
2996 sgmlOpenTag(ofs, depth + command_depth,
3003 SimpleDocBookOnePar(ofs, extra_par, par, desc_on,
3004 depth + 1 + command_depth);
3006 DocBookHandleFootnote(ofs, par,
3007 depth + 1 + command_depth);
3009 while(par && par->IsDummy());
3012 /* write closing SGML tags */
3013 switch(style.latextype) {
3016 sgmlCloseTag(ofs, depth + command_depth, end_tag);
3018 case LATEX_ENVIRONMENT:
3019 if(!style.latexparam().empty())
3020 sgmlCloseTag(ofs, depth + command_depth,
3021 style.latexparam());
3023 case LATEX_ITEM_ENVIRONMENT:
3024 if(desc_on == 1) break;
3026 sgmlCloseTag(ofs, depth + 1 + command_depth, end_tag);
3028 case LATEX_PARAGRAPH:
3029 if(style.latexname() != "dummy")
3030 sgmlCloseTag(ofs, depth + command_depth,
3034 sgmlCloseTag(ofs, depth + command_depth,
3041 for(; depth >= 0; --depth) {
3042 if(!environment_stack[depth].empty()) {
3043 if(environment_inner[depth] != "!-- --") {
3044 item_name= "listitem";
3045 sgmlCloseTag(ofs, command_depth + depth,
3047 if( environment_inner[depth] == "varlistentry")
3048 sgmlCloseTag(ofs, depth + command_depth,
3049 environment_inner[depth]);
3052 sgmlCloseTag(ofs, depth + command_depth,
3053 environment_stack[depth]);
3057 for(int j = command_depth; j >= command_base; --j)
3058 if(!command_stack[j].empty())
3059 sgmlCloseTag(ofs, j, command_stack[j]);
3062 sgmlCloseTag(ofs, 0, top_element);
3065 // How to check for successful close
3069 void Buffer::SimpleDocBookOnePar(ostream & os, string & extra,
3070 LyXParagraph * par, int & desc_on,
3074 par->SimpleDocBookOneTablePar(os, extra, desc_on, depth);
3078 bool emph_flag = false;
3080 LyXLayout const & style = textclasslist.Style(params.textclass,
3083 LyXParagraph::size_type main_body;
3084 if (style.labeltype != LABEL_MANUAL)
3087 main_body = par->BeginningOfMainBody();
3089 // gets paragraph main font
3090 //if (main_body > 0)
3091 // font1 = style.labelfont;
3093 // font1 = style.font;
3094 LyXFont font1 = main_body > 0 ? style.labelfont : style.font;
3096 int char_line_count = depth;
3097 if(!style.free_spacing)
3098 for (int j = 0; j < depth; ++j)
3101 // parsing main loop
3102 for (LyXParagraph::size_type i = 0;
3103 i < par->size(); ++i) {
3104 LyXFont font2 = par->getFont(i);
3106 // handle <emphasis> tag
3107 if (font1.emph() != font2.emph() && i) {
3108 if (font2.emph() == LyXFont::ON) {
3112 os << "</emphasis>";
3117 char c = par->GetChar(i);
3119 if (c == LyXParagraph::META_INSET) {
3120 Inset * inset = par->GetInset(i);
3123 inset->DocBook(ost);
3124 string tmp_out = ost.str().c_str();
3127 inset->DocBook(ost);
3129 char * ctmp = ost.str();
3130 string tmp_out(ctmp);
3134 // This code needs some explanation:
3135 // Two insets are treated specially
3136 // label if it is the first element in a command paragraph
3138 // graphics inside tables or figure floats can't go on
3139 // title (the equivalente in latex for this case is caption
3140 // and title should come first
3143 if(desc_on!= 3 || i!= 0) {
3144 if(!tmp_out.empty() && tmp_out[0] == '@') {
3146 extra += frontStrip(tmp_out, '@');
3148 os << frontStrip(tmp_out, '@');
3153 } else if (font2.latex() == LyXFont::ON) {
3154 // "TeX"-Mode on ==> SGML-Mode on.
3161 if (par->linuxDocConvertChar(c, sgml_string)
3162 && !style.free_spacing) { // in freespacing
3164 // non-breaking characters
3168 os << "\n</term><listitem><para>";
3182 /* needed if there is an optional argument but no contents */
3183 if (main_body > 0 && main_body == par->size()) {
3187 os << "</emphasis>";
3190 /* resets description flag correctly */
3193 /* <term> not closed... */
3201 int Buffer::runLaTeX()
3203 if (!users->text) return 0;
3207 // get LaTeX-Filename
3208 string name = getLatexName();
3210 string path = OnlyPath(filename);
3212 string org_path = path;
3213 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3217 Path p(path); // path to LaTeX file
3218 users->owner()->getMiniBuffer()->Set(_("Running LaTeX..."));
3220 // Remove all error insets
3221 bool a = users->removeAutoInsets();
3223 // Always generate the LaTeX file
3224 makeLaTeXFile(name, org_path, false);
3227 // do the LaTex run(s)
3229 string latex_command = lyxrc.pdf_mode ?
3230 lyxrc.pdflatex_command : lyxrc.latex_command;
3231 LaTeX latex(latex_command, name, filepath);
3232 int res = latex.run(terr,
3233 users->owner()->getMiniBuffer()); // running latex
3235 // check return value from latex.run().
3236 if ((res & LaTeX::NO_LOGFILE)) {
3237 WriteAlert(_("LaTeX did not work!"),
3238 _("Missing log file:"), name);
3239 } else if ((res & LaTeX::ERRORS)) {
3240 users->owner()->getMiniBuffer()->Set(_("Done"));
3241 // Insert all errors as errors boxes
3242 users->insertErrors(terr);
3244 // Dvi should also be kept dirty if the latex run
3245 // ends up with errors. However it should be possible
3246 // to view a dirty dvi too.
3248 //no errors or any other things to think about so:
3249 users->owner()->getMiniBuffer()->Set(_("Done"));
3253 // if we removed error insets before we ran LaTeX or if we inserted
3254 // error insets after we ran LaTeX this must be run:
3255 if (a || (res & LaTeX::ERRORS)){
3258 users->updateScrollbar();
3262 return latex.getNumErrors();
3266 int Buffer::runLiterate()
3268 if (!users->text) return 0;
3272 // get LaTeX-Filename
3273 string name = getLatexName();
3274 // get Literate-Filename
3275 string lit_name = ChangeExtension (getLatexName(),
3276 lyxrc.literate_extension, true);
3278 string path = OnlyPath(filename);
3280 string org_path = path;
3281 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3285 Path p(path); // path to Literate file
3286 users->owner()->getMiniBuffer()->Set(_("Running Literate..."));
3288 // Remove all error insets
3289 bool a = users->removeAutoInsets();
3291 // generate the Literate file if necessary
3292 if (!isDviClean() || a) {
3293 makeLaTeXFile(lit_name, org_path, false);
3297 string latex_command = lyxrc.pdf_mode ?
3298 lyxrc.pdflatex_command : lyxrc.latex_command;
3299 Literate literate(latex_command, name, filepath,
3301 lyxrc.literate_command, lyxrc.literate_error_filter,
3302 lyxrc.build_command, lyxrc.build_error_filter);
3304 int res = literate.weave(terr, users->owner()->getMiniBuffer());
3306 // check return value from literate.weave().
3307 if ((res & Literate::NO_LOGFILE)) {
3308 WriteAlert(_("Literate command did not work!"),
3309 _("Missing log file:"), name);
3310 } else if ((res & Literate::ERRORS)) {
3311 users->owner()->getMiniBuffer()->Set(_("Done"));
3312 // Insert all errors as errors boxes
3313 users->insertErrors(terr);
3315 // Dvi should also be kept dirty if the latex run
3316 // ends up with errors. However it should be possible
3317 // to view a dirty dvi too.
3319 //no errors or any other things to think about so:
3320 users->owner()->getMiniBuffer()->Set(_("Done"));
3324 // if we removed error insets before we ran LaTeX or if we inserted
3325 // error insets after we ran LaTeX this must be run:
3326 if (a || (res & Literate::ERRORS)){
3329 users->updateScrollbar();
3333 return literate.getNumErrors();
3337 int Buffer::buildProgram()
3339 if (!users->text) return 0;
3343 // get LaTeX-Filename
3344 string name = getLatexName();
3345 // get Literate-Filename
3346 string lit_name = ChangeExtension(getLatexName(),
3347 lyxrc.literate_extension, true);
3349 string path = OnlyPath(filename);
3351 string org_path = path;
3352 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3356 Path p(path); // path to Literate file
3357 users->owner()->getMiniBuffer()->Set(_("Building Program..."));
3359 // Remove all error insets
3360 bool a = users->removeAutoInsets();
3362 // generate the LaTeX file if necessary
3363 if (!isNwClean() || a) {
3364 makeLaTeXFile(lit_name, org_path, false);
3368 string latex_command = lyxrc.pdf_mode ?
3369 lyxrc.pdflatex_command : lyxrc.latex_command;
3370 Literate literate(latex_command, name, filepath,
3372 lyxrc.literate_command, lyxrc.literate_error_filter,
3373 lyxrc.build_command, lyxrc.build_error_filter);
3375 int res = literate.build(terr, users->owner()->getMiniBuffer());
3377 // check return value from literate.build().
3378 if ((res & Literate::NO_LOGFILE)) {
3379 WriteAlert(_("Build did not work!"),
3380 _("Missing log file:"), name);
3381 } else if ((res & Literate::ERRORS)) {
3382 users->owner()->getMiniBuffer()->Set(_("Done"));
3383 // Insert all errors as errors boxes
3384 users->insertErrors(terr);
3386 // Literate files should also be kept dirty if the literate
3387 // command run ends up with errors.
3389 //no errors or any other things to think about so:
3390 users->owner()->getMiniBuffer()->Set(_("Done"));
3394 // if we removed error insets before we ran Literate/Build or if we inserted
3395 // error insets after we ran Literate/Build this must be run:
3396 if (a || (res & Literate::ERRORS)){
3399 users->updateScrollbar();
3403 return literate.getNumErrors();
3407 // This should be enabled when the Chktex class is implemented. (Asger)
3408 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
3409 // Other flags: -wall -v0 -x
3410 int Buffer::runChktex()
3412 if (!users->text) return 0;
3416 // get LaTeX-Filename
3417 string name = getLatexName();
3418 string path = OnlyPath(filename);
3420 string org_path = path;
3421 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3425 Path p(path); // path to LaTeX file
3426 users->owner()->getMiniBuffer()->Set(_("Running chktex..."));
3428 // Remove all error insets
3429 bool a = users->removeAutoInsets();
3431 // Generate the LaTeX file if neccessary
3432 if (!isDviClean() || a) {
3433 makeLaTeXFile(name, org_path, false);
3438 Chktex chktex(lyxrc.chktex_command, name, filepath);
3439 int res = chktex.run(terr); // run chktex
3442 WriteAlert(_("chktex did not work!"),
3443 _("Could not run with file:"), name);
3444 } else if (res > 0) {
3445 // Insert all errors as errors boxes
3446 users->insertErrors(terr);
3449 // if we removed error insets before we ran chktex or if we inserted
3450 // error insets after we ran chktex, this must be run:
3454 users->updateScrollbar();
3463 void Buffer::RoffAsciiTable(ostream & os, LyXParagraph * par)
3465 LyXFont font1(LyXFont::ALL_INHERIT,params.language_info);
3468 LyXParagraph::size_type i;
3472 string fname1 = TmpFileName(string(), "RAT1");
3473 string fname2 = TmpFileName(string(), "RAT2");
3475 ofstream ofs(fname1.c_str());
3477 WriteAlert(_("LYX_ERROR:"),
3478 _("Cannot open temporary file:"), fname1);
3481 par->table->RoffEndOfCell(ofs, -1);
3482 for (i = 0; i < par->size(); ++i) {
3483 c = par->GetChar(i);
3484 if (par->table->IsContRow(cell)) {
3485 if (c == LyXParagraph::META_NEWLINE)
3489 font2 = par->GetFontSettings(i);
3490 if (font1.latex() != font2.latex()) {
3491 if (font2.latex() != LyXFont::OFF)
3495 case LyXParagraph::META_INSET:
3496 if ((inset = par->GetInset(i))) {
3499 stringstresm ss(ios::in | ios::out);
3500 inset->Latex(ss, -1);
3512 inset->Latex(ss, -1);
3525 fstream fs(fname2.c_str(), ios::in|ios::out);
3527 WriteAlert(_("LYX_ERROR:"),
3528 _("Cannot open temporary file:"), fname2);
3530 remove(fname1.c_str());
3533 inset->Latex(fs, -1);
3547 case LyXParagraph::META_NEWLINE:
3548 if (par->table->CellHasContRow(cell)>= 0)
3549 par->RoffContTableRows(ofs, i+1, cell);
3550 par->table->RoffEndOfCell(ofs, cell);
3553 case LyXParagraph::META_HFILL:
3556 case LyXParagraph::META_PROTECTED_SEPARATOR:
3567 << "RoffAsciiTable:"
3568 " NULL char in structure." << endl;
3572 par->table->RoffEndOfCell(ofs, cell);
3574 string cmd = lyxrc.ascii_roff_command + " >" + fname2;
3575 cmd = subst(cmd, "$$FName", fname1);
3576 Systemcalls one(Systemcalls::System, cmd);
3577 if (!(lyxerr.debugging(Debug::ROFF))) {
3578 remove(fname1.c_str());
3580 ifstream ifs(fname2.c_str());
3582 WriteFSAlert(_("Error! Can't open temporary file:"), fname2);
3585 // now output the produced file
3589 WriteAlert(_("Error!"),
3590 _("Error executing *roff command on table"));
3591 // overread leading blank lines
3592 while(!ifs && (c == '\n'))
3595 for(j = 0; j < par->depth; ++j)
3597 while(!ifs && (c != '\n')) {
3602 // overread trailing blank lines
3603 while(!ifs && (c == '\n'))
3607 remove(fname2.c_str());
3612 /// changed Heinrich Bauer, 23/03/98
3613 bool Buffer::isDviClean() const
3615 if (lyxrc.use_tempdir)
3616 return dvi_clean_tmpd;
3618 return dvi_clean_orgd;
3622 /// changed Heinrich Bauer, 23/03/98
3623 void Buffer::markDviClean()
3625 if (lyxrc.use_tempdir)
3626 dvi_clean_tmpd = true;
3628 dvi_clean_orgd = true;
3632 /// changed Heinrich Bauer, 23/03/98
3633 void Buffer::markDviDirty()
3635 if (lyxrc.use_tempdir)
3636 dvi_clean_tmpd = false;
3638 dvi_clean_orgd = false;
3642 void Buffer::validate(LaTeXFeatures & features) const
3644 LyXParagraph * par = paragraph;
3645 LyXTextClass const & tclass =
3646 textclasslist.TextClass(params.textclass);
3648 // AMS Style is at document level
3650 features.amsstyle = (params.use_amsmath ||
3651 tclass.provides(LyXTextClass::amsmath));
3654 // We don't use "lyxerr.debug" because of speed. (Asger)
3655 if (lyxerr.debugging(Debug::LATEX))
3656 lyxerr << "Paragraph: " << par << endl;
3658 // Now just follow the list of paragraphs and run
3659 // validate on each of them.
3660 par->validate(features);
3662 // and then the next paragraph
3666 // the bullet shapes are buffer level not paragraph level
3667 // so they are tested here
3668 for (int i = 0; i < 4; ++i) {
3669 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
3670 int font = params.user_defined_bullets[i].getFont();
3673 .user_defined_bullets[i]
3680 features.latexsym = true;
3684 features.amssymb = true;
3686 else if ((font >= 2 && font <= 5)) {
3687 features.pifont = true;
3692 if (lyxerr.debugging(Debug::LATEX)) {
3693 features.showStruct(params);
3698 void Buffer::setPaperStuff()
3700 params.papersize = BufferParams::PAPER_DEFAULT;
3701 char c1 = params.paperpackage;
3702 if (c1 == BufferParams::PACKAGE_NONE) {
3703 char c2 = params.papersize2;
3704 if (c2 == BufferParams::VM_PAPER_USLETTER)
3705 params.papersize = BufferParams::PAPER_USLETTER;
3706 else if (c2 == BufferParams::VM_PAPER_USLEGAL)
3707 params.papersize = BufferParams::PAPER_LEGALPAPER;
3708 else if (c2 == BufferParams::VM_PAPER_USEXECUTIVE)
3709 params.papersize = BufferParams::PAPER_EXECUTIVEPAPER;
3710 else if (c2 == BufferParams::VM_PAPER_A3)
3711 params.papersize = BufferParams::PAPER_A3PAPER;
3712 else if (c2 == BufferParams::VM_PAPER_A4)
3713 params.papersize = BufferParams::PAPER_A4PAPER;
3714 else if (c2 == BufferParams::VM_PAPER_A5)
3715 params.papersize = BufferParams::PAPER_A5PAPER;
3716 else if ((c2 == BufferParams::VM_PAPER_B3) || (c2 == BufferParams::VM_PAPER_B4) ||
3717 (c2 == BufferParams::VM_PAPER_B5))
3718 params.papersize = BufferParams::PAPER_B5PAPER;
3719 } else if ((c1 == BufferParams::PACKAGE_A4) || (c1 == BufferParams::PACKAGE_A4WIDE) ||
3720 (c1 == BufferParams::PACKAGE_WIDEMARGINSA4))
3721 params.papersize = BufferParams::PAPER_A4PAPER;
3725 // This function should be in Buffer because it's a buffer's property (ale)
3726 string Buffer::getIncludeonlyList(char delim)
3729 LyXParagraph * par = paragraph;
3730 LyXParagraph::size_type pos;
3734 while ((inset = par->ReturnNextInsetPointer(pos))){
3735 if (inset->LyxCode() == Inset::INCLUDE_CODE) {
3736 InsetInclude * insetinc =
3737 static_cast<InsetInclude*>(inset);
3738 if (insetinc->isInclude()
3739 && insetinc->isNoLoad()) {
3742 lst += ChangeExtension(insetinc->getContents(), string(), true);
3749 lyxerr.debug() << "Includeonly(" << lst << ')' << endl;
3754 // This is also a buffer property (ale)
3755 string Buffer::getReferenceList(char delim)
3757 /// if this is a child document and the parent is already loaded
3758 /// Use the parent's list instead [ale990407]
3759 if (!params.parentname.empty()
3760 && bufferlist.exists(params.parentname)) {
3761 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3763 return tmp->getReferenceList(delim);
3766 LyXParagraph * par = paragraph;
3767 LyXParagraph::size_type pos;
3772 while ((inset = par->ReturnNextInsetPointer(pos))){
3773 for (int i = 0; i < inset->GetNumberOfLabels(); ++i) {
3776 lst += inset->getLabel(i);
3782 lyxerr.debug() << "References(" << lst << ")" << endl;
3787 // This is also a buffer property (ale)
3788 string Buffer::getBibkeyList(char delim)
3790 /// if this is a child document and the parent is already loaded
3791 /// Use the parent's list instead [ale990412]
3792 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3793 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3795 return tmp->getBibkeyList(delim);
3799 LyXParagraph * par = paragraph;
3802 if (!bibkeys.empty())
3804 bibkeys += par->bibkey->getContents();
3809 // Might be either using bibtex or a child has bibliography
3810 if (bibkeys.empty()) {
3814 LyXParagraph::size_type pos = -1;
3816 // Search for Bibtex or Include inset
3817 while ((inset = par->ReturnNextInsetPointer(pos))) {
3818 if (inset-> LyxCode() == Inset::BIBTEX_CODE) {
3819 if (!bibkeys.empty())
3821 bibkeys += static_cast<InsetBibtex*>(inset)->getKeys(delim);
3822 } else if (inset-> LyxCode() == Inset::INCLUDE_CODE) {
3823 string bk = static_cast<InsetInclude*>(inset)->getKeys(delim);
3825 if (!bibkeys.empty())
3836 lyxerr.debug() << "Bibkeys(" << bibkeys << ")" << endl;
3841 bool Buffer::isDepClean(string const & name) const
3843 DEPCLEAN * item = dep_clean;
3844 while (item && item->master != name)
3846 if (!item) return true;
3851 void Buffer::markDepClean(string const & name)
3854 dep_clean = new DEPCLEAN;
3855 dep_clean->clean = true;
3856 dep_clean->master = name;
3857 dep_clean->next = 0;
3859 DEPCLEAN* item = dep_clean;
3860 while (item && item->master != name)
3865 item = new DEPCLEAN;
3867 item->master = name;
3874 void Buffer::Dispatch(string const & command)
3876 // Split command string into command and argument
3877 string cmd, line = frontStrip(command);
3878 string arg = strip(frontStrip(split(line, cmd, ' ')));
3880 Dispatch(lyxaction.LookupFunc(cmd.c_str()), arg.c_str());
3884 void Buffer::Dispatch(int action, string const & argument)
3888 MenuExport(this, argument);
3892 lyxerr << "A truly unknown func!" << endl;