odocstream & os, TexRow & texrow,
OutputParams const & runparams)
{
- lyxerr[Debug::LATEX] << "TeXDeeper... " << &*pit << endl;
+ LYXERR(Debug::LATEX) << "TeXDeeper... " << &*pit << endl;
ParagraphList::const_iterator par = pit;
while (par != paragraphs.end() &&
os, texrow, runparams);
}
}
- lyxerr[Debug::LATEX] << "TeXDeeper...done " << endl;
+ LYXERR(Debug::LATEX) << "TeXDeeper...done " << endl;
return par;
}
-int latexOptArgInsets(Buffer const & buf, Paragraph const & par,
- odocstream & os, OutputParams const & runparams, int number);
-
-
ParagraphList::const_iterator
TeXEnvironment(Buffer const & buf,
ParagraphList const & paragraphs,
odocstream & os, TexRow & texrow,
OutputParams const & runparams)
{
- lyxerr[Debug::LATEX] << "TeXEnvironment... " << &*pit << endl;
+ LYXERR(Debug::LATEX) << "TeXEnvironment... " << &*pit << endl;
BufferParams const & bparams = buf.params();
LyXLayout_ptr const & style = pit->layout();
- Language const * language = pit->getParLanguage(bparams);
- Language const * doc_language = bparams.language;
- Language const * previous_language =
+ Language const * const par_language = pit->getParLanguage(bparams);
+ Language const * const doc_language = bparams.language;
+ Language const * const prev_par_language =
(pit != paragraphs.begin())
? boost::prior(pit)->getParLanguage(bparams)
: doc_language;
- if (language->babel() != previous_language->babel()) {
+ if (par_language->babel() != prev_par_language->babel()) {
if (!lyxrc.language_command_end.empty() &&
- previous_language->babel() != doc_language->babel()) {
+ prev_par_language->babel() != doc_language->babel()) {
os << from_ascii(subst(
lyxrc.language_command_end,
"$$lang",
- previous_language->babel()))
+ prev_par_language->babel()))
<< '\n';
texrow.newline();
}
if (lyxrc.language_command_end.empty() ||
- language->babel() != doc_language->babel()) {
+ par_language->babel() != doc_language->babel()) {
os << from_ascii(subst(
lyxrc.language_command_begin,
"$$lang",
- language->babel()))
+ par_language->babel()))
<< '\n';
texrow.newline();
}
texrow.newline();
}
- if (par != paragraphs.end() && lyxerr.debugging(Debug::LATEX))
- lyxerr << "TeXEnvironment...done " << &*par << endl;
+ if (par != paragraphs.end())
+ LYXERR(Debug::LATEX) << "TeXEnvironment...done " << &*par << endl;
return par;
}
+}
+
int latexOptArgInsets(Buffer const & buf, Paragraph const & par,
odocstream & os, OutputParams const & runparams, int number)
}
+namespace {
+
ParagraphList::const_iterator
TeXOnePar(Buffer const & buf,
ParagraphList const & paragraphs,
OutputParams const & runparams_in,
string const & everypar)
{
- lyxerr[Debug::LATEX] << "TeXOnePar... " << &*pit << " '"
+ LYXERR(Debug::LATEX) << "TeXOnePar... " << &*pit << " '"
<< everypar << "'" << endl;
BufferParams const & bparams = buf.params();
LyXLayout_ptr style;
OutputParams runparams = runparams_in;
runparams.moving_arg |= style->needprotect;
- Language const * language = pit->getParLanguage(bparams);
- Language const * doc_language = bparams.language;
- Language const * previous_language =
+ Language const * const par_language = pit->getParLanguage(bparams);
+ Language const * const doc_language = bparams.language;
+ Language const * const prev_par_language =
(pit != paragraphs.begin())
? boost::prior(pit)->getParLanguage(bparams)
: doc_language;
- if (language->babel() != previous_language->babel()
+ if (par_language->babel() != prev_par_language->babel()
// check if we already put language command in TeXEnvironment()
&& !(style->isEnvironment()
&& (pit == paragraphs.begin() ||
|| boost::prior(pit)->getDepth() < pit->getDepth())))
{
if (!lyxrc.language_command_end.empty() &&
- previous_language->babel() != doc_language->babel())
+ prev_par_language->babel() != doc_language->babel())
{
os << from_ascii(subst(lyxrc.language_command_end,
"$$lang",
- previous_language->babel()))
+ prev_par_language->babel()))
<< '\n';
texrow.newline();
}
if (lyxrc.language_command_end.empty() ||
- language->babel() != doc_language->babel())
+ par_language->babel() != doc_language->babel())
{
os << from_ascii(subst(
lyxrc.language_command_begin,
"$$lang",
- language->babel()))
+ par_language->babel()))
<< '\n';
texrow.newline();
}
}
- LyXFont const outerfont =
- outerFont(std::distance(paragraphs.begin(), pit),
- paragraphs);
- // This must be identical to basefont in Paragraph::simpleTeXOnePar
- LyXFont basefont = (pit->beginOfBody() > 0) ?
- pit->getLabelFont(bparams, outerfont) :
- pit->getLayoutFont(bparams, outerfont);
- Encoding const & outer_encoding(*(outerfont.language()->encoding()));
- // FIXME we switch from the outer encoding to the encoding of
- // this paragraph, since I could not figure out the correct
- // logic to take the encoding of the previous paragraph into
- // account. This may result in some unneeded encoding changes.
- if (switchEncoding(os, bparams, outer_encoding,
- *(basefont.language()->encoding()))) {
- os << '\n';
- texrow.newline();
+ // Switch file encoding if necessary
+ if (bparams.inputenc == "auto") {
+ // 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
+ // sections.
+ for (pos_type i = 0; i < pit->size(); ++i) {
+ char_type const c = pit->getChar(i);
+ if (c < 0x80)
+ continue;
+ if (pit->isInset(i))
+ break;
+ // All characters before c are in the ASCII range, and
+ // c is non-ASCII (but no inset), so change the
+ // encoding to that required by the language of c.
+ Encoding const * const encoding =
+ pit->getFontSettings(bparams, i).language()->encoding();
+ if (switchEncoding(os, bparams, false,
+ *(runparams.encoding), *encoding) > 0) {
+ runparams.encoding = encoding;
+ os << '\n';
+ texrow.newline();
+ }
+ break;
+ }
}
// In an inset with unlimited length (all in one row),
break;
}
+ LyXFont const outerfont =
+ outerFont(std::distance(paragraphs.begin(), pit),
+ paragraphs);
+
// FIXME UNICODE
os << from_utf8(everypar);
bool need_par = pit->simpleTeXOnePar(buf, bparams, outerfont,
} else if (is_command)
os << '}';
+ bool pending_newline = false;
switch (style->latextype) {
case LATEX_ITEM_ENVIRONMENT:
case LATEX_LIST_ENVIRONMENT:
if (boost::next(pit) != paragraphs.end()
- && (pit->params().depth() < boost::next(pit)->params().depth())) {
- os << '\n';
- texrow.newline();
- }
+ && (pit->params().depth() < boost::next(pit)->params().depth()))
+ pending_newline = true;
break;
case LATEX_ENVIRONMENT: {
// if its the last paragraph of the current environment
// fall through possible
default:
// we don't need it for the last paragraph!!!
- if (boost::next(pit) != paragraphs.end()) {
- os << '\n';
- texrow.newline();
- }
+ if (boost::next(pit) != paragraphs.end())
+ pending_newline = true;
}
if (!pit->forceDefaultParagraphs()) {
&& (boost::next(pit) == paragraphs.end()
|| !boost::next(pit)->hasSameLayout(*pit)))
{
- os << from_ascii(pit->params().spacing().writeEnvirEnd())
- << '\n';
- texrow.newline();
+ if (pending_newline) {
+ os << '\n';
+ texrow.newline();
+ }
+ os << from_ascii(pit->params().spacing().writeEnvirEnd());
+ pending_newline = true;
}
}
if (boost::next(pit) == paragraphs.end()
- && language->babel() != doc_language->babel()) {
+ && par_language->babel() != doc_language->babel()) {
// Since \selectlanguage write the language to the aux file,
// we need to reset the language at the end of footnote or
// float.
+ if (pending_newline) {
+ os << '\n';
+ texrow.newline();
+ }
if (lyxrc.language_command_end.empty())
os << from_ascii(subst(
lyxrc.language_command_begin,
"$$lang",
- doc_language->babel()))
- << '\n';
+ doc_language->babel()));
else
os << from_ascii(subst(
lyxrc.language_command_end,
"$$lang",
- language->babel()))
- << '\n';
- texrow.newline();
+ par_language->babel()));
+ pending_newline = true;
}
- // FIXME we switch from the encoding of this paragraph to the
- // outer encoding, since I could not figure out the correct logic
- // to take the encoding of the next paragraph into account.
- // This may result in some unneeded encoding changes.
- basefont = pit->getLayoutFont(bparams, outerfont);
- if (switchEncoding(os, bparams, *(basefont.language()->encoding()),
- outer_encoding)) {
+ if (pending_newline) {
os << '\n';
texrow.newline();
}
+ runparams_in.encoding = runparams.encoding;
// we don't need it for the last paragraph!!!
// Note from JMarc: we will re-add a \n explicitely in
texrow.newline();
}
- if (boost::next(pit) != paragraphs.end() &&
- lyxerr.debugging(Debug::LATEX))
- lyxerr << "TeXOnePar...done " << &*boost::next(pit) << endl;
+ if (boost::next(pit) != paragraphs.end())
+ LYXERR(Debug::LATEX) << "TeXOnePar...done " << &*boost::next(pit) << endl;
return ++pit;
}
int switchEncoding(odocstream & os, BufferParams const & bparams,
- Encoding const & oldEnc, Encoding const & newEnc)
+ bool moving_arg, Encoding const & oldEnc,
+ Encoding const & newEnc)
{
// FIXME thailatex does not support the inputenc package, so we
// ignore switches from/to tis620-0 encoding here. This does of
// course only work as long as the non-thai text contains ASCII
// only, but it is the best we can do.
- if ((bparams.inputenc == "auto" || bparams.inputenc == "default") &&
+ // Since the \inputencoding command does not work inside sections
+ // we ignore the encoding switch also in moving arguments.
+ if (((bparams.inputenc == "auto" && !moving_arg) ||
+ bparams.inputenc == "default") &&
oldEnc.name() != newEnc.name() &&
+ oldEnc.name() != "ascii" && newEnc.name() != "ascii" &&
oldEnc.name() != "tis620-0" && newEnc.name() != "tis620-0") {
- lyxerr[Debug::LATEX] << "Changing LaTeX encoding from "
+ LYXERR(Debug::LATEX) << "Changing LaTeX encoding from "
<< oldEnc.name() << " to "
<< newEnc.name() << endl;
os << setEncoding(newEnc.iconvName());