]> git.lyx.org Git - lyx.git/blob - src/insets/insetexternal.C
Introduce and use latex_path().
[lyx.git] / src / insets / insetexternal.C
1 /**
2  * \file insetexternal.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Asger Alstrup Nielsen
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "insetexternal.h"
14 #include "insets/ExternalSupport.h"
15 #include "insets/ExternalTemplate.h"
16 #include "insets/render_button.h"
17 #include "insets/render_graphic.h"
18 #include "insets/render_preview.h"
19
20 #include "buffer.h"
21 #include "BufferView.h"
22 #include "cursor.h"
23 #include "debug.h"
24 #include "dispatchresult.h"
25 #include "exporter.h"
26 #include "funcrequest.h"
27 #include "gettext.h"
28 #include "LaTeXFeatures.h"
29 #include "lyx_main.h"
30 #include "lyxlex.h"
31 #include "lyxrc.h"
32 #include "metricsinfo.h"
33 #include "outputparams.h"
34
35 #include "frontends/lyx_gui.h"
36 #include "frontends/LyXView.h"
37
38 #include "graphics/PreviewLoader.h"
39
40 #include "support/filetools.h"
41 #include "support/lstrings.h"
42 #include "support/lyxlib.h"
43 #include "support/convert.h"
44 #include "support/translator.h"
45
46 #include <boost/bind.hpp>
47
48 #include <sstream>
49
50 namespace support = lyx::support;
51 namespace external = lyx::external;
52 namespace graphics = lyx::graphics;
53
54 using std::endl;
55 using std::string;
56 using std::auto_ptr;
57 using std::istringstream;
58 using std::ostream;
59 using std::ostringstream;
60 using std::vector;
61
62
63 namespace {
64
65 external::DisplayType const defaultDisplayType = external::NoDisplay;
66
67 unsigned int const defaultLyxScale = 100;
68
69 string defaultTemplateName = "RasterImage";
70
71 } // namespace anon
72
73
74 namespace lyx {
75 namespace external {
76
77 TempName::TempName()
78 {
79         tempname_ = support::tempName(string(), "lyxext");
80         // FIXME: This is unsafe
81         support::unlink(tempname_);
82         // must have an extension for the converter code to work correctly.
83         tempname_ += ".tmp";
84 }
85
86
87 TempName::TempName(TempName const &)
88 {
89         tempname_ = TempName()();
90 }
91
92
93 TempName::~TempName()
94 {
95         support::unlink(tempname_);
96 }
97
98
99 TempName &
100 TempName::operator=(TempName const & other)
101 {
102         if (this != &other)
103                 tempname_ = TempName()();
104         return *this;
105 }
106
107
108 namespace {
109
110 /// The translator between the Display enum and corresponding lyx string.
111 Translator<DisplayType, string> const initTranslator()
112 {
113         Translator<DisplayType, string> translator(DefaultDisplay, "default");
114
115         // Fill the display translator
116         translator.addPair(MonochromeDisplay, "monochrome");
117         translator.addPair(GrayscaleDisplay, "grayscale");
118         translator.addPair(ColorDisplay, "color");
119         translator.addPair(PreviewDisplay, "preview");
120         translator.addPair(NoDisplay, "none");
121
122         return translator;
123 }
124
125 } // namespace anon
126
127
128 Translator<DisplayType, string> const & displayTranslator()
129 {
130         static Translator<DisplayType, string> const translator =
131                 initTranslator();
132         return translator;
133 }
134
135 } // namespace external
136 } // namespace lyx
137
138
139 InsetExternalParams::InsetExternalParams()
140         : display(defaultDisplayType),
141           lyxscale(defaultLyxScale),
142           draft(false),
143           templatename_(defaultTemplateName)
144 {}
145
146
147 namespace {
148
149 template <typename T>
150 void clearIfNotFound(T & data, external::TransformID value,
151                      vector<external::TransformID> const & ids)
152 {
153         typedef vector<external::TransformID>::const_iterator
154                 const_iterator;
155
156         const_iterator it  = ids.begin();
157         const_iterator end = ids.end();
158         it = std::find(it, end, value);
159         if (it == end)
160                 data = T();
161 }
162
163 } // namespace anon
164
165
166 void InsetExternalParams::settemplate(string const & name)
167 {
168         templatename_ = name;
169
170         external::TemplateManager const & etm =
171                 external::TemplateManager::get();
172         external::Template const * const et = etm.getTemplateByName(name);
173         if (!et)
174                 // Be safe. Don't lose data.
175                 return;
176
177         // Ascertain which transforms the template supports.
178         // Empty all those that it doesn't.
179         vector<external::TransformID> const & ids = et->transformIds;
180         clearIfNotFound(clipdata,     external::Clip,   ids);
181         clearIfNotFound(extradata,    external::Extra,  ids);
182         clearIfNotFound(resizedata,   external::Resize, ids);
183         clearIfNotFound(rotationdata, external::Rotate, ids);
184 }
185
186
187 void InsetExternalParams::write(Buffer const & buffer, ostream & os) const
188 {
189         os << "External\n"
190            << "\ttemplate " << templatename() << '\n';
191
192         if (!filename.empty())
193                 os << "\tfilename "
194                    << filename.outputFilename(buffer.filePath())
195                    << '\n';
196
197         if (display != defaultDisplayType)
198                 os << "\tdisplay "
199                    << external::displayTranslator().find(display)
200                    << '\n';
201
202         if (lyxscale != defaultLyxScale)
203                 os << "\tlyxscale " << convert<string>(lyxscale) << '\n';
204
205         if (draft)
206                 os << "\tdraft\n";
207
208         if (!clipdata.bbox.empty())
209                 os << "\tboundingBox " << clipdata.bbox << '\n';
210         if (clipdata.clip)
211                 os << "\tclip\n";
212
213         external::ExtraData::const_iterator it  = extradata.begin();
214         external::ExtraData::const_iterator end = extradata.end();
215         for (; it != end; ++it) {
216                 if (!it->second.empty())
217                         os << "\textra " << it->first << " \""
218                            << it->second << "\"\n";
219         }
220
221         if (!rotationdata.no_rotation()) {
222                 os << "\trotateAngle " << rotationdata.adjAngle() << '\n';
223                 if (rotationdata.origin() != external::RotationData::DEFAULT)
224                         os << "\trotateOrigin "
225                            << rotationdata.originString() << '\n';
226         }
227
228         if (!resizedata.no_resize()) {
229                 using support::float_equal;
230                 double const scl = convert<double>(resizedata.scale);
231                 if (!float_equal(scl, 0.0, 0.05)) {
232                         if (!float_equal(scl, 100.0, 0.05))
233                                 os << "\tscale "
234                                    << resizedata.scale << '\n';
235                 } else {
236                         if (!resizedata.width.zero())
237                                 os << "\twidth "
238                                    << resizedata.width.asString() << '\n';
239                         if (!resizedata.height.zero())
240                                 os << "\theight "
241                                    << resizedata.height.asString() << '\n';
242                 }
243                 if (resizedata.keepAspectRatio)
244                         os << "\tkeepAspectRatio\n";
245         }
246 }
247
248
249 bool InsetExternalParams::read(Buffer const & buffer, LyXLex & lex)
250 {
251         enum ExternalTags {
252                 EX_TEMPLATE = 1,
253                 EX_FILENAME,
254                 EX_DISPLAY,
255                 EX_LYXSCALE,
256                 EX_DRAFT,
257                 EX_BOUNDINGBOX,
258                 EX_CLIP,
259                 EX_EXTRA,
260                 EX_HEIGHT,
261                 EX_KEEPASPECTRATIO,
262                 EX_ROTATEANGLE,
263                 EX_ROTATEORIGIN,
264                 EX_SCALE,
265                 EX_WIDTH,
266                 EX_END
267         };
268
269         keyword_item external_tags[] = {
270                 { "\\end_inset",     EX_END },
271                 { "boundingBox",     EX_BOUNDINGBOX },
272                 { "clip",            EX_CLIP },
273                 { "display",         EX_DISPLAY},
274                 { "draft",           EX_DRAFT},
275                 { "extra",           EX_EXTRA },
276                 { "filename",        EX_FILENAME},
277                 { "height",          EX_HEIGHT },
278                 { "keepAspectRatio", EX_KEEPASPECTRATIO },
279                 { "lyxscale",        EX_LYXSCALE},
280                 { "rotateAngle",     EX_ROTATEANGLE },
281                 { "rotateOrigin",    EX_ROTATEORIGIN },
282                 { "scale",           EX_SCALE },
283                 { "template",        EX_TEMPLATE },
284                 { "width",           EX_WIDTH }
285         };
286
287         pushpophelper pph(lex, external_tags, EX_END);
288
289         bool found_end  = false;
290         bool read_error = false;
291
292         while (lex.isOK()) {
293                 switch (lex.lex()) {
294                 case EX_TEMPLATE:
295                         lex.next();
296                         templatename_ = lex.getString();
297                         break;
298
299                 case EX_FILENAME: {
300                         lex.next();
301                         string const name = lex.getString();
302                         filename.set(name, buffer.filePath());
303                         break;
304                 }
305
306                 case EX_DISPLAY: {
307                         lex.next();
308                         string const name = lex.getString();
309                         display = external::displayTranslator().find(name);
310                         break;
311                 }
312
313                 case EX_LYXSCALE:
314                         lex.next();
315                         lyxscale = lex.getInteger();
316                         break;
317
318                 case EX_DRAFT:
319                         draft = true;
320                         break;
321
322                 case EX_BOUNDINGBOX:
323                         lex.next();
324                         clipdata.bbox.xl = lex.getInteger();
325                         lex.next();
326                         clipdata.bbox.yb = lex.getInteger();
327                         lex.next();
328                         clipdata.bbox.xr = lex.getInteger();
329                         lex.next();
330                         clipdata.bbox.yt = lex.getInteger();
331                         break;
332
333                 case EX_CLIP:
334                         clipdata.clip = true;
335                         break;
336
337                 case EX_EXTRA: {
338                         lex.next();
339                         string const name = lex.getString();
340                         lex.next();
341                         extradata.set(name, lex.getString());
342                         break;
343                 }
344
345                 case EX_HEIGHT:
346                         lex.next();
347                         resizedata.height = LyXLength(lex.getString());
348                         break;
349
350                 case EX_KEEPASPECTRATIO:
351                         resizedata.keepAspectRatio = true;
352                         break;
353
354                 case EX_ROTATEANGLE:
355                         lex.next();
356                         rotationdata.angle = lex.getString();
357                         break;
358
359                 case EX_ROTATEORIGIN:
360                         lex.next();
361                         rotationdata.origin(lex.getString());
362                         break;
363
364                 case EX_SCALE:
365                         lex.next();
366                         resizedata.scale = lex.getString();
367                         break;
368
369                 case EX_WIDTH:
370                         lex.next();
371                         resizedata.width = LyXLength(lex.getString());
372                         break;
373
374                 case EX_END:
375                         found_end = true;
376                         break;
377
378                 default:
379                         lex.printError("ExternalInset::read: "
380                                        "Wrong tag: $$Token");
381                         read_error = true;
382                         break;
383                 }
384
385                 if (found_end || read_error)
386                         break;
387         }
388
389         if (!found_end)
390                 lex.printError("ExternalInsetParams::read: Missing \\end_inset.");
391
392         // This is a trick to make sure that the data are self-consistent.
393         settemplate(templatename_);
394
395         if (lyxerr.debugging(Debug::EXTERNAL)) {
396                 lyxerr  << "InsetExternalParams::read:\n";
397                 write(buffer, lyxerr);
398         }
399
400         return !read_error;
401 }
402
403
404 InsetExternal::InsetExternal()
405         : renderer_(new RenderButton)
406 {}
407
408
409 InsetExternal::InsetExternal(InsetExternal const & other)
410         : InsetOld(other),
411           boost::signals::trackable(),
412           params_(other.params_),
413           renderer_(other.renderer_->clone(this))
414 {}
415
416
417 auto_ptr<InsetBase> InsetExternal::doClone() const
418 {
419         return auto_ptr<InsetBase>(new InsetExternal(*this));
420 }
421
422
423 InsetExternal::~InsetExternal()
424 {
425         InsetExternalMailer(*this).hideDialog();
426 }
427
428
429 void InsetExternal::statusChanged() const
430 {
431         LyX::cref().updateInset(this);
432 }
433
434
435 void InsetExternal::doDispatch(LCursor & cur, FuncRequest & cmd)
436 {
437         switch (cmd.action) {
438
439         case LFUN_EXTERNAL_EDIT: {
440                 Buffer const & buffer = cur.buffer();
441                 InsetExternalParams p;
442                 InsetExternalMailer::string2params(cmd.argument, buffer, p);
443                 external::editExternal(p, buffer);
444                 break;
445         }
446
447         case LFUN_INSET_MODIFY: {
448                 Buffer const & buffer = cur.buffer();
449                 InsetExternalParams p;
450                 InsetExternalMailer::string2params(cmd.argument, buffer, p);
451                 setParams(p, buffer);
452                 break;
453         }
454
455         case LFUN_INSET_DIALOG_UPDATE:
456                 InsetExternalMailer(*this).updateDialog(&cur.bv());
457                 break;
458
459         case LFUN_MOUSE_RELEASE:
460                 InsetExternalMailer(*this).showDialog(&cur.bv());
461                 break;
462
463         default:
464                 InsetBase::doDispatch(cur, cmd);
465         }
466 }
467
468
469 void InsetExternal::edit(LCursor & cur, bool)
470 {
471         InsetExternalMailer(*this).showDialog(&cur.bv());
472 }
473
474
475 void InsetExternal::metrics(MetricsInfo & mi, Dimension & dim) const
476 {
477         renderer_->metrics(mi, dim);
478         dim_ = dim;
479 }
480
481
482 void InsetExternal::draw(PainterInfo & pi, int x, int y) const
483 {
484         setPosCache(pi, x, y);
485         renderer_->draw(pi, x, y);
486 }
487
488
489 namespace {
490
491 enum RenderType {
492         RENDERBUTTON,
493         RENDERGRAPHIC,
494         RENDERPREVIEW
495 };
496
497
498 RenderType getRenderType(InsetExternalParams const & p)
499 {
500         if (!external::getTemplatePtr(p) ||
501             p.filename.empty() ||
502             p.display == external::NoDisplay)
503                 return RENDERBUTTON;
504
505         if (p.display == external::PreviewDisplay) {
506                 if (RenderPreview::status() != LyXRC::PREVIEW_OFF)
507                         return RENDERPREVIEW;
508                 return RENDERBUTTON;
509         }
510
511         if (p.display == external::DefaultDisplay &&
512             lyxrc.display_graphics == graphics::NoDisplay)
513                 return RENDERBUTTON;
514         return RENDERGRAPHIC;
515 }
516
517
518 graphics::Params get_grfx_params(InsetExternalParams const & eparams)
519 {
520         graphics::Params gparams;
521
522         gparams.filename = eparams.filename.absFilename();
523         gparams.scale = eparams.lyxscale;
524         if (eparams.clipdata.clip)
525                 gparams.bb = eparams.clipdata.bbox;
526         gparams.angle = convert<double>(eparams.rotationdata.adjAngle());
527
528         switch (eparams.display) {
529         case external::DefaultDisplay:
530                 gparams.display = graphics::DefaultDisplay;
531                 break;
532         case external::MonochromeDisplay:
533                 gparams.display = graphics::MonochromeDisplay;
534                 break;
535         case external::GrayscaleDisplay:
536                 gparams.display = graphics::GrayscaleDisplay;
537                 break;
538         case external::ColorDisplay:
539                 gparams.display = graphics::ColorDisplay;
540                 break;
541         case external::NoDisplay:
542                 gparams.display = graphics::NoDisplay;
543                 break;
544         default:
545                 BOOST_ASSERT(false);
546         }
547         if (gparams.display == graphics::DefaultDisplay)
548                 gparams.display = lyxrc.display_graphics;
549         // Override the above if we're not using a gui
550         if (!lyx_gui::use_gui)
551                 gparams.display = graphics::NoDisplay;
552
553         return gparams;
554 }
555
556
557 string const getScreenLabel(InsetExternalParams const & params,
558                             Buffer const & buffer)
559 {
560         external::Template const * const ptr =
561                 external::getTemplatePtr(params);
562         if (!ptr)
563                 return support::bformat(_("External template %1$s is not installed"),
564                                         params.templatename());
565         return external::doSubstitution(params, buffer, ptr->guiName, false);
566 }
567
568 void add_preview_and_start_loading(RenderMonitoredPreview &,
569                                    InsetExternal const &,
570                                    Buffer const &);
571
572 } // namespace anon
573
574
575 InsetExternalParams const & InsetExternal::params() const
576 {
577         return params_;
578 }
579
580
581 void InsetExternal::setParams(InsetExternalParams const & p,
582                               Buffer const & buffer)
583 {
584         params_ = p;
585
586         // Subsequent calls to the InsetExternal::Params default constructor
587         // will use this.
588         defaultTemplateName = params_.templatename();
589
590         switch (getRenderType(params_)) {
591         case RENDERBUTTON: {
592                 RenderButton * button_ptr = renderer_->asButton();
593                 if (!button_ptr) {
594                         renderer_.reset(new RenderButton);
595                         button_ptr = renderer_->asButton();
596                 }
597
598                 button_ptr->update(getScreenLabel(params_, buffer), true);
599                 break;
600
601         } case RENDERGRAPHIC: {
602                 RenderGraphic * graphic_ptr = renderer_->asGraphic();
603                 if (!graphic_ptr) {
604                         renderer_.reset(new RenderGraphic(this));
605                         graphic_ptr = renderer_->asGraphic();
606                 }
607
608                 graphic_ptr->update(get_grfx_params(params_));
609
610                 break;
611
612         } case RENDERPREVIEW: {
613                 RenderMonitoredPreview * preview_ptr =
614                         renderer_->asMonitoredPreview();
615                 if (!preview_ptr) {
616                         renderer_.reset(new RenderMonitoredPreview(this));
617                         preview_ptr = renderer_->asMonitoredPreview();
618                         preview_ptr->fileChanged(
619                                 boost::bind(&InsetExternal::fileChanged, this));
620                 }
621
622                 if (preview_ptr->monitoring())
623                         preview_ptr->stopMonitoring();
624                 add_preview_and_start_loading(*preview_ptr, *this, buffer);
625
626                 break;
627         }
628         }
629 }
630
631
632 void InsetExternal::fileChanged() const
633 {
634         Buffer const * const buffer_ptr = LyX::cref().updateInset(this);
635         if (!buffer_ptr)
636                 return;
637
638         RenderMonitoredPreview * const ptr = renderer_->asMonitoredPreview();
639         BOOST_ASSERT(ptr);
640
641         Buffer const & buffer = *buffer_ptr;
642         ptr->removePreview(buffer);
643         add_preview_and_start_loading(*ptr, *this, buffer);
644 }
645
646
647 void InsetExternal::write(Buffer const & buffer, ostream & os) const
648 {
649         params_.write(buffer, os);
650 }
651
652
653 void InsetExternal::read(Buffer const & buffer, LyXLex & lex)
654 {
655         InsetExternalParams params;
656         if (params.read(buffer, lex))
657                 setParams(params, buffer);
658 }
659
660
661 int InsetExternal::latex(Buffer const & buf, ostream & os,
662                          OutputParams const & runparams) const
663 {
664         if (params_.draft) {
665                 os << "\\fbox{\\ttfamily{}"
666                    << params_.filename.outputFilename(buf.filePath())
667                    << "}\n";
668                 return 1;
669         }
670
671         // "nice" means that the buffer is exported to LaTeX format but not
672         // run through the LaTeX compiler.
673         // If we're running through the LaTeX compiler, we should write the
674         // generated files in the bufer's temporary directory.
675         bool const external_in_tmpdir = !runparams.nice;
676
677         // If the template has specified a PDFLaTeX output, then we try and
678         // use that.
679         if (runparams.flavor == OutputParams::PDFLATEX) {
680                 external::Template const * const et_ptr =
681                         external::getTemplatePtr(params_);
682                 if (!et_ptr)
683                         return 0;
684                 external::Template const & et = *et_ptr;
685
686                 external::Template::Formats::const_iterator cit =
687                         et.formats.find("PDFLaTeX");
688                 if (cit != et.formats.end())
689                         return external::writeExternal(params_, "PDFLaTeX",
690                                                        buf, os,
691                                                        *(runparams.exportdata),
692                                                        external_in_tmpdir);
693         }
694         return external::writeExternal(params_, "LaTeX", buf, os,
695                                        *(runparams.exportdata),
696                                        external_in_tmpdir);
697 }
698
699
700 int InsetExternal::plaintext(Buffer const & buf, ostream & os,
701                          OutputParams const & runparams) const
702 {
703         return external::writeExternal(params_, "Ascii", buf, os,
704                                        *(runparams.exportdata));
705 }
706
707
708 int InsetExternal::linuxdoc(Buffer const & buf, ostream & os,
709                             OutputParams const & runparams) const
710 {
711         return external::writeExternal(params_, "LinuxDoc", buf, os,
712                                        *(runparams.exportdata));
713 }
714
715
716 int InsetExternal::docbook(Buffer const & buf, ostream & os,
717                            OutputParams const & runparams) const
718 {
719         return external::writeExternal(params_, "DocBook", buf, os,
720                                        *(runparams.exportdata));
721 }
722
723
724 void InsetExternal::validate(LaTeXFeatures & features) const
725 {
726         if (params_.draft)
727                 return;
728
729         external::Template const * const et_ptr =
730                 external::getTemplatePtr(params_);
731         if (!et_ptr)
732                 return;
733         external::Template const & et = *et_ptr;
734
735         external::Template::Formats::const_iterator cit =
736                 et.formats.find("LaTeX");
737         if (cit == et.formats.end())
738                 return;
739
740         vector<string>::const_iterator it  = cit->second.requirements.begin();
741         vector<string>::const_iterator end = cit->second.requirements.end();
742         for (; it != end; ++it)
743                 features.require(*it);
744
745         external::TemplateManager & etm = external::TemplateManager::get();
746
747         it  = cit->second.preambleNames.begin();
748         end = cit->second.preambleNames.end();
749         for (; it != end; ++it) {
750                 string const preamble = etm.getPreambleDefByName(*it);
751                 if (!preamble.empty())
752                         features.addExternalPreamble(preamble);
753         }
754 }
755
756
757 //
758 // preview stuff
759 //
760
761 namespace {
762
763 bool preview_wanted(InsetExternalParams const & params)
764 {
765         string const included_file = params.filename.absFilename();
766
767         return params.display == external::PreviewDisplay &&
768                 support::IsFileReadable(included_file);
769 }
770
771
772 string const latex_string(InsetExternal const & inset, Buffer const & buffer)
773 {
774         ostringstream os;
775         OutputParams runparams;
776         runparams.flavor = OutputParams::LATEX;
777         inset.latex(buffer, os, runparams);
778
779         return os.str();
780 }
781
782
783 void add_preview_and_start_loading(RenderMonitoredPreview & renderer,
784                                    InsetExternal const & inset,
785                                    Buffer const & buffer)
786 {
787         InsetExternalParams const & params = inset.params();
788
789         if (RenderPreview::status() != LyXRC::PREVIEW_OFF &&
790             preview_wanted(params)) {
791                 renderer.setAbsFile(params.filename.absFilename());
792                 string const snippet = latex_string(inset, buffer);
793                 renderer.addPreview(snippet, buffer);
794                 renderer.startLoading(buffer);
795         }
796 }
797
798 } // namespace anon
799
800
801 void InsetExternal::addPreview(graphics::PreviewLoader & ploader) const
802 {
803         RenderMonitoredPreview * const ptr = renderer_->asMonitoredPreview();
804         if (!ptr)
805                 return;
806
807         if (preview_wanted(params())) {
808                 ptr->setAbsFile(params_.filename.absFilename());
809                 string const snippet = latex_string(*this, ploader.buffer());
810                 ptr->addPreview(snippet, ploader);
811         }
812 }
813
814
815 /// Mailer stuff
816
817 string const InsetExternalMailer::name_("external");
818
819 InsetExternalMailer::InsetExternalMailer(InsetExternal & inset)
820         : inset_(inset)
821 {}
822
823
824 string const InsetExternalMailer::inset2string(Buffer const & buffer) const
825 {
826         return params2string(inset_.params(), buffer);
827 }
828
829
830 void InsetExternalMailer::string2params(string const & in,
831                                         Buffer const & buffer,
832                                         InsetExternalParams & params)
833 {
834         params = InsetExternalParams();
835         if (in.empty())
836                 return;
837
838         istringstream data(in);
839         LyXLex lex(0,0);
840         lex.setStream(data);
841
842         string name;
843         lex >> name;
844         if (!lex || name != name_)
845                 return print_mailer_error("InsetExternalMailer", in, 1, name_);
846
847         // This is part of the inset proper that is usually swallowed
848         // by LyXText::readInset
849         string id;
850         lex >> id;
851         if (!lex || id != "External")
852                 return print_mailer_error("InsetBoxMailer", in, 2, "External");
853
854         params.read(buffer, lex);
855 }
856
857
858 string const
859 InsetExternalMailer::params2string(InsetExternalParams const & params,
860                                    Buffer const & buffer)
861 {
862         ostringstream data;
863         data << name_ << ' ';
864         params.write(buffer, data);
865         data << "\\end_inset\n";
866         return data.str();
867 }