docstring const LaTeXFeatures::getTClassI18nPreamble(bool use_babel) const { DocumentClass const & tclass = params_.documentClass(); // collect preamble snippets in a set to prevent multiple identical // commands (would happen if e.g. both theorem and theorem* are used) set<docstring> snippets; typedef LanguageList::const_iterator lang_it; lang_it const lbeg = UsedLanguages_.begin(); lang_it const lend = UsedLanguages_.end(); list<docstring>::const_iterator cit = usedLayouts_.begin(); list<docstring>::const_iterator end = usedLayouts_.end(); for (; cit != end; ++cit) { // language dependent commands (once per document) snippets.insert(tclass[*cit].langpreamble(buffer().language())); // commands for language changing (for multilanguage documents) if (use_babel && !UsedLanguages_.empty()) { snippets.insert(tclass[*cit].babelpreamble(buffer().language())); for (lang_it lit = lbeg; lit != lend; ++lit) snippets.insert(tclass[*cit].babelpreamble(*lit)); } } if (use_babel && !UsedLanguages_.empty()) { FloatList const & floats = params_.documentClass().floats(); UsedFloats::const_iterator fit = usedFloats_.begin(); UsedFloats::const_iterator fend = usedFloats_.end(); for (; fit != fend; ++fit) { Floating const & fl = floats.getType(fit->first); docstring const type = from_ascii(fl.floattype()); docstring const flname = from_utf8(fl.name()); docstring name = translateIfPossible(flname, buffer().language()->code()); snippets.insert(getFloatI18nPreamble( type, name, from_ascii(buffer().language()->babel()))); for (lang_it lit = lbeg; lit != lend; ++lit) { name = translateIfPossible(flname, (*lit)->code()); snippets.insert(getFloatI18nPreamble( type, name, from_ascii((*lit)->babel()))); } } } odocstringstream tcpreamble; set<docstring>::const_iterator const send = snippets.end(); set<docstring>::const_iterator it = snippets.begin(); for (; it != send; ++it) tcpreamble << *it; return tcpreamble.str(); }
docstring InsetRef::xhtml(XHTMLStream & xs, OutputParams const & op) const { docstring const & ref = getParam("reference"); InsetLabel const * il = buffer().insetLabel(ref); string const & cmd = params().getCmdName(); docstring display_string; if (il && !il->counterValue().empty()) { // Try to construct a label from the InsetLabel we reference. docstring const & value = il->counterValue(); if (cmd == "ref") display_string = value; else if (cmd == "vref") // normally, would be "ref on page #", but we have no pages display_string = value; else if (cmd == "pageref" || cmd == "vpageref") // normally would be "on page #", but we have no pages. display_string = translateIfPossible(from_ascii("elsewhere"), op.local_font->language()->lang()); else if (cmd == "eqref") display_string = '(' + value + ')'; else if (cmd == "formatted") display_string = il->prettyCounter(); else if (cmd == "nameref") // FIXME We don't really have the ability to handle these // properly in XHTML output yet (bug #8599). // It might not be that hard to do. We have the InsetLabel, // and we can presumably find its paragraph using the TOC. // We could then output the contents of the paragraph using // something? display_string = il->prettyCounter(); } else display_string = ref; // FIXME What we'd really like to do is to be able to output some // appropriate sort of text here. But to do that, we need to associate // some sort of counter with the label, and we don't have that yet. string const attr = "href=\"#" + html::cleanAttr(to_utf8(ref)) + "\""; xs << html::StartTag("a", attr); xs << display_string; xs << html::EndTag("a"); return docstring(); }
void InsetCaption::setCustomLabel(docstring const & label) { custom_label_ = translateIfPossible(label); }
void LaTeXFeatures::getFloatDefinitions(odocstream & os) const { FloatList const & floats = params_.documentClass().floats(); // Here we will output the code to create the needed float styles. // We will try to do this as minimal as possible. // \floatstyle{ruled} // \newfloat{algorithm}{htbp}{loa} // \providecommand{\algorithmname}{Algorithm} // \floatname{algorithm}{\protect\algorithmname} UsedFloats::const_iterator cit = usedFloats_.begin(); UsedFloats::const_iterator end = usedFloats_.end(); for (; cit != end; ++cit) { Floating const & fl = floats.getType(cit->first); // For builtin floats we do nothing. if (!fl.needsFloatPkg()) continue; // We have to special case "table" and "figure" if (fl.floattype() == "tabular" || fl.floattype() == "figure") { // Output code to modify "table" or "figure" // but only if builtin == false // and that have to be true at this point in the // function. docstring const type = from_ascii(fl.floattype()); docstring const placement = from_ascii(fl.placement()); docstring const style = from_ascii(fl.style()); if (!style.empty()) { os << "\\floatstyle{" << style << "}\n" << "\\restylefloat{" << type << "}\n"; } if (!placement.empty()) { os << "\\floatplacement{" << type << "}{" << placement << "}\n"; } } else { // The other non builtin floats. docstring const type = from_ascii(fl.floattype()); docstring const placement = from_ascii(fl.placement()); docstring const ext = from_ascii(fl.ext()); docstring const within = from_ascii(fl.within()); docstring const style = from_ascii(fl.style()); docstring const name = translateIfPossible( from_utf8(fl.name()), buffer().language()->code()); os << "\\floatstyle{" << style << "}\n" << "\\newfloat{" << type << "}{" << placement << "}{" << ext << '}'; if (!within.empty()) os << '[' << within << ']'; os << '\n' << "\\providecommand{\\" << type << "name}{" << name << "}\n" << "\\floatname{" << type << "}{\\protect\\" << type << "name}\n"; // What missing here is to code to minimalize the code // output so that the same floatstyle will not be // used several times, when the same style is still in // effect. (Lgb) } if (cit->second) os << "\n\\newsubfloat{" << from_ascii(fl.floattype()) << "}\n"; } }
docstring InsetTOC::xhtml(XHTMLStream &, OutputParams const & op) const { Layout const & lay = buffer().params().documentClass().htmlTOCLayout(); string const & tocclass = lay.defaultCSSClass(); string const tocattr = "class='tochead " + tocclass + "'"; // we'll use our own stream, because we are going to defer everything. // that's how we deal with the fact that we're probably inside a standard // paragraph, and we don't want to be. odocstringstream ods; XHTMLStream xs(ods); Toc const & toc = buffer().tocBackend().toc("tableofcontents"); if (toc.empty()) return docstring(); xs << html::StartTag("div", "class='toc'"); // Title of TOC Language const * lang = buffer().params().language; static string toctitle = N_("Table of Contents"); docstring title = lang ? translateIfPossible(from_ascii(toctitle), lang->code()) : translateIfPossible(from_ascii(toctitle)); xs << html::StartTag("div", tocattr) << title << html::EndTag("div"); // Output of TOC Toc::const_iterator it = toc.begin(); Toc::const_iterator const en = toc.end(); int lastdepth = 0; for (; it != en; ++it) { // First, we need to manage increases and decreases of depth int const depth = it->depth(); // Ignore stuff above the tocdepth if (depth > buffer().params().tocdepth) continue; if (depth > lastdepth) { xs.cr(); // open as many tags as we need to open to get to this level // this includes the tag for the current level for (int i = lastdepth + 1; i <= depth; ++i) { stringstream attr; attr << "class='lyxtoc-" << i << "'"; xs << html::StartTag("div", attr.str()); } lastdepth = depth; } else if (depth < lastdepth) { // close as many as we have to close to get back to this level // this includes closing the last tag at this level for (int i = lastdepth; i >= depth; --i) xs << html::EndTag("div"); // now open our tag stringstream attr; attr << "class='lyxtoc-" << depth << "'"; xs << html::StartTag("div", attr.str()); lastdepth = depth; } else { // no change of level, so close and open xs << html::EndTag("div"); stringstream attr; attr << "class='lyxtoc-" << depth << "'"; xs << html::StartTag("div", attr.str()); } // Now output TOC info for this entry Paragraph const & par = it->dit().innerParagraph(); // First the label, if there is one docstring const & label = par.params().labelString(); if (!label.empty()) xs << label << " "; // Now the content of the TOC entry, taken from the paragraph itself OutputParams ours = op; ours.for_toc = true; Font const dummy; par.simpleLyXHTMLOnePar(buffer(), xs, ours, dummy); xs << " "; // Now a link to that paragraph string const parattr = "href='#" + par.magicLabel() + "' class='tocarrow'"; xs << html::StartTag("a", parattr); // FIXME XHTML // There ought to be a simple way to customize this. // Maybe if we had an InsetLayout for TOC... xs << XHTMLStream::NextRaw() << ">"; xs << html::EndTag("a"); } for (int i = lastdepth; i > 0; --i) xs << html::EndTag("div"); xs << html::EndTag("div"); return ods.str(); }