]> git.lyx.org Git - lyx.git/blobdiff - src/BufferParams.cpp
Typo.
[lyx.git] / src / BufferParams.cpp
index 43141b46e199df0333736f10b8b1de499adf230f..73bd2258a481e1e880c244ea0e71ee72c81e338e 100644 (file)
@@ -68,7 +68,7 @@ static char const * const string_quotes_language[] = {
 
 
 static char const * const string_papersize[] = {
-       "default", "custom", "letterpaper", "executivepaper", "legalpaper",
+       "default", "custom", "letterpaper", "legalpaper", "executivepaper",
        "a3paper", "a4paper", "a5paper", "b3paper", "b4paper", "b5paper", ""
 };
 
@@ -225,15 +225,15 @@ PackageTranslator const & packagetranslator()
 
 
 // Cite engine
-typedef Translator<string, biblio::CiteEngine> CiteEngineTranslator;
+typedef Translator<string, CiteEngine> CiteEngineTranslator;
 
 
 CiteEngineTranslator const init_citeenginetranslator()
 {
-       CiteEngineTranslator translator("basic", biblio::ENGINE_BASIC);
-       translator.addPair("natbib_numerical", biblio::ENGINE_NATBIB_NUMERICAL);
-       translator.addPair("natbib_authoryear", biblio::ENGINE_NATBIB_AUTHORYEAR);
-       translator.addPair("jurabib", biblio::ENGINE_JURABIB);
+       CiteEngineTranslator translator("basic", ENGINE_BASIC);
+       translator.addPair("natbib_numerical", ENGINE_NATBIB_NUMERICAL);
+       translator.addPair("natbib_authoryear", ENGINE_NATBIB_AUTHORYEAR);
+       translator.addPair("jurabib", ENGINE_JURABIB);
        return translator;
 }
 
@@ -277,7 +277,6 @@ public:
 
        AuthorList authorlist;
        BranchList branchlist;
-       vector<string> extraEmbeddedFiles;
        Bullet temp_bullets[4];
        Bullet user_defined_bullets[4];
        Spacing spacing;
@@ -302,7 +301,7 @@ BufferParams::Impl::Impl()
 BufferParams::Impl *
 BufferParams::MemoryTraits::clone(BufferParams::Impl const * ptr)
 {
-       BOOST_ASSERT(ptr);
+       LASSERT(ptr, /**/);
 
        return new BufferParams::Impl(*ptr);
 }
@@ -329,7 +328,7 @@ BufferParams::BufferParams()
        use_geometry = false;
        use_amsmath = package_auto;
        use_esint = package_auto;
-       cite_engine_ = biblio::ENGINE_BASIC;
+       cite_engine_ = ENGINE_BASIC;
        use_bibtopic = false;
        trackChanges = false;
        outputChanges = false;
@@ -351,7 +350,6 @@ BufferParams::BufferParams()
        listings_params = string();
        pagestyle = "default";
        compressed = false;
-       embedded = lyxrc.use_bundled_format;
        for (int iter = 0; iter < 4; ++iter) {
                user_defined_bullet(iter) = ITEMIZE_DEFAULTS[iter];
                temp_bullet(iter) = ITEMIZE_DEFAULTS[iter];
@@ -361,7 +359,7 @@ BufferParams::BufferParams()
 
 docstring BufferParams::B_(string const & l10n) const
 {
-       BOOST_ASSERT(language);
+       LASSERT(language, /**/);
        return getMessages(language->code()).get(l10n);
 }
 
@@ -378,18 +376,6 @@ AuthorList const & BufferParams::authors() const
 }
 
 
-vector<string> & BufferParams::extraEmbeddedFiles()
-{
-       return pimpl_->extraEmbeddedFiles;
-}
-
-
-vector<string> const & BufferParams::extraEmbeddedFiles() const
-{
-       return pimpl_->extraEmbeddedFiles;
-}
-
-
 BranchList & BufferParams::branchlist()
 {
        return pimpl_->branchlist;
@@ -404,28 +390,28 @@ BranchList const & BufferParams::branchlist() const
 
 Bullet & BufferParams::temp_bullet(lyx::size_type const index)
 {
-       BOOST_ASSERT(index < 4);
+       LASSERT(index < 4, /**/);
        return pimpl_->temp_bullets[index];
 }
 
 
 Bullet const & BufferParams::temp_bullet(lyx::size_type const index) const
 {
-       BOOST_ASSERT(index < 4);
+       LASSERT(index < 4, /**/);
        return pimpl_->temp_bullets[index];
 }
 
 
 Bullet & BufferParams::user_defined_bullet(lyx::size_type const index)
 {
-       BOOST_ASSERT(index < 4);
+       LASSERT(index < 4, /**/);
        return pimpl_->user_defined_bullets[index];
 }
 
 
 Bullet const & BufferParams::user_defined_bullet(lyx::size_type const index) const
 {
-       BOOST_ASSERT(index < 4);
+       LASSERT(index < 4, /**/);
        return pimpl_->user_defined_bullets[index];
 }
 
@@ -467,7 +453,7 @@ void BufferParams::setDefSkip(VSpace const & vs)
 
 
 string BufferParams::readToken(Lexer & lex, string const & token,
-       FileName const & filepath, FileName const & temppath)
+       FileName const & filepath)
 {
        if (token == "\\textclass") {
                lex.next();
@@ -476,8 +462,6 @@ string BufferParams::readToken(Lexer & lex, string const & token,
                // NOTE: in this case, the textclass (.cls file) is assumed to be available.
                string tcp;
                LayoutFileList & bcl = LayoutFileList::get();
-               if (!temppath.empty())
-                       tcp = bcl.addLayoutFile(classname, temppath.absFilename(), LayoutFileList::Embedded);
                if (tcp.empty() && !filepath.empty())
                        tcp = bcl.addLayoutFile(classname, filepath.absFilename(), LayoutFileList::Local);
                if (!tcp.empty())
@@ -513,6 +497,9 @@ string BufferParams::readToken(Lexer & lex, string const & token,
        } else if (token == "\\options") {
                lex.eatLine();
                options = lex.getString();
+       } else if (token == "\\master") {
+               lex.eatLine();
+               master = lex.getString();
        } else if (token == "\\language") {
                readLanguage(lex);
        } else if (token == "\\inputencoding") {
@@ -535,6 +522,8 @@ string BufferParams::readToken(Lexer & lex, string const & token,
                lex >> fontsSansScale;
        } else if (token == "\\font_tt_scale") {
                lex >> fontsTypewriterScale;
+       } else if (token == "\\font_cjk") {
+               lex >> fontsCJK;
        } else if (token == "\\paragraph_separation") {
                string parsep;
                lex >> parsep;
@@ -673,16 +662,6 @@ string BufferParams::readToken(Lexer & lex, string const & token,
                                toktmp << endl;
                        return toktmp;
                }
-       } else if (token == "\\extra_embedded_files") {
-               extraEmbeddedFiles().clear();
-               string par;
-               lex >> par;
-               string tmp;
-               par = split(par, tmp, ',');
-               while (!tmp.empty()) {
-                       extraEmbeddedFiles().push_back(tmp);
-                       par = split(par, tmp, ',');
-               }
        } else {
                lyxerr << "BufferParams::readToken(): Unknown token: " << 
                        token << endl;
@@ -714,6 +693,11 @@ void BufferParams::writeFile(ostream & os) const
        if (!options.empty()) {
                os << "\\options " << options << '\n';
        }
+
+       // the master document
+       if (!master.empty()) {
+               os << "\\master " << master << '\n';
+       }
        
        //the modules
        if (!layoutModules_.empty()) {
@@ -745,7 +729,11 @@ void BufferParams::writeFile(ostream & os) const
           << "\n\\font_osf " << convert<string>(fontsOSF)
           << "\n\\font_sf_scale " << fontsSansScale
           << "\n\\font_tt_scale " << fontsTypewriterScale
-          << "\n\\graphics " << graphicsDriver << '\n';
+          << '\n';
+       if (!fontsCJK.empty()) {
+               os << "\\font_cjk " << fontsCJK << '\n';
+       }
+       os << "\n\\graphics " << graphicsDriver << '\n';
 
        if (!float_placement.empty()) {
                os << "\\float_placement " << float_placement << '\n';
@@ -845,19 +833,6 @@ void BufferParams::writeFile(ostream & os) const
                else
                        os << "\\author " << Author() << "\n";
        }
-
-       vector<string>::const_iterator e_it = extraEmbeddedFiles().begin();
-       vector<string>::const_iterator e_end = extraEmbeddedFiles().end();
-       os << "\\extra_embedded_files \"";
-       bool first = true;
-       for (; e_it != e_end; ++e_it) {
-               if (!first)
-                       os << ",";
-               else
-                       first = false;
-               os << *e_it;
-       }
-       os << "\"\n";
 }
 
 
@@ -1197,6 +1172,8 @@ bool BufferParams::writeLaTeX(odocstream & os, LaTeXFeatures & features,
                        os << ",columnsep=" << from_ascii(Length(columnsep).asLatexString());
                os << "}\n";
                texrow.newline();
+       } else if (orientation == ORIENTATION_LANDSCAPE) {
+               features.require("papersize");
        }
 
        if (tokenPos(tclass.opt_pagestyle(),
@@ -1267,17 +1244,19 @@ bool BufferParams::writeLaTeX(odocstream & os, LaTeXFeatures & features,
        // Line spacing
        lyxpreamble += from_utf8(spacing().writePreamble(tclass.provides("SetSpace")));
 
-       // We try to load babel late, in case it interferes
-       // with other packages. But some packages also need babel to be loaded
-       // before, e.g. jurabib has to be called after babel.
-       // So load babel after the optional packages but before the user-defined
-       // preamble. This allows the users to redefine babel commands, e.g. to
-       // translate the word "Index" to the German "Stichwortverzeichnis".
-       // For more infos why this place was chosen, see
+       // We try to load babel late, in case it interferes with other
+       // packages. But some packages also need babel to be loaded
+       // before, e.g. jurabib has to be called after babel. So load
+       // babel after the optional packages but before the
+       // user-defined preamble. This allows the users to redefine
+       // babel commands, e.g. to translate the word "Index" to the
+       // German "Stichwortverzeichnis". For more infos why this
+       // place was chosen, see
        // http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg128425.html
-       // If you encounter problems, you can shift babel to its old place behind
-       // the user-defined preamble. But in this case you must change the Vietnamese
-       // support from currently "\usepackage[vietnamese]{babel}" to:
+       // If you encounter problems, you can shift babel to its old
+       // place behind the user-defined preamble. But in this case
+       // you must change the Vietnamese support from currently
+       // "\usepackage[vietnamese]{babel}" to:
        // \usepackage{vietnamese}
        // \usepackage{babel}
        // because vietnamese must be loaded before hyperref
@@ -1302,32 +1281,45 @@ bool BufferParams::writeLaTeX(odocstream & os, LaTeXFeatures & features,
                lyxpreamble += oss.str();
        }
 
-       // this might be useful...
-       lyxpreamble += "\n\\makeatletter\n";
+       // Will be surrounded by \makeatletter and \makeatother when needed
+       docstring atlyxpreamble;
 
        // Some macros LyX will need
        docstring tmppreamble(from_ascii(features.getMacros()));
 
-       if (!tmppreamble.empty()) {
-               lyxpreamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
+       if (!tmppreamble.empty())
+               atlyxpreamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
                        "LyX specific LaTeX commands.\n"
                        + tmppreamble + '\n';
-       }
 
        // the text class specific preamble
        tmppreamble = features.getTClassPreamble();
-       if (!tmppreamble.empty()) {
-               lyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
+       if (!tmppreamble.empty())
+               atlyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
                        "Textclass specific LaTeX commands.\n"
                        + tmppreamble + '\n';
-       }
 
        /* the user-defined preamble */
-       if (!preamble.empty()) {
+       if (!preamble.empty())
                // FIXME UNICODE
-               lyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
+               atlyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
                        "User specified LaTeX commands.\n"
                        + from_utf8(preamble) + '\n';
+
+       // subfig loads internally the LaTeX package "caption". As
+       // caption is a very popular package, users will load it in
+       // the preamble. Therefore we must load subfig behind the
+       // user-defined preamble and check if the caption package was
+       // loaded or not. For the case that caption is loaded before
+       // subfig, there is the subfig option "caption=false". This
+       // option also works when a koma-script class is used and
+       // koma's own caption commands are used instead of caption. We
+       // use \PassOptionsToPackage here because the user could have
+       // already loaded subfig in the preamble.
+       if (features.isRequired("subfig")) {
+               atlyxpreamble += "\\@ifundefined{showcaptionsetup}{}{%\n"
+                       " \\PassOptionsToPackage{caption=false}{subfig}}\n"
+                       "\\usepackage{subfig}\n";
        }
 
        // Itemize bullet settings need to be last in case the user
@@ -1363,9 +1355,13 @@ bool BufferParams::writeLaTeX(odocstream & os, LaTeXFeatures & features,
        }
 
        if (!bullets_def.empty())
-               lyxpreamble += bullets_def + "}\n\n";
+               atlyxpreamble += bullets_def + "}\n\n";
 
-       lyxpreamble += "\\makeatother\n\n";
+       if (atlyxpreamble.find(from_ascii("@")) != docstring::npos)
+               lyxpreamble += "\n\\makeatletter\n"
+                       + atlyxpreamble + "\\makeatother\n\n";
+       else
+               lyxpreamble += '\n' + atlyxpreamble;
 
        int const nlines =
                int(count(lyxpreamble.begin(), lyxpreamble.end(), '\n'));
@@ -1413,7 +1409,7 @@ DocumentClass const & BufferParams::documentClass() const
 }
 
 
-DocumentClass * BufferParams::documentClassPtr() const {
+DocumentClass const * BufferParams::documentClassPtr() const {
        return doc_class_;
 }
 
@@ -1486,9 +1482,8 @@ void BufferParams::makeDocumentClass()
                                        "probably need to reconfigure LyX.\n"), from_utf8(modName));
                        frontend::Alert::warning(_("Module not available"),
                                        msg + _("Some layouts may not be available."));
-                       lyxerr << "BufferParams::makeDocumentClass(): Module " <<
-                                       modName << " requested but not found in module list." <<
-                                       endl;
+                       LYXERR0("BufferParams::makeDocumentClass(): Module " <<
+                                       modName << " requested but not found in module list.");
                        continue;
                }
                if (!lm->isAvailable()) {
@@ -1525,12 +1520,9 @@ bool BufferParams::addLayoutModule(string const & modName)
 {
        LayoutModuleList::const_iterator it = layoutModules_.begin();
        LayoutModuleList::const_iterator end = layoutModules_.end();
-       for (; it != end; it++) {
+       for (; it != end; it++)
                if (*it == modName) 
-                       break;
-       }
-       if (it != layoutModules_.end())
-               return false;
+                       return false;
        layoutModules_.push_back(modName);
        return true;
 }
@@ -1607,7 +1599,8 @@ void BufferParams::readGraphicsDriver(Lexer & lex)
                if (test == tmptok) {
                        graphicsDriver = tmptok;
                        break;
-               } else if (test == "") {
+               }
+               if (test.empty()) {
                        lex.printError(
                                "Warning: graphics driver `$$Token' not recognized!\n"
                                "         Setting graphics driver to `default'.\n");
@@ -2004,18 +1997,18 @@ Encoding const & BufferParams::encoding() const
 }
 
 
-biblio::CiteEngine BufferParams::citeEngine() const
+CiteEngine BufferParams::citeEngine() const
 {
        // FIXME the class should provide the numerical/
        // authoryear choice
        if (documentClass().provides("natbib")
-           && cite_engine_ != biblio::ENGINE_NATBIB_NUMERICAL)
-               return biblio::ENGINE_NATBIB_AUTHORYEAR;
+           && cite_engine_ != ENGINE_NATBIB_NUMERICAL)
+               return ENGINE_NATBIB_AUTHORYEAR;
        return cite_engine_;
 }
 
 
-void BufferParams::setCiteEngine(biblio::CiteEngine cite_engine)
+void BufferParams::setCiteEngine(CiteEngine cite_engine)
 {
        cite_engine_ = cite_engine;
 }