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/insetline.h"
35 #include "insets/insetnewline.h"
36 #include "insets/insetpagebreak.h"
37 #include "insets/insetoptarg.h"
38 #include "insets/insetspace.h"
39 #include "insets/insetspecialchar.h"
40 #include "insets/insettabular.h"
42 #include "support/lstrings.h"
43 #include "support/std_sstream.h"
47 using lyx::support::bformat;
48 using lyx::support::subst;
52 using std::istringstream;
56 extern string bibitemWidest(Buffer const &);
61 bool moveItem(Paragraph & from, Paragraph & to,
62 BufferParams const & params, pos_type i, pos_type j)
64 char const tmpchar = from.getChar(i);
65 LyXFont tmpfont = from.getFontSettings(params, i);
67 if (tmpchar == Paragraph::META_INSET) {
68 InsetOld * tmpinset = 0;
69 if (from.getInset(i)) {
70 // the inset is not in a paragraph anymore
71 tmpinset = from.insetlist.release(i);
74 if (!to.insetAllowed(tmpinset->lyxCode()))
76 to.insertInset(j, tmpinset, tmpfont);
78 if (!to.checkInsertChar(tmpfont))
80 to.insertChar(j, tmpchar, tmpfont);
88 void breakParagraph(BufferParams const & bparams,
89 ParagraphList & paragraphs,
90 ParagraphList::iterator par,
94 // create a new paragraph, and insert into the list
95 ParagraphList::iterator tmp = paragraphs.insert(boost::next(par),
98 // without doing that we get a crash when typing <Return> at the
100 tmp->layout(bparams.getLyXTextClass().defaultLayout());
101 // remember to set the inset_owner
102 tmp->setInsetOwner(par->inInset());
104 if (bparams.tracking_changes)
107 // this is an idea for a more userfriendly layout handling, I will
108 // see what the users say
110 // layout stays the same with latex-environments
112 tmp->layout(par->layout());
113 tmp->setLabelWidthString(par->params().labelWidthString());
116 bool const isempty = (par->allowEmpty() && par->empty());
118 if (!isempty && (par->size() > pos || par->empty() || flag == 2)) {
119 tmp->layout(par->layout());
120 tmp->params().align(par->params().align());
121 tmp->setLabelWidthString(par->params().labelWidthString());
123 tmp->params().spaceBottom(par->params().spaceBottom());
124 par->params().spaceBottom(VSpace(VSpace::NONE));
126 tmp->params().depth(par->params().depth());
127 tmp->params().noindent(par->params().noindent());
129 // copy everything behind the break-position
130 // to the new paragraph
133 #warning this seems wrong
135 /* FIXME: if !keepempty, empty() == true, then we reach
136 * here with size() == 0. So pos_end becomes - 1. Why
137 * doesn't this cause problems ???
139 pos_type pos_end = par->size() - 1;
143 for (; i <= pos_end; ++i) {
144 Change::Type change = par->lookupChange(i);
145 if (moveItem(*par, *tmp, bparams, i, j - pos)) {
146 tmp->setChange(j - pos, change);
151 for (i = pos_end; i >= pos; --i)
158 tmp->params().spaceTop(par->params().spaceTop());
159 par->params().clear();
161 par->layout(bparams.getLyXTextClass().defaultLayout());
163 // layout stays the same with latex-environments
165 par->layout(tmp->layout());
166 par->setLabelWidthString(tmp->params().labelWidthString());
167 par->params().depth(tmp->params().depth());
170 // subtle, but needed to get empty pars working right
171 if (bparams.tracking_changes) {
174 } else if (!tmp->size()) {
181 void breakParagraphConservative(BufferParams const & bparams,
182 ParagraphList & paragraphs,
183 ParagraphList::iterator par,
186 // create a new paragraph
187 ParagraphList::iterator tmp = paragraphs.insert(boost::next(par),
189 tmp->makeSameLayout(*par);
191 // When can pos > size()?
192 // I guess pos == size() is possible.
193 if (par->size() > pos) {
194 // copy everything behind the break-position to the new
196 pos_type pos_end = par->size() - 1;
198 for (pos_type i = pos, j = pos; i <= pos_end; ++i)
199 if (moveItem(*par, *tmp, bparams, i, j - pos))
202 for (pos_type k = pos_end; k >= pos; --k)
208 void mergeParagraph(BufferParams const & bparams,
209 ParagraphList & paragraphs,
210 ParagraphList::iterator par)
212 ParagraphList::iterator the_next = boost::next(par);
214 // first the DTP-stuff
215 par->params().spaceBottom(the_next->params().spaceBottom());
217 pos_type pos_end = the_next->size() - 1;
218 pos_type pos_insert = par->size();
220 // ok, now copy the paragraph
221 for (pos_type i = 0, j = 0; i <= pos_end; ++i)
222 if (moveItem(*the_next, *par, bparams, i, pos_insert + j))
225 paragraphs.erase(the_next);
229 ParagraphList::iterator depthHook(ParagraphList::iterator pit,
230 ParagraphList const & plist,
231 Paragraph::depth_type depth)
233 ParagraphList::iterator newpit = pit;
234 ParagraphList::iterator beg = const_cast<ParagraphList&>(plist).begin();
239 while (newpit != beg && newpit->getDepth() > depth) {
243 if (newpit->getDepth() > depth)
250 ParagraphList::iterator outerHook(ParagraphList::iterator pit,
251 ParagraphList const & plist)
253 if (!pit->getDepth())
254 return const_cast<ParagraphList&>(plist).end();
255 return depthHook(pit, plist,
256 Paragraph::depth_type(pit->getDepth() - 1));
260 bool isFirstInSequence(ParagraphList::iterator pit,
261 ParagraphList const & plist)
263 ParagraphList::iterator dhook = depthHook(pit, plist, pit->getDepth());
265 || dhook->layout() != pit->layout()
266 || dhook->getDepth() != pit->getDepth());
270 int getEndLabel(ParagraphList::iterator p, ParagraphList const & plist)
272 ParagraphList::iterator pit = p;
273 Paragraph::depth_type par_depth = p->getDepth();
274 while (pit != const_cast<ParagraphList&>(plist).end()) {
275 LyXLayout_ptr const & layout = pit->layout();
276 int const endlabeltype = layout->endlabeltype;
278 if (endlabeltype != END_LABEL_NO_LABEL) {
279 if (boost::next(p) == const_cast<ParagraphList&>(plist).end())
282 Paragraph::depth_type const next_depth = boost::next(p)->getDepth();
283 if (par_depth > next_depth ||
284 (par_depth == next_depth &&
285 layout != boost::next(p)->layout()))
291 pit = outerHook(pit, plist);
292 if (pit != const_cast<ParagraphList&>(plist).end())
293 par_depth = pit->getDepth();
295 return END_LABEL_NO_LABEL;
301 ParagraphList::iterator
302 TeXEnvironment(Buffer const & buf,
303 ParagraphList const & paragraphs,
304 ParagraphList::iterator pit,
305 ostream & os, TexRow & texrow,
306 LatexRunParams const & runparams);
308 ParagraphList::iterator
309 TeXOnePar(Buffer const & buf,
310 ParagraphList const & paragraphs,
311 ParagraphList::iterator pit,
312 ostream & os, TexRow & texrow,
313 LatexRunParams const & runparams,
314 string const & everypar = string());
317 ParagraphList::iterator
318 TeXDeeper(Buffer const & buf,
319 ParagraphList const & paragraphs,
320 ParagraphList::iterator pit,
321 ostream & os, TexRow & texrow,
322 LatexRunParams const & runparams)
324 lyxerr[Debug::LATEX] << "TeXDeeper... " << &*pit << endl;
325 ParagraphList::iterator par = pit;
327 while (par != const_cast<ParagraphList&>(paragraphs).end() &&
328 par->params().depth() == pit->params().depth()) {
329 if (par->layout()->isEnvironment()) {
330 par = TeXEnvironment(buf, paragraphs, par,
331 os, texrow, runparams);
333 par = TeXOnePar(buf, paragraphs, par,
334 os, texrow, runparams);
337 lyxerr[Debug::LATEX] << "TeXDeeper...done " << &*par << endl;
343 ParagraphList::iterator
344 TeXEnvironment(Buffer const & buf,
345 ParagraphList const & paragraphs,
346 ParagraphList::iterator pit,
347 ostream & os, TexRow & texrow,
348 LatexRunParams const & runparams)
350 lyxerr[Debug::LATEX] << "TeXEnvironment... " << &*pit << endl;
352 BufferParams const & bparams = buf.params();
354 LyXLayout_ptr const & style = pit->layout();
356 Language const * language = pit->getParLanguage(bparams);
357 Language const * doc_language = bparams.language;
358 Language const * previous_language =
359 (pit != const_cast<ParagraphList&>(paragraphs).begin())
360 ? boost::prior(pit)->getParLanguage(bparams)
362 if (language->babel() != previous_language->babel()) {
364 if (!lyxrc.language_command_end.empty() &&
365 previous_language->babel() != doc_language->babel()) {
366 os << subst(lyxrc.language_command_end, "$$lang",
367 previous_language->babel())
372 if (lyxrc.language_command_end.empty() ||
373 language->babel() != doc_language->babel()) {
374 os << subst(lyxrc.language_command_begin, "$$lang",
381 bool leftindent_open = false;
382 if (!pit->params().leftIndent().zero()) {
383 os << "\\begin{LyXParagraphLeftIndent}{" <<
384 pit->params().leftIndent().asLatexString() << "}\n";
386 leftindent_open = true;
389 if (style->isEnvironment()) {
390 if (style->latextype == LATEX_LIST_ENVIRONMENT) {
391 os << "\\begin{" << style->latexname() << "}{"
392 << pit->params().labelWidthString() << "}\n";
393 } else if (style->labeltype == LABEL_BIBLIO) {
395 os << "\\begin{" << style->latexname() << "}{"
396 << bibitemWidest(buf)
398 } else if (style->latextype == LATEX_ITEM_ENVIRONMENT) {
399 os << "\\begin{" << style->latexname() << '}'
400 << style->latexparam() << '\n';
402 os << "\\begin{" << style->latexname() << '}'
403 << style->latexparam() << '\n';
406 ParagraphList::iterator par = pit;
408 par = TeXOnePar(buf, paragraphs, par, os, texrow, runparams);
410 if (par != const_cast<ParagraphList&>(paragraphs).end() && par->params().depth() > pit->params().depth()) {
411 if (par->layout()->isParagraph()) {
414 // How to handle this? (Lgb)
415 //&& !suffixIs(os, "\n\n")
417 // There should be at least one '\n' already
418 // but we need there to be two for Standard
419 // paragraphs that are depth-increment'ed to be
420 // output correctly. However, tables can
421 // also be paragraphs so don't adjust them.
424 // Will it ever harm to have one '\n' too
425 // many? i.e. that we sometimes will have
426 // three in a row. (Lgb)
430 par = TeXDeeper(buf, paragraphs, par, os, texrow,
433 } while (par != const_cast<ParagraphList&>(paragraphs).end()
434 && par->layout() == pit->layout()
435 && par->params().depth() == pit->params().depth()
436 && par->params().leftIndent() == pit->params().leftIndent());
438 if (style->isEnvironment()) {
439 os << "\\end{" << style->latexname() << "}\n";
443 if (leftindent_open) {
444 os << "\\end{LyXParagraphLeftIndent}\n";
448 lyxerr[Debug::LATEX] << "TeXEnvironment...done " << &*par << endl;
449 return par; // ale970302
453 InsetOptArg * optArgInset(Paragraph const & par)
456 InsetList::const_iterator it = par.insetlist.begin();
457 InsetList::const_iterator end = par.insetlist.end();
458 for (; it != end; ++it) {
459 InsetOld * ins = it->inset;
460 if (ins->lyxCode() == InsetOld::OPTARG_CODE) {
461 return static_cast<InsetOptArg *>(ins);
468 ParagraphList::iterator
469 TeXOnePar(Buffer const & buf,
470 ParagraphList const & paragraphs,
471 ParagraphList::iterator pit,
472 ostream & os, TexRow & texrow,
473 LatexRunParams const & runparams,
474 string const & everypar)
476 lyxerr[Debug::LATEX] << "TeXOnePar... " << &*pit << " '"
477 << everypar << "'" << endl;
478 BufferParams const & bparams = buf.params();
480 InsetOld const * in = pit->inInset();
481 bool further_blank_line = false;
484 // well we have to check if we are in an inset with unlimited
485 // length (all in one row) if that is true then we don't allow
486 // any special options in the paragraph and also we don't allow
487 // any environment other then "Standard" to be valid!
488 if (in == 0 || !in->forceDefaultParagraphs(in)) {
489 style = pit->layout();
491 if (pit->params().startOfAppendix()) {
492 os << "\\appendix\n";
496 if (!pit->params().spacing().isDefault()
497 && (pit == const_cast<ParagraphList&>(paragraphs).begin()
498 || !boost::prior(pit)->hasSameLayout(*pit)))
500 os << pit->params().spacing().writeEnvirBegin() << '\n';
504 if (style->isCommand()) {
509 if (pit->params().spaceTop().kind() != VSpace::NONE) {
510 os << pit->params().spaceTop().asLatexCommand(bparams);
511 further_blank_line = true;
514 if (further_blank_line) {
519 style = bparams.getLyXTextClass().defaultLayout();
522 Language const * language = pit->getParLanguage(bparams);
523 Language const * doc_language = bparams.language;
524 Language const * previous_language =
525 (pit != const_cast<ParagraphList&>(paragraphs).begin())
526 ? boost::prior(pit)->getParLanguage(bparams)
529 if (language->babel() != previous_language->babel()
530 // check if we already put language command in TeXEnvironment()
531 && !(style->isEnvironment()
532 && (pit == const_cast<ParagraphList&>(paragraphs).begin() ||
533 (boost::prior(pit)->layout() != pit->layout() &&
534 boost::prior(pit)->getDepth() <= pit->getDepth())
535 || boost::prior(pit)->getDepth() < pit->getDepth())))
537 if (!lyxrc.language_command_end.empty() &&
538 previous_language->babel() != doc_language->babel())
540 os << subst(lyxrc.language_command_end, "$$lang",
541 previous_language->babel())
546 if (lyxrc.language_command_end.empty() ||
547 language->babel() != doc_language->babel())
549 os << subst(lyxrc.language_command_begin, "$$lang",
556 if (bparams.inputenc == "auto" &&
557 language->encoding() != previous_language->encoding()) {
558 os << "\\inputencoding{"
559 << language->encoding()->LatexName()
564 switch (style->latextype) {
566 os << '\\' << style->latexname();
568 // Separate handling of optional argument inset.
569 if (style->optionalargs == 1) {
570 InsetOptArg * it = optArgInset(*pit);
572 it->latexOptional(buf, os, runparams);
575 os << style->latexparam();
577 case LATEX_ITEM_ENVIRONMENT:
578 case LATEX_LIST_ENVIRONMENT:
581 case LATEX_BIB_ENVIRONMENT:
582 // ignore this, the inset will write itself
589 bool need_par = pit->simpleTeXOnePar(buf, bparams,
590 outerFont(pit, paragraphs),
591 os, texrow, runparams);
593 // Make sure that \\par is done with the font of the last
594 // character if this has another size as the default.
595 // This is necessary because LaTeX (and LyX on the screen)
596 // calculates the space between the baselines according
597 // to this font. (Matthias)
599 // Is this really needed ? (Dekel)
600 // We do not need to use to change the font for the last paragraph
602 LyXFont const outerfont(outerFont(pit, paragraphs));
606 ? pit->getLayoutFont(bparams, outerfont)
607 : pit->getFont(bparams, pit->size() - 1, outerfont));
609 bool is_command = style->isCommand();
611 if (style->resfont.size() != font.size()
612 && boost::next(pit) != const_cast<ParagraphList&>(paragraphs).end()
616 os << "\\" << font.latexSize() << " \\par}";
617 } else if (need_par) {
619 } else if (is_command)
622 switch (style->latextype) {
623 case LATEX_ITEM_ENVIRONMENT:
624 case LATEX_LIST_ENVIRONMENT:
625 if (boost::next(pit) != const_cast<ParagraphList&>(paragraphs).end()
626 && (pit->params().depth() < boost::next(pit)->params().depth())) {
631 case LATEX_ENVIRONMENT: {
632 // if its the last paragraph of the current environment
633 // skip it otherwise fall through
634 ParagraphList::iterator next = boost::next(pit);
636 if (next != const_cast<ParagraphList&>(paragraphs).end()
637 && (next->layout() != pit->layout()
638 || next->params().depth() != pit->params().depth()))
642 // fall through possible
644 // we don't need it for the last paragraph!!!
645 if (boost::next(pit) != const_cast<ParagraphList&>(paragraphs).end()) {
651 if (in == 0 || !in->forceDefaultParagraphs(in)) {
652 further_blank_line = false;
654 if (pit->params().spaceBottom().kind() != VSpace::NONE) {
655 os << pit->params().spaceBottom().asLatexCommand(bparams);
656 further_blank_line = true;
659 if (further_blank_line) {
664 if (!pit->params().spacing().isDefault()
665 && (boost::next(pit) == const_cast<ParagraphList&>(paragraphs).end()
666 || !boost::next(pit)->hasSameLayout(*pit)))
668 os << pit->params().spacing().writeEnvirEnd() << '\n';
673 // we don't need it for the last paragraph!!!
674 if (boost::next(pit) != const_cast<ParagraphList&>(paragraphs).end()) {
678 // Since \selectlanguage write the language to the aux file,
679 // we need to reset the language at the end of footnote or
682 if (language->babel() != doc_language->babel()) {
683 if (lyxrc.language_command_end.empty())
684 os << subst(lyxrc.language_command_begin,
686 doc_language->babel())
689 os << subst(lyxrc.language_command_end,
697 lyxerr[Debug::LATEX] << "TeXOnePar...done " << &*boost::next(pit) << endl;
705 // LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
707 void latexParagraphs(Buffer const & buf,
708 ParagraphList const & paragraphs,
711 LatexRunParams const & runparams,
712 string const & everypar)
714 bool was_title = false;
715 bool already_title = false;
716 LyXTextClass const & tclass = buf.params().getLyXTextClass();
717 ParagraphList::iterator par = const_cast<ParagraphList&>(paragraphs).begin();
718 ParagraphList::iterator endpar = const_cast<ParagraphList&>(paragraphs).end();
721 while (par != endpar) {
722 InsetOld * in = par->inInset();
723 // well we have to check if we are in an inset with unlimited
724 // length (all in one row) if that is true then we don't allow
725 // any special options in the paragraph and also we don't allow
726 // any environment other then "Standard" to be valid!
727 if (in == 0 || !in->forceDefaultParagraphs(in)) {
728 LyXLayout_ptr const & layout = par->layout();
730 if (layout->intitle) {
732 lyxerr <<"Error in latexParagraphs: You"
733 " should not mix title layouts"
734 " with normal ones." << endl;
735 } else if (!was_title) {
737 if (tclass.titletype() == TITLE_ENVIRONMENT) {
739 << tclass.titlename()
744 } else if (was_title && !already_title) {
745 if (tclass.titletype() == TITLE_ENVIRONMENT) {
746 os << "\\end{" << tclass.titlename()
750 os << "\\" << tclass.titlename()
754 already_title = true;
758 if (layout->is_environment) {
759 par = TeXOnePar(buf, paragraphs, par, os, texrow,
760 runparams, everypar);
761 } else if (layout->isEnvironment() ||
762 !par->params().leftIndent().zero())
764 par = TeXEnvironment(buf, paragraphs, par, os,
767 par = TeXOnePar(buf, paragraphs, par, os, texrow,
768 runparams, everypar);
771 par = TeXOnePar(buf, paragraphs, par, os, texrow,
772 runparams, everypar);
775 // It might be that we only have a title in this document
776 if (was_title && !already_title) {
777 if (tclass.titletype() == TITLE_ENVIRONMENT) {
778 os << "\\end{" << tclass.titlename()
782 os << "\\" << tclass.titlename()
792 int readParToken(Buffer & buf, Paragraph & par, LyXLex & lex, string const & token)
795 static Change change;
797 BufferParams const & bp = buf.params();
799 if (token[0] != '\\') {
800 string::const_iterator cit = token.begin();
801 for (; cit != token.end(); ++cit) {
802 par.insertChar(par.size(), (*cit), font, change);
804 } else if (token == "\\begin_layout") {
806 string layoutname = lex.getString();
808 font = LyXFont(LyXFont::ALL_INHERIT, bp.language);
811 LyXTextClass const & tclass = bp.getLyXTextClass();
813 if (layoutname.empty()) {
814 layoutname = tclass.defaultLayoutName();
817 bool hasLayout = tclass.hasLayout(layoutname);
820 lyxerr << "Layout '" << layoutname << "' does not"
821 << " exist in textclass '" << tclass.name()
823 lyxerr << "Trying to use default layout instead."
825 layoutname = tclass.defaultLayoutName();
828 par.layout(bp.getLyXTextClass()[layoutname]);
830 // Test whether the layout is obsolete.
831 LyXLayout_ptr const & layout = par.layout();
832 if (!layout->obsoleted_by().empty())
833 par.layout(bp.getLyXTextClass()[layout->obsoleted_by()]);
835 par.params().read(lex);
837 } else if (token == "\\end_layout") {
838 lyxerr << "Solitary \\end_layout in line " << lex.getLineNo() << "\n"
839 << "Missing \\begin_layout?.\n";
840 } else if (token == "\\end_inset") {
841 lyxerr << "Solitary \\end_inset in line " << lex.getLineNo() << "\n"
842 << "Missing \\begin_inset?.\n";
843 } else if (token == "\\begin_inset") {
844 InsetOld * inset = readInset(lex, buf);
846 par.insertInset(par.size(), inset, font, change);
849 string line = lex.getString();
850 buf.error(ErrorItem(_("Unknown Inset"), line,
851 buf.paragraphs().back().id(),
855 } else if (token == "\\family") {
857 font.setLyXFamily(lex.getString());
858 } else if (token == "\\series") {
860 font.setLyXSeries(lex.getString());
861 } else if (token == "\\shape") {
863 font.setLyXShape(lex.getString());
864 } else if (token == "\\size") {
866 font.setLyXSize(lex.getString());
867 } else if (token == "\\lang") {
869 string const tok = lex.getString();
870 Language const * lang = languages.getLanguage(tok);
872 font.setLanguage(lang);
874 font.setLanguage(bp.language);
875 lex.printError("Unknown language `$$Token'");
877 } else if (token == "\\numeric") {
879 font.setNumber(font.setLyXMisc(lex.getString()));
880 } else if (token == "\\emph") {
882 font.setEmph(font.setLyXMisc(lex.getString()));
883 } else if (token == "\\bar") {
885 string const tok = lex.getString();
888 font.setUnderbar(LyXFont::ON);
889 else if (tok == "no")
890 font.setUnderbar(LyXFont::OFF);
891 else if (tok == "default")
892 font.setUnderbar(LyXFont::INHERIT);
894 lex.printError("Unknown bar font flag "
896 } else if (token == "\\noun") {
898 font.setNoun(font.setLyXMisc(lex.getString()));
899 } else if (token == "\\color") {
901 font.setLyXColor(lex.getString());
902 } else if (token == "\\InsetSpace" || token == "\\SpecialChar") {
904 // Insets don't make sense in a free-spacing context! ---Kayvan
905 if (par.isFreeSpacing()) {
906 if (token == "\\InsetSpace")
907 par.insertChar(par.size(), ' ', font, change);
908 else if (lex.isOK()) {
910 string const next_token = lex.getString();
911 if (next_token == "\\-")
912 par.insertChar(par.size(), '-', font, change);
914 lex.printError("Token `$$Token' "
916 "paragraph layout!");
920 InsetOld * inset = 0;
921 if (token == "\\SpecialChar" )
922 inset = new InsetSpecialChar;
924 inset = new InsetSpace;
925 inset->read(buf, lex);
926 par.insertInset(par.size(), inset, font, change);
928 } else if (token == "\\i") {
929 InsetOld * inset = new InsetLatexAccent;
930 inset->read(buf, lex);
931 par.insertInset(par.size(), inset, font, change);
932 } else if (token == "\\backslash") {
933 par.insertChar(par.size(), '\\', font, change);
934 } else if (token == "\\newline") {
935 InsetOld * inset = new InsetNewline;
936 inset->read(buf, lex);
937 par.insertInset(par.size(), inset, font, change);
938 } else if (token == "\\LyXTable") {
939 InsetOld * inset = new InsetTabular(buf);
940 inset->read(buf, lex);
941 par.insertInset(par.size(), inset, font, change);
942 } else if (token == "\\bibitem") {
943 InsetCommandParams p("bibitem", "dummy");
944 InsetBibitem * inset = new InsetBibitem(p);
945 inset->read(buf, lex);
946 par.insertInset(par.size(), inset, font, change);
947 } else if (token == "\\hfill") {
948 par.insertInset(par.size(), new InsetHFill, font, change);
949 } else if (token == "\\lyxline") {
950 par.insertInset(par.size(), new InsetLine, font, change);
951 } else if (token == "\\newpage") {
952 par.insertInset(par.size(), new InsetPagebreak, font, change);
953 } else if (token == "\\change_unchanged") {
954 // Hack ! Needed for empty paragraphs :/
955 // FIXME: is it still ??
958 change = Change(Change::UNCHANGED);
959 } else if (token == "\\change_inserted") {
961 istringstream is(lex.getString());
965 change = Change(Change::INSERTED, bp.author_map[aid], ct);
966 } else if (token == "\\change_deleted") {
968 istringstream is(lex.getString());
972 change = Change(Change::DELETED, bp.author_map[aid], ct);
975 string const s = bformat(_("Unknown token: %1$s %2$s\n"),
976 token, lex.getString());
978 buf.error(ErrorItem(_("Unknown token"), s,
979 buf.paragraphs().back().id(),
989 int readParagraph(Buffer & buf, Paragraph & par, LyXLex & lex)
994 string token = lex.getString();
998 unknown += readParToken(buf, par, lex, token);
1001 token = lex.getString();
1006 if (token == "\\end_layout") {
1007 //Ok, paragraph finished
1011 lyxerr[Debug::PARSER] << "Handling paragraph token: `"
1012 << token << '\'' << endl;
1013 if (token == "\\begin_layout" || token == "\\end_document"
1014 || token == "\\end_inset" || token == "\\begin_deeper"
1015 || token == "\\end_deeper") {
1016 lex.pushToken(token);
1017 lyxerr << "Paragraph ended in line "
1018 << lex.getLineNo() << "\n"
1019 << "Missing \\end_layout.\n";
1028 LyXFont const outerFont(ParagraphList::iterator pit,
1029 ParagraphList const & plist)
1031 Paragraph::depth_type par_depth = pit->getDepth();
1032 LyXFont tmpfont(LyXFont::ALL_INHERIT);
1034 // Resolve against environment font information
1035 while (pit != const_cast<ParagraphList&>(plist).end() &&
1036 par_depth && !tmpfont.resolved()) {
1037 pit = outerHook(pit, plist);
1038 if (pit != const_cast<ParagraphList&>(plist).end()) {
1039 tmpfont.realize(pit->layout()->font);
1040 par_depth = pit->getDepth();
1048 ParagraphList::iterator outerPar(Buffer const & buf, InsetOld const * inset)
1050 ParIterator pit = const_cast<Buffer &>(buf).par_iterator_begin();
1051 ParIterator end = const_cast<Buffer &>(buf).par_iterator_end();
1052 for ( ; pit != end; ++pit) {
1054 ParagraphList * plist;
1055 // the second '=' below is intentional
1056 for (int i = 0; (plist = inset->getParagraphs(i)); ++i)
1057 if (plist == &pit.plist())
1058 return pit.outerPar();
1060 InsetList::iterator ii = pit->insetlist.begin();
1061 InsetList::iterator iend = pit->insetlist.end();
1062 for ( ; ii != iend; ++ii)
1063 if (ii->inset == inset)
1064 return pit.outerPar();
1066 lyxerr << "outerPar: should not happen" << endl;
1067 BOOST_ASSERT(false);
1068 return const_cast<Buffer &>(buf).paragraphs().end(); // shut up compiler
1072 Paragraph const & ownerPar(Buffer const & buf, InsetOld const * inset)
1074 ParConstIterator pit = buf.par_iterator_begin();
1075 ParConstIterator end = buf.par_iterator_end();
1076 for ( ; pit != end; ++pit) {
1077 ParagraphList * plist;
1078 // the second '=' below is intentional
1079 for (int i = 0; (plist = inset->getParagraphs(i)); ++i)
1080 if (plist == &pit.plist())
1083 InsetList::const_iterator ii = pit->insetlist.begin();
1084 InsetList::const_iterator iend = pit->insetlist.end();
1085 for ( ; ii != iend; ++ii)
1086 if (ii->inset == inset)
1089 lyxerr << "ownerPar: should not happen" << endl;
1090 BOOST_ASSERT(false);
1091 return buf.paragraphs().front(); // shut up compiler