]> git.lyx.org Git - lyx.git/blobdiff - src/buffer.C
mathed31.diff
[lyx.git] / src / buffer.C
index 1d7973a8ffaf92dc301684eecedea860244f5022..cd7ff8535cd8f5e98bab0d24438768581af86c7e 100644 (file)
@@ -18,6 +18,7 @@
 #include <iomanip>
 
 #include <cstdlib>
+#include <cmath>
 #include <unistd.h>
 #include <sys/types.h>
 #include <utime.h>
@@ -93,6 +94,7 @@
 #include "encoding.h"
 #include "exporter.h"
 #include "Lsstream.h"
+#include "converter.h"
 
 using std::ostream;
 using std::ofstream;
@@ -102,6 +104,7 @@ using std::ios;
 using std::setw;
 using std::endl;
 using std::pair;
+using std::make_pair;
 using std::vector;
 using std::max;
 using std::set;
@@ -112,7 +115,7 @@ extern BufferList bufferlist;
 extern LyXAction lyxaction;
 
 
-static const float LYX_FORMAT = 2.17;
+static const int LYX_FORMAT = 218;
 
 extern int tex_code_break_column;
 
@@ -172,6 +175,36 @@ string const Buffer::getLatexName(bool no_path) const
                                       ".tex"); 
 }
 
+pair<Buffer::LogType, string> const Buffer::getLogName(void) const
+{
+       string filename, fname, bname, path;
+
+       filename = getLatexName(false);
+
+       if (filename.empty())
+               return make_pair(Buffer::latexlog, string());
+
+       path = OnlyPath(filename);
+
+       if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1))
+               path = tmppath;
+
+       fname = AddName(path, OnlyFilename(ChangeExtension(filename, ".log")));
+       bname = AddName(path, OnlyFilename(ChangeExtension(filename,
+               formats.Extension("literate") + ".out")));
+
+       // If no Latex log or Build log is newer, show Build log
+
+       FileInfo f_fi(fname), b_fi(bname);
+
+       if (b_fi.exist() &&
+               (!f_fi.exist() || f_fi.getModificationTime() < b_fi.getModificationTime())) {
+               lyxerr[Debug::FILES] << "Log name calculated as : " << bname << endl;
+               return make_pair(Buffer::buildlog, bname);
+       }
+       lyxerr[Debug::FILES] << "Log name calculated as : " << fname << endl;
+       return make_pair(Buffer::latexlog, fname);
+}
 
 void Buffer::setReadonly(bool flag)
 {
@@ -247,9 +280,8 @@ bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par)
 
        LyXParagraph * return_par = 0;
        LyXFont font(LyXFont::ALL_INHERIT, params.language);
-       if (format < 2.16 && params.language->lang() == "hebrew")
+       if (file_format < 216 && params.language->lang() == "hebrew")
                font.setLanguage(default_language);
-
        // If we are inserting, we cheat and get a token in advance
        bool has_token = false;
        string pretoken;
@@ -364,7 +396,7 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
 #endif
                par->depth = depth;
                font = LyXFont(LyXFont::ALL_INHERIT, params.language);
