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/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/inseterror.h"
36 #include "insets/insetnewline.h"
38 extern string bibitemWidest(Buffer const *);
41 //using lyx::layout_type;
46 void breakParagraph(BufferParams const & bparams,
47 ParagraphList & paragraphs,
48 ParagraphList::iterator par,
52 // create a new paragraph, and insert into the list
53 ParagraphList::iterator tmp = paragraphs.insert(boost::next(par),
56 // without doing that we get a crash when typing <Return> at the
58 tmp->layout(bparams.getLyXTextClass().defaultLayout());
59 // remember to set the inset_owner
60 tmp->setInsetOwner(par->inInset());
62 if (bparams.tracking_changes)
65 // this is an idea for a more userfriendly layout handling, I will
66 // see what the users say
68 // layout stays the same with latex-environments
70 tmp->layout(par->layout());
71 tmp->setLabelWidthString(par->params().labelWidthString());
74 bool const isempty = (par->layout()->keepempty && par->empty());
76 if (!isempty && (par->size() > pos || par->empty() || flag == 2)) {
77 tmp->layout(par->layout());
78 tmp->params().align(par->params().align());
79 tmp->setLabelWidthString(par->params().labelWidthString());
81 tmp->params().lineBottom(par->params().lineBottom());
82 par->params().lineBottom(false);
83 tmp->params().pagebreakBottom(par->params().pagebreakBottom());
84 par->params().pagebreakBottom(false);
85 tmp->params().spaceBottom(par->params().spaceBottom());
86 par->params().spaceBottom(VSpace(VSpace::NONE));
88 tmp->params().depth(par->params().depth());
89 tmp->params().noindent(par->params().noindent());
91 // copy everything behind the break-position
92 // to the new paragraph
95 #warning this seems wrong
97 /* FIXME: if !keepempty, empty() == true, then we reach
98 * here with size() == 0. So pos_end becomes - 1. Why
99 * doesn't this cause problems ???
101 pos_type pos_end = par->size() - 1;
105 for (; i <= pos_end; ++i) {
106 Change::Type change(par->lookupChange(i));
107 par->cutIntoMinibuffer(bparams, i);
108 if (tmp->insertFromMinibuffer(j - pos)) {
109 tmp->setChange(j - pos, change);
113 for (i = pos_end; i >= pos; --i) {
121 tmp->params().lineTop(par->params().lineTop());
122 tmp->params().pagebreakTop(par->params().pagebreakTop());
123 tmp->params().spaceTop(par->params().spaceTop());
124 par->params().clear();
126 par->layout(bparams.getLyXTextClass().defaultLayout());
128 // layout stays the same with latex-environments
130 par->layout(tmp->layout());
131 par->setLabelWidthString(tmp->params().labelWidthString());
132 par->params().depth(tmp->params().depth());
135 // subtle, but needed to get empty pars working right
136 if (bparams.tracking_changes) {
139 } else if (!tmp->size()) {
146 void breakParagraphConservative(BufferParams const & bparams,
147 ParagraphList & paragraphs,
148 ParagraphList::iterator par,
151 // create a new paragraph
152 ParagraphList::iterator tmp = paragraphs.insert(boost::next(par),
154 tmp->makeSameLayout(*par);
156 // When can pos > size()?
157 // I guess pos == size() is possible.
158 if (par->size() > pos) {
159 // copy everything behind the break-position to the new
161 pos_type pos_end = par->size() - 1;
163 for (pos_type i = pos, j = pos; i <= pos_end; ++i) {
164 par->cutIntoMinibuffer(bparams, i);
165 if (tmp->insertFromMinibuffer(j - pos))
169 for (pos_type k = pos_end; k >= pos; --k) {
176 void mergeParagraph(BufferParams const & bparams,
177 ParagraphList & paragraphs,
178 ParagraphList::iterator par)
180 ParagraphList::iterator the_next = boost::next(par);
182 // first the DTP-stuff
183 par->params().lineBottom(the_next->params().lineBottom());
184 par->params().spaceBottom(the_next->params().spaceBottom());
185 par->params().pagebreakBottom(the_next->params().pagebreakBottom());
187 pos_type pos_end = the_next->size() - 1;
188 pos_type pos_insert = par->size();
190 // ok, now copy the paragraph
191 for (pos_type i = 0, j = 0; i <= pos_end; ++i) {
192 the_next->cutIntoMinibuffer(bparams, i);
193 if (par->insertFromMinibuffer(pos_insert + j))
197 paragraphs.erase(the_next);
201 ParagraphList::iterator depthHook(ParagraphList::iterator pit,
202 ParagraphList const & plist,
203 Paragraph::depth_type depth)
205 ParagraphList::iterator newpit = pit;
206 ParagraphList::iterator beg = plist.begin();
211 while (newpit != beg && newpit->getDepth() > depth) {
215 if (newpit->getDepth() > depth)
222 ParagraphList::iterator outerHook(ParagraphList::iterator pit,
223 ParagraphList const & plist)
225 if (!pit->getDepth())
227 return depthHook(pit, plist,
228 Paragraph::depth_type(pit->getDepth() - 1));
232 bool isFirstInSequence(ParagraphList::iterator pit,
233 ParagraphList const & plist)
235 ParagraphList::iterator dhook = depthHook(pit, plist, pit->getDepth());
237 || dhook->layout() != pit->layout()
238 || dhook->getDepth() != pit->getDepth());
242 int getEndLabel(ParagraphList::iterator p, ParagraphList const & plist)
244 ParagraphList::iterator pit = p;
245 Paragraph::depth_type par_depth = p->getDepth();
246 while (pit != plist.end()) {
247 LyXLayout_ptr const & layout = pit->layout();
248 int const endlabeltype = layout->endlabeltype;
250 if (endlabeltype != END_LABEL_NO_LABEL) {
251 if (boost::next(p) == plist.end())
254 Paragraph::depth_type const next_depth = boost::next(p)->getDepth();
255 if (par_depth > next_depth ||
256 (par_depth == next_depth &&
257 layout != boost::next(p)->layout()))
263 pit = outerHook(pit, plist);
264 if (pit != plist.end())
265 par_depth = pit->getDepth();
267 return END_LABEL_NO_LABEL;
273 ParagraphList::iterator
274 TeXEnvironment(Buffer const * buf,
275 ParagraphList const & paragraphs,
276 ParagraphList::iterator pit,
277 ostream & os, TexRow & texrow,
278 LatexRunParams const & runparams);
280 ParagraphList::iterator
281 TeXOnePar(Buffer const * buf,
282 ParagraphList const & paragraphs,
283 ParagraphList::iterator pit,
284 ostream & os, TexRow & texrow,
285 LatexRunParams const & runparams,
286 string const & everypar = string());
289 ParagraphList::iterator
290 TeXDeeper(Buffer const * buf,
291 ParagraphList const & paragraphs,
292 ParagraphList::iterator pit,
293 ostream & os, TexRow & texrow,
294 LatexRunParams const & runparams)
296 lyxerr[Debug::LATEX] << "TeXDeeper... " << &*pit << endl;
297 ParagraphList::iterator par = pit;
299 while (par != paragraphs.end() &&
300 par->params().depth() == pit->params().depth()) {
301 if (par->layout()->isEnvironment()) {
302 par = TeXEnvironment(buf, paragraphs, par,
303 os, texrow, runparams);
305 par = TeXOnePar(buf, paragraphs, par,
306 os, texrow, runparams);
309 lyxerr[Debug::LATEX] << "TeXDeeper...done " << &*par << endl;
315 ParagraphList::iterator
316 TeXEnvironment(Buffer const * buf,
317 ParagraphList const & paragraphs,
318 ParagraphList::iterator pit,
319 ostream & os, TexRow & texrow,
320 LatexRunParams const & runparams)
322 lyxerr[Debug::LATEX] << "TeXEnvironment... " << &*pit << endl;
324 BufferParams const & bparams = buf->params;
326 LyXLayout_ptr const & style = pit->layout();
328 Language const * language = pit->getParLanguage(bparams);
329 Language const * doc_language = bparams.language;
330 Language const * previous_language =
331 (pit != paragraphs.begin())
332 ? boost::prior(pit)->getParLanguage(bparams)
334 if (language->babel() != previous_language->babel()) {
336 if (!lyxrc.language_command_end.empty() &&
337 previous_language->babel() != doc_language->babel()) {
338 os << subst(lyxrc.language_command_end, "$$lang",
339 previous_language->babel())
344 if (lyxrc.language_command_end.empty() ||
345 language->babel() != doc_language->babel()) {
346 os << subst(lyxrc.language_command_begin, "$$lang",
353 bool leftindent_open = false;
354 if (!pit->params().leftIndent().zero()) {
355 os << "\\begin{LyXParagraphLeftIndent}{" <<
356 pit->params().leftIndent().asLatexString() << "}\n";
358 leftindent_open = true;
361 if (style->isEnvironment()) {
362 if (style->latextype == LATEX_LIST_ENVIRONMENT) {
363 os << "\\begin{" << style->latexname() << "}{"
364 << pit->params().labelWidthString() << "}\n";
365 } else if (style->labeltype == LABEL_BIBLIO) {
367 os << "\\begin{" << style->latexname() << "}{"
368 << bibitemWidest(buf)
370 } else if (style->latextype == LATEX_ITEM_ENVIRONMENT) {
371 os << "\\begin{" << style->latexname() << '}'
372 << style->latexparam() << '\n';
374 os << "\\begin{" << style->latexname() << '}'
375 << style->latexparam() << '\n';
378 ParagraphList::iterator par = pit;
380 par = TeXOnePar(buf, paragraphs, par, os, texrow, runparams);
382 if (par != paragraphs.end()&& par->params().depth() > pit->params().depth()) {
383 if (par->layout()->isParagraph()) {
386 // How to handle this? (Lgb)
387 //&& !suffixIs(os, "\n\n")
389 // There should be at least one '\n' already
390 // but we need there to be two for Standard
391 // paragraphs that are depth-increment'ed to be
392 // output correctly. However, tables can
393 // also be paragraphs so don't adjust them.
396 // Will it ever harm to have one '\n' too
397 // many? i.e. that we sometimes will have
398 // three in a row. (Lgb)
402 par = TeXDeeper(buf, paragraphs, par, os, texrow,
405 } while (par != paragraphs.end()
406 && par->layout() == pit->layout()
407 && par->params().depth() == pit->params().depth()
408 && par->params().leftIndent() == pit->params().leftIndent());
410 if (style->isEnvironment()) {
411 os << "\\end{" << style->latexname() << "}\n";
415 if (leftindent_open) {
416 os << "\\end{LyXParagraphLeftIndent}\n";
420 lyxerr[Debug::LATEX] << "TeXEnvironment...done " << &*par << endl;
421 return par; // ale970302
425 InsetOptArg * optArgInset(Paragraph const & par)
428 InsetList::iterator it = par.insetlist.begin();
429 InsetList::iterator end = par.insetlist.end();
430 for (; it != end; ++it) {
431 Inset * ins = it.getInset();
432 if (ins->lyxCode() == Inset::OPTARG_CODE) {
433 return static_cast<InsetOptArg *>(ins);
440 ParagraphList::iterator
441 TeXOnePar(Buffer const * buf,
442 ParagraphList const & paragraphs,
443 ParagraphList::iterator pit,
444 ostream & os, TexRow & texrow,
445 LatexRunParams const & runparams,
446 string const & everypar)
448 lyxerr[Debug::LATEX] << "TeXOnePar... " << &*pit << " '" << everypar
450 BufferParams const & bparams = buf->params;
452 Inset const * in = pit->inInset();
453 bool further_blank_line = false;
456 // well we have to check if we are in an inset with unlimited
457 // lenght (all in one row) if that is true then we don't allow
458 // any special options in the paragraph and also we don't allow
459 // any environment other then "Standard" to be valid!
460 if ((in == 0) || !in->forceDefaultParagraphs(in)) {
461 style = pit->layout();
463 if (pit->params().startOfAppendix()) {
464 os << "\\appendix\n";
468 if (!pit->params().spacing().isDefault()
469 && (pit == paragraphs.begin() || !boost::prior(pit)->hasSameLayout(*pit))) {
470 os << pit->params().spacing().writeEnvirBegin() << '\n';
474 if (style->isCommand()) {
479 if (pit->params().pagebreakTop()) {
481 further_blank_line = true;
483 if (pit->params().spaceTop().kind() != VSpace::NONE) {
484 os << pit->params().spaceTop().asLatexCommand(bparams);
485 further_blank_line = true;
488 if (pit->params().lineTop()) {
490 << pit->getFont(bparams, 0, outerFont(pit, paragraphs)).latexSize()
492 << "\\vspace{-1\\parskip}";
493 further_blank_line = true;
496 if (further_blank_line) {
501 style = bparams.getLyXTextClass().defaultLayout();
504 Language const * language = pit->getParLanguage(bparams);
505 Language const * doc_language = bparams.language;
506 Language const * previous_language =
507 (pit != paragraphs.begin())
508 ? boost::prior(pit)->getParLanguage(bparams)
511 if (language->babel() != previous_language->babel()
512 // check if we already put language command in TeXEnvironment()
513 && !(style->isEnvironment()
514 && (pit == paragraphs.begin() ||
515 (boost::prior(pit)->layout() != pit->layout() &&
516 boost::prior(pit)->getDepth() <= pit->getDepth())
517 || boost::prior(pit)->getDepth() < pit->getDepth())))
519 if (!lyxrc.language_command_end.empty() &&
520 previous_language->babel() != doc_language->babel())
522 os << subst(lyxrc.language_command_end, "$$lang",
523 previous_language->babel())
528 if (lyxrc.language_command_end.empty() ||
529 language->babel() != doc_language->babel())
531 os << subst(lyxrc.language_command_begin, "$$lang",
538 if (bparams.inputenc == "auto" &&
539 language->encoding() != previous_language->encoding()) {
540 os << "\\inputencoding{"
541 << language->encoding()->LatexName()
546 switch (style->latextype) {
548 os << '\\' << style->latexname();
550 // Separate handling of optional argument inset.
551 if (style->optionalargs == 1) {
552 InsetOptArg * it = optArgInset(*pit);
554 it->latexOptional(buf, os, runparams);
557 os << style->latexparam();
559 case LATEX_ITEM_ENVIRONMENT:
560 case LATEX_LIST_ENVIRONMENT:
563 case LATEX_BIB_ENVIRONMENT:
564 // ignore this, the inset will write itself
571 bool need_par = pit->simpleTeXOnePar(buf, bparams,
572 outerFont(pit, paragraphs),
573 os, texrow, runparams);
575 // Make sure that \\par is done with the font of the last
576 // character if this has another size as the default.
577 // This is necessary because LaTeX (and LyX on the screen)
578 // calculates the space between the baselines according
579 // to this font. (Matthias)
581 // Is this really needed ? (Dekel)
582 // We do not need to use to change the font for the last paragraph
584 LyXFont const outerfont(outerFont(pit, paragraphs));
588 ? pit->getLayoutFont(bparams, outerfont)
589 : pit->getFont(bparams, pit->size() - 1, outerfont));
591 bool is_command = style->isCommand();
593 if (style->resfont.size() != font.size()
594 && boost::next(pit) != paragraphs.end()
598 os << "\\" << font.latexSize() << " \\par}";
599 } else if (need_par) {
601 } else if (is_command)
604 switch (style->latextype) {
605 case LATEX_ITEM_ENVIRONMENT:
606 case LATEX_LIST_ENVIRONMENT:
607 if (boost::next(pit) != paragraphs.end()
608 && (pit->params().depth() < boost::next(pit)->params().depth())) {
613 case LATEX_ENVIRONMENT:
614 // if its the last paragraph of the current environment
615 // skip it otherwise fall through
616 if (boost::next(pit) != paragraphs.end()
617 && (boost::next(pit)->layout() != pit->layout()
618 || boost::next(pit)->params().depth() != pit->params().depth()))
620 // fall through possible
622 // we don't need it for the last paragraph!!!
623 if (boost::next(pit) != paragraphs.end()) {
629 if ((in == 0) || !in->forceDefaultParagraphs(in)) {
630 further_blank_line = false;
631 if (pit->params().lineBottom()) {
632 os << "\\lyxline{\\" << font.latexSize() << '}';
633 further_blank_line = true;
636 if (pit->params().spaceBottom().kind() != VSpace::NONE) {
637 os << pit->params().spaceBottom().asLatexCommand(bparams);
638 further_blank_line = true;
641 if (pit->params().pagebreakBottom()) {
643 further_blank_line = true;
646 if (further_blank_line) {
651 if (!pit->params().spacing().isDefault()
652 && (boost::next(pit) == paragraphs.end()|| !boost::next(pit)->hasSameLayout(*pit))) {
653 os << pit->params().spacing().writeEnvirEnd() << '\n';
658 // we don't need it for the last paragraph!!!
659 if (boost::next(pit) != paragraphs.end()) {
663 // Since \selectlanguage write the language to the aux file,
664 // we need to reset the language at the end of footnote or
667 if (language->babel() != doc_language->babel()) {
668 if (lyxrc.language_command_end.empty())
669 os << subst(lyxrc.language_command_begin,
671 doc_language->babel())
674 os << subst(lyxrc.language_command_end,
682 lyxerr[Debug::LATEX] << "TeXOnePar...done " << &*boost::next(pit) << endl;
690 // LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
692 void latexParagraphs(Buffer const * buf,
693 ParagraphList const & paragraphs,
696 LatexRunParams const & runparams,
697 string const & everypar)
699 bool was_title = false;
700 bool already_title = false;
701 LyXTextClass const & tclass = buf->params.getLyXTextClass();
702 ParagraphList::iterator par = paragraphs.begin();
703 ParagraphList::iterator endpar = paragraphs.end();
706 while (par != endpar) {
707 Inset * in = par->inInset();
708 // well we have to check if we are in an inset with unlimited
709 // length (all in one row) if that is true then we don't allow
710 // any special options in the paragraph and also we don't allow
711 // any environment other then "Standard" to be valid!
712 if ((in == 0) || !in->forceDefaultParagraphs(in)) {
713 LyXLayout_ptr const & layout = par->layout();
715 if (layout->intitle) {
717 lyxerr <<"Error in latexParagraphs: You"
718 " should not mix title layouts"
719 " with normal ones." << endl;
720 } else if (!was_title) {
722 if (tclass.titletype() == TITLE_ENVIRONMENT) {
724 << tclass.titlename()
729 } else if (was_title && !already_title) {
730 if (tclass.titletype() == TITLE_ENVIRONMENT) {
731 os << "\\end{" << tclass.titlename()
735 os << "\\" << tclass.titlename()
739 already_title = true;
743 if (layout->is_environment) {
744 par = TeXOnePar(buf, paragraphs, par, os, texrow,
745 runparams, everypar);
746 } else if (layout->isEnvironment() ||
747 !par->params().leftIndent().zero())
749 par = TeXEnvironment(buf, paragraphs, par, os,
752 par = TeXOnePar(buf, paragraphs, par, os, texrow,
753 runparams, everypar);
756 par = TeXOnePar(buf, paragraphs, par, os, texrow,
757 runparams, everypar);
760 // It might be that we only have a title in this document
761 if (was_title && !already_title) {
762 if (tclass.titletype() == TITLE_ENVIRONMENT) {
763 os << "\\end{" << tclass.titlename()
767 os << "\\" << tclass.titlename()
777 int readParToken(Buffer & buf, Paragraph & par, LyXLex & lex, string const & token)
780 static Change change;
782 BufferParams const & bp = buf.params;
784 if (token[0] != '\\') {
785 string::const_iterator cit = token.begin();
786 for (; cit != token.end(); ++cit) {
787 par.insertChar(par.size(), (*cit), font, change);
789 } else if (token == "\\layout") {
791 string layoutname = lex.getString();
793 font = LyXFont(LyXFont::ALL_INHERIT, bp.language);
796 LyXTextClass const & tclass = bp.getLyXTextClass();
798 if (layoutname.empty()) {
799 layoutname = tclass.defaultLayoutName();
802 bool hasLayout = tclass.hasLayout(layoutname);
805 lyxerr << "Layout '" << layoutname << "' does not"
806 << " exist in textclass '" << tclass.name()
808 lyxerr << "Trying to use default layout instead."
810 layoutname = tclass.defaultLayoutName();
814 // The is the compability reading of layout caption.
815 if (compare_ascii_no_case(layoutname, "caption") == 0) {
816 // We expect that the par we are now working on is
817 // really inside a InsetText inside a InsetFloat.
818 // We also know that captions can only be
819 // one paragraph. (Lgb)
821 // We should now read until the next "\layout"
823 // This is probably not good enough, what if the
824 // caption is the last par in the document (Lgb)
825 istream & ist = lex.getStream();
831 if (prefixIs(line, "\\layout")) {
835 if (prefixIs(line, "\\begin_inset"))
837 if (prefixIs(line, "\\end_inset")) {
849 // Now we should have the whole layout in ss
850 // we should now be able to give this to the
852 ss << "\\end_inset\n";
854 // This seems like a bug in stringstream.
855 // We really should be able to use ss
857 istringstream is(ss.str());
859 tmplex.setStream(is);
860 Inset * inset = new InsetCaption;
861 inset->Read(this, tmplex);
862 par.insertInset(pos, inset, font);
866 par.layout(bp.getLyXTextClass()[layoutname]);
868 // Test whether the layout is obsolete.
869 LyXLayout_ptr const & layout = par.layout();
870 if (!layout->obsoleted_by().empty())
871 par.layout(bp.getLyXTextClass()[layout->obsoleted_by()]);
873 par.params().read(lex);
878 } else if (token == "\\end_inset") {
879 lyxerr << "Solitary \\end_inset in line " << lex.getLineNo() << "\n"
880 << "Missing \\begin_inset?.\n";
881 // Simply ignore this. The insets do not have
883 // But insets should read it, it is a part of
884 // the inset isn't it? Lgb.
885 } else if (token == "\\begin_inset") {
886 Inset * i = readInset(lex, buf);
887 par.insertInset(par.size(), i, font, change);
888 } else if (token == "\\family") {
890 font.setLyXFamily(lex.getString());
891 } else if (token == "\\series") {
893 font.setLyXSeries(lex.getString());
894 } else if (token == "\\shape") {
896 font.setLyXShape(lex.getString());
897 } else if (token == "\\size") {
899 font.setLyXSize(lex.getString());
900 } else if (token == "\\lang") {
902 string const tok = lex.getString();
903 Language const * lang = languages.getLanguage(tok);
905 font.setLanguage(lang);
907 font.setLanguage(bp.language);
908 lex.printError("Unknown language `$$Token'");
910 } else if (token == "\\numeric") {
912 font.setNumber(font.setLyXMisc(lex.getString()));
913 } else if (token == "\\emph") {
915 font.setEmph(font.setLyXMisc(lex.getString()));
916 } else if (token == "\\bar") {
918 string const tok = lex.getString();
921 font.setUnderbar(LyXFont::ON);
922 else if (tok == "no")
923 font.setUnderbar(LyXFont::OFF);
924 else if (tok == "default")
925 font.setUnderbar(LyXFont::INHERIT);
927 lex.printError("Unknown bar font flag "
929 } else if (token == "\\noun") {
931 font.setNoun(font.setLyXMisc(lex.getString()));
932 } else if (token == "\\color") {
934 font.setLyXColor(lex.getString());
935 } else if (token == "\\InsetSpace" || token == "\\SpecialChar") {
936 LyXLayout_ptr const & layout = par.layout();
938 // Insets don't make sense in a free-spacing context! ---Kayvan
939 if (layout->free_spacing || par.isFreeSpacing()) {
940 if (token == "\\InsetSpace")
941 par.insertChar(par.size(), ' ', font, change);
942 else if (lex.isOK()) {
944 string const next_token = lex.getString();
945 if (next_token == "\\-")
946 par.insertChar(par.size(), '-', font, change);
948 lex.printError("Token `$$Token' "
950 "paragraph layout!");
955 if (token == "\\SpecialChar" )
956 inset = new InsetSpecialChar;
958 inset = new InsetSpace;
959 inset->read(&buf, lex);
960 par.insertInset(par.size(), inset, font, change);
962 } else if (token == "\\i") {
963 Inset * inset = new InsetLatexAccent;
964 inset->read(&buf, lex);
965 par.insertInset(par.size(), inset, font, change);
966 } else if (token == "\\backslash") {
967 par.insertChar(par.size(), '\\', font, change);
968 } else if (token == "\\newline") {
969 Inset * inset = new InsetNewline;
970 inset->read(&buf, lex);
971 par.insertInset(par.size(), inset, font, change);
972 } else if (token == "\\LyXTable") {
973 Inset * inset = new InsetTabular(buf);
974 inset->read(&buf, lex);
975 par.insertInset(par.size(), inset, font, change);
976 } else if (token == "\\bibitem") {
977 InsetCommandParams p("bibitem", "dummy");
978 InsetBibitem * inset = new InsetBibitem(p);
979 inset->read(&buf, lex);
980 par.insertInset(par.size(), inset, font, change);
981 } else if (token == "\\hfill") {
982 par.insertInset(par.size(), new InsetHFill(), font, change);
983 } else if (token == "\\change_unchanged") {
984 // Hack ! Needed for empty paragraphs :/
985 // FIXME: is it still ??
988 change = Change(Change::UNCHANGED);
989 } else if (token == "\\change_inserted") {
991 istringstream is(STRCONV(lex.getString()));
995 change = Change(Change::INSERTED, bp.author_map[aid], ct);
996 } else if (token == "\\change_deleted") {
998 istringstream is(STRCONV(lex.getString()));
1002 change = Change(Change::DELETED, bp.author_map[aid], ct);
1005 string const s = bformat(_("Unknown token: %1$s %2$s\n"),
1006 token, lex.getString());
1007 // we can do this here this way because we're actually reading
1008 // the buffer and don't care about LyXText right now.
1009 par.insertInset(par.size(), new InsetError(s), font);
1018 int readParagraph(Buffer & buf, Paragraph & par, LyXLex & lex)
1023 string token = lex.getString();
1025 while (lex.isOK()) {
1027 unknown += readParToken(buf, par, lex, token);
1030 token = lex.getString();
1035 lyxerr[Debug::PARSER] << "Handling paragraph token: `"
1036 << token << '\'' << endl;
1038 // reached the next paragraph. FIXME: really we should
1039 // change the file format to indicate the end of a par
1040 // clearly, but for now, this hack will do
1041 if (token == "\\layout" || token == "\\the_end"
1042 || token == "\\end_inset" || token == "\\begin_deeper"
1043 || token == "\\end_deeper") {
1044 lex.pushToken(token);
1053 LyXFont const outerFont(ParagraphList::iterator pit,
1054 ParagraphList const & plist)
1056 Paragraph::depth_type par_depth = pit->getDepth();
1057 LyXFont tmpfont(LyXFont::ALL_INHERIT);
1059 // Resolve against environment font information
1060 while (pit != plist.end() &&
1061 par_depth && !tmpfont.resolved()) {
1062 pit = outerHook(pit, plist);
1063 if (pit != plist.end()) {
1064 tmpfont.realize(pit->layout()->font);
1065 par_depth = pit->getDepth();
1073 LyXFont const realizeFont(LyXFont const & font,
1074 BufferParams const & params)
1076 LyXTextClass const & tclass = params.getLyXTextClass();
1077 LyXFont tmpfont(font);
1078 tmpfont.realize(tclass.defaultfont());