]> git.lyx.org Git - lyx.git/blob - src/insets/InsetLayout.cpp
64f361dbdd14afdbd452f16b9b6d51223942c40c
[lyx.git] / src / insets / InsetLayout.cpp
1 // -*- C++ -*-
2 /**
3  * \file InsetLayout.cpp
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Martin Vermeer
8  * \author Richard Heck
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #include <config.h>
14
15 #include "InsetLayout.h"
16
17 #include "ColorSet.h"
18 #include "Lexer.h"
19 #include "TextClass.h"
20
21 #include "support/debug.h"
22 #include "support/lstrings.h"
23 #include "support/textutils.h"
24
25 #include <vector>
26
27 using std::string;
28 using std::set;
29 using std::vector;
30
31 using namespace lyx::support;
32
33 namespace lyx {
34
35 InsetLayout::InsetDecoration translateDecoration(std::string const & str)
36 {
37         if (compare_ascii_no_case(str, "classic") == 0)
38                 return InsetLayout::CLASSIC;
39         if (compare_ascii_no_case(str, "minimalistic") == 0)
40                 return InsetLayout::MINIMALISTIC;
41         if (compare_ascii_no_case(str, "conglomerate") == 0)
42                 return InsetLayout::CONGLOMERATE;
43         return InsetLayout::DEFAULT;
44 }
45
46 namespace {
47
48 InsetLayout::InsetLaTeXType translateLaTeXType(std::string const & str)
49 {
50         if (compare_ascii_no_case(str, "command") == 0)
51                 return InsetLayout::COMMAND;
52         if (compare_ascii_no_case(str, "environment") == 0)
53                 return InsetLayout::ENVIRONMENT;
54         if (compare_ascii_no_case(str, "none") == 0)
55                 return InsetLayout::NOLATEXTYPE;
56         return InsetLayout::ILT_ERROR;
57 }
58
59 } // namespace
60
61
62 bool InsetLayout::read(Lexer & lex, TextClass const & tclass,
63         bool validating)
64 {
65         enum {
66                 IL_ADDTOTOC,
67                 IL_ARGUMENT,
68                 IL_BABELPREAMBLE,
69                 IL_BGCOLOR,
70                 IL_CONTENTASLABEL,
71                 IL_COPYSTYLE,
72                 IL_COUNTER,
73                 IL_CUSTOMPARS,
74                 IL_DECORATION,
75                 IL_DISPLAY,
76                 IL_EDITEXTERNAL,
77                 IL_FIXEDWIDTH_PREAMBLE_ENCODING,
78                 IL_FONT,
79                 IL_FORCE_LOCAL_FONT_SWITCH,
80                 IL_FORCELTR,
81                 IL_FORCEOWNLINES,
82                 IL_FORCEPLAIN,
83                 IL_FREESPACING,
84                 IL_HTMLTAG,
85                 IL_HTMLATTR,
86                 IL_HTMLFORCECSS,
87                 IL_HTMLINNERTAG,
88                 IL_HTMLINNERATTR,
89                 IL_HTMLISBLOCK,
90                 IL_HTMLLABEL,
91                 IL_HTMLSTYLE,
92                 IL_HTMLPREAMBLE,
93                 IL_DOCBOOKTAG,
94                 IL_DOCBOOKTAGTYPE,
95                 IL_DOCBOOKATTR,
96                 IL_DOCBOOKSECTION,
97                 IL_DOCBOOKWRAPPERTAG,
98                 IL_DOCBOOKWRAPPERTAGTYPE,
99                 IL_DOCBOOKWRAPPERATTR,
100                 IL_INTOC,
101                 IL_ISTOCCAPTION,
102                 IL_LABELFONT,
103                 IL_LABELSTRING,
104                 IL_LANGPREAMBLE,
105                 IL_LATEXNAME,
106                 IL_LATEXPARAM,
107                 IL_LATEXTYPE,
108                 IL_LEFTDELIM,
109                 IL_LYXTYPE,
110                 IL_OBSOLETEDBY,
111                 IL_KEEPEMPTY,
112                 IL_MENUSTRING,
113                 IL_MULTIPAR,
114                 IL_NEEDCPROTECT,
115                 IL_NEEDMBOXPROTECT,
116                 IL_NEEDPROTECT,
117                 IL_NEWLINE_CMD,
118                 IL_PASSTHRU,
119                 IL_PASSTHRU_CHARS,
120                 IL_PARBREAKIGNORED,
121                 IL_PARBREAKISNEWLINE,
122                 IL_PREAMBLE,
123                 IL_REQUIRES,
124                 IL_RIGHTDELIM,
125                 IL_REFPREFIX,
126                 IL_RESETARGS,
127                 IL_RESETSFONT,
128                 IL_SPELLCHECK,
129                 IL_END
130         };
131
132
133         LexerKeyword elementTags[] = {
134                 { "addtotoc", IL_ADDTOTOC },
135                 { "argument", IL_ARGUMENT },
136                 { "babelpreamble", IL_BABELPREAMBLE },
137                 { "bgcolor", IL_BGCOLOR },
138                 { "contentaslabel", IL_CONTENTASLABEL },
139                 { "copystyle", IL_COPYSTYLE },
140                 { "counter", IL_COUNTER},
141                 { "custompars", IL_CUSTOMPARS },
142                 { "decoration", IL_DECORATION },
143                 { "display", IL_DISPLAY },
144                 { "docbookattr", IL_DOCBOOKATTR },
145                 { "docbooksection", IL_DOCBOOKSECTION },
146                 { "docbooktag", IL_DOCBOOKTAG },
147                 { "docbooktagtype", IL_DOCBOOKTAGTYPE },
148                 { "docbookwrapperattr", IL_DOCBOOKWRAPPERATTR },
149                 { "docbookwrappertag", IL_DOCBOOKWRAPPERTAG },
150                 { "docbookwrappertagtype", IL_DOCBOOKWRAPPERTAGTYPE },
151                 { "editexternal", IL_EDITEXTERNAL },
152                 { "end", IL_END },
153                 { "fixedwidthpreambleencoding", IL_FIXEDWIDTH_PREAMBLE_ENCODING },
154                 { "font", IL_FONT },
155                 { "forcelocalfontswitch", IL_FORCE_LOCAL_FONT_SWITCH },
156                 { "forceltr", IL_FORCELTR },
157                 { "forceownlines", IL_FORCEOWNLINES },
158                 { "forceplain", IL_FORCEPLAIN },
159                 { "freespacing", IL_FREESPACING },
160                 { "htmlattr", IL_HTMLATTR },
161                 { "htmlforcecss", IL_HTMLFORCECSS },
162                 { "htmlinnerattr", IL_HTMLINNERATTR},
163                 { "htmlinnertag", IL_HTMLINNERTAG},
164                 { "htmlisblock", IL_HTMLISBLOCK},
165                 { "htmllabel", IL_HTMLLABEL },
166                 { "htmlpreamble", IL_HTMLPREAMBLE },
167                 { "htmlstyle", IL_HTMLSTYLE },
168                 { "htmltag", IL_HTMLTAG },
169                 { "intoc", IL_INTOC },
170                 { "istoccaption", IL_ISTOCCAPTION },
171                 { "keepempty", IL_KEEPEMPTY },
172                 { "labelfont", IL_LABELFONT },
173                 { "labelstring", IL_LABELSTRING },
174                 { "langpreamble", IL_LANGPREAMBLE },
175                 { "latexname", IL_LATEXNAME },
176                 { "latexparam", IL_LATEXPARAM },
177                 { "latextype", IL_LATEXTYPE },
178                 { "leftdelim", IL_LEFTDELIM },
179                 { "lyxtype", IL_LYXTYPE },
180                 { "menustring", IL_MENUSTRING },
181                 { "multipar", IL_MULTIPAR },
182                 { "needcprotect", IL_NEEDCPROTECT },
183                 { "needmboxprotect", IL_NEEDMBOXPROTECT },
184                 { "needprotect", IL_NEEDPROTECT },
185                 { "newlinecmd", IL_NEWLINE_CMD },
186                 { "obsoletedby", IL_OBSOLETEDBY },
187                 { "parbreakignored", IL_PARBREAKIGNORED },
188                 { "parbreakisnewline", IL_PARBREAKISNEWLINE },
189                 { "passthru", IL_PASSTHRU },
190                 { "passthruchars", IL_PASSTHRU_CHARS },
191                 { "preamble", IL_PREAMBLE },
192                 { "refprefix", IL_REFPREFIX },
193                 { "requires", IL_REQUIRES },
194                 { "resetargs", IL_RESETARGS },
195                 { "resetsfont", IL_RESETSFONT },
196                 { "rightdelim", IL_RIGHTDELIM },
197                 { "spellcheck", IL_SPELLCHECK }
198         };
199
200         lex.pushTable(elementTags);
201
202         labelfont_ = inherit_font;
203         bgcolor_ = Color_none;
204         bool getout = false;
205         // whether we've read the CustomPars or ForcePlain tag
206         // for issuing a warning in case MultiPars comes later
207         bool readCustomOrPlain = false;
208
209         string tmp;
210         while (!getout && lex.isOK()) {
211                 int le = lex.lex();
212                 switch (le) {
213                 case Lexer::LEX_UNDEF:
214                         lex.printError("Unknown InsetLayout tag");
215                         if (validating)
216                                 return false;
217                         continue;
218                 default:
219                         break;
220                 }
221                 switch (le) {
222                 // FIXME
223                 // Perhaps a more elegant way to deal with the next two would be the
224                 // way this sort of thing is handled in Layout::read(), namely, by
225                 // using the Lexer.
226                 case IL_LYXTYPE: {
227                         // make sure that we have the right sort of name.
228                         if (name_ != from_ascii("undefined")
229                             && name_.substr(0,5) != from_ascii("Flex:")) {
230                                 LYXERR0("Flex insets must have names of the form `Flex:<name>'.\n"
231                                         "This one has the name `" << to_utf8(name_) << "'\n"
232                                         "Ignoring LyXType declaration.");
233                                 // this is not really a reason to abort
234                                 if (validating)
235                                         return false;
236                                 break;
237                         }
238                         string lt;
239                         lex >> lt;
240                         lyxtype_ = translateLyXType(lt);
241                         if (lyxtype_  == NOLYXTYPE) {
242                                 LYXERR0("Unknown LyXType `" << lt << "'.");
243                                 // this is not really a reason to abort
244                                 if (validating)
245                                         return false;
246                         }
247                         if (lyxtype_ == CHARSTYLE) {
248                                 // by default, charstyles force the plain layout
249                                 multipar_ = false;
250                                 forceplain_ = true;
251                         }
252                         break;
253                 }
254                 case IL_LATEXTYPE:  {
255                         string lt;
256                         lex >> lt;
257                         latextype_ = translateLaTeXType(lt);
258                         if (latextype_  == ILT_ERROR) {
259                                 LYXERR0("Unknown LaTeXType `" << lt << "'.");
260                                 // this is not really a reason to abort
261                                 if (validating)
262                                         return false;
263                         }
264                         break;
265                 }
266                 case IL_LABELSTRING:
267                         lex >> labelstring_;
268                         break;
269                 case IL_MENUSTRING:
270                         lex >> menustring_;
271                         break;
272                 case IL_DECORATION:
273                         lex >> tmp;
274                         decoration_ = translateDecoration(tmp);
275                         break;
276                 case IL_LATEXNAME:
277                         lex >> latexname_;
278                         break;
279                 case IL_LATEXPARAM:
280                         lex >> tmp;
281                         latexparam_ = subst(tmp, "&quot;", "\"");
282                         break;
283                 case IL_LEFTDELIM:
284                         lex >> leftdelim_;
285                         leftdelim_ = subst(leftdelim_, from_ascii("<br/>"),
286                                                     from_ascii("\n"));
287                         break;
288                 case IL_FIXEDWIDTH_PREAMBLE_ENCODING:
289                         lex >> fixedwidthpreambleencoding_;
290                         break;
291                 case IL_FORCE_LOCAL_FONT_SWITCH:
292                         lex >> forcelocalfontswitch_;
293                         break;
294                 case IL_RIGHTDELIM:
295                         lex >> rightdelim_;
296                         rightdelim_ = subst(rightdelim_, from_ascii("<br/>"),
297                                                      from_ascii("\n"));
298                         break;
299                 case IL_LABELFONT:
300                         labelfont_ = lyxRead(lex, inherit_font);
301                         break;
302                 case IL_FORCELTR:
303                         lex >> forceltr_;
304                         break;
305                 case IL_FORCEOWNLINES:
306                         lex >> forceownlines_;
307                         break;
308                 case IL_INTOC:
309                         lex >> intoc_;
310                         break;
311                 case IL_MULTIPAR:
312                         lex >> multipar_;
313                         // the defaults for these depend upon multipar_
314                         if (readCustomOrPlain)
315                                 LYXERR0("Warning: Read MultiPar after CustomPars or ForcePlain. "
316                                         "Previous value may be overwritten!");
317                         readCustomOrPlain = false;
318                         custompars_ = multipar_;
319                         forceplain_ = !multipar_;
320                         break;
321                 case IL_COUNTER:
322                         lex >> counter_;
323                         break;
324                 case IL_CUSTOMPARS:
325                         lex >> custompars_;
326                         readCustomOrPlain = true;
327                         break;
328                 case IL_FORCEPLAIN:
329                         lex >> forceplain_;
330                         readCustomOrPlain = true;
331                         break;
332                 case IL_PASSTHRU:
333                         lex >> passthru_;
334                         break;
335                 case IL_PASSTHRU_CHARS:
336                         lex >> passthru_chars_;
337                         break;
338                 case IL_NEWLINE_CMD:
339                         lex >> newline_cmd_;
340                         break;
341                 case IL_PARBREAKIGNORED:
342                         lex >> parbreakignored_;
343                         break;
344                 case IL_PARBREAKISNEWLINE:
345                         lex >> parbreakisnewline_;
346                         break;
347                 case IL_KEEPEMPTY:
348                         lex >> keepempty_;
349                         break;
350                 case IL_FREESPACING:
351                         lex >> freespacing_;
352                         break;
353                 case IL_NEEDPROTECT:
354                         lex >> needprotect_;
355                         break;
356                 case IL_NEEDCPROTECT:
357                         lex >> needcprotect_;
358                         break;
359                 case IL_NEEDMBOXPROTECT:
360                         lex >> needmboxprotect_;
361                         break;
362                 case IL_CONTENTASLABEL:
363                         lex >> contentaslabel_;
364                         break;
365                 case IL_COPYSTYLE: {
366                         // initialize with a known style
367                         docstring style;
368                         lex >> style;
369                         style = subst(style, '_', ' ');
370
371                         // We don't want to apply the algorithm in DocumentClass::insetLayout()
372                         // here. So we do it the long way.
373                         TextClass::InsetLayouts::const_iterator it =
374                                         tclass.insetLayouts().find(style);
375                         if (it != tclass.insetLayouts().end()) {
376                                 docstring const tmpname = name_;
377                                 this->operator=(it->second);
378                                 name_ = tmpname;
379                         } else {
380                                 LYXERR0("Cannot copy unknown InsetLayout `"
381                                         << style << "' to InsetLayout `"
382                                         << name() << "'\n"
383                                         << "All InsetLayouts so far:");
384                                 TextClass::InsetLayouts::const_iterator lit =
385                                                 tclass.insetLayouts().begin();
386                                 TextClass::InsetLayouts::const_iterator len =
387                                                 tclass.insetLayouts().end();
388                                 for (; lit != len; ++lit)
389                                         lyxerr << lit->second.name() << "\n";
390                                 // this is not really a reason to abort
391                                 if (validating)
392                                         return false;
393                         }
394                         break;
395                 }
396                 case IL_OBSOLETEDBY: {
397                         docstring style;
398                         lex >> style;
399                         style = subst(style, '_', ' ');
400
401                         // We don't want to apply the algorithm in DocumentClass::insetLayout()
402                         // here. So we do it the long way.
403                         TextClass::InsetLayouts::const_iterator it =
404                                         tclass.insetLayouts().find(style);
405                         if (it != tclass.insetLayouts().end()) {
406                                 docstring const tmpname = name_;
407                                 this->operator=(it->second);
408                                 name_ = tmpname;
409                                 if (obsoleted_by().empty())
410                                         obsoleted_by_ = style;
411                         } else {
412                                 LYXERR0("Cannot replace InsetLayout `"
413                                         << name()
414                                         << "' with unknown InsetLayout `"
415                                         << style << "'\n"
416                                         << "All InsetLayouts so far:");
417                                 TextClass::InsetLayouts::const_iterator lit =
418                                                 tclass.insetLayouts().begin();
419                                 TextClass::InsetLayouts::const_iterator len =
420                                                 tclass.insetLayouts().end();
421                                 for (; lit != len; ++lit)
422                                         lyxerr << lit->second.name() << "\n";
423                                 // this is not really a reason to abort
424                                 if (validating)
425                                         return false;
426                         }
427                         break;
428                 }
429
430                 case IL_FONT: {
431                         font_ = lyxRead(lex, inherit_font);
432                         // If you want to define labelfont, you need to do so after
433                         // font is defined.
434                         labelfont_ = font_;
435                         break;
436                 }
437                 case IL_RESETARGS:
438                         bool reset;
439                         lex >> reset;
440                         if (reset) {
441                                 latexargs_.clear();
442                                 postcommandargs_.clear();
443                         }
444                         break;
445                 case IL_ARGUMENT:
446                         readArgument(lex);
447                         break;
448                 case IL_BGCOLOR:
449                         lex >> tmp;
450                         bgcolor_ = lcolor.getFromLyXName(tmp);
451                         break;
452                 case IL_PREAMBLE:
453                         preamble_ = lex.getLongString(from_ascii("EndPreamble"));
454                         break;
455                 case IL_BABELPREAMBLE:
456                         babelpreamble_ = lex.getLongString(from_ascii("EndBabelPreamble"));
457                         break;
458                 case IL_LANGPREAMBLE:
459                         langpreamble_ = lex.getLongString(from_ascii("EndLangPreamble"));
460                         break;
461                 case IL_REFPREFIX:
462                         lex >> refprefix_;
463                         break;
464                 case IL_HTMLTAG:
465                         lex >> htmltag_;
466                         break;
467                 case IL_HTMLATTR:
468                         lex >> htmlattr_;
469                         break;
470                 case IL_HTMLFORCECSS:
471                         lex >> htmlforcecss_;
472                         break;
473                 case IL_HTMLINNERTAG:
474                         lex >> htmlinnertag_;
475                         break;
476                 case IL_HTMLINNERATTR:
477                         lex >> htmlinnerattr_;
478                         break;
479                 case IL_HTMLLABEL:
480                         lex >> htmllabel_;
481                         break;
482                 case IL_HTMLISBLOCK:
483                         lex >> htmlisblock_;
484                         break;
485                 case IL_HTMLSTYLE:
486                         htmlstyle_ = lex.getLongString(from_ascii("EndHTMLStyle"));
487                         break;
488                 case IL_HTMLPREAMBLE:
489                         htmlpreamble_ = lex.getLongString(from_ascii("EndPreamble"));
490                         break;
491                 case IL_DOCBOOKTAG:
492                         lex >> docbooktag_;
493                         break;
494                 case IL_DOCBOOKTAGTYPE:
495                         lex >> docbooktagtype_;
496                         break;
497                 case IL_DOCBOOKATTR:
498                         lex >> docbookattr_;
499                         break;
500                 case IL_DOCBOOKSECTION:
501                         lex >> docbooksection_;
502                         break;
503                 case IL_DOCBOOKWRAPPERTAG:
504                         lex >> docbookwrappertag_;
505                         break;
506                 case IL_DOCBOOKWRAPPERTAGTYPE:
507                         lex >> docbookwrappertagtype_;
508                         break;
509                 case IL_DOCBOOKWRAPPERATTR:
510                         lex >> docbookwrapperattr_;
511                         break;
512                 case IL_REQUIRES: {
513                         lex.eatLine();
514                         vector<string> const req
515                                 = getVectorFromString(lex.getString(true));
516                         required_.insert(req.begin(), req.end());
517                         break;
518                 }
519                 case IL_SPELLCHECK:
520                         lex >> spellcheck_;
521                         break;
522                 case IL_RESETSFONT:
523                         lex >> resetsfont_;
524                         break;
525                 case IL_DISPLAY:
526                         lex >> display_;
527                         break;
528                 case IL_ADDTOTOC:
529                         lex >> toc_type_;
530                         add_to_toc_ = !toc_type_.empty();
531                         break;
532                 case IL_ISTOCCAPTION:
533                         lex >> is_toc_caption_;
534                         break;
535                 case IL_EDITEXTERNAL:
536                         lex >> edit_external_;
537                         break;
538                 case IL_END:
539                         getout = true;
540                         break;
541                 }
542         }
543
544         // Here add element to list if getout == true
545         if (!getout)
546                 return false;
547
548         // The label font is generally used as-is without
549         // any realization against a given context.
550         labelfont_.realize(sane_font);
551
552         lex.popTable();
553         return true;
554 }
555
556
557 InsetLayout::InsetLyXType translateLyXType(std::string const & str)
558 {
559         if (compare_ascii_no_case(str, "charstyle") == 0)
560                 return InsetLayout::CHARSTYLE;
561         if (compare_ascii_no_case(str, "custom") == 0)
562                 return InsetLayout::CUSTOM;
563         if (compare_ascii_no_case(str, "end") == 0)
564                 return InsetLayout::END;
565         if (compare_ascii_no_case(str, "standard") == 0)
566                 return InsetLayout::STANDARD;
567         return InsetLayout::NOLYXTYPE;
568 }
569
570
571 string const & InsetLayout::htmltag() const
572 {
573         if (htmltag_.empty())
574                 htmltag_ = multipar_ ? "div" : "span";
575         return htmltag_;
576 }
577
578
579 string const & InsetLayout::htmlattr() const
580 {
581         if (htmlattr_.empty())
582                 htmlattr_ = "class=\"" + defaultCSSClass() + "\"";
583         return htmlattr_;
584 }
585
586
587 string const & InsetLayout::htmlinnerattr() const
588 {
589         if (htmlinnerattr_.empty())
590                 htmlinnerattr_ = "class=\"" + defaultCSSClass() + "_inner\"";
591         return htmlinnerattr_;
592 }
593
594
595 string InsetLayout::defaultCSSClass() const
596 {
597         if (!defaultcssclass_.empty())
598                 return defaultcssclass_;
599         string d;
600         string n = to_utf8(name());
601         string::const_iterator it = n.begin();
602         string::const_iterator en = n.end();
603         for (; it != en; ++it) {
604                 if (!isAlphaASCII(*it))
605                         d += "_";
606                 else if (isLower(*it))
607                         d += *it;
608                 else
609                         d += lowercase(*it);
610         }
611         // are there other characters we need to remove?
612         defaultcssclass_ = d;
613         return defaultcssclass_;
614 }
615
616
617 void InsetLayout::makeDefaultCSS() const
618 {
619         if (!htmldefaultstyle_.empty())
620                 return;
621         docstring const mainfontCSS = font_.asCSS();
622         if (!mainfontCSS.empty())
623                 htmldefaultstyle_ =
624                                 from_ascii(htmltag() + "." + defaultCSSClass() + " {\n") +
625                                 mainfontCSS + from_ascii("\n}\n");
626 }
627
628
629 docstring InsetLayout::htmlstyle() const
630 {
631         if (!htmlstyle_.empty() && !htmlforcecss_)
632                 return htmlstyle_;
633         if (htmldefaultstyle_.empty())
634                 makeDefaultCSS();
635         docstring retval = htmldefaultstyle_;
636         if (!htmlstyle_.empty())
637                 retval += '\n' + htmlstyle_ + '\n';
638         return retval;
639 }
640
641 void InsetLayout::readArgument(Lexer & lex)
642 {
643         Layout::latexarg arg;
644         arg.mandatory = false;
645         arg.autoinsert = false;
646         arg.insertcotext = false;
647         arg.insertonnewline = false;
648         bool error = false;
649         bool finished = false;
650         arg.font = inherit_font;
651         arg.labelfont = inherit_font;
652         arg.is_toc_caption = false;
653         arg.free_spacing = false;
654         arg.passthru = PT_INHERITED;
655         arg.nodelims = false;
656         string nr;
657         lex >> nr;
658         bool const postcmd = prefixIs(nr, "post:");
659         while (!finished && lex.isOK() && !error) {
660                 lex.next();
661                 string const tok = ascii_lowercase(lex.getString());
662
663                 if (tok.empty()) {
664                         continue;
665                 } else if (tok == "endargument") {
666                         finished = true;
667                 } else if (tok == "labelstring") {
668                         lex.next();
669                         arg.labelstring = lex.getDocString();
670                 } else if (tok == "menustring") {
671                         lex.next();
672                         arg.menustring = lex.getDocString();
673                 } else if (tok == "mandatory") {
674                         lex.next();
675                         arg.mandatory = lex.getBool();
676                 } else if (tok == "autoinsert") {
677                         lex.next();
678                         arg.autoinsert = lex.getBool();
679                 } else if (tok == "insertcotext") {
680                         lex.next();
681                         arg.insertcotext = lex.getBool();
682                 } else if (tok == "insertonnewline") {
683                         lex.next();
684                         arg.insertonnewline = lex.getBool();
685                 } else if (tok == "leftdelim") {
686                         lex.next();
687                         arg.ldelim = lex.getDocString();
688                         arg.ldelim = subst(arg.ldelim,
689                                                     from_ascii("<br/>"), from_ascii("\n"));
690                 } else if (tok == "rightdelim") {
691                         lex.next();
692                         arg.rdelim = lex.getDocString();
693                         arg.rdelim = subst(arg.rdelim,
694                                                     from_ascii("<br/>"), from_ascii("\n"));
695                 } else if (tok == "defaultarg") {
696                         lex.next();
697                         arg.defaultarg = lex.getDocString();
698                 } else if (tok == "presetarg") {
699                         lex.next();
700                         arg.presetarg = lex.getDocString();
701                 } else if (tok == "tooltip") {
702                         lex.next();
703                         arg.tooltip = lex.getDocString();
704                 } else if (tok == "requires") {
705                         lex.next();
706                         arg.required = lex.getString();
707                 } else if (tok == "decoration") {
708                         lex.next();
709                         arg.decoration = lex.getString();
710                 } else if (tok == "newlinecmd") {
711                         lex.next();
712                         arg.newlinecmd = lex.getString();
713                 } else if (tok == "font") {
714                         arg.font = lyxRead(lex, arg.font);
715                 } else if (tok == "labelfont") {
716                         arg.labelfont = lyxRead(lex, arg.labelfont);
717                 } else if (tok == "passthruchars") {
718                         lex.next();
719                         arg.pass_thru_chars = lex.getDocString();
720                 } else if (tok == "passthru") {
721                         lex.next();
722                         docstring value = lex.getDocString();
723                         if (value == "true" || value == "1")
724                                 arg.passthru = PT_TRUE;
725                         else if (value == "false" || value == "0")
726                                 arg.passthru = PT_FALSE;
727                         else
728                                 arg.passthru = PT_INHERITED;
729                 } else if (tok == "istoccaption") {
730                         lex.next();
731                         arg.is_toc_caption = lex.getBool();
732                 } else if (tok == "freespacing") {
733                         lex.next();
734                         arg.free_spacing = lex.getBool();
735                 } else {
736                         lex.printError("Unknown tag");
737                         error = true;
738                 }
739         }
740         if (arg.labelstring.empty())
741                 LYXERR0("Incomplete Argument definition!");
742         else if (postcmd)
743                 postcommandargs_[nr] = arg;
744         else
745                 latexargs_[nr] = arg;
746 }
747
748
749 Layout::LaTeXArgMap InsetLayout::args() const
750 {
751         Layout::LaTeXArgMap args = latexargs_;
752         if (!postcommandargs_.empty())
753                 args.insert(postcommandargs_.begin(), postcommandargs_.end());
754         return args;
755 }
756
757
758 int InsetLayout::optArgs() const
759 {
760         int nr = 0;
761         Layout::LaTeXArgMap const args = InsetLayout::args();
762         Layout::LaTeXArgMap::const_iterator it = args.begin();
763         for (; it != args.end(); ++it) {
764                 if (!(*it).second.mandatory)
765                         ++nr;
766         }
767         return nr;
768 }
769
770
771 int InsetLayout::requiredArgs() const
772 {
773         int nr = 0;
774         Layout::LaTeXArgMap const args = InsetLayout::args();
775         Layout::LaTeXArgMap::const_iterator it = args.begin();
776         for (; it != args.end(); ++it) {
777                 if ((*it).second.mandatory)
778                         ++nr;
779         }
780         return nr;
781 }
782
783
784 } //namespace lyx