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 static LexerKeyword endlabelTypeTags[] = {
779 { "box", END_LABEL_BOX },
780 { "filled_box", END_LABEL_FILLED_BOX },
781 { "no_label", END_LABEL_NO_LABEL },
782 { "static", END_LABEL_STATIC }
785 PushPopHelper pph(lex, endlabelTypeTags);
788 case Lexer::LEX_UNDEF:
789 lex.printError("Unknown labeltype tag `$$Token'");
791 case END_LABEL_STATIC:
793 case END_LABEL_FILLED_BOX:
794 case END_LABEL_NO_LABEL:
795 endlabeltype = static_cast<EndLabelType>(le);
798 LYXERR0("Unhandled value " << le);
804 void Layout::readMargin(Lexer & lex)
806 LexerKeyword marginTags[] = {
807 { "dynamic", MARGIN_DYNAMIC },
808 { "first_dynamic", MARGIN_FIRST_DYNAMIC },
809 { "manual", MARGIN_MANUAL },
810 { "right_address_box", MARGIN_RIGHT_ADDRESS_BOX },
811 { "static", MARGIN_STATIC }
814 PushPopHelper pph(lex, marginTags);
818 case Lexer::LEX_UNDEF:
819 lex.printError("Unknown margin type tag `$$Token'");
824 case MARGIN_FIRST_DYNAMIC:
825 case MARGIN_RIGHT_ADDRESS_BOX:
826 margintype = static_cast<MarginType>(le);
829 LYXERR0("Unhandled value " << le);
835 void Layout::readLatexType(Lexer & lex)
837 LexerKeyword latexTypeTags[] = {
838 { "bib_environment", LATEX_BIB_ENVIRONMENT },
839 { "command", LATEX_COMMAND },
840 { "environment", LATEX_ENVIRONMENT },
841 { "item_environment", LATEX_ITEM_ENVIRONMENT },
842 { "list_environment", LATEX_LIST_ENVIRONMENT },
843 { "paragraph", LATEX_PARAGRAPH }
846 PushPopHelper pph(lex, latexTypeTags);
849 case Lexer::LEX_UNDEF:
850 lex.printError("Unknown latextype tag `$$Token'");
852 case LATEX_PARAGRAPH:
854 case LATEX_ENVIRONMENT:
855 case LATEX_ITEM_ENVIRONMENT:
856 case LATEX_BIB_ENVIRONMENT:
857 case LATEX_LIST_ENVIRONMENT:
858 latextype = static_cast<LatexType>(le);
861 LYXERR0("Unhandled value " << le);
867 void Layout::readSpacing(Lexer & lex)
870 ST_SPACING_SINGLE = 1,
876 LexerKeyword spacingTags[] = {
877 {"double", ST_SPACING_DOUBLE },
878 {"onehalf", ST_SPACING_ONEHALF },
879 {"other", ST_OTHER },
880 {"single", ST_SPACING_SINGLE }
883 PushPopHelper pph(lex, spacingTags);
886 case Lexer::LEX_UNDEF:
887 lex.printError("Unknown spacing token `$$Token'");
892 case ST_SPACING_SINGLE:
893 spacing.set(Spacing::Single);
895 case ST_SPACING_ONEHALF:
896 spacing.set(Spacing::Onehalf);
898 case ST_SPACING_DOUBLE:
899 spacing.set(Spacing::Double);
903 spacing.set(Spacing::Other, lex.getString());
909 void Layout::readArgument(Lexer & lex)
912 // writeArgument() makes use of these default values
913 arg.mandatory = false;
914 arg.autoinsert = false;
916 bool finished = false;
917 arg.font = inherit_font;
918 arg.labelfont = inherit_font;
921 bool const itemarg = prefixIs(id, "item:");
922 bool const postcmd = prefixIs(id, "post:");
924 while (!finished && lex.isOK() && !error) {
926 string const tok = ascii_lowercase(lex.getString());
930 } else if (tok == "endargument") {
932 } else if (tok == "labelstring") {
934 arg.labelstring = lex.getDocString();
935 } else if (tok == "menustring") {
937 arg.menustring = lex.getDocString();
938 } else if (tok == "mandatory") {
940 arg.mandatory = lex.getBool();
941 } else if (tok == "autoinsert") {
943 arg.autoinsert = lex.getBool();
944 } else if (tok == "leftdelim") {
946 arg.ldelim = lex.getDocString();
947 arg.ldelim = support::subst(arg.ldelim, from_ascii("<br/>"),
949 } else if (tok == "rightdelim") {
951 arg.rdelim = lex.getDocString();
952 arg.rdelim = support::subst(arg.rdelim, from_ascii("<br/>"),
954 } else if (tok == "defaultarg") {
956 arg.defaultarg = lex.getDocString();
957 } else if (tok == "presetarg") {
959 arg.presetarg = lex.getDocString();
960 } else if (tok == "tooltip") {
962 arg.tooltip = lex.getDocString();
963 } else if (tok == "requires") {
965 arg.requires = lex.getString();
966 } else if (tok == "decoration") {
968 arg.decoration = lex.getString();
969 } else if (tok == "font") {
970 arg.font = lyxRead(lex, arg.font);
971 } else if (tok == "labelfont") {
972 arg.labelfont = lyxRead(lex, arg.labelfont);
974 lex.printError("Unknown tag");
978 if (arg.labelstring.empty())
979 LYXERR0("Incomplete Argument definition!");
983 postcommandargs_[id] = arg;
985 latexargs_[id] = arg;
989 void writeArgument(ostream & os, string const & id, Layout::latexarg const & arg)
991 os << "\tArgument " << id << '\n';
992 if (!arg.labelstring.empty())
993 os << "\t\tLabelString \"" << to_utf8(arg.labelstring) << "\"\n";
994 if (!arg.menustring.empty())
995 os << "\t\tMenuString \"" << to_utf8(arg.menustring) << "\"\n";
997 os << "\t\tMandatory " << arg.mandatory << '\n';
999 os << "\t\tAutoinsert " << arg.autoinsert << '\n';
1000 if (!arg.ldelim.empty())
1001 os << "\t\tLeftDelim \""
1002 << to_utf8(subst(arg.ldelim, from_ascii("\n"), from_ascii("<br/>")))
1004 if (!arg.rdelim.empty())
1005 os << "\t\tRightDelim \""
1006 << to_utf8(subst(arg.rdelim, from_ascii("\n"), from_ascii("<br/>")))
1008 if (!arg.defaultarg.empty())
1009 os << "\t\tDefaultArg \"" << to_utf8(arg.defaultarg) << "\"\n";
1010 if (!arg.presetarg.empty())
1011 os << "\t\tPresetArg \"" << to_utf8(arg.presetarg) << "\"\n";
1012 if (!arg.tooltip.empty())
1013 os << "\t\tToolTip \"" << to_utf8(arg.tooltip) << "\"\n";
1014 if (!arg.requires.empty())
1015 os << "\t\tRequires \"" << arg.requires << "\"\n";
1016 if (!arg.decoration.empty())
1017 os << "\t\tDecoration \"" << arg.decoration << "\"\n";
1018 if (arg.font != inherit_font)
1019 lyxWrite(os, arg.font, "Font", 2);
1020 if (arg.labelfont != inherit_font)
1021 lyxWrite(os, arg.labelfont, "LabelFont", 2);
1022 os << "\tEndArgument\n";
1026 void Layout::write(ostream & os) const
1028 os << "Style " << to_utf8(name_) << '\n';
1029 if (!category_.empty() && obsoleted_by_.empty())
1030 os << "\tCategory \"" << to_utf8(category_) << "\"\n";
1031 // Can't deduce Copystyle here :-(
1032 if (!obsoleted_by_.empty()) {
1033 os << "\tObsoletedBy \"" << to_utf8(obsoleted_by_)
1037 if (!depends_on_.empty())
1038 os << "\tDependsOn " << to_utf8(depends_on_) << '\n';
1039 switch (margintype) {
1040 case MARGIN_DYNAMIC:
1041 os << "\tMargin Dynamic\n";
1043 case MARGIN_FIRST_DYNAMIC:
1044 os << "\tMargin First_Dynamic\n";
1047 os << "\tMargin Manual\n";
1049 case MARGIN_RIGHT_ADDRESS_BOX:
1050 os << "\tMargin Right_Address_Box\n";
1053 os << "\tMargin Static\n";
1056 switch (latextype) {
1057 case LATEX_BIB_ENVIRONMENT:
1058 os << "\tLatexType Bib_Environment\n";
1061 os << "\tLatexType Command\n";
1063 case LATEX_ENVIRONMENT:
1064 os << "\tLatexType Environment\n";
1066 case LATEX_ITEM_ENVIRONMENT:
1067 os << "\tLatexType Item_Environment\n";
1069 case LATEX_LIST_ENVIRONMENT:
1070 os << "\tLatexType List_Environment\n";
1072 case LATEX_PARAGRAPH:
1073 os << "\tLatexType Paragraph\n";
1076 os << "\tInTitle " << intitle << "\n"
1077 "\tInPreamble " << inpreamble << "\n"
1078 "\tTocLevel " << toclevel << '\n';
1079 // ResetArgs does not make sense here
1080 for (LaTeXArgMap::const_iterator it = latexargs_.begin();
1081 it != latexargs_.end(); ++it)
1082 writeArgument(os, it->first, it->second);
1083 for (LaTeXArgMap::const_iterator it = itemargs_.begin();
1084 it != itemargs_.end(); ++it)
1085 writeArgument(os, it->first, it->second);
1086 for (LaTeXArgMap::const_iterator it = postcommandargs_.begin();
1087 it != postcommandargs_.end(); ++it)
1088 writeArgument(os, it->first, it->second);
1089 os << "\tNeedProtect " << needprotect << "\n"
1090 "\tKeepEmpty " << keepempty << '\n';
1091 if (labelfont == font)
1092 lyxWrite(os, font, "Font", 1);
1094 lyxWrite(os, font, "TextFont", 1);
1095 lyxWrite(os, labelfont, "LabelFont", 1);
1097 os << "\tNextNoIndent " << nextnoindent << "\n"
1098 "\tCommandDepth " << commanddepth << '\n';
1099 if (!latexname_.empty())
1100 os << "\tLatexName \"" << latexname_ << "\"\n";
1101 if (!latexparam_.empty())
1102 os << "\tLatexParam \"" << subst(latexparam_, "\"", """)
1104 if (!leftdelim_.empty())
1105 os << "\tLeftDelim "
1106 << to_utf8(subst(leftdelim_, from_ascii("\n"), from_ascii("<br/>")))
1108 if (!rightdelim_.empty())
1109 os << "\tRightDelim "
1110 << to_utf8(subst(rightdelim_, from_ascii("\n"), from_ascii("<br/>")))
1112 if (!innertag_.empty())
1113 os << "\tInnerTag \"" << innertag_ << "\"\n";
1114 if (!labeltag_.empty())
1115 os << "\tLabelTag \"" << labeltag_ << "\"\n";
1116 if (!itemtag_.empty())
1117 os << "\tItemTag \"" << itemtag_ << "\"\n";
1118 if (!itemcommand_.empty())
1119 os << "\tItemCommand " << itemcommand_ << '\n';
1120 if (!preamble_.empty())
1121 os << "\tPreamble\n\t"
1122 << to_utf8(subst(rtrim(preamble_, "\n"),
1123 from_ascii("\n"), from_ascii("\n\t")))
1124 << "\n\tEndPreamble\n";
1125 if (!langpreamble_.empty())
1126 os << "\tLangPreamble\n\t"
1127 << to_utf8(subst(rtrim(langpreamble_, "\n"),
1128 from_ascii("\n"), from_ascii("\n\t")))
1129 << "\n\tEndLangPreamble\n";
1130 if (!babelpreamble_.empty())
1131 os << "\tBabelPreamble\n\t"
1132 << to_utf8(subst(rtrim(babelpreamble_, "\n"),
1133 from_ascii("\n"), from_ascii("\n\t")))
1134 << "\n\tEndBabelPreamble\n";
1135 switch (labeltype) {
1137 os << "\tLabelType Above\n";
1140 os << "\tLabelType Bibliography\n";
1142 case LABEL_CENTERED:
1143 os << "\tLabelType Centered\n";
1145 case LABEL_ENUMERATE:
1146 os << "\tLabelType Enumerate\n";
1149 os << "\tLabelType Itemize\n";
1152 os << "\tLabelType Manual\n";
1154 case LABEL_NO_LABEL:
1155 os << "\tLabelType No_Label\n";
1157 case LABEL_SENSITIVE:
1158 os << "\tLabelType Sensitive\n";
1161 os << "\tLabelType Static\n";
1164 switch (endlabeltype) {
1166 os << "\tEndLabelType Box\n";
1168 case END_LABEL_FILLED_BOX:
1169 os << "\tEndLabelType Filled_Box\n";
1171 case END_LABEL_NO_LABEL:
1172 os << "\tEndLabelType No_Label\n";
1174 case END_LABEL_STATIC:
1175 os << "\tEndLabelType Static\n";
1178 if (!leftmargin.empty())
1179 os << "\tLeftMargin \"" << to_utf8(leftmargin) << "\"\n";
1180 if (!rightmargin.empty())
1181 os << "\tRightMargin \"" << to_utf8(rightmargin) << "\"\n";
1182 if (!labelindent.empty())
1183 os << "\tLabelIndent " << to_utf8(labelindent) << '\n';
1184 if (!parindent.empty())
1185 os << "\tParIndent " << to_utf8(parindent) << '\n';
1186 os << "\tParSkip " << parskip << "\n"
1187 "\tItemSep " << itemsep << "\n"
1188 "\tTopSep " << topsep << "\n"
1189 "\tBottomSep " << bottomsep << "\n"
1190 "\tLabelBottomSep " << labelbottomsep << '\n';
1191 if (!labelsep.empty())
1192 os << "\tLabelSep " << to_utf8(subst(labelsep, ' ', 'x'))
1194 os << "\tParSep " << parsep << "\n"
1195 "\tNewLine " << newline_allowed << '\n';
1197 case LYX_ALIGN_BLOCK:
1198 os << "\tAlign Block\n";
1200 case LYX_ALIGN_CENTER:
1201 os << "\tAlign Center\n";
1203 case LYX_ALIGN_LAYOUT:
1204 os << "\tAlign Layout\n";
1206 case LYX_ALIGN_LEFT:
1207 os << "\tAlign Left\n";
1209 case LYX_ALIGN_RIGHT:
1210 os << "\tAlign Right\n";
1212 case LYX_ALIGN_DECIMAL:
1213 case LYX_ALIGN_SPECIAL:
1214 case LYX_ALIGN_NONE:
1217 if (alignpossible & (LYX_ALIGN_BLOCK | LYX_ALIGN_CENTER |
1218 LYX_ALIGN_LAYOUT | LYX_ALIGN_LEFT | LYX_ALIGN_RIGHT)) {
1220 os << "\tAlignPossible";
1221 if (alignpossible & LYX_ALIGN_BLOCK) {
1227 if (alignpossible & LYX_ALIGN_CENTER) {
1233 if (alignpossible & LYX_ALIGN_LAYOUT) {
1239 if (alignpossible & LYX_ALIGN_LEFT) {
1245 if (alignpossible & LYX_ALIGN_RIGHT) {
1253 // LabelString must come before LabelStringAppendix
1254 if (!labelstring_.empty())
1255 os << "\tLabelString \"" << to_utf8(labelstring_) << "\"\n";
1256 if (!endlabelstring_.empty())
1257 os << "\tEndLabelString \"" << to_utf8(endlabelstring_) << "\"\n";
1258 if (!labelstring_appendix_.empty() && labelstring_appendix_ != labelstring_)
1259 os << "\tLabelStringAppendix \""
1260 << to_utf8(labelstring_appendix_) << "\"\n";
1261 if (!counter.empty())
1262 os << "\tLabelCounter \"" << to_utf8(counter) << "\"\n";
1263 os << "\tFreeSpacing " << free_spacing << '\n';
1264 os << "\tPassThru " << pass_thru << '\n';
1265 os << "\tParbreakIsNewline " << parbreak_is_newline << '\n';
1266 switch (spacing.getSpace()) {
1267 case Spacing::Double:
1268 os << "\tSpacing Double\n";
1270 case Spacing::Onehalf:
1271 os << "\tSpacing Onehalf\n";
1273 case Spacing::Other:
1274 os << "\tSpacing Other " << spacing.getValueAsString() << '\n';
1276 case Spacing::Single:
1277 os << "\tSpacing Single\n";
1279 case Spacing::Default:
1282 if (!requires_.empty()) {
1283 os << "\tRequires ";
1284 for (set<string>::const_iterator it = requires_.begin();
1285 it != requires_.end(); ++it) {
1286 if (it != requires_.begin())
1292 if (refprefix.empty())
1293 os << "\tRefPrefix OFF\n";
1295 os << "\tRefPrefix " << to_utf8(refprefix) << '\n';
1296 if (!htmltag_.empty())
1297 os << "\tHTMLTag " << htmltag_ << '\n';
1298 if (!htmlattr_.empty())
1299 os << "\tHTMLAttr " << htmlattr_ << '\n';
1300 if (!htmlitemtag_.empty())
1301 os << "\tHTMLItem " << htmlitemtag_ << '\n';
1302 if (!htmlitemattr_.empty())
1303 os << "\tHTMLItemAttr " << htmlitemattr_ << '\n';
1304 if (!htmllabeltag_.empty())
1305 os << "\tHTMLLabel " << htmllabeltag_ << '\n';
1306 if (!htmllabelattr_.empty())
1307 os << "\tHTMLLabelAttr " << htmllabelattr_ << '\n';
1308 os << "\tHTMLLabelFirst " << htmllabelfirst_ << '\n';
1309 if (!htmlstyle_.empty())
1310 os << "\tHTMLStyle\n"
1311 << to_utf8(rtrim(htmlstyle_, "\n"))
1312 << "\n\tEndHTMLStyle\n";
1313 os << "\tHTMLForceCSS " << htmlforcecss_ << '\n';
1314 if (!htmlpreamble_.empty())
1315 os << "\tHTMLPreamble\n"
1316 << to_utf8(rtrim(htmlpreamble_, "\n"))
1317 << "\n\tEndPreamble\n";
1318 os << "\tHTMLTitle " << htmltitle_ << "\n"
1319 "\tSpellcheck " << spellcheck << "\n"
1320 "\tForceLocal " << forcelocal << "\n"
1325 Layout::LaTeXArgMap Layout::args() const
1327 LaTeXArgMap args = latexargs_;
1328 if (!postcommandargs_.empty())
1329 args.insert(postcommandargs_.begin(), postcommandargs_.end());
1330 if (!itemargs_.empty())
1331 args.insert(itemargs_.begin(), itemargs_.end());
1336 int Layout::optArgs() const
1339 LaTeXArgMap::const_iterator it = latexargs_.begin();
1340 for (; it != latexargs_.end(); ++it) {
1341 if (!(*it).second.mandatory)
1344 LaTeXArgMap::const_iterator iit = postcommandargs_.begin();
1345 for (; iit != postcommandargs_.end(); ++iit) {
1346 if (!(*iit).second.mandatory)
1353 int Layout::requiredArgs() const
1356 LaTeXArgMap::const_iterator it = latexargs_.begin();
1357 for (; it != latexargs_.end(); ++it) {
1358 if ((*it).second.mandatory)
1361 LaTeXArgMap::const_iterator iit = postcommandargs_.begin();
1362 for (; iit != postcommandargs_.end(); ++iit) {
1363 if (!(*iit).second.mandatory)
1370 string const & Layout::htmltag() const
1372 if (htmltag_.empty())
1378 string const & Layout::htmlattr() const
1380 if (htmlattr_.empty())
1381 htmlattr_ = "class=\"" + defaultCSSClass() + "\"";
1386 string const & Layout::htmlitemtag() const
1388 if (htmlitemtag_.empty())
1389 htmlitemtag_ = "div";
1390 return htmlitemtag_;
1394 string const & Layout::htmlitemattr() const
1396 if (htmlitemattr_.empty())
1397 htmlitemattr_ = "class=\"" + defaultCSSItemClass() + "\"";
1398 return htmlitemattr_;
1402 string const & Layout::htmllabeltag() const
1404 if (htmllabeltag_.empty()) {
1405 if (labeltype != LABEL_ABOVE &&
1406 labeltype != LABEL_CENTERED)
1407 htmllabeltag_ = "span";
1409 htmllabeltag_ = "div";
1411 return htmllabeltag_;
1415 string const & Layout::htmllabelattr() const
1417 if (htmllabelattr_.empty())
1418 htmllabelattr_ = "class=\"" + defaultCSSLabelClass() + "\"";
1419 return htmllabelattr_;
1423 docstring Layout::htmlstyle() const
1425 if (!htmlstyle_.empty() && !htmlforcecss_)
1427 if (htmldefaultstyle_.empty())
1429 docstring retval = htmldefaultstyle_;
1430 if (!htmlstyle_.empty())
1431 retval += '\n' + htmlstyle_;
1436 string Layout::defaultCSSClass() const
1438 if (!defaultcssclass_.empty())
1439 return defaultcssclass_;
1441 docstring::const_iterator it = name().begin();
1442 docstring::const_iterator en = name().end();
1443 for (; it != en; ++it) {
1444 char_type const c = *it;
1445 if (!isAlphaASCII(c)) {
1447 // make sure we don't start with an underscore,
1448 // as that sometimes causes problems.
1449 d = from_ascii("lyx_");
1452 } else if (isLower(c))
1455 // this is slow, so do it only if necessary
1458 defaultcssclass_ = to_utf8(d);
1459 return defaultcssclass_;
1465 string makeMarginValue(char const * side, double d)
1468 os << "margin-" << side << ": " << d << "ex;\n";
1475 void Layout::makeDefaultCSS() const
1477 // this never needs to be redone, since reloading layouts will
1478 // wipe out what we did before.
1479 if (!htmldefaultstyle_.empty())
1483 htmldefaultstyle_ = font.asCSS();
1488 tmp += makeMarginValue("top", topsep);
1490 tmp += makeMarginValue("bottom", bottomsep);
1491 if (!leftmargin.empty()) {
1492 // we can't really do what LyX does with the margin, so
1493 // we'll just figure out how many characters it is
1494 int const len = leftmargin.length();
1495 tmp += makeMarginValue("left", len);
1497 if (!rightmargin.empty()) {
1498 int const len = rightmargin.length();
1499 tmp += makeMarginValue("right", len);
1503 if (!htmldefaultstyle_.empty())
1504 htmldefaultstyle_ += from_ascii("\n");
1505 htmldefaultstyle_ += from_ascii(tmp);
1508 // tex2lyx does not see output_xhtml.cpp
1509 #ifndef NO_LAYOUT_CSS
1511 string where = alignmentToCSS(align);
1512 if (!where.empty()) {
1513 htmldefaultstyle_ += from_ascii("text-align: " + where + ";\n");
1517 // wrap up what we have, if anything
1518 if (!htmldefaultstyle_.empty())
1520 from_ascii(htmltag() + "." + defaultCSSClass() + " {\n") +
1521 htmldefaultstyle_ + from_ascii("\n}\n");
1523 if (labeltype == LABEL_NO_LABEL || htmllabeltag() == "NONE")
1529 if (labelfont != font)
1530 labelCSS = labelfont.asCSS() + from_ascii("\n");
1531 if (labeltype == LABEL_CENTERED)
1532 labelCSS += from_ascii("text-align: center;\n");
1534 if (!labelCSS.empty())
1535 htmldefaultstyle_ +=
1536 from_ascii(htmllabeltag() + "." + defaultCSSLabelClass() + " {\n") +
1537 labelCSS + from_ascii("\n}\n");
1541 bool Layout::operator==(Layout const & rhs) const
1543 // This is enough for the applications we actually make,
1544 // at least at the moment. But we could check more.
1545 return name() == rhs.name()
1546 && latexname() == rhs.latexname()
1547 && latextype == rhs.latextype;