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, bool validating)
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, validating);
205 bool const ret = tmp.readIgnoreForcelocal(lex, tclass, validating);
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,
220 // This table is sorted alphabetically [asierra 30March96]
221 LexerKeyword layoutTags[] = {
222 { "addtotoc", LT_ADDTOTOC },
223 { "align", LT_ALIGN },
224 { "alignpossible", LT_ALIGNPOSSIBLE },
225 { "argument", LT_ARGUMENT },
226 { "autonests", LT_AUTONESTS },
227 { "babelpreamble", LT_BABELPREAMBLE },
228 { "bottomsep", LT_BOTTOMSEP },
229 { "category", LT_CATEGORY },
230 { "commanddepth", LT_COMMANDDEPTH },
231 { "copystyle", LT_COPYSTYLE },
232 { "dependson", LT_DEPENDSON },
233 { "docbookabstract", LT_DOCBOOKABSTRACT },
234 { "docbookattr", LT_DOCBOOKATTR },
235 { "docbookforceabstracttag", LT_DOCBOOKFORCEABSTRACTTAG },
236 { "docbookininfo", LT_DOCBOOKININFO },
237 { "docbookitemattr", LT_DOCBOOKITEMATTR },
238 { "docbookiteminnerattr", LT_DOCBOOKITEMINNERATTR },
239 { "docbookiteminnertag", LT_DOCBOOKITEMINNERTAG },
240 { "docbookiteminnertagtype", LT_DOCBOOKITEMINNERTAGTYPE },
241 { "docbookitemlabelattr", LT_DOCBOOKITEMLABELATTR },
242 { "docbookitemlabeltag", LT_DOCBOOKITEMLABELTAG },
243 { "docbookitemlabeltagtype", LT_DOCBOOKITEMLABELTAGTYPE },
244 { "docbookitemtag", LT_DOCBOOKITEMTAG },
245 { "docbookitemtagtype", LT_DOCBOOKITEMTAGTYPE },
246 { "docbookitemwrapperattr", LT_DOCBOOKITEMWRAPPERATTR },
247 { "docbookitemwrappertag", LT_DOCBOOKITEMWRAPPERTAG },
248 { "docbookitemwrappertagtype", LT_DOCBOOKITEMWRAPPERTAGTYPE },
249 { "docbooksectiontag", LT_DOCBOOKSECTIONTAG },
250 { "docbooktag", LT_DOCBOOKTAG },
251 { "docbooktagtype", LT_DOCBOOKTAGTYPE },
252 { "docbookwrapperattr", LT_DOCBOOKWRAPPERATTR },
253 { "docbookwrappermergewithprevious", LT_DOCBOOKWRAPPERMERGEWITHPREVIOUS },
254 { "docbookwrappertag", LT_DOCBOOKWRAPPERTAG },
255 { "docbookwrappertagtype", LT_DOCBOOKWRAPPERTAGTYPE },
257 { "endlabelstring", LT_ENDLABELSTRING },
258 { "endlabeltype", LT_ENDLABELTYPE },
260 { "forcelocal", LT_FORCELOCAL },
261 { "freespacing", LT_FREE_SPACING },
262 { "htmlattr", LT_HTMLATTR },
263 { "htmlforcecss", LT_HTMLFORCECSS },
264 { "htmlitem", LT_HTMLITEM },
265 { "htmlitemattr", LT_HTMLITEMATTR },
266 { "htmllabel", LT_HTMLLABEL },
267 { "htmllabelattr", LT_HTMLLABELATTR },
268 { "htmllabelfirst", LT_HTMLLABELFIRST },
269 { "htmlpreamble", LT_HTMLPREAMBLE },
270 { "htmlstyle", LT_HTMLSTYLE },
271 { "htmltag", LT_HTMLTAG },
272 { "htmltitle", LT_HTMLTITLE },
273 { "innertag", LT_INNERTAG },
274 { "inpreamble", LT_INPREAMBLE },
275 { "intitle", LT_INTITLE },
276 { "isautonestedby", LT_AUTONESTEDBY },
277 { "istoccaption", LT_ISTOCCAPTION },
278 { "itemcommand", LT_ITEMCOMMAND },
279 { "itemsep", LT_ITEMSEP },
280 { "itemtag", LT_ITEMTAG },
281 { "keepempty", LT_KEEPEMPTY },
282 { "labelbottomsep", LT_LABEL_BOTTOMSEP },
283 { "labelcounter", LT_LABELCOUNTER },
284 { "labelfont", LT_LABELFONT },
285 { "labelindent", LT_LABELINDENT },
286 { "labelsep", LT_LABELSEP },
287 { "labelstring", LT_LABELSTRING },
288 { "labelstringappendix", LT_LABELSTRING_APPENDIX },
289 { "labeltag", LT_LABELTAG },
290 { "labeltype", LT_LABELTYPE },
291 { "langpreamble", LT_LANGPREAMBLE },
292 { "latexname", LT_LATEXNAME },
293 { "latexparam", LT_LATEXPARAM },
294 { "latextype", LT_LATEXTYPE },
295 { "leftdelim", LT_LEFTDELIM },
296 { "leftmargin", LT_LEFTMARGIN },
297 { "margin", LT_MARGIN },
298 { "needcprotect", LT_NEED_CPROTECT },
299 { "needmboxprotect", LT_NEED_MBOXPROTECT },
300 { "needprotect", LT_NEED_PROTECT },
301 { "newline", LT_NEWLINE },
302 { "nextnoindent", LT_NEXTNOINDENT },
303 { "obsoletedby", LT_OBSOLETEDBY },
304 { "paragraphgroup", LT_PAR_GROUP },
305 { "parbreakisnewline", LT_PARBREAK_IS_NEWLINE },
306 { "parindent", LT_PARINDENT },
307 { "parsep", LT_PARSEP },
308 { "parskip", LT_PARSKIP },
309 { "passthru", LT_PASS_THRU },
310 { "passthruchars", LT_PASS_THRU_CHARS },
311 { "preamble", LT_PREAMBLE },
312 { "refprefix", LT_REFPREFIX },
313 { "requires", LT_REQUIRES },
314 { "resetargs", LT_RESETARGS },
315 { "resumecounter", LT_RESUMECOUNTER },
316 { "rightdelim", LT_RIGHTDELIM },
317 { "rightmargin", LT_RIGHTMARGIN },
318 { "spacing", LT_SPACING },
319 { "spellcheck", LT_SPELLCHECK },
320 { "stepmastercounter", LT_STEPMASTERCOUNTER },
321 { "textfont", LT_TEXTFONT },
322 { "toclevel", LT_TOCLEVEL },
323 { "toggleindent", LT_TOGGLE_INDENT },
324 { "topsep", LT_TOPSEP }
328 bool finished = false;
329 lex.pushTable(layoutTags);
331 // parse style section
332 while (!finished && lex.isOK() && !error) {
334 // See comment in LyXRC.cpp.
336 case Lexer::LEX_FEOF:
339 case Lexer::LEX_UNDEF:
341 lex.printError("Unknown layout tag `$$Token'");
348 switch (static_cast<LayoutTags>(le)) {
360 style = subst(style, '_', ' ');
362 if (tclass.hasLayout(style)) {
363 docstring const tmpname = name_;
364 this->operator=(tclass[style]);
367 LYXERR0("Cannot copy unknown style `"
369 << "All layouts so far:");
370 DocumentClass::const_iterator lit = tclass.begin();
371 DocumentClass::const_iterator len = tclass.end();
372 for (; lit != len; ++lit)
373 LYXERR0(lit->name());
378 case LT_OBSOLETEDBY: {
381 style = subst(style, '_', ' ');
383 if (tclass.hasLayout(style)) {
384 docstring const tmpname = name_;
385 this->operator=(tclass[style]);
387 if (obsoleted_by().empty())
388 obsoleted_by_ = style;
390 LYXERR0("Cannot replace with unknown style `"
393 //lex.printError("Cannot replace with"
402 depends_on_ = subst(depends_on_, '_', ' ');
431 postcommandargs_.clear();
432 listpreamble_.clear();
436 case LT_RESUMECOUNTER:
437 lex >> resumecounter;
440 case LT_STEPMASTERCOUNTER:
441 lex >> stepmastercounter;
445 readArgument(lex, validating);
448 case LT_NEED_PROTECT:
452 case LT_NEED_CPROTECT:
456 case LT_NEED_MBOXPROTECT:
457 lex >> needmboxprotect;
465 font = lyxRead(lex, font);
470 font = lyxRead(lex, font);
474 labelfont = lyxRead(lex, labelfont);
477 case LT_NEXTNOINDENT:
481 case LT_TOGGLE_INDENT: {
484 tog = support::ascii_lowercase(tog);
486 toggle_indent = ITOGGLE_ALWAYS;
487 else if (tog == "never")
488 toggle_indent = ITOGGLE_NEVER;
490 toggle_indent = ITOGGLE_DOCUMENT_DEFAULT;
494 case LT_COMMANDDEPTH:
504 latexparam_ = subst(latexparam_, """, "\"");
509 leftdelim_ = support::subst(leftdelim_, from_ascii("<br/>"),
515 rightdelim_ = support::subst(rightdelim_, from_ascii("<br/>"),
536 preamble_ = lex.getLongString(from_ascii("EndPreamble"));
539 case LT_LANGPREAMBLE:
540 langpreamble_ = lex.getLongString(from_ascii("EndLangPreamble"));
543 case LT_BABELPREAMBLE:
544 babelpreamble_ = lex.getLongString(from_ascii("EndBabelPreamble"));
551 case LT_ENDLABELTYPE:
552 readEndLabelType(lex);
587 case LT_LABEL_BOTTOMSEP:
588 lex >> labelbottomsep;
593 labelsep = subst(labelsep, 'x', ' ');
601 lex >> newline_allowed;
608 case LT_ALIGNPOSSIBLE:
609 readAlignPossible(lex);
613 // FIXME: this means LT_LABELSTRING_APPENDIX may only
614 // occur after LT_LABELSTRING
616 labelstring_appendix_ = labelstring_;
619 case LT_ENDLABELSTRING:
620 lex >> endlabelstring_;
623 case LT_LABELSTRING_APPENDIX:
624 lex >> labelstring_appendix_;
627 case LT_LABELCOUNTER:
635 case LT_FREE_SPACING:
643 case LT_PASS_THRU_CHARS:
644 lex >> pass_thru_chars;
647 case LT_PARBREAK_IS_NEWLINE:
648 lex >> parbreak_is_newline;
657 vector<string> const req =
658 getVectorFromString(lex.getString(true));
659 required_.insert(req.begin(), req.end());
664 docstring autonest = lex.getLongString(from_ascii("EndAutoNests"));
665 autonest = subst(autonest, from_ascii("\n"), docstring());
666 autonest = subst(autonest, from_ascii("\t"), docstring());
667 autonest = subst(autonest, from_ascii("\""), docstring());
668 autonest = subst(autonest, '_', ' ');
669 vector<docstring> const autonests =
670 getVectorFromString(autonest, from_ascii(","), false, true);
671 autonests_.insert(autonests.begin(), autonests.end());
675 case LT_AUTONESTEDBY: {
676 docstring autonest = lex.getLongString(from_ascii("EndIsAutoNestedBy"));
677 autonest = subst(autonest, from_ascii("\n"), docstring());
678 autonest = subst(autonest, from_ascii("\t"), docstring());
679 autonest = subst(autonest, from_ascii("\""), docstring());
680 autonest = subst(autonest, '_', ' ');
681 vector<docstring> const autonests =
682 getVectorFromString(autonest, from_ascii(","), false, true);
683 autonested_by_.insert(autonests.begin(), autonests.end());
709 case LT_HTMLITEMATTR:
710 lex >> htmlitemattr_;
714 lex >> htmllabeltag_;
717 case LT_HTMLLABELATTR:
718 lex >> htmllabelattr_;
721 case LT_HTMLLABELFIRST:
722 lex >> htmllabelfirst_;
726 htmlstyle_ = lex.getLongString(from_ascii("EndHTMLStyle"));
729 case LT_HTMLFORCECSS:
730 lex >> htmlforcecss_;
733 case LT_HTMLPREAMBLE:
734 htmlpreamble_ = lex.getLongString(from_ascii("EndPreamble"));
749 case LT_DOCBOOKTAGTYPE:
750 lex >> docbooktagtype_;
753 case LT_DOCBOOKFORCEABSTRACTTAG:
754 lex >> docbookforceabstracttag_;
757 case LT_DOCBOOKININFO:
758 lex >> docbookininfo_;
761 case LT_DOCBOOKABSTRACT:
762 lex >> docbookabstract_;
765 case LT_DOCBOOKWRAPPERTAG:
766 lex >> docbookwrappertag_;
769 case LT_DOCBOOKWRAPPERATTR:
770 lex >> docbookwrapperattr_;
773 case LT_DOCBOOKWRAPPERTAGTYPE:
774 lex >> docbookwrappertagtype_;
777 case LT_DOCBOOKWRAPPERMERGEWITHPREVIOUS:
778 lex >> docbookwrappermergewithprevious_;
781 case LT_DOCBOOKSECTIONTAG:
782 lex >> docbooksectiontag_;
785 case LT_DOCBOOKITEMWRAPPERTAG:
786 lex >> docbookitemwrappertag_;
789 case LT_DOCBOOKITEMWRAPPERATTR:
790 lex >> docbookitemwrapperattr_;
793 case LT_DOCBOOKITEMWRAPPERTAGTYPE:
794 lex >> docbookitemwrappertagtype_;
797 case LT_DOCBOOKITEMTAG:
798 lex >> docbookitemtag_;
801 case LT_DOCBOOKITEMATTR:
802 lex >> docbookitemattr_;
805 case LT_DOCBOOKITEMTAGTYPE:
806 lex >> docbookitemtagtype_;
809 case LT_DOCBOOKITEMLABELTAG:
810 lex >> docbookitemlabeltag_;
813 case LT_DOCBOOKITEMLABELATTR:
814 lex >> docbookitemlabelattr_;
817 case LT_DOCBOOKITEMLABELTAGTYPE:
818 lex >> docbookitemlabeltagtype_;
821 case LT_DOCBOOKITEMINNERTAG:
822 lex >> docbookiteminnertag_;
825 case LT_DOCBOOKITEMINNERATTR:
826 lex >> docbookiteminnerattr_;
829 case LT_DOCBOOKITEMINNERTAGTYPE:
830 lex >> docbookiteminnertagtype_;
843 add_to_toc_ = !toc_type_.empty();
846 case LT_ISTOCCAPTION:
847 lex >> is_toc_caption_;
853 // make sure we only have inpreamble = true for commands
854 if (inpreamble && latextype != LATEX_COMMAND && latextype != LATEX_PARAGRAPH) {
855 LYXERR0("InPreamble not permitted except with command and paragraph layouts.");
856 LYXERR0("Layout name: " << name());
860 return finished && !error;
873 LexerKeyword alignTags[] = {
874 { "block", AT_BLOCK },
875 { "center", AT_CENTER },
876 { "layout", AT_LAYOUT },
878 { "right", AT_RIGHT }
882 void Layout::readAlign(Lexer & lex)
884 PushPopHelper pph(lex, alignTags);
887 case Lexer::LEX_UNDEF:
888 lex.printError("Unknown alignment `$$Token'");
894 align = LYX_ALIGN_BLOCK;
897 align = LYX_ALIGN_LEFT;
900 align = LYX_ALIGN_RIGHT;
903 align = LYX_ALIGN_CENTER;
906 align = LYX_ALIGN_LAYOUT;
912 void Layout::readAlignPossible(Lexer & lex)
914 lex.pushTable(alignTags);
915 alignpossible = LYX_ALIGN_NONE | LYX_ALIGN_LAYOUT;
916 int lineno = lex.lineNumber();
920 case Lexer::LEX_UNDEF:
921 lex.printError("Unknown alignment `$$Token'");
927 alignpossible |= LYX_ALIGN_BLOCK;
930 alignpossible |= LYX_ALIGN_LEFT;
933 alignpossible |= LYX_ALIGN_RIGHT;
936 alignpossible |= LYX_ALIGN_CENTER;
939 alignpossible |= LYX_ALIGN_LAYOUT;
942 } while (lineno == lex.lineNumber());
947 void Layout::readLabelType(Lexer & lex)
962 LexerKeyword labelTypeTags[] = {
963 { "above", LA_ABOVE },
964 { "bibliography", LA_BIBLIO },
965 { "centered", LA_CENTERED },
966 { "enumerate", LA_ENUMERATE },
967 { "itemize", LA_ITEMIZE },
968 { "manual", LA_MANUAL },
969 { "no_label", LA_NO_LABEL },
970 { "sensitive", LA_SENSITIVE },
971 { "static", LA_STATIC }
974 PushPopHelper pph(lex, labelTypeTags);
977 case Lexer::LEX_UNDEF:
978 lex.printError("Unknown labeltype tag `$$Token'");
984 labeltype = LABEL_NO_LABEL;
987 labeltype = LABEL_MANUAL;
990 labeltype = LABEL_ABOVE;
993 labeltype = LABEL_CENTERED;
996 labeltype = LABEL_STATIC;
999 labeltype = LABEL_SENSITIVE;
1002 labeltype = LABEL_ENUMERATE;
1005 labeltype = LABEL_ITEMIZE;
1008 labeltype = LABEL_BIBLIO;
1014 void Layout::readEndLabelType(Lexer & lex)
1016 // this should be const, but can't be because
1017 // of PushPopHelper.
1018 static LexerKeyword endlabelTypeTags[] = {
1019 { "box", END_LABEL_BOX },
1020 { "filled_box", END_LABEL_FILLED_BOX },
1021 { "no_label", END_LABEL_NO_LABEL },
1022 { "static", END_LABEL_STATIC }
1025 PushPopHelper pph(lex, endlabelTypeTags);
1028 case Lexer::LEX_UNDEF:
1029 lex.printError("Unknown labeltype tag `$$Token'");
1031 case END_LABEL_STATIC:
1033 case END_LABEL_FILLED_BOX:
1034 case END_LABEL_NO_LABEL:
1035 endlabeltype = static_cast<EndLabelType>(le);
1038 LYXERR0("Unhandled value " << le);
1044 void Layout::readMargin(Lexer & lex)
1046 LexerKeyword marginTags[] = {
1047 { "dynamic", MARGIN_DYNAMIC },
1048 { "first_dynamic", MARGIN_FIRST_DYNAMIC },
1049 { "manual", MARGIN_MANUAL },
1050 { "right_address_box", MARGIN_RIGHT_ADDRESS_BOX },
1051 { "static", MARGIN_STATIC }
1054 PushPopHelper pph(lex, marginTags);
1058 case Lexer::LEX_UNDEF:
1059 lex.printError("Unknown margin type tag `$$Token'");
1063 case MARGIN_DYNAMIC:
1064 case MARGIN_FIRST_DYNAMIC:
1065 case MARGIN_RIGHT_ADDRESS_BOX:
1066 margintype = static_cast<MarginType>(le);
1069 LYXERR0("Unhandled value " << le);
1075 void Layout::readLatexType(Lexer & lex)
1077 LexerKeyword latexTypeTags[] = {
1078 { "bib_environment", LATEX_BIB_ENVIRONMENT },
1079 { "command", LATEX_COMMAND },
1080 { "environment", LATEX_ENVIRONMENT },
1081 { "item_environment", LATEX_ITEM_ENVIRONMENT },
1082 { "list_environment", LATEX_LIST_ENVIRONMENT },
1083 { "paragraph", LATEX_PARAGRAPH }
1086 PushPopHelper pph(lex, latexTypeTags);
1089 case Lexer::LEX_UNDEF:
1090 lex.printError("Unknown latextype tag `$$Token'");
1092 case LATEX_PARAGRAPH:
1094 case LATEX_ITEM_ENVIRONMENT:
1095 case LATEX_LIST_ENVIRONMENT:
1096 latextype = static_cast<LatexType>(le);
1098 case LATEX_ENVIRONMENT:
1099 case LATEX_BIB_ENVIRONMENT:
1100 latextype = static_cast<LatexType>(le);
1104 LYXERR0("Unhandled value " << le);
1110 void Layout::readSpacing(Lexer & lex)
1113 ST_SPACING_SINGLE = 1,
1119 LexerKeyword spacingTags[] = {
1120 {"double", ST_SPACING_DOUBLE },
1121 {"onehalf", ST_SPACING_ONEHALF },
1122 {"other", ST_OTHER },
1123 {"single", ST_SPACING_SINGLE }
1126 PushPopHelper pph(lex, spacingTags);
1129 case Lexer::LEX_UNDEF:
1130 lex.printError("Unknown spacing token `$$Token'");
1135 case ST_SPACING_SINGLE:
1136 spacing.set(Spacing::Single);
1138 case ST_SPACING_ONEHALF:
1139 spacing.set(Spacing::Onehalf);
1141 case ST_SPACING_DOUBLE:
1142 spacing.set(Spacing::Double);
1146 spacing.set(Spacing::Other, lex.getString());
1152 void Layout::readArgument(Lexer & lex, bool validating)
1155 LYXERR0("Unable to read argument ID!");
1158 string const id = lex.getString();
1160 bool const itemarg = prefixIs(id, "item:");
1161 bool const postcmd = prefixIs(id, "post:");
1162 bool const listpreamble = prefixIs(id, "listpreamble:");
1164 LaTeXArgMap & lam = itemarg ? itemargs_ :
1165 (postcmd ? postcommandargs_ :
1166 (listpreamble ? listpreamble_ :
1168 latexarg & arg = lam[id];
1171 bool finished = false;
1172 while (!finished && lex.isOK() && !error) {
1174 string const tok = ascii_lowercase(lex.getString());
1178 } else if (tok == "endargument") {
1180 } else if (tok == "labelstring") {
1182 arg.labelstring = lex.getDocString();
1183 } else if (tok == "menustring") {
1185 arg.menustring = lex.getDocString();
1186 } else if (tok == "mandatory") {
1188 arg.mandatory = lex.getBool();
1189 } else if (tok == "autoinsert") {
1191 arg.autoinsert = lex.getBool();
1192 } else if (tok == "insertcotext") {
1194 arg.insertcotext = lex.getBool();
1195 } else if (tok == "leftdelim") {
1197 arg.ldelim = lex.getDocString();
1198 arg.ldelim = support::subst(arg.ldelim, from_ascii("<br/>"),
1200 } else if (tok == "rightdelim") {
1202 arg.rdelim = lex.getDocString();
1203 arg.rdelim = support::subst(arg.rdelim, from_ascii("<br/>"),
1205 } else if (tok == "defaultarg") {
1207 arg.defaultarg = lex.getDocString();
1208 } else if (tok == "presetarg") {
1210 arg.presetarg = lex.getDocString();
1211 } else if (tok == "tooltip") {
1213 arg.tooltip = lex.getDocString();
1214 } else if (tok == "requires") {
1216 arg.required = lex.getString();
1217 } else if (tok == "decoration") {
1219 arg.decoration = lex.getString();
1220 } else if (tok == "newlinecmd") {
1222 arg.newlinecmd = lex.getString();
1223 } else if (tok == "font") {
1224 arg.font = lyxRead(lex, arg.font);
1225 } else if (tok == "labelfont") {
1226 arg.labelfont = lyxRead(lex, arg.labelfont);
1227 } else if (tok == "passthruchars") {
1229 arg.pass_thru_chars = lex.getDocString();
1230 } else if (tok == "passthru") {
1232 docstring value = lex.getDocString();
1233 if (value == "true" || value == "1")
1234 arg.passthru = PT_TRUE;
1235 else if (value == "false" || value == "0")
1236 arg.passthru = PT_FALSE;
1238 arg.passthru = PT_INHERITED;
1239 } else if (tok == "istoccaption") {
1241 arg.is_toc_caption = lex.getBool();
1242 } else if (tok == "freespacing") {
1244 arg.free_spacing = lex.getBool();
1246 lex.printError("Unknown tag");
1250 if (!validating && arg.labelstring.empty()) {
1251 LYXERR0("Incomplete Argument definition!");
1252 // remove invalid definition
1258 void writeArgument(ostream & os, string const & id, Layout::latexarg const & arg)
1260 os << "\tArgument " << id << '\n';
1261 if (!arg.labelstring.empty())
1262 os << "\t\tLabelString \"" << to_utf8(arg.labelstring) << "\"\n";
1263 if (!arg.menustring.empty())
1264 os << "\t\tMenuString \"" << to_utf8(arg.menustring) << "\"\n";
1266 os << "\t\tMandatory " << arg.mandatory << '\n';
1268 os << "\t\tAutoinsert " << arg.autoinsert << '\n';
1269 if (arg.insertcotext)
1270 os << "\t\tInsertCotext " << arg.insertcotext << '\n';
1271 if (!arg.ldelim.empty())
1272 os << "\t\tLeftDelim \""
1273 << to_utf8(subst(arg.ldelim, from_ascii("\n"), from_ascii("<br/>")))
1275 if (!arg.rdelim.empty())
1276 os << "\t\tRightDelim \""
1277 << to_utf8(subst(arg.rdelim, from_ascii("\n"), from_ascii("<br/>")))
1279 if (!arg.defaultarg.empty())
1280 os << "\t\tDefaultArg \"" << to_utf8(arg.defaultarg) << "\"\n";
1281 if (!arg.presetarg.empty())
1282 os << "\t\tPresetArg \"" << to_utf8(arg.presetarg) << "\"\n";
1283 if (!arg.tooltip.empty())
1284 os << "\t\tToolTip \"" << to_utf8(arg.tooltip) << "\"\n";
1285 if (!arg.required.empty())
1286 os << "\t\tRequires \"" << arg.required << "\"\n";
1287 if (!arg.decoration.empty())
1288 os << "\t\tDecoration \"" << arg.decoration << "\"\n";
1289 if (!arg.newlinecmd.empty())
1290 os << "\t\tNewlineCmd \"" << arg.newlinecmd << "\"\n";
1291 if (arg.font != inherit_font)
1292 lyxWrite(os, arg.font, "Font", 2);
1293 if (arg.labelfont != inherit_font)
1294 lyxWrite(os, arg.labelfont, "LabelFont", 2);
1295 switch (arg.passthru) {
1297 os << "\t\tPassThru true\n";
1300 os << "\t\tPassThru false\n";
1303 os << "\t\tPassThru inherited\n";
1306 if (!arg.pass_thru_chars.empty())
1307 os << "\t\tPassThruChars \"" << to_utf8(arg.pass_thru_chars) << "\"\n";
1308 if (arg.free_spacing)
1309 os << "\t\tFreeSpacing " << arg.free_spacing << "\n";
1310 os << "\tEndArgument\n";
1314 void Layout::write(ostream & os) const
1316 os << "Style \"" << to_utf8(name_) << "\"\n";
1317 if (!category_.empty() && obsoleted_by_.empty())
1318 os << "\tCategory \"" << to_utf8(category_) << "\"\n";
1319 // Can't deduce Copystyle here :-(
1320 if (!obsoleted_by_.empty()) {
1321 os << "\tObsoletedBy \"" << to_utf8(obsoleted_by_)
1325 if (!depends_on_.empty())
1326 os << "\tDependsOn " << to_utf8(depends_on_) << '\n';
1327 switch (margintype) {
1328 case MARGIN_DYNAMIC:
1329 os << "\tMargin Dynamic\n";
1331 case MARGIN_FIRST_DYNAMIC:
1332 os << "\tMargin First_Dynamic\n";
1335 os << "\tMargin Manual\n";
1337 case MARGIN_RIGHT_ADDRESS_BOX:
1338 os << "\tMargin Right_Address_Box\n";
1341 os << "\tMargin Static\n";
1344 switch (latextype) {
1345 case LATEX_BIB_ENVIRONMENT:
1346 os << "\tLatexType Bib_Environment\n";
1349 os << "\tLatexType Command\n";
1351 case LATEX_ENVIRONMENT:
1352 os << "\tLatexType Environment\n";
1354 case LATEX_ITEM_ENVIRONMENT:
1355 os << "\tLatexType Item_Environment\n";
1357 case LATEX_LIST_ENVIRONMENT:
1358 os << "\tLatexType List_Environment\n";
1360 case LATEX_PARAGRAPH:
1361 os << "\tLatexType Paragraph\n";
1364 os << "\tInTitle " << intitle << "\n"
1365 "\tInPreamble " << inpreamble << "\n"
1366 "\tTocLevel " << toclevel << "\n"
1367 "\tResumeCounter " << resumecounter << "\n"
1368 "\tStepMasterCounter " << stepmastercounter << '\n';
1369 // ResetArgs does not make sense here
1370 for (LaTeXArgMap::const_iterator it = latexargs_.begin();
1371 it != latexargs_.end(); ++it)
1372 writeArgument(os, it->first, it->second);
1373 for (LaTeXArgMap::const_iterator it = itemargs_.begin();
1374 it != itemargs_.end(); ++it)
1375 writeArgument(os, it->first, it->second);
1376 for (LaTeXArgMap::const_iterator it = postcommandargs_.begin();
1377 it != postcommandargs_.end(); ++it)
1378 writeArgument(os, it->first, it->second);
1379 for (LaTeXArgMap::const_iterator it = listpreamble_.begin();
1380 it != listpreamble_.end(); ++it)
1381 writeArgument(os, it->first, it->second);
1382 os << "\tNeedProtect " << needprotect << "\n"
1383 "\tNeedCProtect " << needcprotect << "\n"
1384 "\tNeedMBoxProtect " << needmboxprotect << "\n"
1385 "\tKeepEmpty " << keepempty << '\n';
1386 if (labelfont == font)
1387 lyxWrite(os, font, "Font", 1);
1389 lyxWrite(os, font, "TextFont", 1);
1390 lyxWrite(os, labelfont, "LabelFont", 1);
1392 os << "\tNextNoIndent " << nextnoindent << "\n"
1393 "\tCommandDepth " << commanddepth << '\n';
1394 if (!latexname_.empty())
1395 os << "\tLatexName \"" << latexname_ << "\"\n";
1396 if (!latexparam_.empty())
1397 os << "\tLatexParam \"" << subst(latexparam_, "\"", """)
1399 if (!leftdelim_.empty())
1400 os << "\tLeftDelim "
1401 << to_utf8(subst(leftdelim_, from_ascii("\n"), from_ascii("<br/>")))
1403 if (!rightdelim_.empty())
1404 os << "\tRightDelim "
1405 << to_utf8(subst(rightdelim_, from_ascii("\n"), from_ascii("<br/>")))
1407 if (!innertag_.empty())
1408 os << "\tInnerTag \"" << innertag_ << "\"\n";
1409 if (!labeltag_.empty())
1410 os << "\tLabelTag \"" << labeltag_ << "\"\n";
1411 if (!itemtag_.empty())
1412 os << "\tItemTag \"" << itemtag_ << "\"\n";
1413 if (!itemcommand_.empty())
1414 os << "\tItemCommand " << itemcommand_ << '\n';
1415 if (!preamble_.empty())
1416 os << "\tPreamble\n\t"
1417 << to_utf8(subst(rtrim(preamble_, "\n"),
1418 from_ascii("\n"), from_ascii("\n\t")))
1419 << "\n\tEndPreamble\n";
1420 if (!langpreamble_.empty())
1421 os << "\tLangPreamble\n\t"
1422 << to_utf8(subst(rtrim(langpreamble_, "\n"),
1423 from_ascii("\n"), from_ascii("\n\t")))
1424 << "\n\tEndLangPreamble\n";
1425 if (!babelpreamble_.empty())
1426 os << "\tBabelPreamble\n\t"
1427 << to_utf8(subst(rtrim(babelpreamble_, "\n"),
1428 from_ascii("\n"), from_ascii("\n\t")))
1429 << "\n\tEndBabelPreamble\n";
1430 switch (labeltype) {
1432 os << "\tLabelType Above\n";
1435 os << "\tLabelType Bibliography\n";
1437 case LABEL_CENTERED:
1438 os << "\tLabelType Centered\n";
1440 case LABEL_ENUMERATE:
1441 os << "\tLabelType Enumerate\n";
1444 os << "\tLabelType Itemize\n";
1447 os << "\tLabelType Manual\n";
1449 case LABEL_NO_LABEL:
1450 os << "\tLabelType No_Label\n";
1452 case LABEL_SENSITIVE:
1453 os << "\tLabelType Sensitive\n";
1456 os << "\tLabelType Static\n";
1459 switch (endlabeltype) {
1461 os << "\tEndLabelType Box\n";
1463 case END_LABEL_FILLED_BOX:
1464 os << "\tEndLabelType Filled_Box\n";
1466 case END_LABEL_NO_LABEL:
1467 os << "\tEndLabelType No_Label\n";
1469 case END_LABEL_STATIC:
1470 os << "\tEndLabelType Static\n";
1473 os << "\tParagraphGroup \"" << par_group_ << "\"\n";
1474 if (!leftmargin.empty())
1475 os << "\tLeftMargin \"" << to_utf8(leftmargin) << "\"\n";
1476 if (!rightmargin.empty())
1477 os << "\tRightMargin \"" << to_utf8(rightmargin) << "\"\n";
1478 if (!labelindent.empty())
1479 os << "\tLabelIndent " << to_utf8(labelindent) << '\n';
1480 if (!parindent.empty())
1481 os << "\tParIndent " << to_utf8(parindent) << '\n';
1482 os << "\tParSkip " << parskip << "\n"
1483 "\tItemSep " << itemsep << "\n"
1484 "\tTopSep " << topsep << "\n"
1485 "\tBottomSep " << bottomsep << "\n"
1486 "\tLabelBottomSep " << labelbottomsep << '\n';
1487 if (!labelsep.empty())
1488 os << "\tLabelSep " << to_utf8(subst(labelsep, ' ', 'x'))
1490 os << "\tParSep " << parsep << "\n"
1491 "\tNewLine " << newline_allowed << '\n';
1493 case LYX_ALIGN_BLOCK:
1494 os << "\tAlign Block\n";
1496 case LYX_ALIGN_CENTER:
1497 os << "\tAlign Center\n";
1499 case LYX_ALIGN_LAYOUT:
1500 os << "\tAlign Layout\n";
1502 case LYX_ALIGN_LEFT:
1503 os << "\tAlign Left\n";
1505 case LYX_ALIGN_RIGHT:
1506 os << "\tAlign Right\n";
1508 case LYX_ALIGN_DECIMAL:
1509 case LYX_ALIGN_SPECIAL:
1510 case LYX_ALIGN_NONE:
1513 if (alignpossible & (LYX_ALIGN_BLOCK | LYX_ALIGN_CENTER |
1514 LYX_ALIGN_LAYOUT | LYX_ALIGN_LEFT | LYX_ALIGN_RIGHT)) {
1516 os << "\tAlignPossible";
1517 if (alignpossible & LYX_ALIGN_BLOCK) {
1521 if (alignpossible & LYX_ALIGN_CENTER) {
1527 if (alignpossible & LYX_ALIGN_LAYOUT) {
1533 if (alignpossible & LYX_ALIGN_LEFT) {
1539 if (alignpossible & LYX_ALIGN_RIGHT) {
1547 // LabelString must come before LabelStringAppendix
1548 if (!labelstring_.empty())
1549 os << "\tLabelString \"" << to_utf8(labelstring_) << "\"\n";
1550 if (!endlabelstring_.empty())
1551 os << "\tEndLabelString \"" << to_utf8(endlabelstring_) << "\"\n";
1552 if (!labelstring_appendix_.empty() && labelstring_appendix_ != labelstring_)
1553 os << "\tLabelStringAppendix \""
1554 << to_utf8(labelstring_appendix_) << "\"\n";
1555 if (!counter.empty())
1556 os << "\tLabelCounter \"" << to_utf8(counter) << "\"\n";
1557 os << "\tFreeSpacing " << free_spacing << '\n';
1558 os << "\tPassThru " << pass_thru << '\n';
1559 if (!pass_thru_chars.empty())
1560 os << "\tPassThruChars " << to_utf8(pass_thru_chars) << '\n';
1561 os << "\tParbreakIsNewline " << parbreak_is_newline << '\n';
1562 switch (spacing.getSpace()) {
1563 case Spacing::Double:
1564 os << "\tSpacing Double\n";
1566 case Spacing::Onehalf:
1567 os << "\tSpacing Onehalf\n";
1569 case Spacing::Other:
1570 os << "\tSpacing Other " << spacing.getValueAsString() << '\n';
1572 case Spacing::Single:
1573 os << "\tSpacing Single\n";
1575 case Spacing::Default:
1578 if (!required_.empty()) {
1579 os << "\tRequires ";
1580 for (set<string>::const_iterator it = required_.begin();
1581 it != required_.end(); ++it) {
1582 if (it != required_.begin())
1588 if (!autonests_.empty()) {
1589 os << "\tAutoNests\n\t";
1590 for (set<docstring>::const_iterator it = autonests_.begin();
1591 it != autonests_.end(); ++it) {
1592 if (it != autonests_.begin())
1596 os << "\n\tEndAutoNests\n";
1598 if (!autonested_by_.empty()) {
1599 os << "\tIsAutoNestedBy\n\t\t";
1600 for (set<docstring>::const_iterator it = autonested_by_.begin();
1601 it != autonested_by_.end(); ++it) {
1602 if (it != autonested_by_.begin())
1606 os << "\n\tEndIsAutoNestedBy\n";
1608 if (refprefix.empty())
1609 os << "\tRefPrefix OFF\n";
1611 os << "\tRefPrefix " << to_utf8(refprefix) << '\n';
1612 if (!htmltag_.empty())
1613 os << "\tHTMLTag " << htmltag_ << '\n';
1614 if (!htmlattr_.empty())
1615 os << "\tHTMLAttr " << htmlattr_ << '\n';
1616 if (!htmlitemtag_.empty())
1617 os << "\tHTMLItem " << htmlitemtag_ << '\n';
1618 if (!htmlitemattr_.empty())
1619 os << "\tHTMLItemAttr " << htmlitemattr_ << '\n';
1620 if (!htmllabeltag_.empty())
1621 os << "\tHTMLLabel " << htmllabeltag_ << '\n';
1622 if (!htmllabelattr_.empty())
1623 os << "\tHTMLLabelAttr " << htmllabelattr_ << '\n';
1624 os << "\tHTMLLabelFirst " << htmllabelfirst_ << '\n';
1625 if (!htmlstyle_.empty())
1626 os << "\tHTMLStyle\n"
1627 << to_utf8(rtrim(htmlstyle_, "\n"))
1628 << "\n\tEndHTMLStyle\n";
1629 os << "\tHTMLForceCSS " << htmlforcecss_ << '\n';
1630 if (!htmlpreamble_.empty())
1631 os << "\tHTMLPreamble\n"
1632 << to_utf8(rtrim(htmlpreamble_, "\n"))
1633 << "\n\tEndPreamble\n";
1634 os << "\tHTMLTitle " << htmltitle_ << "\n";
1635 if(!docbooktag_.empty())
1636 os << "\tDocBookTag " << docbooktag_ << '\n';
1637 if(!docbookattr_.empty())
1638 os << "\tDocBookAttr \"" << docbookattr_ << "\"\n";
1639 if(!docbooktagtype_.empty())
1640 os << "\tDocBookTagType " << docbooktagtype_ << '\n';
1641 if(!docbookininfo_.empty())
1642 os << "\tDocBookInInfo " << docbookininfo_ << '\n';
1643 os << "\tDocBookAbstract " << docbookabstract_ << '\n';
1644 if(!docbookwrappertag_.empty())
1645 os << "\tDocBookWrapperTag " << docbookwrappertag_ << '\n';
1646 if(!docbookwrapperattr_.empty())
1647 os << "\tDocBookWrapperAttr " << docbookwrapperattr_ << '\n';
1648 if(!docbookwrappertagtype_.empty())
1649 os << "\tDocBookWrapperTagType " << docbookwrappertagtype_ << '\n';
1650 if(!docbooksectiontag_.empty())
1651 os << "\tDocBookSectionTag " << docbooksectiontag_ << '\n';
1652 if(!docbookitemtag_.empty())
1653 os << "\tDocBookItemTag " << docbookitemtag_ << '\n';
1654 if(!docbookitemattr_.empty())
1655 os << "\tDocBookItemAttr " << docbookitemattr_ << '\n';
1656 if(!docbookitemtagtype_.empty())
1657 os << "\tDocBookItemTagType " << docbookitemtagtype_ << '\n';
1658 if(!docbookitemwrappertag_.empty())
1659 os << "\tDocBookItemWrapperTag " << docbookitemwrappertag_ << '\n';
1660 if(!docbookitemwrapperattr_.empty())
1661 os << "\tDocBookItemWrapperAttr " << docbookitemwrapperattr_ << '\n';
1662 if(!docbookitemwrappertagtype_.empty())
1663 os << "\tDocBookItemWrapperTagType " << docbookitemwrappertagtype_ << '\n';
1664 os << "\tDocBookWrapperMergeWithPrevious " << docbookwrappermergewithprevious_ << '\n';
1665 if(!docbookitemlabeltag_.empty())
1666 os << "\tDocBookItemLabelTag " << docbookitemlabeltag_ << '\n';
1667 if(!docbookitemlabelattr_.empty())
1668 os << "\tDocBookItemLabelAttr " << docbookitemlabelattr_ << '\n';
1669 if(!docbookitemlabeltagtype_.empty())
1670 os << "\tDocBookItemLabelTagType " << docbookitemlabeltagtype_ << '\n';
1671 if(!docbookiteminnertag_.empty())
1672 os << "\tDocBookItemInnerTag " << docbookiteminnertag_ << '\n';
1673 if(!docbookiteminnerattr_.empty())
1674 os << "\tDocBookItemInnerAttr " << docbookiteminnerattr_ << '\n';
1675 if(!docbookiteminnertagtype_.empty())
1676 os << "\tDocBookItemInnerTagType " << docbookiteminnertagtype_ << '\n';
1677 if(!docbookforceabstracttag_.empty())
1678 os << "\tDocBookForceAbstractTag " << docbookforceabstracttag_ << '\n';
1679 os << "\tSpellcheck " << spellcheck << "\n"
1680 "\tForceLocal " << forcelocal << "\n"
1685 bool Layout::hasArgs() const
1687 return !latexargs_.empty() || !postcommandargs_.empty() ||
1688 !itemargs_.empty() || !listpreamble_.empty();
1692 Layout::LaTeXArgMap Layout::args() const
1694 LaTeXArgMap args = latexargs_;
1695 if (!postcommandargs_.empty())
1696 args.insert(postcommandargs_.begin(), postcommandargs_.end());
1697 if (!listpreamble_.empty())
1698 args.insert(listpreamble_.begin(), listpreamble_.end());
1699 if (!itemargs_.empty())
1700 args.insert(itemargs_.begin(), itemargs_.end());
1705 int Layout::optArgs() const
1708 LaTeXArgMap::const_iterator it = latexargs_.begin();
1709 for (; it != latexargs_.end(); ++it) {
1710 if (!(*it).second.mandatory)
1713 LaTeXArgMap::const_iterator iit = postcommandargs_.begin();
1714 for (; iit != postcommandargs_.end(); ++iit) {
1715 if (!(*iit).second.mandatory)
1722 int Layout::requiredArgs() const
1725 LaTeXArgMap::const_iterator it = latexargs_.begin();
1726 for (; it != latexargs_.end(); ++it) {
1727 if ((*it).second.mandatory)
1730 LaTeXArgMap::const_iterator iit = postcommandargs_.begin();
1731 for (; iit != postcommandargs_.end(); ++iit) {
1732 if (!(*iit).second.mandatory)
1739 string const & Layout::htmltag() const
1741 if (htmltag_.empty())
1747 string const & Layout::htmlattr() const
1749 if (htmlattr_.empty())
1750 htmlattr_ = "class=\"" + defaultCSSClass() + "\"";
1755 string const & Layout::htmlitemtag() const
1757 if (htmlitemtag_.empty())
1758 htmlitemtag_ = "div";
1759 return htmlitemtag_;
1763 string const & Layout::htmlitemattr() const
1765 if (htmlitemattr_.empty())
1766 htmlitemattr_ = "class=\"" + defaultCSSItemClass() + "\"";
1767 return htmlitemattr_;
1771 string const & Layout::htmllabeltag() const
1773 if (htmllabeltag_.empty())
1774 htmllabeltag_ = "span";
1775 return htmllabeltag_;
1779 string const & Layout::htmllabelattr() const
1781 if (htmllabelattr_.empty())
1782 htmllabelattr_ = "class=\"" + defaultCSSLabelClass() + "\"";
1783 return htmllabelattr_;
1787 docstring Layout::htmlstyle() const
1789 if (!htmlstyle_.empty() && !htmlforcecss_)
1791 if (htmldefaultstyle_.empty())
1793 docstring retval = htmldefaultstyle_;
1794 if (!htmlstyle_.empty())
1795 retval += '\n' + htmlstyle_;
1800 string Layout::defaultCSSClass() const
1802 if (!defaultcssclass_.empty())
1803 return defaultcssclass_;
1805 docstring::const_iterator it = name().begin();
1806 docstring::const_iterator en = name().end();
1807 for (; it != en; ++it) {
1808 char_type const c = *it;
1809 if (!isAlphaASCII(c)) {
1811 // make sure we don't start with an underscore,
1812 // as that sometimes causes problems.
1813 d = from_ascii("lyx_");
1816 } else if (isLower(c))
1819 // this is slow, so do it only if necessary
1822 defaultcssclass_ = to_utf8(d);
1823 return defaultcssclass_;
1827 string const & Layout::docbooktag() const
1829 if (docbooktag_.empty()) {
1830 if (to_ascii(name_) == "Plain Layout")
1831 docbooktag_ = "para";
1832 else // No sensible default value, unhappily...
1833 docbooktag_ = to_utf8(name_);
1839 string const & Layout::docbookattr() const
1841 // Perfectly OK to return no attributes, so docbookattr_ does not need to be filled.
1842 return docbookattr_;
1846 bool isValidTagType(std::string type)
1848 return !(type.empty() || (type != "block" && type != "paragraph" && type != "inline"));
1852 string const & Layout::docbooktagtype() const
1854 if (!isValidTagType(docbooktagtype_))
1855 docbooktagtype_ = "block";
1856 return docbooktagtype_;
1860 string const & Layout::docbookininfo() const
1862 // Indeed, a trilean. Only titles should be "maybe": otherwise, metadata is "always", content is "never".
1863 if (docbookininfo_.empty() || (docbookininfo_ != "never" && docbookininfo_ != "always" && docbookininfo_ != "maybe"))
1864 docbookininfo_ = "never";
1865 return docbookininfo_;
1869 string const & Layout::docbookwrappertag() const
1871 if (docbookwrappertag_.empty())
1872 docbookwrappertag_ = "NONE";
1873 return docbookwrappertag_;
1877 string const & Layout::docbookwrapperattr() const
1879 return docbookwrapperattr_;
1883 string const & Layout::docbookwrappertagtype() const
1885 if (!isValidTagType(docbookwrappertagtype_))
1886 docbookwrappertagtype_ = "block";
1887 return docbookwrappertagtype_;
1891 string const & Layout::docbooksectiontag() const
1893 if (docbooksectiontag_.empty())
1894 docbooksectiontag_ = "section";
1895 return docbooksectiontag_;
1899 string const & Layout::docbookitemwrappertag() const
1901 if (docbookitemwrappertag_.empty())
1902 docbookitemwrappertag_ = "NONE";
1903 return docbookitemwrappertag_;
1907 string const & Layout::docbookitemwrapperattr() const
1909 return docbookitemwrapperattr_;
1913 string const & Layout::docbookitemwrappertagtype() const
1915 if (!isValidTagType(docbookitemwrappertagtype_))
1916 docbookitemwrappertagtype_ = "block";
1917 return docbookitemwrappertagtype_;
1921 string const & Layout::docbookitemtag() const
1923 if (docbookitemtag_.empty())
1924 docbookitemtag_ = "NONE";
1925 return docbookitemtag_;
1929 string const & Layout::docbookitemattr() const
1931 return docbookitemattr_;
1935 string const & Layout::docbookitemtagtype() const
1937 if (!isValidTagType(docbookitemtagtype_))
1938 docbookitemtagtype_ = "block";
1939 return docbookitemtagtype_;
1943 string const & Layout::docbookitemlabeltag() const
1945 if (docbookitemlabeltag_.empty())
1946 docbookitemlabeltag_ = "NONE";
1947 return docbookitemlabeltag_;
1951 string const & Layout::docbookitemlabelattr() const
1953 return docbookitemlabelattr_;
1957 string const & Layout::docbookitemlabeltagtype() const
1959 if (!isValidTagType(docbookitemlabeltagtype_))
1960 docbookitemlabeltagtype_ = "block";
1961 return docbookitemlabeltagtype_;
1965 string const & Layout::docbookiteminnertag() const
1967 if (docbookiteminnertag_.empty())
1968 docbookiteminnertag_ = "NONE";
1969 return docbookiteminnertag_;
1973 string const & Layout::docbookiteminnerattr() const
1975 return docbookiteminnerattr_;
1979 string const & Layout::docbookiteminnertagtype() const
1981 if (!isValidTagType(docbookiteminnertagtype_))
1982 docbookiteminnertagtype_ = "block";
1983 return docbookiteminnertagtype_;
1987 std::string const & Layout::docbookforceabstracttag() const
1989 if (docbookforceabstracttag_.empty())
1990 docbookforceabstracttag_ = "NONE";
1991 return docbookforceabstracttag_;
1998 string makeMarginValue(char const * side, double d)
2001 os << "margin-" << side << ": " << d << "ex;\n";
2008 void Layout::makeDefaultCSS() const
2010 // this never needs to be redone, since reloading layouts will
2011 // wipe out what we did before.
2012 if (!htmldefaultstyle_.empty())
2016 htmldefaultstyle_ = font.asCSS();
2021 tmp += makeMarginValue("top", topsep);
2023 tmp += makeMarginValue("bottom", bottomsep);
2024 if (!leftmargin.empty()) {
2025 // we can't really do what LyX does with the margin, so
2026 // we'll just figure out how many characters it is
2027 int const len = leftmargin.length();
2028 tmp += makeMarginValue("left", len);
2030 if (!rightmargin.empty()) {
2031 int const len = rightmargin.length();
2032 tmp += makeMarginValue("right", len);
2036 if (!htmldefaultstyle_.empty())
2037 htmldefaultstyle_ += from_ascii("\n");
2038 htmldefaultstyle_ += from_ascii(tmp);
2042 string where = alignmentToCSS(align);
2043 if (!where.empty()) {
2044 htmldefaultstyle_ += from_ascii("text-align: " + where + ";\n");
2047 // wrap up what we have, if anything
2048 if (!htmldefaultstyle_.empty())
2050 from_ascii(htmltag() + "." + defaultCSSClass() + " {\n") +
2051 htmldefaultstyle_ + from_ascii("\n}\n");
2053 if (labeltype == LABEL_NO_LABEL || htmllabeltag() == "NONE")
2059 if (labelfont != font)
2060 labelCSS = labelfont.asCSS() + from_ascii("\n");
2061 if (labeltype == LABEL_CENTERED)
2062 labelCSS += from_ascii("text-align: center;\n");
2064 if (!labelCSS.empty())
2065 htmldefaultstyle_ +=
2066 from_ascii(htmllabeltag() + "." + defaultCSSLabelClass() + " {\n") +
2067 labelCSS + from_ascii("\n}\n");
2071 bool Layout::operator==(Layout const & rhs) const
2073 // This is enough for the applications we actually make,
2074 // at least at the moment. But we could check more.
2075 return name() == rhs.name()
2076 && latexname() == rhs.latexname()
2077 && latextype == rhs.latextype;