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.
19 #include "output_xhtml.h"
20 #include "TextClass.h"
22 #include "support/debug.h"
23 #include "support/lassert.h"
24 #include "support/lstrings.h"
25 #include "support/Messages.h"
26 #include "support/textutils.h"
30 using namespace lyx::support;
34 /// Special value of toclevel for layouts that do not belong to a TOC
35 const int Layout::NOT_IN_TOC = -1000;
37 // The order of the LayoutTags enum is no more important. [asierra300396]
57 LT_PARBREAK_IS_NEWLINE,
67 LT_LABELSTRING_APPENDIX,
112 LT_DOCBOOKWRAPPERTAG,
113 LT_DOCBOOKWRAPPERATTR,
114 LT_DOCBOOKWRAPPERTAGTYPE,
115 LT_DOCBOOKWRAPPERMERGEWITHPREVIOUS,
116 LT_DOCBOOKSECTIONTAG,
117 LT_DOCBOOKITEMWRAPPERTAG,
118 LT_DOCBOOKITEMWRAPPERATTR,
119 LT_DOCBOOKITEMWRAPPERTAGTYPE,
122 LT_DOCBOOKITEMTAGTYPE,
123 LT_DOCBOOKITEMLABELTAG,
124 LT_DOCBOOKITEMLABELATTR,
125 LT_DOCBOOKITEMLABELTAGTYPE,
126 LT_DOCBOOKITEMINNERTAG,
127 LT_DOCBOOKITEMINNERATTR,
128 LT_DOCBOOKITEMINNERTAGTYPE,
129 LT_DOCBOOKFORCEABSTRACTTAG,
136 LT_STEPMASTERCOUNTER,
142 LT_INTITLE // keep this last!
145 /////////////////////
148 : add_to_toc_(false), is_toc_caption_(true)
151 margintype = MARGIN_STATIC;
152 latextype = LATEX_PARAGRAPH;
153 resumecounter = false;
154 stepmastercounter = false;
158 needcprotect = false;
159 needmboxprotect = false;
162 labelfont = inherit_font;
164 reslabelfont = sane_font;
165 nextnoindent = false;
170 labelbottomsep = 0.0;
172 align = LYX_ALIGN_BLOCK;
173 alignpossible = LYX_ALIGN_NONE | LYX_ALIGN_LAYOUT;
174 labeltype = LABEL_NO_LABEL;
175 endlabeltype = END_LABEL_NO_LABEL;
176 // Should or should not. That is the question.
177 // spacing.set(Spacing::OneHalf);
178 newline_allowed = true;
179 free_spacing = false;
181 parbreak_is_newline = false;
182 toclevel = NOT_IN_TOC;
184 htmllabelfirst_ = false;
185 htmlforcecss_ = false;
187 docbookabstract_ = false;
188 docbookwrappermergewithprevious_ = false;
191 itemcommand_ = "item";
192 toggle_indent = ITOGGLE_DOCUMENT_DEFAULT;
197 bool Layout::read(Lexer & lex, TextClass const & tclass)
199 // If this is an empty layout, or if no force local version is set,
200 // we know that we will not discard the stuff to read
202 return readIgnoreForcelocal(lex, tclass);
205 bool const ret = tmp.readIgnoreForcelocal(lex, tclass);
207 // - the read version is higher
208 // - both versions are infinity (arbitrary decision)
209 // - the file did not contain any local version (needed for not
210 // skipping user defined local layouts)
211 if (tmp.forcelocal <= 0 || tmp.forcelocal > forcelocal)
217 bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass)
219 // This table is sorted alphabetically [asierra 30March96]
220 LexerKeyword layoutTags[] = {
221 { "addtotoc", LT_ADDTOTOC },
222 { "align", LT_ALIGN },
223 { "alignpossible", LT_ALIGNPOSSIBLE },
224 { "argument", LT_ARGUMENT },
225 { "autonests", LT_AUTONESTS },
226 { "babelpreamble", LT_BABELPREAMBLE },
227 { "bottomsep", LT_BOTTOMSEP },
228 { "category", LT_CATEGORY },
229 { "commanddepth", LT_COMMANDDEPTH },
230 { "copystyle", LT_COPYSTYLE },
231 { "dependson", LT_DEPENDSON },
232 { "docbookabstract", LT_DOCBOOKABSTRACT },
233 { "docbookattr", LT_DOCBOOKATTR },
234 { "docbookforceabstracttag", LT_DOCBOOKFORCEABSTRACTTAG },
235 { "docbookininfo", LT_DOCBOOKININFO },
236 { "docbookitemattr", LT_DOCBOOKITEMATTR },
237 { "docbookiteminnerattr", LT_DOCBOOKITEMINNERATTR },
238 { "docbookiteminnertag", LT_DOCBOOKITEMINNERTAG },
239 { "docbookiteminnertagtype", LT_DOCBOOKITEMINNERTAGTYPE },
240 { "docbookitemlabelattr", LT_DOCBOOKITEMLABELATTR },
241 { "docbookitemlabeltag", LT_DOCBOOKITEMLABELTAG },
242 { "docbookitemlabeltagtype", LT_DOCBOOKITEMLABELTAGTYPE },
243 { "docbookitemtag", LT_DOCBOOKITEMTAG },
244 { "docbookitemtagtype", LT_DOCBOOKITEMTAGTYPE },
245 { "docbookitemwrapperattr", LT_DOCBOOKITEMWRAPPERATTR },
246 { "docbookitemwrappertag", LT_DOCBOOKITEMWRAPPERTAG },
247 { "docbookitemwrappertagtype", LT_DOCBOOKITEMWRAPPERTAGTYPE },
248 { "docbooksectiontag", LT_DOCBOOKSECTIONTAG },
249 { "docbooktag", LT_DOCBOOKTAG },
250 { "docbooktagtype", LT_DOCBOOKTAGTYPE },
251 { "docbookwrapperattr", LT_DOCBOOKWRAPPERATTR },
252 { "docbookwrappermergewithprevious", LT_DOCBOOKWRAPPERMERGEWITHPREVIOUS },
253 { "docbookwrappertag", LT_DOCBOOKWRAPPERTAG },
254 { "docbookwrappertagtype", LT_DOCBOOKWRAPPERTAGTYPE },
256 { "endlabelstring", LT_ENDLABELSTRING },
257 { "endlabeltype", LT_ENDLABELTYPE },
259 { "forcelocal", LT_FORCELOCAL },
260 { "freespacing", LT_FREE_SPACING },
261 { "htmlattr", LT_HTMLATTR },
262 { "htmlforcecss", LT_HTMLFORCECSS },
263 { "htmlitem", LT_HTMLITEM },
264 { "htmlitemattr", LT_HTMLITEMATTR },
265 { "htmllabel", LT_HTMLLABEL },
266 { "htmllabelattr", LT_HTMLLABELATTR },
267 { "htmllabelfirst", LT_HTMLLABELFIRST },
268 { "htmlpreamble", LT_HTMLPREAMBLE },
269 { "htmlstyle", LT_HTMLSTYLE },
270 { "htmltag", LT_HTMLTAG },
271 { "htmltitle", LT_HTMLTITLE },
272 { "innertag", LT_INNERTAG },
273 { "inpreamble", LT_INPREAMBLE },
274 { "intitle", LT_INTITLE },
275 { "isautonestedby", LT_AUTONESTEDBY },
276 { "istoccaption", LT_ISTOCCAPTION },
277 { "itemcommand", LT_ITEMCOMMAND },
278 { "itemsep", LT_ITEMSEP },
279 { "itemtag", LT_ITEMTAG },
280 { "keepempty", LT_KEEPEMPTY },
281 { "labelbottomsep", LT_LABEL_BOTTOMSEP },
282 { "labelcounter", LT_LABELCOUNTER },
283 { "labelfont", LT_LABELFONT },
284 { "labelindent", LT_LABELINDENT },
285 { "labelsep", LT_LABELSEP },
286 { "labelstring", LT_LABELSTRING },
287 { "labelstringappendix", LT_LABELSTRING_APPENDIX },
288 { "labeltag", LT_LABELTAG },
289 { "labeltype", LT_LABELTYPE },
290 { "langpreamble", LT_LANGPREAMBLE },
291 { "latexname", LT_LATEXNAME },
292 { "latexparam", LT_LATEXPARAM },
293 { "latextype", LT_LATEXTYPE },
294 { "leftdelim", LT_LEFTDELIM },
295 { "leftmargin", LT_LEFTMARGIN },
296 { "margin", LT_MARGIN },
297 { "needcprotect", LT_NEED_CPROTECT },
298 { "needmboxprotect", LT_NEED_MBOXPROTECT },
299 { "needprotect", LT_NEED_PROTECT },
300 { "newline", LT_NEWLINE },
301 { "nextnoindent", LT_NEXTNOINDENT },
302 { "obsoletedby", LT_OBSOLETEDBY },
303 { "paragraphgroup", LT_PAR_GROUP },
304 { "parbreakisnewline", LT_PARBREAK_IS_NEWLINE },
305 { "parindent", LT_PARINDENT },
306 { "parsep", LT_PARSEP },
307 { "parskip", LT_PARSKIP },
308 { "passthru", LT_PASS_THRU },
309 { "passthruchars", LT_PASS_THRU_CHARS },
310 { "preamble", LT_PREAMBLE },
311 { "refprefix", LT_REFPREFIX },
312 { "requires", LT_REQUIRES },
313 { "resetargs", LT_RESETARGS },
314 { "resumecounter", LT_RESUMECOUNTER },
315 { "rightdelim", LT_RIGHTDELIM },
316 { "rightmargin", LT_RIGHTMARGIN },
317 { "spacing", LT_SPACING },
318 { "spellcheck", LT_SPELLCHECK },
319 { "stepmastercounter", LT_STEPMASTERCOUNTER },
320 { "textfont", LT_TEXTFONT },
321 { "toclevel", LT_TOCLEVEL },
322 { "toggleindent", LT_TOGGLE_INDENT },
323 { "topsep", LT_TOPSEP }
327 bool finished = false;
328 lex.pushTable(layoutTags);
330 // parse style section
331 while (!finished && lex.isOK() && !error) {
333 // See comment in LyXRC.cpp.
335 case Lexer::LEX_FEOF:
338 case Lexer::LEX_UNDEF:
340 lex.printError("Unknown layout tag `$$Token'");
347 switch (static_cast<LayoutTags>(le)) {
359 style = subst(style, '_', ' ');
361 if (tclass.hasLayout(style)) {
362 docstring const tmpname = name_;
363 this->operator=(tclass[style]);
366 LYXERR0("Cannot copy unknown style `"
368 << "All layouts so far:");
369 DocumentClass::const_iterator lit = tclass.begin();
370 DocumentClass::const_iterator len = tclass.end();
371 for (; lit != len; ++lit)
372 LYXERR0(lit->name());
377 case LT_OBSOLETEDBY: {
380 style = subst(style, '_', ' ');
382 if (tclass.hasLayout(style)) {
383 docstring const tmpname = name_;
384 this->operator=(tclass[style]);
386 if (obsoleted_by().empty())
387 obsoleted_by_ = style;
389 LYXERR0("Cannot replace with unknown style `"
392 //lex.printError("Cannot replace with"
401 depends_on_ = subst(depends_on_, '_', ' ');
430 postcommandargs_.clear();
431 listpreamble_.clear();
435 case LT_RESUMECOUNTER:
436 lex >> resumecounter;
439 case LT_STEPMASTERCOUNTER:
440 lex >> stepmastercounter;
447 case LT_NEED_PROTECT:
451 case LT_NEED_CPROTECT:
455 case LT_NEED_MBOXPROTECT:
456 lex >> needmboxprotect;
464 font = lyxRead(lex, font);
469 font = lyxRead(lex, font);
473 labelfont = lyxRead(lex, labelfont);
476 case LT_NEXTNOINDENT:
480 case LT_TOGGLE_INDENT: {
483 tog = support::ascii_lowercase(tog);
485 toggle_indent = ITOGGLE_ALWAYS;
486 else if (tog == "never")
487 toggle_indent = ITOGGLE_NEVER;
489 toggle_indent = ITOGGLE_DOCUMENT_DEFAULT;
493 case LT_COMMANDDEPTH:
503 latexparam_ = subst(latexparam_, """, "\"");
508 leftdelim_ = support::subst(leftdelim_, from_ascii("<br/>"),
514 rightdelim_ = support::subst(rightdelim_, from_ascii("<br/>"),
535 preamble_ = lex.getLongString(from_ascii("EndPreamble"));
538 case LT_LANGPREAMBLE:
539 langpreamble_ = lex.getLongString(from_ascii("EndLangPreamble"));
542 case LT_BABELPREAMBLE:
543 babelpreamble_ = lex.getLongString(from_ascii("EndBabelPreamble"));
550 case LT_ENDLABELTYPE:
551 readEndLabelType(lex);
586 case LT_LABEL_BOTTOMSEP:
587 lex >> labelbottomsep;
592 labelsep = subst(labelsep, 'x', ' ');
600 lex >> newline_allowed;
607 case LT_ALIGNPOSSIBLE:
608 readAlignPossible(lex);
612 // FIXME: this means LT_LABELSTRING_APPENDIX may only
613 // occur after LT_LABELSTRING
615 labelstring_appendix_ = labelstring_;
618 case LT_ENDLABELSTRING:
619 lex >> endlabelstring_;
622 case LT_LABELSTRING_APPENDIX:
623 lex >> labelstring_appendix_;
626 case LT_LABELCOUNTER:
634 case LT_FREE_SPACING:
642 case LT_PASS_THRU_CHARS:
643 lex >> pass_thru_chars;
646 case LT_PARBREAK_IS_NEWLINE:
647 lex >> parbreak_is_newline;
656 vector<string> const req =
657 getVectorFromString(lex.getString(true));
658 required_.insert(req.begin(), req.end());
663 docstring autonest = lex.getLongString(from_ascii("EndAutoNests"));
664 autonest = subst(autonest, from_ascii("\n"), docstring());
665 autonest = subst(autonest, from_ascii("\t"), docstring());
666 autonest = subst(autonest, from_ascii("\""), docstring());
667 autonest = subst(autonest, '_', ' ');
668 vector<docstring> const autonests =
669 getVectorFromString(autonest, from_ascii(","), false, true);
670 autonests_.insert(autonests.begin(), autonests.end());
674 case LT_AUTONESTEDBY: {
675 docstring autonest = lex.getLongString(from_ascii("EndIsAutoNestedBy"));
676 autonest = subst(autonest, from_ascii("\n"), docstring());
677 autonest = subst(autonest, from_ascii("\t"), docstring());
678 autonest = subst(autonest, from_ascii("\""), docstring());
679 autonest = subst(autonest, '_', ' ');
680 vector<docstring> const autonests =
681 getVectorFromString(autonest, from_ascii(","), false, true);
682 autonested_by_.insert(autonests.begin(), autonests.end());
708 case LT_HTMLITEMATTR:
709 lex >> htmlitemattr_;
713 lex >> htmllabeltag_;
716 case LT_HTMLLABELATTR:
717 lex >> htmllabelattr_;
720 case LT_HTMLLABELFIRST:
721 lex >> htmllabelfirst_;
725 htmlstyle_ = lex.getLongString(from_ascii("EndHTMLStyle"));
728 case LT_HTMLFORCECSS:
729 lex >> htmlforcecss_;
732 case LT_HTMLPREAMBLE:
733 htmlpreamble_ = lex.getLongString(from_ascii("EndPreamble"));
748 case LT_DOCBOOKTAGTYPE:
749 lex >> docbooktagtype_;
752 case LT_DOCBOOKFORCEABSTRACTTAG:
753 lex >> docbookforceabstracttag_;
756 case LT_DOCBOOKININFO:
757 lex >> docbookininfo_;
760 case LT_DOCBOOKABSTRACT:
761 lex >> docbookabstract_;
764 case LT_DOCBOOKWRAPPERTAG:
765 lex >> docbookwrappertag_;
768 case LT_DOCBOOKWRAPPERATTR:
769 lex >> docbookwrapperattr_;
772 case LT_DOCBOOKWRAPPERTAGTYPE:
773 lex >> docbookwrappertagtype_;
776 case LT_DOCBOOKWRAPPERMERGEWITHPREVIOUS:
777 lex >> docbookwrappermergewithprevious_;
780 case LT_DOCBOOKSECTIONTAG:
781 lex >> docbooksectiontag_;
784 case LT_DOCBOOKITEMWRAPPERTAG:
785 lex >> docbookitemwrappertag_;
788 case LT_DOCBOOKITEMWRAPPERATTR:
789 lex >> docbookitemwrapperattr_;
792 case LT_DOCBOOKITEMWRAPPERTAGTYPE:
793 lex >> docbookitemwrappertagtype_;
796 case LT_DOCBOOKITEMTAG:
797 lex >> docbookitemtag_;
800 case LT_DOCBOOKITEMATTR:
801 lex >> docbookitemattr_;
804 case LT_DOCBOOKITEMTAGTYPE:
805 lex >> docbookitemtagtype_;
808 case LT_DOCBOOKITEMLABELTAG:
809 lex >> docbookitemlabeltag_;
812 case LT_DOCBOOKITEMLABELATTR:
813 lex >> docbookitemlabelattr_;
816 case LT_DOCBOOKITEMLABELTAGTYPE:
817 lex >> docbookitemlabeltagtype_;
820 case LT_DOCBOOKITEMINNERTAG:
821 lex >> docbookiteminnertag_;
824 case LT_DOCBOOKITEMINNERATTR:
825 lex >> docbookiteminnerattr_;
828 case LT_DOCBOOKITEMINNERTAGTYPE:
829 lex >> docbookiteminnertagtype_;
842 add_to_toc_ = !toc_type_.empty();
845 case LT_ISTOCCAPTION:
846 lex >> is_toc_caption_;
852 // make sure we only have inpreamble = true for commands
853 if (inpreamble && latextype != LATEX_COMMAND && latextype != LATEX_PARAGRAPH) {
854 LYXERR0("InPreamble not permitted except with command and paragraph layouts.");
855 LYXERR0("Layout name: " << name());
859 return finished && !error;
872 LexerKeyword alignTags[] = {
873 { "block", AT_BLOCK },
874 { "center", AT_CENTER },
875 { "layout", AT_LAYOUT },
877 { "right", AT_RIGHT }
881 void Layout::readAlign(Lexer & lex)
883 PushPopHelper pph(lex, alignTags);
886 case Lexer::LEX_UNDEF:
887 lex.printError("Unknown alignment `$$Token'");
893 align = LYX_ALIGN_BLOCK;
896 align = LYX_ALIGN_LEFT;
899 align = LYX_ALIGN_RIGHT;
902 align = LYX_ALIGN_CENTER;
905 align = LYX_ALIGN_LAYOUT;
911 void Layout::readAlignPossible(Lexer & lex)
913 lex.pushTable(alignTags);
914 alignpossible = LYX_ALIGN_NONE | LYX_ALIGN_LAYOUT;
915 int lineno = lex.lineNumber();
919 case Lexer::LEX_UNDEF:
920 lex.printError("Unknown alignment `$$Token'");
926 alignpossible |= LYX_ALIGN_BLOCK;
929 alignpossible |= LYX_ALIGN_LEFT;
932 alignpossible |= LYX_ALIGN_RIGHT;
935 alignpossible |= LYX_ALIGN_CENTER;
938 alignpossible |= LYX_ALIGN_LAYOUT;
941 } while (lineno == lex.lineNumber());
946 void Layout::readLabelType(Lexer & lex)
961 LexerKeyword labelTypeTags[] = {
962 { "above", LA_ABOVE },
963 { "bibliography", LA_BIBLIO },
964 { "centered", LA_CENTERED },
965 { "enumerate", LA_ENUMERATE },
966 { "itemize", LA_ITEMIZE },
967 { "manual", LA_MANUAL },
968 { "no_label", LA_NO_LABEL },
969 { "sensitive", LA_SENSITIVE },
970 { "static", LA_STATIC }
973 PushPopHelper pph(lex, labelTypeTags);
976 case Lexer::LEX_UNDEF:
977 lex.printError("Unknown labeltype tag `$$Token'");
983 labeltype = LABEL_NO_LABEL;
986 labeltype = LABEL_MANUAL;
989 labeltype = LABEL_ABOVE;
992 labeltype = LABEL_CENTERED;
995 labeltype = LABEL_STATIC;
998 labeltype = LABEL_SENSITIVE;
1001 labeltype = LABEL_ENUMERATE;
1004 labeltype = LABEL_ITEMIZE;
1007 labeltype = LABEL_BIBLIO;
1013 void Layout::readEndLabelType(Lexer & lex)
1015 // this should be const, but can't be because
1016 // of PushPopHelper.
1017 static LexerKeyword endlabelTypeTags[] = {
1018 { "box", END_LABEL_BOX },
1019 { "filled_box", END_LABEL_FILLED_BOX },
1020 { "no_label", END_LABEL_NO_LABEL },
1021 { "static", END_LABEL_STATIC }
1024 PushPopHelper pph(lex, endlabelTypeTags);
1027 case Lexer::LEX_UNDEF:
1028 lex.printError("Unknown labeltype tag `$$Token'");
1030 case END_LABEL_STATIC:
1032 case END_LABEL_FILLED_BOX:
1033 case END_LABEL_NO_LABEL:
1034 endlabeltype = static_cast<EndLabelType>(le);
1037 LYXERR0("Unhandled value " << le);
1043 void Layout::readMargin(Lexer & lex)
1045 LexerKeyword marginTags[] = {
1046 { "dynamic", MARGIN_DYNAMIC },
1047 { "first_dynamic", MARGIN_FIRST_DYNAMIC },
1048 { "manual", MARGIN_MANUAL },
1049 { "right_address_box", MARGIN_RIGHT_ADDRESS_BOX },
1050 { "static", MARGIN_STATIC }
1053 PushPopHelper pph(lex, marginTags);
1057 case Lexer::LEX_UNDEF:
1058 lex.printError("Unknown margin type tag `$$Token'");
1062 case MARGIN_DYNAMIC:
1063 case MARGIN_FIRST_DYNAMIC:
1064 case MARGIN_RIGHT_ADDRESS_BOX:
1065 margintype = static_cast<MarginType>(le);
1068 LYXERR0("Unhandled value " << le);
1074 void Layout::readLatexType(Lexer & lex)
1076 LexerKeyword latexTypeTags[] = {
1077 { "bib_environment", LATEX_BIB_ENVIRONMENT },
1078 { "command", LATEX_COMMAND },
1079 { "environment", LATEX_ENVIRONMENT },
1080 { "item_environment", LATEX_ITEM_ENVIRONMENT },
1081 { "list_environment", LATEX_LIST_ENVIRONMENT },
1082 { "paragraph", LATEX_PARAGRAPH }
1085 PushPopHelper pph(lex, latexTypeTags);
1088 case Lexer::LEX_UNDEF:
1089 lex.printError("Unknown latextype tag `$$Token'");
1091 case LATEX_PARAGRAPH:
1093 case LATEX_ITEM_ENVIRONMENT:
1094 case LATEX_LIST_ENVIRONMENT:
1095 latextype = static_cast<LatexType>(le);
1097 case LATEX_ENVIRONMENT:
1098 case LATEX_BIB_ENVIRONMENT:
1099 latextype = static_cast<LatexType>(le);
1103 LYXERR0("Unhandled value " << le);
1109 void Layout::readSpacing(Lexer & lex)
1112 ST_SPACING_SINGLE = 1,
1118 LexerKeyword spacingTags[] = {
1119 {"double", ST_SPACING_DOUBLE },
1120 {"onehalf", ST_SPACING_ONEHALF },
1121 {"other", ST_OTHER },
1122 {"single", ST_SPACING_SINGLE }
1125 PushPopHelper pph(lex, spacingTags);
1128 case Lexer::LEX_UNDEF:
1129 lex.printError("Unknown spacing token `$$Token'");
1134 case ST_SPACING_SINGLE:
1135 spacing.set(Spacing::Single);
1137 case ST_SPACING_ONEHALF:
1138 spacing.set(Spacing::Onehalf);
1140 case ST_SPACING_DOUBLE:
1141 spacing.set(Spacing::Double);
1145 spacing.set(Spacing::Other, lex.getString());
1151 void Layout::readArgument(Lexer & lex)
1154 // writeArgument() makes use of these default values
1155 arg.mandatory = false;
1156 arg.nodelims = false;
1157 arg.autoinsert = false;
1158 arg.insertcotext = false;
1159 arg.insertonnewline = false;
1161 bool finished = false;
1162 arg.font = inherit_font;
1163 arg.labelfont = inherit_font;
1164 arg.is_toc_caption = false;
1165 arg.passthru = PT_INHERITED;
1166 arg.free_spacing = false;
1169 bool const itemarg = prefixIs(id, "item:");
1170 bool const postcmd = prefixIs(id, "post:");
1171 bool const listpreamble = prefixIs(id, "listpreamble:");
1173 while (!finished && lex.isOK() && !error) {
1175 string const tok = ascii_lowercase(lex.getString());
1179 } else if (tok == "endargument") {
1181 } else if (tok == "labelstring") {
1183 arg.labelstring = lex.getDocString();
1184 } else if (tok == "menustring") {
1186 arg.menustring = lex.getDocString();
1187 } else if (tok == "mandatory") {
1189 arg.mandatory = lex.getBool();
1190 } else if (tok == "autoinsert") {
1192 arg.autoinsert = lex.getBool();
1193 } else if (tok == "insertcotext") {
1195 arg.insertcotext = lex.getBool();
1196 } else if (tok == "leftdelim") {
1198 arg.ldelim = lex.getDocString();
1199 arg.ldelim = support::subst(arg.ldelim, from_ascii("<br/>"),
1201 } else if (tok == "rightdelim") {
1203 arg.rdelim = lex.getDocString();
1204 arg.rdelim = support::subst(arg.rdelim, from_ascii("<br/>"),
1206 } else if (tok == "defaultarg") {
1208 arg.defaultarg = lex.getDocString();
1209 } else if (tok == "presetarg") {
1211 arg.presetarg = lex.getDocString();
1212 } else if (tok == "tooltip") {
1214 arg.tooltip = lex.getDocString();
1215 } else if (tok == "requires") {
1217 arg.required = lex.getString();
1218 } else if (tok == "decoration") {
1220 arg.decoration = lex.getString();
1221 } else if (tok == "newlinecmd") {
1223 arg.newlinecmd = lex.getString();
1224 } else if (tok == "font") {
1225 arg.font = lyxRead(lex, arg.font);
1226 } else if (tok == "labelfont") {
1227 arg.labelfont = lyxRead(lex, arg.labelfont);
1228 } else if (tok == "passthruchars") {
1230 arg.pass_thru_chars = lex.getDocString();
1231 } else if (tok == "passthru") {
1233 docstring value = lex.getDocString();
1234 if (value == "true" || value == "1")
1235 arg.passthru = PT_TRUE;
1236 else if (value == "false" || value == "0")
1237 arg.passthru = PT_FALSE;
1239 arg.passthru = PT_INHERITED;
1240 } else if (tok == "istoccaption") {
1242 arg.is_toc_caption = lex.getBool();
1243 } else if (tok == "freespacing") {
1245 arg.free_spacing = lex.getBool();
1247 lex.printError("Unknown tag");
1251 if (arg.labelstring.empty())
1252 LYXERR0("Incomplete Argument definition!");
1254 itemargs_[id] = arg;
1256 postcommandargs_[id] = arg;
1257 else if (listpreamble) {
1258 // list preamble has no delimiters by default
1259 arg.nodelims = true;
1260 listpreamble_[id] = arg;
1262 latexargs_[id] = arg;
1266 void writeArgument(ostream & os, string const & id, Layout::latexarg const & arg)
1268 os << "\tArgument " << id << '\n';
1269 if (!arg.labelstring.empty())
1270 os << "\t\tLabelString \"" << to_utf8(arg.labelstring) << "\"\n";
1271 if (!arg.menustring.empty())
1272 os << "\t\tMenuString \"" << to_utf8(arg.menustring) << "\"\n";
1274 os << "\t\tMandatory " << arg.mandatory << '\n';
1276 os << "\t\tAutoinsert " << arg.autoinsert << '\n';
1277 if (arg.insertcotext)
1278 os << "\t\tInsertCotext " << arg.insertcotext << '\n';
1279 if (!arg.ldelim.empty())
1280 os << "\t\tLeftDelim \""
1281 << to_utf8(subst(arg.ldelim, from_ascii("\n"), from_ascii("<br/>")))
1283 if (!arg.rdelim.empty())
1284 os << "\t\tRightDelim \""
1285 << to_utf8(subst(arg.rdelim, from_ascii("\n"), from_ascii("<br/>")))
1287 if (!arg.defaultarg.empty())
1288 os << "\t\tDefaultArg \"" << to_utf8(arg.defaultarg) << "\"\n";
1289 if (!arg.presetarg.empty())
1290 os << "\t\tPresetArg \"" << to_utf8(arg.presetarg) << "\"\n";
1291 if (!arg.tooltip.empty())
1292 os << "\t\tToolTip \"" << to_utf8(arg.tooltip) << "\"\n";
1293 if (!arg.required.empty())
1294 os << "\t\tRequires \"" << arg.required << "\"\n";
1295 if (!arg.decoration.empty())
1296 os << "\t\tDecoration \"" << arg.decoration << "\"\n";
1297 if (!arg.newlinecmd.empty())
1298 os << "\t\tNewlineCmd \"" << arg.newlinecmd << "\"\n";
1299 if (arg.font != inherit_font)
1300 lyxWrite(os, arg.font, "Font", 2);
1301 if (arg.labelfont != inherit_font)
1302 lyxWrite(os, arg.labelfont, "LabelFont", 2);
1303 switch (arg.passthru) {
1305 os << "\t\tPassThru true\n";
1308 os << "\t\tPassThru false\n";
1311 os << "\t\tPassThru inherited\n";
1314 if (!arg.pass_thru_chars.empty())
1315 os << "\t\tPassThruChars \"" << to_utf8(arg.pass_thru_chars) << "\"\n";
1316 if (arg.free_spacing)
1317 os << "\t\tFreeSpacing " << arg.free_spacing << "\n";
1318 os << "\tEndArgument\n";
1322 void Layout::write(ostream & os) const
1324 os << "Style \"" << to_utf8(name_) << "\"\n";
1325 if (!category_.empty() && obsoleted_by_.empty())
1326 os << "\tCategory \"" << to_utf8(category_) << "\"\n";
1327 // Can't deduce Copystyle here :-(
1328 if (!obsoleted_by_.empty()) {
1329 os << "\tObsoletedBy \"" << to_utf8(obsoleted_by_)
1333 if (!depends_on_.empty())
1334 os << "\tDependsOn " << to_utf8(depends_on_) << '\n';
1335 switch (margintype) {
1336 case MARGIN_DYNAMIC:
1337 os << "\tMargin Dynamic\n";
1339 case MARGIN_FIRST_DYNAMIC:
1340 os << "\tMargin First_Dynamic\n";
1343 os << "\tMargin Manual\n";
1345 case MARGIN_RIGHT_ADDRESS_BOX:
1346 os << "\tMargin Right_Address_Box\n";
1349 os << "\tMargin Static\n";
1352 switch (latextype) {
1353 case LATEX_BIB_ENVIRONMENT:
1354 os << "\tLatexType Bib_Environment\n";
1357 os << "\tLatexType Command\n";
1359 case LATEX_ENVIRONMENT:
1360 os << "\tLatexType Environment\n";
1362 case LATEX_ITEM_ENVIRONMENT:
1363 os << "\tLatexType Item_Environment\n";
1365 case LATEX_LIST_ENVIRONMENT:
1366 os << "\tLatexType List_Environment\n";
1368 case LATEX_PARAGRAPH:
1369 os << "\tLatexType Paragraph\n";
1372 os << "\tInTitle " << intitle << "\n"
1373 "\tInPreamble " << inpreamble << "\n"
1374 "\tTocLevel " << toclevel << "\n"
1375 "\tResumeCounter " << resumecounter << "\n"
1376 "\tStepMasterCounter " << stepmastercounter << '\n';
1377 // ResetArgs does not make sense here
1378 for (LaTeXArgMap::const_iterator it = latexargs_.begin();
1379 it != latexargs_.end(); ++it)
1380 writeArgument(os, it->first, it->second);
1381 for (LaTeXArgMap::const_iterator it = itemargs_.begin();
1382 it != itemargs_.end(); ++it)
1383 writeArgument(os, it->first, it->second);
1384 for (LaTeXArgMap::const_iterator it = postcommandargs_.begin();
1385 it != postcommandargs_.end(); ++it)
1386 writeArgument(os, it->first, it->second);
1387 for (LaTeXArgMap::const_iterator it = listpreamble_.begin();
1388 it != listpreamble_.end(); ++it)
1389 writeArgument(os, it->first, it->second);
1390 os << "\tNeedProtect " << needprotect << "\n"
1391 "\tNeedCProtect " << needcprotect << "\n"
1392 "\tNeedMBoxProtect " << needmboxprotect << "\n"
1393 "\tKeepEmpty " << keepempty << '\n';
1394 if (labelfont == font)
1395 lyxWrite(os, font, "Font", 1);
1397 lyxWrite(os, font, "TextFont", 1);
1398 lyxWrite(os, labelfont, "LabelFont", 1);
1400 os << "\tNextNoIndent " << nextnoindent << "\n"
1401 "\tCommandDepth " << commanddepth << '\n';
1402 if (!latexname_.empty())
1403 os << "\tLatexName \"" << latexname_ << "\"\n";
1404 if (!latexparam_.empty())
1405 os << "\tLatexParam \"" << subst(latexparam_, "\"", """)
1407 if (!leftdelim_.empty())
1408 os << "\tLeftDelim "
1409 << to_utf8(subst(leftdelim_, from_ascii("\n"), from_ascii("<br/>")))
1411 if (!rightdelim_.empty())
1412 os << "\tRightDelim "
1413 << to_utf8(subst(rightdelim_, from_ascii("\n"), from_ascii("<br/>")))
1415 if (!innertag_.empty())
1416 os << "\tInnerTag \"" << innertag_ << "\"\n";
1417 if (!labeltag_.empty())
1418 os << "\tLabelTag \"" << labeltag_ << "\"\n";
1419 if (!itemtag_.empty())
1420 os << "\tItemTag \"" << itemtag_ << "\"\n";
1421 if (!itemcommand_.empty())
1422 os << "\tItemCommand " << itemcommand_ << '\n';
1423 if (!preamble_.empty())
1424 os << "\tPreamble\n\t"
1425 << to_utf8(subst(rtrim(preamble_, "\n"),
1426 from_ascii("\n"), from_ascii("\n\t")))
1427 << "\n\tEndPreamble\n";
1428 if (!langpreamble_.empty())
1429 os << "\tLangPreamble\n\t"
1430 << to_utf8(subst(rtrim(langpreamble_, "\n"),
1431 from_ascii("\n"), from_ascii("\n\t")))
1432 << "\n\tEndLangPreamble\n";
1433 if (!babelpreamble_.empty())
1434 os << "\tBabelPreamble\n\t"
1435 << to_utf8(subst(rtrim(babelpreamble_, "\n"),
1436 from_ascii("\n"), from_ascii("\n\t")))
1437 << "\n\tEndBabelPreamble\n";
1438 switch (labeltype) {
1440 os << "\tLabelType Above\n";
1443 os << "\tLabelType Bibliography\n";
1445 case LABEL_CENTERED:
1446 os << "\tLabelType Centered\n";
1448 case LABEL_ENUMERATE:
1449 os << "\tLabelType Enumerate\n";
1452 os << "\tLabelType Itemize\n";
1455 os << "\tLabelType Manual\n";
1457 case LABEL_NO_LABEL:
1458 os << "\tLabelType No_Label\n";
1460 case LABEL_SENSITIVE:
1461 os << "\tLabelType Sensitive\n";
1464 os << "\tLabelType Static\n";
1467 switch (endlabeltype) {
1469 os << "\tEndLabelType Box\n";
1471 case END_LABEL_FILLED_BOX:
1472 os << "\tEndLabelType Filled_Box\n";
1474 case END_LABEL_NO_LABEL:
1475 os << "\tEndLabelType No_Label\n";
1477 case END_LABEL_STATIC:
1478 os << "\tEndLabelType Static\n";
1481 os << "\tParagraphGroup \"" << par_group_ << "\"\n";
1482 if (!leftmargin.empty())
1483 os << "\tLeftMargin \"" << to_utf8(leftmargin) << "\"\n";
1484 if (!rightmargin.empty())
1485 os << "\tRightMargin \"" << to_utf8(rightmargin) << "\"\n";
1486 if (!labelindent.empty())
1487 os << "\tLabelIndent " << to_utf8(labelindent) << '\n';
1488 if (!parindent.empty())
1489 os << "\tParIndent " << to_utf8(parindent) << '\n';
1490 os << "\tParSkip " << parskip << "\n"
1491 "\tItemSep " << itemsep << "\n"
1492 "\tTopSep " << topsep << "\n"
1493 "\tBottomSep " << bottomsep << "\n"
1494 "\tLabelBottomSep " << labelbottomsep << '\n';
1495 if (!labelsep.empty())
1496 os << "\tLabelSep " << to_utf8(subst(labelsep, ' ', 'x'))
1498 os << "\tParSep " << parsep << "\n"
1499 "\tNewLine " << newline_allowed << '\n';
1501 case LYX_ALIGN_BLOCK:
1502 os << "\tAlign Block\n";
1504 case LYX_ALIGN_CENTER:
1505 os << "\tAlign Center\n";
1507 case LYX_ALIGN_LAYOUT:
1508 os << "\tAlign Layout\n";
1510 case LYX_ALIGN_LEFT:
1511 os << "\tAlign Left\n";
1513 case LYX_ALIGN_RIGHT:
1514 os << "\tAlign Right\n";
1516 case LYX_ALIGN_DECIMAL:
1517 case LYX_ALIGN_SPECIAL:
1518 case LYX_ALIGN_NONE:
1521 if (alignpossible & (LYX_ALIGN_BLOCK | LYX_ALIGN_CENTER |
1522 LYX_ALIGN_LAYOUT | LYX_ALIGN_LEFT | LYX_ALIGN_RIGHT)) {
1524 os << "\tAlignPossible";
1525 if (alignpossible & LYX_ALIGN_BLOCK) {
1529 if (alignpossible & LYX_ALIGN_CENTER) {
1535 if (alignpossible & LYX_ALIGN_LAYOUT) {
1541 if (alignpossible & LYX_ALIGN_LEFT) {
1547 if (alignpossible & LYX_ALIGN_RIGHT) {
1555 // LabelString must come before LabelStringAppendix
1556 if (!labelstring_.empty())
1557 os << "\tLabelString \"" << to_utf8(labelstring_) << "\"\n";
1558 if (!endlabelstring_.empty())
1559 os << "\tEndLabelString \"" << to_utf8(endlabelstring_) << "\"\n";
1560 if (!labelstring_appendix_.empty() && labelstring_appendix_ != labelstring_)
1561 os << "\tLabelStringAppendix \""
1562 << to_utf8(labelstring_appendix_) << "\"\n";
1563 if (!counter.empty())
1564 os << "\tLabelCounter \"" << to_utf8(counter) << "\"\n";
1565 os << "\tFreeSpacing " << free_spacing << '\n';
1566 os << "\tPassThru " << pass_thru << '\n';
1567 if (!pass_thru_chars.empty())
1568 os << "\tPassThruChars " << to_utf8(pass_thru_chars) << '\n';
1569 os << "\tParbreakIsNewline " << parbreak_is_newline << '\n';
1570 switch (spacing.getSpace()) {
1571 case Spacing::Double:
1572 os << "\tSpacing Double\n";
1574 case Spacing::Onehalf:
1575 os << "\tSpacing Onehalf\n";
1577 case Spacing::Other:
1578 os << "\tSpacing Other " << spacing.getValueAsString() << '\n';
1580 case Spacing::Single:
1581 os << "\tSpacing Single\n";
1583 case Spacing::Default:
1586 if (!required_.empty()) {
1587 os << "\tRequires ";
1588 for (set<string>::const_iterator it = required_.begin();
1589 it != required_.end(); ++it) {
1590 if (it != required_.begin())
1596 if (!autonests_.empty()) {
1597 os << "\tAutoNests\n\t";
1598 for (set<docstring>::const_iterator it = autonests_.begin();
1599 it != autonests_.end(); ++it) {
1600 if (it != autonests_.begin())
1604 os << "\n\tEndAutoNests\n";
1606 if (!autonested_by_.empty()) {
1607 os << "\tIsAutoNestedBy\n\t\t";
1608 for (set<docstring>::const_iterator it = autonested_by_.begin();
1609 it != autonested_by_.end(); ++it) {
1610 if (it != autonested_by_.begin())
1614 os << "\n\tEndIsAutoNestedBy\n";
1616 if (refprefix.empty())
1617 os << "\tRefPrefix OFF\n";
1619 os << "\tRefPrefix " << to_utf8(refprefix) << '\n';
1620 if (!htmltag_.empty())
1621 os << "\tHTMLTag " << htmltag_ << '\n';
1622 if (!htmlattr_.empty())
1623 os << "\tHTMLAttr " << htmlattr_ << '\n';
1624 if (!htmlitemtag_.empty())
1625 os << "\tHTMLItem " << htmlitemtag_ << '\n';
1626 if (!htmlitemattr_.empty())
1627 os << "\tHTMLItemAttr " << htmlitemattr_ << '\n';
1628 if (!htmllabeltag_.empty())
1629 os << "\tHTMLLabel " << htmllabeltag_ << '\n';
1630 if (!htmllabelattr_.empty())
1631 os << "\tHTMLLabelAttr " << htmllabelattr_ << '\n';
1632 os << "\tHTMLLabelFirst " << htmllabelfirst_ << '\n';
1633 if (!htmlstyle_.empty())
1634 os << "\tHTMLStyle\n"
1635 << to_utf8(rtrim(htmlstyle_, "\n"))
1636 << "\n\tEndHTMLStyle\n";
1637 os << "\tHTMLForceCSS " << htmlforcecss_ << '\n';
1638 if (!htmlpreamble_.empty())
1639 os << "\tHTMLPreamble\n"
1640 << to_utf8(rtrim(htmlpreamble_, "\n"))
1641 << "\n\tEndPreamble\n";
1642 os << "\tHTMLTitle " << htmltitle_ << "\n";
1643 if(!docbooktag_.empty())
1644 os << "\tDocBookTag " << docbooktag_ << '\n';
1645 if(!docbookattr_.empty())
1646 os << "\tDocBookAttr " << docbookattr_ << '\n';
1647 if(!docbooktagtype_.empty())
1648 os << "\tDocBookTagType " << docbooktagtype_ << '\n';
1649 if(!docbookininfo_.empty())
1650 os << "\tDocBookInInfo " << docbookininfo_ << '\n';
1651 os << "\tDocBookAbstract " << docbookabstract_ << '\n';
1652 if(!docbookwrappertag_.empty())
1653 os << "\tDocBookWrapperTag " << docbookwrappertag_ << '\n';
1654 if(!docbookwrapperattr_.empty())
1655 os << "\tDocBookWrapperAttr " << docbookwrapperattr_ << '\n';
1656 if(!docbookwrappertagtype_.empty())
1657 os << "\tDocBookWrapperTagType " << docbookwrappertagtype_ << '\n';
1658 if(!docbooksectiontag_.empty())
1659 os << "\tDocBookSectionTag " << docbooksectiontag_ << '\n';
1660 if(!docbookitemtag_.empty())
1661 os << "\tDocBookItemTag " << docbookitemtag_ << '\n';
1662 if(!docbookitemattr_.empty())
1663 os << "\tDocBookItemAttr " << docbookitemattr_ << '\n';
1664 if(!docbookitemtagtype_.empty())
1665 os << "\tDocBookItemTagType " << docbookitemtagtype_ << '\n';
1666 if(!docbookitemwrappertag_.empty())
1667 os << "\tDocBookItemWrapperTag " << docbookitemwrappertag_ << '\n';
1668 if(!docbookitemwrapperattr_.empty())
1669 os << "\tDocBookItemWrapperAttr " << docbookitemwrapperattr_ << '\n';
1670 if(!docbookitemwrappertagtype_.empty())
1671 os << "\tDocBookItemWrapperTagType " << docbookitemwrappertagtype_ << '\n';
1672 os << "\tDocBookItemWrapperMergeWithPrevious " << docbookwrappermergewithprevious_ << '\n';
1673 if(!docbookitemlabeltag_.empty())
1674 os << "\tDocBookItemLabelTag " << docbookitemlabeltag_ << '\n';
1675 if(!docbookitemlabelattr_.empty())
1676 os << "\tDocBookItemLabelAttr " << docbookitemlabelattr_ << '\n';
1677 if(!docbookitemlabeltagtype_.empty())
1678 os << "\tDocBookItemLabelTagType " << docbookitemlabeltagtype_ << '\n';
1679 if(!docbookiteminnertag_.empty())
1680 os << "\tDocBookItemInnerTag " << docbookiteminnertag_ << '\n';
1681 if(!docbookiteminnerattr_.empty())
1682 os << "\tDocBookItemInnerAttr " << docbookiteminnerattr_ << '\n';
1683 if(!docbookiteminnertagtype_.empty())
1684 os << "\tDocBookItemInnerTagType " << docbookiteminnertagtype_ << '\n';
1685 if(!docbookforceabstracttag_.empty())
1686 os << "\tDocBookForceAbstractTag " << docbookforceabstracttag_ << '\n';
1687 os << "\tSpellcheck " << spellcheck << "\n"
1688 "\tForceLocal " << forcelocal << "\n"
1693 bool Layout::hasArgs() const
1695 return !latexargs_.empty() || !postcommandargs_.empty() ||
1696 !itemargs_.empty() || !listpreamble_.empty();
1700 Layout::LaTeXArgMap Layout::args() const
1702 LaTeXArgMap args = latexargs_;
1703 if (!postcommandargs_.empty())
1704 args.insert(postcommandargs_.begin(), postcommandargs_.end());
1705 if (!listpreamble_.empty())
1706 args.insert(listpreamble_.begin(), listpreamble_.end());
1707 if (!itemargs_.empty())
1708 args.insert(itemargs_.begin(), itemargs_.end());
1713 int Layout::optArgs() const
1716 LaTeXArgMap::const_iterator it = latexargs_.begin();
1717 for (; it != latexargs_.end(); ++it) {
1718 if (!(*it).second.mandatory)
1721 LaTeXArgMap::const_iterator iit = postcommandargs_.begin();
1722 for (; iit != postcommandargs_.end(); ++iit) {
1723 if (!(*iit).second.mandatory)
1730 int Layout::requiredArgs() const
1733 LaTeXArgMap::const_iterator it = latexargs_.begin();
1734 for (; it != latexargs_.end(); ++it) {
1735 if ((*it).second.mandatory)
1738 LaTeXArgMap::const_iterator iit = postcommandargs_.begin();
1739 for (; iit != postcommandargs_.end(); ++iit) {
1740 if (!(*iit).second.mandatory)
1747 string const & Layout::htmltag() const
1749 if (htmltag_.empty())
1755 string const & Layout::htmlattr() const
1757 if (htmlattr_.empty())
1758 htmlattr_ = "class=\"" + defaultCSSClass() + "\"";
1763 string const & Layout::htmlitemtag() const
1765 if (htmlitemtag_.empty())
1766 htmlitemtag_ = "div";
1767 return htmlitemtag_;
1771 string const & Layout::htmlitemattr() const
1773 if (htmlitemattr_.empty())
1774 htmlitemattr_ = "class=\"" + defaultCSSItemClass() + "\"";
1775 return htmlitemattr_;
1779 string const & Layout::htmllabeltag() const
1781 if (htmllabeltag_.empty())
1782 htmllabeltag_ = "span";
1783 return htmllabeltag_;
1787 string const & Layout::htmllabelattr() const
1789 if (htmllabelattr_.empty())
1790 htmllabelattr_ = "class=\"" + defaultCSSLabelClass() + "\"";
1791 return htmllabelattr_;
1795 docstring Layout::htmlstyle() const
1797 if (!htmlstyle_.empty() && !htmlforcecss_)
1799 if (htmldefaultstyle_.empty())
1801 docstring retval = htmldefaultstyle_;
1802 if (!htmlstyle_.empty())
1803 retval += '\n' + htmlstyle_;
1808 string Layout::defaultCSSClass() const
1810 if (!defaultcssclass_.empty())
1811 return defaultcssclass_;
1813 docstring::const_iterator it = name().begin();
1814 docstring::const_iterator en = name().end();
1815 for (; it != en; ++it) {
1816 char_type const c = *it;
1817 if (!isAlphaASCII(c)) {
1819 // make sure we don't start with an underscore,
1820 // as that sometimes causes problems.
1821 d = from_ascii("lyx_");
1824 } else if (isLower(c))
1827 // this is slow, so do it only if necessary
1830 defaultcssclass_ = to_utf8(d);
1831 return defaultcssclass_;
1835 string const & Layout::docbooktag() const
1837 if (docbooktag_.empty()) {
1838 if (to_ascii(name_) == "Plain Layout")
1839 docbooktag_ = "para";
1840 else // No sensible default value, unhappily...
1841 docbooktag_ = to_utf8(name_);
1847 string const & Layout::docbookattr() const
1849 // Perfectly OK to return no attributes, so docbookattr_ does not need to be filled.
1850 return docbookattr_;
1854 bool isValidTagType(std::string type)
1856 return !(type.empty() || (type != "block" && type != "paragraph" && type != "inline"));
1860 string const & Layout::docbooktagtype() const
1862 if (!isValidTagType(docbooktagtype_))
1863 docbooktagtype_ = "block";
1864 return docbooktagtype_;
1868 string const & Layout::docbookininfo() const
1870 // Indeed, a trilean. Only titles should be "maybe": otherwise, metadata is "always", content is "never".
1871 if (docbookininfo_.empty() || (docbookininfo_ != "never" && docbookininfo_ != "always" && docbookininfo_ != "maybe"))
1872 docbookininfo_ = "never";
1873 return docbookininfo_;
1877 string const & Layout::docbookwrappertag() const
1879 if (docbookwrappertag_.empty())
1880 docbookwrappertag_ = "NONE";
1881 return docbookwrappertag_;
1885 string const & Layout::docbookwrapperattr() const
1887 return docbookwrapperattr_;
1891 string const & Layout::docbookwrappertagtype() const
1893 if (!isValidTagType(docbookwrappertagtype_))
1894 docbookwrappertagtype_ = "block";
1895 return docbookwrappertagtype_;
1899 string const & Layout::docbooksectiontag() const
1901 if (docbooksectiontag_.empty())
1902 docbooksectiontag_ = "section";
1903 return docbooksectiontag_;
1907 string const & Layout::docbookitemwrappertag() const
1909 if (docbookitemwrappertag_.empty())
1910 docbookitemwrappertag_ = "NONE";
1911 return docbookitemwrappertag_;
1915 string const & Layout::docbookitemwrapperattr() const
1917 return docbookitemwrapperattr_;
1921 string const & Layout::docbookitemwrappertagtype() const
1923 if (!isValidTagType(docbookitemwrappertagtype_))
1924 docbookitemwrappertagtype_ = "block";
1925 return docbookitemwrappertagtype_;
1929 string const & Layout::docbookitemtag() const
1931 if (docbookitemtag_.empty())
1932 docbookitemtag_ = "NONE";
1933 return docbookitemtag_;
1937 string const & Layout::docbookitemattr() const
1939 return docbookitemattr_;
1943 string const & Layout::docbookitemtagtype() const
1945 if (!isValidTagType(docbookitemtagtype_))
1946 docbookitemtagtype_ = "block";
1947 return docbookitemtagtype_;
1951 string const & Layout::docbookitemlabeltag() const
1953 if (docbookitemlabeltag_.empty())
1954 docbookitemlabeltag_ = "NONE";
1955 return docbookitemlabeltag_;
1959 string const & Layout::docbookitemlabelattr() const
1961 return docbookitemlabelattr_;
1965 string const & Layout::docbookitemlabeltagtype() const
1967 if (!isValidTagType(docbookitemlabeltagtype_))
1968 docbookitemlabeltagtype_ = "block";
1969 return docbookitemlabeltagtype_;
1973 string const & Layout::docbookiteminnertag() const
1975 if (docbookiteminnertag_.empty())
1976 docbookiteminnertag_ = "NONE";
1977 return docbookiteminnertag_;
1981 string const & Layout::docbookiteminnerattr() const
1983 return docbookiteminnerattr_;
1987 string const & Layout::docbookiteminnertagtype() const
1989 if (!isValidTagType(docbookiteminnertagtype_))
1990 docbookiteminnertagtype_ = "block";
1991 return docbookiteminnertagtype_;
1995 std::string const & Layout::docbookforceabstracttag() const
1997 if (docbookforceabstracttag_.empty())
1998 docbookforceabstracttag_ = "NONE";
1999 return docbookforceabstracttag_;
2006 string makeMarginValue(char const * side, double d)
2009 os << "margin-" << side << ": " << d << "ex;\n";
2016 void Layout::makeDefaultCSS() const
2018 // this never needs to be redone, since reloading layouts will
2019 // wipe out what we did before.
2020 if (!htmldefaultstyle_.empty())
2024 htmldefaultstyle_ = font.asCSS();
2029 tmp += makeMarginValue("top", topsep);
2031 tmp += makeMarginValue("bottom", bottomsep);
2032 if (!leftmargin.empty()) {
2033 // we can't really do what LyX does with the margin, so
2034 // we'll just figure out how many characters it is
2035 int const len = leftmargin.length();
2036 tmp += makeMarginValue("left", len);
2038 if (!rightmargin.empty()) {
2039 int const len = rightmargin.length();
2040 tmp += makeMarginValue("right", len);
2044 if (!htmldefaultstyle_.empty())
2045 htmldefaultstyle_ += from_ascii("\n");
2046 htmldefaultstyle_ += from_ascii(tmp);
2050 string where = alignmentToCSS(align);
2051 if (!where.empty()) {
2052 htmldefaultstyle_ += from_ascii("text-align: " + where + ";\n");
2055 // wrap up what we have, if anything
2056 if (!htmldefaultstyle_.empty())
2058 from_ascii(htmltag() + "." + defaultCSSClass() + " {\n") +
2059 htmldefaultstyle_ + from_ascii("\n}\n");
2061 if (labeltype == LABEL_NO_LABEL || htmllabeltag() == "NONE")
2067 if (labelfont != font)
2068 labelCSS = labelfont.asCSS() + from_ascii("\n");
2069 if (labeltype == LABEL_CENTERED)
2070 labelCSS += from_ascii("text-align: center;\n");
2072 if (!labelCSS.empty())
2073 htmldefaultstyle_ +=
2074 from_ascii(htmllabeltag() + "." + defaultCSSLabelClass() + " {\n") +
2075 labelCSS + from_ascii("\n}\n");
2079 bool Layout::operator==(Layout const & rhs) const
2081 // This is enough for the applications we actually make,
2082 // at least at the moment. But we could check more.
2083 return name() == rhs.name()
2084 && latexname() == rhs.latexname()
2085 && latextype == rhs.latextype;