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