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,
108 LT_INTITLE // keep this last!
111 /////////////////////
116 margintype = MARGIN_STATIC;
117 latextype = LATEX_PARAGRAPH;
123 labelfont = inherit_font;
125 reslabelfont = sane_font;
126 nextnoindent = false;
131 labelbottomsep = 0.0;
133 align = LYX_ALIGN_BLOCK;
134 alignpossible = LYX_ALIGN_NONE | LYX_ALIGN_LAYOUT;
135 labeltype = LABEL_NO_LABEL;
136 endlabeltype = END_LABEL_NO_LABEL;
137 // Should or should not. That is the question.
138 // spacing.set(Spacing::OneHalf);
139 newline_allowed = true;
140 free_spacing = false;
142 parbreak_is_newline = false;
143 toclevel = NOT_IN_TOC;
145 htmllabelfirst_ = false;
146 htmlforcecss_ = false;
150 itemcommand_ = "item";
154 bool Layout::read(Lexer & lex, TextClass const & tclass)
156 // If this is an empty layout, or if no force local version is set,
157 // we know that we will not discard the stuff to read
159 return readIgnoreForcelocal(lex, tclass);
162 bool const ret = tmp.readIgnoreForcelocal(lex, tclass);
164 // - the read version is higher
165 // - both versions are infinity (arbitrary decision)
166 // - the file did not contain any local version (needed for not
167 // skipping user defined local layouts)
168 if (tmp.forcelocal <= 0 || tmp.forcelocal > forcelocal)
174 bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass)
176 // This table is sorted alphabetically [asierra 30March96]
177 LexerKeyword layoutTags[] = {
178 { "align", LT_ALIGN },
179 { "alignpossible", LT_ALIGNPOSSIBLE },
180 { "argument", LT_ARGUMENT },
181 { "babelpreamble", LT_BABELPREAMBLE },
182 { "bottomsep", LT_BOTTOMSEP },
183 { "category", LT_CATEGORY },
184 { "commanddepth", LT_COMMANDDEPTH },
185 { "copystyle", LT_COPYSTYLE },
186 { "dependson", LT_DEPENDSON },
188 { "endlabelstring", LT_ENDLABELSTRING },
189 { "endlabeltype", LT_ENDLABELTYPE },
191 { "forcelocal", LT_FORCELOCAL },
192 { "freespacing", LT_FREE_SPACING },
193 { "htmlattr", LT_HTMLATTR },
194 { "htmlforcecss", LT_HTMLFORCECSS },
195 { "htmlitem", LT_HTMLITEM },
196 { "htmlitemattr", LT_HTMLITEMATTR },
197 { "htmllabel", LT_HTMLLABEL },
198 { "htmllabelattr", LT_HTMLLABELATTR },
199 { "htmllabelfirst", LT_HTMLLABELFIRST },
200 { "htmlpreamble", LT_HTMLPREAMBLE },
201 { "htmlstyle", LT_HTMLSTYLE },
202 { "htmltag", LT_HTMLTAG },
203 { "htmltitle", LT_HTMLTITLE },
204 { "innertag", LT_INNERTAG },
205 { "inpreamble", LT_INPREAMBLE },
206 { "intitle", LT_INTITLE },
207 { "itemcommand", LT_ITEMCOMMAND },
208 { "itemsep", LT_ITEMSEP },
209 { "itemtag", LT_ITEMTAG },
210 { "keepempty", LT_KEEPEMPTY },
211 { "labelbottomsep", LT_LABEL_BOTTOMSEP },
212 { "labelcounter", LT_LABELCOUNTER },
213 { "labelfont", LT_LABELFONT },
214 { "labelindent", LT_LABELINDENT },
215 { "labelsep", LT_LABELSEP },
216 { "labelstring", LT_LABELSTRING },
217 { "labelstringappendix", LT_LABELSTRING_APPENDIX },
218 { "labeltag", LT_LABELTAG },
219 { "labeltype", LT_LABELTYPE },
220 { "langpreamble", LT_LANGPREAMBLE },
221 { "latexname", LT_LATEXNAME },
222 { "latexparam", LT_LATEXPARAM },
223 { "latextype", LT_LATEXTYPE },
224 { "leftdelim", LT_LEFTDELIM },
225 { "leftmargin", LT_LEFTMARGIN },
226 { "margin", LT_MARGIN },
227 { "needprotect", LT_NEED_PROTECT },
228 { "newline", LT_NEWLINE },
229 { "nextnoindent", LT_NEXTNOINDENT },
230 { "obsoletedby", LT_OBSOLETEDBY },
231 { "parbreakisnewline", LT_PARBREAK_IS_NEWLINE },
232 { "parindent", LT_PARINDENT },
233 { "parsep", LT_PARSEP },
234 { "parskip", LT_PARSKIP },
235 { "passthru", LT_PASS_THRU },
236 { "preamble", LT_PREAMBLE },
237 { "refprefix", LT_REFPREFIX },
238 { "requires", LT_REQUIRES },
239 { "resetargs", LT_RESETARGS },
240 { "rightdelim", LT_RIGHTDELIM },
241 { "rightmargin", LT_RIGHTMARGIN },
242 { "spacing", LT_SPACING },
243 { "spellcheck", LT_SPELLCHECK },
244 { "textfont", LT_TEXTFONT },
245 { "toclevel", LT_TOCLEVEL },
246 { "topsep", LT_TOPSEP }
250 bool finished = false;
251 lex.pushTable(layoutTags);
253 // parse style section
254 while (!finished && lex.isOK() && !error) {
256 // See comment in LyXRC.cpp.
258 case Lexer::LEX_FEOF:
261 case Lexer::LEX_UNDEF:
263 lex.printError("Unknown layout tag `$$Token'");
270 switch (static_cast<LayoutTags>(le)) {
282 style = subst(style, '_', ' ');
284 if (tclass.hasLayout(style)) {
285 docstring const tmpname = name_;
286 this->operator=(tclass[style]);
289 LYXERR0("Cannot copy unknown style `"
291 << "All layouts so far:");
292 DocumentClass::const_iterator lit = tclass.begin();
293 DocumentClass::const_iterator len = tclass.end();
294 for (; lit != len; ++lit)
295 LYXERR0(lit->name());
300 case LT_OBSOLETEDBY: {
303 style = subst(style, '_', ' ');
305 if (tclass.hasLayout(style)) {
306 docstring const tmpname = name_;
307 this->operator=(tclass[style]);
309 if (obsoleted_by().empty())
310 obsoleted_by_ = style;
312 LYXERR0("Cannot replace with unknown style `"
315 //lex.printError("Cannot replace with"
324 depends_on_ = subst(depends_on_, '_', ' ');
353 postcommandargs_.clear();
361 case LT_NEED_PROTECT:
370 font = lyxRead(lex, font);
375 font = lyxRead(lex, font);
379 labelfont = lyxRead(lex, labelfont);
382 case LT_NEXTNOINDENT:
386 case LT_COMMANDDEPTH:
396 latexparam_ = subst(latexparam_, """, "\"");
401 leftdelim_ = support::subst(leftdelim_, from_ascii("<br/>"),
407 rightdelim_ = support::subst(rightdelim_, from_ascii("<br/>"),
428 preamble_ = from_utf8(lex.getLongString("EndPreamble"));
431 case LT_LANGPREAMBLE:
432 langpreamble_ = from_utf8(lex.getLongString("EndLangPreamble"));
435 case LT_BABELPREAMBLE:
436 babelpreamble_ = from_utf8(lex.getLongString("EndBabelPreamble"));
443 case LT_ENDLABELTYPE:
444 readEndLabelType(lex);
479 case LT_LABEL_BOTTOMSEP:
480 lex >> labelbottomsep;
485 labelsep = subst(labelsep, 'x', ' ');
493 lex >> newline_allowed;
500 case LT_ALIGNPOSSIBLE:
501 readAlignPossible(lex);
505 // FIXME: this means LT_LABELSTRING_APPENDIX may only
506 // occur after LT_LABELSTRING
508 labelstring_ = trim(labelstring_);
509 labelstring_appendix_ = labelstring_;
512 case LT_ENDLABELSTRING:
513 lex >> endlabelstring_;
514 endlabelstring_ = trim(endlabelstring_);
517 case LT_LABELSTRING_APPENDIX:
518 lex >> labelstring_appendix_;
519 labelstring_appendix_ = trim(labelstring_appendix_);
522 case LT_LABELCOUNTER:
524 counter = trim(counter);
527 case LT_FREE_SPACING:
535 case LT_PARBREAK_IS_NEWLINE:
536 lex >> parbreak_is_newline;
545 vector<string> const req =
546 getVectorFromString(lex.getString());
547 requires_.insert(req.begin(), req.end());
573 case LT_HTMLITEMATTR:
574 lex >> htmlitemattr_;
578 lex >> htmllabeltag_;
581 case LT_HTMLLABELATTR:
582 lex >> htmllabelattr_;
585 case LT_HTMLLABELFIRST:
586 lex >> htmllabelfirst_;
590 htmlstyle_ = from_utf8(lex.getLongString("EndHTMLStyle"));
593 case LT_HTMLFORCECSS:
594 lex >> htmlforcecss_;
597 case LT_HTMLPREAMBLE:
598 htmlpreamble_ = from_utf8(lex.getLongString("EndPreamble"));
615 // make sure we only have inpreamble = true for commands
616 if (inpreamble && latextype != LATEX_COMMAND && latextype != LATEX_PARAGRAPH) {
617 LYXERR0("InPreamble not permitted except with command and paragraph layouts.");
618 LYXERR0("Layout name: " << name());
622 return finished && !error;
635 LexerKeyword alignTags[] = {
636 { "block", AT_BLOCK },
637 { "center", AT_CENTER },
638 { "layout", AT_LAYOUT },
640 { "right", AT_RIGHT }
644 void Layout::readAlign(Lexer & lex)
646 PushPopHelper pph(lex, alignTags);
649 case Lexer::LEX_UNDEF:
650 lex.printError("Unknown alignment `$$Token'");
656 align = LYX_ALIGN_BLOCK;
659 align = LYX_ALIGN_LEFT;
662 align = LYX_ALIGN_RIGHT;
665 align = LYX_ALIGN_CENTER;
668 align = LYX_ALIGN_LAYOUT;
674 void Layout::readAlignPossible(Lexer & lex)
676 lex.pushTable(alignTags);
677 alignpossible = LYX_ALIGN_NONE | LYX_ALIGN_LAYOUT;
678 int lineno = lex.lineNumber();
682 case Lexer::LEX_UNDEF:
683 lex.printError("Unknown alignment `$$Token'");
689 alignpossible |= LYX_ALIGN_BLOCK;
692 alignpossible |= LYX_ALIGN_LEFT;
695 alignpossible |= LYX_ALIGN_RIGHT;
698 alignpossible |= LYX_ALIGN_CENTER;
701 alignpossible |= LYX_ALIGN_LAYOUT;
704 } while (lineno == lex.lineNumber());
709 void Layout::readLabelType(Lexer & lex)
724 LexerKeyword labelTypeTags[] = {
725 { "above", LA_ABOVE },
726 { "bibliography", LA_BIBLIO },
727 { "centered", LA_CENTERED },
728 { "enumerate", LA_ENUMERATE },
729 { "itemize", LA_ITEMIZE },
730 { "manual", LA_MANUAL },
731 { "no_label", LA_NO_LABEL },
732 { "sensitive", LA_SENSITIVE },
733 { "static", LA_STATIC }
736 PushPopHelper pph(lex, labelTypeTags);
739 case Lexer::LEX_UNDEF:
740 lex.printError("Unknown labeltype tag `$$Token'");
746 labeltype = LABEL_NO_LABEL;
749 labeltype = LABEL_MANUAL;
752 labeltype = LABEL_ABOVE;
755 labeltype = LABEL_CENTERED;
758 labeltype = LABEL_STATIC;
761 labeltype = LABEL_SENSITIVE;
764 labeltype = LABEL_ENUMERATE;
767 labeltype = LABEL_ITEMIZE;
770 labeltype = LABEL_BIBLIO;
776 void Layout::readEndLabelType(Lexer & lex)
778 // this should be const, but can't be because
780 static LexerKeyword endlabelTypeTags[] = {
781 { "box", END_LABEL_BOX },
782 { "filled_box", END_LABEL_FILLED_BOX },
783 { "no_label", END_LABEL_NO_LABEL },
784 { "static", END_LABEL_STATIC }
787 PushPopHelper pph(lex, endlabelTypeTags);
790 case Lexer::LEX_UNDEF:
791 lex.printError("Unknown labeltype tag `$$Token'");
793 case END_LABEL_STATIC:
795 case END_LABEL_FILLED_BOX:
796 case END_LABEL_NO_LABEL:
797 endlabeltype = static_cast<EndLabelType>(le);
800 LYXERR0("Unhandled value " << le);
806 void Layout::readMargin(Lexer & lex)
808 LexerKeyword marginTags[] = {
809 { "dynamic", MARGIN_DYNAMIC },
810 { "first_dynamic", MARGIN_FIRST_DYNAMIC },
811 { "manual", MARGIN_MANUAL },
812 { "right_address_box", MARGIN_RIGHT_ADDRESS_BOX },
813 { "static", MARGIN_STATIC }
816 PushPopHelper pph(lex, marginTags);
820 case Lexer::LEX_UNDEF:
821 lex.printError("Unknown margin type tag `$$Token'");
826 case MARGIN_FIRST_DYNAMIC:
827 case MARGIN_RIGHT_ADDRESS_BOX:
828 margintype = static_cast<MarginType>(le);
831 LYXERR0("Unhandled value " << le);
837 void Layout::readLatexType(Lexer & lex)
839 LexerKeyword latexTypeTags[] = {
840 { "bib_environment", LATEX_BIB_ENVIRONMENT },
841 { "command", LATEX_COMMAND },
842 { "environment", LATEX_ENVIRONMENT },
843 { "item_environment", LATEX_ITEM_ENVIRONMENT },
844 { "list_environment", LATEX_LIST_ENVIRONMENT },
845 { "paragraph", LATEX_PARAGRAPH }
848 PushPopHelper pph(lex, latexTypeTags);
851 case Lexer::LEX_UNDEF:
852 lex.printError("Unknown latextype tag `$$Token'");
854 case LATEX_PARAGRAPH:
856 case LATEX_ENVIRONMENT:
857 case LATEX_ITEM_ENVIRONMENT:
858 case LATEX_BIB_ENVIRONMENT:
859 case LATEX_LIST_ENVIRONMENT:
860 latextype = static_cast<LatexType>(le);
863 LYXERR0("Unhandled value " << le);
869 void Layout::readSpacing(Lexer & lex)
872 ST_SPACING_SINGLE = 1,
878 LexerKeyword spacingTags[] = {
879 {"double", ST_SPACING_DOUBLE },
880 {"onehalf", ST_SPACING_ONEHALF },
881 {"other", ST_OTHER },
882 {"single", ST_SPACING_SINGLE }
885 PushPopHelper pph(lex, spacingTags);
888 case Lexer::LEX_UNDEF:
889 lex.printError("Unknown spacing token `$$Token'");
894 case ST_SPACING_SINGLE:
895 spacing.set(Spacing::Single);
897 case ST_SPACING_ONEHALF:
898 spacing.set(Spacing::Onehalf);
900 case ST_SPACING_DOUBLE:
901 spacing.set(Spacing::Double);
905 spacing.set(Spacing::Other, lex.getString());
911 void Layout::readArgument(Lexer & lex)
914 // writeArgument() makes use of these default values
915 arg.mandatory = false;
916 arg.autoinsert = false;
918 bool finished = false;
919 arg.font = inherit_font;
920 arg.labelfont = inherit_font;
923 bool const itemarg = prefixIs(id, "item:");
924 bool const postcmd = prefixIs(id, "post:");
926 while (!finished && lex.isOK() && !error) {
928 string const tok = ascii_lowercase(lex.getString());
932 } else if (tok == "endargument") {
934 } else if (tok == "labelstring") {
936 arg.labelstring = lex.getDocString();
937 } else if (tok == "menustring") {
939 arg.menustring = lex.getDocString();
940 } else if (tok == "mandatory") {
942 arg.mandatory = lex.getBool();
943 } else if (tok == "autoinsert") {
945 arg.autoinsert = lex.getBool();
946 } else if (tok == "leftdelim") {
948 arg.ldelim = lex.getDocString();
949 arg.ldelim = support::subst(arg.ldelim, from_ascii("<br/>"),
951 } else if (tok == "rightdelim") {
953 arg.rdelim = lex.getDocString();
954 arg.rdelim = support::subst(arg.rdelim, from_ascii("<br/>"),
956 } else if (tok == "defaultarg") {
958 arg.defaultarg = lex.getDocString();
959 } else if (tok == "presetarg") {
961 arg.presetarg = lex.getDocString();
962 } else if (tok == "tooltip") {
964 arg.tooltip = lex.getDocString();
965 } else if (tok == "requires") {
967 arg.requires = lex.getString();
968 } else if (tok == "decoration") {
970 arg.decoration = lex.getString();
971 } else if (tok == "font") {
972 arg.font = lyxRead(lex, arg.font);
973 } else if (tok == "labelfont") {
974 arg.labelfont = lyxRead(lex, arg.labelfont);
976 lex.printError("Unknown tag");
980 if (arg.labelstring.empty())
981 LYXERR0("Incomplete Argument definition!");
985 postcommandargs_[id] = arg;
987 latexargs_[id] = arg;
991 void writeArgument(ostream & os, string const & id, Layout::latexarg const & arg)
993 os << "\tArgument " << id << '\n';
994 if (!arg.labelstring.empty())
995 os << "\t\tLabelString \"" << to_utf8(arg.labelstring) << "\"\n";
996 if (!arg.menustring.empty())
997 os << "\t\tMenuString \"" << to_utf8(arg.menustring) << "\"\n";
999 os << "\t\tMandatory " << arg.mandatory << '\n';
1001 os << "\t\tAutoinsert " << arg.autoinsert << '\n';
1002 if (!arg.ldelim.empty())
1003 os << "\t\tLeftDelim \""
1004 << to_utf8(subst(arg.ldelim, from_ascii("\n"), from_ascii("<br/>")))
1006 if (!arg.rdelim.empty())
1007 os << "\t\tRightDelim \""
1008 << to_utf8(subst(arg.rdelim, from_ascii("\n"), from_ascii("<br/>")))
1010 if (!arg.defaultarg.empty())
1011 os << "\t\tDefaultArg \"" << to_utf8(arg.defaultarg) << "\"\n";
1012 if (!arg.presetarg.empty())
1013 os << "\t\tPresetArg \"" << to_utf8(arg.presetarg) << "\"\n";
1014 if (!arg.tooltip.empty())
1015 os << "\t\tToolTip \"" << to_utf8(arg.tooltip) << "\"\n";
1016 if (!arg.requires.empty())
1017 os << "\t\tRequires \"" << arg.requires << "\"\n";
1018 if (!arg.decoration.empty())
1019 os << "\t\tDecoration \"" << arg.decoration << "\"\n";
1020 if (arg.font != inherit_font)
1021 lyxWrite(os, arg.font, "Font", 2);
1022 if (arg.labelfont != inherit_font)
1023 lyxWrite(os, arg.labelfont, "LabelFont", 2);
1024 os << "\tEndArgument\n";
1028 void Layout::write(ostream & os) const
1030 os << "Style " << to_utf8(name_) << '\n';
1031 if (!category_.empty() && obsoleted_by_.empty())
1032 os << "\tCategory \"" << to_utf8(category_) << "\"\n";
1033 // Can't deduce Copystyle here :-(
1034 if (!obsoleted_by_.empty()) {
1035 os << "\tObsoletedBy \"" << to_utf8(obsoleted_by_)
1039 if (!depends_on_.empty())
1040 os << "\tDependsOn " << to_utf8(depends_on_) << '\n';
1041 switch (margintype) {
1042 case MARGIN_DYNAMIC:
1043 os << "\tMargin Dynamic\n";
1045 case MARGIN_FIRST_DYNAMIC:
1046 os << "\tMargin First_Dynamic\n";
1049 os << "\tMargin Manual\n";
1051 case MARGIN_RIGHT_ADDRESS_BOX:
1052 os << "\tMargin Right_Address_Box\n";
1055 os << "\tMargin Static\n";
1058 switch (latextype) {
1059 case LATEX_BIB_ENVIRONMENT:
1060 os << "\tLatexType Bib_Environment\n";
1063 os << "\tLatexType Command\n";
1065 case LATEX_ENVIRONMENT:
1066 os << "\tLatexType Environment\n";
1068 case LATEX_ITEM_ENVIRONMENT:
1069 os << "\tLatexType Item_Environment\n";
1071 case LATEX_LIST_ENVIRONMENT:
1072 os << "\tLatexType List_Environment\n";
1074 case LATEX_PARAGRAPH:
1075 os << "\tLatexType Paragraph\n";
1078 os << "\tInTitle " << intitle << "\n"
1079 "\tInPreamble " << inpreamble << "\n"
1080 "\tTocLevel " << toclevel << '\n';
1081 // ResetArgs does not make sense here
1082 for (LaTeXArgMap::const_iterator it = latexargs_.begin();
1083 it != latexargs_.end(); ++it)
1084 writeArgument(os, it->first, it->second);
1085 for (LaTeXArgMap::const_iterator it = itemargs_.begin();
1086 it != itemargs_.end(); ++it)
1087 writeArgument(os, it->first, it->second);
1088 for (LaTeXArgMap::const_iterator it = postcommandargs_.begin();
1089 it != postcommandargs_.end(); ++it)
1090 writeArgument(os, it->first, it->second);
1091 os << "\tNeedProtect " << needprotect << "\n"
1092 "\tKeepEmpty " << keepempty << '\n';
1093 if (labelfont == font)
1094 lyxWrite(os, font, "Font", 1);
1096 lyxWrite(os, font, "TextFont", 1);
1097 lyxWrite(os, labelfont, "LabelFont", 1);
1099 os << "\tNextNoIndent " << nextnoindent << "\n"
1100 "\tCommandDepth " << commanddepth << '\n';
1101 if (!latexname_.empty())
1102 os << "\tLatexName \"" << latexname_ << "\"\n";
1103 if (!latexparam_.empty())
1104 os << "\tLatexParam \"" << subst(latexparam_, "\"", """)
1106 if (!leftdelim_.empty())
1107 os << "\tLeftDelim "
1108 << to_utf8(subst(leftdelim_, from_ascii("\n"), from_ascii("<br/>")))
1110 if (!rightdelim_.empty())
1111 os << "\tRightDelim "
1112 << to_utf8(subst(rightdelim_, from_ascii("\n"), from_ascii("<br/>")))
1114 if (!innertag_.empty())
1115 os << "\tInnerTag \"" << innertag_ << "\"\n";
1116 if (!labeltag_.empty())
1117 os << "\tLabelTag \"" << labeltag_ << "\"\n";
1118 if (!itemtag_.empty())
1119 os << "\tItemTag \"" << itemtag_ << "\"\n";
1120 if (!itemcommand_.empty())
1121 os << "\tItemCommand " << itemcommand_ << '\n';
1122 if (!preamble_.empty())
1123 os << "\tPreamble\n\t"
1124 << to_utf8(subst(rtrim(preamble_, "\n"),
1125 from_ascii("\n"), from_ascii("\n\t")))
1126 << "\n\tEndPreamble\n";
1127 if (!langpreamble_.empty())
1128 os << "\tLangPreamble\n\t"
1129 << to_utf8(subst(rtrim(langpreamble_, "\n"),
1130 from_ascii("\n"), from_ascii("\n\t")))
1131 << "\n\tEndLangPreamble\n";
1132 if (!babelpreamble_.empty())
1133 os << "\tBabelPreamble\n\t"
1134 << to_utf8(subst(rtrim(babelpreamble_, "\n"),
1135 from_ascii("\n"), from_ascii("\n\t")))
1136 << "\n\tEndBabelPreamble\n";
1137 switch (labeltype) {
1139 os << "\tLabelType Above\n";
1142 os << "\tLabelType Bibliography\n";
1144 case LABEL_CENTERED:
1145 os << "\tLabelType Centered\n";
1147 case LABEL_ENUMERATE:
1148 os << "\tLabelType Enumerate\n";
1151 os << "\tLabelType Itemize\n";
1154 os << "\tLabelType Manual\n";
1156 case LABEL_NO_LABEL:
1157 os << "\tLabelType No_Label\n";
1159 case LABEL_SENSITIVE:
1160 os << "\tLabelType Sensitive\n";
1163 os << "\tLabelType Static\n";
1166 switch (endlabeltype) {
1168 os << "\tEndLabelType Box\n";
1170 case END_LABEL_FILLED_BOX:
1171 os << "\tEndLabelType Filled_Box\n";
1173 case END_LABEL_NO_LABEL:
1174 os << "\tEndLabelType No_Label\n";
1176 case END_LABEL_STATIC:
1177 os << "\tEndLabelType Static\n";
1180 if (!leftmargin.empty())
1181 os << "\tLeftMargin \"" << to_utf8(leftmargin) << "\"\n";
1182 if (!rightmargin.empty())
1183 os << "\tRightMargin \"" << to_utf8(rightmargin) << "\"\n";
1184 if (!labelindent.empty())
1185 os << "\tLabelIndent " << to_utf8(labelindent) << '\n';
1186 if (!parindent.empty())
1187 os << "\tParIndent " << to_utf8(parindent) << '\n';
1188 os << "\tParSkip " << parskip << "\n"
1189 "\tItemSep " << itemsep << "\n"
1190 "\tTopSep " << topsep << "\n"
1191 "\tBottomSep " << bottomsep << "\n"
1192 "\tLabelBottomSep " << labelbottomsep << '\n';
1193 if (!labelsep.empty())
1194 os << "\tLabelSep " << to_utf8(subst(labelsep, ' ', 'x'))
1196 os << "\tParSep " << parsep << "\n"
1197 "\tNewLine " << newline_allowed << '\n';
1199 case LYX_ALIGN_BLOCK:
1200 os << "\tAlign Block\n";
1202 case LYX_ALIGN_CENTER:
1203 os << "\tAlign Center\n";
1205 case LYX_ALIGN_LAYOUT:
1206 os << "\tAlign Layout\n";
1208 case LYX_ALIGN_LEFT:
1209 os << "\tAlign Left\n";
1211 case LYX_ALIGN_RIGHT:
1212 os << "\tAlign Right\n";
1214 case LYX_ALIGN_DECIMAL:
1215 case LYX_ALIGN_SPECIAL:
1216 case LYX_ALIGN_NONE:
1219 if (alignpossible & (LYX_ALIGN_BLOCK | LYX_ALIGN_CENTER |
1220 LYX_ALIGN_LAYOUT | LYX_ALIGN_LEFT | LYX_ALIGN_RIGHT)) {
1222 os << "\tAlignPossible";
1223 if (alignpossible & LYX_ALIGN_BLOCK) {
1229 if (alignpossible & LYX_ALIGN_CENTER) {
1235 if (alignpossible & LYX_ALIGN_LAYOUT) {
1241 if (alignpossible & LYX_ALIGN_LEFT) {
1247 if (alignpossible & LYX_ALIGN_RIGHT) {
1255 // LabelString must come before LabelStringAppendix
1256 if (!labelstring_.empty())
1257 os << "\tLabelString \"" << to_utf8(labelstring_) << "\"\n";
1258 if (!endlabelstring_.empty())
1259 os << "\tEndLabelString \"" << to_utf8(endlabelstring_) << "\"\n";
1260 if (!labelstring_appendix_.empty() && labelstring_appendix_ != labelstring_)
1261 os << "\tLabelStringAppendix \""
1262 << to_utf8(labelstring_appendix_) << "\"\n";
1263 if (!counter.empty())
1264 os << "\tLabelCounter \"" << to_utf8(counter) << "\"\n";
1265 os << "\tFreeSpacing " << free_spacing << '\n';
1266 os << "\tPassThru " << pass_thru << '\n';
1267 os << "\tParbreakIsNewline " << parbreak_is_newline << '\n';
1268 switch (spacing.getSpace()) {
1269 case Spacing::Double:
1270 os << "\tSpacing Double\n";
1272 case Spacing::Onehalf:
1273 os << "\tSpacing Onehalf\n";
1275 case Spacing::Other:
1276 os << "\tSpacing Other " << spacing.getValueAsString() << '\n';
1278 case Spacing::Single:
1279 os << "\tSpacing Single\n";
1281 case Spacing::Default:
1284 if (!requires_.empty()) {
1285 os << "\tRequires ";
1286 for (set<string>::const_iterator it = requires_.begin();
1287 it != requires_.end(); ++it) {
1288 if (it != requires_.begin())
1294 if (refprefix.empty())
1295 os << "\tRefPrefix OFF\n";
1297 os << "\tRefPrefix " << to_utf8(refprefix) << '\n';
1298 if (!htmltag_.empty())
1299 os << "\tHTMLTag " << htmltag_ << '\n';
1300 if (!htmlattr_.empty())
1301 os << "\tHTMLAttr " << htmlattr_ << '\n';
1302 if (!htmlitemtag_.empty())
1303 os << "\tHTMLItem " << htmlitemtag_ << '\n';
1304 if (!htmlitemattr_.empty())
1305 os << "\tHTMLItemAttr " << htmlitemattr_ << '\n';
1306 if (!htmllabeltag_.empty())
1307 os << "\tHTMLLabel " << htmllabeltag_ << '\n';
1308 if (!htmllabelattr_.empty())
1309 os << "\tHTMLLabelAttr " << htmllabelattr_ << '\n';
1310 os << "\tHTMLLabelFirst " << htmllabelfirst_ << '\n';
1311 if (!htmlstyle_.empty())
1312 os << "\tHTMLStyle\n"
1313 << to_utf8(rtrim(htmlstyle_, "\n"))
1314 << "\n\tEndHTMLStyle\n";
1315 os << "\tHTMLForceCSS " << htmlforcecss_ << '\n';
1316 if (!htmlpreamble_.empty())
1317 os << "\tHTMLPreamble\n"
1318 << to_utf8(rtrim(htmlpreamble_, "\n"))
1319 << "\n\tEndPreamble\n";
1320 os << "\tHTMLTitle " << htmltitle_ << "\n"
1321 "\tSpellcheck " << spellcheck << "\n"
1322 "\tForceLocal " << forcelocal << "\n"
1327 Layout::LaTeXArgMap Layout::args() const
1329 LaTeXArgMap args = latexargs_;
1330 if (!postcommandargs_.empty())
1331 args.insert(postcommandargs_.begin(), postcommandargs_.end());
1332 if (!itemargs_.empty())
1333 args.insert(itemargs_.begin(), itemargs_.end());
1338 int Layout::optArgs() const
1341 LaTeXArgMap::const_iterator it = latexargs_.begin();
1342 for (; it != latexargs_.end(); ++it) {
1343 if (!(*it).second.mandatory)
1346 LaTeXArgMap::const_iterator iit = postcommandargs_.begin();
1347 for (; iit != postcommandargs_.end(); ++iit) {
1348 if (!(*iit).second.mandatory)
1355 int Layout::requiredArgs() const
1358 LaTeXArgMap::const_iterator it = latexargs_.begin();
1359 for (; it != latexargs_.end(); ++it) {
1360 if ((*it).second.mandatory)
1363 LaTeXArgMap::const_iterator iit = postcommandargs_.begin();
1364 for (; iit != postcommandargs_.end(); ++iit) {
1365 if (!(*iit).second.mandatory)
1372 string const & Layout::htmltag() const
1374 if (htmltag_.empty())
1380 string const & Layout::htmlattr() const
1382 if (htmlattr_.empty())
1383 htmlattr_ = "class=\"" + defaultCSSClass() + "\"";
1388 string const & Layout::htmlitemtag() const
1390 if (htmlitemtag_.empty())
1391 htmlitemtag_ = "div";
1392 return htmlitemtag_;
1396 string const & Layout::htmlitemattr() const
1398 if (htmlitemattr_.empty())
1399 htmlitemattr_ = "class=\"" + defaultCSSItemClass() + "\"";
1400 return htmlitemattr_;
1404 string const & Layout::htmllabeltag() const
1406 if (htmllabeltag_.empty()) {
1407 if (labeltype != LABEL_ABOVE &&
1408 labeltype != LABEL_CENTERED)
1409 htmllabeltag_ = "span";
1411 htmllabeltag_ = "div";
1413 return htmllabeltag_;
1417 string const & Layout::htmllabelattr() const
1419 if (htmllabelattr_.empty())
1420 htmllabelattr_ = "class=\"" + defaultCSSLabelClass() + "\"";
1421 return htmllabelattr_;
1425 docstring Layout::htmlstyle() const
1427 if (!htmlstyle_.empty() && !htmlforcecss_)
1429 if (htmldefaultstyle_.empty())
1431 docstring retval = htmldefaultstyle_;
1432 if (!htmlstyle_.empty())
1433 retval += '\n' + htmlstyle_;
1438 string Layout::defaultCSSClass() const
1440 if (!defaultcssclass_.empty())
1441 return defaultcssclass_;
1443 docstring::const_iterator it = name().begin();
1444 docstring::const_iterator en = name().end();
1445 for (; it != en; ++it) {
1446 char_type const c = *it;
1447 if (!isAlphaASCII(c)) {
1449 // make sure we don't start with an underscore,
1450 // as that sometimes causes problems.
1451 d = from_ascii("lyx_");
1454 } else if (isLower(c))
1457 // this is slow, so do it only if necessary
1460 defaultcssclass_ = to_utf8(d);
1461 return defaultcssclass_;
1467 string makeMarginValue(char const * side, double d)
1470 os << "margin-" << side << ": " << d << "ex;\n";
1477 void Layout::makeDefaultCSS() const
1479 // this never needs to be redone, since reloading layouts will
1480 // wipe out what we did before.
1481 if (!htmldefaultstyle_.empty())
1485 htmldefaultstyle_ = font.asCSS();
1490 tmp += makeMarginValue("top", topsep);
1492 tmp += makeMarginValue("bottom", bottomsep);
1493 if (!leftmargin.empty()) {
1494 // we can't really do what LyX does with the margin, so
1495 // we'll just figure out how many characters it is
1496 int const len = leftmargin.length();
1497 tmp += makeMarginValue("left", len);
1499 if (!rightmargin.empty()) {
1500 int const len = rightmargin.length();
1501 tmp += makeMarginValue("right", len);
1505 if (!htmldefaultstyle_.empty())
1506 htmldefaultstyle_ += from_ascii("\n");
1507 htmldefaultstyle_ += from_ascii(tmp);
1511 string where = alignmentToCSS(align);
1512 if (!where.empty()) {
1513 htmldefaultstyle_ += from_ascii("text-align: " + where + ";\n");
1516 // wrap up what we have, if anything
1517 if (!htmldefaultstyle_.empty())
1519 from_ascii(htmltag() + "." + defaultCSSClass() + " {\n") +
1520 htmldefaultstyle_ + from_ascii("\n}\n");
1522 if (labeltype == LABEL_NO_LABEL || htmllabeltag() == "NONE")
1528 if (labelfont != font)
1529 labelCSS = labelfont.asCSS() + from_ascii("\n");
1530 if (labeltype == LABEL_CENTERED)
1531 labelCSS += from_ascii("text-align: center;\n");
1533 if (!labelCSS.empty())
1534 htmldefaultstyle_ +=
1535 from_ascii(htmllabeltag() + "." + defaultCSSLabelClass() + " {\n") +
1536 labelCSS + from_ascii("\n}\n");
1540 bool Layout::operator==(Layout const & rhs) const
1542 // This is enough for the applications we actually make,
1543 // at least at the moment. But we could check more.
1544 return name() == rhs.name()
1545 && latexname() == rhs.latexname()
1546 && latextype == rhs.latextype;