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_INTITLE // keep this last!
113 /////////////////////
118 margintype = MARGIN_STATIC;
119 latextype = LATEX_PARAGRAPH;
125 labelfont = inherit_font;
127 reslabelfont = sane_font;
128 nextnoindent = false;
133 labelbottomsep = 0.0;
135 align = LYX_ALIGN_BLOCK;
136 alignpossible = LYX_ALIGN_NONE | LYX_ALIGN_LAYOUT;
137 labeltype = LABEL_NO_LABEL;
138 endlabeltype = END_LABEL_NO_LABEL;
139 // Should or should not. That is the question.
140 // spacing.set(Spacing::OneHalf);
141 newline_allowed = true;
142 free_spacing = false;
144 parbreak_is_newline = false;
145 toclevel = NOT_IN_TOC;
147 htmllabelfirst_ = false;
148 htmlforcecss_ = false;
152 itemcommand_ = "item";
153 toggle_indent = ITOGGLE_DOCUMENT_DEFAULT;
157 bool Layout::read(Lexer & lex, TextClass const & tclass)
159 // If this is an empty layout, or if no force local version is set,
160 // we know that we will not discard the stuff to read
162 return readIgnoreForcelocal(lex, tclass);
165 bool const ret = tmp.readIgnoreForcelocal(lex, tclass);
167 // - the read version is higher
168 // - both versions are infinity (arbitrary decision)
169 // - the file did not contain any local version (needed for not
170 // skipping user defined local layouts)
171 if (tmp.forcelocal <= 0 || tmp.forcelocal > forcelocal)
177 bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass)
179 // This table is sorted alphabetically [asierra 30March96]
180 LexerKeyword layoutTags[] = {
181 { "align", LT_ALIGN },
182 { "alignpossible", LT_ALIGNPOSSIBLE },
183 { "argument", LT_ARGUMENT },
184 { "babelpreamble", LT_BABELPREAMBLE },
185 { "bottomsep", LT_BOTTOMSEP },
186 { "category", LT_CATEGORY },
187 { "commanddepth", LT_COMMANDDEPTH },
188 { "copystyle", LT_COPYSTYLE },
189 { "dependson", LT_DEPENDSON },
191 { "endlabelstring", LT_ENDLABELSTRING },
192 { "endlabeltype", LT_ENDLABELTYPE },
194 { "forcelocal", LT_FORCELOCAL },
195 { "freespacing", LT_FREE_SPACING },
196 { "htmlattr", LT_HTMLATTR },
197 { "htmlforcecss", LT_HTMLFORCECSS },
198 { "htmlitem", LT_HTMLITEM },
199 { "htmlitemattr", LT_HTMLITEMATTR },
200 { "htmllabel", LT_HTMLLABEL },
201 { "htmllabelattr", LT_HTMLLABELATTR },
202 { "htmllabelfirst", LT_HTMLLABELFIRST },
203 { "htmlpreamble", LT_HTMLPREAMBLE },
204 { "htmlstyle", LT_HTMLSTYLE },
205 { "htmltag", LT_HTMLTAG },
206 { "htmltitle", LT_HTMLTITLE },
207 { "innertag", LT_INNERTAG },
208 { "inpreamble", LT_INPREAMBLE },
209 { "intitle", LT_INTITLE },
210 { "itemcommand", LT_ITEMCOMMAND },
211 { "itemsep", LT_ITEMSEP },
212 { "itemtag", LT_ITEMTAG },
213 { "keepempty", LT_KEEPEMPTY },
214 { "labelbottomsep", LT_LABEL_BOTTOMSEP },
215 { "labelcounter", LT_LABELCOUNTER },
216 { "labelfont", LT_LABELFONT },
217 { "labelindent", LT_LABELINDENT },
218 { "labelsep", LT_LABELSEP },
219 { "labelstring", LT_LABELSTRING },
220 { "labelstringappendix", LT_LABELSTRING_APPENDIX },
221 { "labeltag", LT_LABELTAG },
222 { "labeltype", LT_LABELTYPE },
223 { "langpreamble", LT_LANGPREAMBLE },
224 { "latexname", LT_LATEXNAME },
225 { "latexparam", LT_LATEXPARAM },
226 { "latextype", LT_LATEXTYPE },
227 { "leftdelim", LT_LEFTDELIM },
228 { "leftmargin", LT_LEFTMARGIN },
229 { "margin", LT_MARGIN },
230 { "needprotect", LT_NEED_PROTECT },
231 { "newline", LT_NEWLINE },
232 { "nextnoindent", LT_NEXTNOINDENT },
233 { "obsoletedby", LT_OBSOLETEDBY },
234 { "parbreakisnewline", LT_PARBREAK_IS_NEWLINE },
235 { "parindent", LT_PARINDENT },
236 { "parsep", LT_PARSEP },
237 { "parskip", LT_PARSKIP },
238 { "passthru", LT_PASS_THRU },
239 { "passthruchars", LT_PASS_THRU_CHARS },
240 { "preamble", LT_PREAMBLE },
241 { "refprefix", LT_REFPREFIX },
242 { "requires", LT_REQUIRES },
243 { "resetargs", LT_RESETARGS },
244 { "rightdelim", LT_RIGHTDELIM },
245 { "rightmargin", LT_RIGHTMARGIN },
246 { "spacing", LT_SPACING },
247 { "spellcheck", LT_SPELLCHECK },
248 { "textfont", LT_TEXTFONT },
249 { "toclevel", LT_TOCLEVEL },
250 { "toggleindent", LT_TOGGLE_INDENT },
251 { "topsep", LT_TOPSEP }
255 bool finished = false;
256 lex.pushTable(layoutTags);
258 // parse style section
259 while (!finished && lex.isOK() && !error) {
261 // See comment in LyXRC.cpp.
263 case Lexer::LEX_FEOF:
266 case Lexer::LEX_UNDEF:
268 lex.printError("Unknown layout tag `$$Token'");
275 switch (static_cast<LayoutTags>(le)) {
287 style = subst(style, '_', ' ');
289 if (tclass.hasLayout(style)) {
290 docstring const tmpname = name_;
291 this->operator=(tclass[style]);
294 LYXERR0("Cannot copy unknown style `"
296 << "All layouts so far:");
297 DocumentClass::const_iterator lit = tclass.begin();
298 DocumentClass::const_iterator len = tclass.end();
299 for (; lit != len; ++lit)
300 LYXERR0(lit->name());
305 case LT_OBSOLETEDBY: {
308 style = subst(style, '_', ' ');
310 if (tclass.hasLayout(style)) {
311 docstring const tmpname = name_;
312 this->operator=(tclass[style]);
314 if (obsoleted_by().empty())
315 obsoleted_by_ = style;
317 LYXERR0("Cannot replace with unknown style `"
320 //lex.printError("Cannot replace with"
329 depends_on_ = subst(depends_on_, '_', ' ');
358 postcommandargs_.clear();
366 case LT_NEED_PROTECT:
375 font = lyxRead(lex, font);
380 font = lyxRead(lex, font);
384 labelfont = lyxRead(lex, labelfont);
387 case LT_NEXTNOINDENT:
391 case LT_TOGGLE_INDENT: {
394 tog = support::ascii_lowercase(tog);
396 toggle_indent = ITOGGLE_ALWAYS;
397 else if (tog == "never")
398 toggle_indent = ITOGGLE_NEVER;
400 toggle_indent = ITOGGLE_DOCUMENT_DEFAULT;
404 case LT_COMMANDDEPTH:
414 latexparam_ = subst(latexparam_, """, "\"");
419 leftdelim_ = support::subst(leftdelim_, from_ascii("<br/>"),
425 rightdelim_ = support::subst(rightdelim_, from_ascii("<br/>"),
446 preamble_ = from_utf8(lex.getLongString("EndPreamble"));
449 case LT_LANGPREAMBLE:
450 langpreamble_ = from_utf8(lex.getLongString("EndLangPreamble"));
453 case LT_BABELPREAMBLE:
454 babelpreamble_ = from_utf8(lex.getLongString("EndBabelPreamble"));
461 case LT_ENDLABELTYPE:
462 readEndLabelType(lex);
497 case LT_LABEL_BOTTOMSEP:
498 lex >> labelbottomsep;
503 labelsep = subst(labelsep, 'x', ' ');
511 lex >> newline_allowed;
518 case LT_ALIGNPOSSIBLE:
519 readAlignPossible(lex);
523 // FIXME: this means LT_LABELSTRING_APPENDIX may only
524 // occur after LT_LABELSTRING
526 labelstring_ = trim(labelstring_);
527 labelstring_appendix_ = labelstring_;
530 case LT_ENDLABELSTRING:
531 lex >> endlabelstring_;
532 endlabelstring_ = trim(endlabelstring_);
535 case LT_LABELSTRING_APPENDIX:
536 lex >> labelstring_appendix_;
537 labelstring_appendix_ = trim(labelstring_appendix_);
540 case LT_LABELCOUNTER:
542 counter = trim(counter);
545 case LT_FREE_SPACING:
553 case LT_PASS_THRU_CHARS:
554 lex >> pass_thru_chars;
557 case LT_PARBREAK_IS_NEWLINE:
558 lex >> parbreak_is_newline;
567 vector<string> const req =
568 getVectorFromString(lex.getString());
569 requires_.insert(req.begin(), req.end());
595 case LT_HTMLITEMATTR:
596 lex >> htmlitemattr_;
600 lex >> htmllabeltag_;
603 case LT_HTMLLABELATTR:
604 lex >> htmllabelattr_;
607 case LT_HTMLLABELFIRST:
608 lex >> htmllabelfirst_;
612 htmlstyle_ = from_utf8(lex.getLongString("EndHTMLStyle"));
615 case LT_HTMLFORCECSS:
616 lex >> htmlforcecss_;
619 case LT_HTMLPREAMBLE:
620 htmlpreamble_ = from_utf8(lex.getLongString("EndPreamble"));
637 // make sure we only have inpreamble = true for commands
638 if (inpreamble && latextype != LATEX_COMMAND && latextype != LATEX_PARAGRAPH) {
639 LYXERR0("InPreamble not permitted except with command and paragraph layouts.");
640 LYXERR0("Layout name: " << name());
644 return finished && !error;
657 LexerKeyword alignTags[] = {
658 { "block", AT_BLOCK },
659 { "center", AT_CENTER },
660 { "layout", AT_LAYOUT },
662 { "right", AT_RIGHT }
666 void Layout::readAlign(Lexer & lex)
668 PushPopHelper pph(lex, alignTags);
671 case Lexer::LEX_UNDEF:
672 lex.printError("Unknown alignment `$$Token'");
678 align = LYX_ALIGN_BLOCK;
681 align = LYX_ALIGN_LEFT;
684 align = LYX_ALIGN_RIGHT;
687 align = LYX_ALIGN_CENTER;
690 align = LYX_ALIGN_LAYOUT;
696 void Layout::readAlignPossible(Lexer & lex)
698 lex.pushTable(alignTags);
699 alignpossible = LYX_ALIGN_NONE | LYX_ALIGN_LAYOUT;
700 int lineno = lex.lineNumber();
704 case Lexer::LEX_UNDEF:
705 lex.printError("Unknown alignment `$$Token'");
711 alignpossible |= LYX_ALIGN_BLOCK;
714 alignpossible |= LYX_ALIGN_LEFT;
717 alignpossible |= LYX_ALIGN_RIGHT;
720 alignpossible |= LYX_ALIGN_CENTER;
723 alignpossible |= LYX_ALIGN_LAYOUT;
726 } while (lineno == lex.lineNumber());
731 void Layout::readLabelType(Lexer & lex)
746 LexerKeyword labelTypeTags[] = {
747 { "above", LA_ABOVE },
748 { "bibliography", LA_BIBLIO },
749 { "centered", LA_CENTERED },
750 { "enumerate", LA_ENUMERATE },
751 { "itemize", LA_ITEMIZE },
752 { "manual", LA_MANUAL },
753 { "no_label", LA_NO_LABEL },
754 { "sensitive", LA_SENSITIVE },
755 { "static", LA_STATIC }
758 PushPopHelper pph(lex, labelTypeTags);
761 case Lexer::LEX_UNDEF:
762 lex.printError("Unknown labeltype tag `$$Token'");
768 labeltype = LABEL_NO_LABEL;
771 labeltype = LABEL_MANUAL;
774 labeltype = LABEL_ABOVE;
777 labeltype = LABEL_CENTERED;
780 labeltype = LABEL_STATIC;
783 labeltype = LABEL_SENSITIVE;
786 labeltype = LABEL_ENUMERATE;
789 labeltype = LABEL_ITEMIZE;
792 labeltype = LABEL_BIBLIO;
798 void Layout::readEndLabelType(Lexer & lex)
800 // this should be const, but can't be because
802 static LexerKeyword endlabelTypeTags[] = {
803 { "box", END_LABEL_BOX },
804 { "filled_box", END_LABEL_FILLED_BOX },
805 { "no_label", END_LABEL_NO_LABEL },
806 { "static", END_LABEL_STATIC }
809 PushPopHelper pph(lex, endlabelTypeTags);
812 case Lexer::LEX_UNDEF:
813 lex.printError("Unknown labeltype tag `$$Token'");
815 case END_LABEL_STATIC:
817 case END_LABEL_FILLED_BOX:
818 case END_LABEL_NO_LABEL:
819 endlabeltype = static_cast<EndLabelType>(le);
822 LYXERR0("Unhandled value " << le);
828 void Layout::readMargin(Lexer & lex)
830 LexerKeyword marginTags[] = {
831 { "dynamic", MARGIN_DYNAMIC },
832 { "first_dynamic", MARGIN_FIRST_DYNAMIC },
833 { "manual", MARGIN_MANUAL },
834 { "right_address_box", MARGIN_RIGHT_ADDRESS_BOX },
835 { "static", MARGIN_STATIC }
838 PushPopHelper pph(lex, marginTags);
842 case Lexer::LEX_UNDEF:
843 lex.printError("Unknown margin type tag `$$Token'");
848 case MARGIN_FIRST_DYNAMIC:
849 case MARGIN_RIGHT_ADDRESS_BOX:
850 margintype = static_cast<MarginType>(le);
853 LYXERR0("Unhandled value " << le);
859 void Layout::readLatexType(Lexer & lex)
861 LexerKeyword latexTypeTags[] = {
862 { "bib_environment", LATEX_BIB_ENVIRONMENT },
863 { "command", LATEX_COMMAND },
864 { "environment", LATEX_ENVIRONMENT },
865 { "item_environment", LATEX_ITEM_ENVIRONMENT },
866 { "list_environment", LATEX_LIST_ENVIRONMENT },
867 { "paragraph", LATEX_PARAGRAPH }
870 PushPopHelper pph(lex, latexTypeTags);
873 case Lexer::LEX_UNDEF:
874 lex.printError("Unknown latextype tag `$$Token'");
876 case LATEX_PARAGRAPH:
878 case LATEX_ENVIRONMENT:
879 case LATEX_ITEM_ENVIRONMENT:
880 case LATEX_BIB_ENVIRONMENT:
881 case LATEX_LIST_ENVIRONMENT:
882 latextype = static_cast<LatexType>(le);
885 LYXERR0("Unhandled value " << le);
891 void Layout::readSpacing(Lexer & lex)
894 ST_SPACING_SINGLE = 1,
900 LexerKeyword spacingTags[] = {
901 {"double", ST_SPACING_DOUBLE },
902 {"onehalf", ST_SPACING_ONEHALF },
903 {"other", ST_OTHER },
904 {"single", ST_SPACING_SINGLE }
907 PushPopHelper pph(lex, spacingTags);
910 case Lexer::LEX_UNDEF:
911 lex.printError("Unknown spacing token `$$Token'");
916 case ST_SPACING_SINGLE:
917 spacing.set(Spacing::Single);
919 case ST_SPACING_ONEHALF:
920 spacing.set(Spacing::Onehalf);
922 case ST_SPACING_DOUBLE:
923 spacing.set(Spacing::Double);
927 spacing.set(Spacing::Other, lex.getString());
933 void Layout::readArgument(Lexer & lex)
936 // writeArgument() makes use of these default values
937 arg.mandatory = false;
938 arg.autoinsert = false;
940 bool finished = false;
941 arg.font = inherit_font;
942 arg.labelfont = inherit_font;
945 bool const itemarg = prefixIs(id, "item:");
946 bool const postcmd = prefixIs(id, "post:");
948 while (!finished && lex.isOK() && !error) {
950 string const tok = ascii_lowercase(lex.getString());
954 } else if (tok == "endargument") {
956 } else if (tok == "labelstring") {
958 arg.labelstring = lex.getDocString();
959 } else if (tok == "menustring") {
961 arg.menustring = lex.getDocString();
962 } else if (tok == "mandatory") {
964 arg.mandatory = lex.getBool();
965 } else if (tok == "autoinsert") {
967 arg.autoinsert = lex.getBool();
968 } else if (tok == "leftdelim") {
970 arg.ldelim = lex.getDocString();
971 arg.ldelim = support::subst(arg.ldelim, from_ascii("<br/>"),
973 } else if (tok == "rightdelim") {
975 arg.rdelim = lex.getDocString();
976 arg.rdelim = support::subst(arg.rdelim, from_ascii("<br/>"),
978 } else if (tok == "defaultarg") {
980 arg.defaultarg = lex.getDocString();
981 } else if (tok == "presetarg") {
983 arg.presetarg = lex.getDocString();
984 } else if (tok == "tooltip") {
986 arg.tooltip = lex.getDocString();
987 } else if (tok == "requires") {
989 arg.requires = lex.getString();
990 } else if (tok == "decoration") {
992 arg.decoration = lex.getString();
993 } else if (tok == "font") {
994 arg.font = lyxRead(lex, arg.font);
995 } else if (tok == "labelfont") {
996 arg.labelfont = lyxRead(lex, arg.labelfont);
998 lex.printError("Unknown tag");
1002 if (arg.labelstring.empty())
1003 LYXERR0("Incomplete Argument definition!");
1005 itemargs_[id] = arg;
1007 postcommandargs_[id] = arg;
1009 latexargs_[id] = arg;
1013 void writeArgument(ostream & os, string const & id, Layout::latexarg const & arg)
1015 os << "\tArgument " << id << '\n';
1016 if (!arg.labelstring.empty())
1017 os << "\t\tLabelString \"" << to_utf8(arg.labelstring) << "\"\n";
1018 if (!arg.menustring.empty())
1019 os << "\t\tMenuString \"" << to_utf8(arg.menustring) << "\"\n";
1021 os << "\t\tMandatory " << arg.mandatory << '\n';
1023 os << "\t\tAutoinsert " << arg.autoinsert << '\n';
1024 if (!arg.ldelim.empty())
1025 os << "\t\tLeftDelim \""
1026 << to_utf8(subst(arg.ldelim, from_ascii("\n"), from_ascii("<br/>")))
1028 if (!arg.rdelim.empty())
1029 os << "\t\tRightDelim \""
1030 << to_utf8(subst(arg.rdelim, from_ascii("\n"), from_ascii("<br/>")))
1032 if (!arg.defaultarg.empty())
1033 os << "\t\tDefaultArg \"" << to_utf8(arg.defaultarg) << "\"\n";
1034 if (!arg.presetarg.empty())
1035 os << "\t\tPresetArg \"" << to_utf8(arg.presetarg) << "\"\n";
1036 if (!arg.tooltip.empty())
1037 os << "\t\tToolTip \"" << to_utf8(arg.tooltip) << "\"\n";
1038 if (!arg.requires.empty())
1039 os << "\t\tRequires \"" << arg.requires << "\"\n";
1040 if (!arg.decoration.empty())
1041 os << "\t\tDecoration \"" << arg.decoration << "\"\n";
1042 if (arg.font != inherit_font)
1043 lyxWrite(os, arg.font, "Font", 2);
1044 if (arg.labelfont != inherit_font)
1045 lyxWrite(os, arg.labelfont, "LabelFont", 2);
1046 os << "\tEndArgument\n";
1050 void Layout::write(ostream & os) const
1052 os << "Style " << to_utf8(name_) << '\n';
1053 if (!category_.empty() && obsoleted_by_.empty())
1054 os << "\tCategory \"" << to_utf8(category_) << "\"\n";
1055 // Can't deduce Copystyle here :-(
1056 if (!obsoleted_by_.empty()) {
1057 os << "\tObsoletedBy \"" << to_utf8(obsoleted_by_)
1061 if (!depends_on_.empty())
1062 os << "\tDependsOn " << to_utf8(depends_on_) << '\n';
1063 switch (margintype) {
1064 case MARGIN_DYNAMIC:
1065 os << "\tMargin Dynamic\n";
1067 case MARGIN_FIRST_DYNAMIC:
1068 os << "\tMargin First_Dynamic\n";
1071 os << "\tMargin Manual\n";
1073 case MARGIN_RIGHT_ADDRESS_BOX:
1074 os << "\tMargin Right_Address_Box\n";
1077 os << "\tMargin Static\n";
1080 switch (latextype) {
1081 case LATEX_BIB_ENVIRONMENT:
1082 os << "\tLatexType Bib_Environment\n";
1085 os << "\tLatexType Command\n";
1087 case LATEX_ENVIRONMENT:
1088 os << "\tLatexType Environment\n";
1090 case LATEX_ITEM_ENVIRONMENT:
1091 os << "\tLatexType Item_Environment\n";
1093 case LATEX_LIST_ENVIRONMENT:
1094 os << "\tLatexType List_Environment\n";
1096 case LATEX_PARAGRAPH:
1097 os << "\tLatexType Paragraph\n";
1100 os << "\tInTitle " << intitle << "\n"
1101 "\tInPreamble " << inpreamble << "\n"
1102 "\tTocLevel " << toclevel << '\n';
1103 // ResetArgs does not make sense here
1104 for (LaTeXArgMap::const_iterator it = latexargs_.begin();
1105 it != latexargs_.end(); ++it)
1106 writeArgument(os, it->first, it->second);
1107 for (LaTeXArgMap::const_iterator it = itemargs_.begin();
1108 it != itemargs_.end(); ++it)
1109 writeArgument(os, it->first, it->second);
1110 for (LaTeXArgMap::const_iterator it = postcommandargs_.begin();
1111 it != postcommandargs_.end(); ++it)
1112 writeArgument(os, it->first, it->second);
1113 os << "\tNeedProtect " << needprotect << "\n"
1114 "\tKeepEmpty " << keepempty << '\n';
1115 if (labelfont == font)
1116 lyxWrite(os, font, "Font", 1);
1118 lyxWrite(os, font, "TextFont", 1);
1119 lyxWrite(os, labelfont, "LabelFont", 1);
1121 os << "\tNextNoIndent " << nextnoindent << "\n"
1122 "\tCommandDepth " << commanddepth << '\n';
1123 if (!latexname_.empty())
1124 os << "\tLatexName \"" << latexname_ << "\"\n";
1125 if (!latexparam_.empty())
1126 os << "\tLatexParam \"" << subst(latexparam_, "\"", """)
1128 if (!leftdelim_.empty())
1129 os << "\tLeftDelim "
1130 << to_utf8(subst(leftdelim_, from_ascii("\n"), from_ascii("<br/>")))
1132 if (!rightdelim_.empty())
1133 os << "\tRightDelim "
1134 << to_utf8(subst(rightdelim_, from_ascii("\n"), from_ascii("<br/>")))
1136 if (!innertag_.empty())
1137 os << "\tInnerTag \"" << innertag_ << "\"\n";
1138 if (!labeltag_.empty())
1139 os << "\tLabelTag \"" << labeltag_ << "\"\n";
1140 if (!itemtag_.empty())
1141 os << "\tItemTag \"" << itemtag_ << "\"\n";
1142 if (!itemcommand_.empty())
1143 os << "\tItemCommand " << itemcommand_ << '\n';
1144 if (!preamble_.empty())
1145 os << "\tPreamble\n\t"
1146 << to_utf8(subst(rtrim(preamble_, "\n"),
1147 from_ascii("\n"), from_ascii("\n\t")))
1148 << "\n\tEndPreamble\n";
1149 if (!langpreamble_.empty())
1150 os << "\tLangPreamble\n\t"
1151 << to_utf8(subst(rtrim(langpreamble_, "\n"),
1152 from_ascii("\n"), from_ascii("\n\t")))
1153 << "\n\tEndLangPreamble\n";
1154 if (!babelpreamble_.empty())
1155 os << "\tBabelPreamble\n\t"
1156 << to_utf8(subst(rtrim(babelpreamble_, "\n"),
1157 from_ascii("\n"), from_ascii("\n\t")))
1158 << "\n\tEndBabelPreamble\n";
1159 switch (labeltype) {
1161 os << "\tLabelType Above\n";
1164 os << "\tLabelType Bibliography\n";
1166 case LABEL_CENTERED:
1167 os << "\tLabelType Centered\n";
1169 case LABEL_ENUMERATE:
1170 os << "\tLabelType Enumerate\n";
1173 os << "\tLabelType Itemize\n";
1176 os << "\tLabelType Manual\n";
1178 case LABEL_NO_LABEL:
1179 os << "\tLabelType No_Label\n";
1181 case LABEL_SENSITIVE:
1182 os << "\tLabelType Sensitive\n";
1185 os << "\tLabelType Static\n";
1188 switch (endlabeltype) {
1190 os << "\tEndLabelType Box\n";
1192 case END_LABEL_FILLED_BOX:
1193 os << "\tEndLabelType Filled_Box\n";
1195 case END_LABEL_NO_LABEL:
1196 os << "\tEndLabelType No_Label\n";
1198 case END_LABEL_STATIC:
1199 os << "\tEndLabelType Static\n";
1202 if (!leftmargin.empty())
1203 os << "\tLeftMargin \"" << to_utf8(leftmargin) << "\"\n";
1204 if (!rightmargin.empty())
1205 os << "\tRightMargin \"" << to_utf8(rightmargin) << "\"\n";
1206 if (!labelindent.empty())
1207 os << "\tLabelIndent " << to_utf8(labelindent) << '\n';
1208 if (!parindent.empty())
1209 os << "\tParIndent " << to_utf8(parindent) << '\n';
1210 os << "\tParSkip " << parskip << "\n"
1211 "\tItemSep " << itemsep << "\n"
1212 "\tTopSep " << topsep << "\n"
1213 "\tBottomSep " << bottomsep << "\n"
1214 "\tLabelBottomSep " << labelbottomsep << '\n';
1215 if (!labelsep.empty())
1216 os << "\tLabelSep " << to_utf8(subst(labelsep, ' ', 'x'))
1218 os << "\tParSep " << parsep << "\n"
1219 "\tNewLine " << newline_allowed << '\n';
1221 case LYX_ALIGN_BLOCK:
1222 os << "\tAlign Block\n";
1224 case LYX_ALIGN_CENTER:
1225 os << "\tAlign Center\n";
1227 case LYX_ALIGN_LAYOUT:
1228 os << "\tAlign Layout\n";
1230 case LYX_ALIGN_LEFT:
1231 os << "\tAlign Left\n";
1233 case LYX_ALIGN_RIGHT:
1234 os << "\tAlign Right\n";
1236 case LYX_ALIGN_DECIMAL:
1237 case LYX_ALIGN_SPECIAL:
1238 case LYX_ALIGN_NONE:
1241 if (alignpossible & (LYX_ALIGN_BLOCK | LYX_ALIGN_CENTER |
1242 LYX_ALIGN_LAYOUT | LYX_ALIGN_LEFT | LYX_ALIGN_RIGHT)) {
1244 os << "\tAlignPossible";
1245 if (alignpossible & LYX_ALIGN_BLOCK) {
1251 if (alignpossible & LYX_ALIGN_CENTER) {
1257 if (alignpossible & LYX_ALIGN_LAYOUT) {
1263 if (alignpossible & LYX_ALIGN_LEFT) {
1269 if (alignpossible & LYX_ALIGN_RIGHT) {
1277 // LabelString must come before LabelStringAppendix
1278 if (!labelstring_.empty())
1279 os << "\tLabelString \"" << to_utf8(labelstring_) << "\"\n";
1280 if (!endlabelstring_.empty())
1281 os << "\tEndLabelString \"" << to_utf8(endlabelstring_) << "\"\n";
1282 if (!labelstring_appendix_.empty() && labelstring_appendix_ != labelstring_)
1283 os << "\tLabelStringAppendix \""
1284 << to_utf8(labelstring_appendix_) << "\"\n";
1285 if (!counter.empty())
1286 os << "\tLabelCounter \"" << to_utf8(counter) << "\"\n";
1287 os << "\tFreeSpacing " << free_spacing << '\n';
1288 os << "\tPassThru " << pass_thru << '\n';
1289 if (!pass_thru_chars.empty())
1290 os << "\tPassThruChars " << to_utf8(pass_thru_chars) << '\n';
1291 os << "\tParbreakIsNewline " << parbreak_is_newline << '\n';
1292 switch (spacing.getSpace()) {
1293 case Spacing::Double:
1294 os << "\tSpacing Double\n";
1296 case Spacing::Onehalf:
1297 os << "\tSpacing Onehalf\n";
1299 case Spacing::Other:
1300 os << "\tSpacing Other " << spacing.getValueAsString() << '\n';
1302 case Spacing::Single:
1303 os << "\tSpacing Single\n";
1305 case Spacing::Default:
1308 if (!requires_.empty()) {
1309 os << "\tRequires ";
1310 for (set<string>::const_iterator it = requires_.begin();
1311 it != requires_.end(); ++it) {
1312 if (it != requires_.begin())
1318 if (refprefix.empty())
1319 os << "\tRefPrefix OFF\n";
1321 os << "\tRefPrefix " << to_utf8(refprefix) << '\n';
1322 if (!htmltag_.empty())
1323 os << "\tHTMLTag " << htmltag_ << '\n';
1324 if (!htmlattr_.empty())
1325 os << "\tHTMLAttr " << htmlattr_ << '\n';
1326 if (!htmlitemtag_.empty())
1327 os << "\tHTMLItem " << htmlitemtag_ << '\n';
1328 if (!htmlitemattr_.empty())
1329 os << "\tHTMLItemAttr " << htmlitemattr_ << '\n';
1330 if (!htmllabeltag_.empty())
1331 os << "\tHTMLLabel " << htmllabeltag_ << '\n';
1332 if (!htmllabelattr_.empty())
1333 os << "\tHTMLLabelAttr " << htmllabelattr_ << '\n';
1334 os << "\tHTMLLabelFirst " << htmllabelfirst_ << '\n';
1335 if (!htmlstyle_.empty())
1336 os << "\tHTMLStyle\n"
1337 << to_utf8(rtrim(htmlstyle_, "\n"))
1338 << "\n\tEndHTMLStyle\n";
1339 os << "\tHTMLForceCSS " << htmlforcecss_ << '\n';
1340 if (!htmlpreamble_.empty())
1341 os << "\tHTMLPreamble\n"
1342 << to_utf8(rtrim(htmlpreamble_, "\n"))
1343 << "\n\tEndPreamble\n";
1344 os << "\tHTMLTitle " << htmltitle_ << "\n"
1345 "\tSpellcheck " << spellcheck << "\n"
1346 "\tForceLocal " << forcelocal << "\n"
1351 Layout::LaTeXArgMap Layout::args() const
1353 LaTeXArgMap args = latexargs_;
1354 if (!postcommandargs_.empty())
1355 args.insert(postcommandargs_.begin(), postcommandargs_.end());
1356 if (!itemargs_.empty())
1357 args.insert(itemargs_.begin(), itemargs_.end());
1362 int Layout::optArgs() const
1365 LaTeXArgMap::const_iterator it = latexargs_.begin();
1366 for (; it != latexargs_.end(); ++it) {
1367 if (!(*it).second.mandatory)
1370 LaTeXArgMap::const_iterator iit = postcommandargs_.begin();
1371 for (; iit != postcommandargs_.end(); ++iit) {
1372 if (!(*iit).second.mandatory)
1379 int Layout::requiredArgs() const
1382 LaTeXArgMap::const_iterator it = latexargs_.begin();
1383 for (; it != latexargs_.end(); ++it) {
1384 if ((*it).second.mandatory)
1387 LaTeXArgMap::const_iterator iit = postcommandargs_.begin();
1388 for (; iit != postcommandargs_.end(); ++iit) {
1389 if (!(*iit).second.mandatory)
1396 string const & Layout::htmltag() const
1398 if (htmltag_.empty())
1404 string const & Layout::htmlattr() const
1406 if (htmlattr_.empty())
1407 htmlattr_ = "class=\"" + defaultCSSClass() + "\"";
1412 string const & Layout::htmlitemtag() const
1414 if (htmlitemtag_.empty())
1415 htmlitemtag_ = "div";
1416 return htmlitemtag_;
1420 string const & Layout::htmlitemattr() const
1422 if (htmlitemattr_.empty())
1423 htmlitemattr_ = "class=\"" + defaultCSSItemClass() + "\"";
1424 return htmlitemattr_;
1428 string const & Layout::htmllabeltag() const
1430 if (htmllabeltag_.empty()) {
1431 if (labeltype != LABEL_ABOVE &&
1432 labeltype != LABEL_CENTERED)
1433 htmllabeltag_ = "span";
1435 htmllabeltag_ = "div";
1437 return htmllabeltag_;
1441 string const & Layout::htmllabelattr() const
1443 if (htmllabelattr_.empty())
1444 htmllabelattr_ = "class=\"" + defaultCSSLabelClass() + "\"";
1445 return htmllabelattr_;
1449 docstring Layout::htmlstyle() const
1451 if (!htmlstyle_.empty() && !htmlforcecss_)
1453 if (htmldefaultstyle_.empty())
1455 docstring retval = htmldefaultstyle_;
1456 if (!htmlstyle_.empty())
1457 retval += '\n' + htmlstyle_;
1462 string Layout::defaultCSSClass() const
1464 if (!defaultcssclass_.empty())
1465 return defaultcssclass_;
1467 docstring::const_iterator it = name().begin();
1468 docstring::const_iterator en = name().end();
1469 for (; it != en; ++it) {
1470 char_type const c = *it;
1471 if (!isAlphaASCII(c)) {
1473 // make sure we don't start with an underscore,
1474 // as that sometimes causes problems.
1475 d = from_ascii("lyx_");
1478 } else if (isLower(c))
1481 // this is slow, so do it only if necessary
1484 defaultcssclass_ = to_utf8(d);
1485 return defaultcssclass_;
1491 string makeMarginValue(char const * side, double d)
1494 os << "margin-" << side << ": " << d << "ex;\n";
1501 void Layout::makeDefaultCSS() const
1503 // this never needs to be redone, since reloading layouts will
1504 // wipe out what we did before.
1505 if (!htmldefaultstyle_.empty())
1509 htmldefaultstyle_ = font.asCSS();
1514 tmp += makeMarginValue("top", topsep);
1516 tmp += makeMarginValue("bottom", bottomsep);
1517 if (!leftmargin.empty()) {
1518 // we can't really do what LyX does with the margin, so
1519 // we'll just figure out how many characters it is
1520 int const len = leftmargin.length();
1521 tmp += makeMarginValue("left", len);
1523 if (!rightmargin.empty()) {
1524 int const len = rightmargin.length();
1525 tmp += makeMarginValue("right", len);
1529 if (!htmldefaultstyle_.empty())
1530 htmldefaultstyle_ += from_ascii("\n");
1531 htmldefaultstyle_ += from_ascii(tmp);
1535 string where = alignmentToCSS(align);
1536 if (!where.empty()) {
1537 htmldefaultstyle_ += from_ascii("text-align: " + where + ";\n");
1540 // wrap up what we have, if anything
1541 if (!htmldefaultstyle_.empty())
1543 from_ascii(htmltag() + "." + defaultCSSClass() + " {\n") +
1544 htmldefaultstyle_ + from_ascii("\n}\n");
1546 if (labeltype == LABEL_NO_LABEL || htmllabeltag() == "NONE")
1552 if (labelfont != font)
1553 labelCSS = labelfont.asCSS() + from_ascii("\n");
1554 if (labeltype == LABEL_CENTERED)
1555 labelCSS += from_ascii("text-align: center;\n");
1557 if (!labelCSS.empty())
1558 htmldefaultstyle_ +=
1559 from_ascii(htmllabeltag() + "." + defaultCSSLabelClass() + " {\n") +
1560 labelCSS + from_ascii("\n}\n");
1564 bool Layout::operator==(Layout const & rhs) const
1566 // This is enough for the applications we actually make,
1567 // at least at the moment. But we could check more.
1568 return name() == rhs.name()
1569 && latexname() == rhs.latexname()
1570 && latextype == rhs.latextype;