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"
17 #include "errorlist.h"
19 #include "iterators.h"
24 #include "support/std_sstream.h"
26 #include "support/lstrings.h"
27 #include "support/LAssert.h"
29 #include "insets/insetoptarg.h"
30 #include "insets/insetbibitem.h"
31 #include "insets/insetspace.h"
32 #include "insets/insetspecialchar.h"
33 #include "insets/insetlatexaccent.h"
34 #include "insets/insettabular.h"
35 #include "insets/insethfill.h"
36 #include "insets/insetnewline.h"
38 extern string bibitemWidest(Buffer const &);
40 using namespace lyx::support;
43 //using lyx::layout_type;
45 using std::istringstream;
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);
64 if (!to.insetAllowed(tmpinset->lyxCode()))
66 to.insertInset(j, tmpinset, tmpfont);
68 if (!to.checkInsertChar(tmpfont))
70 to.insertChar(j, tmpchar, tmpfont);
78 void breakParagraph(BufferParams const & bparams,
79 ParagraphList & paragraphs,
80 ParagraphList::iterator par,
84 // create a new paragraph, and insert into the list
85 ParagraphList::iterator tmp = paragraphs.insert(boost::next(par),
88 // without doing that we get a crash when typing <Return> at the
90 tmp->layout(bparams.getLyXTextClass().defaultLayout());
91 // remember to set the inset_owner
92 tmp->setInsetOwner(par->inInset());
94 if (bparams.tracking_changes)
97 // this is an idea for a more userfriendly layout handling, I will
98 // see what the users say
100 // layout stays the same with latex-environments
102 tmp->layout(par->layout());
103 tmp->setLabelWidthString(par->params().labelWidthString());
106 bool const isempty = (par->allowEmpty() && par->empty());
108 if (!isempty && (par->size() > pos || par->empty() || flag == 2)) {
109 tmp->layout(par->layout());
110 tmp->params().align(par->params().align());
111 tmp->setLabelWidthString(par->params().labelWidthString());
113 tmp->params().lineBottom(par->params().lineBottom());
114 par->params().lineBottom(false);
115 tmp->params().pagebreakBottom(par->params().pagebreakBottom());
116 par->params().pagebreakBottom(false);
117 tmp->params().spaceBottom(par->params().spaceBottom());
118 par->params().spaceBottom(VSpace(VSpace::NONE));
120 tmp->params().depth(par->params().depth());
121 tmp->params().noindent(par->params().noindent());
123 // copy everything behind the break-position
124 // to the new paragraph
127 #warning this seems wrong
129 /* FIXME: if !keepempty, empty() == true, then we reach
130 * here with size() == 0. So pos_end becomes - 1. Why
131 * doesn't this cause problems ???
133 pos_type pos_end = par->size() - 1;
137 for (; i <= pos_end; ++i) {
138 Change::Type change = par->lookupChange(i);
139 if (moveItem(*par, *tmp, bparams, i, j - pos)) {
140 tmp->setChange(j - pos, change);
145 for (i = pos_end; i >= pos; --i)
152 tmp->params().lineTop(par->params().lineTop());
153 tmp->params().pagebreakTop(par->params().pagebreakTop());
154 tmp->params().spaceTop(par->params().spaceTop());
155 par->params().clear();
157 par->layout(bparams.getLyXTextClass().defaultLayout());
159 // layout stays the same with latex-environments
161 par->layout(tmp->layout());
162 par->setLabelWidthString(tmp->params().labelWidthString());
163 par->params().depth(tmp->params().depth());
166 // subtle, but needed to get empty pars working right
167 if (bparams.tracking_changes) {
170 } else if (!tmp->size()) {
177 void breakParagraphConservative(BufferParams const & bparams,
178 ParagraphList & paragraphs,
179 ParagraphList::iterator par,
182 // create a new paragraph
183 ParagraphList::iterator tmp = paragraphs.insert(boost::next(par),
185 tmp->makeSameLayout(*par);
187 // When can pos > size()?
188 // I guess pos == size() is possible.
189 if (par->size() > pos) {
190 // copy everything behind the break-position to the new
192 pos_type pos_end = par->size() - 1;
194 for (pos_type i = pos, j = pos; i <= pos_end; ++i)
195 if (moveItem(*par, *tmp, bparams, i, j - pos))
198 for (pos_type k = pos_end; k >= pos; --k)
204 void mergeParagraph(BufferParams const & bparams,
205 ParagraphList & paragraphs,
206 ParagraphList::iterator par)
208 ParagraphList::iterator the_next = boost::next(par);
210 // first the DTP-stuff
211 par->params().lineBottom(the_next->params().lineBottom());
212 par->params().spaceBottom(the_next->params().spaceBottom());
213 par->params().pagebreakBottom(the_next->params().pagebreakBottom());
215 pos_type pos_end = the_next->size() - 1;
216 pos_type pos_insert = par->size();
218 // ok, now copy the paragraph
219 for (pos_type i = 0, j = 0; i <= pos_end; ++i)
220 if (moveItem(*the_next, *par, bparams, i, pos_insert + j))
223 paragraphs.erase(the_next);
227 ParagraphList::iterator depthHook(ParagraphList::iterator pit,
228 ParagraphList const & plist,
229 Paragraph::depth_type depth)
231 ParagraphList::iterator newpit = pit;
232 ParagraphList::iterator beg = const_cast<ParagraphList&>(plist).begin();
237 while (newpit != beg && newpit->getDepth() > depth) {
241 if (newpit->getDepth() > depth)
248 ParagraphList::iterator outerHook(ParagraphList::iterator pit,
249 ParagraphList const & plist)
251 if (!pit->getDepth())
252 return const_cast<ParagraphList&>(plist).end();
253 return depthHook(pit, plist,
254 Paragraph::depth_type(pit->getDepth() - 1));
258 bool isFirstInSequence(ParagraphList::iterator pit,
259 ParagraphList const & plist)
261 ParagraphList::iterator dhook = depthHook(pit, plist, pit->getDepth());
263 || dhook->layout() != pit->layout()
264 || dhook->getDepth() != pit->getDepth());
268 int getEndLabel(ParagraphList::iterator p, ParagraphList const & plist)
270 ParagraphList::iterator pit = p;
271 Paragraph::depth_type par_depth = p->getDepth();
272 while (pit != const_cast<ParagraphList&>(plist).end()) {
273 LyXLayout_ptr const & layout = pit->layout();
274 int const endlabeltype = layout->endlabeltype;
276 if (endlabeltype != END_LABEL_NO_LABEL) {
277 if (boost::next(p) == const_cast<ParagraphList&>(plist).end())
280 Paragraph::depth_type const next_depth = boost::next(p)->getDepth();
281 if (par_depth > next_depth ||
282 (par_depth == next_depth &&
283 layout != boost::next(p)->layout()))
289 pit = outerHook(pit, plist);
290 if (pit != const_cast<ParagraphList&>(plist).end())
291 par_depth = pit->getDepth();
293 return END_LABEL_NO_LABEL;
299 ParagraphList::iterator
300 TeXEnvironment(Buffer const & buf,
301 ParagraphList const & paragraphs,
302 ParagraphList::iterator pit,
303 ostream & os, TexRow & texrow,
304 LatexRunParams const & runparams);
306 ParagraphList::iterator
307 TeXOnePar(Buffer const & buf,
308 ParagraphList const & paragraphs,
309 ParagraphList::iterator pit,
310 ostream & os, TexRow & texrow,
311 LatexRunParams const & runparams,
312 string const & everypar = string());
315 ParagraphList::iterator
316 TeXDeeper(Buffer const & buf,
317 ParagraphList const & paragraphs,
318 ParagraphList::iterator pit,
319 ostream & os, TexRow & texrow,
320 LatexRunParams const & runparams)
322 lyxerr[Debug::LATEX] << "TeXDeeper... " << &*pit << endl;
323 ParagraphList::iterator par = pit;
325 while (par != const_cast<ParagraphList&>(paragraphs).end() &&
326 par->params().depth() == pit->params().depth()) {
327 if (par->layout()->isEnvironment()) {
328 par = TeXEnvironment(buf, paragraphs, par,
329 os, texrow, runparams);
331 par = TeXOnePar(buf, paragraphs, par,
332 os, texrow, runparams);
335 lyxerr[Debug::LATEX] << "TeXDeeper...done " << &*par << endl;
341 ParagraphList::iterator
342 TeXEnvironment(Buffer const & buf,
343 ParagraphList const & paragraphs,
344 ParagraphList::iterator pit,
345 ostream & os, TexRow & texrow,
346 LatexRunParams const & runparams)
348 lyxerr[Debug::LATEX] << "TeXEnvironment... " << &*pit << endl;
350 BufferParams const & bparams = buf.params;
352 LyXLayout_ptr const & style = pit->layout();
354 Language const * language = pit->getParLanguage(bparams);
355 Language const * doc_language = bparams.language;
356 Language const * previous_language =
357 (pit != const_cast<ParagraphList&>(paragraphs).begin())
358 ? boost::prior(pit)->getParLanguage(bparams)
360 if (language->babel() != previous_language->babel()) {
362 if (!lyxrc.language_command_end.empty() &&
363 previous_language->babel() != doc_language->babel()) {
364 os << subst(lyxrc.language_command_end, "$$lang",
365 previous_language->babel())
370 if (lyxrc.language_command_end.empty() ||
371 language->babel() != doc_language->babel()) {
372 os << subst(lyxrc.language_command_begin, "$$lang",
379 bool leftindent_open = false;
380 if (!pit->params().leftIndent().zero()) {
381 os << "\\begin{LyXParagraphLeftIndent}{" <<
382 pit->params().leftIndent().asLatexString() << "}\n";
384 leftindent_open = true;
387 if (style->isEnvironment()) {
388 if (style->latextype == LATEX_LIST_ENVIRONMENT) {
389 os << "\\begin{" << style->latexname() << "}{"
390 << pit->params().labelWidthString() << "}\n";
391 } else if (style->labeltype == LABEL_BIBLIO) {
393 os << "\\begin{" << style->latexname() << "}{"
394 << bibitemWidest(buf)
396 } else if (style->latextype == LATEX_ITEM_ENVIRONMENT) {
397 os << "\\begin{" << style->latexname() << '}'
398 << style->latexparam() << '\n';
400 os << "\\begin{" << style->latexname() << '}'
401 << style->latexparam() << '\n';
404 ParagraphList::iterator par = pit;
406 par = TeXOnePar(buf, paragraphs, par, os, texrow, runparams);
408 if (par != const_cast<ParagraphList&>(paragraphs).end() && par->params().depth() > pit->params().depth()) {
409 if (par->layout()->isParagraph()) {
412 // How to handle this? (Lgb)
413 //&& !suffixIs(os, "\n\n")
415 // There should be at least one '\n' already
416 // but we need there to be two for Standard
417 // paragraphs that are depth-increment'ed to be
418 // output correctly. However, tables can
419 // also be paragraphs so don't adjust them.
422 // Will it ever harm to have one '\n' too
423 // many? i.e. that we sometimes will have
424 // three in a row. (Lgb)
428 par = TeXDeeper(buf, paragraphs, par, os, texrow,
431 } while (par != const_cast<ParagraphList&>(paragraphs).end()
432 && par->layout() == pit->layout()
433 && par->params().depth() == pit->params().depth()
434 && par->params().leftIndent() == pit->params().leftIndent());
436 if (style->isEnvironment()) {
437 os << "\\end{" << style->latexname() << "}\n";
441 if (leftindent_open) {
442 os << "\\end{LyXParagraphLeftIndent}\n";
446 lyxerr[Debug::LATEX] << "TeXEnvironment...done " << &*par << endl;
447 return par; // ale970302
451 InsetOptArg * optArgInset(Paragraph const & par)
454 InsetList::const_iterator it = par.insetlist.begin();
455 InsetList::const_iterator end = par.insetlist.end();
456 for (; it != end; ++it) {
457 InsetOld * ins = it->inset;
458 if (ins->lyxCode() == InsetOld::OPTARG_CODE) {
459 return static_cast<InsetOptArg *>(ins);
466 ParagraphList::iterator
467 TeXOnePar(Buffer const & buf,
468 ParagraphList const & paragraphs,
469 ParagraphList::iterator pit,
470 ostream & os, TexRow & texrow,
471 LatexRunParams const & runparams,
472 string const & everypar)
474 lyxerr[Debug::LATEX] << "TeXOnePar... " << &*pit << " '"
475 << everypar << "'" << endl;
476 BufferParams const & bparams = buf.params;
478 InsetOld const * in = pit->inInset();
479 bool further_blank_line = false;
482 // well we have to check if we are in an inset with unlimited
483 // length (all in one row) if that is true then we don't allow
484 // any special options in the paragraph and also we don't allow
485 // any environment other then "Standard" to be valid!
486 if (in == 0 || !in->forceDefaultParagraphs(in)) {
487 style = pit->layout();
489 if (pit->params().startOfAppendix()) {
490 os << "\\appendix\n";
494 if (!pit->params().spacing().isDefault()
495 && (pit == const_cast<ParagraphList&>(paragraphs).begin() || !boost::prior(pit)->hasSameLayout(*pit))) {
496 os << pit->params().spacing().writeEnvirBegin() << '\n';
500 if (style->isCommand()) {
505 if (pit->params().pagebreakTop()) {
507 further_blank_line = true;
509 if (pit->params().spaceTop().kind() != VSpace::NONE) {
510 os << pit->params().spaceTop().asLatexCommand(bparams);
511 further_blank_line = true;
514 if (pit->params().lineTop()) {
516 << pit->getFont(bparams, 0, outerFont(pit, paragraphs)).latexSize()
518 << "\\vspace{-1\\parskip}";
519 further_blank_line = true;
522 if (further_blank_line) {
527 style = bparams.getLyXTextClass().defaultLayout();
530 Language const * language = pit->getParLanguage(bparams);
531 Language const * doc_language = bparams.language;
532 Language const * previous_language =
533 (pit != const_cast<ParagraphList&>(paragraphs).begin())
534 ? boost::prior(pit)->getParLanguage(bparams)
537 if (language->babel() != previous_language->babel()
538 // check if we already put language command in TeXEnvironment()
539 && !(style->isEnvironment()
540 && (pit == const_cast<ParagraphList&>(paragraphs).begin() ||
541 (boost::prior(pit)->layout() != pit->layout() &&
542 boost::prior(pit)->getDepth() <= pit->getDepth())
543 || boost::prior(pit)->getDepth() < pit->getDepth())))
545 if (!lyxrc.language_command_end.empty() &&
546 previous_language->babel() != doc_language->babel())
548 os << subst(lyxrc.language_command_end, "$$lang",
549 previous_language->babel())
554 if (lyxrc.language_command_end.empty() ||
555 language->babel() != doc_language->babel())
557 os << subst(lyxrc.language_command_begin, "$$lang",
564 if (bparams.inputenc == "auto" &&
565 language->encoding() != previous_language->encoding()) {
566 os << "\\inputencoding{"
567 << language->encoding()->LatexName()
572 switch (style->latextype) {
574 os << '\\' << style->latexname();
576 // Separate handling of optional argument inset.
577 if (style->optionalargs == 1) {
578 InsetOptArg * it = optArgInset(*pit);
580 it->latexOptional(buf, os, runparams);
583 os << style->latexparam();
585 case LATEX_ITEM_ENVIRONMENT:
586 case LATEX_LIST_ENVIRONMENT:
589 case LATEX_BIB_ENVIRONMENT:
590 // ignore this, the inset will write itself
597 bool need_par = pit->simpleTeXOnePar(buf, bparams,
598 outerFont(pit, paragraphs),
599 os, texrow, runparams);
601 // Make sure that \\par is done with the font of the last
602 // character if this has another size as the default.
603 // This is necessary because LaTeX (and LyX on the screen)
604 // calculates the space between the baselines according
605 // to this font. (Matthias)
607 // Is this really needed ? (Dekel)
608 // We do not need to use to change the font for the last paragraph
610 LyXFont const outerfont(outerFont(pit, paragraphs));
614 ? pit->getLayoutFont(bparams, outerfont)
615 : pit->getFont(bparams, pit->size() - 1, outerfont));
617 bool is_command = style->isCommand();
619 if (style->resfont.size() != font.size()
620 && boost::next(pit) != const_cast<ParagraphList&>(paragraphs).end()
624 os << "\\" << font.latexSize() << " \\par}";
625 } else if (need_par) {
627 } else if (is_command)
630 switch (style->latextype) {
631 case LATEX_ITEM_ENVIRONMENT:
632 case LATEX_LIST_ENVIRONMENT:
633 if (boost::next(pit) != const_cast<ParagraphList&>(paragraphs).end()
634 && (pit->params().depth() < boost::next(pit)->params().depth())) {
639 case LATEX_ENVIRONMENT: {
640 // if its the last paragraph of the current environment
641 // skip it otherwise fall through
642 ParagraphList::iterator next = boost::next(pit);
644 if (next != const_cast<ParagraphList&>(paragraphs).end()
645 && (next->layout() != pit->layout()
646 || next->params().depth() != pit->params().depth()))
650 // fall through possible
652 // we don't need it for the last paragraph!!!
653 if (boost::next(pit) != const_cast<ParagraphList&>(paragraphs).end()) {
659 if (in == 0 || !in->forceDefaultParagraphs(in)) {
660 further_blank_line = false;
661 if (pit->params().lineBottom()) {
662 os << "\\lyxline{\\" << font.latexSize() << '}';
663 further_blank_line = true;
666 if (pit->params().spaceBottom().kind() != VSpace::NONE) {
667 os << pit->params().spaceBottom().asLatexCommand(bparams);
668 further_blank_line = true;
671 if (pit->params().pagebreakBottom()) {
673 further_blank_line = true;
676 if (further_blank_line) {
681 if (!pit->params().spacing().isDefault()
682 && (boost::next(pit) == const_cast<ParagraphList&>(paragraphs).end()|| !boost::next(pit)->hasSameLayout(*pit))) {
683 os << pit->params().spacing().writeEnvirEnd() << '\n';
688 // we don't need it for the last paragraph!!!
689 if (boost::next(pit) != const_cast<ParagraphList&>(paragraphs).end()) {
693 // Since \selectlanguage write the language to the aux file,
694 // we need to reset the language at the end of footnote or
697 if (language->babel() != doc_language->babel()) {
698 if (lyxrc.language_command_end.empty())
699 os << subst(lyxrc.language_command_begin,
701 doc_language->babel())
704 os << subst(lyxrc.language_command_end,
712 lyxerr[Debug::LATEX] << "TeXOnePar...done " << &*boost::next(pit) << endl;
720 // LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
722 void latexParagraphs(Buffer const & buf,
723 ParagraphList const & paragraphs,
726 LatexRunParams const & runparams,
727 string const & everypar)
729 bool was_title = false;
730 bool already_title = false;
731 LyXTextClass const & tclass = buf.params.getLyXTextClass();
732 ParagraphList::iterator par = const_cast<ParagraphList&>(paragraphs).begin();
733 ParagraphList::iterator endpar = const_cast<ParagraphList&>(paragraphs).end();
736 while (par != endpar) {
737 InsetOld * in = par->inInset();
738 // well we have to check if we are in an inset with unlimited
739 // length (all in one row) if that is true then we don't allow
740 // any special options in the paragraph and also we don't allow
741 // any environment other then "Standard" to be valid!
742 if (in == 0 || !in->forceDefaultParagraphs(in)) {
743 LyXLayout_ptr const & layout = par->layout();
745 if (layout->intitle) {
747 lyxerr <<"Error in latexParagraphs: You"
748 " should not mix title layouts"
749 " with normal ones." << endl;
750 } else if (!was_title) {
752 if (tclass.titletype() == TITLE_ENVIRONMENT) {
754 << tclass.titlename()
759 } else if (was_title && !already_title) {
760 if (tclass.titletype() == TITLE_ENVIRONMENT) {
761 os << "\\end{" << tclass.titlename()
765 os << "\\" << tclass.titlename()
769 already_title = true;
773 if (layout->is_environment) {
774 par = TeXOnePar(buf, paragraphs, par, os, texrow,
775 runparams, everypar);
776 } else if (layout->isEnvironment() ||
777 !par->params().leftIndent().zero())
779 par = TeXEnvironment(buf, paragraphs, par, os,
782 par = TeXOnePar(buf, paragraphs, par, os, texrow,
783 runparams, everypar);
786 par = TeXOnePar(buf, paragraphs, par, os, texrow,
787 runparams, everypar);
790 // It might be that we only have a title in this document
791 if (was_title && !already_title) {
792 if (tclass.titletype() == TITLE_ENVIRONMENT) {
793 os << "\\end{" << tclass.titlename()
797 os << "\\" << tclass.titlename()
807 int readParToken(Buffer & buf, Paragraph & par, LyXLex & lex, string const & token)
810 static Change change;
812 BufferParams const & bp = buf.params;
814 if (token[0] != '\\') {
815 string::const_iterator cit = token.begin();
816 for (; cit != token.end(); ++cit) {
817 par.insertChar(par.size(), (*cit), font, change);
819 } else if (token == "\\begin_layout") {
821 string layoutname = lex.getString();
823 font = LyXFont(LyXFont::ALL_INHERIT, bp.language);
826 LyXTextClass const & tclass = bp.getLyXTextClass();
828 if (layoutname.empty()) {
829 layoutname = tclass.defaultLayoutName();
832 bool hasLayout = tclass.hasLayout(layoutname);
835 lyxerr << "Layout '" << layoutname << "' does not"
836 << " exist in textclass '" << tclass.name()
838 lyxerr << "Trying to use default layout instead."
840 layoutname = tclass.defaultLayoutName();
843 par.layout(bp.getLyXTextClass()[layoutname]);
845 // Test whether the layout is obsolete.
846 LyXLayout_ptr const & layout = par.layout();
847 if (!layout->obsoleted_by().empty())
848 par.layout(bp.getLyXTextClass()[layout->obsoleted_by()]);
850 par.params().read(lex);
852 } else if (token == "\\end_layout") {
853 lyxerr << "Solitary \\end_layout in line " << lex.getLineNo() << "\n"
854 << "Missing \\begin_layout?.\n";
855 } else if (token == "\\end_inset") {
856 lyxerr << "Solitary \\end_inset in line " << lex.getLineNo() << "\n"
857 << "Missing \\begin_inset?.\n";
858 } else if (token == "\\begin_inset") {
859 InsetOld * inset = readInset(lex, buf);
860 par.insertInset(par.size(), inset, font, change);
861 } else if (token == "\\family") {
863 font.setLyXFamily(lex.getString());
864 } else if (token == "\\series") {
866 font.setLyXSeries(lex.getString());
867 } else if (token == "\\shape") {
869 font.setLyXShape(lex.getString());
870 } else if (token == "\\size") {
872 font.setLyXSize(lex.getString());
873 } else if (token == "\\lang") {
875 string const tok = lex.getString();
876 Language const * lang = languages.getLanguage(tok);
878 font.setLanguage(lang);
880 font.setLanguage(bp.language);
881 lex.printError("Unknown language `$$Token'");
883 } else if (token == "\\numeric") {
885 font.setNumber(font.setLyXMisc(lex.getString()));
886 } else if (token == "\\emph") {
888 font.setEmph(font.setLyXMisc(lex.getString()));
889 } else if (token == "\\bar") {
891 string const tok = lex.getString();
894 font.setUnderbar(LyXFont::ON);
895 else if (tok == "no")
896 font.setUnderbar(LyXFont::OFF);
897 else if (tok == "default")
898 font.setUnderbar(LyXFont::INHERIT);
900 lex.printError("Unknown bar font flag "
902 } else if (token == "\\noun") {
904 font.setNoun(font.setLyXMisc(lex.getString()));
905 } else if (token == "\\color") {
907 font.setLyXColor(lex.getString());
908 } else if (token == "\\InsetSpace" || token == "\\SpecialChar") {
910 // Insets don't make sense in a free-spacing context! ---Kayvan
911 if (par.isFreeSpacing()) {
912 if (token == "\\InsetSpace")
913 par.insertChar(par.size(), ' ', font, change);
914 else if (lex.isOK()) {
916 string const next_token = lex.getString();
917 if (next_token == "\\-")
918 par.insertChar(par.size(), '-', font, change);
920 lex.printError("Token `$$Token' "
922 "paragraph layout!");
926 InsetOld * inset = 0;
927 if (token == "\\SpecialChar" )
928 inset = new InsetSpecialChar;
930 inset = new InsetSpace;
931 inset->read(buf, lex);
932 par.insertInset(par.size(), inset, font, change);
934 } else if (token == "\\i") {
935 InsetOld * inset = new InsetLatexAccent;
936 inset->read(buf, lex);
937 par.insertInset(par.size(), inset, font, change);
938 } else if (token == "\\backslash") {
939 par.insertChar(par.size(), '\\', font, change);
940 } else if (token == "\\newline") {
941 InsetOld * inset = new InsetNewline;
942 inset->read(buf, lex);
943 par.insertInset(par.size(), inset, font, change);
944 } else if (token == "\\LyXTable") {
945 InsetOld * inset = new InsetTabular(buf);
946 inset->read(buf, lex);
947 par.insertInset(par.size(), inset, font, change);
948 } else if (token == "\\bibitem") {
949 InsetCommandParams p("bibitem", "dummy");
950 InsetBibitem * inset = new InsetBibitem(p);
951 inset->read(buf, lex);
952 par.insertInset(par.size(), inset, font, change);
953 } else if (token == "\\hfill") {
954 par.insertInset(par.size(), new InsetHFill, font, change);
955 } else if (token == "\\change_unchanged") {
956 // Hack ! Needed for empty paragraphs :/
957 // FIXME: is it still ??
960 change = Change(Change::UNCHANGED);
961 } else if (token == "\\change_inserted") {
963 istringstream is(STRCONV(lex.getString()));
967 change = Change(Change::INSERTED, bp.author_map[aid], ct);
968 } else if (token == "\\change_deleted") {
970 istringstream is(STRCONV(lex.getString()));
974 change = Change(Change::DELETED, bp.author_map[aid], ct);
977 string const s = bformat(_("Unknown token: %1$s %2$s\n"),
978 token, lex.getString());
980 buf.error(ErrorItem(_("Unknown token"), s,
981 par.id(), 0, par.size()));
990 int readParagraph(Buffer & buf, Paragraph & par, LyXLex & lex)
995 string token = lex.getString();
999 unknown += readParToken(buf, par, lex, token);
1002 token = lex.getString();
1007 if (token == "\\end_layout") {
1008 //Ok, paragraph finished
1012 lyxerr[Debug::PARSER] << "Handling paragraph token: `"
1013 << token << '\'' << endl;
1014 if (token == "\\begin_layout" || token == "\\end_document"
1015 || token == "\\end_inset" || token == "\\begin_deeper"
1016 || token == "\\end_deeper") {
1017 lex.pushToken(token);
1018 lyxerr << "Paragraph ended in line "
1019 << lex.getLineNo() << "\n"
1020 << "Missing \\end_layout.\n";
1029 LyXFont const outerFont(ParagraphList::iterator pit,
1030 ParagraphList const & plist)
1032 Paragraph::depth_type par_depth = pit->getDepth();
1033 LyXFont tmpfont(LyXFont::ALL_INHERIT);
1035 // Resolve against environment font information
1036 while (pit != const_cast<ParagraphList&>(plist).end() &&
1037 par_depth && !tmpfont.resolved()) {
1038 pit = outerHook(pit, plist);
1039 if (pit != const_cast<ParagraphList&>(plist).end()) {
1040 tmpfont.realize(pit->layout()->font);
1041 par_depth = pit->getDepth();
1049 ParagraphList::iterator outerPar(Buffer const & buf, InsetOld const * inset)
1051 ParIterator pit = const_cast<Buffer &>(buf).par_iterator_begin();
1052 ParIterator end = const_cast<Buffer &>(buf).par_iterator_end();
1053 for ( ; pit != end; ++pit) {
1055 ParagraphList * plist;
1056 // the second '=' below is intentional
1057 for (int i = 0; (plist = inset->getParagraphs(i)); ++i)
1058 if (plist == &pit.plist())
1059 return pit.outerPar();
1061 InsetList::iterator ii = pit->insetlist.begin();
1062 InsetList::iterator iend = pit->insetlist.end();
1063 for ( ; ii != iend; ++ii)
1064 if (ii->inset == inset)
1065 return pit.outerPar();
1067 lyxerr << "outerPar: should not happen" << endl;
1069 return const_cast<Buffer &>(buf).paragraphs.end(); // shut up compiler
1073 Paragraph const & ownerPar(Buffer const & buf, InsetOld const * inset)
1075 ParConstIterator pit = buf.par_iterator_begin();
1076 ParConstIterator end = buf.par_iterator_end();
1077 for ( ; pit != end; ++pit) {
1078 ParagraphList * plist;
1079 // the second '=' below is intentional
1080 for (int i = 0; (plist = inset->getParagraphs(i)); ++i)
1081 if (plist == &pit.plist())
1084 InsetList::const_iterator ii = pit->insetlist.begin();
1085 InsetList::const_iterator iend = pit->insetlist.end();
1086 for ( ; ii != iend; ++ii)
1087 if (ii->inset == inset)
1090 lyxerr << "ownerPar: should not happen" << endl;
1092 return buf.paragraphs.front(); // shut up compiler