X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Foutput_latex.cpp;h=92913afb4e92c1cf8f11f34c5d43284bccb0b6f8;hb=837869452ad8d917615aa4bca77402dc49ba094e;hp=c2ec939d7ed6ef4ddc32fb7915ef13195d7d604c;hpb=f76d28c11803753bfc2f20bc2f51e3692a7e9f45;p=lyx.git diff --git a/src/output_latex.cpp b/src/output_latex.cpp index c2ec939d7e..92913afb4e 100644 --- a/src/output_latex.cpp +++ b/src/output_latex.cpp @@ -25,7 +25,6 @@ #include "ParagraphParameters.h" #include "TextClass.h" #include "TexRow.h" -#include "VSpace.h" #include "insets/InsetBibitem.h" #include "insets/InsetArgument.h" @@ -110,16 +109,16 @@ static TeXEnvironmentData prepareEnvironment(Buffer const & buf, : priorpit->getParLanguage(bparams)) : doc_language; - bool const use_pg = runparams.use_polyglossia; - string const par_lang = use_pg ? + bool const use_polyglossia = runparams.use_polyglossia; + string const par_lang = use_polyglossia ? getPolyglossiaEnvName(data.par_language) : data.par_language->babel(); - string const prev_par_lang = use_pg ? + string const prev_par_lang = use_polyglossia ? getPolyglossiaEnvName(prev_par_language) : prev_par_language->babel(); - string const doc_lang = use_pg ? + string const doc_lang = use_polyglossia ? getPolyglossiaEnvName(doc_language) : doc_language->babel(); - string const lang_begin_command = use_pg ? + string const lang_begin_command = use_polyglossia ? "\\begin{$$lang}" : lyxrc.language_command_begin; - string const lang_end_command = use_pg ? + string const lang_end_command = use_polyglossia ? "\\end{$$lang}" : lyxrc.language_command_end; if (par_lang != prev_par_lang) { @@ -141,7 +140,7 @@ static TeXEnvironmentData prepareEnvironment(Buffer const & buf, lang_begin_command, "$$lang", par_lang)); - if (runparams.use_polyglossia + if (use_polyglossia && !data.par_language->polyglossiaOpts().empty()) os << "[" << from_ascii(data.par_language->polyglossiaOpts()) @@ -240,7 +239,6 @@ void TeXEnvironment(Buffer const & buf, Text const & text, // This is for debugging purpose at the end. pit_type const par_begin = pit; for (; pit < runparams.par_end; ++pit) { - ParagraphList::const_iterator par = paragraphs.constIterator(pit); // check first if this is an higher depth paragraph. @@ -277,7 +275,6 @@ void TeXEnvironment(Buffer const & buf, Text const & text, // be two for Standard paragraphs that are depth-increment'ed to be // output correctly. However, tables can also be paragraphs so // don't adjust them. - // // FIXME (Lgb): Will it ever harm to have one '\n' too // many? i.e. that we sometimes will have @@ -334,7 +331,7 @@ void latexArgInsets(Paragraph const & par, otexstream & os, } } - if (!reqargs && ilist.size() == 0) + if (!reqargs && ilist.empty()) return; bool const have_optional_args = ilist.size() > reqargs; @@ -508,18 +505,18 @@ void TeXOnePar(Buffer const & buf, : outer_language; - bool const use_pg = runparams.use_polyglossia; - string const par_lang = use_pg ? + bool const use_polyglossia = runparams.use_polyglossia; + string const par_lang = use_polyglossia ? getPolyglossiaEnvName(par_language): par_language->babel(); - string const prev_lang = use_pg ? + string const prev_lang = use_polyglossia ? getPolyglossiaEnvName(prev_language) : prev_language->babel(); - string const doc_lang = use_pg ? + string const doc_lang = use_polyglossia ? getPolyglossiaEnvName(doc_language) : doc_language->babel(); - string const outer_lang = use_pg ? + string const outer_lang = use_polyglossia ? getPolyglossiaEnvName(outer_language) : outer_language->babel(); - string const lang_begin_command = use_pg ? + string const lang_begin_command = use_polyglossia ? "\\begin{$$lang}" : lyxrc.language_command_begin; - string const lang_end_command = use_pg ? + string const lang_end_command = use_polyglossia ? "\\end{$$lang}" : lyxrc.language_command_end; if (par_lang != prev_lang @@ -552,7 +549,7 @@ void TeXOnePar(Buffer const & buf, // language paragraph should appear within an \L or \R (in addition // to, outside of, the normal language switch commands). // This behavior is not correct for ArabTeX, though. - if (!runparams.use_polyglossia + if (!use_polyglossia // not for ArabTeX && par_language->lang() != "arabic_arabtex" && outer_language->lang() != "arabic_arabtex" @@ -584,12 +581,13 @@ void TeXOnePar(Buffer const & buf, os << "\\L{"; } // With CJK, the CJK tag has to be closed first (see below) - if (runparams.encoding->package() != Encoding::CJK) { + if (runparams.encoding->package() != Encoding::CJK + && !par_lang.empty()) { os << from_ascii(subst( lang_begin_command, "$$lang", par_lang)); - if (runparams.use_polyglossia + if (use_polyglossia && !par_language->polyglossiaOpts().empty()) os << "[" << from_ascii(par_language->polyglossiaOpts()) @@ -645,7 +643,8 @@ void TeXOnePar(Buffer const & buf, os << "%\n"; } // With CJK, the CJK tag had to be closed first (see above) - if (runparams.encoding->package() == Encoding::CJK) { + if (runparams.encoding->package() == Encoding::CJK + && !par_lang.empty()) { os << from_ascii(subst( lang_begin_command, "$$lang", @@ -719,6 +718,7 @@ void TeXOnePar(Buffer const & buf, } bool pending_newline = false; + bool unskip_newline = false; switch (style.latextype) { case LATEX_ITEM_ENVIRONMENT: case LATEX_LIST_ENVIRONMENT: @@ -754,7 +754,7 @@ void TeXOnePar(Buffer const & buf, // Closing the language is needed for the last paragraph; it is also // needed if we're within an \L or \R that we may have opened above (not // necessarily in this paragraph) and are about to close. - bool closing_rtl_ltr_environment = !runparams.use_polyglossia + bool closing_rtl_ltr_environment = !use_polyglossia // not for ArabTeX && (par_language->lang() != "arabic_arabtex" && outer_language->lang() != "arabic_arabtex") @@ -766,7 +766,9 @@ void TeXOnePar(Buffer const & buf, || (runparams.isLastPar && par_language->babel() != outer_language->babel())); if (closing_rtl_ltr_environment - || (runparams.isLastPar && par_language->babel() != outer_language->babel())) { + || (runparams.isLastPar + && ((!use_polyglossia && par_language->babel() != outer_language->babel()) + || (use_polyglossia && par_language->polyglossia() != outer_language->polyglossia())))) { // Since \selectlanguage write the language to the aux file, // we need to reset the language at the end of footnote or // float. @@ -783,7 +785,7 @@ void TeXOnePar(Buffer const & buf, (runparams.isLastPar && runparams.master_language) ? runparams.master_language : outer_language; - string const current_lang = runparams.use_polyglossia + string const current_lang = use_polyglossia ? getPolyglossiaEnvName(current_language) : current_language->babel(); if (!current_lang.empty()) { @@ -792,6 +794,7 @@ void TeXOnePar(Buffer const & buf, "$$lang", current_lang)); pending_newline = true; + unskip_newline = true; } } else if (!par_lang.empty()) { os << from_ascii(subst( @@ -799,14 +802,19 @@ void TeXOnePar(Buffer const & buf, "$$lang", par_lang)); pending_newline = true; + unskip_newline = true; } } } if (closing_rtl_ltr_environment) os << "}"; - if (pending_newline) + if (pending_newline) { + if (unskip_newline) + // prevent unwanted whitespace + os << '%'; os << '\n'; + } // if this is a CJK-paragraph and the next isn't, close CJK // also if the next paragraph is a multilingual environment (because of nesting)