]> git.lyx.org Git - lyx.git/blobdiff - src/buffer.C
fix ru.po typo
[lyx.git] / src / buffer.C
index e789579d21dd6d967c2e7e10a391107603042eb9..c42098707bacd16f6a317ccef77d38358371ece2 100644 (file)
@@ -45,6 +45,7 @@
 #include "BufferView.h"
 #include "ParagraphParameters.h"
 #include "iterators.h"
+#include "lyxtextclasslist.h"
 
 #include "mathed/formulamacro.h"
 #include "mathed/formula.h"
 #include "support/filetools.h"
 #include "support/path.h"
 #include "support/os.h"
-#include "support/syscall.h"
 #include "support/lyxlib.h"
 #include "support/FileInfo.h"
 #include "support/lyxmanip.h"
+#include "support/lyxalgo.h" // for lyx::count
 
 #include <fstream>
 #include <iomanip>
@@ -147,21 +148,26 @@ extern int tex_code_break_column;
 
 
 Buffer::Buffer(string const & file, bool ronly)
+       : paragraph(0), lyx_clean(true), bak_clean(true),
+         unnamed(false), dep_clean(0), read_only(ronly),
+         filename_(file), users(0)
 {
        lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
-       filename = file;
-       filepath = OnlyPath(file);
-       paragraph = 0;
-       lyx_clean = true;
-       bak_clean = true;
-       dep_clean = 0;
-       read_only = ronly;
-       unnamed = false;
-       users = 0;
+//     filename = file;
+       filepath_ = OnlyPath(file);
+//     paragraph = 0;
+//     lyx_clean = true;
+//     bak_clean = true;
+//     dep_clean = 0;
+//     read_only = ronly;
+//     unnamed = false;
+//     users = 0;
        lyxvc.buffer(this);
-       if (read_only || (lyxrc.use_tempdir)) {
+       if (read_only || lyxrc.use_tempdir) {
                tmppath = CreateBufferTmpDir();
-       } else tmppath.erase();
+       } else {
+               tmppath.erase();
+       }
 }
 
 
@@ -193,7 +199,7 @@ Buffer::~Buffer()
 
 string const Buffer::getLatexName(bool no_path) const
 {
-       string const name = ChangeExtension(MakeLatexName(filename), ".tex");
+       string const name = ChangeExtension(MakeLatexName(fileName()), ".tex");
        if (no_path)
                return OnlyFilename(name);
        else
@@ -266,9 +272,9 @@ void Buffer::resetAutosaveTimers() const
 
 void Buffer::setFileName(string const & newfile)
 {
-       filename = MakeAbsPath(newfile);
-       filepath = OnlyPath(filename);
-       setReadonly(IsFileWriteable(filename) == 0);
+       filename_ = MakeAbsPath(newfile);
+       filepath_ = OnlyPath(filename_);
+       setReadonly(IsFileWriteable(filename_) == 0);
        updateTitles();
 }
 
@@ -286,6 +292,7 @@ struct ErtComp
        string contents;
        bool active;
        bool in_tabular;
+       LyXFont font;
 };
 
 std::stack<ErtComp> ert_stack;
