#include "insets/InsetBibitem.h"
#include "insets/InsetOptArg.h"
-#include "support/assert.h"
+#include "support/lassert.h"
#include "support/debug.h"
#include "support/lstrings.h"
};
static int open_encoding_ = none;
-static bool cjk_inherited_ = false;
+static int cjk_inherited_ = 0;
ParagraphList::const_iterator
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();
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();
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);
}
/*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;
}
// 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();
}
// 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
// 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())
// 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;
}
// 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) {
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);
}
// 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.
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: {
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);
}
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);
}