static TeXEnvironementData prepareEnvironement(Buffer const & buf, Text const & text,
- ParagraphList::const_iterator pit, odocstream & os, TexRow & texrow,
+ ParagraphList::const_iterator pit, otexstream & os, TexRow & texrow,
OutputParams const & runparams)
{
TeXEnvironementData data;
}
-static void finishEnvironement(odocstream & os, TexRow & texrow,
+static void finishEnvironement(otexstream & os, TexRow & texrow,
OutputParams const & runparams, TeXEnvironementData const & data)
{
if (open_encoding_ == CJK && data.cjk_nested) {
void TeXEnvironment(Buffer const & buf,
Text const & text, OutputParams const & runparams,
- pit_type & pit, odocstream & os, TexRow & texrow)
+ pit_type & pit, otexstream & os, TexRow & texrow)
{
ParagraphList const & paragraphs = text.paragraphs();
ParagraphList::const_iterator par = paragraphs.constIterator(pit);
} // namespace anon
-int latexArgInsets(Paragraph const & par, odocstream & os,
+int latexArgInsets(Paragraph const & par, otexstream & os,
OutputParams const & runparams, unsigned int reqargs,
unsigned int optargs)
{
return lines;
}
+namespace {
+
+// output the proper paragraph start according to latextype.
+void parStartCommand(Paragraph const & par, otexstream & os, TexRow & texrow,
+ OutputParams const & runparams,Layout const & style)
+{
+ switch (style.latextype) {
+ case LATEX_COMMAND:
+ os << '\\' << from_ascii(style.latexname());
+
+ // Separate handling of optional argument inset.
+ if (style.optargs != 0 || style.reqargs != 0) {
+ int ret = latexArgInsets(par, os, runparams, style.reqargs, style.optargs);
+ while (ret > 0) {
+ texrow.newline();
+ --ret;
+ }
+ }
+ else
+ os << from_ascii(style.latexparam());
+ break;
+ case LATEX_ITEM_ENVIRONMENT:
+ case LATEX_LIST_ENVIRONMENT:
+ os << "\\item ";
+ break;
+ case LATEX_BIB_ENVIRONMENT:
+ // ignore this, the inset will write itself
+ break;
+ default:
+ break;
+ }
+}
+
+} // namespace anon
// FIXME: this should be anonymous
void TeXOnePar(Buffer const & buf,
Text const & text,
pit_type pit,
- odocstream & os, TexRow & texrow,
+ otexstream & os, TexRow & texrow,
OutputParams const & runparams_in,
string const & everypar,
int start_pos, int end_pos)
{
-
BufferParams const & bparams = buf.params();
ParagraphList const & paragraphs = text.paragraphs();
Paragraph const & par = paragraphs.at(pit);
<< everypar << "'");
OutputParams runparams = runparams_in;
- runparams.isLastPar = (pit == paragraphs.size() - 1);
+ runparams.isLastPar = (pit == pit_type(paragraphs.size() - 1));
// We reinitialze par begin and end to be on the safe side
// with embedded inset as we don't know if they set those
// value correctly.
if (style.pass_thru) {
Font const outerfont = text.outerFont(pit);
+ parStartCommand(par, os, texrow,runparams, style);
+
par.latex(bparams, outerfont, os, texrow, runparams, start_pos,
end_pos);
- os << '\n';
+
+ // I did not create a parEndCommand for this minuscule
+ // task because in the other user of parStartCommand
+ // the code is different (JMarc)
+ if (style.isCommand())
+ os << "}\n";
+ else
+ os << '\n';
texrow.newline();
if (!style.parbreak_is_newline) {
os << '\n';
&& priorpar->layout().isEnvironment()
&& (priorpar->getDepth() > par.getDepth()
|| (priorpar->getDepth() == par.getDepth()
- && priorpar->layout() != par.layout()));
+ && priorpar->layout() != par.layout()));
Language const * const prev_language =
(pit != 0)
? (use_prev_env_language ? prev_env_language_
lang_end_command = "\\end{$$lang}";
}
if (par_lang != prev_lang
- // check if we already put language command in TeXEnvironment()
- && !(style.isEnvironment()
- && (pit == 0 ||
- (priorpar->layout() != par.layout() &&
- priorpar->getDepth() <= par.getDepth())
- || priorpar->getDepth() < par.getDepth())))
+ // check if we already put language command in TeXEnvironment()
+ && !(style.isEnvironment()
+ && (pit == 0 || (priorpar->layout() != par.layout()
+ && priorpar->getDepth() <= par.getDepth())
+ || priorpar->getDepth() < par.getDepth())))
{
if (!lang_end_command.empty() &&
prev_lang != outer_lang &&
// the previous one, if the current language is different than the
// outer_language (which is currently in effect once the previous one
// is closed).
- if ((lang_end_command.empty() ||
- par_lang != outer_lang) &&
- !par_lang.empty()) {
+ if ((lang_end_command.empty() || par_lang != outer_lang)
+ && !par_lang.empty()) {
// If we're inside an inset, and that inset is within an \L or \R
// (or equivalents), then within the inset, too, any opposite
// language paragraph should appear within an \L or \R (in addition
// to, outside of, the normal language switch commands).
// This behavior is not correct for ArabTeX, though.
- if (!runparams.use_polyglossia &&
+ if (!runparams.use_polyglossia
// not for ArabTeX
- (par_language->lang() != "arabic_arabtex" &&
- outer_language->lang() != "arabic_arabtex") &&
+ && par_language->lang() != "arabic_arabtex"
+ && outer_language->lang() != "arabic_arabtex"
// are we in an inset?
- runparams.local_font != 0 &&
+ && runparams.local_font != 0
// is the inset within an \L or \R?
//
// FIXME: currently, we don't check this; this means that
// doesn't seem to hurt (though latex will complain)
//
// is this paragraph in the opposite direction?
- runparams.local_font->isRightToLeft() !=
- par_language->rightToLeft()
- ) {
+ && runparams.local_font->isRightToLeft() != par_language->rightToLeft()) {
// FIXME: I don't have a working copy of the Arabi package, so
// I'm not sure if the farsi and arabic_arabi stuff is correct
// or not...
// Switch file encoding if necessary; no need to do this for "default"
// encoding, since this only affects the position of the outputted
// \inputencoding command; the encoding switch will occur when necessary
- if (bparams.inputenc == "auto" &&
- runparams.encoding->package() != Encoding::none) {
+ if (bparams.inputenc == "auto"
+ && runparams.encoding->package() != Encoding::none) {
// 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
char_type const c = par.getChar(i);
Encoding const * const encoding =
par.getFontSettings(bparams, i).language()->encoding();
- if (encoding->package() != Encoding::CJK &&
- runparams.encoding->package() == Encoding::inputenc &&
- c < 0x80)
+ if (encoding->package() != Encoding::CJK
+ && runparams.encoding->package() == Encoding::inputenc
+ && c < 0x80)
continue;
if (par.isInset(i))
break;
// encoding to that required by the language of c.
// With CJK, only add switch if we have CJK content at the beginning
// of the paragraph
- if (encoding->package() != Encoding::CJK || i == 0) {
- pair<bool, int> enc_switch = switchEncoding(os, bparams, runparams,
- *encoding);
- // 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_ == 0) {
- os << "\\begin{CJK}{" << from_ascii(par_language->encoding()->latexName())
- << "}{" << from_ascii(bparams.fonts_cjk) << "}%\n";
- open_encoding_ = CJK;
+ if (i != 0 && encoding->package() == Encoding::CJK)
+ continue;
+
+ pair<bool, int> enc_switch = switchEncoding(os.os(),
+ bparams, runparams, *encoding);
+ // 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_ == 0) {
+ os << "\\begin{CJK}{" << from_ascii(par_language->encoding()->latexName())
+ << "}{" << from_ascii(bparams.fonts_cjk) << "}%\n";
+ open_encoding_ = CJK;
+ texrow.newline();
+ }
+ if (encoding->package() != Encoding::none && enc_switch.first) {
+ if (enc_switch.second > 0) {
+ // the '%' is necessary to prevent unwanted whitespace
+ os << "%\n";
texrow.newline();
}
- if (encoding->package() != Encoding::none && enc_switch.first) {
- if (enc_switch.second > 0) {
- // the '%' is necessary to prevent unwanted whitespace
- os << "%\n";
- texrow.newline();
- }
- // With CJK, the CJK tag had to be closed first (see above)
- if (runparams.encoding->package() == Encoding::CJK) {
- os << from_ascii(subst(
- lang_begin_command,
- "$$lang",
- par_lang))
- // the '%' is necessary to prevent unwanted whitespace
- << "%\n";
- texrow.newline();
- }
- runparams.encoding = encoding;
+ // With CJK, the CJK tag had to be closed first (see above)
+ if (runparams.encoding->package() == Encoding::CJK) {
+ os << from_ascii(subst(
+ lang_begin_command,
+ "$$lang",
+ par_lang))
+ // the '%' is necessary to prevent unwanted whitespace
+ << "%\n";
+ texrow.newline();
}
- break;
+ runparams.encoding = encoding;
}
+ break;
}
}
}
}
- switch (style.latextype) {
- case LATEX_COMMAND:
- os << '\\' << from_ascii(style.latexname());
-
- // Separate handling of optional argument inset.
- if (style.optargs != 0 || style.reqargs != 0) {
- int ret = latexArgInsets(par, os, runparams, style.reqargs, style.optargs);
- while (ret > 0) {
- texrow.newline();
- --ret;
- }
- }
- else
- os << from_ascii(style.latexparam());
- break;
- case LATEX_ITEM_ENVIRONMENT:
- case LATEX_LIST_ENVIRONMENT:
- os << "\\item ";
- break;
- case LATEX_BIB_ENVIRONMENT:
- // ignore this, the inset will write itself
- break;
- default:
- break;
- }
+ parStartCommand(par, os, texrow,runparams, style);
Font const outerfont = text.outerFont(pit);
case LATEX_ENVIRONMENT: {
// if its the last paragraph of the current environment
// skip it otherwise fall through
- if (nextpar && (nextpar->layout() != par.layout()
- || nextpar->params().depth() != par.params().depth()))
+ if (nextpar
+ && (nextpar->layout() != par.layout()
+ || nextpar->params().depth() != par.params().depth()))
break;
}
if (par.allowParagraphCustomization()) {
if (!par.params().spacing().isDefault()
- && (runparams.isLastPar || !nextpar->hasSameLayout(par)))
- {
+ && (runparams.isLastPar || !nextpar->hasSameLayout(par))) {
if (pending_newline) {
os << '\n';
texrow.newline();
// Closing the language is needed for the last paragraph; it is also
// needed if we're within an \L or \R that we may have opened above (not
// necessarily in this paragraph) and are about to close.
- bool closing_rtl_ltr_environment =
- !runparams.use_polyglossia &&
+ bool closing_rtl_ltr_environment = !runparams.use_polyglossia
// not for ArabTeX
- (par_language->lang() != "arabic_arabtex" &&
- outer_language->lang() != "arabic_arabtex") &&
- // have we opened and \L or \R environment?
- runparams.local_font != 0 &&
- runparams.local_font->isRightToLeft() != par_language->rightToLeft() &&
+ && (par_language->lang() != "arabic_arabtex"
+ && outer_language->lang() != "arabic_arabtex")
+ // have we opened and \L or \R environment?
+ && runparams.local_font != 0
+ && runparams.local_font->isRightToLeft() != par_language->rightToLeft()
// are we about to close the language?
- ((nextpar && par_language->babel() != (nextpar->getParLanguage(bparams))->babel())
- || (runparams.isLastPar && par_language->babel() != outer_language->babel()));
+ &&((nextpar && par_language->babel() != (nextpar->getParLanguage(bparams))->babel())
+ || (runparams.isLastPar && par_language->babel() != outer_language->babel()));
if (closing_rtl_ltr_environment
|| (runparams.isLastPar && par_language->babel() != outer_language->babel())) {
// 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 && open_encoding_ == CJK &&
- (nextpar->getParLanguage(bparams)->encoding()->package() != Encoding::CJK ||
- (nextpar->layout().isEnvironment() && nextpar->isMultiLingual(bparams)))
- // inbetween environments, CJK has to be closed later (nesting!)
- && (!style.isEnvironment() || !nextpar->layout().isEnvironment())) {
+ if (nextpar
+ && open_encoding_ == CJK
+ && (nextpar->getParLanguage(bparams)->encoding()->package() != Encoding::CJK
+ || (nextpar->layout().isEnvironment() && nextpar->isMultiLingual(bparams)))
+ // inbetween environments, CJK has to be closed later (nesting!)
+ && (!style.isEnvironment() || !nextpar->layout().isEnvironment())) {
os << "\\end{CJK}\n";
open_encoding_ = none;
}
// LaTeX all paragraphs
void latexParagraphs(Buffer const & buf,
Text const & text,
- odocstream & os,
+ otexstream & os,
TexRow & texrow,
OutputParams const & runparams,
string const & everypar)
pit_type pit = runparams.par_begin;
// lastpit is for the language check after the loop.
- pit_type lastpit;
+ pit_type lastpit = pit;
// variables used in the loop:
bool was_title = false;
bool already_title = false;
if (was_title && !already_title) {
if (tclass.titletype() == TITLE_ENVIRONMENT) {
os << "\\end{" << from_ascii(tclass.titlename())
- << "}\n";
- }
- else {
+ << "}\n";
+ } else {
os << "\\" << from_ascii(tclass.titlename())
- << "\n";
- }
+ << "\n";
+ }
texrow.newline();
}