@@ -330,7 +337,7 @@ bool Buffer::readLyXformat2(LyXLex & lex, Paragraph * par)
        } else {
                // We are inserting into an existing document
                users->text->breakParagraph(users);
-               first_par = users->text->firstParagraph();
+               first_par = users->text->ownerParagraph();
                pos = 0;
                markDirty();
                // We don't want to adopt the parameters from the
@@ -394,16 +401,13 @@ bool Buffer::readLyXformat2(LyXLex & lex, Paragraph * par)
 
 
 #ifndef NO_COMPABILITY
-void Buffer::insertErtContents(Paragraph * par, int & pos,
-                       LyXFont const & f, bool set_inactive) 
+void Buffer::insertErtContents(Paragraph * par, int & pos, bool set_inactive) 
 {
        if (!ert_comp.contents.empty()) {
                lyxerr[Debug::INSETS] << "ERT contents:\n'"
                                      << ert_comp.contents << "'" << endl;
                Inset * inset = new InsetERT(ert_comp.contents, true);
-               LyXFont font;
-               font.setLanguage(f.language());
-               par->insertInset(pos++, inset, font);
+               par->insertInset(pos++, inset, ert_comp.font);
                ert_comp.contents.erase();
        }
        if (set_inactive) {
@@ -456,16 +460,22 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
 #ifndef NO_COMPABILITY
                ert_comp.in_tabular = false;
                // Do the insetert.
-               insertErtContents(par, pos, font);
+               insertErtContents(par, pos);
 #endif
                lex.eatLine();
                string const layoutname = lex.getString();
+               //lyxerr << "Looking for layout '"
+               // << layoutname << "'!" << endl;
+               
                pair<bool, layout_type> pp
                  = textclasslist.NumberOfLayout(params.textclass, layoutname);
 
+               //lyxerr << "Result: " << pp.first << "/" << pp.second << endl;
+               
 #ifndef NO_COMPABILITY
                if (compare_no_case(layoutname, "latex") == 0) {
                        ert_comp.active = true;
+                       ert_comp.font = font;
                }
 #endif
 #ifdef USE_CAPTION
@@ -536,6 +546,9 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
                        } else {
                                // layout not found
                                // use default layout "Standard" (0)
+                               //lyxerr << "Layout '" << layoutname
+                               //       << "' was not found!" << endl;
+                               
                                par->layout = 0;
                                ++unknown_layouts;
                                string const s = _("Layout had to be changed from\n")
@@ -566,8 +579,8 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
 
 #ifndef NO_COMPABILITY
        } else if (token == "\\begin_float") {
-               insertErtContents(par, pos, font);
-               //insertErtContents(par, pos, font, false);
+               insertErtContents(par, pos);
+               //insertErtContents(par, pos, false);
                //ert_stack.push(ert_comp);
                //ert_comp = ErtComp();
                
@@ -657,7 +670,7 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
                inset->read(this, nylex);
                par->insertInset(pos, inset, font);
                ++pos;
-               insertErtContents(par, pos, font);
+               insertErtContents(par, pos);
 #endif
        } else if (token == "\\begin_deeper") {
                ++depth;
@@ -728,21 +741,25 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
                par->params().startOfAppendix(true);
        } else if (token == "\\paragraph_separation") {
                int tmpret = lex.findToken(string_paragraph_separation);
-               if (tmpret == -1) ++tmpret;
+               if (tmpret == -1)
+                       ++tmpret;
                if (tmpret != LYX_LAYOUT_DEFAULT) 
                        params.paragraph_separation =
                                static_cast<BufferParams::PARSEP>(tmpret);
        } else if (token == "\\defskip") {
                lex.nextToken();
                params.defskip = VSpace(lex.getString());
+#ifndef NO_COMPABILITY
        } else if (token == "\\epsfig") { // obsolete
                // Indeed it is obsolete, but we HAVE to be backwards
                // compatible until 0.14, because otherwise all figures
                // in existing documents are irretrivably lost. (Asger)
                params.readGraphicsDriver(lex);
+#endif
        } else if (token == "\\quotes_language") {
                int tmpret = lex.findToken(string_quotes_language);
-               if (tmpret == -1) ++tmpret;
+               if (tmpret == -1)
+                       ++tmpret;
                if (tmpret != LYX_LAYOUT_DEFAULT) {
                        InsetQuotes::quote_language tmpl = 
                                InsetQuotes::EnglishQ;
@@ -805,7 +822,8 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
                params.use_numerical_citations = lex.getInteger();
        } else if (token == "\\paperorientation") {
                int tmpret = lex.findToken(string_orientation);
-               if (tmpret == -1) ++tmpret;
+               if (tmpret == -1)
+                       ++tmpret;
                if (tmpret != LYX_LAYOUT_DEFAULT) 
                        params.orientation = static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
        } else if (token == "\\paperwidth") {
@@ -877,6 +895,7 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
                                //how can I put it back?
                }
        } else if (token == "\\bulletLaTeX") {
+               // The bullet class should be able to read this.
                lex.nextToken();
                int const index = lex.getInteger();
                lex.next();
@@ -893,6 +912,7 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
                        lex.next();
                        temp_str = lex.getString();
                }
+
                params.user_defined_bullets[index].setText(sum_str);
                params.temp_bullets[index].setText(sum_str);
        } else if (token == "\\secnumdepth") {
@@ -963,12 +983,13 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
                string const tok = lex.getString();
                if (tok == "no_latex") {
                        // Do the insetert.
-                       insertErtContents(par, pos, font);
+                       insertErtContents(par, pos);
                } else if (tok == "latex") {
                        ert_comp.active = true;
+                       ert_comp.font = font;
                } else if (tok == "default") {
                        // Do the insetert.
-                       insertErtContents(par, pos, font);
+                       insertErtContents(par, pos);
                } else {
                        lex.printError("Unknown LaTeX font flag "
                                       "`$$Token'");
@@ -1019,10 +1040,16 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
                }
        } else if (token == "\\added_space_top") {
                lex.nextToken();
-               par->params().spaceTop(VSpace(lex.getString()));
+               VSpace value = VSpace(lex.getString());
+               if ((value.length().len().value() != 0) ||
+                   (value.kind() != VSpace::LENGTH))
+                   par->params().spaceTop(value);
        } else if (token == "\\added_space_bottom") {
                lex.nextToken();
-               par->params().spaceBottom(VSpace(lex.getString()));
+               VSpace value = VSpace(lex.getString());
+               if ((value.length().len().value() != 0) ||
+                   (value.kind() != VSpace::LENGTH))
+                   par->params().spaceBottom(value);
 #ifndef NO_COMPABILITY
 #ifndef NO_PEXTRA_REALLY
        } else if (token == "\\pextra_type") {
@@ -1059,7 +1086,7 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
                // the inset isn't it? Lgb.
        } else if (token == "\\begin_inset") {
 #ifndef NO_COMPABILITY
-               insertErtContents(par, pos, font, false);
+               insertErtContents(par, pos, false);
                ert_stack.push(ert_comp);
                ert_comp = ErtComp();
 #endif
@@ -1067,7 +1094,7 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
 #ifndef NO_COMPABILITY
                ert_comp = ert_stack.top();
                ert_stack.pop();
-               insertErtContents(par, pos, font);
+               insertErtContents(par, pos);
 #endif
        } else if (token == "\\SpecialChar") {
                LyXLayout const & layout =
@@ -1105,7 +1132,7 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
                        // Since we cannot know it this is only a regular
                        // newline or a tabular cell delimter we have to
                        // handle the ERT here.
-                       insertErtContents(par, pos, font, false);
+                       insertErtContents(par, pos, false);
 
                        par->insertChar(pos, Paragraph::META_NEWLINE, font);
                        ++pos;
@@ -1161,7 +1188,7 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
 #ifndef NO_COMPABILITY
                // If we still have some ert active here we have to insert
                // it so we don't loose it. (Lgb)
-               insertErtContents(par, pos, font);
+               insertErtContents(par, pos);
 #endif
                the_end_read = true;
 #ifndef NO_COMPABILITY
@@ -1256,10 +1283,10 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
                        }
                        InsetMinipage * mini = new InsetMinipage;
                        mini->pos(static_cast<InsetMinipage::Position>(par->params().pextraAlignment()));
-                       mini->width(par->params().pextraWidth());
+                       mini->pageWidth(LyXLength(par->params().pextraWidth()));
                        if (!par->params().pextraWidthp().empty()) {
-                           lyxerr << "WP:" << mini->width() << endl;
-                           mini->width(tostr(par->params().pextraWidthp())+"%");
+                           lyxerr << "WP:" << mini->pageWidth().asString() << endl;
+                           mini->pageWidth(LyXLength((par->params().pextraWidthp())+"%"));
                        }
                        Paragraph * op = mini->firstParagraph();
                        mini->inset.paragraph(par);
@@ -1337,10 +1364,10 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
 
                InsetMinipage * mini = new InsetMinipage;
                mini->pos(static_cast<InsetMinipage::Position>(minipar->params().pextraAlignment()));
-               mini->width(minipar->params().pextraWidth());
+               mini->pageWidth(LyXLength(minipar->params().pextraWidth()));
                if (!par->params().pextraWidthp().empty()) {
-                   lyxerr << "WP:" << mini->width() << endl;
-                   mini->width(tostr(par->params().pextraWidthp())+"%");
+                   lyxerr << "WP:" << mini->pageWidth().asString() << endl;
+                   mini->pageWidth(LyXLength((par->params().pextraWidthp())+"%"));
                }
                mini->inset.paragraph(minipar);
                        
@@ -1491,8 +1518,8 @@ void Buffer::readInset(LyXLex & lex, Paragraph *& par,
                } else if (tmptok == "Formula") {
                        inset = new InsetFormula;
                } else if (tmptok == "Figure") { // Backward compatibility
-                       inset = new InsetFig(100, 100, *this);
-                       //inset = new InsetGraphics;
+//                     inset = new InsetFig(100, 100, *this);
+                       inset = new InsetGraphics;
                } else if (tmptok == "Graphics") {
                        inset = new InsetGraphics;
                } else if (tmptok == "Info") {// backwards compatibility
@@ -1503,7 +1530,7 @@ void Buffer::readInset(LyXLex & lex, Paragraph *& par,
                } else if (tmptok == "Note") {
                        inset = new InsetNote;
                } else if (tmptok == "Include") {
-                       InsetCommandParams p( "Include" );
+                       InsetCommandParams p("Include");
                        inset = new InsetInclude(p, *this);
                } else if (tmptok == "ERT") {
                        inset = new InsetERT;
@@ -1680,7 +1707,7 @@ bool Buffer::writeFile(string const & fname, bool flag) const
        // warnings, only cerr.
        // Needed for autosave in background or panic save (Matthias 120496)
 
-       if (read_only && (fname == filename)) {
+       if (read_only && (fname == fileName())) {
                // Here we should come with a question if we should
                // perform the write anyway.
                if (flag)
@@ -1904,8 +1931,10 @@ string const Buffer::asciiParagraph(Paragraph const * par,
                {
                        Inset const * inset = par->getInset(i);
                        if (inset) {
-                               if (linelen > 0)
+                               if (linelen > 0) {
                                        buffer << word.str();
+                                       word.str("");
+                               }
                                if (inset->ascii(this, buffer, linelen)) {
                                        // to be sure it breaks paragraph
                                        currlinelen += linelen;
@@ -2004,8 +2033,10 @@ void Buffer::writeFileAscii(ostream & ofs, int linelen)
        ofs << "\n";
 }
 
+
 bool use_babel;
 
+
 void Buffer::makeLaTeXFile(string const & fname, 
                           string const & original_path,
                           bool nice, bool only_body)
@@ -2055,7 +2086,7 @@ void Buffer::makeLaTeXFile(string const & fname,
        // original_path is set. This is done for usual tex-file, but not
        // for nice-latex-file. (Matthias 250696)
        if (!only_body) {
-               if (!nice){
+               if (!nice) {
                        // code for usual, NOT nice-latex-file
                        ofs << "\\batchmode\n"; // changed
                        // from \nonstopmode
@@ -2154,7 +2185,7 @@ void Buffer::makeLaTeXFile(string const & fname,
                }
 
                string strOptions(options.str().c_str());
-               if (!strOptions.empty()){
+               if (!strOptions.empty()) {
                        strOptions = strip(strOptions, ',');
                        ofs << '[' << strOptions << ']';
                }
@@ -2306,12 +2337,6 @@ void Buffer::makeLaTeXFile(string const & fname,
                        texrow.newline();
                }
 
-               if (features.isRequired("amsstyle")
-                           && !tclass.provides(LyXTextClass::amsmath)) {
-                       ofs << "\\usepackage{amsmath}\n";
-                       texrow.newline();
-               }
-               
                if (tokenPos(tclass.opt_pagestyle(),
                             '|', params.pagestyle) >= 0) {
                        if (params.pagestyle == "fancy") {
@@ -2430,7 +2455,9 @@ void Buffer::makeLaTeXFile(string const & fname,
                if (!bullets_def.empty())
                  preamble += bullets_def + "}\n\n";
 
-               for (int j = countChar(preamble, '\n'); j-- ;) {
+               int const nlines =
+                       int(lyx::count(preamble.begin(), preamble.end(), '\n'));
+               for (int j = 0; j != nlines; ++j) {
                        texrow.newline();
                }
 
@@ -2508,33 +2535,41 @@ void Buffer::makeLaTeXFile(string const & fname,
 // LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
 //
 void Buffer::latexParagraphs(ostream & ofs, Paragraph * par,
-                            Paragraph * endpar, TexRow & texrow) const
+                             Paragraph * endpar, TexRow & texrow) const
 {
        bool was_title = false;
        bool already_title = false;
 
        // if only_body
        while (par != endpar) {
-               LyXLayout const & layout =
-                       textclasslist.Style(params.textclass,
-                                           par->layout);
-           
-               if (layout.intitle) {
-                       if (already_title) {
-                               lyxerr <<"Error in latexParagraphs: You"
-                                       " should not mix title layouts"
-                                       " with normal ones." << endl;
-                       } else
-                               was_title = true;
-               } else if (was_title && !already_title) {
-                       ofs << "\\maketitle\n";
-                       texrow.newline();
-                       already_title = true;
-                       was_title = false;                  
-               }
-               
-               if (layout.isEnvironment()) {
-                       par = par->TeXEnvironment(this, params, ofs, texrow);
+               Inset * in = par->inInset();
+               // well we have to check if we are in an inset with unlimited
+               // lenght (all in one row) if that is true then we don't allow
+               // any special options in the paragraph and also we don't allow
+               // any environment other then "Standard" to be valid!
+               if ((in == 0) || !in->forceDefaultParagraphs(in)) {
+                       LyXLayout const & layout =
+                               textclasslist.Style(params.textclass, par->layout);
+                       
+                       if (layout.intitle) {
+                               if (already_title) {
+                                       lyxerr <<"Error in latexParagraphs: You"
+                                               " should not mix title layouts"
+                                               " with normal ones." << endl;
+                               } else
+                                       was_title = true;
+                       } else if (was_title && !already_title) {
+                               ofs << "\\maketitle\n";
+                               texrow.newline();
+                               already_title = true;
+                               was_title = false;                  
+                       }
+                       
+                       if (layout.isEnvironment()) {
+                               par = par->TeXEnvironment(this, params, ofs, texrow);
+                       } else {
+                               par = par->TeXOnePar(this, params, ofs, texrow, false);
+                       }
                } else {
                        par = par->TeXOnePar(this, params, ofs, texrow, false);
                }
@@ -2657,7 +2692,7 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
                if (par->isInset(0)) {
                        Inset * inset = par->getInset(0);
                        Inset::Code lyx_code = inset->lyxCode();
-                       if (lyx_code == Inset::TOC_CODE){
+                       if (lyx_code == Inset::TOC_CODE) {
                                string const temp = "toc";
                                sgmlOpenTag(ofs, depth, temp);
 
@@ -2693,7 +2728,7 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
                                          _("Error : Wrong depth for"
                                            " LatexType Command.\n"));
 
-                       if (!environment_stack[depth].empty()){
+                       if (!environment_stack[depth].empty()) {
                                sgmlCloseTag(ofs, depth,
                                             environment_stack[depth]);
                                ofs << "</p>";
@@ -2826,7 +2861,7 @@ void operator|=(PAR_TAG & p1, PAR_TAG const & p2)
 inline
 void reset(PAR_TAG & p1, PAR_TAG const & p2)
 {
-       p1 = static_cast<PAR_TAG>( p1 & ~p2);
+       p1 = static_cast<PAR_TAG>(p1 & ~p2);
 }
 
 } // namespace anon
@@ -2951,7 +2986,7 @@ void Buffer::simpleLinuxDocOnePar(ostream & os,
                }
 
                list < PAR_TAG > temp;
-               while (!tag_state.empty() && tag_close ) {
+               while (!tag_state.empty() && tag_close) {
                        PAR_TAG k =  tag_state.top();
                        tag_state.pop();
                        os << "</" << tag_name(k) << ">";
@@ -3192,7 +3227,7 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
                        if (par->isInset(0)) {
                                Inset * inset = par->getInset(0);
                                Inset::Code lyx_code = inset->lyxCode();
-                               if (lyx_code == Inset::LABEL_CODE){
+                               if (lyx_code == Inset::LABEL_CODE) {
                                        command_name += " id=\"";
                                        command_name += (static_cast<InsetCommand *>(inset))->getContents();
                                        command_name += "\"";
@@ -3216,7 +3251,7 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
                        }
 
                        if (environment_stack[depth] != style.latexname()) {
-                               if(environment_stack.size() == depth + 1) {
+                               if (environment_stack.size() == depth + 1) {
                                        environment_stack.push_back("!-- --");
                                        environment_inner.push_back("!-- --");
                                }
@@ -3239,7 +3274,7 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
                        
                        if (style.latextype == LATEX_ENVIRONMENT) {
                                if (!style.latexparam().empty()) {
-                                       if(style.latexparam() == "CDATA")
+                                       if (style.latexparam() == "CDATA")
                                                ofs << "<![CDATA[";
                                        else
                                                sgmlOpenTag(ofs, depth + command_depth,
@@ -3289,7 +3324,7 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
                        break;
                case LATEX_ENVIRONMENT:
                        if (!style.latexparam().empty()) {
-                               if(style.latexparam() == "CDATA")
+                               if (style.latexparam() == "CDATA")
                                        ofs << "]]>";
                                else
                                        sgmlCloseTag(ofs, depth + command_depth,
@@ -3363,17 +3398,17 @@ void Buffer::simpleDocBookOnePar(ostream & os,
                        if (font.emph() == LyXFont::ON) {
                                os << "<emphasis>";
                                emph_flag = true;
-                       }else if(i) {
+                       } else if (i) {
                                os << "</emphasis>";
                                emph_flag = false;
                        }
                }
       
 
-               if ( par->isInset(i) ) {
+               if (par->isInset(i)) {
                        Inset * inset = par->getInset(i);
                        // don't print the inset in position 0 if desc_on == 3 (label)
-                       if ( i || desc_on != 3)
+                       if (i || desc_on != 3)
                                inset->docbook(this, os);
                } else {
                        char c = par->getChar(i);
@@ -3382,7 +3417,7 @@ void Buffer::simpleDocBookOnePar(ostream & os,
 
                        if (style.pass_thru) {
                                os << c;
-                       } else if(style.free_spacing || par->isFreeSpacing() || c != ' ') {
+                       } else if (style.free_spacing || par->isFreeSpacing() || c != ' ') {
                                        os << sgml_string;
                        } else if (desc_on ==1) {
                                ++char_line_count;
@@ -3404,7 +3439,7 @@ void Buffer::simpleDocBookOnePar(ostream & os,
                // <term> not closed...
                os << "</term>";
        }
-       if(style.free_spacing) os << '\n';
+       if (style.free_spacing) os << '\n';
 }
 
 
@@ -3419,7 +3454,7 @@ int Buffer::runChktex()
 
        // get LaTeX-Filename
        string const name = getLatexName();
-       string path = OnlyPath(filename);
+       string path = filePath();
 
        string const org_path = path;
        if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
@@ -3436,7 +3471,7 @@ int Buffer::runChktex()
        makeLaTeXFile(name, org_path, false);
 
        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) {
@@ -3449,7 +3484,7 @@ int Buffer::runChktex()
 
        // if we removed error insets before we ran chktex or if we inserted
        // error insets after we ran chktex, this must be run:
-       if (removedErrorInsets || res){
+       if (removedErrorInsets || res) {
                users->redraw();
                users->fitCursor();
        }
@@ -3467,7 +3502,7 @@ void Buffer::validate(LaTeXFeatures & features) const
     
         // AMS Style is at document level
         if (params.use_amsmath || tclass.provides(LyXTextClass::amsmath))
-               features.require("amsstyle");
+               features.require("amsmath");
     
        while (par) {
                // We don't use "lyxerr.debug" because of speed. (Asger)