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]
56 LT_PARBREAK_IS_NEWLINE,
66 LT_LABELSTRING_APPENDIX,
110 LT_STEPMASTERCOUNTER,
116 LT_INTITLE // keep this last!
119 /////////////////////
122 : add_to_toc_(false), is_toc_caption_(false)
125 margintype = MARGIN_STATIC;
126 latextype = LATEX_PARAGRAPH;
127 resumecounter = false;
128 stepmastercounter = false;
134 labelfont = inherit_font;
136 reslabelfont = sane_font;
137 nextnoindent = false;
142 labelbottomsep = 0.0;
144 align = LYX_ALIGN_BLOCK;
145 alignpossible = LYX_ALIGN_NONE | LYX_ALIGN_LAYOUT;
146 labeltype = LABEL_NO_LABEL;
147 endlabeltype = END_LABEL_NO_LABEL;
148 // Should or should not. That is the question.
149 // spacing.set(Spacing::OneHalf);
150 newline_allowed = true;
151 free_spacing = false;
153 parbreak_is_newline = false;
154 toclevel = NOT_IN_TOC;
156 htmllabelfirst_ = false;
157 htmlforcecss_ = false;
161 itemcommand_ = "item";
162 toggle_indent = ITOGGLE_DOCUMENT_DEFAULT;
167 bool Layout::read(Lexer & lex, TextClass const & tclass)
169 // If this is an empty layout, or if no force local version is set,
170 // we know that we will not discard the stuff to read
172 return readIgnoreForcelocal(lex, tclass);
175 bool const ret = tmp.readIgnoreForcelocal(lex, tclass);
177 // - the read version is higher
178 // - both versions are infinity (arbitrary decision)
179 // - the file did not contain any local version (needed for not
180 // skipping user defined local layouts)
181 if (tmp.forcelocal <= 0 || tmp.forcelocal > forcelocal)
187 bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass)
189 // This table is sorted alphabetically [asierra 30March96]
190 LexerKeyword layoutTags[] = {
191 { "addtotoc", LT_ADDTOTOC },
192 { "align", LT_ALIGN },
193 { "alignpossible", LT_ALIGNPOSSIBLE },
194 { "argument", LT_ARGUMENT },
195 { "autonests", LT_AUTONESTS },
196 { "babelpreamble", LT_BABELPREAMBLE },
197 { "bottomsep", LT_BOTTOMSEP },
198 { "category", LT_CATEGORY },
199 { "commanddepth", LT_COMMANDDEPTH },
200 { "copystyle", LT_COPYSTYLE },
201 { "dependson", LT_DEPENDSON },
203 { "endlabelstring", LT_ENDLABELSTRING },
204 { "endlabeltype", LT_ENDLABELTYPE },
206 { "forcelocal", LT_FORCELOCAL },
207 { "freespacing", LT_FREE_SPACING },
208 { "htmlattr", LT_HTMLATTR },
209 { "htmlforcecss", LT_HTMLFORCECSS },
210 { "htmlitem", LT_HTMLITEM },
211 { "htmlitemattr", LT_HTMLITEMATTR },
212 { "htmllabel", LT_HTMLLABEL },
213 { "htmllabelattr", LT_HTMLLABELATTR },
214 { "htmllabelfirst", LT_HTMLLABELFIRST },
215 { "htmlpreamble", LT_HTMLPREAMBLE },
216 { "htmlstyle", LT_HTMLSTYLE },
217 { "htmltag", LT_HTMLTAG },
218 { "htmltitle", LT_HTMLTITLE },
219 { "innertag", LT_INNERTAG },
220 { "inpreamble", LT_INPREAMBLE },
221 { "intitle", LT_INTITLE },
222 { "istoccaption", LT_ISTOCCAPTION },
223 { "itemcommand", LT_ITEMCOMMAND },
224 { "itemsep", LT_ITEMSEP },
225 { "itemtag", LT_ITEMTAG },
226 { "keepempty", LT_KEEPEMPTY },
227 { "labelbottomsep", LT_LABEL_BOTTOMSEP },
228 { "labelcounter", LT_LABELCOUNTER },
229 { "labelfont", LT_LABELFONT },
230 { "labelindent", LT_LABELINDENT },
231 { "labelsep", LT_LABELSEP },
232 { "labelstring", LT_LABELSTRING },
233 { "labelstringappendix", LT_LABELSTRING_APPENDIX },
234 { "labeltag", LT_LABELTAG },
235 { "labeltype", LT_LABELTYPE },
236 { "langpreamble", LT_LANGPREAMBLE },
237 { "latexname", LT_LATEXNAME },
238 { "latexparam", LT_LATEXPARAM },
239 { "latextype", LT_LATEXTYPE },
240 { "leftdelim", LT_LEFTDELIM },
241 { "leftmargin", LT_LEFTMARGIN },
242 { "margin", LT_MARGIN },
243 { "needprotect", LT_NEED_PROTECT },
244 { "newline", LT_NEWLINE },
245 { "nextnoindent", LT_NEXTNOINDENT },
246 { "obsoletedby", LT_OBSOLETEDBY },
247 { "paragraphgroup", LT_PAR_GROUP },
248 { "parbreakisnewline", LT_PARBREAK_IS_NEWLINE },
249 { "parindent", LT_PARINDENT },
250 { "parsep", LT_PARSEP },
251 { "parskip", LT_PARSKIP },
252 { "passthru", LT_PASS_THRU },
253 { "passthruchars", LT_PASS_THRU_CHARS },
254 { "preamble", LT_PREAMBLE },
255 { "refprefix", LT_REFPREFIX },
256 { "requires", LT_REQUIRES },
257 { "resetargs", LT_RESETARGS },
258 { "resumecounter", LT_RESUMECOUNTER },
259 { "rightdelim", LT_RIGHTDELIM },
260 { "rightmargin", LT_RIGHTMARGIN },
261 { "spacing", LT_SPACING },
262 { "spellcheck", LT_SPELLCHECK },
263 { "stepmastercounter", LT_STEPMASTERCOUNTER },
264 { "textfont", LT_TEXTFONT },
265 { "toclevel", LT_TOCLEVEL },
266 { "toggleindent", LT_TOGGLE_INDENT },
267 { "topsep", LT_TOPSEP }
271 bool finished = false;
272 lex.pushTable(layoutTags);
274 // parse style section
275 while (!finished && lex.isOK() && !error) {
277 // See comment in LyXRC.cpp.
279 case Lexer::LEX_FEOF:
282 case Lexer::LEX_UNDEF:
284 lex.printError("Unknown layout tag `$$Token'");
291 switch (static_cast<LayoutTags>(le)) {
303 style = subst(style, '_', ' ');
305 if (tclass.hasLayout(style)) {
306 docstring const tmpname = name_;
307 this->operator=(tclass[style]);
310 LYXERR0("Cannot copy unknown style `"
312 << "All layouts so far:");
313 DocumentClass::const_iterator lit = tclass.begin();
314 DocumentClass::const_iterator len = tclass.end();
315 for (; lit != len; ++lit)
316 LYXERR0(lit->name());
321 case LT_OBSOLETEDBY: {
324 style = subst(style, '_', ' ');
326 if (tclass.hasLayout(style)) {
327 docstring const tmpname = name_;
328 this->operator=(tclass[style]);
330 if (obsoleted_by().empty())
331 obsoleted_by_ = style;
333 LYXERR0("Cannot replace with unknown style `"
336 //lex.printError("Cannot replace with"
345 depends_on_ = subst(depends_on_, '_', ' ');
374 postcommandargs_.clear();
378 case LT_RESUMECOUNTER:
379 lex >> resumecounter;
382 case LT_STEPMASTERCOUNTER:
383 lex >> stepmastercounter;
390 case LT_NEED_PROTECT:
399 font = lyxRead(lex, font);
404 font = lyxRead(lex, font);
408 labelfont = lyxRead(lex, labelfont);
411 case LT_NEXTNOINDENT:
415 case LT_TOGGLE_INDENT: {
418 tog = support::ascii_lowercase(tog);
420 toggle_indent = ITOGGLE_ALWAYS;
421 else if (tog == "never")
422 toggle_indent = ITOGGLE_NEVER;
424 toggle_indent = ITOGGLE_DOCUMENT_DEFAULT;
428 case LT_COMMANDDEPTH:
438 latexparam_ = subst(latexparam_, """, "\"");
443 leftdelim_ = support::subst(leftdelim_, from_ascii("<br/>"),
449 rightdelim_ = support::subst(rightdelim_, from_ascii("<br/>"),
470 preamble_ = lex.getLongString(from_ascii("EndPreamble"));
473 case LT_LANGPREAMBLE:
474 langpreamble_ = lex.getLongString(from_ascii("EndLangPreamble"));
477 case LT_BABELPREAMBLE:
478 babelpreamble_ = lex.getLongString(from_ascii("EndBabelPreamble"));
485 case LT_ENDLABELTYPE:
486 readEndLabelType(lex);
521 case LT_LABEL_BOTTOMSEP:
522 lex >> labelbottomsep;
527 labelsep = subst(labelsep, 'x', ' ');
535 lex >> newline_allowed;
542 case LT_ALIGNPOSSIBLE:
543 readAlignPossible(lex);
547 // FIXME: this means LT_LABELSTRING_APPENDIX may only
548 // occur after LT_LABELSTRING
550 labelstring_appendix_ = labelstring_;
553 case LT_ENDLABELSTRING:
554 lex >> endlabelstring_;
557 case LT_LABELSTRING_APPENDIX:
558 lex >> labelstring_appendix_;
561 case LT_LABELCOUNTER:
569 case LT_FREE_SPACING:
577 case LT_PASS_THRU_CHARS:
578 lex >> pass_thru_chars;
581 case LT_PARBREAK_IS_NEWLINE:
582 lex >> parbreak_is_newline;
591 vector<string> const req =
592 getVectorFromString(lex.getString(true));
593 requires_.insert(req.begin(), req.end());
598 docstring const autonest =
599 subst(subst(subst(lex.getLongString(from_ascii("EndAutoNests")),
600 from_ascii("\n"), docstring()),
601 from_ascii(" "), docstring()),
602 from_ascii("\t"), docstring());
603 vector<docstring> const autonests =
604 getVectorFromString(autonest);
605 autonests_.insert(autonests.begin(), autonests.end());
631 case LT_HTMLITEMATTR:
632 lex >> htmlitemattr_;
636 lex >> htmllabeltag_;
639 case LT_HTMLLABELATTR:
640 lex >> htmllabelattr_;
643 case LT_HTMLLABELFIRST:
644 lex >> htmllabelfirst_;
648 htmlstyle_ = lex.getLongString(from_ascii("EndHTMLStyle"));
651 case LT_HTMLFORCECSS:
652 lex >> htmlforcecss_;
655 case LT_HTMLPREAMBLE:
656 htmlpreamble_ = lex.getLongString(from_ascii("EndPreamble"));
673 add_to_toc_ = !toc_type_.empty();
676 case LT_ISTOCCAPTION:
677 lex >> is_toc_caption_;
683 // make sure we only have inpreamble = true for commands
684 if (inpreamble && latextype != LATEX_COMMAND && latextype != LATEX_PARAGRAPH) {
685 LYXERR0("InPreamble not permitted except with command and paragraph layouts.");
686 LYXERR0("Layout name: " << name());
690 return finished && !error;
703 LexerKeyword alignTags[] = {
704 { "block", AT_BLOCK },
705 { "center", AT_CENTER },
706 { "layout", AT_LAYOUT },
708 { "right", AT_RIGHT }
712 void Layout::readAlign(Lexer & lex)
714 PushPopHelper pph(lex, alignTags);
717 case Lexer::LEX_UNDEF:
718 lex.printError("Unknown alignment `$$Token'");
724 align = LYX_ALIGN_BLOCK;
727 align = LYX_ALIGN_LEFT;
730 align = LYX_ALIGN_RIGHT;
733 align = LYX_ALIGN_CENTER;
736 align = LYX_ALIGN_LAYOUT;
742 void Layout::readAlignPossible(Lexer & lex)
744 lex.pushTable(alignTags);
745 alignpossible = LYX_ALIGN_NONE | LYX_ALIGN_LAYOUT;
746 int lineno = lex.lineNumber();
750 case Lexer::LEX_UNDEF:
751 lex.printError("Unknown alignment `$$Token'");
757 alignpossible |= LYX_ALIGN_BLOCK;
760 alignpossible |= LYX_ALIGN_LEFT;
763 alignpossible |= LYX_ALIGN_RIGHT;
766 alignpossible |= LYX_ALIGN_CENTER;
769 alignpossible |= LYX_ALIGN_LAYOUT;
772 } while (lineno == lex.lineNumber());
777 void Layout::readLabelType(Lexer & lex)
792 LexerKeyword labelTypeTags[] = {
793 { "above", LA_ABOVE },
794 { "bibliography", LA_BIBLIO },
795 { "centered", LA_CENTERED },
796 { "enumerate", LA_ENUMERATE },
797 { "itemize", LA_ITEMIZE },
798 { "manual", LA_MANUAL },
799 { "no_label", LA_NO_LABEL },
800 { "sensitive", LA_SENSITIVE },
801 { "static", LA_STATIC }
804 PushPopHelper pph(lex, labelTypeTags);
807 case Lexer::LEX_UNDEF:
808 lex.printError("Unknown labeltype tag `$$Token'");
814 labeltype = LABEL_NO_LABEL;
817 labeltype = LABEL_MANUAL;
820 labeltype = LABEL_ABOVE;
823 labeltype = LABEL_CENTERED;
826 labeltype = LABEL_STATIC;
829 labeltype = LABEL_SENSITIVE;
832 labeltype = LABEL_ENUMERATE;
835 labeltype = LABEL_ITEMIZE;
838 labeltype = LABEL_BIBLIO;
844 void Layout::readEndLabelType(Lexer & lex)
846 // this should be const, but can't be because
848 static LexerKeyword endlabelTypeTags[] = {
849 { "box", END_LABEL_BOX },
850 { "filled_box", END_LABEL_FILLED_BOX },
851 { "no_label", END_LABEL_NO_LABEL },
852 { "static", END_LABEL_STATIC }
855 PushPopHelper pph(lex, endlabelTypeTags);
858 case Lexer::LEX_UNDEF:
859 lex.printError("Unknown labeltype tag `$$Token'");
861 case END_LABEL_STATIC:
863 case END_LABEL_FILLED_BOX:
864 case END_LABEL_NO_LABEL:
865 endlabeltype = static_cast<EndLabelType>(le);
868 LYXERR0("Unhandled value " << le);
874 void Layout::readMargin(Lexer & lex)
876 LexerKeyword marginTags[] = {
877 { "dynamic", MARGIN_DYNAMIC },
878 { "first_dynamic", MARGIN_FIRST_DYNAMIC },
879 { "manual", MARGIN_MANUAL },
880 { "right_address_box", MARGIN_RIGHT_ADDRESS_BOX },
881 { "static", MARGIN_STATIC }
884 PushPopHelper pph(lex, marginTags);
888 case Lexer::LEX_UNDEF:
889 lex.printError("Unknown margin type tag `$$Token'");
894 case MARGIN_FIRST_DYNAMIC:
895 case MARGIN_RIGHT_ADDRESS_BOX:
896 margintype = static_cast<MarginType>(le);
899 LYXERR0("Unhandled value " << le);
905 void Layout::readLatexType(Lexer & lex)
907 LexerKeyword latexTypeTags[] = {
908 { "bib_environment", LATEX_BIB_ENVIRONMENT },
909 { "command", LATEX_COMMAND },
910 { "environment", LATEX_ENVIRONMENT },
911 { "item_environment", LATEX_ITEM_ENVIRONMENT },
912 { "list_environment", LATEX_LIST_ENVIRONMENT },
913 { "paragraph", LATEX_PARAGRAPH }
916 PushPopHelper pph(lex, latexTypeTags);
919 case Lexer::LEX_UNDEF:
920 lex.printError("Unknown latextype tag `$$Token'");
922 case LATEX_PARAGRAPH:
924 case LATEX_ITEM_ENVIRONMENT:
925 case LATEX_LIST_ENVIRONMENT:
926 latextype = static_cast<LatexType>(le);
928 case LATEX_ENVIRONMENT:
929 case LATEX_BIB_ENVIRONMENT:
930 latextype = static_cast<LatexType>(le);
934 LYXERR0("Unhandled value " << le);
940 void Layout::readSpacing(Lexer & lex)
943 ST_SPACING_SINGLE = 1,
949 LexerKeyword spacingTags[] = {
950 {"double", ST_SPACING_DOUBLE },
951 {"onehalf", ST_SPACING_ONEHALF },
952 {"other", ST_OTHER },
953 {"single", ST_SPACING_SINGLE }
956 PushPopHelper pph(lex, spacingTags);
959 case Lexer::LEX_UNDEF:
960 lex.printError("Unknown spacing token `$$Token'");
965 case ST_SPACING_SINGLE:
966 spacing.set(Spacing::Single);
968 case ST_SPACING_ONEHALF:
969 spacing.set(Spacing::Onehalf);
971 case ST_SPACING_DOUBLE:
972 spacing.set(Spacing::Double);
976 spacing.set(Spacing::Other, lex.getString());
982 void Layout::readArgument(Lexer & lex)
985 // writeArgument() makes use of these default values
986 arg.mandatory = false;
987 arg.autoinsert = false;
988 arg.insertcotext = false;
990 bool finished = false;
991 arg.font = inherit_font;
992 arg.labelfont = inherit_font;
993 arg.is_toc_caption = false;
994 arg.passthru = PT_INHERITED;
997 bool const itemarg = prefixIs(id, "item:");
998 bool const postcmd = prefixIs(id, "post:");
1000 while (!finished && lex.isOK() && !error) {
1002 string const tok = ascii_lowercase(lex.getString());
1006 } else if (tok == "endargument") {
1008 } else if (tok == "labelstring") {
1010 arg.labelstring = lex.getDocString();
1011 } else if (tok == "menustring") {
1013 arg.menustring = lex.getDocString();
1014 } else if (tok == "mandatory") {
1016 arg.mandatory = lex.getBool();
1017 } else if (tok == "autoinsert") {
1019 arg.autoinsert = lex.getBool();
1020 } else if (tok == "insertcotext") {
1022 arg.insertcotext = lex.getBool();
1023 } else if (tok == "leftdelim") {
1025 arg.ldelim = lex.getDocString();
1026 arg.ldelim = support::subst(arg.ldelim, from_ascii("<br/>"),
1028 } else if (tok == "rightdelim") {
1030 arg.rdelim = lex.getDocString();
1031 arg.rdelim = support::subst(arg.rdelim, from_ascii("<br/>"),
1033 } else if (tok == "defaultarg") {
1035 arg.defaultarg = lex.getDocString();
1036 } else if (tok == "presetarg") {
1038 arg.presetarg = lex.getDocString();
1039 } else if (tok == "tooltip") {
1041 arg.tooltip = lex.getDocString();
1042 } else if (tok == "requires") {
1044 arg.requires = lex.getString();
1045 } else if (tok == "decoration") {
1047 arg.decoration = lex.getString();
1048 } else if (tok == "font") {
1049 arg.font = lyxRead(lex, arg.font);
1050 } else if (tok == "labelfont") {
1051 arg.labelfont = lyxRead(lex, arg.labelfont);
1052 } else if (tok == "passthruchars") {
1054 arg.pass_thru_chars = lex.getDocString();
1055 } else if (tok == "passthru") {
1057 docstring value = lex.getDocString();
1058 if (value == "true" || value == "1")
1059 arg.passthru = PT_TRUE;
1060 else if (value == "false" || value == "0")
1061 arg.passthru = PT_FALSE;
1063 arg.passthru = PT_INHERITED;
1064 } else if (tok == "istoccaption") {
1066 arg.is_toc_caption = lex.getBool();
1068 lex.printError("Unknown tag");
1072 if (arg.labelstring.empty())
1073 LYXERR0("Incomplete Argument definition!");
1075 itemargs_[id] = arg;
1077 postcommandargs_[id] = arg;
1079 latexargs_[id] = arg;
1083 void writeArgument(ostream & os, string const & id, Layout::latexarg const & arg)
1085 os << "\tArgument " << id << '\n';
1086 if (!arg.labelstring.empty())
1087 os << "\t\tLabelString \"" << to_utf8(arg.labelstring) << "\"\n";
1088 if (!arg.menustring.empty())
1089 os << "\t\tMenuString \"" << to_utf8(arg.menustring) << "\"\n";
1091 os << "\t\tMandatory " << arg.mandatory << '\n';
1093 os << "\t\tAutoinsert " << arg.autoinsert << '\n';
1094 if (arg.insertcotext)
1095 os << "\t\tInsertCotext " << arg.insertcotext << '\n';
1096 if (!arg.ldelim.empty())
1097 os << "\t\tLeftDelim \""
1098 << to_utf8(subst(arg.ldelim, from_ascii("\n"), from_ascii("<br/>")))
1100 if (!arg.rdelim.empty())
1101 os << "\t\tRightDelim \""
1102 << to_utf8(subst(arg.rdelim, from_ascii("\n"), from_ascii("<br/>")))
1104 if (!arg.defaultarg.empty())
1105 os << "\t\tDefaultArg \"" << to_utf8(arg.defaultarg) << "\"\n";
1106 if (!arg.presetarg.empty())
1107 os << "\t\tPresetArg \"" << to_utf8(arg.presetarg) << "\"\n";
1108 if (!arg.tooltip.empty())
1109 os << "\t\tToolTip \"" << to_utf8(arg.tooltip) << "\"\n";
1110 if (!arg.requires.empty())
1111 os << "\t\tRequires \"" << arg.requires << "\"\n";
1112 if (!arg.decoration.empty())
1113 os << "\t\tDecoration \"" << arg.decoration << "\"\n";
1114 if (arg.font != inherit_font)
1115 lyxWrite(os, arg.font, "Font", 2);
1116 if (arg.labelfont != inherit_font)
1117 lyxWrite(os, arg.labelfont, "LabelFont", 2);
1118 switch (arg.passthru) {
1120 os << "\t\tPassThru true\n";
1123 os << "\t\tPassThru false\n";
1126 os << "\t\tPassThru inherited\n";
1129 if (!arg.pass_thru_chars.empty())
1130 os << "\t\tPassThruChars \"" << to_utf8(arg.pass_thru_chars) << "\"\n";
1131 os << "\tEndArgument\n";
1135 void Layout::write(ostream & os) const
1137 os << "Style \"" << to_utf8(name_) << "\"\n";
1138 if (!category_.empty() && obsoleted_by_.empty())
1139 os << "\tCategory \"" << to_utf8(category_) << "\"\n";
1140 // Can't deduce Copystyle here :-(
1141 if (!obsoleted_by_.empty()) {
1142 os << "\tObsoletedBy \"" << to_utf8(obsoleted_by_)
1146 if (!depends_on_.empty())
1147 os << "\tDependsOn " << to_utf8(depends_on_) << '\n';
1148 switch (margintype) {
1149 case MARGIN_DYNAMIC:
1150 os << "\tMargin Dynamic\n";
1152 case MARGIN_FIRST_DYNAMIC:
1153 os << "\tMargin First_Dynamic\n";
1156 os << "\tMargin Manual\n";
1158 case MARGIN_RIGHT_ADDRESS_BOX:
1159 os << "\tMargin Right_Address_Box\n";
1162 os << "\tMargin Static\n";
1165 switch (latextype) {
1166 case LATEX_BIB_ENVIRONMENT:
1167 os << "\tLatexType Bib_Environment\n";
1170 os << "\tLatexType Command\n";
1172 case LATEX_ENVIRONMENT:
1173 os << "\tLatexType Environment\n";
1175 case LATEX_ITEM_ENVIRONMENT:
1176 os << "\tLatexType Item_Environment\n";
1178 case LATEX_LIST_ENVIRONMENT:
1179 os << "\tLatexType List_Environment\n";
1181 case LATEX_PARAGRAPH:
1182 os << "\tLatexType Paragraph\n";
1185 os << "\tInTitle " << intitle << "\n"
1186 "\tInPreamble " << inpreamble << "\n"
1187 "\tTocLevel " << toclevel << "\n"
1188 "\tResumeCounter " << resumecounter << "\n"
1189 "\tStepMasterCounter " << stepmastercounter << '\n';
1190 // ResetArgs does not make sense here
1191 for (LaTeXArgMap::const_iterator it = latexargs_.begin();
1192 it != latexargs_.end(); ++it)
1193 writeArgument(os, it->first, it->second);
1194 for (LaTeXArgMap::const_iterator it = itemargs_.begin();
1195 it != itemargs_.end(); ++it)
1196 writeArgument(os, it->first, it->second);
1197 for (LaTeXArgMap::const_iterator it = postcommandargs_.begin();
1198 it != postcommandargs_.end(); ++it)
1199 writeArgument(os, it->first, it->second);
1200 os << "\tNeedProtect " << needprotect << "\n"
1201 "\tKeepEmpty " << keepempty << '\n';
1202 if (labelfont == font)
1203 lyxWrite(os, font, "Font", 1);
1205 lyxWrite(os, font, "TextFont", 1);
1206 lyxWrite(os, labelfont, "LabelFont", 1);
1208 os << "\tNextNoIndent " << nextnoindent << "\n"
1209 "\tCommandDepth " << commanddepth << '\n';
1210 if (!latexname_.empty())
1211 os << "\tLatexName \"" << latexname_ << "\"\n";
1212 if (!latexparam_.empty())
1213 os << "\tLatexParam \"" << subst(latexparam_, "\"", """)
1215 if (!leftdelim_.empty())
1216 os << "\tLeftDelim "
1217 << to_utf8(subst(leftdelim_, from_ascii("\n"), from_ascii("<br/>")))
1219 if (!rightdelim_.empty())
1220 os << "\tRightDelim "
1221 << to_utf8(subst(rightdelim_, from_ascii("\n"), from_ascii("<br/>")))
1223 if (!innertag_.empty())
1224 os << "\tInnerTag \"" << innertag_ << "\"\n";
1225 if (!labeltag_.empty())
1226 os << "\tLabelTag \"" << labeltag_ << "\"\n";
1227 if (!itemtag_.empty())
1228 os << "\tItemTag \"" << itemtag_ << "\"\n";
1229 if (!itemcommand_.empty())
1230 os << "\tItemCommand " << itemcommand_ << '\n';
1231 if (!preamble_.empty())
1232 os << "\tPreamble\n\t"
1233 << to_utf8(subst(rtrim(preamble_, "\n"),
1234 from_ascii("\n"), from_ascii("\n\t")))
1235 << "\n\tEndPreamble\n";
1236 if (!langpreamble_.empty())
1237 os << "\tLangPreamble\n\t"
1238 << to_utf8(subst(rtrim(langpreamble_, "\n"),
1239 from_ascii("\n"), from_ascii("\n\t")))
1240 << "\n\tEndLangPreamble\n";
1241 if (!babelpreamble_.empty())
1242 os << "\tBabelPreamble\n\t"
1243 << to_utf8(subst(rtrim(babelpreamble_, "\n"),
1244 from_ascii("\n"), from_ascii("\n\t")))
1245 << "\n\tEndBabelPreamble\n";
1246 switch (labeltype) {
1248 os << "\tLabelType Above\n";
1251 os << "\tLabelType Bibliography\n";
1253 case LABEL_CENTERED:
1254 os << "\tLabelType Centered\n";
1256 case LABEL_ENUMERATE:
1257 os << "\tLabelType Enumerate\n";
1260 os << "\tLabelType Itemize\n";
1263 os << "\tLabelType Manual\n";
1265 case LABEL_NO_LABEL:
1266 os << "\tLabelType No_Label\n";
1268 case LABEL_SENSITIVE:
1269 os << "\tLabelType Sensitive\n";
1272 os << "\tLabelType Static\n";
1275 switch (endlabeltype) {
1277 os << "\tEndLabelType Box\n";
1279 case END_LABEL_FILLED_BOX:
1280 os << "\tEndLabelType Filled_Box\n";
1282 case END_LABEL_NO_LABEL:
1283 os << "\tEndLabelType No_Label\n";
1285 case END_LABEL_STATIC:
1286 os << "\tEndLabelType Static\n";
1289 os << "\tParagraphGroup \"" << par_group_ << "\"\n";
1290 if (!leftmargin.empty())
1291 os << "\tLeftMargin \"" << to_utf8(leftmargin) << "\"\n";
1292 if (!rightmargin.empty())
1293 os << "\tRightMargin \"" << to_utf8(rightmargin) << "\"\n";
1294 if (!labelindent.empty())
1295 os << "\tLabelIndent " << to_utf8(labelindent) << '\n';
1296 if (!parindent.empty())
1297 os << "\tParIndent " << to_utf8(parindent) << '\n';
1298 os << "\tParSkip " << parskip << "\n"
1299 "\tItemSep " << itemsep << "\n"
1300 "\tTopSep " << topsep << "\n"
1301 "\tBottomSep " << bottomsep << "\n"
1302 "\tLabelBottomSep " << labelbottomsep << '\n';
1303 if (!labelsep.empty())
1304 os << "\tLabelSep " << to_utf8(subst(labelsep, ' ', 'x'))
1306 os << "\tParSep " << parsep << "\n"
1307 "\tNewLine " << newline_allowed << '\n';
1309 case LYX_ALIGN_BLOCK:
1310 os << "\tAlign Block\n";
1312 case LYX_ALIGN_CENTER:
1313 os << "\tAlign Center\n";
1315 case LYX_ALIGN_LAYOUT:
1316 os << "\tAlign Layout\n";
1318 case LYX_ALIGN_LEFT:
1319 os << "\tAlign Left\n";
1321 case LYX_ALIGN_RIGHT:
1322 os << "\tAlign Right\n";
1324 case LYX_ALIGN_DECIMAL:
1325 case LYX_ALIGN_SPECIAL:
1326 case LYX_ALIGN_NONE:
1329 if (alignpossible & (LYX_ALIGN_BLOCK | LYX_ALIGN_CENTER |
1330 LYX_ALIGN_LAYOUT | LYX_ALIGN_LEFT | LYX_ALIGN_RIGHT)) {
1332 os << "\tAlignPossible";
1333 if (alignpossible & LYX_ALIGN_BLOCK) {
1337 if (alignpossible & LYX_ALIGN_CENTER) {
1343 if (alignpossible & LYX_ALIGN_LAYOUT) {
1349 if (alignpossible & LYX_ALIGN_LEFT) {
1355 if (alignpossible & LYX_ALIGN_RIGHT) {
1363 // LabelString must come before LabelStringAppendix
1364 if (!labelstring_.empty())
1365 os << "\tLabelString \"" << to_utf8(labelstring_) << "\"\n";
1366 if (!endlabelstring_.empty())
1367 os << "\tEndLabelString \"" << to_utf8(endlabelstring_) << "\"\n";
1368 if (!labelstring_appendix_.empty() && labelstring_appendix_ != labelstring_)
1369 os << "\tLabelStringAppendix \""
1370 << to_utf8(labelstring_appendix_) << "\"\n";
1371 if (!counter.empty())
1372 os << "\tLabelCounter \"" << to_utf8(counter) << "\"\n";
1373 os << "\tFreeSpacing " << free_spacing << '\n';
1374 os << "\tPassThru " << pass_thru << '\n';
1375 if (!pass_thru_chars.empty())
1376 os << "\tPassThruChars " << to_utf8(pass_thru_chars) << '\n';
1377 os << "\tParbreakIsNewline " << parbreak_is_newline << '\n';
1378 switch (spacing.getSpace()) {
1379 case Spacing::Double:
1380 os << "\tSpacing Double\n";
1382 case Spacing::Onehalf:
1383 os << "\tSpacing Onehalf\n";
1385 case Spacing::Other:
1386 os << "\tSpacing Other " << spacing.getValueAsString() << '\n';
1388 case Spacing::Single:
1389 os << "\tSpacing Single\n";
1391 case Spacing::Default:
1394 if (!requires_.empty()) {
1395 os << "\tRequires ";
1396 for (set<string>::const_iterator it = requires_.begin();
1397 it != requires_.end(); ++it) {
1398 if (it != requires_.begin())
1404 if (!autonests_.empty()) {
1405 os << "\tAutoNests\n\t";
1406 for (set<docstring>::const_iterator it = autonests_.begin();
1407 it != autonests_.end(); ++it) {
1408 if (it != autonests_.begin())
1412 os << "\n\tEndAutoNests\n";
1414 if (refprefix.empty())
1415 os << "\tRefPrefix OFF\n";
1417 os << "\tRefPrefix " << to_utf8(refprefix) << '\n';
1418 if (!htmltag_.empty())
1419 os << "\tHTMLTag " << htmltag_ << '\n';
1420 if (!htmlattr_.empty())
1421 os << "\tHTMLAttr " << htmlattr_ << '\n';
1422 if (!htmlitemtag_.empty())
1423 os << "\tHTMLItem " << htmlitemtag_ << '\n';
1424 if (!htmlitemattr_.empty())
1425 os << "\tHTMLItemAttr " << htmlitemattr_ << '\n';
1426 if (!htmllabeltag_.empty())
1427 os << "\tHTMLLabel " << htmllabeltag_ << '\n';
1428 if (!htmllabelattr_.empty())
1429 os << "\tHTMLLabelAttr " << htmllabelattr_ << '\n';
1430 os << "\tHTMLLabelFirst " << htmllabelfirst_ << '\n';
1431 if (!htmlstyle_.empty())
1432 os << "\tHTMLStyle\n"
1433 << to_utf8(rtrim(htmlstyle_, "\n"))
1434 << "\n\tEndHTMLStyle\n";
1435 os << "\tHTMLForceCSS " << htmlforcecss_ << '\n';
1436 if (!htmlpreamble_.empty())
1437 os << "\tHTMLPreamble\n"
1438 << to_utf8(rtrim(htmlpreamble_, "\n"))
1439 << "\n\tEndPreamble\n";
1440 os << "\tHTMLTitle " << htmltitle_ << "\n"
1441 "\tSpellcheck " << spellcheck << "\n"
1442 "\tForceLocal " << forcelocal << "\n"
1447 bool Layout::hasArgs() const
1449 return !latexargs_.empty() || !postcommandargs_.empty() ||
1454 Layout::LaTeXArgMap Layout::args() const
1456 LaTeXArgMap args = latexargs_;
1457 if (!postcommandargs_.empty())
1458 args.insert(postcommandargs_.begin(), postcommandargs_.end());
1459 if (!itemargs_.empty())
1460 args.insert(itemargs_.begin(), itemargs_.end());
1465 int Layout::optArgs() const
1468 LaTeXArgMap::const_iterator it = latexargs_.begin();
1469 for (; it != latexargs_.end(); ++it) {
1470 if (!(*it).second.mandatory)
1473 LaTeXArgMap::const_iterator iit = postcommandargs_.begin();
1474 for (; iit != postcommandargs_.end(); ++iit) {
1475 if (!(*iit).second.mandatory)
1482 int Layout::requiredArgs() const
1485 LaTeXArgMap::const_iterator it = latexargs_.begin();
1486 for (; it != latexargs_.end(); ++it) {
1487 if ((*it).second.mandatory)
1490 LaTeXArgMap::const_iterator iit = postcommandargs_.begin();
1491 for (; iit != postcommandargs_.end(); ++iit) {
1492 if (!(*iit).second.mandatory)
1499 string const & Layout::htmltag() const
1501 if (htmltag_.empty())
1507 string const & Layout::htmlattr() const
1509 if (htmlattr_.empty())
1510 htmlattr_ = "class=\"" + defaultCSSClass() + "\"";
1515 string const & Layout::htmlitemtag() const
1517 if (htmlitemtag_.empty())
1518 htmlitemtag_ = "div";
1519 return htmlitemtag_;
1523 string const & Layout::htmlitemattr() const
1525 if (htmlitemattr_.empty())
1526 htmlitemattr_ = "class=\"" + defaultCSSItemClass() + "\"";
1527 return htmlitemattr_;
1531 string const & Layout::htmllabeltag() const
1533 if (htmllabeltag_.empty())
1534 htmllabeltag_ = "span";
1535 return htmllabeltag_;
1539 string const & Layout::htmllabelattr() const
1541 if (htmllabelattr_.empty())
1542 htmllabelattr_ = "class=\"" + defaultCSSLabelClass() + "\"";
1543 return htmllabelattr_;
1547 docstring Layout::htmlstyle() const
1549 if (!htmlstyle_.empty() && !htmlforcecss_)
1551 if (htmldefaultstyle_.empty())
1553 docstring retval = htmldefaultstyle_;
1554 if (!htmlstyle_.empty())
1555 retval += '\n' + htmlstyle_;
1560 string Layout::defaultCSSClass() const
1562 if (!defaultcssclass_.empty())
1563 return defaultcssclass_;
1565 docstring::const_iterator it = name().begin();
1566 docstring::const_iterator en = name().end();
1567 for (; it != en; ++it) {
1568 char_type const c = *it;
1569 if (!isAlphaASCII(c)) {
1571 // make sure we don't start with an underscore,
1572 // as that sometimes causes problems.
1573 d = from_ascii("lyx_");
1576 } else if (isLower(c))
1579 // this is slow, so do it only if necessary
1582 defaultcssclass_ = to_utf8(d);
1583 return defaultcssclass_;
1589 string makeMarginValue(char const * side, double d)
1592 os << "margin-" << side << ": " << d << "ex;\n";
1599 void Layout::makeDefaultCSS() const
1601 // this never needs to be redone, since reloading layouts will
1602 // wipe out what we did before.
1603 if (!htmldefaultstyle_.empty())
1607 htmldefaultstyle_ = font.asCSS();
1612 tmp += makeMarginValue("top", topsep);
1614 tmp += makeMarginValue("bottom", bottomsep);
1615 if (!leftmargin.empty()) {
1616 // we can't really do what LyX does with the margin, so
1617 // we'll just figure out how many characters it is
1618 int const len = leftmargin.length();
1619 tmp += makeMarginValue("left", len);
1621 if (!rightmargin.empty()) {
1622 int const len = rightmargin.length();
1623 tmp += makeMarginValue("right", len);
1627 if (!htmldefaultstyle_.empty())
1628 htmldefaultstyle_ += from_ascii("\n");
1629 htmldefaultstyle_ += from_ascii(tmp);
1633 string where = alignmentToCSS(align);
1634 if (!where.empty()) {
1635 htmldefaultstyle_ += from_ascii("text-align: " + where + ";\n");
1638 // wrap up what we have, if anything
1639 if (!htmldefaultstyle_.empty())
1641 from_ascii(htmltag() + "." + defaultCSSClass() + " {\n") +
1642 htmldefaultstyle_ + from_ascii("\n}\n");
1644 if (labeltype == LABEL_NO_LABEL || htmllabeltag() == "NONE")
1650 if (labelfont != font)
1651 labelCSS = labelfont.asCSS() + from_ascii("\n");
1652 if (labeltype == LABEL_CENTERED)
1653 labelCSS += from_ascii("text-align: center;\n");
1655 if (!labelCSS.empty())
1656 htmldefaultstyle_ +=
1657 from_ascii(htmllabeltag() + "." + defaultCSSLabelClass() + " {\n") +
1658 labelCSS + from_ascii("\n}\n");
1662 bool Layout::operator==(Layout const & rhs) const
1664 // This is enough for the applications we actually make,
1665 // at least at the moment. But we could check more.
1666 return name() == rhs.name()
1667 && latexname() == rhs.latexname()
1668 && latextype == rhs.latextype;