return state->lang_switch_depth_.size() == 0
? true
- : state->lang_switch_depth_.top() == state->nest_level_;
+ : abs(state->lang_switch_depth_.top()) == state->nest_level_;
+}
+
+
+bool isLocalSwitch(OutputState const * state)
+{
+ // Return true if the language was opened by the \text<lang> command.
+
+ return state->lang_switch_depth_.size()
+ && state->lang_switch_depth_.top() < 0;
+}
+
+
+bool langOpenedAtThisLevel(OutputState const * state)
+{
+ // Return true if the language was opened at the current nesting level.
+
+ return state->lang_switch_depth_.size()
+ && abs(state->lang_switch_depth_.top()) == state->nest_level_;
}
prev_par_lang))
// the '%' is necessary to prevent unwanted whitespace
<< "%\n";
- if (use_polyglossia) {
- state->lang_switch_depth_.pop();
- state->open_polyglossia_lang_.pop();
- }
+ if (use_polyglossia)
+ popPolyglossiaLang();
}
+ // If no language was explicitly opened and we are using
+ // polyglossia, then the current polyglossia language is
+ // the document language.
+ string const & pol_lang = use_polyglossia
+ && state->lang_switch_depth_.size()
+ ? openPolyglossiaLang(state)
+ : doc_lang;
+
if ((lang_end_command.empty() ||
par_lang != doc_lang ||
- par_lang != openPolyglossiaLang(state)) &&
+ par_lang != pol_lang) &&
!par_lang.empty()) {
string bc = use_polyglossia ?
getPolyglossiaBegin(lang_begin_command, par_lang,
os << bc;
// the '%' is necessary to prevent unwanted whitespace
os << "%\n";
- if (use_polyglossia) {
- state->lang_switch_depth_.push(state->nest_level_);
- state->open_polyglossia_lang_.push(par_lang);
- }
+ if (use_polyglossia)
+ pushPolyglossiaLang(par_lang);
}
}
os << breakln;
// Close any polyglossia language opened at this nest level
if (runparams.use_polyglossia) {
- OutputState * state = getOutputState();
- while (state->lang_switch_depth_.size()
- && state->lang_switch_depth_.top() == state->nest_level_) {
- os << "\\end{" << openPolyglossiaLang(state)
- << "}%\n";
- state->lang_switch_depth_.pop();
- state->open_polyglossia_lang_.pop();
+ while (langOpenedAtThisLevel(state)) {
+ if (isLocalSwitch(state)) {
+ os << "}";
+ } else {
+ os << "\\end{"
+ << openPolyglossiaLang(state)
+ << "}%\n";
+ }
+ popPolyglossiaLang();
}
}
state->nest_level_ -= 1;
} // namespace anon
-void pushPolyglossiaLang(string const & lang_name)
+void pushPolyglossiaLang(string const & lang_name, bool localswitch)
{
OutputState * state = getOutputState();
- state->lang_switch_depth_.push(state->nest_level_);
+ int nest_level = localswitch ? -state->nest_level_ : state->nest_level_;
+ state->lang_switch_depth_.push(nest_level);
state->open_polyglossia_lang_.push(lang_name);
}
"$$lang",
prev_lang))
<< lang_command_termination;
- if (use_polyglossia && !localswitch) {
- state->lang_switch_depth_.pop();
- state->open_polyglossia_lang_.pop();
- }
+ if (use_polyglossia)
+ popPolyglossiaLang();
}
// We need to open a new language if we couldn't close the previous
: subst(lang_begin_command, "$$lang", par_lang);
os << bc;
os << lang_command_termination;
- if (use_polyglossia && !localswitch) {
- state->lang_switch_depth_.push(state->nest_level_);
- state->open_polyglossia_lang_.push(par_lang);
- }
+ if (use_polyglossia)
+ pushPolyglossiaLang(par_lang, localswitch);
}
}
}
"$$lang",
par_lang))
<< lang_command_termination;
- if (use_polyglossia && !localswitch) {
- state->lang_switch_depth_.push(state->nest_level_);
- state->open_polyglossia_lang_.push(par_lang);
- }
+ if (use_polyglossia)
+ pushPolyglossiaLang(par_lang, localswitch);
}
runparams.encoding = encoding;
}
switch (style.latextype) {
case LATEX_ITEM_ENVIRONMENT:
case LATEX_LIST_ENVIRONMENT:
- if (nextpar && par_lang != nextpar_lang
- && nextpar->getDepth() == par.getDepth()
+ if ((nextpar && par_lang != nextpar_lang
+ && nextpar->getDepth() == par.getDepth())
|| (atSameLastLangSwitchDepth(state) && nextpar
&& nextpar->getDepth() < par.getDepth()))
close_lang_switch = use_polyglossia;
os << bc;
pending_newline = !localswitch;
unskip_newline = !localswitch;
- if (use_polyglossia && !localswitch) {
- state->lang_switch_depth_.push(
- state->nest_level_);
- state->open_polyglossia_lang_.push(current_lang);
- }
+ if (use_polyglossia)
+ pushPolyglossiaLang(current_lang, localswitch);
}
} else if (!par_lang.empty()) {
// If we are in an environment, we have to close the "outer" language afterwards
par_lang));
pending_newline = !localswitch;
unskip_newline = !localswitch;
- if (use_polyglossia && !localswitch) {
- state->lang_switch_depth_.pop();
- state->open_polyglossia_lang_.pop();
- }
+ if (use_polyglossia)
+ popPolyglossiaLang();
}
}
}
{ os << "% LaTeX Output Error\n"; return; } );
BufferParams const & bparams = buf.params();
+ BufferParams const & mparams = buf.masterParams();
bool const maintext = text.isMainText();
bool const is_child = buf.masterBuffer() != &buf;
+ bool const multibib_child = maintext && is_child
+ && mparams.multibib == "child";
+
+ if (multibib_child && mparams.useBiblatex())
+ os << "\\newrefsection";
+ else if (multibib_child && mparams.useBibtopic()) {
+ os << "\\begin{btUnit}\n";
+ runparams.openbtUnit = true;
+ }
// Open a CJK environment at the beginning of the main buffer
// if the document's language is a CJK language
: subst(lang_begin_command, "$$lang", mainlang);
os << bc;
os << '\n';
- if (runparams.use_polyglossia) {
- state->lang_switch_depth_.push(state->nest_level_);
- state->open_polyglossia_lang_.push(mainlang);
- }
+ if (runparams.use_polyglossia)
+ pushPolyglossiaLang(mainlang);
}
- runparams.pushPolyglossiaLang = pushPolyglossiaLang;
- runparams.popPolyglossiaLang = popPolyglossiaLang;
-
ParagraphList const & paragraphs = text.paragraphs();
if (runparams.par_begin == runparams.par_end) {
was_title = false;
}
+ if (layout.isCommand() && !layout.latexname().empty()
+ && layout.latexname() == bparams.multibib) {
+ if (runparams.openbtUnit)
+ os << "\\end{btUnit}\n";
+ if (!bparams.useBiblatex()) {
+ os << '\n' << "\\begin{btUnit}\n";
+ runparams.openbtUnit = true;
+ }
+ }
if (!layout.isEnvironment() && par->params().leftIndent().zero()) {
// This is a standard top level paragraph, TeX it and continue.
}
}
+ if (maintext && !is_child && runparams.openbtUnit)
+ os << "\\end{btUnit}\n";
+
// if "auto end" is switched off, explicitly close the language at the end
// but only if the last par is in a babel or polyglossia language
string const lang_end_command = runparams.use_polyglossia ?
"$$lang",
mainlang))
<< '\n';
- if (runparams.use_polyglossia) {
- state->lang_switch_depth_.pop();
- state->open_polyglossia_lang_.pop();
- }
+ if (runparams.use_polyglossia)
+ popPolyglossiaLang();
}
// If the last paragraph is an environment, we'll have to close
"$$lang",
pol_lang))
<< '\n';
- if (runparams.use_polyglossia) {
- state->lang_switch_depth_.pop();
- state->open_polyglossia_lang_.pop();
- }
+ if (runparams.use_polyglossia)
+ popPolyglossiaLang();
}
// reset inherited encoding
if (state->cjk_inherited_ == 0)
state->open_encoding_ = CJK;
}
+
+ if (multibib_child && mparams.useBibtopic()) {
+ os << "\\end{btUnit}\n";
+ runparams.openbtUnit = false;
+ }
}