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