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/insetparent.h"
60 #include "insets/insetspecialchar.h"
61 #include "insets/figinset.h"
62 #include "insets/insettext.h"
63 #include "insets/insetert.h"
64 #include "insets/insetgraphics.h"
65 #include "insets/insetfoot.h"
66 #include "insets/insetmarginal.h"
67 #include "insets/insetminipage.h"
68 #include "insets/insetfloat.h"
69 #include "insets/insetlist.h"
70 #include "insets/insettabular.h"
71 #include "insets/insettheorem.h"
72 #include "insets/insetcaption.h"
73 #include "support/filetools.h"
74 #include "support/path.h"
80 #include "LaTeXFeatures.h"
81 #include "support/syscall.h"
82 #include "support/lyxlib.h"
83 #include "support/FileInfo.h"
87 #include "lyx_gui_misc.h" // WarnReadonly()
88 #include "frontends/Dialogs.h"
103 using std::istringstream;
106 // all these externs should eventually be removed.
107 extern BufferList bufferlist;
109 extern void MenuExport(Buffer *, string const &);
110 extern LyXAction lyxaction;
113 static const float LYX_FORMAT = 2.16;
115 extern int tex_code_break_column;
118 Buffer::Buffer(string const & file, bool ronly)
120 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
122 filepath = OnlyPath(file);
131 if (read_only || (lyxrc.use_tempdir)) {
132 tmppath = CreateBufferTmpDir();
133 } else tmppath.erase();
139 lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
140 // here the buffer should take care that it is
141 // saved properly, before it goes into the void.
143 // make sure that views using this buffer
148 if (!tmppath.empty()) {
149 DestroyBufferTmpDir(tmppath);
152 LyXParagraph * par = paragraph;
153 LyXParagraph * tmppar;
163 string Buffer::getLatexName(bool no_path) const
166 return OnlyFilename(ChangeExtension(MakeLatexName(filename),
169 return ChangeExtension(MakeLatexName(filename),
174 void Buffer::setReadonly(bool flag)
176 if (read_only != flag) {
179 users->owner()->getDialogs()->updateBufferDependent();
182 WarnReadonly(filename);
187 bool Buffer::saveParamsAsDefaults()
189 string fname = AddName(AddPath(user_lyxdir, "templates/"),
191 Buffer defaults = Buffer(fname);
193 // Use the current buffer's parameters as default
194 defaults.params = params;
196 // add an empty paragraph. Is this enough?
197 defaults.paragraph = new LyXParagraph;
199 return defaults.writeFile(defaults.filename, false);
203 /// Update window titles of all users
204 // Should work on a list
205 void Buffer::updateTitles() const
207 if (users) users->owner()->updateWindowTitle();
211 /// Reset autosave timer of all users
212 // Should work on a list
213 void Buffer::resetAutosaveTimers() const
215 if (users) users->owner()->resetAutosaveTimer();
219 void Buffer::fileName(string const & newfile)
221 filename = MakeAbsPath(newfile);
222 filepath = OnlyPath(filename);
223 setReadonly(IsFileWriteable(filename) == 0);
228 // candidate for move to BufferView
229 // (at least some parts in the beginning of the func)
232 // changed to be public and have one parameter
233 // if par = 0 normal behavior
234 // else insert behavior
235 // Returns false if "\the_end" is not read for formats >= 2.13. (Asger)
236 bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par)
240 char depth = 0; // signed or unsigned?
242 LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
243 LyXParagraph::footnote_kind footnotekind = LyXParagraph::FOOTNOTE;
245 bool the_end_read = false;
247 LyXParagraph * return_par = 0;
248 LyXFont font(LyXFont::ALL_INHERIT, params.language_info);
249 if (format < 2.16 && params.language == "hebrew")
250 font.setLanguage(default_language);
252 // If we are inserting, we cheat and get a token in advance
253 bool has_token = false;
257 par = new LyXParagraph;
259 users->text->BreakParagraph(users);
260 return_par = users->text->FirstParagraph();
263 // We don't want to adopt the parameters from the
264 // document we insert, so we skip until the text begins:
267 pretoken = lex.GetString();
268 if (pretoken == "\\layout") {
280 pretoken = lex.GetString();
283 // Profiling show this should give a lot: (Asger)
284 string const token = pretoken;
288 the_end_read = parseSingleLyXformat2Token(lex, par, return_par,
301 paragraph = return_par;
307 // We'll remove this later. (Lgb)
308 static string last_inset_read;
312 Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
313 LyXParagraph *& return_par,
314 string const & token, int & pos,
315 char & depth, LyXFont & font
317 , LyXParagraph::footnote_flag & footnoteflag,
318 LyXParagraph::footnote_kind & footnotekind
322 bool the_end_read = false;
324 if (token[0] != '\\') {
325 for (string::const_iterator cit = token.begin();
326 cit != token.end(); ++cit) {
327 par->InsertChar(pos, (*cit), font);
330 } else if (token == "\\i") {
331 Inset * inset = new InsetLatexAccent;
332 inset->Read(this, lex);
333 par->InsertInset(pos, inset, font);
335 } else if (token == "\\layout") {
340 par = new LyXParagraph(par);
344 string layoutname = lex.GetString();
345 pair<bool, LyXTextClass::LayoutList::size_type> pp
346 = textclasslist.NumberOfLayout(params.textclass,
349 par->layout = pp.second;
350 } else { // layout not found
351 // use default layout "Standard" (0)
354 // Test whether the layout is obsolete.
355 LyXLayout const & layout =
356 textclasslist.Style(params.textclass,
358 if (!layout.obsoleted_by().empty())
360 textclasslist.NumberOfLayout(params.textclass,
361 layout.obsoleted_by()).second;
363 par->footnoteflag = footnoteflag;
364 par->footnotekind = footnotekind;
367 font = LyXFont(LyXFont::ALL_INHERIT, params.language_info);
368 if (format < 2.16 && params.language == "hebrew")
369 font.setLanguage(default_language);
371 } else if (token == "\\end_float") {
376 par = new LyXParagraph(par);
378 footnotekind = LyXParagraph::FOOTNOTE;
379 footnoteflag = LyXParagraph::NO_FOOTNOTE;
382 par->layout = LYX_DUMMY_LAYOUT;
383 font = LyXFont(LyXFont::ALL_INHERIT, params.language_info);
384 if (format < 2.16 && params.language == "hebrew")
385 font.setLanguage(default_language);
386 } else if (token == "\\begin_float") {
387 int tmpret = lex.FindToken(string_footnotekinds);
388 if (tmpret == -1) ++tmpret;
389 if (tmpret != LYX_LAYOUT_DEFAULT)
390 footnotekind = static_cast<LyXParagraph::footnote_kind>(tmpret); // bad
391 if (footnotekind == LyXParagraph::FOOTNOTE
392 || footnotekind == LyXParagraph::MARGIN)
393 footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
395 footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
397 } else if (token == "\\begin_float") {
398 // This is the compability reader, unfinished but tested.
401 string tmptok = lex.GetString();
402 //lyxerr << "old float: " << tmptok << endl;
407 if (tmptok == "footnote") {
408 inset = new InsetFoot;
409 } else if (tmptok == "margin") {
410 inset = new InsetMarginal;
411 } else if (tmptok == "fig") {
412 inset = new InsetFloat("figure");
413 old_float += "placement htbp\n";
414 } else if (tmptok == "tab") {
415 inset = new InsetFloat("table");
416 old_float += "placement htbp\n";
417 } else if (tmptok == "alg") {
418 inset = new InsetFloat("algorithm");
419 old_float += "placement htbp\n";
420 } else if (tmptok == "wide-fig") {
421 InsetFloat * tmp = new InsetFloat("figure");
424 old_float += "placement htbp\n";
425 } else if (tmptok == "wide-tab") {
426 InsetFloat * tmp = new InsetFloat("table");
429 old_float += "placement htbp\n";
432 if (!inset) return false; // no end read yet
434 old_float += "collapsed true\n";
436 // Here we need to check for \end_deeper and handle that
437 // before we do the footnote parsing.
438 // This _is_ a hack! (Lgb)
441 string tmp = lex.GetString();
442 if (tmp == "\\end_deeper") {
443 lyxerr << "\\end_deeper caught!" << endl;
445 lex.printError("\\end_deeper: "
446 "depth is already null");
457 old_float += lex.getLongString("\\end_float");
458 old_float += "\n\\end_inset\n";
459 //lyxerr << "float body: " << old_float << endl;
462 istringstream istr(old_float.c_str());
464 istrstream istr(old_float.c_str());
468 nylex.setStream(istr);
470 inset->Read(this, nylex);
471 par->InsertInset(pos, inset, font);
474 } else if (token == "\\begin_deeper") {
476 } else if (token == "\\end_deeper") {
478 lex.printError("\\end_deeper: "
479 "depth is already null");
483 } else if (token == "\\begin_preamble") {
484 params.readPreamble(lex);
485 } else if (token == "\\textclass") {
487 pair<bool, LyXTextClassList::size_type> pp =
488 textclasslist.NumberOfClass(lex.GetString());
490 params.textclass = pp.second;
492 lex.printError("Unknown textclass `$$Token'");
493 params.textclass = 0;
495 if (!textclasslist.Load(params.textclass)) {
496 // if the textclass wasn't loaded properly
497 // we need to either substitute another
498 // or stop loading the file.
499 // I can substitute but I don't see how I can
500 // stop loading... ideas?? ARRae980418
501 WriteAlert(_("Textclass Loading Error!"),
502 string(_("Can't load textclass ")) +
503 textclasslist.NameOfClass(params.textclass),
504 _("-- substituting default"));
505 params.textclass = 0;
507 } else if (token == "\\options") {
509 params.options = lex.GetString();
510 } else if (token == "\\language") {
511 params.readLanguage(lex);
512 } else if (token == "\\fontencoding") {
514 } else if (token == "\\inputencoding") {
516 params.inputenc = lex.GetString();
517 } else if (token == "\\graphics") {
518 params.readGraphicsDriver(lex);
519 } else if (token == "\\fontscheme") {
521 params.fonts = lex.GetString();
522 } else if (token == "\\noindent") {
523 par->noindent = true;
524 } else if (token == "\\fill_top") {
525 par->added_space_top = VSpace(VSpace::VFILL);
526 } else if (token == "\\fill_bottom") {
527 par->added_space_bottom = VSpace(VSpace::VFILL);
528 } else if (token == "\\line_top") {
529 par->line_top = true;
530 } else if (token == "\\line_bottom") {
531 par->line_bottom = true;
532 } else if (token == "\\pagebreak_top") {
533 par->pagebreak_top = true;
534 } else if (token == "\\pagebreak_bottom") {
535 par->pagebreak_bottom = true;
536 } else if (token == "\\start_of_appendix") {
537 par->start_of_appendix = true;
538 } else if (token == "\\paragraph_separation") {
539 int tmpret = lex.FindToken(string_paragraph_separation);
540 if (tmpret == -1) ++tmpret;
541 if (tmpret != LYX_LAYOUT_DEFAULT)
542 params.paragraph_separation =
543 static_cast<BufferParams::PARSEP>(tmpret);
544 } else if (token == "\\defskip") {
546 params.defskip = VSpace(lex.GetString());
547 } else if (token == "\\epsfig") { // obsolete
548 // Indeed it is obsolete, but we HAVE to be backwards
549 // compatible until 0.14, because otherwise all figures
550 // in existing documents are irretrivably lost. (Asger)
551 params.readGraphicsDriver(lex);
552 } else if (token == "\\quotes_language") {
553 int tmpret = lex.FindToken(string_quotes_language);
554 if (tmpret == -1) ++tmpret;
555 if (tmpret != LYX_LAYOUT_DEFAULT) {
556 InsetQuotes::quote_language tmpl =
557 InsetQuotes::EnglishQ;
560 tmpl = InsetQuotes::EnglishQ;
563 tmpl = InsetQuotes::SwedishQ;
566 tmpl = InsetQuotes::GermanQ;
569 tmpl = InsetQuotes::PolishQ;
572 tmpl = InsetQuotes::FrenchQ;
575 tmpl = InsetQuotes::DanishQ;
578 params.quotes_language = tmpl;
580 } else if (token == "\\quotes_times") {
582 switch(lex.GetInteger()) {
584 params.quotes_times = InsetQuotes::SingleQ;
587 params.quotes_times = InsetQuotes::DoubleQ;
590 } else if (token == "\\papersize") {
591 int tmpret = lex.FindToken(string_papersize);
595 params.papersize2 = tmpret;
596 } else if (token == "\\paperpackage") {
597 int tmpret = lex.FindToken(string_paperpackages);
600 params.paperpackage = BufferParams::PACKAGE_NONE;
602 params.paperpackage = tmpret;
603 } else if (token == "\\use_geometry") {
605 params.use_geometry = lex.GetInteger();
606 } else if (token == "\\use_amsmath") {
608 params.use_amsmath = lex.GetInteger();
609 } else if (token == "\\paperorientation") {
610 int tmpret = lex.FindToken(string_orientation);
611 if (tmpret == -1) ++tmpret;
612 if (tmpret != LYX_LAYOUT_DEFAULT)
613 params.orientation = static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
614 } else if (token == "\\paperwidth") {
616 params.paperwidth = lex.GetString();
617 } else if (token == "\\paperheight") {
619 params.paperheight = lex.GetString();
620 } else if (token == "\\leftmargin") {
622 params.leftmargin = lex.GetString();
623 } else if (token == "\\topmargin") {
625 params.topmargin = lex.GetString();
626 } else if (token == "\\rightmargin") {
628 params.rightmargin = lex.GetString();
629 } else if (token == "\\bottommargin") {
631 params.bottommargin = lex.GetString();
632 } else if (token == "\\headheight") {
634 params.headheight = lex.GetString();
635 } else if (token == "\\headsep") {
637 params.headsep = lex.GetString();
638 } else if (token == "\\footskip") {
640 params.footskip = lex.GetString();
641 } else if (token == "\\paperfontsize") {
643 params.fontsize = strip(lex.GetString());
644 } else if (token == "\\papercolumns") {
646 params.columns = lex.GetInteger();
647 } else if (token == "\\papersides") {
649 switch(lex.GetInteger()) {
651 case 1: params.sides = LyXTextClass::OneSide; break;
652 case 2: params.sides = LyXTextClass::TwoSides; break;
654 } else if (token == "\\paperpagestyle") {
656 params.pagestyle = strip(lex.GetString());
657 } else if (token == "\\bullet") {
659 int index = lex.GetInteger();
661 int temp_int = lex.GetInteger();
662 params.user_defined_bullets[index].setFont(temp_int);
663 params.temp_bullets[index].setFont(temp_int);
665 temp_int = lex.GetInteger();
666 params.user_defined_bullets[index].setCharacter(temp_int);
667 params.temp_bullets[index].setCharacter(temp_int);
669 temp_int = lex.GetInteger();
670 params.user_defined_bullets[index].setSize(temp_int);
671 params.temp_bullets[index].setSize(temp_int);
673 string temp_str = lex.GetString();
674 if (temp_str != "\\end_bullet") {
675 // this element isn't really necessary for
676 // parsing but is easier for humans
677 // to understand bullets. Put it back and
678 // set a debug message?
679 lex.printError("\\end_bullet expected, got" + temp_str);
680 //how can I put it back?
682 } else if (token == "\\bulletLaTeX") {
684 int index = lex.GetInteger();
686 string temp_str = lex.GetString(), sum_str;
687 while (temp_str != "\\end_bullet") {
688 // this loop structure is needed when user
689 // enters an empty string since the first
690 // thing returned will be the \\end_bullet
692 // if the LaTeX entry has spaces. Each element
693 // therefore needs to be read in turn
696 temp_str = lex.GetString();
698 params.user_defined_bullets[index].setText(sum_str);
699 params.temp_bullets[index].setText(sum_str);
700 } else if (token == "\\secnumdepth") {
702 params.secnumdepth = lex.GetInteger();
703 } else if (token == "\\tocdepth") {
705 params.tocdepth = lex.GetInteger();
706 } else if (token == "\\spacing") {
708 string tmp = strip(lex.GetString());
709 Spacing::Space tmp_space = Spacing::Default;
711 if (tmp == "single") {
712 tmp_space = Spacing::Single;
713 } else if (tmp == "onehalf") {
714 tmp_space = Spacing::Onehalf;
715 } else if (tmp == "double") {
716 tmp_space = Spacing::Double;
717 } else if (tmp == "other") {
719 tmp_space = Spacing::Other;
720 tmp_val = lex.GetFloat();
722 lex.printError("Unknown spacing token: '$$Token'");
724 // Small hack so that files written with klyx will be
727 par->spacing.set(tmp_space, tmp_val);
729 params.spacing.set(tmp_space, tmp_val);
731 } else if (token == "\\paragraph_spacing") {
733 string tmp = strip(lex.GetString());
734 if (tmp == "single") {
735 par->spacing.set(Spacing::Single);
736 } else if (tmp == "onehalf") {
737 par->spacing.set(Spacing::Onehalf);
738 } else if (tmp == "double") {
739 par->spacing.set(Spacing::Double);
740 } else if (tmp == "other") {
742 par->spacing.set(Spacing::Other,
745 lex.printError("Unknown spacing token: '$$Token'");
747 } else if (token == "\\float_placement") {
749 params.float_placement = lex.GetString();
750 } else if (token == "\\family") {
752 font.setLyXFamily(lex.GetString());
753 } else if (token == "\\series") {
755 font.setLyXSeries(lex.GetString());
756 } else if (token == "\\shape") {
758 font.setLyXShape(lex.GetString());
759 } else if (token == "\\size") {
761 font.setLyXSize(lex.GetString());
762 } else if (token == "\\latex") {
764 string tok = lex.GetString();
765 // This is dirty, but gone with LyX3. (Asger)
766 if (tok == "no_latex")
767 font.setLatex(LyXFont::OFF);
768 else if (tok == "latex")
769 font.setLatex(LyXFont::ON);
770 else if (tok == "default")
771 font.setLatex(LyXFont::INHERIT);
773 lex.printError("Unknown LaTeX font flag "
775 } else if (token == "\\lang") {
777 string tok = lex.GetString();
778 Languages::iterator lit = languages.find(tok);
779 if (lit != languages.end()) {
780 font.setLanguage(&(*lit).second);
782 font.setLanguage(params.language_info);
783 lex.printError("Unknown language `$$Token'");
785 } else if (token == "\\emph") {
787 font.setEmph(font.setLyXMisc(lex.GetString()));
788 } else if (token == "\\bar") {
790 string tok = lex.GetString();
791 // This is dirty, but gone with LyX3. (Asger)
793 font.setUnderbar(LyXFont::ON);
794 else if (tok == "no")
795 font.setUnderbar(LyXFont::OFF);
796 else if (tok == "default")
797 font.setUnderbar(LyXFont::INHERIT);
799 lex.printError("Unknown bar font flag "
801 } else if (token == "\\noun") {
803 font.setNoun(font.setLyXMisc(lex.GetString()));
804 } else if (token == "\\color") {
806 font.setLyXColor(lex.GetString());
807 } else if (token == "\\align") {
808 int tmpret = lex.FindToken(string_align);
809 if (tmpret == -1) ++tmpret;
810 if (tmpret != LYX_LAYOUT_DEFAULT) { // tmpret != 99 ???
812 for (; tmpret > 0; --tmpret)
813 tmpret2 = tmpret2 * 2;
814 par->align = LyXAlignment(tmpret2);
816 } else if (token == "\\added_space_top") {
818 par->added_space_top = VSpace(lex.GetString());
819 } else if (token == "\\added_space_bottom") {
821 par->added_space_bottom = VSpace(lex.GetString());
822 } else if (token == "\\pextra_type") {
824 par->pextra_type = lex.GetInteger();
825 } else if (token == "\\pextra_width") {
827 par->pextra_width = lex.GetString();
828 } else if (token == "\\pextra_widthp") {
830 par->pextra_widthp = lex.GetString();
831 } else if (token == "\\pextra_alignment") {
833 par->pextra_alignment = lex.GetInteger();
834 } else if (token == "\\pextra_hfill") {
836 par->pextra_hfill = lex.GetInteger();
837 } else if (token == "\\pextra_start_minipage") {
839 par->pextra_start_minipage = lex.GetInteger();
840 } else if (token == "\\labelwidthstring") {
842 par->labelwidthstring = lex.GetString();
843 // do not delete this token, it is still needed!
844 } else if (token == "\\end_inset") {
845 lyxerr << "Solitary \\end_inset. Missing \\begin_inset?.\n"
846 << "Last inset read was: " << last_inset_read
848 // Simply ignore this. The insets do not have
850 // But insets should read it, it is a part of
851 // the inset isn't it? Lgb.
852 } else if (token == "\\begin_inset") {
854 readInset(lex, par, pos, font);
856 // Should be moved out into its own function/method. (Lgb)
858 string tmptok = lex.GetString();
859 last_inset_read = tmptok;
860 // test the different insets
861 if (tmptok == "Quotes") {
862 Inset * inset = new InsetQuotes;
863 inset->Read(this, lex);
864 par->InsertInset(pos, inset, font);
866 } else if (tmptok == "External") {
867 Inset * inset = new InsetExternal;
868 inset->Read(this, lex);
869 par->InsertInset(pos, inset, font);
871 } else if (tmptok == "FormulaMacro") {
872 Inset * inset = new InsetFormulaMacro;
873 inset->Read(this, lex);
874 par->InsertInset(pos, inset, font);
876 } else if (tmptok == "Formula") {
877 Inset * inset = new InsetFormula;
878 inset->Read(this, lex);
879 par->InsertInset(pos, inset, font);
881 } else if (tmptok == "Figure") {
882 Inset * inset = new InsetFig(100, 100, this);
883 inset->Read(this, lex);
884 par->InsertInset(pos, inset, font);
886 } else if (tmptok == "Info") {
887 Inset * inset = new InsetInfo;
888 inset->Read(this, lex);
889 par->InsertInset(pos, inset, font);
891 } else if (tmptok == "Include") {
892 Inset * inset = new InsetInclude(string(), this);
893 inset->Read(this, lex);
894 par->InsertInset(pos, inset, font);
896 } else if (tmptok == "ERT") {
897 Inset * inset = new InsetERT;
898 inset->Read(this, lex);
899 par->InsertInset(pos, inset, font);
901 } else if (tmptok == "Tabular") {
902 Inset * inset = new InsetTabular(this);
903 inset->Read(this, lex);
904 par->InsertInset(pos, inset, font);
906 } else if (tmptok == "Text") {
907 Inset * inset = new InsetText;
908 inset->Read(this, lex);
909 par->InsertInset(pos, inset, font);
911 } else if (tmptok == "Foot") {
912 Inset * inset = new InsetFoot;
913 inset->Read(this, lex);
914 par->InsertInset(pos, inset, font);
916 } else if (tmptok == "Marginal") {
917 Inset * inset = new InsetMarginal;
918 inset->Read(this, lex);
919 par->InsertInset(pos, inset, font);
921 } else if (tmptok == "Minipage") {
922 Inset * inset = new InsetMinipage;
923 inset->Read(this, lex);
924 par->InsertInset(pos, inset, font);
926 } else if (tmptok == "Float") {
928 string tmptok = lex.GetString();
929 Inset * inset = new InsetFloat(tmptok);
930 inset->Read(this, lex);
931 par->InsertInset(pos, inset, font);
933 } else if (tmptok == "List") {
934 Inset * inset = new InsetList;
935 inset->Read(this, lex);
936 par->InsertInset(pos, inset, font);
938 } else if (tmptok == "Theorem") {
939 Inset * inset = new InsetList;
940 inset->Read(this, lex);
941 par->InsertInset(pos, inset, font);
943 } else if (tmptok == "Caption") {
944 Inset * inset = new InsetCaption;
945 inset->Read(this, lex);
946 par->InsertInset(pos, inset, font);
948 } else if (tmptok == "Graphics") {
949 Inset * inset = new InsetGraphics;
950 inset->Read(this, lex);
951 par->InsertInset(pos, inset, font);
953 } else if (tmptok == "LatexCommand") {
955 inscmd.Read(this, lex);
957 if (inscmd.getCmdName() == "cite") {
958 inset = new InsetCitation(inscmd.params());
959 } else if (inscmd.getCmdName() == "bibitem") {
960 lex.printError("Wrong place for bibitem");
961 inset = inscmd.Clone();
962 } else if (inscmd.getCmdName() == "BibTeX") {
963 inset = new InsetBibtex(inscmd.getContents(), inscmd.getOptions(), this);
964 } else if (inscmd.getCmdName() == "index") {
965 inset = new InsetIndex(inscmd.params());
966 } else if (inscmd.getCmdName() == "include") {
967 inset = new InsetInclude(inscmd.getContents(), this);
968 } else if (inscmd.getCmdName() == "label") {
969 inset = new InsetLabel(inscmd.getCommand());
970 } else if (inscmd.getCmdName() == "url"
971 || inscmd.getCmdName() == "htmlurl") {
972 inset = new InsetUrl(inscmd.params());
973 } else if (inscmd.getCmdName() == "ref"
974 || inscmd.getCmdName() == "pageref"
975 || inscmd.getCmdName() == "vref"
976 || inscmd.getCmdName() == "vpageref"
977 || inscmd.getCmdName() == "prettyref") {
978 if (!inscmd.getOptions().empty() || !inscmd.getContents().empty()) {
979 inset = new InsetRef(inscmd, this);
981 } else if (inscmd.getCmdName() == "tableofcontents"
982 || inscmd.getCmdName() == "listofalgorithms"
983 || inscmd.getCmdName() == "listoffigures"
984 || inscmd.getCmdName() == "listoftables") {
985 inset = new InsetTOC(inscmd.params());
986 } else if (inscmd.getCmdName() == "printindex") {
987 inset = new InsetPrintIndex(inscmd.params());
988 } else if (inscmd.getCmdName() == "lyxparent") {
989 inset = new InsetParent(inscmd.getContents(), this);
993 par->InsertInset(pos, inset, font);
998 } else if (token == "\\SpecialChar") {
999 LyXLayout const & layout =
1000 textclasslist.Style(params.textclass,
1003 // Insets don't make sense in a free-spacing context! ---Kayvan
1004 if (layout.free_spacing) {
1007 string next_token = lex.GetString();
1008 if (next_token == "\\-") {
1009 par->InsertChar(pos, '-', font);
1010 } else if (next_token == "\\protected_separator"
1011 || next_token == "~") {
1012 par->InsertChar(pos, ' ', font);
1014 lex.printError("Token `$$Token' "
1016 "paragraph layout!");
1021 Inset * inset = new InsetSpecialChar;
1022 inset->Read(this, lex);
1023 par->InsertInset(pos, inset, font);
1026 } else if (token == "\\newline") {
1027 par->InsertChar(pos, LyXParagraph::META_NEWLINE, font);
1029 } else if (token == "\\LyXTable") {
1031 Inset * inset = new InsetTabular(this);
1032 inset->Read(this, lex);
1033 par->InsertInset(pos, inset, font);
1036 par->table = new LyXTable(lex);
1038 } else if (token == "\\hfill") {
1039 par->InsertChar(pos, LyXParagraph::META_HFILL, font);
1041 } else if (token == "\\protected_separator") { // obsolete
1042 // This is a backward compability thingie. (Lgb)
1043 // Remove it later some time...introduced with fileformat
1045 LyXLayout const & layout =
1046 textclasslist.Style(params.textclass,
1049 if (layout.free_spacing) {
1050 par->InsertChar(pos, ' ', font);
1052 Inset * inset = new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
1053 par->InsertInset(pos, inset, font);
1056 } else if (token == "\\bibitem") { // ale970302
1058 par->bibkey = new InsetBibKey;
1059 par->bibkey->Read(this, lex);
1060 }else if (token == "\\backslash") {
1061 par->InsertChar(pos, '\\', font);
1063 }else if (token == "\\the_end") {
1064 the_end_read = true;
1066 // This should be insurance for the future: (Asger)
1067 lex.printError("Unknown token `$$Token'. "
1068 "Inserting as text.");
1069 for(string::const_iterator cit = token.begin();
1070 cit != token.end(); ++cit) {
1071 par->InsertChar(pos, (*cit), font);
1075 return the_end_read;
1079 void Buffer::readInset(LyXLex & lex, LyXParagraph *& par,
1080 int & pos, LyXFont & font)
1082 // consistency check
1083 if (lex.GetString() != "\\begin_inset") {
1084 lyxerr << "Buffer::readInset: Consistency check failed."
1089 string tmptok = lex.GetString();
1090 last_inset_read = tmptok;
1091 // test the different insets
1092 if (tmptok == "Quotes") {
1093 Inset * inset = new InsetQuotes;
1094 inset->Read(this, lex);
1095 par->InsertInset(pos, inset, font);
1097 } else if (tmptok == "External") {
1098 Inset * inset = new InsetExternal;
1099 inset->Read(this, lex);
1100 par->InsertInset(pos, inset, font);
1102 } else if (tmptok == "FormulaMacro") {
1103 Inset * inset = new InsetFormulaMacro;
1104 inset->Read(this, lex);
1105 par->InsertInset(pos, inset, font);
1107 } else if (tmptok == "Formula") {
1108 Inset * inset = new InsetFormula;
1109 inset->Read(this, lex);
1110 par->InsertInset(pos, inset, font);
1112 } else if (tmptok == "Figure") {
1113 Inset * inset = new InsetFig(100, 100, this);
1114 inset->Read(this, lex);
1115 par->InsertInset(pos, inset, font);
1117 } else if (tmptok == "Info") {
1118 Inset * inset = new InsetInfo;
1119 inset->Read(this, lex);
1120 par->InsertInset(pos, inset, font);
1122 } else if (tmptok == "Include") {
1123 Inset * inset = new InsetInclude(string(), this);
1124 inset->Read(this, lex);
1125 par->InsertInset(pos, inset, font);
1127 } else if (tmptok == "ERT") {
1128 Inset * inset = new InsetERT;
1129 inset->Read(this, lex);
1130 par->InsertInset(pos, inset, font);
1132 } else if (tmptok == "Tabular") {
1133 Inset * inset = new InsetTabular(this);
1134 inset->Read(this, lex);
1135 par->InsertInset(pos, inset, font);
1137 } else if (tmptok == "Text") {
1138 Inset * inset = new InsetText;
1139 inset->Read(this, lex);
1140 par->InsertInset(pos, inset, font);
1142 } else if (tmptok == "Foot") {
1143 Inset * inset = new InsetFoot;
1144 inset->Read(this, lex);
1145 par->InsertInset(pos, inset, font);
1147 } else if (tmptok == "Marginal") {
1148 Inset * inset = new InsetMarginal;
1149 inset->Read(this, lex);
1150 par->InsertInset(pos, inset, font);
1152 } else if (tmptok == "Minipage") {
1153 Inset * inset = new InsetMinipage;
1154 inset->Read(this, lex);
1155 par->InsertInset(pos, inset, font);
1157 } else if (tmptok == "Float") {
1159 string tmptok = lex.GetString();
1160 Inset * inset = new InsetFloat(tmptok);
1161 inset->Read(this, lex);
1162 par->InsertInset(pos, inset, font);
1164 } else if (tmptok == "List") {
1165 Inset * inset = new InsetList;
1166 inset->Read(this, lex);
1167 par->InsertInset(pos, inset, font);
1169 } else if (tmptok == "Theorem") {
1170 Inset * inset = new InsetList;
1171 inset->Read(this, lex);
1172 par->InsertInset(pos, inset, font);
1174 } else if (tmptok == "Caption") {
1175 Inset * inset = new InsetCaption;
1176 inset->Read(this, lex);
1177 par->InsertInset(pos, inset, font);
1179 } else if (tmptok == "GRAPHICS") {
1180 Inset * inset = new InsetGraphics;
1181 //inset->Read(this, lex);
1182 par->InsertInset(pos, inset, font);
1183 } else if (tmptok == "LatexCommand") {
1184 InsetCommand inscmd;
1185 inscmd.Read(this, lex);
1187 if (inscmd.getCmdName() == "cite") {
1188 inset = new InsetCitation(inscmd.params());
1189 } else if (inscmd.getCmdName() == "bibitem") {
1190 lex.printError("Wrong place for bibitem");
1191 inset = inscmd.Clone();
1192 } else if (inscmd.getCmdName() == "BibTeX") {
1193 inset = new InsetBibtex(inscmd.getContents(),
1194 inscmd.getOptions(), this);
1195 } else if (inscmd.getCmdName() == "index") {
1196 inset = new InsetIndex(inscmd.params());
1197 } else if (inscmd.getCmdName() == "include") {
1198 inset = new InsetInclude(inscmd.getContents(), this);
1199 } else if (inscmd.getCmdName() == "label") {
1200 inset = new InsetLabel(inscmd.getCommand());
1201 } else if (inscmd.getCmdName() == "url"
1202 || inscmd.getCmdName() == "htmlurl") {
1203 inset = new InsetUrl(inscmd.params());
1204 } else if (inscmd.getCmdName() == "ref"
1205 || inscmd.getCmdName() == "pageref"
1206 || inscmd.getCmdName() == "vref"
1207 || inscmd.getCmdName() == "vpageref"
1208 || inscmd.getCmdName() == "prettyref") {
1209 if (!inscmd.getOptions().empty()
1210 || !inscmd.getContents().empty()) {
1211 inset = new InsetRef(inscmd, this);
1213 } else if (inscmd.getCmdName() == "tableofcontents"
1214 || inscmd.getCmdName() == "listofalgorithms"
1215 || inscmd.getCmdName() == "listoffigures"
1216 || inscmd.getCmdName() == "listoftables") {
1217 inset = new InsetTOC(inscmd.params());
1218 } else if (inscmd.getCmdName() == "printindex") {
1219 inset = new InsetPrintIndex(inscmd.params());
1220 } else if (inscmd.getCmdName() == "lyxparent") {
1221 inset = new InsetParent(inscmd.getContents(), this);
1225 par->InsertInset(pos, inset, font);
1232 bool Buffer::readFile(LyXLex & lex, LyXParagraph * par)
1238 token = lex.GetString();
1239 if (token == "\\lyxformat") { // the first token _must_ be...
1241 format = lex.GetFloat();
1243 if (LYX_FORMAT - format > 0.05) {
1244 printf(_("Warning: need lyxformat %.2f but found %.2f\n"),
1245 LYX_FORMAT, format);
1247 if (format - LYX_FORMAT > 0.05) {
1248 printf(_("ERROR: need lyxformat %.2f but found %.2f\n"),
1249 LYX_FORMAT, format);
1251 bool the_end = readLyXformat2(lex, par);
1252 // Formats >= 2.13 support "\the_end" marker
1259 WriteAlert(_("Warning!"),
1260 _("Reading of document is not complete"),
1261 _("Maybe the document is truncated"));
1262 // We simulate a safe reading anyways to allow
1263 // users to take the chance... (Asger)
1267 WriteAlert(_("ERROR!"),
1268 _("Old LyX file format found. "
1269 "Use LyX 0.10.x to read this!"));
1273 } else { // "\\lyxformat" not found
1274 WriteAlert(_("ERROR!"), _("Not a LyX file!"));
1277 WriteAlert(_("ERROR!"), _("Unable to read file!"));
1283 // Should probably be moved to somewhere else: BufferView? LyXView?
1284 bool Buffer::save() const
1286 // We don't need autosaves in the immediate future. (Asger)
1287 resetAutosaveTimers();
1291 if (lyxrc.make_backup) {
1292 s = fileName() + '~';
1293 if (!lyxrc.backupdir_path.empty())
1294 s = AddName(lyxrc.backupdir_path,
1295 subst(CleanupPath(s),'/','!'));
1297 // Rename is the wrong way of making a backup,
1298 // this is the correct way.
1299 /* truss cp fil fil2:
1300 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
1301 stat("LyXVC.lyx", 0xEFFFF688) = 0
1302 open("LyXVC.lyx", O_RDONLY) = 3
1303 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
1304 fstat(4, 0xEFFFF508) = 0
1305 fstat(3, 0xEFFFF508) = 0
1306 read(3, " # T h i s f i l e w".., 8192) = 5579
1307 write(4, " # T h i s f i l e w".., 5579) = 5579
1308 read(3, 0xEFFFD4A0, 8192) = 0
1311 chmod("LyXVC3.lyx", 0100644) = 0
1312 lseek(0, 0, SEEK_CUR) = 46440
1316 // Should proabaly have some more error checking here.
1317 // Should be cleaned up in 0.13, at least a bit.
1318 // Doing it this way, also makes the inodes stay the same.
1319 // This is still not a very good solution, in particular we
1320 // might loose the owner of the backup.
1321 FileInfo finfo(fileName());
1322 if (finfo.exist()) {
1323 mode_t fmode = finfo.getMode();
1324 struct utimbuf times = {
1325 finfo.getAccessTime(),
1326 finfo.getModificationTime() };
1328 ifstream ifs(fileName().c_str());
1329 ofstream ofs(s.c_str(), ios::out|ios::trunc);
1334 ::chmod(s.c_str(), fmode);
1336 if (::utime(s.c_str(), ×)) {
1337 lyxerr << "utime error." << endl;
1340 lyxerr << "LyX was not able to make "
1341 "backupcopy. Beware." << endl;
1346 if (writeFile(fileName(), false)) {
1349 // now delete the autosavefile
1350 string a = OnlyPath(fileName());
1352 a += OnlyFilename(fileName());
1354 FileInfo fileinfo(a);
1355 if (fileinfo.exist()) {
1356 if (::remove(a.c_str()) != 0) {
1357 WriteFSAlert(_("Could not delete "
1358 "auto-save file!"), a);
1362 // Saving failed, so backup is not backup
1363 if (lyxrc.make_backup) {
1364 ::rename(s.c_str(), fileName().c_str());
1372 // Returns false if unsuccesful
1373 bool Buffer::writeFile(string const & fname, bool flag) const
1375 // if flag is false writeFile will not create any GUI
1376 // warnings, only cerr.
1377 // Needed for autosave in background or panic save (Matthias 120496)
1379 if (read_only && (fname == filename)) {
1380 // Here we should come with a question if we should
1381 // perform the write anyway.
1383 lyxerr << _("Error! Document is read-only: ")
1386 WriteAlert(_("Error! Document is read-only: "),
1391 FileInfo finfo(fname);
1392 if (finfo.exist() && !finfo.writable()) {
1393 // Here we should come with a question if we should
1394 // try to do the save anyway. (i.e. do a chmod first)
1396 lyxerr << _("Error! Cannot write file: ")
1399 WriteFSAlert(_("Error! Cannot write file: "),
1404 ofstream ofs(fname.c_str());
1407 lyxerr << _("Error! Cannot open file: ")
1410 WriteFSAlert(_("Error! Cannot open file: "),
1414 // The top of the file should not be written by params.
1416 // write out a comment in the top of the file
1417 ofs << '#' << LYX_DOCVERSION
1418 << " created this file. For more info see http://www.lyx.org/\n";
1419 ofs.setf(ios::showpoint|ios::fixed);
1421 ofs << "\\lyxformat " << setw(4) << LYX_FORMAT << "\n";
1423 // now write out the buffer paramters.
1424 params.writeFile(ofs);
1426 char footnoteflag = 0;
1429 // this will write out all the paragraphs
1430 // using recursive descent.
1431 paragraph->writeFile(this, ofs, params, footnoteflag, depth);
1433 // Write marker that shows file is complete
1434 ofs << "\n\\the_end" << endl;
1436 // how to check if close went ok?
1441 void Buffer::writeFileAscii(string const & fname, int linelen)
1443 LyXFont font1, font2;
1445 char c, footnoteflag = 0, depth = 0;
1447 LyXParagraph::size_type i;
1450 int ltype_depth = 0;
1459 int currlinelen = 0;
1461 bool ref_printed = false;
1463 ofstream ofs(fname.c_str());
1465 WriteFSAlert(_("Error: Cannot write file:"), fname);
1469 string fname1 = TmpFileName();
1470 LyXParagraph * par = paragraph;
1476 par->footnoteflag != LyXParagraph::NO_FOOTNOTE ||
1480 || par->previous->footnoteflag == LyXParagraph::NO_FOOTNOTE
1485 /* begins a footnote environment ? */
1486 if (footnoteflag != par->footnoteflag) {
1487 footnoteflag = par->footnoteflag;
1489 j = strlen(string_footnotekinds[par->footnotekind])+4;
1490 if (currlinelen + j > linelen)
1493 << string_footnotekinds[par->footnotekind] << "] ";
1499 /* begins or ends a deeper area ?*/
1500 if (depth != par->depth) {
1501 if (par->depth > depth) {
1502 while (par->depth > depth) {
1507 while (par->depth < depth) {
1513 /* First write the layout */
1514 tmp = textclasslist.NameOfLayout(params.textclass, par->layout);
1515 if (tmp == "Itemize") {
1517 ltype_depth = depth+1;
1518 } else if (tmp == "Enumerate") {
1520 ltype_depth = depth+1;
1521 } else if (strstr(tmp.c_str(), "ection")) {
1523 ltype_depth = depth+1;
1524 } else if (strstr(tmp.c_str(), "aragraph")) {
1526 ltype_depth = depth+1;
1527 } else if (tmp == "Description") {
1529 ltype_depth = depth+1;
1530 } else if (tmp == "Abstract") {
1533 } else if (tmp == "Bibliography") {
1541 /* maybe some vertical spaces */
1543 /* the labelwidthstring used in lists */
1547 /* some pagebreaks? */
1551 /* what about the alignment */
1554 /* dummy layout, that means a footnote ended */
1555 footnoteflag = LyXParagraph::NO_FOOTNOTE;
1559 lyxerr << "Should this ever happen?" << endl;
1563 //LyXLayout const & layout =
1564 // textclasslist.Style(params.textclass,
1565 // par->GetLayout()); // unused
1566 //bool free_spc = layout.free_spacing; //unused
1569 /* It might be a table */
1573 cells = par->table->columns;
1574 clen = new int [cells];
1575 memset(clen, 0, sizeof(int) * cells);
1577 for (i = 0, j = 0, h = 1; i < par->size(); ++i, ++h) {
1578 c = par->GetChar(i);
1579 if (c == LyXParagraph::META_INSET) {
1580 if ((inset = par->GetInset(i))) {
1582 std::ostringstream ost;
1583 inset->Ascii(this, ost);
1584 h += ost.str().length();
1587 inset->Ascii(this, ost);
1589 char * tmp = ost.str();
1595 } else if (c == LyXParagraph::META_NEWLINE) {
1599 j = (++j) % par->table->NumberOfCellsInRow(actcell);
1607 font1 = LyXFont(LyXFont::ALL_INHERIT, params.language_info);
1609 for (i = 0, actpos = 1; i < par->size(); ++i, ++actpos) {
1610 if (!i && !footnoteflag && !noparbreak){
1612 for(j = 0; j < depth; ++j)
1614 currlinelen = depth * 2;
1616 case 0: /* Standard */
1617 case 4: /* (Sub)Paragraph */
1618 case 5: /* Description */
1620 case 6: /* Abstract */
1621 ofs << "Abstract\n\n";
1623 case 7: /* Bibliography */
1625 ofs << "References\n\n";
1630 ofs << par->labelstring << " ";
1633 if (ltype_depth > depth) {
1634 for(j = ltype_depth - 1; j > depth; --j)
1636 currlinelen += (ltype_depth-depth)*2;
1640 for(j = 0; j < cells; ++j) {
1642 for(h = 0; h < (clen[j] + 1);
1647 for(j = 0; j < depth; ++j)
1649 currlinelen = depth * 2;
1650 if (ltype_depth > depth) {
1651 for(j = ltype_depth;
1654 currlinelen += (ltype_depth-depth)*2;
1660 font2 = par->GetFontSettings(params, i);
1661 if (font1.latex() != font2.latex()) {
1662 if (font2.latex() == LyXFont::OFF)
1669 c = par->GetChar(i);
1673 case LyXParagraph::META_INSET:
1674 if ((inset = par->GetInset(i))) {
1676 inset->Ascii(this, ofs);
1677 currlinelen += (ofs.tellp() - fpos);
1678 actpos += (ofs.tellp() - fpos) - 1;
1681 case LyXParagraph::META_NEWLINE:
1684 if (par->table->NumberOfCellsInRow(actcell) <= cell) {
1685 for(j = actpos; j < clen[cell - 1]; ++j)
1688 for(j = 0; j < depth; ++j)
1690 currlinelen = depth*2;
1691 if (ltype_depth > depth) {
1692 for(j = ltype_depth; j > depth; --j)
1694 currlinelen += (ltype_depth-depth) * 2;
1696 for(j = 0; j < cells; ++j) {
1698 for(h = 0; h < (clen[j] + 1); ++h)
1702 for(j = 0; j < depth; ++j)
1704 currlinelen = depth * 2;
1705 if (ltype_depth > depth) {
1706 for(j = ltype_depth;
1709 currlinelen += (ltype_depth-depth)*2;
1715 j < clen[cell - 1]; ++j)
1721 currlinelen = actpos = 0;
1725 for(j = 0; j < depth; ++j)
1727 currlinelen = depth * 2;
1728 if (ltype_depth > depth) {
1729 for(j = ltype_depth;
1732 currlinelen += (ltype_depth - depth) * 2;
1738 case LyXParagraph::META_HFILL:
1745 if (currlinelen > linelen - 10
1746 && c == ' ' && i + 2 < par->size()) {
1748 for(j = 0; j < depth; ++j)
1750 currlinelen = depth * 2;
1751 if (ltype_depth > depth) {
1752 for(j = ltype_depth;
1755 currlinelen += (ltype_depth-depth)*2;
1757 } else if (c != '\0')
1760 lyxerr.debug() << "writeAsciiFile: NULL char in structure." << endl;
1767 for(j = actpos; j < clen[cell - 1]; ++j)
1770 for(j = 0; j < depth; ++j)
1772 currlinelen = depth * 2;
1773 if (ltype_depth > depth) {
1774 for(j = ltype_depth; j > depth; --j)
1776 currlinelen += (ltype_depth - depth) * 2;
1778 for(j = 0; j < cells; ++j) {
1780 for(h = 0; h < (clen[j] + 1); ++h)
1794 void Buffer::makeLaTeXFile(string const & fname,
1795 string const & original_path,
1796 bool nice, bool only_body)
1798 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
1800 niceFile = nice; // this will be used by Insetincludes.
1802 tex_code_break_column = lyxrc.ascii_linelen;
1804 LyXTextClass const & tclass =
1805 textclasslist.TextClass(params.textclass);
1807 ofstream ofs(fname.c_str());
1809 WriteFSAlert(_("Error: Cannot open file: "), fname);
1813 // validate the buffer.
1814 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
1815 LaTeXFeatures features(params, tclass.numLayouts());
1817 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
1820 // The starting paragraph of the coming rows is the
1821 // first paragraph of the document. (Asger)
1822 texrow.start(paragraph, 0);
1824 if (!only_body && nice) {
1825 ofs << "%% " LYX_DOCVERSION " created this file. "
1826 "For more info, see http://www.lyx.org/.\n"
1827 "%% Do not edit unless you really know what "
1832 lyxerr.debug() << "lyx header finished" << endl;
1833 // There are a few differences between nice LaTeX and usual files:
1834 // usual is \batchmode and has a
1835 // special input@path to allow the including of figures
1836 // with either \input or \includegraphics (what figinsets do).
1837 // batchmode is not set if there is a tex_code_break_column.
1838 // In this case somebody is interested in the generated LaTeX,
1839 // so this is OK. input@path is set when the actual parameter
1840 // original_path is set. This is done for usual tex-file, but not
1841 // for nice-latex-file. (Matthias 250696)
1844 // code for usual, NOT nice-latex-file
1845 ofs << "\\batchmode\n"; // changed
1846 // from \nonstopmode
1849 if (!original_path.empty()) {
1850 ofs << "\\makeatletter\n"
1851 << "\\def\\input@path{{"
1852 << original_path << "/}}\n"
1853 << "\\makeatother\n";
1859 ofs << "\\documentclass";
1861 string options; // the document class options.
1863 if (tokenPos(tclass.opt_fontsize(),
1864 '|', params.fontsize) >= 0) {
1865 // only write if existing in list (and not default)
1866 options += params.fontsize;
1871 if (!params.use_geometry &&
1872 (params.paperpackage == BufferParams::PACKAGE_NONE)) {
1873 switch (params.papersize) {
1874 case BufferParams::PAPER_A4PAPER:
1875 options += "a4paper,";
1877 case BufferParams::PAPER_USLETTER:
1878 options += "letterpaper,";
1880 case BufferParams::PAPER_A5PAPER:
1881 options += "a5paper,";
1883 case BufferParams::PAPER_B5PAPER:
1884 options += "b5paper,";
1886 case BufferParams::PAPER_EXECUTIVEPAPER:
1887 options += "executivepaper,";
1889 case BufferParams::PAPER_LEGALPAPER:
1890 options += "legalpaper,";
1896 if (params.sides != tclass.sides()) {
1897 switch (params.sides) {
1898 case LyXTextClass::OneSide:
1899 options += "oneside,";
1901 case LyXTextClass::TwoSides:
1902 options += "twoside,";
1909 if (params.columns != tclass.columns()) {
1910 if (params.columns == 2)
1911 options += "twocolumn,";
1913 options += "onecolumn,";
1916 if (!params.use_geometry
1917 && params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1918 options += "landscape,";
1920 // language should be a parameter to \documentclass
1921 bool use_babel = false;
1922 if (params.language_info->lang() == "hebrew") // This seems necessary
1923 features.UsedLanguages.insert(default_language);
1924 if (params.language != "default" ||
1925 !features.UsedLanguages.empty() ) {
1927 for (LaTeXFeatures::LanguageList::const_iterator cit =
1928 features.UsedLanguages.begin();
1929 cit != features.UsedLanguages.end(); ++cit)
1930 options += (*cit)->lang() + ",";
1931 options += params.language_info->lang() + ',';
1934 // the user-defined options
1935 if (!params.options.empty()) {
1936 options += params.options + ',';
1939 if (!options.empty()){
1940 options = strip(options, ',');
1941 ofs << '[' << options << ']';
1945 << textclasslist.LatexnameOfClass(params.textclass)
1948 // end of \documentclass defs
1950 // font selection must be done before loading fontenc.sty
1951 if (params.fonts != "default") {
1952 ofs << "\\usepackage{" << params.fonts << "}\n";
1955 // this one is not per buffer
1956 if (lyxrc.fontenc != "default") {
1957 ofs << "\\usepackage[" << lyxrc.fontenc
1962 if (params.inputenc == "auto") {
1963 string doc_encoding =
1964 params.language_info->encoding()->LatexName();
1966 // Create a list with all the input encodings used
1968 set<string> encodings;
1969 for (LaTeXFeatures::LanguageList::const_iterator it =
1970 features.UsedLanguages.begin();
1971 it != features.UsedLanguages.end(); ++it)
1972 if ((*it)->encoding()->LatexName() != doc_encoding)
1973 encodings.insert((*it)->encoding()->LatexName());
1975 ofs << "\\usepackage[";
1976 for (set<string>::const_iterator it = encodings.begin();
1977 it != encodings.end(); ++it)
1979 ofs << doc_encoding << "]{inputenc}\n";
1981 } else if (params.inputenc != "default") {
1982 ofs << "\\usepackage[" << params.inputenc
1987 // At the very beginning the text parameters.
1988 if (params.paperpackage != BufferParams::PACKAGE_NONE) {
1989 switch (params.paperpackage) {
1990 case BufferParams::PACKAGE_A4:
1991 ofs << "\\usepackage{a4}\n";
1994 case BufferParams::PACKAGE_A4WIDE:
1995 ofs << "\\usepackage{a4wide}\n";
1998 case BufferParams::PACKAGE_WIDEMARGINSA4:
1999 ofs << "\\usepackage[widemargins]{a4}\n";
2004 if (params.use_geometry) {
2005 ofs << "\\usepackage{geometry}\n";
2007 ofs << "\\geometry{verbose";
2008 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
2009 ofs << ",landscape";
2010 switch (params.papersize2) {
2011 case BufferParams::VM_PAPER_CUSTOM:
2012 if (!params.paperwidth.empty())
2013 ofs << ",paperwidth="
2014 << params.paperwidth;
2015 if (!params.paperheight.empty())
2016 ofs << ",paperheight="
2017 << params.paperheight;
2019 case BufferParams::VM_PAPER_USLETTER:
2020 ofs << ",letterpaper";
2022 case BufferParams::VM_PAPER_USLEGAL:
2023 ofs << ",legalpaper";
2025 case BufferParams::VM_PAPER_USEXECUTIVE:
2026 ofs << ",executivepaper";
2028 case BufferParams::VM_PAPER_A3:
2031 case BufferParams::VM_PAPER_A4:
2034 case BufferParams::VM_PAPER_A5:
2037 case BufferParams::VM_PAPER_B3:
2040 case BufferParams::VM_PAPER_B4:
2043 case BufferParams::VM_PAPER_B5:
2047 // default papersize ie BufferParams::VM_PAPER_DEFAULT
2048 switch (lyxrc.default_papersize) {
2049 case BufferParams::PAPER_DEFAULT: // keep compiler happy
2050 case BufferParams::PAPER_USLETTER:
2051 ofs << ",letterpaper";
2053 case BufferParams::PAPER_LEGALPAPER:
2054 ofs << ",legalpaper";
2056 case BufferParams::PAPER_EXECUTIVEPAPER:
2057 ofs << ",executivepaper";
2059 case BufferParams::PAPER_A3PAPER:
2062 case BufferParams::PAPER_A4PAPER:
2065 case BufferParams::PAPER_A5PAPER:
2068 case BufferParams::PAPER_B5PAPER:
2073 if (!params.topmargin.empty())
2074 ofs << ",tmargin=" << params.topmargin;
2075 if (!params.bottommargin.empty())
2076 ofs << ",bmargin=" << params.bottommargin;
2077 if (!params.leftmargin.empty())
2078 ofs << ",lmargin=" << params.leftmargin;
2079 if (!params.rightmargin.empty())
2080 ofs << ",rmargin=" << params.rightmargin;
2081 if (!params.headheight.empty())
2082 ofs << ",headheight=" << params.headheight;
2083 if (!params.headsep.empty())
2084 ofs << ",headsep=" << params.headsep;
2085 if (!params.footskip.empty())
2086 ofs << ",footskip=" << params.footskip;
2090 if (params.use_amsmath
2091 && !tclass.provides(LyXTextClass::amsmath)) {
2092 ofs << "\\usepackage{amsmath}\n";
2096 if (tokenPos(tclass.opt_pagestyle(),
2097 '|', params.pagestyle) >= 0) {
2098 if (params.pagestyle == "fancy") {
2099 ofs << "\\usepackage{fancyhdr}\n";
2102 ofs << "\\pagestyle{" << params.pagestyle << "}\n";
2106 // We try to load babel late, in case it interferes
2107 // with other packages.
2109 ofs << lyxrc.language_package << endl;
2113 if (params.secnumdepth != tclass.secnumdepth()) {
2114 ofs << "\\setcounter{secnumdepth}{"
2115 << params.secnumdepth
2119 if (params.tocdepth != tclass.tocdepth()) {
2120 ofs << "\\setcounter{tocdepth}{"
2126 if (params.paragraph_separation) {
2127 switch (params.defskip.kind()) {
2128 case VSpace::SMALLSKIP:
2129 ofs << "\\setlength\\parskip{\\smallskipamount}\n";
2131 case VSpace::MEDSKIP:
2132 ofs << "\\setlength\\parskip{\\medskipamount}\n";
2134 case VSpace::BIGSKIP:
2135 ofs << "\\setlength\\parskip{\\bigskipamount}\n";
2137 case VSpace::LENGTH:
2138 ofs << "\\setlength\\parskip{"
2139 << params.defskip.length().asLatexString()
2142 default: // should never happen // Then delete it.
2143 ofs << "\\setlength\\parskip{\\medskipamount}\n";
2148 ofs << "\\setlength\\parindent{0pt}\n";
2152 // Now insert the LyX specific LaTeX commands...
2154 // The optional packages;
2155 string preamble(features.getPackages());
2157 // this might be useful...
2158 preamble += "\n\\makeatletter\n";
2160 // Some macros LyX will need
2161 string tmppreamble(features.getMacros());
2163 if (!tmppreamble.empty()) {
2164 preamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2165 "LyX specific LaTeX commands.\n"
2166 + tmppreamble + '\n';
2169 // the text class specific preamble
2170 tmppreamble = features.getTClassPreamble();
2171 if (!tmppreamble.empty()) {
2172 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2173 "Textclass specific LaTeX commands.\n"
2174 + tmppreamble + '\n';
2177 /* the user-defined preamble */
2178 if (!params.preamble.empty()) {
2179 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2180 "User specified LaTeX commands.\n"
2181 + params.preamble + '\n';
2184 preamble += "\\makeatother\n";
2186 // Itemize bullet settings need to be last in case the user
2187 // defines their own bullets that use a package included
2188 // in the user-defined preamble -- ARRae
2189 // Actually it has to be done much later than that
2190 // since some packages like frenchb make modifications
2191 // at \begin{document} time -- JMarc
2193 for (int i = 0; i < 4; ++i) {
2194 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
2195 if (bullets_def.empty())
2196 bullets_def="\\AtBeginDocument{\n";
2197 bullets_def += " \\renewcommand{\\labelitemi";
2199 // `i' is one less than the item to modify
2206 bullets_def += "ii";
2212 bullets_def += "}{" +
2213 params.user_defined_bullets[i].getText()
2218 if (!bullets_def.empty())
2219 preamble += bullets_def + "}\n\n";
2221 for (int j = countChar(preamble, '\n'); j-- ;) {
2228 ofs << "\\begin{document}\n";
2231 lyxerr.debug() << "preamble finished, now the body." << endl;
2232 if (!lyxrc.language_auto_begin && params.language != "default") {
2233 ofs << subst(lyxrc.language_command_begin, "$$lang",
2239 latexParagraphs(ofs, paragraph, 0, texrow);
2241 // add this just in case after all the paragraphs
2245 if (!lyxrc.language_auto_end && params.language != "default") {
2246 ofs << subst(lyxrc.language_command_end, "$$lang",
2253 ofs << "\\end{document}\n";
2256 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
2258 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
2262 // Just to be sure. (Asger)
2265 // tex_code_break_column's value is used to decide
2266 // if we are in batchmode or not (within mathed_write()
2267 // in math_write.C) so we must set it to a non-zero
2268 // value when we leave otherwise we save incorrect .lyx files.
2269 tex_code_break_column = lyxrc.ascii_linelen;
2273 lyxerr << "File was not closed properly." << endl;
2276 lyxerr.debug() << "Finished making latex file." << endl;
2281 // LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
2283 void Buffer::latexParagraphs(ostream & ofs, LyXParagraph * par,
2284 LyXParagraph * endpar, TexRow & texrow) const
2286 bool was_title = false;
2287 bool already_title = false;
2289 std::ostringstream ftnote;
2291 char * tmpholder = 0;
2297 while (par != endpar) {
2298 #ifndef HAVE_SSTREAM
2301 ftnote << tmpholder;
2302 delete [] tmpholder;
2308 lyxerr[Debug::LATEX] << "Error in latexParagraphs."
2311 LyXLayout const & layout =
2312 textclasslist.Style(params.textclass,
2315 if (layout.intitle) {
2316 if (already_title) {
2317 lyxerr <<"Error in latexParagraphs: You"
2318 " should not mix title layouts"
2319 " with normal ones." << endl;
2322 } else if (was_title && !already_title) {
2323 ofs << "\\maketitle\n";
2325 already_title = true;
2328 // We are at depth 0 so we can just use
2329 // ordinary \footnote{} generation
2330 // flag this with ftcount
2332 if (layout.isEnvironment()
2333 || par->pextra_type != LyXParagraph::PEXTRA_NONE) {
2334 par = par->TeXEnvironment(this, params, ofs, texrow
2336 ,ftnote, ft_texrow, ftcount
2340 par = par->TeXOnePar(this, params, ofs, texrow, false
2343 ftnote, ft_texrow, ftcount
2348 // Write out what we've generated...
2351 ofs << "\\addtocounter{footnote}{-"
2355 ofs << ftnote.str();
2356 texrow += ft_texrow;
2358 // The extra .c_str() is needed when we use
2359 // lyxstring instead of the STL string class.
2360 ftnote.str(string().c_str());
2362 delete [] ftnote.str();
2367 #ifndef HAVE_SSTREAM
2369 // I hate strstreams
2370 tmpholder = ftnote.str();
2374 #ifndef HAVE_SSTREAM
2375 delete [] tmpholder;
2377 // It might be that we only have a title in this document
2378 if (was_title && !already_title) {
2379 ofs << "\\maketitle\n";
2385 bool Buffer::isLatex() const
2387 return textclasslist.TextClass(params.textclass).outputType() == LATEX;
2391 bool Buffer::isLinuxDoc() const
2393 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC;
2397 bool Buffer::isLiterate() const
2399 return textclasslist.TextClass(params.textclass).outputType() == LITERATE;
2403 bool Buffer::isDocBook() const
2405 return textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2409 bool Buffer::isSGML() const
2411 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC ||
2412 textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2416 void Buffer::sgmlOpenTag(ostream & os, int depth,
2417 string const & latexname) const
2419 os << string(depth, ' ') << "<" << latexname << ">\n";
2423 void Buffer::sgmlCloseTag(ostream & os, int depth,
2424 string const & latexname) const
2426 os << string(depth, ' ') << "</" << latexname << ">\n";
2430 void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
2432 LyXParagraph * par = paragraph;
2434 niceFile = nice; // this will be used by Insetincludes.
2436 string top_element = textclasslist.LatexnameOfClass(params.textclass);
2437 string environment_stack[10];
2440 int depth = 0; // paragraph depth
2442 ofstream ofs(fname.c_str());
2445 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2449 LyXTextClass const & tclass =
2450 textclasslist.TextClass(params.textclass);
2452 LaTeXFeatures features(params, tclass.numLayouts());
2456 tex_code_break_column = lyxrc.ascii_linelen;
2458 //tex_code_break_column = 0;
2463 string sgml_includedfiles=features.getIncludedFiles();
2465 if (params.preamble.empty() && sgml_includedfiles.empty()) {
2466 ofs << "<!doctype linuxdoc system>\n\n";
2468 ofs << "<!doctype linuxdoc system [ "
2469 << params.preamble << sgml_includedfiles << " \n]>\n\n";
2472 if(params.options.empty())
2473 sgmlOpenTag(ofs, 0, top_element);
2475 string top = top_element;
2477 top += params.options;
2478 sgmlOpenTag(ofs, 0, top);
2482 ofs << "<!-- " << LYX_DOCVERSION
2483 << " created this file. For more info see http://www.lyx.org/"
2487 int desc_on = 0; // description mode
2488 LyXLayout const & style =
2489 textclasslist.Style(params.textclass,
2492 // treat <toc> as a special case for compatibility with old code
2493 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2494 Inset * inset = par->GetInset(0);
2495 Inset::Code lyx_code = inset->LyxCode();
2496 if (lyx_code == Inset::TOC_CODE){
2497 string temp = "toc";
2498 sgmlOpenTag(ofs, depth, temp);
2502 linuxDocHandleFootnote(ofs, par, depth);
2508 // environment tag closing
2509 for( ; depth > par->depth; --depth) {
2510 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2511 environment_stack[depth].erase();
2514 // write opening SGML tags
2515 switch(style.latextype) {
2516 case LATEX_PARAGRAPH:
2517 if(depth == par->depth
2518 && !environment_stack[depth].empty()) {
2519 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2520 environment_stack[depth].erase();
2526 sgmlOpenTag(ofs, depth, style.latexname());
2531 LinuxDocError(par, 0,
2532 _("Error : Wrong depth for"
2533 " LatexType Command.\n"));
2535 if (!environment_stack[depth].empty()){
2536 sgmlCloseTag(ofs, depth,
2537 environment_stack[depth]);
2541 environment_stack[depth].erase();
2542 sgmlOpenTag(ofs, depth, style.latexname());
2545 case LATEX_ENVIRONMENT:
2546 case LATEX_ITEM_ENVIRONMENT:
2547 if(depth == par->depth
2548 && environment_stack[depth] != style.latexname()
2549 && !environment_stack[depth].empty()) {
2551 sgmlCloseTag(ofs, depth,
2552 environment_stack[depth]);
2553 environment_stack[depth].erase();
2555 if (depth < par->depth) {
2557 environment_stack[depth].erase();
2559 if (environment_stack[depth] != style.latexname()) {
2562 sgmlOpenTag(ofs, depth, temp);
2564 environment_stack[depth] = style.latexname();
2565 sgmlOpenTag(ofs, depth,
2566 environment_stack[depth]);
2568 if(style.latextype == LATEX_ENVIRONMENT) break;
2570 desc_on = (style.labeltype == LABEL_MANUAL);
2577 sgmlOpenTag(ofs, depth + 1, item_name);
2580 sgmlOpenTag(ofs, depth, style.latexname());
2587 SimpleLinuxDocOnePar(ofs, par, desc_on, depth);
2591 linuxDocHandleFootnote(ofs, par, depth);
2593 while(par && par->IsDummy());
2597 // write closing SGML tags
2598 switch(style.latextype) {
2600 case LATEX_ENVIRONMENT:
2601 case LATEX_ITEM_ENVIRONMENT:
2604 sgmlCloseTag(ofs, depth, style.latexname());
2610 for(; depth > 0; --depth)
2611 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2613 if(!environment_stack[depth].empty())
2614 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2618 sgmlCloseTag(ofs, 0, top_element);
2622 // How to check for successful close
2627 void Buffer::linuxDocHandleFootnote(ostream & os, LyXParagraph * & par,
2630 string tag = "footnote";
2632 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2633 sgmlOpenTag(os, depth + 1, tag);
2634 SimpleLinuxDocOnePar(os, par, 0, depth + 1);
2635 sgmlCloseTag(os, depth + 1, tag);
2642 void Buffer::DocBookHandleCaption(ostream & os, string & inner_tag,
2643 int const depth, int desc_on,
2644 LyXParagraph * & par)
2646 LyXParagraph * tpar = par;
2649 && (tpar->footnoteflag != LyXParagraph::NO_FOOTNOTE)
2651 && (tpar->layout != textclasslist.NumberOfLayout(params.textclass,
2655 tpar->layout == textclasslist.NumberOfLayout(params.textclass,
2656 "Caption").second) {
2657 sgmlOpenTag(os, depth + 1, inner_tag);
2659 SimpleDocBookOnePar(os, extra_par, tpar,
2660 desc_on, depth + 2);
2661 sgmlCloseTag(os, depth+1, inner_tag);
2662 if(!extra_par.empty())
2669 void Buffer::DocBookHandleFootnote(ostream & os, LyXParagraph * & par,
2672 string tag, inner_tag;
2673 string tmp_par, extra_par;
2674 bool inner_span = false;
2677 // Someone should give this enum a proper name (Lgb)
2685 SOME_ENUM last = NO_ONE;
2686 SOME_ENUM present = FOOTNOTE_LIKE;
2688 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2689 if(last == present) {
2691 if(!tmp_par.empty()) {
2694 sgmlCloseTag(os, depth + 1, inner_tag);
2695 sgmlOpenTag(os, depth + 1, inner_tag);
2702 if(!inner_tag.empty()) sgmlCloseTag(os, depth + 1,
2704 if(!extra_par.empty()) os << extra_par;
2705 if(!tag.empty()) sgmlCloseTag(os, depth, tag);
2708 switch (par->footnotekind) {
2709 case LyXParagraph::FOOTNOTE:
2710 case LyXParagraph::ALGORITHM:
2713 present = FOOTNOTE_LIKE;
2716 case LyXParagraph::MARGIN:
2719 present = MARGIN_LIKE;
2722 case LyXParagraph::FIG:
2723 case LyXParagraph::WIDE_FIG:
2725 inner_tag = "title";
2729 case LyXParagraph::TAB:
2730 case LyXParagraph::WIDE_TAB:
2732 inner_tag = "title";
2737 sgmlOpenTag(os, depth, tag);
2738 if ((present == TAB_LIKE) || (present == FIG_LIKE)) {
2739 DocBookHandleCaption(os, inner_tag, depth,
2743 sgmlOpenTag(os, depth + 1, inner_tag);
2746 // ignore all caption here, we processed them above!!!
2747 if (par->layout != textclasslist
2748 .NumberOfLayout(params.textclass,
2749 "Caption").second) {
2751 std::ostringstream ost;
2755 SimpleDocBookOnePar(ost, extra_par, par,
2756 desc_on, depth + 2);
2758 tmp_par += ost.str().c_str();
2761 char * ctmp = ost.str();
2766 tmp_par = frontStrip(strip(tmp_par));
2772 if(!inner_tag.empty()) sgmlCloseTag(os, depth + 1, inner_tag);
2773 if(!extra_par.empty()) os << extra_par;
2774 if(!tag.empty()) sgmlCloseTag(os, depth, tag);
2779 // push a tag in a style stack
2780 void Buffer::push_tag(ostream & os, char const * tag,
2781 int & pos, char stack[5][3])
2783 // pop all previous tags
2784 for (int j = pos; j >= 0; --j)
2785 os << "</" << stack[j] << ">";
2788 sprintf(stack[++pos], "%s", tag);
2791 for (int i = 0; i <= pos; ++i)
2792 os << "<" << stack[i] << ">";
2796 void Buffer::pop_tag(ostream & os, char const * tag,
2797 int & pos, char stack[5][3])
2801 // pop all tags till specified one
2802 for (j = pos; (j >= 0) && (strcmp(stack[j], tag)); --j)
2803 os << "</" << stack[j] << ">";
2806 os << "</" << tag << ">";
2808 // push all tags, but the specified one
2809 for (j = j + 1; j <= pos; ++j) {
2810 os << "<" << stack[j] << ">";
2811 strcpy(stack[j-1], stack[j]);
2817 // Handle internal paragraph parsing -- layout already processed.
2819 // checks, if newcol chars should be put into this line
2820 // writes newline, if necessary.
2822 void linux_doc_line_break(ostream & os, unsigned int & colcount,
2823 const unsigned int newcol)
2826 if (colcount > lyxrc.ascii_linelen) {
2828 colcount = newcol; // assume write after this call
2833 void Buffer::SimpleLinuxDocOnePar(ostream & os, LyXParagraph * par,
2834 int desc_on, int const /*depth*/)
2836 LyXFont font1, font2;
2839 LyXParagraph::size_type main_body;
2841 LyXLayout const & style = textclasslist.Style(params.textclass,
2844 char family_type = 0; // family font flag
2845 bool is_bold = false; // series font flag
2846 char shape_type = 0; // shape font flag
2847 bool is_em = false; // emphasis (italic) font flag
2849 int stack_num = -1; // style stack position
2850 // Can this be rewritten to use a std::stack, please. (Lgb)
2851 char stack[5][3]; // style stack
2852 unsigned int char_line_count = 5; // Heuristic choice ;-)
2854 if (style.labeltype != LABEL_MANUAL)
2857 main_body = par->BeginningOfMainBody();
2859 // gets paragraph main font
2861 font1 = style.labelfont;
2866 // parsing main loop
2867 for (LyXParagraph::size_type i = 0;
2868 i < par->size(); ++i) {
2880 font2 = par->getFont(params, i);
2882 if (font1.family() != font2.family()) {
2883 switch(family_type) {
2885 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2886 push_tag(os, "tt", stack_num, stack);
2889 else if (font2.family() == LyXFont::SANS_FAMILY) {
2890 push_tag(os, "sf", stack_num, stack);
2895 pop_tag(os, "tt", stack_num, stack);
2896 if (font2.family() == LyXFont::SANS_FAMILY) {
2897 push_tag(os, "sf", stack_num, stack);
2904 pop_tag(os, "sf", stack_num, stack);
2905 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2906 push_tag(os, "tt", stack_num, stack);
2915 if (font1.series() != font2.series()) {
2916 if (font2.series() == LyXFont::BOLD_SERIES) {
2917 push_tag(os, "bf", stack_num, stack);
2919 } else if (is_bold) {
2920 pop_tag(os, "bf", stack_num, stack);
2925 // handle italic and slanted fonts
2926 if (font1.shape() != font2.shape()) {
2927 switch(shape_type) {
2929 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2930 push_tag(os, "it", stack_num, stack);
2932 } else if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2933 push_tag(os, "sl", stack_num, stack);
2938 pop_tag(os, "it", stack_num, stack);
2939 if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2940 push_tag(os, "sl", stack_num, stack);
2947 pop_tag(os, "sl", stack_num, stack);
2948 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2949 push_tag(os, "it", stack_num, stack);
2957 if (font1.emph() != font2.emph()) {
2958 if (font2.emph() == LyXFont::ON) {
2959 push_tag(os, "em", stack_num, stack);
2962 pop_tag(os, "em", stack_num, stack);
2967 c = par->GetChar(i);
2969 if (c == LyXParagraph::META_INSET) {
2970 inset = par->GetInset(i);
2971 inset->Linuxdoc(this, os);
2974 if (font2.latex() == LyXFont::ON) {
2975 // "TeX"-Mode on == > SGML-Mode on.
2977 os << c; // see LaTeX-Generation...
2981 if (par->linuxDocConvertChar(c, sgml_string)
2982 && !style.free_spacing) { // in freespacing
2984 // non-breaking characters
2988 linux_doc_line_break(os, char_line_count, 6);
2992 linux_doc_line_break(os, char_line_count, 1);
2997 char_line_count += sgml_string.length();
3003 // needed if there is an optional argument but no contents
3004 if (main_body > 0 && main_body == par->size()) {
3008 // pop all defined Styles
3009 for (j = stack_num; j >= 0; --j) {
3010 linux_doc_line_break(os,
3012 3 + strlen(stack[j]));
3013 os << "</" << stack[j] << ">";
3016 // resets description flag correctly
3019 // <tag> not closed...
3020 linux_doc_line_break(os, char_line_count, 6);
3024 // fprintf(file, "</p>");
3030 // Print an error message.
3031 void Buffer::LinuxDocError(LyXParagraph * par, int pos,
3032 char const * message)
3034 // insert an error marker in text
3035 InsetError * new_inset = new InsetError(message);
3036 par->InsertInset(pos, new_inset);
3039 // This constant defines the maximum number of
3040 // environment layouts that can be nesteded.
3041 // The same applies for command layouts.
3042 // These values should be more than enough.
3043 // José Matos (1999/07/22)
3045 enum { MAX_NEST_LEVEL = 25};
3047 void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
3049 LyXParagraph * par = paragraph;
3051 niceFile = nice; // this will be used by Insetincludes.
3053 string top_element= textclasslist.LatexnameOfClass(params.textclass);
3054 // Please use a real stack.
3055 string environment_stack[MAX_NEST_LEVEL];
3056 string environment_inner[MAX_NEST_LEVEL];
3057 // Please use a real stack.
3058 string command_stack[MAX_NEST_LEVEL];
3059 bool command_flag= false;
3060 int command_depth= 0, command_base= 0, cmd_depth= 0;
3062 string item_name, command_name;
3063 string c_depth, c_params, tmps;
3065 int depth = 0; // paragraph depth
3066 LyXTextClass const & tclass =
3067 textclasslist.TextClass(params.textclass);
3069 LaTeXFeatures features(params, tclass.numLayouts());
3073 tex_code_break_column = lyxrc.ascii_linelen;
3075 //tex_code_break_column = 0;
3077 ofstream ofs(fname.c_str());
3079 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
3086 string sgml_includedfiles=features.getIncludedFiles();
3088 ofs << "<!doctype " << top_element
3089 << " public \"-//OASIS//DTD DocBook V3.1//EN\"";
3091 if (params.preamble.empty() && sgml_includedfiles.empty())
3094 ofs << "\n [ " << params.preamble
3095 << sgml_includedfiles << " \n]>\n\n";
3097 if(params.options.empty())
3098 sgmlOpenTag(ofs, 0, top_element);
3100 string top = top_element;
3102 top += params.options;
3103 sgmlOpenTag(ofs, 0, top);
3107 ofs << "<!-- DocBook file was created by " << LYX_DOCVERSION
3108 << "\n See http://www.lyx.org/ for more information -->\n";
3111 int desc_on = 0; // description mode
3112 LyXLayout const & style =
3113 textclasslist.Style(params.textclass,
3116 // environment tag closing
3117 for( ; depth > par->depth; --depth) {
3118 if(environment_inner[depth] != "!-- --") {
3119 item_name= "listitem";
3120 sgmlCloseTag(ofs, command_depth + depth,
3122 if( environment_inner[depth] == "varlistentry")
3123 sgmlCloseTag(ofs, depth+command_depth,
3124 environment_inner[depth]);
3126 sgmlCloseTag(ofs, depth + command_depth,
3127 environment_stack[depth]);
3128 environment_stack[depth].erase();
3129 environment_inner[depth].erase();
3132 if(depth == par->depth
3133 && environment_stack[depth] != style.latexname()
3134 && !environment_stack[depth].empty()) {
3135 if(environment_inner[depth] != "!-- --") {
3136 item_name= "listitem";
3137 sgmlCloseTag(ofs, command_depth+depth,
3139 if( environment_inner[depth] == "varlistentry")
3141 depth + command_depth,
3142 environment_inner[depth]);
3145 sgmlCloseTag(ofs, depth + command_depth,
3146 environment_stack[depth]);
3148 environment_stack[depth].erase();
3149 environment_inner[depth].erase();
3152 // Write opening SGML tags.
3153 switch(style.latextype) {
3154 case LATEX_PARAGRAPH:
3155 if(style.latexname() != "dummy")
3156 sgmlOpenTag(ofs, depth+command_depth,
3162 LinuxDocError(par, 0,
3163 _("Error : Wrong depth for "
3164 "LatexType Command.\n"));
3166 command_name = style.latexname();
3168 tmps = style.latexparam();
3169 c_params = split(tmps, c_depth,'|');
3171 cmd_depth= atoi(c_depth.c_str());
3174 if(cmd_depth<command_base) {
3175 for(int j = command_depth;
3176 j >= command_base; --j)
3177 if(!command_stack[j].empty())
3178 sgmlCloseTag(ofs, j, command_stack[j]);
3179 command_depth= command_base= cmd_depth;
3180 } else if(cmd_depth <= command_depth) {
3181 for(int j = command_depth;
3182 j >= cmd_depth; --j)
3184 if(!command_stack[j].empty())
3185 sgmlCloseTag(ofs, j, command_stack[j]);
3186 command_depth= cmd_depth;
3188 command_depth= cmd_depth;
3190 command_depth = command_base = cmd_depth;
3191 command_flag = true;
3193 command_stack[command_depth]= command_name;
3195 // treat label as a special case for
3196 // more WYSIWYM handling.
3197 if (par->GetChar(0) == LyXParagraph::META_INSET) {
3198 Inset * inset = par->GetInset(0);
3199 Inset::Code lyx_code = inset->LyxCode();
3200 if (lyx_code == Inset::LABEL_CODE){
3201 command_name += " id=\"";
3202 command_name += (static_cast<InsetCommand *>(inset))->getContents();
3203 command_name += "\"";
3208 sgmlOpenTag(ofs, depth + command_depth, command_name);
3209 item_name = "title";
3210 sgmlOpenTag(ofs, depth + 1 + command_depth, item_name);
3213 case LATEX_ENVIRONMENT:
3214 case LATEX_ITEM_ENVIRONMENT:
3215 if (depth < par->depth) {
3217 environment_stack[depth].erase();
3220 if (environment_stack[depth] != style.latexname()) {
3221 environment_stack[depth] = style.latexname();
3222 environment_inner[depth] = "!-- --";
3223 sgmlOpenTag(ofs, depth + command_depth,
3224 environment_stack[depth]);
3226 if(environment_inner[depth] != "!-- --") {
3227 item_name= "listitem";
3229 command_depth + depth,
3231 if (environment_inner[depth] == "varlistentry")
3233 depth + command_depth,
3234 environment_inner[depth]);
3238 if(style.latextype == LATEX_ENVIRONMENT) {
3239 if(!style.latexparam().empty())
3240 sgmlOpenTag(ofs, depth + command_depth,
3241 style.latexparam());
3245 desc_on = (style.labeltype == LABEL_MANUAL);
3248 environment_inner[depth]= "varlistentry";
3250 environment_inner[depth]= "listitem";
3252 sgmlOpenTag(ofs, depth + 1 + command_depth,
3253 environment_inner[depth]);
3257 sgmlOpenTag(ofs, depth + 1 + command_depth,
3261 sgmlOpenTag(ofs, depth + 1 + command_depth,
3266 sgmlOpenTag(ofs, depth + command_depth,
3275 SimpleDocBookOnePar(ofs, extra_par, par, desc_on,
3276 depth + 1 + command_depth);
3279 DocBookHandleFootnote(ofs, par,
3280 depth + 1 + command_depth);
3282 while(par && par->IsDummy());
3285 // write closing SGML tags
3286 switch(style.latextype) {
3289 sgmlCloseTag(ofs, depth + command_depth, end_tag);
3291 case LATEX_ENVIRONMENT:
3292 if(!style.latexparam().empty())
3293 sgmlCloseTag(ofs, depth + command_depth,
3294 style.latexparam());
3296 case LATEX_ITEM_ENVIRONMENT:
3297 if(desc_on == 1) break;
3299 sgmlCloseTag(ofs, depth + 1 + command_depth, end_tag);
3301 case LATEX_PARAGRAPH:
3302 if(style.latexname() != "dummy")
3303 sgmlCloseTag(ofs, depth + command_depth,
3307 sgmlCloseTag(ofs, depth + command_depth,
3314 for(; depth >= 0; --depth) {
3315 if(!environment_stack[depth].empty()) {
3316 if(environment_inner[depth] != "!-- --") {
3317 item_name= "listitem";
3318 sgmlCloseTag(ofs, command_depth + depth,
3320 if( environment_inner[depth] == "varlistentry")
3321 sgmlCloseTag(ofs, depth + command_depth,
3322 environment_inner[depth]);
3325 sgmlCloseTag(ofs, depth + command_depth,
3326 environment_stack[depth]);
3330 for(int j = command_depth; j >= command_base; --j)
3331 if(!command_stack[j].empty())
3332 sgmlCloseTag(ofs, j, command_stack[j]);
3336 sgmlCloseTag(ofs, 0, top_element);
3340 // How to check for successful close
3344 void Buffer::SimpleDocBookOnePar(ostream & os, string & extra,
3345 LyXParagraph * par, int & desc_on,
3350 par->SimpleDocBookOneTablePar(this,
3351 os, extra, desc_on, depth);
3356 bool emph_flag = false;
3358 LyXLayout const & style = textclasslist.Style(params.textclass,
3361 LyXParagraph::size_type main_body;
3362 if (style.labeltype != LABEL_MANUAL)
3365 main_body = par->BeginningOfMainBody();
3367 // gets paragraph main font
3368 LyXFont font1 = main_body > 0 ? style.labelfont : style.font;
3370 int char_line_count = depth;
3371 if(!style.free_spacing)
3372 for (int j = 0; j < depth; ++j)
3375 // parsing main loop
3376 for (LyXParagraph::size_type i = 0;
3377 i < par->size(); ++i) {
3378 LyXFont font2 = par->getFont(params, i);
3380 // handle <emphasis> tag
3381 if (font1.emph() != font2.emph() && i) {
3382 if (font2.emph() == LyXFont::ON) {
3386 os << "</emphasis>";
3391 char c = par->GetChar(i);
3393 if (c == LyXParagraph::META_INSET) {
3394 Inset * inset = par->GetInset(i);
3396 std::ostringstream ost;
3397 inset->DocBook(this, ost);
3398 string tmp_out = ost.str().c_str();
3401 inset->DocBook(this, ost);
3403 char * ctmp = ost.str();
3404 string tmp_out(ctmp);
3408 // This code needs some explanation:
3409 // Two insets are treated specially
3410 // label if it is the first element in a command paragraph
3412 // graphics inside tables or figure floats can't go on
3413 // title (the equivalente in latex for this case is caption
3414 // and title should come first
3417 if(desc_on!= 3 || i!= 0) {
3418 if(!tmp_out.empty() && tmp_out[0] == '@') {
3420 extra += frontStrip(tmp_out, '@');
3422 os << frontStrip(tmp_out, '@');
3427 } else if (font2.latex() == LyXFont::ON) {
3428 // "TeX"-Mode on ==> SGML-Mode on.
3434 if (par->linuxDocConvertChar(c, sgml_string)
3435 && !style.free_spacing) { // in freespacing
3437 // non-breaking characters
3441 os << "\n</term><listitem><para>";
3453 // needed if there is an optional argument but no contents
3454 if (main_body > 0 && main_body == par->size()) {
3458 os << "</emphasis>";
3461 // resets description flag correctly
3464 // <term> not closed...
3472 int Buffer::runLaTeX()
3474 if (!users->text) return 0;
3476 ProhibitInput(users);
3478 // get LaTeX-Filename
3479 string name = getLatexName();
3481 string path = OnlyPath(filename);
3483 string org_path = path;
3484 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3488 Path p(path); // path to LaTeX file
3489 users->owner()->getMiniBuffer()->Set(_("Running LaTeX..."));
3491 // Remove all error insets
3492 bool a = users->removeAutoInsets();
3494 // Always generate the LaTeX file
3495 makeLaTeXFile(name, org_path, false);
3497 // do the LaTex run(s)
3499 string latex_command = lyxrc.pdf_mode ?
3500 lyxrc.pdflatex_command : lyxrc.latex_command;
3501 LaTeX latex(latex_command, name, filepath);
3502 int res = latex.run(terr,
3503 users->owner()->getMiniBuffer()); // running latex
3505 // check return value from latex.run().
3506 if ((res & LaTeX::NO_LOGFILE)) {
3507 WriteAlert(_("LaTeX did not work!"),
3508 _("Missing log file:"), name);
3509 } else if ((res & LaTeX::ERRORS)) {
3510 users->owner()->getMiniBuffer()->Set(_("Done"));
3511 // Insert all errors as errors boxes
3512 users->insertErrors(terr);
3514 // Dvi should also be kept dirty if the latex run
3515 // ends up with errors. However it should be possible
3516 // to view a dirty dvi too.
3518 //no errors or any other things to think about so:
3519 users->owner()->getMiniBuffer()->Set(_("Done"));
3522 // if we removed error insets before we ran LaTeX or if we inserted
3523 // error insets after we ran LaTeX this must be run:
3524 if (a || (res & LaTeX::ERRORS)){
3527 //users->updateScrollbar();
3531 return latex.getNumErrors();
3535 int Buffer::runLiterate()
3537 if (!users->text) return 0;
3539 ProhibitInput(users);
3541 // get LaTeX-Filename
3542 string name = getLatexName();
3543 // get Literate-Filename
3544 string lit_name = OnlyFilename(ChangeExtension (getLatexName(),
3545 lyxrc.literate_extension));
3547 string path = OnlyPath(filename);
3549 string org_path = path;
3550 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3554 Path p(path); // path to Literate file
3555 users->owner()->getMiniBuffer()->Set(_("Running Literate..."));
3557 // Remove all error insets
3558 bool removedErrorInsets = users->removeAutoInsets();
3560 // generate the Literate file if necessary
3561 makeLaTeXFile(lit_name, org_path, false);
3563 string latex_command = lyxrc.pdf_mode ?
3564 lyxrc.pdflatex_command : lyxrc.latex_command;
3565 Literate literate(latex_command, name, filepath,
3567 lyxrc.literate_command, lyxrc.literate_error_filter,
3568 lyxrc.build_command, lyxrc.build_error_filter);
3570 int res = literate.weave(terr, users->owner()->getMiniBuffer());
3572 // check return value from literate.weave().
3573 if ((res & Literate::NO_LOGFILE)) {
3574 WriteAlert(_("Literate command did not work!"),
3575 _("Missing log file:"), name);
3576 } else if ((res & Literate::ERRORS)) {
3577 users->owner()->getMiniBuffer()->Set(_("Done"));
3578 // Insert all errors as errors boxes
3579 users->insertErrors(terr);
3581 // Dvi should also be kept dirty if the latex run
3582 // ends up with errors. However it should be possible
3583 // to view a dirty dvi too.
3585 //no errors or any other things to think about so:
3586 users->owner()->getMiniBuffer()->Set(_("Done"));
3589 // if we removed error insets before we ran LaTeX or if we inserted
3590 // error insets after we ran LaTeX this must be run:
3591 if (removedErrorInsets || (res & Literate::ERRORS)){
3594 //users->updateScrollbar();
3598 return literate.getNumErrors();
3602 int Buffer::buildProgram()
3604 if (!users->text) return 0;
3606 ProhibitInput(users);
3608 // get LaTeX-Filename
3609 string name = getLatexName();
3610 // get Literate-Filename
3611 string lit_name = OnlyFilename(ChangeExtension(getLatexName(),
3612 lyxrc.literate_extension));
3614 string path = OnlyPath(filename);
3616 string org_path = path;
3617 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3621 Path p(path); // path to Literate file
3622 users->owner()->getMiniBuffer()->Set(_("Building Program..."));
3624 // Remove all error insets
3625 bool removedErrorInsets = users->removeAutoInsets();
3627 // generate the LaTeX file if necessary
3628 if (!isNwClean() || removedErrorInsets) {
3629 makeLaTeXFile(lit_name, org_path, false);
3633 string latex_command = lyxrc.pdf_mode ?
3634 lyxrc.pdflatex_command : lyxrc.latex_command;
3635 Literate literate(latex_command, name, filepath,
3637 lyxrc.literate_command, lyxrc.literate_error_filter,
3638 lyxrc.build_command, lyxrc.build_error_filter);
3640 int res = literate.build(terr, users->owner()->getMiniBuffer());
3642 // check return value from literate.build().
3643 if ((res & Literate::NO_LOGFILE)) {
3644 WriteAlert(_("Build did not work!"),
3645 _("Missing log file:"), name);
3646 } else if ((res & Literate::ERRORS)) {
3647 users->owner()->getMiniBuffer()->Set(_("Done"));
3648 // Insert all errors as errors boxes
3649 users->insertErrors(terr);
3651 // Literate files should also be kept dirty if the literate
3652 // command run ends up with errors.
3654 //no errors or any other things to think about so:
3655 users->owner()->getMiniBuffer()->Set(_("Done"));
3659 // if we removed error insets before we ran Literate/Build or
3660 // if we inserted error insets after we ran Literate/Build this
3662 if (removedErrorInsets || (res & Literate::ERRORS)){
3665 //users->updateScrollbar();
3669 return literate.getNumErrors();
3673 // This should be enabled when the Chktex class is implemented. (Asger)
3674 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
3675 // Other flags: -wall -v0 -x
3676 int Buffer::runChktex()
3678 if (!users->text) return 0;
3680 ProhibitInput(users);
3682 // get LaTeX-Filename
3683 string name = getLatexName();
3684 string path = OnlyPath(filename);
3686 string org_path = path;
3687 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3691 Path p(path); // path to LaTeX file
3692 users->owner()->getMiniBuffer()->Set(_("Running chktex..."));
3694 // Remove all error insets
3695 bool removedErrorInsets = users->removeAutoInsets();
3697 // Generate the LaTeX file if neccessary
3698 makeLaTeXFile(name, org_path, false);
3701 Chktex chktex(lyxrc.chktex_command, name, filepath);
3702 int res = chktex.run(terr); // run chktex
3705 WriteAlert(_("chktex did not work!"),
3706 _("Could not run with file:"), name);
3707 } else if (res > 0) {
3708 // Insert all errors as errors boxes
3709 users->insertErrors(terr);
3712 // if we removed error insets before we ran chktex or if we inserted
3713 // error insets after we ran chktex, this must be run:
3714 if (removedErrorInsets || res){
3717 //users->updateScrollbar();
3725 void Buffer::validate(LaTeXFeatures & features) const
3727 LyXParagraph * par = paragraph;
3728 LyXTextClass const & tclass =
3729 textclasslist.TextClass(params.textclass);
3731 // AMS Style is at document level
3733 features.amsstyle = (params.use_amsmath ||
3734 tclass.provides(LyXTextClass::amsmath));
3737 // We don't use "lyxerr.debug" because of speed. (Asger)
3738 if (lyxerr.debugging(Debug::LATEX))
3739 lyxerr << "Paragraph: " << par << endl;
3741 // Now just follow the list of paragraphs and run
3742 // validate on each of them.
3743 par->validate(features);
3745 // and then the next paragraph
3749 // the bullet shapes are buffer level not paragraph level
3750 // so they are tested here
3751 for (int i = 0; i < 4; ++i) {
3752 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
3753 int font = params.user_defined_bullets[i].getFont();
3756 .user_defined_bullets[i]
3763 features.latexsym = true;
3767 features.amssymb = true;
3769 else if ((font >= 2 && font <= 5)) {
3770 features.pifont = true;
3775 if (lyxerr.debugging(Debug::LATEX)) {
3776 features.showStruct();
3781 void Buffer::setPaperStuff()
3783 params.papersize = BufferParams::PAPER_DEFAULT;
3784 char c1 = params.paperpackage;
3785 if (c1 == BufferParams::PACKAGE_NONE) {
3786 char c2 = params.papersize2;
3787 if (c2 == BufferParams::VM_PAPER_USLETTER)
3788 params.papersize = BufferParams::PAPER_USLETTER;
3789 else if (c2 == BufferParams::VM_PAPER_USLEGAL)
3790 params.papersize = BufferParams::PAPER_LEGALPAPER;
3791 else if (c2 == BufferParams::VM_PAPER_USEXECUTIVE)
3792 params.papersize = BufferParams::PAPER_EXECUTIVEPAPER;
3793 else if (c2 == BufferParams::VM_PAPER_A3)
3794 params.papersize = BufferParams::PAPER_A3PAPER;
3795 else if (c2 == BufferParams::VM_PAPER_A4)
3796 params.papersize = BufferParams::PAPER_A4PAPER;
3797 else if (c2 == BufferParams::VM_PAPER_A5)
3798 params.papersize = BufferParams::PAPER_A5PAPER;
3799 else if ((c2 == BufferParams::VM_PAPER_B3) || (c2 == BufferParams::VM_PAPER_B4) ||
3800 (c2 == BufferParams::VM_PAPER_B5))
3801 params.papersize = BufferParams::PAPER_B5PAPER;
3802 } else if ((c1 == BufferParams::PACKAGE_A4) || (c1 == BufferParams::PACKAGE_A4WIDE) ||
3803 (c1 == BufferParams::PACKAGE_WIDEMARGINSA4))
3804 params.papersize = BufferParams::PAPER_A4PAPER;
3808 // This function should be in Buffer because it's a buffer's property (ale)
3809 string Buffer::getIncludeonlyList(char delim)
3812 for (inset_iterator it = inset_iterator_begin();
3813 it != inset_iterator_end(); ++it) {
3814 if ((*it)->LyxCode() == Inset::INCLUDE_CODE) {
3815 InsetInclude * insetinc =
3816 static_cast<InsetInclude *>(*it);
3817 if (insetinc->isInclude()
3818 && insetinc->isNoLoad()) {
3821 lst += OnlyFilename(ChangeExtension(insetinc->getContents(), string()));
3825 lyxerr.debug() << "Includeonly(" << lst << ')' << endl;
3830 vector<string> Buffer::getLabelList()
3832 /// if this is a child document and the parent is already loaded
3833 /// Use the parent's list instead [ale990407]
3834 if (!params.parentname.empty()
3835 && bufferlist.exists(params.parentname)) {
3836 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3838 return tmp->getLabelList();
3841 vector<string> label_list;
3842 for (inset_iterator it = inset_iterator_begin();
3843 it != inset_iterator_end(); ++it) {
3844 vector<string> l = (*it)->getLabelList();
3845 label_list.insert(label_list.end(), l.begin(), l.end());
3851 vector<vector<Buffer::TocItem> > Buffer::getTocList()
3853 vector<vector<TocItem> > l(4);
3854 LyXParagraph * par = paragraph;
3857 if (par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
3858 if (textclasslist.Style(params.textclass,
3859 par->GetLayout()).labeltype
3860 == LABEL_SENSITIVE) {
3864 tmp.str = par->String(this, false);
3865 switch (par->footnotekind) {
3866 case LyXParagraph::FIG:
3867 case LyXParagraph::WIDE_FIG:
3868 l[TOC_LOF].push_back(tmp);
3870 case LyXParagraph::TAB:
3871 case LyXParagraph::WIDE_TAB:
3872 l[TOC_LOT].push_back(tmp);
3874 case LyXParagraph::ALGORITHM:
3875 l[TOC_LOA].push_back(tmp);
3877 case LyXParagraph::FOOTNOTE:
3878 case LyXParagraph::MARGIN:
3882 } else if (!par->IsDummy()) {
3884 char labeltype = textclasslist.Style(params.textclass,
3885 par->GetLayout()).labeltype;
3887 if (labeltype >= LABEL_COUNTER_CHAPTER
3888 && labeltype <= LABEL_COUNTER_CHAPTER + params.tocdepth) {
3889 // insert this into the table of contents
3894 textclasslist.TextClass(params.textclass).maxcounter());
3895 tmp.str = par->String(this, true);
3896 l[TOC_TOC].push_back(tmp);
3906 // This is also a buffer property (ale)
3907 vector<pair<string,string> > Buffer::getBibkeyList()
3909 /// if this is a child document and the parent is already loaded
3910 /// Use the parent's list instead [ale990412]
3911 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3912 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3914 return tmp->getBibkeyList();
3917 vector<pair<string, string> > keys;
3918 LyXParagraph * par = paragraph;
3921 keys.push_back(pair<string, string>(par->bibkey->getContents(),
3922 par->String(this, false)));
3926 // Might be either using bibtex or a child has bibliography
3928 for (inset_iterator it = inset_iterator_begin();
3929 it != inset_iterator_end(); ++it) {
3930 // Search for Bibtex or Include inset
3931 if ((*it)->LyxCode() == Inset::BIBTEX_CODE) {
3932 vector<pair<string,string> > tmp =
3933 static_cast<InsetBibtex*>(*it)->getKeys();
3934 keys.insert(keys.end(), tmp.begin(), tmp.end());
3935 } else if ((*it)->LyxCode() == Inset::INCLUDE_CODE) {
3936 vector<pair<string,string> > tmp =
3937 static_cast<InsetInclude*>(*it)->getKeys();
3938 keys.insert(keys.end(), tmp.begin(), tmp.end());
3947 bool Buffer::isDepClean(string const & name) const
3949 DEPCLEAN * item = dep_clean;
3950 while (item && item->master != name)
3952 if (!item) return true;
3957 void Buffer::markDepClean(string const & name)
3960 dep_clean = new DEPCLEAN;
3961 dep_clean->clean = true;
3962 dep_clean->master = name;
3963 dep_clean->next = 0;
3965 DEPCLEAN* item = dep_clean;
3966 while (item && item->master != name)
3971 item = new DEPCLEAN;
3973 item->master = name;
3980 bool Buffer::Dispatch(string const & command)
3982 // Split command string into command and argument
3983 string cmd, line = frontStrip(command);
3984 string arg = strip(frontStrip(split(line, cmd, ' ')));
3986 return Dispatch(lyxaction.LookupFunc(cmd.c_str()), arg.c_str());
3990 bool Buffer::Dispatch(int action, string const & argument)
3992 bool dispatched = true;
3995 MenuExport(this, argument);
4005 void Buffer::resize()
4007 /// resize the BufferViews!
4013 void Buffer::resizeInsets(BufferView * bv)
4015 /// then remove all LyXText in text-insets
4016 LyXParagraph * par = paragraph;
4017 for(;par;par = par->next) {
4018 par->resizeInsetsLyXText(bv);
4022 void Buffer::ChangeLanguage(Language const * from, Language const * to)
4025 LyXParagraph * par = paragraph;
4027 par->ChangeLanguage(params, from, to);
4033 bool Buffer::isMultiLingual()
4036 LyXParagraph * par = paragraph;
4038 if (par->isMultiLingual(params))
4046 Buffer::inset_iterator::inset_iterator(LyXParagraph * paragraph,
4047 LyXParagraph::size_type pos)
4049 it = par->InsetIterator(pos);
4050 if (it == par->inset_iterator_end()) {
4057 void Buffer::inset_iterator::SetParagraph() {
4059 it = par->inset_iterator_begin();
4060 if (it != par->inset_iterator_end())
4065 // We maintain an invariant that whenever par = 0 then it = 0