]> git.lyx.org Git - lyx.git/blob - src/factory.cpp
858e53f138de902f1d0823688d070a588f03b9e1
[lyx.git] / src / factory.cpp
1 /**
2  * \file factory.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author André Pönitz
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "factory.h"
14
15 #include "Buffer.h"
16 #include "BufferParams.h"
17 #include "FloatList.h"
18 #include "FuncRequest.h"
19 #include "Lexer.h"
20 #include "LyX.h"
21 #include "TextClass.h"
22
23 #include "insets/InsetBibitem.h"
24 #include "insets/InsetBibtex.h"
25 #include "insets/InsetBox.h"
26 #include "insets/InsetBranch.h"
27 #include "insets/InsetCaption.h"
28 #include "insets/InsetCitation.h"
29 #include "insets/InsetFlex.h"
30 #include "insets/InsetERT.h"
31 #include "insets/InsetListings.h"
32 #include "insets/InsetExternal.h"
33 #include "insets/InsetFloat.h"
34 #include "insets/InsetFloatList.h"
35 #include "insets/InsetFoot.h"
36 #include "insets/InsetGraphics.h"
37 #include "insets/InsetHyperlink.h"
38 #include "insets/InsetInclude.h"
39 #include "insets/InsetIndex.h"
40 #include "insets/InsetInfo.h"
41 #include "insets/InsetIPA.h"
42 #include "insets/InsetIPAMacro.h"
43 #include "insets/InsetLabel.h"
44 #include "insets/InsetLine.h"
45 #include "insets/InsetMarginal.h"
46 #include "insets/InsetNewline.h"
47 #include "insets/InsetNewpage.h"
48 #include "insets/InsetNomencl.h"
49 #include "insets/InsetNote.h"
50 #include "insets/InsetArgument.h"
51 #include "insets/InsetPhantom.h"
52 #include "insets/InsetPreview.h"
53 #include "insets/InsetRef.h"
54 #include "insets/InsetScript.h"
55 #include "insets/InsetSpace.h"
56 #include "insets/InsetTabular.h"
57 #include "insets/InsetTOC.h"
58 #include "insets/InsetVSpace.h"
59 #include "insets/InsetWrap.h"
60
61 #include "mathed/MathMacroTemplate.h"
62 #include "mathed/InsetMathHull.h"
63
64 #include "frontends/alert.h"
65
66 #include "support/debug.h"
67 #include "support/lstrings.h"
68 #include "support/ExceptionMessage.h"
69
70 #include "support/lassert.h"
71
72 #include <sstream>
73
74 using namespace std;
75 using namespace lyx::support;
76
77 namespace lyx {
78
79 namespace Alert = frontend::Alert;
80
81
82 Inset * createInsetHelper(Buffer * buf, FuncRequest const & cmd)
83 {
84         try {
85
86                 switch (cmd.action()) {
87
88                 case LFUN_NEWPAGE_INSERT: {
89                         string const name = cmd.getArg(0);
90                         InsetNewpageParams inp;
91                         if (name.empty() || name == "newpage")
92                                 inp.kind = InsetNewpageParams::NEWPAGE;
93                         else if (name == "pagebreak")
94                                 inp.kind = InsetNewpageParams::PAGEBREAK;
95                         else if (name == "clearpage")
96                                 inp.kind = InsetNewpageParams::CLEARPAGE;
97                         else if (name == "cleardoublepage")
98                                 inp.kind = InsetNewpageParams::CLEARDOUBLEPAGE;
99                         return new InsetNewpage(inp);
100                 }
101
102                 case LFUN_FLEX_INSERT: {
103                         string s = cmd.getArg(0);
104                         return new InsetFlex(buf, s);
105                 }
106
107                 case LFUN_NOTE_INSERT: {
108                         string arg = cmd.getArg(0);
109                         if (arg.empty())
110                                 arg = "Note";
111                         return new InsetNote(buf, arg);
112                 }
113
114                 case LFUN_BOX_INSERT: {
115                         string arg = cmd.getArg(0);
116                         if (arg.empty())
117                                 arg = "Boxed";
118                         return new InsetBox(buf, arg);
119                 }
120
121                 case LFUN_BRANCH_INSERT: {
122                         docstring arg = cmd.argument();
123                         if (arg.empty())
124                                 arg = from_ascii("none");
125                         return new InsetBranch(buf, InsetBranchParams(arg));
126                 }
127
128                 case LFUN_PHANTOM_INSERT: {
129                         string arg = cmd.getArg(0);
130                         if (arg.empty())
131                                 arg = "Phantom";
132                         return new InsetPhantom(buf, arg);
133                 }
134
135                 case LFUN_IPAMACRO_INSERT: {
136                         string const arg1 = cmd.getArg(0);
137                         string const arg2 = cmd.getArg(1);
138                         if (arg1 != "deco") {
139                                 LYXERR0("LFUN_IPAMACRO_INSERT: wrong argument");
140                                 return 0;
141                         }
142                         return new InsetIPADeco(buf, arg2);
143                 }
144
145                 case LFUN_ERT_INSERT:
146                         return new InsetERT(buf);
147
148                 case LFUN_LISTING_INSERT:
149                         return new InsetListings(buf);
150
151                 case LFUN_FOOTNOTE_INSERT:
152                         return new InsetFoot(buf);
153
154                 case LFUN_MARGINALNOTE_INSERT:
155                         return new InsetMarginal(buf);
156
157                 case LFUN_ARGUMENT_INSERT:
158                         return new InsetArgument(buf);
159
160                 case LFUN_FLOAT_INSERT: {
161                         string argument = to_utf8(cmd.argument());
162                         if (!argument.empty()) {
163                                 if (!contains(argument, "sideways")) {
164                                         if (!contains(argument, "wide"))
165                                                 argument += "\nwide false";
166                                         argument += "\nsideways false";
167                                 }
168                         }
169                         return new InsetFloat(buf, argument);
170                 }
171
172                 case LFUN_FLOAT_WIDE_INSERT: {
173                         string argument = to_utf8(cmd.argument());
174                         if (!argument.empty()) {
175                                 if (!contains(argument, "sideways")) {
176                                         if (!contains(argument, "wide"))
177                                                 argument += "\nwide true";
178                                         argument += "\nsideways false";
179                                 }
180                         }
181                         InsetFloat * fl = new InsetFloat(buf, argument);
182                         fl->setWide(true);
183                         return fl;
184                 }
185
186                 case LFUN_WRAP_INSERT: {
187                         string const argument = to_utf8(cmd.argument());
188                         if (argument == "figure" || argument == "table")
189                                 return new InsetWrap(buf, argument);
190                         lyxerr << "Non-existent wrapfig type: " << argument << endl;
191                         return 0;
192                 }
193
194                 case LFUN_INDEX_INSERT: {
195                         docstring arg = cmd.argument();
196                         return new InsetIndex(buf, InsetIndexParams(arg));
197                 }
198
199                 case LFUN_IPA_INSERT:
200                         return new InsetIPA(buf);
201
202                 case LFUN_NOMENCL_INSERT: {
203                         InsetCommandParams icp(NOMENCL_CODE);
204                         icp["symbol"] = cmd.argument();
205                         return new InsetNomencl(buf, icp);
206                 }
207
208                 case LFUN_TABULAR_INSERT: {
209                         if (cmd.argument().empty())
210                                 return 0;
211                         istringstream ss(to_utf8(cmd.argument()));
212                         int r = 0, c = 0;
213                         ss >> r >> c;
214                         if (r <= 0)
215                                 r = 2;
216                         if (c <= 0)
217                                 c = 2;
218                         return new InsetTabular(buf, r, c);
219                 }
220
221                 case LFUN_CAPTION_INSERT:
222                         return new InsetCaption(buf);
223
224                 case LFUN_INDEX_PRINT:  {
225                         InsetCommandParams icp(INDEX_PRINT_CODE);
226                         icp["type"] = cmd.argument();
227                         return new InsetPrintIndex(buf, icp);
228                 }
229
230                 case LFUN_NOMENCL_PRINT: {
231                         InsetCommandParams icp(NOMENCL_PRINT_CODE);
232                         icp["set_width"] = from_ascii("auto");
233                         return new InsetPrintNomencl(buf, icp);
234                 }
235
236                 case LFUN_INFO_INSERT: {
237                         InsetInfo * inset = new InsetInfo(buf, to_utf8(cmd.argument()));
238                         inset->updateInfo();
239                         return inset;
240                 }
241
242                 case LFUN_PREVIEW_INSERT:
243                         return new InsetPreview(buf);
244
245                 case LFUN_SCRIPT_INSERT: {
246                         InsetScriptParams isp;
247                         InsetScript::string2params("script script " + to_utf8(cmd.argument()), isp);
248                         return new InsetScript(buf, isp);
249                 }
250
251                 case LFUN_INSET_INSERT: {
252                         string const name = cmd.getArg(0);
253                         InsetCode code = insetCode(name);
254                         switch (code) {
255                         case NO_CODE:
256                                 lyxerr << "No such inset '" << name << "'.";
257                                 return 0;
258                         
259                         case BIBITEM_CODE: {
260                                 InsetCommandParams icp(code);
261                                 InsetCommand::string2params(to_utf8(cmd.argument()), icp);
262                                 return new InsetBibitem(buf, icp);
263                         }
264                         
265                         case BIBTEX_CODE: {
266                                 InsetCommandParams icp(code);
267                                 InsetCommand::string2params(to_utf8(cmd.argument()), icp);
268                                 return new InsetBibtex(buf, icp);
269                         }
270                         
271                         case CITE_CODE: {
272                                 InsetCommandParams icp(code);
273                                 InsetCommand::string2params(to_utf8(cmd.argument()), icp);
274                                 return new InsetCitation(buf, icp);
275                         }
276                         
277                         case ERT_CODE: {
278                                 return new InsetERT(buf,
279                                         InsetERT::string2params(to_utf8(cmd.argument())));
280                         }
281                         
282                         case EXTERNAL_CODE: {
283                                 InsetExternalParams iep;
284                                 InsetExternal::string2params(to_utf8(cmd.argument()), *buf, iep);
285                                 auto_ptr<InsetExternal> inset(new InsetExternal(buf));
286                                 inset->setBuffer(*buf);
287                                 inset->setParams(iep);
288                                 return inset.release();
289                         }
290                         
291                         case GRAPHICS_CODE: {
292                                 InsetGraphicsParams igp;
293                                 InsetGraphics::string2params(to_utf8(cmd.argument()), *buf, igp);
294                                 auto_ptr<InsetGraphics> inset(new InsetGraphics(buf));
295                                 inset->setParams(igp);
296                                 return inset.release();
297                         }
298                         
299                         case HYPERLINK_CODE: {
300                                 InsetCommandParams icp(code);
301                                 InsetCommand::string2params(to_utf8(cmd.argument()), icp);
302                                 return new InsetHyperlink(buf, icp);
303                         }
304                         
305                         case INCLUDE_CODE: {
306                                 InsetCommandParams icp(code);
307                                 InsetCommand::string2params(to_utf8(cmd.argument()), icp);
308                                 return new InsetInclude(buf, icp);
309                         }
310                         
311                         case INDEX_CODE: {
312                                 docstring arg = cmd.argument();
313                                 return new InsetIndex(buf, InsetIndexParams(arg));
314                         }
315                         
316                         case INDEX_PRINT_CODE:  {
317                                 InsetCommandParams icp(code);
318                                 InsetCommand::string2params(to_utf8(cmd.argument()), icp);
319                                 return new InsetPrintIndex(buf, icp);
320                         }
321                         
322                         case LABEL_CODE: {
323                                 InsetCommandParams icp(code);
324                                 InsetCommand::string2params(to_utf8(cmd.argument()), icp);
325                                 return new InsetLabel(buf, icp);
326                         }
327                         
328                         case LINE_CODE: {
329                                 InsetCommandParams icp(code);
330                                 InsetCommand::string2params(to_utf8(cmd.argument()), icp);
331                                 return new InsetLine(buf, icp);
332                         }
333                                 
334                         case LISTINGS_CODE: {
335                                 InsetListingsParams par;
336                                 InsetListings::string2params(to_utf8(cmd.argument()), par);
337                                 return new InsetListings(buf, par);
338                         }
339                         
340                         case NOMENCL_CODE: {
341                                 InsetCommandParams icp(code);
342                                 InsetCommand::string2params(to_utf8(cmd.argument()), icp);
343                                 return new InsetNomencl(buf, icp);
344                         }
345                         
346                         case REF_CODE: {
347                                 InsetCommandParams icp(code);
348                                 InsetCommand::string2params(to_utf8(cmd.argument()), icp);
349                                 return new InsetRef(buf, icp);
350                         }
351
352                         case SCRIPT_CODE: {
353                                 InsetScriptParams isp;
354                                 InsetScript::string2params(to_utf8(cmd.argument()), isp);
355                                 return new InsetScript(buf, isp);
356                         }
357
358                         case SPACE_CODE: {
359                                 InsetSpaceParams isp;
360                                 InsetSpace::string2params(to_utf8(cmd.argument()), isp);
361                                 return new InsetSpace(isp);
362                         }
363                         
364                         case TOC_CODE: {
365                                 InsetCommandParams icp(code);
366                                 InsetCommand::string2params(to_utf8(cmd.argument()), icp);
367                                 return new InsetTOC(buf, icp);
368                         }
369                         
370                         case VSPACE_CODE: {
371                                 VSpace vspace;
372                                 InsetVSpace::string2params(to_utf8(cmd.argument()), vspace);
373                                 return new InsetVSpace(vspace);
374                         }
375
376                         case PREVIEW_CODE:
377                                 return new InsetPreview(buf);
378                         
379                         default:
380                                 lyxerr << "Inset '" << name << "' not permitted with LFUN_INSET_INSERT."
381                                                 << endl;
382                                 return 0;
383                         
384                         }
385                 } //end LFUN_INSET_INSERT
386
387                 case LFUN_SPACE_INSERT: {
388                         string const name = cmd.getArg(0);
389                         string const len = cmd.getArg(1);
390                         if (name.empty()) {
391                                 lyxerr << "LyX function 'space-insert' needs an argument." << endl;
392                                 break;
393                         }
394                         InsetSpaceParams isp;
395                         // The tests for isp.math might be disabled after a file format change
396                         if (name == "normal")
397                                 isp.kind = InsetSpaceParams::NORMAL;
398                         else if (name == "protected")
399                                 isp.kind = InsetSpaceParams::PROTECTED;
400                         else if (name == "visible")
401                                 isp.kind = InsetSpaceParams::VISIBLE;
402                         else if (name == "thin")
403                                 isp.kind = InsetSpaceParams::THIN;
404                         else if (isp.math && name == "med")
405                                 isp.kind = InsetSpaceParams::MEDIUM;
406                         else if (isp.math && name == "thick")
407                                 isp.kind = InsetSpaceParams::THICK;
408                         else if (name == "quad")
409                                 isp.kind = InsetSpaceParams::QUAD;
410                         else if (name == "qquad")
411                                 isp.kind = InsetSpaceParams::QQUAD;
412                         else if (name == "enspace")
413                                 isp.kind = InsetSpaceParams::ENSPACE;
414                         else if (name == "enskip")
415                                 isp.kind = InsetSpaceParams::ENSKIP;
416                         else if (name == "negthinspace")
417                                 isp.kind = InsetSpaceParams::NEGTHIN;
418                         else if (name == "negmedspace")
419                                 isp.kind = InsetSpaceParams::NEGMEDIUM;
420                         else if (name == "negthickspace")
421                                 isp.kind = InsetSpaceParams::NEGTHICK;
422                         else if (name == "hfill")
423                                 isp.kind = InsetSpaceParams::HFILL;
424                         else if (name == "hfill*")
425                                 isp.kind = InsetSpaceParams::HFILL_PROTECTED;
426                         else if (name == "dotfill")
427                                 isp.kind = InsetSpaceParams::DOTFILL;
428                         else if (name == "hrulefill")
429                                 isp.kind = InsetSpaceParams::HRULEFILL;
430                         else if (name == "hspace") {
431                                 if (len.empty() || !isValidGlueLength(len)) {
432                                         lyxerr << "LyX function 'space-insert hspace' "
433                                                << "needs a valid length argument." << endl;
434                                         break;
435                                 }
436                                 isp.kind = InsetSpaceParams::CUSTOM;
437                                 isp.length = GlueLength(len);
438                         }
439                         else if (name == "hspace*") {
440                                 if (len.empty() || !isValidGlueLength(len)) {
441                                         lyxerr << "LyX function 'space-insert hspace*' "
442                                                << "needs a valid length argument." << endl;
443                                         break;
444                                 }
445                                 isp.kind = InsetSpaceParams::CUSTOM_PROTECTED;
446                                 isp.length = GlueLength(len);
447                         }
448                         else {
449                                 lyxerr << "Wrong argument for LyX function 'space-insert'." << endl;
450                                 break;
451                         }
452                         return new InsetSpace(isp);
453                 }
454                 break;
455
456                 default:
457                         break;
458                 }
459
460         } catch (ExceptionMessage const & message) {
461                 if (message.type_ == ErrorException) {
462                         // This should never happen!
463                         Alert::error(message.title_, message.details_);
464                         lyx_exit(1);
465                 } else if (message.type_ == WarningException) {
466                         Alert::warning(message.title_, message.details_);
467                         return 0;
468                 }
469         }
470
471         return 0;
472 }
473
474
475 Inset * createInset(Buffer * buf, FuncRequest const & cmd)
476 {
477         Inset * inset = createInsetHelper(buf, cmd);
478         if (inset)
479                 inset->setBuffer(*buf);
480         return inset;
481 }
482
483
484 Inset * readInset(Lexer & lex, Buffer * buf)
485 {
486         // consistency check
487         if (lex.getString() != "\\begin_inset")
488                 LYXERR0("Buffer::readInset: Consistency check failed.");
489
490         auto_ptr<Inset> inset;
491
492         string tmptok;
493         lex >> tmptok;
494
495         // test the different insets
496         
497         // FIXME It would be better if we did not have this branch and could
498         // just do one massive switch for all insets. But at present, it's
499         // easier to do it this way, and we can't do the massive switch until
500         // the conversion mentioned below.  Note that if we do want to do a
501         // single switch, we need to remove this "CommandInset" line---or
502         // replace it with a single "InsetType" line that would be used in all
503         // insets.
504         if (tmptok == "CommandInset") {
505                 lex.next();
506                 string const insetType = lex.getString();
507                 lex.pushToken(insetType);
508                 
509                 InsetCode const code = insetCode(insetType);
510                 
511                 //FIXME If we do the one massive switch, we cannot do this here, since
512                 //we do not know in advance that we're dealing with a command inset.
513                 //Worst case, we could put it in each case below. Better, we could
514                 //pass the lexer to the constructor and let the params be built there.
515                 InsetCommandParams inscmd(code);
516                 inscmd.read(lex);
517
518                 switch (code) {
519                         case BIBITEM_CODE:
520                                 inset.reset(new InsetBibitem(buf, inscmd));
521                                 break;
522                         case BIBTEX_CODE:
523                                 inset.reset(new InsetBibtex(buf, inscmd));
524                                 break;
525                         case CITE_CODE: 
526                                 inset.reset(new InsetCitation(buf, inscmd));
527                                 break;
528                         case HYPERLINK_CODE:
529                                 inset.reset(new InsetHyperlink(buf, inscmd));
530                                 break;
531                         case INCLUDE_CODE:
532                                 inset.reset(new InsetInclude(buf, inscmd));
533                                 break;
534                         case INDEX_PRINT_CODE:
535                                 inset.reset(new InsetPrintIndex(buf, inscmd));
536                                 break;
537                         case LABEL_CODE:
538                                 inset.reset(new InsetLabel(buf, inscmd));
539                                 break;
540                         case LINE_CODE:
541                                 inset.reset(new InsetLine(buf, inscmd));
542                                 break;
543                         case NOMENCL_CODE:
544                                 inset.reset(new InsetNomencl(buf, inscmd));
545                                 break;
546                         case NOMENCL_PRINT_CODE:
547                                 inset.reset(new InsetPrintNomencl(buf, inscmd));
548                                 break;
549                         case REF_CODE:
550                                 if (inscmd["name"].empty() && inscmd["reference"].empty())
551                                         return 0;
552                                 inset.reset(new InsetRef(buf, inscmd));
553                                 break;
554                         case TOC_CODE:
555                                 inset.reset(new InsetTOC(buf, inscmd));
556                                 break;
557                         case NO_CODE:
558                         default:
559                                 lyxerr << "unknown CommandInset '" << insetType
560                                                         << "'" << endl;
561                                 while (lex.isOK() && lex.getString() != "\\end_inset")
562                                         lex.next();
563                                 return 0;
564                 }
565                 inset->setBuffer(*buf);
566         } else { 
567                 // FIXME This branch should be made to use inset codes as the preceding 
568                 // branch does. Unfortunately, that will take some doing. It requires
569                 // converting the representation of the insets in LyX files so that they
570                 // use the inset names listed in Inset.cpp. Then, as above, the inset names
571                 // can be translated to inset codes using insetCode(). And the insets'
572                 // write() routines should use insetName() rather than hardcoding it.
573                 if (tmptok == "Quotes") {
574                         inset.reset(new InsetQuotes(buf));
575                 } else if (tmptok == "External") {
576                         inset.reset(new InsetExternal(buf));
577                 } else if (tmptok == "FormulaMacro") {
578                         inset.reset(new MathMacroTemplate(buf));
579                 } else if (tmptok == "Formula") {
580                         inset.reset(new InsetMathHull(buf));
581                 } else if (tmptok == "Graphics") {
582                         inset.reset(new InsetGraphics(buf));
583                 } else if (tmptok == "Note") {
584                         inset.reset(new InsetNote(buf, tmptok));
585                 } else if (tmptok == "Box") {
586                         inset.reset(new InsetBox(buf, tmptok));
587                 } else if (tmptok == "Flex") {
588                         lex.eatLine();
589                         string s = lex.getString();
590                         inset.reset(new InsetFlex(buf, s));
591                 } else if (tmptok == "Branch") {
592                         inset.reset(new InsetBranch(buf, InsetBranchParams()));
593                 } else if (tmptok == "Phantom") {
594                         inset.reset(new InsetPhantom(buf, tmptok));
595                 } else if (tmptok == "ERT") {
596                         inset.reset(new InsetERT(buf));
597                 } else if (tmptok == "listings") {
598                         inset.reset(new InsetListings(buf));
599                 } else if (tmptok == "script") {
600                         inset.reset(new InsetScript(buf));
601                 } else if (tmptok == "space") {
602                         inset.reset(new InsetSpace);
603                 } else if (tmptok == "Tabular") {
604                         inset.reset(new InsetTabular(buf));
605                 } else if (tmptok == "Text") {
606                         inset.reset(new InsetText(buf));
607                 } else if (tmptok == "VSpace") {
608                         inset.reset(new InsetVSpace);
609                 } else if (tmptok == "Foot") {
610                         inset.reset(new InsetFoot(buf));
611                 } else if (tmptok == "Marginal") {
612                         inset.reset(new InsetMarginal(buf));
613                 } else if (tmptok == "Newpage") {
614                         inset.reset(new InsetNewpage);
615                 } else if (tmptok == "Newline") {
616                         inset.reset(new InsetNewline);
617                 } else if (tmptok == "Argument") {
618                         inset.reset(new InsetArgument(buf));
619                 } else if (tmptok == "Float") {
620                         inset.reset(new InsetFloat(buf, string()));
621                 } else if (tmptok == "Wrap") {
622                         lex.next();
623                         string tmptok = lex.getString();
624                         inset.reset(new InsetWrap(buf, tmptok));
625                 } else if (tmptok == "Caption") {
626                         inset.reset(new InsetCaption(buf));
627                 } else if (tmptok == "Index") {
628                         inset.reset(new InsetIndex(buf, InsetIndexParams()));
629                 } else if (tmptok == "FloatList") {
630                         inset.reset(new InsetFloatList(buf));
631                 } else if (tmptok == "Info") {
632                         inset.reset(new InsetInfo(buf));
633                 } else if (tmptok == "IPA") {
634                         inset.reset(new InsetIPA(buf));
635                 } else if (tmptok == "IPADeco") {
636                         inset.reset(new InsetIPADeco(buf, tmptok));
637                 } else if (tmptok == "Preview") {
638                         inset.reset(new InsetPreview(buf));
639                 } else {
640                         lyxerr << "unknown Inset type '" << tmptok
641                                << "'" << endl;
642                         while (lex.isOK() && lex.getString() != "\\end_inset")
643                                 lex.next();
644                         return 0;
645                 }
646
647                 // Set the buffer reference for proper parsing of some insets
648                 // (InsetCollapsable for example)
649                 inset->setBuffer(*buf);
650                 inset->read(lex);
651                 // Set again the buffer for insets that are created inside this inset
652                 // (InsetMathHull for example).
653                 inset->setBuffer(*buf);
654         }
655         return inset.release();
656 }
657
658
659 } // namespace lyx