2 * \file output_latex.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
8 * Full author contact details are available in file CREDITS.
13 #include "output_latex.h"
16 #include "BufferParams.h"
18 #include "InsetList.h"
22 #include "OutputParams.h"
23 #include "Paragraph.h"
24 #include "paragraph_funcs.h"
25 #include "ParagraphParameters.h"
26 #include "TextClass.h"
30 #include "insets/InsetBibitem.h"
31 #include "insets/InsetOptArg.h"
33 #include "support/assert.h"
34 #include "support/debug.h"
35 #include "support/lstrings.h"
37 #include <boost/next_prior.hpp>
40 using namespace lyx::support;
53 static int open_encoding_ = none;
54 static bool cjk_inherited_ = false;
57 ParagraphList::const_iterator
58 TeXEnvironment(Buffer const & buf,
60 ParagraphList::const_iterator pit,
61 odocstream & os, TexRow & texrow,
62 OutputParams const & runparams);
64 ParagraphList::const_iterator
65 TeXOnePar(Buffer const & buf,
67 ParagraphList::const_iterator pit,
68 odocstream & os, TexRow & texrow,
69 OutputParams const & runparams,
70 string const & everypar = string());
73 ParagraphList::const_iterator
74 TeXDeeper(Buffer const & buf,
76 ParagraphList::const_iterator pit,
77 odocstream & os, TexRow & texrow,
78 OutputParams const & runparams)
80 LYXERR(Debug::LATEX, "TeXDeeper... " << &*pit);
81 ParagraphList::const_iterator par = pit;
83 ParagraphList const & paragraphs = text.paragraphs();
85 while (par != paragraphs.end() &&
86 par->params().depth() == pit->params().depth()) {
87 if (par->layout().isEnvironment()) {
88 par = TeXEnvironment(buf, text, par,
89 os, texrow, runparams);
91 par = TeXOnePar(buf, text, par,
92 os, texrow, runparams);
95 LYXERR(Debug::LATEX, "TeXDeeper...done ");
101 ParagraphList::const_iterator
102 TeXEnvironment(Buffer const & buf,
104 ParagraphList::const_iterator pit,
105 odocstream & os, TexRow & texrow,
106 OutputParams const & runparams)
108 LYXERR(Debug::LATEX, "TeXEnvironment... " << &*pit);
110 BufferParams const & bparams = buf.params();
112 Layout const & style = pit->forceEmptyLayout() ?
113 bparams.documentClass().emptyLayout() : pit->layout();
115 ParagraphList const & paragraphs = text.paragraphs();
117 Language const * const par_language = pit->getParLanguage(bparams);
118 Language const * const doc_language = bparams.language;
119 Language const * const prev_par_language =
120 (pit != paragraphs.begin())
121 ? boost::prior(pit)->getParLanguage(bparams)
123 if (par_language->babel() != prev_par_language->babel()) {
125 if (!lyxrc.language_command_end.empty() &&
126 prev_par_language->babel() != doc_language->babel() &&
127 !prev_par_language->babel().empty()) {
128 os << from_ascii(subst(
129 lyxrc.language_command_end,
131 prev_par_language->babel()))
132 // the '%' is necessary to prevent unwanted whitespace
137 if ((lyxrc.language_command_end.empty() ||
138 par_language->babel() != doc_language->babel()) &&
139 !par_language->babel().empty()) {
140 os << from_ascii(subst(
141 lyxrc.language_command_begin,
143 par_language->babel()))
144 // the '%' is necessary to prevent unwanted whitespace
150 bool leftindent_open = false;
151 if (!pit->params().leftIndent().zero()) {
152 os << "\\begin{LyXParagraphLeftIndent}{"
153 << from_ascii(pit->params().leftIndent().asLatexString())
156 leftindent_open = true;
159 if (style.isEnvironment()) {
160 os << "\\begin{" << from_ascii(style.latexname()) << '}';
161 if (style.optionalargs > 0) {
162 int ret = latexOptArgInsets(*pit, os, runparams,
169 if (style.latextype == LATEX_LIST_ENVIRONMENT) {
171 << pit->params().labelWidthString()
173 } else if (style.labeltype == LABEL_BIBLIO) {
175 os << '{' << bibitemWidest(buf) << "}\n";
177 os << from_ascii(style.latexparam()) << '\n';
181 // in multilingual environments, the CJK tags have to be nested properly
182 bool cjk_nested = false;
183 if (par_language->encoding()->package() == Encoding::CJK &&
184 open_encoding_ != CJK && pit->isMultiLingual(bparams)) {
185 os << "\\begin{CJK}{" << from_ascii(par_language->encoding()->latexName())
187 open_encoding_ = CJK;
192 ParagraphList::const_iterator par = pit;
194 par = TeXOnePar(buf, text, par, os, texrow, runparams);
196 if (par == paragraphs.end()) {
197 // Make sure that the last paragraph is
198 // correctly terminated (because TeXOnePar does
199 // not add a \n in this case)
202 } else if (par->params().depth() > pit->params().depth()) {
203 if (par->layout().isParagraph()) {
205 // How to handle this? (Lgb)
206 //&& !suffixIs(os, "\n\n")
208 // There should be at least one '\n' already
209 // but we need there to be two for Standard
210 // paragraphs that are depth-increment'ed to be
211 // output correctly. However, tables can
212 // also be paragraphs so don't adjust them.
215 // Will it ever harm to have one '\n' too
216 // many? i.e. that we sometimes will have
217 // three in a row. (Lgb)
221 par = TeXDeeper(buf, text, par, os, texrow,
224 } while (par != paragraphs.end()
225 && par->layout() == pit->layout()
226 && par->params().depth() == pit->params().depth()
227 && par->params().leftIndent() == pit->params().leftIndent());
229 if (open_encoding_ == CJK && cjk_nested) {
230 // We need to close the encoding even if it does not change
231 // to do correct environment nesting
232 os << "\\end{CJK}\n";
234 open_encoding_ = none;
237 if (style.isEnvironment()) {
238 os << "\\end{" << from_ascii(style.latexname()) << "}\n";
242 if (leftindent_open) {
243 os << "\\end{LyXParagraphLeftIndent}\n";
247 if (par != paragraphs.end())
248 LYXERR(Debug::LATEX, "TeXEnvironment...done " << &*par);
256 int latexOptArgInsets(Paragraph const & par, odocstream & os,
257 OutputParams const & runparams, int number)
261 InsetList::const_iterator it = par.insetList().begin();
262 InsetList::const_iterator end = par.insetList().end();
263 for (; it != end && number > 0 ; ++it) {
264 if (it->inset->lyxCode() == OPTARG_CODE) {
266 static_cast<InsetOptArg *>(it->inset);
267 lines += ins->latexOptional(os, runparams);
277 ParagraphList::const_iterator
278 TeXOnePar(Buffer const & buf,
280 ParagraphList::const_iterator const pit,
281 odocstream & os, TexRow & texrow,
282 OutputParams const & runparams_in,
283 string const & everypar)
285 LYXERR(Debug::LATEX, "TeXOnePar... " << &*pit << " '"
287 BufferParams const & bparams = buf.params();
288 ParagraphList const & paragraphs = text.paragraphs();
290 ParagraphList::const_iterator priorpit = pit;
291 if (priorpit != paragraphs.begin())
293 ParagraphList::const_iterator nextpit = pit;
294 if (nextpit != paragraphs.end())
297 if (runparams_in.verbatim) {
298 int const dist = distance(paragraphs.begin(), pit);
299 Font const outerfont = outerFont(dist, paragraphs);
301 // No newline if only one paragraph in this lyxtext
307 /*bool need_par = */ pit->latex(bparams, outerfont,
308 os, texrow, runparams_in);
312 Layout const style = pit->forceEmptyLayout() ?
313 bparams.documentClass().emptyLayout() : pit->layout();
315 OutputParams runparams = runparams_in;
316 runparams.moving_arg |= style.needprotect;
318 bool const maintext = text.isMainText(buf);
319 // we are at the beginning of an inset and CJK is already open.
320 if (pit == paragraphs.begin() && !maintext && open_encoding_ == CJK) {
321 cjk_inherited_ = true;
322 open_encoding_ = none;
325 // This paragraph's language
326 Language const * const par_language = pit->getParLanguage(bparams);
327 // The document's language
328 Language const * const doc_language = bparams.language;
329 // The language that was in effect when the environment this paragraph is
330 // inside of was opened
331 Language const * const outer_language =
332 (runparams.local_font != 0) ?
333 runparams.local_font->language() : doc_language;
334 // The previous language that was in effect is either the language of
335 // the previous paragraph, if there is one, or else the outer language
336 // if there is no previous paragraph
337 Language const * const prev_language =
338 (pit != paragraphs.begin()) ?
339 priorpit->getParLanguage(bparams) : outer_language;
341 if (par_language->babel() != prev_language->babel()
342 // check if we already put language command in TeXEnvironment()
343 && !(style.isEnvironment()
344 && (pit == paragraphs.begin() ||
345 (priorpit->layout() != pit->layout() &&
346 priorpit->getDepth() <= pit->getDepth())
347 || priorpit->getDepth() < pit->getDepth())))
349 if (!lyxrc.language_command_end.empty() &&
350 prev_language->babel() != outer_language->babel() &&
351 !prev_language->babel().empty())
353 os << from_ascii(subst(lyxrc.language_command_end,
355 prev_language->babel()))
356 // the '%' is necessary to prevent unwanted whitespace
361 // We need to open a new language if we couldn't close the previous
362 // one (because there's no language_command_end); and even if we closed
363 // the previous one, if the current language is different than the
364 // outer_language (which is currently in effect once the previous one
366 if ((lyxrc.language_command_end.empty() ||
367 par_language->babel() != outer_language->babel()) &&
368 !par_language->babel().empty()) {
369 // If we're inside an inset, and that inset is within an \L or \R
370 // (or equivalents), then within the inset, too, any opposite
371 // language paragraph should appear within an \L or \R (in addition
372 // to, outside of, the normal language switch commands).
373 // This behavior is not correct for ArabTeX, though.
374 if ( // not for ArabTeX
375 (par_language->lang() != "arabic_arabtex" &&
376 outer_language->lang() != "arabic_arabtex") &&
377 // are we in an inset?
378 runparams.local_font != 0 &&
379 // is the inset within an \L or \R?
381 // FIXME: currently, we don't check this; this means that
382 // we'll have unnnecessary \L and \R commands, but that
383 // doesn't seem to hurt (though latex will complain)
385 // is this paragraph in the opposite direction?
386 runparams.local_font->isRightToLeft() !=
387 par_language->rightToLeft()
389 // FIXME: I don't have a working copy of the Arabi package, so
390 // I'm not sure if the farsi and arabic_arabi stuff is correct
392 if (par_language->lang() == "farsi")
394 else if (outer_language->lang() == "farsi")
396 else if (par_language->lang() == "arabic_arabi")
398 else if (outer_language->lang() == "arabic_arabi")
400 // remaining RTL languages currently is hebrew
401 else if (par_language->rightToLeft())
406 // With CJK, the CJK tag has to be closed first (see below)
407 if (runparams.encoding->package() != Encoding::CJK) {
408 os << from_ascii(subst(
409 lyxrc.language_command_begin,
411 par_language->babel()))
412 // the '%' is necessary to prevent unwanted whitespace
419 // Switch file encoding if necessary; no need to do this for "default"
420 // encoding, since this only affects the position of the outputted
421 // \inputencoding command; the encoding switch will occur when necessary
422 if (bparams.inputenc == "auto" &&
423 runparams.encoding->package() != Encoding::none) {
424 // Look ahead for future encoding changes.
425 // We try to output them at the beginning of the paragraph,
426 // since the \inputencoding command is not allowed e.g. in
428 for (pos_type i = 0; i < pit->size(); ++i) {
429 char_type const c = pit->getChar(i);
430 Encoding const * const encoding =
431 pit->getFontSettings(bparams, i).language()->encoding();
432 if (encoding->package() != Encoding::CJK &&
433 runparams.encoding->package() == Encoding::inputenc &&
438 // All characters before c are in the ASCII range, and
439 // c is non-ASCII (but no inset), so change the
440 // encoding to that required by the language of c.
441 // With CJK, only add switch if we have CJK content at the beginning
443 if (encoding->package() != Encoding::CJK || i == 0) {
444 OutputParams tmp_rp = runparams;
445 runparams.moving_arg = false;
446 pair<bool, int> enc_switch = switchEncoding(os, bparams, runparams,
449 // the following is necessary after a CJK environment in a multilingual
450 // context (nesting issue).
451 if (par_language->encoding()->package() == Encoding::CJK &&
452 open_encoding_ != CJK && !cjk_inherited_) {
453 os << "\\begin{CJK}{" << from_ascii(par_language->encoding()->latexName())
455 open_encoding_ = CJK;
458 if (encoding->package() != Encoding::none && enc_switch.first) {
459 if (enc_switch.second > 0) {
460 // the '%' is necessary to prevent unwanted whitespace
464 // With CJK, the CJK tag had to be closed first (see above)
465 if (runparams.encoding->package() == Encoding::CJK) {
466 os << from_ascii(subst(
467 lyxrc.language_command_begin,
469 par_language->babel()))
470 // the '%' is necessary to prevent unwanted whitespace
474 runparams.encoding = encoding;
481 bool const useSetSpace = bparams.documentClass().provides("SetSpace");
482 if (pit->allowParagraphCustomization()) {
483 if (pit->params().startOfAppendix()) {
484 os << "\\appendix\n";
488 if (!pit->params().spacing().isDefault()
489 && (pit == paragraphs.begin()
490 || !priorpit->hasSameLayout(*pit)))
492 os << from_ascii(pit->params().spacing().writeEnvirBegin(useSetSpace))
497 if (style.isCommand()) {
503 switch (style.latextype) {
505 os << '\\' << from_ascii(style.latexname());
507 // Separate handling of optional argument inset.
508 if (style.optionalargs > 0) {
509 int ret = latexOptArgInsets(*pit, os, runparams,
517 os << from_ascii(style.latexparam());
519 case LATEX_ITEM_ENVIRONMENT:
520 case LATEX_LIST_ENVIRONMENT:
523 case LATEX_BIB_ENVIRONMENT:
524 // ignore this, the inset will write itself
530 Font const outerfont = outerFont(distance(paragraphs.begin(), pit),
534 os << from_utf8(everypar);
535 bool need_par = pit->latex(bparams, outerfont,
536 os, texrow, runparams);
538 // Make sure that \\par is done with the font of the last
539 // character if this has another size as the default.
540 // This is necessary because LaTeX (and LyX on the screen)
541 // calculates the space between the baselines according
542 // to this font. (Matthias)
544 // Is this really needed ? (Dekel)
545 // We do not need to use to change the font for the last paragraph
548 Font const font = pit->empty()
549 ? pit->getLayoutFont(bparams, outerfont)
550 : pit->getFont(bparams, pit->size() - 1, outerfont);
552 bool is_command = style.isCommand();
554 if (style.resfont.size() != font.fontInfo().size()
555 && nextpit != paragraphs.end()
559 os << "\\" << from_ascii(font.latexSize()) << " \\par}";
560 } else if (need_par) {
562 } else if (is_command)
565 bool pending_newline = false;
566 switch (style.latextype) {
567 case LATEX_ITEM_ENVIRONMENT:
568 case LATEX_LIST_ENVIRONMENT:
569 if (nextpit != paragraphs.end()
570 && (pit->params().depth() < nextpit->params().depth()))
571 pending_newline = true;
573 case LATEX_ENVIRONMENT: {
574 // if its the last paragraph of the current environment
575 // skip it otherwise fall through
576 ParagraphList::const_iterator next = nextpit;
578 if (next != paragraphs.end() && (next->layout() != pit->layout()
579 || next->params().depth() != pit->params().depth()))
583 // fall through possible
585 // we don't need it for the last paragraph!!!
586 if (nextpit != paragraphs.end())
587 pending_newline = true;
590 if (pit->allowParagraphCustomization()) {
591 if (!pit->params().spacing().isDefault()
592 && (nextpit == paragraphs.end() || !nextpit->hasSameLayout(*pit)))
594 if (pending_newline) {
598 os << from_ascii(pit->params().spacing().writeEnvirEnd(useSetSpace));
599 pending_newline = true;
603 // Closing the language is needed for the last paragraph; it is also
604 // needed if we're within an \L or \R that we may have opened above (not
605 // necessarily in this paragraph) and are about to close.
606 bool closing_rtl_ltr_environment =
608 (par_language->lang() != "arabic_arabtex" &&
609 outer_language->lang() != "arabic_arabtex") &&
610 // have we opened and \L or \R environment?
611 runparams.local_font != 0 &&
612 runparams.local_font->isRightToLeft() != par_language->rightToLeft() &&
613 // are we about to close the language?
614 ((nextpit != paragraphs.end() &&
615 par_language->babel() !=
616 (nextpit->getParLanguage(bparams))->babel()) ||
617 (nextpit == paragraphs.end() &&
618 par_language->babel() != outer_language->babel()));
620 if (closing_rtl_ltr_environment || (nextpit == paragraphs.end()
621 && par_language->babel() != outer_language->babel())) {
622 // Since \selectlanguage write the language to the aux file,
623 // we need to reset the language at the end of footnote or
626 if (pending_newline) {
630 // when the paragraph uses CJK, the language has to be closed earlier
631 if (font.language()->encoding()->package() != Encoding::CJK) {
632 if (lyxrc.language_command_end.empty()) {
633 if (!prev_language->babel().empty()) {
634 os << from_ascii(subst(
635 lyxrc.language_command_begin,
637 prev_language->babel()));
638 pending_newline = true;
640 } else if (!par_language->babel().empty()) {
641 os << from_ascii(subst(
642 lyxrc.language_command_end,
644 par_language->babel()));
645 pending_newline = true;
649 if (closing_rtl_ltr_environment)
652 if (pending_newline) {
657 // if this is a CJK-paragraph and the next isn't, close CJK
658 // also if the next paragraph is a multilingual environment (because of nesting)
659 if (nextpit != paragraphs.end() && open_encoding_ == CJK &&
660 (nextpit->getParLanguage(bparams)->encoding()->package() != Encoding::CJK ||
661 nextpit->layout().isEnvironment() && nextpit->isMultiLingual(bparams))
662 // in environments, CJK has to be closed later (nesting!)
663 && !style.isEnvironment()) {
664 os << "\\end{CJK}\n";
665 open_encoding_ = none;
668 // If this is the last paragraph, close the CJK environment
669 // if necessary. If it's an environment, we'll have to \end that first.
670 if (nextpit == paragraphs.end() && !style.isEnvironment()) {
671 switch (open_encoding_) {
677 os << "\\end{CJK}\n";
682 open_encoding_ = none;
687 open_encoding_ = none;
697 // If this is the last paragraph, and a local_font was set upon entering
698 // the inset, and we're using "auto" or "default" encoding, the encoding
699 // should be set back to that local_font's encoding.
700 if (nextpit == paragraphs.end() && runparams_in.local_font != 0
701 && (bparams.inputenc == "auto" || bparams.inputenc == "default")) {
702 runparams_in.encoding = runparams_in.local_font->language()->encoding();
703 os << setEncoding(runparams_in.encoding->iconvName());
706 // Otherwise, the current encoding should be set for the next paragraph.
708 runparams_in.encoding = runparams.encoding;
711 // we don't need it for the last paragraph!!!
712 // Note from JMarc: we will re-add a \n explicitely in
713 // TeXEnvironment, because it is needed in this case
714 if (nextpit != paragraphs.end()) {
719 if (nextpit != paragraphs.end())
720 LYXERR(Debug::LATEX, "TeXOnePar...done " << &*nextpit);
728 // LaTeX all paragraphs
729 void latexParagraphs(Buffer const & buf,
733 OutputParams const & runparams,
734 string const & everypar)
736 bool was_title = false;
737 bool already_title = false;
738 BufferParams const & bparams = buf.params();
739 DocumentClass const & tclass = bparams.documentClass();
740 ParagraphList const & paragraphs = text.paragraphs();
741 ParagraphList::const_iterator par = paragraphs.begin();
742 ParagraphList::const_iterator endpar = paragraphs.end();
744 LASSERT(runparams.par_begin <= runparams.par_end, /**/);
745 // if only part of the paragraphs will be outputed
746 if (runparams.par_begin != runparams.par_end) {
747 par = boost::next(paragraphs.begin(), runparams.par_begin);
748 endpar = boost::next(paragraphs.begin(), runparams.par_end);
749 // runparams will be passed to nested paragraphs, so
750 // we have to reset the range parameters.
751 const_cast<OutputParams&>(runparams).par_begin = 0;
752 const_cast<OutputParams&>(runparams).par_end = 0;
755 bool const maintext = text.isMainText(buf);
757 // Open a CJK environment at the beginning of the main buffer
758 // if the document's language is a CJK language
759 if (maintext && bparams.encoding().package() == Encoding::CJK) {
760 os << "\\begin{CJK}{" << from_ascii(bparams.encoding().latexName())
763 open_encoding_ = CJK;
765 // if "auto begin" is switched off, explicitely switch the
766 // language on at start
767 if (maintext && !lyxrc.language_auto_begin &&
768 !bparams.language->babel().empty()) {
770 os << from_utf8(subst(lyxrc.language_command_begin,
772 bparams.language->babel()))
777 ParagraphList::const_iterator lastpar;
779 while (par != endpar) {
781 Layout const & layout = par->forceEmptyLayout() ?
782 tclass.emptyLayout() :
785 if (layout.intitle) {
787 lyxerr << "Error in latexParagraphs: You"
788 " should not mix title layouts"
789 " with normal ones." << endl;
790 } else if (!was_title) {
792 if (tclass.titletype() == TITLE_ENVIRONMENT) {
794 << from_ascii(tclass.titlename())
799 } else if (was_title && !already_title) {
800 if (tclass.titletype() == TITLE_ENVIRONMENT) {
801 os << "\\end{" << from_ascii(tclass.titlename())
805 os << "\\" << from_ascii(tclass.titlename())
809 already_title = true;
813 if (layout.is_environment) {
814 par = TeXOnePar(buf, text, par, os, texrow,
815 runparams, everypar);
816 } else if (layout.isEnvironment() ||
817 !par->params().leftIndent().zero()) {
818 par = TeXEnvironment(buf, text, par, os,
821 par = TeXOnePar(buf, text, par, os, texrow,
822 runparams, everypar);
825 if (distance(lastpar, par) >= distance(lastpar, endpar))
828 // It might be that we only have a title in this document
829 if (was_title && !already_title) {
830 if (tclass.titletype() == TITLE_ENVIRONMENT) {
831 os << "\\end{" << from_ascii(tclass.titlename())
835 os << "\\" << from_ascii(tclass.titlename())
840 // if "auto end" is switched off, explicitely close the language at the end
841 // but only if the last par is in a babel language
842 if (maintext && !lyxrc.language_auto_end && !bparams.language->babel().empty() &&
843 lastpar->getParLanguage(bparams)->encoding()->package() != Encoding::CJK) {
844 os << from_utf8(subst(lyxrc.language_command_end,
846 bparams.language->babel()))
850 // If the last paragraph is an environment, we'll have to close
851 // CJK at the very end to do proper nesting.
852 if (maintext && open_encoding_ == CJK) {
853 os << "\\end{CJK}\n";
855 open_encoding_ = none;
857 // reset inherited encoding
858 if (cjk_inherited_) {
859 open_encoding_ = CJK;
860 cjk_inherited_ = false;
865 pair<bool, int> switchEncoding(odocstream & os, BufferParams const & bparams,
866 OutputParams const & runparams, Encoding const & newEnc)
868 Encoding const oldEnc = *runparams.encoding;
869 bool moving_arg = runparams.moving_arg;
870 if ((bparams.inputenc != "auto" && bparams.inputenc != "default")
872 return make_pair(false, 0);
874 // Do nothing if the encoding is unchanged.
875 if (oldEnc.name() == newEnc.name())
876 return make_pair(false, 0);
878 // FIXME We ignore encoding switches from/to encodings that do
879 // neither support the inputenc package nor the CJK package here.
880 // This does of course only work in special cases (e.g. switch from
881 // tis620-0 to latin1, but the text in latin1 contains ASCII only),
882 // but it is the best we can do
883 if (oldEnc.package() == Encoding::none
884 || newEnc.package() == Encoding::none)
885 return make_pair(false, 0);
887 LYXERR(Debug::LATEX, "Changing LaTeX encoding from "
888 << oldEnc.name() << " to " << newEnc.name());
889 os << setEncoding(newEnc.iconvName());
890 if (bparams.inputenc == "default")
891 return make_pair(true, 0);
893 docstring const inputenc_arg(from_ascii(newEnc.latexName()));
894 switch (newEnc.package()) {
896 // shouldn't ever reach here, see above
897 return make_pair(true, 0);
898 case Encoding::inputenc: {
899 int count = inputenc_arg.length();
900 if (oldEnc.package() == Encoding::CJK &&
901 open_encoding_ == CJK) {
903 open_encoding_ = none;
906 else if (oldEnc.package() == Encoding::inputenc &&
907 open_encoding_ == inputenc) {
909 open_encoding_ = none;
912 if (runparams.local_font != 0 && oldEnc.package() == Encoding::CJK) {
913 // within insets, \inputenc switches need to be
914 // embraced within \bgroup ... \egroup; else CJK fails.
917 open_encoding_ = inputenc;
919 os << "\\inputencoding{" << inputenc_arg << '}';
920 return make_pair(true, count + 16);
922 case Encoding::CJK: {
923 int count = inputenc_arg.length();
924 if (oldEnc.package() == Encoding::CJK &&
925 open_encoding_ == CJK) {
929 if (oldEnc.package() == Encoding::inputenc &&
930 open_encoding_ == inputenc) {
934 os << "\\begin{CJK}{" << inputenc_arg << "}{}";
935 open_encoding_ = CJK;
936 return make_pair(true, count + 15);
939 // Dead code to avoid a warning:
940 return make_pair(true, 0);