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"
27 #include "support/lstrings.h"
29 #include "insets/insetoptarg.h"
30 #include "insets/insetcommandparams.h"
31 #include "insets/insetbibitem.h"
32 #include "insets/insetspace.h"
33 #include "insets/insetspecialchar.h"
34 #include "insets/insetlatexaccent.h"
35 #include "insets/insettabular.h"
36 #include "insets/insethfill.h"
37 #include "insets/insetnewline.h"
39 extern string bibitemWidest(Buffer const *);
41 using namespace lyx::support;
44 //using lyx::layout_type;
49 void breakParagraph(BufferParams const & bparams,
50 ParagraphList & paragraphs,
51 ParagraphList::iterator par,
55 // create a new paragraph, and insert into the list
56 ParagraphList::iterator tmp = paragraphs.insert(boost::next(par),
59 // without doing that we get a crash when typing <Return> at the
61 tmp->layout(bparams.getLyXTextClass().defaultLayout());
62 // remember to set the inset_owner
63 tmp->setInsetOwner(par->inInset());
65 if (bparams.tracking_changes)
68 // this is an idea for a more userfriendly layout handling, I will
69 // see what the users say
71 // layout stays the same with latex-environments
73 tmp->layout(par->layout());
74 tmp->setLabelWidthString(par->params().labelWidthString());
77 bool const isempty = (par->allowEmpty() && par->empty());
79 if (!isempty && (par->size() > pos || par->empty() || flag == 2)) {
80 tmp->layout(par->layout());
81 tmp->params().align(par->params().align());
82 tmp->setLabelWidthString(par->params().labelWidthString());
84 tmp->params().lineBottom(par->params().lineBottom());
85 par->params().lineBottom(false);
86 tmp->params().pagebreakBottom(par->params().pagebreakBottom());
87 par->params().pagebreakBottom(false);
88 tmp->params().spaceBottom(par->params().spaceBottom());
89 par->params().spaceBottom(VSpace(VSpace::NONE));
91 tmp->params().depth(par->params().depth());
92 tmp->params().noindent(par->params().noindent());
94 // copy everything behind the break-position
95 // to the new paragraph
98 #warning this seems wrong
100 /* FIXME: if !keepempty, empty() == true, then we reach
101 * here with size() == 0. So pos_end becomes - 1. Why
102 * doesn't this cause problems ???
104 pos_type pos_end = par->size() - 1;
108 for (; i <= pos_end; ++i) {
109 Change::Type change(par->lookupChange(i));
110 par->cutIntoMinibuffer(bparams, i);
111 if (tmp->insertFromMinibuffer(j - pos)) {
112 tmp->setChange(j - pos, change);
116 for (i = pos_end; i >= pos; --i) {
124 tmp->params().lineTop(par->params().lineTop());
125 tmp->params().pagebreakTop(par->params().pagebreakTop());
126 tmp->params().spaceTop(par->params().spaceTop());
127 par->params().clear();
129 par->layout(bparams.getLyXTextClass().defaultLayout());
131 // layout stays the same with latex-environments
133 par->layout(tmp->layout());
134 par->setLabelWidthString(tmp->params().labelWidthString());
135 par->params().depth(tmp->params().depth());
138 // subtle, but needed to get empty pars working right
139 if (bparams.tracking_changes) {
142 } else if (!tmp->size()) {
149 void breakParagraphConservative(BufferParams const & bparams,
150 ParagraphList & paragraphs,
151 ParagraphList::iterator par,
154 // create a new paragraph
155 ParagraphList::iterator tmp = paragraphs.insert(boost::next(par),
157 tmp->makeSameLayout(*par);
159 // When can pos > size()?
160 // I guess pos == size() is possible.
161 if (par->size() > pos) {
162 // copy everything behind the break-position to the new
164 pos_type pos_end = par->size() - 1;
166 for (pos_type i = pos, j = pos; i <= pos_end; ++i) {
167 par->cutIntoMinibuffer(bparams, i);
168 if (tmp->insertFromMinibuffer(j - pos))
172 for (pos_type k = pos_end; k >= pos; --k) {
179 void mergeParagraph(BufferParams const & bparams,
180 ParagraphList & paragraphs,
181 ParagraphList::iterator par)
183 ParagraphList::iterator the_next = boost::next(par);
185 // first the DTP-stuff
186 par->params().lineBottom(the_next->params().lineBottom());
187 par->params().spaceBottom(the_next->params().spaceBottom());
188 par->params().pagebreakBottom(the_next->params().pagebreakBottom());
190 pos_type pos_end = the_next->size() - 1;
191 pos_type pos_insert = par->size();
193 // ok, now copy the paragraph
194 for (pos_type i = 0, j = 0; i <= pos_end; ++i) {
195 the_next->cutIntoMinibuffer(bparams, i);
196 if (par->insertFromMinibuffer(pos_insert + j))
200 paragraphs.erase(the_next);
204 ParagraphList::iterator depthHook(ParagraphList::iterator pit,
205 ParagraphList const & plist,
206 Paragraph::depth_type depth)
208 ParagraphList::iterator newpit = pit;
209 ParagraphList::iterator beg = const_cast<ParagraphList&>(plist).begin();
214 while (newpit != beg && newpit->getDepth() > depth) {
218 if (newpit->getDepth() > depth)
225 ParagraphList::iterator outerHook(ParagraphList::iterator pit,
226 ParagraphList const & plist)
228 if (!pit->getDepth())
229 return const_cast<ParagraphList&>(plist).end();
230 return depthHook(pit, plist,
231 Paragraph::depth_type(pit->getDepth() - 1));
235 bool isFirstInSequence(ParagraphList::iterator pit,
236 ParagraphList const & plist)
238 ParagraphList::iterator dhook = depthHook(pit, plist, pit->getDepth());
240 || dhook->layout() != pit->layout()
241 || dhook->getDepth() != pit->getDepth());
245 int getEndLabel(ParagraphList::iterator p, ParagraphList const & plist)
247 ParagraphList::iterator pit = p;
248 Paragraph::depth_type par_depth = p->getDepth();
249 while (pit != const_cast<ParagraphList&>(plist).end()) {
250 LyXLayout_ptr const & layout = pit->layout();
251 int const endlabeltype = layout->endlabeltype;
253 if (endlabeltype != END_LABEL_NO_LABEL) {
254 if (boost::next(p) == const_cast<ParagraphList&>(plist).end())
257 Paragraph::depth_type const next_depth = boost::next(p)->getDepth();
258 if (par_depth > next_depth ||
259 (par_depth == next_depth &&
260 layout != boost::next(p)->layout()))
266 pit = outerHook(pit, plist);
267 if (pit != const_cast<ParagraphList&>(plist).end())
268 par_depth = pit->getDepth();
270 return END_LABEL_NO_LABEL;
276 ParagraphList::iterator
277 TeXEnvironment(Buffer const * buf,
278 ParagraphList const & paragraphs,
279 ParagraphList::iterator pit,
280 ostream & os, TexRow & texrow,
281 LatexRunParams const & runparams);
283 ParagraphList::iterator
284 TeXOnePar(Buffer const * buf,
285 ParagraphList const & paragraphs,
286 ParagraphList::iterator pit,
287 ostream & os, TexRow & texrow,
288 LatexRunParams const & runparams,
289 string const & everypar = string());
292 ParagraphList::iterator
293 TeXDeeper(Buffer const * buf,
294 ParagraphList const & paragraphs,
295 ParagraphList::iterator pit,
296 ostream & os, TexRow & texrow,
297 LatexRunParams const & runparams)
299 lyxerr[Debug::LATEX] << "TeXDeeper... " << &*pit << endl;
300 ParagraphList::iterator par = pit;
302 while (par != const_cast<ParagraphList&>(paragraphs).end() &&
303 par->params().depth() == pit->params().depth()) {
304 if (par->layout()->isEnvironment()) {
305 par = TeXEnvironment(buf, paragraphs, par,
306 os, texrow, runparams);
308 par = TeXOnePar(buf, paragraphs, par,
309 os, texrow, runparams);
312 lyxerr[Debug::LATEX] << "TeXDeeper...done " << &*par << endl;
318 ParagraphList::iterator
319 TeXEnvironment(Buffer const * buf,
320 ParagraphList const & paragraphs,
321 ParagraphList::iterator pit,
322 ostream & os, TexRow & texrow,
323 LatexRunParams const & runparams)
325 lyxerr[Debug::LATEX] << "TeXEnvironment... " << &*pit << endl;
327 BufferParams const & bparams = buf->params;
329 LyXLayout_ptr const & style = pit->layout();
331 Language const * language = pit->getParLanguage(bparams);
332 Language const * doc_language = bparams.language;
333 Language const * previous_language =
334 (pit != const_cast<ParagraphList&>(paragraphs).begin())
335 ? boost::prior(pit)->getParLanguage(bparams)
337 if (language->babel() != previous_language->babel()) {
339 if (!lyxrc.language_command_end.empty() &&
340 previous_language->babel() != doc_language->babel()) {
341 os << subst(lyxrc.language_command_end, "$$lang",
342 previous_language->babel())
347 if (lyxrc.language_command_end.empty() ||
348 language->babel() != doc_language->babel()) {
349 os << subst(lyxrc.language_command_begin, "$$lang",
356 bool leftindent_open = false;
357 if (!pit->params().leftIndent().zero()) {
358 os << "\\begin{LyXParagraphLeftIndent}{" <<
359 pit->params().leftIndent().asLatexString() << "}\n";
361 leftindent_open = true;
364 if (style->isEnvironment()) {
365 if (style->latextype == LATEX_LIST_ENVIRONMENT) {
366 os << "\\begin{" << style->latexname() << "}{"
367 << pit->params().labelWidthString() << "}\n";
368 } else if (style->labeltype == LABEL_BIBLIO) {
370 os << "\\begin{" << style->latexname() << "}{"
371 << bibitemWidest(buf)
373 } else if (style->latextype == LATEX_ITEM_ENVIRONMENT) {
374 os << "\\begin{" << style->latexname() << '}'
375 << style->latexparam() << '\n';
377 os << "\\begin{" << style->latexname() << '}'
378 << style->latexparam() << '\n';
381 ParagraphList::iterator par = pit;
383 par = TeXOnePar(buf, paragraphs, par, os, texrow, runparams);
385 if (par != const_cast<ParagraphList&>(paragraphs).end() && par->params().depth() > pit->params().depth()) {
386 if (par->layout()->isParagraph()) {
389 // How to handle this? (Lgb)
390 //&& !suffixIs(os, "\n\n")
392 // There should be at least one '\n' already
393 // but we need there to be two for Standard
394 // paragraphs that are depth-increment'ed to be
395 // output correctly. However, tables can
396 // also be paragraphs so don't adjust them.
399 // Will it ever harm to have one '\n' too
400 // many? i.e. that we sometimes will have
401 // three in a row. (Lgb)
405 par = TeXDeeper(buf, paragraphs, par, os, texrow,
408 } while (par != const_cast<ParagraphList&>(paragraphs).end()
409 && par->layout() == pit->layout()
410 && par->params().depth() == pit->params().depth()
411 && par->params().leftIndent() == pit->params().leftIndent());
413 if (style->isEnvironment()) {
414 os << "\\end{" << style->latexname() << "}\n";
418 if (leftindent_open) {
419 os << "\\end{LyXParagraphLeftIndent}\n";
423 lyxerr[Debug::LATEX] << "TeXEnvironment...done " << &*par << endl;
424 return par; // ale970302
428 InsetOptArg * optArgInset(Paragraph const & par)
431 InsetList::const_iterator it = par.insetlist.begin();
432 InsetList::const_iterator end = par.insetlist.end();
433 for (; it != end; ++it) {
434 InsetOld * ins = it->inset;
435 if (ins->lyxCode() == InsetOld::OPTARG_CODE) {
436 return static_cast<InsetOptArg *>(ins);
443 ParagraphList::iterator
444 TeXOnePar(Buffer const * buf,
445 ParagraphList const & paragraphs,
446 ParagraphList::iterator pit,
447 ostream & os, TexRow & texrow,
448 LatexRunParams const & runparams,
449 string const & everypar)
451 lyxerr[Debug::LATEX] << "TeXOnePar... " << &*pit << " '" << everypar
453 BufferParams const & bparams = buf->params;
455 InsetOld const * in = pit->inInset();
456 bool further_blank_line = false;
459 // well we have to check if we are in an inset with unlimited
460 // lenght (all in one row) if that is true then we don't allow
461 // any special options in the paragraph and also we don't allow
462 // any environment other then "Standard" to be valid!
463 if ((in == 0) || !in->forceDefaultParagraphs(in)) {
464 style = pit->layout();
466 if (pit->params().startOfAppendix()) {
467 os << "\\appendix\n";
471 if (!pit->params().spacing().isDefault()
472 && (pit == const_cast<ParagraphList&>(paragraphs).begin() || !boost::prior(pit)->hasSameLayout(*pit))) {
473 os << pit->params().spacing().writeEnvirBegin() << '\n';
477 if (style->isCommand()) {
482 if (pit->params().pagebreakTop()) {
484 further_blank_line = true;
486 if (pit->params().spaceTop().kind() != VSpace::NONE) {
487 os << pit->params().spaceTop().asLatexCommand(bparams);
488 further_blank_line = true;
491 if (pit->params().lineTop()) {
493 << pit->getFont(bparams, 0, outerFont(pit, paragraphs)).latexSize()
495 << "\\vspace{-1\\parskip}";
496 further_blank_line = true;
499 if (further_blank_line) {
504 style = bparams.getLyXTextClass().defaultLayout();
507 Language const * language = pit->getParLanguage(bparams);
508 Language const * doc_language = bparams.language;
509 Language const * previous_language =
510 (pit != const_cast<ParagraphList&>(paragraphs).begin())
511 ? boost::prior(pit)->getParLanguage(bparams)
514 if (language->babel() != previous_language->babel()
515 // check if we already put language command in TeXEnvironment()
516 && !(style->isEnvironment()
517 && (pit == const_cast<ParagraphList&>(paragraphs).begin() ||
518 (boost::prior(pit)->layout() != pit->layout() &&
519 boost::prior(pit)->getDepth() <= pit->getDepth())
520 || boost::prior(pit)->getDepth() < pit->getDepth())))
522 if (!lyxrc.language_command_end.empty() &&
523 previous_language->babel() != doc_language->babel())
525 os << subst(lyxrc.language_command_end, "$$lang",
526 previous_language->babel())
531 if (lyxrc.language_command_end.empty() ||
532 language->babel() != doc_language->babel())
534 os << subst(lyxrc.language_command_begin, "$$lang",
541 if (bparams.inputenc == "auto" &&
542 language->encoding() != previous_language->encoding()) {
543 os << "\\inputencoding{"
544 << language->encoding()->LatexName()
549 switch (style->latextype) {
551 os << '\\' << style->latexname();
553 // Separate handling of optional argument inset.
554 if (style->optionalargs == 1) {
555 InsetOptArg * it = optArgInset(*pit);
557 it->latexOptional(buf, os, runparams);
560 os << style->latexparam();
562 case LATEX_ITEM_ENVIRONMENT:
563 case LATEX_LIST_ENVIRONMENT:
566 case LATEX_BIB_ENVIRONMENT:
567 // ignore this, the inset will write itself
574 bool need_par = pit->simpleTeXOnePar(buf, bparams,
575 outerFont(pit, paragraphs),
576 os, texrow, runparams);
578 // Make sure that \\par is done with the font of the last
579 // character if this has another size as the default.
580 // This is necessary because LaTeX (and LyX on the screen)
581 // calculates the space between the baselines according
582 // to this font. (Matthias)
584 // Is this really needed ? (Dekel)
585 // We do not need to use to change the font for the last paragraph
587 LyXFont const outerfont(outerFont(pit, paragraphs));
591 ? pit->getLayoutFont(bparams, outerfont)
592 : pit->getFont(bparams, pit->size() - 1, outerfont));
594 bool is_command = style->isCommand();
596 if (style->resfont.size() != font.size()
597 && boost::next(pit) != const_cast<ParagraphList&>(paragraphs).end()
601 os << "\\" << font.latexSize() << " \\par}";
602 } else if (need_par) {
604 } else if (is_command)
607 switch (style->latextype) {
608 case LATEX_ITEM_ENVIRONMENT:
609 case LATEX_LIST_ENVIRONMENT:
610 if (boost::next(pit) != const_cast<ParagraphList&>(paragraphs).end()
611 && (pit->params().depth() < boost::next(pit)->params().depth())) {
616 case LATEX_ENVIRONMENT: {
617 // if its the last paragraph of the current environment
618 // skip it otherwise fall through
619 ParagraphList::iterator next = boost::next(pit);
621 if (next != const_cast<ParagraphList&>(paragraphs).end()
622 && (next->layout() != pit->layout()
623 || next->params().depth() != pit->params().depth()))
627 // fall through possible
629 // we don't need it for the last paragraph!!!
630 if (boost::next(pit) != const_cast<ParagraphList&>(paragraphs).end()) {
636 if ((in == 0) || !in->forceDefaultParagraphs(in)) {
637 further_blank_line = false;
638 if (pit->params().lineBottom()) {
639 os << "\\lyxline{\\" << font.latexSize() << '}';
640 further_blank_line = true;
643 if (pit->params().spaceBottom().kind() != VSpace::NONE) {
644 os << pit->params().spaceBottom().asLatexCommand(bparams);
645 further_blank_line = true;
648 if (pit->params().pagebreakBottom()) {
650 further_blank_line = true;
653 if (further_blank_line) {
658 if (!pit->params().spacing().isDefault()
659 && (boost::next(pit) == const_cast<ParagraphList&>(paragraphs).end()|| !boost::next(pit)->hasSameLayout(*pit))) {
660 os << pit->params().spacing().writeEnvirEnd() << '\n';
665 // we don't need it for the last paragraph!!!
666 if (boost::next(pit) != const_cast<ParagraphList&>(paragraphs).end()) {
670 // Since \selectlanguage write the language to the aux file,
671 // we need to reset the language at the end of footnote or
674 if (language->babel() != doc_language->babel()) {
675 if (lyxrc.language_command_end.empty())
676 os << subst(lyxrc.language_command_begin,
678 doc_language->babel())
681 os << subst(lyxrc.language_command_end,
689 lyxerr[Debug::LATEX] << "TeXOnePar...done " << &*boost::next(pit) << endl;
697 // LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
699 void latexParagraphs(Buffer const * buf,
700 ParagraphList const & paragraphs,
703 LatexRunParams const & runparams,
704 string const & everypar)
706 bool was_title = false;
707 bool already_title = false;
708 LyXTextClass const & tclass = buf->params.getLyXTextClass();
709 ParagraphList::iterator par = const_cast<ParagraphList&>(paragraphs).begin();
710 ParagraphList::iterator endpar = const_cast<ParagraphList&>(paragraphs).end();
713 while (par != endpar) {
714 InsetOld * in = par->inInset();
715 // well we have to check if we are in an inset with unlimited
716 // length (all in one row) if that is true then we don't allow
717 // any special options in the paragraph and also we don't allow
718 // any environment other then "Standard" to be valid!
719 if ((in == 0) || !in->forceDefaultParagraphs(in)) {
720 LyXLayout_ptr const & layout = par->layout();
722 if (layout->intitle) {
724 lyxerr <<"Error in latexParagraphs: You"
725 " should not mix title layouts"
726 " with normal ones." << endl;
727 } else if (!was_title) {
729 if (tclass.titletype() == TITLE_ENVIRONMENT) {
731 << tclass.titlename()
736 } else if (was_title && !already_title) {
737 if (tclass.titletype() == TITLE_ENVIRONMENT) {
738 os << "\\end{" << tclass.titlename()
742 os << "\\" << tclass.titlename()
746 already_title = true;
750 if (layout->is_environment) {
751 par = TeXOnePar(buf, paragraphs, par, os, texrow,
752 runparams, everypar);
753 } else if (layout->isEnvironment() ||
754 !par->params().leftIndent().zero())
756 par = TeXEnvironment(buf, paragraphs, par, os,
759 par = TeXOnePar(buf, paragraphs, par, os, texrow,
760 runparams, everypar);
763 par = TeXOnePar(buf, paragraphs, par, os, texrow,
764 runparams, everypar);
767 // It might be that we only have a title in this document
768 if (was_title && !already_title) {
769 if (tclass.titletype() == TITLE_ENVIRONMENT) {
770 os << "\\end{" << tclass.titlename()
774 os << "\\" << tclass.titlename()
784 int readParToken(Buffer & buf, Paragraph & par, LyXLex & lex, string const & token)
787 static Change change;
789 BufferParams const & bp = buf.params;
791 if (token[0] != '\\') {
792 string::const_iterator cit = token.begin();
793 for (; cit != token.end(); ++cit) {
794 par.insertChar(par.size(), (*cit), font, change);
796 } else if (token == "\\begin_layout") {
798 string layoutname = lex.getString();
800 font = LyXFont(LyXFont::ALL_INHERIT, bp.language);
803 LyXTextClass const & tclass = bp.getLyXTextClass();
805 if (layoutname.empty()) {
806 layoutname = tclass.defaultLayoutName();
809 bool hasLayout = tclass.hasLayout(layoutname);
812 lyxerr << "Layout '" << layoutname << "' does not"
813 << " exist in textclass '" << tclass.name()
815 lyxerr << "Trying to use default layout instead."
817 layoutname = tclass.defaultLayoutName();
820 par.layout(bp.getLyXTextClass()[layoutname]);
822 // Test whether the layout is obsolete.
823 LyXLayout_ptr const & layout = par.layout();
824 if (!layout->obsoleted_by().empty())
825 par.layout(bp.getLyXTextClass()[layout->obsoleted_by()]);
827 par.params().read(lex);
829 } else if (token == "\\end_layout") {
830 lyxerr << "Solitary \\end_layout in line " << lex.getLineNo() << "\n"
831 << "Missing \\begin_layout?.\n";
832 } else if (token == "\\end_inset") {
833 lyxerr << "Solitary \\end_inset in line " << lex.getLineNo() << "\n"
834 << "Missing \\begin_inset?.\n";
835 } else if (token == "\\begin_inset") {
836 InsetOld * inset = readInset(lex, buf);
837 par.insertInset(par.size(), inset, font, change);
838 } else if (token == "\\family") {
840 font.setLyXFamily(lex.getString());
841 } else if (token == "\\series") {
843 font.setLyXSeries(lex.getString());
844 } else if (token == "\\shape") {
846 font.setLyXShape(lex.getString());
847 } else if (token == "\\size") {
849 font.setLyXSize(lex.getString());
850 } else if (token == "\\lang") {
852 string const tok = lex.getString();
853 Language const * lang = languages.getLanguage(tok);
855 font.setLanguage(lang);
857 font.setLanguage(bp.language);
858 lex.printError("Unknown language `$$Token'");
860 } else if (token == "\\numeric") {
862 font.setNumber(font.setLyXMisc(lex.getString()));
863 } else if (token == "\\emph") {
865 font.setEmph(font.setLyXMisc(lex.getString()));
866 } else if (token == "\\bar") {
868 string const tok = lex.getString();
871 font.setUnderbar(LyXFont::ON);
872 else if (tok == "no")
873 font.setUnderbar(LyXFont::OFF);
874 else if (tok == "default")
875 font.setUnderbar(LyXFont::INHERIT);
877 lex.printError("Unknown bar font flag "
879 } else if (token == "\\noun") {
881 font.setNoun(font.setLyXMisc(lex.getString()));
882 } else if (token == "\\color") {
884 font.setLyXColor(lex.getString());
885 } else if (token == "\\InsetSpace" || token == "\\SpecialChar") {
887 // Insets don't make sense in a free-spacing context! ---Kayvan
888 if (par.isFreeSpacing()) {
889 if (token == "\\InsetSpace")
890 par.insertChar(par.size(), ' ', font, change);
891 else if (lex.isOK()) {
893 string const next_token = lex.getString();
894 if (next_token == "\\-")
895 par.insertChar(par.size(), '-', font, change);
897 lex.printError("Token `$$Token' "
899 "paragraph layout!");
903 InsetOld * inset = 0;
904 if (token == "\\SpecialChar" )
905 inset = new InsetSpecialChar;
907 inset = new InsetSpace;
908 inset->read(&buf, lex);
909 par.insertInset(par.size(), inset, font, change);
911 } else if (token == "\\i") {
912 InsetOld * inset = new InsetLatexAccent;
913 inset->read(&buf, lex);
914 par.insertInset(par.size(), inset, font, change);
915 } else if (token == "\\backslash") {
916 par.insertChar(par.size(), '\\', font, change);
917 } else if (token == "\\newline") {
918 InsetOld * inset = new InsetNewline;
919 inset->read(&buf, lex);
920 par.insertInset(par.size(), inset, font, change);
921 } else if (token == "\\LyXTable") {
922 InsetOld * inset = new InsetTabular(buf);
923 inset->read(&buf, lex);
924 par.insertInset(par.size(), inset, font, change);
925 } else if (token == "\\bibitem") {
926 InsetCommandParams p("bibitem", "dummy");
927 InsetBibitem * inset = new InsetBibitem(p);
928 inset->read(&buf, lex);
929 par.insertInset(par.size(), inset, font, change);
930 } else if (token == "\\hfill") {
931 par.insertInset(par.size(), new InsetHFill(), font, change);
932 } else if (token == "\\change_unchanged") {
933 // Hack ! Needed for empty paragraphs :/
934 // FIXME: is it still ??
937 change = Change(Change::UNCHANGED);
938 } else if (token == "\\change_inserted") {
940 istringstream is(STRCONV(lex.getString()));
944 change = Change(Change::INSERTED, bp.author_map[aid], ct);
945 } else if (token == "\\change_deleted") {
947 istringstream is(STRCONV(lex.getString()));
951 change = Change(Change::DELETED, bp.author_map[aid], ct);
954 string const s = bformat(_("Unknown token: %1$s %2$s\n"),
955 token, lex.getString());
957 buf.error(ErrorItem(_("Unknown token"), s,
958 par.id(), 0, par.size()));
967 int readParagraph(Buffer & buf, Paragraph & par, LyXLex & lex)
972 string token = lex.getString();
976 unknown += readParToken(buf, par, lex, token);
979 token = lex.getString();
984 if (token == "\\end_layout") {
985 //Ok, paragraph finished
989 lyxerr[Debug::PARSER] << "Handling paragraph token: `"
990 << token << '\'' << endl;
991 if (token == "\\begin_layout" || token == "\\end_document"
992 || token == "\\end_inset" || token == "\\begin_deeper"
993 || token == "\\end_deeper") {
994 lex.pushToken(token);
995 lyxerr << "Paragraph ended in line "
996 << lex.getLineNo() << "\n"
997 << "Missing \\end_layout.\n";
1006 LyXFont const outerFont(ParagraphList::iterator pit,
1007 ParagraphList const & plist)
1009 Paragraph::depth_type par_depth = pit->getDepth();
1010 LyXFont tmpfont(LyXFont::ALL_INHERIT);
1012 // Resolve against environment font information
1013 while (pit != const_cast<ParagraphList&>(plist).end() &&
1014 par_depth && !tmpfont.resolved()) {
1015 pit = outerHook(pit, plist);
1016 if (pit != const_cast<ParagraphList&>(plist).end()) {
1017 tmpfont.realize(pit->layout()->font);
1018 par_depth = pit->getDepth();