]> git.lyx.org Git - lyx.git/blob - src/insets/InsetLayout.cpp
Let tm be a reference here as elsewhere
[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 "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         intoc_(false), spellcheck_(true), resetsfont_(false), display_(true),
47         forcelocalfontswitch_(false), add_to_toc_(false), is_toc_caption_(false),
48         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_MULTIPAR,
124                 IL_NEEDCPROTECT,
125                 IL_NEEDPROTECT,
126                 IL_PASSTHRU,
127                 IL_PASSTHRU_CHARS,
128                 IL_PARBREAKISNEWLINE,
129                 IL_PREAMBLE,
130                 IL_REQUIRES,
131                 IL_RIGHTDELIM,
132                 IL_REFPREFIX,
133                 IL_RESETARGS,
134                 IL_RESETSFONT,
135                 IL_SPELLCHECK,
136                 IL_END
137         };
138
139
140         LexerKeyword elementTags[] = {
141                 { "addtotoc", IL_ADDTOTOC },
142                 { "argument", IL_ARGUMENT },
143                 { "babelpreamble", IL_BABELPREAMBLE },
144                 { "bgcolor", IL_BGCOLOR },
145                 { "contentaslabel", IL_CONTENTASLABEL },
146                 { "copystyle", IL_COPYSTYLE },
147                 { "counter", IL_COUNTER},
148                 { "custompars", IL_CUSTOMPARS },
149                 { "decoration", IL_DECORATION },
150                 { "display", IL_DISPLAY },
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                 { "multipar", IL_MULTIPAR },
181                 { "needcprotect", IL_NEEDCPROTECT },
182                 { "needprotect", IL_NEEDPROTECT },
183                 { "obsoletedby", IL_OBSOLETEDBY },
184                 { "parbreakisnewline", IL_PARBREAKISNEWLINE },
185                 { "passthru", IL_PASSTHRU },
186                 { "passthruchars", IL_PASSTHRU_CHARS },
187                 { "preamble", IL_PREAMBLE },
188                 { "refprefix", IL_REFPREFIX },
189                 { "requires", IL_REQUIRES },
190                 { "resetargs", IL_RESETARGS },
191                 { "resetsfont", IL_RESETSFONT },
192                 { "rightdelim", IL_RIGHTDELIM },
193                 { "spellcheck", IL_SPELLCHECK }
194         };
195
196         lex.pushTable(elementTags);
197
198         labelfont_ = inherit_font;
199         bgcolor_ = Color_none;
200         bool getout = false;
201         // whether we've read the CustomPars or ForcePlain tag
202         // for issuing a warning in case MultiPars comes later
203         bool readCustomOrPlain = false;
204
205         string tmp;
206         while (!getout && lex.isOK()) {
207                 int le = lex.lex();
208                 switch (le) {
209                 case Lexer::LEX_UNDEF:
210                         lex.printError("Unknown InsetLayout tag");
211                         continue;
212                 default:
213                         break;
214                 }
215                 switch (le) {
216                 // FIXME
217                 // Perhaps a more elegant way to deal with the next two would be the
218                 // way this sort of thing is handled in Layout::read(), namely, by
219                 // using the Lexer.
220                 case IL_LYXTYPE: {
221                         // make sure that we have the right sort of name.
222                         if (name_ != from_ascii("undefined")
223                             && name_.substr(0,5) != from_ascii("Flex:")) {
224                                 LYXERR0("Flex insets must have names of the form `Flex:<name>'.\n"
225                                         "This one has the name `" << to_utf8(name_) << "'\n"
226                                         "Ignoring LyXType declaration.");
227                                 break;
228                         }
229                         string lt;
230                         lex >> lt;
231                         lyxtype_ = translateLyXType(lt);
232                         if (lyxtype_  == NOLYXTYPE)
233                                 LYXERR0("Unknown LyXType `" << lt << "'.");
234                         if (lyxtype_ == CHARSTYLE) {
235                                 // by default, charstyles force the plain layout
236                                 multipar_ = false;
237                                 forceplain_ = true;
238                         }
239                         break;
240                 }
241                 case IL_LATEXTYPE:  {
242                         string lt;
243                         lex >> lt;
244                         latextype_ = translateLaTeXType(lt);
245                         if (latextype_  == ILT_ERROR)
246                                 LYXERR0("Unknown LaTeXType `" << lt << "'.");
247                         break;
248                 }
249                 case IL_LABELSTRING:
250                         lex >> labelstring_;
251                         break;
252                 case IL_DECORATION:
253                         lex >> tmp;
254                         decoration_ = translateDecoration(tmp);
255                         break;
256                 case IL_LATEXNAME:
257                         lex >> latexname_;
258                         break;
259                 case IL_LATEXPARAM:
260                         lex >> tmp;
261                         latexparam_ = subst(tmp, "&quot;", "\"");
262                         break;
263                 case IL_LEFTDELIM:
264                         lex >> leftdelim_;
265                         leftdelim_ = subst(leftdelim_, from_ascii("<br/>"),
266                                                     from_ascii("\n"));
267                         break;
268                 case IL_FIXEDWIDTH_PREAMBLE_ENCODING:
269                         lex >> fixedwidthpreambleencoding_;
270                         break;
271                 case IL_FORCE_LOCAL_FONT_SWITCH:
272                         lex >> forcelocalfontswitch_;
273                         break;
274                 case IL_RIGHTDELIM:
275                         lex >> rightdelim_;
276                         rightdelim_ = subst(rightdelim_, from_ascii("<br/>"),
277                                                      from_ascii("\n"));
278                         break;
279                 case IL_LABELFONT:
280                         labelfont_ = lyxRead(lex, inherit_font);
281                         break;
282                 case IL_FORCELTR:
283                         lex >> forceltr_;
284                         break;
285                 case IL_FORCEOWNLINES:
286                         lex >> forceownlines_;
287                         break;
288                 case IL_INTOC:
289                         lex >> intoc_;
290                         break;
291                 case IL_MULTIPAR:
292                         lex >> multipar_;
293                         // the defaults for these depend upon multipar_
294                         if (readCustomOrPlain)
295                                 LYXERR0("Warning: Read MultiPar after CustomPars or ForcePlain. "
296                                         "Previous value may be overwritten!");
297                         readCustomOrPlain = false;
298                         custompars_ = multipar_;
299                         forceplain_ = !multipar_;
300                         break;
301                 case IL_COUNTER:
302                         lex >> counter_;
303                         break;
304                 case IL_CUSTOMPARS:
305                         lex >> custompars_;
306                         readCustomOrPlain = true;
307                         break;
308                 case IL_FORCEPLAIN:
309                         lex >> forceplain_;
310                         readCustomOrPlain = true;
311                         break;
312                 case IL_PASSTHRU:
313                         lex >> passthru_;
314                         break;
315                 case IL_PASSTHRU_CHARS:
316                         lex >> passthru_chars_;
317                         break;
318                 case IL_PARBREAKISNEWLINE:
319                         lex >> parbreakisnewline_;
320                         break;
321                 case IL_KEEPEMPTY:
322                         lex >> keepempty_;
323                         break;
324                 case IL_FREESPACING:
325                         lex >> freespacing_;
326                         break;
327                 case IL_NEEDPROTECT:
328                         lex >> needprotect_;
329                         break;
330                 case IL_NEEDCPROTECT:
331                         lex >> needcprotect_;
332                         break;
333                 case IL_CONTENTASLABEL:
334                         lex >> contentaslabel_;
335                         break;
336                 case IL_COPYSTYLE: {
337                         // initialize with a known style
338                         docstring style;
339                         lex >> style;
340                         style = subst(style, '_', ' ');
341
342                         // We don't want to apply the algorithm in DocumentClass::insetLayout()
343                         // here. So we do it the long way.
344                         TextClass::InsetLayouts::const_iterator it =
345                                         tclass.insetLayouts().find(style);
346                         if (it != tclass.insetLayouts().end()) {
347                                 docstring const tmpname = name_;
348                                 this->operator=(it->second);
349                                 name_ = tmpname;
350                         } else {
351                                 LYXERR0("Cannot copy unknown InsetLayout `"
352                                         << style << "' to InsetLayout `"
353                                         << name() << "'\n"
354                                         << "All InsetLayouts so far:");
355                                 TextClass::InsetLayouts::const_iterator lit =
356                                                 tclass.insetLayouts().begin();
357                                 TextClass::InsetLayouts::const_iterator len =
358                                                 tclass.insetLayouts().end();
359                                 for (; lit != len; ++lit)
360                                         lyxerr << lit->second.name() << "\n";
361                         }
362                         break;
363                 }
364                 case IL_OBSOLETEDBY: {
365                         docstring style;
366                         lex >> style;
367                         style = subst(style, '_', ' ');
368
369                         // We don't want to apply the algorithm in DocumentClass::insetLayout()
370                         // here. So we do it the long way.
371                         TextClass::InsetLayouts::const_iterator it =
372                                         tclass.insetLayouts().find(style);
373                         if (it != tclass.insetLayouts().end()) {
374                                 docstring const tmpname = name_;
375                                 this->operator=(it->second);
376                                 name_ = tmpname;
377                                 if (obsoleted_by().empty())
378                                         obsoleted_by_ = style;
379                         } else {
380                                 LYXERR0("Cannot replace InsetLayout `"
381                                         << name()
382                                         << "' with unknown InsetLayout `"
383                                         << style << "'\n"
384                                         << "All InsetLayouts so far:");
385                                 TextClass::InsetLayouts::const_iterator lit =
386                                                 tclass.insetLayouts().begin();
387                                 TextClass::InsetLayouts::const_iterator len =
388                                                 tclass.insetLayouts().end();
389                                 for (; lit != len; ++lit)
390                                         lyxerr << lit->second.name() << "\n";
391                         }
392                         break;
393                 }
394
395                 case IL_FONT: {
396                         font_ = lyxRead(lex, inherit_font);
397                         // If you want to define labelfont, you need to do so after
398                         // font is defined.
399                         labelfont_ = font_;
400                         break;
401                 }
402                 case IL_RESETARGS:
403                         bool reset;
404                         lex >> reset;
405                         if (reset) {
406                                 latexargs_.clear();
407                                 postcommandargs_.clear();
408                         }
409                         break;
410                 case IL_ARGUMENT:
411                         readArgument(lex);
412                         break;
413                 case IL_BGCOLOR:
414                         lex >> tmp;
415                         bgcolor_ = lcolor.getFromLyXName(tmp);
416                         break;
417                 case IL_PREAMBLE:
418                         preamble_ = lex.getLongString(from_ascii("EndPreamble"));
419                         break;
420                 case IL_BABELPREAMBLE:
421                         babelpreamble_ = lex.getLongString(from_ascii("EndBabelPreamble"));
422                         break;
423                 case IL_LANGPREAMBLE:
424                         langpreamble_ = lex.getLongString(from_ascii("EndLangPreamble"));
425                         break;
426                 case IL_REFPREFIX:
427                         lex >> refprefix_;
428                         break;
429                 case IL_HTMLTAG:
430                         lex >> htmltag_;
431                         break;
432                 case IL_HTMLATTR:
433                         lex >> htmlattr_;
434                         break;
435                 case IL_HTMLFORCECSS:
436                         lex >> htmlforcecss_;
437                         break;
438                 case IL_HTMLINNERTAG:
439                         lex >> htmlinnertag_;
440                         break;
441                 case IL_HTMLINNERATTR:
442                         lex >> htmlinnerattr_;
443                         break;
444                 case IL_HTMLLABEL:
445                         lex >> htmllabel_;
446                         break;
447                 case IL_HTMLISBLOCK:
448                         lex >> htmlisblock_;
449                         break;
450                 case IL_HTMLSTYLE:
451                         htmlstyle_ = lex.getLongString(from_ascii("EndHTMLStyle"));
452                         break;
453                 case IL_HTMLPREAMBLE:
454                         htmlpreamble_ = lex.getLongString(from_ascii("EndPreamble"));
455                         break;
456                 case IL_REQUIRES: {
457                         lex.eatLine();
458                         vector<string> const req
459                                 = getVectorFromString(lex.getString(true));
460                         requires_.insert(req.begin(), req.end());
461                         break;
462                 }
463                 case IL_SPELLCHECK:
464                         lex >> spellcheck_;
465                         break;
466                 case IL_RESETSFONT:
467                         lex >> resetsfont_;
468                         break;
469                 case IL_DISPLAY:
470                         lex >> display_;
471                         break;
472                 case IL_ADDTOTOC:
473                         lex >> toc_type_;
474                         add_to_toc_ = !toc_type_.empty();
475                         break;
476                 case IL_ISTOCCAPTION:
477                         lex >> is_toc_caption_;
478                         break;
479                 case IL_EDITEXTERNAL:
480                         lex >> edit_external_;
481                         break;
482                 case IL_END:
483                         getout = true;
484                         break;
485                 }
486         }
487
488         // Here add element to list if getout == true
489         if (!getout)
490                 return false;
491
492         // The label font is generally used as-is without
493         // any realization against a given context.
494         labelfont_.realize(sane_font);
495
496         lex.popTable();
497         return true;
498 }
499
500
501 InsetLayout::InsetLyXType translateLyXType(std::string const & str)
502 {
503         if (compare_ascii_no_case(str, "charstyle") == 0)
504                 return InsetLayout::CHARSTYLE;
505         if (compare_ascii_no_case(str, "custom") == 0)
506                 return InsetLayout::CUSTOM;
507         if (compare_ascii_no_case(str, "element") == 0)
508                 return InsetLayout::ELEMENT;
509         if (compare_ascii_no_case(str, "end") == 0)
510                 return InsetLayout::END;
511         if (compare_ascii_no_case(str, "standard") == 0)
512                 return InsetLayout::STANDARD;
513         return InsetLayout::NOLYXTYPE;
514 }
515
516
517 string const & InsetLayout::htmltag() const
518 {
519         if (htmltag_.empty())
520                 htmltag_ = multipar_ ? "div" : "span";
521         return htmltag_;
522 }
523
524
525 string const & InsetLayout::htmlattr() const
526 {
527         if (htmlattr_.empty())
528                 htmlattr_ = "class=\"" + defaultCSSClass() + "\"";
529         return htmlattr_;
530 }
531
532
533 string const & InsetLayout::htmlinnerattr() const
534 {
535         if (htmlinnerattr_.empty())
536                 htmlinnerattr_ = "class=\"" + defaultCSSClass() + "_inner\"";
537         return htmlinnerattr_;
538 }
539
540
541 string InsetLayout::defaultCSSClass() const
542 {
543         if (!defaultcssclass_.empty())
544                 return defaultcssclass_;
545         string d;
546         string n = to_utf8(name());
547         string::const_iterator it = n.begin();
548         string::const_iterator en = n.end();
549         for (; it != en; ++it) {
550                 if (!isAlphaASCII(*it))
551                         d += "_";
552                 else if (isLower(*it))
553                         d += *it;
554                 else
555                         d += lowercase(*it);
556         }
557         // are there other characters we need to remove?
558         defaultcssclass_ = d;
559         return defaultcssclass_;
560 }
561
562
563 void InsetLayout::makeDefaultCSS() const
564 {
565         if (!htmldefaultstyle_.empty())
566                 return;
567         docstring const mainfontCSS = font_.asCSS();
568         if (!mainfontCSS.empty())
569                 htmldefaultstyle_ =
570                                 from_ascii(htmltag() + "." + defaultCSSClass() + " {\n") +
571                                 mainfontCSS + from_ascii("\n}\n");
572 }
573
574
575 docstring InsetLayout::htmlstyle() const
576 {
577         if (!htmlstyle_.empty() && !htmlforcecss_)
578                 return htmlstyle_;
579         if (htmldefaultstyle_.empty())
580                 makeDefaultCSS();
581         docstring retval = htmldefaultstyle_;
582         if (!htmlstyle_.empty())
583                 retval += '\n' + htmlstyle_ + '\n';
584         return retval;
585 }
586
587 void InsetLayout::readArgument(Lexer & lex)
588 {
589         Layout::latexarg arg;
590         arg.mandatory = false;
591         arg.autoinsert = false;
592         arg.insertcotext = false;
593         bool error = false;
594         bool finished = false;
595         arg.font = inherit_font;
596         arg.labelfont = inherit_font;
597         arg.is_toc_caption = false;
598         arg.passthru = PT_INHERITED;
599         arg.nodelims = false;
600         string nr;
601         lex >> nr;
602         bool const postcmd = prefixIs(nr, "post:");
603         while (!finished && lex.isOK() && !error) {
604                 lex.next();
605                 string const tok = ascii_lowercase(lex.getString());
606
607                 if (tok.empty()) {
608                         continue;
609                 } else if (tok == "endargument") {
610                         finished = true;
611                 } else if (tok == "labelstring") {
612                         lex.next();
613                         arg.labelstring = lex.getDocString();
614                 } else if (tok == "menustring") {
615                         lex.next();
616                         arg.menustring = lex.getDocString();
617                 } else if (tok == "mandatory") {
618                         lex.next();
619                         arg.mandatory = lex.getBool();
620                 } else if (tok == "autoinsert") {
621                         lex.next();
622                         arg.autoinsert = lex.getBool();
623                 } else if (tok == "insertcotext") {
624                         lex.next();
625                         arg.insertcotext = lex.getBool();
626                 } else if (tok == "leftdelim") {
627                         lex.next();
628                         arg.ldelim = lex.getDocString();
629                         arg.ldelim = subst(arg.ldelim,
630                                                     from_ascii("<br/>"), from_ascii("\n"));
631                 } else if (tok == "rightdelim") {
632                         lex.next();
633                         arg.rdelim = lex.getDocString();
634                         arg.rdelim = subst(arg.rdelim,
635                                                     from_ascii("<br/>"), from_ascii("\n"));
636                 } else if (tok == "defaultarg") {
637                         lex.next();
638                         arg.defaultarg = lex.getDocString();
639                 } else if (tok == "presetarg") {
640                         lex.next();
641                         arg.presetarg = lex.getDocString();
642                 } else if (tok == "tooltip") {
643                         lex.next();
644                         arg.tooltip = lex.getDocString();
645                 } else if (tok == "requires") {
646                         lex.next();
647                         arg.requires = lex.getString();
648                 } else if (tok == "decoration") {
649                         lex.next();
650                         arg.decoration = lex.getString();
651                 } else if (tok == "font") {
652                         arg.font = lyxRead(lex, arg.font);
653                 } else if (tok == "labelfont") {
654                         arg.labelfont = lyxRead(lex, arg.labelfont);
655                 } else if (tok == "passthruchars") {
656                         lex.next();
657                         arg.pass_thru_chars = lex.getDocString();
658                 } else if (tok == "passthru") {
659                         lex.next();
660                         docstring value = lex.getDocString();
661                         if (value == "true" || value == "1")
662                                 arg.passthru = PT_TRUE;
663                         else if (value == "false" || value == "0")
664                                 arg.passthru = PT_FALSE;
665                         else
666                                 arg.passthru = PT_INHERITED;
667                 } else if (tok == "istoccaption") {
668                         lex.next();
669                         arg.is_toc_caption = lex.getBool();
670                 } else {
671                         lex.printError("Unknown tag");
672                         error = true;
673                 }
674         }
675         if (arg.labelstring.empty())
676                 LYXERR0("Incomplete Argument definition!");
677         else if (postcmd)
678                 postcommandargs_[nr] = arg;
679         else
680                 latexargs_[nr] = arg;
681 }
682
683
684 Layout::LaTeXArgMap InsetLayout::args() const
685 {
686         Layout::LaTeXArgMap args = latexargs_;
687         if (!postcommandargs_.empty())
688                 args.insert(postcommandargs_.begin(), postcommandargs_.end());
689         return args;
690 }
691
692
693 unsigned int InsetLayout::optArgs() const
694 {
695         unsigned int nr = 0;
696         Layout::LaTeXArgMap const args = InsetLayout::args();
697         Layout::LaTeXArgMap::const_iterator it = args.begin();
698         for (; it != args.end(); ++it) {
699                 if (!(*it).second.mandatory)
700                         ++nr;
701         }
702         return nr;
703 }
704
705
706 unsigned int InsetLayout::requiredArgs() const
707 {
708         unsigned int nr = 0;
709         Layout::LaTeXArgMap const args = InsetLayout::args();
710         Layout::LaTeXArgMap::const_iterator it = args.begin();
711         for (; it != args.end(); ++it) {
712                 if ((*it).second.mandatory)
713                         ++nr;
714         }
715         return nr;
716 }
717
718
719 } //namespace lyx