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