1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2000 The LyX Team.
9 * This file is Copyright 1996-1999
12 * ======================================================
17 // 23/03/98 Heinrich Bauer (heinrich.bauer@t-mobil.de)
18 // Spots marked "changed Heinrich Bauer, 23/03/98" modified due to the
19 // following bug: dvi file export did not work after printing (or previewing)
20 // and vice versa as long as the same file was concerned. This happened
21 // every time the LyX-file was left unchanged between the two actions mentioned
31 #include <sys/types.h>
35 #pragma implementation "buffer.h"
39 #include "bufferlist.h"
41 #include "lyx_gui_misc.h"
42 #include "LyXAction.h"
45 #include "tex-strings.h"
48 #include "minibuffer.h"
51 #include "mathed/formulamacro.h"
52 #include "insets/lyxinset.h"
53 #include "insets/inseterror.h"
54 #include "insets/insetlabel.h"
55 #include "insets/insetref.h"
56 #include "insets/inseturl.h"
57 #include "insets/insetinfo.h"
58 #include "insets/insetquotes.h"
59 #include "insets/insetlatexaccent.h"
60 #include "insets/insetbib.h"
61 #include "insets/insetindex.h"
62 #include "insets/insetinclude.h"
63 #include "insets/insettoc.h"
64 #include "insets/insetlof.h"
65 #include "insets/insetlot.h"
66 #include "insets/insetloa.h"
67 #include "insets/insetparent.h"
68 #include "insets/insetspecialchar.h"
69 #include "insets/figinset.h"
70 #include "insets/insettext.h"
71 //#include "insets/insetnumber.h"
72 #include "insets/insetert.h"
73 #include "insets/insetgraphics.h"
74 #include "insets/insetfoot.h"
75 #include "support/filetools.h"
76 #include "support/path.h"
82 #include "LaTeXFeatures.h"
83 #include "support/syscall.h"
84 #include "support/lyxlib.h"
85 #include "support/FileInfo.h"
99 // Uncomment this line to enable a workaround for the weird behaviour
100 // of the cursor between a displayed inset and last character
101 // at the upper line. (Alejandro 20.9.96)
102 // #define BREAK_BEFORE_INSET
104 /* Lars, when changing this file sometime in the future to a list,
105 * please check out the figinsets-sideeffects described at the
106 * beginning of figinset.C Matthias (04.07.1996)
110 // all these externs should eventually be removed.
111 extern BufferList bufferlist;
113 extern void MenuExport(Buffer *, string const &);
114 extern LyXAction lyxaction;
117 static const float LYX_FORMAT = 2.16;
119 extern int tex_code_break_column;
121 extern void FreeUpdateTimer();
124 Buffer::Buffer(string const & file, bool ronly)
126 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
128 filepath = OnlyPath(file);
132 dvi_clean_orgd = false; // Heinrich Bauer, 23/03/98
133 dvi_clean_tmpd = false; // Heinrich Bauer, 23/03/98
138 if (read_only || (lyxrc.use_tempdir)) {
139 tmppath = CreateBufferTmpDir();
140 } else tmppath.clear();
146 lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
147 // here the buffer should take care that it is
148 // saved properly, before it goes into the void.
150 // make sure that views using this buffer
155 if (!tmppath.empty()) {
156 DestroyBufferTmpDir(tmppath);
159 LyXParagraph * par = paragraph;
160 LyXParagraph * tmppar;
170 string Buffer::getLatexName(bool no_path /* = true */) const
172 return ChangeExtension(MakeLatexName(filename),
177 void Buffer::setReadonly(bool flag /* = true */)
179 if (read_only != flag) {
182 updateAllVisibleBufferRelatedPopups();
185 WarnReadonly(filename);
190 bool Buffer::saveParamsAsDefaults()
192 string fname = AddName(AddPath(user_lyxdir, "templates/"),
194 Buffer defaults = Buffer(fname);
196 // Use the current buffer's parameters as default
197 defaults.params = params;
199 // add an empty paragraph. Is this enough?
200 defaults.paragraph = new LyXParagraph;
202 return defaults.writeFile(defaults.filename, false);
206 /// Update window titles of all users
207 // Should work on a list
208 void Buffer::updateTitles() const
210 if (users) users->owner()->updateWindowTitle();
214 /// Reset autosave timer of all users
215 // Should work on a list
216 void Buffer::resetAutosaveTimers() const
218 if (users) users->owner()->resetAutosaveTimer();
222 void Buffer::fileName(string const & newfile)
224 filename = MakeAbsPath(newfile);
225 filepath = OnlyPath(filename);
226 setReadonly(IsFileWriteable(filename) == 0);
231 // candidate for move to BufferView
232 // (at least some parts in the beginning of the func)
235 // changed to be public and have one parameter
236 // if par = 0 normal behavior
237 // else insert behavior
238 // Returns false if "\the_end" is not read for formats >= 2.13. (Asger)
239 #define USE_PARSE_FUNCTION 1
240 bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par)
244 char depth = 0; // signed or unsigned?
245 LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
246 LyXParagraph::footnote_kind footnotekind = LyXParagraph::FOOTNOTE;
247 bool the_end_read = false;
249 LyXParagraph * return_par = 0;
250 LyXFont font(LyXFont::ALL_INHERIT,params.language_info);
251 if (format < 2.16 && params.language == "hebrew")
252 font.setLanguage(default_language);
254 // If we are inserting, we cheat and get a token in advance
255 bool has_token = false;
259 par = new LyXParagraph;
261 users->text->BreakParagraph();
262 return_par = users->text->FirstParagraph();
265 // We don't want to adopt the parameters from the
266 // document we insert, so we skip until the text begins:
269 pretoken = lex.GetString();
270 if (pretoken == "\\layout") {
282 pretoken = lex.GetString();
285 // Profiling show this should give a lot: (Asger)
286 string const token = pretoken;
290 the_end_read = parseSingleLyXformat2Token(lex, par, return_par,
299 paragraph = return_par;
305 bool Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
306 LyXParagraph *& return_par,
307 const string & token, int & pos,
308 char & depth, LyXFont & font,
309 LyXParagraph::footnote_flag & footnoteflag,
310 LyXParagraph::footnote_kind & footnotekind)
315 bool the_end_read = false;
317 if (token[0] != '\\') {
318 int n = token.length();
319 for (int i = 0; i < n; ++i) {
320 par->InsertChar(pos, token[i]);
321 par->SetFont(pos, font);
324 } else if (token == "\\i") {
325 inset = new InsetLatexAccent;
327 par->InsertChar(pos, LyXParagraph::META_INSET);
328 par->InsertInset(pos, inset);
329 par->SetFont(pos, font);
331 } else if (token == "\\layout") {
336 par = new LyXParagraph(par);
340 string layoutname = lex.GetString();
341 pair<bool, LyXTextClass::LayoutList::size_type> pp
342 = textclasslist.NumberOfLayout(params.textclass,
345 par->layout = pp.second;
346 } else { // layout not found
347 // use default layout "Standard" (0)
350 // Test whether the layout is obsolete.
351 LyXLayout const & layout =
352 textclasslist.Style(params.textclass,
354 if (!layout.obsoleted_by().empty())
356 textclasslist.NumberOfLayout(params.textclass,
357 layout.obsoleted_by()).second;
358 par->footnoteflag = footnoteflag;
359 par->footnotekind = footnotekind;
361 font = LyXFont(LyXFont::ALL_INHERIT,params.language_info);
362 if (format < 2.16 && params.language == "hebrew")
363 font.setLanguage(default_language);
364 } else if (token == "\\end_float") {
369 par = new LyXParagraph(par);
371 footnotekind = LyXParagraph::FOOTNOTE;
372 footnoteflag = LyXParagraph::NO_FOOTNOTE;
375 par->layout = LYX_DUMMY_LAYOUT;
376 font = LyXFont(LyXFont::ALL_INHERIT,params.language_info);
377 if (format < 2.16 && params.language == "hebrew")
378 font.setLanguage(default_language);
379 } else if (token == "\\begin_float") {
380 tmpret = lex.FindToken(string_footnotekinds);
381 if (tmpret == -1) ++tmpret;
382 if (tmpret != LYX_LAYOUT_DEFAULT)
383 footnotekind = static_cast<LyXParagraph::footnote_kind>(tmpret); // bad
384 if (footnotekind == LyXParagraph::FOOTNOTE
385 || footnotekind == LyXParagraph::MARGIN)
386 footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
388 footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
389 } else if (token == "\\begin_deeper") {
391 } else if (token == "\\end_deeper") {
393 lex.printError("\\end_deeper: "
394 "depth is already null");
398 } else if (token == "\\begin_preamble") {
399 params.readPreamble(lex);
400 } else if (token == "\\textclass") {
402 pair<bool, LyXTextClassList::size_type> pp =
403 textclasslist.NumberOfClass(lex.GetString());
405 params.textclass = pp.second;
407 lex.printError("Unknown textclass `$$Token'");
408 params.textclass = 0;
410 if (!textclasslist.Load(params.textclass)) {
411 // if the textclass wasn't loaded properly
412 // we need to either substitute another
413 // or stop loading the file.
414 // I can substitute but I don't see how I can
415 // stop loading... ideas?? ARRae980418
416 WriteAlert(_("Textclass Loading Error!"),
417 string(_("Can't load textclass ")) +
418 textclasslist.NameOfClass(params.textclass),
419 _("-- substituting default"));
420 params.textclass = 0;
422 } else if (token == "\\options") {
424 params.options = lex.GetString();
425 } else if (token == "\\language") {
426 params.readLanguage(lex);
427 } else if (token == "\\fontencoding") {
429 } else if (token == "\\inputencoding") {
431 params.inputenc = lex.GetString();
432 } else if (token == "\\graphics") {
433 params.readGraphicsDriver(lex);
434 } else if (token == "\\fontscheme") {
436 params.fonts = lex.GetString();
437 } else if (token == "\\noindent") {
438 par->noindent = true;
439 } else if (token == "\\fill_top") {
440 par->added_space_top = VSpace(VSpace::VFILL);
441 } else if (token == "\\fill_bottom") {
442 par->added_space_bottom = VSpace(VSpace::VFILL);
443 } else if (token == "\\line_top") {
444 par->line_top = true;
445 } else if (token == "\\line_bottom") {
446 par->line_bottom = true;
447 } else if (token == "\\pagebreak_top") {
448 par->pagebreak_top = true;
449 } else if (token == "\\pagebreak_bottom") {
450 par->pagebreak_bottom = true;
451 } else if (token == "\\start_of_appendix") {
452 par->start_of_appendix = true;
453 } else if (token == "\\paragraph_separation") {
454 tmpret = lex.FindToken(string_paragraph_separation);
455 if (tmpret == -1) ++tmpret;
456 if (tmpret != LYX_LAYOUT_DEFAULT)
457 params.paragraph_separation =
458 static_cast<BufferParams::PARSEP>(tmpret);
459 } else if (token == "\\defskip") {
461 params.defskip = VSpace(lex.GetString());
463 } else if (token == "\\no_isolatin1") { // obsolete
465 } else if (token == "\\no_babel") { // obsolete
467 } else if (token == "\\no_epsfig") { // obsolete
470 } else if (token == "\\epsfig") { // obsolete
471 // Indeed it is obsolete, but we HAVE to be backwards
472 // compatible until 0.14, because otherwise all figures
473 // in existing documents are irretrivably lost. (Asger)
474 params.readGraphicsDriver(lex);
475 } else if (token == "\\quotes_language") {
476 tmpret = lex.FindToken(string_quotes_language);
477 if (tmpret == -1) ++tmpret;
478 if (tmpret != LYX_LAYOUT_DEFAULT) {
479 InsetQuotes::quote_language tmpl =
480 InsetQuotes::EnglishQ;
483 tmpl = InsetQuotes::EnglishQ;
486 tmpl = InsetQuotes::SwedishQ;
489 tmpl = InsetQuotes::GermanQ;
492 tmpl = InsetQuotes::PolishQ;
495 tmpl = InsetQuotes::FrenchQ;
498 tmpl = InsetQuotes::DanishQ;
501 params.quotes_language = tmpl;
503 } else if (token == "\\quotes_times") {
505 switch(lex.GetInteger()) {
507 params.quotes_times = InsetQuotes::SingleQ;
510 params.quotes_times = InsetQuotes::DoubleQ;
513 } else if (token == "\\papersize") {
514 tmpret = lex.FindToken(string_papersize);
518 params.papersize2 = tmpret;
519 } else if (token == "\\paperpackage") {
520 tmpret = lex.FindToken(string_paperpackages);
523 params.paperpackage = BufferParams::PACKAGE_NONE;
525 params.paperpackage = tmpret;
526 } else if (token == "\\use_geometry") {
528 params.use_geometry = lex.GetInteger();
529 } else if (token == "\\use_amsmath") {
531 params.use_amsmath = lex.GetInteger();
532 } else if (token == "\\paperorientation") {
533 tmpret = lex.FindToken(string_orientation);
534 if (tmpret == -1) ++tmpret;
535 if (tmpret != LYX_LAYOUT_DEFAULT)
536 params.orientation = static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
537 } else if (token == "\\paperwidth") {
539 params.paperwidth = lex.GetString();
540 } else if (token == "\\paperheight") {
542 params.paperheight = lex.GetString();
543 } else if (token == "\\leftmargin") {
545 params.leftmargin = lex.GetString();
546 } else if (token == "\\topmargin") {
548 params.topmargin = lex.GetString();
549 } else if (token == "\\rightmargin") {
551 params.rightmargin = lex.GetString();
552 } else if (token == "\\bottommargin") {
554 params.bottommargin = lex.GetString();
555 } else if (token == "\\headheight") {
557 params.headheight = lex.GetString();
558 } else if (token == "\\headsep") {
560 params.headsep = lex.GetString();
561 } else if (token == "\\footskip") {
563 params.footskip = lex.GetString();
564 } else if (token == "\\paperfontsize") {
566 params.fontsize = strip(lex.GetString());
567 } else if (token == "\\papercolumns") {
569 params.columns = lex.GetInteger();
570 } else if (token == "\\papersides") {
572 switch(lex.GetInteger()) {
574 case 1: params.sides = LyXTextClass::OneSide; break;
575 case 2: params.sides = LyXTextClass::TwoSides; break;
577 } else if (token == "\\paperpagestyle") {
579 params.pagestyle = strip(lex.GetString());
580 } else if (token == "\\bullet") {
582 int index = lex.GetInteger();
584 int temp_int = lex.GetInteger();
585 params.user_defined_bullets[index].setFont(temp_int);
586 params.temp_bullets[index].setFont(temp_int);
588 temp_int = lex.GetInteger();
589 params.user_defined_bullets[index].setCharacter(temp_int);
590 params.temp_bullets[index].setCharacter(temp_int);
592 temp_int = lex.GetInteger();
593 params.user_defined_bullets[index].setSize(temp_int);
594 params.temp_bullets[index].setSize(temp_int);
596 string temp_str = lex.GetString();
597 if (temp_str != "\\end_bullet") {
598 // this element isn't really necessary for
599 // parsing but is easier for humans
600 // to understand bullets. Put it back and
601 // set a debug message?
602 lex.printError("\\end_bullet expected, got" + temp_str);
603 //how can I put it back?
605 } else if (token == "\\bulletLaTeX") {
607 int index = lex.GetInteger();
609 string temp_str = lex.GetString(), sum_str;
610 while (temp_str != "\\end_bullet") {
611 // this loop structure is needed when user
612 // enters an empty string since the first
613 // thing returned will be the \\end_bullet
615 // if the LaTeX entry has spaces. Each element
616 // therefore needs to be read in turn
619 temp_str = lex.GetString();
621 params.user_defined_bullets[index].setText(sum_str);
622 params.temp_bullets[index].setText(sum_str);
623 } else if (token == "\\secnumdepth") {
625 params.secnumdepth = lex.GetInteger();
626 } else if (token == "\\tocdepth") {
628 params.tocdepth = lex.GetInteger();
629 } else if (token == "\\baselinestretch") { // obsolete
630 lex.nextToken(); // should not be used directly
632 // Will probably keep a kind of support just for
634 params.spacing.set(Spacing::Other, lex.GetFloat());
635 } else if (token == "\\spacing") {
637 string tmp = strip(lex.GetString());
638 if (tmp == "single") {
639 params.spacing.set(Spacing::Single);
640 } else if (tmp == "onehalf") {
641 params.spacing.set(Spacing::Onehalf);
642 } else if (tmp == "double") {
643 params.spacing.set(Spacing::Double);
644 } else if (tmp == "other") {
646 params.spacing.set(Spacing::Other,
649 lex.printError("Unknown spacing token: '$$Token'");
651 } else if (token == "\\float_placement") {
653 params.float_placement = lex.GetString();
654 } else if (token == "\\cursor") { // obsolete
655 // this is obsolete, so we just skip it.
657 } else if (token == "\\family") {
659 font.setLyXFamily(lex.GetString());
660 } else if (token == "\\series") {
662 font.setLyXSeries(lex.GetString());
663 } else if (token == "\\shape") {
665 font.setLyXShape(lex.GetString());
666 } else if (token == "\\size") {
668 font.setLyXSize(lex.GetString());
669 } else if (token == "\\latex") {
671 string tok = lex.GetString();
672 // This is dirty, but gone with LyX3. (Asger)
673 if (tok == "no_latex")
674 font.setLatex(LyXFont::OFF);
675 else if (tok == "latex")
676 font.setLatex(LyXFont::ON);
677 else if (tok == "default")
678 font.setLatex(LyXFont::INHERIT);
680 lex.printError("Unknown LaTeX font flag "
682 } else if (token == "\\lang") {
684 string tok = lex.GetString();
685 Languages::iterator lit = languages.find(tok);
686 if (lit != languages.end()) {
687 font.setLanguage(&(*lit).second);
689 font.setLanguage(params.language_info);
690 lex.printError("Unknown language `$$Token'");
692 } else if (token == "\\direction") { // obsolete
694 lex.printError("Command \\direction is obsolete");
696 string tok = lex.GetString();
698 font.setLanguage(&languages["hebrew"]);
699 else if (tok == "default")
700 if (params.language == "hebrew")
701 font.setLanguage(default_language);
703 font.setLanguage(params.language_info);
705 lex.printError("Unknown direction `$$Token'");
706 } else if (token == "\\emph") {
708 font.setEmph(font.setLyXMisc(lex.GetString()));
709 } else if (token == "\\bar") {
711 string tok = lex.GetString();
712 // This is dirty, but gone with LyX3. (Asger)
714 font.setUnderbar(LyXFont::ON);
715 else if (tok == "no")
716 font.setUnderbar(LyXFont::OFF);
717 else if (tok == "default")
718 font.setUnderbar(LyXFont::INHERIT);
720 lex.printError("Unknown bar font flag "
722 } else if (token == "\\noun") {
724 font.setNoun(font.setLyXMisc(lex.GetString()));
725 } else if (token == "\\color") {
727 font.setLyXColor(lex.GetString());
728 } else if (token == "\\align") {
729 tmpret = lex.FindToken(string_align);
730 if (tmpret == -1) ++tmpret;
731 if (tmpret != LYX_LAYOUT_DEFAULT) { // tmpret != 99 ???
733 for (; tmpret > 0; --tmpret)
734 tmpret2 = tmpret2 * 2;
735 par->align = LyXAlignment(tmpret2);
737 } else if (token == "\\added_space_top") {
739 par->added_space_top = VSpace(lex.GetString());
740 } else if (token == "\\added_space_bottom") {
742 par->added_space_bottom = VSpace(lex.GetString());
743 } else if (token == "\\pextra_type") {
745 par->pextra_type = lex.GetInteger();
746 } else if (token == "\\pextra_width") {
748 par->pextra_width = lex.GetString();
749 } else if (token == "\\pextra_widthp") {
751 par->pextra_widthp = lex.GetString();
752 } else if (token == "\\pextra_alignment") {
754 par->pextra_alignment = lex.GetInteger();
755 } else if (token == "\\pextra_hfill") {
757 par->pextra_hfill = lex.GetInteger();
758 } else if (token == "\\pextra_start_minipage") {
760 par->pextra_start_minipage = lex.GetInteger();
761 } else if (token == "\\labelwidthstring") {
763 par->labelwidthstring = lex.GetString();
764 /* do not delete this token, it is still needed! */
765 } else if (token == "\\end_inset") {
766 /* simple ignore this. The insets do not have
768 // but insets should read it, it is a part of
769 //the inset isn't it? Lgb.
770 } else if (token == "\\begin_inset") {
772 tmptok = lex.GetString();
773 /* test the different insets */
774 if (tmptok == "Quotes") {
775 inset = new InsetQuotes;
777 par->InsertChar(pos, LyXParagraph::META_INSET);
778 par->InsertInset(pos, inset);
779 par->SetFont(pos, font);
781 } else if (tmptok == "\\i") {
782 inset = new InsetLatexAccent;
784 par->InsertChar(pos, LyXParagraph::META_INSET);
785 par->InsertInset(pos, inset);
786 par->SetFont(pos, font);
788 } else if (tmptok == "FormulaMacro") {
789 inset = new InsetFormulaMacro;
791 par->InsertChar(pos, LyXParagraph::META_INSET);
792 par->InsertInset(pos, inset);
793 par->SetFont(pos, font);
795 } else if (tmptok == "Formula") {
796 inset = new InsetFormula;
798 par->InsertChar(pos, LyXParagraph::META_INSET);
799 par->InsertInset(pos, inset);
800 par->SetFont(pos, font);
802 } else if (tmptok == "Figure") {
803 inset = new InsetFig(100, 100, this);
805 par->InsertChar(pos, LyXParagraph::META_INSET);
806 par->InsertInset(pos, inset);
807 par->SetFont(pos, font);
809 } else if (tmptok == "Info") {
810 inset = new InsetInfo;
812 par->InsertChar(pos, LyXParagraph::META_INSET);
813 par->InsertInset(pos, inset);
814 par->SetFont(pos, font);
816 } else if (tmptok == "Include") {
817 inset = new InsetInclude(string(), this);
819 par->InsertChar(pos, LyXParagraph::META_INSET);
820 par->InsertInset(pos, inset);
821 par->SetFont(pos, font);
823 } else if (tmptok == "ERT") {
824 inset = new InsetERT(this);
826 par->InsertChar(pos, LyXParagraph::META_INSET);
827 par->InsertInset(pos, inset);
828 par->SetFont(pos, font);
830 } else if (tmptok == "Text") {
831 inset = new InsetText(this);
833 par->InsertChar(pos, LyXParagraph::META_INSET);
834 par->InsertInset(pos, inset);
835 par->SetFont(pos, font);
838 } else if (tmptok == "Number") {
839 inset = new InsetNumber(this);
841 par->InsertChar(pos, LyXParagraph::META_INSET);
842 par->InsertInset(pos, inset);
843 par->SetFont(pos, font);
846 } else if (tmptok == "Foot") {
847 inset = new InsetFoot(this);
849 par->InsertChar(pos, LyXParagraph::META_INSET);
850 par->InsertInset(pos, inset);
851 par->SetFont(pos, font);
853 } else if (tmptok == "GRAPHICS") {
854 inset = new InsetGraphics;
856 par->InsertChar(pos, LyXParagraph::META_INSET);
857 par->InsertInset(pos, inset);
858 par->SetFont(pos, font);
859 } else if (tmptok == "LatexCommand") {
862 if (inscmd.getCmdName() == "cite") {
863 inset = new InsetCitation(inscmd.getContents(), inscmd.getOptions());
864 } else if (inscmd.getCmdName() == "bibitem") {
865 lex.printError("Wrong place for bibitem");
866 inset = inscmd.Clone();
867 } else if (inscmd.getCmdName() == "BibTeX") {
868 inset = new InsetBibtex(inscmd.getContents(), inscmd.getOptions(), this);
869 } else if (inscmd.getCmdName() == "index") {
870 inset = new InsetIndex(inscmd.getContents());
871 } else if (inscmd.getCmdName() == "include") {
872 inset = new InsetInclude(inscmd.getContents(), this);
873 } else if (inscmd.getCmdName() == "label") {
874 inset = new InsetLabel(inscmd.getCommand());
875 } else if (inscmd.getCmdName() == "url"
876 || inscmd.getCmdName() == "htmlurl") {
877 inset = new InsetUrl(inscmd.getCommand());
878 } else if (inscmd.getCmdName() == "ref"
879 || inscmd.getCmdName() == "pageref") {
880 if (!inscmd.getOptions().empty() || !inscmd.getContents().empty()) {
881 inset = new InsetRef(inscmd, this);
883 #warning Check if this else clause is still needed. (Lgb)
885 // This condition comes from a
886 // temporary solution to the latexdel
887 // ref inset that was transformed to
888 // an empty ref inset plus the body
889 // surronded by latexdel insets
891 string cont, opt, tmptmptok, cmdname;
893 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
898 tmptmptok = lex.GetString();
899 if(tmptmptok[0] == '\\') {
900 if( tmptmptok == "\\backslash")
910 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
915 tmptmptok = lex.GetString();
916 if(tmptmptok[0] == '\\') {
917 if( tmptmptok == "\\backslash")
927 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
933 cmdname = "\\" + inscmd.getCmdName();
934 cmdname += "[" + cont + "]";
935 cmdname += "{" + opt + "}";
936 inset = new InsetRef(cmdname, this);
939 } else if (inscmd.getCmdName() == "tableofcontents") {
940 inset = new InsetTOC(this);
941 } else if (inscmd.getCmdName() == "listoffigures") {
942 inset = new InsetLOF(this);
943 } else if (inscmd.getCmdName() == "listofalgorithms") {
944 inset = new InsetLOA(this);
945 } else if (inscmd.getCmdName() == "listoftables") {
946 inset = new InsetLOT(this);
947 } else if (inscmd.getCmdName() == "printindex") {
948 inset = new InsetPrintIndex(this);
949 } else if (inscmd.getCmdName() == "lyxparent") {
950 inset = new InsetParent(inscmd.getContents(), this);
954 par->InsertChar(pos, LyXParagraph::META_INSET);
955 par->InsertInset(pos, inset);
956 par->SetFont(pos, font);
960 } else if (token == "\\InsetQuotes") {
961 inset = new InsetQuotes;
963 par->InsertChar(pos, LyXParagraph::META_INSET);
964 par->InsertInset(pos, inset);
965 par->SetFont(pos, font);
967 } else if (token == "\\InsetFormula") {
968 inset = new InsetFormula;
970 par->InsertChar(pos, LyXParagraph::META_INSET);
971 par->InsertInset(pos, inset);
972 par->SetFont(pos, font);
974 } else if (token == "\\SpecialChar") {
975 LyXLayout const & layout =
976 textclasslist.Style(params.textclass,
979 // Insets don't make sense in a free-spacing context! ---Kayvan
980 if (layout.free_spacing)
985 next_token = lex.GetString();
986 if (next_token == "\\-") {
987 par->InsertChar(pos, '-');
988 par->SetFont(pos, font);
989 } else if (next_token == "\\protected_separator") {
990 par->InsertChar(pos, ' ');
991 par->SetFont(pos, font);
993 lex.printError("Token `$$Token' "
995 "paragraph layout!");
1002 inset = new InsetSpecialChar;
1004 par->InsertChar(pos, LyXParagraph::META_INSET);
1005 par->InsertInset(pos, inset);
1006 par->SetFont(pos, font);
1009 } else if (token == "\\Figure") {
1010 inset = new InsetFig(100, 100, this);
1012 par->InsertChar(pos, LyXParagraph::META_INSET);
1013 par->InsertInset(pos, inset);
1014 par->SetFont(pos, font);
1016 } else if (token == "\\newline") { // soon obsolete
1018 par->InsertChar(pos, LyXParagraph::META_NEWLINE);
1019 par->SetFont(pos, font);
1021 inset = new InsetSpecialChar(InsetSpecialChar::NEWLINE);
1022 par->InsertChar(pos, LyXParagraph::META_INSET);
1023 par->InsertInset(pos, inset);
1024 par->SetFont(pos, font);
1027 } else if (token == "\\LyXTable") {
1028 par->table = new LyXTable(lex);
1029 } else if (token == "\\hfill") {
1030 par->InsertChar(pos, LyXParagraph::META_HFILL);
1031 par->SetFont(pos, font);
1033 } else if (token == "\\protected_separator") { // obsolete
1035 LyXLayout const & layout =
1036 textclasslist.Style(params.textclass,
1039 if (layout.free_spacing) {
1040 par->InsertChar(pos, ' ');
1041 par->SetFont(pos, font);
1043 inset = new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
1044 par->InsertChar(pos, LyXParagraph::META_INSET);
1045 par->InsertInset(pos, inset);
1046 par->SetFont(pos, font);
1049 par->InsertChar(pos, LyXParagraph::META_PROTECTED_SEPARATOR);
1050 par->SetFont(pos, font);
1053 } else if (token == "\\bibitem") { // ale970302
1055 par->bibkey = new InsetBibKey;
1056 par->bibkey->Read(lex);
1057 }else if (token == "\\backslash") {
1058 par->InsertChar(pos, '\\');
1059 par->SetFont(pos, font);
1061 }else if (token == "\\the_end") {
1062 the_end_read = true;
1064 // This should be insurance for the future: (Asger)
1065 lex.printError("Unknown token `$$Token'. "
1066 "Inserting as text.");
1067 int n = token.length();
1068 for (int i = 0; i < n; ++i) {
1069 par->InsertChar(pos, token[i]);
1070 par->SetFont(pos, font);
1074 return the_end_read;
1077 bool Buffer::readFile(LyXLex & lex, LyXParagraph * par)
1083 token = lex.GetString();
1084 if (token == "\\lyxformat") { // the first token _must_ be...
1086 format = lex.GetFloat();
1088 if (LYX_FORMAT - format > 0.05) {
1089 printf(_("Warning: need lyxformat %.2f but found %.2f\n"),
1090 LYX_FORMAT, format);
1092 if (format - LYX_FORMAT > 0.05) {
1093 printf(_("ERROR: need lyxformat %.2f but found %.2f\n"),
1094 LYX_FORMAT, format);
1096 bool the_end = readLyXformat2(lex, par);
1097 // Formats >= 2.13 support "\the_end" marker
1104 WriteAlert(_("Warning!"),
1105 _("Reading of document is not complete"),
1106 _("Maybe the document is truncated"));
1107 // We simulate a safe reading anyways to allow
1108 // users to take the chance... (Asger)
1112 WriteAlert(_("ERROR!"),
1113 _("Old LyX file format found. "
1114 "Use LyX 0.10.x to read this!"));
1118 } else { // "\\lyxformat" not found
1119 WriteAlert(_("ERROR!"), _("Not a LyX file!"));
1122 WriteAlert(_("ERROR!"), _("Unable to read file!"));
1128 // Should probably be moved to somewhere else: BufferView? LyXView?
1129 bool Buffer::save() const
1131 // We don't need autosaves in the immediate future. (Asger)
1132 resetAutosaveTimers();
1136 if (lyxrc.make_backup) {
1137 s = fileName() + '~';
1138 if (!lyxrc.backupdir_path.empty())
1139 s = AddName(lyxrc.backupdir_path,
1140 subst(CleanupPath(s),'/','!'));
1142 // Rename is the wrong way of making a backup,
1143 // this is the correct way.
1144 /* truss cp fil fil2:
1145 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
1146 stat("LyXVC.lyx", 0xEFFFF688) = 0
1147 open("LyXVC.lyx", O_RDONLY) = 3
1148 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
1149 fstat(4, 0xEFFFF508) = 0
1150 fstat(3, 0xEFFFF508) = 0
1151 read(3, " # T h i s f i l e w".., 8192) = 5579
1152 write(4, " # T h i s f i l e w".., 5579) = 5579
1153 read(3, 0xEFFFD4A0, 8192) = 0
1156 chmod("LyXVC3.lyx", 0100644) = 0
1157 lseek(0, 0, SEEK_CUR) = 46440
1161 // Should proabaly have some more error checking here.
1162 // Should be cleaned up in 0.13, at least a bit.
1163 // Doing it this way, also makes the inodes stay the same.
1164 // This is still not a very good solution, in particular we
1165 // might loose the owner of the backup.
1166 FileInfo finfo(fileName());
1167 if (finfo.exist()) {
1168 mode_t fmode = finfo.getMode();
1169 struct utimbuf times = {
1170 finfo.getAccessTime(),
1171 finfo.getModificationTime() };
1173 ifstream ifs(fileName().c_str());
1174 ofstream ofs(s.c_str(), ios::out|ios::trunc);
1179 ::chmod(s.c_str(), fmode);
1181 if (::utime(s.c_str(), ×)) {
1182 lyxerr << "utime error." << endl;
1185 lyxerr << "LyX was not able to make "
1186 "backupcopy. Beware." << endl;
1191 if (writeFile(fileName(), false)) {
1194 // now delete the autosavefile
1195 string a = OnlyPath(fileName());
1197 a += OnlyFilename(fileName());
1199 FileInfo fileinfo(a);
1200 if (fileinfo.exist()) {
1201 if (::remove(a.c_str()) != 0) {
1202 WriteFSAlert(_("Could not delete "
1203 "auto-save file!"), a);
1207 // Saving failed, so backup is not backup
1208 if (lyxrc.make_backup) {
1209 ::rename(s.c_str(), fileName().c_str());
1217 // Returns false if unsuccesful
1218 bool Buffer::writeFile(string const & fname, bool flag) const
1220 // if flag is false writeFile will not create any GUI
1221 // warnings, only cerr.
1222 // Needed for autosave in background or panic save (Matthias 120496)
1224 if (read_only && (fname == filename)) {
1225 // Here we should come with a question if we should
1226 // perform the write anyway.
1228 lyxerr << _("Error! Document is read-only: ")
1231 WriteAlert(_("Error! Document is read-only: "),
1236 FileInfo finfo(fname);
1237 if (finfo.exist() && !finfo.writable()) {
1238 // Here we should come with a question if we should
1239 // try to do the save anyway. (i.e. do a chmod first)
1241 lyxerr << _("Error! Cannot write file: ")
1244 WriteFSAlert(_("Error! Cannot write file: "),
1249 ofstream ofs(fname.c_str());
1252 lyxerr << _("Error! Cannot open file: ")
1255 WriteFSAlert(_("Error! Cannot open file: "),
1259 // The top of the file should not be written by params.
1261 // write out a comment in the top of the file
1262 ofs << '#' << LYX_DOCVERSION
1263 << " created this file. For more info see http://www.lyx.org/\n";
1264 ofs.setf(ios::showpoint|ios::fixed);
1266 ofs << "\\lyxformat " << setw(4) << LYX_FORMAT << "\n";
1268 // now write out the buffer paramters.
1269 params.writeFile(ofs);
1271 char footnoteflag = 0;
1274 // this will write out all the paragraphs
1275 // using recursive descent.
1276 paragraph->writeFile(ofs, params, footnoteflag, depth);
1278 // Write marker that shows file is complete
1279 ofs << "\n\\the_end" << endl;
1281 // how to check if close went ok?
1286 void Buffer::writeFileAscii(string const & fname, int linelen)
1288 LyXFont font1, font2;
1290 char c, footnoteflag = 0, depth = 0;
1292 LyXParagraph::size_type i;
1293 int j, h, ltype = 0, ltype_depth = 0,
1294 * clen = 0, actcell = 0, actpos = 0, cell = 0, cells = 0,
1297 bool ref_printed = false;
1299 ofstream ofs(fname.c_str());
1301 WriteFSAlert(_("Error: Cannot write file:"), fname);
1305 string fname1 = TmpFileName();
1306 LyXParagraph * par = paragraph;
1310 if (par->footnoteflag != LyXParagraph::NO_FOOTNOTE ||
1312 par->previous->footnoteflag == LyXParagraph::NO_FOOTNOTE){
1314 /* begins a footnote environment ? */
1315 if (footnoteflag != par->footnoteflag) {
1316 footnoteflag = par->footnoteflag;
1318 j = strlen(string_footnotekinds[par->footnotekind])+4;
1319 if (currlinelen + j > linelen)
1322 << string_footnotekinds[par->footnotekind] << "] ";
1327 /* begins or ends a deeper area ?*/
1328 if (depth != par->depth) {
1329 if (par->depth > depth) {
1330 while (par->depth > depth) {
1335 while (par->depth < depth) {
1341 /* First write the layout */
1342 tmp = textclasslist.NameOfLayout(params.textclass, par->layout);
1343 if (tmp == "Itemize") {
1345 ltype_depth = depth+1;
1346 } else if (tmp == "Enumerate") {
1348 ltype_depth = depth+1;
1349 } else if (strstr(tmp.c_str(), "ection")) {
1351 ltype_depth = depth+1;
1352 } else if (strstr(tmp.c_str(), "aragraph")) {
1354 ltype_depth = depth+1;
1355 } else if (tmp == "Description") {
1357 ltype_depth = depth+1;
1358 } else if (tmp == "Abstract") {
1361 } else if (tmp == "Bibliography") {
1369 /* maybe some vertical spaces */
1371 /* the labelwidthstring used in lists */
1375 /* some pagebreaks? */
1379 /* what about the alignment */
1382 /* dummy layout, that means a footnote ended */
1383 footnoteflag = LyXParagraph::NO_FOOTNOTE;
1388 LyXLayout const & layout =
1389 textclasslist.Style(params.textclass,
1391 bool free_spc = layout.free_spacing;
1393 /* It might be a table */
1396 if (!lyxrc.ascii_roff_command.empty() &&
1397 lyxrc.ascii_roff_command != "none") {
1398 RoffAsciiTable(ofs, par);
1405 cells = par->table->columns;
1406 clen = new int [cells];
1407 memset(clen, 0, sizeof(int) * cells);
1409 for (i = 0, j = 0, h = 1; i < par->size(); ++i, ++h) {
1410 c = par->GetChar(i);
1411 if (c == LyXParagraph::META_INSET) {
1412 if ((inset = par->GetInset(i))) {
1415 std::ostringstream ost;
1416 inset->Latex(ost, -1, free_spc);
1417 h += ost.str().length();
1420 inset->Latex(ost, -1, free_spc);
1422 char * tmp = ost.str();
1428 ofstream fs(fname1.c_str());
1430 WriteFSAlert(_("Error: Cannot open temporary file:"), fname1);
1433 inset->Latex(fs, -1, free_spc);
1434 h += fs.tellp() - 1;
1435 ::remove(fname1.c_str());
1438 } else if (c == LyXParagraph::META_NEWLINE) {
1442 j = (++j) % par->table->NumberOfCellsInRow(actcell);
1450 font1 = LyXFont(LyXFont::ALL_INHERIT,params.language_info);
1452 for (i = 0, actpos = 1; i < par->size(); ++i, ++actpos) {
1453 if (!i && !footnoteflag && !noparbreak){
1455 for(j = 0; j < depth; ++j)
1457 currlinelen = depth * 2;
1459 case 0: /* Standard */
1460 case 4: /* (Sub)Paragraph */
1461 case 5: /* Description */
1463 case 6: /* Abstract */
1464 ofs << "Abstract\n\n";
1466 case 7: /* Bibliography */
1468 ofs << "References\n\n";
1473 ofs << par->labelstring << " ";
1476 if (ltype_depth > depth) {
1477 for(j = ltype_depth - 1; j > depth; --j)
1479 currlinelen += (ltype_depth-depth)*2;
1482 for(j = 0; j < cells; ++j) {
1484 for(h = 0; h < (clen[j] + 1);
1489 for(j = 0; j < depth; ++j)
1491 currlinelen = depth * 2;
1492 if (ltype_depth > depth) {
1493 for(j = ltype_depth;
1496 currlinelen += (ltype_depth-depth)*2;
1501 font2 = par->GetFontSettings(i);
1502 if (font1.latex() != font2.latex()) {
1503 if (font2.latex() == LyXFont::OFF)
1511 c = par->GetChar(i);
1515 case LyXParagraph::META_INSET:
1516 if ((inset = par->GetInset(i))) {
1518 inset->Latex(ofs, -1, free_spc);
1519 currlinelen += (ofs.tellp() - fpos);
1520 actpos += (ofs.tellp() - fpos) - 1;
1523 case LyXParagraph::META_NEWLINE:
1525 if (par->table->NumberOfCellsInRow(actcell) <= cell) {
1526 for(j = actpos; j < clen[cell - 1]; ++j)
1529 for(j = 0; j < depth; ++j)
1531 currlinelen = depth*2;
1532 if (ltype_depth > depth) {
1533 for(j = ltype_depth; j > depth; --j)
1535 currlinelen += (ltype_depth-depth) * 2;
1537 for(j = 0; j < cells; ++j) {
1539 for(h = 0; h < (clen[j] + 1); ++h)
1543 for(j = 0; j < depth; ++j)
1545 currlinelen = depth * 2;
1546 if (ltype_depth > depth) {
1547 for(j = ltype_depth;
1550 currlinelen += (ltype_depth-depth)*2;
1556 j < clen[cell - 1]; ++j)
1562 currlinelen = actpos = 0;
1565 for(j = 0; j < depth; ++j)
1567 currlinelen = depth * 2;
1568 if (ltype_depth > depth) {
1569 for(j = ltype_depth;
1572 currlinelen += (ltype_depth - depth) * 2;
1576 case LyXParagraph::META_HFILL:
1580 case LyXParagraph::META_PROTECTED_SEPARATOR:
1588 if (currlinelen > linelen - 10
1589 && c == ' ' && i + 2 < par->size()) {
1591 for(j = 0; j < depth; ++j)
1593 currlinelen = depth * 2;
1594 if (ltype_depth > depth) {
1595 for(j = ltype_depth;
1598 currlinelen += (ltype_depth-depth)*2;
1600 } else if (c != '\0')
1603 lyxerr.debug() << "writeAsciiFile: NULL char in structure." << endl;
1609 for(j = actpos; j < clen[cell - 1]; ++j)
1612 for(j = 0; j < depth; ++j)
1614 currlinelen = depth * 2;
1615 if (ltype_depth > depth) {
1616 for(j = ltype_depth; j > depth; --j)
1618 currlinelen += (ltype_depth - depth) * 2;
1620 for(j = 0; j < cells; ++j) {
1622 for(h = 0; h < (clen[j] + 1); ++h)
1635 void Buffer::makeLaTeXFile(string const & fname,
1636 string const & original_path,
1637 bool nice, bool only_body)
1639 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
1641 niceFile = nice; // this will be used by Insetincludes.
1643 tex_code_break_column = lyxrc.ascii_linelen;
1645 LyXTextClass const & tclass =
1646 textclasslist.TextClass(params.textclass);
1648 ofstream ofs(fname.c_str());
1650 WriteFSAlert(_("Error: Cannot open file: "), fname);
1654 // validate the buffer.
1655 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
1656 LaTeXFeatures features(params, tclass.numLayouts());
1658 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
1661 // The starting paragraph of the coming rows is the
1662 // first paragraph of the document. (Asger)
1663 texrow.start(paragraph, 0);
1665 if (!only_body && nice) {
1666 ofs << "%% " LYX_DOCVERSION " created this file. "
1667 "For more info, see http://www.lyx.org/.\n"
1668 "%% Do not edit unless you really know what "
1673 lyxerr.debug() << "lyx header finished" << endl;
1674 // There are a few differences between nice LaTeX and usual files:
1675 // usual is \batchmode and has a
1676 // special input@path to allow the including of figures
1677 // with either \input or \includegraphics (what figinsets do).
1678 // batchmode is not set if there is a tex_code_break_column.
1679 // In this case somebody is interested in the generated LaTeX,
1680 // so this is OK. input@path is set when the actual parameter
1681 // original_path is set. This is done for usual tex-file, but not
1682 // for nice-latex-file. (Matthias 250696)
1685 // code for usual, NOT nice-latex-file
1686 ofs << "\\batchmode\n"; // changed
1687 // from \nonstopmode
1690 if (!original_path.empty()) {
1691 ofs << "\\makeatletter\n"
1692 << "\\def\\input@path{{"
1693 << original_path << "/}}\n"
1694 << "\\makeatother\n";
1700 ofs << "\\documentclass";
1702 string options; // the document class options.
1704 if (tokenPos(tclass.opt_fontsize(), '|', params.fontsize) >= 0) {
1705 // only write if existing in list (and not default)
1706 options += params.fontsize;
1711 if (!params.use_geometry &&
1712 (params.paperpackage == BufferParams::PACKAGE_NONE)) {
1713 switch (params.papersize) {
1714 case BufferParams::PAPER_A4PAPER:
1715 options += "a4paper,";
1717 case BufferParams::PAPER_USLETTER:
1718 options += "letterpaper,";
1720 case BufferParams::PAPER_A5PAPER:
1721 options += "a5paper,";
1723 case BufferParams::PAPER_B5PAPER:
1724 options += "b5paper,";
1726 case BufferParams::PAPER_EXECUTIVEPAPER:
1727 options += "executivepaper,";
1729 case BufferParams::PAPER_LEGALPAPER:
1730 options += "legalpaper,";
1736 if (params.sides != tclass.sides()) {
1737 switch (params.sides) {
1738 case LyXTextClass::OneSide:
1739 options += "oneside,";
1741 case LyXTextClass::TwoSides:
1742 options += "twoside,";
1749 if (params.columns != tclass.columns()) {
1750 if (params.columns == 2)
1751 options += "twocolumn,";
1753 options += "onecolumn,";
1756 if (!params.use_geometry
1757 && params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1758 options += "landscape,";
1760 // language should be a parameter to \documentclass
1761 bool use_babel = false;
1762 if (params.language != "default" ||
1763 !features.UsedLanguages.empty() ) {
1765 for (LaTeXFeatures::LanguageList::const_iterator cit =
1766 features.UsedLanguages.begin();
1767 cit != features.UsedLanguages.end(); ++cit) {
1768 options += (*cit)->lang + ",";
1770 if (default_language != params.language_info)
1771 options += default_language ->lang + ',';
1772 options += params.language_info->lang + ',';
1775 // the user-defined options
1776 if (!params.options.empty()) {
1777 options += params.options + ',';
1780 if (!options.empty()){
1781 options = strip(options, ',');
1782 ofs << '[' << options << ']';
1786 << textclasslist.LatexnameOfClass(params.textclass)
1789 // end of \documentclass defs
1791 // font selection must be done before loading fontenc.sty
1792 if (params.fonts != "default") {
1793 ofs << "\\usepackage{" << params.fonts << "}\n";
1796 // this one is not per buffer
1797 if (lyxrc.fontenc != "default") {
1798 ofs << "\\usepackage[" << lyxrc.fontenc
1802 if (params.inputenc != "default") {
1803 ofs << "\\usepackage[" << params.inputenc
1808 /* at the very beginning the text parameters */
1809 if (params.paperpackage != BufferParams::PACKAGE_NONE) {
1810 switch (params.paperpackage) {
1811 case BufferParams::PACKAGE_A4:
1812 ofs << "\\usepackage{a4}\n";
1815 case BufferParams::PACKAGE_A4WIDE:
1816 ofs << "\\usepackage{a4wide}\n";
1819 case BufferParams::PACKAGE_WIDEMARGINSA4:
1820 ofs << "\\usepackage[widemargins]{a4}\n";
1825 if (params.use_geometry) {
1826 ofs << "\\usepackage{geometry}\n";
1828 ofs << "\\geometry{verbose";
1829 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1830 ofs << ",landscape";
1831 switch (params.papersize2) {
1832 case BufferParams::VM_PAPER_CUSTOM:
1833 if (!params.paperwidth.empty())
1834 ofs << ",paperwidth="
1835 << params.paperwidth;
1836 if (!params.paperheight.empty())
1837 ofs << ",paperheight="
1838 << params.paperheight;
1840 case BufferParams::VM_PAPER_USLETTER:
1841 ofs << ",letterpaper";
1843 case BufferParams::VM_PAPER_USLEGAL:
1844 ofs << ",legalpaper";
1846 case BufferParams::VM_PAPER_USEXECUTIVE:
1847 ofs << ",executivepaper";
1849 case BufferParams::VM_PAPER_A3:
1852 case BufferParams::VM_PAPER_A4:
1855 case BufferParams::VM_PAPER_A5:
1858 case BufferParams::VM_PAPER_B3:
1861 case BufferParams::VM_PAPER_B4:
1864 case BufferParams::VM_PAPER_B5:
1868 // default papersize ie BufferParams::VM_PAPER_DEFAULT
1869 switch (lyxrc.default_papersize) {
1870 case BufferParams::PAPER_DEFAULT: // keep compiler happy
1871 case BufferParams::PAPER_USLETTER:
1872 ofs << ",letterpaper";
1874 case BufferParams::PAPER_LEGALPAPER:
1875 ofs << ",legalpaper";
1877 case BufferParams::PAPER_EXECUTIVEPAPER:
1878 ofs << ",executivepaper";
1880 case BufferParams::PAPER_A3PAPER:
1883 case BufferParams::PAPER_A4PAPER:
1886 case BufferParams::PAPER_A5PAPER:
1889 case BufferParams::PAPER_B5PAPER:
1894 if (!params.topmargin.empty())
1895 ofs << ",tmargin=" << params.topmargin;
1896 if (!params.bottommargin.empty())
1897 ofs << ",bmargin=" << params.bottommargin;
1898 if (!params.leftmargin.empty())
1899 ofs << ",lmargin=" << params.leftmargin;
1900 if (!params.rightmargin.empty())
1901 ofs << ",rmargin=" << params.rightmargin;
1902 if (!params.headheight.empty())
1903 ofs << ",headheight=" << params.headheight;
1904 if (!params.headsep.empty())
1905 ofs << ",headsep=" << params.headsep;
1906 if (!params.footskip.empty())
1907 ofs << ",footskip=" << params.footskip;
1911 if (params.use_amsmath
1912 && !prefixIs(textclasslist.LatexnameOfClass(params.textclass), "ams")) {
1913 ofs << "\\usepackage{amsmath}\n";
1917 if (tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle) >= 0) {
1918 if (params.pagestyle == "fancy") {
1919 ofs << "\\usepackage{fancyhdr}\n";
1922 ofs << "\\pagestyle{" << params.pagestyle << "}\n";
1926 // We try to load babel late, in case it interferes
1927 // with other packages.
1929 ofs << lyxrc.language_package << endl;
1933 if (params.secnumdepth != tclass.secnumdepth()) {
1934 ofs << "\\setcounter{secnumdepth}{"
1935 << params.secnumdepth
1939 if (params.tocdepth != tclass.tocdepth()) {
1940 ofs << "\\setcounter{tocdepth}{"
1946 if (params.paragraph_separation) {
1947 switch (params.defskip.kind()) {
1948 case VSpace::SMALLSKIP:
1949 ofs << "\\setlength\\parskip{\\smallskipamount}\n";
1951 case VSpace::MEDSKIP:
1952 ofs << "\\setlength\\parskip{\\medskipamount}\n";
1954 case VSpace::BIGSKIP:
1955 ofs << "\\setlength\\parskip{\\bigskipamount}\n";
1957 case VSpace::LENGTH:
1958 ofs << "\\setlength\\parskip{"
1959 << params.defskip.length().asLatexString()
1962 default: // should never happen // Then delete it.
1963 ofs << "\\setlength\\parskip{\\medskipamount}\n";
1968 ofs << "\\setlength\\parindent{0pt}\n";
1972 // Now insert the LyX specific LaTeX commands...
1973 string preamble, tmppreamble;
1975 // The optional packages;
1976 preamble = features.getPackages();
1978 // this might be useful...
1979 preamble += "\n\\makeatletter\n\n";
1981 // Some macros LyX will need
1982 tmppreamble = features.getMacros();
1984 if (!tmppreamble.empty()) {
1985 preamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1986 "LyX specific LaTeX commands.\n"
1987 + tmppreamble + '\n';
1990 // the text class specific preamble
1991 tmppreamble = features.getTClassPreamble();
1992 if (!tmppreamble.empty()) {
1993 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1994 "Textclass specific LaTeX commands.\n"
1995 + tmppreamble + '\n';
1998 /* the user-defined preamble */
1999 if (!params.preamble.empty()) {
2000 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2001 "User specified LaTeX commands.\n"
2002 + params.preamble + '\n';
2005 preamble += "\\makeatother\n\n";
2007 // Itemize bullet settings need to be last in case the user
2008 // defines their own bullets that use a package included
2009 // in the user-defined preamble -- ARRae
2010 // Actually it has to be done much later than that
2011 // since some packages like frenchb make modifications
2012 // at \begin{document} time -- JMarc
2014 for (int i = 0; i < 4; ++i) {
2015 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
2016 if (bullets_def.empty())
2017 bullets_def="\\AtBeginDocument{\n";
2018 bullets_def += " \\renewcommand{\\labelitemi";
2020 // `i' is one less than the item to modify
2027 bullets_def += "ii";
2033 bullets_def += "}{" +
2034 params.user_defined_bullets[i].getText()
2039 if (!bullets_def.empty())
2040 preamble += bullets_def + "}\n\n";
2042 for (int j = countChar(preamble, '\n'); j-- ;) {
2049 ofs << "\\begin{document}\n\n";
2053 lyxerr.debug() << "preamble finished, now the body." << endl;
2054 if (!lyxrc.language_auto_begin && params.language != "default") {
2055 ofs << subst(lyxrc.language_command_begin, "$$lang",
2061 bool was_title = false;
2062 bool already_title = false;
2064 std::ostringstream ftnote;
2066 char * tmpholder = 0;
2071 LyXParagraph * par = paragraph;
2075 #ifndef HAVE_SSTREAM
2078 ftnote << tmpholder;
2079 delete [] tmpholder;
2084 lyxerr[Debug::LATEX] << "Error in MakeLateXFile."
2086 LyXLayout const & layout =
2087 textclasslist.Style(params.textclass,
2090 if (layout.intitle) {
2091 if (already_title) {
2092 lyxerr <<"Error in MakeLatexFile: You"
2093 " should not mix title layouts"
2094 " with normal ones." << endl;
2097 } else if (was_title && !already_title) {
2098 ofs << "\\maketitle\n";
2100 already_title = true;
2103 // We are at depth 0 so we can just use
2104 // ordinary \footnote{} generation
2105 // flag this with ftcount
2107 if (layout.isEnvironment()
2108 || par->pextra_type != LyXParagraph::PEXTRA_NONE) {
2109 par = par->TeXEnvironment(ofs, texrow,
2110 ftnote, ft_texrow, ftcount);
2112 par = par->TeXOnePar(ofs, texrow,
2113 ftnote, ft_texrow, ftcount);
2116 // Write out what we've generated...
2119 ofs << "\\addtocounter{footnote}{-"
2123 ofs << ftnote.str();
2124 texrow += ft_texrow;
2126 // The extra .c_str() is needed when we use
2127 // lyxstring instead of the STL string class.
2128 ftnote.str(string().c_str());
2130 delete [] ftnote.str();
2135 #ifndef HAVE_SSTREAM
2137 // I hate strstreams
2138 tmpholder = ftnote.str();
2142 #ifndef HAVE_SSTREAM
2143 delete [] tmpholder;
2145 // It might be that we only have a title in this document
2146 if (was_title && !already_title) {
2147 ofs << "\\maketitle\n";
2151 if (!lyxrc.language_auto_end && params.language != "default") {
2152 ofs << subst(lyxrc.language_command_end, "$$lang",
2159 ofs << "\\end{document}\n";
2162 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
2164 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
2168 // Just to be sure. (Asger)
2171 // tex_code_break_column's value is used to decide
2172 // if we are in batchmode or not (within mathed_write()
2173 // in math_write.C) so we must set it to a non-zero
2174 // value when we leave otherwise we save incorrect .lyx files.
2175 tex_code_break_column = lyxrc.ascii_linelen;
2179 lyxerr << "File was not closed properly." << endl;
2182 lyxerr.debug() << "Finished making latex file." << endl;
2186 bool Buffer::isLatex() const
2188 return textclasslist.TextClass(params.textclass).outputType() == LATEX;
2192 bool Buffer::isLinuxDoc() const
2194 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC;
2198 bool Buffer::isLiterate() const
2200 return textclasslist.TextClass(params.textclass).outputType() == LITERATE;
2204 bool Buffer::isDocBook() const
2206 return textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2210 bool Buffer::isSGML() const
2212 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC ||
2213 textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2217 void Buffer::sgmlOpenTag(ostream & os, int depth,
2218 string const & latexname) const
2220 os << string(depth, ' ') << "<" << latexname << ">\n";
2224 void Buffer::sgmlCloseTag(ostream & os, int depth,
2225 string const & latexname) const
2227 os << string(depth, ' ') << "</" << latexname << ">\n";
2231 void Buffer::makeLinuxDocFile(string const & fname, int column)
2233 LyXParagraph * par = paragraph;
2235 string top_element = textclasslist.LatexnameOfClass(params.textclass);
2236 string environment_stack[10];
2239 int depth = 0; /* paragraph depth */
2241 ofstream ofs(fname.c_str());
2244 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2248 tex_code_break_column = column;
2251 if (params.preamble.empty()) {
2252 ofs << "<!doctype linuxdoc system>\n\n";
2255 ofs << "<!doctype linuxdoc system \n [ "
2256 << params.preamble << " \n]>\n\n";
2259 ofs << "<!-- " << LYX_DOCVERSION
2260 << " created this file. For more info see http://www.lyx.org/"
2263 if(params.options.empty())
2264 sgmlOpenTag(ofs, 0, top_element);
2266 string top = top_element;
2268 top += params.options;
2269 sgmlOpenTag(ofs, 0, top);
2273 int desc_on = 0; /* description mode*/
2274 LyXLayout const & style =
2275 textclasslist.Style(users->buffer()->params.textclass,
2277 par->AutoDeleteInsets();
2279 /* treat <toc> as a special case for compatibility with old code */
2280 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2281 Inset * inset = par->GetInset(0);
2282 char lyx_code = inset->LyxCode();
2283 if (lyx_code == Inset::TOC_CODE){
2284 string temp = "toc";
2285 sgmlOpenTag(ofs, depth, temp);
2288 linuxDocHandleFootnote(ofs, par, depth);
2293 // environment tag closing
2294 for( ; depth > par->depth; --depth) {
2295 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2296 environment_stack[depth].clear();
2299 // write opening SGML tags
2300 switch(style.latextype) {
2301 case LATEX_PARAGRAPH:
2302 if(depth == par->depth
2303 && !environment_stack[depth].empty()) {
2304 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2305 environment_stack[depth].clear();
2311 sgmlOpenTag(ofs, depth, style.latexname());
2316 LinuxDocError(par, 0, _("Error : Wrong depth for LatexType Command.\n"));
2318 if (!environment_stack[depth].empty()){
2319 sgmlCloseTag(ofs, depth,
2320 environment_stack[depth]);
2324 environment_stack[depth].clear();
2325 sgmlOpenTag(ofs, depth, style.latexname());
2328 case LATEX_ENVIRONMENT:
2329 case LATEX_ITEM_ENVIRONMENT:
2330 if(depth == par->depth
2331 && environment_stack[depth] != style.latexname()
2332 && !environment_stack[depth].empty()) {
2334 sgmlCloseTag(ofs, depth,
2335 environment_stack[depth]);
2336 environment_stack[depth].clear();
2338 if (depth < par->depth) {
2340 environment_stack[depth].clear();
2342 if (environment_stack[depth] != style.latexname()) {
2345 sgmlOpenTag(ofs, depth, temp);
2347 environment_stack[depth] = style.latexname();
2348 sgmlOpenTag(ofs, depth, environment_stack[depth]);
2350 if(style.latextype == LATEX_ENVIRONMENT) break;
2352 desc_on = (style.labeltype == LABEL_MANUAL);
2359 sgmlOpenTag(ofs, depth + 1, item_name);
2362 sgmlOpenTag(ofs, depth, style.latexname());
2367 SimpleLinuxDocOnePar(ofs, par, desc_on, depth);
2370 linuxDocHandleFootnote(ofs, par, depth);
2372 while(par && par->IsDummy());
2375 /* write closing SGML tags */
2376 switch(style.latextype) {
2378 case LATEX_ENVIRONMENT:
2379 case LATEX_ITEM_ENVIRONMENT:
2382 sgmlCloseTag(ofs, depth, style.latexname());
2387 /* Close open tags */
2388 for(; depth > 0; --depth)
2389 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2391 if(!environment_stack[depth].empty())
2392 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2395 sgmlCloseTag(ofs, 0, top_element);
2398 // How to check for successful close
2402 void Buffer::linuxDocHandleFootnote(ostream & os, LyXParagraph * & par,
2405 string tag = "footnote";
2407 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2408 sgmlOpenTag(os, depth + 1, tag);
2409 SimpleLinuxDocOnePar(os, par, 0, depth + 1);
2410 sgmlCloseTag(os, depth + 1, tag);
2416 void Buffer::DocBookHandleCaption(ostream & os, string & inner_tag,
2417 int const depth, int desc_on,
2418 LyXParagraph * & par)
2420 LyXParagraph * tpar = par;
2421 while (tpar && (tpar->footnoteflag != LyXParagraph::NO_FOOTNOTE) &&
2422 (tpar->layout != textclasslist.NumberOfLayout(params.textclass,
2426 tpar->layout == textclasslist.NumberOfLayout(params.textclass,
2427 "Caption").second) {
2428 sgmlOpenTag(os, depth + 1, inner_tag);
2430 SimpleDocBookOnePar(os, extra_par, tpar,
2431 desc_on, depth + 2);
2432 sgmlCloseTag(os, depth+1, inner_tag);
2433 if(!extra_par.empty())
2439 void Buffer::DocBookHandleFootnote(ostream & os, LyXParagraph * & par,
2442 string tag, inner_tag;
2443 string tmp_par, extra_par;
2444 bool inner_span = false;
2447 // Someone should give this enum a proper name (Lgb)
2455 SOME_ENUM last = NO_ONE;
2456 SOME_ENUM present = FOOTNOTE_LIKE;
2458 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2459 if(last == present) {
2461 if(!tmp_par.empty()) {
2464 sgmlCloseTag(os, depth + 1, inner_tag);
2465 sgmlOpenTag(os, depth + 1, inner_tag);
2472 if(!inner_tag.empty()) sgmlCloseTag(os, depth + 1,
2474 if(!extra_par.empty()) os << extra_par;
2475 if(!tag.empty()) sgmlCloseTag(os, depth, tag);
2478 switch (par->footnotekind) {
2479 case LyXParagraph::FOOTNOTE:
2480 case LyXParagraph::ALGORITHM:
2483 present = FOOTNOTE_LIKE;
2486 case LyXParagraph::MARGIN:
2489 present = MARGIN_LIKE;
2492 case LyXParagraph::FIG:
2493 case LyXParagraph::WIDE_FIG:
2495 inner_tag = "title";
2499 case LyXParagraph::TAB:
2500 case LyXParagraph::WIDE_TAB:
2502 inner_tag = "title";
2507 sgmlOpenTag(os, depth, tag);
2508 if ((present == TAB_LIKE) || (present == FIG_LIKE)) {
2509 DocBookHandleCaption(os, inner_tag, depth,
2513 sgmlOpenTag(os, depth + 1, inner_tag);
2516 // ignore all caption here, we processed them above!!!
2517 if (par->layout != textclasslist
2518 .NumberOfLayout(params.textclass,
2519 "Caption").second) {
2521 std::ostringstream ost;
2525 SimpleDocBookOnePar(ost, extra_par, par,
2526 desc_on, depth + 2);
2528 tmp_par += ost.str().c_str();
2531 char * ctmp = ost.str();
2536 tmp_par = frontStrip(strip(tmp_par));
2542 if(!inner_tag.empty()) sgmlCloseTag(os, depth + 1, inner_tag);
2543 if(!extra_par.empty()) os << extra_par;
2544 if(!tag.empty()) sgmlCloseTag(os, depth, tag);
2548 /* push a tag in a style stack */
2549 void Buffer::push_tag(ostream & os, char const * tag,
2550 int & pos, char stack[5][3])
2552 /* pop all previous tags */
2553 for (int j = pos; j >= 0; --j)
2554 os << "</" << stack[j] << ">";
2557 sprintf(stack[++pos], "%s", tag);
2560 for (int i = 0; i <= pos; ++i)
2561 os << "<" << stack[i] << ">";
2565 void Buffer::pop_tag(ostream & os, char const * tag,
2566 int & pos, char stack[5][3])
2570 // pop all tags till specified one
2571 for (j = pos; (j >= 0) && (strcmp(stack[j], tag)); --j)
2572 os << "</" << stack[j] << ">";
2575 os << "</" << tag << ">";
2577 // push all tags, but the specified one
2578 for (j = j + 1; j <= pos; ++j) {
2579 os << "<" << stack[j] << ">";
2580 strcpy(stack[j-1], stack[j]);
2586 /* handle internal paragraph parsing -- layout already processed */
2588 // checks, if newcol chars should be put into this line
2589 // writes newline, if necessary.
2591 void linux_doc_line_break(ostream & os, unsigned int & colcount,
2592 const unsigned int newcol)
2595 if (colcount > lyxrc.ascii_linelen) {
2597 colcount = newcol; // assume write after this call
2602 void Buffer::SimpleLinuxDocOnePar(ostream & os, LyXParagraph * par,
2603 int desc_on, int const /*depth*/)
2605 LyXFont font1, font2;
2608 LyXParagraph::size_type main_body;
2610 LyXLayout const & style = textclasslist.Style(params.textclass,
2613 char family_type = 0; // family font flag
2614 bool is_bold = false; // series font flag
2615 char shape_type = 0; // shape font flag
2616 bool is_em = false; // emphasis (italic) font flag
2618 int stack_num = -1; // style stack position
2619 char stack[5][3]; // style stack
2620 unsigned int char_line_count = 5; // Heuristic choice ;-)
2622 if (style.labeltype != LABEL_MANUAL)
2625 main_body = par->BeginningOfMainBody();
2627 /* gets paragraph main font */
2629 font1 = style.labelfont;
2634 /* parsing main loop */
2635 for (LyXParagraph::size_type i = 0;
2636 i < par->size(); ++i) {
2638 /* handle quote tag */
2639 if (i == main_body && !par->IsDummy()) {
2644 font2 = par->getFont(i);
2646 if (font1.family() != font2.family()) {
2647 switch(family_type) {
2649 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2650 push_tag(os, "tt", stack_num, stack);
2653 else if (font2.family() == LyXFont::SANS_FAMILY) {
2654 push_tag(os, "sf", stack_num, stack);
2659 pop_tag(os, "tt", stack_num, stack);
2660 if (font2.family() == LyXFont::SANS_FAMILY) {
2661 push_tag(os, "sf", stack_num, stack);
2669 pop_tag(os, "sf", stack_num, stack);
2670 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2671 push_tag(os, "tt", stack_num, stack);
2680 /* handle bold face */
2681 if (font1.series() != font2.series()) {
2682 if (font2.series() == LyXFont::BOLD_SERIES) {
2683 push_tag(os, "bf", stack_num, stack);
2687 pop_tag(os, "bf", stack_num, stack);
2692 /* handle italic and slanted fonts */
2693 if (font1.shape() != font2.shape()) {
2694 switch(shape_type) {
2696 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2697 push_tag(os, "it", stack_num, stack);
2700 else if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2701 push_tag(os, "sl", stack_num, stack);
2706 pop_tag(os, "it", stack_num, stack);
2707 if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2708 push_tag(os, "sl", stack_num, stack);
2716 pop_tag(os, "sl", stack_num, stack);
2717 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2718 push_tag(os, "it", stack_num, stack);
2726 /* handle <em> tag */
2727 if (font1.emph() != font2.emph()) {
2728 if (font2.emph() == LyXFont::ON) {
2729 push_tag(os, "em", stack_num, stack);
2732 pop_tag(os, "em", stack_num, stack);
2737 c = par->GetChar(i);
2739 if (font2.latex() == LyXFont::ON) {
2740 // "TeX"-Mode on == > SGML-Mode on.
2742 os << c; // see LaTeX-Generation...
2744 } else if (c == LyXParagraph::META_INSET) {
2745 inset = par->GetInset(i);
2746 inset->Linuxdoc(os);
2749 if (par->linuxDocConvertChar(c, sgml_string)
2750 && !style.free_spacing) { // in freespacing
2752 // non-breaking characters
2756 linux_doc_line_break(os, char_line_count, 6);
2761 linux_doc_line_break(os, char_line_count, 1);
2767 char_line_count += sgml_string.length();
2773 /* needed if there is an optional argument but no contents */
2774 if (main_body > 0 && main_body == par->size()) {
2778 /* pop all defined Styles */
2779 for (j = stack_num; j >= 0; --j) {
2780 linux_doc_line_break(os,
2782 3 + strlen(stack[j]));
2783 os << "</" << stack[j] << ">";
2786 /* resets description flag correctly */
2789 /* <tag> not closed... */
2790 linux_doc_line_break(os, char_line_count, 6);
2794 /* fprintf(file, "</p>");*/
2800 /* print an error message */
2801 void Buffer::LinuxDocError(LyXParagraph * par, int pos,
2802 char const * message)
2804 InsetError * new_inset;
2806 /* insert an error marker in text */
2807 new_inset = new InsetError(message);
2808 par->InsertChar(pos, LyXParagraph::META_INSET);
2809 par->InsertInset(pos, new_inset);
2812 // This constant defines the maximum number of
2813 // environment layouts that can be nesteded.
2814 // The same applies for command layouts.
2815 // These values should be more than enough.
2816 // José Matos (1999/07/22)
2818 enum { MAX_NEST_LEVEL = 25};
2820 void Buffer::makeDocBookFile(string const & fname, int column)
2822 LyXParagraph * par = paragraph;
2824 string top_element= textclasslist.LatexnameOfClass(params.textclass);
2825 string environment_stack[MAX_NEST_LEVEL];
2826 string environment_inner[MAX_NEST_LEVEL];
2827 string command_stack[MAX_NEST_LEVEL];
2828 bool command_flag= false;
2829 int command_depth= 0, command_base= 0, cmd_depth= 0;
2831 string item_name, command_name;
2832 string c_depth, c_params, tmps;
2834 int depth= 0; /* paragraph depth */
2836 tex_code_break_column = column;
2838 ofstream ofs(fname.c_str());
2840 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2846 ofs << "<!doctype " << top_element
2847 << " public \"-//OASIS//DTD DocBook V3.1//EN\"";
2849 if (params.preamble.empty())
2852 ofs << "\n [ " << params.preamble << " \n]>\n\n";
2854 ofs << "<!-- DocBook file was created by " << LYX_DOCVERSION
2855 << "\n See http://www.lyx.org/ for more information -->\n";
2857 if(params.options.empty())
2858 sgmlOpenTag(ofs, 0, top_element);
2860 string top = top_element;
2862 top += params.options;
2863 sgmlOpenTag(ofs, 0, top);
2867 int desc_on = 0; /* description mode*/
2868 LyXLayout const & style =
2869 textclasslist.Style(users->buffer()->params.textclass,
2871 par->AutoDeleteInsets();
2873 /* environment tag closing */
2874 for( ; depth > par->depth; --depth) {
2875 if(environment_inner[depth] != "!-- --") {
2876 item_name= "listitem";
2877 sgmlCloseTag(ofs, command_depth + depth,
2879 if( environment_inner[depth] == "varlistentry")
2880 sgmlCloseTag(ofs, depth+command_depth,
2881 environment_inner[depth]);
2883 sgmlCloseTag(ofs, depth + command_depth,
2884 environment_stack[depth]);
2885 environment_stack[depth].clear();
2886 environment_inner[depth].clear();
2889 if(depth == par->depth
2890 && environment_stack[depth] != style.latexname()
2891 && !environment_stack[depth].empty()) {
2892 if(environment_inner[depth] != "!-- --") {
2893 item_name= "listitem";
2894 sgmlCloseTag(ofs, command_depth+depth,
2896 if( environment_inner[depth] == "varlistentry")
2898 depth + command_depth,
2899 environment_inner[depth]);
2902 sgmlCloseTag(ofs, depth + command_depth,
2903 environment_stack[depth]);
2905 environment_stack[depth].clear();
2906 environment_inner[depth].clear();
2909 // Write opening SGML tags.
2910 switch(style.latextype) {
2911 case LATEX_PARAGRAPH:
2912 if(style.latexname() != "dummy")
2913 sgmlOpenTag(ofs, depth+command_depth,
2919 LinuxDocError(par, 0,
2920 _("Error : Wrong depth for "
2921 "LatexType Command.\n"));
2923 command_name = style.latexname();
2925 tmps = style.latexparam();
2926 c_params = split(tmps, c_depth,'|');
2928 cmd_depth= atoi(c_depth.c_str());
2931 if(cmd_depth<command_base) {
2932 for(int j = command_depth;
2933 j >= command_base; --j)
2934 if(!command_stack[j].empty())
2935 sgmlCloseTag(ofs, j, command_stack[j]);
2936 command_depth= command_base= cmd_depth;
2938 else if(cmd_depth <= command_depth) {
2939 for(int j = command_depth;
2940 j >= cmd_depth; --j)
2942 if(!command_stack[j].empty())
2943 sgmlCloseTag(ofs, j, command_stack[j]);
2944 command_depth= cmd_depth;
2947 command_depth= cmd_depth;
2950 command_depth = command_base = cmd_depth;
2951 command_flag = true;
2953 command_stack[command_depth]= command_name;
2955 // treat label as a special case for
2956 // more WYSIWYM handling.
2957 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2958 Inset * inset = par->GetInset(0);
2959 char lyx_code = inset->LyxCode();
2960 if (lyx_code == Inset::LABEL_CODE){
2961 command_name += " id=\"";
2962 command_name += (static_cast<InsetCommand *>(inset))->getContents();
2963 command_name += "\"";
2968 sgmlOpenTag(ofs, depth+command_depth, command_name);
2969 item_name = "title";
2970 sgmlOpenTag(ofs, depth + 1 + command_depth, item_name);
2973 case LATEX_ENVIRONMENT:
2974 case LATEX_ITEM_ENVIRONMENT:
2975 if (depth < par->depth) {
2977 environment_stack[depth].clear();
2980 if (environment_stack[depth] != style.latexname()) {
2981 environment_stack[depth] = style.latexname();
2982 environment_inner[depth] = "!-- --";
2983 sgmlOpenTag(ofs, depth + command_depth,
2984 environment_stack[depth]);
2986 if(environment_inner[depth] != "!-- --") {
2987 item_name= "listitem";
2989 command_depth + depth,
2991 if (environment_inner[depth] == "varlistentry")
2993 depth + command_depth,
2994 environment_inner[depth]);
2998 if(style.latextype == LATEX_ENVIRONMENT) {
2999 if(!style.latexparam().empty())
3000 sgmlOpenTag(ofs, depth + command_depth,
3001 style.latexparam());
3005 desc_on = (style.labeltype == LABEL_MANUAL);
3008 environment_inner[depth]= "varlistentry";
3010 environment_inner[depth]= "listitem";
3012 sgmlOpenTag(ofs, depth + 1 + command_depth,
3013 environment_inner[depth]);
3017 sgmlOpenTag(ofs, depth + 1 + command_depth,
3022 sgmlOpenTag(ofs, depth + 1 + command_depth,
3027 sgmlOpenTag(ofs, depth + command_depth,
3034 SimpleDocBookOnePar(ofs, extra_par, par, desc_on,
3035 depth + 1 + command_depth);
3037 DocBookHandleFootnote(ofs, par,
3038 depth + 1 + command_depth);
3040 while(par && par->IsDummy());
3043 /* write closing SGML tags */
3044 switch(style.latextype) {
3047 sgmlCloseTag(ofs, depth + command_depth, end_tag);
3049 case LATEX_ENVIRONMENT:
3050 if(!style.latexparam().empty())
3051 sgmlCloseTag(ofs, depth + command_depth,
3052 style.latexparam());
3054 case LATEX_ITEM_ENVIRONMENT:
3055 if(desc_on == 1) break;
3057 sgmlCloseTag(ofs, depth + 1 + command_depth, end_tag);
3059 case LATEX_PARAGRAPH:
3060 if(style.latexname() != "dummy")
3061 sgmlCloseTag(ofs, depth + command_depth,
3065 sgmlCloseTag(ofs, depth + command_depth,
3072 for(; depth >= 0; --depth) {
3073 if(!environment_stack[depth].empty()) {
3074 if(environment_inner[depth] != "!-- --") {
3075 item_name= "listitem";
3076 sgmlCloseTag(ofs, command_depth + depth,
3078 if( environment_inner[depth] == "varlistentry")
3079 sgmlCloseTag(ofs, depth + command_depth,
3080 environment_inner[depth]);
3083 sgmlCloseTag(ofs, depth + command_depth,
3084 environment_stack[depth]);
3088 for(int j = command_depth; j >= command_base; --j)
3089 if(!command_stack[j].empty())
3090 sgmlCloseTag(ofs, j, command_stack[j]);
3093 sgmlCloseTag(ofs, 0, top_element);
3096 // How to check for successful close
3100 void Buffer::SimpleDocBookOnePar(ostream & os, string & extra,
3101 LyXParagraph * par, int & desc_on,
3105 par->SimpleDocBookOneTablePar(os, extra, desc_on, depth);
3109 bool emph_flag = false;
3111 LyXLayout const & style = textclasslist.Style(params.textclass,
3114 LyXParagraph::size_type main_body;
3115 if (style.labeltype != LABEL_MANUAL)
3118 main_body = par->BeginningOfMainBody();
3120 // gets paragraph main font
3121 //if (main_body > 0)
3122 // font1 = style.labelfont;
3124 // font1 = style.font;
3125 LyXFont font1 = main_body > 0 ? style.labelfont : style.font;
3127 int char_line_count = depth;
3128 if(!style.free_spacing)
3129 for (int j = 0; j < depth; ++j)
3132 // parsing main loop
3133 for (LyXParagraph::size_type i = 0;
3134 i < par->size(); ++i) {
3135 LyXFont font2 = par->getFont(i);
3137 // handle <emphasis> tag
3138 if (font1.emph() != font2.emph() && i) {
3139 if (font2.emph() == LyXFont::ON) {
3143 os << "</emphasis>";
3148 char c = par->GetChar(i);
3150 if (c == LyXParagraph::META_INSET) {
3151 Inset * inset = par->GetInset(i);
3153 std::ostringstream ost;
3154 inset->DocBook(ost);
3155 string tmp_out = ost.str().c_str();
3158 inset->DocBook(ost);
3160 char * ctmp = ost.str();
3161 string tmp_out(ctmp);
3165 // This code needs some explanation:
3166 // Two insets are treated specially
3167 // label if it is the first element in a command paragraph
3169 // graphics inside tables or figure floats can't go on
3170 // title (the equivalente in latex for this case is caption
3171 // and title should come first
3174 if(desc_on!= 3 || i!= 0) {
3175 if(!tmp_out.empty() && tmp_out[0] == '@') {
3177 extra += frontStrip(tmp_out, '@');
3179 os << frontStrip(tmp_out, '@');
3184 } else if (font2.latex() == LyXFont::ON) {
3185 // "TeX"-Mode on ==> SGML-Mode on.
3192 if (par->linuxDocConvertChar(c, sgml_string)
3193 && !style.free_spacing) { // in freespacing
3195 // non-breaking characters
3199 os << "\n</term><listitem><para>";
3213 /* needed if there is an optional argument but no contents */
3214 if (main_body > 0 && main_body == par->size()) {
3218 os << "</emphasis>";
3221 /* resets description flag correctly */
3224 /* <term> not closed... */
3232 int Buffer::runLaTeX()
3234 if (!users->text) return 0;
3238 // get LaTeX-Filename
3239 string name = getLatexName();
3241 string path = OnlyPath(filename);
3243 string org_path = path;
3244 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3248 Path p(path); // path to LaTeX file
3249 users->owner()->getMiniBuffer()->Set(_("Running LaTeX..."));
3251 // Remove all error insets
3252 bool a = users->removeAutoInsets();
3254 // Always generate the LaTeX file
3255 makeLaTeXFile(name, org_path, false);
3258 // do the LaTex run(s)
3260 string latex_command = lyxrc.pdf_mode ?
3261 lyxrc.pdflatex_command : lyxrc.latex_command;
3262 LaTeX latex(latex_command, name, filepath);
3263 int res = latex.run(terr,
3264 users->owner()->getMiniBuffer()); // running latex
3266 // check return value from latex.run().
3267 if ((res & LaTeX::NO_LOGFILE)) {
3268 WriteAlert(_("LaTeX did not work!"),
3269 _("Missing log file:"), name);
3270 } else if ((res & LaTeX::ERRORS)) {
3271 users->owner()->getMiniBuffer()->Set(_("Done"));
3272 // Insert all errors as errors boxes
3273 users->insertErrors(terr);
3275 // Dvi should also be kept dirty if the latex run
3276 // ends up with errors. However it should be possible
3277 // to view a dirty dvi too.
3279 //no errors or any other things to think about so:
3280 users->owner()->getMiniBuffer()->Set(_("Done"));
3284 // if we removed error insets before we ran LaTeX or if we inserted
3285 // error insets after we ran LaTeX this must be run:
3286 if (a || (res & LaTeX::ERRORS)){
3289 users->updateScrollbar();
3293 return latex.getNumErrors();
3297 int Buffer::runLiterate()
3299 if (!users->text) return 0;
3303 // get LaTeX-Filename
3304 string name = getLatexName();
3305 // get Literate-Filename
3306 string lit_name = ChangeExtension (getLatexName(),
3307 lyxrc.literate_extension, true);
3309 string path = OnlyPath(filename);
3311 string org_path = path;
3312 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3316 Path p(path); // path to Literate file
3317 users->owner()->getMiniBuffer()->Set(_("Running Literate..."));
3319 // Remove all error insets
3320 bool a = users->removeAutoInsets();
3322 // generate the Literate file if necessary
3323 if (!isDviClean() || a) {
3324 makeLaTeXFile(lit_name, org_path, false);
3328 string latex_command = lyxrc.pdf_mode ?
3329 lyxrc.pdflatex_command : lyxrc.latex_command;
3330 Literate literate(latex_command, name, filepath,
3332 lyxrc.literate_command, lyxrc.literate_error_filter,
3333 lyxrc.build_command, lyxrc.build_error_filter);
3335 int res = literate.weave(terr, users->owner()->getMiniBuffer());
3337 // check return value from literate.weave().
3338 if ((res & Literate::NO_LOGFILE)) {
3339 WriteAlert(_("Literate command did not work!"),
3340 _("Missing log file:"), name);
3341 } else if ((res & Literate::ERRORS)) {
3342 users->owner()->getMiniBuffer()->Set(_("Done"));
3343 // Insert all errors as errors boxes
3344 users->insertErrors(terr);
3346 // Dvi should also be kept dirty if the latex run
3347 // ends up with errors. However it should be possible
3348 // to view a dirty dvi too.
3350 //no errors or any other things to think about so:
3351 users->owner()->getMiniBuffer()->Set(_("Done"));
3355 // if we removed error insets before we ran LaTeX or if we inserted
3356 // error insets after we ran LaTeX this must be run:
3357 if (a || (res & Literate::ERRORS)){
3360 users->updateScrollbar();
3364 return literate.getNumErrors();
3368 int Buffer::buildProgram()
3370 if (!users->text) return 0;
3374 // get LaTeX-Filename
3375 string name = getLatexName();
3376 // get Literate-Filename
3377 string lit_name = ChangeExtension(getLatexName(),
3378 lyxrc.literate_extension, true);
3380 string path = OnlyPath(filename);
3382 string org_path = path;
3383 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3387 Path p(path); // path to Literate file
3388 users->owner()->getMiniBuffer()->Set(_("Building Program..."));
3390 // Remove all error insets
3391 bool a = users->removeAutoInsets();
3393 // generate the LaTeX file if necessary
3394 if (!isNwClean() || a) {
3395 makeLaTeXFile(lit_name, org_path, false);
3399 string latex_command = lyxrc.pdf_mode ?
3400 lyxrc.pdflatex_command : lyxrc.latex_command;
3401 Literate literate(latex_command, name, filepath,
3403 lyxrc.literate_command, lyxrc.literate_error_filter,
3404 lyxrc.build_command, lyxrc.build_error_filter);
3406 int res = literate.build(terr, users->owner()->getMiniBuffer());
3408 // check return value from literate.build().
3409 if ((res & Literate::NO_LOGFILE)) {
3410 WriteAlert(_("Build did not work!"),
3411 _("Missing log file:"), name);
3412 } else if ((res & Literate::ERRORS)) {
3413 users->owner()->getMiniBuffer()->Set(_("Done"));
3414 // Insert all errors as errors boxes
3415 users->insertErrors(terr);
3417 // Literate files should also be kept dirty if the literate
3418 // command run ends up with errors.
3420 //no errors or any other things to think about so:
3421 users->owner()->getMiniBuffer()->Set(_("Done"));
3425 // if we removed error insets before we ran Literate/Build or if we inserted
3426 // error insets after we ran Literate/Build this must be run:
3427 if (a || (res & Literate::ERRORS)){
3430 users->updateScrollbar();
3434 return literate.getNumErrors();
3438 // This should be enabled when the Chktex class is implemented. (Asger)
3439 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
3440 // Other flags: -wall -v0 -x
3441 int Buffer::runChktex()
3443 if (!users->text) return 0;
3447 // get LaTeX-Filename
3448 string name = getLatexName();
3449 string path = OnlyPath(filename);
3451 string org_path = path;
3452 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3456 Path p(path); // path to LaTeX file
3457 users->owner()->getMiniBuffer()->Set(_("Running chktex..."));
3459 // Remove all error insets
3460 bool a = users->removeAutoInsets();
3462 // Generate the LaTeX file if neccessary
3463 if (!isDviClean() || a) {
3464 makeLaTeXFile(name, org_path, false);
3469 Chktex chktex(lyxrc.chktex_command, name, filepath);
3470 int res = chktex.run(terr); // run chktex
3473 WriteAlert(_("chktex did not work!"),
3474 _("Could not run with file:"), name);
3475 } else if (res > 0) {
3476 // Insert all errors as errors boxes
3477 users->insertErrors(terr);
3480 // if we removed error insets before we ran chktex or if we inserted
3481 // error insets after we ran chktex, this must be run:
3485 users->updateScrollbar();
3494 void Buffer::RoffAsciiTable(ostream & os, LyXParagraph * par)
3496 LyXFont font1(LyXFont::ALL_INHERIT,params.language_info);
3499 LyXParagraph::size_type i;
3503 string fname1 = TmpFileName(string(), "RAT1");
3504 string fname2 = TmpFileName(string(), "RAT2");
3506 ofstream ofs(fname1.c_str());
3508 WriteAlert(_("LYX_ERROR:"),
3509 _("Cannot open temporary file:"), fname1);
3512 par->table->RoffEndOfCell(ofs, -1);
3513 for (i = 0; i < par->size(); ++i) {
3514 c = par->GetChar(i);
3515 if (par->table->IsContRow(cell)) {
3516 if (c == LyXParagraph::META_NEWLINE)
3520 font2 = par->GetFontSettings(i);
3521 if (font1.latex() != font2.latex()) {
3522 if (font2.latex() != LyXFont::OFF)
3526 case LyXParagraph::META_INSET:
3527 if ((inset = par->GetInset(i))) {
3530 stringstresm ss(ios::in | ios::out);
3531 inset->Latex(ss, -1);
3543 inset->Latex(ss, -1);
3556 fstream fs(fname2.c_str(), ios::in|ios::out);
3558 WriteAlert(_("LYX_ERROR:"),
3559 _("Cannot open temporary file:"), fname2);
3561 remove(fname1.c_str());
3564 inset->Latex(fs, -1);
3578 case LyXParagraph::META_NEWLINE:
3579 if (par->table->CellHasContRow(cell)>= 0)
3580 par->RoffContTableRows(ofs, i+1, cell);
3581 par->table->RoffEndOfCell(ofs, cell);
3584 case LyXParagraph::META_HFILL:
3587 case LyXParagraph::META_PROTECTED_SEPARATOR:
3598 << "RoffAsciiTable:"
3599 " NULL char in structure." << endl;
3603 par->table->RoffEndOfCell(ofs, cell);
3605 string cmd = lyxrc.ascii_roff_command + " >" + fname2;
3606 cmd = subst(cmd, "$$FName", fname1);
3607 Systemcalls one(Systemcalls::System, cmd);
3608 if (!(lyxerr.debugging(Debug::ROFF))) {
3609 remove(fname1.c_str());
3611 ifstream ifs(fname2.c_str());
3613 WriteFSAlert(_("Error! Can't open temporary file:"), fname2);
3616 // now output the produced file
3620 WriteAlert(_("Error!"),
3621 _("Error executing *roff command on table"));
3622 // overread leading blank lines
3623 while(!ifs && (c == '\n'))
3626 for(j = 0; j < par->depth; ++j)
3628 while(!ifs && (c != '\n')) {
3633 // overread trailing blank lines
3634 while(!ifs && (c == '\n'))
3638 remove(fname2.c_str());
3643 /// changed Heinrich Bauer, 23/03/98
3644 bool Buffer::isDviClean() const
3646 if (lyxrc.use_tempdir)
3647 return dvi_clean_tmpd;
3649 return dvi_clean_orgd;
3653 /// changed Heinrich Bauer, 23/03/98
3654 void Buffer::markDviClean()
3656 if (lyxrc.use_tempdir)
3657 dvi_clean_tmpd = true;
3659 dvi_clean_orgd = true;
3663 /// changed Heinrich Bauer, 23/03/98
3664 void Buffer::markDviDirty()
3666 if (lyxrc.use_tempdir)
3667 dvi_clean_tmpd = false;
3669 dvi_clean_orgd = false;
3673 void Buffer::validate(LaTeXFeatures & features) const
3675 LyXParagraph * par = paragraph;
3676 LyXTextClass const & tclass =
3677 textclasslist.TextClass(params.textclass);
3679 // AMS Style is at document level
3681 features.amsstyle = (params.use_amsmath ||
3682 tclass.provides(LyXTextClass::amsmath));
3685 // We don't use "lyxerr.debug" because of speed. (Asger)
3686 if (lyxerr.debugging(Debug::LATEX))
3687 lyxerr << "Paragraph: " << par << endl;
3689 // Now just follow the list of paragraphs and run
3690 // validate on each of them.
3691 par->validate(features);
3693 // and then the next paragraph
3697 // the bullet shapes are buffer level not paragraph level
3698 // so they are tested here
3699 for (int i = 0; i < 4; ++i) {
3700 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
3701 int font = params.user_defined_bullets[i].getFont();
3704 .user_defined_bullets[i]
3711 features.latexsym = true;
3715 features.amssymb = true;
3717 else if ((font >= 2 && font <= 5)) {
3718 features.pifont = true;
3723 if (lyxerr.debugging(Debug::LATEX)) {
3724 features.showStruct();
3729 void Buffer::setPaperStuff()
3731 params.papersize = BufferParams::PAPER_DEFAULT;
3732 char c1 = params.paperpackage;
3733 if (c1 == BufferParams::PACKAGE_NONE) {
3734 char c2 = params.papersize2;
3735 if (c2 == BufferParams::VM_PAPER_USLETTER)
3736 params.papersize = BufferParams::PAPER_USLETTER;
3737 else if (c2 == BufferParams::VM_PAPER_USLEGAL)
3738 params.papersize = BufferParams::PAPER_LEGALPAPER;
3739 else if (c2 == BufferParams::VM_PAPER_USEXECUTIVE)
3740 params.papersize = BufferParams::PAPER_EXECUTIVEPAPER;
3741 else if (c2 == BufferParams::VM_PAPER_A3)
3742 params.papersize = BufferParams::PAPER_A3PAPER;
3743 else if (c2 == BufferParams::VM_PAPER_A4)
3744 params.papersize = BufferParams::PAPER_A4PAPER;
3745 else if (c2 == BufferParams::VM_PAPER_A5)
3746 params.papersize = BufferParams::PAPER_A5PAPER;
3747 else if ((c2 == BufferParams::VM_PAPER_B3) || (c2 == BufferParams::VM_PAPER_B4) ||
3748 (c2 == BufferParams::VM_PAPER_B5))
3749 params.papersize = BufferParams::PAPER_B5PAPER;
3750 } else if ((c1 == BufferParams::PACKAGE_A4) || (c1 == BufferParams::PACKAGE_A4WIDE) ||
3751 (c1 == BufferParams::PACKAGE_WIDEMARGINSA4))
3752 params.papersize = BufferParams::PAPER_A4PAPER;
3756 // This function should be in Buffer because it's a buffer's property (ale)
3757 string Buffer::getIncludeonlyList(char delim)
3760 LyXParagraph * par = paragraph;
3761 LyXParagraph::size_type pos;
3765 while ((inset = par->ReturnNextInsetPointer(pos))){
3766 if (inset->LyxCode() == Inset::INCLUDE_CODE) {
3767 InsetInclude * insetinc =
3768 static_cast<InsetInclude*>(inset);
3769 if (insetinc->isInclude()
3770 && insetinc->isNoLoad()) {
3773 lst += ChangeExtension(insetinc->getContents(), string(), true);
3780 lyxerr.debug() << "Includeonly(" << lst << ')' << endl;
3785 // This is also a buffer property (ale)
3786 string Buffer::getReferenceList(char delim)
3788 /// if this is a child document and the parent is already loaded
3789 /// Use the parent's list instead [ale990407]
3790 if (!params.parentname.empty()
3791 && bufferlist.exists(params.parentname)) {
3792 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3794 return tmp->getReferenceList(delim);
3797 LyXParagraph * par = paragraph;
3798 LyXParagraph::size_type pos;
3803 while ((inset = par->ReturnNextInsetPointer(pos))){
3804 for (int i = 0; i < inset->GetNumberOfLabels(); ++i) {
3807 lst += inset->getLabel(i);
3813 lyxerr.debug() << "References(" << lst << ")" << endl;
3818 // This is also a buffer property (ale)
3819 string Buffer::getBibkeyList(char delim)
3821 /// if this is a child document and the parent is already loaded
3822 /// Use the parent's list instead [ale990412]
3823 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3824 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3826 return tmp->getBibkeyList(delim);
3830 LyXParagraph * par = paragraph;
3833 if (!bibkeys.empty())
3835 bibkeys += par->bibkey->getContents();
3840 // Might be either using bibtex or a child has bibliography
3841 if (bibkeys.empty()) {
3845 LyXParagraph::size_type pos = -1;
3847 // Search for Bibtex or Include inset
3848 while ((inset = par->ReturnNextInsetPointer(pos))) {
3849 if (inset-> LyxCode() == Inset::BIBTEX_CODE) {
3850 if (!bibkeys.empty())
3852 bibkeys += static_cast<InsetBibtex*>(inset)->getKeys(delim);
3853 } else if (inset-> LyxCode() == Inset::INCLUDE_CODE) {
3854 string bk = static_cast<InsetInclude*>(inset)->getKeys(delim);
3856 if (!bibkeys.empty())
3867 lyxerr.debug() << "Bibkeys(" << bibkeys << ")" << endl;
3872 bool Buffer::isDepClean(string const & name) const
3874 DEPCLEAN * item = dep_clean;
3875 while (item && item->master != name)
3877 if (!item) return true;
3882 void Buffer::markDepClean(string const & name)
3885 dep_clean = new DEPCLEAN;
3886 dep_clean->clean = true;
3887 dep_clean->master = name;
3888 dep_clean->next = 0;
3890 DEPCLEAN* item = dep_clean;
3891 while (item && item->master != name)
3896 item = new DEPCLEAN;
3898 item->master = name;
3905 void Buffer::Dispatch(string const & command)
3907 // Split command string into command and argument
3908 string cmd, line = frontStrip(command);
3909 string arg = strip(frontStrip(split(line, cmd, ' ')));
3911 Dispatch(lyxaction.LookupFunc(cmd.c_str()), arg.c_str());
3915 void Buffer::Dispatch(int action, string const & argument)
3919 MenuExport(this, argument);
3923 lyxerr << "A truly unknown func!" << endl;
3929 void Buffer::ChangeLanguage(Language const * from, Language const * to)
3932 LyXParagraph * par = paragraph;
3934 par->ChangeLanguage(from,to);
3939 bool Buffer::isMultiLingual()
3942 LyXParagraph * par = paragraph;
3944 if (par->isMultiLingual())