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);
955 } else if (tmptok == "LatexCommand") {
957 inscmd.Read(this, lex);
959 if (inscmd.getCmdName() == "cite") {
960 inset = new InsetCitation(inscmd.params());
961 } else if (inscmd.getCmdName() == "bibitem") {
962 lex.printError("Wrong place for bibitem");
963 inset = inscmd.Clone();
964 } else if (inscmd.getCmdName() == "BibTeX") {
965 inset = new InsetBibtex(inscmd.getContents(), inscmd.getOptions(), this);
966 } else if (inscmd.getCmdName() == "index") {
967 inset = new InsetIndex(inscmd.getContents());
968 } else if (inscmd.getCmdName() == "include") {
969 inset = new InsetInclude(inscmd.getContents(), this);
970 } else if (inscmd.getCmdName() == "label") {
971 inset = new InsetLabel(inscmd.getCommand());
972 } else if (inscmd.getCmdName() == "url"
973 || inscmd.getCmdName() == "htmlurl") {
974 inset = new InsetUrl(inscmd.params());
975 } else if (inscmd.getCmdName() == "ref"
976 || inscmd.getCmdName() == "pageref"
977 || inscmd.getCmdName() == "vref"
978 || inscmd.getCmdName() == "vpageref"
979 || inscmd.getCmdName() == "prettyref") {
980 if (!inscmd.getOptions().empty() || !inscmd.getContents().empty()) {
981 inset = new InsetRef(inscmd, this);
983 } else if (inscmd.getCmdName() == "tableofcontents") {
984 inset = new InsetTOC(this);
985 } else if (inscmd.getCmdName() == "listoffigures") {
986 inset = new InsetLOF(this);
987 } else if (inscmd.getCmdName() == "listofalgorithms") {
988 inset = new InsetLOA(this);
989 } else if (inscmd.getCmdName() == "listoftables") {
990 inset = new InsetLOT(this);
991 } else if (inscmd.getCmdName() == "printindex") {
992 inset = new InsetPrintIndex(this);
993 } else if (inscmd.getCmdName() == "lyxparent") {
994 inset = new InsetParent(inscmd.getContents(), this);
998 par->InsertInset(pos, inset, font);
1003 } else if (token == "\\SpecialChar") {
1004 LyXLayout const & layout =
1005 textclasslist.Style(params.textclass,
1008 // Insets don't make sense in a free-spacing context! ---Kayvan
1009 if (layout.free_spacing) {
1012 string next_token = lex.GetString();
1013 if (next_token == "\\-") {
1014 par->InsertChar(pos, '-', font);
1015 } else if (next_token == "\\protected_separator"
1016 || next_token == "~") {
1017 par->InsertChar(pos, ' ', font);
1019 lex.printError("Token `$$Token' "
1021 "paragraph layout!");
1026 Inset * inset = new InsetSpecialChar;
1027 inset->Read(this, lex);
1028 par->InsertInset(pos, inset, font);
1031 } else if (token == "\\newline") {
1032 par->InsertChar(pos, LyXParagraph::META_NEWLINE, font);
1034 } else if (token == "\\LyXTable") {
1036 Inset * inset = new InsetTabular(this);
1037 inset->Read(this, lex);
1038 par->InsertInset(pos, inset, font);
1041 par->table = new LyXTable(lex);
1043 } else if (token == "\\hfill") {
1044 par->InsertChar(pos, LyXParagraph::META_HFILL, font);
1046 } else if (token == "\\protected_separator") { // obsolete
1047 // This is a backward compability thingie. (Lgb)
1048 // Remove it later some time...introduced with fileformat
1050 LyXLayout const & layout =
1051 textclasslist.Style(params.textclass,
1054 if (layout.free_spacing) {
1055 par->InsertChar(pos, ' ', font);
1057 Inset * inset = new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
1058 par->InsertInset(pos, inset, font);
1061 } else if (token == "\\bibitem") { // ale970302
1063 par->bibkey = new InsetBibKey;
1064 par->bibkey->Read(this, lex);
1065 }else if (token == "\\backslash") {
1066 par->InsertChar(pos, '\\', font);
1068 }else if (token == "\\the_end") {
1069 the_end_read = true;
1071 // This should be insurance for the future: (Asger)
1072 lex.printError("Unknown token `$$Token'. "
1073 "Inserting as text.");
1074 for(string::const_iterator cit = token.begin();
1075 cit != token.end(); ++cit) {
1076 par->InsertChar(pos, (*cit), font);
1080 return the_end_read;
1084 void Buffer::readInset(LyXLex & lex, LyXParagraph *& par,
1085 int & pos, LyXFont & font)
1087 // consistency check
1088 if (lex.GetString() != "\\begin_inset") {
1089 lyxerr << "Buffer::readInset: Consistency check failed."
1094 string tmptok = lex.GetString();
1095 last_inset_read = tmptok;
1096 // test the different insets
1097 if (tmptok == "Quotes") {
1098 Inset * inset = new InsetQuotes;
1099 inset->Read(this, lex);
1100 par->InsertInset(pos, inset, font);
1102 } else if (tmptok == "External") {
1103 Inset * inset = new InsetExternal;
1104 inset->Read(this, lex);
1105 par->InsertInset(pos, inset, font);
1107 } else if (tmptok == "FormulaMacro") {
1108 Inset * inset = new InsetFormulaMacro;
1109 inset->Read(this, lex);
1110 par->InsertInset(pos, inset, font);
1112 } else if (tmptok == "Formula") {
1113 Inset * inset = new InsetFormula;
1114 inset->Read(this, lex);
1115 par->InsertInset(pos, inset, font);
1117 } else if (tmptok == "Figure") {
1118 Inset * inset = new InsetFig(100, 100, this);
1119 inset->Read(this, lex);
1120 par->InsertInset(pos, inset, font);
1122 } else if (tmptok == "Info") {
1123 Inset * inset = new InsetInfo;
1124 inset->Read(this, lex);
1125 par->InsertInset(pos, inset, font);
1127 } else if (tmptok == "Include") {
1128 Inset * inset = new InsetInclude(string(), this);
1129 inset->Read(this, lex);
1130 par->InsertInset(pos, inset, font);
1132 } else if (tmptok == "ERT") {
1133 Inset * inset = new InsetERT;
1134 inset->Read(this, lex);
1135 par->InsertInset(pos, inset, font);
1137 } else if (tmptok == "Tabular") {
1138 Inset * inset = new InsetTabular(this);
1139 inset->Read(this, lex);
1140 par->InsertInset(pos, inset, font);
1142 } else if (tmptok == "Text") {
1143 Inset * inset = new InsetText;
1144 inset->Read(this, lex);
1145 par->InsertInset(pos, inset, font);
1147 } else if (tmptok == "Foot") {
1148 Inset * inset = new InsetFoot;
1149 inset->Read(this, lex);
1150 par->InsertInset(pos, inset, font);
1152 } else if (tmptok == "Marginal") {
1153 Inset * inset = new InsetMarginal;
1154 inset->Read(this, lex);
1155 par->InsertInset(pos, inset, font);
1157 } else if (tmptok == "Minipage") {
1158 Inset * inset = new InsetMinipage;
1159 inset->Read(this, lex);
1160 par->InsertInset(pos, inset, font);
1162 } else if (tmptok == "Float") {
1164 string tmptok = lex.GetString();
1165 Inset * inset = new InsetFloat(tmptok);
1166 inset->Read(this, lex);
1167 par->InsertInset(pos, inset, font);
1169 } else if (tmptok == "List") {
1170 Inset * inset = new InsetList;
1171 inset->Read(this, lex);
1172 par->InsertInset(pos, inset, font);
1174 } else if (tmptok == "Theorem") {
1175 Inset * inset = new InsetList;
1176 inset->Read(this, lex);
1177 par->InsertInset(pos, inset, font);
1179 } else if (tmptok == "Caption") {
1180 Inset * inset = new InsetCaption;
1181 inset->Read(this, lex);
1182 par->InsertInset(pos, inset, font);
1184 } else if (tmptok == "GRAPHICS") {
1185 Inset * inset = new InsetGraphics;
1186 //inset->Read(this, lex);
1187 par->InsertInset(pos, inset, font);
1188 } else if (tmptok == "LatexCommand") {
1189 InsetCommand inscmd;
1190 inscmd.Read(this, lex);
1192 if (inscmd.getCmdName() == "cite") {
1193 inset = new InsetCitation(inscmd.params());
1194 } else if (inscmd.getCmdName() == "bibitem") {
1195 lex.printError("Wrong place for bibitem");
1196 inset = inscmd.Clone();
1197 } else if (inscmd.getCmdName() == "BibTeX") {
1198 inset = new InsetBibtex(inscmd.getContents(),
1199 inscmd.getOptions(), this);
1200 } else if (inscmd.getCmdName() == "index") {
1201 inset = new InsetIndex(inscmd.getContents());
1202 } else if (inscmd.getCmdName() == "include") {
1203 inset = new InsetInclude(inscmd.getContents(), this);
1204 } else if (inscmd.getCmdName() == "label") {
1205 inset = new InsetLabel(inscmd.getCommand());
1206 } else if (inscmd.getCmdName() == "url"
1207 || inscmd.getCmdName() == "htmlurl") {
1208 inset = new InsetUrl(inscmd.params());
1209 } else if (inscmd.getCmdName() == "ref"
1210 || inscmd.getCmdName() == "pageref"
1211 || inscmd.getCmdName() == "vref"
1212 || inscmd.getCmdName() == "vpageref"
1213 || inscmd.getCmdName() == "prettyref") {
1214 if (!inscmd.getOptions().empty()
1215 || !inscmd.getContents().empty()) {
1216 inset = new InsetRef(inscmd, this);
1218 } else if (inscmd.getCmdName() == "tableofcontents") {
1219 inset = new InsetTOC(this);
1220 } else if (inscmd.getCmdName() == "listoffigures") {
1221 inset = new InsetLOF(this);
1222 } else if (inscmd.getCmdName() == "listofalgorithms") {
1223 inset = new InsetLOA(this);
1224 } else if (inscmd.getCmdName() == "listoftables") {
1225 inset = new InsetLOT(this);
1226 } else if (inscmd.getCmdName() == "printindex") {
1227 inset = new InsetPrintIndex(this);
1228 } else if (inscmd.getCmdName() == "lyxparent") {
1229 inset = new InsetParent(inscmd.getContents(), this);
1233 par->InsertInset(pos, inset, font);
1240 bool Buffer::readFile(LyXLex & lex, LyXParagraph * par)
1246 token = lex.GetString();
1247 if (token == "\\lyxformat") { // the first token _must_ be...
1249 format = lex.GetFloat();
1251 if (LYX_FORMAT - format > 0.05) {
1252 printf(_("Warning: need lyxformat %.2f but found %.2f\n"),
1253 LYX_FORMAT, format);
1255 if (format - LYX_FORMAT > 0.05) {
1256 printf(_("ERROR: need lyxformat %.2f but found %.2f\n"),
1257 LYX_FORMAT, format);
1259 bool the_end = readLyXformat2(lex, par);
1260 // Formats >= 2.13 support "\the_end" marker
1267 WriteAlert(_("Warning!"),
1268 _("Reading of document is not complete"),
1269 _("Maybe the document is truncated"));
1270 // We simulate a safe reading anyways to allow
1271 // users to take the chance... (Asger)
1275 WriteAlert(_("ERROR!"),
1276 _("Old LyX file format found. "
1277 "Use LyX 0.10.x to read this!"));
1281 } else { // "\\lyxformat" not found
1282 WriteAlert(_("ERROR!"), _("Not a LyX file!"));
1285 WriteAlert(_("ERROR!"), _("Unable to read file!"));
1291 // Should probably be moved to somewhere else: BufferView? LyXView?
1292 bool Buffer::save() const
1294 // We don't need autosaves in the immediate future. (Asger)
1295 resetAutosaveTimers();
1299 if (lyxrc.make_backup) {
1300 s = fileName() + '~';
1301 if (!lyxrc.backupdir_path.empty())
1302 s = AddName(lyxrc.backupdir_path,
1303 subst(CleanupPath(s),'/','!'));
1305 // Rename is the wrong way of making a backup,
1306 // this is the correct way.
1307 /* truss cp fil fil2:
1308 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
1309 stat("LyXVC.lyx", 0xEFFFF688) = 0
1310 open("LyXVC.lyx", O_RDONLY) = 3
1311 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
1312 fstat(4, 0xEFFFF508) = 0
1313 fstat(3, 0xEFFFF508) = 0
1314 read(3, " # T h i s f i l e w".., 8192) = 5579
1315 write(4, " # T h i s f i l e w".., 5579) = 5579
1316 read(3, 0xEFFFD4A0, 8192) = 0
1319 chmod("LyXVC3.lyx", 0100644) = 0
1320 lseek(0, 0, SEEK_CUR) = 46440
1324 // Should proabaly have some more error checking here.
1325 // Should be cleaned up in 0.13, at least a bit.
1326 // Doing it this way, also makes the inodes stay the same.
1327 // This is still not a very good solution, in particular we
1328 // might loose the owner of the backup.
1329 FileInfo finfo(fileName());
1330 if (finfo.exist()) {
1331 mode_t fmode = finfo.getMode();
1332 struct utimbuf times = {
1333 finfo.getAccessTime(),
1334 finfo.getModificationTime() };
1336 ifstream ifs(fileName().c_str());
1337 ofstream ofs(s.c_str(), ios::out|ios::trunc);
1342 ::chmod(s.c_str(), fmode);
1344 if (::utime(s.c_str(), ×)) {
1345 lyxerr << "utime error." << endl;
1348 lyxerr << "LyX was not able to make "
1349 "backupcopy. Beware." << endl;
1354 if (writeFile(fileName(), false)) {
1357 // now delete the autosavefile
1358 string a = OnlyPath(fileName());
1360 a += OnlyFilename(fileName());
1362 FileInfo fileinfo(a);
1363 if (fileinfo.exist()) {
1364 if (::remove(a.c_str()) != 0) {
1365 WriteFSAlert(_("Could not delete "
1366 "auto-save file!"), a);
1370 // Saving failed, so backup is not backup
1371 if (lyxrc.make_backup) {
1372 ::rename(s.c_str(), fileName().c_str());
1380 // Returns false if unsuccesful
1381 bool Buffer::writeFile(string const & fname, bool flag) const
1383 // if flag is false writeFile will not create any GUI
1384 // warnings, only cerr.
1385 // Needed for autosave in background or panic save (Matthias 120496)
1387 if (read_only && (fname == filename)) {
1388 // Here we should come with a question if we should
1389 // perform the write anyway.
1391 lyxerr << _("Error! Document is read-only: ")
1394 WriteAlert(_("Error! Document is read-only: "),
1399 FileInfo finfo(fname);
1400 if (finfo.exist() && !finfo.writable()) {
1401 // Here we should come with a question if we should
1402 // try to do the save anyway. (i.e. do a chmod first)
1404 lyxerr << _("Error! Cannot write file: ")
1407 WriteFSAlert(_("Error! Cannot write file: "),
1412 ofstream ofs(fname.c_str());
1415 lyxerr << _("Error! Cannot open file: ")
1418 WriteFSAlert(_("Error! Cannot open file: "),
1422 // The top of the file should not be written by params.
1424 // write out a comment in the top of the file
1425 ofs << '#' << LYX_DOCVERSION
1426 << " created this file. For more info see http://www.lyx.org/\n";
1427 ofs.setf(ios::showpoint|ios::fixed);
1429 ofs << "\\lyxformat " << setw(4) << LYX_FORMAT << "\n";
1431 // now write out the buffer paramters.
1432 params.writeFile(ofs);
1434 char footnoteflag = 0;
1437 // this will write out all the paragraphs
1438 // using recursive descent.
1439 paragraph->writeFile(this, ofs, params, footnoteflag, depth);
1441 // Write marker that shows file is complete
1442 ofs << "\n\\the_end" << endl;
1444 // how to check if close went ok?
1449 void Buffer::writeFileAscii(string const & fname, int linelen)
1451 LyXFont font1, font2;
1453 char c, footnoteflag = 0, depth = 0;
1455 LyXParagraph::size_type i;
1458 int ltype_depth = 0;
1467 int currlinelen = 0;
1469 bool ref_printed = false;
1471 ofstream ofs(fname.c_str());
1473 WriteFSAlert(_("Error: Cannot write file:"), fname);
1477 string fname1 = TmpFileName();
1478 LyXParagraph * par = paragraph;
1484 par->footnoteflag != LyXParagraph::NO_FOOTNOTE ||
1488 || par->previous->footnoteflag == LyXParagraph::NO_FOOTNOTE
1493 /* begins a footnote environment ? */
1494 if (footnoteflag != par->footnoteflag) {
1495 footnoteflag = par->footnoteflag;
1497 j = strlen(string_footnotekinds[par->footnotekind])+4;
1498 if (currlinelen + j > linelen)
1501 << string_footnotekinds[par->footnotekind] << "] ";
1507 /* begins or ends a deeper area ?*/
1508 if (depth != par->depth) {
1509 if (par->depth > depth) {
1510 while (par->depth > depth) {
1515 while (par->depth < depth) {
1521 /* First write the layout */
1522 tmp = textclasslist.NameOfLayout(params.textclass, par->layout);
1523 if (tmp == "Itemize") {
1525 ltype_depth = depth+1;
1526 } else if (tmp == "Enumerate") {
1528 ltype_depth = depth+1;
1529 } else if (strstr(tmp.c_str(), "ection")) {
1531 ltype_depth = depth+1;
1532 } else if (strstr(tmp.c_str(), "aragraph")) {
1534 ltype_depth = depth+1;
1535 } else if (tmp == "Description") {
1537 ltype_depth = depth+1;
1538 } else if (tmp == "Abstract") {
1541 } else if (tmp == "Bibliography") {
1549 /* maybe some vertical spaces */
1551 /* the labelwidthstring used in lists */
1555 /* some pagebreaks? */
1559 /* what about the alignment */
1562 /* dummy layout, that means a footnote ended */
1563 footnoteflag = LyXParagraph::NO_FOOTNOTE;
1567 lyxerr << "Should this ever happen?" << endl;
1571 //LyXLayout const & layout =
1572 // textclasslist.Style(params.textclass,
1573 // par->GetLayout()); // unused
1574 //bool free_spc = layout.free_spacing; //unused
1577 /* It might be a table */
1581 cells = par->table->columns;
1582 clen = new int [cells];
1583 memset(clen, 0, sizeof(int) * cells);
1585 for (i = 0, j = 0, h = 1; i < par->size(); ++i, ++h) {
1586 c = par->GetChar(i);
1587 if (c == LyXParagraph::META_INSET) {
1588 if ((inset = par->GetInset(i))) {
1590 std::ostringstream ost;
1591 inset->Ascii(this, ost);
1592 h += ost.str().length();
1595 inset->Ascii(this, ost);
1597 char * tmp = ost.str();
1603 } else if (c == LyXParagraph::META_NEWLINE) {
1607 j = (++j) % par->table->NumberOfCellsInRow(actcell);
1615 font1 = LyXFont(LyXFont::ALL_INHERIT, params.language_info);
1617 for (i = 0, actpos = 1; i < par->size(); ++i, ++actpos) {
1618 if (!i && !footnoteflag && !noparbreak){
1620 for(j = 0; j < depth; ++j)
1622 currlinelen = depth * 2;
1624 case 0: /* Standard */
1625 case 4: /* (Sub)Paragraph */
1626 case 5: /* Description */
1628 case 6: /* Abstract */
1629 ofs << "Abstract\n\n";
1631 case 7: /* Bibliography */
1633 ofs << "References\n\n";
1638 ofs << par->labelstring << " ";
1641 if (ltype_depth > depth) {
1642 for(j = ltype_depth - 1; j > depth; --j)
1644 currlinelen += (ltype_depth-depth)*2;
1648 for(j = 0; j < cells; ++j) {
1650 for(h = 0; h < (clen[j] + 1);
1655 for(j = 0; j < depth; ++j)
1657 currlinelen = depth * 2;
1658 if (ltype_depth > depth) {
1659 for(j = ltype_depth;
1662 currlinelen += (ltype_depth-depth)*2;
1668 font2 = par->GetFontSettings(params, i);
1669 if (font1.latex() != font2.latex()) {
1670 if (font2.latex() == LyXFont::OFF)
1677 c = par->GetChar(i);
1681 case LyXParagraph::META_INSET:
1682 if ((inset = par->GetInset(i))) {
1684 inset->Ascii(this, ofs);
1685 currlinelen += (ofs.tellp() - fpos);
1686 actpos += (ofs.tellp() - fpos) - 1;
1689 case LyXParagraph::META_NEWLINE:
1692 if (par->table->NumberOfCellsInRow(actcell) <= cell) {
1693 for(j = actpos; j < clen[cell - 1]; ++j)
1696 for(j = 0; j < depth; ++j)
1698 currlinelen = depth*2;
1699 if (ltype_depth > depth) {
1700 for(j = ltype_depth; j > depth; --j)
1702 currlinelen += (ltype_depth-depth) * 2;
1704 for(j = 0; j < cells; ++j) {
1706 for(h = 0; h < (clen[j] + 1); ++h)
1710 for(j = 0; j < depth; ++j)
1712 currlinelen = depth * 2;
1713 if (ltype_depth > depth) {
1714 for(j = ltype_depth;
1717 currlinelen += (ltype_depth-depth)*2;
1723 j < clen[cell - 1]; ++j)
1729 currlinelen = actpos = 0;
1733 for(j = 0; j < depth; ++j)
1735 currlinelen = depth * 2;
1736 if (ltype_depth > depth) {
1737 for(j = ltype_depth;
1740 currlinelen += (ltype_depth - depth) * 2;
1746 case LyXParagraph::META_HFILL:
1753 if (currlinelen > linelen - 10
1754 && c == ' ' && i + 2 < par->size()) {
1756 for(j = 0; j < depth; ++j)
1758 currlinelen = depth * 2;
1759 if (ltype_depth > depth) {
1760 for(j = ltype_depth;
1763 currlinelen += (ltype_depth-depth)*2;
1765 } else if (c != '\0')
1768 lyxerr.debug() << "writeAsciiFile: NULL char in structure." << endl;
1775 for(j = actpos; j < clen[cell - 1]; ++j)
1778 for(j = 0; j < depth; ++j)
1780 currlinelen = depth * 2;
1781 if (ltype_depth > depth) {
1782 for(j = ltype_depth; j > depth; --j)
1784 currlinelen += (ltype_depth - depth) * 2;
1786 for(j = 0; j < cells; ++j) {
1788 for(h = 0; h < (clen[j] + 1); ++h)
1802 void Buffer::makeLaTeXFile(string const & fname,
1803 string const & original_path,
1804 bool nice, bool only_body)
1806 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
1808 niceFile = nice; // this will be used by Insetincludes.
1810 tex_code_break_column = lyxrc.ascii_linelen;
1812 LyXTextClass const & tclass =
1813 textclasslist.TextClass(params.textclass);
1815 ofstream ofs(fname.c_str());
1817 WriteFSAlert(_("Error: Cannot open file: "), fname);
1821 // validate the buffer.
1822 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
1823 LaTeXFeatures features(params, tclass.numLayouts());
1825 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
1828 // The starting paragraph of the coming rows is the
1829 // first paragraph of the document. (Asger)
1830 texrow.start(paragraph, 0);
1832 if (!only_body && nice) {
1833 ofs << "%% " LYX_DOCVERSION " created this file. "
1834 "For more info, see http://www.lyx.org/.\n"
1835 "%% Do not edit unless you really know what "
1840 lyxerr.debug() << "lyx header finished" << endl;
1841 // There are a few differences between nice LaTeX and usual files:
1842 // usual is \batchmode and has a
1843 // special input@path to allow the including of figures
1844 // with either \input or \includegraphics (what figinsets do).
1845 // batchmode is not set if there is a tex_code_break_column.
1846 // In this case somebody is interested in the generated LaTeX,
1847 // so this is OK. input@path is set when the actual parameter
1848 // original_path is set. This is done for usual tex-file, but not
1849 // for nice-latex-file. (Matthias 250696)
1852 // code for usual, NOT nice-latex-file
1853 ofs << "\\batchmode\n"; // changed
1854 // from \nonstopmode
1857 if (!original_path.empty()) {
1858 ofs << "\\makeatletter\n"
1859 << "\\def\\input@path{{"
1860 << original_path << "/}}\n"
1861 << "\\makeatother\n";
1867 ofs << "\\documentclass";
1869 string options; // the document class options.
1871 if (tokenPos(tclass.opt_fontsize(),
1872 '|', params.fontsize) >= 0) {
1873 // only write if existing in list (and not default)
1874 options += params.fontsize;
1879 if (!params.use_geometry &&
1880 (params.paperpackage == BufferParams::PACKAGE_NONE)) {
1881 switch (params.papersize) {
1882 case BufferParams::PAPER_A4PAPER:
1883 options += "a4paper,";
1885 case BufferParams::PAPER_USLETTER:
1886 options += "letterpaper,";
1888 case BufferParams::PAPER_A5PAPER:
1889 options += "a5paper,";
1891 case BufferParams::PAPER_B5PAPER:
1892 options += "b5paper,";
1894 case BufferParams::PAPER_EXECUTIVEPAPER:
1895 options += "executivepaper,";
1897 case BufferParams::PAPER_LEGALPAPER:
1898 options += "legalpaper,";
1904 if (params.sides != tclass.sides()) {
1905 switch (params.sides) {
1906 case LyXTextClass::OneSide:
1907 options += "oneside,";
1909 case LyXTextClass::TwoSides:
1910 options += "twoside,";
1917 if (params.columns != tclass.columns()) {
1918 if (params.columns == 2)
1919 options += "twocolumn,";
1921 options += "onecolumn,";
1924 if (!params.use_geometry
1925 && params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1926 options += "landscape,";
1928 // language should be a parameter to \documentclass
1929 bool use_babel = false;
1930 if (params.language_info->lang() == "hebrew") // This seems necessary
1931 features.UsedLanguages.insert(default_language);
1932 if (params.language != "default" ||
1933 !features.UsedLanguages.empty() ) {
1935 for (LaTeXFeatures::LanguageList::const_iterator cit =
1936 features.UsedLanguages.begin();
1937 cit != features.UsedLanguages.end(); ++cit)
1938 options += (*cit)->lang() + ",";
1939 options += params.language_info->lang() + ',';
1942 // the user-defined options
1943 if (!params.options.empty()) {
1944 options += params.options + ',';
1947 if (!options.empty()){
1948 options = strip(options, ',');
1949 ofs << '[' << options << ']';
1953 << textclasslist.LatexnameOfClass(params.textclass)
1956 // end of \documentclass defs
1958 // font selection must be done before loading fontenc.sty
1959 if (params.fonts != "default") {
1960 ofs << "\\usepackage{" << params.fonts << "}\n";
1963 // this one is not per buffer
1964 if (lyxrc.fontenc != "default") {
1965 ofs << "\\usepackage[" << lyxrc.fontenc
1970 if (params.inputenc == "auto") {
1971 string doc_encoding =
1972 params.language_info->encoding()->LatexName();
1974 // Create a list with all the input encodings used
1976 set<string> encodings;
1977 for (LaTeXFeatures::LanguageList::const_iterator it =
1978 features.UsedLanguages.begin();
1979 it != features.UsedLanguages.end(); ++it)
1980 if ((*it)->encoding()->LatexName() != doc_encoding)
1981 encodings.insert((*it)->encoding()->LatexName());
1983 ofs << "\\usepackage[";
1984 for (set<string>::const_iterator it = encodings.begin();
1985 it != encodings.end(); ++it)
1987 ofs << doc_encoding << "]{inputenc}\n";
1989 } else if (params.inputenc != "default") {
1990 ofs << "\\usepackage[" << params.inputenc
1995 // At the very beginning the text parameters.
1996 if (params.paperpackage != BufferParams::PACKAGE_NONE) {
1997 switch (params.paperpackage) {
1998 case BufferParams::PACKAGE_A4:
1999 ofs << "\\usepackage{a4}\n";
2002 case BufferParams::PACKAGE_A4WIDE:
2003 ofs << "\\usepackage{a4wide}\n";
2006 case BufferParams::PACKAGE_WIDEMARGINSA4:
2007 ofs << "\\usepackage[widemargins]{a4}\n";
2012 if (params.use_geometry) {
2013 ofs << "\\usepackage{geometry}\n";
2015 ofs << "\\geometry{verbose";
2016 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
2017 ofs << ",landscape";
2018 switch (params.papersize2) {
2019 case BufferParams::VM_PAPER_CUSTOM:
2020 if (!params.paperwidth.empty())
2021 ofs << ",paperwidth="
2022 << params.paperwidth;
2023 if (!params.paperheight.empty())
2024 ofs << ",paperheight="
2025 << params.paperheight;
2027 case BufferParams::VM_PAPER_USLETTER:
2028 ofs << ",letterpaper";
2030 case BufferParams::VM_PAPER_USLEGAL:
2031 ofs << ",legalpaper";
2033 case BufferParams::VM_PAPER_USEXECUTIVE:
2034 ofs << ",executivepaper";
2036 case BufferParams::VM_PAPER_A3:
2039 case BufferParams::VM_PAPER_A4:
2042 case BufferParams::VM_PAPER_A5:
2045 case BufferParams::VM_PAPER_B3:
2048 case BufferParams::VM_PAPER_B4:
2051 case BufferParams::VM_PAPER_B5:
2055 // default papersize ie BufferParams::VM_PAPER_DEFAULT
2056 switch (lyxrc.default_papersize) {
2057 case BufferParams::PAPER_DEFAULT: // keep compiler happy
2058 case BufferParams::PAPER_USLETTER:
2059 ofs << ",letterpaper";
2061 case BufferParams::PAPER_LEGALPAPER:
2062 ofs << ",legalpaper";
2064 case BufferParams::PAPER_EXECUTIVEPAPER:
2065 ofs << ",executivepaper";
2067 case BufferParams::PAPER_A3PAPER:
2070 case BufferParams::PAPER_A4PAPER:
2073 case BufferParams::PAPER_A5PAPER:
2076 case BufferParams::PAPER_B5PAPER:
2081 if (!params.topmargin.empty())
2082 ofs << ",tmargin=" << params.topmargin;
2083 if (!params.bottommargin.empty())
2084 ofs << ",bmargin=" << params.bottommargin;
2085 if (!params.leftmargin.empty())
2086 ofs << ",lmargin=" << params.leftmargin;
2087 if (!params.rightmargin.empty())
2088 ofs << ",rmargin=" << params.rightmargin;
2089 if (!params.headheight.empty())
2090 ofs << ",headheight=" << params.headheight;
2091 if (!params.headsep.empty())
2092 ofs << ",headsep=" << params.headsep;
2093 if (!params.footskip.empty())
2094 ofs << ",footskip=" << params.footskip;
2098 if (params.use_amsmath
2099 && !tclass.provides(LyXTextClass::amsmath)) {
2100 ofs << "\\usepackage{amsmath}\n";
2104 if (tokenPos(tclass.opt_pagestyle(),
2105 '|', params.pagestyle) >= 0) {
2106 if (params.pagestyle == "fancy") {
2107 ofs << "\\usepackage{fancyhdr}\n";
2110 ofs << "\\pagestyle{" << params.pagestyle << "}\n";
2114 // We try to load babel late, in case it interferes
2115 // with other packages.
2117 ofs << lyxrc.language_package << endl;
2121 if (params.secnumdepth != tclass.secnumdepth()) {
2122 ofs << "\\setcounter{secnumdepth}{"
2123 << params.secnumdepth
2127 if (params.tocdepth != tclass.tocdepth()) {
2128 ofs << "\\setcounter{tocdepth}{"
2134 if (params.paragraph_separation) {
2135 switch (params.defskip.kind()) {
2136 case VSpace::SMALLSKIP:
2137 ofs << "\\setlength\\parskip{\\smallskipamount}\n";
2139 case VSpace::MEDSKIP:
2140 ofs << "\\setlength\\parskip{\\medskipamount}\n";
2142 case VSpace::BIGSKIP:
2143 ofs << "\\setlength\\parskip{\\bigskipamount}\n";
2145 case VSpace::LENGTH:
2146 ofs << "\\setlength\\parskip{"
2147 << params.defskip.length().asLatexString()
2150 default: // should never happen // Then delete it.
2151 ofs << "\\setlength\\parskip{\\medskipamount}\n";
2156 ofs << "\\setlength\\parindent{0pt}\n";
2160 // Now insert the LyX specific LaTeX commands...
2162 // The optional packages;
2163 string preamble(features.getPackages());
2165 // this might be useful...
2166 preamble += "\n\\makeatletter\n";
2168 // Some macros LyX will need
2169 string tmppreamble(features.getMacros());
2171 if (!tmppreamble.empty()) {
2172 preamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2173 "LyX specific LaTeX commands.\n"
2174 + tmppreamble + '\n';
2177 // the text class specific preamble
2178 tmppreamble = features.getTClassPreamble();
2179 if (!tmppreamble.empty()) {
2180 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2181 "Textclass specific LaTeX commands.\n"
2182 + tmppreamble + '\n';
2185 /* the user-defined preamble */
2186 if (!params.preamble.empty()) {
2187 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2188 "User specified LaTeX commands.\n"
2189 + params.preamble + '\n';
2192 preamble += "\\makeatother\n";
2194 // Itemize bullet settings need to be last in case the user
2195 // defines their own bullets that use a package included
2196 // in the user-defined preamble -- ARRae
2197 // Actually it has to be done much later than that
2198 // since some packages like frenchb make modifications
2199 // at \begin{document} time -- JMarc
2201 for (int i = 0; i < 4; ++i) {
2202 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
2203 if (bullets_def.empty())
2204 bullets_def="\\AtBeginDocument{\n";
2205 bullets_def += " \\renewcommand{\\labelitemi";
2207 // `i' is one less than the item to modify
2214 bullets_def += "ii";
2220 bullets_def += "}{" +
2221 params.user_defined_bullets[i].getText()
2226 if (!bullets_def.empty())
2227 preamble += bullets_def + "}\n\n";
2229 for (int j = countChar(preamble, '\n'); j-- ;) {
2236 ofs << "\\begin{document}\n";
2239 lyxerr.debug() << "preamble finished, now the body." << endl;
2240 if (!lyxrc.language_auto_begin && params.language != "default") {
2241 ofs << subst(lyxrc.language_command_begin, "$$lang",
2247 latexParagraphs(ofs, paragraph, 0, texrow);
2249 // add this just in case after all the paragraphs
2253 if (!lyxrc.language_auto_end && params.language != "default") {
2254 ofs << subst(lyxrc.language_command_end, "$$lang",
2261 ofs << "\\end{document}\n";
2264 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
2266 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
2270 // Just to be sure. (Asger)
2273 // tex_code_break_column's value is used to decide
2274 // if we are in batchmode or not (within mathed_write()
2275 // in math_write.C) so we must set it to a non-zero
2276 // value when we leave otherwise we save incorrect .lyx files.
2277 tex_code_break_column = lyxrc.ascii_linelen;
2281 lyxerr << "File was not closed properly." << endl;
2284 lyxerr.debug() << "Finished making latex file." << endl;
2289 // LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
2291 void Buffer::latexParagraphs(ostream & ofs, LyXParagraph * par,
2292 LyXParagraph * endpar, TexRow & texrow) const
2294 bool was_title = false;
2295 bool already_title = false;
2297 std::ostringstream ftnote;
2299 char * tmpholder = 0;
2305 while (par != endpar) {
2306 #ifndef HAVE_SSTREAM
2309 ftnote << tmpholder;
2310 delete [] tmpholder;
2316 lyxerr[Debug::LATEX] << "Error in latexParagraphs."
2319 LyXLayout const & layout =
2320 textclasslist.Style(params.textclass,
2323 if (layout.intitle) {
2324 if (already_title) {
2325 lyxerr <<"Error in latexParagraphs: You"
2326 " should not mix title layouts"
2327 " with normal ones." << endl;
2330 } else if (was_title && !already_title) {
2331 ofs << "\\maketitle\n";
2333 already_title = true;
2336 // We are at depth 0 so we can just use
2337 // ordinary \footnote{} generation
2338 // flag this with ftcount
2340 if (layout.isEnvironment()
2341 || par->pextra_type != LyXParagraph::PEXTRA_NONE) {
2342 par = par->TeXEnvironment(this, params, ofs, texrow
2344 ,ftnote, ft_texrow, ftcount
2348 par = par->TeXOnePar(this, params, ofs, texrow, false
2351 ftnote, ft_texrow, ftcount
2356 // Write out what we've generated...
2359 ofs << "\\addtocounter{footnote}{-"
2363 ofs << ftnote.str();
2364 texrow += ft_texrow;
2366 // The extra .c_str() is needed when we use
2367 // lyxstring instead of the STL string class.
2368 ftnote.str(string().c_str());
2370 delete [] ftnote.str();
2375 #ifndef HAVE_SSTREAM
2377 // I hate strstreams
2378 tmpholder = ftnote.str();
2382 #ifndef HAVE_SSTREAM
2383 delete [] tmpholder;
2385 // It might be that we only have a title in this document
2386 if (was_title && !already_title) {
2387 ofs << "\\maketitle\n";
2393 bool Buffer::isLatex() const
2395 return textclasslist.TextClass(params.textclass).outputType() == LATEX;
2399 bool Buffer::isLinuxDoc() const
2401 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC;
2405 bool Buffer::isLiterate() const
2407 return textclasslist.TextClass(params.textclass).outputType() == LITERATE;
2411 bool Buffer::isDocBook() const
2413 return textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2417 bool Buffer::isSGML() const
2419 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC ||
2420 textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2424 void Buffer::sgmlOpenTag(ostream & os, int depth,
2425 string const & latexname) const
2427 os << string(depth, ' ') << "<" << latexname << ">\n";
2431 void Buffer::sgmlCloseTag(ostream & os, int depth,
2432 string const & latexname) const
2434 os << string(depth, ' ') << "</" << latexname << ">\n";
2438 void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
2440 LyXParagraph * par = paragraph;
2442 niceFile = nice; // this will be used by Insetincludes.
2444 string top_element = textclasslist.LatexnameOfClass(params.textclass);
2445 string environment_stack[10];
2448 int depth = 0; // paragraph depth
2450 ofstream ofs(fname.c_str());
2453 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2457 LyXTextClass const & tclass =
2458 textclasslist.TextClass(params.textclass);
2460 LaTeXFeatures features(params, tclass.numLayouts());
2464 tex_code_break_column = lyxrc.ascii_linelen;
2466 //tex_code_break_column = 0;
2471 string sgml_includedfiles=features.getIncludedFiles();
2473 if (params.preamble.empty() && sgml_includedfiles.empty()) {
2474 ofs << "<!doctype linuxdoc system>\n\n";
2476 ofs << "<!doctype linuxdoc system [ "
2477 << params.preamble << sgml_includedfiles << " \n]>\n\n";
2480 if(params.options.empty())
2481 sgmlOpenTag(ofs, 0, top_element);
2483 string top = top_element;
2485 top += params.options;
2486 sgmlOpenTag(ofs, 0, top);
2490 ofs << "<!-- " << LYX_DOCVERSION
2491 << " created this file. For more info see http://www.lyx.org/"
2495 int desc_on = 0; // description mode
2496 LyXLayout const & style =
2497 textclasslist.Style(params.textclass,
2500 // treat <toc> as a special case for compatibility with old code
2501 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2502 Inset * inset = par->GetInset(0);
2503 Inset::Code lyx_code = inset->LyxCode();
2504 if (lyx_code == Inset::TOC_CODE){
2505 string temp = "toc";
2506 sgmlOpenTag(ofs, depth, temp);
2510 linuxDocHandleFootnote(ofs, par, depth);
2516 // environment tag closing
2517 for( ; depth > par->depth; --depth) {
2518 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2519 environment_stack[depth].erase();
2522 // write opening SGML tags
2523 switch(style.latextype) {
2524 case LATEX_PARAGRAPH:
2525 if(depth == par->depth
2526 && !environment_stack[depth].empty()) {
2527 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2528 environment_stack[depth].erase();
2534 sgmlOpenTag(ofs, depth, style.latexname());
2539 LinuxDocError(par, 0,
2540 _("Error : Wrong depth for"
2541 " LatexType Command.\n"));
2543 if (!environment_stack[depth].empty()){
2544 sgmlCloseTag(ofs, depth,
2545 environment_stack[depth]);
2549 environment_stack[depth].erase();
2550 sgmlOpenTag(ofs, depth, style.latexname());
2553 case LATEX_ENVIRONMENT:
2554 case LATEX_ITEM_ENVIRONMENT:
2555 if(depth == par->depth
2556 && environment_stack[depth] != style.latexname()
2557 && !environment_stack[depth].empty()) {
2559 sgmlCloseTag(ofs, depth,
2560 environment_stack[depth]);
2561 environment_stack[depth].erase();
2563 if (depth < par->depth) {
2565 environment_stack[depth].erase();
2567 if (environment_stack[depth] != style.latexname()) {
2570 sgmlOpenTag(ofs, depth, temp);
2572 environment_stack[depth] = style.latexname();
2573 sgmlOpenTag(ofs, depth,
2574 environment_stack[depth]);
2576 if(style.latextype == LATEX_ENVIRONMENT) break;
2578 desc_on = (style.labeltype == LABEL_MANUAL);
2585 sgmlOpenTag(ofs, depth + 1, item_name);
2588 sgmlOpenTag(ofs, depth, style.latexname());
2595 SimpleLinuxDocOnePar(ofs, par, desc_on, depth);
2599 linuxDocHandleFootnote(ofs, par, depth);
2601 while(par && par->IsDummy());
2605 // write closing SGML tags
2606 switch(style.latextype) {
2608 case LATEX_ENVIRONMENT:
2609 case LATEX_ITEM_ENVIRONMENT:
2612 sgmlCloseTag(ofs, depth, style.latexname());
2618 for(; depth > 0; --depth)
2619 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2621 if(!environment_stack[depth].empty())
2622 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2626 sgmlCloseTag(ofs, 0, top_element);
2630 // How to check for successful close
2635 void Buffer::linuxDocHandleFootnote(ostream & os, LyXParagraph * & par,
2638 string tag = "footnote";
2640 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2641 sgmlOpenTag(os, depth + 1, tag);
2642 SimpleLinuxDocOnePar(os, par, 0, depth + 1);
2643 sgmlCloseTag(os, depth + 1, tag);
2650 void Buffer::DocBookHandleCaption(ostream & os, string & inner_tag,
2651 int const depth, int desc_on,
2652 LyXParagraph * & par)
2654 LyXParagraph * tpar = par;
2657 && (tpar->footnoteflag != LyXParagraph::NO_FOOTNOTE)
2659 && (tpar->layout != textclasslist.NumberOfLayout(params.textclass,
2663 tpar->layout == textclasslist.NumberOfLayout(params.textclass,
2664 "Caption").second) {
2665 sgmlOpenTag(os, depth + 1, inner_tag);
2667 SimpleDocBookOnePar(os, extra_par, tpar,
2668 desc_on, depth + 2);
2669 sgmlCloseTag(os, depth+1, inner_tag);
2670 if(!extra_par.empty())
2677 void Buffer::DocBookHandleFootnote(ostream & os, LyXParagraph * & par,
2680 string tag, inner_tag;
2681 string tmp_par, extra_par;
2682 bool inner_span = false;
2685 // Someone should give this enum a proper name (Lgb)
2693 SOME_ENUM last = NO_ONE;
2694 SOME_ENUM present = FOOTNOTE_LIKE;
2696 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2697 if(last == present) {
2699 if(!tmp_par.empty()) {
2702 sgmlCloseTag(os, depth + 1, inner_tag);
2703 sgmlOpenTag(os, depth + 1, inner_tag);
2710 if(!inner_tag.empty()) sgmlCloseTag(os, depth + 1,
2712 if(!extra_par.empty()) os << extra_par;
2713 if(!tag.empty()) sgmlCloseTag(os, depth, tag);
2716 switch (par->footnotekind) {
2717 case LyXParagraph::FOOTNOTE:
2718 case LyXParagraph::ALGORITHM:
2721 present = FOOTNOTE_LIKE;
2724 case LyXParagraph::MARGIN:
2727 present = MARGIN_LIKE;
2730 case LyXParagraph::FIG:
2731 case LyXParagraph::WIDE_FIG:
2733 inner_tag = "title";
2737 case LyXParagraph::TAB:
2738 case LyXParagraph::WIDE_TAB:
2740 inner_tag = "title";
2745 sgmlOpenTag(os, depth, tag);
2746 if ((present == TAB_LIKE) || (present == FIG_LIKE)) {
2747 DocBookHandleCaption(os, inner_tag, depth,
2751 sgmlOpenTag(os, depth + 1, inner_tag);
2754 // ignore all caption here, we processed them above!!!
2755 if (par->layout != textclasslist
2756 .NumberOfLayout(params.textclass,
2757 "Caption").second) {
2759 std::ostringstream ost;
2763 SimpleDocBookOnePar(ost, extra_par, par,
2764 desc_on, depth + 2);
2766 tmp_par += ost.str().c_str();
2769 char * ctmp = ost.str();
2774 tmp_par = frontStrip(strip(tmp_par));
2780 if(!inner_tag.empty()) sgmlCloseTag(os, depth + 1, inner_tag);
2781 if(!extra_par.empty()) os << extra_par;
2782 if(!tag.empty()) sgmlCloseTag(os, depth, tag);
2787 // push a tag in a style stack
2788 void Buffer::push_tag(ostream & os, char const * tag,
2789 int & pos, char stack[5][3])
2791 // pop all previous tags
2792 for (int j = pos; j >= 0; --j)
2793 os << "</" << stack[j] << ">";
2796 sprintf(stack[++pos], "%s", tag);
2799 for (int i = 0; i <= pos; ++i)
2800 os << "<" << stack[i] << ">";
2804 void Buffer::pop_tag(ostream & os, char const * tag,
2805 int & pos, char stack[5][3])
2809 // pop all tags till specified one
2810 for (j = pos; (j >= 0) && (strcmp(stack[j], tag)); --j)
2811 os << "</" << stack[j] << ">";
2814 os << "</" << tag << ">";
2816 // push all tags, but the specified one
2817 for (j = j + 1; j <= pos; ++j) {
2818 os << "<" << stack[j] << ">";
2819 strcpy(stack[j-1], stack[j]);
2825 // Handle internal paragraph parsing -- layout already processed.
2827 // checks, if newcol chars should be put into this line
2828 // writes newline, if necessary.
2830 void linux_doc_line_break(ostream & os, unsigned int & colcount,
2831 const unsigned int newcol)
2834 if (colcount > lyxrc.ascii_linelen) {
2836 colcount = newcol; // assume write after this call
2841 void Buffer::SimpleLinuxDocOnePar(ostream & os, LyXParagraph * par,
2842 int desc_on, int const /*depth*/)
2844 LyXFont font1, font2;
2847 LyXParagraph::size_type main_body;
2849 LyXLayout const & style = textclasslist.Style(params.textclass,
2852 char family_type = 0; // family font flag
2853 bool is_bold = false; // series font flag
2854 char shape_type = 0; // shape font flag
2855 bool is_em = false; // emphasis (italic) font flag
2857 int stack_num = -1; // style stack position
2858 // Can this be rewritten to use a std::stack, please. (Lgb)
2859 char stack[5][3]; // style stack
2860 unsigned int char_line_count = 5; // Heuristic choice ;-)
2862 if (style.labeltype != LABEL_MANUAL)
2865 main_body = par->BeginningOfMainBody();
2867 // gets paragraph main font
2869 font1 = style.labelfont;
2874 // parsing main loop
2875 for (LyXParagraph::size_type i = 0;
2876 i < par->size(); ++i) {
2888 font2 = par->getFont(params, i);
2890 if (font1.family() != font2.family()) {
2891 switch(family_type) {
2893 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2894 push_tag(os, "tt", stack_num, stack);
2897 else if (font2.family() == LyXFont::SANS_FAMILY) {
2898 push_tag(os, "sf", stack_num, stack);
2903 pop_tag(os, "tt", stack_num, stack);
2904 if (font2.family() == LyXFont::SANS_FAMILY) {
2905 push_tag(os, "sf", stack_num, stack);
2912 pop_tag(os, "sf", stack_num, stack);
2913 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2914 push_tag(os, "tt", stack_num, stack);
2923 if (font1.series() != font2.series()) {
2924 if (font2.series() == LyXFont::BOLD_SERIES) {
2925 push_tag(os, "bf", stack_num, stack);
2927 } else if (is_bold) {
2928 pop_tag(os, "bf", stack_num, stack);
2933 // handle italic and slanted fonts
2934 if (font1.shape() != font2.shape()) {
2935 switch(shape_type) {
2937 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2938 push_tag(os, "it", stack_num, stack);
2940 } else if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2941 push_tag(os, "sl", stack_num, stack);
2946 pop_tag(os, "it", stack_num, stack);
2947 if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2948 push_tag(os, "sl", stack_num, stack);
2955 pop_tag(os, "sl", stack_num, stack);
2956 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2957 push_tag(os, "it", stack_num, stack);
2965 if (font1.emph() != font2.emph()) {
2966 if (font2.emph() == LyXFont::ON) {
2967 push_tag(os, "em", stack_num, stack);
2970 pop_tag(os, "em", stack_num, stack);
2975 c = par->GetChar(i);
2977 if (c == LyXParagraph::META_INSET) {
2978 inset = par->GetInset(i);
2979 inset->Linuxdoc(this, os);
2982 if (font2.latex() == LyXFont::ON) {
2983 // "TeX"-Mode on == > SGML-Mode on.
2985 os << c; // see LaTeX-Generation...
2989 if (par->linuxDocConvertChar(c, sgml_string)
2990 && !style.free_spacing) { // in freespacing
2992 // non-breaking characters
2996 linux_doc_line_break(os, char_line_count, 6);
3000 linux_doc_line_break(os, char_line_count, 1);
3005 char_line_count += sgml_string.length();
3011 // needed if there is an optional argument but no contents
3012 if (main_body > 0 && main_body == par->size()) {
3016 // pop all defined Styles
3017 for (j = stack_num; j >= 0; --j) {
3018 linux_doc_line_break(os,
3020 3 + strlen(stack[j]));
3021 os << "</" << stack[j] << ">";
3024 // resets description flag correctly
3027 // <tag> not closed...
3028 linux_doc_line_break(os, char_line_count, 6);
3032 // fprintf(file, "</p>");
3038 // Print an error message.
3039 void Buffer::LinuxDocError(LyXParagraph * par, int pos,
3040 char const * message)
3042 // insert an error marker in text
3043 InsetError * new_inset = new InsetError(message);
3044 par->InsertInset(pos, new_inset);
3047 // This constant defines the maximum number of
3048 // environment layouts that can be nesteded.
3049 // The same applies for command layouts.
3050 // These values should be more than enough.
3051 // José Matos (1999/07/22)
3053 enum { MAX_NEST_LEVEL = 25};
3055 void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
3057 LyXParagraph * par = paragraph;
3059 niceFile = nice; // this will be used by Insetincludes.
3061 string top_element= textclasslist.LatexnameOfClass(params.textclass);
3062 // Please use a real stack.
3063 string environment_stack[MAX_NEST_LEVEL];
3064 string environment_inner[MAX_NEST_LEVEL];
3065 // Please use a real stack.
3066 string command_stack[MAX_NEST_LEVEL];
3067 bool command_flag= false;
3068 int command_depth= 0, command_base= 0, cmd_depth= 0;
3070 string item_name, command_name;
3071 string c_depth, c_params, tmps;
3073 int depth = 0; // paragraph depth
3074 LyXTextClass const & tclass =
3075 textclasslist.TextClass(params.textclass);
3077 LaTeXFeatures features(params, tclass.numLayouts());
3081 tex_code_break_column = lyxrc.ascii_linelen;
3083 //tex_code_break_column = 0;
3085 ofstream ofs(fname.c_str());
3087 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
3094 string sgml_includedfiles=features.getIncludedFiles();
3096 ofs << "<!doctype " << top_element
3097 << " public \"-//OASIS//DTD DocBook V3.1//EN\"";
3099 if (params.preamble.empty() && sgml_includedfiles.empty())
3102 ofs << "\n [ " << params.preamble
3103 << sgml_includedfiles << " \n]>\n\n";
3105 if(params.options.empty())
3106 sgmlOpenTag(ofs, 0, top_element);
3108 string top = top_element;
3110 top += params.options;
3111 sgmlOpenTag(ofs, 0, top);
3115 ofs << "<!-- DocBook file was created by " << LYX_DOCVERSION
3116 << "\n See http://www.lyx.org/ for more information -->\n";
3119 int desc_on = 0; // description mode
3120 LyXLayout const & style =
3121 textclasslist.Style(params.textclass,
3124 // environment tag closing
3125 for( ; depth > par->depth; --depth) {
3126 if(environment_inner[depth] != "!-- --") {
3127 item_name= "listitem";
3128 sgmlCloseTag(ofs, command_depth + depth,
3130 if( environment_inner[depth] == "varlistentry")
3131 sgmlCloseTag(ofs, depth+command_depth,
3132 environment_inner[depth]);
3134 sgmlCloseTag(ofs, depth + command_depth,
3135 environment_stack[depth]);
3136 environment_stack[depth].erase();
3137 environment_inner[depth].erase();
3140 if(depth == par->depth
3141 && environment_stack[depth] != style.latexname()
3142 && !environment_stack[depth].empty()) {
3143 if(environment_inner[depth] != "!-- --") {
3144 item_name= "listitem";
3145 sgmlCloseTag(ofs, command_depth+depth,
3147 if( environment_inner[depth] == "varlistentry")
3149 depth + command_depth,
3150 environment_inner[depth]);
3153 sgmlCloseTag(ofs, depth + command_depth,
3154 environment_stack[depth]);
3156 environment_stack[depth].erase();
3157 environment_inner[depth].erase();
3160 // Write opening SGML tags.
3161 switch(style.latextype) {
3162 case LATEX_PARAGRAPH:
3163 if(style.latexname() != "dummy")
3164 sgmlOpenTag(ofs, depth+command_depth,
3170 LinuxDocError(par, 0,
3171 _("Error : Wrong depth for "
3172 "LatexType Command.\n"));
3174 command_name = style.latexname();
3176 tmps = style.latexparam();
3177 c_params = split(tmps, c_depth,'|');
3179 cmd_depth= atoi(c_depth.c_str());
3182 if(cmd_depth<command_base) {
3183 for(int j = command_depth;
3184 j >= command_base; --j)
3185 if(!command_stack[j].empty())
3186 sgmlCloseTag(ofs, j, command_stack[j]);
3187 command_depth= command_base= cmd_depth;
3188 } else if(cmd_depth <= command_depth) {
3189 for(int j = command_depth;
3190 j >= cmd_depth; --j)
3192 if(!command_stack[j].empty())
3193 sgmlCloseTag(ofs, j, command_stack[j]);
3194 command_depth= cmd_depth;
3196 command_depth= cmd_depth;
3198 command_depth = command_base = cmd_depth;
3199 command_flag = true;
3201 command_stack[command_depth]= command_name;
3203 // treat label as a special case for
3204 // more WYSIWYM handling.
3205 if (par->GetChar(0) == LyXParagraph::META_INSET) {
3206 Inset * inset = par->GetInset(0);
3207 Inset::Code lyx_code = inset->LyxCode();
3208 if (lyx_code == Inset::LABEL_CODE){
3209 command_name += " id=\"";
3210 command_name += (static_cast<InsetCommand *>(inset))->getContents();
3211 command_name += "\"";
3216 sgmlOpenTag(ofs, depth + command_depth, command_name);
3217 item_name = "title";
3218 sgmlOpenTag(ofs, depth + 1 + command_depth, item_name);
3221 case LATEX_ENVIRONMENT:
3222 case LATEX_ITEM_ENVIRONMENT:
3223 if (depth < par->depth) {
3225 environment_stack[depth].erase();
3228 if (environment_stack[depth] != style.latexname()) {
3229 environment_stack[depth] = style.latexname();
3230 environment_inner[depth] = "!-- --";
3231 sgmlOpenTag(ofs, depth + command_depth,
3232 environment_stack[depth]);
3234 if(environment_inner[depth] != "!-- --") {
3235 item_name= "listitem";
3237 command_depth + depth,
3239 if (environment_inner[depth] == "varlistentry")
3241 depth + command_depth,
3242 environment_inner[depth]);
3246 if(style.latextype == LATEX_ENVIRONMENT) {
3247 if(!style.latexparam().empty())
3248 sgmlOpenTag(ofs, depth + command_depth,
3249 style.latexparam());
3253 desc_on = (style.labeltype == LABEL_MANUAL);
3256 environment_inner[depth]= "varlistentry";
3258 environment_inner[depth]= "listitem";
3260 sgmlOpenTag(ofs, depth + 1 + command_depth,
3261 environment_inner[depth]);
3265 sgmlOpenTag(ofs, depth + 1 + command_depth,
3269 sgmlOpenTag(ofs, depth + 1 + command_depth,
3274 sgmlOpenTag(ofs, depth + command_depth,
3283 SimpleDocBookOnePar(ofs, extra_par, par, desc_on,
3284 depth + 1 + command_depth);
3287 DocBookHandleFootnote(ofs, par,
3288 depth + 1 + command_depth);
3290 while(par && par->IsDummy());
3293 // write closing SGML tags
3294 switch(style.latextype) {
3297 sgmlCloseTag(ofs, depth + command_depth, end_tag);
3299 case LATEX_ENVIRONMENT:
3300 if(!style.latexparam().empty())
3301 sgmlCloseTag(ofs, depth + command_depth,
3302 style.latexparam());
3304 case LATEX_ITEM_ENVIRONMENT:
3305 if(desc_on == 1) break;
3307 sgmlCloseTag(ofs, depth + 1 + command_depth, end_tag);
3309 case LATEX_PARAGRAPH:
3310 if(style.latexname() != "dummy")
3311 sgmlCloseTag(ofs, depth + command_depth,
3315 sgmlCloseTag(ofs, depth + command_depth,
3322 for(; depth >= 0; --depth) {
3323 if(!environment_stack[depth].empty()) {
3324 if(environment_inner[depth] != "!-- --") {
3325 item_name= "listitem";
3326 sgmlCloseTag(ofs, command_depth + depth,
3328 if( environment_inner[depth] == "varlistentry")
3329 sgmlCloseTag(ofs, depth + command_depth,
3330 environment_inner[depth]);
3333 sgmlCloseTag(ofs, depth + command_depth,
3334 environment_stack[depth]);
3338 for(int j = command_depth; j >= command_base; --j)
3339 if(!command_stack[j].empty())
3340 sgmlCloseTag(ofs, j, command_stack[j]);
3344 sgmlCloseTag(ofs, 0, top_element);
3348 // How to check for successful close
3352 void Buffer::SimpleDocBookOnePar(ostream & os, string & extra,
3353 LyXParagraph * par, int & desc_on,
3358 par->SimpleDocBookOneTablePar(this,
3359 os, extra, desc_on, depth);
3364 bool emph_flag = false;
3366 LyXLayout const & style = textclasslist.Style(params.textclass,
3369 LyXParagraph::size_type main_body;
3370 if (style.labeltype != LABEL_MANUAL)
3373 main_body = par->BeginningOfMainBody();
3375 // gets paragraph main font
3376 LyXFont font1 = main_body > 0 ? style.labelfont : style.font;
3378 int char_line_count = depth;
3379 if(!style.free_spacing)
3380 for (int j = 0; j < depth; ++j)
3383 // parsing main loop
3384 for (LyXParagraph::size_type i = 0;
3385 i < par->size(); ++i) {
3386 LyXFont font2 = par->getFont(params, i);
3388 // handle <emphasis> tag
3389 if (font1.emph() != font2.emph() && i) {
3390 if (font2.emph() == LyXFont::ON) {
3394 os << "</emphasis>";
3399 char c = par->GetChar(i);
3401 if (c == LyXParagraph::META_INSET) {
3402 Inset * inset = par->GetInset(i);
3404 std::ostringstream ost;
3405 inset->DocBook(this, ost);
3406 string tmp_out = ost.str().c_str();
3409 inset->DocBook(this, ost);
3411 char * ctmp = ost.str();
3412 string tmp_out(ctmp);
3416 // This code needs some explanation:
3417 // Two insets are treated specially
3418 // label if it is the first element in a command paragraph
3420 // graphics inside tables or figure floats can't go on
3421 // title (the equivalente in latex for this case is caption
3422 // and title should come first
3425 if(desc_on!= 3 || i!= 0) {
3426 if(!tmp_out.empty() && tmp_out[0] == '@') {
3428 extra += frontStrip(tmp_out, '@');
3430 os << frontStrip(tmp_out, '@');
3435 } else if (font2.latex() == LyXFont::ON) {
3436 // "TeX"-Mode on ==> SGML-Mode on.
3442 if (par->linuxDocConvertChar(c, sgml_string)
3443 && !style.free_spacing) { // in freespacing
3445 // non-breaking characters
3449 os << "\n</term><listitem><para>";
3461 // needed if there is an optional argument but no contents
3462 if (main_body > 0 && main_body == par->size()) {
3466 os << "</emphasis>";
3469 // resets description flag correctly
3472 // <term> not closed...
3480 int Buffer::runLaTeX()
3482 if (!users->text) return 0;
3484 ProhibitInput(users);
3486 // get LaTeX-Filename
3487 string name = getLatexName();
3489 string path = OnlyPath(filename);
3491 string org_path = path;
3492 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3496 Path p(path); // path to LaTeX file
3497 users->owner()->getMiniBuffer()->Set(_("Running LaTeX..."));
3499 // Remove all error insets
3500 bool a = users->removeAutoInsets();
3502 // Always generate the LaTeX file
3503 makeLaTeXFile(name, org_path, false);
3505 // do the LaTex run(s)
3507 string latex_command = lyxrc.pdf_mode ?
3508 lyxrc.pdflatex_command : lyxrc.latex_command;
3509 LaTeX latex(latex_command, name, filepath);
3510 int res = latex.run(terr,
3511 users->owner()->getMiniBuffer()); // running latex
3513 // check return value from latex.run().
3514 if ((res & LaTeX::NO_LOGFILE)) {
3515 WriteAlert(_("LaTeX did not work!"),
3516 _("Missing log file:"), name);
3517 } else if ((res & LaTeX::ERRORS)) {
3518 users->owner()->getMiniBuffer()->Set(_("Done"));
3519 // Insert all errors as errors boxes
3520 users->insertErrors(terr);
3522 // Dvi should also be kept dirty if the latex run
3523 // ends up with errors. However it should be possible
3524 // to view a dirty dvi too.
3526 //no errors or any other things to think about so:
3527 users->owner()->getMiniBuffer()->Set(_("Done"));
3530 // if we removed error insets before we ran LaTeX or if we inserted
3531 // error insets after we ran LaTeX this must be run:
3532 if (a || (res & LaTeX::ERRORS)){
3535 //users->updateScrollbar();
3539 return latex.getNumErrors();
3543 int Buffer::runLiterate()
3545 if (!users->text) return 0;
3547 ProhibitInput(users);
3549 // get LaTeX-Filename
3550 string name = getLatexName();
3551 // get Literate-Filename
3552 string lit_name = OnlyFilename(ChangeExtension (getLatexName(),
3553 lyxrc.literate_extension));
3555 string path = OnlyPath(filename);
3557 string org_path = path;
3558 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3562 Path p(path); // path to Literate file
3563 users->owner()->getMiniBuffer()->Set(_("Running Literate..."));
3565 // Remove all error insets
3566 bool a = users->removeAutoInsets();
3568 // generate the Literate file if necessary
3569 makeLaTeXFile(lit_name, org_path, false);
3571 string latex_command = lyxrc.pdf_mode ?
3572 lyxrc.pdflatex_command : lyxrc.latex_command;
3573 Literate literate(latex_command, name, filepath,
3575 lyxrc.literate_command, lyxrc.literate_error_filter,
3576 lyxrc.build_command, lyxrc.build_error_filter);
3578 int res = literate.weave(terr, users->owner()->getMiniBuffer());
3580 // check return value from literate.weave().
3581 if ((res & Literate::NO_LOGFILE)) {
3582 WriteAlert(_("Literate command did not work!"),
3583 _("Missing log file:"), name);
3584 } else if ((res & Literate::ERRORS)) {
3585 users->owner()->getMiniBuffer()->Set(_("Done"));
3586 // Insert all errors as errors boxes
3587 users->insertErrors(terr);
3589 // Dvi should also be kept dirty if the latex run
3590 // ends up with errors. However it should be possible
3591 // to view a dirty dvi too.
3593 //no errors or any other things to think about so:
3594 users->owner()->getMiniBuffer()->Set(_("Done"));
3597 // if we removed error insets before we ran LaTeX or if we inserted
3598 // error insets after we ran LaTeX this must be run:
3599 if (a || (res & Literate::ERRORS)){
3602 //users->updateScrollbar();
3606 return literate.getNumErrors();
3610 int Buffer::buildProgram()
3612 if (!users->text) return 0;
3614 ProhibitInput(users);
3616 // get LaTeX-Filename
3617 string name = getLatexName();
3618 // get Literate-Filename
3619 string lit_name = OnlyFilename(ChangeExtension(getLatexName(),
3620 lyxrc.literate_extension));
3622 string path = OnlyPath(filename);
3624 string org_path = path;
3625 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3629 Path p(path); // path to Literate file
3630 users->owner()->getMiniBuffer()->Set(_("Building Program..."));
3632 // Remove all error insets
3633 bool a = users->removeAutoInsets();
3635 // generate the LaTeX file if necessary
3636 if (!isNwClean() || a) {
3637 makeLaTeXFile(lit_name, org_path, false);
3641 string latex_command = lyxrc.pdf_mode ?
3642 lyxrc.pdflatex_command : lyxrc.latex_command;
3643 Literate literate(latex_command, name, filepath,
3645 lyxrc.literate_command, lyxrc.literate_error_filter,
3646 lyxrc.build_command, lyxrc.build_error_filter);
3648 int res = literate.build(terr, users->owner()->getMiniBuffer());
3650 // check return value from literate.build().
3651 if ((res & Literate::NO_LOGFILE)) {
3652 WriteAlert(_("Build did not work!"),
3653 _("Missing log file:"), name);
3654 } else if ((res & Literate::ERRORS)) {
3655 users->owner()->getMiniBuffer()->Set(_("Done"));
3656 // Insert all errors as errors boxes
3657 users->insertErrors(terr);
3659 // Literate files should also be kept dirty if the literate
3660 // command run ends up with errors.
3662 //no errors or any other things to think about so:
3663 users->owner()->getMiniBuffer()->Set(_("Done"));
3667 // if we removed error insets before we ran Literate/Build or
3668 // if we inserted error insets after we ran Literate/Build this
3670 if (a || (res & Literate::ERRORS)){
3673 //users->updateScrollbar();
3677 return literate.getNumErrors();
3681 // This should be enabled when the Chktex class is implemented. (Asger)
3682 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
3683 // Other flags: -wall -v0 -x
3684 int Buffer::runChktex()
3686 if (!users->text) return 0;
3688 ProhibitInput(users);
3690 // get LaTeX-Filename
3691 string name = getLatexName();
3692 string path = OnlyPath(filename);
3694 string org_path = path;
3695 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3699 Path p(path); // path to LaTeX file
3700 users->owner()->getMiniBuffer()->Set(_("Running chktex..."));
3702 // Remove all error insets
3703 bool removedErrorInsets = users->removeAutoInsets();
3705 // Generate the LaTeX file if neccessary
3706 makeLaTeXFile(name, org_path, false);
3709 Chktex chktex(lyxrc.chktex_command, name, filepath);
3710 int res = chktex.run(terr); // run chktex
3713 WriteAlert(_("chktex did not work!"),
3714 _("Could not run with file:"), name);
3715 } else if (res > 0) {
3716 // Insert all errors as errors boxes
3717 users->insertErrors(terr);
3720 // if we removed error insets before we ran chktex or if we inserted
3721 // error insets after we ran chktex, this must be run:
3722 if (removedErrorInsets || res){
3725 //users->updateScrollbar();
3733 void Buffer::validate(LaTeXFeatures & features) const
3735 LyXParagraph * par = paragraph;
3736 LyXTextClass const & tclass =
3737 textclasslist.TextClass(params.textclass);
3739 // AMS Style is at document level
3741 features.amsstyle = (params.use_amsmath ||
3742 tclass.provides(LyXTextClass::amsmath));
3745 // We don't use "lyxerr.debug" because of speed. (Asger)
3746 if (lyxerr.debugging(Debug::LATEX))
3747 lyxerr << "Paragraph: " << par << endl;
3749 // Now just follow the list of paragraphs and run
3750 // validate on each of them.
3751 par->validate(features);
3753 // and then the next paragraph
3757 // the bullet shapes are buffer level not paragraph level
3758 // so they are tested here
3759 for (int i = 0; i < 4; ++i) {
3760 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
3761 int font = params.user_defined_bullets[i].getFont();
3764 .user_defined_bullets[i]
3771 features.latexsym = true;
3775 features.amssymb = true;
3777 else if ((font >= 2 && font <= 5)) {
3778 features.pifont = true;
3783 if (lyxerr.debugging(Debug::LATEX)) {
3784 features.showStruct();
3789 void Buffer::setPaperStuff()
3791 params.papersize = BufferParams::PAPER_DEFAULT;
3792 char c1 = params.paperpackage;
3793 if (c1 == BufferParams::PACKAGE_NONE) {
3794 char c2 = params.papersize2;
3795 if (c2 == BufferParams::VM_PAPER_USLETTER)
3796 params.papersize = BufferParams::PAPER_USLETTER;
3797 else if (c2 == BufferParams::VM_PAPER_USLEGAL)
3798 params.papersize = BufferParams::PAPER_LEGALPAPER;
3799 else if (c2 == BufferParams::VM_PAPER_USEXECUTIVE)
3800 params.papersize = BufferParams::PAPER_EXECUTIVEPAPER;
3801 else if (c2 == BufferParams::VM_PAPER_A3)
3802 params.papersize = BufferParams::PAPER_A3PAPER;
3803 else if (c2 == BufferParams::VM_PAPER_A4)
3804 params.papersize = BufferParams::PAPER_A4PAPER;
3805 else if (c2 == BufferParams::VM_PAPER_A5)
3806 params.papersize = BufferParams::PAPER_A5PAPER;
3807 else if ((c2 == BufferParams::VM_PAPER_B3) || (c2 == BufferParams::VM_PAPER_B4) ||
3808 (c2 == BufferParams::VM_PAPER_B5))
3809 params.papersize = BufferParams::PAPER_B5PAPER;
3810 } else if ((c1 == BufferParams::PACKAGE_A4) || (c1 == BufferParams::PACKAGE_A4WIDE) ||
3811 (c1 == BufferParams::PACKAGE_WIDEMARGINSA4))
3812 params.papersize = BufferParams::PAPER_A4PAPER;
3816 // This function should be in Buffer because it's a buffer's property (ale)
3817 string Buffer::getIncludeonlyList(char delim)
3820 for (inset_iterator it = inset_iterator_begin();
3821 it != inset_iterator_end(); ++it) {
3822 if ((*it)->LyxCode() == Inset::INCLUDE_CODE) {
3823 InsetInclude * insetinc =
3824 static_cast<InsetInclude *>(*it);
3825 if (insetinc->isInclude()
3826 && insetinc->isNoLoad()) {
3829 lst += OnlyFilename(ChangeExtension(insetinc->getContents(), string()));
3833 lyxerr.debug() << "Includeonly(" << lst << ')' << endl;
3838 vector<string> Buffer::getLabelList()
3840 /// if this is a child document and the parent is already loaded
3841 /// Use the parent's list instead [ale990407]
3842 if (!params.parentname.empty()
3843 && bufferlist.exists(params.parentname)) {
3844 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3846 return tmp->getLabelList();
3849 vector<string> label_list;
3850 for (inset_iterator it = inset_iterator_begin();
3851 it != inset_iterator_end(); ++it) {
3852 vector<string> l = (*it)->getLabelList();
3853 label_list.insert(label_list.end(), l.begin(), l.end());
3859 vector<vector<Buffer::TocItem> > Buffer::getTocList()
3861 vector<vector<TocItem> > l(4);
3862 LyXParagraph * par = paragraph;
3865 if (par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
3866 if (textclasslist.Style(params.textclass,
3867 par->GetLayout()).labeltype
3868 == LABEL_SENSITIVE) {
3872 tmp.str = par->String(this, false);
3873 switch (par->footnotekind) {
3874 case LyXParagraph::FIG:
3875 case LyXParagraph::WIDE_FIG:
3876 l[TOC_LOF].push_back(tmp);
3878 case LyXParagraph::TAB:
3879 case LyXParagraph::WIDE_TAB:
3880 l[TOC_LOT].push_back(tmp);
3882 case LyXParagraph::ALGORITHM:
3883 l[TOC_LOA].push_back(tmp);
3885 case LyXParagraph::FOOTNOTE:
3886 case LyXParagraph::MARGIN:
3890 } else if (!par->IsDummy()) {
3892 char labeltype = textclasslist.Style(params.textclass,
3893 par->GetLayout()).labeltype;
3895 if (labeltype >= LABEL_COUNTER_CHAPTER
3896 && labeltype <= LABEL_COUNTER_CHAPTER + params.tocdepth) {
3897 // insert this into the table of contents
3902 textclasslist.TextClass(params.textclass).maxcounter());
3903 tmp.str = par->String(this, true);
3904 l[TOC_TOC].push_back(tmp);
3914 // This is also a buffer property (ale)
3915 vector<pair<string,string> > Buffer::getBibkeyList()
3917 /// if this is a child document and the parent is already loaded
3918 /// Use the parent's list instead [ale990412]
3919 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3920 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3922 return tmp->getBibkeyList();
3925 vector<pair<string, string> > keys;
3926 LyXParagraph * par = paragraph;
3929 keys.push_back(pair<string, string>(par->bibkey->getContents(),
3930 par->String(this, false)));
3934 // Might be either using bibtex or a child has bibliography
3936 for (inset_iterator it = inset_iterator_begin();
3937 it != inset_iterator_end(); ++it) {
3938 // Search for Bibtex or Include inset
3939 if ((*it)->LyxCode() == Inset::BIBTEX_CODE) {
3940 vector<pair<string,string> > tmp =
3941 static_cast<InsetBibtex*>(*it)->getKeys();
3942 keys.insert(keys.end(), tmp.begin(), tmp.end());
3943 } else if ((*it)->LyxCode() == Inset::INCLUDE_CODE) {
3944 vector<pair<string,string> > tmp =
3945 static_cast<InsetInclude*>(*it)->getKeys();
3946 keys.insert(keys.end(), tmp.begin(), tmp.end());
3955 bool Buffer::isDepClean(string const & name) const
3957 DEPCLEAN * item = dep_clean;
3958 while (item && item->master != name)
3960 if (!item) return true;
3965 void Buffer::markDepClean(string const & name)
3968 dep_clean = new DEPCLEAN;
3969 dep_clean->clean = true;
3970 dep_clean->master = name;
3971 dep_clean->next = 0;
3973 DEPCLEAN* item = dep_clean;
3974 while (item && item->master != name)
3979 item = new DEPCLEAN;
3981 item->master = name;
3988 bool Buffer::Dispatch(string const & command)
3990 // Split command string into command and argument
3991 string cmd, line = frontStrip(command);
3992 string arg = strip(frontStrip(split(line, cmd, ' ')));
3994 return Dispatch(lyxaction.LookupFunc(cmd.c_str()), arg.c_str());
3998 bool Buffer::Dispatch(int action, string const & argument)
4000 bool dispatched = true;
4003 MenuExport(this, argument);
4013 void Buffer::resize()
4015 /// resize the BufferViews!
4021 void Buffer::resizeInsets(BufferView * bv)
4023 /// then remove all LyXText in text-insets
4024 LyXParagraph * par = paragraph;
4025 for(;par;par = par->next) {
4026 par->resizeInsetsLyXText(bv);
4030 void Buffer::ChangeLanguage(Language const * from, Language const * to)
4033 LyXParagraph * par = paragraph;
4035 par->ChangeLanguage(params, from, to);
4041 bool Buffer::isMultiLingual()
4044 LyXParagraph * par = paragraph;
4046 if (par->isMultiLingual(params))
4054 Buffer::inset_iterator::inset_iterator(LyXParagraph * paragraph,
4055 LyXParagraph::size_type pos)
4057 it = par->InsetIterator(pos);
4058 if (it == par->inset_iterator_end()) {
4065 void Buffer::inset_iterator::SetParagraph() {
4067 it = par->inset_iterator_begin();
4068 if (it != par->inset_iterator_end())
4073 // We maintain an invariant that whenever par = 0 then it = 0