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"
95 // Uncomment this line to enable a workaround for the weird behaviour
96 // of the cursor between a displayed inset and last character
97 // at the upper line. (Alejandro 20.9.96)
98 // #define BREAK_BEFORE_INSET
100 /* Lars, when changing this file sometime in the future to a list,
101 * please check out the figinsets-sideeffects described at the
102 * beginning of figinset.C Matthias (04.07.1996)
106 // all these externs should eventually be removed.
107 extern BufferList bufferlist;
109 extern void MenuExport(Buffer *, string const &);
110 extern LyXAction lyxaction;
113 static const float LYX_FORMAT = 2.16;
115 extern int tex_code_break_column;
117 extern void FreeUpdateTimer();
120 Buffer::Buffer(string const & file, bool ronly)
122 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
124 filepath = OnlyPath(file);
128 dvi_clean_orgd = false; // Heinrich Bauer, 23/03/98
129 dvi_clean_tmpd = false; // Heinrich Bauer, 23/03/98
134 if (read_only || (lyxrc.use_tempdir)) {
135 tmppath = CreateBufferTmpDir();
136 } else tmppath.clear();
142 lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
143 // here the buffer should take care that it is
144 // saved properly, before it goes into the void.
146 // make sure that views using this buffer
151 if (!tmppath.empty()) {
152 DestroyBufferTmpDir(tmppath);
155 LyXParagraph * par = paragraph;
156 LyXParagraph * tmppar;
166 bool Buffer::saveParamsAsDefaults()
168 string fname = AddName(AddPath(user_lyxdir, "templates/"),
170 Buffer defaults = Buffer(fname);
172 // Use the current buffer's parameters as default
173 defaults.params = params;
175 // add an empty paragraph. Is this enough?
176 defaults.paragraph = new LyXParagraph;
178 return defaults.writeFile(defaults.filename, false);
182 /// Update window titles of all users
183 // Should work on a list
184 void Buffer::updateTitles() const
186 if (users) users->owner()->updateWindowTitle();
190 /// Reset autosave timer of all users
191 // Should work on a list
192 void Buffer::resetAutosaveTimers() const
194 if (users) users->owner()->resetAutosaveTimer();
198 void Buffer::fileName(string const & newfile)
200 filename = MakeAbsPath(newfile);
201 filepath = OnlyPath(filename);
202 setReadonly(IsFileWriteable(filename) == 0);
207 // candidate for move to BufferView
208 // (at least some parts in the beginning of the func)
211 // changed to be public and have one parameter
212 // if par = 0 normal behavior
213 // else insert behavior
214 // Returns false if "\the_end" is not read for formats >= 2.13. (Asger)
215 #define USE_PARSE_FUNCTION 1
216 bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par)
220 char depth = 0; // signed or unsigned?
221 LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
222 LyXParagraph::footnote_kind footnotekind = LyXParagraph::FOOTNOTE;
223 bool the_end_read = false;
225 LyXParagraph * return_par = 0;
226 LyXFont font(LyXFont::ALL_INHERIT,params.language_info);
227 if (format < 2.16 && params.language == "hebrew")
228 font.setLanguage(default_language);
230 // If we are inserting, we cheat and get a token in advance
231 bool has_token = false;
235 par = new LyXParagraph;
237 users->text->BreakParagraph();
238 return_par = users->text->FirstParagraph();
241 // We don't want to adopt the parameters from the
242 // document we insert, so we skip until the text begins:
245 pretoken = lex.GetString();
246 if (pretoken == "\\layout") {
258 pretoken = lex.GetString();
261 // Profiling show this should give a lot: (Asger)
262 string const token = pretoken;
266 the_end_read = parseSingleLyXformat2Token(lex, par, return_par,
275 paragraph = return_par;
281 bool Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
282 LyXParagraph *& return_par,
283 const string & token, int & pos,
284 char & depth, LyXFont & font,
285 LyXParagraph::footnote_flag & footnoteflag,
286 LyXParagraph::footnote_kind & footnotekind)
291 bool the_end_read = false;
293 if (token[0] != '\\') {
294 int n = token.length();
295 for (int i = 0; i < n; ++i) {
296 par->InsertChar(pos, token[i]);
297 par->SetFont(pos, font);
300 } else if (token == "\\i") {
301 inset = new InsetLatexAccent;
303 par->InsertChar(pos, LyXParagraph::META_INSET);
304 par->InsertInset(pos, inset);
305 par->SetFont(pos, font);
307 } else if (token == "\\layout") {
312 par = new LyXParagraph(par);
316 string layoutname = lex.GetString();
317 pair<bool, LyXTextClass::LayoutList::size_type> pp
318 = textclasslist.NumberOfLayout(params.textclass,
321 par->layout = pp.second;
322 } else { // layout not found
323 // use default layout "Standard" (0)
326 // Test whether the layout is obsolete.
327 LyXLayout const & layout =
328 textclasslist.Style(params.textclass,
330 if (!layout.obsoleted_by().empty())
332 textclasslist.NumberOfLayout(params.textclass,
333 layout.obsoleted_by()).second;
334 par->footnoteflag = footnoteflag;
335 par->footnotekind = footnotekind;
337 font = LyXFont(LyXFont::ALL_INHERIT,params.language_info);
338 if (format < 2.16 && params.language == "hebrew")
339 font.setLanguage(default_language);
340 } else if (token == "\\end_float") {
345 par = new LyXParagraph(par);
347 footnotekind = LyXParagraph::FOOTNOTE;
348 footnoteflag = LyXParagraph::NO_FOOTNOTE;
351 par->layout = LYX_DUMMY_LAYOUT;
352 font = LyXFont(LyXFont::ALL_INHERIT,params.language_info);
353 if (format < 2.16 && params.language == "hebrew")
354 font.setLanguage(default_language);
355 } else if (token == "\\begin_float") {
356 tmpret = lex.FindToken(string_footnotekinds);
357 if (tmpret == -1) ++tmpret;
358 if (tmpret != LYX_LAYOUT_DEFAULT)
359 footnotekind = static_cast<LyXParagraph::footnote_kind>(tmpret); // bad
360 if (footnotekind == LyXParagraph::FOOTNOTE
361 || footnotekind == LyXParagraph::MARGIN)
362 footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
364 footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
365 } else if (token == "\\begin_deeper") {
367 } else if (token == "\\end_deeper") {
369 lex.printError("\\end_deeper: "
370 "depth is already null");
374 } else if (token == "\\begin_preamble") {
375 params.readPreamble(lex);
376 } else if (token == "\\textclass") {
378 pair<bool, LyXTextClassList::size_type> pp =
379 textclasslist.NumberOfClass(lex.GetString());
381 params.textclass = pp.second;
383 lex.printError("Unknown textclass `$$Token'");
384 params.textclass = 0;
386 if (!textclasslist.Load(params.textclass)) {
387 // if the textclass wasn't loaded properly
388 // we need to either substitute another
389 // or stop loading the file.
390 // I can substitute but I don't see how I can
391 // stop loading... ideas?? ARRae980418
392 WriteAlert(_("Textclass Loading Error!"),
393 string(_("Can't load textclass ")) +
394 textclasslist.NameOfClass(params.textclass),
395 _("-- substituting default"));
396 params.textclass = 0;
398 } else if (token == "\\options") {
400 params.options = lex.GetString();
401 } else if (token == "\\language") {
402 params.readLanguage(lex);
403 } else if (token == "\\fontencoding") {
405 } else if (token == "\\inputencoding") {
407 params.inputenc = lex.GetString();
408 } else if (token == "\\graphics") {
409 params.readGraphicsDriver(lex);
410 } else if (token == "\\fontscheme") {
412 params.fonts = lex.GetString();
413 } else if (token == "\\noindent") {
414 par->noindent = true;
415 } else if (token == "\\fill_top") {
416 par->added_space_top = VSpace(VSpace::VFILL);
417 } else if (token == "\\fill_bottom") {
418 par->added_space_bottom = VSpace(VSpace::VFILL);
419 } else if (token == "\\line_top") {
420 par->line_top = true;
421 } else if (token == "\\line_bottom") {
422 par->line_bottom = true;
423 } else if (token == "\\pagebreak_top") {
424 par->pagebreak_top = true;
425 } else if (token == "\\pagebreak_bottom") {
426 par->pagebreak_bottom = true;
427 } else if (token == "\\start_of_appendix") {
428 par->start_of_appendix = true;
429 } else if (token == "\\paragraph_separation") {
430 tmpret = lex.FindToken(string_paragraph_separation);
431 if (tmpret == -1) ++tmpret;
432 if (tmpret != LYX_LAYOUT_DEFAULT)
433 params.paragraph_separation =
434 static_cast<BufferParams::PARSEP>(tmpret);
435 } else if (token == "\\defskip") {
437 params.defskip = VSpace(lex.GetString());
439 } else if (token == "\\no_isolatin1") { // obsolete
441 } else if (token == "\\no_babel") { // obsolete
443 } else if (token == "\\no_epsfig") { // obsolete
446 } else if (token == "\\epsfig") { // obsolete
447 // Indeed it is obsolete, but we HAVE to be backwards
448 // compatible until 0.14, because otherwise all figures
449 // in existing documents are irretrivably lost. (Asger)
450 params.readGraphicsDriver(lex);
451 } else if (token == "\\quotes_language") {
452 tmpret = lex.FindToken(string_quotes_language);
453 if (tmpret == -1) ++tmpret;
454 if (tmpret != LYX_LAYOUT_DEFAULT) {
455 InsetQuotes::quote_language tmpl =
456 InsetQuotes::EnglishQ;
459 tmpl = InsetQuotes::EnglishQ;
462 tmpl = InsetQuotes::SwedishQ;
465 tmpl = InsetQuotes::GermanQ;
468 tmpl = InsetQuotes::PolishQ;
471 tmpl = InsetQuotes::FrenchQ;
474 tmpl = InsetQuotes::DanishQ;
477 params.quotes_language = tmpl;
479 } else if (token == "\\quotes_times") {
481 switch(lex.GetInteger()) {
483 params.quotes_times = InsetQuotes::SingleQ;
486 params.quotes_times = InsetQuotes::DoubleQ;
489 } else if (token == "\\papersize") {
490 tmpret = lex.FindToken(string_papersize);
494 params.papersize2 = tmpret;
495 } else if (token == "\\paperpackage") {
496 tmpret = lex.FindToken(string_paperpackages);
499 params.paperpackage = BufferParams::PACKAGE_NONE;
501 params.paperpackage = tmpret;
502 } else if (token == "\\use_geometry") {
504 params.use_geometry = lex.GetInteger();
505 } else if (token == "\\use_amsmath") {
507 params.use_amsmath = lex.GetInteger();
508 } else if (token == "\\paperorientation") {
509 tmpret = lex.FindToken(string_orientation);
510 if (tmpret == -1) ++tmpret;
511 if (tmpret != LYX_LAYOUT_DEFAULT)
512 params.orientation = static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
513 } else if (token == "\\paperwidth") {
515 params.paperwidth = lex.GetString();
516 } else if (token == "\\paperheight") {
518 params.paperheight = lex.GetString();
519 } else if (token == "\\leftmargin") {
521 params.leftmargin = lex.GetString();
522 } else if (token == "\\topmargin") {
524 params.topmargin = lex.GetString();
525 } else if (token == "\\rightmargin") {
527 params.rightmargin = lex.GetString();
528 } else if (token == "\\bottommargin") {
530 params.bottommargin = lex.GetString();
531 } else if (token == "\\headheight") {
533 params.headheight = lex.GetString();
534 } else if (token == "\\headsep") {
536 params.headsep = lex.GetString();
537 } else if (token == "\\footskip") {
539 params.footskip = lex.GetString();
540 } else if (token == "\\paperfontsize") {
542 params.fontsize = strip(lex.GetString());
543 } else if (token == "\\papercolumns") {
545 params.columns = lex.GetInteger();
546 } else if (token == "\\papersides") {
548 switch(lex.GetInteger()) {
550 case 1: params.sides = LyXTextClass::OneSide; break;
551 case 2: params.sides = LyXTextClass::TwoSides; break;
553 } else if (token == "\\paperpagestyle") {
555 params.pagestyle = strip(lex.GetString());
556 } else if (token == "\\bullet") {
558 int index = lex.GetInteger();
560 int temp_int = lex.GetInteger();
561 params.user_defined_bullets[index].setFont(temp_int);
562 params.temp_bullets[index].setFont(temp_int);
564 temp_int = lex.GetInteger();
565 params.user_defined_bullets[index].setCharacter(temp_int);
566 params.temp_bullets[index].setCharacter(temp_int);
568 temp_int = lex.GetInteger();
569 params.user_defined_bullets[index].setSize(temp_int);
570 params.temp_bullets[index].setSize(temp_int);
572 string temp_str = lex.GetString();
573 if (temp_str != "\\end_bullet") {
574 // this element isn't really necessary for
575 // parsing but is easier for humans
576 // to understand bullets. Put it back and
577 // set a debug message?
578 lex.printError("\\end_bullet expected, got" + temp_str);
579 //how can I put it back?
581 } else if (token == "\\bulletLaTeX") {
583 int index = lex.GetInteger();
585 string temp_str = lex.GetString(), sum_str;
586 while (temp_str != "\\end_bullet") {
587 // this loop structure is needed when user
588 // enters an empty string since the first
589 // thing returned will be the \\end_bullet
591 // if the LaTeX entry has spaces. Each element
592 // therefore needs to be read in turn
595 temp_str = lex.GetString();
597 params.user_defined_bullets[index].setText(sum_str);
598 params.temp_bullets[index].setText(sum_str);
599 } else if (token == "\\secnumdepth") {
601 params.secnumdepth = lex.GetInteger();
602 } else if (token == "\\tocdepth") {
604 params.tocdepth = lex.GetInteger();
605 } else if (token == "\\baselinestretch") { // obsolete
606 lex.nextToken(); // should not be used directly
608 // Will probably keep a kind of support just for
610 params.spacing.set(Spacing::Other, lex.GetFloat());
611 } else if (token == "\\spacing") {
613 string tmp = strip(lex.GetString());
614 if (tmp == "single") {
615 params.spacing.set(Spacing::Single);
616 } else if (tmp == "onehalf") {
617 params.spacing.set(Spacing::Onehalf);
618 } else if (tmp == "double") {
619 params.spacing.set(Spacing::Double);
620 } else if (tmp == "other") {
622 params.spacing.set(Spacing::Other,
625 lex.printError("Unknown spacing token: '$$Token'");
627 } else if (token == "\\float_placement") {
629 params.float_placement = lex.GetString();
630 } else if (token == "\\cursor") { // obsolete
631 // this is obsolete, so we just skip it.
633 } else if (token == "\\family") {
635 font.setLyXFamily(lex.GetString());
636 } else if (token == "\\series") {
638 font.setLyXSeries(lex.GetString());
639 } else if (token == "\\shape") {
641 font.setLyXShape(lex.GetString());
642 } else if (token == "\\size") {
644 font.setLyXSize(lex.GetString());
645 } else if (token == "\\latex") {
647 string tok = lex.GetString();
648 // This is dirty, but gone with LyX3. (Asger)
649 if (tok == "no_latex")
650 font.setLatex(LyXFont::OFF);
651 else if (tok == "latex")
652 font.setLatex(LyXFont::ON);
653 else if (tok == "default")
654 font.setLatex(LyXFont::INHERIT);
656 lex.printError("Unknown LaTeX font flag "
658 } else if (token == "\\lang") {
660 string tok = lex.GetString();
661 Languages::iterator lit = languages.find(tok);
662 if (lit != languages.end()) {
663 font.setLanguage(&(*lit).second);
665 font.setLanguage(params.language_info);
666 lex.printError("Unknown language `$$Token'");
668 } else if (token == "\\direction") { // obsolete
670 lex.printError("Command \\direction is obsolete");
672 string tok = lex.GetString();
674 font.setLanguage(&languages["hebrew"]);
675 else if (tok == "default")
676 if (params.language == "hebrew")
677 font.setLanguage(default_language);
679 font.setLanguage(params.language_info);
681 lex.printError("Unknown direction `$$Token'");
682 } else if (token == "\\emph") {
684 font.setEmph(font.setLyXMisc(lex.GetString()));
685 } else if (token == "\\bar") {
687 string tok = lex.GetString();
688 // This is dirty, but gone with LyX3. (Asger)
690 font.setUnderbar(LyXFont::ON);
691 else if (tok == "no")
692 font.setUnderbar(LyXFont::OFF);
693 else if (tok == "default")
694 font.setUnderbar(LyXFont::INHERIT);
696 lex.printError("Unknown bar font flag "
698 } else if (token == "\\noun") {
700 font.setNoun(font.setLyXMisc(lex.GetString()));
701 } else if (token == "\\color") {
703 font.setLyXColor(lex.GetString());
704 } else if (token == "\\align") {
705 tmpret = lex.FindToken(string_align);
706 if (tmpret == -1) ++tmpret;
707 if (tmpret != LYX_LAYOUT_DEFAULT) { // tmpret != 99 ???
709 for (; tmpret > 0; --tmpret)
710 tmpret2 = tmpret2 * 2;
711 par->align = LyXAlignment(tmpret2);
713 } else if (token == "\\added_space_top") {
715 par->added_space_top = lex.GetString();
716 } else if (token == "\\added_space_bottom") {
718 par->added_space_bottom = lex.GetString();
719 } else if (token == "\\pextra_type") {
721 par->pextra_type = lex.GetInteger();
722 } else if (token == "\\pextra_width") {
724 par->pextra_width = lex.GetString();
725 } else if (token == "\\pextra_widthp") {
727 par->pextra_widthp = lex.GetString();
728 } else if (token == "\\pextra_alignment") {
730 par->pextra_alignment = lex.GetInteger();
731 } else if (token == "\\pextra_hfill") {
733 par->pextra_hfill = lex.GetInteger();
734 } else if (token == "\\pextra_start_minipage") {
736 par->pextra_start_minipage = lex.GetInteger();
737 } else if (token == "\\labelwidthstring") {
739 par->labelwidthstring = lex.GetString();
740 /* do not delete this token, it is still needed! */
741 } else if (token == "\\end_inset") {
742 /* simple ignore this. The insets do not have
744 // but insets should read it, it is a part of
745 //the inset isn't it? Lgb.
746 } else if (token == "\\begin_inset") {
748 tmptok = lex.GetString();
749 /* test the different insets */
750 if (tmptok == "Quotes") {
751 inset = new InsetQuotes;
753 par->InsertChar(pos, LyXParagraph::META_INSET);
754 par->InsertInset(pos, inset);
755 par->SetFont(pos, font);
757 } else if (tmptok == "\\i") {
758 inset = new InsetLatexAccent;
760 par->InsertChar(pos, LyXParagraph::META_INSET);
761 par->InsertInset(pos, inset);
762 par->SetFont(pos, font);
764 } else if (tmptok == "FormulaMacro") {
765 inset = new InsetFormulaMacro;
767 par->InsertChar(pos, LyXParagraph::META_INSET);
768 par->InsertInset(pos, inset);
769 par->SetFont(pos, font);
771 } else if (tmptok == "Formula") {
772 inset = new InsetFormula;
774 par->InsertChar(pos, LyXParagraph::META_INSET);
775 par->InsertInset(pos, inset);
776 par->SetFont(pos, font);
778 } else if (tmptok == "Figure") {
779 inset = new InsetFig(100, 100, this);
781 par->InsertChar(pos, LyXParagraph::META_INSET);
782 par->InsertInset(pos, inset);
783 par->SetFont(pos, font);
785 } else if (tmptok == "Info") {
786 inset = new InsetInfo;
788 par->InsertChar(pos, LyXParagraph::META_INSET);
789 par->InsertInset(pos, inset);
790 par->SetFont(pos, font);
792 } else if (tmptok == "Include") {
793 inset = new InsetInclude(string(), this);
795 par->InsertChar(pos, LyXParagraph::META_INSET);
796 par->InsertInset(pos, inset);
797 par->SetFont(pos, font);
799 } else if (tmptok == "ERT") {
800 inset = new InsetERT(this);
802 par->InsertChar(pos, LyXParagraph::META_INSET);
803 par->InsertInset(pos, inset);
804 par->SetFont(pos, font);
806 } else if (tmptok == "Text") {
807 inset = new InsetText(this);
809 par->InsertChar(pos, LyXParagraph::META_INSET);
810 par->InsertInset(pos, inset);
811 par->SetFont(pos, font);
813 } else if (tmptok == "Foot") {
814 inset = new InsetFoot(this);
816 par->InsertChar(pos, LyXParagraph::META_INSET);
817 par->InsertInset(pos, inset);
818 par->SetFont(pos, font);
820 } else if (tmptok == "GRAPHICS") {
821 inset = new InsetGraphics;
823 par->InsertChar(pos, LyXParagraph::META_INSET);
824 par->InsertInset(pos, inset);
825 par->SetFont(pos, font);
826 } else if (tmptok == "LatexCommand") {
829 if (inscmd.getCmdName() == "cite") {
830 inset = new InsetCitation(inscmd.getContents(), inscmd.getOptions());
831 } else if (inscmd.getCmdName() == "bibitem") {
832 lex.printError("Wrong place for bibitem");
833 inset = inscmd.Clone();
834 } else if (inscmd.getCmdName() == "BibTeX") {
835 inset = new InsetBibtex(inscmd.getContents(), inscmd.getOptions(), this);
836 } else if (inscmd.getCmdName() == "index") {
837 inset = new InsetIndex(inscmd.getContents());
838 } else if (inscmd.getCmdName() == "include") {
839 inset = new InsetInclude(inscmd.getContents(), this);
840 } else if (inscmd.getCmdName() == "label") {
841 inset = new InsetLabel(inscmd.getCommand());
842 } else if (inscmd.getCmdName() == "url"
843 || inscmd.getCmdName() == "htmlurl") {
844 inset = new InsetUrl(inscmd.getCommand());
845 } else if (inscmd.getCmdName() == "ref"
846 || inscmd.getCmdName() == "pageref") {
847 if (!inscmd.getOptions().empty() || !inscmd.getContents().empty()) {
848 inset = new InsetRef(inscmd, this);
850 #warning Verify that this else clause is still needed. (Lgb)
852 // This condition comes from a
853 // temporary solution to the latexdel
854 // ref inset that was transformed to
855 // an empty ref inset plus the body
856 // surronded by latexdel insets
858 string cont, opt, tmptmptok, cmdname;
860 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
865 tmptmptok = lex.GetString();
866 if(tmptmptok[0] == '\\') {
867 if( tmptmptok == "\\backslash")
877 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
882 tmptmptok = lex.GetString();
883 if(tmptmptok[0] == '\\') {
884 if( tmptmptok == "\\backslash")
894 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
900 cmdname = "\\" + inscmd.getCmdName();
901 cmdname += "[" + cont + "]";
902 cmdname += "{" + opt + "}";
903 inset = new InsetRef(cmdname, this);
906 } else if (inscmd.getCmdName() == "tableofcontents") {
907 inset = new InsetTOC(this);
908 } else if (inscmd.getCmdName() == "listoffigures") {
909 inset = new InsetLOF(this);
910 } else if (inscmd.getCmdName() == "listofalgorithms") {
911 inset = new InsetLOA(this);
912 } else if (inscmd.getCmdName() == "listoftables") {
913 inset = new InsetLOT(this);
914 } else if (inscmd.getCmdName() == "printindex") {
915 inset = new InsetPrintIndex(this);
916 } else if (inscmd.getCmdName() == "lyxparent") {
917 inset = new InsetParent(inscmd.getContents(), this);
921 par->InsertChar(pos, LyXParagraph::META_INSET);
922 par->InsertInset(pos, inset);
923 par->SetFont(pos, font);
927 } else if (token == "\\InsetQuotes") {
928 inset = new InsetQuotes;
930 par->InsertChar(pos, LyXParagraph::META_INSET);
931 par->InsertInset(pos, inset);
932 par->SetFont(pos, font);
934 } else if (token == "\\InsetFormula") {
935 inset = new InsetFormula;
937 par->InsertChar(pos, LyXParagraph::META_INSET);
938 par->InsertInset(pos, inset);
939 par->SetFont(pos, font);
941 } else if (token == "\\SpecialChar") {
942 LyXLayout const & layout =
943 textclasslist.Style(params.textclass,
946 // Insets don't make sense in a free-spacing context! ---Kayvan
947 if (layout.free_spacing)
952 next_token = lex.GetString();
953 if (next_token == "\\-") {
954 par->InsertChar(pos, '-');
955 par->SetFont(pos, font);
956 } else if (next_token == "\\protected_separator") {
957 par->InsertChar(pos, ' ');
958 par->SetFont(pos, font);
960 lex.printError("Token `$$Token' "
962 "paragraph layout!");
969 inset = new InsetSpecialChar;
971 par->InsertChar(pos, LyXParagraph::META_INSET);
972 par->InsertInset(pos, inset);
973 par->SetFont(pos, font);
976 } else if (token == "\\Figure") {
977 inset = new InsetFig(100, 100, this);
979 par->InsertChar(pos, LyXParagraph::META_INSET);
980 par->InsertInset(pos, inset);
981 par->SetFont(pos, font);
983 } else if (token == "\\newline") { // soon obsolete
985 par->InsertChar(pos, LyXParagraph::META_NEWLINE);
986 par->SetFont(pos, font);
988 inset = new InsetSpecialChar(InsetSpecialChar::NEWLINE);
989 par->InsertChar(pos, LyXParagraph::META_INSET);
990 par->InsertInset(pos, inset);
991 par->SetFont(pos, font);
994 } else if (token == "\\LyXTable") {
995 par->table = new LyXTable(lex);
996 } else if (token == "\\hfill") {
997 par->InsertChar(pos, LyXParagraph::META_HFILL);
998 par->SetFont(pos, font);
1000 } else if (token == "\\protected_separator") { // obsolete
1002 LyXLayout const & layout =
1003 textclasslist.Style(params.textclass,
1006 if (layout.free_spacing) {
1007 par->InsertChar(pos, ' ');
1008 par->SetFont(pos, font);
1010 inset = new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
1011 par->InsertChar(pos, LyXParagraph::META_INSET);
1012 par->InsertInset(pos, inset);
1013 par->SetFont(pos, font);
1016 par->InsertChar(pos, LyXParagraph::META_PROTECTED_SEPARATOR);
1017 par->SetFont(pos, font);
1020 } else if (token == "\\bibitem") { // ale970302
1022 par->bibkey = new InsetBibKey;
1023 par->bibkey->Read(lex);
1024 }else if (token == "\\backslash") {
1025 par->InsertChar(pos, '\\');
1026 par->SetFont(pos, font);
1028 }else if (token == "\\the_end") {
1029 the_end_read = true;
1031 // This should be insurance for the future: (Asger)
1032 lex.printError("Unknown token `$$Token'. "
1033 "Inserting as text.");
1034 int n = token.length();
1035 for (int i = 0; i < n; ++i) {
1036 par->InsertChar(pos, token[i]);
1037 par->SetFont(pos, font);
1041 return the_end_read;
1044 bool Buffer::readFile(LyXLex & lex, LyXParagraph * par)
1050 token = lex.GetString();
1051 if (token == "\\lyxformat") { // the first token _must_ be...
1053 format = lex.GetFloat();
1055 if (LYX_FORMAT - format > 0.05) {
1056 printf(_("Warning: need lyxformat %.2f but found %.2f\n"),
1057 LYX_FORMAT, format);
1059 if (format - LYX_FORMAT > 0.05) {
1060 printf(_("ERROR: need lyxformat %.2f but found %.2f\n"),
1061 LYX_FORMAT, format);
1063 bool the_end = readLyXformat2(lex, par);
1064 // Formats >= 2.13 support "\the_end" marker
1071 WriteAlert(_("Warning!"),
1072 _("Reading of document is not complete"),
1073 _("Maybe the document is truncated"));
1074 // We simulate a safe reading anyways to allow
1075 // users to take the chance... (Asger)
1079 WriteAlert(_("ERROR!"),
1080 _("Old LyX file format found. "
1081 "Use LyX 0.10.x to read this!"));
1085 } else { // "\\lyxformat" not found
1086 WriteAlert(_("ERROR!"), _("Not a LyX file!"));
1089 WriteAlert(_("ERROR!"), _("Unable to read file!"));
1095 // Should probably be moved to somewhere else: BufferView? LyXView?
1096 bool Buffer::save() const
1098 // We don't need autosaves in the immediate future. (Asger)
1099 resetAutosaveTimers();
1103 if (lyxrc.make_backup) {
1104 s = fileName() + '~';
1105 if (!lyxrc.backupdir_path.empty())
1106 s = AddName(lyxrc.backupdir_path,
1107 subst(CleanupPath(s),'/','!'));
1109 // Rename is the wrong way of making a backup,
1110 // this is the correct way.
1111 /* truss cp fil fil2:
1112 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
1113 stat("LyXVC.lyx", 0xEFFFF688) = 0
1114 open("LyXVC.lyx", O_RDONLY) = 3
1115 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
1116 fstat(4, 0xEFFFF508) = 0
1117 fstat(3, 0xEFFFF508) = 0
1118 read(3, " # T h i s f i l e w".., 8192) = 5579
1119 write(4, " # T h i s f i l e w".., 5579) = 5579
1120 read(3, 0xEFFFD4A0, 8192) = 0
1123 chmod("LyXVC3.lyx", 0100644) = 0
1124 lseek(0, 0, SEEK_CUR) = 46440
1128 // Should proabaly have some more error checking here.
1129 // Should be cleaned up in 0.13, at least a bit.
1130 // Doing it this way, also makes the inodes stay the same.
1131 // This is still not a very good solution, in particular we
1132 // might loose the owner of the backup.
1133 FileInfo finfo(fileName());
1134 if (finfo.exist()) {
1135 mode_t fmode = finfo.getMode();
1136 struct utimbuf * times = new struct utimbuf;
1138 times->actime = finfo.getAccessTime();
1139 times->modtime = finfo.getModificationTime();
1140 ifstream ifs(fileName().c_str());
1141 ofstream ofs(s.c_str(), ios::out|ios::trunc);
1146 ::chmod(s.c_str(), fmode);
1148 if (::utime(s.c_str(), times)) {
1149 lyxerr << "utime error." << endl;
1152 lyxerr << "LyX was not able to make "
1153 "backupcopy. Beware." << endl;
1159 if (writeFile(fileName(), false)) {
1162 // now delete the autosavefile
1163 string a = OnlyPath(fileName());
1165 a += OnlyFilename(fileName());
1167 FileInfo fileinfo(a);
1168 if (fileinfo.exist()) {
1169 if (::remove(a.c_str()) != 0) {
1170 WriteFSAlert(_("Could not delete "
1171 "auto-save file!"), a);
1175 // Saving failed, so backup is not backup
1176 if (lyxrc.make_backup) {
1177 ::rename(s.c_str(), fileName().c_str());
1185 // Returns false if unsuccesful
1186 bool Buffer::writeFile(string const & fname, bool flag) const
1188 // if flag is false writeFile will not create any GUI
1189 // warnings, only cerr.
1190 // Needed for autosave in background or panic save (Matthias 120496)
1192 if (read_only && (fname == filename)) {
1193 // Here we should come with a question if we should
1194 // perform the write anyway.
1196 lyxerr << _("Error! Document is read-only: ")
1199 WriteAlert(_("Error! Document is read-only: "),
1204 FileInfo finfo(fname);
1205 if (finfo.exist() && !finfo.writable()) {
1206 // Here we should come with a question if we should
1207 // try to do the save anyway. (i.e. do a chmod first)
1209 lyxerr << _("Error! Cannot write file: ")
1212 WriteFSAlert(_("Error! Cannot write file: "),
1217 ofstream ofs(fname.c_str());
1220 lyxerr << _("Error! Cannot open file: ")
1223 WriteFSAlert(_("Error! Cannot open file: "),
1227 // The top of the file should not be written by params.
1229 // write out a comment in the top of the file
1230 ofs << '#' << LYX_DOCVERSION
1231 << " created this file. For more info see http://www.lyx.org/\n";
1232 ofs.setf(ios::showpoint|ios::fixed);
1234 ofs << "\\lyxformat " << setw(4) << LYX_FORMAT << "\n";
1236 // now write out the buffer paramters.
1237 params.writeFile(ofs);
1239 char footnoteflag = 0;
1242 // this will write out all the paragraphs
1243 // using recursive descent.
1244 paragraph->writeFile(ofs, params, footnoteflag, depth);
1246 // Write marker that shows file is complete
1247 ofs << "\n\\the_end" << endl;
1249 // how to check if close went ok?
1254 void Buffer::writeFileAscii(string const & fname, int linelen)
1256 LyXFont font1, font2;
1258 char c, footnoteflag = 0, depth = 0;
1260 LyXParagraph::size_type i;
1261 int j, h, ltype = 0, ltype_depth = 0,
1262 * clen = 0, actcell = 0, actpos = 0, cell = 0, cells = 0,
1265 bool ref_printed = false;
1267 ofstream ofs(fname.c_str());
1269 WriteFSAlert(_("Error: Cannot write file:"), fname);
1273 string fname1 = TmpFileName();
1274 LyXParagraph * par = paragraph;
1278 if (par->footnoteflag != LyXParagraph::NO_FOOTNOTE ||
1280 par->previous->footnoteflag == LyXParagraph::NO_FOOTNOTE){
1282 /* begins a footnote environment ? */
1283 if (footnoteflag != par->footnoteflag) {
1284 footnoteflag = par->footnoteflag;
1286 j = strlen(string_footnotekinds[par->footnotekind])+4;
1287 if (currlinelen + j > linelen)
1290 << string_footnotekinds[par->footnotekind] << "] ";
1295 /* begins or ends a deeper area ?*/
1296 if (depth != par->depth) {
1297 if (par->depth > depth) {
1298 while (par->depth > depth) {
1303 while (par->depth < depth) {
1309 /* First write the layout */
1310 tmp = textclasslist.NameOfLayout(params.textclass, par->layout);
1311 if (tmp == "Itemize") {
1313 ltype_depth = depth+1;
1314 } else if (tmp == "Enumerate") {
1316 ltype_depth = depth+1;
1317 } else if (strstr(tmp.c_str(), "ection")) {
1319 ltype_depth = depth+1;
1320 } else if (strstr(tmp.c_str(), "aragraph")) {
1322 ltype_depth = depth+1;
1323 } else if (tmp == "Description") {
1325 ltype_depth = depth+1;
1326 } else if (tmp == "Abstract") {
1329 } else if (tmp == "Bibliography") {
1337 /* maybe some vertical spaces */
1339 /* the labelwidthstring used in lists */
1343 /* some pagebreaks? */
1347 /* what about the alignment */
1350 /* dummy layout, that means a footnote ended */
1351 footnoteflag = LyXParagraph::NO_FOOTNOTE;
1356 LyXLayout const & layout =
1357 textclasslist.Style(params.textclass,
1359 bool free_spc = layout.free_spacing;
1361 /* It might be a table */
1364 if (!lyxrc.ascii_roff_command.empty() &&
1365 lyxrc.ascii_roff_command != "none") {
1366 RoffAsciiTable(ofs, par);
1373 cells = par->table->columns;
1374 clen = new int [cells];
1375 memset(clen, 0, sizeof(int) * cells);
1377 for (i = 0, j = 0, h = 1; i < par->size(); ++i, ++h) {
1378 c = par->GetChar(i);
1379 if (c == LyXParagraph::META_INSET) {
1380 if ((inset = par->GetInset(i))) {
1384 inset->Latex(ost, -1, free_spc);
1385 h += ost.str().length();
1388 inset->Latex(ost, -1, free_spc);
1390 char * tmp = ost.str();
1396 ofstream fs(fname1.c_str());
1398 WriteFSAlert(_("Error: Cannot open temporary file:"), fname1);
1401 inset->Latex(fs, -1, free_spc);
1402 h += fs.tellp() - 1;
1403 ::remove(fname1.c_str());
1406 } else if (c == LyXParagraph::META_NEWLINE) {
1410 j = (++j) % par->table->NumberOfCellsInRow(actcell);
1418 font1 = LyXFont(LyXFont::ALL_INHERIT,params.language_info);
1420 for (i = 0, actpos = 1; i < par->size(); ++i, ++actpos) {
1421 if (!i && !footnoteflag && !noparbreak){
1423 for(j = 0; j < depth; ++j)
1425 currlinelen = depth * 2;
1427 case 0: /* Standard */
1428 case 4: /* (Sub)Paragraph */
1429 case 5: /* Description */
1431 case 6: /* Abstract */
1432 ofs << "Abstract\n\n";
1434 case 7: /* Bibliography */
1436 ofs << "References\n\n";
1441 ofs << par->labelstring << " ";
1444 if (ltype_depth > depth) {
1445 for(j = ltype_depth - 1; j > depth; --j)
1447 currlinelen += (ltype_depth-depth)*2;
1450 for(j = 0; j < cells; ++j) {
1452 for(h = 0; h < (clen[j] + 1);
1457 for(j = 0; j < depth; ++j)
1459 currlinelen = depth * 2;
1460 if (ltype_depth > depth) {
1461 for(j = ltype_depth;
1464 currlinelen += (ltype_depth-depth)*2;
1469 font2 = par->GetFontSettings(i);
1470 if (font1.latex() != font2.latex()) {
1471 if (font2.latex() == LyXFont::OFF)
1479 c = par->GetChar(i);
1483 case LyXParagraph::META_INSET:
1484 if ((inset = par->GetInset(i))) {
1486 inset->Latex(ofs, -1, free_spc);
1487 currlinelen += (ofs.tellp() - fpos);
1488 actpos += (ofs.tellp() - fpos) - 1;
1491 case LyXParagraph::META_NEWLINE:
1493 if (par->table->NumberOfCellsInRow(actcell) <= cell) {
1494 for(j = actpos; j < clen[cell - 1]; ++j)
1497 for(j = 0; j < depth; ++j)
1499 currlinelen = depth*2;
1500 if (ltype_depth > depth) {
1501 for(j = ltype_depth; j > depth; --j)
1503 currlinelen += (ltype_depth-depth) * 2;
1505 for(j = 0; j < cells; ++j) {
1507 for(h = 0; h < (clen[j] + 1); ++h)
1511 for(j = 0; j < depth; ++j)
1513 currlinelen = depth * 2;
1514 if (ltype_depth > depth) {
1515 for(j = ltype_depth;
1518 currlinelen += (ltype_depth-depth)*2;
1524 j < clen[cell - 1]; ++j)
1530 currlinelen = actpos = 0;
1533 for(j = 0; j < depth; ++j)
1535 currlinelen = depth * 2;
1536 if (ltype_depth > depth) {
1537 for(j = ltype_depth;
1540 currlinelen += (ltype_depth - depth) * 2;
1544 case LyXParagraph::META_HFILL:
1548 case LyXParagraph::META_PROTECTED_SEPARATOR:
1556 if (currlinelen > linelen - 10
1557 && c == ' ' && i + 2 < par->size()) {
1559 for(j = 0; j < depth; ++j)
1561 currlinelen = depth * 2;
1562 if (ltype_depth > depth) {
1563 for(j = ltype_depth;
1566 currlinelen += (ltype_depth-depth)*2;
1568 } else if (c != '\0')
1571 lyxerr.debug() << "writeAsciiFile: NULL char in structure." << endl;
1577 for(j = actpos; j < clen[cell - 1]; ++j)
1580 for(j = 0; j < depth; ++j)
1582 currlinelen = depth * 2;
1583 if (ltype_depth > depth) {
1584 for(j = ltype_depth; j > depth; --j)
1586 currlinelen += (ltype_depth - depth) * 2;
1588 for(j = 0; j < cells; ++j) {
1590 for(h = 0; h < (clen[j] + 1); ++h)
1603 void Buffer::makeLaTeXFile(string const & fname,
1604 string const & original_path,
1605 bool nice, bool only_body)
1607 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
1609 niceFile = nice; // this will be used by Insetincludes.
1611 tex_code_break_column = lyxrc.ascii_linelen;
1613 LyXTextClass const & tclass =
1614 textclasslist.TextClass(params.textclass);
1616 ofstream ofs(fname.c_str());
1618 WriteFSAlert(_("Error: Cannot open file: "), fname);
1622 // validate the buffer.
1623 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
1624 LaTeXFeatures features(tclass.numLayouts());
1626 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
1629 // The starting paragraph of the coming rows is the
1630 // first paragraph of the document. (Asger)
1631 texrow.start(paragraph, 0);
1633 if (!only_body && nice) {
1634 ofs << "%% " LYX_DOCVERSION " created this file. "
1635 "For more info, see http://www.lyx.org/.\n"
1636 "%% Do not edit unless you really know what "
1641 lyxerr.debug() << "lyx header finished" << endl;
1642 // There are a few differences between nice LaTeX and usual files:
1643 // usual is \batchmode and has a
1644 // special input@path to allow the including of figures
1645 // with either \input or \includegraphics (what figinsets do).
1646 // batchmode is not set if there is a tex_code_break_column.
1647 // In this case somebody is interested in the generated LaTeX,
1648 // so this is OK. input@path is set when the actual parameter
1649 // original_path is set. This is done for usual tex-file, but not
1650 // for nice-latex-file. (Matthias 250696)
1653 // code for usual, NOT nice-latex-file
1654 ofs << "\\batchmode\n"; // changed
1655 // from \nonstopmode
1658 if (!original_path.empty()) {
1659 ofs << "\\makeatletter\n"
1660 << "\\def\\input@path{{"
1661 << original_path << "/}}\n"
1662 << "\\makeatother\n";
1668 ofs << "\\documentclass";
1670 string options; // the document class options.
1672 if (tokenPos(tclass.opt_fontsize(), '|', params.fontsize) >= 0) {
1673 // only write if existing in list (and not default)
1674 options += params.fontsize;
1679 if (!params.use_geometry &&
1680 (params.paperpackage == BufferParams::PACKAGE_NONE)) {
1681 switch (params.papersize) {
1682 case BufferParams::PAPER_A4PAPER:
1683 options += "a4paper,";
1685 case BufferParams::PAPER_USLETTER:
1686 options += "letterpaper,";
1688 case BufferParams::PAPER_A5PAPER:
1689 options += "a5paper,";
1691 case BufferParams::PAPER_B5PAPER:
1692 options += "b5paper,";
1694 case BufferParams::PAPER_EXECUTIVEPAPER:
1695 options += "executivepaper,";
1697 case BufferParams::PAPER_LEGALPAPER:
1698 options += "legalpaper,";
1704 if (params.sides != tclass.sides()) {
1705 switch (params.sides) {
1706 case LyXTextClass::OneSide:
1707 options += "oneside,";
1709 case LyXTextClass::TwoSides:
1710 options += "twoside,";
1717 if (params.columns != tclass.columns()) {
1718 if (params.columns == 2)
1719 options += "twocolumn,";
1721 options += "onecolumn,";
1724 if (!params.use_geometry
1725 && params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1726 options += "landscape,";
1728 // language should be a parameter to \documentclass
1729 bool use_babel = false;
1730 if (params.language != "default" ||
1731 !features.UsedLanguages.empty() ) {
1733 for (LaTeXFeatures::LanguageList::const_iterator cit =
1734 features.UsedLanguages.begin();
1735 cit != features.UsedLanguages.end(); ++cit) {
1736 options += (*cit)->lang + ",";
1738 if (default_language != params.language_info)
1739 options += default_language ->lang + ',';
1740 options += params.language_info->lang + ',';
1743 // the user-defined options
1744 if (!params.options.empty()) {
1745 options += params.options + ',';
1748 if (!options.empty()){
1749 options = strip(options, ',');
1750 ofs << '[' << options << ']';
1754 << textclasslist.LatexnameOfClass(params.textclass)
1757 // end of \documentclass defs
1759 // font selection must be done before loading fontenc.sty
1760 if (params.fonts != "default") {
1761 ofs << "\\usepackage{" << params.fonts << "}\n";
1764 // this one is not per buffer
1765 if (lyxrc.fontenc != "default") {
1766 ofs << "\\usepackage[" << lyxrc.fontenc
1770 if (params.inputenc != "default") {
1771 ofs << "\\usepackage[" << params.inputenc
1776 /* at the very beginning the text parameters */
1777 if (params.paperpackage != BufferParams::PACKAGE_NONE) {
1778 switch (params.paperpackage) {
1779 case BufferParams::PACKAGE_A4:
1780 ofs << "\\usepackage{a4}\n";
1783 case BufferParams::PACKAGE_A4WIDE:
1784 ofs << "\\usepackage{a4wide}\n";
1787 case BufferParams::PACKAGE_WIDEMARGINSA4:
1788 ofs << "\\usepackage[widemargins]{a4}\n";
1793 if (params.use_geometry) {
1794 ofs << "\\usepackage{geometry}\n";
1796 ofs << "\\geometry{verbose";
1797 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1798 ofs << ",landscape";
1799 switch (params.papersize2) {
1800 case BufferParams::VM_PAPER_CUSTOM:
1801 if (!params.paperwidth.empty())
1802 ofs << ",paperwidth="
1803 << params.paperwidth;
1804 if (!params.paperheight.empty())
1805 ofs << ",paperheight="
1806 << params.paperheight;
1808 case BufferParams::VM_PAPER_USLETTER:
1809 ofs << ",letterpaper";
1811 case BufferParams::VM_PAPER_USLEGAL:
1812 ofs << ",legalpaper";
1814 case BufferParams::VM_PAPER_USEXECUTIVE:
1815 ofs << ",executivepaper";
1817 case BufferParams::VM_PAPER_A3:
1820 case BufferParams::VM_PAPER_A4:
1823 case BufferParams::VM_PAPER_A5:
1826 case BufferParams::VM_PAPER_B3:
1829 case BufferParams::VM_PAPER_B4:
1832 case BufferParams::VM_PAPER_B5:
1836 // default papersize ie BufferParams::VM_PAPER_DEFAULT
1837 switch (lyxrc.default_papersize) {
1838 case BufferParams::PAPER_DEFAULT: // keep compiler happy
1839 case BufferParams::PAPER_USLETTER:
1840 ofs << ",letterpaper";
1842 case BufferParams::PAPER_LEGALPAPER:
1843 ofs << ",legalpaper";
1845 case BufferParams::PAPER_EXECUTIVEPAPER:
1846 ofs << ",executivepaper";
1848 case BufferParams::PAPER_A3PAPER:
1851 case BufferParams::PAPER_A4PAPER:
1854 case BufferParams::PAPER_A5PAPER:
1857 case BufferParams::PAPER_B5PAPER:
1862 if (!params.topmargin.empty())
1863 ofs << ",tmargin=" << params.topmargin;
1864 if (!params.bottommargin.empty())
1865 ofs << ",bmargin=" << params.bottommargin;
1866 if (!params.leftmargin.empty())
1867 ofs << ",lmargin=" << params.leftmargin;
1868 if (!params.rightmargin.empty())
1869 ofs << ",rmargin=" << params.rightmargin;
1870 if (!params.headheight.empty())
1871 ofs << ",headheight=" << params.headheight;
1872 if (!params.headsep.empty())
1873 ofs << ",headsep=" << params.headsep;
1874 if (!params.footskip.empty())
1875 ofs << ",footskip=" << params.footskip;
1879 if (params.use_amsmath
1880 && !prefixIs(textclasslist.LatexnameOfClass(params.textclass), "ams")) {
1881 ofs << "\\usepackage{amsmath}\n";
1885 if (tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle) >= 0) {
1886 if (params.pagestyle == "fancy") {
1887 ofs << "\\usepackage{fancyhdr}\n";
1890 ofs << "\\pagestyle{" << params.pagestyle << "}\n";
1894 // We try to load babel late, in case it interferes
1895 // with other packages.
1897 ofs << lyxrc.language_package << endl;
1901 if (params.secnumdepth != tclass.secnumdepth()) {
1902 ofs << "\\setcounter{secnumdepth}{"
1903 << params.secnumdepth
1907 if (params.tocdepth != tclass.tocdepth()) {
1908 ofs << "\\setcounter{tocdepth}{"
1914 if (params.paragraph_separation) {
1915 switch (params.defskip.kind()) {
1916 case VSpace::SMALLSKIP:
1917 ofs << "\\setlength\\parskip{\\smallskipamount}\n";
1919 case VSpace::MEDSKIP:
1920 ofs << "\\setlength\\parskip{\\medskipamount}\n";
1922 case VSpace::BIGSKIP:
1923 ofs << "\\setlength\\parskip{\\bigskipamount}\n";
1925 case VSpace::LENGTH:
1926 ofs << "\\setlength\\parskip{"
1927 << params.defskip.length().asLatexString()
1930 default: // should never happen // Then delete it.
1931 ofs << "\\setlength\\parskip{\\medskipamount}\n";
1936 ofs << "\\setlength\\parindent{0pt}\n";
1940 // Now insert the LyX specific LaTeX commands...
1941 string preamble, tmppreamble;
1943 // The optional packages;
1944 preamble = features.getPackages(params);
1946 // this might be useful...
1947 preamble += "\n\\makeatletter\n\n";
1949 // Some macros LyX will need
1950 tmppreamble = features.getMacros(params);
1952 if (!tmppreamble.empty()) {
1953 preamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1954 "LyX specific LaTeX commands.\n"
1955 + tmppreamble + '\n';
1958 // the text class specific preamble
1959 tmppreamble = features.getTClassPreamble(params);
1960 if (!tmppreamble.empty()) {
1961 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1962 "Textclass specific LaTeX commands.\n"
1963 + tmppreamble + '\n';
1966 /* the user-defined preamble */
1967 if (!params.preamble.empty()) {
1968 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1969 "User specified LaTeX commands.\n"
1970 + params.preamble + '\n';
1973 preamble += "\\makeatother\n\n";
1975 // Itemize bullet settings need to be last in case the user
1976 // defines their own bullets that use a package included
1977 // in the user-defined preamble -- ARRae
1978 // Actually it has to be done much later than that
1979 // since some packages like frenchb make modifications
1980 // at \begin{document} time -- JMarc
1982 for (int i = 0; i < 4; ++i) {
1983 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
1984 if (bullets_def.empty())
1985 bullets_def="\\AtBeginDocument{\n";
1986 bullets_def += " \\renewcommand{\\labelitemi";
1988 // `i' is one less than the item to modify
1995 bullets_def += "ii";
2001 bullets_def += "}{" +
2002 params.user_defined_bullets[i].getText()
2007 if (!bullets_def.empty())
2008 preamble += bullets_def + "}\n\n";
2010 for (int j = countChar(preamble, '\n'); j-- ;) {
2017 ofs << "\\begin{document}\n\n";
2021 lyxerr.debug() << "preamble finished, now the body." << endl;
2022 if (!lyxrc.language_auto_begin && params.language != "default") {
2023 ofs << subst(lyxrc.language_command_begin, "$$lang",
2029 bool was_title = false;
2030 bool already_title = false;
2032 ostringstream ftnote;
2034 char * tmpholder = 0;
2039 LyXParagraph * par = paragraph;
2043 #ifndef HAVE_SSTREAM
2046 ftnote << tmpholder;
2047 delete [] tmpholder;
2052 lyxerr[Debug::LATEX] << "Error in MakeLateXFile."
2054 LyXLayout const & layout =
2055 textclasslist.Style(params.textclass,
2058 if (layout.intitle) {
2059 if (already_title) {
2060 lyxerr <<"Error in MakeLatexFile: You"
2061 " should not mix title layouts"
2062 " with normal ones." << endl;
2065 } else if (was_title && !already_title) {
2066 ofs << "\\maketitle\n";
2068 already_title = true;
2071 // We are at depth 0 so we can just use
2072 // ordinary \footnote{} generation
2073 // flag this with ftcount
2075 if (layout.isEnvironment()
2076 || par->pextra_type != LyXParagraph::PEXTRA_NONE) {
2077 par = par->TeXEnvironment(ofs, texrow,
2078 ftnote, ft_texrow, ftcount);
2080 par = par->TeXOnePar(ofs, texrow,
2081 ftnote, ft_texrow, ftcount);
2084 // Write out what we've generated...
2087 ofs << "\\addtocounter{footnote}{-"
2091 ofs << ftnote.str();
2092 texrow += ft_texrow;
2094 // The extra .c_str() is needed when we use
2095 // lyxstring instead of the STL string class.
2096 ftnote.str(string().c_str());
2098 delete [] ftnote.str();
2103 #ifndef HAVE_SSTREAM
2105 // I hate strstreams
2106 tmpholder = ftnote.str();
2110 #ifndef HAVE_SSTREAM
2111 delete [] tmpholder;
2113 // It might be that we only have a title in this document
2114 if (was_title && !already_title) {
2115 ofs << "\\maketitle\n";
2119 if (!lyxrc.language_auto_end && params.language != "default") {
2120 ofs << subst(lyxrc.language_command_end, "$$lang",
2127 ofs << "\\end{document}\n";
2130 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
2132 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
2136 // Just to be sure. (Asger)
2139 // tex_code_break_column's value is used to decide
2140 // if we are in batchmode or not (within mathed_write()
2141 // in math_write.C) so we must set it to a non-zero
2142 // value when we leave otherwise we save incorrect .lyx files.
2143 tex_code_break_column = lyxrc.ascii_linelen;
2147 lyxerr << "File was not closed properly." << endl;
2150 lyxerr.debug() << "Finished making latex file." << endl;
2154 bool Buffer::isLatex() const
2156 return textclasslist.TextClass(params.textclass).outputType() == LATEX;
2160 bool Buffer::isLinuxDoc() const
2162 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC;
2166 bool Buffer::isLiterate() const
2168 return textclasslist.TextClass(params.textclass).outputType() == LITERATE;
2172 bool Buffer::isDocBook() const
2174 return textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2178 bool Buffer::isSGML() const
2180 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC ||
2181 textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2185 void Buffer::sgmlOpenTag(ostream & os, int depth,
2186 string const & latexname) const
2188 os << string(depth, ' ') << "<" << latexname << ">\n";
2192 void Buffer::sgmlCloseTag(ostream & os, int depth,
2193 string const & latexname) const
2195 os << string(depth, ' ') << "</" << latexname << ">\n";
2199 void Buffer::makeLinuxDocFile(string const & fname, int column)
2201 LyXParagraph * par = paragraph;
2203 string top_element = textclasslist.LatexnameOfClass(params.textclass);
2204 string environment_stack[10];
2207 int depth = 0; /* paragraph depth */
2209 ofstream ofs(fname.c_str());
2212 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2216 tex_code_break_column = column;
2219 if (params.preamble.empty()) {
2220 ofs << "<!doctype linuxdoc system>\n\n";
2223 ofs << "<!doctype linuxdoc system \n [ "
2224 << params.preamble << " \n]>\n\n";
2227 ofs << "<!-- " << LYX_DOCVERSION
2228 << " created this file. For more info see http://www.lyx.org/"
2231 if(params.options.empty())
2232 sgmlOpenTag(ofs, 0, top_element);
2234 string top = top_element;
2236 top += params.options;
2237 sgmlOpenTag(ofs, 0, top);
2241 int desc_on = 0; /* description mode*/
2242 LyXLayout const & style =
2243 textclasslist.Style(users->buffer()->params.textclass,
2245 par->AutoDeleteInsets();
2247 /* treat <toc> as a special case for compatibility with old code */
2248 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2249 Inset * inset = par->GetInset(0);
2250 char lyx_code = inset->LyxCode();
2251 if (lyx_code == Inset::TOC_CODE){
2252 string temp = "toc";
2253 sgmlOpenTag(ofs, depth, temp);
2256 linuxDocHandleFootnote(ofs, par, depth);
2261 // environment tag closing
2262 for( ; depth > par->depth; --depth) {
2263 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2264 environment_stack[depth].clear();
2267 // write opening SGML tags
2268 switch(style.latextype) {
2269 case LATEX_PARAGRAPH:
2270 if(depth == par->depth
2271 && !environment_stack[depth].empty()) {
2272 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2273 environment_stack[depth].clear();
2279 sgmlOpenTag(ofs, depth, style.latexname());
2284 LinuxDocError(par, 0, _("Error : Wrong depth for LatexType Command.\n"));
2286 if (!environment_stack[depth].empty()){
2287 sgmlCloseTag(ofs, depth,
2288 environment_stack[depth]);
2292 environment_stack[depth].clear();
2293 sgmlOpenTag(ofs, depth, style.latexname());
2296 case LATEX_ENVIRONMENT:
2297 case LATEX_ITEM_ENVIRONMENT:
2298 if(depth == par->depth
2299 && environment_stack[depth] != style.latexname()
2300 && !environment_stack[depth].empty()) {
2302 sgmlCloseTag(ofs, depth,
2303 environment_stack[depth]);
2304 environment_stack[depth].clear();
2306 if (depth < par->depth) {
2308 environment_stack[depth].clear();
2310 if (environment_stack[depth] != style.latexname()) {
2313 sgmlOpenTag(ofs, depth, temp);
2315 environment_stack[depth] = style.latexname();
2316 sgmlOpenTag(ofs, depth, environment_stack[depth]);
2318 if(style.latextype == LATEX_ENVIRONMENT) break;
2320 desc_on = (style.labeltype == LABEL_MANUAL);
2327 sgmlOpenTag(ofs, depth + 1, item_name);
2330 sgmlOpenTag(ofs, depth, style.latexname());
2335 SimpleLinuxDocOnePar(ofs, par, desc_on, depth);
2338 linuxDocHandleFootnote(ofs, par, depth);
2340 while(par && par->IsDummy());
2343 /* write closing SGML tags */
2344 switch(style.latextype) {
2346 case LATEX_ENVIRONMENT:
2347 case LATEX_ITEM_ENVIRONMENT:
2350 sgmlCloseTag(ofs, depth, style.latexname());
2355 /* Close open tags */
2356 for(; depth > 0; --depth)
2357 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2359 if(!environment_stack[depth].empty())
2360 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2363 sgmlCloseTag(ofs, 0, top_element);
2366 // How to check for successful close
2370 void Buffer::linuxDocHandleFootnote(ostream & os, LyXParagraph * & par,
2373 string tag = "footnote";
2375 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2376 sgmlOpenTag(os, depth + 1, tag);
2377 SimpleLinuxDocOnePar(os, par, 0, depth + 1);
2378 sgmlCloseTag(os, depth + 1, tag);
2384 void Buffer::DocBookHandleCaption(ostream & os, string & inner_tag,
2385 int const depth, int desc_on,
2386 LyXParagraph * & par)
2388 LyXParagraph * tpar = par;
2389 while (tpar && (tpar->footnoteflag != LyXParagraph::NO_FOOTNOTE) &&
2390 (tpar->layout != textclasslist.NumberOfLayout(params.textclass,
2394 tpar->layout == textclasslist.NumberOfLayout(params.textclass,
2395 "Caption").second) {
2396 sgmlOpenTag(os, depth + 1, inner_tag);
2398 SimpleDocBookOnePar(os, extra_par, tpar,
2399 desc_on, depth + 2);
2400 sgmlCloseTag(os, depth+1, inner_tag);
2401 if(!extra_par.empty())
2407 void Buffer::DocBookHandleFootnote(ostream & os, LyXParagraph * & par,
2410 string tag, inner_tag;
2411 string tmp_par, extra_par;
2412 bool inner_span = false;
2415 // Someone should give this enum a proper name (Lgb)
2423 SOME_ENUM last = NO_ONE;
2424 SOME_ENUM present = FOOTNOTE_LIKE;
2426 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2427 if(last == present) {
2429 if(!tmp_par.empty()) {
2432 sgmlCloseTag(os, depth + 1, inner_tag);
2433 sgmlOpenTag(os, depth + 1, inner_tag);
2440 if(!inner_tag.empty()) sgmlCloseTag(os, depth + 1,
2442 if(!extra_par.empty()) os << extra_par;
2443 if(!tag.empty()) sgmlCloseTag(os, depth, tag);
2446 switch (par->footnotekind) {
2447 case LyXParagraph::FOOTNOTE:
2448 case LyXParagraph::ALGORITHM:
2451 present = FOOTNOTE_LIKE;
2454 case LyXParagraph::MARGIN:
2457 present = MARGIN_LIKE;
2460 case LyXParagraph::FIG:
2461 case LyXParagraph::WIDE_FIG:
2463 inner_tag = "title";
2467 case LyXParagraph::TAB:
2468 case LyXParagraph::WIDE_TAB:
2470 inner_tag = "title";
2475 sgmlOpenTag(os, depth, tag);
2476 if ((present == TAB_LIKE) || (present == FIG_LIKE)) {
2477 DocBookHandleCaption(os, inner_tag, depth,
2481 sgmlOpenTag(os, depth + 1, inner_tag);
2484 // ignore all caption here, we processed them above!!!
2485 if (par->layout != textclasslist
2486 .NumberOfLayout(params.textclass,
2487 "Caption").second) {
2493 SimpleDocBookOnePar(ost, extra_par, par,
2494 desc_on, depth + 2);
2496 tmp_par += ost.str().c_str();
2499 char * ctmp = ost.str();
2504 tmp_par = frontStrip(strip(tmp_par));
2510 if(!inner_tag.empty()) sgmlCloseTag(os, depth + 1, inner_tag);
2511 if(!extra_par.empty()) os << extra_par;
2512 if(!tag.empty()) sgmlCloseTag(os, depth, tag);
2516 /* push a tag in a style stack */
2517 void Buffer::push_tag(ostream & os, char const * tag,
2518 int & pos, char stack[5][3])
2520 /* pop all previous tags */
2521 for (int j = pos; j >= 0; --j)
2522 os << "</" << stack[j] << ">";
2525 sprintf(stack[++pos], "%s", tag);
2528 for (int i = 0; i <= pos; ++i)
2529 os << "<" << stack[i] << ">";
2532 void Buffer::pop_tag(ostream & os, char const * tag,
2533 int & pos, char stack[5][3])
2537 // pop all tags till specified one
2538 for (j = pos; (j >= 0) && (strcmp(stack[j], tag)); --j)
2539 os << "</" << stack[j] << ">";
2542 os << "</" << tag << ">";
2544 // push all tags, but the specified one
2545 for (j = j + 1; j <= pos; ++j) {
2546 os << "<" << stack[j] << ">";
2547 strcpy(stack[j-1], stack[j]);
2553 /* handle internal paragraph parsing -- layout already processed */
2555 // checks, if newcol chars should be put into this line
2556 // writes newline, if necessary.
2558 void linux_doc_line_break(ostream & os, unsigned int & colcount,
2559 const unsigned int newcol)
2562 if (colcount > lyxrc.ascii_linelen) {
2564 colcount = newcol; // assume write after this call
2569 void Buffer::SimpleLinuxDocOnePar(ostream & os, LyXParagraph * par,
2570 int desc_on, int const /*depth*/)
2572 LyXFont font1, font2;
2575 LyXParagraph::size_type main_body;
2577 LyXLayout const & style = textclasslist.Style(params.textclass,
2580 char family_type = 0; // family font flag
2581 bool is_bold = false; // series font flag
2582 char shape_type = 0; // shape font flag
2583 bool is_em = false; // emphasis (italic) font flag
2585 int stack_num = -1; // style stack position
2586 char stack[5][3]; // style stack
2587 unsigned int char_line_count = 5; // Heuristic choice ;-)
2589 if (style.labeltype != LABEL_MANUAL)
2592 main_body = par->BeginningOfMainBody();
2594 /* gets paragraph main font */
2596 font1 = style.labelfont;
2601 /* parsing main loop */
2602 for (LyXParagraph::size_type i = 0;
2603 i < par->size(); ++i) {
2605 /* handle quote tag */
2606 if (i == main_body && !par->IsDummy()) {
2611 font2 = par->getFont(i);
2613 if (font1.family() != font2.family()) {
2614 switch(family_type) {
2616 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2617 push_tag(os, "tt", stack_num, stack);
2620 else if (font2.family() == LyXFont::SANS_FAMILY) {
2621 push_tag(os, "sf", stack_num, stack);
2626 pop_tag(os, "tt", stack_num, stack);
2627 if (font2.family() == LyXFont::SANS_FAMILY) {
2628 push_tag(os, "sf", stack_num, stack);
2636 pop_tag(os, "sf", stack_num, stack);
2637 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2638 push_tag(os, "tt", stack_num, stack);
2647 /* handle bold face */
2648 if (font1.series() != font2.series()) {
2649 if (font2.series() == LyXFont::BOLD_SERIES) {
2650 push_tag(os, "bf", stack_num, stack);
2654 pop_tag(os, "bf", stack_num, stack);
2659 /* handle italic and slanted fonts */
2660 if (font1.shape() != font2.shape()) {
2661 switch(shape_type) {
2663 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2664 push_tag(os, "it", stack_num, stack);
2667 else if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2668 push_tag(os, "sl", stack_num, stack);
2673 pop_tag(os, "it", stack_num, stack);
2674 if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2675 push_tag(os, "sl", stack_num, stack);
2683 pop_tag(os, "sl", stack_num, stack);
2684 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2685 push_tag(os, "it", stack_num, stack);
2693 /* handle <em> tag */
2694 if (font1.emph() != font2.emph()) {
2695 if (font2.emph() == LyXFont::ON) {
2696 push_tag(os, "em", stack_num, stack);
2699 pop_tag(os, "em", stack_num, stack);
2704 c = par->GetChar(i);
2706 if (font2.latex() == LyXFont::ON) {
2707 // "TeX"-Mode on == > SGML-Mode on.
2709 os << c; // see LaTeX-Generation...
2711 } else if (c == LyXParagraph::META_INSET) {
2712 inset = par->GetInset(i);
2713 inset->Linuxdoc(os);
2716 if (par->linuxDocConvertChar(c, sgml_string)
2717 && !style.free_spacing) { // in freespacing
2719 // non-breaking characters
2723 linux_doc_line_break(os, char_line_count, 6);
2728 linux_doc_line_break(os, char_line_count, 1);
2734 char_line_count += sgml_string.length();
2740 /* needed if there is an optional argument but no contents */
2741 if (main_body > 0 && main_body == par->size()) {
2745 /* pop all defined Styles */
2746 for (j = stack_num; j >= 0; --j) {
2747 linux_doc_line_break(os,
2749 3 + strlen(stack[j]));
2750 os << "</" << stack[j] << ">";
2753 /* resets description flag correctly */
2756 /* <tag> not closed... */
2757 linux_doc_line_break(os, char_line_count, 6);
2761 /* fprintf(file, "</p>");*/
2767 /* print an error message */
2768 void Buffer::LinuxDocError(LyXParagraph * par, int pos,
2769 char const * message)
2771 InsetError * new_inset;
2773 /* insert an error marker in text */
2774 new_inset = new InsetError(message);
2775 par->InsertChar(pos, LyXParagraph::META_INSET);
2776 par->InsertInset(pos, new_inset);
2779 // This constant defines the maximum number of
2780 // environment layouts that can be nesteded.
2781 // The same applies for command layouts.
2782 // These values should be more than enough.
2783 // José Matos (1999/07/22)
2785 enum { MAX_NEST_LEVEL = 25};
2787 void Buffer::makeDocBookFile(string const & fname, int column)
2789 LyXParagraph * par = paragraph;
2791 string top_element= textclasslist.LatexnameOfClass(params.textclass);
2792 string environment_stack[MAX_NEST_LEVEL];
2793 string environment_inner[MAX_NEST_LEVEL];
2794 string command_stack[MAX_NEST_LEVEL];
2795 bool command_flag= false;
2796 int command_depth= 0, command_base= 0, cmd_depth= 0;
2798 string item_name, command_name;
2799 string c_depth, c_params, tmps;
2801 int depth= 0; /* paragraph depth */
2803 tex_code_break_column = column;
2805 ofstream ofs(fname.c_str());
2807 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2813 ofs << "<!doctype " << top_element
2814 << " public \"-//OASIS//DTD DocBook V3.1//EN\"";
2816 if (params.preamble.empty())
2819 ofs << "\n [ " << params.preamble << " \n]>\n\n";
2821 ofs << "<!-- DocBook file was created by " << LYX_DOCVERSION
2822 << "\n See http://www.lyx.org/ for more information -->\n";
2824 if(params.options.empty())
2825 sgmlOpenTag(ofs, 0, top_element);
2827 string top = top_element;
2829 top += params.options;
2830 sgmlOpenTag(ofs, 0, top);
2834 int desc_on = 0; /* description mode*/
2835 LyXLayout const & style =
2836 textclasslist.Style(users->buffer()->params.textclass,
2838 par->AutoDeleteInsets();
2840 /* environment tag closing */
2841 for( ; depth > par->depth; --depth) {
2842 if(environment_inner[depth] != "!-- --") {
2843 item_name= "listitem";
2844 sgmlCloseTag(ofs, command_depth + depth,
2846 if( environment_inner[depth] == "varlistentry")
2847 sgmlCloseTag(ofs, depth+command_depth,
2848 environment_inner[depth]);
2850 sgmlCloseTag(ofs, depth + command_depth,
2851 environment_stack[depth]);
2852 environment_stack[depth].clear();
2853 environment_inner[depth].clear();
2856 if(depth == par->depth
2857 && environment_stack[depth] != style.latexname()
2858 && !environment_stack[depth].empty()) {
2859 if(environment_inner[depth] != "!-- --") {
2860 item_name= "listitem";
2861 sgmlCloseTag(ofs, command_depth+depth,
2863 if( environment_inner[depth] == "varlistentry")
2865 depth + command_depth,
2866 environment_inner[depth]);
2869 sgmlCloseTag(ofs, depth + command_depth,
2870 environment_stack[depth]);
2872 environment_stack[depth].clear();
2873 environment_inner[depth].clear();
2876 // Write opening SGML tags.
2877 switch(style.latextype) {
2878 case LATEX_PARAGRAPH:
2879 if(style.latexname() != "dummy")
2880 sgmlOpenTag(ofs, depth+command_depth,
2886 LinuxDocError(par, 0,
2887 _("Error : Wrong depth for "
2888 "LatexType Command.\n"));
2890 command_name = style.latexname();
2892 tmps = style.latexparam();
2893 c_params = split(tmps, c_depth,'|');
2895 cmd_depth= atoi(c_depth.c_str());
2898 if(cmd_depth<command_base) {
2899 for(int j = command_depth;
2900 j >= command_base; --j)
2901 if(!command_stack[j].empty())
2902 sgmlCloseTag(ofs, j, command_stack[j]);
2903 command_depth= command_base= cmd_depth;
2905 else if(cmd_depth <= command_depth) {
2906 for(int j = command_depth;
2907 j >= cmd_depth; --j)
2909 if(!command_stack[j].empty())
2910 sgmlCloseTag(ofs, j, command_stack[j]);
2911 command_depth= cmd_depth;
2914 command_depth= cmd_depth;
2917 command_depth = command_base = cmd_depth;
2918 command_flag = true;
2920 command_stack[command_depth]= command_name;
2922 // treat label as a special case for
2923 // more WYSIWYM handling.
2924 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2925 Inset * inset = par->GetInset(0);
2926 char lyx_code = inset->LyxCode();
2927 if (lyx_code == Inset::LABEL_CODE){
2928 command_name += " id=\"";
2929 command_name += (static_cast<InsetCommand *>(inset))->getContents();
2930 command_name += "\"";
2935 sgmlOpenTag(ofs, depth+command_depth, command_name);
2936 item_name = "title";
2937 sgmlOpenTag(ofs, depth + 1 + command_depth, item_name);
2940 case LATEX_ENVIRONMENT:
2941 case LATEX_ITEM_ENVIRONMENT:
2942 if (depth < par->depth) {
2944 environment_stack[depth].clear();
2947 if (environment_stack[depth] != style.latexname()) {
2948 environment_stack[depth] = style.latexname();
2949 environment_inner[depth] = "!-- --";
2950 sgmlOpenTag(ofs, depth + command_depth,
2951 environment_stack[depth]);
2953 if(environment_inner[depth] != "!-- --") {
2954 item_name= "listitem";
2956 command_depth + depth,
2958 if (environment_inner[depth] == "varlistentry")
2960 depth + command_depth,
2961 environment_inner[depth]);
2965 if(style.latextype == LATEX_ENVIRONMENT) {
2966 if(!style.latexparam().empty())
2967 sgmlOpenTag(ofs, depth + command_depth,
2968 style.latexparam());
2972 desc_on = (style.labeltype == LABEL_MANUAL);
2975 environment_inner[depth]= "varlistentry";
2977 environment_inner[depth]= "listitem";
2979 sgmlOpenTag(ofs, depth + 1 + command_depth,
2980 environment_inner[depth]);
2984 sgmlOpenTag(ofs, depth + 1 + command_depth,
2989 sgmlOpenTag(ofs, depth + 1 + command_depth,
2994 sgmlOpenTag(ofs, depth + command_depth,
3001 SimpleDocBookOnePar(ofs, extra_par, par, desc_on,
3002 depth + 1 + command_depth);
3004 DocBookHandleFootnote(ofs, par,
3005 depth + 1 + command_depth);
3007 while(par && par->IsDummy());
3010 /* write closing SGML tags */
3011 switch(style.latextype) {
3014 sgmlCloseTag(ofs, depth + command_depth, end_tag);
3016 case LATEX_ENVIRONMENT:
3017 if(!style.latexparam().empty())
3018 sgmlCloseTag(ofs, depth + command_depth,
3019 style.latexparam());
3021 case LATEX_ITEM_ENVIRONMENT:
3022 if(desc_on == 1) break;
3024 sgmlCloseTag(ofs, depth + 1 + command_depth, end_tag);
3026 case LATEX_PARAGRAPH:
3027 if(style.latexname() != "dummy")
3028 sgmlCloseTag(ofs, depth + command_depth,
3032 sgmlCloseTag(ofs, depth + command_depth,
3039 for(; depth >= 0; --depth) {
3040 if(!environment_stack[depth].empty()) {
3041 if(environment_inner[depth] != "!-- --") {
3042 item_name= "listitem";
3043 sgmlCloseTag(ofs, command_depth + depth,
3045 if( environment_inner[depth] == "varlistentry")
3046 sgmlCloseTag(ofs, depth + command_depth,
3047 environment_inner[depth]);
3050 sgmlCloseTag(ofs, depth + command_depth,
3051 environment_stack[depth]);
3055 for(int j = command_depth; j >= command_base; --j)
3056 if(!command_stack[j].empty())
3057 sgmlCloseTag(ofs, j, command_stack[j]);
3060 sgmlCloseTag(ofs, 0, top_element);
3063 // How to check for successful close
3067 void Buffer::SimpleDocBookOnePar(ostream & os, string & extra,
3068 LyXParagraph * par, int & desc_on,
3072 par->SimpleDocBookOneTablePar(os, extra, desc_on, depth);
3076 bool emph_flag = false;
3078 LyXLayout const & style = textclasslist.Style(params.textclass,
3081 LyXParagraph::size_type main_body;
3082 if (style.labeltype != LABEL_MANUAL)
3085 main_body = par->BeginningOfMainBody();
3087 // gets paragraph main font
3088 //if (main_body > 0)
3089 // font1 = style.labelfont;
3091 // font1 = style.font;
3092 LyXFont font1 = main_body > 0 ? style.labelfont : style.font;
3094 int char_line_count = depth;
3095 if(!style.free_spacing)
3096 for (int j = 0; j < depth; ++j)
3099 // parsing main loop
3100 for (LyXParagraph::size_type i = 0;
3101 i < par->size(); ++i) {
3102 LyXFont font2 = par->getFont(i);
3104 // handle <emphasis> tag
3105 if (font1.emph() != font2.emph() && i) {
3106 if (font2.emph() == LyXFont::ON) {
3110 os << "</emphasis>";
3115 char c = par->GetChar(i);
3117 if (c == LyXParagraph::META_INSET) {
3118 Inset * inset = par->GetInset(i);
3121 inset->DocBook(ost);
3122 string tmp_out = ost.str().c_str();
3125 inset->DocBook(ost);
3127 char * ctmp = ost.str();
3128 string tmp_out(ctmp);
3132 // This code needs some explanation:
3133 // Two insets are treated specially
3134 // label if it is the first element in a command paragraph
3136 // graphics inside tables or figure floats can't go on
3137 // title (the equivalente in latex for this case is caption
3138 // and title should come first
3141 if(desc_on!= 3 || i!= 0) {
3142 if(!tmp_out.empty() && tmp_out[0] == '@') {
3144 extra += frontStrip(tmp_out, '@');
3146 os << frontStrip(tmp_out, '@');
3151 } else if (font2.latex() == LyXFont::ON) {
3152 // "TeX"-Mode on ==> SGML-Mode on.
3159 if (par->linuxDocConvertChar(c, sgml_string)
3160 && !style.free_spacing) { // in freespacing
3162 // non-breaking characters
3166 os << "\n</term><listitem><para>";
3180 /* needed if there is an optional argument but no contents */
3181 if (main_body > 0 && main_body == par->size()) {
3185 os << "</emphasis>";
3188 /* resets description flag correctly */
3191 /* <term> not closed... */
3199 int Buffer::runLaTeX()
3201 if (!users->text) return 0;
3205 // get LaTeX-Filename
3206 string name = getLatexName();
3208 string path = OnlyPath(filename);
3210 string org_path = path;
3211 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3215 Path p(path); // path to LaTeX file
3216 users->owner()->getMiniBuffer()->Set(_("Running LaTeX..."));
3218 // Remove all error insets
3219 bool a = users->removeAutoInsets();
3221 // Always generate the LaTeX file
3222 makeLaTeXFile(name, org_path, false);
3225 // do the LaTex run(s)
3227 string latex_command = lyxrc.pdf_mode ?
3228 lyxrc.pdflatex_command : lyxrc.latex_command;
3229 LaTeX latex(latex_command, name, filepath);
3230 int res = latex.run(terr,
3231 users->owner()->getMiniBuffer()); // running latex
3233 // check return value from latex.run().
3234 if ((res & LaTeX::NO_LOGFILE)) {
3235 WriteAlert(_("LaTeX did not work!"),
3236 _("Missing log file:"), name);
3237 } else if ((res & LaTeX::ERRORS)) {
3238 users->owner()->getMiniBuffer()->Set(_("Done"));
3239 // Insert all errors as errors boxes
3240 users->insertErrors(terr);
3242 // Dvi should also be kept dirty if the latex run
3243 // ends up with errors. However it should be possible
3244 // to view a dirty dvi too.
3246 //no errors or any other things to think about so:
3247 users->owner()->getMiniBuffer()->Set(_("Done"));
3251 // if we removed error insets before we ran LaTeX or if we inserted
3252 // error insets after we ran LaTeX this must be run:
3253 if (a || (res & LaTeX::ERRORS)){
3256 users->updateScrollbar();
3260 return latex.getNumErrors();
3264 int Buffer::runLiterate()
3266 if (!users->text) return 0;
3270 // get LaTeX-Filename
3271 string name = getLatexName();
3272 // get Literate-Filename
3273 string lit_name = ChangeExtension (getLatexName(),
3274 lyxrc.literate_extension, true);
3276 string path = OnlyPath(filename);
3278 string org_path = path;
3279 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3283 Path p(path); // path to Literate file
3284 users->owner()->getMiniBuffer()->Set(_("Running Literate..."));
3286 // Remove all error insets
3287 bool a = users->removeAutoInsets();
3289 // generate the Literate file if necessary
3290 if (!isDviClean() || a) {
3291 makeLaTeXFile(lit_name, org_path, false);
3295 string latex_command = lyxrc.pdf_mode ?
3296 lyxrc.pdflatex_command : lyxrc.latex_command;
3297 Literate literate(latex_command, name, filepath,
3299 lyxrc.literate_command, lyxrc.literate_error_filter,
3300 lyxrc.build_command, lyxrc.build_error_filter);
3302 int res = literate.weave(terr, users->owner()->getMiniBuffer());
3304 // check return value from literate.weave().
3305 if ((res & Literate::NO_LOGFILE)) {
3306 WriteAlert(_("Literate command did not work!"),
3307 _("Missing log file:"), name);
3308 } else if ((res & Literate::ERRORS)) {
3309 users->owner()->getMiniBuffer()->Set(_("Done"));
3310 // Insert all errors as errors boxes
3311 users->insertErrors(terr);
3313 // Dvi should also be kept dirty if the latex run
3314 // ends up with errors. However it should be possible
3315 // to view a dirty dvi too.
3317 //no errors or any other things to think about so:
3318 users->owner()->getMiniBuffer()->Set(_("Done"));
3322 // if we removed error insets before we ran LaTeX or if we inserted
3323 // error insets after we ran LaTeX this must be run:
3324 if (a || (res & Literate::ERRORS)){
3327 users->updateScrollbar();
3331 return literate.getNumErrors();
3335 int Buffer::buildProgram()
3337 if (!users->text) return 0;
3341 // get LaTeX-Filename
3342 string name = getLatexName();
3343 // get Literate-Filename
3344 string lit_name = ChangeExtension(getLatexName(),
3345 lyxrc.literate_extension, true);
3347 string path = OnlyPath(filename);
3349 string org_path = path;
3350 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3354 Path p(path); // path to Literate file
3355 users->owner()->getMiniBuffer()->Set(_("Building Program..."));
3357 // Remove all error insets
3358 bool a = users->removeAutoInsets();
3360 // generate the LaTeX file if necessary
3361 if (!isNwClean() || a) {
3362 makeLaTeXFile(lit_name, org_path, false);
3366 string latex_command = lyxrc.pdf_mode ?
3367 lyxrc.pdflatex_command : lyxrc.latex_command;
3368 Literate literate(latex_command, name, filepath,
3370 lyxrc.literate_command, lyxrc.literate_error_filter,
3371 lyxrc.build_command, lyxrc.build_error_filter);
3373 int res = literate.build(terr, users->owner()->getMiniBuffer());
3375 // check return value from literate.build().
3376 if ((res & Literate::NO_LOGFILE)) {
3377 WriteAlert(_("Build did not work!"),
3378 _("Missing log file:"), name);
3379 } else if ((res & Literate::ERRORS)) {
3380 users->owner()->getMiniBuffer()->Set(_("Done"));
3381 // Insert all errors as errors boxes
3382 users->insertErrors(terr);
3384 // Literate files should also be kept dirty if the literate
3385 // command run ends up with errors.
3387 //no errors or any other things to think about so:
3388 users->owner()->getMiniBuffer()->Set(_("Done"));
3392 // if we removed error insets before we ran Literate/Build or if we inserted
3393 // error insets after we ran Literate/Build this must be run:
3394 if (a || (res & Literate::ERRORS)){
3397 users->updateScrollbar();
3401 return literate.getNumErrors();
3405 // This should be enabled when the Chktex class is implemented. (Asger)
3406 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
3407 // Other flags: -wall -v0 -x
3408 int Buffer::runChktex()
3410 if (!users->text) return 0;
3414 // get LaTeX-Filename
3415 string name = getLatexName();
3416 string path = OnlyPath(filename);
3418 string org_path = path;
3419 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3423 Path p(path); // path to LaTeX file
3424 users->owner()->getMiniBuffer()->Set(_("Running chktex..."));
3426 // Remove all error insets
3427 bool a = users->removeAutoInsets();
3429 // Generate the LaTeX file if neccessary
3430 if (!isDviClean() || a) {
3431 makeLaTeXFile(name, org_path, false);
3436 Chktex chktex(lyxrc.chktex_command, name, filepath);
3437 int res = chktex.run(terr); // run chktex
3440 WriteAlert(_("chktex did not work!"),
3441 _("Could not run with file:"), name);
3442 } else if (res > 0) {
3443 // Insert all errors as errors boxes
3444 users->insertErrors(terr);
3447 // if we removed error insets before we ran chktex or if we inserted
3448 // error insets after we ran chktex, this must be run:
3452 users->updateScrollbar();
3461 void Buffer::RoffAsciiTable(ostream & os, LyXParagraph * par)
3463 LyXFont font1(LyXFont::ALL_INHERIT,params.language_info);
3466 LyXParagraph::size_type i;
3470 string fname1 = TmpFileName(string(), "RAT1");
3471 string fname2 = TmpFileName(string(), "RAT2");
3473 ofstream ofs(fname1.c_str());
3475 WriteAlert(_("LYX_ERROR:"),
3476 _("Cannot open temporary file:"), fname1);
3479 par->table->RoffEndOfCell(ofs, -1);
3480 for (i = 0; i < par->size(); ++i) {
3481 c = par->GetChar(i);
3482 if (par->table->IsContRow(cell)) {
3483 if (c == LyXParagraph::META_NEWLINE)
3487 font2 = par->GetFontSettings(i);
3488 if (font1.latex() != font2.latex()) {
3489 if (font2.latex() != LyXFont::OFF)
3493 case LyXParagraph::META_INSET:
3494 if ((inset = par->GetInset(i))) {
3497 stringstresm ss(ios::in | ios::out);
3498 inset->Latex(ss, -1);
3510 inset->Latex(ss, -1);
3523 fstream fs(fname2.c_str(), ios::in|ios::out);
3525 WriteAlert(_("LYX_ERROR:"),
3526 _("Cannot open temporary file:"), fname2);
3528 remove(fname1.c_str());
3531 inset->Latex(fs, -1);
3545 case LyXParagraph::META_NEWLINE:
3546 if (par->table->CellHasContRow(cell)>= 0)
3547 par->RoffContTableRows(ofs, i+1, cell);
3548 par->table->RoffEndOfCell(ofs, cell);
3551 case LyXParagraph::META_HFILL:
3554 case LyXParagraph::META_PROTECTED_SEPARATOR:
3565 << "RoffAsciiTable:"
3566 " NULL char in structure." << endl;
3570 par->table->RoffEndOfCell(ofs, cell);
3572 string cmd = lyxrc.ascii_roff_command + " >" + fname2;
3573 cmd = subst(cmd, "$$FName", fname1);
3574 Systemcalls one(Systemcalls::System, cmd);
3575 if (!(lyxerr.debugging(Debug::ROFF))) {
3576 remove(fname1.c_str());
3578 ifstream ifs(fname2.c_str());
3580 WriteFSAlert(_("Error! Can't open temporary file:"), fname2);
3583 // now output the produced file
3587 WriteAlert(_("Error!"),
3588 _("Error executing *roff command on table"));
3589 // overread leading blank lines
3590 while(!ifs && (c == '\n'))
3593 for(j = 0; j < par->depth; ++j)
3595 while(!ifs && (c != '\n')) {
3600 // overread trailing blank lines
3601 while(!ifs && (c == '\n'))
3605 remove(fname2.c_str());
3610 /// changed Heinrich Bauer, 23/03/98
3611 bool Buffer::isDviClean() const
3613 if (lyxrc.use_tempdir)
3614 return dvi_clean_tmpd;
3616 return dvi_clean_orgd;
3620 /// changed Heinrich Bauer, 23/03/98
3621 void Buffer::markDviClean()
3623 if (lyxrc.use_tempdir)
3624 dvi_clean_tmpd = true;
3626 dvi_clean_orgd = true;
3630 /// changed Heinrich Bauer, 23/03/98
3631 void Buffer::markDviDirty()
3633 if (lyxrc.use_tempdir)
3634 dvi_clean_tmpd = false;
3636 dvi_clean_orgd = false;
3640 void Buffer::validate(LaTeXFeatures & features) const
3642 LyXParagraph * par = paragraph;
3643 LyXTextClass const & tclass =
3644 textclasslist.TextClass(params.textclass);
3646 // AMS Style is at document level
3648 features.amsstyle = (params.use_amsmath ||
3649 tclass.provides(LyXTextClass::amsmath));
3652 // We don't use "lyxerr.debug" because of speed. (Asger)
3653 if (lyxerr.debugging(Debug::LATEX))
3654 lyxerr << "Paragraph: " << par << endl;
3656 // Now just follow the list of paragraphs and run
3657 // validate on each of them.
3658 par->validate(features);
3660 // and then the next paragraph
3664 // the bullet shapes are buffer level not paragraph level
3665 // so they are tested here
3666 for (int i = 0; i < 4; ++i) {
3667 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
3668 int font = params.user_defined_bullets[i].getFont();
3671 .user_defined_bullets[i]
3678 features.latexsym = true;
3682 features.amssymb = true;
3684 else if ((font >= 2 && font <= 5)) {
3685 features.pifont = true;
3690 if (lyxerr.debugging(Debug::LATEX)) {
3691 features.showStruct(params);
3696 void Buffer::setPaperStuff()
3698 params.papersize = BufferParams::PAPER_DEFAULT;
3699 char c1 = params.paperpackage;
3700 if (c1 == BufferParams::PACKAGE_NONE) {
3701 char c2 = params.papersize2;
3702 if (c2 == BufferParams::VM_PAPER_USLETTER)
3703 params.papersize = BufferParams::PAPER_USLETTER;
3704 else if (c2 == BufferParams::VM_PAPER_USLEGAL)
3705 params.papersize = BufferParams::PAPER_LEGALPAPER;
3706 else if (c2 == BufferParams::VM_PAPER_USEXECUTIVE)
3707 params.papersize = BufferParams::PAPER_EXECUTIVEPAPER;
3708 else if (c2 == BufferParams::VM_PAPER_A3)
3709 params.papersize = BufferParams::PAPER_A3PAPER;
3710 else if (c2 == BufferParams::VM_PAPER_A4)
3711 params.papersize = BufferParams::PAPER_A4PAPER;
3712 else if (c2 == BufferParams::VM_PAPER_A5)
3713 params.papersize = BufferParams::PAPER_A5PAPER;
3714 else if ((c2 == BufferParams::VM_PAPER_B3) || (c2 == BufferParams::VM_PAPER_B4) ||
3715 (c2 == BufferParams::VM_PAPER_B5))
3716 params.papersize = BufferParams::PAPER_B5PAPER;
3717 } else if ((c1 == BufferParams::PACKAGE_A4) || (c1 == BufferParams::PACKAGE_A4WIDE) ||
3718 (c1 == BufferParams::PACKAGE_WIDEMARGINSA4))
3719 params.papersize = BufferParams::PAPER_A4PAPER;
3723 // This function should be in Buffer because it's a buffer's property (ale)
3724 string Buffer::getIncludeonlyList(char delim)
3727 LyXParagraph * par = paragraph;
3728 LyXParagraph::size_type pos;
3732 while ((inset = par->ReturnNextInsetPointer(pos))){
3733 if (inset->LyxCode() == Inset::INCLUDE_CODE) {
3734 InsetInclude * insetinc =
3735 static_cast<InsetInclude*>(inset);
3736 if (insetinc->isInclude()
3737 && insetinc->isNoLoad()) {
3740 lst += ChangeExtension(insetinc->getContents(), string(), true);
3747 lyxerr.debug() << "Includeonly(" << lst << ')' << endl;
3752 // This is also a buffer property (ale)
3753 string Buffer::getReferenceList(char delim)
3755 /// if this is a child document and the parent is already loaded
3756 /// Use the parent's list instead [ale990407]
3757 if (!params.parentname.empty()
3758 && bufferlist.exists(params.parentname)) {
3759 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3761 return tmp->getReferenceList(delim);
3764 LyXParagraph * par = paragraph;
3765 LyXParagraph::size_type pos;
3770 while ((inset = par->ReturnNextInsetPointer(pos))){
3771 for (int i = 0; i < inset->GetNumberOfLabels(); ++i) {
3774 lst += inset->getLabel(i);
3780 lyxerr.debug() << "References(" << lst << ")" << endl;
3785 // This is also a buffer property (ale)
3786 string Buffer::getBibkeyList(char delim)
3788 /// if this is a child document and the parent is already loaded
3789 /// Use the parent's list instead [ale990412]
3790 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3791 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3793 return tmp->getBibkeyList(delim);
3797 LyXParagraph * par = paragraph;
3800 if (!bibkeys.empty())
3802 bibkeys += par->bibkey->getContents();
3807 // Might be either using bibtex or a child has bibliography
3808 if (bibkeys.empty()) {
3812 LyXParagraph::size_type pos = -1;
3814 // Search for Bibtex or Include inset
3815 while ((inset = par->ReturnNextInsetPointer(pos))) {
3816 if (inset-> LyxCode() == Inset::BIBTEX_CODE) {
3817 if (!bibkeys.empty())
3819 bibkeys += static_cast<InsetBibtex*>(inset)->getKeys(delim);
3820 } else if (inset-> LyxCode() == Inset::INCLUDE_CODE) {
3821 string bk = static_cast<InsetInclude*>(inset)->getKeys(delim);
3823 if (!bibkeys.empty())
3834 lyxerr.debug() << "Bibkeys(" << bibkeys << ")" << endl;
3839 bool Buffer::isDepClean(string const & name) const
3841 DEPCLEAN * item = dep_clean;
3842 while (item && item->master != name)
3844 if (!item) return true;
3849 void Buffer::markDepClean(string const & name)
3852 dep_clean = new DEPCLEAN;
3853 dep_clean->clean = true;
3854 dep_clean->master = name;
3855 dep_clean->next = 0;
3857 DEPCLEAN* item = dep_clean;
3858 while (item && item->master != name)
3863 item = new DEPCLEAN;
3865 item->master = name;
3872 void Buffer::Dispatch(string const & command)
3874 // Split command string into command and argument
3875 string cmd, line = frontStrip(command);
3876 string arg = strip(frontStrip(split(line, cmd, ' ')));
3878 Dispatch(lyxaction.LookupFunc(cmd.c_str()), arg.c_str());
3882 void Buffer::Dispatch(int action, string const & argument)
3886 MenuExport(this, argument);
3890 lyxerr << "A truly unknown func!" << endl;