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"
18 #include "iterators.h"
25 #include "support/lstrings.h"
26 #include "support/LAssert.h"
28 #include "insets/insetoptarg.h"
29 #include "insets/insetbibitem.h"
30 #include "insets/insetspace.h"
31 #include "insets/insetspecialchar.h"
32 #include "insets/insetlatexaccent.h"
33 #include "insets/insettabular.h"
34 #include "insets/insethfill.h"
35 #include "insets/insetnewline.h"
37 extern string bibitemWidest(Buffer const &);
39 using namespace lyx::support;
42 //using lyx::layout_type;
49 bool moveItem(Paragraph & from, Paragraph & to,
50 BufferParams const & params, pos_type i, pos_type j)
52 char const tmpchar = from.getChar(i);
53 LyXFont tmpfont = from.getFontSettings(params, i);
55 if (tmpchar == Paragraph::META_INSET) {
56 InsetOld * tmpinset = 0;
57 if (from.getInset(i)) {
58 // the inset is not in a paragraph anymore
59 tmpinset = from.insetlist.release(i);
62 if (!to.insetAllowed(tmpinset->lyxCode()))
64 to.insertInset(j, tmpinset, tmpfont);
66 if (!to.checkInsertChar(tmpfont))
68 to.insertChar(j, tmpchar, tmpfont);
76 void breakParagraph(BufferParams const & bparams,
77 ParagraphList & paragraphs,
78 ParagraphList::iterator par,
82 // create a new paragraph, and insert into the list
83 ParagraphList::iterator tmp = paragraphs.insert(boost::next(par),
86 // without doing that we get a crash when typing <Return> at the
88 tmp->layout(bparams.getLyXTextClass().defaultLayout());
89 // remember to set the inset_owner
90 tmp->setInsetOwner(par->inInset());
92 if (bparams.tracking_changes)
95 // this is an idea for a more userfriendly layout handling, I will
96 // see what the users say
98 // layout stays the same with latex-environments
100 tmp->layout(par->layout());
101 tmp->setLabelWidthString(par->params().labelWidthString());
104 bool const isempty = (par->allowEmpty() && par->empty());
106 if (!isempty && (par->size() > pos || par->empty() || flag == 2)) {
107 tmp->layout(par->layout());
108 tmp->params().align(par->params().align());
109 tmp->setLabelWidthString(par->params().labelWidthString());
111 tmp->params().lineBottom(par->params().lineBottom());
112 par->params().lineBottom(false);
113 tmp->params().pagebreakBottom(par->params().pagebreakBottom());
114 par->params().pagebreakBottom(false);
115 tmp->params().spaceBottom(par->params().spaceBottom());
116 par->params().spaceBottom(VSpace(VSpace::NONE));
118 tmp->params().depth(par->params().depth());
119 tmp->params().noindent(par->params().noindent());
121 // copy everything behind the break-position
122 // to the new paragraph
125 #warning this seems wrong
127 /* FIXME: if !keepempty, empty() == true, then we reach
128 * here with size() == 0. So pos_end becomes - 1. Why
129 * doesn't this cause problems ???
131 pos_type pos_end = par->size() - 1;
135 for (; i <= pos_end; ++i) {
136 Change::Type change = par->lookupChange(i);
137 if (moveItem(*par, *tmp, bparams, i, j - pos)) {
138 tmp->setChange(j - pos, change);
143 for (i = pos_end; i >= pos; --i)
150 tmp->params().lineTop(par->params().lineTop());
151 tmp->params().pagebreakTop(par->params().pagebreakTop());
152 tmp->params().spaceTop(par->params().spaceTop());
153 par->params().clear();
155 par->layout(bparams.getLyXTextClass().defaultLayout());
157 // layout stays the same with latex-environments
159 par->layout(tmp->layout());
160 par->setLabelWidthString(tmp->params().labelWidthString());
161 par->params().depth(tmp->params().depth());
164 // subtle, but needed to get empty pars working right
165 if (bparams.tracking_changes) {
168 } else if (!tmp->size()) {
175 void breakParagraphConservative(BufferParams const & bparams,
176 ParagraphList & paragraphs,
177 ParagraphList::iterator par,
180 // create a new paragraph
181 ParagraphList::iterator tmp = paragraphs.insert(boost::next(par),
183 tmp->makeSameLayout(*par);
185 // When can pos > size()?
186 // I guess pos == size() is possible.
187 if (par->size() > pos) {
188 // copy everything behind the break-position to the new
190 pos_type pos_end = par->size() - 1;
192 for (pos_type i = pos, j = pos; i <= pos_end; ++i)
193 if (moveItem(*par, *tmp, bparams, i, j - pos))
196 for (pos_type k = pos_end; k >= pos; --k)
202 void mergeParagraph(BufferParams const & bparams,
203 ParagraphList & paragraphs,
204 ParagraphList::iterator par)
206 ParagraphList::iterator the_next = boost::next(par);
208 // first the DTP-stuff
209 par->params().lineBottom(the_next->params().lineBottom());
210 par->params().spaceBottom(the_next->params().spaceBottom());
211 par->params().pagebreakBottom(the_next->params().pagebreakBottom());
213 pos_type pos_end = the_next->size() - 1;
214 pos_type pos_insert = par->size();
216 // ok, now copy the paragraph
217 for (pos_type i = 0, j = 0; i <= pos_end; ++i)
218 if (moveItem(*the_next, *par, bparams, i, pos_insert + j))
221 paragraphs.erase(the_next);
225 ParagraphList::iterator depthHook(ParagraphList::iterator pit,
226 ParagraphList const & plist,
227 Paragraph::depth_type depth)
229 ParagraphList::iterator newpit = pit;
230 ParagraphList::iterator beg = const_cast<ParagraphList&>(plist).begin();
235 while (newpit != beg && newpit->getDepth() > depth) {
239 if (newpit->getDepth() > depth)
246 ParagraphList::iterator outerHook(ParagraphList::iterator pit,
247 ParagraphList const & plist)
249 if (!pit->getDepth())
250 return const_cast<ParagraphList&>(plist).end();
251 return depthHook(pit, plist,
252 Paragraph::depth_type(pit->getDepth() - 1));
256 bool isFirstInSequence(ParagraphList::iterator pit,
257 ParagraphList const & plist)
259 ParagraphList::iterator dhook = depthHook(pit, plist, pit->getDepth());
261 || dhook->layout() != pit->layout()
262 || dhook->getDepth() != pit->getDepth());
266 int getEndLabel(ParagraphList::iterator p, ParagraphList const & plist)
268 ParagraphList::iterator pit = p;
269 Paragraph::depth_type par_depth = p->getDepth();
270 while (pit != const_cast<ParagraphList&>(plist).end()) {
271 LyXLayout_ptr const & layout = pit->layout();
272 int const endlabeltype = layout->endlabeltype;
274 if (endlabeltype != END_LABEL_NO_LABEL) {
275 if (boost::next(p) == const_cast<ParagraphList&>(plist).end())
278 Paragraph::depth_type const next_depth = boost::next(p)->getDepth();
279 if (par_depth > next_depth ||
280 (par_depth == next_depth &&
281 layout != boost::next(p)->layout()))
287 pit = outerHook(pit, plist);
288 if (pit != const_cast<ParagraphList&>(plist).end())
289 par_depth = pit->getDepth();
291 return END_LABEL_NO_LABEL;
297 ParagraphList::iterator
298 TeXEnvironment(Buffer const & buf,
299 ParagraphList const & paragraphs,
300 ParagraphList::iterator pit,
301 ostream & os, TexRow & texrow,
302 LatexRunParams const & runparams);
304 ParagraphList::iterator
305 TeXOnePar(Buffer const & buf,
306 ParagraphList const & paragraphs,
307 ParagraphList::iterator pit,
308 ostream & os, TexRow & texrow,
309 LatexRunParams const & runparams,
310 string const & everypar = string());
313 ParagraphList::iterator
314 TeXDeeper(Buffer const & buf,
315 ParagraphList const & paragraphs,
316 ParagraphList::iterator pit,
317 ostream & os, TexRow & texrow,
318 LatexRunParams const & runparams)
320 lyxerr[Debug::LATEX] << "TeXDeeper... " << &*pit << endl;
321 ParagraphList::iterator par = pit;
323 while (par != const_cast<ParagraphList&>(paragraphs).end() &&
324 par->params().depth() == pit->params().depth()) {
325 if (par->layout()->isEnvironment()) {
326 par = TeXEnvironment(buf, paragraphs, par,
327 os, texrow, runparams);
329 par = TeXOnePar(buf, paragraphs, par,
330 os, texrow, runparams);
333 lyxerr[Debug::LATEX] << "TeXDeeper...done " << &*par << endl;
339 ParagraphList::iterator
340 TeXEnvironment(Buffer const & buf,
341 ParagraphList const & paragraphs,
342 ParagraphList::iterator pit,
343 ostream & os, TexRow & texrow,
344 LatexRunParams const & runparams)
346 lyxerr[Debug::LATEX] << "TeXEnvironment... " << &*pit << endl;
348 BufferParams const & bparams = buf.params;
350 LyXLayout_ptr const & style = pit->layout();
352 Language const * language = pit->getParLanguage(bparams);
353 Language const * doc_language = bparams.language;
354 Language const * previous_language =
355 (pit != const_cast<ParagraphList&>(paragraphs).begin())
356 ? boost::prior(pit)->getParLanguage(bparams)
358 if (language->babel() != previous_language->babel()) {
360 if (!lyxrc.language_command_end.empty() &&
361 previous_language->babel() != doc_language->babel()) {
362 os << subst(lyxrc.language_command_end, "$$lang",
363 previous_language->babel())
368 if (lyxrc.language_command_end.empty() ||
369 language->babel() != doc_language->babel()) {
370 os << subst(lyxrc.language_command_begin, "$$lang",
377 bool leftindent_open = false;
378 if (!pit->params().leftIndent().zero()) {
379 os << "\\begin{LyXParagraphLeftIndent}{" <<
380 pit->params().leftIndent().asLatexString() << "}\n";
382 leftindent_open = true;
385 if (style->isEnvironment()) {
386 if (style->latextype == LATEX_LIST_ENVIRONMENT) {
387 os << "\\begin{" << style->latexname() << "}{"
388 << pit->params().labelWidthString() << "}\n";
389 } else if (style->labeltype == LABEL_BIBLIO) {
391 os << "\\begin{" << style->latexname() << "}{"
392 << bibitemWidest(buf)
394 } else if (style->latextype == LATEX_ITEM_ENVIRONMENT) {
395 os << "\\begin{" << style->latexname() << '}'
396 << style->latexparam() << '\n';
398 os << "\\begin{" << style->latexname() << '}'
399 << style->latexparam() << '\n';
402 ParagraphList::iterator par = pit;
404 par = TeXOnePar(buf, paragraphs, par, os, texrow, runparams);
406 if (par != const_cast<ParagraphList&>(paragraphs).end() && par->params().depth() > pit->params().depth()) {
407 if (par->layout()->isParagraph()) {
410 // How to handle this? (Lgb)
411 //&& !suffixIs(os, "\n\n")
413 // There should be at least one '\n' already
414 // but we need there to be two for Standard
415 // paragraphs that are depth-increment'ed to be
416 // output correctly. However, tables can
417 // also be paragraphs so don't adjust them.
420 // Will it ever harm to have one '\n' too
421 // many? i.e. that we sometimes will have
422 // three in a row. (Lgb)
426 par = TeXDeeper(buf, paragraphs, par, os, texrow,
429 } while (par != const_cast<ParagraphList&>(paragraphs).end()
430 && par->layout() == pit->layout()
431 && par->params().depth() == pit->params().depth()
432 && par->params().leftIndent() == pit->params().leftIndent());
434 if (style->isEnvironment()) {
435 os << "\\end{" << style->latexname() << "}\n";
439 if (leftindent_open) {
440 os << "\\end{LyXParagraphLeftIndent}\n";
444 lyxerr[Debug::LATEX] << "TeXEnvironment...done " << &*par << endl;
445 return par; // ale970302
449 InsetOptArg * optArgInset(Paragraph const & par)
452 InsetList::const_iterator it = par.insetlist.begin();
453 InsetList::const_iterator end = par.insetlist.end();
454 for (; it != end; ++it) {
455 InsetOld * ins = it->inset;
456 if (ins->lyxCode() == InsetOld::OPTARG_CODE) {
457 return static_cast<InsetOptArg *>(ins);
464 ParagraphList::iterator
465 TeXOnePar(Buffer const & buf,
466 ParagraphList const & paragraphs,
467 ParagraphList::iterator pit,
468 ostream & os, TexRow & texrow,
469 LatexRunParams const & runparams,
470 string const & everypar)
472 lyxerr[Debug::LATEX] << "TeXOnePar... " << &*pit << " '"
473 << everypar << "'" << endl;
474 BufferParams const & bparams = buf.params;
476 InsetOld const * in = pit->inInset();
477 bool further_blank_line = false;
480 // well we have to check if we are in an inset with unlimited
481 // length (all in one row) if that is true then we don't allow
482 // any special options in the paragraph and also we don't allow
483 // any environment other then "Standard" to be valid!
484 if (in == 0 || !in->forceDefaultParagraphs(in)) {
485 style = pit->layout();
487 if (pit->params().startOfAppendix()) {
488 os << "\\appendix\n";
492 if (!pit->params().spacing().isDefault()
493 && (pit == const_cast<ParagraphList&>(paragraphs).begin() || !boost::prior(pit)->hasSameLayout(*pit))) {
494 os << pit->params().spacing().writeEnvirBegin() << '\n';
498 if (style->isCommand()) {
503 if (pit->params().pagebreakTop()) {
505 further_blank_line = true;
507 if (pit->params().spaceTop().kind() != VSpace::NONE) {
508 os << pit->params().spaceTop().asLatexCommand(bparams);
509 further_blank_line = true;
512 if (pit->params().lineTop()) {
514 << pit->getFont(bparams, 0, outerFont(pit, paragraphs)).latexSize()
516 << "\\vspace{-1\\parskip}";
517 further_blank_line = true;
520 if (further_blank_line) {
525 style = bparams.getLyXTextClass().defaultLayout();
528 Language const * language = pit->getParLanguage(bparams);
529 Language const * doc_language = bparams.language;
530 Language const * previous_language =
531 (pit != const_cast<ParagraphList&>(paragraphs).begin())
532 ? boost::prior(pit)->getParLanguage(bparams)
535 if (language->babel() != previous_language->babel()
536 // check if we already put language command in TeXEnvironment()
537 && !(style->isEnvironment()
538 && (pit == const_cast<ParagraphList&>(paragraphs).begin() ||
539 (boost::prior(pit)->layout() != pit->layout() &&
540 boost::prior(pit)->getDepth() <= pit->getDepth())
541 || boost::prior(pit)->getDepth() < pit->getDepth())))
543 if (!lyxrc.language_command_end.empty() &&
544 previous_language->babel() != doc_language->babel())
546 os << subst(lyxrc.language_command_end, "$$lang",
547 previous_language->babel())
552 if (lyxrc.language_command_end.empty() ||
553 language->babel() != doc_language->babel())
555 os << subst(lyxrc.language_command_begin, "$$lang",
562 if (bparams.inputenc == "auto" &&
563 language->encoding() != previous_language->encoding()) {
564 os << "\\inputencoding{"
565 << language->encoding()->LatexName()
570 switch (style->latextype) {
572 os << '\\' << style->latexname();
574 // Separate handling of optional argument inset.
575 if (style->optionalargs == 1) {
576 InsetOptArg * it = optArgInset(*pit);
578 it->latexOptional(buf, os, runparams);
581 os << style->latexparam();
583 case LATEX_ITEM_ENVIRONMENT:
584 case LATEX_LIST_ENVIRONMENT:
587 case LATEX_BIB_ENVIRONMENT:
588 // ignore this, the inset will write itself
595 bool need_par = pit->simpleTeXOnePar(buf, bparams,
596 outerFont(pit, paragraphs),
597 os, texrow, runparams);
599 // Make sure that \\par is done with the font of the last
600 // character if this has another size as the default.
601 // This is necessary because LaTeX (and LyX on the screen)
602 // calculates the space between the baselines according
603 // to this font. (Matthias)
605 // Is this really needed ? (Dekel)
606 // We do not need to use to change the font for the last paragraph
608 LyXFont const outerfont(outerFont(pit, paragraphs));
612 ? pit->getLayoutFont(bparams, outerfont)
613 : pit->getFont(bparams, pit->size() - 1, outerfont));
615 bool is_command = style->isCommand();
617 if (style->resfont.size() != font.size()
618 && boost::next(pit) != const_cast<ParagraphList&>(paragraphs).end()
622 os << "\\" << font.latexSize() << " \\par}";
623 } else if (need_par) {
625 } else if (is_command)
628 switch (style->latextype) {
629 case LATEX_ITEM_ENVIRONMENT:
630 case LATEX_LIST_ENVIRONMENT:
631 if (boost::next(pit) != const_cast<ParagraphList&>(paragraphs).end()
632 && (pit->params().depth() < boost::next(pit)->params().depth())) {
637 case LATEX_ENVIRONMENT: {
638 // if its the last paragraph of the current environment
639 // skip it otherwise fall through
640 ParagraphList::iterator next = boost::next(pit);
642 if (next != const_cast<ParagraphList&>(paragraphs).end()
643 && (next->layout() != pit->layout()
644 || next->params().depth() != pit->params().depth()))
648 // fall through possible
650 // we don't need it for the last paragraph!!!
651 if (boost::next(pit) != const_cast<ParagraphList&>(paragraphs).end()) {
657 if (in == 0 || !in->forceDefaultParagraphs(in)) {
658 further_blank_line = false;
659 if (pit->params().lineBottom()) {
660 os << "\\lyxline{\\" << font.latexSize() << '}';
661 further_blank_line = true;
664 if (pit->params().spaceBottom().kind() != VSpace::NONE) {
665 os << pit->params().spaceBottom().asLatexCommand(bparams);
666 further_blank_line = true;
669 if (pit->params().pagebreakBottom()) {
671 further_blank_line = true;
674 if (further_blank_line) {
679 if (!pit->params().spacing().isDefault()
680 && (boost::next(pit) == const_cast<ParagraphList&>(paragraphs).end()|| !boost::next(pit)->hasSameLayout(*pit))) {
681 os << pit->params().spacing().writeEnvirEnd() << '\n';
686 // we don't need it for the last paragraph!!!
687 if (boost::next(pit) != const_cast<ParagraphList&>(paragraphs).end()) {
691 // Since \selectlanguage write the language to the aux file,
692 // we need to reset the language at the end of footnote or
695 if (language->babel() != doc_language->babel()) {
696 if (lyxrc.language_command_end.empty())
697 os << subst(lyxrc.language_command_begin,
699 doc_language->babel())
702 os << subst(lyxrc.language_command_end,
710 lyxerr[Debug::LATEX] << "TeXOnePar...done " << &*boost::next(pit) << endl;
718 // LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
720 void latexParagraphs(Buffer const & buf,
721 ParagraphList const & paragraphs,
724 LatexRunParams const & runparams,
725 string const & everypar)
727 bool was_title = false;
728 bool already_title = false;
729 LyXTextClass const & tclass = buf.params.getLyXTextClass();
730 ParagraphList::iterator par = const_cast<ParagraphList&>(paragraphs).begin();
731 ParagraphList::iterator endpar = const_cast<ParagraphList&>(paragraphs).end();
734 while (par != endpar) {
735 InsetOld * in = par->inInset();
736 // well we have to check if we are in an inset with unlimited
737 // length (all in one row) if that is true then we don't allow
738 // any special options in the paragraph and also we don't allow
739 // any environment other then "Standard" to be valid!
740 if (in == 0 || !in->forceDefaultParagraphs(in)) {
741 LyXLayout_ptr const & layout = par->layout();
743 if (layout->intitle) {
745 lyxerr <<"Error in latexParagraphs: You"
746 " should not mix title layouts"
747 " with normal ones." << endl;
748 } else if (!was_title) {
750 if (tclass.titletype() == TITLE_ENVIRONMENT) {
752 << tclass.titlename()
757 } else if (was_title && !already_title) {
758 if (tclass.titletype() == TITLE_ENVIRONMENT) {
759 os << "\\end{" << tclass.titlename()
763 os << "\\" << tclass.titlename()
767 already_title = true;
771 if (layout->is_environment) {
772 par = TeXOnePar(buf, paragraphs, par, os, texrow,
773 runparams, everypar);
774 } else if (layout->isEnvironment() ||
775 !par->params().leftIndent().zero())
777 par = TeXEnvironment(buf, paragraphs, par, os,
780 par = TeXOnePar(buf, paragraphs, par, os, texrow,
781 runparams, everypar);
784 par = TeXOnePar(buf, paragraphs, par, os, texrow,
785 runparams, everypar);
788 // It might be that we only have a title in this document
789 if (was_title && !already_title) {
790 if (tclass.titletype() == TITLE_ENVIRONMENT) {
791 os << "\\end{" << tclass.titlename()
795 os << "\\" << tclass.titlename()
805 int readParToken(Buffer & buf, Paragraph & par, LyXLex & lex, string const & token)
808 static Change change;
810 BufferParams const & bp = buf.params;
812 if (token[0] != '\\') {
813 string::const_iterator cit = token.begin();
814 for (; cit != token.end(); ++cit) {
815 par.insertChar(par.size(), (*cit), font, change);
817 } else if (token == "\\begin_layout") {
819 string layoutname = lex.getString();
821 font = LyXFont(LyXFont::ALL_INHERIT, bp.language);
824 LyXTextClass const & tclass = bp.getLyXTextClass();
826 if (layoutname.empty()) {
827 layoutname = tclass.defaultLayoutName();
830 bool hasLayout = tclass.hasLayout(layoutname);
833 lyxerr << "Layout '" << layoutname << "' does not"
834 << " exist in textclass '" << tclass.name()
836 lyxerr << "Trying to use default layout instead."
838 layoutname = tclass.defaultLayoutName();
841 par.layout(bp.getLyXTextClass()[layoutname]);
843 // Test whether the layout is obsolete.
844 LyXLayout_ptr const & layout = par.layout();
845 if (!layout->obsoleted_by().empty())
846 par.layout(bp.getLyXTextClass()[layout->obsoleted_by()]);
848 par.params().read(lex);
850 } else if (token == "\\end_layout") {
851 lyxerr << "Solitary \\end_layout in line " << lex.getLineNo() << "\n"
852 << "Missing \\begin_layout?.\n";
853 } else if (token == "\\end_inset") {
854 lyxerr << "Solitary \\end_inset in line " << lex.getLineNo() << "\n"
855 << "Missing \\begin_inset?.\n";
856 } else if (token == "\\begin_inset") {
857 InsetOld * inset = readInset(lex, buf);
858 par.insertInset(par.size(), inset, font, change);
859 } else if (token == "\\family") {
861 font.setLyXFamily(lex.getString());
862 } else if (token == "\\series") {
864 font.setLyXSeries(lex.getString());
865 } else if (token == "\\shape") {
867 font.setLyXShape(lex.getString());
868 } else if (token == "\\size") {
870 font.setLyXSize(lex.getString());
871 } else if (token == "\\lang") {
873 string const tok = lex.getString();
874 Language const * lang = languages.getLanguage(tok);
876 font.setLanguage(lang);
878 font.setLanguage(bp.language);
879 lex.printError("Unknown language `$$Token'");
881 } else if (token == "\\numeric") {
883 font.setNumber(font.setLyXMisc(lex.getString()));
884 } else if (token == "\\emph") {
886 font.setEmph(font.setLyXMisc(lex.getString()));
887 } else if (token == "\\bar") {
889 string const tok = lex.getString();
892 font.setUnderbar(LyXFont::ON);
893 else if (tok == "no")
894 font.setUnderbar(LyXFont::OFF);
895 else if (tok == "default")
896 font.setUnderbar(LyXFont::INHERIT);
898 lex.printError("Unknown bar font flag "
900 } else if (token == "\\noun") {
902 font.setNoun(font.setLyXMisc(lex.getString()));
903 } else if (token == "\\color") {
905 font.setLyXColor(lex.getString());
906 } else if (token == "\\InsetSpace" || token == "\\SpecialChar") {
908 // Insets don't make sense in a free-spacing context! ---Kayvan
909 if (par.isFreeSpacing()) {
910 if (token == "\\InsetSpace")
911 par.insertChar(par.size(), ' ', font, change);
912 else if (lex.isOK()) {
914 string const next_token = lex.getString();
915 if (next_token == "\\-")
916 par.insertChar(par.size(), '-', font, change);
918 lex.printError("Token `$$Token' "
920 "paragraph layout!");
924 InsetOld * inset = 0;
925 if (token == "\\SpecialChar" )
926 inset = new InsetSpecialChar;
928 inset = new InsetSpace;
929 inset->read(buf, lex);
930 par.insertInset(par.size(), inset, font, change);
932 } else if (token == "\\i") {
933 InsetOld * inset = new InsetLatexAccent;
934 inset->read(buf, lex);
935 par.insertInset(par.size(), inset, font, change);
936 } else if (token == "\\backslash") {
937 par.insertChar(par.size(), '\\', font, change);
938 } else if (token == "\\newline") {
939 InsetOld * inset = new InsetNewline;
940 inset->read(buf, lex);
941 par.insertInset(par.size(), inset, font, change);
942 } else if (token == "\\LyXTable") {
943 InsetOld * inset = new InsetTabular(buf);
944 inset->read(buf, lex);
945 par.insertInset(par.size(), inset, font, change);
946 } else if (token == "\\bibitem") {
947 InsetCommandParams p("bibitem", "dummy");
948 InsetBibitem * inset = new InsetBibitem(p);
949 inset->read(buf, lex);
950 par.insertInset(par.size(), inset, font, change);
951 } else if (token == "\\hfill") {
952 par.insertInset(par.size(), new InsetHFill, 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(STRCONV(lex.getString()));
965 change = Change(Change::INSERTED, bp.author_map[aid], ct);
966 } else if (token == "\\change_deleted") {
968 istringstream is(STRCONV(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 par.id(), 0, par.size()));
988 int readParagraph(Buffer & buf, Paragraph & par, LyXLex & lex)
993 string token = lex.getString();
997 unknown += readParToken(buf, par, lex, token);
1000 token = lex.getString();
1005 if (token == "\\end_layout") {
1006 //Ok, paragraph finished
1010 lyxerr[Debug::PARSER] << "Handling paragraph token: `"
1011 << token << '\'' << endl;
1012 if (token == "\\begin_layout" || token == "\\end_document"
1013 || token == "\\end_inset" || token == "\\begin_deeper"
1014 || token == "\\end_deeper") {
1015 lex.pushToken(token);
1016 lyxerr << "Paragraph ended in line "
1017 << lex.getLineNo() << "\n"
1018 << "Missing \\end_layout.\n";
1027 LyXFont const outerFont(ParagraphList::iterator pit,
1028 ParagraphList const & plist)
1030 Paragraph::depth_type par_depth = pit->getDepth();
1031 LyXFont tmpfont(LyXFont::ALL_INHERIT);
1033 // Resolve against environment font information
1034 while (pit != const_cast<ParagraphList&>(plist).end() &&
1035 par_depth && !tmpfont.resolved()) {
1036 pit = outerHook(pit, plist);
1037 if (pit != const_cast<ParagraphList&>(plist).end()) {
1038 tmpfont.realize(pit->layout()->font);
1039 par_depth = pit->getDepth();
1047 ParagraphList::iterator outerPar(Buffer const & buf, InsetOld const * inset)
1049 ParIterator pit = const_cast<Buffer &>(buf).par_iterator_begin();
1050 ParIterator end = const_cast<Buffer &>(buf).par_iterator_end();
1051 for ( ; pit != end; ++pit) {
1053 ParagraphList * plist;
1054 // the second '=' below is intentional
1055 for (int i = 0; (plist = inset->getParagraphs(i)); ++i)
1056 if (plist == &pit.plist())
1057 return pit.outerPar();
1059 InsetList::iterator ii = pit->insetlist.begin();
1060 InsetList::iterator iend = pit->insetlist.end();
1061 for ( ; ii != iend; ++ii)
1062 if (ii->inset == inset)
1063 return pit.outerPar();
1065 lyxerr << "outerPar: should not happen" << endl;
1067 return const_cast<Buffer &>(buf).paragraphs.end(); // shut up compiler
1071 Paragraph const & ownerPar(Buffer const & buf, InsetOld const * inset)
1073 ParConstIterator pit = buf.par_iterator_begin();
1074 ParConstIterator end = buf.par_iterator_end();
1075 for ( ; pit != end; ++pit) {
1076 ParagraphList * plist;
1077 // the second '=' below is intentional
1078 for (int i = 0; (plist = inset->getParagraphs(i)); ++i)
1079 if (plist == &pit.plist())
1082 InsetList::const_iterator ii = pit->insetlist.begin();
1083 InsetList::const_iterator iend = pit->insetlist.end();
1084 for ( ; ii != iend; ++ii)
1085 if (ii->inset == inset)
1088 lyxerr << "ownerPar: should not happen" << endl;
1090 return buf.paragraphs.front(); // shut up compiler