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"
26 #include "support/lstrings.h"
27 #include "insets/insetoptarg.h"
28 #include "insets/insetcommandparams.h"
29 #include "insets/insetbibitem.h"
30 #include "insets/insetspecialchar.h"
31 #include "insets/insetlatexaccent.h"
32 #include "insets/insettabular.h"
33 #include "insets/insethfill.h"
34 #include "insets/inseterror.h"
35 #include "insets/insetnewline.h"
37 extern string bibitemWidest(Buffer const *);
40 //using lyx::layout_type;
44 void breakParagraph(BufferParams const & bparams,
45 ParagraphList & paragraphs,
46 ParagraphList::iterator par,
50 // create a new paragraph, and insert into the list
51 ParagraphList::iterator tmp = paragraphs.insert(boost::next(par),
54 // without doing that we get a crash when typing <Return> at the
56 tmp->layout(bparams.getLyXTextClass().defaultLayout());
57 // remember to set the inset_owner
58 tmp->setInsetOwner(par->inInset());
60 if (bparams.tracking_changes)
63 // this is an idea for a more userfriendly layout handling, I will
64 // see what the users say
66 // layout stays the same with latex-environments
68 tmp->layout(par->layout());
69 tmp->setLabelWidthString(par->params().labelWidthString());
72 bool const isempty = (par->layout()->keepempty && par->empty());
74 if (!isempty && (par->size() > pos || par->empty() || flag == 2)) {
75 tmp->layout(par->layout());
76 tmp->params().align(par->params().align());
77 tmp->setLabelWidthString(par->params().labelWidthString());
79 tmp->params().lineBottom(par->params().lineBottom());
80 par->params().lineBottom(false);
81 tmp->params().pagebreakBottom(par->params().pagebreakBottom());
82 par->params().pagebreakBottom(false);
83 tmp->params().spaceBottom(par->params().spaceBottom());
84 par->params().spaceBottom(VSpace(VSpace::NONE));
86 tmp->params().depth(par->params().depth());
87 tmp->params().noindent(par->params().noindent());
89 // copy everything behind the break-position
90 // to the new paragraph
93 #warning this seems wrong
95 /* FIXME: if !keepempty, empty() == true, then we reach
96 * here with size() == 0. So pos_end becomes - 1. Why
97 * doesn't this cause problems ???
99 pos_type pos_end = par->size() - 1;
103 for (; i <= pos_end; ++i) {
104 Change::Type change(par->lookupChange(i));
105 par->cutIntoMinibuffer(bparams, i);
106 if (tmp->insertFromMinibuffer(j - pos)) {
107 tmp->setChange(j - pos, change);
111 for (i = pos_end; i >= pos; --i) {
119 tmp->params().lineTop(par->params().lineTop());
120 tmp->params().pagebreakTop(par->params().pagebreakTop());
121 tmp->params().spaceTop(par->params().spaceTop());
122 par->params().clear();
124 par->layout(bparams.getLyXTextClass().defaultLayout());
126 // layout stays the same with latex-environments
128 par->layout(tmp->layout());
129 par->setLabelWidthString(tmp->params().labelWidthString());
130 par->params().depth(tmp->params().depth());
133 // subtle, but needed to get empty pars working right
134 if (bparams.tracking_changes) {
137 } else if (!tmp->size()) {
144 void breakParagraphConservative(BufferParams const & bparams,
145 ParagraphList & paragraphs,
146 ParagraphList::iterator par,
149 // create a new paragraph
150 ParagraphList::iterator tmp = paragraphs.insert(boost::next(par),
152 tmp->makeSameLayout(*par);
154 // When can pos > size()?
155 // I guess pos == size() is possible.
156 if (par->size() > pos) {
157 // copy everything behind the break-position to the new
159 pos_type pos_end = par->size() - 1;
161 for (pos_type i = pos, j = pos; i <= pos_end; ++i) {
162 par->cutIntoMinibuffer(bparams, i);
163 if (tmp->insertFromMinibuffer(j - pos))
167 for (pos_type k = pos_end; k >= pos; --k) {
174 void mergeParagraph(BufferParams const & bparams,
175 ParagraphList & paragraphs,
176 ParagraphList::iterator par)
178 ParagraphList::iterator the_next = boost::next(par);
180 // first the DTP-stuff
181 par->params().lineBottom(the_next->params().lineBottom());
182 par->params().spaceBottom(the_next->params().spaceBottom());
183 par->params().pagebreakBottom(the_next->params().pagebreakBottom());
185 pos_type pos_end = the_next->size() - 1;
186 pos_type pos_insert = par->size();
188 // ok, now copy the paragraph
189 for (pos_type i = 0, j = 0; i <= pos_end; ++i) {
190 the_next->cutIntoMinibuffer(bparams, i);
191 if (par->insertFromMinibuffer(pos_insert + j))
195 paragraphs.erase(the_next);
199 ParagraphList::iterator depthHook(ParagraphList::iterator pit,
200 ParagraphList const & plist,
201 Paragraph::depth_type depth)
203 ParagraphList::iterator newpit = pit;
204 ParagraphList::iterator beg = plist.begin();
209 while (newpit != beg && newpit->getDepth() > depth) {
213 if (newpit->getDepth() > depth)
220 ParagraphList::iterator outerHook(ParagraphList::iterator pit,
221 ParagraphList const & plist)
223 if (!pit->getDepth())
225 return depthHook(pit, plist,
226 Paragraph::depth_type(pit->getDepth() - 1));
230 bool isFirstInSequence(ParagraphList::iterator pit,
231 ParagraphList const & plist)
233 ParagraphList::iterator dhook = depthHook(pit, plist, pit->getDepth());
235 || dhook->layout() != pit->layout()
236 || dhook->getDepth() != pit->getDepth());
240 int getEndLabel(ParagraphList::iterator p, ParagraphList const & plist)
242 ParagraphList::iterator pit = p;
243 Paragraph::depth_type par_depth = p->getDepth();
244 while (pit != plist.end()) {
245 LyXLayout_ptr const & layout = pit->layout();
246 int const endlabeltype = layout->endlabeltype;
248 if (endlabeltype != END_LABEL_NO_LABEL) {
249 if (boost::next(p) == plist.end())
252 Paragraph::depth_type const next_depth = boost::next(p)->getDepth();
253 if (par_depth > next_depth ||
254 (par_depth == next_depth &&
255 layout != boost::next(p)->layout()))
261 pit = outerHook(pit, plist);
262 if (pit != plist.end())
263 par_depth = pit->getDepth();
265 return END_LABEL_NO_LABEL;
271 ParagraphList::iterator
272 TeXEnvironment(Buffer const * buf,
273 ParagraphList const & paragraphs,
274 ParagraphList::iterator pit,
275 ostream & os, TexRow & texrow);
277 ParagraphList::iterator
278 TeXOnePar(Buffer const * buf,
279 ParagraphList const & paragraphs,
280 ParagraphList::iterator pit,
281 ostream & os, TexRow & texrow,
283 string const & everypar = string());
286 ParagraphList::iterator
287 TeXDeeper(Buffer const * buf,
288 ParagraphList const & paragraphs,
289 ParagraphList::iterator pit,
290 ostream & os, TexRow & texrow)
292 lyxerr[Debug::LATEX] << "TeXDeeper... " << &*pit << endl;
293 ParagraphList::iterator par = pit;
295 while (par != paragraphs.end() &&
296 par->params().depth() == pit->params().depth()) {
297 if (par->layout()->isEnvironment()) {
298 par = TeXEnvironment(buf, paragraphs, par,
301 par = TeXOnePar(buf, paragraphs, par,
305 lyxerr[Debug::LATEX] << "TeXDeeper...done " << &*par << endl;
311 ParagraphList::iterator
312 TeXEnvironment(Buffer const * buf,
313 ParagraphList const & paragraphs,
314 ParagraphList::iterator pit,
315 ostream & os, TexRow & texrow)
317 lyxerr[Debug::LATEX] << "TeXEnvironment... " << &*pit << endl;
319 BufferParams const & bparams = buf->params;
321 LyXLayout_ptr const & style = pit->layout();
323 Language const * language = pit->getParLanguage(bparams);
324 Language const * doc_language = bparams.language;
325 Language const * previous_language =
326 (pit != paragraphs.begin())
327 ? boost::prior(pit)->getParLanguage(bparams)
329 if (language->babel() != previous_language->babel()) {
331 if (!lyxrc.language_command_end.empty() &&
332 previous_language->babel() != doc_language->babel()) {
333 os << subst(lyxrc.language_command_end, "$$lang",
334 previous_language->babel())
339 if (lyxrc.language_command_end.empty() ||
340 language->babel() != doc_language->babel()) {
341 os << subst(lyxrc.language_command_begin, "$$lang",
348 bool leftindent_open = false;
349 if (!pit->params().leftIndent().zero()) {
350 os << "\\begin{LyXParagraphLeftIndent}{" <<
351 pit->params().leftIndent().asLatexString() << "}\n";
353 leftindent_open = true;
356 if (style->isEnvironment()) {
357 if (style->latextype == LATEX_LIST_ENVIRONMENT) {
358 os << "\\begin{" << style->latexname() << "}{"
359 << pit->params().labelWidthString() << "}\n";
360 } else if (style->labeltype == LABEL_BIBLIO) {
362 os << "\\begin{" << style->latexname() << "}{"
363 << bibitemWidest(buf)
365 } else if (style->latextype == LATEX_ITEM_ENVIRONMENT) {
366 os << "\\begin{" << style->latexname() << '}'
367 << style->latexparam() << '\n';
369 os << "\\begin{" << style->latexname() << '}'
370 << style->latexparam() << '\n';
373 ParagraphList::iterator par = pit;
375 par = TeXOnePar(buf, paragraphs, par, os, texrow, false);
377 if (par != paragraphs.end()&& par->params().depth() > pit->params().depth()) {
378 if (par->layout()->isParagraph()) {
381 // How to handle this? (Lgb)
382 //&& !suffixIs(os, "\n\n")
384 // There should be at least one '\n' already
385 // but we need there to be two for Standard
386 // paragraphs that are depth-increment'ed to be
387 // output correctly. However, tables can
388 // also be paragraphs so don't adjust them.
391 // Will it ever harm to have one '\n' too
392 // many? i.e. that we sometimes will have
393 // three in a row. (Lgb)
397 par = TeXDeeper(buf, paragraphs, par, os, texrow);
399 } while (par != paragraphs.end()
400 && par->layout() == pit->layout()
401 && par->params().depth() == pit->params().depth()
402 && par->params().leftIndent() == pit->params().leftIndent());
404 if (style->isEnvironment()) {
405 os << "\\end{" << style->latexname() << "}\n";
409 if (leftindent_open) {
410 os << "\\end{LyXParagraphLeftIndent}\n";
414 lyxerr[Debug::LATEX] << "TeXEnvironment...done " << &*par << endl;
415 return par; // ale970302
419 InsetOptArg * optArgInset(Paragraph const & par)
422 InsetList::iterator it = par.insetlist.begin();
423 InsetList::iterator end = par.insetlist.end();
424 for (; it != end; ++it) {
425 Inset * ins = it.getInset();
426 if (ins->lyxCode() == Inset::OPTARG_CODE) {
427 return static_cast<InsetOptArg *>(ins);
434 ParagraphList::iterator
435 TeXOnePar(Buffer const * buf,
436 ParagraphList const & paragraphs,
437 ParagraphList::iterator pit,
438 ostream & os, TexRow & texrow,
440 string const & everypar)
442 lyxerr[Debug::LATEX] << "TeXOnePar... " << &*pit << " '" << everypar
444 BufferParams const & bparams = buf->params;
446 Inset const * in = pit->inInset();
447 bool further_blank_line = false;
450 // well we have to check if we are in an inset with unlimited
451 // lenght (all in one row) if that is true then we don't allow
452 // any special options in the paragraph and also we don't allow
453 // any environment other then "Standard" to be valid!
454 if ((in == 0) || !in->forceDefaultParagraphs(in)) {
455 style = pit->layout();
457 if (pit->params().startOfAppendix()) {
458 os << "\\appendix\n";
462 if (!pit->params().spacing().isDefault()
463 && (pit == paragraphs.begin() || !boost::prior(pit)->hasSameLayout(*pit))) {
464 os << pit->params().spacing().writeEnvirBegin() << '\n';
468 if (style->isCommand()) {
473 if (pit->params().pagebreakTop()) {
475 further_blank_line = true;
477 if (pit->params().spaceTop().kind() != VSpace::NONE) {
478 os << pit->params().spaceTop().asLatexCommand(bparams);
479 further_blank_line = true;
482 if (pit->params().lineTop()) {
484 << pit->getFont(bparams, 0, outerFont(pit, paragraphs)).latexSize()
486 << "\\vspace{-1\\parskip}";
487 further_blank_line = true;
490 if (further_blank_line) {
495 style = bparams.getLyXTextClass().defaultLayout();
498 Language const * language = pit->getParLanguage(bparams);
499 Language const * doc_language = bparams.language;
500 Language const * previous_language =
501 (pit != paragraphs.begin())
502 ? boost::prior(pit)->getParLanguage(bparams)
505 if (language->babel() != previous_language->babel()
506 // check if we already put language command in TeXEnvironment()
507 && !(style->isEnvironment()
508 && (pit == paragraphs.begin() ||
509 (boost::prior(pit)->layout() != pit->layout() &&
510 boost::prior(pit)->getDepth() <= pit->getDepth())
511 || boost::prior(pit)->getDepth() < pit->getDepth())))
513 if (!lyxrc.language_command_end.empty() &&
514 previous_language->babel() != doc_language->babel())
516 os << subst(lyxrc.language_command_end, "$$lang",
517 previous_language->babel())
522 if (lyxrc.language_command_end.empty() ||
523 language->babel() != doc_language->babel())
525 os << subst(lyxrc.language_command_begin, "$$lang",
532 if (bparams.inputenc == "auto" &&
533 language->encoding() != previous_language->encoding()) {
534 os << "\\inputencoding{"
535 << language->encoding()->LatexName()
540 switch (style->latextype) {
542 os << '\\' << style->latexname();
544 // Separate handling of optional argument inset.
545 if (style->optionalargs == 1) {
546 InsetOptArg * it = optArgInset(*pit);
548 it->latexOptional(buf, os, false, false);
551 os << style->latexparam();
553 case LATEX_ITEM_ENVIRONMENT:
554 case LATEX_LIST_ENVIRONMENT:
557 case LATEX_BIB_ENVIRONMENT:
558 // ignore this, the inset will write itself
565 bool need_par = pit->simpleTeXOnePar(buf, bparams,
566 outerFont(pit, paragraphs),
567 os, texrow, moving_arg);
569 // Make sure that \\par is done with the font of the last
570 // character if this has another size as the default.
571 // This is necessary because LaTeX (and LyX on the screen)
572 // calculates the space between the baselines according
573 // to this font. (Matthias)
575 // Is this really needed ? (Dekel)
576 // We do not need to use to change the font for the last paragraph
578 LyXFont const outerfont(outerFont(pit, paragraphs));
582 ? pit->getLayoutFont(bparams, outerfont)
583 : pit->getFont(bparams, pit->size() - 1, outerfont));
585 bool is_command = style->isCommand();
587 if (style->resfont.size() != font.size()
588 && boost::next(pit) != paragraphs.end()
592 os << "\\" << font.latexSize() << " \\par}";
593 } else if (need_par) {
595 } else if (is_command)
598 switch (style->latextype) {
599 case LATEX_ITEM_ENVIRONMENT:
600 case LATEX_LIST_ENVIRONMENT:
601 if (boost::next(pit) != paragraphs.end()
602 && (pit->params().depth() < boost::next(pit)->params().depth())) {
607 case LATEX_ENVIRONMENT:
608 // if its the last paragraph of the current environment
609 // skip it otherwise fall through
610 if (boost::next(pit) != paragraphs.end()
611 && (boost::next(pit)->layout() != pit->layout()
612 || boost::next(pit)->params().depth() != pit->params().depth()))
614 // fall through possible
616 // we don't need it for the last paragraph!!!
617 if (boost::next(pit) != paragraphs.end()) {
623 if ((in == 0) || !in->forceDefaultParagraphs(in)) {
624 further_blank_line = false;
625 if (pit->params().lineBottom()) {
626 os << "\\lyxline{\\" << font.latexSize() << '}';
627 further_blank_line = true;
630 if (pit->params().spaceBottom().kind() != VSpace::NONE) {
631 os << pit->params().spaceBottom().asLatexCommand(bparams);
632 further_blank_line = true;
635 if (pit->params().pagebreakBottom()) {
637 further_blank_line = true;
640 if (further_blank_line) {
645 if (!pit->params().spacing().isDefault()
646 && (boost::next(pit) == paragraphs.end()|| !boost::next(pit)->hasSameLayout(*pit))) {
647 os << pit->params().spacing().writeEnvirEnd() << '\n';
652 // we don't need it for the last paragraph!!!
653 if (boost::next(pit) != paragraphs.end()) {
657 // Since \selectlanguage write the language to the aux file,
658 // we need to reset the language at the end of footnote or
661 if (language->babel() != doc_language->babel()) {
662 if (lyxrc.language_command_end.empty())
663 os << subst(lyxrc.language_command_begin,
665 doc_language->babel())
668 os << subst(lyxrc.language_command_end,
676 lyxerr[Debug::LATEX] << "TeXOnePar...done " << &*boost::next(pit) << endl;
684 // LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
686 void latexParagraphs(Buffer const * buf,
687 ParagraphList const & paragraphs,
691 string const & everypar)
693 bool was_title = false;
694 bool already_title = false;
695 LyXTextClass const & tclass = buf->params.getLyXTextClass();
696 ParagraphList::iterator par = paragraphs.begin();
697 ParagraphList::iterator endpar = paragraphs.end();
700 while (par != endpar) {
701 Inset * in = par->inInset();
702 // well we have to check if we are in an inset with unlimited
703 // length (all in one row) if that is true then we don't allow
704 // any special options in the paragraph and also we don't allow
705 // any environment other then "Standard" to be valid!
706 if ((in == 0) || !in->forceDefaultParagraphs(in)) {
707 LyXLayout_ptr const & layout = par->layout();
709 if (layout->intitle) {
711 lyxerr <<"Error in latexParagraphs: You"
712 " should not mix title layouts"
713 " with normal ones." << endl;
714 } else if (!was_title) {
716 if (tclass.titletype() == TITLE_ENVIRONMENT) {
718 << tclass.titlename()
723 } else if (was_title && !already_title) {
724 if (tclass.titletype() == TITLE_ENVIRONMENT) {
725 os << "\\end{" << tclass.titlename()
729 os << "\\" << tclass.titlename()
733 already_title = true;
737 if (layout->is_environment) {
738 par = TeXOnePar(buf, paragraphs, par, os, texrow,
739 moving_arg, everypar);
740 } else if (layout->isEnvironment() ||
741 !par->params().leftIndent().zero())
743 par = TeXEnvironment(buf, paragraphs, par, os, texrow);
745 par = TeXOnePar(buf, paragraphs, par, os, texrow,
746 moving_arg, everypar);
749 par = TeXOnePar(buf, paragraphs, par, os, texrow,
750 moving_arg, everypar);
753 // It might be that we only have a title in this document
754 if (was_title && !already_title) {
755 if (tclass.titletype() == TITLE_ENVIRONMENT) {
756 os << "\\end{" << tclass.titlename()
760 os << "\\" << tclass.titlename()
770 int readParToken(Buffer & buf, Paragraph & par, LyXLex & lex, string const & token)
773 static Change change;
775 BufferParams const & bp = buf.params;
777 if (token[0] != '\\') {
778 string::const_iterator cit = token.begin();
779 for (; cit != token.end(); ++cit) {
780 par.insertChar(par.size(), (*cit), font, change);
782 } else if (token == "\\layout") {
784 string layoutname = lex.getString();
786 font = LyXFont(LyXFont::ALL_INHERIT, bp.language);
789 LyXTextClass const & tclass = bp.getLyXTextClass();
791 if (layoutname.empty()) {
792 layoutname = tclass.defaultLayoutName();
795 bool hasLayout = tclass.hasLayout(layoutname);
798 lyxerr << "Layout '" << layoutname << "' does not"
799 << " exist in textclass '" << tclass.name()
801 lyxerr << "Trying to use default layout instead."
803 layoutname = tclass.defaultLayoutName();
807 // The is the compability reading of layout caption.
808 if (compare_ascii_no_case(layoutname, "caption") == 0) {
809 // We expect that the par we are now working on is
810 // really inside a InsetText inside a InsetFloat.
811 // We also know that captions can only be
812 // one paragraph. (Lgb)
814 // We should now read until the next "\layout"
816 // This is probably not good enough, what if the
817 // caption is the last par in the document (Lgb)
818 istream & ist = lex.getStream();
824 if (prefixIs(line, "\\layout")) {
828 if (prefixIs(line, "\\begin_inset"))
830 if (prefixIs(line, "\\end_inset")) {
842 // Now we should have the whole layout in ss
843 // we should now be able to give this to the
845 ss << "\\end_inset\n";
847 // This seems like a bug in stringstream.
848 // We really should be able to use ss
850 istringstream is(ss.str());
852 tmplex.setStream(is);
853 Inset * inset = new InsetCaption;
854 inset->Read(this, tmplex);
855 par.insertInset(pos, inset, font);
859 par.layout(bp.getLyXTextClass()[layoutname]);
861 // Test whether the layout is obsolete.
862 LyXLayout_ptr const & layout = par.layout();
863 if (!layout->obsoleted_by().empty())
864 par.layout(bp.getLyXTextClass()[layout->obsoleted_by()]);
866 par.params().read(lex);
871 } else if (token == "\\end_inset") {
872 lyxerr << "Solitary \\end_inset in line " << lex.getLineNo() << "\n"
873 << "Missing \\begin_inset?.\n";
874 // Simply ignore this. The insets do not have
876 // But insets should read it, it is a part of
877 // the inset isn't it? Lgb.
878 } else if (token == "\\begin_inset") {
879 Inset * i = readInset(lex, buf);
880 par.insertInset(par.size(), i, font, change);
881 } else if (token == "\\family") {
883 font.setLyXFamily(lex.getString());
884 } else if (token == "\\series") {
886 font.setLyXSeries(lex.getString());
887 } else if (token == "\\shape") {
889 font.setLyXShape(lex.getString());
890 } else if (token == "\\size") {
892 font.setLyXSize(lex.getString());
893 } else if (token == "\\lang") {
895 string const tok = lex.getString();
896 Language const * lang = languages.getLanguage(tok);
898 font.setLanguage(lang);
900 font.setLanguage(bp.language);
901 lex.printError("Unknown language `$$Token'");
903 } else if (token == "\\numeric") {
905 font.setNumber(font.setLyXMisc(lex.getString()));
906 } else if (token == "\\emph") {
908 font.setEmph(font.setLyXMisc(lex.getString()));
909 } else if (token == "\\bar") {
911 string const tok = lex.getString();
914 font.setUnderbar(LyXFont::ON);
915 else if (tok == "no")
916 font.setUnderbar(LyXFont::OFF);
917 else if (tok == "default")
918 font.setUnderbar(LyXFont::INHERIT);
920 lex.printError("Unknown bar font flag "
922 } else if (token == "\\noun") {
924 font.setNoun(font.setLyXMisc(lex.getString()));
925 } else if (token == "\\color") {
927 font.setLyXColor(lex.getString());
928 } else if (token == "\\SpecialChar") {
929 LyXLayout_ptr const & layout = par.layout();
931 // Insets don't make sense in a free-spacing context! ---Kayvan
932 if (layout->free_spacing || par.isFreeSpacing()) {
935 string const next_token = lex.getString();
936 if (next_token == "\\-") {
937 par.insertChar(par.size(), '-', font, change);
938 } else if (next_token == "~") {
939 par.insertChar(par.size(), ' ', font, change);
941 lex.printError("Token `$$Token' "
943 "paragraph layout!");
947 Inset * inset = new InsetSpecialChar;
948 inset->read(&buf, lex);
949 par.insertInset(par.size(), inset, font, change);
951 } else if (token == "\\i") {
952 Inset * inset = new InsetLatexAccent;
953 inset->read(&buf, lex);
954 par.insertInset(par.size(), inset, font, change);
955 } else if (token == "\\backslash") {
956 par.insertChar(par.size(), '\\', font, change);
957 } else if (token == "\\newline") {
958 Inset * inset = new InsetNewline;
959 inset->read(&buf, lex);
960 par.insertInset(par.size(), inset, font, change);
961 } else if (token == "\\LyXTable") {
962 Inset * inset = new InsetTabular(buf);
963 inset->read(&buf, lex);
964 par.insertInset(par.size(), inset, font, change);
965 } else if (token == "\\bibitem") {
966 InsetCommandParams p("bibitem", "dummy");
967 InsetBibitem * inset = new InsetBibitem(p);
968 inset->read(&buf, lex);
969 par.insertInset(par.size(), inset, font, change);
970 } else if (token == "\\hfill") {
971 par.insertInset(par.size(), new InsetHFill(), font, change);
972 } else if (token == "\\change_unchanged") {
973 // Hack ! Needed for empty paragraphs :/
974 // FIXME: is it still ??
977 change = Change(Change::UNCHANGED);
978 } else if (token == "\\change_inserted") {
980 istringstream is(STRCONV(lex.getString()));
984 change = Change(Change::INSERTED, bp.author_map[aid], ct);
985 } else if (token == "\\change_deleted") {
987 istringstream is(STRCONV(lex.getString()));
991 change = Change(Change::DELETED, bp.author_map[aid], ct);
994 string const s = bformat(_("Unknown token: %1$s %2$s\n"),
995 token, lex.getString());
996 // we can do this here this way because we're actually reading
997 // the buffer and don't care about LyXText right now.
998 par.insertInset(par.size(), new InsetError(s), font);
1007 int readParagraph(Buffer & buf, Paragraph & par, LyXLex & lex)
1012 string token = lex.getString();
1014 while (lex.isOK()) {
1016 unknown += readParToken(buf, par, lex, token);
1019 token = lex.getString();
1024 lyxerr[Debug::PARSER] << "Handling paragraph token: `"
1025 << token << '\'' << endl;
1027 // reached the next paragraph. FIXME: really we should
1028 // change the file format to indicate the end of a par
1029 // clearly, but for now, this hack will do
1030 if (token == "\\layout" || token == "\\the_end"
1031 || token == "\\end_inset" || token == "\\begin_deeper"
1032 || token == "\\end_deeper") {
1033 lex.pushToken(token);
1042 LyXFont const outerFont(ParagraphList::iterator pit,
1043 ParagraphList const & plist)
1045 Paragraph::depth_type par_depth = pit->getDepth();
1046 LyXFont tmpfont(LyXFont::ALL_INHERIT);
1048 // Resolve against environment font information
1049 while (pit != plist.end() &&
1050 par_depth && !tmpfont.resolved()) {
1051 pit = outerHook(pit, plist);
1052 if (pit != plist.end()) {
1053 tmpfont.realize(pit->layout()->font);
1054 par_depth = pit->getDepth();
1062 LyXFont const realizeFont(LyXFont const & font,
1063 BufferParams const & params)
1065 LyXTextClass const & tclass = params.getLyXTextClass();
1066 LyXFont tmpfont(font);
1067 tmpfont.realize(tclass.defaultfont());