1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-1999 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
39 #pragma implementation "buffer.h"
43 #include "bufferlist.h"
45 #include "lyx_gui_misc.h"
46 #include "LyXAction.h"
49 #include "tex-strings.h"
52 #include "minibuffer.h"
55 #include "mathed/formulamacro.h"
56 #include "insets/lyxinset.h"
57 #include "insets/inseterror.h"
58 #include "insets/insetlabel.h"
59 #include "insets/insetref.h"
60 #include "insets/inseturl.h"
61 #include "insets/insetinfo.h"
62 #include "insets/insetquotes.h"
64 #include "insets/insetlatex.h"
66 #include "insets/insetlatexaccent.h"
67 #include "insets/insetbib.h"
68 #include "insets/insetindex.h"
69 #include "insets/insetinclude.h"
70 #include "insets/insettoc.h"
71 #include "insets/insetlof.h"
72 #include "insets/insetlot.h"
73 #include "insets/insetloa.h"
74 #include "insets/insetparent.h"
75 #include "insets/insetspecialchar.h"
76 #include "insets/figinset.h"
77 #include "support/filetools.h"
78 #include "support/path.h"
84 #include "LaTeXFeatures.h"
85 #include "support/syscall.h"
86 #include "support/lyxlib.h"
87 #include "support/FileInfo.h"
91 // Uncomment this line to enable a workaround for the weird behaviour
92 // of the cursor between a displayed inset and last character
93 // at the upper line. (Alejandro 20.9.96)
94 // #define BREAK_BEFORE_INSET
96 /* Lars, when changing this file sometime in the future to a list,
97 * please check out the figinsets-sideeffects described at the
98 * beginning of figinset.C Matthias (04.07.1996)
102 // all these externs should eventually be removed.
103 extern BufferList bufferlist;
104 extern void SmallUpdate(signed char);
105 extern unsigned char GetCurrentTextClass();
106 extern void BeforeChange();
108 extern void MenuExport(Buffer *, string const &);
109 extern LyXAction lyxaction;
112 static const float LYX_FORMAT = 2.15;
114 extern int tex_code_break_column;
116 extern void FreeUpdateTimer();
119 Buffer::Buffer(string const & file, LyXRC * lyxrc, bool ronly)
121 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
123 filepath = OnlyPath(file);
125 the_locking_inset = 0;
128 dvi_clean_orgd = false; // Heinrich Bauer, 23/03/98
129 dvi_clean_tmpd = false; // Heinrich Bauer, 23/03/98
135 if (read_only || (lyxrc && lyxrc->use_tempdir)) {
136 tmppath = CreateBufferTmpDir();
137 } else tmppath.clear();
143 lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
144 // here the buffer should take care that it is
145 // saved properly, before it goes into the void.
147 // make sure that views using this buffer
152 if (!tmppath.empty()) {
153 DestroyBufferTmpDir(tmppath);
156 LyXParagraph * par = paragraph;
157 LyXParagraph * tmppar;
167 bool Buffer::saveParamsAsDefaults()
169 string fname = AddName(AddPath(user_lyxdir, "templates/"),
171 Buffer defaults = Buffer(fname);
173 // Use the current buffer's parameters as default
174 defaults.params = params;
176 // add an empty paragraph. Is this enough?
177 defaults.paragraph = new LyXParagraph;
179 return defaults.writeFile(defaults.filename, false);
183 /// Update window titles of all users
184 // Should work on a list
185 void Buffer::updateTitles()
187 if (users) users->owner()->updateWindowTitle();
191 /// Reset autosave timer of all users
192 // Should work on a list
193 void Buffer::resetAutosaveTimers()
195 if (users) users->owner()->resetAutosaveTimer();
199 void Buffer::fileName(string const & newfile)
201 filename = MakeAbsPath(newfile);
202 filepath = OnlyPath(filename);
203 setReadonly(IsFileWriteable(filename) == 0);
208 // candidate for move to BufferView
209 void Buffer::InsetUnlock()
211 if (the_locking_inset) {
212 if (!inset_slept) the_locking_inset->InsetUnlock();
213 the_locking_inset = 0;
214 users->text->FinishUndo();
220 // candidate for move to BufferView
221 // Inserts a file into current document
222 bool Buffer::insertLyXFile(string const & filen)
224 // (c) CHT Software Service GmbH
227 // Insert a Lyxformat - file into current buffer
229 // Moved from lyx_cb.C (Lgb)
231 if (filen.empty()) return false;
233 string filename = MakeAbsPath(filen);
235 // check if file exist
236 FileInfo fi(filename);
238 if (!fi.readable()) {
239 WriteAlert(_("Error!"),
240 _("Specified file is unreadable: "),
241 MakeDisplayPath(filename, 50));
247 FilePtr myfile(filename, FilePtr::read);
249 WriteAlert(_("Error!"),
250 _("Cannot open specified file: "),
251 MakeDisplayPath(filename, 50));
256 int c = fgetc(myfile());
262 lyxerr.debug() << "Will insert file with header" << endl;
263 res = readFile(lex, users->text->cursor.par);
265 lyxerr.debug() << "Will insert file without header" << endl;
266 res = readLyXformat2(lex, users->text->cursor.par);
274 // candidate for move to BufferView
275 // (at least some parts in the beginning of the func)
278 // changed to be public and have one parameter
279 // if par = 0 normal behavior
280 // else insert behavior
281 // Returns false if "\the_end" is not read for formats >= 2.13. (Asger)
282 bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par)
288 char depth = 0; // signed or unsigned?
289 LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
290 LyXParagraph::footnote_kind footnotekind = LyXParagraph::FOOTNOTE;
291 bool the_end_read = false;
293 LyXParagraph * return_par = 0;
294 LyXFont font = LyXFont(LyXFont::ALL_INHERIT);
296 // If we are inserting, we cheat and get a token in advance
297 bool has_token = false;
301 par = new LyXParagraph;
303 users->text->BreakParagraph();
304 return_par = users->text->FirstParagraph();
307 // We don't want to adopt the parameters from the
308 // document we insert, so we skip until the text begins:
311 pretoken = lex.GetString();
312 if (pretoken == "\\layout") {
324 pretoken = lex.GetString();
327 // Profiling show this should give a lot: (Asger)
328 string const token = pretoken;
332 else if (token[0] != '\\') {
333 int n = token.length();
334 for (int i = 0; i < n; i++) {
335 par->InsertChar(pos, token[i]);
336 par->SetFont(pos, font);
339 } else if (token == "\\i") {
340 inset = new InsetLatexAccent;
342 par->InsertChar(pos, LyXParagraph::META_INSET);
344 par->InsertInset(pos, inset);
345 par->SetFont(pos, font);
347 } else if (token == "\\layout") {
351 par->text.resize(par->text.size());
352 par = new LyXParagraph(par);
356 string layoutname = lex.GetString();
357 pair<bool, LyXTextClass::LayoutList::size_type> pp
358 = textclasslist.NumberOfLayout(params.textclass,
361 par->layout = pp.second;
362 } else { // layout not found
363 // use default layout "Standard" (0)
366 // Test whether the layout is obsolete.
367 LyXLayout const & layout = textclasslist.Style(params.textclass,
369 if (!layout.obsoleted_by().empty())
371 textclasslist.NumberOfLayout(params.textclass,
372 layout.obsoleted_by()).second;
373 par->footnoteflag = footnoteflag;
374 par->footnotekind = footnotekind;
376 font = LyXFont(LyXFont::ALL_INHERIT);
377 } else if (token == "\\end_float") {
381 par->text.resize(par->text.size());
382 par = new LyXParagraph(par);
384 footnotekind = LyXParagraph::FOOTNOTE;
385 footnoteflag = LyXParagraph::NO_FOOTNOTE;
388 par->layout = LYX_DUMMY_LAYOUT;
389 font = LyXFont(LyXFont::ALL_INHERIT);
390 } else if (token == "\\begin_float") {
391 tmpret = lex.FindToken(string_footnotekinds);
392 if (tmpret == -1) tmpret++;
393 if (tmpret != LYX_LAYOUT_DEFAULT)
394 footnotekind = static_cast<LyXParagraph::footnote_kind>(tmpret); // bad
395 if (footnotekind == LyXParagraph::FOOTNOTE
396 || footnotekind == LyXParagraph::MARGIN)
397 footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
399 footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
400 } else if (token == "\\begin_deeper") {
402 } else if (token == "\\end_deeper") {
404 lex.printError("\\end_deeper: "
405 "depth is already null");
409 } else if (token == "\\begin_preamble") {
410 params.readPreamble(lex);
411 } else if (token == "\\textclass") {
413 pair<bool, LyXTextClassList::ClassList::size_type> pp =
414 textclasslist.NumberOfClass(lex.GetString());
416 params.textclass = pp.second;
418 lex.printError("Unknown textclass `$$Token'");
419 params.textclass = 0;
421 if (!textclasslist.Load(params.textclass)) {
422 // if the textclass wasn't loaded properly
423 // we need to either substitute another
424 // or stop loading the file.
425 // I can substitute but I don't see how I can
426 // stop loading... ideas?? ARRae980418
427 WriteAlert(_("Textclass Loading Error!"),
428 string(_("Can't load textclass ")) +
429 textclasslist.NameOfClass(params.textclass),
430 _("-- substituting default"));
431 params.textclass = 0;
433 } else if (token == "\\options") {
435 params.options = lex.GetString();
436 } else if (token == "\\language") {
437 params.readLanguage(lex);
438 } else if (token == "\\fontencoding") {
440 } else if (token == "\\inputencoding") {
442 params.inputenc = lex.GetString();
443 } else if (token == "\\graphics") {
444 params.readGraphicsDriver(lex);
445 } else if (token == "\\fontscheme") {
447 params.fonts = lex.GetString();
448 } else if (token == "\\noindent") {
449 par->noindent = true;
450 } else if (token == "\\fill_top") {
451 par->added_space_top = VSpace(VSpace::VFILL);
452 } else if (token == "\\fill_bottom") {
453 par->added_space_bottom = VSpace(VSpace::VFILL);
454 } else if (token == "\\line_top") {
455 par->line_top = true;
456 } else if (token == "\\line_bottom") {
457 par->line_bottom = true;
458 } else if (token == "\\pagebreak_top") {
459 par->pagebreak_top = true;
460 } else if (token == "\\pagebreak_bottom") {
461 par->pagebreak_bottom = true;
462 } else if (token == "\\start_of_appendix") {
463 par->start_of_appendix = true;
464 } else if (token == "\\paragraph_separation") {
465 tmpret = lex.FindToken(string_paragraph_separation);
466 if (tmpret == -1) tmpret++;
467 if (tmpret != LYX_LAYOUT_DEFAULT)
468 params.paragraph_separation =
469 static_cast<BufferParams::PARSEP>(tmpret);
470 } else if (token == "\\defskip") {
472 params.defskip = VSpace(lex.GetString());
473 } else if (token == "\\no_isolatin1") {
475 } else if (token == "\\no_babel") {
477 } else if (token == "\\no_epsfig") {
479 } else if (token == "\\epsfig") { // obsolete
480 // Indeed it is obsolete, but we HAVE to be backwards
481 // compatible until 0.14, because otherwise all figures
482 // in existing documents are irretrivably lost. (Asger)
483 params.readGraphicsDriver(lex);
484 } else if (token == "\\quotes_language") {
485 tmpret = lex.FindToken(string_quotes_language);
486 if (tmpret == -1) tmpret++;
487 if (tmpret != LYX_LAYOUT_DEFAULT) {
488 InsetQuotes::quote_language tmpl =
489 InsetQuotes::EnglishQ;
492 tmpl = InsetQuotes::EnglishQ;
495 tmpl = InsetQuotes::SwedishQ;
498 tmpl = InsetQuotes::GermanQ;
501 tmpl = InsetQuotes::PolishQ;
504 tmpl = InsetQuotes::FrenchQ;
507 tmpl = InsetQuotes::DanishQ;
510 params.quotes_language = tmpl;
512 } else if (token == "\\quotes_times") {
514 switch(lex.GetInteger()) {
516 params.quotes_times = InsetQuotes::SingleQ;
519 params.quotes_times = InsetQuotes::DoubleQ;
522 } else if (token == "\\papersize") {
526 tmpret = lex.FindToken(string_papersize);
529 tmpret = lex.FindToken(string_oldpapersize);
534 params.papersize2 = tmpret;
535 } else if (token == "\\paperpackage") {
536 tmpret = lex.FindToken(string_paperpackages);
539 params.paperpackage = BufferParams::PACKAGE_NONE;
541 params.paperpackage = tmpret;
542 } else if (token == "\\use_geometry") {
544 params.use_geometry = lex.GetInteger();
545 } else if (token == "\\use_amsmath") {
547 params.use_amsmath = lex.GetInteger();
548 } else if (token == "\\paperorientation") {
549 tmpret = lex.FindToken(string_orientation);
550 if (tmpret == -1) tmpret++;
551 if (tmpret != LYX_LAYOUT_DEFAULT)
552 params.orientation = static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
553 } else if (token == "\\paperwidth") {
555 params.paperwidth = lex.GetString();
556 } else if (token == "\\paperheight") {
558 params.paperheight = lex.GetString();
559 } else if (token == "\\leftmargin") {
561 params.leftmargin = lex.GetString();
562 } else if (token == "\\topmargin") {
564 params.topmargin = lex.GetString();
565 } else if (token == "\\rightmargin") {
567 params.rightmargin = lex.GetString();
568 } else if (token == "\\bottommargin") {
570 params.bottommargin = lex.GetString();
571 } else if (token == "\\headheight") {
573 params.headheight = lex.GetString();
574 } else if (token == "\\headsep") {
576 params.headsep = lex.GetString();
577 } else if (token == "\\footskip") {
579 params.footskip = lex.GetString();
580 } else if (token == "\\paperfontsize") {
582 params.fontsize = strip(lex.GetString());
583 } else if (token == "\\papercolumns") {
585 params.columns = lex.GetInteger();
586 } else if (token == "\\papersides") {
588 switch(lex.GetInteger()) {
590 case 1: params.sides = LyXTextClass::OneSide; break;
591 case 2: params.sides = LyXTextClass::TwoSides; break;
593 } else if (token == "\\paperpagestyle") {
595 params.pagestyle = strip(lex.GetString());
596 } else if (token == "\\bullet") {
598 int index = lex.GetInteger();
600 int temp_int = lex.GetInteger();
601 params.user_defined_bullets[index].setFont(temp_int);
602 params.temp_bullets[index].setFont(temp_int);
604 temp_int = lex.GetInteger();
605 params.user_defined_bullets[index].setCharacter(temp_int);
606 params.temp_bullets[index].setCharacter(temp_int);
608 temp_int = lex.GetInteger();
609 params.user_defined_bullets[index].setSize(temp_int);
610 params.temp_bullets[index].setSize(temp_int);
612 string temp_str = lex.GetString();
613 if (temp_str != "\\end_bullet") {
614 // this element isn't really necessary for
615 // parsing but is easier for humans
616 // to understand bullets. Put it back and
617 // set a debug message?
618 lex.printError("\\end_bullet expected, got" + temp_str);
619 //how can I put it back?
621 } else if (token == "\\bulletLaTeX") {
623 int index = lex.GetInteger();
625 string temp_str = lex.GetString(), sum_str;
626 while (temp_str != "\\end_bullet") {
627 // this loop structure is needed when user
628 // enters an empty string since the first
629 // thing returned will be the \\end_bullet
631 // if the LaTeX entry has spaces. Each element
632 // therefore needs to be read in turn
635 temp_str = lex.GetString();
637 params.user_defined_bullets[index].setText(sum_str);
638 params.temp_bullets[index].setText(sum_str);
639 } else if (token == "\\secnumdepth") {
641 params.secnumdepth = lex.GetInteger();
642 } else if (token == "\\tocdepth") {
644 params.tocdepth = lex.GetInteger();
645 } else if (token == "\\baselinestretch") { // now obsolete
646 lex.nextToken(); // should not be used directly
648 // Will probably keep a kind of support just for
650 params.spacing.set(Spacing::Other, lex.GetFloat());
651 } else if (token == "\\spacing") {
653 string tmp = strip(lex.GetString());
654 if (tmp == "single") {
655 params.spacing.set(Spacing::Single);
656 } else if (tmp == "onehalf") {
657 params.spacing.set(Spacing::Onehalf);
658 } else if (tmp == "double") {
659 params.spacing.set(Spacing::Double);
660 } else if (tmp == "other") {
662 params.spacing.set(Spacing::Other,
665 lex.printError("Unknown spacing token: '$$Token'");
667 } else if (token == "\\float_placement") {
669 params.float_placement = lex.GetString();
670 } else if (token == "\\cursor") {
671 // this is obsolete, so we just skip it.
673 } else if (token == "\\family") {
675 font.setLyXFamily(lex.GetString());
676 } else if (token == "\\series") {
678 font.setLyXSeries(lex.GetString());
679 } else if (token == "\\shape") {
681 font.setLyXShape(lex.GetString());
682 } else if (token == "\\size") {
684 font.setLyXSize(lex.GetString());
685 } else if (token == "\\latex") {
687 string tok = lex.GetString();
688 // This is dirty, but gone with LyX3. (Asger)
689 if (tok == "no_latex")
690 font.setLatex(LyXFont::OFF);
691 else if (tok == "latex")
692 font.setLatex(LyXFont::ON);
693 else if (tok == "default")
694 font.setLatex(LyXFont::INHERIT);
696 lex.printError("Unknown LaTeX font flag "
698 } else if (token == "\\emph") {
700 font.setEmph(font.setLyXMisc(lex.GetString()));
701 } else if (token == "\\bar") {
703 string tok = lex.GetString();
704 // This is dirty, but gone with LyX3. (Asger)
706 font.setUnderbar(LyXFont::ON);
707 else if (tok == "no")
708 font.setUnderbar(LyXFont::OFF);
709 else if (tok == "default")
710 font.setUnderbar(LyXFont::INHERIT);
712 lex.printError("Unknown bar font flag "
714 } else if (token == "\\noun") {
716 font.setNoun(font.setLyXMisc(lex.GetString()));
717 } else if (token == "\\color") {
719 font.setLyXColor(lex.GetString());
720 } else if (token == "\\align") {
721 tmpret = lex.FindToken(string_align);
722 if (tmpret == -1) tmpret++;
723 if (tmpret != LYX_LAYOUT_DEFAULT) {
725 for (; tmpret>0; tmpret--)
726 tmpret2 = tmpret2 * 2;
727 par->align = LyXAlignment(tmpret2);
729 } else if (token == "\\added_space_top"){
731 par->added_space_top = lex.GetString();
732 } else if (token == "\\added_space_bottom") {
734 par->added_space_bottom = lex.GetString();
735 } else if (token == "\\pextra_type") {
737 par->pextra_type = lex.GetInteger();
738 } else if (token == "\\pextra_width") {
740 par->pextra_width = lex.GetString();
741 } else if (token == "\\pextra_widthp") {
743 par->pextra_widthp = lex.GetString();
744 } else if (token == "\\pextra_alignment") {
746 par->pextra_alignment = lex.GetInteger();
747 } else if (token == "\\pextra_hfill") {
749 par->pextra_hfill = lex.GetInteger();
750 } else if (token == "\\pextra_start_minipage") {
752 par->pextra_start_minipage = lex.GetInteger();
753 } else if (token == "\\labelwidthstring") {
755 par->labelwidthstring = lex.GetString();
756 /* do not delete this token, it is still needed! */
757 } else if (token == "\\end_inset") {
758 /* simple ignore this. The insets do not have
760 // but insets should read it, it is a part of
761 //the inset isn't it? Lgb.
762 } else if (token == "\\begin_inset") {
764 tmptok = lex.GetString();
765 /* test the different insets */
766 if (tmptok == "Quotes") {
767 inset = new InsetQuotes;
769 par->InsertChar(pos, LyXParagraph::META_INSET);
770 par->InsertInset(pos, inset);
771 par->SetFont(pos, font);
773 #if 0 // should not be used any more
774 } else if (tmptok == "Latex") {
775 // This one is on its way out
777 tmptok = strip(lex.GetString());
778 //lyxerr <<string(tmptok[0]));
779 if (tmptok[0] == '\\') {
780 // then this latex is a
782 InsetCommand *tmpinset =
784 tmpinset->scanCommand(tmptok);
787 // This should not use InsetLaTexDel
788 // it should rather insert text into
789 // the paragraph and mark it as tex.
790 inset = new InsetLatex(tmptok);
792 par->InsertChar(pos, LyXParagraph::META_INSET);
793 par->InsertInset(pos, inset);
794 par->SetFont(pos, font);
797 #if 0 // should not be used any more
798 } else if (tmptok == "LatexDel") {
799 // This one is on its way out...
801 tmptok = strip(lex.GetString());
802 //lyxerr <<string(tmptok[0]));
803 if (tmptok == "\\tableofcontents") {
804 inset = new InsetTOC(this);
805 } else if (tmptok == "\\listoffigures") {
806 inset = new InsetLOF(this);
807 } else if (tmptok == "\\listoftables") {
808 inset = new InsetLOT(this);
809 } else if (tmptok == "\\listofalgorithms") {
810 inset = new InsetLOA(this);
811 } else if (contains(tmptok, "\\ref{")
812 || contains(tmptok, "\\pageref{")) {
813 inset = new InsetRef(tmptok, this);
814 } else if (contains(tmptok, "\\url{")
815 || contains(tmptok, "\\htmlurl{")) {
816 string cont, opt, tmptmptok, cmdname;
818 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
823 tmptmptok = lex.GetString();
824 if(tmptmptok[0] == '\\') {
825 if( tmptmptok == "\\backslash")
835 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
840 tmptmptok = lex.GetString();
841 if(tmptmptok[0] == '\\') {
842 if( tmptmptok == "\\backslash")
852 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
855 if(contains(tmptok, "\\url{"))
856 cmdname = string("url");
858 cmdname = string("htmlurl");
861 inset = new InsetUrl(cmdname, cont, opt);
862 } else if (tmptok[0] == '\\') {
863 // then this latex del is a
865 InsetCommand * tmpinset =
867 tmpinset->scanCommand(tmptok);
870 par->InsertChar(pos, LyXParagraph::META_INSET);
871 par->InsertInset(pos, inset);
872 par->SetFont(pos, font);
875 } else if (tmptok == "\\i") {
876 inset = new InsetLatexAccent;
878 par->InsertChar(pos, LyXParagraph::META_INSET);
879 par->InsertInset(pos, inset);
880 par->SetFont(pos, font);
882 } else if (tmptok == "FormulaMacro") {
883 inset = new InsetFormulaMacro;
885 par->InsertChar(pos, LyXParagraph::META_INSET);
886 par->InsertInset(pos, inset);
887 par->SetFont(pos, font);
889 } else if (tmptok == "Formula") {
890 inset = new InsetFormula;
892 par->InsertChar(pos, LyXParagraph::META_INSET);
893 par->InsertInset(pos, inset);
894 par->SetFont(pos, font);
896 } else if (tmptok == "Figure") {
897 inset = new InsetFig(100, 100, this);
899 par->InsertChar(pos, LyXParagraph::META_INSET);
900 par->InsertInset(pos, inset);
901 par->SetFont(pos, font);
903 } else if (tmptok == "Label") {
904 // Kept for compability. Remove in 0.13.
906 string tmp = "\\label{";
907 tmp += lex.GetString();
909 inset = new InsetLabel(tmp);
910 par->InsertChar(pos, LyXParagraph::META_INSET);
911 par->InsertInset(pos, inset);
912 par->SetFont(pos, font);
915 } else if (tmptok == "Info") {
916 inset = new InsetInfo;
918 par->InsertChar(pos, LyXParagraph::META_INSET);
919 par->InsertInset(pos, inset);
920 par->SetFont(pos, font);
922 } else if (tmptok == "Include") {
923 inset = new InsetInclude(string(), this);
925 par->InsertChar(pos, LyXParagraph::META_INSET);
926 par->InsertInset(pos, inset);
927 par->SetFont(pos, font);
929 } else if (tmptok == "LatexCommand") {
932 if (inscmd.getCmdName() == "cite") {
933 inset = new InsetCitation(inscmd.getContents(), inscmd.getOptions());
934 } else if (inscmd.getCmdName() == "bibitem") {
935 lex.printError("Wrong place for bibitem");
936 inset = inscmd.Clone();
937 } else if (inscmd.getCmdName() == "BibTeX") {
938 inset = new InsetBibtex(inscmd.getContents(), inscmd.getOptions(), this);
939 } else if (inscmd.getCmdName() == "index") {
940 inset = new InsetIndex(inscmd.getContents());
941 } else if (inscmd.getCmdName() == "include") {
942 inset = new InsetInclude(inscmd.getContents(), this);
943 } else if (inscmd.getCmdName() == "label") {
944 inset = new InsetLabel(inscmd.getCommand());
945 } else if (inscmd.getCmdName() == "url"
946 || inscmd.getCmdName() == "htmlurl") {
947 inset = new InsetUrl(inscmd.getCommand());
948 } else if (inscmd.getCmdName() == "ref"
949 || inscmd.getCmdName() == "pageref") {
950 if (!inscmd.getOptions().empty() || !inscmd.getContents().empty()) {
951 inset = new InsetRef(inscmd, this);
953 /* This condition comes from a temporary solution
954 to the latexdel ref inset that was transformed to an empty ref
955 inset plus the body surronded by latexdel insets */
957 string cont, opt, tmptmptok, cmdname;
959 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
964 tmptmptok = lex.GetString();
965 if(tmptmptok[0] == '\\') {
966 if( tmptmptok == "\\backslash")
976 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
981 tmptmptok = lex.GetString();
982 if(tmptmptok[0] == '\\') {
983 if( tmptmptok == "\\backslash")
993 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
999 cmdname = "\\" + inscmd.getCmdName();
1000 cmdname += "[" + cont + "]";
1001 cmdname += "{" + opt + "}";
1002 inset = new InsetRef(cmdname, this);
1004 } else if (inscmd.getCmdName() == "tableofcontents") {
1005 inset = new InsetTOC(this);
1006 } else if (inscmd.getCmdName() == "listoffigures") {
1007 inset = new InsetLOF(this);
1008 } else if (inscmd.getCmdName() == "listofalgorithms") {
1009 inset = new InsetLOA(this);
1010 } else if (inscmd.getCmdName() == "listoftables") {
1011 inset = new InsetLOT(this);
1012 } else if (inscmd.getCmdName() == "printindex") {
1013 inset = new InsetPrintIndex(this);
1014 } else if (inscmd.getCmdName() == "lyxparent") {
1015 inset = new InsetParent(inscmd.getContents(), this);
1017 // The following three are only for compatibility
1018 if (inscmd.getCmdName() == "-") {
1019 inset = new InsetSpecialChar(InsetSpecialChar::HYPHENATION);
1020 } else if (inscmd.getCmdName() == "@.") {
1021 inset = new InsetSpecialChar(InsetSpecialChar::END_OF_SENTENCE);
1022 } else if (inscmd.getCmdName() == "ldots") {
1023 inset = new InsetSpecialChar(InsetSpecialChar::LDOTS);
1025 inset = inscmd.Clone();
1028 par->InsertChar(pos, LyXParagraph::META_INSET);
1029 par->InsertInset(pos, inset);
1030 par->SetFont(pos, font);
1034 } else if (token == "\\InsetQuotes") {
1035 inset = new InsetQuotes;
1037 par->InsertChar(pos, LyXParagraph::META_INSET);
1038 par->InsertInset(pos, inset);
1039 par->SetFont(pos, font);
1042 } else if (token == "\\InsetLatex") {
1043 inset = new InsetLatex;
1045 par->InsertChar(pos, LyXParagraph::META_INSET);
1046 par->InsertInset(pos, inset);
1047 par->SetFont(pos, font);
1049 } else if (token == "\\InsetLatexDel") {
1050 lex.printError(_("Warning: Ignoring Old Inset"));
1052 } else if (token == "\\InsetFormula") {
1053 inset = new InsetFormula;
1055 par->InsertChar(pos, LyXParagraph::META_INSET);
1056 par->InsertInset(pos, inset);
1057 par->SetFont(pos, font);
1059 } else if (token == "\\SpecialChar") {
1060 inset = new InsetSpecialChar;
1062 par->InsertChar(pos, LyXParagraph::META_INSET);
1063 par->InsertInset(pos, inset);
1064 par->SetFont(pos, font);
1066 } else if (token == "\\Figure") {
1067 inset = new InsetFig(100, 100, this);
1069 par->InsertChar(pos, LyXParagraph::META_INSET);
1070 par->InsertInset(pos, inset);
1071 par->SetFont(pos, font);
1073 } else if (token == "\\newline") {
1074 par->InsertChar(pos, LyXParagraph::META_NEWLINE);
1075 par->SetFont(pos, font);
1077 } else if (token == "\\LyXTable") {
1078 par->table = new LyXTable(lex);
1079 } else if (token == "\\hfill") {
1080 par->InsertChar(pos, LyXParagraph::META_HFILL);
1081 par->SetFont(pos, font);
1083 } else if (token == "\\protected_separator") {
1084 par->InsertChar(pos, LyXParagraph::META_PROTECTED_SEPARATOR);
1085 par->SetFont(pos, font);
1087 } else if (token == "\\bibitem") { // ale970302
1089 par->bibkey = new InsetBibKey;
1090 par->bibkey->Read(lex);
1091 }else if (token == "\\backslash") {
1092 par->InsertChar(pos, '\\');
1093 par->SetFont(pos, font);
1095 }else if (token == "\\the_end") {
1096 the_end_read = true;
1098 // This should be insurance for the future: (Asger)
1099 lex.printError("Unknown token `$$Token'. "
1100 "Inserting as text.");
1101 int n = token.length();
1102 for (int i = 0; i < n; i++) {
1103 par->InsertChar(pos, token[i]);
1104 par->SetFont(pos, font);
1113 paragraph = return_par;
1115 return the_end_read;
1119 bool Buffer::readFile(LyXLex & lex, LyXParagraph * par)
1125 token = lex.GetString();
1126 if (token == "\\lyxformat") { // the first token _must_ be...
1128 format = lex.GetFloat();
1130 if (LYX_FORMAT - format > 0.05) {
1131 printf(_("Warning: need lyxformat %.2f but found %.2f\n"),
1132 LYX_FORMAT, format);
1134 if (format - LYX_FORMAT > 0.05) {
1135 printf(_("ERROR: need lyxformat %.2f but found %.2f\n"),
1136 LYX_FORMAT, format);
1138 bool the_end = readLyXformat2(lex, par);
1139 // Formats >= 2.13 support "\the_end" marker
1143 // Formats >= 2.14 changed papersize stuff
1144 if (format < 2.14) {
1153 WriteAlert(_("Warning!"),
1154 _("Reading of document is not complete"),
1155 _("Maybe the document is truncated"));
1156 // We simulate a safe reading anyways to allow
1157 // users to take the chance... (Asger)
1161 WriteAlert(_("ERROR!"),
1162 _("Old LyX file format found. "
1163 "Use LyX 0.10.x to read this!"));
1167 } else { // "\\lyxformat" not found
1168 WriteAlert(_("ERROR!"), _("Not a LyX file!"));
1171 WriteAlert(_("ERROR!"), _("Unable to read file!"));
1176 // Returns false if unsuccesful
1177 bool Buffer::writeFile(string const & filename, bool flag)
1179 // if flag is false writeFile will not create any GUI
1180 // warnings, only cerr.
1181 // Needed for autosave in background or panic save (Matthias 120496)
1183 if (read_only && (filename == this->filename)) {
1184 // Here we should come with a question if we should
1185 // perform the write anyway.
1187 lyxerr << _("Error! Document is read-only: ")
1188 << filename << endl;
1190 WriteAlert(_("Error! Document is read-only: "),
1195 FileInfo finfo(filename);
1196 if (finfo.exist() && !finfo.writable()) {
1197 // Here we should come with a question if we should
1198 // try to do the save anyway. (i.e. do a chmod first)
1200 lyxerr << _("Error! Cannot write file: ")
1201 << filename << endl;
1203 WriteFSAlert(_("Error! Cannot write file: "),
1208 ofstream ofs(filename.c_str());
1211 lyxerr << _("Error! Cannot open file: ")
1212 << filename << endl;
1214 WriteFSAlert(_("Error! Cannot open file: "),
1218 // The top of the file should not be written by params.
1220 // write out a comment in the top of the file
1221 ofs << '#' << LYX_DOCVERSION
1222 << " created this file. For more info see http://www.lyx.org/\n";
1223 ofs.setf(ios::showpoint|ios::fixed);
1225 ofs << "\\lyxformat " << setw(4) << LYX_FORMAT << "\n";
1227 // now write out the buffer paramters.
1228 params.writeFile(ofs);
1230 char footnoteflag = 0;
1233 // this will write out all the paragraphs
1234 // using recursive descent.
1235 paragraph->writeFile(ofs, params, footnoteflag, depth);
1237 // Write marker that shows file is complete
1238 ofs << "\n\\the_end" << endl;
1240 // how to check if close went ok?
1245 void Buffer::writeFileAscii(string const & filename, int linelen)
1247 LyXFont font1, font2;
1249 char c, footnoteflag = 0, depth = 0;
1251 LyXParagraph::size_type i;
1252 int j, h, ltype = 0, ltype_depth = 0,
1253 * clen = 0, actcell = 0, actpos = 0, cell = 0, cells = 0,
1256 bool ref_printed = false;
1258 ofstream ofs(filename.c_str());
1260 WriteFSAlert(_("Error: Cannot write file:"), filename);
1264 string fname1 = TmpFileName();
1265 LyXParagraph * par = paragraph;
1269 if (par->footnoteflag != LyXParagraph::NO_FOOTNOTE ||
1271 par->previous->footnoteflag == LyXParagraph::NO_FOOTNOTE){
1273 /* begins a footnote environment ? */
1274 if (footnoteflag != par->footnoteflag) {
1275 footnoteflag = par->footnoteflag;
1277 j = strlen(string_footnotekinds[par->footnotekind])+4;
1278 if (currlinelen + j > linelen)
1281 << string_footnotekinds[par->footnotekind] << "] ";
1286 /* begins or ends a deeper area ?*/
1287 if (depth != par->depth) {
1288 if (par->depth > depth) {
1289 while (par->depth > depth) {
1294 while (par->depth < depth) {
1300 /* First write the layout */
1301 tmp = textclasslist.NameOfLayout(params.textclass, par->layout);
1302 if (tmp == "Itemize") {
1304 ltype_depth = depth+1;
1305 } else if (tmp == "Enumerate") {
1307 ltype_depth = depth+1;
1308 } else if (strstr(tmp.c_str(), "ection")) {
1310 ltype_depth = depth+1;
1311 } else if (strstr(tmp.c_str(), "aragraph")) {
1313 ltype_depth = depth+1;
1314 } else if (tmp == "Description") {
1316 ltype_depth = depth+1;
1317 } else if (tmp == "Abstract") {
1320 } else if (tmp == "Bibliography") {
1328 /* maybe some vertical spaces */
1330 /* the labelwidthstring used in lists */
1334 /* some pagebreaks? */
1338 /* what about the alignment */
1341 /* dummy layout, that means a footnote ended */
1342 footnoteflag = LyXParagraph::NO_FOOTNOTE;
1347 /* It might be a table */
1349 if (!lyxrc->ascii_roff_command.empty() &&
1350 lyxrc->ascii_roff_command != "none") {
1351 RoffAsciiTable(ofs, par);
1357 cells = par->table->columns;
1358 clen = new int [cells];
1359 memset(clen, 0, sizeof(int) * cells);
1360 for (i = 0, j = 0, h = 1; i < par->size(); ++i, ++h) {
1361 c = par->GetChar(i);
1362 if (c == LyXParagraph::META_INSET) {
1363 if ((inset = par->GetInset(i))) {
1364 ofstream fs(fname1.c_str());
1366 WriteFSAlert(_("Error: Cannot open temporary file:"), fname1);
1369 inset->Latex(fs, -1);
1370 h += fs.tellp() - 1;
1371 remove(fname1.c_str());
1373 } else if (c == LyXParagraph::META_NEWLINE) {
1377 j = (++j) % par->table->NumberOfCellsInRow(actcell);
1385 font1 = LyXFont(LyXFont::ALL_INHERIT);
1387 for (i = 0, actpos = 1; i < par->size(); ++i, ++actpos) {
1388 if (!i && !footnoteflag && !noparbreak){
1390 for(j = 0; j < depth; ++j)
1392 currlinelen = depth * 2;
1394 case 0: /* Standart */
1395 case 4: /* (Sub)Paragraph */
1396 case 5: /* Description */
1398 case 6: /* Abstract */
1399 ofs << "Abstract\n\n";
1401 case 7: /* Bibliography */
1403 ofs << "References\n\n";
1408 ofs << par->labelstring << " ";
1411 if (ltype_depth > depth) {
1412 for(j = ltype_depth - 1; j > depth; --j)
1414 currlinelen += (ltype_depth-depth)*2;
1417 for(j = 0; j < cells; ++j) {
1419 for(h = 0; h < (clen[j] + 1);
1424 for(j = 0; j < depth; ++j)
1426 currlinelen = depth * 2;
1427 if (ltype_depth > depth) {
1428 for(j = ltype_depth;
1431 currlinelen += (ltype_depth-depth)*2;
1436 font2 = par->GetFontSettings(i);
1437 if (font1.latex() != font2.latex()) {
1438 if (font2.latex() == LyXFont::OFF)
1446 c = par->GetChar(i);
1450 case LyXParagraph::META_INSET:
1451 if ((inset = par->GetInset(i))) {
1453 inset->Latex(ofs, -1);
1454 currlinelen += (ofs.tellp() - fpos);
1455 actpos += (ofs.tellp() - fpos) - 1;
1458 case LyXParagraph::META_NEWLINE:
1460 if (par->table->NumberOfCellsInRow(actcell) <= cell) {
1461 for(j = actpos; j < clen[cell-1];j++)
1464 for(j = 0; j < depth; ++j)
1466 currlinelen = depth*2;
1467 if (ltype_depth > depth) {
1468 for(j = ltype_depth; j > depth; --j)
1470 currlinelen += (ltype_depth-depth) * 2;
1472 for(j = 0; j < cells; ++j) {
1474 for(h = 0; h < (clen[j] + 1); ++h)
1478 for(j = 0; j < depth; ++j)
1480 currlinelen = depth * 2;
1481 if (ltype_depth > depth) {
1482 for(j = ltype_depth;
1485 currlinelen += (ltype_depth-depth)*2;
1491 j < clen[cell - 1]; ++j)
1497 currlinelen = actpos = 0;
1500 for(j = 0; j < depth; ++j)
1502 currlinelen = depth * 2;
1503 if (ltype_depth > depth) {
1504 for(j = ltype_depth;
1507 currlinelen += (ltype_depth - depth) * 2;
1511 case LyXParagraph::META_HFILL:
1514 case LyXParagraph::META_PROTECTED_SEPARATOR:
1521 if (currlinelen > linelen - 10
1522 && c == ' ' && i + 2 < par->size()) {
1524 for(j = 0; j < depth; ++j)
1526 currlinelen = depth * 2;
1527 if (ltype_depth > depth) {
1528 for(j = ltype_depth;
1531 currlinelen += (ltype_depth-depth)*2;
1533 } else if (c != '\0')
1536 lyxerr.debug() << "writeAsciiFile: NULL char in structure." << endl;
1542 for(j = actpos; j < clen[cell - 1]; ++j)
1545 for(j = 0; j < depth; ++j)
1547 currlinelen = depth * 2;
1548 if (ltype_depth > depth) {
1549 for(j = ltype_depth; j > depth; --j)
1551 currlinelen += (ltype_depth - depth) * 2;
1553 for(j = 0; j < cells; ++j) {
1555 for(h = 0; h < (clen[j] + 1); ++h)
1568 void Buffer::makeLaTeXFile(string const & filename,
1569 string const & original_path,
1570 bool nice, bool only_body)
1572 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
1573 params.textclass = GetCurrentTextClass();
1574 niceFile = nice; // this will be used by Insetincludes.
1576 tex_code_break_column = lyxrc->ascii_linelen;
1578 LyXTextClass const & tclass =
1579 textclasslist.TextClass(params.textclass);
1581 ofstream ofs(filename.c_str());
1583 WriteFSAlert(_("Error: Cannot open file: "), filename);
1587 // validate the buffer.
1588 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
1589 LaTeXFeatures features(tclass.numLayouts());
1591 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
1594 // The starting paragraph of the coming rows is the
1595 // first paragraph of the document. (Asger)
1596 texrow.start(paragraph, 0);
1598 string userName(getUserName());
1601 if (!only_body && nice) {
1602 LFile += "%% This LaTeX-file was created by <";
1603 LFile += userName + "> " + date();
1604 LFile += "%% LyX 1.0 (C) 1995-1999 by Matthias Ettrich and the LyX Team\n";
1605 LFile += "\n%% Do not edit this file unless you know what you are doing.\n";
1611 lyxerr.debug() << "lyx header finished" << endl;
1612 // There are a few differences between nice LaTeX and usual files:
1613 // usual is \batchmode, uses \listfiles and has a
1614 // special input@path to allow the including of figures
1615 // with either \input or \includegraphics (what figinsets do).
1616 // batchmode is not set if there is a tex_code_break_column.
1617 // In this case somebody is interested in the generated LaTeX,
1618 // so this is OK. input@path is set when the actual parameter
1619 // original_path is set. This is done for usual tex-file, but not
1620 // for nice-latex-file. (Matthias 250696)
1623 // code for usual, NOT nice-latex-file
1624 LFile += "\\batchmode\n"; // changed
1625 // from \nonstopmode
1627 // We don't need listfiles anymore
1628 //LFile += "\\listfiles\n";
1631 if (!original_path.empty()) {
1632 LFile += "\\makeatletter\n";
1634 LFile += "\\def\\input@path{{" + original_path
1637 LFile += "\\makeatother\n";
1641 LFile += "\\documentclass";
1643 string options; // the document class options.
1645 if (tokenPos(tclass.opt_fontsize(), '|', params.fontsize) >= 0) {
1646 // only write if existing in list (and not default)
1647 options += params.fontsize;
1652 if (!params.use_geometry &&
1653 (params.paperpackage == BufferParams::PACKAGE_NONE)) {
1654 switch (params.papersize) {
1655 case BufferParams::PAPER_A4PAPER:
1656 options += "a4paper,";
1658 case BufferParams::PAPER_USLETTER:
1659 options += "letterpaper,";
1661 case BufferParams::PAPER_A5PAPER:
1662 options += "a5paper,";
1664 case BufferParams::PAPER_B5PAPER:
1665 options += "b5paper,";
1667 case BufferParams::PAPER_EXECUTIVEPAPER:
1668 options += "executivepaper,";
1670 case BufferParams::PAPER_LEGALPAPER:
1671 options += "legalpaper,";
1677 if (params.sides != tclass.sides()) {
1678 if (params.sides == 2)
1679 options += "twoside,";
1681 options += "oneside,";
1685 if (params.columns != tclass.columns()) {
1686 if (params.columns == 2)
1687 options += "twocolumn,";
1689 options += "onecolumn,";
1692 if (!params.use_geometry
1693 && params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1694 options += "landscape,";
1696 // language should be a parameter to \documentclass
1697 if (params.language != "default") {
1698 options += params.language + ',';
1701 // the user-defined options
1702 if (!params.options.empty()) {
1703 options += params.options + ',';
1706 if (!options.empty()){
1707 options = strip(options, ',');
1714 LFile += textclasslist.LatexnameOfClass(params.textclass);
1717 // end of \documentclass defs
1719 // font selection must be done before loading fontenc.sty
1720 if (params.fonts != "default") {
1721 LFile += "\\usepackage{" + params.fonts + "}\n";
1724 // this one is not per buffer
1725 if (lyxrc->fontenc != "default") {
1726 LFile += "\\usepackage[" + lyxrc->fontenc
1730 if (params.inputenc != "default") {
1731 LFile += "\\usepackage[" + params.inputenc
1736 /* at the very beginning the text parameters */
1737 if (params.paperpackage != BufferParams::PACKAGE_NONE) {
1738 switch (params.paperpackage) {
1739 case BufferParams::PACKAGE_A4:
1740 LFile += "\\usepackage{a4}\n";
1743 case BufferParams::PACKAGE_A4WIDE:
1744 LFile += "\\usepackage{a4wide}\n";
1747 case BufferParams::PACKAGE_WIDEMARGINSA4:
1748 LFile += "\\usepackage[widemargins]{a4}\n";
1753 if (params.use_geometry) {
1754 LFile += "\\usepackage{geometry}\n";
1756 LFile += "\\geometry{verbose";
1757 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1758 LFile += ",landscape";
1759 switch (params.papersize2) {
1760 case BufferParams::VM_PAPER_CUSTOM:
1761 if (!params.paperwidth.empty())
1762 LFile += ",paperwidth="
1763 + params.paperwidth;
1764 if (!params.paperheight.empty())
1765 LFile += ",paperheight="
1766 + params.paperheight;
1768 case BufferParams::VM_PAPER_USLETTER:
1769 LFile += ",letterpaper";
1771 case BufferParams::VM_PAPER_USLEGAL:
1772 LFile += ",legalpaper";
1774 case BufferParams::VM_PAPER_USEXECUTIVE:
1775 LFile += ",executivepaper";
1777 case BufferParams::VM_PAPER_A3:
1778 LFile += ",a3paper";
1780 case BufferParams::VM_PAPER_A4:
1781 LFile += ",a4paper";
1783 case BufferParams::VM_PAPER_A5:
1784 LFile += ",a5paper";
1786 case BufferParams::VM_PAPER_B3:
1787 LFile += ",b3paper";
1789 case BufferParams::VM_PAPER_B4:
1790 LFile += ",b4paper";
1792 case BufferParams::VM_PAPER_B5:
1793 LFile += ",b5paper";
1796 // default papersize ie BufferParams::VM_PAPER_DEFAULT
1797 switch (lyxrc->default_papersize) {
1798 case BufferParams::PAPER_DEFAULT: // keep compiler happy
1799 case BufferParams::PAPER_USLETTER:
1800 LFile += ",letterpaper";
1802 case BufferParams::PAPER_LEGALPAPER:
1803 LFile += ",legalpaper";
1805 case BufferParams::PAPER_EXECUTIVEPAPER:
1806 LFile += ",executivepaper";
1808 case BufferParams::PAPER_A3PAPER:
1809 LFile += ",a3paper";
1811 case BufferParams::PAPER_A4PAPER:
1812 LFile += ",a4paper";
1814 case BufferParams::PAPER_A5PAPER:
1815 LFile += ",a5paper";
1817 case BufferParams::PAPER_B5PAPER:
1818 LFile += ",b5paper";
1822 if (!params.topmargin.empty())
1823 LFile += ",tmargin=" + params.topmargin;
1824 if (!params.bottommargin.empty())
1825 LFile += ",bmargin=" + params.bottommargin;
1826 if (!params.leftmargin.empty())
1827 LFile += ",lmargin=" + params.leftmargin;
1828 if (!params.rightmargin.empty())
1829 LFile += ",rmargin=" + params.rightmargin;
1830 if (!params.headheight.empty())
1831 LFile += ",headheight=" + params.headheight;
1832 if (!params.headsep.empty())
1833 LFile += ",headsep=" + params.headsep;
1834 if (!params.footskip.empty())
1835 LFile += ",footskip=" + params.footskip;
1839 if (params.use_amsmath
1840 && !prefixIs(textclasslist.LatexnameOfClass(params.textclass), "ams")) {
1841 LFile += "\\usepackage{amsmath}\n";
1844 if (tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle) >= 0) {
1845 if (params.pagestyle == "fancy") {
1846 LFile += "\\usepackage{fancyhdr}\n";
1849 LFile += "\\pagestyle{" + params.pagestyle + "}\n";
1853 // We try to load babel late, in case it interferes
1854 // with other packages.
1855 if (params.language != "default") {
1856 LFile += "\\usepackage{babel}\n";
1860 if (params.secnumdepth != tclass.secnumdepth()) {
1861 LFile += "\\setcounter{secnumdepth}{";
1862 LFile += tostr(params.secnumdepth);
1866 if (params.tocdepth != tclass.tocdepth()) {
1867 LFile += "\\setcounter{tocdepth}{";
1868 LFile += tostr(params.tocdepth);
1873 if (params.paragraph_separation) {
1874 switch (params.defskip.kind()) {
1875 case VSpace::SMALLSKIP:
1876 LFile += "\\setlength\\parskip{\\smallskipamount}\n";
1878 case VSpace::MEDSKIP:
1879 LFile += "\\setlength\\parskip{\\medskipamount}\n";
1881 case VSpace::BIGSKIP:
1882 LFile += "\\setlength\\parskip{\\bigskipamount}\n";
1884 case VSpace::LENGTH:
1885 LFile += "\\setlength\\parskip{"
1886 + params.defskip.length().asLatexString()
1889 default: // should never happen // Then delete it.
1890 LFile += "\\setlength\\parskip{\\medskipamount}\n";
1895 LFile += "\\setlength\\parindent{0pt}\n";
1899 // Write out what we've generated so far...and reset LFile
1903 // Now insert the LyX specific LaTeX commands...
1904 string preamble, tmppreamble;
1906 // The optional packages;
1907 preamble = features.getPackages(params);
1909 // this might be useful...
1910 preamble += "\n\\makeatletter\n\n";
1912 // Some macros LyX will need
1913 tmppreamble = features.getMacros(params);
1915 if (!tmppreamble.empty()) {
1916 preamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1917 "LyX specific LaTeX commands.\n"
1918 + tmppreamble + '\n';
1921 // the text class specific preamble
1922 tmppreamble = features.getTClassPreamble(params);
1923 if (!tmppreamble.empty()) {
1924 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1925 "Textclass specific LaTeX commands.\n"
1926 + tmppreamble + '\n';
1929 /* the user-defined preamble */
1930 if (!params.preamble.empty()) {
1931 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1932 "User specified LaTeX commands.\n"
1933 + params.preamble + '\n';
1936 preamble += "\\makeatother\n\n";
1938 // Itemize bullet settings need to be last in case the user
1939 // defines their own bullets that use a package included
1940 // in the user-defined preamble -- ARRae
1941 // Actually it has to be done much later than that
1942 // since some packages like frenchb make modifications
1943 // at \begin{document} time -- JMarc
1945 for (int i = 0; i < 4; ++i) {
1946 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
1947 if (bullets_def.empty())
1948 bullets_def="\\AtBeginDocument{\n";
1949 bullets_def += " \\renewcommand{\\labelitemi";
1951 // `i' is one less than the item to modify
1958 bullets_def += "ii";
1964 bullets_def += "}{" +
1965 params.user_defined_bullets[i].getText()
1970 if (!bullets_def.empty())
1971 preamble += bullets_def + "}\n\n";
1973 for (int j = countChar(preamble, '\n'); j-- ;) {
1980 LFile += "\\begin{document}\n\n";
1984 lyxerr.debug() << "preamble finished, now the body." << endl;
1986 bool was_title = false;
1987 bool already_title = false;
1993 LyXParagraph * par = paragraph;
1999 lyxerr[Debug::LATEX] << "Error in MakeLateXFile."
2001 LyXLayout const & layout = textclasslist.Style(params.textclass,
2004 if (layout.intitle) {
2005 if (already_title) {
2006 lyxerr <<"Error in MakeLatexFile: You"
2007 " should not mix title layouts"
2008 " with normal ones." << endl;
2011 } else if (was_title && !already_title) {
2012 LFile += "\\maketitle\n";
2014 already_title = true;
2017 // We are at depth 0 so we can just use
2018 // ordinary \footnote{} generation
2019 // flag this with ftcount
2021 if (layout.isEnvironment()
2022 || par->pextra_type != LyXParagraph::PEXTRA_NONE) {
2023 par = par->TeXEnvironment(LFile, texrow,
2024 ftnote, ft_texrow, ftcount);
2026 par = par->TeXOnePar(LFile, texrow,
2027 ftnote, ft_texrow, ftcount);
2030 // Write out what we've generated...and reset LFile
2033 LFile += "\\addtocounter{footnote}{-";
2034 LFile += tostr(ftcount - 1);
2038 texrow += ft_texrow;
2043 if (loop_count == 2) {
2044 // fwrite()ing every second time through the loop
2045 // gains a few extra % of speed; going higher than
2046 // 2 will slow things down again. I'll look at
2047 // LFile.length() in a future revision. ARRae
2054 // It might be that we only have a title in this document
2055 if (was_title && !already_title) {
2056 LFile += "\\maketitle\n";
2061 LFile += "\\end{document}\n";
2064 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
2066 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
2070 // Just to be sure. (Asger)
2073 // Write out what we've generated...and reset LFile
2077 // tex_code_break_column's value is used to decide
2078 // if we are in batchmode or not (within mathed_write()
2079 // in math_write.C) so we must set it to a non-zero
2080 // value when we leave otherwise we save incorrect .lyx files.
2081 tex_code_break_column = lyxrc->ascii_linelen;
2083 // How to check if the close went ok when using fstreams
2085 lyxerr.debug() << "Finished making latex file." << endl;
2089 bool Buffer::isLatex() const
2091 return textclasslist.TextClass(params.textclass).outputType() == LATEX;
2095 bool Buffer::isLinuxDoc() const
2097 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC;
2101 bool Buffer::isLiterate() const
2103 return textclasslist.TextClass(params.textclass).outputType() == LITERATE;
2107 bool Buffer::isDocBook() const
2109 return textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2113 bool Buffer::isSGML() const
2115 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC ||
2116 textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2120 void Buffer::sgmlOpenTag(ostream & os, int depth,
2121 string const & latexname) const
2123 static char * space[] = {" "," ", " ", " ", " ", " ",
2128 os << space[depth] << "<" << latexname << ">\n";
2132 void Buffer::sgmlCloseTag(ostream & os, int depth,
2133 string const & latexname) const
2135 static char * space[] = {" ", " ", " ", " ", " ",
2139 os << space[depth] << "</" << latexname << ">\n";
2143 void Buffer::makeLinuxDocFile(string const & filename, int column)
2145 LyXParagraph * par = paragraph;
2147 string top_element = textclasslist.LatexnameOfClass(params.textclass);
2148 string environment_stack[10];
2151 int depth = 0; /* paragraph depth */
2153 ofstream ofs(filename.c_str());
2156 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), filename);
2160 tex_code_break_column = column;
2163 if (params.preamble.empty()) {
2164 ofs << "<!doctype linuxdoc system>\n\n";
2167 ofs << "<!doctype linuxdoc system \n [ "
2168 << params.preamble << " \n]>\n\n";
2171 string userName(getUserName());
2172 ofs << "<!-- LinuxDoc file was created by LyX 1.0 (C) 1995-1999 "
2173 << "by <" << userName << "> " << date() << " -->\n";
2175 if(params.options.empty())
2176 sgmlOpenTag(ofs, 0, top_element);
2178 string top = top_element;
2180 top += params.options;
2181 sgmlOpenTag(ofs, 0, top);
2185 int desc_on = 0; /* description mode*/
2186 LyXLayout const & style =
2187 textclasslist.Style(GetCurrentTextClass(),
2189 par->AutoDeleteInsets();
2191 /* treat <toc> as a special case for compatibility with old code */
2192 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2193 Inset * inset = par->GetInset(0);
2194 char lyx_code = inset->LyxCode();
2195 if (lyx_code == Inset::TOC_CODE){
2196 string temp = "toc";
2197 sgmlOpenTag(ofs, depth, temp);
2200 linuxDocHandleFootnote(ofs, par, depth);
2205 /* environment tag closing */
2206 for( ; depth > par->depth; --depth) {
2207 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2208 environment_stack[depth].clear();
2211 /* write opening SGML tags */
2212 switch(style.latextype) {
2213 case LATEX_PARAGRAPH:
2214 if(depth == par->depth
2215 && !environment_stack[depth].empty()) {
2216 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2217 environment_stack[depth].clear();
2223 sgmlOpenTag(ofs, depth, style.latexname());
2228 LinuxDocError(par, 0, _("Error : Wrong depth for LatexType Command.\n"));
2230 if (!environment_stack[depth].empty()){
2231 sgmlCloseTag(ofs, depth,
2232 environment_stack[depth]);
2236 environment_stack[depth].clear();
2237 sgmlOpenTag(ofs, depth, style.latexname());
2240 case LATEX_ENVIRONMENT:
2241 case LATEX_ITEM_ENVIRONMENT:
2242 if(depth == par->depth
2243 && environment_stack[depth] != style.latexname()
2244 && !environment_stack[depth].empty()) {
2246 sgmlCloseTag(ofs, depth,
2247 environment_stack[depth]);
2248 environment_stack[depth].clear();
2250 if (depth < par->depth) {
2252 environment_stack[depth].clear();
2254 if (environment_stack[depth] != style.latexname()) {
2257 sgmlOpenTag(ofs, depth, temp);
2259 environment_stack[depth] = style.latexname();
2260 sgmlOpenTag(ofs, depth, environment_stack[depth]);
2262 if(style.latextype == LATEX_ENVIRONMENT) break;
2264 desc_on = (style.labeltype == LABEL_MANUAL);
2271 sgmlOpenTag(ofs, depth + 1, item_name);
2274 sgmlOpenTag(ofs, depth, style.latexname());
2279 SimpleLinuxDocOnePar(ofs, par, desc_on, depth);
2282 linuxDocHandleFootnote(ofs, par, depth);
2284 while(par && par->IsDummy());
2287 /* write closing SGML tags */
2288 switch(style.latextype) {
2290 case LATEX_ENVIRONMENT:
2291 case LATEX_ITEM_ENVIRONMENT:
2294 sgmlCloseTag(ofs, depth, style.latexname());
2299 /* Close open tags */
2300 for(; depth > 0; --depth)
2301 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2303 if(!environment_stack[depth].empty())
2304 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2307 sgmlCloseTag(ofs, 0, top_element);
2310 // How to check for successful close
2314 void Buffer::linuxDocHandleFootnote(ostream & os, LyXParagraph * & par,
2317 string tag = "footnote";
2319 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2320 sgmlOpenTag(os, depth + 1, tag);
2321 SimpleLinuxDocOnePar(os, par, 0, depth + 1);
2322 sgmlCloseTag(os, depth + 1, tag);
2328 void Buffer::DocBookHandleCaption(ostream & os, string & inner_tag,
2329 int const depth, int desc_on,
2330 LyXParagraph * & par)
2332 LyXParagraph * tpar = par;
2333 string tmp_par, extra_par;
2334 while (tpar && (tpar->footnoteflag != LyXParagraph::NO_FOOTNOTE) &&
2335 (tpar->layout != textclasslist.NumberOfLayout(params.textclass,
2339 tpar->layout == textclasslist.NumberOfLayout(params.textclass,
2340 "Caption").second) {
2341 sgmlOpenTag(os, depth + 1, inner_tag);
2342 SimpleDocBookOnePar(tmp_par, extra_par, tpar,
2343 desc_on, depth + 2);
2344 tmp_par = strip(tmp_par);
2345 tmp_par = frontStrip(tmp_par);
2347 sgmlCloseTag(os, depth+1, inner_tag);
2348 if(!extra_par.empty())
2354 void Buffer::DocBookHandleFootnote(ostream & os, LyXParagraph * & par,
2357 string tag, inner_tag;
2358 string tmp_par, extra_par;
2359 bool inner_span = false;
2362 // This is not how I like to see enums. They should not be anonymous
2363 // and variables of its type should not be declared right after the
2364 // last brace. (Lgb)
2371 } last = NO_ONE, present = FOOTNOTE_LIKE;
2373 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2374 if(last == present) {
2376 if(!tmp_par.empty()) {
2379 sgmlCloseTag(os, depth+1, inner_tag);
2380 sgmlOpenTag(os, depth+1, inner_tag);
2387 if(!inner_tag.empty()) sgmlCloseTag(os, depth+1, inner_tag);
2388 if(!extra_par.empty()) os << extra_par;
2389 if(!tag.empty()) sgmlCloseTag(os, depth, tag);
2392 switch (par->footnotekind) {
2393 case LyXParagraph::FOOTNOTE:
2394 case LyXParagraph::ALGORITHM:
2397 present = FOOTNOTE_LIKE;
2400 case LyXParagraph::MARGIN:
2403 present = MARGIN_LIKE;
2406 case LyXParagraph::FIG:
2407 case LyXParagraph::WIDE_FIG:
2409 inner_tag = "title";
2413 case LyXParagraph::TAB:
2414 case LyXParagraph::WIDE_TAB:
2416 inner_tag = "title";
2421 sgmlOpenTag(os, depth, tag);
2422 if ((present == TAB_LIKE) || (present == FIG_LIKE)) {
2423 DocBookHandleCaption(os, inner_tag, depth,
2427 sgmlOpenTag(os, depth + 1, inner_tag);
2430 // ignore all caption here, we processed them above!!!
2431 if (par->layout != textclasslist.NumberOfLayout(params.textclass,
2432 "Caption").second) {
2433 SimpleDocBookOnePar(tmp_par, extra_par, par,
2434 desc_on, depth + 2);
2436 tmp_par = frontStrip(strip(tmp_par));
2442 if(!inner_tag.empty()) sgmlCloseTag(os, depth+1, inner_tag);
2443 if(!extra_par.empty()) os << extra_par;
2444 if(!tag.empty()) sgmlCloseTag(os, depth, tag);
2448 /* push a tag in a style stack */
2449 void Buffer::push_tag(ostream & os, char const * tag,
2450 int & pos, char stack[5][3])
2454 /* pop all previous tags */
2455 for (j = pos; j >= 0; --j)
2456 os << "</" << stack[j] << ">";
2459 sprintf(stack[++pos], "%s", tag);
2462 for (j = 0; j <= pos; ++j)
2463 os << "<" << stack[j] << ">";
2467 // pop a tag from a style stack
2468 void Buffer::pop_tag(ostream & os, char const * tag,
2469 int & pos, char stack[5][3])
2473 // pop all tags till specified one
2474 for (j = pos; (j >= 0) && (strcmp(stack[j], tag)); --j)
2475 os << "</" << stack[j] << ">";
2478 os << "</" << tag << ">";
2480 // push all tags, but the specified one
2481 for (j = j + 1; j <= pos; ++j) {
2482 os << "<" << stack[j] << ">";
2483 strcpy(stack[j-1], stack[j]);
2489 /* handle internal paragraph parsing -- layout already processed */
2491 // checks, if newcol chars should be put into this line
2492 // writes newline, if necessary.
2494 void linux_doc_line_break(ostream & os, unsigned int & colcount,
2495 const unsigned int newcol)
2498 if (colcount > lyxrc->ascii_linelen) {
2500 colcount = newcol; // assume write after this call
2505 void Buffer::SimpleLinuxDocOnePar(ostream & os, LyXParagraph * par,
2506 int desc_on, int const /*depth*/)
2508 LyXFont font1, font2;
2511 LyXParagraph::size_type main_body;
2513 LyXLayout const & style = textclasslist.Style(params.textclass,
2516 char family_type = 0; // family font flag
2517 bool is_bold = false; // series font flag
2518 char shape_type = 0; // shape font flag
2519 bool is_em = false; // emphasis (italic) font flag
2521 int stack_num = -1; // style stack position
2522 char stack[5][3]; // style stack
2523 unsigned int char_line_count = 5; // Heuristic choice ;-)
2525 if (style.labeltype != LABEL_MANUAL)
2528 main_body = par->BeginningOfMainBody();
2530 /* gets paragraph main font */
2532 font1 = style.labelfont;
2537 /* parsing main loop */
2538 for (LyXParagraph::size_type i = 0;
2539 i < par->size(); ++i) {
2541 /* handle quote tag */
2542 if (i == main_body && !par->IsDummy()) {
2547 font2 = par->getFont(i);
2549 if (font1.family() != font2.family()) {
2550 switch(family_type) {
2552 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2553 push_tag(os, "tt", stack_num, stack);
2556 else if (font2.family() == LyXFont::SANS_FAMILY) {
2557 push_tag(os, "sf", stack_num, stack);
2562 pop_tag(os, "tt", stack_num, stack);
2563 if (font2.family() == LyXFont::SANS_FAMILY) {
2564 push_tag(os, "sf", stack_num, stack);
2572 pop_tag(os, "sf", stack_num, stack);
2573 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2574 push_tag(os, "tt", stack_num, stack);
2583 /* handle bold face */
2584 if (font1.series() != font2.series()) {
2585 if (font2.series() == LyXFont::BOLD_SERIES) {
2586 push_tag(os, "bf", stack_num, stack);
2590 pop_tag(os, "bf", stack_num, stack);
2595 /* handle italic and slanted fonts */
2596 if (font1.shape() != font2.shape()) {
2597 switch(shape_type) {
2599 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2600 push_tag(os, "it", stack_num, stack);
2603 else if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2604 push_tag(os, "sl", stack_num, stack);
2609 pop_tag(os, "it", stack_num, stack);
2610 if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2611 push_tag(os, "sl", stack_num, stack);
2619 pop_tag(os, "sl", stack_num, stack);
2620 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2621 push_tag(os, "it", stack_num, stack);
2629 /* handle <em> tag */
2630 if (font1.emph() != font2.emph()) {
2631 if (font2.emph() == LyXFont::ON) {
2632 push_tag(os, "em", stack_num, stack);
2635 pop_tag(os, "em", stack_num, stack);
2640 c = par->GetChar(i);
2642 if (font2.latex() == LyXFont::ON) {
2643 // "TeX"-Mode on == > SGML-Mode on.
2645 os << c; // see LaTeX-Generation...
2647 } else if (c == LyXParagraph::META_INSET) {
2648 inset = par->GetInset(i);
2650 inset->Linuxdoc(tmp_out);
2655 if (par->linuxDocConvertChar(c, sgml_string)
2656 && !style.free_spacing) { // in freespacing
2658 // non-breaking characters
2662 linux_doc_line_break(os, char_line_count, 6);
2667 linux_doc_line_break(os, char_line_count, 1);
2673 char_line_count += sgml_string.length();
2679 /* needed if there is an optional argument but no contents */
2680 if (main_body > 0 && main_body == par->size()) {
2684 /* pop all defined Styles */
2685 for (j = stack_num; j >= 0; --j) {
2686 linux_doc_line_break(os,
2688 3 + strlen(stack[j]));
2689 os << "</" << stack[j] << ">";
2692 /* resets description flag correctly */
2695 /* <tag> not closed... */
2696 linux_doc_line_break(os, char_line_count, 6);
2700 /* fprintf(file, "</p>");*/
2706 /* print an error message */
2707 void Buffer::LinuxDocError(LyXParagraph * par, int pos,
2708 char const * message)
2710 InsetError * new_inset;
2712 /* insert an error marker in text */
2713 new_inset = new InsetError(message);
2714 par->InsertChar(pos, LyXParagraph::META_INSET);
2715 par->InsertInset(pos, new_inset);
2718 // This constant defines the maximum number of
2719 // environment layouts that can be nesteded.
2720 // The same applies for command layouts.
2721 // These values should be more than enough.
2722 // José Matos (1999/07/22)
2724 enum { MAX_NEST_LEVEL = 25};
2726 void Buffer::makeDocBookFile(string const & filename, int column)
2728 LyXParagraph * par = paragraph;
2730 string top_element= textclasslist.LatexnameOfClass(params.textclass);
2731 string environment_stack[MAX_NEST_LEVEL];
2732 string environment_inner[MAX_NEST_LEVEL];
2733 string command_stack[MAX_NEST_LEVEL];
2734 bool command_flag= false;
2735 int command_depth= 0, command_base= 0, cmd_depth= 0;
2737 string item_name, command_name;
2738 string c_depth, c_params, tmps;
2740 int depth= 0; /* paragraph depth */
2742 tex_code_break_column = column;
2744 ofstream ofs(filename.c_str());
2746 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), filename);
2753 ofs << "<!doctype " << top_element
2754 << " public \"-//OASIS//DTD DocBook V3.1//EN\"";
2756 if (params.preamble.empty())
2759 ofs << "\n [ " << params.preamble << " \n]>\n\n";
2761 ofs << "<!-- DocBook file was created by " << LYX_DOCVERSION
2762 << "\n See http://www.lyx.org/ for more information -->\n";
2764 if(params.options.empty())
2765 sgmlOpenTag(ofs, 0, top_element);
2767 string top = top_element;
2769 top += params.options;
2770 sgmlOpenTag(ofs, 0, top);
2774 int desc_on= 0; /* description mode*/
2775 LyXLayout const & style = textclasslist.Style(GetCurrentTextClass(),
2777 par->AutoDeleteInsets();
2779 /* environment tag closing */
2780 for( ; depth > par->depth; --depth) {
2781 if(environment_inner[depth] != "!-- --") {
2782 item_name= "listitem";
2783 sgmlCloseTag(ofs, command_depth + depth,
2785 if( environment_inner[depth] == "varlistentry")
2786 sgmlCloseTag(ofs, depth+command_depth,
2787 environment_inner[depth]);
2789 sgmlCloseTag(ofs, depth + command_depth,
2790 environment_stack[depth]);
2791 environment_stack[depth].clear();
2792 environment_inner[depth].clear();
2795 if(depth == par->depth
2796 && environment_stack[depth] != style.latexname()
2797 && !environment_stack[depth].empty()) {
2798 if(environment_inner[depth] != "!-- --") {
2799 item_name= "listitem";
2800 sgmlCloseTag(ofs, command_depth+depth,
2802 if( environment_inner[depth] == "varlistentry")
2804 depth + command_depth,
2805 environment_inner[depth]);
2808 sgmlCloseTag(ofs, depth + command_depth,
2809 environment_stack[depth]);
2811 environment_stack[depth].clear();
2812 environment_inner[depth].clear();
2815 // Write opening SGML tags.
2816 switch(style.latextype) {
2817 case LATEX_PARAGRAPH:
2818 if(style.latexname() != "dummy")
2819 sgmlOpenTag(ofs, depth+command_depth,
2825 LinuxDocError(par, 0,
2826 _("Error : Wrong depth for "
2827 "LatexType Command.\n"));
2829 command_name = style.latexname();
2831 tmps = style.latexparam();
2832 c_params = split(tmps, c_depth,'|');
2834 cmd_depth= atoi(c_depth.c_str());
2837 if(cmd_depth<command_base) {
2838 for(int j = command_depth;
2839 j >= command_base; --j)
2840 if(!command_stack[j].empty())
2841 sgmlCloseTag(ofs, j, command_stack[j]);
2842 command_depth= command_base= cmd_depth;
2844 else if(cmd_depth <= command_depth) {
2845 for(int j = command_depth;
2846 j >= cmd_depth; --j)
2848 if(!command_stack[j].empty())
2849 sgmlCloseTag(ofs, j, command_stack[j]);
2850 command_depth= cmd_depth;
2853 command_depth= cmd_depth;
2856 command_depth = command_base = cmd_depth;
2857 command_flag = true;
2859 command_stack[command_depth]= command_name;
2861 // treat label as a special case for
2862 // more WYSIWYM handling.
2863 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2864 Inset * inset = par->GetInset(0);
2865 char lyx_code = inset->LyxCode();
2866 if (lyx_code == Inset::LABEL_CODE){
2867 command_name += " id=\"";
2868 command_name += (static_cast<InsetCommand *>(inset))->getContents();
2869 command_name += "\"";
2874 sgmlOpenTag(ofs, depth+command_depth, command_name);
2875 item_name = "title";
2876 sgmlOpenTag(ofs, depth + 1 + command_depth, item_name);
2879 case LATEX_ENVIRONMENT:
2880 case LATEX_ITEM_ENVIRONMENT:
2881 if (depth < par->depth) {
2883 environment_stack[depth].clear();
2886 if (environment_stack[depth] != style.latexname()) {
2887 environment_stack[depth] = style.latexname();
2888 environment_inner[depth] = "!-- --";
2889 sgmlOpenTag(ofs, depth + command_depth,
2890 environment_stack[depth]);
2892 if(environment_inner[depth] != "!-- --") {
2893 item_name= "listitem";
2895 command_depth + depth,
2897 if (environment_inner[depth] == "varlistentry")
2899 depth + command_depth,
2900 environment_inner[depth]);
2904 if(style.latextype == LATEX_ENVIRONMENT) {
2905 if(!style.latexparam().empty())
2906 sgmlOpenTag(ofs, depth + command_depth,
2907 style.latexparam());
2911 desc_on = (style.labeltype == LABEL_MANUAL);
2914 environment_inner[depth]= "varlistentry";
2916 environment_inner[depth]= "listitem";
2918 sgmlOpenTag(ofs, depth + 1 + command_depth,
2919 environment_inner[depth]);
2923 sgmlOpenTag(ofs, depth + 1 + command_depth,
2928 sgmlOpenTag(ofs, depth + 1 + command_depth,
2933 sgmlOpenTag(ofs, depth + command_depth,
2939 string tmp_par, extra_par;
2941 SimpleDocBookOnePar(tmp_par, extra_par, par, desc_on,
2942 depth + 1 + command_depth);
2946 DocBookHandleFootnote(ofs, par,
2947 depth + 1 + command_depth);
2949 while(par && par->IsDummy());
2952 /* write closing SGML tags */
2953 switch(style.latextype) {
2956 sgmlCloseTag(ofs, depth + command_depth, end_tag);
2958 case LATEX_ENVIRONMENT:
2959 if(!style.latexparam().empty())
2960 sgmlCloseTag(ofs, depth + command_depth,
2961 style.latexparam());
2963 case LATEX_ITEM_ENVIRONMENT:
2964 if(desc_on == 1) break;
2966 sgmlCloseTag(ofs, depth + 1 + command_depth, end_tag);
2968 case LATEX_PARAGRAPH:
2969 if(style.latexname() != "dummy")
2970 sgmlCloseTag(ofs, depth + command_depth,
2974 sgmlCloseTag(ofs, depth + command_depth,
2981 for(; depth >= 0; --depth) {
2982 if(!environment_stack[depth].empty()) {
2983 if(environment_inner[depth] != "!-- --") {
2984 item_name= "listitem";
2985 sgmlCloseTag(ofs, command_depth + depth,
2987 if( environment_inner[depth] == "varlistentry")
2988 sgmlCloseTag(ofs, depth + command_depth,
2989 environment_inner[depth]);
2992 sgmlCloseTag(ofs, depth + command_depth,
2993 environment_stack[depth]);
2997 for(int j = command_depth; j >= command_base; --j)
2998 if(!command_stack[j].empty())
2999 sgmlCloseTag(ofs, j, command_stack[j]);
3002 sgmlCloseTag(ofs, 0, top_element);
3005 // How to check for successful close
3009 void Buffer::SimpleDocBookOnePar(string & file, string & extra,
3010 LyXParagraph * par, int & desc_on,
3014 par->SimpleDocBookOneTablePar(file, extra, desc_on, depth);
3017 LyXFont font1, font2;
3020 LyXParagraph::size_type main_body;
3022 string emph= "emphasis";
3023 bool emph_flag= false;
3024 int char_line_count= 0;
3026 LyXLayout const & style = textclasslist.Style(params.textclass,
3029 if (style.labeltype != LABEL_MANUAL)
3032 main_body = par->BeginningOfMainBody();
3034 /* gets paragraph main font */
3036 font1 = style.labelfont;
3040 char_line_count = depth;
3041 if(!style.free_spacing)
3042 for (j= 0;j< depth;j++)
3045 /* parsing main loop */
3046 for (LyXParagraph::size_type i = 0;
3047 i < par->size(); ++i) {
3048 font2 = par->getFont(i);
3050 /* handle <emphasis> tag */
3051 if (font1.emph() != font2.emph() && i) {
3052 if (font2.emph() == LyXFont::ON) {
3053 file += "<emphasis>";
3056 file += "</emphasis>";
3061 c = par->GetChar(i);
3063 if (c == LyXParagraph::META_INSET) {
3064 inset = par->GetInset(i);
3066 inset->DocBook(tmp_out);
3068 // This code needs some explanation:
3069 // Two insets are treated specially
3070 // label if it is the first element in a command paragraph
3072 // graphics inside tables or figure floats can't go on
3073 // title (the equivalente in latex for this case is caption
3074 // and title should come first
3077 if(desc_on!= 3 || i!= 0) {
3078 if(!tmp_out.empty() && tmp_out[0] == '@') {
3080 extra += frontStrip(tmp_out, '@');
3082 file += frontStrip(tmp_out, '@');
3087 } else if (font2.latex() == LyXFont::ON) {
3088 // "TeX"-Mode on ==> SGML-Mode on.
3095 if (par->linuxDocConvertChar(c, sgml_string)
3096 && !style.free_spacing) { // in freespacing
3098 // non-breaking characters
3103 file += "</term><listitem><para>";
3111 file += sgml_string;
3117 /* needed if there is an optional argument but no contents */
3118 if (main_body > 0 && main_body == par->size()) {
3122 file += "</emphasis>";
3125 /* resets description flag correctly */
3128 /* <term> not closed... */
3136 // candidate for move to BufferView
3137 bool Buffer::removeAutoInsets()
3139 LyXParagraph * par = paragraph;
3141 LyXCursor cursor = users->text->cursor;
3142 LyXCursor tmpcursor = cursor;
3143 cursor.par = tmpcursor.par->ParFromPos(tmpcursor.pos);
3144 cursor.pos = tmpcursor.par->PositionInParFromPos(tmpcursor.pos);
3148 if (par->AutoDeleteInsets()){
3150 if (par->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE){
3151 /* this is possible now, since SetCursor takes
3152 care about footnotes */
3153 users->text->SetCursorIntern(par, 0);
3154 users->text->RedoParagraphs(users->text->cursor, users->text->cursor.par->Next());
3155 users->text->FullRebreak();
3160 /* avoid forbidden cursor positions caused by error removing */
3161 if (cursor.pos > cursor.par->Last())
3162 cursor.pos = cursor.par->Last();
3163 users->text->SetCursorIntern(cursor.par, cursor.pos);
3169 int Buffer::runLaTeX()
3171 if (!users->text) return 0;
3175 // get LaTeX-Filename
3176 string name = getLatexName();
3178 string path = OnlyPath(filename);
3180 string org_path = path;
3181 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
3185 Path p(path); // path to LaTeX file
3186 users->owner()->getMiniBuffer()->Set(_("Running LaTeX..."));
3188 // Remove all error insets
3189 bool a = removeAutoInsets();
3191 // Always generate the LaTeX file
3192 makeLaTeXFile(name, org_path, false);
3195 // do the LaTex run(s)
3197 LaTeX latex(lyxrc->latex_command, name, filepath);
3198 int res = latex.run(terr,
3199 users->owner()->getMiniBuffer()); // running latex
3201 // check return value from latex.run().
3202 if ((res & LaTeX::NO_LOGFILE)) {
3203 WriteAlert(_("LaTeX did not work!"),
3204 _("Missing log file:"), name);
3205 } else if ((res & LaTeX::ERRORS)) {
3206 users->owner()->getMiniBuffer()->Set(_("Done"));
3207 // Insert all errors as errors boxes
3210 // Dvi should also be kept dirty if the latex run
3211 // ends up with errors. However it should be possible
3212 // to view a dirty dvi too.
3214 //no errors or any other things to think about so:
3215 users->owner()->getMiniBuffer()->Set(_("Done"));
3219 // if we removed error insets before we ran LaTeX or if we inserted
3220 // error insets after we ran LaTeX this must be run:
3221 if (a || (res & LaTeX::ERRORS)){
3224 users->updateScrollbar();
3228 return latex.getNumErrors();
3232 int Buffer::runLiterate()
3234 if (!users->text) return 0;
3238 // get LaTeX-Filename
3239 string name = getLatexName();
3240 // get Literate-Filename
3241 string lit_name = ChangeExtension (getLatexName(),
3242 lyxrc->literate_extension, true);
3244 string path = OnlyPath(filename);
3246 string org_path = path;
3247 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
3251 Path p(path); // path to Literate file
3252 users->owner()->getMiniBuffer()->Set(_("Running Literate..."));
3254 // Remove all error insets
3255 bool a = removeAutoInsets();
3257 // generate the Literate file if necessary
3258 if (!isDviClean() || a) {
3259 makeLaTeXFile(lit_name, org_path, false);
3263 Literate literate(lyxrc->latex_command, name, filepath,
3265 lyxrc->literate_command, lyxrc->literate_error_filter,
3266 lyxrc->build_command, lyxrc->build_error_filter);
3268 int res = literate.weave(terr, users->owner()->getMiniBuffer());
3270 // check return value from literate.weave().
3271 if ((res & Literate::NO_LOGFILE)) {
3272 WriteAlert(_("Literate command did not work!"),
3273 _("Missing log file:"), name);
3274 } else if ((res & Literate::ERRORS)) {
3275 users->owner()->getMiniBuffer()->Set(_("Done"));
3276 // Insert all errors as errors boxes
3279 // Dvi should also be kept dirty if the latex run
3280 // ends up with errors. However it should be possible
3281 // to view a dirty dvi too.
3283 //no errors or any other things to think about so:
3284 users->owner()->getMiniBuffer()->Set(_("Done"));
3288 // if we removed error insets before we ran LaTeX or if we inserted
3289 // error insets after we ran LaTeX this must be run:
3290 if (a || (res & Literate::ERRORS)){
3293 users->updateScrollbar();
3297 return literate.getNumErrors();
3301 int Buffer::buildProgram()
3303 if (!users->text) return 0;
3307 // get LaTeX-Filename
3308 string name = getLatexName();
3309 // get Literate-Filename
3310 string lit_name = ChangeExtension(getLatexName(),
3311 lyxrc->literate_extension, true);
3313 string path = OnlyPath(filename);
3315 string org_path = path;
3316 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
3320 Path p(path); // path to Literate file
3321 users->owner()->getMiniBuffer()->Set(_("Building Program..."));
3323 // Remove all error insets
3324 bool a = removeAutoInsets();
3326 // generate the LaTeX file if necessary
3327 if (!isNwClean() || a) {
3328 makeLaTeXFile(lit_name, org_path, false);
3332 Literate literate(lyxrc->latex_command, name, filepath,
3334 lyxrc->literate_command, lyxrc->literate_error_filter,
3335 lyxrc->build_command, lyxrc->build_error_filter);
3337 int res = literate.build(terr, users->owner()->getMiniBuffer());
3339 // check return value from literate.build().
3340 if ((res & Literate::NO_LOGFILE)) {
3341 WriteAlert(_("Build did not work!"),
3342 _("Missing log file:"), name);
3343 } else if ((res & Literate::ERRORS)) {
3344 users->owner()->getMiniBuffer()->Set(_("Done"));
3345 // Insert all errors as errors boxes
3348 // Literate files should also be kept dirty if the literate
3349 // command run ends up with errors.
3351 //no errors or any other things to think about so:
3352 users->owner()->getMiniBuffer()->Set(_("Done"));
3356 // if we removed error insets before we ran Literate/Build or if we inserted
3357 // error insets after we ran Literate/Build this must be run:
3358 if (a || (res & Literate::ERRORS)){
3361 users->updateScrollbar();
3365 return literate.getNumErrors();
3369 // This should be enabled when the Chktex class is implemented. (Asger)
3370 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
3371 // Other flags: -wall -v0 -x
3372 int Buffer::runChktex()
3374 if (!users->text) return 0;
3378 // get LaTeX-Filename
3379 string name = getLatexName();
3380 string path = OnlyPath(filename);
3382 string org_path = path;
3383 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
3387 Path p(path); // path to LaTeX file
3388 users->owner()->getMiniBuffer()->Set(_("Running chktex..."));
3390 // Remove all error insets
3391 bool a = removeAutoInsets();
3393 // Generate the LaTeX file if neccessary
3394 if (!isDviClean() || a) {
3395 makeLaTeXFile(name, org_path, false);
3400 Chktex chktex(lyxrc->chktex_command, name, filepath);
3401 int res = chktex.run(terr); // run chktex
3404 WriteAlert(_("chktex did not work!"),
3405 _("Could not run with file:"), name);
3406 } else if (res > 0) {
3407 // Insert all errors as errors boxes
3411 // if we removed error insets before we ran chktex or if we inserted
3412 // error insets after we ran chktex, this must be run:
3416 users->updateScrollbar();
3424 extern void AllFloats(char, char);
3427 // candidate for move to BufferView
3428 void Buffer::insertErrors(TeXErrors & terr)
3430 // Save the cursor position
3431 LyXCursor cursor = users->text->cursor;
3433 // This is drastic, but it's the only fix, I could find. (Asger)
3437 for (TeXErrors::Errors::const_iterator cit = terr.begin();
3440 string desctext((*cit).error_desc);
3441 string errortext((*cit).error_text);
3442 string msgtxt = desctext + '\n' + errortext;
3443 int errorrow = (*cit).error_in_line;
3445 // Insert error string for row number
3449 texrow.getIdFromRow(errorrow, tmpid, tmppos);
3451 LyXParagraph * texrowpar = 0;
3454 texrowpar = users->text->FirstParagraph();
3457 texrowpar = users->text->GetParFromID(tmpid);
3463 InsetError * new_inset = new InsetError(msgtxt);
3464 users->text->SetCursorIntern(texrowpar, tmppos);
3465 users->text->InsertInset(new_inset);
3466 users->text->FullRebreak();
3468 // Restore the cursor position
3469 users->text->SetCursorIntern(cursor.par, cursor.pos);
3473 // candidate for move to BufferView
3474 void Buffer::setCursorFromRow (int row)
3479 texrow.getIdFromRow(row, tmpid, tmppos);
3481 LyXParagraph * texrowpar;
3484 texrowpar = users->text->FirstParagraph();
3487 texrowpar = users->text->GetParFromID(tmpid);
3489 users->text->SetCursor(texrowpar, tmppos);
3493 void Buffer::RoffAsciiTable(ostream & os, LyXParagraph * par)
3495 LyXFont font1 = LyXFont(LyXFont::ALL_INHERIT);
3498 LyXParagraph::size_type i;
3502 string fname1 = TmpFileName(string(), "RAT1");
3503 string fname2 = TmpFileName(string(), "RAT2");
3505 ofstream ofs(fname1.c_str());
3507 WriteAlert(_("LYX_ERROR:"),
3508 _("Cannot open temporary file:"), fname1);
3511 par->table->RoffEndOfCell(ofs, -1);
3512 for (i = 0; i < par->size(); ++i) {
3513 c = par->GetChar(i);
3514 if (par->table->IsContRow(cell)) {
3515 if (c == LyXParagraph::META_NEWLINE)
3519 font2 = par->GetFontSettings(i);
3520 if (font1.latex() != font2.latex()) {
3521 if (font2.latex() != LyXFont::OFF)
3525 case LyXParagraph::META_INSET:
3526 if ((inset = par->GetInset(i))) {
3527 fstream fs(fname2.c_str(), ios::in|ios::out);
3529 WriteAlert(_("LYX_ERROR:"),
3530 _("Cannot open temporary file:"), fname2);
3532 remove(fname1.c_str());
3535 inset->Latex(fs, -1);
3548 case LyXParagraph::META_NEWLINE:
3549 if (par->table->CellHasContRow(cell)>= 0)
3550 par->RoffContTableRows(ofs, i+1, cell);
3551 par->table->RoffEndOfCell(ofs, cell);
3554 case LyXParagraph::META_HFILL:
3556 case LyXParagraph::META_PROTECTED_SEPARATOR:
3566 << "RoffAsciiTable:"
3567 " NULL char in structure." << endl;
3571 par->table->RoffEndOfCell(ofs, cell);
3573 string cmd = lyxrc->ascii_roff_command + " >" + fname2;
3574 cmd = subst(cmd, "$$FName", fname1);
3575 Systemcalls one(Systemcalls::System, cmd);
3576 if (!(lyxerr.debugging(Debug::ROFF))) {
3577 remove(fname1.c_str());
3579 ifstream ifs(fname2.c_str());
3581 WriteFSAlert(_("Error! Can't open temporary file:"), fname2);
3584 // now output the produced file
3588 WriteAlert(_("Error!"),
3589 _("Error executing *roff command on table"));
3590 // overread leading blank lines
3591 while(!ifs && (c == '\n'))
3594 for(j = 0; j < par->depth; ++j)
3596 while(!ifs && (c != '\n')) {
3601 // overread trailing blank lines
3602 while(!ifs && (c == '\n'))
3606 remove(fname2.c_str());
3610 /// changed Heinrich Bauer, 23/03/98
3611 bool Buffer::isDviClean()
3613 if (lyxrc->use_tempdir)
3614 return dvi_clean_tmpd;
3616 return dvi_clean_orgd;
3620 /// changed Heinrich Bauer, 23/03/98
3621 void Buffer::markDviClean()
3623 if (lyxrc->use_tempdir)
3624 dvi_clean_tmpd = true;
3626 dvi_clean_orgd = true;
3630 /// changed Heinrich Bauer, 23/03/98
3631 void Buffer::markDviDirty()
3633 if (lyxrc->use_tempdir)
3634 dvi_clean_tmpd = false;
3636 dvi_clean_orgd = false;
3640 void Buffer::validate(LaTeXFeatures & features)
3642 LyXParagraph * par = paragraph;
3643 LyXTextClass const & tclass =
3644 textclasslist.TextClass(params.textclass);
3646 // AMS Style is at document level
3648 features.amsstyle = (params.use_amsmath ||
3649 tclass.provides(LyXTextClass::amsmath));
3652 // We don't use "lyxerr.debug" because of speed. (Asger)
3653 if (lyxerr.debugging(Debug::LATEX))
3654 lyxerr << "Paragraph: " << par << endl;
3656 // Now just follow the list of paragraphs and run
3657 // validate on each of them.
3658 par->validate(features);
3660 // and then the next paragraph
3664 // the bullet shapes are buffer level not paragraph level
3665 // so they are tested here
3666 for (int i = 0; i < 4; ++i) {
3667 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
3668 int font = params.user_defined_bullets[i].getFont();
3671 .user_defined_bullets[i]
3678 features.latexsym = true;
3682 features.amssymb = true;
3684 else if ((font >= 2 && font <= 5)) {
3685 features.pifont = true;
3690 if (lyxerr.debugging(Debug::LATEX)) {
3691 features.showStruct(params);
3696 void Buffer::setPaperStuff()
3698 params.papersize = BufferParams::PAPER_DEFAULT;
3699 char c1 = params.paperpackage;
3700 if (c1 == BufferParams::PACKAGE_NONE) {
3701 char c2 = params.papersize2;
3702 if (c2 == BufferParams::VM_PAPER_USLETTER)
3703 params.papersize = BufferParams::PAPER_USLETTER;
3704 else if (c2 == BufferParams::VM_PAPER_USLEGAL)
3705 params.papersize = BufferParams::PAPER_LEGALPAPER;
3706 else if (c2 == BufferParams::VM_PAPER_USEXECUTIVE)
3707 params.papersize = BufferParams::PAPER_EXECUTIVEPAPER;
3708 else if (c2 == BufferParams::VM_PAPER_A3)
3709 params.papersize = BufferParams::PAPER_A3PAPER;
3710 else if (c2 == BufferParams::VM_PAPER_A4)
3711 params.papersize = BufferParams::PAPER_A4PAPER;
3712 else if (c2 == BufferParams::VM_PAPER_A5)
3713 params.papersize = BufferParams::PAPER_A5PAPER;
3714 else if ((c2 == BufferParams::VM_PAPER_B3) || (c2 == BufferParams::VM_PAPER_B4) ||
3715 (c2 == BufferParams::VM_PAPER_B5))
3716 params.papersize = BufferParams::PAPER_B5PAPER;
3717 } else if ((c1 == BufferParams::PACKAGE_A4) || (c1 == BufferParams::PACKAGE_A4WIDE) ||
3718 (c1 == BufferParams::PACKAGE_WIDEMARGINSA4))
3719 params.papersize = BufferParams::PAPER_A4PAPER;
3724 void Buffer::setOldPaperStuff()
3726 char c = params.papersize = params.papersize2;
3727 params.papersize2 = BufferParams::VM_PAPER_DEFAULT;
3728 params.paperpackage = BufferParams::PACKAGE_NONE;
3729 if (c == OLD_PAPER_A4PAPER)
3730 params.papersize2 = BufferParams::VM_PAPER_A4;
3731 else if (c == OLD_PAPER_A4)
3732 params.paperpackage = BufferParams::PACKAGE_A4;
3733 else if (c == OLD_PAPER_A4WIDE)
3734 params.paperpackage = BufferParams::PACKAGE_A4WIDE;
3735 else if (c == OLD_PAPER_WIDEMARGINSA4)
3736 params.paperpackage = BufferParams::PACKAGE_WIDEMARGINSA4;
3737 else if (c == OLD_PAPER_USLETTER)
3738 params.papersize2 = BufferParams::VM_PAPER_USLETTER;
3739 else if (c == OLD_PAPER_A5PAPER)
3740 params.papersize2 = BufferParams::VM_PAPER_A5;
3741 else if (c == OLD_PAPER_B5PAPER)
3742 params.papersize2 = BufferParams::VM_PAPER_B5;
3743 else if (c == OLD_PAPER_EXECUTIVEPAPER)
3744 params.papersize2 = BufferParams::VM_PAPER_USEXECUTIVE;
3745 else if (c == OLD_PAPER_LEGALPAPER)
3746 params.papersize2 = BufferParams::VM_PAPER_USLEGAL;
3752 // candidate for move to BufferView
3753 void Buffer::insertInset(Inset * inset, string const & lout,
3756 // check for table/list in tables
3757 if (no_table && users->text->cursor.par->table){
3758 WriteAlert(_("Impossible Operation!"),
3759 _("Cannot insert table/list in table."),
3763 // not quite sure if we want this...
3764 users->text->SetCursorParUndo();
3765 users->text->FreezeUndo();
3768 if (!lout.empty()) {
3770 users->text->BreakParagraph();
3773 if (users->text->cursor.par->Last()) {
3774 users->text->CursorLeft();
3776 users->text->BreakParagraph();
3780 int lay = textclasslist.NumberOfLayout(params.textclass,
3782 if (lay == -1) // layout not found
3783 // use default layout "Standard" (0)
3786 users->text->SetLayout(lay);
3788 users->text->SetParagraph(0, 0,
3790 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3796 users->text->current_font.setLatex(LyXFont::OFF);
3799 users->text->InsertInset(inset);
3802 users->text->UnFreezeUndo();
3806 // Open and lock an updatable inset
3807 // candidate for move to BufferView
3808 void Buffer::open_new_inset(UpdatableInset * new_inset)
3811 users->text->FinishUndo();
3812 insertInset(new_inset);
3813 users->text->CursorLeft();
3815 new_inset->Edit(0, 0);
3819 /* This function should be in Buffer because it's a buffer's property (ale) */
3820 string Buffer::getIncludeonlyList(char delim)
3823 LyXParagraph * par = paragraph;
3824 LyXParagraph::size_type pos;
3828 while ((inset = par->ReturnNextInsetPointer(pos))){
3829 if (inset->LyxCode() == Inset::INCLUDE_CODE) {
3830 InsetInclude * insetinc =
3831 static_cast<InsetInclude*>(inset);
3832 if (insetinc->isInclude()
3833 && insetinc->isNoLoad()) {
3836 lst += ChangeExtension(insetinc->getContents(), string(), true);
3843 lyxerr.debug() << "Includeonly(" << lst << ')' << endl;
3848 /* This is also a buffer property (ale) */
3849 string Buffer::getReferenceList(char delim)
3851 /// if this is a child document and the parent is already loaded
3852 /// Use the parent's list instead [ale990407]
3853 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3854 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3856 return tmp->getReferenceList(delim);
3859 LyXParagraph * par = paragraph;
3860 LyXParagraph::size_type pos;
3865 while ((inset = par->ReturnNextInsetPointer(pos))){
3866 for (int i = 0; i < inset->GetNumberOfLabels(); i++) {
3869 lst += inset->getLabel(i);
3875 lyxerr.debug() << "References(" << lst << ")" << endl;
3880 /* This is also a buffer property (ale) */
3881 string Buffer::getBibkeyList(char delim)
3883 /// if this is a child document and the parent is already loaded
3884 /// Use the parent's list instead [ale990412]
3885 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3886 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3888 return tmp->getBibkeyList(delim);
3892 LyXParagraph * par = paragraph;
3895 if (!bibkeys.empty())
3897 bibkeys += par->bibkey->getContents();
3902 // Might be either using bibtex or a child has bibliography
3903 if (bibkeys.empty()) {
3907 LyXParagraph::size_type pos = -1;
3909 // Search for Bibtex or Include inset
3910 while ((inset = par->ReturnNextInsetPointer(pos))) {
3911 if (inset-> LyxCode() == Inset::BIBTEX_CODE) {
3912 if (!bibkeys.empty())
3914 bibkeys += static_cast<InsetBibtex*>(inset)->getKeys();
3915 } else if (inset-> LyxCode() == Inset::INCLUDE_CODE) {
3916 string bk = static_cast<InsetInclude*>(inset)->getKeys();
3918 if (!bibkeys.empty())
3929 lyxerr.debug() << "Bibkeys(" << bibkeys << ")" << endl;
3934 // candidate for move to BufferView
3935 /* This is also a buffer property (ale) */
3936 // Not so sure about that. a goto Label function can not be buffer local, just
3937 // think how this will work in a multiwindo/buffer environment, all the
3938 // cursors in all the views showing this buffer will move. (Lgb)
3939 // OK, then no cursor action should be allowed in buffer. (ale)
3940 bool Buffer::gotoLabel(string const & label)
3943 LyXParagraph * par = paragraph;
3944 LyXParagraph::size_type pos;
3948 while ((inset = par->ReturnNextInsetPointer(pos))){
3949 for (int i = 0; i < inset->GetNumberOfLabels(); i++) {
3950 if (label == inset->getLabel(i)) {
3952 users->text->SetCursor(par, pos);
3953 users->text->sel_cursor = users->text->cursor;
3966 bool Buffer::isDepClean(string const & name) const
3968 DEPCLEAN * item = dep_clean;
3969 while (item && item->master != name)
3971 if (!item) return true;
3976 void Buffer::markDepClean(string const & name)
3979 dep_clean = new DEPCLEAN;
3980 dep_clean->clean = true;
3981 dep_clean->master = name;
3982 dep_clean->next = 0;
3984 DEPCLEAN* item = dep_clean;
3985 while (item && item->master != name)
3990 item = new DEPCLEAN;
3992 item->master = name;
3998 void Buffer::Dispatch(const string & command)
4000 // Split command string into command and argument
4001 string cmd, line = frontStrip(command);
4002 string arg = strip(frontStrip(split(line, cmd, ' ')));
4004 Dispatch(lyxaction.LookupFunc(cmd.c_str()), arg.c_str());
4007 void Buffer::Dispatch(int action, const string & argument)
4011 MenuExport(this, argument);
4016 lyxerr << "A truly unknown func!" << endl;