]> git.lyx.org Git - lyx.git/blobdiff - src/TextClass.cpp
HTML for stackrel.
[lyx.git] / src / TextClass.cpp
index 30eeb4df31c171bbec946279af339821f6af5a47..6bc0bc0c8e65aded738618c509014955e8c4588b 100644 (file)
@@ -66,7 +66,7 @@ private:
 };
 
 // Keep the changes documented in the Customization manual. 
-int const FORMAT = 17;
+int const FORMAT = 26;
 
 
 bool layout2layout(FileName const & filename, FileName const & tempfile)
@@ -95,7 +95,7 @@ bool layout2layout(FileName const & filename, FileName const & tempfile)
 }
 
 
-std::string translateRT(TextClass::ReadType rt) 
+string translateRT(TextClass::ReadType rt) 
 {
        switch (rt) {
        case TextClass::BASECLASS:
@@ -196,7 +196,9 @@ enum TextClassTags {
        TC_ADDTOHTMLPREAMBLE,
        TC_DEFAULTMODULE,
        TC_PROVIDESMODULE,
-       TC_EXCLUDESMODULE
+       TC_EXCLUDESMODULE,
+       TC_HTMLTOCSECTION,
+       TC_CITEFORMAT
 };
 
 
@@ -205,6 +207,7 @@ namespace {
        LexerKeyword textClassTags[] = {
                { "addtohtmlpreamble", TC_ADDTOHTMLPREAMBLE },
                { "addtopreamble",     TC_ADDTOPREAMBLE },
+               { "citeformat",        TC_CITEFORMAT },
                { "classoptions",      TC_CLASSOPTIONS },
                { "columns",           TC_COLUMNS },
                { "counter",           TC_COUNTER },
@@ -215,6 +218,7 @@ namespace {
                { "float",             TC_FLOAT },
                { "format",            TC_FORMAT },
                { "htmlpreamble",      TC_HTMLPREAMBLE },
+               { "htmltocsection",    TC_HTMLTOCSECTION },
                { "ifcounter",         TC_IFCOUNTER },
                { "ifstyle",           TC_IFSTYLE },
                { "input",             TC_INPUT },
@@ -529,6 +533,10 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt)
                case TC_HTMLPREAMBLE:
                        htmlpreamble_ = from_utf8(lexrc.getLongString("EndPreamble"));
                        break;
+               
+               case TC_HTMLTOCSECTION:
+                       html_toc_section_ = from_utf8(trim(lexrc.getString()));
+                       break;
 
                case TC_ADDTOPREAMBLE:
                        preamble_ += from_utf8(lexrc.getLongString("EndPreamble"));
@@ -628,6 +636,10 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt)
                case TC_FLOAT:
                        readFloat(lexrc);
                        break;
+               
+               case TC_CITEFORMAT:
+                       readCiteFormat(lexrc);
+                       break;
 
                case TC_IFCOUNTER:
                        ifcounter = true;
@@ -840,6 +852,28 @@ void TextClass::readClassOptions(Lexer & lexrc)
 }
 
 
+void TextClass::readCiteFormat(Lexer & lexrc)
+{
+       string etype;
+       string definition;
+       while (lexrc.isOK()) {
+               lexrc.next();
+               etype = lexrc.getString();
+               if (!lexrc.isOK() || compare_ascii_no_case(etype, "end") == 0)
+                       break;
+               lexrc.eatLine();
+               definition = lexrc.getString();
+               char initchar = etype[0];
+               if (initchar == '#')
+                       continue;
+               if (initchar == '!' || initchar == '_')
+                       cite_macros_[etype] = definition;
+               else
+                       cite_formats_[etype] = definition;
+       }
+}
+
+
 void TextClass::readFloat(Lexer & lexrc)
 {
        enum {
@@ -850,10 +884,12 @@ void TextClass::readFloat(Lexer & lexrc)
                FT_WITHIN,
                FT_STYLE,
                FT_LISTNAME,
-               FT_BUILTIN,
+               FT_NEEDSFLOAT,
                FT_HTMLSTYLE,
-               FT_HTMLCLASS,
-               FT_HTMLTYPE,
+               FT_HTMLATTR,
+               FT_HTMLTAG,
+               FT_LISTCOMMAND,
+               FT_REFPREFIX,
                FT_END
        };
 
@@ -861,13 +897,15 @@ void TextClass::readFloat(Lexer & lexrc)
                { "end", FT_END },
                { "extension", FT_EXT },
                { "guiname", FT_NAME },
-               { "htmlclass", FT_HTMLCLASS },
+               { "htmlattr", FT_HTMLATTR },
                { "htmlstyle", FT_HTMLSTYLE },
-               { "htmltype", FT_HTMLTYPE },
-               { "latexbuiltin", FT_BUILTIN },
+               { "htmltag", FT_HTMLTAG },
+               { "listcommand", FT_LISTCOMMAND },
                { "listname", FT_LISTNAME },
+               { "needsfloatpkg", FT_NEEDSFLOAT },
                { "numberwithin", FT_WITHIN },
                { "placement", FT_PLACEMENT },
+               { "refprefix", FT_REFPREFIX },
                { "style", FT_STYLE },
                { "type", FT_TYPE }
        };
@@ -875,16 +913,18 @@ void TextClass::readFloat(Lexer & lexrc)
        lexrc.pushTable(floatTags);
 
        string ext;
-       string htmlclass;
+       string htmlattr;
        string htmlstyle;
-       string htmltype;
-       string listName;
+       string htmltag;
+       string listname;
+       string listcommand;
        string name;
        string placement;
+       string refprefix;
        string style;
        string type;
        string within;
-       bool builtin = false;
+       bool needsfloat = true;
 
        bool getout = false;
        while (!getout && lexrc.isOK()) {
@@ -906,8 +946,10 @@ void TextClass::readFloat(Lexer & lexrc)
                                within = fl.within();
                                style = fl.style();
                                name = fl.name();
-                               listName = fl.listName();
-                               builtin = fl.builtin();
+                               listname = fl.listName();
+                               needsfloat = fl.needsFloatPkg();
+                               listcommand = fl.listCommand();
+                               refprefix = fl.refPrefix();
                        } 
                        break;
                case FT_NAME:
@@ -932,25 +974,33 @@ void TextClass::readFloat(Lexer & lexrc)
                        lexrc.next();
                        style = lexrc.getString();
                        break;
+               case FT_LISTCOMMAND:
+                       lexrc.next();
+                       listcommand = lexrc.getString();
+                       break;
+               case FT_REFPREFIX:
+                       lexrc.next();
+                       refprefix = lexrc.getString();
+                       break;
                case FT_LISTNAME:
                        lexrc.next();
-                       listName = lexrc.getString();
+                       listname = lexrc.getString();
                        break;
-               case FT_BUILTIN:
+               case FT_NEEDSFLOAT:
                        lexrc.next();
-                       builtin = lexrc.getBool();
+                       needsfloat = lexrc.getBool();
                        break;
-               case FT_HTMLCLASS:
+               case FT_HTMLATTR:
                        lexrc.next();
-                       htmlclass = lexrc.getString();
+                       htmlattr = lexrc.getString();
                        break;
                case FT_HTMLSTYLE:
                        lexrc.next();
                        htmlstyle = lexrc.getLongString("EndHTMLStyle");
                        break;
-               case FT_HTMLTYPE:
+               case FT_HTMLTAG:
                        lexrc.next();
-                       htmltype = lexrc.getString();
+                       htmltag = lexrc.getString();
                        break;
                case FT_END:
                        getout = true;
@@ -958,10 +1008,15 @@ void TextClass::readFloat(Lexer & lexrc)
                }
        }
 
