1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2000 The LyX Team.
9 * This file is Copyright 1996-1999
12 * ======================================================
22 #include <sys/types.h>
28 #pragma implementation "buffer.h"
32 #include "bufferlist.h"
34 #include "lyx_gui_misc.h"
35 #include "LyXAction.h"
38 #include "tex-strings.h"
40 #include "bufferview_funcs.h"
41 #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"
52 #include "insets/insetlatexaccent.h"
53 #include "insets/insetbib.h"
54 #include "insets/insetcite.h"
55 #include "insets/insetexternal.h"
56 #include "insets/insetindex.h"
57 #include "insets/insetinclude.h"
58 #include "insets/insettoc.h"
59 #include "insets/insetlof.h"
60 #include "insets/insetlot.h"
61 #include "insets/insetloa.h"
62 #include "insets/insetparent.h"
63 #include "insets/insetspecialchar.h"
64 #include "insets/figinset.h"
65 #include "insets/insettext.h"
66 #include "insets/insetert.h"
67 #include "insets/insetgraphics.h"
68 #include "insets/insetfoot.h"
69 #include "insets/insetmarginal.h"
70 #include "insets/insetminipage.h"
71 #include "insets/insetfloat.h"
72 #include "insets/insetlist.h"
73 #include "insets/insettabular.h"
74 #include "insets/insettheorem.h"
75 #include "insets/insetcaption.h"
76 #include "support/filetools.h"
77 #include "support/path.h"
83 #include "LaTeXFeatures.h"
84 #include "support/syscall.h"
85 #include "support/lyxlib.h"
86 #include "support/FileInfo.h"
90 #include "lyx_gui_misc.h" // WarnReadonly()
91 #include "frontends/Dialogs.h"
106 using std::istringstream;
109 // all these externs should eventually be removed.
110 extern BufferList bufferlist;
112 extern void MenuExport(Buffer *, string const &);
113 extern LyXAction lyxaction;
116 static const float LYX_FORMAT = 2.16;
118 extern int tex_code_break_column;
121 Buffer::Buffer(string const & file, bool ronly)
123 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
125 filepath = OnlyPath(file);
134 if (read_only || (lyxrc.use_tempdir)) {
135 tmppath = CreateBufferTmpDir();
136 } else tmppath.erase();
142 lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
143 // here the buffer should take care that it is
144 // saved properly, before it goes into the void.
146 // make sure that views using this buffer
151 if (!tmppath.empty()) {
152 DestroyBufferTmpDir(tmppath);
155 LyXParagraph * par = paragraph;
156 LyXParagraph * tmppar;
166 string Buffer::getLatexName(bool no_path) const
169 return OnlyFilename(ChangeExtension(MakeLatexName(filename),
172 return ChangeExtension(MakeLatexName(filename),
177 void Buffer::setReadonly(bool flag)
179 if (read_only != flag) {
182 users->owner()->getDialogs()->updateBufferDependent();
185 WarnReadonly(filename);
190 bool Buffer::saveParamsAsDefaults()
192 string fname = AddName(AddPath(user_lyxdir, "templates/"),
194 Buffer defaults = Buffer(fname);
196 // Use the current buffer's parameters as default
197 defaults.params = params;
199 // add an empty paragraph. Is this enough?
200 defaults.paragraph = new LyXParagraph;
202 return defaults.writeFile(defaults.filename, false);
206 /// Update window titles of all users
207 // Should work on a list
208 void Buffer::updateTitles() const
210 if (users) users->owner()->updateWindowTitle();
214 /// Reset autosave timer of all users
215 // Should work on a list
216 void Buffer::resetAutosaveTimers() const
218 if (users) users->owner()->resetAutosaveTimer();
222 void Buffer::fileName(string const & newfile)
224 filename = MakeAbsPath(newfile);
225 filepath = OnlyPath(filename);
226 setReadonly(IsFileWriteable(filename) == 0);
231 // candidate for move to BufferView
232 // (at least some parts in the beginning of the func)
235 // changed to be public and have one parameter
236 // if par = 0 normal behavior
237 // else insert behavior
238 // Returns false if "\the_end" is not read for formats >= 2.13. (Asger)
239 bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par)
243 char depth = 0; // signed or unsigned?
245 LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
246 LyXParagraph::footnote_kind footnotekind = LyXParagraph::FOOTNOTE;
248 bool the_end_read = false;
250 LyXParagraph * return_par = 0;
251 LyXFont font(LyXFont::ALL_INHERIT, params.language_info);
252 if (format < 2.16 && params.language == "hebrew")
253 font.setLanguage(default_language);
255 // If we are inserting, we cheat and get a token in advance
256 bool has_token = false;
260 par = new LyXParagraph;
262 users->text->BreakParagraph(users);
263 return_par = users->text->FirstParagraph();
266 // We don't want to adopt the parameters from the
267 // document we insert, so we skip until the text begins:
270 pretoken = lex.GetString();
271 if (pretoken == "\\layout") {
283 pretoken = lex.GetString();
286 // Profiling show this should give a lot: (Asger)
287 string const token = pretoken;
291 the_end_read = parseSingleLyXformat2Token(lex, par, return_par,
304 paragraph = return_par;
310 // We'll remove this later. (Lgb)
311 static string last_inset_read;
315 Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
316 LyXParagraph *& return_par,
317 string const & token, int & pos,
318 char & depth, LyXFont & font
320 , LyXParagraph::footnote_flag & footnoteflag,
321 LyXParagraph::footnote_kind & footnotekind
325 bool the_end_read = false;
327 if (token[0] != '\\') {
328 for (string::const_iterator cit = token.begin();
329 cit != token.end(); ++cit) {
330 par->InsertChar(pos, (*cit), font);
333 } else if (token == "\\i") {
334 Inset * inset = new InsetLatexAccent;
335 inset->Read(this, lex);
336 par->InsertInset(pos, inset, font);
338 } else if (token == "\\layout") {
343 par = new LyXParagraph(par);
347 string layoutname = lex.GetString();
348 pair<bool, LyXTextClass::LayoutList::size_type> pp
349 = textclasslist.NumberOfLayout(params.textclass,
352 par->layout = pp.second;
353 } else { // layout not found
354 // use default layout "Standard" (0)
357 // Test whether the layout is obsolete.
358 LyXLayout const & layout =
359 textclasslist.Style(params.textclass,
361 if (!layout.obsoleted_by().empty())
363 textclasslist.NumberOfLayout(params.textclass,
364 layout.obsoleted_by()).second;
366 par->footnoteflag = footnoteflag;
367 par->footnotekind = footnotekind;
370 font = LyXFont(LyXFont::ALL_INHERIT, params.language_info);
371 if (format < 2.16 && params.language == "hebrew")
372 font.setLanguage(default_language);
374 } else if (token == "\\end_float") {
379 par = new LyXParagraph(par);
381 footnotekind = LyXParagraph::FOOTNOTE;
382 footnoteflag = LyXParagraph::NO_FOOTNOTE;
385 par->layout = LYX_DUMMY_LAYOUT;
386 font = LyXFont(LyXFont::ALL_INHERIT, params.language_info);
387 if (format < 2.16 && params.language == "hebrew")
388 font.setLanguage(default_language);
389 } else if (token == "\\begin_float") {
390 int tmpret = lex.FindToken(string_footnotekinds);
391 if (tmpret == -1) ++tmpret;
392 if (tmpret != LYX_LAYOUT_DEFAULT)
393 footnotekind = static_cast<LyXParagraph::footnote_kind>(tmpret); // bad
394 if (footnotekind == LyXParagraph::FOOTNOTE
395 || footnotekind == LyXParagraph::MARGIN)
396 footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
398 footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
400 } else if (token == "\\begin_float") {
401 // This is the compability reader, unfinished but tested.
404 string tmptok = lex.GetString();
405 //lyxerr << "old float: " << tmptok << endl;
410 if (tmptok == "footnote") {
411 inset = new InsetFoot;
412 } else if (tmptok == "margin") {
413 inset = new InsetMarginal;
414 } else if (tmptok == "fig") {
415 inset = new InsetFloat("figure");
416 old_float += "placement htbp\n";
417 } else if (tmptok == "tab") {
418 inset = new InsetFloat("table");
419 old_float += "placement htbp\n";
420 } else if (tmptok == "alg") {
421 inset = new InsetFloat("algorithm");
422 old_float += "placement htbp\n";
423 } else if (tmptok == "wide-fig") {
424 InsetFloat * tmp = new InsetFloat("figure");
427 old_float += "placement htbp\n";
428 } else if (tmptok == "wide-tab") {
429 InsetFloat * tmp = new InsetFloat("table");
432 old_float += "placement htbp\n";
435 if (!inset) return false; // no end read yet
437 old_float += "collapsed true\n";
439 // Here we need to check for \end_deeper and handle that
440 // before we do the footnote parsing.
441 // This _is_ a hack! (Lgb)
444 string tmp = lex.GetString();
445 if (tmp == "\\end_deeper") {
446 lyxerr << "\\end_deeper caught!" << endl;
448 lex.printError("\\end_deeper: "
449 "depth is already null");
460 old_float += lex.getLongString("\\end_float");
461 old_float += "\n\\end_inset\n";
462 //lyxerr << "float body: " << old_float << endl;
465 istringstream istr(old_float.c_str());
467 istrstream istr(old_float.c_str());
471 nylex.setStream(istr);
473 inset->Read(this, nylex);
474 par->InsertInset(pos, inset, font);
477 } else if (token == "\\begin_deeper") {
479 } else if (token == "\\end_deeper") {
481 lex.printError("\\end_deeper: "
482 "depth is already null");
486 } else if (token == "\\begin_preamble") {
487 params.readPreamble(lex);
488 } else if (token == "\\textclass") {
490 pair<bool, LyXTextClassList::size_type> pp =
491 textclasslist.NumberOfClass(lex.GetString());
493 params.textclass = pp.second;
495 lex.printError("Unknown textclass `$$Token'");
496 params.textclass = 0;
498 if (!textclasslist.Load(params.textclass)) {
499 // if the textclass wasn't loaded properly
500 // we need to either substitute another
501 // or stop loading the file.
502 // I can substitute but I don't see how I can
503 // stop loading... ideas?? ARRae980418
504 WriteAlert(_("Textclass Loading Error!"),
505 string(_("Can't load textclass ")) +
506 textclasslist.NameOfClass(params.textclass),
507 _("-- substituting default"));
508 params.textclass = 0;
510 } else if (token == "\\options") {
512 params.options = lex.GetString();
513 } else if (token == "\\language") {
514 params.readLanguage(lex);
515 } else if (token == "\\fontencoding") {
517 } else if (token == "\\inputencoding") {
519 params.inputenc = lex.GetString();
520 } else if (token == "\\graphics") {
521 params.readGraphicsDriver(lex);
522 } else if (token == "\\fontscheme") {
524 params.fonts = lex.GetString();
525 } else if (token == "\\noindent") {
526 par->noindent = true;
527 } else if (token == "\\fill_top") {
528 par->added_space_top = VSpace(VSpace::VFILL);
529 } else if (token == "\\fill_bottom") {
530 par->added_space_bottom = VSpace(VSpace::VFILL);
531 } else if (token == "\\line_top") {
532 par->line_top = true;
533 } else if (token == "\\line_bottom") {
534 par->line_bottom = true;
535 } else if (token == "\\pagebreak_top") {
536 par->pagebreak_top = true;
537 } else if (token == "\\pagebreak_bottom") {
538 par->pagebreak_bottom = true;
539 } else if (token == "\\start_of_appendix") {
540 par->start_of_appendix = true;
541 } else if (token == "\\paragraph_separation") {
542 int tmpret = lex.FindToken(string_paragraph_separation);
543 if (tmpret == -1) ++tmpret;
544 if (tmpret != LYX_LAYOUT_DEFAULT)
545 params.paragraph_separation =
546 static_cast<BufferParams::PARSEP>(tmpret);
547 } else if (token == "\\defskip") {
549 params.defskip = VSpace(lex.GetString());
550 } else if (token == "\\epsfig") { // obsolete
551 // Indeed it is obsolete, but we HAVE to be backwards
552 // compatible until 0.14, because otherwise all figures
553 // in existing documents are irretrivably lost. (Asger)
554 params.readGraphicsDriver(lex);
555 } else if (token == "\\quotes_language") {
556 int tmpret = lex.FindToken(string_quotes_language);
557 if (tmpret == -1) ++tmpret;
558 if (tmpret != LYX_LAYOUT_DEFAULT) {
559 InsetQuotes::quote_language tmpl =
560 InsetQuotes::EnglishQ;
563 tmpl = InsetQuotes::EnglishQ;
566 tmpl = InsetQuotes::SwedishQ;
569 tmpl = InsetQuotes::GermanQ;
572 tmpl = InsetQuotes::PolishQ;
575 tmpl = InsetQuotes::FrenchQ;
578 tmpl = InsetQuotes::DanishQ;
581 params.quotes_language = tmpl;
583 } else if (token == "\\quotes_times") {
585 switch(lex.GetInteger()) {
587 params.quotes_times = InsetQuotes::SingleQ;
590 params.quotes_times = InsetQuotes::DoubleQ;
593 } else if (token == "\\papersize") {
594 int tmpret = lex.FindToken(string_papersize);
598 params.papersize2 = tmpret;
599 } else if (token == "\\paperpackage") {
600 int tmpret = lex.FindToken(string_paperpackages);
603 params.paperpackage = BufferParams::PACKAGE_NONE;
605 params.paperpackage = tmpret;
606 } else if (token == "\\use_geometry") {
608 params.use_geometry = lex.GetInteger();
609 } else if (token == "\\use_amsmath") {
611 params.use_amsmath = lex.GetInteger();
612 } else if (token == "\\paperorientation") {
613 int tmpret = lex.FindToken(string_orientation);
614 if (tmpret == -1) ++tmpret;
615 if (tmpret != LYX_LAYOUT_DEFAULT)
616 params.orientation = static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
617 } else if (token == "\\paperwidth") {
619 params.paperwidth = lex.GetString();
620 } else if (token == "\\paperheight") {
622 params.paperheight = lex.GetString();
623 } else if (token == "\\leftmargin") {
625 params.leftmargin = lex.GetString();
626 } else if (token == "\\topmargin") {
628 params.topmargin = lex.GetString();
629 } else if (token == "\\rightmargin") {
631 params.rightmargin = lex.GetString();
632 } else if (token == "\\bottommargin") {
634 params.bottommargin = lex.GetString();
635 } else if (token == "\\headheight") {
637 params.headheight = lex.GetString();
638 } else if (token == "\\headsep") {
640 params.headsep = lex.GetString();
641 } else if (token == "\\footskip") {
643 params.footskip = lex.GetString();
644 } else if (token == "\\paperfontsize") {
646 params.fontsize = strip(lex.GetString());
647 } else if (token == "\\papercolumns") {
649 params.columns = lex.GetInteger();
650 } else if (token == "\\papersides") {
652 switch(lex.GetInteger()) {
654 case 1: params.sides = LyXTextClass::OneSide; break;
655 case 2: params.sides = LyXTextClass::TwoSides; break;
657 } else if (token == "\\paperpagestyle") {
659 params.pagestyle = strip(lex.GetString());
660 } else if (token == "\\bullet") {
662 int index = lex.GetInteger();
664 int temp_int = lex.GetInteger();
665 params.user_defined_bullets[index].setFont(temp_int);
666 params.temp_bullets[index].setFont(temp_int);
668 temp_int = lex.GetInteger();
669 params.user_defined_bullets[index].setCharacter(temp_int);
670 params.temp_bullets[index].setCharacter(temp_int);
672 temp_int = lex.GetInteger();
673 params.user_defined_bullets[index].setSize(temp_int);
674 params.temp_bullets[index].setSize(temp_int);
676 string temp_str = lex.GetString();
677 if (temp_str != "\\end_bullet") {
678 // this element isn't really necessary for
679 // parsing but is easier for humans
680 // to understand bullets. Put it back and
681 // set a debug message?
682 lex.printError("\\end_bullet expected, got" + temp_str);
683 //how can I put it back?
685 } else if (token == "\\bulletLaTeX") {
687 int index = lex.GetInteger();
689 string temp_str = lex.GetString(), sum_str;
690 while (temp_str != "\\end_bullet") {
691 // this loop structure is needed when user
692 // enters an empty string since the first
693 // thing returned will be the \\end_bullet
695 // if the LaTeX entry has spaces. Each element
696 // therefore needs to be read in turn
699 temp_str = lex.GetString();
701 params.user_defined_bullets[index].setText(sum_str);
702 params.temp_bullets[index].setText(sum_str);
703 } else if (token == "\\secnumdepth") {
705 params.secnumdepth = lex.GetInteger();
706 } else if (token == "\\tocdepth") {
708 params.tocdepth = lex.GetInteger();
709 } else if (token == "\\spacing") {
711 string tmp = strip(lex.GetString());
712 Spacing::Space tmp_space = Spacing::Default;
714 if (tmp == "single") {
715 tmp_space = Spacing::Single;
716 } else if (tmp == "onehalf") {
717 tmp_space = Spacing::Onehalf;
718 } else if (tmp == "double") {
719 tmp_space = Spacing::Double;
720 } else if (tmp == "other") {
722 tmp_space = Spacing::Other;
723 tmp_val = lex.GetFloat();
725 lex.printError("Unknown spacing token: '$$Token'");
727 // Small hack so that files written with klyx will be
730 par->spacing.set(tmp_space, tmp_val);
732 params.spacing.set(tmp_space, tmp_val);
734 } else if (token == "\\paragraph_spacing") {
736 string tmp = strip(lex.GetString());
737 if (tmp == "single") {
738 par->spacing.set(Spacing::Single);
739 } else if (tmp == "onehalf") {
740 par->spacing.set(Spacing::Onehalf);
741 } else if (tmp == "double") {
742 par->spacing.set(Spacing::Double);
743 } else if (tmp == "other") {
745 par->spacing.set(Spacing::Other,
748 lex.printError("Unknown spacing token: '$$Token'");
750 } else if (token == "\\float_placement") {
752 params.float_placement = lex.GetString();
753 } else if (token == "\\family") {
755 font.setLyXFamily(lex.GetString());
756 } else if (token == "\\series") {
758 font.setLyXSeries(lex.GetString());
759 } else if (token == "\\shape") {
761 font.setLyXShape(lex.GetString());
762 } else if (token == "\\size") {
764 font.setLyXSize(lex.GetString());
765 } else if (token == "\\latex") {
767 string tok = lex.GetString();
768 // This is dirty, but gone with LyX3. (Asger)
769 if (tok == "no_latex")
770 font.setLatex(LyXFont::OFF);
771 else if (tok == "latex")
772 font.setLatex(LyXFont::ON);
773 else if (tok == "default")
774 font.setLatex(LyXFont::INHERIT);
776 lex.printError("Unknown LaTeX font flag "
778 } else if (token == "\\lang") {
780 string tok = lex.GetString();
781 Languages::iterator lit = languages.find(tok);
782 if (lit != languages.end()) {
783 font.setLanguage(&(*lit).second);
785 font.setLanguage(params.language_info);
786 lex.printError("Unknown language `$$Token'");
788 } else if (token == "\\emph") {
790 font.setEmph(font.setLyXMisc(lex.GetString()));
791 } else if (token == "\\bar") {
793 string tok = lex.GetString();
794 // This is dirty, but gone with LyX3. (Asger)
796 font.setUnderbar(LyXFont::ON);
797 else if (tok == "no")
798 font.setUnderbar(LyXFont::OFF);
799 else if (tok == "default")
800 font.setUnderbar(LyXFont::INHERIT);
802 lex.printError("Unknown bar font flag "
804 } else if (token == "\\noun") {
806 font.setNoun(font.setLyXMisc(lex.GetString()));
807 } else if (token == "\\color") {
809 font.setLyXColor(lex.GetString());
810 } else if (token == "\\align") {
811 int tmpret = lex.FindToken(string_align);
812 if (tmpret == -1) ++tmpret;
813 if (tmpret != LYX_LAYOUT_DEFAULT) { // tmpret != 99 ???
815 for (; tmpret > 0; --tmpret)
816 tmpret2 = tmpret2 * 2;
817 par->align = LyXAlignment(tmpret2);
819 } else if (token == "\\added_space_top") {
821 par->added_space_top = VSpace(lex.GetString());
822 } else if (token == "\\added_space_bottom") {
824 par->added_space_bottom = VSpace(lex.GetString());
825 } else if (token == "\\pextra_type") {
827 par->pextra_type = lex.GetInteger();
828 } else if (token == "\\pextra_width") {
830 par->pextra_width = lex.GetString();
831 } else if (token == "\\pextra_widthp") {
833 par->pextra_widthp = lex.GetString();
834 } else if (token == "\\pextra_alignment") {
836 par->pextra_alignment = lex.GetInteger();
837 } else if (token == "\\pextra_hfill") {
839 par->pextra_hfill = lex.GetInteger();
840 } else if (token == "\\pextra_start_minipage") {
842 par->pextra_start_minipage = lex.GetInteger();
843 } else if (token == "\\labelwidthstring") {
845 par->labelwidthstring = lex.GetString();
846 // do not delete this token, it is still needed!
847 } else if (token == "\\end_inset") {
848 lyxerr << "Solitary \\end_inset. Missing \\begin_inset?.\n"
849 << "Last inset read was: " << last_inset_read
851 // Simply ignore this. The insets do not have
853 // But insets should read it, it is a part of
854 // the inset isn't it? Lgb.
855 } else if (token == "\\begin_inset") {
857 readInset(lex, par, pos, font);
859 // Should be moved out into its own function/method. (Lgb)
861 string tmptok = lex.GetString();
862 last_inset_read = tmptok;
863 // test the different insets
864 if (tmptok == "Quotes") {
865 Inset * inset = new InsetQuotes;
866 inset->Read(this, lex);
867 par->InsertInset(pos, inset, font);
869 } else if (tmptok == "External") {
870 Inset * inset = new InsetExternal;
871 inset->Read(this, lex);
872 par->InsertInset(pos, inset, font);
874 } else if (tmptok == "FormulaMacro") {
875 Inset * inset = new InsetFormulaMacro;
876 inset->Read(this, lex);
877 par->InsertInset(pos, inset, font);
879 } else if (tmptok == "Formula") {
880 Inset * inset = new InsetFormula;
881 inset->Read(this, lex);
882 par->InsertInset(pos, inset, font);
884 } else if (tmptok == "Figure") {
885 Inset * inset = new InsetFig(100, 100, this);
886 inset->Read(this, lex);
887 par->InsertInset(pos, inset, font);
889 } else if (tmptok == "Info") {
890 Inset * inset = new InsetInfo;
891 inset->Read(this, lex);
892 par->InsertInset(pos, inset, font);
894 } else if (tmptok == "Include") {
895 Inset * inset = new InsetInclude(string(), this);
896 inset->Read(this, lex);
897 par->InsertInset(pos, inset, font);
899 } else if (tmptok == "ERT") {
900 Inset * inset = new InsetERT;
901 inset->Read(this, lex);
902 par->InsertInset(pos, inset, font);
904 } else if (tmptok == "Tabular") {
905 Inset * inset = new InsetTabular(this);
906 inset->Read(this, lex);
907 par->InsertInset(pos, inset, font);
909 } else if (tmptok == "Text") {
910 Inset * inset = new InsetText;
911 inset->Read(this, lex);
912 par->InsertInset(pos, inset, font);
914 } else if (tmptok == "Foot") {
915 Inset * inset = new InsetFoot;
916 inset->Read(this, lex);
917 par->InsertInset(pos, inset, font);
919 } else if (tmptok == "Marginal") {
920 Inset * inset = new InsetMarginal;
921 inset->Read(this, lex);
922 par->InsertInset(pos, inset, font);
924 } else if (tmptok == "Minipage") {
925 Inset * inset = new InsetMinipage;
926 inset->Read(this, lex);
927 par->InsertInset(pos, inset, font);
929 } else if (tmptok == "Float") {
931 string tmptok = lex.GetString();
932 Inset * inset = new InsetFloat(tmptok);
933 inset->Read(this, lex);
934 par->InsertInset(pos, inset, font);
936 } else if (tmptok == "List") {
937 Inset * inset = new InsetList;
938 inset->Read(this, lex);
939 par->InsertInset(pos, inset, font);
941 } else if (tmptok == "Theorem") {
942 Inset * inset = new InsetList;
943 inset->Read(this, lex);
944 par->InsertInset(pos, inset, font);
946 } else if (tmptok == "Caption") {
947 Inset * inset = new InsetCaption;
948 inset->Read(this, lex);
949 par->InsertInset(pos, inset, font);
951 } else if (tmptok == "Graphics") {
952 Inset * inset = new InsetGraphics;
953 inset->Read(this, lex);
954 par->InsertInset(pos, inset, font);
956 } else if (tmptok == "LatexCommand") {
958 inscmd.Read(this, lex);
960 if (inscmd.getCmdName() == "cite") {
961 inset = new InsetCitation(inscmd.params());
962 } else if (inscmd.getCmdName() == "bibitem") {
963 lex.printError("Wrong place for bibitem");
964 inset = inscmd.Clone();
965 } else if (inscmd.getCmdName() == "BibTeX") {
966 inset = new InsetBibtex(inscmd.getContents(), inscmd.getOptions(), this);
967 } else if (inscmd.getCmdName() == "index") {
968 inset = new InsetIndex(inscmd.getContents());
969 } else if (inscmd.getCmdName() == "include") {
970 inset = new InsetInclude(inscmd.getContents(), this);
971 } else if (inscmd.getCmdName() == "label") {
972 inset = new InsetLabel(inscmd.getCommand());
973 } else if (inscmd.getCmdName() == "url"
974 || inscmd.getCmdName() == "htmlurl") {
975 inset = new InsetUrl(inscmd.params());
976 } else if (inscmd.getCmdName() == "ref"
977 || inscmd.getCmdName() == "pageref"
978 || inscmd.getCmdName() == "vref"
979 || inscmd.getCmdName() == "vpageref"
980 || inscmd.getCmdName() == "prettyref") {
981 if (!inscmd.getOptions().empty() || !inscmd.getContents().empty()) {
982 inset = new InsetRef(inscmd, this);
984 } else if (inscmd.getCmdName() == "tableofcontents") {
985 inset = new InsetTOC(this);
986 } else if (inscmd.getCmdName() == "listoffigures") {
987 inset = new InsetLOF(this);
988 } else if (inscmd.getCmdName() == "listofalgorithms") {
989 inset = new InsetLOA(this);
990 } else if (inscmd.getCmdName() == "listoftables") {
991 inset = new InsetLOT(this);
992 } else if (inscmd.getCmdName() == "printindex") {
993 inset = new InsetPrintIndex(this);
994 } else if (inscmd.getCmdName() == "lyxparent") {
995 inset = new InsetParent(inscmd.getContents(), this);
999 par->InsertInset(pos, inset, font);
1004 } else if (token == "\\SpecialChar") {
1005 LyXLayout const & layout =
1006 textclasslist.Style(params.textclass,
1009 // Insets don't make sense in a free-spacing context! ---Kayvan
1010 if (layout.free_spacing) {
1013 string next_token = lex.GetString();
1014 if (next_token == "\\-") {
1015 par->InsertChar(pos, '-', font);
1016 } else if (next_token == "\\protected_separator"
1017 || next_token == "~") {
1018 par->InsertChar(pos, ' ', font);
1020 lex.printError("Token `$$Token' "
1022 "paragraph layout!");
1027 Inset * inset = new InsetSpecialChar;
1028 inset->Read(this, lex);
1029 par->InsertInset(pos, inset, font);
1032 } else if (token == "\\newline") {
1033 par->InsertChar(pos, LyXParagraph::META_NEWLINE, font);
1035 } else if (token == "\\LyXTable") {
1037 Inset * inset = new InsetTabular(this);
1038 inset->Read(this, lex);
1039 par->InsertInset(pos, inset, font);
1042 par->table = new LyXTable(lex);
1044 } else if (token == "\\hfill") {
1045 par->InsertChar(pos, LyXParagraph::META_HFILL, font);
1047 } else if (token == "\\protected_separator") { // obsolete
1048 // This is a backward compability thingie. (Lgb)
1049 // Remove it later some time...introduced with fileformat
1051 LyXLayout const & layout =
1052 textclasslist.Style(params.textclass,
1055 if (layout.free_spacing) {
1056 par->InsertChar(pos, ' ', font);
1058 Inset * inset = new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
1059 par->InsertInset(pos, inset, font);
1062 } else if (token == "\\bibitem") { // ale970302
1064 par->bibkey = new InsetBibKey;
1065 par->bibkey->Read(this, lex);
1066 }else if (token == "\\backslash") {
1067 par->InsertChar(pos, '\\', font);
1069 }else if (token == "\\the_end") {
1070 the_end_read = true;
1072 // This should be insurance for the future: (Asger)
1073 lex.printError("Unknown token `$$Token'. "
1074 "Inserting as text.");
1075 for(string::const_iterator cit = token.begin();
1076 cit != token.end(); ++cit) {
1077 par->InsertChar(pos, (*cit), font);
1081 return the_end_read;
1085 void Buffer::readInset(LyXLex & lex, LyXParagraph *& par,
1086 int & pos, LyXFont & font)
1088 // consistency check
1089 if (lex.GetString() != "\\begin_inset") {
1090 lyxerr << "Buffer::readInset: Consistency check failed."
1095 string tmptok = lex.GetString();
1096 last_inset_read = tmptok;
1097 // test the different insets
1098 if (tmptok == "Quotes") {
1099 Inset * inset = new InsetQuotes;
1100 inset->Read(this, lex);
1101 par->InsertInset(pos, inset, font);
1103 } else if (tmptok == "External") {
1104 Inset * inset = new InsetExternal;
1105 inset->Read(this, lex);
1106 par->InsertInset(pos, inset, font);
1108 } else if (tmptok == "FormulaMacro") {
1109 Inset * inset = new InsetFormulaMacro;
1110 inset->Read(this, lex);
1111 par->InsertInset(pos, inset, font);
1113 } else if (tmptok == "Formula") {
1114 Inset * inset = new InsetFormula;
1115 inset->Read(this, lex);
1116 par->InsertInset(pos, inset, font);
1118 } else if (tmptok == "Figure") {
1119 Inset * inset = new InsetFig(100, 100, this);
1120 inset->Read(this, lex);
1121 par->InsertInset(pos, inset, font);
1123 } else if (tmptok == "Info") {
1124 Inset * inset = new InsetInfo;
1125 inset->Read(this, lex);
1126 par->InsertInset(pos, inset, font);
1128 } else if (tmptok == "Include") {
1129 Inset * inset = new InsetInclude(string(), this);
1130 inset->Read(this, lex);
1131 par->InsertInset(pos, inset, font);
1133 } else if (tmptok == "ERT") {
1134 Inset * inset = new InsetERT;
1135 inset->Read(this, lex);
1136 par->InsertInset(pos, inset, font);
1138 } else if (tmptok == "Tabular") {
1139 Inset * inset = new InsetTabular(this);
1140 inset->Read(this, lex);
1141 par->InsertInset(pos, inset, font);
1143 } else if (tmptok == "Text") {
1144 Inset * inset = new InsetText;
1145 inset->Read(this, lex);
1146 par->InsertInset(pos, inset, font);
1148 } else if (tmptok == "Foot") {
1149 Inset * inset = new InsetFoot;
1150 inset->Read(this, lex);
1151 par->InsertInset(pos, inset, font);
1153 } else if (tmptok == "Marginal") {
1154 Inset * inset = new InsetMarginal;
1155 inset->Read(this, lex);
1156 par->InsertInset(pos, inset, font);
1158 } else if (tmptok == "Minipage") {
1159 Inset * inset = new InsetMinipage;
1160 inset->Read(this, lex);
1161 par->InsertInset(pos, inset, font);
1163 } else if (tmptok == "Float") {
1165 string tmptok = lex.GetString();
1166 Inset * inset = new InsetFloat(tmptok);
1167 inset->Read(this, lex);
1168 par->InsertInset(pos, inset, font);
1170 } else if (tmptok == "List") {
1171 Inset * inset = new InsetList;
1172 inset->Read(this, lex);
1173 par->InsertInset(pos, inset, font);
1175 } else if (tmptok == "Theorem") {
1176 Inset * inset = new InsetList;
1177 inset->Read(this, lex);
1178 par->InsertInset(pos, inset, font);
1180 } else if (tmptok == "Caption") {
1181 Inset * inset = new InsetCaption;
1182 inset->Read(this, lex);
1183 par->InsertInset(pos, inset, font);
1185 } else if (tmptok == "GRAPHICS") {
1186 Inset * inset = new InsetGraphics;
1187 //inset->Read(this, lex);
1188 par->InsertInset(pos, inset, font);
1189 } else if (tmptok == "LatexCommand") {
1190 InsetCommand inscmd;
1191 inscmd.Read(this, lex);
1193 if (inscmd.getCmdName() == "cite") {
1194 inset = new InsetCitation(inscmd.params());
1195 } else if (inscmd.getCmdName() == "bibitem") {
1196 lex.printError("Wrong place for bibitem");
1197 inset = inscmd.Clone();
1198 } else if (inscmd.getCmdName() == "BibTeX") {
1199 inset = new InsetBibtex(inscmd.getContents(),
1200 inscmd.getOptions(), this);
1201 } else if (inscmd.getCmdName() == "index") {
1202 inset = new InsetIndex(inscmd.getContents());
1203 } else if (inscmd.getCmdName() == "include") {
1204 inset = new InsetInclude(inscmd.getContents(), this);
1205 } else if (inscmd.getCmdName() == "label") {
1206 inset = new InsetLabel(inscmd.getCommand());
1207 } else if (inscmd.getCmdName() == "url"
1208 || inscmd.getCmdName() == "htmlurl") {
1209 inset = new InsetUrl(inscmd.params());
1210 } else if (inscmd.getCmdName() == "ref"
1211 || inscmd.getCmdName() == "pageref"
1212 || inscmd.getCmdName() == "vref"
1213 || inscmd.getCmdName() == "vpageref"
1214 || inscmd.getCmdName() == "prettyref") {
1215 if (!inscmd.getOptions().empty()
1216 || !inscmd.getContents().empty()) {
1217 inset = new InsetRef(inscmd, this);
1219 } else if (inscmd.getCmdName() == "tableofcontents") {
1220 inset = new InsetTOC(this);
1221 } else if (inscmd.getCmdName() == "listoffigures") {
1222 inset = new InsetLOF(this);
1223 } else if (inscmd.getCmdName() == "listofalgorithms") {
1224 inset = new InsetLOA(this);
1225 } else if (inscmd.getCmdName() == "listoftables") {
1226 inset = new InsetLOT(this);
1227 } else if (inscmd.getCmdName() == "printindex") {
1228 inset = new InsetPrintIndex(this);
1229 } else if (inscmd.getCmdName() == "lyxparent") {
1230 inset = new InsetParent(inscmd.getContents(), this);
1234 par->InsertInset(pos, inset, font);
1241 bool Buffer::readFile(LyXLex & lex, LyXParagraph * par)
1247 token = lex.GetString();
1248 if (token == "\\lyxformat") { // the first token _must_ be...
1250 format = lex.GetFloat();
1252 if (LYX_FORMAT - format > 0.05) {
1253 printf(_("Warning: need lyxformat %.2f but found %.2f\n"),
1254 LYX_FORMAT, format);
1256 if (format - LYX_FORMAT > 0.05) {
1257 printf(_("ERROR: need lyxformat %.2f but found %.2f\n"),
1258 LYX_FORMAT, format);
1260 bool the_end = readLyXformat2(lex, par);
1261 // Formats >= 2.13 support "\the_end" marker
1268 WriteAlert(_("Warning!"),
1269 _("Reading of document is not complete"),
1270 _("Maybe the document is truncated"));
1271 // We simulate a safe reading anyways to allow
1272 // users to take the chance... (Asger)
1276 WriteAlert(_("ERROR!"),
1277 _("Old LyX file format found. "
1278 "Use LyX 0.10.x to read this!"));
1282 } else { // "\\lyxformat" not found
1283 WriteAlert(_("ERROR!"), _("Not a LyX file!"));
1286 WriteAlert(_("ERROR!"), _("Unable to read file!"));
1292 // Should probably be moved to somewhere else: BufferView? LyXView?
1293 bool Buffer::save() const
1295 // We don't need autosaves in the immediate future. (Asger)
1296 resetAutosaveTimers();
1300 if (lyxrc.make_backup) {
1301 s = fileName() + '~';
1302 if (!lyxrc.backupdir_path.empty())
1303 s = AddName(lyxrc.backupdir_path,
1304 subst(CleanupPath(s),'/','!'));
1306 // Rename is the wrong way of making a backup,
1307 // this is the correct way.
1308 /* truss cp fil fil2:
1309 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
1310 stat("LyXVC.lyx", 0xEFFFF688) = 0
1311 open("LyXVC.lyx", O_RDONLY) = 3
1312 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
1313 fstat(4, 0xEFFFF508) = 0
1314 fstat(3, 0xEFFFF508) = 0
1315 read(3, " # T h i s f i l e w".., 8192) = 5579
1316 write(4, " # T h i s f i l e w".., 5579) = 5579
1317 read(3, 0xEFFFD4A0, 8192) = 0
1320 chmod("LyXVC3.lyx", 0100644) = 0
1321 lseek(0, 0, SEEK_CUR) = 46440
1325 // Should proabaly have some more error checking here.
1326 // Should be cleaned up in 0.13, at least a bit.
1327 // Doing it this way, also makes the inodes stay the same.
1328 // This is still not a very good solution, in particular we
1329 // might loose the owner of the backup.
1330 FileInfo finfo(fileName());
1331 if (finfo.exist()) {
1332 mode_t fmode = finfo.getMode();
1333 struct utimbuf times = {
1334 finfo.getAccessTime(),
1335 finfo.getModificationTime() };
1337 ifstream ifs(fileName().c_str());
1338 ofstream ofs(s.c_str(), ios::out|ios::trunc);
1343 ::chmod(s.c_str(), fmode);
1345 if (::utime(s.c_str(), ×)) {
1346 lyxerr << "utime error." << endl;
1349 lyxerr << "LyX was not able to make "
1350 "backupcopy. Beware." << endl;
1355 if (writeFile(fileName(), false)) {
1358 // now delete the autosavefile
1359 string a = OnlyPath(fileName());
1361 a += OnlyFilename(fileName());
1363 FileInfo fileinfo(a);
1364 if (fileinfo.exist()) {
1365 if (::remove(a.c_str()) != 0) {
1366 WriteFSAlert(_("Could not delete "
1367 "auto-save file!"), a);
1371 // Saving failed, so backup is not backup
1372 if (lyxrc.make_backup) {
1373 ::rename(s.c_str(), fileName().c_str());
1381 // Returns false if unsuccesful
1382 bool Buffer::writeFile(string const & fname, bool flag) const
1384 // if flag is false writeFile will not create any GUI
1385 // warnings, only cerr.
1386 // Needed for autosave in background or panic save (Matthias 120496)
1388 if (read_only && (fname == filename)) {
1389 // Here we should come with a question if we should
1390 // perform the write anyway.
1392 lyxerr << _("Error! Document is read-only: ")
1395 WriteAlert(_("Error! Document is read-only: "),
1400 FileInfo finfo(fname);
1401 if (finfo.exist() && !finfo.writable()) {
1402 // Here we should come with a question if we should
1403 // try to do the save anyway. (i.e. do a chmod first)
1405 lyxerr << _("Error! Cannot write file: ")
1408 WriteFSAlert(_("Error! Cannot write file: "),
1413 ofstream ofs(fname.c_str());
1416 lyxerr << _("Error! Cannot open file: ")
1419 WriteFSAlert(_("Error! Cannot open file: "),
1423 // The top of the file should not be written by params.
1425 // write out a comment in the top of the file
1426 ofs << '#' << LYX_DOCVERSION
1427 << " created this file. For more info see http://www.lyx.org/\n";
1428 ofs.setf(ios::showpoint|ios::fixed);
1430 ofs << "\\lyxformat " << setw(4) << LYX_FORMAT << "\n";
1432 // now write out the buffer paramters.
1433 params.writeFile(ofs);
1435 char footnoteflag = 0;
1438 // this will write out all the paragraphs
1439 // using recursive descent.
1440 paragraph->writeFile(this, ofs, params, footnoteflag, depth);
1442 // Write marker that shows file is complete
1443 ofs << "\n\\the_end" << endl;
1445 // how to check if close went ok?
1450 void Buffer::writeFileAscii(string const & fname, int linelen)
1452 LyXFont font1, font2;
1454 char c, footnoteflag = 0, depth = 0;
1456 LyXParagraph::size_type i;
1459 int ltype_depth = 0;
1468 int currlinelen = 0;
1470 bool ref_printed = false;
1472 ofstream ofs(fname.c_str());
1474 WriteFSAlert(_("Error: Cannot write file:"), fname);
1478 string fname1 = TmpFileName();
1479 LyXParagraph * par = paragraph;
1485 par->footnoteflag != LyXParagraph::NO_FOOTNOTE ||
1489 || par->previous->footnoteflag == LyXParagraph::NO_FOOTNOTE
1494 /* begins a footnote environment ? */
1495 if (footnoteflag != par->footnoteflag) {
1496 footnoteflag = par->footnoteflag;
1498 j = strlen(string_footnotekinds[par->footnotekind])+4;
1499 if (currlinelen + j > linelen)
1502 << string_footnotekinds[par->footnotekind] << "] ";
1508 /* begins or ends a deeper area ?*/
1509 if (depth != par->depth) {
1510 if (par->depth > depth) {
1511 while (par->depth > depth) {
1516 while (par->depth < depth) {
1522 /* First write the layout */
1523 tmp = textclasslist.NameOfLayout(params.textclass, par->layout);
1524 if (tmp == "Itemize") {
1526 ltype_depth = depth+1;
1527 } else if (tmp == "Enumerate") {
1529 ltype_depth = depth+1;
1530 } else if (strstr(tmp.c_str(), "ection")) {
1532 ltype_depth = depth+1;
1533 } else if (strstr(tmp.c_str(), "aragraph")) {
1535 ltype_depth = depth+1;
1536 } else if (tmp == "Description") {
1538 ltype_depth = depth+1;
1539 } else if (tmp == "Abstract") {
1542 } else if (tmp == "Bibliography") {
1550 /* maybe some vertical spaces */
1552 /* the labelwidthstring used in lists */
1556 /* some pagebreaks? */
1560 /* what about the alignment */
1563 /* dummy layout, that means a footnote ended */
1564 footnoteflag = LyXParagraph::NO_FOOTNOTE;
1568 lyxerr << "Should this ever happen?" << endl;
1572 //LyXLayout const & layout =
1573 // textclasslist.Style(params.textclass,
1574 // par->GetLayout()); // unused
1575 //bool free_spc = layout.free_spacing; //unused
1578 /* It might be a table */
1582 cells = par->table->columns;
1583 clen = new int [cells];
1584 memset(clen, 0, sizeof(int) * cells);
1586 for (i = 0, j = 0, h = 1; i < par->size(); ++i, ++h) {
1587 c = par->GetChar(i);
1588 if (c == LyXParagraph::META_INSET) {
1589 if ((inset = par->GetInset(i))) {
1591 std::ostringstream ost;
1592 inset->Ascii(this, ost);
1593 h += ost.str().length();
1596 inset->Ascii(this, ost);
1598 char * tmp = ost.str();
1604 } else if (c == LyXParagraph::META_NEWLINE) {
1608 j = (++j) % par->table->NumberOfCellsInRow(actcell);
1616 font1 = LyXFont(LyXFont::ALL_INHERIT, params.language_info);
1618 for (i = 0, actpos = 1; i < par->size(); ++i, ++actpos) {
1619 if (!i && !footnoteflag && !noparbreak){
1621 for(j = 0; j < depth; ++j)
1623 currlinelen = depth * 2;
1625 case 0: /* Standard */
1626 case 4: /* (Sub)Paragraph */
1627 case 5: /* Description */
1629 case 6: /* Abstract */
1630 ofs << "Abstract\n\n";
1632 case 7: /* Bibliography */
1634 ofs << "References\n\n";
1639 ofs << par->labelstring << " ";
1642 if (ltype_depth > depth) {
1643 for(j = ltype_depth - 1; j > depth; --j)
1645 currlinelen += (ltype_depth-depth)*2;
1649 for(j = 0; j < cells; ++j) {
1651 for(h = 0; h < (clen[j] + 1);
1656 for(j = 0; j < depth; ++j)
1658 currlinelen = depth * 2;
1659 if (ltype_depth > depth) {
1660 for(j = ltype_depth;
1663 currlinelen += (ltype_depth-depth)*2;
1669 font2 = par->GetFontSettings(params, i);
1670 if (font1.latex() != font2.latex()) {
1671 if (font2.latex() == LyXFont::OFF)
1678 c = par->GetChar(i);
1682 case LyXParagraph::META_INSET:
1683 if ((inset = par->GetInset(i))) {
1685 inset->Ascii(this, ofs);
1686 currlinelen += (ofs.tellp() - fpos);
1687 actpos += (ofs.tellp() - fpos) - 1;
1690 case LyXParagraph::META_NEWLINE:
1693 if (par->table->NumberOfCellsInRow(actcell) <= cell) {
1694 for(j = actpos; j < clen[cell - 1]; ++j)
1697 for(j = 0; j < depth; ++j)
1699 currlinelen = depth*2;
1700 if (ltype_depth > depth) {
1701 for(j = ltype_depth; j > depth; --j)
1703 currlinelen += (ltype_depth-depth) * 2;
1705 for(j = 0; j < cells; ++j) {
1707 for(h = 0; h < (clen[j] + 1); ++h)
1711 for(j = 0; j < depth; ++j)
1713 currlinelen = depth * 2;
1714 if (ltype_depth > depth) {
1715 for(j = ltype_depth;
1718 currlinelen += (ltype_depth-depth)*2;
1724 j < clen[cell - 1]; ++j)
1730 currlinelen = actpos = 0;
1734 for(j = 0; j < depth; ++j)
1736 currlinelen = depth * 2;
1737 if (ltype_depth > depth) {
1738 for(j = ltype_depth;
1741 currlinelen += (ltype_depth - depth) * 2;
1747 case LyXParagraph::META_HFILL:
1754 if (currlinelen > linelen - 10
1755 && c == ' ' && i + 2 < par->size()) {
1757 for(j = 0; j < depth; ++j)
1759 currlinelen = depth * 2;
1760 if (ltype_depth > depth) {
1761 for(j = ltype_depth;
1764 currlinelen += (ltype_depth-depth)*2;
1766 } else if (c != '\0')
1769 lyxerr.debug() << "writeAsciiFile: NULL char in structure." << endl;
1776 for(j = actpos; j < clen[cell - 1]; ++j)
1779 for(j = 0; j < depth; ++j)
1781 currlinelen = depth * 2;
1782 if (ltype_depth > depth) {
1783 for(j = ltype_depth; j > depth; --j)
1785 currlinelen += (ltype_depth - depth) * 2;
1787 for(j = 0; j < cells; ++j) {
1789 for(h = 0; h < (clen[j] + 1); ++h)
1803 void Buffer::makeLaTeXFile(string const & fname,
1804 string const & original_path,
1805 bool nice, bool only_body)
1807 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
1809 niceFile = nice; // this will be used by Insetincludes.
1811 tex_code_break_column = lyxrc.ascii_linelen;
1813 LyXTextClass const & tclass =
1814 textclasslist.TextClass(params.textclass);
1816 ofstream ofs(fname.c_str());
1818 WriteFSAlert(_("Error: Cannot open file: "), fname);
1822 // validate the buffer.
1823 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
1824 LaTeXFeatures features(params, tclass.numLayouts());
1826 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
1829 // The starting paragraph of the coming rows is the
1830 // first paragraph of the document. (Asger)
1831 texrow.start(paragraph, 0);
1833 if (!only_body && nice) {
1834 ofs << "%% " LYX_DOCVERSION " created this file. "
1835 "For more info, see http://www.lyx.org/.\n"
1836 "%% Do not edit unless you really know what "
1841 lyxerr.debug() << "lyx header finished" << endl;
1842 // There are a few differences between nice LaTeX and usual files:
1843 // usual is \batchmode and has a
1844 // special input@path to allow the including of figures
1845 // with either \input or \includegraphics (what figinsets do).
1846 // batchmode is not set if there is a tex_code_break_column.
1847 // In this case somebody is interested in the generated LaTeX,
1848 // so this is OK. input@path is set when the actual parameter
1849 // original_path is set. This is done for usual tex-file, but not
1850 // for nice-latex-file. (Matthias 250696)
1853 // code for usual, NOT nice-latex-file
1854 ofs << "\\batchmode\n"; // changed
1855 // from \nonstopmode
1858 if (!original_path.empty()) {
1859 ofs << "\\makeatletter\n"
1860 << "\\def\\input@path{{"
1861 << original_path << "/}}\n"
1862 << "\\makeatother\n";
1868 ofs << "\\documentclass";
1870 string options; // the document class options.
1872 if (tokenPos(tclass.opt_fontsize(),
1873 '|', params.fontsize) >= 0) {
1874 // only write if existing in list (and not default)
1875 options += params.fontsize;
1880 if (!params.use_geometry &&
1881 (params.paperpackage == BufferParams::PACKAGE_NONE)) {
1882 switch (params.papersize) {
1883 case BufferParams::PAPER_A4PAPER:
1884 options += "a4paper,";
1886 case BufferParams::PAPER_USLETTER:
1887 options += "letterpaper,";
1889 case BufferParams::PAPER_A5PAPER:
1890 options += "a5paper,";
1892 case BufferParams::PAPER_B5PAPER:
1893 options += "b5paper,";
1895 case BufferParams::PAPER_EXECUTIVEPAPER:
1896 options += "executivepaper,";
1898 case BufferParams::PAPER_LEGALPAPER:
1899 options += "legalpaper,";
1905 if (params.sides != tclass.sides()) {
1906 switch (params.sides) {
1907 case LyXTextClass::OneSide:
1908 options += "oneside,";
1910 case LyXTextClass::TwoSides:
1911 options += "twoside,";
1918 if (params.columns != tclass.columns()) {
1919 if (params.columns == 2)
1920 options += "twocolumn,";
1922 options += "onecolumn,";
1925 if (!params.use_geometry
1926 && params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1927 options += "landscape,";
1929 // language should be a parameter to \documentclass
1930 bool use_babel = false;
1931 if (params.language_info->lang() == "hebrew") // This seems necessary
1932 features.UsedLanguages.insert(default_language);
1933 if (params.language != "default" ||
1934 !features.UsedLanguages.empty() ) {
1936 for (LaTeXFeatures::LanguageList::const_iterator cit =
1937 features.UsedLanguages.begin();
1938 cit != features.UsedLanguages.end(); ++cit)
1939 options += (*cit)->lang() + ",";
1940 options += params.language_info->lang() + ',';
1943 // the user-defined options
1944 if (!params.options.empty()) {
1945 options += params.options + ',';
1948 if (!options.empty()){
1949 options = strip(options, ',');
1950 ofs << '[' << options << ']';
1954 << textclasslist.LatexnameOfClass(params.textclass)
1957 // end of \documentclass defs
1959 // font selection must be done before loading fontenc.sty
1960 if (params.fonts != "default") {
1961 ofs << "\\usepackage{" << params.fonts << "}\n";
1964 // this one is not per buffer
1965 if (lyxrc.fontenc != "default") {
1966 ofs << "\\usepackage[" << lyxrc.fontenc
1971 if (params.inputenc == "auto") {
1972 string doc_encoding =
1973 params.language_info->encoding()->LatexName();
1975 // Create a list with all the input encodings used
1977 set<string> encodings;
1978 for (LaTeXFeatures::LanguageList::const_iterator it =
1979 features.UsedLanguages.begin();
1980 it != features.UsedLanguages.end(); ++it)
1981 if ((*it)->encoding()->LatexName() != doc_encoding)
1982 encodings.insert((*it)->encoding()->LatexName());
1984 ofs << "\\usepackage[";
1985 for (set<string>::const_iterator it = encodings.begin();
1986 it != encodings.end(); ++it)
1988 ofs << doc_encoding << "]{inputenc}\n";
1990 } else if (params.inputenc != "default") {
1991 ofs << "\\usepackage[" << params.inputenc
1996 // At the very beginning the text parameters.
1997 if (params.paperpackage != BufferParams::PACKAGE_NONE) {
1998 switch (params.paperpackage) {
1999 case BufferParams::PACKAGE_A4:
2000 ofs << "\\usepackage{a4}\n";
2003 case BufferParams::PACKAGE_A4WIDE:
2004 ofs << "\\usepackage{a4wide}\n";
2007 case BufferParams::PACKAGE_WIDEMARGINSA4:
2008 ofs << "\\usepackage[widemargins]{a4}\n";
2013 if (params.use_geometry) {
2014 ofs << "\\usepackage{geometry}\n";
2016 ofs << "\\geometry{verbose";
2017 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
2018 ofs << ",landscape";
2019 switch (params.papersize2) {
2020 case BufferParams::VM_PAPER_CUSTOM:
2021 if (!params.paperwidth.empty())
2022 ofs << ",paperwidth="
2023 << params.paperwidth;
2024 if (!params.paperheight.empty())
2025 ofs << ",paperheight="
2026 << params.paperheight;
2028 case BufferParams::VM_PAPER_USLETTER:
2029 ofs << ",letterpaper";
2031 case BufferParams::VM_PAPER_USLEGAL:
2032 ofs << ",legalpaper";
2034 case BufferParams::VM_PAPER_USEXECUTIVE:
2035 ofs << ",executivepaper";
2037 case BufferParams::VM_PAPER_A3:
2040 case BufferParams::VM_PAPER_A4:
2043 case BufferParams::VM_PAPER_A5:
2046 case BufferParams::VM_PAPER_B3:
2049 case BufferParams::VM_PAPER_B4:
2052 case BufferParams::VM_PAPER_B5:
2056 // default papersize ie BufferParams::VM_PAPER_DEFAULT
2057 switch (lyxrc.default_papersize) {
2058 case BufferParams::PAPER_DEFAULT: // keep compiler happy
2059 case BufferParams::PAPER_USLETTER:
2060 ofs << ",letterpaper";
2062 case BufferParams::PAPER_LEGALPAPER:
2063 ofs << ",legalpaper";
2065 case BufferParams::PAPER_EXECUTIVEPAPER:
2066 ofs << ",executivepaper";
2068 case BufferParams::PAPER_A3PAPER:
2071 case BufferParams::PAPER_A4PAPER:
2074 case BufferParams::PAPER_A5PAPER:
2077 case BufferParams::PAPER_B5PAPER:
2082 if (!params.topmargin.empty())
2083 ofs << ",tmargin=" << params.topmargin;
2084 if (!params.bottommargin.empty())
2085 ofs << ",bmargin=" << params.bottommargin;
2086 if (!params.leftmargin.empty())
2087 ofs << ",lmargin=" << params.leftmargin;
2088 if (!params.rightmargin.empty())
2089 ofs << ",rmargin=" << params.rightmargin;
2090 if (!params.headheight.empty())
2091 ofs << ",headheight=" << params.headheight;
2092 if (!params.headsep.empty())
2093 ofs << ",headsep=" << params.headsep;
2094 if (!params.footskip.empty())
2095 ofs << ",footskip=" << params.footskip;
2099 if (params.use_amsmath
2100 && !tclass.provides(LyXTextClass::amsmath)) {
2101 ofs << "\\usepackage{amsmath}\n";
2105 if (tokenPos(tclass.opt_pagestyle(),
2106 '|', params.pagestyle) >= 0) {
2107 if (params.pagestyle == "fancy") {
2108 ofs << "\\usepackage{fancyhdr}\n";
2111 ofs << "\\pagestyle{" << params.pagestyle << "}\n";
2115 // We try to load babel late, in case it interferes
2116 // with other packages.
2118 ofs << lyxrc.language_package << endl;
2122 if (params.secnumdepth != tclass.secnumdepth()) {
2123 ofs << "\\setcounter{secnumdepth}{"
2124 << params.secnumdepth
2128 if (params.tocdepth != tclass.tocdepth()) {
2129 ofs << "\\setcounter{tocdepth}{"
2135 if (params.paragraph_separation) {
2136 switch (params.defskip.kind()) {
2137 case VSpace::SMALLSKIP:
2138 ofs << "\\setlength\\parskip{\\smallskipamount}\n";
2140 case VSpace::MEDSKIP:
2141 ofs << "\\setlength\\parskip{\\medskipamount}\n";
2143 case VSpace::BIGSKIP:
2144 ofs << "\\setlength\\parskip{\\bigskipamount}\n";
2146 case VSpace::LENGTH:
2147 ofs << "\\setlength\\parskip{"
2148 << params.defskip.length().asLatexString()
2151 default: // should never happen // Then delete it.
2152 ofs << "\\setlength\\parskip{\\medskipamount}\n";
2157 ofs << "\\setlength\\parindent{0pt}\n";
2161 // Now insert the LyX specific LaTeX commands...
2163 // The optional packages;
2164 string preamble(features.getPackages());
2166 // this might be useful...
2167 preamble += "\n\\makeatletter\n";
2169 // Some macros LyX will need
2170 string tmppreamble(features.getMacros());
2172 if (!tmppreamble.empty()) {
2173 preamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2174 "LyX specific LaTeX commands.\n"
2175 + tmppreamble + '\n';
2178 // the text class specific preamble
2179 tmppreamble = features.getTClassPreamble();
2180 if (!tmppreamble.empty()) {
2181 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2182 "Textclass specific LaTeX commands.\n"
2183 + tmppreamble + '\n';
2186 /* the user-defined preamble */
2187 if (!params.preamble.empty()) {
2188 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2189 "User specified LaTeX commands.\n"
2190 + params.preamble + '\n';
2193 preamble += "\\makeatother\n";
2195 // Itemize bullet settings need to be last in case the user
2196 // defines their own bullets that use a package included
2197 // in the user-defined preamble -- ARRae
2198 // Actually it has to be done much later than that
2199 // since some packages like frenchb make modifications
2200 // at \begin{document} time -- JMarc
2202 for (int i = 0; i < 4; ++i) {
2203 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
2204 if (bullets_def.empty())
2205 bullets_def="\\AtBeginDocument{\n";
2206 bullets_def += " \\renewcommand{\\labelitemi";
2208 // `i' is one less than the item to modify
2215 bullets_def += "ii";
2221 bullets_def += "}{" +
2222 params.user_defined_bullets[i].getText()
2227 if (!bullets_def.empty())
2228 preamble += bullets_def + "}\n\n";
2230 for (int j = countChar(preamble, '\n'); j-- ;) {
2237 ofs << "\\begin{document}\n";
2240 lyxerr.debug() << "preamble finished, now the body." << endl;
2241 if (!lyxrc.language_auto_begin && params.language != "default") {
2242 ofs << subst(lyxrc.language_command_begin, "$$lang",
2248 latexParagraphs(ofs, paragraph, 0, texrow);
2250 // add this just in case after all the paragraphs
2254 if (!lyxrc.language_auto_end && params.language != "default") {
2255 ofs << subst(lyxrc.language_command_end, "$$lang",
2262 ofs << "\\end{document}\n";
2265 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
2267 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
2271 // Just to be sure. (Asger)
2274 // tex_code_break_column's value is used to decide
2275 // if we are in batchmode or not (within mathed_write()
2276 // in math_write.C) so we must set it to a non-zero
2277 // value when we leave otherwise we save incorrect .lyx files.
2278 tex_code_break_column = lyxrc.ascii_linelen;
2282 lyxerr << "File was not closed properly." << endl;
2285 lyxerr.debug() << "Finished making latex file." << endl;
2290 // LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
2292 void Buffer::latexParagraphs(ostream & ofs, LyXParagraph * par,
2293 LyXParagraph * endpar, TexRow & texrow) const
2295 bool was_title = false;
2296 bool already_title = false;
2298 std::ostringstream ftnote;
2300 char * tmpholder = 0;
2306 while (par != endpar) {
2307 #ifndef HAVE_SSTREAM
2310 ftnote << tmpholder;
2311 delete [] tmpholder;
2317 lyxerr[Debug::LATEX] << "Error in latexParagraphs."
2320 LyXLayout const & layout =
2321 textclasslist.Style(params.textclass,
2324 if (layout.intitle) {
2325 if (already_title) {
2326 lyxerr <<"Error in latexParagraphs: You"
2327 " should not mix title layouts"
2328 " with normal ones." << endl;
2331 } else if (was_title && !already_title) {
2332 ofs << "\\maketitle\n";
2334 already_title = true;
2337 // We are at depth 0 so we can just use
2338 // ordinary \footnote{} generation
2339 // flag this with ftcount
2341 if (layout.isEnvironment()
2342 || par->pextra_type != LyXParagraph::PEXTRA_NONE) {
2343 par = par->TeXEnvironment(this, params, ofs, texrow
2345 ,ftnote, ft_texrow, ftcount
2349 par = par->TeXOnePar(this, params, ofs, texrow, false
2352 ftnote, ft_texrow, ftcount
2357 // Write out what we've generated...
2360 ofs << "\\addtocounter{footnote}{-"
2364 ofs << ftnote.str();
2365 texrow += ft_texrow;
2367 // The extra .c_str() is needed when we use
2368 // lyxstring instead of the STL string class.
2369 ftnote.str(string().c_str());
2371 delete [] ftnote.str();
2376 #ifndef HAVE_SSTREAM
2378 // I hate strstreams
2379 tmpholder = ftnote.str();
2383 #ifndef HAVE_SSTREAM
2384 delete [] tmpholder;
2386 // It might be that we only have a title in this document
2387 if (was_title && !already_title) {
2388 ofs << "\\maketitle\n";
2394 bool Buffer::isLatex() const
2396 return textclasslist.TextClass(params.textclass).outputType() == LATEX;
2400 bool Buffer::isLinuxDoc() const
2402 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC;
2406 bool Buffer::isLiterate() const
2408 return textclasslist.TextClass(params.textclass).outputType() == LITERATE;
2412 bool Buffer::isDocBook() const
2414 return textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2418 bool Buffer::isSGML() const
2420 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC ||
2421 textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2425 void Buffer::sgmlOpenTag(ostream & os, int depth,
2426 string const & latexname) const
2428 os << string(depth, ' ') << "<" << latexname << ">\n";
2432 void Buffer::sgmlCloseTag(ostream & os, int depth,
2433 string const & latexname) const
2435 os << string(depth, ' ') << "</" << latexname << ">\n";
2439 void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
2441 LyXParagraph * par = paragraph;
2443 niceFile = nice; // this will be used by Insetincludes.
2445 string top_element = textclasslist.LatexnameOfClass(params.textclass);
2446 string environment_stack[10];
2449 int depth = 0; // paragraph depth
2451 ofstream ofs(fname.c_str());
2454 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2458 LyXTextClass const & tclass =
2459 textclasslist.TextClass(params.textclass);
2461 LaTeXFeatures features(params, tclass.numLayouts());
2465 tex_code_break_column = lyxrc.ascii_linelen;
2467 //tex_code_break_column = 0;
2472 string sgml_includedfiles=features.getIncludedFiles();
2474 if (params.preamble.empty() && sgml_includedfiles.empty()) {
2475 ofs << "<!doctype linuxdoc system>\n\n";
2477 ofs << "<!doctype linuxdoc system [ "
2478 << params.preamble << sgml_includedfiles << " \n]>\n\n";
2481 if(params.options.empty())
2482 sgmlOpenTag(ofs, 0, top_element);
2484 string top = top_element;
2486 top += params.options;
2487 sgmlOpenTag(ofs, 0, top);
2491 ofs << "<!-- " << LYX_DOCVERSION
2492 << " created this file. For more info see http://www.lyx.org/"
2496 int desc_on = 0; // description mode
2497 LyXLayout const & style =
2498 textclasslist.Style(params.textclass,
2501 // treat <toc> as a special case for compatibility with old code
2502 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2503 Inset * inset = par->GetInset(0);
2504 Inset::Code lyx_code = inset->LyxCode();
2505 if (lyx_code == Inset::TOC_CODE){
2506 string temp = "toc";
2507 sgmlOpenTag(ofs, depth, temp);
2511 linuxDocHandleFootnote(ofs, par, depth);
2517 // environment tag closing
2518 for( ; depth > par->depth; --depth) {
2519 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2520 environment_stack[depth].erase();
2523 // write opening SGML tags
2524 switch(style.latextype) {
2525 case LATEX_PARAGRAPH:
2526 if(depth == par->depth
2527 && !environment_stack[depth].empty()) {
2528 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2529 environment_stack[depth].erase();
2535 sgmlOpenTag(ofs, depth, style.latexname());
2540 LinuxDocError(par, 0,
2541 _("Error : Wrong depth for"
2542 " LatexType Command.\n"));
2544 if (!environment_stack[depth].empty()){
2545 sgmlCloseTag(ofs, depth,
2546 environment_stack[depth]);
2550 environment_stack[depth].erase();
2551 sgmlOpenTag(ofs, depth, style.latexname());
2554 case LATEX_ENVIRONMENT:
2555 case LATEX_ITEM_ENVIRONMENT:
2556 if(depth == par->depth
2557 && environment_stack[depth] != style.latexname()
2558 && !environment_stack[depth].empty()) {
2560 sgmlCloseTag(ofs, depth,
2561 environment_stack[depth]);
2562 environment_stack[depth].erase();
2564 if (depth < par->depth) {
2566 environment_stack[depth].erase();
2568 if (environment_stack[depth] != style.latexname()) {
2571 sgmlOpenTag(ofs, depth, temp);
2573 environment_stack[depth] = style.latexname();
2574 sgmlOpenTag(ofs, depth,
2575 environment_stack[depth]);
2577 if(style.latextype == LATEX_ENVIRONMENT) break;
2579 desc_on = (style.labeltype == LABEL_MANUAL);
2586 sgmlOpenTag(ofs, depth + 1, item_name);
2589 sgmlOpenTag(ofs, depth, style.latexname());
2596 SimpleLinuxDocOnePar(ofs, par, desc_on, depth);
2600 linuxDocHandleFootnote(ofs, par, depth);
2602 while(par && par->IsDummy());
2606 // write closing SGML tags
2607 switch(style.latextype) {
2609 case LATEX_ENVIRONMENT:
2610 case LATEX_ITEM_ENVIRONMENT:
2613 sgmlCloseTag(ofs, depth, style.latexname());
2619 for(; depth > 0; --depth)
2620 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2622 if(!environment_stack[depth].empty())
2623 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2627 sgmlCloseTag(ofs, 0, top_element);
2631 // How to check for successful close
2636 void Buffer::linuxDocHandleFootnote(ostream & os, LyXParagraph * & par,
2639 string tag = "footnote";
2641 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2642 sgmlOpenTag(os, depth + 1, tag);
2643 SimpleLinuxDocOnePar(os, par, 0, depth + 1);
2644 sgmlCloseTag(os, depth + 1, tag);
2651 void Buffer::DocBookHandleCaption(ostream & os, string & inner_tag,
2652 int const depth, int desc_on,
2653 LyXParagraph * & par)
2655 LyXParagraph * tpar = par;
2658 && (tpar->footnoteflag != LyXParagraph::NO_FOOTNOTE)
2660 && (tpar->layout != textclasslist.NumberOfLayout(params.textclass,
2664 tpar->layout == textclasslist.NumberOfLayout(params.textclass,
2665 "Caption").second) {
2666 sgmlOpenTag(os, depth + 1, inner_tag);
2668 SimpleDocBookOnePar(os, extra_par, tpar,
2669 desc_on, depth + 2);
2670 sgmlCloseTag(os, depth+1, inner_tag);
2671 if(!extra_par.empty())
2678 void Buffer::DocBookHandleFootnote(ostream & os, LyXParagraph * & par,
2681 string tag, inner_tag;
2682 string tmp_par, extra_par;
2683 bool inner_span = false;
2686 // Someone should give this enum a proper name (Lgb)
2694 SOME_ENUM last = NO_ONE;
2695 SOME_ENUM present = FOOTNOTE_LIKE;
2697 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2698 if(last == present) {
2700 if(!tmp_par.empty()) {
2703 sgmlCloseTag(os, depth + 1, inner_tag);
2704 sgmlOpenTag(os, depth + 1, inner_tag);
2711 if(!inner_tag.empty()) sgmlCloseTag(os, depth + 1,
2713 if(!extra_par.empty()) os << extra_par;
2714 if(!tag.empty()) sgmlCloseTag(os, depth, tag);
2717 switch (par->footnotekind) {
2718 case LyXParagraph::FOOTNOTE:
2719 case LyXParagraph::ALGORITHM:
2722 present = FOOTNOTE_LIKE;
2725 case LyXParagraph::MARGIN:
2728 present = MARGIN_LIKE;
2731 case LyXParagraph::FIG:
2732 case LyXParagraph::WIDE_FIG:
2734 inner_tag = "title";
2738 case LyXParagraph::TAB:
2739 case LyXParagraph::WIDE_TAB:
2741 inner_tag = "title";
2746 sgmlOpenTag(os, depth, tag);
2747 if ((present == TAB_LIKE) || (present == FIG_LIKE)) {
2748 DocBookHandleCaption(os, inner_tag, depth,
2752 sgmlOpenTag(os, depth + 1, inner_tag);
2755 // ignore all caption here, we processed them above!!!
2756 if (par->layout != textclasslist
2757 .NumberOfLayout(params.textclass,
2758 "Caption").second) {
2760 std::ostringstream ost;
2764 SimpleDocBookOnePar(ost, extra_par, par,
2765 desc_on, depth + 2);
2767 tmp_par += ost.str().c_str();
2770 char * ctmp = ost.str();
2775 tmp_par = frontStrip(strip(tmp_par));
2781 if(!inner_tag.empty()) sgmlCloseTag(os, depth + 1, inner_tag);
2782 if(!extra_par.empty()) os << extra_par;
2783 if(!tag.empty()) sgmlCloseTag(os, depth, tag);
2788 // push a tag in a style stack
2789 void Buffer::push_tag(ostream & os, char const * tag,
2790 int & pos, char stack[5][3])
2792 // pop all previous tags
2793 for (int j = pos; j >= 0; --j)
2794 os << "</" << stack[j] << ">";
2797 sprintf(stack[++pos], "%s", tag);
2800 for (int i = 0; i <= pos; ++i)
2801 os << "<" << stack[i] << ">";
2805 void Buffer::pop_tag(ostream & os, char const * tag,
2806 int & pos, char stack[5][3])
2810 // pop all tags till specified one
2811 for (j = pos; (j >= 0) && (strcmp(stack[j], tag)); --j)
2812 os << "</" << stack[j] << ">";
2815 os << "</" << tag << ">";
2817 // push all tags, but the specified one
2818 for (j = j + 1; j <= pos; ++j) {
2819 os << "<" << stack[j] << ">";
2820 strcpy(stack[j-1], stack[j]);
2826 // Handle internal paragraph parsing -- layout already processed.
2828 // checks, if newcol chars should be put into this line
2829 // writes newline, if necessary.
2831 void linux_doc_line_break(ostream & os, unsigned int & colcount,
2832 const unsigned int newcol)
2835 if (colcount > lyxrc.ascii_linelen) {
2837 colcount = newcol; // assume write after this call
2842 void Buffer::SimpleLinuxDocOnePar(ostream & os, LyXParagraph * par,
2843 int desc_on, int const /*depth*/)
2845 LyXFont font1, font2;
2848 LyXParagraph::size_type main_body;
2850 LyXLayout const & style = textclasslist.Style(params.textclass,
2853 char family_type = 0; // family font flag
2854 bool is_bold = false; // series font flag
2855 char shape_type = 0; // shape font flag
2856 bool is_em = false; // emphasis (italic) font flag
2858 int stack_num = -1; // style stack position
2859 // Can this be rewritten to use a std::stack, please. (Lgb)
2860 char stack[5][3]; // style stack
2861 unsigned int char_line_count = 5; // Heuristic choice ;-)
2863 if (style.labeltype != LABEL_MANUAL)
2866 main_body = par->BeginningOfMainBody();
2868 // gets paragraph main font
2870 font1 = style.labelfont;
2875 // parsing main loop
2876 for (LyXParagraph::size_type i = 0;
2877 i < par->size(); ++i) {
2889 font2 = par->getFont(params, i);
2891 if (font1.family() != font2.family()) {
2892 switch(family_type) {
2894 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2895 push_tag(os, "tt", stack_num, stack);
2898 else if (font2.family() == LyXFont::SANS_FAMILY) {
2899 push_tag(os, "sf", stack_num, stack);
2904 pop_tag(os, "tt", stack_num, stack);
2905 if (font2.family() == LyXFont::SANS_FAMILY) {
2906 push_tag(os, "sf", stack_num, stack);
2913 pop_tag(os, "sf", stack_num, stack);
2914 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2915 push_tag(os, "tt", stack_num, stack);
2924 if (font1.series() != font2.series()) {
2925 if (font2.series() == LyXFont::BOLD_SERIES) {
2926 push_tag(os, "bf", stack_num, stack);
2928 } else if (is_bold) {
2929 pop_tag(os, "bf", stack_num, stack);
2934 // handle italic and slanted fonts
2935 if (font1.shape() != font2.shape()) {
2936 switch(shape_type) {
2938 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2939 push_tag(os, "it", stack_num, stack);
2941 } else if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2942 push_tag(os, "sl", stack_num, stack);
2947 pop_tag(os, "it", stack_num, stack);
2948 if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2949 push_tag(os, "sl", stack_num, stack);
2956 pop_tag(os, "sl", stack_num, stack);
2957 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2958 push_tag(os, "it", stack_num, stack);
2966 if (font1.emph() != font2.emph()) {
2967 if (font2.emph() == LyXFont::ON) {
2968 push_tag(os, "em", stack_num, stack);
2971 pop_tag(os, "em", stack_num, stack);
2976 c = par->GetChar(i);
2978 if (c == LyXParagraph::META_INSET) {
2979 inset = par->GetInset(i);
2980 inset->Linuxdoc(this, os);
2983 if (font2.latex() == LyXFont::ON) {
2984 // "TeX"-Mode on == > SGML-Mode on.
2986 os << c; // see LaTeX-Generation...
2990 if (par->linuxDocConvertChar(c, sgml_string)
2991 && !style.free_spacing) { // in freespacing
2993 // non-breaking characters
2997 linux_doc_line_break(os, char_line_count, 6);
3001 linux_doc_line_break(os, char_line_count, 1);
3006 char_line_count += sgml_string.length();
3012 // needed if there is an optional argument but no contents
3013 if (main_body > 0 && main_body == par->size()) {
3017 // pop all defined Styles
3018 for (j = stack_num; j >= 0; --j) {
3019 linux_doc_line_break(os,
3021 3 + strlen(stack[j]));
3022 os << "</" << stack[j] << ">";
3025 // resets description flag correctly
3028 // <tag> not closed...
3029 linux_doc_line_break(os, char_line_count, 6);
3033 // fprintf(file, "</p>");
3039 // Print an error message.
3040 void Buffer::LinuxDocError(LyXParagraph * par, int pos,
3041 char const * message)
3043 // insert an error marker in text
3044 InsetError * new_inset = new InsetError(message);
3045 par->InsertInset(pos, new_inset);
3048 // This constant defines the maximum number of
3049 // environment layouts that can be nesteded.
3050 // The same applies for command layouts.
3051 // These values should be more than enough.
3052 // José Matos (1999/07/22)
3054 enum { MAX_NEST_LEVEL = 25};
3056 void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
3058 LyXParagraph * par = paragraph;
3060 niceFile = nice; // this will be used by Insetincludes.
3062 string top_element= textclasslist.LatexnameOfClass(params.textclass);
3063 // Please use a real stack.
3064 string environment_stack[MAX_NEST_LEVEL];
3065 string environment_inner[MAX_NEST_LEVEL];
3066 // Please use a real stack.
3067 string command_stack[MAX_NEST_LEVEL];
3068 bool command_flag= false;
3069 int command_depth= 0, command_base= 0, cmd_depth= 0;
3071 string item_name, command_name;
3072 string c_depth, c_params, tmps;
3074 int depth = 0; // paragraph depth
3075 LyXTextClass const & tclass =
3076 textclasslist.TextClass(params.textclass);
3078 LaTeXFeatures features(params, tclass.numLayouts());
3082 tex_code_break_column = lyxrc.ascii_linelen;
3084 //tex_code_break_column = 0;
3086 ofstream ofs(fname.c_str());
3088 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
3095 string sgml_includedfiles=features.getIncludedFiles();
3097 ofs << "<!doctype " << top_element
3098 << " public \"-//OASIS//DTD DocBook V3.1//EN\"";
3100 if (params.preamble.empty() && sgml_includedfiles.empty())
3103 ofs << "\n [ " << params.preamble
3104 << sgml_includedfiles << " \n]>\n\n";
3106 if(params.options.empty())
3107 sgmlOpenTag(ofs, 0, top_element);
3109 string top = top_element;
3111 top += params.options;
3112 sgmlOpenTag(ofs, 0, top);
3116 ofs << "<!-- DocBook file was created by " << LYX_DOCVERSION
3117 << "\n See http://www.lyx.org/ for more information -->\n";
3120 int desc_on = 0; // description mode
3121 LyXLayout const & style =
3122 textclasslist.Style(params.textclass,
3125 // environment tag closing
3126 for( ; depth > par->depth; --depth) {
3127 if(environment_inner[depth] != "!-- --") {
3128 item_name= "listitem";
3129 sgmlCloseTag(ofs, command_depth + depth,
3131 if( environment_inner[depth] == "varlistentry")
3132 sgmlCloseTag(ofs, depth+command_depth,
3133 environment_inner[depth]);
3135 sgmlCloseTag(ofs, depth + command_depth,
3136 environment_stack[depth]);
3137 environment_stack[depth].erase();
3138 environment_inner[depth].erase();
3141 if(depth == par->depth
3142 && environment_stack[depth] != style.latexname()
3143 && !environment_stack[depth].empty()) {
3144 if(environment_inner[depth] != "!-- --") {
3145 item_name= "listitem";
3146 sgmlCloseTag(ofs, command_depth+depth,
3148 if( environment_inner[depth] == "varlistentry")
3150 depth + command_depth,
3151 environment_inner[depth]);
3154 sgmlCloseTag(ofs, depth + command_depth,
3155 environment_stack[depth]);
3157 environment_stack[depth].erase();
3158 environment_inner[depth].erase();
3161 // Write opening SGML tags.
3162 switch(style.latextype) {
3163 case LATEX_PARAGRAPH:
3164 if(style.latexname() != "dummy")
3165 sgmlOpenTag(ofs, depth+command_depth,
3171 LinuxDocError(par, 0,
3172 _("Error : Wrong depth for "
3173 "LatexType Command.\n"));
3175 command_name = style.latexname();
3177 tmps = style.latexparam();
3178 c_params = split(tmps, c_depth,'|');
3180 cmd_depth= atoi(c_depth.c_str());
3183 if(cmd_depth<command_base) {
3184 for(int j = command_depth;
3185 j >= command_base; --j)
3186 if(!command_stack[j].empty())
3187 sgmlCloseTag(ofs, j, command_stack[j]);
3188 command_depth= command_base= cmd_depth;
3189 } else if(cmd_depth <= command_depth) {
3190 for(int j = command_depth;
3191 j >= cmd_depth; --j)
3193 if(!command_stack[j].empty())
3194 sgmlCloseTag(ofs, j, command_stack[j]);
3195 command_depth= cmd_depth;
3197 command_depth= cmd_depth;
3199 command_depth = command_base = cmd_depth;
3200 command_flag = true;
3202 command_stack[command_depth]= command_name;
3204 // treat label as a special case for
3205 // more WYSIWYM handling.
3206 if (par->GetChar(0) == LyXParagraph::META_INSET) {
3207 Inset * inset = par->GetInset(0);
3208 Inset::Code lyx_code = inset->LyxCode();
3209 if (lyx_code == Inset::LABEL_CODE){
3210 command_name += " id=\"";
3211 command_name += (static_cast<InsetCommand *>(inset))->getContents();
3212 command_name += "\"";
3217 sgmlOpenTag(ofs, depth + command_depth, command_name);
3218 item_name = "title";
3219 sgmlOpenTag(ofs, depth + 1 + command_depth, item_name);
3222 case LATEX_ENVIRONMENT:
3223 case LATEX_ITEM_ENVIRONMENT:
3224 if (depth < par->depth) {
3226 environment_stack[depth].erase();
3229 if (environment_stack[depth] != style.latexname()) {
3230 environment_stack[depth] = style.latexname();
3231 environment_inner[depth] = "!-- --";
3232 sgmlOpenTag(ofs, depth + command_depth,
3233 environment_stack[depth]);
3235 if(environment_inner[depth] != "!-- --") {
3236 item_name= "listitem";
3238 command_depth + depth,
3240 if (environment_inner[depth] == "varlistentry")
3242 depth + command_depth,
3243 environment_inner[depth]);
3247 if(style.latextype == LATEX_ENVIRONMENT) {
3248 if(!style.latexparam().empty())
3249 sgmlOpenTag(ofs, depth + command_depth,
3250 style.latexparam());
3254 desc_on = (style.labeltype == LABEL_MANUAL);
3257 environment_inner[depth]= "varlistentry";
3259 environment_inner[depth]= "listitem";
3261 sgmlOpenTag(ofs, depth + 1 + command_depth,
3262 environment_inner[depth]);
3266 sgmlOpenTag(ofs, depth + 1 + command_depth,
3270 sgmlOpenTag(ofs, depth + 1 + command_depth,
3275 sgmlOpenTag(ofs, depth + command_depth,
3284 SimpleDocBookOnePar(ofs, extra_par, par, desc_on,
3285 depth + 1 + command_depth);
3288 DocBookHandleFootnote(ofs, par,
3289 depth + 1 + command_depth);
3291 while(par && par->IsDummy());
3294 // write closing SGML tags
3295 switch(style.latextype) {
3298 sgmlCloseTag(ofs, depth + command_depth, end_tag);
3300 case LATEX_ENVIRONMENT:
3301 if(!style.latexparam().empty())
3302 sgmlCloseTag(ofs, depth + command_depth,
3303 style.latexparam());
3305 case LATEX_ITEM_ENVIRONMENT:
3306 if(desc_on == 1) break;
3308 sgmlCloseTag(ofs, depth + 1 + command_depth, end_tag);
3310 case LATEX_PARAGRAPH:
3311 if(style.latexname() != "dummy")
3312 sgmlCloseTag(ofs, depth + command_depth,
3316 sgmlCloseTag(ofs, depth + command_depth,
3323 for(; depth >= 0; --depth) {
3324 if(!environment_stack[depth].empty()) {
3325 if(environment_inner[depth] != "!-- --") {
3326 item_name= "listitem";
3327 sgmlCloseTag(ofs, command_depth + depth,
3329 if( environment_inner[depth] == "varlistentry")
3330 sgmlCloseTag(ofs, depth + command_depth,
3331 environment_inner[depth]);
3334 sgmlCloseTag(ofs, depth + command_depth,
3335 environment_stack[depth]);
3339 for(int j = command_depth; j >= command_base; --j)
3340 if(!command_stack[j].empty())
3341 sgmlCloseTag(ofs, j, command_stack[j]);
3345 sgmlCloseTag(ofs, 0, top_element);
3349 // How to check for successful close
3353 void Buffer::SimpleDocBookOnePar(ostream & os, string & extra,
3354 LyXParagraph * par, int & desc_on,
3359 par->SimpleDocBookOneTablePar(this,
3360 os, extra, desc_on, depth);
3365 bool emph_flag = false;
3367 LyXLayout const & style = textclasslist.Style(params.textclass,
3370 LyXParagraph::size_type main_body;
3371 if (style.labeltype != LABEL_MANUAL)
3374 main_body = par->BeginningOfMainBody();
3376 // gets paragraph main font
3377 LyXFont font1 = main_body > 0 ? style.labelfont : style.font;
3379 int char_line_count = depth;
3380 if(!style.free_spacing)
3381 for (int j = 0; j < depth; ++j)
3384 // parsing main loop
3385 for (LyXParagraph::size_type i = 0;
3386 i < par->size(); ++i) {
3387 LyXFont font2 = par->getFont(params, i);
3389 // handle <emphasis> tag
3390 if (font1.emph() != font2.emph() && i) {
3391 if (font2.emph() == LyXFont::ON) {
3395 os << "</emphasis>";
3400 char c = par->GetChar(i);
3402 if (c == LyXParagraph::META_INSET) {
3403 Inset * inset = par->GetInset(i);
3405 std::ostringstream ost;
3406 inset->DocBook(this, ost);
3407 string tmp_out = ost.str().c_str();
3410 inset->DocBook(this, ost);
3412 char * ctmp = ost.str();
3413 string tmp_out(ctmp);
3417 // This code needs some explanation:
3418 // Two insets are treated specially
3419 // label if it is the first element in a command paragraph
3421 // graphics inside tables or figure floats can't go on
3422 // title (the equivalente in latex for this case is caption
3423 // and title should come first
3426 if(desc_on!= 3 || i!= 0) {
3427 if(!tmp_out.empty() && tmp_out[0] == '@') {
3429 extra += frontStrip(tmp_out, '@');
3431 os << frontStrip(tmp_out, '@');
3436 } else if (font2.latex() == LyXFont::ON) {
3437 // "TeX"-Mode on ==> SGML-Mode on.
3443 if (par->linuxDocConvertChar(c, sgml_string)
3444 && !style.free_spacing) { // in freespacing
3446 // non-breaking characters
3450 os << "\n</term><listitem><para>";
3462 // needed if there is an optional argument but no contents
3463 if (main_body > 0 && main_body == par->size()) {
3467 os << "</emphasis>";
3470 // resets description flag correctly
3473 // <term> not closed...
3481 int Buffer::runLaTeX()
3483 if (!users->text) return 0;
3485 ProhibitInput(users);
3487 // get LaTeX-Filename
3488 string name = getLatexName();
3490 string path = OnlyPath(filename);
3492 string org_path = path;
3493 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3497 Path p(path); // path to LaTeX file
3498 users->owner()->getMiniBuffer()->Set(_("Running LaTeX..."));
3500 // Remove all error insets
3501 bool a = users->removeAutoInsets();
3503 // Always generate the LaTeX file
3504 makeLaTeXFile(name, org_path, false);
3506 // do the LaTex run(s)
3508 string latex_command = lyxrc.pdf_mode ?
3509 lyxrc.pdflatex_command : lyxrc.latex_command;
3510 LaTeX latex(latex_command, name, filepath);
3511 int res = latex.run(terr,
3512 users->owner()->getMiniBuffer()); // running latex
3514 // check return value from latex.run().
3515 if ((res & LaTeX::NO_LOGFILE)) {
3516 WriteAlert(_("LaTeX did not work!"),
3517 _("Missing log file:"), name);
3518 } else if ((res & LaTeX::ERRORS)) {
3519 users->owner()->getMiniBuffer()->Set(_("Done"));
3520 // Insert all errors as errors boxes
3521 users->insertErrors(terr);
3523 // Dvi should also be kept dirty if the latex run
3524 // ends up with errors. However it should be possible
3525 // to view a dirty dvi too.
3527 //no errors or any other things to think about so:
3528 users->owner()->getMiniBuffer()->Set(_("Done"));
3531 // if we removed error insets before we ran LaTeX or if we inserted
3532 // error insets after we ran LaTeX this must be run:
3533 if (a || (res & LaTeX::ERRORS)){
3536 //users->updateScrollbar();
3540 return latex.getNumErrors();
3544 int Buffer::runLiterate()
3546 if (!users->text) return 0;
3548 ProhibitInput(users);
3550 // get LaTeX-Filename
3551 string name = getLatexName();
3552 // get Literate-Filename
3553 string lit_name = OnlyFilename(ChangeExtension (getLatexName(),
3554 lyxrc.literate_extension));
3556 string path = OnlyPath(filename);
3558 string org_path = path;
3559 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3563 Path p(path); // path to Literate file
3564 users->owner()->getMiniBuffer()->Set(_("Running Literate..."));
3566 // Remove all error insets
3567 bool removedErrorInsets = users->removeAutoInsets();
3569 // generate the Literate file if necessary
3570 makeLaTeXFile(lit_name, org_path, false);
3572 string latex_command = lyxrc.pdf_mode ?
3573 lyxrc.pdflatex_command : lyxrc.latex_command;
3574 Literate literate(latex_command, name, filepath,
3576 lyxrc.literate_command, lyxrc.literate_error_filter,
3577 lyxrc.build_command, lyxrc.build_error_filter);
3579 int res = literate.weave(terr, users->owner()->getMiniBuffer());
3581 // check return value from literate.weave().
3582 if ((res & Literate::NO_LOGFILE)) {
3583 WriteAlert(_("Literate command did not work!"),
3584 _("Missing log file:"), name);
3585 } else if ((res & Literate::ERRORS)) {
3586 users->owner()->getMiniBuffer()->Set(_("Done"));
3587 // Insert all errors as errors boxes
3588 users->insertErrors(terr);
3590 // Dvi should also be kept dirty if the latex run
3591 // ends up with errors. However it should be possible
3592 // to view a dirty dvi too.
3594 //no errors or any other things to think about so:
3595 users->owner()->getMiniBuffer()->Set(_("Done"));
3598 // if we removed error insets before we ran LaTeX or if we inserted
3599 // error insets after we ran LaTeX this must be run:
3600 if (removedErrorInsets || (res & Literate::ERRORS)){
3603 //users->updateScrollbar();
3607 return literate.getNumErrors();
3611 int Buffer::buildProgram()
3613 if (!users->text) return 0;
3615 ProhibitInput(users);
3617 // get LaTeX-Filename
3618 string name = getLatexName();
3619 // get Literate-Filename
3620 string lit_name = OnlyFilename(ChangeExtension(getLatexName(),
3621 lyxrc.literate_extension));
3623 string path = OnlyPath(filename);
3625 string org_path = path;
3626 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3630 Path p(path); // path to Literate file
3631 users->owner()->getMiniBuffer()->Set(_("Building Program..."));
3633 // Remove all error insets
3634 bool removedErrorInsets = users->removeAutoInsets();
3636 // generate the LaTeX file if necessary
3637 if (!isNwClean() || removedErrorInsets) {
3638 makeLaTeXFile(lit_name, org_path, false);
3642 string latex_command = lyxrc.pdf_mode ?
3643 lyxrc.pdflatex_command : lyxrc.latex_command;
3644 Literate literate(latex_command, name, filepath,
3646 lyxrc.literate_command, lyxrc.literate_error_filter,
3647 lyxrc.build_command, lyxrc.build_error_filter);
3649 int res = literate.build(terr, users->owner()->getMiniBuffer());
3651 // check return value from literate.build().
3652 if ((res & Literate::NO_LOGFILE)) {
3653 WriteAlert(_("Build did not work!"),
3654 _("Missing log file:"), name);
3655 } else if ((res & Literate::ERRORS)) {
3656 users->owner()->getMiniBuffer()->Set(_("Done"));
3657 // Insert all errors as errors boxes
3658 users->insertErrors(terr);
3660 // Literate files should also be kept dirty if the literate
3661 // command run ends up with errors.
3663 //no errors or any other things to think about so:
3664 users->owner()->getMiniBuffer()->Set(_("Done"));
3668 // if we removed error insets before we ran Literate/Build or
3669 // if we inserted error insets after we ran Literate/Build this
3671 if (removedErrorInsets || (res & Literate::ERRORS)){
3674 //users->updateScrollbar();
3678 return literate.getNumErrors();
3682 // This should be enabled when the Chktex class is implemented. (Asger)
3683 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
3684 // Other flags: -wall -v0 -x
3685 int Buffer::runChktex()
3687 if (!users->text) return 0;
3689 ProhibitInput(users);
3691 // get LaTeX-Filename
3692 string name = getLatexName();
3693 string path = OnlyPath(filename);
3695 string org_path = path;
3696 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3700 Path p(path); // path to LaTeX file
3701 users->owner()->getMiniBuffer()->Set(_("Running chktex..."));
3703 // Remove all error insets
3704 bool removedErrorInsets = users->removeAutoInsets();
3706 // Generate the LaTeX file if neccessary
3707 makeLaTeXFile(name, org_path, false);
3710 Chktex chktex(lyxrc.chktex_command, name, filepath);
3711 int res = chktex.run(terr); // run chktex
3714 WriteAlert(_("chktex did not work!"),
3715 _("Could not run with file:"), name);
3716 } else if (res > 0) {
3717 // Insert all errors as errors boxes
3718 users->insertErrors(terr);
3721 // if we removed error insets before we ran chktex or if we inserted
3722 // error insets after we ran chktex, this must be run:
3723 if (removedErrorInsets || res){
3726 //users->updateScrollbar();
3734 void Buffer::validate(LaTeXFeatures & features) const
3736 LyXParagraph * par = paragraph;
3737 LyXTextClass const & tclass =
3738 textclasslist.TextClass(params.textclass);
3740 // AMS Style is at document level
3742 features.amsstyle = (params.use_amsmath ||
3743 tclass.provides(LyXTextClass::amsmath));
3746 // We don't use "lyxerr.debug" because of speed. (Asger)
3747 if (lyxerr.debugging(Debug::LATEX))
3748 lyxerr << "Paragraph: " << par << endl;
3750 // Now just follow the list of paragraphs and run
3751 // validate on each of them.
3752 par->validate(features);
3754 // and then the next paragraph
3758 // the bullet shapes are buffer level not paragraph level
3759 // so they are tested here
3760 for (int i = 0; i < 4; ++i) {
3761 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
3762 int font = params.user_defined_bullets[i].getFont();
3765 .user_defined_bullets[i]
3772 features.latexsym = true;
3776 features.amssymb = true;
3778 else if ((font >= 2 && font <= 5)) {
3779 features.pifont = true;
3784 if (lyxerr.debugging(Debug::LATEX)) {
3785 features.showStruct();
3790 void Buffer::setPaperStuff()
3792 params.papersize = BufferParams::PAPER_DEFAULT;
3793 char c1 = params.paperpackage;
3794 if (c1 == BufferParams::PACKAGE_NONE) {
3795 char c2 = params.papersize2;
3796 if (c2 == BufferParams::VM_PAPER_USLETTER)
3797 params.papersize = BufferParams::PAPER_USLETTER;
3798 else if (c2 == BufferParams::VM_PAPER_USLEGAL)
3799 params.papersize = BufferParams::PAPER_LEGALPAPER;
3800 else if (c2 == BufferParams::VM_PAPER_USEXECUTIVE)
3801 params.papersize = BufferParams::PAPER_EXECUTIVEPAPER;
3802 else if (c2 == BufferParams::VM_PAPER_A3)
3803 params.papersize = BufferParams::PAPER_A3PAPER;
3804 else if (c2 == BufferParams::VM_PAPER_A4)
3805 params.papersize = BufferParams::PAPER_A4PAPER;
3806 else if (c2 == BufferParams::VM_PAPER_A5)
3807 params.papersize = BufferParams::PAPER_A5PAPER;
3808 else if ((c2 == BufferParams::VM_PAPER_B3) || (c2 == BufferParams::VM_PAPER_B4) ||
3809 (c2 == BufferParams::VM_PAPER_B5))
3810 params.papersize = BufferParams::PAPER_B5PAPER;
3811 } else if ((c1 == BufferParams::PACKAGE_A4) || (c1 == BufferParams::PACKAGE_A4WIDE) ||
3812 (c1 == BufferParams::PACKAGE_WIDEMARGINSA4))
3813 params.papersize = BufferParams::PAPER_A4PAPER;
3817 // This function should be in Buffer because it's a buffer's property (ale)
3818 string Buffer::getIncludeonlyList(char delim)
3821 for (inset_iterator it = inset_iterator_begin();
3822 it != inset_iterator_end(); ++it) {
3823 if ((*it)->LyxCode() == Inset::INCLUDE_CODE) {
3824 InsetInclude * insetinc =
3825 static_cast<InsetInclude *>(*it);
3826 if (insetinc->isInclude()
3827 && insetinc->isNoLoad()) {
3830 lst += OnlyFilename(ChangeExtension(insetinc->getContents(), string()));
3834 lyxerr.debug() << "Includeonly(" << lst << ')' << endl;
3839 vector<string> Buffer::getLabelList()
3841 /// if this is a child document and the parent is already loaded
3842 /// Use the parent's list instead [ale990407]
3843 if (!params.parentname.empty()
3844 && bufferlist.exists(params.parentname)) {
3845 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3847 return tmp->getLabelList();
3850 vector<string> label_list;
3851 for (inset_iterator it = inset_iterator_begin();
3852 it != inset_iterator_end(); ++it) {
3853 vector<string> l = (*it)->getLabelList();
3854 label_list.insert(label_list.end(), l.begin(), l.end());
3860 vector<vector<Buffer::TocItem> > Buffer::getTocList()
3862 vector<vector<TocItem> > l(4);
3863 LyXParagraph * par = paragraph;
3866 if (par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
3867 if (textclasslist.Style(params.textclass,
3868 par->GetLayout()).labeltype
3869 == LABEL_SENSITIVE) {
3873 tmp.str = par->String(this, false);
3874 switch (par->footnotekind) {
3875 case LyXParagraph::FIG:
3876 case LyXParagraph::WIDE_FIG:
3877 l[TOC_LOF].push_back(tmp);
3879 case LyXParagraph::TAB:
3880 case LyXParagraph::WIDE_TAB:
3881 l[TOC_LOT].push_back(tmp);
3883 case LyXParagraph::ALGORITHM:
3884 l[TOC_LOA].push_back(tmp);
3886 case LyXParagraph::FOOTNOTE:
3887 case LyXParagraph::MARGIN:
3891 } else if (!par->IsDummy()) {
3893 char labeltype = textclasslist.Style(params.textclass,
3894 par->GetLayout()).labeltype;
3896 if (labeltype >= LABEL_COUNTER_CHAPTER
3897 && labeltype <= LABEL_COUNTER_CHAPTER + params.tocdepth) {
3898 // insert this into the table of contents
3903 textclasslist.TextClass(params.textclass).maxcounter());
3904 tmp.str = par->String(this, true);
3905 l[TOC_TOC].push_back(tmp);
3915 // This is also a buffer property (ale)
3916 vector<pair<string,string> > Buffer::getBibkeyList()
3918 /// if this is a child document and the parent is already loaded
3919 /// Use the parent's list instead [ale990412]
3920 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3921 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3923 return tmp->getBibkeyList();
3926 vector<pair<string, string> > keys;
3927 LyXParagraph * par = paragraph;
3930 keys.push_back(pair<string, string>(par->bibkey->getContents(),
3931 par->String(this, false)));
3935 // Might be either using bibtex or a child has bibliography
3937 for (inset_iterator it = inset_iterator_begin();
3938 it != inset_iterator_end(); ++it) {
3939 // Search for Bibtex or Include inset
3940 if ((*it)->LyxCode() == Inset::BIBTEX_CODE) {
3941 vector<pair<string,string> > tmp =
3942 static_cast<InsetBibtex*>(*it)->getKeys();
3943 keys.insert(keys.end(), tmp.begin(), tmp.end());
3944 } else if ((*it)->LyxCode() == Inset::INCLUDE_CODE) {
3945 vector<pair<string,string> > tmp =
3946 static_cast<InsetInclude*>(*it)->getKeys();
3947 keys.insert(keys.end(), tmp.begin(), tmp.end());
3956 bool Buffer::isDepClean(string const & name) const
3958 DEPCLEAN * item = dep_clean;
3959 while (item && item->master != name)
3961 if (!item) return true;
3966 void Buffer::markDepClean(string const & name)
3969 dep_clean = new DEPCLEAN;
3970 dep_clean->clean = true;
3971 dep_clean->master = name;
3972 dep_clean->next = 0;
3974 DEPCLEAN* item = dep_clean;
3975 while (item && item->master != name)
3980 item = new DEPCLEAN;
3982 item->master = name;
3989 bool Buffer::Dispatch(string const & command)
3991 // Split command string into command and argument
3992 string cmd, line = frontStrip(command);
3993 string arg = strip(frontStrip(split(line, cmd, ' ')));
3995 return Dispatch(lyxaction.LookupFunc(cmd.c_str()), arg.c_str());
3999 bool Buffer::Dispatch(int action, string const & argument)
4001 bool dispatched = true;
4004 MenuExport(this, argument);
4014 void Buffer::resize()
4016 /// resize the BufferViews!
4022 void Buffer::resizeInsets(BufferView * bv)
4024 /// then remove all LyXText in text-insets
4025 LyXParagraph * par = paragraph;
4026 for(;par;par = par->next) {
4027 par->resizeInsetsLyXText(bv);
4031 void Buffer::ChangeLanguage(Language const * from, Language const * to)
4034 LyXParagraph * par = paragraph;
4036 par->ChangeLanguage(params, from, to);
4042 bool Buffer::isMultiLingual()
4045 LyXParagraph * par = paragraph;
4047 if (par->isMultiLingual(params))
4055 Buffer::inset_iterator::inset_iterator(LyXParagraph * paragraph,
4056 LyXParagraph::size_type pos)
4058 it = par->InsetIterator(pos);
4059 if (it == par->inset_iterator_end()) {
4066 void Buffer::inset_iterator::SetParagraph() {
4068 it = par->inset_iterator_begin();
4069 if (it != par->inset_iterator_end())
4074 // We maintain an invariant that whenever par = 0 then it = 0