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"
14 #include "paragraph_pimpl.h"
16 #include "ParagraphParameters.h"
17 #include "lyxtextclasslist.h"
20 #include "iterators.h"
28 #include "support/lstrings.h"
29 #include "support/LAssert.h"
31 #include "insets/insetoptarg.h"
32 #include "insets/insetcommandparams.h"
33 #include "insets/insetbibitem.h"
34 #include "insets/insetspace.h"
35 #include "insets/insetspecialchar.h"
36 #include "insets/insetlatexaccent.h"
37 #include "insets/insettabular.h"
38 #include "insets/insethfill.h"
39 #include "insets/insetnewline.h"
41 extern string bibitemWidest(Buffer const &);
43 using namespace lyx::support;
46 //using lyx::layout_type;
53 bool moveItem(Paragraph & from, Paragraph & to,
54 BufferParams const & params, pos_type i, pos_type j)
56 char const tmpchar = from.getChar(i);
57 LyXFont tmpfont = from.getFontSettings(params, i);
59 if (tmpchar == Paragraph::META_INSET) {
60 InsetOld * tmpinset = 0;
61 if (from.getInset(i)) {
62 // the inset is not in a paragraph anymore
63 tmpinset = from.insetlist.release(i);
66 if (!to.insetAllowed(tmpinset->lyxCode()))
68 to.insertInset(j, tmpinset, tmpfont);
70 if (!to.checkInsertChar(tmpfont))
72 to.insertChar(j, tmpchar, tmpfont);
80 void breakParagraph(BufferParams const & bparams,
81 ParagraphList & paragraphs,
82 ParagraphList::iterator par,
86 // create a new paragraph, and insert into the list
87 ParagraphList::iterator tmp = paragraphs.insert(boost::next(par),
90 // without doing that we get a crash when typing <Return> at the
92 tmp->layout(bparams.getLyXTextClass().defaultLayout());
93 // remember to set the inset_owner
94 tmp->setInsetOwner(par->inInset());
96 if (bparams.tracking_changes)
99 // this is an idea for a more userfriendly layout handling, I will
100 // see what the users say
102 // layout stays the same with latex-environments
104 tmp->layout(par->layout());
105 tmp->setLabelWidthString(par->params().labelWidthString());
108 bool const isempty = (par->allowEmpty() && par->empty());
110 if (!isempty && (par->size() > pos || par->empty() || flag == 2)) {
111 tmp->layout(par->layout());
112 tmp->params().align(par->params().align());
113 tmp->setLabelWidthString(par->params().labelWidthString());
115 tmp->params().lineBottom(par->params().lineBottom());
116 par->params().lineBottom(false);
117 tmp->params().pagebreakBottom(par->params().pagebreakBottom());
118 par->params().pagebreakBottom(false);
119 tmp->params().spaceBottom(par->params().spaceBottom());
120 par->params().spaceBottom(VSpace(VSpace::NONE));
122 tmp->params().depth(par->params().depth());
123 tmp->params().noindent(par->params().noindent());
125 // copy everything behind the break-position
126 // to the new paragraph
129 #warning this seems wrong
131 /* FIXME: if !keepempty, empty() == true, then we reach
132 * here with size() == 0. So pos_end becomes - 1. Why
133 * doesn't this cause problems ???
135 pos_type pos_end = par->size() - 1;
139 for (; i <= pos_end; ++i) {
140 Change::Type change = par->lookupChange(i);
141 if (moveItem(*par, *tmp, bparams, i, j - pos)) {
142 tmp->setChange(j - pos, change);
147 for (i = pos_end; i >= pos; --i)
154 tmp->params().lineTop(par->params().lineTop());
155 tmp->params().pagebreakTop(par->params().pagebreakTop());
156 tmp->params().spaceTop(par->params().spaceTop());
157 par->params().clear();
159 par->layout(bparams.getLyXTextClass().defaultLayout());
161 // layout stays the same with latex-environments
163 par->layout(tmp->layout());
164 par->setLabelWidthString(tmp->params().labelWidthString());
165 par->params().depth(tmp->params().depth());
168 // subtle, but needed to get empty pars working right
169 if (bparams.tracking_changes) {
172 } else if (!tmp->size()) {
179 void breakParagraphConservative(BufferParams const & bparams,
180 ParagraphList & paragraphs,
181 ParagraphList::iterator par,
184 // create a new paragraph
185 ParagraphList::iterator tmp = paragraphs.insert(boost::next(par),
187 tmp->makeSameLayout(*par);
189 // When can pos > size()?
190 // I guess pos == size() is possible.
191 if (par->size() > pos) {
192 // copy everything behind the break-position to the new
194 pos_type pos_end = par->size() - 1;
196 for (pos_type i = pos, j = pos; i <= pos_end; ++i)
197 if (moveItem(*par, *tmp, bparams, i, j - pos))
200 for (pos_type k = pos_end; k >= pos; --k)
206 void mergeParagraph(BufferParams const & bparams,
207 ParagraphList & paragraphs,
208 ParagraphList::iterator par)
210 ParagraphList::iterator the_next = boost::next(par);
212 // first the DTP-stuff
213 par->params().lineBottom(the_next->params().lineBottom());
214 par->params().spaceBottom(the_next->params().spaceBottom());
215 par->params().pagebreakBottom(the_next->params().pagebreakBottom());
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() || !boost::prior(pit)->hasSameLayout(*pit))) {
498 os << pit->params().spacing().writeEnvirBegin() << '\n';
502 if (style->isCommand()) {
507 if (pit->params().pagebreakTop()) {
509 further_blank_line = true;
511 if (pit->params().spaceTop().kind() != VSpace::NONE) {
512 os << pit->params().spaceTop().asLatexCommand(bparams);
513 further_blank_line = true;
516 if (pit->params().lineTop()) {
518 << pit->getFont(bparams, 0, outerFont(pit, paragraphs)).latexSize()
520 << "\\vspace{-1\\parskip}";
521 further_blank_line = true;
524 if (further_blank_line) {
529 style = bparams.getLyXTextClass().defaultLayout();
532 Language const * language = pit->getParLanguage(bparams);
533 Language const * doc_language = bparams.language;
534 Language const * previous_language =
535 (pit != const_cast<ParagraphList&>(paragraphs).begin())
536 ? boost::prior(pit)->getParLanguage(bparams)
539 if (language->babel() != previous_language->babel()
540 // check if we already put language command in TeXEnvironment()
541 && !(style->isEnvironment()
542 && (pit == const_cast<ParagraphList&>(paragraphs).begin() ||
543 (boost::prior(pit)->layout() != pit->layout() &&
544 boost::prior(pit)->getDepth() <= pit->getDepth())
545 || boost::prior(pit)->getDepth() < pit->getDepth())))
547 if (!lyxrc.language_command_end.empty() &&
548 previous_language->babel() != doc_language->babel())
550 os << subst(lyxrc.language_command_end, "$$lang",
551 previous_language->babel())
556 if (lyxrc.language_command_end.empty() ||
557 language->babel() != doc_language->babel())
559 os << subst(lyxrc.language_command_begin, "$$lang",
566 if (bparams.inputenc == "auto" &&
567 language->encoding() != previous_language->encoding()) {
568 os << "\\inputencoding{"
569 << language->encoding()->LatexName()
574 switch (style->latextype) {
576 os << '\\' << style->latexname();
578 // Separate handling of optional argument inset.
579 if (style->optionalargs == 1) {
580 InsetOptArg * it = optArgInset(*pit);
582 it->latexOptional(buf, os, runparams);
585 os << style->latexparam();
587 case LATEX_ITEM_ENVIRONMENT:
588 case LATEX_LIST_ENVIRONMENT:
591 case LATEX_BIB_ENVIRONMENT:
592 // ignore this, the inset will write itself
599 bool need_par = pit->simpleTeXOnePar(buf, bparams,
600 outerFont(pit, paragraphs),
601 os, texrow, runparams);
603 // Make sure that \\par is done with the font of the last
604 // character if this has another size as the default.
605 // This is necessary because LaTeX (and LyX on the screen)
606 // calculates the space between the baselines according
607 // to this font. (Matthias)
609 // Is this really needed ? (Dekel)
610 // We do not need to use to change the font for the last paragraph
612 LyXFont const outerfont(outerFont(pit, paragraphs));
616 ? pit->getLayoutFont(bparams, outerfont)
617 : pit->getFont(bparams, pit->size() - 1, outerfont));
619 bool is_command = style->isCommand();
621 if (style->resfont.size() != font.size()
622 && boost::next(pit) != const_cast<ParagraphList&>(paragraphs).end()
626 os << "\\" << font.latexSize() << " \\par}";
627 } else if (need_par) {
629 } else if (is_command)
632 switch (style->latextype) {
633 case LATEX_ITEM_ENVIRONMENT:
634 case LATEX_LIST_ENVIRONMENT:
635 if (boost::next(pit) != const_cast<ParagraphList&>(paragraphs).end()
636 && (pit->params().depth() < boost::next(pit)->params().depth())) {
641 case LATEX_ENVIRONMENT: {
642 // if its the last paragraph of the current environment
643 // skip it otherwise fall through
644 ParagraphList::iterator next = boost::next(pit);
646 if (next != const_cast<ParagraphList&>(paragraphs).end()
647 && (next->layout() != pit->layout()
648 || next->params().depth() != pit->params().depth()))
652 // fall through possible
654 // we don't need it for the last paragraph!!!
655 if (boost::next(pit) != const_cast<ParagraphList&>(paragraphs).end()) {
661 if (in == 0 || !in->forceDefaultParagraphs(in)) {
662 further_blank_line = false;
663 if (pit->params().lineBottom()) {
664 os << "\\lyxline{\\" << font.latexSize() << '}';
665 further_blank_line = true;
668 if (pit->params().spaceBottom().kind() != VSpace::NONE) {
669 os << pit->params().spaceBottom().asLatexCommand(bparams);
670 further_blank_line = true;
673 if (pit->params().pagebreakBottom()) {
675 further_blank_line = true;
678 if (further_blank_line) {
683 if (!pit->params().spacing().isDefault()
684 && (boost::next(pit) == const_cast<ParagraphList&>(paragraphs).end()|| !boost::next(pit)->hasSameLayout(*pit))) {
685 os << pit->params().spacing().writeEnvirEnd() << '\n';
690 // we don't need it for the last paragraph!!!
691 if (boost::next(pit) != const_cast<ParagraphList&>(paragraphs).end()) {
695 // Since \selectlanguage write the language to the aux file,
696 // we need to reset the language at the end of footnote or
699 if (language->babel() != doc_language->babel()) {
700 if (lyxrc.language_command_end.empty())
701 os << subst(lyxrc.language_command_begin,
703 doc_language->babel())
706 os << subst(lyxrc.language_command_end,
714 lyxerr[Debug::LATEX] << "TeXOnePar...done " << &*boost::next(pit) << endl;
722 // LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
724 void latexParagraphs(Buffer const & buf,
725 ParagraphList const & paragraphs,
728 LatexRunParams const & runparams,
729 string const & everypar)
731 bool was_title = false;
732 bool already_title = false;
733 LyXTextClass const & tclass = buf.params.getLyXTextClass();
734 ParagraphList::iterator par = const_cast<ParagraphList&>(paragraphs).begin();
735 ParagraphList::iterator endpar = const_cast<ParagraphList&>(paragraphs).end();
738 while (par != endpar) {
739 InsetOld * in = par->inInset();
740 // well we have to check if we are in an inset with unlimited
741 // length (all in one row) if that is true then we don't allow
742 // any special options in the paragraph and also we don't allow
743 // any environment other then "Standard" to be valid!
744 if (in == 0 || !in->forceDefaultParagraphs(in)) {
745 LyXLayout_ptr const & layout = par->layout();
747 if (layout->intitle) {
749 lyxerr <<"Error in latexParagraphs: You"
750 " should not mix title layouts"
751 " with normal ones." << endl;
752 } else if (!was_title) {
754 if (tclass.titletype() == TITLE_ENVIRONMENT) {
756 << tclass.titlename()
761 } else if (was_title && !already_title) {
762 if (tclass.titletype() == TITLE_ENVIRONMENT) {
763 os << "\\end{" << tclass.titlename()
767 os << "\\" << tclass.titlename()
771 already_title = true;
775 if (layout->is_environment) {
776 par = TeXOnePar(buf, paragraphs, par, os, texrow,
777 runparams, everypar);
778 } else if (layout->isEnvironment() ||
779 !par->params().leftIndent().zero())
781 par = TeXEnvironment(buf, paragraphs, par, os,
784 par = TeXOnePar(buf, paragraphs, par, os, texrow,
785 runparams, everypar);
788 par = TeXOnePar(buf, paragraphs, par, os, texrow,
789 runparams, everypar);
792 // It might be that we only have a title in this document
793 if (was_title && !already_title) {
794 if (tclass.titletype() == TITLE_ENVIRONMENT) {
795 os << "\\end{" << tclass.titlename()
799 os << "\\" << tclass.titlename()
809 int readParToken(Buffer & buf, Paragraph & par, LyXLex & lex, string const & token)
812 static Change change;
814 BufferParams const & bp = buf.params;
816 if (token[0] != '\\') {
817 string::const_iterator cit = token.begin();
818 for (; cit != token.end(); ++cit) {
819 par.insertChar(par.size(), (*cit), font, change);
821 } else if (token == "\\begin_layout") {
823 string layoutname = lex.getString();
825 font = LyXFont(LyXFont::ALL_INHERIT, bp.language);
828 LyXTextClass const & tclass = bp.getLyXTextClass();
830 if (layoutname.empty()) {
831 layoutname = tclass.defaultLayoutName();
834 bool hasLayout = tclass.hasLayout(layoutname);
837 lyxerr << "Layout '" << layoutname << "' does not"
838 << " exist in textclass '" << tclass.name()
840 lyxerr << "Trying to use default layout instead."
842 layoutname = tclass.defaultLayoutName();
845 par.layout(bp.getLyXTextClass()[layoutname]);
847 // Test whether the layout is obsolete.
848 LyXLayout_ptr const & layout = par.layout();
849 if (!layout->obsoleted_by().empty())
850 par.layout(bp.getLyXTextClass()[layout->obsoleted_by()]);
852 par.params().read(lex);
854 } else if (token == "\\end_layout") {
855 lyxerr << "Solitary \\end_layout in line " << lex.getLineNo() << "\n"
856 << "Missing \\begin_layout?.\n";
857 } else if (token == "\\end_inset") {
858 lyxerr << "Solitary \\end_inset in line " << lex.getLineNo() << "\n"
859 << "Missing \\begin_inset?.\n";
860 } else if (token == "\\begin_inset") {
861 InsetOld * inset = readInset(lex, buf);
862 par.insertInset(par.size(), inset, font, change);
863 } else if (token == "\\family") {
865 font.setLyXFamily(lex.getString());
866 } else if (token == "\\series") {
868 font.setLyXSeries(lex.getString());
869 } else if (token == "\\shape") {
871 font.setLyXShape(lex.getString());
872 } else if (token == "\\size") {
874 font.setLyXSize(lex.getString());
875 } else if (token == "\\lang") {
877 string const tok = lex.getString();
878 Language const * lang = languages.getLanguage(tok);
880 font.setLanguage(lang);
882 font.setLanguage(bp.language);
883 lex.printError("Unknown language `$$Token'");
885 } else if (token == "\\numeric") {
887 font.setNumber(font.setLyXMisc(lex.getString()));
888 } else if (token == "\\emph") {
890 font.setEmph(font.setLyXMisc(lex.getString()));
891 } else if (token == "\\bar") {
893 string const tok = lex.getString();
896 font.setUnderbar(LyXFont::ON);
897 else if (tok == "no")
898 font.setUnderbar(LyXFont::OFF);
899 else if (tok == "default")
900 font.setUnderbar(LyXFont::INHERIT);
902 lex.printError("Unknown bar font flag "
904 } else if (token == "\\noun") {
906 font.setNoun(font.setLyXMisc(lex.getString()));
907 } else if (token == "\\color") {
909 font.setLyXColor(lex.getString());
910 } else if (token == "\\InsetSpace" || token == "\\SpecialChar") {
912 // Insets don't make sense in a free-spacing context! ---Kayvan
913 if (par.isFreeSpacing()) {
914 if (token == "\\InsetSpace")
915 par.insertChar(par.size(), ' ', font, change);
916 else if (lex.isOK()) {
918 string const next_token = lex.getString();
919 if (next_token == "\\-")
920 par.insertChar(par.size(), '-', font, change);
922 lex.printError("Token `$$Token' "
924 "paragraph layout!");
928 InsetOld * inset = 0;
929 if (token == "\\SpecialChar" )
930 inset = new InsetSpecialChar;
932 inset = new InsetSpace;
933 inset->read(buf, lex);
934 par.insertInset(par.size(), inset, font, change);
936 } else if (token == "\\i") {
937 InsetOld * inset = new InsetLatexAccent;
938 inset->read(buf, lex);
939 par.insertInset(par.size(), inset, font, change);
940 } else if (token == "\\backslash") {
941 par.insertChar(par.size(), '\\', font, change);
942 } else if (token == "\\newline") {
943 InsetOld * inset = new InsetNewline;
944 inset->read(buf, lex);
945 par.insertInset(par.size(), inset, font, change);
946 } else if (token == "\\LyXTable") {
947 InsetOld * inset = new InsetTabular(buf);
948 inset->read(buf, lex);
949 par.insertInset(par.size(), inset, font, change);
950 } else if (token == "\\bibitem") {
951 InsetCommandParams p("bibitem", "dummy");
952 InsetBibitem * inset = new InsetBibitem(p);
953 inset->read(buf, lex);
954 par.insertInset(par.size(), inset, font, change);
955 } else if (token == "\\hfill") {
956 par.insertInset(par.size(), new InsetHFill, font, change);
957 } else if (token == "\\change_unchanged") {
958 // Hack ! Needed for empty paragraphs :/
959 // FIXME: is it still ??
962 change = Change(Change::UNCHANGED);
963 } else if (token == "\\change_inserted") {
965 istringstream is(STRCONV(lex.getString()));
969 change = Change(Change::INSERTED, bp.author_map[aid], ct);
970 } else if (token == "\\change_deleted") {
972 istringstream is(STRCONV(lex.getString()));
976 change = Change(Change::DELETED, bp.author_map[aid], ct);
979 string const s = bformat(_("Unknown token: %1$s %2$s\n"),
980 token, lex.getString());
982 buf.error(ErrorItem(_("Unknown token"), s,
983 par.id(), 0, par.size()));
992 int readParagraph(Buffer & buf, Paragraph & par, LyXLex & lex)
997 string token = lex.getString();
1001 unknown += readParToken(buf, par, lex, token);
1004 token = lex.getString();
1009 if (token == "\\end_layout") {
1010 //Ok, paragraph finished
1014 lyxerr[Debug::PARSER] << "Handling paragraph token: `"
1015 << token << '\'' << endl;
1016 if (token == "\\begin_layout" || token == "\\end_document"
1017 || token == "\\end_inset" || token == "\\begin_deeper"
1018 || token == "\\end_deeper") {
1019 lex.pushToken(token);
1020 lyxerr << "Paragraph ended in line "
1021 << lex.getLineNo() << "\n"
1022 << "Missing \\end_layout.\n";
1031 LyXFont const outerFont(ParagraphList::iterator pit,
1032 ParagraphList const & plist)
1034 Paragraph::depth_type par_depth = pit->getDepth();
1035 LyXFont tmpfont(LyXFont::ALL_INHERIT);
1037 // Resolve against environment font information
1038 while (pit != const_cast<ParagraphList&>(plist).end() &&
1039 par_depth && !tmpfont.resolved()) {
1040 pit = outerHook(pit, plist);
1041 if (pit != const_cast<ParagraphList&>(plist).end()) {
1042 tmpfont.realize(pit->layout()->font);
1043 par_depth = pit->getDepth();
1051 ParagraphList::iterator outerPar(Buffer const & buf, InsetOld const * inset)
1053 ParIterator pit = const_cast<Buffer &>(buf).par_iterator_begin();
1054 ParIterator end = const_cast<Buffer &>(buf).par_iterator_end();
1055 for ( ; pit != end; ++pit) {
1057 ParagraphList * plist;
1058 // the second '=' below is intentional
1059 for (int i = 0; (plist = inset->getParagraphs(i)); ++i)
1060 if (plist == &pit.plist())
1061 return pit.outerPar();
1063 InsetList::iterator ii = pit->insetlist.begin();
1064 InsetList::iterator iend = pit->insetlist.end();
1065 for ( ; ii != iend; ++ii)
1066 if (ii->inset == inset)
1067 return pit.outerPar();
1069 lyxerr << "outerPar: should not happen" << endl;
1071 return const_cast<Buffer &>(buf).paragraphs.end(); // shut up compiler
1075 Paragraph const & ownerPar(Buffer const & buf, InsetOld const * inset)
1077 ParConstIterator pit = buf.par_iterator_begin();
1078 ParConstIterator end = buf.par_iterator_end();
1079 for ( ; pit != end; ++pit) {
1080 ParagraphList * plist;
1081 // the second '=' below is intentional
1082 for (int i = 0; (plist = inset->getParagraphs(i)); ++i)
1083 if (plist == &pit.plist())
1086 InsetList::const_iterator ii = pit->insetlist.begin();
1087 InsetList::const_iterator iend = pit->insetlist.end();
1088 for ( ; ii != iend; ++ii)
1089 if (ii->inset == inset)
1092 lyxerr << "ownerPar: should not happen" << endl;
1094 return buf.paragraphs.front(); // shut up compiler