1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-1999 The LyX Team.
9 * This file is Copyright 1996-1999
12 * ======================================================
17 // 23/03/98 Heinrich Bauer (heinrich.bauer@t-mobil.de)
18 // Spots marked "changed Heinrich Bauer, 23/03/98" modified due to the
19 // following bug: dvi file export did not work after printing (or previewing)
20 // and vice versa as long as the same file was concerned. This happened
21 // every time the LyX-file was left unchanged between the two actions mentioned
39 #pragma implementation "buffer.h"
43 #include "bufferlist.h"
45 #include "lyx_gui_misc.h"
46 #include "LyXAction.h"
49 #include "tex-strings.h"
52 #include "minibuffer.h"
55 #include "mathed/formulamacro.h"
56 #include "insets/lyxinset.h"
57 #include "insets/inseterror.h"
58 #include "insets/insetlabel.h"
59 #include "insets/insetref.h"
60 #include "insets/inseturl.h"
61 #include "insets/insetinfo.h"
62 #include "insets/insetquotes.h"
64 #include "insets/insetlatex.h"
66 #include "insets/insetlatexaccent.h"
67 #include "insets/insetbib.h"
68 #include "insets/insetindex.h"
69 #include "insets/insetinclude.h"
70 #include "insets/insettoc.h"
71 #include "insets/insetlof.h"
72 #include "insets/insetlot.h"
73 #include "insets/insetloa.h"
74 #include "insets/insetparent.h"
75 #include "insets/insetspecialchar.h"
76 #include "insets/figinset.h"
77 #include "support/filetools.h"
78 #include "support/path.h"
84 #include "LaTeXFeatures.h"
85 #include "support/syscall.h"
86 #include "support/lyxlib.h"
87 #include "support/FileInfo.h"
91 // Uncomment this line to enable a workaround for the weird behaviour
92 // of the cursor between a displayed inset and last character
93 // at the upper line. (Alejandro 20.9.96)
94 // #define BREAK_BEFORE_INSET
96 /* Lars, when changing this file sometime in the future to a list,
97 * please check out the figinsets-sideeffects described at the
98 * beginning of figinset.C Matthias (04.07.1996)
102 // all these externs should eventually be removed.
103 extern BufferList bufferlist;
104 extern void SmallUpdate(signed char);
105 extern unsigned char GetCurrentTextClass();
106 extern void BeforeChange();
108 extern void MenuExport(Buffer *, string const &);
109 extern LyXAction lyxaction;
112 static const float LYX_FORMAT = 2.15;
114 extern int tex_code_break_column;
116 extern void FreeUpdateTimer();
119 Buffer::Buffer(string const & file, LyXRC * lyxrc, bool ronly)
121 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
123 filepath = OnlyPath(file);
128 the_locking_inset = 0;
131 dvi_clean_orgd = false; // Heinrich Bauer, 23/03/98
132 dvi_clean_tmpd = false; // Heinrich Bauer, 23/03/98
138 if (read_only || (lyxrc && lyxrc->use_tempdir)) {
139 tmppath = CreateBufferTmpDir();
140 } else tmppath.clear();
146 lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
147 // here the buffer should take care that it is
148 // saved properly, before it goes into the void.
150 // make sure that views using this buffer
155 if (!tmppath.empty()) {
156 DestroyBufferTmpDir(tmppath);
159 LyXParagraph * par = paragraph;
160 LyXParagraph * tmppar;
173 bool Buffer::saveParamsAsDefaults()
175 string fname = AddName(AddPath(user_lyxdir, "templates/"),
177 Buffer defaults = Buffer(fname);
179 // Use the current buffer's parameters as default
180 defaults.params = params;
182 // add an empty paragraph. Is this enough?
183 defaults.paragraph = new LyXParagraph;
185 return defaults.writeFile(defaults.filename, false);
189 /// Update window titles of all users
190 // Should work on a list
191 void Buffer::updateTitles()
193 if (users) users->owner()->updateWindowTitle();
197 /// Reset autosave timer of all users
198 // Should work on a list
199 void Buffer::resetAutosaveTimers()
201 if (users) users->owner()->resetAutosaveTimer();
205 void Buffer::fileName(string const & newfile)
207 filename = MakeAbsPath(newfile);
208 filepath = OnlyPath(filename);
209 setReadonly(IsFileWriteable(filename) == 0);
214 // candidate for move to BufferView
215 void Buffer::InsetUnlock()
217 if (the_locking_inset) {
218 if (!inset_slept) the_locking_inset->InsetUnlock();
219 the_locking_inset = 0;
221 users->text->FinishUndo();
230 // candidate for move to BufferView
231 // Inserts a file into current document
232 bool Buffer::insertLyXFile(string const & filen)
234 // (c) CHT Software Service GmbH
237 // Insert a Lyxformat - file into current buffer
239 // Moved from lyx_cb.C (Lgb)
241 if (filen.empty()) return false;
243 string filename = MakeAbsPath(filen);
245 // check if file exist
246 FileInfo fi(filename);
248 if (!fi.readable()) {
249 WriteAlert(_("Error!"),
250 _("Specified file is unreadable: "),
251 MakeDisplayPath(filename, 50));
257 FilePtr myfile(filename, FilePtr::read);
259 WriteAlert(_("Error!"),
260 _("Cannot open specified file: "),
261 MakeDisplayPath(filename, 50));
266 int c = fgetc(myfile());
273 lyxerr.debug() << "Will insert file with header" << endl;
274 res = readFile(lex, users->text->cursor.par);
276 lyxerr.debug() << "Will insert file without header" << endl;
277 res = readLyXformat2(lex, users->text->cursor.par);
281 lyxerr.debug() << "Will insert file with header" << endl;
282 res = readFile(lex, text->cursor.par);
284 lyxerr.debug() << "Will insert file without header" << endl;
285 res = readLyXformat2(lex, text->cursor.par);
293 // candidate for move to BufferView
294 // (at least some parts in the beginning of the func)
297 // changed to be public and have one parameter
298 // if par = 0 normal behavior
299 // else insert behavior
300 // Returns false if "\the_end" is not read for formats >= 2.13. (Asger)
301 bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par)
307 char depth = 0; // signed or unsigned?
308 LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
309 LyXParagraph::footnote_kind footnotekind = LyXParagraph::FOOTNOTE;
310 bool the_end_read = false;
312 LyXParagraph * return_par = 0;
313 LyXFont font = LyXFont(LyXFont::ALL_INHERIT);
315 // If we are inserting, we cheat and get a token in advance
316 bool has_token = false;
320 par = new LyXParagraph;
323 users->text->BreakParagraph();
324 return_par = users->text->FirstParagraph();
326 text->BreakParagraph();
327 return_par = text->FirstParagraph();
331 // We don't want to adopt the parameters from the
332 // document we insert, so we skip until the text begins:
335 pretoken = lex.GetString();
336 if (pretoken == "\\layout") {
348 pretoken = lex.GetString();
351 // Profiling show this should give a lot: (Asger)
352 string const token = pretoken;
356 else if (token[0] != '\\') {
357 int n = token.length();
358 for (int i = 0; i < n; i++) {
359 par->InsertChar(pos, token[i]);
360 par->SetFont(pos, font);
363 } else if (token == "\\i") {
364 inset = new InsetLatexAccent;
366 par->InsertChar(pos, LyXParagraph::META_INSET);
368 par->InsertInset(pos, inset);
369 par->SetFont(pos, font);
371 } else if (token == "\\layout") {
375 par->text.resize(par->text.size());
376 par = new LyXParagraph(par);
380 string layoutname = lex.GetString();
381 pair<bool, LyXTextClass::LayoutList::size_type> pp
382 = textclasslist.NumberOfLayout(params.textclass,
385 par->layout = pp.second;
386 } else { // layout not found
387 // use default layout "Standard" (0)
390 // Test whether the layout is obsolete.
391 LyXLayout const & layout = textclasslist.Style(params.textclass,
393 if (!layout.obsoleted_by().empty())
395 textclasslist.NumberOfLayout(params.textclass,
396 layout.obsoleted_by()).second;
397 par->footnoteflag = footnoteflag;
398 par->footnotekind = footnotekind;
400 font = LyXFont(LyXFont::ALL_INHERIT);
401 } else if (token == "\\end_float") {
405 par->text.resize(par->text.size());
406 par = new LyXParagraph(par);
408 footnotekind = LyXParagraph::FOOTNOTE;
409 footnoteflag = LyXParagraph::NO_FOOTNOTE;
412 par->layout = LYX_DUMMY_LAYOUT;
413 font = LyXFont(LyXFont::ALL_INHERIT);
414 } else if (token == "\\begin_float") {
415 tmpret = lex.FindToken(string_footnotekinds);
416 if (tmpret == -1) tmpret++;
417 if (tmpret != LYX_LAYOUT_DEFAULT)
418 footnotekind = static_cast<LyXParagraph::footnote_kind>(tmpret); // bad
419 if (footnotekind == LyXParagraph::FOOTNOTE
420 || footnotekind == LyXParagraph::MARGIN)
421 footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
423 footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
424 } else if (token == "\\begin_deeper") {
426 } else if (token == "\\end_deeper") {
428 lex.printError("\\end_deeper: "
429 "depth is already null");
433 } else if (token == "\\begin_preamble") {
434 params.readPreamble(lex);
435 } else if (token == "\\textclass") {
437 pair<bool, LyXTextClassList::ClassList::size_type> pp =
438 textclasslist.NumberOfClass(lex.GetString());
440 params.textclass = pp.second;
442 lex.printError("Unknown textclass `$$Token'");
443 params.textclass = 0;
445 if (!textclasslist.Load(params.textclass)) {
446 // if the textclass wasn't loaded properly
447 // we need to either substitute another
448 // or stop loading the file.
449 // I can substitute but I don't see how I can
450 // stop loading... ideas?? ARRae980418
451 WriteAlert(_("Textclass Loading Error!"),
452 string(_("Can't load textclass ")) +
453 textclasslist.NameOfClass(params.textclass),
454 _("-- substituting default"));
455 params.textclass = 0;
457 } else if (token == "\\options") {
459 params.options = lex.GetString();
460 } else if (token == "\\language") {
461 params.readLanguage(lex);
462 } else if (token == "\\fontencoding") {
464 } else if (token == "\\inputencoding") {
466 params.inputenc = lex.GetString();
467 } else if (token == "\\graphics") {
468 params.readGraphicsDriver(lex);
469 } else if (token == "\\fontscheme") {
471 params.fonts = lex.GetString();
472 } else if (token == "\\noindent") {
473 par->noindent = true;
474 } else if (token == "\\fill_top") {
475 par->added_space_top = VSpace(VSpace::VFILL);
476 } else if (token == "\\fill_bottom") {
477 par->added_space_bottom = VSpace(VSpace::VFILL);
478 } else if (token == "\\line_top") {
479 par->line_top = true;
480 } else if (token == "\\line_bottom") {
481 par->line_bottom = true;
482 } else if (token == "\\pagebreak_top") {
483 par->pagebreak_top = true;
484 } else if (token == "\\pagebreak_bottom") {
485 par->pagebreak_bottom = true;
486 } else if (token == "\\start_of_appendix") {
487 par->start_of_appendix = true;
488 } else if (token == "\\paragraph_separation") {
489 tmpret = lex.FindToken(string_paragraph_separation);
490 if (tmpret == -1) tmpret++;
491 if (tmpret != LYX_LAYOUT_DEFAULT)
492 params.paragraph_separation =
493 static_cast<BufferParams::PARSEP>(tmpret);
494 } else if (token == "\\defskip") {
496 params.defskip = VSpace(lex.GetString());
497 } else if (token == "\\no_isolatin1") {
499 } else if (token == "\\no_babel") {
501 } else if (token == "\\no_epsfig") {
503 } else if (token == "\\epsfig") { // obsolete
504 // Indeed it is obsolete, but we HAVE to be backwards
505 // compatible until 0.14, because otherwise all figures
506 // in existing documents are irretrivably lost. (Asger)
507 params.readGraphicsDriver(lex);
508 } else if (token == "\\quotes_language") {
509 tmpret = lex.FindToken(string_quotes_language);
510 if (tmpret == -1) tmpret++;
511 if (tmpret != LYX_LAYOUT_DEFAULT) {
512 InsetQuotes::quote_language tmpl =
513 InsetQuotes::EnglishQ;
516 tmpl = InsetQuotes::EnglishQ;
519 tmpl = InsetQuotes::SwedishQ;
522 tmpl = InsetQuotes::GermanQ;
525 tmpl = InsetQuotes::PolishQ;
528 tmpl = InsetQuotes::FrenchQ;
531 tmpl = InsetQuotes::DanishQ;
534 params.quotes_language = tmpl;
536 } else if (token == "\\quotes_times") {
538 switch(lex.GetInteger()) {
540 params.quotes_times = InsetQuotes::SingleQ;
543 params.quotes_times = InsetQuotes::DoubleQ;
546 } else if (token == "\\papersize") {
550 tmpret = lex.FindToken(string_papersize);
553 tmpret = lex.FindToken(string_oldpapersize);
558 params.papersize2 = tmpret;
559 } else if (token == "\\paperpackage") {
560 tmpret = lex.FindToken(string_paperpackages);
563 params.paperpackage = BufferParams::PACKAGE_NONE;
565 params.paperpackage = tmpret;
566 } else if (token == "\\use_geometry") {
568 params.use_geometry = lex.GetInteger();
569 } else if (token == "\\use_amsmath") {
571 params.use_amsmath = lex.GetInteger();
572 } else if (token == "\\paperorientation") {
573 tmpret = lex.FindToken(string_orientation);
574 if (tmpret == -1) tmpret++;
575 if (tmpret != LYX_LAYOUT_DEFAULT)
576 params.orientation = static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
577 } else if (token == "\\paperwidth") {
579 params.paperwidth = lex.GetString();
580 } else if (token == "\\paperheight") {
582 params.paperheight = lex.GetString();
583 } else if (token == "\\leftmargin") {
585 params.leftmargin = lex.GetString();
586 } else if (token == "\\topmargin") {
588 params.topmargin = lex.GetString();
589 } else if (token == "\\rightmargin") {
591 params.rightmargin = lex.GetString();
592 } else if (token == "\\bottommargin") {
594 params.bottommargin = lex.GetString();
595 } else if (token == "\\headheight") {
597 params.headheight = lex.GetString();
598 } else if (token == "\\headsep") {
600 params.headsep = lex.GetString();
601 } else if (token == "\\footskip") {
603 params.footskip = lex.GetString();
604 } else if (token == "\\paperfontsize") {
606 params.fontsize = strip(lex.GetString());
607 } else if (token == "\\papercolumns") {
609 params.columns = lex.GetInteger();
610 } else if (token == "\\papersides") {
612 switch(lex.GetInteger()) {
614 case 1: params.sides = LyXTextClass::OneSide; break;
615 case 2: params.sides = LyXTextClass::TwoSides; break;
617 } else if (token == "\\paperpagestyle") {
619 params.pagestyle = strip(lex.GetString());
620 } else if (token == "\\bullet") {
622 int index = lex.GetInteger();
624 int temp_int = lex.GetInteger();
625 params.user_defined_bullets[index].setFont(temp_int);
626 params.temp_bullets[index].setFont(temp_int);
628 temp_int = lex.GetInteger();
629 params.user_defined_bullets[index].setCharacter(temp_int);
630 params.temp_bullets[index].setCharacter(temp_int);
632 temp_int = lex.GetInteger();
633 params.user_defined_bullets[index].setSize(temp_int);
634 params.temp_bullets[index].setSize(temp_int);
636 string temp_str = lex.GetString();
637 if (temp_str != "\\end_bullet") {
638 // this element isn't really necessary for
639 // parsing but is easier for humans
640 // to understand bullets. Put it back and
641 // set a debug message?
642 lex.printError("\\end_bullet expected, got" + temp_str);
643 //how can I put it back?
645 } else if (token == "\\bulletLaTeX") {
647 int index = lex.GetInteger();
649 string temp_str = lex.GetString(), sum_str;
650 while (temp_str != "\\end_bullet") {
651 // this loop structure is needed when user
652 // enters an empty string since the first
653 // thing returned will be the \\end_bullet
655 // if the LaTeX entry has spaces. Each element
656 // therefore needs to be read in turn
659 temp_str = lex.GetString();
661 params.user_defined_bullets[index].setText(sum_str);
662 params.temp_bullets[index].setText(sum_str);
663 } else if (token == "\\secnumdepth") {
665 params.secnumdepth = lex.GetInteger();
666 } else if (token == "\\tocdepth") {
668 params.tocdepth = lex.GetInteger();
669 } else if (token == "\\baselinestretch") { // now obsolete
670 lex.nextToken(); // should not be used directly
672 // Will probably keep a kind of support just for
674 params.spacing.set(Spacing::Other, lex.GetFloat());
675 } else if (token == "\\spacing") {
677 string tmp = strip(lex.GetString());
678 if (tmp == "single") {
679 params.spacing.set(Spacing::Single);
680 } else if (tmp == "onehalf") {
681 params.spacing.set(Spacing::Onehalf);
682 } else if (tmp == "double") {
683 params.spacing.set(Spacing::Double);
684 } else if (tmp == "other") {
686 params.spacing.set(Spacing::Other,
689 lex.printError("Unknown spacing token: '$$Token'");
691 } else if (token == "\\float_placement") {
693 params.float_placement = lex.GetString();
694 } else if (token == "\\cursor") {
695 // this is obsolete, so we just skip it.
697 } else if (token == "\\family") {
699 font.setLyXFamily(lex.GetString());
700 } else if (token == "\\series") {
702 font.setLyXSeries(lex.GetString());
703 } else if (token == "\\shape") {
705 font.setLyXShape(lex.GetString());
706 } else if (token == "\\size") {
708 font.setLyXSize(lex.GetString());
709 } else if (token == "\\latex") {
711 string tok = lex.GetString();
712 // This is dirty, but gone with LyX3. (Asger)
713 if (tok == "no_latex")
714 font.setLatex(LyXFont::OFF);
715 else if (tok == "latex")
716 font.setLatex(LyXFont::ON);
717 else if (tok == "default")
718 font.setLatex(LyXFont::INHERIT);
720 lex.printError("Unknown LaTeX font flag "
722 } else if (token == "\\emph") {
724 font.setEmph(font.setLyXMisc(lex.GetString()));
725 } else if (token == "\\bar") {
727 string tok = lex.GetString();
728 // This is dirty, but gone with LyX3. (Asger)
730 font.setUnderbar(LyXFont::ON);
731 else if (tok == "no")
732 font.setUnderbar(LyXFont::OFF);
733 else if (tok == "default")
734 font.setUnderbar(LyXFont::INHERIT);
736 lex.printError("Unknown bar font flag "
738 } else if (token == "\\noun") {
740 font.setNoun(font.setLyXMisc(lex.GetString()));
741 } else if (token == "\\color") {
743 font.setLyXColor(lex.GetString());
744 } else if (token == "\\align") {
745 tmpret = lex.FindToken(string_align);
746 if (tmpret == -1) tmpret++;
747 if (tmpret != LYX_LAYOUT_DEFAULT) {
749 for (; tmpret>0; tmpret--)
750 tmpret2 = tmpret2 * 2;
751 par->align = LyXAlignment(tmpret2);
753 } else if (token == "\\added_space_top"){
755 par->added_space_top = lex.GetString();
756 } else if (token == "\\added_space_bottom") {
758 par->added_space_bottom = lex.GetString();
759 } else if (token == "\\pextra_type") {
761 par->pextra_type = lex.GetInteger();
762 } else if (token == "\\pextra_width") {
764 par->pextra_width = lex.GetString();
765 } else if (token == "\\pextra_widthp") {
767 par->pextra_widthp = lex.GetString();
768 } else if (token == "\\pextra_alignment") {
770 par->pextra_alignment = lex.GetInteger();
771 } else if (token == "\\pextra_hfill") {
773 par->pextra_hfill = lex.GetInteger();
774 } else if (token == "\\pextra_start_minipage") {
776 par->pextra_start_minipage = lex.GetInteger();
777 } else if (token == "\\labelwidthstring") {
779 par->labelwidthstring = lex.GetString();
780 /* do not delete this token, it is still needed! */
781 } else if (token == "\\end_inset") {
782 /* simple ignore this. The insets do not have
784 // but insets should read it, it is a part of
785 //the inset isn't it? Lgb.
786 } else if (token == "\\begin_inset") {
788 tmptok = lex.GetString();
789 /* test the different insets */
790 if (tmptok == "Quotes") {
791 inset = new InsetQuotes;
793 par->InsertChar(pos, LyXParagraph::META_INSET);
794 par->InsertInset(pos, inset);
795 par->SetFont(pos, font);
797 #if 0 // should not be used any more
798 } else if (tmptok == "Latex") {
799 // This one is on its way out
801 tmptok = strip(lex.GetString());
802 //lyxerr <<string(tmptok[0]));
803 if (tmptok[0] == '\\') {
804 // then this latex is a
806 InsetCommand *tmpinset =
808 tmpinset->scanCommand(tmptok);
811 // This should not use InsetLaTexDel
812 // it should rather insert text into
813 // the paragraph and mark it as tex.
814 inset = new InsetLatex(tmptok);
816 par->InsertChar(pos, LyXParagraph::META_INSET);
817 par->InsertInset(pos, inset);
818 par->SetFont(pos, font);
821 #if 0 // should not be used any more
822 } else if (tmptok == "LatexDel") {
823 // This one is on its way out...
825 tmptok = strip(lex.GetString());
826 //lyxerr <<string(tmptok[0]));
827 if (tmptok == "\\tableofcontents") {
828 inset = new InsetTOC(this);
829 } else if (tmptok == "\\listoffigures") {
830 inset = new InsetLOF(this);
831 } else if (tmptok == "\\listoftables") {
832 inset = new InsetLOT(this);
833 } else if (tmptok == "\\listofalgorithms") {
834 inset = new InsetLOA(this);
835 } else if (contains(tmptok, "\\ref{")
836 || contains(tmptok, "\\pageref{")) {
837 inset = new InsetRef(tmptok, this);
838 } else if (contains(tmptok, "\\url{")
839 || contains(tmptok, "\\htmlurl{")) {
840 string cont, opt, tmptmptok, cmdname;
842 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
847 tmptmptok = lex.GetString();
848 if(tmptmptok[0] == '\\') {
849 if( tmptmptok == "\\backslash")
859 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
864 tmptmptok = lex.GetString();
865 if(tmptmptok[0] == '\\') {
866 if( tmptmptok == "\\backslash")
876 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
879 if(contains(tmptok, "\\url{"))
880 cmdname = string("url");
882 cmdname = string("htmlurl");
885 inset = new InsetUrl(cmdname, cont, opt);
886 } else if (tmptok[0] == '\\') {
887 // then this latex del is a
889 InsetCommand * tmpinset =
891 tmpinset->scanCommand(tmptok);
894 par->InsertChar(pos, LyXParagraph::META_INSET);
895 par->InsertInset(pos, inset);
896 par->SetFont(pos, font);
899 } else if (tmptok == "\\i") {
900 inset = new InsetLatexAccent;
902 par->InsertChar(pos, LyXParagraph::META_INSET);
903 par->InsertInset(pos, inset);
904 par->SetFont(pos, font);
906 } else if (tmptok == "FormulaMacro") {
907 inset = new InsetFormulaMacro;
909 par->InsertChar(pos, LyXParagraph::META_INSET);
910 par->InsertInset(pos, inset);
911 par->SetFont(pos, font);
913 } else if (tmptok == "Formula") {
914 inset = new InsetFormula;
916 par->InsertChar(pos, LyXParagraph::META_INSET);
917 par->InsertInset(pos, inset);
918 par->SetFont(pos, font);
920 } else if (tmptok == "Figure") {
921 inset = new InsetFig(100, 100, this);
923 par->InsertChar(pos, LyXParagraph::META_INSET);
924 par->InsertInset(pos, inset);
925 par->SetFont(pos, font);
927 } else if (tmptok == "Label") {
928 // Kept for compability. Remove in 0.13.
930 string tmp = "\\label{";
931 tmp += lex.GetString();
933 inset = new InsetLabel(tmp);
934 par->InsertChar(pos, LyXParagraph::META_INSET);
935 par->InsertInset(pos, inset);
936 par->SetFont(pos, font);
939 } else if (tmptok == "Info") {
940 inset = new InsetInfo;
942 par->InsertChar(pos, LyXParagraph::META_INSET);
943 par->InsertInset(pos, inset);
944 par->SetFont(pos, font);
946 } else if (tmptok == "Include") {
947 inset = new InsetInclude(string(), this);
949 par->InsertChar(pos, LyXParagraph::META_INSET);
950 par->InsertInset(pos, inset);
951 par->SetFont(pos, font);
953 } else if (tmptok == "LatexCommand") {
956 if (inscmd.getCmdName() == "cite") {
957 inset = new InsetCitation(inscmd.getContents(), inscmd.getOptions());
958 } else if (inscmd.getCmdName() == "bibitem") {
959 lex.printError("Wrong place for bibitem");
960 inset = inscmd.Clone();
961 } else if (inscmd.getCmdName() == "BibTeX") {
962 inset = new InsetBibtex(inscmd.getContents(), inscmd.getOptions(), this);
963 } else if (inscmd.getCmdName() == "index") {
964 inset = new InsetIndex(inscmd.getContents());
965 } else if (inscmd.getCmdName() == "include") {
966 inset = new InsetInclude(inscmd.getContents(), this);
967 } else if (inscmd.getCmdName() == "label") {
968 inset = new InsetLabel(inscmd.getCommand());
969 } else if (inscmd.getCmdName() == "url"
970 || inscmd.getCmdName() == "htmlurl") {
971 inset = new InsetUrl(inscmd.getCommand());
972 } else if (inscmd.getCmdName() == "ref"
973 || inscmd.getCmdName() == "pageref") {
974 if (!inscmd.getOptions().empty() || !inscmd.getContents().empty()) {
975 inset = new InsetRef(inscmd, this);
977 /* This condition comes from a temporary solution
978 to the latexdel ref inset that was transformed to an empty ref
979 inset plus the body surronded by latexdel insets */
981 string cont, opt, tmptmptok, cmdname;
983 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
988 tmptmptok = lex.GetString();
989 if(tmptmptok[0] == '\\') {
990 if( tmptmptok == "\\backslash")
1000 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
1005 tmptmptok = lex.GetString();
1006 if(tmptmptok[0] == '\\') {
1007 if( tmptmptok == "\\backslash")
1017 while(lex.IsOK() && lex.GetString() != "\\end_inset" ) {
1023 cmdname = "\\" + inscmd.getCmdName();
1024 cmdname += "[" + cont + "]";
1025 cmdname += "{" + opt + "}";
1026 inset = new InsetRef(cmdname, this);
1028 } else if (inscmd.getCmdName() == "tableofcontents") {
1029 inset = new InsetTOC(this);
1030 } else if (inscmd.getCmdName() == "listoffigures") {
1031 inset = new InsetLOF(this);
1032 } else if (inscmd.getCmdName() == "listofalgorithms") {
1033 inset = new InsetLOA(this);
1034 } else if (inscmd.getCmdName() == "listoftables") {
1035 inset = new InsetLOT(this);
1036 } else if (inscmd.getCmdName() == "printindex") {
1037 inset = new InsetPrintIndex(this);
1038 } else if (inscmd.getCmdName() == "lyxparent") {
1039 inset = new InsetParent(inscmd.getContents(), this);
1041 // The following three are only for compatibility
1042 if (inscmd.getCmdName() == "-") {
1043 inset = new InsetSpecialChar(InsetSpecialChar::HYPHENATION);
1044 } else if (inscmd.getCmdName() == "@.") {
1045 inset = new InsetSpecialChar(InsetSpecialChar::END_OF_SENTENCE);
1046 } else if (inscmd.getCmdName() == "ldots") {
1047 inset = new InsetSpecialChar(InsetSpecialChar::LDOTS);
1049 inset = inscmd.Clone();
1052 par->InsertChar(pos, LyXParagraph::META_INSET);
1053 par->InsertInset(pos, inset);
1054 par->SetFont(pos, font);
1058 } else if (token == "\\InsetQuotes") {
1059 inset = new InsetQuotes;
1061 par->InsertChar(pos, LyXParagraph::META_INSET);
1062 par->InsertInset(pos, inset);
1063 par->SetFont(pos, font);
1066 } else if (token == "\\InsetLatex") {
1067 inset = new InsetLatex;
1069 par->InsertChar(pos, LyXParagraph::META_INSET);
1070 par->InsertInset(pos, inset);
1071 par->SetFont(pos, font);
1073 } else if (token == "\\InsetLatexDel") {
1074 lex.printError(_("Warning: Ignoring Old Inset"));
1076 } else if (token == "\\InsetFormula") {
1077 inset = new InsetFormula;
1079 par->InsertChar(pos, LyXParagraph::META_INSET);
1080 par->InsertInset(pos, inset);
1081 par->SetFont(pos, font);
1083 } else if (token == "\\SpecialChar") {
1084 inset = new InsetSpecialChar;
1086 par->InsertChar(pos, LyXParagraph::META_INSET);
1087 par->InsertInset(pos, inset);
1088 par->SetFont(pos, font);
1090 } else if (token == "\\Figure") {
1091 inset = new InsetFig(100, 100, this);
1093 par->InsertChar(pos, LyXParagraph::META_INSET);
1094 par->InsertInset(pos, inset);
1095 par->SetFont(pos, font);
1097 } else if (token == "\\newline") {
1098 par->InsertChar(pos, LyXParagraph::META_NEWLINE);
1099 par->SetFont(pos, font);
1101 } else if (token == "\\LyXTable") {
1102 par->table = new LyXTable(lex);
1103 } else if (token == "\\hfill") {
1104 par->InsertChar(pos, LyXParagraph::META_HFILL);
1105 par->SetFont(pos, font);
1107 } else if (token == "\\protected_separator") {
1108 par->InsertChar(pos, LyXParagraph::META_PROTECTED_SEPARATOR);
1109 par->SetFont(pos, font);
1111 } else if (token == "\\bibitem") { // ale970302
1113 par->bibkey = new InsetBibKey;
1114 par->bibkey->Read(lex);
1115 }else if (token == "\\backslash") {
1116 par->InsertChar(pos, '\\');
1117 par->SetFont(pos, font);
1119 }else if (token == "\\the_end") {
1120 the_end_read = true;
1122 // This should be insurance for the future: (Asger)
1123 lex.printError("Unknown token `$$Token'. "
1124 "Inserting as text.");
1125 int n = token.length();
1126 for (int i = 0; i < n; i++) {
1127 par->InsertChar(pos, token[i]);
1128 par->SetFont(pos, font);
1137 paragraph = return_par;
1139 return the_end_read;
1143 bool Buffer::readFile(LyXLex & lex, LyXParagraph * par)
1149 token = lex.GetString();
1150 if (token == "\\lyxformat") { // the first token _must_ be...
1152 format = lex.GetFloat();
1154 if (LYX_FORMAT - format > 0.05) {
1155 printf(_("Warning: need lyxformat %.2f but found %.2f\n"),
1156 LYX_FORMAT, format);
1158 if (format - LYX_FORMAT > 0.05) {
1159 printf(_("ERROR: need lyxformat %.2f but found %.2f\n"),
1160 LYX_FORMAT, format);
1162 bool the_end = readLyXformat2(lex, par);
1163 // Formats >= 2.13 support "\the_end" marker
1167 // Formats >= 2.14 changed papersize stuff
1168 if (format < 2.14) {
1177 WriteAlert(_("Warning!"),
1178 _("Reading of document is not complete"),
1179 _("Maybe the document is truncated"));
1180 // We simulate a safe reading anyways to allow
1181 // users to take the chance... (Asger)
1185 WriteAlert(_("ERROR!"),
1186 _("Old LyX file format found. "
1187 "Use LyX 0.10.x to read this!"));
1191 } else { // "\\lyxformat" not found
1192 WriteAlert(_("ERROR!"), _("Not a LyX file!"));
1195 WriteAlert(_("ERROR!"), _("Unable to read file!"));
1200 // Returns false if unsuccesful
1201 bool Buffer::writeFile(string const & filename, bool flag)
1203 // if flag is false writeFile will not create any GUI
1204 // warnings, only cerr.
1205 // Needed for autosave in background or panic save (Matthias 120496)
1207 if (read_only && (filename == this->filename)) {
1208 // Here we should come with a question if we should
1209 // perform the write anyway.
1211 lyxerr << _("Error! Document is read-only: ")
1212 << filename << endl;
1214 WriteAlert(_("Error! Document is read-only: "),
1219 FileInfo finfo(filename);
1220 if (finfo.exist() && !finfo.writable()) {
1221 // Here we should come with a question if we should
1222 // try to do the save anyway. (i.e. do a chmod first)
1224 lyxerr << _("Error! Cannot write file: ")
1225 << filename << endl;
1227 WriteFSAlert(_("Error! Cannot write file: "),
1232 ofstream ofs(filename.c_str());
1235 lyxerr << _("Error! Cannot open file: ")
1236 << filename << endl;
1238 WriteFSAlert(_("Error! Cannot open file: "),
1242 // The top of the file should not be written by params.
1244 // write out a comment in the top of the file
1245 ofs << '#' << LYX_DOCVERSION
1246 << " created this file. For more info see http://www.lyx.org/\n";
1247 ofs.setf(ios::showpoint|ios::fixed);
1249 ofs << "\\lyxformat " << setw(4) << LYX_FORMAT << "\n";
1251 // now write out the buffer paramters.
1252 params.writeFile(ofs);
1254 char footnoteflag = 0;
1257 // this will write out all the paragraphs
1258 // using recursive descent.
1259 paragraph->writeFile(ofs, params, footnoteflag, depth);
1261 // Write marker that shows file is complete
1262 ofs << "\n\\the_end" << endl;
1264 // how to check if close went ok?
1269 void Buffer::writeFileAscii(string const & filename, int linelen)
1271 LyXFont font1, font2;
1273 char c, footnoteflag = 0, depth = 0;
1275 LyXParagraph::size_type i;
1276 int j, h, ltype = 0, ltype_depth = 0,
1277 * clen = 0, actcell = 0, actpos = 0, cell = 0, cells = 0,
1280 bool ref_printed = false;
1282 ofstream ofs(filename.c_str());
1284 WriteFSAlert(_("Error: Cannot write file:"), filename);
1288 string fname1 = TmpFileName();
1289 LyXParagraph * par = paragraph;
1293 if (par->footnoteflag != LyXParagraph::NO_FOOTNOTE ||
1295 par->previous->footnoteflag == LyXParagraph::NO_FOOTNOTE){
1297 /* begins a footnote environment ? */
1298 if (footnoteflag != par->footnoteflag) {
1299 footnoteflag = par->footnoteflag;
1301 j = strlen(string_footnotekinds[par->footnotekind])+4;
1302 if (currlinelen + j > linelen)
1305 << string_footnotekinds[par->footnotekind] << "] ";
1310 /* begins or ends a deeper area ?*/
1311 if (depth != par->depth) {
1312 if (par->depth > depth) {
1313 while (par->depth > depth) {
1318 while (par->depth < depth) {
1324 /* First write the layout */
1325 tmp = textclasslist.NameOfLayout(params.textclass, par->layout);
1326 if (tmp == "Itemize") {
1328 ltype_depth = depth+1;
1329 } else if (tmp == "Enumerate") {
1331 ltype_depth = depth+1;
1332 } else if (strstr(tmp.c_str(), "ection")) {
1334 ltype_depth = depth+1;
1335 } else if (strstr(tmp.c_str(), "aragraph")) {
1337 ltype_depth = depth+1;
1338 } else if (tmp == "Description") {
1340 ltype_depth = depth+1;
1341 } else if (tmp == "Abstract") {
1344 } else if (tmp == "Bibliography") {
1352 /* maybe some vertical spaces */
1354 /* the labelwidthstring used in lists */
1358 /* some pagebreaks? */
1362 /* what about the alignment */
1365 /* dummy layout, that means a footnote ended */
1366 footnoteflag = LyXParagraph::NO_FOOTNOTE;
1371 /* It might be a table */
1373 if (!lyxrc->ascii_roff_command.empty() &&
1374 lyxrc->ascii_roff_command != "none") {
1375 RoffAsciiTable(ofs, par);
1381 cells = par->table->columns;
1382 clen = new int [cells];
1383 memset(clen, 0, sizeof(int) * cells);
1384 for (i = 0, j = 0, h = 1; i < par->size(); ++i, ++h) {
1385 c = par->GetChar(i);
1386 if (c == LyXParagraph::META_INSET) {
1387 if ((inset = par->GetInset(i))) {
1388 ofstream fs(fname1.c_str());
1390 WriteFSAlert(_("Error: Cannot open temporary file:"), fname1);
1393 inset->Latex(fs, -1);
1394 h += fs.tellp() - 1;
1395 remove(fname1.c_str());
1397 } else if (c == LyXParagraph::META_NEWLINE) {
1401 j = (++j) % par->table->NumberOfCellsInRow(actcell);
1409 font1 = LyXFont(LyXFont::ALL_INHERIT);
1411 for (i = 0, actpos = 1; i < par->size(); ++i, ++actpos) {
1412 if (!i && !footnoteflag && !noparbreak){
1414 for(j = 0; j < depth; ++j)
1416 currlinelen = depth * 2;
1418 case 0: /* Standart */
1419 case 4: /* (Sub)Paragraph */
1420 case 5: /* Description */
1422 case 6: /* Abstract */
1423 ofs << "Abstract\n\n";
1425 case 7: /* Bibliography */
1427 ofs << "References\n\n";
1432 ofs << par->labelstring << " ";
1435 if (ltype_depth > depth) {
1436 for(j = ltype_depth - 1; j > depth; --j)
1438 currlinelen += (ltype_depth-depth)*2;
1441 for(j = 0; j < cells; ++j) {
1443 for(h = 0; h < (clen[j] + 1);
1448 for(j = 0; j < depth; ++j)
1450 currlinelen = depth * 2;
1451 if (ltype_depth > depth) {
1452 for(j = ltype_depth;
1455 currlinelen += (ltype_depth-depth)*2;
1460 font2 = par->GetFontSettings(i);
1461 if (font1.latex() != font2.latex()) {
1462 if (font2.latex() == LyXFont::OFF)
1470 c = par->GetChar(i);
1474 case LyXParagraph::META_INSET:
1475 if ((inset = par->GetInset(i))) {
1477 inset->Latex(ofs, -1);
1478 currlinelen += (ofs.tellp() - fpos);
1479 actpos += (ofs.tellp() - fpos) - 1;
1482 case LyXParagraph::META_NEWLINE:
1484 if (par->table->NumberOfCellsInRow(actcell) <= cell) {
1485 for(j = actpos; j < clen[cell-1];j++)
1488 for(j = 0; j < depth; ++j)
1490 currlinelen = depth*2;
1491 if (ltype_depth > depth) {
1492 for(j = ltype_depth; j > depth; --j)
1494 currlinelen += (ltype_depth-depth) * 2;
1496 for(j = 0; j < cells; ++j) {
1498 for(h = 0; h < (clen[j] + 1); ++h)
1502 for(j = 0; j < depth; ++j)
1504 currlinelen = depth * 2;
1505 if (ltype_depth > depth) {
1506 for(j = ltype_depth;
1509 currlinelen += (ltype_depth-depth)*2;
1515 j < clen[cell - 1]; ++j)
1521 currlinelen = actpos = 0;
1524 for(j = 0; j < depth; ++j)
1526 currlinelen = depth * 2;
1527 if (ltype_depth > depth) {
1528 for(j = ltype_depth;
1531 currlinelen += (ltype_depth - depth) * 2;
1535 case LyXParagraph::META_HFILL:
1538 case LyXParagraph::META_PROTECTED_SEPARATOR:
1545 if (currlinelen > linelen - 10
1546 && c == ' ' && i + 2 < par->size()) {
1548 for(j = 0; j < depth; ++j)
1550 currlinelen = depth * 2;
1551 if (ltype_depth > depth) {
1552 for(j = ltype_depth;
1555 currlinelen += (ltype_depth-depth)*2;
1557 } else if (c != '\0')
1560 lyxerr.debug() << "writeAsciiFile: NULL char in structure." << endl;
1566 for(j = actpos; j < clen[cell - 1]; ++j)
1569 for(j = 0; j < depth; ++j)
1571 currlinelen = depth * 2;
1572 if (ltype_depth > depth) {
1573 for(j = ltype_depth; j > depth; --j)
1575 currlinelen += (ltype_depth - depth) * 2;
1577 for(j = 0; j < cells; ++j) {
1579 for(h = 0; h < (clen[j] + 1); ++h)
1592 void Buffer::makeLaTeXFile(string const & filename,
1593 string const & original_path,
1594 bool nice, bool only_body)
1596 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
1597 params.textclass = GetCurrentTextClass();
1598 niceFile = nice; // this will be used by Insetincludes.
1600 tex_code_break_column = lyxrc->ascii_linelen;
1602 LyXTextClass const & tclass =
1603 textclasslist.TextClass(params.textclass);
1605 ofstream ofs(filename.c_str());
1607 WriteFSAlert(_("Error: Cannot open file: "), filename);
1611 // validate the buffer.
1612 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
1613 LaTeXFeatures features(tclass.numLayouts());
1615 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
1618 // The starting paragraph of the coming rows is the
1619 // first paragraph of the document. (Asger)
1620 texrow.start(paragraph, 0);
1622 string userName(getUserName());
1625 if (!only_body && nice) {
1626 LFile += "%% This LaTeX-file was created by <";
1627 LFile += userName + "> " + date();
1628 LFile += "%% LyX 1.0 (C) 1995-1999 by Matthias Ettrich and the LyX Team\n";
1629 LFile += "\n%% Do not edit this file unless you know what you are doing.\n";
1635 lyxerr.debug() << "lyx header finished" << endl;
1636 // There are a few differences between nice LaTeX and usual files:
1637 // usual is \batchmode, uses \listfiles and has a
1638 // special input@path to allow the including of figures
1639 // with either \input or \includegraphics (what figinsets do).
1640 // batchmode is not set if there is a tex_code_break_column.
1641 // In this case somebody is interested in the generated LaTeX,
1642 // so this is OK. input@path is set when the actual parameter
1643 // original_path is set. This is done for usual tex-file, but not
1644 // for nice-latex-file. (Matthias 250696)
1647 // code for usual, NOT nice-latex-file
1648 LFile += "\\batchmode\n"; // changed
1649 // from \nonstopmode
1651 // We don't need listfiles anymore
1652 //LFile += "\\listfiles\n";
1655 if (!original_path.empty()) {
1656 LFile += "\\makeatletter\n";
1658 LFile += "\\def\\input@path{{" + original_path
1661 LFile += "\\makeatother\n";
1665 LFile += "\\documentclass";
1667 string options; // the document class options.
1669 if (tokenPos(tclass.opt_fontsize(), '|', params.fontsize) >= 0) {
1670 // only write if existing in list (and not default)
1671 options += params.fontsize;
1676 if (!params.use_geometry &&
1677 (params.paperpackage == BufferParams::PACKAGE_NONE)) {
1678 switch (params.papersize) {
1679 case BufferParams::PAPER_A4PAPER:
1680 options += "a4paper,";
1682 case BufferParams::PAPER_USLETTER:
1683 options += "letterpaper,";
1685 case BufferParams::PAPER_A5PAPER:
1686 options += "a5paper,";
1688 case BufferParams::PAPER_B5PAPER:
1689 options += "b5paper,";
1691 case BufferParams::PAPER_EXECUTIVEPAPER:
1692 options += "executivepaper,";
1694 case BufferParams::PAPER_LEGALPAPER:
1695 options += "legalpaper,";
1701 if (params.sides != tclass.sides()) {
1702 if (params.sides == 2)
1703 options += "twoside,";
1705 options += "oneside,";
1709 if (params.columns != tclass.columns()) {
1710 if (params.columns == 2)
1711 options += "twocolumn,";
1713 options += "onecolumn,";
1716 if (!params.use_geometry
1717 && params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1718 options += "landscape,";
1720 // language should be a parameter to \documentclass
1721 if (params.language != "default") {
1722 options += params.language + ',';
1725 // the user-defined options
1726 if (!params.options.empty()) {
1727 options += params.options + ',';
1730 if (!options.empty()){
1731 options = strip(options, ',');
1738 LFile += textclasslist.LatexnameOfClass(params.textclass);
1741 // end of \documentclass defs
1743 // font selection must be done before loading fontenc.sty
1744 if (params.fonts != "default") {
1745 LFile += "\\usepackage{" + params.fonts + "}\n";
1748 // this one is not per buffer
1749 if (lyxrc->fontenc != "default") {
1750 LFile += "\\usepackage[" + lyxrc->fontenc
1754 if (params.inputenc != "default") {
1755 LFile += "\\usepackage[" + params.inputenc
1760 /* at the very beginning the text parameters */
1761 if (params.paperpackage != BufferParams::PACKAGE_NONE) {
1762 switch (params.paperpackage) {
1763 case BufferParams::PACKAGE_A4:
1764 LFile += "\\usepackage{a4}\n";
1767 case BufferParams::PACKAGE_A4WIDE:
1768 LFile += "\\usepackage{a4wide}\n";
1771 case BufferParams::PACKAGE_WIDEMARGINSA4:
1772 LFile += "\\usepackage[widemargins]{a4}\n";
1777 if (params.use_geometry) {
1778 LFile += "\\usepackage{geometry}\n";
1780 LFile += "\\geometry{verbose";
1781 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1782 LFile += ",landscape";
1783 switch (params.papersize2) {
1784 case BufferParams::VM_PAPER_CUSTOM:
1785 if (!params.paperwidth.empty())
1786 LFile += ",paperwidth="
1787 + params.paperwidth;
1788 if (!params.paperheight.empty())
1789 LFile += ",paperheight="
1790 + params.paperheight;
1792 case BufferParams::VM_PAPER_USLETTER:
1793 LFile += ",letterpaper";
1795 case BufferParams::VM_PAPER_USLEGAL:
1796 LFile += ",legalpaper";
1798 case BufferParams::VM_PAPER_USEXECUTIVE:
1799 LFile += ",executivepaper";
1801 case BufferParams::VM_PAPER_A3:
1802 LFile += ",a3paper";
1804 case BufferParams::VM_PAPER_A4:
1805 LFile += ",a4paper";
1807 case BufferParams::VM_PAPER_A5:
1808 LFile += ",a5paper";
1810 case BufferParams::VM_PAPER_B3:
1811 LFile += ",b3paper";
1813 case BufferParams::VM_PAPER_B4:
1814 LFile += ",b4paper";
1816 case BufferParams::VM_PAPER_B5:
1817 LFile += ",b5paper";
1820 // default papersize ie BufferParams::VM_PAPER_DEFAULT
1821 switch (lyxrc->default_papersize) {
1822 case BufferParams::PAPER_DEFAULT: // keep compiler happy
1823 case BufferParams::PAPER_USLETTER:
1824 LFile += ",letterpaper";
1826 case BufferParams::PAPER_LEGALPAPER:
1827 LFile += ",legalpaper";
1829 case BufferParams::PAPER_EXECUTIVEPAPER:
1830 LFile += ",executivepaper";
1832 case BufferParams::PAPER_A3PAPER:
1833 LFile += ",a3paper";
1835 case BufferParams::PAPER_A4PAPER:
1836 LFile += ",a4paper";
1838 case BufferParams::PAPER_A5PAPER:
1839 LFile += ",a5paper";
1841 case BufferParams::PAPER_B5PAPER:
1842 LFile += ",b5paper";
1846 if (!params.topmargin.empty())
1847 LFile += ",tmargin=" + params.topmargin;
1848 if (!params.bottommargin.empty())
1849 LFile += ",bmargin=" + params.bottommargin;
1850 if (!params.leftmargin.empty())
1851 LFile += ",lmargin=" + params.leftmargin;
1852 if (!params.rightmargin.empty())
1853 LFile += ",rmargin=" + params.rightmargin;
1854 if (!params.headheight.empty())
1855 LFile += ",headheight=" + params.headheight;
1856 if (!params.headsep.empty())
1857 LFile += ",headsep=" + params.headsep;
1858 if (!params.footskip.empty())
1859 LFile += ",footskip=" + params.footskip;
1863 if (params.use_amsmath
1864 && !prefixIs(textclasslist.LatexnameOfClass(params.textclass), "ams")) {
1865 LFile += "\\usepackage{amsmath}\n";
1868 if (tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle) >= 0) {
1869 if (params.pagestyle == "fancy") {
1870 LFile += "\\usepackage{fancyhdr}\n";
1873 LFile += "\\pagestyle{" + params.pagestyle + "}\n";
1877 // We try to load babel late, in case it interferes
1878 // with other packages.
1879 if (params.language != "default") {
1880 LFile += "\\usepackage{babel}\n";
1884 if (params.secnumdepth != tclass.secnumdepth()) {
1885 LFile += "\\setcounter{secnumdepth}{";
1886 LFile += tostr(params.secnumdepth);
1890 if (params.tocdepth != tclass.tocdepth()) {
1891 LFile += "\\setcounter{tocdepth}{";
1892 LFile += tostr(params.tocdepth);
1897 if (params.paragraph_separation) {
1898 switch (params.defskip.kind()) {
1899 case VSpace::SMALLSKIP:
1900 LFile += "\\setlength\\parskip{\\smallskipamount}\n";
1902 case VSpace::MEDSKIP:
1903 LFile += "\\setlength\\parskip{\\medskipamount}\n";
1905 case VSpace::BIGSKIP:
1906 LFile += "\\setlength\\parskip{\\bigskipamount}\n";
1908 case VSpace::LENGTH:
1909 LFile += "\\setlength\\parskip{"
1910 + params.defskip.length().asLatexString()
1913 default: // should never happen // Then delete it.
1914 LFile += "\\setlength\\parskip{\\medskipamount}\n";
1919 LFile += "\\setlength\\parindent{0pt}\n";
1923 // Write out what we've generated so far...and reset LFile
1927 // Now insert the LyX specific LaTeX commands...
1928 string preamble, tmppreamble;
1930 // The optional packages;
1931 preamble = features.getPackages(params);
1933 // this might be useful...
1934 preamble += "\n\\makeatletter\n\n";
1936 // Some macros LyX will need
1937 tmppreamble = features.getMacros(params);
1939 if (!tmppreamble.empty()) {
1940 preamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1941 "LyX specific LaTeX commands.\n"
1942 + tmppreamble + '\n';
1945 // the text class specific preamble
1946 tmppreamble = features.getTClassPreamble(params);
1947 if (!tmppreamble.empty()) {
1948 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1949 "Textclass specific LaTeX commands.\n"
1950 + tmppreamble + '\n';
1953 /* the user-defined preamble */
1954 if (!params.preamble.empty()) {
1955 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1956 "User specified LaTeX commands.\n"
1957 + params.preamble + '\n';
1960 preamble += "\\makeatother\n\n";
1962 // Itemize bullet settings need to be last in case the user
1963 // defines their own bullets that use a package included
1964 // in the user-defined preamble -- ARRae
1965 // Actually it has to be done much later than that
1966 // since some packages like frenchb make modifications
1967 // at \begin{document} time -- JMarc
1969 for (int i = 0; i < 4; ++i) {
1970 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
1971 if (bullets_def.empty())
1972 bullets_def="\\AtBeginDocument{\n";
1973 bullets_def += " \\renewcommand{\\labelitemi";
1975 // `i' is one less than the item to modify
1982 bullets_def += "ii";
1988 bullets_def += "}{" +
1989 params.user_defined_bullets[i].getText()
1994 if (!bullets_def.empty())
1995 preamble += bullets_def + "}\n\n";
1997 for (int j = countChar(preamble, '\n'); j-- ;) {
2004 LFile += "\\begin{document}\n\n";
2008 lyxerr.debug() << "preamble finished, now the body." << endl;
2010 bool was_title = false;
2011 bool already_title = false;
2017 LyXParagraph * par = paragraph;
2023 lyxerr[Debug::LATEX] << "Error in MakeLateXFile."
2025 LyXLayout const & layout = textclasslist.Style(params.textclass,
2028 if (layout.intitle) {
2029 if (already_title) {
2030 lyxerr <<"Error in MakeLatexFile: You"
2031 " should not mix title layouts"
2032 " with normal ones." << endl;
2035 } else if (was_title && !already_title) {
2036 LFile += "\\maketitle\n";
2038 already_title = true;
2041 // We are at depth 0 so we can just use
2042 // ordinary \footnote{} generation
2043 // flag this with ftcount
2045 if (layout.isEnvironment()
2046 || par->pextra_type != LyXParagraph::PEXTRA_NONE) {
2047 par = par->TeXEnvironment(LFile, texrow,
2048 ftnote, ft_texrow, ftcount);
2050 par = par->TeXOnePar(LFile, texrow,
2051 ftnote, ft_texrow, ftcount);
2054 // Write out what we've generated...and reset LFile
2057 LFile += "\\addtocounter{footnote}{-";
2058 LFile += tostr(ftcount - 1);
2062 texrow += ft_texrow;
2067 if (loop_count == 2) {
2068 // fwrite()ing every second time through the loop
2069 // gains a few extra % of speed; going higher than
2070 // 2 will slow things down again. I'll look at
2071 // LFile.length() in a future revision. ARRae
2078 // It might be that we only have a title in this document
2079 if (was_title && !already_title) {
2080 LFile += "\\maketitle\n";
2085 LFile += "\\end{document}\n";
2088 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
2090 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
2094 // Just to be sure. (Asger)
2097 // Write out what we've generated...and reset LFile
2101 // tex_code_break_column's value is used to decide
2102 // if we are in batchmode or not (within mathed_write()
2103 // in math_write.C) so we must set it to a non-zero
2104 // value when we leave otherwise we save incorrect .lyx files.
2105 tex_code_break_column = lyxrc->ascii_linelen;
2107 // How to check if the close went ok when using fstreams
2109 lyxerr.debug() << "Finished making latex file." << endl;
2113 bool Buffer::isLatex() const
2115 return textclasslist.TextClass(params.textclass).outputType() == LATEX;
2119 bool Buffer::isLinuxDoc() const
2121 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC;
2125 bool Buffer::isLiterate() const
2127 return textclasslist.TextClass(params.textclass).outputType() == LITERATE;
2131 bool Buffer::isDocBook() const
2133 return textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2137 bool Buffer::isSGML() const
2139 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC ||
2140 textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2144 void Buffer::sgmlOpenTag(ostream & os, int depth,
2145 string const & latexname) const
2147 static char * space[] = {" "," ", " ", " ", " ", " ",
2152 os << space[depth] << "<" << latexname << ">\n";
2156 void Buffer::sgmlCloseTag(ostream & os, int depth,
2157 string const & latexname) const
2159 static char * space[] = {" ", " ", " ", " ", " ",
2163 os << space[depth] << "</" << latexname << ">\n";
2167 void Buffer::makeLinuxDocFile(string const & filename, int column)
2169 LyXParagraph * par = paragraph;
2171 string top_element = textclasslist.LatexnameOfClass(params.textclass);
2172 string environment_stack[10];
2175 int depth = 0; /* paragraph depth */
2177 ofstream ofs(filename.c_str());
2180 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), filename);
2184 tex_code_break_column = column;
2187 if (params.preamble.empty()) {
2188 ofs << "<!doctype linuxdoc system>\n\n";
2191 ofs << "<!doctype linuxdoc system \n [ "
2192 << params.preamble << " \n]>\n\n";
2195 string userName(getUserName());
2196 ofs << "<!-- LinuxDoc file was created by LyX 1.0 (C) 1995-1999 "
2197 << "by <" << userName << "> " << date() << " -->\n";
2199 if(params.options.empty())
2200 sgmlOpenTag(ofs, 0, top_element);
2202 string top = top_element;
2204 top += params.options;
2205 sgmlOpenTag(ofs, 0, top);
2209 int desc_on = 0; /* description mode*/
2210 LyXLayout const & style =
2211 textclasslist.Style(GetCurrentTextClass(),
2213 par->AutoDeleteInsets();
2215 /* treat <toc> as a special case for compatibility with old code */
2216 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2217 Inset * inset = par->GetInset(0);
2218 char lyx_code = inset->LyxCode();
2219 if (lyx_code == Inset::TOC_CODE){
2220 string temp = "toc";
2221 sgmlOpenTag(ofs, depth, temp);
2224 linuxDocHandleFootnote(ofs, par, depth);
2229 /* environment tag closing */
2230 for( ; depth > par->depth; --depth) {
2231 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2232 environment_stack[depth].clear();
2235 /* write opening SGML tags */
2236 switch(style.latextype) {
2237 case LATEX_PARAGRAPH:
2238 if(depth == par->depth
2239 && !environment_stack[depth].empty()) {
2240 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2241 environment_stack[depth].clear();
2247 sgmlOpenTag(ofs, depth, style.latexname());
2252 LinuxDocError(par, 0, _("Error : Wrong depth for LatexType Command.\n"));
2254 if (!environment_stack[depth].empty()){
2255 sgmlCloseTag(ofs, depth,
2256 environment_stack[depth]);
2260 environment_stack[depth].clear();
2261 sgmlOpenTag(ofs, depth, style.latexname());
2264 case LATEX_ENVIRONMENT:
2265 case LATEX_ITEM_ENVIRONMENT:
2266 if(depth == par->depth
2267 && environment_stack[depth] != style.latexname()
2268 && !environment_stack[depth].empty()) {
2270 sgmlCloseTag(ofs, depth,
2271 environment_stack[depth]);
2272 environment_stack[depth].clear();
2274 if (depth < par->depth) {
2276 environment_stack[depth].clear();
2278 if (environment_stack[depth] != style.latexname()) {
2281 sgmlOpenTag(ofs, depth, temp);
2283 environment_stack[depth] = style.latexname();
2284 sgmlOpenTag(ofs, depth, environment_stack[depth]);
2286 if(style.latextype == LATEX_ENVIRONMENT) break;
2288 desc_on = (style.labeltype == LABEL_MANUAL);
2295 sgmlOpenTag(ofs, depth + 1, item_name);
2298 sgmlOpenTag(ofs, depth, style.latexname());
2303 SimpleLinuxDocOnePar(ofs, par, desc_on, depth);
2306 linuxDocHandleFootnote(ofs, par, depth);
2308 while(par && par->IsDummy());
2311 /* write closing SGML tags */
2312 switch(style.latextype) {
2314 case LATEX_ENVIRONMENT:
2315 case LATEX_ITEM_ENVIRONMENT:
2318 sgmlCloseTag(ofs, depth, style.latexname());
2323 /* Close open tags */
2324 for(; depth > 0; --depth)
2325 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2327 if(!environment_stack[depth].empty())
2328 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2331 sgmlCloseTag(ofs, 0, top_element);
2334 // How to check for successful close
2338 void Buffer::linuxDocHandleFootnote(ostream & os, LyXParagraph * & par,
2341 string tag = "footnote";
2343 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2344 sgmlOpenTag(os, depth + 1, tag);
2345 SimpleLinuxDocOnePar(os, par, 0, depth + 1);
2346 sgmlCloseTag(os, depth + 1, tag);
2352 void Buffer::DocBookHandleCaption(ostream & os, string & inner_tag,
2353 int const depth, int desc_on,
2354 LyXParagraph * & par)
2356 LyXParagraph * tpar = par;
2357 string tmp_par, extra_par;
2358 while (tpar && (tpar->footnoteflag != LyXParagraph::NO_FOOTNOTE) &&
2359 (tpar->layout != textclasslist.NumberOfLayout(params.textclass,
2363 tpar->layout == textclasslist.NumberOfLayout(params.textclass,
2364 "Caption").second) {
2365 sgmlOpenTag(os, depth + 1, inner_tag);
2366 SimpleDocBookOnePar(tmp_par, extra_par, tpar,
2367 desc_on, depth + 2);
2368 tmp_par = strip(tmp_par);
2369 tmp_par = frontStrip(tmp_par);
2371 sgmlCloseTag(os, depth+1, inner_tag);
2372 if(!extra_par.empty())
2378 void Buffer::DocBookHandleFootnote(ostream & os, LyXParagraph * & par,
2381 string tag, inner_tag;
2382 string tmp_par, extra_par;
2383 bool inner_span = false;
2386 // This is not how I like to see enums. They should not be anonymous
2387 // and variables of its type should not be declared right after the
2388 // last brace. (Lgb)
2395 } last = NO_ONE, present = FOOTNOTE_LIKE;
2397 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2398 if(last == present) {
2400 if(!tmp_par.empty()) {
2403 sgmlCloseTag(os, depth+1, inner_tag);
2404 sgmlOpenTag(os, depth+1, inner_tag);
2411 if(!inner_tag.empty()) sgmlCloseTag(os, depth+1, inner_tag);
2412 if(!extra_par.empty()) os << extra_par;
2413 if(!tag.empty()) sgmlCloseTag(os, depth, tag);
2416 switch (par->footnotekind) {
2417 case LyXParagraph::FOOTNOTE:
2418 case LyXParagraph::ALGORITHM:
2421 present = FOOTNOTE_LIKE;
2424 case LyXParagraph::MARGIN:
2427 present = MARGIN_LIKE;
2430 case LyXParagraph::FIG:
2431 case LyXParagraph::WIDE_FIG:
2433 inner_tag = "title";
2437 case LyXParagraph::TAB:
2438 case LyXParagraph::WIDE_TAB:
2440 inner_tag = "title";
2445 sgmlOpenTag(os, depth, tag);
2446 if ((present == TAB_LIKE) || (present == FIG_LIKE)) {
2447 DocBookHandleCaption(os, inner_tag, depth,
2451 sgmlOpenTag(os, depth + 1, inner_tag);
2454 // ignore all caption here, we processed them above!!!
2455 if (par->layout != textclasslist.NumberOfLayout(params.textclass,
2456 "Caption").second) {
2457 SimpleDocBookOnePar(tmp_par, extra_par, par,
2458 desc_on, depth + 2);
2460 tmp_par = frontStrip(strip(tmp_par));
2466 if(!inner_tag.empty()) sgmlCloseTag(os, depth+1, inner_tag);
2467 if(!extra_par.empty()) os << extra_par;
2468 if(!tag.empty()) sgmlCloseTag(os, depth, tag);
2472 /* push a tag in a style stack */
2473 void Buffer::push_tag(ostream & os, char const * tag,
2474 int & pos, char stack[5][3])
2478 /* pop all previous tags */
2479 for (j = pos; j >= 0; --j)
2480 os << "</" << stack[j] << ">";
2483 sprintf(stack[++pos], "%s", tag);
2486 for (j = 0; j <= pos; ++j)
2487 os << "<" << stack[j] << ">";
2491 // pop a tag from a style stack
2492 void Buffer::pop_tag(ostream & os, char const * tag,
2493 int & pos, char stack[5][3])
2497 // pop all tags till specified one
2498 for (j = pos; (j >= 0) && (strcmp(stack[j], tag)); --j)
2499 os << "</" << stack[j] << ">";
2502 os << "</" << tag << ">";
2504 // push all tags, but the specified one
2505 for (j = j + 1; j <= pos; ++j) {
2506 os << "<" << stack[j] << ">";
2507 strcpy(stack[j-1], stack[j]);
2513 /* handle internal paragraph parsing -- layout already processed */
2515 // checks, if newcol chars should be put into this line
2516 // writes newline, if necessary.
2518 void linux_doc_line_break(ostream & os, unsigned int & colcount,
2519 const unsigned int newcol)
2522 if (colcount > lyxrc->ascii_linelen) {
2524 colcount = newcol; // assume write after this call
2529 void Buffer::SimpleLinuxDocOnePar(ostream & os, LyXParagraph * par,
2530 int desc_on, int const /*depth*/)
2532 LyXFont font1, font2;
2535 LyXParagraph::size_type main_body;
2537 LyXLayout const & style = textclasslist.Style(params.textclass,
2540 char family_type = 0; // family font flag
2541 bool is_bold = false; // series font flag
2542 char shape_type = 0; // shape font flag
2543 bool is_em = false; // emphasis (italic) font flag
2545 int stack_num = -1; // style stack position
2546 char stack[5][3]; // style stack
2547 unsigned int char_line_count = 5; // Heuristic choice ;-)
2549 if (style.labeltype != LABEL_MANUAL)
2552 main_body = par->BeginningOfMainBody();
2554 /* gets paragraph main font */
2556 font1 = style.labelfont;
2561 /* parsing main loop */
2562 for (LyXParagraph::size_type i = 0;
2563 i < par->size(); ++i) {
2565 /* handle quote tag */
2566 if (i == main_body && !par->IsDummy()) {
2571 font2 = par->getFont(i);
2573 if (font1.family() != font2.family()) {
2574 switch(family_type) {
2576 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2577 push_tag(os, "tt", stack_num, stack);
2580 else if (font2.family() == LyXFont::SANS_FAMILY) {
2581 push_tag(os, "sf", stack_num, stack);
2586 pop_tag(os, "tt", stack_num, stack);
2587 if (font2.family() == LyXFont::SANS_FAMILY) {
2588 push_tag(os, "sf", stack_num, stack);
2596 pop_tag(os, "sf", stack_num, stack);
2597 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2598 push_tag(os, "tt", stack_num, stack);
2607 /* handle bold face */
2608 if (font1.series() != font2.series()) {
2609 if (font2.series() == LyXFont::BOLD_SERIES) {
2610 push_tag(os, "bf", stack_num, stack);
2614 pop_tag(os, "bf", stack_num, stack);
2619 /* handle italic and slanted fonts */
2620 if (font1.shape() != font2.shape()) {
2621 switch(shape_type) {
2623 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2624 push_tag(os, "it", stack_num, stack);
2627 else if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2628 push_tag(os, "sl", stack_num, stack);
2633 pop_tag(os, "it", stack_num, stack);
2634 if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2635 push_tag(os, "sl", stack_num, stack);
2643 pop_tag(os, "sl", stack_num, stack);
2644 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2645 push_tag(os, "it", stack_num, stack);
2653 /* handle <em> tag */
2654 if (font1.emph() != font2.emph()) {
2655 if (font2.emph() == LyXFont::ON) {
2656 push_tag(os, "em", stack_num, stack);
2659 pop_tag(os, "em", stack_num, stack);
2664 c = par->GetChar(i);
2666 if (font2.latex() == LyXFont::ON) {
2667 // "TeX"-Mode on == > SGML-Mode on.
2669 os << c; // see LaTeX-Generation...
2671 } else if (c == LyXParagraph::META_INSET) {
2672 inset = par->GetInset(i);
2674 inset->Linuxdoc(tmp_out);
2679 if (par->linuxDocConvertChar(c, sgml_string)
2680 && !style.free_spacing) { // in freespacing
2682 // non-breaking characters
2686 linux_doc_line_break(os, char_line_count, 6);
2691 linux_doc_line_break(os, char_line_count, 1);
2697 char_line_count += sgml_string.length();
2703 /* needed if there is an optional argument but no contents */
2704 if (main_body > 0 && main_body == par->size()) {
2708 /* pop all defined Styles */
2709 for (j = stack_num; j >= 0; --j) {
2710 linux_doc_line_break(os,
2712 3 + strlen(stack[j]));
2713 os << "</" << stack[j] << ">";
2716 /* resets description flag correctly */
2719 /* <tag> not closed... */
2720 linux_doc_line_break(os, char_line_count, 6);
2724 /* fprintf(file, "</p>");*/
2730 /* print an error message */
2731 void Buffer::LinuxDocError(LyXParagraph * par, int pos,
2732 char const * message)
2734 InsetError * new_inset;
2736 /* insert an error marker in text */
2737 new_inset = new InsetError(message);
2738 par->InsertChar(pos, LyXParagraph::META_INSET);
2739 par->InsertInset(pos, new_inset);
2742 // This constant defines the maximum number of
2743 // environment layouts that can be nesteded.
2744 // The same applies for command layouts.
2745 // These values should be more than enough.
2746 // José Matos (1999/07/22)
2748 enum { MAX_NEST_LEVEL = 25};
2750 void Buffer::makeDocBookFile(string const & filename, int column)
2752 LyXParagraph * par = paragraph;
2754 string top_element= textclasslist.LatexnameOfClass(params.textclass);
2755 string environment_stack[MAX_NEST_LEVEL];
2756 string environment_inner[MAX_NEST_LEVEL];
2757 string command_stack[MAX_NEST_LEVEL];
2758 bool command_flag= false;
2759 int command_depth= 0, command_base= 0, cmd_depth= 0;
2761 string item_name, command_name;
2762 string c_depth, c_params, tmps;
2764 int depth= 0; /* paragraph depth */
2766 tex_code_break_column = column;
2768 ofstream ofs(filename.c_str());
2770 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), filename);
2777 ofs << "<!doctype " << top_element
2778 << " public \"-//OASIS//DTD DocBook V3.1//EN\"";
2780 if (params.preamble.empty())
2783 ofs << "\n [ " << params.preamble << " \n]>\n\n";
2785 ofs << "<!-- DocBook file was created by " << LYX_DOCVERSION
2786 << "\n See http://www.lyx.org/ for more information -->\n";
2788 if(params.options.empty())
2789 sgmlOpenTag(ofs, 0, top_element);
2791 string top = top_element;
2793 top += params.options;
2794 sgmlOpenTag(ofs, 0, top);
2798 int desc_on= 0; /* description mode*/
2799 LyXLayout const & style = textclasslist.Style(GetCurrentTextClass(),
2801 par->AutoDeleteInsets();
2803 /* environment tag closing */
2804 for( ; depth > par->depth; --depth) {
2805 if(environment_inner[depth] != "!-- --") {
2806 item_name= "listitem";
2807 sgmlCloseTag(ofs, command_depth + depth,
2809 if( environment_inner[depth] == "varlistentry")
2810 sgmlCloseTag(ofs, depth+command_depth,
2811 environment_inner[depth]);
2813 sgmlCloseTag(ofs, depth + command_depth,
2814 environment_stack[depth]);
2815 environment_stack[depth].clear();
2816 environment_inner[depth].clear();
2819 if(depth == par->depth
2820 && environment_stack[depth] != style.latexname()
2821 && !environment_stack[depth].empty()) {
2822 if(environment_inner[depth] != "!-- --") {
2823 item_name= "listitem";
2824 sgmlCloseTag(ofs, command_depth+depth,
2826 if( environment_inner[depth] == "varlistentry")
2828 depth + command_depth,
2829 environment_inner[depth]);
2832 sgmlCloseTag(ofs, depth + command_depth,
2833 environment_stack[depth]);
2835 environment_stack[depth].clear();
2836 environment_inner[depth].clear();
2839 // Write opening SGML tags.
2840 switch(style.latextype) {
2841 case LATEX_PARAGRAPH:
2842 if(style.latexname() != "dummy")
2843 sgmlOpenTag(ofs, depth+command_depth,
2849 LinuxDocError(par, 0,
2850 _("Error : Wrong depth for "
2851 "LatexType Command.\n"));
2853 command_name = style.latexname();
2855 tmps = style.latexparam();
2856 c_params = split(tmps, c_depth,'|');
2858 cmd_depth= atoi(c_depth.c_str());
2861 if(cmd_depth<command_base) {
2862 for(int j = command_depth;
2863 j >= command_base; --j)
2864 if(!command_stack[j].empty())
2865 sgmlCloseTag(ofs, j, command_stack[j]);
2866 command_depth= command_base= cmd_depth;
2868 else if(cmd_depth <= command_depth) {
2869 for(int j = command_depth;
2870 j >= cmd_depth; --j)
2872 if(!command_stack[j].empty())
2873 sgmlCloseTag(ofs, j, command_stack[j]);
2874 command_depth= cmd_depth;
2877 command_depth= cmd_depth;
2880 command_depth = command_base = cmd_depth;
2881 command_flag = true;
2883 command_stack[command_depth]= command_name;
2885 // treat label as a special case for
2886 // more WYSIWYM handling.
2887 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2888 Inset * inset = par->GetInset(0);
2889 char lyx_code = inset->LyxCode();
2890 if (lyx_code == Inset::LABEL_CODE){
2891 command_name += " id=\"";
2892 command_name += (static_cast<InsetCommand *>(inset))->getContents();
2893 command_name += "\"";
2898 sgmlOpenTag(ofs, depth+command_depth, command_name);
2899 item_name = "title";
2900 sgmlOpenTag(ofs, depth + 1 + command_depth, item_name);
2903 case LATEX_ENVIRONMENT:
2904 case LATEX_ITEM_ENVIRONMENT:
2905 if (depth < par->depth) {
2907 environment_stack[depth].clear();
2910 if (environment_stack[depth] != style.latexname()) {
2911 environment_stack[depth] = style.latexname();
2912 environment_inner[depth] = "!-- --";
2913 sgmlOpenTag(ofs, depth + command_depth,
2914 environment_stack[depth]);
2916 if(environment_inner[depth] != "!-- --") {
2917 item_name= "listitem";
2919 command_depth + depth,
2921 if (environment_inner[depth] == "varlistentry")
2923 depth + command_depth,
2924 environment_inner[depth]);
2928 if(style.latextype == LATEX_ENVIRONMENT) {
2929 if(!style.latexparam().empty())
2930 sgmlOpenTag(ofs, depth + command_depth,
2931 style.latexparam());
2935 desc_on = (style.labeltype == LABEL_MANUAL);
2938 environment_inner[depth]= "varlistentry";
2940 environment_inner[depth]= "listitem";
2942 sgmlOpenTag(ofs, depth + 1 + command_depth,
2943 environment_inner[depth]);
2947 sgmlOpenTag(ofs, depth + 1 + command_depth,
2952 sgmlOpenTag(ofs, depth + 1 + command_depth,
2957 sgmlOpenTag(ofs, depth + command_depth,
2963 string tmp_par, extra_par;
2965 SimpleDocBookOnePar(tmp_par, extra_par, par, desc_on,
2966 depth + 1 + command_depth);
2970 DocBookHandleFootnote(ofs, par,
2971 depth + 1 + command_depth);
2973 while(par && par->IsDummy());
2976 /* write closing SGML tags */
2977 switch(style.latextype) {
2980 sgmlCloseTag(ofs, depth + command_depth, end_tag);
2982 case LATEX_ENVIRONMENT:
2983 if(!style.latexparam().empty())
2984 sgmlCloseTag(ofs, depth + command_depth,
2985 style.latexparam());
2987 case LATEX_ITEM_ENVIRONMENT:
2988 if(desc_on == 1) break;
2990 sgmlCloseTag(ofs, depth + 1 + command_depth, end_tag);
2992 case LATEX_PARAGRAPH:
2993 if(style.latexname() != "dummy")
2994 sgmlCloseTag(ofs, depth + command_depth,
2998 sgmlCloseTag(ofs, depth + command_depth,
3005 for(; depth >= 0; --depth) {
3006 if(!environment_stack[depth].empty()) {
3007 if(environment_inner[depth] != "!-- --") {
3008 item_name= "listitem";
3009 sgmlCloseTag(ofs, command_depth + depth,
3011 if( environment_inner[depth] == "varlistentry")
3012 sgmlCloseTag(ofs, depth + command_depth,
3013 environment_inner[depth]);
3016 sgmlCloseTag(ofs, depth + command_depth,
3017 environment_stack[depth]);
3021 for(int j = command_depth; j >= command_base; --j)
3022 if(!command_stack[j].empty())
3023 sgmlCloseTag(ofs, j, command_stack[j]);
3026 sgmlCloseTag(ofs, 0, top_element);
3029 // How to check for successful close
3033 void Buffer::SimpleDocBookOnePar(string & file, string & extra,
3034 LyXParagraph * par, int & desc_on,
3038 par->SimpleDocBookOneTablePar(file, extra, desc_on, depth);
3041 LyXFont font1, font2;
3044 LyXParagraph::size_type main_body;
3046 string emph= "emphasis";
3047 bool emph_flag= false;
3048 int char_line_count= 0;
3050 LyXLayout const & style = textclasslist.Style(params.textclass,
3053 if (style.labeltype != LABEL_MANUAL)
3056 main_body = par->BeginningOfMainBody();
3058 /* gets paragraph main font */
3060 font1 = style.labelfont;
3064 char_line_count = depth;
3065 if(!style.free_spacing)
3066 for (j= 0;j< depth;j++)
3069 /* parsing main loop */
3070 for (LyXParagraph::size_type i = 0;
3071 i < par->size(); ++i) {
3072 font2 = par->getFont(i);
3074 /* handle <emphasis> tag */
3075 if (font1.emph() != font2.emph() && i) {
3076 if (font2.emph() == LyXFont::ON) {
3077 file += "<emphasis>";
3080 file += "</emphasis>";
3085 c = par->GetChar(i);
3087 if (c == LyXParagraph::META_INSET) {
3088 inset = par->GetInset(i);
3090 inset->DocBook(tmp_out);
3092 // This code needs some explanation:
3093 // Two insets are treated specially
3094 // label if it is the first element in a command paragraph
3096 // graphics inside tables or figure floats can't go on
3097 // title (the equivalente in latex for this case is caption
3098 // and title should come first
3101 if(desc_on!= 3 || i!= 0) {
3102 if(!tmp_out.empty() && tmp_out[0] == '@') {
3104 extra += frontStrip(tmp_out, '@');
3106 file += frontStrip(tmp_out, '@');
3111 } else if (font2.latex() == LyXFont::ON) {
3112 // "TeX"-Mode on ==> SGML-Mode on.
3119 if (par->linuxDocConvertChar(c, sgml_string)
3120 && !style.free_spacing) { // in freespacing
3122 // non-breaking characters
3127 file += "</term><listitem><para>";
3135 file += sgml_string;
3141 /* needed if there is an optional argument but no contents */
3142 if (main_body > 0 && main_body == par->size()) {
3146 file += "</emphasis>";
3149 /* resets description flag correctly */
3152 /* <term> not closed... */
3160 // candidate for move to BufferView
3161 bool Buffer::removeAutoInsets()
3163 LyXParagraph *par = paragraph;
3166 LyXCursor cursor = users->text->cursor;
3168 LyXCursor cursor = text->cursor;
3170 LyXCursor tmpcursor = cursor;
3171 cursor.par = tmpcursor.par->ParFromPos(tmpcursor.pos);
3172 cursor.pos = tmpcursor.par->PositionInParFromPos(tmpcursor.pos);
3176 if (par->AutoDeleteInsets()){
3178 if (par->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE){
3180 /* this is possible now, since SetCursor takes
3181 care about footnotes */
3182 users->text->SetCursorIntern(par, 0);
3183 users->text->RedoParagraphs(users->text->cursor, users->text->cursor.par->Next());
3184 users->text->FullRebreak();
3186 /* this is possible now, since SetCursor takes
3187 care about footnotes */
3188 text->SetCursorIntern(par, 0);
3189 text->RedoParagraphs(text->cursor, text->cursor.par->Next());
3190 text->FullRebreak();
3196 /* avoid forbidden cursor positions caused by error removing */
3197 if (cursor.pos > cursor.par->Last())
3198 cursor.pos = cursor.par->Last();
3200 users->text->SetCursorIntern(cursor.par, cursor.pos);
3202 text->SetCursorIntern(cursor.par, cursor.pos);
3209 int Buffer::runLaTeX()
3212 if (!users->text) return 0;
3214 if (!text) return 0;
3219 // get LaTeX-Filename
3220 string name = getLatexName();
3222 string path = OnlyPath(filename);
3224 string org_path = path;
3225 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
3229 Path p(path); // path to LaTeX file
3230 users->owner()->getMiniBuffer()->Set(_("Running LaTeX..."));
3232 // Remove all error insets
3233 bool a = removeAutoInsets();
3235 // Always generate the LaTeX file
3236 makeLaTeXFile(name, org_path, false);
3239 // do the LaTex run(s)
3241 LaTeX latex(lyxrc->latex_command, name, filepath);
3242 int res = latex.run(terr,
3243 users->owner()->getMiniBuffer()); // running latex
3245 // check return value from latex.run().
3246 if ((res & LaTeX::NO_LOGFILE)) {
3247 WriteAlert(_("LaTeX did not work!"),
3248 _("Missing log file:"), name);
3249 } else if ((res & LaTeX::ERRORS)) {
3250 users->owner()->getMiniBuffer()->Set(_("Done"));
3251 // Insert all errors as errors boxes
3254 // Dvi should also be kept dirty if the latex run
3255 // ends up with errors. However it should be possible
3256 // to view a dirty dvi too.
3258 //no errors or any other things to think about so:
3259 users->owner()->getMiniBuffer()->Set(_("Done"));
3263 // if we removed error insets before we ran LaTeX or if we inserted
3264 // error insets after we ran LaTeX this must be run:
3265 if (a || (res & LaTeX::ERRORS)){
3268 users->updateScrollbar();
3272 return latex.getNumErrors();
3276 int Buffer::runLiterate()
3279 if (!users->text) return 0;
3281 if (!text) return 0;
3286 // get LaTeX-Filename
3287 string name = getLatexName();
3288 // get Literate-Filename
3289 string lit_name = ChangeExtension (getLatexName(),
3290 lyxrc->literate_extension, true);
3292 string path = OnlyPath(filename);
3294 string org_path = path;
3295 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
3299 Path p(path); // path to Literate file
3300 users->owner()->getMiniBuffer()->Set(_("Running Literate..."));
3302 // Remove all error insets
3303 bool a = removeAutoInsets();
3305 // generate the Literate file if necessary
3306 if (!isDviClean() || a) {
3307 makeLaTeXFile(lit_name, org_path, false);
3311 Literate literate(lyxrc->latex_command, name, filepath,
3313 lyxrc->literate_command, lyxrc->literate_error_filter,
3314 lyxrc->build_command, lyxrc->build_error_filter);
3316 int res = literate.weave(terr, users->owner()->getMiniBuffer());
3318 // check return value from literate.weave().
3319 if ((res & Literate::NO_LOGFILE)) {
3320 WriteAlert(_("Literate command did not work!"),
3321 _("Missing log file:"), name);
3322 } else if ((res & Literate::ERRORS)) {
3323 users->owner()->getMiniBuffer()->Set(_("Done"));
3324 // Insert all errors as errors boxes
3327 // Dvi should also be kept dirty if the latex run
3328 // ends up with errors. However it should be possible
3329 // to view a dirty dvi too.
3331 //no errors or any other things to think about so:
3332 users->owner()->getMiniBuffer()->Set(_("Done"));
3336 // if we removed error insets before we ran LaTeX or if we inserted
3337 // error insets after we ran LaTeX this must be run:
3338 if (a || (res & Literate::ERRORS)){
3341 users->updateScrollbar();
3345 return literate.getNumErrors();
3349 int Buffer::buildProgram()
3352 if (!users->text) return 0;
3354 if (!text) return 0;
3359 // get LaTeX-Filename
3360 string name = getLatexName();
3361 // get Literate-Filename
3362 string lit_name = ChangeExtension(getLatexName(),
3363 lyxrc->literate_extension, true);
3365 string path = OnlyPath(filename);
3367 string org_path = path;
3368 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
3372 Path p(path); // path to Literate file
3373 users->owner()->getMiniBuffer()->Set(_("Building Program..."));
3375 // Remove all error insets
3376 bool a = removeAutoInsets();
3378 // generate the LaTeX file if necessary
3379 if (!isNwClean() || a) {
3380 makeLaTeXFile(lit_name, org_path, false);
3384 Literate literate(lyxrc->latex_command, name, filepath,
3386 lyxrc->literate_command, lyxrc->literate_error_filter,
3387 lyxrc->build_command, lyxrc->build_error_filter);
3389 int res = literate.build(terr, users->owner()->getMiniBuffer());
3391 // check return value from literate.build().
3392 if ((res & Literate::NO_LOGFILE)) {
3393 WriteAlert(_("Build did not work!"),
3394 _("Missing log file:"), name);
3395 } else if ((res & Literate::ERRORS)) {
3396 users->owner()->getMiniBuffer()->Set(_("Done"));
3397 // Insert all errors as errors boxes
3400 // Literate files should also be kept dirty if the literate
3401 // command run ends up with errors.
3403 //no errors or any other things to think about so:
3404 users->owner()->getMiniBuffer()->Set(_("Done"));
3408 // if we removed error insets before we ran Literate/Build or if we inserted
3409 // error insets after we ran Literate/Build this must be run:
3410 if (a || (res & Literate::ERRORS)){
3413 users->updateScrollbar();
3417 return literate.getNumErrors();
3421 // This should be enabled when the Chktex class is implemented. (Asger)
3422 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
3423 // Other flags: -wall -v0 -x
3424 int Buffer::runChktex()
3427 if (!users->text) return 0;
3429 if (!text) return 0;
3434 // get LaTeX-Filename
3435 string name = getLatexName();
3436 string path = OnlyPath(filename);
3438 string org_path = path;
3439 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
3443 Path p(path); // path to LaTeX file
3444 users->owner()->getMiniBuffer()->Set(_("Running chktex..."));
3446 // Remove all error insets
3447 bool a = removeAutoInsets();
3449 // Generate the LaTeX file if neccessary
3450 if (!isDviClean() || a) {
3451 makeLaTeXFile(name, org_path, false);
3456 Chktex chktex(lyxrc->chktex_command, name, filepath);
3457 int res = chktex.run(terr); // run chktex
3460 WriteAlert(_("chktex did not work!"),
3461 _("Could not run with file:"), name);
3462 } else if (res > 0) {
3463 // Insert all errors as errors boxes
3467 // if we removed error insets before we ran chktex or if we inserted
3468 // error insets after we ran chktex, this must be run:
3472 users->updateScrollbar();
3480 extern void AllFloats(char, char);
3483 // candidate for move to BufferView
3484 void Buffer::insertErrors(TeXErrors & terr)
3487 // Save the cursor position
3488 LyXCursor cursor = users->text->cursor;
3490 // Save the cursor position
3491 LyXCursor cursor = text->cursor;
3494 // This is drastic, but it's the only fix, I could find. (Asger)
3498 for (TeXErrors::Errors::const_iterator cit = terr.begin();
3501 string desctext((*cit).error_desc);
3502 string errortext((*cit).error_text);
3503 string msgtxt = desctext + '\n' + errortext;
3504 int errorrow = (*cit).error_in_line;
3506 // Insert error string for row number
3510 texrow.getIdFromRow(errorrow, tmpid, tmppos);
3512 LyXParagraph * texrowpar = 0;
3516 texrowpar = users->text->FirstParagraph();
3519 texrowpar = users->text->GetParFromID(tmpid);
3523 texrowpar = text->FirstParagraph();
3526 texrowpar = text->GetParFromID(tmpid);
3533 InsetError * new_inset = new InsetError(msgtxt);
3535 users->text->SetCursorIntern(texrowpar, tmppos);
3536 users->text->InsertInset(new_inset);
3537 users->text->FullRebreak();
3539 // Restore the cursor position
3540 users->text->SetCursorIntern(cursor.par, cursor.pos);
3542 text->SetCursorIntern(texrowpar, tmppos);
3543 text->InsertInset(new_inset);
3544 text->FullRebreak();
3546 // Restore the cursor position
3547 text->SetCursorIntern(cursor.par, cursor.pos);
3552 // candidate for move to BufferView
3553 void Buffer::setCursorFromRow (int row)
3558 texrow.getIdFromRow(row, tmpid, tmppos);
3560 LyXParagraph * texrowpar;
3564 texrowpar = users->text->FirstParagraph();
3567 texrowpar = users->text->GetParFromID(tmpid);
3569 users->text->SetCursor(texrowpar, tmppos);
3572 texrowpar = text->FirstParagraph();
3575 texrowpar = text->GetParFromID(tmpid);
3577 text->SetCursor(texrowpar, tmppos);
3582 void Buffer::RoffAsciiTable(ostream & os, LyXParagraph * par)
3584 LyXFont font1 = LyXFont(LyXFont::ALL_INHERIT);
3587 LyXParagraph::size_type i;
3591 string fname1 = TmpFileName(string(), "RAT1");
3592 string fname2 = TmpFileName(string(), "RAT2");
3594 ofstream ofs(fname1.c_str());
3596 WriteAlert(_("LYX_ERROR:"),
3597 _("Cannot open temporary file:"), fname1);
3600 par->table->RoffEndOfCell(ofs, -1);
3601 for (i = 0; i < par->size(); ++i) {
3602 c = par->GetChar(i);
3603 if (par->table->IsContRow(cell)) {
3604 if (c == LyXParagraph::META_NEWLINE)
3608 font2 = par->GetFontSettings(i);
3609 if (font1.latex() != font2.latex()) {
3610 if (font2.latex() != LyXFont::OFF)
3614 case LyXParagraph::META_INSET:
3615 if ((inset = par->GetInset(i))) {
3616 fstream fs(fname2.c_str(), ios::in|ios::out);
3618 WriteAlert(_("LYX_ERROR:"),
3619 _("Cannot open temporary file:"), fname2);
3621 remove(fname1.c_str());
3624 inset->Latex(fs, -1);
3637 case LyXParagraph::META_NEWLINE:
3638 if (par->table->CellHasContRow(cell)>= 0)
3639 par->RoffContTableRows(ofs, i+1, cell);
3640 par->table->RoffEndOfCell(ofs, cell);
3643 case LyXParagraph::META_HFILL:
3645 case LyXParagraph::META_PROTECTED_SEPARATOR:
3655 << "RoffAsciiTable:"
3656 " NULL char in structure." << endl;
3660 par->table->RoffEndOfCell(ofs, cell);
3662 string cmd = lyxrc->ascii_roff_command + " >" + fname2;
3663 cmd = subst(cmd, "$$FName", fname1);
3664 Systemcalls one(Systemcalls::System, cmd);
3665 if (!(lyxerr.debugging(Debug::ROFF))) {
3666 remove(fname1.c_str());
3668 ifstream ifs(fname2.c_str());
3670 WriteFSAlert(_("Error! Can't open temporary file:"), fname2);
3673 // now output the produced file
3677 WriteAlert(_("Error!"),
3678 _("Error executing *roff command on table"));
3679 // overread leading blank lines
3680 while(!ifs && (c == '\n'))
3683 for(j = 0; j < par->depth; ++j)
3685 while(!ifs && (c != '\n')) {
3690 // overread trailing blank lines
3691 while(!ifs && (c == '\n'))
3695 remove(fname2.c_str());
3699 /// changed Heinrich Bauer, 23/03/98
3700 bool Buffer::isDviClean()
3702 if (lyxrc->use_tempdir)
3703 return dvi_clean_tmpd;
3705 return dvi_clean_orgd;
3709 /// changed Heinrich Bauer, 23/03/98
3710 void Buffer::markDviClean()
3712 if (lyxrc->use_tempdir)
3713 dvi_clean_tmpd = true;
3715 dvi_clean_orgd = true;
3719 /// changed Heinrich Bauer, 23/03/98
3720 void Buffer::markDviDirty()
3722 if (lyxrc->use_tempdir)
3723 dvi_clean_tmpd = false;
3725 dvi_clean_orgd = false;
3730 // candidate for move to BufferView
3731 void Buffer::update(signed char f)
3735 users->owner()->updateLayoutChoice();
3736 if (!text->selection && f > -3)
3737 text->sel_cursor = text->cursor;
3740 text->FullRebreak();
3744 if (f != 3 && f != -3) {
3746 users->updateScrollbar();
3749 if (f == 1 || f == -1) {
3752 users->owner()->getMiniBuffer()->setTimer(4);
3760 void Buffer::validate(LaTeXFeatures & features)
3762 LyXParagraph * par = paragraph;
3763 LyXTextClass const & tclass =
3764 textclasslist.TextClass(params.textclass);
3766 // AMS Style is at document level
3768 features.amsstyle = (params.use_amsmath ||
3769 tclass.provides(LyXTextClass::amsmath));
3772 // We don't use "lyxerr.debug" because of speed. (Asger)
3773 if (lyxerr.debugging(Debug::LATEX))
3774 lyxerr << "Paragraph: " << par << endl;
3776 // Now just follow the list of paragraphs and run
3777 // validate on each of them.
3778 par->validate(features);
3780 // and then the next paragraph
3784 // the bullet shapes are buffer level not paragraph level
3785 // so they are tested here
3786 for (int i = 0; i < 4; ++i) {
3787 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
3788 int font = params.user_defined_bullets[i].getFont();
3791 .user_defined_bullets[i]
3798 features.latexsym = true;
3802 features.amssymb = true;
3804 else if ((font >= 2 && font <= 5)) {
3805 features.pifont = true;
3810 if (lyxerr.debugging(Debug::LATEX)) {
3811 features.showStruct(params);
3816 void Buffer::setPaperStuff()
3818 params.papersize = BufferParams::PAPER_DEFAULT;
3819 char c1 = params.paperpackage;
3820 if (c1 == BufferParams::PACKAGE_NONE) {
3821 char c2 = params.papersize2;
3822 if (c2 == BufferParams::VM_PAPER_USLETTER)
3823 params.papersize = BufferParams::PAPER_USLETTER;
3824 else if (c2 == BufferParams::VM_PAPER_USLEGAL)
3825 params.papersize = BufferParams::PAPER_LEGALPAPER;
3826 else if (c2 == BufferParams::VM_PAPER_USEXECUTIVE)
3827 params.papersize = BufferParams::PAPER_EXECUTIVEPAPER;
3828 else if (c2 == BufferParams::VM_PAPER_A3)
3829 params.papersize = BufferParams::PAPER_A3PAPER;
3830 else if (c2 == BufferParams::VM_PAPER_A4)
3831 params.papersize = BufferParams::PAPER_A4PAPER;
3832 else if (c2 == BufferParams::VM_PAPER_A5)
3833 params.papersize = BufferParams::PAPER_A5PAPER;
3834 else if ((c2 == BufferParams::VM_PAPER_B3) || (c2 == BufferParams::VM_PAPER_B4) ||
3835 (c2 == BufferParams::VM_PAPER_B5))
3836 params.papersize = BufferParams::PAPER_B5PAPER;
3837 } else if ((c1 == BufferParams::PACKAGE_A4) || (c1 == BufferParams::PACKAGE_A4WIDE) ||
3838 (c1 == BufferParams::PACKAGE_WIDEMARGINSA4))
3839 params.papersize = BufferParams::PAPER_A4PAPER;
3844 void Buffer::setOldPaperStuff()
3846 char c = params.papersize = params.papersize2;
3847 params.papersize2 = BufferParams::VM_PAPER_DEFAULT;
3848 params.paperpackage = BufferParams::PACKAGE_NONE;
3849 if (c == OLD_PAPER_A4PAPER)
3850 params.papersize2 = BufferParams::VM_PAPER_A4;
3851 else if (c == OLD_PAPER_A4)
3852 params.paperpackage = BufferParams::PACKAGE_A4;
3853 else if (c == OLD_PAPER_A4WIDE)
3854 params.paperpackage = BufferParams::PACKAGE_A4WIDE;
3855 else if (c == OLD_PAPER_WIDEMARGINSA4)
3856 params.paperpackage = BufferParams::PACKAGE_WIDEMARGINSA4;
3857 else if (c == OLD_PAPER_USLETTER)
3858 params.papersize2 = BufferParams::VM_PAPER_USLETTER;
3859 else if (c == OLD_PAPER_A5PAPER)
3860 params.papersize2 = BufferParams::VM_PAPER_A5;
3861 else if (c == OLD_PAPER_B5PAPER)
3862 params.papersize2 = BufferParams::VM_PAPER_B5;
3863 else if (c == OLD_PAPER_EXECUTIVEPAPER)
3864 params.papersize2 = BufferParams::VM_PAPER_USEXECUTIVE;
3865 else if (c == OLD_PAPER_LEGALPAPER)
3866 params.papersize2 = BufferParams::VM_PAPER_USLEGAL;
3872 // candidate for move to BufferView
3873 void Buffer::insertInset(Inset * inset, string const & lout,
3876 // check for table/list in tables
3877 if (no_table && users->text->cursor.par->table){
3878 WriteAlert(_("Impossible Operation!"),
3879 _("Cannot insert table/list in table."),
3883 // not quite sure if we want this...
3884 users->text->SetCursorParUndo();
3885 users->text->FreezeUndo();
3888 if (!lout.empty()) {
3890 users->text->BreakParagraph();
3893 if (users->text->cursor.par->Last()) {
3894 users->text->CursorLeft();
3896 users->text->BreakParagraph();
3900 int lay = textclasslist.NumberOfLayout(params.textclass,
3902 if (lay == -1) // layout not found
3903 // use default layout "Standard" (0)
3906 users->text->SetLayout(lay);
3908 users->text->SetParagraph(0, 0,
3910 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3916 users->text->current_font.setLatex(LyXFont::OFF);
3919 users->text->InsertInset(inset);
3922 users->text->UnFreezeUndo();
3925 void Buffer::insertInset(Inset * inset, string const & lout,
3928 // check for table/list in tables
3929 if (no_table && text->cursor.par->table){
3930 WriteAlert(_("Impossible Operation!"),
3931 _("Cannot insert table/list in table."),
3935 // not quite sure if we want this...
3936 text->SetCursorParUndo();
3940 if (!lout.empty()) {
3942 text->BreakParagraph();
3945 if (text->cursor.par->Last()) {
3948 text->BreakParagraph();
3952 int lay = textclasslist.NumberOfLayout(params.textclass,
3954 if (lay == -1) // layout not found
3955 // use default layout "Standard" (0)
3958 text->SetLayout(lay);
3960 text->SetParagraph(0, 0,
3962 VSpace(VSpace::NONE), VSpace(VSpace::NONE),
3968 text->current_font.setLatex(LyXFont::OFF);
3971 text->InsertInset(inset);
3974 text->UnFreezeUndo();
3978 // Open and lock an updatable inset
3979 // candidate for move to BufferView
3980 void Buffer::open_new_inset(UpdatableInset * new_inset)
3984 users->text->FinishUndo();
3985 insertInset(new_inset);
3986 users->text->CursorLeft();
3988 new_inset->Edit(0, 0);
3992 insertInset(new_inset);
3995 new_inset->Edit(0, 0);
4000 /* This function should be in Buffer because it's a buffer's property (ale) */
4001 string Buffer::getIncludeonlyList(char delim)
4004 LyXParagraph * par = paragraph;
4005 LyXParagraph::size_type pos;
4009 while ((inset = par->ReturnNextInsetPointer(pos))){
4010 if (inset->LyxCode() == Inset::INCLUDE_CODE) {
4011 InsetInclude * insetinc =
4012 static_cast<InsetInclude*>(inset);
4013 if (insetinc->isInclude()
4014 && insetinc->isNoLoad()) {
4017 lst += ChangeExtension(insetinc->getContents(), string(), true);
4024 lyxerr.debug() << "Includeonly(" << lst << ')' << endl;
4029 /* This is also a buffer property (ale) */
4030 string Buffer::getReferenceList(char delim)
4032 /// if this is a child document and the parent is already loaded
4033 /// Use the parent's list instead [ale990407]
4034 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
4035 Buffer * tmp = bufferlist.getBuffer(params.parentname);
4037 return tmp->getReferenceList(delim);
4040 LyXParagraph * par = paragraph;
4041 LyXParagraph::size_type pos;
4046 while ((inset = par->ReturnNextInsetPointer(pos))){
4047 for (int i = 0; i < inset->GetNumberOfLabels(); i++) {
4050 lst += inset->getLabel(i);
4056 lyxerr.debug() << "References(" << lst << ")" << endl;
4061 /* This is also a buffer property (ale) */
4062 string Buffer::getBibkeyList(char delim)
4064 /// if this is a child document and the parent is already loaded
4065 /// Use the parent's list instead [ale990412]
4066 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
4067 Buffer * tmp = bufferlist.getBuffer(params.parentname);
4069 return tmp->getBibkeyList(delim);
4073 LyXParagraph * par = paragraph;
4076 if (!bibkeys.empty())
4078 bibkeys += par->bibkey->getContents();
4083 // Might be either using bibtex or a child has bibliography
4084 if (bibkeys.empty()) {
4088 LyXParagraph::size_type pos = -1;
4090 // Search for Bibtex or Include inset
4091 while ((inset = par->ReturnNextInsetPointer(pos))) {
4092 if (inset-> LyxCode() == Inset::BIBTEX_CODE) {
4093 if (!bibkeys.empty())
4095 bibkeys += static_cast<InsetBibtex*>(inset)->getKeys();
4096 } else if (inset-> LyxCode() == Inset::INCLUDE_CODE) {
4097 string bk = static_cast<InsetInclude*>(inset)->getKeys();
4099 if (!bibkeys.empty())
4110 lyxerr.debug() << "Bibkeys(" << bibkeys << ")" << endl;
4115 // candidate for move to BufferView
4116 /* This is also a buffer property (ale) */
4117 // Not so sure about that. a goto Label function can not be buffer local, just
4118 // think how this will work in a multiwindo/buffer environment, all the
4119 // cursors in all the views showing this buffer will move. (Lgb)
4120 // OK, then no cursor action should be allowed in buffer. (ale)
4121 bool Buffer::gotoLabel(string const & label)
4124 LyXParagraph * par = paragraph;
4125 LyXParagraph::size_type pos;
4129 while ((inset = par->ReturnNextInsetPointer(pos))){
4130 for (int i = 0; i < inset->GetNumberOfLabels(); i++) {
4131 if (label == inset->getLabel(i)) {
4134 users->text->SetCursor(par, pos);
4135 users->text->sel_cursor = users->text->cursor;
4140 text->SetCursor(par, pos);
4141 text->sel_cursor = text->cursor;
4155 bool Buffer::isDepClean(string const & name) const
4157 DEPCLEAN * item = dep_clean;
4158 while (item && item->master != name)
4160 if (!item) return true;
4165 void Buffer::markDepClean(string const & name)
4168 dep_clean = new DEPCLEAN;
4169 dep_clean->clean = true;
4170 dep_clean->master = name;
4171 dep_clean->next = 0;
4173 DEPCLEAN* item = dep_clean;
4174 while (item && item->master != name)
4179 item = new DEPCLEAN;
4181 item->master = name;
4187 void Buffer::Dispatch(const string & command)
4189 // Split command string into command and argument
4190 string cmd, line = frontStrip(command);
4191 string arg = strip(frontStrip(split(line, cmd, ' ')));
4193 Dispatch(lyxaction.LookupFunc(cmd.c_str()), arg.c_str());
4196 void Buffer::Dispatch(int action, const string & argument)
4200 MenuExport(this, argument);
4205 lyxerr << "A truly unknown func!" << endl;