-               if (format < 2.16 && params.language->lang() == "hebrew")
+               if (file_format < 216 && params.language->lang() == "hebrew")
                        font.setLanguage(default_language);
 #ifndef NEW_INSETS
        } else if (token == "\\end_float") {
@@ -380,7 +412,7 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
                lex.EatLine();
                par->layout = LYX_DUMMY_LAYOUT;
                font = LyXFont(LyXFont::ALL_INHERIT, params.language);
-               if (format < 2.16 && params.language->lang() == "hebrew")
+               if (file_format < 216 && params.language->lang() == "hebrew")
                        font.setLanguage(default_language);
        } else if (token == "\\begin_float") {
                int tmpret = lex.FindToken(string_footnotekinds);
@@ -484,7 +516,10 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
                if (pp.first) {
                        params.textclass = pp.second;
                } else {
-                 lex.printError("Unknown textclass `$$Token'");
+                       WriteAlert(string(_("Textclass error")), 
+                               string(_("The document uses an unknown textclass \"")) + 
+                               lex.GetString() + string("\"."),
+                               string(_("LyX will not be able to produce output correctly.")));
                        params.textclass = 0;
                }
                if (!textclasslist.Load(params.textclass)) {
@@ -807,9 +842,8 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
                int tmpret = lex.FindToken(string_align);
                if (tmpret == -1) ++tmpret;
                if (tmpret != LYX_LAYOUT_DEFAULT) { // tmpret != 99 ???
-                       int tmpret2 = 1;
-                       for (; tmpret > 0; --tmpret)
-                               tmpret2 = tmpret2 * 2;
+                       int const tmpret2 = int(pow(2.0, tmpret));
+                       //lyxerr << "Tmpret2 = " << tmpret2 << endl;
                        par->align = LyXAlignment(tmpret2);
                }
        } else if (token == "\\added_space_top") {
@@ -906,7 +940,7 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
                ++pos;
        } else if (token == "\\bibitem") {  // ale970302
                if (!par->bibkey) {
-                       InsetCommandParams p( "bibitem" );
+                       InsetCommandParams p("bibitem", "dummy");
                        par->bibkey = new InsetBibKey(p);
                }
                par->bibkey->Read(this, lex);                   
@@ -1044,38 +1078,42 @@ bool Buffer::readFile(LyXLex & lex, LyXParagraph * par)
                string const token(lex.GetString());
                if (token == "\\lyxformat") { // the first token _must_ be...
                        lex.EatLine();
-                       format = lex.GetFloat();
-                       if (format > 1.0) {
-                               if (LYX_FORMAT - format > 0.05) {
-                                       lyxerr << fmt(_("Warning: need lyxformat %.2f but found %.2f"),
-                                                     LYX_FORMAT, format) << endl;
-                               }
-                               if (format - LYX_FORMAT > 0.05) {
-                                       lyxerr << fmt(_("ERROR: need lyxformat %.2f but found %.2f"),
-                                                     LYX_FORMAT, format) << endl;
+                       string tmp_format = lex.GetString();
+                       //lyxerr << "LyX Format: `" << tmp_format << "'" << endl;
+                       // if present remove ".," from string.
+                       string::size_type dot = tmp_format.find_first_of(".,");
+                       //lyxerr << "           dot found at " << dot << endl;
+                       if (dot != string::npos)
+                               tmp_format.erase(dot, 1);
+                       file_format = strToInt(tmp_format);
+                       if (file_format == LYX_FORMAT) {
+                               // current format
+                       } else if (file_format > LYX_FORMAT) {
+                               // future format
+                               WriteAlert(_("Warning!"),
+                                          _("LyX file format is newer that what"),
+                                          _("is supported in this LyX version. Expect some problems."));
+                               
+                       } else if (file_format < LYX_FORMAT) {
+                               // old formats
+                               if (file_format < 200) {
+                                       WriteAlert(_("ERROR!"),
+                                                  _("Old LyX file format found. "
+                                                    "Use LyX 0.10.x to read this!"));
+                                       return false;
                                }
-                               bool the_end = readLyXformat2(lex, par);
-                               // Formats >= 2.13 support "\the_end" marker
-                               if (format < 2.13)
-                                       the_end = true;
-
-                               setPaperStuff();
-
-                               if (!the_end)
-                                       WriteAlert(_("Warning!"),
-                                                  _("Reading of document is not complete"),
-                                                  _("Maybe the document is truncated"));
-                               // We simulate a safe reading anyways to allow
-                               // users to take the chance... (Asger)
-                               return true;
-                       } // format < 1.0
-                       else {
-                               WriteAlert(_("ERROR!"),
-                                          _("Old LyX file format found. "
-                                            "Use LyX 0.10.x to read this!"));
-                               return false;
                        }
-
+                       bool the_end = readLyXformat2(lex, par);
+                       setPaperStuff();
+                       // the_end was added in 213
+                       if (file_format < 213)
+                               the_end = true;
+
+                       if (!the_end)
+                               WriteAlert(_("Warning!"),
+                                          _("Reading of document is not complete"),
+                                          _("Maybe the document is truncated"));
+                       return true;
                } else { // "\\lyxformat" not found
                        WriteAlert(_("ERROR!"), _("Not a LyX file!"));
                }
@@ -1215,16 +1253,9 @@ bool Buffer::writeFile(string const & fname, bool flag) const
 
        // write out a comment in the top of the file
        ofs << '#' << LYX_DOCVERSION 
-           << " created this file. For more info see http://www.lyx.org/\n";
-       ofs.setf(ios::showpoint|ios::fixed);
-       ofs.precision(2);
-#ifndef HAVE_LOCALE
-       char dummy_format[512];
-       sprintf(dummy_format, "%.2f", LYX_FORMAT);
-       ofs << "\\lyxformat " <<  dummy_format << "\n";
-#else
-       ofs << "\\lyxformat " << setw(4) <<  LYX_FORMAT << "\n";
-#endif
+           << " created this file. For more info see http://www.lyx.org/\n"
+           << "\\lyxformat " << LYX_FORMAT << "\n";
+
        // now write out the buffer paramters.
        params.writeFile(ofs);
 
@@ -1265,225 +1296,6 @@ bool Buffer::writeFile(string const & fname, bool flag) const
 }
 
 
-#if 0
-void Buffer::writeFileAscii(string const & fname, int linelen) 
-{
-       Inset * inset;
-       char c;
-       char footnoteflag = 0;
-       char depth = 0;
-       string tmp;
-       LyXParagraph::size_type i;
-       int j;
-       int ltype = 0;
-       int ltype_depth = 0;
-       int actcell = 0;
-       int actpos = 0;
-       int currlinelen = 0;
-       int fpos = 0;
-       bool ref_printed = false;
-
-       ofstream ofs(fname.c_str());
-       if (!ofs) {
-               WriteFSAlert(_("Error: Cannot write file:"), fname);
-               return;
-       }
-
-       string const fname1 = lyx::tempName(); //TmpFileName();
-       LyXParagraph * par = paragraph;
-       while (par) {
-               int noparbreak = 0;
-               int islatex = 0;
-               if (
-#ifndef NEW_INSETS
-                       par->footnoteflag != LyXParagraph::NO_FOOTNOTE ||
-#endif
-                   !par->previous
-#ifndef NEW_INSETS
-                   || par->previous->footnoteflag == LyXParagraph::NO_FOOTNOTE
-#endif
-                       ){
-
-#ifndef NEW_INSETS
-                       /* begins a footnote environment ? */ 
-                       if (footnoteflag != par->footnoteflag) {
-                               footnoteflag = par->footnoteflag;
-                               if (footnoteflag) {
-                                       j = strlen(string_footnotekinds[par->footnotekind])+4;
-                                       if (currlinelen + j > linelen)
-                                               ofs << "\n";
-                                       ofs << "(["
-                                           << string_footnotekinds[par->footnotekind] << "] ";
-                                       currlinelen += j;
-                               }
-                       }
-#endif
-        
-                       /* begins or ends a deeper area ?*/ 
-                       if (depth != par->depth) {
-                               if (par->depth > depth) {
-                                       while (par->depth > depth) {
-                                               ++depth;
-                                       }
-                               }
-                               else {
-                                       while (par->depth < depth) {
-                                               --depth;
-                                       }
-                               }
-                       }
-        
-                       /* First write the layout */
-                       tmp = textclasslist.NameOfLayout(params.textclass, par->layout);
-                       if (tmp == "Itemize") {
-                               ltype = 1;
-                               ltype_depth = depth+1;
-                       } else if (tmp == "Enumerate") {
-                               ltype = 2;
-                               ltype_depth = depth+1;
-                       } else if (contains(tmp, "ection")) {
-                               ltype = 3;
-                               ltype_depth = depth+1;
-                       } else if (contains(tmp, "aragraph")) {
-                               ltype = 4;
-                               ltype_depth = depth+1;
-                       } else if (tmp == "Description") {
-                               ltype = 5;
-                               ltype_depth = depth+1;
-                       } else if (tmp == "Abstract") {
-                               ltype = 6;
-                               ltype_depth = 0;
-                       } else if (tmp == "Bibliography") {
-                               ltype = 7;
-                               ltype_depth = 0;
-                       } else {
-                               ltype = 0;
-                               ltype_depth = 0;
-                       }
-        
-                       /* maybe some vertical spaces */ 
-
-                       /* the labelwidthstring used in lists */ 
-        
-                       /* some lines? */ 
-        
-                       /* some pagebreaks? */ 
-        
-                       /* noindent ? */ 
-        
-                       /* what about the alignment */ 
-               } else {
-#ifndef NEW_INSETS
-                       /* dummy layout, that means a footnote ended */ 
-                       footnoteflag = LyXParagraph::NO_FOOTNOTE;
-                       ofs << ") ";
-                       noparbreak = 1;
-#else
-                       lyxerr << "Should this ever happen?" << endl;
-#endif
-               }
-      
-               LyXFont font1 =
-                       LyXFont(LyXFont::ALL_INHERIT, params.language);
-                actcell = 0;
-               for (i = 0, actpos = 1; i < par->size(); ++i, ++actpos) {
-                       if (!i && !footnoteflag && !noparbreak){
-                               ofs << "\n\n";
-                               for (j = 0; j < depth; ++j)
-                                       ofs << "  ";
-                               currlinelen = depth * 2;
-                               switch (ltype) {
-                               case 0: /* Standard */
-                               case 4: /* (Sub)Paragraph */
-                                case 5: /* Description */
-                                       break;
-                               case 6: /* Abstract */
-                                       ofs << "Abstract\n\n";
-                                       break;
-                               case 7: /* Bibliography */
-                                       if (!ref_printed) {
-                                               ofs << "References\n\n";
-                                               ref_printed = true;
-                                       }
-                                       break;
-                               default:
-                                       ofs << par->labelstring << " ";
-                                       break;
-                               }
-                               if (ltype_depth > depth) {
-                                       for (j = ltype_depth - 1; j > depth; --j)
-                                               ofs << "  ";
-                                       currlinelen += (ltype_depth-depth)*2;
-                               }
-                       }
-                       LyXFont font2 = par->GetFontSettings(params, i);
-                       if (font1.latex() != font2.latex()) {
-                               if (font2.latex() == LyXFont::OFF)
-                                       islatex = 0;
-                               else
-                                       islatex = 1;
-                       } else {
-                               islatex = 0;
-                       }
-                       c = par->GetChar(i);
-                       if (islatex)
-                               continue;
-                       switch (c) {
-                       case LyXParagraph::META_INSET:
-                               if ((inset = par->GetInset(i))) {
-                                       fpos = ofs.tellp();
-                                       inset->Ascii(this, ofs);
-                                       currlinelen += (ofs.tellp() - fpos);
-                                       actpos += (ofs.tellp() - fpos) - 1;
-                               }
-                               break;
-                       case LyXParagraph::META_NEWLINE:
-                               ofs << "\n";
-                               for (j = 0; j < depth; ++j)
-                                       ofs << "  ";
-                               currlinelen = depth * 2;
-                               if (ltype_depth > depth) {
-                                       for (j = ltype_depth;
-                                           j > depth; --j)
-                                               ofs << "  ";
-                                       currlinelen += (ltype_depth - depth) * 2;
-                               }
-                               break;
-                       case LyXParagraph::META_HFILL: 
-                               ofs << "\t";
-                               break;
-                       case '\\':
-                               ofs << "\\";
-                               break;
-                       default:
-                               if (currlinelen > linelen - 10
-                                    && c == ' ' && i + 2 < par->size()) {
-                                       ofs << "\n";
-                                       for (j = 0; j < depth; ++j)
-                                               ofs << "  ";
-                                       currlinelen = depth * 2;
-                                       if (ltype_depth > depth) {
-                                               for (j = ltype_depth;
-                                                   j > depth; --j)
-                                                       ofs << "  ";
-                                               currlinelen += (ltype_depth-depth)*2;
-                                       }
-                               } else if (c != '\0')
-                                       ofs << c;
-                               else if (c == '\0')
-                                       lyxerr.debug() << "writeAsciiFile: NULL char in structure." << endl;
-                               ++currlinelen;
-                               break;
-                       }
-               }
-               par = par->next;
-       }
-   
-       ofs << "\n";
-}
-//----------------------------------------------------------------------------
-#else
-//----------------------------------------------------------------------------
 string const Buffer::asciiParagraph(LyXParagraph const * par,
                                    unsigned int linelen) const
 {
@@ -1492,7 +1304,9 @@ string const Buffer::asciiParagraph(LyXParagraph const * par,
        LyXFont font2;
        Inset const * inset;
        char c;
+#ifndef NEW_INSETS
        LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
+#endif
        char depth = 0;
        int ltype = 0;
        int ltype_depth = 0;
@@ -1594,7 +1408,11 @@ string const Buffer::asciiParagraph(LyXParagraph const * par,
       
        font1 = LyXFont(LyXFont::ALL_INHERIT, params.language);
        for (LyXParagraph::size_type i = 0; i < par->size(); ++i) {
-               if (!i && !footnoteflag && !noparbreak){
+               if (!i &&
+#ifndef NEW_INSETS
+                   !footnoteflag &&
+#endif
+                   !noparbreak) {
                        if (linelen > 0)
                                buffer << "\n\n";
                        for (char j = 0; j < depth; ++j)
@@ -1639,7 +1457,7 @@ string const Buffer::asciiParagraph(LyXParagraph const * par,
                } else {
                        islatex = 0;
                }
-               c = par->GetChar(i);
+               c = par->GetUChar(params, i);
                if (islatex)
                        continue;
                switch (c) {
@@ -1722,7 +1540,7 @@ void Buffer::writeFileAscii(ostream & ofs, int linelen)
        }
        ofs << "\n";
 }
-#endif
+
 
 void Buffer::makeLaTeXFile(string const & fname, 
                           string const & original_path,
@@ -1852,7 +1670,9 @@ void Buffer::makeLaTeXFile(string const & fname,
                
                // language should be a parameter to \documentclass
                bool use_babel = false;
-               if (params.language->babel() == "hebrew") // This seems necessary
+               if (params.language->babel() == "hebrew"
+                   && default_language->babel() != "hebrew")
+                        // This seems necessary
                        features.UsedLanguages.insert(default_language);
 #ifdef DO_USE_DEFAULT_LANGUAGE
                if (params.language->lang() != "default" ||
@@ -1885,9 +1705,15 @@ void Buffer::makeLaTeXFile(string const & fname,
                // end of \documentclass defs
                
                // font selection must be done before loading fontenc.sty
-               if (params.fonts != "default") {
+               // The ae package is not needed when using OT1 font encoding.
+               if (params.fonts != "default" &&
+                   (params.fonts != "ae" || lyxrc.fontenc != "default")) {
                        ofs << "\\usepackage{" << params.fonts << "}\n";
                        texrow.newline();
+                       if (params.fonts == "ae") {
+                               ofs << "\\usepackage{aecompl}\n";
+                               texrow.newline();
+                       }
                }
                // this one is not per buffer
                if (lyxrc.fontenc != "default") {
@@ -2023,7 +1849,7 @@ void Buffer::makeLaTeXFile(string const & fname,
                        ofs << "}\n";
                        texrow.newline();
                }
-               if (params.use_amsmath
+               if (features.amsstyle
                    && !tclass.provides(LyXTextClass::amsmath)) {
                        ofs << "\\usepackage{amsmath}\n";
                        texrow.newline();
@@ -2336,14 +2162,16 @@ bool Buffer::isSGML() const
 void Buffer::sgmlOpenTag(ostream & os, int depth,
                         string const & latexname) const
 {
-       os << string(depth, ' ') << "<" << latexname << ">\n";
+       if (latexname != "!-- --")
+               os << string(depth, ' ') << "<" << latexname << ">\n";
 }
 
 
 void Buffer::sgmlCloseTag(ostream & os, int depth,
                          string const & latexname) const
 {
-       os << string(depth, ' ') << "</" << latexname << ">\n";
+       if (latexname != "!-- --")
+               os << string(depth, ' ') << "</" << latexname << ">\n";
 }
 
 
@@ -2380,7 +2208,7 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
        texrow.reset();
 
        if (!body_only) {
-               string sgml_includedfiles=features.getIncludedFiles();
+               string sgml_includedfiles=features.getIncludedFiles(fname);
 
                if (params.preamble.empty() && sgml_includedfiles.empty()) {
                        ofs << "<!doctype linuxdoc system>\n\n";
@@ -2712,11 +2540,13 @@ void Buffer::pop_tag(ostream & os, string const & tag,
 #warning Use a real stack! (Lgb)
 #endif
        // Please, Lars, do not remove the global variable. I already
-       // had to reintroduce it twice! (JMarc) 
+       // had to reintroduce it twice! (JMarc)
+       // but...but... I'll remove it anyway. (well not quite) (Lgb)
+#if 0
        int j;
        
         // pop all tags till specified one
-        for (j = pos; (j >= 0) && (strcmp(stack[j], tag.c_str())); --j)
+        for (j = pos; (j >= 0) && tag != stack[j]; --j)
                 os << "</" << stack[j] << ">";
 
         // closes the tag
@@ -2725,9 +2555,25 @@ void Buffer::pop_tag(ostream & os, string const & tag,
         // push all tags, but the specified one
         for (j = j + 1; j <= pos; ++j) {
                 os << "<" << stack[j] << ">";
-                strcpy(stack[j-1], stack[j]);
+                strcpy(stack[j - 1], stack[j]);
         }
         --pos;
+#else
+        // pop all tags till specified one
+       int j = pos;
+        for (int j = pos; (j >= 0) && tag != stack[j]; --j)
+                os << "</" << stack[j] << ">";
+
+        // closes the tag
+        os << "</" << tag << ">";
+       
+        // push all tags, but the specified one
+        for (int i = j + 1; i <= pos; ++i) {
+                os << "<" << stack[i] << ">";
+                strcpy(stack[i - 1], stack[i]);
+        }
+        --pos;
+#endif
 }
 
 
@@ -3000,7 +2846,7 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
        texrow.reset();
 
        if (!only_body) {
-               string sgml_includedfiles=features.getIncludedFiles();
+               string sgml_includedfiles=features.getIncludedFiles(fname);
 
                ofs << "<!doctype " << top_element
                    << " public \"-//OASIS//DTD DocBook V3.1//EN\"";
@@ -3010,16 +2856,18 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
                else
                        ofs << "\n [ " << params.preamble 
                            << sgml_includedfiles << " \n]>\n\n";
+       }
 
-               if (params.options.empty())
-                       sgmlOpenTag(ofs, 0, top_element);
-               else {
-                       string top = top_element;
-                       top += " ";
-                       top += params.options;
-                       sgmlOpenTag(ofs, 0, top);
-               }
+       string top = top_element;       
+       top += " lang=\"";
+       top += params.language->code();
+       top += "\"";
+
+       if (!params.options.empty()) {
+               top += " ";
+               top += params.options;
        }
+       sgmlOpenTag(ofs, 0, top);
 
        ofs << "<!-- DocBook file was created by " << LYX_DOCVERSION 
            << "\n  See http://www.lyx.org/ for more information -->\n";
@@ -3069,9 +2917,7 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
                // Write opening SGML tags.
                switch (style.latextype) {
                case LATEX_PARAGRAPH:
-                       if (style.latexname() != "dummy")
-                               sgmlOpenTag(ofs, depth+command_depth,
-                                           style.latexname());
+                       sgmlOpenTag(ofs, depth+command_depth, style.latexname());
                        break;
 
                case LATEX_COMMAND:
@@ -3123,7 +2969,10 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
                        }
 
                        sgmlOpenTag(ofs, depth + command_depth, command_name);
-                       item_name = "title";
+                       if (c_params.empty())
+                               item_name = "title";
+                       else
+                               item_name = c_params;
                        sgmlOpenTag(ofs, depth + 1 + command_depth, item_name);
                        break;
 
@@ -3153,9 +3002,13 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
                        }
                        
                        if (style.latextype == LATEX_ENVIRONMENT) {
-                               if (!style.latexparam().empty())
-                                       sgmlOpenTag(ofs, depth + command_depth,
-                                                   style.latexparam());
+                               if (!style.latexparam().empty()) {
+                                       if(style.latexparam() == "CDATA")
+                                               ofs << "<![ CDATA [";
+                                       else
+                                               sgmlOpenTag(ofs, depth + command_depth,
+                                                           style.latexparam());
+                               }
                                break;
                        }
 
@@ -3202,13 +3055,20 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
                // write closing SGML tags
                switch (style.latextype) {
                case LATEX_COMMAND:
-                       end_tag = "title";
+                       if (c_params.empty())
+                               end_tag = "title";
+                       else
+                               end_tag = c_params;
                        sgmlCloseTag(ofs, depth + command_depth, end_tag);
                        break;
                case LATEX_ENVIRONMENT:
-                       if (!style.latexparam().empty())
-                               sgmlCloseTag(ofs, depth + command_depth,
-                                            style.latexparam());
+                       if (!style.latexparam().empty()) {
+                               if(style.latexparam() == "CDATA")
+                                       ofs << "]]>";
+                               else
+                                       sgmlCloseTag(ofs, depth + command_depth,
+                                                    style.latexparam());
+                       }
                        break;
                case LATEX_ITEM_ENVIRONMENT:
                        if (desc_on == 1) break;
@@ -3216,13 +3076,10 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
                        sgmlCloseTag(ofs, depth + 1 + command_depth, end_tag);
                        break;
                case LATEX_PARAGRAPH:
-                       if (style.latexname() != "dummy")
-                               sgmlCloseTag(ofs, depth + command_depth,
-                                            style.latexname());
+                       sgmlCloseTag(ofs, depth + command_depth, style.latexname());
                        break;
                default:
-                       sgmlCloseTag(ofs, depth + command_depth,
-                                    style.latexname());
+                       sgmlCloseTag(ofs, depth + command_depth, style.latexname());
                        break;
                }
        }
@@ -3248,10 +3105,8 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
                if (!command_stack[j].empty())
                        sgmlCloseTag(ofs, j, command_stack[j]);
 
-       if (!only_body) {
-               ofs << "\n\n";
-               sgmlCloseTag(ofs, 0, top_element);
-       }
+       ofs << "\n\n";
+       sgmlCloseTag(ofs, 0, top_element);
 
        ofs.close();
        // How to check for successful close
@@ -3545,7 +3400,7 @@ vector<string> const Buffer::getLabelList()
 }
 
 
-vector<vector<Buffer::TocItem> > const Buffer::getTocList()
+vector<vector<Buffer::TocItem> > const Buffer::getTocList() const
 {
        int figs = 0;
        int tables = 0;