]> git.lyx.org Git - lyx.git/blobdiff - src/buffer.C
Small changes; ChangeLog is your friend
[lyx.git] / src / buffer.C
index 2cc1ffe5ad1c920f4f612b50e55415d203cc7207..f36aa069e7945b6e222e6a48f86cda9988a7a4a4 100644 (file)
@@ -4,7 +4,7 @@
  *           LyX, The Document Processor
  *
  *          Copyright 1995 Matthias Ettrich
- *           Copyright 1995-1999 The LyX Team.
+ *           Copyright 1995-2000 The LyX Team.
  *
  *           This file is Copyright 1996-1999
  *           Lars Gullik Bjønnes
 
 #include <fstream>
 #include <iomanip>
-using std::ofstream;
-using std::ifstream;
-using std::fstream;
-using std::ios;
-using std::setw;
-
 
 #include <cstdlib>
 #include <unistd.h>
@@ -74,8 +68,10 @@ using std::setw;
 #include "insets/insetspecialchar.h"
 #include "insets/figinset.h"
 #include "insets/insettext.h"
+//#include "insets/insetnumber.h"
 #include "insets/insetert.h"
 #include "insets/insetgraphics.h"
+#include "insets/insetfoot.h"
 #include "support/filetools.h"
 #include "support/path.h"
 #include "LaTeX.h"
@@ -89,6 +85,16 @@ using std::setw;
 #include "support/FileInfo.h"
 #include "lyxtext.h"
 #include "gettext.h"
+#include "language.h"
+
+using std::ostream;
+using std::ofstream;
+using std::ifstream;
+using std::fstream;
+using std::ios;
+using std::setw;
+using std::endl;
+using std::pair;
 
 // Uncomment this line to enable a workaround for the weird behaviour
 // of the cursor between a displayed inset and last character
@@ -108,14 +114,14 @@ extern void MenuExport(Buffer *, string const &);
 extern LyXAction lyxaction;
 
 
-static const float LYX_FORMAT = 2.15;
+static const float LYX_FORMAT = 2.16;
 
 extern int tex_code_break_column;
 
 extern void FreeUpdateTimer();
 
 
-Buffer::Buffer(string const & file, LyXRC * lyxrc, bool ronly)
+Buffer::Buffer(string const & file, bool ronly)
 {
        lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
        filename = file;
@@ -129,7 +135,7 @@ Buffer::Buffer(string const & file, LyXRC * lyxrc, bool ronly)
        read_only = ronly;
        users = 0;
        lyxvc.buffer(this);
-       if (read_only || (lyxrc && lyxrc->use_tempdir)) {
+       if (read_only || (lyxrc.use_tempdir)) {
                tmppath = CreateBufferTmpDir();
        } else tmppath.clear();
 }
@@ -161,6 +167,26 @@ Buffer::~Buffer()
 }
 
 
