#include "Buffer.h"
#include "BufferParams.h"
-#include "support/debug.h"
#include "Encoding.h"
#include "InsetList.h"
#include "Language.h"
#include "insets/InsetBibitem.h"
#include "insets/InsetOptArg.h"
+#include "support/debug.h"
#include "support/lstrings.h"
#include <boost/next_prior.hpp>
ParagraphList::const_iterator
TeXEnvironment(Buffer const & buf,
- ParagraphList const & paragraphs,
+ Text const & text,
ParagraphList::const_iterator pit,
odocstream & os, TexRow & texrow,
OutputParams const & runparams);
ParagraphList::const_iterator
TeXOnePar(Buffer const & buf,
- ParagraphList const & paragraphs,
+ Text const & text,
ParagraphList::const_iterator pit,
odocstream & os, TexRow & texrow,
OutputParams const & runparams,
ParagraphList::const_iterator
TeXDeeper(Buffer const & buf,
- ParagraphList const & paragraphs,
+ Text const & text,
ParagraphList::const_iterator pit,
odocstream & os, TexRow & texrow,
OutputParams const & runparams)
LYXERR(Debug::LATEX, "TeXDeeper... " << &*pit);
ParagraphList::const_iterator par = pit;
+ ParagraphList const & paragraphs = text.paragraphs();
+
while (par != paragraphs.end() &&
par->params().depth() == pit->params().depth()) {
if (par->layout()->isEnvironment()) {
- par = TeXEnvironment(buf, paragraphs, par,
+ par = TeXEnvironment(buf, text, par,
os, texrow, runparams);
} else {
- par = TeXOnePar(buf, paragraphs, par,
+ par = TeXOnePar(buf, text, par,
os, texrow, runparams);
}
}
ParagraphList::const_iterator
TeXEnvironment(Buffer const & buf,
- ParagraphList const & paragraphs,
+ Text const & text,
ParagraphList::const_iterator pit,
odocstream & os, TexRow & texrow,
OutputParams const & runparams)
BufferParams const & bparams = buf.params();
- LayoutPtr const & style = pit->layout();
+ LayoutPtr const & style = pit->forceEmptyLayout() ?
+ bparams.documentClass().emptyLayout() : pit->layout();
+
+ ParagraphList const & paragraphs = text.paragraphs();
Language const * const par_language = pit->getParLanguage(bparams);
Language const * const doc_language = bparams.language;
if (style->isEnvironment()) {
os << "\\begin{" << from_ascii(style->latexname()) << '}';
if (style->optionalargs > 0) {
- int ret = latexOptArgInsets(buf, *pit, os, runparams,
+ int ret = latexOptArgInsets(*pit, os, runparams,
style->optionalargs);
while (ret > 0) {
texrow.newline();
ParagraphList::const_iterator par = pit;
do {
- par = TeXOnePar(buf, paragraphs, par, os, texrow, runparams);
+ par = TeXOnePar(buf, text, par, os, texrow, runparams);
if (par == paragraphs.end()) {
// Make sure that the last paragraph is
os << '\n';
texrow.newline();
}
- par = TeXDeeper(buf, paragraphs, par, os, texrow,
+ par = TeXDeeper(buf, text, par, os, texrow,
runparams);
}
} while (par != paragraphs.end()
}
-int latexOptArgInsets(Buffer const & buf, Paragraph const & par,
- odocstream & os, OutputParams const & runparams, int number)
+int latexOptArgInsets(Paragraph const & par, odocstream & os,
+ OutputParams const & runparams, int number)
{
int lines = 0;
if (it->inset->lyxCode() == OPTARG_CODE) {
InsetOptArg * ins =
static_cast<InsetOptArg *>(it->inset);
- lines += ins->latexOptional(buf, os, runparams);
+ lines += ins->latexOptional(os, runparams);
--number;
}
}
ParagraphList::const_iterator
TeXOnePar(Buffer const & buf,
- ParagraphList const & paragraphs,
+ Text const & text,
ParagraphList::const_iterator pit,
odocstream & os, TexRow & texrow,
OutputParams const & runparams_in,
LYXERR(Debug::LATEX, "TeXOnePar... " << &*pit << " '"
<< everypar << "'");
BufferParams const & bparams = buf.params();
- LayoutPtr style;
+ ParagraphList const & paragraphs = text.paragraphs();
if (runparams_in.verbatim) {
- int const dist = std::distance(paragraphs.begin(), pit);
+ int const dist = distance(paragraphs.begin(), pit);
Font const outerfont = outerFont(dist, paragraphs);
// No newline if only one paragraph in this lyxtext
texrow.newline();
}
- /*bool need_par = */ pit->latex(buf, bparams, outerfont,
+ /*bool need_par = */ pit->latex(bparams, outerfont,
os, texrow, runparams_in);
return ++pit;
}
+ // FIXME This comment doesn't make sense. What's the
+ // length got to do with forceEmptyLayout()? I.e., what
+ // was forceDefaultParagraphs()?
// In an inset with unlimited length (all in one row),
// force layout to default
- if (!pit->forceDefaultParagraphs())
- style = pit->layout();
- else
- style = bparams.getTextClass().defaultLayout();
+ LayoutPtr const style = pit->forceEmptyLayout() ?
+ bparams.documentClass().emptyLayout() : 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() && runparams.local_font != 0 &&
- open_encoding_ == CJK) {
+ if (pit == paragraphs.begin() && !maintext && open_encoding_ == CJK) {
cjk_inherited_ = true;
open_encoding_ = none;
}
- if (pit == paragraphs.begin() && runparams.local_font == 0) {
- // Open a CJK environment at the beginning of the main buffer
- // if the document's language is a CJK language
- if (bparams.encoding().package() == Encoding::CJK) {
- os << "\\begin{CJK}{" << from_ascii(bparams.encoding().latexName())
- << "}{}%\n";
- texrow.newline();
- open_encoding_ = CJK;
- }
- if (!lyxrc.language_auto_begin && !bparams.language->babel().empty()) {
- // FIXME UNICODE
- os << from_utf8(subst(lyxrc.language_command_begin,
- "$$lang",
- bparams.language->babel()))
- << '\n';
- texrow.newline();
- }
- }
-
// This paragraph's language
Language const * const par_language = pit->getParLanguage(bparams);
// The document's language
// sections.
for (pos_type i = 0; i < pit->size(); ++i) {
char_type const c = pit->getChar(i);
- if (runparams.encoding->package() == Encoding::inputenc && c < 0x80)
+ Encoding const * const encoding =
+ pit->getFontSettings(bparams, i).language()->encoding();
+ if (encoding->package() != Encoding::CJK &&
+ runparams.encoding->package() == Encoding::inputenc &&
+ 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();
-
- // with CJK, only add switch if we have CJK content at the beginning
+ // With CJK, only add switch if we have CJK content at the beginning
// of the paragraph
if (encoding->package() != Encoding::CJK || i == 0) {
OutputParams tmp_rp = runparams;
runparams.moving_arg = false;
pair<bool, int> enc_switch = switchEncoding(os, bparams, runparams,
- *(runparams.encoding), *encoding);
+ *encoding);
runparams = tmp_rp;
// the following is necessary after a CJK environment in a multilingual
// context (nesting issue).
}
}
- // In an inset with unlimited length (all in one row),
- // don't allow any special options in the paragraph
- if (!pit->forceDefaultParagraphs()) {
+ bool const useSetSpace = bparams.documentClass().provides("SetSpace");
+ if (pit->allowParagraphCustomization()) {
if (pit->params().startOfAppendix()) {
os << "\\appendix\n";
texrow.newline();
&& (pit == paragraphs.begin()
|| !boost::prior(pit)->hasSameLayout(*pit)))
{
- os << from_ascii(pit->params().spacing().writeEnvirBegin())
+ os << from_ascii(pit->params().spacing().writeEnvirBegin(useSetSpace))
<< '\n';
texrow.newline();
}
// Separate handling of optional argument inset.
if (style->optionalargs > 0) {
- int ret = latexOptArgInsets(buf, *pit, os, runparams,
+ int ret = latexOptArgInsets(*pit, os, runparams,
style->optionalargs);
while (ret > 0) {
texrow.newline();
break;
}
- Font const outerfont =
- outerFont(std::distance(paragraphs.begin(), pit),
+ Font const outerfont = outerFont(distance(paragraphs.begin(), pit),
paragraphs);
// FIXME UNICODE
os << from_utf8(everypar);
- bool need_par = pit->latex(buf, bparams, outerfont,
+ bool need_par = pit->latex(bparams, outerfont,
os, texrow, runparams);
// Make sure that \\par is done with the font of the last
// We do not need to use to change the font for the last paragraph
// or for a command.
- Font const font =
- (pit->empty()
+ Font const font = pit->empty()
? pit->getLayoutFont(bparams, outerfont)
- : pit->getFont(bparams, pit->size() - 1, outerfont));
+ : pit->getFont(bparams, pit->size() - 1, outerfont);
bool is_command = style->isCommand();
pending_newline = true;
}
- if (!pit->forceDefaultParagraphs()) {
+ if (pit->allowParagraphCustomization()) {
if (!pit->params().spacing().isDefault()
&& (boost::next(pit) == paragraphs.end()
|| !boost::next(pit)->hasSameLayout(*pit)))
os << '\n';
texrow.newline();
}
- os << from_ascii(pit->params().spacing().writeEnvirEnd());
+ os << from_ascii(pit->params().spacing().writeEnvirEnd(useSetSpace));
pending_newline = true;
}
}
switch (open_encoding_) {
case CJK: {
// end of main text
- if (runparams.local_font == 0) {
+ if (maintext) {
os << '\n';
texrow.newline();
os << "\\end{CJK}\n";
// do nothing
break;
}
- // auto_end tag only if the last par is in a babel language
- if (runparams.local_font == 0 && !lyxrc.language_auto_end &&
- !bparams.language->babel().empty() &&
- font.language()->encoding()->package() != Encoding::CJK) {
- os << from_utf8(subst(lyxrc.language_command_end,
- "$$lang",
- bparams.language->babel()))
- << '\n';
- texrow.newline();
- }
}
// If this is the last paragraph, and a local_font was set upon entering
// LaTeX all paragraphs
void latexParagraphs(Buffer const & buf,
- ParagraphList const & paragraphs,
+ Text const & text,
odocstream & os,
TexRow & texrow,
OutputParams const & runparams,
{
bool was_title = false;
bool already_title = false;
- TextClass const & tclass = buf.params().getTextClass();
+ BufferParams const & bparams = buf.params();
+ DocumentClass const & tclass = bparams.documentClass();
+ ParagraphList const & paragraphs = text.paragraphs();
ParagraphList::const_iterator par = paragraphs.begin();
ParagraphList::const_iterator endpar = paragraphs.end();
const_cast<OutputParams&>(runparams).par_end = 0;
}
+ bool const maintext = text.isMainText(buf);
+
+ // Open a CJK environment at the beginning of the main buffer
+ // 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";
+ texrow.newline();
+ open_encoding_ = CJK;
+ }
+ // if "auto begin" is switched off, explicitely switch the
+ // language on at start
+ if (maintext && !lyxrc.language_auto_begin &&
+ !bparams.language->babel().empty()) {
+ // FIXME UNICODE
+ os << from_utf8(subst(lyxrc.language_command_begin,
+ "$$lang",
+ bparams.language->babel()))
+ << '\n';
+ texrow.newline();
+ }
+
+ ParagraphList::const_iterator lastpar;
// if only_body
while (par != endpar) {
- ParagraphList::const_iterator lastpar = par;
+ lastpar = par;
// well we have to check if we are in an inset with unlimited
// length (all in one row) if that is true then we don't allow
// any special options in the paragraph and also we don't allow
// any environment other than the default layout of the
// text class to be valid!
- if (!par->forceDefaultParagraphs()) {
- LayoutPtr const & layout = par->layout();
+ if (par->allowParagraphCustomization()) {
+ LayoutPtr const & layout = par->forceEmptyLayout() ?
+ tclass.emptyLayout() :
+ par->layout();
if (layout->intitle) {
if (already_title) {
}
if (layout->is_environment) {
- par = TeXOnePar(buf, paragraphs, par, os, texrow,
+ par = TeXOnePar(buf, text, par, os, texrow,
runparams, everypar);
} else if (layout->isEnvironment() ||
!par->params().leftIndent().zero()) {
- par = TeXEnvironment(buf, paragraphs, par, os,
+ par = TeXEnvironment(buf, text, par, os,
texrow, runparams);
} else {
- par = TeXOnePar(buf, paragraphs, par, os, texrow,
+ par = TeXOnePar(buf, text, par, os, texrow,
runparams, everypar);
}
} else {
- par = TeXOnePar(buf, paragraphs, par, os, texrow,
+ par = TeXOnePar(buf, text, par, os, texrow,
runparams, everypar);
}
- if (std::distance(lastpar, par) >= std::distance(lastpar, endpar))
+ if (distance(lastpar, par) >= distance(lastpar, endpar))
break;
}
// It might be that we only have a title in this document
}
texrow.newline();
}
+ // if "auto end" is switched off, explicitely close the language at the end
+ // but only if the last par is in a babel language
+ if (maintext && !lyxrc.language_auto_end && !bparams.language->babel().empty() &&
+ lastpar->getParLanguage(bparams)->encoding()->package() != Encoding::CJK) {
+ os << from_utf8(subst(lyxrc.language_command_end,
+ "$$lang",
+ bparams.language->babel()))
+ << '\n';
+ texrow.newline();
+ }
// If the last paragraph is an environment, we'll have to close
// CJK at the very end to do proper nesting.
- if (open_encoding_ == CJK) {
+ if (maintext && open_encoding_ == CJK) {
os << "\\end{CJK}\n";
texrow.newline();
open_encoding_ = none;
pair<bool, int> switchEncoding(odocstream & os, BufferParams const & bparams,
- OutputParams const & runparams, Encoding const & oldEnc,
- Encoding const & newEnc)
+ OutputParams const & runparams, Encoding const & newEnc)
{
+ Encoding const oldEnc = *runparams.encoding;
bool moving_arg = runparams.moving_arg;
if ((bparams.inputenc != "auto" && bparams.inputenc != "default")
|| moving_arg)