if (data.par_language->encoding()->package() == Encoding::CJK &&
state->open_encoding_ != CJK && pit->isMultiLingual(bparams)) {
if (prev_par_language->encoding()->package() == Encoding::CJK) {
- docstring const cjkenc = (bparams.encoding().iconvName() == "UTF-8"
+ docstring const cjkenc = (bparams.encoding().name() == "utf8-cjk"
&& LaTeXFeatures::isAvailable("CJKutf8")) ?
from_ascii("UTF8")
: from_ascii(data.par_language->encoding()->latexName());
lang_end_command = "}";
lang_command_termination.clear();
}
-
+
bool const localswitch_needed = localswitch && par_lang != outer_lang;
// localswitches need to be closed and reopened at each par
if (!localswitch
&& (!using_begin_end || langOpenedAtThisLevel(state))
&& !lang_end_command.empty()
- && prev_lang != outer_lang
+ && prev_lang != outer_lang
&& !prev_lang.empty()
&& (!using_begin_end || !style.isEnvironment())) {
os << from_ascii(subst(lang_end_command,
// context (nesting issue).
if (par_language->encoding()->package() == Encoding::CJK
&& state->open_encoding_ != CJK && state->cjk_inherited_ == 0) {
- docstring const cjkenc = (bparams.encoding().iconvName() == "UTF-8"
+ docstring const cjkenc = (bparams.encoding().name() == "utf8-cjk"
&& LaTeXFeatures::isAvailable("CJKutf8")) ?
from_ascii("UTF8")
: from_ascii(par_language->encoding()->latexName());
// 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)
if (nextpar
- && state->open_encoding_ == CJK
+ && (state->open_encoding_ == CJK && bparams.encoding().iconvName() != "UTF-8")
&& (nextpar_language->encoding()->package() != Encoding::CJK
|| (nextpar->layout().isEnvironment() && nextpar->isMultiLingual(bparams)))
// inbetween environments, CJK has to be closed later (nesting!)
}
// If this is the last paragraph, close the CJK environment
- // if necessary. If it's an environment, we'll have to \end that first.
- if (runparams.isLastPar && !style.isEnvironment()) {
+ // if necessary. If it's an environment or nested in an environment,
+ // we'll have to \end that first.
+ if (runparams.isLastPar && !style.isEnvironment()
+ && par.params().depth() < 1) {
switch (state->open_encoding_) {
case CJK: {
// do nothing at the end of child documents
if (maintext && buf.masterBuffer() != &buf)
break;
- // end of main text
+ // end of main text: also insert a \clearpage (see #5386)
if (maintext) {
- os << "\n\\end{CJK}\n";
+ os << "\n\\clearpage\n\\end{CJK}\n";
// end of an inset
} else
os << "\\end{CJK}";
}
// Open a CJK environment at the beginning of the main buffer
- // if the document's language is a CJK language
- // (but not in child documents)
+ // (but not in child documents or documents using system fonts)
+ // if the document's language is a CJK language (with some exceptions)
+ // or the document encoding is utf8-cjk:
OutputState * state = getOutputState();
- if (maintext && !is_child
- && bparams.language->encoding()->package() == Encoding::CJK) {
- docstring const cjkenc = (bparams.encoding().iconvName() == "UTF-8"
- && LaTeXFeatures::isAvailable("CJKutf8")) ?
- from_ascii("UTF8")
- : from_ascii(bparams.encoding().latexName());
+ if (maintext && !is_child && !bparams.useNonTeXFonts
+ && ((bparams.language->encoding()->package() == Encoding::CJK
+ && (bparams.encoding().iconvName() != "UTF-8"
+ || bparams.encoding().name() == "utf8-cjk"
+ || bparams.encoding().name() == "utf8" ))
+ || (bparams.encoding().name() == "utf8-cjk"
+ && LaTeXFeatures::isAvailable("CJKutf8")))) {
+ docstring const cjkenc = bparams.encoding().iconvName() == "UTF-8"
+ ? from_ascii("UTF8") : from_ascii(bparams.encoding().latexName());
os << "\\begin{CJK}{" << cjkenc
<< "}{" << from_ascii(bparams.fonts_cjk) << "}%\n";
state->open_encoding_ = CJK;
// If the last paragraph is an environment, we'll have to close
// CJK at the very end to do proper nesting.
if (maintext && !is_child && state->open_encoding_ == CJK) {
- os << "\\end{CJK}\n";
+ os << "\\clearpage\n\\end{CJK}\n";
state->open_encoding_ = none;
}
// Likewise for polyglossia or when using begin/end commands
// except if we use CJKutf8
bool const from_to_cjk =
((oldEnc.package() == Encoding::CJK && newEnc.package() != Encoding::CJK)
- || (oldEnc.package() != Encoding::CJK && newEnc.package() == Encoding::CJK))
- && (bparams.inputenc != "utf8" && LaTeXFeatures::isAvailable("CJKutf8"));
+ || (oldEnc.package() != Encoding::CJK && newEnc.package() == Encoding::CJK))
+ && ((bparams.encoding().name() != "utf8-cjk" && bparams.encoding().name() != "utf8")
+ || !LaTeXFeatures::isAvailable("CJKutf8"));
if (!force && !from_to_cjk
&& ((bparams.inputenc != "auto" && bparams.inputenc != "default") || moving_arg))
return make_pair(false, 0);
// This does of course only work in special cases (e.g. switch from
// tis620-0 to latin1, but the text in latin1 contains ASCII only),
// but it is the best we can do
- if (oldEnc.package() == Encoding::none
- || newEnc.package() == Encoding::none)
+ //
+ // 2019-01-08 Possibly no longer required since tis620-0 is supported
+ // by inputenc (but check special encodings "utf8-plain" and "default").
+ if (oldEnc.package() == Encoding::none || newEnc.package() == Encoding::none)
return make_pair(false, 0);
- LYXERR(Debug::LATEX, "Changing LaTeX encoding from "
- << oldEnc.name() << " to " << newEnc.name());
- os << setEncoding(newEnc.iconvName());
- if (bparams.inputenc == "default")
- return make_pair(true, 0);
+ // change encoding (not required with UTF8)
+ if (bparams.encoding().iconvName() != "UTF-8") {
+ LYXERR(Debug::LATEX, "Changing LaTeX encoding from "
+ << oldEnc.name() << " to " << newEnc.name());
+ os << setEncoding(newEnc.iconvName());
+ if (bparams.inputenc == "default")
+ return make_pair(true, 0);
+ }
docstring const inputenc_arg(from_ascii(newEnc.latexName()));
OutputState * state = getOutputState();
count += 7;
}
docstring const cjkenc = (bparams.encoding().iconvName() == "UTF-8"
- && LaTeXFeatures::isAvailable("CJKutf8")) ?
- from_ascii("UTF8")
- : from_ascii(bparams.encoding().latexName());
+ && LaTeXFeatures::isAvailable("CJKutf8"))
+ ? from_ascii("UTF8") : from_ascii(newEnc.latexName());
os << "\\begin{CJK}{" << cjkenc << "}{"
<< from_ascii(bparams.fonts_cjk) << "}";
state->open_encoding_ = CJK;
}
// Dead code to avoid a warning:
return make_pair(true, 0);
-
}
} // namespace lyx