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,
111 LT_INTITLE // keep this last!
114 /////////////////////
119 margintype = MARGIN_STATIC;
120 latextype = LATEX_PARAGRAPH;
126 labelfont = inherit_font;
128 reslabelfont = sane_font;
129 nextnoindent = false;
134 labelbottomsep = 0.0;
136 align = LYX_ALIGN_BLOCK;
137 alignpossible = LYX_ALIGN_NONE | LYX_ALIGN_LAYOUT;
138 labeltype = LABEL_NO_LABEL;
139 endlabeltype = END_LABEL_NO_LABEL;
140 // Should or should not. That is the question.
141 // spacing.set(Spacing::OneHalf);
142 newline_allowed = true;
143 free_spacing = false;
145 parbreak_is_newline = false;
146 toclevel = NOT_IN_TOC;
148 htmllabelfirst_ = false;
149 htmlforcecss_ = false;
153 itemcommand_ = "item";
154 toggle_indent = ITOGGLE_DOCUMENT_DEFAULT;
159 bool Layout::read(Lexer & lex, TextClass const & tclass)
161 // If this is an empty layout, or if no force local version is set,
162 // we know that we will not discard the stuff to read
164 return readIgnoreForcelocal(lex, tclass);
167 bool const ret = tmp.readIgnoreForcelocal(lex, tclass);
169 // - the read version is higher
170 // - both versions are infinity (arbitrary decision)
171 // - the file did not contain any local version (needed for not
172 // skipping user defined local layouts)
173 if (tmp.forcelocal <= 0 || tmp.forcelocal > forcelocal)
179 bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass)
181 // This table is sorted alphabetically [asierra 30March96]
182 LexerKeyword layoutTags[] = {
183 { "align", LT_ALIGN },
184 { "alignpossible", LT_ALIGNPOSSIBLE },
185 { "argument", LT_ARGUMENT },
186 { "babelpreamble", LT_BABELPREAMBLE },
187 { "bottomsep", LT_BOTTOMSEP },
188 { "category", LT_CATEGORY },
189 { "commanddepth", LT_COMMANDDEPTH },
190 { "copystyle", LT_COPYSTYLE },
191 { "dependson", LT_DEPENDSON },
193 { "endlabelstring", LT_ENDLABELSTRING },
194 { "endlabeltype", LT_ENDLABELTYPE },
196 { "forcelocal", LT_FORCELOCAL },
197 { "freespacing", LT_FREE_SPACING },
198 { "htmlattr", LT_HTMLATTR },
199 { "htmlforcecss", LT_HTMLFORCECSS },
200 { "htmlitem", LT_HTMLITEM },
201 { "htmlitemattr", LT_HTMLITEMATTR },
202 { "htmllabel", LT_HTMLLABEL },
203 { "htmllabelattr", LT_HTMLLABELATTR },
204 { "htmllabelfirst", LT_HTMLLABELFIRST },
205 { "htmlpreamble", LT_HTMLPREAMBLE },
206 { "htmlstyle", LT_HTMLSTYLE },
207 { "htmltag", LT_HTMLTAG },
208 { "htmltitle", LT_HTMLTITLE },
209 { "innertag", LT_INNERTAG },
210 { "inpreamble", LT_INPREAMBLE },
211 { "intitle", LT_INTITLE },
212 { "itemcommand", LT_ITEMCOMMAND },
213 { "itemsep", LT_ITEMSEP },
214 { "itemtag", LT_ITEMTAG },
215 { "keepempty", LT_KEEPEMPTY },
216 { "labelbottomsep", LT_LABEL_BOTTOMSEP },
217 { "labelcounter", LT_LABELCOUNTER },
218 { "labelfont", LT_LABELFONT },
219 { "labelindent", LT_LABELINDENT },
220 { "labelsep", LT_LABELSEP },
221 { "labelstring", LT_LABELSTRING },
222 { "labelstringappendix", LT_LABELSTRING_APPENDIX },
223 { "labeltag", LT_LABELTAG },
224 { "labeltype", LT_LABELTYPE },
225 { "langpreamble", LT_LANGPREAMBLE },
226 { "latexname", LT_LATEXNAME },
227 { "latexparam", LT_LATEXPARAM },
228 { "latextype", LT_LATEXTYPE },
229 { "leftdelim", LT_LEFTDELIM },
230 { "leftmargin", LT_LEFTMARGIN },
231 { "margin", LT_MARGIN },
232 { "needprotect", LT_NEED_PROTECT },
233 { "newline", LT_NEWLINE },
234 { "nextnoindent", LT_NEXTNOINDENT },
235 { "obsoletedby", LT_OBSOLETEDBY },
236 { "paragraphgroup", LT_PAR_GROUP },
237 { "parbreakisnewline", LT_PARBREAK_IS_NEWLINE },
238 { "parindent", LT_PARINDENT },
239 { "parsep", LT_PARSEP },
240 { "parskip", LT_PARSKIP },
241 { "passthru", LT_PASS_THRU },
242 { "passthruchars", LT_PASS_THRU_CHARS },
243 { "preamble", LT_PREAMBLE },
244 { "refprefix", LT_REFPREFIX },
245 { "requires", LT_REQUIRES },
246 { "resetargs", LT_RESETARGS },
247 { "rightdelim", LT_RIGHTDELIM },
248 { "rightmargin", LT_RIGHTMARGIN },
249 { "spacing", LT_SPACING },
250 { "spellcheck", LT_SPELLCHECK },
251 { "textfont", LT_TEXTFONT },
252 { "toclevel", LT_TOCLEVEL },
253 { "toggleindent", LT_TOGGLE_INDENT },
254 { "topsep", LT_TOPSEP }
258 bool finished = false;
259 lex.pushTable(layoutTags);
261 // parse style section
262 while (!finished && lex.isOK() && !error) {
264 // See comment in LyXRC.cpp.
266 case Lexer::LEX_FEOF:
269 case Lexer::LEX_UNDEF:
271 lex.printError("Unknown layout tag `$$Token'");
278 switch (static_cast<LayoutTags>(le)) {
290 style = subst(style, '_', ' ');
292 if (tclass.hasLayout(style)) {
293 docstring const tmpname = name_;
294 this->operator=(tclass[style]);
297 LYXERR0("Cannot copy unknown style `"
299 << "All layouts so far:");
300 DocumentClass::const_iterator lit = tclass.begin();
301 DocumentClass::const_iterator len = tclass.end();
302 for (; lit != len; ++lit)
303 LYXERR0(lit->name());
308 case LT_OBSOLETEDBY: {
311 style = subst(style, '_', ' ');
313 if (tclass.hasLayout(style)) {
314 docstring const tmpname = name_;
315 this->operator=(tclass[style]);
317 if (obsoleted_by().empty())
318 obsoleted_by_ = style;
320 LYXERR0("Cannot replace with unknown style `"
323 //lex.printError("Cannot replace with"
332 depends_on_ = subst(depends_on_, '_', ' ');
361 postcommandargs_.clear();
369 case LT_NEED_PROTECT:
378 font = lyxRead(lex, font);
383 font = lyxRead(lex, font);
387 labelfont = lyxRead(lex, labelfont);
390 case LT_NEXTNOINDENT:
394 case LT_TOGGLE_INDENT: {
397 tog = support::ascii_lowercase(tog);
399 toggle_indent = ITOGGLE_ALWAYS;
400 else if (tog == "never")
401 toggle_indent = ITOGGLE_NEVER;
403 toggle_indent = ITOGGLE_DOCUMENT_DEFAULT;
407 case LT_COMMANDDEPTH:
417 latexparam_ = subst(latexparam_, """, "\"");
422 leftdelim_ = support::subst(leftdelim_, from_ascii("<br/>"),
428 rightdelim_ = support::subst(rightdelim_, from_ascii("<br/>"),
449 preamble_ = from_utf8(lex.getLongString("EndPreamble"));
452 case LT_LANGPREAMBLE:
453 langpreamble_ = from_utf8(lex.getLongString("EndLangPreamble"));
456 case LT_BABELPREAMBLE:
457 babelpreamble_ = from_utf8(lex.getLongString("EndBabelPreamble"));
464 case LT_ENDLABELTYPE:
465 readEndLabelType(lex);
500 case LT_LABEL_BOTTOMSEP:
501 lex >> labelbottomsep;
506 labelsep = subst(labelsep, 'x', ' ');
514 lex >> newline_allowed;
521 case LT_ALIGNPOSSIBLE:
522 readAlignPossible(lex);
526 // FIXME: this means LT_LABELSTRING_APPENDIX may only
527 // occur after LT_LABELSTRING
529 labelstring_ = trim(labelstring_);
530 labelstring_appendix_ = labelstring_;
533 case LT_ENDLABELSTRING:
534 lex >> endlabelstring_;
535 endlabelstring_ = trim(endlabelstring_);
538 case LT_LABELSTRING_APPENDIX:
539 lex >> labelstring_appendix_;
540 labelstring_appendix_ = trim(labelstring_appendix_);
543 case LT_LABELCOUNTER:
545 counter = trim(counter);
552 case LT_FREE_SPACING:
560 case LT_PASS_THRU_CHARS:
561 lex >> pass_thru_chars;
564 case LT_PARBREAK_IS_NEWLINE:
565 lex >> parbreak_is_newline;
574 vector<string> const req =
575 getVectorFromString(lex.getString(true));
576 requires_.insert(req.begin(), req.end());
602 case LT_HTMLITEMATTR:
603 lex >> htmlitemattr_;
607 lex >> htmllabeltag_;
610 case LT_HTMLLABELATTR:
611 lex >> htmllabelattr_;
614 case LT_HTMLLABELFIRST:
615 lex >> htmllabelfirst_;
619 htmlstyle_ = from_utf8(lex.getLongString("EndHTMLStyle"));
622 case LT_HTMLFORCECSS:
623 lex >> htmlforcecss_;
626 case LT_HTMLPREAMBLE:
627 htmlpreamble_ = from_utf8(lex.getLongString("EndPreamble"));
644 // make sure we only have inpreamble = true for commands
645 if (inpreamble && latextype != LATEX_COMMAND && latextype != LATEX_PARAGRAPH) {
646 LYXERR0("InPreamble not permitted except with command and paragraph layouts.");
647 LYXERR0("Layout name: " << name());
651 return finished && !error;
664 LexerKeyword alignTags[] = {
665 { "block", AT_BLOCK },
666 { "center", AT_CENTER },
667 { "layout", AT_LAYOUT },
669 { "right", AT_RIGHT }
673 void Layout::readAlign(Lexer & lex)
675 PushPopHelper pph(lex, alignTags);
678 case Lexer::LEX_UNDEF:
679 lex.printError("Unknown alignment `$$Token'");
685 align = LYX_ALIGN_BLOCK;
688 align = LYX_ALIGN_LEFT;
691 align = LYX_ALIGN_RIGHT;
694 align = LYX_ALIGN_CENTER;
697 align = LYX_ALIGN_LAYOUT;
703 void Layout::readAlignPossible(Lexer & lex)
705 lex.pushTable(alignTags);
706 alignpossible = LYX_ALIGN_NONE | LYX_ALIGN_LAYOUT;
707 int lineno = lex.lineNumber();
711 case Lexer::LEX_UNDEF:
712 lex.printError("Unknown alignment `$$Token'");
718 alignpossible |= LYX_ALIGN_BLOCK;
721 alignpossible |= LYX_ALIGN_LEFT;
724 alignpossible |= LYX_ALIGN_RIGHT;
727 alignpossible |= LYX_ALIGN_CENTER;
730 alignpossible |= LYX_ALIGN_LAYOUT;
733 } while (lineno == lex.lineNumber());
738 void Layout::readLabelType(Lexer & lex)
753 LexerKeyword labelTypeTags[] = {
754 { "above", LA_ABOVE },
755 { "bibliography", LA_BIBLIO },
756 { "centered", LA_CENTERED },
757 { "enumerate", LA_ENUMERATE },
758 { "itemize", LA_ITEMIZE },
759 { "manual", LA_MANUAL },
760 { "no_label", LA_NO_LABEL },
761 { "sensitive", LA_SENSITIVE },
762 { "static", LA_STATIC }
765 PushPopHelper pph(lex, labelTypeTags);
768 case Lexer::LEX_UNDEF:
769 lex.printError("Unknown labeltype tag `$$Token'");
775 labeltype = LABEL_NO_LABEL;
778 labeltype = LABEL_MANUAL;
781 labeltype = LABEL_ABOVE;
784 labeltype = LABEL_CENTERED;
787 labeltype = LABEL_STATIC;
790 labeltype = LABEL_SENSITIVE;
793 labeltype = LABEL_ENUMERATE;
796 labeltype = LABEL_ITEMIZE;
799 labeltype = LABEL_BIBLIO;
805 void Layout::readEndLabelType(Lexer & lex)
807 // this should be const, but can't be because
809 static LexerKeyword endlabelTypeTags[] = {
810 { "box", END_LABEL_BOX },
811 { "filled_box", END_LABEL_FILLED_BOX },
812 { "no_label", END_LABEL_NO_LABEL },
813 { "static", END_LABEL_STATIC }
816 PushPopHelper pph(lex, endlabelTypeTags);
819 case Lexer::LEX_UNDEF:
820 lex.printError("Unknown labeltype tag `$$Token'");
822 case END_LABEL_STATIC:
824 case END_LABEL_FILLED_BOX:
825 case END_LABEL_NO_LABEL:
826 endlabeltype = static_cast<EndLabelType>(le);
829 LYXERR0("Unhandled value " << le);
835 void Layout::readMargin(Lexer & lex)
837 LexerKeyword marginTags[] = {
838 { "dynamic", MARGIN_DYNAMIC },
839 { "first_dynamic", MARGIN_FIRST_DYNAMIC },
840 { "manual", MARGIN_MANUAL },
841 { "right_address_box", MARGIN_RIGHT_ADDRESS_BOX },
842 { "static", MARGIN_STATIC }
845 PushPopHelper pph(lex, marginTags);
849 case Lexer::LEX_UNDEF:
850 lex.printError("Unknown margin type tag `$$Token'");
855 case MARGIN_FIRST_DYNAMIC:
856 case MARGIN_RIGHT_ADDRESS_BOX:
857 margintype = static_cast<MarginType>(le);
860 LYXERR0("Unhandled value " << le);
866 void Layout::readLatexType(Lexer & lex)
868 LexerKeyword latexTypeTags[] = {
869 { "bib_environment", LATEX_BIB_ENVIRONMENT },
870 { "command", LATEX_COMMAND },
871 { "environment", LATEX_ENVIRONMENT },
872 { "item_environment", LATEX_ITEM_ENVIRONMENT },
873 { "list_environment", LATEX_LIST_ENVIRONMENT },
874 { "paragraph", LATEX_PARAGRAPH }
877 PushPopHelper pph(lex, latexTypeTags);
880 case Lexer::LEX_UNDEF:
881 lex.printError("Unknown latextype tag `$$Token'");
883 case LATEX_PARAGRAPH:
885 case LATEX_ITEM_ENVIRONMENT:
886 case LATEX_LIST_ENVIRONMENT:
887 latextype = static_cast<LatexType>(le);
889 case LATEX_ENVIRONMENT:
890 case LATEX_BIB_ENVIRONMENT:
891 latextype = static_cast<LatexType>(le);
895 LYXERR0("Unhandled value " << le);
901 void Layout::readSpacing(Lexer & lex)
904 ST_SPACING_SINGLE = 1,
910 LexerKeyword spacingTags[] = {
911 {"double", ST_SPACING_DOUBLE },
912 {"onehalf", ST_SPACING_ONEHALF },
913 {"other", ST_OTHER },
914 {"single", ST_SPACING_SINGLE }
917 PushPopHelper pph(lex, spacingTags);
920 case Lexer::LEX_UNDEF:
921 lex.printError("Unknown spacing token `$$Token'");
926 case ST_SPACING_SINGLE:
927 spacing.set(Spacing::Single);
929 case ST_SPACING_ONEHALF:
930 spacing.set(Spacing::Onehalf);
932 case ST_SPACING_DOUBLE:
933 spacing.set(Spacing::Double);
937 spacing.set(Spacing::Other, lex.getString());
943 void Layout::readArgument(Lexer & lex)
946 // writeArgument() makes use of these default values
947 arg.mandatory = false;
948 arg.autoinsert = false;
949 arg.insertcotext = false;
951 bool finished = false;
952 arg.font = inherit_font;
953 arg.labelfont = inherit_font;
956 bool const itemarg = prefixIs(id, "item:");
957 bool const postcmd = prefixIs(id, "post:");
959 while (!finished && lex.isOK() && !error) {
961 string const tok = ascii_lowercase(lex.getString());
965 } else if (tok == "endargument") {
967 } else if (tok == "labelstring") {
969 arg.labelstring = lex.getDocString();
970 } else if (tok == "menustring") {
972 arg.menustring = lex.getDocString();
973 } else if (tok == "mandatory") {
975 arg.mandatory = lex.getBool();
976 } else if (tok == "autoinsert") {
978 arg.autoinsert = lex.getBool();
979 } else if (tok == "insertcotext") {
981 arg.insertcotext = lex.getBool();
982 } else if (tok == "leftdelim") {
984 arg.ldelim = lex.getDocString();
985 arg.ldelim = support::subst(arg.ldelim, from_ascii("<br/>"),
987 } else if (tok == "rightdelim") {
989 arg.rdelim = lex.getDocString();
990 arg.rdelim = support::subst(arg.rdelim, from_ascii("<br/>"),
992 } else if (tok == "defaultarg") {
994 arg.defaultarg = lex.getDocString();
995 } else if (tok == "presetarg") {
997 arg.presetarg = lex.getDocString();
998 } else if (tok == "tooltip") {
1000 arg.tooltip = lex.getDocString();
1001 } else if (tok == "requires") {
1003 arg.requires = lex.getString();
1004 } else if (tok == "decoration") {
1006 arg.decoration = lex.getString();
1007 } else if (tok == "font") {
1008 arg.font = lyxRead(lex, arg.font);
1009 } else if (tok == "labelfont") {
1010 arg.labelfont = lyxRead(lex, arg.labelfont);
1011 } else if (tok == "passthruchars") {
1013 arg.pass_thru_chars = lex.getDocString();
1015 lex.printError("Unknown tag");
1019 if (arg.labelstring.empty())
1020 LYXERR0("Incomplete Argument definition!");
1022 itemargs_[id] = arg;
1024 postcommandargs_[id] = arg;
1026 latexargs_[id] = arg;
1030 void writeArgument(ostream & os, string const & id, Layout::latexarg const & arg)
1032 os << "\tArgument " << id << '\n';
1033 if (!arg.labelstring.empty())
1034 os << "\t\tLabelString \"" << to_utf8(arg.labelstring) << "\"\n";
1035 if (!arg.menustring.empty())
1036 os << "\t\tMenuString \"" << to_utf8(arg.menustring) << "\"\n";
1038 os << "\t\tMandatory " << arg.mandatory << '\n';
1040 os << "\t\tAutoinsert " << arg.autoinsert << '\n';
1041 if (arg.insertcotext)
1042 os << "\t\tInsertCotext " << arg.insertcotext << '\n';
1043 if (!arg.ldelim.empty())
1044 os << "\t\tLeftDelim \""
1045 << to_utf8(subst(arg.ldelim, from_ascii("\n"), from_ascii("<br/>")))
1047 if (!arg.rdelim.empty())
1048 os << "\t\tRightDelim \""
1049 << to_utf8(subst(arg.rdelim, from_ascii("\n"), from_ascii("<br/>")))
1051 if (!arg.defaultarg.empty())
1052 os << "\t\tDefaultArg \"" << to_utf8(arg.defaultarg) << "\"\n";
1053 if (!arg.presetarg.empty())
1054 os << "\t\tPresetArg \"" << to_utf8(arg.presetarg) << "\"\n";
1055 if (!arg.tooltip.empty())
1056 os << "\t\tToolTip \"" << to_utf8(arg.tooltip) << "\"\n";
1057 if (!arg.requires.empty())
1058 os << "\t\tRequires \"" << arg.requires << "\"\n";
1059 if (!arg.decoration.empty())
1060 os << "\t\tDecoration \"" << arg.decoration << "\"\n";
1061 if (arg.font != inherit_font)
1062 lyxWrite(os, arg.font, "Font", 2);
1063 if (arg.labelfont != inherit_font)
1064 lyxWrite(os, arg.labelfont, "LabelFont", 2);
1065 if (!arg.pass_thru_chars.empty())
1066 os << "\t\tPassThruChars \"" << to_utf8(arg.pass_thru_chars) << "\"\n";
1067 os << "\tEndArgument\n";
1071 void Layout::write(ostream & os) const
1073 os << "Style " << to_utf8(name_) << '\n';
1074 if (!category_.empty() && obsoleted_by_.empty())
1075 os << "\tCategory \"" << to_utf8(category_) << "\"\n";
1076 // Can't deduce Copystyle here :-(
1077 if (!obsoleted_by_.empty()) {
1078 os << "\tObsoletedBy \"" << to_utf8(obsoleted_by_)
1082 if (!depends_on_.empty())
1083 os << "\tDependsOn " << to_utf8(depends_on_) << '\n';
1084 switch (margintype) {
1085 case MARGIN_DYNAMIC:
1086 os << "\tMargin Dynamic\n";
1088 case MARGIN_FIRST_DYNAMIC:
1089 os << "\tMargin First_Dynamic\n";
1092 os << "\tMargin Manual\n";
1094 case MARGIN_RIGHT_ADDRESS_BOX:
1095 os << "\tMargin Right_Address_Box\n";
1098 os << "\tMargin Static\n";
1101 switch (latextype) {
1102 case LATEX_BIB_ENVIRONMENT:
1103 os << "\tLatexType Bib_Environment\n";
1106 os << "\tLatexType Command\n";
1108 case LATEX_ENVIRONMENT:
1109 os << "\tLatexType Environment\n";
1111 case LATEX_ITEM_ENVIRONMENT:
1112 os << "\tLatexType Item_Environment\n";
1114 case LATEX_LIST_ENVIRONMENT:
1115 os << "\tLatexType List_Environment\n";
1117 case LATEX_PARAGRAPH:
1118 os << "\tLatexType Paragraph\n";
1121 os << "\tInTitle " << intitle << "\n"
1122 "\tInPreamble " << inpreamble << "\n"
1123 "\tTocLevel " << toclevel << '\n';
1124 // ResetArgs does not make sense here
1125 for (LaTeXArgMap::const_iterator it = latexargs_.begin();
1126 it != latexargs_.end(); ++it)
1127 writeArgument(os, it->first, it->second);
1128 for (LaTeXArgMap::const_iterator it = itemargs_.begin();
1129 it != itemargs_.end(); ++it)
1130 writeArgument(os, it->first, it->second);
1131 for (LaTeXArgMap::const_iterator it = postcommandargs_.begin();
1132 it != postcommandargs_.end(); ++it)
1133 writeArgument(os, it->first, it->second);
1134 os << "\tNeedProtect " << needprotect << "\n"
1135 "\tKeepEmpty " << keepempty << '\n';
1136 if (labelfont == font)
1137 lyxWrite(os, font, "Font", 1);
1139 lyxWrite(os, font, "TextFont", 1);
1140 lyxWrite(os, labelfont, "LabelFont", 1);
1142 os << "\tNextNoIndent " << nextnoindent << "\n"
1143 "\tCommandDepth " << commanddepth << '\n';
1144 if (!latexname_.empty())
1145 os << "\tLatexName \"" << latexname_ << "\"\n";
1146 if (!latexparam_.empty())
1147 os << "\tLatexParam \"" << subst(latexparam_, "\"", """)
1149 if (!leftdelim_.empty())
1150 os << "\tLeftDelim "
1151 << to_utf8(subst(leftdelim_, from_ascii("\n"), from_ascii("<br/>")))
1153 if (!rightdelim_.empty())
1154 os << "\tRightDelim "
1155 << to_utf8(subst(rightdelim_, from_ascii("\n"), from_ascii("<br/>")))
1157 if (!innertag_.empty())
1158 os << "\tInnerTag \"" << innertag_ << "\"\n";
1159 if (!labeltag_.empty())
1160 os << "\tLabelTag \"" << labeltag_ << "\"\n";
1161 if (!itemtag_.empty())
1162 os << "\tItemTag \"" << itemtag_ << "\"\n";
1163 if (!itemcommand_.empty())
1164 os << "\tItemCommand " << itemcommand_ << '\n';
1165 if (!preamble_.empty())
1166 os << "\tPreamble\n\t"
1167 << to_utf8(subst(rtrim(preamble_, "\n"),
1168 from_ascii("\n"), from_ascii("\n\t")))
1169 << "\n\tEndPreamble\n";
1170 if (!langpreamble_.empty())
1171 os << "\tLangPreamble\n\t"
1172 << to_utf8(subst(rtrim(langpreamble_, "\n"),
1173 from_ascii("\n"), from_ascii("\n\t")))
1174 << "\n\tEndLangPreamble\n";
1175 if (!babelpreamble_.empty())
1176 os << "\tBabelPreamble\n\t"
1177 << to_utf8(subst(rtrim(babelpreamble_, "\n"),
1178 from_ascii("\n"), from_ascii("\n\t")))
1179 << "\n\tEndBabelPreamble\n";
1180 switch (labeltype) {
1182 os << "\tLabelType Above\n";
1185 os << "\tLabelType Bibliography\n";
1187 case LABEL_CENTERED:
1188 os << "\tLabelType Centered\n";
1190 case LABEL_ENUMERATE:
1191 os << "\tLabelType Enumerate\n";
1194 os << "\tLabelType Itemize\n";
1197 os << "\tLabelType Manual\n";
1199 case LABEL_NO_LABEL:
1200 os << "\tLabelType No_Label\n";
1202 case LABEL_SENSITIVE:
1203 os << "\tLabelType Sensitive\n";
1206 os << "\tLabelType Static\n";
1209 switch (endlabeltype) {
1211 os << "\tEndLabelType Box\n";
1213 case END_LABEL_FILLED_BOX:
1214 os << "\tEndLabelType Filled_Box\n";
1216 case END_LABEL_NO_LABEL:
1217 os << "\tEndLabelType No_Label\n";
1219 case END_LABEL_STATIC:
1220 os << "\tEndLabelType Static\n";
1223 os << "\tParagraphGroup \"" << par_group_ << "\"\n";
1224 if (!leftmargin.empty())
1225 os << "\tLeftMargin \"" << to_utf8(leftmargin) << "\"\n";
1226 if (!rightmargin.empty())
1227 os << "\tRightMargin \"" << to_utf8(rightmargin) << "\"\n";
1228 if (!labelindent.empty())
1229 os << "\tLabelIndent " << to_utf8(labelindent) << '\n';
1230 if (!parindent.empty())
1231 os << "\tParIndent " << to_utf8(parindent) << '\n';
1232 os << "\tParSkip " << parskip << "\n"
1233 "\tItemSep " << itemsep << "\n"
1234 "\tTopSep " << topsep << "\n"
1235 "\tBottomSep " << bottomsep << "\n"
1236 "\tLabelBottomSep " << labelbottomsep << '\n';
1237 if (!labelsep.empty())
1238 os << "\tLabelSep " << to_utf8(subst(labelsep, ' ', 'x'))
1240 os << "\tParSep " << parsep << "\n"
1241 "\tNewLine " << newline_allowed << '\n';
1243 case LYX_ALIGN_BLOCK:
1244 os << "\tAlign Block\n";
1246 case LYX_ALIGN_CENTER:
1247 os << "\tAlign Center\n";
1249 case LYX_ALIGN_LAYOUT:
1250 os << "\tAlign Layout\n";
1252 case LYX_ALIGN_LEFT:
1253 os << "\tAlign Left\n";
1255 case LYX_ALIGN_RIGHT:
1256 os << "\tAlign Right\n";
1258 case LYX_ALIGN_DECIMAL:
1259 case LYX_ALIGN_SPECIAL:
1260 case LYX_ALIGN_NONE:
1263 if (alignpossible & (LYX_ALIGN_BLOCK | LYX_ALIGN_CENTER |
1264 LYX_ALIGN_LAYOUT | LYX_ALIGN_LEFT | LYX_ALIGN_RIGHT)) {
1266 os << "\tAlignPossible";
1267 if (alignpossible & LYX_ALIGN_BLOCK) {
1271 if (alignpossible & LYX_ALIGN_CENTER) {
1277 if (alignpossible & LYX_ALIGN_LAYOUT) {
1283 if (alignpossible & LYX_ALIGN_LEFT) {
1289 if (alignpossible & LYX_ALIGN_RIGHT) {
1297 // LabelString must come before LabelStringAppendix
1298 if (!labelstring_.empty())
1299 os << "\tLabelString \"" << to_utf8(labelstring_) << "\"\n";
1300 if (!endlabelstring_.empty())
1301 os << "\tEndLabelString \"" << to_utf8(endlabelstring_) << "\"\n";
1302 if (!labelstring_appendix_.empty() && labelstring_appendix_ != labelstring_)
1303 os << "\tLabelStringAppendix \""
1304 << to_utf8(labelstring_appendix_) << "\"\n";
1305 if (!counter.empty())
1306 os << "\tLabelCounter \"" << to_utf8(counter) << "\"\n";
1307 os << "\tFreeSpacing " << free_spacing << '\n';
1308 os << "\tPassThru " << pass_thru << '\n';
1309 if (!pass_thru_chars.empty())
1310 os << "\tPassThruChars " << to_utf8(pass_thru_chars) << '\n';
1311 os << "\tParbreakIsNewline " << parbreak_is_newline << '\n';
1312 switch (spacing.getSpace()) {
1313 case Spacing::Double:
1314 os << "\tSpacing Double\n";
1316 case Spacing::Onehalf:
1317 os << "\tSpacing Onehalf\n";
1319 case Spacing::Other:
1320 os << "\tSpacing Other " << spacing.getValueAsString() << '\n';
1322 case Spacing::Single:
1323 os << "\tSpacing Single\n";
1325 case Spacing::Default:
1328 if (!requires_.empty()) {
1329 os << "\tRequires ";
1330 for (set<string>::const_iterator it = requires_.begin();
1331 it != requires_.end(); ++it) {
1332 if (it != requires_.begin())
1338 if (refprefix.empty())
1339 os << "\tRefPrefix OFF\n";
1341 os << "\tRefPrefix " << to_utf8(refprefix) << '\n';
1342 if (!htmltag_.empty())
1343 os << "\tHTMLTag " << htmltag_ << '\n';
1344 if (!htmlattr_.empty())
1345 os << "\tHTMLAttr " << htmlattr_ << '\n';
1346 if (!htmlitemtag_.empty())
1347 os << "\tHTMLItem " << htmlitemtag_ << '\n';
1348 if (!htmlitemattr_.empty())
1349 os << "\tHTMLItemAttr " << htmlitemattr_ << '\n';
1350 if (!htmllabeltag_.empty())
1351 os << "\tHTMLLabel " << htmllabeltag_ << '\n';
1352 if (!htmllabelattr_.empty())
1353 os << "\tHTMLLabelAttr " << htmllabelattr_ << '\n';
1354 os << "\tHTMLLabelFirst " << htmllabelfirst_ << '\n';
1355 if (!htmlstyle_.empty())
1356 os << "\tHTMLStyle\n"
1357 << to_utf8(rtrim(htmlstyle_, "\n"))
1358 << "\n\tEndHTMLStyle\n";
1359 os << "\tHTMLForceCSS " << htmlforcecss_ << '\n';
1360 if (!htmlpreamble_.empty())
1361 os << "\tHTMLPreamble\n"
1362 << to_utf8(rtrim(htmlpreamble_, "\n"))
1363 << "\n\tEndPreamble\n";
1364 os << "\tHTMLTitle " << htmltitle_ << "\n"
1365 "\tSpellcheck " << spellcheck << "\n"
1366 "\tForceLocal " << forcelocal << "\n"
1371 Layout::LaTeXArgMap Layout::args() const
1373 LaTeXArgMap args = latexargs_;
1374 if (!postcommandargs_.empty())
1375 args.insert(postcommandargs_.begin(), postcommandargs_.end());
1376 if (!itemargs_.empty())
1377 args.insert(itemargs_.begin(), itemargs_.end());
1382 int Layout::optArgs() const
1385 LaTeXArgMap::const_iterator it = latexargs_.begin();
1386 for (; it != latexargs_.end(); ++it) {
1387 if (!(*it).second.mandatory)
1390 LaTeXArgMap::const_iterator iit = postcommandargs_.begin();
1391 for (; iit != postcommandargs_.end(); ++iit) {
1392 if (!(*iit).second.mandatory)
1399 int Layout::requiredArgs() const
1402 LaTeXArgMap::const_iterator it = latexargs_.begin();
1403 for (; it != latexargs_.end(); ++it) {
1404 if ((*it).second.mandatory)
1407 LaTeXArgMap::const_iterator iit = postcommandargs_.begin();
1408 for (; iit != postcommandargs_.end(); ++iit) {
1409 if (!(*iit).second.mandatory)
1416 string const & Layout::htmltag() const
1418 if (htmltag_.empty())
1424 string const & Layout::htmlattr() const
1426 if (htmlattr_.empty())
1427 htmlattr_ = "class=\"" + defaultCSSClass() + "\"";
1432 string const & Layout::htmlitemtag() const
1434 if (htmlitemtag_.empty())
1435 htmlitemtag_ = "div";
1436 return htmlitemtag_;
1440 string const & Layout::htmlitemattr() const
1442 if (htmlitemattr_.empty())
1443 htmlitemattr_ = "class=\"" + defaultCSSItemClass() + "\"";
1444 return htmlitemattr_;
1448 string const & Layout::htmllabeltag() const
1450 if (htmllabeltag_.empty()) {
1451 if (labeltype != LABEL_ABOVE &&
1452 labeltype != LABEL_CENTERED)
1453 htmllabeltag_ = "span";
1455 htmllabeltag_ = "div";
1457 return htmllabeltag_;
1461 string const & Layout::htmllabelattr() const
1463 if (htmllabelattr_.empty())
1464 htmllabelattr_ = "class=\"" + defaultCSSLabelClass() + "\"";
1465 return htmllabelattr_;
1469 docstring Layout::htmlstyle() const
1471 if (!htmlstyle_.empty() && !htmlforcecss_)
1473 if (htmldefaultstyle_.empty())
1475 docstring retval = htmldefaultstyle_;
1476 if (!htmlstyle_.empty())
1477 retval += '\n' + htmlstyle_;
1482 string Layout::defaultCSSClass() const
1484 if (!defaultcssclass_.empty())
1485 return defaultcssclass_;
1487 docstring::const_iterator it = name().begin();
1488 docstring::const_iterator en = name().end();
1489 for (; it != en; ++it) {
1490 char_type const c = *it;
1491 if (!isAlphaASCII(c)) {
1493 // make sure we don't start with an underscore,
1494 // as that sometimes causes problems.
1495 d = from_ascii("lyx_");
1498 } else if (isLower(c))
1501 // this is slow, so do it only if necessary
1504 defaultcssclass_ = to_utf8(d);
1505 return defaultcssclass_;
1511 string makeMarginValue(char const * side, double d)
1514 os << "margin-" << side << ": " << d << "ex;\n";
1521 void Layout::makeDefaultCSS() const
1523 // this never needs to be redone, since reloading layouts will
1524 // wipe out what we did before.
1525 if (!htmldefaultstyle_.empty())
1529 htmldefaultstyle_ = font.asCSS();
1534 tmp += makeMarginValue("top", topsep);
1536 tmp += makeMarginValue("bottom", bottomsep);
1537 if (!leftmargin.empty()) {
1538 // we can't really do what LyX does with the margin, so
1539 // we'll just figure out how many characters it is
1540 int const len = leftmargin.length();
1541 tmp += makeMarginValue("left", len);
1543 if (!rightmargin.empty()) {
1544 int const len = rightmargin.length();
1545 tmp += makeMarginValue("right", len);
1549 if (!htmldefaultstyle_.empty())
1550 htmldefaultstyle_ += from_ascii("\n");
1551 htmldefaultstyle_ += from_ascii(tmp);
1555 string where = alignmentToCSS(align);
1556 if (!where.empty()) {
1557 htmldefaultstyle_ += from_ascii("text-align: " + where + ";\n");
1560 // wrap up what we have, if anything
1561 if (!htmldefaultstyle_.empty())
1563 from_ascii(htmltag() + "." + defaultCSSClass() + " {\n") +
1564 htmldefaultstyle_ + from_ascii("\n}\n");
1566 if (labeltype == LABEL_NO_LABEL || htmllabeltag() == "NONE")
1572 if (labelfont != font)
1573 labelCSS = labelfont.asCSS() + from_ascii("\n");
1574 if (labeltype == LABEL_CENTERED)
1575 labelCSS += from_ascii("text-align: center;\n");
1577 if (!labelCSS.empty())
1578 htmldefaultstyle_ +=
1579 from_ascii(htmllabeltag() + "." + defaultCSSLabelClass() + " {\n") +
1580 labelCSS + from_ascii("\n}\n");
1584 bool Layout::operator==(Layout const & rhs) const
1586 // This is enough for the applications we actually make,
1587 // at least at the moment. But we could check more.
1588 return name() == rhs.name()
1589 && latexname() == rhs.latexname()
1590 && latextype == rhs.latextype;