2 * \file paragraph_funcs.C
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 "paragraph_funcs.h"
16 #include "bufferparams.h"
20 #include "errorlist.h"
23 #include "iterators.h"
27 #include "paragraph_pimpl.h"
31 #include "insets/insetbibitem.h"
32 #include "insets/insethfill.h"
33 #include "insets/insetlatexaccent.h"
34 #include "insets/insetnewline.h"
35 #include "insets/insetoptarg.h"
36 #include "insets/insetspace.h"
37 #include "insets/insetspecialchar.h"
38 #include "insets/insettabular.h"
40 #include "support/LAssert.h"
41 #include "support/lstrings.h"
43 #include "support/std_sstream.h"
45 using namespace lyx::support;
48 //using lyx::layout_type;
50 using std::istringstream;
53 extern string bibitemWidest(Buffer const &);
58 bool moveItem(Paragraph & from, Paragraph & to,
59 BufferParams const & params, pos_type i, pos_type j)
61 char const tmpchar = from.getChar(i);
62 LyXFont tmpfont = from.getFontSettings(params, i);
64 if (tmpchar == Paragraph::META_INSET) {
65 InsetOld * tmpinset = 0;
66 if (from.getInset(i)) {
67 // the inset is not in a paragraph anymore
68 tmpinset = from.insetlist.release(i);
71 if (!to.insetAllowed(tmpinset->lyxCode()))
73 to.insertInset(j, tmpinset, tmpfont);
75 if (!to.checkInsertChar(tmpfont))
77 to.insertChar(j, tmpchar, tmpfont);
85 void breakParagraph(BufferParams const & bparams,
86 ParagraphList & paragraphs,
87 ParagraphList::iterator par,
91 // create a new paragraph, and insert into the list
92 ParagraphList::iterator tmp = paragraphs.insert(boost::next(par),
95 // without doing that we get a crash when typing <Return> at the
97 tmp->layout(bparams.getLyXTextClass().defaultLayout());
98 // remember to set the inset_owner
99 tmp->setInsetOwner(par->inInset());
101 if (bparams.tracking_changes)
104 // this is an idea for a more userfriendly layout handling, I will
105 // see what the users say
107 // layout stays the same with latex-environments
109 tmp->layout(par->layout());
110 tmp->setLabelWidthString(par->params().labelWidthString());
113 bool const isempty = (par->allowEmpty() && par->empty());
115 if (!isempty && (par->size() > pos || par->empty() || flag == 2)) {
116 tmp->layout(par->layout());
117 tmp->params().align(par->params().align());
118 tmp->setLabelWidthString(par->params().labelWidthString());
120 tmp->params().lineBottom(par->params().lineBottom());
121 par->params().lineBottom(false);
122 tmp->params().pagebreakBottom(par->params().pagebreakBottom());
123 par->params().pagebreakBottom(false);
124 tmp->params().spaceBottom(par->params().spaceBottom());
125 par->params().spaceBottom(VSpace(VSpace::NONE));
127 tmp->params().depth(par->params().depth());
128 tmp->params().noindent(par->params().noindent());
130 // copy everything behind the break-position
131 // to the new paragraph
134 #warning this seems wrong
136 /* FIXME: if !keepempty, empty() == true, then we reach
137 * here with size() == 0. So pos_end becomes - 1. Why
138 * doesn't this cause problems ???
140 pos_type pos_end = par->size() - 1;
144 for (; i <= pos_end; ++i) {
145 Change::Type change = par->lookupChange(i);
146 if (moveItem(*par, *tmp, bparams, i, j - pos)) {
147 tmp->setChange(j - pos, change);
152 for (i = pos_end; i >= pos; --i)
159 tmp->params().lineTop(par->params().lineTop());
160 tmp->params().pagebreakTop(par->params().pagebreakTop());
161 tmp->params().spaceTop(par->params().spaceTop());
162 par->params().clear();
164 par->layout(bparams.getLyXTextClass().defaultLayout());
166 // layout stays the same with latex-environments
168 par->layout(tmp->layout());
169 par->setLabelWidthString(tmp->params().labelWidthString());
170 par->params().depth(tmp->params().depth());
173 // subtle, but needed to get empty pars working right
174 if (bparams.tracking_changes) {
177 } else if (!tmp->size()) {
184 void breakParagraphConservative(BufferParams const & bparams,
185 ParagraphList & paragraphs,
186 ParagraphList::iterator par,
189 // create a new paragraph
190 ParagraphList::iterator tmp = paragraphs.insert(boost::next(par),
192 tmp->makeSameLayout(*par);
194 // When can pos > size()?
195 // I guess pos == size() is possible.
196 if (par->size() > pos) {
197 // copy everything behind the break-position to the new
199 pos_type pos_end = par->size() - 1;
201 for (pos_type i = pos, j = pos; i <= pos_end; ++i)
202 if (moveItem(*par, *tmp, bparams, i, j - pos))
205 for (pos_type k = pos_end; k >= pos; --k)
211 void mergeParagraph(BufferParams const & bparams,
212 ParagraphList & paragraphs,
213 ParagraphList::iterator par)
215 ParagraphList::iterator the_next = boost::next(par);
217 // first the DTP-stuff
218 par->params().lineBottom(the_next->params().lineBottom());
219 par->params().spaceBottom(the_next->params().spaceBottom());
220 par->params().pagebreakBottom(the_next->params().pagebreakBottom());
222 pos_type pos_end = the_next->size() - 1;
223 pos_type pos_insert = par->size();
225 // ok, now copy the paragraph
226 for (pos_type i = 0, j = 0; i <= pos_end; ++i)
227 if (moveItem(*the_next, *par, bparams, i, pos_insert + j))
230 paragraphs.erase(the_next);
234 ParagraphList::iterator depthHook(ParagraphList::iterator pit,
235 ParagraphList const & plist,
236 Paragraph::depth_type depth)
238 ParagraphList::iterator newpit = pit;
239 ParagraphList::iterator beg = const_cast<ParagraphList&>(plist).begin();
244 while (newpit != beg && newpit->getDepth() > depth) {
248 if (newpit->getDepth() > depth)
255 ParagraphList::iterator outerHook(ParagraphList::iterator pit,
256 ParagraphList const & plist)
258 if (!pit->getDepth())
259 return const_cast<ParagraphList&>(plist).end();
260 return depthHook(pit, plist,
261 Paragraph::depth_type(pit->getDepth() - 1));
265 bool isFirstInSequence(ParagraphList::iterator pit,
266 ParagraphList const & plist)
268 ParagraphList::iterator dhook = depthHook(pit, plist, pit->getDepth());
270 || dhook->layout() != pit->layout()
271 || dhook->getDepth() != pit->getDepth());
275 int getEndLabel(ParagraphList::iterator p, ParagraphList const & plist)
277 ParagraphList::iterator pit = p;
278 Paragraph::depth_type par_depth = p->getDepth();
279 while (pit != const_cast<ParagraphList&>(plist).end()) {
280 LyXLayout_ptr const & layout = pit->layout();
281 int const endlabeltype = layout->endlabeltype;
283 if (endlabeltype != END_LABEL_NO_LABEL) {
284 if (boost::next(p) == const_cast<ParagraphList&>(plist).end())
287 Paragraph::depth_type const next_depth = boost::next(p)->getDepth();
288 if (par_depth > next_depth ||
289 (par_depth == next_depth &&
290 layout != boost::next(p)->layout()))
296 pit = outerHook(pit, plist);
297 if (pit != const_cast<ParagraphList&>(plist).end())
298 par_depth = pit->getDepth();
300 return END_LABEL_NO_LABEL;
306 ParagraphList::iterator
307 TeXEnvironment(Buffer const & buf,
308 ParagraphList const & paragraphs,
309 ParagraphList::iterator pit,
310 ostream & os, TexRow & texrow,
311 LatexRunParams const & runparams);
313 ParagraphList::iterator
314 TeXOnePar(Buffer const & buf,
315 ParagraphList const & paragraphs,
316 ParagraphList::iterator pit,
317 ostream & os, TexRow & texrow,
318 LatexRunParams const & runparams,
319 string const & everypar = string());
322 ParagraphList::iterator
323 TeXDeeper(Buffer const & buf,
324 ParagraphList const & paragraphs,
325 ParagraphList::iterator pit,
326 ostream & os, TexRow & texrow,
327 LatexRunParams const & runparams)
329 lyxerr[Debug::LATEX] << "TeXDeeper... " << &*pit << endl;
330 ParagraphList::iterator par = pit;
332 while (par != const_cast<ParagraphList&>(paragraphs).end() &&
333 par->params().depth() == pit->params().depth()) {
334 if (par->layout()->isEnvironment()) {
335 par = TeXEnvironment(buf, paragraphs, par,
336 os, texrow, runparams);
338 par = TeXOnePar(buf, paragraphs, par,
339 os, texrow, runparams);
342 lyxerr[Debug::LATEX] << "TeXDeeper...done " << &*par << endl;
348 ParagraphList::iterator
349 TeXEnvironment(Buffer const & buf,
350 ParagraphList const & paragraphs,
351 ParagraphList::iterator pit,
352 ostream & os, TexRow & texrow,
353 LatexRunParams const & runparams)
355 lyxerr[Debug::LATEX] << "TeXEnvironment... " << &*pit << endl;
357 BufferParams const & bparams = buf.params();
359 LyXLayout_ptr const & style = pit->layout();
361 Language const * language = pit->getParLanguage(bparams);
362 Language const * doc_language = bparams.language;
363 Language const * previous_language =
364 (pit != const_cast<ParagraphList&>(paragraphs).begin())
365 ? boost::prior(pit)->getParLanguage(bparams)
367 if (language->babel() != previous_language->babel()) {
369 if (!lyxrc.language_command_end.empty() &&
370 previous_language->babel() != doc_language->babel()) {
371 os << subst(lyxrc.language_command_end, "$$lang",
372 previous_language->babel())
377 if (lyxrc.language_command_end.empty() ||
378 language->babel() != doc_language->babel()) {
379 os << subst(lyxrc.language_command_begin, "$$lang",
386 bool leftindent_open = false;
387 if (!pit->params().leftIndent().zero()) {
388 os << "\\begin{LyXParagraphLeftIndent}{" <<
389 pit->params().leftIndent().asLatexString() << "}\n";
391 leftindent_open = true;
394 if (style->isEnvironment()) {
395 if (style->latextype == LATEX_LIST_ENVIRONMENT) {
396 os << "\\begin{" << style->latexname() << "}{"
397 << pit->params().labelWidthString() << "}\n";
398 } else if (style->labeltype == LABEL_BIBLIO) {
400 os << "\\begin{" << style->latexname() << "}{"
401 << bibitemWidest(buf)
403 } else if (style->latextype == LATEX_ITEM_ENVIRONMENT) {
404 os << "\\begin{" << style->latexname() << '}'
405 << style->latexparam() << '\n';
407 os << "\\begin{" << style->latexname() << '}'
408 << style->latexparam() << '\n';
411 ParagraphList::iterator par = pit;
413 par = TeXOnePar(buf, paragraphs, par, os, texrow, runparams);
415 if (par != const_cast<ParagraphList&>(paragraphs).end() && par->params().depth() > pit->params().depth()) {
416 if (par->layout()->isParagraph()) {
419 // How to handle this? (Lgb)
420 //&& !suffixIs(os, "\n\n")
422 // There should be at least one '\n' already
423 // but we need there to be two for Standard
424 // paragraphs that are depth-increment'ed to be
425 // output correctly. However, tables can
426 // also be paragraphs so don't adjust them.
429 // Will it ever harm to have one '\n' too
430 // many? i.e. that we sometimes will have
431 // three in a row. (Lgb)
435 par = TeXDeeper(buf, paragraphs, par, os, texrow,
438 } while (par != const_cast<ParagraphList&>(paragraphs).end()
439 && par->layout() == pit->layout()
440 && par->params().depth() == pit->params().depth()
441 && par->params().leftIndent() == pit->params().leftIndent());
443 if (style->isEnvironment()) {
444 os << "\\end{" << style->latexname() << "}\n";
448 if (leftindent_open) {
449 os << "\\end{LyXParagraphLeftIndent}\n";
453 lyxerr[Debug::LATEX] << "TeXEnvironment...done " << &*par << endl;
454 return par; // ale970302
458 InsetOptArg * optArgInset(Paragraph const & par)
461 InsetList::const_iterator it = par.insetlist.begin();
462 InsetList::const_iterator end = par.insetlist.end();
463 for (; it != end; ++it) {
464 InsetOld * ins = it->inset;
465 if (ins->lyxCode() == InsetOld::OPTARG_CODE) {
466 return static_cast<InsetOptArg *>(ins);
473 ParagraphList::iterator
474 TeXOnePar(Buffer const & buf,
475 ParagraphList const & paragraphs,
476 ParagraphList::iterator pit,
477 ostream & os, TexRow & texrow,
478 LatexRunParams const & runparams,
479 string const & everypar)
481 lyxerr[Debug::LATEX] << "TeXOnePar... " << &*pit << " '"
482 << everypar << "'" << endl;
483 BufferParams const & bparams = buf.params();
485 InsetOld const * in = pit->inInset();
486 bool further_blank_line = false;
489 // well we have to check if we are in an inset with unlimited
490 // length (all in one row) if that is true then we don't allow
491 // any special options in the paragraph and also we don't allow
492 // any environment other then "Standard" to be valid!
493 if (in == 0 || !in->forceDefaultParagraphs(in)) {
494 style = pit->layout();
496 if (pit->params().startOfAppendix()) {
497 os << "\\appendix\n";
501 if (!pit->params().spacing().isDefault()
502 && (pit == const_cast<ParagraphList&>(paragraphs).begin() || !boost::prior(pit)->hasSameLayout(*pit))) {
503 os << pit->params().spacing().writeEnvirBegin() << '\n';
507 if (style->isCommand()) {
512 if (pit->params().pagebreakTop()) {
514 further_blank_line = true;
516 if (pit->params().spaceTop().kind() != VSpace::NONE) {
517 os << pit->params().spaceTop().asLatexCommand(bparams);
518 further_blank_line = true;
521 if (pit->params().lineTop()) {
523 << pit->getFont(bparams, 0, outerFont(pit, paragraphs)).latexSize()
525 << "\\vspace{-1\\parskip}";
526 further_blank_line = true;
529 if (further_blank_line) {
534 style = bparams.getLyXTextClass().defaultLayout();
537 Language const * language = pit->getParLanguage(bparams);
538 Language const * doc_language = bparams.language;
539 Language const * previous_language =
540 (pit != const_cast<ParagraphList&>(paragraphs).begin())
541 ? boost::prior(pit)->getParLanguage(bparams)
544 if (language->babel() != previous_language->babel()
545 // check if we already put language command in TeXEnvironment()
546 && !(style->isEnvironment()
547 && (pit == const_cast<ParagraphList&>(paragraphs).begin() ||
548 (boost::prior(pit)->layout() != pit->layout() &&
549 boost::prior(pit)->getDepth() <= pit->getDepth())
550 || boost::prior(pit)->getDepth() < pit->getDepth())))
552 if (!lyxrc.language_command_end.empty() &&
553 previous_language->babel() != doc_language->babel())
555 os << subst(lyxrc.language_command_end, "$$lang",
556 previous_language->babel())
561 if (lyxrc.language_command_end.empty() ||
562 language->babel() != doc_language->babel())
564 os << subst(lyxrc.language_command_begin, "$$lang",
571 if (bparams.inputenc == "auto" &&
572 language->encoding() != previous_language->encoding()) {
573 os << "\\inputencoding{"
574 << language->encoding()->LatexName()
579 switch (style->latextype) {
581 os << '\\' << style->latexname();
583 // Separate handling of optional argument inset.
584 if (style->optionalargs == 1) {
585 InsetOptArg * it = optArgInset(*pit);
587 it->latexOptional(buf, os, runparams);
590 os << style->latexparam();
592 case LATEX_ITEM_ENVIRONMENT:
593 case LATEX_LIST_ENVIRONMENT:
596 case LATEX_BIB_ENVIRONMENT:
597 // ignore this, the inset will write itself
604 bool need_par = pit->simpleTeXOnePar(buf, bparams,
605 outerFont(pit, paragraphs),
606 os, texrow, runparams);
608 // Make sure that \\par is done with the font of the last
609 // character if this has another size as the default.
610 // This is necessary because LaTeX (and LyX on the screen)
611 // calculates the space between the baselines according
612 // to this font. (Matthias)
614 // Is this really needed ? (Dekel)
615 // We do not need to use to change the font for the last paragraph
617 LyXFont const outerfont(outerFont(pit, paragraphs));
621 ? pit->getLayoutFont(bparams, outerfont)
622 : pit->getFont(bparams, pit->size() - 1, outerfont));
624 bool is_command = style->isCommand();
626 if (style->resfont.size() != font.size()
627 && boost::next(pit) != const_cast<ParagraphList&>(paragraphs).end()
631 os << "\\" << font.latexSize() << " \\par}";
632 } else if (need_par) {
634 } else if (is_command)
637 switch (style->latextype) {
638 case LATEX_ITEM_ENVIRONMENT:
639 case LATEX_LIST_ENVIRONMENT:
640 if (boost::next(pit) != const_cast<ParagraphList&>(paragraphs).end()
641 && (pit->params().depth() < boost::next(pit)->params().depth())) {
646 case LATEX_ENVIRONMENT: {
647 // if its the last paragraph of the current environment
648 // skip it otherwise fall through
649 ParagraphList::iterator next = boost::next(pit);
651 if (next != const_cast<ParagraphList&>(paragraphs).end()
652 && (next->layout() != pit->layout()
653 || next->params().depth() != pit->params().depth()))
657 // fall through possible
659 // we don't need it for the last paragraph!!!
660 if (boost::next(pit) != const_cast<ParagraphList&>(paragraphs).end()) {
666 if (in == 0 || !in->forceDefaultParagraphs(in)) {
667 further_blank_line = false;
668 if (pit->params().lineBottom()) {
669 os << "\\lyxline{\\" << font.latexSize() << '}';
670 further_blank_line = true;
673 if (pit->params().spaceBottom().kind() != VSpace::NONE) {
674 os << pit->params().spaceBottom().asLatexCommand(bparams);
675 further_blank_line = true;
678 if (pit->params().pagebreakBottom()) {
680 further_blank_line = true;
683 if (further_blank_line) {
688 if (!pit->params().spacing().isDefault()
689 && (boost::next(pit) == const_cast<ParagraphList&>(paragraphs).end()|| !boost::next(pit)->hasSameLayout(*pit))) {
690 os << pit->params().spacing().writeEnvirEnd() << '\n';
695 // we don't need it for the last paragraph!!!
696 if (boost::next(pit) != const_cast<ParagraphList&>(paragraphs).end()) {
700 // Since \selectlanguage write the language to the aux file,
701 // we need to reset the language at the end of footnote or
704 if (language->babel() != doc_language->babel()) {
705 if (lyxrc.language_command_end.empty())
706 os << subst(lyxrc.language_command_begin,
708 doc_language->babel())
711 os << subst(lyxrc.language_command_end,
719 lyxerr[Debug::LATEX] << "TeXOnePar...done " << &*boost::next(pit) << endl;
727 // LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
729 void latexParagraphs(Buffer const & buf,
730 ParagraphList const & paragraphs,
733 LatexRunParams const & runparams,
734 string const & everypar)
736 bool was_title = false;
737 bool already_title = false;
738 LyXTextClass const & tclass = buf.params().getLyXTextClass();
739 ParagraphList::iterator par = const_cast<ParagraphList&>(paragraphs).begin();
740 ParagraphList::iterator endpar = const_cast<ParagraphList&>(paragraphs).end();
743 while (par != endpar) {
744 InsetOld * in = par->inInset();
745 // well we have to check if we are in an inset with unlimited
746 // length (all in one row) if that is true then we don't allow
747 // any special options in the paragraph and also we don't allow
748 // any environment other then "Standard" to be valid!
749 if (in == 0 || !in->forceDefaultParagraphs(in)) {
750 LyXLayout_ptr const & layout = par->layout();
752 if (layout->intitle) {
754 lyxerr <<"Error in latexParagraphs: You"
755 " should not mix title layouts"
756 " with normal ones." << endl;
757 } else if (!was_title) {
759 if (tclass.titletype() == TITLE_ENVIRONMENT) {
761 << tclass.titlename()
766 } else if (was_title && !already_title) {
767 if (tclass.titletype() == TITLE_ENVIRONMENT) {
768 os << "\\end{" << tclass.titlename()
772 os << "\\" << tclass.titlename()
776 already_title = true;
780 if (layout->is_environment) {
781 par = TeXOnePar(buf, paragraphs, par, os, texrow,
782 runparams, everypar);
783 } else if (layout->isEnvironment() ||
784 !par->params().leftIndent().zero())
786 par = TeXEnvironment(buf, paragraphs, par, os,
789 par = TeXOnePar(buf, paragraphs, par, os, texrow,
790 runparams, everypar);
793 par = TeXOnePar(buf, paragraphs, par, os, texrow,
794 runparams, everypar);
797 // It might be that we only have a title in this document
798 if (was_title && !already_title) {
799 if (tclass.titletype() == TITLE_ENVIRONMENT) {
800 os << "\\end{" << tclass.titlename()
804 os << "\\" << tclass.titlename()
814 int readParToken(Buffer & buf, Paragraph & par, LyXLex & lex, string const & token)
817 static Change change;
819 BufferParams const & bp = buf.params();
821 if (token[0] != '\\') {
822 string::const_iterator cit = token.begin();
823 for (; cit != token.end(); ++cit) {
824 par.insertChar(par.size(), (*cit), font, change);
826 } else if (token == "\\begin_layout") {
828 string layoutname = lex.getString();
830 font = LyXFont(LyXFont::ALL_INHERIT, bp.language);
833 LyXTextClass const & tclass = bp.getLyXTextClass();
835 if (layoutname.empty()) {
836 layoutname = tclass.defaultLayoutName();
839 bool hasLayout = tclass.hasLayout(layoutname);
842 lyxerr << "Layout '" << layoutname << "' does not"
843 << " exist in textclass '" << tclass.name()
845 lyxerr << "Trying to use default layout instead."
847 layoutname = tclass.defaultLayoutName();
850 par.layout(bp.getLyXTextClass()[layoutname]);
852 // Test whether the layout is obsolete.
853 LyXLayout_ptr const & layout = par.layout();
854 if (!layout->obsoleted_by().empty())
855 par.layout(bp.getLyXTextClass()[layout->obsoleted_by()]);
857 par.params().read(lex);
859 } else if (token == "\\end_layout") {
860 lyxerr << "Solitary \\end_layout in line " << lex.getLineNo() << "\n"
861 << "Missing \\begin_layout?.\n";
862 } else if (token == "\\end_inset") {
863 lyxerr << "Solitary \\end_inset in line " << lex.getLineNo() << "\n"
864 << "Missing \\begin_inset?.\n";
865 } else if (token == "\\begin_inset") {
866 InsetOld * inset = readInset(lex, buf);
867 par.insertInset(par.size(), inset, font, change);
868 } else if (token == "\\family") {
870 font.setLyXFamily(lex.getString());
871 } else if (token == "\\series") {
873 font.setLyXSeries(lex.getString());
874 } else if (token == "\\shape") {
876 font.setLyXShape(lex.getString());
877 } else if (token == "\\size") {
879 font.setLyXSize(lex.getString());
880 } else if (token == "\\lang") {
882 string const tok = lex.getString();
883 Language const * lang = languages.getLanguage(tok);
885 font.setLanguage(lang);
887 font.setLanguage(bp.language);
888 lex.printError("Unknown language `$$Token'");
890 } else if (token == "\\numeric") {
892 font.setNumber(font.setLyXMisc(lex.getString()));
893 } else if (token == "\\emph") {
895 font.setEmph(font.setLyXMisc(lex.getString()));
896 } else if (token == "\\bar") {
898 string const tok = lex.getString();
901 font.setUnderbar(LyXFont::ON);
902 else if (tok == "no")
903 font.setUnderbar(LyXFont::OFF);
904 else if (tok == "default")
905 font.setUnderbar(LyXFont::INHERIT);
907 lex.printError("Unknown bar font flag "
909 } else if (token == "\\noun") {
911 font.setNoun(font.setLyXMisc(lex.getString()));
912 } else if (token == "\\color") {
914 font.setLyXColor(lex.getString());
915 } else if (token == "\\InsetSpace" || token == "\\SpecialChar") {
917 // Insets don't make sense in a free-spacing context! ---Kayvan
918 if (par.isFreeSpacing()) {
919 if (token == "\\InsetSpace")
920 par.insertChar(par.size(), ' ', font, change);
921 else if (lex.isOK()) {
923 string const next_token = lex.getString();
924 if (next_token == "\\-")
925 par.insertChar(par.size(), '-', font, change);
927 lex.printError("Token `$$Token' "
929 "paragraph layout!");
933 InsetOld * inset = 0;
934 if (token == "\\SpecialChar" )
935 inset = new InsetSpecialChar;
937 inset = new InsetSpace;
938 inset->read(buf, lex);
939 par.insertInset(par.size(), inset, font, change);
941 } else if (token == "\\i") {
942 InsetOld * inset = new InsetLatexAccent;
943 inset->read(buf, lex);
944 par.insertInset(par.size(), inset, font, change);
945 } else if (token == "\\backslash") {
946 par.insertChar(par.size(), '\\', font, change);
947 } else if (token == "\\newline") {
948 InsetOld * inset = new InsetNewline;
949 inset->read(buf, lex);
950 par.insertInset(par.size(), inset, font, change);
951 } else if (token == "\\LyXTable") {
952 InsetOld * inset = new InsetTabular(buf);
953 inset->read(buf, lex);
954 par.insertInset(par.size(), inset, font, change);
955 } else if (token == "\\bibitem") {
956 InsetCommandParams p("bibitem", "dummy");
957 InsetBibitem * inset = new InsetBibitem(p);
958 inset->read(buf, lex);
959 par.insertInset(par.size(), inset, font, change);
960 } else if (token == "\\hfill") {
961 par.insertInset(par.size(), new InsetHFill, font, change);
962 } else if (token == "\\change_unchanged") {
963 // Hack ! Needed for empty paragraphs :/
964 // FIXME: is it still ??
967 change = Change(Change::UNCHANGED);
968 } else if (token == "\\change_inserted") {
970 istringstream is(STRCONV(lex.getString()));
974 change = Change(Change::INSERTED, bp.author_map[aid], ct);
975 } else if (token == "\\change_deleted") {
977 istringstream is(STRCONV(lex.getString()));
981 change = Change(Change::DELETED, bp.author_map[aid], ct);
984 string const s = bformat(_("Unknown token: %1$s %2$s\n"),
985 token, lex.getString());
987 buf.error(ErrorItem(_("Unknown token"), s,
988 par.id(), 0, par.size()));
997 int readParagraph(Buffer & buf, Paragraph & par, LyXLex & lex)
1002 string token = lex.getString();
1004 while (lex.isOK()) {
1006 unknown += readParToken(buf, par, lex, token);
1009 token = lex.getString();
1014 if (token == "\\end_layout") {
1015 //Ok, paragraph finished
1019 lyxerr[Debug::PARSER] << "Handling paragraph token: `"
1020 << token << '\'' << endl;
1021 if (token == "\\begin_layout" || token == "\\end_document"
1022 || token == "\\end_inset" || token == "\\begin_deeper"
1023 || token == "\\end_deeper") {
1024 lex.pushToken(token);
1025 lyxerr << "Paragraph ended in line "
1026 << lex.getLineNo() << "\n"
1027 << "Missing \\end_layout.\n";
1036 LyXFont const outerFont(ParagraphList::iterator pit,
1037 ParagraphList const & plist)
1039 Paragraph::depth_type par_depth = pit->getDepth();
1040 LyXFont tmpfont(LyXFont::ALL_INHERIT);
1042 // Resolve against environment font information
1043 while (pit != const_cast<ParagraphList&>(plist).end() &&
1044 par_depth && !tmpfont.resolved()) {
1045 pit = outerHook(pit, plist);
1046 if (pit != const_cast<ParagraphList&>(plist).end()) {
1047 tmpfont.realize(pit->layout()->font);
1048 par_depth = pit->getDepth();
1056 ParagraphList::iterator outerPar(Buffer const & buf, InsetOld const * inset)
1058 ParIterator pit = const_cast<Buffer &>(buf).par_iterator_begin();
1059 ParIterator end = const_cast<Buffer &>(buf).par_iterator_end();
1060 for ( ; pit != end; ++pit) {
1062 ParagraphList * plist;
1063 // the second '=' below is intentional
1064 for (int i = 0; (plist = inset->getParagraphs(i)); ++i)
1065 if (plist == &pit.plist())
1066 return pit.outerPar();
1068 InsetList::iterator ii = pit->insetlist.begin();
1069 InsetList::iterator iend = pit->insetlist.end();
1070 for ( ; ii != iend; ++ii)
1071 if (ii->inset == inset)
1072 return pit.outerPar();
1074 lyxerr << "outerPar: should not happen" << endl;
1076 return const_cast<Buffer &>(buf).paragraphs().end(); // shut up compiler
1080 Paragraph const & ownerPar(Buffer const & buf, InsetOld const * inset)
1082 ParConstIterator pit = buf.par_iterator_begin();
1083 ParConstIterator end = buf.par_iterator_end();
1084 for ( ; pit != end; ++pit) {
1085 ParagraphList * plist;
1086 // the second '=' below is intentional
1087 for (int i = 0; (plist = inset->getParagraphs(i)); ++i)
1088 if (plist == &pit.plist())
1091 InsetList::const_iterator ii = pit->insetlist.begin();
1092 InsetList::const_iterator iend = pit->insetlist.end();
1093 for ( ; ii != iend; ++ii)
1094 if (ii->inset == inset)
1097 lyxerr << "ownerPar: should not happen" << endl;
1099 return buf.paragraphs().front(); // shut up compiler