2 * \file InsetInclude.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
8 * Full author contact details are available in file CREDITS.
13 #include "InsetInclude.h"
16 #include "buffer_funcs.h"
17 #include "BufferList.h"
18 #include "BufferParams.h"
19 #include "BufferView.h"
22 #include "DispatchResult.h"
24 #include "FuncRequest.h"
25 #include "FuncStatus.h"
27 #include "LaTeXFeatures.h"
31 #include "MetricsInfo.h"
32 #include "OutputParams.h"
33 #include "TocBackend.h"
35 #include "frontends/alert.h"
36 #include "frontends/Painter.h"
38 #include "graphics/PreviewImage.h"
39 #include "graphics/PreviewLoader.h"
41 #include "insets/RenderPreview.h"
42 #include "insets/InsetListingsParams.h"
44 #include "support/filetools.h"
45 #include "support/lstrings.h" // contains
46 #include "support/lyxalgo.h"
47 #include "support/lyxlib.h"
48 #include "support/convert.h"
50 #include <boost/bind.hpp>
51 #include <boost/filesystem/operations.hpp>
56 // Implementation is in LyX.cpp
57 extern void dispatch(FuncRequest const & action);
59 using support::addName;
60 using support::absolutePath;
61 using support::bformat;
62 using support::changeExtension;
63 using support::contains;
65 using support::DocFileName;
66 using support::FileName;
67 using support::getFileContents;
68 using support::getVectorFromString;
69 using support::isFileReadable;
70 using support::isLyXFilename;
71 using support::isValidLaTeXFilename;
72 using support::latex_path;
73 using support::makeAbsPath;
74 using support::makeDisplayPath;
75 using support::makeRelPath;
76 using support::onlyFilename;
77 using support::onlyPath;
78 using support::prefixIs;
85 using std::istringstream;
87 using std::ostringstream;
90 namespace Alert = frontend::Alert;
91 namespace fs = boost::filesystem;
96 docstring const uniqueID()
98 static unsigned int seed = 1000;
99 return "file" + convert<docstring>(++seed);
103 bool isListings(InsetCommandParams const & params)
105 return params.getCmdName() == "lstinputlisting";
111 InsetInclude::InsetInclude(InsetCommandParams const & p)
112 : params_(p), include_label(uniqueID()),
113 preview_(new RenderMonitoredPreview(this)),
116 preview_->fileChanged(boost::bind(&InsetInclude::fileChanged, this));
120 InsetInclude::InsetInclude(InsetInclude const & other)
122 params_(other.params_),
123 include_label(other.include_label),
124 preview_(new RenderMonitoredPreview(this)),
127 preview_->fileChanged(boost::bind(&InsetInclude::fileChanged, this));
131 InsetInclude::~InsetInclude()
133 InsetIncludeMailer(*this).hideDialog();
137 void InsetInclude::doDispatch(Cursor & cur, FuncRequest & cmd)
139 switch (cmd.action) {
141 case LFUN_INSET_MODIFY: {
142 InsetCommandParams p("include");
143 InsetIncludeMailer::string2params(to_utf8(cmd.argument()), p);
144 if (!p.getCmdName().empty()) {
146 InsetListingsParams par_old(params().getOptions());
147 InsetListingsParams par_new(p.getOptions());
148 if (par_old.getParamValue("label") !=
149 par_new.getParamValue("label")
150 && !par_new.getParamValue("label").empty())
151 cur.bv().buffer()->changeRefsIfUnique(
152 from_utf8(par_old.getParamValue("label")),
153 from_utf8(par_new.getParamValue("label")),
156 set(p, cur.buffer());
157 cur.buffer().updateBibfilesCache();
163 case LFUN_INSET_DIALOG_UPDATE:
164 InsetIncludeMailer(*this).updateDialog(&cur.bv());
167 case LFUN_MOUSE_RELEASE:
168 if (!cur.selection())
169 InsetIncludeMailer(*this).showDialog(&cur.bv());
173 Inset::doDispatch(cur, cmd);
179 bool InsetInclude::getStatus(Cursor & cur, FuncRequest const & cmd,
180 FuncStatus & flag) const
182 switch (cmd.action) {
184 case LFUN_INSET_MODIFY:
185 case LFUN_INSET_DIALOG_UPDATE:
190 return Inset::getStatus(cur, cmd, flag);
195 InsetCommandParams const & InsetInclude::params() const
203 /// the type of inclusion
213 Types type(InsetCommandParams const & params)
215 string const command_name = params.getCmdName();
217 if (command_name == "input")
219 if (command_name == "verbatiminput")
221 if (command_name == "verbatiminput*")
223 if (command_name == "lstinputlisting")
229 bool isVerbatim(InsetCommandParams const & params)
231 string const command_name = params.getCmdName();
232 return command_name == "verbatiminput" ||
233 command_name == "verbatiminput*";
237 bool isInputOrInclude(InsetCommandParams const & params)
239 Types const t = type(params);
240 return (t == INPUT) || (t == INCLUDE);
244 string const masterFilename(Buffer const & buffer)
246 return buffer.getMasterBuffer()->fileName();
250 string const parentFilename(Buffer const & buffer)
252 return buffer.fileName();
256 FileName const includedFilename(Buffer const & buffer,
257 InsetCommandParams const & params)
259 return makeAbsPath(to_utf8(params["filename"]),
260 onlyPath(parentFilename(buffer)));
264 void add_preview(RenderMonitoredPreview &, InsetInclude const &, Buffer const &);
269 void InsetInclude::set(InsetCommandParams const & p, Buffer const & buffer)
274 if (preview_->monitoring())
275 preview_->stopMonitoring();
277 if (type(params_) == INPUT)
278 add_preview(*preview_, *this, buffer);
282 auto_ptr<Inset> InsetInclude::doClone() const
284 return auto_ptr<Inset>(new InsetInclude(*this));
288 void InsetInclude::write(Buffer const &, ostream & os) const
294 void InsetInclude::write(ostream & os) const
296 os << "Include " << to_utf8(params_.getCommand()) << '\n'
297 << "preview " << convert<string>(params_.preview()) << '\n';
301 void InsetInclude::read(Buffer const &, Lexer & lex)
307 void InsetInclude::read(Lexer & lex)
311 string const command = lex.getString();
312 params_.scanCommand(command);
317 token = lex.getString();
318 if (token == "\\end_inset")
320 if (token == "preview") {
322 params_.preview(lex.getBool());
324 lex.printError("Unknown parameter name `$$Token' for command " + params_.getCmdName());
326 if (token != "\\end_inset") {
327 lex.printError("Missing \\end_inset at this point. "
333 docstring const InsetInclude::getScreenLabel(Buffer const & buf) const
337 switch (type(params_)) {
339 temp = buf.B_("Input");
342 temp = buf.B_("Verbatim Input");
345 temp = buf.B_("Verbatim Input*");
348 temp = buf.B_("Include");
351 temp = listings_label_;
357 if (params_["filename"].empty())
360 temp += from_utf8(onlyFilename(to_utf8(params_["filename"])));
368 /// return the child buffer if the file is a LyX doc and is loaded
369 Buffer * getChildBuffer(Buffer const & buffer, InsetCommandParams const & params)
371 if (isVerbatim(params) || isListings(params))
374 string const included_file = includedFilename(buffer, params).absFilename();
375 if (!isLyXFilename(included_file))
378 Buffer * childBuffer = theBufferList().getBuffer(included_file);
380 //FIXME RECURSIVE INCLUDES
381 if (childBuffer == & buffer)
390 Buffer * loadIfNeeded(Buffer const & buffer, InsetCommandParams const & params)
392 if (isVerbatim(params) || isListings(params))
395 FileName const included_file = includedFilename(buffer, params);
396 if (!isLyXFilename(included_file.absFilename()))
399 Buffer * buf = theBufferList().getBuffer(included_file.absFilename());
401 // the readonly flag can/will be wrong, not anymore I think.
402 if (!fs::exists(included_file.toFilesystemEncoding()))
405 lyx::dispatch(FuncRequest(LFUN_BUFFER_CHILD_OPEN,
406 included_file.absFilename() + "|true"));
407 buf = theBufferList().getBuffer(included_file.absFilename());
410 buf = theBufferList().newBuffer(included_file.absFilename());
411 if (!loadLyXFile(buf, included_file)) {
412 //close the buffer we just opened
413 theBufferList().close(buf, false);
419 buf->setParentName(parentFilename(buffer));
424 int InsetInclude::latex(Buffer const & buffer, odocstream & os,
425 OutputParams const & runparams) const
427 string incfile(to_utf8(params_["filename"]));
429 // Do nothing if no file name has been specified
433 FileName const included_file(includedFilename(buffer, params_));
435 //Check we're not trying to include ourselves.
436 //FIXME RECURSIVE INCLUDE
437 //This isn't sufficient, as the inclusion could be downstream.
438 //But it'll have to do for now.
439 if (isInputOrInclude(params_) &&
440 buffer.fileName() == included_file.absFilename())
442 Alert::error(_("Recursive input"),
443 bformat(_("Attempted to include file %1$s in itself! "
444 "Ignoring inclusion."), from_utf8(incfile)));
448 Buffer const * const m_buffer = buffer.getMasterBuffer();
450 // if incfile is relative, make it relative to the master
452 if (!absolutePath(incfile)) {
454 incfile = to_utf8(makeRelPath(from_utf8(included_file.absFilename()),
455 from_utf8(m_buffer->filePath())));
458 // write it to a file (so far the complete file)
459 string const exportfile = changeExtension(incfile, ".tex");
460 string const mangled =
461 DocFileName(changeExtension(included_file.absFilename(),".tex")).
463 FileName const writefile(makeAbsPath(mangled, m_buffer->temppath()));
467 else if (!isValidLaTeXFilename(incfile)) {
468 frontend::Alert::warning(_("Invalid filename"),
469 _("The following filename is likely to cause trouble "
470 "when running the exported file through LaTeX: ") +
473 LYXERR(Debug::LATEX) << "incfile:" << incfile << endl;
474 LYXERR(Debug::LATEX) << "exportfile:" << exportfile << endl;
475 LYXERR(Debug::LATEX) << "writefile:" << writefile << endl;
477 if (runparams.inComment || runparams.dryrun) {
478 //Don't try to load or copy the file if we're
479 //in a comment or doing a dryrun
480 } else if (isInputOrInclude(params_) &&
481 isLyXFilename(included_file.absFilename())) {
482 //if it's a LyX file and we're inputting or including,
483 //try to load it so we can write the associated latex
484 if (!loadIfNeeded(buffer, params_))
487 Buffer * tmp = theBufferList().getBuffer(included_file.absFilename());
489 if (tmp->params().textclass != m_buffer->params().textclass) {
491 docstring text = bformat(_("Included file `%1$s'\n"
492 "has textclass `%2$s'\n"
493 "while parent file has textclass `%3$s'."),
494 makeDisplayPath(included_file.absFilename()),
495 from_utf8(tmp->params().getTextClass().name()),
496 from_utf8(m_buffer->params().getTextClass().name()));
497 Alert::warning(_("Different textclasses"), text);
501 tmp->markDepClean(m_buffer->temppath());
503 // FIXME: handle non existing files
504 // FIXME: Second argument is irrelevant!
505 // since only_body is true, makeLaTeXFile will not look at second
506 // argument. Should we set it to string(), or should makeLaTeXFile
507 // make use of it somehow? (JMarc 20031002)
508 // The included file might be written in a different encoding
509 Encoding const * const oldEnc = runparams.encoding;
510 runparams.encoding = &tmp->params().encoding();
511 tmp->makeLaTeXFile(writefile,
512 onlyPath(masterFilename(buffer)),
514 runparams.encoding = oldEnc;
516 // In this case, it's not a LyX file, so we copy the file
517 // to the temp dir, so that .aux files etc. are not created
518 // in the original dir. Files included by this file will be
519 // found via input@path, see ../Buffer.cpp.
520 unsigned long const checksum_in = sum(included_file);
521 unsigned long const checksum_out = sum(writefile);
523 if (checksum_in != checksum_out) {
524 if (!copy(included_file, writefile)) {
527 << to_utf8(bformat(_("Could not copy the file\n%1$s\n"
528 "into the temporary directory."),
529 from_utf8(included_file.absFilename())))
536 string const tex_format = (runparams.flavor == OutputParams::LATEX) ?
537 "latex" : "pdflatex";
538 if (isVerbatim(params_)) {
539 incfile = latex_path(incfile);
541 os << '\\' << from_ascii(params_.getCmdName()) << '{'
542 << from_utf8(incfile) << '}';
543 } else if (type(params_) == INPUT) {
544 runparams.exportdata->addExternalFile(tex_format, writefile,
547 // \input wants file with extension (default is .tex)
548 if (!isLyXFilename(included_file.absFilename())) {
549 incfile = latex_path(incfile);
551 os << '\\' << from_ascii(params_.getCmdName())
552 << '{' << from_utf8(incfile) << '}';
554 incfile = changeExtension(incfile, ".tex");
555 incfile = latex_path(incfile);
557 os << '\\' << from_ascii(params_.getCmdName())
558 << '{' << from_utf8(incfile) << '}';
560 } else if (type(params_) == LISTINGS) {
561 os << '\\' << from_ascii(params_.getCmdName());
562 string opt = params_.getOptions();
563 // opt is set in QInclude dialog and should have passed validation.
564 InsetListingsParams params(opt);
565 if (!params.params().empty())
566 os << "[" << from_utf8(params.params()) << "]";
567 os << '{' << from_utf8(incfile) << '}';
569 runparams.exportdata->addExternalFile(tex_format, writefile,
572 // \include don't want extension and demands that the
573 // file really have .tex
574 incfile = changeExtension(incfile, string());
575 incfile = latex_path(incfile);
577 os << '\\' << from_ascii(params_.getCmdName()) << '{'
578 << from_utf8(incfile) << '}';
585 int InsetInclude::plaintext(Buffer const & buffer, odocstream & os,
586 OutputParams const &) const
588 if (isVerbatim(params_) || isListings(params_)) {
589 os << '[' << getScreenLabel(buffer) << '\n';
590 // FIXME: We don't know the encoding of the file
591 docstring const str =
592 from_utf8(getFileContents(includedFilename(buffer, params_)));
595 return PLAINTEXT_NEWLINE + 1; // one char on a separate line
597 docstring const str = '[' + getScreenLabel(buffer) + ']';
604 int InsetInclude::docbook(Buffer const & buffer, odocstream & os,
605 OutputParams const & runparams) const
607 string incfile = to_utf8(params_["filename"]);
609 // Do nothing if no file name has been specified
613 string const included_file = includedFilename(buffer, params_).absFilename();
615 //Check we're not trying to include ourselves.
616 //FIXME RECURSIVE INCLUDE
617 //This isn't sufficient, as the inclusion could be downstream.
618 //But it'll have to do for now.
619 if (buffer.fileName() == included_file) {
620 Alert::error(_("Recursive input"),
621 bformat(_("Attempted to include file %1$s in itself! "
622 "Ignoring inclusion."), from_utf8(incfile)));
626 // write it to a file (so far the complete file)
627 string const exportfile = changeExtension(incfile, ".sgml");
628 DocFileName writefile(changeExtension(included_file, ".sgml"));
630 if (loadIfNeeded(buffer, params_)) {
631 Buffer * tmp = theBufferList().getBuffer(included_file);
633 string const mangled = writefile.mangledFilename();
634 writefile = makeAbsPath(mangled,
635 buffer.getMasterBuffer()->temppath());
639 LYXERR(Debug::LATEX) << "incfile:" << incfile << endl;
640 LYXERR(Debug::LATEX) << "exportfile:" << exportfile << endl;
641 LYXERR(Debug::LATEX) << "writefile:" << writefile << endl;
643 tmp->makeDocBookFile(writefile, runparams, true);
646 runparams.exportdata->addExternalFile("docbook", writefile,
648 runparams.exportdata->addExternalFile("docbook-xml", writefile,
651 if (isVerbatim(params_) || isListings(params_)) {
652 os << "<inlinegraphic fileref=\""
653 << '&' << include_label << ';'
654 << "\" format=\"linespecific\">";
656 os << '&' << include_label << ';';
662 void InsetInclude::validate(LaTeXFeatures & features) const
664 string incfile(to_utf8(params_["filename"]));
667 Buffer const & buffer = features.buffer();
669 string const included_file = includedFilename(buffer, params_).absFilename();
671 if (isLyXFilename(included_file))
672 writefile = changeExtension(included_file, ".sgml");
674 writefile = included_file;
676 if (!features.runparams().nice && !isVerbatim(params_) && !isListings(params_)) {
677 incfile = DocFileName(writefile).mangledFilename();
678 writefile = makeAbsPath(incfile,
679 buffer.getMasterBuffer()->temppath()).absFilename();
682 features.includeFile(include_label, writefile);
684 if (isVerbatim(params_))
685 features.require("verbatim");
686 else if (isListings(params_))
687 features.require("listings");
689 // Here we must do the fun stuff...
690 // Load the file in the include if it needs
692 if (loadIfNeeded(buffer, params_)) {
694 Buffer * const tmp = theBufferList().getBuffer(included_file);
695 // make sure the buffer isn't us
696 // FIXME RECURSIVE INCLUDES
697 // This is not sufficient, as recursive includes could be
698 // more than a file away. But it will do for now.
699 if (tmp && tmp != & buffer) {
700 // We must temporarily change features.buffer,
701 // otherwise it would always be the master buffer,
702 // and nested includes would not work.
703 features.setBuffer(*tmp);
704 tmp->validate(features);
705 features.setBuffer(buffer);
711 void InsetInclude::getLabelList(Buffer const & buffer,
712 std::vector<docstring> & list) const
714 if (isListings(params_)) {
715 InsetListingsParams params(params_.getOptions());
716 string label = params.getParamValue("label");
718 list.push_back(from_utf8(label));
720 else if (loadIfNeeded(buffer, params_)) {
721 string const included_file = includedFilename(buffer, params_).absFilename();
722 Buffer * tmp = theBufferList().getBuffer(included_file);
723 tmp->setParentName("");
724 tmp->getLabelList(list);
725 tmp->setParentName(parentFilename(buffer));
730 void InsetInclude::fillWithBibKeys(Buffer const & buffer,
731 std::vector<std::pair<string, docstring> > & keys,
732 InsetIterator const & /*di*/) const
734 if (loadIfNeeded(buffer, params_)) {
735 string const included_file = includedFilename(buffer, params_).absFilename();
736 Buffer * tmp = theBufferList().getBuffer(included_file);
737 tmp->setParentName("");
738 tmp->fillWithBibKeys(keys);
739 tmp->setParentName(parentFilename(buffer));
744 void InsetInclude::updateBibfilesCache(Buffer const & buffer)
746 Buffer * const tmp = getChildBuffer(buffer, params_);
748 tmp->setParentName("");
749 tmp->updateBibfilesCache();
750 tmp->setParentName(parentFilename(buffer));
755 std::vector<FileName> const &
756 InsetInclude::getBibfilesCache(Buffer const & buffer) const
758 Buffer * const tmp = getChildBuffer(buffer, params_);
760 tmp->setParentName("");
761 std::vector<FileName> const & cache = tmp->getBibfilesCache();
762 tmp->setParentName(parentFilename(buffer));
765 static std::vector<FileName> const empty;
770 bool InsetInclude::metrics(MetricsInfo & mi, Dimension & dim) const
772 BOOST_ASSERT(mi.base.bv && mi.base.bv->buffer());
774 bool use_preview = false;
775 if (RenderPreview::status() != LyXRC::PREVIEW_OFF) {
776 graphics::PreviewImage const * pimage =
777 preview_->getPreviewImage(*mi.base.bv->buffer());
778 use_preview = pimage && pimage->image();
782 preview_->metrics(mi, dim);
786 button_.update(getScreenLabel(*mi.base.bv->buffer()),
789 button_.metrics(mi, dim);
792 Box b(0, dim.wid, -dim.asc, dim.des);
795 bool const changed = dim_ != dim;
801 void InsetInclude::draw(PainterInfo & pi, int x, int y) const
803 setPosCache(pi, x, y);
805 BOOST_ASSERT(pi.base.bv && pi.base.bv->buffer());
807 bool use_preview = false;
808 if (RenderPreview::status() != LyXRC::PREVIEW_OFF) {
809 graphics::PreviewImage const * pimage =
810 preview_->getPreviewImage(*pi.base.bv->buffer());
811 use_preview = pimage && pimage->image();
815 preview_->draw(pi, x, y);
817 button_.draw(pi, x, y);
821 Inset::DisplayType InsetInclude::display() const
823 return type(params_) == INPUT ? Inline : AlignCenter;
832 void InsetInclude::fileChanged() const
834 Buffer const * const buffer_ptr = LyX::cref().updateInset(this);
838 Buffer const & buffer = *buffer_ptr;
839 preview_->removePreview(buffer);
840 add_preview(*preview_.get(), *this, buffer);
841 preview_->startLoading(buffer);
847 bool preview_wanted(InsetCommandParams const & params, Buffer const & buffer)
849 FileName const included_file = includedFilename(buffer, params);
851 return type(params) == INPUT && params.preview() &&
852 isFileReadable(included_file);
856 docstring const latex_string(InsetInclude const & inset, Buffer const & buffer)
859 // We don't need to set runparams.encoding since this will be done
860 // by latex() anyway.
861 OutputParams runparams(0);
862 runparams.flavor = OutputParams::LATEX;
863 inset.latex(buffer, os, runparams);
869 void add_preview(RenderMonitoredPreview & renderer, InsetInclude const & inset,
870 Buffer const & buffer)
872 InsetCommandParams const & params = inset.params();
873 if (RenderPreview::status() != LyXRC::PREVIEW_OFF &&
874 preview_wanted(params, buffer)) {
875 renderer.setAbsFile(includedFilename(buffer, params));
876 docstring const snippet = latex_string(inset, buffer);
877 renderer.addPreview(snippet, buffer);
884 void InsetInclude::addPreview(graphics::PreviewLoader & ploader) const
886 Buffer const & buffer = ploader.buffer();
887 if (preview_wanted(params(), buffer)) {
888 preview_->setAbsFile(includedFilename(buffer, params()));
889 docstring const snippet = latex_string(*this, buffer);
890 preview_->addPreview(snippet, ploader);
895 void InsetInclude::addToToc(TocList & toclist, Buffer const & buffer, ParConstIterator const & pit) const
897 if (isListings(params_)) {
898 InsetListingsParams params(params_.getOptions());
899 string caption = params.getParamValue("caption");
900 if (!caption.empty()) {
901 Toc & toc = toclist["listing"];
902 docstring const str = convert<docstring>(toc.size() + 1)
903 + ". " + from_utf8(caption);
904 // This inset does not have a valid ParConstIterator
905 // so it has to use the iterator of its parent paragraph
906 toc.push_back(TocItem(pit, 0, str));
910 Buffer const * const childbuffer = getChildBuffer(buffer, params_);
914 TocList const & childtoclist = childbuffer->tocBackend().tocs();
915 TocList::const_iterator it = childtoclist.begin();
916 TocList::const_iterator const end = childtoclist.end();
917 for(; it != end; ++it)
918 toclist[it->first].insert(toclist[it->first].end(),
919 it->second.begin(), it->second.end());
923 void InsetInclude::updateLabels(Buffer const & buffer,
924 ParIterator const &) const
926 Buffer const * const childbuffer = getChildBuffer(buffer, params_);
928 lyx::updateLabels(*childbuffer, true);
929 else if (isListings(params_)) {
930 InsetListingsParams const par = params_.getOptions();
931 if (par.getParamValue("caption").empty())
932 listings_label_.clear();
934 Counters & counters = buffer.params().getTextClass().counters();
935 docstring const cnt = from_ascii("listing");
936 if (counters.hasCounter(cnt)) {
938 listings_label_ = buffer.B_("Program Listing ") + convert<docstring>(counters.value(cnt));
940 listings_label_ = buffer.B_("Program Listing");
946 string const InsetIncludeMailer::name_("include");
948 InsetIncludeMailer::InsetIncludeMailer(InsetInclude & inset)
953 string const InsetIncludeMailer::inset2string(Buffer const &) const
955 return params2string(inset_.params());
959 void InsetIncludeMailer::string2params(string const & in,
960 InsetCommandParams & params)
966 istringstream data(in);
972 if (!lex || name != name_)
973 return print_mailer_error("InsetIncludeMailer", in, 1, name_);
975 // This is part of the inset proper that is usually swallowed
976 // by Text::readInset
979 if (!lex || id != "Include")
980 return print_mailer_error("InsetIncludeMailer", in, 2, "Include");
982 InsetInclude inset(params);
984 params = inset.params();
989 InsetIncludeMailer::params2string(InsetCommandParams const & params)
991 InsetInclude inset(params);
993 data << name_ << ' ';
995 data << "\\end_inset\n";