3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Lars Gullik Bjønnes
8 * \author Jürgen Spitzmüller
10 * Full author contact details are available in file CREDITS.
16 #include "InsetCaption.h"
17 #include "InsetFloat.h"
18 #include "InsetGraphics.h"
19 #include "InsetLabel.h"
22 #include "BufferParams.h"
23 #include "BufferView.h"
26 #include "DispatchResult.h"
28 #include "FloatList.h"
29 #include "FuncRequest.h"
30 #include "FuncStatus.h"
31 #include "LaTeXFeatures.h"
34 #include "output_docbook.h"
35 #include "output_xhtml.h"
36 #include "ParIterator.h"
38 #include "texstream.h"
39 #include "TextClass.h"
40 #include "InsetList.h"
42 #include "support/debug.h"
43 #include "support/docstream.h"
44 #include "support/gettext.h"
45 #include "support/lstrings.h"
47 #include "frontends/Application.h"
50 using namespace lyx::support;
55 // With this inset it will be possible to support the latex package
56 // float.sty, and I am sure that with this and some additional support
57 // classes we can support similar functionality in other formats
59 // By using float.sty we will have the same handling for all floats, both
60 // for those already in existence (table and figure) and all user created
61 // ones¹. So suddenly we give the users the possibility of creating new
62 // kinds of floats on the fly. (and with a uniform look)
65 // \newfloat{type}{placement}{ext}[within]
66 // type - The "type" of the new class of floats, like program or
67 // algorithm. After the appropriate \newfloat, commands
68 // such as \begin{program} or \end{algorithm*} will be
70 // placement - The default placement for the given class of floats.
71 // They are like in standard LaTeX: t, b, p and h for top,
72 // bottom, page, and here, respectively. On top of that
73 // there is a new type, H, which does not really correspond
74 // to a float, since it means: put it "here" and nowhere else.
75 // Note, however that the H specifier is special and, because
76 // of implementation details cannot be used in the second
77 // argument of \newfloat.
78 // ext - The file name extension of an auxiliary file for the list
79 // of figures (or whatever). LaTeX writes the captions to
81 // within - This (optional) argument determines whether floats of this
82 // class will be numbered within some sectional unit of the
83 // document. For example, if within is equal to chapter, the
84 // floats will be numbered within chapters.
86 // style - plain, boxed, ruled
87 // \floatname{float}{floatname}
90 // \floatplacement{float}{placement}
93 // \restylefloat{float}
95 // \listof{type}{title}
98 // ¹ the algorithm float is defined using the float.sty package. Like this
100 // \newfloat{algorithm}{htbp}{loa}[<sect>]
101 // \floatname{algorithm}{Algorithm}
103 // The intention is that floats should be definable from two places:
105 // - the "gui" (i.e. by the user)
107 // From layout files.
108 // This should only be done for floats defined in a documentclass and that
109 // does not need any additional packages. The two most known floats in this
110 // category is "table" and "figure". Floats defined in layout files are only
111 // stored in lyx files if the user modifies them.
114 // There should be a gui dialog (and also a collection of lyxfuncs) where
115 // the user can modify existing floats and/or create new ones.
117 // The individual floats will also have some settable
118 // variables: wide and placement.
122 //FIXME: why do we set in stone the type here?
123 InsetFloat::InsetFloat(Buffer * buf, string const & params_str)
124 : InsetCaptionable(buf)
126 string2params(params_str, params_);
127 setCaptionType(params_.type);
131 // Enforce equality of float type and caption type.
132 void InsetFloat::setCaptionType(std::string const & type)
134 InsetCaptionable::setCaptionType(type);
135 params_.type = captionType();
136 // check if the float type exists
137 if (buffer().params().documentClass().floats().typeExist(params_.type))
140 setLabel(bformat(_("ERROR: Unknown float type: %1$s"), from_utf8(params_.type)));
144 docstring InsetFloat::layoutName() const
146 return "Float:" + from_utf8(params_.type);
150 docstring InsetFloat::toolTip(BufferView const & bv, int x, int y) const
153 return InsetCaptionable::toolTip(bv, x, y);
155 OutputParams rp(&buffer().params().encoding());
156 return getCaptionText(rp);
160 void InsetFloat::doDispatch(Cursor & cur, FuncRequest & cmd)
162 switch (cmd.action()) {
164 case LFUN_INSET_MODIFY: {
165 if (!buffer().params().documentClass().floats().typeExist(cmd.getArg(0))) {
166 // not for us: pass further.
170 InsetFloatParams params;
171 string2params(to_utf8(cmd.argument()), params);
172 cur.recordUndoInset(this);
174 // placement, wide and sideways are not used for subfloats
175 if (!params_.subfloat) {
176 params_.placement = params.placement;
177 params_.wide = params.wide;
178 params_.sideways = params.sideways;
180 params_.alignment = params.alignment;
182 if (params_.type != params.type)
183 setCaptionType(params.type);
184 // what we really want here is a TOC update, but that means
185 // a full buffer update
186 cur.forceBufferUpdate();
190 case LFUN_INSET_DIALOG_UPDATE: {
191 cur.bv().updateDialog("float", params2string(params()));
196 InsetCaptionable::doDispatch(cur, cmd);
202 bool InsetFloat::getStatus(Cursor & cur, FuncRequest const & cmd,
203 FuncStatus & flag) const
205 switch (cmd.action()) {
207 case LFUN_INSET_MODIFY:
208 if (!buffer().params().documentClass().floats().typeExist(cmd.getArg(0)))
209 return Inset::getStatus(cur, cmd, flag);
211 case LFUN_INSET_DIALOG_UPDATE:
212 flag.setEnabled(true);
215 case LFUN_INSET_SETTINGS:
216 if (InsetCaptionable::getStatus(cur, cmd, flag)) {
217 flag.setEnabled(flag.enabled() && !params_.subfloat);
222 case LFUN_NEWLINE_INSERT:
223 if (params_.subfloat) {
224 flag.setEnabled(false);
231 return InsetCaptionable::getStatus(cur, cmd, flag);
236 bool InsetFloat::hasSubCaptions(ParIterator const & it) const
238 return (it.innerInsetOfType(FLOAT_CODE) || it.innerInsetOfType(WRAP_CODE));
242 string InsetFloat::getAlignment() const
245 string const buf_alignment = buffer().params().float_alignment;
246 if (params_.alignment == "document"
247 && !buf_alignment.empty()) {
248 alignment = buf_alignment;
249 } else if (!params_.alignment.empty()
250 && params_.alignment != "class"
251 && params_.alignment != "document") {
252 alignment = params_.alignment;
258 LyXAlignment InsetFloat::contentAlignment() const
260 LyXAlignment align = LYX_ALIGN_NONE;
261 string alignment = getAlignment();
262 if (alignment == "left")
263 align = LYX_ALIGN_LEFT;
264 else if (alignment == "center")
265 align = LYX_ALIGN_CENTER;
266 else if (alignment == "right")
267 align = LYX_ALIGN_RIGHT;
273 void InsetFloatParams::write(ostream & os) const
276 // Better this than creating a parse error. This in fact happens in the
277 // parameters dialog via InsetFloatParams::params2string.
278 os << "senseless" << '\n';
282 if (!placement.empty())
283 os << "placement " << placement << "\n";
284 if (!alignment.empty())
285 os << "alignment " << alignment << "\n";
290 os << "wide false\n";
293 os << "sideways true\n";
295 os << "sideways false\n";
299 void InsetFloatParams::read(Lexer & lex)
301 lex.setContext("InsetFloatParams::read");
303 if (lex.checkFor("placement"))
305 if (lex.checkFor("alignment"))
307 lex >> "wide" >> wide;
308 lex >> "sideways" >> sideways;
312 void InsetFloat::write(ostream & os) const
316 InsetCaptionable::write(os);
320 void InsetFloat::read(Lexer & lex)
323 InsetCaptionable::read(lex);
324 setCaptionType(params_.type);
328 void InsetFloat::validate(LaTeXFeatures & features) const
330 if (support::contains(params_.placement, 'H'))
331 features.require("float");
333 if (params_.sideways)
334 features.require("rotfloat");
336 if (features.inFloat())
337 features.require("subfig");
339 if (features.inDeletedInset()) {
340 features.require("tikz");
341 features.require("ct-tikz-object-sout");
344 features.useFloat(params_.type, features.inFloat());
345 features.inFloat(true);
346 InsetCaptionable::validate(features);
347 features.inFloat(false);
351 docstring InsetFloat::xhtml(XMLStream & xs, OutputParams const & rp) const
353 FloatList const & floats = buffer().params().documentClass().floats();
354 Floating const & ftype = floats.getType(params_.type);
355 string const & htmltype = ftype.htmlTag();
356 string const & attr = ftype.htmlAttrib();
358 odocstringstream ods;
359 XMLStream newxs(ods);
360 newxs << xml::StartTag(htmltype, attr);
361 InsetText::XHTMLOptions const opts =
362 InsetText::WriteLabel | InsetText::WriteInnerTag;
363 docstring deferred = InsetText::insetAsXHTML(newxs, rp, opts);
364 newxs << xml::EndTag(htmltype);
366 if (rp.inFloat == OutputParams::NONFLOAT) {
367 // In this case, this float needs to be deferred, but we'll put it
368 // before anything the text itself deferred.
369 deferred = ods.str() + '\n' + deferred;
371 // In this case, the whole thing is already being deferred, so
372 // we can write to the stream.
373 // Note that things will already have been escaped, so we do not
374 // want to escape them again.
375 xs << XMLStream::ESCAPE_NONE << ods.str();
381 void InsetFloat::latex(otexstream & os, OutputParams const & runparams_in) const
383 if (runparams_in.inFloat != OutputParams::NONFLOAT) {
384 if (!paragraphs().empty() && !runparams_in.nice)
385 // improve TexRow precision in non-nice mode
388 if (runparams_in.moving_arg)
392 OutputParams rp = runparams_in;
393 rp.moving_arg = true;
394 rp.inFloat = OutputParams::SUBFLOAT;
395 os << getCaption(rp);
397 // The main argument is the contents of the float. This is not a moving argument.
398 rp.moving_arg = false;
399 InsetText::latex(os, rp);
404 OutputParams runparams(runparams_in);
405 runparams.inFloat = OutputParams::MAINFLOAT;
407 FloatList const & floats = buffer().params().documentClass().floats();
408 string tmptype = params_.type;
409 if (params_.sideways && floats.allowsSideways(params_.type))
410 tmptype = "sideways" + params_.type;
411 if (params_.wide && floats.allowsWide(params_.type)
412 && (!params_.sideways ||
413 params_.type == "figure" ||
414 params_.type == "table"))
416 // Figure out the float placement to use.
417 // From lowest to highest:
418 // - float default placement
419 // - document wide default placement
420 // - specific float placement
422 string const buf_placement = buffer().params().float_placement;
423 string const def_placement = floats.defaultPlacement(params_.type);
424 if (params_.placement == "document"
425 && !buf_placement.empty()
426 && buf_placement != def_placement) {
427 tmpplacement = buf_placement;
428 } else if (!params_.placement.empty()
429 && params_.placement != "document"
430 && params_.placement != def_placement) {
431 tmpplacement = params_.placement;
434 // Check if placement is allowed by this float
435 string const allowed_placement =
436 floats.allowedPlacement(params_.type);
438 string::const_iterator lit = tmpplacement.begin();
439 string::const_iterator end = tmpplacement.end();
440 for (; lit != end; ++lit) {
441 if (contains(allowed_placement, *lit))
445 // Force \begin{<floatname>} to appear in a new line.
446 os << breakln << "\\begin{" << from_ascii(tmptype) << '}';
447 if (runparams.lastid != -1)
448 os.texrow().start(runparams.lastid, runparams.lastpos);
449 // We only output placement if different from the def_placement.
450 // sidewaysfloats always use their own page,
451 // therefore don't output the p option that is always set
452 if (!placement.empty()
453 && (!params_.sideways || from_ascii(placement) != "p"))
454 os << '[' << from_ascii(placement) << ']';
457 if (runparams.inDeletedInset) {
458 // This has to be done manually since we need it inside the float
459 OutputParams::CtObject ctobject = runparams.ctObject;
460 runparams.ctObject = OutputParams::CT_DISPLAYOBJECT;
461 Changes::latexMarkChange(os, buffer().params(), Change(Change::UNCHANGED),
462 Change(Change::DELETED), runparams);
463 runparams.ctObject = ctobject;
466 string alignment = getAlignment();
467 if (alignment == "left")
468 os << "\\raggedright" << breakln;
469 else if (alignment == "center")
470 os << "\\centering" << breakln;
471 else if (alignment == "right")
472 os << "\\raggedleft" << breakln;
474 InsetText::latex(os, runparams);
476 if (runparams.inDeletedInset)
479 // Force \end{<floatname>} to appear in a new line.
480 os << breakln << "\\end{" << from_ascii(tmptype) << "}\n";
484 int InsetFloat::plaintext(odocstringstream & os, OutputParams const & runparams, size_t max_length) const
486 os << '[' << buffer().B_("float") << ' '
487 << floatName(params_.type) << ":\n";
488 InsetText::plaintext(os, runparams, max_length);
491 return PLAINTEXT_NEWLINE + 1; // one char on a separate line
495 std::vector<const InsetCollapsible *> findSubfiguresInParagraph(const Paragraph &par)
498 // Don't make the hypothesis that all subfigures are in the same paragraph.
499 // Similarly, there may be several subfigures in the same paragraph (most likely case, based on the documentation).
500 // Any box is considered as a subfigure, even though the most likely case is \minipage.
501 // Boxes are not required to make subfigures. The common root between InsetBox and InsetFLoat is InsetCollapsible.
502 std::vector<const InsetCollapsible *> subfigures;
503 for (pos_type pos = 0; pos < par.size(); ++pos) {
504 const Inset *inset = par.getInset(pos);
507 if (const auto box = dynamic_cast<const InsetBox *>(inset))
508 subfigures.push_back(box);
509 else if (const auto fl = dynamic_cast<const InsetFloat *>(inset))
510 subfigures.push_back(fl);
516 const InsetLabel* findLabelInParagraph(const Paragraph &par)
518 for (pos_type pos = 0; pos < par.size(); ++pos) {
519 // If this inset is a subfigure, skip it.
520 const Inset *inset = par.getInset(pos);
521 if (dynamic_cast<const InsetBox *>(inset)) {
525 // Maybe an inset is directly a label, in which case no more work is needed.
526 if (inset && dynamic_cast<const InsetLabel *>(inset))
527 return dynamic_cast<const InsetLabel *>(inset);
529 // More likely, the label is hidden in an inset of a paragraph (only if a subtype of InsetText).
530 if (!dynamic_cast<const InsetText *>(inset))
533 auto insetAsText = dynamic_cast<const InsetText *>(inset);
534 auto itIn = insetAsText->paragraphs().begin();
535 auto endIn = insetAsText->paragraphs().end();
536 for (; itIn != endIn; ++itIn) {
537 for (pos_type posIn = 0; posIn < itIn->size(); ++posIn) {
538 const Inset *insetIn = itIn->getInset(posIn);
539 if (insetIn && dynamic_cast<const InsetLabel *>(insetIn)) {
540 return dynamic_cast<const InsetLabel *>(insetIn);
545 // Obviously, this solution does not scale with more levels of paragraphs-insets, but this should be enough.
552 const InsetCaption* findCaptionInParagraph(const Paragraph &par)
554 // Don't dive too deep, otherwise, this could be a subfigure caption.
555 for (pos_type pos = 0; pos < par.size(); ++pos) {
556 // If this inset is a subfigure, skip it.
557 const Inset *inset = par.getInset(pos);
558 if (dynamic_cast<const InsetBox *>(inset))
561 if (inset && dynamic_cast<const InsetCaption *>(inset))
562 return dynamic_cast<const InsetCaption *>(inset);
569 /// Takes an unstructured subfigure container (typically, an InsetBox) and find the elements within:
570 /// actual content (image or table), maybe a caption, maybe a label.
571 std::tuple<InsetCode, const Inset *, const InsetCaption *, const InsetLabel *> docbookParseHopelessSubfigure(const InsetText * subfigure)
573 InsetCode type = NO_CODE;
574 const Inset * content = nullptr;
575 const InsetCaption * caption = nullptr;
576 const InsetLabel * label = nullptr;
578 for (const auto & it : subfigure->paragraphs()) {
579 for (pos_type posIn = 0; posIn < it.size(); ++posIn) {
580 const Inset * inset = it.getInset(posIn);
582 switch (inset->lyxCode()) {
587 type = inset->lyxCode();
592 caption = dynamic_cast<const InsetCaption *>(inset);
594 // A label often hides in a caption. Make a simplified version of the main loop.
596 for (const auto &cit : caption->paragraphs()) {
597 for (pos_type cposIn = 0; cposIn < cit.size(); ++cposIn) {
598 const Inset *cinset = cit.getInset(posIn);
599 if (cinset && cinset->lyxCode() == LABEL_CODE) {
600 label = dynamic_cast<const InsetLabel *>(cinset);
613 label = dynamic_cast<const InsetLabel *>(inset);
621 if (content && caption && label)
625 return std::make_tuple(type, content, caption, label);
629 void docbookSubfigures(XMLStream & xs, OutputParams const & runparams, const InsetCaption * caption,
630 const InsetLabel * label, std::vector<const InsetCollapsible *> const & subfigures)
632 // Ensure there is no label output, it is supposed to be handled as xml:id.
633 OutputParams rpNoLabel = runparams;
635 rpNoLabel.docbook_anchors_to_ignore.emplace(label->screenLabel());
637 // First, open the formal group.
638 docstring attr = docstring();
640 attr += "xml:id=\"" + xml::cleanID(label->screenLabel()) + "\"";
642 xs.startDivision(false);
643 xs << xml::StartTag("formalgroup", attr);
646 xs << xml::StartTag("title"); // Don't take attr here, the ID should only go in one place, not two.
648 caption->getCaptionAsDocBook(xs, rpNoLabel);
651 // No caption has been detected, but this tag is required for the document to be valid DocBook.
653 xs << xml::EndTag("title");
656 // Deal with each subfigure individually. This should also deal with their caption and their label.
657 // This should be a recursive call to InsetFloat.
658 // An item in subfigure should either be an InsetBox containing an InsetFloat, or an InsetBox directly containing
659 // an image or a table, or directly an InsetFloat.
660 for (const InsetCollapsible * subfigure: subfigures) {
661 if (subfigure == nullptr)
664 // The collapsible may already be a float (InsetFloat).
665 if (dynamic_cast<const InsetFloat *>(subfigure)) {
666 subfigure->docbook(xs, runparams);
670 // Subfigures are in boxes, then in InsetFloat.
672 bool foundInsetFloat = false;
673 for (const auto &it : subfigure->paragraphs()) {
674 for (pos_type posIn = 0; posIn < it.size(); ++posIn) {
675 const Inset *inset = it.getInset(posIn);
676 if (inset && inset->lyxCode() == FLOAT_CODE) {
677 foundInsetFloat = true;
678 inset->docbook(xs, runparams);
690 // Subfigures are in boxes, then directly an image or a table. In that case, generate the whole content of the
691 // InsetBox, but not the box container.
692 // Impose some model on the subfigure: at most a caption, at most a label, exactly one figure or one table.
694 InsetCode stype = NO_CODE;
695 const Inset * scontent = nullptr;
696 const InsetCaption * scaption = nullptr;
697 const InsetLabel * slabel = nullptr;
699 std::tie(stype, scontent, scaption, slabel) = docbookParseHopelessSubfigure(subfigure);
701 // If there is something, generate it. This is very much like docbookNoSubfigures, but many things
702 // must be coded differently because there is no float.
703 // TODO: some code is identical to Floating, like Floating::docbookTag or Floating::docbookCaption. How to reuse that code?
705 // Floating::docbookCaption()
706 string docbook_caption = "caption"; // This is already correct for tables.
707 if (stype == GRAPHICS_CODE)
708 docbook_caption = "title";
710 // Floating::docbookTag() with hasTitle = true, as we are in formalgroup.
711 string stag = "float";
712 if (stype == GRAPHICS_CODE)
714 else if (stype == TABULAR_CODE)
717 // Ensure there is no label output, it is supposed to be handled as xml:id.
719 rpNoLabel.docbook_anchors_to_ignore.emplace(slabel->screenLabel());
721 // Ensure the float does not output its caption, as it is handled here (DocBook mandates a specific place for
722 // captions, they cannot appear at the end of the float, albeit LyX is happy with that).
723 OutputParams rpNoTitle = runparams;
724 rpNoTitle.docbook_in_float = true;
725 if (stype == TABULAR_CODE)
726 rpNoTitle.docbook_in_table = true;
728 // Organisation: <float> <title if any/> <contents without title/> </float>.
729 docstring sattr = docstring();
731 sattr += "xml:id=\"" + xml::cleanID(slabel->screenLabel()) + "\"";
732 // No layout way of adding attributes, unlike the normal code path.
734 xs << xml::StartTag(stag, sattr);
736 xs << xml::StartTag(docbook_caption);
738 scaption->getCaptionAsDocBook(xs, rpNoLabel);
739 else // Mandatory in formalgroup.
740 xs << "No caption detected";
741 xs << xml::EndTag(docbook_caption);
743 scontent->docbook(xs, rpNoTitle);
744 xs << xml::EndTag(stag);
747 // This subfigure could be generated.
752 // If there is no InsetFloat in the inset, output a warning.
753 xs << XMLStream::ESCAPE_NONE << "Error: no float found in the box. "
754 "To use subfigures in DocBook, elements must be wrapped in a float "
755 "inset and have a title/caption.";
756 // TODO: could also output a table, that would ensure that the document is correct and *displays* correctly (but without the right semantics), instead of just an error.
758 // Recurse to generate as much content as possible (avoid any loss).
759 subfigure->docbook(xs, runparams);
762 // Every subfigure is done: close the formal group.
763 xs << xml::EndTag("formalgroup");
769 void docbookNoSubfigures(XMLStream & xs, OutputParams const & runparams, const InsetCaption * caption,
770 const InsetLabel * label, Floating const & ftype, const InsetFloat * thisFloat)
772 string const &titleTag = ftype.docbookCaption();
774 // Ensure there is no label output, it is supposed to be handled as xml:id.
775 OutputParams rpNoLabel = runparams;
777 rpNoLabel.docbook_anchors_to_ignore.emplace(label->screenLabel());
779 // Ensure the float does not output its caption, as it is handled here (DocBook mandates a specific place for
780 // captions, they cannot appear at the end of the float, albeit LyX is happy with that).
781 OutputParams rpNoTitle = runparams;
782 rpNoTitle.docbook_in_float = true;
783 if (ftype.docbookFloatType() == "table")
784 rpNoTitle.docbook_in_table = true;
786 // Organisation: <float> <title if any/> <contents without title/> </float>.
787 docstring attr = docstring();
789 attr += "xml:id=\"" + xml::cleanID(label->screenLabel()) + "\"";
790 if (!ftype.docbookAttr().empty()) {
793 attr += from_utf8(ftype.docbookAttr());
796 xs << xml::StartTag(ftype.docbookTag(caption != nullptr), attr);
799 xs << xml::StartTag(titleTag);
800 caption->getCaptionAsDocBook(xs, rpNoLabel);
801 xs << xml::EndTag(titleTag);
804 thisFloat->InsetText::docbook(xs, rpNoTitle);
805 xs << xml::EndTag(ftype.docbookTag(caption != nullptr));
810 void InsetFloat::docbook(XMLStream & xs, OutputParams const & runparams) const
812 // Determine whether the float has a title or not. For this, iterate through the paragraphs and look
813 // for an InsetCaption. Do the same for labels and subfigures.
814 // The caption and the label for each subfigure is handled by recursive calls.
815 const InsetCaption* caption = nullptr;
816 const InsetLabel* label = nullptr;
817 std::vector<const InsetCollapsible *> subfigures;
819 auto end = paragraphs().end();
820 for (auto it = paragraphs().begin(); it != end; ++it) {
821 std::vector<const InsetCollapsible *> foundSubfigures = findSubfiguresInParagraph(*it);
822 if (!foundSubfigures.empty()) {
823 subfigures.reserve(subfigures.size() + foundSubfigures.size());
824 subfigures.insert(subfigures.end(), foundSubfigures.begin(), foundSubfigures.end());
828 caption = findCaptionInParagraph(*it);
830 label = findLabelInParagraph(*it);
833 // Gather a few things from global environment that are shared between all following cases.
834 FloatList const &floats = buffer().params().documentClass().floats();
835 Floating const &ftype = floats.getType(params_.type);
837 // Switch on subfigures.
838 if (!subfigures.empty())
839 docbookSubfigures(xs, runparams, caption, label, subfigures);
841 docbookNoSubfigures(xs, runparams, caption, label, ftype, this);
845 bool InsetFloat::insetAllowed(InsetCode code) const
847 // The case that code == FLOAT_CODE is handled in Text3.cpp,
848 // because we need to know what type of float is meant.
855 return InsetCaptionable::insetAllowed(code);
860 void InsetFloat::setWide(bool w, bool update_label)
862 if (!buffer().params().documentClass().floats().allowsWide(params_.type))
863 params_.wide = false;
871 void InsetFloat::setSideways(bool s, bool update_label)
873 if (!buffer().params().documentClass().floats().allowsSideways(params_.type))
874 params_.sideways = false;
876 params_.sideways = s;
882 void InsetFloat::setSubfloat(bool s, bool update_label)
884 params_.subfloat = s;
890 void InsetFloat::setNewLabel()
892 docstring lab = _("float: ");
894 if (params_.subfloat)
895 lab = _("subfloat: ");
897 lab += floatName(params_.type);
899 FloatList const & floats = buffer().params().documentClass().floats();
901 if (params_.wide && floats.allowsWide(params_.type))
904 if (params_.sideways && floats.allowsSideways(params_.type))
905 lab += _(" (sideways)");
911 bool InsetFloat::allowsCaptionVariation(std::string const & newtype) const
913 return !params_.subfloat && newtype != "Unnumbered";
917 TexString InsetFloat::getCaption(OutputParams const & runparams) const
919 InsetCaption const * ins = getCaptionInset();
924 ins->getArgs(os, runparams);
927 // increase TexRow precision in non-nice mode
930 otexstringstream os2;
931 ins->getArgument(os2, runparams);
932 TexString ts = os2.release();
933 docstring & arg = ts.str;
935 if (arg.find(']') != docstring::npos)
936 arg = '{' + arg + '}';
945 void InsetFloat::string2params(string const & in, InsetFloatParams & params)
947 params = InsetFloatParams();
951 istringstream data(in);
954 lex.setContext("InsetFloat::string2params");
959 string InsetFloat::params2string(InsetFloatParams const & params)