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 to not belong in 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,
113 LT_STEPMASTERCOUNTER,
119 LT_INTITLE // keep this last!
122 /////////////////////
125 : add_to_toc_(false), is_toc_caption_(true)
128 margintype = MARGIN_STATIC;
129 latextype = LATEX_PARAGRAPH;
130 resumecounter = false;
131 stepmastercounter = false;
135 needcprotect = false;
136 needmboxprotect = false;
139 labelfont = inherit_font;
141 reslabelfont = sane_font;
142 nextnoindent = false;
147 labelbottomsep = 0.0;
149 align = LYX_ALIGN_BLOCK;
150 alignpossible = LYX_ALIGN_NONE | LYX_ALIGN_LAYOUT;
151 labeltype = LABEL_NO_LABEL;
152 endlabeltype = END_LABEL_NO_LABEL;
153 // Should or should not. That is the question.
154 // spacing.set(Spacing::OneHalf);
155 newline_allowed = true;
156 free_spacing = false;
158 parbreak_is_newline = false;
159 toclevel = NOT_IN_TOC;
161 htmllabelfirst_ = false;
162 htmlforcecss_ = false;
166 itemcommand_ = "item";
167 toggle_indent = ITOGGLE_DOCUMENT_DEFAULT;
172 bool Layout::read(Lexer & lex, TextClass const & tclass)
174 // If this is an empty layout, or if no force local version is set,
175 // we know that we will not discard the stuff to read
177 return readIgnoreForcelocal(lex, tclass);
180 bool const ret = tmp.readIgnoreForcelocal(lex, tclass);
182 // - the read version is higher
183 // - both versions are infinity (arbitrary decision)
184 // - the file did not contain any local version (needed for not
185 // skipping user defined local layouts)
186 if (tmp.forcelocal <= 0 || tmp.forcelocal > forcelocal)
192 bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass)
194 // This table is sorted alphabetically [asierra 30March96]
195 LexerKeyword layoutTags[] = {
196 { "addtotoc", LT_ADDTOTOC },
197 { "align", LT_ALIGN },
198 { "alignpossible", LT_ALIGNPOSSIBLE },
199 { "argument", LT_ARGUMENT },
200 { "autonests", LT_AUTONESTS },
201 { "babelpreamble", LT_BABELPREAMBLE },
202 { "bottomsep", LT_BOTTOMSEP },
203 { "category", LT_CATEGORY },
204 { "commanddepth", LT_COMMANDDEPTH },
205 { "copystyle", LT_COPYSTYLE },
206 { "dependson", LT_DEPENDSON },
208 { "endlabelstring", LT_ENDLABELSTRING },
209 { "endlabeltype", LT_ENDLABELTYPE },
211 { "forcelocal", LT_FORCELOCAL },
212 { "freespacing", LT_FREE_SPACING },
213 { "htmlattr", LT_HTMLATTR },
214 { "htmlforcecss", LT_HTMLFORCECSS },
215 { "htmlitem", LT_HTMLITEM },
216 { "htmlitemattr", LT_HTMLITEMATTR },
217 { "htmllabel", LT_HTMLLABEL },
218 { "htmllabelattr", LT_HTMLLABELATTR },
219 { "htmllabelfirst", LT_HTMLLABELFIRST },
220 { "htmlpreamble", LT_HTMLPREAMBLE },
221 { "htmlstyle", LT_HTMLSTYLE },
222 { "htmltag", LT_HTMLTAG },
223 { "htmltitle", LT_HTMLTITLE },
224 { "innertag", LT_INNERTAG },
225 { "inpreamble", LT_INPREAMBLE },
226 { "intitle", LT_INTITLE },
227 { "isautonestedby", LT_AUTONESTEDBY },
228 { "istoccaption", LT_ISTOCCAPTION },
229 { "itemcommand", LT_ITEMCOMMAND },
230 { "itemsep", LT_ITEMSEP },
231 { "itemtag", LT_ITEMTAG },
232 { "keepempty", LT_KEEPEMPTY },
233 { "labelbottomsep", LT_LABEL_BOTTOMSEP },
234 { "labelcounter", LT_LABELCOUNTER },
235 { "labelfont", LT_LABELFONT },
236 { "labelindent", LT_LABELINDENT },
237 { "labelsep", LT_LABELSEP },
238 { "labelstring", LT_LABELSTRING },
239 { "labelstringappendix", LT_LABELSTRING_APPENDIX },
240 { "labeltag", LT_LABELTAG },
241 { "labeltype", LT_LABELTYPE },
242 { "langpreamble", LT_LANGPREAMBLE },
243 { "latexname", LT_LATEXNAME },
244 { "latexparam", LT_LATEXPARAM },
245 { "latextype", LT_LATEXTYPE },
246 { "leftdelim", LT_LEFTDELIM },
247 { "leftmargin", LT_LEFTMARGIN },
248 { "margin", LT_MARGIN },
249 { "needcprotect", LT_NEED_CPROTECT },
250 { "needmboxprotect", LT_NEED_MBOXPROTECT },
251 { "needprotect", LT_NEED_PROTECT },
252 { "newline", LT_NEWLINE },
253 { "nextnoindent", LT_NEXTNOINDENT },
254 { "obsoletedby", LT_OBSOLETEDBY },
255 { "paragraphgroup", LT_PAR_GROUP },
256 { "parbreakisnewline", LT_PARBREAK_IS_NEWLINE },
257 { "parindent", LT_PARINDENT },
258 { "parsep", LT_PARSEP },
259 { "parskip", LT_PARSKIP },
260 { "passthru", LT_PASS_THRU },
261 { "passthruchars", LT_PASS_THRU_CHARS },
262 { "preamble", LT_PREAMBLE },
263 { "refprefix", LT_REFPREFIX },
264 { "requires", LT_REQUIRES },
265 { "resetargs", LT_RESETARGS },
266 { "resumecounter", LT_RESUMECOUNTER },
267 { "rightdelim", LT_RIGHTDELIM },
268 { "rightmargin", LT_RIGHTMARGIN },
269 { "spacing", LT_SPACING },
270 { "spellcheck", LT_SPELLCHECK },
271 { "stepmastercounter", LT_STEPMASTERCOUNTER },
272 { "textfont", LT_TEXTFONT },
273 { "toclevel", LT_TOCLEVEL },
274 { "toggleindent", LT_TOGGLE_INDENT },
275 { "topsep", LT_TOPSEP }
279 bool finished = false;
280 lex.pushTable(layoutTags);
282 // parse style section
283 while (!finished && lex.isOK() && !error) {
285 // See comment in LyXRC.cpp.
287 case Lexer::LEX_FEOF:
290 case Lexer::LEX_UNDEF:
292 lex.printError("Unknown layout tag `$$Token'");
299 switch (static_cast<LayoutTags>(le)) {
311 style = subst(style, '_', ' ');
313 if (tclass.hasLayout(style)) {
314 docstring const tmpname = name_;
315 this->operator=(tclass[style]);
318 LYXERR0("Cannot copy unknown style `"
320 << "All layouts so far:");
321 DocumentClass::const_iterator lit = tclass.begin();
322 DocumentClass::const_iterator len = tclass.end();
323 for (; lit != len; ++lit)
324 LYXERR0(lit->name());
329 case LT_OBSOLETEDBY: {
332 style = subst(style, '_', ' ');
334 if (tclass.hasLayout(style)) {
335 docstring const tmpname = name_;
336 this->operator=(tclass[style]);
338 if (obsoleted_by().empty())
339 obsoleted_by_ = style;
341 LYXERR0("Cannot replace with unknown style `"
344 //lex.printError("Cannot replace with"
353 depends_on_ = subst(depends_on_, '_', ' ');
382 postcommandargs_.clear();
383 listpreamble_.clear();
387 case LT_RESUMECOUNTER:
388 lex >> resumecounter;
391 case LT_STEPMASTERCOUNTER:
392 lex >> stepmastercounter;
399 case LT_NEED_PROTECT:
403 case LT_NEED_CPROTECT:
407 case LT_NEED_MBOXPROTECT:
408 lex >> needmboxprotect;
416 font = lyxRead(lex, font);
421 font = lyxRead(lex, font);
425 labelfont = lyxRead(lex, labelfont);
428 case LT_NEXTNOINDENT:
432 case LT_TOGGLE_INDENT: {
435 tog = support::ascii_lowercase(tog);
437 toggle_indent = ITOGGLE_ALWAYS;
438 else if (tog == "never")
439 toggle_indent = ITOGGLE_NEVER;
441 toggle_indent = ITOGGLE_DOCUMENT_DEFAULT;
445 case LT_COMMANDDEPTH:
455 latexparam_ = subst(latexparam_, """, "\"");
460 leftdelim_ = support::subst(leftdelim_, from_ascii("<br/>"),
466 rightdelim_ = support::subst(rightdelim_, from_ascii("<br/>"),
487 preamble_ = lex.getLongString(from_ascii("EndPreamble"));
490 case LT_LANGPREAMBLE:
491 langpreamble_ = lex.getLongString(from_ascii("EndLangPreamble"));
494 case LT_BABELPREAMBLE:
495 babelpreamble_ = lex.getLongString(from_ascii("EndBabelPreamble"));
502 case LT_ENDLABELTYPE:
503 readEndLabelType(lex);
538 case LT_LABEL_BOTTOMSEP:
539 lex >> labelbottomsep;
544 labelsep = subst(labelsep, 'x', ' ');
552 lex >> newline_allowed;
559 case LT_ALIGNPOSSIBLE:
560 readAlignPossible(lex);
564 // FIXME: this means LT_LABELSTRING_APPENDIX may only
565 // occur after LT_LABELSTRING
567 labelstring_appendix_ = labelstring_;
570 case LT_ENDLABELSTRING:
571 lex >> endlabelstring_;
574 case LT_LABELSTRING_APPENDIX:
575 lex >> labelstring_appendix_;
578 case LT_LABELCOUNTER:
586 case LT_FREE_SPACING:
594 case LT_PASS_THRU_CHARS:
595 lex >> pass_thru_chars;
598 case LT_PARBREAK_IS_NEWLINE:
599 lex >> parbreak_is_newline;
608 vector<string> const req =
609 getVectorFromString(lex.getString(true));
610 requires_.insert(req.begin(), req.end());
615 docstring autonest = lex.getLongString(from_ascii("EndAutoNests"));
616 autonest = subst(autonest, from_ascii("\n"), docstring());
617 autonest = subst(autonest, from_ascii("\t"), docstring());
618 autonest = subst(autonest, from_ascii("\""), docstring());
619 autonest = subst(autonest, '_', ' ');
620 vector<docstring> const autonests =
621 getVectorFromString(autonest, from_ascii(","), false, true);
622 autonests_.insert(autonests.begin(), autonests.end());
626 case LT_AUTONESTEDBY: {
627 docstring autonest = lex.getLongString(from_ascii("EndIsAutoNestedBy"));
628 autonest = subst(autonest, from_ascii("\n"), docstring());
629 autonest = subst(autonest, from_ascii("\t"), docstring());
630 autonest = subst(autonest, from_ascii("\""), docstring());
631 autonest = subst(autonest, '_', ' ');
632 vector<docstring> const autonests =
633 getVectorFromString(autonest, from_ascii(","), false, true);
634 autonested_by_.insert(autonests.begin(), autonests.end());
660 case LT_HTMLITEMATTR:
661 lex >> htmlitemattr_;
665 lex >> htmllabeltag_;
668 case LT_HTMLLABELATTR:
669 lex >> htmllabelattr_;
672 case LT_HTMLLABELFIRST:
673 lex >> htmllabelfirst_;
677 htmlstyle_ = lex.getLongString(from_ascii("EndHTMLStyle"));
680 case LT_HTMLFORCECSS:
681 lex >> htmlforcecss_;
684 case LT_HTMLPREAMBLE:
685 htmlpreamble_ = lex.getLongString(from_ascii("EndPreamble"));
702 add_to_toc_ = !toc_type_.empty();
705 case LT_ISTOCCAPTION:
706 lex >> is_toc_caption_;
712 // make sure we only have inpreamble = true for commands
713 if (inpreamble && latextype != LATEX_COMMAND && latextype != LATEX_PARAGRAPH) {
714 LYXERR0("InPreamble not permitted except with command and paragraph layouts.");
715 LYXERR0("Layout name: " << name());
719 return finished && !error;
732 LexerKeyword alignTags[] = {
733 { "block", AT_BLOCK },
734 { "center", AT_CENTER },
735 { "layout", AT_LAYOUT },
737 { "right", AT_RIGHT }
741 void Layout::readAlign(Lexer & lex)
743 PushPopHelper pph(lex, alignTags);
746 case Lexer::LEX_UNDEF:
747 lex.printError("Unknown alignment `$$Token'");
753 align = LYX_ALIGN_BLOCK;
756 align = LYX_ALIGN_LEFT;
759 align = LYX_ALIGN_RIGHT;
762 align = LYX_ALIGN_CENTER;
765 align = LYX_ALIGN_LAYOUT;
771 void Layout::readAlignPossible(Lexer & lex)
773 lex.pushTable(alignTags);
774 alignpossible = LYX_ALIGN_NONE | LYX_ALIGN_LAYOUT;
775 int lineno = lex.lineNumber();
779 case Lexer::LEX_UNDEF:
780 lex.printError("Unknown alignment `$$Token'");
786 alignpossible |= LYX_ALIGN_BLOCK;
789 alignpossible |= LYX_ALIGN_LEFT;
792 alignpossible |= LYX_ALIGN_RIGHT;
795 alignpossible |= LYX_ALIGN_CENTER;
798 alignpossible |= LYX_ALIGN_LAYOUT;
801 } while (lineno == lex.lineNumber());
806 void Layout::readLabelType(Lexer & lex)
821 LexerKeyword labelTypeTags[] = {
822 { "above", LA_ABOVE },
823 { "bibliography", LA_BIBLIO },
824 { "centered", LA_CENTERED },
825 { "enumerate", LA_ENUMERATE },
826 { "itemize", LA_ITEMIZE },
827 { "manual", LA_MANUAL },
828 { "no_label", LA_NO_LABEL },
829 { "sensitive", LA_SENSITIVE },
830 { "static", LA_STATIC }
833 PushPopHelper pph(lex, labelTypeTags);
836 case Lexer::LEX_UNDEF:
837 lex.printError("Unknown labeltype tag `$$Token'");
843 labeltype = LABEL_NO_LABEL;
846 labeltype = LABEL_MANUAL;
849 labeltype = LABEL_ABOVE;
852 labeltype = LABEL_CENTERED;
855 labeltype = LABEL_STATIC;
858 labeltype = LABEL_SENSITIVE;
861 labeltype = LABEL_ENUMERATE;
864 labeltype = LABEL_ITEMIZE;
867 labeltype = LABEL_BIBLIO;
873 void Layout::readEndLabelType(Lexer & lex)
875 // this should be const, but can't be because
877 static LexerKeyword endlabelTypeTags[] = {
878 { "box", END_LABEL_BOX },
879 { "filled_box", END_LABEL_FILLED_BOX },
880 { "no_label", END_LABEL_NO_LABEL },
881 { "static", END_LABEL_STATIC }
884 PushPopHelper pph(lex, endlabelTypeTags);
887 case Lexer::LEX_UNDEF:
888 lex.printError("Unknown labeltype tag `$$Token'");
890 case END_LABEL_STATIC:
892 case END_LABEL_FILLED_BOX:
893 case END_LABEL_NO_LABEL:
894 endlabeltype = static_cast<EndLabelType>(le);
897 LYXERR0("Unhandled value " << le);
903 void Layout::readMargin(Lexer & lex)
905 LexerKeyword marginTags[] = {
906 { "dynamic", MARGIN_DYNAMIC },
907 { "first_dynamic", MARGIN_FIRST_DYNAMIC },
908 { "manual", MARGIN_MANUAL },
909 { "right_address_box", MARGIN_RIGHT_ADDRESS_BOX },
910 { "static", MARGIN_STATIC }
913 PushPopHelper pph(lex, marginTags);
917 case Lexer::LEX_UNDEF:
918 lex.printError("Unknown margin type tag `$$Token'");
923 case MARGIN_FIRST_DYNAMIC:
924 case MARGIN_RIGHT_ADDRESS_BOX:
925 margintype = static_cast<MarginType>(le);
928 LYXERR0("Unhandled value " << le);
934 void Layout::readLatexType(Lexer & lex)
936 LexerKeyword latexTypeTags[] = {
937 { "bib_environment", LATEX_BIB_ENVIRONMENT },
938 { "command", LATEX_COMMAND },
939 { "environment", LATEX_ENVIRONMENT },
940 { "item_environment", LATEX_ITEM_ENVIRONMENT },
941 { "list_environment", LATEX_LIST_ENVIRONMENT },
942 { "paragraph", LATEX_PARAGRAPH }
945 PushPopHelper pph(lex, latexTypeTags);
948 case Lexer::LEX_UNDEF:
949 lex.printError("Unknown latextype tag `$$Token'");
951 case LATEX_PARAGRAPH:
953 case LATEX_ITEM_ENVIRONMENT:
954 case LATEX_LIST_ENVIRONMENT:
955 latextype = static_cast<LatexType>(le);
957 case LATEX_ENVIRONMENT:
958 case LATEX_BIB_ENVIRONMENT:
959 latextype = static_cast<LatexType>(le);
963 LYXERR0("Unhandled value " << le);
969 void Layout::readSpacing(Lexer & lex)
972 ST_SPACING_SINGLE = 1,
978 LexerKeyword spacingTags[] = {
979 {"double", ST_SPACING_DOUBLE },
980 {"onehalf", ST_SPACING_ONEHALF },
981 {"other", ST_OTHER },
982 {"single", ST_SPACING_SINGLE }
985 PushPopHelper pph(lex, spacingTags);
988 case Lexer::LEX_UNDEF:
989 lex.printError("Unknown spacing token `$$Token'");
994 case ST_SPACING_SINGLE:
995 spacing.set(Spacing::Single);
997 case ST_SPACING_ONEHALF:
998 spacing.set(Spacing::Onehalf);
1000 case ST_SPACING_DOUBLE:
1001 spacing.set(Spacing::Double);
1005 spacing.set(Spacing::Other, lex.getString());
1011 void Layout::readArgument(Lexer & lex)
1014 // writeArgument() makes use of these default values
1015 arg.mandatory = false;
1016 arg.nodelims = false;
1017 arg.autoinsert = false;
1018 arg.insertcotext = false;
1020 bool finished = false;
1021 arg.font = inherit_font;
1022 arg.labelfont = inherit_font;
1023 arg.is_toc_caption = false;
1024 arg.passthru = PT_INHERITED;
1025 arg.free_spacing = false;
1028 bool const itemarg = prefixIs(id, "item:");
1029 bool const postcmd = prefixIs(id, "post:");
1030 bool const listpreamble = prefixIs(id, "listpreamble:");
1032 while (!finished && lex.isOK() && !error) {
1034 string const tok = ascii_lowercase(lex.getString());
1038 } else if (tok == "endargument") {
1040 } else if (tok == "labelstring") {
1042 arg.labelstring = lex.getDocString();
1043 } else if (tok == "menustring") {
1045 arg.menustring = lex.getDocString();
1046 } else if (tok == "mandatory") {
1048 arg.mandatory = lex.getBool();
1049 } else if (tok == "autoinsert") {
1051 arg.autoinsert = lex.getBool();
1052 } else if (tok == "insertcotext") {
1054 arg.insertcotext = lex.getBool();
1055 } else if (tok == "leftdelim") {
1057 arg.ldelim = lex.getDocString();
1058 arg.ldelim = support::subst(arg.ldelim, from_ascii("<br/>"),
1060 } else if (tok == "rightdelim") {
1062 arg.rdelim = lex.getDocString();
1063 arg.rdelim = support::subst(arg.rdelim, from_ascii("<br/>"),
1065 } else if (tok == "defaultarg") {
1067 arg.defaultarg = lex.getDocString();
1068 } else if (tok == "presetarg") {
1070 arg.presetarg = lex.getDocString();
1071 } else if (tok == "tooltip") {
1073 arg.tooltip = lex.getDocString();
1074 } else if (tok == "requires") {
1076 arg.requires = lex.getString();
1077 } else if (tok == "decoration") {
1079 arg.decoration = lex.getString();
1080 } else if (tok == "newlinecmd") {
1082 arg.newlinecmd = lex.getString();
1083 } else if (tok == "font") {
1084 arg.font = lyxRead(lex, arg.font);
1085 } else if (tok == "labelfont") {
1086 arg.labelfont = lyxRead(lex, arg.labelfont);
1087 } else if (tok == "passthruchars") {
1089 arg.pass_thru_chars = lex.getDocString();
1090 } else if (tok == "passthru") {
1092 docstring value = lex.getDocString();
1093 if (value == "true" || value == "1")
1094 arg.passthru = PT_TRUE;
1095 else if (value == "false" || value == "0")
1096 arg.passthru = PT_FALSE;
1098 arg.passthru = PT_INHERITED;
1099 } else if (tok == "istoccaption") {
1101 arg.is_toc_caption = lex.getBool();
1102 } else if (tok == "freespacing") {
1104 arg.free_spacing = lex.getBool();
1106 lex.printError("Unknown tag");
1110 if (arg.labelstring.empty())
1111 LYXERR0("Incomplete Argument definition!");
1113 itemargs_[id] = arg;
1115 postcommandargs_[id] = arg;
1116 else if (listpreamble) {
1117 // list preamble has no delimiters by default
1118 arg.nodelims = true;
1119 listpreamble_[id] = arg;
1121 latexargs_[id] = arg;
1125 void writeArgument(ostream & os, string const & id, Layout::latexarg const & arg)
1127 os << "\tArgument " << id << '\n';
1128 if (!arg.labelstring.empty())
1129 os << "\t\tLabelString \"" << to_utf8(arg.labelstring) << "\"\n";
1130 if (!arg.menustring.empty())
1131 os << "\t\tMenuString \"" << to_utf8(arg.menustring) << "\"\n";
1133 os << "\t\tMandatory " << arg.mandatory << '\n';
1135 os << "\t\tAutoinsert " << arg.autoinsert << '\n';
1136 if (arg.insertcotext)
1137 os << "\t\tInsertCotext " << arg.insertcotext << '\n';
1138 if (!arg.ldelim.empty())
1139 os << "\t\tLeftDelim \""
1140 << to_utf8(subst(arg.ldelim, from_ascii("\n"), from_ascii("<br/>")))
1142 if (!arg.rdelim.empty())
1143 os << "\t\tRightDelim \""
1144 << to_utf8(subst(arg.rdelim, from_ascii("\n"), from_ascii("<br/>")))
1146 if (!arg.defaultarg.empty())
1147 os << "\t\tDefaultArg \"" << to_utf8(arg.defaultarg) << "\"\n";
1148 if (!arg.presetarg.empty())
1149 os << "\t\tPresetArg \"" << to_utf8(arg.presetarg) << "\"\n";
1150 if (!arg.tooltip.empty())
1151 os << "\t\tToolTip \"" << to_utf8(arg.tooltip) << "\"\n";
1152 if (!arg.requires.empty())
1153 os << "\t\tRequires \"" << arg.requires << "\"\n";
1154 if (!arg.decoration.empty())
1155 os << "\t\tDecoration \"" << arg.decoration << "\"\n";
1156 if (!arg.newlinecmd.empty())
1157 os << "\t\tNewlineCmd \"" << arg.newlinecmd << "\"\n";
1158 if (arg.font != inherit_font)
1159 lyxWrite(os, arg.font, "Font", 2);
1160 if (arg.labelfont != inherit_font)
1161 lyxWrite(os, arg.labelfont, "LabelFont", 2);
1162 switch (arg.passthru) {
1164 os << "\t\tPassThru true\n";
1167 os << "\t\tPassThru false\n";
1170 os << "\t\tPassThru inherited\n";
1173 if (!arg.pass_thru_chars.empty())
1174 os << "\t\tPassThruChars \"" << to_utf8(arg.pass_thru_chars) << "\"\n";
1175 os << "\tEndArgument\n";
1179 void Layout::write(ostream & os) const
1181 os << "Style \"" << to_utf8(name_) << "\"\n";
1182 if (!category_.empty() && obsoleted_by_.empty())
1183 os << "\tCategory \"" << to_utf8(category_) << "\"\n";
1184 // Can't deduce Copystyle here :-(
1185 if (!obsoleted_by_.empty()) {
1186 os << "\tObsoletedBy \"" << to_utf8(obsoleted_by_)
1190 if (!depends_on_.empty())
1191 os << "\tDependsOn " << to_utf8(depends_on_) << '\n';
1192 switch (margintype) {
1193 case MARGIN_DYNAMIC:
1194 os << "\tMargin Dynamic\n";
1196 case MARGIN_FIRST_DYNAMIC:
1197 os << "\tMargin First_Dynamic\n";
1200 os << "\tMargin Manual\n";
1202 case MARGIN_RIGHT_ADDRESS_BOX:
1203 os << "\tMargin Right_Address_Box\n";
1206 os << "\tMargin Static\n";
1209 switch (latextype) {
1210 case LATEX_BIB_ENVIRONMENT:
1211 os << "\tLatexType Bib_Environment\n";
1214 os << "\tLatexType Command\n";
1216 case LATEX_ENVIRONMENT:
1217 os << "\tLatexType Environment\n";
1219 case LATEX_ITEM_ENVIRONMENT:
1220 os << "\tLatexType Item_Environment\n";
1222 case LATEX_LIST_ENVIRONMENT:
1223 os << "\tLatexType List_Environment\n";
1225 case LATEX_PARAGRAPH:
1226 os << "\tLatexType Paragraph\n";
1229 os << "\tInTitle " << intitle << "\n"
1230 "\tInPreamble " << inpreamble << "\n"
1231 "\tTocLevel " << toclevel << "\n"
1232 "\tResumeCounter " << resumecounter << "\n"
1233 "\tStepMasterCounter " << stepmastercounter << '\n';
1234 // ResetArgs does not make sense here
1235 for (LaTeXArgMap::const_iterator it = latexargs_.begin();
1236 it != latexargs_.end(); ++it)
1237 writeArgument(os, it->first, it->second);
1238 for (LaTeXArgMap::const_iterator it = itemargs_.begin();
1239 it != itemargs_.end(); ++it)
1240 writeArgument(os, it->first, it->second);
1241 for (LaTeXArgMap::const_iterator it = postcommandargs_.begin();
1242 it != postcommandargs_.end(); ++it)
1243 writeArgument(os, it->first, it->second);
1244 for (LaTeXArgMap::const_iterator it = listpreamble_.begin();
1245 it != listpreamble_.end(); ++it)
1246 writeArgument(os, it->first, it->second);
1247 os << "\tNeedProtect " << needprotect << "\n"
1248 "\tNeedCProtect " << needcprotect << "\n"
1249 "\tNeedMBoxProtect " << needmboxprotect << "\n"
1250 "\tKeepEmpty " << keepempty << '\n';
1251 if (labelfont == font)
1252 lyxWrite(os, font, "Font", 1);
1254 lyxWrite(os, font, "TextFont", 1);
1255 lyxWrite(os, labelfont, "LabelFont", 1);
1257 os << "\tNextNoIndent " << nextnoindent << "\n"
1258 "\tCommandDepth " << commanddepth << '\n';
1259 if (!latexname_.empty())
1260 os << "\tLatexName \"" << latexname_ << "\"\n";
1261 if (!latexparam_.empty())
1262 os << "\tLatexParam \"" << subst(latexparam_, "\"", """)
1264 if (!leftdelim_.empty())
1265 os << "\tLeftDelim "
1266 << to_utf8(subst(leftdelim_, from_ascii("\n"), from_ascii("<br/>")))
1268 if (!rightdelim_.empty())
1269 os << "\tRightDelim "
1270 << to_utf8(subst(rightdelim_, from_ascii("\n"), from_ascii("<br/>")))
1272 if (!innertag_.empty())
1273 os << "\tInnerTag \"" << innertag_ << "\"\n";
1274 if (!labeltag_.empty())
1275 os << "\tLabelTag \"" << labeltag_ << "\"\n";
1276 if (!itemtag_.empty())
1277 os << "\tItemTag \"" << itemtag_ << "\"\n";
1278 if (!itemcommand_.empty())
1279 os << "\tItemCommand " << itemcommand_ << '\n';
1280 if (!preamble_.empty())
1281 os << "\tPreamble\n\t"
1282 << to_utf8(subst(rtrim(preamble_, "\n"),
1283 from_ascii("\n"), from_ascii("\n\t")))
1284 << "\n\tEndPreamble\n";
1285 if (!langpreamble_.empty())
1286 os << "\tLangPreamble\n\t"
1287 << to_utf8(subst(rtrim(langpreamble_, "\n"),
1288 from_ascii("\n"), from_ascii("\n\t")))
1289 << "\n\tEndLangPreamble\n";
1290 if (!babelpreamble_.empty())
1291 os << "\tBabelPreamble\n\t"
1292 << to_utf8(subst(rtrim(babelpreamble_, "\n"),
1293 from_ascii("\n"), from_ascii("\n\t")))
1294 << "\n\tEndBabelPreamble\n";
1295 switch (labeltype) {
1297 os << "\tLabelType Above\n";
1300 os << "\tLabelType Bibliography\n";
1302 case LABEL_CENTERED:
1303 os << "\tLabelType Centered\n";
1305 case LABEL_ENUMERATE:
1306 os << "\tLabelType Enumerate\n";
1309 os << "\tLabelType Itemize\n";
1312 os << "\tLabelType Manual\n";
1314 case LABEL_NO_LABEL:
1315 os << "\tLabelType No_Label\n";
1317 case LABEL_SENSITIVE:
1318 os << "\tLabelType Sensitive\n";
1321 os << "\tLabelType Static\n";
1324 switch (endlabeltype) {
1326 os << "\tEndLabelType Box\n";
1328 case END_LABEL_FILLED_BOX:
1329 os << "\tEndLabelType Filled_Box\n";
1331 case END_LABEL_NO_LABEL:
1332 os << "\tEndLabelType No_Label\n";
1334 case END_LABEL_STATIC:
1335 os << "\tEndLabelType Static\n";
1338 os << "\tParagraphGroup \"" << par_group_ << "\"\n";
1339 if (!leftmargin.empty())
1340 os << "\tLeftMargin \"" << to_utf8(leftmargin) << "\"\n";
1341 if (!rightmargin.empty())
1342 os << "\tRightMargin \"" << to_utf8(rightmargin) << "\"\n";
1343 if (!labelindent.empty())
1344 os << "\tLabelIndent " << to_utf8(labelindent) << '\n';
1345 if (!parindent.empty())
1346 os << "\tParIndent " << to_utf8(parindent) << '\n';
1347 os << "\tParSkip " << parskip << "\n"
1348 "\tItemSep " << itemsep << "\n"
1349 "\tTopSep " << topsep << "\n"
1350 "\tBottomSep " << bottomsep << "\n"
1351 "\tLabelBottomSep " << labelbottomsep << '\n';
1352 if (!labelsep.empty())
1353 os << "\tLabelSep " << to_utf8(subst(labelsep, ' ', 'x'))
1355 os << "\tParSep " << parsep << "\n"
1356 "\tNewLine " << newline_allowed << '\n';
1358 case LYX_ALIGN_BLOCK:
1359 os << "\tAlign Block\n";
1361 case LYX_ALIGN_CENTER:
1362 os << "\tAlign Center\n";
1364 case LYX_ALIGN_LAYOUT:
1365 os << "\tAlign Layout\n";
1367 case LYX_ALIGN_LEFT:
1368 os << "\tAlign Left\n";
1370 case LYX_ALIGN_RIGHT:
1371 os << "\tAlign Right\n";
1373 case LYX_ALIGN_DECIMAL:
1374 case LYX_ALIGN_SPECIAL:
1375 case LYX_ALIGN_NONE:
1378 if (alignpossible & (LYX_ALIGN_BLOCK | LYX_ALIGN_CENTER |
1379 LYX_ALIGN_LAYOUT | LYX_ALIGN_LEFT | LYX_ALIGN_RIGHT)) {
1381 os << "\tAlignPossible";
1382 if (alignpossible & LYX_ALIGN_BLOCK) {
1386 if (alignpossible & LYX_ALIGN_CENTER) {
1392 if (alignpossible & LYX_ALIGN_LAYOUT) {
1398 if (alignpossible & LYX_ALIGN_LEFT) {
1404 if (alignpossible & LYX_ALIGN_RIGHT) {
1412 // LabelString must come before LabelStringAppendix
1413 if (!labelstring_.empty())
1414 os << "\tLabelString \"" << to_utf8(labelstring_) << "\"\n";
1415 if (!endlabelstring_.empty())
1416 os << "\tEndLabelString \"" << to_utf8(endlabelstring_) << "\"\n";
1417 if (!labelstring_appendix_.empty() && labelstring_appendix_ != labelstring_)
1418 os << "\tLabelStringAppendix \""
1419 << to_utf8(labelstring_appendix_) << "\"\n";
1420 if (!counter.empty())
1421 os << "\tLabelCounter \"" << to_utf8(counter) << "\"\n";
1422 os << "\tFreeSpacing " << free_spacing << '\n';
1423 os << "\tPassThru " << pass_thru << '\n';
1424 if (!pass_thru_chars.empty())
1425 os << "\tPassThruChars " << to_utf8(pass_thru_chars) << '\n';
1426 os << "\tParbreakIsNewline " << parbreak_is_newline << '\n';
1427 switch (spacing.getSpace()) {
1428 case Spacing::Double:
1429 os << "\tSpacing Double\n";
1431 case Spacing::Onehalf:
1432 os << "\tSpacing Onehalf\n";
1434 case Spacing::Other:
1435 os << "\tSpacing Other " << spacing.getValueAsString() << '\n';
1437 case Spacing::Single:
1438 os << "\tSpacing Single\n";
1440 case Spacing::Default:
1443 if (!requires_.empty()) {
1444 os << "\tRequires ";
1445 for (set<string>::const_iterator it = requires_.begin();
1446 it != requires_.end(); ++it) {
1447 if (it != requires_.begin())
1453 if (!autonests_.empty()) {
1454 os << "\tAutoNests\n\t";
1455 for (set<docstring>::const_iterator it = autonests_.begin();
1456 it != autonests_.end(); ++it) {
1457 if (it != autonests_.begin())
1461 os << "\n\tEndAutoNests\n";
1463 if (!autonested_by_.empty()) {
1464 os << "\tIsAutoNestedBy\n\t\t";
1465 for (set<docstring>::const_iterator it = autonested_by_.begin();
1466 it != autonested_by_.end(); ++it) {
1467 if (it != autonested_by_.begin())
1471 os << "\n\tEndIsAutoNestedBy\n";
1473 if (refprefix.empty())
1474 os << "\tRefPrefix OFF\n";
1476 os << "\tRefPrefix " << to_utf8(refprefix) << '\n';
1477 if (!htmltag_.empty())
1478 os << "\tHTMLTag " << htmltag_ << '\n';
1479 if (!htmlattr_.empty())
1480 os << "\tHTMLAttr " << htmlattr_ << '\n';
1481 if (!htmlitemtag_.empty())
1482 os << "\tHTMLItem " << htmlitemtag_ << '\n';
1483 if (!htmlitemattr_.empty())
1484 os << "\tHTMLItemAttr " << htmlitemattr_ << '\n';
1485 if (!htmllabeltag_.empty())
1486 os << "\tHTMLLabel " << htmllabeltag_ << '\n';
1487 if (!htmllabelattr_.empty())
1488 os << "\tHTMLLabelAttr " << htmllabelattr_ << '\n';
1489 os << "\tHTMLLabelFirst " << htmllabelfirst_ << '\n';
1490 if (!htmlstyle_.empty())
1491 os << "\tHTMLStyle\n"
1492 << to_utf8(rtrim(htmlstyle_, "\n"))
1493 << "\n\tEndHTMLStyle\n";
1494 os << "\tHTMLForceCSS " << htmlforcecss_ << '\n';
1495 if (!htmlpreamble_.empty())
1496 os << "\tHTMLPreamble\n"
1497 << to_utf8(rtrim(htmlpreamble_, "\n"))
1498 << "\n\tEndPreamble\n";
1499 os << "\tHTMLTitle " << htmltitle_ << "\n"
1500 "\tSpellcheck " << spellcheck << "\n"
1501 "\tForceLocal " << forcelocal << "\n"
1506 bool Layout::hasArgs() const
1508 return !latexargs_.empty() || !postcommandargs_.empty() ||
1509 !itemargs_.empty() || !listpreamble_.empty();
1513 Layout::LaTeXArgMap Layout::args() const
1515 LaTeXArgMap args = latexargs_;
1516 if (!postcommandargs_.empty())
1517 args.insert(postcommandargs_.begin(), postcommandargs_.end());
1518 if (!listpreamble_.empty())
1519 args.insert(listpreamble_.begin(), listpreamble_.end());
1520 if (!itemargs_.empty())
1521 args.insert(itemargs_.begin(), itemargs_.end());
1526 int Layout::optArgs() const
1529 LaTeXArgMap::const_iterator it = latexargs_.begin();
1530 for (; it != latexargs_.end(); ++it) {
1531 if (!(*it).second.mandatory)
1534 LaTeXArgMap::const_iterator iit = postcommandargs_.begin();
1535 for (; iit != postcommandargs_.end(); ++iit) {
1536 if (!(*iit).second.mandatory)
1543 int Layout::requiredArgs() const
1546 LaTeXArgMap::const_iterator it = latexargs_.begin();
1547 for (; it != latexargs_.end(); ++it) {
1548 if ((*it).second.mandatory)
1551 LaTeXArgMap::const_iterator iit = postcommandargs_.begin();
1552 for (; iit != postcommandargs_.end(); ++iit) {
1553 if (!(*iit).second.mandatory)
1560 string const & Layout::htmltag() const
1562 if (htmltag_.empty())
1568 string const & Layout::htmlattr() const
1570 if (htmlattr_.empty())
1571 htmlattr_ = "class=\"" + defaultCSSClass() + "\"";
1576 string const & Layout::htmlitemtag() const
1578 if (htmlitemtag_.empty())
1579 htmlitemtag_ = "div";
1580 return htmlitemtag_;
1584 string const & Layout::htmlitemattr() const
1586 if (htmlitemattr_.empty())
1587 htmlitemattr_ = "class=\"" + defaultCSSItemClass() + "\"";
1588 return htmlitemattr_;
1592 string const & Layout::htmllabeltag() const
1594 if (htmllabeltag_.empty())
1595 htmllabeltag_ = "span";
1596 return htmllabeltag_;
1600 string const & Layout::htmllabelattr() const
1602 if (htmllabelattr_.empty())
1603 htmllabelattr_ = "class=\"" + defaultCSSLabelClass() + "\"";
1604 return htmllabelattr_;
1608 docstring Layout::htmlstyle() const
1610 if (!htmlstyle_.empty() && !htmlforcecss_)
1612 if (htmldefaultstyle_.empty())
1614 docstring retval = htmldefaultstyle_;
1615 if (!htmlstyle_.empty())
1616 retval += '\n' + htmlstyle_;
1621 string Layout::defaultCSSClass() const
1623 if (!defaultcssclass_.empty())
1624 return defaultcssclass_;
1626 docstring::const_iterator it = name().begin();
1627 docstring::const_iterator en = name().end();
1628 for (; it != en; ++it) {
1629 char_type const c = *it;
1630 if (!isAlphaASCII(c)) {
1632 // make sure we don't start with an underscore,
1633 // as that sometimes causes problems.
1634 d = from_ascii("lyx_");
1637 } else if (isLower(c))
1640 // this is slow, so do it only if necessary
1643 defaultcssclass_ = to_utf8(d);
1644 return defaultcssclass_;
1650 string makeMarginValue(char const * side, double d)
1653 os << "margin-" << side << ": " << d << "ex;\n";
1660 void Layout::makeDefaultCSS() const
1662 // this never needs to be redone, since reloading layouts will
1663 // wipe out what we did before.
1664 if (!htmldefaultstyle_.empty())
1668 htmldefaultstyle_ = font.asCSS();
1673 tmp += makeMarginValue("top", topsep);
1675 tmp += makeMarginValue("bottom", bottomsep);
1676 if (!leftmargin.empty()) {
1677 // we can't really do what LyX does with the margin, so
1678 // we'll just figure out how many characters it is
1679 int const len = leftmargin.length();
1680 tmp += makeMarginValue("left", len);
1682 if (!rightmargin.empty()) {
1683 int const len = rightmargin.length();
1684 tmp += makeMarginValue("right", len);
1688 if (!htmldefaultstyle_.empty())
1689 htmldefaultstyle_ += from_ascii("\n");
1690 htmldefaultstyle_ += from_ascii(tmp);
1694 string where = alignmentToCSS(align);
1695 if (!where.empty()) {
1696 htmldefaultstyle_ += from_ascii("text-align: " + where + ";\n");
1699 // wrap up what we have, if anything
1700 if (!htmldefaultstyle_.empty())
1702 from_ascii(htmltag() + "." + defaultCSSClass() + " {\n") +
1703 htmldefaultstyle_ + from_ascii("\n}\n");
1705 if (labeltype == LABEL_NO_LABEL || htmllabeltag() == "NONE")
1711 if (labelfont != font)
1712 labelCSS = labelfont.asCSS() + from_ascii("\n");
1713 if (labeltype == LABEL_CENTERED)
1714 labelCSS += from_ascii("text-align: center;\n");
1716 if (!labelCSS.empty())
1717 htmldefaultstyle_ +=
1718 from_ascii(htmllabeltag() + "." + defaultCSSLabelClass() + " {\n") +
1719 labelCSS + from_ascii("\n}\n");
1723 bool Layout::operator==(Layout const & rhs) const
1725 // This is enough for the applications we actually make,
1726 // at least at the moment. But we could check more.
1727 return name() == rhs.name()
1728 && latexname() == rhs.latexname()
1729 && latextype == rhs.latextype;