]> git.lyx.org Git - lyx.git/blobdiff - src/BufferParams.cpp
this we don't need anymore
[lyx.git] / src / BufferParams.cpp
index 9914ae94297ab00ad50c6e55605c72995090aa82..01fbfb0a457cf01dc65966e45ce492cd7aa365a9 100644 (file)
@@ -302,7 +302,7 @@ BufferParams::Impl::Impl()
 BufferParams::Impl *
 BufferParams::MemoryTraits::clone(BufferParams::Impl const * ptr)
 {
-       BOOST_ASSERT(ptr);
+       LASSERT(ptr, /**/);
 
        return new BufferParams::Impl(*ptr);
 }
@@ -351,7 +351,7 @@ BufferParams::BufferParams()
        listings_params = string();
        pagestyle = "default";
        compressed = false;
-       embedded = 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 +361,7 @@ BufferParams::BufferParams()
 
 docstring BufferParams::B_(string const & l10n) const
 {
-       BOOST_ASSERT(language);
+       LASSERT(language, /**/);
        return getMessages(language->code()).get(l10n);
 }
 
@@ -404,28 +404,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];
 }
 
@@ -506,6 +506,8 @@ string BufferParams::readToken(Lexer & lex, string const & token,
                
        } else if (token == "\\begin_preamble") {
                readPreamble(lex);
+       } else if (token == "\\begin_local_layout") {
+               readLocalLayout(lex);
        } else if (token == "\\begin_modules") {
                readModules(lex);
        } else if (token == "\\options") {
@@ -722,6 +724,15 @@ void BufferParams::writeFile(ostream & os) const
                os << "\\end_modules" << '\n';
        }
 
+       // local layout information
+       if (!local_layout.empty()) {
+               // remove '\n' from the end 
+               string const tmplocal = rtrim(local_layout, "\n");
+               os << "\\begin_local_layout\n"
+                  << tmplocal
+                  << "\n\\end_local_layout\n";
+       }
+
        // then the text parameters
        if (language != ignore_language)
                os << "\\language " << language->lang() << '\n';
@@ -834,19 +845,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";
 }
 
 
@@ -1024,8 +1022,13 @@ bool BufferParams::writeLaTeX(odocstream & os, LaTeXFeatures & features,
                // http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg129417.html
                size_t viet = language_options.str().find("vietnam");
                // viet = string::npos when not found
+               // when Japanese is used, babel must directly be loaded with the
+               // language options, not in the class options, see
+               // http://bugzilla.lyx.org/show_bug.cgi?id=4597#c4
+               size_t japan = language_options.str().find("japanese");
+               // japan = string::npos when not found
                if (lyxrc.language_global_options && !language_options.str().empty()
-                       && viet == string::npos)
+                       && viet == string::npos && japan == string::npos)
                        clsoptions << language_options.str() << ',';
        }
 
@@ -1271,18 +1274,6 @@ bool BufferParams::writeLaTeX(odocstream & os, LaTeXFeatures & features,
                lyxpreamble += from_utf8(features.getBabelOptions());
        }
 
-       // When the language "japanese-plain" is used, the package "japanese" must
-       // be loaded behind babel (it provides babel support for Japanese) but before
-       // hyperref, see
-       // http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg129680.html
-       if (language->lang() == "japanese-plain" &&
-               !documentClass().provides("japanese")) {
-               //load babel in case it was not loaded due to an empty language list
-               if (language_options.str().empty())
-                       lyxpreamble += "\\usepackage{babel}\n";
-               lyxpreamble += "\\usepackage{japanese}\n";
-       }
-
        // PDF support.
        // * Hyperref manual: "Make sure it comes last of your loaded
        //   packages, to give it a fighting chance of not being over-written,
@@ -1298,13 +1289,17 @@ bool BufferParams::writeLaTeX(odocstream & os, LaTeXFeatures & features,
                lyxpreamble += oss.str();
        }
 
