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]
55 LT_PARBREAK_IS_NEWLINE,
65 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 { "babelpreamble", LT_BABELPREAMBLE },
196 { "bottomsep", LT_BOTTOMSEP },
197 { "category", LT_CATEGORY },
198 { "commanddepth", LT_COMMANDDEPTH },
199 { "copystyle", LT_COPYSTYLE },
200 { "dependson", LT_DEPENDSON },
202 { "endlabelstring", LT_ENDLABELSTRING },
203 { "endlabeltype", LT_ENDLABELTYPE },
205 { "forcelocal", LT_FORCELOCAL },
206 { "freespacing", LT_FREE_SPACING },
207 { "htmlattr", LT_HTMLATTR },
208 { "htmlforcecss", LT_HTMLFORCECSS },
209 { "htmlitem", LT_HTMLITEM },
210 { "htmlitemattr", LT_HTMLITEMATTR },
211 { "htmllabel", LT_HTMLLABEL },
212 { "htmllabelattr", LT_HTMLLABELATTR },
213 { "htmllabelfirst", LT_HTMLLABELFIRST },
214 { "htmlpreamble", LT_HTMLPREAMBLE },
215 { "htmlstyle", LT_HTMLSTYLE },
216 { "htmltag", LT_HTMLTAG },
217 { "htmltitle", LT_HTMLTITLE },
218 { "innertag", LT_INNERTAG },
219 { "inpreamble", LT_INPREAMBLE },
220 { "intitle", LT_INTITLE },
221 { "istoccaption", LT_ISTOCCAPTION },
222 { "itemcommand", LT_ITEMCOMMAND },
223 { "itemsep", LT_ITEMSEP },
224 { "itemtag", LT_ITEMTAG },
225 { "keepempty", LT_KEEPEMPTY },
226 { "labelbottomsep", LT_LABEL_BOTTOMSEP },
227 { "labelcounter", LT_LABELCOUNTER },
228 { "labelfont", LT_LABELFONT },
229 { "labelindent", LT_LABELINDENT },
230 { "labelsep", LT_LABELSEP },
231 { "labelstring", LT_LABELSTRING },
232 { "labelstringappendix", LT_LABELSTRING_APPENDIX },
233 { "labeltag", LT_LABELTAG },
234 { "labeltype", LT_LABELTYPE },
235 { "langpreamble", LT_LANGPREAMBLE },
236 { "latexname", LT_LATEXNAME },
237 { "latexparam", LT_LATEXPARAM },
238 { "latextype", LT_LATEXTYPE },
239 { "leftdelim", LT_LEFTDELIM },
240 { "leftmargin", LT_LEFTMARGIN },
241 { "margin", LT_MARGIN },
242 { "needprotect", LT_NEED_PROTECT },
243 { "nests", LT_NESTS },
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 nest = subst(subst(subst(lex.getLongString(from_ascii("EndNests")),
599 from_ascii("\n"), docstring()),
600 from_ascii(" "), docstring()),
601 from_ascii("\t"), docstring());
602 vector<docstring> const nests =
603 getVectorFromString(nest);
604 nests_.insert(nests.begin(), nests.end());
630 case LT_HTMLITEMATTR:
631 lex >> htmlitemattr_;
635 lex >> htmllabeltag_;
638 case LT_HTMLLABELATTR:
639 lex >> htmllabelattr_;
642 case LT_HTMLLABELFIRST:
643 lex >> htmllabelfirst_;
647 htmlstyle_ = lex.getLongString(from_ascii("EndHTMLStyle"));
650 case LT_HTMLFORCECSS:
651 lex >> htmlforcecss_;
654 case LT_HTMLPREAMBLE:
655 htmlpreamble_ = lex.getLongString(from_ascii("EndPreamble"));
672 add_to_toc_ = !toc_type_.empty();
675 case LT_ISTOCCAPTION:
676 lex >> is_toc_caption_;
682 // make sure we only have inpreamble = true for commands
683 if (inpreamble && latextype != LATEX_COMMAND && latextype != LATEX_PARAGRAPH) {
684 LYXERR0("InPreamble not permitted except with command and paragraph layouts.");
685 LYXERR0("Layout name: " << name());
689 return finished && !error;
702 LexerKeyword alignTags[] = {
703 { "block", AT_BLOCK },
704 { "center", AT_CENTER },
705 { "layout", AT_LAYOUT },
707 { "right", AT_RIGHT }
711 void Layout::readAlign(Lexer & lex)
713 PushPopHelper pph(lex, alignTags);
716 case Lexer::LEX_UNDEF:
717 lex.printError("Unknown alignment `$$Token'");
723 align = LYX_ALIGN_BLOCK;
726 align = LYX_ALIGN_LEFT;
729 align = LYX_ALIGN_RIGHT;
732 align = LYX_ALIGN_CENTER;
735 align = LYX_ALIGN_LAYOUT;
741 void Layout::readAlignPossible(Lexer & lex)
743 lex.pushTable(alignTags);
744 alignpossible = LYX_ALIGN_NONE | LYX_ALIGN_LAYOUT;
745 int lineno = lex.lineNumber();
749 case Lexer::LEX_UNDEF:
750 lex.printError("Unknown alignment `$$Token'");
756 alignpossible |= LYX_ALIGN_BLOCK;
759 alignpossible |= LYX_ALIGN_LEFT;
762 alignpossible |= LYX_ALIGN_RIGHT;
765 alignpossible |= LYX_ALIGN_CENTER;
768 alignpossible |= LYX_ALIGN_LAYOUT;
771 } while (lineno == lex.lineNumber());
776 void Layout::readLabelType(Lexer & lex)
791 LexerKeyword labelTypeTags[] = {
792 { "above", LA_ABOVE },
793 { "bibliography", LA_BIBLIO },
794 { "centered", LA_CENTERED },
795 { "enumerate", LA_ENUMERATE },
796 { "itemize", LA_ITEMIZE },
797 { "manual", LA_MANUAL },
798 { "no_label", LA_NO_LABEL },
799 { "sensitive", LA_SENSITIVE },
800 { "static", LA_STATIC }
803 PushPopHelper pph(lex, labelTypeTags);
806 case Lexer::LEX_UNDEF:
807 lex.printError("Unknown labeltype tag `$$Token'");
813 labeltype = LABEL_NO_LABEL;
816 labeltype = LABEL_MANUAL;
819 labeltype = LABEL_ABOVE;
822 labeltype = LABEL_CENTERED;
825 labeltype = LABEL_STATIC;
828 labeltype = LABEL_SENSITIVE;
831 labeltype = LABEL_ENUMERATE;
834 labeltype = LABEL_ITEMIZE;
837 labeltype = LABEL_BIBLIO;
843 void Layout::readEndLabelType(Lexer & lex)
845 // this should be const, but can't be because
847 static LexerKeyword endlabelTypeTags[] = {
848 { "box", END_LABEL_BOX },
849 { "filled_box", END_LABEL_FILLED_BOX },
850 { "no_label", END_LABEL_NO_LABEL },
851 { "static", END_LABEL_STATIC }
854 PushPopHelper pph(lex, endlabelTypeTags);
857 case Lexer::LEX_UNDEF:
858 lex.printError("Unknown labeltype tag `$$Token'");
860 case END_LABEL_STATIC:
862 case END_LABEL_FILLED_BOX:
863 case END_LABEL_NO_LABEL:
864 endlabeltype = static_cast<EndLabelType>(le);
867 LYXERR0("Unhandled value " << le);
873 void Layout::readMargin(Lexer & lex)
875 LexerKeyword marginTags[] = {
876 { "dynamic", MARGIN_DYNAMIC },
877 { "first_dynamic", MARGIN_FIRST_DYNAMIC },
878 { "manual", MARGIN_MANUAL },
879 { "right_address_box", MARGIN_RIGHT_ADDRESS_BOX },
880 { "static", MARGIN_STATIC }
883 PushPopHelper pph(lex, marginTags);
887 case Lexer::LEX_UNDEF:
888 lex.printError("Unknown margin type tag `$$Token'");
893 case MARGIN_FIRST_DYNAMIC:
894 case MARGIN_RIGHT_ADDRESS_BOX:
895 margintype = static_cast<MarginType>(le);
898 LYXERR0("Unhandled value " << le);
904 void Layout::readLatexType(Lexer & lex)
906 LexerKeyword latexTypeTags[] = {
907 { "bib_environment", LATEX_BIB_ENVIRONMENT },
908 { "command", LATEX_COMMAND },
909 { "environment", LATEX_ENVIRONMENT },
910 { "item_environment", LATEX_ITEM_ENVIRONMENT },
911 { "list_environment", LATEX_LIST_ENVIRONMENT },
912 { "paragraph", LATEX_PARAGRAPH }
915 PushPopHelper pph(lex, latexTypeTags);
918 case Lexer::LEX_UNDEF:
919 lex.printError("Unknown latextype tag `$$Token'");
921 case LATEX_PARAGRAPH:
923 case LATEX_ITEM_ENVIRONMENT:
924 case LATEX_LIST_ENVIRONMENT:
925 latextype = static_cast<LatexType>(le);
927 case LATEX_ENVIRONMENT:
928 case LATEX_BIB_ENVIRONMENT:
929 latextype = static_cast<LatexType>(le);
933 LYXERR0("Unhandled value " << le);
939 void Layout::readSpacing(Lexer & lex)
942 ST_SPACING_SINGLE = 1,
948 LexerKeyword spacingTags[] = {
949 {"double", ST_SPACING_DOUBLE },
950 {"onehalf", ST_SPACING_ONEHALF },
951 {"other", ST_OTHER },
952 {"single", ST_SPACING_SINGLE }
955 PushPopHelper pph(lex, spacingTags);
958 case Lexer::LEX_UNDEF:
959 lex.printError("Unknown spacing token `$$Token'");
964 case ST_SPACING_SINGLE:
965 spacing.set(Spacing::Single);
967 case ST_SPACING_ONEHALF:
968 spacing.set(Spacing::Onehalf);
970 case ST_SPACING_DOUBLE:
971 spacing.set(Spacing::Double);
975 spacing.set(Spacing::Other, lex.getString());
981 void Layout::readArgument(Lexer & lex)
984 // writeArgument() makes use of these default values
985 arg.mandatory = false;
986 arg.autoinsert = false;
987 arg.insertcotext = false;
989 bool finished = false;
990 arg.font = inherit_font;
991 arg.labelfont = inherit_font;
992 arg.is_toc_caption = false;
993 arg.passthru = PT_INHERITED;
996 bool const itemarg = prefixIs(id, "item:");
997 bool const postcmd = prefixIs(id, "post:");
999 while (!finished && lex.isOK() && !error) {
1001 string const tok = ascii_lowercase(lex.getString());
1005 } else if (tok == "endargument") {
1007 } else if (tok == "labelstring") {
1009 arg.labelstring = lex.getDocString();
1010 } else if (tok == "menustring") {
1012 arg.menustring = lex.getDocString();
1013 } else if (tok == "mandatory") {
1015 arg.mandatory = lex.getBool();
1016 } else if (tok == "autoinsert") {
1018 arg.autoinsert = lex.getBool();
1019 } else if (tok == "insertcotext") {
1021 arg.insertcotext = lex.getBool();
1022 } else if (tok == "leftdelim") {
1024 arg.ldelim = lex.getDocString();
1025 arg.ldelim = support::subst(arg.ldelim, from_ascii("<br/>"),
1027 } else if (tok == "rightdelim") {
1029 arg.rdelim = lex.getDocString();
1030 arg.rdelim = support::subst(arg.rdelim, from_ascii("<br/>"),
1032 } else if (tok == "defaultarg") {
1034 arg.defaultarg = lex.getDocString();
1035 } else if (tok == "presetarg") {
1037 arg.presetarg = lex.getDocString();
1038 } else if (tok == "tooltip") {
1040 arg.tooltip = lex.getDocString();
1041 } else if (tok == "requires") {
1043 arg.requires = lex.getString();
1044 } else if (tok == "decoration") {
1046 arg.decoration = lex.getString();
1047 } else if (tok == "font") {
1048 arg.font = lyxRead(lex, arg.font);
1049 } else if (tok == "labelfont") {
1050 arg.labelfont = lyxRead(lex, arg.labelfont);
1051 } else if (tok == "passthruchars") {
1053 arg.pass_thru_chars = lex.getDocString();
1054 } else if (tok == "passthru") {
1056 docstring value = lex.getDocString();
1057 if (value == "true" || value == "1")
1058 arg.passthru = PT_TRUE;
1059 else if (value == "false" || value == "0")
1060 arg.passthru = PT_FALSE;
1062 arg.passthru = PT_INHERITED;
1063 } else if (tok == "istoccaption") {
1065 arg.is_toc_caption = lex.getBool();
1067 lex.printError("Unknown tag");
1071 if (arg.labelstring.empty())
1072 LYXERR0("Incomplete Argument definition!");
1074 itemargs_[id] = arg;
1076 postcommandargs_[id] = arg;
1078 latexargs_[id] = arg;
1082 void writeArgument(ostream & os, string const & id, Layout::latexarg const & arg)
1084 os << "\tArgument " << id << '\n';
1085 if (!arg.labelstring.empty())
1086 os << "\t\tLabelString \"" << to_utf8(arg.labelstring) << "\"\n";
1087 if (!arg.menustring.empty())
1088 os << "\t\tMenuString \"" << to_utf8(arg.menustring) << "\"\n";
1090 os << "\t\tMandatory " << arg.mandatory << '\n';
1092 os << "\t\tAutoinsert " << arg.autoinsert << '\n';
1093 if (arg.insertcotext)
1094 os << "\t\tInsertCotext " << arg.insertcotext << '\n';
1095 if (!arg.ldelim.empty())
1096 os << "\t\tLeftDelim \""
1097 << to_utf8(subst(arg.ldelim, from_ascii("\n"), from_ascii("<br/>")))
1099 if (!arg.rdelim.empty())
1100 os << "\t\tRightDelim \""
1101 << to_utf8(subst(arg.rdelim, from_ascii("\n"), from_ascii("<br/>")))
1103 if (!arg.defaultarg.empty())
1104 os << "\t\tDefaultArg \"" << to_utf8(arg.defaultarg) << "\"\n";
1105 if (!arg.presetarg.empty())
1106 os << "\t\tPresetArg \"" << to_utf8(arg.presetarg) << "\"\n";
1107 if (!arg.tooltip.empty())
1108 os << "\t\tToolTip \"" << to_utf8(arg.tooltip) << "\"\n";
1109 if (!arg.requires.empty())
1110 os << "\t\tRequires \"" << arg.requires << "\"\n";
1111 if (!arg.decoration.empty())
1112 os << "\t\tDecoration \"" << arg.decoration << "\"\n";
1113 if (arg.font != inherit_font)
1114 lyxWrite(os, arg.font, "Font", 2);
1115 if (arg.labelfont != inherit_font)
1116 lyxWrite(os, arg.labelfont, "LabelFont", 2);
1117 switch (arg.passthru) {
1119 os << "\t\tPassThru true\n";
1122 os << "\t\tPassThru false\n";
1125 os << "\t\tPassThru inherited\n";
1128 if (!arg.pass_thru_chars.empty())
1129 os << "\t\tPassThruChars \"" << to_utf8(arg.pass_thru_chars) << "\"\n";
1130 os << "\tEndArgument\n";
1134 void Layout::write(ostream & os) const
1136 os << "Style \"" << to_utf8(name_) << "\"\n";
1137 if (!category_.empty() && obsoleted_by_.empty())
1138 os << "\tCategory \"" << to_utf8(category_) << "\"\n";
1139 // Can't deduce Copystyle here :-(
1140 if (!obsoleted_by_.empty()) {
1141 os << "\tObsoletedBy \"" << to_utf8(obsoleted_by_)
1145 if (!depends_on_.empty())
1146 os << "\tDependsOn " << to_utf8(depends_on_) << '\n';
1147 switch (margintype) {
1148 case MARGIN_DYNAMIC:
1149 os << "\tMargin Dynamic\n";
1151 case MARGIN_FIRST_DYNAMIC:
1152 os << "\tMargin First_Dynamic\n";
1155 os << "\tMargin Manual\n";
1157 case MARGIN_RIGHT_ADDRESS_BOX:
1158 os << "\tMargin Right_Address_Box\n";
1161 os << "\tMargin Static\n";
1164 switch (latextype) {
1165 case LATEX_BIB_ENVIRONMENT:
1166 os << "\tLatexType Bib_Environment\n";
1169 os << "\tLatexType Command\n";
1171 case LATEX_ENVIRONMENT:
1172 os << "\tLatexType Environment\n";
1174 case LATEX_ITEM_ENVIRONMENT:
1175 os << "\tLatexType Item_Environment\n";
1177 case LATEX_LIST_ENVIRONMENT:
1178 os << "\tLatexType List_Environment\n";
1180 case LATEX_PARAGRAPH:
1181 os << "\tLatexType Paragraph\n";
1184 os << "\tInTitle " << intitle << "\n"
1185 "\tInPreamble " << inpreamble << "\n"
1186 "\tTocLevel " << toclevel << "\n"
1187 "\tResumeCounter " << resumecounter << "\n"
1188 "\tStepMasterCounter " << stepmastercounter << '\n';
1189 // ResetArgs does not make sense here
1190 for (LaTeXArgMap::const_iterator it = latexargs_.begin();
1191 it != latexargs_.end(); ++it)
1192 writeArgument(os, it->first, it->second);
1193 for (LaTeXArgMap::const_iterator it = itemargs_.begin();
1194 it != itemargs_.end(); ++it)
1195 writeArgument(os, it->first, it->second);
1196 for (LaTeXArgMap::const_iterator it = postcommandargs_.begin();
1197 it != postcommandargs_.end(); ++it)
1198 writeArgument(os, it->first, it->second);
1199 os << "\tNeedProtect " << needprotect << "\n"
1200 "\tKeepEmpty " << keepempty << '\n';
1201 if (labelfont == font)
1202 lyxWrite(os, font, "Font", 1);
1204 lyxWrite(os, font, "TextFont", 1);
1205 lyxWrite(os, labelfont, "LabelFont", 1);
1207 os << "\tNextNoIndent " << nextnoindent << "\n"
1208 "\tCommandDepth " << commanddepth << '\n';
1209 if (!latexname_.empty())
1210 os << "\tLatexName \"" << latexname_ << "\"\n";
1211 if (!latexparam_.empty())
1212 os << "\tLatexParam \"" << subst(latexparam_, "\"", """)
1214 if (!leftdelim_.empty())
1215 os << "\tLeftDelim "
1216 << to_utf8(subst(leftdelim_, from_ascii("\n"), from_ascii("<br/>")))
1218 if (!rightdelim_.empty())
1219 os << "\tRightDelim "
1220 << to_utf8(subst(rightdelim_, from_ascii("\n"), from_ascii("<br/>")))
1222 if (!innertag_.empty())
1223 os << "\tInnerTag \"" << innertag_ << "\"\n";
1224 if (!labeltag_.empty())
1225 os << "\tLabelTag \"" << labeltag_ << "\"\n";
1226 if (!itemtag_.empty())
1227 os << "\tItemTag \"" << itemtag_ << "\"\n";
1228 if (!itemcommand_.empty())
1229 os << "\tItemCommand " << itemcommand_ << '\n';
1230 if (!preamble_.empty())
1231 os << "\tPreamble\n\t"
1232 << to_utf8(subst(rtrim(preamble_, "\n"),
1233 from_ascii("\n"), from_ascii("\n\t")))
1234 << "\n\tEndPreamble\n";
1235 if (!langpreamble_.empty())
1236 os << "\tLangPreamble\n\t"
1237 << to_utf8(subst(rtrim(langpreamble_, "\n"),
1238 from_ascii("\n"), from_ascii("\n\t")))
1239 << "\n\tEndLangPreamble\n";
1240 if (!babelpreamble_.empty())
1241 os << "\tBabelPreamble\n\t"
1242 << to_utf8(subst(rtrim(babelpreamble_, "\n"),
1243 from_ascii("\n"), from_ascii("\n\t")))
1244 << "\n\tEndBabelPreamble\n";
1245 switch (labeltype) {
1247 os << "\tLabelType Above\n";
1250 os << "\tLabelType Bibliography\n";
1252 case LABEL_CENTERED:
1253 os << "\tLabelType Centered\n";
1255 case LABEL_ENUMERATE:
1256 os << "\tLabelType Enumerate\n";
1259 os << "\tLabelType Itemize\n";
1262 os << "\tLabelType Manual\n";
1264 case LABEL_NO_LABEL:
1265 os << "\tLabelType No_Label\n";
1267 case LABEL_SENSITIVE:
1268 os << "\tLabelType Sensitive\n";
1271 os << "\tLabelType Static\n";
1274 switch (endlabeltype) {
1276 os << "\tEndLabelType Box\n";
1278 case END_LABEL_FILLED_BOX:
1279 os << "\tEndLabelType Filled_Box\n";
1281 case END_LABEL_NO_LABEL:
1282 os << "\tEndLabelType No_Label\n";
1284 case END_LABEL_STATIC:
1285 os << "\tEndLabelType Static\n";
1288 os << "\tParagraphGroup \"" << par_group_ << "\"\n";
1289 if (!leftmargin.empty())
1290 os << "\tLeftMargin \"" << to_utf8(leftmargin) << "\"\n";
1291 if (!rightmargin.empty())
1292 os << "\tRightMargin \"" << to_utf8(rightmargin) << "\"\n";
1293 if (!labelindent.empty())
1294 os << "\tLabelIndent " << to_utf8(labelindent) << '\n';
1295 if (!parindent.empty())
1296 os << "\tParIndent " << to_utf8(parindent) << '\n';
1297 os << "\tParSkip " << parskip << "\n"
1298 "\tItemSep " << itemsep << "\n"
1299 "\tTopSep " << topsep << "\n"
1300 "\tBottomSep " << bottomsep << "\n"
1301 "\tLabelBottomSep " << labelbottomsep << '\n';
1302 if (!labelsep.empty())
1303 os << "\tLabelSep " << to_utf8(subst(labelsep, ' ', 'x'))
1305 os << "\tParSep " << parsep << "\n"
1306 "\tNewLine " << newline_allowed << '\n';
1308 case LYX_ALIGN_BLOCK:
1309 os << "\tAlign Block\n";
1311 case LYX_ALIGN_CENTER:
1312 os << "\tAlign Center\n";
1314 case LYX_ALIGN_LAYOUT:
1315 os << "\tAlign Layout\n";
1317 case LYX_ALIGN_LEFT:
1318 os << "\tAlign Left\n";
1320 case LYX_ALIGN_RIGHT:
1321 os << "\tAlign Right\n";
1323 case LYX_ALIGN_DECIMAL:
1324 case LYX_ALIGN_SPECIAL:
1325 case LYX_ALIGN_NONE:
1328 if (alignpossible & (LYX_ALIGN_BLOCK | LYX_ALIGN_CENTER |
1329 LYX_ALIGN_LAYOUT | LYX_ALIGN_LEFT | LYX_ALIGN_RIGHT)) {
1331 os << "\tAlignPossible";
1332 if (alignpossible & LYX_ALIGN_BLOCK) {
1336 if (alignpossible & LYX_ALIGN_CENTER) {
1342 if (alignpossible & LYX_ALIGN_LAYOUT) {
1348 if (alignpossible & LYX_ALIGN_LEFT) {
1354 if (alignpossible & LYX_ALIGN_RIGHT) {
1362 // LabelString must come before LabelStringAppendix
1363 if (!labelstring_.empty())
1364 os << "\tLabelString \"" << to_utf8(labelstring_) << "\"\n";
1365 if (!endlabelstring_.empty())
1366 os << "\tEndLabelString \"" << to_utf8(endlabelstring_) << "\"\n";
1367 if (!labelstring_appendix_.empty() && labelstring_appendix_ != labelstring_)
1368 os << "\tLabelStringAppendix \""
1369 << to_utf8(labelstring_appendix_) << "\"\n";
1370 if (!counter.empty())
1371 os << "\tLabelCounter \"" << to_utf8(counter) << "\"\n";
1372 os << "\tFreeSpacing " << free_spacing << '\n';
1373 os << "\tPassThru " << pass_thru << '\n';
1374 if (!pass_thru_chars.empty())
1375 os << "\tPassThruChars " << to_utf8(pass_thru_chars) << '\n';
1376 os << "\tParbreakIsNewline " << parbreak_is_newline << '\n';
1377 switch (spacing.getSpace()) {
1378 case Spacing::Double:
1379 os << "\tSpacing Double\n";
1381 case Spacing::Onehalf:
1382 os << "\tSpacing Onehalf\n";
1384 case Spacing::Other:
1385 os << "\tSpacing Other " << spacing.getValueAsString() << '\n';
1387 case Spacing::Single:
1388 os << "\tSpacing Single\n";
1390 case Spacing::Default:
1393 if (!requires_.empty()) {
1394 os << "\tRequires ";
1395 for (set<string>::const_iterator it = requires_.begin();
1396 it != requires_.end(); ++it) {
1397 if (it != requires_.begin())
1403 if (!nests_.empty()) {
1404 os << "\tNests\n\t";
1405 for (set<docstring>::const_iterator it = nests_.begin();
1406 it != nests_.end(); ++it) {
1407 if (it != nests_.begin())
1411 os << "\n\tEndNests\n";
1413 if (refprefix.empty())
1414 os << "\tRefPrefix OFF\n";
1416 os << "\tRefPrefix " << to_utf8(refprefix) << '\n';
1417 if (!htmltag_.empty())
1418 os << "\tHTMLTag " << htmltag_ << '\n';
1419 if (!htmlattr_.empty())
1420 os << "\tHTMLAttr " << htmlattr_ << '\n';
1421 if (!htmlitemtag_.empty())
1422 os << "\tHTMLItem " << htmlitemtag_ << '\n';
1423 if (!htmlitemattr_.empty())
1424 os << "\tHTMLItemAttr " << htmlitemattr_ << '\n';
1425 if (!htmllabeltag_.empty())
1426 os << "\tHTMLLabel " << htmllabeltag_ << '\n';
1427 if (!htmllabelattr_.empty())
1428 os << "\tHTMLLabelAttr " << htmllabelattr_ << '\n';
1429 os << "\tHTMLLabelFirst " << htmllabelfirst_ << '\n';
1430 if (!htmlstyle_.empty())
1431 os << "\tHTMLStyle\n"
1432 << to_utf8(rtrim(htmlstyle_, "\n"))
1433 << "\n\tEndHTMLStyle\n";
1434 os << "\tHTMLForceCSS " << htmlforcecss_ << '\n';
1435 if (!htmlpreamble_.empty())
1436 os << "\tHTMLPreamble\n"
1437 << to_utf8(rtrim(htmlpreamble_, "\n"))
1438 << "\n\tEndPreamble\n";
1439 os << "\tHTMLTitle " << htmltitle_ << "\n"
1440 "\tSpellcheck " << spellcheck << "\n"
1441 "\tForceLocal " << forcelocal << "\n"
1446 bool Layout::hasArgs() const
1448 return !latexargs_.empty() || !postcommandargs_.empty() ||
1453 Layout::LaTeXArgMap Layout::args() const
1455 LaTeXArgMap args = latexargs_;
1456 if (!postcommandargs_.empty())
1457 args.insert(postcommandargs_.begin(), postcommandargs_.end());
1458 if (!itemargs_.empty())
1459 args.insert(itemargs_.begin(), itemargs_.end());
1464 int Layout::optArgs() const
1467 LaTeXArgMap::const_iterator it = latexargs_.begin();
1468 for (; it != latexargs_.end(); ++it) {
1469 if (!(*it).second.mandatory)
1472 LaTeXArgMap::const_iterator iit = postcommandargs_.begin();
1473 for (; iit != postcommandargs_.end(); ++iit) {
1474 if (!(*iit).second.mandatory)
1481 int Layout::requiredArgs() const
1484 LaTeXArgMap::const_iterator it = latexargs_.begin();
1485 for (; it != latexargs_.end(); ++it) {
1486 if ((*it).second.mandatory)
1489 LaTeXArgMap::const_iterator iit = postcommandargs_.begin();
1490 for (; iit != postcommandargs_.end(); ++iit) {
1491 if (!(*iit).second.mandatory)
1498 string const & Layout::htmltag() const
1500 if (htmltag_.empty())
1506 string const & Layout::htmlattr() const
1508 if (htmlattr_.empty())
1509 htmlattr_ = "class=\"" + defaultCSSClass() + "\"";
1514 string const & Layout::htmlitemtag() const
1516 if (htmlitemtag_.empty())
1517 htmlitemtag_ = "div";
1518 return htmlitemtag_;
1522 string const & Layout::htmlitemattr() const
1524 if (htmlitemattr_.empty())
1525 htmlitemattr_ = "class=\"" + defaultCSSItemClass() + "\"";
1526 return htmlitemattr_;
1530 string const & Layout::htmllabeltag() const
1532 if (htmllabeltag_.empty())
1533 htmllabeltag_ = "span";
1534 return htmllabeltag_;
1538 string const & Layout::htmllabelattr() const
1540 if (htmllabelattr_.empty())
1541 htmllabelattr_ = "class=\"" + defaultCSSLabelClass() + "\"";
1542 return htmllabelattr_;
1546 docstring Layout::htmlstyle() const
1548 if (!htmlstyle_.empty() && !htmlforcecss_)
1550 if (htmldefaultstyle_.empty())
1552 docstring retval = htmldefaultstyle_;
1553 if (!htmlstyle_.empty())
1554 retval += '\n' + htmlstyle_;
1559 string Layout::defaultCSSClass() const
1561 if (!defaultcssclass_.empty())
1562 return defaultcssclass_;
1564 docstring::const_iterator it = name().begin();
1565 docstring::const_iterator en = name().end();
1566 for (; it != en; ++it) {
1567 char_type const c = *it;
1568 if (!isAlphaASCII(c)) {
1570 // make sure we don't start with an underscore,
1571 // as that sometimes causes problems.
1572 d = from_ascii("lyx_");
1575 } else if (isLower(c))
1578 // this is slow, so do it only if necessary
1581 defaultcssclass_ = to_utf8(d);
1582 return defaultcssclass_;
1588 string makeMarginValue(char const * side, double d)
1591 os << "margin-" << side << ": " << d << "ex;\n";
1598 void Layout::makeDefaultCSS() const
1600 // this never needs to be redone, since reloading layouts will
1601 // wipe out what we did before.
1602 if (!htmldefaultstyle_.empty())
1606 htmldefaultstyle_ = font.asCSS();
1611 tmp += makeMarginValue("top", topsep);
1613 tmp += makeMarginValue("bottom", bottomsep);
1614 if (!leftmargin.empty()) {
1615 // we can't really do what LyX does with the margin, so
1616 // we'll just figure out how many characters it is
1617 int const len = leftmargin.length();
1618 tmp += makeMarginValue("left", len);
1620 if (!rightmargin.empty()) {
1621 int const len = rightmargin.length();
1622 tmp += makeMarginValue("right", len);
1626 if (!htmldefaultstyle_.empty())
1627 htmldefaultstyle_ += from_ascii("\n");
1628 htmldefaultstyle_ += from_ascii(tmp);
1632 string where = alignmentToCSS(align);
1633 if (!where.empty()) {
1634 htmldefaultstyle_ += from_ascii("text-align: " + where + ";\n");
1637 // wrap up what we have, if anything
1638 if (!htmldefaultstyle_.empty())
1640 from_ascii(htmltag() + "." + defaultCSSClass() + " {\n") +
1641 htmldefaultstyle_ + from_ascii("\n}\n");
1643 if (labeltype == LABEL_NO_LABEL || htmllabeltag() == "NONE")
1649 if (labelfont != font)
1650 labelCSS = labelfont.asCSS() + from_ascii("\n");
1651 if (labeltype == LABEL_CENTERED)
1652 labelCSS += from_ascii("text-align: center;\n");
1654 if (!labelCSS.empty())
1655 htmldefaultstyle_ +=
1656 from_ascii(htmllabeltag() + "." + defaultCSSLabelClass() + " {\n") +
1657 labelCSS + from_ascii("\n}\n");
1661 bool Layout::operator==(Layout const & rhs) const
1663 // This is enough for the applications we actually make,
1664 // at least at the moment. But we could check more.
1665 return name() == rhs.name()
1666 && latexname() == rhs.latexname()
1667 && latextype == rhs.latextype;