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"
48 #include "tex-strings.h"
51 #include "minibuffer.h"
53 #include "mathed/formulamacro.h"
54 #include "insets/lyxinset.h"
55 #include "insets/inseterror.h"
56 #include "insets/insetlabel.h"
57 #include "insets/insetref.h"
58 #include "insets/inseturl.h"
59 #include "insets/insetinfo.h"
60 #include "insets/insetquotes.h"
62 #include "insets/insetlatex.h"
64 #include "insets/insetlatexaccent.h"
65 #include "insets/insetbib.h"
66 #include "insets/insetindex.h"
67 #include "insets/insetinclude.h"
68 #include "insets/insettoc.h"
69 #include "insets/insetlof.h"
70 #include "insets/insetlot.h"
71 #include "insets/insetloa.h"
72 #include "insets/insetparent.h"
73 #include "insets/insetspecialchar.h"
74 #include "insets/figinset.h"
75 #include "support/filetools.h"
76 #include "support/path.h"
82 #include "LaTeXFeatures.h"
83 #include "support/syscall.h"
84 #include "support/lyxlib.h"
85 #include "support/FileInfo.h"
89 // Uncomment this line to enable a workaround for the weird behaviour
90 // of the cursor between a displayed inset and last character
91 // at the upper line. (Alejandro 20.9.96)
92 // #define BREAK_BEFORE_INSET
94 /* Lars, when changing this file sometime in the future to a list,
95 * please check out the figinsets-sideeffects described at the
96 * beginning of figinset.C Matthias (04.07.1996)
100 // all these externs should eventually be removed.
101 extern BufferList bufferlist;
102 extern void SmallUpdate(signed char);
103 extern unsigned char GetCurrentTextClass();
104 extern void BeforeChange();
106 static const float LYX_FORMAT = 2.15;
108 extern int tex_code_break_column;
110 extern void FreeUpdateTimer();
113 Buffer::Buffer(string const & file, LyXRC * lyxrc, bool ronly)
115 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
117 filepath = OnlyPath(file);
120 the_locking_inset = 0;
123 dvi_clean_orgd = false; // Heinrich Bauer, 23/03/98
124 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;
163 bool Buffer::saveParamsAsDefaults()
165 string fname = AddName(AddPath(user_lyxdir, "templates/"),
167 Buffer defaults = Buffer(fname);
169 // Use the current buffer's parameters as default
170 defaults.params = params;
172 // add an empty paragraph. Is this enough?
173 defaults.paragraph = new LyXParagraph;
175 return defaults.writeFile(defaults.filename, false);
179 /// Update window titles of all users
180 // Should work on a list
181 void Buffer::updateTitles()
183 if (users) users->owner()->updateWindowTitle();
187 /// Reset autosave timer of all users
188 // Should work on a list
189 void Buffer::resetAutosaveTimers()
191 if (users) users->owner()->resetAutosaveTimer();
195 void Buffer::setFileName(string const & newfile)
197 filename = MakeAbsPath(newfile);
198 filepath = OnlyPath(filename);
199 setReadonly(IsFileWriteable(filename) == 0);
203 void Buffer::InsetUnlock()
205 if (the_locking_inset) {
206 if (!inset_slept) the_locking_inset->InsetUnlock();
207 the_locking_inset = 0;
214 // Inserts a file into current document
215 bool Buffer::insertLyXFile(string const & filen)
217 // (c) CHT Software Service GmbH
220 // Insert a Lyxformat - file into current buffer
222 // Moved from lyx_cb.C (Lgb)
224 if (filen.empty()) return false;
226 string filename = MakeAbsPath(filen);
228 // check if file exist
229 FileInfo fi(filename);
231 if (!fi.readable()) {
232 WriteAlert(_("Error!"),
233 _("Specified file is unreadable: "),
234 MakeDisplayPath(filename, 50));
240 FilePtr myfile(filename, FilePtr::read);
242 WriteAlert(_("Error!"),
243 _("Cannot open specified file: "),
244 MakeDisplayPath(filename, 50));
249 int c = fgetc(myfile());
255 lyxerr.debug() << "Will insert file with header" << endl;
256 res = readFile(lex, text->cursor.par);
258 lyxerr.debug() << "Will insert file without header" << endl;
259 res = readLyXformat2(lex, text->cursor.par);
268 // changed to be public and have one parameter
269 // if par = 0 normal behavior
270 // else insert behavior
271 // Returns false if "\the_end" is not read for formats >= 2.13. (Asger)
272 bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par)
278 char depth = 0; // signed or unsigned?
279 LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
280 LyXParagraph::footnote_kind footnotekind = LyXParagraph::FOOTNOTE;
281 bool the_end_read = false;
283 LyXParagraph * return_par = 0;
284 LyXFont font = LyXFont(LyXFont::ALL_INHERIT);
286 // If we are inserting, we cheat and get a token in advance
287 bool has_token = false;
291 par = new LyXParagraph;
293 text->BreakParagraph();
294 return_par = text->FirstParagraph();
297 // We don't want to adopt the parameters from the
298 // document we insert, so we skip until the text begins:
301 pretoken = lex.GetString();
302 if (pretoken == "\\layout") {
314 pretoken = lex.GetString();
317 // Profiling show this should give a lot: (Asger)
318 string const token = pretoken;
322 else if (token[0] != '\\') {
323 int n = token.length();
324 for (int i = 0; i < n; i++) {
325 par->InsertChar(pos, token[i]);
326 par->SetFont(pos, font);
329 } else if (token == "\\i") {
330 inset = new InsetLatexAccent;
332 par->InsertChar(pos, LyXParagraph::META_INSET);
334 par->InsertInset(pos, inset);
335 par->SetFont(pos, font);
337 } else if (token == "\\layout") {
341 par->text.resize(par->text.size());
342 par = new LyXParagraph(par);
346 string layoutname = lex.GetString();
347 pair<bool, LyXTextClass::LayoutList::size_type> pp
348 = textclasslist.NumberOfLayout(params.textclass,
351 par->layout = pp.second;
352 } else { // layout not found
353 // use default layout "Standard" (0)
356 // Test whether the layout is obsolete.
357 LyXLayout const & layout = textclasslist.Style(params.textclass,
359 if (!layout.obsoleted_by().empty())
361 textclasslist.NumberOfLayout(params.textclass,
362 layout.obsoleted_by()).second;
363 par->footnoteflag = footnoteflag;
364 par->footnotekind = footnotekind;
366 font = LyXFont(LyXFont::ALL_INHERIT);
367 } else if (token == "\\end_float") {
371 par->text.resize(par->text.size());
372 par = new LyXParagraph(par);
374 footnotekind = LyXParagraph::FOOTNOTE;
375 footnoteflag = LyXParagraph::NO_FOOTNOTE;
378 par->layout = LYX_DUMMY_LAYOUT;
379 font = LyXFont(LyXFont::ALL_INHERIT);
380 } else if (token == "\\begin_float") {
381 tmpret = lex.FindToken(string_footnotekinds);
382 if (tmpret == -1) tmpret++;
383 if (tmpret != LYX_LAYOUT_DEFAULT)
384 footnotekind = (LyXParagraph::footnote_kind)tmpret; // bad
385 if (footnotekind == LyXParagraph::FOOTNOTE
386 || footnotekind == LyXParagraph::MARGIN)
387 footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
389 footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
390 } else if (token == "\\begin_deeper") {
392 } else if (token == "\\end_deeper") {
394 lex.printError("\\end_deeper: "
395 "depth is already null");
399 } else if (token == "\\begin_preamble") {
400 params.readPreamble(lex);
401 } else if (token == "\\textclass") {
403 pair<bool, LyXTextClassList::ClassList::size_type> pp =
404 textclasslist.NumberOfClass(lex.GetString());
406 params.textclass = pp.second;
408 lex.printError("Unknown textclass `$$Token'");
409 params.textclass = 0;
411 if (!textclasslist.Load(params.textclass)) {
412 // if the textclass wasn't loaded properly
413 // we need to either substitute another
414 // or stop loading the file.
415 // I can substitute but I don't see how I can
416 // stop loading... ideas?? ARRae980418
417 WriteAlert(_("Textclass Loading Error!"),
418 string(_("Can't load textclass ")) +
419 textclasslist.NameOfClass(params.textclass),
420 _("-- substituting default"));
421 params.textclass = 0;
423 } else if (token == "\\options") {
425 params.options = lex.GetString();
426 } else if (token == "\\language") {
427 params.readLanguage(lex);
428 } else if (token == "\\fontencoding") {
430 } else if (token == "\\inputencoding") {
432 params.inputenc = lex.GetString();
433 } else if (token == "\\graphics") {
434 params.readGraphicsDriver(lex);
435 } else if (token == "\\fontscheme") {
437 params.fonts = lex.GetString();
438 } else if (token == "\\noindent") {
439 par->noindent = true;
440 } else if (token == "\\fill_top") {
441 par->added_space_top = VSpace(VSpace::VFILL);
442 } else if (token == "\\fill_bottom") {
443 par->added_space_bottom = VSpace(VSpace::VFILL);
444 } else if (token == "\\line_top") {
445 par->line_top = true;
446 } else if (token == "\\line_bottom") {
447 par->line_bottom = true;
448 } else if (token == "\\pagebreak_top") {
449 par->pagebreak_top = true;
450 } else if (token == "\\pagebreak_bottom") {
451 par->pagebreak_bottom = true;
452 } else if (token == "\\start_of_appendix") {
453 par->start_of_appendix = true;
454 } else if (token == "\\paragraph_separation") {
455 tmpret = lex.FindToken(string_paragraph_separation);
456 if (tmpret == -1) tmpret++;
457 if (tmpret != LYX_LAYOUT_DEFAULT)
458 params.paragraph_separation =
459 static_cast<BufferParams::PARSEP>(tmpret);
460 } else if (token == "\\defskip") {
462 params.defskip = VSpace(lex.GetString());
463 } else if (token == "\\no_isolatin1") {
465 } else if (token == "\\no_babel") {
467 } else if (token == "\\no_epsfig") {
469 } else if (token == "\\epsfig") { // obsolete
470 // Indeed it is obsolete, but we HAVE to be backwards
471 // compatible until 0.14, because otherwise all figures
472 // in existing documents are irretrivably lost. (Asger)
473 params.readGraphicsDriver(lex);
474 } else if (token == "\\quotes_language") {
475 tmpret = lex.FindToken(string_quotes_language);
476 if (tmpret == -1) tmpret++;
477 if (tmpret != LYX_LAYOUT_DEFAULT) {
478 InsetQuotes::quote_language tmpl =
479 InsetQuotes::EnglishQ;
482 tmpl = InsetQuotes::EnglishQ;
485 tmpl = InsetQuotes::SwedishQ;
488 tmpl = InsetQuotes::GermanQ;
491 tmpl = InsetQuotes::PolishQ;
494 tmpl = InsetQuotes::FrenchQ;
497 tmpl = InsetQuotes::DanishQ;
500 params.quotes_language = tmpl;
502 } else if (token == "\\quotes_times") {
504 switch(lex.GetInteger()) {
506 params.quotes_times = InsetQuotes::SingleQ;
509 params.quotes_times = InsetQuotes::DoubleQ;
512 } else if (token == "\\papersize") {
516 tmpret = lex.FindToken(string_papersize);
519 tmpret = lex.FindToken(string_oldpapersize);
524 params.papersize2 = tmpret;
525 } else if (token == "\\paperpackage") {
526 tmpret = lex.FindToken(string_paperpackages);
529 params.paperpackage = BufferParams::PACKAGE_NONE;
531 params.paperpackage = tmpret;
532 } else if (token == "\\use_geometry") {
534 params.use_geometry = lex.GetInteger();
535 } else if (token == "\\use_amsmath") {
537 params.use_amsmath = lex.GetInteger();
538 } else if (token == "\\paperorientation") {
539 tmpret = lex.FindToken(string_orientation);
540 if (tmpret == -1) tmpret++;
541 if (tmpret != LYX_LAYOUT_DEFAULT)
542 params.orientation = static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
543 } else if (token == "\\paperwidth") {
545 params.paperwidth = lex.GetString();
546 } else if (token == "\\paperheight") {
548 params.paperheight = lex.GetString();
549 } else if (token == "\\leftmargin") {
551 params.leftmargin = lex.GetString();
552 } else if (token == "\\topmargin") {
554 params.topmargin = lex.GetString();
555 } else if (token == "\\rightmargin") {
557 params.rightmargin = lex.GetString();
558 } else if (token == "\\bottommargin") {
560 params.bottommargin = lex.GetString();
561 } else if (token == "\\headheight") {
563 params.headheight = lex.GetString();
564 } else if (token == "\\headsep") {
566 params.headsep = lex.GetString();
567 } else if (token == "\\footskip") {
569 params.footskip = lex.GetString();
570 } else if (token == "\\paperfontsize") {
572 params.fontsize = strip(lex.GetString());
573 } else if (token == "\\papercolumns") {
575 params.columns = lex.GetInteger();
576 } else if (token == "\\papersides") {
578 switch(lex.GetInteger()) {
580 case 1: params.sides = LyXTextClass::OneSide; break;
581 case 2: params.sides = LyXTextClass::TwoSides; break;
583 } else if (token == "\\paperpagestyle") {
585 params.pagestyle = strip(lex.GetString());
586 } else if (token == "\\bullet") {
588 int index = lex.GetInteger();
590 int temp_int = lex.GetInteger();
591 params.user_defined_bullets[index].setFont(temp_int);
592 params.temp_bullets[index].setFont(temp_int);
594 temp_int = lex.GetInteger();
595 params.user_defined_bullets[index].setCharacter(temp_int);
596 params.temp_bullets[index].setCharacter(temp_int);
598 temp_int = lex.GetInteger();
599 params.user_defined_bullets[index].setSize(temp_int);
600 params.temp_bullets[index].setSize(temp_int);
602 string temp_str = lex.GetString();
603 if (temp_str != "\\end_bullet") {
604 // this element isn't really necessary for
605 // parsing but is easier for humans
606 // to understand bullets. Put it back and
607 // set a debug message?
608 lex.printError("\\end_bullet expected, got" + temp_str);
609 //how can I put it back?
611 } else if (token == "\\bulletLaTeX") {
613 int index = lex.GetInteger();
615 string temp_str = lex.GetString(), sum_str;
616 while (temp_str != "\\end_bullet") {
617 // this loop structure is needed when user
618 // enters an empty string since the first
619 // thing returned will be the \\end_bullet
621 // if the LaTeX entry has spaces. Each element
622 // therefore needs to be read in turn
625 temp_str = lex.GetString();
627 params.user_defined_bullets[index].setText(sum_str);
628 params.temp_bullets[index].setText(sum_str);
629 } else if (token == "\\secnumdepth") {
631 params.secnumdepth = lex.GetInteger();
632 } else if (token == "\\tocdepth") {
634 params.tocdepth = lex.GetInteger();
635 } else if (token == "\\baselinestretch") { // now obsolete
636 lex.nextToken(); // should not be used directly
638 // Will probably keep a kind of support just for
640 params.spacing.set(Spacing::Other, lex.GetFloat());
641 } else if (token == "\\spacing") {
643 string tmp = strip(lex.GetString());
644 if (tmp == "single") {
645 params.spacing.set(Spacing::Single);
646 } else if (tmp == "onehalf") {
647 params.spacing.set(Spacing::Onehalf);
648 } else if (tmp == "double") {
649 params.spacing.set(Spacing::Double);
650 } else if (tmp == "other") {
652 params.spacing.set(Spacing::Other,
655 lex.printError("Unknown spacing token: '$$Token'");
657 } else if (token == "\\float_placement") {
659 params.float_placement = lex.GetString();
660 } else if (token == "\\cursor") {
661 // this is obsolete, so we just skip it.
663 } else if (token == "\\family") {
665 font.setLyXFamily(lex.GetString());
666 } else if (token == "\\series") {
668 font.setLyXSeries(lex.GetString());
669 } else if (token == "\\shape") {
671 font.setLyXShape(lex.GetString());
672 } else if (token == "\\size") {
674 font.setLyXSize(lex.GetString());
675 } else if (token == "\\latex") {
677 string tok = lex.GetString();
678 // This is dirty, but gone with LyX3. (Asger)
679 if (tok == "no_latex")
680 font.setLatex(LyXFont::OFF);
681 else if (tok == "latex")
682 font.setLatex(LyXFont::ON);
683 else if (tok == "default")
684 font.setLatex(LyXFont::INHERIT);
686 lex.printError("Unknown LaTeX font flag "
688 } else if (token == "\\emph") {
690 font.setEmph(font.setLyXMisc(lex.GetString()));
691 } else if (token == "\\bar") {
693 string tok = lex.GetString();
694 // This is dirty, but gone with LyX3. (Asger)
696 font.setUnderbar(LyXFont::ON);
697 else if (tok == "no")
698 font.setUnderbar(LyXFont::OFF);
699 else if (tok == "default")
700 font.setUnderbar(LyXFont::INHERIT);
702 lex.printError("Unknown bar font flag "
704 } else if (token == "\\noun") {
706 font.setNoun(font.setLyXMisc(lex.GetString()));
707 } else if (token == "\\color") {
709 font.setLyXColor(lex.GetString());
710 } else if (token == "\\align") {
711 tmpret = lex.FindToken(string_align);
712 if (tmpret == -1) tmpret++;
713 if (tmpret != LYX_LAYOUT_DEFAULT) {
715 for (; tmpret>0; tmpret--)
716 tmpret2 = tmpret2 * 2;
717 par->align = LyXAlignment(tmpret2);
719 } else if (token == "\\added_space_top"){
721 par->added_space_top = lex.GetString();
722 } else if (token == "\\added_space_bottom") {
724 par->added_space_bottom = lex.GetString();
725 } else if (token == "\\pextra_type") {
727 par->pextra_type = lex.GetInteger();
728 } else if (token == "\\pextra_width") {
730 par->pextra_width = lex.GetString();
731 } else if (token == "\\pextra_widthp") {
733 par->pextra_widthp = lex.GetString();
734 } else if (token == "\\pextra_alignment") {
736 par->pextra_alignment = lex.GetInteger();
737 } else if (token == "\\pextra_hfill") {
739 par->pextra_hfill = lex.GetInteger();
740 } else if (token == "\\pextra_start_minipage") {
742 par->pextra_start_minipage = lex.GetInteger();
743 } else if (token == "\\labelwidthstring") {
745 par->labelwidthstring = lex.GetString();
746 /* do not delete this token, it is still needed! */
747 } else if (token == "\\end_inset") {
748 /* simple ignore this. The insets do not have
750 // but insets should read it, it is a part of
751 //the inset isn't it? Lgb.
752 } else if (token == "\\begin_inset") {
754 tmptok = lex.GetString();
755 /* test the different insets */
756 if (tmptok == "Quotes") {
757 inset = new InsetQuotes;
759 par->InsertChar(pos, LyXParagraph::META_INSET);
760 par->InsertInset(pos, inset);
761 par->SetFont(pos, font);
763 #if 0 // should not be used any more
764 } else if (tmptok == "Latex") {
765 // This one is on its way out
767 tmptok = strip(lex.GetString());
768 //lyxerr <<string(tmptok[0]));
769 if (tmptok[0] == '\\') {
770 // then this latex is a
772 InsetCommand *tmpinset =
774 tmpinset->scanCommand(tmptok);
777 // This should not use InsetLaTexDel
778 // it should rather insert text into
779 // the paragraph and mark it as tex.
780 inset = new InsetLatex(tmptok);
782 par->InsertChar(pos, LyXParagraph::META_INSET);
783 par->InsertInset(pos, inset);
784 par->SetFont(pos, font);
787 #if 0 // should not be used any more
788 } else if (tmptok == "LatexDel") {
789 // This one is on its way out...
791 tmptok = strip(lex.GetString());
792 //lyxerr <<string(tmptok[0]));
793 if (tmptok == "\\tableofcontents") {
794 inset = new InsetTOC(this);
795 } else if (tmptok == "\\listoffigures") {
796 inset = new InsetLOF(this);
797 } else if (tmptok == "\\listoftables") {
798 inset = new InsetLOT(this);
799 } else if (tmptok == "\\listofalgorithms") {
800 inset = new InsetLOA(this);
801 } else if (contains(tmptok, "\\ref{")
802 || contains(tmptok, "\\pageref{")) {
803 inset = new InsetRef(tmptok, this);
804 } else if (contains(tmptok, "\\url{")
805 || contains(tmptok, "\\htmlurl{")) {
806 string cont, opt, tmptmptok, cmdname;
808 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
813 tmptmptok = lex.GetString();
814 if(tmptmptok[0] == '\\') {
815 if( tmptmptok == "\\backslash")
825 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
830 tmptmptok = lex.GetString();
831 if(tmptmptok[0] == '\\') {
832 if( tmptmptok == "\\backslash")
842 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
845 if(contains(tmptok, "\\url{"))
846 cmdname = string("url");
848 cmdname = string("htmlurl");
851 inset = new InsetUrl(cmdname, cont, opt);
852 } else if (tmptok[0] == '\\') {
853 // then this latex del is a
855 InsetCommand * tmpinset =
857 tmpinset->scanCommand(tmptok);
860 par->InsertChar(pos, LyXParagraph::META_INSET);
861 par->InsertInset(pos, inset);
862 par->SetFont(pos, font);
865 } else if (tmptok == "\\i") {
866 inset = new InsetLatexAccent;
868 par->InsertChar(pos, LyXParagraph::META_INSET);
869 par->InsertInset(pos, inset);
870 par->SetFont(pos, font);
872 } else if (tmptok == "FormulaMacro") {
873 inset = new InsetFormulaMacro;
875 par->InsertChar(pos, LyXParagraph::META_INSET);
876 par->InsertInset(pos, inset);
877 par->SetFont(pos, font);
879 } else if (tmptok == "Formula") {
880 inset = new InsetFormula;
882 par->InsertChar(pos, LyXParagraph::META_INSET);
883 par->InsertInset(pos, inset);
884 par->SetFont(pos, font);
886 } else if (tmptok == "Figure") {
887 inset = new InsetFig(100, 100, this);
889 par->InsertChar(pos, LyXParagraph::META_INSET);
890 par->InsertInset(pos, inset);
891 par->SetFont(pos, font);
893 } else if (tmptok == "Label") {
894 // Kept for compability. Remove in 0.13.
896 string tmp = "\\label{";
897 tmp += lex.GetString();
899 inset = new InsetLabel(tmp);
900 par->InsertChar(pos, LyXParagraph::META_INSET);
901 par->InsertInset(pos, inset);
902 par->SetFont(pos, font);
905 } else if (tmptok == "Info") {
906 inset = new InsetInfo;
908 par->InsertChar(pos, LyXParagraph::META_INSET);
909 par->InsertInset(pos, inset);
910 par->SetFont(pos, font);
912 } else if (tmptok == "Include") {
913 inset = new InsetInclude(string(), this);
915 par->InsertChar(pos, LyXParagraph::META_INSET);
916 par->InsertInset(pos, inset);
917 par->SetFont(pos, font);
919 } else if (tmptok == "LatexCommand") {
922 if (inscmd.getCmdName() == "cite") {
923 inset = new InsetCitation(inscmd.getContents(), inscmd.getOptions());
924 } else if (inscmd.getCmdName() == "bibitem") {
925 lex.printError("Wrong place for bibitem");
926 inset = inscmd.Clone();
927 } else if (inscmd.getCmdName() == "BibTeX") {
928 inset = new InsetBibtex(inscmd.getContents(), inscmd.getOptions(), this);
929 } else if (inscmd.getCmdName() == "index") {
930 inset = new InsetIndex(inscmd.getContents());
931 } else if (inscmd.getCmdName() == "include") {
932 inset = new InsetInclude(inscmd.getContents(), this);
933 } else if (inscmd.getCmdName() == "label") {
934 inset = new InsetLabel(inscmd.getCommand());
935 } else if (inscmd.getCmdName() == "url"
936 || inscmd.getCmdName() == "htmlurl") {
937 inset = new InsetUrl(inscmd.getCommand());
938 } else if (inscmd.getCmdName() == "ref"
939 || inscmd.getCmdName() == "pageref") {
940 if (!inscmd.getOptions().empty() || !inscmd.getContents().empty()) {
941 inset = new InsetRef(inscmd, this);
943 /* This condition comes from a temporary solution
944 to the latexdel ref inset that was transformed to an empty ref
945 inset plus the body surronded by latexdel insets */
947 string cont, opt, tmptmptok, cmdname;
949 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
954 tmptmptok = lex.GetString();
955 if(tmptmptok[0] == '\\') {
956 if( tmptmptok == "\\backslash")
966 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
971 tmptmptok = lex.GetString();
972 if(tmptmptok[0] == '\\') {
973 if( tmptmptok == "\\backslash")
983 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
989 cmdname = "\\" + inscmd.getCmdName();
990 cmdname += "[" + cont + "]";
991 cmdname += "{" + opt + "}";
992 inset = new InsetRef(cmdname, this);
994 } else if (inscmd.getCmdName() == "tableofcontents") {
995 inset = new InsetTOC(this);
996 } else if (inscmd.getCmdName() == "listoffigures") {
997 inset = new InsetLOF(this);
998 } else if (inscmd.getCmdName() == "listofalgorithms") {
999 inset = new InsetLOA(this);
1000 } else if (inscmd.getCmdName() == "listoftables") {
1001 inset = new InsetLOT(this);
1002 } else if (inscmd.getCmdName() == "printindex") {
1003 inset = new InsetPrintIndex(this);
1004 } else if (inscmd.getCmdName() == "lyxparent") {
1005 inset = new InsetParent(inscmd.getContents(), this);
1007 // The following three are only for compatibility
1008 if (inscmd.getCmdName() == "-") {
1009 inset = new InsetSpecialChar(InsetSpecialChar::HYPHENATION);
1010 } else if (inscmd.getCmdName() == "@.") {
1011 inset = new InsetSpecialChar(InsetSpecialChar::END_OF_SENTENCE);
1012 } else if (inscmd.getCmdName() == "ldots") {
1013 inset = new InsetSpecialChar(InsetSpecialChar::LDOTS);
1015 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 & filename, 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 && (filename == this->filename)) {
1174 // Here we should come with a question if we should
1175 // perform the write anyway.
1177 lyxerr << _("Error! Document is read-only: ")
1178 << filename << endl;
1180 WriteAlert(_("Error! Document is read-only: "),
1185 FileInfo finfo(filename);
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: ")
1191 << filename << endl;
1193 WriteFSAlert(_("Error! Cannot write file: "),
1198 ofstream ofs(filename.c_str());
1201 lyxerr << _("Error! Cannot open file: ")
1202 << filename << endl;
1204 WriteFSAlert(_("Error! Canno open file:"),
1208 // The top of the file should not be written by params.
1209 // collect some very important information
1210 string userName(getUserName()) ;
1212 // write out a comment in the top of the file
1213 ofs << "#LyX 1.1 Copyright 1995-1999 Matthias Ettrich"
1214 " and the LyX Team\n";
1215 ofs.setf(ios::showpoint|ios::fixed);
1217 ofs << "\\lyxformat " << setw(4) << LYX_FORMAT << "\n";
1219 // now write out the buffer paramters.
1220 params.writeFile(ofs);
1222 char footnoteflag = 0;
1225 // this will write out all the paragraphs
1226 // using recursive descent.
1227 paragraph->writeFile(ofs, params, footnoteflag, depth);
1229 // Write marker that shows file is complete
1230 ofs << "\n\\the_end" << endl;
1232 // how to check if close went ok?
1237 void Buffer::writeFileAscii(string const & filename, int linelen)
1239 LyXFont font1, font2;
1241 char c, footnoteflag = 0, depth = 0;
1243 LyXParagraph::size_type i;
1244 int j, h, ltype = 0, ltype_depth = 0,
1245 * clen = 0, actcell = 0, actpos = 0, cell = 0, cells = 0,
1248 bool ref_printed = false;
1250 ofstream ofs(filename.c_str());
1252 WriteFSAlert(_("Error: Cannot write file:"), filename);
1256 string fname1 = TmpFileName();
1257 LyXParagraph * par = paragraph;
1261 if (par->footnoteflag != LyXParagraph::NO_FOOTNOTE ||
1263 par->previous->footnoteflag == LyXParagraph::NO_FOOTNOTE){
1265 /* begins a footnote environment ? */
1266 if (footnoteflag != par->footnoteflag) {
1267 footnoteflag = par->footnoteflag;
1269 j = strlen(string_footnotekinds[par->footnotekind])+4;
1270 if (currlinelen + j > linelen)
1273 << string_footnotekinds[par->footnotekind] << "] ";
1278 /* begins or ends a deeper area ?*/
1279 if (depth != par->depth) {
1280 if (par->depth > depth) {
1281 while (par->depth > depth) {
1286 while (par->depth < depth) {
1292 /* First write the layout */
1293 tmp = textclasslist.NameOfLayout(params.textclass, par->layout);
1294 if (tmp == "Itemize") {
1296 ltype_depth = depth+1;
1297 } else if (tmp == "Enumerate") {
1299 ltype_depth = depth+1;
1300 } else if (strstr(tmp.c_str(), "ection")) {
1302 ltype_depth = depth+1;
1303 } else if (strstr(tmp.c_str(), "aragraph")) {
1305 ltype_depth = depth+1;
1306 } else if (tmp == "Description") {
1308 ltype_depth = depth+1;
1309 } else if (tmp == "Abstract") {
1312 } else if (tmp == "Bibliography") {
1320 /* maybe some vertical spaces */
1322 /* the labelwidthstring used in lists */
1326 /* some pagebreaks? */
1330 /* what about the alignment */
1333 /* dummy layout, that means a footnote ended */
1334 footnoteflag = LyXParagraph::NO_FOOTNOTE;
1339 /* It might be a table */
1341 if (!lyxrc->ascii_roff_command.empty() &&
1342 lyxrc->ascii_roff_command != "none") {
1343 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); h++)
1415 for(j = 0; j<depth; j++)
1417 currlinelen = depth*2;
1418 if (ltype_depth > depth) {
1419 for(j = ltype_depth; j>depth; j--)
1421 currlinelen += (ltype_depth-depth)*2;
1426 font2 = par->GetFontSettings(i);
1427 if (font1.latex() != font2.latex()) {
1428 if (font2.latex() == LyXFont::OFF)
1436 c = par->GetChar(i);
1440 case LyXParagraph::META_INSET:
1441 if ((inset = par->GetInset(i))) {
1443 inset->Latex(ofs, -1);
1444 currlinelen += (ofs.tellp() - fpos);
1445 actpos += (ofs.tellp() - fpos) - 1;
1448 case LyXParagraph::META_NEWLINE:
1450 if (par->table->NumberOfCellsInRow(actcell) <= cell) {
1451 for(j = actpos; j < clen[cell-1];j++)
1454 for(j = 0; j<depth; j++)
1456 currlinelen = depth*2;
1457 if (ltype_depth > depth) {
1458 for(j = ltype_depth; j>depth; j--)
1460 currlinelen += (ltype_depth-depth)*2;
1462 for(j = 0;j<cells;j++) {
1464 for(h = 0; h < (clen[j]+1); ++h)
1468 for(j = 0; j<depth; j++)
1470 currlinelen = depth*2;
1471 if (ltype_depth > depth) {
1472 for(j = ltype_depth; j>depth; j--)
1474 currlinelen += (ltype_depth-depth)*2;
1479 for(j = actpos; j<clen[cell-1]; j++)
1485 currlinelen = actpos = 0;
1488 for(j = 0; j<depth; j++)
1490 currlinelen = depth * 2;
1491 if (ltype_depth > depth) {
1492 for(j = ltype_depth; j>depth; j--)
1494 currlinelen += (ltype_depth-depth)*2;
1498 case LyXParagraph::META_HFILL:
1501 case LyXParagraph::META_PROTECTED_SEPARATOR:
1508 if (currlinelen > linelen - 10
1509 && c == ' ' && i + 2 < par->size()) {
1511 for(j = 0; j < depth; ++j)
1513 currlinelen = depth * 2;
1514 if (ltype_depth > depth) {
1515 for(j = ltype_depth;
1518 currlinelen += (ltype_depth-depth)*2;
1520 } else if (c != '\0')
1523 lyxerr.debug() << "writeAsciiFile: NULL char in structure." << endl;
1529 for(j = actpos; j < clen[cell - 1]; ++j)
1532 for(j = 0; j<depth; j++)
1534 currlinelen = depth * 2;
1535 if (ltype_depth > depth) {
1536 for(j = ltype_depth; j > depth; --j)
1538 currlinelen += (ltype_depth-depth)*2;
1540 for(j = 0;j<cells; ++j) {
1542 for(h = 0; h < (clen[j] + 1); ++h)
1555 void Buffer::makeLaTeXFile(string const & filename,
1556 string const & original_path,
1557 bool nice, bool only_body)
1559 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
1560 params.textclass = GetCurrentTextClass();
1561 niceFile = nice; // this will be used by Insetincludes.
1563 tex_code_break_column = lyxrc->ascii_linelen;
1565 LyXTextClass const & tclass =
1566 textclasslist.TextClass(params.textclass);
1568 ofstream ofs(filename.c_str());
1570 WriteFSAlert(_("Error: Cannot open file:"), filename);
1574 // validate the buffer.
1575 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
1576 LaTeXFeatures features(tclass.numLayouts());
1578 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
1581 // The starting paragraph of the coming rows is the
1582 // first paragraph of the document. (Asger)
1583 texrow.start(paragraph, 0);
1585 string userName(getUserName());
1588 if (!only_body && nice) {
1589 LFile += "%% This LaTeX-file was created by <";
1590 LFile += userName + "> " + date();
1591 LFile += "%% LyX 1.0 (C) 1995-1999 by Matthias Ettrich and the LyX Team\n";
1592 LFile += "\n%% Do not edit this file unless you know what you are doing.\n";
1598 lyxerr.debug() << "lyx header finished" << endl;
1599 // There are a few differences between nice LaTeX and usual files:
1600 // usual is \batchmode, uses \listfiles and has a
1601 // special input@path to allow the including of figures
1602 // with either \input or \includegraphics (what figinsets do).
1603 // batchmode is not set if there is a tex_code_break_column.
1604 // In this case somebody is interested in the generated LaTeX,
1605 // so this is OK. input@path is set when the actual parameter
1606 // original_path is set. This is done for usual tex-file, but not
1607 // for nice-latex-file. (Matthias 250696)
1610 // code for usual, NOT nice-latex-file
1611 LFile += "\\batchmode\n"; // changed
1612 // from \nonstopmode
1614 // We don't need listfiles anymore
1615 //LFile += "\\listfiles\n";
1618 if (!original_path.empty()) {
1619 LFile += "\\makeatletter\n";
1621 LFile += "\\def\\input@path{{" + original_path
1624 LFile += "\\makeatother\n";
1628 LFile += "\\documentclass";
1630 string options; // the document class options.
1632 if (tokenPos(tclass.opt_fontsize(), '|', params.fontsize) >= 0) {
1633 // only write if existing in list (and not default)
1634 options += params.fontsize;
1639 if (!params.use_geometry &&
1640 (params.paperpackage == BufferParams::PACKAGE_NONE)) {
1641 switch (params.papersize) {
1642 case BufferParams::PAPER_A4PAPER:
1643 options += "a4paper,";
1645 case BufferParams::PAPER_USLETTER:
1646 options += "letterpaper,";
1648 case BufferParams::PAPER_A5PAPER:
1649 options += "a5paper,";
1651 case BufferParams::PAPER_B5PAPER:
1652 options += "b5paper,";
1654 case BufferParams::PAPER_EXECUTIVEPAPER:
1655 options += "executivepaper,";
1657 case BufferParams::PAPER_LEGALPAPER:
1658 options += "legalpaper,";
1664 if (params.sides != tclass.sides()) {
1665 if (params.sides == 2)
1666 options += "twoside,";
1668 options += "oneside,";
1672 if (params.columns != tclass.columns()) {
1673 if (params.columns == 2)
1674 options += "twocolumn,";
1676 options += "onecolumn,";
1679 if (!params.use_geometry && params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1680 options += "landscape,";
1682 // language should be a parameter to \documentclass
1683 if (params.language != "default") {
1684 options += params.language + ',';
1687 // the user-defined options
1688 if (!params.options.empty()) {
1689 options += params.options + ',';
1692 if (!options.empty()){
1693 options = strip(options, ',');
1700 LFile += textclasslist.LatexnameOfClass(params.textclass);
1703 // end of \documentclass defs
1705 // font selection must be done before loading fontenc.sty
1706 if (params.fonts != "default") {
1707 LFile += "\\usepackage{" + params.fonts + "}\n";
1710 // this one is not per buffer
1711 if (lyxrc->fontenc != "default") {
1712 LFile += "\\usepackage[" + lyxrc->fontenc
1716 if (params.inputenc != "default") {
1717 LFile += "\\usepackage[" + params.inputenc
1722 /* at the very beginning the text parameters */
1723 if (params.paperpackage != BufferParams::PACKAGE_NONE) {
1724 switch (params.paperpackage) {
1725 case BufferParams::PACKAGE_A4:
1726 LFile += "\\usepackage{a4}\n";
1729 case BufferParams::PACKAGE_A4WIDE:
1730 LFile += "\\usepackage{a4wide}\n";
1733 case BufferParams::PACKAGE_WIDEMARGINSA4:
1734 LFile += "\\usepackage[widemargins]{a4}\n";
1739 if (params.use_geometry) {
1740 LFile += "\\usepackage{geometry}\n";
1742 LFile += "\\geometry{verbose";
1743 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1744 LFile += ",landscape";
1745 switch (params.papersize2) {
1746 case BufferParams::VM_PAPER_CUSTOM:
1747 if (!params.paperwidth.empty())
1748 LFile += ",paperwidth="
1749 + params.paperwidth;
1750 if (!params.paperheight.empty())
1751 LFile += ",paperheight="
1752 + params.paperheight;
1754 case BufferParams::VM_PAPER_USLETTER:
1755 LFile += ",letterpaper";
1757 case BufferParams::VM_PAPER_USLEGAL:
1758 LFile += ",legalpaper";
1760 case BufferParams::VM_PAPER_USEXECUTIVE:
1761 LFile += ",executivepaper";
1763 case BufferParams::VM_PAPER_A3:
1764 LFile += ",a3paper";
1766 case BufferParams::VM_PAPER_A4:
1767 LFile += ",a4paper";
1769 case BufferParams::VM_PAPER_A5:
1770 LFile += ",a5paper";
1772 case BufferParams::VM_PAPER_B3:
1773 LFile += ",b3paper";
1775 case BufferParams::VM_PAPER_B4:
1776 LFile += ",b4paper";
1778 case BufferParams::VM_PAPER_B5:
1779 LFile += ",b5paper";
1782 // default papersize ie BufferParams::VM_PAPER_DEFAULT
1783 switch (lyxrc->default_papersize) {
1784 case BufferParams::PAPER_DEFAULT: // keep compiler happy
1785 case BufferParams::PAPER_USLETTER:
1786 LFile += ",letterpaper";
1788 case BufferParams::PAPER_LEGALPAPER:
1789 LFile += ",legalpaper";
1791 case BufferParams::PAPER_EXECUTIVEPAPER:
1792 LFile += ",executivepaper";
1794 case BufferParams::PAPER_A3PAPER:
1795 LFile += ",a3paper";
1797 case BufferParams::PAPER_A4PAPER:
1798 LFile += ",a4paper";
1800 case BufferParams::PAPER_A5PAPER:
1801 LFile += ",a5paper";
1803 case BufferParams::PAPER_B5PAPER:
1804 LFile += ",b5paper";
1808 if (!params.topmargin.empty())
1809 LFile += ",tmargin=" + params.topmargin;
1810 if (!params.bottommargin.empty())
1811 LFile += ",bmargin=" + params.bottommargin;
1812 if (!params.leftmargin.empty())
1813 LFile += ",lmargin=" + params.leftmargin;
1814 if (!params.rightmargin.empty())
1815 LFile += ",rmargin=" + params.rightmargin;
1816 if (!params.headheight.empty())
1817 LFile += ",headheight=" + params.headheight;
1818 if (!params.headsep.empty())
1819 LFile += ",headsep=" + params.headsep;
1820 if (!params.footskip.empty())
1821 LFile += ",footskip=" + params.footskip;
1825 if (params.use_amsmath
1826 && !prefixIs(textclasslist.LatexnameOfClass(params.textclass), "ams")) {
1827 LFile += "\\usepackage{amsmath}\n";
1830 if (tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle) >= 0) {
1831 if (params.pagestyle == "fancy") {
1832 LFile += "\\usepackage{fancyhdr}\n";
1835 LFile += "\\pagestyle{" + params.pagestyle + "}\n";
1839 // We try to load babel late, in case it interferes
1840 // with other packages.
1841 if (params.language != "default") {
1842 LFile += "\\usepackage{babel}\n";
1846 if (params.secnumdepth != tclass.secnumdepth()) {
1847 LFile += "\\setcounter{secnumdepth}{";
1848 LFile += tostr(params.secnumdepth);
1852 if (params.tocdepth != tclass.tocdepth()) {
1853 LFile += "\\setcounter{tocdepth}{";
1854 LFile += tostr(params.tocdepth);
1859 if (params.paragraph_separation) {
1860 switch (params.defskip.kind()) {
1861 case VSpace::SMALLSKIP:
1862 LFile += "\\setlength\\parskip{\\smallskipamount}\n";
1864 case VSpace::MEDSKIP:
1865 LFile += "\\setlength\\parskip{\\medskipamount}\n";
1867 case VSpace::BIGSKIP:
1868 LFile += "\\setlength\\parskip{\\bigskipamount}\n";
1870 case VSpace::LENGTH:
1871 LFile += "\\setlength\\parskip{"
1872 + params.defskip.length().asLatexString()
1875 default: // should never happen // Then delete it.
1876 LFile += "\\setlength\\parskip{\\medskipamount}\n";
1881 LFile += "\\setlength\\parindent{0pt}\n";
1885 // Write out what we've generated so far...and reset LFile
1889 // Now insert the LyX specific LaTeX commands...
1890 string preamble, tmppreamble;
1892 // The optional packages;
1893 preamble = features.getPackages(params);
1895 // this might be useful...
1896 preamble += "\n\\makeatletter\n\n";
1898 // Some macros LyX will need
1899 tmppreamble = features.getMacros(params);
1901 if (!tmppreamble.empty()) {
1902 preamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1903 "LyX specific LaTeX commands.\n"
1904 + tmppreamble + '\n';
1907 // the text class specific preamble
1908 tmppreamble = features.getTClassPreamble(params);
1909 if (!tmppreamble.empty()) {
1910 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1911 "Textclass specific LaTeX commands.\n"
1912 + tmppreamble + '\n';
1915 /* the user-defined preamble */
1916 if (!params.preamble.empty()) {
1917 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1918 "User specified LaTeX commands.\n"
1919 + params.preamble + '\n';
1922 preamble += "\\makeatother\n\n";
1924 // Itemize bullet settings need to be last in case the user
1925 // defines their own bullets that use a package included
1926 // in the user-defined preamble -- ARRae
1927 // Actually it has to be done much later than that
1928 // since some packages like frenchb make modifications
1929 // at \begin{document} time -- JMarc
1931 for (int i = 0; i < 4; ++i) {
1932 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
1933 if (bullets_def.empty())
1934 bullets_def="\\AtBeginDocument{\n";
1935 bullets_def += " \\renewcommand{\\labelitemi";
1937 // `i' is one less than the item to modify
1944 bullets_def += "ii";
1950 bullets_def += "}{" +
1951 params.user_defined_bullets[i].getText()
1956 if (!bullets_def.empty())
1957 preamble += bullets_def + "}\n\n";
1959 for (int j = countChar(preamble, '\n'); j-- ;) {
1966 LFile += "\\begin{document}\n\n";
1970 lyxerr.debug() << "preamble finished, now the body." << endl;
1972 bool was_title = false;
1973 bool already_title = false;
1979 LyXParagraph * par = paragraph;
1985 lyxerr[Debug::LATEX] << "Error in MakeLateXFile."
1987 LyXLayout const & layout = textclasslist.Style(params.textclass,
1990 if (layout.intitle) {
1991 if (already_title) {
1992 lyxerr <<"Error in MakeLatexFile: You"
1993 " should not mix title layouts"
1994 " with normal ones." << endl;
1997 } else if (was_title && !already_title) {
1998 LFile += "\\maketitle\n";
2000 already_title = true;
2003 // We are at depth 0 so we can just use
2004 // ordinary \footnote{} generation
2005 // flag this with ftcount
2007 if (layout.isEnvironment()
2008 || par->pextra_type != LyXParagraph::PEXTRA_NONE) {
2009 par = par->TeXEnvironment(LFile, texrow,
2010 ftnote, ft_texrow, ftcount);
2012 par = par->TeXOnePar(LFile, texrow,
2013 ftnote, ft_texrow, ftcount);
2016 // Write out what we've generated...and reset LFile
2019 LFile += "\\addtocounter{footnote}{-";
2020 LFile += tostr(ftcount - 1);
2024 texrow += ft_texrow;
2029 if (loop_count == 2) {
2030 // fwrite()ing every second time through the loop
2031 // gains a few extra % of speed; going higher than
2032 // 2 will slow things down again. I'll look at
2033 // LFile.length() in a future revision. ARRae
2040 // It might be that we only have a title in this document
2041 if (was_title && !already_title) {
2042 LFile += "\\maketitle\n";
2047 LFile += "\\end{document}\n";
2050 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
2052 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
2056 // Just to be sure. (Asger)
2059 // Write out what we've generated...and reset LFile
2063 // tex_code_break_column's value is used to decide
2064 // if we are in batchmode or not (within mathed_write()
2065 // in math_write.C) so we must set it to a non-zero
2066 // value when we leave otherwise we save incorrect .lyx files.
2067 tex_code_break_column = lyxrc->ascii_linelen;
2069 // How to check if the close went ok when using fstreams
2071 lyxerr.debug() << "Finished making latex file." << endl;
2075 bool Buffer::isLatex() const
2077 return textclasslist.TextClass(params.textclass).outputType() == LATEX;
2081 bool Buffer::isLinuxDoc() const
2083 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC;
2087 bool Buffer::isLiterate() const
2089 return textclasslist.TextClass(params.textclass).outputType() == LITERATE;
2093 bool Buffer::isDocBook() const
2095 return textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2099 bool Buffer::isSGML() const
2101 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC ||
2102 textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2106 void Buffer::sgmlOpenTag(ostream & os, int depth,
2107 string const & latexname) const
2109 static char * space[] = {" "," ", " ", " ", " ", " ",
2114 os << space[depth] << "<" << latexname << ">\n";
2118 void Buffer::sgmlCloseTag(ostream & os, int depth,
2119 string const & latexname) const
2121 static char * space[] = {" ", " ", " ", " ", " ",
2125 os << space[depth] << "</" << latexname << ">\n";
2129 void Buffer::makeLinuxDocFile(string const & filename, int column)
2131 LyXParagraph * par = paragraph;
2133 string top_element = textclasslist.LatexnameOfClass(params.textclass);
2134 string environment_stack[10];
2137 int depth = 0; /* paragraph depth */
2139 ofstream ofs(filename.c_str());
2142 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), filename);
2146 tex_code_break_column = column;
2149 if (params.preamble.empty()) {
2150 ofs << "<!doctype linuxdoc system>\n\n";
2153 ofs << "<!doctype linuxdoc system \n [ "
2154 << params.preamble << " \n]>\n\n";
2157 string userName(getUserName());
2158 ofs << "<!-- LinuxDoc file was created by LyX 1.0 (C) 1995-1999 "
2159 << "by <" << userName << "> " << (char*)date() << " -->\n";
2161 if(params.options.empty())
2162 sgmlOpenTag(ofs, 0, top_element);
2164 string top = top_element;
2166 top += params.options;
2167 sgmlOpenTag(ofs, 0, top);
2171 int desc_on = 0; /* description mode*/
2172 LyXLayout const & style =
2173 textclasslist.Style(GetCurrentTextClass(),
2175 par->AutoDeleteInsets();
2177 /* treat <toc> as a special case for compatibility with old code */
2178 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2179 Inset * inset = par->GetInset(0);
2180 char lyx_code = inset->LyxCode();
2181 if (lyx_code == Inset::TOC_CODE){
2182 string temp = "toc";
2183 sgmlOpenTag(ofs, depth, temp);
2186 linuxDocHandleFootnote(ofs, par, depth);
2191 /* environment tag closing */
2192 for( ; depth > par->depth; --depth) {
2193 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2194 environment_stack[depth].clear();
2197 /* write opening SGML tags */
2198 switch(style.latextype) {
2199 case LATEX_PARAGRAPH:
2200 if(depth == par->depth
2201 && !environment_stack[depth].empty()) {
2202 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2203 environment_stack[depth].clear();
2209 sgmlOpenTag(ofs, depth, style.latexname());
2214 LinuxDocError(par, 0, _("Error : Wrong depth for LatexType Command.\n"));
2216 if (!environment_stack[depth].empty()){
2217 sgmlCloseTag(ofs, depth,
2218 environment_stack[depth]);
2222 environment_stack[depth].clear();
2223 sgmlOpenTag(ofs, depth, style.latexname());
2226 case LATEX_ENVIRONMENT:
2227 case LATEX_ITEM_ENVIRONMENT:
2228 if(depth == par->depth
2229 && environment_stack[depth] != style.latexname()
2230 && !environment_stack[depth].empty()) {
2232 sgmlCloseTag(ofs, depth,
2233 environment_stack[depth]);
2234 environment_stack[depth].clear();
2236 if (depth < par->depth) {
2238 environment_stack[depth].clear();
2240 if (environment_stack[depth] != style.latexname()) {
2243 sgmlOpenTag(ofs, depth, temp);
2245 environment_stack[depth] = style.latexname();
2246 sgmlOpenTag(ofs, depth, environment_stack[depth]);
2248 if(style.latextype == LATEX_ENVIRONMENT) break;
2250 desc_on = (style.labeltype == LABEL_MANUAL);
2257 sgmlOpenTag(ofs, depth + 1, item_name);
2260 sgmlOpenTag(ofs, depth, style.latexname());
2265 SimpleLinuxDocOnePar(ofs, par, desc_on, depth);
2268 linuxDocHandleFootnote(ofs, par, depth);
2270 while(par && par->IsDummy());
2273 /* write closing SGML tags */
2274 switch(style.latextype) {
2276 case LATEX_ENVIRONMENT:
2277 case LATEX_ITEM_ENVIRONMENT:
2280 sgmlCloseTag(ofs, depth, style.latexname());
2285 /* Close open tags */
2286 for(; depth > 0; --depth)
2287 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2289 if(!environment_stack[depth].empty())
2290 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2293 sgmlCloseTag(ofs, 0, top_element);
2296 // How to check for successful close
2300 void Buffer::linuxDocHandleFootnote(ostream & os, LyXParagraph * & par,
2303 string tag = "footnote";
2305 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2306 sgmlOpenTag(os, depth + 1, tag);
2307 SimpleLinuxDocOnePar(os, par, 0, depth + 1);
2308 sgmlCloseTag(os, depth + 1, tag);
2314 void Buffer::DocBookHandleCaption(ostream & os, string & inner_tag,
2315 int const depth, int desc_on,
2316 LyXParagraph * & par)
2318 LyXParagraph * tpar = par;
2319 string tmp_par, extra_par;
2320 while (tpar && (tpar->footnoteflag != LyXParagraph::NO_FOOTNOTE) &&
2321 (tpar->layout != textclasslist.NumberOfLayout(params.textclass,
2325 tpar->layout == textclasslist.NumberOfLayout(params.textclass,
2326 "Caption").second) {
2327 sgmlOpenTag(os, depth + 1, inner_tag);
2328 SimpleDocBookOnePar(tmp_par, extra_par, tpar,
2329 desc_on, depth + 2);
2330 tmp_par = strip(tmp_par);
2331 tmp_par = frontStrip(tmp_par);
2333 sgmlCloseTag(os, depth+1, inner_tag);
2334 if(!extra_par.empty())
2340 void Buffer::DocBookHandleFootnote(ostream & os, LyXParagraph * & par,
2343 string tag, inner_tag;
2344 string tmp_par, extra_par;
2345 bool inner_span = false;
2348 // This is not how I like to see enums. They should not be anonymous
2349 // and variables of its type should not be declared right after the
2350 // last brace. (Lgb)
2357 } last = NO_ONE, present = FOOTNOTE_LIKE;
2359 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2360 if(last == present) {
2362 if(!tmp_par.empty()) {
2365 sgmlCloseTag(os, depth+1, inner_tag);
2366 sgmlOpenTag(os, depth+1, inner_tag);
2373 if(!inner_tag.empty()) sgmlCloseTag(os, depth+1, inner_tag);
2374 if(!extra_par.empty()) os << extra_par;
2375 if(!tag.empty()) sgmlCloseTag(os, depth, tag);
2378 switch (par->footnotekind) {
2379 case LyXParagraph::FOOTNOTE:
2380 case LyXParagraph::ALGORITHM:
2383 present = FOOTNOTE_LIKE;
2386 case LyXParagraph::MARGIN:
2389 present = MARGIN_LIKE;
2392 case LyXParagraph::FIG:
2393 case LyXParagraph::WIDE_FIG:
2395 inner_tag = "title";
2399 case LyXParagraph::TAB:
2400 case LyXParagraph::WIDE_TAB:
2402 inner_tag = "title";
2407 sgmlOpenTag(os, depth, tag);
2408 if ((present == TAB_LIKE) || (present == FIG_LIKE)) {
2409 DocBookHandleCaption(os, inner_tag, depth,
2413 sgmlOpenTag(os, depth + 1, inner_tag);
2416 // ignore all caption here, we processed them above!!!
2417 if (par->layout != textclasslist.NumberOfLayout(params.textclass,
2418 "Caption").second) {
2419 SimpleDocBookOnePar(tmp_par, extra_par, par,
2420 desc_on, depth + 2);
2422 tmp_par = frontStrip(strip(tmp_par));
2428 if(!inner_tag.empty()) sgmlCloseTag(os, depth+1, inner_tag);
2429 if(!extra_par.empty()) os << extra_par;
2430 if(!tag.empty()) sgmlCloseTag(os, depth, tag);
2434 /* push a tag in a style stack */
2435 void Buffer::push_tag(ostream & os, char const * tag,
2436 int & pos, char stack[5][3])
2440 /* pop all previous tags */
2441 for (j = pos; j >= 0; --j)
2442 os << "</" << stack[j] << ">";
2445 sprintf(stack[++pos], "%s", tag);
2448 for (j = 0; j <= pos; ++j)
2449 os << "<" << stack[j] << ">";
2453 // pop a tag from a style stack
2454 void Buffer::pop_tag(ostream & os, char const * tag,
2455 int & pos, char stack[5][3])
2459 // pop all tags till specified one
2460 for (j = pos; (j >= 0) && (strcmp(stack[j], tag)); --j)
2461 os << "</" << stack[j] << ">";
2464 os << "</" << tag << ">";
2466 // push all tags, but the specified one
2467 for (j = j + 1; j <= pos; ++j) {
2468 os << "<" << stack[j] << ">";
2469 strcpy(stack[j-1], stack[j]);
2475 /* handle internal paragraph parsing -- layout already processed */
2477 // checks, if newcol chars should be put into this line
2478 // writes newline, if necessary.
2480 void linux_doc_line_break(ostream & os, unsigned int & colcount,
2481 const unsigned int newcol)
2484 if (colcount > lyxrc->ascii_linelen) {
2486 colcount = newcol; // assume write after this call
2491 void Buffer::SimpleLinuxDocOnePar(ostream & os, LyXParagraph * par,
2492 int desc_on, int const depth)
2494 LyXFont font1, font2;
2497 LyXParagraph::size_type main_body;
2499 LyXLayout const & style = textclasslist.Style(params.textclass,
2502 char family_type = 0; // family font flag
2503 bool is_bold = false; // series font flag
2504 char shape_type = 0; // shape font flag
2505 bool is_em = false; // emphasis (italic) font flag
2507 int stack_num = -1; // style stack position
2508 char stack[5][3]; // style stack
2509 unsigned int char_line_count = 5; // Heuristic choice ;-)
2511 if (style.labeltype != LABEL_MANUAL)
2514 main_body = par->BeginningOfMainBody();
2516 /* gets paragraph main font */
2518 font1 = style.labelfont;
2523 /* parsing main loop */
2524 for (LyXParagraph::size_type i = 0;
2525 i < par->size(); ++i) {
2527 /* handle quote tag */
2528 if (i == main_body && !par->IsDummy()) {
2533 font2 = par->getFont(i);
2535 if (font1.family() != font2.family()) {
2536 switch(family_type) {
2538 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2539 push_tag(os, "tt", stack_num, stack);
2542 else if (font2.family() == LyXFont::SANS_FAMILY) {
2543 push_tag(os, "sf", stack_num, stack);
2548 pop_tag(os, "tt", stack_num, stack);
2549 if (font2.family() == LyXFont::SANS_FAMILY) {
2550 push_tag(os, "sf", stack_num, stack);
2558 pop_tag(os, "sf", stack_num, stack);
2559 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2560 push_tag(os, "tt", stack_num, stack);
2569 /* handle bold face */
2570 if (font1.series() != font2.series()) {
2571 if (font2.series() == LyXFont::BOLD_SERIES) {
2572 push_tag(os, "bf", stack_num, stack);
2576 pop_tag(os, "bf", stack_num, stack);
2581 /* handle italic and slanted fonts */
2582 if (font1.shape() != font2.shape()) {
2583 switch(shape_type) {
2585 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2586 push_tag(os, "it", stack_num, stack);
2589 else if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2590 push_tag(os, "sl", stack_num, stack);
2595 pop_tag(os, "it", stack_num, stack);
2596 if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2597 push_tag(os, "sl", stack_num, stack);
2605 pop_tag(os, "sl", stack_num, stack);
2606 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2607 push_tag(os, "it", stack_num, stack);
2615 /* handle <em> tag */
2616 if (font1.emph() != font2.emph()) {
2617 if (font2.emph() == LyXFont::ON) {
2618 push_tag(os, "em", stack_num, stack);
2621 pop_tag(os, "em", stack_num, stack);
2626 c = par->GetChar(i);
2628 if (font2.latex() == LyXFont::ON) {
2629 // "TeX"-Mode on == > SGML-Mode on.
2631 os << c; // see LaTeX-Generation...
2633 } else if (c == LyXParagraph::META_INSET) {
2634 inset = par->GetInset(i);
2636 inset->Linuxdoc(tmp_out);
2641 if (par->linuxDocConvertChar(c, sgml_string)
2642 && !style.free_spacing) { // in freespacing
2644 // non-breaking characters
2648 linux_doc_line_break(os, char_line_count, 6);
2653 linux_doc_line_break(os, char_line_count, 1);
2659 char_line_count += sgml_string.length();
2665 /* needed if there is an optional argument but no contents */
2666 if (main_body > 0 && main_body == par->size()) {
2670 /* pop all defined Styles */
2671 for (j = stack_num; j >= 0; --j) {
2672 linux_doc_line_break(os,
2674 3 + strlen(stack[j]));
2675 os << "</" << stack[j] << ">";
2678 /* resets description flag correctly */
2681 /* <tag> not closed... */
2682 linux_doc_line_break(os, char_line_count, 6);
2686 /* fprintf(file, "</p>");*/
2692 /* print an error message */
2693 void Buffer::LinuxDocError(LyXParagraph * par, int pos,
2694 char const * message)
2696 InsetError * new_inset;
2698 /* insert an error marker in text */
2699 new_inset = new InsetError(message);
2700 par->InsertChar(pos, LyXParagraph::META_INSET);
2701 par->InsertInset(pos, new_inset);
2704 // This constant defines the maximum number of
2705 // environment layouts that can be nesteded.
2706 // The same applies for command layouts.
2707 // These values should be more than enough.
2708 // José Matos (1999/07/22)
2710 enum { MAX_NEST_LEVEL = 25};
2712 void Buffer::makeDocBookFile(string const & filename, int column)
2714 LyXParagraph * par = paragraph;
2716 string top_element= textclasslist.LatexnameOfClass(params.textclass);
2717 string environment_stack[MAX_NEST_LEVEL];
2718 string environment_inner[MAX_NEST_LEVEL];
2719 string command_stack[MAX_NEST_LEVEL];
2720 bool command_flag= false;
2721 int command_depth= 0, command_base= 0, cmd_depth= 0;
2723 string item_name, command_name;
2724 string c_depth, c_params, tmps;
2726 int depth= 0; /* paragraph depth */
2728 tex_code_break_column = column;
2730 ofstream ofs(filename.c_str());
2732 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), filename);
2739 ofs << "<!doctype " << top_element
2740 << " public \"-//OASIS//DTD DocBook V3.1//EN\"";
2742 if (params.preamble.empty())
2745 ofs << "\n [ " << params.preamble << " \n]>\n\n";
2747 string userName(getUserName());
2748 ofs << "<!-- DocBook file was created by LyX 1.0 (C) 1995-1999\n"
2749 << "by <" << userName << "> " << (char*)date() << " -->\n";
2751 if(params.options.empty())
2752 sgmlOpenTag(ofs, 0, top_element);
2754 string top = top_element;
2756 top += params.options;
2757 sgmlOpenTag(ofs, 0, top);
2761 int desc_on= 0; /* description mode*/
2762 LyXLayout const & style = textclasslist.Style(GetCurrentTextClass(),
2764 par->AutoDeleteInsets();
2766 /* environment tag closing */
2767 for( ; depth > par->depth; --depth) {
2768 if(environment_inner[depth] != "!-- --") {
2769 item_name= "listitem";
2770 sgmlCloseTag(ofs, command_depth + depth,
2772 if( environment_inner[depth] == "varlistentry")
2773 sgmlCloseTag(ofs, depth+command_depth,
2774 environment_inner[depth]);
2776 sgmlCloseTag(ofs, depth + command_depth,
2777 environment_stack[depth]);
2778 environment_stack[depth].clear();
2779 environment_inner[depth].clear();
2782 if(depth == par->depth
2783 && environment_stack[depth] != style.latexname()
2784 && !environment_stack[depth].empty()) {
2785 if(environment_inner[depth] != "!-- --") {
2786 item_name= "listitem";
2787 sgmlCloseTag(ofs, command_depth+depth,
2789 if( environment_inner[depth] == "varlistentry")
2791 depth + command_depth,
2792 environment_inner[depth]);
2795 sgmlCloseTag(ofs, depth + command_depth,
2796 environment_stack[depth]);
2798 environment_stack[depth].clear();
2799 environment_inner[depth].clear();
2802 // Write opening SGML tags.
2803 switch(style.latextype) {
2804 case LATEX_PARAGRAPH:
2805 if(style.latexname() != "dummy")
2806 sgmlOpenTag(ofs, depth+command_depth,
2812 LinuxDocError(par, 0,
2813 _("Error : Wrong depth for "
2814 "LatexType Command.\n"));
2816 command_name = style.latexname();
2818 tmps = style.latexparam();
2819 c_params = split(tmps, c_depth,'|');
2821 cmd_depth= atoi(c_depth.c_str());
2824 if(cmd_depth<command_base) {
2825 for(int j = command_depth;
2826 j >= command_base; --j)
2827 if(!command_stack[j].empty())
2828 sgmlCloseTag(ofs, j, command_stack[j]);
2829 command_depth= command_base= cmd_depth;
2831 else if(cmd_depth <= command_depth) {
2832 for(int j = command_depth;
2833 j >= cmd_depth; --j)
2835 if(!command_stack[j].empty())
2836 sgmlCloseTag(ofs, j, command_stack[j]);
2837 command_depth= cmd_depth;
2840 command_depth= cmd_depth;
2843 command_depth = command_base = cmd_depth;
2844 command_flag = true;
2846 command_stack[command_depth]= command_name;
2848 // treat label as a special case for
2849 // more WYSIWYM handling.
2850 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2851 Inset * inset = par->GetInset(0);
2852 char lyx_code = inset->LyxCode();
2853 if (lyx_code == Inset::LABEL_CODE){
2854 command_name += " id=\"";
2855 command_name += (static_cast<InsetCommand *>(inset))->getContents();
2856 command_name += "\"";
2861 sgmlOpenTag(ofs, depth+command_depth, command_name);
2862 item_name = "title";
2863 sgmlOpenTag(ofs, depth + 1 + command_depth, item_name);
2866 case LATEX_ENVIRONMENT:
2867 case LATEX_ITEM_ENVIRONMENT:
2868 if (depth < par->depth) {
2870 environment_stack[depth].clear();
2873 if (environment_stack[depth] != style.latexname()) {
2874 environment_stack[depth] = style.latexname();
2875 environment_inner[depth] = "!-- --";
2876 sgmlOpenTag(ofs, depth + command_depth,
2877 environment_stack[depth]);
2879 if(environment_inner[depth] != "!-- --") {
2880 item_name= "listitem";
2882 command_depth + depth,
2884 if (environment_inner[depth] == "varlistentry")
2886 depth + command_depth,
2887 environment_inner[depth]);
2891 if(style.latextype == LATEX_ENVIRONMENT) {
2892 if(!style.latexparam().empty())
2893 sgmlOpenTag(ofs, depth + command_depth,
2894 style.latexparam());
2898 desc_on = (style.labeltype == LABEL_MANUAL);
2901 environment_inner[depth]= "varlistentry";
2903 environment_inner[depth]= "listitem";
2905 sgmlOpenTag(ofs, depth + 1 + command_depth,
2906 environment_inner[depth]);
2910 sgmlOpenTag(ofs, depth + 1 + command_depth,
2915 sgmlOpenTag(ofs, depth + 1 + command_depth,
2920 sgmlOpenTag(ofs, depth + command_depth,
2926 string tmp_par, extra_par;
2928 SimpleDocBookOnePar(tmp_par, extra_par, par, desc_on,
2929 depth + 1 + command_depth);
2933 DocBookHandleFootnote(ofs, par,
2934 depth + 1 + command_depth);
2936 while(par && par->IsDummy());
2939 /* write closing SGML tags */
2940 switch(style.latextype) {
2943 sgmlCloseTag(ofs, depth + command_depth, end_tag);
2945 case LATEX_ENVIRONMENT:
2946 if(!style.latexparam().empty())
2947 sgmlCloseTag(ofs, depth + command_depth,
2948 style.latexparam());
2950 case LATEX_ITEM_ENVIRONMENT:
2951 if(desc_on == 1) break;
2953 sgmlCloseTag(ofs, depth + 1 + command_depth, end_tag);
2955 case LATEX_PARAGRAPH:
2956 if(style.latexname() != "dummy")
2957 sgmlCloseTag(ofs, depth + command_depth,
2961 sgmlCloseTag(ofs, depth + command_depth,
2968 for(; depth >= 0; --depth) {
2969 if(!environment_stack[depth].empty()) {
2970 if(environment_inner[depth] != "!-- --") {
2971 item_name= "listitem";
2972 sgmlCloseTag(ofs, command_depth + depth,
2974 if( environment_inner[depth] == "varlistentry")
2975 sgmlCloseTag(ofs, depth + command_depth,
2976 environment_inner[depth]);
2979 sgmlCloseTag(ofs, depth + command_depth,
2980 environment_stack[depth]);
2984 for(int j = command_depth; j >= command_base; --j)
2985 if(!command_stack[j].empty())
2986 sgmlCloseTag(ofs, j, command_stack[j]);
2989 sgmlCloseTag(ofs, 0, top_element);
2992 // How to check for successful close
2996 void Buffer::SimpleDocBookOnePar(string & file, string & extra,
2997 LyXParagraph * par, int & desc_on,
3001 par->SimpleDocBookOneTablePar(file, extra, desc_on, depth);
3004 LyXFont font1, font2;
3007 LyXParagraph::size_type main_body;
3009 string emph= "emphasis";
3010 bool emph_flag= false;
3011 int char_line_count= 0;
3013 LyXLayout const & style = textclasslist.Style(params.textclass,
3016 if (style.labeltype != LABEL_MANUAL)
3019 main_body = par->BeginningOfMainBody();
3021 /* gets paragraph main font */
3023 font1 = style.labelfont;
3027 char_line_count = depth;
3028 if(!style.free_spacing)
3029 for (j= 0;j< depth;j++)
3032 /* parsing main loop */
3033 for (LyXParagraph::size_type i = 0;
3034 i < par->size(); ++i) {
3035 font2 = par->getFont(i);
3037 /* handle <emphasis> tag */
3038 if (font1.emph() != font2.emph() && i) {
3039 if (font2.emph() == LyXFont::ON) {
3040 file += "<emphasis>";
3043 file += "</emphasis>";
3048 c = par->GetChar(i);
3050 if (c == LyXParagraph::META_INSET) {
3051 inset = par->GetInset(i);
3053 inset->DocBook(tmp_out);
3055 // This code needs some explanation:
3056 // Two insets are treated specially
3057 // label if it is the first element in a command paragraph
3059 // graphics inside tables or figure floats can't go on
3060 // title (the equivalente in latex for this case is caption
3061 // and title should come first
3064 if(desc_on!= 3 || i!= 0) {
3065 if(tmp_out[0] == '@') {
3067 extra += frontStrip(tmp_out, '@');
3069 file += frontStrip(tmp_out, '@');
3074 } else if (font2.latex() == LyXFont::ON) {
3075 // "TeX"-Mode on ==> SGML-Mode on.
3082 if (par->linuxDocConvertChar(c, sgml_string)
3083 && !style.free_spacing) { // in freespacing
3085 // non-breaking characters
3090 file += "</term><listitem><para>";
3098 file += sgml_string;
3104 /* needed if there is an optional argument but no contents */
3105 if (main_body > 0 && main_body == par->size()) {
3109 file += "</emphasis>";
3112 /* resets description flag correctly */
3115 /* <term> not closed... */
3123 bool Buffer::removeAutoInsets()
3125 LyXParagraph *par = paragraph;
3127 LyXCursor cursor = text->cursor;
3128 LyXCursor tmpcursor = cursor;
3129 cursor.par = tmpcursor.par->ParFromPos(tmpcursor.pos);
3130 cursor.pos = tmpcursor.par->PositionInParFromPos(tmpcursor.pos);
3134 if (par->AutoDeleteInsets()){
3136 if (par->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE){
3137 /* this is possible now, since SetCursor takes
3138 care about footnotes */
3139 text->SetCursorIntern(par, 0);
3140 text->RedoParagraphs(text->cursor, text->cursor.par->Next());
3141 text->FullRebreak();
3146 /* avoid forbidden cursor positions caused by error removing */
3147 if (cursor.pos > cursor.par->Last())
3148 cursor.pos = cursor.par->Last();
3149 text->SetCursorIntern(cursor.par, cursor.pos);
3155 int Buffer::runLaTeX()
3157 if (!text) return 0;
3161 // get LaTeX-Filename
3162 string name = getLatexName();
3164 string path = OnlyPath(filename);
3166 string org_path = path;
3167 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
3171 Path p(path); // path to LaTeX file
3172 users->owner()->getMiniBuffer()->Set(_("Running LaTeX..."));
3174 // Remove all error insets
3175 bool a = removeAutoInsets();
3177 // Always generate the LaTeX file
3178 makeLaTeXFile(name, org_path, false);
3181 // do the LaTex run(s)
3183 LaTeX latex(lyxrc->latex_command, name, filepath);
3184 int res = latex.run(terr,
3185 users->owner()->getMiniBuffer()); // running latex
3187 // check return value from latex.run().
3188 if ((res & LaTeX::NO_LOGFILE)) {
3189 WriteAlert(_("LaTeX did not work!"),
3190 _("Missing log file:"), name);
3191 } else if ((res & LaTeX::ERRORS)) {
3192 users->owner()->getMiniBuffer()->Set(_("Done"));
3193 // Insert all errors as errors boxes
3196 // Dvi should also be kept dirty if the latex run
3197 // ends up with errors. However it should be possible
3198 // to view a dirty dvi too.
3200 //no errors or any other things to think about so:
3201 users->owner()->getMiniBuffer()->Set(_("Done"));
3205 // if we removed error insets before we ran LaTeX or if we inserted
3206 // error insets after we ran LaTeX this must be run:
3207 if (a || (res & LaTeX::ERRORS)){
3210 users->updateScrollbar();
3214 return latex.getNumErrors();
3218 int Buffer::runLiterate()
3220 if (!text) return 0;
3224 // get LaTeX-Filename
3225 string name = getLatexName();
3226 // get Literate-Filename
3227 string lit_name = ChangeExtension (getLatexName(),
3228 lyxrc->literate_extension, true);
3230 string path = OnlyPath(filename);
3232 string org_path = path;
3233 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
3237 Path p(path); // path to Literate file
3238 users->owner()->getMiniBuffer()->Set(_("Running Literate..."));
3240 // Remove all error insets
3241 bool a = removeAutoInsets();
3243 // generate the Literate file if necessary
3244 if (!isDviClean() || a) {
3245 makeLaTeXFile(lit_name, org_path, false);
3249 Literate literate(lyxrc->latex_command, name, filepath,
3251 lyxrc->literate_command, lyxrc->literate_error_filter,
3252 lyxrc->build_command, lyxrc->build_error_filter);
3254 int res = literate.weave(terr, users->owner()->getMiniBuffer());
3256 // check return value from literate.weave().
3257 if ((res & Literate::NO_LOGFILE)) {
3258 WriteAlert(_("Literate command did not work!"),
3259 _("Missing log file:"), name);
3260 } else if ((res & Literate::ERRORS)) {
3261 users->owner()->getMiniBuffer()->Set(_("Done"));
3262 // Insert all errors as errors boxes
3265 // Dvi should also be kept dirty if the latex run
3266 // ends up with errors. However it should be possible
3267 // to view a dirty dvi too.
3269 //no errors or any other things to think about so:
3270 users->owner()->getMiniBuffer()->Set(_("Done"));
3274 // if we removed error insets before we ran LaTeX or if we inserted
3275 // error insets after we ran LaTeX this must be run:
3276 if (a || (res & Literate::ERRORS)){
3279 users->updateScrollbar();
3283 return literate.getNumErrors();
3287 int Buffer::buildProgram()
3289 if (!text) return 0;
3293 // get LaTeX-Filename
3294 string name = getLatexName();
3295 // get Literate-Filename
3296 string lit_name = ChangeExtension(getLatexName(),
3297 lyxrc->literate_extension, true);
3299 string path = OnlyPath(filename);
3301 string org_path = path;
3302 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
3306 Path p(path); // path to Literate file
3307 users->owner()->getMiniBuffer()->Set(_("Building Program..."));
3309 // Remove all error insets
3310 bool a = removeAutoInsets();
3312 // generate the LaTeX file if necessary
3313 if (!isNwClean() || a) {
3314 makeLaTeXFile(lit_name, org_path, false);
3318 Literate literate(lyxrc->latex_command, name, filepath,
3320 lyxrc->literate_command, lyxrc->literate_error_filter,
3321 lyxrc->build_command, lyxrc->build_error_filter);
3323 int res = literate.build(terr, users->owner()->getMiniBuffer());
3325 // check return value from literate.build().
3326 if ((res & Literate::NO_LOGFILE)) {
3327 WriteAlert(_("Build did not work!"),
3328 _("Missing log file:"), name);
3329 } else if ((res & Literate::ERRORS)) {
3330 users->owner()->getMiniBuffer()->Set(_("Done"));
3331 // Insert all errors as errors boxes
3334 // Literate files should also be kept dirty if the literate
3335 // command run ends up with errors.
3337 //no errors or any other things to think about so:
3338 users->owner()->getMiniBuffer()->Set(_("Done"));
3342 // if we removed error insets before we ran Literate/Build or if we inserted
3343 // error insets after we ran Literate/Build this must be run:
3344 if (a || (res & Literate::ERRORS)){
3347 users->updateScrollbar();
3351 return literate.getNumErrors();
3355 // This should be enabled when the Chktex class is implemented. (Asger)
3356 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
3357 // Other flags: -wall -v0 -x
3358 int Buffer::runChktex()
3360 if (!text) return 0;
3364 // get LaTeX-Filename
3365 string name = getLatexName();
3366 string path = OnlyPath(filename);
3368 string org_path = path;
3369 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
3373 Path p(path); // path to LaTeX file
3374 users->owner()->getMiniBuffer()->Set(_("Running chktex..."));
3376 // Remove all error insets
3377 bool a = removeAutoInsets();
3379 // Generate the LaTeX file if neccessary
3380 if (!isDviClean() || a) {
3381 makeLaTeXFile(name, org_path, false);
3386 Chktex chktex(lyxrc->chktex_command, name, filepath);
3387 int res = chktex.run(terr); // run chktex
3390 WriteAlert(_("chktex did not work!"),
3391 _("Could not run with file:"), name);
3392 } else if (res > 0) {
3393 // Insert all errors as errors boxes
3397 // if we removed error insets before we ran chktex or if we inserted
3398 // error insets after we ran chktex, this must be run:
3402 users->updateScrollbar();
3410 extern void AllFloats(char, char);
3413 void Buffer::insertErrors(TeXErrors & terr)
3415 // Save the cursor position
3416 LyXCursor cursor = text->cursor;
3418 // This is drastic, but it's the only fix, I could find. (Asger)
3422 for (TeXErrors::Errors::const_iterator cit = terr.begin();
3425 string desctext((*cit).error_desc);
3426 string errortext((*cit).error_text);
3427 string msgtxt = desctext + '\n' + errortext;
3428 int errorrow = (*cit).error_in_line;
3430 // Insert error string for row number
3434 texrow.getIdFromRow(errorrow, tmpid, tmppos);
3436 LyXParagraph* texrowpar;
3439 texrowpar = text->FirstParagraph();
3442 texrowpar = text->GetParFromID(tmpid);
3448 InsetError * new_inset = new InsetError(msgtxt);
3450 text->SetCursorIntern(texrowpar, tmppos);
3451 text->InsertInset(new_inset);
3452 text->FullRebreak();
3454 // Restore the cursor position
3455 text->SetCursorIntern(cursor.par, cursor.pos);
3459 void Buffer::setCursorFromRow (int row)
3464 texrow.getIdFromRow(row, tmpid, tmppos);
3466 LyXParagraph* texrowpar;
3469 texrowpar = text->FirstParagraph();
3472 texrowpar = text->GetParFromID(tmpid);
3474 text->SetCursor(texrowpar, tmppos);
3478 void Buffer::RoffAsciiTable(ostream & os, LyXParagraph * par)
3480 LyXFont font1 = LyXFont(LyXFont::ALL_INHERIT);
3483 LyXParagraph::size_type i;
3487 string fname1 = TmpFileName(string(), "RAT1");
3488 string fname2 = TmpFileName(string(), "RAT2");
3490 ofstream ofs(fname1.c_str());
3492 WriteAlert(_("LYX_ERROR:"),
3493 _("Cannot open temporary file:"), fname1);
3496 par->table->RoffEndOfCell(ofs, -1);
3497 for (i = 0; i < par->size(); ++i) {
3498 c = par->GetChar(i);
3499 if (par->table->IsContRow(cell)) {
3500 if (c == LyXParagraph::META_NEWLINE)
3504 font2 = par->GetFontSettings(i);
3505 if (font1.latex() != font2.latex()) {
3506 if (font2.latex() != LyXFont::OFF)
3510 case LyXParagraph::META_INSET:
3511 if ((inset = par->GetInset(i))) {
3512 fstream fs(fname2.c_str(), ios::in|ios::out);
3514 WriteAlert(_("LYX_ERROR:"),
3515 _("Cannot open temporary file:"), fname2);
3517 remove(fname1.c_str());
3520 inset->Latex(fs, -1);
3533 case LyXParagraph::META_NEWLINE:
3534 if (par->table->CellHasContRow(cell)>= 0)
3535 par->RoffContTableRows(ofs, i+1, cell);
3536 par->table->RoffEndOfCell(ofs, cell);
3539 case LyXParagraph::META_HFILL:
3541 case LyXParagraph::META_PROTECTED_SEPARATOR:
3551 << "RoffAsciiTable:"
3552 " NULL char in structure." << endl;
3556 par->table->RoffEndOfCell(ofs, cell);
3558 string cmd = lyxrc->ascii_roff_command + " >" + fname2;
3559 cmd = subst(cmd, "$$FName", fname1);
3560 Systemcalls one(Systemcalls::System, cmd);
3561 if (!(lyxerr.debugging(Debug::ROFF))) {
3562 remove(fname1.c_str());
3564 ifstream ifs(fname2.c_str());
3566 WriteFSAlert(_("Error! Can't open temporary file:"), fname2);
3569 // now output the produced file
3573 WriteAlert(_("Error!"),
3574 _("Error executing *roff command on table"));
3575 // overread leading blank lines
3576 while(!ifs && (c == '\n'))
3579 for(j = 0; j < par->depth; ++j)
3581 while(!ifs && (c != '\n')) {
3586 // overread trailing blank lines
3587 while(!ifs && (c == '\n'))
3591 remove(fname2.c_str());
3595 /// changed Heinrich Bauer, 23/03/98
3596 bool Buffer::isDviClean()
3598 if (lyxrc->use_tempdir)
3599 return dvi_clean_tmpd;
3601 return dvi_clean_orgd;
3605 /// changed Heinrich Bauer, 23/03/98
3606 void Buffer::markDviClean()
3608 if (lyxrc->use_tempdir)
3609 dvi_clean_tmpd = true;
3611 dvi_clean_orgd = true;
3615 /// changed Heinrich Bauer, 23/03/98
3616 void Buffer::markDviDirty()
3618 if (lyxrc->use_tempdir)
3619 dvi_clean_tmpd = false;
3621 dvi_clean_orgd = false;
3625 void Buffer::update(signed char f)
3629 users->owner()->updateLayoutChoice();
3631 if (!text->selection && f > -3)
3632 text->sel_cursor = text->cursor;
3635 text->FullRebreak();
3638 if (f != 3 && f != -3) {
3640 users->updateScrollbar();
3643 if (f == 1 || f == -1) {
3646 users->owner()->getMiniBuffer()->setTimer(4);
3654 void Buffer::validate(LaTeXFeatures & features)
3656 LyXParagraph * par = paragraph;
3657 LyXTextClass const & tclass =
3658 textclasslist.TextClass(params.textclass);
3660 // AMS Style is at document level
3662 features.amsstyle = (params.use_amsmath ||
3663 tclass.provides(LyXTextClass::amsmath));
3666 // We don't use "lyxerr.debug" because of speed. (Asger)
3667 if (lyxerr.debugging(Debug::LATEX))
3668 lyxerr << "Paragraph: " << par << endl;
3670 // Now just follow the list of paragraphs and run
3671 // validate on each of them.
3672 par->validate(features);
3674 // and then the next paragraph
3678 // the bullet shapes are buffer level not paragraph level
3679 // so they are tested here
3680 for (int i = 0; i < 4; ++i) {
3681 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
3682 int font = params.user_defined_bullets[i].getFont();
3685 .user_defined_bullets[i]
3692 features.latexsym = true;
3696 features.amssymb = true;
3698 else if ((font >= 2 && font <= 5)) {
3699 features.pifont = true;
3704 if (lyxerr.debugging(Debug::LATEX)) {
3705 features.showStruct(params);
3710 void Buffer::setPaperStuff()
3712 params.papersize = BufferParams::PAPER_DEFAULT;
3713 char c1 = params.paperpackage;
3714 if (c1 == BufferParams::PACKAGE_NONE) {
3715 char c2 = params.papersize2;
3716 if (c2 == BufferParams::VM_PAPER_USLETTER)
3717 params.papersize = BufferParams::PAPER_USLETTER;
3718 else if (c2 == BufferParams::VM_PAPER_USLEGAL)
3719 params.papersize = BufferParams::PAPER_LEGALPAPER;
3720 else if (c2 == BufferParams::VM_PAPER_USEXECUTIVE)
3721 params.papersize = BufferParams::PAPER_EXECUTIVEPAPER;
3722 else if (c2 == BufferParams::VM_PAPER_A3)
3723 params.papersize = BufferParams::PAPER_A3PAPER;
3724 else if (c2 == BufferParams::VM_PAPER_A4)
3725 params.papersize = BufferParams::PAPER_A4PAPER;
3726 else if (c2 == BufferParams::VM_PAPER_A5)
3727 params.papersize = BufferParams::PAPER_A5PAPER;
3728 else if ((c2 == BufferParams::VM_PAPER_B3) || (c2 == BufferParams::VM_PAPER_B4) ||
3729 (c2 == BufferParams::VM_PAPER_B5))
3730 params.papersize = BufferParams::PAPER_B5PAPER;
3731 } else if ((c1 == BufferParams::PACKAGE_A4) || (c1 == BufferParams::PACKAGE_A4WIDE) ||
3732 (c1 == BufferParams::PACKAGE_WIDEMARGINSA4))
3733 params.papersize = BufferParams::PAPER_A4PAPER;
3738 void Buffer::setOldPaperStuff()
3740 char c = params.papersize = params.papersize2;
3741 params.papersize2 = BufferParams::VM_PAPER_DEFAULT;
3742 params.paperpackage = BufferParams::PACKAGE_NONE;
3743 if (c == OLD_PAPER_A4PAPER)
3744 params.papersize2 = BufferParams::VM_PAPER_A4;
3745 else if (c == OLD_PAPER_A4)
3746 params.paperpackage = BufferParams::PACKAGE_A4;
3747 else if (c == OLD_PAPER_A4WIDE)
3748 params.paperpackage = BufferParams::PACKAGE_A4WIDE;
3749 else if (c == OLD_PAPER_WIDEMARGINSA4)
3750 params.paperpackage = BufferParams::PACKAGE_WIDEMARGINSA4;
3751 else if (c == OLD_PAPER_USLETTER)
3752 params.papersize2 = BufferParams::VM_PAPER_USLETTER;
3753 else if (c == OLD_PAPER_A5PAPER)
3754 params.papersize2 = BufferParams::VM_PAPER_A5;
3755 else if (c == OLD_PAPER_B5PAPER)
3756 params.papersize2 = BufferParams::VM_PAPER_B5;
3757 else if (c == OLD_PAPER_EXECUTIVEPAPER)
3758 params.papersize2 = BufferParams::VM_PAPER_USEXECUTIVE;
3759 else if (c == OLD_PAPER_LEGALPAPER)
3760 params.papersize2 = BufferParams::VM_PAPER_USLEGAL;
3765 void Buffer::insertInset(Inset * inset, string const & lout,
3768 // check for table/list in tables
3769 if (no_table && text->cursor.par->table){
3770 WriteAlert(_("Impossible Operation!"),
3771 _("Cannot insert table/list in table."),
3775 // not quite sure if we want this...
3776 text->SetCursorParUndo();
3780 if (!lout.empty()) {
3782 text->BreakParagraph();
3785 if (text->cursor.par->Last()) {
3788 text->BreakParagraph();
3792 int lay = textclasslist.NumberOfLayout(params.textclass,
3794 if (lay == -1) // layout not found
3795 // use default layout "Standard" (0)
3798 text->SetLayout(lay);
3800 text->SetParagraph(0, 0,
3802 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3808 text->current_font.setLatex(LyXFont::OFF);
3811 text->InsertInset(inset);
3814 text->UnFreezeUndo();
3818 // Open and lock an updatable inset
3819 void Buffer::open_new_inset(UpdatableInset * new_inset)
3823 insertInset(new_inset);
3826 new_inset->Edit(0, 0);
3830 /* This function should be in Buffer because it's a buffer's property (ale) */
3831 string Buffer::getIncludeonlyList(char delim)
3834 LyXParagraph * par = paragraph;
3835 LyXParagraph::size_type pos;
3839 while ((inset = par->ReturnNextInsetPointer(pos))){
3840 if (inset->LyxCode() == Inset::INCLUDE_CODE) {
3841 InsetInclude * insetinc =
3842 static_cast<InsetInclude*>(inset);
3843 if (insetinc->isInclude()
3844 && insetinc->isNoLoad()) {
3847 lst += ChangeExtension(insetinc->getContents(), string(), true);
3854 lyxerr.debug() << "Includeonly(" << lst << ')' << endl;
3859 /* This is also a buffer property (ale) */
3860 string Buffer::getReferenceList(char delim)
3862 /// if this is a child document and the parent is already loaded
3863 /// Use the parent's list instead [ale990407]
3864 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3865 Buffer *tmp = bufferlist.getBuffer(params.parentname);
3867 return tmp->getReferenceList(delim);
3870 LyXParagraph *par = paragraph;
3871 LyXParagraph::size_type pos;
3876 while ((inset = par->ReturnNextInsetPointer(pos))){
3877 for (int i = 0; i < inset->GetNumberOfLabels(); i++) {
3880 lst += inset->getLabel(i);
3886 lyxerr.debug() << "References(" << lst << ")" << endl;
3891 /* This is also a buffer property (ale) */
3892 string Buffer::getBibkeyList(char delim)
3894 /// if this is a child document and the parent is already loaded
3895 /// Use the parent's list instead [ale990412]
3896 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3897 Buffer *tmp = bufferlist.getBuffer(params.parentname);
3899 return tmp->getBibkeyList(delim);
3903 LyXParagraph * par = paragraph;
3906 if (!bibkeys.empty())
3908 bibkeys += par->bibkey->getContents();
3913 // Might be either using bibtex or a child has bibliography
3914 if (bibkeys.empty()) {
3918 LyXParagraph::size_type pos = -1;
3920 // Search for Bibtex or Include inset
3921 while ((inset = par->ReturnNextInsetPointer(pos))) {
3922 if (inset-> LyxCode() == Inset::BIBTEX_CODE) {
3923 if (!bibkeys.empty())
3925 bibkeys += static_cast<InsetBibtex*>(inset)->getKeys();
3926 } else if (inset-> LyxCode() == Inset::INCLUDE_CODE) {
3927 string bk = static_cast<InsetInclude*>(inset)->getKeys();
3929 if (!bibkeys.empty())
3940 lyxerr.debug() << "Bibkeys(" << bibkeys << ")" << endl;
3945 /* This is also a buffer property (ale) */
3946 // Not so sure about that. a goto Label function can not be buffer local, just
3947 // think how this will work in a multiwindo/buffer environment, all the
3948 // cursors in all the views showing this buffer will move. (Lgb)
3949 // OK, then no cursor action should be allowed in buffer. (ale)
3950 bool Buffer::gotoLabel(string const & label)
3953 LyXParagraph * par = paragraph;
3954 LyXParagraph::size_type pos;
3958 while ((inset = par->ReturnNextInsetPointer(pos))){
3959 for (int i = 0; i < inset->GetNumberOfLabels(); i++) {
3960 if (label == inset->getLabel(i)) {
3962 text->SetCursor(par, pos);
3963 text->sel_cursor = text->cursor;
3976 bool Buffer::isDepClean(string const & name) const
3978 DEPCLEAN * item = dep_clean;
3979 while (item && item->master != name)
3981 if (!item) return true;
3986 void Buffer::markDepClean(string const & name)
3989 dep_clean = new DEPCLEAN;
3990 dep_clean->clean = true;
3991 dep_clean->master = name;
3992 dep_clean->next = 0;
3994 DEPCLEAN* item = dep_clean;
3995 while (item && item->master != name)
4000 item = new DEPCLEAN;
4002 item->master = name;