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"
34 #include "bufferlist.h"
36 #include "lyx_gui_misc.h"
39 #include "tex-strings.h"
42 #include "minibuffer.h"
44 #include "mathed/formulamacro.h"
45 #include "insets/lyxinset.h"
46 #include "insets/inseterror.h"
47 #include "insets/insetlabel.h"
48 #include "insets/insetref.h"
49 #include "insets/inseturl.h"
50 #include "insets/insetinfo.h"
51 #include "insets/insetquotes.h"
53 #include "insets/insetlatex.h"
55 #include "insets/insetlatexaccent.h"
56 #include "insets/insetbib.h"
57 #include "insets/insetindex.h"
58 #include "insets/insetinclude.h"
59 #include "insets/insettoc.h"
60 #include "insets/insetlof.h"
61 #include "insets/insetlot.h"
62 #include "insets/insetloa.h"
63 #include "insets/insetparent.h"
64 #include "insets/insetspecialchar.h"
65 #include "insets/figinset.h"
66 #include "support/filetools.h"
67 #include "support/path.h"
73 #include "LaTeXFeatures.h"
74 #include "support/syscall.h"
75 #include "support/lyxlib.h"
76 #include "support/FileInfo.h"
80 // Uncomment this line to enable a workaround for the weird behaviour
81 // of the cursor between a displayed inset and last character
82 // at the upper line. (Alejandro 20.9.96)
83 // #define BREAK_BEFORE_INSET
85 /* Lars, when changing this file sometime in the future to a list,
86 * please check out the figinsets-sideeffects described at the
87 * beginning of figinset.C Matthias (04.07.1996)
91 // all these externs should eventually be removed.
92 extern BufferList bufferlist;
93 extern void SmallUpdate(signed char);
94 extern unsigned char GetCurrentTextClass();
95 extern void BeforeChange();
97 static const float LYX_FORMAT = 2.15;
99 extern int tex_code_break_column;
101 extern void FreeUpdateTimer();
104 Buffer::Buffer(string const & file, LyXRC * lyxrc, bool ronly)
106 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
108 filepath = OnlyPath(file);
111 the_locking_inset = 0;
114 dvi_clean_orgd = false; // Heinrich Bauer, 23/03/98
115 dvi_clean_tmpd = false; // Heinrich Bauer, 23/03/98
121 if (read_only || (lyxrc && lyxrc->use_tempdir)) {
122 tmppath = CreateBufferTmpDir();
123 } else tmppath.clear();
129 lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
130 // here the buffer should take care that it is
131 // saved properly, before it goes into the void.
133 // make sure that views using this buffer
138 if (!tmppath.empty()) {
139 DestroyBufferTmpDir(tmppath);
142 LyXParagraph * par = paragraph;
143 LyXParagraph * tmppar;
154 bool Buffer::saveParamsAsDefaults()
156 string fname = AddName(AddPath(user_lyxdir, "templates/"),
158 Buffer defaults = Buffer(fname);
160 // Use the current buffer's parameters as default
161 defaults.params = params;
163 // add an empty paragraph. Is this enough?
164 defaults.paragraph = new LyXParagraph;
166 return defaults.writeFile(defaults.filename, false);
170 /// Update window titles of all users
171 // Should work on a list
172 void Buffer::updateTitles()
174 if (users) users->owner()->updateWindowTitle();
178 /// Reset autosave timer of all users
179 // Should work on a list
180 void Buffer::resetAutosaveTimers()
182 if (users) users->owner()->resetAutosaveTimer();
186 void Buffer::setFileName(string const & newfile)
188 filename = MakeAbsPath(newfile);
189 filepath = OnlyPath(filename);
190 setReadonly(IsFileWriteable(filename) == 0);
194 void Buffer::InsetUnlock()
196 if (the_locking_inset) {
197 if (!inset_slept) the_locking_inset->InsetUnlock();
198 the_locking_inset = 0;
205 // Inserts a file into current document
206 bool Buffer::insertLyXFile(string const & filen)
208 // (c) CHT Software Service GmbH
211 // Insert a Lyxformat - file into current buffer
213 // Moved from lyx_cb.C (Lgb)
215 if (filen.empty()) return false;
217 string filename = MakeAbsPath(filen);
219 // check if file exist
220 FileInfo fi(filename);
222 if (!fi.readable()) {
223 WriteAlert(_("Error!"),
224 _("Specified file is unreadable: "),
225 MakeDisplayPath(filename, 50));
231 FilePtr myfile(filename, FilePtr::read);
233 WriteAlert(_("Error!"),
234 _("Cannot open specified file: "),
235 MakeDisplayPath(filename, 50));
240 int c = fgetc(myfile());
246 lyxerr.debug() << "Will insert file with header" << endl;
247 res = readFile(lex, text->cursor.par);
249 lyxerr.debug() << "Will insert file without header" << endl;
250 res = readLyXformat2(lex, text->cursor.par);
259 // changed to be public and have one parameter
260 // if par = 0 normal behavior
261 // else insert behavior
262 // Returns false if "\the_end" is not read for formats >= 2.13. (Asger)
263 bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par)
269 char depth = 0; // signed or unsigned?
270 LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
271 LyXParagraph::footnote_kind footnotekind = LyXParagraph::FOOTNOTE;
272 bool the_end_read = false;
274 LyXParagraph * return_par = 0;
275 LyXFont font = LyXFont(LyXFont::ALL_INHERIT);
277 // If we are inserting, we cheat and get a token in advance
278 bool has_token = false;
282 par = new LyXParagraph;
284 text->BreakParagraph();
285 return_par = text->FirstParagraph();
288 // We don't want to adopt the parameters from the
289 // document we insert, so we skip until the text begins:
292 pretoken = lex.GetString();
293 if (pretoken == "\\layout") {
305 pretoken = lex.GetString();
308 // Profiling show this should give a lot: (Asger)
309 string const token = pretoken;
313 else if (token[0] != '\\') {
314 int n = token.length();
315 for (int i = 0; i < n; i++) {
316 par->InsertChar(pos, token[i]);
317 par->SetFont(pos, font);
320 } else if (token == "\\i") {
321 inset = new InsetLatexAccent;
323 par->InsertChar(pos, LyXParagraph::META_INSET);
325 par->InsertInset(pos, inset);
326 par->SetFont(pos, font);
328 } else if (token == "\\layout") {
332 par->text.resize(par->text.size());
333 par = new LyXParagraph(par);
337 string layoutname = lex.GetString();
338 pair<bool, LyXTextClass::LayoutList::size_type> pp
339 = textclasslist.NumberOfLayout(params.textclass,
342 par->layout = pp.second;
343 } else { // layout not found
344 // use default layout "Standard" (0)
347 // Test whether the layout is obsolete.
348 LyXLayout const & layout = textclasslist.Style(params.textclass,
350 if (!layout.obsoleted_by().empty())
352 textclasslist.NumberOfLayout(params.textclass,
353 layout.obsoleted_by()).second;
354 par->footnoteflag = footnoteflag;
355 par->footnotekind = footnotekind;
357 font = LyXFont(LyXFont::ALL_INHERIT);
358 } else if (token == "\\end_float") {
362 par->text.resize(par->text.size());
363 par = new LyXParagraph(par);
365 footnotekind = LyXParagraph::FOOTNOTE;
366 footnoteflag = LyXParagraph::NO_FOOTNOTE;
369 par->layout = LYX_DUMMY_LAYOUT;
370 font = LyXFont(LyXFont::ALL_INHERIT);
371 } else if (token == "\\begin_float") {
372 tmpret = lex.FindToken(string_footnotekinds);
373 if (tmpret == -1) tmpret++;
374 if (tmpret != LYX_LAYOUT_DEFAULT)
375 footnotekind = (LyXParagraph::footnote_kind)tmpret; // bad
376 if (footnotekind == LyXParagraph::FOOTNOTE
377 || footnotekind == LyXParagraph::MARGIN)
378 footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
380 footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
381 } else if (token == "\\begin_deeper") {
383 } else if (token == "\\end_deeper") {
385 lex.printError("\\end_deeper: "
386 "depth is already null");
390 } else if (token == "\\begin_preamble") {
391 params.readPreamble(lex);
392 } else if (token == "\\textclass") {
394 pair<bool, LyXTextClassList::ClassList::size_type> pp =
395 textclasslist.NumberOfClass(lex.GetString());
397 params.textclass = pp.second;
399 lex.printError("Unknown textclass `$$Token'");
400 params.textclass = 0;
402 if (!textclasslist.Load(params.textclass)) {
403 // if the textclass wasn't loaded properly
404 // we need to either substitute another
405 // or stop loading the file.
406 // I can substitute but I don't see how I can
407 // stop loading... ideas?? ARRae980418
408 WriteAlert(_("Textclass Loading Error!"),
409 string(_("Can't load textclass ")) +
410 textclasslist.NameOfClass(params.textclass),
411 _("-- substituting default"));
412 params.textclass = 0;
414 } else if (token == "\\options") {
416 params.options = lex.GetString();
417 } else if (token == "\\language") {
418 params.readLanguage(lex);
419 } else if (token == "\\fontencoding") {
421 } else if (token == "\\inputencoding") {
423 params.inputenc = lex.GetString();
424 } else if (token == "\\graphics") {
425 params.readGraphicsDriver(lex);
426 } else if (token == "\\fontscheme") {
428 params.fonts = lex.GetString();
429 } else if (token == "\\noindent") {
430 par->noindent = true;
431 } else if (token == "\\fill_top") {
432 par->added_space_top = VSpace(VSpace::VFILL);
433 } else if (token == "\\fill_bottom") {
434 par->added_space_bottom = VSpace(VSpace::VFILL);
435 } else if (token == "\\line_top") {
436 par->line_top = true;
437 } else if (token == "\\line_bottom") {
438 par->line_bottom = true;
439 } else if (token == "\\pagebreak_top") {
440 par->pagebreak_top = true;
441 } else if (token == "\\pagebreak_bottom") {
442 par->pagebreak_bottom = true;
443 } else if (token == "\\start_of_appendix") {
444 par->start_of_appendix = true;
445 } else if (token == "\\paragraph_separation") {
446 tmpret = lex.FindToken(string_paragraph_separation);
447 if (tmpret == -1) tmpret++;
448 if (tmpret != LYX_LAYOUT_DEFAULT)
449 params.paragraph_separation =
450 static_cast<BufferParams::PARSEP>(tmpret);
451 } else if (token == "\\defskip") {
453 params.defskip = VSpace(lex.GetString());
454 } else if (token == "\\no_isolatin1") {
456 } else if (token == "\\no_babel") {
458 } else if (token == "\\no_epsfig") {
460 } else if (token == "\\epsfig") { // obsolete
461 // Indeed it is obsolete, but we HAVE to be backwards
462 // compatible until 0.14, because otherwise all figures
463 // in existing documents are irretrivably lost. (Asger)
464 params.readGraphicsDriver(lex);
465 } else if (token == "\\quotes_language") {
466 tmpret = lex.FindToken(string_quotes_language);
467 if (tmpret == -1) tmpret++;
468 if (tmpret != LYX_LAYOUT_DEFAULT) {
469 InsetQuotes::quote_language tmpl =
470 InsetQuotes::EnglishQ;
473 tmpl = InsetQuotes::EnglishQ;
476 tmpl = InsetQuotes::SwedishQ;
479 tmpl = InsetQuotes::GermanQ;
482 tmpl = InsetQuotes::PolishQ;
485 tmpl = InsetQuotes::FrenchQ;
488 tmpl = InsetQuotes::DanishQ;
491 params.quotes_language = tmpl;
493 } else if (token == "\\quotes_times") {
495 switch(lex.GetInteger()) {
497 params.quotes_times = InsetQuotes::SingleQ;
500 params.quotes_times = InsetQuotes::DoubleQ;
503 } else if (token == "\\papersize") {
507 tmpret = lex.FindToken(string_papersize);
510 tmpret = lex.FindToken(string_oldpapersize);
515 params.papersize2 = tmpret;
516 } else if (token == "\\paperpackage") {
517 tmpret = lex.FindToken(string_paperpackages);
520 params.paperpackage = BufferParams::PACKAGE_NONE;
522 params.paperpackage = tmpret;
523 } else if (token == "\\use_geometry") {
525 params.use_geometry = lex.GetInteger();
526 } else if (token == "\\use_amsmath") {
528 params.use_amsmath = lex.GetInteger();
529 } else if (token == "\\paperorientation") {
530 tmpret = lex.FindToken(string_orientation);
531 if (tmpret == -1) tmpret++;
532 if (tmpret != LYX_LAYOUT_DEFAULT)
533 params.orientation = static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
534 } else if (token == "\\paperwidth") {
536 params.paperwidth = lex.GetString();
537 } else if (token == "\\paperheight") {
539 params.paperheight = lex.GetString();
540 } else if (token == "\\leftmargin") {
542 params.leftmargin = lex.GetString();
543 } else if (token == "\\topmargin") {
545 params.topmargin = lex.GetString();
546 } else if (token == "\\rightmargin") {
548 params.rightmargin = lex.GetString();
549 } else if (token == "\\bottommargin") {
551 params.bottommargin = lex.GetString();
552 } else if (token == "\\headheight") {
554 params.headheight = lex.GetString();
555 } else if (token == "\\headsep") {
557 params.headsep = lex.GetString();
558 } else if (token == "\\footskip") {
560 params.footskip = lex.GetString();
561 } else if (token == "\\paperfontsize") {
563 params.fontsize = strip(lex.GetString());
564 } else if (token == "\\papercolumns") {
566 params.columns = lex.GetInteger();
567 } else if (token == "\\papersides") {
569 switch(lex.GetInteger()) {
571 case 1: params.sides = LyXTextClass::OneSide; break;
572 case 2: params.sides = LyXTextClass::TwoSides; break;
574 } else if (token == "\\paperpagestyle") {
576 params.pagestyle = strip(lex.GetString());
577 } else if (token == "\\bullet") {
579 int index = lex.GetInteger();
581 int temp_int = lex.GetInteger();
582 params.user_defined_bullets[index].setFont(temp_int);
583 params.temp_bullets[index].setFont(temp_int);
585 temp_int = lex.GetInteger();
586 params.user_defined_bullets[index].setCharacter(temp_int);
587 params.temp_bullets[index].setCharacter(temp_int);
589 temp_int = lex.GetInteger();
590 params.user_defined_bullets[index].setSize(temp_int);
591 params.temp_bullets[index].setSize(temp_int);
593 string temp_str = lex.GetString();
594 if (temp_str != "\\end_bullet") {
595 // this element isn't really necessary for
596 // parsing but is easier for humans
597 // to understand bullets. Put it back and
598 // set a debug message?
599 lex.printError("\\end_bullet expected, got" + temp_str);
600 //how can I put it back?
602 } else if (token == "\\bulletLaTeX") {
604 int index = lex.GetInteger();
606 string temp_str = lex.GetString(), sum_str;
607 while (temp_str != "\\end_bullet") {
608 // this loop structure is needed when user
609 // enters an empty string since the first
610 // thing returned will be the \\end_bullet
612 // if the LaTeX entry has spaces. Each element
613 // therefore needs to be read in turn
616 temp_str = lex.GetString();
618 params.user_defined_bullets[index].setText(sum_str);
619 params.temp_bullets[index].setText(sum_str);
620 } else if (token == "\\secnumdepth") {
622 params.secnumdepth = lex.GetInteger();
623 } else if (token == "\\tocdepth") {
625 params.tocdepth = lex.GetInteger();
626 } else if (token == "\\baselinestretch") { // now obsolete
627 lex.nextToken(); // should not be used directly
629 // Will probably keep a kind of support just for
631 params.spacing.set(Spacing::Other, lex.GetFloat());
632 } else if (token == "\\spacing") {
634 string tmp = strip(lex.GetString());
635 if (tmp == "single") {
636 params.spacing.set(Spacing::Single);
637 } else if (tmp == "onehalf") {
638 params.spacing.set(Spacing::Onehalf);
639 } else if (tmp == "double") {
640 params.spacing.set(Spacing::Double);
641 } else if (tmp == "other") {
643 params.spacing.set(Spacing::Other,
646 lex.printError("Unknown spacing token: '$$Token'");
648 } else if (token == "\\float_placement") {
650 params.float_placement = lex.GetString();
651 } else if (token == "\\cursor") {
652 // this is obsolete, so we just skip it.
654 } else if (token == "\\family") {
656 font.setLyXFamily(lex.GetString());
657 } else if (token == "\\series") {
659 font.setLyXSeries(lex.GetString());
660 } else if (token == "\\shape") {
662 font.setLyXShape(lex.GetString());
663 } else if (token == "\\size") {
665 font.setLyXSize(lex.GetString());
666 } else if (token == "\\latex") {
668 string tok = lex.GetString();
669 // This is dirty, but gone with LyX3. (Asger)
670 if (tok == "no_latex")
671 font.setLatex(LyXFont::OFF);
672 else if (tok == "latex")
673 font.setLatex(LyXFont::ON);
674 else if (tok == "default")
675 font.setLatex(LyXFont::INHERIT);
677 lex.printError("Unknown LaTeX font flag "
679 } else if (token == "\\emph") {
681 font.setEmph(font.setLyXMisc(lex.GetString()));
682 } else if (token == "\\bar") {
684 string tok = lex.GetString();
685 // This is dirty, but gone with LyX3. (Asger)
687 font.setUnderbar(LyXFont::ON);
688 else if (tok == "no")
689 font.setUnderbar(LyXFont::OFF);
690 else if (tok == "default")
691 font.setUnderbar(LyXFont::INHERIT);
693 lex.printError("Unknown bar font flag "
695 } else if (token == "\\noun") {
697 font.setNoun(font.setLyXMisc(lex.GetString()));
698 } else if (token == "\\color") {
700 font.setLyXColor(lex.GetString());
701 } else if (token == "\\align") {
702 tmpret = lex.FindToken(string_align);
703 if (tmpret == -1) tmpret++;
704 if (tmpret != LYX_LAYOUT_DEFAULT) {
706 for (; tmpret>0; tmpret--)
707 tmpret2 = tmpret2 * 2;
708 par->align = LyXAlignment(tmpret2);
710 } else if (token == "\\added_space_top"){
712 par->added_space_top = lex.GetString();
713 } else if (token == "\\added_space_bottom") {
715 par->added_space_bottom = lex.GetString();
716 } else if (token == "\\pextra_type") {
718 par->pextra_type = lex.GetInteger();
719 } else if (token == "\\pextra_width") {
721 par->pextra_width = lex.GetString();
722 } else if (token == "\\pextra_widthp") {
724 par->pextra_widthp = lex.GetString();
725 } else if (token == "\\pextra_alignment") {
727 par->pextra_alignment = lex.GetInteger();
728 } else if (token == "\\pextra_hfill") {
730 par->pextra_hfill = lex.GetInteger();
731 } else if (token == "\\pextra_start_minipage") {
733 par->pextra_start_minipage = lex.GetInteger();
734 } else if (token == "\\labelwidthstring") {
736 par->labelwidthstring = lex.GetString();
737 /* do not delete this token, it is still needed! */
738 } else if (token == "\\end_inset") {
739 /* simple ignore this. The insets do not have
741 // but insets should read it, it is a part of
742 //the inset isn't it? Lgb.
743 } else if (token == "\\begin_inset") {
745 tmptok = lex.GetString();
746 /* test the different insets */
747 if (tmptok == "Quotes") {
748 inset = new InsetQuotes;
750 par->InsertChar(pos, LyXParagraph::META_INSET);
751 par->InsertInset(pos, inset);
752 par->SetFont(pos, font);
754 #if 0 // should not be used any more
755 } else if (tmptok == "Latex") {
756 // This one is on its way out
758 tmptok = strip(lex.GetString());
759 //lyxerr <<string(tmptok[0]));
760 if (tmptok[0] == '\\') {
761 // then this latex is a
763 InsetCommand *tmpinset =
765 tmpinset->scanCommand(tmptok);
768 // This should not use InsetLaTexDel
769 // it should rather insert text into
770 // the paragraph and mark it as tex.
771 inset = new InsetLatex(tmptok);
773 par->InsertChar(pos, LyXParagraph::META_INSET);
774 par->InsertInset(pos, inset);
775 par->SetFont(pos, font);
778 #if 0 // should not be used any more
779 } else if (tmptok == "LatexDel") {
780 // This one is on its way out...
782 tmptok = strip(lex.GetString());
783 //lyxerr <<string(tmptok[0]));
784 if (tmptok == "\\tableofcontents") {
785 inset = new InsetTOC(this);
786 } else if (tmptok == "\\listoffigures") {
787 inset = new InsetLOF(this);
788 } else if (tmptok == "\\listoftables") {
789 inset = new InsetLOT(this);
790 } else if (tmptok == "\\listofalgorithms") {
791 inset = new InsetLOA(this);
792 } else if (contains(tmptok, "\\ref{")
793 || contains(tmptok, "\\pageref{")) {
794 inset = new InsetRef(tmptok, this);
795 } else if (contains(tmptok, "\\url{")
796 || contains(tmptok, "\\htmlurl{")) {
797 string cont, opt, tmptmptok, cmdname;
799 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
804 tmptmptok = lex.GetString();
805 if(tmptmptok[0] == '\\') {
806 if( tmptmptok == "\\backslash")
816 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
821 tmptmptok = lex.GetString();
822 if(tmptmptok[0] == '\\') {
823 if( tmptmptok == "\\backslash")
833 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
836 if(contains(tmptok, "\\url{"))
837 cmdname = string("url");
839 cmdname = string("htmlurl");
842 inset = new InsetUrl(cmdname, cont, opt);
843 } else if (tmptok[0] == '\\') {
844 // then this latex del is a
846 InsetCommand * tmpinset =
848 tmpinset->scanCommand(tmptok);
851 par->InsertChar(pos, LyXParagraph::META_INSET);
852 par->InsertInset(pos, inset);
853 par->SetFont(pos, font);
856 } else if (tmptok == "\\i") {
857 inset = new InsetLatexAccent;
859 par->InsertChar(pos, LyXParagraph::META_INSET);
860 par->InsertInset(pos, inset);
861 par->SetFont(pos, font);
863 } else if (tmptok == "FormulaMacro") {
864 inset = new InsetFormulaMacro;
866 par->InsertChar(pos, LyXParagraph::META_INSET);
867 par->InsertInset(pos, inset);
868 par->SetFont(pos, font);
870 } else if (tmptok == "Formula") {
871 inset = new InsetFormula;
873 par->InsertChar(pos, LyXParagraph::META_INSET);
874 par->InsertInset(pos, inset);
875 par->SetFont(pos, font);
877 } else if (tmptok == "Figure") {
878 inset = new InsetFig(100, 100, this);
880 par->InsertChar(pos, LyXParagraph::META_INSET);
881 par->InsertInset(pos, inset);
882 par->SetFont(pos, font);
884 } else if (tmptok == "Label") {
885 // Kept for compability. Remove in 0.13.
887 string tmp = "\\label{";
888 tmp += lex.GetString();
890 inset = new InsetLabel(tmp);
891 par->InsertChar(pos, LyXParagraph::META_INSET);
892 par->InsertInset(pos, inset);
893 par->SetFont(pos, font);
896 } else if (tmptok == "Info") {
897 inset = new InsetInfo;
899 par->InsertChar(pos, LyXParagraph::META_INSET);
900 par->InsertInset(pos, inset);
901 par->SetFont(pos, font);
903 } else if (tmptok == "Include") {
904 inset = new InsetInclude(string(), this);
906 par->InsertChar(pos, LyXParagraph::META_INSET);
907 par->InsertInset(pos, inset);
908 par->SetFont(pos, font);
910 } else if (tmptok == "LatexCommand") {
913 if (inscmd.getCmdName() == "cite") {
914 inset = new InsetCitation(inscmd.getContents(), inscmd.getOptions());
915 } else if (inscmd.getCmdName() == "bibitem") {
916 lex.printError("Wrong place for bibitem");
917 inset = inscmd.Clone();
918 } else if (inscmd.getCmdName() == "BibTeX") {
919 inset = new InsetBibtex(inscmd.getContents(), inscmd.getOptions(), this);
920 } else if (inscmd.getCmdName() == "index") {
921 inset = new InsetIndex(inscmd.getContents());
922 } else if (inscmd.getCmdName() == "include") {
923 inset = new InsetInclude(inscmd.getContents(), this);
924 } else if (inscmd.getCmdName() == "label") {
925 inset = new InsetLabel(inscmd.getCommand());
926 } else if (inscmd.getCmdName() == "url"
927 || inscmd.getCmdName() == "htmlurl") {
928 inset = new InsetUrl(inscmd.getCommand());
929 } else if (inscmd.getCmdName() == "ref"
930 || inscmd.getCmdName() == "pageref") {
931 if (!inscmd.getOptions().empty() || !inscmd.getContents().empty()) {
932 inset = new InsetRef(inscmd, this);
934 /* This condition comes from a temporary solution
935 to the latexdel ref inset that was transformed to an empty ref
936 inset plus the body surronded by latexdel insets */
938 string cont, opt, tmptmptok, cmdname;
940 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
945 tmptmptok = lex.GetString();
946 if(tmptmptok[0] == '\\') {
947 if( tmptmptok == "\\backslash")
957 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
962 tmptmptok = lex.GetString();
963 if(tmptmptok[0] == '\\') {
964 if( tmptmptok == "\\backslash")
974 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
980 cmdname = "\\" + inscmd.getCmdName();
981 cmdname += "[" + cont + "]";
982 cmdname += "{" + opt + "}";
983 inset = new InsetRef(cmdname, this);
985 } else if (inscmd.getCmdName() == "tableofcontents") {
986 inset = new InsetTOC(this);
987 } else if (inscmd.getCmdName() == "listoffigures") {
988 inset = new InsetLOF(this);
989 } else if (inscmd.getCmdName() == "listofalgorithms") {
990 inset = new InsetLOA(this);
991 } else if (inscmd.getCmdName() == "listoftables") {
992 inset = new InsetLOT(this);
993 } else if (inscmd.getCmdName() == "printindex") {
994 inset = new InsetPrintIndex(this);
995 } else if (inscmd.getCmdName() == "lyxparent") {
996 inset = new InsetParent(inscmd.getContents(), this);
998 // The following three are only for compatibility
999 if (inscmd.getCmdName() == "-") {
1000 inset = new InsetSpecialChar(InsetSpecialChar::HYPHENATION);
1001 } else if (inscmd.getCmdName() == "@.") {
1002 inset = new InsetSpecialChar(InsetSpecialChar::END_OF_SENTENCE);
1003 } else if (inscmd.getCmdName() == "ldots") {
1004 inset = new InsetSpecialChar(InsetSpecialChar::LDOTS);
1006 inset = inscmd.Clone();
1009 par->InsertChar(pos, LyXParagraph::META_INSET);
1010 par->InsertInset(pos, inset);
1011 par->SetFont(pos, font);
1015 } else if (token == "\\InsetQuotes") {
1016 inset = new InsetQuotes;
1018 par->InsertChar(pos, LyXParagraph::META_INSET);
1019 par->InsertInset(pos, inset);
1020 par->SetFont(pos, font);
1023 } else if (token == "\\InsetLatex") {
1024 inset = new InsetLatex;
1026 par->InsertChar(pos, LyXParagraph::META_INSET);
1027 par->InsertInset(pos, inset);
1028 par->SetFont(pos, font);
1030 } else if (token == "\\InsetLatexDel") {
1031 lex.printError(_("Warning: Ignoring Old Inset"));
1033 } else if (token == "\\InsetFormula") {
1034 inset = new InsetFormula;
1036 par->InsertChar(pos, LyXParagraph::META_INSET);
1037 par->InsertInset(pos, inset);
1038 par->SetFont(pos, font);
1040 } else if (token == "\\SpecialChar") {
1041 inset = new InsetSpecialChar;
1043 par->InsertChar(pos, LyXParagraph::META_INSET);
1044 par->InsertInset(pos, inset);
1045 par->SetFont(pos, font);
1047 } else if (token == "\\Figure") {
1048 inset = new InsetFig(100, 100, this);
1050 par->InsertChar(pos, LyXParagraph::META_INSET);
1051 par->InsertInset(pos, inset);
1052 par->SetFont(pos, font);
1054 } else if (token == "\\newline") {
1055 par->InsertChar(pos, LyXParagraph::META_NEWLINE);
1056 par->SetFont(pos, font);
1058 } else if (token == "\\LyXTable") {
1059 par->table = new LyXTable(lex);
1060 } else if (token == "\\hfill") {
1061 par->InsertChar(pos, LyXParagraph::META_HFILL);
1062 par->SetFont(pos, font);
1064 } else if (token == "\\protected_separator") {
1065 par->InsertChar(pos, LyXParagraph::META_PROTECTED_SEPARATOR);
1066 par->SetFont(pos, font);
1068 } else if (token == "\\bibitem") { // ale970302
1070 par->bibkey = new InsetBibKey;
1071 par->bibkey->Read(lex);
1072 }else if (token == "\\backslash") {
1073 par->InsertChar(pos, '\\');
1074 par->SetFont(pos, font);
1076 }else if (token == "\\the_end") {
1077 the_end_read = true;
1079 // This should be insurance for the future: (Asger)
1080 lex.printError("Unknown token `$$Token'. "
1081 "Inserting as text.");
1082 int n = token.length();
1083 for (int i = 0; i < n; i++) {
1084 par->InsertChar(pos, token[i]);
1085 par->SetFont(pos, font);
1094 paragraph = return_par;
1096 return the_end_read;
1100 bool Buffer::readFile(LyXLex & lex, LyXParagraph * par)
1106 token = lex.GetString();
1107 if (token == "\\lyxformat") { // the first token _must_ be...
1109 format = lex.GetFloat();
1111 if (LYX_FORMAT - format > 0.05) {
1112 printf(_("Warning: need lyxformat %.2f but found %.2f\n"),
1113 LYX_FORMAT, format);
1115 if (format - LYX_FORMAT > 0.05) {
1116 printf(_("ERROR: need lyxformat %.2f but found %.2f\n"),
1117 LYX_FORMAT, format);
1119 bool the_end = readLyXformat2(lex, par);
1120 // Formats >= 2.13 support "\the_end" marker
1124 // Formats >= 2.14 changed papersize stuff
1125 if (format < 2.14) {
1134 WriteAlert(_("Warning!"),
1135 _("Reading of document is not complete"),
1136 _("Maybe the document is truncated"));
1137 // We simulate a safe reading anyways to allow
1138 // users to take the chance... (Asger)
1142 WriteAlert(_("ERROR!"),
1143 _("Old LyX file format found. "
1144 "Use LyX 0.10.x to read this!"));
1148 } else { // "\\lyxformat" not found
1149 WriteAlert(_("ERROR!"), _("Not a LyX file!"));
1152 WriteAlert(_("ERROR!"), _("Unable to read file!"));
1157 // Returns false if unsuccesful
1158 bool Buffer::writeFile(string const & filename, bool flag)
1160 // if flag is false writeFile will not create any GUI
1161 // warnings, only cerr.
1162 // Needed for autosave in background or panic save (Matthias 120496)
1164 if (read_only && (filename == this->filename)) {
1165 // Here we should come with a question if we should
1166 // perform the write anyway.
1168 lyxerr << _("Error! Document is read-only: ")
1169 << filename << endl;
1171 WriteAlert(_("Error! Document is read-only: "),
1176 FileInfo finfo(filename);
1177 if (finfo.exist() && !finfo.writable()) {
1178 // Here we should come with a question if we should
1179 // try to do the save anyway. (i.e. do a chmod first)
1181 lyxerr << _("Error! Cannot write file: ")
1182 << filename << endl;
1184 WriteFSAlert(_("Error! Cannot write file: "),
1189 FilePtr file(filename, FilePtr::truncate);
1192 lyxerr << _("Error! Cannot write file: ")
1193 << filename << endl;
1195 WriteFSAlert(_("Error! Cannot write file: "),
1199 // The top of the file should not be written by params.
1200 // collect some very important information
1201 string userName(getUserName()) ;
1203 // write out a comment in the top of the file
1205 "#LyX 1.1 Copyright 1995-1999 Matthias Ettrich"
1206 " and the LyX Team\n");
1208 // at the very beginning the used lyx format
1209 fprintf(file, "\\lyxformat %.2f\n", LYX_FORMAT);
1211 // now write out the buffer parameters.
1212 params.writeFile(file);
1214 char footnoteflag = 0;
1217 // this will write out all the paragraphs
1218 // using recursive descent.
1219 paragraph->writeFile(file, params, footnoteflag, depth);
1221 // Write marker that shows file is complete
1222 fprintf(file, "\n\\the_end\n");
1225 lyxerr << _("Error! Could not close file properly: ")
1226 << filename << endl;
1228 WriteFSAlert(_("Error! Could not close file properly: "),
1236 void Buffer::writeFileAscii(string const & filename, int linelen)
1238 FilePtr file(filename, FilePtr::write);
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;
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)
1271 fprintf(file, "\n");
1272 fprintf(file, "([%s] ",
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;
1335 fprintf(file, ") ");
1339 /* It might be a table */
1341 if (!lyxrc->ascii_roff_command.empty() &&
1342 lyxrc->ascii_roff_command != "none") {
1343 RoffAsciiTable(file, 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))) {
1359 WriteFSAlert(_("Error: Cannot open temporary file:"), fname1);
1362 inset->Latex(fp,-1);
1364 remove(fname1.c_str());
1366 } else if (c == LyXParagraph::META_NEWLINE) {
1370 j = (++j) % par->table->NumberOfCellsInRow(actcell);
1378 font1 = LyXFont(LyXFont::ALL_INHERIT);
1380 for (i = 0, actpos = 1; i < par->size(); ++i, ++actpos) {
1381 if (!i && !footnoteflag && !noparbreak){
1382 fprintf(file, "\n\n");
1383 for(j = 0; j<depth; j++)
1385 currlinelen = depth*2;
1387 case 0: /* Standart */
1388 case 4: /* (Sub)Paragraph */
1389 case 5: /* Description */
1391 case 6: /* Abstract */
1392 fprintf(file, "Abstract\n\n");
1394 case 7: /* Bibliography */
1396 fprintf(file, "References\n\n");
1401 fprintf(file, "%s ", par->labelstring.c_str());
1404 if (ltype_depth > depth) {
1405 for(j = ltype_depth-1; j>depth; j--)
1407 currlinelen += (ltype_depth-depth)*2;
1410 for(j = 0;j<cells;j++) {
1412 for(h = 0; h<(clen[j]+1); h++)
1415 fprintf(file, "+\n");
1416 for(j = 0; j<depth; j++)
1418 currlinelen = depth*2;
1419 if (ltype_depth > depth) {
1420 for(j = ltype_depth; j>depth; j--)
1422 currlinelen += (ltype_depth-depth)*2;
1424 fprintf(file, "| ");
1427 font2 = par->GetFontSettings(i);
1428 if (font1.latex() != font2.latex()) {
1429 if (font2.latex() == LyXFont::OFF)
1437 c = par->GetChar(i);
1441 case LyXParagraph::META_INSET:
1442 if ((inset = par->GetInset(i))) {
1444 inset->Latex(file,-1);
1445 currlinelen += (ftell(file) - fpos);
1446 actpos += (ftell(file) - fpos) - 1;
1449 case LyXParagraph::META_NEWLINE:
1451 if (par->table->NumberOfCellsInRow(actcell) <= cell) {
1452 for(j = actpos;j<clen[cell-1];j++)
1454 fprintf(file, " |\n");
1455 for(j = 0; j<depth; j++)
1457 currlinelen = depth*2;
1458 if (ltype_depth > depth) {
1459 for(j = ltype_depth; j>depth; j--)
1461 currlinelen += (ltype_depth-depth)*2;
1463 for(j = 0;j<cells;j++) {
1465 for(h = 0; h<(clen[j]+1); h++)
1468 fprintf(file, "+\n");
1469 for(j = 0; j<depth; j++)
1471 currlinelen = depth*2;
1472 if (ltype_depth > depth) {
1473 for(j = ltype_depth; j>depth; j--)
1475 currlinelen += (ltype_depth-depth)*2;
1477 fprintf(file, "| ");
1480 for(j = actpos; j<clen[cell-1]; j++)
1482 fprintf(file, " | ");
1486 currlinelen = actpos = 0;
1488 fprintf(file, "\n");
1489 for(j = 0; j<depth; j++)
1491 currlinelen = depth*2;
1492 if (ltype_depth > depth) {
1493 for(j = ltype_depth; j>depth; j--)
1495 currlinelen += (ltype_depth-depth)*2;
1499 case LyXParagraph::META_HFILL:
1500 fprintf(file, "\t");
1502 case LyXParagraph::META_PROTECTED_SEPARATOR:
1506 fprintf(file, "\\");
1509 if (currlinelen > linelen - 10
1510 && c == ' ' && i + 2 < par->size()) {
1511 fprintf(file, "\n");
1512 for(j = 0; j < depth; ++j)
1514 currlinelen = depth * 2;
1515 if (ltype_depth > depth) {
1516 for(j = ltype_depth;
1519 currlinelen += (ltype_depth-depth)*2;
1521 } else if (c != '\0')
1522 fprintf(file, "%c", c);
1524 lyxerr.debug() << "writeAsciiFile: NULL char in structure." << endl;
1530 for(j = actpos;j<clen[cell-1];j++)
1532 fprintf(file, " |\n");
1533 for(j = 0; j<depth; j++)
1535 currlinelen = depth*2;
1536 if (ltype_depth > depth) {
1537 for(j = ltype_depth; j>depth; j--)
1539 currlinelen += (ltype_depth-depth)*2;
1541 for(j = 0;j<cells;j++) {
1543 for(h = 0; h<(clen[j]+1); h++)
1546 fprintf(file, "+\n");
1552 fprintf(file, "\n");
1556 void Buffer::makeLaTeXFile(string const & filename,
1557 string const & original_path,
1558 bool nice, bool only_body)
1560 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
1561 params.textclass = GetCurrentTextClass();
1562 niceFile = nice; // this will be used by Insetincludes.
1564 tex_code_break_column = lyxrc->ascii_linelen;
1566 LyXTextClass const & tclass =
1567 textclasslist.TextClass(params.textclass);
1569 FilePtr file(filename, FilePtr::write);
1571 WriteFSAlert(_("Error: Cannot write file:"), filename);
1575 // validate the buffer.
1576 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
1577 LaTeXFeatures features(tclass.numLayouts());
1579 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
1582 // The starting paragraph of the coming rows is the
1583 // first paragraph of the document. (Asger)
1584 texrow.start(paragraph, 0);
1586 string userName(getUserName());
1589 if (!only_body && nice) {
1590 LFile += "%% This LaTeX-file was created by <";
1591 LFile += userName + "> " + (char*)date();
1592 LFile += "%% LyX 1.0 (C) 1995-1999 by Matthias Ettrich and the LyX Team\n";
1593 LFile += "\n%% Do not edit this file unless you know what you are doing.\n";
1599 lyxerr.debug() << "lyx header finished" << endl;
1600 // There are a few differences between nice LaTeX and usual files:
1601 // usual is \batchmode, uses \listfiles and has a
1602 // special input@path to allow the including of figures
1603 // with either \input or \includegraphics (what figinsets do).
1604 // batchmode is not set if there is a tex_code_break_column.
1605 // In this case somebody is interested in the generated LaTeX,
1606 // so this is OK. input@path is set when the actual parameter
1607 // original_path is set. This is done for usual tex-file, but not
1608 // for nice-latex-file. (Matthias 250696)
1611 // code for usual, NOT nice-latex-file
1612 LFile += "\\batchmode\n"; // changed
1613 // from \nonstopmode
1615 // We don't need listfiles anymore
1616 //LFile += "\\listfiles\n";
1619 if (!original_path.empty()) {
1620 LFile += "\\makeatletter\n";
1622 LFile += "\\def\\input@path{{" + original_path
1625 LFile += "\\makeatother\n";
1629 LFile += "\\documentclass";
1631 string options; // the document class options.
1633 if (tokenPos(tclass.opt_fontsize(), '|', params.fontsize) >= 0) {
1634 // only write if existing in list (and not default)
1635 options += params.fontsize;
1640 if (!params.use_geometry &&
1641 (params.paperpackage == BufferParams::PACKAGE_NONE)) {
1642 switch (params.papersize) {
1643 case BufferParams::PAPER_A4PAPER:
1644 options += "a4paper,";
1646 case BufferParams::PAPER_USLETTER:
1647 options += "letterpaper,";
1649 case BufferParams::PAPER_A5PAPER:
1650 options += "a5paper,";
1652 case BufferParams::PAPER_B5PAPER:
1653 options += "b5paper,";
1655 case BufferParams::PAPER_EXECUTIVEPAPER:
1656 options += "executivepaper,";
1658 case BufferParams::PAPER_LEGALPAPER:
1659 options += "legalpaper,";
1665 if (params.sides != tclass.sides()) {
1666 if (params.sides == 2)
1667 options += "twoside,";
1669 options += "oneside,";
1673 if (params.columns != tclass.columns()) {
1674 if (params.columns == 2)
1675 options += "twocolumn,";
1677 options += "onecolumn,";
1680 if (!params.use_geometry && params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1681 options += "landscape,";
1683 // language should be a parameter to \documentclass
1684 if (params.language != "default") {
1685 options += params.language + ',';
1688 // the user-defined options
1689 if (!params.options.empty()) {
1690 options += params.options + ',';
1693 if (!options.empty()){
1694 options = strip(options, ',');
1701 LFile += textclasslist.LatexnameOfClass(params.textclass);
1704 // end of \documentclass defs
1706 // font selection must be done before loading fontenc.sty
1707 if (params.fonts != "default") {
1708 LFile += "\\usepackage{" + params.fonts + "}\n";
1711 // this one is not per buffer
1712 if (lyxrc->fontenc != "default") {
1713 LFile += "\\usepackage[" + lyxrc->fontenc
1717 if (params.inputenc != "default") {
1718 LFile += "\\usepackage[" + params.inputenc
1723 /* at the very beginning the text parameters */
1724 if (params.paperpackage != BufferParams::PACKAGE_NONE) {
1725 switch (params.paperpackage) {
1726 case BufferParams::PACKAGE_A4:
1727 LFile += "\\usepackage{a4}\n";
1730 case BufferParams::PACKAGE_A4WIDE:
1731 LFile += "\\usepackage{a4wide}\n";
1734 case BufferParams::PACKAGE_WIDEMARGINSA4:
1735 LFile += "\\usepackage[widemargins]{a4}\n";
1740 if (params.use_geometry) {
1741 LFile += "\\usepackage{geometry}\n";
1743 LFile += "\\geometry{verbose";
1744 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1745 LFile += ",landscape";
1746 switch (params.papersize2) {
1747 case BufferParams::VM_PAPER_CUSTOM:
1748 if (!params.paperwidth.empty())
1749 LFile += ",paperwidth="
1750 + params.paperwidth;
1751 if (!params.paperheight.empty())
1752 LFile += ",paperheight="
1753 + params.paperheight;
1755 case BufferParams::VM_PAPER_USLETTER:
1756 LFile += ",letterpaper";
1758 case BufferParams::VM_PAPER_USLEGAL:
1759 LFile += ",legalpaper";
1761 case BufferParams::VM_PAPER_USEXECUTIVE:
1762 LFile += ",executivepaper";
1764 case BufferParams::VM_PAPER_A3:
1765 LFile += ",a3paper";
1767 case BufferParams::VM_PAPER_A4:
1768 LFile += ",a4paper";
1770 case BufferParams::VM_PAPER_A5:
1771 LFile += ",a5paper";
1773 case BufferParams::VM_PAPER_B3:
1774 LFile += ",b3paper";
1776 case BufferParams::VM_PAPER_B4:
1777 LFile += ",b4paper";
1779 case BufferParams::VM_PAPER_B5:
1780 LFile += ",b5paper";
1783 // default papersize ie BufferParams::VM_PAPER_DEFAULT
1784 switch (lyxrc->default_papersize) {
1785 case BufferParams::PAPER_DEFAULT: // keep compiler happy
1786 case BufferParams::PAPER_USLETTER:
1787 LFile += ",letterpaper";
1789 case BufferParams::PAPER_LEGALPAPER:
1790 LFile += ",legalpaper";
1792 case BufferParams::PAPER_EXECUTIVEPAPER:
1793 LFile += ",executivepaper";
1795 case BufferParams::PAPER_A3PAPER:
1796 LFile += ",a3paper";
1798 case BufferParams::PAPER_A4PAPER:
1799 LFile += ",a4paper";
1801 case BufferParams::PAPER_A5PAPER:
1802 LFile += ",a5paper";
1804 case BufferParams::PAPER_B5PAPER:
1805 LFile += ",b5paper";
1809 if (!params.topmargin.empty())
1810 LFile += ",tmargin=" + params.topmargin;
1811 if (!params.bottommargin.empty())
1812 LFile += ",bmargin=" + params.bottommargin;
1813 if (!params.leftmargin.empty())
1814 LFile += ",lmargin=" + params.leftmargin;
1815 if (!params.rightmargin.empty())
1816 LFile += ",rmargin=" + params.rightmargin;
1817 if (!params.headheight.empty())
1818 LFile += ",headheight=" + params.headheight;
1819 if (!params.headsep.empty())
1820 LFile += ",headsep=" + params.headsep;
1821 if (!params.footskip.empty())
1822 LFile += ",footskip=" + params.footskip;
1826 if (params.use_amsmath
1827 && !prefixIs(textclasslist.LatexnameOfClass(params.textclass), "ams")) {
1828 LFile += "\\usepackage{amsmath}\n";
1831 if (tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle) >= 0) {
1832 if (params.pagestyle == "fancy") {
1833 LFile += "\\usepackage{fancyhdr}\n";
1836 LFile += "\\pagestyle{" + params.pagestyle + "}\n";
1840 // We try to load babel late, in case it interferes
1841 // with other packages.
1842 if (params.language != "default") {
1843 LFile += "\\usepackage{babel}\n";
1847 if (params.secnumdepth != tclass.secnumdepth()) {
1848 LFile += "\\setcounter{secnumdepth}{";
1849 LFile += tostr(params.secnumdepth);
1853 if (params.tocdepth != tclass.tocdepth()) {
1854 LFile += "\\setcounter{tocdepth}{";
1855 LFile += tostr(params.tocdepth);
1860 if (params.paragraph_separation) {
1861 switch (params.defskip.kind()) {
1862 case VSpace::SMALLSKIP:
1863 LFile += "\\setlength\\parskip{\\smallskipamount}\n";
1865 case VSpace::MEDSKIP:
1866 LFile += "\\setlength\\parskip{\\medskipamount}\n";
1868 case VSpace::BIGSKIP:
1869 LFile += "\\setlength\\parskip{\\bigskipamount}\n";
1871 case VSpace::LENGTH:
1872 LFile += "\\setlength\\parskip{"
1873 + params.defskip.length().asLatexString()
1876 default: // should never happen // Then delete it.
1877 LFile += "\\setlength\\parskip{\\medskipamount}\n";
1882 LFile += "\\setlength\\parindent{0pt}\n";
1886 // Write out what we've generated so far...and reset LFile
1887 fwrite(LFile.c_str(), sizeof(char), LFile.length(), file);
1890 // Now insert the LyX specific LaTeX commands...
1891 string preamble, tmppreamble;
1893 // The optional packages;
1894 preamble = features.getPackages(params);
1896 // this might be useful...
1897 preamble += "\n\\makeatletter\n\n";
1899 // Some macros LyX will need
1900 tmppreamble = features.getMacros(params);
1902 if (!tmppreamble.empty()) {
1903 preamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1904 "LyX specific LaTeX commands.\n"
1905 + tmppreamble + '\n';
1908 // the text class specific preamble
1909 tmppreamble = features.getTClassPreamble(params);
1910 if (!tmppreamble.empty()) {
1911 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1912 "Textclass specific LaTeX commands.\n"
1913 + tmppreamble + '\n';
1916 /* the user-defined preamble */
1917 if (!params.preamble.empty()) {
1918 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1919 "User specified LaTeX commands.\n"
1920 + params.preamble + '\n';
1923 preamble += "\\makeatother\n\n";
1925 // Itemize bullet settings need to be last in case the user
1926 // defines their own bullets that use a package included
1927 // in the user-defined preamble -- ARRae
1928 // Actually it has to be done much later than that
1929 // since some packages like frenchb make modifications
1930 // at \begin{document} time -- JMarc
1932 for (int i = 0; i < 4; ++i) {
1933 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
1934 if (bullets_def.empty())
1935 bullets_def="\\AtBeginDocument{\n";
1936 bullets_def += " \\renewcommand{\\labelitemi";
1938 // `i' is one less than the item to modify
1945 bullets_def += "ii";
1951 bullets_def += "}{" +
1952 params.user_defined_bullets[i].getText()
1957 if (!bullets_def.empty())
1958 preamble += bullets_def + "}\n\n";
1960 for (int j = countChar(preamble, '\n'); j-- ;) {
1964 // A bit faster than printing a char at a time I think.
1965 fwrite(preamble.c_str(), sizeof(char),
1966 preamble.length(), file);
1969 LFile += "\\begin{document}\n\n";
1973 lyxerr.debug() << "preamble finished, now the body." << endl;
1975 bool was_title = false;
1976 bool already_title = false;
1982 LyXParagraph * par = paragraph;
1988 lyxerr[Debug::LATEX] << "Error in MakeLateXFile."
1990 LyXLayout const & layout = textclasslist.Style(params.textclass,
1993 if (layout.intitle) {
1994 if (already_title) {
1995 lyxerr <<"Error in MakeLatexFile: You"
1996 " should not mix title layouts"
1997 " with normal ones." << endl;
2000 } else if (was_title && !already_title) {
2001 LFile += "\\maketitle\n";
2003 already_title = true;
2006 // We are at depth 0 so we can just use
2007 // ordinary \footnote{} generation
2008 // flag this with ftcount
2010 if (layout.isEnvironment()
2011 || par->pextra_type != LyXParagraph::PEXTRA_NONE) {
2012 par = par->TeXEnvironment(LFile, texrow,
2013 ftnote, ft_texrow, ftcount);
2015 par = par->TeXOnePar(LFile, texrow,
2016 ftnote, ft_texrow, ftcount);
2019 // Write out what we've generated...and reset LFile
2022 LFile += "\\addtocounter{footnote}{-";
2023 LFile += tostr(ftcount - 1);
2027 texrow += ft_texrow;
2032 if (loop_count == 2) {
2033 // fwrite()ing every second time through the loop
2034 // gains a few extra % of speed; going higher than
2035 // 2 will slow things down again. I'll look at
2036 // LFile.length() in a future revision. ARRae
2037 fwrite(LFile.c_str(), sizeof(char),
2038 LFile.length(), file);
2044 // It might be that we only have a title in this document
2045 if (was_title && !already_title) {
2046 LFile += "\\maketitle\n";
2051 LFile += "\\end{document}\n";
2054 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
2056 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
2060 // Just to be sure. (Asger)
2063 // Write out what we've generated...and reset LFile
2064 fwrite(LFile.c_str(), sizeof(char), LFile.length(), file);
2067 // tex_code_break_column's value is used to decide
2068 // if we are in batchmode or not (within mathed_write()
2069 // in math_write.C) so we must set it to a non-zero
2070 // value when we leave otherwise we save incorrect .lyx files.
2071 tex_code_break_column = lyxrc->ascii_linelen;
2074 WriteFSAlert(_("Error! Could not close file properly:"), filename);
2076 lyxerr.debug() << "Finished making latex file." << endl;
2080 bool Buffer::isLatex() const
2082 return textclasslist.TextClass(params.textclass).outputType() == LATEX;
2086 bool Buffer::isLinuxDoc() const
2088 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC;
2092 bool Buffer::isLiterate() const
2094 return textclasslist.TextClass(params.textclass).outputType() == LITERATE;
2098 bool Buffer::isDocBook() const
2100 return textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2104 bool Buffer::isSGML() const
2106 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC ||
2107 textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2111 void Buffer::sgmlOpenTag(FILE * file, int depth, string const & latexname) const
2113 static char * space[] = {" "," ", " ", " ", " ", " ", " ",
2114 " ", " ", " ", " "};
2116 fprintf(file, "%s<%s>\n", space[depth], latexname.c_str());
2120 void Buffer::sgmlCloseTag(FILE * file, int depth,
2121 string const & latexname) const
2123 static char * space[] = {" ", " ", " ", " ", " ", " ", " ",
2124 " ", " ", " ", " "};
2126 fprintf(file, "%s</%s>\n", space[depth], latexname.c_str());
2130 void Buffer::makeLinuxDocFile(string const & filename, int column)
2132 LyXParagraph * par = paragraph;
2134 string top_element = textclasslist.LatexnameOfClass(params.textclass);
2135 string environment_stack[10];
2138 int depth = 0; /* paragraph depth */
2140 FilePtr file(filename, FilePtr::write);
2141 tex_code_break_column = column;
2144 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), filename);
2150 if (params.preamble.empty()) {
2151 fprintf(file, "<!doctype linuxdoc system>\n\n");
2154 fprintf(file, "<!doctype linuxdoc system \n [ %s \n]>\n\n",
2155 params.preamble.c_str() );
2158 string userName(getUserName());
2160 "<!-- LinuxDoc file was created by LyX 1.0 (C) 1995-1999 ");
2161 fprintf(file, "by <%s> %s -->\n", userName.c_str(), (char *)date());
2163 if(params.options.empty())
2164 sgmlOpenTag(file, 0, top_element);
2166 string top = top_element;
2168 top += params.options;
2169 sgmlOpenTag(file, 0, top);
2173 int desc_on = 0; /* description mode*/
2174 LyXLayout const & style =
2175 textclasslist.Style(GetCurrentTextClass(),
2177 par->AutoDeleteInsets();
2179 /* treat <toc> as a special case for compatibility with old code */
2180 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2181 Inset *inset = par->GetInset(0);
2182 char lyx_code = inset->LyxCode();
2183 if (lyx_code == Inset::TOC_CODE){
2184 string temp = "toc";
2185 sgmlOpenTag(file, depth, temp);
2188 linuxDocHandleFootnote(file, par, depth);
2193 /* environment tag closing */
2194 for( ;depth > par->depth; depth--) {
2195 sgmlCloseTag(file, depth, environment_stack[depth]);
2196 environment_stack[depth].clear();
2199 /* write opening SGML tags */
2200 switch(style.latextype) {
2201 case LATEX_PARAGRAPH:
2202 if(depth == par->depth
2203 && !environment_stack[depth].empty()) {
2204 sgmlCloseTag(file, depth, environment_stack[depth]);
2205 environment_stack[depth].clear();
2209 fprintf(file, "</p>");
2211 sgmlOpenTag(file, depth, style.latexname());
2216 LinuxDocError(par, 0, _("Error : Wrong depth for LatexType Command.\n"));
2218 if (!environment_stack[depth].empty()){
2219 sgmlCloseTag(file, depth, environment_stack[depth]);
2220 fprintf(file, "</p>");
2223 environment_stack[depth].clear();
2224 sgmlOpenTag(file, depth, style.latexname());
2227 case LATEX_ENVIRONMENT:
2228 case LATEX_ITEM_ENVIRONMENT:
2229 if(depth == par->depth
2230 && environment_stack[depth] != style.latexname()
2231 && !environment_stack[depth].empty()) {
2233 sgmlCloseTag(file, depth,
2234 environment_stack[depth]);
2235 environment_stack[depth].clear();
2237 if (depth < par->depth) {
2239 environment_stack[depth].clear();
2241 if (environment_stack[depth] != style.latexname()) {
2244 sgmlOpenTag(file, depth, temp);
2246 environment_stack[depth] = style.latexname();
2247 sgmlOpenTag(file, depth, environment_stack[depth]);
2249 if(style.latextype == LATEX_ENVIRONMENT) break;
2251 desc_on = (style.labeltype == LABEL_MANUAL);
2258 sgmlOpenTag(file, depth+1, item_name);
2261 sgmlOpenTag(file, depth, style.latexname());
2266 SimpleLinuxDocOnePar(file, par, desc_on, depth);
2269 linuxDocHandleFootnote(file, par, depth);
2271 while(par && par->IsDummy());
2273 fprintf(file, "\n");
2274 /* write closing SGML tags */
2275 switch(style.latextype) {
2277 case LATEX_ENVIRONMENT:
2278 case LATEX_ITEM_ENVIRONMENT:
2281 sgmlCloseTag(file, depth, style.latexname());
2286 /* Close open tags */
2287 for(;depth>0;depth--)
2288 sgmlCloseTag(file, depth, environment_stack[depth]);
2290 if(!environment_stack[depth].empty())
2291 sgmlCloseTag(file, depth, environment_stack[depth]);
2293 fprintf(file, "\n\n");
2294 sgmlCloseTag(file, 0, top_element);
2297 WriteFSAlert(_("Error! Could not close file properly:"),
2303 void Buffer::linuxDocHandleFootnote(FILE * file, LyXParagraph * & par,
2306 string tag = "footnote";
2308 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2309 sgmlOpenTag(file, depth+1, tag);
2310 SimpleLinuxDocOnePar(file, par, 0, depth+1);
2311 sgmlCloseTag(file, depth+1, tag);
2316 void Buffer::DocBookHandleCaption(FILE * file, string & inner_tag,
2317 int const depth, int desc_on,
2318 LyXParagraph * & par)
2320 LyXParagraph * tpar = par;
2321 string tmp_par, extra_par;
2322 while (tpar && (tpar->footnoteflag != LyXParagraph::NO_FOOTNOTE) &&
2323 (tpar->layout != textclasslist.NumberOfLayout(params.textclass, "Caption").second))
2326 tpar->layout == textclasslist.NumberOfLayout(params.textclass,
2327 "Caption").second) {
2328 sgmlOpenTag(file, depth+1, inner_tag);
2329 SimpleDocBookOnePar(tmp_par, extra_par, tpar, desc_on, depth+2);
2330 tmp_par = strip(tmp_par);
2331 tmp_par = frontStrip(tmp_par);
2332 fprintf(file, "%s", tmp_par.c_str());
2333 sgmlCloseTag(file, depth+1, inner_tag);
2334 if(!extra_par.empty())
2335 fprintf(file, "%s", extra_par.c_str());
2339 void Buffer::DocBookHandleFootnote(FILE * file, LyXParagraph * & par,
2342 string tag, inner_tag;
2343 string tmp_par, extra_par;
2344 bool inner_span = false;
2347 // This is not how I like to see enums. They should not be anonymous
2348 // and variables of its type should not be declared right after the
2349 // last brace. (Lgb)
2356 } last = NO_ONE, present = FOOTNOTE_LIKE;
2358 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2359 if(last == present) {
2361 if(!tmp_par.empty()) {
2362 fprintf(file, "%s", tmp_par.c_str());
2364 sgmlCloseTag(file, depth+1, inner_tag);
2365 sgmlOpenTag(file, depth+1, inner_tag);
2369 fprintf(file, "\n");
2371 fprintf(file, "%s", tmp_par.c_str());
2372 if(!inner_tag.empty()) sgmlCloseTag(file, depth+1, inner_tag);
2373 if(!extra_par.empty()) fprintf(file, "%s", extra_par.c_str());
2374 if(!tag.empty()) sgmlCloseTag(file, depth, tag);
2377 switch (par->footnotekind) {
2378 case LyXParagraph::FOOTNOTE:
2379 case LyXParagraph::ALGORITHM:
2382 present = FOOTNOTE_LIKE;
2385 case LyXParagraph::MARGIN:
2388 present = MARGIN_LIKE;
2391 case LyXParagraph::FIG:
2392 case LyXParagraph::WIDE_FIG:
2394 inner_tag = "title";
2398 case LyXParagraph::TAB:
2399 case LyXParagraph::WIDE_TAB:
2401 inner_tag = "title";
2406 sgmlOpenTag(file, depth, tag);
2407 if ((present == TAB_LIKE) || (present == FIG_LIKE)) {
2408 DocBookHandleCaption(file, inner_tag, depth,
2412 sgmlOpenTag(file, depth+1, inner_tag);
2415 // ignore all caption here, we processed them above!!!
2416 if (par->layout != textclasslist.NumberOfLayout(params.textclass,
2417 "Caption").second) {
2418 SimpleDocBookOnePar(tmp_par, extra_par, par,
2421 tmp_par = frontStrip(strip(tmp_par));
2426 fprintf(file, "%s", tmp_par.c_str());
2427 if(!inner_tag.empty()) sgmlCloseTag(file, depth+1, inner_tag);
2428 if(!extra_par.empty()) fprintf(file, "%s", extra_par.c_str());
2429 if(!tag.empty()) sgmlCloseTag(file, depth, tag);
2434 /* push a tag in a style stack */
2435 void Buffer::push_tag(FILE * file, char const * tag,
2436 int & pos, char stack[5][3])
2440 /* pop all previous tags */
2441 for (j = pos; j >= 0; j--)
2442 fprintf(file, "</%s>", stack[j]);
2445 sprintf(stack[++pos], "%s", tag);
2448 for (j= 0; j<= pos; j++)
2449 fprintf(file, "<%s>", stack[j]);
2453 // pop a tag from a style stack
2454 void Buffer::pop_tag(FILE * file, 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 fprintf(file, "</%s>", stack[j]);
2464 fprintf(file, "</%s>", tag);
2466 // push all tags, but the specified one
2467 for (j= j+1; j<= pos; j++) {
2468 fprintf(file, "<%s>", 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(FILE * file, unsigned int & colcount,
2481 const unsigned int newcol)
2484 if (colcount > lyxrc->ascii_linelen) {
2485 fprintf(file, "\n");
2486 colcount = newcol; // assume write after this call
2491 void Buffer::SimpleLinuxDocOnePar(FILE * file, 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(file, "tt", stack_num, stack);
2542 else if (font2.family() == LyXFont::SANS_FAMILY) {
2543 push_tag(file, "sf", stack_num, stack);
2548 pop_tag(file, "tt", stack_num, stack);
2549 if (font2.family() == LyXFont::SANS_FAMILY) {
2550 push_tag(file, "sf", stack_num, stack);
2558 pop_tag(file, "sf", stack_num, stack);
2559 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2560 push_tag(file, "tt", stack_num, stack);
2569 /* handle bold face */
2570 if (font1.series() != font2.series()) {
2571 if (font2.series() == LyXFont::BOLD_SERIES) {
2572 push_tag(file, "bf", stack_num, stack);
2576 pop_tag(file, "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(file, "it", stack_num, stack);
2589 else if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2590 push_tag(file, "sl", stack_num, stack);
2595 pop_tag(file, "it", stack_num, stack);
2596 if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2597 push_tag(file, "sl", stack_num, stack);
2605 pop_tag(file, "sl", stack_num, stack);
2606 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2607 push_tag(file, "it", stack_num, stack);
2615 /* handle <em> tag */
2616 if (font1.emph() != font2.emph()) {
2617 if (font2.emph() == LyXFont::ON) {
2618 push_tag(file, "em", stack_num, stack);
2621 pop_tag(file, "em", stack_num, stack);
2626 c = par->GetChar(i);
2628 if (font2.latex() == LyXFont::ON) {
2629 // "TeX"-Mode on == > SGML-Mode on.
2631 fprintf(file, "%c", c); // see LaTeX-Generation...
2633 } else if (c == LyXParagraph::META_INSET) {
2634 inset = par->GetInset(i);
2636 inset->Linuxdoc(tmp_out);
2637 fprintf(file, "%s", tmp_out.c_str());
2641 if (par->linuxDocConvertChar(c, sgml_string)
2642 && !style.free_spacing) { // in freespacing
2644 // non-breaking characters
2648 linux_doc_line_break(file, char_line_count, 6);
2649 fprintf(file, "</tag>");
2653 linux_doc_line_break(file, char_line_count, 1);
2654 fprintf(file, "%c", c);
2658 fprintf(file, "%s", sgml_string.c_str());
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(file,
2674 3+strlen(stack[j]));
2675 fprintf(file, "</%s>", stack[j]);
2678 /* resets description flag correctly */
2681 /* <tag> not closed... */
2682 linux_doc_line_break(file, char_line_count, 6);
2683 fprintf(file, "</tag>");
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 FilePtr file(filename, FilePtr::write);
2729 tex_code_break_column = column;
2732 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), filename);
2740 "<!doctype %s public \"-//OASIS//DTD DocBook V3.1//EN\"",
2741 top_element.c_str());
2743 if (params.preamble.empty())
2744 fprintf(file, ">\n\n");
2746 fprintf(file, "\n [ %s \n]>\n\n", params.preamble.c_str() );
2748 string userName(getUserName());
2750 "<!-- DocBook file was created by LyX 1.0 (C) 1995-1999\n");
2751 fprintf(file, "by <%s> %s -->\n", userName.c_str(), (char *)date());
2753 if(params.options.empty())
2754 sgmlOpenTag(file, 0, top_element);
2756 string top = top_element;
2758 top += params.options;
2759 sgmlOpenTag(file, 0, top);
2763 int desc_on= 0; /* description mode*/
2764 LyXLayout const & style = textclasslist.Style(GetCurrentTextClass(),
2766 par->AutoDeleteInsets();
2768 /* environment tag closing */
2769 for( ;depth > par->depth; depth--) {
2770 if(environment_inner[depth] != "!-- --") {
2771 item_name= "listitem";
2772 sgmlCloseTag(file, command_depth+depth,
2774 if( environment_inner[depth] == "varlistentry")
2775 sgmlCloseTag(file, depth+command_depth,
2776 environment_inner[depth]);
2778 sgmlCloseTag(file, depth+command_depth,
2779 environment_stack[depth]);
2780 environment_stack[depth].clear();
2781 environment_inner[depth].clear();
2784 if(depth == par->depth
2785 && environment_stack[depth] != style.latexname()
2786 && !environment_stack[depth].empty()) {
2787 if(environment_inner[depth] != "!-- --") {
2788 item_name= "listitem";
2789 sgmlCloseTag(file, command_depth+depth,
2791 if( environment_inner[depth] == "varlistentry")
2792 sgmlCloseTag(file, depth+command_depth,
2793 environment_inner[depth]);
2796 sgmlCloseTag(file, depth+command_depth,
2797 environment_stack[depth]);
2799 environment_stack[depth].clear();
2800 environment_inner[depth].clear();
2803 // Write opening SGML tags.
2804 switch(style.latextype) {
2805 case LATEX_PARAGRAPH:
2806 if(style.latexname() != "dummy")
2807 sgmlOpenTag(file, depth+command_depth,
2813 LinuxDocError(par, 0,
2814 _("Error : Wrong depth for "
2815 "LatexType Command.\n"));
2817 command_name = style.latexname();
2819 tmps = style.latexparam();
2820 c_params = split(tmps, c_depth,'|');
2822 cmd_depth= atoi(c_depth.c_str());
2825 if(cmd_depth<command_base) {
2826 for(int j = command_depth;
2827 j >= command_base; j--)
2828 if(!command_stack[j].empty())
2829 sgmlCloseTag(file, j, command_stack[j]);
2830 command_depth= command_base= cmd_depth;
2832 else if(cmd_depth<= command_depth) {
2833 for(int j= command_depth;
2834 j >= cmd_depth; j--)
2836 if(!command_stack[j].empty())
2837 sgmlCloseTag(file, j, command_stack[j]);
2838 command_depth= cmd_depth;
2841 command_depth= cmd_depth;
2844 command_depth = command_base = cmd_depth;
2845 command_flag = true;
2847 command_stack[command_depth]= command_name;
2849 // treat label as a special case for
2850 // more WYSIWYM handling.
2851 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2852 Inset *inset = par->GetInset(0);
2853 char lyx_code = inset->LyxCode();
2854 if (lyx_code == Inset::LABEL_CODE){
2855 command_name+= " id=\"";
2856 command_name+= ((InsetCommand *) inset)->getContents();
2857 command_name+= "\"";
2862 sgmlOpenTag(file, depth+command_depth, command_name);
2864 sgmlOpenTag(file, depth+1+command_depth, item_name);
2867 case LATEX_ENVIRONMENT:
2868 case LATEX_ITEM_ENVIRONMENT:
2869 if (depth < par->depth) {
2871 environment_stack[depth].clear();
2874 if (environment_stack[depth] != style.latexname()) {
2875 environment_stack[depth]= style.latexname();
2876 environment_inner[depth]= "!-- --";
2877 sgmlOpenTag(file, depth + command_depth,
2878 environment_stack[depth]);
2880 if(environment_inner[depth] != "!-- --") {
2881 item_name= "listitem";
2883 command_depth + depth,
2885 if (environment_inner[depth] == "varlistentry")
2887 depth+command_depth,
2888 environment_inner[depth]);
2892 if(style.latextype == LATEX_ENVIRONMENT) {
2893 if(!style.latexparam().empty())
2894 sgmlOpenTag(file, depth+command_depth,
2895 style.latexparam());
2899 desc_on = (style.labeltype == LABEL_MANUAL);
2902 environment_inner[depth]= "varlistentry";
2904 environment_inner[depth]= "listitem";
2906 sgmlOpenTag(file, depth+1+command_depth,
2907 environment_inner[depth]);
2911 sgmlOpenTag(file, depth+1+command_depth,
2916 sgmlOpenTag(file, depth+1+command_depth,
2921 sgmlOpenTag(file, depth + command_depth,
2927 string tmp_par, extra_par;
2929 SimpleDocBookOnePar(tmp_par, extra_par, par, desc_on,
2930 depth+1+command_depth);
2931 fprintf(file, "%s", tmp_par.c_str());
2934 DocBookHandleFootnote(file, par, depth+1+command_depth);
2936 while(par && par->IsDummy());
2939 /* write closing SGML tags */
2940 switch(style.latextype) {
2943 sgmlCloseTag(file, depth + command_depth, end_tag);
2945 case LATEX_ENVIRONMENT:
2946 if(!style.latexparam().empty())
2947 sgmlCloseTag(file, depth + command_depth,
2948 style.latexparam());
2950 case LATEX_ITEM_ENVIRONMENT:
2951 if(desc_on == 1) break;
2953 sgmlCloseTag(file, depth+1+command_depth, end_tag);
2955 case LATEX_PARAGRAPH:
2956 if(style.latexname() != "dummy")
2957 sgmlCloseTag(file, depth + command_depth,
2961 sgmlCloseTag(file, 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(file, command_depth+depth,
2974 if( environment_inner[depth] == "varlistentry")
2975 sgmlCloseTag(file, depth+command_depth,
2976 environment_inner[depth]);
2979 sgmlCloseTag(file, 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(file, j, command_stack[j]);
2988 fprintf(file, "\n\n");
2989 sgmlCloseTag(file, 0, top_element);
2992 WriteFSAlert(_("Error! Could not close file properly:"),
2998 void Buffer::SimpleDocBookOnePar(string & file, string & extra,
2999 LyXParagraph * par, int & desc_on,
3003 par->SimpleDocBookOneTablePar(file, extra, desc_on, depth);
3006 LyXFont font1, font2;
3009 LyXParagraph::size_type main_body;
3011 string emph= "emphasis";
3012 bool emph_flag= false;
3013 int char_line_count= 0;
3015 LyXLayout const & style = textclasslist.Style(params.textclass,
3018 if (style.labeltype != LABEL_MANUAL)
3021 main_body = par->BeginningOfMainBody();
3023 /* gets paragraph main font */
3025 font1 = style.labelfont;
3029 char_line_count = depth;
3030 if(!style.free_spacing)
3031 for (j= 0;j< depth;j++)
3034 /* parsing main loop */
3035 for (LyXParagraph::size_type i = 0;
3036 i < par->size(); ++i) {
3037 font2 = par->getFont(i);
3039 /* handle <emphasis> tag */
3040 if (font1.emph() != font2.emph() && i) {
3041 if (font2.emph() == LyXFont::ON) {
3042 file += "<emphasis>";
3045 file += "</emphasis>";
3050 c = par->GetChar(i);
3052 if (c == LyXParagraph::META_INSET) {
3053 inset = par->GetInset(i);
3055 inset->DocBook(tmp_out);
3057 // This code needs some explanation:
3058 // Two insets are treated specially
3059 // label if it is the first element in a command paragraph
3061 // graphics inside tables or figure floats can't go on
3062 // title (the equivalente in latex for this case is caption
3063 // and title should come first
3066 if(desc_on!= 3 || i!= 0) {
3067 if(tmp_out[0] == '@') {
3069 extra += frontStrip(tmp_out, '@');
3071 file += frontStrip(tmp_out, '@');
3076 } else if (font2.latex() == LyXFont::ON) {
3077 // "TeX"-Mode on ==> SGML-Mode on.
3084 if (par->linuxDocConvertChar(c, sgml_string)
3085 && !style.free_spacing) { // in freespacing
3087 // non-breaking characters
3092 file += "</term><listitem><para>";
3100 file += sgml_string;
3106 /* needed if there is an optional argument but no contents */
3107 if (main_body > 0 && main_body == par->size()) {
3111 file += "</emphasis>";
3114 /* resets description flag correctly */
3117 /* <term> not closed... */
3125 bool Buffer::removeAutoInsets()
3127 LyXParagraph *par = paragraph;
3129 LyXCursor cursor = text->cursor;
3130 LyXCursor tmpcursor = cursor;
3131 cursor.par = tmpcursor.par->ParFromPos(tmpcursor.pos);
3132 cursor.pos = tmpcursor.par->PositionInParFromPos(tmpcursor.pos);
3136 if (par->AutoDeleteInsets()){
3138 if (par->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE){
3139 /* this is possible now, since SetCursor takes
3140 care about footnotes */
3141 text->SetCursorIntern(par, 0);
3142 text->RedoParagraphs(text->cursor, text->cursor.par->Next());
3143 text->FullRebreak();
3148 /* avoid forbidden cursor positions caused by error removing */
3149 if (cursor.pos > cursor.par->Last())
3150 cursor.pos = cursor.par->Last();
3151 text->SetCursorIntern(cursor.par, cursor.pos);
3157 int Buffer::runLaTeX()
3159 if (!text) return 0;
3163 // get LaTeX-Filename
3164 string name = SpaceLess(ChangeExtension (filename, ".tex", true));
3166 string path = OnlyPath(filename);
3168 string org_path = path;
3169 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
3173 Path p(path); // path to LaTeX file
3174 users->owner()->getMiniBuffer()->Set(_("Running LaTeX..."));
3176 // Remove all error insets
3177 bool a = removeAutoInsets();
3179 // Always generate the LaTeX file
3180 makeLaTeXFile(name, org_path, false);
3183 // do the LaTex run(s)
3185 LaTeX latex(lyxrc->latex_command, name, filepath);
3186 int res = latex.run(terr,
3187 users->owner()->getMiniBuffer()); // running latex
3189 // check return value from latex.run().
3190 if ((res & LaTeX::NO_LOGFILE)) {
3191 WriteAlert(_("LaTeX did not work!"),
3192 _("Missing log file:"), name);
3193 } else if ((res & LaTeX::ERRORS)) {
3194 users->owner()->getMiniBuffer()->Set(_("Done"));
3195 // Insert all errors as errors boxes
3198 // Dvi should also be kept dirty if the latex run
3199 // ends up with errors. However it should be possible
3200 // to view a dirty dvi too.
3202 //no errors or any other things to think about so:
3203 users->owner()->getMiniBuffer()->Set(_("Done"));
3207 // if we removed error insets before we ran LaTeX or if we inserted
3208 // error insets after we ran LaTeX this must be run:
3209 if (a || (res & LaTeX::ERRORS)){
3212 users->updateScrollbar();
3216 return latex.getNumErrors();
3220 int Buffer::runLiterate()
3222 if (!text) return 0;
3226 // get LaTeX-Filename
3227 string name = SpaceLess(ChangeExtension (filename, ".tex", true));
3228 // get Literate-Filename
3229 string lit_name = SpaceLess(ChangeExtension (filename, lyxrc->literate_extension, true));
3231 string path = OnlyPath(filename);
3233 string org_path = path;
3234 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
3238 Path p(path); // path to Literate file
3239 users->owner()->getMiniBuffer()->Set(_("Running Literate..."));
3241 // Remove all error insets
3242 bool a = removeAutoInsets();
3244 // generate the Literate file if necessary
3245 if (!isDviClean() || a) {
3246 makeLaTeXFile(lit_name, org_path, false);
3250 Literate literate(lyxrc->latex_command, name, filepath,
3252 lyxrc->literate_command, lyxrc->literate_error_filter,
3253 lyxrc->build_command, lyxrc->build_error_filter);
3255 int res = literate.weave(terr, users->owner()->getMiniBuffer());
3257 // check return value from literate.weave().
3258 if ((res & Literate::NO_LOGFILE)) {
3259 WriteAlert(_("Literate command did not work!"),
3260 _("Missing log file:"), name);
3261 } else if ((res & Literate::ERRORS)) {
3262 users->owner()->getMiniBuffer()->Set(_("Done"));
3263 // Insert all errors as errors boxes
3266 // Dvi should also be kept dirty if the latex run
3267 // ends up with errors. However it should be possible
3268 // to view a dirty dvi too.
3270 //no errors or any other things to think about so:
3271 users->owner()->getMiniBuffer()->Set(_("Done"));
3275 // if we removed error insets before we ran LaTeX or if we inserted
3276 // error insets after we ran LaTeX this must be run:
3277 if (a || (res & Literate::ERRORS)){
3280 users->updateScrollbar();
3284 return literate.getNumErrors();
3288 int Buffer::buildProgram()
3290 if (!text) return 0;
3294 // get LaTeX-Filename
3295 string name = SpaceLess(ChangeExtension (filename, ".tex", true));
3296 // get Literate-Filename
3297 string lit_name = SpaceLess(ChangeExtension (filename, 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 = SpaceLess(ChangeExtension (filename, ".tex", true));
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(FILE * file, LyXParagraph * par)
3481 font1 = LyXFont(LyXFont::ALL_INHERIT),
3484 LyXParagraph::size_type i;
3493 string fname1 = TmpFileName(string(), "RAT1");
3494 string fname2 = TmpFileName(string(), "RAT2");
3495 if (!(fp= fopen(fname1.c_str(), "w"))) {
3496 WriteAlert(_("LYX_ERROR:"),
3497 _("Cannot open temporary file:"), fname1);
3500 par->table->RoffEndOfCell(fp, -1);
3501 for (i = 0; i < par->size(); ++i) {
3502 c = par->GetChar(i);
3503 if (par->table->IsContRow(cell)) {
3504 if (c == LyXParagraph::META_NEWLINE)
3508 font2 = par->GetFontSettings(i);
3509 if (font1.latex() != font2.latex()) {
3510 if (font2.latex() != LyXFont::OFF)
3514 case LyXParagraph::META_INSET:
3515 if ((inset = par->GetInset(i))) {
3516 if (!(fp2= fopen(fname2.c_str(), "w+"))) {
3517 WriteAlert(_("LYX_ERROR:"),
3518 _("Cannot open temporary file:"), fname2);
3520 remove(fname1.c_str());
3523 inset->Latex(fp2,-1);
3528 fprintf(fp, "\\\\");
3536 case LyXParagraph::META_NEWLINE:
3537 if (par->table->CellHasContRow(cell)>= 0)
3538 par->RoffContTableRows(fp, i+1, cell);
3539 par->table->RoffEndOfCell(fp, cell);
3542 case LyXParagraph::META_HFILL:
3544 case LyXParagraph::META_PROTECTED_SEPARATOR:
3547 fprintf(fp, "\\\\");
3551 fprintf(fp, "%c", c);
3554 << "RoffAsciiTable:"
3555 " NULL char in structure." << endl;
3559 par->table->RoffEndOfCell(fp, cell);
3561 string cmd = lyxrc->ascii_roff_command + " >" + fname2;
3562 cmd = subst(cmd, "$$FName", fname1);
3563 Systemcalls one(Systemcalls::System, cmd);
3564 if (!(lyxerr.debugging(Debug::ROFF))) {
3565 remove(fname1.c_str());
3567 if (!(fp= fopen(fname2.c_str(), "r"))) {
3568 WriteFSAlert(_("Error! Can't open temporary file:"), fname2);
3571 // now output the produced file
3572 fprintf(file, "\n\n");
3575 WriteAlert(_("Error!"),
3576 _("Error executing *roff command on table"));
3577 // overread leading blank lines
3578 while(!feof(fp) && (c == '\n'))
3581 for(j= 0; j<par->depth; j++)
3583 while(!feof(fp) && (c != '\n')) {
3588 // overread trailing blank lines
3589 while(!feof(fp) && (c == '\n'))
3593 remove(fname2.c_str());
3597 /// changed Heinrich Bauer, 23/03/98
3598 bool Buffer::isDviClean()
3600 if (lyxrc->use_tempdir)
3601 return dvi_clean_tmpd;
3603 return dvi_clean_orgd;
3607 /// changed Heinrich Bauer, 23/03/98
3608 void Buffer::markDviClean()
3610 if (lyxrc->use_tempdir)
3611 dvi_clean_tmpd = true;
3613 dvi_clean_orgd = true;
3617 /// changed Heinrich Bauer, 23/03/98
3618 void Buffer::markDviDirty()
3620 if (lyxrc->use_tempdir)
3621 dvi_clean_tmpd = false;
3623 dvi_clean_orgd = false;
3627 void Buffer::update(signed char f)
3631 users->owner()->updateLayoutChoice();
3633 if (!text->selection && f > -3)
3634 text->sel_cursor = text->cursor;
3637 text->FullRebreak();
3640 if (f != 3 && f != -3) {
3642 users->updateScrollbar();
3645 if (f == 1 || f == -1) {
3648 users->owner()->getMiniBuffer()->setTimer(4);
3656 void Buffer::validate(LaTeXFeatures & features)
3658 LyXParagraph * par = paragraph;
3659 LyXTextClass const & tclass =
3660 textclasslist.TextClass(params.textclass);
3662 // AMS Style is at document level
3664 features.amsstyle = (params.use_amsmath ||
3665 tclass.provides(LyXTextClass::amsmath));
3668 // We don't use "lyxerr.debug" because of speed. (Asger)
3669 if (lyxerr.debugging(Debug::LATEX))
3670 lyxerr << "Paragraph: " << par << endl;
3672 // Now just follow the list of paragraphs and run
3673 // validate on each of them.
3674 par->validate(features);
3676 // and then the next paragraph
3680 // the bullet shapes are buffer level not paragraph level
3681 // so they are tested here
3682 for (int i = 0; i < 4; ++i) {
3683 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
3684 int font = params.user_defined_bullets[i].getFont();
3687 .user_defined_bullets[i]
3694 features.latexsym = true;
3698 features.amssymb = true;
3700 else if ((font >= 2 && font <= 5)) {
3701 features.pifont = true;
3706 if (lyxerr.debugging(Debug::LATEX)) {
3707 features.showStruct(params);
3712 void Buffer::setPaperStuff()
3714 params.papersize = BufferParams::PAPER_DEFAULT;
3715 char c1 = params.paperpackage;
3716 if (c1 == BufferParams::PACKAGE_NONE) {
3717 char c2 = params.papersize2;
3718 if (c2 == BufferParams::VM_PAPER_USLETTER)
3719 params.papersize = BufferParams::PAPER_USLETTER;
3720 else if (c2 == BufferParams::VM_PAPER_USLEGAL)
3721 params.papersize = BufferParams::PAPER_LEGALPAPER;
3722 else if (c2 == BufferParams::VM_PAPER_USEXECUTIVE)
3723 params.papersize = BufferParams::PAPER_EXECUTIVEPAPER;
3724 else if (c2 == BufferParams::VM_PAPER_A3)
3725 params.papersize = BufferParams::PAPER_A3PAPER;
3726 else if (c2 == BufferParams::VM_PAPER_A4)
3727 params.papersize = BufferParams::PAPER_A4PAPER;
3728 else if (c2 == BufferParams::VM_PAPER_A5)
3729 params.papersize = BufferParams::PAPER_A5PAPER;
3730 else if ((c2 == BufferParams::VM_PAPER_B3) || (c2 == BufferParams::VM_PAPER_B4) ||
3731 (c2 == BufferParams::VM_PAPER_B5))
3732 params.papersize = BufferParams::PAPER_B5PAPER;
3733 } else if ((c1 == BufferParams::PACKAGE_A4) || (c1 == BufferParams::PACKAGE_A4WIDE) ||
3734 (c1 == BufferParams::PACKAGE_WIDEMARGINSA4))
3735 params.papersize = BufferParams::PAPER_A4PAPER;
3740 void Buffer::setOldPaperStuff()
3742 char c = params.papersize = params.papersize2;
3743 params.papersize2 = BufferParams::VM_PAPER_DEFAULT;
3744 params.paperpackage = BufferParams::PACKAGE_NONE;
3745 if (c == OLD_PAPER_A4PAPER)
3746 params.papersize2 = BufferParams::VM_PAPER_A4;
3747 else if (c == OLD_PAPER_A4)
3748 params.paperpackage = BufferParams::PACKAGE_A4;
3749 else if (c == OLD_PAPER_A4WIDE)
3750 params.paperpackage = BufferParams::PACKAGE_A4WIDE;
3751 else if (c == OLD_PAPER_WIDEMARGINSA4)
3752 params.paperpackage = BufferParams::PACKAGE_WIDEMARGINSA4;
3753 else if (c == OLD_PAPER_USLETTER)
3754 params.papersize2 = BufferParams::VM_PAPER_USLETTER;
3755 else if (c == OLD_PAPER_A5PAPER)
3756 params.papersize2 = BufferParams::VM_PAPER_A5;
3757 else if (c == OLD_PAPER_B5PAPER)
3758 params.papersize2 = BufferParams::VM_PAPER_B5;
3759 else if (c == OLD_PAPER_EXECUTIVEPAPER)
3760 params.papersize2 = BufferParams::VM_PAPER_USEXECUTIVE;
3761 else if (c == OLD_PAPER_LEGALPAPER)
3762 params.papersize2 = BufferParams::VM_PAPER_USLEGAL;
3767 void Buffer::insertInset(Inset * inset, string const & lout,
3770 // check for table/list in tables
3771 if (no_table && text->cursor.par->table){
3772 WriteAlert(_("Impossible Operation!"),
3773 _("Cannot insert table/list in table."),
3777 // not quite sure if we want this...
3778 text->SetCursorParUndo();
3782 if (!lout.empty()) {
3784 text->BreakParagraph();
3787 if (text->cursor.par->Last()) {
3790 text->BreakParagraph();
3794 int lay = textclasslist.NumberOfLayout(params.textclass,
3796 if (lay == -1) // layout not found
3797 // use default layout "Standard" (0)
3800 text->SetLayout(lay);
3802 text->SetParagraph(0, 0,
3804 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3810 text->current_font.setLatex(LyXFont::OFF);
3813 text->InsertInset(inset);
3816 text->UnFreezeUndo();
3820 // Open and lock an updatable inset
3821 void Buffer::open_new_inset(UpdatableInset * new_inset)
3825 insertInset(new_inset);
3828 new_inset->Edit(0, 0);
3832 /* This function should be in Buffer because it's a buffer's property (ale) */
3833 string Buffer::getIncludeonlyList(char delim)
3836 LyXParagraph * par = paragraph;
3837 LyXParagraph::size_type pos;
3841 while ((inset = par->ReturnNextInsetPointer(pos))){
3842 if (inset->LyxCode() == Inset::INCLUDE_CODE) {
3843 InsetInclude * insetinc =
3844 static_cast<InsetInclude*>(inset);
3845 if (insetinc->isInclude()
3846 && insetinc->isNoLoad()) {
3849 lst += ChangeExtension(insetinc->getContents(), string(), true);
3856 lyxerr.debug() << "Includeonly(" << lst << ')' << endl;
3861 /* This is also a buffer property (ale) */
3862 string Buffer::getReferenceList(char delim)
3864 /// if this is a child document and the parent is already loaded
3865 /// Use the parent's list instead [ale990407]
3866 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3867 Buffer *tmp = bufferlist.getBuffer(params.parentname);
3869 return tmp->getReferenceList(delim);
3872 LyXParagraph *par = paragraph;
3873 LyXParagraph::size_type pos;
3878 while ((inset = par->ReturnNextInsetPointer(pos))){
3879 for (int i = 0; i < inset->GetNumberOfLabels(); i++) {
3882 lst += inset->getLabel(i);
3888 lyxerr.debug() << "References(" << lst << ")" << endl;
3893 /* This is also a buffer property (ale) */
3894 string Buffer::getBibkeyList(char delim)
3896 /// if this is a child document and the parent is already loaded
3897 /// Use the parent's list instead [ale990412]
3898 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3899 Buffer *tmp = bufferlist.getBuffer(params.parentname);
3901 return tmp->getBibkeyList(delim);
3905 LyXParagraph * par = paragraph;
3908 if (!bibkeys.empty())
3910 bibkeys += par->bibkey->getContents();
3915 // Might be either using bibtex or a child has bibliography
3916 if (bibkeys.empty()) {
3920 LyXParagraph::size_type pos = -1;
3922 // Search for Bibtex or Include inset
3923 while ((inset = par->ReturnNextInsetPointer(pos))) {
3924 if (inset-> LyxCode() == Inset::BIBTEX_CODE) {
3925 if (!bibkeys.empty())
3927 bibkeys += static_cast<InsetBibtex*>(inset)->getKeys();
3928 } else if (inset-> LyxCode() == Inset::INCLUDE_CODE) {
3929 string bk = static_cast<InsetInclude*>(inset)->getKeys();
3931 if (!bibkeys.empty())
3942 lyxerr.debug() << "Bibkeys(" << bibkeys << ")" << endl;
3947 /* This is also a buffer property (ale) */
3948 // Not so sure about that. a goto Label function can not be buffer local, just
3949 // think how this will work in a multiwindo/buffer environment, all the
3950 // cursors in all the views showing this buffer will move. (Lgb)
3951 // OK, then no cursor action should be allowed in buffer. (ale)
3952 bool Buffer::gotoLabel(string const & label)
3955 LyXParagraph * par = paragraph;
3956 LyXParagraph::size_type pos;
3960 while ((inset = par->ReturnNextInsetPointer(pos))){
3961 for (int i = 0; i < inset->GetNumberOfLabels(); i++) {
3962 if (label == inset->getLabel(i)) {
3964 text->SetCursor(par, pos);
3965 text->sel_cursor = text->cursor;
3978 bool Buffer::isDepClean(string const & name) const
3980 DEPCLEAN * item = dep_clean;
3981 while (item && item->master != name)
3983 if (!item) return true;
3988 void Buffer::markDepClean(string const & name)
3991 dep_clean = new DEPCLEAN;
3992 dep_clean->clean = true;
3993 dep_clean->master = name;
3994 dep_clean->next = 0;
3996 DEPCLEAN* item = dep_clean;
3997 while (item && item->master != name)
4002 item = new DEPCLEAN;
4004 item->master = name;