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"
23 #include "support/std_sstream.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;
44 using std::istringstream;
50 bool moveItem(Paragraph & from, Paragraph & to,
51 BufferParams const & params, pos_type i, pos_type j)
53 char const tmpchar = from.getChar(i);
54 LyXFont tmpfont = from.getFontSettings(params, i);
56 if (tmpchar == Paragraph::META_INSET) {
57 InsetOld * tmpinset = 0;
58 if (from.getInset(i)) {
59 // the inset is not in a paragraph anymore
60 tmpinset = from.insetlist.release(i);
63 if (!to.insetAllowed(tmpinset->lyxCode()))
65 to.insertInset(j, tmpinset, tmpfont);
67 if (!to.checkInsertChar(tmpfont))
69 to.insertChar(j, tmpchar, tmpfont);
77 void breakParagraph(BufferParams const & bparams,
78 ParagraphList & paragraphs,
79 ParagraphList::iterator par,
83 // create a new paragraph, and insert into the list
84 ParagraphList::iterator tmp = paragraphs.insert(boost::next(par),
87 // without doing that we get a crash when typing <Return> at the
89 tmp->layout(bparams.getLyXTextClass().defaultLayout());
90 // remember to set the inset_owner
91 tmp->setInsetOwner(par->inInset());
93 if (bparams.tracking_changes)
96 // this is an idea for a more userfriendly layout handling, I will
97 // see what the users say
99 // layout stays the same with latex-environments
101 tmp->layout(par->layout());
102 tmp->setLabelWidthString(par->params().labelWidthString());
105 bool const isempty = (par->allowEmpty() && par->empty());
107 if (!isempty && (par->size() > pos || par->empty() || flag == 2)) {
108 tmp->layout(par->layout());
109 tmp->params().align(par->params().align());
110 tmp->setLabelWidthString(par->params().labelWidthString());
112 tmp->params().lineBottom(par->params().lineBottom());
113 par->params().lineBottom(false);
114 tmp->params().pagebreakBottom(par->params().pagebreakBottom());
115 par->params().pagebreakBottom(false);
116 tmp->params().spaceBottom(par->params().spaceBottom());
117 par->params().spaceBottom(VSpace(VSpace::NONE));
119 tmp->params().depth(par->params().depth());
120 tmp->params().noindent(par->params().noindent());
122 // copy everything behind the break-position
123 // to the new paragraph
126 #warning this seems wrong
128 /* FIXME: if !keepempty, empty() == true, then we reach
129 * here with size() == 0. So pos_end becomes - 1. Why
130 * doesn't this cause problems ???
132 pos_type pos_end = par->size() - 1;
136 for (; i <= pos_end; ++i) {
137 Change::Type change = par->lookupChange(i);
138 if (moveItem(*par, *tmp, bparams, i, j - pos)) {
139 tmp->setChange(j - pos, change);
144 for (i = pos_end; i >= pos; --i)
151 tmp->params().lineTop(par->params().lineTop());
152 tmp->params().pagebreakTop(par->params().pagebreakTop());
153 tmp->params().spaceTop(par->params().spaceTop());
154 par->params().clear();
156 par->layout(bparams.getLyXTextClass().defaultLayout());
158 // layout stays the same with latex-environments
160 par->layout(tmp->layout());
161 par->setLabelWidthString(tmp->params().labelWidthString());
162 par->params().depth(tmp->params().depth());
165 // subtle, but needed to get empty pars working right
166 if (bparams.tracking_changes) {
169 } else if (!tmp->size()) {
176 void breakParagraphConservative(BufferParams const & bparams,
177 ParagraphList & paragraphs,
178 ParagraphList::iterator par,
181 // create a new paragraph
182 ParagraphList::iterator tmp = paragraphs.insert(boost::next(par),
184 tmp->makeSameLayout(*par);
186 // When can pos > size()?
187 // I guess pos == size() is possible.
188 if (par->size() > pos) {
189 // copy everything behind the break-position to the new
191 pos_type pos_end = par->size() - 1;
193 for (pos_type i = pos, j = pos; i <= pos_end; ++i)
194 if (moveItem(*par, *tmp, bparams, i, j - pos))
197 for (pos_type k = pos_end; k >= pos; --k)
203 void mergeParagraph(BufferParams const & bparams,
204 ParagraphList & paragraphs,
205 ParagraphList::iterator par)
207 ParagraphList::iterator the_next = boost::next(par);
209 // first the DTP-stuff
210 par->params().lineBottom(the_next->params().lineBottom());
211 par->params().spaceBottom(the_next->params().spaceBottom());
212 par->params().pagebreakBottom(the_next->params().pagebreakBottom());
214 pos_type pos_end = the_next->size() - 1;
215 pos_type pos_insert = par->size();
217 // ok, now copy the paragraph
218 for (pos_type i = 0, j = 0; i <= pos_end; ++i)
219 if (moveItem(*the_next, *par, bparams, i, pos_insert + j))
222 paragraphs.erase(the_next);
226 ParagraphList::iterator depthHook(ParagraphList::iterator pit,
227 ParagraphList const & plist,
228 Paragraph::depth_type depth)
230 ParagraphList::iterator newpit = pit;
231 ParagraphList::iterator beg = const_cast<ParagraphList&>(plist).begin();
236 while (newpit != beg && newpit->getDepth() > depth) {
240 if (newpit->getDepth() > depth)
247 ParagraphList::iterator outerHook(ParagraphList::iterator pit,
248 ParagraphList const & plist)
250 if (!pit->getDepth())
251 return const_cast<ParagraphList&>(plist).end();
252 return depthHook(pit, plist,
253 Paragraph::depth_type(pit->getDepth() - 1));
257 bool isFirstInSequence(ParagraphList::iterator pit,
258 ParagraphList const & plist)
260 ParagraphList::iterator dhook = depthHook(pit, plist, pit->getDepth());
262 || dhook->layout() != pit->layout()
263 || dhook->getDepth() != pit->getDepth());
267 int getEndLabel(ParagraphList::iterator p, ParagraphList const & plist)
269 ParagraphList::iterator pit = p;
270 Paragraph::depth_type par_depth = p->getDepth();
271 while (pit != const_cast<ParagraphList&>(plist).end()) {
272 LyXLayout_ptr const & layout = pit->layout();
273 int const endlabeltype = layout->endlabeltype;
275 if (endlabeltype != END_LABEL_NO_LABEL) {
276 if (boost::next(p) == const_cast<ParagraphList&>(plist).end())
279 Paragraph::depth_type const next_depth = boost::next(p)->getDepth();
280 if (par_depth > next_depth ||
281 (par_depth == next_depth &&
282 layout != boost::next(p)->layout()))
288 pit = outerHook(pit, plist);
289 if (pit != const_cast<ParagraphList&>(plist).end())
290 par_depth = pit->getDepth();
292 return END_LABEL_NO_LABEL;
298 ParagraphList::iterator
299 TeXEnvironment(Buffer const & buf,
300 ParagraphList const & paragraphs,
301 ParagraphList::iterator pit,
302 ostream & os, TexRow & texrow,
303 LatexRunParams const & runparams);
305 ParagraphList::iterator
306 TeXOnePar(Buffer const & buf,
307 ParagraphList const & paragraphs,
308 ParagraphList::iterator pit,
309 ostream & os, TexRow & texrow,
310 LatexRunParams const & runparams,
311 string const & everypar = string());
314 ParagraphList::iterator
315 TeXDeeper(Buffer const & buf,
316 ParagraphList const & paragraphs,
317 ParagraphList::iterator pit,
318 ostream & os, TexRow & texrow,
319 LatexRunParams const & runparams)
321 lyxerr[Debug::LATEX] << "TeXDeeper... " << &*pit << endl;
322 ParagraphList::iterator par = pit;
324 while (par != const_cast<ParagraphList&>(paragraphs).end() &&
325 par->params().depth() == pit->params().depth()) {
326 if (par->layout()->isEnvironment()) {
327 par = TeXEnvironment(buf, paragraphs, par,
328 os, texrow, runparams);
330 par = TeXOnePar(buf, paragraphs, par,
331 os, texrow, runparams);
334 lyxerr[Debug::LATEX] << "TeXDeeper...done " << &*par << endl;
340 ParagraphList::iterator
341 TeXEnvironment(Buffer const & buf,
342 ParagraphList const & paragraphs,
343 ParagraphList::iterator pit,
344 ostream & os, TexRow & texrow,
345 LatexRunParams const & runparams)
347 lyxerr[Debug::LATEX] << "TeXEnvironment... " << &*pit << endl;
349 BufferParams const & bparams = buf.params;
351 LyXLayout_ptr const & style = pit->layout();
353 Language const * language = pit->getParLanguage(bparams);
354 Language const * doc_language = bparams.language;
355 Language const * previous_language =
356 (pit != const_cast<ParagraphList&>(paragraphs).begin())
357 ? boost::prior(pit)->getParLanguage(bparams)
359 if (language->babel() != previous_language->babel()) {
361 if (!lyxrc.language_command_end.empty() &&
362 previous_language->babel() != doc_language->babel()) {
363 os << subst(lyxrc.language_command_end, "$$lang",
364 previous_language->babel())
369 if (lyxrc.language_command_end.empty() ||
370 language->babel() != doc_language->babel()) {
371 os << subst(lyxrc.language_command_begin, "$$lang",
378 bool leftindent_open = false;
379 if (!pit->params().leftIndent().zero()) {
380 os << "\\begin{LyXParagraphLeftIndent}{" <<
381 pit->params().leftIndent().asLatexString() << "}\n";
383 leftindent_open = true;
386 if (style->isEnvironment()) {
387 if (style->latextype == LATEX_LIST_ENVIRONMENT) {
388 os << "\\begin{" << style->latexname() << "}{"
389 << pit->params().labelWidthString() << "}\n";
390 } else if (style->labeltype == LABEL_BIBLIO) {
392 os << "\\begin{" << style->latexname() << "}{"
393 << bibitemWidest(buf)
395 } else if (style->latextype == LATEX_ITEM_ENVIRONMENT) {
396 os << "\\begin{" << style->latexname() << '}'
397 << style->latexparam() << '\n';
399 os << "\\begin{" << style->latexname() << '}'
400 << style->latexparam() << '\n';
403 ParagraphList::iterator par = pit;
405 par = TeXOnePar(buf, paragraphs, par, os, texrow, runparams);
407 if (par != const_cast<ParagraphList&>(paragraphs).end() && par->params().depth() > pit->params().depth()) {
408 if (par->layout()->isParagraph()) {
411 // How to handle this? (Lgb)
412 //&& !suffixIs(os, "\n\n")
414 // There should be at least one '\n' already
415 // but we need there to be two for Standard
416 // paragraphs that are depth-increment'ed to be
417 // output correctly. However, tables can
418 // also be paragraphs so don't adjust them.
421 // Will it ever harm to have one '\n' too
422 // many? i.e. that we sometimes will have
423 // three in a row. (Lgb)
427 par = TeXDeeper(buf, paragraphs, par, os, texrow,
430 } while (par != const_cast<ParagraphList&>(paragraphs).end()
431 && par->layout() == pit->layout()
432 && par->params().depth() == pit->params().depth()
433 && par->params().leftIndent() == pit->params().leftIndent());
435 if (style->isEnvironment()) {
436 os << "\\end{" << style->latexname() << "}\n";
440 if (leftindent_open) {
441 os << "\\end{LyXParagraphLeftIndent}\n";
445 lyxerr[Debug::LATEX] << "TeXEnvironment...done " << &*par << endl;
446 return par; // ale970302
450 InsetOptArg * optArgInset(Paragraph const & par)
453 InsetList::const_iterator it = par.insetlist.begin();
454 InsetList::const_iterator end = par.insetlist.end();
455 for (; it != end; ++it) {
456 InsetOld * ins = it->inset;
457 if (ins->lyxCode() == InsetOld::OPTARG_CODE) {
458 return static_cast<InsetOptArg *>(ins);
465 ParagraphList::iterator
466 TeXOnePar(Buffer const & buf,
467 ParagraphList const & paragraphs,
468 ParagraphList::iterator pit,
469 ostream & os, TexRow & texrow,
470 LatexRunParams const & runparams,
471 string const & everypar)
473 lyxerr[Debug::LATEX] << "TeXOnePar... " << &*pit << " '"
474 << everypar << "'" << endl;
475 BufferParams const & bparams = buf.params;
477 InsetOld const * in = pit->inInset();
478 bool further_blank_line = false;
481 // well we have to check if we are in an inset with unlimited
482 // length (all in one row) if that is true then we don't allow
483 // any special options in the paragraph and also we don't allow
484 // any environment other then "Standard" to be valid!
485 if (in == 0 || !in->forceDefaultParagraphs(in)) {
486 style = pit->layout();
488 if (pit->params().startOfAppendix()) {
489 os << "\\appendix\n";
493 if (!pit->params().spacing().isDefault()
494 && (pit == const_cast<ParagraphList&>(paragraphs).begin() || !boost::prior(pit)->hasSameLayout(*pit))) {
495 os << pit->params().spacing().writeEnvirBegin() << '\n';
499 if (style->isCommand()) {
504 if (pit->params().pagebreakTop()) {
506 further_blank_line = true;
508 if (pit->params().spaceTop().kind() != VSpace::NONE) {
509 os << pit->params().spaceTop().asLatexCommand(bparams);
510 further_blank_line = true;
513 if (pit->params().lineTop()) {
515 << pit->getFont(bparams, 0, outerFont(pit, paragraphs)).latexSize()
517 << "\\vspace{-1\\parskip}";
518 further_blank_line = true;
521 if (further_blank_line) {
526 style = bparams.getLyXTextClass().defaultLayout();
529 Language const * language = pit->getParLanguage(bparams);
530 Language const * doc_language = bparams.language;
531 Language const * previous_language =
532 (pit != const_cast<ParagraphList&>(paragraphs).begin())
533 ? boost::prior(pit)->getParLanguage(bparams)
536 if (language->babel() != previous_language->babel()
537 // check if we already put language command in TeXEnvironment()
538 && !(style->isEnvironment()
539 && (pit == const_cast<ParagraphList&>(paragraphs).begin() ||
540 (boost::prior(pit)->layout() != pit->layout() &&
541 boost::prior(pit)->getDepth() <= pit->getDepth())
542 || boost::prior(pit)->getDepth() < pit->getDepth())))
544 if (!lyxrc.language_command_end.empty() &&
545 previous_language->babel() != doc_language->babel())
547 os << subst(lyxrc.language_command_end, "$$lang",
548 previous_language->babel())
553 if (lyxrc.language_command_end.empty() ||
554 language->babel() != doc_language->babel())
556 os << subst(lyxrc.language_command_begin, "$$lang",
563 if (bparams.inputenc == "auto" &&
564 language->encoding() != previous_language->encoding()) {
565 os << "\\inputencoding{"
566 << language->encoding()->LatexName()
571 switch (style->latextype) {
573 os << '\\' << style->latexname();
575 // Separate handling of optional argument inset.
576 if (style->optionalargs == 1) {
577 InsetOptArg * it = optArgInset(*pit);
579 it->latexOptional(buf, os, runparams);
582 os << style->latexparam();
584 case LATEX_ITEM_ENVIRONMENT:
585 case LATEX_LIST_ENVIRONMENT:
588 case LATEX_BIB_ENVIRONMENT:
589 // ignore this, the inset will write itself
596 bool need_par = pit->simpleTeXOnePar(buf, bparams,
597 outerFont(pit, paragraphs),
598 os, texrow, runparams);
600 // Make sure that \\par is done with the font of the last
601 // character if this has another size as the default.
602 // This is necessary because LaTeX (and LyX on the screen)
603 // calculates the space between the baselines according
604 // to this font. (Matthias)
606 // Is this really needed ? (Dekel)
607 // We do not need to use to change the font for the last paragraph
609 LyXFont const outerfont(outerFont(pit, paragraphs));
613 ? pit->getLayoutFont(bparams, outerfont)
614 : pit->getFont(bparams, pit->size() - 1, outerfont));
616 bool is_command = style->isCommand();
618 if (style->resfont.size() != font.size()
619 && boost::next(pit) != const_cast<ParagraphList&>(paragraphs).end()
623 os << "\\" << font.latexSize() << " \\par}";
624 } else if (need_par) {
626 } else if (is_command)
629 switch (style->latextype) {
630 case LATEX_ITEM_ENVIRONMENT:
631 case LATEX_LIST_ENVIRONMENT:
632 if (boost::next(pit) != const_cast<ParagraphList&>(paragraphs).end()
633 && (pit->params().depth() < boost::next(pit)->params().depth())) {
638 case LATEX_ENVIRONMENT: {
639 // if its the last paragraph of the current environment
640 // skip it otherwise fall through
641 ParagraphList::iterator next = boost::next(pit);
643 if (next != const_cast<ParagraphList&>(paragraphs).end()
644 && (next->layout() != pit->layout()
645 || next->params().depth() != pit->params().depth()))
649 // fall through possible
651 // we don't need it for the last paragraph!!!
652 if (boost::next(pit) != const_cast<ParagraphList&>(paragraphs).end()) {
658 if (in == 0 || !in->forceDefaultParagraphs(in)) {
659 further_blank_line = false;
660 if (pit->params().lineBottom()) {
661 os << "\\lyxline{\\" << font.latexSize() << '}';
662 further_blank_line = true;
665 if (pit->params().spaceBottom().kind() != VSpace::NONE) {
666 os << pit->params().spaceBottom().asLatexCommand(bparams);
667 further_blank_line = true;
670 if (pit->params().pagebreakBottom()) {
672 further_blank_line = true;
675 if (further_blank_line) {
680 if (!pit->params().spacing().isDefault()
681 && (boost::next(pit) == const_cast<ParagraphList&>(paragraphs).end()|| !boost::next(pit)->hasSameLayout(*pit))) {
682 os << pit->params().spacing().writeEnvirEnd() << '\n';
687 // we don't need it for the last paragraph!!!
688 if (boost::next(pit) != const_cast<ParagraphList&>(paragraphs).end()) {
692 // Since \selectlanguage write the language to the aux file,
693 // we need to reset the language at the end of footnote or
696 if (language->babel() != doc_language->babel()) {
697 if (lyxrc.language_command_end.empty())
698 os << subst(lyxrc.language_command_begin,
700 doc_language->babel())
703 os << subst(lyxrc.language_command_end,
711 lyxerr[Debug::LATEX] << "TeXOnePar...done " << &*boost::next(pit) << endl;
719 // LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
721 void latexParagraphs(Buffer const & buf,
722 ParagraphList const & paragraphs,
725 LatexRunParams const & runparams,
726 string const & everypar)
728 bool was_title = false;
729 bool already_title = false;
730 LyXTextClass const & tclass = buf.params.getLyXTextClass();
731 ParagraphList::iterator par = const_cast<ParagraphList&>(paragraphs).begin();
732 ParagraphList::iterator endpar = const_cast<ParagraphList&>(paragraphs).end();
735 while (par != endpar) {
736 InsetOld * in = par->inInset();
737 // well we have to check if we are in an inset with unlimited
738 // length (all in one row) if that is true then we don't allow
739 // any special options in the paragraph and also we don't allow
740 // any environment other then "Standard" to be valid!
741 if (in == 0 || !in->forceDefaultParagraphs(in)) {
742 LyXLayout_ptr const & layout = par->layout();
744 if (layout->intitle) {
746 lyxerr <<"Error in latexParagraphs: You"
747 " should not mix title layouts"
748 " with normal ones." << endl;
749 } else if (!was_title) {
751 if (tclass.titletype() == TITLE_ENVIRONMENT) {
753 << tclass.titlename()
758 } else if (was_title && !already_title) {
759 if (tclass.titletype() == TITLE_ENVIRONMENT) {
760 os << "\\end{" << tclass.titlename()
764 os << "\\" << tclass.titlename()
768 already_title = true;
772 if (layout->is_environment) {
773 par = TeXOnePar(buf, paragraphs, par, os, texrow,
774 runparams, everypar);
775 } else if (layout->isEnvironment() ||
776 !par->params().leftIndent().zero())
778 par = TeXEnvironment(buf, paragraphs, par, os,
781 par = TeXOnePar(buf, paragraphs, par, os, texrow,
782 runparams, everypar);
785 par = TeXOnePar(buf, paragraphs, par, os, texrow,
786 runparams, everypar);
789 // It might be that we only have a title in this document
790 if (was_title && !already_title) {
791 if (tclass.titletype() == TITLE_ENVIRONMENT) {
792 os << "\\end{" << tclass.titlename()
796 os << "\\" << tclass.titlename()
806 int readParToken(Buffer & buf, Paragraph & par, LyXLex & lex, string const & token)
809 static Change change;
811 BufferParams const & bp = buf.params;
813 if (token[0] != '\\') {
814 string::const_iterator cit = token.begin();
815 for (; cit != token.end(); ++cit) {
816 par.insertChar(par.size(), (*cit), font, change);
818 } else if (token == "\\begin_layout") {
820 string layoutname = lex.getString();
822 font = LyXFont(LyXFont::ALL_INHERIT, bp.language);
825 LyXTextClass const & tclass = bp.getLyXTextClass();
827 if (layoutname.empty()) {
828 layoutname = tclass.defaultLayoutName();
831 bool hasLayout = tclass.hasLayout(layoutname);
834 lyxerr << "Layout '" << layoutname << "' does not"
835 << " exist in textclass '" << tclass.name()
837 lyxerr << "Trying to use default layout instead."
839 layoutname = tclass.defaultLayoutName();
842 par.layout(bp.getLyXTextClass()[layoutname]);
844 // Test whether the layout is obsolete.
845 LyXLayout_ptr const & layout = par.layout();
846 if (!layout->obsoleted_by().empty())
847 par.layout(bp.getLyXTextClass()[layout->obsoleted_by()]);
849 par.params().read(lex);
851 } else if (token == "\\end_layout") {
852 lyxerr << "Solitary \\end_layout in line " << lex.getLineNo() << "\n"
853 << "Missing \\begin_layout?.\n";
854 } else if (token == "\\end_inset") {
855 lyxerr << "Solitary \\end_inset in line " << lex.getLineNo() << "\n"
856 << "Missing \\begin_inset?.\n";
857 } else if (token == "\\begin_inset") {
858 InsetOld * inset = readInset(lex, buf);
859 par.insertInset(par.size(), inset, font, change);
860 } else if (token == "\\family") {
862 font.setLyXFamily(lex.getString());
863 } else if (token == "\\series") {
865 font.setLyXSeries(lex.getString());
866 } else if (token == "\\shape") {
868 font.setLyXShape(lex.getString());
869 } else if (token == "\\size") {
871 font.setLyXSize(lex.getString());
872 } else if (token == "\\lang") {
874 string const tok = lex.getString();
875 Language const * lang = languages.getLanguage(tok);
877 font.setLanguage(lang);
879 font.setLanguage(bp.language);
880 lex.printError("Unknown language `$$Token'");
882 } else if (token == "\\numeric") {
884 font.setNumber(font.setLyXMisc(lex.getString()));
885 } else if (token == "\\emph") {
887 font.setEmph(font.setLyXMisc(lex.getString()));
888 } else if (token == "\\bar") {
890 string const tok = lex.getString();
893 font.setUnderbar(LyXFont::ON);
894 else if (tok == "no")
895 font.setUnderbar(LyXFont::OFF);
896 else if (tok == "default")
897 font.setUnderbar(LyXFont::INHERIT);
899 lex.printError("Unknown bar font flag "
901 } else if (token == "\\noun") {
903 font.setNoun(font.setLyXMisc(lex.getString()));
904 } else if (token == "\\color") {
906 font.setLyXColor(lex.getString());
907 } else if (token == "\\InsetSpace" || token == "\\SpecialChar") {
909 // Insets don't make sense in a free-spacing context! ---Kayvan
910 if (par.isFreeSpacing()) {
911 if (token == "\\InsetSpace")
912 par.insertChar(par.size(), ' ', font, change);
913 else if (lex.isOK()) {
915 string const next_token = lex.getString();
916 if (next_token == "\\-")
917 par.insertChar(par.size(), '-', font, change);
919 lex.printError("Token `$$Token' "
921 "paragraph layout!");
925 InsetOld * inset = 0;
926 if (token == "\\SpecialChar" )
927 inset = new InsetSpecialChar;
929 inset = new InsetSpace;
930 inset->read(buf, lex);
931 par.insertInset(par.size(), inset, font, change);
933 } else if (token == "\\i") {
934 InsetOld * inset = new InsetLatexAccent;
935 inset->read(buf, lex);
936 par.insertInset(par.size(), inset, font, change);
937 } else if (token == "\\backslash") {
938 par.insertChar(par.size(), '\\', font, change);
939 } else if (token == "\\newline") {
940 InsetOld * inset = new InsetNewline;
941 inset->read(buf, lex);
942 par.insertInset(par.size(), inset, font, change);
943 } else if (token == "\\LyXTable") {
944 InsetOld * inset = new InsetTabular(buf);
945 inset->read(buf, lex);
946 par.insertInset(par.size(), inset, font, change);
947 } else if (token == "\\bibitem") {
948 InsetCommandParams p("bibitem", "dummy");
949 InsetBibitem * inset = new InsetBibitem(p);
950 inset->read(buf, lex);
951 par.insertInset(par.size(), inset, font, change);
952 } else if (token == "\\hfill") {
953 par.insertInset(par.size(), new InsetHFill, font, change);
954 } else if (token == "\\change_unchanged") {
955 // Hack ! Needed for empty paragraphs :/
956 // FIXME: is it still ??
959 change = Change(Change::UNCHANGED);
960 } else if (token == "\\change_inserted") {
962 istringstream is(STRCONV(lex.getString()));
966 change = Change(Change::INSERTED, bp.author_map[aid], ct);
967 } else if (token == "\\change_deleted") {
969 istringstream is(STRCONV(lex.getString()));
973 change = Change(Change::DELETED, bp.author_map[aid], ct);
976 string const s = bformat(_("Unknown token: %1$s %2$s\n"),
977 token, lex.getString());
979 buf.error(ErrorItem(_("Unknown token"), s,
980 par.id(), 0, par.size()));
989 int readParagraph(Buffer & buf, Paragraph & par, LyXLex & lex)
994 string token = lex.getString();
998 unknown += readParToken(buf, par, lex, token);
1001 token = lex.getString();
1006 if (token == "\\end_layout") {
1007 //Ok, paragraph finished
1011 lyxerr[Debug::PARSER] << "Handling paragraph token: `"
1012 << token << '\'' << endl;
1013 if (token == "\\begin_layout" || token == "\\end_document"
1014 || token == "\\end_inset" || token == "\\begin_deeper"
1015 || token == "\\end_deeper") {
1016 lex.pushToken(token);
1017 lyxerr << "Paragraph ended in line "
1018 << lex.getLineNo() << "\n"
1019 << "Missing \\end_layout.\n";
1028 LyXFont const outerFont(ParagraphList::iterator pit,
1029 ParagraphList const & plist)
1031 Paragraph::depth_type par_depth = pit->getDepth();
1032 LyXFont tmpfont(LyXFont::ALL_INHERIT);
1034 // Resolve against environment font information
1035 while (pit != const_cast<ParagraphList&>(plist).end() &&
1036 par_depth && !tmpfont.resolved()) {
1037 pit = outerHook(pit, plist);
1038 if (pit != const_cast<ParagraphList&>(plist).end()) {
1039 tmpfont.realize(pit->layout()->font);
1040 par_depth = pit->getDepth();
1048 ParagraphList::iterator outerPar(Buffer const & buf, InsetOld const * inset)
1050 ParIterator pit = const_cast<Buffer &>(buf).par_iterator_begin();
1051 ParIterator end = const_cast<Buffer &>(buf).par_iterator_end();
1052 for ( ; pit != end; ++pit) {
1054 ParagraphList * plist;
1055 // the second '=' below is intentional
1056 for (int i = 0; (plist = inset->getParagraphs(i)); ++i)
1057 if (plist == &pit.plist())
1058 return pit.outerPar();
1060 InsetList::iterator ii = pit->insetlist.begin();
1061 InsetList::iterator iend = pit->insetlist.end();
1062 for ( ; ii != iend; ++ii)
1063 if (ii->inset == inset)
1064 return pit.outerPar();
1066 lyxerr << "outerPar: should not happen" << endl;
1068 return const_cast<Buffer &>(buf).paragraphs.end(); // shut up compiler
1072 Paragraph const & ownerPar(Buffer const & buf, InsetOld const * inset)
1074 ParConstIterator pit = buf.par_iterator_begin();
1075 ParConstIterator end = buf.par_iterator_end();
1076 for ( ; pit != end; ++pit) {
1077 ParagraphList * plist;
1078 // the second '=' below is intentional
1079 for (int i = 0; (plist = inset->getParagraphs(i)); ++i)
1080 if (plist == &pit.plist())
1083 InsetList::const_iterator ii = pit->insetlist.begin();
1084 InsetList::const_iterator iend = pit->insetlist.end();
1085 for ( ; ii != iend; ++ii)
1086 if (ii->inset == inset)
1089 lyxerr << "ownerPar: should not happen" << endl;
1091 return buf.paragraphs.front(); // shut up compiler