-#ifdef USE_CAPTION
- // The is the compability reading of layout caption.
- // It can be removed in LyX version 1.3.0. (Lgb)
- if (compare_ascii_no_case(layoutname, "caption") == 0) {
- // We expect that the par we are now working on is
- // really inside a InsetText inside a InsetFloat.
- // We also know that captions can only be
- // one paragraph. (Lgb)
-
- // We should now read until the next "\layout"
- // is reached.
- // This is probably not good enough, what if the
- // caption is the last par in the document (Lgb)
- istream & ist = lex.getStream();
- stringstream ss;
- string line;
- int begin = 0;
- while (true) {
- getline(ist, line);
- if (prefixIs(line, "\\layout")) {
- lex.pushToken(line);
- break;
- }
- if (prefixIs(line, "\\begin_inset"))
- ++begin;
- if (prefixIs(line, "\\end_inset")) {
- if (begin)
- --begin;
- else {
- lex.pushToken(line);
- break;
- }
- }
-
- ss << line << '\n';
- }
- // Now we should have the whole layout in ss
- // we should now be able to give this to the
- // caption inset.
- ss << "\\end_inset\n";
-
- // This seems like a bug in stringstream.
- // We really should be able to use ss
- // directly. (Lgb)
- istringstream is(ss.str());
- LyXLex tmplex(0, 0);
- tmplex.setStream(is);
- Inset * inset = new InsetCaption;
- inset->Read(this, tmplex);
- par->InsertInset(pos, inset, font);
- ++pos;
- } else {
-#endif
- if (!first_par)
- first_par = par;
- else {
- par = new Paragraph(par);
- par->layout(params.getLyXTextClass().defaultLayout());
- if (params.tracking_changes)
- par->trackChanges();
- }
- pos = 0;
- par->layout(params.getLyXTextClass()[layoutname]);
- // Test whether the layout is obsolete.
- LyXLayout_ptr const & layout = par->layout();
- if (!layout->obsoleted_by().empty())
- par->layout(params.getLyXTextClass()[layout->obsoleted_by()]);
- par->params().depth(depth);
-#if USE_CAPTION
- }
-#endif
-
- } else if (token == "\\end_inset") {
- lyxerr << "Solitary \\end_inset. Missing \\begin_inset?.\n"
- << "Last inset read was: " << last_inset_read
- << endl;
- // Simply ignore this. The insets do not have
- // to read this.
- // But insets should read it, it is a part of
- // the inset isn't it? Lgb.
- } else if (token == "\\begin_inset") {
- readInset(lex, par, pos, font);
- } else if (token == "\\family") {
- lex.next();
- font.setLyXFamily(lex.getString());
- } else if (token == "\\series") {
- lex.next();
- font.setLyXSeries(lex.getString());
- } else if (token == "\\shape") {
- lex.next();
- font.setLyXShape(lex.getString());
- } else if (token == "\\size") {
- lex.next();
- font.setLyXSize(lex.getString());
- } else if (token == "\\lang") {
- lex.next();
- string const tok = lex.getString();
- Language const * lang = languages.getLanguage(tok);
- if (lang) {
- font.setLanguage(lang);
- } else {
- font.setLanguage(params.language);
- lex.printError("Unknown language `$$Token'");
- }
- } else if (token == "\\numeric") {
- lex.next();
- font.setNumber(font.setLyXMisc(lex.getString()));
- } else if (token == "\\emph") {
- lex.next();
- font.setEmph(font.setLyXMisc(lex.getString()));
- } else if (token == "\\bar") {
- lex.next();
- string const tok = lex.getString();
- // This is dirty, but gone with LyX3. (Asger)
- if (tok == "under")
- font.setUnderbar(LyXFont::ON);
- else if (tok == "no")
- font.setUnderbar(LyXFont::OFF);
- else if (tok == "default")
- font.setUnderbar(LyXFont::INHERIT);
- else
- lex.printError("Unknown bar font flag "
- "`$$Token'");
- } else if (token == "\\noun") {
- lex.next();
- font.setNoun(font.setLyXMisc(lex.getString()));
- } else if (token == "\\color") {
- lex.next();
- font.setLyXColor(lex.getString());
- } else if (token == "\\SpecialChar") {
- LyXLayout_ptr const & layout = par->layout();
-
- // Insets don't make sense in a free-spacing context! ---Kayvan
- if (layout->free_spacing || par->isFreeSpacing()) {
- if (lex.isOK()) {
- lex.next();
- string const next_token = lex.getString();
- if (next_token == "\\-") {
- par->insertChar(pos, '-', font, current_change);
- } else if (next_token == "~") {
- par->insertChar(pos, ' ', font, current_change);
- } else {
- lex.printError("Token `$$Token' "
- "is in free space "
- "paragraph layout!");
- --pos;
- }
- }
- } else {
- Inset * inset = new InsetSpecialChar;
- inset->read(this, lex);
- par->insertInset(pos, inset, font, current_change);
- }
- ++pos;
- } else if (token == "\\i") {
- Inset * inset = new InsetLatexAccent;
- inset->read(this, lex);
- par->insertInset(pos, inset, font, current_change);
- ++pos;
- } else if (token == "\\backslash") {
- par->insertChar(pos, '\\', font, current_change);
- ++pos;
- } else if (token == "\\begin_deeper") {
- ++depth;
- } else if (token == "\\end_deeper") {
- if (!depth) {
- lex.printError("\\end_deeper: "
- "depth is already null");
- }
- else
- --depth;
- } else if (token == "\\begin_preamble") {
- params.readPreamble(lex);
- } else if (token == "\\textclass") {
- lex.eatLine();
- pair<bool, textclass_type> pp =
- textclasslist.NumberOfClass(lex.getString());
- if (pp.first) {
- params.textclass = pp.second;
- } else {
-#if USE_BOOST_FORMAT
- Alert::alert(_("Textclass error"),
- boost::io::str(boost::format(_("The document uses an unknown textclass \"%1$s\".")) % lex.getString()),
- _("-- substituting default."));
-#else
- Alert::alert(
- _("Textclass error"),
- _("The document uses an unknown textclass ")
- + lex.getString(),
- _("-- substituting default."));
-#endif
- params.textclass = 0;
- }
- if (!params.getLyXTextClass().load()) {
- // if the textclass wasn't loaded properly
- // we need to either substitute another
- // or stop loading the file.
- // I can substitute but I don't see how I can
- // stop loading... ideas?? ARRae980418
-#if USE_BOOST_FORMAT
- Alert::alert(_("Textclass Loading Error!"),
- boost::io::str(boost::format(_("Can't load textclass %1$s")) %
- params.getLyXTextClass().name()),
- _("-- substituting default."));
-#else
- Alert::alert(_("Textclass Loading Error!"),
- _("Can't load textclass ")
- + params.getLyXTextClass().name(),
- _("-- substituting default."));
-#endif
- params.textclass = 0;
- }
- } else if (token == "\\options") {
- lex.eatLine();
- params.options = lex.getString();
- } else if (token == "\\language") {
- params.readLanguage(lex);
- } else if (token == "\\fontencoding") {
- lex.eatLine();
- } else if (token == "\\inputencoding") {
- lex.eatLine();
- params.inputenc = lex.getString();
- } else if (token == "\\graphics") {
- params.readGraphicsDriver(lex);
- } else if (token == "\\fontscheme") {
- lex.eatLine();
- params.fonts = lex.getString();
- } else if (token == "\\noindent") {
- par->params().noindent(true);
- } else if (token == "\\leftindent") {
- lex.nextToken();
- LyXLength value(lex.getString());
- par->params().leftIndent(value);
- } else if (token == "\\fill_top") {
- par->params().spaceTop(VSpace(VSpace::VFILL));
- } else if (token == "\\fill_bottom") {
- par->params().spaceBottom(VSpace(VSpace::VFILL));
- } else if (token == "\\line_top") {
- par->params().lineTop(true);
- } else if (token == "\\line_bottom") {
- par->params().lineBottom(true);
- } else if (token == "\\pagebreak_top") {
- par->params().pagebreakTop(true);
- } else if (token == "\\pagebreak_bottom") {
- par->params().pagebreakBottom(true);
- } else if (token == "\\start_of_appendix") {
- par->params().startOfAppendix(true);
- } else if (token == "\\paragraph_separation") {
- int tmpret = lex.findToken(string_paragraph_separation);
- if (tmpret == -1)
- ++tmpret;
- params.paragraph_separation =
- static_cast<BufferParams::PARSEP>(tmpret);
- } else if (token == "\\defskip") {
- lex.nextToken();
- params.defskip = VSpace(lex.getString());
- } else if (token == "\\quotes_language") {
- int tmpret = lex.findToken(string_quotes_language);
- if (tmpret == -1)
- ++tmpret;
- InsetQuotes::quote_language tmpl =
- InsetQuotes::EnglishQ;
- switch (tmpret) {
- case 0:
- tmpl = InsetQuotes::EnglishQ;
- break;
- case 1:
- tmpl = InsetQuotes::SwedishQ;
- break;
- case 2:
- tmpl = InsetQuotes::GermanQ;
- break;
- case 3:
- tmpl = InsetQuotes::PolishQ;
- break;
- case 4:
- tmpl = InsetQuotes::FrenchQ;
- break;
- case 5:
- tmpl = InsetQuotes::DanishQ;
- break;
- }
- params.quotes_language = tmpl;
- } else if (token == "\\quotes_times") {
- lex.nextToken();
- switch (lex.getInteger()) {
- case 1:
- params.quotes_times = InsetQuotes::SingleQ;
- break;
- case 2:
- params.quotes_times = InsetQuotes::DoubleQ;
- break;
- }
- } else if (token == "\\papersize") {
- int tmpret = lex.findToken(string_papersize);
- if (tmpret == -1)
- ++tmpret;
- else
- params.papersize2 = tmpret;
- } else if (token == "\\paperpackage") {
- int tmpret = lex.findToken(string_paperpackages);
- if (tmpret == -1) {
- ++tmpret;
- params.paperpackage = BufferParams::PACKAGE_NONE;
- } else
- params.paperpackage = tmpret;
- } else if (token == "\\use_geometry") {
- lex.nextToken();
- params.use_geometry = lex.getInteger();
- } else if (token == "\\use_amsmath") {
- lex.nextToken();
- params.use_amsmath = lex.getInteger();
- } else if (token == "\\use_natbib") {
- lex.nextToken();
- params.use_natbib = lex.getInteger();
- } else if (token == "\\use_numerical_citations") {
- lex.nextToken();
- params.use_numerical_citations = lex.getInteger();
- } else if (token == "\\tracking_changes") {
- lex.nextToken();
- params.tracking_changes = lex.getInteger();
- // mark the first paragraph
- if (params.tracking_changes)
- par->trackChanges();
- } else if (token == "\\author") {
- lex.nextToken();
- istringstream ss(lex.getString());
- Author a;
- ss >> a;
- int aid(authorlist.record(a));
- lyxerr << "aid is " << aid << endl;
- lyxerr << "listed aid is " << author_ids.size() << endl;
- author_ids.push_back(authorlist.record(a));
- } else if (token == "\\paperorientation") {
- int tmpret = lex.findToken(string_orientation);
- if (tmpret == -1)
- ++tmpret;
- params.orientation =
- static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
- } else if (token == "\\paperwidth") {
- lex.next();
- params.paperwidth = lex.getString();
- } else if (token == "\\paperheight") {
- lex.next();
- params.paperheight = lex.getString();
- } else if (token == "\\leftmargin") {
- lex.next();
- params.leftmargin = lex.getString();
- } else if (token == "\\topmargin") {
- lex.next();
- params.topmargin = lex.getString();
- } else if (token == "\\rightmargin") {
- lex.next();
- params.rightmargin = lex.getString();
- } else if (token == "\\bottommargin") {
- lex.next();
- params.bottommargin = lex.getString();
- } else if (token == "\\headheight") {
- lex.next();
- params.headheight = lex.getString();
- } else if (token == "\\headsep") {
- lex.next();
- params.headsep = lex.getString();
- } else if (token == "\\footskip") {
- lex.next();
- params.footskip = lex.getString();
- } else if (token == "\\paperfontsize") {
- lex.nextToken();
- params.fontsize = rtrim(lex.getString());
- } else if (token == "\\papercolumns") {
- lex.nextToken();
- params.columns = lex.getInteger();
- } else if (token == "\\papersides") {
- lex.nextToken();
- switch (lex.getInteger()) {
- default:
- case 1: params.sides = LyXTextClass::OneSide; break;
- case 2: params.sides = LyXTextClass::TwoSides; break;
- }
- } else if (token == "\\paperpagestyle") {
- lex.nextToken();
- params.pagestyle = rtrim(lex.getString());
- } else if (token == "\\bullet") {
- lex.nextToken();
- int const index = lex.getInteger();
- lex.nextToken();
- int temp_int = lex.getInteger();
- params.user_defined_bullets[index].setFont(temp_int);
- params.temp_bullets[index].setFont(temp_int);
- lex.nextToken();
- temp_int = lex.getInteger();
- params.user_defined_bullets[index].setCharacter(temp_int);
- params.temp_bullets[index].setCharacter(temp_int);
- lex.nextToken();
- temp_int = lex.getInteger();
- params.user_defined_bullets[index].setSize(temp_int);
- params.temp_bullets[index].setSize(temp_int);
- lex.nextToken();
- string const temp_str = lex.getString();
- if (temp_str != "\\end_bullet") {
- // this element isn't really necessary for
- // parsing but is easier for humans
- // to understand bullets. Put it back and
- // set a debug message?
- lex.printError("\\end_bullet expected, got" + temp_str);
- //how can I put it back?
- }
- } else if (token == "\\bulletLaTeX") {
- // The bullet class should be able to read this.
- lex.nextToken();
- int const index = lex.getInteger();
- lex.next();
- string temp_str = lex.getString();
- string sum_str;
- while (temp_str != "\\end_bullet") {
- // this loop structure is needed when user
- // enters an empty string since the first
- // thing returned will be the \\end_bullet
- // OR
- // if the LaTeX entry has spaces. Each element
- // therefore needs to be read in turn
- sum_str += temp_str;
- lex.next();
- temp_str = lex.getString();
- }
-
- params.user_defined_bullets[index].setText(sum_str);
- params.temp_bullets[index].setText(sum_str);
- } else if (token == "\\secnumdepth") {
- lex.nextToken();
- params.secnumdepth = lex.getInteger();
- } else if (token == "\\tocdepth") {
- lex.nextToken();
- params.tocdepth = lex.getInteger();
- } else if (token == "\\spacing") {
- lex.next();
- string const tmp = rtrim(lex.getString());
- Spacing::Space tmp_space = Spacing::Default;
- float tmp_val = 0.0;
- if (tmp == "single") {
- tmp_space = Spacing::Single;
- } else if (tmp == "onehalf") {
- tmp_space = Spacing::Onehalf;
- } else if (tmp == "double") {
- tmp_space = Spacing::Double;
- } else if (tmp == "other") {
- lex.next();
- tmp_space = Spacing::Other;
- tmp_val = lex.getFloat();
- } else {
- lex.printError("Unknown spacing token: '$$Token'");
- }
- // Small hack so that files written with klyx will be
- // parsed correctly.
- if (first_par) {
- par->params().spacing(Spacing(tmp_space, tmp_val));
- } else {
- params.spacing.set(tmp_space, tmp_val);
- }
- } else if (token == "\\paragraph_spacing") {
- lex.next();
- string const tmp = rtrim(lex.getString());
- if (tmp == "single") {
- par->params().spacing(Spacing(Spacing::Single));
- } else if (tmp == "onehalf") {
- par->params().spacing(Spacing(Spacing::Onehalf));
- } else if (tmp == "double") {
- par->params().spacing(Spacing(Spacing::Double));
- } else if (tmp == "other") {
- lex.next();
- par->params().spacing(Spacing(Spacing::Other,
- lex.getFloat()));
- } else {
- lex.printError("Unknown spacing token: '$$Token'");
- }
- } else if (token == "\\float_placement") {
- lex.nextToken();
- params.float_placement = lex.getString();
- } else if (token == "\\align") {
- int tmpret = lex.findToken(string_align);
- if (tmpret == -1)
- ++tmpret;
- int const tmpret2 = int(pow(2.0, tmpret));
- par->params().align(LyXAlignment(tmpret2));
- } else if (token == "\\added_space_top") {
- lex.nextToken();
- VSpace value = VSpace(lex.getString());
- // only add the length when value > 0 or
- // with option keep
- if ((value.length().len().value() != 0) ||
- value.keep() ||
- (value.kind() != VSpace::LENGTH))
- par->params().spaceTop(value);
- } else if (token == "\\added_space_bottom") {
- lex.nextToken();
- VSpace value = VSpace(lex.getString());
- // only add the length when value > 0 or
- // with option keep
- if ((value.length().len().value() != 0) ||
- value.keep() ||
- (value.kind() != VSpace::LENGTH))
- par->params().spaceBottom(value);
- } else if (token == "\\labelwidthstring") {
- lex.eatLine();
- par->params().labelWidthString(lex.getString());
- // do not delete this token, it is still needed!
- } else if (token == "\\newline") {
- par->insertChar(pos, Paragraph::META_NEWLINE, font, current_change);
- ++pos;
- } else if (token == "\\LyXTable") {
- Inset * inset = new InsetTabular(*this);
- inset->read(this, lex);
- par->insertInset(pos, inset, font, current_change);
- ++pos;
- } else if (token == "\\bibitem") { // ale970302
- InsetCommandParams p("bibitem", "dummy");
- InsetBibitem * inset = new InsetBibitem(p);
- inset->read(this, lex);
- par->insertInset(pos, inset, font, current_change);
- ++pos;
- } else if (token == "\\hfill") {
- par->insertChar(pos, Paragraph::META_HFILL, font, current_change);
- ++pos;
- } else if (token == "\\change_unchanged") {
- // Hack ! Needed for empty paragraphs :/
- if (!pos)
- par->cleanChanges();
- current_change = Change(Change::UNCHANGED);
- } else if (token == "\\change_inserted") {
- lex.nextToken();
- istringstream istr(lex.getString());
- int aid;
- lyx::time_type ct;
- istr >> aid;
- istr >> ct;
- current_change = Change(Change::INSERTED, author_ids[aid], ct);
- } else if (token == "\\change_deleted") {
- lex.nextToken();
- istringstream istr(lex.getString());
- int aid;
- lyx::time_type ct;
- istr >> aid;
- istr >> ct;
- current_change = Change(Change::DELETED, author_ids[aid], ct);
- } else if (token == "\\the_end") {
- the_end_read = true;
- } else {
- // This should be insurance for the future: (Asger)
- ++unknown_tokens;
- lex.eatLine();
-#if USE_BOOST_FORMAT
- boost::format fmt(_("Unknown token: %1$s %2$s\n"));
- fmt % token % lex.text();
- string const s = fmt.str();
-#else
- string const s = _("Unknown token: ") + token
- + ' ' + lex.text() + '\n';
-#endif
- // we can do this here this way because we're actually reading
- // the buffer and don't care about LyXText right now.
- InsetError * new_inset = new InsetError(s);
- par->insertInset(pos, new_inset, LyXFont(LyXFont::ALL_INHERIT,
- params.language));