3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
7 * \author Jean-Marc Lasgouttes
10 * Full author contact details are available in file CREDITS.
16 #include "output_xhtml.h"
17 #include "TextClass.h"
19 #include "support/debug.h"
20 #include "support/docstream.h"
21 #include "support/lassert.h"
22 #include "support/Lexer.h"
23 #include "support/lstrings.h"
24 #include "support/textutils.h"
28 using namespace lyx::support;
32 /// Special value of toclevel for layouts that do not belong to a TOC
33 const int Layout::NOT_IN_TOC = -1000;
35 // The order of the LayoutTags enum is no more important. [asierra300396]
55 LT_PARBREAK_IS_NEWLINE,
65 LT_LABELSTRING_APPENDIX,
111 LT_DOCBOOKINNERTAGTYPE,
114 LT_DOCBOOKGENERATETITLE,
115 LT_DOCBOOKWRAPPERTAG,
116 LT_DOCBOOKWRAPPERATTR,
117 LT_DOCBOOKWRAPPERTAGTYPE,
118 LT_DOCBOOKWRAPPERMERGEWITHPREVIOUS,
120 LT_DOCBOOKSECTIONTAG,
121 LT_DOCBOOKITEMWRAPPERTAG,
122 LT_DOCBOOKITEMWRAPPERATTR,
123 LT_DOCBOOKITEMWRAPPERTAGTYPE,
126 LT_DOCBOOKITEMTAGTYPE,
127 LT_DOCBOOKITEMLABELTAG,
128 LT_DOCBOOKITEMLABELATTR,
129 LT_DOCBOOKITEMLABELTAGTYPE,
130 LT_DOCBOOKITEMINNERTAG,
131 LT_DOCBOOKITEMINNERATTR,
132 LT_DOCBOOKITEMINNERTAGTYPE,
133 LT_DOCBOOKFORCEABSTRACTTAG,
134 LT_DOCBOOKNOFONTINSIDE,
141 LT_STEPPARENTCOUNTER,
148 LT_INTITLE // keep this last!
151 /////////////////////
154 : add_to_toc_(false), is_toc_caption_(true)
157 margintype = MARGIN_STATIC;
158 latextype = LATEX_PARAGRAPH;
159 resumecounter = false;
160 stepparentcounter = false;
164 needcprotect = false;
166 needmboxprotect = false;
169 labelfont = inherit_font;
171 reslabelfont = sane_font;
172 nextnoindent = false;
177 labelbottomsep = 0.0;
179 align = LYX_ALIGN_BLOCK;
180 alignpossible = LYX_ALIGN_NONE | LYX_ALIGN_LAYOUT;
181 labeltype = LABEL_NO_LABEL;
182 endlabeltype = END_LABEL_NO_LABEL;
183 // Should or should not. That is the question.
184 // spacing.set(Spacing::OneHalf);
185 newline_allowed = true;
186 free_spacing = false;
188 parbreak_is_newline = false;
189 toclevel = NOT_IN_TOC;
191 htmllabelfirst_ = false;
192 htmlforcecss_ = false;
195 docbookabstract_ = false;
196 docbookwrappermergewithprevious_ = false;
197 docbooksection_ = false;
200 itemcommand_ = "item";
201 toggle_indent = ITOGGLE_DOCUMENT_DEFAULT;
206 bool Layout::read(Lexer & lex, TextClass const & tclass, bool validating)
208 // If this is an empty layout, or if no force local version is set,
209 // we know that we will not discard the stuff to read
211 return readIgnoreForcelocal(lex, tclass, validating);
214 bool const ret = tmp.readIgnoreForcelocal(lex, tclass, validating);
216 // - the read version is higher
217 // - both versions are infinity (arbitrary decision)
218 // - the file did not contain any local version (needed for not
219 // skipping user defined local layouts)
220 if (tmp.forcelocal <= 0 || tmp.forcelocal > forcelocal)
226 bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass,
229 // This table is sorted alphabetically [asierra 30March96]
230 LexerKeyword layoutTags[] = {
231 { "addtotoc", LT_ADDTOTOC },
232 { "align", LT_ALIGN },
233 { "alignpossible", LT_ALIGNPOSSIBLE },
234 { "argument", LT_ARGUMENT },
235 { "autonests", LT_AUTONESTS },
236 { "babelpreamble", LT_BABELPREAMBLE },
237 { "bottomsep", LT_BOTTOMSEP },
238 { "category", LT_CATEGORY },
239 { "commanddepth", LT_COMMANDDEPTH },
240 { "copystyle", LT_COPYSTYLE },
241 { "dependson", LT_DEPENDSON },
242 { "docbookabstract", LT_DOCBOOKABSTRACT },
243 { "docbookattr", LT_DOCBOOKATTR },
244 { "docbookforceabstracttag", LT_DOCBOOKFORCEABSTRACTTAG },
245 { "docbookgeneratetitle", LT_DOCBOOKGENERATETITLE },
246 { "docbookininfo", LT_DOCBOOKININFO },
247 { "docbookinnerattr", LT_DOCBOOKINNERATTR },
248 { "docbookinnertag", LT_DOCBOOKINNERTAG },
249 { "docbookinnertagtype", LT_DOCBOOKINNERTAGTYPE },
250 { "docbookitemattr", LT_DOCBOOKITEMATTR },
251 { "docbookiteminnerattr", LT_DOCBOOKITEMINNERATTR },
252 { "docbookiteminnertag", LT_DOCBOOKITEMINNERTAG },
253 { "docbookiteminnertagtype", LT_DOCBOOKITEMINNERTAGTYPE },
254 { "docbookitemlabelattr", LT_DOCBOOKITEMLABELATTR },
255 { "docbookitemlabeltag", LT_DOCBOOKITEMLABELTAG },
256 { "docbookitemlabeltagtype", LT_DOCBOOKITEMLABELTAGTYPE },
257 { "docbookitemtag", LT_DOCBOOKITEMTAG },
258 { "docbookitemtagtype", LT_DOCBOOKITEMTAGTYPE },
259 { "docbookitemwrapperattr", LT_DOCBOOKITEMWRAPPERATTR },
260 { "docbookitemwrappertag", LT_DOCBOOKITEMWRAPPERTAG },
261 { "docbookitemwrappertagtype", LT_DOCBOOKITEMWRAPPERTAGTYPE },
262 { "docbooknofontinside", LT_DOCBOOKNOFONTINSIDE, },
263 { "docbooksection", LT_DOCBOOKSECTION },
264 { "docbooksectiontag", LT_DOCBOOKSECTIONTAG },
265 { "docbooktag", LT_DOCBOOKTAG },
266 { "docbooktagtype", LT_DOCBOOKTAGTYPE },
267 { "docbookwrapperattr", LT_DOCBOOKWRAPPERATTR },
268 { "docbookwrappermergewithprevious", LT_DOCBOOKWRAPPERMERGEWITHPREVIOUS },
269 { "docbookwrappertag", LT_DOCBOOKWRAPPERTAG },
270 { "docbookwrappertagtype", LT_DOCBOOKWRAPPERTAGTYPE },
272 { "endlabelstring", LT_ENDLABELSTRING },
273 { "endlabeltype", LT_ENDLABELTYPE },
275 { "forcelocal", LT_FORCELOCAL },
276 { "freespacing", LT_FREE_SPACING },
277 { "htmlattr", LT_HTMLATTR },
278 { "htmlclass", LT_HTMLCLASS },
279 { "htmlforcecss", LT_HTMLFORCECSS },
280 { "htmlintoc", LT_HTMLINTOC },
281 { "htmlitem", LT_HTMLITEM },
282 { "htmlitemattr", LT_HTMLITEMATTR },
283 { "htmllabel", LT_HTMLLABEL },
284 { "htmllabelattr", LT_HTMLLABELATTR },
285 { "htmllabelfirst", LT_HTMLLABELFIRST },
286 { "htmlpreamble", LT_HTMLPREAMBLE },
287 { "htmlstyle", LT_HTMLSTYLE },
288 { "htmltag", LT_HTMLTAG },
289 { "htmltitle", LT_HTMLTITLE },
290 { "innertag", LT_INNERTAG },
291 { "inpreamble", LT_INPREAMBLE },
292 { "intitle", LT_INTITLE },
293 { "isautonestedby", LT_AUTONESTEDBY },
294 { "istoccaption", LT_ISTOCCAPTION },
295 { "itemcommand", LT_ITEMCOMMAND },
296 { "itemsep", LT_ITEMSEP },
297 { "itemtag", LT_ITEMTAG },
298 { "keepempty", LT_KEEPEMPTY },
299 { "labelbottomsep", LT_LABEL_BOTTOMSEP },
300 { "labelcounter", LT_LABELCOUNTER },
301 { "labelfont", LT_LABELFONT },
302 { "labelindent", LT_LABELINDENT },
303 { "labelsep", LT_LABELSEP },
304 { "labelstring", LT_LABELSTRING },
305 { "labelstringappendix", LT_LABELSTRING_APPENDIX },
306 { "labeltag", LT_LABELTAG },
307 { "labeltype", LT_LABELTYPE },
308 { "langpreamble", LT_LANGPREAMBLE },
309 { "latexname", LT_LATEXNAME },
310 { "latexparam", LT_LATEXPARAM },
311 { "latextype", LT_LATEXTYPE },
312 { "leftdelim", LT_LEFTDELIM },
313 { "leftmargin", LT_LEFTMARGIN },
314 { "margin", LT_MARGIN },
315 { "needcprotect", LT_NEED_CPROTECT },
316 { "needmboxprotect", LT_NEED_MBOXPROTECT },
317 { "needprotect", LT_NEED_PROTECT },
318 { "newline", LT_NEWLINE },
319 { "nextnoindent", LT_NEXTNOINDENT },
320 { "obsoletedby", LT_OBSOLETEDBY },
321 { "paragraphgroup", LT_PAR_GROUP },
322 { "parbreakisnewline", LT_PARBREAK_IS_NEWLINE },
323 { "parindent", LT_PARINDENT },
324 { "parsep", LT_PARSEP },
325 { "parskip", LT_PARSKIP },
326 { "passthru", LT_PASS_THRU },
327 { "passthruchars", LT_PASS_THRU_CHARS },
328 { "preamble", LT_PREAMBLE },
329 { "refprefix", LT_REFPREFIX },
330 { "requires", LT_REQUIRES },
331 { "resetargs", LT_RESETARGS },
332 { "resumecounter", LT_RESUMECOUNTER },
333 { "rightdelim", LT_RIGHTDELIM },
334 { "rightmargin", LT_RIGHTMARGIN },
335 { "spacing", LT_SPACING },
336 { "spellcheck", LT_SPELLCHECK },
337 { "stepparentcounter", LT_STEPPARENTCOUNTER },
338 { "textfont", LT_TEXTFONT },
339 { "toclevel", LT_TOCLEVEL },
340 { "toggleindent", LT_TOGGLE_INDENT },
341 { "topsep", LT_TOPSEP }
345 bool finished = false;
346 lex.pushTable(layoutTags);
348 // parse style section
349 while (!finished && lex.isOK() && !error) {
351 // See comment in LyXRC.cpp.
353 case Lexer::LEX_FEOF:
356 case Lexer::LEX_UNDEF:
358 lex.printError("Unknown layout tag `$$Token'");
365 switch (static_cast<LayoutTags>(le)) {
377 style = subst(style, '_', ' ');
379 if (tclass.hasLayout(style)) {
380 docstring const tmpname = name_;
381 this->operator=(tclass[style]);
384 LYXERR0("Cannot copy unknown style `"
386 << "All layouts so far:");
387 DocumentClass::const_iterator lit = tclass.begin();
388 DocumentClass::const_iterator len = tclass.end();
389 for (; lit != len; ++lit)
390 LYXERR0(lit->name());
395 case LT_OBSOLETEDBY: {
398 style = subst(style, '_', ' ');
400 if (tclass.hasLayout(style)) {
401 docstring const tmpname = name_;
402 this->operator=(tclass[style]);
404 if (obsoleted_by().empty())
405 obsoleted_by_ = style;
407 LYXERR0("Cannot replace with unknown style `"
410 //lex.printError("Cannot replace with"
419 depends_on_ = subst(depends_on_, '_', ' ');
448 postcommandargs_.clear();
449 listpreamble_.clear();
453 case LT_RESUMECOUNTER:
454 lex >> resumecounter;
457 case LT_STEPPARENTCOUNTER:
458 lex >> stepparentcounter;
462 readArgument(lex, validating);
465 case LT_NEED_PROTECT:
469 case LT_NEED_CPROTECT: {
473 needcprotect = false;
481 case LT_NEED_MBOXPROTECT:
482 lex >> needmboxprotect;
490 font = lyxRead(lex, font);
495 font = lyxRead(lex, font);
499 labelfont = lyxRead(lex, labelfont);
502 case LT_NEXTNOINDENT:
506 case LT_TOGGLE_INDENT: {
509 tog = support::ascii_lowercase(tog);
511 toggle_indent = ITOGGLE_ALWAYS;
512 else if (tog == "never")
513 toggle_indent = ITOGGLE_NEVER;
515 toggle_indent = ITOGGLE_DOCUMENT_DEFAULT;
519 case LT_COMMANDDEPTH:
529 latexparam_ = subst(latexparam_, """, "\"");
534 leftdelim_ = support::subst(leftdelim_, from_ascii("<br/>"),
540 rightdelim_ = support::subst(rightdelim_, from_ascii("<br/>"),
561 preamble_ = lex.getLongString(from_ascii("EndPreamble"));
564 case LT_LANGPREAMBLE:
565 langpreamble_ = lex.getLongString(from_ascii("EndLangPreamble"));
568 case LT_BABELPREAMBLE:
569 babelpreamble_ = lex.getLongString(from_ascii("EndBabelPreamble"));
576 case LT_ENDLABELTYPE:
577 readEndLabelType(lex);
612 case LT_LABEL_BOTTOMSEP:
613 lex >> labelbottomsep;
618 labelsep = subst(labelsep, 'x', ' ');
626 lex >> newline_allowed;
633 case LT_ALIGNPOSSIBLE:
634 readAlignPossible(lex);
638 // FIXME: this means LT_LABELSTRING_APPENDIX may only
639 // occur after LT_LABELSTRING
641 labelstring_appendix_ = labelstring_;
644 case LT_ENDLABELSTRING:
645 lex >> endlabelstring_;
648 case LT_LABELSTRING_APPENDIX:
649 lex >> labelstring_appendix_;
652 case LT_LABELCOUNTER:
660 case LT_FREE_SPACING:
668 case LT_PASS_THRU_CHARS:
669 lex >> pass_thru_chars;
672 case LT_PARBREAK_IS_NEWLINE:
673 lex >> parbreak_is_newline;
682 vector<string> const req =
683 getVectorFromString(lex.getString(true));
684 required_.insert(req.begin(), req.end());
689 docstring autonest = lex.getLongString(from_ascii("EndAutoNests"));
690 autonest = subst(autonest, from_ascii("\n"), docstring());
691 autonest = subst(autonest, from_ascii("\t"), docstring());
692 autonest = subst(autonest, from_ascii("\""), docstring());
693 autonest = subst(autonest, '_', ' ');
694 vector<docstring> const autonests =
695 getVectorFromString(autonest, from_ascii(","), false, true);
696 autonests_.insert(autonests.begin(), autonests.end());
700 case LT_AUTONESTEDBY: {
701 docstring autonest = lex.getLongString(from_ascii("EndIsAutoNestedBy"));
702 autonest = subst(autonest, from_ascii("\n"), docstring());
703 autonest = subst(autonest, from_ascii("\t"), docstring());
704 autonest = subst(autonest, from_ascii("\""), docstring());
705 autonest = subst(autonest, '_', ' ');
706 vector<docstring> const autonests =
707 getVectorFromString(autonest, from_ascii(","), false, true);
708 autonested_by_.insert(autonests.begin(), autonests.end());
742 case LT_HTMLITEMATTR:
743 lex >> htmlitemattr_;
747 lex >> htmllabeltag_;
750 case LT_HTMLLABELATTR:
751 lex >> htmllabelattr_;
754 case LT_HTMLLABELFIRST:
755 lex >> htmllabelfirst_;
759 htmlstyle_ = lex.getLongString(from_ascii("EndHTMLStyle"));
762 case LT_HTMLFORCECSS:
763 lex >> htmlforcecss_;
766 case LT_HTMLPREAMBLE:
767 htmlpreamble_ = lex.getLongString(from_ascii("EndPreamble"));
782 case LT_DOCBOOKTAGTYPE:
783 lex >> docbooktagtype_;
786 case LT_DOCBOOKINNERTAG:
787 lex >> docbookinnertag_;
790 case LT_DOCBOOKINNERATTR:
791 lex >> docbookinnerattr_;
794 case LT_DOCBOOKINNERTAGTYPE:
795 lex >> docbookinnertagtype_;
798 case LT_DOCBOOKFORCEABSTRACTTAG:
799 lex >> docbookforceabstracttag_;
802 case LT_DOCBOOKININFO:
803 lex >> docbookininfo_;
806 case LT_DOCBOOKABSTRACT:
807 lex >> docbookabstract_;
810 case LT_DOCBOOKWRAPPERTAG:
811 lex >> docbookwrappertag_;
814 case LT_DOCBOOKWRAPPERATTR:
815 lex >> docbookwrapperattr_;
818 case LT_DOCBOOKWRAPPERTAGTYPE:
819 lex >> docbookwrappertagtype_;
822 case LT_DOCBOOKWRAPPERMERGEWITHPREVIOUS:
823 lex >> docbookwrappermergewithprevious_;
826 case LT_DOCBOOKSECTION:
827 lex >> docbooksection_;
830 case LT_DOCBOOKSECTIONTAG:
831 lex >> docbooksectiontag_;
834 case LT_DOCBOOKITEMWRAPPERTAG:
835 lex >> docbookitemwrappertag_;
838 case LT_DOCBOOKITEMWRAPPERATTR:
839 lex >> docbookitemwrapperattr_;
842 case LT_DOCBOOKITEMWRAPPERTAGTYPE:
843 lex >> docbookitemwrappertagtype_;
846 case LT_DOCBOOKITEMTAG:
847 lex >> docbookitemtag_;
850 case LT_DOCBOOKITEMATTR:
851 lex >> docbookitemattr_;
854 case LT_DOCBOOKITEMTAGTYPE:
855 lex >> docbookitemtagtype_;
858 case LT_DOCBOOKITEMLABELTAG:
859 lex >> docbookitemlabeltag_;
862 case LT_DOCBOOKITEMLABELATTR:
863 lex >> docbookitemlabelattr_;
866 case LT_DOCBOOKITEMLABELTAGTYPE:
867 lex >> docbookitemlabeltagtype_;
870 case LT_DOCBOOKITEMINNERTAG:
871 lex >> docbookiteminnertag_;
874 case LT_DOCBOOKITEMINNERATTR:
875 lex >> docbookiteminnerattr_;
878 case LT_DOCBOOKITEMINNERTAGTYPE:
879 lex >> docbookiteminnertagtype_;
882 case LT_DOCBOOKNOFONTINSIDE:
883 lex >> docbooknofontinside_;
886 case LT_DOCBOOKGENERATETITLE:
887 lex >> docbookgeneratetitle_;
900 add_to_toc_ = !toc_type_.empty();
903 case LT_ISTOCCAPTION:
904 lex >> is_toc_caption_;
910 // make sure we only have inpreamble = true for commands
911 if (inpreamble && latextype != LATEX_COMMAND && latextype != LATEX_PARAGRAPH) {
912 LYXERR0("InPreamble not permitted except with command and paragraph layouts.");
913 LYXERR0("Layout name: " << name());
917 return finished && !error;
930 LexerKeyword alignTags[] = {
931 { "block", AT_BLOCK },
932 { "center", AT_CENTER },
933 { "layout", AT_LAYOUT },
935 { "right", AT_RIGHT }
939 void Layout::readAlign(Lexer & lex)
941 PushPopHelper pph(lex, alignTags);
944 case Lexer::LEX_UNDEF:
945 lex.printError("Unknown alignment `$$Token'");
951 align = LYX_ALIGN_BLOCK;
954 align = LYX_ALIGN_LEFT;
957 align = LYX_ALIGN_RIGHT;
960 align = LYX_ALIGN_CENTER;
963 align = LYX_ALIGN_LAYOUT;
969 void Layout::readAlignPossible(Lexer & lex)
971 lex.pushTable(alignTags);
972 alignpossible = LYX_ALIGN_NONE | LYX_ALIGN_LAYOUT;
973 int lineno = lex.lineNumber();
977 case Lexer::LEX_UNDEF:
978 lex.printError("Unknown alignment `$$Token'");
984 alignpossible |= LYX_ALIGN_BLOCK;
987 alignpossible |= LYX_ALIGN_LEFT;
990 alignpossible |= LYX_ALIGN_RIGHT;
993 alignpossible |= LYX_ALIGN_CENTER;
996 alignpossible |= LYX_ALIGN_LAYOUT;
999 } while (lineno == lex.lineNumber());
1004 void Layout::readLabelType(Lexer & lex)
1019 LexerKeyword labelTypeTags[] = {
1020 { "above", LA_ABOVE },
1021 { "bibliography", LA_BIBLIO },
1022 { "centered", LA_CENTERED },
1023 { "enumerate", LA_ENUMERATE },
1024 { "itemize", LA_ITEMIZE },
1025 { "manual", LA_MANUAL },
1026 { "no_label", LA_NO_LABEL },
1027 { "sensitive", LA_SENSITIVE },
1028 { "static", LA_STATIC }
1031 PushPopHelper pph(lex, labelTypeTags);
1034 case Lexer::LEX_UNDEF:
1035 lex.printError("Unknown labeltype tag `$$Token'");
1041 labeltype = LABEL_NO_LABEL;
1044 labeltype = LABEL_MANUAL;
1047 labeltype = LABEL_ABOVE;
1050 labeltype = LABEL_CENTERED;
1053 labeltype = LABEL_STATIC;
1056 labeltype = LABEL_SENSITIVE;
1059 labeltype = LABEL_ENUMERATE;
1062 labeltype = LABEL_ITEMIZE;
1065 labeltype = LABEL_BIBLIO;
1071 void Layout::readEndLabelType(Lexer & lex)
1073 // this should be const, but can't be because
1074 // of PushPopHelper.
1075 static LexerKeyword endlabelTypeTags[] = {
1076 { "box", END_LABEL_BOX },
1077 { "filled_box", END_LABEL_FILLED_BOX },
1078 { "no_label", END_LABEL_NO_LABEL },
1079 { "static", END_LABEL_STATIC }
1082 PushPopHelper pph(lex, endlabelTypeTags);
1085 case Lexer::LEX_UNDEF:
1086 lex.printError("Unknown labeltype tag `$$Token'");
1088 case END_LABEL_STATIC:
1090 case END_LABEL_FILLED_BOX:
1091 case END_LABEL_NO_LABEL:
1092 endlabeltype = static_cast<EndLabelType>(le);
1095 LYXERR0("Unhandled value " << le);
1101 void Layout::readMargin(Lexer & lex)
1103 LexerKeyword marginTags[] = {
1104 { "dynamic", MARGIN_DYNAMIC },
1105 { "first_dynamic", MARGIN_FIRST_DYNAMIC },
1106 { "manual", MARGIN_MANUAL },
1107 { "right_address_box", MARGIN_RIGHT_ADDRESS_BOX },
1108 { "static", MARGIN_STATIC }
1111 PushPopHelper pph(lex, marginTags);
1115 case Lexer::LEX_UNDEF:
1116 lex.printError("Unknown margin type tag `$$Token'");
1120 case MARGIN_DYNAMIC:
1121 case MARGIN_FIRST_DYNAMIC:
1122 case MARGIN_RIGHT_ADDRESS_BOX:
1123 margintype = static_cast<MarginType>(le);
1126 LYXERR0("Unhandled value " << le);
1132 void Layout::readLatexType(Lexer & lex)
1134 LexerKeyword latexTypeTags[] = {
1135 { "bib_environment", LATEX_BIB_ENVIRONMENT },
1136 { "command", LATEX_COMMAND },
1137 { "environment", LATEX_ENVIRONMENT },
1138 { "item_environment", LATEX_ITEM_ENVIRONMENT },
1139 { "list_environment", LATEX_LIST_ENVIRONMENT },
1140 { "paragraph", LATEX_PARAGRAPH }
1143 PushPopHelper pph(lex, latexTypeTags);
1146 case Lexer::LEX_UNDEF:
1147 lex.printError("Unknown latextype tag `$$Token'");
1149 case LATEX_PARAGRAPH:
1151 case LATEX_ITEM_ENVIRONMENT:
1152 case LATEX_LIST_ENVIRONMENT:
1153 latextype = static_cast<LatexType>(le);
1155 case LATEX_ENVIRONMENT:
1156 case LATEX_BIB_ENVIRONMENT:
1157 latextype = static_cast<LatexType>(le);
1161 LYXERR0("Unhandled value " << le);
1167 void Layout::readSpacing(Lexer & lex)
1170 ST_SPACING_SINGLE = 1,
1176 LexerKeyword spacingTags[] = {
1177 {"double", ST_SPACING_DOUBLE },
1178 {"onehalf", ST_SPACING_ONEHALF },
1179 {"other", ST_OTHER },
1180 {"single", ST_SPACING_SINGLE }
1183 PushPopHelper pph(lex, spacingTags);
1186 case Lexer::LEX_UNDEF:
1187 lex.printError("Unknown spacing token `$$Token'");
1192 case ST_SPACING_SINGLE:
1193 spacing.set(Spacing::Single);
1195 case ST_SPACING_ONEHALF:
1196 spacing.set(Spacing::Onehalf);
1198 case ST_SPACING_DOUBLE:
1199 spacing.set(Spacing::Double);
1203 spacing.set(Spacing::Other, lex.getString());
1209 void Layout::readArgument(Lexer & lex, bool validating)
1212 LYXERR0("Unable to read argument ID!");
1215 string const id = lex.getString();
1217 bool const itemarg = prefixIs(id, "item:");
1218 bool const postcmd = prefixIs(id, "post:");
1219 bool const listpreamble = prefixIs(id, "listpreamble:");
1221 LaTeXArgMap & lam = itemarg ? itemargs_ :
1222 (postcmd ? postcommandargs_ :
1223 (listpreamble ? listpreamble_ :
1225 latexarg & arg = lam[id];
1228 // list preamble has no delimiters by default
1229 arg.nodelims = true;
1232 bool finished = false;
1233 while (!finished && lex.isOK() && !error) {
1235 string const tok = ascii_lowercase(lex.getString());
1239 } else if (tok == "endargument") {
1241 } else if (tok == "labelstring") {
1243 arg.labelstring = lex.getDocString();
1244 } else if (tok == "menustring") {
1246 arg.menustring = lex.getDocString();
1247 } else if (tok == "mandatory") {
1249 arg.mandatory = lex.getBool();
1250 } else if (tok == "autoinsert") {
1252 arg.autoinsert = lex.getBool();
1253 } else if (tok == "insertcotext") {
1255 arg.insertcotext = lex.getBool();
1256 } else if (tok == "leftdelim") {
1258 arg.ldelim = lex.getDocString();
1259 arg.ldelim = support::subst(arg.ldelim, from_ascii("<br/>"),
1261 } else if (tok == "rightdelim") {
1263 arg.rdelim = lex.getDocString();
1264 arg.rdelim = support::subst(arg.rdelim, from_ascii("<br/>"),
1266 } else if (tok == "defaultarg") {
1268 arg.defaultarg = lex.getDocString();
1269 } else if (tok == "presetarg") {
1271 arg.presetarg = lex.getDocString();
1272 } else if (tok == "tooltip") {
1274 arg.tooltip = lex.getDocString();
1275 } else if (tok == "requires") {
1277 arg.required = lex.getString();
1278 } else if (tok == "decoration") {
1280 arg.decoration = lex.getString();
1281 } else if (tok == "newlinecmd") {
1283 arg.newlinecmd = lex.getString();
1284 } else if (tok == "font") {
1285 arg.font = lyxRead(lex, arg.font);
1286 } else if (tok == "labelfont") {
1287 arg.labelfont = lyxRead(lex, arg.labelfont);
1288 } else if (tok == "passthruchars") {
1290 arg.pass_thru_chars = lex.getDocString();
1291 } else if (tok == "passthru") {
1293 docstring value = lex.getDocString();
1294 if (value == "true" || value == "1")
1295 arg.passthru = PT_TRUE;
1296 else if (value == "false" || value == "0")
1297 arg.passthru = PT_FALSE;
1299 arg.passthru = PT_INHERITED;
1300 } else if (tok == "istoccaption") {
1302 arg.is_toc_caption = lex.getBool();
1303 } else if (tok == "freespacing") {
1305 arg.free_spacing = lex.getBool();
1306 } else if (tok == "docbooktag") {
1308 arg.docbooktag = lex.getDocString();
1309 } else if (tok == "docbookattr") {
1311 arg.docbookattr = lex.getDocString();
1312 } else if (tok == "docbooktagtype") {
1314 arg.docbooktagtype = lex.getDocString();
1315 } else if (tok == "docbookargumentaftermaintag") {
1317 arg.docbookargumentaftermaintag = lex.getBool();
1318 } else if (tok == "docbookargumentbeforemaintag") {
1320 arg.docbookargumentbeforemaintag = lex.getBool();
1322 lex.printError("Unknown tag");
1326 if (!validating && arg.labelstring.empty()) {
1327 LYXERR0("Incomplete Argument definition!");
1328 // remove invalid definition
1334 void writeArgument(ostream & os, string const & id, Layout::latexarg const & arg)
1336 os << "\tArgument " << id << '\n';
1337 if (!arg.labelstring.empty())
1338 os << "\t\tLabelString \"" << to_utf8(arg.labelstring) << "\"\n";
1339 if (!arg.menustring.empty())
1340 os << "\t\tMenuString \"" << to_utf8(arg.menustring) << "\"\n";
1342 os << "\t\tMandatory " << arg.mandatory << '\n';
1344 os << "\t\tAutoinsert " << arg.autoinsert << '\n';
1345 if (arg.insertcotext)
1346 os << "\t\tInsertCotext " << arg.insertcotext << '\n';
1347 if (!arg.ldelim.empty())
1348 os << "\t\tLeftDelim \""
1349 << to_utf8(subst(arg.ldelim, from_ascii("\n"), from_ascii("<br/>")))
1351 if (!arg.rdelim.empty())
1352 os << "\t\tRightDelim \""
1353 << to_utf8(subst(arg.rdelim, from_ascii("\n"), from_ascii("<br/>")))
1355 if (!arg.defaultarg.empty())
1356 os << "\t\tDefaultArg \"" << to_utf8(arg.defaultarg) << "\"\n";
1357 if (!arg.presetarg.empty())
1358 os << "\t\tPresetArg \"" << to_utf8(arg.presetarg) << "\"\n";
1359 if (!arg.tooltip.empty())
1360 os << "\t\tToolTip \"" << to_utf8(arg.tooltip) << "\"\n";
1361 if (!arg.required.empty())
1362 os << "\t\tRequires " << arg.required << "\n";
1363 if (!arg.decoration.empty())
1364 os << "\t\tDecoration \"" << arg.decoration << "\"\n";
1365 if (!arg.newlinecmd.empty())
1366 os << "\t\tNewlineCmd \"" << arg.newlinecmd << "\"\n";
1367 if (arg.font != inherit_font)
1368 lyxWrite(os, arg.font, "Font", 2);
1369 if (arg.labelfont != inherit_font)
1370 lyxWrite(os, arg.labelfont, "LabelFont", 2);
1371 switch (arg.passthru) {
1373 os << "\t\tPassThru true\n";
1376 os << "\t\tPassThru false\n";
1379 os << "\t\tPassThru inherited\n";
1382 if (!arg.pass_thru_chars.empty())
1383 os << "\t\tPassThruChars \"" << to_utf8(arg.pass_thru_chars) << "\"\n";
1384 if (arg.free_spacing)
1385 os << "\t\tFreeSpacing " << arg.free_spacing << "\n";
1386 os << "\tEndArgument\n";
1390 void Layout::write(ostream & os) const
1392 os << "Style \"" << to_utf8(name_) << "\"\n";
1393 if (!category_.empty() && obsoleted_by_.empty())
1394 os << "\tCategory \"" << to_utf8(category_) << "\"\n";
1395 // Can't deduce Copystyle here :-(
1396 if (!obsoleted_by_.empty()) {
1397 os << "\tObsoletedBy \"" << to_utf8(obsoleted_by_)
1401 if (!depends_on_.empty())
1402 os << "\tDependsOn " << to_utf8(depends_on_) << '\n';
1403 switch (margintype) {
1404 case MARGIN_DYNAMIC:
1405 os << "\tMargin Dynamic\n";
1407 case MARGIN_FIRST_DYNAMIC:
1408 os << "\tMargin First_Dynamic\n";
1411 os << "\tMargin Manual\n";
1413 case MARGIN_RIGHT_ADDRESS_BOX:
1414 os << "\tMargin Right_Address_Box\n";
1417 os << "\tMargin Static\n";
1420 switch (latextype) {
1421 case LATEX_BIB_ENVIRONMENT:
1422 os << "\tLatexType Bib_Environment\n";
1425 os << "\tLatexType Command\n";
1427 case LATEX_ENVIRONMENT:
1428 os << "\tLatexType Environment\n";
1430 case LATEX_ITEM_ENVIRONMENT:
1431 os << "\tLatexType Item_Environment\n";
1433 case LATEX_LIST_ENVIRONMENT:
1434 os << "\tLatexType List_Environment\n";
1436 case LATEX_PARAGRAPH:
1437 os << "\tLatexType Paragraph\n";
1440 os << "\tInTitle " << intitle << "\n"
1441 "\tInPreamble " << inpreamble << "\n"
1442 "\tTocLevel " << toclevel << "\n"
1443 "\tResumeCounter " << resumecounter << "\n"
1444 "\tStepParentCounter " << stepparentcounter << '\n';
1445 // ResetArgs does not make sense here
1446 for (LaTeXArgMap::const_iterator it = latexargs_.begin();
1447 it != latexargs_.end(); ++it)
1448 writeArgument(os, it->first, it->second);
1449 for (LaTeXArgMap::const_iterator it = itemargs_.begin();
1450 it != itemargs_.end(); ++it)
1451 writeArgument(os, it->first, it->second);
1452 for (LaTeXArgMap::const_iterator it = postcommandargs_.begin();
1453 it != postcommandargs_.end(); ++it)
1454 writeArgument(os, it->first, it->second);
1455 for (LaTeXArgMap::const_iterator it = listpreamble_.begin();
1456 it != listpreamble_.end(); ++it)
1457 writeArgument(os, it->first, it->second);
1458 os << "\tNeedProtect " << needprotect << "\n"
1459 "\tNeedCProtect " << needcprotect << "\n"
1460 "\tNeedMBoxProtect " << needmboxprotect << "\n"
1461 "\tKeepEmpty " << keepempty << '\n';
1462 if (labelfont == font)
1463 lyxWrite(os, font, "Font", 1);
1465 lyxWrite(os, font, "TextFont", 1);
1466 lyxWrite(os, labelfont, "LabelFont", 1);
1468 os << "\tNextNoIndent " << nextnoindent << "\n"
1469 "\tCommandDepth " << commanddepth << '\n';
1470 if (!latexname_.empty())
1471 os << "\tLatexName \"" << latexname_ << "\"\n";
1472 if (!latexparam_.empty())
1473 os << "\tLatexParam \"" << subst(latexparam_, "\"", """)
1475 if (!leftdelim_.empty())
1476 os << "\tLeftDelim "
1477 << to_utf8(subst(leftdelim_, from_ascii("\n"), from_ascii("<br/>")))
1479 if (!rightdelim_.empty())
1480 os << "\tRightDelim "
1481 << to_utf8(subst(rightdelim_, from_ascii("\n"), from_ascii("<br/>")))
1483 if (!innertag_.empty())
1484 os << "\tInnerTag \"" << innertag_ << "\"\n";
1485 if (!labeltag_.empty())
1486 os << "\tLabelTag \"" << labeltag_ << "\"\n";
1487 if (!itemtag_.empty())
1488 os << "\tItemTag \"" << itemtag_ << "\"\n";
1489 if (!itemcommand_.empty())
1490 os << "\tItemCommand " << itemcommand_ << '\n';
1491 if (!preamble_.empty())
1492 os << "\tPreamble\n\t"
1493 << to_utf8(subst(rtrim(preamble_, "\n"),
1494 from_ascii("\n"), from_ascii("\n\t")))
1495 << "\n\tEndPreamble\n";
1496 if (!langpreamble_.empty())
1497 os << "\tLangPreamble\n\t"
1498 << to_utf8(subst(rtrim(langpreamble_, "\n"),
1499 from_ascii("\n"), from_ascii("\n\t")))
1500 << "\n\tEndLangPreamble\n";
1501 if (!babelpreamble_.empty())
1502 os << "\tBabelPreamble\n\t"
1503 << to_utf8(subst(rtrim(babelpreamble_, "\n"),
1504 from_ascii("\n"), from_ascii("\n\t")))
1505 << "\n\tEndBabelPreamble\n";
1506 switch (labeltype) {
1508 os << "\tLabelType Above\n";
1511 os << "\tLabelType Bibliography\n";
1513 case LABEL_CENTERED:
1514 os << "\tLabelType Centered\n";
1516 case LABEL_ENUMERATE:
1517 os << "\tLabelType Enumerate\n";
1520 os << "\tLabelType Itemize\n";
1523 os << "\tLabelType Manual\n";
1525 case LABEL_NO_LABEL:
1526 os << "\tLabelType No_Label\n";
1528 case LABEL_SENSITIVE:
1529 os << "\tLabelType Sensitive\n";
1532 os << "\tLabelType Static\n";
1535 switch (endlabeltype) {
1537 os << "\tEndLabelType Box\n";
1539 case END_LABEL_FILLED_BOX:
1540 os << "\tEndLabelType Filled_Box\n";
1542 case END_LABEL_NO_LABEL:
1543 os << "\tEndLabelType No_Label\n";
1545 case END_LABEL_STATIC:
1546 os << "\tEndLabelType Static\n";
1549 os << "\tParagraphGroup \"" << par_group_ << "\"\n";
1550 if (!leftmargin.empty())
1551 os << "\tLeftMargin \"" << to_utf8(leftmargin) << "\"\n";
1552 if (!rightmargin.empty())
1553 os << "\tRightMargin \"" << to_utf8(rightmargin) << "\"\n";
1554 if (!labelindent.empty())
1555 os << "\tLabelIndent " << to_utf8(labelindent) << '\n';
1556 if (!parindent.empty())
1557 os << "\tParIndent " << to_utf8(parindent) << '\n';
1558 os << "\tParSkip " << parskip << "\n"
1559 "\tItemSep " << itemsep << "\n"
1560 "\tTopSep " << topsep << "\n"
1561 "\tBottomSep " << bottomsep << "\n"
1562 "\tLabelBottomSep " << labelbottomsep << '\n';
1563 if (!labelsep.empty())
1564 os << "\tLabelSep " << to_utf8(subst(labelsep, ' ', 'x'))
1566 os << "\tParSep " << parsep << "\n"
1567 "\tNewLine " << newline_allowed << '\n';
1569 case LYX_ALIGN_BLOCK:
1570 os << "\tAlign Block\n";
1572 case LYX_ALIGN_CENTER:
1573 os << "\tAlign Center\n";
1575 case LYX_ALIGN_LAYOUT:
1576 os << "\tAlign Layout\n";
1578 case LYX_ALIGN_LEFT:
1579 os << "\tAlign Left\n";
1581 case LYX_ALIGN_RIGHT:
1582 os << "\tAlign Right\n";
1584 case LYX_ALIGN_DECIMAL:
1585 case LYX_ALIGN_SPECIAL:
1586 case LYX_ALIGN_NONE:
1589 if (alignpossible & (LYX_ALIGN_BLOCK | LYX_ALIGN_CENTER |
1590 LYX_ALIGN_LAYOUT | LYX_ALIGN_LEFT | LYX_ALIGN_RIGHT)) {
1592 os << "\tAlignPossible";
1593 if (alignpossible & LYX_ALIGN_BLOCK) {
1597 if (alignpossible & LYX_ALIGN_CENTER) {
1603 if (alignpossible & LYX_ALIGN_LAYOUT) {
1609 if (alignpossible & LYX_ALIGN_LEFT) {
1615 if (alignpossible & LYX_ALIGN_RIGHT) {
1623 // LabelString must come before LabelStringAppendix
1624 if (!labelstring_.empty())
1625 os << "\tLabelString \"" << to_utf8(labelstring_) << "\"\n";
1626 if (!endlabelstring_.empty())
1627 os << "\tEndLabelString \"" << to_utf8(endlabelstring_) << "\"\n";
1628 if (!labelstring_appendix_.empty() && labelstring_appendix_ != labelstring_)
1629 os << "\tLabelStringAppendix \""
1630 << to_utf8(labelstring_appendix_) << "\"\n";
1631 if (!counter.empty())
1632 os << "\tLabelCounter \"" << to_utf8(counter) << "\"\n";
1633 os << "\tFreeSpacing " << free_spacing << '\n';
1634 os << "\tPassThru " << pass_thru << '\n';
1635 if (!pass_thru_chars.empty())
1636 os << "\tPassThruChars " << to_utf8(pass_thru_chars) << '\n';
1637 os << "\tParbreakIsNewline " << parbreak_is_newline << '\n';
1638 switch (spacing.getSpace()) {
1639 case Spacing::Double:
1640 os << "\tSpacing Double\n";
1642 case Spacing::Onehalf:
1643 os << "\tSpacing Onehalf\n";
1645 case Spacing::Other:
1646 os << "\tSpacing Other " << spacing.getValueAsString() << '\n';
1648 case Spacing::Single:
1649 os << "\tSpacing Single\n";
1651 case Spacing::Default:
1654 if (!required_.empty()) {
1655 os << "\tRequires ";
1656 for (set<string>::const_iterator it = required_.begin();
1657 it != required_.end(); ++it) {
1658 if (it != required_.begin())
1664 if (!autonests_.empty()) {
1665 os << "\tAutoNests\n\t";
1666 for (set<docstring>::const_iterator it = autonests_.begin();
1667 it != autonests_.end(); ++it) {
1668 if (it != autonests_.begin())
1672 os << "\n\tEndAutoNests\n";
1674 if (!autonested_by_.empty()) {
1675 os << "\tIsAutoNestedBy\n\t\t";
1676 for (set<docstring>::const_iterator it = autonested_by_.begin();
1677 it != autonested_by_.end(); ++it) {
1678 if (it != autonested_by_.begin())
1682 os << "\n\tEndIsAutoNestedBy\n";
1684 if (refprefix.empty())
1685 os << "\tRefPrefix OFF\n";
1687 os << "\tRefPrefix " << to_utf8(refprefix) << '\n';
1688 if (!htmltag_.empty())
1689 os << "\tHTMLTag " << htmltag_ << '\n';
1690 if (!htmlattr_.empty())
1691 os << "\tHTMLAttr " << htmlattr_ << '\n';
1692 if (!htmlclass_.empty())
1693 os << "\tHTMLClass " << htmlclass_ << '\n';
1695 os << "\tHTMLInToc " << htmlintoc_ << '\n';
1696 if (!htmlitemtag_.empty())
1697 os << "\tHTMLItem " << htmlitemtag_ << '\n';
1698 if (!htmlitemattr_.empty())
1699 os << "\tHTMLItemAttr " << htmlitemattr_ << '\n';
1700 if (!htmllabeltag_.empty())
1701 os << "\tHTMLLabel " << htmllabeltag_ << '\n';
1702 if (!htmllabelattr_.empty())
1703 os << "\tHTMLLabelAttr " << htmllabelattr_ << '\n';
1704 os << "\tHTMLLabelFirst " << htmllabelfirst_ << '\n';
1705 if (!htmlstyle_.empty())
1706 os << "\tHTMLStyle\n"
1707 << to_utf8(rtrim(htmlstyle_, "\n"))
1708 << "\n\tEndHTMLStyle\n";
1709 os << "\tHTMLForceCSS " << htmlforcecss_ << '\n';
1710 if (!htmlpreamble_.empty())
1711 os << "\tHTMLPreamble\n"
1712 << to_utf8(rtrim(htmlpreamble_, "\n"))
1713 << "\n\tEndPreamble\n";
1714 os << "\tHTMLTitle " << htmltitle_ << "\n";
1715 if (!docbooktag_.empty())
1716 os << "\tDocBookTag " << docbooktag_ << '\n';
1717 if (!docbookattr_.empty())
1718 os << "\tDocBookAttr \"" << docbookattr_ << "\"\n";
1719 if (!docbooktagtype_.empty())
1720 os << "\tDocBookTagType " << docbooktagtype_ << '\n';
1721 if (!docbookinnertag_.empty())
1722 os << "\tDocBookInnerTag " << docbookinnertag_ << '\n';
1723 if (!docbookinnerattr_.empty())
1724 os << "\tDocBookInnerAttr \"" << docbookinnerattr_ << "\"\n";
1725 if (!docbookinnertagtype_.empty())
1726 os << "\tDocBookInnerTagType " << docbookinnertagtype_ << '\n';
1727 if (!docbookininfo_.empty())
1728 os << "\tDocBookInInfo " << docbookininfo_ << '\n';
1729 os << "\tDocBookAbstract " << docbookabstract_ << '\n';
1730 if (!docbookwrappertag_.empty())
1731 os << "\tDocBookWrapperTag " << docbookwrappertag_ << '\n';
1732 if (!docbookwrapperattr_.empty())
1733 os << "\tDocBookWrapperAttr " << docbookwrapperattr_ << '\n';
1734 if (!docbookwrappertagtype_.empty())
1735 os << "\tDocBookWrapperTagType " << docbookwrappertagtype_ << '\n';
1736 os << "\tDocBookSection " << docbooksection_ << '\n';
1737 if (!docbooksectiontag_.empty())
1738 os << "\tDocBookSectionTag " << docbooksectiontag_ << '\n';
1739 if (!docbookitemtag_.empty())
1740 os << "\tDocBookItemTag " << docbookitemtag_ << '\n';
1741 if (!docbookitemattr_.empty())
1742 os << "\tDocBookItemAttr " << docbookitemattr_ << '\n';
1743 if (!docbookitemtagtype_.empty())
1744 os << "\tDocBookItemTagType " << docbookitemtagtype_ << '\n';
1745 if (!docbookitemwrappertag_.empty())
1746 os << "\tDocBookItemWrapperTag " << docbookitemwrappertag_ << '\n';
1747 if (!docbookitemwrapperattr_.empty())
1748 os << "\tDocBookItemWrapperAttr " << docbookitemwrapperattr_ << '\n';
1749 if (!docbookitemwrappertagtype_.empty())
1750 os << "\tDocBookItemWrapperTagType " << docbookitemwrappertagtype_ << '\n';
1751 os << "\tDocBookWrapperMergeWithPrevious " << docbookwrappermergewithprevious_ << '\n';
1752 if (!docbookitemlabeltag_.empty())
1753 os << "\tDocBookItemLabelTag " << docbookitemlabeltag_ << '\n';
1754 if (!docbookitemlabelattr_.empty())
1755 os << "\tDocBookItemLabelAttr " << docbookitemlabelattr_ << '\n';
1756 if (!docbookitemlabeltagtype_.empty())
1757 os << "\tDocBookItemLabelTagType " << docbookitemlabeltagtype_ << '\n';
1758 if (!docbookiteminnertag_.empty())
1759 os << "\tDocBookItemInnerTag " << docbookiteminnertag_ << '\n';
1760 if (!docbookiteminnerattr_.empty())
1761 os << "\tDocBookItemInnerAttr " << docbookiteminnerattr_ << '\n';
1762 if (!docbookiteminnertagtype_.empty())
1763 os << "\tDocBookItemInnerTagType " << docbookiteminnertagtype_ << '\n';
1764 if (!docbookforceabstracttag_.empty())
1765 os << "\tDocBookForceAbstractTag " << docbookforceabstracttag_ << '\n';
1766 os << "\tDocBookNoFontInside " << docbooknofontinside_ << "\n"
1767 "\tSpellcheck " << spellcheck << "\n"
1768 "\tForceLocal " << forcelocal << "\n"
1773 bool Layout::hasArgs() const
1775 return !latexargs_.empty() || !postcommandargs_.empty() ||
1776 !itemargs_.empty() || !listpreamble_.empty();
1780 Layout::LaTeXArgMap Layout::args() const
1782 LaTeXArgMap args = latexargs_;
1783 if (!postcommandargs_.empty())
1784 args.insert(postcommandargs_.begin(), postcommandargs_.end());
1785 if (!listpreamble_.empty())
1786 args.insert(listpreamble_.begin(), listpreamble_.end());
1787 if (!itemargs_.empty())
1788 args.insert(itemargs_.begin(), itemargs_.end());
1793 int Layout::optArgs() const
1796 LaTeXArgMap::const_iterator it = latexargs_.begin();
1797 for (; it != latexargs_.end(); ++it) {
1798 if (!(*it).second.mandatory)
1801 LaTeXArgMap::const_iterator iit = postcommandargs_.begin();
1802 for (; iit != postcommandargs_.end(); ++iit) {
1803 if (!(*iit).second.mandatory)
1810 int Layout::requiredArgs() const
1813 LaTeXArgMap::const_iterator it = latexargs_.begin();
1814 for (; it != latexargs_.end(); ++it) {
1815 if ((*it).second.mandatory)
1818 LaTeXArgMap::const_iterator iit = postcommandargs_.begin();
1819 for (; iit != postcommandargs_.end(); ++iit) {
1820 if (!(*iit).second.mandatory)
1827 string const & Layout::htmltag() const
1829 if (htmltag_.empty())
1835 string const & Layout::htmlclass() const
1837 // If it's an enumeration or itemize list, then we recalculate the class each
1838 // time through (unless it has been given explicitly). So we do nothing here.
1839 if (htmlclass_.empty() && labeltype != LABEL_ENUMERATE && labeltype != LABEL_ITEMIZE)
1840 htmlclass_ = defaultCSSClass();
1845 string const & Layout::htmlGetAttrString() const {
1846 if (!htmlfullattrs_.empty())
1847 return htmlfullattrs_;
1848 htmlfullattrs_ = htmlclass();
1849 if (!htmlfullattrs_.empty())
1850 htmlfullattrs_ = "class='" + htmlfullattrs_ + "'";
1851 if (!htmlattr_.empty())
1852 htmlfullattrs_ += " " + htmlattr_;
1853 return htmlfullattrs_;
1857 string const & Layout::htmlitemtag() const
1859 if (htmlitemtag_.empty())
1860 htmlitemtag_ = "div";
1861 return htmlitemtag_;
1865 string const & Layout::htmlitemattr() const
1867 if (htmlitemattr_.empty())
1868 htmlitemattr_ = "class=\"" + defaultCSSItemClass() + "\"";
1869 return htmlitemattr_;
1873 string const & Layout::htmllabeltag() const
1875 if (htmllabeltag_.empty())
1876 htmllabeltag_ = "span";
1877 return htmllabeltag_;
1881 string const & Layout::htmllabelattr() const
1883 if (htmllabelattr_.empty())
1884 htmllabelattr_ = "class=\"" + defaultCSSLabelClass() + "\"";
1885 return htmllabelattr_;
1889 docstring Layout::htmlstyle() const
1891 if (!htmlstyle_.empty() && !htmlforcecss_)
1893 if (htmldefaultstyle_.empty())
1895 docstring retval = htmldefaultstyle_;
1896 if (!htmlstyle_.empty())
1897 retval += '\n' + htmlstyle_;
1902 string Layout::defaultCSSClass() const
1904 if (!defaultcssclass_.empty())
1905 return defaultcssclass_;
1907 docstring::const_iterator it = name().begin();
1908 docstring::const_iterator en = name().end();
1909 for (; it != en; ++it) {
1910 char_type const c = *it;
1911 if (!isAlphaASCII(c)) {
1913 // make sure we don't start with an underscore,
1914 // as that sometimes causes problems.
1915 d = from_ascii("lyx_");
1918 } else if (isLower(c))
1921 // this is slow, so do it only if necessary
1924 defaultcssclass_ = to_utf8(d);
1925 return defaultcssclass_;
1929 string const & Layout::docbooktag() const
1931 if (docbooktag_.empty()) {
1932 if (to_ascii(name_) == "Plain Layout")
1933 docbooktag_ = "para";
1934 else // No sensible default value, unhappily...
1935 docbooktag_ = to_utf8(name_);
1941 string const & Layout::docbookattr() const
1943 // Perfectly OK to return no attributes, so docbookattr_ does not need to be filled.
1944 return docbookattr_;
1948 bool isValidTagType(std::string const & type)
1950 return !(type.empty() || (type != "block" && type != "paragraph" && type != "inline"));
1954 string const & Layout::docbooktagtype() const
1956 if (!isValidTagType(docbooktagtype_))
1957 docbooktagtype_ = "block";
1958 return docbooktagtype_;
1962 string const & Layout::docbookinnertag() const
1964 if (docbookinnertag_.empty())
1965 docbookinnertag_ = "NONE";
1966 return docbookinnertag_;
1970 string const & Layout::docbookinnerattr() const
1972 return docbookinnerattr_;
1976 string const & Layout::docbookinnertagtype() const
1978 if (!isValidTagType(docbookinnertagtype_))
1979 docbookinnertagtype_ = "block";
1980 return docbookinnertagtype_;
1984 string const & Layout::docbookininfo() const
1986 // Indeed, a trilean. Only titles should be "maybe": otherwise, metadata is "always", content is "never".
1987 if (docbookininfo_.empty() || (docbookininfo_ != "never" && docbookininfo_ != "always" && docbookininfo_ != "maybe"))
1988 docbookininfo_ = "never";
1989 return docbookininfo_;
1993 string const & Layout::docbookwrappertag() const
1995 if (docbookwrappertag_.empty())
1996 docbookwrappertag_ = "NONE";
1997 return docbookwrappertag_;
2001 string const & Layout::docbookwrapperattr() const
2003 return docbookwrapperattr_;
2007 string const & Layout::docbookwrappertagtype() const
2009 if (!isValidTagType(docbookwrappertagtype_))
2010 docbookwrappertagtype_ = "block";
2011 return docbookwrappertagtype_;
2015 string const & Layout::docbooksectiontag() const
2017 if (docbooksectiontag_.empty())
2018 docbooksectiontag_ = "section";
2019 return docbooksectiontag_;
2023 string const & Layout::docbookitemwrappertag() const
2025 if (docbookitemwrappertag_.empty())
2026 docbookitemwrappertag_ = "NONE";
2027 return docbookitemwrappertag_;
2031 string const & Layout::docbookitemwrapperattr() const
2033 return docbookitemwrapperattr_;
2037 string const & Layout::docbookitemwrappertagtype() const
2039 if (!isValidTagType(docbookitemwrappertagtype_))
2040 docbookitemwrappertagtype_ = "block";
2041 return docbookitemwrappertagtype_;
2045 string const & Layout::docbookitemtag() const
2047 if (docbookitemtag_.empty())
2048 docbookitemtag_ = "NONE";
2049 return docbookitemtag_;
2053 string const & Layout::docbookitemattr() const
2055 return docbookitemattr_;
2059 string const & Layout::docbookitemtagtype() const
2061 if (!isValidTagType(docbookitemtagtype_))
2062 docbookitemtagtype_ = "block";
2063 return docbookitemtagtype_;
2067 string const & Layout::docbookitemlabeltag() const
2069 if (docbookitemlabeltag_.empty())
2070 docbookitemlabeltag_ = "NONE";
2071 return docbookitemlabeltag_;
2075 string const & Layout::docbookitemlabelattr() const
2077 return docbookitemlabelattr_;
2081 string const & Layout::docbookitemlabeltagtype() const
2083 if (!isValidTagType(docbookitemlabeltagtype_))
2084 docbookitemlabeltagtype_ = "block";
2085 return docbookitemlabeltagtype_;
2089 string const & Layout::docbookiteminnertag() const
2091 if (docbookiteminnertag_.empty())
2092 docbookiteminnertag_ = "NONE";
2093 return docbookiteminnertag_;
2097 string const & Layout::docbookiteminnerattr() const
2099 return docbookiteminnerattr_;
2103 string const & Layout::docbookiteminnertagtype() const
2105 if (!isValidTagType(docbookiteminnertagtype_))
2106 docbookiteminnertagtype_ = "block";
2107 return docbookiteminnertagtype_;
2111 std::string const & Layout::docbookforceabstracttag() const
2113 if (docbookforceabstracttag_.empty())
2114 docbookforceabstracttag_ = "NONE";
2115 return docbookforceabstracttag_;
2122 string makeMarginValue(char const * side, double d)
2125 os << "margin-" << side << ": " << d << "ex;\n";
2132 void Layout::makeDefaultCSS() const
2134 // this never needs to be redone, since reloading layouts will
2135 // wipe out what we did before.
2136 if (!htmldefaultstyle_.empty())
2140 htmldefaultstyle_ = font.asCSS();
2145 tmp += makeMarginValue("top", topsep);
2147 tmp += makeMarginValue("bottom", bottomsep);
2148 if (!leftmargin.empty()) {
2149 // we can't really do what LyX does with the margin, so
2150 // we'll just figure out how many characters it is
2151 int const len = leftmargin.length();
2152 tmp += makeMarginValue("left", len);
2154 if (!rightmargin.empty()) {
2155 int const len = rightmargin.length();
2156 tmp += makeMarginValue("right", len);
2160 if (!htmldefaultstyle_.empty())
2161 htmldefaultstyle_ += from_ascii("\n");
2162 htmldefaultstyle_ += from_ascii(tmp);
2166 string where = alignmentToCSS(align);
2167 if (!where.empty()) {
2168 htmldefaultstyle_ += from_ascii("text-align: " + where + ";\n");
2171 // wrap up what we have, if anything
2172 if (!htmldefaultstyle_.empty())
2174 from_ascii(htmltag() + "." + defaultCSSClass() + " {\n") +
2175 htmldefaultstyle_ + from_ascii("\n}\n");
2177 if (labeltype == LABEL_NO_LABEL || htmllabeltag() == "NONE")
2183 if (labelfont != font)
2184 labelCSS = labelfont.asCSS() + from_ascii("\n");
2185 if (labeltype == LABEL_CENTERED)
2186 labelCSS += from_ascii("text-align: center;\n");
2188 if (!labelCSS.empty())
2189 htmldefaultstyle_ +=
2190 from_ascii(htmllabeltag() + "." + defaultCSSLabelClass() + " {\n") +
2191 labelCSS + from_ascii("\n}\n");
2195 bool Layout::operator==(Layout const & rhs) const
2197 // This is enough for the applications we actually make,
2198 // at least at the moment. But we could check more.
2199 return name() == rhs.name()
2200 && latexname() == rhs.latexname()
2201 && latextype == rhs.latextype;