]> git.lyx.org Git - lyx.git/blobdiff - src/output_latex.cpp
Further to r26743, add CustomPars and ForcePlain layout tags to InsetLayout,
[lyx.git] / src / output_latex.cpp
index 2f919f4fec998973bbf7375dd1d94d1aae2d6b5c..646e836480751b3c6323d1ea1cd8ce3888f36b2e 100644 (file)
@@ -51,7 +51,7 @@ enum OpenEncoding {
 };
 
 static int open_encoding_ = none;
-static bool cjk_inherited_ = false;
+static int cjk_inherited_ = 0;
 
 
 ParagraphList::const_iterator
@@ -109,8 +109,8 @@ TeXEnvironment(Buffer const & buf,
 
        BufferParams const & bparams = buf.params();
 
-       Layout const & style = pit->forceEmptyLayout() ?
-               bparams.documentClass().emptyLayout() : pit->layout();
+       Layout const & style = pit->forcePlainLayout() ?
+               bparams.documentClass().plainLayout() : pit->layout();
 
        ParagraphList const & paragraphs = text.paragraphs();
 
@@ -183,7 +183,7 @@ TeXEnvironment(Buffer const & buf,
        if (par_language->encoding()->package() == Encoding::CJK &&
            open_encoding_ != CJK && pit->isMultiLingual(bparams)) {
                os << "\\begin{CJK}{" << from_ascii(par_language->encoding()->latexName())
-                  << "}{}%\n";
+                  << "}{" << from_ascii(bparams.fontsCJK) << "}%\n";
                open_encoding_ = CJK;
                cjk_nested = true;
                texrow.newline();
@@ -294,7 +294,10 @@ TeXOnePar(Buffer const & buf,
        if (nextpit != paragraphs.end())
                ++nextpit;
 
-       if (runparams_in.verbatim) {
+       OutputParams runparams = runparams_in;
+       runparams.isLastPar = nextpit == paragraphs.end();
+
+       if (runparams.verbatim) {
                int const dist = distance(paragraphs.begin(), pit);
                Font const outerfont = outerFont(dist, paragraphs);
 
@@ -305,20 +308,21 @@ TeXOnePar(Buffer const & buf,
                }
 
                /*bool need_par = */ pit->latex(bparams, outerfont,
-                       os, texrow, runparams_in);
+                       os, texrow, runparams);
                return nextpit;
        }
 
-       Layout const style = pit->forceEmptyLayout() ?
-               bparams.documentClass().emptyLayout() : pit->layout();
+       Layout const style = pit->forcePlainLayout() ?
+               bparams.documentClass().plainLayout() : pit->layout();
 
-       OutputParams runparams = runparams_in;
        runparams.moving_arg |= style.needprotect;
 
        bool const maintext = text.isMainText(buf);
-       // we are at the beginning of an inset and CJK is already open.
-       if (pit == paragraphs.begin() && !maintext && open_encoding_ == CJK) {
-               cjk_inherited_ = true;
+       // we are at the beginning of an inset and CJK is already open;
+       // we count inheritation levels to get the inset nesting right.
+       if (pit == paragraphs.begin() && !maintext
+           && (cjk_inherited_ > 0 || open_encoding_ == CJK)) {
+               cjk_inherited_ += 1;
                open_encoding_ = none;
        }
 
@@ -449,9 +453,9 @@ TeXOnePar(Buffer const & buf,
                                // the following is necessary after a CJK environment in a multilingual
                                // context (nesting issue).
                                if (par_language->encoding()->package() == Encoding::CJK &&
-                                   open_encoding_ != CJK && !cjk_inherited_) {
+                                   open_encoding_ != CJK && cjk_inherited_ == 0) {
                                        os << "\\begin{CJK}{" << from_ascii(par_language->encoding()->latexName())
-                                          << "}{}%\n";
+                                          << "}{" << from_ascii(bparams.fontsCJK) << "}%\n";
                                        open_encoding_ = CJK;
                                        texrow.newline();
                                }
@@ -698,10 +702,10 @@ TeXOnePar(Buffer const & buf,
        // the inset, and we're using "auto" or "default" encoding, the encoding
        // should be set back to that local_font's encoding.
        if (nextpit == paragraphs.end() && runparams_in.local_font != 0
+           && runparams_in.encoding != runparams_in.local_font->language()->encoding()
            && (bparams.inputenc == "auto" || bparams.inputenc == "default")) {
                runparams_in.encoding = runparams_in.local_font->language()->encoding();
                os << setEncoding(runparams_in.encoding->iconvName());
-
        }
        // Otherwise, the current encoding should be set for the next paragraph.
        else
@@ -712,8 +716,12 @@ TeXOnePar(Buffer const & buf,
        // Note from JMarc: we will re-add a \n explicitely in
        // TeXEnvironment, because it is needed in this case
        if (nextpit != paragraphs.end()) {
-               os << '\n';
-               texrow.newline();
+               Layout const & next_layout = nextpit->layout();
+               // no blank lines before environments!
+               if (!next_layout.isEnvironment() || style == next_layout) {
+                       os << '\n';
+                       texrow.newline();
+               }
        }
 
        if (nextpit != paragraphs.end())
@@ -758,7 +766,7 @@ void latexParagraphs(Buffer const & buf,
        // if the document's language is a CJK language
        if (maintext && bparams.encoding().package() == Encoding::CJK) {
                os << "\\begin{CJK}{" << from_ascii(bparams.encoding().latexName())
-               << "}{}%\n";
+               << "}{" << from_ascii(bparams.fontsCJK) << "}%\n";
                texrow.newline();
                open_encoding_ = CJK;
        }
@@ -778,8 +786,8 @@ void latexParagraphs(Buffer const & buf,
        // if only_body
        while (par != endpar) {
                lastpar = par;
-               Layout const & layout = par->forceEmptyLayout() ?
-                               tclass.emptyLayout() :
+               Layout const & layout = par->forcePlainLayout() ?
+                               tclass.plainLayout() :
                                par->layout();
 
                if (layout.intitle) {
@@ -810,10 +818,7 @@ void latexParagraphs(Buffer const & buf,
                        was_title = false;
                }
 
-               if (layout.is_environment) {
-                       par = TeXOnePar(buf, text, par, os, texrow,
-                                       runparams, everypar);
-               } else if (layout.isEnvironment() ||
+               if (layout.isEnvironment() ||
                                        !par->params().leftIndent().zero()) {
                        par = TeXEnvironment(buf, text, par, os,
                                                                texrow, runparams);
@@ -858,20 +863,22 @@ void latexParagraphs(Buffer const & buf,
        }
 
        // reset inherited encoding
-       if (cjk_inherited_) {
-               open_encoding_ = CJK;
-               cjk_inherited_ = false;
+       if (cjk_inherited_ > 0) {
+               cjk_inherited_ -= 1;
+               if (cjk_inherited_ == 0)
+                       open_encoding_ = CJK;
        }
 }
 
 
 pair<bool, int> switchEncoding(odocstream & os, BufferParams const & bparams,
-                  OutputParams const & runparams, Encoding const & newEnc)
+                  OutputParams const & runparams, Encoding const & newEnc,
+                  bool force)
 {
        Encoding const oldEnc = *runparams.encoding;
        bool moving_arg = runparams.moving_arg;
-       if ((bparams.inputenc != "auto" && bparams.inputenc != "default")
-               || moving_arg)
+       if (!force && ((bparams.inputenc != "auto" && bparams.inputenc != "default")
+               || moving_arg))
                return make_pair(false, 0);
 
        // Do nothing if the encoding is unchanged.
@@ -896,6 +903,7 @@ pair<bool, int> switchEncoding(odocstream & os, BufferParams const & bparams,
        docstring const inputenc_arg(from_ascii(newEnc.latexName()));
        switch (newEnc.package()) {
                case Encoding::none:
+               case Encoding::japanese:
                        // shouldn't ever reach here, see above
                        return make_pair(true, 0);
                case Encoding::inputenc: {
@@ -912,13 +920,18 @@ pair<bool, int> switchEncoding(odocstream & os, BufferParams const & bparams,
                                open_encoding_ = none;
                                count += 7;
                        }
-                       if (runparams.local_font != 0 && oldEnc.package() == Encoding::CJK) {
-                               // within insets, \inputenc switches need to be 
-                               // embraced within \bgroup ... \egroup; else CJK fails.
+                       if (runparams.local_font != 0
+                           && oldEnc.package() == Encoding::CJK) {
+                               // within insets, \inputenc switches need
+                               // to be embraced within \bgroup...\egroup;
+                               // else CJK fails.
                                os << "\\bgroup";
                                count += 7;
                                open_encoding_ = inputenc;
                        }
+                       // with the japanese option, inputenc is omitted.
+                       if (runparams.use_japanese)
+                               return make_pair(true, count);
                        os << "\\inputencoding{" << inputenc_arg << '}';
                        return make_pair(true, count + 16);
                }
@@ -934,7 +947,8 @@ pair<bool, int> switchEncoding(odocstream & os, BufferParams const & bparams,
                                os << "\\egroup";
                                count += 7;
                        }
-                       os << "\\begin{CJK}{" << inputenc_arg << "}{}";
+                       os << "\\begin{CJK}{" << inputenc_arg << "}{"
+                          << from_ascii(bparams.fontsCJK) << "}";
                        open_encoding_ = CJK;
                        return make_pair(true, count + 15);
                }