-       // Here if have a full float if getout == true
+       // Here we have a full float if getout == true
        if (getout) {
+               if (!needsfloat && listcommand.empty())
+                       LYXERR0("The layout does not provide a list command " <<
+                               "for the builtin float `" << type << "'. LyX will " <<
+                               "not be able to produce a float list.");
                Floating fl(type, placement, ext, within, style, name, 
-                               listName, htmltype, htmlclass, htmlstyle, builtin);
+                               listname, listcommand, refprefix, 
+                               htmltag, htmlattr, htmlstyle, needsfloat);
                floatlist_.newFloat(fl);
                // each float has its own counter
                counters_.newCounter(from_ascii(type), from_ascii(within),
@@ -976,6 +1031,15 @@ void TextClass::readFloat(Lexer & lexrc)
 }
 
 
+string const & TextClass::prerequisites() const
+{ 
+       if (contains(prerequisites_, ',')) {
+               vector<string> const pres = getVectorFromString(prerequisites_);
+               prerequisites_ = getStringFromVector(pres, "\n\t");
+       }
+       return prerequisites_; 
+}
+
 bool TextClass::hasLayout(docstring const & n) const
 {
        docstring const name = n.empty() ? defaultLayoutName() : n;
@@ -1166,6 +1230,7 @@ Layout TextClass::createBasicLayout(docstring const & name, bool unknown) const
        return *defaultLayout;
 }
 
+
 /////////////////////////////////////////////////////////////////////////
 //
 // DocumentClassBundle
@@ -1265,6 +1330,53 @@ bool DocumentClass::hasTocLevels() const
 }
 
 
+Layout const & DocumentClass::htmlTOCLayout() const
+{
+       if (html_toc_section_.empty()) {
+               // we're going to look for the layout with the minimum toclevel
+               TextClass::LayoutList::const_iterator lit = begin();
+               TextClass::LayoutList::const_iterator const len = end();
+               int minlevel = 1000;
+               Layout const * lay = NULL;
+               for (; lit != len; ++lit) {
+                       int const level = lit->toclevel;
+                       // we don't want Part
+                       if (level == Layout::NOT_IN_TOC || level < 0 || level >= minlevel)
+                               continue;
+                       lay = &*lit;
+                       minlevel = level;
+               }
+               if (lay)
+                       html_toc_section_ = lay->name();
+               else
+                       // hmm. that is very odd, so we'll do our best
+                       html_toc_section_ = defaultLayoutName();
+       }
+       return operator[](html_toc_section_);
+}
+
+
+string const & DocumentClass::getCiteFormat(string const & entry_type) const
+{
+       static string default_format = N_("{%author%[[%author%, ]][[{%editor%[[%editor%, ed., ]]}]]}\"%title%\"{%journal%[[, {!<i>!}%journal%{!</i>!}]][[{%publisher%[[, %publisher%]][[{%institution%[[, %institution%]]}]]}]]}{%year%[[ (%year%)]]}{%pages%[[, %pages%]]}.");
+       
+       map<string, string>::const_iterator it = cite_formats_.find(entry_type);
+       if (it != cite_formats_.end())
+               return it->second;
+       return default_format;
+}
+
+
+string const & DocumentClass::getCiteMacro(string const & macro) const
+{
+       static string empty;
+       map<string, string>::const_iterator it = cite_macros_.find(macro);
+       if (it != cite_macros_.end())
+               return it->second;
+       return empty;
+}
+
+
 /////////////////////////////////////////////////////////////////////////
 //
 // PageSides