-       // this might be useful...
-       lyxpreamble += "\n\\makeatletter\n";
+       // only add \makeatletter and \makeatother when actually needed
+       bool makeatletter = false;
 
        // Some macros LyX will need
        docstring tmppreamble(from_ascii(features.getMacros()));
 
        if (!tmppreamble.empty()) {
+               if (!makeatletter) {
+                       lyxpreamble += "\n\\makeatletter\n";
+                       makeatletter = true;
+               }
                lyxpreamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
                        "LyX specific LaTeX commands.\n"
                        + tmppreamble + '\n';
@@ -1313,6 +1308,10 @@ bool BufferParams::writeLaTeX(odocstream & os, LaTeXFeatures & features,
        // the text class specific preamble
        tmppreamble = features.getTClassPreamble();
        if (!tmppreamble.empty()) {
+               if (!makeatletter) {
+                       lyxpreamble += "\n\\makeatletter\n";
+                       makeatletter = true;
+               }
                lyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
                        "Textclass specific LaTeX commands.\n"
                        + tmppreamble + '\n';
@@ -1320,6 +1319,10 @@ bool BufferParams::writeLaTeX(odocstream & os, LaTeXFeatures & features,
 
        /* the user-defined preamble */
        if (!preamble.empty()) {
+               if (!makeatletter) {
+                       lyxpreamble += "\n\\makeatletter\n";
+                       makeatletter = true;
+               }
                // FIXME UNICODE
                lyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
                        "User specified LaTeX commands.\n"
@@ -1358,10 +1361,16 @@ bool BufferParams::writeLaTeX(odocstream & os, LaTeXFeatures & features,
                }
        }
 
-       if (!bullets_def.empty())
+       if (!bullets_def.empty()) {
+               if (!makeatletter) {
+                       lyxpreamble += "\n\\makeatletter\n";
+                       makeatletter = true;
+               }
                lyxpreamble += bullets_def + "}\n\n";
+       }
 
-       lyxpreamble += "\\makeatother\n\n";
+       if (makeatletter)
+               lyxpreamble += "\\makeatother\n\n";
 
        int const nlines =
                int(count(lyxpreamble.begin(), lyxpreamble.end(), '\n'));
@@ -1501,6 +1510,12 @@ void BufferParams::makeDocumentClass()
                        frontend::Alert::warning(_("Read Error"), msg);
                }
        }
+       if (!local_layout.empty()) {
+               if (!doc_class_->read(local_layout, TextClass::MODULE)) {
+                       docstring const msg = _("Error reading internal layout information");
+                       frontend::Alert::warning(_("Read Error"), msg);
+               }
+       }
 }
 
 
@@ -1555,6 +1570,16 @@ void BufferParams::readPreamble(Lexer & lex)
 }
 
 
+void BufferParams::readLocalLayout(Lexer & lex)
+{
+       if (lex.getString() != "\\begin_local_layout")
+               lyxerr << "Error (BufferParams::readLocalLayout):"
+                       "consistency check failed." << endl;
+
+       local_layout = lex.getLongString("\\end_local_layout");
+}
+
+
 void BufferParams::readLanguage(Lexer & lex)
 {
        if (!lex.next()) return;
@@ -1587,7 +1612,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");
@@ -1755,7 +1781,12 @@ string BufferParams::babelCall(string const & lang_opts) const
        // http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg129417.html
        size_t viet = lang_opts.find("vietnam");
        // viet = string::npos when not found
-       if (!lyxrc.language_global_options || viet != string::npos)
+       // when Japanese is used, babel must directly be loaded with the
+       // language options, see
+       // http://bugzilla.lyx.org/show_bug.cgi?id=4597#c4
+       size_t japan = lang_opts.find("japanese");
+       // japan = string::npos when not found
+       if (!lyxrc.language_global_options || viet != string::npos || japan != string::npos)
                return "\\usepackage[" + lang_opts + "]{babel}";
        return lang_pack;
 }
@@ -1959,7 +1990,7 @@ string const BufferParams::loadFonts(string const & rm,
        else if (tt == "courier" )
                os << "\\usepackage{" << tt << "}\n";
        // Computer Modern, Latin Modern, CM Bright
-       else if  (tt != "default")
+       else if (tt != "default")
                os << "\\renewcommand{\\ttdefault}{" << tt << "}\n";
 
        return os.str();
@@ -1969,14 +2000,13 @@ string const BufferParams::loadFonts(string const & rm,
 Encoding const & BufferParams::encoding() const
 {
        if (inputenc == "auto" || inputenc == "default")
-               return *(language->encoding());
-       Encoding const * const enc =
-               encodings.getFromLaTeXName(inputenc);
+               return *language->encoding();
+       Encoding const * const enc = encodings.fromLaTeXName(inputenc);
        if (enc)
                return *enc;
-       lyxerr << "Unknown inputenc value `" << inputenc
-              << "'. Using `auto' instead." << endl;
-       return *(language->encoding());
+       LYXERR0("Unknown inputenc value `" << inputenc
+              << "'. Using `auto' instead.");
+       return *language->encoding();
 }