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
30 #pragma implementation "buffer.h"
33 #include "definitions.h"
35 #include "bufferlist.h"
37 #include "lyx_gui_misc.h"
40 #include "tex-strings.h"
43 #include "minibuffer.h"
45 #include "mathed/formulamacro.h"
46 #include "insets/lyxinset.h"
47 #include "insets/inseterror.h"
48 #include "insets/insetlabel.h"
49 #include "insets/insetref.h"
50 #include "insets/inseturl.h"
51 #include "insets/insetinfo.h"
52 #include "insets/insetquotes.h"
53 #include "insets/insetlatex.h"
54 #include "insets/insetlatexaccent.h"
55 #include "insets/insetbib.h"
56 #include "insets/insetindex.h"
57 #include "insets/insetinclude.h"
58 #include "insets/insettoc.h"
59 #include "insets/insetlof.h"
60 #include "insets/insetlot.h"
61 #include "insets/insetloa.h"
62 #include "insets/insetparent.h"
63 #include "insets/insetspecialchar.h"
64 #include "insets/figinset.h"
65 #include "support/filetools.h"
66 #include "pathstack.h"
72 #include "LaTeXFeatures.h"
73 #include "support/syscall.h"
74 #include "support/lyxlib.h"
75 #include "support/FileInfo.h"
79 // Uncomment this line to enable a workaround for the weird behaviour
80 // of the cursor between a displayed inset and last character
81 // at the upper line. (Alejandro 20.9.96)
82 // #define BREAK_BEFORE_INSET
84 /* Lars, when changing this file sometime in the future to a list,
85 * please check out the figinsets-sideeffects described at the
86 * beginning of figinset.C Matthias (04.07.1996)
90 // all these externs should eventually be removed.
91 extern BufferList bufferlist;
92 extern void SmallUpdate(signed char);
93 extern unsigned char GetCurrentTextClass();
94 extern void BeforeChange();
96 static const float LYX_FORMAT = 2.15;
98 extern int tex_code_break_column;
100 extern void FreeUpdateTimer();
103 Buffer::Buffer(string const & file, LyXRC *lyxrc, bool ronly)
106 filepath = OnlyPath(file);
109 the_locking_inset = 0;
112 dvi_clean_orgd = false; // Heinrich Bauer, 23/03/98
113 dvi_clean_tmpd = false; // Heinrich Bauer, 23/03/98
118 lyxvc.setBuffer(this);
119 lyxerr.debug("Buffer::Buffer()");
120 if (read_only || (lyxrc && lyxrc->use_tempdir)) {
121 tmppath = CreateBufferTmpDir();
122 } else tmppath.erase();
128 lyxerr.debug("Buffer::~Buffer()");
129 // here the buffer should take care that it is
130 // saved properly, before it goes into the void.
132 // make sure that views using this buffer
137 if (!tmppath.empty()) {
138 DestroyBufferTmpDir(tmppath);
141 LyXParagraph *par = paragraph;
142 LyXParagraph *tmppar;
153 bool Buffer::saveParamsAsDefaults()
155 string fname = AddName(AddPath(user_lyxdir, "templates/"),
157 Buffer defaults = Buffer(fname);
159 // Use the current buffer's parameters as default
160 defaults.params.Copy(params);
161 // add an empty paragraph. Is this enough?
162 defaults.paragraph = new LyXParagraph();
164 return defaults.writeFile(defaults.filename,false);
168 /// Update window titles of all users
169 // Should work on a list
170 void Buffer::updateTitles()
172 if (users) users->getOwner()->updateWindowTitle();
176 /// Reset autosave timer of all users
177 // Should work on a list
178 void Buffer::resetAutosaveTimers()
180 if (users) users->getOwner()->resetAutosaveTimer();
184 void Buffer::setFileName(string const & newfile)
186 filename = MakeAbsPath(newfile);
187 filepath = OnlyPath(filename);
188 setReadonly(IsFileWriteable(filename) == 0);
192 void Buffer::InsetUnlock()
194 if (the_locking_inset) {
195 if (!inset_slept) the_locking_inset->InsetUnlock();
196 the_locking_inset = 0;
203 // Inserts a file into current document
204 bool Buffer::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 filename = MakeAbsPath(filen);
217 // check if file exist
218 FileInfo fi(filename);
220 if (!fi.exist() || !fi.readable()) {
221 WriteAlert(_("Error!"),
222 _("Cannot open specified file:"),
223 MakeDisplayPath(filename,50));
229 FilePtr myfile(filename, FilePtr::read);
231 WriteAlert(_("Error!"),
232 _("Cannot open specified file:"),
233 MakeDisplayPath(filename,50));
238 int c = fgetc(myfile());
244 lyxerr.debug("Will insert file with header");
245 res = readFile(lex, text->cursor.par);
247 lyxerr.debug("Will insert file without header");
248 res = readLyXformat2(lex, text->cursor.par);
257 // changed to be public and have one parameter
258 // if par = 0 normal behavior
259 // else insert behavior
260 // Returns false if "\the_end" is not read for formats >= 2.13. (Asger)
261 bool Buffer::readLyXformat2(LyXLex &lex, LyXParagraph *par)
267 char depth = 0; // signed or unsigned?
268 LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
269 LyXParagraph::footnote_kind footnotekind = LyXParagraph::FOOTNOTE;
270 bool the_end_read = false;
272 LyXParagraph *return_par = 0;
273 LyXFont font = LyXFont(LyXFont::ALL_INHERIT);
275 // If we are inserting, we cheat and get a token in advance
276 bool has_token = false;
280 par = new LyXParagraph();
282 text->BreakParagraph();
283 return_par = text->FirstParagraph();
286 // We don't want to adopt the parameters from the
287 // document we insert, so we skip until the text begins:
290 pretoken = lex.GetString();
291 if (pretoken == "\\layout") {
303 pretoken = lex.GetString();
306 // Profiling show this should give a lot: (Asger)
307 string const token = pretoken;
311 else if (token[0] != '\\') {
312 int n = token.length();
313 for (int i=0; i < n; i++) {
314 par->InsertChar(pos, token[i]);
315 par->SetFont(pos, font);
318 } else if (token == "\\i") {
319 inset = new InsetLatexAccent;
321 par->InsertChar(pos, LYX_META_INSET);
323 par->InsertInset(pos, inset);
324 par->SetFont(pos, font);
326 } else if (token == "\\layout") {
330 par = new LyXParagraph(par);
334 lyxstyle.NumberOfLayout(params.textclass,
336 if (par->layout == -1) // layout not found
337 // use default layout "Standard" (0)
339 // Test whether the layout is obsolete.
340 LyXLayout* layout = lyxstyle.Style(params.textclass,
342 if (!layout->obsoleted_by.empty())
344 lyxstyle.NumberOfLayout(params.textclass,
345 layout->obsoleted_by);
346 par->footnoteflag = footnoteflag;
347 par->footnotekind = footnotekind;
349 font = LyXFont(LyXFont::ALL_INHERIT);
350 } else if (token == "\\end_float") {
354 par = new LyXParagraph(par);
355 footnotekind = LyXParagraph::FOOTNOTE;
356 footnoteflag = LyXParagraph::NO_FOOTNOTE;
359 par->layout = LYX_DUMMY_LAYOUT;
360 font = LyXFont(LyXFont::ALL_INHERIT);
361 } else if (token == "\\begin_float") {
362 tmpret = lex.FindToken(string_footnotekinds);
363 if (tmpret == -1) tmpret++;
364 if (tmpret != LYX_LAYOUT_DEFAULT)
365 footnotekind = (LyXParagraph::footnote_kind)tmpret; // bad
366 if (footnotekind == LyXParagraph::FOOTNOTE
367 || footnotekind == LyXParagraph::MARGIN)
368 footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
370 footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
371 } else if (token == "\\begin_deeper") {
373 } else if (token == "\\end_deeper") {
375 lex.printError("\\end_deeper: "
376 "depth is already null");
380 } else if (token == "\\begin_preamble") {
381 params.readPreamble(lex);
382 } else if (token == "\\textclass") {
384 params.textclass = lyxstyle.NumberOfClass(lex.GetString());
385 if (params.textclass == -1) {
386 lex.printError("Unknown textclass `$$Token'");
387 params.textclass = 0;
389 if (!lyxstyle.Load(params.textclass)) {
390 // if the textclass wasn't loaded properly
391 // we need to either substitute another
392 // or stop loading the file.
393 // I can substitute but I don't see how I can
394 // stop loading... ideas?? ARRae980418
395 WriteAlert(_("Textclass Loading Error!"),
396 string(_("Can't load textclass ")) +
397 lyxstyle.NameOfClass(params.textclass),
398 _("-- substituting default"));
399 params.textclass = 0;
401 } else if (token == "\\options") {
403 params.options = lex.GetString();
404 } else if (token == "\\language") {
405 params.readLanguage(lex);
406 } else if (token == "\\fontencoding") {
408 } else if (token == "\\inputencoding") {
410 params.inputenc = lex.GetString();
411 } else if (token == "\\graphics") {
412 params.readGraphicsDriver(lex);
413 } else if (token == "\\fontscheme") {
415 params.fonts = lex.GetString();
416 } else if (token == "\\noindent") {
417 par->noindent = true;
418 } else if (token == "\\fill_top") {
419 par->added_space_top = VSpace(VSpace::VFILL);
420 } else if (token == "\\fill_bottom") {
421 par->added_space_bottom = VSpace(VSpace::VFILL);
422 } else if (token == "\\line_top") {
423 par->line_top = true;
424 } else if (token == "\\line_bottom") {
425 par->line_bottom = true;
426 } else if (token == "\\pagebreak_top") {
427 par->pagebreak_top = true;
428 } else if (token == "\\pagebreak_bottom") {
429 par->pagebreak_bottom = true;
430 } else if (token == "\\start_of_appendix") {
431 par->start_of_appendix = true;
432 } else if (token == "\\paragraph_separation") {
433 tmpret = lex.FindToken(string_paragraph_separation);
434 if (tmpret == -1) tmpret++;
435 if (tmpret != LYX_LAYOUT_DEFAULT)
436 params.paragraph_separation = tmpret;
437 } else if (token == "\\defskip") {
439 params.defskip = VSpace(lex.GetString());
440 } else if (token == "\\no_isolatin1") {
442 } else if (token == "\\no_babel") {
444 } else if (token == "\\no_epsfig") {
446 } else if (token == "\\epsfig") { // obsolete
447 // Indeed it is obsolete, but we HAVE to be backwards
448 // compatible until 0.14, because otherwise all figures
449 // in existing documents are irretrivably lost. (Asger)
450 params.readGraphicsDriver(lex);
451 } else if (token == "\\quotes_language") {
452 tmpret = lex.FindToken(string_quotes_language);
453 if (tmpret == -1) tmpret++;
454 if (tmpret != LYX_LAYOUT_DEFAULT) {
455 InsetQuotes::quote_language tmpl =
456 InsetQuotes::EnglishQ;
459 tmpl = InsetQuotes::EnglishQ;
462 tmpl = InsetQuotes::SwedishQ;
465 tmpl = InsetQuotes::GermanQ;
468 tmpl = InsetQuotes::PolishQ;
471 tmpl = InsetQuotes::FrenchQ;
474 tmpl = InsetQuotes::DanishQ;
477 params.quotes_language = tmpl;
479 } else if (token == "\\quotes_times") {
481 switch(lex.GetInteger()) {
483 params.quotes_times = InsetQuotes::SingleQ;
486 params.quotes_times = InsetQuotes::DoubleQ;
489 } else if (token == "\\papersize") {
491 tmpret = lex.FindToken(string_papersize);
493 tmpret = lex.FindToken(string_oldpapersize);
497 params.papersize2 = tmpret;
498 } else if (token == "\\paperpackage") {
499 tmpret = lex.FindToken(string_paperpackages);
502 params.paperpackage = PACKAGE_NONE;
504 params.paperpackage = tmpret;
505 } else if (token == "\\use_geometry") {
507 params.use_geometry = lex.GetInteger();
508 } else if (token == "\\use_amsmath") {
510 params.use_amsmath = lex.GetInteger();
511 } else if (token == "\\paperorientation") {
512 tmpret = lex.FindToken(string_orientation);
513 if (tmpret == -1) tmpret++;
514 if (tmpret != LYX_LAYOUT_DEFAULT)
515 params.orientation = tmpret;
516 } else if (token == "\\paperwidth") {
518 params.paperwidth = lex.GetString();
519 } else if (token == "\\paperheight") {
521 params.paperheight = lex.GetString();
522 } else if (token == "\\leftmargin") {
524 params.leftmargin = lex.GetString();
525 } else if (token == "\\topmargin") {
527 params.topmargin = lex.GetString();
528 } else if (token == "\\rightmargin") {
530 params.rightmargin = lex.GetString();
531 } else if (token == "\\bottommargin") {
533 params.bottommargin = lex.GetString();
534 } else if (token == "\\headheight") {
536 params.headheight = lex.GetString();
537 } else if (token == "\\headsep") {
539 params.headsep = lex.GetString();
540 } else if (token == "\\footskip") {
542 params.footskip = lex.GetString();
543 } else if (token == "\\paperfontsize") {
545 params.fontsize = strip(lex.GetString());
546 } else if (token == "\\papercolumns") {
548 params.columns = lex.GetInteger();
549 } else if (token == "\\papersides") {
551 params.sides = lex.GetInteger();
552 } else if (token == "\\paperpagestyle") {
554 params.pagestyle = strip(lex.GetString());
555 } else if (token == "\\bullet") {
557 int index = lex.GetInteger();
559 int temp_int = lex.GetInteger();
560 params.user_defined_bullets[index].setFont(temp_int);
561 params.temp_bullets[index].setFont(temp_int);
563 temp_int = lex.GetInteger();
564 params.user_defined_bullets[index].setCharacter(temp_int);
565 params.temp_bullets[index].setCharacter(temp_int);
567 temp_int = lex.GetInteger();
568 params.user_defined_bullets[index].setSize(temp_int);
569 params.temp_bullets[index].setSize(temp_int);
571 string temp_str = lex.GetString();
572 if (temp_str != "\\end_bullet") {
573 // this element isn't really necessary for
574 // parsing but is easier for humans
575 // to understand bullets. Put it back and
576 // set a debug message?
577 lex.printError("\\end_bullet expected, got" + temp_str);
578 //how can I put it back?
580 } else if (token == "\\bulletLaTeX") {
582 int index = lex.GetInteger();
584 string temp_str = lex.GetString(), sum_str;
585 while (temp_str != "\\end_bullet") {
586 // this loop structure is needed when user
587 // enters an empty string since the first
588 // thing returned will be the \\end_bullet
590 // if the LaTeX entry has spaces. Each element
591 // therefore needs to be read in turn
594 temp_str = lex.GetString();
596 params.user_defined_bullets[index].setText(sum_str);
597 params.temp_bullets[index].setText(sum_str);
598 } else if (token == "\\secnumdepth") {
600 params.secnumdepth = lex.GetInteger();
601 } else if (token == "\\tocdepth") {
603 params.tocdepth = lex.GetInteger();
604 } else if (token == "\\baselinestretch") { // now obsolete
605 lex.nextToken(); // should not be used directly
607 // Will probably keep a kind of support just for
609 params.spacing.set(Spacing::Other, lex.GetFloat());
610 } else if (token == "\\spacing") {
612 string tmp = strip(lex.GetString());
613 if (tmp == "single") {
614 params.spacing.set(Spacing::Single);
615 } else if (tmp == "onehalf") {
616 params.spacing.set(Spacing::Onehalf);
617 } else if (tmp == "double") {
618 params.spacing.set(Spacing::Double);
619 } else if (tmp == "other") {
621 params.spacing.set(Spacing::Other,
624 lex.printError("Unknown spacing token: '$$Token'");
626 } else if (token == "\\float_placement") {
628 params.float_placement = lex.GetString();
629 } else if (token == "\\cursor") {
630 // this is obsolete, so we just skip it.
632 } else if (token == "\\family") {
634 font.setLyXFamily(lex.GetString());
635 } else if (token == "\\series") {
637 font.setLyXSeries(lex.GetString());
638 } else if (token == "\\shape") {
640 font.setLyXShape(lex.GetString());
641 } else if (token == "\\size") {
643 font.setLyXSize(lex.GetString());
644 } else if (token == "\\latex") {
646 string tok = lex.GetString();
647 // This is dirty, but gone with LyX3. (Asger)
648 if (tok == "no_latex")
649 font.setLatex(LyXFont::OFF);
650 else if (tok == "latex")
651 font.setLatex(LyXFont::ON);
652 else if (tok == "default")
653 font.setLatex(LyXFont::INHERIT);
655 lex.printError("Unknown LaTeX font flag "
657 } else if (token == "\\emph") {
659 font.setEmph(font.setLyXMisc(lex.GetString()));
660 } else if (token == "\\bar") {
662 string tok = lex.GetString();
663 // This is dirty, but gone with LyX3. (Asger)
665 font.setUnderbar(LyXFont::ON);
666 else if (tok == "no")
667 font.setUnderbar(LyXFont::OFF);
668 else if (tok == "default")
669 font.setUnderbar(LyXFont::INHERIT);
671 lex.printError("Unknown bar font flag "
673 } else if (token == "\\noun") {
675 font.setNoun(font.setLyXMisc(lex.GetString()));
676 } else if (token == "\\color") {
678 font.setLyXColor(lex.GetString());
679 } else if (token == "\\align") {
680 tmpret = lex.FindToken(string_align);
681 if (tmpret == -1) tmpret++;
682 if (tmpret != LYX_LAYOUT_DEFAULT) {
684 for (; tmpret>0; tmpret--)
685 tmpret2 = tmpret2 * 2;
686 par->align = tmpret2;
688 } else if (token == "\\added_space_top"){
690 par->added_space_top = lex.GetString();
691 } else if (token == "\\added_space_bottom") {
693 par->added_space_bottom = lex.GetString();
694 } else if (token == "\\pextra_type") {
696 par->pextra_type = lex.GetInteger();
697 } else if (token == "\\pextra_width") {
699 par->pextra_width = lex.GetString();
700 } else if (token == "\\pextra_widthp") {
702 par->pextra_widthp = lex.GetString();
703 } else if (token == "\\pextra_alignment") {
705 par->pextra_alignment = lex.GetInteger();
706 } else if (token == "\\pextra_hfill") {
708 par->pextra_hfill = lex.GetInteger();
709 } else if (token == "\\pextra_start_minipage") {
711 par->pextra_start_minipage = lex.GetInteger();
712 } else if (token == "\\labelwidthstring") {
714 par->labelwidthstring = lex.GetString();
715 /* do not delete this token, it is still needed! */
716 } else if (token == "\\end_inset") {
717 /* simple ignore this. The insets do not have
719 // but insets should read it, it is a part of
720 //the inset isn't it? Lgb.
721 } else if (token == "\\begin_inset") {
723 tmptok = lex.GetString();
724 /* test the different insets */
725 if (tmptok == "Quotes") {
726 inset = new InsetQuotes;
728 par->InsertChar(pos, LYX_META_INSET);
729 par->InsertInset(pos, inset);
730 par->SetFont(pos, font);
732 } else if (tmptok == "Latex") {
733 // This one is on its way out
735 tmptok = strip(lex.GetString());
736 //lyxerr.print(string(tmptok[0]));
737 if (tmptok[0] == '\\') {
738 // then this latex is a
740 InsetCommand *tmpinset =
742 tmpinset->scanCommand(tmptok);
745 // This should not use InsetLaTexDel
746 // it should rather insert text into
747 // the paragraph and mark it as tex.
748 inset = new InsetLatex(tmptok);
750 par->InsertChar(pos, LYX_META_INSET);
751 par->InsertInset(pos, inset);
752 par->SetFont(pos, font);
754 } else if (tmptok == "LatexDel") {
755 // This one is on its way out...
757 tmptok = strip(lex.GetString());
758 //lyxerr.print(string(tmptok[0]));
759 if (tmptok == "\\tableofcontents") {
760 inset = new InsetTOC(this);
761 } else if (tmptok == "\\listoffigures") {
762 inset = new InsetLOF(this);
763 } else if (tmptok == "\\listoftables") {
764 inset = new InsetLOT(this);
765 } else if (tmptok == "\\listofalgorithms") {
766 inset = new InsetLOA(this);
767 } else if (contains(tmptok, "\\ref{")
768 || contains(tmptok, "\\pageref{")) {
769 inset = new InsetRef(tmptok, this);
770 } else if (contains(tmptok, "\\url{")
771 || contains(tmptok, "\\htmlurl{")) {
772 string cont,opt,tmptmptok,cmdname;
774 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
779 tmptmptok=lex.GetString();
780 if(tmptmptok[0] == '\\') {
781 if( tmptmptok == "\\backslash")
791 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
796 tmptmptok=lex.GetString();
797 if(tmptmptok[0] == '\\') {
798 if( tmptmptok == "\\backslash")
808 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
811 if(contains(tmptok, "\\url{"))
812 cmdname = string("url");
814 cmdname = string("htmlurl");
817 inset = new InsetUrl(cmdname,cont,opt);
818 } else if (tmptok[0] == '\\') {
819 // then this latex del is a
821 InsetCommand *tmpinset =
823 tmpinset->scanCommand(tmptok);
826 par->InsertChar(pos, LYX_META_INSET);
827 par->InsertInset(pos, inset);
828 par->SetFont(pos, font);
830 } else if (tmptok == "\\i") {
831 inset = new InsetLatexAccent;
833 par->InsertChar(pos, LYX_META_INSET);
834 par->InsertInset(pos, inset);
835 par->SetFont(pos, font);
837 } else if (tmptok == "FormulaMacro") {
838 inset = new InsetFormulaMacro;
840 par->InsertChar(pos, LYX_META_INSET);
841 par->InsertInset(pos, inset);
842 par->SetFont(pos, font);
844 } else if (tmptok == "Formula") {
845 inset = new InsetFormula;
847 par->InsertChar(pos, LYX_META_INSET);
848 par->InsertInset(pos, inset);
849 par->SetFont(pos, font);
851 } else if (tmptok == "Figure") {
852 inset = new InsetFig(100,100, this);
854 par->InsertChar(pos, LYX_META_INSET);
855 par->InsertInset(pos, inset);
856 par->SetFont(pos, font);
858 } else if (tmptok == "Label") {
859 // Kept for compability. Remove in 0.13.
863 tmp += lex.GetString();
865 inset = new InsetLabel(tmp);
866 par->InsertChar(pos, LYX_META_INSET);
867 par->InsertInset(pos, inset);
868 par->SetFont(pos, font);
871 } else if (tmptok == "Info") {
872 inset = new InsetInfo;
874 par->InsertChar(pos, LYX_META_INSET);
875 par->InsertInset(pos, inset);
876 par->SetFont(pos, font);
878 } else if (tmptok == "Include") {
879 inset = new InsetInclude(string(), this);
881 par->InsertChar(pos, LYX_META_INSET);
882 par->InsertInset(pos, inset);
883 par->SetFont(pos, font);
885 } else if (tmptok == "LatexCommand") {
888 if (inscmd.getCmdName()=="cite") {
889 inset = new InsetCitation(inscmd.getContents(), inscmd.getOptions());
890 } else if (inscmd.getCmdName()=="bibitem") {
891 lex.printError("Wrong place for bibitem");
892 inset = inscmd.Clone();
893 } else if (inscmd.getCmdName()=="BibTeX") {
894 inset = new InsetBibtex(inscmd.getContents(), inscmd.getOptions(), this);
895 } else if (inscmd.getCmdName()=="index") {
896 inset = new InsetIndex(inscmd.getContents());
897 } else if (inscmd.getCmdName()=="include") {
898 inset = new InsetInclude(inscmd.getContents(), this);
899 } else if (inscmd.getCmdName()=="label") {
900 inset = new InsetLabel(inscmd.getCommand());
901 } else if (inscmd.getCmdName()=="url"
902 || inscmd.getCmdName()=="htmlurl") {
903 inset = new InsetUrl(inscmd.getCommand());
904 } else if (inscmd.getCmdName() == "ref"
905 || inscmd.getCmdName() == "pageref") {
906 if (!inscmd.getOptions().empty() || !inscmd.getContents().empty()) {
907 inset = new InsetRef(inscmd, this);
909 /* This condition comes from a temporary solution
910 to the latexdel ref inset that was transformed to an empty ref
911 inset plus the body surronded by latexdel insets */
913 string cont,opt,tmptmptok,cmdname;
915 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
920 tmptmptok=lex.GetString();
921 if(tmptmptok[0] == '\\') {
922 if( tmptmptok == "\\backslash")
932 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
937 tmptmptok=lex.GetString();
938 if(tmptmptok[0] == '\\') {
939 if( tmptmptok == "\\backslash")
949 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
955 cmdname = "\\" + inscmd.getCmdName();
956 cmdname += "[" + cont + "]";
957 cmdname += "{" + opt + "}";
958 inset = new InsetRef(cmdname,this);
960 } else if (inscmd.getCmdName()=="tableofcontents") {
961 inset = new InsetTOC(this);
962 } else if (inscmd.getCmdName()=="listoffigures") {
963 inset = new InsetLOF(this);
964 } else if (inscmd.getCmdName()=="listofalgorithms") {
965 inset = new InsetLOA(this);
966 } else if (inscmd.getCmdName()=="listoftables") {
967 inset = new InsetLOT(this);
968 } else if (inscmd.getCmdName()=="printindex") {
969 inset = new InsetPrintIndex(this);
970 } else if (inscmd.getCmdName()=="lyxparent") {
971 inset = new InsetParent(inscmd.getContents(),this);
973 // The following three are only for compatibility
974 if (inscmd.getCmdName()=="-") {
975 inset = new InsetSpecialChar(InsetSpecialChar::HYPHENATION);
976 } else if (inscmd.getCmdName()=="@.") {
977 inset = new InsetSpecialChar(InsetSpecialChar::END_OF_SENTENCE);
978 } else if (inscmd.getCmdName()=="ldots") {
979 inset = new InsetSpecialChar(InsetSpecialChar::LDOTS);
981 inset = inscmd.Clone();
984 par->InsertChar(pos, LYX_META_INSET);
985 par->InsertInset(pos, inset);
986 par->SetFont(pos, font);
990 } else if (token == "\\InsetQuotes") {
991 inset = new InsetQuotes;
993 par->InsertChar(pos, LYX_META_INSET);
994 par->InsertInset(pos, inset);
995 par->SetFont(pos, font);
997 } else if (token == "\\InsetLatex") {
998 inset = new InsetLatex;
1000 par->InsertChar(pos, LYX_META_INSET);
1001 par->InsertInset(pos, inset);
1002 par->SetFont(pos, font);
1004 } else if (token == "\\InsetLatexDel") {
1005 lex.printError(_("Warning: Ignoring Old Inset"));
1006 } else if (token == "\\InsetFormula") {
1007 inset = new InsetFormula;
1009 par->InsertChar(pos, LYX_META_INSET);
1010 par->InsertInset(pos, inset);
1011 par->SetFont(pos, font);
1013 } else if (token == "\\SpecialChar") {
1014 inset = new InsetSpecialChar;
1016 par->InsertChar(pos, LYX_META_INSET);
1017 par->InsertInset(pos, inset);
1018 par->SetFont(pos, font);
1020 } else if (token == "\\Figure") {
1021 inset = new InsetFig(100,100, this);
1023 par->InsertChar(pos, LYX_META_INSET);
1024 par->InsertInset(pos, inset);
1025 par->SetFont(pos, font);
1027 } else if (token == "\\newline") {
1028 par->InsertChar(pos, LYX_META_NEWLINE);
1029 par->SetFont(pos, font);
1031 } else if (token == "\\LyXTable") {
1032 par->table = new LyXTable(lex);
1033 } else if (token == "\\hfill") {
1034 par->InsertChar(pos, LYX_META_HFILL);
1035 par->SetFont(pos, font);
1037 } else if (token == "\\protected_separator") {
1038 par->InsertChar(pos, LYX_META_PROTECTED_SEPARATOR);
1039 par->SetFont(pos, font);
1041 } else if (token == "\\bibitem") { // ale970302
1043 par->bibkey = new InsetBibKey;
1044 par->bibkey->Read(lex);
1045 }else if (token == "\\backslash") {
1046 par->InsertChar(pos, '\\');
1047 par->SetFont(pos, font);
1049 }else if (token == "\\the_end") {
1050 the_end_read = true;
1052 // This should be insurance for the future: (Asger)
1053 lex.printError("Unknown token `$$Token'. "
1054 "Inserting as text.");
1055 int n = token.length();
1056 for (int i=0; i < n; i++) {
1057 par->InsertChar(pos, token[i]);
1058 par->SetFont(pos, font);
1067 paragraph = return_par;
1069 return the_end_read;
1073 bool Buffer::readFile(LyXLex &lex, LyXParagraph *par)
1079 token = lex.GetString();
1080 if (token == "\\lyxformat") { // the first token _must_ be...
1082 format = lex.GetFloat();
1084 if (LYX_FORMAT - format > 0.05) {
1085 printf(_("Warning: need lyxformat %.2f but found %.2f\n"),
1086 LYX_FORMAT, format);
1088 if (format - LYX_FORMAT > 0.05) {
1089 printf(_("ERROR: need lyxformat %.2f but found %.2f\n"),
1090 LYX_FORMAT, format);
1092 bool the_end = readLyXformat2(lex, par);
1093 // Formats >= 2.13 support "\the_end" marker
1096 // Formats >= 2.14 changed papersize stuff
1097 if (format < 2.14) {
1103 WriteAlert(_("Warning!"),
1104 _("Reading of document is not complete"),
1105 _("Maybe the document is truncated"));
1106 // We simulate a safe reading anyways to allow
1107 // users to take the chance... (Asger)
1111 WriteAlert(_("ERROR!"),
1112 _("Old LyX file format found. "
1113 "Use LyX 0.10.x to read this!"));
1117 } else { // "\\lyxformat" not found
1118 WriteAlert(_("ERROR!"), _("Not a LyX file!"));
1121 WriteAlert(_("ERROR!"), _("Unable to read file!"));
1126 // Returns false if unsuccesful
1127 bool Buffer::writeFile(string const & filename, bool flag)
1129 // if flag is false writeFile will not create any GUI
1130 // warnings, only stderr.
1131 // Needed for autosave in background or panic save (Matthias 120496)
1133 if (read_only && (filename == this->filename)) {
1134 // Here we should come with a question if we should
1135 // perform the write anyway.
1137 lyxerr.print(_("Error! Document is read-only: ") + filename);
1139 WriteAlert(_("Error! Document is read-only: "), filename);
1143 FileInfo finfo(filename);
1144 if (finfo.exist() && !finfo.writable()) {
1145 // Here we should come with a question if we should
1146 // try to do the save anyway. (i.e. do a chmod first)
1148 lyxerr.print(_("Error! Cannot write file: ") + filename);
1150 WriteFSAlert(_("Error! Cannot write file: "), filename);
1154 FilePtr file(filename, FilePtr::truncate);
1157 lyxerr.print(_("Error! Cannot write file: ") + filename);
1159 WriteFSAlert(_("Error! Cannot write file: "), filename);
1162 // The top of the file should not be written by params.
1163 // collect some very important information
1164 string userName(getUserName()) ;
1166 // write out a comment in the top of the file
1168 "#This file was created by <%s> %s",
1169 userName.c_str(),(char*)date());
1171 "#LyX 1.0 (C) 1995-1999 Matthias Ettrich"
1172 " and the LyX Team\n");
1174 // at the very beginning the used lyx format
1175 fprintf(file, "\\lyxformat %.2f\n", LYX_FORMAT);
1177 // now write out the buffer parameters.
1178 params.writeFile(file);
1180 char footnoteflag = 0;
1183 // this will write out all the paragraphs
1184 // using recursive descent.
1185 paragraph->writeFile(file, params, footnoteflag, depth);
1187 // Write marker that shows file is complete
1188 fprintf(file, "\n\\the_end\n");
1191 lyxerr.print(_("Error! Could not close file properly: ")
1194 WriteFSAlert(_("Error! Could not close file properly: "),
1202 void Buffer::writeFileAscii(string const & filename, int linelen)
1204 FilePtr file(filename, FilePtr::write);
1235 ref_printed = false;
1239 WriteFSAlert(_("Error: Cannot write file:"), filename);
1242 fname1=TmpFileName();
1246 if (par->footnoteflag != LyXParagraph::NO_FOOTNOTE ||
1248 par->previous->footnoteflag == LyXParagraph::NO_FOOTNOTE){
1250 /* begins a footnote environment ? */
1251 if (footnoteflag != par->footnoteflag) {
1252 footnoteflag = par->footnoteflag;
1254 j=strlen(string_footnotekinds[par->footnotekind])+4;
1255 if (currlinelen+j > linelen)
1257 fprintf(file, "([%s] ",
1258 string_footnotekinds[par->footnotekind]);
1263 /* begins or ends a deeper area ?*/
1264 if (depth != par->depth) {
1265 if (par->depth > depth) {
1266 while (par->depth > depth) {
1271 while (par->depth < depth) {
1277 /* First write the layout */
1278 tmp = lyxstyle.NameOfLayout(params.textclass,par->layout);
1279 if (tmp == "Itemize") {
1281 ltype_depth = depth+1;
1282 } else if (tmp =="Enumerate") {
1284 ltype_depth = depth+1;
1285 } else if (strstr(tmp.c_str(),"ection")) {
1287 ltype_depth = depth+1;
1288 } else if (strstr(tmp.c_str(),"aragraph")) {
1290 ltype_depth = depth+1;
1291 } else if (tmp == "Description") {
1293 ltype_depth = depth+1;
1294 } else if (tmp == "Abstract") {
1297 } else if (tmp == "Bibliography") {
1305 /* maybe some vertical spaces */
1307 /* the labelwidthstring used in lists */
1311 /* some pagebreaks? */
1315 /* what about the alignment */
1318 /* dummy layout, that means a footnote ended */
1319 footnoteflag = LyXParagraph::NO_FOOTNOTE;
1320 fprintf(file, ") ");
1324 /* It might be a table */
1326 if (!lyxrc->ascii_roff_command.empty() &&
1327 lyxrc->ascii_roff_command != "none") {
1328 RoffAsciiTable(file,par);
1334 cells = par->table->columns;
1335 clen = new int [cells];
1336 memset(clen,0,sizeof(int)*cells);
1337 for (i = 0, j = 0, h=1; i < par->last; i++, h++) {
1338 c = par->GetChar(i);
1339 if (c == LYX_META_INSET) {
1340 if ((inset = par->GetInset(i))) {
1344 WriteFSAlert(_("Error: Cannot open temporary file:"), fname1);
1347 inset->Latex(fp,-1);
1349 remove(fname1.c_str());
1351 } else if (c == LYX_META_NEWLINE) {
1355 j = (++j) % par->table->NumberOfCellsInRow(actcell);
1363 font1 = LyXFont(LyXFont::ALL_INHERIT);
1365 for (i = 0,actpos=1; i < par->last; i++, actpos++) {
1366 if (!i && !footnoteflag && !noparbreak){
1367 fprintf(file, "\n\n");
1368 for(j=0; j<depth; j++)
1370 currlinelen = depth*2;
1372 case 0: /* Standart */
1373 case 4: /* (Sub)Paragraph */
1374 case 5: /* Description */
1376 case 6: /* Abstract */
1377 fprintf(file, "Abstract\n\n");
1379 case 7: /* Bibliography */
1381 fprintf(file, "References\n\n");
1386 fprintf(file,"%s ",par->labelstring.c_str());
1389 if (ltype_depth > depth) {
1390 for(j=ltype_depth-1; j>depth; j--)
1392 currlinelen += (ltype_depth-depth)*2;
1395 for(j=0;j<cells;j++) {
1397 for(h=0; h<(clen[j]+1); h++)
1400 fprintf(file,"+\n");
1401 for(j=0; j<depth; j++)
1403 currlinelen = depth*2;
1404 if (ltype_depth > depth) {
1405 for(j=ltype_depth; j>depth; j--)
1407 currlinelen += (ltype_depth-depth)*2;
1412 font2 = par->GetFontSettings(i);
1413 if (font1.latex() != font2.latex()) {
1414 if (font2.latex() == LyXFont::OFF)
1422 c = par->GetChar(i);
1426 case LYX_META_INSET:
1427 if ((inset = par->GetInset(i))) {
1429 inset->Latex(file,-1);
1430 currlinelen += (ftell(file) - fpos);
1431 actpos += (ftell(file) - fpos) - 1;
1434 case LYX_META_NEWLINE:
1436 if (par->table->NumberOfCellsInRow(actcell) <= cell) {
1437 for(j=actpos;j<clen[cell-1];j++)
1439 fprintf(file," |\n");
1440 for(j=0; j<depth; j++)
1442 currlinelen = depth*2;
1443 if (ltype_depth > depth) {
1444 for(j=ltype_depth; j>depth; j--)
1446 currlinelen += (ltype_depth-depth)*2;
1448 for(j=0;j<cells;j++) {
1450 for(h=0; h<(clen[j]+1); h++)
1453 fprintf(file,"+\n");
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;
1465 for(j=actpos; j<clen[cell-1]; j++)
1467 fprintf(file, " | ");
1471 currlinelen = actpos = 0;
1473 fprintf(file, "\n");
1474 for(j=0; j<depth; j++)
1476 currlinelen = depth*2;
1477 if (ltype_depth > depth) {
1478 for(j=ltype_depth; j>depth; j--)
1480 currlinelen += (ltype_depth-depth)*2;
1484 case LYX_META_HFILL:
1485 fprintf(file, "\t");
1487 case LYX_META_PROTECTED_SEPARATOR:
1491 fprintf(file, "\\");
1494 if (currlinelen > (linelen-10) \
1495 && c==' ' && (i+2 < par->last)) {
1496 fprintf(file, "\n");
1497 for(j=0; j<depth; j++)
1499 currlinelen = depth*2;
1500 if (ltype_depth > depth) {
1501 for(j=ltype_depth; j>depth; j--)
1503 currlinelen += (ltype_depth-depth)*2;
1505 } else if (c != '\0')
1506 fprintf(file, "%c", c);
1508 lyxerr.debug("writeAsciiFile: NULL char in structure.");
1514 for(j=actpos;j<clen[cell-1];j++)
1516 fprintf(file," |\n");
1517 for(j=0; j<depth; j++)
1519 currlinelen = depth*2;
1520 if (ltype_depth > depth) {
1521 for(j=ltype_depth; j>depth; j--)
1523 currlinelen += (ltype_depth-depth)*2;
1525 for(j=0;j<cells;j++) {
1527 for(h=0; h<(clen[j]+1); h++)
1530 fprintf(file,"+\n");
1536 fprintf(file, "\n");
1540 void Buffer::makeLaTeXFile(string const & filename,
1541 string const & original_path,
1542 bool nice, bool only_body)
1544 lyxerr.debug("makeLaTeXFile...", Error::LATEX);
1545 params.textclass = GetCurrentTextClass();
1546 niceFile = nice; // this will be used by Insetincludes.
1548 tex_code_break_column = lyxrc->ascii_linelen;
1550 LyXTextClass *tclass = lyxstyle.TextClass(params.textclass);
1552 FilePtr file(filename, FilePtr::write);
1554 WriteFSAlert(_("Error: Cannot write file:"),filename);
1558 // validate the buffer.
1559 lyxerr.debug(" Validating buffer...", Error::LATEX);
1560 LaTeXFeatures features(tclass->number_of_defined_layouts);
1562 lyxerr.debug(" Buffer validation done.", Error::LATEX);
1565 // The starting paragraph of the coming rows is the
1566 // first paragraph of the document. (Asger)
1567 texrow.start(paragraph, 0);
1569 string userName(getUserName());
1572 if (!only_body && nice) {
1573 LFile += "%% This LaTeX-file was created by <";
1574 LFile += userName + "> " + (char*)date();
1575 LFile += "%% LyX 1.0 (C) 1995-1999 by Matthias Ettrich and the LyX Team\n";
1576 LFile += "\n%% Do not edit this file unless you know what you are doing.\n";
1582 lyxerr.debug("lyx header finished");
1583 // There are a few differences between nice LaTeX and usual files:
1584 // usual is \batchmode, uses \listfiles and has a
1585 // special input@path to allow the including of figures
1586 // with either \input or \includegraphics (what figinsets do).
1587 // batchmode is not set if there is a tex_code_break_column.
1588 // In this case somebody is interested in the generated LaTeX,
1589 // so this is OK. input@path is set when the actual parameter
1590 // original_path is set. This is done for usual tex-file, but not
1591 // for nice-latex-file. (Matthias 250696)
1594 // code for usual, NOT nice-latex-file
1595 LFile += "\\batchmode\n"; // changed
1596 // from \nonstopmode
1598 // We don't need listfiles anymore
1599 //LFile += "\\listfiles\n";
1602 if (!original_path.empty()) {
1603 LFile += "\\makeatletter\n";
1605 LFile += "\\def\\input@path{{" + original_path
1608 LFile += "\\makeatother\n";
1612 LFile += "\\documentclass";
1614 string options; // the document class options.
1616 if (tokenPos(tclass->opt_fontsize, '|',params.fontsize) >= 0) {
1617 // only write if existing in list (and not default)
1618 options += params.fontsize;
1623 if (!params.use_geometry &&
1624 (params.paperpackage == PACKAGE_NONE)) {
1625 switch (params.papersize) {
1627 options += "a4paper,";
1629 case PAPER_USLETTER:
1630 options += "letterpaper,";
1633 options += "a5paper,";
1636 options += "b5paper,";
1638 case PAPER_EXECUTIVEPAPER:
1639 options += "executivepaper,";
1641 case PAPER_LEGALPAPER:
1642 options += "legalpaper,";
1648 if (params.sides != tclass->sides) {
1649 if (params.sides == 2)
1650 options += "twoside,";
1652 options += "oneside,";
1656 if (params.columns != tclass->columns) {
1657 if (params.columns == 2)
1658 options += "twocolumn,";
1660 options += "onecolumn,";
1663 if (!params.use_geometry && params.orientation == ORIENTATION_LANDSCAPE)
1664 options += "landscape,";
1666 // language should be a parameter to \documentclass
1667 if (params.language != "default") {
1668 options += params.language + ',';
1671 // the user-defined options
1672 if (!params.options.empty()) {
1673 options += params.options + ',';
1676 if (!options.empty()){
1677 options = strip(options, ',');
1684 LFile += lyxstyle.LatexnameOfClass(params.textclass);
1687 // end of \documentclass defs
1689 // font selection must be done before loading fontenc.sty
1690 if (params.fonts != "default") {
1691 LFile += "\\usepackage{" + params.fonts + "}\n";
1694 // this one is not per buffer
1695 if (lyxrc->fontenc != "default") {
1696 LFile += "\\usepackage[" + lyxrc->fontenc
1700 if (params.inputenc != "default") {
1701 LFile += "\\usepackage[" + params.inputenc
1706 /* at the very beginning the text parameters */
1707 if (params.paperpackage != PACKAGE_NONE) {
1708 switch (params.paperpackage) {
1710 LFile += "\\usepackage{a4}\n";
1713 case PACKAGE_A4WIDE:
1714 LFile += "\\usepackage{a4wide}\n";
1717 case PACKAGE_WIDEMARGINSA4:
1718 LFile += "\\usepackage[widemargins]{a4}\n";
1723 if (params.use_geometry) {
1724 LFile += "\\usepackage{geometry}\n";
1726 LFile += "\\geometry{verbose";
1727 if (params.orientation == ORIENTATION_LANDSCAPE)
1728 LFile += ",landscape";
1729 switch (params.papersize2) {
1730 case VM_PAPER_CUSTOM:
1731 if (!params.paperwidth.empty())
1732 LFile += ",paperwidth="
1733 + params.paperwidth;
1734 if (!params.paperheight.empty())
1735 LFile += ",paperheight="
1736 + params.paperheight;
1738 case VM_PAPER_USLETTER:
1739 LFile += ",letterpaper";
1741 case VM_PAPER_USLEGAL:
1742 LFile += ",legalpaper";
1744 case VM_PAPER_USEXECUTIVE:
1745 LFile += ",executivepaper";
1748 LFile += ",a3paper";
1751 LFile += ",a4paper";
1754 LFile += ",a5paper";
1757 LFile += ",b3paper";
1760 LFile += ",b4paper";
1763 LFile += ",b5paper";
1766 // default papersize ie VM_PAPER_DEFAULT
1767 switch (lyxrc->default_papersize) {
1768 case PAPER_DEFAULT: // keep compiler happy
1769 case PAPER_USLETTER:
1770 LFile += ",letterpaper";
1772 case PAPER_LEGALPAPER:
1773 LFile += ",legalpaper";
1775 case PAPER_EXECUTIVEPAPER:
1776 LFile += ",executivepaper";
1779 LFile += ",a3paper";
1782 LFile += ",a4paper";
1785 LFile += ",a5paper";
1788 LFile += ",b5paper";
1792 if (!params.topmargin.empty())
1793 LFile += ",tmargin=" + params.topmargin;
1794 if (!params.bottommargin.empty())
1795 LFile += ",bmargin=" + params.bottommargin;
1796 if (!params.leftmargin.empty())
1797 LFile += ",lmargin=" + params.leftmargin;
1798 if (!params.rightmargin.empty())
1799 LFile += ",rmargin=" + params.rightmargin;
1800 if (!params.headheight.empty())
1801 LFile += ",headheight=" + params.headheight;
1802 if (!params.headsep.empty())
1803 LFile += ",headsep=" + params.headsep;
1804 if (!params.footskip.empty())
1805 LFile += ",footskip=" + params.footskip;
1809 if (params.use_amsmath
1810 && !prefixIs(lyxstyle.LatexnameOfClass(params.textclass), "ams")) {
1811 LFile += "\\usepackage{amsmath}\n";
1814 if (tokenPos(tclass->opt_pagestyle, '|',params.pagestyle) >= 0) {
1815 if (params.pagestyle == "fancy") {
1816 LFile += "\\usepackage{fancyhdr}\n";
1819 LFile += "\\pagestyle{" + params.pagestyle + "}\n";
1823 // We try to load babel late, in case it interferes
1824 // with other packages.
1825 if (params.language != "default") {
1826 LFile += "\\usepackage{babel}\n";
1830 if (params.secnumdepth != tclass->secnumdepth) {
1831 LFile += "\\setcounter{secnumdepth}{";
1832 LFile += params.secnumdepth;
1836 if (params.tocdepth != tclass->tocdepth) {
1837 LFile += "\\setcounter{tocdepth}{";
1838 LFile += params.tocdepth;
1843 if (params.paragraph_separation) {
1844 switch (params.defskip.kind()) {
1845 case VSpace::SMALLSKIP:
1846 LFile += "\\setlength\\parskip{\\smallskipamount}\n";
1848 case VSpace::MEDSKIP:
1849 LFile += "\\setlength\\parskip{\\medskipamount}\n";
1851 case VSpace::BIGSKIP:
1852 LFile += "\\setlength\\parskip{\\bigskipamount}\n";
1854 case VSpace::LENGTH:
1855 LFile += "\\setlength\\parskip{"
1856 + params.defskip.length().asLatexString()
1859 default: // should never happen // Then delete it.
1860 LFile += "\\setlength\\parskip{\\medskipamount}\n";
1865 LFile += "\\setlength\\parindent{0pt}\n";
1869 // Write out what we've generated so far...and reset LFile
1870 fwrite(LFile.c_str(), sizeof(char), LFile.length(), file);
1873 // Now insert the LyX specific LaTeX commands...
1874 string preamble, tmppreamble;
1876 // The optional packages;
1877 preamble = features.getPackages(params);
1879 // this might be useful...
1880 preamble += "\n\\makeatletter\n\n";
1882 // Some macros LyX will need
1883 tmppreamble = features.getMacros(params);
1885 if (!tmppreamble.empty()) {
1886 preamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1887 "LyX specific LaTeX commands.\n"
1888 + tmppreamble + '\n';
1891 // the text class specific preamble
1892 tmppreamble = features.getTClassPreamble(params);
1893 if (!tmppreamble.empty()) {
1894 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1895 "Textclass specific LaTeX commands.\n"
1896 + tmppreamble + '\n';
1899 /* the user-defined preamble */
1900 if (!params.preamble.empty()) {
1901 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1902 "User specified LaTeX commands.\n"
1903 + params.preamble + '\n';
1906 preamble += "\\makeatother\n\n";
1908 // Itemize bullet settings need to be last in case the user
1909 // defines their own bullets that use a package included
1910 // in the user-defined preamble -- ARRae
1911 for (int i = 0; i < 4; ++i) {
1912 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
1913 preamble += "\\renewcommand\\labelitemi";
1915 // `i' is one less than the item to modify
1928 preamble += "[0]{" + params.user_defined_bullets[i].getText() + "}\n";
1932 for (int j = countChar(preamble, '\n'); j-- ;) {
1936 // A bit faster than printing a char at a time I think.
1937 fwrite(preamble.c_str(), sizeof(char),
1938 preamble.length(), file);
1941 LFile += "\\begin{document}\n\n";
1945 lyxerr.debug("preamble finished, now the body.");
1947 bool was_title = false;
1948 bool already_title = false;
1954 LyXParagraph *par = paragraph;
1960 lyxerr.debug("Error in MakeLateXFile.", Error::LATEX);
1961 LyXLayout * layout = lyxstyle.Style(params.textclass,
1964 if (layout->intitle) {
1965 if (already_title) {
1966 lyxerr.print("Error in MakeLatexFile: You"
1967 " should not mix title layouts"
1968 " with normal ones.");
1971 } else if (was_title && !already_title) {
1972 LFile += "\\maketitle\n";
1974 already_title = true;
1977 // We are at depth 0 so we can just use
1978 // ordinary \footnote{} generation
1979 // flag this with ftcount
1981 if (layout->isEnvironment()
1982 || par->pextra_type != PEXTRA_NONE) {
1983 par = par->TeXEnvironment(LFile, texrow,
1984 ftnote, ft_texrow, ftcount);
1986 par = par->TeXOnePar(LFile, texrow,
1987 ftnote, ft_texrow, ftcount);
1990 // Write out what we've generated...and reset LFile
1993 LFile += "\\addtocounter{footnote}{-";
1994 LFile += ftcount - 1;
1998 texrow += ft_texrow;
2003 if (loop_count == 2) {
2004 // fwrite()ing every second time through the loop
2005 // gains a few extra % of speed; going higher than
2006 // 2 will slow things down again. I'll look at
2007 // LFile.length() in a future revision. ARRae
2008 fwrite(LFile.c_str(), sizeof(char),
2009 LFile.length(), file);
2015 // It might be that we only have a title in this document
2016 if (was_title && !already_title) {
2017 LFile += "\\maketitle\n";
2022 LFile += "\\end{document}\n";
2025 lyxerr.debug("makeLaTeXFile...done", Error::LATEX);
2027 lyxerr.debug("LaTeXFile for inclusion made.", Error::LATEX);
2030 // Just to be sure. (Asger)
2033 // Write out what we've generated...and reset LFile
2034 fwrite(LFile.c_str(), sizeof(char), LFile.length(), file);
2037 // tex_code_break_column's value is used to decide
2038 // if we are in batchmode or not (within mathed_write()
2039 // in math_write.C) so we must set it to a non-zero
2040 // value when we leave otherwise we save incorrect .lyx files.
2041 tex_code_break_column = lyxrc->ascii_linelen;
2044 WriteFSAlert(_("Error! Could not close file properly:"), filename);
2046 lyxerr.debug("Finished making latex file.");
2050 bool Buffer::isLatex()
2052 return lyxstyle.TextClass(params.textclass)->output_type == LATEX;
2056 bool Buffer::isLinuxDoc()
2058 return lyxstyle.TextClass(params.textclass)->output_type == LINUXDOC;
2062 bool Buffer::isLiterate()
2064 return lyxstyle.TextClass(params.textclass)->output_type == LITERATE;
2068 bool Buffer::isDocBook()
2070 return lyxstyle.TextClass(params.textclass)->output_type == DOCBOOK;
2074 bool Buffer::isSGML()
2076 return lyxstyle.TextClass(params.textclass)->output_type == LINUXDOC ||
2077 lyxstyle.TextClass(params.textclass)->output_type == DOCBOOK;
2081 void Buffer::sgmlOpenTag(FILE * file,int depth,string & latexname)
2083 static char *space[] = {" "," "," "," "," "," "," ",
2086 fprintf(file,"%s<%s>\n",space[depth],latexname.c_str());
2090 void Buffer::sgmlCloseTag(FILE * file,int depth,string & latexname)
2092 static char *space[] = {" "," "," "," "," "," "," ",
2095 fprintf(file,"%s</%s>\n",space[depth],latexname.c_str());
2099 void Buffer::makeLinuxDocFile(string const & filename, int column)
2101 LyXParagraph *par = paragraph;
2103 string top_element=lyxstyle.LatexnameOfClass(params.textclass);
2104 string environment_stack[10];
2107 int depth=0; /* paragraph depth */
2109 FilePtr file(filename, FilePtr::write);
2110 tex_code_break_column = column;
2113 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), filename);
2120 if (params.preamble.empty()) {
2121 fprintf(file, "<!doctype linuxdoc system>\n\n");
2124 fprintf(file, "<!doctype linuxdoc system \n [ %s \n]>\n\n",
2125 params.preamble.c_str() );
2128 string userName(getUserName());
2129 fprintf(file, "<!-- LinuxDoc file was created by LyX 1.0 (C) 1995-1999 ");
2130 fprintf(file, "by <%s> %s -->\n", userName.c_str(), (char *)date());
2132 if(params.options.empty())
2133 sgmlOpenTag(file,0,top_element);
2135 string top = top_element;
2137 top += params.options;
2138 sgmlOpenTag(file,0,top);
2142 int desc_on=0; /* description mode*/
2143 LyXLayout *style=lyxstyle.Style(GetCurrentTextClass(), par->layout);
2144 par->AutoDeleteInsets();
2146 /* treat <toc> as a special case for compatibility with old code */
2147 if (par->GetChar(0) == LYX_META_INSET) {
2148 Inset *inset = par->GetInset(0);
2149 char lyx_code = inset->LyxCode();
2150 if (lyx_code ==Inset::TOC_CODE){
2152 sgmlOpenTag(file, depth, temp);
2155 linuxDocHandleFootnote(file, par, depth);
2160 /* environment tag closing */
2161 for( ;depth > par->depth; depth--) {
2162 sgmlCloseTag(file,depth,environment_stack[depth]);
2163 environment_stack[depth].erase();
2166 /* write opening SGML tags */
2167 switch(style->latextype) {
2168 case LATEX_PARAGRAPH:
2169 if(depth == par->depth
2170 && !environment_stack[depth].empty()) {
2171 sgmlCloseTag(file,depth,environment_stack[depth]);
2172 environment_stack[depth].erase();
2176 fprintf(file,"</p>");
2178 sgmlOpenTag(file,depth,style->latexname);
2183 LinuxDocError(par, 0, _("Error : Wrong depth for LatexType Command.\n"));
2185 if (!environment_stack[depth].empty()){
2186 sgmlCloseTag(file,depth,environment_stack[depth]);
2187 fprintf(file, "</p>");
2190 environment_stack[depth].erase();
2191 sgmlOpenTag(file,depth, style->latexname);
2194 case LATEX_ENVIRONMENT:
2195 case LATEX_ITEM_ENVIRONMENT:
2196 if(depth == par->depth
2197 && environment_stack[depth]!=style->latexname
2198 && !environment_stack[depth].empty()) {
2200 sgmlCloseTag(file,depth,environment_stack[depth]);
2201 environment_stack[depth].erase();
2203 if (depth < par->depth) {
2205 environment_stack[depth].erase();
2207 if (environment_stack[depth] != style->latexname) {
2210 sgmlOpenTag(file,depth,temp);
2212 environment_stack[depth]= style->latexname;
2213 sgmlOpenTag(file,depth,environment_stack[depth]);
2215 if(style->latextype == LATEX_ENVIRONMENT) break;
2217 desc_on =(style->labeltype == LABEL_MANUAL);
2224 sgmlOpenTag(file,depth+1,item_name);
2227 sgmlOpenTag(file,depth,style->latexname);
2232 SimpleLinuxDocOnePar(file, par, desc_on, depth);
2235 linuxDocHandleFootnote(file,par,depth);
2237 while(par && par->IsDummy());
2240 /* write closing SGML tags */
2241 switch(style->latextype) {
2243 case LATEX_ENVIRONMENT:
2244 case LATEX_ITEM_ENVIRONMENT:
2247 sgmlCloseTag(file,depth,style->latexname);
2255 /* Close open tags */
2256 for(;depth>0;depth--)
2257 sgmlCloseTag(file,depth,environment_stack[depth]);
2259 if(!environment_stack[depth].empty())
2260 sgmlCloseTag(file,depth,environment_stack[depth]);
2262 fprintf(file, "\n\n");
2263 sgmlCloseTag(file,0,top_element);
2266 WriteFSAlert(_("Error! Could not close file properly:"),
2272 void Buffer::linuxDocHandleFootnote(FILE *file,LyXParagraph* &par, int const depth)
2274 string tag="footnote";
2276 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2277 sgmlOpenTag(file,depth+1,tag);
2278 SimpleLinuxDocOnePar(file, par, 0,depth+1);
2279 sgmlCloseTag(file,depth+1,tag);
2284 void Buffer::DocBookHandleCaption(FILE *file, string &inner_tag,
2285 int const depth, int desc_on,
2288 LyXParagraph *tpar = par;
2289 string tmp_par, extra_par;
2290 while (tpar && (tpar->footnoteflag != LyXParagraph::NO_FOOTNOTE) &&
2291 (tpar->layout != lyxstyle.NumberOfLayout(params.textclass,"Caption")))
2294 tpar->layout==lyxstyle.NumberOfLayout(params.textclass,"Caption")) {
2295 sgmlOpenTag(file,depth+1,inner_tag);
2296 SimpleDocBookOnePar(tmp_par,extra_par,tpar,desc_on,depth+2);
2297 tmp_par = strip(tmp_par);
2298 tmp_par = frontStrip(tmp_par);
2299 fprintf(file,"%s",tmp_par.c_str());
2300 sgmlCloseTag(file,depth+1,inner_tag);
2301 if(!extra_par.empty())
2302 fprintf(file,"%s",extra_par.c_str());
2306 void Buffer::DocBookHandleFootnote(FILE *file,LyXParagraph* &par, int const depth)
2308 string tag,inner_tag;
2309 string tmp_par,extra_par;
2310 bool inner_span = false;
2313 // This is not how I like to see enums. They should not be anonymous
2314 // and variables of its type should not be declared right after the
2315 // last brace. (Lgb)
2322 } last=NO_ONE, present=FOOTNOTE_LIKE;
2324 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2327 if(!tmp_par.empty()) {
2328 fprintf(file,"%s",tmp_par.c_str());
2330 sgmlCloseTag(file,depth+1,inner_tag);
2331 sgmlOpenTag(file,depth+1,inner_tag);
2337 fprintf(file,"%s",tmp_par.c_str());
2338 if(!inner_tag.empty()) sgmlCloseTag(file,depth+1,inner_tag);
2339 if(!extra_par.empty()) fprintf(file,"%s",extra_par.c_str());
2340 if(!tag.empty()) sgmlCloseTag(file,depth,tag);
2343 switch (par->footnotekind) {
2344 case LyXParagraph::FOOTNOTE:
2345 case LyXParagraph::ALGORITHM:
2348 present=FOOTNOTE_LIKE;
2351 case LyXParagraph::MARGIN:
2354 present=MARGIN_LIKE;
2357 case LyXParagraph::FIG:
2358 case LyXParagraph::WIDE_FIG:
2364 case LyXParagraph::TAB:
2365 case LyXParagraph::WIDE_TAB:
2372 sgmlOpenTag(file,depth,tag);
2373 if ((present == TAB_LIKE) || (present == FIG_LIKE)) {
2374 DocBookHandleCaption(file, inner_tag, depth,
2378 sgmlOpenTag(file,depth+1,inner_tag);
2381 // ignore all caption here, we processed them above!!!
2382 if (par->layout != lyxstyle.NumberOfLayout(params.textclass,
2384 SimpleDocBookOnePar(tmp_par,extra_par,par,
2387 tmp_par = frontStrip(strip(tmp_par));
2392 fprintf(file,"%s",tmp_par.c_str());
2393 if(!inner_tag.empty()) sgmlCloseTag(file,depth+1,inner_tag);
2394 if(!extra_par.empty()) fprintf(file,"%s",extra_par.c_str());
2395 if(!tag.empty()) sgmlCloseTag(file,depth,tag);
2400 /* push a tag in a style stack */
2401 void Buffer::push_tag(FILE *file, char const *tag,
2402 int& pos, char stack[5][3])
2406 /* pop all previous tags */
2407 for (j=pos; j>=0; j--)
2408 fprintf(file, "</%s>", stack[j]);
2411 sprintf(stack[++pos], "%s", tag);
2414 for (j=0; j<=pos; j++)
2415 fprintf(file, "<%s>", stack[j]);
2419 // pop a tag from a style stack
2420 void Buffer::pop_tag(FILE *file, char const * tag,
2421 int& pos, char stack[5][3])
2425 // pop all tags till specified one
2426 for (j=pos; (j>=0) && (strcmp(stack[j], tag)); j--)
2427 fprintf(file, "</%s>", stack[j]);
2430 fprintf(file, "</%s>", tag);
2432 // push all tags, but the specified one
2433 for (j=j+1; j<=pos; j++) {
2434 fprintf(file, "<%s>", stack[j]);
2435 strcpy(stack[j-1], stack[j]);
2441 /* handle internal paragraph parsing -- layout already processed */
2443 // checks, if newcol chars should be put into this line
2444 // writes newline, if necessary.
2446 void linux_doc_line_break(FILE *file, unsigned int &colcount, const unsigned int newcol)
2449 if (colcount > lyxrc->ascii_linelen) {
2450 fprintf(file, "\n");
2451 colcount = newcol; // assume write after this call
2456 void Buffer::SimpleLinuxDocOnePar(FILE *file, LyXParagraph *par, int desc_on, int const depth)
2458 LyXFont font1,font2;
2462 LyXLayout * style = lyxstyle.Style(params.textclass, par->GetLayout());
2464 char family_type = 0; // family font flag
2465 bool is_bold = false; // series font flag
2466 char shape_type = 0; // shape font flag
2467 bool is_em = false; // emphasis (italic) font flag
2469 int stack_num = -1; // style stack position
2470 char stack[5][3]; // style stack
2471 unsigned int char_line_count = 5; // Heuristic choice ;-)
2473 if (style->labeltype != LABEL_MANUAL)
2476 main_body = par->BeginningOfMainBody();
2478 /* gets paragraph main font */
2480 font1 = style->labelfont;
2482 font1 = style->font;
2485 /* parsing main loop */
2486 for (int i = 0; i < par->last; i++) {
2488 /* handle quote tag */
2489 if (i == main_body && !par->IsDummy()) {
2491 font1 = style->font;
2494 font2 = par->getFont(i);
2496 if (font1.family() != font2.family()) {
2497 switch(family_type) {
2499 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2500 push_tag(file, "tt", stack_num, stack);
2503 else if (font2.family() == LyXFont::SANS_FAMILY) {
2504 push_tag(file, "sf", stack_num, stack);
2509 pop_tag(file, "tt", stack_num, stack);
2510 if (font2.family() == LyXFont::SANS_FAMILY) {
2511 push_tag(file, "sf", stack_num, stack);
2519 pop_tag(file, "sf", stack_num, stack);
2520 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2521 push_tag(file, "tt", stack_num, stack);
2530 /* handle bold face */
2531 if (font1.series() != font2.series()) {
2532 if (font2.series() == LyXFont::BOLD_SERIES) {
2533 push_tag(file, "bf", stack_num, stack);
2537 pop_tag(file, "bf", stack_num, stack);
2542 /* handle italic and slanted fonts */
2543 if (font1.shape() != font2.shape()) {
2544 switch(shape_type) {
2546 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2547 push_tag(file, "it", stack_num, stack);
2550 else if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2551 push_tag(file, "sl", stack_num, stack);
2556 pop_tag(file, "it", stack_num, stack);
2557 if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2558 push_tag(file, "sl", stack_num, stack);
2566 pop_tag(file, "sl", stack_num, stack);
2567 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2568 push_tag(file, "it", stack_num, stack);
2576 /* handle <em> tag */
2577 if (font1.emph() != font2.emph()) {
2578 if (font2.emph() == LyXFont::ON) {
2579 push_tag(file, "em", stack_num, stack);
2582 pop_tag(file, "em", stack_num, stack);
2587 c = par->GetChar(i);
2589 if (font2.latex() == LyXFont::ON) {
2590 // "TeX"-Mode on ==> SGML-Mode on.
2592 fprintf(file, "%c", c); // see LaTeX-Generation...
2594 } else if (c == LYX_META_INSET) {
2595 inset = par->GetInset(i);
2597 inset->Linuxdoc(tmp_out);
2598 fprintf(file,"%s",tmp_out.c_str());
2602 if (par->linuxDocConvertChar(c, sgml_string)
2603 && !style->free_spacing) { // in freespacing
2605 // non-breaking characters
2609 linux_doc_line_break(file, char_line_count, 6);
2610 fprintf(file, "</tag>");
2614 linux_doc_line_break(file, char_line_count, 1);
2615 fprintf(file, "%c", c);
2619 fprintf(file, "%s", sgml_string.c_str());
2620 char_line_count += sgml_string.length();
2626 /* needed if there is an optional argument but no contents */
2627 if (main_body > 0 && main_body == par->last) {
2628 font1 = style->font;
2631 /* pop all defined Styles */
2632 for (j=stack_num; j>=0; j--) {
2633 linux_doc_line_break(file,
2635 3+strlen(stack[j]));
2636 fprintf(file, "</%s>", stack[j]);
2639 /* resets description flag correctly */
2642 /* <tag> not closed... */
2643 linux_doc_line_break(file, char_line_count, 6);
2644 fprintf(file, "</tag>");
2647 /* fprintf(file, "</p>");*/
2653 /* print an error message */
2654 void Buffer::LinuxDocError(LyXParagraph *par, int pos,
2655 char const *message)
2657 InsetError *new_inset;
2659 /* insert an error marker in text */
2660 new_inset = new InsetError(message);
2661 par->InsertChar(pos, LYX_META_INSET);
2662 par->InsertInset(pos, new_inset);
2665 // This constant defines the maximum number of
2666 // environment layouts that can be nesteded.
2667 // The same applies for command layouts.
2668 // These values should be more than enough.
2669 // José Matos (1999/07/22)
2671 enum { MAX_NEST_LEVEL = 25};
2673 void Buffer::makeDocBookFile(string const & filename, int column)
2675 LyXParagraph *par = paragraph;
2677 string top_element=lyxstyle.LatexnameOfClass(params.textclass);
2678 string environment_stack[MAX_NEST_LEVEL];
2679 string environment_inner[MAX_NEST_LEVEL];
2680 string command_stack[MAX_NEST_LEVEL];
2681 bool command_flag=false;
2682 int command_depth=0,command_base=0,cmd_depth=0;
2684 string item_name,command_name;
2685 string c_depth,c_params,tmps;
2687 int depth=0; /* paragraph depth */
2689 FilePtr file(filename, FilePtr::write);
2690 tex_code_break_column = column;
2693 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), filename);
2700 fprintf(file, "<!doctype %s public \"-//OASIS//DTD DocBook V3.1//EN\"",top_element.c_str());
2702 if (params.preamble.empty())
2703 fprintf(file, ">\n\n");
2705 fprintf(file, "\n [ %s \n]>\n\n",params.preamble.c_str() );
2707 string userName(getUserName());
2709 "<!-- DocBook file was created by LyX 1.0 (C) 1995-1999\n");
2710 fprintf(file, "by <%s> %s -->\n", userName.c_str(), (char *)date());
2712 if(params.options.empty())
2713 sgmlOpenTag(file,0,top_element);
2715 string top = top_element;
2717 top += params.options;
2718 sgmlOpenTag(file,0,top);
2722 int desc_on=0; /* description mode*/
2723 LyXLayout * style = lyxstyle.Style(GetCurrentTextClass(),
2725 par->AutoDeleteInsets();
2727 /* environment tag closing */
2728 for( ;depth > par->depth; depth--) {
2729 if(environment_inner[depth] != "!-- --") {
2730 item_name="listitem";
2731 sgmlCloseTag(file,command_depth+depth,
2733 if( environment_inner[depth] == "varlistentry")
2734 sgmlCloseTag(file,depth+command_depth,
2735 environment_inner[depth]);
2737 sgmlCloseTag(file,depth+command_depth,
2738 environment_stack[depth]);
2739 environment_stack[depth].erase();
2740 environment_inner[depth].erase();
2743 if(depth == par->depth
2744 && environment_stack[depth]!=style->latexname
2745 && !environment_stack[depth].empty()) {
2746 if(environment_inner[depth] != "!-- --") {
2747 item_name="listitem";
2748 sgmlCloseTag(file,command_depth+depth,
2750 if( environment_inner[depth] == "varlistentry")
2751 sgmlCloseTag(file,depth+command_depth,
2752 environment_inner[depth]);
2755 sgmlCloseTag(file,depth+command_depth,
2756 environment_stack[depth]);
2758 environment_stack[depth].erase();
2759 environment_inner[depth].erase();
2762 // Write opening SGML tags.
2763 switch(style->latextype) {
2764 case LATEX_PARAGRAPH:
2765 if(style->latexname != "dummy")
2766 sgmlOpenTag(file, depth+command_depth,
2772 LinuxDocError(par, 0,
2773 _("Error : Wrong depth for "
2774 "LatexType Command.\n"));
2776 command_name=style->latexname;
2778 tmps=style->latexparam;
2779 c_params= split(tmps, c_depth,'|');
2781 cmd_depth=atoi(c_depth.c_str());
2784 if(cmd_depth<command_base) {
2785 for(int j = command_depth;
2786 j >= command_base; j--)
2787 if(!command_stack[j].empty())
2788 sgmlCloseTag(file,j,command_stack[j]);
2789 command_depth=command_base=cmd_depth;
2791 else if(cmd_depth<=command_depth) {
2792 for(int j= command_depth;
2793 j >= cmd_depth; j--)
2795 if(!command_stack[j].empty())
2796 sgmlCloseTag(file,j,command_stack[j]);
2797 command_depth=cmd_depth;
2800 command_depth=cmd_depth;
2803 command_depth = command_base = cmd_depth;
2804 command_flag = true;
2806 command_stack[command_depth]=command_name;
2808 // treat label as a special case for
2809 // more WYSIWYM handling.
2810 if (par->GetChar(0) == LYX_META_INSET) {
2811 Inset *inset = par->GetInset(0);
2812 char lyx_code = inset->LyxCode();
2813 if (lyx_code ==Inset::LABEL_CODE){
2814 command_name+= " id=\"";
2815 command_name+=((InsetCommand *) inset)->getContents();
2821 sgmlOpenTag(file,depth+command_depth, command_name);
2823 sgmlOpenTag(file,depth+1+command_depth,item_name);
2826 case LATEX_ENVIRONMENT:
2827 case LATEX_ITEM_ENVIRONMENT:
2828 if (depth < par->depth) {
2830 environment_stack[depth].erase();
2833 if (environment_stack[depth] != style->latexname) {
2834 environment_stack[depth]= style->latexname;
2835 environment_inner[depth]= "!-- --";
2836 sgmlOpenTag(file, depth + command_depth,
2837 environment_stack[depth]);
2839 if(environment_inner[depth] != "!-- --") {
2840 item_name="listitem";
2842 command_depth + depth,
2844 if (environment_inner[depth] == "varlistentry")
2846 depth+command_depth,
2847 environment_inner[depth]);
2851 if(style->latextype == LATEX_ENVIRONMENT) {
2852 if(!style->latexparam.empty())
2853 sgmlOpenTag(file, depth+command_depth,
2858 desc_on =(style->labeltype == LABEL_MANUAL);
2861 environment_inner[depth]="varlistentry";
2863 environment_inner[depth]="listitem";
2865 sgmlOpenTag(file,depth+1+command_depth,
2866 environment_inner[depth]);
2870 sgmlOpenTag(file,depth+1+command_depth,
2875 sgmlOpenTag(file,depth+1+command_depth,
2880 sgmlOpenTag(file,depth+command_depth,style->latexname);
2885 string tmp_par,extra_par;
2887 SimpleDocBookOnePar(tmp_par,extra_par, par, desc_on,
2888 depth+1+command_depth);
2889 fprintf(file,"%s",tmp_par.c_str());
2892 DocBookHandleFootnote(file,par, depth+1+command_depth);
2894 while(par && par->IsDummy());
2897 /* write closing SGML tags */
2898 switch(style->latextype) {
2901 sgmlCloseTag(file,depth+command_depth,end_tag);
2903 case LATEX_ENVIRONMENT:
2904 if(!style->latexparam.empty())
2905 sgmlCloseTag(file,depth+command_depth,
2908 case LATEX_ITEM_ENVIRONMENT:
2909 if(desc_on==1) break;
2911 sgmlCloseTag(file,depth+1+command_depth,end_tag);
2913 case LATEX_PARAGRAPH:
2914 if( style->latexname != "dummy")
2915 sgmlCloseTag(file,depth+command_depth,
2919 sgmlCloseTag(file,depth+command_depth,
2926 for(;depth>=0;depth--) {
2927 if(!environment_stack[depth].empty()) {
2928 if(environment_inner[depth] != "!-- --") {
2929 item_name="listitem";
2930 sgmlCloseTag(file,command_depth+depth,
2932 if( environment_inner[depth] == "varlistentry")
2933 sgmlCloseTag(file,depth+command_depth,
2934 environment_inner[depth]);
2937 sgmlCloseTag(file,depth+command_depth,
2938 environment_stack[depth]);
2942 for(int j=command_depth;j>=command_base;j--)
2943 if(!command_stack[j].empty())
2944 sgmlCloseTag(file,j,command_stack[j]);
2946 fprintf(file, "\n\n");
2947 sgmlCloseTag(file,0,top_element);
2950 WriteFSAlert(_("Error! Could not close file properly:"),
2956 void Buffer::SimpleDocBookOnePar(string & file, string & extra,
2957 LyXParagraph * par, int & desc_on,
2961 par->SimpleDocBookOneTablePar(file, extra, desc_on, depth);
2964 LyXFont font1,font2;
2968 string emph="emphasis";
2969 bool emph_flag=false;
2970 int char_line_count=0;
2972 LyXLayout * style = lyxstyle.Style(params.textclass, par->GetLayout());
2974 if (style->labeltype != LABEL_MANUAL)
2977 main_body = par->BeginningOfMainBody();
2979 /* gets paragraph main font */
2981 font1 = style->labelfont;
2983 font1 = style->font;
2985 char_line_count = depth;
2986 if(!style->free_spacing)
2987 for (j=0;j< depth;j++)
2990 /* parsing main loop */
2991 for (int i = 0; i < par->last; i++) {
2993 font2 = par->getFont(i);
2995 /* handle <emphasis> tag */
2996 if (font1.emph() != font2.emph() && i) {
2997 if (font2.emph() == LyXFont::ON) {
2998 file += "<emphasis>";
3001 file += "</emphasis>";
3006 c = par->GetChar(i);
3008 if (c == LYX_META_INSET) {
3009 inset = par->GetInset(i);
3011 inset->DocBook(tmp_out);
3013 // This code needs some explanation:
3014 // Two insets are treated specially
3015 // label if it is the first element in a command paragraph
3017 // graphics inside tables or figure floats can't go on
3018 // title (the equivalente in latex for this case is caption
3019 // and title should come first
3022 if(desc_on!=3 || i!=0) {
3023 if(tmp_out[0]=='@') {
3025 extra += frontStrip(tmp_out, '@');
3027 file += frontStrip(tmp_out, '@');
3032 } else if (font2.latex() == LyXFont::ON) {
3033 // "TeX"-Mode on ==> SGML-Mode on.
3040 if (par->linuxDocConvertChar(c, sgml_string)
3041 && !style->free_spacing) { // in freespacing
3043 // non-breaking characters
3048 file += "</term><listitem><para>";
3056 file += sgml_string;
3062 /* needed if there is an optional argument but no contents */
3063 if (main_body > 0 && main_body == par->last) {
3064 font1 = style->font;
3068 file += "</emphasis>";
3071 /* resets description flag correctly */
3074 /* <term> not closed... */
3082 bool Buffer::removeAutoInsets()
3084 LyXParagraph *par = paragraph;
3086 LyXCursor cursor = text->cursor;
3087 LyXCursor tmpcursor = cursor;
3088 cursor.par = tmpcursor.par->ParFromPos(tmpcursor.pos);
3089 cursor.pos = tmpcursor.par->PositionInParFromPos(tmpcursor.pos);
3093 if (par->AutoDeleteInsets()){
3095 if (par->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE){
3096 /* this is possible now, since SetCursor takes
3097 care about footnotes */
3098 text->SetCursorIntern(par, 0);
3099 text->RedoParagraphs(text->cursor, text->cursor.par->Next());
3100 text->FullRebreak();
3105 /* avoid forbidden cursor positions caused by error removing */
3106 if (cursor.pos > cursor.par->Last())
3107 cursor.pos = cursor.par->Last();
3108 text->SetCursorIntern(cursor.par, cursor.pos);
3114 int Buffer::runLaTeX()
3116 if (!text) return 0;
3120 // get LaTeX-Filename
3121 string name = SpaceLess(ChangeExtension (filename, ".tex", true));
3123 string path = OnlyPath(filename);
3125 string org_path = path;
3126 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
3130 PathPush(path); // path to LaTeX file
3131 users->getOwner()->getMiniBuffer()->Set(_("Running LaTeX..."));
3133 // Remove all error insets
3134 bool a = removeAutoInsets();
3136 // generate the LaTeX file if necessary
3137 //if (!isDviClean() || a) {
3138 // makeLaTeXFile(name, org_path, false);
3142 // Always generate the LaTeX file
3143 makeLaTeXFile(name, org_path, false);
3146 // do the LaTex run(s)
3148 LaTeX latex(lyxrc->latex_command, name, filepath);
3149 int res = latex.run(terr,users->getOwner()->getMiniBuffer()); // running latex
3151 // check return value from latex.run().
3152 if ((res & LaTeX::NO_LOGFILE)) {
3153 WriteAlert(_("LaTeX did not work!"),
3154 _("Missing log file:"), name);
3155 } else if ((res & LaTeX::ERRORS)) {
3156 users->getOwner()->getMiniBuffer()->Set(_("Done"));
3157 // Insert all errors as errors boxes
3160 // Dvi should also be kept dirty if the latex run
3161 // ends up with errors. However it should be possible
3162 // to view a dirty dvi too.
3164 //no errors or any other things to think about so:
3165 users->getOwner()->getMiniBuffer()->Set(_("Done"));
3169 // if we removed error insets before we ran LaTeX or if we inserted
3170 // error insets after we ran LaTeX this must be run:
3171 if (a || (res & LaTeX::ERRORS)){
3174 users->updateScrollbar();
3177 PathPop(); // path to LaTeX file
3179 return latex.getNumErrors();
3183 int Buffer::runLiterate()
3185 if (!text) return 0;
3189 // get LaTeX-Filename
3190 string name = SpaceLess(ChangeExtension (filename, ".tex", true));
3191 // get Literate-Filename
3192 string lit_name = SpaceLess(ChangeExtension (filename, lyxrc->literate_extension, true));
3194 string path = OnlyPath(filename);
3196 string org_path = path;
3197 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
3201 PathPush(path); // path to Literate file
3202 users->getOwner()->getMiniBuffer()->Set(_("Running Literate..."));
3204 // Remove all error insets
3205 bool a = removeAutoInsets();
3207 // generate the Literate file if necessary
3208 if (!isDviClean() || a) {
3209 makeLaTeXFile(lit_name, org_path, false);
3214 Literate literate(lyxrc->latex_command, name, filepath,
3216 lyxrc->literate_command, lyxrc->literate_error_filter,
3217 lyxrc->build_command, lyxrc->build_error_filter);
3218 int res = literate.weave(terr,users->getOwner()->getMiniBuffer());
3220 // check return value from literate.weave().
3221 if ((res & Literate::NO_LOGFILE)) {
3222 WriteAlert(_("Literate command did not work!"),
3223 _("Missing log file:"), name);
3224 } else if ((res & Literate::ERRORS)) {
3225 users->getOwner()->getMiniBuffer()->Set(_("Done"));
3226 // Insert all errors as errors boxes
3229 // Dvi should also be kept dirty if the latex run
3230 // ends up with errors. However it should be possible
3231 // to view a dirty dvi too.
3233 //no errors or any other things to think about so:
3234 users->getOwner()->getMiniBuffer()->Set(_("Done"));
3238 // if we removed error insets before we ran LaTeX or if we inserted
3239 // error insets after we ran LaTeX this must be run:
3240 if (a || (res & Literate::ERRORS)){
3243 users->updateScrollbar();
3246 PathPop(); // path to LaTeX file
3248 return literate.getNumErrors();
3252 int Buffer::buildProgram()
3254 if (!text) return 0;
3258 // get LaTeX-Filename
3259 string name = SpaceLess(ChangeExtension (filename, ".tex", true));
3260 // get Literate-Filename
3261 string lit_name = SpaceLess(ChangeExtension (filename, lyxrc->literate_extension, true));
3263 string path = OnlyPath(filename);
3265 string org_path = path;
3266 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
3270 PathPush(path); // path to Literate file
3271 users->getOwner()->getMiniBuffer()->Set(_("Building Program..."));
3273 // Remove all error insets
3274 bool a = removeAutoInsets();
3276 // generate the LaTeX file if necessary
3277 if (!isNwClean() || a) {
3278 makeLaTeXFile(lit_name, org_path, false);
3283 Literate literate(lyxrc->latex_command, name, filepath,
3285 lyxrc->literate_command, lyxrc->literate_error_filter,
3286 lyxrc->build_command, lyxrc->build_error_filter);
3287 int res = literate.build(terr,users->getOwner()->getMiniBuffer());
3289 // check return value from literate.build().
3290 if ((res & Literate::NO_LOGFILE)) {
3291 WriteAlert(_("Build did not work!"),
3292 _("Missing log file:"), name);
3293 } else if ((res & Literate::ERRORS)) {
3294 users->getOwner()->getMiniBuffer()->Set(_("Done"));
3295 // Insert all errors as errors boxes
3298 // Literate files should also be kept dirty if the literate
3299 // command run ends up with errors.
3301 //no errors or any other things to think about so:
3302 users->getOwner()->getMiniBuffer()->Set(_("Done"));
3306 // if we removed error insets before we ran Literate/Build or if we inserted
3307 // error insets after we ran Literate/Build this must be run:
3308 if (a || (res & Literate::ERRORS)){
3311 users->updateScrollbar();
3314 PathPop(); // path to LaTeX file
3316 return literate.getNumErrors();
3320 // This should be enabled when the Chktex class is implemented. (Asger)
3321 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
3322 // Other flags: -wall -v0 -x
3323 int Buffer::runChktex()
3325 if (!text) return 0;
3329 // get LaTeX-Filename
3330 string name = SpaceLess(ChangeExtension (filename, ".tex", true));
3331 string path = OnlyPath(filename);
3333 string org_path = path;
3334 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
3338 PathPush(path); // path to LaTeX file
3339 users->getOwner()->getMiniBuffer()->Set(_("Running chktex..."));
3341 // Remove all error insets
3342 bool a = removeAutoInsets();
3344 // Generate the LaTeX file if neccessary
3345 if (!isDviClean() || a) {
3346 makeLaTeXFile(name, org_path, false);
3351 Chktex chktex(lyxrc->chktex_command, name, filepath);
3352 int res = chktex.run(terr); // run chktex
3355 WriteAlert(_("chktex did not work!"),
3356 _("Could not run with file:"), name);
3357 } else if (res > 0) {
3358 // Insert all errors as errors boxes
3362 // if we removed error insets before we ran chktex or if we inserted
3363 // error insets after we ran chktex, this must be run:
3367 users->updateScrollbar();
3370 PathPop(); // path to LaTeX file
3376 extern void AllFloats(char, char);
3379 void Buffer::insertErrors(TeXErrors &terr)
3381 // Save the cursor position
3382 LyXCursor cursor = text->cursor;
3384 // Now traverse all the errors and insert them
3385 bool firsterror = true;
3388 // This is drastic, but it's the only fix, I could find. (Asger)
3397 more = terr.getFirstError(&errorrow, &errortext);
3400 more = terr.getNextError(&errorrow, &errortext);
3406 // Insert error string for row number
3410 texrow.getIdFromRow(errorrow, tmpid, tmppos);
3412 LyXParagraph* texrowpar;
3415 texrowpar = text->FirstParagraph();
3418 texrowpar = text->GetParFromID(tmpid);
3424 InsetError *new_inset = new InsetError(errortext);
3426 text->SetCursorIntern(texrowpar, tmppos);
3427 text->InsertInset(new_inset);
3428 text->FullRebreak();
3430 // Restore the cursor position
3431 text->SetCursorIntern(cursor.par, cursor.pos);
3435 void Buffer::setCursorFromRow (int row)
3440 texrow.getIdFromRow(row, tmpid, tmppos);
3442 LyXParagraph* texrowpar;
3445 texrowpar = text->FirstParagraph();
3448 texrowpar = text->GetParFromID(tmpid);
3450 text->SetCursor(texrowpar, tmppos);
3454 void Buffer::RoffAsciiTable(FILE *file, LyXParagraph *par)
3457 font1 = LyXFont(LyXFont::ALL_INHERIT),
3472 fname1 = TmpFileName(string(),"RAT1");
3473 fname2 = TmpFileName(string(),"RAT2");
3474 if (!(fp=fopen(fname1.c_str(),"w"))) {
3475 WriteAlert(_("LYX_ERROR:"),
3476 _("Cannot open temporary file:"), fname1);
3479 par->table->RoffEndOfCell(fp, -1);
3480 for (i = 0; i < par->last; i++) {
3481 c = par->GetChar(i);
3482 if (par->table->IsContRow(cell)) {
3483 if (c == LYX_META_NEWLINE)
3487 font2 = par->GetFontSettings(i);
3488 if (font1.latex() != font2.latex()) {
3489 if (font2.latex() != LyXFont::OFF)
3493 case LYX_META_INSET:
3494 if ((inset = par->GetInset(i))) {
3495 if (!(fp2=fopen(fname2.c_str(),"w+"))) {
3496 WriteAlert(_("LYX_ERROR:"),
3497 _("Cannot open temporary file:"), fname2);
3499 remove(fname1.c_str());
3502 inset->Latex(fp2,-1);
3515 case LYX_META_NEWLINE:
3516 if (par->table->CellHasContRow(cell)>=0)
3517 par->RoffContTableRows(fp, i+1,cell);
3518 par->table->RoffEndOfCell(fp, cell);
3521 case LYX_META_HFILL:
3523 case LYX_META_PROTECTED_SEPARATOR:
3526 fprintf(fp, "\\\\");
3530 fprintf(fp, "%c", c);
3532 lyxerr.debug("RoffAsciiTable:"
3533 " NULL char in structure.");
3537 par->table->RoffEndOfCell(fp, cell);
3539 string cmd = lyxrc->ascii_roff_command + " >" + fname2;
3540 subst(cmd, "$$FName",fname1);
3541 Systemcalls one(Systemcalls::System, cmd);
3542 if (!(lyxerr.debugging(Error::ROFF))) {
3543 remove(fname1.c_str());
3545 if (!(fp=fopen(fname2.c_str(),"r"))) {
3546 WriteFSAlert(_("Error! Can't open temporary file:"), fname2);
3549 // now output the produced file
3550 fprintf(file, "\n\n");
3553 WriteAlert(_("Error!"),
3554 _("Error executing *roff command on table"));
3555 // overread leading blank lines
3556 while(!feof(fp) && (c == '\n'))
3559 for(j=0; j<par->depth; j++)
3561 while(!feof(fp) && (c != '\n')) {
3566 // overread trailing blank lines
3567 while(!feof(fp) && (c == '\n'))
3571 remove(fname2.c_str());
3574 /// changed Heinrich Bauer, 23/03/98
3575 bool Buffer::isDviClean()
3577 if (lyxrc->use_tempdir)
3578 return dvi_clean_tmpd;
3580 return dvi_clean_orgd;
3583 /// changed Heinrich Bauer, 23/03/98
3584 void Buffer::markDviClean()
3586 if (lyxrc->use_tempdir)
3587 dvi_clean_tmpd = true;
3589 dvi_clean_orgd = true;
3592 /// changed Heinrich Bauer, 23/03/98
3593 void Buffer::markDviDirty()
3595 if (lyxrc->use_tempdir)
3596 dvi_clean_tmpd = false;
3598 dvi_clean_orgd = false;
3601 void Buffer::update(signed char f)
3605 users->getOwner()->updateLayoutChoice();
3607 if (!text->selection && f > -3)
3608 text->sel_cursor = text->cursor;
3611 text->FullRebreak();
3614 if (f != 3 && f != -3) {
3616 users->updateScrollbar();
3619 if (f==1 || f==-1) {
3622 users->getOwner()->getMiniBuffer()->setTimer(4);
3630 void Buffer::validate(LaTeXFeatures &features)
3632 LyXParagraph *par = paragraph;
3633 LyXTextClass *tclass = lyxstyle.TextClass(params.textclass);
3635 // AMS Style is at document level
3637 features.amsstyle = (params.use_amsmath ||
3638 tclass->provides_amsmath);
3641 // We don't use "lyxerr.debug" because of speed. (Asger)
3642 if (lyxerr.debugging(Error::LATEX))
3643 lyxerr.print(string("Paragraph: ") + tostr(par));
3645 // Now just follow the list of paragraphs and run
3646 // validate on each of them.
3647 par->validate(features);
3649 // and then the next paragraph
3653 // the bullet shapes are buffer level not paragraph level
3654 // so they are tested here
3655 for (int i = 0; i < 4; ++i) {
3656 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
3657 int font = params.user_defined_bullets[i].getFont();
3659 int c = params.user_defined_bullets[i].getCharacter();
3665 features.latexsym = true;
3669 features.amssymb = true;
3671 else if ((font >= 2 && font <=5)) {
3672 features.pifont = true;
3677 if (lyxerr.debugging(Error::LATEX)) {
3678 features.showStruct(params);
3683 void Buffer::setPaperStuff()
3687 params.papersize = PAPER_DEFAULT;
3688 c1 = params.paperpackage;
3689 if (c1 == PACKAGE_NONE) {
3690 c2 = params.papersize2;
3691 if (c2 == VM_PAPER_USLETTER)
3692 params.papersize = PAPER_USLETTER;
3693 else if (c2 == VM_PAPER_USLEGAL)
3694 params.papersize = PAPER_LEGALPAPER;
3695 else if (c2 == VM_PAPER_USEXECUTIVE)
3696 params.papersize = PAPER_EXECUTIVEPAPER;
3697 else if (c2 == VM_PAPER_A3)
3698 params.papersize = PAPER_A3PAPER;
3699 else if (c2 == VM_PAPER_A4)
3700 params.papersize = PAPER_A4PAPER;
3701 else if (c2 == VM_PAPER_A5)
3702 params.papersize = PAPER_A5PAPER;
3703 else if ((c2 == VM_PAPER_B3) || (c2 == VM_PAPER_B4) ||
3704 (c2 == VM_PAPER_B5))
3705 params.papersize = PAPER_B5PAPER;
3706 } else if ((c1 == PACKAGE_A4) || (c1 == PACKAGE_A4WIDE) ||
3707 (c1 == PACKAGE_WIDEMARGINSA4))
3708 params.papersize = PAPER_A4PAPER;
3712 void Buffer::setOldPaperStuff()
3716 c = params.papersize = params.papersize2;
3717 params.papersize2 = VM_PAPER_DEFAULT;
3718 params.paperpackage = PACKAGE_NONE;
3719 if (c == OLD_PAPER_A4PAPER)
3720 params.papersize2 = VM_PAPER_A4;
3721 else if (c == OLD_PAPER_A4)
3722 params.paperpackage = PACKAGE_A4;
3723 else if (c == OLD_PAPER_A4WIDE)
3724 params.paperpackage = PACKAGE_A4WIDE;
3725 else if (c == OLD_PAPER_WIDEMARGINSA4)
3726 params.paperpackage = PACKAGE_WIDEMARGINSA4;
3727 else if (c == OLD_PAPER_USLETTER)
3728 params.papersize2 = VM_PAPER_USLETTER;
3729 else if (c == OLD_PAPER_A5PAPER)
3730 params.papersize2 = VM_PAPER_A5;
3731 else if (c == OLD_PAPER_B5PAPER)
3732 params.papersize2 = VM_PAPER_B5;
3733 else if (c == OLD_PAPER_EXECUTIVEPAPER)
3734 params.papersize2 = VM_PAPER_USEXECUTIVE;
3735 else if (c == OLD_PAPER_LEGALPAPER)
3736 params.papersize2 = VM_PAPER_USLEGAL;
3741 void Buffer::insertInset(Inset *inset, string const &lout,
3744 // check for table/list in tables
3745 if (no_table && text->cursor.par->table){
3746 WriteAlert(_("Impossible Operation!"),
3747 _("Cannot insert table/list in table."),
3751 // not quite sure if we want this...
3752 text->SetCursorParUndo();
3756 if (!lout.empty()) {
3758 text->BreakParagraph();
3761 if (text->cursor.par->Last()) {
3764 text->BreakParagraph();
3768 int lay = lyxstyle.NumberOfLayout(params.textclass, lout);
3769 if (lay == -1) // layout not found
3770 // use default layout "Standard" (0)
3773 text->SetLayout(lay);
3775 text->SetParagraph(0, 0,
3777 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3783 text->current_font.setLatex(LyXFont::OFF);
3786 text->InsertInset(inset);
3789 // Commenting these two lines fixes the problem with new display inset
3790 // inside a paragraph, not sure why. (ale 971117)
3791 // if (inset->Display())
3792 // text->CursorRight();
3794 text->UnFreezeUndo();
3798 // Open and lock an updatable inset
3799 void Buffer::open_new_inset(UpdatableInset* new_inset)
3803 insertInset(new_inset);
3806 new_inset->Edit(0,0);
3810 /* This function should be in Buffer because it's a buffer's property (ale) */
3811 string Buffer::getIncludeonlyList(char delim)
3814 LyXParagraph *par = paragraph;
3819 while ((inset = par->ReturnNextInsetPointer(pos))){
3820 if (inset->LyxCode()==Inset::INCLUDE_CODE) {
3821 InsetInclude *insetinc = (InsetInclude*)inset;
3822 if (insetinc->isInclude()
3823 && insetinc->isNoLoad()) {
3826 list += ChangeExtension(insetinc->getContents(), string(), true);
3833 lyxerr.debug(string("Includeonly(") + list + ')');
3838 /* This is also a buffer property (ale) */
3839 string Buffer::getReferenceList(char delim)
3841 /// if this is a child document and the parent is already loaded
3842 /// Use the parent's list instead [ale990407]
3843 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3844 Buffer *tmp = bufferlist.getBuffer(params.parentname);
3846 return tmp->getReferenceList(delim);
3849 LyXParagraph *par = paragraph;
3855 while ((inset = par->ReturnNextInsetPointer(pos))){
3856 for (int i = 0; i < inset->GetNumberOfLabels(); i++) {
3859 list += inset->getLabel(i);
3865 lyxerr.debug(string("References(") + list + string(")"));
3870 /* This is also a buffer property (ale) */
3871 string Buffer::getBibkeyList(char delim)
3873 /// if this is a child document and the parent is already loaded
3874 /// Use the parent's list instead [ale990412]
3875 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3876 Buffer *tmp = bufferlist.getBuffer(params.parentname);
3878 return tmp->getBibkeyList(delim);
3882 LyXParagraph *par = paragraph;
3885 if (!bibkeys.empty())
3887 bibkeys += par->bibkey->getContents();
3892 // Might be either using bibtex or a child has bibliography
3893 if (bibkeys.empty()) {
3899 // Search for Bibtex or Include inset
3900 while ((inset = par->ReturnNextInsetPointer(pos))) {
3901 if (inset-> LyxCode()==Inset::BIBTEX_CODE) {
3902 if (!bibkeys.empty())
3904 bibkeys += ((InsetBibtex*)inset)->getKeys();
3905 } else if (inset-> LyxCode()==Inset::INCLUDE_CODE) {
3906 string bk = ((InsetInclude*)inset)->getKeys();
3908 if (!bibkeys.empty())
3919 lyxerr.debug(string("Bibkeys(") + bibkeys + string(")"));
3924 /* This is also a buffer property (ale) */
3925 // Not so sure about that. a goto Label function can not be buffer local, just
3926 // think how this will work in a multiwindo/buffer environment, all the
3927 // cursors in all the views showing this buffer will move. (Lgb)
3928 // OK, then no cursor action should be allowed in buffer. (ale)
3929 bool Buffer::gotoLabel(const string &label)
3932 LyXParagraph *par = paragraph;
3938 while ((inset = par->ReturnNextInsetPointer(pos))){
3939 for (int i = 0; i < inset->GetNumberOfLabels(); i++) {
3940 if (label==inset->getLabel(i)) {
3942 text->SetCursor(par, pos);
3943 text->sel_cursor = text->cursor;
3956 bool Buffer::isDepClean(string const & name) const
3958 DEPCLEAN* item = dep_clean;
3959 while (item && item->master != name)
3961 if (!item) return true;
3966 void Buffer::markDepClean(string const & name)
3969 dep_clean = new DEPCLEAN;
3970 dep_clean->clean = true;
3971 dep_clean->master = name;
3972 dep_clean->next = 0;
3974 DEPCLEAN* item = dep_clean;
3975 while (item && item->master != name)
3980 item = new DEPCLEAN;
3982 item->master = name;
3986 //return false; // why use that in a void method??