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;
51 bool moveItem(Paragraph & from, Paragraph & to,
52 BufferParams const & params, pos_type i, pos_type j)
54 char const tmpchar = from.getChar(i);
55 LyXFont tmpfont = from.getFontSettings(params, i);
57 if (tmpchar == Paragraph::META_INSET) {
58 InsetOld * tmpinset = 0;
59 if (from.getInset(i)) {
60 // the inset is not in a paragraph anymore
61 tmpinset = from.insetlist.release(i);
62 tmpinset->parOwner(0);
65 if (!to.insetAllowed(tmpinset->lyxCode()))
67 to.insertInset(j, tmpinset, tmpfont);
69 if (!to.checkInsertChar(tmpfont))
71 to.insertChar(j, tmpchar, tmpfont);
79 void breakParagraph(BufferParams const & bparams,
80 ParagraphList & paragraphs,
81 ParagraphList::iterator par,
85 // create a new paragraph, and insert into the list
86 ParagraphList::iterator tmp = paragraphs.insert(boost::next(par),
89 // without doing that we get a crash when typing <Return> at the
91 tmp->layout(bparams.getLyXTextClass().defaultLayout());
92 // remember to set the inset_owner
93 tmp->setInsetOwner(par->inInset());
95 if (bparams.tracking_changes)
98 // this is an idea for a more userfriendly layout handling, I will
99 // see what the users say
101 // layout stays the same with latex-environments
103 tmp->layout(par->layout());
104 tmp->setLabelWidthString(par->params().labelWidthString());
107 bool const isempty = (par->allowEmpty() && par->empty());
109 if (!isempty && (par->size() > pos || par->empty() || flag == 2)) {
110 tmp->layout(par->layout());
111 tmp->params().align(par->params().align());
112 tmp->setLabelWidthString(par->params().labelWidthString());
114 tmp->params().lineBottom(par->params().lineBottom());
115 par->params().lineBottom(false);
116 tmp->params().pagebreakBottom(par->params().pagebreakBottom());
117 par->params().pagebreakBottom(false);
118 tmp->params().spaceBottom(par->params().spaceBottom());
119 par->params().spaceBottom(VSpace(VSpace::NONE));
121 tmp->params().depth(par->params().depth());
122 tmp->params().noindent(par->params().noindent());
124 // copy everything behind the break-position
125 // to the new paragraph
128 #warning this seems wrong
130 /* FIXME: if !keepempty, empty() == true, then we reach
131 * here with size() == 0. So pos_end becomes - 1. Why
132 * doesn't this cause problems ???
134 pos_type pos_end = par->size() - 1;
138 for (; i <= pos_end; ++i) {
139 Change::Type change = par->lookupChange(i);
140 if (moveItem(*par, *tmp, bparams, i, j - pos)) {
141 tmp->setChange(j - pos, change);
146 for (i = pos_end; i >= pos; --i)
153 tmp->params().lineTop(par->params().lineTop());
154 tmp->params().pagebreakTop(par->params().pagebreakTop());
155 tmp->params().spaceTop(par->params().spaceTop());
156 par->params().clear();
158 par->layout(bparams.getLyXTextClass().defaultLayout());
160 // layout stays the same with latex-environments
162 par->layout(tmp->layout());
163 par->setLabelWidthString(tmp->params().labelWidthString());
164 par->params().depth(tmp->params().depth());
167 // subtle, but needed to get empty pars working right
168 if (bparams.tracking_changes) {
171 } else if (!tmp->size()) {
178 void breakParagraphConservative(BufferParams const & bparams,
179 ParagraphList & paragraphs,
180 ParagraphList::iterator par,
183 // create a new paragraph
184 ParagraphList::iterator tmp = paragraphs.insert(boost::next(par),
186 tmp->makeSameLayout(*par);
188 // When can pos > size()?
189 // I guess pos == size() is possible.
190 if (par->size() > pos) {
191 // copy everything behind the break-position to the new
193 pos_type pos_end = par->size() - 1;
195 for (pos_type i = pos, j = pos; i <= pos_end; ++i)
196 if (moveItem(*par, *tmp, bparams, i, j - pos))
199 for (pos_type k = pos_end; k >= pos; --k)
205 void mergeParagraph(BufferParams const & bparams,
206 ParagraphList & paragraphs,
207 ParagraphList::iterator par)
209 ParagraphList::iterator the_next = boost::next(par);
211 // first the DTP-stuff
212 par->params().lineBottom(the_next->params().lineBottom());
213 par->params().spaceBottom(the_next->params().spaceBottom());
214 par->params().pagebreakBottom(the_next->params().pagebreakBottom());
216 pos_type pos_end = the_next->size() - 1;
217 pos_type pos_insert = par->size();
219 // ok, now copy the paragraph
220 for (pos_type i = 0, j = 0; i <= pos_end; ++i)
221 if (moveItem(*the_next, *par, bparams, i, pos_insert + j))
224 paragraphs.erase(the_next);
228 ParagraphList::iterator depthHook(ParagraphList::iterator pit,
229 ParagraphList const & plist,
230 Paragraph::depth_type depth)
232 ParagraphList::iterator newpit = pit;
233 ParagraphList::iterator beg = const_cast<ParagraphList&>(plist).begin();
238 while (newpit != beg && newpit->getDepth() > depth) {
242 if (newpit->getDepth() > depth)
249 ParagraphList::iterator outerHook(ParagraphList::iterator pit,
250 ParagraphList const & plist)
252 if (!pit->getDepth())
253 return const_cast<ParagraphList&>(plist).end();
254 return depthHook(pit, plist,
255 Paragraph::depth_type(pit->getDepth() - 1));
259 bool isFirstInSequence(ParagraphList::iterator pit,
260 ParagraphList const & plist)
262 ParagraphList::iterator dhook = depthHook(pit, plist, pit->getDepth());
264 || dhook->layout() != pit->layout()
265 || dhook->getDepth() != pit->getDepth());
269 int getEndLabel(ParagraphList::iterator p, ParagraphList const & plist)
271 ParagraphList::iterator pit = p;
272 Paragraph::depth_type par_depth = p->getDepth();
273 while (pit != const_cast<ParagraphList&>(plist).end()) {
274 LyXLayout_ptr const & layout = pit->layout();
275 int const endlabeltype = layout->endlabeltype;
277 if (endlabeltype != END_LABEL_NO_LABEL) {
278 if (boost::next(p) == const_cast<ParagraphList&>(plist).end())
281 Paragraph::depth_type const next_depth = boost::next(p)->getDepth();
282 if (par_depth > next_depth ||
283 (par_depth == next_depth &&
284 layout != boost::next(p)->layout()))
290 pit = outerHook(pit, plist);
291 if (pit != const_cast<ParagraphList&>(plist).end())
292 par_depth = pit->getDepth();
294 return END_LABEL_NO_LABEL;
300 ParagraphList::iterator
301 TeXEnvironment(Buffer const * buf,
302 ParagraphList const & paragraphs,
303 ParagraphList::iterator pit,
304 ostream & os, TexRow & texrow,
305 LatexRunParams const & runparams);
307 ParagraphList::iterator
308 TeXOnePar(Buffer const * buf,
309 ParagraphList const & paragraphs,
310 ParagraphList::iterator pit,
311 ostream & os, TexRow & texrow,
312 LatexRunParams const & runparams,
313 string const & everypar = string());
316 ParagraphList::iterator
317 TeXDeeper(Buffer const * buf,
318 ParagraphList const & paragraphs,
319 ParagraphList::iterator pit,
320 ostream & os, TexRow & texrow,
321 LatexRunParams const & runparams)
323 lyxerr[Debug::LATEX] << "TeXDeeper... " << &*pit << endl;
324 ParagraphList::iterator par = pit;
326 while (par != const_cast<ParagraphList&>(paragraphs).end() &&
327 par->params().depth() == pit->params().depth()) {
328 if (par->layout()->isEnvironment()) {
329 par = TeXEnvironment(buf, paragraphs, par,
330 os, texrow, runparams);
332 par = TeXOnePar(buf, paragraphs, par,
333 os, texrow, runparams);
336 lyxerr[Debug::LATEX] << "TeXDeeper...done " << &*par << endl;
342 ParagraphList::iterator
343 TeXEnvironment(Buffer const * buf,
344 ParagraphList const & paragraphs,
345 ParagraphList::iterator pit,
346 ostream & os, TexRow & texrow,
347 LatexRunParams const & runparams)
349 lyxerr[Debug::LATEX] << "TeXEnvironment... " << &*pit << endl;
351 BufferParams const & bparams = buf->params;
353 LyXLayout_ptr const & style = pit->layout();
355 Language const * language = pit->getParLanguage(bparams);
356 Language const * doc_language = bparams.language;
357 Language const * previous_language =
358 (pit != const_cast<ParagraphList&>(paragraphs).begin())
359 ? boost::prior(pit)->getParLanguage(bparams)
361 if (language->babel() != previous_language->babel()) {
363 if (!lyxrc.language_command_end.empty() &&
364 previous_language->babel() != doc_language->babel()) {
365 os << subst(lyxrc.language_command_end, "$$lang",
366 previous_language->babel())
371 if (lyxrc.language_command_end.empty() ||
372 language->babel() != doc_language->babel()) {
373 os << subst(lyxrc.language_command_begin, "$$lang",
380 bool leftindent_open = false;
381 if (!pit->params().leftIndent().zero()) {
382 os << "\\begin{LyXParagraphLeftIndent}{" <<
383 pit->params().leftIndent().asLatexString() << "}\n";
385 leftindent_open = true;
388 if (style->isEnvironment()) {
389 if (style->latextype == LATEX_LIST_ENVIRONMENT) {
390 os << "\\begin{" << style->latexname() << "}{"
391 << pit->params().labelWidthString() << "}\n";
392 } else if (style->labeltype == LABEL_BIBLIO) {
394 os << "\\begin{" << style->latexname() << "}{"
395 << bibitemWidest(buf)
397 } else if (style->latextype == LATEX_ITEM_ENVIRONMENT) {
398 os << "\\begin{" << style->latexname() << '}'
399 << style->latexparam() << '\n';
401 os << "\\begin{" << style->latexname() << '}'
402 << style->latexparam() << '\n';
405 ParagraphList::iterator par = pit;
407 par = TeXOnePar(buf, paragraphs, par, os, texrow, runparams);
409 if (par != const_cast<ParagraphList&>(paragraphs).end() && par->params().depth() > pit->params().depth()) {
410 if (par->layout()->isParagraph()) {
413 // How to handle this? (Lgb)
414 //&& !suffixIs(os, "\n\n")
416 // There should be at least one '\n' already
417 // but we need there to be two for Standard
418 // paragraphs that are depth-increment'ed to be
419 // output correctly. However, tables can
420 // also be paragraphs so don't adjust them.
423 // Will it ever harm to have one '\n' too
424 // many? i.e. that we sometimes will have
425 // three in a row. (Lgb)
429 par = TeXDeeper(buf, paragraphs, par, os, texrow,
432 } while (par != const_cast<ParagraphList&>(paragraphs).end()
433 && par->layout() == pit->layout()
434 && par->params().depth() == pit->params().depth()
435 && par->params().leftIndent() == pit->params().leftIndent());
437 if (style->isEnvironment()) {
438 os << "\\end{" << style->latexname() << "}\n";
442 if (leftindent_open) {
443 os << "\\end{LyXParagraphLeftIndent}\n";
447 lyxerr[Debug::LATEX] << "TeXEnvironment...done " << &*par << endl;
448 return par; // ale970302
452 InsetOptArg * optArgInset(Paragraph const & par)
455 InsetList::const_iterator it = par.insetlist.begin();
456 InsetList::const_iterator end = par.insetlist.end();
457 for (; it != end; ++it) {
458 InsetOld * ins = it->inset;
459 if (ins->lyxCode() == InsetOld::OPTARG_CODE) {
460 return static_cast<InsetOptArg *>(ins);
467 ParagraphList::iterator
468 TeXOnePar(Buffer const * buf,
469 ParagraphList const & paragraphs,
470 ParagraphList::iterator pit,
471 ostream & os, TexRow & texrow,
472 LatexRunParams const & runparams,
473 string const & everypar)
475 lyxerr[Debug::LATEX] << "TeXOnePar... " << &*pit << " '"
476 << everypar << "'" << endl;
477 BufferParams const & bparams = buf->params;
479 InsetOld const * in = pit->inInset();
480 bool further_blank_line = false;
483 // well we have to check if we are in an inset with unlimited
484 // length (all in one row) if that is true then we don't allow
485 // any special options in the paragraph and also we don't allow
486 // any environment other then "Standard" to be valid!
487 if (in == 0 || !in->forceDefaultParagraphs(in)) {
488 style = pit->layout();
490 if (pit->params().startOfAppendix()) {
491 os << "\\appendix\n";
495 if (!pit->params().spacing().isDefault()
496 && (pit == const_cast<ParagraphList&>(paragraphs).begin() || !boost::prior(pit)->hasSameLayout(*pit))) {
497 os << pit->params().spacing().writeEnvirBegin() << '\n';
501 if (style->isCommand()) {
506 if (pit->params().pagebreakTop()) {
508 further_blank_line = true;
510 if (pit->params().spaceTop().kind() != VSpace::NONE) {
511 os << pit->params().spaceTop().asLatexCommand(bparams);
512 further_blank_line = true;
515 if (pit->params().lineTop()) {
517 << pit->getFont(bparams, 0, outerFont(pit, paragraphs)).latexSize()
519 << "\\vspace{-1\\parskip}";
520 further_blank_line = true;
523 if (further_blank_line) {
528 style = bparams.getLyXTextClass().defaultLayout();
531 Language const * language = pit->getParLanguage(bparams);
532 Language const * doc_language = bparams.language;
533 Language const * previous_language =
534 (pit != const_cast<ParagraphList&>(paragraphs).begin())
535 ? boost::prior(pit)->getParLanguage(bparams)
538 if (language->babel() != previous_language->babel()
539 // check if we already put language command in TeXEnvironment()
540 && !(style->isEnvironment()
541 && (pit == const_cast<ParagraphList&>(paragraphs).begin() ||
542 (boost::prior(pit)->layout() != pit->layout() &&
543 boost::prior(pit)->getDepth() <= pit->getDepth())
544 || boost::prior(pit)->getDepth() < pit->getDepth())))
546 if (!lyxrc.language_command_end.empty() &&
547 previous_language->babel() != doc_language->babel())
549 os << subst(lyxrc.language_command_end, "$$lang",
550 previous_language->babel())
555 if (lyxrc.language_command_end.empty() ||
556 language->babel() != doc_language->babel())
558 os << subst(lyxrc.language_command_begin, "$$lang",
565 if (bparams.inputenc == "auto" &&
566 language->encoding() != previous_language->encoding()) {
567 os << "\\inputencoding{"
568 << language->encoding()->LatexName()
573 switch (style->latextype) {
575 os << '\\' << style->latexname();
577 // Separate handling of optional argument inset.
578 if (style->optionalargs == 1) {
579 InsetOptArg * it = optArgInset(*pit);
581 it->latexOptional(buf, os, runparams);
584 os << style->latexparam();
586 case LATEX_ITEM_ENVIRONMENT:
587 case LATEX_LIST_ENVIRONMENT:
590 case LATEX_BIB_ENVIRONMENT:
591 // ignore this, the inset will write itself
598 bool need_par = pit->simpleTeXOnePar(buf, bparams,
599 outerFont(pit, paragraphs),
600 os, texrow, runparams);
602 // Make sure that \\par is done with the font of the last
603 // character if this has another size as the default.
604 // This is necessary because LaTeX (and LyX on the screen)
605 // calculates the space between the baselines according
606 // to this font. (Matthias)
608 // Is this really needed ? (Dekel)
609 // We do not need to use to change the font for the last paragraph
611 LyXFont const outerfont(outerFont(pit, paragraphs));
615 ? pit->getLayoutFont(bparams, outerfont)
616 : pit->getFont(bparams, pit->size() - 1, outerfont));
618 bool is_command = style->isCommand();
620 if (style->resfont.size() != font.size()
621 && boost::next(pit) != const_cast<ParagraphList&>(paragraphs).end()
625 os << "\\" << font.latexSize() << " \\par}";
626 } else if (need_par) {
628 } else if (is_command)
631 switch (style->latextype) {
632 case LATEX_ITEM_ENVIRONMENT:
633 case LATEX_LIST_ENVIRONMENT:
634 if (boost::next(pit) != const_cast<ParagraphList&>(paragraphs).end()
635 && (pit->params().depth() < boost::next(pit)->params().depth())) {
640 case LATEX_ENVIRONMENT: {
641 // if its the last paragraph of the current environment
642 // skip it otherwise fall through
643 ParagraphList::iterator next = boost::next(pit);
645 if (next != const_cast<ParagraphList&>(paragraphs).end()
646 && (next->layout() != pit->layout()
647 || next->params().depth() != pit->params().depth()))
651 // fall through possible
653 // we don't need it for the last paragraph!!!
654 if (boost::next(pit) != const_cast<ParagraphList&>(paragraphs).end()) {
660 if (in == 0 || !in->forceDefaultParagraphs(in)) {
661 further_blank_line = false;
662 if (pit->params().lineBottom()) {
663 os << "\\lyxline{\\" << font.latexSize() << '}';
664 further_blank_line = true;
667 if (pit->params().spaceBottom().kind() != VSpace::NONE) {
668 os << pit->params().spaceBottom().asLatexCommand(bparams);
669 further_blank_line = true;
672 if (pit->params().pagebreakBottom()) {
674 further_blank_line = true;
677 if (further_blank_line) {
682 if (!pit->params().spacing().isDefault()
683 && (boost::next(pit) == const_cast<ParagraphList&>(paragraphs).end()|| !boost::next(pit)->hasSameLayout(*pit))) {
684 os << pit->params().spacing().writeEnvirEnd() << '\n';
689 // we don't need it for the last paragraph!!!
690 if (boost::next(pit) != const_cast<ParagraphList&>(paragraphs).end()) {
694 // Since \selectlanguage write the language to the aux file,
695 // we need to reset the language at the end of footnote or
698 if (language->babel() != doc_language->babel()) {
699 if (lyxrc.language_command_end.empty())
700 os << subst(lyxrc.language_command_begin,
702 doc_language->babel())
705 os << subst(lyxrc.language_command_end,
713 lyxerr[Debug::LATEX] << "TeXOnePar...done " << &*boost::next(pit) << endl;
721 // LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
723 void latexParagraphs(Buffer const * buf,
724 ParagraphList const & paragraphs,
727 LatexRunParams const & runparams,
728 string const & everypar)
730 bool was_title = false;
731 bool already_title = false;
732 LyXTextClass const & tclass = buf->params.getLyXTextClass();
733 ParagraphList::iterator par = const_cast<ParagraphList&>(paragraphs).begin();
734 ParagraphList::iterator endpar = const_cast<ParagraphList&>(paragraphs).end();
737 while (par != endpar) {
738 InsetOld * in = par->inInset();
739 // well we have to check if we are in an inset with unlimited
740 // length (all in one row) if that is true then we don't allow
741 // any special options in the paragraph and also we don't allow
742 // any environment other then "Standard" to be valid!
743 if (in == 0 || !in->forceDefaultParagraphs(in)) {
744 LyXLayout_ptr const & layout = par->layout();
746 if (layout->intitle) {
748 lyxerr <<"Error in latexParagraphs: You"
749 " should not mix title layouts"
750 " with normal ones." << endl;
751 } else if (!was_title) {
753 if (tclass.titletype() == TITLE_ENVIRONMENT) {
755 << tclass.titlename()
760 } else if (was_title && !already_title) {
761 if (tclass.titletype() == TITLE_ENVIRONMENT) {
762 os << "\\end{" << tclass.titlename()
766 os << "\\" << tclass.titlename()
770 already_title = true;
774 if (layout->is_environment) {
775 par = TeXOnePar(buf, paragraphs, par, os, texrow,
776 runparams, everypar);
777 } else if (layout->isEnvironment() ||
778 !par->params().leftIndent().zero())
780 par = TeXEnvironment(buf, paragraphs, par, os,
783 par = TeXOnePar(buf, paragraphs, par, os, texrow,
784 runparams, everypar);
787 par = TeXOnePar(buf, paragraphs, par, os, texrow,
788 runparams, everypar);
791 // It might be that we only have a title in this document
792 if (was_title && !already_title) {
793 if (tclass.titletype() == TITLE_ENVIRONMENT) {
794 os << "\\end{" << tclass.titlename()
798 os << "\\" << tclass.titlename()
808 int readParToken(Buffer & buf, Paragraph & par, LyXLex & lex, string const & token)
811 static Change change;
813 BufferParams const & bp = buf.params;
815 if (token[0] != '\\') {
816 string::const_iterator cit = token.begin();
817 for (; cit != token.end(); ++cit) {
818 par.insertChar(par.size(), (*cit), font, change);
820 } else if (token == "\\begin_layout") {
822 string layoutname = lex.getString();
824 font = LyXFont(LyXFont::ALL_INHERIT, bp.language);
827 LyXTextClass const & tclass = bp.getLyXTextClass();
829 if (layoutname.empty()) {
830 layoutname = tclass.defaultLayoutName();
833 bool hasLayout = tclass.hasLayout(layoutname);
836 lyxerr << "Layout '" << layoutname << "' does not"
837 << " exist in textclass '" << tclass.name()
839 lyxerr << "Trying to use default layout instead."
841 layoutname = tclass.defaultLayoutName();
844 par.layout(bp.getLyXTextClass()[layoutname]);
846 // Test whether the layout is obsolete.
847 LyXLayout_ptr const & layout = par.layout();
848 if (!layout->obsoleted_by().empty())
849 par.layout(bp.getLyXTextClass()[layout->obsoleted_by()]);
851 par.params().read(lex);
853 } else if (token == "\\end_layout") {
854 lyxerr << "Solitary \\end_layout in line " << lex.getLineNo() << "\n"
855 << "Missing \\begin_layout?.\n";
856 } else if (token == "\\end_inset") {
857 lyxerr << "Solitary \\end_inset in line " << lex.getLineNo() << "\n"
858 << "Missing \\begin_inset?.\n";
859 } else if (token == "\\begin_inset") {
860 InsetOld * inset = readInset(lex, buf);
861 par.insertInset(par.size(), inset, font, change);
862 } else if (token == "\\family") {
864 font.setLyXFamily(lex.getString());
865 } else if (token == "\\series") {
867 font.setLyXSeries(lex.getString());
868 } else if (token == "\\shape") {
870 font.setLyXShape(lex.getString());
871 } else if (token == "\\size") {
873 font.setLyXSize(lex.getString());
874 } else if (token == "\\lang") {
876 string const tok = lex.getString();
877 Language const * lang = languages.getLanguage(tok);
879 font.setLanguage(lang);
881 font.setLanguage(bp.language);
882 lex.printError("Unknown language `$$Token'");
884 } else if (token == "\\numeric") {
886 font.setNumber(font.setLyXMisc(lex.getString()));
887 } else if (token == "\\emph") {
889 font.setEmph(font.setLyXMisc(lex.getString()));
890 } else if (token == "\\bar") {
892 string const tok = lex.getString();
895 font.setUnderbar(LyXFont::ON);
896 else if (tok == "no")
897 font.setUnderbar(LyXFont::OFF);
898 else if (tok == "default")
899 font.setUnderbar(LyXFont::INHERIT);
901 lex.printError("Unknown bar font flag "
903 } else if (token == "\\noun") {
905 font.setNoun(font.setLyXMisc(lex.getString()));
906 } else if (token == "\\color") {
908 font.setLyXColor(lex.getString());
909 } else if (token == "\\InsetSpace" || token == "\\SpecialChar") {
911 // Insets don't make sense in a free-spacing context! ---Kayvan
912 if (par.isFreeSpacing()) {
913 if (token == "\\InsetSpace")
914 par.insertChar(par.size(), ' ', font, change);
915 else if (lex.isOK()) {
917 string const next_token = lex.getString();
918 if (next_token == "\\-")
919 par.insertChar(par.size(), '-', font, change);
921 lex.printError("Token `$$Token' "
923 "paragraph layout!");
927 InsetOld * inset = 0;
928 if (token == "\\SpecialChar" )
929 inset = new InsetSpecialChar;
931 inset = new InsetSpace;
932 inset->read(&buf, lex);
933 par.insertInset(par.size(), inset, font, change);
935 } else if (token == "\\i") {
936 InsetOld * inset = new InsetLatexAccent;
937 inset->read(&buf, lex);
938 par.insertInset(par.size(), inset, font, change);
939 } else if (token == "\\backslash") {
940 par.insertChar(par.size(), '\\', font, change);
941 } else if (token == "\\newline") {
942 InsetOld * inset = new InsetNewline;
943 inset->read(&buf, lex);
944 par.insertInset(par.size(), inset, font, change);
945 } else if (token == "\\LyXTable") {
946 InsetOld * inset = new InsetTabular(buf);
947 inset->read(&buf, lex);
948 par.insertInset(par.size(), inset, font, change);
949 } else if (token == "\\bibitem") {
950 InsetCommandParams p("bibitem", "dummy");
951 InsetBibitem * inset = new InsetBibitem(p);
952 inset->read(&buf, lex);
953 par.insertInset(par.size(), inset, font, change);
954 } else if (token == "\\hfill") {
955 par.insertInset(par.size(), new InsetHFill, font, change);
956 } else if (token == "\\change_unchanged") {
957 // Hack ! Needed for empty paragraphs :/
958 // FIXME: is it still ??
961 change = Change(Change::UNCHANGED);
962 } else if (token == "\\change_inserted") {
964 istringstream is(STRCONV(lex.getString()));
968 change = Change(Change::INSERTED, bp.author_map[aid], ct);
969 } else if (token == "\\change_deleted") {
971 istringstream is(STRCONV(lex.getString()));
975 change = Change(Change::DELETED, bp.author_map[aid], ct);
978 string const s = bformat(_("Unknown token: %1$s %2$s\n"),
979 token, lex.getString());
981 buf.error(ErrorItem(_("Unknown token"), s,
982 par.id(), 0, par.size()));
991 int readParagraph(Buffer & buf, Paragraph & par, LyXLex & lex)
996 string token = lex.getString();
1000 unknown += readParToken(buf, par, lex, token);
1003 token = lex.getString();
1008 if (token == "\\end_layout") {
1009 //Ok, paragraph finished
1013 lyxerr[Debug::PARSER] << "Handling paragraph token: `"
1014 << token << '\'' << endl;
1015 if (token == "\\begin_layout" || token == "\\end_document"
1016 || token == "\\end_inset" || token == "\\begin_deeper"
1017 || token == "\\end_deeper") {
1018 lex.pushToken(token);
1019 lyxerr << "Paragraph ended in line "
1020 << lex.getLineNo() << "\n"
1021 << "Missing \\end_layout.\n";
1030 LyXFont const outerFont(ParagraphList::iterator pit,
1031 ParagraphList const & plist)
1033 Paragraph::depth_type par_depth = pit->getDepth();
1034 LyXFont tmpfont(LyXFont::ALL_INHERIT);
1036 // Resolve against environment font information
1037 while (pit != const_cast<ParagraphList&>(plist).end() &&
1038 par_depth && !tmpfont.resolved()) {
1039 pit = outerHook(pit, plist);
1040 if (pit != const_cast<ParagraphList&>(plist).end()) {
1041 tmpfont.realize(pit->layout()->font);
1042 par_depth = pit->getDepth();