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]
54 LT_PARBREAK_IS_NEWLINE,
64 LT_LABELSTRING_APPENDIX,
109 LT_INTITLE // keep this last!
112 /////////////////////
117 margintype = MARGIN_STATIC;
118 latextype = LATEX_PARAGRAPH;
124 labelfont = inherit_font;
126 reslabelfont = sane_font;
127 nextnoindent = false;
132 labelbottomsep = 0.0;
134 align = LYX_ALIGN_BLOCK;
135 alignpossible = LYX_ALIGN_NONE | LYX_ALIGN_LAYOUT;
136 labeltype = LABEL_NO_LABEL;
137 endlabeltype = END_LABEL_NO_LABEL;
138 // Should or should not. That is the question.
139 // spacing.set(Spacing::OneHalf);
140 newline_allowed = true;
141 free_spacing = false;
143 parbreak_is_newline = false;
144 toclevel = NOT_IN_TOC;
146 htmllabelfirst_ = false;
147 htmlforcecss_ = false;
151 itemcommand_ = "item";
152 toggle_indent = ITOGGLE_DOCUMENT_DEFAULT;
156 bool Layout::read(Lexer & lex, TextClass const & tclass)
158 // If this is an empty layout, or if no force local version is set,
159 // we know that we will not discard the stuff to read
161 return readIgnoreForcelocal(lex, tclass);
164 bool const ret = tmp.readIgnoreForcelocal(lex, tclass);
166 // - the read version is higher
167 // - both versions are infinity (arbitrary decision)
168 // - the file did not contain any local version (needed for not
169 // skipping user defined local layouts)
170 if (tmp.forcelocal <= 0 || tmp.forcelocal > forcelocal)
176 bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass)
178 // This table is sorted alphabetically [asierra 30March96]
179 LexerKeyword layoutTags[] = {
180 { "align", LT_ALIGN },
181 { "alignpossible", LT_ALIGNPOSSIBLE },
182 { "argument", LT_ARGUMENT },
183 { "babelpreamble", LT_BABELPREAMBLE },
184 { "bottomsep", LT_BOTTOMSEP },
185 { "category", LT_CATEGORY },
186 { "commanddepth", LT_COMMANDDEPTH },
187 { "copystyle", LT_COPYSTYLE },
188 { "dependson", LT_DEPENDSON },
190 { "endlabelstring", LT_ENDLABELSTRING },
191 { "endlabeltype", LT_ENDLABELTYPE },
193 { "forcelocal", LT_FORCELOCAL },
194 { "freespacing", LT_FREE_SPACING },
195 { "htmlattr", LT_HTMLATTR },
196 { "htmlforcecss", LT_HTMLFORCECSS },
197 { "htmlitem", LT_HTMLITEM },
198 { "htmlitemattr", LT_HTMLITEMATTR },
199 { "htmllabel", LT_HTMLLABEL },
200 { "htmllabelattr", LT_HTMLLABELATTR },
201 { "htmllabelfirst", LT_HTMLLABELFIRST },
202 { "htmlpreamble", LT_HTMLPREAMBLE },
203 { "htmlstyle", LT_HTMLSTYLE },
204 { "htmltag", LT_HTMLTAG },
205 { "htmltitle", LT_HTMLTITLE },
206 { "innertag", LT_INNERTAG },
207 { "inpreamble", LT_INPREAMBLE },
208 { "intitle", LT_INTITLE },
209 { "itemcommand", LT_ITEMCOMMAND },
210 { "itemsep", LT_ITEMSEP },
211 { "itemtag", LT_ITEMTAG },
212 { "keepempty", LT_KEEPEMPTY },
213 { "labelbottomsep", LT_LABEL_BOTTOMSEP },
214 { "labelcounter", LT_LABELCOUNTER },
215 { "labelfont", LT_LABELFONT },
216 { "labelindent", LT_LABELINDENT },
217 { "labelsep", LT_LABELSEP },
218 { "labelstring", LT_LABELSTRING },
219 { "labelstringappendix", LT_LABELSTRING_APPENDIX },
220 { "labeltag", LT_LABELTAG },
221 { "labeltype", LT_LABELTYPE },
222 { "langpreamble", LT_LANGPREAMBLE },
223 { "latexname", LT_LATEXNAME },
224 { "latexparam", LT_LATEXPARAM },
225 { "latextype", LT_LATEXTYPE },
226 { "leftdelim", LT_LEFTDELIM },
227 { "leftmargin", LT_LEFTMARGIN },
228 { "margin", LT_MARGIN },
229 { "needprotect", LT_NEED_PROTECT },
230 { "newline", LT_NEWLINE },
231 { "nextnoindent", LT_NEXTNOINDENT },
232 { "obsoletedby", LT_OBSOLETEDBY },
233 { "parbreakisnewline", LT_PARBREAK_IS_NEWLINE },
234 { "parindent", LT_PARINDENT },
235 { "parsep", LT_PARSEP },
236 { "parskip", LT_PARSKIP },
237 { "passthru", LT_PASS_THRU },
238 { "preamble", LT_PREAMBLE },
239 { "refprefix", LT_REFPREFIX },
240 { "requires", LT_REQUIRES },
241 { "resetargs", LT_RESETARGS },
242 { "rightdelim", LT_RIGHTDELIM },
243 { "rightmargin", LT_RIGHTMARGIN },
244 { "spacing", LT_SPACING },
245 { "spellcheck", LT_SPELLCHECK },
246 { "textfont", LT_TEXTFONT },
247 { "toclevel", LT_TOCLEVEL },
248 { "toggleindent", LT_TOGGLE_INDENT },
249 { "topsep", LT_TOPSEP }
253 bool finished = false;
254 lex.pushTable(layoutTags);
256 // parse style section
257 while (!finished && lex.isOK() && !error) {
259 // See comment in LyXRC.cpp.
261 case Lexer::LEX_FEOF:
264 case Lexer::LEX_UNDEF:
266 lex.printError("Unknown layout tag `$$Token'");
273 switch (static_cast<LayoutTags>(le)) {
285 style = subst(style, '_', ' ');
287 if (tclass.hasLayout(style)) {
288 docstring const tmpname = name_;
289 this->operator=(tclass[style]);
292 LYXERR0("Cannot copy unknown style `"
294 << "All layouts so far:");
295 DocumentClass::const_iterator lit = tclass.begin();
296 DocumentClass::const_iterator len = tclass.end();
297 for (; lit != len; ++lit)
298 LYXERR0(lit->name());
303 case LT_OBSOLETEDBY: {
306 style = subst(style, '_', ' ');
308 if (tclass.hasLayout(style)) {
309 docstring const tmpname = name_;
310 this->operator=(tclass[style]);
312 if (obsoleted_by().empty())
313 obsoleted_by_ = style;
315 LYXERR0("Cannot replace with unknown style `"
318 //lex.printError("Cannot replace with"
327 depends_on_ = subst(depends_on_, '_', ' ');
356 postcommandargs_.clear();
364 case LT_NEED_PROTECT:
373 font = lyxRead(lex, font);
378 font = lyxRead(lex, font);
382 labelfont = lyxRead(lex, labelfont);
385 case LT_NEXTNOINDENT:
389 case LT_TOGGLE_INDENT: {
392 tog = support::ascii_lowercase(tog);
394 toggle_indent = ITOGGLE_ALWAYS;
395 else if (tog == "never")
396 toggle_indent = ITOGGLE_NEVER;
398 toggle_indent = ITOGGLE_DOCUMENT_DEFAULT;
402 case LT_COMMANDDEPTH:
412 latexparam_ = subst(latexparam_, """, "\"");
417 leftdelim_ = support::subst(leftdelim_, from_ascii("<br/>"),
423 rightdelim_ = support::subst(rightdelim_, from_ascii("<br/>"),
444 preamble_ = from_utf8(lex.getLongString("EndPreamble"));
447 case LT_LANGPREAMBLE:
448 langpreamble_ = from_utf8(lex.getLongString("EndLangPreamble"));
451 case LT_BABELPREAMBLE:
452 babelpreamble_ = from_utf8(lex.getLongString("EndBabelPreamble"));
459 case LT_ENDLABELTYPE:
460 readEndLabelType(lex);
495 case LT_LABEL_BOTTOMSEP:
496 lex >> labelbottomsep;
501 labelsep = subst(labelsep, 'x', ' ');
509 lex >> newline_allowed;
516 case LT_ALIGNPOSSIBLE:
517 readAlignPossible(lex);
521 // FIXME: this means LT_LABELSTRING_APPENDIX may only
522 // occur after LT_LABELSTRING
524 labelstring_ = trim(labelstring_);
525 labelstring_appendix_ = labelstring_;
528 case LT_ENDLABELSTRING:
529 lex >> endlabelstring_;
530 endlabelstring_ = trim(endlabelstring_);
533 case LT_LABELSTRING_APPENDIX:
534 lex >> labelstring_appendix_;
535 labelstring_appendix_ = trim(labelstring_appendix_);
538 case LT_LABELCOUNTER:
540 counter = trim(counter);
543 case LT_FREE_SPACING:
551 case LT_PARBREAK_IS_NEWLINE:
552 lex >> parbreak_is_newline;
561 vector<string> const req =
562 getVectorFromString(lex.getString());
563 requires_.insert(req.begin(), req.end());
589 case LT_HTMLITEMATTR:
590 lex >> htmlitemattr_;
594 lex >> htmllabeltag_;
597 case LT_HTMLLABELATTR:
598 lex >> htmllabelattr_;
601 case LT_HTMLLABELFIRST:
602 lex >> htmllabelfirst_;
606 htmlstyle_ = from_utf8(lex.getLongString("EndHTMLStyle"));
609 case LT_HTMLFORCECSS:
610 lex >> htmlforcecss_;
613 case LT_HTMLPREAMBLE:
614 htmlpreamble_ = from_utf8(lex.getLongString("EndPreamble"));
631 // make sure we only have inpreamble = true for commands
632 if (inpreamble && latextype != LATEX_COMMAND && latextype != LATEX_PARAGRAPH) {
633 LYXERR0("InPreamble not permitted except with command and paragraph layouts.");
634 LYXERR0("Layout name: " << name());
638 return finished && !error;
651 LexerKeyword alignTags[] = {
652 { "block", AT_BLOCK },
653 { "center", AT_CENTER },
654 { "layout", AT_LAYOUT },
656 { "right", AT_RIGHT }
660 void Layout::readAlign(Lexer & lex)
662 PushPopHelper pph(lex, alignTags);
665 case Lexer::LEX_UNDEF:
666 lex.printError("Unknown alignment `$$Token'");
672 align = LYX_ALIGN_BLOCK;
675 align = LYX_ALIGN_LEFT;
678 align = LYX_ALIGN_RIGHT;
681 align = LYX_ALIGN_CENTER;
684 align = LYX_ALIGN_LAYOUT;
690 void Layout::readAlignPossible(Lexer & lex)
692 lex.pushTable(alignTags);
693 alignpossible = LYX_ALIGN_NONE | LYX_ALIGN_LAYOUT;
694 int lineno = lex.lineNumber();
698 case Lexer::LEX_UNDEF:
699 lex.printError("Unknown alignment `$$Token'");
705 alignpossible |= LYX_ALIGN_BLOCK;
708 alignpossible |= LYX_ALIGN_LEFT;
711 alignpossible |= LYX_ALIGN_RIGHT;
714 alignpossible |= LYX_ALIGN_CENTER;
717 alignpossible |= LYX_ALIGN_LAYOUT;
720 } while (lineno == lex.lineNumber());
725 void Layout::readLabelType(Lexer & lex)
740 LexerKeyword labelTypeTags[] = {
741 { "above", LA_ABOVE },
742 { "bibliography", LA_BIBLIO },
743 { "centered", LA_CENTERED },
744 { "enumerate", LA_ENUMERATE },
745 { "itemize", LA_ITEMIZE },
746 { "manual", LA_MANUAL },
747 { "no_label", LA_NO_LABEL },
748 { "sensitive", LA_SENSITIVE },
749 { "static", LA_STATIC }
752 PushPopHelper pph(lex, labelTypeTags);
755 case Lexer::LEX_UNDEF:
756 lex.printError("Unknown labeltype tag `$$Token'");
762 labeltype = LABEL_NO_LABEL;
765 labeltype = LABEL_MANUAL;
768 labeltype = LABEL_ABOVE;
771 labeltype = LABEL_CENTERED;
774 labeltype = LABEL_STATIC;
777 labeltype = LABEL_SENSITIVE;
780 labeltype = LABEL_ENUMERATE;
783 labeltype = LABEL_ITEMIZE;
786 labeltype = LABEL_BIBLIO;
792 void Layout::readEndLabelType(Lexer & lex)
794 // this should be const, but can't be because
796 static LexerKeyword endlabelTypeTags[] = {
797 { "box", END_LABEL_BOX },
798 { "filled_box", END_LABEL_FILLED_BOX },
799 { "no_label", END_LABEL_NO_LABEL },
800 { "static", END_LABEL_STATIC }
803 PushPopHelper pph(lex, endlabelTypeTags);
806 case Lexer::LEX_UNDEF:
807 lex.printError("Unknown labeltype tag `$$Token'");
809 case END_LABEL_STATIC:
811 case END_LABEL_FILLED_BOX:
812 case END_LABEL_NO_LABEL:
813 endlabeltype = static_cast<EndLabelType>(le);
816 LYXERR0("Unhandled value " << le);
822 void Layout::readMargin(Lexer & lex)
824 LexerKeyword marginTags[] = {
825 { "dynamic", MARGIN_DYNAMIC },
826 { "first_dynamic", MARGIN_FIRST_DYNAMIC },
827 { "manual", MARGIN_MANUAL },
828 { "right_address_box", MARGIN_RIGHT_ADDRESS_BOX },
829 { "static", MARGIN_STATIC }
832 PushPopHelper pph(lex, marginTags);
836 case Lexer::LEX_UNDEF:
837 lex.printError("Unknown margin type tag `$$Token'");
842 case MARGIN_FIRST_DYNAMIC:
843 case MARGIN_RIGHT_ADDRESS_BOX:
844 margintype = static_cast<MarginType>(le);
847 LYXERR0("Unhandled value " << le);
853 void Layout::readLatexType(Lexer & lex)
855 LexerKeyword latexTypeTags[] = {
856 { "bib_environment", LATEX_BIB_ENVIRONMENT },
857 { "command", LATEX_COMMAND },
858 { "environment", LATEX_ENVIRONMENT },
859 { "item_environment", LATEX_ITEM_ENVIRONMENT },
860 { "list_environment", LATEX_LIST_ENVIRONMENT },
861 { "paragraph", LATEX_PARAGRAPH }
864 PushPopHelper pph(lex, latexTypeTags);
867 case Lexer::LEX_UNDEF:
868 lex.printError("Unknown latextype tag `$$Token'");
870 case LATEX_PARAGRAPH:
872 case LATEX_ENVIRONMENT:
873 case LATEX_ITEM_ENVIRONMENT:
874 case LATEX_BIB_ENVIRONMENT:
875 case LATEX_LIST_ENVIRONMENT:
876 latextype = static_cast<LatexType>(le);
879 LYXERR0("Unhandled value " << le);
885 void Layout::readSpacing(Lexer & lex)
888 ST_SPACING_SINGLE = 1,
894 LexerKeyword spacingTags[] = {
895 {"double", ST_SPACING_DOUBLE },
896 {"onehalf", ST_SPACING_ONEHALF },
897 {"other", ST_OTHER },
898 {"single", ST_SPACING_SINGLE }
901 PushPopHelper pph(lex, spacingTags);
904 case Lexer::LEX_UNDEF:
905 lex.printError("Unknown spacing token `$$Token'");
910 case ST_SPACING_SINGLE:
911 spacing.set(Spacing::Single);
913 case ST_SPACING_ONEHALF:
914 spacing.set(Spacing::Onehalf);
916 case ST_SPACING_DOUBLE:
917 spacing.set(Spacing::Double);
921 spacing.set(Spacing::Other, lex.getString());
927 void Layout::readArgument(Lexer & lex)
930 // writeArgument() makes use of these default values
931 arg.mandatory = false;
932 arg.autoinsert = false;
934 bool finished = false;
935 arg.font = inherit_font;
936 arg.labelfont = inherit_font;
939 bool const itemarg = prefixIs(id, "item:");
940 bool const postcmd = prefixIs(id, "post:");
942 while (!finished && lex.isOK() && !error) {
944 string const tok = ascii_lowercase(lex.getString());
948 } else if (tok == "endargument") {
950 } else if (tok == "labelstring") {
952 arg.labelstring = lex.getDocString();
953 } else if (tok == "menustring") {
955 arg.menustring = lex.getDocString();
956 } else if (tok == "mandatory") {
958 arg.mandatory = lex.getBool();
959 } else if (tok == "autoinsert") {
961 arg.autoinsert = lex.getBool();
962 } else if (tok == "leftdelim") {
964 arg.ldelim = lex.getDocString();
965 arg.ldelim = support::subst(arg.ldelim, from_ascii("<br/>"),
967 } else if (tok == "rightdelim") {
969 arg.rdelim = lex.getDocString();
970 arg.rdelim = support::subst(arg.rdelim, from_ascii("<br/>"),
972 } else if (tok == "defaultarg") {
974 arg.defaultarg = lex.getDocString();
975 } else if (tok == "presetarg") {
977 arg.presetarg = lex.getDocString();
978 } else if (tok == "tooltip") {
980 arg.tooltip = lex.getDocString();
981 } else if (tok == "requires") {
983 arg.requires = lex.getString();
984 } else if (tok == "decoration") {
986 arg.decoration = lex.getString();
987 } else if (tok == "font") {
988 arg.font = lyxRead(lex, arg.font);
989 } else if (tok == "labelfont") {
990 arg.labelfont = lyxRead(lex, arg.labelfont);
992 lex.printError("Unknown tag");
996 if (arg.labelstring.empty())
997 LYXERR0("Incomplete Argument definition!");
1001 postcommandargs_[id] = arg;
1003 latexargs_[id] = arg;
1007 void writeArgument(ostream & os, string const & id, Layout::latexarg const & arg)
1009 os << "\tArgument " << id << '\n';
1010 if (!arg.labelstring.empty())
1011 os << "\t\tLabelString \"" << to_utf8(arg.labelstring) << "\"\n";
1012 if (!arg.menustring.empty())
1013 os << "\t\tMenuString \"" << to_utf8(arg.menustring) << "\"\n";
1015 os << "\t\tMandatory " << arg.mandatory << '\n';
1017 os << "\t\tAutoinsert " << arg.autoinsert << '\n';
1018 if (!arg.ldelim.empty())
1019 os << "\t\tLeftDelim \""
1020 << to_utf8(subst(arg.ldelim, from_ascii("\n"), from_ascii("<br/>")))
1022 if (!arg.rdelim.empty())
1023 os << "\t\tRightDelim \""
1024 << to_utf8(subst(arg.rdelim, from_ascii("\n"), from_ascii("<br/>")))
1026 if (!arg.defaultarg.empty())
1027 os << "\t\tDefaultArg \"" << to_utf8(arg.defaultarg) << "\"\n";
1028 if (!arg.presetarg.empty())
1029 os << "\t\tPresetArg \"" << to_utf8(arg.presetarg) << "\"\n";
1030 if (!arg.tooltip.empty())
1031 os << "\t\tToolTip \"" << to_utf8(arg.tooltip) << "\"\n";
1032 if (!arg.requires.empty())
1033 os << "\t\tRequires \"" << arg.requires << "\"\n";
1034 if (!arg.decoration.empty())
1035 os << "\t\tDecoration \"" << arg.decoration << "\"\n";
1036 if (arg.font != inherit_font)
1037 lyxWrite(os, arg.font, "Font", 2);
1038 if (arg.labelfont != inherit_font)
1039 lyxWrite(os, arg.labelfont, "LabelFont", 2);
1040 os << "\tEndArgument\n";
1044 void Layout::write(ostream & os) const
1046 os << "Style " << to_utf8(name_) << '\n';
1047 if (!category_.empty() && obsoleted_by_.empty())
1048 os << "\tCategory \"" << to_utf8(category_) << "\"\n";
1049 // Can't deduce Copystyle here :-(
1050 if (!obsoleted_by_.empty()) {
1051 os << "\tObsoletedBy \"" << to_utf8(obsoleted_by_)
1055 if (!depends_on_.empty())
1056 os << "\tDependsOn " << to_utf8(depends_on_) << '\n';
1057 switch (margintype) {
1058 case MARGIN_DYNAMIC:
1059 os << "\tMargin Dynamic\n";
1061 case MARGIN_FIRST_DYNAMIC:
1062 os << "\tMargin First_Dynamic\n";
1065 os << "\tMargin Manual\n";
1067 case MARGIN_RIGHT_ADDRESS_BOX:
1068 os << "\tMargin Right_Address_Box\n";
1071 os << "\tMargin Static\n";
1074 switch (latextype) {
1075 case LATEX_BIB_ENVIRONMENT:
1076 os << "\tLatexType Bib_Environment\n";
1079 os << "\tLatexType Command\n";
1081 case LATEX_ENVIRONMENT:
1082 os << "\tLatexType Environment\n";
1084 case LATEX_ITEM_ENVIRONMENT:
1085 os << "\tLatexType Item_Environment\n";
1087 case LATEX_LIST_ENVIRONMENT:
1088 os << "\tLatexType List_Environment\n";
1090 case LATEX_PARAGRAPH:
1091 os << "\tLatexType Paragraph\n";
1094 os << "\tInTitle " << intitle << "\n"
1095 "\tInPreamble " << inpreamble << "\n"
1096 "\tTocLevel " << toclevel << '\n';
1097 // ResetArgs does not make sense here
1098 for (LaTeXArgMap::const_iterator it = latexargs_.begin();
1099 it != latexargs_.end(); ++it)
1100 writeArgument(os, it->first, it->second);
1101 for (LaTeXArgMap::const_iterator it = itemargs_.begin();
1102 it != itemargs_.end(); ++it)
1103 writeArgument(os, it->first, it->second);
1104 for (LaTeXArgMap::const_iterator it = postcommandargs_.begin();
1105 it != postcommandargs_.end(); ++it)
1106 writeArgument(os, it->first, it->second);
1107 os << "\tNeedProtect " << needprotect << "\n"
1108 "\tKeepEmpty " << keepempty << '\n';
1109 if (labelfont == font)
1110 lyxWrite(os, font, "Font", 1);
1112 lyxWrite(os, font, "TextFont", 1);
1113 lyxWrite(os, labelfont, "LabelFont", 1);
1115 os << "\tNextNoIndent " << nextnoindent << "\n"
1116 "\tCommandDepth " << commanddepth << '\n';
1117 if (!latexname_.empty())
1118 os << "\tLatexName \"" << latexname_ << "\"\n";
1119 if (!latexparam_.empty())
1120 os << "\tLatexParam \"" << subst(latexparam_, "\"", """)
1122 if (!leftdelim_.empty())
1123 os << "\tLeftDelim "
1124 << to_utf8(subst(leftdelim_, from_ascii("\n"), from_ascii("<br/>")))
1126 if (!rightdelim_.empty())
1127 os << "\tRightDelim "
1128 << to_utf8(subst(rightdelim_, from_ascii("\n"), from_ascii("<br/>")))
1130 if (!innertag_.empty())
1131 os << "\tInnerTag \"" << innertag_ << "\"\n";
1132 if (!labeltag_.empty())
1133 os << "\tLabelTag \"" << labeltag_ << "\"\n";
1134 if (!itemtag_.empty())
1135 os << "\tItemTag \"" << itemtag_ << "\"\n";
1136 if (!itemcommand_.empty())
1137 os << "\tItemCommand " << itemcommand_ << '\n';
1138 if (!preamble_.empty())
1139 os << "\tPreamble\n\t"
1140 << to_utf8(subst(rtrim(preamble_, "\n"),
1141 from_ascii("\n"), from_ascii("\n\t")))
1142 << "\n\tEndPreamble\n";
1143 if (!langpreamble_.empty())
1144 os << "\tLangPreamble\n\t"
1145 << to_utf8(subst(rtrim(langpreamble_, "\n"),
1146 from_ascii("\n"), from_ascii("\n\t")))
1147 << "\n\tEndLangPreamble\n";
1148 if (!babelpreamble_.empty())
1149 os << "\tBabelPreamble\n\t"
1150 << to_utf8(subst(rtrim(babelpreamble_, "\n"),
1151 from_ascii("\n"), from_ascii("\n\t")))
1152 << "\n\tEndBabelPreamble\n";
1153 switch (labeltype) {
1155 os << "\tLabelType Above\n";
1158 os << "\tLabelType Bibliography\n";
1160 case LABEL_CENTERED:
1161 os << "\tLabelType Centered\n";
1163 case LABEL_ENUMERATE:
1164 os << "\tLabelType Enumerate\n";
1167 os << "\tLabelType Itemize\n";
1170 os << "\tLabelType Manual\n";
1172 case LABEL_NO_LABEL:
1173 os << "\tLabelType No_Label\n";
1175 case LABEL_SENSITIVE:
1176 os << "\tLabelType Sensitive\n";
1179 os << "\tLabelType Static\n";
1182 switch (endlabeltype) {
1184 os << "\tEndLabelType Box\n";
1186 case END_LABEL_FILLED_BOX:
1187 os << "\tEndLabelType Filled_Box\n";
1189 case END_LABEL_NO_LABEL:
1190 os << "\tEndLabelType No_Label\n";
1192 case END_LABEL_STATIC:
1193 os << "\tEndLabelType Static\n";
1196 if (!leftmargin.empty())
1197 os << "\tLeftMargin \"" << to_utf8(leftmargin) << "\"\n";
1198 if (!rightmargin.empty())
1199 os << "\tRightMargin \"" << to_utf8(rightmargin) << "\"\n";
1200 if (!labelindent.empty())
1201 os << "\tLabelIndent " << to_utf8(labelindent) << '\n';
1202 if (!parindent.empty())
1203 os << "\tParIndent " << to_utf8(parindent) << '\n';
1204 os << "\tParSkip " << parskip << "\n"
1205 "\tItemSep " << itemsep << "\n"
1206 "\tTopSep " << topsep << "\n"
1207 "\tBottomSep " << bottomsep << "\n"
1208 "\tLabelBottomSep " << labelbottomsep << '\n';
1209 if (!labelsep.empty())
1210 os << "\tLabelSep " << to_utf8(subst(labelsep, ' ', 'x'))
1212 os << "\tParSep " << parsep << "\n"
1213 "\tNewLine " << newline_allowed << '\n';
1215 case LYX_ALIGN_BLOCK:
1216 os << "\tAlign Block\n";
1218 case LYX_ALIGN_CENTER:
1219 os << "\tAlign Center\n";
1221 case LYX_ALIGN_LAYOUT:
1222 os << "\tAlign Layout\n";
1224 case LYX_ALIGN_LEFT:
1225 os << "\tAlign Left\n";
1227 case LYX_ALIGN_RIGHT:
1228 os << "\tAlign Right\n";
1230 case LYX_ALIGN_DECIMAL:
1231 case LYX_ALIGN_SPECIAL:
1232 case LYX_ALIGN_NONE:
1235 if (alignpossible & (LYX_ALIGN_BLOCK | LYX_ALIGN_CENTER |
1236 LYX_ALIGN_LAYOUT | LYX_ALIGN_LEFT | LYX_ALIGN_RIGHT)) {
1238 os << "\tAlignPossible";
1239 if (alignpossible & LYX_ALIGN_BLOCK) {
1245 if (alignpossible & LYX_ALIGN_CENTER) {
1251 if (alignpossible & LYX_ALIGN_LAYOUT) {
1257 if (alignpossible & LYX_ALIGN_LEFT) {
1263 if (alignpossible & LYX_ALIGN_RIGHT) {
1271 // LabelString must come before LabelStringAppendix
1272 if (!labelstring_.empty())
1273 os << "\tLabelString \"" << to_utf8(labelstring_) << "\"\n";
1274 if (!endlabelstring_.empty())
1275 os << "\tEndLabelString \"" << to_utf8(endlabelstring_) << "\"\n";
1276 if (!labelstring_appendix_.empty() && labelstring_appendix_ != labelstring_)
1277 os << "\tLabelStringAppendix \""
1278 << to_utf8(labelstring_appendix_) << "\"\n";
1279 if (!counter.empty())
1280 os << "\tLabelCounter \"" << to_utf8(counter) << "\"\n";
1281 os << "\tFreeSpacing " << free_spacing << '\n';
1282 os << "\tPassThru " << pass_thru << '\n';
1283 os << "\tParbreakIsNewline " << parbreak_is_newline << '\n';
1284 switch (spacing.getSpace()) {
1285 case Spacing::Double:
1286 os << "\tSpacing Double\n";
1288 case Spacing::Onehalf:
1289 os << "\tSpacing Onehalf\n";
1291 case Spacing::Other:
1292 os << "\tSpacing Other " << spacing.getValueAsString() << '\n';
1294 case Spacing::Single:
1295 os << "\tSpacing Single\n";
1297 case Spacing::Default:
1300 if (!requires_.empty()) {
1301 os << "\tRequires ";
1302 for (set<string>::const_iterator it = requires_.begin();
1303 it != requires_.end(); ++it) {
1304 if (it != requires_.begin())
1310 if (refprefix.empty())
1311 os << "\tRefPrefix OFF\n";
1313 os << "\tRefPrefix " << to_utf8(refprefix) << '\n';
1314 if (!htmltag_.empty())
1315 os << "\tHTMLTag " << htmltag_ << '\n';
1316 if (!htmlattr_.empty())
1317 os << "\tHTMLAttr " << htmlattr_ << '\n';
1318 if (!htmlitemtag_.empty())
1319 os << "\tHTMLItem " << htmlitemtag_ << '\n';
1320 if (!htmlitemattr_.empty())
1321 os << "\tHTMLItemAttr " << htmlitemattr_ << '\n';
1322 if (!htmllabeltag_.empty())
1323 os << "\tHTMLLabel " << htmllabeltag_ << '\n';
1324 if (!htmllabelattr_.empty())
1325 os << "\tHTMLLabelAttr " << htmllabelattr_ << '\n';
1326 os << "\tHTMLLabelFirst " << htmllabelfirst_ << '\n';
1327 if (!htmlstyle_.empty())
1328 os << "\tHTMLStyle\n"
1329 << to_utf8(rtrim(htmlstyle_, "\n"))
1330 << "\n\tEndHTMLStyle\n";
1331 os << "\tHTMLForceCSS " << htmlforcecss_ << '\n';
1332 if (!htmlpreamble_.empty())
1333 os << "\tHTMLPreamble\n"
1334 << to_utf8(rtrim(htmlpreamble_, "\n"))
1335 << "\n\tEndPreamble\n";
1336 os << "\tHTMLTitle " << htmltitle_ << "\n"
1337 "\tSpellcheck " << spellcheck << "\n"
1338 "\tForceLocal " << forcelocal << "\n"
1343 Layout::LaTeXArgMap Layout::args() const
1345 LaTeXArgMap args = latexargs_;
1346 if (!postcommandargs_.empty())
1347 args.insert(postcommandargs_.begin(), postcommandargs_.end());
1348 if (!itemargs_.empty())
1349 args.insert(itemargs_.begin(), itemargs_.end());
1354 int Layout::optArgs() const
1357 LaTeXArgMap::const_iterator it = latexargs_.begin();
1358 for (; it != latexargs_.end(); ++it) {
1359 if (!(*it).second.mandatory)
1362 LaTeXArgMap::const_iterator iit = postcommandargs_.begin();
1363 for (; iit != postcommandargs_.end(); ++iit) {
1364 if (!(*iit).second.mandatory)
1371 int Layout::requiredArgs() const
1374 LaTeXArgMap::const_iterator it = latexargs_.begin();
1375 for (; it != latexargs_.end(); ++it) {
1376 if ((*it).second.mandatory)
1379 LaTeXArgMap::const_iterator iit = postcommandargs_.begin();
1380 for (; iit != postcommandargs_.end(); ++iit) {
1381 if (!(*iit).second.mandatory)
1388 string const & Layout::htmltag() const
1390 if (htmltag_.empty())
1396 string const & Layout::htmlattr() const
1398 if (htmlattr_.empty())
1399 htmlattr_ = "class=\"" + defaultCSSClass() + "\"";
1404 string const & Layout::htmlitemtag() const
1406 if (htmlitemtag_.empty())
1407 htmlitemtag_ = "div";
1408 return htmlitemtag_;
1412 string const & Layout::htmlitemattr() const
1414 if (htmlitemattr_.empty())
1415 htmlitemattr_ = "class=\"" + defaultCSSItemClass() + "\"";
1416 return htmlitemattr_;
1420 string const & Layout::htmllabeltag() const
1422 if (htmllabeltag_.empty()) {
1423 if (labeltype != LABEL_ABOVE &&
1424 labeltype != LABEL_CENTERED)
1425 htmllabeltag_ = "span";
1427 htmllabeltag_ = "div";
1429 return htmllabeltag_;
1433 string const & Layout::htmllabelattr() const
1435 if (htmllabelattr_.empty())
1436 htmllabelattr_ = "class=\"" + defaultCSSLabelClass() + "\"";
1437 return htmllabelattr_;
1441 docstring Layout::htmlstyle() const
1443 if (!htmlstyle_.empty() && !htmlforcecss_)
1445 if (htmldefaultstyle_.empty())
1447 docstring retval = htmldefaultstyle_;
1448 if (!htmlstyle_.empty())
1449 retval += '\n' + htmlstyle_;
1454 string Layout::defaultCSSClass() const
1456 if (!defaultcssclass_.empty())
1457 return defaultcssclass_;
1459 docstring::const_iterator it = name().begin();
1460 docstring::const_iterator en = name().end();
1461 for (; it != en; ++it) {
1462 char_type const c = *it;
1463 if (!isAlphaASCII(c)) {
1465 // make sure we don't start with an underscore,
1466 // as that sometimes causes problems.
1467 d = from_ascii("lyx_");
1470 } else if (isLower(c))
1473 // this is slow, so do it only if necessary
1476 defaultcssclass_ = to_utf8(d);
1477 return defaultcssclass_;
1483 string makeMarginValue(char const * side, double d)
1486 os << "margin-" << side << ": " << d << "ex;\n";
1493 void Layout::makeDefaultCSS() const
1495 // this never needs to be redone, since reloading layouts will
1496 // wipe out what we did before.
1497 if (!htmldefaultstyle_.empty())
1501 htmldefaultstyle_ = font.asCSS();
1506 tmp += makeMarginValue("top", topsep);
1508 tmp += makeMarginValue("bottom", bottomsep);
1509 if (!leftmargin.empty()) {
1510 // we can't really do what LyX does with the margin, so
1511 // we'll just figure out how many characters it is
1512 int const len = leftmargin.length();
1513 tmp += makeMarginValue("left", len);
1515 if (!rightmargin.empty()) {
1516 int const len = rightmargin.length();
1517 tmp += makeMarginValue("right", len);
1521 if (!htmldefaultstyle_.empty())
1522 htmldefaultstyle_ += from_ascii("\n");
1523 htmldefaultstyle_ += from_ascii(tmp);
1527 string where = alignmentToCSS(align);
1528 if (!where.empty()) {
1529 htmldefaultstyle_ += from_ascii("text-align: " + where + ";\n");
1532 // wrap up what we have, if anything
1533 if (!htmldefaultstyle_.empty())
1535 from_ascii(htmltag() + "." + defaultCSSClass() + " {\n") +
1536 htmldefaultstyle_ + from_ascii("\n}\n");
1538 if (labeltype == LABEL_NO_LABEL || htmllabeltag() == "NONE")
1544 if (labelfont != font)
1545 labelCSS = labelfont.asCSS() + from_ascii("\n");
1546 if (labeltype == LABEL_CENTERED)
1547 labelCSS += from_ascii("text-align: center;\n");
1549 if (!labelCSS.empty())
1550 htmldefaultstyle_ +=
1551 from_ascii(htmllabeltag() + "." + defaultCSSLabelClass() + " {\n") +
1552 labelCSS + from_ascii("\n}\n");
1556 bool Layout::operator==(Layout const & rhs) const
1558 // This is enough for the applications we actually make,
1559 // at least at the moment. But we could check more.
1560 return name() == rhs.name()
1561 && latexname() == rhs.latexname()
1562 && latextype == rhs.latextype;