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;
105 extern void MenuExport(Buffer *, string const &);
106 extern LyXAction lyxaction;
109 static const float LYX_FORMAT = 2.15;
111 extern int tex_code_break_column;
113 extern void FreeUpdateTimer();
116 Buffer::Buffer(string const & file, LyXRC * lyxrc, bool ronly)
118 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
120 filepath = OnlyPath(file);
124 dvi_clean_orgd = false; // Heinrich Bauer, 23/03/98
125 dvi_clean_tmpd = false; // Heinrich Bauer, 23/03/98
130 if (read_only || (lyxrc && lyxrc->use_tempdir)) {
131 tmppath = CreateBufferTmpDir();
132 } else tmppath.clear();
138 lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
139 // here the buffer should take care that it is
140 // saved properly, before it goes into the void.
142 // make sure that views using this buffer
147 if (!tmppath.empty()) {
148 DestroyBufferTmpDir(tmppath);
151 LyXParagraph * par = paragraph;
152 LyXParagraph * tmppar;
162 bool Buffer::saveParamsAsDefaults()
164 string fname = AddName(AddPath(user_lyxdir, "templates/"),
166 Buffer defaults = Buffer(fname);
168 // Use the current buffer's parameters as default
169 defaults.params = params;
171 // add an empty paragraph. Is this enough?
172 defaults.paragraph = new LyXParagraph;
174 return defaults.writeFile(defaults.filename, false);
178 /// Update window titles of all users
179 // Should work on a list
180 void Buffer::updateTitles()
182 if (users) users->owner()->updateWindowTitle();
186 /// Reset autosave timer of all users
187 // Should work on a list
188 void Buffer::resetAutosaveTimers()
190 if (users) users->owner()->resetAutosaveTimer();
194 void Buffer::fileName(string const & newfile)
196 filename = MakeAbsPath(newfile);
197 filepath = OnlyPath(filename);
198 setReadonly(IsFileWriteable(filename) == 0);
203 // Inserts a file into current document
204 bool BufferView::insertLyXFile(string const & filen)
206 // (c) CHT Software Service GmbH
209 // Insert a Lyxformat - file into current buffer
211 // Moved from lyx_cb.C (Lgb)
213 if (filen.empty()) return false;
215 string fname = MakeAbsPath(filen);
217 // check if file exist
220 if (!fi.readable()) {
221 WriteAlert(_("Error!"),
222 _("Specified file is unreadable: "),
223 MakeDisplayPath(fname, 50));
229 ifstream ifs(fname.c_str());
231 WriteAlert(_("Error!"),
232 _("Cannot open specified file: "),
233 MakeDisplayPath(fname, 50));
244 lyxerr.debug() << "Will insert file with header" << endl;
245 res = buffer()->readFile(lex, text->cursor.par);
247 lyxerr.debug() << "Will insert file without header" << endl;
248 res = buffer()->readLyXformat2(lex, text->cursor.par);
256 // candidate for move to BufferView
257 // (at least some parts in the beginning of the func)
260 // changed to be public and have one parameter
261 // if par = 0 normal behavior
262 // else insert behavior
263 // Returns false if "\the_end" is not read for formats >= 2.13. (Asger)
264 bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par)
270 char depth = 0; // signed or unsigned?
271 LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
272 LyXParagraph::footnote_kind footnotekind = LyXParagraph::FOOTNOTE;
273 bool the_end_read = false;
275 LyXParagraph * return_par = 0;
276 LyXFont font = LyXFont(LyXFont::ALL_INHERIT);
278 // If we are inserting, we cheat and get a token in advance
279 bool has_token = false;
283 par = new LyXParagraph;
285 users->text->BreakParagraph();
286 return_par = users->text->FirstParagraph();
289 // We don't want to adopt the parameters from the
290 // document we insert, so we skip until the text begins:
293 pretoken = lex.GetString();
294 if (pretoken == "\\layout") {
306 pretoken = lex.GetString();
309 // Profiling show this should give a lot: (Asger)
310 string const token = pretoken;
314 else if (token[0] != '\\') {
315 int n = token.length();
316 for (int i = 0; i < n; ++i) {
317 par->InsertChar(pos, token[i]);
318 par->SetFont(pos, font);
321 } else if (token == "\\i") {
322 inset = new InsetLatexAccent;
324 par->InsertChar(pos, LyXParagraph::META_INSET);
326 par->InsertInset(pos, inset);
327 par->SetFont(pos, font);
329 } else if (token == "\\layout") {
333 par->text.resize(par->text.size());
334 par = new LyXParagraph(par);
338 string layoutname = lex.GetString();
339 pair<bool, LyXTextClass::LayoutList::size_type> pp
340 = textclasslist.NumberOfLayout(params.textclass,
343 par->layout = pp.second;
344 } else { // layout not found
345 // use default layout "Standard" (0)
348 // Test whether the layout is obsolete.
349 LyXLayout const & layout = textclasslist.Style(params.textclass,
351 if (!layout.obsoleted_by().empty())
353 textclasslist.NumberOfLayout(params.textclass,
354 layout.obsoleted_by()).second;
355 par->footnoteflag = footnoteflag;
356 par->footnotekind = footnotekind;
358 font = LyXFont(LyXFont::ALL_INHERIT);
359 } else if (token == "\\end_float") {
363 par->text.resize(par->text.size());
364 par = new LyXParagraph(par);
366 footnotekind = LyXParagraph::FOOTNOTE;
367 footnoteflag = LyXParagraph::NO_FOOTNOTE;
370 par->layout = LYX_DUMMY_LAYOUT;
371 font = LyXFont(LyXFont::ALL_INHERIT);
372 } else if (token == "\\begin_float") {
373 tmpret = lex.FindToken(string_footnotekinds);
374 if (tmpret == -1) ++tmpret;
375 if (tmpret != LYX_LAYOUT_DEFAULT)
376 footnotekind = static_cast<LyXParagraph::footnote_kind>(tmpret); // bad
377 if (footnotekind == LyXParagraph::FOOTNOTE
378 || footnotekind == LyXParagraph::MARGIN)
379 footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
381 footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
382 } else if (token == "\\begin_deeper") {
384 } else if (token == "\\end_deeper") {
386 lex.printError("\\end_deeper: "
387 "depth is already null");
391 } else if (token == "\\begin_preamble") {
392 params.readPreamble(lex);
393 } else if (token == "\\textclass") {
395 pair<bool, LyXTextClassList::size_type> pp =
396 textclasslist.NumberOfClass(lex.GetString());
398 params.textclass = pp.second;
400 lex.printError("Unknown textclass `$$Token'");
401 params.textclass = 0;
403 if (!textclasslist.Load(params.textclass)) {
404 // if the textclass wasn't loaded properly
405 // we need to either substitute another
406 // or stop loading the file.
407 // I can substitute but I don't see how I can
408 // stop loading... ideas?? ARRae980418
409 WriteAlert(_("Textclass Loading Error!"),
410 string(_("Can't load textclass ")) +
411 textclasslist.NameOfClass(params.textclass),
412 _("-- substituting default"));
413 params.textclass = 0;
415 } else if (token == "\\options") {
417 params.options = lex.GetString();
418 } else if (token == "\\language") {
419 params.readLanguage(lex);
420 } else if (token == "\\fontencoding") {
422 } else if (token == "\\inputencoding") {
424 params.inputenc = lex.GetString();
425 } else if (token == "\\graphics") {
426 params.readGraphicsDriver(lex);
427 } else if (token == "\\fontscheme") {
429 params.fonts = lex.GetString();
430 } else if (token == "\\noindent") {
431 par->noindent = true;
432 } else if (token == "\\fill_top") {
433 par->added_space_top = VSpace(VSpace::VFILL);
434 } else if (token == "\\fill_bottom") {
435 par->added_space_bottom = VSpace(VSpace::VFILL);
436 } else if (token == "\\line_top") {
437 par->line_top = true;
438 } else if (token == "\\line_bottom") {
439 par->line_bottom = true;
440 } else if (token == "\\pagebreak_top") {
441 par->pagebreak_top = true;
442 } else if (token == "\\pagebreak_bottom") {
443 par->pagebreak_bottom = true;
444 } else if (token == "\\start_of_appendix") {
445 par->start_of_appendix = true;
446 } else if (token == "\\paragraph_separation") {
447 tmpret = lex.FindToken(string_paragraph_separation);
448 if (tmpret == -1) tmpret++;
449 if (tmpret != LYX_LAYOUT_DEFAULT)
450 params.paragraph_separation =
451 static_cast<BufferParams::PARSEP>(tmpret);
452 } else if (token == "\\defskip") {
454 params.defskip = VSpace(lex.GetString());
455 } else if (token == "\\no_isolatin1") { // obsolete
457 } else if (token == "\\no_babel") { // obsolete
459 } else if (token == "\\no_epsfig") { // obsolete
461 } else if (token == "\\epsfig") { // obsolete
462 // Indeed it is obsolete, but we HAVE to be backwards
463 // compatible until 0.14, because otherwise all figures
464 // in existing documents are irretrivably lost. (Asger)
465 params.readGraphicsDriver(lex);
466 } else if (token == "\\quotes_language") {
467 tmpret = lex.FindToken(string_quotes_language);
468 if (tmpret == -1) tmpret++;
469 if (tmpret != LYX_LAYOUT_DEFAULT) {
470 InsetQuotes::quote_language tmpl =
471 InsetQuotes::EnglishQ;
474 tmpl = InsetQuotes::EnglishQ;
477 tmpl = InsetQuotes::SwedishQ;
480 tmpl = InsetQuotes::GermanQ;
483 tmpl = InsetQuotes::PolishQ;
486 tmpl = InsetQuotes::FrenchQ;
489 tmpl = InsetQuotes::DanishQ;
492 params.quotes_language = tmpl;
494 } else if (token == "\\quotes_times") {
496 switch(lex.GetInteger()) {
498 params.quotes_times = InsetQuotes::SingleQ;
501 params.quotes_times = InsetQuotes::DoubleQ;
504 } else if (token == "\\papersize") {
508 tmpret = lex.FindToken(string_papersize);
511 tmpret = lex.FindToken(string_oldpapersize);
516 params.papersize2 = tmpret;
517 } else if (token == "\\paperpackage") {
518 tmpret = lex.FindToken(string_paperpackages);
521 params.paperpackage = BufferParams::PACKAGE_NONE;
523 params.paperpackage = tmpret;
524 } else if (token == "\\use_geometry") {
526 params.use_geometry = lex.GetInteger();
527 } else if (token == "\\use_amsmath") {
529 params.use_amsmath = lex.GetInteger();
530 } else if (token == "\\paperorientation") {
531 tmpret = lex.FindToken(string_orientation);
532 if (tmpret == -1) tmpret++;
533 if (tmpret != LYX_LAYOUT_DEFAULT)
534 params.orientation = static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
535 } else if (token == "\\paperwidth") {
537 params.paperwidth = lex.GetString();
538 } else if (token == "\\paperheight") {
540 params.paperheight = lex.GetString();
541 } else if (token == "\\leftmargin") {
543 params.leftmargin = lex.GetString();
544 } else if (token == "\\topmargin") {
546 params.topmargin = lex.GetString();
547 } else if (token == "\\rightmargin") {
549 params.rightmargin = lex.GetString();
550 } else if (token == "\\bottommargin") {
552 params.bottommargin = lex.GetString();
553 } else if (token == "\\headheight") {
555 params.headheight = lex.GetString();
556 } else if (token == "\\headsep") {
558 params.headsep = lex.GetString();
559 } else if (token == "\\footskip") {
561 params.footskip = lex.GetString();
562 } else if (token == "\\paperfontsize") {
564 params.fontsize = strip(lex.GetString());
565 } else if (token == "\\papercolumns") {
567 params.columns = lex.GetInteger();
568 } else if (token == "\\papersides") {
570 switch(lex.GetInteger()) {
572 case 1: params.sides = LyXTextClass::OneSide; break;
573 case 2: params.sides = LyXTextClass::TwoSides; break;
575 } else if (token == "\\paperpagestyle") {
577 params.pagestyle = strip(lex.GetString());
578 } else if (token == "\\bullet") {
580 int index = lex.GetInteger();
582 int temp_int = lex.GetInteger();
583 params.user_defined_bullets[index].setFont(temp_int);
584 params.temp_bullets[index].setFont(temp_int);
586 temp_int = lex.GetInteger();
587 params.user_defined_bullets[index].setCharacter(temp_int);
588 params.temp_bullets[index].setCharacter(temp_int);
590 temp_int = lex.GetInteger();
591 params.user_defined_bullets[index].setSize(temp_int);
592 params.temp_bullets[index].setSize(temp_int);
594 string temp_str = lex.GetString();
595 if (temp_str != "\\end_bullet") {
596 // this element isn't really necessary for
597 // parsing but is easier for humans
598 // to understand bullets. Put it back and
599 // set a debug message?
600 lex.printError("\\end_bullet expected, got" + temp_str);
601 //how can I put it back?
603 } else if (token == "\\bulletLaTeX") {
605 int index = lex.GetInteger();
607 string temp_str = lex.GetString(), sum_str;
608 while (temp_str != "\\end_bullet") {
609 // this loop structure is needed when user
610 // enters an empty string since the first
611 // thing returned will be the \\end_bullet
613 // if the LaTeX entry has spaces. Each element
614 // therefore needs to be read in turn
617 temp_str = lex.GetString();
619 params.user_defined_bullets[index].setText(sum_str);
620 params.temp_bullets[index].setText(sum_str);
621 } else if (token == "\\secnumdepth") {
623 params.secnumdepth = lex.GetInteger();
624 } else if (token == "\\tocdepth") {
626 params.tocdepth = lex.GetInteger();
627 } else if (token == "\\baselinestretch") { // obsolete
628 lex.nextToken(); // should not be used directly
630 // Will probably keep a kind of support just for
632 params.spacing.set(Spacing::Other, lex.GetFloat());
633 } else if (token == "\\spacing") {
635 string tmp = strip(lex.GetString());
636 if (tmp == "single") {
637 params.spacing.set(Spacing::Single);
638 } else if (tmp == "onehalf") {
639 params.spacing.set(Spacing::Onehalf);
640 } else if (tmp == "double") {
641 params.spacing.set(Spacing::Double);
642 } else if (tmp == "other") {
644 params.spacing.set(Spacing::Other,
647 lex.printError("Unknown spacing token: '$$Token'");
649 } else if (token == "\\float_placement") {
651 params.float_placement = lex.GetString();
652 } else if (token == "\\cursor") { // obsolete
653 // this is obsolete, so we just skip it.
655 } else if (token == "\\family") {
657 font.setLyXFamily(lex.GetString());
658 } else if (token == "\\series") {
660 font.setLyXSeries(lex.GetString());
661 } else if (token == "\\shape") {
663 font.setLyXShape(lex.GetString());
664 } else if (token == "\\size") {
666 font.setLyXSize(lex.GetString());
667 } else if (token == "\\latex") {
669 string tok = lex.GetString();
670 // This is dirty, but gone with LyX3. (Asger)
671 if (tok == "no_latex")
672 font.setLatex(LyXFont::OFF);
673 else if (tok == "latex")
674 font.setLatex(LyXFont::ON);
675 else if (tok == "default")
676 font.setLatex(LyXFont::INHERIT);
678 lex.printError("Unknown LaTeX font flag "
680 } else if (token == "\\emph") {
682 font.setEmph(font.setLyXMisc(lex.GetString()));
683 } else if (token == "\\bar") {
685 string tok = lex.GetString();
686 // This is dirty, but gone with LyX3. (Asger)
688 font.setUnderbar(LyXFont::ON);
689 else if (tok == "no")
690 font.setUnderbar(LyXFont::OFF);
691 else if (tok == "default")
692 font.setUnderbar(LyXFont::INHERIT);
694 lex.printError("Unknown bar font flag "
696 } else if (token == "\\noun") {
698 font.setNoun(font.setLyXMisc(lex.GetString()));
699 } else if (token == "\\color") {
701 font.setLyXColor(lex.GetString());
702 } else if (token == "\\align") {
703 tmpret = lex.FindToken(string_align);
704 if (tmpret == -1) tmpret++;
705 if (tmpret != LYX_LAYOUT_DEFAULT) { // tmpret != 99 ???
707 for (; tmpret > 0; --tmpret)
708 tmpret2 = tmpret2 * 2;
709 par->align = LyXAlignment(tmpret2);
711 } else if (token == "\\added_space_top") {
713 par->added_space_top = lex.GetString();
714 } else if (token == "\\added_space_bottom") {
716 par->added_space_bottom = lex.GetString();
717 } else if (token == "\\pextra_type") {
719 par->pextra_type = lex.GetInteger();
720 } else if (token == "\\pextra_width") {
722 par->pextra_width = lex.GetString();
723 } else if (token == "\\pextra_widthp") {
725 par->pextra_widthp = lex.GetString();
726 } else if (token == "\\pextra_alignment") {
728 par->pextra_alignment = lex.GetInteger();
729 } else if (token == "\\pextra_hfill") {
731 par->pextra_hfill = lex.GetInteger();
732 } else if (token == "\\pextra_start_minipage") {
734 par->pextra_start_minipage = lex.GetInteger();
735 } else if (token == "\\labelwidthstring") {
737 par->labelwidthstring = lex.GetString();
738 /* do not delete this token, it is still needed! */
739 } else if (token == "\\end_inset") {
740 /* simple ignore this. The insets do not have
742 // but insets should read it, it is a part of
743 //the inset isn't it? Lgb.
744 } else if (token == "\\begin_inset") {
746 tmptok = lex.GetString();
747 /* test the different insets */
748 if (tmptok == "Quotes") {
749 inset = new InsetQuotes;
751 par->InsertChar(pos, LyXParagraph::META_INSET);
752 par->InsertInset(pos, inset);
753 par->SetFont(pos, font);
755 #if 0 // should not be used any more
756 } else if (tmptok == "Latex") {
757 // This one is on its way out
759 tmptok = strip(lex.GetString());
760 //lyxerr <<string(tmptok[0]));
761 if (tmptok[0] == '\\') {
762 // then this latex is a
764 InsetCommand *tmpinset =
766 tmpinset->scanCommand(tmptok);
769 // This should not use InsetLaTexDel
770 // it should rather insert text into
771 // the paragraph and mark it as tex.
772 inset = new InsetLatex(tmptok);
774 par->InsertChar(pos, LyXParagraph::META_INSET);
775 par->InsertInset(pos, inset);
776 par->SetFont(pos, font);
779 #if 0 // should not be used any more
780 } else if (tmptok == "LatexDel") {
781 // This one is on its way out...
783 tmptok = strip(lex.GetString());
784 //lyxerr <<string(tmptok[0]));
785 if (tmptok == "\\tableofcontents") {
786 inset = new InsetTOC(this);
787 } else if (tmptok == "\\listoffigures") {
788 inset = new InsetLOF(this);
789 } else if (tmptok == "\\listoftables") {
790 inset = new InsetLOT(this);
791 } else if (tmptok == "\\listofalgorithms") {
792 inset = new InsetLOA(this);
793 } else if (contains(tmptok, "\\ref{")
794 || contains(tmptok, "\\pageref{")) {
795 inset = new InsetRef(tmptok, this);
796 } else if (contains(tmptok, "\\url{")
797 || contains(tmptok, "\\htmlurl{")) {
798 string cont, opt, tmptmptok, cmdname;
800 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
805 tmptmptok = lex.GetString();
806 if(tmptmptok[0] == '\\') {
807 if( tmptmptok == "\\backslash")
817 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
822 tmptmptok = lex.GetString();
823 if(tmptmptok[0] == '\\') {
824 if( tmptmptok == "\\backslash")
834 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
837 if(contains(tmptok, "\\url{"))
838 cmdname = string("url");
840 cmdname = string("htmlurl");
843 inset = new InsetUrl(cmdname, cont, opt);
844 } else if (tmptok[0] == '\\') {
845 // then this latex del is a
847 InsetCommand * tmpinset =
849 tmpinset->scanCommand(tmptok);
852 par->InsertChar(pos, LyXParagraph::META_INSET);
853 par->InsertInset(pos, inset);
854 par->SetFont(pos, font);
857 } else if (tmptok == "\\i") {
858 inset = new InsetLatexAccent;
860 par->InsertChar(pos, LyXParagraph::META_INSET);
861 par->InsertInset(pos, inset);
862 par->SetFont(pos, font);
864 } else if (tmptok == "FormulaMacro") {
865 inset = new InsetFormulaMacro;
867 par->InsertChar(pos, LyXParagraph::META_INSET);
868 par->InsertInset(pos, inset);
869 par->SetFont(pos, font);
871 } else if (tmptok == "Formula") {
872 inset = new InsetFormula;
874 par->InsertChar(pos, LyXParagraph::META_INSET);
875 par->InsertInset(pos, inset);
876 par->SetFont(pos, font);
878 } else if (tmptok == "Figure") {
879 inset = new InsetFig(100, 100, this);
881 par->InsertChar(pos, LyXParagraph::META_INSET);
882 par->InsertInset(pos, inset);
883 par->SetFont(pos, font);
886 } else if (tmptok == "Label") {
887 // Kept for compability. Remove in 0.13.
889 string tmp = "\\label{";
890 tmp += lex.GetString();
892 inset = new InsetLabel(tmp);
893 par->InsertChar(pos, LyXParagraph::META_INSET);
894 par->InsertInset(pos, inset);
895 par->SetFont(pos, font);
899 } else if (tmptok == "Info") {
900 inset = new InsetInfo;
902 par->InsertChar(pos, LyXParagraph::META_INSET);
903 par->InsertInset(pos, inset);
904 par->SetFont(pos, font);
906 } else if (tmptok == "Include") {
907 inset = new InsetInclude(string(), this);
909 par->InsertChar(pos, LyXParagraph::META_INSET);
910 par->InsertInset(pos, inset);
911 par->SetFont(pos, font);
913 } else if (tmptok == "LatexCommand") {
916 if (inscmd.getCmdName() == "cite") {
917 inset = new InsetCitation(inscmd.getContents(), inscmd.getOptions());
918 } else if (inscmd.getCmdName() == "bibitem") {
919 lex.printError("Wrong place for bibitem");
920 inset = inscmd.Clone();
921 } else if (inscmd.getCmdName() == "BibTeX") {
922 inset = new InsetBibtex(inscmd.getContents(), inscmd.getOptions(), this);
923 } else if (inscmd.getCmdName() == "index") {
924 inset = new InsetIndex(inscmd.getContents());
925 } else if (inscmd.getCmdName() == "include") {
926 inset = new InsetInclude(inscmd.getContents(), this);
927 } else if (inscmd.getCmdName() == "label") {
928 inset = new InsetLabel(inscmd.getCommand());
929 } else if (inscmd.getCmdName() == "url"
930 || inscmd.getCmdName() == "htmlurl") {
931 inset = new InsetUrl(inscmd.getCommand());
932 } else if (inscmd.getCmdName() == "ref"
933 || inscmd.getCmdName() == "pageref") {
934 if (!inscmd.getOptions().empty() || !inscmd.getContents().empty()) {
935 inset = new InsetRef(inscmd, this);
937 // This condition comes from a
938 // temporary solution to the latexdel
939 // ref inset that was transformed to
940 // an empty ref inset plus the body
941 // surronded by latexdel insets
943 string cont, opt, tmptmptok, cmdname;
945 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
950 tmptmptok = lex.GetString();
951 if(tmptmptok[0] == '\\') {
952 if( tmptmptok == "\\backslash")
962 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
967 tmptmptok = lex.GetString();
968 if(tmptmptok[0] == '\\') {
969 if( tmptmptok == "\\backslash")
979 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
985 cmdname = "\\" + inscmd.getCmdName();
986 cmdname += "[" + cont + "]";
987 cmdname += "{" + opt + "}";
988 inset = new InsetRef(cmdname, this);
990 } else if (inscmd.getCmdName() == "tableofcontents") {
991 inset = new InsetTOC(this);
992 } else if (inscmd.getCmdName() == "listoffigures") {
993 inset = new InsetLOF(this);
994 } else if (inscmd.getCmdName() == "listofalgorithms") {
995 inset = new InsetLOA(this);
996 } else if (inscmd.getCmdName() == "listoftables") {
997 inset = new InsetLOT(this);
998 } else if (inscmd.getCmdName() == "printindex") {
999 inset = new InsetPrintIndex(this);
1000 } else if (inscmd.getCmdName() == "lyxparent") {
1001 inset = new InsetParent(inscmd.getContents(), this);
1004 // Do we need this at all now?
1006 // The following three are only for compatibility
1007 if (inscmd.getCmdName() == "-") {
1008 inset = new InsetSpecialChar(InsetSpecialChar::HYPHENATION);
1009 } else if (inscmd.getCmdName() == "@.") {
1010 inset = new InsetSpecialChar(InsetSpecialChar::END_OF_SENTENCE);
1011 } else if (inscmd.getCmdName() == "ldots") {
1012 inset = new InsetSpecialChar(InsetSpecialChar::LDOTS);
1014 inset = inscmd.Clone();
1018 par->InsertChar(pos, LyXParagraph::META_INSET);
1019 par->InsertInset(pos, inset);
1020 par->SetFont(pos, font);
1024 } else if (token == "\\InsetQuotes") {
1025 inset = new InsetQuotes;
1027 par->InsertChar(pos, LyXParagraph::META_INSET);
1028 par->InsertInset(pos, inset);
1029 par->SetFont(pos, font);
1032 } else if (token == "\\InsetLatex") {
1033 inset = new InsetLatex;
1035 par->InsertChar(pos, LyXParagraph::META_INSET);
1036 par->InsertInset(pos, inset);
1037 par->SetFont(pos, font);
1039 } else if (token == "\\InsetLatexDel") {
1040 lex.printError(_("Warning: Ignoring Old Inset"));
1042 } else if (token == "\\InsetFormula") {
1043 inset = new InsetFormula;
1045 par->InsertChar(pos, LyXParagraph::META_INSET);
1046 par->InsertInset(pos, inset);
1047 par->SetFont(pos, font);
1049 } else if (token == "\\SpecialChar") {
1050 inset = new InsetSpecialChar;
1052 par->InsertChar(pos, LyXParagraph::META_INSET);
1053 par->InsertInset(pos, inset);
1054 par->SetFont(pos, font);
1056 } else if (token == "\\Figure") {
1057 inset = new InsetFig(100, 100, this);
1059 par->InsertChar(pos, LyXParagraph::META_INSET);
1060 par->InsertInset(pos, inset);
1061 par->SetFont(pos, font);
1063 } else if (token == "\\newline") {
1064 par->InsertChar(pos, LyXParagraph::META_NEWLINE);
1065 par->SetFont(pos, font);
1067 } else if (token == "\\LyXTable") {
1068 par->table = new LyXTable(lex);
1069 } else if (token == "\\hfill") {
1070 par->InsertChar(pos, LyXParagraph::META_HFILL);
1071 par->SetFont(pos, font);
1073 } else if (token == "\\protected_separator") {
1074 par->InsertChar(pos, LyXParagraph::META_PROTECTED_SEPARATOR);
1075 par->SetFont(pos, font);
1077 } else if (token == "\\bibitem") { // ale970302
1079 par->bibkey = new InsetBibKey;
1080 par->bibkey->Read(lex);
1081 }else if (token == "\\backslash") {
1082 par->InsertChar(pos, '\\');
1083 par->SetFont(pos, font);
1085 }else if (token == "\\the_end") {
1086 the_end_read = true;
1088 // This should be insurance for the future: (Asger)
1089 lex.printError("Unknown token `$$Token'. "
1090 "Inserting as text.");
1091 int n = token.length();
1092 for (int i = 0; i < n; ++i) {
1093 par->InsertChar(pos, token[i]);
1094 par->SetFont(pos, font);
1103 paragraph = return_par;
1105 return the_end_read;
1109 bool Buffer::readFile(LyXLex & lex, LyXParagraph * par)
1115 token = lex.GetString();
1116 if (token == "\\lyxformat") { // the first token _must_ be...
1118 format = lex.GetFloat();
1120 if (LYX_FORMAT - format > 0.05) {
1121 printf(_("Warning: need lyxformat %.2f but found %.2f\n"),
1122 LYX_FORMAT, format);
1124 if (format - LYX_FORMAT > 0.05) {
1125 printf(_("ERROR: need lyxformat %.2f but found %.2f\n"),
1126 LYX_FORMAT, format);
1128 bool the_end = readLyXformat2(lex, par);
1129 // Formats >= 2.13 support "\the_end" marker
1133 // Formats >= 2.14 changed papersize stuff
1134 if (format < 2.14) {
1143 WriteAlert(_("Warning!"),
1144 _("Reading of document is not complete"),
1145 _("Maybe the document is truncated"));
1146 // We simulate a safe reading anyways to allow
1147 // users to take the chance... (Asger)
1151 WriteAlert(_("ERROR!"),
1152 _("Old LyX file format found. "
1153 "Use LyX 0.10.x to read this!"));
1157 } else { // "\\lyxformat" not found
1158 WriteAlert(_("ERROR!"), _("Not a LyX file!"));
1161 WriteAlert(_("ERROR!"), _("Unable to read file!"));
1166 // Returns false if unsuccesful
1167 bool Buffer::writeFile(string const & fname, bool flag)
1169 // if flag is false writeFile will not create any GUI
1170 // warnings, only cerr.
1171 // Needed for autosave in background or panic save (Matthias 120496)
1173 if (read_only && (fname == filename)) {
1174 // Here we should come with a question if we should
1175 // perform the write anyway.
1177 lyxerr << _("Error! Document is read-only: ")
1180 WriteAlert(_("Error! Document is read-only: "),
1185 FileInfo finfo(fname);
1186 if (finfo.exist() && !finfo.writable()) {
1187 // Here we should come with a question if we should
1188 // try to do the save anyway. (i.e. do a chmod first)
1190 lyxerr << _("Error! Cannot write file: ")
1193 WriteFSAlert(_("Error! Cannot write file: "),
1198 ofstream ofs(fname.c_str());
1201 lyxerr << _("Error! Cannot open file: ")
1204 WriteFSAlert(_("Error! Cannot open file: "),
1208 // The top of the file should not be written by params.
1210 // write out a comment in the top of the file
1211 ofs << '#' << LYX_DOCVERSION
1212 << " created this file. For more info see http://www.lyx.org/\n";
1213 ofs.setf(ios::showpoint|ios::fixed);
1215 ofs << "\\lyxformat " << setw(4) << LYX_FORMAT << "\n";
1217 // now write out the buffer paramters.
1218 params.writeFile(ofs);
1220 char footnoteflag = 0;
1223 // this will write out all the paragraphs
1224 // using recursive descent.
1225 paragraph->writeFile(ofs, params, footnoteflag, depth);
1227 // Write marker that shows file is complete
1228 ofs << "\n\\the_end" << endl;
1230 // how to check if close went ok?
1235 void Buffer::writeFileAscii(string const & fname, int linelen)
1237 LyXFont font1, font2;
1239 char c, footnoteflag = 0, depth = 0;
1241 LyXParagraph::size_type i;
1242 int j, h, ltype = 0, ltype_depth = 0,
1243 * clen = 0, actcell = 0, actpos = 0, cell = 0, cells = 0,
1246 bool ref_printed = false;
1248 ofstream ofs(fname.c_str());
1250 WriteFSAlert(_("Error: Cannot write file:"), fname);
1254 string fname1 = TmpFileName();
1255 LyXParagraph * par = paragraph;
1259 if (par->footnoteflag != LyXParagraph::NO_FOOTNOTE ||
1261 par->previous->footnoteflag == LyXParagraph::NO_FOOTNOTE){
1263 /* begins a footnote environment ? */
1264 if (footnoteflag != par->footnoteflag) {
1265 footnoteflag = par->footnoteflag;
1267 j = strlen(string_footnotekinds[par->footnotekind])+4;
1268 if (currlinelen + j > linelen)
1271 << string_footnotekinds[par->footnotekind] << "] ";
1276 /* begins or ends a deeper area ?*/
1277 if (depth != par->depth) {
1278 if (par->depth > depth) {
1279 while (par->depth > depth) {
1284 while (par->depth < depth) {
1290 /* First write the layout */
1291 tmp = textclasslist.NameOfLayout(params.textclass, par->layout);
1292 if (tmp == "Itemize") {
1294 ltype_depth = depth+1;
1295 } else if (tmp == "Enumerate") {
1297 ltype_depth = depth+1;
1298 } else if (strstr(tmp.c_str(), "ection")) {
1300 ltype_depth = depth+1;
1301 } else if (strstr(tmp.c_str(), "aragraph")) {
1303 ltype_depth = depth+1;
1304 } else if (tmp == "Description") {
1306 ltype_depth = depth+1;
1307 } else if (tmp == "Abstract") {
1310 } else if (tmp == "Bibliography") {
1318 /* maybe some vertical spaces */
1320 /* the labelwidthstring used in lists */
1324 /* some pagebreaks? */
1328 /* what about the alignment */
1331 /* dummy layout, that means a footnote ended */
1332 footnoteflag = LyXParagraph::NO_FOOTNOTE;
1337 /* It might be a table */
1340 if (!lyxrc->ascii_roff_command.empty() &&
1341 lyxrc->ascii_roff_command != "none") {
1342 RoffAsciiTable(ofs, par);
1349 cells = par->table->columns;
1350 clen = new int [cells];
1351 memset(clen, 0, sizeof(int) * cells);
1352 for (i = 0, j = 0, h = 1; i < par->size(); ++i, ++h) {
1353 c = par->GetChar(i);
1354 if (c == LyXParagraph::META_INSET) {
1355 if ((inset = par->GetInset(i))) {
1356 ofstream fs(fname1.c_str());
1358 WriteFSAlert(_("Error: Cannot open temporary file:"), fname1);
1361 inset->Latex(fs, -1);
1362 h += fs.tellp() - 1;
1363 remove(fname1.c_str());
1365 } else if (c == LyXParagraph::META_NEWLINE) {
1369 j = (++j) % par->table->NumberOfCellsInRow(actcell);
1377 font1 = LyXFont(LyXFont::ALL_INHERIT);
1379 for (i = 0, actpos = 1; i < par->size(); ++i, ++actpos) {
1380 if (!i && !footnoteflag && !noparbreak){
1382 for(j = 0; j < depth; ++j)
1384 currlinelen = depth * 2;
1386 case 0: /* Standart */
1387 case 4: /* (Sub)Paragraph */
1388 case 5: /* Description */
1390 case 6: /* Abstract */
1391 ofs << "Abstract\n\n";
1393 case 7: /* Bibliography */
1395 ofs << "References\n\n";
1400 ofs << par->labelstring << " ";
1403 if (ltype_depth > depth) {
1404 for(j = ltype_depth - 1; j > depth; --j)
1406 currlinelen += (ltype_depth-depth)*2;
1409 for(j = 0; j < cells; ++j) {
1411 for(h = 0; h < (clen[j] + 1);
1416 for(j = 0; j < depth; ++j)
1418 currlinelen = depth * 2;
1419 if (ltype_depth > depth) {
1420 for(j = ltype_depth;
1423 currlinelen += (ltype_depth-depth)*2;
1428 font2 = par->GetFontSettings(i);
1429 if (font1.latex() != font2.latex()) {
1430 if (font2.latex() == LyXFont::OFF)
1438 c = par->GetChar(i);
1442 case LyXParagraph::META_INSET:
1443 if ((inset = par->GetInset(i))) {
1445 inset->Latex(ofs, -1);
1446 currlinelen += (ofs.tellp() - fpos);
1447 actpos += (ofs.tellp() - fpos) - 1;
1450 case LyXParagraph::META_NEWLINE:
1452 if (par->table->NumberOfCellsInRow(actcell) <= cell) {
1453 for(j = actpos; j < clen[cell-1];j++)
1456 for(j = 0; j < depth; ++j)
1458 currlinelen = depth*2;
1459 if (ltype_depth > depth) {
1460 for(j = ltype_depth; j > depth; --j)
1462 currlinelen += (ltype_depth-depth) * 2;
1464 for(j = 0; j < cells; ++j) {
1466 for(h = 0; h < (clen[j] + 1); ++h)
1470 for(j = 0; j < depth; ++j)
1472 currlinelen = depth * 2;
1473 if (ltype_depth > depth) {
1474 for(j = ltype_depth;
1477 currlinelen += (ltype_depth-depth)*2;
1483 j < clen[cell - 1]; ++j)
1489 currlinelen = actpos = 0;
1492 for(j = 0; j < depth; ++j)
1494 currlinelen = depth * 2;
1495 if (ltype_depth > depth) {
1496 for(j = ltype_depth;
1499 currlinelen += (ltype_depth - depth) * 2;
1503 case LyXParagraph::META_HFILL:
1506 case LyXParagraph::META_PROTECTED_SEPARATOR:
1513 if (currlinelen > linelen - 10
1514 && c == ' ' && i + 2 < par->size()) {
1516 for(j = 0; j < depth; ++j)
1518 currlinelen = depth * 2;
1519 if (ltype_depth > depth) {
1520 for(j = ltype_depth;
1523 currlinelen += (ltype_depth-depth)*2;
1525 } else if (c != '\0')
1528 lyxerr.debug() << "writeAsciiFile: NULL char in structure." << endl;
1534 for(j = actpos; j < clen[cell - 1]; ++j)
1537 for(j = 0; j < depth; ++j)
1539 currlinelen = depth * 2;
1540 if (ltype_depth > depth) {
1541 for(j = ltype_depth; j > depth; --j)
1543 currlinelen += (ltype_depth - depth) * 2;
1545 for(j = 0; j < cells; ++j) {
1547 for(h = 0; h < (clen[j] + 1); ++h)
1560 void Buffer::makeLaTeXFile(string const & fname,
1561 string const & original_path,
1562 bool nice, bool only_body)
1564 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
1566 // How the **** can this be needed?
1567 //params.textclass = current_view->buffer()->params.textclass;
1569 niceFile = nice; // this will be used by Insetincludes.
1571 tex_code_break_column = lyxrc->ascii_linelen;
1573 LyXTextClass const & tclass =
1574 textclasslist.TextClass(params.textclass);
1576 ofstream ofs(fname.c_str());
1578 WriteFSAlert(_("Error: Cannot open file: "), fname);
1582 // validate the buffer.
1583 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
1584 LaTeXFeatures features(tclass.numLayouts());
1586 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
1589 // The starting paragraph of the coming rows is the
1590 // first paragraph of the document. (Asger)
1591 texrow.start(paragraph, 0);
1595 if (!only_body && nice) {
1596 LFile += "%% " LYX_DOCVERSION " created this file. "
1597 "For more info, see http://www.lyx.org/.\n";
1598 LFile += "%% Do not edit unless you really know what you are doing.\n";
1602 lyxerr.debug() << "lyx header finished" << endl;
1603 // There are a few differences between nice LaTeX and usual files:
1604 // usual is \batchmode and has a
1605 // special input@path to allow the including of figures
1606 // with either \input or \includegraphics (what figinsets do).
1607 // batchmode is not set if there is a tex_code_break_column.
1608 // In this case somebody is interested in the generated LaTeX,
1609 // so this is OK. input@path is set when the actual parameter
1610 // original_path is set. This is done for usual tex-file, but not
1611 // for nice-latex-file. (Matthias 250696)
1614 // code for usual, NOT nice-latex-file
1615 LFile += "\\batchmode\n"; // changed
1616 // from \nonstopmode
1619 if (!original_path.empty()) {
1620 LFile += "\\makeatletter\n";
1622 LFile += "\\def\\input@path{{" + original_path
1625 LFile += "\\makeatother\n";
1629 LFile += "\\documentclass";
1631 string options; // the document class options.
1633 if (tokenPos(tclass.opt_fontsize(), '|', params.fontsize) >= 0) {
1634 // only write if existing in list (and not default)
1635 options += params.fontsize;
1640 if (!params.use_geometry &&
1641 (params.paperpackage == BufferParams::PACKAGE_NONE)) {
1642 switch (params.papersize) {
1643 case BufferParams::PAPER_A4PAPER:
1644 options += "a4paper,";
1646 case BufferParams::PAPER_USLETTER:
1647 options += "letterpaper,";
1649 case BufferParams::PAPER_A5PAPER:
1650 options += "a5paper,";
1652 case BufferParams::PAPER_B5PAPER:
1653 options += "b5paper,";
1655 case BufferParams::PAPER_EXECUTIVEPAPER:
1656 options += "executivepaper,";
1658 case BufferParams::PAPER_LEGALPAPER:
1659 options += "legalpaper,";
1665 if (params.sides != tclass.sides()) {
1666 if (params.sides == 2)
1667 options += "twoside,";
1669 options += "oneside,";
1673 if (params.columns != tclass.columns()) {
1674 if (params.columns == 2)
1675 options += "twocolumn,";
1677 options += "onecolumn,";
1680 if (!params.use_geometry
1681 && params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1682 options += "landscape,";
1684 // language should be a parameter to \documentclass
1685 if (params.language != "default") {
1686 options += params.language + ',';
1689 // the user-defined options
1690 if (!params.options.empty()) {
1691 options += params.options + ',';
1694 if (!options.empty()){
1695 options = strip(options, ',');
1702 LFile += textclasslist.LatexnameOfClass(params.textclass);
1705 // end of \documentclass defs
1707 // font selection must be done before loading fontenc.sty
1708 if (params.fonts != "default") {
1709 LFile += "\\usepackage{" + params.fonts + "}\n";
1712 // this one is not per buffer
1713 if (lyxrc->fontenc != "default") {
1714 LFile += "\\usepackage[" + lyxrc->fontenc
1718 if (params.inputenc != "default") {
1719 LFile += "\\usepackage[" + params.inputenc
1724 /* at the very beginning the text parameters */
1725 if (params.paperpackage != BufferParams::PACKAGE_NONE) {
1726 switch (params.paperpackage) {
1727 case BufferParams::PACKAGE_A4:
1728 LFile += "\\usepackage{a4}\n";
1731 case BufferParams::PACKAGE_A4WIDE:
1732 LFile += "\\usepackage{a4wide}\n";
1735 case BufferParams::PACKAGE_WIDEMARGINSA4:
1736 LFile += "\\usepackage[widemargins]{a4}\n";
1741 if (params.use_geometry) {
1742 LFile += "\\usepackage{geometry}\n";
1744 LFile += "\\geometry{verbose";
1745 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1746 LFile += ",landscape";
1747 switch (params.papersize2) {
1748 case BufferParams::VM_PAPER_CUSTOM:
1749 if (!params.paperwidth.empty())
1750 LFile += ",paperwidth="
1751 + params.paperwidth;
1752 if (!params.paperheight.empty())
1753 LFile += ",paperheight="
1754 + params.paperheight;
1756 case BufferParams::VM_PAPER_USLETTER:
1757 LFile += ",letterpaper";
1759 case BufferParams::VM_PAPER_USLEGAL:
1760 LFile += ",legalpaper";
1762 case BufferParams::VM_PAPER_USEXECUTIVE:
1763 LFile += ",executivepaper";
1765 case BufferParams::VM_PAPER_A3:
1766 LFile += ",a3paper";
1768 case BufferParams::VM_PAPER_A4:
1769 LFile += ",a4paper";
1771 case BufferParams::VM_PAPER_A5:
1772 LFile += ",a5paper";
1774 case BufferParams::VM_PAPER_B3:
1775 LFile += ",b3paper";
1777 case BufferParams::VM_PAPER_B4:
1778 LFile += ",b4paper";
1780 case BufferParams::VM_PAPER_B5:
1781 LFile += ",b5paper";
1784 // default papersize ie BufferParams::VM_PAPER_DEFAULT
1785 switch (lyxrc->default_papersize) {
1786 case BufferParams::PAPER_DEFAULT: // keep compiler happy
1787 case BufferParams::PAPER_USLETTER:
1788 LFile += ",letterpaper";
1790 case BufferParams::PAPER_LEGALPAPER:
1791 LFile += ",legalpaper";
1793 case BufferParams::PAPER_EXECUTIVEPAPER:
1794 LFile += ",executivepaper";
1796 case BufferParams::PAPER_A3PAPER:
1797 LFile += ",a3paper";
1799 case BufferParams::PAPER_A4PAPER:
1800 LFile += ",a4paper";
1802 case BufferParams::PAPER_A5PAPER:
1803 LFile += ",a5paper";
1805 case BufferParams::PAPER_B5PAPER:
1806 LFile += ",b5paper";
1810 if (!params.topmargin.empty())
1811 LFile += ",tmargin=" + params.topmargin;
1812 if (!params.bottommargin.empty())
1813 LFile += ",bmargin=" + params.bottommargin;
1814 if (!params.leftmargin.empty())
1815 LFile += ",lmargin=" + params.leftmargin;
1816 if (!params.rightmargin.empty())
1817 LFile += ",rmargin=" + params.rightmargin;
1818 if (!params.headheight.empty())
1819 LFile += ",headheight=" + params.headheight;
1820 if (!params.headsep.empty())
1821 LFile += ",headsep=" + params.headsep;
1822 if (!params.footskip.empty())
1823 LFile += ",footskip=" + params.footskip;
1827 if (params.use_amsmath
1828 && !prefixIs(textclasslist.LatexnameOfClass(params.textclass), "ams")) {
1829 LFile += "\\usepackage{amsmath}\n";
1832 if (tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle) >= 0) {
1833 if (params.pagestyle == "fancy") {
1834 LFile += "\\usepackage{fancyhdr}\n";
1837 LFile += "\\pagestyle{" + params.pagestyle + "}\n";
1841 // We try to load babel late, in case it interferes
1842 // with other packages.
1843 if (params.language != "default") {
1844 LFile += "\\usepackage{babel}\n";
1848 if (params.secnumdepth != tclass.secnumdepth()) {
1849 LFile += "\\setcounter{secnumdepth}{";
1850 LFile += tostr(params.secnumdepth);
1854 if (params.tocdepth != tclass.tocdepth()) {
1855 LFile += "\\setcounter{tocdepth}{";
1856 LFile += tostr(params.tocdepth);
1861 if (params.paragraph_separation) {
1862 switch (params.defskip.kind()) {
1863 case VSpace::SMALLSKIP:
1864 LFile += "\\setlength\\parskip{\\smallskipamount}\n";
1866 case VSpace::MEDSKIP:
1867 LFile += "\\setlength\\parskip{\\medskipamount}\n";
1869 case VSpace::BIGSKIP:
1870 LFile += "\\setlength\\parskip{\\bigskipamount}\n";
1872 case VSpace::LENGTH:
1873 LFile += "\\setlength\\parskip{"
1874 + params.defskip.length().asLatexString()
1877 default: // should never happen // Then delete it.
1878 LFile += "\\setlength\\parskip{\\medskipamount}\n";
1883 LFile += "\\setlength\\parindent{0pt}\n";
1887 // Write out what we've generated so far...and reset LFile
1891 // Now insert the LyX specific LaTeX commands...
1892 string preamble, tmppreamble;
1894 // The optional packages;
1895 preamble = features.getPackages(params);
1897 // this might be useful...
1898 preamble += "\n\\makeatletter\n\n";
1900 // Some macros LyX will need
1901 tmppreamble = features.getMacros(params);
1903 if (!tmppreamble.empty()) {
1904 preamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1905 "LyX specific LaTeX commands.\n"
1906 + tmppreamble + '\n';
1909 // the text class specific preamble
1910 tmppreamble = features.getTClassPreamble(params);
1911 if (!tmppreamble.empty()) {
1912 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1913 "Textclass specific LaTeX commands.\n"
1914 + tmppreamble + '\n';
1917 /* the user-defined preamble */
1918 if (!params.preamble.empty()) {
1919 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1920 "User specified LaTeX commands.\n"
1921 + params.preamble + '\n';
1924 preamble += "\\makeatother\n\n";
1926 // Itemize bullet settings need to be last in case the user
1927 // defines their own bullets that use a package included
1928 // in the user-defined preamble -- ARRae
1929 // Actually it has to be done much later than that
1930 // since some packages like frenchb make modifications
1931 // at \begin{document} time -- JMarc
1933 for (int i = 0; i < 4; ++i) {
1934 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
1935 if (bullets_def.empty())
1936 bullets_def="\\AtBeginDocument{\n";
1937 bullets_def += " \\renewcommand{\\labelitemi";
1939 // `i' is one less than the item to modify
1946 bullets_def += "ii";
1952 bullets_def += "}{" +
1953 params.user_defined_bullets[i].getText()
1958 if (!bullets_def.empty())
1959 preamble += bullets_def + "}\n\n";
1961 for (int j = countChar(preamble, '\n'); j-- ;) {
1968 LFile += "\\begin{document}\n\n";
1972 lyxerr.debug() << "preamble finished, now the body." << endl;
1974 bool was_title = false;
1975 bool already_title = false;
1981 LyXParagraph * par = paragraph;
1987 lyxerr[Debug::LATEX] << "Error in MakeLateXFile."
1989 LyXLayout const & layout = textclasslist.Style(params.textclass,
1992 if (layout.intitle) {
1993 if (already_title) {
1994 lyxerr <<"Error in MakeLatexFile: You"
1995 " should not mix title layouts"
1996 " with normal ones." << endl;
1999 } else if (was_title && !already_title) {
2000 LFile += "\\maketitle\n";
2002 already_title = true;
2005 // We are at depth 0 so we can just use
2006 // ordinary \footnote{} generation
2007 // flag this with ftcount
2009 if (layout.isEnvironment()
2010 || par->pextra_type != LyXParagraph::PEXTRA_NONE) {
2011 par = par->TeXEnvironment(LFile, texrow,
2012 ftnote, ft_texrow, ftcount);
2014 par = par->TeXOnePar(LFile, texrow,
2015 ftnote, ft_texrow, ftcount);
2018 // Write out what we've generated...and reset LFile
2021 LFile += "\\addtocounter{footnote}{-";
2022 LFile += tostr(ftcount - 1);
2026 texrow += ft_texrow;
2031 if (loop_count == 2) {
2032 // fwrite()ing every second time through the loop
2033 // gains a few extra % of speed; going higher than
2034 // 2 will slow things down again. I'll look at
2035 // LFile.length() in a future revision. ARRae
2042 // It might be that we only have a title in this document
2043 if (was_title && !already_title) {
2044 LFile += "\\maketitle\n";
2049 LFile += "\\end{document}\n";
2052 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
2054 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
2058 // Just to be sure. (Asger)
2061 // Write out what we've generated...and reset LFile
2065 // tex_code_break_column's value is used to decide
2066 // if we are in batchmode or not (within mathed_write()
2067 // in math_write.C) so we must set it to a non-zero
2068 // value when we leave otherwise we save incorrect .lyx files.
2069 tex_code_break_column = lyxrc->ascii_linelen;
2071 // How to check if the close went ok when using fstreams
2073 lyxerr.debug() << "Finished making latex file." << endl;
2077 bool Buffer::isLatex() const
2079 return textclasslist.TextClass(params.textclass).outputType() == LATEX;
2083 bool Buffer::isLinuxDoc() const
2085 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC;
2089 bool Buffer::isLiterate() const
2091 return textclasslist.TextClass(params.textclass).outputType() == LITERATE;
2095 bool Buffer::isDocBook() const
2097 return textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2101 bool Buffer::isSGML() const
2103 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC ||
2104 textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2108 void Buffer::sgmlOpenTag(ostream & os, int depth,
2109 string const & latexname) const
2111 os << string(depth, ' ') << "<" << latexname << ">\n";
2115 void Buffer::sgmlCloseTag(ostream & os, int depth,
2116 string const & latexname) const
2118 os << string(depth, ' ') << "</" << latexname << ">\n";
2122 void Buffer::makeLinuxDocFile(string const & fname, int column)
2124 LyXParagraph * par = paragraph;
2126 string top_element = textclasslist.LatexnameOfClass(params.textclass);
2127 string environment_stack[10];
2130 int depth = 0; /* paragraph depth */
2132 ofstream ofs(fname.c_str());
2135 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2139 tex_code_break_column = column;
2142 if (params.preamble.empty()) {
2143 ofs << "<!doctype linuxdoc system>\n\n";
2146 ofs << "<!doctype linuxdoc system \n [ "
2147 << params.preamble << " \n]>\n\n";
2150 ofs << "<!-- " << LYX_DOCVERSION
2151 << " created this file. For more info see http://www.lyx.org/"
2154 if(params.options.empty())
2155 sgmlOpenTag(ofs, 0, top_element);
2157 string top = top_element;
2159 top += params.options;
2160 sgmlOpenTag(ofs, 0, top);
2164 int desc_on = 0; /* description mode*/
2165 LyXLayout const & style =
2166 textclasslist.Style(users->buffer()->params.textclass,
2168 par->AutoDeleteInsets();
2170 /* treat <toc> as a special case for compatibility with old code */
2171 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2172 Inset * inset = par->GetInset(0);
2173 char lyx_code = inset->LyxCode();
2174 if (lyx_code == Inset::TOC_CODE){
2175 string temp = "toc";
2176 sgmlOpenTag(ofs, depth, temp);
2179 linuxDocHandleFootnote(ofs, par, depth);
2184 // environment tag closing
2185 for( ; depth > par->depth; --depth) {
2186 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2187 environment_stack[depth].clear();
2190 // write opening SGML tags
2191 switch(style.latextype) {
2192 case LATEX_PARAGRAPH:
2193 if(depth == par->depth
2194 && !environment_stack[depth].empty()) {
2195 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2196 environment_stack[depth].clear();
2202 sgmlOpenTag(ofs, depth, style.latexname());
2207 LinuxDocError(par, 0, _("Error : Wrong depth for LatexType Command.\n"));
2209 if (!environment_stack[depth].empty()){
2210 sgmlCloseTag(ofs, depth,
2211 environment_stack[depth]);
2215 environment_stack[depth].clear();
2216 sgmlOpenTag(ofs, depth, style.latexname());
2219 case LATEX_ENVIRONMENT:
2220 case LATEX_ITEM_ENVIRONMENT:
2221 if(depth == par->depth
2222 && environment_stack[depth] != style.latexname()
2223 && !environment_stack[depth].empty()) {
2225 sgmlCloseTag(ofs, depth,
2226 environment_stack[depth]);
2227 environment_stack[depth].clear();
2229 if (depth < par->depth) {
2231 environment_stack[depth].clear();
2233 if (environment_stack[depth] != style.latexname()) {
2236 sgmlOpenTag(ofs, depth, temp);
2238 environment_stack[depth] = style.latexname();
2239 sgmlOpenTag(ofs, depth, environment_stack[depth]);
2241 if(style.latextype == LATEX_ENVIRONMENT) break;
2243 desc_on = (style.labeltype == LABEL_MANUAL);
2250 sgmlOpenTag(ofs, depth + 1, item_name);
2253 sgmlOpenTag(ofs, depth, style.latexname());
2258 SimpleLinuxDocOnePar(ofs, par, desc_on, depth);
2261 linuxDocHandleFootnote(ofs, par, depth);
2263 while(par && par->IsDummy());
2266 /* write closing SGML tags */
2267 switch(style.latextype) {
2269 case LATEX_ENVIRONMENT:
2270 case LATEX_ITEM_ENVIRONMENT:
2273 sgmlCloseTag(ofs, depth, style.latexname());
2278 /* Close open tags */
2279 for(; depth > 0; --depth)
2280 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2282 if(!environment_stack[depth].empty())
2283 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2286 sgmlCloseTag(ofs, 0, top_element);
2289 // How to check for successful close
2293 void Buffer::linuxDocHandleFootnote(ostream & os, LyXParagraph * & par,
2296 string tag = "footnote";
2298 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2299 sgmlOpenTag(os, depth + 1, tag);
2300 SimpleLinuxDocOnePar(os, par, 0, depth + 1);
2301 sgmlCloseTag(os, depth + 1, tag);
2307 void Buffer::DocBookHandleCaption(ostream & os, string & inner_tag,
2308 int const depth, int desc_on,
2309 LyXParagraph * & par)
2311 LyXParagraph * tpar = par;
2312 string tmp_par, extra_par;
2313 while (tpar && (tpar->footnoteflag != LyXParagraph::NO_FOOTNOTE) &&
2314 (tpar->layout != textclasslist.NumberOfLayout(params.textclass,
2318 tpar->layout == textclasslist.NumberOfLayout(params.textclass,
2319 "Caption").second) {
2320 sgmlOpenTag(os, depth + 1, inner_tag);
2321 SimpleDocBookOnePar(tmp_par, extra_par, tpar,
2322 desc_on, depth + 2);
2323 tmp_par = strip(tmp_par);
2324 tmp_par = frontStrip(tmp_par);
2326 sgmlCloseTag(os, depth+1, inner_tag);
2327 if(!extra_par.empty())
2333 void Buffer::DocBookHandleFootnote(ostream & os, LyXParagraph * & par,
2336 string tag, inner_tag;
2337 string tmp_par, extra_par;
2338 bool inner_span = false;
2341 // This is not how I like to see enums. They should not be anonymous
2342 // and variables of its type should not be declared right after the
2343 // last brace. (Lgb)
2350 } last = NO_ONE, present = FOOTNOTE_LIKE;
2352 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2353 if(last == present) {
2355 if(!tmp_par.empty()) {
2358 sgmlCloseTag(os, depth+1, inner_tag);
2359 sgmlOpenTag(os, depth+1, inner_tag);
2366 if(!inner_tag.empty()) sgmlCloseTag(os, depth+1, inner_tag);
2367 if(!extra_par.empty()) os << extra_par;
2368 if(!tag.empty()) sgmlCloseTag(os, depth, tag);
2371 switch (par->footnotekind) {
2372 case LyXParagraph::FOOTNOTE:
2373 case LyXParagraph::ALGORITHM:
2376 present = FOOTNOTE_LIKE;
2379 case LyXParagraph::MARGIN:
2382 present = MARGIN_LIKE;
2385 case LyXParagraph::FIG:
2386 case LyXParagraph::WIDE_FIG:
2388 inner_tag = "title";
2392 case LyXParagraph::TAB:
2393 case LyXParagraph::WIDE_TAB:
2395 inner_tag = "title";
2400 sgmlOpenTag(os, depth, tag);
2401 if ((present == TAB_LIKE) || (present == FIG_LIKE)) {
2402 DocBookHandleCaption(os, inner_tag, depth,
2406 sgmlOpenTag(os, depth + 1, inner_tag);
2409 // ignore all caption here, we processed them above!!!
2410 if (par->layout != textclasslist.NumberOfLayout(params.textclass,
2411 "Caption").second) {
2412 SimpleDocBookOnePar(tmp_par, extra_par, par,
2413 desc_on, depth + 2);
2415 tmp_par = frontStrip(strip(tmp_par));
2421 if(!inner_tag.empty()) sgmlCloseTag(os, depth+1, inner_tag);
2422 if(!extra_par.empty()) os << extra_par;
2423 if(!tag.empty()) sgmlCloseTag(os, depth, tag);
2427 /* push a tag in a style stack */
2428 void Buffer::push_tag(ostream & os, char const * tag,
2429 int & pos, char stack[5][3])
2431 /* pop all previous tags */
2432 for (int j = pos; j >= 0; --j)
2433 os << "</" << stack[j] << ">";
2436 sprintf(stack[++pos], "%s", tag);
2439 for (int i = 0; i <= pos; ++i)
2440 os << "<" << stack[i] << ">";
2444 // pop a tag from a style stack
2445 void Buffer::pop_tag(ostream & os, char const * tag,
2446 int & pos, char stack[5][3])
2448 // pop all tags till specified one
2449 for (int j = pos; (j >= 0) && (strcmp(stack[j], tag)); --j)
2450 os << "</" << stack[j] << ">";
2453 os << "</" << tag << ">";
2455 // push all tags, but the specified one
2456 for (int i = 0; i <= pos; ++i) {
2457 os << "<" << stack[i] << ">";
2458 strcpy(stack[i - 1], stack[i]);
2464 /* handle internal paragraph parsing -- layout already processed */
2466 // checks, if newcol chars should be put into this line
2467 // writes newline, if necessary.
2469 void linux_doc_line_break(ostream & os, unsigned int & colcount,
2470 const unsigned int newcol)
2473 if (colcount > lyxrc->ascii_linelen) {
2475 colcount = newcol; // assume write after this call
2480 void Buffer::SimpleLinuxDocOnePar(ostream & os, LyXParagraph * par,
2481 int desc_on, int const /*depth*/)
2483 LyXFont font1, font2;
2486 LyXParagraph::size_type main_body;
2488 LyXLayout const & style = textclasslist.Style(params.textclass,
2491 char family_type = 0; // family font flag
2492 bool is_bold = false; // series font flag
2493 char shape_type = 0; // shape font flag
2494 bool is_em = false; // emphasis (italic) font flag
2496 int stack_num = -1; // style stack position
2497 char stack[5][3]; // style stack
2498 unsigned int char_line_count = 5; // Heuristic choice ;-)
2500 if (style.labeltype != LABEL_MANUAL)
2503 main_body = par->BeginningOfMainBody();
2505 /* gets paragraph main font */
2507 font1 = style.labelfont;
2512 /* parsing main loop */
2513 for (LyXParagraph::size_type i = 0;
2514 i < par->size(); ++i) {
2516 /* handle quote tag */
2517 if (i == main_body && !par->IsDummy()) {
2522 font2 = par->getFont(i);
2524 if (font1.family() != font2.family()) {
2525 switch(family_type) {
2527 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2528 push_tag(os, "tt", stack_num, stack);
2531 else if (font2.family() == LyXFont::SANS_FAMILY) {
2532 push_tag(os, "sf", stack_num, stack);
2537 pop_tag(os, "tt", stack_num, stack);
2538 if (font2.family() == LyXFont::SANS_FAMILY) {
2539 push_tag(os, "sf", stack_num, stack);
2547 pop_tag(os, "sf", stack_num, stack);
2548 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2549 push_tag(os, "tt", stack_num, stack);
2558 /* handle bold face */
2559 if (font1.series() != font2.series()) {
2560 if (font2.series() == LyXFont::BOLD_SERIES) {
2561 push_tag(os, "bf", stack_num, stack);
2565 pop_tag(os, "bf", stack_num, stack);
2570 /* handle italic and slanted fonts */
2571 if (font1.shape() != font2.shape()) {
2572 switch(shape_type) {
2574 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2575 push_tag(os, "it", stack_num, stack);
2578 else if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2579 push_tag(os, "sl", stack_num, stack);
2584 pop_tag(os, "it", stack_num, stack);
2585 if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2586 push_tag(os, "sl", stack_num, stack);
2594 pop_tag(os, "sl", stack_num, stack);
2595 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2596 push_tag(os, "it", stack_num, stack);
2604 /* handle <em> tag */
2605 if (font1.emph() != font2.emph()) {
2606 if (font2.emph() == LyXFont::ON) {
2607 push_tag(os, "em", stack_num, stack);
2610 pop_tag(os, "em", stack_num, stack);
2615 c = par->GetChar(i);
2617 if (font2.latex() == LyXFont::ON) {
2618 // "TeX"-Mode on == > SGML-Mode on.
2620 os << c; // see LaTeX-Generation...
2622 } else if (c == LyXParagraph::META_INSET) {
2623 inset = par->GetInset(i);
2625 inset->Linuxdoc(tmp_out);
2630 if (par->linuxDocConvertChar(c, sgml_string)
2631 && !style.free_spacing) { // in freespacing
2633 // non-breaking characters
2637 linux_doc_line_break(os, char_line_count, 6);
2642 linux_doc_line_break(os, char_line_count, 1);
2648 char_line_count += sgml_string.length();
2654 /* needed if there is an optional argument but no contents */
2655 if (main_body > 0 && main_body == par->size()) {
2659 /* pop all defined Styles */
2660 for (j = stack_num; j >= 0; --j) {
2661 linux_doc_line_break(os,
2663 3 + strlen(stack[j]));
2664 os << "</" << stack[j] << ">";
2667 /* resets description flag correctly */
2670 /* <tag> not closed... */
2671 linux_doc_line_break(os, char_line_count, 6);
2675 /* fprintf(file, "</p>");*/
2681 /* print an error message */
2682 void Buffer::LinuxDocError(LyXParagraph * par, int pos,
2683 char const * message)
2685 InsetError * new_inset;
2687 /* insert an error marker in text */
2688 new_inset = new InsetError(message);
2689 par->InsertChar(pos, LyXParagraph::META_INSET);
2690 par->InsertInset(pos, new_inset);
2693 // This constant defines the maximum number of
2694 // environment layouts that can be nesteded.
2695 // The same applies for command layouts.
2696 // These values should be more than enough.
2697 // José Matos (1999/07/22)
2699 enum { MAX_NEST_LEVEL = 25};
2701 void Buffer::makeDocBookFile(string const & fname, int column)
2703 LyXParagraph * par = paragraph;
2705 string top_element= textclasslist.LatexnameOfClass(params.textclass);
2706 string environment_stack[MAX_NEST_LEVEL];
2707 string environment_inner[MAX_NEST_LEVEL];
2708 string command_stack[MAX_NEST_LEVEL];
2709 bool command_flag= false;
2710 int command_depth= 0, command_base= 0, cmd_depth= 0;
2712 string item_name, command_name;
2713 string c_depth, c_params, tmps;
2715 int depth= 0; /* paragraph depth */
2717 tex_code_break_column = column;
2719 ofstream ofs(fname.c_str());
2721 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2727 ofs << "<!doctype " << top_element
2728 << " public \"-//OASIS//DTD DocBook V3.1//EN\"";
2730 if (params.preamble.empty())
2733 ofs << "\n [ " << params.preamble << " \n]>\n\n";
2735 ofs << "<!-- DocBook file was created by " << LYX_DOCVERSION
2736 << "\n See http://www.lyx.org/ for more information -->\n";
2738 if(params.options.empty())
2739 sgmlOpenTag(ofs, 0, top_element);
2741 string top = top_element;
2743 top += params.options;
2744 sgmlOpenTag(ofs, 0, top);
2748 int desc_on= 0; /* description mode*/
2749 LyXLayout const & style = textclasslist.Style(users->buffer()->params.textclass,
2751 par->AutoDeleteInsets();
2753 /* environment tag closing */
2754 for( ; depth > par->depth; --depth) {
2755 if(environment_inner[depth] != "!-- --") {
2756 item_name= "listitem";
2757 sgmlCloseTag(ofs, command_depth + depth,
2759 if( environment_inner[depth] == "varlistentry")
2760 sgmlCloseTag(ofs, depth+command_depth,
2761 environment_inner[depth]);
2763 sgmlCloseTag(ofs, depth + command_depth,
2764 environment_stack[depth]);
2765 environment_stack[depth].clear();
2766 environment_inner[depth].clear();
2769 if(depth == par->depth
2770 && environment_stack[depth] != style.latexname()
2771 && !environment_stack[depth].empty()) {
2772 if(environment_inner[depth] != "!-- --") {
2773 item_name= "listitem";
2774 sgmlCloseTag(ofs, command_depth+depth,
2776 if( environment_inner[depth] == "varlistentry")
2778 depth + command_depth,
2779 environment_inner[depth]);
2782 sgmlCloseTag(ofs, depth + command_depth,
2783 environment_stack[depth]);
2785 environment_stack[depth].clear();
2786 environment_inner[depth].clear();
2789 // Write opening SGML tags.
2790 switch(style.latextype) {
2791 case LATEX_PARAGRAPH:
2792 if(style.latexname() != "dummy")
2793 sgmlOpenTag(ofs, depth+command_depth,
2799 LinuxDocError(par, 0,
2800 _("Error : Wrong depth for "
2801 "LatexType Command.\n"));
2803 command_name = style.latexname();
2805 tmps = style.latexparam();
2806 c_params = split(tmps, c_depth,'|');
2808 cmd_depth= atoi(c_depth.c_str());
2811 if(cmd_depth<command_base) {
2812 for(int j = command_depth;
2813 j >= command_base; --j)
2814 if(!command_stack[j].empty())
2815 sgmlCloseTag(ofs, j, command_stack[j]);
2816 command_depth= command_base= cmd_depth;
2818 else if(cmd_depth <= command_depth) {
2819 for(int j = command_depth;
2820 j >= cmd_depth; --j)
2822 if(!command_stack[j].empty())
2823 sgmlCloseTag(ofs, j, command_stack[j]);
2824 command_depth= cmd_depth;
2827 command_depth= cmd_depth;
2830 command_depth = command_base = cmd_depth;
2831 command_flag = true;
2833 command_stack[command_depth]= command_name;
2835 // treat label as a special case for
2836 // more WYSIWYM handling.
2837 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2838 Inset * inset = par->GetInset(0);
2839 char lyx_code = inset->LyxCode();
2840 if (lyx_code == Inset::LABEL_CODE){
2841 command_name += " id=\"";
2842 command_name += (static_cast<InsetCommand *>(inset))->getContents();
2843 command_name += "\"";
2848 sgmlOpenTag(ofs, depth+command_depth, command_name);
2849 item_name = "title";
2850 sgmlOpenTag(ofs, depth + 1 + command_depth, item_name);
2853 case LATEX_ENVIRONMENT:
2854 case LATEX_ITEM_ENVIRONMENT:
2855 if (depth < par->depth) {
2857 environment_stack[depth].clear();
2860 if (environment_stack[depth] != style.latexname()) {
2861 environment_stack[depth] = style.latexname();
2862 environment_inner[depth] = "!-- --";
2863 sgmlOpenTag(ofs, depth + command_depth,
2864 environment_stack[depth]);
2866 if(environment_inner[depth] != "!-- --") {
2867 item_name= "listitem";
2869 command_depth + depth,
2871 if (environment_inner[depth] == "varlistentry")
2873 depth + command_depth,
2874 environment_inner[depth]);
2878 if(style.latextype == LATEX_ENVIRONMENT) {
2879 if(!style.latexparam().empty())
2880 sgmlOpenTag(ofs, depth + command_depth,
2881 style.latexparam());
2885 desc_on = (style.labeltype == LABEL_MANUAL);
2888 environment_inner[depth]= "varlistentry";
2890 environment_inner[depth]= "listitem";
2892 sgmlOpenTag(ofs, depth + 1 + command_depth,
2893 environment_inner[depth]);
2897 sgmlOpenTag(ofs, depth + 1 + command_depth,
2902 sgmlOpenTag(ofs, depth + 1 + command_depth,
2907 sgmlOpenTag(ofs, depth + command_depth,
2913 string tmp_par, extra_par;
2915 SimpleDocBookOnePar(tmp_par, extra_par, par, desc_on,
2916 depth + 1 + command_depth);
2920 DocBookHandleFootnote(ofs, par,
2921 depth + 1 + command_depth);
2923 while(par && par->IsDummy());
2926 /* write closing SGML tags */
2927 switch(style.latextype) {
2930 sgmlCloseTag(ofs, depth + command_depth, end_tag);
2932 case LATEX_ENVIRONMENT:
2933 if(!style.latexparam().empty())
2934 sgmlCloseTag(ofs, depth + command_depth,
2935 style.latexparam());
2937 case LATEX_ITEM_ENVIRONMENT:
2938 if(desc_on == 1) break;
2940 sgmlCloseTag(ofs, depth + 1 + command_depth, end_tag);
2942 case LATEX_PARAGRAPH:
2943 if(style.latexname() != "dummy")
2944 sgmlCloseTag(ofs, depth + command_depth,
2948 sgmlCloseTag(ofs, depth + command_depth,
2955 for(; depth >= 0; --depth) {
2956 if(!environment_stack[depth].empty()) {
2957 if(environment_inner[depth] != "!-- --") {
2958 item_name= "listitem";
2959 sgmlCloseTag(ofs, command_depth + depth,
2961 if( environment_inner[depth] == "varlistentry")
2962 sgmlCloseTag(ofs, depth + command_depth,
2963 environment_inner[depth]);
2966 sgmlCloseTag(ofs, depth + command_depth,
2967 environment_stack[depth]);
2971 for(int j = command_depth; j >= command_base; --j)
2972 if(!command_stack[j].empty())
2973 sgmlCloseTag(ofs, j, command_stack[j]);
2976 sgmlCloseTag(ofs, 0, top_element);
2979 // How to check for successful close
2983 void Buffer::SimpleDocBookOnePar(string & file, string & extra,
2984 LyXParagraph * par, int & desc_on,
2988 par->SimpleDocBookOneTablePar(file, extra, desc_on, depth);
2991 LyXFont font1, font2;
2994 LyXParagraph::size_type main_body;
2996 string emph= "emphasis";
2997 bool emph_flag= false;
2998 int char_line_count= 0;
3000 LyXLayout const & style = textclasslist.Style(params.textclass,
3003 if (style.labeltype != LABEL_MANUAL)
3006 main_body = par->BeginningOfMainBody();
3008 /* gets paragraph main font */
3010 font1 = style.labelfont;
3014 char_line_count = depth;
3015 if(!style.free_spacing)
3016 for (j= 0;j< depth;j++)
3019 /* parsing main loop */
3020 for (LyXParagraph::size_type i = 0;
3021 i < par->size(); ++i) {
3022 font2 = par->getFont(i);
3024 /* handle <emphasis> tag */
3025 if (font1.emph() != font2.emph() && i) {
3026 if (font2.emph() == LyXFont::ON) {
3027 file += "<emphasis>";
3030 file += "</emphasis>";
3035 c = par->GetChar(i);
3037 if (c == LyXParagraph::META_INSET) {
3038 inset = par->GetInset(i);
3040 inset->DocBook(tmp_out);
3042 // This code needs some explanation:
3043 // Two insets are treated specially
3044 // label if it is the first element in a command paragraph
3046 // graphics inside tables or figure floats can't go on
3047 // title (the equivalente in latex for this case is caption
3048 // and title should come first
3051 if(desc_on!= 3 || i!= 0) {
3052 if(!tmp_out.empty() && tmp_out[0] == '@') {
3054 extra += frontStrip(tmp_out, '@');
3056 file += frontStrip(tmp_out, '@');
3061 } else if (font2.latex() == LyXFont::ON) {
3062 // "TeX"-Mode on ==> SGML-Mode on.
3069 if (par->linuxDocConvertChar(c, sgml_string)
3070 && !style.free_spacing) { // in freespacing
3072 // non-breaking characters
3077 file += "</term><listitem><para>";
3085 file += sgml_string;
3091 /* needed if there is an optional argument but no contents */
3092 if (main_body > 0 && main_body == par->size()) {
3096 file += "</emphasis>";
3099 /* resets description flag correctly */
3102 /* <term> not closed... */
3110 bool BufferView::removeAutoInsets()
3112 LyXParagraph * par = buffer()->paragraph;
3114 LyXCursor cursor = text->cursor;
3115 LyXCursor tmpcursor = cursor;
3116 cursor.par = tmpcursor.par->ParFromPos(tmpcursor.pos);
3117 cursor.pos = tmpcursor.par->PositionInParFromPos(tmpcursor.pos);
3121 if (par->AutoDeleteInsets()){
3123 if (par->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE){
3124 // this is possible now, since SetCursor takes
3125 // care about footnotes
3126 text->SetCursorIntern(par, 0);
3127 text->RedoParagraphs(text->cursor,
3128 text->cursor.par->Next());
3129 text->FullRebreak();
3134 // avoid forbidden cursor positions caused by error removing
3135 if (cursor.pos > cursor.par->Last())
3136 cursor.pos = cursor.par->Last();
3137 text->SetCursorIntern(cursor.par, cursor.pos);
3143 int Buffer::runLaTeX()
3145 if (!users->text) return 0;
3149 // get LaTeX-Filename
3150 string name = getLatexName();
3152 string path = OnlyPath(filename);
3154 string org_path = path;
3155 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
3159 Path p(path); // path to LaTeX file
3160 users->owner()->getMiniBuffer()->Set(_("Running LaTeX..."));
3162 // Remove all error insets
3163 bool a = users->removeAutoInsets();
3165 // Always generate the LaTeX file
3166 makeLaTeXFile(name, org_path, false);
3169 // do the LaTex run(s)
3171 string latex_command = lyxrc->pdf_mode ?
3172 lyxrc->pdflatex_command : lyxrc->latex_command;
3173 LaTeX latex(latex_command, name, filepath);
3174 int res = latex.run(terr,
3175 users->owner()->getMiniBuffer()); // running latex
3177 // check return value from latex.run().
3178 if ((res & LaTeX::NO_LOGFILE)) {
3179 WriteAlert(_("LaTeX did not work!"),
3180 _("Missing log file:"), name);
3181 } else if ((res & LaTeX::ERRORS)) {
3182 users->owner()->getMiniBuffer()->Set(_("Done"));
3183 // Insert all errors as errors boxes
3184 users->insertErrors(terr);
3186 // Dvi should also be kept dirty if the latex run
3187 // ends up with errors. However it should be possible
3188 // to view a dirty dvi too.
3190 //no errors or any other things to think about so:
3191 users->owner()->getMiniBuffer()->Set(_("Done"));
3195 // if we removed error insets before we ran LaTeX or if we inserted
3196 // error insets after we ran LaTeX this must be run:
3197 if (a || (res & LaTeX::ERRORS)){
3200 users->updateScrollbar();
3204 return latex.getNumErrors();
3208 int Buffer::runLiterate()
3210 if (!users->text) return 0;
3214 // get LaTeX-Filename
3215 string name = getLatexName();
3216 // get Literate-Filename
3217 string lit_name = ChangeExtension (getLatexName(),
3218 lyxrc->literate_extension, true);
3220 string path = OnlyPath(filename);
3222 string org_path = path;
3223 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
3227 Path p(path); // path to Literate file
3228 users->owner()->getMiniBuffer()->Set(_("Running Literate..."));
3230 // Remove all error insets
3231 bool a = users->removeAutoInsets();
3233 // generate the Literate file if necessary
3234 if (!isDviClean() || a) {
3235 makeLaTeXFile(lit_name, org_path, false);
3239 string latex_command = lyxrc->pdf_mode ?
3240 lyxrc->pdflatex_command : lyxrc->latex_command;
3241 Literate literate(latex_command, name, filepath,
3243 lyxrc->literate_command, lyxrc->literate_error_filter,
3244 lyxrc->build_command, lyxrc->build_error_filter);
3246 int res = literate.weave(terr, users->owner()->getMiniBuffer());
3248 // check return value from literate.weave().
3249 if ((res & Literate::NO_LOGFILE)) {
3250 WriteAlert(_("Literate command did not work!"),
3251 _("Missing log file:"), name);
3252 } else if ((res & Literate::ERRORS)) {
3253 users->owner()->getMiniBuffer()->Set(_("Done"));
3254 // Insert all errors as errors boxes
3255 users->insertErrors(terr);
3257 // Dvi should also be kept dirty if the latex run
3258 // ends up with errors. However it should be possible
3259 // to view a dirty dvi too.
3261 //no errors or any other things to think about so:
3262 users->owner()->getMiniBuffer()->Set(_("Done"));
3266 // if we removed error insets before we ran LaTeX or if we inserted
3267 // error insets after we ran LaTeX this must be run:
3268 if (a || (res & Literate::ERRORS)){
3271 users->updateScrollbar();
3275 return literate.getNumErrors();
3279 int Buffer::buildProgram()
3281 if (!users->text) return 0;
3285 // get LaTeX-Filename
3286 string name = getLatexName();
3287 // get Literate-Filename
3288 string lit_name = ChangeExtension(getLatexName(),
3289 lyxrc->literate_extension, true);
3291 string path = OnlyPath(filename);
3293 string org_path = path;
3294 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
3298 Path p(path); // path to Literate file
3299 users->owner()->getMiniBuffer()->Set(_("Building Program..."));
3301 // Remove all error insets
3302 bool a = users->removeAutoInsets();
3304 // generate the LaTeX file if necessary
3305 if (!isNwClean() || a) {
3306 makeLaTeXFile(lit_name, org_path, false);
3310 string latex_command = lyxrc->pdf_mode ?
3311 lyxrc->pdflatex_command : lyxrc->latex_command;
3312 Literate literate(latex_command, name, filepath,
3314 lyxrc->literate_command, lyxrc->literate_error_filter,
3315 lyxrc->build_command, lyxrc->build_error_filter);
3317 int res = literate.build(terr, users->owner()->getMiniBuffer());
3319 // check return value from literate.build().
3320 if ((res & Literate::NO_LOGFILE)) {
3321 WriteAlert(_("Build did not work!"),
3322 _("Missing log file:"), name);
3323 } else if ((res & Literate::ERRORS)) {
3324 users->owner()->getMiniBuffer()->Set(_("Done"));
3325 // Insert all errors as errors boxes
3326 users->insertErrors(terr);
3328 // Literate files should also be kept dirty if the literate
3329 // command run ends up with errors.
3331 //no errors or any other things to think about so:
3332 users->owner()->getMiniBuffer()->Set(_("Done"));
3336 // if we removed error insets before we ran Literate/Build or if we inserted
3337 // error insets after we ran Literate/Build this must be run:
3338 if (a || (res & Literate::ERRORS)){
3341 users->updateScrollbar();
3345 return literate.getNumErrors();
3349 // This should be enabled when the Chktex class is implemented. (Asger)
3350 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
3351 // Other flags: -wall -v0 -x
3352 int Buffer::runChktex()
3354 if (!users->text) return 0;
3358 // get LaTeX-Filename
3359 string name = getLatexName();
3360 string path = OnlyPath(filename);
3362 string org_path = path;
3363 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
3367 Path p(path); // path to LaTeX file
3368 users->owner()->getMiniBuffer()->Set(_("Running chktex..."));
3370 // Remove all error insets
3371 bool a = users->removeAutoInsets();
3373 // Generate the LaTeX file if neccessary
3374 if (!isDviClean() || a) {
3375 makeLaTeXFile(name, org_path, false);
3380 Chktex chktex(lyxrc->chktex_command, name, filepath);
3381 int res = chktex.run(terr); // run chktex
3384 WriteAlert(_("chktex did not work!"),
3385 _("Could not run with file:"), name);
3386 } else if (res > 0) {
3387 // Insert all errors as errors boxes
3388 users->insertErrors(terr);
3391 // if we removed error insets before we ran chktex or if we inserted
3392 // error insets after we ran chktex, this must be run:
3396 users->updateScrollbar();
3404 void BufferView::insertErrors(TeXErrors & terr)
3406 // Save the cursor position
3407 LyXCursor cursor = text->cursor;
3409 // This is drastic, but it's the only fix, I could find. (Asger)
3413 for (TeXErrors::Errors::const_iterator cit = terr.begin();
3416 string desctext((*cit).error_desc);
3417 string errortext((*cit).error_text);
3418 string msgtxt = desctext + '\n' + errortext;
3419 int errorrow = (*cit).error_in_line;
3421 // Insert error string for row number
3425 buffer()->texrow.getIdFromRow(errorrow, tmpid, tmppos);
3427 LyXParagraph * texrowpar = 0;
3430 texrowpar = text->FirstParagraph();
3433 texrowpar = text->GetParFromID(tmpid);
3439 InsetError * new_inset = new InsetError(msgtxt);
3440 text->SetCursorIntern(texrowpar, tmppos);
3441 text->InsertInset(new_inset);
3442 text->FullRebreak();
3444 // Restore the cursor position
3445 text->SetCursorIntern(cursor.par, cursor.pos);
3449 void BufferView::setCursorFromRow(int row)
3454 buffer()->texrow.getIdFromRow(row, tmpid, tmppos);
3456 LyXParagraph * texrowpar;
3459 texrowpar = text->FirstParagraph();
3462 texrowpar = text->GetParFromID(tmpid);
3464 text->SetCursor(texrowpar, tmppos);
3468 void Buffer::RoffAsciiTable(ostream & os, LyXParagraph * par)
3470 LyXFont font1 = LyXFont(LyXFont::ALL_INHERIT);
3473 LyXParagraph::size_type i;
3477 string fname1 = TmpFileName(string(), "RAT1");
3478 string fname2 = TmpFileName(string(), "RAT2");
3480 ofstream ofs(fname1.c_str());
3482 WriteAlert(_("LYX_ERROR:"),
3483 _("Cannot open temporary file:"), fname1);
3486 par->table->RoffEndOfCell(ofs, -1);
3487 for (i = 0; i < par->size(); ++i) {
3488 c = par->GetChar(i);
3489 if (par->table->IsContRow(cell)) {
3490 if (c == LyXParagraph::META_NEWLINE)
3494 font2 = par->GetFontSettings(i);
3495 if (font1.latex() != font2.latex()) {
3496 if (font2.latex() != LyXFont::OFF)
3500 case LyXParagraph::META_INSET:
3501 if ((inset = par->GetInset(i))) {
3502 fstream fs(fname2.c_str(), ios::in|ios::out);
3504 WriteAlert(_("LYX_ERROR:"),
3505 _("Cannot open temporary file:"), fname2);
3507 remove(fname1.c_str());
3510 inset->Latex(fs, -1);
3523 case LyXParagraph::META_NEWLINE:
3524 if (par->table->CellHasContRow(cell)>= 0)
3525 par->RoffContTableRows(ofs, i+1, cell);
3526 par->table->RoffEndOfCell(ofs, cell);
3529 case LyXParagraph::META_HFILL:
3531 case LyXParagraph::META_PROTECTED_SEPARATOR:
3541 << "RoffAsciiTable:"
3542 " NULL char in structure." << endl;
3546 par->table->RoffEndOfCell(ofs, cell);
3548 string cmd = lyxrc->ascii_roff_command + " >" + fname2;
3549 cmd = subst(cmd, "$$FName", fname1);
3550 Systemcalls one(Systemcalls::System, cmd);
3551 if (!(lyxerr.debugging(Debug::ROFF))) {
3552 remove(fname1.c_str());
3554 ifstream ifs(fname2.c_str());
3556 WriteFSAlert(_("Error! Can't open temporary file:"), fname2);
3559 // now output the produced file
3563 WriteAlert(_("Error!"),
3564 _("Error executing *roff command on table"));
3565 // overread leading blank lines
3566 while(!ifs && (c == '\n'))
3569 for(j = 0; j < par->depth; ++j)
3571 while(!ifs && (c != '\n')) {
3576 // overread trailing blank lines
3577 while(!ifs && (c == '\n'))
3581 remove(fname2.c_str());
3585 /// changed Heinrich Bauer, 23/03/98
3586 bool Buffer::isDviClean()
3588 if (lyxrc->use_tempdir)
3589 return dvi_clean_tmpd;
3591 return dvi_clean_orgd;
3595 /// changed Heinrich Bauer, 23/03/98
3596 void Buffer::markDviClean()
3598 if (lyxrc->use_tempdir)
3599 dvi_clean_tmpd = true;
3601 dvi_clean_orgd = true;
3605 /// changed Heinrich Bauer, 23/03/98
3606 void Buffer::markDviDirty()
3608 if (lyxrc->use_tempdir)
3609 dvi_clean_tmpd = false;
3611 dvi_clean_orgd = false;
3615 void Buffer::validate(LaTeXFeatures & features)
3617 LyXParagraph * par = paragraph;
3618 LyXTextClass const & tclass =
3619 textclasslist.TextClass(params.textclass);
3621 // AMS Style is at document level
3623 features.amsstyle = (params.use_amsmath ||
3624 tclass.provides(LyXTextClass::amsmath));
3627 // We don't use "lyxerr.debug" because of speed. (Asger)
3628 if (lyxerr.debugging(Debug::LATEX))
3629 lyxerr << "Paragraph: " << par << endl;
3631 // Now just follow the list of paragraphs and run
3632 // validate on each of them.
3633 par->validate(features);
3635 // and then the next paragraph
3639 // the bullet shapes are buffer level not paragraph level
3640 // so they are tested here
3641 for (int i = 0; i < 4; ++i) {
3642 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
3643 int font = params.user_defined_bullets[i].getFont();
3646 .user_defined_bullets[i]
3653 features.latexsym = true;
3657 features.amssymb = true;
3659 else if ((font >= 2 && font <= 5)) {
3660 features.pifont = true;
3665 if (lyxerr.debugging(Debug::LATEX)) {
3666 features.showStruct(params);
3671 void Buffer::setPaperStuff()
3673 params.papersize = BufferParams::PAPER_DEFAULT;
3674 char c1 = params.paperpackage;
3675 if (c1 == BufferParams::PACKAGE_NONE) {
3676 char c2 = params.papersize2;
3677 if (c2 == BufferParams::VM_PAPER_USLETTER)
3678 params.papersize = BufferParams::PAPER_USLETTER;
3679 else if (c2 == BufferParams::VM_PAPER_USLEGAL)
3680 params.papersize = BufferParams::PAPER_LEGALPAPER;
3681 else if (c2 == BufferParams::VM_PAPER_USEXECUTIVE)
3682 params.papersize = BufferParams::PAPER_EXECUTIVEPAPER;
3683 else if (c2 == BufferParams::VM_PAPER_A3)
3684 params.papersize = BufferParams::PAPER_A3PAPER;
3685 else if (c2 == BufferParams::VM_PAPER_A4)
3686 params.papersize = BufferParams::PAPER_A4PAPER;
3687 else if (c2 == BufferParams::VM_PAPER_A5)
3688 params.papersize = BufferParams::PAPER_A5PAPER;
3689 else if ((c2 == BufferParams::VM_PAPER_B3) || (c2 == BufferParams::VM_PAPER_B4) ||
3690 (c2 == BufferParams::VM_PAPER_B5))
3691 params.papersize = BufferParams::PAPER_B5PAPER;
3692 } else if ((c1 == BufferParams::PACKAGE_A4) || (c1 == BufferParams::PACKAGE_A4WIDE) ||
3693 (c1 == BufferParams::PACKAGE_WIDEMARGINSA4))
3694 params.papersize = BufferParams::PAPER_A4PAPER;
3699 void Buffer::setOldPaperStuff()
3701 char c = params.papersize = params.papersize2;
3702 params.papersize2 = BufferParams::VM_PAPER_DEFAULT;
3703 params.paperpackage = BufferParams::PACKAGE_NONE;
3704 if (c == OLD_PAPER_A4PAPER)
3705 params.papersize2 = BufferParams::VM_PAPER_A4;
3706 else if (c == OLD_PAPER_A4)
3707 params.paperpackage = BufferParams::PACKAGE_A4;
3708 else if (c == OLD_PAPER_A4WIDE)
3709 params.paperpackage = BufferParams::PACKAGE_A4WIDE;
3710 else if (c == OLD_PAPER_WIDEMARGINSA4)
3711 params.paperpackage = BufferParams::PACKAGE_WIDEMARGINSA4;
3712 else if (c == OLD_PAPER_USLETTER)
3713 params.papersize2 = BufferParams::VM_PAPER_USLETTER;
3714 else if (c == OLD_PAPER_A5PAPER)
3715 params.papersize2 = BufferParams::VM_PAPER_A5;
3716 else if (c == OLD_PAPER_B5PAPER)
3717 params.papersize2 = BufferParams::VM_PAPER_B5;
3718 else if (c == OLD_PAPER_EXECUTIVEPAPER)
3719 params.papersize2 = BufferParams::VM_PAPER_USEXECUTIVE;
3720 else if (c == OLD_PAPER_LEGALPAPER)
3721 params.papersize2 = BufferParams::VM_PAPER_USLEGAL;
3727 void BufferView::insertInset(Inset * inset, string const & lout,
3730 // check for table/list in tables
3731 if (no_table && text->cursor.par->table){
3732 WriteAlert(_("Impossible Operation!"),
3733 _("Cannot insert table/list in table."),
3737 // not quite sure if we want this...
3738 text->SetCursorParUndo();
3742 if (!lout.empty()) {
3744 text->BreakParagraph();
3747 if (text->cursor.par->Last()) {
3750 text->BreakParagraph();
3754 int lay = textclasslist.NumberOfLayout(buffer()->params.textclass,
3756 if (lay == -1) // layout not found
3757 // use default layout "Standard" (0)
3760 text->SetLayout(lay);
3762 text->SetParagraph(0, 0,
3764 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3770 text->current_font.setLatex(LyXFont::OFF);
3773 text->InsertInset(inset);
3776 text->UnFreezeUndo();
3780 // Open and lock an updatable inset
3781 void BufferView::open_new_inset(UpdatableInset * new_inset)
3785 insertInset(new_inset);
3788 new_inset->Edit(0, 0);
3792 // This function should be in Buffer because it's a buffer's property (ale)
3793 string Buffer::getIncludeonlyList(char delim)
3796 LyXParagraph * par = paragraph;
3797 LyXParagraph::size_type pos;
3801 while ((inset = par->ReturnNextInsetPointer(pos))){
3802 if (inset->LyxCode() == Inset::INCLUDE_CODE) {
3803 InsetInclude * insetinc =
3804 static_cast<InsetInclude*>(inset);
3805 if (insetinc->isInclude()
3806 && insetinc->isNoLoad()) {
3809 lst += ChangeExtension(insetinc->getContents(), string(), true);
3816 lyxerr.debug() << "Includeonly(" << lst << ')' << endl;
3821 // This is also a buffer property (ale)
3822 string Buffer::getReferenceList(char delim)
3824 /// if this is a child document and the parent is already loaded
3825 /// Use the parent's list instead [ale990407]
3826 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3827 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3829 return tmp->getReferenceList(delim);
3832 LyXParagraph * par = paragraph;
3833 LyXParagraph::size_type pos;
3838 while ((inset = par->ReturnNextInsetPointer(pos))){
3839 for (int i = 0; i < inset->GetNumberOfLabels(); i++) {
3842 lst += inset->getLabel(i);
3848 lyxerr.debug() << "References(" << lst << ")" << endl;
3853 // This is also a buffer property (ale)
3854 string Buffer::getBibkeyList(char delim)
3856 /// if this is a child document and the parent is already loaded
3857 /// Use the parent's list instead [ale990412]
3858 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3859 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3861 return tmp->getBibkeyList(delim);
3865 LyXParagraph * par = paragraph;
3868 if (!bibkeys.empty())
3870 bibkeys += par->bibkey->getContents();
3875 // Might be either using bibtex or a child has bibliography
3876 if (bibkeys.empty()) {
3880 LyXParagraph::size_type pos = -1;
3882 // Search for Bibtex or Include inset
3883 while ((inset = par->ReturnNextInsetPointer(pos))) {
3884 if (inset-> LyxCode() == Inset::BIBTEX_CODE) {
3885 if (!bibkeys.empty())
3887 bibkeys += static_cast<InsetBibtex*>(inset)->getKeys(delim);
3888 } else if (inset-> LyxCode() == Inset::INCLUDE_CODE) {
3889 string bk = static_cast<InsetInclude*>(inset)->getKeys(delim);
3891 if (!bibkeys.empty())
3902 lyxerr.debug() << "Bibkeys(" << bibkeys << ")" << endl;
3907 /* This is also a buffer property (ale) */
3908 // Not so sure about that. a goto Label function can not be buffer local, just
3909 // think how this will work in a multiwindo/buffer environment, all the
3910 // cursors in all the views showing this buffer will move. (Lgb)
3911 // OK, then no cursor action should be allowed in buffer. (ale)
3912 bool BufferView::gotoLabel(string const & label)
3915 LyXParagraph * par = buffer()->paragraph;
3916 LyXParagraph::size_type pos;
3920 while ((inset = par->ReturnNextInsetPointer(pos))){
3921 for (int i = 0; i < inset->GetNumberOfLabels(); i++) {
3922 if (label == inset->getLabel(i)) {
3924 text->SetCursor(par, pos);
3925 text->sel_cursor = text->cursor;
3938 bool Buffer::isDepClean(string const & name) const
3940 DEPCLEAN * item = dep_clean;
3941 while (item && item->master != name)
3943 if (!item) return true;
3948 void Buffer::markDepClean(string const & name)
3951 dep_clean = new DEPCLEAN;
3952 dep_clean->clean = true;
3953 dep_clean->master = name;
3954 dep_clean->next = 0;
3956 DEPCLEAN* item = dep_clean;
3957 while (item && item->master != name)
3962 item = new DEPCLEAN;
3964 item->master = name;
3971 void Buffer::Dispatch(string const & command)
3973 // Split command string into command and argument
3974 string cmd, line = frontStrip(command);
3975 string arg = strip(frontStrip(split(line, cmd, ' ')));
3977 Dispatch(lyxaction.LookupFunc(cmd.c_str()), arg.c_str());
3981 void Buffer::Dispatch(int action, string const & argument)
3985 MenuExport(this, argument);
3989 lyxerr << "A truly unknown func!" << endl;