1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2000 The LyX Team.
9 * This file is Copyright 1996-1999
12 * ======================================================
17 // 23/03/98 Heinrich Bauer (heinrich.bauer@t-mobil.de)
18 // Spots marked "changed Heinrich Bauer, 23/03/98" modified due to the
19 // following bug: dvi file export did not work after printing (or previewing)
20 // and vice versa as long as the same file was concerned. This happened
21 // every time the LyX-file was left unchanged between the two actions mentioned
31 #include <sys/types.h>
35 #pragma implementation "buffer.h"
39 #include "bufferlist.h"
41 #include "lyx_gui_misc.h"
42 #include "LyXAction.h"
45 #include "tex-strings.h"
47 #include "bufferview_funcs.h"
48 #include "minibuffer.h"
51 #include "mathed/formulamacro.h"
52 #include "insets/lyxinset.h"
53 #include "insets/inseterror.h"
54 #include "insets/insetlabel.h"
55 #include "insets/insetref.h"
56 #include "insets/inseturl.h"
57 #include "insets/insetinfo.h"
58 #include "insets/insetquotes.h"
59 #include "insets/insetlatexaccent.h"
60 #include "insets/insetbib.h"
61 #include "insets/insetindex.h"
62 #include "insets/insetinclude.h"
63 #include "insets/insettoc.h"
64 #include "insets/insetlof.h"
65 #include "insets/insetlot.h"
66 #include "insets/insetloa.h"
67 #include "insets/insetparent.h"
68 #include "insets/insetspecialchar.h"
69 #include "insets/figinset.h"
70 #include "insets/insettext.h"
71 #include "insets/insetert.h"
72 #include "insets/insetgraphics.h"
73 #include "insets/insetfoot.h"
74 #include "insets/insettabular.h"
75 #include "support/filetools.h"
76 #include "support/path.h"
82 #include "LaTeXFeatures.h"
83 #include "support/syscall.h"
84 #include "support/lyxlib.h"
85 #include "support/FileInfo.h"
100 // all these externs should eventually be removed.
101 extern BufferList bufferlist;
103 extern void MenuExport(Buffer *, string const &);
104 extern LyXAction lyxaction;
107 static const float LYX_FORMAT = 2.16;
109 extern int tex_code_break_column;
112 Buffer::Buffer(string const & file, bool ronly)
114 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
116 filepath = OnlyPath(file);
120 dvi_clean_orgd = false; // Heinrich Bauer, 23/03/98
121 dvi_clean_tmpd = false; // Heinrich Bauer, 23/03/98
126 if (read_only || (lyxrc.use_tempdir)) {
127 tmppath = CreateBufferTmpDir();
128 } else tmppath.erase();
134 lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
135 // here the buffer should take care that it is
136 // saved properly, before it goes into the void.
138 // make sure that views using this buffer
143 if (!tmppath.empty()) {
144 DestroyBufferTmpDir(tmppath);
147 LyXParagraph * par = paragraph;
148 LyXParagraph * tmppar;
158 string Buffer::getLatexName(bool no_path) const
160 return ChangeExtension(MakeLatexName(filename),
165 void Buffer::setReadonly(bool flag)
167 if (read_only != flag) {
170 updateAllVisibleBufferRelatedPopups();
173 WarnReadonly(filename);
178 bool Buffer::saveParamsAsDefaults()
180 string fname = AddName(AddPath(user_lyxdir, "templates/"),
182 Buffer defaults = Buffer(fname);
184 // Use the current buffer's parameters as default
185 defaults.params = params;
187 // add an empty paragraph. Is this enough?
188 defaults.paragraph = new LyXParagraph;
190 return defaults.writeFile(defaults.filename, false);
194 /// Update window titles of all users
195 // Should work on a list
196 void Buffer::updateTitles() const
198 if (users) users->owner()->updateWindowTitle();
202 /// Reset autosave timer of all users
203 // Should work on a list
204 void Buffer::resetAutosaveTimers() const
206 if (users) users->owner()->resetAutosaveTimer();
210 void Buffer::fileName(string const & newfile)
212 filename = MakeAbsPath(newfile);
213 filepath = OnlyPath(filename);
214 setReadonly(IsFileWriteable(filename) == 0);
219 // candidate for move to BufferView
220 // (at least some parts in the beginning of the func)
223 // changed to be public and have one parameter
224 // if par = 0 normal behavior
225 // else insert behavior
226 // Returns false if "\the_end" is not read for formats >= 2.13. (Asger)
227 #define USE_PARSE_FUNCTION 1
228 bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par)
232 char depth = 0; // signed or unsigned?
233 LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
234 LyXParagraph::footnote_kind footnotekind = LyXParagraph::FOOTNOTE;
235 bool the_end_read = false;
237 LyXParagraph * return_par = 0;
238 LyXFont font(LyXFont::ALL_INHERIT, params.language_info);
239 if (format < 2.16 && params.language == "hebrew")
240 font.setLanguage(default_language);
242 // If we are inserting, we cheat and get a token in advance
243 bool has_token = false;
247 par = new LyXParagraph;
249 users->text->BreakParagraph();
250 return_par = users->text->FirstParagraph();
253 // We don't want to adopt the parameters from the
254 // document we insert, so we skip until the text begins:
257 pretoken = lex.GetString();
258 if (pretoken == "\\layout") {
270 pretoken = lex.GetString();
273 // Profiling show this should give a lot: (Asger)
274 string const token = pretoken;
278 the_end_read = parseSingleLyXformat2Token(lex, par, return_par,
287 paragraph = return_par;
294 Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
295 LyXParagraph *& return_par,
296 string const & token, int & pos,
297 char & depth, LyXFont & font,
298 LyXParagraph::footnote_flag & footnoteflag,
299 LyXParagraph::footnote_kind & footnotekind)
301 bool the_end_read = false;
303 if (token[0] != '\\') {
304 for (string::const_iterator cit = token.begin();
305 cit != token.end(); ++cit) {
306 par->InsertChar(pos, (*cit));
307 par->SetFont(pos, font);
310 } else if (token == "\\i") {
311 Inset * inset = new InsetLatexAccent;
313 par->InsertChar(pos, LyXParagraph::META_INSET);
314 par->InsertInset(pos, inset);
315 par->SetFont(pos, font);
317 } else if (token == "\\layout") {
322 par = new LyXParagraph(par);
326 string layoutname = lex.GetString();
327 pair<bool, LyXTextClass::LayoutList::size_type> pp
328 = textclasslist.NumberOfLayout(params.textclass,
331 par->layout = pp.second;
332 } else { // layout not found
333 // use default layout "Standard" (0)
336 // Test whether the layout is obsolete.
337 LyXLayout const & layout =
338 textclasslist.Style(params.textclass,
340 if (!layout.obsoleted_by().empty())
342 textclasslist.NumberOfLayout(params.textclass,
343 layout.obsoleted_by()).second;
344 par->footnoteflag = footnoteflag;
345 par->footnotekind = footnotekind;
347 font = LyXFont(LyXFont::ALL_INHERIT, params.language_info);
348 if (format < 2.16 && params.language == "hebrew")
349 font.setLanguage(default_language);
350 } else if (token == "\\end_float") {
355 par = new LyXParagraph(par);
357 footnotekind = LyXParagraph::FOOTNOTE;
358 footnoteflag = LyXParagraph::NO_FOOTNOTE;
361 par->layout = LYX_DUMMY_LAYOUT;
362 font = LyXFont(LyXFont::ALL_INHERIT, params.language_info);
363 if (format < 2.16 && params.language == "hebrew")
364 font.setLanguage(default_language);
365 } else if (token == "\\begin_float") {
366 int tmpret = lex.FindToken(string_footnotekinds);
367 if (tmpret == -1) ++tmpret;
368 if (tmpret != LYX_LAYOUT_DEFAULT)
369 footnotekind = static_cast<LyXParagraph::footnote_kind>(tmpret); // bad
370 if (footnotekind == LyXParagraph::FOOTNOTE
371 || footnotekind == LyXParagraph::MARGIN)
372 footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
374 footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
375 } else if (token == "\\begin_deeper") {
377 } else if (token == "\\end_deeper") {
379 lex.printError("\\end_deeper: "
380 "depth is already null");
384 } else if (token == "\\begin_preamble") {
385 params.readPreamble(lex);
386 } else if (token == "\\textclass") {
388 pair<bool, LyXTextClassList::size_type> pp =
389 textclasslist.NumberOfClass(lex.GetString());
391 params.textclass = pp.second;
393 lex.printError("Unknown textclass `$$Token'");
394 params.textclass = 0;
396 if (!textclasslist.Load(params.textclass)) {
397 // if the textclass wasn't loaded properly
398 // we need to either substitute another
399 // or stop loading the file.
400 // I can substitute but I don't see how I can
401 // stop loading... ideas?? ARRae980418
402 WriteAlert(_("Textclass Loading Error!"),
403 string(_("Can't load textclass ")) +
404 textclasslist.NameOfClass(params.textclass),
405 _("-- substituting default"));
406 params.textclass = 0;
408 } else if (token == "\\options") {
410 params.options = lex.GetString();
411 } else if (token == "\\language") {
412 params.readLanguage(lex);
413 } else if (token == "\\fontencoding") {
415 } else if (token == "\\inputencoding") {
417 params.inputenc = lex.GetString();
418 } else if (token == "\\graphics") {
419 params.readGraphicsDriver(lex);
420 } else if (token == "\\fontscheme") {
422 params.fonts = lex.GetString();
423 } else if (token == "\\noindent") {
424 par->noindent = true;
425 } else if (token == "\\fill_top") {
426 par->added_space_top = VSpace(VSpace::VFILL);
427 } else if (token == "\\fill_bottom") {
428 par->added_space_bottom = VSpace(VSpace::VFILL);
429 } else if (token == "\\line_top") {
430 par->line_top = true;
431 } else if (token == "\\line_bottom") {
432 par->line_bottom = true;
433 } else if (token == "\\pagebreak_top") {
434 par->pagebreak_top = true;
435 } else if (token == "\\pagebreak_bottom") {
436 par->pagebreak_bottom = true;
437 } else if (token == "\\start_of_appendix") {
438 par->start_of_appendix = true;
439 } else if (token == "\\paragraph_separation") {
440 int tmpret = lex.FindToken(string_paragraph_separation);
441 if (tmpret == -1) ++tmpret;
442 if (tmpret != LYX_LAYOUT_DEFAULT)
443 params.paragraph_separation =
444 static_cast<BufferParams::PARSEP>(tmpret);
445 } else if (token == "\\defskip") {
447 params.defskip = VSpace(lex.GetString());
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 int 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 int tmpret = lex.FindToken(string_papersize);
496 params.papersize2 = tmpret;
497 } else if (token == "\\paperpackage") {
498 int 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 int 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();
608 } else if (token == "\\baselinestretch") { // obsolete
609 lex.nextToken(); // should not be used directly
611 // Will probably keep a kind of support just for
613 params.spacing.set(Spacing::Other, lex.GetFloat());
615 } else if (token == "\\spacing") {
617 string tmp = strip(lex.GetString());
618 Spacing::Space tmp_space = Spacing::Default;
620 if (tmp == "single") {
621 tmp_space = Spacing::Single;
622 } else if (tmp == "onehalf") {
623 tmp_space = Spacing::Onehalf;
624 } else if (tmp == "double") {
625 tmp_space = Spacing::Double;
626 } else if (tmp == "other") {
628 tmp_space = Spacing::Other;
629 tmp_val = lex.GetFloat();
631 lex.printError("Unknown spacing token: '$$Token'");
633 // Small hack so that files written with klyx will be
636 par->spacing.set(tmp_space, tmp_val);
638 params.spacing.set(tmp_space, tmp_val);
640 } else if (token == "\\paragraph_spacing") {
642 string tmp = strip(lex.GetString());
643 if (tmp == "single") {
644 par->spacing.set(Spacing::Single);
645 } else if (tmp == "onehalf") {
646 par->spacing.set(Spacing::Onehalf);
647 } else if (tmp == "double") {
648 par->spacing.set(Spacing::Double);
649 } else if (tmp == "other") {
651 par->spacing.set(Spacing::Other,
654 lex.printError("Unknown spacing token: '$$Token'");
656 } else if (token == "\\float_placement") {
658 params.float_placement = lex.GetString();
660 } else if (token == "\\cursor") { // obsolete
661 // this is obsolete, so we just skip it.
664 } else if (token == "\\family") {
666 font.setLyXFamily(lex.GetString());
667 } else if (token == "\\series") {
669 font.setLyXSeries(lex.GetString());
670 } else if (token == "\\shape") {
672 font.setLyXShape(lex.GetString());
673 } else if (token == "\\size") {
675 font.setLyXSize(lex.GetString());
676 } else if (token == "\\latex") {
678 string tok = lex.GetString();
679 // This is dirty, but gone with LyX3. (Asger)
680 if (tok == "no_latex")
681 font.setLatex(LyXFont::OFF);
682 else if (tok == "latex")
683 font.setLatex(LyXFont::ON);
684 else if (tok == "default")
685 font.setLatex(LyXFont::INHERIT);
687 lex.printError("Unknown LaTeX font flag "
689 } else if (token == "\\lang") {
691 string tok = lex.GetString();
692 Languages::iterator lit = languages.find(tok);
693 if (lit != languages.end()) {
694 font.setLanguage(&(*lit).second);
696 font.setLanguage(params.language_info);
697 lex.printError("Unknown language `$$Token'");
699 } else if (token == "\\emph") {
701 font.setEmph(font.setLyXMisc(lex.GetString()));
702 } else if (token == "\\bar") {
704 string tok = lex.GetString();
705 // This is dirty, but gone with LyX3. (Asger)
707 font.setUnderbar(LyXFont::ON);
708 else if (tok == "no")
709 font.setUnderbar(LyXFont::OFF);
710 else if (tok == "default")
711 font.setUnderbar(LyXFont::INHERIT);
713 lex.printError("Unknown bar font flag "
715 } else if (token == "\\noun") {
717 font.setNoun(font.setLyXMisc(lex.GetString()));
718 } else if (token == "\\color") {
720 font.setLyXColor(lex.GetString());
721 } else if (token == "\\align") {
722 int tmpret = lex.FindToken(string_align);
723 if (tmpret == -1) ++tmpret;
724 if (tmpret != LYX_LAYOUT_DEFAULT) { // tmpret != 99 ???
726 for (; tmpret > 0; --tmpret)
727 tmpret2 = tmpret2 * 2;
728 par->align = LyXAlignment(tmpret2);
730 } else if (token == "\\added_space_top") {
732 par->added_space_top = VSpace(lex.GetString());
733 } else if (token == "\\added_space_bottom") {
735 par->added_space_bottom = VSpace(lex.GetString());
736 } else if (token == "\\pextra_type") {
738 par->pextra_type = lex.GetInteger();
739 } else if (token == "\\pextra_width") {
741 par->pextra_width = lex.GetString();
742 } else if (token == "\\pextra_widthp") {
744 par->pextra_widthp = lex.GetString();
745 } else if (token == "\\pextra_alignment") {
747 par->pextra_alignment = lex.GetInteger();
748 } else if (token == "\\pextra_hfill") {
750 par->pextra_hfill = lex.GetInteger();
751 } else if (token == "\\pextra_start_minipage") {
753 par->pextra_start_minipage = lex.GetInteger();
754 } else if (token == "\\labelwidthstring") {
756 par->labelwidthstring = lex.GetString();
757 // do not delete this token, it is still needed!
758 } else if (token == "\\end_inset") {
759 // Simply ignore this. The insets do not have
761 // But insets should read it, it is a part of
762 // the inset isn't it? Lgb.
763 } else if (token == "\\begin_inset") {
764 // Should be moved out into its own function/method. (Lgb)
766 string tmptok = lex.GetString();
767 // test the different insets
768 if (tmptok == "Quotes") {
769 Inset * inset = new InsetQuotes;
771 par->InsertChar(pos, LyXParagraph::META_INSET);
772 par->InsertInset(pos, inset);
773 par->SetFont(pos, font);
776 } else if (tmptok == "\\i") {
777 Inset * inset = new InsetLatexAccent;
779 par->InsertChar(pos, LyXParagraph::META_INSET);
780 par->InsertInset(pos, inset);
781 par->SetFont(pos, font);
784 } else if (tmptok == "FormulaMacro") {
785 Inset * inset = new InsetFormulaMacro;
787 par->InsertChar(pos, LyXParagraph::META_INSET);
788 par->InsertInset(pos, inset);
789 par->SetFont(pos, font);
791 } else if (tmptok == "Formula") {
792 Inset * inset = new InsetFormula;
794 par->InsertChar(pos, LyXParagraph::META_INSET);
795 par->InsertInset(pos, inset);
796 par->SetFont(pos, font);
798 } else if (tmptok == "Figure") {
799 Inset * inset = new InsetFig(100, 100, this);
801 par->InsertChar(pos, LyXParagraph::META_INSET);
802 par->InsertInset(pos, inset);
803 par->SetFont(pos, font);
805 } else if (tmptok == "Info") {
806 Inset * inset = new InsetInfo;
808 par->InsertChar(pos, LyXParagraph::META_INSET);
809 par->InsertInset(pos, inset);
810 par->SetFont(pos, font);
812 } else if (tmptok == "Include") {
813 Inset * inset = new InsetInclude(string(), this);
815 par->InsertChar(pos, LyXParagraph::META_INSET);
816 par->InsertInset(pos, inset);
817 par->SetFont(pos, font);
819 } else if (tmptok == "ERT") {
820 Inset * inset = new InsetERT(this);
822 par->InsertChar(pos, LyXParagraph::META_INSET);
823 par->InsertInset(pos, inset);
824 par->SetFont(pos, font);
826 } else if (tmptok == "Tabular") {
827 Inset * inset = new InsetTabular(this);
829 par->InsertChar(pos, LyXParagraph::META_INSET);
830 par->InsertInset(pos, inset);
831 par->SetFont(pos, font);
833 } else if (tmptok == "Text") {
834 Inset * inset = new InsetText(this);
836 par->InsertChar(pos, LyXParagraph::META_INSET);
837 par->InsertInset(pos, inset);
838 par->SetFont(pos, font);
840 } else if (tmptok == "Foot") {
841 Inset * inset = new InsetFoot(this);
843 par->InsertChar(pos, LyXParagraph::META_INSET);
844 par->InsertInset(pos, inset);
845 par->SetFont(pos, font);
847 } else if (tmptok == "GRAPHICS") {
848 Inset * inset = new InsetGraphics;
850 par->InsertChar(pos, LyXParagraph::META_INSET);
851 par->InsertInset(pos, inset);
852 par->SetFont(pos, font);
853 } else if (tmptok == "LatexCommand") {
857 if (inscmd.getCmdName() == "cite") {
858 inset = new InsetCitation(inscmd.getContents(), inscmd.getOptions());
859 } else if (inscmd.getCmdName() == "bibitem") {
860 lex.printError("Wrong place for bibitem");
861 inset = inscmd.Clone();
862 } else if (inscmd.getCmdName() == "BibTeX") {
863 inset = new InsetBibtex(inscmd.getContents(), inscmd.getOptions(), this);
864 } else if (inscmd.getCmdName() == "index") {
865 inset = new InsetIndex(inscmd.getContents());
866 } else if (inscmd.getCmdName() == "include") {
867 inset = new InsetInclude(inscmd.getContents(), this);
868 } else if (inscmd.getCmdName() == "label") {
869 inset = new InsetLabel(inscmd.getCommand());
870 } else if (inscmd.getCmdName() == "url"
871 || inscmd.getCmdName() == "htmlurl") {
872 inset = new InsetUrl(inscmd.getCommand());
873 } else if (inscmd.getCmdName() == "ref"
874 || inscmd.getCmdName() == "pageref") {
875 if (!inscmd.getOptions().empty() || !inscmd.getContents().empty()) {
876 inset = new InsetRef(inscmd, this);
878 // CHECK if this else clause
879 //is still needed. (Lgb)
881 // This condition comes from a
882 // temporary solution to the latexdel
883 // ref inset that was transformed to
884 // an empty ref inset plus the body
885 // surronded by latexdel insets
887 string cont, opt, tmptmptok, cmdname;
889 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
894 tmptmptok = lex.GetString();
895 if(tmptmptok[0] == '\\') {
896 if( tmptmptok == "\\backslash")
906 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
911 tmptmptok = lex.GetString();
912 if(tmptmptok[0] == '\\') {
913 if( tmptmptok == "\\backslash")
923 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
929 cmdname = "\\" + inscmd.getCmdName();
930 cmdname += "[" + cont + "]";
931 cmdname += "{" + opt + "}";
932 inset = new InsetRef(cmdname, this);
935 } else if (inscmd.getCmdName() == "tableofcontents") {
936 inset = new InsetTOC(this);
937 } else if (inscmd.getCmdName() == "listoffigures") {
938 inset = new InsetLOF(this);
939 } else if (inscmd.getCmdName() == "listofalgorithms") {
940 inset = new InsetLOA(this);
941 } else if (inscmd.getCmdName() == "listoftables") {
942 inset = new InsetLOT(this);
943 } else if (inscmd.getCmdName() == "printindex") {
944 inset = new InsetPrintIndex(this);
945 } else if (inscmd.getCmdName() == "lyxparent") {
946 inset = new InsetParent(inscmd.getContents(), this);
950 par->InsertChar(pos, LyXParagraph::META_INSET);
951 par->InsertInset(pos, inset);
952 par->SetFont(pos, font);
957 } else if (token == "\\InsetQuotes") {
958 lyxerr << "InsetQuotes" << endl;
959 Inset * inset = new InsetQuotes;
961 par->InsertChar(pos, LyXParagraph::META_INSET);
962 par->InsertInset(pos, inset);
963 par->SetFont(pos, font);
967 } else if (token == "\\InsetFormula") {
968 lyxerr << "InsetFormula" << endl;
969 Inset * inset = new InsetFormula;
971 par->InsertChar(pos, LyXParagraph::META_INSET);
972 par->InsertInset(pos, inset);
973 par->SetFont(pos, font);
976 } else if (token == "\\SpecialChar") {
977 LyXLayout const & layout =
978 textclasslist.Style(params.textclass,
981 // Insets don't make sense in a free-spacing context! ---Kayvan
982 if (layout.free_spacing) {
986 next_token = lex.GetString();
987 if (next_token == "\\-") {
988 par->InsertChar(pos, '-');
989 par->SetFont(pos, font);
990 } else if (next_token == "\\protected_separator"
991 || next_token == "~") {
992 par->InsertChar(pos, ' ');
993 par->SetFont(pos, font);
995 lex.printError("Token `$$Token' "
997 "paragraph layout!");
1002 Inset * inset = new InsetSpecialChar;
1004 par->InsertChar(pos, LyXParagraph::META_INSET);
1005 par->InsertInset(pos, inset);
1006 par->SetFont(pos, font);
1010 } else if (token == "\\Figure") {
1011 lyxerr << "Figure" << endl;
1012 Inset * inset = new InsetFig(100, 100, this);
1014 par->InsertChar(pos, LyXParagraph::META_INSET);
1015 par->InsertInset(pos, inset);
1016 par->SetFont(pos, font);
1019 } else if (token == "\\newline") {
1020 par->InsertChar(pos, LyXParagraph::META_NEWLINE);
1021 par->SetFont(pos, font);
1023 } else if (token == "\\LyXTable") {
1024 par->table = new LyXTable(lex);
1025 } else if (token == "\\hfill") {
1026 par->InsertChar(pos, LyXParagraph::META_HFILL);
1027 par->SetFont(pos, font);
1029 } else if (token == "\\protected_separator") { // obsolete
1030 // This is a backward compability thingie. (Lgb)
1031 // Remove it later some time...introduced with fileformat
1033 LyXLayout const & layout =
1034 textclasslist.Style(params.textclass,
1037 if (layout.free_spacing) {
1038 par->InsertChar(pos, ' ');
1039 par->SetFont(pos, font);
1041 Inset * inset = new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
1042 par->InsertChar(pos, LyXParagraph::META_INSET);
1043 par->InsertInset(pos, inset);
1044 par->SetFont(pos, font);
1047 } else if (token == "\\bibitem") { // ale970302
1049 par->bibkey = new InsetBibKey;
1050 par->bibkey->Read(lex);
1051 }else if (token == "\\backslash") {
1052 par->InsertChar(pos, '\\');
1053 par->SetFont(pos, font);
1055 }else if (token == "\\the_end") {
1056 the_end_read = true;
1058 // This should be insurance for the future: (Asger)
1059 lex.printError("Unknown token `$$Token'. "
1060 "Inserting as text.");
1061 for(string::const_iterator cit = token.begin();
1062 cit != token.end(); ++cit) {
1063 par->InsertChar(pos, (*cit));
1064 par->SetFont(pos, font);
1068 return the_end_read;
1071 bool Buffer::readFile(LyXLex & lex, LyXParagraph * par)
1077 token = lex.GetString();
1078 if (token == "\\lyxformat") { // the first token _must_ be...
1080 format = lex.GetFloat();
1082 if (LYX_FORMAT - format > 0.05) {
1083 printf(_("Warning: need lyxformat %.2f but found %.2f\n"),
1084 LYX_FORMAT, format);
1086 if (format - LYX_FORMAT > 0.05) {
1087 printf(_("ERROR: need lyxformat %.2f but found %.2f\n"),
1088 LYX_FORMAT, format);
1090 bool the_end = readLyXformat2(lex, par);
1091 // Formats >= 2.13 support "\the_end" marker
1098 WriteAlert(_("Warning!"),
1099 _("Reading of document is not complete"),
1100 _("Maybe the document is truncated"));
1101 // We simulate a safe reading anyways to allow
1102 // users to take the chance... (Asger)
1106 WriteAlert(_("ERROR!"),
1107 _("Old LyX file format found. "
1108 "Use LyX 0.10.x to read this!"));
1112 } else { // "\\lyxformat" not found
1113 WriteAlert(_("ERROR!"), _("Not a LyX file!"));
1116 WriteAlert(_("ERROR!"), _("Unable to read file!"));
1122 // Should probably be moved to somewhere else: BufferView? LyXView?
1123 bool Buffer::save() const
1125 // We don't need autosaves in the immediate future. (Asger)
1126 resetAutosaveTimers();
1130 if (lyxrc.make_backup) {
1131 s = fileName() + '~';
1132 if (!lyxrc.backupdir_path.empty())
1133 s = AddName(lyxrc.backupdir_path,
1134 subst(CleanupPath(s),'/','!'));
1136 // Rename is the wrong way of making a backup,
1137 // this is the correct way.
1138 /* truss cp fil fil2:
1139 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
1140 stat("LyXVC.lyx", 0xEFFFF688) = 0
1141 open("LyXVC.lyx", O_RDONLY) = 3
1142 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
1143 fstat(4, 0xEFFFF508) = 0
1144 fstat(3, 0xEFFFF508) = 0
1145 read(3, " # T h i s f i l e w".., 8192) = 5579
1146 write(4, " # T h i s f i l e w".., 5579) = 5579
1147 read(3, 0xEFFFD4A0, 8192) = 0
1150 chmod("LyXVC3.lyx", 0100644) = 0
1151 lseek(0, 0, SEEK_CUR) = 46440
1155 // Should proabaly have some more error checking here.
1156 // Should be cleaned up in 0.13, at least a bit.
1157 // Doing it this way, also makes the inodes stay the same.
1158 // This is still not a very good solution, in particular we
1159 // might loose the owner of the backup.
1160 FileInfo finfo(fileName());
1161 if (finfo.exist()) {
1162 mode_t fmode = finfo.getMode();
1163 struct utimbuf times = {
1164 finfo.getAccessTime(),
1165 finfo.getModificationTime() };
1167 ifstream ifs(fileName().c_str());
1168 ofstream ofs(s.c_str(), ios::out|ios::trunc);
1173 ::chmod(s.c_str(), fmode);
1175 if (::utime(s.c_str(), ×)) {
1176 lyxerr << "utime error." << endl;
1179 lyxerr << "LyX was not able to make "
1180 "backupcopy. Beware." << endl;
1185 if (writeFile(fileName(), false)) {
1188 // now delete the autosavefile
1189 string a = OnlyPath(fileName());
1191 a += OnlyFilename(fileName());
1193 FileInfo fileinfo(a);
1194 if (fileinfo.exist()) {
1195 if (::remove(a.c_str()) != 0) {
1196 WriteFSAlert(_("Could not delete "
1197 "auto-save file!"), a);
1201 // Saving failed, so backup is not backup
1202 if (lyxrc.make_backup) {
1203 ::rename(s.c_str(), fileName().c_str());
1211 // Returns false if unsuccesful
1212 bool Buffer::writeFile(string const & fname, bool flag) const
1214 // if flag is false writeFile will not create any GUI
1215 // warnings, only cerr.
1216 // Needed for autosave in background or panic save (Matthias 120496)
1218 if (read_only && (fname == filename)) {
1219 // Here we should come with a question if we should
1220 // perform the write anyway.
1222 lyxerr << _("Error! Document is read-only: ")
1225 WriteAlert(_("Error! Document is read-only: "),
1230 FileInfo finfo(fname);
1231 if (finfo.exist() && !finfo.writable()) {
1232 // Here we should come with a question if we should
1233 // try to do the save anyway. (i.e. do a chmod first)
1235 lyxerr << _("Error! Cannot write file: ")
1238 WriteFSAlert(_("Error! Cannot write file: "),
1243 ofstream ofs(fname.c_str());
1246 lyxerr << _("Error! Cannot open file: ")
1249 WriteFSAlert(_("Error! Cannot open file: "),
1253 // The top of the file should not be written by params.
1255 // write out a comment in the top of the file
1256 ofs << '#' << LYX_DOCVERSION
1257 << " created this file. For more info see http://www.lyx.org/\n";
1258 ofs.setf(ios::showpoint|ios::fixed);
1260 ofs << "\\lyxformat " << setw(4) << LYX_FORMAT << "\n";
1262 // now write out the buffer paramters.
1263 params.writeFile(ofs);
1265 char footnoteflag = 0;
1268 // this will write out all the paragraphs
1269 // using recursive descent.
1270 paragraph->writeFile(ofs, params, footnoteflag, depth);
1272 // Write marker that shows file is complete
1273 ofs << "\n\\the_end" << endl;
1275 // how to check if close went ok?
1280 void Buffer::writeFileAscii(string const & fname, int linelen)
1282 LyXFont font1, font2;
1284 char c, footnoteflag = 0, depth = 0;
1286 LyXParagraph::size_type i;
1287 int j, h, ltype = 0, ltype_depth = 0,
1288 * clen = 0, actcell = 0, actpos = 0, cell = 0, cells = 0,
1291 bool ref_printed = false;
1293 ofstream ofs(fname.c_str());
1295 WriteFSAlert(_("Error: Cannot write file:"), fname);
1299 string fname1 = TmpFileName();
1300 LyXParagraph * par = paragraph;
1304 if (par->footnoteflag != LyXParagraph::NO_FOOTNOTE ||
1306 par->previous->footnoteflag == LyXParagraph::NO_FOOTNOTE){
1308 /* begins a footnote environment ? */
1309 if (footnoteflag != par->footnoteflag) {
1310 footnoteflag = par->footnoteflag;
1312 j = strlen(string_footnotekinds[par->footnotekind])+4;
1313 if (currlinelen + j > linelen)
1316 << string_footnotekinds[par->footnotekind] << "] ";
1321 /* begins or ends a deeper area ?*/
1322 if (depth != par->depth) {
1323 if (par->depth > depth) {
1324 while (par->depth > depth) {
1329 while (par->depth < depth) {
1335 /* First write the layout */
1336 tmp = textclasslist.NameOfLayout(params.textclass, par->layout);
1337 if (tmp == "Itemize") {
1339 ltype_depth = depth+1;
1340 } else if (tmp == "Enumerate") {
1342 ltype_depth = depth+1;
1343 } else if (strstr(tmp.c_str(), "ection")) {
1345 ltype_depth = depth+1;
1346 } else if (strstr(tmp.c_str(), "aragraph")) {
1348 ltype_depth = depth+1;
1349 } else if (tmp == "Description") {
1351 ltype_depth = depth+1;
1352 } else if (tmp == "Abstract") {
1355 } else if (tmp == "Bibliography") {
1363 /* maybe some vertical spaces */
1365 /* the labelwidthstring used in lists */
1369 /* some pagebreaks? */
1373 /* what about the alignment */
1375 /* dummy layout, that means a footnote ended */
1376 footnoteflag = LyXParagraph::NO_FOOTNOTE;
1381 //LyXLayout const & layout =
1382 // textclasslist.Style(params.textclass,
1383 // par->GetLayout()); // unused
1384 //bool free_spc = layout.free_spacing; //unused
1386 /* It might be a table */
1389 if (!lyxrc.ascii_roff_command.empty() &&
1390 lyxrc.ascii_roff_command != "none") {
1391 RoffAsciiTable(ofs, par);
1398 cells = par->table->columns;
1399 clen = new int [cells];
1400 memset(clen, 0, sizeof(int) * cells);
1402 for (i = 0, j = 0, h = 1; i < par->size(); ++i, ++h) {
1403 c = par->GetChar(i);
1404 if (c == LyXParagraph::META_INSET) {
1405 if ((inset = par->GetInset(i))) {
1407 std::ostringstream ost;
1409 h += ost.str().length();
1414 char * tmp = ost.str();
1420 } else if (c == LyXParagraph::META_NEWLINE) {
1424 j = (++j) % par->table->NumberOfCellsInRow(actcell);
1432 font1 = LyXFont(LyXFont::ALL_INHERIT, params.language_info);
1434 for (i = 0, actpos = 1; i < par->size(); ++i, ++actpos) {
1435 if (!i && !footnoteflag && !noparbreak){
1437 for(j = 0; j < depth; ++j)
1439 currlinelen = depth * 2;
1441 case 0: /* Standard */
1442 case 4: /* (Sub)Paragraph */
1443 case 5: /* Description */
1445 case 6: /* Abstract */
1446 ofs << "Abstract\n\n";
1448 case 7: /* Bibliography */
1450 ofs << "References\n\n";
1455 ofs << par->labelstring << " ";
1458 if (ltype_depth > depth) {
1459 for(j = ltype_depth - 1; j > depth; --j)
1461 currlinelen += (ltype_depth-depth)*2;
1464 for(j = 0; j < cells; ++j) {
1466 for(h = 0; h < (clen[j] + 1);
1471 for(j = 0; j < depth; ++j)
1473 currlinelen = depth * 2;
1474 if (ltype_depth > depth) {
1475 for(j = ltype_depth;
1478 currlinelen += (ltype_depth-depth)*2;
1483 font2 = par->GetFontSettings(i);
1484 if (font1.latex() != font2.latex()) {
1485 if (font2.latex() == LyXFont::OFF)
1492 c = par->GetChar(i);
1496 case LyXParagraph::META_INSET:
1497 if ((inset = par->GetInset(i))) {
1500 currlinelen += (ofs.tellp() - fpos);
1501 actpos += (ofs.tellp() - fpos) - 1;
1504 case LyXParagraph::META_NEWLINE:
1506 if (par->table->NumberOfCellsInRow(actcell) <= cell) {
1507 for(j = actpos; j < clen[cell - 1]; ++j)
1510 for(j = 0; j < depth; ++j)
1512 currlinelen = depth*2;
1513 if (ltype_depth > depth) {
1514 for(j = ltype_depth; j > depth; --j)
1516 currlinelen += (ltype_depth-depth) * 2;
1518 for(j = 0; j < cells; ++j) {
1520 for(h = 0; h < (clen[j] + 1); ++h)
1524 for(j = 0; j < depth; ++j)
1526 currlinelen = depth * 2;
1527 if (ltype_depth > depth) {
1528 for(j = ltype_depth;
1531 currlinelen += (ltype_depth-depth)*2;
1537 j < clen[cell - 1]; ++j)
1543 currlinelen = actpos = 0;
1546 for(j = 0; j < depth; ++j)
1548 currlinelen = depth * 2;
1549 if (ltype_depth > depth) {
1550 for(j = ltype_depth;
1553 currlinelen += (ltype_depth - depth) * 2;
1557 case LyXParagraph::META_HFILL:
1564 if (currlinelen > linelen - 10
1565 && c == ' ' && i + 2 < par->size()) {
1567 for(j = 0; j < depth; ++j)
1569 currlinelen = depth * 2;
1570 if (ltype_depth > depth) {
1571 for(j = ltype_depth;
1574 currlinelen += (ltype_depth-depth)*2;
1576 } else if (c != '\0')
1579 lyxerr.debug() << "writeAsciiFile: NULL char in structure." << endl;
1585 for(j = actpos; j < clen[cell - 1]; ++j)
1588 for(j = 0; j < depth; ++j)
1590 currlinelen = depth * 2;
1591 if (ltype_depth > depth) {
1592 for(j = ltype_depth; j > depth; --j)
1594 currlinelen += (ltype_depth - depth) * 2;
1596 for(j = 0; j < cells; ++j) {
1598 for(h = 0; h < (clen[j] + 1); ++h)
1611 void Buffer::makeLaTeXFile(string const & fname,
1612 string const & original_path,
1613 bool nice, bool only_body)
1615 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
1617 niceFile = nice; // this will be used by Insetincludes.
1619 tex_code_break_column = lyxrc.ascii_linelen;
1621 LyXTextClass const & tclass =
1622 textclasslist.TextClass(params.textclass);
1624 ofstream ofs(fname.c_str());
1626 WriteFSAlert(_("Error: Cannot open file: "), fname);
1630 // validate the buffer.
1631 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
1632 LaTeXFeatures features(params, tclass.numLayouts());
1634 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
1637 // The starting paragraph of the coming rows is the
1638 // first paragraph of the document. (Asger)
1639 texrow.start(paragraph, 0);
1641 if (!only_body && nice) {
1642 ofs << "%% " LYX_DOCVERSION " created this file. "
1643 "For more info, see http://www.lyx.org/.\n"
1644 "%% Do not edit unless you really know what "
1649 lyxerr.debug() << "lyx header finished" << endl;
1650 // There are a few differences between nice LaTeX and usual files:
1651 // usual is \batchmode and has a
1652 // special input@path to allow the including of figures
1653 // with either \input or \includegraphics (what figinsets do).
1654 // batchmode is not set if there is a tex_code_break_column.
1655 // In this case somebody is interested in the generated LaTeX,
1656 // so this is OK. input@path is set when the actual parameter
1657 // original_path is set. This is done for usual tex-file, but not
1658 // for nice-latex-file. (Matthias 250696)
1661 // code for usual, NOT nice-latex-file
1662 ofs << "\\batchmode\n"; // changed
1663 // from \nonstopmode
1666 if (!original_path.empty()) {
1667 ofs << "\\makeatletter\n"
1668 << "\\def\\input@path{{"
1669 << original_path << "/}}\n"
1670 << "\\makeatother\n";
1676 ofs << "\\documentclass";
1678 string options; // the document class options.
1680 if (tokenPos(tclass.opt_fontsize(), '|', params.fontsize) >= 0) {
1681 // only write if existing in list (and not default)
1682 options += params.fontsize;
1687 if (!params.use_geometry &&
1688 (params.paperpackage == BufferParams::PACKAGE_NONE)) {
1689 switch (params.papersize) {
1690 case BufferParams::PAPER_A4PAPER:
1691 options += "a4paper,";
1693 case BufferParams::PAPER_USLETTER:
1694 options += "letterpaper,";
1696 case BufferParams::PAPER_A5PAPER:
1697 options += "a5paper,";
1699 case BufferParams::PAPER_B5PAPER:
1700 options += "b5paper,";
1702 case BufferParams::PAPER_EXECUTIVEPAPER:
1703 options += "executivepaper,";
1705 case BufferParams::PAPER_LEGALPAPER:
1706 options += "legalpaper,";
1712 if (params.sides != tclass.sides()) {
1713 switch (params.sides) {
1714 case LyXTextClass::OneSide:
1715 options += "oneside,";
1717 case LyXTextClass::TwoSides:
1718 options += "twoside,";
1725 if (params.columns != tclass.columns()) {
1726 if (params.columns == 2)
1727 options += "twocolumn,";
1729 options += "onecolumn,";
1732 if (!params.use_geometry
1733 && params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1734 options += "landscape,";
1736 // language should be a parameter to \documentclass
1737 bool use_babel = false;
1738 if (params.language != "default" ||
1739 !features.UsedLanguages.empty() ) {
1741 for (LaTeXFeatures::LanguageList::const_iterator cit =
1742 features.UsedLanguages.begin();
1743 cit != features.UsedLanguages.end(); ++cit)
1744 options += (*cit)->lang + ",";
1745 options += params.language_info->lang + ',';
1748 // the user-defined options
1749 if (!params.options.empty()) {
1750 options += params.options + ',';
1753 if (!options.empty()){
1754 options = strip(options, ',');
1755 ofs << '[' << options << ']';
1759 << textclasslist.LatexnameOfClass(params.textclass)
1762 // end of \documentclass defs
1764 // font selection must be done before loading fontenc.sty
1765 if (params.fonts != "default") {
1766 ofs << "\\usepackage{" << params.fonts << "}\n";
1769 // this one is not per buffer
1770 if (lyxrc.fontenc != "default") {
1771 ofs << "\\usepackage[" << lyxrc.fontenc
1775 if (params.inputenc != "default") {
1776 ofs << "\\usepackage[" << params.inputenc
1781 // At the very beginning the text parameters.
1782 if (params.paperpackage != BufferParams::PACKAGE_NONE) {
1783 switch (params.paperpackage) {
1784 case BufferParams::PACKAGE_A4:
1785 ofs << "\\usepackage{a4}\n";
1788 case BufferParams::PACKAGE_A4WIDE:
1789 ofs << "\\usepackage{a4wide}\n";
1792 case BufferParams::PACKAGE_WIDEMARGINSA4:
1793 ofs << "\\usepackage[widemargins]{a4}\n";
1798 if (params.use_geometry) {
1799 ofs << "\\usepackage{geometry}\n";
1801 ofs << "\\geometry{verbose";
1802 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1803 ofs << ",landscape";
1804 switch (params.papersize2) {
1805 case BufferParams::VM_PAPER_CUSTOM:
1806 if (!params.paperwidth.empty())
1807 ofs << ",paperwidth="
1808 << params.paperwidth;
1809 if (!params.paperheight.empty())
1810 ofs << ",paperheight="
1811 << params.paperheight;
1813 case BufferParams::VM_PAPER_USLETTER:
1814 ofs << ",letterpaper";
1816 case BufferParams::VM_PAPER_USLEGAL:
1817 ofs << ",legalpaper";
1819 case BufferParams::VM_PAPER_USEXECUTIVE:
1820 ofs << ",executivepaper";
1822 case BufferParams::VM_PAPER_A3:
1825 case BufferParams::VM_PAPER_A4:
1828 case BufferParams::VM_PAPER_A5:
1831 case BufferParams::VM_PAPER_B3:
1834 case BufferParams::VM_PAPER_B4:
1837 case BufferParams::VM_PAPER_B5:
1841 // default papersize ie BufferParams::VM_PAPER_DEFAULT
1842 switch (lyxrc.default_papersize) {
1843 case BufferParams::PAPER_DEFAULT: // keep compiler happy
1844 case BufferParams::PAPER_USLETTER:
1845 ofs << ",letterpaper";
1847 case BufferParams::PAPER_LEGALPAPER:
1848 ofs << ",legalpaper";
1850 case BufferParams::PAPER_EXECUTIVEPAPER:
1851 ofs << ",executivepaper";
1853 case BufferParams::PAPER_A3PAPER:
1856 case BufferParams::PAPER_A4PAPER:
1859 case BufferParams::PAPER_A5PAPER:
1862 case BufferParams::PAPER_B5PAPER:
1867 if (!params.topmargin.empty())
1868 ofs << ",tmargin=" << params.topmargin;
1869 if (!params.bottommargin.empty())
1870 ofs << ",bmargin=" << params.bottommargin;
1871 if (!params.leftmargin.empty())
1872 ofs << ",lmargin=" << params.leftmargin;
1873 if (!params.rightmargin.empty())
1874 ofs << ",rmargin=" << params.rightmargin;
1875 if (!params.headheight.empty())
1876 ofs << ",headheight=" << params.headheight;
1877 if (!params.headsep.empty())
1878 ofs << ",headsep=" << params.headsep;
1879 if (!params.footskip.empty())
1880 ofs << ",footskip=" << params.footskip;
1884 if (params.use_amsmath
1885 && !tclass.provides(LyXTextClass::amsmath)) {
1886 ofs << "\\usepackage{amsmath}\n";
1890 if (tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle) >= 0) {
1891 if (params.pagestyle == "fancy") {
1892 ofs << "\\usepackage{fancyhdr}\n";
1895 ofs << "\\pagestyle{" << params.pagestyle << "}\n";
1899 // We try to load babel late, in case it interferes
1900 // with other packages.
1902 ofs << lyxrc.language_package << endl;
1906 if (params.secnumdepth != tclass.secnumdepth()) {
1907 ofs << "\\setcounter{secnumdepth}{"
1908 << params.secnumdepth
1912 if (params.tocdepth != tclass.tocdepth()) {
1913 ofs << "\\setcounter{tocdepth}{"
1919 if (params.paragraph_separation) {
1920 switch (params.defskip.kind()) {
1921 case VSpace::SMALLSKIP:
1922 ofs << "\\setlength\\parskip{\\smallskipamount}\n";
1924 case VSpace::MEDSKIP:
1925 ofs << "\\setlength\\parskip{\\medskipamount}\n";
1927 case VSpace::BIGSKIP:
1928 ofs << "\\setlength\\parskip{\\bigskipamount}\n";
1930 case VSpace::LENGTH:
1931 ofs << "\\setlength\\parskip{"
1932 << params.defskip.length().asLatexString()
1935 default: // should never happen // Then delete it.
1936 ofs << "\\setlength\\parskip{\\medskipamount}\n";
1941 ofs << "\\setlength\\parindent{0pt}\n";
1945 // Now insert the LyX specific LaTeX commands...
1946 string preamble, tmppreamble;
1948 // The optional packages;
1949 preamble = features.getPackages();
1951 // this might be useful...
1952 preamble += "\n\\makeatletter\n\n";
1954 // Some macros LyX will need
1955 tmppreamble = features.getMacros();
1957 if (!tmppreamble.empty()) {
1958 preamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1959 "LyX specific LaTeX commands.\n"
1960 + tmppreamble + '\n';
1963 // the text class specific preamble
1964 tmppreamble = features.getTClassPreamble();
1965 if (!tmppreamble.empty()) {
1966 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1967 "Textclass specific LaTeX commands.\n"
1968 + tmppreamble + '\n';
1971 /* the user-defined preamble */
1972 if (!params.preamble.empty()) {
1973 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1974 "User specified LaTeX commands.\n"
1975 + params.preamble + '\n';
1978 preamble += "\\makeatother\n\n";
1980 // Itemize bullet settings need to be last in case the user
1981 // defines their own bullets that use a package included
1982 // in the user-defined preamble -- ARRae
1983 // Actually it has to be done much later than that
1984 // since some packages like frenchb make modifications
1985 // at \begin{document} time -- JMarc
1987 for (int i = 0; i < 4; ++i) {
1988 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
1989 if (bullets_def.empty())
1990 bullets_def="\\AtBeginDocument{\n";
1991 bullets_def += " \\renewcommand{\\labelitemi";
1993 // `i' is one less than the item to modify
2000 bullets_def += "ii";
2006 bullets_def += "}{" +
2007 params.user_defined_bullets[i].getText()
2012 if (!bullets_def.empty())
2013 preamble += bullets_def + "}\n\n";
2015 for (int j = countChar(preamble, '\n'); j-- ;) {
2022 ofs << "\\begin{document}\n\n";
2026 lyxerr.debug() << "preamble finished, now the body." << endl;
2027 if (!lyxrc.language_auto_begin && params.language != "default") {
2028 ofs << subst(lyxrc.language_command_begin, "$$lang",
2034 latexParagraphs(ofs, paragraph, 0, texrow);
2036 // add this just in case after all the paragraphs
2040 if (!lyxrc.language_auto_end && params.language != "default") {
2041 ofs << subst(lyxrc.language_command_end, "$$lang",
2048 ofs << "\\end{document}\n";
2051 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
2053 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
2057 // Just to be sure. (Asger)
2060 // tex_code_break_column's value is used to decide
2061 // if we are in batchmode or not (within mathed_write()
2062 // in math_write.C) so we must set it to a non-zero
2063 // value when we leave otherwise we save incorrect .lyx files.
2064 tex_code_break_column = lyxrc.ascii_linelen;
2068 lyxerr << "File was not closed properly." << endl;
2071 lyxerr.debug() << "Finished making latex file." << endl;
2075 // LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
2077 void Buffer::latexParagraphs(ostream & ofs, LyXParagraph *par,
2078 LyXParagraph *endpar, TexRow & texrow)
2080 bool was_title = false;
2081 bool already_title = false;
2083 std::ostringstream ftnote;
2085 char * tmpholder = 0;
2091 while (par != endpar) {
2092 #ifndef HAVE_SSTREAM
2095 ftnote << tmpholder;
2096 delete [] tmpholder;
2101 lyxerr[Debug::LATEX] << "Error in latexParagraphs."
2103 LyXLayout const & layout =
2104 textclasslist.Style(params.textclass,
2107 if (layout.intitle) {
2108 if (already_title) {
2109 lyxerr <<"Error in latexParagraphs: You"
2110 " should not mix title layouts"
2111 " with normal ones." << endl;
2114 } else if (was_title && !already_title) {
2115 ofs << "\\maketitle\n";
2117 already_title = true;
2120 // We are at depth 0 so we can just use
2121 // ordinary \footnote{} generation
2122 // flag this with ftcount
2124 if (layout.isEnvironment()
2125 || par->pextra_type != LyXParagraph::PEXTRA_NONE) {
2126 par = par->TeXEnvironment(ofs, texrow,
2127 ftnote, ft_texrow, ftcount);
2129 par = par->TeXOnePar(ofs, texrow, false,
2130 ftnote, ft_texrow, ftcount);
2133 // Write out what we've generated...
2136 ofs << "\\addtocounter{footnote}{-"
2140 ofs << ftnote.str();
2141 texrow += ft_texrow;
2143 // The extra .c_str() is needed when we use
2144 // lyxstring instead of the STL string class.
2145 ftnote.str(string().c_str());
2147 delete [] ftnote.str();
2152 #ifndef HAVE_SSTREAM
2154 // I hate strstreams
2155 tmpholder = ftnote.str();
2159 #ifndef HAVE_SSTREAM
2160 delete [] tmpholder;
2162 // It might be that we only have a title in this document
2163 if (was_title && !already_title) {
2164 ofs << "\\maketitle\n";
2169 bool Buffer::isLatex() const
2171 return textclasslist.TextClass(params.textclass).outputType() == LATEX;
2175 bool Buffer::isLinuxDoc() const
2177 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC;
2181 bool Buffer::isLiterate() const
2183 return textclasslist.TextClass(params.textclass).outputType() == LITERATE;
2187 bool Buffer::isDocBook() const
2189 return textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2193 bool Buffer::isSGML() const
2195 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC ||
2196 textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2200 void Buffer::sgmlOpenTag(ostream & os, int depth,
2201 string const & latexname) const
2203 os << string(depth, ' ') << "<" << latexname << ">\n";
2207 void Buffer::sgmlCloseTag(ostream & os, int depth,
2208 string const & latexname) const
2210 os << string(depth, ' ') << "</" << latexname << ">\n";
2214 void Buffer::makeLinuxDocFile(string const & fname, int column)
2216 LyXParagraph * par = paragraph;
2218 string top_element = textclasslist.LatexnameOfClass(params.textclass);
2219 string environment_stack[10];
2222 int depth = 0; // paragraph depth
2224 ofstream ofs(fname.c_str());
2227 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2231 tex_code_break_column = column;
2234 if (params.preamble.empty()) {
2235 ofs << "<!doctype linuxdoc system>\n\n";
2238 ofs << "<!doctype linuxdoc system \n [ "
2239 << params.preamble << " \n]>\n\n";
2242 ofs << "<!-- " << LYX_DOCVERSION
2243 << " created this file. For more info see http://www.lyx.org/"
2246 if(params.options.empty())
2247 sgmlOpenTag(ofs, 0, top_element);
2249 string top = top_element;
2251 top += params.options;
2252 sgmlOpenTag(ofs, 0, top);
2256 int desc_on = 0; // description mode
2257 LyXLayout const & style =
2258 textclasslist.Style(users->buffer()->params.textclass,
2260 par->AutoDeleteInsets();
2262 // treat <toc> as a special case for compatibility with old code
2263 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2264 Inset * inset = par->GetInset(0);
2265 char lyx_code = inset->LyxCode();
2266 if (lyx_code == Inset::TOC_CODE){
2267 string temp = "toc";
2268 sgmlOpenTag(ofs, depth, temp);
2271 linuxDocHandleFootnote(ofs, par, depth);
2276 // environment tag closing
2277 for( ; depth > par->depth; --depth) {
2278 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2279 environment_stack[depth].erase();
2282 // write opening SGML tags
2283 switch(style.latextype) {
2284 case LATEX_PARAGRAPH:
2285 if(depth == par->depth
2286 && !environment_stack[depth].empty()) {
2287 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2288 environment_stack[depth].erase();
2294 sgmlOpenTag(ofs, depth, style.latexname());
2299 LinuxDocError(par, 0,
2300 _("Error : Wrong depth for"
2301 " LatexType Command.\n"));
2303 if (!environment_stack[depth].empty()){
2304 sgmlCloseTag(ofs, depth,
2305 environment_stack[depth]);
2309 environment_stack[depth].erase();
2310 sgmlOpenTag(ofs, depth, style.latexname());
2313 case LATEX_ENVIRONMENT:
2314 case LATEX_ITEM_ENVIRONMENT:
2315 if(depth == par->depth
2316 && environment_stack[depth] != style.latexname()
2317 && !environment_stack[depth].empty()) {
2319 sgmlCloseTag(ofs, depth,
2320 environment_stack[depth]);
2321 environment_stack[depth].erase();
2323 if (depth < par->depth) {
2325 environment_stack[depth].erase();
2327 if (environment_stack[depth] != style.latexname()) {
2330 sgmlOpenTag(ofs, depth, temp);
2332 environment_stack[depth] = style.latexname();
2333 sgmlOpenTag(ofs, depth,
2334 environment_stack[depth]);
2336 if(style.latextype == LATEX_ENVIRONMENT) break;
2338 desc_on = (style.labeltype == LABEL_MANUAL);
2345 sgmlOpenTag(ofs, depth + 1, item_name);
2348 sgmlOpenTag(ofs, depth, style.latexname());
2353 SimpleLinuxDocOnePar(ofs, par, desc_on, depth);
2356 linuxDocHandleFootnote(ofs, par, depth);
2358 while(par && par->IsDummy());
2361 // write closing SGML tags
2362 switch(style.latextype) {
2364 case LATEX_ENVIRONMENT:
2365 case LATEX_ITEM_ENVIRONMENT:
2368 sgmlCloseTag(ofs, depth, style.latexname());
2374 for(; depth > 0; --depth)
2375 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2377 if(!environment_stack[depth].empty())
2378 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2381 sgmlCloseTag(ofs, 0, top_element);
2384 // How to check for successful close
2388 void Buffer::linuxDocHandleFootnote(ostream & os, LyXParagraph * & par,
2391 string tag = "footnote";
2393 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2394 sgmlOpenTag(os, depth + 1, tag);
2395 SimpleLinuxDocOnePar(os, par, 0, depth + 1);
2396 sgmlCloseTag(os, depth + 1, tag);
2402 void Buffer::DocBookHandleCaption(ostream & os, string & inner_tag,
2403 int const depth, int desc_on,
2404 LyXParagraph * & par)
2406 LyXParagraph * tpar = par;
2407 while (tpar && (tpar->footnoteflag != LyXParagraph::NO_FOOTNOTE) &&
2408 (tpar->layout != textclasslist.NumberOfLayout(params.textclass,
2412 tpar->layout == textclasslist.NumberOfLayout(params.textclass,
2413 "Caption").second) {
2414 sgmlOpenTag(os, depth + 1, inner_tag);
2416 SimpleDocBookOnePar(os, extra_par, tpar,
2417 desc_on, depth + 2);
2418 sgmlCloseTag(os, depth+1, inner_tag);
2419 if(!extra_par.empty())
2425 void Buffer::DocBookHandleFootnote(ostream & os, LyXParagraph * & par,
2428 string tag, inner_tag;
2429 string tmp_par, extra_par;
2430 bool inner_span = false;
2433 // Someone should give this enum a proper name (Lgb)
2441 SOME_ENUM last = NO_ONE;
2442 SOME_ENUM present = FOOTNOTE_LIKE;
2444 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2445 if(last == present) {
2447 if(!tmp_par.empty()) {
2450 sgmlCloseTag(os, depth + 1, inner_tag);
2451 sgmlOpenTag(os, depth + 1, inner_tag);
2458 if(!inner_tag.empty()) sgmlCloseTag(os, depth + 1,
2460 if(!extra_par.empty()) os << extra_par;
2461 if(!tag.empty()) sgmlCloseTag(os, depth, tag);
2464 switch (par->footnotekind) {
2465 case LyXParagraph::FOOTNOTE:
2466 case LyXParagraph::ALGORITHM:
2469 present = FOOTNOTE_LIKE;
2472 case LyXParagraph::MARGIN:
2475 present = MARGIN_LIKE;
2478 case LyXParagraph::FIG:
2479 case LyXParagraph::WIDE_FIG:
2481 inner_tag = "title";
2485 case LyXParagraph::TAB:
2486 case LyXParagraph::WIDE_TAB:
2488 inner_tag = "title";
2493 sgmlOpenTag(os, depth, tag);
2494 if ((present == TAB_LIKE) || (present == FIG_LIKE)) {
2495 DocBookHandleCaption(os, inner_tag, depth,
2499 sgmlOpenTag(os, depth + 1, inner_tag);
2502 // ignore all caption here, we processed them above!!!
2503 if (par->layout != textclasslist
2504 .NumberOfLayout(params.textclass,
2505 "Caption").second) {
2507 std::ostringstream ost;
2511 SimpleDocBookOnePar(ost, extra_par, par,
2512 desc_on, depth + 2);
2514 tmp_par += ost.str().c_str();
2517 char * ctmp = ost.str();
2522 tmp_par = frontStrip(strip(tmp_par));
2528 if(!inner_tag.empty()) sgmlCloseTag(os, depth + 1, inner_tag);
2529 if(!extra_par.empty()) os << extra_par;
2530 if(!tag.empty()) sgmlCloseTag(os, depth, tag);
2534 // push a tag in a style stack
2535 void Buffer::push_tag(ostream & os, char const * tag,
2536 int & pos, char stack[5][3])
2538 // pop all previous tags
2539 for (int j = pos; j >= 0; --j)
2540 os << "</" << stack[j] << ">";
2543 sprintf(stack[++pos], "%s", tag);
2546 for (int i = 0; i <= pos; ++i)
2547 os << "<" << stack[i] << ">";
2551 void Buffer::pop_tag(ostream & os, char const * tag,
2552 int & pos, char stack[5][3])
2556 // pop all tags till specified one
2557 for (j = pos; (j >= 0) && (strcmp(stack[j], tag)); --j)
2558 os << "</" << stack[j] << ">";
2561 os << "</" << tag << ">";
2563 // push all tags, but the specified one
2564 for (j = j + 1; j <= pos; ++j) {
2565 os << "<" << stack[j] << ">";
2566 strcpy(stack[j-1], stack[j]);
2572 // Handle internal paragraph parsing -- layout already processed.
2574 // checks, if newcol chars should be put into this line
2575 // writes newline, if necessary.
2577 void linux_doc_line_break(ostream & os, unsigned int & colcount,
2578 const unsigned int newcol)
2581 if (colcount > lyxrc.ascii_linelen) {
2583 colcount = newcol; // assume write after this call
2588 void Buffer::SimpleLinuxDocOnePar(ostream & os, LyXParagraph * par,
2589 int desc_on, int const /*depth*/)
2591 LyXFont font1, font2;
2594 LyXParagraph::size_type main_body;
2596 LyXLayout const & style = textclasslist.Style(params.textclass,
2599 char family_type = 0; // family font flag
2600 bool is_bold = false; // series font flag
2601 char shape_type = 0; // shape font flag
2602 bool is_em = false; // emphasis (italic) font flag
2604 int stack_num = -1; // style stack position
2605 // Can this be rewritten to use a std::stack, please. (Lgb)
2606 char stack[5][3]; // style stack
2607 unsigned int char_line_count = 5; // Heuristic choice ;-)
2609 if (style.labeltype != LABEL_MANUAL)
2612 main_body = par->BeginningOfMainBody();
2614 // gets paragraph main font
2616 font1 = style.labelfont;
2621 // parsing main loop
2622 for (LyXParagraph::size_type i = 0;
2623 i < par->size(); ++i) {
2626 if (i == main_body && !par->IsDummy()) {
2631 font2 = par->getFont(i);
2633 if (font1.family() != font2.family()) {
2634 switch(family_type) {
2636 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2637 push_tag(os, "tt", stack_num, stack);
2640 else if (font2.family() == LyXFont::SANS_FAMILY) {
2641 push_tag(os, "sf", stack_num, stack);
2646 pop_tag(os, "tt", stack_num, stack);
2647 if (font2.family() == LyXFont::SANS_FAMILY) {
2648 push_tag(os, "sf", stack_num, stack);
2656 pop_tag(os, "sf", stack_num, stack);
2657 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2658 push_tag(os, "tt", stack_num, stack);
2668 if (font1.series() != font2.series()) {
2669 if (font2.series() == LyXFont::BOLD_SERIES) {
2670 push_tag(os, "bf", stack_num, stack);
2674 pop_tag(os, "bf", stack_num, stack);
2679 // handle italic and slanted fonts
2680 if (font1.shape() != font2.shape()) {
2681 switch(shape_type) {
2683 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2684 push_tag(os, "it", stack_num, stack);
2687 else if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2688 push_tag(os, "sl", stack_num, stack);
2693 pop_tag(os, "it", stack_num, stack);
2694 if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2695 push_tag(os, "sl", stack_num, stack);
2703 pop_tag(os, "sl", stack_num, stack);
2704 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2705 push_tag(os, "it", stack_num, stack);
2714 if (font1.emph() != font2.emph()) {
2715 if (font2.emph() == LyXFont::ON) {
2716 push_tag(os, "em", stack_num, stack);
2719 pop_tag(os, "em", stack_num, stack);
2724 c = par->GetChar(i);
2726 if (font2.latex() == LyXFont::ON) {
2727 // "TeX"-Mode on == > SGML-Mode on.
2729 os << c; // see LaTeX-Generation...
2731 } else if (c == LyXParagraph::META_INSET) {
2732 inset = par->GetInset(i);
2733 inset->Linuxdoc(os);
2736 if (par->linuxDocConvertChar(c, sgml_string)
2737 && !style.free_spacing) { // in freespacing
2739 // non-breaking characters
2743 linux_doc_line_break(os, char_line_count, 6);
2748 linux_doc_line_break(os, char_line_count, 1);
2754 char_line_count += sgml_string.length();
2760 // needed if there is an optional argument but no contents
2761 if (main_body > 0 && main_body == par->size()) {
2765 // pop all defined Styles
2766 for (j = stack_num; j >= 0; --j) {
2767 linux_doc_line_break(os,
2769 3 + strlen(stack[j]));
2770 os << "</" << stack[j] << ">";
2773 // resets description flag correctly
2776 // <tag> not closed...
2777 linux_doc_line_break(os, char_line_count, 6);
2781 // fprintf(file, "</p>");
2787 // Print an error message.
2788 void Buffer::LinuxDocError(LyXParagraph * par, int pos,
2789 char const * message)
2791 InsetError * new_inset;
2793 // insert an error marker in text
2794 new_inset = new InsetError(message);
2795 par->InsertChar(pos, LyXParagraph::META_INSET);
2796 par->InsertInset(pos, new_inset);
2799 // This constant defines the maximum number of
2800 // environment layouts that can be nesteded.
2801 // The same applies for command layouts.
2802 // These values should be more than enough.
2803 // José Matos (1999/07/22)
2805 enum { MAX_NEST_LEVEL = 25};
2807 void Buffer::makeDocBookFile(string const & fname, int column)
2809 LyXParagraph * par = paragraph;
2811 string top_element= textclasslist.LatexnameOfClass(params.textclass);
2812 // Please use a real stack.
2813 string environment_stack[MAX_NEST_LEVEL];
2814 string environment_inner[MAX_NEST_LEVEL];
2815 // Please use a real stack.
2816 string command_stack[MAX_NEST_LEVEL];
2817 bool command_flag= false;
2818 int command_depth= 0, command_base= 0, cmd_depth= 0;
2820 string item_name, command_name;
2821 string c_depth, c_params, tmps;
2823 int depth = 0; // paragraph depth
2825 tex_code_break_column = column;
2827 ofstream ofs(fname.c_str());
2829 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2835 ofs << "<!doctype " << top_element
2836 << " public \"-//OASIS//DTD DocBook V3.1//EN\"";
2838 if (params.preamble.empty())
2841 ofs << "\n [ " << params.preamble << " \n]>\n\n";
2843 ofs << "<!-- DocBook file was created by " << LYX_DOCVERSION
2844 << "\n See http://www.lyx.org/ for more information -->\n";
2846 if(params.options.empty())
2847 sgmlOpenTag(ofs, 0, top_element);
2849 string top = top_element;
2851 top += params.options;
2852 sgmlOpenTag(ofs, 0, top);
2856 int desc_on = 0; // description mode
2857 LyXLayout const & style =
2858 textclasslist.Style(users->buffer()->params.textclass,
2860 par->AutoDeleteInsets();
2862 // environment tag closing
2863 for( ; depth > par->depth; --depth) {
2864 if(environment_inner[depth] != "!-- --") {
2865 item_name= "listitem";
2866 sgmlCloseTag(ofs, command_depth + depth,
2868 if( environment_inner[depth] == "varlistentry")
2869 sgmlCloseTag(ofs, depth+command_depth,
2870 environment_inner[depth]);
2872 sgmlCloseTag(ofs, depth + command_depth,
2873 environment_stack[depth]);
2874 environment_stack[depth].erase();
2875 environment_inner[depth].erase();
2878 if(depth == par->depth
2879 && environment_stack[depth] != style.latexname()
2880 && !environment_stack[depth].empty()) {
2881 if(environment_inner[depth] != "!-- --") {
2882 item_name= "listitem";
2883 sgmlCloseTag(ofs, command_depth+depth,
2885 if( environment_inner[depth] == "varlistentry")
2887 depth + command_depth,
2888 environment_inner[depth]);
2891 sgmlCloseTag(ofs, depth + command_depth,
2892 environment_stack[depth]);
2894 environment_stack[depth].erase();
2895 environment_inner[depth].erase();
2898 // Write opening SGML tags.
2899 switch(style.latextype) {
2900 case LATEX_PARAGRAPH:
2901 if(style.latexname() != "dummy")
2902 sgmlOpenTag(ofs, depth+command_depth,
2908 LinuxDocError(par, 0,
2909 _("Error : Wrong depth for "
2910 "LatexType Command.\n"));
2912 command_name = style.latexname();
2914 tmps = style.latexparam();
2915 c_params = split(tmps, c_depth,'|');
2917 cmd_depth= atoi(c_depth.c_str());
2920 if(cmd_depth<command_base) {
2921 for(int j = command_depth;
2922 j >= command_base; --j)
2923 if(!command_stack[j].empty())
2924 sgmlCloseTag(ofs, j, command_stack[j]);
2925 command_depth= command_base= cmd_depth;
2927 else if(cmd_depth <= command_depth) {
2928 for(int j = command_depth;
2929 j >= cmd_depth; --j)
2931 if(!command_stack[j].empty())
2932 sgmlCloseTag(ofs, j, command_stack[j]);
2933 command_depth= cmd_depth;
2936 command_depth= cmd_depth;
2939 command_depth = command_base = cmd_depth;
2940 command_flag = true;
2942 command_stack[command_depth]= command_name;
2944 // treat label as a special case for
2945 // more WYSIWYM handling.
2946 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2947 Inset * inset = par->GetInset(0);
2948 char lyx_code = inset->LyxCode();
2949 if (lyx_code == Inset::LABEL_CODE){
2950 command_name += " id=\"";
2951 command_name += (static_cast<InsetCommand *>(inset))->getContents();
2952 command_name += "\"";
2957 sgmlOpenTag(ofs, depth+command_depth, command_name);
2958 item_name = "title";
2959 sgmlOpenTag(ofs, depth + 1 + command_depth, item_name);
2962 case LATEX_ENVIRONMENT:
2963 case LATEX_ITEM_ENVIRONMENT:
2964 if (depth < par->depth) {
2966 environment_stack[depth].erase();
2969 if (environment_stack[depth] != style.latexname()) {
2970 environment_stack[depth] = style.latexname();
2971 environment_inner[depth] = "!-- --";
2972 sgmlOpenTag(ofs, depth + command_depth,
2973 environment_stack[depth]);
2975 if(environment_inner[depth] != "!-- --") {
2976 item_name= "listitem";
2978 command_depth + depth,
2980 if (environment_inner[depth] == "varlistentry")
2982 depth + command_depth,
2983 environment_inner[depth]);
2987 if(style.latextype == LATEX_ENVIRONMENT) {
2988 if(!style.latexparam().empty())
2989 sgmlOpenTag(ofs, depth + command_depth,
2990 style.latexparam());
2994 desc_on = (style.labeltype == LABEL_MANUAL);
2997 environment_inner[depth]= "varlistentry";
2999 environment_inner[depth]= "listitem";
3001 sgmlOpenTag(ofs, depth + 1 + command_depth,
3002 environment_inner[depth]);
3006 sgmlOpenTag(ofs, depth + 1 + command_depth,
3011 sgmlOpenTag(ofs, depth + 1 + command_depth,
3016 sgmlOpenTag(ofs, depth + command_depth,
3023 SimpleDocBookOnePar(ofs, extra_par, par, desc_on,
3024 depth + 1 + command_depth);
3026 DocBookHandleFootnote(ofs, par,
3027 depth + 1 + command_depth);
3029 while(par && par->IsDummy());
3032 // write closing SGML tags
3033 switch(style.latextype) {
3036 sgmlCloseTag(ofs, depth + command_depth, end_tag);
3038 case LATEX_ENVIRONMENT:
3039 if(!style.latexparam().empty())
3040 sgmlCloseTag(ofs, depth + command_depth,
3041 style.latexparam());
3043 case LATEX_ITEM_ENVIRONMENT:
3044 if(desc_on == 1) break;
3046 sgmlCloseTag(ofs, depth + 1 + command_depth, end_tag);
3048 case LATEX_PARAGRAPH:
3049 if(style.latexname() != "dummy")
3050 sgmlCloseTag(ofs, depth + command_depth,
3054 sgmlCloseTag(ofs, depth + command_depth,
3061 for(; depth >= 0; --depth) {
3062 if(!environment_stack[depth].empty()) {
3063 if(environment_inner[depth] != "!-- --") {
3064 item_name= "listitem";
3065 sgmlCloseTag(ofs, command_depth + depth,
3067 if( environment_inner[depth] == "varlistentry")
3068 sgmlCloseTag(ofs, depth + command_depth,
3069 environment_inner[depth]);
3072 sgmlCloseTag(ofs, depth + command_depth,
3073 environment_stack[depth]);
3077 for(int j = command_depth; j >= command_base; --j)
3078 if(!command_stack[j].empty())
3079 sgmlCloseTag(ofs, j, command_stack[j]);
3082 sgmlCloseTag(ofs, 0, top_element);
3085 // How to check for successful close
3089 void Buffer::SimpleDocBookOnePar(ostream & os, string & extra,
3090 LyXParagraph * par, int & desc_on,
3094 par->SimpleDocBookOneTablePar(os, extra, desc_on, depth);
3098 bool emph_flag = false;
3100 LyXLayout const & style = textclasslist.Style(params.textclass,
3103 LyXParagraph::size_type main_body;
3104 if (style.labeltype != LABEL_MANUAL)
3107 main_body = par->BeginningOfMainBody();
3109 // gets paragraph main font
3110 LyXFont font1 = main_body > 0 ? style.labelfont : style.font;
3112 int char_line_count = depth;
3113 if(!style.free_spacing)
3114 for (int j = 0; j < depth; ++j)
3117 // parsing main loop
3118 for (LyXParagraph::size_type i = 0;
3119 i < par->size(); ++i) {
3120 LyXFont font2 = par->getFont(i);
3122 // handle <emphasis> tag
3123 if (font1.emph() != font2.emph() && i) {
3124 if (font2.emph() == LyXFont::ON) {
3128 os << "</emphasis>";
3133 char c = par->GetChar(i);
3135 if (c == LyXParagraph::META_INSET) {
3136 Inset * inset = par->GetInset(i);
3138 std::ostringstream ost;
3139 inset->DocBook(ost);
3140 string tmp_out = ost.str().c_str();
3143 inset->DocBook(ost);
3145 char * ctmp = ost.str();
3146 string tmp_out(ctmp);
3150 // This code needs some explanation:
3151 // Two insets are treated specially
3152 // label if it is the first element in a command paragraph
3154 // graphics inside tables or figure floats can't go on
3155 // title (the equivalente in latex for this case is caption
3156 // and title should come first
3159 if(desc_on!= 3 || i!= 0) {
3160 if(!tmp_out.empty() && tmp_out[0] == '@') {
3162 extra += frontStrip(tmp_out, '@');
3164 os << frontStrip(tmp_out, '@');
3169 } else if (font2.latex() == LyXFont::ON) {
3170 // "TeX"-Mode on ==> SGML-Mode on.
3176 if (par->linuxDocConvertChar(c, sgml_string)
3177 && !style.free_spacing) { // in freespacing
3179 // non-breaking characters
3183 os << "\n</term><listitem><para>";
3195 // needed if there is an optional argument but no contents
3196 if (main_body > 0 && main_body == par->size()) {
3200 os << "</emphasis>";
3203 // resets description flag correctly
3206 // <term> not closed...
3214 int Buffer::runLaTeX()
3216 if (!users->text) return 0;
3218 ProhibitInput(users);
3220 // get LaTeX-Filename
3221 string name = getLatexName();
3223 string path = OnlyPath(filename);
3225 string org_path = path;
3226 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3230 Path p(path); // path to LaTeX file
3231 users->owner()->getMiniBuffer()->Set(_("Running LaTeX..."));
3233 // Remove all error insets
3234 bool a = users->removeAutoInsets();
3236 // Always generate the LaTeX file
3237 makeLaTeXFile(name, org_path, false);
3240 // do the LaTex run(s)
3242 string latex_command = lyxrc.pdf_mode ?
3243 lyxrc.pdflatex_command : lyxrc.latex_command;
3244 LaTeX latex(latex_command, name, filepath);
3245 int res = latex.run(terr,
3246 users->owner()->getMiniBuffer()); // running latex
3248 // check return value from latex.run().
3249 if ((res & LaTeX::NO_LOGFILE)) {
3250 WriteAlert(_("LaTeX did not work!"),
3251 _("Missing log file:"), name);
3252 } else if ((res & LaTeX::ERRORS)) {
3253 users->owner()->getMiniBuffer()->Set(_("Done"));
3254 // Insert all errors as errors boxes
3255 users->insertErrors(terr);
3257 // Dvi should also be kept dirty if the latex run
3258 // ends up with errors. However it should be possible
3259 // to view a dirty dvi too.
3261 //no errors or any other things to think about so:
3262 users->owner()->getMiniBuffer()->Set(_("Done"));
3266 // if we removed error insets before we ran LaTeX or if we inserted
3267 // error insets after we ran LaTeX this must be run:
3268 if (a || (res & LaTeX::ERRORS)){
3271 //users->updateScrollbar();
3275 return latex.getNumErrors();
3279 int Buffer::runLiterate()
3281 if (!users->text) return 0;
3283 ProhibitInput(users);
3285 // get LaTeX-Filename
3286 string name = getLatexName();
3287 // get Literate-Filename
3288 string lit_name = ChangeExtension (getLatexName(),
3289 lyxrc.literate_extension, true);
3291 string path = OnlyPath(filename);
3293 string org_path = path;
3294 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3298 Path p(path); // path to Literate file
3299 users->owner()->getMiniBuffer()->Set(_("Running Literate..."));
3301 // Remove all error insets
3302 bool a = users->removeAutoInsets();
3304 // generate the Literate file if necessary
3305 if (!isDviClean() || a) {
3306 makeLaTeXFile(lit_name, org_path, false);
3310 string latex_command = lyxrc.pdf_mode ?
3311 lyxrc.pdflatex_command : lyxrc.latex_command;
3312 Literate literate(latex_command, name, filepath,
3314 lyxrc.literate_command, lyxrc.literate_error_filter,
3315 lyxrc.build_command, lyxrc.build_error_filter);
3317 int res = literate.weave(terr, users->owner()->getMiniBuffer());
3319 // check return value from literate.weave().
3320 if ((res & Literate::NO_LOGFILE)) {
3321 WriteAlert(_("Literate command did not work!"),
3322 _("Missing log file:"), name);
3323 } else if ((res & Literate::ERRORS)) {
3324 users->owner()->getMiniBuffer()->Set(_("Done"));
3325 // Insert all errors as errors boxes
3326 users->insertErrors(terr);
3328 // Dvi should also be kept dirty if the latex run
3329 // ends up with errors. However it should be possible
3330 // to view a dirty dvi too.
3332 //no errors or any other things to think about so:
3333 users->owner()->getMiniBuffer()->Set(_("Done"));
3337 // if we removed error insets before we ran LaTeX or if we inserted
3338 // error insets after we ran LaTeX this must be run:
3339 if (a || (res & Literate::ERRORS)){
3342 //users->updateScrollbar();
3346 return literate.getNumErrors();
3350 int Buffer::buildProgram()
3352 if (!users->text) return 0;
3354 ProhibitInput(users);
3356 // get LaTeX-Filename
3357 string name = getLatexName();
3358 // get Literate-Filename
3359 string lit_name = ChangeExtension(getLatexName(),
3360 lyxrc.literate_extension, true);
3362 string path = OnlyPath(filename);
3364 string org_path = path;
3365 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3369 Path p(path); // path to Literate file
3370 users->owner()->getMiniBuffer()->Set(_("Building Program..."));
3372 // Remove all error insets
3373 bool a = users->removeAutoInsets();
3375 // generate the LaTeX file if necessary
3376 if (!isNwClean() || a) {
3377 makeLaTeXFile(lit_name, org_path, false);
3381 string latex_command = lyxrc.pdf_mode ?
3382 lyxrc.pdflatex_command : lyxrc.latex_command;
3383 Literate literate(latex_command, name, filepath,
3385 lyxrc.literate_command, lyxrc.literate_error_filter,
3386 lyxrc.build_command, lyxrc.build_error_filter);
3388 int res = literate.build(terr, users->owner()->getMiniBuffer());
3390 // check return value from literate.build().
3391 if ((res & Literate::NO_LOGFILE)) {
3392 WriteAlert(_("Build did not work!"),
3393 _("Missing log file:"), name);
3394 } else if ((res & Literate::ERRORS)) {
3395 users->owner()->getMiniBuffer()->Set(_("Done"));
3396 // Insert all errors as errors boxes
3397 users->insertErrors(terr);
3399 // Literate files should also be kept dirty if the literate
3400 // command run ends up with errors.
3402 //no errors or any other things to think about so:
3403 users->owner()->getMiniBuffer()->Set(_("Done"));
3407 // if we removed error insets before we ran Literate/Build or
3408 // if we inserted error insets after we ran Literate/Build this
3410 if (a || (res & Literate::ERRORS)){
3413 //users->updateScrollbar();
3417 return literate.getNumErrors();
3421 // This should be enabled when the Chktex class is implemented. (Asger)
3422 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
3423 // Other flags: -wall -v0 -x
3424 int Buffer::runChktex()
3426 if (!users->text) return 0;
3428 ProhibitInput(users);
3430 // get LaTeX-Filename
3431 string name = getLatexName();
3432 string path = OnlyPath(filename);
3434 string org_path = path;
3435 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3439 Path p(path); // path to LaTeX file
3440 users->owner()->getMiniBuffer()->Set(_("Running chktex..."));
3442 // Remove all error insets
3443 bool a = users->removeAutoInsets();
3445 // Generate the LaTeX file if neccessary
3446 if (!isDviClean() || a) {
3447 makeLaTeXFile(name, org_path, false);
3452 Chktex chktex(lyxrc.chktex_command, name, filepath);
3453 int res = chktex.run(terr); // run chktex
3456 WriteAlert(_("chktex did not work!"),
3457 _("Could not run with file:"), name);
3458 } else if (res > 0) {
3459 // Insert all errors as errors boxes
3460 users->insertErrors(terr);
3463 // if we removed error insets before we ran chktex or if we inserted
3464 // error insets after we ran chktex, this must be run:
3468 //users->updateScrollbar();
3477 void Buffer::RoffAsciiTable(ostream & os, LyXParagraph * par)
3479 LyXFont font1(LyXFont::ALL_INHERIT,params.language_info);
3482 LyXParagraph::size_type i;
3486 string fname1 = TmpFileName(string(), "RAT1");
3487 string fname2 = TmpFileName(string(), "RAT2");
3489 ofstream ofs(fname1.c_str());
3491 WriteAlert(_("LYX_ERROR:"),
3492 _("Cannot open temporary file:"), fname1);
3495 par->table->RoffEndOfCell(ofs, -1);
3496 for (i = 0; i < par->size(); ++i) {
3497 c = par->GetChar(i);
3498 if (par->table->IsContRow(cell)) {
3499 if (c == LyXParagraph::META_NEWLINE)
3503 font2 = par->GetFontSettings(i);
3504 if (font1.latex() != font2.latex()) {
3505 if (font2.latex() != LyXFont::OFF)
3509 case LyXParagraph::META_INSET:
3510 if ((inset = par->GetInset(i))) {
3512 stringstresm ss(ios::in | ios::out);
3539 case LyXParagraph::META_NEWLINE:
3540 if (par->table->CellHasContRow(cell)>= 0)
3541 par->RoffContTableRows(ofs, i+1, cell);
3542 par->table->RoffEndOfCell(ofs, cell);
3545 case LyXParagraph::META_HFILL:
3555 << "RoffAsciiTable:"
3556 " NULL char in structure." << endl;
3560 par->table->RoffEndOfCell(ofs, cell);
3562 string cmd = lyxrc.ascii_roff_command + " >" + fname2;
3563 cmd = subst(cmd, "$$FName", fname1);
3564 Systemcalls one(Systemcalls::System, cmd);
3565 if (!(lyxerr.debugging(Debug::ROFF))) {
3566 remove(fname1.c_str());
3568 ifstream ifs(fname2.c_str());
3570 WriteFSAlert(_("Error! Can't open temporary file:"), fname2);
3573 // now output the produced file
3577 WriteAlert(_("Error!"),
3578 _("Error executing *roff command on table"));
3579 // overread leading blank lines
3580 while(!ifs && (c == '\n'))
3583 for(j = 0; j < par->depth; ++j)
3585 while(!ifs && (c != '\n')) {
3590 // overread trailing blank lines
3591 while(!ifs && (c == '\n'))
3595 remove(fname2.c_str());
3600 /// changed Heinrich Bauer, 23/03/98
3601 bool Buffer::isDviClean() const
3603 if (lyxrc.use_tempdir)
3604 return dvi_clean_tmpd;
3606 return dvi_clean_orgd;
3610 /// changed Heinrich Bauer, 23/03/98
3611 void Buffer::markDviClean()
3613 if (lyxrc.use_tempdir)
3614 dvi_clean_tmpd = true;
3616 dvi_clean_orgd = true;
3620 /// changed Heinrich Bauer, 23/03/98
3621 void Buffer::markDviDirty()
3623 if (lyxrc.use_tempdir)
3624 dvi_clean_tmpd = false;
3626 dvi_clean_orgd = false;
3630 void Buffer::validate(LaTeXFeatures & features) const
3632 LyXParagraph * par = paragraph;
3633 LyXTextClass const & tclass =
3634 textclasslist.TextClass(params.textclass);
3636 // AMS Style is at document level
3638 features.amsstyle = (params.use_amsmath ||
3639 tclass.provides(LyXTextClass::amsmath));
3642 // We don't use "lyxerr.debug" because of speed. (Asger)
3643 if (lyxerr.debugging(Debug::LATEX))
3644 lyxerr << "Paragraph: " << par << endl;
3646 // Now just follow the list of paragraphs and run
3647 // validate on each of them.
3648 par->validate(features);
3650 // and then the next paragraph
3654 // the bullet shapes are buffer level not paragraph level
3655 // so they are tested here
3656 for (int i = 0; i < 4; ++i) {
3657 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
3658 int font = params.user_defined_bullets[i].getFont();
3661 .user_defined_bullets[i]
3668 features.latexsym = true;
3672 features.amssymb = true;
3674 else if ((font >= 2 && font <= 5)) {
3675 features.pifont = true;
3680 if (lyxerr.debugging(Debug::LATEX)) {
3681 features.showStruct();
3686 void Buffer::setPaperStuff()
3688 params.papersize = BufferParams::PAPER_DEFAULT;
3689 char c1 = params.paperpackage;
3690 if (c1 == BufferParams::PACKAGE_NONE) {
3691 char c2 = params.papersize2;
3692 if (c2 == BufferParams::VM_PAPER_USLETTER)
3693 params.papersize = BufferParams::PAPER_USLETTER;
3694 else if (c2 == BufferParams::VM_PAPER_USLEGAL)
3695 params.papersize = BufferParams::PAPER_LEGALPAPER;
3696 else if (c2 == BufferParams::VM_PAPER_USEXECUTIVE)
3697 params.papersize = BufferParams::PAPER_EXECUTIVEPAPER;
3698 else if (c2 == BufferParams::VM_PAPER_A3)
3699 params.papersize = BufferParams::PAPER_A3PAPER;
3700 else if (c2 == BufferParams::VM_PAPER_A4)
3701 params.papersize = BufferParams::PAPER_A4PAPER;
3702 else if (c2 == BufferParams::VM_PAPER_A5)
3703 params.papersize = BufferParams::PAPER_A5PAPER;
3704 else if ((c2 == BufferParams::VM_PAPER_B3) || (c2 == BufferParams::VM_PAPER_B4) ||
3705 (c2 == BufferParams::VM_PAPER_B5))
3706 params.papersize = BufferParams::PAPER_B5PAPER;
3707 } else if ((c1 == BufferParams::PACKAGE_A4) || (c1 == BufferParams::PACKAGE_A4WIDE) ||
3708 (c1 == BufferParams::PACKAGE_WIDEMARGINSA4))
3709 params.papersize = BufferParams::PAPER_A4PAPER;
3713 // This function should be in Buffer because it's a buffer's property (ale)
3714 string Buffer::getIncludeonlyList(char delim)
3717 LyXParagraph * par = paragraph;
3718 LyXParagraph::size_type pos;
3722 while ((inset = par->ReturnNextInsetPointer(pos))){
3723 if (inset->LyxCode() == Inset::INCLUDE_CODE) {
3724 InsetInclude * insetinc =
3725 static_cast<InsetInclude*>(inset);
3726 if (insetinc->isInclude()
3727 && insetinc->isNoLoad()) {
3730 lst += ChangeExtension(insetinc->getContents(), string(), true);
3737 lyxerr.debug() << "Includeonly(" << lst << ')' << endl;
3742 // This is also a buffer property (ale)
3743 string Buffer::getReferenceList(char delim)
3745 /// if this is a child document and the parent is already loaded
3746 /// Use the parent's list instead [ale990407]
3747 if (!params.parentname.empty()
3748 && bufferlist.exists(params.parentname)) {
3749 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3751 return tmp->getReferenceList(delim);
3754 LyXParagraph * par = paragraph;
3755 LyXParagraph::size_type pos;
3760 while ((inset = par->ReturnNextInsetPointer(pos))){
3761 for (int i = 0; i < inset->GetNumberOfLabels(); ++i) {
3764 lst += inset->getLabel(i);
3770 lyxerr.debug() << "References(" << lst << ")" << endl;
3775 // This is also a buffer property (ale)
3776 string Buffer::getBibkeyList(char delim)
3778 /// if this is a child document and the parent is already loaded
3779 /// Use the parent's list instead [ale990412]
3780 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3781 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3783 return tmp->getBibkeyList(delim);
3787 LyXParagraph * par = paragraph;
3790 if (!bibkeys.empty())
3792 bibkeys += par->bibkey->getContents();
3797 // Might be either using bibtex or a child has bibliography
3798 if (bibkeys.empty()) {
3802 LyXParagraph::size_type pos = -1;
3804 // Search for Bibtex or Include inset
3805 while ((inset = par->ReturnNextInsetPointer(pos))) {
3806 if (inset-> LyxCode() == Inset::BIBTEX_CODE) {
3807 if (!bibkeys.empty())
3809 bibkeys += static_cast<InsetBibtex*>(inset)->getKeys(delim);
3810 } else if (inset-> LyxCode() == Inset::INCLUDE_CODE) {
3811 string bk = static_cast<InsetInclude*>(inset)->getKeys(delim);
3813 if (!bibkeys.empty())
3824 lyxerr.debug() << "Bibkeys(" << bibkeys << ")" << endl;
3829 bool Buffer::isDepClean(string const & name) const
3831 DEPCLEAN * item = dep_clean;
3832 while (item && item->master != name)
3834 if (!item) return true;
3839 void Buffer::markDepClean(string const & name)
3842 dep_clean = new DEPCLEAN;
3843 dep_clean->clean = true;
3844 dep_clean->master = name;
3845 dep_clean->next = 0;
3847 DEPCLEAN* item = dep_clean;
3848 while (item && item->master != name)
3853 item = new DEPCLEAN;
3855 item->master = name;
3862 bool Buffer::Dispatch(string const & command)
3864 // Split command string into command and argument
3865 string cmd, line = frontStrip(command);
3866 string arg = strip(frontStrip(split(line, cmd, ' ')));
3868 return Dispatch(lyxaction.LookupFunc(cmd.c_str()), arg.c_str());
3872 bool Buffer::Dispatch(int action, string const & argument)
3874 bool dispatched = true;
3877 MenuExport(this, argument);
3887 void Buffer::ChangeLanguage(Language const * from, Language const * to)
3890 LyXParagraph * par = paragraph;
3892 par->ChangeLanguage(from, to);
3898 bool Buffer::isMultiLingual()
3901 LyXParagraph * par = paragraph;
3903 if (par->isMultiLingual())