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