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.exist() || !fi.readable()) {
223 WriteAlert(_("Error!"),
224 _("Cannot open specified file:"),
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
1204 // We do not print this anymore, since it annoys cvs and is useless
1205 // anyway. It could even be seen as including private
1206 // information without telling the user :) -- JMarc
1208 // "#This file was created by <%s> %s",
1209 // userName.c_str(),(char*)date());
1211 "#LyX 1.1 (C) 1995-1999 Matthias Ettrich"
1212 " and the LyX Team\n");
1214 // at the very beginning the used lyx format
1215 fprintf(file, "\\lyxformat %.2f\n", LYX_FORMAT);
1217 // now write out the buffer parameters.
1218 params.writeFile(file);
1220 char footnoteflag = 0;
1223 // this will write out all the paragraphs
1224 // using recursive descent.
1225 paragraph->writeFile(file, params, footnoteflag, depth);
1227 // Write marker that shows file is complete
1228 fprintf(file, "\n\\the_end\n");
1231 lyxerr << _("Error! Could not close file properly: ")
1232 << filename << endl;
1234 WriteFSAlert(_("Error! Could not close file properly: "),
1242 void Buffer::writeFileAscii(string const & filename, int linelen)
1244 FilePtr file(filename, FilePtr::write);
1248 LyXParagraph * par = paragraph;
1258 LyXParagraph::size_type i;
1274 ref_printed = false;
1278 WriteFSAlert(_("Error: Cannot write file:"), filename);
1281 fname1 = TmpFileName();
1285 if (par->footnoteflag != LyXParagraph::NO_FOOTNOTE ||
1287 par->previous->footnoteflag == LyXParagraph::NO_FOOTNOTE){
1289 /* begins a footnote environment ? */
1290 if (footnoteflag != par->footnoteflag) {
1291 footnoteflag = par->footnoteflag;
1293 j = strlen(string_footnotekinds[par->footnotekind])+4;
1294 if (currlinelen+j > linelen)
1295 fprintf(file, "\n");
1296 fprintf(file, "([%s] ",
1297 string_footnotekinds[par->footnotekind]);
1302 /* begins or ends a deeper area ?*/
1303 if (depth != par->depth) {
1304 if (par->depth > depth) {
1305 while (par->depth > depth) {
1310 while (par->depth < depth) {
1316 /* First write the layout */
1317 tmp = textclasslist.NameOfLayout(params.textclass, par->layout);
1318 if (tmp == "Itemize") {
1320 ltype_depth = depth+1;
1321 } else if (tmp == "Enumerate") {
1323 ltype_depth = depth+1;
1324 } else if (strstr(tmp.c_str(), "ection")) {
1326 ltype_depth = depth+1;
1327 } else if (strstr(tmp.c_str(), "aragraph")) {
1329 ltype_depth = depth+1;
1330 } else if (tmp == "Description") {
1332 ltype_depth = depth+1;
1333 } else if (tmp == "Abstract") {
1336 } else if (tmp == "Bibliography") {
1344 /* maybe some vertical spaces */
1346 /* the labelwidthstring used in lists */
1350 /* some pagebreaks? */
1354 /* what about the alignment */
1357 /* dummy layout, that means a footnote ended */
1358 footnoteflag = LyXParagraph::NO_FOOTNOTE;
1359 fprintf(file, ") ");
1363 /* It might be a table */
1365 if (!lyxrc->ascii_roff_command.empty() &&
1366 lyxrc->ascii_roff_command != "none") {
1367 RoffAsciiTable(file, par);
1373 cells = par->table->columns;
1374 clen = new int [cells];
1375 memset(clen, 0, sizeof(int)*cells);
1376 for (i = 0, j = 0, h = 1; i < par->size(); ++i, ++h) {
1377 c = par->GetChar(i);
1378 if (c == LyXParagraph::META_INSET) {
1379 if ((inset = par->GetInset(i))) {
1383 WriteFSAlert(_("Error: Cannot open temporary file:"), fname1);
1386 inset->Latex(fp,-1);
1388 remove(fname1.c_str());
1390 } else if (c == LyXParagraph::META_NEWLINE) {
1394 j = (++j) % par->table->NumberOfCellsInRow(actcell);
1402 font1 = LyXFont(LyXFont::ALL_INHERIT);
1404 for (i = 0, actpos = 1; i < par->size(); ++i, ++actpos) {
1405 if (!i && !footnoteflag && !noparbreak){
1406 fprintf(file, "\n\n");
1407 for(j = 0; j<depth; j++)
1409 currlinelen = depth*2;
1411 case 0: /* Standart */
1412 case 4: /* (Sub)Paragraph */
1413 case 5: /* Description */
1415 case 6: /* Abstract */
1416 fprintf(file, "Abstract\n\n");
1418 case 7: /* Bibliography */
1420 fprintf(file, "References\n\n");
1425 fprintf(file, "%s ", par->labelstring.c_str());
1428 if (ltype_depth > depth) {
1429 for(j = ltype_depth-1; j>depth; j--)
1431 currlinelen += (ltype_depth-depth)*2;
1434 for(j = 0;j<cells;j++) {
1436 for(h = 0; h<(clen[j]+1); h++)
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 fprintf(file, "| ");
1451 font2 = par->GetFontSettings(i);
1452 if (font1.latex() != font2.latex()) {
1453 if (font2.latex() == LyXFont::OFF)
1461 c = par->GetChar(i);
1465 case LyXParagraph::META_INSET:
1466 if ((inset = par->GetInset(i))) {
1468 inset->Latex(file,-1);
1469 currlinelen += (ftell(file) - fpos);
1470 actpos += (ftell(file) - fpos) - 1;
1473 case LyXParagraph::META_NEWLINE:
1475 if (par->table->NumberOfCellsInRow(actcell) <= cell) {
1476 for(j = actpos;j<clen[cell-1];j++)
1478 fprintf(file, " |\n");
1479 for(j = 0; j<depth; j++)
1481 currlinelen = depth*2;
1482 if (ltype_depth > depth) {
1483 for(j = ltype_depth; j>depth; j--)
1485 currlinelen += (ltype_depth-depth)*2;
1487 for(j = 0;j<cells;j++) {
1489 for(h = 0; h<(clen[j]+1); h++)
1492 fprintf(file, "+\n");
1493 for(j = 0; j<depth; j++)
1495 currlinelen = depth*2;
1496 if (ltype_depth > depth) {
1497 for(j = ltype_depth; j>depth; j--)
1499 currlinelen += (ltype_depth-depth)*2;
1501 fprintf(file, "| ");
1504 for(j = actpos; j<clen[cell-1]; j++)
1506 fprintf(file, " | ");
1510 currlinelen = actpos = 0;
1512 fprintf(file, "\n");
1513 for(j = 0; j<depth; j++)
1515 currlinelen = depth*2;
1516 if (ltype_depth > depth) {
1517 for(j = ltype_depth; j>depth; j--)
1519 currlinelen += (ltype_depth-depth)*2;
1523 case LyXParagraph::META_HFILL:
1524 fprintf(file, "\t");
1526 case LyXParagraph::META_PROTECTED_SEPARATOR:
1530 fprintf(file, "\\");
1533 if (currlinelen > linelen - 10
1534 && c == ' ' && i + 2 < par->size()) {
1535 fprintf(file, "\n");
1536 for(j = 0; j < depth; ++j)
1538 currlinelen = depth * 2;
1539 if (ltype_depth > depth) {
1540 for(j = ltype_depth;
1543 currlinelen += (ltype_depth-depth)*2;
1545 } else if (c != '\0')
1546 fprintf(file, "%c", c);
1548 lyxerr.debug() << "writeAsciiFile: NULL char in structure." << endl;
1554 for(j = actpos;j<clen[cell-1];j++)
1556 fprintf(file, " |\n");
1557 for(j = 0; j<depth; j++)
1559 currlinelen = depth*2;
1560 if (ltype_depth > depth) {
1561 for(j = ltype_depth; j>depth; j--)
1563 currlinelen += (ltype_depth-depth)*2;
1565 for(j = 0;j<cells;j++) {
1567 for(h = 0; h<(clen[j]+1); h++)
1570 fprintf(file, "+\n");
1576 fprintf(file, "\n");
1580 void Buffer::makeLaTeXFile(string const & filename,
1581 string const & original_path,
1582 bool nice, bool only_body)
1584 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
1585 params.textclass = GetCurrentTextClass();
1586 niceFile = nice; // this will be used by Insetincludes.
1588 tex_code_break_column = lyxrc->ascii_linelen;
1590 LyXTextClass const & tclass =
1591 textclasslist.TextClass(params.textclass);
1593 FilePtr file(filename, FilePtr::write);
1595 WriteFSAlert(_("Error: Cannot write file:"), filename);
1599 // validate the buffer.
1600 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
1601 LaTeXFeatures features(tclass.numLayouts());
1603 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
1606 // The starting paragraph of the coming rows is the
1607 // first paragraph of the document. (Asger)
1608 texrow.start(paragraph, 0);
1610 string userName(getUserName());
1613 if (!only_body && nice) {
1614 LFile += "%% This LaTeX-file was created by <";
1615 LFile += userName + "> " + (char*)date();
1616 LFile += "%% LyX 1.0 (C) 1995-1999 by Matthias Ettrich and the LyX Team\n";
1617 LFile += "\n%% Do not edit this file unless you know what you are doing.\n";
1623 lyxerr.debug() << "lyx header finished" << endl;
1624 // There are a few differences between nice LaTeX and usual files:
1625 // usual is \batchmode, uses \listfiles and has a
1626 // special input@path to allow the including of figures
1627 // with either \input or \includegraphics (what figinsets do).
1628 // batchmode is not set if there is a tex_code_break_column.
1629 // In this case somebody is interested in the generated LaTeX,
1630 // so this is OK. input@path is set when the actual parameter
1631 // original_path is set. This is done for usual tex-file, but not
1632 // for nice-latex-file. (Matthias 250696)
1635 // code for usual, NOT nice-latex-file
1636 LFile += "\\batchmode\n"; // changed
1637 // from \nonstopmode
1639 // We don't need listfiles anymore
1640 //LFile += "\\listfiles\n";
1643 if (!original_path.empty()) {
1644 LFile += "\\makeatletter\n";
1646 LFile += "\\def\\input@path{{" + original_path
1649 LFile += "\\makeatother\n";
1653 LFile += "\\documentclass";
1655 string options; // the document class options.
1657 if (tokenPos(tclass.opt_fontsize(), '|', params.fontsize) >= 0) {
1658 // only write if existing in list (and not default)
1659 options += params.fontsize;
1664 if (!params.use_geometry &&
1665 (params.paperpackage == BufferParams::PACKAGE_NONE)) {
1666 switch (params.papersize) {
1667 case BufferParams::PAPER_A4PAPER:
1668 options += "a4paper,";
1670 case BufferParams::PAPER_USLETTER:
1671 options += "letterpaper,";
1673 case BufferParams::PAPER_A5PAPER:
1674 options += "a5paper,";
1676 case BufferParams::PAPER_B5PAPER:
1677 options += "b5paper,";
1679 case BufferParams::PAPER_EXECUTIVEPAPER:
1680 options += "executivepaper,";
1682 case BufferParams::PAPER_LEGALPAPER:
1683 options += "legalpaper,";
1689 if (params.sides != tclass.sides()) {
1690 if (params.sides == 2)
1691 options += "twoside,";
1693 options += "oneside,";
1697 if (params.columns != tclass.columns()) {
1698 if (params.columns == 2)
1699 options += "twocolumn,";
1701 options += "onecolumn,";
1704 if (!params.use_geometry && params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1705 options += "landscape,";
1707 // language should be a parameter to \documentclass
1708 if (params.language != "default") {
1709 options += params.language + ',';
1712 // the user-defined options
1713 if (!params.options.empty()) {
1714 options += params.options + ',';
1717 if (!options.empty()){
1718 options = strip(options, ',');
1725 LFile += textclasslist.LatexnameOfClass(params.textclass);
1728 // end of \documentclass defs
1730 // font selection must be done before loading fontenc.sty
1731 if (params.fonts != "default") {
1732 LFile += "\\usepackage{" + params.fonts + "}\n";
1735 // this one is not per buffer
1736 if (lyxrc->fontenc != "default") {
1737 LFile += "\\usepackage[" + lyxrc->fontenc
1741 if (params.inputenc != "default") {
1742 LFile += "\\usepackage[" + params.inputenc
1747 /* at the very beginning the text parameters */
1748 if (params.paperpackage != BufferParams::PACKAGE_NONE) {
1749 switch (params.paperpackage) {
1750 case BufferParams::PACKAGE_A4:
1751 LFile += "\\usepackage{a4}\n";
1754 case BufferParams::PACKAGE_A4WIDE:
1755 LFile += "\\usepackage{a4wide}\n";
1758 case BufferParams::PACKAGE_WIDEMARGINSA4:
1759 LFile += "\\usepackage[widemargins]{a4}\n";
1764 if (params.use_geometry) {
1765 LFile += "\\usepackage{geometry}\n";
1767 LFile += "\\geometry{verbose";
1768 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1769 LFile += ",landscape";
1770 switch (params.papersize2) {
1771 case BufferParams::VM_PAPER_CUSTOM:
1772 if (!params.paperwidth.empty())
1773 LFile += ",paperwidth= "
1774 + params.paperwidth;
1775 if (!params.paperheight.empty())
1776 LFile += ",paperheight= "
1777 + params.paperheight;
1779 case BufferParams::VM_PAPER_USLETTER:
1780 LFile += ",letterpaper";
1782 case BufferParams::VM_PAPER_USLEGAL:
1783 LFile += ",legalpaper";
1785 case BufferParams::VM_PAPER_USEXECUTIVE:
1786 LFile += ",executivepaper";
1788 case BufferParams::VM_PAPER_A3:
1789 LFile += ",a3paper";
1791 case BufferParams::VM_PAPER_A4:
1792 LFile += ",a4paper";
1794 case BufferParams::VM_PAPER_A5:
1795 LFile += ",a5paper";
1797 case BufferParams::VM_PAPER_B3:
1798 LFile += ",b3paper";
1800 case BufferParams::VM_PAPER_B4:
1801 LFile += ",b4paper";
1803 case BufferParams::VM_PAPER_B5:
1804 LFile += ",b5paper";
1807 // default papersize ie BufferParams::VM_PAPER_DEFAULT
1808 switch (lyxrc->default_papersize) {
1809 case BufferParams::PAPER_DEFAULT: // keep compiler happy
1810 case BufferParams::PAPER_USLETTER:
1811 LFile += ",letterpaper";
1813 case BufferParams::PAPER_LEGALPAPER:
1814 LFile += ",legalpaper";
1816 case BufferParams::PAPER_EXECUTIVEPAPER:
1817 LFile += ",executivepaper";
1819 case BufferParams::PAPER_A3PAPER:
1820 LFile += ",a3paper";
1822 case BufferParams::PAPER_A4PAPER:
1823 LFile += ",a4paper";
1825 case BufferParams::PAPER_A5PAPER:
1826 LFile += ",a5paper";
1828 case BufferParams::PAPER_B5PAPER:
1829 LFile += ",b5paper";
1833 if (!params.topmargin.empty())
1834 LFile += ",tmargin= " + params.topmargin;
1835 if (!params.bottommargin.empty())
1836 LFile += ",bmargin= " + params.bottommargin;
1837 if (!params.leftmargin.empty())
1838 LFile += ",lmargin= " + params.leftmargin;
1839 if (!params.rightmargin.empty())
1840 LFile += ",rmargin= " + params.rightmargin;
1841 if (!params.headheight.empty())
1842 LFile += ",headheight= " + params.headheight;
1843 if (!params.headsep.empty())
1844 LFile += ",headsep= " + params.headsep;
1845 if (!params.footskip.empty())
1846 LFile += ",footskip= " + params.footskip;
1850 if (params.use_amsmath
1851 && !prefixIs(textclasslist.LatexnameOfClass(params.textclass), "ams")) {
1852 LFile += "\\usepackage{amsmath}\n";
1855 if (tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle) >= 0) {
1856 if (params.pagestyle == "fancy") {
1857 LFile += "\\usepackage{fancyhdr}\n";
1860 LFile += "\\pagestyle{" + params.pagestyle + "}\n";
1864 // We try to load babel late, in case it interferes
1865 // with other packages.
1866 if (params.language != "default") {
1867 LFile += "\\usepackage{babel}\n";
1871 if (params.secnumdepth != tclass.secnumdepth()) {
1872 LFile += "\\setcounter{secnumdepth}{";
1873 LFile += tostr(params.secnumdepth);
1877 if (params.tocdepth != tclass.tocdepth()) {
1878 LFile += "\\setcounter{tocdepth}{";
1879 LFile += tostr(params.tocdepth);
1884 if (params.paragraph_separation) {
1885 switch (params.defskip.kind()) {
1886 case VSpace::SMALLSKIP:
1887 LFile += "\\setlength\\parskip{\\smallskipamount}\n";
1889 case VSpace::MEDSKIP:
1890 LFile += "\\setlength\\parskip{\\medskipamount}\n";
1892 case VSpace::BIGSKIP:
1893 LFile += "\\setlength\\parskip{\\bigskipamount}\n";
1895 case VSpace::LENGTH:
1896 LFile += "\\setlength\\parskip{"
1897 + params.defskip.length().asLatexString()
1900 default: // should never happen // Then delete it.
1901 LFile += "\\setlength\\parskip{\\medskipamount}\n";
1906 LFile += "\\setlength\\parindent{0pt}\n";
1910 // Write out what we've generated so far...and reset LFile
1911 fwrite(LFile.c_str(), sizeof(char), LFile.length(), file);
1914 // Now insert the LyX specific LaTeX commands...
1915 string preamble, tmppreamble;
1917 // The optional packages;
1918 preamble = features.getPackages(params);
1920 // this might be useful...
1921 preamble += "\n\\makeatletter\n\n";
1923 // Some macros LyX will need
1924 tmppreamble = features.getMacros(params);
1926 if (!tmppreamble.empty()) {
1927 preamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1928 "LyX specific LaTeX commands.\n"
1929 + tmppreamble + '\n';
1932 // the text class specific preamble
1933 tmppreamble = features.getTClassPreamble(params);
1934 if (!tmppreamble.empty()) {
1935 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1936 "Textclass specific LaTeX commands.\n"
1937 + tmppreamble + '\n';
1940 /* the user-defined preamble */
1941 if (!params.preamble.empty()) {
1942 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1943 "User specified LaTeX commands.\n"
1944 + params.preamble + '\n';
1947 preamble += "\\makeatother\n\n";
1949 // Itemize bullet settings need to be last in case the user
1950 // defines their own bullets that use a package included
1951 // in the user-defined preamble -- ARRae
1952 // Actually it has to be done much later than that
1953 // since some packages like frenchb make modifications
1954 // at \begin{document} time -- JMarc
1956 for (int i = 0; i < 4; ++i) {
1957 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
1958 if (bullets_def.empty())
1959 bullets_def="\\AtBeginDocument{\n";
1960 bullets_def += " \\renewcommand{\\labelitemi";
1962 // `i' is one less than the item to modify
1969 bullets_def += "ii";
1975 bullets_def += "}{" +
1976 params.user_defined_bullets[i].getText()
1981 if (!bullets_def.empty())
1982 preamble += bullets_def + "}\n\n";
1984 for (int j = countChar(preamble, '\n'); j-- ;) {
1988 // A bit faster than printing a char at a time I think.
1989 fwrite(preamble.c_str(), sizeof(char),
1990 preamble.length(), file);
1993 LFile += "\\begin{document}\n\n";
1997 lyxerr.debug() << "preamble finished, now the body." << endl;
1999 bool was_title = false;
2000 bool already_title = false;
2006 LyXParagraph * par = paragraph;
2012 lyxerr[Debug::LATEX] << "Error in MakeLateXFile."
2014 LyXLayout const & layout = textclasslist.Style(params.textclass,
2017 if (layout.intitle) {
2018 if (already_title) {
2019 lyxerr <<"Error in MakeLatexFile: You"
2020 " should not mix title layouts"
2021 " with normal ones." << endl;
2024 } else if (was_title && !already_title) {
2025 LFile += "\\maketitle\n";
2027 already_title = true;
2030 // We are at depth 0 so we can just use
2031 // ordinary \footnote{} generation
2032 // flag this with ftcount
2034 if (layout.isEnvironment()
2035 || par->pextra_type != LyXParagraph::PEXTRA_NONE) {
2036 par = par->TeXEnvironment(LFile, texrow,
2037 ftnote, ft_texrow, ftcount);
2039 par = par->TeXOnePar(LFile, texrow,
2040 ftnote, ft_texrow, ftcount);
2043 // Write out what we've generated...and reset LFile
2046 LFile += "\\addtocounter{footnote}{-";
2047 LFile += tostr(ftcount - 1);
2051 texrow += ft_texrow;
2056 if (loop_count == 2) {
2057 // fwrite()ing every second time through the loop
2058 // gains a few extra % of speed; going higher than
2059 // 2 will slow things down again. I'll look at
2060 // LFile.length() in a future revision. ARRae
2061 fwrite(LFile.c_str(), sizeof(char),
2062 LFile.length(), file);
2068 // It might be that we only have a title in this document
2069 if (was_title && !already_title) {
2070 LFile += "\\maketitle\n";
2075 LFile += "\\end{document}\n";
2078 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
2080 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
2084 // Just to be sure. (Asger)
2087 // Write out what we've generated...and reset LFile
2088 fwrite(LFile.c_str(), sizeof(char), LFile.length(), file);
2091 // tex_code_break_column's value is used to decide
2092 // if we are in batchmode or not (within mathed_write()
2093 // in math_write.C) so we must set it to a non-zero
2094 // value when we leave otherwise we save incorrect .lyx files.
2095 tex_code_break_column = lyxrc->ascii_linelen;
2098 WriteFSAlert(_("Error! Could not close file properly:"), filename);
2100 lyxerr.debug() << "Finished making latex file." << endl;
2104 bool Buffer::isLatex() const
2106 return textclasslist.TextClass(params.textclass).outputType() == LATEX;
2110 bool Buffer::isLinuxDoc() const
2112 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC;
2116 bool Buffer::isLiterate() const
2118 return textclasslist.TextClass(params.textclass).outputType() == LITERATE;
2122 bool Buffer::isDocBook() const
2124 return textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2128 bool Buffer::isSGML() const
2130 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC ||
2131 textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2135 void Buffer::sgmlOpenTag(FILE * file, int depth, string const & latexname) const
2137 static char * space[] = {" "," ", " ", " ", " ", " ", " ",
2138 " ", " ", " ", " "};
2140 fprintf(file, "%s<%s>\n", space[depth], latexname.c_str());
2144 void Buffer::sgmlCloseTag(FILE * file, int depth,
2145 string const & latexname) const
2147 static char * space[] = {" ", " ", " ", " ", " ", " ", " ",
2148 " ", " ", " ", " "};
2150 fprintf(file, "%s</%s>\n", space[depth], latexname.c_str());
2154 void Buffer::makeLinuxDocFile(string const & filename, int column)
2156 LyXParagraph * par = paragraph;
2158 string top_element = textclasslist.LatexnameOfClass(params.textclass);
2159 string environment_stack[10];
2162 int depth = 0; /* paragraph depth */
2164 FilePtr file(filename, FilePtr::write);
2165 tex_code_break_column = column;
2168 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), filename);
2174 if (params.preamble.empty()) {
2175 fprintf(file, "<!doctype linuxdoc system>\n\n");
2178 fprintf(file, "<!doctype linuxdoc system \n [ %s \n]>\n\n",
2179 params.preamble.c_str() );
2182 string userName(getUserName());
2184 "<!-- LinuxDoc file was created by LyX 1.0 (C) 1995-1999 ");
2185 fprintf(file, "by <%s> %s -->\n", userName.c_str(), (char *)date());
2187 if(params.options.empty())
2188 sgmlOpenTag(file, 0, top_element);
2190 string top = top_element;
2192 top += params.options;
2193 sgmlOpenTag(file, 0, top);
2197 int desc_on = 0; /* description mode*/
2198 LyXLayout const & style =
2199 textclasslist.Style(GetCurrentTextClass(),
2201 par->AutoDeleteInsets();
2203 /* treat <toc> as a special case for compatibility with old code */
2204 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2205 Inset *inset = par->GetInset(0);
2206 char lyx_code = inset->LyxCode();
2207 if (lyx_code == Inset::TOC_CODE){
2208 string temp = "toc";
2209 sgmlOpenTag(file, depth, temp);
2212 linuxDocHandleFootnote(file, par, depth);
2217 /* environment tag closing */
2218 for( ;depth > par->depth; depth--) {
2219 sgmlCloseTag(file, depth, environment_stack[depth]);
2220 environment_stack[depth].clear();
2223 /* write opening SGML tags */
2224 switch(style.latextype) {
2225 case LATEX_PARAGRAPH:
2226 if(depth == par->depth
2227 && !environment_stack[depth].empty()) {
2228 sgmlCloseTag(file, depth, environment_stack[depth]);
2229 environment_stack[depth].clear();
2233 fprintf(file, "</p>");
2235 sgmlOpenTag(file, depth, style.latexname());
2240 LinuxDocError(par, 0, _("Error : Wrong depth for LatexType Command.\n"));
2242 if (!environment_stack[depth].empty()){
2243 sgmlCloseTag(file, depth, environment_stack[depth]);
2244 fprintf(file, "</p>");
2247 environment_stack[depth].clear();
2248 sgmlOpenTag(file, depth, style.latexname());
2251 case LATEX_ENVIRONMENT:
2252 case LATEX_ITEM_ENVIRONMENT:
2253 if(depth == par->depth
2254 && environment_stack[depth] != style.latexname()
2255 && !environment_stack[depth].empty()) {
2257 sgmlCloseTag(file, depth,
2258 environment_stack[depth]);
2259 environment_stack[depth].clear();
2261 if (depth < par->depth) {
2263 environment_stack[depth].clear();
2265 if (environment_stack[depth] != style.latexname()) {
2268 sgmlOpenTag(file, depth, temp);
2270 environment_stack[depth] = style.latexname();
2271 sgmlOpenTag(file, depth, environment_stack[depth]);
2273 if(style.latextype == LATEX_ENVIRONMENT) break;
2275 desc_on = (style.labeltype == LABEL_MANUAL);
2282 sgmlOpenTag(file, depth+1, item_name);
2285 sgmlOpenTag(file, depth, style.latexname());
2290 SimpleLinuxDocOnePar(file, par, desc_on, depth);
2293 linuxDocHandleFootnote(file, par, depth);
2295 while(par && par->IsDummy());
2297 fprintf(file, "\n");
2298 /* write closing SGML tags */
2299 switch(style.latextype) {
2301 case LATEX_ENVIRONMENT:
2302 case LATEX_ITEM_ENVIRONMENT:
2305 sgmlCloseTag(file, depth, style.latexname());
2310 /* Close open tags */
2311 for(;depth>0;depth--)
2312 sgmlCloseTag(file, depth, environment_stack[depth]);
2314 if(!environment_stack[depth].empty())
2315 sgmlCloseTag(file, depth, environment_stack[depth]);
2317 fprintf(file, "\n\n");
2318 sgmlCloseTag(file, 0, top_element);
2321 WriteFSAlert(_("Error! Could not close file properly:"),
2327 void Buffer::linuxDocHandleFootnote(FILE * file, LyXParagraph * & par,
2330 string tag = "footnote";
2332 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2333 sgmlOpenTag(file, depth+1, tag);
2334 SimpleLinuxDocOnePar(file, par, 0, depth+1);
2335 sgmlCloseTag(file, depth+1, tag);
2340 void Buffer::DocBookHandleCaption(FILE * file, string & inner_tag,
2341 int const depth, int desc_on,
2342 LyXParagraph * & par)
2344 LyXParagraph * tpar = par;
2345 string tmp_par, extra_par;
2346 while (tpar && (tpar->footnoteflag != LyXParagraph::NO_FOOTNOTE) &&
2347 (tpar->layout != textclasslist.NumberOfLayout(params.textclass, "Caption").second))
2350 tpar->layout == textclasslist.NumberOfLayout(params.textclass,
2351 "Caption").second) {
2352 sgmlOpenTag(file, depth+1, inner_tag);
2353 SimpleDocBookOnePar(tmp_par, extra_par, tpar, desc_on, depth+2);
2354 tmp_par = strip(tmp_par);
2355 tmp_par = frontStrip(tmp_par);
2356 fprintf(file, "%s", tmp_par.c_str());
2357 sgmlCloseTag(file, depth+1, inner_tag);
2358 if(!extra_par.empty())
2359 fprintf(file, "%s", extra_par.c_str());
2363 void Buffer::DocBookHandleFootnote(FILE * file, LyXParagraph * & par,
2366 string tag, inner_tag;
2367 string tmp_par, extra_par;
2368 bool inner_span = false;
2371 // This is not how I like to see enums. They should not be anonymous
2372 // and variables of its type should not be declared right after the
2373 // last brace. (Lgb)
2380 } last = NO_ONE, present = FOOTNOTE_LIKE;
2382 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2383 if(last == present) {
2385 if(!tmp_par.empty()) {
2386 fprintf(file, "%s", tmp_par.c_str());
2388 sgmlCloseTag(file, depth+1, inner_tag);
2389 sgmlOpenTag(file, depth+1, inner_tag);
2393 fprintf(file, "\n");
2395 fprintf(file, "%s", tmp_par.c_str());
2396 if(!inner_tag.empty()) sgmlCloseTag(file, depth+1, inner_tag);
2397 if(!extra_par.empty()) fprintf(file, "%s", extra_par.c_str());
2398 if(!tag.empty()) sgmlCloseTag(file, depth, tag);
2401 switch (par->footnotekind) {
2402 case LyXParagraph::FOOTNOTE:
2403 case LyXParagraph::ALGORITHM:
2406 present = FOOTNOTE_LIKE;
2409 case LyXParagraph::MARGIN:
2412 present = MARGIN_LIKE;
2415 case LyXParagraph::FIG:
2416 case LyXParagraph::WIDE_FIG:
2418 inner_tag = "title";
2422 case LyXParagraph::TAB:
2423 case LyXParagraph::WIDE_TAB:
2425 inner_tag = "title";
2430 sgmlOpenTag(file, depth, tag);
2431 if ((present == TAB_LIKE) || (present == FIG_LIKE)) {
2432 DocBookHandleCaption(file, inner_tag, depth,
2436 sgmlOpenTag(file, depth+1, inner_tag);
2439 // ignore all caption here, we processed them above!!!
2440 if (par->layout != textclasslist.NumberOfLayout(params.textclass,
2441 "Caption").second) {
2442 SimpleDocBookOnePar(tmp_par, extra_par, par,
2445 tmp_par = frontStrip(strip(tmp_par));
2450 fprintf(file, "%s", tmp_par.c_str());
2451 if(!inner_tag.empty()) sgmlCloseTag(file, depth+1, inner_tag);
2452 if(!extra_par.empty()) fprintf(file, "%s", extra_par.c_str());
2453 if(!tag.empty()) sgmlCloseTag(file, depth, tag);
2458 /* push a tag in a style stack */
2459 void Buffer::push_tag(FILE * file, char const * tag,
2460 int & pos, char stack[5][3])
2464 /* pop all previous tags */
2465 for (j = pos; j >= 0; j--)
2466 fprintf(file, "</%s>", stack[j]);
2469 sprintf(stack[++pos], "%s", tag);
2472 for (j= 0; j<= pos; j++)
2473 fprintf(file, "<%s>", stack[j]);
2477 // pop a tag from a style stack
2478 void Buffer::pop_tag(FILE * file, char const * tag,
2479 int & pos, char stack[5][3])
2483 // pop all tags till specified one
2484 for (j= pos; (j>= 0) && (strcmp(stack[j], tag)); j--)
2485 fprintf(file, "</%s>", stack[j]);
2488 fprintf(file, "</%s>", tag);
2490 // push all tags, but the specified one
2491 for (j= j+1; j<= pos; j++) {
2492 fprintf(file, "<%s>", stack[j]);
2493 strcpy(stack[j-1], stack[j]);
2499 /* handle internal paragraph parsing -- layout already processed */
2501 // checks, if newcol chars should be put into this line
2502 // writes newline, if necessary.
2504 void linux_doc_line_break(FILE * file, unsigned int & colcount,
2505 const unsigned int newcol)
2508 if (colcount > lyxrc->ascii_linelen) {
2509 fprintf(file, "\n");
2510 colcount = newcol; // assume write after this call
2515 void Buffer::SimpleLinuxDocOnePar(FILE * file, LyXParagraph * par,
2516 int desc_on, int const depth)
2518 LyXFont font1, font2;
2521 LyXParagraph::size_type main_body;
2523 LyXLayout const & style = textclasslist.Style(params.textclass,
2526 char family_type = 0; // family font flag
2527 bool is_bold = false; // series font flag
2528 char shape_type = 0; // shape font flag
2529 bool is_em = false; // emphasis (italic) font flag
2531 int stack_num = -1; // style stack position
2532 char stack[5][3]; // style stack
2533 unsigned int char_line_count = 5; // Heuristic choice ;-)
2535 if (style.labeltype != LABEL_MANUAL)
2538 main_body = par->BeginningOfMainBody();
2540 /* gets paragraph main font */
2542 font1 = style.labelfont;
2547 /* parsing main loop */
2548 for (LyXParagraph::size_type i = 0;
2549 i < par->size(); ++i) {
2551 /* handle quote tag */
2552 if (i == main_body && !par->IsDummy()) {
2557 font2 = par->getFont(i);
2559 if (font1.family() != font2.family()) {
2560 switch(family_type) {
2562 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2563 push_tag(file, "tt", stack_num, stack);
2566 else if (font2.family() == LyXFont::SANS_FAMILY) {
2567 push_tag(file, "sf", stack_num, stack);
2572 pop_tag(file, "tt", stack_num, stack);
2573 if (font2.family() == LyXFont::SANS_FAMILY) {
2574 push_tag(file, "sf", stack_num, stack);
2582 pop_tag(file, "sf", stack_num, stack);
2583 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2584 push_tag(file, "tt", stack_num, stack);
2593 /* handle bold face */
2594 if (font1.series() != font2.series()) {
2595 if (font2.series() == LyXFont::BOLD_SERIES) {
2596 push_tag(file, "bf", stack_num, stack);
2600 pop_tag(file, "bf", stack_num, stack);
2605 /* handle italic and slanted fonts */
2606 if (font1.shape() != font2.shape()) {
2607 switch(shape_type) {
2609 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2610 push_tag(file, "it", stack_num, stack);
2613 else if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2614 push_tag(file, "sl", stack_num, stack);
2619 pop_tag(file, "it", stack_num, stack);
2620 if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2621 push_tag(file, "sl", stack_num, stack);
2629 pop_tag(file, "sl", stack_num, stack);
2630 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2631 push_tag(file, "it", stack_num, stack);
2639 /* handle <em> tag */
2640 if (font1.emph() != font2.emph()) {
2641 if (font2.emph() == LyXFont::ON) {
2642 push_tag(file, "em", stack_num, stack);
2645 pop_tag(file, "em", stack_num, stack);
2650 c = par->GetChar(i);
2652 if (font2.latex() == LyXFont::ON) {
2653 // "TeX"-Mode on == > SGML-Mode on.
2655 fprintf(file, "%c", c); // see LaTeX-Generation...
2657 } else if (c == LyXParagraph::META_INSET) {
2658 inset = par->GetInset(i);
2660 inset->Linuxdoc(tmp_out);
2661 fprintf(file, "%s", tmp_out.c_str());
2665 if (par->linuxDocConvertChar(c, sgml_string)
2666 && !style.free_spacing) { // in freespacing
2668 // non-breaking characters
2672 linux_doc_line_break(file, char_line_count, 6);
2673 fprintf(file, "</tag>");
2677 linux_doc_line_break(file, char_line_count, 1);
2678 fprintf(file, "%c", c);
2682 fprintf(file, "%s", sgml_string.c_str());
2683 char_line_count += sgml_string.length();
2689 /* needed if there is an optional argument but no contents */
2690 if (main_body > 0 && main_body == par->size()) {
2694 /* pop all defined Styles */
2695 for (j = stack_num; j >= 0; j--) {
2696 linux_doc_line_break(file,
2698 3+strlen(stack[j]));
2699 fprintf(file, "</%s>", stack[j]);
2702 /* resets description flag correctly */
2705 /* <tag> not closed... */
2706 linux_doc_line_break(file, char_line_count, 6);
2707 fprintf(file, "</tag>");
2710 /* fprintf(file, "</p>");*/
2716 /* print an error message */
2717 void Buffer::LinuxDocError(LyXParagraph * par, int pos,
2718 char const * message)
2720 InsetError * new_inset;
2722 /* insert an error marker in text */
2723 new_inset = new InsetError(message);
2724 par->InsertChar(pos, LyXParagraph::META_INSET);
2725 par->InsertInset(pos, new_inset);
2728 // This constant defines the maximum number of
2729 // environment layouts that can be nesteded.
2730 // The same applies for command layouts.
2731 // These values should be more than enough.
2732 // José Matos (1999/07/22)
2734 enum { MAX_NEST_LEVEL = 25};
2736 void Buffer::makeDocBookFile(string const & filename, int column)
2738 LyXParagraph * par = paragraph;
2740 string top_element= textclasslist.LatexnameOfClass(params.textclass);
2741 string environment_stack[MAX_NEST_LEVEL];
2742 string environment_inner[MAX_NEST_LEVEL];
2743 string command_stack[MAX_NEST_LEVEL];
2744 bool command_flag= false;
2745 int command_depth= 0, command_base= 0, cmd_depth= 0;
2747 string item_name, command_name;
2748 string c_depth, c_params, tmps;
2750 int depth= 0; /* paragraph depth */
2752 FilePtr file(filename, FilePtr::write);
2753 tex_code_break_column = column;
2756 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), filename);
2764 "<!doctype %s public \"-//OASIS//DTD DocBook V3.1//EN\"",
2765 top_element.c_str());
2767 if (params.preamble.empty())
2768 fprintf(file, ">\n\n");
2770 fprintf(file, "\n [ %s \n]>\n\n", params.preamble.c_str() );
2772 string userName(getUserName());
2774 "<!-- DocBook file was created by LyX 1.0 (C) 1995-1999\n");
2775 fprintf(file, "by <%s> %s -->\n", userName.c_str(), (char *)date());
2777 if(params.options.empty())
2778 sgmlOpenTag(file, 0, top_element);
2780 string top = top_element;
2782 top += params.options;
2783 sgmlOpenTag(file, 0, top);
2787 int desc_on= 0; /* description mode*/
2788 LyXLayout const & style = textclasslist.Style(GetCurrentTextClass(),
2790 par->AutoDeleteInsets();
2792 /* environment tag closing */
2793 for( ;depth > par->depth; depth--) {
2794 if(environment_inner[depth] != "!-- --") {
2795 item_name= "listitem";
2796 sgmlCloseTag(file, command_depth+depth,
2798 if( environment_inner[depth] == "varlistentry")
2799 sgmlCloseTag(file, depth+command_depth,
2800 environment_inner[depth]);
2802 sgmlCloseTag(file, depth+command_depth,
2803 environment_stack[depth]);
2804 environment_stack[depth].clear();
2805 environment_inner[depth].clear();
2808 if(depth == par->depth
2809 && environment_stack[depth] != style.latexname()
2810 && !environment_stack[depth].empty()) {
2811 if(environment_inner[depth] != "!-- --") {
2812 item_name= "listitem";
2813 sgmlCloseTag(file, command_depth+depth,
2815 if( environment_inner[depth] == "varlistentry")
2816 sgmlCloseTag(file, depth+command_depth,
2817 environment_inner[depth]);
2820 sgmlCloseTag(file, depth+command_depth,
2821 environment_stack[depth]);
2823 environment_stack[depth].clear();
2824 environment_inner[depth].clear();
2827 // Write opening SGML tags.
2828 switch(style.latextype) {
2829 case LATEX_PARAGRAPH:
2830 if(style.latexname() != "dummy")
2831 sgmlOpenTag(file, depth+command_depth,
2837 LinuxDocError(par, 0,
2838 _("Error : Wrong depth for "
2839 "LatexType Command.\n"));
2841 command_name = style.latexname();
2843 tmps = style.latexparam();
2844 c_params = split(tmps, c_depth,'|');
2846 cmd_depth= atoi(c_depth.c_str());
2849 if(cmd_depth<command_base) {
2850 for(int j = command_depth;
2851 j >= command_base; j--)
2852 if(!command_stack[j].empty())
2853 sgmlCloseTag(file, j, command_stack[j]);
2854 command_depth= command_base= cmd_depth;
2856 else if(cmd_depth<= command_depth) {
2857 for(int j= command_depth;
2858 j >= cmd_depth; j--)
2860 if(!command_stack[j].empty())
2861 sgmlCloseTag(file, j, command_stack[j]);
2862 command_depth= cmd_depth;
2865 command_depth= cmd_depth;
2868 command_depth = command_base = cmd_depth;
2869 command_flag = true;
2871 command_stack[command_depth]= command_name;
2873 // treat label as a special case for
2874 // more WYSIWYM handling.
2875 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2876 Inset *inset = par->GetInset(0);
2877 char lyx_code = inset->LyxCode();
2878 if (lyx_code == Inset::LABEL_CODE){
2879 command_name+= " id=\"";
2880 command_name+= ((InsetCommand *) inset)->getContents();
2881 command_name+= "\"";
2886 sgmlOpenTag(file, depth+command_depth, command_name);
2888 sgmlOpenTag(file, depth+1+command_depth, item_name);
2891 case LATEX_ENVIRONMENT:
2892 case LATEX_ITEM_ENVIRONMENT:
2893 if (depth < par->depth) {
2895 environment_stack[depth].clear();
2898 if (environment_stack[depth] != style.latexname()) {
2899 environment_stack[depth]= style.latexname();
2900 environment_inner[depth]= "!-- --";
2901 sgmlOpenTag(file, depth + command_depth,
2902 environment_stack[depth]);
2904 if(environment_inner[depth] != "!-- --") {
2905 item_name= "listitem";
2907 command_depth + depth,
2909 if (environment_inner[depth] == "varlistentry")
2911 depth+command_depth,
2912 environment_inner[depth]);
2916 if(style.latextype == LATEX_ENVIRONMENT) {
2917 if(!style.latexparam().empty())
2918 sgmlOpenTag(file, depth+command_depth,
2919 style.latexparam());
2923 desc_on = (style.labeltype == LABEL_MANUAL);
2926 environment_inner[depth]= "varlistentry";
2928 environment_inner[depth]= "listitem";
2930 sgmlOpenTag(file, depth+1+command_depth,
2931 environment_inner[depth]);
2935 sgmlOpenTag(file, depth+1+command_depth,
2940 sgmlOpenTag(file, depth+1+command_depth,
2945 sgmlOpenTag(file, depth + command_depth,
2951 string tmp_par, extra_par;
2953 SimpleDocBookOnePar(tmp_par, extra_par, par, desc_on,
2954 depth+1+command_depth);
2955 fprintf(file, "%s", tmp_par.c_str());
2958 DocBookHandleFootnote(file, par, depth+1+command_depth);
2960 while(par && par->IsDummy());
2963 /* write closing SGML tags */
2964 switch(style.latextype) {
2967 sgmlCloseTag(file, depth + command_depth, end_tag);
2969 case LATEX_ENVIRONMENT:
2970 if(!style.latexparam().empty())
2971 sgmlCloseTag(file, depth + command_depth,
2972 style.latexparam());
2974 case LATEX_ITEM_ENVIRONMENT:
2975 if(desc_on == 1) break;
2977 sgmlCloseTag(file, depth+1+command_depth, end_tag);
2979 case LATEX_PARAGRAPH:
2980 if(style.latexname() != "dummy")
2981 sgmlCloseTag(file, depth + command_depth,
2985 sgmlCloseTag(file, depth+command_depth,
2992 for(;depth>= 0;depth--) {
2993 if(!environment_stack[depth].empty()) {
2994 if(environment_inner[depth] != "!-- --") {
2995 item_name= "listitem";
2996 sgmlCloseTag(file, command_depth+depth,
2998 if( environment_inner[depth] == "varlistentry")
2999 sgmlCloseTag(file, depth+command_depth,
3000 environment_inner[depth]);
3003 sgmlCloseTag(file, depth+command_depth,
3004 environment_stack[depth]);
3008 for(int j= command_depth;j>= command_base;j--)
3009 if(!command_stack[j].empty())
3010 sgmlCloseTag(file, j, command_stack[j]);
3012 fprintf(file, "\n\n");
3013 sgmlCloseTag(file, 0, top_element);
3016 WriteFSAlert(_("Error! Could not close file properly:"),
3022 void Buffer::SimpleDocBookOnePar(string & file, string & extra,
3023 LyXParagraph * par, int & desc_on,
3027 par->SimpleDocBookOneTablePar(file, extra, desc_on, depth);
3030 LyXFont font1, font2;
3033 LyXParagraph::size_type main_body;
3035 string emph= "emphasis";
3036 bool emph_flag= false;
3037 int char_line_count= 0;
3039 LyXLayout const & style = textclasslist.Style(params.textclass,
3042 if (style.labeltype != LABEL_MANUAL)
3045 main_body = par->BeginningOfMainBody();
3047 /* gets paragraph main font */
3049 font1 = style.labelfont;
3053 char_line_count = depth;
3054 if(!style.free_spacing)
3055 for (j= 0;j< depth;j++)
3058 /* parsing main loop */
3059 for (LyXParagraph::size_type i = 0;
3060 i < par->size(); ++i) {
3061 font2 = par->getFont(i);
3063 /* handle <emphasis> tag */
3064 if (font1.emph() != font2.emph() && i) {
3065 if (font2.emph() == LyXFont::ON) {
3066 file += "<emphasis>";
3069 file += "</emphasis>";
3074 c = par->GetChar(i);
3076 if (c == LyXParagraph::META_INSET) {
3077 inset = par->GetInset(i);
3079 inset->DocBook(tmp_out);
3081 // This code needs some explanation:
3082 // Two insets are treated specially
3083 // label if it is the first element in a command paragraph
3085 // graphics inside tables or figure floats can't go on
3086 // title (the equivalente in latex for this case is caption
3087 // and title should come first
3090 if(desc_on!= 3 || i!= 0) {
3091 if(tmp_out[0] == '@') {
3093 extra += frontStrip(tmp_out, '@');
3095 file += frontStrip(tmp_out, '@');
3100 } else if (font2.latex() == LyXFont::ON) {
3101 // "TeX"-Mode on ==> SGML-Mode on.
3108 if (par->linuxDocConvertChar(c, sgml_string)
3109 && !style.free_spacing) { // in freespacing
3111 // non-breaking characters
3116 file += "</term><listitem><para>";
3124 file += sgml_string;
3130 /* needed if there is an optional argument but no contents */
3131 if (main_body > 0 && main_body == par->size()) {
3135 file += "</emphasis>";
3138 /* resets description flag correctly */
3141 /* <term> not closed... */
3149 bool Buffer::removeAutoInsets()
3151 LyXParagraph *par = paragraph;
3153 LyXCursor cursor = text->cursor;
3154 LyXCursor tmpcursor = cursor;
3155 cursor.par = tmpcursor.par->ParFromPos(tmpcursor.pos);
3156 cursor.pos = tmpcursor.par->PositionInParFromPos(tmpcursor.pos);
3160 if (par->AutoDeleteInsets()){
3162 if (par->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE){
3163 /* this is possible now, since SetCursor takes
3164 care about footnotes */
3165 text->SetCursorIntern(par, 0);
3166 text->RedoParagraphs(text->cursor, text->cursor.par->Next());
3167 text->FullRebreak();
3172 /* avoid forbidden cursor positions caused by error removing */
3173 if (cursor.pos > cursor.par->Last())
3174 cursor.pos = cursor.par->Last();
3175 text->SetCursorIntern(cursor.par, cursor.pos);
3181 int Buffer::runLaTeX()
3183 if (!text) return 0;
3187 // get LaTeX-Filename
3188 string name = SpaceLess(ChangeExtension (filename, ".tex", true));
3190 string path = OnlyPath(filename);
3192 string org_path = path;
3193 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
3197 Path p(path); // path to LaTeX file
3198 users->owner()->getMiniBuffer()->Set(_("Running LaTeX..."));
3200 // Remove all error insets
3201 bool a = removeAutoInsets();
3203 // Always generate the LaTeX file
3204 makeLaTeXFile(name, org_path, false);
3207 // do the LaTex run(s)
3209 LaTeX latex(lyxrc->latex_command, name, filepath);
3210 int res = latex.run(terr,
3211 users->owner()->getMiniBuffer()); // running latex
3213 // check return value from latex.run().
3214 if ((res & LaTeX::NO_LOGFILE)) {
3215 WriteAlert(_("LaTeX did not work!"),
3216 _("Missing log file:"), name);
3217 } else if ((res & LaTeX::ERRORS)) {
3218 users->owner()->getMiniBuffer()->Set(_("Done"));
3219 // Insert all errors as errors boxes
3222 // Dvi should also be kept dirty if the latex run
3223 // ends up with errors. However it should be possible
3224 // to view a dirty dvi too.
3226 //no errors or any other things to think about so:
3227 users->owner()->getMiniBuffer()->Set(_("Done"));
3231 // if we removed error insets before we ran LaTeX or if we inserted
3232 // error insets after we ran LaTeX this must be run:
3233 if (a || (res & LaTeX::ERRORS)){
3236 users->updateScrollbar();
3240 return latex.getNumErrors();
3244 int Buffer::runLiterate()
3246 if (!text) return 0;
3250 // get LaTeX-Filename
3251 string name = SpaceLess(ChangeExtension (filename, ".tex", true));
3252 // get Literate-Filename
3253 string lit_name = SpaceLess(ChangeExtension (filename, lyxrc->literate_extension, true));
3255 string path = OnlyPath(filename);
3257 string org_path = path;
3258 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
3262 Path p(path); // path to Literate file
3263 users->owner()->getMiniBuffer()->Set(_("Running Literate..."));
3265 // Remove all error insets
3266 bool a = removeAutoInsets();
3268 // generate the Literate file if necessary
3269 if (!isDviClean() || a) {
3270 makeLaTeXFile(lit_name, org_path, false);
3274 Literate literate(lyxrc->latex_command, name, filepath,
3276 lyxrc->literate_command, lyxrc->literate_error_filter,
3277 lyxrc->build_command, lyxrc->build_error_filter);
3279 int res = literate.weave(terr, users->owner()->getMiniBuffer());
3281 // check return value from literate.weave().
3282 if ((res & Literate::NO_LOGFILE)) {
3283 WriteAlert(_("Literate command did not work!"),
3284 _("Missing log file:"), name);
3285 } else if ((res & Literate::ERRORS)) {
3286 users->owner()->getMiniBuffer()->Set(_("Done"));
3287 // Insert all errors as errors boxes
3290 // Dvi should also be kept dirty if the latex run
3291 // ends up with errors. However it should be possible
3292 // to view a dirty dvi too.
3294 //no errors or any other things to think about so:
3295 users->owner()->getMiniBuffer()->Set(_("Done"));
3299 // if we removed error insets before we ran LaTeX or if we inserted
3300 // error insets after we ran LaTeX this must be run:
3301 if (a || (res & Literate::ERRORS)){
3304 users->updateScrollbar();
3308 return literate.getNumErrors();
3312 int Buffer::buildProgram()
3314 if (!text) return 0;
3318 // get LaTeX-Filename
3319 string name = SpaceLess(ChangeExtension (filename, ".tex", true));
3320 // get Literate-Filename
3321 string lit_name = SpaceLess(ChangeExtension (filename, lyxrc->literate_extension, true));
3323 string path = OnlyPath(filename);
3325 string org_path = path;
3326 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
3330 Path p(path); // path to Literate file
3331 users->owner()->getMiniBuffer()->Set(_("Building Program..."));
3333 // Remove all error insets
3334 bool a = removeAutoInsets();
3336 // generate the LaTeX file if necessary
3337 if (!isNwClean() || a) {
3338 makeLaTeXFile(lit_name, org_path, false);
3342 Literate literate(lyxrc->latex_command, name, filepath,
3344 lyxrc->literate_command, lyxrc->literate_error_filter,
3345 lyxrc->build_command, lyxrc->build_error_filter);
3347 int res = literate.build(terr, users->owner()->getMiniBuffer());
3349 // check return value from literate.build().
3350 if ((res & Literate::NO_LOGFILE)) {
3351 WriteAlert(_("Build did not work!"),
3352 _("Missing log file:"), name);
3353 } else if ((res & Literate::ERRORS)) {
3354 users->owner()->getMiniBuffer()->Set(_("Done"));
3355 // Insert all errors as errors boxes
3358 // Literate files should also be kept dirty if the literate
3359 // command run ends up with errors.
3361 //no errors or any other things to think about so:
3362 users->owner()->getMiniBuffer()->Set(_("Done"));
3366 // if we removed error insets before we ran Literate/Build or if we inserted
3367 // error insets after we ran Literate/Build this must be run:
3368 if (a || (res & Literate::ERRORS)){
3371 users->updateScrollbar();
3375 return literate.getNumErrors();
3379 // This should be enabled when the Chktex class is implemented. (Asger)
3380 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
3381 // Other flags: -wall -v0 -x
3382 int Buffer::runChktex()
3384 if (!text) return 0;
3388 // get LaTeX-Filename
3389 string name = SpaceLess(ChangeExtension (filename, ".tex", true));
3390 string path = OnlyPath(filename);
3392 string org_path = path;
3393 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
3397 Path p(path); // path to LaTeX file
3398 users->owner()->getMiniBuffer()->Set(_("Running chktex..."));
3400 // Remove all error insets
3401 bool a = removeAutoInsets();
3403 // Generate the LaTeX file if neccessary
3404 if (!isDviClean() || a) {
3405 makeLaTeXFile(name, org_path, false);
3410 Chktex chktex(lyxrc->chktex_command, name, filepath);
3411 int res = chktex.run(terr); // run chktex
3414 WriteAlert(_("chktex did not work!"),
3415 _("Could not run with file:"), name);
3416 } else if (res > 0) {
3417 // Insert all errors as errors boxes
3421 // if we removed error insets before we ran chktex or if we inserted
3422 // error insets after we ran chktex, this must be run:
3426 users->updateScrollbar();
3434 extern void AllFloats(char, char);
3437 void Buffer::insertErrors(TeXErrors & terr)
3439 // Save the cursor position
3440 LyXCursor cursor = text->cursor;
3442 // This is drastic, but it's the only fix, I could find. (Asger)
3446 for (TeXErrors::Errors::const_iterator cit = terr.begin();
3449 string desctext((*cit).error_desc);
3450 string errortext((*cit).error_text);
3451 string msgtxt = desctext + '\n' + errortext;
3452 int errorrow = (*cit).error_in_line;
3454 // Insert error string for row number
3458 texrow.getIdFromRow(errorrow, tmpid, tmppos);
3460 LyXParagraph* texrowpar;
3463 texrowpar = text->FirstParagraph();
3466 texrowpar = text->GetParFromID(tmpid);
3472 InsetError *new_inset = new InsetError(msgtxt);
3474 text->SetCursorIntern(texrowpar, tmppos);
3475 text->InsertInset(new_inset);
3476 text->FullRebreak();
3478 // Restore the cursor position
3479 text->SetCursorIntern(cursor.par, cursor.pos);
3483 void Buffer::setCursorFromRow (int row)
3488 texrow.getIdFromRow(row, tmpid, tmppos);
3490 LyXParagraph* texrowpar;
3493 texrowpar = text->FirstParagraph();
3496 texrowpar = text->GetParFromID(tmpid);
3498 text->SetCursor(texrowpar, tmppos);
3502 void Buffer::RoffAsciiTable(FILE * file, LyXParagraph * par)
3505 font1 = LyXFont(LyXFont::ALL_INHERIT),
3508 LyXParagraph::size_type i;
3517 string fname1 = TmpFileName(string(), "RAT1");
3518 string fname2 = TmpFileName(string(), "RAT2");
3519 if (!(fp= fopen(fname1.c_str(), "w"))) {
3520 WriteAlert(_("LYX_ERROR:"),
3521 _("Cannot open temporary file:"), fname1);
3524 par->table->RoffEndOfCell(fp, -1);
3525 for (i = 0; i < par->size(); ++i) {
3526 c = par->GetChar(i);
3527 if (par->table->IsContRow(cell)) {
3528 if (c == LyXParagraph::META_NEWLINE)
3532 font2 = par->GetFontSettings(i);
3533 if (font1.latex() != font2.latex()) {
3534 if (font2.latex() != LyXFont::OFF)
3538 case LyXParagraph::META_INSET:
3539 if ((inset = par->GetInset(i))) {
3540 if (!(fp2= fopen(fname2.c_str(), "w+"))) {
3541 WriteAlert(_("LYX_ERROR:"),
3542 _("Cannot open temporary file:"), fname2);
3544 remove(fname1.c_str());
3547 inset->Latex(fp2,-1);
3552 fprintf(fp, "\\\\");
3560 case LyXParagraph::META_NEWLINE:
3561 if (par->table->CellHasContRow(cell)>= 0)
3562 par->RoffContTableRows(fp, i+1, cell);
3563 par->table->RoffEndOfCell(fp, cell);
3566 case LyXParagraph::META_HFILL:
3568 case LyXParagraph::META_PROTECTED_SEPARATOR:
3571 fprintf(fp, "\\\\");
3575 fprintf(fp, "%c", c);
3578 << "RoffAsciiTable:"
3579 " NULL char in structure." << endl;
3583 par->table->RoffEndOfCell(fp, cell);
3585 string cmd = lyxrc->ascii_roff_command + " >" + fname2;
3586 cmd = subst(cmd, "$$FName", fname1);
3587 Systemcalls one(Systemcalls::System, cmd);
3588 if (!(lyxerr.debugging(Debug::ROFF))) {
3589 remove(fname1.c_str());
3591 if (!(fp= fopen(fname2.c_str(), "r"))) {
3592 WriteFSAlert(_("Error! Can't open temporary file:"), fname2);
3595 // now output the produced file
3596 fprintf(file, "\n\n");
3599 WriteAlert(_("Error!"),
3600 _("Error executing *roff command on table"));
3601 // overread leading blank lines
3602 while(!feof(fp) && (c == '\n'))
3605 for(j= 0; j<par->depth; j++)
3607 while(!feof(fp) && (c != '\n')) {
3612 // overread trailing blank lines
3613 while(!feof(fp) && (c == '\n'))
3617 remove(fname2.c_str());
3621 /// changed Heinrich Bauer, 23/03/98
3622 bool Buffer::isDviClean()
3624 if (lyxrc->use_tempdir)
3625 return dvi_clean_tmpd;
3627 return dvi_clean_orgd;
3631 /// changed Heinrich Bauer, 23/03/98
3632 void Buffer::markDviClean()
3634 if (lyxrc->use_tempdir)
3635 dvi_clean_tmpd = true;
3637 dvi_clean_orgd = true;
3641 /// changed Heinrich Bauer, 23/03/98
3642 void Buffer::markDviDirty()
3644 if (lyxrc->use_tempdir)
3645 dvi_clean_tmpd = false;
3647 dvi_clean_orgd = false;
3651 void Buffer::update(signed char f)
3655 users->owner()->updateLayoutChoice();
3657 if (!text->selection && f > -3)
3658 text->sel_cursor = text->cursor;
3661 text->FullRebreak();
3664 if (f != 3 && f != -3) {
3666 users->updateScrollbar();
3669 if (f == 1 || f == -1) {
3672 users->owner()->getMiniBuffer()->setTimer(4);
3680 void Buffer::validate(LaTeXFeatures & features)
3682 LyXParagraph * par = paragraph;
3683 LyXTextClass const & tclass =
3684 textclasslist.TextClass(params.textclass);
3686 // AMS Style is at document level
3688 features.amsstyle = (params.use_amsmath ||
3689 tclass.provides(LyXTextClass::amsmath));
3692 // We don't use "lyxerr.debug" because of speed. (Asger)
3693 if (lyxerr.debugging(Debug::LATEX))
3694 lyxerr << "Paragraph: " << par << endl;
3696 // Now just follow the list of paragraphs and run
3697 // validate on each of them.
3698 par->validate(features);
3700 // and then the next paragraph
3704 // the bullet shapes are buffer level not paragraph level
3705 // so they are tested here
3706 for (int i = 0; i < 4; ++i) {
3707 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
3708 int font = params.user_defined_bullets[i].getFont();
3711 .user_defined_bullets[i]
3718 features.latexsym = true;
3722 features.amssymb = true;
3724 else if ((font >= 2 && font <= 5)) {
3725 features.pifont = true;
3730 if (lyxerr.debugging(Debug::LATEX)) {
3731 features.showStruct(params);
3736 void Buffer::setPaperStuff()
3738 params.papersize = BufferParams::PAPER_DEFAULT;
3739 char c1 = params.paperpackage;
3740 if (c1 == BufferParams::PACKAGE_NONE) {
3741 char c2 = params.papersize2;
3742 if (c2 == BufferParams::VM_PAPER_USLETTER)
3743 params.papersize = BufferParams::PAPER_USLETTER;
3744 else if (c2 == BufferParams::VM_PAPER_USLEGAL)
3745 params.papersize = BufferParams::PAPER_LEGALPAPER;
3746 else if (c2 == BufferParams::VM_PAPER_USEXECUTIVE)
3747 params.papersize = BufferParams::PAPER_EXECUTIVEPAPER;
3748 else if (c2 == BufferParams::VM_PAPER_A3)
3749 params.papersize = BufferParams::PAPER_A3PAPER;
3750 else if (c2 == BufferParams::VM_PAPER_A4)
3751 params.papersize = BufferParams::PAPER_A4PAPER;
3752 else if (c2 == BufferParams::VM_PAPER_A5)
3753 params.papersize = BufferParams::PAPER_A5PAPER;
3754 else if ((c2 == BufferParams::VM_PAPER_B3) || (c2 == BufferParams::VM_PAPER_B4) ||
3755 (c2 == BufferParams::VM_PAPER_B5))
3756 params.papersize = BufferParams::PAPER_B5PAPER;
3757 } else if ((c1 == BufferParams::PACKAGE_A4) || (c1 == BufferParams::PACKAGE_A4WIDE) ||
3758 (c1 == BufferParams::PACKAGE_WIDEMARGINSA4))
3759 params.papersize = BufferParams::PAPER_A4PAPER;
3764 void Buffer::setOldPaperStuff()
3766 char c = params.papersize = params.papersize2;
3767 params.papersize2 = BufferParams::VM_PAPER_DEFAULT;
3768 params.paperpackage = BufferParams::PACKAGE_NONE;
3769 if (c == OLD_PAPER_A4PAPER)
3770 params.papersize2 = BufferParams::VM_PAPER_A4;
3771 else if (c == OLD_PAPER_A4)
3772 params.paperpackage = BufferParams::PACKAGE_A4;
3773 else if (c == OLD_PAPER_A4WIDE)
3774 params.paperpackage = BufferParams::PACKAGE_A4WIDE;
3775 else if (c == OLD_PAPER_WIDEMARGINSA4)
3776 params.paperpackage = BufferParams::PACKAGE_WIDEMARGINSA4;
3777 else if (c == OLD_PAPER_USLETTER)
3778 params.papersize2 = BufferParams::VM_PAPER_USLETTER;
3779 else if (c == OLD_PAPER_A5PAPER)
3780 params.papersize2 = BufferParams::VM_PAPER_A5;
3781 else if (c == OLD_PAPER_B5PAPER)
3782 params.papersize2 = BufferParams::VM_PAPER_B5;
3783 else if (c == OLD_PAPER_EXECUTIVEPAPER)
3784 params.papersize2 = BufferParams::VM_PAPER_USEXECUTIVE;
3785 else if (c == OLD_PAPER_LEGALPAPER)
3786 params.papersize2 = BufferParams::VM_PAPER_USLEGAL;
3791 void Buffer::insertInset(Inset * inset, string const & lout,
3794 // check for table/list in tables
3795 if (no_table && text->cursor.par->table){
3796 WriteAlert(_("Impossible Operation!"),
3797 _("Cannot insert table/list in table."),
3801 // not quite sure if we want this...
3802 text->SetCursorParUndo();
3806 if (!lout.empty()) {
3808 text->BreakParagraph();
3811 if (text->cursor.par->Last()) {
3814 text->BreakParagraph();
3818 int lay = textclasslist.NumberOfLayout(params.textclass,
3820 if (lay == -1) // layout not found
3821 // use default layout "Standard" (0)
3824 text->SetLayout(lay);
3826 text->SetParagraph(0, 0,
3828 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3834 text->current_font.setLatex(LyXFont::OFF);
3837 text->InsertInset(inset);
3840 text->UnFreezeUndo();
3844 // Open and lock an updatable inset
3845 void Buffer::open_new_inset(UpdatableInset * new_inset)
3849 insertInset(new_inset);
3852 new_inset->Edit(0, 0);
3856 /* This function should be in Buffer because it's a buffer's property (ale) */
3857 string Buffer::getIncludeonlyList(char delim)
3860 LyXParagraph * par = paragraph;
3861 LyXParagraph::size_type pos;
3865 while ((inset = par->ReturnNextInsetPointer(pos))){
3866 if (inset->LyxCode() == Inset::INCLUDE_CODE) {
3867 InsetInclude * insetinc =
3868 static_cast<InsetInclude*>(inset);
3869 if (insetinc->isInclude()
3870 && insetinc->isNoLoad()) {
3873 lst += ChangeExtension(insetinc->getContents(), string(), true);
3880 lyxerr.debug() << "Includeonly(" << lst << ')' << endl;
3885 /* This is also a buffer property (ale) */
3886 string Buffer::getReferenceList(char delim)
3888 /// if this is a child document and the parent is already loaded
3889 /// Use the parent's list instead [ale990407]
3890 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3891 Buffer *tmp = bufferlist.getBuffer(params.parentname);
3893 return tmp->getReferenceList(delim);
3896 LyXParagraph *par = paragraph;
3897 LyXParagraph::size_type pos;
3902 while ((inset = par->ReturnNextInsetPointer(pos))){
3903 for (int i = 0; i < inset->GetNumberOfLabels(); i++) {
3906 lst += inset->getLabel(i);
3912 lyxerr.debug() << "References(" << lst << ")" << endl;
3917 /* This is also a buffer property (ale) */
3918 string Buffer::getBibkeyList(char delim)
3920 /// if this is a child document and the parent is already loaded
3921 /// Use the parent's list instead [ale990412]
3922 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3923 Buffer *tmp = bufferlist.getBuffer(params.parentname);
3925 return tmp->getBibkeyList(delim);
3929 LyXParagraph * par = paragraph;
3932 if (!bibkeys.empty())
3934 bibkeys += par->bibkey->getContents();
3939 // Might be either using bibtex or a child has bibliography
3940 if (bibkeys.empty()) {
3944 LyXParagraph::size_type pos = -1;
3946 // Search for Bibtex or Include inset
3947 while ((inset = par->ReturnNextInsetPointer(pos))) {
3948 if (inset-> LyxCode() == Inset::BIBTEX_CODE) {
3949 if (!bibkeys.empty())
3951 bibkeys += static_cast<InsetBibtex*>(inset)->getKeys();
3952 } else if (inset-> LyxCode() == Inset::INCLUDE_CODE) {
3953 string bk = static_cast<InsetInclude*>(inset)->getKeys();
3955 if (!bibkeys.empty())
3966 lyxerr.debug() << "Bibkeys(" << bibkeys << ")" << endl;
3971 /* This is also a buffer property (ale) */
3972 // Not so sure about that. a goto Label function can not be buffer local, just
3973 // think how this will work in a multiwindo/buffer environment, all the
3974 // cursors in all the views showing this buffer will move. (Lgb)
3975 // OK, then no cursor action should be allowed in buffer. (ale)
3976 bool Buffer::gotoLabel(string const & label)
3979 LyXParagraph * par = paragraph;
3980 LyXParagraph::size_type pos;
3984 while ((inset = par->ReturnNextInsetPointer(pos))){
3985 for (int i = 0; i < inset->GetNumberOfLabels(); i++) {
3986 if (label == inset->getLabel(i)) {
3988 text->SetCursor(par, pos);
3989 text->sel_cursor = text->cursor;
4002 bool Buffer::isDepClean(string const & name) const
4004 DEPCLEAN * item = dep_clean;
4005 while (item && item->master != name)
4007 if (!item) return true;
4012 void Buffer::markDepClean(string const & name)
4015 dep_clean = new DEPCLEAN;
4016 dep_clean->clean = true;
4017 dep_clean->master = name;
4018 dep_clean->next = 0;
4020 DEPCLEAN* item = dep_clean;
4021 while (item && item->master != name)
4026 item = new DEPCLEAN;
4028 item->master = name;