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
1205 "#This file was created by <%s> %s",
1206 userName.c_str(),(char*)date());
1208 "#LyX 1.0 (C) 1995-1999 Matthias Ettrich"
1209 " and the LyX Team\n");
1211 // at the very beginning the used lyx format
1212 fprintf(file, "\\lyxformat %.2f\n", LYX_FORMAT);
1214 // now write out the buffer parameters.
1215 params.writeFile(file);
1217 char footnoteflag = 0;
1220 // this will write out all the paragraphs
1221 // using recursive descent.
1222 paragraph->writeFile(file, params, footnoteflag, depth);
1224 // Write marker that shows file is complete
1225 fprintf(file, "\n\\the_end\n");
1228 lyxerr << _("Error! Could not close file properly: ")
1229 << filename << endl;
1231 WriteFSAlert(_("Error! Could not close file properly: "),
1239 void Buffer::writeFileAscii(string const & filename, int linelen)
1241 FilePtr file(filename, FilePtr::write);
1245 LyXParagraph * par = paragraph;
1255 LyXParagraph::size_type i;
1271 ref_printed = false;
1275 WriteFSAlert(_("Error: Cannot write file:"), filename);
1278 fname1 = TmpFileName();
1282 if (par->footnoteflag != LyXParagraph::NO_FOOTNOTE ||
1284 par->previous->footnoteflag == LyXParagraph::NO_FOOTNOTE){
1286 /* begins a footnote environment ? */
1287 if (footnoteflag != par->footnoteflag) {
1288 footnoteflag = par->footnoteflag;
1290 j = strlen(string_footnotekinds[par->footnotekind])+4;
1291 if (currlinelen+j > linelen)
1292 fprintf(file, "\n");
1293 fprintf(file, "([%s] ",
1294 string_footnotekinds[par->footnotekind]);
1299 /* begins or ends a deeper area ?*/
1300 if (depth != par->depth) {
1301 if (par->depth > depth) {
1302 while (par->depth > depth) {
1307 while (par->depth < depth) {
1313 /* First write the layout */
1314 tmp = textclasslist.NameOfLayout(params.textclass, par->layout);
1315 if (tmp == "Itemize") {
1317 ltype_depth = depth+1;
1318 } else if (tmp == "Enumerate") {
1320 ltype_depth = depth+1;
1321 } else if (strstr(tmp.c_str(), "ection")) {
1323 ltype_depth = depth+1;
1324 } else if (strstr(tmp.c_str(), "aragraph")) {
1326 ltype_depth = depth+1;
1327 } else if (tmp == "Description") {
1329 ltype_depth = depth+1;
1330 } else if (tmp == "Abstract") {
1333 } else if (tmp == "Bibliography") {
1341 /* maybe some vertical spaces */
1343 /* the labelwidthstring used in lists */
1347 /* some pagebreaks? */
1351 /* what about the alignment */
1354 /* dummy layout, that means a footnote ended */
1355 footnoteflag = LyXParagraph::NO_FOOTNOTE;
1356 fprintf(file, ") ");
1360 /* It might be a table */
1362 if (!lyxrc->ascii_roff_command.empty() &&
1363 lyxrc->ascii_roff_command != "none") {
1364 RoffAsciiTable(file, par);
1370 cells = par->table->columns;
1371 clen = new int [cells];
1372 memset(clen, 0, sizeof(int)*cells);
1373 for (i = 0, j = 0, h = 1; i < par->size(); ++i, ++h) {
1374 c = par->GetChar(i);
1375 if (c == LyXParagraph::META_INSET) {
1376 if ((inset = par->GetInset(i))) {
1380 WriteFSAlert(_("Error: Cannot open temporary file:"), fname1);
1383 inset->Latex(fp,-1);
1385 remove(fname1.c_str());
1387 } else if (c == LyXParagraph::META_NEWLINE) {
1391 j = (++j) % par->table->NumberOfCellsInRow(actcell);
1399 font1 = LyXFont(LyXFont::ALL_INHERIT);
1401 for (i = 0, actpos = 1; i < par->size(); ++i, ++actpos) {
1402 if (!i && !footnoteflag && !noparbreak){
1403 fprintf(file, "\n\n");
1404 for(j = 0; j<depth; j++)
1406 currlinelen = depth*2;
1408 case 0: /* Standart */
1409 case 4: /* (Sub)Paragraph */
1410 case 5: /* Description */
1412 case 6: /* Abstract */
1413 fprintf(file, "Abstract\n\n");
1415 case 7: /* Bibliography */
1417 fprintf(file, "References\n\n");
1422 fprintf(file, "%s ", par->labelstring.c_str());
1425 if (ltype_depth > depth) {
1426 for(j = ltype_depth-1; j>depth; j--)
1428 currlinelen += (ltype_depth-depth)*2;
1431 for(j = 0;j<cells;j++) {
1433 for(h = 0; h<(clen[j]+1); h++)
1436 fprintf(file, "+\n");
1437 for(j = 0; j<depth; j++)
1439 currlinelen = depth*2;
1440 if (ltype_depth > depth) {
1441 for(j = ltype_depth; j>depth; j--)
1443 currlinelen += (ltype_depth-depth)*2;
1445 fprintf(file, "| ");
1448 font2 = par->GetFontSettings(i);
1449 if (font1.latex() != font2.latex()) {
1450 if (font2.latex() == LyXFont::OFF)
1458 c = par->GetChar(i);
1462 case LyXParagraph::META_INSET:
1463 if ((inset = par->GetInset(i))) {
1465 inset->Latex(file,-1);
1466 currlinelen += (ftell(file) - fpos);
1467 actpos += (ftell(file) - fpos) - 1;
1470 case LyXParagraph::META_NEWLINE:
1472 if (par->table->NumberOfCellsInRow(actcell) <= cell) {
1473 for(j = actpos;j<clen[cell-1];j++)
1475 fprintf(file, " |\n");
1476 for(j = 0; j<depth; j++)
1478 currlinelen = depth*2;
1479 if (ltype_depth > depth) {
1480 for(j = ltype_depth; j>depth; j--)
1482 currlinelen += (ltype_depth-depth)*2;
1484 for(j = 0;j<cells;j++) {
1486 for(h = 0; h<(clen[j]+1); h++)
1489 fprintf(file, "+\n");
1490 for(j = 0; j<depth; j++)
1492 currlinelen = depth*2;
1493 if (ltype_depth > depth) {
1494 for(j = ltype_depth; j>depth; j--)
1496 currlinelen += (ltype_depth-depth)*2;
1498 fprintf(file, "| ");
1501 for(j = actpos; j<clen[cell-1]; j++)
1503 fprintf(file, " | ");
1507 currlinelen = actpos = 0;
1509 fprintf(file, "\n");
1510 for(j = 0; j<depth; j++)
1512 currlinelen = depth*2;
1513 if (ltype_depth > depth) {
1514 for(j = ltype_depth; j>depth; j--)
1516 currlinelen += (ltype_depth-depth)*2;
1520 case LyXParagraph::META_HFILL:
1521 fprintf(file, "\t");
1523 case LyXParagraph::META_PROTECTED_SEPARATOR:
1527 fprintf(file, "\\");
1530 if (currlinelen > linelen - 10
1531 && c == ' ' && i + 2 < par->size()) {
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;
1540 currlinelen += (ltype_depth-depth)*2;
1542 } else if (c != '\0')
1543 fprintf(file, "%c", c);
1545 lyxerr.debug() << "writeAsciiFile: NULL char in structure." << endl;
1551 for(j = actpos;j<clen[cell-1];j++)
1553 fprintf(file, " |\n");
1554 for(j = 0; j<depth; j++)
1556 currlinelen = depth*2;
1557 if (ltype_depth > depth) {
1558 for(j = ltype_depth; j>depth; j--)
1560 currlinelen += (ltype_depth-depth)*2;
1562 for(j = 0;j<cells;j++) {
1564 for(h = 0; h<(clen[j]+1); h++)
1567 fprintf(file, "+\n");
1573 fprintf(file, "\n");
1577 void Buffer::makeLaTeXFile(string const & filename,
1578 string const & original_path,
1579 bool nice, bool only_body)
1581 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
1582 params.textclass = GetCurrentTextClass();
1583 niceFile = nice; // this will be used by Insetincludes.
1585 tex_code_break_column = lyxrc->ascii_linelen;
1587 LyXTextClass const & tclass =
1588 textclasslist.TextClass(params.textclass);
1590 FilePtr file(filename, FilePtr::write);
1592 WriteFSAlert(_("Error: Cannot write file:"), filename);
1596 // validate the buffer.
1597 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
1598 LaTeXFeatures features(tclass.numLayouts());
1600 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
1603 // The starting paragraph of the coming rows is the
1604 // first paragraph of the document. (Asger)
1605 texrow.start(paragraph, 0);
1607 string userName(getUserName());
1610 if (!only_body && nice) {
1611 LFile += "%% This LaTeX-file was created by <";
1612 LFile += userName + "> " + (char*)date();
1613 LFile += "%% LyX 1.0 (C) 1995-1999 by Matthias Ettrich and the LyX Team\n";
1614 LFile += "\n%% Do not edit this file unless you know what you are doing.\n";
1620 lyxerr.debug() << "lyx header finished" << endl;
1621 // There are a few differences between nice LaTeX and usual files:
1622 // usual is \batchmode, uses \listfiles and has a
1623 // special input@path to allow the including of figures
1624 // with either \input or \includegraphics (what figinsets do).
1625 // batchmode is not set if there is a tex_code_break_column.
1626 // In this case somebody is interested in the generated LaTeX,
1627 // so this is OK. input@path is set when the actual parameter
1628 // original_path is set. This is done for usual tex-file, but not
1629 // for nice-latex-file. (Matthias 250696)
1632 // code for usual, NOT nice-latex-file
1633 LFile += "\\batchmode\n"; // changed
1634 // from \nonstopmode
1636 // We don't need listfiles anymore
1637 //LFile += "\\listfiles\n";
1640 if (!original_path.empty()) {
1641 LFile += "\\makeatletter\n";
1643 LFile += "\\def\\input@path{{" + original_path
1646 LFile += "\\makeatother\n";
1650 LFile += "\\documentclass";
1652 string options; // the document class options.
1654 if (tokenPos(tclass.opt_fontsize(), '|', params.fontsize) >= 0) {
1655 // only write if existing in list (and not default)
1656 options += params.fontsize;
1661 if (!params.use_geometry &&
1662 (params.paperpackage == BufferParams::PACKAGE_NONE)) {
1663 switch (params.papersize) {
1664 case BufferParams::PAPER_A4PAPER:
1665 options += "a4paper,";
1667 case BufferParams::PAPER_USLETTER:
1668 options += "letterpaper,";
1670 case BufferParams::PAPER_A5PAPER:
1671 options += "a5paper,";
1673 case BufferParams::PAPER_B5PAPER:
1674 options += "b5paper,";
1676 case BufferParams::PAPER_EXECUTIVEPAPER:
1677 options += "executivepaper,";
1679 case BufferParams::PAPER_LEGALPAPER:
1680 options += "legalpaper,";
1686 if (params.sides != tclass.sides()) {
1687 if (params.sides == 2)
1688 options += "twoside,";
1690 options += "oneside,";
1694 if (params.columns != tclass.columns()) {
1695 if (params.columns == 2)
1696 options += "twocolumn,";
1698 options += "onecolumn,";
1701 if (!params.use_geometry && params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1702 options += "landscape,";
1704 // language should be a parameter to \documentclass
1705 if (params.language != "default") {
1706 options += params.language + ',';
1709 // the user-defined options
1710 if (!params.options.empty()) {
1711 options += params.options + ',';
1714 if (!options.empty()){
1715 options = strip(options, ',');
1722 LFile += textclasslist.LatexnameOfClass(params.textclass);
1725 // end of \documentclass defs
1727 // font selection must be done before loading fontenc.sty
1728 if (params.fonts != "default") {
1729 LFile += "\\usepackage{" + params.fonts + "}\n";
1732 // this one is not per buffer
1733 if (lyxrc->fontenc != "default") {
1734 LFile += "\\usepackage[" + lyxrc->fontenc
1738 if (params.inputenc != "default") {
1739 LFile += "\\usepackage[" + params.inputenc
1744 /* at the very beginning the text parameters */
1745 if (params.paperpackage != BufferParams::PACKAGE_NONE) {
1746 switch (params.paperpackage) {
1747 case BufferParams::PACKAGE_A4:
1748 LFile += "\\usepackage{a4}\n";
1751 case BufferParams::PACKAGE_A4WIDE:
1752 LFile += "\\usepackage{a4wide}\n";
1755 case BufferParams::PACKAGE_WIDEMARGINSA4:
1756 LFile += "\\usepackage[widemargins]{a4}\n";
1761 if (params.use_geometry) {
1762 LFile += "\\usepackage{geometry}\n";
1764 LFile += "\\geometry{verbose";
1765 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1766 LFile += ",landscape";
1767 switch (params.papersize2) {
1768 case BufferParams::VM_PAPER_CUSTOM:
1769 if (!params.paperwidth.empty())
1770 LFile += ",paperwidth= "
1771 + params.paperwidth;
1772 if (!params.paperheight.empty())
1773 LFile += ",paperheight= "
1774 + params.paperheight;
1776 case BufferParams::VM_PAPER_USLETTER:
1777 LFile += ",letterpaper";
1779 case BufferParams::VM_PAPER_USLEGAL:
1780 LFile += ",legalpaper";
1782 case BufferParams::VM_PAPER_USEXECUTIVE:
1783 LFile += ",executivepaper";
1785 case BufferParams::VM_PAPER_A3:
1786 LFile += ",a3paper";
1788 case BufferParams::VM_PAPER_A4:
1789 LFile += ",a4paper";
1791 case BufferParams::VM_PAPER_A5:
1792 LFile += ",a5paper";
1794 case BufferParams::VM_PAPER_B3:
1795 LFile += ",b3paper";
1797 case BufferParams::VM_PAPER_B4:
1798 LFile += ",b4paper";
1800 case BufferParams::VM_PAPER_B5:
1801 LFile += ",b5paper";
1804 // default papersize ie BufferParams::VM_PAPER_DEFAULT
1805 switch (lyxrc->default_papersize) {
1806 case BufferParams::PAPER_DEFAULT: // keep compiler happy
1807 case BufferParams::PAPER_USLETTER:
1808 LFile += ",letterpaper";
1810 case BufferParams::PAPER_LEGALPAPER:
1811 LFile += ",legalpaper";
1813 case BufferParams::PAPER_EXECUTIVEPAPER:
1814 LFile += ",executivepaper";
1816 case BufferParams::PAPER_A3PAPER:
1817 LFile += ",a3paper";
1819 case BufferParams::PAPER_A4PAPER:
1820 LFile += ",a4paper";
1822 case BufferParams::PAPER_A5PAPER:
1823 LFile += ",a5paper";
1825 case BufferParams::PAPER_B5PAPER:
1826 LFile += ",b5paper";
1830 if (!params.topmargin.empty())
1831 LFile += ",tmargin= " + params.topmargin;
1832 if (!params.bottommargin.empty())
1833 LFile += ",bmargin= " + params.bottommargin;
1834 if (!params.leftmargin.empty())
1835 LFile += ",lmargin= " + params.leftmargin;
1836 if (!params.rightmargin.empty())
1837 LFile += ",rmargin= " + params.rightmargin;
1838 if (!params.headheight.empty())
1839 LFile += ",headheight= " + params.headheight;
1840 if (!params.headsep.empty())
1841 LFile += ",headsep= " + params.headsep;
1842 if (!params.footskip.empty())
1843 LFile += ",footskip= " + params.footskip;
1847 if (params.use_amsmath
1848 && !prefixIs(textclasslist.LatexnameOfClass(params.textclass), "ams")) {
1849 LFile += "\\usepackage{amsmath}\n";
1852 if (tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle) >= 0) {
1853 if (params.pagestyle == "fancy") {
1854 LFile += "\\usepackage{fancyhdr}\n";
1857 LFile += "\\pagestyle{" + params.pagestyle + "}\n";
1861 // We try to load babel late, in case it interferes
1862 // with other packages.
1863 if (params.language != "default") {
1864 LFile += "\\usepackage{babel}\n";
1868 if (params.secnumdepth != tclass.secnumdepth()) {
1869 LFile += "\\setcounter{secnumdepth}{";
1870 LFile += tostr(params.secnumdepth);
1874 if (params.tocdepth != tclass.tocdepth()) {
1875 LFile += "\\setcounter{tocdepth}{";
1876 LFile += tostr(params.tocdepth);
1881 if (params.paragraph_separation) {
1882 switch (params.defskip.kind()) {
1883 case VSpace::SMALLSKIP:
1884 LFile += "\\setlength\\parskip{\\smallskipamount}\n";
1886 case VSpace::MEDSKIP:
1887 LFile += "\\setlength\\parskip{\\medskipamount}\n";
1889 case VSpace::BIGSKIP:
1890 LFile += "\\setlength\\parskip{\\bigskipamount}\n";
1892 case VSpace::LENGTH:
1893 LFile += "\\setlength\\parskip{"
1894 + params.defskip.length().asLatexString()
1897 default: // should never happen // Then delete it.
1898 LFile += "\\setlength\\parskip{\\medskipamount}\n";
1903 LFile += "\\setlength\\parindent{0pt}\n";
1907 // Write out what we've generated so far...and reset LFile
1908 fwrite(LFile.c_str(), sizeof(char), LFile.length(), file);
1911 // Now insert the LyX specific LaTeX commands...
1912 string preamble, tmppreamble;
1914 // The optional packages;
1915 preamble = features.getPackages(params);
1917 // this might be useful...
1918 preamble += "\n\\makeatletter\n\n";
1920 // Some macros LyX will need
1921 tmppreamble = features.getMacros(params);
1923 if (!tmppreamble.empty()) {
1924 preamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1925 "LyX specific LaTeX commands.\n"
1926 + tmppreamble + '\n';
1929 // the text class specific preamble
1930 tmppreamble = features.getTClassPreamble(params);
1931 if (!tmppreamble.empty()) {
1932 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1933 "Textclass specific LaTeX commands.\n"
1934 + tmppreamble + '\n';
1937 /* the user-defined preamble */
1938 if (!params.preamble.empty()) {
1939 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1940 "User specified LaTeX commands.\n"
1941 + params.preamble + '\n';
1944 preamble += "\\makeatother\n\n";
1946 // Itemize bullet settings need to be last in case the user
1947 // defines their own bullets that use a package included
1948 // in the user-defined preamble -- ARRae
1949 for (int i = 0; i < 4; ++i) {
1950 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
1951 preamble += "\\renewcommand\\labelitemi";
1953 // `i' is one less than the item to modify
1966 preamble += "[0]{" + params.user_defined_bullets[i].getText() + "}\n";
1970 for (int j = countChar(preamble, '\n'); j-- ;) {
1974 // A bit faster than printing a char at a time I think.
1975 fwrite(preamble.c_str(), sizeof(char),
1976 preamble.length(), file);
1979 LFile += "\\begin{document}\n\n";
1983 lyxerr.debug() << "preamble finished, now the body." << endl;
1985 bool was_title = false;
1986 bool already_title = false;
1992 LyXParagraph * par = paragraph;
1998 lyxerr[Debug::LATEX] << "Error in MakeLateXFile."
2000 LyXLayout const & layout = textclasslist.Style(params.textclass,
2003 if (layout.intitle) {
2004 if (already_title) {
2005 lyxerr <<"Error in MakeLatexFile: You"
2006 " should not mix title layouts"
2007 " with normal ones." << endl;
2010 } else if (was_title && !already_title) {
2011 LFile += "\\maketitle\n";
2013 already_title = true;
2016 // We are at depth 0 so we can just use
2017 // ordinary \footnote{} generation
2018 // flag this with ftcount
2020 if (layout.isEnvironment()
2021 || par->pextra_type != LyXParagraph::PEXTRA_NONE) {
2022 par = par->TeXEnvironment(LFile, texrow,
2023 ftnote, ft_texrow, ftcount);
2025 par = par->TeXOnePar(LFile, texrow,
2026 ftnote, ft_texrow, ftcount);
2029 // Write out what we've generated...and reset LFile
2032 LFile += "\\addtocounter{footnote}{-";
2033 LFile += tostr(ftcount - 1);
2037 texrow += ft_texrow;
2042 if (loop_count == 2) {
2043 // fwrite()ing every second time through the loop
2044 // gains a few extra % of speed; going higher than
2045 // 2 will slow things down again. I'll look at
2046 // LFile.length() in a future revision. ARRae
2047 fwrite(LFile.c_str(), sizeof(char),
2048 LFile.length(), file);
2054 // It might be that we only have a title in this document
2055 if (was_title && !already_title) {
2056 LFile += "\\maketitle\n";
2061 LFile += "\\end{document}\n";
2064 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
2066 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
2070 // Just to be sure. (Asger)
2073 // Write out what we've generated...and reset LFile
2074 fwrite(LFile.c_str(), sizeof(char), LFile.length(), file);
2077 // tex_code_break_column's value is used to decide
2078 // if we are in batchmode or not (within mathed_write()
2079 // in math_write.C) so we must set it to a non-zero
2080 // value when we leave otherwise we save incorrect .lyx files.
2081 tex_code_break_column = lyxrc->ascii_linelen;
2084 WriteFSAlert(_("Error! Could not close file properly:"), filename);
2086 lyxerr.debug() << "Finished making latex file." << endl;
2090 bool Buffer::isLatex() const
2092 return textclasslist.TextClass(params.textclass).outputType() == LATEX;
2096 bool Buffer::isLinuxDoc() const
2098 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC;
2102 bool Buffer::isLiterate() const
2104 return textclasslist.TextClass(params.textclass).outputType() == LITERATE;
2108 bool Buffer::isDocBook() const
2110 return textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2114 bool Buffer::isSGML() const
2116 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC ||
2117 textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2121 void Buffer::sgmlOpenTag(FILE * file, int depth, string const & latexname) const
2123 static char * space[] = {" "," ", " ", " ", " ", " ", " ",
2124 " ", " ", " ", " "};
2126 fprintf(file, "%s<%s>\n", space[depth], latexname.c_str());
2130 void Buffer::sgmlCloseTag(FILE * file, int depth,
2131 string const & latexname) const
2133 static char * space[] = {" ", " ", " ", " ", " ", " ", " ",
2134 " ", " ", " ", " "};
2136 fprintf(file, "%s</%s>\n", space[depth], latexname.c_str());
2140 void Buffer::makeLinuxDocFile(string const & filename, int column)
2142 LyXParagraph * par = paragraph;
2144 string top_element = textclasslist.LatexnameOfClass(params.textclass);
2145 string environment_stack[10];
2148 int depth = 0; /* paragraph depth */
2150 FilePtr file(filename, FilePtr::write);
2151 tex_code_break_column = column;
2154 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), filename);
2160 if (params.preamble.empty()) {
2161 fprintf(file, "<!doctype linuxdoc system>\n\n");
2164 fprintf(file, "<!doctype linuxdoc system \n [ %s \n]>\n\n",
2165 params.preamble.c_str() );
2168 string userName(getUserName());
2170 "<!-- LinuxDoc file was created by LyX 1.0 (C) 1995-1999 ");
2171 fprintf(file, "by <%s> %s -->\n", userName.c_str(), (char *)date());
2173 if(params.options.empty())
2174 sgmlOpenTag(file, 0, top_element);
2176 string top = top_element;
2178 top += params.options;
2179 sgmlOpenTag(file, 0, top);
2183 int desc_on = 0; /* description mode*/
2184 LyXLayout const & style =
2185 textclasslist.Style(GetCurrentTextClass(),
2187 par->AutoDeleteInsets();
2189 /* treat <toc> as a special case for compatibility with old code */
2190 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2191 Inset *inset = par->GetInset(0);
2192 char lyx_code = inset->LyxCode();
2193 if (lyx_code == Inset::TOC_CODE){
2194 string temp = "toc";
2195 sgmlOpenTag(file, depth, temp);
2198 linuxDocHandleFootnote(file, par, depth);
2203 /* environment tag closing */
2204 for( ;depth > par->depth; depth--) {
2205 sgmlCloseTag(file, depth, environment_stack[depth]);
2206 environment_stack[depth].clear();
2209 /* write opening SGML tags */
2210 switch(style.latextype) {
2211 case LATEX_PARAGRAPH:
2212 if(depth == par->depth
2213 && !environment_stack[depth].empty()) {
2214 sgmlCloseTag(file, depth, environment_stack[depth]);
2215 environment_stack[depth].clear();
2219 fprintf(file, "</p>");
2221 sgmlOpenTag(file, depth, style.latexname());
2226 LinuxDocError(par, 0, _("Error : Wrong depth for LatexType Command.\n"));
2228 if (!environment_stack[depth].empty()){
2229 sgmlCloseTag(file, depth, environment_stack[depth]);
2230 fprintf(file, "</p>");
2233 environment_stack[depth].clear();
2234 sgmlOpenTag(file, depth, style.latexname());
2237 case LATEX_ENVIRONMENT:
2238 case LATEX_ITEM_ENVIRONMENT:
2239 if(depth == par->depth
2240 && environment_stack[depth] != style.latexname()
2241 && !environment_stack[depth].empty()) {
2243 sgmlCloseTag(file, depth,
2244 environment_stack[depth]);
2245 environment_stack[depth].clear();
2247 if (depth < par->depth) {
2249 environment_stack[depth].clear();
2251 if (environment_stack[depth] != style.latexname()) {
2254 sgmlOpenTag(file, depth, temp);
2256 environment_stack[depth] = style.latexname();
2257 sgmlOpenTag(file, depth, environment_stack[depth]);
2259 if(style.latextype == LATEX_ENVIRONMENT) break;
2261 desc_on = (style.labeltype == LABEL_MANUAL);
2268 sgmlOpenTag(file, depth+1, item_name);
2271 sgmlOpenTag(file, depth, style.latexname());
2276 SimpleLinuxDocOnePar(file, par, desc_on, depth);
2279 linuxDocHandleFootnote(file, par, depth);
2281 while(par && par->IsDummy());
2283 fprintf(file, "\n");
2284 /* write closing SGML tags */
2285 switch(style.latextype) {
2287 case LATEX_ENVIRONMENT:
2288 case LATEX_ITEM_ENVIRONMENT:
2291 sgmlCloseTag(file, depth, style.latexname());
2296 /* Close open tags */
2297 for(;depth>0;depth--)
2298 sgmlCloseTag(file, depth, environment_stack[depth]);
2300 if(!environment_stack[depth].empty())
2301 sgmlCloseTag(file, depth, environment_stack[depth]);
2303 fprintf(file, "\n\n");
2304 sgmlCloseTag(file, 0, top_element);
2307 WriteFSAlert(_("Error! Could not close file properly:"),
2313 void Buffer::linuxDocHandleFootnote(FILE * file, LyXParagraph * & par,
2316 string tag = "footnote";
2318 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2319 sgmlOpenTag(file, depth+1, tag);
2320 SimpleLinuxDocOnePar(file, par, 0, depth+1);
2321 sgmlCloseTag(file, depth+1, tag);
2326 void Buffer::DocBookHandleCaption(FILE * file, string & inner_tag,
2327 int const depth, int desc_on,
2328 LyXParagraph * & par)
2330 LyXParagraph * tpar = par;
2331 string tmp_par, extra_par;
2332 while (tpar && (tpar->footnoteflag != LyXParagraph::NO_FOOTNOTE) &&
2333 (tpar->layout != textclasslist.NumberOfLayout(params.textclass, "Caption").second))
2336 tpar->layout == textclasslist.NumberOfLayout(params.textclass,
2337 "Caption").second) {
2338 sgmlOpenTag(file, depth+1, inner_tag);
2339 SimpleDocBookOnePar(tmp_par, extra_par, tpar, desc_on, depth+2);
2340 tmp_par = strip(tmp_par);
2341 tmp_par = frontStrip(tmp_par);
2342 fprintf(file, "%s", tmp_par.c_str());
2343 sgmlCloseTag(file, depth+1, inner_tag);
2344 if(!extra_par.empty())
2345 fprintf(file, "%s", extra_par.c_str());
2349 void Buffer::DocBookHandleFootnote(FILE * file, LyXParagraph * & par,
2352 string tag, inner_tag;
2353 string tmp_par, extra_par;
2354 bool inner_span = false;
2357 // This is not how I like to see enums. They should not be anonymous
2358 // and variables of its type should not be declared right after the
2359 // last brace. (Lgb)
2366 } last = NO_ONE, present = FOOTNOTE_LIKE;
2368 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2369 if(last == present) {
2371 if(!tmp_par.empty()) {
2372 fprintf(file, "%s", tmp_par.c_str());
2374 sgmlCloseTag(file, depth+1, inner_tag);
2375 sgmlOpenTag(file, depth+1, inner_tag);
2379 fprintf(file, "\n");
2381 fprintf(file, "%s", tmp_par.c_str());
2382 if(!inner_tag.empty()) sgmlCloseTag(file, depth+1, inner_tag);
2383 if(!extra_par.empty()) fprintf(file, "%s", extra_par.c_str());
2384 if(!tag.empty()) sgmlCloseTag(file, depth, tag);
2387 switch (par->footnotekind) {
2388 case LyXParagraph::FOOTNOTE:
2389 case LyXParagraph::ALGORITHM:
2392 present = FOOTNOTE_LIKE;
2395 case LyXParagraph::MARGIN:
2398 present = MARGIN_LIKE;
2401 case LyXParagraph::FIG:
2402 case LyXParagraph::WIDE_FIG:
2404 inner_tag = "title";
2408 case LyXParagraph::TAB:
2409 case LyXParagraph::WIDE_TAB:
2411 inner_tag = "title";
2416 sgmlOpenTag(file, depth, tag);
2417 if ((present == TAB_LIKE) || (present == FIG_LIKE)) {
2418 DocBookHandleCaption(file, inner_tag, depth,
2422 sgmlOpenTag(file, depth+1, inner_tag);
2425 // ignore all caption here, we processed them above!!!
2426 if (par->layout != textclasslist.NumberOfLayout(params.textclass,
2427 "Caption").second) {
2428 SimpleDocBookOnePar(tmp_par, extra_par, par,
2431 tmp_par = frontStrip(strip(tmp_par));
2436 fprintf(file, "%s", tmp_par.c_str());
2437 if(!inner_tag.empty()) sgmlCloseTag(file, depth+1, inner_tag);
2438 if(!extra_par.empty()) fprintf(file, "%s", extra_par.c_str());
2439 if(!tag.empty()) sgmlCloseTag(file, depth, tag);
2444 /* push a tag in a style stack */
2445 void Buffer::push_tag(FILE * file, char const * tag,
2446 int & pos, char stack[5][3])
2450 /* pop all previous tags */
2451 for (j = pos; j >= 0; j--)
2452 fprintf(file, "</%s>", stack[j]);
2455 sprintf(stack[++pos], "%s", tag);
2458 for (j= 0; j<= pos; j++)
2459 fprintf(file, "<%s>", stack[j]);
2463 // pop a tag from a style stack
2464 void Buffer::pop_tag(FILE * file, char const * tag,
2465 int & pos, char stack[5][3])
2469 // pop all tags till specified one
2470 for (j= pos; (j>= 0) && (strcmp(stack[j], tag)); j--)
2471 fprintf(file, "</%s>", stack[j]);
2474 fprintf(file, "</%s>", tag);
2476 // push all tags, but the specified one
2477 for (j= j+1; j<= pos; j++) {
2478 fprintf(file, "<%s>", stack[j]);
2479 strcpy(stack[j-1], stack[j]);
2485 /* handle internal paragraph parsing -- layout already processed */
2487 // checks, if newcol chars should be put into this line
2488 // writes newline, if necessary.
2490 void linux_doc_line_break(FILE * file, unsigned int & colcount,
2491 const unsigned int newcol)
2494 if (colcount > lyxrc->ascii_linelen) {
2495 fprintf(file, "\n");
2496 colcount = newcol; // assume write after this call
2501 void Buffer::SimpleLinuxDocOnePar(FILE * file, LyXParagraph * par,
2502 int desc_on, int const depth)
2504 LyXFont font1, font2;
2507 LyXParagraph::size_type main_body;
2509 LyXLayout const & style = textclasslist.Style(params.textclass,
2512 char family_type = 0; // family font flag
2513 bool is_bold = false; // series font flag
2514 char shape_type = 0; // shape font flag
2515 bool is_em = false; // emphasis (italic) font flag
2517 int stack_num = -1; // style stack position
2518 char stack[5][3]; // style stack
2519 unsigned int char_line_count = 5; // Heuristic choice ;-)
2521 if (style.labeltype != LABEL_MANUAL)
2524 main_body = par->BeginningOfMainBody();
2526 /* gets paragraph main font */
2528 font1 = style.labelfont;
2533 /* parsing main loop */
2534 for (LyXParagraph::size_type i = 0;
2535 i < par->size(); ++i) {
2537 /* handle quote tag */
2538 if (i == main_body && !par->IsDummy()) {
2543 font2 = par->getFont(i);
2545 if (font1.family() != font2.family()) {
2546 switch(family_type) {
2548 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2549 push_tag(file, "tt", stack_num, stack);
2552 else if (font2.family() == LyXFont::SANS_FAMILY) {
2553 push_tag(file, "sf", stack_num, stack);
2558 pop_tag(file, "tt", stack_num, stack);
2559 if (font2.family() == LyXFont::SANS_FAMILY) {
2560 push_tag(file, "sf", stack_num, stack);
2568 pop_tag(file, "sf", stack_num, stack);
2569 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2570 push_tag(file, "tt", stack_num, stack);
2579 /* handle bold face */
2580 if (font1.series() != font2.series()) {
2581 if (font2.series() == LyXFont::BOLD_SERIES) {
2582 push_tag(file, "bf", stack_num, stack);
2586 pop_tag(file, "bf", stack_num, stack);
2591 /* handle italic and slanted fonts */
2592 if (font1.shape() != font2.shape()) {
2593 switch(shape_type) {
2595 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2596 push_tag(file, "it", stack_num, stack);
2599 else if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2600 push_tag(file, "sl", stack_num, stack);
2605 pop_tag(file, "it", stack_num, stack);
2606 if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2607 push_tag(file, "sl", stack_num, stack);
2615 pop_tag(file, "sl", stack_num, stack);
2616 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2617 push_tag(file, "it", stack_num, stack);
2625 /* handle <em> tag */
2626 if (font1.emph() != font2.emph()) {
2627 if (font2.emph() == LyXFont::ON) {
2628 push_tag(file, "em", stack_num, stack);
2631 pop_tag(file, "em", stack_num, stack);
2636 c = par->GetChar(i);
2638 if (font2.latex() == LyXFont::ON) {
2639 // "TeX"-Mode on == > SGML-Mode on.
2641 fprintf(file, "%c", c); // see LaTeX-Generation...
2643 } else if (c == LyXParagraph::META_INSET) {
2644 inset = par->GetInset(i);
2646 inset->Linuxdoc(tmp_out);
2647 fprintf(file, "%s", tmp_out.c_str());
2651 if (par->linuxDocConvertChar(c, sgml_string)
2652 && !style.free_spacing) { // in freespacing
2654 // non-breaking characters
2658 linux_doc_line_break(file, char_line_count, 6);
2659 fprintf(file, "</tag>");
2663 linux_doc_line_break(file, char_line_count, 1);
2664 fprintf(file, "%c", c);
2668 fprintf(file, "%s", sgml_string.c_str());
2669 char_line_count += sgml_string.length();
2675 /* needed if there is an optional argument but no contents */
2676 if (main_body > 0 && main_body == par->size()) {
2680 /* pop all defined Styles */
2681 for (j = stack_num; j >= 0; j--) {
2682 linux_doc_line_break(file,
2684 3+strlen(stack[j]));
2685 fprintf(file, "</%s>", stack[j]);
2688 /* resets description flag correctly */
2691 /* <tag> not closed... */
2692 linux_doc_line_break(file, char_line_count, 6);
2693 fprintf(file, "</tag>");
2696 /* fprintf(file, "</p>");*/
2702 /* print an error message */
2703 void Buffer::LinuxDocError(LyXParagraph * par, int pos,
2704 char const * message)
2706 InsetError * new_inset;
2708 /* insert an error marker in text */
2709 new_inset = new InsetError(message);
2710 par->InsertChar(pos, LyXParagraph::META_INSET);
2711 par->InsertInset(pos, new_inset);
2714 // This constant defines the maximum number of
2715 // environment layouts that can be nesteded.
2716 // The same applies for command layouts.
2717 // These values should be more than enough.
2718 // José Matos (1999/07/22)
2720 enum { MAX_NEST_LEVEL = 25};
2722 void Buffer::makeDocBookFile(string const & filename, int column)
2724 LyXParagraph * par = paragraph;
2726 string top_element= textclasslist.LatexnameOfClass(params.textclass);
2727 string environment_stack[MAX_NEST_LEVEL];
2728 string environment_inner[MAX_NEST_LEVEL];
2729 string command_stack[MAX_NEST_LEVEL];
2730 bool command_flag= false;
2731 int command_depth= 0, command_base= 0, cmd_depth= 0;
2733 string item_name, command_name;
2734 string c_depth, c_params, tmps;
2736 int depth= 0; /* paragraph depth */
2738 FilePtr file(filename, FilePtr::write);
2739 tex_code_break_column = column;
2742 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), filename);
2750 "<!doctype %s public \"-//OASIS//DTD DocBook V3.1//EN\"",
2751 top_element.c_str());
2753 if (params.preamble.empty())
2754 fprintf(file, ">\n\n");
2756 fprintf(file, "\n [ %s \n]>\n\n", params.preamble.c_str() );
2758 string userName(getUserName());
2760 "<!-- DocBook file was created by LyX 1.0 (C) 1995-1999\n");
2761 fprintf(file, "by <%s> %s -->\n", userName.c_str(), (char *)date());
2763 if(params.options.empty())
2764 sgmlOpenTag(file, 0, top_element);
2766 string top = top_element;
2768 top += params.options;
2769 sgmlOpenTag(file, 0, top);
2773 int desc_on= 0; /* description mode*/
2774 LyXLayout const & style = textclasslist.Style(GetCurrentTextClass(),
2776 par->AutoDeleteInsets();
2778 /* environment tag closing */
2779 for( ;depth > par->depth; depth--) {
2780 if(environment_inner[depth] != "!-- --") {
2781 item_name= "listitem";
2782 sgmlCloseTag(file, command_depth+depth,
2784 if( environment_inner[depth] == "varlistentry")
2785 sgmlCloseTag(file, depth+command_depth,
2786 environment_inner[depth]);
2788 sgmlCloseTag(file, depth+command_depth,
2789 environment_stack[depth]);
2790 environment_stack[depth].clear();
2791 environment_inner[depth].clear();
2794 if(depth == par->depth
2795 && environment_stack[depth] != style.latexname()
2796 && !environment_stack[depth].empty()) {
2797 if(environment_inner[depth] != "!-- --") {
2798 item_name= "listitem";
2799 sgmlCloseTag(file, command_depth+depth,
2801 if( environment_inner[depth] == "varlistentry")
2802 sgmlCloseTag(file, depth+command_depth,
2803 environment_inner[depth]);
2806 sgmlCloseTag(file, depth+command_depth,
2807 environment_stack[depth]);
2809 environment_stack[depth].clear();
2810 environment_inner[depth].clear();
2813 // Write opening SGML tags.
2814 switch(style.latextype) {
2815 case LATEX_PARAGRAPH:
2816 if(style.latexname() != "dummy")
2817 sgmlOpenTag(file, depth+command_depth,
2823 LinuxDocError(par, 0,
2824 _("Error : Wrong depth for "
2825 "LatexType Command.\n"));
2827 command_name = style.latexname();
2829 tmps = style.latexparam();
2830 c_params = split(tmps, c_depth,'|');
2832 cmd_depth= atoi(c_depth.c_str());
2835 if(cmd_depth<command_base) {
2836 for(int j = command_depth;
2837 j >= command_base; j--)
2838 if(!command_stack[j].empty())
2839 sgmlCloseTag(file, j, command_stack[j]);
2840 command_depth= command_base= cmd_depth;
2842 else if(cmd_depth<= command_depth) {
2843 for(int j= command_depth;
2844 j >= cmd_depth; j--)
2846 if(!command_stack[j].empty())
2847 sgmlCloseTag(file, j, command_stack[j]);
2848 command_depth= cmd_depth;
2851 command_depth= cmd_depth;
2854 command_depth = command_base = cmd_depth;
2855 command_flag = true;
2857 command_stack[command_depth]= command_name;
2859 // treat label as a special case for
2860 // more WYSIWYM handling.
2861 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2862 Inset *inset = par->GetInset(0);
2863 char lyx_code = inset->LyxCode();
2864 if (lyx_code == Inset::LABEL_CODE){
2865 command_name+= " id= \"";
2866 command_name+= ((InsetCommand *) inset)->getContents();
2867 command_name+= "\"";
2872 sgmlOpenTag(file, depth+command_depth, command_name);
2874 sgmlOpenTag(file, depth+1+command_depth, item_name);
2877 case LATEX_ENVIRONMENT:
2878 case LATEX_ITEM_ENVIRONMENT:
2879 if (depth < par->depth) {
2881 environment_stack[depth].clear();
2884 if (environment_stack[depth] != style.latexname()) {
2885 environment_stack[depth]= style.latexname();
2886 environment_inner[depth]= "!-- --";
2887 sgmlOpenTag(file, depth + command_depth,
2888 environment_stack[depth]);
2890 if(environment_inner[depth] != "!-- --") {
2891 item_name= "listitem";
2893 command_depth + depth,
2895 if (environment_inner[depth] == "varlistentry")
2897 depth+command_depth,
2898 environment_inner[depth]);
2902 if(style.latextype == LATEX_ENVIRONMENT) {
2903 if(!style.latexparam().empty())
2904 sgmlOpenTag(file, depth+command_depth,
2905 style.latexparam());
2909 desc_on = (style.labeltype == LABEL_MANUAL);
2912 environment_inner[depth]= "varlistentry";
2914 environment_inner[depth]= "listitem";
2916 sgmlOpenTag(file, depth+1+command_depth,
2917 environment_inner[depth]);
2921 sgmlOpenTag(file, depth+1+command_depth,
2926 sgmlOpenTag(file, depth+1+command_depth,
2931 sgmlOpenTag(file, depth + command_depth,
2937 string tmp_par, extra_par;
2939 SimpleDocBookOnePar(tmp_par, extra_par, par, desc_on,
2940 depth+1+command_depth);
2941 fprintf(file, "%s", tmp_par.c_str());
2944 DocBookHandleFootnote(file, par, depth+1+command_depth);
2946 while(par && par->IsDummy());
2949 /* write closing SGML tags */
2950 switch(style.latextype) {
2953 sgmlCloseTag(file, depth + command_depth, end_tag);
2955 case LATEX_ENVIRONMENT:
2956 if(!style.latexparam().empty())
2957 sgmlCloseTag(file, depth + command_depth,
2958 style.latexparam());
2960 case LATEX_ITEM_ENVIRONMENT:
2961 if(desc_on == 1) break;
2963 sgmlCloseTag(file, depth+1+command_depth, end_tag);
2965 case LATEX_PARAGRAPH:
2966 if(style.latexname() != "dummy")
2967 sgmlCloseTag(file, depth + command_depth,
2971 sgmlCloseTag(file, depth+command_depth,
2978 for(;depth>= 0;depth--) {
2979 if(!environment_stack[depth].empty()) {
2980 if(environment_inner[depth] != "!-- --") {
2981 item_name= "listitem";
2982 sgmlCloseTag(file, command_depth+depth,
2984 if( environment_inner[depth] == "varlistentry")
2985 sgmlCloseTag(file, depth+command_depth,
2986 environment_inner[depth]);
2989 sgmlCloseTag(file, depth+command_depth,
2990 environment_stack[depth]);
2994 for(int j= command_depth;j>= command_base;j--)
2995 if(!command_stack[j].empty())
2996 sgmlCloseTag(file, j, command_stack[j]);
2998 fprintf(file, "\n\n");
2999 sgmlCloseTag(file, 0, top_element);
3002 WriteFSAlert(_("Error! Could not close file properly:"),
3008 void Buffer::SimpleDocBookOnePar(string & file, string & extra,
3009 LyXParagraph * par, int & desc_on,
3013 par->SimpleDocBookOneTablePar(file, extra, desc_on, depth);
3016 LyXFont font1, font2;
3019 LyXParagraph::size_type main_body;
3021 string emph= "emphasis";
3022 bool emph_flag= false;
3023 int char_line_count= 0;
3025 LyXLayout const & style = textclasslist.Style(params.textclass,
3028 if (style.labeltype != LABEL_MANUAL)
3031 main_body = par->BeginningOfMainBody();
3033 /* gets paragraph main font */
3035 font1 = style.labelfont;
3039 char_line_count = depth;
3040 if(!style.free_spacing)
3041 for (j= 0;j< depth;j++)
3044 /* parsing main loop */
3045 for (LyXParagraph::size_type i = 0;
3046 i < par->size(); ++i) {
3047 font2 = par->getFont(i);
3049 /* handle <emphasis> tag */
3050 if (font1.emph() != font2.emph() && i) {
3051 if (font2.emph() == LyXFont::ON) {
3052 file += "<emphasis>";
3055 file += "</emphasis>";
3060 c = par->GetChar(i);
3062 if (c == LyXParagraph::META_INSET) {
3063 inset = par->GetInset(i);
3065 inset->DocBook(tmp_out);
3067 // This code needs some explanation:
3068 // Two insets are treated specially
3069 // label if it is the first element in a command paragraph
3071 // graphics inside tables or figure floats can't go on
3072 // title (the equivalente in latex for this case is caption
3073 // and title should come first
3076 if(desc_on!= 3 || i!= 0) {
3077 if(tmp_out[0] == '@') {
3079 extra += frontStrip(tmp_out, '@');
3081 file += frontStrip(tmp_out, '@');
3086 } else if (font2.latex() == LyXFont::ON) {
3087 // "TeX"-Mode on == > SGML-Mode on.
3094 if (par->linuxDocConvertChar(c, sgml_string)
3095 && !style.free_spacing) { // in freespacing
3097 // non-breaking characters
3102 file += "</term><listitem><para>";
3110 file += sgml_string;
3116 /* needed if there is an optional argument but no contents */
3117 if (main_body > 0 && main_body == par->size()) {
3121 file += "</emphasis>";
3124 /* resets description flag correctly */
3127 /* <term> not closed... */
3135 bool Buffer::removeAutoInsets()
3137 LyXParagraph *par = paragraph;
3139 LyXCursor cursor = text->cursor;
3140 LyXCursor tmpcursor = cursor;
3141 cursor.par = tmpcursor.par->ParFromPos(tmpcursor.pos);
3142 cursor.pos = tmpcursor.par->PositionInParFromPos(tmpcursor.pos);
3146 if (par->AutoDeleteInsets()){
3148 if (par->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE){
3149 /* this is possible now, since SetCursor takes
3150 care about footnotes */
3151 text->SetCursorIntern(par, 0);
3152 text->RedoParagraphs(text->cursor, text->cursor.par->Next());
3153 text->FullRebreak();
3158 /* avoid forbidden cursor positions caused by error removing */
3159 if (cursor.pos > cursor.par->Last())
3160 cursor.pos = cursor.par->Last();
3161 text->SetCursorIntern(cursor.par, cursor.pos);
3167 int Buffer::runLaTeX()
3169 if (!text) return 0;
3173 // get LaTeX-Filename
3174 string name = SpaceLess(ChangeExtension (filename, ".tex", true));
3176 string path = OnlyPath(filename);
3178 string org_path = path;
3179 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
3183 Path p(path); // path to LaTeX file
3184 users->owner()->getMiniBuffer()->Set(_("Running LaTeX..."));
3186 // Remove all error insets
3187 bool a = removeAutoInsets();
3189 // Always generate the LaTeX file
3190 makeLaTeXFile(name, org_path, false);
3193 // do the LaTex run(s)
3195 LaTeX latex(lyxrc->latex_command, name, filepath);
3196 int res = latex.run(terr,
3197 users->owner()->getMiniBuffer()); // running latex
3199 // check return value from latex.run().
3200 if ((res & LaTeX::NO_LOGFILE)) {
3201 WriteAlert(_("LaTeX did not work!"),
3202 _("Missing log file:"), name);
3203 } else if ((res & LaTeX::ERRORS)) {
3204 users->owner()->getMiniBuffer()->Set(_("Done"));
3205 // Insert all errors as errors boxes
3208 // Dvi should also be kept dirty if the latex run
3209 // ends up with errors. However it should be possible
3210 // to view a dirty dvi too.
3212 //no errors or any other things to think about so:
3213 users->owner()->getMiniBuffer()->Set(_("Done"));
3217 // if we removed error insets before we ran LaTeX or if we inserted
3218 // error insets after we ran LaTeX this must be run:
3219 if (a || (res & LaTeX::ERRORS)){
3222 users->updateScrollbar();
3226 return latex.getNumErrors();
3230 int Buffer::runLiterate()
3232 if (!text) return 0;
3236 // get LaTeX-Filename
3237 string name = SpaceLess(ChangeExtension (filename, ".tex", true));
3238 // get Literate-Filename
3239 string lit_name = SpaceLess(ChangeExtension (filename, lyxrc->literate_extension, true));
3241 string path = OnlyPath(filename);
3243 string org_path = path;
3244 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
3248 Path p(path); // path to Literate file
3249 users->owner()->getMiniBuffer()->Set(_("Running Literate..."));
3251 // Remove all error insets
3252 bool a = removeAutoInsets();
3254 // generate the Literate file if necessary
3255 if (!isDviClean() || a) {
3256 makeLaTeXFile(lit_name, org_path, false);
3260 Literate literate(lyxrc->latex_command, name, filepath,
3262 lyxrc->literate_command, lyxrc->literate_error_filter,
3263 lyxrc->build_command, lyxrc->build_error_filter);
3265 int res = literate.weave(terr, users->owner()->getMiniBuffer());
3267 // check return value from literate.weave().
3268 if ((res & Literate::NO_LOGFILE)) {
3269 WriteAlert(_("Literate command did not work!"),
3270 _("Missing log file:"), name);
3271 } else if ((res & Literate::ERRORS)) {
3272 users->owner()->getMiniBuffer()->Set(_("Done"));
3273 // Insert all errors as errors boxes
3276 // Dvi should also be kept dirty if the latex run
3277 // ends up with errors. However it should be possible
3278 // to view a dirty dvi too.
3280 //no errors or any other things to think about so:
3281 users->owner()->getMiniBuffer()->Set(_("Done"));
3285 // if we removed error insets before we ran LaTeX or if we inserted
3286 // error insets after we ran LaTeX this must be run:
3287 if (a || (res & Literate::ERRORS)){
3290 users->updateScrollbar();
3294 return literate.getNumErrors();
3298 int Buffer::buildProgram()
3300 if (!text) return 0;
3304 // get LaTeX-Filename
3305 string name = SpaceLess(ChangeExtension (filename, ".tex", true));
3306 // get Literate-Filename
3307 string lit_name = SpaceLess(ChangeExtension (filename, lyxrc->literate_extension, true));
3309 string path = OnlyPath(filename);
3311 string org_path = path;
3312 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
3316 Path p(path); // path to Literate file
3317 users->owner()->getMiniBuffer()->Set(_("Building Program..."));
3319 // Remove all error insets
3320 bool a = removeAutoInsets();
3322 // generate the LaTeX file if necessary
3323 if (!isNwClean() || a) {
3324 makeLaTeXFile(lit_name, org_path, false);
3328 Literate literate(lyxrc->latex_command, name, filepath,
3330 lyxrc->literate_command, lyxrc->literate_error_filter,
3331 lyxrc->build_command, lyxrc->build_error_filter);
3333 int res = literate.build(terr, users->owner()->getMiniBuffer());
3335 // check return value from literate.build().
3336 if ((res & Literate::NO_LOGFILE)) {
3337 WriteAlert(_("Build did not work!"),
3338 _("Missing log file:"), name);
3339 } else if ((res & Literate::ERRORS)) {
3340 users->owner()->getMiniBuffer()->Set(_("Done"));
3341 // Insert all errors as errors boxes
3344 // Literate files should also be kept dirty if the literate
3345 // command run ends up with errors.
3347 //no errors or any other things to think about so:
3348 users->owner()->getMiniBuffer()->Set(_("Done"));
3352 // if we removed error insets before we ran Literate/Build or if we inserted
3353 // error insets after we ran Literate/Build this must be run:
3354 if (a || (res & Literate::ERRORS)){
3357 users->updateScrollbar();
3361 return literate.getNumErrors();
3365 // This should be enabled when the Chktex class is implemented. (Asger)
3366 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
3367 // Other flags: -wall -v0 -x
3368 int Buffer::runChktex()
3370 if (!text) return 0;
3374 // get LaTeX-Filename
3375 string name = SpaceLess(ChangeExtension (filename, ".tex", true));
3376 string path = OnlyPath(filename);
3378 string org_path = path;
3379 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
3383 Path p(path); // path to LaTeX file
3384 users->owner()->getMiniBuffer()->Set(_("Running chktex..."));
3386 // Remove all error insets
3387 bool a = removeAutoInsets();
3389 // Generate the LaTeX file if neccessary
3390 if (!isDviClean() || a) {
3391 makeLaTeXFile(name, org_path, false);
3396 Chktex chktex(lyxrc->chktex_command, name, filepath);
3397 int res = chktex.run(terr); // run chktex
3400 WriteAlert(_("chktex did not work!"),
3401 _("Could not run with file:"), name);
3402 } else if (res > 0) {
3403 // Insert all errors as errors boxes
3407 // if we removed error insets before we ran chktex or if we inserted
3408 // error insets after we ran chktex, this must be run:
3412 users->updateScrollbar();
3420 extern void AllFloats(char, char);
3423 void Buffer::insertErrors(TeXErrors & terr)
3425 // Save the cursor position
3426 LyXCursor cursor = text->cursor;
3428 // This is drastic, but it's the only fix, I could find. (Asger)
3432 for (TeXErrors::Errors::const_iterator cit = terr.begin();
3435 string desctext((*cit).error_desc);
3436 string errortext((*cit).error_text);
3437 string msgtxt = desctext + '\n' + errortext;
3438 int errorrow = (*cit).error_in_line;
3440 // Insert error string for row number
3444 texrow.getIdFromRow(errorrow, tmpid, tmppos);
3446 LyXParagraph* texrowpar;
3449 texrowpar = text->FirstParagraph();
3452 texrowpar = text->GetParFromID(tmpid);
3458 InsetError *new_inset = new InsetError(msgtxt);
3460 text->SetCursorIntern(texrowpar, tmppos);
3461 text->InsertInset(new_inset);
3462 text->FullRebreak();
3464 // Restore the cursor position
3465 text->SetCursorIntern(cursor.par, cursor.pos);
3469 void Buffer::setCursorFromRow (int row)
3474 texrow.getIdFromRow(row, tmpid, tmppos);
3476 LyXParagraph* texrowpar;
3479 texrowpar = text->FirstParagraph();
3482 texrowpar = text->GetParFromID(tmpid);
3484 text->SetCursor(texrowpar, tmppos);
3488 void Buffer::RoffAsciiTable(FILE * file, LyXParagraph * par)
3491 font1 = LyXFont(LyXFont::ALL_INHERIT),
3494 LyXParagraph::size_type i;
3503 string fname1 = TmpFileName(string(), "RAT1");
3504 string fname2 = TmpFileName(string(), "RAT2");
3505 if (!(fp= fopen(fname1.c_str(), "w"))) {
3506 WriteAlert(_("LYX_ERROR:"),
3507 _("Cannot open temporary file:"), fname1);
3510 par->table->RoffEndOfCell(fp, -1);
3511 for (i = 0; i < par->size(); ++i) {
3512 c = par->GetChar(i);
3513 if (par->table->IsContRow(cell)) {
3514 if (c == LyXParagraph::META_NEWLINE)
3518 font2 = par->GetFontSettings(i);
3519 if (font1.latex() != font2.latex()) {
3520 if (font2.latex() != LyXFont::OFF)
3524 case LyXParagraph::META_INSET:
3525 if ((inset = par->GetInset(i))) {
3526 if (!(fp2= fopen(fname2.c_str(), "w+"))) {
3527 WriteAlert(_("LYX_ERROR:"),
3528 _("Cannot open temporary file:"), fname2);
3530 remove(fname1.c_str());
3533 inset->Latex(fp2,-1);
3538 fprintf(fp, "\\\\");
3546 case LyXParagraph::META_NEWLINE:
3547 if (par->table->CellHasContRow(cell)>= 0)
3548 par->RoffContTableRows(fp, i+1, cell);
3549 par->table->RoffEndOfCell(fp, cell);
3552 case LyXParagraph::META_HFILL:
3554 case LyXParagraph::META_PROTECTED_SEPARATOR:
3557 fprintf(fp, "\\\\");
3561 fprintf(fp, "%c", c);
3564 << "RoffAsciiTable:"
3565 " NULL char in structure." << endl;
3569 par->table->RoffEndOfCell(fp, cell);
3571 string cmd = lyxrc->ascii_roff_command + " >" + fname2;
3572 cmd = subst(cmd, "$$FName", fname1);
3573 Systemcalls one(Systemcalls::System, cmd);
3574 if (!(lyxerr.debugging(Debug::ROFF))) {
3575 remove(fname1.c_str());
3577 if (!(fp= fopen(fname2.c_str(), "r"))) {
3578 WriteFSAlert(_("Error! Can't open temporary file:"), fname2);
3581 // now output the produced file
3582 fprintf(file, "\n\n");
3585 WriteAlert(_("Error!"),
3586 _("Error executing *roff command on table"));
3587 // overread leading blank lines
3588 while(!feof(fp) && (c == '\n'))
3591 for(j= 0; j<par->depth; j++)
3593 while(!feof(fp) && (c != '\n')) {
3598 // overread trailing blank lines
3599 while(!feof(fp) && (c == '\n'))
3603 remove(fname2.c_str());
3607 /// changed Heinrich Bauer, 23/03/98
3608 bool Buffer::isDviClean()
3610 if (lyxrc->use_tempdir)
3611 return dvi_clean_tmpd;
3613 return dvi_clean_orgd;
3617 /// changed Heinrich Bauer, 23/03/98
3618 void Buffer::markDviClean()
3620 if (lyxrc->use_tempdir)
3621 dvi_clean_tmpd = true;
3623 dvi_clean_orgd = true;
3627 /// changed Heinrich Bauer, 23/03/98
3628 void Buffer::markDviDirty()
3630 if (lyxrc->use_tempdir)
3631 dvi_clean_tmpd = false;
3633 dvi_clean_orgd = false;
3637 void Buffer::update(signed char f)
3641 users->owner()->updateLayoutChoice();
3643 if (!text->selection && f > -3)
3644 text->sel_cursor = text->cursor;
3647 text->FullRebreak();
3650 if (f != 3 && f != -3) {
3652 users->updateScrollbar();
3655 if (f == 1 || f == -1) {
3658 users->owner()->getMiniBuffer()->setTimer(4);
3666 void Buffer::validate(LaTeXFeatures & features)
3668 LyXParagraph * par = paragraph;
3669 LyXTextClass const & tclass =
3670 textclasslist.TextClass(params.textclass);
3672 // AMS Style is at document level
3674 features.amsstyle = (params.use_amsmath ||
3675 tclass.provides(LyXTextClass::amsmath));
3678 // We don't use "lyxerr.debug" because of speed. (Asger)
3679 if (lyxerr.debugging(Debug::LATEX))
3680 lyxerr << "Paragraph: " << par << endl;
3682 // Now just follow the list of paragraphs and run
3683 // validate on each of them.
3684 par->validate(features);
3686 // and then the next paragraph
3690 // the bullet shapes are buffer level not paragraph level
3691 // so they are tested here
3692 for (int i = 0; i < 4; ++i) {
3693 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
3694 int font = params.user_defined_bullets[i].getFont();
3697 .user_defined_bullets[i]
3704 features.latexsym = true;
3708 features.amssymb = true;
3710 else if ((font >= 2 && font <= 5)) {
3711 features.pifont = true;
3716 if (lyxerr.debugging(Debug::LATEX)) {
3717 features.showStruct(params);
3722 void Buffer::setPaperStuff()
3724 params.papersize = BufferParams::PAPER_DEFAULT;
3725 char c1 = params.paperpackage;
3726 if (c1 == BufferParams::PACKAGE_NONE) {
3727 char c2 = params.papersize2;
3728 if (c2 == BufferParams::VM_PAPER_USLETTER)
3729 params.papersize = BufferParams::PAPER_USLETTER;
3730 else if (c2 == BufferParams::VM_PAPER_USLEGAL)
3731 params.papersize = BufferParams::PAPER_LEGALPAPER;
3732 else if (c2 == BufferParams::VM_PAPER_USEXECUTIVE)
3733 params.papersize = BufferParams::PAPER_EXECUTIVEPAPER;
3734 else if (c2 == BufferParams::VM_PAPER_A3)
3735 params.papersize = BufferParams::PAPER_A3PAPER;
3736 else if (c2 == BufferParams::VM_PAPER_A4)
3737 params.papersize = BufferParams::PAPER_A4PAPER;
3738 else if (c2 == BufferParams::VM_PAPER_A5)
3739 params.papersize = BufferParams::PAPER_A5PAPER;
3740 else if ((c2 == BufferParams::VM_PAPER_B3) || (c2 == BufferParams::VM_PAPER_B4) ||
3741 (c2 == BufferParams::VM_PAPER_B5))
3742 params.papersize = BufferParams::PAPER_B5PAPER;
3743 } else if ((c1 == BufferParams::PACKAGE_A4) || (c1 == BufferParams::PACKAGE_A4WIDE) ||
3744 (c1 == BufferParams::PACKAGE_WIDEMARGINSA4))
3745 params.papersize = BufferParams::PAPER_A4PAPER;
3750 void Buffer::setOldPaperStuff()
3752 char c = params.papersize = params.papersize2;
3753 params.papersize2 = BufferParams::VM_PAPER_DEFAULT;
3754 params.paperpackage = BufferParams::PACKAGE_NONE;
3755 if (c == OLD_PAPER_A4PAPER)
3756 params.papersize2 = BufferParams::VM_PAPER_A4;
3757 else if (c == OLD_PAPER_A4)
3758 params.paperpackage = BufferParams::PACKAGE_A4;
3759 else if (c == OLD_PAPER_A4WIDE)
3760 params.paperpackage = BufferParams::PACKAGE_A4WIDE;
3761 else if (c == OLD_PAPER_WIDEMARGINSA4)
3762 params.paperpackage = BufferParams::PACKAGE_WIDEMARGINSA4;
3763 else if (c == OLD_PAPER_USLETTER)
3764 params.papersize2 = BufferParams::VM_PAPER_USLETTER;
3765 else if (c == OLD_PAPER_A5PAPER)
3766 params.papersize2 = BufferParams::VM_PAPER_A5;
3767 else if (c == OLD_PAPER_B5PAPER)
3768 params.papersize2 = BufferParams::VM_PAPER_B5;
3769 else if (c == OLD_PAPER_EXECUTIVEPAPER)
3770 params.papersize2 = BufferParams::VM_PAPER_USEXECUTIVE;
3771 else if (c == OLD_PAPER_LEGALPAPER)
3772 params.papersize2 = BufferParams::VM_PAPER_USLEGAL;
3777 void Buffer::insertInset(Inset * inset, string const & lout,
3780 // check for table/list in tables
3781 if (no_table && text->cursor.par->table){
3782 WriteAlert(_("Impossible Operation!"),
3783 _("Cannot insert table/list in table."),
3787 // not quite sure if we want this...
3788 text->SetCursorParUndo();
3792 if (!lout.empty()) {
3794 text->BreakParagraph();
3797 if (text->cursor.par->Last()) {
3800 text->BreakParagraph();
3804 int lay = textclasslist.NumberOfLayout(params.textclass,
3806 if (lay == -1) // layout not found
3807 // use default layout "Standard" (0)
3810 text->SetLayout(lay);
3812 text->SetParagraph(0, 0,
3814 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3820 text->current_font.setLatex(LyXFont::OFF);
3823 text->InsertInset(inset);
3826 text->UnFreezeUndo();
3830 // Open and lock an updatable inset
3831 void Buffer::open_new_inset(UpdatableInset * new_inset)
3835 insertInset(new_inset);
3838 new_inset->Edit(0, 0);
3842 /* This function should be in Buffer because it's a buffer's property (ale) */
3843 string Buffer::getIncludeonlyList(char delim)
3846 LyXParagraph * par = paragraph;
3847 LyXParagraph::size_type pos;
3851 while ((inset = par->ReturnNextInsetPointer(pos))){
3852 if (inset->LyxCode() == Inset::INCLUDE_CODE) {
3853 InsetInclude * insetinc =
3854 static_cast<InsetInclude*>(inset);
3855 if (insetinc->isInclude()
3856 && insetinc->isNoLoad()) {
3859 lst += ChangeExtension(insetinc->getContents(), string(), true);
3866 lyxerr.debug() << "Includeonly(" << lst << ')' << endl;
3871 /* This is also a buffer property (ale) */
3872 string Buffer::getReferenceList(char delim)
3874 /// if this is a child document and the parent is already loaded
3875 /// Use the parent's list instead [ale990407]
3876 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3877 Buffer *tmp = bufferlist.getBuffer(params.parentname);
3879 return tmp->getReferenceList(delim);
3882 LyXParagraph *par = paragraph;
3883 LyXParagraph::size_type pos;
3888 while ((inset = par->ReturnNextInsetPointer(pos))){
3889 for (int i = 0; i < inset->GetNumberOfLabels(); i++) {
3892 lst += inset->getLabel(i);
3898 lyxerr.debug() << "References(" << lst << ")" << endl;
3903 /* This is also a buffer property (ale) */
3904 string Buffer::getBibkeyList(char delim)
3906 /// if this is a child document and the parent is already loaded
3907 /// Use the parent's list instead [ale990412]
3908 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3909 Buffer *tmp = bufferlist.getBuffer(params.parentname);
3911 return tmp->getBibkeyList(delim);
3915 LyXParagraph * par = paragraph;
3918 if (!bibkeys.empty())
3920 bibkeys += par->bibkey->getContents();
3925 // Might be either using bibtex or a child has bibliography
3926 if (bibkeys.empty()) {
3930 LyXParagraph::size_type pos = -1;
3932 // Search for Bibtex or Include inset
3933 while ((inset = par->ReturnNextInsetPointer(pos))) {
3934 if (inset-> LyxCode() == Inset::BIBTEX_CODE) {
3935 if (!bibkeys.empty())
3937 bibkeys += static_cast<InsetBibtex*>(inset)->getKeys();
3938 } else if (inset-> LyxCode() == Inset::INCLUDE_CODE) {
3939 string bk = static_cast<InsetInclude*>(inset)->getKeys();
3941 if (!bibkeys.empty())
3952 lyxerr.debug() << "Bibkeys(" << bibkeys << ")" << endl;
3957 /* This is also a buffer property (ale) */
3958 // Not so sure about that. a goto Label function can not be buffer local, just
3959 // think how this will work in a multiwindo/buffer environment, all the
3960 // cursors in all the views showing this buffer will move. (Lgb)
3961 // OK, then no cursor action should be allowed in buffer. (ale)
3962 bool Buffer::gotoLabel(string const & label)
3965 LyXParagraph * par = paragraph;
3966 LyXParagraph::size_type pos;
3970 while ((inset = par->ReturnNextInsetPointer(pos))){
3971 for (int i = 0; i < inset->GetNumberOfLabels(); i++) {
3972 if (label == inset->getLabel(i)) {
3974 text->SetCursor(par, pos);
3975 text->sel_cursor = text->cursor;
3988 bool Buffer::isDepClean(string const & name) const
3990 DEPCLEAN * item = dep_clean;
3991 while (item && item->master != name)
3993 if (!item) return true;
3998 void Buffer::markDepClean(string const & name)
4001 dep_clean = new DEPCLEAN;
4002 dep_clean->clean = true;
4003 dep_clean->master = name;
4004 dep_clean->next = 0;
4006 DEPCLEAN* item = dep_clean;
4007 while (item && item->master != name)
4012 item = new DEPCLEAN;
4014 item->master = name;