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