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 par->InsertChar(pos, ' ');
992 par->SetFont(pos, font);
994 lex.printError("Token `$$Token' "
996 "paragraph layout!");
1001 Inset * inset = new InsetSpecialChar;
1003 par->InsertChar(pos, LyXParagraph::META_INSET);
1004 par->InsertInset(pos, inset);
1005 par->SetFont(pos, font);
1009 } else if (token == "\\Figure") {
1010 lyxerr << "Figure" << endl;
1011 Inset * inset = new InsetFig(100, 100, this);
1013 par->InsertChar(pos, LyXParagraph::META_INSET);
1014 par->InsertInset(pos, inset);
1015 par->SetFont(pos, font);
1018 } else if (token == "\\newline") {
1019 par->InsertChar(pos, LyXParagraph::META_NEWLINE);
1020 par->SetFont(pos, font);
1022 } else if (token == "\\LyXTable") {
1023 par->table = new LyXTable(lex);
1024 } else if (token == "\\hfill") {
1025 par->InsertChar(pos, LyXParagraph::META_HFILL);
1026 par->SetFont(pos, font);
1028 } else if (token == "\\protected_separator") { // obsolete
1029 // This is a backward compability thingie. (Lgb)
1030 // Remove it later some time...introduced with fileformat
1032 LyXLayout const & layout =
1033 textclasslist.Style(params.textclass,
1036 if (layout.free_spacing) {
1037 par->InsertChar(pos, ' ');
1038 par->SetFont(pos, font);
1040 Inset * inset = new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
1041 par->InsertChar(pos, LyXParagraph::META_INSET);
1042 par->InsertInset(pos, inset);
1043 par->SetFont(pos, font);
1046 } else if (token == "\\bibitem") { // ale970302
1048 par->bibkey = new InsetBibKey;
1049 par->bibkey->Read(lex);
1050 }else if (token == "\\backslash") {
1051 par->InsertChar(pos, '\\');
1052 par->SetFont(pos, font);
1054 }else if (token == "\\the_end") {
1055 the_end_read = true;
1057 // This should be insurance for the future: (Asger)
1058 lex.printError("Unknown token `$$Token'. "
1059 "Inserting as text.");
1060 for(string::const_iterator cit = token.begin();
1061 cit != token.end(); ++cit) {
1062 par->InsertChar(pos, (*cit));
1063 par->SetFont(pos, font);
1067 return the_end_read;
1070 bool Buffer::readFile(LyXLex & lex, LyXParagraph * par)
1076 token = lex.GetString();
1077 if (token == "\\lyxformat") { // the first token _must_ be...
1079 format = lex.GetFloat();
1081 if (LYX_FORMAT - format > 0.05) {
1082 printf(_("Warning: need lyxformat %.2f but found %.2f\n"),
1083 LYX_FORMAT, format);
1085 if (format - LYX_FORMAT > 0.05) {
1086 printf(_("ERROR: need lyxformat %.2f but found %.2f\n"),
1087 LYX_FORMAT, format);
1089 bool the_end = readLyXformat2(lex, par);
1090 // Formats >= 2.13 support "\the_end" marker
1097 WriteAlert(_("Warning!"),
1098 _("Reading of document is not complete"),
1099 _("Maybe the document is truncated"));
1100 // We simulate a safe reading anyways to allow
1101 // users to take the chance... (Asger)
1105 WriteAlert(_("ERROR!"),
1106 _("Old LyX file format found. "
1107 "Use LyX 0.10.x to read this!"));
1111 } else { // "\\lyxformat" not found
1112 WriteAlert(_("ERROR!"), _("Not a LyX file!"));
1115 WriteAlert(_("ERROR!"), _("Unable to read file!"));
1121 // Should probably be moved to somewhere else: BufferView? LyXView?
1122 bool Buffer::save() const
1124 // We don't need autosaves in the immediate future. (Asger)
1125 resetAutosaveTimers();
1129 if (lyxrc.make_backup) {
1130 s = fileName() + '~';
1131 if (!lyxrc.backupdir_path.empty())
1132 s = AddName(lyxrc.backupdir_path,
1133 subst(CleanupPath(s),'/','!'));
1135 // Rename is the wrong way of making a backup,
1136 // this is the correct way.
1137 /* truss cp fil fil2:
1138 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
1139 stat("LyXVC.lyx", 0xEFFFF688) = 0
1140 open("LyXVC.lyx", O_RDONLY) = 3
1141 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
1142 fstat(4, 0xEFFFF508) = 0
1143 fstat(3, 0xEFFFF508) = 0
1144 read(3, " # T h i s f i l e w".., 8192) = 5579
1145 write(4, " # T h i s f i l e w".., 5579) = 5579
1146 read(3, 0xEFFFD4A0, 8192) = 0
1149 chmod("LyXVC3.lyx", 0100644) = 0
1150 lseek(0, 0, SEEK_CUR) = 46440
1154 // Should proabaly have some more error checking here.
1155 // Should be cleaned up in 0.13, at least a bit.
1156 // Doing it this way, also makes the inodes stay the same.
1157 // This is still not a very good solution, in particular we
1158 // might loose the owner of the backup.
1159 FileInfo finfo(fileName());
1160 if (finfo.exist()) {
1161 mode_t fmode = finfo.getMode();
1162 struct utimbuf times = {
1163 finfo.getAccessTime(),
1164 finfo.getModificationTime() };
1166 ifstream ifs(fileName().c_str());
1167 ofstream ofs(s.c_str(), ios::out|ios::trunc);
1172 ::chmod(s.c_str(), fmode);
1174 if (::utime(s.c_str(), ×)) {
1175 lyxerr << "utime error." << endl;
1178 lyxerr << "LyX was not able to make "
1179 "backupcopy. Beware." << endl;
1184 if (writeFile(fileName(), false)) {
1187 // now delete the autosavefile
1188 string a = OnlyPath(fileName());
1190 a += OnlyFilename(fileName());
1192 FileInfo fileinfo(a);
1193 if (fileinfo.exist()) {
1194 if (::remove(a.c_str()) != 0) {
1195 WriteFSAlert(_("Could not delete "
1196 "auto-save file!"), a);
1200 // Saving failed, so backup is not backup
1201 if (lyxrc.make_backup) {
1202 ::rename(s.c_str(), fileName().c_str());
1210 // Returns false if unsuccesful
1211 bool Buffer::writeFile(string const & fname, bool flag) const
1213 // if flag is false writeFile will not create any GUI
1214 // warnings, only cerr.
1215 // Needed for autosave in background or panic save (Matthias 120496)
1217 if (read_only && (fname == filename)) {
1218 // Here we should come with a question if we should
1219 // perform the write anyway.
1221 lyxerr << _("Error! Document is read-only: ")
1224 WriteAlert(_("Error! Document is read-only: "),
1229 FileInfo finfo(fname);
1230 if (finfo.exist() && !finfo.writable()) {
1231 // Here we should come with a question if we should
1232 // try to do the save anyway. (i.e. do a chmod first)
1234 lyxerr << _("Error! Cannot write file: ")
1237 WriteFSAlert(_("Error! Cannot write file: "),
1242 ofstream ofs(fname.c_str());
1245 lyxerr << _("Error! Cannot open file: ")
1248 WriteFSAlert(_("Error! Cannot open file: "),
1252 // The top of the file should not be written by params.
1254 // write out a comment in the top of the file
1255 ofs << '#' << LYX_DOCVERSION
1256 << " created this file. For more info see http://www.lyx.org/\n";
1257 ofs.setf(ios::showpoint|ios::fixed);
1259 ofs << "\\lyxformat " << setw(4) << LYX_FORMAT << "\n";
1261 // now write out the buffer paramters.
1262 params.writeFile(ofs);
1264 char footnoteflag = 0;
1267 // this will write out all the paragraphs
1268 // using recursive descent.
1269 paragraph->writeFile(ofs, params, footnoteflag, depth);
1271 // Write marker that shows file is complete
1272 ofs << "\n\\the_end" << endl;
1274 // how to check if close went ok?
1279 void Buffer::writeFileAscii(string const & fname, int linelen)
1281 LyXFont font1, font2;
1283 char c, footnoteflag = 0, depth = 0;
1285 LyXParagraph::size_type i;
1286 int j, h, ltype = 0, ltype_depth = 0,
1287 * clen = 0, actcell = 0, actpos = 0, cell = 0, cells = 0,
1290 bool ref_printed = false;
1292 ofstream ofs(fname.c_str());
1294 WriteFSAlert(_("Error: Cannot write file:"), fname);
1298 string fname1 = TmpFileName();
1299 LyXParagraph * par = paragraph;
1303 if (par->footnoteflag != LyXParagraph::NO_FOOTNOTE ||
1305 par->previous->footnoteflag == LyXParagraph::NO_FOOTNOTE){
1307 /* begins a footnote environment ? */
1308 if (footnoteflag != par->footnoteflag) {
1309 footnoteflag = par->footnoteflag;
1311 j = strlen(string_footnotekinds[par->footnotekind])+4;
1312 if (currlinelen + j > linelen)
1315 << string_footnotekinds[par->footnotekind] << "] ";
1320 /* begins or ends a deeper area ?*/
1321 if (depth != par->depth) {
1322 if (par->depth > depth) {
1323 while (par->depth > depth) {
1328 while (par->depth < depth) {
1334 /* First write the layout */
1335 tmp = textclasslist.NameOfLayout(params.textclass, par->layout);
1336 if (tmp == "Itemize") {
1338 ltype_depth = depth+1;
1339 } else if (tmp == "Enumerate") {
1341 ltype_depth = depth+1;
1342 } else if (strstr(tmp.c_str(), "ection")) {
1344 ltype_depth = depth+1;
1345 } else if (strstr(tmp.c_str(), "aragraph")) {
1347 ltype_depth = depth+1;
1348 } else if (tmp == "Description") {
1350 ltype_depth = depth+1;
1351 } else if (tmp == "Abstract") {
1354 } else if (tmp == "Bibliography") {
1362 /* maybe some vertical spaces */
1364 /* the labelwidthstring used in lists */
1368 /* some pagebreaks? */
1372 /* what about the alignment */
1374 /* dummy layout, that means a footnote ended */
1375 footnoteflag = LyXParagraph::NO_FOOTNOTE;
1380 //LyXLayout const & layout =
1381 // textclasslist.Style(params.textclass,
1382 // par->GetLayout()); // unused
1383 //bool free_spc = layout.free_spacing; //unused
1385 /* It might be a table */
1388 if (!lyxrc.ascii_roff_command.empty() &&
1389 lyxrc.ascii_roff_command != "none") {
1390 RoffAsciiTable(ofs, par);
1397 cells = par->table->columns;
1398 clen = new int [cells];
1399 memset(clen, 0, sizeof(int) * cells);
1401 for (i = 0, j = 0, h = 1; i < par->size(); ++i, ++h) {
1402 c = par->GetChar(i);
1403 if (c == LyXParagraph::META_INSET) {
1404 if ((inset = par->GetInset(i))) {
1406 std::ostringstream ost;
1408 h += ost.str().length();
1413 char * tmp = ost.str();
1419 } else if (c == LyXParagraph::META_NEWLINE) {
1423 j = (++j) % par->table->NumberOfCellsInRow(actcell);
1431 font1 = LyXFont(LyXFont::ALL_INHERIT, params.language_info);
1433 for (i = 0, actpos = 1; i < par->size(); ++i, ++actpos) {
1434 if (!i && !footnoteflag && !noparbreak){
1436 for(j = 0; j < depth; ++j)
1438 currlinelen = depth * 2;
1440 case 0: /* Standard */
1441 case 4: /* (Sub)Paragraph */
1442 case 5: /* Description */
1444 case 6: /* Abstract */
1445 ofs << "Abstract\n\n";
1447 case 7: /* Bibliography */
1449 ofs << "References\n\n";
1454 ofs << par->labelstring << " ";
1457 if (ltype_depth > depth) {
1458 for(j = ltype_depth - 1; j > depth; --j)
1460 currlinelen += (ltype_depth-depth)*2;
1463 for(j = 0; j < cells; ++j) {
1465 for(h = 0; h < (clen[j] + 1);
1470 for(j = 0; j < depth; ++j)
1472 currlinelen = depth * 2;
1473 if (ltype_depth > depth) {
1474 for(j = ltype_depth;
1477 currlinelen += (ltype_depth-depth)*2;
1482 font2 = par->GetFontSettings(i);
1483 if (font1.latex() != font2.latex()) {
1484 if (font2.latex() == LyXFont::OFF)
1491 c = par->GetChar(i);
1495 case LyXParagraph::META_INSET:
1496 if ((inset = par->GetInset(i))) {
1499 currlinelen += (ofs.tellp() - fpos);
1500 actpos += (ofs.tellp() - fpos) - 1;
1503 case LyXParagraph::META_NEWLINE:
1505 if (par->table->NumberOfCellsInRow(actcell) <= cell) {
1506 for(j = actpos; j < clen[cell - 1]; ++j)
1509 for(j = 0; j < depth; ++j)
1511 currlinelen = depth*2;
1512 if (ltype_depth > depth) {
1513 for(j = ltype_depth; j > depth; --j)
1515 currlinelen += (ltype_depth-depth) * 2;
1517 for(j = 0; j < cells; ++j) {
1519 for(h = 0; h < (clen[j] + 1); ++h)
1523 for(j = 0; j < depth; ++j)
1525 currlinelen = depth * 2;
1526 if (ltype_depth > depth) {
1527 for(j = ltype_depth;
1530 currlinelen += (ltype_depth-depth)*2;
1536 j < clen[cell - 1]; ++j)
1542 currlinelen = actpos = 0;
1545 for(j = 0; j < depth; ++j)
1547 currlinelen = depth * 2;
1548 if (ltype_depth > depth) {
1549 for(j = ltype_depth;
1552 currlinelen += (ltype_depth - depth) * 2;
1556 case LyXParagraph::META_HFILL:
1563 if (currlinelen > linelen - 10
1564 && c == ' ' && i + 2 < par->size()) {
1566 for(j = 0; j < depth; ++j)
1568 currlinelen = depth * 2;
1569 if (ltype_depth > depth) {
1570 for(j = ltype_depth;
1573 currlinelen += (ltype_depth-depth)*2;
1575 } else if (c != '\0')
1578 lyxerr.debug() << "writeAsciiFile: NULL char in structure." << endl;
1584 for(j = actpos; j < clen[cell - 1]; ++j)
1587 for(j = 0; j < depth; ++j)
1589 currlinelen = depth * 2;
1590 if (ltype_depth > depth) {
1591 for(j = ltype_depth; j > depth; --j)
1593 currlinelen += (ltype_depth - depth) * 2;
1595 for(j = 0; j < cells; ++j) {
1597 for(h = 0; h < (clen[j] + 1); ++h)
1610 void Buffer::makeLaTeXFile(string const & fname,
1611 string const & original_path,
1612 bool nice, bool only_body)
1614 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
1616 niceFile = nice; // this will be used by Insetincludes.
1618 tex_code_break_column = lyxrc.ascii_linelen;
1620 LyXTextClass const & tclass =
1621 textclasslist.TextClass(params.textclass);
1623 ofstream ofs(fname.c_str());
1625 WriteFSAlert(_("Error: Cannot open file: "), fname);
1629 // validate the buffer.
1630 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
1631 LaTeXFeatures features(params, tclass.numLayouts());
1633 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
1636 // The starting paragraph of the coming rows is the
1637 // first paragraph of the document. (Asger)
1638 texrow.start(paragraph, 0);
1640 if (!only_body && nice) {
1641 ofs << "%% " LYX_DOCVERSION " created this file. "
1642 "For more info, see http://www.lyx.org/.\n"
1643 "%% Do not edit unless you really know what "
1648 lyxerr.debug() << "lyx header finished" << endl;
1649 // There are a few differences between nice LaTeX and usual files:
1650 // usual is \batchmode and has a
1651 // special input@path to allow the including of figures
1652 // with either \input or \includegraphics (what figinsets do).
1653 // batchmode is not set if there is a tex_code_break_column.
1654 // In this case somebody is interested in the generated LaTeX,
1655 // so this is OK. input@path is set when the actual parameter
1656 // original_path is set. This is done for usual tex-file, but not
1657 // for nice-latex-file. (Matthias 250696)
1660 // code for usual, NOT nice-latex-file
1661 ofs << "\\batchmode\n"; // changed
1662 // from \nonstopmode
1665 if (!original_path.empty()) {
1666 ofs << "\\makeatletter\n"
1667 << "\\def\\input@path{{"
1668 << original_path << "/}}\n"
1669 << "\\makeatother\n";
1675 ofs << "\\documentclass";
1677 string options; // the document class options.
1679 if (tokenPos(tclass.opt_fontsize(), '|', params.fontsize) >= 0) {
1680 // only write if existing in list (and not default)
1681 options += params.fontsize;
1686 if (!params.use_geometry &&
1687 (params.paperpackage == BufferParams::PACKAGE_NONE)) {
1688 switch (params.papersize) {
1689 case BufferParams::PAPER_A4PAPER:
1690 options += "a4paper,";
1692 case BufferParams::PAPER_USLETTER:
1693 options += "letterpaper,";
1695 case BufferParams::PAPER_A5PAPER:
1696 options += "a5paper,";
1698 case BufferParams::PAPER_B5PAPER:
1699 options += "b5paper,";
1701 case BufferParams::PAPER_EXECUTIVEPAPER:
1702 options += "executivepaper,";
1704 case BufferParams::PAPER_LEGALPAPER:
1705 options += "legalpaper,";
1711 if (params.sides != tclass.sides()) {
1712 switch (params.sides) {
1713 case LyXTextClass::OneSide:
1714 options += "oneside,";
1716 case LyXTextClass::TwoSides:
1717 options += "twoside,";
1724 if (params.columns != tclass.columns()) {
1725 if (params.columns == 2)
1726 options += "twocolumn,";
1728 options += "onecolumn,";
1731 if (!params.use_geometry
1732 && params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1733 options += "landscape,";
1735 // language should be a parameter to \documentclass
1736 bool use_babel = false;
1737 if (params.language != "default" ||
1738 !features.UsedLanguages.empty() ) {
1740 for (LaTeXFeatures::LanguageList::const_iterator cit =
1741 features.UsedLanguages.begin();
1742 cit != features.UsedLanguages.end(); ++cit)
1743 options += (*cit)->lang + ",";
1744 options += params.language_info->lang + ',';
1747 // the user-defined options
1748 if (!params.options.empty()) {
1749 options += params.options + ',';
1752 if (!options.empty()){
1753 options = strip(options, ',');
1754 ofs << '[' << options << ']';
1758 << textclasslist.LatexnameOfClass(params.textclass)
1761 // end of \documentclass defs
1763 // font selection must be done before loading fontenc.sty
1764 if (params.fonts != "default") {
1765 ofs << "\\usepackage{" << params.fonts << "}\n";
1768 // this one is not per buffer
1769 if (lyxrc.fontenc != "default") {
1770 ofs << "\\usepackage[" << lyxrc.fontenc
1774 if (params.inputenc != "default") {
1775 ofs << "\\usepackage[" << params.inputenc
1780 // At the very beginning the text parameters.
1781 if (params.paperpackage != BufferParams::PACKAGE_NONE) {
1782 switch (params.paperpackage) {
1783 case BufferParams::PACKAGE_A4:
1784 ofs << "\\usepackage{a4}\n";
1787 case BufferParams::PACKAGE_A4WIDE:
1788 ofs << "\\usepackage{a4wide}\n";
1791 case BufferParams::PACKAGE_WIDEMARGINSA4:
1792 ofs << "\\usepackage[widemargins]{a4}\n";
1797 if (params.use_geometry) {
1798 ofs << "\\usepackage{geometry}\n";
1800 ofs << "\\geometry{verbose";
1801 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1802 ofs << ",landscape";
1803 switch (params.papersize2) {
1804 case BufferParams::VM_PAPER_CUSTOM:
1805 if (!params.paperwidth.empty())
1806 ofs << ",paperwidth="
1807 << params.paperwidth;
1808 if (!params.paperheight.empty())
1809 ofs << ",paperheight="
1810 << params.paperheight;
1812 case BufferParams::VM_PAPER_USLETTER:
1813 ofs << ",letterpaper";
1815 case BufferParams::VM_PAPER_USLEGAL:
1816 ofs << ",legalpaper";
1818 case BufferParams::VM_PAPER_USEXECUTIVE:
1819 ofs << ",executivepaper";
1821 case BufferParams::VM_PAPER_A3:
1824 case BufferParams::VM_PAPER_A4:
1827 case BufferParams::VM_PAPER_A5:
1830 case BufferParams::VM_PAPER_B3:
1833 case BufferParams::VM_PAPER_B4:
1836 case BufferParams::VM_PAPER_B5:
1840 // default papersize ie BufferParams::VM_PAPER_DEFAULT
1841 switch (lyxrc.default_papersize) {
1842 case BufferParams::PAPER_DEFAULT: // keep compiler happy
1843 case BufferParams::PAPER_USLETTER:
1844 ofs << ",letterpaper";
1846 case BufferParams::PAPER_LEGALPAPER:
1847 ofs << ",legalpaper";
1849 case BufferParams::PAPER_EXECUTIVEPAPER:
1850 ofs << ",executivepaper";
1852 case BufferParams::PAPER_A3PAPER:
1855 case BufferParams::PAPER_A4PAPER:
1858 case BufferParams::PAPER_A5PAPER:
1861 case BufferParams::PAPER_B5PAPER:
1866 if (!params.topmargin.empty())
1867 ofs << ",tmargin=" << params.topmargin;
1868 if (!params.bottommargin.empty())
1869 ofs << ",bmargin=" << params.bottommargin;
1870 if (!params.leftmargin.empty())
1871 ofs << ",lmargin=" << params.leftmargin;
1872 if (!params.rightmargin.empty())
1873 ofs << ",rmargin=" << params.rightmargin;
1874 if (!params.headheight.empty())
1875 ofs << ",headheight=" << params.headheight;
1876 if (!params.headsep.empty())
1877 ofs << ",headsep=" << params.headsep;
1878 if (!params.footskip.empty())
1879 ofs << ",footskip=" << params.footskip;
1883 if (params.use_amsmath
1884 && !tclass.provides(LyXTextClass::amsmath)) {
1885 ofs << "\\usepackage{amsmath}\n";
1889 if (tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle) >= 0) {
1890 if (params.pagestyle == "fancy") {
1891 ofs << "\\usepackage{fancyhdr}\n";
1894 ofs << "\\pagestyle{" << params.pagestyle << "}\n";
1898 // We try to load babel late, in case it interferes
1899 // with other packages.
1901 ofs << lyxrc.language_package << endl;
1905 if (params.secnumdepth != tclass.secnumdepth()) {
1906 ofs << "\\setcounter{secnumdepth}{"
1907 << params.secnumdepth
1911 if (params.tocdepth != tclass.tocdepth()) {
1912 ofs << "\\setcounter{tocdepth}{"
1918 if (params.paragraph_separation) {
1919 switch (params.defskip.kind()) {
1920 case VSpace::SMALLSKIP:
1921 ofs << "\\setlength\\parskip{\\smallskipamount}\n";
1923 case VSpace::MEDSKIP:
1924 ofs << "\\setlength\\parskip{\\medskipamount}\n";
1926 case VSpace::BIGSKIP:
1927 ofs << "\\setlength\\parskip{\\bigskipamount}\n";
1929 case VSpace::LENGTH:
1930 ofs << "\\setlength\\parskip{"
1931 << params.defskip.length().asLatexString()
1934 default: // should never happen // Then delete it.
1935 ofs << "\\setlength\\parskip{\\medskipamount}\n";
1940 ofs << "\\setlength\\parindent{0pt}\n";
1944 // Now insert the LyX specific LaTeX commands...
1945 string preamble, tmppreamble;
1947 // The optional packages;
1948 preamble = features.getPackages();
1950 // this might be useful...
1951 preamble += "\n\\makeatletter\n\n";
1953 // Some macros LyX will need
1954 tmppreamble = features.getMacros();
1956 if (!tmppreamble.empty()) {
1957 preamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1958 "LyX specific LaTeX commands.\n"
1959 + tmppreamble + '\n';
1962 // the text class specific preamble
1963 tmppreamble = features.getTClassPreamble();
1964 if (!tmppreamble.empty()) {
1965 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1966 "Textclass specific LaTeX commands.\n"
1967 + tmppreamble + '\n';
1970 /* the user-defined preamble */
1971 if (!params.preamble.empty()) {
1972 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1973 "User specified LaTeX commands.\n"
1974 + params.preamble + '\n';
1977 preamble += "\\makeatother\n\n";
1979 // Itemize bullet settings need to be last in case the user
1980 // defines their own bullets that use a package included
1981 // in the user-defined preamble -- ARRae
1982 // Actually it has to be done much later than that
1983 // since some packages like frenchb make modifications
1984 // at \begin{document} time -- JMarc
1986 for (int i = 0; i < 4; ++i) {
1987 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
1988 if (bullets_def.empty())
1989 bullets_def="\\AtBeginDocument{\n";
1990 bullets_def += " \\renewcommand{\\labelitemi";
1992 // `i' is one less than the item to modify
1999 bullets_def += "ii";
2005 bullets_def += "}{" +
2006 params.user_defined_bullets[i].getText()
2011 if (!bullets_def.empty())
2012 preamble += bullets_def + "}\n\n";
2014 for (int j = countChar(preamble, '\n'); j-- ;) {
2021 ofs << "\\begin{document}\n\n";
2025 lyxerr.debug() << "preamble finished, now the body." << endl;
2026 if (!lyxrc.language_auto_begin && params.language != "default") {
2027 ofs << subst(lyxrc.language_command_begin, "$$lang",
2033 latexParagraphs(ofs, paragraph, 0, texrow);
2035 // add this just in case after all the paragraphs
2039 if (!lyxrc.language_auto_end && params.language != "default") {
2040 ofs << subst(lyxrc.language_command_end, "$$lang",
2047 ofs << "\\end{document}\n";
2050 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
2052 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
2056 // Just to be sure. (Asger)
2059 // tex_code_break_column's value is used to decide
2060 // if we are in batchmode or not (within mathed_write()
2061 // in math_write.C) so we must set it to a non-zero
2062 // value when we leave otherwise we save incorrect .lyx files.
2063 tex_code_break_column = lyxrc.ascii_linelen;
2067 lyxerr << "File was not closed properly." << endl;
2070 lyxerr.debug() << "Finished making latex file." << endl;
2074 // LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
2076 void Buffer::latexParagraphs(ostream & ofs, LyXParagraph *par,
2077 LyXParagraph *endpar, TexRow & texrow)
2079 bool was_title = false;
2080 bool already_title = false;
2082 std::ostringstream ftnote;
2084 char * tmpholder = 0;
2090 while (par != endpar) {
2091 #ifndef HAVE_SSTREAM
2094 ftnote << tmpholder;
2095 delete [] tmpholder;
2100 lyxerr[Debug::LATEX] << "Error in latexParagraphs."
2102 LyXLayout const & layout =
2103 textclasslist.Style(params.textclass,
2106 if (layout.intitle) {
2107 if (already_title) {
2108 lyxerr <<"Error in latexParagraphs: You"
2109 " should not mix title layouts"
2110 " with normal ones." << endl;
2113 } else if (was_title && !already_title) {
2114 ofs << "\\maketitle\n";
2116 already_title = true;
2119 // We are at depth 0 so we can just use
2120 // ordinary \footnote{} generation
2121 // flag this with ftcount
2123 if (layout.isEnvironment()
2124 || par->pextra_type != LyXParagraph::PEXTRA_NONE) {
2125 par = par->TeXEnvironment(ofs, texrow,
2126 ftnote, ft_texrow, ftcount);
2128 par = par->TeXOnePar(ofs, texrow, false,
2129 ftnote, ft_texrow, ftcount);
2132 // Write out what we've generated...
2135 ofs << "\\addtocounter{footnote}{-"
2139 ofs << ftnote.str();
2140 texrow += ft_texrow;
2142 // The extra .c_str() is needed when we use
2143 // lyxstring instead of the STL string class.
2144 ftnote.str(string().c_str());
2146 delete [] ftnote.str();
2151 #ifndef HAVE_SSTREAM
2153 // I hate strstreams
2154 tmpholder = ftnote.str();
2158 #ifndef HAVE_SSTREAM
2159 delete [] tmpholder;
2161 // It might be that we only have a title in this document
2162 if (was_title && !already_title) {
2163 ofs << "\\maketitle\n";
2168 bool Buffer::isLatex() const
2170 return textclasslist.TextClass(params.textclass).outputType() == LATEX;
2174 bool Buffer::isLinuxDoc() const
2176 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC;
2180 bool Buffer::isLiterate() const
2182 return textclasslist.TextClass(params.textclass).outputType() == LITERATE;
2186 bool Buffer::isDocBook() const
2188 return textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2192 bool Buffer::isSGML() const
2194 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC ||
2195 textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2199 void Buffer::sgmlOpenTag(ostream & os, int depth,
2200 string const & latexname) const
2202 os << string(depth, ' ') << "<" << latexname << ">\n";
2206 void Buffer::sgmlCloseTag(ostream & os, int depth,
2207 string const & latexname) const
2209 os << string(depth, ' ') << "</" << latexname << ">\n";
2213 void Buffer::makeLinuxDocFile(string const & fname, int column)
2215 LyXParagraph * par = paragraph;
2217 string top_element = textclasslist.LatexnameOfClass(params.textclass);
2218 string environment_stack[10];
2221 int depth = 0; // paragraph depth
2223 ofstream ofs(fname.c_str());
2226 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2230 tex_code_break_column = column;
2233 if (params.preamble.empty()) {
2234 ofs << "<!doctype linuxdoc system>\n\n";
2237 ofs << "<!doctype linuxdoc system \n [ "
2238 << params.preamble << " \n]>\n\n";
2241 ofs << "<!-- " << LYX_DOCVERSION
2242 << " created this file. For more info see http://www.lyx.org/"
2245 if(params.options.empty())
2246 sgmlOpenTag(ofs, 0, top_element);
2248 string top = top_element;
2250 top += params.options;
2251 sgmlOpenTag(ofs, 0, top);
2255 int desc_on = 0; // description mode
2256 LyXLayout const & style =
2257 textclasslist.Style(users->buffer()->params.textclass,
2259 par->AutoDeleteInsets();
2261 // treat <toc> as a special case for compatibility with old code
2262 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2263 Inset * inset = par->GetInset(0);
2264 char lyx_code = inset->LyxCode();
2265 if (lyx_code == Inset::TOC_CODE){
2266 string temp = "toc";
2267 sgmlOpenTag(ofs, depth, temp);
2270 linuxDocHandleFootnote(ofs, par, depth);
2275 // environment tag closing
2276 for( ; depth > par->depth; --depth) {
2277 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2278 environment_stack[depth].erase();
2281 // write opening SGML tags
2282 switch(style.latextype) {
2283 case LATEX_PARAGRAPH:
2284 if(depth == par->depth
2285 && !environment_stack[depth].empty()) {
2286 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2287 environment_stack[depth].erase();
2293 sgmlOpenTag(ofs, depth, style.latexname());
2298 LinuxDocError(par, 0,
2299 _("Error : Wrong depth for"
2300 " LatexType Command.\n"));
2302 if (!environment_stack[depth].empty()){
2303 sgmlCloseTag(ofs, depth,
2304 environment_stack[depth]);
2308 environment_stack[depth].erase();
2309 sgmlOpenTag(ofs, depth, style.latexname());
2312 case LATEX_ENVIRONMENT:
2313 case LATEX_ITEM_ENVIRONMENT:
2314 if(depth == par->depth
2315 && environment_stack[depth] != style.latexname()
2316 && !environment_stack[depth].empty()) {
2318 sgmlCloseTag(ofs, depth,
2319 environment_stack[depth]);
2320 environment_stack[depth].erase();
2322 if (depth < par->depth) {
2324 environment_stack[depth].erase();
2326 if (environment_stack[depth] != style.latexname()) {
2329 sgmlOpenTag(ofs, depth, temp);
2331 environment_stack[depth] = style.latexname();
2332 sgmlOpenTag(ofs, depth,
2333 environment_stack[depth]);
2335 if(style.latextype == LATEX_ENVIRONMENT) break;
2337 desc_on = (style.labeltype == LABEL_MANUAL);
2344 sgmlOpenTag(ofs, depth + 1, item_name);
2347 sgmlOpenTag(ofs, depth, style.latexname());
2352 SimpleLinuxDocOnePar(ofs, par, desc_on, depth);
2355 linuxDocHandleFootnote(ofs, par, depth);
2357 while(par && par->IsDummy());
2360 // write closing SGML tags
2361 switch(style.latextype) {
2363 case LATEX_ENVIRONMENT:
2364 case LATEX_ITEM_ENVIRONMENT:
2367 sgmlCloseTag(ofs, depth, style.latexname());
2373 for(; depth > 0; --depth)
2374 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2376 if(!environment_stack[depth].empty())
2377 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2380 sgmlCloseTag(ofs, 0, top_element);
2383 // How to check for successful close
2387 void Buffer::linuxDocHandleFootnote(ostream & os, LyXParagraph * & par,
2390 string tag = "footnote";
2392 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2393 sgmlOpenTag(os, depth + 1, tag);
2394 SimpleLinuxDocOnePar(os, par, 0, depth + 1);
2395 sgmlCloseTag(os, depth + 1, tag);
2401 void Buffer::DocBookHandleCaption(ostream & os, string & inner_tag,
2402 int const depth, int desc_on,
2403 LyXParagraph * & par)
2405 LyXParagraph * tpar = par;
2406 while (tpar && (tpar->footnoteflag != LyXParagraph::NO_FOOTNOTE) &&
2407 (tpar->layout != textclasslist.NumberOfLayout(params.textclass,
2411 tpar->layout == textclasslist.NumberOfLayout(params.textclass,
2412 "Caption").second) {
2413 sgmlOpenTag(os, depth + 1, inner_tag);
2415 SimpleDocBookOnePar(os, extra_par, tpar,
2416 desc_on, depth + 2);
2417 sgmlCloseTag(os, depth+1, inner_tag);
2418 if(!extra_par.empty())
2424 void Buffer::DocBookHandleFootnote(ostream & os, LyXParagraph * & par,
2427 string tag, inner_tag;
2428 string tmp_par, extra_par;
2429 bool inner_span = false;
2432 // Someone should give this enum a proper name (Lgb)
2440 SOME_ENUM last = NO_ONE;
2441 SOME_ENUM present = FOOTNOTE_LIKE;
2443 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2444 if(last == present) {
2446 if(!tmp_par.empty()) {
2449 sgmlCloseTag(os, depth + 1, inner_tag);
2450 sgmlOpenTag(os, depth + 1, inner_tag);
2457 if(!inner_tag.empty()) sgmlCloseTag(os, depth + 1,
2459 if(!extra_par.empty()) os << extra_par;
2460 if(!tag.empty()) sgmlCloseTag(os, depth, tag);
2463 switch (par->footnotekind) {
2464 case LyXParagraph::FOOTNOTE:
2465 case LyXParagraph::ALGORITHM:
2468 present = FOOTNOTE_LIKE;
2471 case LyXParagraph::MARGIN:
2474 present = MARGIN_LIKE;
2477 case LyXParagraph::FIG:
2478 case LyXParagraph::WIDE_FIG:
2480 inner_tag = "title";
2484 case LyXParagraph::TAB:
2485 case LyXParagraph::WIDE_TAB:
2487 inner_tag = "title";
2492 sgmlOpenTag(os, depth, tag);
2493 if ((present == TAB_LIKE) || (present == FIG_LIKE)) {
2494 DocBookHandleCaption(os, inner_tag, depth,
2498 sgmlOpenTag(os, depth + 1, inner_tag);
2501 // ignore all caption here, we processed them above!!!
2502 if (par->layout != textclasslist
2503 .NumberOfLayout(params.textclass,
2504 "Caption").second) {
2506 std::ostringstream ost;
2510 SimpleDocBookOnePar(ost, extra_par, par,
2511 desc_on, depth + 2);
2513 tmp_par += ost.str().c_str();
2516 char * ctmp = ost.str();
2521 tmp_par = frontStrip(strip(tmp_par));
2527 if(!inner_tag.empty()) sgmlCloseTag(os, depth + 1, inner_tag);
2528 if(!extra_par.empty()) os << extra_par;
2529 if(!tag.empty()) sgmlCloseTag(os, depth, tag);
2533 // push a tag in a style stack
2534 void Buffer::push_tag(ostream & os, char const * tag,
2535 int & pos, char stack[5][3])
2537 // pop all previous tags
2538 for (int j = pos; j >= 0; --j)
2539 os << "</" << stack[j] << ">";
2542 sprintf(stack[++pos], "%s", tag);
2545 for (int i = 0; i <= pos; ++i)
2546 os << "<" << stack[i] << ">";
2550 void Buffer::pop_tag(ostream & os, char const * tag,
2551 int & pos, char stack[5][3])
2555 // pop all tags till specified one
2556 for (j = pos; (j >= 0) && (strcmp(stack[j], tag)); --j)
2557 os << "</" << stack[j] << ">";
2560 os << "</" << tag << ">";
2562 // push all tags, but the specified one
2563 for (j = j + 1; j <= pos; ++j) {
2564 os << "<" << stack[j] << ">";
2565 strcpy(stack[j-1], stack[j]);
2571 // Handle internal paragraph parsing -- layout already processed.
2573 // checks, if newcol chars should be put into this line
2574 // writes newline, if necessary.
2576 void linux_doc_line_break(ostream & os, unsigned int & colcount,
2577 const unsigned int newcol)
2580 if (colcount > lyxrc.ascii_linelen) {
2582 colcount = newcol; // assume write after this call
2587 void Buffer::SimpleLinuxDocOnePar(ostream & os, LyXParagraph * par,
2588 int desc_on, int const /*depth*/)
2590 LyXFont font1, font2;
2593 LyXParagraph::size_type main_body;
2595 LyXLayout const & style = textclasslist.Style(params.textclass,
2598 char family_type = 0; // family font flag
2599 bool is_bold = false; // series font flag
2600 char shape_type = 0; // shape font flag
2601 bool is_em = false; // emphasis (italic) font flag
2603 int stack_num = -1; // style stack position
2604 // Can this be rewritten to use a std::stack, please. (Lgb)
2605 char stack[5][3]; // style stack
2606 unsigned int char_line_count = 5; // Heuristic choice ;-)
2608 if (style.labeltype != LABEL_MANUAL)
2611 main_body = par->BeginningOfMainBody();
2613 // gets paragraph main font
2615 font1 = style.labelfont;
2620 // parsing main loop
2621 for (LyXParagraph::size_type i = 0;
2622 i < par->size(); ++i) {
2625 if (i == main_body && !par->IsDummy()) {
2630 font2 = par->getFont(i);
2632 if (font1.family() != font2.family()) {
2633 switch(family_type) {
2635 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2636 push_tag(os, "tt", stack_num, stack);
2639 else if (font2.family() == LyXFont::SANS_FAMILY) {
2640 push_tag(os, "sf", stack_num, stack);
2645 pop_tag(os, "tt", stack_num, stack);
2646 if (font2.family() == LyXFont::SANS_FAMILY) {
2647 push_tag(os, "sf", stack_num, stack);
2655 pop_tag(os, "sf", stack_num, stack);
2656 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2657 push_tag(os, "tt", stack_num, stack);
2667 if (font1.series() != font2.series()) {
2668 if (font2.series() == LyXFont::BOLD_SERIES) {
2669 push_tag(os, "bf", stack_num, stack);
2673 pop_tag(os, "bf", stack_num, stack);
2678 // handle italic and slanted fonts
2679 if (font1.shape() != font2.shape()) {
2680 switch(shape_type) {
2682 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2683 push_tag(os, "it", stack_num, stack);
2686 else if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2687 push_tag(os, "sl", stack_num, stack);
2692 pop_tag(os, "it", stack_num, stack);
2693 if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2694 push_tag(os, "sl", stack_num, stack);
2702 pop_tag(os, "sl", stack_num, stack);
2703 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2704 push_tag(os, "it", stack_num, stack);
2713 if (font1.emph() != font2.emph()) {
2714 if (font2.emph() == LyXFont::ON) {
2715 push_tag(os, "em", stack_num, stack);
2718 pop_tag(os, "em", stack_num, stack);
2723 c = par->GetChar(i);
2725 if (font2.latex() == LyXFont::ON) {
2726 // "TeX"-Mode on == > SGML-Mode on.
2728 os << c; // see LaTeX-Generation...
2730 } else if (c == LyXParagraph::META_INSET) {
2731 inset = par->GetInset(i);
2732 inset->Linuxdoc(os);
2735 if (par->linuxDocConvertChar(c, sgml_string)
2736 && !style.free_spacing) { // in freespacing
2738 // non-breaking characters
2742 linux_doc_line_break(os, char_line_count, 6);
2747 linux_doc_line_break(os, char_line_count, 1);
2753 char_line_count += sgml_string.length();
2759 // needed if there is an optional argument but no contents
2760 if (main_body > 0 && main_body == par->size()) {
2764 // pop all defined Styles
2765 for (j = stack_num; j >= 0; --j) {
2766 linux_doc_line_break(os,
2768 3 + strlen(stack[j]));
2769 os << "</" << stack[j] << ">";
2772 // resets description flag correctly
2775 // <tag> not closed...
2776 linux_doc_line_break(os, char_line_count, 6);
2780 // fprintf(file, "</p>");
2786 // Print an error message.
2787 void Buffer::LinuxDocError(LyXParagraph * par, int pos,
2788 char const * message)
2790 InsetError * new_inset;
2792 // insert an error marker in text
2793 new_inset = new InsetError(message);
2794 par->InsertChar(pos, LyXParagraph::META_INSET);
2795 par->InsertInset(pos, new_inset);
2798 // This constant defines the maximum number of
2799 // environment layouts that can be nesteded.
2800 // The same applies for command layouts.
2801 // These values should be more than enough.
2802 // José Matos (1999/07/22)
2804 enum { MAX_NEST_LEVEL = 25};
2806 void Buffer::makeDocBookFile(string const & fname, int column)
2808 LyXParagraph * par = paragraph;
2810 string top_element= textclasslist.LatexnameOfClass(params.textclass);
2811 // Please use a real stack.
2812 string environment_stack[MAX_NEST_LEVEL];
2813 string environment_inner[MAX_NEST_LEVEL];
2814 // Please use a real stack.
2815 string command_stack[MAX_NEST_LEVEL];
2816 bool command_flag= false;
2817 int command_depth= 0, command_base= 0, cmd_depth= 0;
2819 string item_name, command_name;
2820 string c_depth, c_params, tmps;
2822 int depth = 0; // paragraph depth
2824 tex_code_break_column = column;
2826 ofstream ofs(fname.c_str());
2828 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2834 ofs << "<!doctype " << top_element
2835 << " public \"-//OASIS//DTD DocBook V3.1//EN\"";
2837 if (params.preamble.empty())
2840 ofs << "\n [ " << params.preamble << " \n]>\n\n";
2842 ofs << "<!-- DocBook file was created by " << LYX_DOCVERSION
2843 << "\n See http://www.lyx.org/ for more information -->\n";
2845 if(params.options.empty())
2846 sgmlOpenTag(ofs, 0, top_element);
2848 string top = top_element;
2850 top += params.options;
2851 sgmlOpenTag(ofs, 0, top);
2855 int desc_on = 0; // description mode
2856 LyXLayout const & style =
2857 textclasslist.Style(users->buffer()->params.textclass,
2859 par->AutoDeleteInsets();
2861 // environment tag closing
2862 for( ; depth > par->depth; --depth) {
2863 if(environment_inner[depth] != "!-- --") {
2864 item_name= "listitem";
2865 sgmlCloseTag(ofs, command_depth + depth,
2867 if( environment_inner[depth] == "varlistentry")
2868 sgmlCloseTag(ofs, depth+command_depth,
2869 environment_inner[depth]);
2871 sgmlCloseTag(ofs, depth + command_depth,
2872 environment_stack[depth]);
2873 environment_stack[depth].erase();
2874 environment_inner[depth].erase();
2877 if(depth == par->depth
2878 && environment_stack[depth] != style.latexname()
2879 && !environment_stack[depth].empty()) {
2880 if(environment_inner[depth] != "!-- --") {
2881 item_name= "listitem";
2882 sgmlCloseTag(ofs, command_depth+depth,
2884 if( environment_inner[depth] == "varlistentry")
2886 depth + command_depth,
2887 environment_inner[depth]);
2890 sgmlCloseTag(ofs, depth + command_depth,
2891 environment_stack[depth]);
2893 environment_stack[depth].erase();
2894 environment_inner[depth].erase();
2897 // Write opening SGML tags.
2898 switch(style.latextype) {
2899 case LATEX_PARAGRAPH:
2900 if(style.latexname() != "dummy")
2901 sgmlOpenTag(ofs, depth+command_depth,
2907 LinuxDocError(par, 0,
2908 _("Error : Wrong depth for "
2909 "LatexType Command.\n"));
2911 command_name = style.latexname();
2913 tmps = style.latexparam();
2914 c_params = split(tmps, c_depth,'|');
2916 cmd_depth= atoi(c_depth.c_str());
2919 if(cmd_depth<command_base) {
2920 for(int j = command_depth;
2921 j >= command_base; --j)
2922 if(!command_stack[j].empty())
2923 sgmlCloseTag(ofs, j, command_stack[j]);
2924 command_depth= command_base= cmd_depth;
2926 else if(cmd_depth <= command_depth) {
2927 for(int j = command_depth;
2928 j >= cmd_depth; --j)
2930 if(!command_stack[j].empty())
2931 sgmlCloseTag(ofs, j, command_stack[j]);
2932 command_depth= cmd_depth;
2935 command_depth= cmd_depth;
2938 command_depth = command_base = cmd_depth;
2939 command_flag = true;
2941 command_stack[command_depth]= command_name;
2943 // treat label as a special case for
2944 // more WYSIWYM handling.
2945 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2946 Inset * inset = par->GetInset(0);
2947 char lyx_code = inset->LyxCode();
2948 if (lyx_code == Inset::LABEL_CODE){
2949 command_name += " id=\"";
2950 command_name += (static_cast<InsetCommand *>(inset))->getContents();
2951 command_name += "\"";
2956 sgmlOpenTag(ofs, depth+command_depth, command_name);
2957 item_name = "title";
2958 sgmlOpenTag(ofs, depth + 1 + command_depth, item_name);
2961 case LATEX_ENVIRONMENT:
2962 case LATEX_ITEM_ENVIRONMENT:
2963 if (depth < par->depth) {
2965 environment_stack[depth].erase();
2968 if (environment_stack[depth] != style.latexname()) {
2969 environment_stack[depth] = style.latexname();
2970 environment_inner[depth] = "!-- --";
2971 sgmlOpenTag(ofs, depth + command_depth,
2972 environment_stack[depth]);
2974 if(environment_inner[depth] != "!-- --") {
2975 item_name= "listitem";
2977 command_depth + depth,
2979 if (environment_inner[depth] == "varlistentry")
2981 depth + command_depth,
2982 environment_inner[depth]);
2986 if(style.latextype == LATEX_ENVIRONMENT) {
2987 if(!style.latexparam().empty())
2988 sgmlOpenTag(ofs, depth + command_depth,
2989 style.latexparam());
2993 desc_on = (style.labeltype == LABEL_MANUAL);
2996 environment_inner[depth]= "varlistentry";
2998 environment_inner[depth]= "listitem";
3000 sgmlOpenTag(ofs, depth + 1 + command_depth,
3001 environment_inner[depth]);
3005 sgmlOpenTag(ofs, depth + 1 + command_depth,
3010 sgmlOpenTag(ofs, depth + 1 + command_depth,
3015 sgmlOpenTag(ofs, depth + command_depth,
3022 SimpleDocBookOnePar(ofs, extra_par, par, desc_on,
3023 depth + 1 + command_depth);
3025 DocBookHandleFootnote(ofs, par,
3026 depth + 1 + command_depth);
3028 while(par && par->IsDummy());
3031 // write closing SGML tags
3032 switch(style.latextype) {
3035 sgmlCloseTag(ofs, depth + command_depth, end_tag);
3037 case LATEX_ENVIRONMENT:
3038 if(!style.latexparam().empty())
3039 sgmlCloseTag(ofs, depth + command_depth,
3040 style.latexparam());
3042 case LATEX_ITEM_ENVIRONMENT:
3043 if(desc_on == 1) break;
3045 sgmlCloseTag(ofs, depth + 1 + command_depth, end_tag);
3047 case LATEX_PARAGRAPH:
3048 if(style.latexname() != "dummy")
3049 sgmlCloseTag(ofs, depth + command_depth,
3053 sgmlCloseTag(ofs, depth + command_depth,
3060 for(; depth >= 0; --depth) {
3061 if(!environment_stack[depth].empty()) {
3062 if(environment_inner[depth] != "!-- --") {
3063 item_name= "listitem";
3064 sgmlCloseTag(ofs, command_depth + depth,
3066 if( environment_inner[depth] == "varlistentry")
3067 sgmlCloseTag(ofs, depth + command_depth,
3068 environment_inner[depth]);
3071 sgmlCloseTag(ofs, depth + command_depth,
3072 environment_stack[depth]);
3076 for(int j = command_depth; j >= command_base; --j)
3077 if(!command_stack[j].empty())
3078 sgmlCloseTag(ofs, j, command_stack[j]);
3081 sgmlCloseTag(ofs, 0, top_element);
3084 // How to check for successful close
3088 void Buffer::SimpleDocBookOnePar(ostream & os, string & extra,
3089 LyXParagraph * par, int & desc_on,
3093 par->SimpleDocBookOneTablePar(os, extra, desc_on, depth);
3097 bool emph_flag = false;
3099 LyXLayout const & style = textclasslist.Style(params.textclass,
3102 LyXParagraph::size_type main_body;
3103 if (style.labeltype != LABEL_MANUAL)
3106 main_body = par->BeginningOfMainBody();
3108 // gets paragraph main font
3109 LyXFont font1 = main_body > 0 ? style.labelfont : style.font;
3111 int char_line_count = depth;
3112 if(!style.free_spacing)
3113 for (int j = 0; j < depth; ++j)
3116 // parsing main loop
3117 for (LyXParagraph::size_type i = 0;
3118 i < par->size(); ++i) {
3119 LyXFont font2 = par->getFont(i);
3121 // handle <emphasis> tag
3122 if (font1.emph() != font2.emph() && i) {
3123 if (font2.emph() == LyXFont::ON) {
3127 os << "</emphasis>";
3132 char c = par->GetChar(i);
3134 if (c == LyXParagraph::META_INSET) {
3135 Inset * inset = par->GetInset(i);
3137 std::ostringstream ost;
3138 inset->DocBook(ost);
3139 string tmp_out = ost.str().c_str();
3142 inset->DocBook(ost);
3144 char * ctmp = ost.str();
3145 string tmp_out(ctmp);
3149 // This code needs some explanation:
3150 // Two insets are treated specially
3151 // label if it is the first element in a command paragraph
3153 // graphics inside tables or figure floats can't go on
3154 // title (the equivalente in latex for this case is caption
3155 // and title should come first
3158 if(desc_on!= 3 || i!= 0) {
3159 if(!tmp_out.empty() && tmp_out[0] == '@') {
3161 extra += frontStrip(tmp_out, '@');
3163 os << frontStrip(tmp_out, '@');
3168 } else if (font2.latex() == LyXFont::ON) {
3169 // "TeX"-Mode on ==> SGML-Mode on.
3175 if (par->linuxDocConvertChar(c, sgml_string)
3176 && !style.free_spacing) { // in freespacing
3178 // non-breaking characters
3182 os << "\n</term><listitem><para>";
3194 // needed if there is an optional argument but no contents
3195 if (main_body > 0 && main_body == par->size()) {
3199 os << "</emphasis>";
3202 // resets description flag correctly
3205 // <term> not closed...
3213 int Buffer::runLaTeX()
3215 if (!users->text) return 0;
3217 ProhibitInput(users);
3219 // get LaTeX-Filename
3220 string name = getLatexName();
3222 string path = OnlyPath(filename);
3224 string org_path = path;
3225 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3229 Path p(path); // path to LaTeX file
3230 users->owner()->getMiniBuffer()->Set(_("Running LaTeX..."));
3232 // Remove all error insets
3233 bool a = users->removeAutoInsets();
3235 // Always generate the LaTeX file
3236 makeLaTeXFile(name, org_path, false);
3239 // do the LaTex run(s)
3241 string latex_command = lyxrc.pdf_mode ?
3242 lyxrc.pdflatex_command : lyxrc.latex_command;
3243 LaTeX latex(latex_command, name, filepath);
3244 int res = latex.run(terr,
3245 users->owner()->getMiniBuffer()); // running latex
3247 // check return value from latex.run().
3248 if ((res & LaTeX::NO_LOGFILE)) {
3249 WriteAlert(_("LaTeX did not work!"),
3250 _("Missing log file:"), name);
3251 } else if ((res & LaTeX::ERRORS)) {
3252 users->owner()->getMiniBuffer()->Set(_("Done"));
3253 // Insert all errors as errors boxes
3254 users->insertErrors(terr);
3256 // Dvi should also be kept dirty if the latex run
3257 // ends up with errors. However it should be possible
3258 // to view a dirty dvi too.
3260 //no errors or any other things to think about so:
3261 users->owner()->getMiniBuffer()->Set(_("Done"));
3265 // if we removed error insets before we ran LaTeX or if we inserted
3266 // error insets after we ran LaTeX this must be run:
3267 if (a || (res & LaTeX::ERRORS)){
3270 //users->updateScrollbar();
3274 return latex.getNumErrors();
3278 int Buffer::runLiterate()
3280 if (!users->text) return 0;
3282 ProhibitInput(users);
3284 // get LaTeX-Filename
3285 string name = getLatexName();
3286 // get Literate-Filename
3287 string lit_name = ChangeExtension (getLatexName(),
3288 lyxrc.literate_extension, true);
3290 string path = OnlyPath(filename);
3292 string org_path = path;
3293 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3297 Path p(path); // path to Literate file
3298 users->owner()->getMiniBuffer()->Set(_("Running Literate..."));
3300 // Remove all error insets
3301 bool a = users->removeAutoInsets();
3303 // generate the Literate file if necessary
3304 if (!isDviClean() || a) {
3305 makeLaTeXFile(lit_name, org_path, false);
3309 string latex_command = lyxrc.pdf_mode ?
3310 lyxrc.pdflatex_command : lyxrc.latex_command;
3311 Literate literate(latex_command, name, filepath,
3313 lyxrc.literate_command, lyxrc.literate_error_filter,
3314 lyxrc.build_command, lyxrc.build_error_filter);
3316 int res = literate.weave(terr, users->owner()->getMiniBuffer());
3318 // check return value from literate.weave().
3319 if ((res & Literate::NO_LOGFILE)) {
3320 WriteAlert(_("Literate command did not work!"),
3321 _("Missing log file:"), name);
3322 } else if ((res & Literate::ERRORS)) {
3323 users->owner()->getMiniBuffer()->Set(_("Done"));
3324 // Insert all errors as errors boxes
3325 users->insertErrors(terr);
3327 // Dvi should also be kept dirty if the latex run
3328 // ends up with errors. However it should be possible
3329 // to view a dirty dvi too.
3331 //no errors or any other things to think about so:
3332 users->owner()->getMiniBuffer()->Set(_("Done"));
3336 // if we removed error insets before we ran LaTeX or if we inserted
3337 // error insets after we ran LaTeX this must be run:
3338 if (a || (res & Literate::ERRORS)){
3341 //users->updateScrollbar();
3345 return literate.getNumErrors();
3349 int Buffer::buildProgram()
3351 if (!users->text) return 0;
3353 ProhibitInput(users);
3355 // get LaTeX-Filename
3356 string name = getLatexName();
3357 // get Literate-Filename
3358 string lit_name = ChangeExtension(getLatexName(),
3359 lyxrc.literate_extension, true);
3361 string path = OnlyPath(filename);
3363 string org_path = path;
3364 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3368 Path p(path); // path to Literate file
3369 users->owner()->getMiniBuffer()->Set(_("Building Program..."));
3371 // Remove all error insets
3372 bool a = users->removeAutoInsets();
3374 // generate the LaTeX file if necessary
3375 if (!isNwClean() || a) {
3376 makeLaTeXFile(lit_name, org_path, false);
3380 string latex_command = lyxrc.pdf_mode ?
3381 lyxrc.pdflatex_command : lyxrc.latex_command;
3382 Literate literate(latex_command, name, filepath,
3384 lyxrc.literate_command, lyxrc.literate_error_filter,
3385 lyxrc.build_command, lyxrc.build_error_filter);
3387 int res = literate.build(terr, users->owner()->getMiniBuffer());
3389 // check return value from literate.build().
3390 if ((res & Literate::NO_LOGFILE)) {
3391 WriteAlert(_("Build did not work!"),
3392 _("Missing log file:"), name);
3393 } else if ((res & Literate::ERRORS)) {
3394 users->owner()->getMiniBuffer()->Set(_("Done"));
3395 // Insert all errors as errors boxes
3396 users->insertErrors(terr);
3398 // Literate files should also be kept dirty if the literate
3399 // command run ends up with errors.
3401 //no errors or any other things to think about so:
3402 users->owner()->getMiniBuffer()->Set(_("Done"));
3406 // if we removed error insets before we ran Literate/Build or
3407 // if we inserted error insets after we ran Literate/Build this
3409 if (a || (res & Literate::ERRORS)){
3412 //users->updateScrollbar();
3416 return literate.getNumErrors();
3420 // This should be enabled when the Chktex class is implemented. (Asger)
3421 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
3422 // Other flags: -wall -v0 -x
3423 int Buffer::runChktex()
3425 if (!users->text) return 0;
3427 ProhibitInput(users);
3429 // get LaTeX-Filename
3430 string name = getLatexName();
3431 string path = OnlyPath(filename);
3433 string org_path = path;
3434 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3438 Path p(path); // path to LaTeX file
3439 users->owner()->getMiniBuffer()->Set(_("Running chktex..."));
3441 // Remove all error insets
3442 bool a = users->removeAutoInsets();
3444 // Generate the LaTeX file if neccessary
3445 if (!isDviClean() || a) {
3446 makeLaTeXFile(name, org_path, false);
3451 Chktex chktex(lyxrc.chktex_command, name, filepath);
3452 int res = chktex.run(terr); // run chktex
3455 WriteAlert(_("chktex did not work!"),
3456 _("Could not run with file:"), name);
3457 } else if (res > 0) {
3458 // Insert all errors as errors boxes
3459 users->insertErrors(terr);
3462 // if we removed error insets before we ran chktex or if we inserted
3463 // error insets after we ran chktex, this must be run:
3467 //users->updateScrollbar();
3476 void Buffer::RoffAsciiTable(ostream & os, LyXParagraph * par)
3478 LyXFont font1(LyXFont::ALL_INHERIT,params.language_info);
3481 LyXParagraph::size_type i;
3485 string fname1 = TmpFileName(string(), "RAT1");
3486 string fname2 = TmpFileName(string(), "RAT2");
3488 ofstream ofs(fname1.c_str());
3490 WriteAlert(_("LYX_ERROR:"),
3491 _("Cannot open temporary file:"), fname1);
3494 par->table->RoffEndOfCell(ofs, -1);
3495 for (i = 0; i < par->size(); ++i) {
3496 c = par->GetChar(i);
3497 if (par->table->IsContRow(cell)) {
3498 if (c == LyXParagraph::META_NEWLINE)
3502 font2 = par->GetFontSettings(i);
3503 if (font1.latex() != font2.latex()) {
3504 if (font2.latex() != LyXFont::OFF)
3508 case LyXParagraph::META_INSET:
3509 if ((inset = par->GetInset(i))) {
3511 stringstresm ss(ios::in | ios::out);
3538 case LyXParagraph::META_NEWLINE:
3539 if (par->table->CellHasContRow(cell)>= 0)
3540 par->RoffContTableRows(ofs, i+1, cell);
3541 par->table->RoffEndOfCell(ofs, cell);
3544 case LyXParagraph::META_HFILL:
3554 << "RoffAsciiTable:"
3555 " NULL char in structure." << endl;
3559 par->table->RoffEndOfCell(ofs, cell);
3561 string cmd = lyxrc.ascii_roff_command + " >" + fname2;
3562 cmd = subst(cmd, "$$FName", fname1);
3563 Systemcalls one(Systemcalls::System, cmd);
3564 if (!(lyxerr.debugging(Debug::ROFF))) {
3565 remove(fname1.c_str());
3567 ifstream ifs(fname2.c_str());
3569 WriteFSAlert(_("Error! Can't open temporary file:"), fname2);
3572 // now output the produced file
3576 WriteAlert(_("Error!"),
3577 _("Error executing *roff command on table"));
3578 // overread leading blank lines
3579 while(!ifs && (c == '\n'))
3582 for(j = 0; j < par->depth; ++j)
3584 while(!ifs && (c != '\n')) {
3589 // overread trailing blank lines
3590 while(!ifs && (c == '\n'))
3594 remove(fname2.c_str());
3599 /// changed Heinrich Bauer, 23/03/98
3600 bool Buffer::isDviClean() const
3602 if (lyxrc.use_tempdir)
3603 return dvi_clean_tmpd;
3605 return dvi_clean_orgd;
3609 /// changed Heinrich Bauer, 23/03/98
3610 void Buffer::markDviClean()
3612 if (lyxrc.use_tempdir)
3613 dvi_clean_tmpd = true;
3615 dvi_clean_orgd = true;
3619 /// changed Heinrich Bauer, 23/03/98
3620 void Buffer::markDviDirty()
3622 if (lyxrc.use_tempdir)
3623 dvi_clean_tmpd = false;
3625 dvi_clean_orgd = false;
3629 void Buffer::validate(LaTeXFeatures & features) const
3631 LyXParagraph * par = paragraph;
3632 LyXTextClass const & tclass =
3633 textclasslist.TextClass(params.textclass);
3635 // AMS Style is at document level
3637 features.amsstyle = (params.use_amsmath ||
3638 tclass.provides(LyXTextClass::amsmath));
3641 // We don't use "lyxerr.debug" because of speed. (Asger)
3642 if (lyxerr.debugging(Debug::LATEX))
3643 lyxerr << "Paragraph: " << par << endl;
3645 // Now just follow the list of paragraphs and run
3646 // validate on each of them.
3647 par->validate(features);
3649 // and then the next paragraph
3653 // the bullet shapes are buffer level not paragraph level
3654 // so they are tested here
3655 for (int i = 0; i < 4; ++i) {
3656 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
3657 int font = params.user_defined_bullets[i].getFont();
3660 .user_defined_bullets[i]
3667 features.latexsym = true;
3671 features.amssymb = true;
3673 else if ((font >= 2 && font <= 5)) {
3674 features.pifont = true;
3679 if (lyxerr.debugging(Debug::LATEX)) {
3680 features.showStruct();
3685 void Buffer::setPaperStuff()
3687 params.papersize = BufferParams::PAPER_DEFAULT;
3688 char c1 = params.paperpackage;
3689 if (c1 == BufferParams::PACKAGE_NONE) {
3690 char c2 = params.papersize2;
3691 if (c2 == BufferParams::VM_PAPER_USLETTER)
3692 params.papersize = BufferParams::PAPER_USLETTER;
3693 else if (c2 == BufferParams::VM_PAPER_USLEGAL)
3694 params.papersize = BufferParams::PAPER_LEGALPAPER;
3695 else if (c2 == BufferParams::VM_PAPER_USEXECUTIVE)
3696 params.papersize = BufferParams::PAPER_EXECUTIVEPAPER;
3697 else if (c2 == BufferParams::VM_PAPER_A3)
3698 params.papersize = BufferParams::PAPER_A3PAPER;
3699 else if (c2 == BufferParams::VM_PAPER_A4)
3700 params.papersize = BufferParams::PAPER_A4PAPER;
3701 else if (c2 == BufferParams::VM_PAPER_A5)
3702 params.papersize = BufferParams::PAPER_A5PAPER;
3703 else if ((c2 == BufferParams::VM_PAPER_B3) || (c2 == BufferParams::VM_PAPER_B4) ||
3704 (c2 == BufferParams::VM_PAPER_B5))
3705 params.papersize = BufferParams::PAPER_B5PAPER;
3706 } else if ((c1 == BufferParams::PACKAGE_A4) || (c1 == BufferParams::PACKAGE_A4WIDE) ||
3707 (c1 == BufferParams::PACKAGE_WIDEMARGINSA4))
3708 params.papersize = BufferParams::PAPER_A4PAPER;
3712 // This function should be in Buffer because it's a buffer's property (ale)
3713 string Buffer::getIncludeonlyList(char delim)
3716 LyXParagraph * par = paragraph;
3717 LyXParagraph::size_type pos;
3721 while ((inset = par->ReturnNextInsetPointer(pos))){
3722 if (inset->LyxCode() == Inset::INCLUDE_CODE) {
3723 InsetInclude * insetinc =
3724 static_cast<InsetInclude*>(inset);
3725 if (insetinc->isInclude()
3726 && insetinc->isNoLoad()) {
3729 lst += ChangeExtension(insetinc->getContents(), string(), true);
3736 lyxerr.debug() << "Includeonly(" << lst << ')' << endl;
3741 // This is also a buffer property (ale)
3742 string Buffer::getReferenceList(char delim)
3744 /// if this is a child document and the parent is already loaded
3745 /// Use the parent's list instead [ale990407]
3746 if (!params.parentname.empty()
3747 && bufferlist.exists(params.parentname)) {
3748 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3750 return tmp->getReferenceList(delim);
3753 LyXParagraph * par = paragraph;
3754 LyXParagraph::size_type pos;
3759 while ((inset = par->ReturnNextInsetPointer(pos))){
3760 for (int i = 0; i < inset->GetNumberOfLabels(); ++i) {
3763 lst += inset->getLabel(i);
3769 lyxerr.debug() << "References(" << lst << ")" << endl;
3774 // This is also a buffer property (ale)
3775 string Buffer::getBibkeyList(char delim)
3777 /// if this is a child document and the parent is already loaded
3778 /// Use the parent's list instead [ale990412]
3779 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3780 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3782 return tmp->getBibkeyList(delim);
3786 LyXParagraph * par = paragraph;
3789 if (!bibkeys.empty())
3791 bibkeys += par->bibkey->getContents();
3796 // Might be either using bibtex or a child has bibliography
3797 if (bibkeys.empty()) {
3801 LyXParagraph::size_type pos = -1;
3803 // Search for Bibtex or Include inset
3804 while ((inset = par->ReturnNextInsetPointer(pos))) {
3805 if (inset-> LyxCode() == Inset::BIBTEX_CODE) {
3806 if (!bibkeys.empty())
3808 bibkeys += static_cast<InsetBibtex*>(inset)->getKeys(delim);
3809 } else if (inset-> LyxCode() == Inset::INCLUDE_CODE) {
3810 string bk = static_cast<InsetInclude*>(inset)->getKeys(delim);
3812 if (!bibkeys.empty())
3823 lyxerr.debug() << "Bibkeys(" << bibkeys << ")" << endl;
3828 bool Buffer::isDepClean(string const & name) const
3830 DEPCLEAN * item = dep_clean;
3831 while (item && item->master != name)
3833 if (!item) return true;
3838 void Buffer::markDepClean(string const & name)
3841 dep_clean = new DEPCLEAN;
3842 dep_clean->clean = true;
3843 dep_clean->master = name;
3844 dep_clean->next = 0;
3846 DEPCLEAN* item = dep_clean;
3847 while (item && item->master != name)
3852 item = new DEPCLEAN;
3854 item->master = name;
3861 bool Buffer::Dispatch(string const & command)
3863 // Split command string into command and argument
3864 string cmd, line = frontStrip(command);
3865 string arg = strip(frontStrip(split(line, cmd, ' ')));
3867 return Dispatch(lyxaction.LookupFunc(cmd.c_str()), arg.c_str());
3871 bool Buffer::Dispatch(int action, string const & argument)
3873 bool dispatched = true;
3876 MenuExport(this, argument);
3886 void Buffer::ChangeLanguage(Language const * from, Language const * to)
3889 LyXParagraph * par = paragraph;
3891 par->ChangeLanguage(from, to);
3897 bool Buffer::isMultiLingual()
3900 LyXParagraph * par = paragraph;
3902 if (par->isMultiLingual())