]> git.lyx.org Git - lyx.git/blobdiff - src/output_latex.cpp
Check for fontspec an configure the GUI accordingly.
[lyx.git] / src / output_latex.cpp
index d7cd2d5293a17314f1f905a711695132755ecec9..a5473bf4813d5684a00479d1570d3670de9810d2 100644 (file)
@@ -77,7 +77,7 @@ struct TeXEnvironementData
 
 
 static TeXEnvironementData prepareEnvironement(Buffer const & buf, Text const & text,
-               ParagraphList::const_iterator pit, odocstream & os, TexRow & texrow,
+               ParagraphList::const_iterator pit, otexstream & os, TexRow & texrow,
                OutputParams const & runparams)
 {
        TeXEnvironementData data;
@@ -202,7 +202,7 @@ static TeXEnvironementData prepareEnvironement(Buffer const & buf, Text const &
 }
 
 
-static void finishEnvironement(odocstream & os, TexRow & texrow,
+static void finishEnvironement(otexstream & os, TexRow & texrow,
                OutputParams const & runparams, TeXEnvironementData const & data)
 {
        if (open_encoding_ == CJK && data.cjk_nested) {
@@ -239,7 +239,7 @@ static void finishEnvironement(odocstream & os, TexRow & texrow,
 
 void TeXEnvironment(Buffer const & buf,
               Text const & text, OutputParams const & runparams,
-                  pit_type & pit, odocstream & os, TexRow & texrow)
+                  pit_type & pit, otexstream & os, TexRow & texrow)
 {
        ParagraphList const & paragraphs = text.paragraphs();
        ParagraphList::const_iterator par = paragraphs.constIterator(pit);
@@ -326,7 +326,7 @@ void TeXEnvironment(Buffer const & buf,
 } // namespace anon
 
 
-int latexArgInsets(Paragraph const & par, odocstream & os,
+int latexArgInsets(Paragraph const & par, otexstream & os,
        OutputParams const & runparams, unsigned int reqargs,
        unsigned int optargs)
 {
@@ -380,12 +380,46 @@ int latexArgInsets(Paragraph const & par, odocstream & os,
        return lines;
 }
 
+namespace {
+
+// output the proper paragraph start according to latextype.
+void parStartCommand(Paragraph const & par, otexstream & os, TexRow & texrow,
+                    OutputParams const & runparams,Layout const & style) 
+{
+       switch (style.latextype) {
+       case LATEX_COMMAND:
+               os << '\\' << from_ascii(style.latexname());
+
+               // Separate handling of optional argument inset.
+               if (style.optargs != 0 || style.reqargs != 0) {
+                       int ret = latexArgInsets(par, os, runparams, style.reqargs, style.optargs);
+                       while (ret > 0) {
+                               texrow.newline();
+                               --ret;
+                       }
+               }
+               else
+                       os << from_ascii(style.latexparam());
+               break;
+       case LATEX_ITEM_ENVIRONMENT:
+       case LATEX_LIST_ENVIRONMENT:
+               os << "\\item ";
+               break;
+       case LATEX_BIB_ENVIRONMENT:
+               // ignore this, the inset will write itself
+               break;
+       default:
+               break;
+       }
+}
+
+} // namespace anon
 
 // FIXME: this should be anonymous
 void TeXOnePar(Buffer const & buf,
          Text const & text,
          pit_type pit,
-         odocstream & os, TexRow & texrow,
+         otexstream & os, TexRow & texrow,
          OutputParams const & runparams_in,
          string const & everypar,
          int start_pos, int end_pos)
@@ -405,7 +439,7 @@ void TeXOnePar(Buffer const & buf,
                << everypar << "'");
 
        OutputParams runparams = runparams_in;
-       runparams.isLastPar = (pit == paragraphs.size() - 1);
+       runparams.isLastPar = (pit == pit_type(paragraphs.size() - 1));
        // We reinitialze par begin and end to be on the safe side
        // with embedded inset as we don't know if they set those
        // value correctly.
@@ -444,9 +478,18 @@ void TeXOnePar(Buffer const & buf,
 
        if (style.pass_thru) {
                Font const outerfont = text.outerFont(pit);
+               parStartCommand(par, os, texrow,runparams, style);
+
                par.latex(bparams, outerfont, os, texrow, runparams, start_pos,
                        end_pos);
-               os << '\n';
+
+               // I did not create a parEndCommand for this minuscule
+               // task because in the other user of parStartCommand
+               // the code is different (JMarc)
+               if (style.isCommand())
+                       os << "}\n";
+               else
+                       os << '\n';
                texrow.newline();
                if (!style.parbreak_is_newline) {
                        os << '\n';
@@ -590,8 +633,8 @@ void TeXOnePar(Buffer const & buf,
        // Switch file encoding if necessary; no need to do this for "default"
        // encoding, since this only affects the position of the outputted
        // \inputencoding command; the encoding switch will occur when necessary
-       if (bparams.inputenc == "auto" &&
-           runparams.encoding->package() != Encoding::none) {
+       if (bparams.inputenc == "auto"
+               && runparams.encoding->package() != Encoding::none) {
                // Look ahead for future encoding changes.
                // We try to output them at the beginning of the paragraph,
                // since the \inputencoding command is not allowed e.g. in
@@ -602,9 +645,9 @@ void TeXOnePar(Buffer const & buf,
                        char_type const c = par.getChar(i);
                        Encoding const * const encoding =
                                par.getFontSettings(bparams, i).language()->encoding();
-                       if (encoding->package() != Encoding::CJK &&
-                           runparams.encoding->package() == Encoding::inputenc &&
-                           c < 0x80)
+                       if (encoding->package() != Encoding::CJK
+                               && runparams.encoding->package() == Encoding::inputenc
+                               && c < 0x80)
                                continue;
                        if (par.isInset(i))
                                break;
@@ -613,38 +656,39 @@ void TeXOnePar(Buffer const & buf,
                        // encoding to that required by the language of c.
                        // With CJK, only add switch if we have CJK content at the beginning
                        // of the paragraph
-                       if (encoding->package() != Encoding::CJK || i == 0) {
-                               pair<bool, int> enc_switch = switchEncoding(os, bparams, runparams,
-                                       *encoding);
-                               // 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_ == 0) {
-                                       os << "\\begin{CJK}{" << from_ascii(par_language->encoding()->latexName())
-                                          << "}{" << from_ascii(bparams.fonts_cjk) << "}%\n";
-                                       open_encoding_ = CJK;
+                       if (i != 0 && encoding->package() == Encoding::CJK)
+                               continue;
+
+                       pair<bool, int> enc_switch = switchEncoding(os.os(),
+                                               bparams, runparams, *encoding);
+                       // 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_ == 0) {
+                               os << "\\begin{CJK}{" << from_ascii(par_language->encoding()->latexName())
+                                  << "}{" << from_ascii(bparams.fonts_cjk) << "}%\n";
+                               open_encoding_ = CJK;
+                               texrow.newline();
+                       }
+                       if (encoding->package() != Encoding::none && enc_switch.first) {
+                               if (enc_switch.second > 0) {
+                                       // the '%' is necessary to prevent unwanted whitespace
+                                       os << "%\n";
                                        texrow.newline();
                                }
-                               if (encoding->package() != Encoding::none && enc_switch.first) {
-                                       if (enc_switch.second > 0) {
-                                               // the '%' is necessary to prevent unwanted whitespace
-                                               os << "%\n";
-                                               texrow.newline();
-                                       }
-                                       // With CJK, the CJK tag had to be closed first (see above)
-                                       if (runparams.encoding->package() == Encoding::CJK) {
-                                               os << from_ascii(subst(
-                                                       lang_begin_command,
-                                                       "$$lang",
-                                                       par_lang))
-                                               // the '%' is necessary to prevent unwanted whitespace
-                                               << "%\n";
-                                               texrow.newline();
-                                       }
-                                       runparams.encoding = encoding;
+                               // With CJK, the CJK tag had to be closed first (see above)
+                               if (runparams.encoding->package() == Encoding::CJK) {
+                                       os << from_ascii(subst(
+                                               lang_begin_command,
+                                               "$$lang",
+                                               par_lang))
+                                       // the '%' is necessary to prevent unwanted whitespace
+                                       << "%\n";
+                                       texrow.newline();
                                }
-                               break;
+                               runparams.encoding = encoding;
                        }
+                       break;
                }
        }
 
@@ -672,31 +716,7 @@ void TeXOnePar(Buffer const & buf,
                }
        }
 
-       switch (style.latextype) {
-       case LATEX_COMMAND:
-               os << '\\' << from_ascii(style.latexname());
-
-               // Separate handling of optional argument inset.
-               if (style.optargs != 0 || style.reqargs != 0) {
-                       int ret = latexArgInsets(par, os, runparams, style.reqargs, style.optargs);
-                       while (ret > 0) {
-                               texrow.newline();
-                               --ret;
-                       }
-               }
-               else
-                       os << from_ascii(style.latexparam());
-               break;
-       case LATEX_ITEM_ENVIRONMENT:
-       case LATEX_LIST_ENVIRONMENT:
-               os << "\\item ";
-               break;
-       case LATEX_BIB_ENVIRONMENT:
-               // ignore this, the inset will write itself
-               break;
-       default:
-               break;
-       }
+       parStartCommand(par, os, texrow,runparams, style);
 
        Font const outerfont = text.outerFont(pit);
 
@@ -921,7 +941,7 @@ void TeXOnePar(Buffer const & buf,
 // LaTeX all paragraphs
 void latexParagraphs(Buffer const & buf,
                     Text const & text,
-                    odocstream & os,
+                    otexstream & os,
                     TexRow & texrow,
                     OutputParams const & runparams,
                     string const & everypar)
@@ -976,7 +996,7 @@ void latexParagraphs(Buffer const & buf,
 
        pit_type pit = runparams.par_begin;
        // lastpit is for the language check after the loop.
-       pit_type lastpit;
+       pit_type lastpit = pit;
        // variables used in the loop:
        bool was_title = false;
        bool already_title = false;
@@ -1045,12 +1065,11 @@ void latexParagraphs(Buffer const & buf,
        if (was_title && !already_title) {
                if (tclass.titletype() == TITLE_ENVIRONMENT) {
                        os << "\\end{" << from_ascii(tclass.titlename())
-                           << "}\n";
-               }
-               else {
+                          << "}\n";
+               } else {
                        os << "\\" << from_ascii(tclass.titlename())
-                           << "\n";
-                               }
+                          << "\n";
+               }
                texrow.newline();
        }