+string Buffer::getLatexName(bool no_path /* = true */) const
+{
+       return ChangeExtension(MakeLatexName(filename), 
+                              ".tex", no_path); 
+}
+
+
+void Buffer::setReadonly(bool flag /* = true */)
+{
+       if (read_only != flag) {
+               read_only = flag; 
+               updateTitles();
+               updateAllVisibleBufferRelatedPopups();
+       }
+       if (read_only) {
+               WarnReadonly(filename);
+       }
+}
+
+
 bool Buffer::saveParamsAsDefaults()
 {
        string fname = AddName(AddPath(user_lyxdir, "templates/"),
@@ -221,7 +247,9 @@ bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par)
        bool the_end_read = false;
 
        LyXParagraph * return_par = 0;
-       LyXFont font(LyXFont::ALL_INHERIT);
+       LyXFont font(LyXFont::ALL_INHERIT,params.language_info);
+       if (format < 2.16 && params.language == "hebrew")
+               font.setLanguage(default_language);
 
        // If we are inserting, we cheat and get a token in advance
        bool has_token = false;
@@ -297,7 +325,6 @@ bool Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
                inset = new InsetLatexAccent;
                inset->Read(lex);
                par->InsertChar(pos, LyXParagraph::META_INSET); 
-                       
                par->InsertInset(pos, inset);
                par->SetFont(pos, font);
                ++pos;
@@ -305,7 +332,7 @@ bool Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
                if (!return_par) 
                        return_par = par;
                else {
-                       par->text.resize(par->text.size());
+                       par->fitToSize();
                        par = new LyXParagraph(par);
                }
                pos = 0;
@@ -331,12 +358,14 @@ bool Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
                par->footnoteflag = footnoteflag;
                par->footnotekind = footnotekind;
                par->depth = depth;
-               font = LyXFont(LyXFont::ALL_INHERIT);
+               font = LyXFont(LyXFont::ALL_INHERIT,params.language_info);
+               if (format < 2.16 && params.language == "hebrew")
+                       font.setLanguage(default_language);
        } else if (token == "\\end_float") {
                if (!return_par) 
                        return_par = par;
                else {
-                       par->text.resize(par->text.size());
+                       par->fitToSize();
                        par = new LyXParagraph(par);
                }
                footnotekind = LyXParagraph::FOOTNOTE;
@@ -344,7 +373,9 @@ bool Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
                pos = 0;
                lex.EatLine();
                par->layout = LYX_DUMMY_LAYOUT;
-               font = LyXFont(LyXFont::ALL_INHERIT);
+               font = LyXFont(LyXFont::ALL_INHERIT,params.language_info);
+               if (format < 2.16 && params.language == "hebrew")
+                       font.setLanguage(default_language);
        } else if (token == "\\begin_float") {
                tmpret = lex.FindToken(string_footnotekinds);
                if (tmpret == -1) ++tmpret;
@@ -428,12 +459,14 @@ bool Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
        } else if (token == "\\defskip") {
                lex.nextToken();
                params.defskip = VSpace(lex.GetString());
+#if 0
        } else if (token == "\\no_isolatin1") { // obsolete
                lex.nextToken();
        } else if (token == "\\no_babel") { // obsolete
                lex.nextToken();
        } else if (token == "\\no_epsfig") { // obsolete
                lex.nextToken();
+#endif
        } else if (token == "\\epsfig") { // obsolete
                // Indeed it is obsolete, but we HAVE to be backwards
                // compatible until 0.14, because otherwise all figures
@@ -646,18 +679,30 @@ bool Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
                else
                        lex.printError("Unknown LaTeX font flag "
                                       "`$$Token'");
-       } else if (token == "\\direction") {
+       } else if (token == "\\lang") {
+               lex.next();
+               string tok = lex.GetString();
+               Languages::iterator lit = languages.find(tok);
+               if (lit != languages.end()) {
+                       font.setLanguage(&(*lit).second);
+               } else {
+                       font.setLanguage(params.language_info);
+                       lex.printError("Unknown language `$$Token'");
+               }
+       } else if (token == "\\direction") { // obsolete
+               if (format >= 2.16)
+                       lex.printError("Command \\direction is obsolete");
                lex.next();
                string tok = lex.GetString();
-               if (tok == "ltr")
-                       font.setDirection(LyXFont::LTR_DIR);
-               else if (tok == "rtl")
-                       font.setDirection(LyXFont::RTL_DIR);
+               if (tok == "rtl")
+                       font.setLanguage(&languages["hebrew"]);
                else if (tok == "default")
-                       font.setDirection(LyXFont::INHERIT_DIR);
+                       if (params.language == "hebrew")
+                               font.setLanguage(default_language);
+                       else
+                               font.setLanguage(params.language_info);
                else
-                       lex.printError("Unknown font flag "
-                                      "`$$Token'");
+                       lex.printError("Unknown direction `$$Token'");
        } else if (token == "\\emph") {
                lex.next();
                font.setEmph(font.setLyXMisc(lex.GetString()));
@@ -691,10 +736,10 @@ bool Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
                }
        } else if (token == "\\added_space_top") {
                lex.nextToken();
-               par->added_space_top = lex.GetString();
+               par->added_space_top = VSpace(lex.GetString());
        } else if (token == "\\added_space_bottom") {
                lex.nextToken();
-               par->added_space_bottom = lex.GetString();
+               par->added_space_bottom = VSpace(lex.GetString());
        } else if (token == "\\pextra_type") {
                lex.nextToken();
                par->pextra_type = lex.GetInteger();
@@ -789,6 +834,22 @@ bool Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
                        par->InsertInset(pos, inset);
                        par->SetFont(pos, font);
                        ++pos;
+#if 0
+               } else if (tmptok == "Number") {
+                       inset = new InsetNumber(this);
+                       inset->Read(lex);
+                       par->InsertChar(pos, LyXParagraph::META_INSET);
+                       par->InsertInset(pos, inset);
+                       par->SetFont(pos, font);
+                       ++pos;
+#endif
+               } else if (tmptok == "Foot") {
+                       inset = new InsetFoot(this);
+                       inset->Read(lex);
+                       par->InsertChar(pos, LyXParagraph::META_INSET);
+                       par->InsertInset(pos, inset);
+                       par->SetFont(pos, font);
+                       ++pos;
                } else if (tmptok == "GRAPHICS") {
                        inset = new InsetGraphics;
                                //inset->Read(lex);
@@ -819,7 +880,7 @@ bool Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
                                if (!inscmd.getOptions().empty() || !inscmd.getContents().empty()) {
                                        inset = new InsetRef(inscmd, this);
                                }
-#warning Verify that this else clause is still needed. (Lgb)
+#warning Check if this else clause is still needed. (Lgb)
 #if 0
                                // This condition comes from a
                                // temporary solution to the latexdel
@@ -911,11 +972,39 @@ bool Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
                par->SetFont(pos, font);
                ++pos;
        } else if (token == "\\SpecialChar") {
-               inset = new InsetSpecialChar;
-               inset->Read(lex);
-               par->InsertChar(pos, LyXParagraph::META_INSET); 
-               par->InsertInset(pos, inset);
-               par->SetFont(pos, font);
+               LyXLayout const & layout =
+                       textclasslist.Style(params.textclass, 
+                                           par->GetLayout());
+
+               // Insets don't make sense in a free-spacing context! ---Kayvan
+               if (layout.free_spacing)
+               {
+                       if (lex.IsOK()) {
+                               string next_token;
+                               lex.next();
+                               next_token = lex.GetString();
+                               if (next_token == "\\-") {
+                                       par->InsertChar(pos, '-');
+                                       par->SetFont(pos, font);
+                               } else if (next_token == "\\protected_separator") {
+                                       par->InsertChar(pos, ' ');
+                                       par->SetFont(pos, font);
+                               } else {
+                                       lex.printError("Token `$$Token' "
+                                                      "is in free space "
+                                                      "paragraph layout!");
+                                       pos--;
+                               }
+                       }
+               }
+               else
+               {
+                       inset = new InsetSpecialChar;
+                       inset->Read(lex);
+                       par->InsertChar(pos, LyXParagraph::META_INSET); 
+                       par->InsertInset(pos, inset);
+                       par->SetFont(pos, font);
+               }
                ++pos;
        } else if (token == "\\Figure") {
                inset = new InsetFig(100, 100, this);
@@ -943,10 +1032,19 @@ bool Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
                ++pos;
        } else if (token == "\\protected_separator") { // obsolete
 #if 1
-               inset = new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
-               par->InsertChar(pos, LyXParagraph::META_INSET);
-               par->InsertInset(pos, inset);
-               par->SetFont(pos, font);
+               LyXLayout const & layout =
+                       textclasslist.Style(params.textclass, 
+                                           par->GetLayout());
+
+               if (layout.free_spacing) {
+                       par->InsertChar(pos, ' ');
+                       par->SetFont(pos, font);
+               } else {
+                       inset = new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
+                       par->InsertChar(pos, LyXParagraph::META_INSET);
+                       par->InsertInset(pos, inset);
+                       par->SetFont(pos, font);
+               }
 #else
                par->InsertChar(pos, LyXParagraph::META_PROTECTED_SEPARATOR);
                par->SetFont(pos, font);
@@ -1028,14 +1126,19 @@ bool Buffer::readFile(LyXLex & lex, LyXParagraph * par)
 
 
 // Should probably be moved to somewhere else: BufferView? LyXView?
-bool Buffer::save(bool makeBackup) const
+bool Buffer::save() const
 {
        // We don't need autosaves in the immediate future. (Asger)
        resetAutosaveTimers();
 
        // make a backup
-       if (makeBackup) {
-               string s = fileName() + '~';
+       string s;
+       if (lyxrc.make_backup) {
+               s = fileName() + '~';
+               if (!lyxrc.backupdir_path.empty())
+                       s = AddName(lyxrc.backupdir_path,
+                                   subst(CleanupPath(s),'/','!'));
+
                // Rename is the wrong way of making a backup,
                // this is the correct way.
                /* truss cp fil fil2:
@@ -1063,10 +1166,10 @@ bool Buffer::save(bool makeBackup) const
                FileInfo finfo(fileName());
                if (finfo.exist()) {
                        mode_t fmode = finfo.getMode();
-                       struct utimbuf * times = new struct utimbuf;
+                       struct utimbuf times = {
+                               finfo.getAccessTime(),
+                               finfo.getModificationTime() };
 
-                       times->actime = finfo.getAccessTime();
-                       times->modtime = finfo.getModificationTime();
                        ifstream ifs(fileName().c_str());
                        ofstream ofs(s.c_str(), ios::out|ios::trunc);
                        if (ifs && ofs) {
@@ -1075,14 +1178,13 @@ bool Buffer::save(bool makeBackup) const
                                ofs.close();
                                ::chmod(s.c_str(), fmode);
                                
-                               if (::utime(s.c_str(), times)) {
+                               if (::utime(s.c_str(), &times)) {
                                        lyxerr << "utime error." << endl;
                                }
                        } else {
                                lyxerr << "LyX was not able to make "
                                        "backupcopy. Beware." << endl;
                        }
-                       delete times;
                }
        }
        
@@ -1103,8 +1205,7 @@ bool Buffer::save(bool makeBackup) const
                }
        } else {
                // Saving failed, so backup is not backup
-               if (makeBackup) {
-                       string s = fileName() + '~';
+               if (lyxrc.make_backup) {
                        ::rename(s.c_str(), fileName().c_str());
                }
                return false;
@@ -1284,11 +1385,16 @@ void Buffer::writeFileAscii(string const & fname, int linelen)
                        noparbreak = 1;
                }
       
+               LyXLayout const & layout =
+                       textclasslist.Style(params.textclass, 
+                                           par->GetLayout());
+               bool free_spc = layout.free_spacing;
+
                /* It might be a table */ 
                if (par->table){
 #if 0
-                       if (!lyxrc->ascii_roff_command.empty() &&
-                            lyxrc->ascii_roff_command != "none") {
+                       if (!lyxrc.ascii_roff_command.empty() &&
+                            lyxrc.ascii_roff_command != "none") {
                                RoffAsciiTable(ofs, par);
                                par = par->next;
                                continue;
@@ -1299,18 +1405,19 @@ void Buffer::writeFileAscii(string const & fname, int linelen)
                        cells = par->table->columns;
                        clen = new int [cells];
                        memset(clen, 0, sizeof(int) * cells);
+
                        for (i = 0, j = 0, h = 1; i < par->size(); ++i, ++h) {
                                c = par->GetChar(i);
                                if (c == LyXParagraph::META_INSET) {
                                        if ((inset = par->GetInset(i))) {
 #if 1
 #ifdef HAVE_SSTREAM
-                                               ostringstream ost;
-                                               inset->Latex(ost, -1);
+                                               std::ostringstream ost;
+                                               inset->Latex(ost, -1, free_spc);
                                                h += ost.str().length();
 #else
                                                ostrstream ost;
-                                               inset->Latex(ost, -1);
+                                               inset->Latex(ost, -1, free_spc);
                                                ost << '\0';
                                                char * tmp = ost.str();
                                                string tstr(tmp);
@@ -1323,7 +1430,7 @@ void Buffer::writeFileAscii(string const & fname, int linelen)
                                                        WriteFSAlert(_("Error: Cannot open temporary file:"), fname1);
                                                        return;
                                                }
-                                               inset->Latex(fs, -1);
+                                               inset->Latex(fs, -1, free_spc);
                                                h += fs.tellp() - 1;
                                                ::remove(fname1.c_str());
 #endif
@@ -1340,7 +1447,7 @@ void Buffer::writeFileAscii(string const & fname, int linelen)
                                clen[j] = h;
                }
       
-               font1 = LyXFont(LyXFont::ALL_INHERIT);
+               font1 = LyXFont(LyXFont::ALL_INHERIT,params.language_info);
                 actcell = 0;
                for (i = 0, actpos = 1; i < par->size(); ++i, ++actpos) {
                        if (!i && !footnoteflag && !noparbreak){
@@ -1408,7 +1515,7 @@ void Buffer::writeFileAscii(string const & fname, int linelen)
                        case LyXParagraph::META_INSET:
                                if ((inset = par->GetInset(i))) {
                                        fpos = ofs.tellp();
-                                       inset->Latex(ofs, -1);
+                                       inset->Latex(ofs, -1, free_spc);
                                        currlinelen += (ofs.tellp() - fpos);
                                        actpos += (ofs.tellp() - fpos) - 1;
                                }
@@ -1525,7 +1632,6 @@ void Buffer::writeFileAscii(string const & fname, int linelen)
 }
 
 
-#ifdef USE_OSTREAM_ONLY
 void Buffer::makeLaTeXFile(string const & fname, 
                           string const & original_path,
                           bool nice, bool only_body)
@@ -1534,7 +1640,7 @@ void Buffer::makeLaTeXFile(string const & fname,
        
        niceFile = nice; // this will be used by Insetincludes.
 
-       tex_code_break_column = lyxrc->ascii_linelen;
+       tex_code_break_column = lyxrc.ascii_linelen;
 
         LyXTextClass const & tclass =
                textclasslist.TextClass(params.textclass);
@@ -1547,7 +1653,7 @@ void Buffer::makeLaTeXFile(string const & fname,
        
        // validate the buffer.
        lyxerr[Debug::LATEX] << "  Validating buffer..." << endl;
-       LaTeXFeatures features(tclass.numLayouts());
+       LaTeXFeatures features(params, tclass.numLayouts());
        validate(features);
        lyxerr[Debug::LATEX] << "  Buffer validation done." << endl;
        
@@ -1651,15 +1757,20 @@ void Buffer::makeLaTeXFile(string const & fname,
                    && params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
                        options += "landscape,";
                
-               // language should be a parameter to \documentclass             
-               if (params.language != "default") {
-                       if (params.language == "hebrew")
-                               options += "english,";
-                       else if (lyxrc->rtl_support)
-                               options += "hebrew,";
-                       options += params.language + ',';
-               } else if (lyxrc->rtl_support)
-                       options += "hebrew,english,";
+               // language should be a parameter to \documentclass
+               bool use_babel = false;
+               if (params.language != "default" ||
+                   !features.UsedLanguages.empty() ) {
+                       use_babel = true;
+                       for (LaTeXFeatures::LanguageList::const_iterator cit =
+                                    features.UsedLanguages.begin();
+                            cit != features.UsedLanguages.end(); ++cit) {
+                               options += (*cit)->lang + ",";
+                       }
+                       if (default_language != params.language_info)
+                               options += default_language ->lang + ',';
+                       options += params.language_info->lang + ',';
+               }
 
                // the user-defined options
                if (!params.options.empty()) {
@@ -1683,8 +1794,8 @@ void Buffer::makeLaTeXFile(string const & fname,
                        texrow.newline();
                }
                // this one is not per buffer
-               if (lyxrc->fontenc != "default") {
-                       ofs << "\\usepackage[" << lyxrc->fontenc
+               if (lyxrc.fontenc != "default") {
+                       ofs << "\\usepackage[" << lyxrc.fontenc
                            << "]{fontenc}\n";
                        texrow.newline();
                }
@@ -1755,7 +1866,7 @@ void Buffer::makeLaTeXFile(string const & fname,
                                break;
                        default:
                                // default papersize ie BufferParams::VM_PAPER_DEFAULT
-                               switch (lyxrc->default_papersize) {
+                               switch (lyxrc.default_papersize) {
                                case BufferParams::PAPER_DEFAULT: // keep compiler happy
                                case BufferParams::PAPER_USLETTER:
                                        ofs << ",letterpaper";
@@ -1814,8 +1925,8 @@ void Buffer::makeLaTeXFile(string const & fname,
 
                // We try to load babel late, in case it interferes
                // with other packages.
-               if (params.language != "default" || lyxrc->rtl_support ) {
-                       ofs << "\\usepackage{babel}\n";
+               if (use_babel) {
+                       ofs << lyxrc.language_package << endl;
                        texrow.newline();
                }
 
@@ -1862,13 +1973,13 @@ void Buffer::makeLaTeXFile(string const & fname,
                string preamble, tmppreamble;
 
                // The optional packages;
-               preamble = features.getPackages(params);
+               preamble = features.getPackages();
 
                // this might be useful...
                preamble += "\n\\makeatletter\n\n";
 
                // Some macros LyX will need
-               tmppreamble = features.getMacros(params);
+               tmppreamble = features.getMacros();
 
                if (!tmppreamble.empty()) {
                        preamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
@@ -1877,7 +1988,7 @@ void Buffer::makeLaTeXFile(string const & fname,
                }
 
                // the text class specific preamble 
-               tmppreamble = features.getTClassPreamble(params);
+               tmppreamble = features.getTClassPreamble();
                if (!tmppreamble.empty()) {
                        preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
                                "Textclass specific LaTeX commands.\n"
@@ -1940,11 +2051,17 @@ void Buffer::makeLaTeXFile(string const & fname,
                texrow.newline();
        } // only_body
        lyxerr.debug() << "preamble finished, now the body." << endl;
+       if (!lyxrc.language_auto_begin && params.language != "default") {
+               ofs << subst(lyxrc.language_command_begin, "$$lang",
+                            params.language)
+                   << endl;
+               texrow.newline();
+       }
        
        bool was_title = false;
        bool already_title = false;
 #ifdef HAVE_SSTREAM
-       ostringstream ftnote;
+       std::ostringstream ftnote;
 #else
        char * tmpholder = 0;
 #endif
@@ -2031,6 +2148,13 @@ void Buffer::makeLaTeXFile(string const & fname,
                texrow.newline();
        }
 
+       if (!lyxrc.language_auto_end && params.language != "default") {
+               ofs << subst(lyxrc.language_command_end, "$$lang",
+                            params.language)
+                   << endl;
+               texrow.newline();
+       }
+
        if (!only_body) {
                ofs << "\\end{document}\n";
                texrow.newline();
@@ -2048,7 +2172,7 @@ void Buffer::makeLaTeXFile(string const & fname,
        // if we are in batchmode or not (within mathed_write()
        // in math_write.C) so we must set it to a non-zero
        // value when we leave otherwise we save incorrect .lyx files.
-       tex_code_break_column = lyxrc->ascii_linelen;
+       tex_code_break_column = lyxrc.ascii_linelen;
 
        ofs.close();
        if (ofs.fail()) {
@@ -2057,637 +2181,112 @@ void Buffer::makeLaTeXFile(string const & fname,
        
        lyxerr.debug() << "Finished making latex file." << endl;
 }
-#else
-void Buffer::makeLaTeXFile(string const & fname, 
-                          string const & original_path,
-                          bool nice, bool only_body)
+
+
+bool Buffer::isLatex() const
 {
-       lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
-       
-       niceFile = nice; // this will be used by Insetincludes.
+       return textclasslist.TextClass(params.textclass).outputType() == LATEX;
+}
 
-       tex_code_break_column = lyxrc->ascii_linelen;
 
-        LyXTextClass const & tclass =
-               textclasslist.TextClass(params.textclass);
+bool Buffer::isLinuxDoc() const
+{
+       return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC;
+}
+
+
+bool Buffer::isLiterate() const
+{
+       return textclasslist.TextClass(params.textclass).outputType() == LITERATE;
+}
+
+
+bool Buffer::isDocBook() const
+{
+       return textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
+}
+
+
+bool Buffer::isSGML() const
+{
+       return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC ||
+              textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
+}
+
+
+void Buffer::sgmlOpenTag(ostream & os, int depth,
+                        string const & latexname) const
+{
+       os << string(depth, ' ') << "<" << latexname << ">\n";
+}
+
+
+void Buffer::sgmlCloseTag(ostream & os, int depth,
+                         string const & latexname) const
+{
+       os << string(depth, ' ') << "</" << latexname << ">\n";
+}
+
+
+void Buffer::makeLinuxDocFile(string const & fname, int column)
+{
+       LyXParagraph * par = paragraph;
+
+       string top_element = textclasslist.LatexnameOfClass(params.textclass);
+       string environment_stack[10];
+        string item_name;
+
+       int depth = 0;              /* paragraph depth */
 
        ofstream ofs(fname.c_str());
+
        if (!ofs) {
-               WriteFSAlert(_("Error: Cannot open file: "), fname);
+               WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
                return;
        }
-       
-       // validate the buffer.
-       lyxerr[Debug::LATEX] << "  Validating buffer..." << endl;
-       LaTeXFeatures features(tclass.numLayouts());
-       validate(features);
-       lyxerr[Debug::LATEX] << "  Buffer validation done." << endl;
-       
+   
+       tex_code_break_column = column; 
        texrow.reset();
-       // The starting paragraph of the coming rows is the 
-       // first paragraph of the document. (Asger)
-       texrow.start(paragraph, 0);
+   
+       if (params.preamble.empty()) {
+               ofs << "<!doctype linuxdoc system>\n\n";
+       }
+       else {
+               ofs << "<!doctype linuxdoc system \n [ "
+                   << params.preamble << " \n]>\n\n";
+       }
 
-       string LFile;
-       
-       if (!only_body && nice) {
-               LFile += "%% " LYX_DOCVERSION " created this file.  "
-                        "For more info, see http://www.lyx.org/.\n";
-               LFile += "%% Do not edit unless you really know what you are doing.\n";
-               texrow.newline();
-               texrow.newline();
+       ofs << "<!-- "  << LYX_DOCVERSION 
+           << " created this file. For more info see http://www.lyx.org/"
+           << " -->\n";
+
+       if(params.options.empty())
+               sgmlOpenTag(ofs, 0, top_element);
+       else {
+               string top = top_element;
+               top += " ";
+               top += params.options;
+               sgmlOpenTag(ofs, 0, top);
        }
-       lyxerr.debug() << "lyx header finished" << endl;
-       // There are a few differences between nice LaTeX and usual files:
-       // usual is \batchmode and has a 
-       // special input@path to allow the including of figures
-       // with either \input or \includegraphics (what figinsets do).
-       // batchmode is not set if there is a tex_code_break_column.
-       // In this case somebody is interested in the generated LaTeX,
-       // so this is OK. input@path is set when the actual parameter
-       // original_path is set. This is done for usual tex-file, but not
-       // for nice-latex-file. (Matthias 250696)
-       if (!only_body) {
-               if (!nice){
-                       // code for usual, NOT nice-latex-file
-                       LFile += "\\batchmode\n"; // changed
-                       // from \nonstopmode
-                       texrow.newline();
-               }
-               if (!original_path.empty()) {
-                       LFile += "\\makeatletter\n";
-                       texrow.newline();
-                       LFile += "\\def\\input@path{{" + original_path
-                                + "/}}\n";
-                       texrow.newline();
-                       LFile += "\\makeatother\n";
-                       texrow.newline();
-               }
-               
-               LFile += "\\documentclass";
-               
-               string options; // the document class options.
-               
-               if (tokenPos(tclass.opt_fontsize(), '|', params.fontsize) >= 0) {
-                       // only write if existing in list (and not default)
-                       options += params.fontsize;
-                       options += "pt,";
-               }
-               
-               
-               if (!params.use_geometry &&
-                   (params.paperpackage == BufferParams::PACKAGE_NONE)) {
-                       switch (params.papersize) {
-                       case BufferParams::PAPER_A4PAPER:
-                               options += "a4paper,";
-                               break;
-                       case BufferParams::PAPER_USLETTER:
-                               options += "letterpaper,";
-                               break;
-                       case BufferParams::PAPER_A5PAPER:
-                               options += "a5paper,";
-                               break;
-                       case BufferParams::PAPER_B5PAPER:
-                               options += "b5paper,";
-                               break;
-                       case BufferParams::PAPER_EXECUTIVEPAPER:
-                               options += "executivepaper,";
-                               break;
-                       case BufferParams::PAPER_LEGALPAPER:
-                               options += "legalpaper,";
-                               break;
-                       }
-               }
-
-               // if needed
-               if (params.sides != tclass.sides()) {
-                       switch (params.sides) {
-                       case LyXTextClass::OneSide:
-                               options += "oneside,";
-                               break;
-                       case LyXTextClass::TwoSides:
-                               options += "twoside,";
-                               break;
-                       }
-
-               }
-
-               // if needed
-               if (params.columns != tclass.columns()) {
-                       if (params.columns == 2)
-                               options += "twocolumn,";
-                       else
-                               options += "onecolumn,";
-               }
-
-               if (!params.use_geometry 
-                   && params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
-                       options += "landscape,";
-               
-               // language should be a parameter to \documentclass             
-               if (params.language != "default") {
-                       if (params.language == "hebrew")
-                               options += "english,";
-                       else if (lyxrc->rtl_support)
-                               options += "hebrew,";
-                       options += params.language + ',';
-               } else if (lyxrc->rtl_support)
-                       options += "hebrew,english,";
-
-               // the user-defined options
-               if (!params.options.empty()) {
-                       options += params.options + ',';
-               }
-               
-               if (!options.empty()){
-                       options = strip(options, ',');
-                       LFile += '[';
-                       LFile += options;
-                       LFile += ']';
-               }
-               
-               LFile += '{';
-               LFile += textclasslist.LatexnameOfClass(params.textclass);
-               LFile += "}\n";
-               texrow.newline();
-               // end of \documentclass defs
-               
-               // font selection must be done before loading fontenc.sty
-               if (params.fonts != "default") {
-                       LFile += "\\usepackage{" + params.fonts + "}\n";
-                       texrow.newline();
-               }
-               // this one is not per buffer
-               if (lyxrc->fontenc != "default") {
-                       LFile += "\\usepackage[" + lyxrc->fontenc
-                                + "]{fontenc}\n";
-                       texrow.newline();
-               }
-               if (params.inputenc != "default") {
-                       LFile += "\\usepackage[" + params.inputenc
-                                + "]{inputenc}\n";
-                       texrow.newline();
-               }
-               
-               /* at the very beginning the text parameters */
-               if (params.paperpackage != BufferParams::PACKAGE_NONE) {
-                       switch (params.paperpackage) {
-                       case BufferParams::PACKAGE_A4:
-                               LFile += "\\usepackage{a4}\n";
-                               texrow.newline();
-                               break;
-                       case BufferParams::PACKAGE_A4WIDE:
-                               LFile += "\\usepackage{a4wide}\n";
-                               texrow.newline();
-                               break;
-                       case BufferParams::PACKAGE_WIDEMARGINSA4:
-                               LFile += "\\usepackage[widemargins]{a4}\n";
-                               texrow.newline();
-                               break;
-                       }
-               }
-               if (params.use_geometry) {
-                       LFile += "\\usepackage{geometry}\n";
-                       texrow.newline();
-                       LFile += "\\geometry{verbose";
-                       if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
-                               LFile += ",landscape";
-                       switch (params.papersize2) {
-                       case BufferParams::VM_PAPER_CUSTOM:
-                               if (!params.paperwidth.empty())
-                                       LFile += ",paperwidth="
-                                                + params.paperwidth;
-                               if (!params.paperheight.empty())
-                                       LFile += ",paperheight="
-                                                + params.paperheight;
-                               break;
-                       case BufferParams::VM_PAPER_USLETTER:
-                               LFile += ",letterpaper";
-                               break;
-                       case BufferParams::VM_PAPER_USLEGAL:
-                               LFile += ",legalpaper";
-                               break;
-                       case BufferParams::VM_PAPER_USEXECUTIVE:
-                               LFile += ",executivepaper";
-                               break;
-                       case BufferParams::VM_PAPER_A3:
-                               LFile += ",a3paper";
-                               break;
-                       case BufferParams::VM_PAPER_A4:
-                               LFile += ",a4paper";
-                               break;
-                       case BufferParams::VM_PAPER_A5:
-                               LFile += ",a5paper";
-                               break;
-                       case BufferParams::VM_PAPER_B3:
-                               LFile += ",b3paper";
-                               break;
-                       case BufferParams::VM_PAPER_B4:
-                               LFile += ",b4paper";
-                               break;
-                       case BufferParams::VM_PAPER_B5:
-                               LFile += ",b5paper";
-                               break;
-                       default:
-                               // default papersize ie BufferParams::VM_PAPER_DEFAULT
-                               switch (lyxrc->default_papersize) {
-                               case BufferParams::PAPER_DEFAULT: // keep compiler happy
-                               case BufferParams::PAPER_USLETTER:
-                                       LFile += ",letterpaper";
-                                       break;
-                               case BufferParams::PAPER_LEGALPAPER:
-                                       LFile += ",legalpaper";
-                                       break;
-                               case BufferParams::PAPER_EXECUTIVEPAPER:
-                                       LFile += ",executivepaper";
-                                       break;
-                               case BufferParams::PAPER_A3PAPER:
-                                       LFile += ",a3paper";
-                                       break;
-                               case BufferParams::PAPER_A4PAPER:
-                                       LFile += ",a4paper";
-                                       break;
-                               case BufferParams::PAPER_A5PAPER:
-                                       LFile += ",a5paper";
-                                       break;
-                               case BufferParams::PAPER_B5PAPER:
-                                       LFile += ",b5paper";
-                                       break;
-                               }
-                       }
-                       if (!params.topmargin.empty())
-                               LFile += ",tmargin=" + params.topmargin;
-                       if (!params.bottommargin.empty())
-                               LFile += ",bmargin=" + params.bottommargin;
-                       if (!params.leftmargin.empty())
-                               LFile += ",lmargin=" + params.leftmargin;
-                       if (!params.rightmargin.empty())
-                               LFile += ",rmargin=" + params.rightmargin;
-                       if (!params.headheight.empty())
-                               LFile += ",headheight=" + params.headheight;
-                       if (!params.headsep.empty())
-                               LFile += ",headsep=" + params.headsep;
-                       if (!params.footskip.empty())
-                               LFile += ",footskip=" + params.footskip;
-                       LFile += "}\n";
-                       texrow.newline();
-               }
-               if (params.use_amsmath
-                   && !prefixIs(textclasslist.LatexnameOfClass(params.textclass), "ams")) {
-                       LFile += "\\usepackage{amsmath}\n";
-               }
-
-               if (tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle) >= 0) {
-                       if (params.pagestyle == "fancy") {
-                               LFile += "\\usepackage{fancyhdr}\n";
-                               texrow.newline();
-                       }
-                       LFile += "\\pagestyle{" + params.pagestyle + "}\n";
-                       texrow.newline();
-               }
-
-               // We try to load babel late, in case it interferes
-               // with other packages.
-               if (params.language != "default" || lyxrc->rtl_support ) {
-                       LFile += "\\usepackage{babel}\n";
-                       texrow.newline();
-               }
-
-               if (params.secnumdepth != tclass.secnumdepth()) {
-                       LFile += "\\setcounter{secnumdepth}{";
-                       LFile += tostr(params.secnumdepth);
-                       LFile += "}\n";
-                       texrow.newline();
-               }
-               if (params.tocdepth != tclass.tocdepth()) {
-                       LFile += "\\setcounter{tocdepth}{";
-                       LFile += tostr(params.tocdepth);
-                       LFile += "}\n";
-                       texrow.newline();
-               }
-               
-               if (params.paragraph_separation) {
-                       switch (params.defskip.kind()) {
-                       case VSpace::SMALLSKIP: 
-                               LFile += "\\setlength\\parskip{\\smallskipamount}\n";
-                               break;
-                       case VSpace::MEDSKIP:
-                               LFile += "\\setlength\\parskip{\\medskipamount}\n";
-                               break;
-                       case VSpace::BIGSKIP:
-                               LFile += "\\setlength\\parskip{\\bigskipamount}\n";
-                               break;
-                       case VSpace::LENGTH:
-                               LFile += "\\setlength\\parskip{"
-                                        + params.defskip.length().asLatexString()
-                                        + "}\n";
-                               break;
-                       default: // should never happen // Then delete it.
-                               LFile += "\\setlength\\parskip{\\medskipamount}\n";
-                               break;
-                       }
-                       texrow.newline();
-                       
-                       LFile += "\\setlength\\parindent{0pt}\n";
-                       texrow.newline();
-               }
-
-               // Write out what we've generated so far...and reset LFile
-               ofs << LFile;
-               LFile.clear(); 
-
-               // Now insert the LyX specific LaTeX commands...
-               string preamble, tmppreamble;
-
-               // The optional packages;
-               preamble = features.getPackages(params);
-
-               // this might be useful...
-               preamble += "\n\\makeatletter\n\n";
-
-               // Some macros LyX will need
-               tmppreamble = features.getMacros(params);
-
-               if (!tmppreamble.empty()) {
-                       preamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
-                               "LyX specific LaTeX commands.\n"
-                               + tmppreamble + '\n';
-               }
-
-               // the text class specific preamble 
-               tmppreamble = features.getTClassPreamble(params);
-               if (!tmppreamble.empty()) {
-                       preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
-                               "Textclass specific LaTeX commands.\n"
-                               + tmppreamble + '\n';
-               }
-
-               /* the user-defined preamble */
-               if (!params.preamble.empty()) {
-                       preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
-                               "User specified LaTeX commands.\n"
-                               + params.preamble + '\n';
-               }
-
-               preamble += "\\makeatother\n\n";
-
-               // Itemize bullet settings need to be last in case the user
-               // defines their own bullets that use a package included
-               // in the user-defined preamble -- ARRae
-               // Actually it has to be done much later than that
-               // since some packages like frenchb make modifications
-               // at \begin{document} time -- JMarc 
-               string bullets_def;
-               for (int i = 0; i < 4; ++i) {
-                       if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
-                               if (bullets_def.empty())
-                                       bullets_def="\\AtBeginDocument{\n";
-                               bullets_def += "  \\renewcommand{\\labelitemi";
-                               switch (i) {
-                               // `i' is one less than the item to modify
-                               case 0:
-                                       break;
-                               case 1:
-                                       bullets_def += 'i';
-                                       break;
-                               case 2:
-                                       bullets_def += "ii";
-                                       break;
-                               case 3:
-                                       bullets_def += 'v';
-                                       break;
-                               }
-                               bullets_def += "}{" + 
-                                 params.user_defined_bullets[i].getText() 
-                                 + "}\n";
-                       }
-               }
-
-               if (!bullets_def.empty())
-                 preamble += bullets_def + "}\n\n";
-
-               for (int j = countChar(preamble, '\n'); j-- ;) {
-                       texrow.newline();
-               }
-
-               ofs << preamble;
-
-               // make the body.
-               LFile += "\\begin{document}\n\n";
-               texrow.newline();
-               texrow.newline();
-       } // only_body
-       lyxerr.debug() << "preamble finished, now the body." << endl;
-       
-       bool was_title = false;
-       bool already_title = false;
-       string ftnote;
-       TexRow ft_texrow;
-       int ftcount = 0;
-       int loop_count = 0;
-
-       LyXParagraph * par = paragraph;
-
-       // if only_body
-       while (par) {
-               ++loop_count;
-               if (par->IsDummy())
-                       lyxerr[Debug::LATEX] << "Error in MakeLateXFile."
-                                            << endl;
-               LyXLayout const & layout =
-                       textclasslist.Style(params.textclass,
-                                           par->layout);
-           
-               if (layout.intitle) {
-                       if (already_title) {
-                               lyxerr <<"Error in MakeLatexFile: You"
-                                       " should not mix title layouts"
-                                       " with normal ones." << endl;
-                       } else
-                               was_title = true;
-               } else if (was_title && !already_title) {
-                       LFile += "\\maketitle\n";
-                       texrow.newline();
-                       already_title = true;
-                       was_title = false;                  
-               }
-               // We are at depth 0 so we can just use
-               // ordinary \footnote{} generation
-               // flag this with ftcount
-               ftcount = -1;
-               if (layout.isEnvironment()
-                    || par->pextra_type != LyXParagraph::PEXTRA_NONE) {
-                       par = par->TeXEnvironment(LFile, texrow,
-                                                 ftnote, ft_texrow, ftcount);
-               } else {
-                       par = par->TeXOnePar(LFile, texrow,
-                                            ftnote, ft_texrow, ftcount);
-               }
-
-               // Write out what we've generated...and reset LFile
-               if (ftcount >= 1) {
-                       if (ftcount > 1) {
-                               LFile += "\\addtocounter{footnote}{-";
-                               LFile += tostr(ftcount - 1);
-                               LFile += '}';
-                       }
-                       LFile += ftnote;
-                       texrow += ft_texrow;
-                       ftnote.clear();
-                       ft_texrow.reset();
-                       ftcount = 0;
-               }
-               if (loop_count == 2) {
-                       // fwrite()ing every second time through the loop
-                       // gains a few extra % of speed; going higher than
-                       // 2 will slow things down again.  I'll look at
-                       // LFile.length() in a future revision.  ARRae
-                       ofs << LFile;
-                       LFile.clear();
-                       loop_count = 0;
-               }
-       }
-
-       // It might be that we only have a title in this document
-       if (was_title && !already_title) {
-               LFile += "\\maketitle\n";
-               texrow.newline();
-       }
-
-       if (!only_body) {
-               LFile += "\\end{document}\n";
-               texrow.newline();
-       
-               lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
-       } else {
-               lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
-                                    << endl;
-       }
-
-       // Just to be sure. (Asger)
-       texrow.newline();
-
-       // Write out what we've generated...and reset LFile
-       ofs << LFile;
-       LFile.clear();
-
-       // tex_code_break_column's value is used to decide
-       // if we are in batchmode or not (within mathed_write()
-       // in math_write.C) so we must set it to a non-zero
-       // value when we leave otherwise we save incorrect .lyx files.
-       tex_code_break_column = lyxrc->ascii_linelen;
-
-       // How to check if the close went ok when using fstreams
-       ofs.close();
-       lyxerr.debug() << "Finished making latex file." << endl;
-}
-#endif
-
-
-bool Buffer::isLatex() const
-{
-       return textclasslist.TextClass(params.textclass).outputType() == LATEX;
-}
-
-
-bool Buffer::isLinuxDoc() const
-{
-       return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC;
-}
-
-
-bool Buffer::isLiterate() const
-{
-       return textclasslist.TextClass(params.textclass).outputType() == LITERATE;
-}
-
-
-bool Buffer::isDocBook() const
-{
-       return textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
-}
-
-
-bool Buffer::isSGML() const
-{
-       return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC ||
-              textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
-}
-
-
-void Buffer::sgmlOpenTag(ostream & os, int depth,
-                        string const & latexname) const
-{
-       os << string(depth, ' ') << "<" << latexname << ">\n";
-}
-
-
-void Buffer::sgmlCloseTag(ostream & os, int depth,
-                         string const & latexname) const
-{
-       os << string(depth, ' ') << "</" << latexname << ">\n";
-}
-
-
-void Buffer::makeLinuxDocFile(string const & fname, int column)
-{
-       LyXParagraph * par = paragraph;
-
-       string top_element = textclasslist.LatexnameOfClass(params.textclass);
-       string environment_stack[10];
-        string item_name;
-
-       int depth = 0;              /* paragraph depth */
-
-       ofstream ofs(fname.c_str());
-
-       if (!ofs) {
-               WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
-               return;
-       }
-   
-       tex_code_break_column = column; 
-       texrow.reset();
-   
-       if (params.preamble.empty()) {
-               ofs << "<!doctype linuxdoc system>\n\n";
-       }
-       else {
-               ofs << "<!doctype linuxdoc system \n [ "
-                   << params.preamble << " \n]>\n\n";
-       }
-
-       ofs << "<!-- "  << LYX_DOCVERSION 
-           << " created this file. For more info see http://www.lyx.org/"
-           << " -->\n";
-
-       if(params.options.empty())
-               sgmlOpenTag(ofs, 0, top_element);
-       else {
-               string top = top_element;
-               top += " ";
-               top += params.options;
-               sgmlOpenTag(ofs, 0, top);
-       }
-
-       while (par) {
-               int desc_on = 0;            /* description mode*/
-               LyXLayout const & style =
-                       textclasslist.Style(users->buffer()->params.textclass,
-                                           par->layout);
-               par->AutoDeleteInsets();
-
-               /* treat <toc> as a special case for compatibility with old code */
-               if (par->GetChar(0) == LyXParagraph::META_INSET) {
-                       Inset * inset = par->GetInset(0);
-                       char  lyx_code = inset->LyxCode();
-                       if (lyx_code == Inset::TOC_CODE){
-                               string temp = "toc";
-                               sgmlOpenTag(ofs, depth, temp);
-
-                               par = par->next;
-                               linuxDocHandleFootnote(ofs, par, depth);
-                               continue;
+
+       while (par) {
+               int desc_on = 0;            /* description mode*/
+               LyXLayout const & style =
+                       textclasslist.Style(users->buffer()->params.textclass,
+                                           par->layout);
+               par->AutoDeleteInsets();
+
+               /* treat <toc> as a special case for compatibility with old code */
+               if (par->GetChar(0) == LyXParagraph::META_INSET) {
+                       Inset * inset = par->GetInset(0);
+                       char  lyx_code = inset->LyxCode();
+                       if (lyx_code == Inset::TOC_CODE){
+                               string temp = "toc";
+                               sgmlOpenTag(ofs, depth, temp);
+
+                               par = par->next;
+                               linuxDocHandleFootnote(ofs, par, depth);
+                               continue;
                        }
                }
 
@@ -2827,18 +2426,9 @@ void Buffer::DocBookHandleCaption(ostream & os, string & inner_tag,
            tpar->layout == textclasslist.NumberOfLayout(params.textclass,
                                                         "Caption").second) {
                sgmlOpenTag(os, depth + 1, inner_tag);
-#ifdef USE_OSTREAM_ONLY
                string extra_par;
                SimpleDocBookOnePar(os, extra_par, tpar,
                                    desc_on, depth + 2);
-#else
-               string tmp_par, extra_par;
-               SimpleDocBookOnePar(tmp_par, extra_par, tpar,
-                                   desc_on, depth + 2);
-               tmp_par = strip(tmp_par);
-               tmp_par = frontStrip(tmp_par);
-               os << tmp_par;
-#endif
                sgmlCloseTag(os, depth+1, inner_tag);
                if(!extra_par.empty())
                        os << extra_par;
@@ -2854,9 +2444,7 @@ void Buffer::DocBookHandleFootnote(ostream & os, LyXParagraph * & par,
        bool inner_span = false;
        int desc_on = 4;
 
-       // This is not how I like to see enums. They should not be anonymous
-       // and variables of its type should not be declared right after the
-       // last brace. (Lgb)
+       // Someone should give this enum a proper name (Lgb)
        enum SOME_ENUM {
                NO_ONE,
                FOOTNOTE_LIKE,
@@ -2873,8 +2461,8 @@ void Buffer::DocBookHandleFootnote(ostream & os, LyXParagraph * & par,
                                if(!tmp_par.empty()) {
                                        os << tmp_par;
                                        tmp_par.clear();
-                                       sgmlCloseTag(os, depth+1, inner_tag);
-                                       sgmlOpenTag(os, depth+1, inner_tag);
+                                       sgmlCloseTag(os, depth + 1, inner_tag);
+                                       sgmlOpenTag(os, depth + 1, inner_tag);
                                }
                        }
                        else
@@ -2926,11 +2514,11 @@ void Buffer::DocBookHandleFootnote(ostream & os, LyXParagraph * & par,
                        }
                }
                // ignore all caption here, we processed them above!!!
-               if (par->layout != textclasslist.NumberOfLayout(params.textclass,
-                                                          "Caption").second) {
-#ifdef USE_OSTREAM_ONLY
+               if (par->layout != textclasslist
+                   .NumberOfLayout(params.textclass,
+                                   "Caption").second) {
 #ifdef HAVE_SSTREAM
-                       ostringstream ost;
+                       std::ostringstream ost;
 #else
                        ostrstream ost;
 #endif
@@ -2943,8 +2531,6 @@ void Buffer::DocBookHandleFootnote(ostream & os, LyXParagraph * & par,
                        char * ctmp = ost.str();
                        tmp_par += ctmp;
                        delete [] ctmp;
-#endif
-#else
 #endif
                }
                tmp_par = frontStrip(strip(tmp_par));
@@ -2975,6 +2561,7 @@ void Buffer::push_tag(ostream & os, char const * tag,
                os << "<" << stack[i] << ">";
 }
 
+
 void Buffer::pop_tag(ostream & os, char const * tag,
                      int & pos, char stack[5][3])
 {
@@ -3005,7 +2592,7 @@ void linux_doc_line_break(ostream & os, unsigned int & colcount,
                          const unsigned int newcol)
 {
        colcount += newcol;
-       if (colcount > lyxrc->ascii_linelen) {
+       if (colcount > lyxrc.ascii_linelen) {
                os << "\n";
                colcount = newcol; // assume write after this call
        }
@@ -3151,20 +2738,13 @@ void Buffer::SimpleLinuxDocOnePar(ostream & os, LyXParagraph * par,
       
                if (font2.latex() == LyXFont::ON) {
                        // "TeX"-Mode on == > SGML-Mode on.
-                       if (c!= '\0')
+                       if (c != '\0')
                                os << c; // see LaTeX-Generation...
                        ++char_line_count;
                } else if (c == LyXParagraph::META_INSET) {
                        inset = par->GetInset(i);
-#ifdef USE_OSTREAM_ONLY
                        inset->Linuxdoc(os);
-#else
-                       string tmp_out;
-                       inset->Linuxdoc(tmp_out);
-                       os << tmp_out;
-#endif
-               }
-               else {
+               } else {
                        string sgml_string;
                        if (par->linuxDocConvertChar(c, sgml_string)
                            && !style.free_spacing) { // in freespacing
@@ -3450,24 +3030,12 @@ void Buffer::makeDocBookFile(string const & fname, int column)
                }
 
                do {
-#ifdef USE_OSTREAM_ONLY
                        string extra_par;
                        SimpleDocBookOnePar(ofs, extra_par, par, desc_on,
                                            depth + 1 + command_depth);
                        par = par->next;
                        DocBookHandleFootnote(ofs, par,
                                              depth + 1 + command_depth);
-#else
-                       string tmp_par, extra_par;
-
-                       SimpleDocBookOnePar(tmp_par, extra_par, par, desc_on,
-                                           depth + 1 + command_depth);
-                       ofs << tmp_par;
-
-                       par = par->next;
-                       DocBookHandleFootnote(ofs, par,
-                                             depth + 1 + command_depth);
-#endif
                }
                while(par && par->IsDummy());
 
@@ -3529,7 +3097,6 @@ void Buffer::makeDocBookFile(string const & fname, int column)
 }
 
 
-#ifdef USE_OSTREAM_ONLY
 void Buffer::SimpleDocBookOnePar(ostream & os, string & extra,
                                 LyXParagraph * par, int & desc_on,
                                 int const depth) 
@@ -3538,56 +3105,52 @@ void Buffer::SimpleDocBookOnePar(ostream & os, string & extra,
                par->SimpleDocBookOneTablePar(os, extra, desc_on, depth);
                return;
        }
-       LyXFont font1, font2;
-       char c;
-       Inset * inset;
-       LyXParagraph::size_type main_body;
-       int j;
-       //string emph = "emphasis";
+
        bool emph_flag = false;
-       int char_line_count = 0;
 
        LyXLayout const & style = textclasslist.Style(params.textclass,
                                                      par->GetLayout());
 
+       LyXParagraph::size_type main_body;
        if (style.labeltype != LABEL_MANUAL)
                main_body = 0;
        else
                main_body = par->BeginningOfMainBody();
 
        // gets paragraph main font
-       if (main_body > 0)
-               font1 = style.labelfont;
-       else
-               font1 = style.font;
-
-       char_line_count = depth;
+       //if (main_body > 0)
+       //      font1 = style.labelfont;
+       //else
+       //      font1 = style.font;
+       LyXFont font1 = main_body > 0 ? style.labelfont : style.font;
+       
+       int char_line_count = depth;
        if(!style.free_spacing)
-               for (j = 0; j < depth; ++j)
+               for (int j = 0; j < depth; ++j)
                        os << ' ';
 
        // parsing main loop
        for (LyXParagraph::size_type i = 0;
             i < par->size(); ++i) {
-               font2 = par->getFont(i);
+               LyXFont font2 = par->getFont(i);
 
                // handle <emphasis> tag
                if (font1.emph() != font2.emph() && i) {
                        if (font2.emph() == LyXFont::ON) {
                                os << "<emphasis>";
-                               emph_flag= true;
+                               emph_flag = true;
                        }else {
                                os << "</emphasis>";
-                               emph_flag= false;
+                               emph_flag = false;
                        }
                }
       
-               c = par->GetChar(i);
+               char c = par->GetChar(i);
 
                if (c == LyXParagraph::META_INSET) {
-                       inset = par->GetInset(i);
+                       Inset * inset = par->GetInset(i);
 #ifdef HAVE_SSTREAM
-                       ostringstream ost;
+                       std::ostringstream ost;
                        inset->DocBook(ost);
                        string tmp_out = ost.str().c_str();
 #else
@@ -3620,7 +3183,7 @@ void Buffer::SimpleDocBookOnePar(ostream & os, string & extra,
                        }
                } else if (font2.latex() == LyXFont::ON) {
                        // "TeX"-Mode on ==> SGML-Mode on.
-                       if (c!= '\0')
+                       if (c != '\0')
                                os << c;
                        ++char_line_count;
                }
@@ -3664,148 +3227,6 @@ void Buffer::SimpleDocBookOnePar(ostream & os, string & extra,
        }
        os << '\n';
 }
-#else
-void Buffer::SimpleDocBookOnePar(string & file, string & extra,
-                                LyXParagraph * par, int & desc_on,
-                                int const depth) 
-{
-       if (par->table) {
-               par->SimpleDocBookOneTablePar(file, extra, desc_on, depth);
-               return;
-       }
-       LyXFont font1, font2;
-       char c;
-       Inset * inset;
-       LyXParagraph::size_type main_body;
-       int j;
-       string emph= "emphasis";
-       bool emph_flag= false;
-       int char_line_count= 0;
-
-       LyXLayout const & style = textclasslist.Style(params.textclass,
-                                                     par->GetLayout());
-
-       if (style.labeltype != LABEL_MANUAL)
-               main_body = 0;
-       else
-               main_body = par->BeginningOfMainBody();
-
-       /* gets paragraph main font */
-       if (main_body > 0)
-               font1 = style.labelfont;
-       else
-               font1 = style.font;
-
-       char_line_count = depth;
-       if(!style.free_spacing)
-               for (j = 0; j < depth; ++j)
-                       file += ' ';
-
-       /* parsing main loop */
-       for (LyXParagraph::size_type i = 0;
-            i < par->size(); ++i) {
-               font2 = par->getFont(i);
-
-               /* handle <emphasis> tag */
-               if (font1.emph() != font2.emph() && i) {
-                       if (font2.emph() == LyXFont::ON) {
-                               file += "<emphasis>";
-                               emph_flag= true;
-                       }else {
-                               file += "</emphasis>";
-                               emph_flag= false;
-                       }
-               }
-      
-               c = par->GetChar(i);
-
-               if (c == LyXParagraph::META_INSET) {
-                       inset = par->GetInset(i);
-#ifdef USE_OSTREAM_ONLY
-#ifdef HAVE_SSTREAM
-                       ostringstream ost;
-                       inset->DocBook(ost);
-                       string tmp_out = ost.str().c_str();
-#else
-                       ostrstream ost;
-                       inset->DocBook(ost);
-                       ost << '\0';
-                       char * ctmp = ost.str();
-                       string tmp_out(ctmp);
-                       delete [] ctmp;
-#endif
-#else
-                       string tmp_out;
-                       inset->DocBook(tmp_out);
-#endif
-                       //
-                       // This code needs some explanation:
-                       // Two insets are treated specially
-                       //   label if it is the first element in a command paragraph
-                       //         desc_on == 3
-                       //   graphics inside tables or figure floats can't go on
-                       //   title (the equivalente in latex for this case is caption
-                       //   and title should come first
-                       //         desc_on == 4
-                       //
-                       if(desc_on!= 3 || i!= 0) {
-                               if(!tmp_out.empty() && tmp_out[0] == '@') {
-                                       if(desc_on == 4)
-                                               extra += frontStrip(tmp_out, '@');
-                                       else
-                                               file += frontStrip(tmp_out, '@');
-                               }
-                               else
-                                       file += tmp_out;
-                       }
-               } else if (font2.latex() == LyXFont::ON) {
-                       // "TeX"-Mode on ==> SGML-Mode on.
-                       if (c!= '\0')
-                               file += c;
-                       ++char_line_count;
-               }
-               else {
-                       string sgml_string;
-                       if (par->linuxDocConvertChar(c, sgml_string)
-                           && !style.free_spacing) { // in freespacing
-                                                    // mode, spaces are
-                                                    // non-breaking characters
-                               // char is ' '
-                               if (desc_on == 1) {
-                                       ++char_line_count;
-                                       file += '\n';
-                                       file += "</term><listitem><para>";
-                                       desc_on = 2;
-                               }
-                               else  {
-                                       file += c;
-                               }
-                       }
-                       else {
-                               file += sgml_string;
-                       }
-               }
-               font1 = font2;
-       }
-
-       /* needed if there is an optional argument but no contents */
-       if (main_body > 0 && main_body == par->size()) {
-               font1 = style.font;
-       }
-       if (emph_flag) {
-               file += "</emphasis>";
-       }
-       
-       /* resets description flag correctly */
-       switch(desc_on){
-       case 1:
-               /* <term> not closed... */
-               file += "</term>";
-               break;
-       }
-       file += '\n';
-}
-#endif
 
 
 int Buffer::runLaTeX()
@@ -3820,7 +3241,7 @@ int Buffer::runLaTeX()
        string path = OnlyPath(filename);
 
        string org_path = path;
-       if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
+       if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
                path = tmppath;  
        }
 
@@ -3836,8 +3257,8 @@ int Buffer::runLaTeX()
 
        // do the LaTex run(s)
        TeXErrors terr;
-       string latex_command = lyxrc->pdf_mode ?
-               lyxrc->pdflatex_command : lyxrc->latex_command;
+       string latex_command = lyxrc.pdf_mode ?
+               lyxrc.pdflatex_command : lyxrc.latex_command;
        LaTeX latex(latex_command, name, filepath);
        int res = latex.run(terr,
                            users->owner()->getMiniBuffer()); // running latex
@@ -3883,12 +3304,12 @@ int Buffer::runLiterate()
        string name = getLatexName();
         // get Literate-Filename
         string lit_name = ChangeExtension (getLatexName(), 
-                                          lyxrc->literate_extension, true);
+                                          lyxrc.literate_extension, true);
 
        string path = OnlyPath(filename);
 
        string org_path = path;
-       if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
+       if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
                path = tmppath;  
        }
 
@@ -3904,12 +3325,12 @@ int Buffer::runLiterate()
                markDviDirty();
        }
 
-       string latex_command = lyxrc->pdf_mode ?
-               lyxrc->pdflatex_command : lyxrc->latex_command;
+       string latex_command = lyxrc.pdf_mode ?
+               lyxrc.pdflatex_command : lyxrc.latex_command;
         Literate literate(latex_command, name, filepath, 
                          lit_name,
-                         lyxrc->literate_command, lyxrc->literate_error_filter,
-                         lyxrc->build_command, lyxrc->build_error_filter);
+                         lyxrc.literate_command, lyxrc.literate_error_filter,
+                         lyxrc.build_command, lyxrc.build_error_filter);
        TeXErrors terr;
        int res = literate.weave(terr, users->owner()->getMiniBuffer());
 
@@ -3954,12 +3375,12 @@ int Buffer::buildProgram()
         string name = getLatexName();
         // get Literate-Filename
         string lit_name = ChangeExtension(getLatexName(), 
-                                         lyxrc->literate_extension, true);
+                                         lyxrc.literate_extension, true);
  
         string path = OnlyPath(filename);
  
         string org_path = path;
-        if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
+        if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
                 path = tmppath;  
         }
  
@@ -3975,12 +3396,12 @@ int Buffer::buildProgram()
                 markNwDirty();
         }
 
-       string latex_command = lyxrc->pdf_mode ?
-               lyxrc->pdflatex_command : lyxrc->latex_command;
+       string latex_command = lyxrc.pdf_mode ?
+               lyxrc.pdflatex_command : lyxrc.latex_command;
         Literate literate(latex_command, name, filepath, 
                          lit_name,
-                         lyxrc->literate_command, lyxrc->literate_error_filter,
-                         lyxrc->build_command, lyxrc->build_error_filter);
+                         lyxrc.literate_command, lyxrc.literate_error_filter,
+                         lyxrc.build_command, lyxrc.build_error_filter);
         TeXErrors terr;
         int res = literate.build(terr, users->owner()->getMiniBuffer());
  
@@ -4028,7 +3449,7 @@ int Buffer::runChktex()
        string path = OnlyPath(filename);
 
        string org_path = path;
-       if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
+       if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
                path = tmppath;  
        }
 
@@ -4045,7 +3466,7 @@ int Buffer::runChktex()
        }
 
        TeXErrors terr;
-       Chktex chktex(lyxrc->chktex_command, name, filepath);
+       Chktex chktex(lyxrc.chktex_command, name, filepath);
        int res = chktex.run(terr); // run chktex
 
        if (res == -1) {
@@ -4072,7 +3493,7 @@ int Buffer::runChktex()
 #if 0
 void Buffer::RoffAsciiTable(ostream & os, LyXParagraph * par)
 {
-       LyXFont font1(LyXFont::ALL_INHERIT);
+       LyXFont font1(LyXFont::ALL_INHERIT,params.language_info);
        LyXFont font2;
        Inset * inset;
        LyXParagraph::size_type i;
@@ -4181,7 +3602,7 @@ void Buffer::RoffAsciiTable(ostream & os, LyXParagraph * par)
        }
        par->table->RoffEndOfCell(ofs, cell);
        ofs.close();
-       string cmd = lyxrc->ascii_roff_command + " >" + fname2;
+       string cmd = lyxrc.ascii_roff_command + " >" + fname2;
        cmd = subst(cmd, "$$FName", fname1);
        Systemcalls one(Systemcalls::System, cmd);
        if (!(lyxerr.debugging(Debug::ROFF))) {
@@ -4222,7 +3643,7 @@ void Buffer::RoffAsciiTable(ostream & os, LyXParagraph * par)
 /// changed Heinrich Bauer, 23/03/98
 bool Buffer::isDviClean() const
 {
-  if (lyxrc->use_tempdir)
+  if (lyxrc.use_tempdir)
     return dvi_clean_tmpd;
   else
     return dvi_clean_orgd;
@@ -4232,7 +3653,7 @@ bool Buffer::isDviClean() const
 /// changed Heinrich Bauer, 23/03/98
 void Buffer::markDviClean()
 {
-  if (lyxrc->use_tempdir)
+  if (lyxrc.use_tempdir)
     dvi_clean_tmpd = true;
   else
     dvi_clean_orgd = true;
@@ -4242,7 +3663,7 @@ void Buffer::markDviClean()
 /// changed Heinrich Bauer, 23/03/98
 void Buffer::markDviDirty()
 {
-  if (lyxrc->use_tempdir)
+  if (lyxrc.use_tempdir)
     dvi_clean_tmpd = false;
   else
     dvi_clean_orgd = false;
@@ -4300,7 +3721,7 @@ void Buffer::validate(LaTeXFeatures & features) const
        }
        
        if (lyxerr.debugging(Debug::LATEX)) {
-               features.showStruct(params);
+               features.showStruct();
        }
 }
 
@@ -4504,3 +3925,25 @@ void Buffer::Dispatch(int action, string const & argument)
 
        } // end of switch
 }
+
+void Buffer::ChangeLanguage(Language const * from, Language const * to)
+{
+
+       LyXParagraph * par = paragraph;
+       while (par) {
+               par->ChangeLanguage(from,to);
+               par = par->next;
+       }
+}
+
+bool Buffer::isMultiLingual()
+{
+
+       LyXParagraph * par = paragraph;
+       while (par) {
+               if (par->isMultiLingual())
+                       return true;
+               par = par->next;
+       }
+       return false;
+}