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,
113 LT_INTITLE // keep this last!
116 /////////////////////
119 : add_to_toc_(false), is_toc_caption_(false)
122 margintype = MARGIN_STATIC;
123 latextype = LATEX_PARAGRAPH;
129 labelfont = inherit_font;
131 reslabelfont = sane_font;
132 nextnoindent = false;
137 labelbottomsep = 0.0;
139 align = LYX_ALIGN_BLOCK;
140 alignpossible = LYX_ALIGN_NONE | LYX_ALIGN_LAYOUT;
141 labeltype = LABEL_NO_LABEL;
142 endlabeltype = END_LABEL_NO_LABEL;
143 // Should or should not. That is the question.
144 // spacing.set(Spacing::OneHalf);
145 newline_allowed = true;
146 free_spacing = false;
148 parbreak_is_newline = false;
149 toclevel = NOT_IN_TOC;
151 htmllabelfirst_ = false;
152 htmlforcecss_ = false;
156 itemcommand_ = "item";
157 toggle_indent = ITOGGLE_DOCUMENT_DEFAULT;
162 bool Layout::read(Lexer & lex, TextClass const & tclass)
164 // If this is an empty layout, or if no force local version is set,
165 // we know that we will not discard the stuff to read
167 return readIgnoreForcelocal(lex, tclass);
170 bool const ret = tmp.readIgnoreForcelocal(lex, tclass);
172 // - the read version is higher
173 // - both versions are infinity (arbitrary decision)
174 // - the file did not contain any local version (needed for not
175 // skipping user defined local layouts)
176 if (tmp.forcelocal <= 0 || tmp.forcelocal > forcelocal)
182 bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass)
184 // This table is sorted alphabetically [asierra 30March96]
185 LexerKeyword layoutTags[] = {
186 { "addtotoc", LT_ADDTOTOC },
187 { "align", LT_ALIGN },
188 { "alignpossible", LT_ALIGNPOSSIBLE },
189 { "argument", LT_ARGUMENT },
190 { "babelpreamble", LT_BABELPREAMBLE },
191 { "bottomsep", LT_BOTTOMSEP },
192 { "category", LT_CATEGORY },
193 { "commanddepth", LT_COMMANDDEPTH },
194 { "copystyle", LT_COPYSTYLE },
195 { "dependson", LT_DEPENDSON },
197 { "endlabelstring", LT_ENDLABELSTRING },
198 { "endlabeltype", LT_ENDLABELTYPE },
200 { "forcelocal", LT_FORCELOCAL },
201 { "freespacing", LT_FREE_SPACING },
202 { "htmlattr", LT_HTMLATTR },
203 { "htmlforcecss", LT_HTMLFORCECSS },
204 { "htmlitem", LT_HTMLITEM },
205 { "htmlitemattr", LT_HTMLITEMATTR },
206 { "htmllabel", LT_HTMLLABEL },
207 { "htmllabelattr", LT_HTMLLABELATTR },
208 { "htmllabelfirst", LT_HTMLLABELFIRST },
209 { "htmlpreamble", LT_HTMLPREAMBLE },
210 { "htmlstyle", LT_HTMLSTYLE },
211 { "htmltag", LT_HTMLTAG },
212 { "htmltitle", LT_HTMLTITLE },
213 { "innertag", LT_INNERTAG },
214 { "inpreamble", LT_INPREAMBLE },
215 { "intitle", LT_INTITLE },
216 { "istoccaption", LT_ISTOCCAPTION },
217 { "itemcommand", LT_ITEMCOMMAND },
218 { "itemsep", LT_ITEMSEP },
219 { "itemtag", LT_ITEMTAG },
220 { "keepempty", LT_KEEPEMPTY },
221 { "labelbottomsep", LT_LABEL_BOTTOMSEP },
222 { "labelcounter", LT_LABELCOUNTER },
223 { "labelfont", LT_LABELFONT },
224 { "labelindent", LT_LABELINDENT },
225 { "labelsep", LT_LABELSEP },
226 { "labelstring", LT_LABELSTRING },
227 { "labelstringappendix", LT_LABELSTRING_APPENDIX },
228 { "labeltag", LT_LABELTAG },
229 { "labeltype", LT_LABELTYPE },
230 { "langpreamble", LT_LANGPREAMBLE },
231 { "latexname", LT_LATEXNAME },
232 { "latexparam", LT_LATEXPARAM },
233 { "latextype", LT_LATEXTYPE },
234 { "leftdelim", LT_LEFTDELIM },
235 { "leftmargin", LT_LEFTMARGIN },
236 { "margin", LT_MARGIN },
237 { "needprotect", LT_NEED_PROTECT },
238 { "newline", LT_NEWLINE },
239 { "nextnoindent", LT_NEXTNOINDENT },
240 { "obsoletedby", LT_OBSOLETEDBY },
241 { "paragraphgroup", LT_PAR_GROUP },
242 { "parbreakisnewline", LT_PARBREAK_IS_NEWLINE },
243 { "parindent", LT_PARINDENT },
244 { "parsep", LT_PARSEP },
245 { "parskip", LT_PARSKIP },
246 { "passthru", LT_PASS_THRU },
247 { "passthruchars", LT_PASS_THRU_CHARS },
248 { "preamble", LT_PREAMBLE },
249 { "refprefix", LT_REFPREFIX },
250 { "requires", LT_REQUIRES },
251 { "resetargs", LT_RESETARGS },
252 { "rightdelim", LT_RIGHTDELIM },
253 { "rightmargin", LT_RIGHTMARGIN },
254 { "spacing", LT_SPACING },
255 { "spellcheck", LT_SPELLCHECK },
256 { "textfont", LT_TEXTFONT },
257 { "toclevel", LT_TOCLEVEL },
258 { "toggleindent", LT_TOGGLE_INDENT },
259 { "topsep", LT_TOPSEP }
263 bool finished = false;
264 lex.pushTable(layoutTags);
266 // parse style section
267 while (!finished && lex.isOK() && !error) {
269 // See comment in LyXRC.cpp.
271 case Lexer::LEX_FEOF:
274 case Lexer::LEX_UNDEF:
276 lex.printError("Unknown layout tag `$$Token'");
283 switch (static_cast<LayoutTags>(le)) {
295 style = subst(style, '_', ' ');
297 if (tclass.hasLayout(style)) {
298 docstring const tmpname = name_;
299 this->operator=(tclass[style]);
302 LYXERR0("Cannot copy unknown style `"
304 << "All layouts so far:");
305 DocumentClass::const_iterator lit = tclass.begin();
306 DocumentClass::const_iterator len = tclass.end();
307 for (; lit != len; ++lit)
308 LYXERR0(lit->name());
313 case LT_OBSOLETEDBY: {
316 style = subst(style, '_', ' ');
318 if (tclass.hasLayout(style)) {
319 docstring const tmpname = name_;
320 this->operator=(tclass[style]);
322 if (obsoleted_by().empty())
323 obsoleted_by_ = style;
325 LYXERR0("Cannot replace with unknown style `"
328 //lex.printError("Cannot replace with"
337 depends_on_ = subst(depends_on_, '_', ' ');
366 postcommandargs_.clear();
374 case LT_NEED_PROTECT:
383 font = lyxRead(lex, font);
388 font = lyxRead(lex, font);
392 labelfont = lyxRead(lex, labelfont);
395 case LT_NEXTNOINDENT:
399 case LT_TOGGLE_INDENT: {
402 tog = support::ascii_lowercase(tog);
404 toggle_indent = ITOGGLE_ALWAYS;
405 else if (tog == "never")
406 toggle_indent = ITOGGLE_NEVER;
408 toggle_indent = ITOGGLE_DOCUMENT_DEFAULT;
412 case LT_COMMANDDEPTH:
422 latexparam_ = subst(latexparam_, """, "\"");
427 leftdelim_ = support::subst(leftdelim_, from_ascii("<br/>"),
433 rightdelim_ = support::subst(rightdelim_, from_ascii("<br/>"),
454 preamble_ = from_utf8(lex.getLongString("EndPreamble"));
457 case LT_LANGPREAMBLE:
458 langpreamble_ = from_utf8(lex.getLongString("EndLangPreamble"));
461 case LT_BABELPREAMBLE:
462 babelpreamble_ = from_utf8(lex.getLongString("EndBabelPreamble"));
469 case LT_ENDLABELTYPE:
470 readEndLabelType(lex);
505 case LT_LABEL_BOTTOMSEP:
506 lex >> labelbottomsep;
511 labelsep = subst(labelsep, 'x', ' ');
519 lex >> newline_allowed;
526 case LT_ALIGNPOSSIBLE:
527 readAlignPossible(lex);
531 // FIXME: this means LT_LABELSTRING_APPENDIX may only
532 // occur after LT_LABELSTRING
534 labelstring_ = trim(labelstring_);
535 labelstring_appendix_ = labelstring_;
538 case LT_ENDLABELSTRING:
539 lex >> endlabelstring_;
540 endlabelstring_ = trim(endlabelstring_);
543 case LT_LABELSTRING_APPENDIX:
544 lex >> labelstring_appendix_;
545 labelstring_appendix_ = trim(labelstring_appendix_);
548 case LT_LABELCOUNTER:
550 counter = trim(counter);
557 case LT_FREE_SPACING:
565 case LT_PASS_THRU_CHARS:
566 lex >> pass_thru_chars;
569 case LT_PARBREAK_IS_NEWLINE:
570 lex >> parbreak_is_newline;
579 vector<string> const req =
580 getVectorFromString(lex.getString(true));
581 requires_.insert(req.begin(), req.end());
607 case LT_HTMLITEMATTR:
608 lex >> htmlitemattr_;
612 lex >> htmllabeltag_;
615 case LT_HTMLLABELATTR:
616 lex >> htmllabelattr_;
619 case LT_HTMLLABELFIRST:
620 lex >> htmllabelfirst_;
624 htmlstyle_ = from_utf8(lex.getLongString("EndHTMLStyle"));
627 case LT_HTMLFORCECSS:
628 lex >> htmlforcecss_;
631 case LT_HTMLPREAMBLE:
632 htmlpreamble_ = from_utf8(lex.getLongString("EndPreamble"));
649 add_to_toc_ = !toc_type_.empty();
652 case LT_ISTOCCAPTION:
653 lex >> is_toc_caption_;
659 // make sure we only have inpreamble = true for commands
660 if (inpreamble && latextype != LATEX_COMMAND && latextype != LATEX_PARAGRAPH) {
661 LYXERR0("InPreamble not permitted except with command and paragraph layouts.");
662 LYXERR0("Layout name: " << name());
666 return finished && !error;
679 LexerKeyword alignTags[] = {
680 { "block", AT_BLOCK },
681 { "center", AT_CENTER },
682 { "layout", AT_LAYOUT },
684 { "right", AT_RIGHT }
688 void Layout::readAlign(Lexer & lex)
690 PushPopHelper pph(lex, alignTags);
693 case Lexer::LEX_UNDEF:
694 lex.printError("Unknown alignment `$$Token'");
700 align = LYX_ALIGN_BLOCK;
703 align = LYX_ALIGN_LEFT;
706 align = LYX_ALIGN_RIGHT;
709 align = LYX_ALIGN_CENTER;
712 align = LYX_ALIGN_LAYOUT;
718 void Layout::readAlignPossible(Lexer & lex)
720 lex.pushTable(alignTags);
721 alignpossible = LYX_ALIGN_NONE | LYX_ALIGN_LAYOUT;
722 int lineno = lex.lineNumber();
726 case Lexer::LEX_UNDEF:
727 lex.printError("Unknown alignment `$$Token'");
733 alignpossible |= LYX_ALIGN_BLOCK;
736 alignpossible |= LYX_ALIGN_LEFT;
739 alignpossible |= LYX_ALIGN_RIGHT;
742 alignpossible |= LYX_ALIGN_CENTER;
745 alignpossible |= LYX_ALIGN_LAYOUT;
748 } while (lineno == lex.lineNumber());
753 void Layout::readLabelType(Lexer & lex)
768 LexerKeyword labelTypeTags[] = {
769 { "above", LA_ABOVE },
770 { "bibliography", LA_BIBLIO },
771 { "centered", LA_CENTERED },
772 { "enumerate", LA_ENUMERATE },
773 { "itemize", LA_ITEMIZE },
774 { "manual", LA_MANUAL },
775 { "no_label", LA_NO_LABEL },
776 { "sensitive", LA_SENSITIVE },
777 { "static", LA_STATIC }
780 PushPopHelper pph(lex, labelTypeTags);
783 case Lexer::LEX_UNDEF:
784 lex.printError("Unknown labeltype tag `$$Token'");
790 labeltype = LABEL_NO_LABEL;
793 labeltype = LABEL_MANUAL;
796 labeltype = LABEL_ABOVE;
799 labeltype = LABEL_CENTERED;
802 labeltype = LABEL_STATIC;
805 labeltype = LABEL_SENSITIVE;
808 labeltype = LABEL_ENUMERATE;
811 labeltype = LABEL_ITEMIZE;
814 labeltype = LABEL_BIBLIO;
820 void Layout::readEndLabelType(Lexer & lex)
822 // this should be const, but can't be because
824 static LexerKeyword endlabelTypeTags[] = {
825 { "box", END_LABEL_BOX },
826 { "filled_box", END_LABEL_FILLED_BOX },
827 { "no_label", END_LABEL_NO_LABEL },
828 { "static", END_LABEL_STATIC }
831 PushPopHelper pph(lex, endlabelTypeTags);
834 case Lexer::LEX_UNDEF:
835 lex.printError("Unknown labeltype tag `$$Token'");
837 case END_LABEL_STATIC:
839 case END_LABEL_FILLED_BOX:
840 case END_LABEL_NO_LABEL:
841 endlabeltype = static_cast<EndLabelType>(le);
844 LYXERR0("Unhandled value " << le);
850 void Layout::readMargin(Lexer & lex)
852 LexerKeyword marginTags[] = {
853 { "dynamic", MARGIN_DYNAMIC },
854 { "first_dynamic", MARGIN_FIRST_DYNAMIC },
855 { "manual", MARGIN_MANUAL },
856 { "right_address_box", MARGIN_RIGHT_ADDRESS_BOX },
857 { "static", MARGIN_STATIC }
860 PushPopHelper pph(lex, marginTags);
864 case Lexer::LEX_UNDEF:
865 lex.printError("Unknown margin type tag `$$Token'");
870 case MARGIN_FIRST_DYNAMIC:
871 case MARGIN_RIGHT_ADDRESS_BOX:
872 margintype = static_cast<MarginType>(le);
875 LYXERR0("Unhandled value " << le);
881 void Layout::readLatexType(Lexer & lex)
883 LexerKeyword latexTypeTags[] = {
884 { "bib_environment", LATEX_BIB_ENVIRONMENT },
885 { "command", LATEX_COMMAND },
886 { "environment", LATEX_ENVIRONMENT },
887 { "item_environment", LATEX_ITEM_ENVIRONMENT },
888 { "list_environment", LATEX_LIST_ENVIRONMENT },
889 { "paragraph", LATEX_PARAGRAPH }
892 PushPopHelper pph(lex, latexTypeTags);
895 case Lexer::LEX_UNDEF:
896 lex.printError("Unknown latextype tag `$$Token'");
898 case LATEX_PARAGRAPH:
900 case LATEX_ITEM_ENVIRONMENT:
901 case LATEX_LIST_ENVIRONMENT:
902 latextype = static_cast<LatexType>(le);
904 case LATEX_ENVIRONMENT:
905 case LATEX_BIB_ENVIRONMENT:
906 latextype = static_cast<LatexType>(le);
910 LYXERR0("Unhandled value " << le);
916 void Layout::readSpacing(Lexer & lex)
919 ST_SPACING_SINGLE = 1,
925 LexerKeyword spacingTags[] = {
926 {"double", ST_SPACING_DOUBLE },
927 {"onehalf", ST_SPACING_ONEHALF },
928 {"other", ST_OTHER },
929 {"single", ST_SPACING_SINGLE }
932 PushPopHelper pph(lex, spacingTags);
935 case Lexer::LEX_UNDEF:
936 lex.printError("Unknown spacing token `$$Token'");
941 case ST_SPACING_SINGLE:
942 spacing.set(Spacing::Single);
944 case ST_SPACING_ONEHALF:
945 spacing.set(Spacing::Onehalf);
947 case ST_SPACING_DOUBLE:
948 spacing.set(Spacing::Double);
952 spacing.set(Spacing::Other, lex.getString());
958 void Layout::readArgument(Lexer & lex)
961 // writeArgument() makes use of these default values
962 arg.mandatory = false;
963 arg.autoinsert = false;
964 arg.insertcotext = false;
966 bool finished = false;
967 arg.font = inherit_font;
968 arg.labelfont = inherit_font;
969 arg.is_toc_caption = false;
972 bool const itemarg = prefixIs(id, "item:");
973 bool const postcmd = prefixIs(id, "post:");
975 while (!finished && lex.isOK() && !error) {
977 string const tok = ascii_lowercase(lex.getString());
981 } else if (tok == "endargument") {
983 } else if (tok == "labelstring") {
985 arg.labelstring = lex.getDocString();
986 } else if (tok == "menustring") {
988 arg.menustring = lex.getDocString();
989 } else if (tok == "mandatory") {
991 arg.mandatory = lex.getBool();
992 } else if (tok == "autoinsert") {
994 arg.autoinsert = lex.getBool();
995 } else if (tok == "insertcotext") {
997 arg.insertcotext = lex.getBool();
998 } else if (tok == "leftdelim") {
1000 arg.ldelim = lex.getDocString();
1001 arg.ldelim = support::subst(arg.ldelim, from_ascii("<br/>"),
1003 } else if (tok == "rightdelim") {
1005 arg.rdelim = lex.getDocString();
1006 arg.rdelim = support::subst(arg.rdelim, from_ascii("<br/>"),
1008 } else if (tok == "defaultarg") {
1010 arg.defaultarg = lex.getDocString();
1011 } else if (tok == "presetarg") {
1013 arg.presetarg = lex.getDocString();
1014 } else if (tok == "tooltip") {
1016 arg.tooltip = lex.getDocString();
1017 } else if (tok == "requires") {
1019 arg.requires = lex.getString();
1020 } else if (tok == "decoration") {
1022 arg.decoration = lex.getString();
1023 } else if (tok == "font") {
1024 arg.font = lyxRead(lex, arg.font);
1025 } else if (tok == "labelfont") {
1026 arg.labelfont = lyxRead(lex, arg.labelfont);
1027 } else if (tok == "passthruchars") {
1029 arg.pass_thru_chars = lex.getDocString();
1030 } else if (tok == "istoccaption") {
1032 arg.is_toc_caption = lex.getBool();
1034 lex.printError("Unknown tag");
1038 if (arg.labelstring.empty())
1039 LYXERR0("Incomplete Argument definition!");
1041 itemargs_[id] = arg;
1043 postcommandargs_[id] = arg;
1045 latexargs_[id] = arg;
1049 void writeArgument(ostream & os, string const & id, Layout::latexarg const & arg)
1051 os << "\tArgument " << id << '\n';
1052 if (!arg.labelstring.empty())
1053 os << "\t\tLabelString \"" << to_utf8(arg.labelstring) << "\"\n";
1054 if (!arg.menustring.empty())
1055 os << "\t\tMenuString \"" << to_utf8(arg.menustring) << "\"\n";
1057 os << "\t\tMandatory " << arg.mandatory << '\n';
1059 os << "\t\tAutoinsert " << arg.autoinsert << '\n';
1060 if (arg.insertcotext)
1061 os << "\t\tInsertCotext " << arg.insertcotext << '\n';
1062 if (!arg.ldelim.empty())
1063 os << "\t\tLeftDelim \""
1064 << to_utf8(subst(arg.ldelim, from_ascii("\n"), from_ascii("<br/>")))
1066 if (!arg.rdelim.empty())
1067 os << "\t\tRightDelim \""
1068 << to_utf8(subst(arg.rdelim, from_ascii("\n"), from_ascii("<br/>")))
1070 if (!arg.defaultarg.empty())
1071 os << "\t\tDefaultArg \"" << to_utf8(arg.defaultarg) << "\"\n";
1072 if (!arg.presetarg.empty())
1073 os << "\t\tPresetArg \"" << to_utf8(arg.presetarg) << "\"\n";
1074 if (!arg.tooltip.empty())
1075 os << "\t\tToolTip \"" << to_utf8(arg.tooltip) << "\"\n";
1076 if (!arg.requires.empty())
1077 os << "\t\tRequires \"" << arg.requires << "\"\n";
1078 if (!arg.decoration.empty())
1079 os << "\t\tDecoration \"" << arg.decoration << "\"\n";
1080 if (arg.font != inherit_font)
1081 lyxWrite(os, arg.font, "Font", 2);
1082 if (arg.labelfont != inherit_font)
1083 lyxWrite(os, arg.labelfont, "LabelFont", 2);
1084 if (!arg.pass_thru_chars.empty())
1085 os << "\t\tPassThruChars \"" << to_utf8(arg.pass_thru_chars) << "\"\n";
1086 os << "\tEndArgument\n";
1090 void Layout::write(ostream & os) const
1092 os << "Style " << to_utf8(name_) << '\n';
1093 if (!category_.empty() && obsoleted_by_.empty())
1094 os << "\tCategory \"" << to_utf8(category_) << "\"\n";
1095 // Can't deduce Copystyle here :-(
1096 if (!obsoleted_by_.empty()) {
1097 os << "\tObsoletedBy \"" << to_utf8(obsoleted_by_)
1101 if (!depends_on_.empty())
1102 os << "\tDependsOn " << to_utf8(depends_on_) << '\n';
1103 switch (margintype) {
1104 case MARGIN_DYNAMIC:
1105 os << "\tMargin Dynamic\n";
1107 case MARGIN_FIRST_DYNAMIC:
1108 os << "\tMargin First_Dynamic\n";
1111 os << "\tMargin Manual\n";
1113 case MARGIN_RIGHT_ADDRESS_BOX:
1114 os << "\tMargin Right_Address_Box\n";
1117 os << "\tMargin Static\n";
1120 switch (latextype) {
1121 case LATEX_BIB_ENVIRONMENT:
1122 os << "\tLatexType Bib_Environment\n";
1125 os << "\tLatexType Command\n";
1127 case LATEX_ENVIRONMENT:
1128 os << "\tLatexType Environment\n";
1130 case LATEX_ITEM_ENVIRONMENT:
1131 os << "\tLatexType Item_Environment\n";
1133 case LATEX_LIST_ENVIRONMENT:
1134 os << "\tLatexType List_Environment\n";
1136 case LATEX_PARAGRAPH:
1137 os << "\tLatexType Paragraph\n";
1140 os << "\tInTitle " << intitle << "\n"
1141 "\tInPreamble " << inpreamble << "\n"
1142 "\tTocLevel " << toclevel << '\n';
1143 // ResetArgs does not make sense here
1144 for (LaTeXArgMap::const_iterator it = latexargs_.begin();
1145 it != latexargs_.end(); ++it)
1146 writeArgument(os, it->first, it->second);
1147 for (LaTeXArgMap::const_iterator it = itemargs_.begin();
1148 it != itemargs_.end(); ++it)
1149 writeArgument(os, it->first, it->second);
1150 for (LaTeXArgMap::const_iterator it = postcommandargs_.begin();
1151 it != postcommandargs_.end(); ++it)
1152 writeArgument(os, it->first, it->second);
1153 os << "\tNeedProtect " << needprotect << "\n"
1154 "\tKeepEmpty " << keepempty << '\n';
1155 if (labelfont == font)
1156 lyxWrite(os, font, "Font", 1);
1158 lyxWrite(os, font, "TextFont", 1);
1159 lyxWrite(os, labelfont, "LabelFont", 1);
1161 os << "\tNextNoIndent " << nextnoindent << "\n"
1162 "\tCommandDepth " << commanddepth << '\n';
1163 if (!latexname_.empty())
1164 os << "\tLatexName \"" << latexname_ << "\"\n";
1165 if (!latexparam_.empty())
1166 os << "\tLatexParam \"" << subst(latexparam_, "\"", """)
1168 if (!leftdelim_.empty())
1169 os << "\tLeftDelim "
1170 << to_utf8(subst(leftdelim_, from_ascii("\n"), from_ascii("<br/>")))
1172 if (!rightdelim_.empty())
1173 os << "\tRightDelim "
1174 << to_utf8(subst(rightdelim_, from_ascii("\n"), from_ascii("<br/>")))
1176 if (!innertag_.empty())
1177 os << "\tInnerTag \"" << innertag_ << "\"\n";
1178 if (!labeltag_.empty())
1179 os << "\tLabelTag \"" << labeltag_ << "\"\n";
1180 if (!itemtag_.empty())
1181 os << "\tItemTag \"" << itemtag_ << "\"\n";
1182 if (!itemcommand_.empty())
1183 os << "\tItemCommand " << itemcommand_ << '\n';
1184 if (!preamble_.empty())
1185 os << "\tPreamble\n\t"
1186 << to_utf8(subst(rtrim(preamble_, "\n"),
1187 from_ascii("\n"), from_ascii("\n\t")))
1188 << "\n\tEndPreamble\n";
1189 if (!langpreamble_.empty())
1190 os << "\tLangPreamble\n\t"
1191 << to_utf8(subst(rtrim(langpreamble_, "\n"),
1192 from_ascii("\n"), from_ascii("\n\t")))
1193 << "\n\tEndLangPreamble\n";
1194 if (!babelpreamble_.empty())
1195 os << "\tBabelPreamble\n\t"
1196 << to_utf8(subst(rtrim(babelpreamble_, "\n"),
1197 from_ascii("\n"), from_ascii("\n\t")))
1198 << "\n\tEndBabelPreamble\n";
1199 switch (labeltype) {
1201 os << "\tLabelType Above\n";
1204 os << "\tLabelType Bibliography\n";
1206 case LABEL_CENTERED:
1207 os << "\tLabelType Centered\n";
1209 case LABEL_ENUMERATE:
1210 os << "\tLabelType Enumerate\n";
1213 os << "\tLabelType Itemize\n";
1216 os << "\tLabelType Manual\n";
1218 case LABEL_NO_LABEL:
1219 os << "\tLabelType No_Label\n";
1221 case LABEL_SENSITIVE:
1222 os << "\tLabelType Sensitive\n";
1225 os << "\tLabelType Static\n";
1228 switch (endlabeltype) {
1230 os << "\tEndLabelType Box\n";
1232 case END_LABEL_FILLED_BOX:
1233 os << "\tEndLabelType Filled_Box\n";
1235 case END_LABEL_NO_LABEL:
1236 os << "\tEndLabelType No_Label\n";
1238 case END_LABEL_STATIC:
1239 os << "\tEndLabelType Static\n";
1242 os << "\tParagraphGroup \"" << par_group_ << "\"\n";
1243 if (!leftmargin.empty())
1244 os << "\tLeftMargin \"" << to_utf8(leftmargin) << "\"\n";
1245 if (!rightmargin.empty())
1246 os << "\tRightMargin \"" << to_utf8(rightmargin) << "\"\n";
1247 if (!labelindent.empty())
1248 os << "\tLabelIndent " << to_utf8(labelindent) << '\n';
1249 if (!parindent.empty())
1250 os << "\tParIndent " << to_utf8(parindent) << '\n';
1251 os << "\tParSkip " << parskip << "\n"
1252 "\tItemSep " << itemsep << "\n"
1253 "\tTopSep " << topsep << "\n"
1254 "\tBottomSep " << bottomsep << "\n"
1255 "\tLabelBottomSep " << labelbottomsep << '\n';
1256 if (!labelsep.empty())
1257 os << "\tLabelSep " << to_utf8(subst(labelsep, ' ', 'x'))
1259 os << "\tParSep " << parsep << "\n"
1260 "\tNewLine " << newline_allowed << '\n';
1262 case LYX_ALIGN_BLOCK:
1263 os << "\tAlign Block\n";
1265 case LYX_ALIGN_CENTER:
1266 os << "\tAlign Center\n";
1268 case LYX_ALIGN_LAYOUT:
1269 os << "\tAlign Layout\n";
1271 case LYX_ALIGN_LEFT:
1272 os << "\tAlign Left\n";
1274 case LYX_ALIGN_RIGHT:
1275 os << "\tAlign Right\n";
1277 case LYX_ALIGN_DECIMAL:
1278 case LYX_ALIGN_SPECIAL:
1279 case LYX_ALIGN_NONE:
1282 if (alignpossible & (LYX_ALIGN_BLOCK | LYX_ALIGN_CENTER |
1283 LYX_ALIGN_LAYOUT | LYX_ALIGN_LEFT | LYX_ALIGN_RIGHT)) {
1285 os << "\tAlignPossible";
1286 if (alignpossible & LYX_ALIGN_BLOCK) {
1290 if (alignpossible & LYX_ALIGN_CENTER) {
1296 if (alignpossible & LYX_ALIGN_LAYOUT) {
1302 if (alignpossible & LYX_ALIGN_LEFT) {
1308 if (alignpossible & LYX_ALIGN_RIGHT) {
1316 // LabelString must come before LabelStringAppendix
1317 if (!labelstring_.empty())
1318 os << "\tLabelString \"" << to_utf8(labelstring_) << "\"\n";
1319 if (!endlabelstring_.empty())
1320 os << "\tEndLabelString \"" << to_utf8(endlabelstring_) << "\"\n";
1321 if (!labelstring_appendix_.empty() && labelstring_appendix_ != labelstring_)
1322 os << "\tLabelStringAppendix \""
1323 << to_utf8(labelstring_appendix_) << "\"\n";
1324 if (!counter.empty())
1325 os << "\tLabelCounter \"" << to_utf8(counter) << "\"\n";
1326 os << "\tFreeSpacing " << free_spacing << '\n';
1327 os << "\tPassThru " << pass_thru << '\n';
1328 if (!pass_thru_chars.empty())
1329 os << "\tPassThruChars " << to_utf8(pass_thru_chars) << '\n';
1330 os << "\tParbreakIsNewline " << parbreak_is_newline << '\n';
1331 switch (spacing.getSpace()) {
1332 case Spacing::Double:
1333 os << "\tSpacing Double\n";
1335 case Spacing::Onehalf:
1336 os << "\tSpacing Onehalf\n";
1338 case Spacing::Other:
1339 os << "\tSpacing Other " << spacing.getValueAsString() << '\n';
1341 case Spacing::Single:
1342 os << "\tSpacing Single\n";
1344 case Spacing::Default:
1347 if (!requires_.empty()) {
1348 os << "\tRequires ";
1349 for (set<string>::const_iterator it = requires_.begin();
1350 it != requires_.end(); ++it) {
1351 if (it != requires_.begin())
1357 if (refprefix.empty())
1358 os << "\tRefPrefix OFF\n";
1360 os << "\tRefPrefix " << to_utf8(refprefix) << '\n';
1361 if (!htmltag_.empty())
1362 os << "\tHTMLTag " << htmltag_ << '\n';
1363 if (!htmlattr_.empty())
1364 os << "\tHTMLAttr " << htmlattr_ << '\n';
1365 if (!htmlitemtag_.empty())
1366 os << "\tHTMLItem " << htmlitemtag_ << '\n';
1367 if (!htmlitemattr_.empty())
1368 os << "\tHTMLItemAttr " << htmlitemattr_ << '\n';
1369 if (!htmllabeltag_.empty())
1370 os << "\tHTMLLabel " << htmllabeltag_ << '\n';
1371 if (!htmllabelattr_.empty())
1372 os << "\tHTMLLabelAttr " << htmllabelattr_ << '\n';
1373 os << "\tHTMLLabelFirst " << htmllabelfirst_ << '\n';
1374 if (!htmlstyle_.empty())
1375 os << "\tHTMLStyle\n"
1376 << to_utf8(rtrim(htmlstyle_, "\n"))
1377 << "\n\tEndHTMLStyle\n";
1378 os << "\tHTMLForceCSS " << htmlforcecss_ << '\n';
1379 if (!htmlpreamble_.empty())
1380 os << "\tHTMLPreamble\n"
1381 << to_utf8(rtrim(htmlpreamble_, "\n"))
1382 << "\n\tEndPreamble\n";
1383 os << "\tHTMLTitle " << htmltitle_ << "\n"
1384 "\tSpellcheck " << spellcheck << "\n"
1385 "\tForceLocal " << forcelocal << "\n"
1390 Layout::LaTeXArgMap Layout::args() const
1392 LaTeXArgMap args = latexargs_;
1393 if (!postcommandargs_.empty())
1394 args.insert(postcommandargs_.begin(), postcommandargs_.end());
1395 if (!itemargs_.empty())
1396 args.insert(itemargs_.begin(), itemargs_.end());
1401 int Layout::optArgs() const
1404 LaTeXArgMap::const_iterator it = latexargs_.begin();
1405 for (; it != latexargs_.end(); ++it) {
1406 if (!(*it).second.mandatory)
1409 LaTeXArgMap::const_iterator iit = postcommandargs_.begin();
1410 for (; iit != postcommandargs_.end(); ++iit) {
1411 if (!(*iit).second.mandatory)
1418 int Layout::requiredArgs() const
1421 LaTeXArgMap::const_iterator it = latexargs_.begin();
1422 for (; it != latexargs_.end(); ++it) {
1423 if ((*it).second.mandatory)
1426 LaTeXArgMap::const_iterator iit = postcommandargs_.begin();
1427 for (; iit != postcommandargs_.end(); ++iit) {
1428 if (!(*iit).second.mandatory)
1435 string const & Layout::htmltag() const
1437 if (htmltag_.empty())
1443 string const & Layout::htmlattr() const
1445 if (htmlattr_.empty())
1446 htmlattr_ = "class=\"" + defaultCSSClass() + "\"";
1451 string const & Layout::htmlitemtag() const
1453 if (htmlitemtag_.empty())
1454 htmlitemtag_ = "div";
1455 return htmlitemtag_;
1459 string const & Layout::htmlitemattr() const
1461 if (htmlitemattr_.empty())
1462 htmlitemattr_ = "class=\"" + defaultCSSItemClass() + "\"";
1463 return htmlitemattr_;
1467 string const & Layout::htmllabeltag() const
1469 if (htmllabeltag_.empty()) {
1470 if (labeltype != LABEL_ABOVE &&
1471 labeltype != LABEL_CENTERED)
1472 htmllabeltag_ = "span";
1474 htmllabeltag_ = "div";
1476 return htmllabeltag_;
1480 string const & Layout::htmllabelattr() const
1482 if (htmllabelattr_.empty())
1483 htmllabelattr_ = "class=\"" + defaultCSSLabelClass() + "\"";
1484 return htmllabelattr_;
1488 docstring Layout::htmlstyle() const
1490 if (!htmlstyle_.empty() && !htmlforcecss_)
1492 if (htmldefaultstyle_.empty())
1494 docstring retval = htmldefaultstyle_;
1495 if (!htmlstyle_.empty())
1496 retval += '\n' + htmlstyle_;
1501 string Layout::defaultCSSClass() const
1503 if (!defaultcssclass_.empty())
1504 return defaultcssclass_;
1506 docstring::const_iterator it = name().begin();
1507 docstring::const_iterator en = name().end();
1508 for (; it != en; ++it) {
1509 char_type const c = *it;
1510 if (!isAlphaASCII(c)) {
1512 // make sure we don't start with an underscore,
1513 // as that sometimes causes problems.
1514 d = from_ascii("lyx_");
1517 } else if (isLower(c))
1520 // this is slow, so do it only if necessary
1523 defaultcssclass_ = to_utf8(d);
1524 return defaultcssclass_;
1530 string makeMarginValue(char const * side, double d)
1533 os << "margin-" << side << ": " << d << "ex;\n";
1540 void Layout::makeDefaultCSS() const
1542 // this never needs to be redone, since reloading layouts will
1543 // wipe out what we did before.
1544 if (!htmldefaultstyle_.empty())
1548 htmldefaultstyle_ = font.asCSS();
1553 tmp += makeMarginValue("top", topsep);
1555 tmp += makeMarginValue("bottom", bottomsep);
1556 if (!leftmargin.empty()) {
1557 // we can't really do what LyX does with the margin, so
1558 // we'll just figure out how many characters it is
1559 int const len = leftmargin.length();
1560 tmp += makeMarginValue("left", len);
1562 if (!rightmargin.empty()) {
1563 int const len = rightmargin.length();
1564 tmp += makeMarginValue("right", len);
1568 if (!htmldefaultstyle_.empty())
1569 htmldefaultstyle_ += from_ascii("\n");
1570 htmldefaultstyle_ += from_ascii(tmp);
1574 string where = alignmentToCSS(align);
1575 if (!where.empty()) {
1576 htmldefaultstyle_ += from_ascii("text-align: " + where + ";\n");
1579 // wrap up what we have, if anything
1580 if (!htmldefaultstyle_.empty())
1582 from_ascii(htmltag() + "." + defaultCSSClass() + " {\n") +
1583 htmldefaultstyle_ + from_ascii("\n}\n");
1585 if (labeltype == LABEL_NO_LABEL || htmllabeltag() == "NONE")
1591 if (labelfont != font)
1592 labelCSS = labelfont.asCSS() + from_ascii("\n");
1593 if (labeltype == LABEL_CENTERED)
1594 labelCSS += from_ascii("text-align: center;\n");
1596 if (!labelCSS.empty())
1597 htmldefaultstyle_ +=
1598 from_ascii(htmllabeltag() + "." + defaultCSSLabelClass() + " {\n") +
1599 labelCSS + from_ascii("\n}\n");
1603 bool Layout::operator==(Layout const & rhs) const
1605 // This is enough for the applications we actually make,
1606 // at least at the moment. But we could check more.
1607 return name() == rhs.name()
1608 && latexname() == rhs.latexname()
1609 && latextype == rhs.latextype;