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/lstrings.h"
41 #include "support/std_sstream.h"
43 using namespace lyx::support;
46 //using lyx::layout_type;
48 using std::istringstream;
51 extern string bibitemWidest(Buffer const &);
56 bool moveItem(Paragraph & from, Paragraph & to,
57 BufferParams const & params, pos_type i, pos_type j)
59 char const tmpchar = from.getChar(i);
60 LyXFont tmpfont = from.getFontSettings(params, i);
62 if (tmpchar == Paragraph::META_INSET) {
63 InsetOld * tmpinset = 0;
64 if (from.getInset(i)) {
65 // the inset is not in a paragraph anymore
66 tmpinset = from.insetlist.release(i);
69 if (!to.insetAllowed(tmpinset->lyxCode()))
71 to.insertInset(j, tmpinset, tmpfont);
73 if (!to.checkInsertChar(tmpfont))
75 to.insertChar(j, tmpchar, tmpfont);
83 void breakParagraph(BufferParams const & bparams,
84 ParagraphList & paragraphs,
85 ParagraphList::iterator par,
89 // create a new paragraph, and insert into the list
90 ParagraphList::iterator tmp = paragraphs.insert(boost::next(par),
93 // without doing that we get a crash when typing <Return> at the
95 tmp->layout(bparams.getLyXTextClass().defaultLayout());
96 // remember to set the inset_owner
97 tmp->setInsetOwner(par->inInset());
99 if (bparams.tracking_changes)
102 // this is an idea for a more userfriendly layout handling, I will
103 // see what the users say
105 // layout stays the same with latex-environments
107 tmp->layout(par->layout());
108 tmp->setLabelWidthString(par->params().labelWidthString());
111 bool const isempty = (par->allowEmpty() && par->empty());
113 if (!isempty && (par->size() > pos || par->empty() || flag == 2)) {
114 tmp->layout(par->layout());
115 tmp->params().align(par->params().align());
116 tmp->setLabelWidthString(par->params().labelWidthString());
118 tmp->params().lineBottom(par->params().lineBottom());
119 par->params().lineBottom(false);
120 tmp->params().pagebreakBottom(par->params().pagebreakBottom());
121 par->params().pagebreakBottom(false);
122 tmp->params().spaceBottom(par->params().spaceBottom());
123 par->params().spaceBottom(VSpace(VSpace::NONE));
125 tmp->params().depth(par->params().depth());
126 tmp->params().noindent(par->params().noindent());
128 // copy everything behind the break-position
129 // to the new paragraph
132 #warning this seems wrong
134 /* FIXME: if !keepempty, empty() == true, then we reach
135 * here with size() == 0. So pos_end becomes - 1. Why
136 * doesn't this cause problems ???
138 pos_type pos_end = par->size() - 1;
142 for (; i <= pos_end; ++i) {
143 Change::Type change = par->lookupChange(i);
144 if (moveItem(*par, *tmp, bparams, i, j - pos)) {
145 tmp->setChange(j - pos, change);
150 for (i = pos_end; i >= pos; --i)
157 tmp->params().lineTop(par->params().lineTop());
158 tmp->params().pagebreakTop(par->params().pagebreakTop());
159 tmp->params().spaceTop(par->params().spaceTop());
160 par->params().clear();
162 par->layout(bparams.getLyXTextClass().defaultLayout());
164 // layout stays the same with latex-environments
166 par->layout(tmp->layout());
167 par->setLabelWidthString(tmp->params().labelWidthString());
168 par->params().depth(tmp->params().depth());
171 // subtle, but needed to get empty pars working right
172 if (bparams.tracking_changes) {
175 } else if (!tmp->size()) {
182 void breakParagraphConservative(BufferParams const & bparams,
183 ParagraphList & paragraphs,
184 ParagraphList::iterator par,
187 // create a new paragraph
188 ParagraphList::iterator tmp = paragraphs.insert(boost::next(par),
190 tmp->makeSameLayout(*par);
192 // When can pos > size()?
193 // I guess pos == size() is possible.
194 if (par->size() > pos) {
195 // copy everything behind the break-position to the new
197 pos_type pos_end = par->size() - 1;
199 for (pos_type i = pos, j = pos; i <= pos_end; ++i)
200 if (moveItem(*par, *tmp, bparams, i, j - pos))
203 for (pos_type k = pos_end; k >= pos; --k)
209 void mergeParagraph(BufferParams const & bparams,
210 ParagraphList & paragraphs,
211 ParagraphList::iterator par)
213 ParagraphList::iterator the_next = boost::next(par);
215 // first the DTP-stuff
216 par->params().lineBottom(the_next->params().lineBottom());
217 par->params().spaceBottom(the_next->params().spaceBottom());
218 par->params().pagebreakBottom(the_next->params().pagebreakBottom());
220 pos_type pos_end = the_next->size() - 1;
221 pos_type pos_insert = par->size();
223 // ok, now copy the paragraph
224 for (pos_type i = 0, j = 0; i <= pos_end; ++i)
225 if (moveItem(*the_next, *par, bparams, i, pos_insert + j))
228 paragraphs.erase(the_next);
232 ParagraphList::iterator depthHook(ParagraphList::iterator pit,
233 ParagraphList const & plist,
234 Paragraph::depth_type depth)
236 ParagraphList::iterator newpit = pit;
237 ParagraphList::iterator beg = const_cast<ParagraphList&>(plist).begin();
242 while (newpit != beg && newpit->getDepth() > depth) {
246 if (newpit->getDepth() > depth)
253 ParagraphList::iterator outerHook(ParagraphList::iterator pit,
254 ParagraphList const & plist)
256 if (!pit->getDepth())
257 return const_cast<ParagraphList&>(plist).end();
258 return depthHook(pit, plist,
259 Paragraph::depth_type(pit->getDepth() - 1));
263 bool isFirstInSequence(ParagraphList::iterator pit,
264 ParagraphList const & plist)
266 ParagraphList::iterator dhook = depthHook(pit, plist, pit->getDepth());
268 || dhook->layout() != pit->layout()
269 || dhook->getDepth() != pit->getDepth());
273 int getEndLabel(ParagraphList::iterator p, ParagraphList const & plist)
275 ParagraphList::iterator pit = p;
276 Paragraph::depth_type par_depth = p->getDepth();
277 while (pit != const_cast<ParagraphList&>(plist).end()) {
278 LyXLayout_ptr const & layout = pit->layout();
279 int const endlabeltype = layout->endlabeltype;
281 if (endlabeltype != END_LABEL_NO_LABEL) {
282 if (boost::next(p) == const_cast<ParagraphList&>(plist).end())
285 Paragraph::depth_type const next_depth = boost::next(p)->getDepth();
286 if (par_depth > next_depth ||
287 (par_depth == next_depth &&
288 layout != boost::next(p)->layout()))
294 pit = outerHook(pit, plist);
295 if (pit != const_cast<ParagraphList&>(plist).end())
296 par_depth = pit->getDepth();
298 return END_LABEL_NO_LABEL;
304 ParagraphList::iterator
305 TeXEnvironment(Buffer const & buf,
306 ParagraphList const & paragraphs,
307 ParagraphList::iterator pit,
308 ostream & os, TexRow & texrow,
309 LatexRunParams const & runparams);
311 ParagraphList::iterator
312 TeXOnePar(Buffer const & buf,
313 ParagraphList const & paragraphs,
314 ParagraphList::iterator pit,
315 ostream & os, TexRow & texrow,
316 LatexRunParams const & runparams,
317 string const & everypar = string());
320 ParagraphList::iterator
321 TeXDeeper(Buffer const & buf,
322 ParagraphList const & paragraphs,
323 ParagraphList::iterator pit,
324 ostream & os, TexRow & texrow,
325 LatexRunParams const & runparams)
327 lyxerr[Debug::LATEX] << "TeXDeeper... " << &*pit << endl;
328 ParagraphList::iterator par = pit;
330 while (par != const_cast<ParagraphList&>(paragraphs).end() &&
331 par->params().depth() == pit->params().depth()) {
332 if (par->layout()->isEnvironment()) {
333 par = TeXEnvironment(buf, paragraphs, par,
334 os, texrow, runparams);
336 par = TeXOnePar(buf, paragraphs, par,
337 os, texrow, runparams);
340 lyxerr[Debug::LATEX] << "TeXDeeper...done " << &*par << endl;
346 ParagraphList::iterator
347 TeXEnvironment(Buffer const & buf,
348 ParagraphList const & paragraphs,
349 ParagraphList::iterator pit,
350 ostream & os, TexRow & texrow,
351 LatexRunParams const & runparams)
353 lyxerr[Debug::LATEX] << "TeXEnvironment... " << &*pit << endl;
355 BufferParams const & bparams = buf.params();
357 LyXLayout_ptr const & style = pit->layout();
359 Language const * language = pit->getParLanguage(bparams);
360 Language const * doc_language = bparams.language;
361 Language const * previous_language =
362 (pit != const_cast<ParagraphList&>(paragraphs).begin())
363 ? boost::prior(pit)->getParLanguage(bparams)
365 if (language->babel() != previous_language->babel()) {
367 if (!lyxrc.language_command_end.empty() &&
368 previous_language->babel() != doc_language->babel()) {
369 os << subst(lyxrc.language_command_end, "$$lang",
370 previous_language->babel())
375 if (lyxrc.language_command_end.empty() ||
376 language->babel() != doc_language->babel()) {
377 os << subst(lyxrc.language_command_begin, "$$lang",
384 bool leftindent_open = false;
385 if (!pit->params().leftIndent().zero()) {
386 os << "\\begin{LyXParagraphLeftIndent}{" <<
387 pit->params().leftIndent().asLatexString() << "}\n";
389 leftindent_open = true;
392 if (style->isEnvironment()) {
393 if (style->latextype == LATEX_LIST_ENVIRONMENT) {
394 os << "\\begin{" << style->latexname() << "}{"
395 << pit->params().labelWidthString() << "}\n";
396 } else if (style->labeltype == LABEL_BIBLIO) {
398 os << "\\begin{" << style->latexname() << "}{"
399 << bibitemWidest(buf)
401 } else if (style->latextype == LATEX_ITEM_ENVIRONMENT) {
402 os << "\\begin{" << style->latexname() << '}'
403 << style->latexparam() << '\n';
405 os << "\\begin{" << style->latexname() << '}'
406 << style->latexparam() << '\n';
409 ParagraphList::iterator par = pit;
411 par = TeXOnePar(buf, paragraphs, par, os, texrow, runparams);
413 if (par != const_cast<ParagraphList&>(paragraphs).end() && par->params().depth() > pit->params().depth()) {
414 if (par->layout()->isParagraph()) {
417 // How to handle this? (Lgb)
418 //&& !suffixIs(os, "\n\n")
420 // There should be at least one '\n' already
421 // but we need there to be two for Standard
422 // paragraphs that are depth-increment'ed to be
423 // output correctly. However, tables can
424 // also be paragraphs so don't adjust them.
427 // Will it ever harm to have one '\n' too
428 // many? i.e. that we sometimes will have
429 // three in a row. (Lgb)
433 par = TeXDeeper(buf, paragraphs, par, os, texrow,
436 } while (par != const_cast<ParagraphList&>(paragraphs).end()
437 && par->layout() == pit->layout()
438 && par->params().depth() == pit->params().depth()
439 && par->params().leftIndent() == pit->params().leftIndent());
441 if (style->isEnvironment()) {
442 os << "\\end{" << style->latexname() << "}\n";
446 if (leftindent_open) {
447 os << "\\end{LyXParagraphLeftIndent}\n";
451 lyxerr[Debug::LATEX] << "TeXEnvironment...done " << &*par << endl;
452 return par; // ale970302
456 InsetOptArg * optArgInset(Paragraph const & par)
459 InsetList::const_iterator it = par.insetlist.begin();
460 InsetList::const_iterator end = par.insetlist.end();
461 for (; it != end; ++it) {
462 InsetOld * ins = it->inset;
463 if (ins->lyxCode() == InsetOld::OPTARG_CODE) {
464 return static_cast<InsetOptArg *>(ins);
471 ParagraphList::iterator
472 TeXOnePar(Buffer const & buf,
473 ParagraphList const & paragraphs,
474 ParagraphList::iterator pit,
475 ostream & os, TexRow & texrow,
476 LatexRunParams const & runparams,
477 string const & everypar)
479 lyxerr[Debug::LATEX] << "TeXOnePar... " << &*pit << " '"
480 << everypar << "'" << endl;
481 BufferParams const & bparams = buf.params();
483 InsetOld const * in = pit->inInset();
484 bool further_blank_line = false;
487 // well we have to check if we are in an inset with unlimited
488 // length (all in one row) if that is true then we don't allow
489 // any special options in the paragraph and also we don't allow
490 // any environment other then "Standard" to be valid!
491 if (in == 0 || !in->forceDefaultParagraphs(in)) {
492 style = pit->layout();
494 if (pit->params().startOfAppendix()) {
495 os << "\\appendix\n";
499 if (!pit->params().spacing().isDefault()
500 && (pit == const_cast<ParagraphList&>(paragraphs).begin() || !boost::prior(pit)->hasSameLayout(*pit))) {
501 os << pit->params().spacing().writeEnvirBegin() << '\n';
505 if (style->isCommand()) {
510 if (pit->params().pagebreakTop()) {
512 further_blank_line = true;
514 if (pit->params().spaceTop().kind() != VSpace::NONE) {
515 os << pit->params().spaceTop().asLatexCommand(bparams);
516 further_blank_line = true;
519 if (pit->params().lineTop()) {
521 << pit->getFont(bparams, 0, outerFont(pit, paragraphs)).latexSize()
523 << "\\vspace{-1\\parskip}";
524 further_blank_line = true;
527 if (further_blank_line) {
532 style = bparams.getLyXTextClass().defaultLayout();
535 Language const * language = pit->getParLanguage(bparams);
536 Language const * doc_language = bparams.language;
537 Language const * previous_language =
538 (pit != const_cast<ParagraphList&>(paragraphs).begin())
539 ? boost::prior(pit)->getParLanguage(bparams)
542 if (language->babel() != previous_language->babel()
543 // check if we already put language command in TeXEnvironment()
544 && !(style->isEnvironment()
545 && (pit == const_cast<ParagraphList&>(paragraphs).begin() ||
546 (boost::prior(pit)->layout() != pit->layout() &&
547 boost::prior(pit)->getDepth() <= pit->getDepth())
548 || boost::prior(pit)->getDepth() < pit->getDepth())))
550 if (!lyxrc.language_command_end.empty() &&
551 previous_language->babel() != doc_language->babel())
553 os << subst(lyxrc.language_command_end, "$$lang",
554 previous_language->babel())
559 if (lyxrc.language_command_end.empty() ||
560 language->babel() != doc_language->babel())
562 os << subst(lyxrc.language_command_begin, "$$lang",
569 if (bparams.inputenc == "auto" &&
570 language->encoding() != previous_language->encoding()) {
571 os << "\\inputencoding{"
572 << language->encoding()->LatexName()
577 switch (style->latextype) {
579 os << '\\' << style->latexname();
581 // Separate handling of optional argument inset.
582 if (style->optionalargs == 1) {
583 InsetOptArg * it = optArgInset(*pit);
585 it->latexOptional(buf, os, runparams);
588 os << style->latexparam();
590 case LATEX_ITEM_ENVIRONMENT:
591 case LATEX_LIST_ENVIRONMENT:
594 case LATEX_BIB_ENVIRONMENT:
595 // ignore this, the inset will write itself
602 bool need_par = pit->simpleTeXOnePar(buf, bparams,
603 outerFont(pit, paragraphs),
604 os, texrow, runparams);
606 // Make sure that \\par is done with the font of the last
607 // character if this has another size as the default.
608 // This is necessary because LaTeX (and LyX on the screen)
609 // calculates the space between the baselines according
610 // to this font. (Matthias)
612 // Is this really needed ? (Dekel)
613 // We do not need to use to change the font for the last paragraph
615 LyXFont const outerfont(outerFont(pit, paragraphs));
619 ? pit->getLayoutFont(bparams, outerfont)
620 : pit->getFont(bparams, pit->size() - 1, outerfont));
622 bool is_command = style->isCommand();
624 if (style->resfont.size() != font.size()
625 && boost::next(pit) != const_cast<ParagraphList&>(paragraphs).end()
629 os << "\\" << font.latexSize() << " \\par}";
630 } else if (need_par) {
632 } else if (is_command)
635 switch (style->latextype) {
636 case LATEX_ITEM_ENVIRONMENT:
637 case LATEX_LIST_ENVIRONMENT:
638 if (boost::next(pit) != const_cast<ParagraphList&>(paragraphs).end()
639 && (pit->params().depth() < boost::next(pit)->params().depth())) {
644 case LATEX_ENVIRONMENT: {
645 // if its the last paragraph of the current environment
646 // skip it otherwise fall through
647 ParagraphList::iterator next = boost::next(pit);
649 if (next != const_cast<ParagraphList&>(paragraphs).end()
650 && (next->layout() != pit->layout()
651 || next->params().depth() != pit->params().depth()))
655 // fall through possible
657 // we don't need it for the last paragraph!!!
658 if (boost::next(pit) != const_cast<ParagraphList&>(paragraphs).end()) {
664 if (in == 0 || !in->forceDefaultParagraphs(in)) {
665 further_blank_line = false;
666 if (pit->params().lineBottom()) {
667 os << "\\lyxline{\\" << font.latexSize() << '}';
668 further_blank_line = true;
671 if (pit->params().spaceBottom().kind() != VSpace::NONE) {
672 os << pit->params().spaceBottom().asLatexCommand(bparams);
673 further_blank_line = true;
676 if (pit->params().pagebreakBottom()) {
678 further_blank_line = true;
681 if (further_blank_line) {
686 if (!pit->params().spacing().isDefault()
687 && (boost::next(pit) == const_cast<ParagraphList&>(paragraphs).end()|| !boost::next(pit)->hasSameLayout(*pit))) {
688 os << pit->params().spacing().writeEnvirEnd() << '\n';
693 // we don't need it for the last paragraph!!!
694 if (boost::next(pit) != const_cast<ParagraphList&>(paragraphs).end()) {
698 // Since \selectlanguage write the language to the aux file,
699 // we need to reset the language at the end of footnote or
702 if (language->babel() != doc_language->babel()) {
703 if (lyxrc.language_command_end.empty())
704 os << subst(lyxrc.language_command_begin,
706 doc_language->babel())
709 os << subst(lyxrc.language_command_end,
717 lyxerr[Debug::LATEX] << "TeXOnePar...done " << &*boost::next(pit) << endl;
725 // LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
727 void latexParagraphs(Buffer const & buf,
728 ParagraphList const & paragraphs,
731 LatexRunParams const & runparams,
732 string const & everypar)
734 bool was_title = false;
735 bool already_title = false;
736 LyXTextClass const & tclass = buf.params().getLyXTextClass();
737 ParagraphList::iterator par = const_cast<ParagraphList&>(paragraphs).begin();
738 ParagraphList::iterator endpar = const_cast<ParagraphList&>(paragraphs).end();
741 while (par != endpar) {
742 InsetOld * in = par->inInset();
743 // well we have to check if we are in an inset with unlimited
744 // length (all in one row) if that is true then we don't allow
745 // any special options in the paragraph and also we don't allow
746 // any environment other then "Standard" to be valid!
747 if (in == 0 || !in->forceDefaultParagraphs(in)) {
748 LyXLayout_ptr const & layout = par->layout();
750 if (layout->intitle) {
752 lyxerr <<"Error in latexParagraphs: You"
753 " should not mix title layouts"
754 " with normal ones." << endl;
755 } else if (!was_title) {
757 if (tclass.titletype() == TITLE_ENVIRONMENT) {
759 << tclass.titlename()
764 } else if (was_title && !already_title) {
765 if (tclass.titletype() == TITLE_ENVIRONMENT) {
766 os << "\\end{" << tclass.titlename()
770 os << "\\" << tclass.titlename()
774 already_title = true;
778 if (layout->is_environment) {
779 par = TeXOnePar(buf, paragraphs, par, os, texrow,
780 runparams, everypar);
781 } else if (layout->isEnvironment() ||
782 !par->params().leftIndent().zero())
784 par = TeXEnvironment(buf, paragraphs, par, os,
787 par = TeXOnePar(buf, paragraphs, par, os, texrow,
788 runparams, everypar);
791 par = TeXOnePar(buf, paragraphs, par, os, texrow,
792 runparams, everypar);
795 // It might be that we only have a title in this document
796 if (was_title && !already_title) {
797 if (tclass.titletype() == TITLE_ENVIRONMENT) {
798 os << "\\end{" << tclass.titlename()
802 os << "\\" << tclass.titlename()
812 int readParToken(Buffer & buf, Paragraph & par, LyXLex & lex, string const & token)
815 static Change change;
817 BufferParams const & bp = buf.params();
819 if (token[0] != '\\') {
820 string::const_iterator cit = token.begin();
821 for (; cit != token.end(); ++cit) {
822 par.insertChar(par.size(), (*cit), font, change);
824 } else if (token == "\\begin_layout") {
826 string layoutname = lex.getString();
828 font = LyXFont(LyXFont::ALL_INHERIT, bp.language);
831 LyXTextClass const & tclass = bp.getLyXTextClass();
833 if (layoutname.empty()) {
834 layoutname = tclass.defaultLayoutName();
837 bool hasLayout = tclass.hasLayout(layoutname);
840 lyxerr << "Layout '" << layoutname << "' does not"
841 << " exist in textclass '" << tclass.name()
843 lyxerr << "Trying to use default layout instead."
845 layoutname = tclass.defaultLayoutName();
848 par.layout(bp.getLyXTextClass()[layoutname]);
850 // Test whether the layout is obsolete.
851 LyXLayout_ptr const & layout = par.layout();
852 if (!layout->obsoleted_by().empty())
853 par.layout(bp.getLyXTextClass()[layout->obsoleted_by()]);
855 par.params().read(lex);
857 } else if (token == "\\end_layout") {
858 lyxerr << "Solitary \\end_layout in line " << lex.getLineNo() << "\n"
859 << "Missing \\begin_layout?.\n";
860 } else if (token == "\\end_inset") {
861 lyxerr << "Solitary \\end_inset in line " << lex.getLineNo() << "\n"
862 << "Missing \\begin_inset?.\n";
863 } else if (token == "\\begin_inset") {
864 InsetOld * inset = readInset(lex, buf);
865 par.insertInset(par.size(), inset, font, change);
866 } else if (token == "\\family") {
868 font.setLyXFamily(lex.getString());
869 } else if (token == "\\series") {
871 font.setLyXSeries(lex.getString());
872 } else if (token == "\\shape") {
874 font.setLyXShape(lex.getString());
875 } else if (token == "\\size") {
877 font.setLyXSize(lex.getString());
878 } else if (token == "\\lang") {
880 string const tok = lex.getString();
881 Language const * lang = languages.getLanguage(tok);
883 font.setLanguage(lang);
885 font.setLanguage(bp.language);
886 lex.printError("Unknown language `$$Token'");
888 } else if (token == "\\numeric") {
890 font.setNumber(font.setLyXMisc(lex.getString()));
891 } else if (token == "\\emph") {
893 font.setEmph(font.setLyXMisc(lex.getString()));
894 } else if (token == "\\bar") {
896 string const tok = lex.getString();
899 font.setUnderbar(LyXFont::ON);
900 else if (tok == "no")
901 font.setUnderbar(LyXFont::OFF);
902 else if (tok == "default")
903 font.setUnderbar(LyXFont::INHERIT);
905 lex.printError("Unknown bar font flag "
907 } else if (token == "\\noun") {
909 font.setNoun(font.setLyXMisc(lex.getString()));
910 } else if (token == "\\color") {
912 font.setLyXColor(lex.getString());
913 } else if (token == "\\InsetSpace" || token == "\\SpecialChar") {
915 // Insets don't make sense in a free-spacing context! ---Kayvan
916 if (par.isFreeSpacing()) {
917 if (token == "\\InsetSpace")
918 par.insertChar(par.size(), ' ', font, change);
919 else if (lex.isOK()) {
921 string const next_token = lex.getString();
922 if (next_token == "\\-")
923 par.insertChar(par.size(), '-', font, change);
925 lex.printError("Token `$$Token' "
927 "paragraph layout!");
931 InsetOld * inset = 0;
932 if (token == "\\SpecialChar" )
933 inset = new InsetSpecialChar;
935 inset = new InsetSpace;
936 inset->read(buf, lex);
937 par.insertInset(par.size(), inset, font, change);
939 } else if (token == "\\i") {
940 InsetOld * inset = new InsetLatexAccent;
941 inset->read(buf, lex);
942 par.insertInset(par.size(), inset, font, change);
943 } else if (token == "\\backslash") {
944 par.insertChar(par.size(), '\\', font, change);
945 } else if (token == "\\newline") {
946 InsetOld * inset = new InsetNewline;
947 inset->read(buf, lex);
948 par.insertInset(par.size(), inset, font, change);
949 } else if (token == "\\LyXTable") {
950 InsetOld * inset = new InsetTabular(buf);
951 inset->read(buf, lex);
952 par.insertInset(par.size(), inset, font, change);
953 } else if (token == "\\bibitem") {
954 InsetCommandParams p("bibitem", "dummy");
955 InsetBibitem * inset = new InsetBibitem(p);
956 inset->read(buf, lex);
957 par.insertInset(par.size(), inset, font, change);
958 } else if (token == "\\hfill") {
959 par.insertInset(par.size(), new InsetHFill, font, change);
960 } else if (token == "\\change_unchanged") {
961 // Hack ! Needed for empty paragraphs :/
962 // FIXME: is it still ??
965 change = Change(Change::UNCHANGED);
966 } else if (token == "\\change_inserted") {
968 istringstream is(STRCONV(lex.getString()));
972 change = Change(Change::INSERTED, bp.author_map[aid], ct);
973 } else if (token == "\\change_deleted") {
975 istringstream is(STRCONV(lex.getString()));
979 change = Change(Change::DELETED, bp.author_map[aid], ct);
982 string const s = bformat(_("Unknown token: %1$s %2$s\n"),
983 token, lex.getString());
985 buf.error(ErrorItem(_("Unknown token"), s,
986 par.id(), 0, par.size()));
995 int readParagraph(Buffer & buf, Paragraph & par, LyXLex & lex)
1000 string token = lex.getString();
1002 while (lex.isOK()) {
1004 unknown += readParToken(buf, par, lex, token);
1007 token = lex.getString();
1012 if (token == "\\end_layout") {
1013 //Ok, paragraph finished
1017 lyxerr[Debug::PARSER] << "Handling paragraph token: `"
1018 << token << '\'' << endl;
1019 if (token == "\\begin_layout" || token == "\\end_document"
1020 || token == "\\end_inset" || token == "\\begin_deeper"
1021 || token == "\\end_deeper") {
1022 lex.pushToken(token);
1023 lyxerr << "Paragraph ended in line "
1024 << lex.getLineNo() << "\n"
1025 << "Missing \\end_layout.\n";
1034 LyXFont const outerFont(ParagraphList::iterator pit,
1035 ParagraphList const & plist)
1037 Paragraph::depth_type par_depth = pit->getDepth();
1038 LyXFont tmpfont(LyXFont::ALL_INHERIT);
1040 // Resolve against environment font information
1041 while (pit != const_cast<ParagraphList&>(plist).end() &&
1042 par_depth && !tmpfont.resolved()) {
1043 pit = outerHook(pit, plist);
1044 if (pit != const_cast<ParagraphList&>(plist).end()) {
1045 tmpfont.realize(pit->layout()->font);
1046 par_depth = pit->getDepth();
1054 ParagraphList::iterator outerPar(Buffer const & buf, InsetOld const * inset)
1056 ParIterator pit = const_cast<Buffer &>(buf).par_iterator_begin();
1057 ParIterator end = const_cast<Buffer &>(buf).par_iterator_end();
1058 for ( ; pit != end; ++pit) {
1060 ParagraphList * plist;
1061 // the second '=' below is intentional
1062 for (int i = 0; (plist = inset->getParagraphs(i)); ++i)
1063 if (plist == &pit.plist())
1064 return pit.outerPar();
1066 InsetList::iterator ii = pit->insetlist.begin();
1067 InsetList::iterator iend = pit->insetlist.end();
1068 for ( ; ii != iend; ++ii)
1069 if (ii->inset == inset)
1070 return pit.outerPar();
1072 lyxerr << "outerPar: should not happen" << endl;
1073 BOOST_ASSERT(false);
1074 return const_cast<Buffer &>(buf).paragraphs().end(); // shut up compiler
1078 Paragraph const & ownerPar(Buffer const & buf, InsetOld const * inset)
1080 ParConstIterator pit = buf.par_iterator_begin();
1081 ParConstIterator end = buf.par_iterator_end();
1082 for ( ; pit != end; ++pit) {
1083 ParagraphList * plist;
1084 // the second '=' below is intentional
1085 for (int i = 0; (plist = inset->getParagraphs(i)); ++i)
1086 if (plist == &pit.plist())
1089 InsetList::const_iterator ii = pit->insetlist.begin();
1090 InsetList::const_iterator iend = pit->insetlist.end();
1091 for ( ; ii != iend; ++ii)
1092 if (ii->inset == inset)
1095 lyxerr << "ownerPar: should not happen" << endl;
1096 BOOST_ASSERT(false);
1097 return buf.paragraphs().front(); // shut up compiler